@amplitude/analytics-core 2.41.2 → 2.41.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/storage/cookie.d.ts +1 -0
- package/lib/cjs/storage/cookie.d.ts.map +1 -1
- package/lib/cjs/storage/cookie.js +12 -1
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/utils/observable.d.ts +2 -2
- package/lib/cjs/utils/observable.d.ts.map +1 -1
- package/lib/cjs/utils/observable.js +5 -6
- package/lib/cjs/utils/observable.js.map +1 -1
- package/lib/cjs/utils/safe-stringify.d.ts.map +1 -1
- package/lib/cjs/utils/safe-stringify.js +3 -1
- package/lib/cjs/utils/safe-stringify.js.map +1 -1
- package/lib/esm/storage/cookie.d.ts +1 -0
- package/lib/esm/storage/cookie.d.ts.map +1 -1
- package/lib/esm/storage/cookie.js +12 -1
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/utils/observable.d.ts +2 -2
- package/lib/esm/utils/observable.d.ts.map +1 -1
- package/lib/esm/utils/observable.js +2 -2
- package/lib/esm/utils/observable.js.map +1 -1
- package/lib/esm/utils/safe-stringify.d.ts.map +1 -1
- package/lib/esm/utils/safe-stringify.js +1 -0
- package/lib/esm/utils/safe-stringify.js.map +1 -1
- package/package.json +3 -2
|
@@ -2,6 +2,7 @@ import { Storage, CookieStorageOptions, CookieStorageConfig } from '../types/sto
|
|
|
2
2
|
export declare class CookieStorage<T> implements Storage<T> {
|
|
3
3
|
options: CookieStorageOptions;
|
|
4
4
|
config: CookieStorageConfig;
|
|
5
|
+
private static cachedTlds;
|
|
5
6
|
constructor(options?: CookieStorageOptions, config?: CookieStorageConfig);
|
|
6
7
|
isEnabled(): Promise<boolean>;
|
|
7
8
|
get(key: string): Promise<T | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"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B;AAoBD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,MAAM,GAAG,SAE1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,GAAG,SAAS,WAAW,MAAM,GAAG,SAAS,KAAG,OAUxF,CAAC"}
|
|
@@ -256,6 +256,9 @@ var CookieStorage = /** @class */ (function () {
|
|
|
256
256
|
return tslib_1.__generator(this, function (_a) {
|
|
257
257
|
switch (_a.label) {
|
|
258
258
|
case 0:
|
|
259
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
260
|
+
return [2 /*return*/, true];
|
|
261
|
+
}
|
|
259
262
|
options = {
|
|
260
263
|
domain: '.' + domain,
|
|
261
264
|
};
|
|
@@ -265,9 +268,16 @@ var CookieStorage = /** @class */ (function () {
|
|
|
265
268
|
case 1:
|
|
266
269
|
_a.trys.push([1, 3, , 4]);
|
|
267
270
|
return [4 /*yield*/, storage.transaction(storageKey, function (storageSync) {
|
|
271
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
268
274
|
try {
|
|
269
275
|
storageSync.set(1);
|
|
270
|
-
|
|
276
|
+
var result = !!storageSync.get();
|
|
277
|
+
if (result) {
|
|
278
|
+
CookieStorage.cachedTlds[domain] = true;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
271
281
|
}
|
|
272
282
|
finally {
|
|
273
283
|
storageSync.set(null);
|
|
@@ -312,6 +322,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
312
322
|
});
|
|
313
323
|
});
|
|
314
324
|
};
|
|
325
|
+
CookieStorage.cachedTlds = {};
|
|
315
326
|
return CookieStorage;
|
|
316
327
|
}());
|
|
317
328
|
exports.CookieStorage = CookieStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";;;;AACA,gDAAiD;AAoBjD,0BA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aAAa,GAAG,UAAC,OAA2B,EAAE,OAA2B;IACpF,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,EAAE,EAAE;QACpC,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IACD,IAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,IAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,OAAO,WAAW,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB","sourcesContent":["import { Storage, StorageSync, CookieStorageOptions, CookieStorageConfig } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\n// CookieStore is a Web API not included in standard TypeScript lib types\n// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore\ninterface CookieStoreSetOptions {\n name: string;\n value: string;\n expires?: number;\n domain?: string;\n sameSite?: 'strict' | 'lax' | 'none';\n}\n\ninterface CookieStore {\n getAll(key: string): Promise<CookieStoreSetOptions[] | undefined>;\n}\n\ntype GlobalScopeWithCookieStore = {\n cookieStore?: CookieStore;\n} & typeof global;\n\n/* istanbul ignore next */\nconst getLocks = (): typeof global.navigator.locks | undefined => {\n const globalScope = getGlobalScope();\n return globalScope?.navigator?.locks;\n};\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n config: CookieStorageConfig;\n\n constructor(options?: CookieStorageOptions, config: CookieStorageConfig = {}) {\n this.options = { ...options };\n this.config = config;\n }\n\n async isEnabled(): Promise<boolean> {\n const testKey = 'AMP_TEST';\n const testCookieOptions = { ...this.options };\n const testStorage = new CookieStorage<string>(testCookieOptions);\n const testValue = String(Date.now());\n return await testStorage.transaction<boolean>(testKey, (storage: StorageSync<string>) => {\n try {\n storage.set(testValue);\n const value = storage.get();\n const result = value === testValue;\n /* istanbul ignore next */\n if (!result && this.config.diagnosticsClient) {\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Test Value mismatch',\n testKey,\n testValue,\n sync: true,\n });\n }\n return result;\n } catch (e) {\n /* istanbul ignore next */\n if (this.config.diagnosticsClient) {\n const errMessage = e instanceof Error ? e.message : String(e);\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Cookie getter/setter failed',\n testKey,\n testValue,\n error: errMessage,\n sync: true,\n });\n }\n return false;\n } finally {\n // clean-up the AMP_TEST cookie behind us\n storage.set(null);\n }\n });\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n return this.decodeCookieValue(key, value);\n }\n\n private decodeCookieValue(key: string, value: string | undefined): T | undefined {\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookieValue(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n private getSync(key: string): T | undefined {\n const value = this.getRawSync(key);\n return this.decodeCookieValue(key, value);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n\n // use CookieStore if available and enabled\n const globalScopeWithCookiesStore = globalScope as GlobalScopeWithCookieStore;\n try {\n const cookieStore = globalScopeWithCookiesStore?.cookieStore;\n if (cookieStore) {\n const cookies = await cookieStore.getAll(key);\n if (cookies) {\n /* istanbul ignore if */\n if (cookies.length > 1) {\n this.config.diagnosticsClient?.recordEvent('cookies.duplicate', {\n cookies: cookies.map((cookie) => cookie.domain),\n });\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.cookieStore');\n }\n\n for (const cookie of cookies) {\n if (isDomainEqual(cookie.domain, this.options.domain)) {\n return cookie.value;\n }\n }\n }\n }\n } catch (ignoreError) {\n /* istanbul ignore next */\n // if cookieStore had a surprise failure, fallback to document.cookie\n }\n\n return this.getRawSync(key);\n }\n\n private getRawSync(key: string): string | undefined {\n const globalScope = getGlobalScope();\n const cookies = (globalScope?.document?.cookie.split('; ') ?? []).filter((c) => c.indexOf(key + '=') === 0);\n let match: string | undefined = undefined;\n\n // if matcher function is provided, use it to de-duplicate when there's more than one cookie\n /* istanbul ignore if */\n const duplicateResolverFn = this.config.duplicateResolverFn;\n if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {\n match = cookies.find((c) => {\n try {\n const res = duplicateResolverFn(c.substring(key.length + 1));\n if (!res) {\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.document.cookie');\n }\n return res;\n } catch (ignoreError) {\n /* istanbul ignore next */\n return false;\n }\n });\n }\n\n // if match was not found, just get the first one that matches the key\n if (!match) {\n match = cookies[0];\n }\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n this.setSync(key, value);\n }\n\n private setSync(key: string, value: T | null): void {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n\n static async isDomainWritable(domain: string): Promise<boolean> {\n const options = {\n domain: '.' + domain,\n };\n const storageKey = 'AMP_TLDTEST';\n const storage = new CookieStorage<number>(options);\n try {\n const res = await storage.transaction(storageKey, (storageSync) => {\n try {\n storageSync.set(1);\n return storageSync.get();\n } finally {\n storageSync.set(null);\n }\n });\n return !!res;\n } catch (error) {\n return false;\n }\n }\n\n private async transaction<ReturnType>(\n key: string,\n callback: (storageSync: StorageSync<T>) => ReturnType,\n ): Promise<ReturnType> {\n const locks = getLocks();\n const callbackWrapper = () => {\n // construct a sync storage object that is scoped to\n // Cookie with name <key>\n const storageSync: StorageSync<T> = {\n get: () => this.getSync(key),\n set: (value: T | null) => this.setSync(key, value),\n };\n return callback(storageSync);\n };\n\n // if 'locks' is missing, it is a legacy browser, just call the callback directly\n // and settle for a transaction that isn't isolated across tabs\n if (!locks) {\n return callbackWrapper();\n }\n return (await locks.request(`com.amplitude:cookie-lock:${key}`, callbackWrapper)) as ReturnType;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n\n/**\n * Decodes a cookie value that was encoded with btoa(encodeURIComponent(...)).\n * Handles both standard encoding and double URL encoding (used by Ruby Rails v7+).\n */\nexport const decodeCookieValue = (value: string): string | undefined => {\n return decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n};\n\n/**\n * Compares two domain strings for equality, ignoring leading dots.\n * This is useful for comparing cookie domains since \".example.com\" and \"example.com\"\n * are effectively equivalent for cookie scoping.\n */\nexport const isDomainEqual = (domain1: string | undefined, domain2: string | undefined): boolean => {\n if (domain1 === '' && domain2 === '') {\n return true;\n }\n if (!domain1 || !domain2) {\n return false;\n }\n const normalized1 = domain1.startsWith('.') ? domain1.substring(1) : domain1;\n const normalized2 = domain2.startsWith('.') ? domain2.substring(1) : domain2;\n return normalized1.toLowerCase() === normalized2.toLowerCase();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";;;;AACA,gDAAiD;AAoBjD,0BAA0B;AAC1B,IAAM,QAAQ,GAAG;;IACf,IAAM,WAAW,GAAG,IAAA,6BAAc,GAAE,CAAC;IACrC,OAAO,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,0CAAE,KAAK,CAAC;AACvC,CAAC,CAAC;AAEF;IAME,uBAAY,OAA8B,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC1E,IAAI,CAAC,OAAO,wBAAQ,OAAO,CAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEK,iCAAS,GAAf;;;;;;;wBACQ,OAAO,GAAG,UAAU,CAAC;wBACrB,iBAAiB,wBAAQ,IAAI,CAAC,OAAO,CAAE,CAAC;wBACxC,WAAW,GAAG,IAAI,aAAa,CAAS,iBAAiB,CAAC,CAAC;wBAC3D,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC9B,qBAAM,WAAW,CAAC,WAAW,CAAU,OAAO,EAAE,UAAC,OAA4B;;gCAClF,IAAI;oCACF,OAAO,CAAC,GAAG,CAAC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,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,OAAO,WAAW,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB","sourcesContent":["import { Storage, StorageSync, CookieStorageOptions, CookieStorageConfig } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\n// CookieStore is a Web API not included in standard TypeScript lib types\n// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore\ninterface CookieStoreSetOptions {\n name: string;\n value: string;\n expires?: number;\n domain?: string;\n sameSite?: 'strict' | 'lax' | 'none';\n}\n\ninterface CookieStore {\n getAll(key: string): Promise<CookieStoreSetOptions[] | undefined>;\n}\n\ntype GlobalScopeWithCookieStore = {\n cookieStore?: CookieStore;\n} & typeof global;\n\n/* istanbul ignore next */\nconst getLocks = (): typeof global.navigator.locks | undefined => {\n const globalScope = getGlobalScope();\n return globalScope?.navigator?.locks;\n};\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n config: CookieStorageConfig;\n\n private static cachedTlds: Record<string, boolean> = {};\n\n constructor(options?: CookieStorageOptions, config: CookieStorageConfig = {}) {\n this.options = { ...options };\n this.config = config;\n }\n\n async isEnabled(): Promise<boolean> {\n const testKey = 'AMP_TEST';\n const testCookieOptions = { ...this.options };\n const testStorage = new CookieStorage<string>(testCookieOptions);\n const testValue = String(Date.now());\n return await testStorage.transaction<boolean>(testKey, (storage: StorageSync<string>) => {\n try {\n storage.set(testValue);\n const value = storage.get();\n const result = value === testValue;\n /* istanbul ignore next */\n if (!result && this.config.diagnosticsClient) {\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Test Value mismatch',\n testKey,\n testValue,\n sync: true,\n });\n }\n return result;\n } catch (e) {\n /* istanbul ignore next */\n if (this.config.diagnosticsClient) {\n const errMessage = e instanceof Error ? e.message : String(e);\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Cookie getter/setter failed',\n testKey,\n testValue,\n error: errMessage,\n sync: true,\n });\n }\n return false;\n } finally {\n // clean-up the AMP_TEST cookie behind us\n storage.set(null);\n }\n });\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n return this.decodeCookieValue(key, value);\n }\n\n private decodeCookieValue(key: string, value: string | undefined): T | undefined {\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookieValue(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n private getSync(key: string): T | undefined {\n const value = this.getRawSync(key);\n return this.decodeCookieValue(key, value);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n\n // use CookieStore if available and enabled\n const globalScopeWithCookiesStore = globalScope as GlobalScopeWithCookieStore;\n try {\n const cookieStore = globalScopeWithCookiesStore?.cookieStore;\n if (cookieStore) {\n const cookies = await cookieStore.getAll(key);\n if (cookies) {\n /* istanbul ignore if */\n if (cookies.length > 1) {\n this.config.diagnosticsClient?.recordEvent('cookies.duplicate', {\n cookies: cookies.map((cookie) => cookie.domain),\n });\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.cookieStore');\n }\n\n for (const cookie of cookies) {\n if (isDomainEqual(cookie.domain, this.options.domain)) {\n return cookie.value;\n }\n }\n }\n }\n } catch (ignoreError) {\n /* istanbul ignore next */\n // if cookieStore had a surprise failure, fallback to document.cookie\n }\n\n return this.getRawSync(key);\n }\n\n private getRawSync(key: string): string | undefined {\n const globalScope = getGlobalScope();\n const cookies = (globalScope?.document?.cookie.split('; ') ?? []).filter((c) => c.indexOf(key + '=') === 0);\n let match: string | undefined = undefined;\n\n // if matcher function is provided, use it to de-duplicate when there's more than one cookie\n /* istanbul ignore if */\n const duplicateResolverFn = this.config.duplicateResolverFn;\n if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {\n match = cookies.find((c) => {\n try {\n const res = duplicateResolverFn(c.substring(key.length + 1));\n if (!res) {\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.document.cookie');\n }\n return res;\n } catch (ignoreError) {\n /* istanbul ignore next */\n return false;\n }\n });\n }\n\n // if match was not found, just get the first one that matches the key\n if (!match) {\n match = cookies[0];\n }\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n this.setSync(key, value);\n }\n\n private setSync(key: string, value: T | null): void {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n\n static async isDomainWritable(domain: string): Promise<boolean> {\n if (CookieStorage.cachedTlds[domain]) {\n return true;\n }\n const options = {\n domain: '.' + domain,\n };\n const storageKey = 'AMP_TLDTEST';\n const storage = new CookieStorage<number>(options);\n try {\n const res = await storage.transaction(storageKey, (storageSync) => {\n if (CookieStorage.cachedTlds[domain]) {\n return true;\n }\n try {\n storageSync.set(1);\n const result = !!storageSync.get();\n if (result) {\n CookieStorage.cachedTlds[domain] = true;\n }\n return result;\n } finally {\n storageSync.set(null);\n }\n });\n return !!res;\n } catch (error) {\n return false;\n }\n }\n\n private async transaction<ReturnType>(\n key: string,\n callback: (storageSync: StorageSync<T>) => ReturnType,\n ): Promise<ReturnType> {\n const locks = getLocks();\n const callbackWrapper = () => {\n // construct a sync storage object that is scoped to\n // Cookie with name <key>\n const storageSync: StorageSync<T> = {\n get: () => this.getSync(key),\n set: (value: T | null) => this.setSync(key, value),\n };\n return callback(storageSync);\n };\n\n // if 'locks' is missing, it is a legacy browser, just call the callback directly\n // and settle for a transaction that isn't isolated across tabs\n if (!locks) {\n return callbackWrapper();\n }\n return (await locks.request(`com.amplitude:cookie-lock:${key}`, callbackWrapper)) as ReturnType;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n\n/**\n * Decodes a cookie value that was encoded with btoa(encodeURIComponent(...)).\n * Handles both standard encoding and double URL encoding (used by Ruby Rails v7+).\n */\nexport const decodeCookieValue = (value: string): string | undefined => {\n return decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n};\n\n/**\n * Compares two domain strings for equality, ignoring leading dots.\n * This is useful for comparing cookie domains since \".example.com\" and \"example.com\"\n * are effectively equivalent for cookie scoping.\n */\nexport const isDomainEqual = (domain1: string | undefined, domain2: string | undefined): boolean => {\n if (domain1 === '' && domain2 === '') {\n return true;\n }\n if (!domain1 || !domain2) {\n return false;\n }\n const normalized1 = domain1.startsWith('.') ? domain1.substring(1) : domain1;\n const normalized2 = domain2.startsWith('.') ? domain2.substring(1) : domain2;\n return normalized1.toLowerCase() === normalized2.toLowerCase();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,aAAa,IAAI,UAAU,EAAE,CAAC;AAgBvC;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAoBpG;AAED,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAIF;;;;;;;GAOG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAgD/F;AAGD,iBAAS,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAkDhE;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.merge = exports.multicast = exports.asyncMap = exports.Observable = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var zen_observable_ts_2 = require("zen-observable-ts");
|
|
5
|
+
var zen_observable_1 = tslib_1.__importDefault(require("zen-observable"));
|
|
6
|
+
exports.Observable = zen_observable_1.default;
|
|
8
7
|
/**
|
|
9
8
|
* asyncMap operator for Zen Observable
|
|
10
9
|
*
|
|
@@ -12,7 +11,7 @@ var zen_observable_ts_2 = require("zen-observable-ts");
|
|
|
12
11
|
* emitting the resolved values in the same order they arrive.
|
|
13
12
|
*/
|
|
14
13
|
function asyncMap(observable, fn) {
|
|
15
|
-
return new
|
|
14
|
+
return new zen_observable_1.default(function (observer) {
|
|
16
15
|
observable.subscribe({
|
|
17
16
|
next: function (value) {
|
|
18
17
|
fn(value)
|
|
@@ -40,7 +39,7 @@ exports.asyncMap = asyncMap;
|
|
|
40
39
|
* @returns Unsubscribable cleanup function
|
|
41
40
|
*/
|
|
42
41
|
function merge(sourceA, sourceB) {
|
|
43
|
-
return new
|
|
42
|
+
return new zen_observable_1.default(function (observer) {
|
|
44
43
|
var closed = false;
|
|
45
44
|
var subscriptions = new Set();
|
|
46
45
|
var cleanup = function () {
|
|
@@ -106,7 +105,7 @@ function multicast(source) {
|
|
|
106
105
|
subscription = null;
|
|
107
106
|
observers.clear();
|
|
108
107
|
}
|
|
109
|
-
return new
|
|
108
|
+
return new zen_observable_1.default(function (observer) {
|
|
110
109
|
observers.add(observer);
|
|
111
110
|
if (subscription === null) {
|
|
112
111
|
subscription = source.subscribe({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":";;;;AAAA,0EAA2C;AAEjB,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EAAE;YACzB,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC;gBAC9B,IAAI,YAAC,KAAQ;;;;wBACX,KAAkB,IAAA,cAAA,iBAAA,SAAS,CAAA,oCAAA,2DAAE;4BAAxB,IAAM,GAAG,sBAAA;4BACZ,0BAA0B;4BAC1B,MAAA,GAAG,CAAC,IAAI,oDAAG,KAAK,CAAC,CAAC;yBACnB;;;;;;;;;gBACH,CAAC;gBACD,KAAK,YAAC,GAAY;;;;wBAChB,KAAkB,IAAA,cAAA,iBAAA,SAAS,CAAA,oCAAA,2DAAE;4BAAxB,IAAM,GAAG,sBAAA;4BACZ,0BAA0B;4BAC1B,MAAA,GAAG,CAAC,KAAK,oDAAG,GAAG,CAAC,CAAC;yBAClB;;;;;;;;;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;gBACD,QAAQ;;;;wBACN,KAAkB,IAAA,cAAA,iBAAA,SAAS,CAAA,oCAAA,2DAAE;4BAAxB,IAAM,GAAG,sBAAA;4BACZ,0BAA0B;4BAC1B,MAAA,GAAG,CAAC,QAAQ,mDAAI,CAAC;yBAClB;;;;;;;;;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;aACF,CAAC,CAAC;SACJ;QAED,gDAAgD;QAChD,OAAO;YACL,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAE3B,oDAAoD;YACpD,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,YAAY,EAAE;gBACxC,YAAY,CAAC,WAAW,EAAE,CAAC;gBAC3B,YAAY,GAAG,IAAI,CAAC;aACrB;QACH,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAEkB,8BAAS","sourcesContent":["import ZenObservable from 'zen-observable';\n\nexport { ZenObservable as Observable };\n\n/** Subscription type for zen-observable */\ninterface Subscription {\n closed: boolean;\n unsubscribe(): void;\n}\n\n/** Observer type for zen-observable */\ninterface Observer<T> {\n start?(subscription: Subscription): unknown;\n next?(value: T): void;\n error?(errorValue: unknown): void;\n complete?(): void;\n}\n\n/**\n * asyncMap operator for Zen Observable\n *\n * Maps each value emitted by the source Observable using an async function,\n * emitting the resolved values in the same order they arrive.\n */\nfunction asyncMap<T, R>(observable: ZenObservable<T>, fn: (value: T) => Promise<R>): ZenObservable<R> {\n return new ZenObservable(\n (observer: { next: (value: R) => void; error: (error: any) => void; complete: () => void }) => {\n observable.subscribe({\n next: (value: T) => {\n fn(value)\n .then((result: R) => {\n return observer.next(result);\n })\n .catch((error: any) => observer.error(error));\n },\n error: (error: any) => {\n observer.error(error);\n },\n complete: () => {\n observer.complete();\n },\n });\n },\n );\n}\n\ntype Unsubscribable = {\n unsubscribe: () => void;\n};\n\ntype ZenObserver<A, B> = { next: (v: A | B) => void; error: (e: unknown) => void; complete: () => void };\n\n/**\n * merge operator for Zen Observable\n *\n * Merges two observables into a single observable, emitting values from both sources in the order they arrive.\n * @param sourceA Observable to merge\n * @param sourceB Observable to merge\n * @returns Unsubscribable cleanup function\n */\nfunction merge<A, B>(sourceA: ZenObservable<A>, sourceB: ZenObservable<B>): ZenObservable<A | B> {\n return new ZenObservable<A | B>((observer: ZenObserver<A, B>) => {\n let closed = false;\n\n const subscriptions: Set<Unsubscribable> = new Set();\n\n const cleanup = (): void => {\n closed = true;\n for (const sub of subscriptions) {\n try {\n sub.unsubscribe();\n } catch {\n /* do nothing */\n }\n }\n subscriptions.clear();\n };\n\n const subscribeTo = <T>(source: ZenObservable<T>) => {\n const sub = source.subscribe({\n next(value: T) {\n if (!closed) observer.next(value as A | B);\n },\n error(err: unknown) {\n if (!closed) {\n closed = true;\n observer.error(err);\n cleanup();\n }\n },\n complete() {\n subscriptions.delete(sub);\n if (!closed && subscriptions.size === 0) {\n observer.complete();\n cleanup();\n closed = true;\n }\n },\n });\n\n subscriptions.add(sub);\n };\n\n subscribeTo(sourceA);\n subscribeTo(sourceB);\n\n return cleanup;\n });\n}\n\n// function share() {\nfunction multicast<T>(source: ZenObservable<T>): ZenObservable<T> {\n const observers: Set<Observer<T>> = new Set();\n let subscription: Subscription | null = null;\n\n function cleanup() {\n /* istanbul ignore next */\n subscription?.unsubscribe();\n subscription = null;\n observers.clear();\n }\n\n return new ZenObservable<T>((observer: Observer<T>) => {\n observers.add(observer);\n\n if (subscription === null) {\n subscription = source.subscribe({\n next(value: T) {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.next?.(value);\n }\n },\n error(err: unknown) {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.error?.(err);\n }\n cleanup();\n },\n complete() {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.complete?.();\n }\n cleanup();\n },\n });\n }\n\n // Return unsubscribe function for this observer\n return () => {\n observers.delete(observer);\n\n // If no observers left, unsubscribe from the source\n if (observers.size === 0 && subscription) {\n subscription.unsubscribe();\n subscription = null;\n }\n };\n });\n}\n\nexport { asyncMap, multicast, merge, Unsubscribable };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-stringify.d.ts","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAKA,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"safe-stringify.d.ts","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAKA,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AAE7F,QAAA,MAAM,iBAAiB,EAAE,mBACqD,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.safeJsonStringify = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
4
5
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
6
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
|
-
var safeJsonStringifyModule = require("safe-json-stringify");
|
|
7
|
+
var safeJsonStringifyModule = tslib_1.__importStar(require("safe-json-stringify"));
|
|
8
|
+
/* istanbul ignore next */
|
|
7
9
|
var safeJsonStringify = safeJsonStringifyModule.default || safeJsonStringifyModule;
|
|
8
10
|
exports.safeJsonStringify = safeJsonStringify;
|
|
9
11
|
//# sourceMappingURL=safe-stringify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-stringify.js","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"safe-stringify.js","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":";;;;AAAA,4DAA4D;AAC5D,+DAA+D;AAC/D,mFAA+D;AAI/D,0BAA0B;AAC1B,IAAM,iBAAiB,GACpB,uBAA+B,CAAC,OAAO,IAAK,uBAA+B,CAAC;AAEtE,8CAAiB","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport * as safeJsonStringifyModule from 'safe-json-stringify';\n\n// do a simple, typed re-export of \"safe-json-stringify\"\ntype SafeJsonStringifyFn = (data: object, replacer?: any, space?: string | number) => string;\n/* istanbul ignore next */\nconst safeJsonStringify: SafeJsonStringifyFn =\n (safeJsonStringifyModule as any).default || (safeJsonStringifyModule as any);\n\nexport { safeJsonStringify };\n"]}
|
|
@@ -2,6 +2,7 @@ import { Storage, CookieStorageOptions, CookieStorageConfig } from '../types/sto
|
|
|
2
2
|
export declare class CookieStorage<T> implements Storage<T> {
|
|
3
3
|
options: CookieStorageOptions;
|
|
4
4
|
config: CookieStorageConfig;
|
|
5
|
+
private static cachedTlds;
|
|
5
6
|
constructor(options?: CookieStorageOptions, config?: CookieStorageConfig);
|
|
6
7
|
isEnabled(): Promise<boolean>;
|
|
7
8
|
get(key: string): Promise<T | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AA2BnG,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,EAAE,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AA2BnG,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,EAAE,mBAAmB,CAAC;IAE5B,OAAO,CAAC,MAAM,CAAC,UAAU,CAA+B;gBAE5C,OAAO,CAAC,EAAE,oBAAoB,EAAE,MAAM,GAAE,mBAAwB;IAKtE,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAwC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAK9C,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,OAAO;IAKT,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiCtD,OAAO,CAAC,UAAU;IAiCZ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,OAAO,CAAC,OAAO;IAkCT,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;WAIf,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YA+BjD,WAAW;CAsB1B;AAoBD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,MAAM,GAAG,SAE1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,GAAG,SAAS,WAAW,MAAM,GAAG,SAAS,KAAG,OAUxF,CAAC"}
|
|
@@ -253,6 +253,9 @@ var CookieStorage = /** @class */ (function () {
|
|
|
253
253
|
return __generator(this, function (_a) {
|
|
254
254
|
switch (_a.label) {
|
|
255
255
|
case 0:
|
|
256
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
257
|
+
return [2 /*return*/, true];
|
|
258
|
+
}
|
|
256
259
|
options = {
|
|
257
260
|
domain: '.' + domain,
|
|
258
261
|
};
|
|
@@ -262,9 +265,16 @@ var CookieStorage = /** @class */ (function () {
|
|
|
262
265
|
case 1:
|
|
263
266
|
_a.trys.push([1, 3, , 4]);
|
|
264
267
|
return [4 /*yield*/, storage.transaction(storageKey, function (storageSync) {
|
|
268
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
265
271
|
try {
|
|
266
272
|
storageSync.set(1);
|
|
267
|
-
|
|
273
|
+
var result = !!storageSync.get();
|
|
274
|
+
if (result) {
|
|
275
|
+
CookieStorage.cachedTlds[domain] = true;
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
268
278
|
}
|
|
269
279
|
finally {
|
|
270
280
|
storageSync.set(null);
|
|
@@ -309,6 +319,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
309
319
|
});
|
|
310
320
|
});
|
|
311
321
|
};
|
|
322
|
+
CookieStorage.cachedTlds = {};
|
|
312
323
|
return CookieStorage;
|
|
313
324
|
}());
|
|
314
325
|
export { CookieStorage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAoBjD,0BAA0B;AAC1B,IAAM,QAAQ,GAAG;;IACf,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,OAAO,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,0CAAE,KAAK,CAAC;AACvC,CAAC,CAAC;AAEF;IAIE,uBAAY,OAA8B,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC1E,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEK,iCAAS,GAAf;;;;;;;wBACQ,OAAO,GAAG,UAAU,CAAC;wBACrB,iBAAiB,gBAAQ,IAAI,CAAC,OAAO,CAAE,CAAC;wBACxC,WAAW,GAAG,IAAI,aAAa,CAAS,iBAAiB,CAAC,CAAC;wBAC3D,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC9B,qBAAM,WAAW,CAAC,WAAW,CAAU,OAAO,EAAE,UAAC,OAA4B;;gCAClF,IAAI;oCACF,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oCACvB,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;oCAC5B,IAAM,MAAM,GAAG,KAAK,KAAK,SAAS,CAAC;oCACnC,0BAA0B;oCAC1B,IAAI,CAAC,MAAM,IAAI,KAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;wCAC5C,MAAA,KAAI,CAAC,MAAM,CAAC,iBAAiB,0CAAE,WAAW,CAAC,2BAA2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H,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,KAAa;;IAC7C,OAAO,MAAA,sBAAsB,CAAC,KAAK,CAAC,mCAAI,kCAAkC,CAAC,KAAK,CAAC,CAAC;AACpF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,OAA2B,EAAE,OAA2B;IACpF,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,EAAE,EAAE;QACpC,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IACD,IAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,IAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,OAAO,WAAW,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC","sourcesContent":["import { Storage, StorageSync, CookieStorageOptions, CookieStorageConfig } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\n// CookieStore is a Web API not included in standard TypeScript lib types\n// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore\ninterface CookieStoreSetOptions {\n name: string;\n value: string;\n expires?: number;\n domain?: string;\n sameSite?: 'strict' | 'lax' | 'none';\n}\n\ninterface CookieStore {\n getAll(key: string): Promise<CookieStoreSetOptions[] | undefined>;\n}\n\ntype GlobalScopeWithCookieStore = {\n cookieStore?: CookieStore;\n} & typeof global;\n\n/* istanbul ignore next */\nconst getLocks = (): typeof global.navigator.locks | undefined => {\n const globalScope = getGlobalScope();\n return globalScope?.navigator?.locks;\n};\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n config: CookieStorageConfig;\n\n constructor(options?: CookieStorageOptions, config: CookieStorageConfig = {}) {\n this.options = { ...options };\n this.config = config;\n }\n\n async isEnabled(): Promise<boolean> {\n const testKey = 'AMP_TEST';\n const testCookieOptions = { ...this.options };\n const testStorage = new CookieStorage<string>(testCookieOptions);\n const testValue = String(Date.now());\n return await testStorage.transaction<boolean>(testKey, (storage: StorageSync<string>) => {\n try {\n storage.set(testValue);\n const value = storage.get();\n const result = value === testValue;\n /* istanbul ignore next */\n if (!result && this.config.diagnosticsClient) {\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Test Value mismatch',\n testKey,\n testValue,\n sync: true,\n });\n }\n return result;\n } catch (e) {\n /* istanbul ignore next */\n if (this.config.diagnosticsClient) {\n const errMessage = e instanceof Error ? e.message : String(e);\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Cookie getter/setter failed',\n testKey,\n testValue,\n error: errMessage,\n sync: true,\n });\n }\n return false;\n } finally {\n // clean-up the AMP_TEST cookie behind us\n storage.set(null);\n }\n });\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n return this.decodeCookieValue(key, value);\n }\n\n private decodeCookieValue(key: string, value: string | undefined): T | undefined {\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookieValue(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n private getSync(key: string): T | undefined {\n const value = this.getRawSync(key);\n return this.decodeCookieValue(key, value);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n\n // use CookieStore if available and enabled\n const globalScopeWithCookiesStore = globalScope as GlobalScopeWithCookieStore;\n try {\n const cookieStore = globalScopeWithCookiesStore?.cookieStore;\n if (cookieStore) {\n const cookies = await cookieStore.getAll(key);\n if (cookies) {\n /* istanbul ignore if */\n if (cookies.length > 1) {\n this.config.diagnosticsClient?.recordEvent('cookies.duplicate', {\n cookies: cookies.map((cookie) => cookie.domain),\n });\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.cookieStore');\n }\n\n for (const cookie of cookies) {\n if (isDomainEqual(cookie.domain, this.options.domain)) {\n return cookie.value;\n }\n }\n }\n }\n } catch (ignoreError) {\n /* istanbul ignore next */\n // if cookieStore had a surprise failure, fallback to document.cookie\n }\n\n return this.getRawSync(key);\n }\n\n private getRawSync(key: string): string | undefined {\n const globalScope = getGlobalScope();\n const cookies = (globalScope?.document?.cookie.split('; ') ?? []).filter((c) => c.indexOf(key + '=') === 0);\n let match: string | undefined = undefined;\n\n // if matcher function is provided, use it to de-duplicate when there's more than one cookie\n /* istanbul ignore if */\n const duplicateResolverFn = this.config.duplicateResolverFn;\n if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {\n match = cookies.find((c) => {\n try {\n const res = duplicateResolverFn(c.substring(key.length + 1));\n if (!res) {\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.document.cookie');\n }\n return res;\n } catch (ignoreError) {\n /* istanbul ignore next */\n return false;\n }\n });\n }\n\n // if match was not found, just get the first one that matches the key\n if (!match) {\n match = cookies[0];\n }\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n this.setSync(key, value);\n }\n\n private setSync(key: string, value: T | null): void {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n\n static async isDomainWritable(domain: string): Promise<boolean> {\n const options = {\n domain: '.' + domain,\n };\n const storageKey = 'AMP_TLDTEST';\n const storage = new CookieStorage<number>(options);\n try {\n const res = await storage.transaction(storageKey, (storageSync) => {\n try {\n storageSync.set(1);\n return storageSync.get();\n } finally {\n storageSync.set(null);\n }\n });\n return !!res;\n } catch (error) {\n return false;\n }\n }\n\n private async transaction<ReturnType>(\n key: string,\n callback: (storageSync: StorageSync<T>) => ReturnType,\n ): Promise<ReturnType> {\n const locks = getLocks();\n const callbackWrapper = () => {\n // construct a sync storage object that is scoped to\n // Cookie with name <key>\n const storageSync: StorageSync<T> = {\n get: () => this.getSync(key),\n set: (value: T | null) => this.setSync(key, value),\n };\n return callback(storageSync);\n };\n\n // if 'locks' is missing, it is a legacy browser, just call the callback directly\n // and settle for a transaction that isn't isolated across tabs\n if (!locks) {\n return callbackWrapper();\n }\n return (await locks.request(`com.amplitude:cookie-lock:${key}`, callbackWrapper)) as ReturnType;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n\n/**\n * Decodes a cookie value that was encoded with btoa(encodeURIComponent(...)).\n * Handles both standard encoding and double URL encoding (used by Ruby Rails v7+).\n */\nexport const decodeCookieValue = (value: string): string | undefined => {\n return decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n};\n\n/**\n * Compares two domain strings for equality, ignoring leading dots.\n * This is useful for comparing cookie domains since \".example.com\" and \"example.com\"\n * are effectively equivalent for cookie scoping.\n */\nexport const isDomainEqual = (domain1: string | undefined, domain2: string | undefined): boolean => {\n if (domain1 === '' && domain2 === '') {\n return true;\n }\n if (!domain1 || !domain2) {\n return false;\n }\n const normalized1 = domain1.startsWith('.') ? domain1.substring(1) : domain1;\n const normalized2 = domain2.startsWith('.') ? domain2.substring(1) : domain2;\n return normalized1.toLowerCase() === normalized2.toLowerCase();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAoBjD,0BAA0B;AAC1B,IAAM,QAAQ,GAAG;;IACf,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,OAAO,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,0CAAE,KAAK,CAAC;AACvC,CAAC,CAAC;AAEF;IAME,uBAAY,OAA8B,EAAE,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAC1E,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEK,iCAAS,GAAf;;;;;;;wBACQ,OAAO,GAAG,UAAU,CAAC;wBACrB,iBAAiB,gBAAQ,IAAI,CAAC,OAAO,CAAE,CAAC;wBACxC,WAAW,GAAG,IAAI,aAAa,CAAS,iBAAiB,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M,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,IAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7E,OAAO,WAAW,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC","sourcesContent":["import { Storage, StorageSync, CookieStorageOptions, CookieStorageConfig } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\n// CookieStore is a Web API not included in standard TypeScript lib types\n// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore\ninterface CookieStoreSetOptions {\n name: string;\n value: string;\n expires?: number;\n domain?: string;\n sameSite?: 'strict' | 'lax' | 'none';\n}\n\ninterface CookieStore {\n getAll(key: string): Promise<CookieStoreSetOptions[] | undefined>;\n}\n\ntype GlobalScopeWithCookieStore = {\n cookieStore?: CookieStore;\n} & typeof global;\n\n/* istanbul ignore next */\nconst getLocks = (): typeof global.navigator.locks | undefined => {\n const globalScope = getGlobalScope();\n return globalScope?.navigator?.locks;\n};\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n config: CookieStorageConfig;\n\n private static cachedTlds: Record<string, boolean> = {};\n\n constructor(options?: CookieStorageOptions, config: CookieStorageConfig = {}) {\n this.options = { ...options };\n this.config = config;\n }\n\n async isEnabled(): Promise<boolean> {\n const testKey = 'AMP_TEST';\n const testCookieOptions = { ...this.options };\n const testStorage = new CookieStorage<string>(testCookieOptions);\n const testValue = String(Date.now());\n return await testStorage.transaction<boolean>(testKey, (storage: StorageSync<string>) => {\n try {\n storage.set(testValue);\n const value = storage.get();\n const result = value === testValue;\n /* istanbul ignore next */\n if (!result && this.config.diagnosticsClient) {\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Test Value mismatch',\n testKey,\n testValue,\n sync: true,\n });\n }\n return result;\n } catch (e) {\n /* istanbul ignore next */\n if (this.config.diagnosticsClient) {\n const errMessage = e instanceof Error ? e.message : String(e);\n this.config.diagnosticsClient?.recordEvent('cookies.isEnabled.failure', {\n reason: 'Cookie getter/setter failed',\n testKey,\n testValue,\n error: errMessage,\n sync: true,\n });\n }\n return false;\n } finally {\n // clean-up the AMP_TEST cookie behind us\n storage.set(null);\n }\n });\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n return this.decodeCookieValue(key, value);\n }\n\n private decodeCookieValue(key: string, value: string | undefined): T | undefined {\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookieValue(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n private getSync(key: string): T | undefined {\n const value = this.getRawSync(key);\n return this.decodeCookieValue(key, value);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n\n // use CookieStore if available and enabled\n const globalScopeWithCookiesStore = globalScope as GlobalScopeWithCookieStore;\n try {\n const cookieStore = globalScopeWithCookiesStore?.cookieStore;\n if (cookieStore) {\n const cookies = await cookieStore.getAll(key);\n if (cookies) {\n /* istanbul ignore if */\n if (cookies.length > 1) {\n this.config.diagnosticsClient?.recordEvent('cookies.duplicate', {\n cookies: cookies.map((cookie) => cookie.domain),\n });\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.cookieStore');\n }\n\n for (const cookie of cookies) {\n if (isDomainEqual(cookie.domain, this.options.domain)) {\n return cookie.value;\n }\n }\n }\n }\n } catch (ignoreError) {\n /* istanbul ignore next */\n // if cookieStore had a surprise failure, fallback to document.cookie\n }\n\n return this.getRawSync(key);\n }\n\n private getRawSync(key: string): string | undefined {\n const globalScope = getGlobalScope();\n const cookies = (globalScope?.document?.cookie.split('; ') ?? []).filter((c) => c.indexOf(key + '=') === 0);\n let match: string | undefined = undefined;\n\n // if matcher function is provided, use it to de-duplicate when there's more than one cookie\n /* istanbul ignore if */\n const duplicateResolverFn = this.config.duplicateResolverFn;\n if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {\n match = cookies.find((c) => {\n try {\n const res = duplicateResolverFn(c.substring(key.length + 1));\n if (!res) {\n this.config.diagnosticsClient?.increment('cookies.duplicate.occurrence.document.cookie');\n }\n return res;\n } catch (ignoreError) {\n /* istanbul ignore next */\n return false;\n }\n });\n }\n\n // if match was not found, just get the first one that matches the key\n if (!match) {\n match = cookies[0];\n }\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n this.setSync(key, value);\n }\n\n private setSync(key: string, value: T | null): void {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n\n static async isDomainWritable(domain: string): Promise<boolean> {\n if (CookieStorage.cachedTlds[domain]) {\n return true;\n }\n const options = {\n domain: '.' + domain,\n };\n const storageKey = 'AMP_TLDTEST';\n const storage = new CookieStorage<number>(options);\n try {\n const res = await storage.transaction(storageKey, (storageSync) => {\n if (CookieStorage.cachedTlds[domain]) {\n return true;\n }\n try {\n storageSync.set(1);\n const result = !!storageSync.get();\n if (result) {\n CookieStorage.cachedTlds[domain] = true;\n }\n return result;\n } finally {\n storageSync.set(null);\n }\n });\n return !!res;\n } catch (error) {\n return false;\n }\n }\n\n private async transaction<ReturnType>(\n key: string,\n callback: (storageSync: StorageSync<T>) => ReturnType,\n ): Promise<ReturnType> {\n const locks = getLocks();\n const callbackWrapper = () => {\n // construct a sync storage object that is scoped to\n // Cookie with name <key>\n const storageSync: StorageSync<T> = {\n get: () => this.getSync(key),\n set: (value: T | null) => this.setSync(key, value),\n };\n return callback(storageSync);\n };\n\n // if 'locks' is missing, it is a legacy browser, just call the callback directly\n // and settle for a transaction that isn't isolated across tabs\n if (!locks) {\n return callbackWrapper();\n }\n return (await locks.request(`com.amplitude:cookie-lock:${key}`, callbackWrapper)) as ReturnType;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n\n/**\n * Decodes a cookie value that was encoded with btoa(encodeURIComponent(...)).\n * Handles both standard encoding and double URL encoding (used by Ruby Rails v7+).\n */\nexport const decodeCookieValue = (value: string): string | undefined => {\n return decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n};\n\n/**\n * Compares two domain strings for equality, ignoring leading dots.\n * This is useful for comparing cookie domains since \".example.com\" and \"example.com\"\n * are effectively equivalent for cookie scoping.\n */\nexport const isDomainEqual = (domain1: string | undefined, domain2: string | undefined): boolean => {\n if (domain1 === '' && domain2 === '') {\n return true;\n }\n if (!domain1 || !domain2) {\n return false;\n }\n const normalized1 = domain1.startsWith('.') ? domain1.substring(1) : domain1;\n const normalized2 = domain2.startsWith('.') ? domain2.substring(1) : domain2;\n return normalized1.toLowerCase() === normalized2.toLowerCase();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,aAAa,IAAI,UAAU,EAAE,CAAC;AAgBvC;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAoBpG;AAED,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAIF;;;;;;;GAOG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAgD/F;AAGD,iBAAS,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAkDhE;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __values } from "tslib";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import ZenObservable from 'zen-observable';
|
|
3
|
+
export { ZenObservable as Observable };
|
|
4
4
|
/**
|
|
5
5
|
* asyncMap operator for Zen Observable
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/utils/observable.ts"],"names":[],"mappings":";AAAA,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,aAAa,IAAI,UAAU,EAAE,CAAC;AAgBvC;;;;;GAKG;AACH,SAAS,QAAQ,CAAO,UAA4B,EAAE,EAA4B;IAChF,OAAO,IAAI,aAAa,CACtB,UAAC,QAAyF;QACxF,UAAU,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,UAAC,KAAQ;gBACb,EAAE,CAAC,KAAK,CAAC;qBACN,IAAI,CAAC,UAAC,MAAS;oBACd,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC/B,CAAC,CAAC;qBACD,KAAK,CAAC,UAAC,KAAU,IAAK,OAAA,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAArB,CAAqB,CAAC,CAAC;YAClD,CAAC;YACD,KAAK,EAAE,UAAC,KAAU;gBAChB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;YACD,QAAQ,EAAE;gBACR,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACtB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC;AAQD;;;;;;;GAOG;AACH,SAAS,KAAK,CAAO,OAAyB,EAAE,OAAyB;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AgD;QAChD,OAAO;YACL,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAE3B,oDAAoD;YACpD,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,YAAY,EAAE;gBACxC,YAAY,CAAC,WAAW,EAAE,CAAC;gBAC3B,YAAY,GAAG,IAAI,CAAC;aACrB;QACH,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAkB,CAAC","sourcesContent":["import ZenObservable from 'zen-observable';\n\nexport { ZenObservable as Observable };\n\n/** Subscription type for zen-observable */\ninterface Subscription {\n closed: boolean;\n unsubscribe(): void;\n}\n\n/** Observer type for zen-observable */\ninterface Observer<T> {\n start?(subscription: Subscription): unknown;\n next?(value: T): void;\n error?(errorValue: unknown): void;\n complete?(): void;\n}\n\n/**\n * asyncMap operator for Zen Observable\n *\n * Maps each value emitted by the source Observable using an async function,\n * emitting the resolved values in the same order they arrive.\n */\nfunction asyncMap<T, R>(observable: ZenObservable<T>, fn: (value: T) => Promise<R>): ZenObservable<R> {\n return new ZenObservable(\n (observer: { next: (value: R) => void; error: (error: any) => void; complete: () => void }) => {\n observable.subscribe({\n next: (value: T) => {\n fn(value)\n .then((result: R) => {\n return observer.next(result);\n })\n .catch((error: any) => observer.error(error));\n },\n error: (error: any) => {\n observer.error(error);\n },\n complete: () => {\n observer.complete();\n },\n });\n },\n );\n}\n\ntype Unsubscribable = {\n unsubscribe: () => void;\n};\n\ntype ZenObserver<A, B> = { next: (v: A | B) => void; error: (e: unknown) => void; complete: () => void };\n\n/**\n * merge operator for Zen Observable\n *\n * Merges two observables into a single observable, emitting values from both sources in the order they arrive.\n * @param sourceA Observable to merge\n * @param sourceB Observable to merge\n * @returns Unsubscribable cleanup function\n */\nfunction merge<A, B>(sourceA: ZenObservable<A>, sourceB: ZenObservable<B>): ZenObservable<A | B> {\n return new ZenObservable<A | B>((observer: ZenObserver<A, B>) => {\n let closed = false;\n\n const subscriptions: Set<Unsubscribable> = new Set();\n\n const cleanup = (): void => {\n closed = true;\n for (const sub of subscriptions) {\n try {\n sub.unsubscribe();\n } catch {\n /* do nothing */\n }\n }\n subscriptions.clear();\n };\n\n const subscribeTo = <T>(source: ZenObservable<T>) => {\n const sub = source.subscribe({\n next(value: T) {\n if (!closed) observer.next(value as A | B);\n },\n error(err: unknown) {\n if (!closed) {\n closed = true;\n observer.error(err);\n cleanup();\n }\n },\n complete() {\n subscriptions.delete(sub);\n if (!closed && subscriptions.size === 0) {\n observer.complete();\n cleanup();\n closed = true;\n }\n },\n });\n\n subscriptions.add(sub);\n };\n\n subscribeTo(sourceA);\n subscribeTo(sourceB);\n\n return cleanup;\n });\n}\n\n// function share() {\nfunction multicast<T>(source: ZenObservable<T>): ZenObservable<T> {\n const observers: Set<Observer<T>> = new Set();\n let subscription: Subscription | null = null;\n\n function cleanup() {\n /* istanbul ignore next */\n subscription?.unsubscribe();\n subscription = null;\n observers.clear();\n }\n\n return new ZenObservable<T>((observer: Observer<T>) => {\n observers.add(observer);\n\n if (subscription === null) {\n subscription = source.subscribe({\n next(value: T) {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.next?.(value);\n }\n },\n error(err: unknown) {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.error?.(err);\n }\n cleanup();\n },\n complete() {\n for (const obs of observers) {\n /* istanbul ignore next */\n obs.complete?.();\n }\n cleanup();\n },\n });\n }\n\n // Return unsubscribe function for this observer\n return () => {\n observers.delete(observer);\n\n // If no observers left, unsubscribe from the source\n if (observers.size === 0 && subscription) {\n subscription.unsubscribe();\n subscription = null;\n }\n };\n });\n}\n\nexport { asyncMap, multicast, merge, Unsubscribable };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-stringify.d.ts","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAKA,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"safe-stringify.d.ts","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAKA,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AAE7F,QAAA,MAAM,iBAAiB,EAAE,mBACqD,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
3
|
import * as safeJsonStringifyModule from 'safe-json-stringify';
|
|
4
|
+
/* istanbul ignore next */
|
|
4
5
|
var safeJsonStringify = safeJsonStringifyModule.default || safeJsonStringifyModule;
|
|
5
6
|
export { safeJsonStringify };
|
|
6
7
|
//# sourceMappingURL=safe-stringify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-stringify.js","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,+DAA+D;AAC/D,OAAO,KAAK,uBAAuB,MAAM,qBAAqB,CAAC;AAI/D,IAAM,iBAAiB,GACpB,uBAA+B,CAAC,OAAO,IAAK,uBAA+B,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport * as safeJsonStringifyModule from 'safe-json-stringify';\n\n// do a simple, typed re-export of \"safe-json-stringify\"\ntype SafeJsonStringifyFn = (data: object, replacer?: any, space?: string | number) => string;\nconst safeJsonStringify: SafeJsonStringifyFn =\n (safeJsonStringifyModule as any).default || (safeJsonStringifyModule as any);\n\nexport { safeJsonStringify };\n"]}
|
|
1
|
+
{"version":3,"file":"safe-stringify.js","sourceRoot":"","sources":["../../../src/utils/safe-stringify.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,+DAA+D;AAC/D,OAAO,KAAK,uBAAuB,MAAM,qBAAqB,CAAC;AAI/D,0BAA0B;AAC1B,IAAM,iBAAiB,GACpB,uBAA+B,CAAC,OAAO,IAAK,uBAA+B,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport * as safeJsonStringifyModule from 'safe-json-stringify';\n\n// do a simple, typed re-export of \"safe-json-stringify\"\ntype SafeJsonStringifyFn = (data: object, replacer?: any, space?: string | number) => string;\n/* istanbul ignore next */\nconst safeJsonStringify: SafeJsonStringifyFn =\n (safeJsonStringifyModule as any).default || (safeJsonStringifyModule as any);\n\nexport { safeJsonStringify };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "2.41.
|
|
3
|
+
"version": "2.41.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@amplitude/analytics-connector": "^1.6.4",
|
|
25
|
+
"@types/zen-observable": "0.8.3",
|
|
25
26
|
"safe-json-stringify": "1.2.0",
|
|
26
27
|
"tslib": "^2.4.1",
|
|
27
|
-
"zen-observable
|
|
28
|
+
"zen-observable": "0.10.0"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"lib"
|