Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __test__/support/helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const setupSubscriptionModel = async (
*/
export const setupLoadStylesheet = async () => {
vi.spyOn(
OneSignal.context.dynamicResourceLoader,
OneSignal.context._dynamicResourceLoader,
'loadSdkStylesheet',
).mockResolvedValue(ResourceLoadState.Loaded);
};
Expand Down
4 changes: 2 additions & 2 deletions __test__/unit/push/registerForPush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Register for push', () => {
expect(spy).not.toHaveBeenCalled();
OneSignalEvent.trigger(OneSignal.EVENTS.SDK_INITIALIZED);
await promise;
expect(Log.error).toHaveBeenCalled();
expect(Log._error).toHaveBeenCalled();
expect(OneSignal.initialized).toBe(true);
expect(spy).toHaveBeenCalledTimes(1);
});
Expand All @@ -42,7 +42,7 @@ describe('Register for push', () => {
(global as any).OneSignal._initCalled = false;

await InitHelper.registerForPushNotifications();
expect(Log.error).toHaveBeenCalled();
expect(Log._error).toHaveBeenCalled();
expect(spy).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { createPushSub } from '__test__/support/environment/TestEnvironmentHelpe
import { MockServiceWorker } from '__test__/support/mocks/MockServiceWorker';
import { clearStore, db, getOptionsValue } from 'src/shared/database/client';
import { setAppState as setDBAppState } from 'src/shared/database/config';
import type { AppState } from 'src/shared/database/types';
import * as PermissionUtils from 'src/shared/helpers/permissions';
import Emitter from 'src/shared/libraries/Emitter';
import { checkAndTriggerSubscriptionChanged } from 'src/shared/listeners';
import { AppState } from 'src/shared/models/AppState';
import MainHelper from '../../../src/shared/helpers/MainHelper';

vi.mock('src/shared/libraries/Log');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
},
{
"path": "./build/releases/OneSignalSDK.page.es6.js",
"limit": "52.153 kB",
"limit": "51.8 kB",
"gzip": true
},
{
"path": "./build/releases/OneSignalSDK.sw.js",
"limit": "14.564 kB",
"limit": "13.96 kB",
"gzip": true
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/CoreModuleDirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CoreModuleDirector {
});
const model = new SubscriptionModel();
model.initializeFromJson(
new FuturePushSubscriptionRecord(rawPushSubscription).serialize(),
new FuturePushSubscriptionRecord(rawPushSubscription)._serialize(),
);
model.id = IDManager._createLocalId();

Expand Down
2 changes: 1 addition & 1 deletion src/core/executors/CustomEventOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class CustomEventsOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(
Log._debug(
`CustomEventsOperationExecutor(operations: ${JSON.stringify(
operations,
)})`,
Expand Down
2 changes: 1 addition & 1 deletion src/core/executors/IdentityOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class IdentityOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(
Log._debug(
`IdentityOperationExecutor(operations: ${JSON.stringify(operations)})`,
);

Expand Down
6 changes: 3 additions & 3 deletions src/core/executors/LoginUserOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(
Log._debug(
`LoginUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
);
const startingOp = operations[0];
Expand Down Expand Up @@ -124,11 +124,11 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
}

case ExecutionResult.FAIL_CONFLICT:
Log.debug(`Handling 409 for externalId: ${loginUserOp.externalId}`);
Log._debug(`Handling 409 for externalId: ${loginUserOp.externalId}`);
return this.createUser(loginUserOp, operations);

case ExecutionResult.FAIL_NORETRY:
Log.error(
Log._error(
`Recovering from SetAlias failure for externalId: ${loginUserOp.externalId}`,
);
return this.createUser(loginUserOp, operations);
Expand Down
2 changes: 1 addition & 1 deletion src/core/executors/RefreshUserOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(
Log._debug(
`RefreshUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
);

Expand Down
2 changes: 1 addition & 1 deletion src/core/executors/SubscriptionOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class SubscriptionOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(`SubscriptionOperationExecutor(operations: ${operations})`);
Log._debug(`SubscriptionOperationExecutor(operations: ${operations})`);

const startingOp = operations[0];
if (startingOp instanceof CreateSubscriptionOperation)
Expand Down
2 changes: 1 addition & 1 deletion src/core/executors/UpdateUserOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class UpdateUserOperationExecutor implements IOperationExecutor {
}

async execute(operations: Operation[]): Promise<ExecutionResponse> {
Log.debug(`UpdateUserOperationExecutor(operation: ${operations})`);
Log._debug(`UpdateUserOperationExecutor(operation: ${operations})`);

const { appId, onesignalId, propertiesObject, refreshDeviceMetadata } =
this.processOperations(operations);
Expand Down
6 changes: 3 additions & 3 deletions src/core/modelRepo/OperationModelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class OperationModelStore extends ModelStore<Operation> {

create(jsonObject?: { name?: string } | null): Operation | null {
if (jsonObject === null) {
Log.error('null jsonObject sent to OperationModelStore.create');
Log._error('null jsonObject sent to OperationModelStore.create');
return null;
}

Expand Down Expand Up @@ -96,15 +96,15 @@ export class OperationModelStore extends ModelStore<Operation> {
} {
const operationName = object?.name;
if (!operationName) {
Log.error("jsonObject must have 'name' attribute");
Log._error("jsonObject must have 'name' attribute");
return false;
}

const excluded = new Set<string>([OPERATION_NAME.LOGIN_USER]);

// Must have onesignalId if it is not one of the excluded operations above
if (!object.onesignalId && !excluded.has(operationName)) {
Log.error(
Log._error(
`${operationName} jsonObject must have 'onesignalId' attribute`,
);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/operationRepo/OperationRepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { NewRecordsState } from './NewRecordsState';
import { OperationQueueItem, OperationRepo } from './OperationRepo';

vi.spyOn(Log, 'error').mockImplementation((msg) => {
vi.spyOn(Log, '_error').mockImplementation((msg) => {
if (typeof msg === 'string' && msg.includes('Operation execution failed'))
return '';
return msg;
Expand Down
24 changes: 12 additions & 12 deletions src/core/operationRepo/OperationRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}

public _containsInstanceOf<T extends Operation>(
type: new (...args: any[]) => T,

Check warning on line 86 in src/core/operationRepo/OperationRepo.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
): boolean {
return this.queue.some((item) => item.operation instanceof type);
}
Expand All @@ -96,11 +96,11 @@
public _pause(): void {
clearInterval(this._timerID);
this._timerID = undefined;
Log.debug('OperationRepo: Paused');
Log._debug('OperationRepo: Paused');
}

public enqueue(operation: Operation): void {
Log.debug(`OperationRepo.enqueue(operation: ${operation})`);
Log._debug(`OperationRepo.enqueue(operation: ${operation})`);

this._internalEnqueue(
new OperationQueueItem({
Expand All @@ -112,7 +112,7 @@
}

public async enqueueAndWait(operation: Operation): Promise<void> {
Log.debug(`OperationRepo.enqueueAndWaitoperation: ${operation})`);
Log._debug(`OperationRepo.enqueueAndWaitoperation: ${operation})`);

await new Promise((resolve) => {
this._internalEnqueue(
Expand All @@ -135,7 +135,7 @@
(item) => item.operation.modelId === queueItem.operation.modelId,
);
if (hasExisting) {
Log.debug(
Log._debug(
`OperationRepo: internalEnqueue - operation.modelId: ${queueItem.operation.modelId} already exists in the queue.`,
);
return;
Expand All @@ -157,7 +157,7 @@
let runningOps = false;

this._timerID = setInterval(async () => {
if (runningOps) return Log.debug('Operations in progress');
if (runningOps) return Log._debug('Operations in progress');

const ops = this._getNextOps(this._executeBucket);

Expand Down Expand Up @@ -186,7 +186,7 @@
const response = await executor.execute(operations);
const idTranslations = response.idTranslations;

Log.debug(`OperationRepo: execute response = ${response.result}`);
Log._debug(`OperationRepo: execute response = ${response.result}`);

// Handle ID translations
if (idTranslations) {
Expand All @@ -213,7 +213,7 @@
case ExecutionResult.FAIL_UNAUTHORIZED:
case ExecutionResult.FAIL_NORETRY:
case ExecutionResult.FAIL_CONFLICT:
Log.error(`Operation execution failed without retry: ${operations}`);
Log._error(`Operation execution failed without retry: ${operations}`);
ops.forEach((op) => {
this._operationModelStore.remove(op.operation.modelId);
});
Expand All @@ -232,7 +232,7 @@
break;

case ExecutionResult.FAIL_RETRY:
Log.error(`Operation execution failed, retrying: ${operations}`);
Log._error(`Operation execution failed, retrying: ${operations}`);
// Add back all operations to front of queue
ops.toReversed().forEach((op) => {
removeOpFromDB(op.operation);
Expand All @@ -245,7 +245,7 @@
break;

case ExecutionResult.FAIL_PAUSE_OPREPO:
Log.error(
Log._error(
`Operation execution failed with eventual retry, pausing the operation repo: ${operations}`,
);
this._pause();
Expand Down Expand Up @@ -277,7 +277,7 @@
await delay(OP_REPO_POST_CREATE_DELAY);
}
} catch (e) {
Log.error(`Error attempting to execute operation: ${ops}`, e);
Log._error(`Error attempting to execute operation: ${ops}`, e);

// On failure remove operations from store
ops.forEach((op) => {
Expand All @@ -291,14 +291,14 @@
retries: number,
retryAfterSeconds?: number,
): Promise<void> {
Log.debug(`retryAfterSeconds: ${retryAfterSeconds}`);
Log._debug(`retryAfterSeconds: ${retryAfterSeconds}`);
const retryAfterSecondsMs = (retryAfterSeconds || 0) * 1000;
const delayForOnRetries = retries * OP_REPO_DEFAULT_FAIL_RETRY_BACKOFF;
const delayFor = Math.max(delayForOnRetries, retryAfterSecondsMs);

if (delayFor < 1) return;

Log.error(`Operations being delay for: ${delayFor} ms`);
Log._error(`Operations being delay for: ${delayFor} ms`);
await delay(delayFor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/entries/pageSdkInit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('pageSdkInit', () => {
});

test('can process deferred items long after page init', async () => {
vi.spyOn(Log, 'error').mockImplementation(() => '');
vi.spyOn(Log, '_error').mockImplementation(() => '');
await import('./pageSdkInit');
const initSpy = vi.spyOn(window.OneSignal, 'init');

Expand Down
6 changes: 3 additions & 3 deletions src/entries/pageSdkInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ async function processOneSignalDeferredArray(
await OneSignal.push(item);
} catch (e) {
// Catch and log error here so other elements still run
Log.error(e);
Log._error(e);
}
}
}

function onesignalSdkInit() {
incrementSdkLoadCount();
if (getSdkLoadCount() > 1) {
Log.warn(
Log._warn(
`OneSignal: The web push SDK is included more than once. For optimal performance, please include our ` +
`SDK only once on your page.`,
);
Log.debug(
Log._debug(
`OneSignal: Exiting from SDK initialization to prevent double-initialization errors. ` +
`Occurred ${getSdkLoadCount()} times.`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/entries/pageSdkInit2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('pageSdkInit 2', () => {
response: emailSubModel,
});

const errorSpy = vi.spyOn(Log, 'error').mockImplementation(() => '');
const errorSpy = vi.spyOn(Log, '_error').mockImplementation(() => '');

// wait for init so it can initialize user namespace otherwise it won't be available for addEmail
window.OneSignalDeferred = [];
Expand Down
3 changes: 2 additions & 1 deletion src/entries/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import { OneSignalServiceWorker } from '../sw/serviceWorker/ServiceWorker';

// Expose this class to the global scope
(self as any).OneSignal = OneSignalServiceWorker;
declare const self: ServiceWorkerGlobalScope;
self.OneSignalWorker = OneSignalServiceWorker;
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare global {
interface WorkerGlobalScope {
OneSignal: _OneSignal;
OneSignalWorker: typeof import('./sw/serviceWorker/ServiceWorker').OneSignalServiceWorker;
workerMessenger: import('./sw/serviceWorker/WorkerMessengerSW').WorkerMessengerSW;
_workerMessenger: import('./sw/serviceWorker/WorkerMessengerSW').WorkerMessengerSW;
shouldLog: boolean;
}
}
2 changes: 1 addition & 1 deletion src/onesignal/DebugNamesapce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default class DebugNamespace {
* @param logLevel - string
*/
setLogLevel(logLevel: string) {
Log.setLevel(logLevel);
Log._setLevel(logLevel);
}
}
2 changes: 1 addition & 1 deletion src/onesignal/NotificationsNamespace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('should set the default title', async () => {
);
});

const warnSpy = vi.spyOn(Log, 'warn');
const warnSpy = vi.spyOn(Log, '_warn');
describe('Consent Required', () => {
beforeEach(() => {
OneSignal.setConsentRequired(true);
Expand Down
6 changes: 3 additions & 3 deletions src/onesignal/OneSignal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,9 @@
writable: true,
});

vi.spyOn(Log, 'error').mockImplementation(() => '');
const debugSpy = vi.spyOn(Log, 'debug');
const warnSpy = vi.spyOn(Log, 'warn');
vi.spyOn(Log, '_error').mockImplementation(() => '');
const debugSpy = vi.spyOn(Log, '_debug');
const warnSpy = vi.spyOn(Log, '_warn');

const getPropertiesItem = async () => (await db.getAll('properties'))[0];

Expand All @@ -1201,4 +1201,4 @@
);

const showLocalNotificationSpy = vi.spyOn(MainHelper, 'showLocalNotification');
showLocalNotificationSpy.mockImplementation(async () => {});

Check failure on line 1204 in src/onesignal/OneSignal.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected empty async arrow function
Loading
Loading