Skip to content

Commit

Permalink
Merge pull request #1213 from OneSignal/160205-release
Browse files Browse the repository at this point in the history
160205 release
  • Loading branch information
rgomezp authored Dec 13, 2024
2 parents dc853f9 + 4a7a8b8 commit d2409a1
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 21 deletions.
8 changes: 3 additions & 5 deletions __test__/support/environment/TestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export default class TestContext {
enable: false,
},
serviceWorker: {
customizationEnabled: false,
path: '/',
workerName: 'OneSignalSDKWorker.js',
registrationScope: '/',
Expand Down Expand Up @@ -294,10 +293,9 @@ export default class TestContext {
kind: configIntegrationKind,
},
serviceWorker: {
path: undefined,
workerName: undefined,
registrationScope: undefined,
customizationEnabled: true,
path: '/',
workerName: 'OneSignalSDKWorker.js',
registrationScope: '/',
},
setupBehavior: {
allowLocalhostAsSecureOrigin: false,
Expand Down
50 changes: 50 additions & 0 deletions __test__/unit/helpers/configHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -200,4 +202,52 @@ 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: '/' });
});
});
19 changes: 13 additions & 6 deletions build/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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"

Expand All @@ -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
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
version: '3.4'
services:
onesignal-web-sdk-dev:
image: onesignal/web-sdk-dev
container_name: web-sdk-dev
build: .
volumes:
- .:/sdk:cached
- sdk-build:/sdk/build/releases
- ./build/releases:/sdk/build/releases
ports:
- published: 4001
target: 4001
Expand Down
1 change: 1 addition & 0 deletions express_webpack/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
//serviceWorkerOverrideForTypical: true, // keep as example
notifyButton: {
enable: true
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"jest": "jest --coverage"
},
"config": {
"sdkVersion": "160204"
"sdkVersion": "160205"
},
"repository": {
"type": "git",
Expand Down
48 changes: 42 additions & 6 deletions src/shared/helpers/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AppConfig,
ConfigIntegrationKind,
ServerAppPromptConfig,
ServiceWorkerConfigParams,
} from '../models/AppConfig';
import {
AppUserConfigCustomLinkOptions,
Expand Down Expand Up @@ -481,6 +482,39 @@ 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,
Expand All @@ -490,19 +524,20 @@ 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),
Expand Down Expand Up @@ -612,6 +647,7 @@ export class ConfigHelper {
unattributed: serverConfig.config.outcomes.unattributed,
},
};
}
case IntegrationConfigurationKind.JavaScript: {
/*
Ignores dashboard configuration and uses code-based configuration only.
Expand Down
8 changes: 7 additions & 1 deletion src/shared/models/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface AppUserConfig {
allowLocalhostAsSecureOrigin?: boolean;
pageUrl?: string;
outcomes?: OutcomesConfig;
serviceWorkerOverrideForTypical?: boolean;
}

export interface AppUserConfigWelcomeNotification {
Expand Down Expand Up @@ -243,7 +244,6 @@ export interface ServerAppConfig {
path?: string;
workerName?: string;
registrationScope?: string;
customizationEnabled: boolean;
};
setupBehavior?: {
allowLocalhostAsSecureOrigin: false;
Expand Down Expand Up @@ -274,3 +274,9 @@ export interface ServerAppConfig {

generated_at: number;
}

export type ServiceWorkerConfigParams = {
path?: string;
serviceWorkerParam?: { scope: string };
serviceWorkerPath?: string;
};

0 comments on commit d2409a1

Please sign in to comment.