From 5f7a1d2978742d444fc09b40ad28e8c83f034301 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Tue, 3 Dec 2024 10:45:56 +0530 Subject: [PATCH 01/11] feat: lock plugins and integrations version by default --- packages/analytics-js-common/src/types/LoadOptions.ts | 10 ++++++++-- .../components/configManager/ConfigManager.test.ts | 3 ++- .../src/components/configManager/ConfigManager.ts | 1 + .../src/components/utilities/loadOptions.ts | 5 +++-- packages/analytics-js/src/state/slices/loadOptions.ts | 4 ++-- packages/sanity-suite/public/v1.1/index-local.html | 1 - packages/sanity-suite/public/v3/index-local.html | 1 - .../public/v3/integrations/index-local.html | 1 - .../public/v3/manualLoadCall/index-local.html | 1 - 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/analytics-js-common/src/types/LoadOptions.ts b/packages/analytics-js-common/src/types/LoadOptions.ts index ad615b2f8..536fedc5f 100644 --- a/packages/analytics-js-common/src/types/LoadOptions.ts +++ b/packages/analytics-js-common/src/types/LoadOptions.ts @@ -144,8 +144,14 @@ export type LoadOptions = { anonymousIdOptions?: AnonymousIdOptions; setCookieDomain?: string; // defaults to current domain. sameSiteCookie?: CookieSameSite; // defaults to Lax. - lockIntegrationsVersion?: boolean; // defaults to false. - lockPluginsVersion?: boolean; // defaults to false. + /** + * @deprecated Integrations version are locked by default. We do not recommend using this option. + */ + lockIntegrationsVersion?: boolean; // defaults to true. + /** + * @deprecated Plugins version are locked by default. We do not recommend using this option. + */ + lockPluginsVersion?: boolean; // defaults to true. polyfillIfRequired?: boolean; // defaults to true. Controls whether the SDK should polyfill unsupported browser API's if they are detected as missing onLoaded?: OnLoadedCallback; uaChTrackLevel?: UaChTrackLevel; diff --git a/packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts b/packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts index 9f1fc0915..37257815f 100644 --- a/packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/deprecation */ import { effect, signal } from '@preact/signals-core'; import { http, HttpResponse } from 'msw'; import { defaultHttpClient } from '../../../src/services/HttpClient'; @@ -8,7 +9,7 @@ import { state, resetState } from '../../../src/state'; import { getSDKUrl } from '../../../src/components/configManager/util/commonUtil'; import { server } from '../../../__fixtures__/msw.server'; import { dummySourceConfigResponse } from '../../../__fixtures__/fixtures'; -import { +import type { ConfigResponseDestinationItem, SourceConfigResponse, } from '../../../src/components/configManager/types'; diff --git a/packages/analytics-js/src/components/configManager/ConfigManager.ts b/packages/analytics-js/src/components/configManager/ConfigManager.ts index 315f2ab5a..762b92d6a 100644 --- a/packages/analytics-js/src/components/configManager/ConfigManager.ts +++ b/packages/analytics-js/src/components/configManager/ConfigManager.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/deprecation */ /* eslint-disable class-methods-use-this */ import type { IHttpClient, diff --git a/packages/analytics-js/src/components/utilities/loadOptions.ts b/packages/analytics-js/src/components/utilities/loadOptions.ts index f70d11948..0cf244feb 100644 --- a/packages/analytics-js/src/components/utilities/loadOptions.ts +++ b/packages/analytics-js/src/components/utilities/loadOptions.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/deprecation */ import { clone } from 'ramda'; import { isNonEmptyObject, @@ -102,9 +103,9 @@ const normalizeLoadOptions = ( normalizedLoadOpts.queueOptions = removeUndefinedAndNullValues(normalizedLoadOpts.queueOptions); } - normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion === true; + normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion !== false; - normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion === true; + normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion !== false; if (!isNumber(normalizedLoadOpts.dataPlaneEventsBufferTimeout)) { delete normalizedLoadOpts.dataPlaneEventsBufferTimeout; diff --git a/packages/analytics-js/src/state/slices/loadOptions.ts b/packages/analytics-js/src/state/slices/loadOptions.ts index 8d9759353..74c122895 100644 --- a/packages/analytics-js/src/state/slices/loadOptions.ts +++ b/packages/analytics-js/src/state/slices/loadOptions.ts @@ -25,8 +25,8 @@ const defaultLoadOptions: LoadOptions = { beaconQueueOptions: {}, destinationsQueueOptions: {}, queueOptions: {}, - lockIntegrationsVersion: false, - lockPluginsVersion: false, + lockIntegrationsVersion: true, + lockPluginsVersion: true, uaChTrackLevel: 'none', plugins: [], useGlobalIntegrationsConfigInEvents: false, diff --git a/packages/sanity-suite/public/v1.1/index-local.html b/packages/sanity-suite/public/v1.1/index-local.html index a7f13349f..1410057e7 100644 --- a/packages/sanity-suite/public/v1.1/index-local.html +++ b/packages/sanity-suite/public/v1.1/index-local.html @@ -70,7 +70,6 @@ { logLevel: 'DEBUG', configUrl: '__CONFIG_SERVER_HOST__', - lockIntegrationsVersion: true, destSDKBaseURL: '__DEST_SDK_BASE_URL__', cookieConsentManager: { oneTrust: { diff --git a/packages/sanity-suite/public/v3/index-local.html b/packages/sanity-suite/public/v3/index-local.html index 4e4be85cf..2b05b6d3d 100644 --- a/packages/sanity-suite/public/v3/index-local.html +++ b/packages/sanity-suite/public/v3/index-local.html @@ -132,7 +132,6 @@ '__DEST_SDK_BASE_URL__', pluginsSDKBaseURL: '__PLUGINS_SDK_BASE_URL__', - lockIntegrationsVersion: true, consentManagement: { enabled: true, provider: 'oneTrust', diff --git a/packages/sanity-suite/public/v3/integrations/index-local.html b/packages/sanity-suite/public/v3/integrations/index-local.html index 9400a451b..8199af524 100644 --- a/packages/sanity-suite/public/v3/integrations/index-local.html +++ b/packages/sanity-suite/public/v3/integrations/index-local.html @@ -121,7 +121,6 @@ '__DEST_SDK_BASE_URL__', pluginsSDKBaseURL: '__PLUGINS_SDK_BASE_URL__', - lockIntegrationsVersion: true, consentManagement: { enabled: true, provider: 'oneTrust', diff --git a/packages/sanity-suite/public/v3/manualLoadCall/index-local.html b/packages/sanity-suite/public/v3/manualLoadCall/index-local.html index b4c862bba..8d4afa5f3 100644 --- a/packages/sanity-suite/public/v3/manualLoadCall/index-local.html +++ b/packages/sanity-suite/public/v3/manualLoadCall/index-local.html @@ -118,7 +118,6 @@ '__DEST_SDK_BASE_URL__', pluginsSDKBaseURL: '__PLUGINS_SDK_BASE_URL__', - lockIntegrationsVersion: true, consentManagement: { enabled: true, provider: 'oneTrust', From 6c22167792bf6f9a0c224f17e1ea183df9225d8e Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Tue, 3 Dec 2024 10:54:20 +0530 Subject: [PATCH 02/11] chore: avoid publishing latest plugins and integrations to common prod location --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b71bd210d..a1c69f7b9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -153,11 +153,11 @@ jobs: # Upload all the files to S3 aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args - aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args + # aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args - aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args - aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args + # aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args + # aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args + # aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args # Generate the HTML file to list all the integrations ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} ${{ inputs.s3_dir_path }}/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations" $integration_sdks_zip_file From 53e278e76c8f87559dec185b2cf3853cade631f7 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Tue, 3 Dec 2024 11:30:59 +0530 Subject: [PATCH 03/11] chore: regenerate listing html for other paths --- .github/workflows/deploy.yml | 61 ++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a1c69f7b9..f28ef1568 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -128,7 +128,8 @@ jobs: core_sdk_path_prefix="packages/analytics-js/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" - s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ inputs.s3_dir_path }}" + s3_relative_path_prefix="${{ inputs.s3_dir_path }}" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" integration_sdks_zip_file="all_integration_sdks.tar.gz" @@ -160,17 +161,17 @@ jobs: # aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args # Generate the HTML file to list all the integrations - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} ${{ inputs.s3_dir_path }}/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations" $integration_sdks_zip_file + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} ${{ inputs.s3_dir_path }}/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations" $integration_sdks_zip_file + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file # Generate the HTML file to list all the plugins - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} ${{ inputs.s3_dir_path }}/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file # Copy the HTML files to S3 - aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file --cache-control ${{ env.CACHE_CONTROL }} - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file --cache-control ${{ env.CACHE_CONTROL }} - aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file --cache-control ${{ env.CACHE_CONTROL }} + aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args - name: Create Cloudfront invalidation run: | @@ -182,9 +183,17 @@ jobs: core_sdk_path_prefix="packages/analytics-js/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" - s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ env.CURRENT_VERSION_VALUE }}" + s3_relative_path_prefix="${{ env.CURRENT_VERSION_VALUE }}" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" + integration_sdks_zip_file="all_integration_sdks.tar.gz" + plugins_zip_file="all_plugins.tar.gz" + + integration_sdks_html_file="list.html" + plugins_html_file="list.html" + + # Copy all the files to S3 aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args @@ -192,6 +201,19 @@ jobs: aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args + # Generate the HTML file to list all the integrations + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file + + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file + + # Generate the HTML file to list all the plugins + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file + + # Copy all the HTML files to S3 + aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args + - name: Create Cloudfront invalidation if: ${{ inputs.environment == 'production' }} run: | @@ -204,9 +226,17 @@ jobs: core_sdk_path_prefix="packages/analytics-js/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" - s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/latest" + s3_relative_path_prefix="latest" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" + integration_sdks_zip_file="all_integration_sdks.tar.gz" + plugins_zip_file="all_plugins.tar.gz" + + integration_sdks_html_file="list.html" + plugins_html_file="list.html" + + # Copy all the files to S3 aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args @@ -214,6 +244,19 @@ jobs: aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args + # Generate the HTML file to list all the integrations + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file + + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file + + # Generate the HTML file to list all the plugins + ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file + + # Copy all the HTML files to S3 + aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args + aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args + - name: Create Cloudfront invalidation if: ${{ inputs.environment == 'production' }} run: | From 061545b47c478abe08708e9b69d3f0ec284e980e Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Tue, 3 Dec 2024 13:19:03 +0530 Subject: [PATCH 04/11] feat: get sdk url from script tag using the write key --- packages/analytics-js/.size-limit.mjs | 2 +- .../configManager/commonUtil.test.ts | 53 ++++++++++++------- .../configManager/util/commonUtil.ts | 12 +++++ 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/packages/analytics-js/.size-limit.mjs b/packages/analytics-js/.size-limit.mjs index d55635d44..2189a71a7 100644 --- a/packages/analytics-js/.size-limit.mjs +++ b/packages/analytics-js/.size-limit.mjs @@ -13,7 +13,7 @@ export default [ name: 'Core - Legacy - NPM (CJS)', path: 'dist/npm/legacy/cjs/index.cjs', import: '*', - limit: '49 KiB', + limit: '49.5 KiB', }, { name: 'Core - Legacy - NPM (UMD)', diff --git a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts index ff30f7960..3c58904fe 100644 --- a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts @@ -17,11 +17,14 @@ import { state, resetState } from '../../../src/state'; jest.mock('../../../src/components/configManager/util/validate'); -const createScriptElement = (url: string) => { +const createScriptElement = (url: string, writeKey?: string) => { const script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; script.id = 'SOME_ID'; + if (writeKey) { + script.setAttribute('data-rsa-write-key', writeKey); + } document.head.appendChild(script); }; @@ -51,6 +54,7 @@ describe('Config Manager Common Utilities', () => { beforeEach(() => { resetState(); + state.lifecycle.writeKey.value = 'writeKey'; (getDataServiceUrl as jest.Mock).mockRestore(); }); @@ -63,28 +67,39 @@ describe('Config Manager Common Utilities', () => { // expected, input [ 'https://www.dummy.url/fromScript/v3/rsa.min.js', - 'https://www.dummy.url/fromScript/v3/rsa.min.js', + ['https://www.dummy.url/fromScript/v3/rsa.min.js'], + ], + [undefined, ['https://www.dummy.url/fromScript/v3/other.min.js']], + [ + 'https://www.dummy.url/fromScript/v3/rsa.js', + ['https://www.dummy.url/fromScript/v3/rsa.js'], + ], + [undefined, ['https://www.dummy.url/fromScript/v3/rudder.min.js']], + [undefined, ['https://www.dummy.url/fromScript/v3/analytics.min.js']], + [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min']], + [ + 'https://www.dummy.url/fromScript/v3/rsa.js', + ['https://www.dummy.url/fromScript/v3/rsa.js'], + ], + [undefined, ['https://www.dummy.url/fromScript/v3/rsa']], + [undefined, ['https://www.dummy.url/fromScript/v3rsa.min.js']], + ['/rsa.min.js', ['/rsa.min.js']], + ['/rsa.js', ['/rsa.js']], + [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js']], + [ + 'https://www.dummy.url/fromScript/v3/rs.min.js', + ['https://www.dummy.url/fromScript/v3/rs.min.js', 'writeKey'], ], - [undefined, 'https://www.dummy.url/fromScript/v3/other.min.js'], - ['https://www.dummy.url/fromScript/v3/rsa.js', 'https://www.dummy.url/fromScript/v3/rsa.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rudder.min.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/analytics.min.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rsa.min'], - ['https://www.dummy.url/fromScript/v3/rsa.js', 'https://www.dummy.url/fromScript/v3/rsa.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rsa'], - [undefined, 'https://www.dummy.url/fromScript/v3rsa.min.js'], - ['/rsa.min.js', '/rsa.min.js'], - ['/rsa.js', '/rsa.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rs.min.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rsamin.js'], - ['rsa.min.js', 'rsa.min.js'], - ['rsa.js', 'rsa.js'], - [undefined, 'https://www.dummy.url/fromScript/v3/rsa.min.jsx'], - [undefined, null], + [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js', 'writeKey-1']], + [undefined, ['https://www.dummy.url/fromScript/v3/rsamin.js']], + ['rsa.min.js', ['rsa.min.js']], + ['rsa.js', ['rsa.js']], + [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min.jsx']], + [undefined, [null]], ]; test.each(testCases)('should return %s when the script src is %s', (expected, input) => { - createScriptElement(input as string); + createScriptElement((input as any[])[0], (input as any[])[1]); const sdkURL = getSDKUrl(); expect(sdkURL).toBe(expected); diff --git a/packages/analytics-js/src/components/configManager/util/commonUtil.ts b/packages/analytics-js/src/components/configManager/util/commonUtil.ts index 139663988..04cf64a3c 100644 --- a/packages/analytics-js/src/components/configManager/util/commonUtil.ts +++ b/packages/analytics-js/src/components/configManager/util/commonUtil.ts @@ -56,6 +56,18 @@ import { getConsentManagementData } from '../../utilities/consent'; * @returns sdkURL */ const getSDKUrl = (): string | undefined => { + // First try the new method of getting the SDK URL + // from the script tag + const scriptTag = document.querySelector( + 'script[data-rsa-write-key]', + ) as HTMLScriptElement | null; + if (scriptTag && scriptTag.dataset?.rsaWriteKey === state.lifecycle.writeKey.value) { + return scriptTag.src; + } + + // If the new method fails, try the old method + // TODO: We need to remove this once all the customers upgrade to the + // latest SDK loading snippet const scripts = document.getElementsByTagName('script'); const sdkFileNameRegex = /(?:^|\/)rsa(\.min)?\.js$/; From 83279ae4c7d4db01b4559d86ff73e21d1659e6ac Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Tue, 3 Dec 2024 14:12:13 +0530 Subject: [PATCH 05/11] choer: bump size limit --- packages/analytics-js/.size-limit.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/analytics-js/.size-limit.mjs b/packages/analytics-js/.size-limit.mjs index 2189a71a7..d34b941f7 100644 --- a/packages/analytics-js/.size-limit.mjs +++ b/packages/analytics-js/.size-limit.mjs @@ -59,7 +59,7 @@ export default [ name: 'Core (Bundled) - Legacy - NPM (CJS)', path: 'dist/npm/legacy/bundled/cjs/index.cjs', import: '*', - limit: '49 KiB', + limit: '49.5 KiB', }, { name: 'Core (Bundled) - Legacy - NPM (UMD)', From bf88dc564e22197c9539a69a5ef643e9aefcc69f Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Fri, 6 Dec 2024 16:49:53 +0530 Subject: [PATCH 06/11] chore: update deploy script to copy dependencies first --- .github/workflows/deploy.yml | 124 +++++++++++++---------------------- 1 file changed, 44 insertions(+), 80 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f28ef1568..b6ba921a6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -77,12 +77,12 @@ jobs: echo "Checkout SHA: $sha" echo "SHA=$sha" >> $GITHUB_OUTPUT - - name: Checkout + - name: Checkout source code uses: actions/checkout@v4 with: ref: ${{ steps.getSHA.outputs.SHA }} - - name: Get new version number + - name: Get new versions run: | current_version_v1=$(jq -r .version packages/analytics-v1.1/package.json) current_version=$(jq -r .version packages/analytics-js/package.json) @@ -96,7 +96,7 @@ jobs: node-version-file: '.nvmrc' cache: 'npm' - - name: Install dependencies + - name: Setup workspace env: HUSKY: 0 REMOTE_MODULES_BASE_PATH: 'https://cdn.rudderlabs.com/${{ inputs.s3_dir_path }}/modern/plugins' @@ -105,7 +105,7 @@ jobs: run: | npm run setup:ci - - name: Build release artifacts + - name: Build artifacts env: BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }} @@ -113,19 +113,19 @@ jobs: npm run build:browser npm run build:browser:modern - - name: Sync Adobe Analytics assets to S3 + - name: Copy assets to S3 if: ${{ inputs.environment == 'production' }} run: | aws s3 cp assets/integrations/AdobeAnalytics/ s3://${{ secrets.AWS_S3_BUCKET_NAME }}/adobe-analytics-js --recursive --cache-control ${{ env.CACHE_CONTROL }} - - name: Create Cloudfront invalidation + - name: Invalidate CloudFront cache for assets if: ${{ inputs.environment == 'production' }} run: | aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/adobe-analytics-js*" - - name: Sync files to S3 + - name: Copy SDK dependencies to S3 + if: false run: | - core_sdk_path_prefix="packages/analytics-js/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" s3_relative_path_prefix="${{ inputs.s3_dir_path }}" @@ -153,12 +153,10 @@ jobs: mv "$tmp_file" "$plugins_path_prefix/modern/plugins/$plugins_zip_file" # Upload all the files to S3 - aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args - # aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args + aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args - # aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args - # aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args - # aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args + aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args + aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args # Generate the HTML file to list all the integrations ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file @@ -173,14 +171,24 @@ jobs: aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args - - name: Create Cloudfront invalidation + - name: Copy core SDK artifacts to S3 + run: | + core_sdk_path_prefix="packages/analytics-js/dist/cdn" + s3_relative_path_prefix="${{ inputs.s3_dir_path }}" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix" + copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" + + # Upload all the files to S3 + aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args + aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args + + - name: Invalidate CloudFront cache for all the SDK artifacts run: | AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ inputs.s3_dir_path }}/*" - - name: Sync files to S3 versioned directory + - name: Copy SDK dependencies to S3 (versioned directory) if: ${{ inputs.environment == 'production' }} run: | - core_sdk_path_prefix="packages/analytics-js/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" s3_relative_path_prefix="${{ env.CURRENT_VERSION_VALUE }}" @@ -194,10 +202,8 @@ jobs: plugins_html_file="list.html" # Copy all the files to S3 - aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args - aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args @@ -214,53 +220,22 @@ jobs: aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args - - name: Create Cloudfront invalidation - if: ${{ inputs.environment == 'production' }} - run: | - AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_VALUE }}/*" - - # TODO: The '/latest' directory is unused. Might be removed in future. - - name: Sync files to S3 latest + - name: Copy core SDK artifacts to S3 (versioned directory) if: ${{ inputs.environment == 'production' }} run: | core_sdk_path_prefix="packages/analytics-js/dist/cdn" - integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" - plugins_path_prefix="packages/analytics-js-plugins/dist/cdn" - s3_relative_path_prefix="latest" + s3_relative_path_prefix="${{ env.CURRENT_VERSION_VALUE }}" s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" - integration_sdks_zip_file="all_integration_sdks.tar.gz" - plugins_zip_file="all_plugins.tar.gz" - - integration_sdks_html_file="list.html" - plugins_html_file="list.html" - # Copy all the files to S3 aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_args - aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args - aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_args - aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args - - # Generate the HTML file to list all the integrations - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file - - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file - - # Generate the HTML file to list all the plugins - ./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file - # Copy all the HTML files to S3 - aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args - aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args - - - name: Create Cloudfront invalidation + - name: Invalidate CloudFront cache for all the SDK artifacts (versioned directory) if: ${{ inputs.environment == 'production' }} run: | - AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/latest*" + AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_VALUE }}/*" - name: Send message to Slack channel id: slack @@ -306,57 +281,46 @@ jobs: # Below steps are for v1.1 SDK (legacy) - - name: Sync files to S3 v1.1 directory + - name: Copy legacy SDK dependencies to S3 run: | - core_sdk_path_prefix="packages/analytics-v1.1/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ inputs.s3_dir_path_legacy }}" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" - aws s3 cp $core_sdk_path_prefix/legacy/ $s3_path_prefix/ $copy_args aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/js-integrations/ $copy_args + aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args + - name: Copy core legacy SDK artifacts to S3 + run: | + core_sdk_path_prefix="packages/analytics-v1.1/dist/cdn" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ inputs.s3_dir_path_legacy }}" + copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" + + aws s3 cp $core_sdk_path_prefix/legacy/ $s3_path_prefix/ $copy_args aws s3 cp $core_sdk_path_prefix/modern/ $s3_path_prefix/modern/ $copy_args - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args - - name: Create Cloudfront invalidation + - name: Invalidate CloudFront cache for all the legacy SDK artifacts run: | - AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ inputs.s3_dir_path_legacy }}*" + AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ inputs.s3_dir_path_legacy }}/*" - - name: Sync files to S3 v1.1 versioned directory - if: ${{ inputs.environment == 'production' }} + - name: Copy legacy SDK dependencies to S3 (versioned directory) run: | - core_sdk_path_prefix="packages/analytics-v1.1/dist/cdn" integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ env.CURRENT_VERSION_V1_VALUE }}" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" - aws s3 cp $core_sdk_path_prefix/legacy/ $s3_path_prefix/ $copy_args aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/js-integrations/ $copy_args - - aws s3 cp $core_sdk_path_prefix/modern/ $s3_path_prefix/modern/ $copy_args aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args - - name: Create Cloudfront invalidation - if: ${{ inputs.environment == 'production' }} - run: | - AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_V1_VALUE }}*" - - - name: Sync files to S3 latest (v1.1) - if: ${{ inputs.environment == 'production' }} + - name: Copy core legacy SDK artifacts to S3 (versioned directory) run: | core_sdk_path_prefix="packages/analytics-v1.1/dist/cdn" - integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" - s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/latest" + s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/${{ env.CURRENT_VERSION_V1_VALUE }}" copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}" aws s3 cp $core_sdk_path_prefix/legacy/ $s3_path_prefix/ $copy_args - aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/js-integrations/ $copy_args - aws s3 cp $core_sdk_path_prefix/modern/ $s3_path_prefix/modern/ $copy_args - aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args - - name: Create Cloudfront invalidation - if: ${{ inputs.environment == 'production' }} + - name: Invalidate CloudFront cache for all the legacy SDK artifacts (versioned directory) run: | - AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/latest*" + AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_V1_VALUE }}/*" From 4e41fe0c5e402e6c760d95c565acfacfd8fc1013 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Fri, 6 Dec 2024 20:45:02 +0530 Subject: [PATCH 07/11] chore: include url in cdn path error messages --- .../components/configManager/cdnPaths.test.ts | 69 ++++++++++++------- .../components/configManager/util/cdnPaths.ts | 2 +- .../analytics-js/src/constants/logMessages.ts | 4 +- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts b/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts index 1f2e91288..51e653aed 100644 --- a/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts @@ -1,10 +1,9 @@ -import { CDN_INT_DIR } from '@rudderstack/analytics-js-common/constants/urls'; import { getIntegrationsCDNPath, getPluginsCDNPath, } from '../../../src/components/configManager/util/cdnPaths'; -import { getSDKUrl } from '../../../src/components/configManager/util/commonUtil'; -import { DEST_SDK_BASE_URL, SDK_CDN_BASE_URL } from '../../../src/constants/urls'; + +const getSDKUrlMock = jest.fn(); jest.mock('../../../src/components/configManager/util/commonUtil.ts', () => { const originalModule = jest.requireActual( @@ -14,62 +13,75 @@ jest.mock('../../../src/components/configManager/util/commonUtil.ts', () => { return { __esModule: true, ...originalModule, - getSDKUrl: jest.fn(), + getSDKUrl: (...args: any[]) => getSDKUrlMock(...args), }; }); describe('CDN path utilities', () => { describe('getIntegrationsCDNPath', () => { - const dummyCustomURL = 'https://www.dummy.url/integrations'; + const dummyCustomURL = 'https://www.dummy.url/integrations/'; const dummyScriptURL = 'https://www.dummy.url/fromScript/v3/modern/rsa.min.js'; const dummyVersion = '3.x.x'; beforeEach(() => { - getSDKUrl.mockImplementation(() => dummyScriptURL); + getSDKUrlMock.mockImplementation(() => dummyScriptURL); }); afterEach(() => { jest.resetAllMocks(); }); - it('should return custom url if valid url is provided', () => { + it('should return custom URL if it is valid', () => { const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, false, dummyCustomURL); - expect(integrationsCDNPath).toBe(dummyCustomURL); + expect(integrationsCDNPath).toBe('https://www.dummy.url/integrations'); }); - it('should throw error if invalid custom url is provided', () => { + it('should throw error if invalid custom URL is provided', () => { const integrationsCDNPath = () => getIntegrationsCDNPath(dummyVersion, false, '/'); expect(integrationsCDNPath).toThrow( - 'Failed to load the SDK as the base URL for integrations is not valid.', + 'Failed to load the SDK as the base URL "/" for integrations is not valid.', ); }); it('should return script src path if script src exists and integrations version is not locked', () => { - const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, false, undefined); + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, false); expect(integrationsCDNPath).toBe( 'https://www.dummy.url/fromScript/v3/modern/js-integrations', ); }); it('should return script src path with versioned folder if script src exists and integrations version is locked', () => { - const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true, undefined); + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true); expect(integrationsCDNPath).toBe( 'https://www.dummy.url/fromScript/3.x.x/modern/js-integrations', ); }); it('should return default path if no script src exists and integrations version is not locked', () => { - getSDKUrl.mockImplementation(() => undefined); + getSDKUrlMock.mockImplementation(() => undefined); - const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, false, undefined); + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, false); expect(integrationsCDNPath).toBe('https://cdn.rudderlabs.com/v3/modern/js-integrations'); }); it('should return default path with versioned folder if no script src exists and integrations version is locked', () => { - getSDKUrl.mockImplementation(() => undefined); + getSDKUrlMock.mockImplementation(() => undefined); + + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true); + expect(integrationsCDNPath).toBe( + `https://cdn.rudderlabs.com/${dummyVersion}/modern/js-integrations`, + ); + }); + + it('should return that is not version locked when the script source is not as per the convention', () => { + getSDKUrlMock.mockImplementation( + () => 'https://www.dummy.url/fromScript/v3/custom/rsa.min.js', + ); - const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true, undefined); - expect(integrationsCDNPath).toBe(`${SDK_CDN_BASE_URL}/${dummyVersion}/modern/${CDN_INT_DIR}`); + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true); + expect(integrationsCDNPath).toBe( + `https://www.dummy.url/fromScript/v3/custom/js-integrations`, + ); }); }); @@ -79,7 +91,7 @@ describe('CDN path utilities', () => { const dummyVersion = '3.x.x'; beforeEach(() => { - getSDKUrl.mockImplementation(() => dummyScriptURL); + getSDKUrlMock.mockImplementation(() => dummyScriptURL); }); afterEach(() => { @@ -91,10 +103,10 @@ describe('CDN path utilities', () => { expect(pluginsCDNPath).toBe('https://www.dummy.url/plugins'); }); - it('should throw error if invalid custom url is provided', () => { + it('should throw error if invalid custom URL is provided', () => { const pluginsCDNPath = () => getPluginsCDNPath(dummyVersion, false, 'htp:/some.broken.url'); expect(pluginsCDNPath).toThrow( - 'Failed to load the SDK as the base URL for plugins is not valid.', + 'Failed to load the SDK as the base URL "htp:/some.broken.url" for plugins is not valid.', ); }); @@ -109,17 +121,26 @@ describe('CDN path utilities', () => { }); it('should return default path if no script src exists and plugins version is not locked', () => { - getSDKUrl.mockImplementation(() => undefined); + getSDKUrlMock.mockImplementation(() => undefined); - const pluginsCDNPath = getPluginsCDNPath(dummyVersion, false, undefined); + const pluginsCDNPath = getPluginsCDNPath(dummyVersion, false); expect(pluginsCDNPath).toBe('https://cdn.rudderlabs.com/v3/modern/plugins'); }); it('should return default path if no script src exists but plugins version is locked', () => { - getSDKUrl.mockImplementation(() => undefined); + getSDKUrlMock.mockImplementation(() => undefined); - const pluginsCDNPath = getPluginsCDNPath(dummyVersion, true, undefined); + const pluginsCDNPath = getPluginsCDNPath(dummyVersion, true); expect(pluginsCDNPath).toBe('https://cdn.rudderlabs.com/3.x.x/modern/plugins'); }); + + it('should return that is not version locked when the script source is not as per the convention', () => { + getSDKUrlMock.mockImplementation( + () => 'https://www.dummy.url/fromScript/v3/custom/rsa.min.js', + ); + + const pluginsCDNPath = getPluginsCDNPath(dummyVersion, true); + expect(pluginsCDNPath).toBe(`https://www.dummy.url/fromScript/v3/custom/plugins`); + }); }); }); diff --git a/packages/analytics-js/src/components/configManager/util/cdnPaths.ts b/packages/analytics-js/src/components/configManager/util/cdnPaths.ts index 0cc0070b1..f050d0e34 100644 --- a/packages/analytics-js/src/components/configManager/util/cdnPaths.ts +++ b/packages/analytics-js/src/components/configManager/util/cdnPaths.ts @@ -22,7 +22,7 @@ const getSDKComponentBaseURL = ( if (customURL) { if (!isValidURL(customURL)) { - throw new Error(COMPONENT_BASE_URL_ERROR(componentType)); + throw new Error(COMPONENT_BASE_URL_ERROR(componentType, customURL)); } return removeTrailingSlashes(customURL) as string; diff --git a/packages/analytics-js/src/constants/logMessages.ts b/packages/analytics-js/src/constants/logMessages.ts index 0020c5fdb..d521f97ed 100644 --- a/packages/analytics-js/src/constants/logMessages.ts +++ b/packages/analytics-js/src/constants/logMessages.ts @@ -19,8 +19,8 @@ const EVENT_OBJECT_GENERATION_ERROR = `Failed to generate the event object.`; const PLUGIN_EXT_POINT_MISSING_ERROR = `Failed to invoke plugin because the extension point name is missing.`; const PLUGIN_EXT_POINT_INVALID_ERROR = `Failed to invoke plugin because the extension point name is invalid.`; -const COMPONENT_BASE_URL_ERROR = (component: string): string => - `Failed to load the SDK as the base URL for ${component} is not valid.`; +const COMPONENT_BASE_URL_ERROR = (component: string, url: string): string => + `Failed to load the SDK as the base URL "${url}" for ${component} is not valid.`; // ERROR const UNSUPPORTED_CONSENT_MANAGER_ERROR = ( From 007f4a01ce2768ef4a1af937150eac883a098dbb Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Fri, 6 Dec 2024 22:28:22 +0530 Subject: [PATCH 08/11] fix: lock deps version through build --- jest/jest.setup-dom.js | 1 + packages/analytics-js/.env.example | 3 ++- .../configManager/commonUtil.test.ts | 13 +++---------- packages/analytics-js/public/index.html | 18 +++++++++++++----- packages/analytics-js/rollup.config.mjs | 13 +++++++++---- .../configManager/util/commonUtil.ts | 2 +- .../src/components/utilities/loadOptions.ts | 4 ++-- .../src/state/slices/loadOptions.ts | 4 ++-- types/global.d.ts | 2 ++ 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/jest/jest.setup-dom.js b/jest/jest.setup-dom.js index 11be1cf08..79263911d 100644 --- a/jest/jest.setup-dom.js +++ b/jest/jest.setup-dom.js @@ -6,6 +6,7 @@ global.window.document.body.innerHTML = documentHTML; global.window.innerWidth = 1680; global.window.innerHeight = 1024; global.window.__BUNDLE_ALL_PLUGINS__ = false; +global.window.__LOCK_DEPS_VERSION__ = false; global.window.__IS_LEGACY_BUILD__ = false; global.window.__IS_DYNAMIC_CUSTOM_BUNDLE__ = false; global.PromiseRejectionEvent = function (reason) { diff --git a/packages/analytics-js/.env.example b/packages/analytics-js/.env.example index eb0bfe7e9..fce36073b 100644 --- a/packages/analytics-js/.env.example +++ b/packages/analytics-js/.env.example @@ -1,7 +1,8 @@ # Variables required for the example WRITE_KEY= DATAPLANE_URL= -TEST_FILE_PATH= + +# Optional variables CONFIG_SERVER_HOST= DEST_SDK_BASE_URL= REMOTE_MODULES_BASE_PATH= diff --git a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts index 3c58904fe..067b196ae 100644 --- a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts @@ -70,21 +70,14 @@ describe('Config Manager Common Utilities', () => { ['https://www.dummy.url/fromScript/v3/rsa.min.js'], ], [undefined, ['https://www.dummy.url/fromScript/v3/other.min.js']], - [ - 'https://www.dummy.url/fromScript/v3/rsa.js', - ['https://www.dummy.url/fromScript/v3/rsa.js'], - ], + [undefined, ['https://www.dummy.url/fromScript/v3/rsa.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rudder.min.js']], [undefined, ['https://www.dummy.url/fromScript/v3/analytics.min.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min']], - [ - 'https://www.dummy.url/fromScript/v3/rsa.js', - ['https://www.dummy.url/fromScript/v3/rsa.js'], - ], [undefined, ['https://www.dummy.url/fromScript/v3/rsa']], [undefined, ['https://www.dummy.url/fromScript/v3rsa.min.js']], ['/rsa.min.js', ['/rsa.min.js']], - ['/rsa.js', ['/rsa.js']], + [undefined, ['/rsa.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js']], [ 'https://www.dummy.url/fromScript/v3/rs.min.js', @@ -93,7 +86,7 @@ describe('Config Manager Common Utilities', () => { [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js', 'writeKey-1']], [undefined, ['https://www.dummy.url/fromScript/v3/rsamin.js']], ['rsa.min.js', ['rsa.min.js']], - ['rsa.js', ['rsa.js']], + [undefined, ['rsa.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min.jsx']], [undefined, [null]], ]; diff --git a/packages/analytics-js/public/index.html b/packages/analytics-js/public/index.html index fb35e033a..420953747 100644 --- a/packages/analytics-js/public/index.html +++ b/packages/analytics-js/public/index.html @@ -93,10 +93,6 @@ } var loadOptions = { logLevel: 'DEBUG', - configUrl: '__CONFIG_SERVER_HOST__', - destSDKBaseURL: - '__DEST_SDK_BASE_URL__' + window.rudderAnalyticsBuildType + '/js-integrations', - pluginsSDKBaseURL: '__PLUGINS_BASE_URL__' + window.rudderAnalyticsBuildType + '/plugins', // integrations: { // All: false // }, @@ -168,6 +164,18 @@ // } }; + const envDestSDKBaseURL = '__DEST_SDK_BASE_URL__'; + if (envDestSDKBaseURL !== 'undefined') { + loadOptions.destSDKBaseURL = envDestSDKBaseURL + window.rudderAnalyticsBuildType + '/js-integrations'; + } + const envPluginsSDKBaseURL = '__PLUGINS_BASE_URL__'; + if (envPluginsSDKBaseURL !== 'undefined') { + loadOptions.pluginsSDKBaseURL = envPluginsSDKBaseURL + window.rudderAnalyticsBuildType + '/plugins'; + } + const envConfigUrl = '__CONFIG_SERVER_HOST__'; + if (envConfigUrl !== 'undefined') { + loadOptions.configUrl = envConfigUrl; + } rudderanalytics.load('__WRITE_KEY__', '__DATAPLANE_URL__', loadOptions); } } @@ -391,4 +399,4 @@

Test HTML file

} - \ No newline at end of file + diff --git a/packages/analytics-js/rollup.config.mjs b/packages/analytics-js/rollup.config.mjs index 2a1a2e8ea..5db56d0c8 100644 --- a/packages/analytics-js/rollup.config.mjs +++ b/packages/analytics-js/rollup.config.mjs @@ -32,8 +32,11 @@ const isModuleFederatedBuild = !isDynamicCustomBuild && !isLegacyBuild; const sourceMapType = process.env.PROD_DEBUG === 'inline' ? 'inline' : process.env.PROD_DEBUG === 'true'; const cdnPath = isDynamicCustomBuild ? `dynamicCdnBundle` : `cdn`; -const remotePluginsBasePath = - process.env.REMOTE_MODULES_BASE_PATH || `http://localhost:3002/${cdnPath}/`; +let remotePluginsBasePath = + process.env.REMOTE_MODULES_BASE_PATH; +remotePluginsBasePath = remotePluginsBasePath?.endsWith('/') ? remotePluginsBasePath.substring(0, remotePluginsBasePath.length - 1) : remotePluginsBasePath; +let destSDKBaseURL = process.env.DEST_SDK_BASE_URL; +destSDKBaseURL = destSDKBaseURL?.endsWith('/') ? destSDKBaseURL.substring(0, destSDKBaseURL.length - 1) : destSDKBaseURL; const outDirNpmRoot = `dist/npm`; const outDirCDNRoot = isDynamicCustomBuild ? `dist/${cdnPath}` : `dist/${cdnPath}`; let outDirNpm = `${outDirNpmRoot}${variantSubfolder}`; @@ -43,6 +46,7 @@ const modName = 'rudderanalytics'; const remotePluginsExportsFilename = `rsa-plugins`; const remotePluginsHostPromise = `Promise.resolve(window.RudderStackGlobals && window.RudderStackGlobals.app && window.RudderStackGlobals.app.pluginsCDNPath ? \`\${window.RudderStackGlobals.app.pluginsCDNPath}/${remotePluginsExportsFilename}.js\` : \`${remotePluginsBasePath}/${remotePluginsExportsFilename}.js\`)`; const moduleType = process.env.MODULE_TYPE || 'cdn'; +const lockDepsVersion = process.env.LOCK_DEPS_VERSION || 'false'; const isCDNPackageBuild = moduleType === 'cdn'; let bugsnagSDKUrl = 'https://d2wy8f7a9ursnm.cloudfront.net/v6/bugsnag.min.js'; let polyfillIoUrl = 'https://polyfill-fastly.io/v3/polyfill.min.js'; @@ -190,6 +194,7 @@ export function getDefaultConfig(distName) { __IS_LEGACY_BUILD__: isLegacyBuild, __PACKAGE_VERSION__: version, __MODULE_TYPE__: moduleType, + __LOCK_DEPS_VERSION__: lockDepsVersion, __SDK_BUNDLE_FILENAME__: distName, __RS_POLYFILLIO_SDK_URL__: polyfillIoUrl, __RS_BUGSNAG_API_KEY__: process.env.BUGSNAG_API_KEY || '{{__RS_BUGSNAG_API_KEY__}}', @@ -262,8 +267,8 @@ export function getDefaultConfig(distName) { replaceVars: { __WRITE_KEY__: process.env.WRITE_KEY, __DATAPLANE_URL__: process.env.DATAPLANE_URL, - __CONFIG_SERVER_HOST__: process.env.CONFIG_SERVER_HOST || '', - __DEST_SDK_BASE_URL__: process.env.DEST_SDK_BASE_URL, + __CONFIG_SERVER_HOST__: process.env.CONFIG_SERVER_HOST, + __DEST_SDK_BASE_URL__: destSDKBaseURL, __PLUGINS_BASE_URL__: remotePluginsBasePath, __SDK_BUNDLE_FILENAME__: distName, }, diff --git a/packages/analytics-js/src/components/configManager/util/commonUtil.ts b/packages/analytics-js/src/components/configManager/util/commonUtil.ts index 04cf64a3c..78071446b 100644 --- a/packages/analytics-js/src/components/configManager/util/commonUtil.ts +++ b/packages/analytics-js/src/components/configManager/util/commonUtil.ts @@ -69,7 +69,7 @@ const getSDKUrl = (): string | undefined => { // TODO: We need to remove this once all the customers upgrade to the // latest SDK loading snippet const scripts = document.getElementsByTagName('script'); - const sdkFileNameRegex = /(?:^|\/)rsa(\.min)?\.js$/; + const sdkFileNameRegex = /(?:^|\/)rsa\.min\.js$/; // eslint-disable-next-line no-restricted-syntax for (const script of scripts) { diff --git a/packages/analytics-js/src/components/utilities/loadOptions.ts b/packages/analytics-js/src/components/utilities/loadOptions.ts index 0cf244feb..44790addd 100644 --- a/packages/analytics-js/src/components/utilities/loadOptions.ts +++ b/packages/analytics-js/src/components/utilities/loadOptions.ts @@ -103,9 +103,9 @@ const normalizeLoadOptions = ( normalizedLoadOpts.queueOptions = removeUndefinedAndNullValues(normalizedLoadOpts.queueOptions); } - normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion !== false; + normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion === true; - normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion !== false; + normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion === true; if (!isNumber(normalizedLoadOpts.dataPlaneEventsBufferTimeout)) { delete normalizedLoadOpts.dataPlaneEventsBufferTimeout; diff --git a/packages/analytics-js/src/state/slices/loadOptions.ts b/packages/analytics-js/src/state/slices/loadOptions.ts index 74c122895..dbc612612 100644 --- a/packages/analytics-js/src/state/slices/loadOptions.ts +++ b/packages/analytics-js/src/state/slices/loadOptions.ts @@ -25,8 +25,8 @@ const defaultLoadOptions: LoadOptions = { beaconQueueOptions: {}, destinationsQueueOptions: {}, queueOptions: {}, - lockIntegrationsVersion: true, - lockPluginsVersion: true, + lockIntegrationsVersion: __LOCK_DEPS_VERSION__, + lockPluginsVersion: __LOCK_DEPS_VERSION__, uaChTrackLevel: 'none', plugins: [], useGlobalIntegrationsConfigInEvents: false, diff --git a/types/global.d.ts b/types/global.d.ts index af82260a2..1c3ee3f5f 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -16,3 +16,5 @@ declare const __IS_DYNAMIC_CUSTOM_BUNDLE__: boolean; declare const __IS_LEGACY_BUILD__: boolean; declare const __BUNDLED_PLUGINS_LIST__: string | undefined; + +declare const __LOCK_DEPS_VERSION__: boolean; From e504da7388ca6794cafabb47f1931847dd757d88 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Fri, 6 Dec 2024 22:39:26 +0530 Subject: [PATCH 09/11] chore: add env to deploy workflow --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b6ba921a6..e378d0e3b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -102,6 +102,7 @@ jobs: REMOTE_MODULES_BASE_PATH: 'https://cdn.rudderlabs.com/${{ inputs.s3_dir_path }}/modern/plugins' BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }} + LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && true || false }} run: | npm run setup:ci @@ -109,6 +110,7 @@ jobs: env: BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }} + LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && true || false }} run: | npm run build:browser npm run build:browser:modern From a4f80d03f236fb395890fc4d30d87fc9cf2893ec Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Mon, 9 Dec 2024 20:25:39 +0530 Subject: [PATCH 10/11] fix: cdn paths edge case handling --- .../components/configManager/cdnPaths.test.ts | 24 +++++++++++++++++++ .../configManager/commonUtil.test.ts | 9 ++++--- .../components/configManager/util/cdnPaths.ts | 8 +++---- .../configManager/util/commonUtil.ts | 2 +- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts b/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts index 51e653aed..28e3ba401 100644 --- a/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/cdnPaths.test.ts @@ -83,6 +83,18 @@ describe('CDN path utilities', () => { `https://www.dummy.url/fromScript/v3/custom/js-integrations`, ); }); + + it('should return the url that is not version locked when the script source is slightly off from the convention', () => { + // /v3/modern/js-integrations matches but it is in the middle of the path + getSDKUrlMock.mockImplementation( + () => 'https://www.dummy.url/fromScript/v3/modern/js-integrations/custom/rsa.min.js', + ); + + const integrationsCDNPath = getIntegrationsCDNPath(dummyVersion, true); + expect(integrationsCDNPath).toBe( + `https://www.dummy.url/fromScript/v3/modern/js-integrations/custom/js-integrations`, + ); + }); }); describe('getPluginsCDNPath', () => { @@ -142,5 +154,17 @@ describe('CDN path utilities', () => { const pluginsCDNPath = getPluginsCDNPath(dummyVersion, true); expect(pluginsCDNPath).toBe(`https://www.dummy.url/fromScript/v3/custom/plugins`); }); + + it('should return the url that is not version locked when the script source is slightly off from the convention', () => { + // /v3/modern/plugins matches but it is in the middle of the path + getSDKUrlMock.mockImplementation( + () => 'https://www.dummy.url/fromScript/v3/modern/plugins/custom/rsa.min.js', + ); + + const pluginsCDNPath = getPluginsCDNPath(dummyVersion, true); + expect(pluginsCDNPath).toBe( + `https://www.dummy.url/fromScript/v3/modern/plugins/custom/plugins`, + ); + }); }); }); diff --git a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts index 067b196ae..d3e1b2773 100644 --- a/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts +++ b/packages/analytics-js/__tests__/components/configManager/commonUtil.test.ts @@ -70,14 +70,17 @@ describe('Config Manager Common Utilities', () => { ['https://www.dummy.url/fromScript/v3/rsa.min.js'], ], [undefined, ['https://www.dummy.url/fromScript/v3/other.min.js']], - [undefined, ['https://www.dummy.url/fromScript/v3/rsa.js']], + [ + 'https://www.dummy.url/fromScript/v3/rsa.js', + ['https://www.dummy.url/fromScript/v3/rsa.js'], + ], [undefined, ['https://www.dummy.url/fromScript/v3/rudder.min.js']], [undefined, ['https://www.dummy.url/fromScript/v3/analytics.min.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min']], [undefined, ['https://www.dummy.url/fromScript/v3/rsa']], [undefined, ['https://www.dummy.url/fromScript/v3rsa.min.js']], ['/rsa.min.js', ['/rsa.min.js']], - [undefined, ['/rsa.js']], + ['/rsa.js', ['/rsa.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js']], [ 'https://www.dummy.url/fromScript/v3/rs.min.js', @@ -86,7 +89,7 @@ describe('Config Manager Common Utilities', () => { [undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js', 'writeKey-1']], [undefined, ['https://www.dummy.url/fromScript/v3/rsamin.js']], ['rsa.min.js', ['rsa.min.js']], - [undefined, ['rsa.js']], + ['rsa.js', ['rsa.js']], [undefined, ['https://www.dummy.url/fromScript/v3/rsa.min.jsx']], [undefined, [null]], ]; diff --git a/packages/analytics-js/src/components/configManager/util/cdnPaths.ts b/packages/analytics-js/src/components/configManager/util/cdnPaths.ts index f050d0e34..a6dc80c29 100644 --- a/packages/analytics-js/src/components/configManager/util/cdnPaths.ts +++ b/packages/analytics-js/src/components/configManager/util/cdnPaths.ts @@ -18,8 +18,6 @@ const getSDKComponentBaseURL = ( lockVersion: boolean, customURL?: string, ) => { - let sdkComponentURL = ''; - if (customURL) { if (!isValidURL(customURL)) { throw new Error(COMPONENT_BASE_URL_ERROR(componentType, customURL)); @@ -29,11 +27,13 @@ const getSDKComponentBaseURL = ( } const sdkURL = getSDKUrl(); - sdkComponentURL = sdkURL ? sdkURL.split('/').slice(0, -1).concat(pathSuffix).join('/') : baseURL; + let sdkComponentURL = sdkURL + ? sdkURL.split('/').slice(0, -1).concat(pathSuffix).join('/') + : baseURL; if (lockVersion) { sdkComponentURL = sdkComponentURL.replace( - `/${CDN_ARCH_VERSION_DIR}/${BUILD_TYPE}/${pathSuffix}`, + new RegExp(`/${CDN_ARCH_VERSION_DIR}/${BUILD_TYPE}/${pathSuffix}$`), `/${currentVersion}/${BUILD_TYPE}/${pathSuffix}`, ); } diff --git a/packages/analytics-js/src/components/configManager/util/commonUtil.ts b/packages/analytics-js/src/components/configManager/util/commonUtil.ts index 78071446b..04cf64a3c 100644 --- a/packages/analytics-js/src/components/configManager/util/commonUtil.ts +++ b/packages/analytics-js/src/components/configManager/util/commonUtil.ts @@ -69,7 +69,7 @@ const getSDKUrl = (): string | undefined => { // TODO: We need to remove this once all the customers upgrade to the // latest SDK loading snippet const scripts = document.getElementsByTagName('script'); - const sdkFileNameRegex = /(?:^|\/)rsa\.min\.js$/; + const sdkFileNameRegex = /(?:^|\/)rsa(\.min)?\.js$/; // eslint-disable-next-line no-restricted-syntax for (const script of scripts) { From c572c44e4b5359bfbf299646fa9e28ebb5366fc3 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju Date: Mon, 9 Dec 2024 20:33:45 +0530 Subject: [PATCH 11/11] chore: fix lock deps envs --- .github/workflows/deploy.yml | 5 +++-- packages/analytics-js/rollup.config.mjs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e378d0e3b..115f37b9c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -102,7 +102,7 @@ jobs: REMOTE_MODULES_BASE_PATH: 'https://cdn.rudderlabs.com/${{ inputs.s3_dir_path }}/modern/plugins' BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }} - LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && true || false }} + LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && 'true' || 'false' }} run: | npm run setup:ci @@ -110,7 +110,7 @@ jobs: env: BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }} - LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && true || false }} + LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && 'true' || 'false' }} run: | npm run build:browser npm run build:browser:modern @@ -126,6 +126,7 @@ jobs: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/adobe-analytics-js*" - name: Copy SDK dependencies to S3 + # IMPORTANT: Don't remove the if condition. This is required to avoid copying the dependencies to the common path. if: false run: | integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn" diff --git a/packages/analytics-js/rollup.config.mjs b/packages/analytics-js/rollup.config.mjs index 5db56d0c8..617e18b5b 100644 --- a/packages/analytics-js/rollup.config.mjs +++ b/packages/analytics-js/rollup.config.mjs @@ -46,7 +46,7 @@ const modName = 'rudderanalytics'; const remotePluginsExportsFilename = `rsa-plugins`; const remotePluginsHostPromise = `Promise.resolve(window.RudderStackGlobals && window.RudderStackGlobals.app && window.RudderStackGlobals.app.pluginsCDNPath ? \`\${window.RudderStackGlobals.app.pluginsCDNPath}/${remotePluginsExportsFilename}.js\` : \`${remotePluginsBasePath}/${remotePluginsExportsFilename}.js\`)`; const moduleType = process.env.MODULE_TYPE || 'cdn'; -const lockDepsVersion = process.env.LOCK_DEPS_VERSION || 'false'; +const lockDepsVersion = process.env.LOCK_DEPS_VERSION ?? false; const isCDNPackageBuild = moduleType === 'cdn'; let bugsnagSDKUrl = 'https://d2wy8f7a9ursnm.cloudfront.net/v6/bugsnag.min.js'; let polyfillIoUrl = 'https://polyfill-fastly.io/v3/polyfill.min.js';