@amplitude/analytics-client-common 2.2.1 → 2.2.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/global-scope.d.ts.map +1 -1
- package/lib/cjs/global-scope.js +6 -0
- package/lib/cjs/global-scope.js.map +1 -1
- package/lib/cjs/storage/cookie.d.ts.map +1 -1
- package/lib/cjs/storage/cookie.js +6 -5
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/transports/fetch.d.ts.map +1 -1
- package/lib/cjs/transports/fetch.js +8 -2
- package/lib/cjs/transports/fetch.js.map +1 -1
- package/lib/cjs/types/global.d.ts +2 -0
- package/lib/cjs/types/global.d.ts.map +1 -0
- package/lib/cjs/types/global.js +3 -0
- package/lib/cjs/types/global.js.map +1 -0
- package/lib/esm/global-scope.d.ts.map +1 -1
- package/lib/esm/global-scope.js +6 -0
- package/lib/esm/global-scope.js.map +1 -1
- package/lib/esm/storage/cookie.d.ts.map +1 -1
- package/lib/esm/storage/cookie.js +6 -5
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/transports/fetch.d.ts.map +1 -1
- package/lib/esm/transports/fetch.js +8 -2
- package/lib/esm/transports/fetch.js.map +1 -1
- package/lib/esm/types/global.d.ts +2 -0
- package/lib/esm/types/global.d.ts.map +1 -0
- package/lib/esm/types/global.js +4 -0
- package/lib/esm/types/global.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-scope.d.ts","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAO,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"file":"global-scope.d.ts","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAO,iBAAiB,GAAG,SAoBrD,CAAC"}
|
package/lib/cjs/global-scope.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getGlobalScope = void 0;
|
|
5
5
|
var getGlobalScope = function () {
|
|
6
|
+
// This should only be used for integrations with Amplitude that are not running in a browser environment
|
|
7
|
+
// We need to specify the name of the global variable as a string to prevent it from being minified
|
|
8
|
+
var ampIntegrationContextName = 'ampIntegrationContext';
|
|
9
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis[ampIntegrationContextName] !== 'undefined') {
|
|
10
|
+
return globalThis[ampIntegrationContextName];
|
|
11
|
+
}
|
|
6
12
|
if (typeof globalThis !== 'undefined') {
|
|
7
13
|
return globalThis;
|
|
8
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-scope.js","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,6DAA6D;;;AAEtD,IAAM,cAAc,GAAG;IAC5B,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAC;KACnB;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC;KACb;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"global-scope.js","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,6DAA6D;;;AAEtD,IAAM,cAAc,GAAG;IAC5B,yGAAyG;IACzG,qGAAqG;IACrG,IAAM,yBAAyB,GAAG,uBAAkD,CAAC;IACrF,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,OAAO,UAAU,CAAC,yBAAyB,CAAC,KAAK,WAAW,EAAE;QACrG,OAAO,UAAU,CAAC,yBAAyB,CAAsB,CAAC;KACnE;IACD,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAC;KACnB;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC;KACb;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApBW,QAAA,cAAc,kBAoBzB","sourcesContent":["/* eslint-disable no-restricted-globals */\n/* Only file allowed to access to globalThis, window, self */\n\nexport const getGlobalScope = (): typeof globalThis | undefined => {\n // This should only be used for integrations with Amplitude that are not running in a browser environment\n // We need to specify the name of the global variable as a string to prevent it from being minified\n const ampIntegrationContextName = 'ampIntegrationContext' as keyof typeof globalThis;\n if (typeof globalThis !== 'undefined' && typeof globalThis[ampIntegrationContextName] !== 'undefined') {\n return globalThis[ampIntegrationContextName] as typeof globalThis;\n }\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n return undefined;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAG3E,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAqB;gBAEjC,OAAO,CAAC,EAAE,oBAAoB;IAIpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAG3E,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAqB;gBAEjC,OAAO,CAAC,EAAE,oBAAoB;IAIpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAkChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -58,13 +58,13 @@ var CookieStorage = /** @class */ (function () {
|
|
|
58
58
|
value = decodeURIComponent(atob(value));
|
|
59
59
|
}
|
|
60
60
|
catch (_b) {
|
|
61
|
-
|
|
61
|
+
console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
62
62
|
}
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
64
64
|
return [2 /*return*/, JSON.parse(value)];
|
|
65
65
|
}
|
|
66
66
|
catch (_c) {
|
|
67
|
-
|
|
67
|
+
console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
68
68
|
return [2 /*return*/, undefined];
|
|
69
69
|
}
|
|
70
70
|
return [2 /*return*/];
|
|
@@ -90,7 +90,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
90
90
|
CookieStorage.prototype.set = function (key, value) {
|
|
91
91
|
var _a;
|
|
92
92
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var expirationDays, expires, expireDate, date, str, globalScope;
|
|
93
|
+
var expirationDays, expires, expireDate, date, str, globalScope, errorMessage;
|
|
94
94
|
return tslib_1.__generator(this, function (_b) {
|
|
95
95
|
try {
|
|
96
96
|
expirationDays = (_a = this.options.expirationDays) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -120,8 +120,9 @@ var CookieStorage = /** @class */ (function () {
|
|
|
120
120
|
globalScope.document.cookie = str;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
catch (
|
|
124
|
-
|
|
123
|
+
catch (error) {
|
|
124
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
125
|
+
console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(key, ". Error: ").concat(errorMessage));
|
|
125
126
|
}
|
|
126
127
|
return [2 /*return*/];
|
|
127
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";;;AACA,gDAAiD;AAEjD;IAIE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,wBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,IAAA,6BAAc,GAAE,EAAE;4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IAAI,mBAAY,IAAI,CAAC,OAAO,CAAC,MAAM,CAAE,CAAC;qBAC1C;oBACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;wBACvB,GAAG,IAAI,UAAU,CAAC;qBACnB;oBACD,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;wBACzB,GAAG,IAAI,qBAAc,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAE,CAAC;qBAC9C;oBACK,WAAW,GAAG,IAAA,6BAAc,GAAE,CAAC;oBACrC,IAAI,WAAW,EAAE;wBACf,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;qBACnC;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACR,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,OAAO,CAAC,KAAK,CAAC,kEAA2D,GAAG,sBAAY,YAAY,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;4BACtB,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;;;;;KAC3B;IAEK,6BAAK,GAAX;;;gBACE,sBAAO;;;KACR;IACH,oBAAC;AAAD,CAAC,AAnGD,IAmGC;AAnGY,sCAAa","sourcesContent":["import { Storage, CookieStorageOptions } from '@amplitude/analytics-types';\nimport { getGlobalScope } from '../global-scope';\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n private static testValue: undefined | string;\n\n constructor(options?: CookieStorageOptions) {\n this.options = { ...options };\n }\n\n async isEnabled(): Promise<boolean> {\n /* istanbul ignore if */\n if (!getGlobalScope()) {\n return false;\n }\n\n CookieStorage.testValue = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, CookieStorage.testValue);\n const value = await testStrorage.get(testKey);\n return value === CookieStorage.testValue;\n } catch {\n /* istanbul ignore next */\n return false;\n } finally {\n await testStrorage.remove(testKey);\n }\n }\n\n async get(key: string): Promise<T | undefined> {\n let value = await this.getRaw(key);\n if (!value) {\n return undefined;\n }\n try {\n try {\n value = decodeURIComponent(atob(value));\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\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 async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n const cookie = globalScope?.document?.cookie.split('; ') ?? [];\n const match = cookie.find((c) => c.indexOf(key + '=') === 0);\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 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAsB1E"}
|
|
@@ -31,8 +31,14 @@ var FetchTransport = /** @class */ (function (_super) {
|
|
|
31
31
|
return [4 /*yield*/, response.text()];
|
|
32
32
|
case 2:
|
|
33
33
|
responseText = _a.sent();
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
try {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
36
|
+
return [2 /*return*/, this.buildResponse(JSON.parse(responseText))];
|
|
37
|
+
}
|
|
38
|
+
catch (_b) {
|
|
39
|
+
return [2 /*return*/, this.buildResponse({ code: response.status })];
|
|
40
|
+
}
|
|
41
|
+
return [2 /*return*/];
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":";;;AAAA,4DAA0D;AAG1D;IAAoC,0CAAa;IAAjD;;
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":";;;AAAA,4DAA0D;AAG1D;IAAoC,0CAAa;IAAjD;;IAuBA,CAAC;IAtBO,6BAAI,GAAV,UAAW,SAAiB,EAAE,OAAgB;;;;;;wBAC5C,wBAAwB;wBACxB,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;4BAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;yBACpD;wBACK,OAAO,GAAgB;4BAC3B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;gCAClC,MAAM,EAAE,KAAK;6BACd;4BACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;4BAC7B,MAAM,EAAE,MAAM;yBACf,CAAC;wBACe,qBAAM,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAC3B,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAApC,YAAY,GAAG,SAAqB;wBAC1C,IAAI;4BACF,iEAAiE;4BACjE,sBAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAC;yBACrD;wBAAC,WAAM;4BACN,sBAAO,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAC;yBACtD;;;;;KACF;IACH,qBAAC;AAAD,CAAC,AAvBD,CAAoC,8BAAa,GAuBhD;AAvBY,wCAAc","sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class FetchTransport extends BaseTransport implements Transport {\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n /* istanbul ignore if */\n if (typeof fetch === 'undefined') {\n throw new Error('FetchTransport is not supported');\n }\n const options: RequestInit = {\n headers: {\n 'Content-Type': 'application/json',\n Accept: '*/*',\n },\n body: JSON.stringify(payload),\n method: 'POST',\n };\n const response = await fetch(serverUrl, options);\n const responseText = await response.text();\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.buildResponse(JSON.parse(responseText));\n } catch {\n return this.buildResponse({ code: response.status });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/types/global.ts"],"names":[],"mappings":"AAEA,eAAO,IAAI,qBAAqB,EAAE,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/types/global.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable no-restricted-globals */\n// eslint-disable-next-line no-var\nexport var ampIntegrationContext: typeof globalThis;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-scope.d.ts","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAO,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"file":"global-scope.d.ts","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAO,iBAAiB,GAAG,SAoBrD,CAAC"}
|
package/lib/esm/global-scope.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
2
|
/* Only file allowed to access to globalThis, window, self */
|
|
3
3
|
export var getGlobalScope = function () {
|
|
4
|
+
// This should only be used for integrations with Amplitude that are not running in a browser environment
|
|
5
|
+
// We need to specify the name of the global variable as a string to prevent it from being minified
|
|
6
|
+
var ampIntegrationContextName = 'ampIntegrationContext';
|
|
7
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis[ampIntegrationContextName] !== 'undefined') {
|
|
8
|
+
return globalThis[ampIntegrationContextName];
|
|
9
|
+
}
|
|
4
10
|
if (typeof globalThis !== 'undefined') {
|
|
5
11
|
return globalThis;
|
|
6
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-scope.js","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,6DAA6D;AAE7D,MAAM,CAAC,IAAM,cAAc,GAAG;IAC5B,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAC;KACnB;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC;KACb;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n/* Only file allowed to access to globalThis, window, self */\n\nexport const getGlobalScope = (): typeof globalThis | undefined => {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n return undefined;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"global-scope.js","sourceRoot":"","sources":["../../src/global-scope.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,6DAA6D;AAE7D,MAAM,CAAC,IAAM,cAAc,GAAG;IAC5B,yGAAyG;IACzG,qGAAqG;IACrG,IAAM,yBAAyB,GAAG,uBAAkD,CAAC;IACrF,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,OAAO,UAAU,CAAC,yBAAyB,CAAC,KAAK,WAAW,EAAE;QACrG,OAAO,UAAU,CAAC,yBAAyB,CAAsB,CAAC;KACnE;IACD,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAC;KACnB;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC;KACb;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n/* Only file allowed to access to globalThis, window, self */\n\nexport const getGlobalScope = (): typeof globalThis | undefined => {\n // This should only be used for integrations with Amplitude that are not running in a browser environment\n // We need to specify the name of the global variable as a string to prevent it from being minified\n const ampIntegrationContextName = 'ampIntegrationContext' as keyof typeof globalThis;\n if (typeof globalThis !== 'undefined' && typeof globalThis[ampIntegrationContextName] !== 'undefined') {\n return globalThis[ampIntegrationContextName] as typeof globalThis;\n }\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n return undefined;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAG3E,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAqB;gBAEjC,OAAO,CAAC,EAAE,oBAAoB;IAIpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAG3E,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAqB;gBAEjC,OAAO,CAAC,EAAE,oBAAoB;IAIpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAkChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -56,13 +56,13 @@ var CookieStorage = /** @class */ (function () {
|
|
|
56
56
|
value = decodeURIComponent(atob(value));
|
|
57
57
|
}
|
|
58
58
|
catch (_b) {
|
|
59
|
-
|
|
59
|
+
console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
60
60
|
}
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
62
62
|
return [2 /*return*/, JSON.parse(value)];
|
|
63
63
|
}
|
|
64
64
|
catch (_c) {
|
|
65
|
-
|
|
65
|
+
console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(key, ", value: ").concat(value));
|
|
66
66
|
return [2 /*return*/, undefined];
|
|
67
67
|
}
|
|
68
68
|
return [2 /*return*/];
|
|
@@ -88,7 +88,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
88
88
|
CookieStorage.prototype.set = function (key, value) {
|
|
89
89
|
var _a;
|
|
90
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
-
var expirationDays, expires, expireDate, date, str, globalScope;
|
|
91
|
+
var expirationDays, expires, expireDate, date, str, globalScope, errorMessage;
|
|
92
92
|
return __generator(this, function (_b) {
|
|
93
93
|
try {
|
|
94
94
|
expirationDays = (_a = this.options.expirationDays) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -118,8 +118,9 @@ var CookieStorage = /** @class */ (function () {
|
|
|
118
118
|
globalScope.document.cookie = str;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
catch (
|
|
122
|
-
|
|
121
|
+
catch (error) {
|
|
122
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
123
|
+
console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(key, ". Error: ").concat(errorMessage));
|
|
123
124
|
}
|
|
124
125
|
return [2 /*return*/];
|
|
125
126
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;IAIE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,cAAc,EAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;w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IAAI,CAAC,OAAO,CAAC,MAAM,CAAE,CAAC;qBAC1C;oBACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;wBACvB,GAAG,IAAI,UAAU,CAAC;qBACnB;oBACD,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;wBACzB,GAAG,IAAI,qBAAc,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAE,CAAC;qBAC9C;oBACK,WAAW,GAAG,cAAc,EAAE,CAAC;oBACrC,IAAI,WAAW,EAAE;wBACf,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;qBACnC;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACR,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,OAAO,CAAC,KAAK,CAAC,kEAA2D,GAAG,sBAAY,YAAY,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;4BACtB,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;;;;;KAC3B;IAEK,6BAAK,GAAX;;;gBACE,sBAAO;;;KACR;IACH,oBAAC;AAAD,CAAC,AAnGD,IAmGC","sourcesContent":["import { Storage, CookieStorageOptions } from '@amplitude/analytics-types';\nimport { getGlobalScope } from '../global-scope';\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n private static testValue: undefined | string;\n\n constructor(options?: CookieStorageOptions) {\n this.options = { ...options };\n }\n\n async isEnabled(): Promise<boolean> {\n /* istanbul ignore if */\n if (!getGlobalScope()) {\n return false;\n }\n\n CookieStorage.testValue = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, CookieStorage.testValue);\n const value = await testStrorage.get(testKey);\n return value === CookieStorage.testValue;\n } catch {\n /* istanbul ignore next */\n return false;\n } finally {\n await testStrorage.remove(testKey);\n }\n }\n\n async get(key: string): Promise<T | undefined> {\n let value = await this.getRaw(key);\n if (!value) {\n return undefined;\n }\n try {\n try {\n value = decodeURIComponent(atob(value));\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\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 async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n const cookie = globalScope?.document?.cookie.split('; ') ?? [];\n const match = cookie.find((c) => c.indexOf(key + '=') === 0);\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 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAsB1E"}
|
|
@@ -29,8 +29,14 @@ var FetchTransport = /** @class */ (function (_super) {
|
|
|
29
29
|
return [4 /*yield*/, response.text()];
|
|
30
30
|
case 2:
|
|
31
31
|
responseText = _a.sent();
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
try {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
34
|
+
return [2 /*return*/, this.buildResponse(JSON.parse(responseText))];
|
|
35
|
+
}
|
|
36
|
+
catch (_b) {
|
|
37
|
+
return [2 /*return*/, this.buildResponse({ code: response.status })];
|
|
38
|
+
}
|
|
39
|
+
return [2 /*return*/];
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D;IAAoC,kCAAa;IAAjD;;
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D;IAAoC,kCAAa;IAAjD;;IAuBA,CAAC;IAtBO,6BAAI,GAAV,UAAW,SAAiB,EAAE,OAAgB;;;;;;wBAC5C,wBAAwB;wBACxB,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;4BAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;yBACpD;wBACK,OAAO,GAAgB;4BAC3B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;gCAClC,MAAM,EAAE,KAAK;6BACd;4BACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;4BAC7B,MAAM,EAAE,MAAM;yBACf,CAAC;wBACe,qBAAM,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAC3B,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAApC,YAAY,GAAG,SAAqB;wBAC1C,IAAI;4BACF,iEAAiE;4BACjE,sBAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAC;yBACrD;wBAAC,WAAM;4BACN,sBAAO,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAC;yBACtD;;;;;KACF;IACH,qBAAC;AAAD,CAAC,AAvBD,CAAoC,aAAa,GAuBhD","sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class FetchTransport extends BaseTransport implements Transport {\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n /* istanbul ignore if */\n if (typeof fetch === 'undefined') {\n throw new Error('FetchTransport is not supported');\n }\n const options: RequestInit = {\n headers: {\n 'Content-Type': 'application/json',\n Accept: '*/*',\n },\n body: JSON.stringify(payload),\n method: 'POST',\n };\n const response = await fetch(serverUrl, options);\n const responseText = await response.text();\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.buildResponse(JSON.parse(responseText));\n } catch {\n return this.buildResponse({ code: response.status });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/types/global.ts"],"names":[],"mappings":"AAEA,eAAO,IAAI,qBAAqB,EAAE,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/types/global.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,kCAAkC;AAClC,MAAM,CAAC,IAAI,qBAAwC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n// eslint-disable-next-line no-var\nexport var ampIntegrationContext: typeof globalThis;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-client-common",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@amplitude/analytics-connector": "^1.4.8",
|
|
39
|
-
"@amplitude/analytics-core": "^2.
|
|
40
|
-
"@amplitude/analytics-types": "^2.
|
|
39
|
+
"@amplitude/analytics-core": "^2.3.0",
|
|
40
|
+
"@amplitude/analytics-types": "^2.6.0",
|
|
41
41
|
"tslib": "^2.4.1"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"lib"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "58f78b288db20dec13ef0c4381d14916ad4d4811"
|
|
47
47
|
}
|