From ad45c439e339ffd8c932fb2dd3054387973637cb Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 13:27:06 -0600 Subject: [PATCH 1/8] Update docker-compose.yml Motivation: volume mounting was incorrect. This led to `releases` directory on host not accurately reflecting contents in container. version property is deprecated --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 27f036bea..1faa56a49 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.4' services: onesignal-web-sdk-dev: image: onesignal/web-sdk-dev @@ -6,7 +5,7 @@ services: build: . volumes: - .:/sdk:cached - - sdk-build:/sdk/build/releases + - ./build/releases:/sdk/build/releases ports: - published: 4001 target: 4001 From 6a6ff17f7a48af3f6a3970b58eceb2715ac45be8 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 13:38:26 -0600 Subject: [PATCH 2/8] Update publish.sh script Motivation: get map files working no matter the environment. Works by updating the sourceMappingUrl comment in the output files --- build/scripts/publish.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/build/scripts/publish.sh b/build/scripts/publish.sh index 586e73f4c..5d40889a4 100755 --- a/build/scripts/publish.sh +++ b/build/scripts/publish.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash + getPrefix() { if [ "$ENV" = "production" ]; then echo "" elif [ "$ENV" = "staging" ]; then echo "Staging-" - else [ "$ENV" = "development" ] + else echo "Dev-" fi } @@ -14,10 +15,13 @@ set -x pwd -mkdir build/releases +rm -rf build/releases +mkdir -p build/releases +# Copy files with the prefix cp build/bundles/OneSignalSDK.page.js build/releases/$PREFIX"OneSignalSDK.page.js" cp build/bundles/OneSignalSDK.page.js.map build/releases/$PREFIX"OneSignalSDK.page.js.map" + cp build/bundles/OneSignalSDK.page.es6.js build/releases/$PREFIX"OneSignalSDK.page.es6.js" cp build/bundles/OneSignalSDK.page.es6.js.map build/releases/$PREFIX"OneSignalSDK.page.es6.js.map" @@ -27,7 +31,10 @@ cp build/bundles/OneSignalSDK.sw.js.map build/releases/$PREFIX"OneSignalSDK.sw.j cp build/bundles/OneSignalSDK.page.styles.css build/releases/$PREFIX"OneSignalSDK.page.styles.css" cp build/bundles/OneSignalSDK.page.styles.css.map build/releases/$PREFIX"OneSignalSDK.page.styles.css.map" -if [ "$ENV" = "staging" ]; then - sed -i 's/sourceMappingURL=OneSignal/sourceMappingURL=Staging-OneSignal/' build/releases/Staging-*.js - sed -i 's/sourceMappingURL=OneSignal/sourceMappingURL=Staging-OneSignal/' build/releases/Staging-*.css -fi +# Update sourceMappingURL to include the prefix +for file in build/releases/$PREFIX*.js build/releases/$PREFIX*.css; do + # Ensure we're only updating files with a sourceMappingURL + if grep -q "sourceMappingURL=" "$file"; then + sed -i "s|sourceMappingURL=OneSignal|sourceMappingURL=${PREFIX}OneSignal|g" "$file" + fi +done From 16d03458f7206132c0edd03a2ac5312ca59f722c Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 15:16:10 -0600 Subject: [PATCH 3/8] add `serviceWorkerOverrideForTypical` param Motivation: control whether we override the server config for typical site by exposing a new user config param that overrides SW settings --- src/shared/helpers/ConfigHelper.ts | 45 ++++++++++++++++++++++++++---- src/shared/models/AppConfig.ts | 7 +++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/shared/helpers/ConfigHelper.ts b/src/shared/helpers/ConfigHelper.ts index cda59b9fd..2a0c9c98b 100644 --- a/src/shared/helpers/ConfigHelper.ts +++ b/src/shared/helpers/ConfigHelper.ts @@ -18,6 +18,7 @@ import { AppConfig, ConfigIntegrationKind, ServerAppPromptConfig, + ServiceWorkerConfigParams, } from '../models/AppConfig'; import { AppUserConfigCustomLinkOptions, @@ -481,6 +482,33 @@ export class ConfigHelper { }; } + public static getServiceWorkerValues( + userConfig: AppUserConfig, + serverConfig: ServerAppConfig, + ): ServiceWorkerConfigParams { + const useUserOverride = userConfig.serviceWorkerOverrideForTypical; + + const path = useUserOverride + ? Utils.getValueOrDefault(userConfig.path, serverConfig.config.serviceWorker.path) + : serverConfig.config.serviceWorker.path; + + const serviceWorkerParam = useUserOverride + ? Utils.getValueOrDefault(userConfig.serviceWorkerParam, { + scope: serverConfig.config.serviceWorker.registrationScope, + }) + : { scope: serverConfig.config.serviceWorker.registrationScope }; + + const serviceWorkerPath = useUserOverride + ? Utils.getValueOrDefault(userConfig.serviceWorkerPath, serverConfig.config.serviceWorker.workerName) + : serverConfig.config.serviceWorker.workerName; + + return { + path, + serviceWorkerParam, + serviceWorkerPath, + }; + } + public static getUserConfigForConfigIntegrationKind( configIntegrationKind: ConfigIntegrationKind, userConfig: AppUserConfig, @@ -490,19 +518,23 @@ export class ConfigHelper { configIntegrationKind, ); switch (integrationCapabilities.configuration) { - case IntegrationConfigurationKind.Dashboard: + case IntegrationConfigurationKind.Dashboard: { /* Ignores code-based initialization configuration and uses dashboard configuration only. */ + const { + path, + serviceWorkerPath, + serviceWorkerParam, + } = this.getServiceWorkerValues(userConfig, serverConfig); + return { appId: serverConfig.app_id, autoRegister: false, autoResubscribe: serverConfig.config.autoResubscribe, - path: serverConfig.config.serviceWorker.path, - serviceWorkerPath: serverConfig.config.serviceWorker.workerName, - serviceWorkerParam: { - scope: serverConfig.config.serviceWorker.registrationScope, - }, + path, + serviceWorkerPath, + serviceWorkerParam, subdomainName: serverConfig.config.siteInfo.proxyOrigin, promptOptions: this.getPromptOptionsForDashboardConfiguration(serverConfig), @@ -612,6 +644,7 @@ export class ConfigHelper { unattributed: serverConfig.config.outcomes.unattributed, }, }; + } case IntegrationConfigurationKind.JavaScript: { /* Ignores dashboard configuration and uses code-based configuration only. diff --git a/src/shared/models/AppConfig.ts b/src/shared/models/AppConfig.ts index a23d155c5..53d35d2d7 100755 --- a/src/shared/models/AppConfig.ts +++ b/src/shared/models/AppConfig.ts @@ -94,6 +94,7 @@ export interface AppUserConfig { allowLocalhostAsSecureOrigin?: boolean; pageUrl?: string; outcomes?: OutcomesConfig; + serviceWorkerOverrideForTypical?: boolean; } export interface AppUserConfigWelcomeNotification { @@ -274,3 +275,9 @@ export interface ServerAppConfig { generated_at: number; } + +export type ServiceWorkerConfigParams = { + path?: string; + serviceWorkerParam?: { scope: string }, + serviceWorkerPath?: string; +}; From b9bcf324a9360b1e3a2d5ca473e43d9360f3a5a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 15:17:06 -0600 Subject: [PATCH 4/8] add example to index.html --- express_webpack/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/express_webpack/index.html b/express_webpack/index.html index 8bd717122..61adb8ef2 100644 --- a/express_webpack/index.html +++ b/express_webpack/index.html @@ -41,6 +41,7 @@ }, serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH }, serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js', + //serviceWorkerOverrideForTypical: true, // keep as example notifyButton: { enable: true }, From 3e8261bf2f393961e1cd685cd3005874b51b64b4 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 15:36:22 -0600 Subject: [PATCH 5/8] Update unit tests Motivation: add coverage for new functionality, update default values for SW params --- __test__/support/environment/TestContext.ts | 8 ++-- __test__/unit/helpers/configHelper.test.ts | 46 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/__test__/support/environment/TestContext.ts b/__test__/support/environment/TestContext.ts index f8f68160a..1dc053d5c 100644 --- a/__test__/support/environment/TestContext.ts +++ b/__test__/support/environment/TestContext.ts @@ -294,10 +294,10 @@ export default class TestContext { kind: configIntegrationKind, }, serviceWorker: { - path: undefined, - workerName: undefined, - registrationScope: undefined, - customizationEnabled: true, + customizationEnabled: false, + path: '/', + workerName: 'OneSignalSDKWorker.js', + registrationScope: '/', }, setupBehavior: { allowLocalhostAsSecureOrigin: false, diff --git a/__test__/unit/helpers/configHelper.test.ts b/__test__/unit/helpers/configHelper.test.ts index c854e89b5..a695727e1 100644 --- a/__test__/unit/helpers/configHelper.test.ts +++ b/__test__/unit/helpers/configHelper.test.ts @@ -8,6 +8,8 @@ import { getFinalAppConfig } from '../../support/helpers/configHelper'; import { ConfigHelper } from '../../../src/shared/helpers/ConfigHelper'; import TestContext from '../../support/environment/TestContext'; +const SERVICE_WORKER_PATH = 'push/onesignal/'; + describe('ConfigHelper Tests', () => { beforeEach(async () => { await TestEnvironment.initialize(); @@ -200,4 +202,48 @@ describe('ConfigHelper Tests', () => { ); expect(finalConfig.autoResubscribe).toBe(true); }); + + test('service worker config override (true) for typical site works', () => { + const fakeUserConfig: AppUserConfig = { + appId: getRandomUuid(), + serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH }, + serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js', + serviceWorkerOverrideForTypical: true, + } + + const fakeServerConfig = TestContext.getFakeServerAppConfig( + ConfigIntegrationKind.TypicalSite, + ); + + const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind( + ConfigIntegrationKind.TypicalSite, + fakeUserConfig, + fakeServerConfig, + ); + + expect(finalConfig.serviceWorkerPath).toBe('push/onesignal/OneSignalSDKWorker.js'); + expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/push/onesignal/' }); + }) + + test('service worker config override (false) for typical site works', () => { + const fakeUserConfig: AppUserConfig = { + appId: getRandomUuid(), + serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH }, + serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js', + serviceWorkerOverrideForTypical: false, + } + + const fakeServerConfig = TestContext.getFakeServerAppConfig( + ConfigIntegrationKind.TypicalSite, + ); + + const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind( + ConfigIntegrationKind.TypicalSite, + fakeUserConfig, + fakeServerConfig, + ); + + expect(finalConfig.serviceWorkerPath).toBe('OneSignalSDKWorker.js'); + expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/' }); + }) }); From 92063fbfc40dd637c8d03f8bdb59e0a5e43a454d Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 16:26:46 -0600 Subject: [PATCH 6/8] Clean up dead code --- __test__/support/environment/TestContext.ts | 2 -- src/shared/models/AppConfig.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/__test__/support/environment/TestContext.ts b/__test__/support/environment/TestContext.ts index 1dc053d5c..b8307cffa 100644 --- a/__test__/support/environment/TestContext.ts +++ b/__test__/support/environment/TestContext.ts @@ -134,7 +134,6 @@ export default class TestContext { enable: false, }, serviceWorker: { - customizationEnabled: false, path: '/', workerName: 'OneSignalSDKWorker.js', registrationScope: '/', @@ -294,7 +293,6 @@ export default class TestContext { kind: configIntegrationKind, }, serviceWorker: { - customizationEnabled: false, path: '/', workerName: 'OneSignalSDKWorker.js', registrationScope: '/', diff --git a/src/shared/models/AppConfig.ts b/src/shared/models/AppConfig.ts index 53d35d2d7..019cbd90a 100755 --- a/src/shared/models/AppConfig.ts +++ b/src/shared/models/AppConfig.ts @@ -244,7 +244,6 @@ export interface ServerAppConfig { path?: string; workerName?: string; registrationScope?: string; - customizationEnabled: boolean; }; setupBehavior?: { allowLocalhostAsSecureOrigin: false; From ef2906728bd02138a13c5d9d5889bad1062f2219 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 15:38:20 -0600 Subject: [PATCH 7/8] Appease linter --- __test__/unit/helpers/configHelper.test.ts | 16 ++++++++++------ src/shared/helpers/ConfigHelper.ts | 17 ++++++++++------- src/shared/models/AppConfig.ts | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/__test__/unit/helpers/configHelper.test.ts b/__test__/unit/helpers/configHelper.test.ts index a695727e1..7411b7f8b 100644 --- a/__test__/unit/helpers/configHelper.test.ts +++ b/__test__/unit/helpers/configHelper.test.ts @@ -209,7 +209,7 @@ describe('ConfigHelper Tests', () => { serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH }, serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js', serviceWorkerOverrideForTypical: true, - } + }; const fakeServerConfig = TestContext.getFakeServerAppConfig( ConfigIntegrationKind.TypicalSite, @@ -221,9 +221,13 @@ describe('ConfigHelper Tests', () => { fakeServerConfig, ); - expect(finalConfig.serviceWorkerPath).toBe('push/onesignal/OneSignalSDKWorker.js'); - expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/push/onesignal/' }); - }) + expect(finalConfig.serviceWorkerPath).toBe( + 'push/onesignal/OneSignalSDKWorker.js', + ); + expect(finalConfig.serviceWorkerParam).toEqual({ + scope: '/push/onesignal/', + }); + }); test('service worker config override (false) for typical site works', () => { const fakeUserConfig: AppUserConfig = { @@ -231,7 +235,7 @@ describe('ConfigHelper Tests', () => { serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH }, serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js', serviceWorkerOverrideForTypical: false, - } + }; const fakeServerConfig = TestContext.getFakeServerAppConfig( ConfigIntegrationKind.TypicalSite, @@ -245,5 +249,5 @@ describe('ConfigHelper Tests', () => { expect(finalConfig.serviceWorkerPath).toBe('OneSignalSDKWorker.js'); expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/' }); - }) + }); }); diff --git a/src/shared/helpers/ConfigHelper.ts b/src/shared/helpers/ConfigHelper.ts index 2a0c9c98b..6a3bbaa4b 100644 --- a/src/shared/helpers/ConfigHelper.ts +++ b/src/shared/helpers/ConfigHelper.ts @@ -489,7 +489,10 @@ export class ConfigHelper { const useUserOverride = userConfig.serviceWorkerOverrideForTypical; const path = useUserOverride - ? Utils.getValueOrDefault(userConfig.path, serverConfig.config.serviceWorker.path) + ? Utils.getValueOrDefault( + userConfig.path, + serverConfig.config.serviceWorker.path, + ) : serverConfig.config.serviceWorker.path; const serviceWorkerParam = useUserOverride @@ -499,7 +502,10 @@ export class ConfigHelper { : { scope: serverConfig.config.serviceWorker.registrationScope }; const serviceWorkerPath = useUserOverride - ? Utils.getValueOrDefault(userConfig.serviceWorkerPath, serverConfig.config.serviceWorker.workerName) + ? Utils.getValueOrDefault( + userConfig.serviceWorkerPath, + serverConfig.config.serviceWorker.workerName, + ) : serverConfig.config.serviceWorker.workerName; return { @@ -522,11 +528,8 @@ export class ConfigHelper { /* Ignores code-based initialization configuration and uses dashboard configuration only. */ - const { - path, - serviceWorkerPath, - serviceWorkerParam, - } = this.getServiceWorkerValues(userConfig, serverConfig); + const { path, serviceWorkerPath, serviceWorkerParam } = + this.getServiceWorkerValues(userConfig, serverConfig); return { appId: serverConfig.app_id, diff --git a/src/shared/models/AppConfig.ts b/src/shared/models/AppConfig.ts index 019cbd90a..4e0564646 100755 --- a/src/shared/models/AppConfig.ts +++ b/src/shared/models/AppConfig.ts @@ -277,6 +277,6 @@ export interface ServerAppConfig { export type ServiceWorkerConfigParams = { path?: string; - serviceWorkerParam?: { scope: string }, + serviceWorkerParam?: { scope: string }; serviceWorkerPath?: string; }; From 4a7a8b8ab3a9fbcfde04e76b1bfe7047e68e78ce Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 13 Dec 2024 15:18:51 -0600 Subject: [PATCH 8/8] 160205 Release Commit Motivation: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 30a5c2abb..055d18ba7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "jest": "jest --coverage" }, "config": { - "sdkVersion": "160204" + "sdkVersion": "160205" }, "repository": { "type": "git",