From 7602f41723c54589ba2ecb04a88c0d44334d16b8 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 20 Sep 2024 23:13:26 +0000 Subject: [PATCH 1/4] move strictFunctionTypes=true from IDE to compile No code changes were needed to move strictFunctionTypes=true from a IDE only setting to a compile settings. --- build/config/tsconfig.base.json | 1 + tsconfig.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/build/config/tsconfig.base.json b/build/config/tsconfig.base.json index 0cec68380..b34ca3dea 100644 --- a/build/config/tsconfig.base.json +++ b/build/config/tsconfig.base.json @@ -27,6 +27,7 @@ "sourceRoot": "../..", "rootDir": "../..", "esModuleInterop": true, + "strictFunctionTypes": true, "baseUrl": "../..", "types": [ "node" diff --git a/tsconfig.json b/tsconfig.json index 7e7f5b119..940a29ae7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ "noUnusedLocals": true, "noUnusedParameters": true, "strictPropertyInitialization": true, - "strictFunctionTypes": true, "baseUrl": ".", "types": ["jest", "node"] }, From aec283791e3081c2d2937e3fc2d607cc52f14572 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 20 Sep 2024 23:18:39 +0000 Subject: [PATCH 2/4] move noUnusedLocals=true from IDE to compile Adjusted a few files that didn't follow this rule to get it to compile. --- build/config/tsconfig.base.json | 2 +- src/page/bell/Bell.ts | 4 +--- src/page/bell/Dialog.ts | 2 -- src/page/managers/PromptsManager.ts | 1 - src/shared/helpers/EventHelper.ts | 1 - src/shared/utils/utils.ts | 1 - tsconfig.json | 1 - 7 files changed, 2 insertions(+), 10 deletions(-) diff --git a/build/config/tsconfig.base.json b/build/config/tsconfig.base.json index b34ca3dea..c5f767701 100644 --- a/build/config/tsconfig.base.json +++ b/build/config/tsconfig.base.json @@ -8,7 +8,7 @@ "noImplicitAny": false, "noImplicitReturns": true, "noImplicitThis": true, - "noUnusedLocals": false, + "noUnusedLocals": true, "noUnusedParameters": false, "allowSyntheticDefaultImports": true, "allowUnreachableCode": false, diff --git a/src/page/bell/Bell.ts b/src/page/bell/Bell.ts index a03dd3c8e..5c9ed3cb2 100755 --- a/src/page/bell/Bell.ts +++ b/src/page/bell/Bell.ts @@ -494,9 +494,7 @@ export default class Bell { const isPushEnabled = await OneSignal.context.subscriptionManager.isPushNotificationsEnabled(); - const doNotPrompt = DismissHelper.wasPromptOfTypeDismissed( - DismissPrompt.Push, - ); + DismissHelper.wasPromptOfTypeDismissed(DismissPrompt.Push); // Resize to small instead of specified size if enabled, otherwise there's a jerking motion // where the bell, at a different size than small, jerks sideways to go from large -> small or medium -> small diff --git a/src/page/bell/Dialog.ts b/src/page/bell/Dialog.ts index 02178197f..4b50099aa 100755 --- a/src/page/bell/Dialog.ts +++ b/src/page/bell/Dialog.ts @@ -1,5 +1,3 @@ -import bowser from 'bowser'; - import OneSignalEvent from '../../shared/services/OneSignalEvent'; import SdkEnvironment from '../../shared/managers/SdkEnvironment'; import { diff --git a/src/page/managers/PromptsManager.ts b/src/page/managers/PromptsManager.ts index 3870fbb92..3fdc8f290 100644 --- a/src/page/managers/PromptsManager.ts +++ b/src/page/managers/PromptsManager.ts @@ -6,7 +6,6 @@ import { } from '../../shared/config/constants'; import { DismissHelper } from '../../shared/helpers/DismissHelper'; import InitHelper from '../../shared/helpers/InitHelper'; -import MainHelper from '../../shared/helpers/MainHelper'; import PromptsHelper from '../../shared/helpers/PromptsHelper'; import Log from '../../shared/libraries/Log'; import { diff --git a/src/shared/helpers/EventHelper.ts b/src/shared/helpers/EventHelper.ts index f5dded02a..ce45796a3 100755 --- a/src/shared/helpers/EventHelper.ts +++ b/src/shared/helpers/EventHelper.ts @@ -1,4 +1,3 @@ -import OneSignalApiShared from '../api/OneSignalApiShared'; import Log from '../libraries/Log'; import { CustomLinkManager } from '../managers/CustomLinkManager'; import { ContextSWInterface } from '../models/ContextSW'; diff --git a/src/shared/utils/utils.ts b/src/shared/utils/utils.ts index 74a252a0e..85dba386c 100755 --- a/src/shared/utils/utils.ts +++ b/src/shared/utils/utils.ts @@ -1,6 +1,5 @@ import SdkEnvironment from '../managers/SdkEnvironment'; import { WindowEnvironmentKind } from '../models/WindowEnvironmentKind'; -import Database from '../services/Database'; import { OneSignalUtils } from './OneSignalUtils'; import { PermissionUtils } from './PermissionUtils'; import { Utils } from '../context/Utils'; diff --git a/tsconfig.json b/tsconfig.json index 940a29ae7..5d626af18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,6 @@ "strictNullChecks": true, "checkJs": true, "noImplicitAny": true, - "noUnusedLocals": true, "noUnusedParameters": true, "strictPropertyInitialization": true, "baseUrl": ".", From 700f8ec66c6bd9c890a9aa58b828c2effc39d372 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Sat, 21 Sep 2024 00:06:39 +0000 Subject: [PATCH 3/4] move noUnusedParameters=true from IDE to compile --- build/config/tsconfig.base.json | 2 +- src/shared/managers/SubscriptionManager.ts | 10 ++++++++-- src/shared/utils/Encoding.ts | 2 +- tsconfig.json | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build/config/tsconfig.base.json b/build/config/tsconfig.base.json index c5f767701..48c345695 100644 --- a/build/config/tsconfig.base.json +++ b/build/config/tsconfig.base.json @@ -9,7 +9,7 @@ "noImplicitReturns": true, "noImplicitThis": true, "noUnusedLocals": true, - "noUnusedParameters": false, + "noUnusedParameters": true, "allowSyntheticDefaultImports": true, "allowUnreachableCode": false, "allowUnusedLabels": false, diff --git a/src/shared/managers/SubscriptionManager.ts b/src/shared/managers/SubscriptionManager.ts index 7b37ce256..ab98c4fe7 100644 --- a/src/shared/managers/SubscriptionManager.ts +++ b/src/shared/managers/SubscriptionManager.ts @@ -242,7 +242,9 @@ export class SubscriptionManager { * @param rawPushSubscription The raw push subscription obtained from calling subscribe(). This * can be null, in which case OneSignal's device record is set to unsubscribed. * - * @param subscriptionState Describes whether the device record is subscribed, unsubscribed, or in + * @param subscriptionState TODO: This is no longer used here and needs some refactoring to + * put this back into place. + * Describes whether the device record is subscribed, unsubscribed, or in * another state. By default, this is set from the availability of rawPushSubscription (exists: * Subscribed, null: Unsubscribed). Other use cases may result in creation of a device record that * warrants a special subscription state. For example, a device ID can be retrieved by providing @@ -251,7 +253,7 @@ export class SubscriptionManager { */ public async registerSubscription( pushSubscription: RawPushSubscription, - subscriptionState?: SubscriptionStateKind, + _subscriptionState?: SubscriptionStateKind, ): Promise { /* This may be called after the RawPushSubscription has been serialized across a postMessage @@ -477,6 +479,10 @@ export class SubscriptionManager { await this.context.serviceWorkerManager.installWorker(); } catch (err) { if (err instanceof ServiceWorkerRegistrationError) { + // TODO: This doesn't register the subscription any more, most likely broke + // in some refactoring in the v16 major release. It would be useful if a + // subscription was created so the customer knows this failed by seeing + // subscriptions in this state on the OneSignal dashboard. if (err.status === 403) { await this.context.subscriptionManager.registerFailedSubscription( SubscriptionStateKind.ServiceWorkerStatus403, diff --git a/src/shared/utils/Encoding.ts b/src/shared/utils/Encoding.ts index 7f30d7239..eb900c0c8 100644 --- a/src/shared/utils/Encoding.ts +++ b/src/shared/utils/Encoding.ts @@ -80,7 +80,7 @@ export function base64Encode(str) { return btoa( encodeURIComponent(str).replace( /%([0-9A-F]{2})/g, - function toSolidBytes(match, p1) { + function toSolidBytes(_match, p1) { return String.fromCharCode(('0x' as any) + p1); }, ), diff --git a/tsconfig.json b/tsconfig.json index 5d626af18..e8654add4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,6 @@ "strictNullChecks": true, "checkJs": true, "noImplicitAny": true, - "noUnusedParameters": true, "strictPropertyInitialization": true, "baseUrl": ".", "types": ["jest", "node"] From 3f8d65df53b73f068ed52a5b944afee408cd6896 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Mon, 23 Sep 2024 18:07:05 +0000 Subject: [PATCH 4/4] remove unused functions --- src/shared/utils/Encoding.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/shared/utils/Encoding.ts b/src/shared/utils/Encoding.ts index eb900c0c8..9c3d17b69 100644 --- a/src/shared/utils/Encoding.ts +++ b/src/shared/utils/Encoding.ts @@ -70,35 +70,6 @@ export function arrayBufferToBase64(arrayBuffer: ArrayBufferLike): string { return base64; } -/** - * From: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding - */ -export function base64Encode(str) { - // first we use encodeURIComponent to get percent-encoded UTF-8, - // then we convert the percent encodings into raw bytes which - // can be fed into btoa. - return btoa( - encodeURIComponent(str).replace( - /%([0-9A-F]{2})/g, - function toSolidBytes(_match, p1) { - return String.fromCharCode(('0x' as any) + p1); - }, - ), - ); -} - -export function base64Decode(str) { - // Going backwards: from bytestream, to percent-encoding, to original string. - return decodeURIComponent( - atob(str) - .split('') - .map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }) - .join(''), - ); -} - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 export function encodeRFC3986URIComponent(str: string): string { return encodeURIComponent(str).replace(