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
34 changes: 17 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
"source.fixAll.eslint": "explicit",
"source.organizeImports": "always"
},
"editor.rename.enablePreview": false,

// a macro to rename a variable to _variable
"macros": {
"rename_": [
{
"javascript": [
"const ed = vscode.window.activeTextEditor;",
"if (!ed) return;",
"const ed = vscode.window.activeTextEditor; if (!ed) return;",
"const pos = ed.selection.active;",
"const rng = ed.document.getWordRangeAtPosition(pos);",
"if (!rng) return;",
"const oldName = ed.document.getText(rng);",
"// if it already starts with '_', do nothing (remove this guard if you always want to re-run)",
"if (oldName.startsWith('_')) return;",
"const rng = ed.document.getWordRangeAtPosition(pos); if (!rng) return;",
"const oldName = ed.document.getText(rng); if (oldName.startsWith('_')) return;",
"const newName = '_' + oldName;",
"// Ask VS Code for a rename edit at this position",
"const edit = await vscode.commands.executeCommand(",
" 'vscode.executeDocumentRenameProvider',",
" ed.document.uri,",
" pos,",
" newName",
");",
"if (edit) await vscode.workspace.applyEdit(edit);",
"await new Promise(resolve => setTimeout(resolve, 100));",
"await vscode.commands.executeCommand('workbench.action.files.saveAll');"
"const edit = await vscode.commands.executeCommand('vscode.executeDocumentRenameProvider', ed.document.uri, pos, newName);",
"if (!edit) return;",
"await vscode.workspace.applyEdit(edit);",
"(async () => {",
" for (let attempt = 0; attempt < 5; attempt++) {",
" let remaining = 0;",
" for (const doc of vscode.workspace.textDocuments) {",
" try { if (doc.isDirty) { remaining++; await doc.save(); } } catch (_) {}",
" }",
" if (remaining === 0) break;",
" await new Promise(r => setTimeout(r, 80));",
" }",
"})();"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion __test__/support/environment/TestEnvironmentHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const setupSubModelStore = async ({
pushModel.web_p256 = web_p256;
}
await setPushToken(pushModel.token);
OneSignal._coreDirector._subscriptionModelStore.replaceAll(
OneSignal._coreDirector._subscriptionModelStore._replaceAll(
[pushModel],
ModelChangeTags.NO_PROPAGATE,
);
Expand Down
10 changes: 5 additions & 5 deletions __test__/support/helpers/executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ export class SomeOperation extends Operation {
super('some-operation');
}

get applyToRecordId() {
get _applyToRecordId() {
return '';
}

get createComparisonKey() {
get _createComparisonKey() {
return '';
}

get modifyComparisonKey() {
get _modifyComparisonKey() {
return '';
}

get groupComparisonType() {
get _groupComparisonType() {
return GroupComparisonType.CREATE;
}

get canStartExecute() {
get _canStartExecute() {
return true;
}
}
6 changes: 3 additions & 3 deletions __test__/support/helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const setupIdentityModel = async (
onesignalID: string = ONESIGNAL_ID,
) => {
const newIdentityModel = new IdentityModel();
newIdentityModel.onesignalId = onesignalID;
newIdentityModel._onesignalId = onesignalID;
OneSignal._coreDirector._identityModelStore.replace(
newIdentityModel,
ModelChangeTags.NO_PROPAGATE,
Expand All @@ -77,7 +77,7 @@ export const setupPropertiesModel = async (
onesignalID: string = ONESIGNAL_ID,
) => {
const newPropertiesModel = new PropertiesModel();
newPropertiesModel.onesignalId = onesignalID;
newPropertiesModel._onesignalId = onesignalID;
OneSignal._coreDirector._propertiesModelStore.replace(
newPropertiesModel,
ModelChangeTags.NO_PROPAGATE,
Expand Down Expand Up @@ -126,7 +126,7 @@ export const setupSubscriptionModel = async (
const subscriptionModel = new SubscriptionModel();
subscriptionModel.id = id || '';
subscriptionModel.token = token || '';
OneSignal._coreDirector._subscriptionModelStore.replaceAll(
OneSignal._coreDirector._subscriptionModelStore._replaceAll(
[subscriptionModel],
ModelChangeTags.NO_PROPAGATE,
);
Expand Down
6 changes: 3 additions & 3 deletions __test__/unit/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('User tests', () => {

const tagsSample = { key1: 'value1' };
const propModel = OneSignal._coreDirector._getPropertiesModel();
propModel.tags = tagsSample;
propModel._tags = tagsSample;

const user = User._createOrGetInstance();
const tags = user.getTags();
Expand All @@ -42,7 +42,7 @@ describe('User tests', () => {
const languageSample = 'fr';

const propModel = OneSignal._coreDirector._getPropertiesModel();
propModel.language = languageSample;
propModel._language = languageSample;

const user = User._createOrGetInstance();
const language = user.getLanguage();
Expand All @@ -59,6 +59,6 @@ describe('User tests', () => {
user.setLanguage(languageSample);

const propModel = OneSignal._coreDirector._getPropertiesModel();
expect(propModel.language).toBe(languageSample);
expect(propModel._language).toBe(languageSample);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
{
"path": "./build/releases/OneSignalSDK.page.es6.js",
"limit": "47.886 kB",
"limit": "47.565 kB",
"gzip": true
},
{
Expand Down
6 changes: 2 additions & 4 deletions src/core/CoreModuleDirector.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import FuturePushSubscriptionRecord from 'src/page/userModel/FuturePushSubscriptionRecord';
import { getPushToken } from 'src/shared/database/subscription';
import { isPushSubscriptionType } from 'src/shared/helpers/subscription';
import { IDManager } from 'src/shared/managers/IDManager';
import {
SubscriptionChannel,
SubscriptionType,
} from 'src/shared/subscriptions/constants';
import type { SubscriptionChannelValue } from 'src/shared/subscriptions/types';
import { logMethodCall } from 'src/shared/utils/utils';
import SubscriptionHelper from '../../src/shared/helpers/SubscriptionHelper';
import MainHelper from '../shared/helpers/MainHelper';
import { RawPushSubscription } from '../shared/models/RawPushSubscription';
import CoreModule from './CoreModule';
Expand Down Expand Up @@ -108,9 +108,7 @@ export class CoreModuleDirector {
public _getAllPushSubscriptionModels(): SubscriptionModel[] {
logMethodCall('CoreModuleDirector.getAllPushSubscriptionModels');
const subscriptions = this._core._subscriptionModelStore.list();
return subscriptions.filter((s) =>
SubscriptionHelper.isPushSubscriptionType(s.type),
);
return subscriptions.filter((s) => isPushSubscriptionType(s.type));
}

async _getPushSubscriptionModelByCurrentToken(): Promise<
Expand Down
4 changes: 2 additions & 2 deletions src/core/controllers/CustomEventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class CustomEventController implements ICustomEventController {

const op = new TrackCustomEventOperation({
appId,
onesignalId: identityModel.onesignalId,
externalId: identityModel.externalId,
onesignalId: identityModel._onesignalId,
externalId: identityModel._externalId,
timestamp: new Date().toISOString(),
event,
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/executors/CustomEventOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export class CustomEventsOperationExecutor implements IOperationExecutor {
}

const response = await sendCustomEvent(
{ appId: operation.appId },
{ appId: operation._appId },
{
name: operation.event.name,
onesignal_id: operation.onesignalId,
onesignal_id: operation._onesignalId,
external_id: operation.externalId,
timestamp: operation.timestamp,
payload: {
Expand Down
16 changes: 8 additions & 8 deletions src/core/executors/IdentityOperationExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('IdentityOperationExecutor', () => {
);
getRebuildOpsSpy = vi.spyOn(
rebuildUserService,
'getRebuildOperationsIfCurrentUser',
'_getRebuildOperationsIfCurrentUser',
);
});

Expand Down Expand Up @@ -158,20 +158,20 @@ describe('IdentityOperationExecutor', () => {
expect(res5.retryAfterSeconds).toBeUndefined();

// with rebuild ops
identityModelStore.model.onesignalId = ONESIGNAL_ID;
identityModelStore.model._onesignalId = ONESIGNAL_ID;
const res7 = await executor._execute(ops);
expect(res7.result).toBe(ExecutionResult.FAIL_RETRY);
expect(res7.retryAfterSeconds).toBeUndefined();
expect(res7.operations).toMatchObject([
{
name: 'login-user',
appId: APP_ID,
onesignalId: ONESIGNAL_ID,
_name: 'login-user',
_appId: APP_ID,
_onesignalId: ONESIGNAL_ID,
},
{
name: 'refresh-user',
appId: APP_ID,
onesignalId: ONESIGNAL_ID,
_name: 'refresh-user',
_appId: APP_ID,
_onesignalId: ONESIGNAL_ID,
},
]);

Expand Down
19 changes: 10 additions & 9 deletions src/core/executors/IdentityOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,27 @@ export class IdentityOperationExecutor implements IOperationExecutor {
const isSetAlias = lastOperation instanceof SetAliasOperation;
const request = isSetAlias
? addAlias(
{ appId: lastOperation.appId },
{ appId: lastOperation._appId },
{
label: IdentityConstants.ONESIGNAL_ID,
id: lastOperation.onesignalId,
id: lastOperation._onesignalId,
},
{ [lastOperation.label]: lastOperation.value },
)
: deleteAlias(
{ appId: lastOperation.appId },
{ appId: lastOperation._appId },
{
label: IdentityConstants.ONESIGNAL_ID,
id: lastOperation.onesignalId,
id: lastOperation._onesignalId,
},
lastOperation.label,
);

const { ok, status, retryAfterSeconds } = await request;
if (ok) {
if (
this._identityModelStore.model.onesignalId === lastOperation.onesignalId
this._identityModelStore.model._onesignalId ===
lastOperation._onesignalId
) {
this._identityModelStore.model._setProperty(
lastOperation.label,
Expand Down Expand Up @@ -136,7 +137,7 @@ export class IdentityOperationExecutor implements IOperationExecutor {
if (
status === 404 &&
this._newRecordState._isInMissingRetryWindow(
lastOperation.onesignalId,
lastOperation._onesignalId,
)
)
return new ExecutionResponse(
Expand All @@ -146,9 +147,9 @@ export class IdentityOperationExecutor implements IOperationExecutor {

if (isSetAlias) {
const rebuildOps =
await this._buildUserService.getRebuildOperationsIfCurrentUser(
lastOperation.appId,
lastOperation.onesignalId,
await this._buildUserService._getRebuildOperationsIfCurrentUser(
lastOperation._appId,
lastOperation._onesignalId,
);

if (rebuildOps == null)
Expand Down
4 changes: 2 additions & 2 deletions src/core/executors/LoginUserOperationExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('LoginUserOperationExecutor', () => {
const ops = [someOp];
const result = executor._execute(ops);
await expect(() => result).rejects.toThrow(
`Unrecognized operation: ${someOp.name}`,
`Unrecognized operation: ${someOp._name}`,
);
});

Expand All @@ -125,7 +125,7 @@ describe('LoginUserOperationExecutor', () => {
const ops2 = [loginOp, transferSubOp, someOp];
const res2 = executor._execute(ops2);
await expect(res2).rejects.toThrow(
`Unrecognized operation: ${someOp.name}`,
`Unrecognized operation: ${someOp._name}`,
);
});

Expand Down
Loading
Loading