Skip to content

Commit d2409a1

Browse files
author
Rodrigo Gomez Palacio
authoredDec 13, 2024··
Merge pull request #1213 from OneSignal/160205-release
160205 release
2 parents dc853f9 + 4a7a8b8 commit d2409a1

File tree

8 files changed

+118
-21
lines changed

8 files changed

+118
-21
lines changed
 

‎__test__/support/environment/TestContext.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export default class TestContext {
134134
enable: false,
135135
},
136136
serviceWorker: {
137-
customizationEnabled: false,
138137
path: '/',
139138
workerName: 'OneSignalSDKWorker.js',
140139
registrationScope: '/',
@@ -294,10 +293,9 @@ export default class TestContext {
294293
kind: configIntegrationKind,
295294
},
296295
serviceWorker: {
297-
path: undefined,
298-
workerName: undefined,
299-
registrationScope: undefined,
300-
customizationEnabled: true,
296+
path: '/',
297+
workerName: 'OneSignalSDKWorker.js',
298+
registrationScope: '/',
301299
},
302300
setupBehavior: {
303301
allowLocalhostAsSecureOrigin: false,

‎__test__/unit/helpers/configHelper.test.ts

+50
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { getFinalAppConfig } from '../../support/helpers/configHelper';
88
import { ConfigHelper } from '../../../src/shared/helpers/ConfigHelper';
99
import TestContext from '../../support/environment/TestContext';
1010

11+
const SERVICE_WORKER_PATH = 'push/onesignal/';
12+
1113
describe('ConfigHelper Tests', () => {
1214
beforeEach(async () => {
1315
await TestEnvironment.initialize();
@@ -200,4 +202,52 @@ describe('ConfigHelper Tests', () => {
200202
);
201203
expect(finalConfig.autoResubscribe).toBe(true);
202204
});
205+
206+
test('service worker config override (true) for typical site works', () => {
207+
const fakeUserConfig: AppUserConfig = {
208+
appId: getRandomUuid(),
209+
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
210+
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
211+
serviceWorkerOverrideForTypical: true,
212+
};
213+
214+
const fakeServerConfig = TestContext.getFakeServerAppConfig(
215+
ConfigIntegrationKind.TypicalSite,
216+
);
217+
218+
const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind(
219+
ConfigIntegrationKind.TypicalSite,
220+
fakeUserConfig,
221+
fakeServerConfig,
222+
);
223+
224+
expect(finalConfig.serviceWorkerPath).toBe(
225+
'push/onesignal/OneSignalSDKWorker.js',
226+
);
227+
expect(finalConfig.serviceWorkerParam).toEqual({
228+
scope: '/push/onesignal/',
229+
});
230+
});
231+
232+
test('service worker config override (false) for typical site works', () => {
233+
const fakeUserConfig: AppUserConfig = {
234+
appId: getRandomUuid(),
235+
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
236+
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
237+
serviceWorkerOverrideForTypical: false,
238+
};
239+
240+
const fakeServerConfig = TestContext.getFakeServerAppConfig(
241+
ConfigIntegrationKind.TypicalSite,
242+
);
243+
244+
const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind(
245+
ConfigIntegrationKind.TypicalSite,
246+
fakeUserConfig,
247+
fakeServerConfig,
248+
);
249+
250+
expect(finalConfig.serviceWorkerPath).toBe('OneSignalSDKWorker.js');
251+
expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/' });
252+
});
203253
});

‎build/scripts/publish.sh

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env bash
2+
23
getPrefix() {
34
if [ "$ENV" = "production" ]; then
45
echo ""
56
elif [ "$ENV" = "staging" ]; then
67
echo "Staging-"
7-
else [ "$ENV" = "development" ]
8+
else
89
echo "Dev-"
910
fi
1011
}
@@ -14,10 +15,13 @@ set -x
1415

1516
pwd
1617

17-
mkdir build/releases
18+
rm -rf build/releases
19+
mkdir -p build/releases
1820

21+
# Copy files with the prefix
1922
cp build/bundles/OneSignalSDK.page.js build/releases/$PREFIX"OneSignalSDK.page.js"
2023
cp build/bundles/OneSignalSDK.page.js.map build/releases/$PREFIX"OneSignalSDK.page.js.map"
24+
2125
cp build/bundles/OneSignalSDK.page.es6.js build/releases/$PREFIX"OneSignalSDK.page.es6.js"
2226
cp build/bundles/OneSignalSDK.page.es6.js.map build/releases/$PREFIX"OneSignalSDK.page.es6.js.map"
2327

@@ -27,7 +31,10 @@ cp build/bundles/OneSignalSDK.sw.js.map build/releases/$PREFIX"OneSignalSDK.sw.j
2731
cp build/bundles/OneSignalSDK.page.styles.css build/releases/$PREFIX"OneSignalSDK.page.styles.css"
2832
cp build/bundles/OneSignalSDK.page.styles.css.map build/releases/$PREFIX"OneSignalSDK.page.styles.css.map"
2933

30-
if [ "$ENV" = "staging" ]; then
31-
sed -i 's/sourceMappingURL=OneSignal/sourceMappingURL=Staging-OneSignal/' build/releases/Staging-*.js
32-
sed -i 's/sourceMappingURL=OneSignal/sourceMappingURL=Staging-OneSignal/' build/releases/Staging-*.css
33-
fi
34+
# Update sourceMappingURL to include the prefix
35+
for file in build/releases/$PREFIX*.js build/releases/$PREFIX*.css; do
36+
# Ensure we're only updating files with a sourceMappingURL
37+
if grep -q "sourceMappingURL=" "$file"; then
38+
sed -i "s|sourceMappingURL=OneSignal|sourceMappingURL=${PREFIX}OneSignal|g" "$file"
39+
fi
40+
done

‎docker-compose.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
version: '3.4'
21
services:
32
onesignal-web-sdk-dev:
43
image: onesignal/web-sdk-dev
54
container_name: web-sdk-dev
65
build: .
76
volumes:
87
- .:/sdk:cached
9-
- sdk-build:/sdk/build/releases
8+
- ./build/releases:/sdk/build/releases
109
ports:
1110
- published: 4001
1211
target: 4001

‎express_webpack/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
4343
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
44+
//serviceWorkerOverrideForTypical: true, // keep as example
4445
notifyButton: {
4546
enable: true
4647
},

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"jest": "jest --coverage"
4444
},
4545
"config": {
46-
"sdkVersion": "160204"
46+
"sdkVersion": "160205"
4747
},
4848
"repository": {
4949
"type": "git",

‎src/shared/helpers/ConfigHelper.ts

+42-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
AppConfig,
1919
ConfigIntegrationKind,
2020
ServerAppPromptConfig,
21+
ServiceWorkerConfigParams,
2122
} from '../models/AppConfig';
2223
import {
2324
AppUserConfigCustomLinkOptions,
@@ -481,6 +482,39 @@ export class ConfigHelper {
481482
};
482483
}
483484

485+
public static getServiceWorkerValues(
486+
userConfig: AppUserConfig,
487+
serverConfig: ServerAppConfig,
488+
): ServiceWorkerConfigParams {
489+
const useUserOverride = userConfig.serviceWorkerOverrideForTypical;
490+
491+
const path = useUserOverride
492+
? Utils.getValueOrDefault(
493+
userConfig.path,
494+
serverConfig.config.serviceWorker.path,
495+
)
496+
: serverConfig.config.serviceWorker.path;
497+
498+
const serviceWorkerParam = useUserOverride
499+
? Utils.getValueOrDefault(userConfig.serviceWorkerParam, {
500+
scope: serverConfig.config.serviceWorker.registrationScope,
501+
})
502+
: { scope: serverConfig.config.serviceWorker.registrationScope };
503+
504+
const serviceWorkerPath = useUserOverride
505+
? Utils.getValueOrDefault(
506+
userConfig.serviceWorkerPath,
507+
serverConfig.config.serviceWorker.workerName,
508+
)
509+
: serverConfig.config.serviceWorker.workerName;
510+
511+
return {
512+
path,
513+
serviceWorkerParam,
514+
serviceWorkerPath,
515+
};
516+
}
517+
484518
public static getUserConfigForConfigIntegrationKind(
485519
configIntegrationKind: ConfigIntegrationKind,
486520
userConfig: AppUserConfig,
@@ -490,19 +524,20 @@ export class ConfigHelper {
490524
configIntegrationKind,
491525
);
492526
switch (integrationCapabilities.configuration) {
493-
case IntegrationConfigurationKind.Dashboard:
527+
case IntegrationConfigurationKind.Dashboard: {
494528
/*
495529
Ignores code-based initialization configuration and uses dashboard configuration only.
496530
*/
531+
const { path, serviceWorkerPath, serviceWorkerParam } =
532+
this.getServiceWorkerValues(userConfig, serverConfig);
533+
497534
return {
498535
appId: serverConfig.app_id,
499536
autoRegister: false,
500537
autoResubscribe: serverConfig.config.autoResubscribe,
501-
path: serverConfig.config.serviceWorker.path,
502-
serviceWorkerPath: serverConfig.config.serviceWorker.workerName,
503-
serviceWorkerParam: {
504-
scope: serverConfig.config.serviceWorker.registrationScope,
505-
},
538+
path,
539+
serviceWorkerPath,
540+
serviceWorkerParam,
506541
subdomainName: serverConfig.config.siteInfo.proxyOrigin,
507542
promptOptions:
508543
this.getPromptOptionsForDashboardConfiguration(serverConfig),
@@ -612,6 +647,7 @@ export class ConfigHelper {
612647
unattributed: serverConfig.config.outcomes.unattributed,
613648
},
614649
};
650+
}
615651
case IntegrationConfigurationKind.JavaScript: {
616652
/*
617653
Ignores dashboard configuration and uses code-based configuration only.

‎src/shared/models/AppConfig.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface AppUserConfig {
9494
allowLocalhostAsSecureOrigin?: boolean;
9595
pageUrl?: string;
9696
outcomes?: OutcomesConfig;
97+
serviceWorkerOverrideForTypical?: boolean;
9798
}
9899

99100
export interface AppUserConfigWelcomeNotification {
@@ -243,7 +244,6 @@ export interface ServerAppConfig {
243244
path?: string;
244245
workerName?: string;
245246
registrationScope?: string;
246-
customizationEnabled: boolean;
247247
};
248248
setupBehavior?: {
249249
allowLocalhostAsSecureOrigin: false;
@@ -274,3 +274,9 @@ export interface ServerAppConfig {
274274

275275
generated_at: number;
276276
}
277+
278+
export type ServiceWorkerConfigParams = {
279+
path?: string;
280+
serviceWorkerParam?: { scope: string };
281+
serviceWorkerPath?: string;
282+
};

0 commit comments

Comments
 (0)
Please sign in to comment.