@amplitude/analytics-core 2.41.1 → 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 +7 -0
- package/lib/cjs/storage/cookie.d.ts.map +1 -1
- package/lib/cjs/storage/cookie.js +234 -146
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/types/storage.d.ts +4 -0
- package/lib/cjs/types/storage.d.ts.map +1 -1
- package/lib/cjs/types/storage.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 +7 -0
- package/lib/esm/storage/cookie.d.ts.map +1 -1
- package/lib/esm/storage/cookie.js +234 -146
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/types/storage.d.ts +4 -0
- package/lib/esm/types/storage.d.ts.map +1 -1
- package/lib/esm/types/storage.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,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,qBAFnB,wBAAa,CAEgB;AAgBpC;;;;;GAKG;AACH,SAAS,QAAQ,CAAO,UAA4B,EAAE,EAA4B;IAChF,OAAO,IAAI,wBAAa,CACtB,UAAC,QAAyF;QACxF,UAAU,CAAC,SAAS,CAAC;YACnB,I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ACZ,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,13 +2,20 @@ 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>;
|
|
9
|
+
private decodeCookieValue;
|
|
10
|
+
private getSync;
|
|
8
11
|
getRaw(key: string): Promise<string | undefined>;
|
|
12
|
+
private getRawSync;
|
|
9
13
|
set(key: string, value: T | null): Promise<void>;
|
|
14
|
+
private setSync;
|
|
10
15
|
remove(key: string): Promise<void>;
|
|
11
16
|
reset(): Promise<void>;
|
|
17
|
+
static isDomainWritable(domain: string): Promise<boolean>;
|
|
18
|
+
private transaction;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
21
|
* Decodes a cookie value that was encoded with btoa(encodeURIComponent(...)).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
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"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator, __values } from "tslib";
|
|
2
2
|
import { getGlobalScope } from '../global-scope';
|
|
3
|
-
|
|
3
|
+
/* istanbul ignore next */
|
|
4
|
+
var getLocks = function () {
|
|
5
|
+
var _a;
|
|
6
|
+
var globalScope = getGlobalScope();
|
|
7
|
+
return (_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.navigator) === null || _a === void 0 ? void 0 : _a.locks;
|
|
8
|
+
};
|
|
4
9
|
var CookieStorage = /** @class */ (function () {
|
|
5
10
|
function CookieStorage(options, config) {
|
|
6
11
|
if (config === void 0) { config = {}; }
|
|
@@ -8,211 +13,221 @@ var CookieStorage = /** @class */ (function () {
|
|
|
8
13
|
this.config = config;
|
|
9
14
|
}
|
|
10
15
|
CookieStorage.prototype.isEnabled = function () {
|
|
11
|
-
var _a, _b;
|
|
12
16
|
return __awaiter(this, void 0, void 0, function () {
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
var testKey, testCookieOptions, testStorage, testValue;
|
|
18
|
+
var _this = this;
|
|
19
|
+
return __generator(this, function (_a) {
|
|
20
|
+
switch (_a.label) {
|
|
16
21
|
case 0:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!globalScope || !globalScope.document) {
|
|
20
|
-
return [2 /*return*/, false];
|
|
21
|
-
}
|
|
22
|
-
testValue = String(Date.now());
|
|
23
|
-
testCookieOptions = __assign(__assign({}, this.options), { expirationDays: 0.003 });
|
|
22
|
+
testKey = 'AMP_TEST';
|
|
23
|
+
testCookieOptions = __assign({}, this.options);
|
|
24
24
|
testStorage = new CookieStorage(testCookieOptions);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
25
|
+
testValue = String(Date.now());
|
|
26
|
+
return [4 /*yield*/, testStorage.transaction(testKey, function (storage) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
try {
|
|
29
|
+
storage.set(testValue);
|
|
30
|
+
var value = storage.get();
|
|
31
|
+
var result = value === testValue;
|
|
32
|
+
/* istanbul ignore next */
|
|
33
|
+
if (!result && _this.config.diagnosticsClient) {
|
|
34
|
+
(_a = _this.config.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.recordEvent('cookies.isEnabled.failure', {
|
|
35
|
+
reason: 'Test Value mismatch',
|
|
36
|
+
testKey: testKey,
|
|
37
|
+
testValue: testValue,
|
|
38
|
+
sync: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
/* istanbul ignore next */
|
|
45
|
+
if (_this.config.diagnosticsClient) {
|
|
46
|
+
var errMessage = e instanceof Error ? e.message : String(e);
|
|
47
|
+
(_b = _this.config.diagnosticsClient) === null || _b === void 0 ? void 0 : _b.recordEvent('cookies.isEnabled.failure', {
|
|
48
|
+
reason: 'Cookie getter/setter failed',
|
|
49
|
+
testKey: testKey,
|
|
50
|
+
testValue: testValue,
|
|
51
|
+
error: errMessage,
|
|
52
|
+
sync: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
// clean-up the AMP_TEST cookie behind us
|
|
59
|
+
storage.set(null);
|
|
60
|
+
}
|
|
61
|
+
})];
|
|
62
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
65
|
});
|
|
65
66
|
};
|
|
66
67
|
CookieStorage.prototype.get = function (key) {
|
|
67
68
|
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
-
var value
|
|
69
|
+
var value;
|
|
69
70
|
return __generator(this, function (_a) {
|
|
70
71
|
switch (_a.label) {
|
|
71
72
|
case 0: return [4 /*yield*/, this.getRaw(key)];
|
|
72
73
|
case 1:
|
|
73
74
|
value = _a.sent();
|
|
74
|
-
|
|
75
|
-
return [2 /*return*/, undefined];
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
decodedValue = decodeCookieValue(value);
|
|
79
|
-
if (decodedValue === undefined) {
|
|
80
|
-
console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
81
|
-
return [2 /*return*/, undefined];
|
|
82
|
-
}
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
84
|
-
return [2 /*return*/, JSON.parse(decodedValue)];
|
|
85
|
-
}
|
|
86
|
-
catch (_b) {
|
|
87
|
-
console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
88
|
-
return [2 /*return*/, undefined];
|
|
89
|
-
}
|
|
90
|
-
return [2 /*return*/];
|
|
75
|
+
return [2 /*return*/, this.decodeCookieValue(key, value)];
|
|
91
76
|
}
|
|
92
77
|
});
|
|
93
78
|
});
|
|
94
79
|
};
|
|
80
|
+
CookieStorage.prototype.decodeCookieValue = function (key, value) {
|
|
81
|
+
if (!value) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
var decodedValue = decodeCookieValue(value);
|
|
86
|
+
if (decodedValue === undefined) {
|
|
87
|
+
console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
91
|
+
return JSON.parse(decodedValue);
|
|
92
|
+
}
|
|
93
|
+
catch (_a) {
|
|
94
|
+
console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
CookieStorage.prototype.getSync = function (key) {
|
|
99
|
+
var value = this.getRawSync(key);
|
|
100
|
+
return this.decodeCookieValue(key, value);
|
|
101
|
+
};
|
|
95
102
|
CookieStorage.prototype.getRaw = function (key) {
|
|
96
|
-
var _a, _b
|
|
103
|
+
var _a, _b;
|
|
97
104
|
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
-
var globalScope, globalScopeWithCookiesStore, cookieStore,
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
switch (_f.label) {
|
|
105
|
+
var globalScope, globalScopeWithCookiesStore, cookieStore, cookies, cookies_1, cookies_1_1, cookie, ignoreError_1;
|
|
106
|
+
var e_1, _c;
|
|
107
|
+
return __generator(this, function (_d) {
|
|
108
|
+
switch (_d.label) {
|
|
103
109
|
case 0:
|
|
104
110
|
globalScope = getGlobalScope();
|
|
105
111
|
globalScopeWithCookiesStore = globalScope;
|
|
106
|
-
|
|
112
|
+
_d.label = 1;
|
|
107
113
|
case 1:
|
|
108
|
-
|
|
114
|
+
_d.trys.push([1, 4, , 5]);
|
|
109
115
|
cookieStore = globalScopeWithCookiesStore === null || globalScopeWithCookiesStore === void 0 ? void 0 : globalScopeWithCookiesStore.cookieStore;
|
|
110
116
|
if (!cookieStore) return [3 /*break*/, 3];
|
|
111
117
|
return [4 /*yield*/, cookieStore.getAll(key)];
|
|
112
118
|
case 2:
|
|
113
|
-
|
|
114
|
-
if (
|
|
119
|
+
cookies = _d.sent();
|
|
120
|
+
if (cookies) {
|
|
115
121
|
/* istanbul ignore if */
|
|
116
|
-
if (
|
|
122
|
+
if (cookies.length > 1) {
|
|
117
123
|
(_a = this.config.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.recordEvent('cookies.duplicate', {
|
|
118
|
-
cookies:
|
|
124
|
+
cookies: cookies.map(function (cookie) { return cookie.domain; }),
|
|
119
125
|
});
|
|
120
126
|
(_b = this.config.diagnosticsClient) === null || _b === void 0 ? void 0 : _b.increment('cookies.duplicate.occurrence.cookieStore');
|
|
121
127
|
}
|
|
122
128
|
try {
|
|
123
|
-
for (cookies_1 = __values(
|
|
129
|
+
for (cookies_1 = __values(cookies), cookies_1_1 = cookies_1.next(); !cookies_1_1.done; cookies_1_1 = cookies_1.next()) {
|
|
124
130
|
cookie = cookies_1_1.value;
|
|
125
131
|
if (isDomainEqual(cookie.domain, this.options.domain)) {
|
|
126
132
|
return [2 /*return*/, cookie.value];
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
|
-
catch (
|
|
136
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
131
137
|
finally {
|
|
132
138
|
try {
|
|
133
|
-
if (cookies_1_1 && !cookies_1_1.done && (
|
|
139
|
+
if (cookies_1_1 && !cookies_1_1.done && (_c = cookies_1.return)) _c.call(cookies_1);
|
|
134
140
|
}
|
|
135
|
-
finally { if (
|
|
141
|
+
finally { if (e_1) throw e_1.error; }
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
|
-
|
|
144
|
+
_d.label = 3;
|
|
139
145
|
case 3: return [3 /*break*/, 5];
|
|
140
146
|
case 4:
|
|
141
|
-
ignoreError_1 =
|
|
147
|
+
ignoreError_1 = _d.sent();
|
|
142
148
|
return [3 /*break*/, 5];
|
|
143
|
-
case 5:
|
|
144
|
-
cookies = ((_d = (_c = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document) === null || _c === void 0 ? void 0 : _c.cookie.split('; ')) !== null && _d !== void 0 ? _d : []).filter(function (c) { return c.indexOf(key + '=') === 0; });
|
|
145
|
-
match = undefined;
|
|
146
|
-
duplicateResolverFn = this.config.duplicateResolverFn;
|
|
147
|
-
if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {
|
|
148
|
-
match = cookies.find(function (c) {
|
|
149
|
-
var _a;
|
|
150
|
-
try {
|
|
151
|
-
var res = duplicateResolverFn(c.substring(key.length + 1));
|
|
152
|
-
if (!res) {
|
|
153
|
-
(_a = _this.config.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.increment('cookies.duplicate.occurrence.document.cookie');
|
|
154
|
-
}
|
|
155
|
-
return res;
|
|
156
|
-
}
|
|
157
|
-
catch (ignoreError) {
|
|
158
|
-
/* istanbul ignore next */
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
// if match was not found, just get the first one that matches the key
|
|
164
|
-
if (!match) {
|
|
165
|
-
match = cookies[0];
|
|
166
|
-
}
|
|
167
|
-
if (!match) {
|
|
168
|
-
return [2 /*return*/, undefined];
|
|
169
|
-
}
|
|
170
|
-
return [2 /*return*/, match.substring(key.length + 1)];
|
|
149
|
+
case 5: return [2 /*return*/, this.getRawSync(key)];
|
|
171
150
|
}
|
|
172
151
|
});
|
|
173
152
|
});
|
|
174
153
|
};
|
|
175
|
-
CookieStorage.prototype.
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
154
|
+
CookieStorage.prototype.getRawSync = function (key) {
|
|
155
|
+
var _this = this;
|
|
156
|
+
var _a, _b;
|
|
157
|
+
var globalScope = getGlobalScope();
|
|
158
|
+
var cookies = ((_b = (_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document) === null || _a === void 0 ? void 0 : _a.cookie.split('; ')) !== null && _b !== void 0 ? _b : []).filter(function (c) { return c.indexOf(key + '=') === 0; });
|
|
159
|
+
var match = undefined;
|
|
160
|
+
// if matcher function is provided, use it to de-duplicate when there's more than one cookie
|
|
161
|
+
/* istanbul ignore if */
|
|
162
|
+
var duplicateResolverFn = this.config.duplicateResolverFn;
|
|
163
|
+
if (typeof duplicateResolverFn === 'function' && cookies.length > 1) {
|
|
164
|
+
match = cookies.find(function (c) {
|
|
165
|
+
var _a;
|
|
180
166
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (expires) {
|
|
185
|
-
date = new Date();
|
|
186
|
-
date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
|
|
187
|
-
expireDate = date;
|
|
188
|
-
}
|
|
189
|
-
str = "".concat(key, "=").concat(btoa(encodeURIComponent(JSON.stringify(value))));
|
|
190
|
-
if (expireDate) {
|
|
191
|
-
str += "; expires=".concat(expireDate.toUTCString());
|
|
192
|
-
}
|
|
193
|
-
str += '; path=/';
|
|
194
|
-
if (this.options.domain) {
|
|
195
|
-
str += "; domain=".concat(this.options.domain);
|
|
196
|
-
}
|
|
197
|
-
if (this.options.secure) {
|
|
198
|
-
str += '; Secure';
|
|
199
|
-
}
|
|
200
|
-
if (this.options.sameSite) {
|
|
201
|
-
str += "; SameSite=".concat(this.options.sameSite);
|
|
202
|
-
}
|
|
203
|
-
globalScope = getGlobalScope();
|
|
204
|
-
if (globalScope) {
|
|
205
|
-
globalScope.document.cookie = str;
|
|
167
|
+
var res = duplicateResolverFn(c.substring(key.length + 1));
|
|
168
|
+
if (!res) {
|
|
169
|
+
(_a = _this.config.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.increment('cookies.duplicate.occurrence.document.cookie');
|
|
206
170
|
}
|
|
171
|
+
return res;
|
|
207
172
|
}
|
|
208
|
-
catch (
|
|
209
|
-
|
|
210
|
-
|
|
173
|
+
catch (ignoreError) {
|
|
174
|
+
/* istanbul ignore next */
|
|
175
|
+
return false;
|
|
211
176
|
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// if match was not found, just get the first one that matches the key
|
|
180
|
+
if (!match) {
|
|
181
|
+
match = cookies[0];
|
|
182
|
+
}
|
|
183
|
+
if (!match) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
return match.substring(key.length + 1);
|
|
187
|
+
};
|
|
188
|
+
CookieStorage.prototype.set = function (key, value) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
this.setSync(key, value);
|
|
212
192
|
return [2 /*return*/];
|
|
213
193
|
});
|
|
214
194
|
});
|
|
215
195
|
};
|
|
196
|
+
CookieStorage.prototype.setSync = function (key, value) {
|
|
197
|
+
var _a;
|
|
198
|
+
try {
|
|
199
|
+
var expirationDays = (_a = this.options.expirationDays) !== null && _a !== void 0 ? _a : 0;
|
|
200
|
+
var expires = value !== null ? expirationDays : -1;
|
|
201
|
+
var expireDate = undefined;
|
|
202
|
+
if (expires) {
|
|
203
|
+
var date = new Date();
|
|
204
|
+
date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
|
|
205
|
+
expireDate = date;
|
|
206
|
+
}
|
|
207
|
+
var str = "".concat(key, "=").concat(btoa(encodeURIComponent(JSON.stringify(value))));
|
|
208
|
+
if (expireDate) {
|
|
209
|
+
str += "; expires=".concat(expireDate.toUTCString());
|
|
210
|
+
}
|
|
211
|
+
str += '; path=/';
|
|
212
|
+
if (this.options.domain) {
|
|
213
|
+
str += "; domain=".concat(this.options.domain);
|
|
214
|
+
}
|
|
215
|
+
if (this.options.secure) {
|
|
216
|
+
str += '; Secure';
|
|
217
|
+
}
|
|
218
|
+
if (this.options.sameSite) {
|
|
219
|
+
str += "; SameSite=".concat(this.options.sameSite);
|
|
220
|
+
}
|
|
221
|
+
var globalScope = getGlobalScope();
|
|
222
|
+
if (globalScope) {
|
|
223
|
+
globalScope.document.cookie = str;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
var errorMessage = error instanceof Error ? error.message : String(error);
|
|
228
|
+
console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(key, ". Error: ").concat(errorMessage));
|
|
229
|
+
}
|
|
230
|
+
};
|
|
216
231
|
CookieStorage.prototype.remove = function (key) {
|
|
217
232
|
return __awaiter(this, void 0, void 0, function () {
|
|
218
233
|
return __generator(this, function (_a) {
|
|
@@ -232,6 +247,79 @@ var CookieStorage = /** @class */ (function () {
|
|
|
232
247
|
});
|
|
233
248
|
});
|
|
234
249
|
};
|
|
250
|
+
CookieStorage.isDomainWritable = function (domain) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
+
var options, storageKey, storage, res, error_1;
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0:
|
|
256
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
257
|
+
return [2 /*return*/, true];
|
|
258
|
+
}
|
|
259
|
+
options = {
|
|
260
|
+
domain: '.' + domain,
|
|
261
|
+
};
|
|
262
|
+
storageKey = 'AMP_TLDTEST';
|
|
263
|
+
storage = new CookieStorage(options);
|
|
264
|
+
_a.label = 1;
|
|
265
|
+
case 1:
|
|
266
|
+
_a.trys.push([1, 3, , 4]);
|
|
267
|
+
return [4 /*yield*/, storage.transaction(storageKey, function (storageSync) {
|
|
268
|
+
if (CookieStorage.cachedTlds[domain]) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
storageSync.set(1);
|
|
273
|
+
var result = !!storageSync.get();
|
|
274
|
+
if (result) {
|
|
275
|
+
CookieStorage.cachedTlds[domain] = true;
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
storageSync.set(null);
|
|
281
|
+
}
|
|
282
|
+
})];
|
|
283
|
+
case 2:
|
|
284
|
+
res = _a.sent();
|
|
285
|
+
return [2 /*return*/, !!res];
|
|
286
|
+
case 3:
|
|
287
|
+
error_1 = _a.sent();
|
|
288
|
+
return [2 /*return*/, false];
|
|
289
|
+
case 4: return [2 /*return*/];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
CookieStorage.prototype.transaction = function (key, callback) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var locks, callbackWrapper;
|
|
297
|
+
var _this = this;
|
|
298
|
+
return __generator(this, function (_a) {
|
|
299
|
+
switch (_a.label) {
|
|
300
|
+
case 0:
|
|
301
|
+
locks = getLocks();
|
|
302
|
+
callbackWrapper = function () {
|
|
303
|
+
// construct a sync storage object that is scoped to
|
|
304
|
+
// Cookie with name <key>
|
|
305
|
+
var storageSync = {
|
|
306
|
+
get: function () { return _this.getSync(key); },
|
|
307
|
+
set: function (value) { return _this.setSync(key, value); },
|
|
308
|
+
};
|
|
309
|
+
return callback(storageSync);
|
|
310
|
+
};
|
|
311
|
+
// if 'locks' is missing, it is a legacy browser, just call the callback directly
|
|
312
|
+
// and settle for a transaction that isn't isolated across tabs
|
|
313
|
+
if (!locks) {
|
|
314
|
+
return [2 /*return*/, callbackWrapper()];
|
|
315
|
+
}
|
|
316
|
+
return [4 /*yield*/, locks.request("com.amplitude:cookie-lock:".concat(key), callbackWrapper)];
|
|
317
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
CookieStorage.cachedTlds = {};
|
|
235
323
|
return CookieStorage;
|
|
236
324
|
}());
|
|
237
325
|
export { CookieStorage };
|