Skip to content

Commit

Permalink
Merge pull request #11 from Dhruv-Techapps/feature/google-sheets
Browse files Browse the repository at this point in the history
Feature/google sheets
  • Loading branch information
dharmesh-hemaram authored Oct 1, 2023
2 parents 233fd7f + 1d6b6c5 commit b65ce06
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 59 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/push-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: mono-repo

on:
workflow_dispatch:
push:
branches:
- 'feature/**'

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:
EnvSetup:
name: Setup Dynamic Environment Variables
runs-on: ubuntu-latest
environment: Development
outputs:
#Name
NX_NAME: ${{ steps.set-output-defaults.outputs.NX_NAME}}
#Variant
NX_VARIANT: ${{ steps.set-output-defaults.outputs.NX_VARIANT}}
#Chrome Extension
NX_CHROME_EXTENSION_ID: ${{ steps.set-output-defaults.outputs.NX_CHROME_EXTENSION_ID}}
#Edge Extension
NX_EDGE_EXTENSION_ID: ${{ steps.set-output-defaults.outputs.NX_EDGE_EXTENSION_ID}}
#i18n
NX_I18N: ${{steps.set-output-defaults.outputs.NX_I18N}}
#Google Analytics
NX_GOOGLE_ANALYTICS_ID: ${{steps.set-output-defaults.outputs.NX_GOOGLE_ANALYTICS_ID}}
#Google Adsense
NX_GOOGLE_ADS_SLOT: ${{steps.set-output-defaults.outputs.NX_GOOGLE_ADS_SLOT}}
NX_GOOGLE_ADS_CLIENT: ${{steps.set-output-defaults.outputs.NX_GOOGLE_ADS_CLIENT}}
# Public URL
PUBLIC_URL: ${{ steps.set-output-defaults.outputs.PUBLIC_URL}}
# Extension
UNINSTALL_URL: ${{ steps.set-output-defaults.outputs.UNINSTALL_URL}}
TRACKING_ID: ${{ steps.set-output-defaults.outputs.TRACKING_ID}}
FUNCTION_URL: ${{ steps.set-output-defaults.outputs.FUNCTION_URL}}
DISCORD_CLIENT_ID: ${{ steps.set-output-defaults.outputs.DISCORD_CLIENT_ID}}
OAUTH_CLIENT_ID: ${{ steps.set-output-defaults.outputs.OAUTH_CLIENT_ID}}
steps:
- name: set outputs with default values
id: set-output-defaults
run: |
echo "NX_NAME=${{ vars.NX_NAME }}" >> $GITHUB_OUTPUT
echo "NX_VARIANT=${{ vars.NX_VARIANT }}" >> $GITHUB_OUTPUT
echo "NX_CHROME_EXTENSION_ID=${{ vars.NX_CHROME_EXTENSION_ID }}" >> $GITHUB_OUTPUT
echo "NX_EDGE_EXTENSION_ID=${{ vars.NX_EDGE_EXTENSION_ID || 'DEV' }}" >> $GITHUB_OUTPUT
echo "NX_I18N=${{ vars.NX_I18N }}" >> $GITHUB_OUTPUT
echo "NX_GOOGLE_ANALYTICS_ID=${{ vars.NX_GOOGLE_ANALYTICS_ID }}" >> $GITHUB_OUTPUT
echo "NX_GOOGLE_ADS_SLOT=${{ vars.NX_GOOGLE_ADS_SLOT }}" >> $GITHUB_OUTPUT
echo "NX_GOOGLE_ADS_CLIENT=${{ vars.NX_GOOGLE_ADS_CLIENT }}" >> $GITHUB_OUTPUT
echo "UNINSTALL_URL=${{ vars.UNINSTALL_URL }}" >> $GITHUB_OUTPUT
echo "TRACKING_ID=${{ vars.TRACKING_ID }}" >> $GITHUB_OUTPUT
echo "FUNCTION_URL=${{ vars.FUNCTION_URL }}" >> $GITHUB_OUTPUT
echo "DISCORD_CLIENT_ID='${{ vars.DISCORD_CLIENT_ID }}'" >> $GITHUB_OUTPUT
echo "OAUTH_CLIENT_ID=${{ vars.OAUTH_CLIENT_ID }}" >> $GITHUB_OUTPUT
echo "PUBLIC_URL=${{ vars.PUBLIC_URL }}" >> $GITHUB_OUTPUT
main:
needs: [EnvSetup]
name: Nx Cloud - Main Job
uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.0
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
with:
# parallel-commands: |
# npx nx-cloud record -- npx nx format:check
artifacts-path: 'dist/apps/*'
environment-variables: |
NX_NAME=${{needs.EnvSetup.outputs.NX_NAME}}
NX_VARIANT=${{needs.EnvSetup.outputs.NX_VARIANT}}
NX_CHROME_EXTENSION_ID=${{needs.EnvSetup.outputs.NX_CHROME_EXTENSION_ID}}
NX_EDGE_EXTENSION_ID=${{needs.EnvSetup.outputs.NX_EDGE_EXTENSION_ID}}
NX_I18N=${{needs.EnvSetup.outputs.NX_I18N}}
NX_GOOGLE_ANALYTICS_ID=${{needs.EnvSetup.outputs.NX_GOOGLE_ANALYTICS_ID}}
NX_GOOGLE_ADS_SLOT=${{needs.EnvSetup.outputs.NX_GOOGLE_ADS_SLOT}}
NX_GOOGLE_ADS_CLIENT=${{needs.EnvSetup.outputs.NX_GOOGLE_ADS_CLIENT}}
UNINSTALL_URL=${{needs.EnvSetup.outputs.UNINSTALL_URL}}
TRACKING_ID=${{needs.EnvSetup.outputs.TRACKING_ID}}
FUNCTION_URL=${{needs.EnvSetup.outputs.FUNCTION_URL}}
DISCORD_CLIENT_ID=${{needs.EnvSetup.outputs.DISCORD_CLIENT_ID}}
OAUTH_CLIENT_ID=${{needs.EnvSetup.outputs.OAUTH_CLIENT_ID}}
PUBLIC_URL=${{needs.EnvSetup.outputs.PUBLIC_URL}}
init-commands: |
ls
parallel-commands-on-agents: |
npx nx run-many --target=lint --parallel=3
npx nx run-many --target=test --parallel=3 --exclude='tag:puppeteer' --ci --code-coverage
npx nx run-many --target=build --parallel=3 --exclude='tag:puppeteer'
agents:
needs: [EnvSetup]
name: Nx Cloud - Agents
uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.0
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
with:
number-of-agents: 3
environment-variables: |
NX_NAME=${{needs.EnvSetup.outputs.NX_NAME}}
NX_VARIANT=${{needs.EnvSetup.outputs.NX_VARIANT}}
NX_CHROME_EXTENSION_ID=${{needs.EnvSetup.outputs.NX_CHROME_EXTENSION_ID}}
NX_EDGE_EXTENSION_ID=${{needs.EnvSetup.outputs.NX_EDGE_EXTENSION_ID}}
NX_I18N=${{needs.EnvSetup.outputs.NX_I18N}}
NX_GOOGLE_ANALYTICS_ID=${{needs.EnvSetup.outputs.NX_GOOGLE_ANALYTICS_ID}}
NX_GOOGLE_ADS_SLOT=${{needs.EnvSetup.outputs.NX_GOOGLE_ADS_SLOT}}
NX_GOOGLE_ADS_CLIENT=${{needs.EnvSetup.outputs.NX_GOOGLE_ADS_CLIENT}}
UNINSTALL_URL=${{needs.EnvSetup.outputs.UNINSTALL_URL}}
TRACKING_ID=${{needs.EnvSetup.outputs.TRACKING_ID}}
FUNCTION_URL=${{needs.EnvSetup.outputs.FUNCTION_URL}}
DISCORD_CLIENT_ID=${{needs.EnvSetup.outputs.DISCORD_CLIENT_ID}}
OAUTH_CLIENT_ID=${{needs.EnvSetup.outputs.OAUTH_CLIENT_ID}}
PUBLIC_URL=${{needs.EnvSetup.outputs.PUBLIC_URL}}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ jobs:
api_location: '' # Api source code path - optional
skip_app_build: true
skip_api_build: true
production_branch: 'main'
output_location: '' # Built app content directory - optional
###### End of Repository/Build Configurations ######

Expand Down
2 changes: 1 addition & 1 deletion apps/acf-extension/src/background/google-oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class GoogleOauth2 {
const headers = await this.getHeaders([GOOGLE_SCOPES.PROFILE, scope]);
const google = await this.getCurrentUser(headers);
const googleScopes = await this.#getScopes();
return { googleScopes, google };
return { [LOCAL_STORAGE_KEY.GOOGLE_SCOPES]: googleScopes, [LOCAL_STORAGE_KEY.GOOGLE]: google };
} catch (error) {
if (error instanceof Error) {
NotificationHandler.notify(NOTIFICATIONS_ID, NOTIFICATIONS_TITLE, error.message);
Expand Down
2 changes: 1 addition & 1 deletion apps/acf-extension/src/background/google-sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type GoogleSheetsType = {
};

export default class GoogleSheets extends GoogleOauth2 {
scopes = [GOOGLE_SCOPES.DRIVE, GOOGLE_SCOPES.PROFILE];
scopes = [GOOGLE_SCOPES.SHEETS, GOOGLE_SCOPES.PROFILE];
async getSheets({ spreadsheetId, ranges }: GoogleSheetsType) {
let response;
if (!spreadsheetId || !ranges) {
Expand Down
7 changes: 3 additions & 4 deletions apps/acf-extension/src/content_scripts/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Common from './common';
import Value from './util/value';
import Events from './events';
import { wait } from './util';
import { Sheets } from './util/google-sheets';

const LOGGER_LETTER = 'Action';

Expand All @@ -20,15 +19,15 @@ const ActionProcessor = (() => {
return ACTION_STATUS.DONE;
};

const start = async (action: Action, batchRepeat: number, sheets?: Sheets) => {
const elementFinder = action.elementFinder.replaceAll('<batchRepeat>', String(batchRepeat));
const start = async (action: Action) => {
const elementFinder = await Value.getValue(action.elementFinder);
const elements = await Common.start(elementFinder, action.settings);
if (!elements) {
return ACTION_STATUS.SKIPPED;
} else if (typeof elements === 'number') {
return elements;
}
const value = action.value ? await Value.getValue(action.value, batchRepeat, sheets) : action.value;
const value = action.value ? await Value.getValue(action.value) : action.value;
await Events.check(elements, value);
return await repeatFunc(elements, action.repeat, action.repeatInterval, value);
};
Expand Down
16 changes: 8 additions & 8 deletions apps/acf-extension/src/content_scripts/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import Statement from './statement';
import { wait } from './util';
import AddonProcessor from './addon';
import Common from './common';
import { Sheets } from './util/google-sheets';
import { ConfigError } from './error';
import SettingsStorage from './store/settings-storage';
import { Logger } from '@dhruv-techapps/core-common';

const LOGGER_LETTER = 'Action';

const Actions = (() => {
const setBadge = (batchRepeat: number, i: number) => {
const setBadge = (i: number) => {
ActionService.setBadgeBackgroundColor(chrome.runtime.id, { color: [25, 135, 84, 1] });
ActionService.setBadgeText(chrome.runtime.id, { text: `${batchRepeat}-${i}` });
ActionService.setTitle(chrome.runtime.id, { title: `Batch:${batchRepeat} Action:${i}` });
ActionService.setBadgeText(chrome.runtime.id, { text: `${window.__batchRepeat}-${i}` });
ActionService.setTitle(chrome.runtime.id, { title: `Batch:${window.__batchRepeat} Action:${i}` });
};

const checkStatement = async (actions: Array<Action>, action: Action) => {
Expand All @@ -37,24 +36,25 @@ const Actions = (() => {
});
}
};
const start = async (actions: Array<Action>, batchRepeat: number, sheets?: Sheets) => {
const start = async (actions: Array<Action>, batchRepeat: number) => {
window.__batchRepeat = batchRepeat;
let i = 0;
while (i < actions.length) {
const action = actions[i];
console.group(`${LOGGER_LETTER} #${action.name || i}`);
if (!action.elementFinder) {
throw new ConfigError('Element Finder is blank', 'Configuration Action');
}
setBadge(batchRepeat, i);
setBadge(i);
const statementResult = await checkStatement(actions, action);
if (statementResult === true) {
await wait(action.initWait, `${LOGGER_LETTER} initWait`);
const addonResult = await AddonProcessor.check(batchRepeat, action.addon, action.settings);
const addonResult = await AddonProcessor.check(action.addon, action.settings);
if (typeof addonResult === 'number') {
i = Number(addonResult) - 1;
Logger.colorInfo('Goto', Number(addonResult) + 1);
} else if (addonResult) {
const status = await ActionProcessor.start(action, batchRepeat, sheets);
const status = await ActionProcessor.start(action);
if (typeof status === 'number') {
i = Number(status) - 1;
Logger.colorInfo('Goto', Number(status) + 1);
Expand Down
31 changes: 15 additions & 16 deletions apps/acf-extension/src/content_scripts/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@ import { wait } from './util';
import { ConfigError, SystemError } from './error';
import Common from './common';
import { RADIO_CHECKBOX_NODE_NAME } from '../common/constant';
import Value from './util/value';

const LOGGER_LETTER = 'Addon';

type AddonType = { nodeValue: string | boolean } & Addon;

const AddonProcessor = (() => {
const recheckFunc = async (
{ nodeValue, elementFinder, value, condition, recheck, recheckInterval, recheckOption, recheckGoto, valueExtractor, valueExtractorFlags }: AddonType,
batchRepeat: number,
settings?: ActionSettings
): Promise<number | boolean> => {
const recheckFunc = async ({ nodeValue, elementFinder, value, condition, recheck, recheckOption, ...props }: AddonType, settings?: ActionSettings): Promise<number | boolean> => {
if (recheck !== undefined) {
if (recheck > 0 || recheck < -1) {
recheck -= 1;
ActionService.setBadgeBackgroundColor(chrome.runtime.id, { color: [13, 202, 240, 1] });
ActionService.setBadgeText(chrome.runtime.id, { text: 'Recheck' });
await wait(recheckInterval, `${LOGGER_LETTER} Recheck`, recheck, '<interval>');
await wait(props.recheckInterval, `${LOGGER_LETTER} Recheck`, recheck, '<interval>');
// eslint-disable-next-line no-use-before-define
return await start({ elementFinder, value, condition, recheck, recheckInterval, recheckOption, valueExtractor, valueExtractorFlags }, batchRepeat, settings);
return await start({ elementFinder, value, condition, recheck, recheckOption, ...props }, settings);
}
}
// eslint-disable-next-line no-console
Expand All @@ -38,8 +35,8 @@ const AddonProcessor = (() => {
}
} else if (recheckOption === RECHECK_OPTIONS.STOP) {
throw new ConfigError(`'${nodeValue}' ${condition} '${value}'`, "Addon didn't matched");
} else if (recheckOption === RECHECK_OPTIONS.GOTO && recheckGoto) {
return recheckGoto;
} else if (recheckOption === RECHECK_OPTIONS.GOTO && props.recheckGoto) {
return props.recheckGoto;
}
Logger.colorInfo('RecheckOption', recheckOption);
return false;
Expand Down Expand Up @@ -114,14 +111,14 @@ const AddonProcessor = (() => {
}
};

const start = async ({ elementFinder, value, condition, valueExtractor, valueExtractorFlags, ...props }: Addon, batchRepeat: number, settings?: ActionSettings) => {
const start = async ({ elementFinder, value, condition, valueExtractor, valueExtractorFlags, ...props }: Addon, settings?: ActionSettings) => {
try {
Logger.colorDebug('Start', { elementFinder, value, condition, valueExtractor, valueExtractorFlags });
let nodeValue;
if (/^Func::/gi.test(elementFinder)) {
nodeValue = await Common.sandboxEval(elementFinder.replace(/^Func::/gi, ''));
} else {
elementFinder = elementFinder.replaceAll('<batchRepeat>', String(batchRepeat));
elementFinder = await Value.getValue(elementFinder);
const elements = await Common.start(elementFinder, settings);
if (typeof elements === 'number') {
return elements;
Expand All @@ -131,10 +128,9 @@ const AddonProcessor = (() => {
}
}
if (nodeValue !== undefined) {
value = value.replaceAll('<batchRepeat>', String(batchRepeat));
let result: boolean | number = compare(nodeValue, condition, value);
if (!result) {
result = await recheckFunc({ nodeValue, elementFinder, value, condition, valueExtractor, valueExtractorFlags, ...props }, batchRepeat, settings);
result = await recheckFunc({ nodeValue, elementFinder, value, condition, valueExtractor, valueExtractorFlags, ...props }, settings);
}
Logger.colorDebug('Compare Result', result);
console.groupEnd();
Expand All @@ -147,12 +143,15 @@ const AddonProcessor = (() => {
throw error;
}
};
const check = async (batchRepeat: number, addon?: Addon, actionSettings?: ActionSettings) => {
const check = async (addon?: Addon, actionSettings?: ActionSettings) => {
if (addon) {
const { elementFinder, value, condition, ...props } = addon;
let { value } = addon;
const { elementFinder, condition, ...props } = addon;
if (elementFinder && value && condition) {
console.groupCollapsed(LOGGER_LETTER);
return await start({ elementFinder, value, condition, ...props }, batchRepeat, actionSettings);

value = await Value.getValue(value);
return await start({ ...props, elementFinder, value, condition }, actionSettings);
}
}
return true;
Expand Down
13 changes: 6 additions & 7 deletions apps/acf-extension/src/content_scripts/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { NotificationsService } from '@dhruv-techapps/core-service';
import Actions from './actions';
import { wait } from './util';
import Common from './common';
import { Sheets } from './util/google-sheets';
import SettingsStorage from './store/settings-storage';

const LOGGER_LETTER = 'Batch';
Expand All @@ -19,15 +18,15 @@ const BatchProcessor = (() => {
}
};

const checkRepeat = async (actions: Array<Action>, batch: Batch, sheets?: Sheets) => {
const checkRepeat = async (actions: Array<Action>, batch: Batch) => {
if (batch.repeat) {
if (batch.repeat > 0) {
for (let i = 0; i < batch.repeat; i += 1) {
console.group(`${LOGGER_LETTER} #${i + 1}`);
if (batch?.repeatInterval) {
await wait(batch?.repeatInterval, `${LOGGER_LETTER} Repeat`, batch.repeat, '<interval>');
}
await Actions.start(actions, i + 1, sheets);
await Actions.start(actions, i + 1);
const { notifications } = await new SettingsStorage().getSettings();
if (notifications?.onBatch) {
NotificationsService.create(chrome.runtime.id, {
Expand All @@ -47,23 +46,23 @@ const BatchProcessor = (() => {
if (batch?.repeatInterval) {
await wait(batch?.repeatInterval, `${LOGGER_LETTER} Repeat`, '∞', '<interval>');
}
await Actions.start(actions, i, sheets);
await Actions.start(actions, i);
i += 1;
}
}
}
};

const start = async (actions: Array<Action>, batch?: Batch, sheets?: Sheets) => {
const start = async (actions: Array<Action>, batch?: Batch) => {
try {
console.group(`${LOGGER_LETTER} #0`);
await Actions.start(actions, 0, sheets);
await Actions.start(actions, 0);
console.groupEnd();
if (batch) {
if (batch.refresh) {
refresh();
} else {
await checkRepeat(actions, batch, sheets);
await checkRepeat(actions, batch);
}
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions apps/acf-extension/src/content_scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const ConfigProcessor = (() => {

const start = async (config: Configuration) => {
Logger.colorDebug('Config Start');
const sheets = await new GoogleSheets().getValues(config);
await new GoogleSheets().getValues(config);
try {
await BatchProcessor.start(config.actions, config.batch, sheets);
await BatchProcessor.start(config.actions, config.batch);
setBadgeDone();
const { notifications } = await new SettingsStorage().getSettings();
if (notifications) {
Expand Down
8 changes: 8 additions & 0 deletions apps/acf-extension/src/content_scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { Logger, LoggerColor } from '@dhruv-techapps/core-common';
import ConfigProcessor from './config';
import Session from './util/session';
import ConfigStorage from './store/config-storage';
import { Sheets } from './util/google-sheets';

declare global {
interface Window {
__batchRepeat: number;
__sheets?: Sheets;
}
}

async function loadConfig(loadType: LOAD_TYPES) {
try {
Expand Down
Loading

0 comments on commit b65ce06

Please sign in to comment.