From 1f114a19ac14ffd9af6ae876a54d4d19afd80d65 Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:55:10 +0530 Subject: [PATCH 01/13] fix: type issues (#1663) * fix: update consent management options types to make all fields optional * fix: update rudderanalytics type * fix: preloaded types * fix: type cast * fix: types for loading script module --- .../analytics-js-common/src/types/Consent.ts | 4 ++-- .../types/rudderanalytics.d.ts | 16 ---------------- packages/analytics-js/src/app/RudderAnalytics.ts | 2 +- .../src/components/preloadBuffer/types.ts | 2 +- .../src/components/utilities/consent.ts | 4 ++-- packages/analytics-js/src/index.ts | 9 +++------ .../analytics-js/src/types/rudderanalytics.d.ts | 2 +- packages/loading-scripts/src/index.ts | 4 ++-- .../src/types/rudderanalytics.d.ts | 2 +- .../sanity-suite/src/types/rudderanalytics.d.ts | 2 +- 10 files changed, 14 insertions(+), 33 deletions(-) delete mode 100644 packages/analytics-js-common/types/rudderanalytics.d.ts diff --git a/packages/analytics-js-common/src/types/Consent.ts b/packages/analytics-js-common/src/types/Consent.ts index 6d5d1f51a..ab7af0148 100644 --- a/packages/analytics-js-common/src/types/Consent.ts +++ b/packages/analytics-js-common/src/types/Consent.ts @@ -31,8 +31,8 @@ export type ConsentResolutionStrategy = 'and' | 'or'; export type Consents = string[]; export type ConsentManagementOptions = { - enabled: boolean; - provider: ConsentManagementProvider; + enabled?: boolean; + provider?: ConsentManagementProvider; allowedConsentIds?: Consents; deniedConsentIds?: Consents; }; diff --git a/packages/analytics-js-common/types/rudderanalytics.d.ts b/packages/analytics-js-common/types/rudderanalytics.d.ts deleted file mode 100644 index a1b747c52..000000000 --- a/packages/analytics-js-common/types/rudderanalytics.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { - IRudderStackGlobals, - RudderAnalytics, - PreloadedEventCall, - RudderAnalyticsPreloader, -} from '@rudderstack/analytics-js'; - -declare global { - interface Window { - rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader; - RudderStackGlobals: IRudderStackGlobals; - rudderAnalyticsMount: () => void; - rudderAnalyticsBuildType: 'legacy' | 'modern'; - RudderSnippetVersion?: string; - } -} diff --git a/packages/analytics-js/src/app/RudderAnalytics.ts b/packages/analytics-js/src/app/RudderAnalytics.ts index a6db07148..7478cd7dd 100644 --- a/packages/analytics-js/src/app/RudderAnalytics.ts +++ b/packages/analytics-js/src/app/RudderAnalytics.ts @@ -139,7 +139,7 @@ class RudderAnalytics implements IRudderAnalytics { */ triggerBufferedLoadEvent() { const preloadedEventsArray = Array.isArray((globalThis as typeof window).rudderanalytics) - ? ((globalThis as typeof window).rudderanalytics as PreloadedEventCall[]) + ? ((globalThis as typeof window).rudderanalytics as unknown as PreloadedEventCall[]) : ([] as PreloadedEventCall[]); // The array will be mutated in the below method diff --git a/packages/analytics-js/src/components/preloadBuffer/types.ts b/packages/analytics-js/src/components/preloadBuffer/types.ts index 49a108d7d..3b3cbfb2a 100644 --- a/packages/analytics-js/src/components/preloadBuffer/types.ts +++ b/packages/analytics-js/src/components/preloadBuffer/types.ts @@ -1,5 +1,5 @@ export type PreloadedEventCall = Array; export type RudderAnalyticsPreloader = { - [index: string]: (...args: number[]) => any; + [index: string]: (...args: any[]) => any; }; diff --git a/packages/analytics-js/src/components/utilities/consent.ts b/packages/analytics-js/src/components/utilities/consent.ts index a27e0c485..939ab2796 100644 --- a/packages/analytics-js/src/components/utilities/consent.ts +++ b/packages/analytics-js/src/components/utilities/consent.ts @@ -98,8 +98,8 @@ const getConsentManagerInfo = ( consentManagementOpts: ConsentManagementOptions, logger?: ILogger, ) => { - let { provider }: { provider: ConsentManagementProvider | undefined } = consentManagementOpts; - const consentManagerPluginName = ConsentManagersToPluginNameMap[provider]; + let { provider }: { provider?: ConsentManagementProvider } = consentManagementOpts; + const consentManagerPluginName = provider ? ConsentManagersToPluginNameMap[provider] : undefined; if (provider && !consentManagerPluginName) { logger?.error( UNSUPPORTED_CONSENT_MANAGER_ERROR(CONFIG_MANAGER, provider, ConsentManagersToPluginNameMap), diff --git a/packages/analytics-js/src/index.ts b/packages/analytics-js/src/index.ts index ea666431f..2560a91c4 100644 --- a/packages/analytics-js/src/index.ts +++ b/packages/analytics-js/src/index.ts @@ -1,8 +1,5 @@ import type { RudderAnalytics } from './app/RudderAnalytics'; -import type { - PreloadedEventCall, - RudderAnalyticsPreloader, -} from './components/preloadBuffer/types'; +import type { RudderAnalyticsPreloader } from './components/preloadBuffer/types'; import type { IRudderStackGlobals } from './app/IRudderStackGlobals'; export { @@ -26,13 +23,13 @@ export { type IdentifyTraits } from '@rudderstack/analytics-js-common/types/trai export { RudderAnalytics } from './app/RudderAnalytics'; export { type IRudderStackGlobals } from './app/IRudderStackGlobals'; export { - type PreloadedEventCall, type RudderAnalyticsPreloader, + type PreloadedEventCall, } from './components/preloadBuffer/types'; declare global { interface Window { - rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader; + rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined; RudderStackGlobals: IRudderStackGlobals; rudderAnalyticsMount: () => void; rudderAnalyticsBuildType: 'legacy' | 'modern'; diff --git a/packages/analytics-js/src/types/rudderanalytics.d.ts b/packages/analytics-js/src/types/rudderanalytics.d.ts index f8876c7f6..d36695f8f 100644 --- a/packages/analytics-js/src/types/rudderanalytics.d.ts +++ b/packages/analytics-js/src/types/rudderanalytics.d.ts @@ -7,7 +7,7 @@ import type { declare global { interface Window { - rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader; + rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined; RudderStackGlobals: IRudderStackGlobals; rudderAnalyticsMount: () => void; rudderAnalyticsBuildType: 'legacy' | 'modern'; diff --git a/packages/loading-scripts/src/index.ts b/packages/loading-scripts/src/index.ts index 743c86b31..70d68a7ef 100644 --- a/packages/loading-scripts/src/index.ts +++ b/packages/loading-scripts/src/index.ts @@ -18,7 +18,7 @@ const sdkName = 'rsa.min.js'; const asyncScript = true; window.rudderAnalyticsBuildType = 'legacy'; -window.rudderanalytics = []; +(window.rudderanalytics as unknown as PreloadedEventCall[]) = []; const methods: string[] = [ 'setDefaultInstanceKey', 'load', @@ -39,7 +39,7 @@ for (let i = 0; i < methods.length; i++) { const method = methods[i] as string; (window.rudderanalytics as unknown as RudderAnalyticsPreloader)[method] = (methodName => function () { - (window.rudderanalytics as PreloadedEventCall[]).push( + (window.rudderanalytics as unknown as PreloadedEventCall[]).push( [methodName].concat(Array.prototype.slice.call(arguments) as PreloadedEventCall), ); })(method); diff --git a/packages/loading-scripts/src/types/rudderanalytics.d.ts b/packages/loading-scripts/src/types/rudderanalytics.d.ts index a1b747c52..b7c64d731 100644 --- a/packages/loading-scripts/src/types/rudderanalytics.d.ts +++ b/packages/loading-scripts/src/types/rudderanalytics.d.ts @@ -7,7 +7,7 @@ import type { declare global { interface Window { - rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader; + rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined; RudderStackGlobals: IRudderStackGlobals; rudderAnalyticsMount: () => void; rudderAnalyticsBuildType: 'legacy' | 'modern'; diff --git a/packages/sanity-suite/src/types/rudderanalytics.d.ts b/packages/sanity-suite/src/types/rudderanalytics.d.ts index a1b747c52..b7c64d731 100644 --- a/packages/sanity-suite/src/types/rudderanalytics.d.ts +++ b/packages/sanity-suite/src/types/rudderanalytics.d.ts @@ -7,7 +7,7 @@ import type { declare global { interface Window { - rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader; + rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined; RudderStackGlobals: IRudderStackGlobals; rudderAnalyticsMount: () => void; rudderAnalyticsBuildType: 'legacy' | 'modern'; From 24d3a0b383f58b79fc1970d0c74761de30bb3f4a Mon Sep 17 00:00:00 2001 From: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:33:33 +0530 Subject: [PATCH 02/13] fix: replace polyfillio with fastly (#1664) --- packages/analytics-js/public/index-legacy-only.html | 2 +- packages/analytics-js/public/index.html | 2 +- packages/analytics-js/rollup.config.mjs | 3 +-- packages/analytics-v1.1/rollup-configs/rollup.utilities.mjs | 2 +- packages/loading-scripts/src/index.ts | 4 ++-- packages/sanity-suite/public/v1.1/index-cdn.html | 2 +- packages/sanity-suite/public/v1.1/index-local.html | 2 +- packages/sanity-suite/public/v1.1/index-npm.html | 2 +- packages/sanity-suite/public/v1.1/integrations/index-cdn.html | 2 +- .../sanity-suite/public/v1.1/integrations/index-local.html | 2 +- packages/sanity-suite/public/v1.1/integrations/index-npm.html | 2 +- .../sanity-suite/public/v1.1/manualLoadCall/index-cdn.html | 2 +- .../sanity-suite/public/v1.1/manualLoadCall/index-local.html | 2 +- .../sanity-suite/public/v1.1/manualLoadCall/index-npm.html | 2 +- packages/sanity-suite/public/v3/index-cdn.html | 2 +- packages/sanity-suite/public/v3/index-local.html | 2 +- packages/sanity-suite/public/v3/index-npm.html | 2 +- packages/sanity-suite/public/v3/integrations/index-cdn.html | 2 +- packages/sanity-suite/public/v3/integrations/index-local.html | 2 +- packages/sanity-suite/public/v3/integrations/index-npm.html | 2 +- packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html | 2 +- .../sanity-suite/public/v3/manualLoadCall/index-local.html | 2 +- packages/sanity-suite/public/v3/manualLoadCall/index-npm.html | 2 +- 23 files changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/analytics-js/public/index-legacy-only.html b/packages/analytics-js/public/index-legacy-only.html index bdd6f5985..37909e493 100644 --- a/packages/analytics-js/public/index-legacy-only.html +++ b/packages/analytics-js/public/index-legacy-only.html @@ -62,7 +62,7 @@ if (typeof Promise === 'undefined' || typeof globalThis === 'undefined') { var rudderAnalyticsPromisesScript = document.createElement('script'); rudderAnalyticsPromisesScript.src = - 'https://polyfill.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; + 'https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; rudderAnalyticsPromisesScript.async = asyncScript; if (document.head) { document.head.appendChild(rudderAnalyticsPromisesScript); diff --git a/packages/analytics-js/public/index.html b/packages/analytics-js/public/index.html index c8a80740a..d09025959 100644 --- a/packages/analytics-js/public/index.html +++ b/packages/analytics-js/public/index.html @@ -62,7 +62,7 @@ if (typeof Promise === 'undefined' || typeof globalThis === 'undefined') { var rudderAnalyticsPromisesScript = document.createElement('script'); rudderAnalyticsPromisesScript.src = - 'https://polyfill.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; + 'https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; rudderAnalyticsPromisesScript.async = asyncScript; if (document.head) { document.head.appendChild(rudderAnalyticsPromisesScript); diff --git a/packages/analytics-js/rollup.config.mjs b/packages/analytics-js/rollup.config.mjs index 809e10c81..e718611a1 100644 --- a/packages/analytics-js/rollup.config.mjs +++ b/packages/analytics-js/rollup.config.mjs @@ -42,10 +42,9 @@ 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 isNpmPackageBuild = moduleType === 'npm'; const isCDNPackageBuild = moduleType === 'cdn'; let bugsnagSDKUrl = 'https://d2wy8f7a9ursnm.cloudfront.net/v6/bugsnag.min.js'; -let polyfillIoUrl = 'https://polyfill.io/v3/polyfill.min.js'; +let polyfillIoUrl = 'https://polyfill-fastly.io/v3/polyfill.min.js'; // For Chrome extension as content script any references in code to third party URLs // throw violations at approval phase even if relevant code is not used diff --git a/packages/analytics-v1.1/rollup-configs/rollup.utilities.mjs b/packages/analytics-v1.1/rollup-configs/rollup.utilities.mjs index 81dabac3a..1c591d6cd 100644 --- a/packages/analytics-v1.1/rollup-configs/rollup.utilities.mjs +++ b/packages/analytics-v1.1/rollup-configs/rollup.utilities.mjs @@ -21,7 +21,7 @@ dotenv.config(); const isContentScriptBuild = process.env.NO_EXTERNAL_HOST; let bugsnagSDKUrl = 'https://d2wy8f7a9ursnm.cloudfront.net/v6/bugsnag.min.js'; -let polyfillIoUrl = 'https://polyfill.io/v3/polyfill.min.js'; +let polyfillIoUrl = 'https://polyfill-fastly.io/v3/polyfill.min.js'; let googleAdsSDKUrl = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; // For Chrome extension as content script any references in code to third party URLs diff --git a/packages/loading-scripts/src/index.ts b/packages/loading-scripts/src/index.ts index 70d68a7ef..859372a98 100644 --- a/packages/loading-scripts/src/index.ts +++ b/packages/loading-scripts/src/index.ts @@ -55,7 +55,7 @@ try { window.rudderAnalyticsMount = () => { /* eslint-disable */ - // globalThis polyfill as polyfill.io one does not work in legacy safari + // globalThis polyfill as polyfill-fastly.io one does not work in legacy safari if (typeof globalThis === 'undefined') { Object.defineProperty(Object.prototype, '__globalThis_magic__', { get: function get() { @@ -83,7 +83,7 @@ window.rudderAnalyticsMount = () => { if (typeof Promise === 'undefined' || typeof globalThis === 'undefined') { const rudderAnalyticsPromisesScript = document.createElement('script'); rudderAnalyticsPromisesScript.src = - 'https://polyfill.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; + 'https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; rudderAnalyticsPromisesScript.async = asyncScript; if (document.head) { document.head.appendChild(rudderAnalyticsPromisesScript); diff --git a/packages/sanity-suite/public/v1.1/index-cdn.html b/packages/sanity-suite/public/v1.1/index-cdn.html index 47a8d590e..0714c7841 100644 --- a/packages/sanity-suite/public/v1.1/index-cdn.html +++ b/packages/sanity-suite/public/v1.1/index-cdn.html @@ -106,7 +106,7 @@ crossorigin="anonymous" > - - - + + +
diff --git a/packages/sanity-suite/public/v3/index-local.html b/packages/sanity-suite/public/v3/index-local.html index cfdda54cf..ca946582b 100644 --- a/packages/sanity-suite/public/v3/index-local.html +++ b/packages/sanity-suite/public/v3/index-local.html @@ -1,8 +1,8 @@ - - - + + + RudderStack JS SDK Sanity Suite + crossorigin="anonymous"> + crossorigin="anonymous"> - - - -
-
-
-
+ + +
+
+
+
-
- + diff --git a/packages/sanity-suite/public/v3/integrations/index-cdn.html b/packages/sanity-suite/public/v3/integrations/index-cdn.html index 55a908c8d..3938c9f8c 100644 --- a/packages/sanity-suite/public/v3/integrations/index-cdn.html +++ b/packages/sanity-suite/public/v3/integrations/index-cdn.html @@ -1,4 +1,4 @@ - + @@ -15,45 +15,62 @@ { CustomGroupId: 'C0003', GroupName: 'Analytical Cookies' }, { CustomGroupId: 'C0004', GroupName: 'Targeting Cookies' }, { CustomGroupId: 'C0005', GroupName: 'Social Media Cookies' }, - { CustomGroupId: 'C0006', GroupName: 'Advertisement Cookies' } - ] + { CustomGroupId: 'C0006', GroupName: 'Advertisement Cookies' }, + ], }; - } + }, }; window.OnetrustActiveGroups = ',C0001,C0003,'; - window.RudderSnippetVersion = "3.0.0-beta.13"; - var sdkBaseUrl = "https://cdn.rudderlabs.com/__CDN_VERSION_PATH__"; - var sdkName = "rsa.min.js"; + window.RudderSnippetVersion = '3.0.1'; + var sdkBaseUrl = 'https://cdn.rudderlabs.com/__CDN_VERSION_PATH__'; + var sdkName = 'rsa.min.js'; var asyncScript = true; - window.rudderAnalyticsBuildType = "legacy"; + window.rudderAnalyticsBuildType = 'legacy'; window.rudderanalytics = []; - var methods = [ "setDefaultInstanceKey", "load", "ready", "page", "track", "identify", "alias", "group", "reset", "setAnonymousId", "startSession", "endSession", "consent" ]; + var methods = [ + 'setDefaultInstanceKey', + 'load', + 'ready', + 'page', + 'track', + 'identify', + 'alias', + 'group', + 'reset', + 'setAnonymousId', + 'startSession', + 'endSession', + 'consent', + ]; for (var i = 0; i < methods.length; i++) { var method = methods[i]; - window.rudderanalytics[method] = function(methodName) { - return function() { - window.rudderanalytics.push([ methodName ].concat(Array.prototype.slice.call(arguments))); + window.rudderanalytics[method] = (function (methodName) { + return function () { + window.rudderanalytics.push([methodName].concat(Array.prototype.slice.call(arguments))); }; - }(method); + })(method); } try { new Function('return import("")'); - window.rudderAnalyticsBuildType = "modern"; + window.rudderAnalyticsBuildType = 'modern'; } catch (e) {} - window.rudderAnalyticsMount = function() { + window.rudderAnalyticsMount = function () { if (typeof globalThis === 'undefined') { Object.defineProperty(Object.prototype, '__globalThis_magic__', { get: function get() { return this; }, - configurable: true + configurable: true, }); __globalThis_magic__.globalThis = __globalThis_magic__; delete Object.prototype.__globalThis_magic__; } - var rudderAnalyticsScript = document.createElement("script"); - rudderAnalyticsScript.src = "".concat(sdkBaseUrl, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkName); + var rudderAnalyticsScript = document.createElement('script'); + rudderAnalyticsScript.src = '' + .concat(sdkBaseUrl, '/') + .concat(window.rudderAnalyticsBuildType, '/') + .concat(sdkName); rudderAnalyticsScript.async = asyncScript; if (document.head) { document.head.appendChild(rudderAnalyticsScript); @@ -62,8 +79,9 @@ } }; if (typeof Promise === 'undefined' || typeof globalThis === 'undefined') { - var rudderAnalyticsPromisesScript = document.createElement("script"); - rudderAnalyticsPromisesScript.src = "https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount"; + var rudderAnalyticsPromisesScript = document.createElement('script'); + rudderAnalyticsPromisesScript.src = + 'https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount'; rudderAnalyticsPromisesScript.async = asyncScript; if (document.head) { document.head.appendChild(rudderAnalyticsPromisesScript); @@ -75,28 +93,24 @@ } // New addition to load script ends - var loadOptions={ + var loadOptions = { logLevel: 'DEBUG', configUrl: '__CONFIG_SERVER_HOST__', destSDKBaseURL: sdkBaseUrl + '/' + window.rudderAnalyticsBuildType + '/js-integrations', pluginsSDKBaseURL: sdkBaseUrl + '/' + window.rudderAnalyticsBuildType + '/plugins', consentManagement: { enabled: true, - provider: 'oneTrust' + provider: 'oneTrust', }, storage: { - migrate: true - } + migrate: true, + }, }; - window.manualLoad = function(writeKey, dataplane, manualLoadOptions) { + window.manualLoad = function (writeKey, dataplane, manualLoadOptions) { var loadOpts = manualLoadOptions || loadOptions; - rudderanalytics.load( - writeKey, - dataplane, - loadOpts - ); + rudderanalytics.load(writeKey, dataplane, loadOpts); window.userWriteKey = writeKey; window.userConfigUrl = loadOpts.configUrl; @@ -110,22 +124,18 @@ rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" - crossorigin="anonymous" - /> + crossorigin="anonymous" /> + href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css" /> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous"> + crossorigin="anonymous">