Skip to content

Commit

Permalink
Merge pull request #1195 from OneSignal/dev/enable_more_compile_ts_ch…
Browse files Browse the repository at this point in the history
…ecks_2024-09-20

[Dev] Enable compile TypeScript checks; noUnusedLocals, noUnusedParameters, & strictFunctionTypes
  • Loading branch information
jkasten2 authored Sep 23, 2024
2 parents 24895d0 + 3f8d65d commit 7ca28ca
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 44 deletions.
5 changes: 3 additions & 2 deletions build/config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
Expand All @@ -27,6 +27,7 @@
"sourceRoot": "../..",
"rootDir": "../..",
"esModuleInterop": true,
"strictFunctionTypes": true,
"baseUrl": "../..",
"types": [
"node"
Expand Down
4 changes: 1 addition & 3 deletions src/page/bell/Bell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/page/bell/Dialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import bowser from 'bowser';

import OneSignalEvent from '../../shared/services/OneSignalEvent';
import SdkEnvironment from '../../shared/managers/SdkEnvironment';
import {
Expand Down
1 change: 0 additions & 1 deletion src/page/managers/PromptsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/shared/helpers/EventHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import OneSignalApiShared from '../api/OneSignalApiShared';
import Log from '../libraries/Log';
import { CustomLinkManager } from '../managers/CustomLinkManager';
import { ContextSWInterface } from '../models/ContextSW';
Expand Down
10 changes: 8 additions & 2 deletions src/shared/managers/SubscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -251,7 +253,7 @@ export class SubscriptionManager {
*/
public async registerSubscription(
pushSubscription: RawPushSubscription,
subscriptionState?: SubscriptionStateKind,
_subscriptionState?: SubscriptionStateKind,
): Promise<Subscription> {
/*
This may be called after the RawPushSubscription has been serialized across a postMessage
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 0 additions & 29 deletions src/shared/utils/Encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/shared/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
"strictNullChecks": true,
"checkJs": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"baseUrl": ".",
"types": ["jest", "node"]
},
Expand Down

0 comments on commit 7ca28ca

Please sign in to comment.