@amplitude/analytics-client-common 2.0.0-beta.8 → 2.0.1

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.
@@ -73,12 +73,12 @@ var CookieStorage = /** @class */ (function () {
73
73
  });
74
74
  };
75
75
  CookieStorage.prototype.getRaw = function (key) {
76
- var _a;
76
+ var _a, _b;
77
77
  return tslib_1.__awaiter(this, void 0, void 0, function () {
78
78
  var globalScope, cookie, match;
79
- return tslib_1.__generator(this, function (_b) {
79
+ return tslib_1.__generator(this, function (_c) {
80
80
  globalScope = (0, global_scope_1.getGlobalScope)();
81
- cookie = (_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document.cookie.split('; ')) !== null && _a !== void 0 ? _a : [];
81
+ cookie = (_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 : [];
82
82
  match = cookie.find(function (c) { return c.indexOf(key + '=') === 0; });
83
83
  if (!match) {
84
84
  return [2 /*return*/, undefined];
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";;;AACA,gDAAiD;AAEjD;IAGE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,wBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,IAAA,6BAAc,GAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;wBAEK,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC5B,YAAY,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACvD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;wBAAvC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,GAAG,GAAG,CAAC;qBACnC;iBACF;gBAAC,WAAM;oBACN,EAAE;iBACH;;;;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,AAjGD,IAiGC;AAjGY,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\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 const random = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, random);\n const value = await testStrorage.get(testKey);\n return value === random;\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 // value not encoded\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\n } catch {\n /* istanbul ignore next */\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 {\n //\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
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";;;AACA,gDAAiD;AAEjD;IAGE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,wBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,IAAA,6BAAc,GAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;wBAEK,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC5B,YAAY,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACvD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;wBAAvC,SAAuC,CAAC;wBAC1B,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAAvC,KAAK,GAAG,SAA+B;wBAC7C,sBAAO,KAAK,KAAK,MAAM,EAAC;;;wBAExB,0BAA0B;wBAC1B,sBAAO,KAAK,EAAC;4BAEb,qBAAM,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;wBAAlC,SAAkC,CAAC;;;;;;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;AAAD,CAAC,AAjGD,IAiGC;AAjGY,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\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 const random = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, random);\n const value = await testStrorage.get(testKey);\n return value === random;\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 // value not encoded\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\n } catch {\n /* istanbul ignore next */\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 {\n //\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"]}
@@ -71,12 +71,12 @@ var CookieStorage = /** @class */ (function () {
71
71
  });
72
72
  };
73
73
  CookieStorage.prototype.getRaw = function (key) {
74
- var _a;
74
+ var _a, _b;
75
75
  return __awaiter(this, void 0, void 0, function () {
76
76
  var globalScope, cookie, match;
77
- return __generator(this, function (_b) {
77
+ return __generator(this, function (_c) {
78
78
  globalScope = getGlobalScope();
79
- cookie = (_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document.cookie.split('; ')) !== null && _a !== void 0 ? _a : [];
79
+ cookie = (_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 : [];
80
80
  match = cookie.find(function (c) { return c.indexOf(key + '=') === 0; });
81
81
  if (!match) {
82
82
  return [2 /*return*/, undefined];
@@ -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;IAGE,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;wBAEK,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC5B,YAAY,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACvD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM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C,MAAM,GAAG,GAAG,CAAC;qBACnC;iBACF;gBAAC,WAAM;oBACN,EAAE;iBACH;;;;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,AAjGD,IAiGC","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\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 const random = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, random);\n const value = await testStrorage.get(testKey);\n return value === random;\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 // value not encoded\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\n } catch {\n /* istanbul ignore next */\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 {\n //\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
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;IAGE,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;wBAEK,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBAC5B,YAAY,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACvD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;wBAAvC,SAAuC,CAAC;wBAC1B,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAAvC,KAAK,GAAG,SAA+B;wBAC7C,sBAAO,KAAK,KAAK,MAAM,EAAC;;;wBAExB,0BAA0B;wBAC1B,sBAAO,KAAK,EAAC;4BAEb,qBAAM,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;wBAAlC,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BAAC;AAAD,CAAC,AAjGD,IAiGC","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\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 const random = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, random);\n const value = await testStrorage.get(testKey);\n return value === random;\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 // value not encoded\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(value);\n } catch {\n /* istanbul ignore next */\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 {\n //\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/analytics-client-common",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.1",
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.0.0-beta.8",
40
- "@amplitude/analytics-types": "^2.0.0-beta.8",
39
+ "@amplitude/analytics-core": "^2.0.1",
40
+ "@amplitude/analytics-types": "^2.0.1",
41
41
  "tslib": "^2.4.1"
42
42
  },
43
43
  "files": [
44
44
  "lib"
45
45
  ],
46
- "gitHead": "790489ad98a62bc8e8afa9ee749e113442e8beef"
46
+ "gitHead": "8999d1e1eb063c2a511b3d8c3fad25a7622ca730"
47
47
  }