@amplitude/analytics-client-common 0.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.
- package/LICENSE +21 -0
- package/lib/cjs/analytics-connector.d.ts +3 -0
- package/lib/cjs/analytics-connector.d.ts.map +1 -0
- package/lib/cjs/analytics-connector.js +8 -0
- package/lib/cjs/analytics-connector.js.map +1 -0
- package/lib/cjs/attribution/campaign-parser.d.ts +10 -0
- package/lib/cjs/attribution/campaign-parser.d.ts.map +1 -0
- package/lib/cjs/attribution/campaign-parser.js +83 -0
- package/lib/cjs/attribution/campaign-parser.js.map +1 -0
- package/lib/cjs/attribution/campaign-tracker.d.ts +75 -0
- package/lib/cjs/attribution/campaign-tracker.d.ts.map +1 -0
- package/lib/cjs/attribution/campaign-tracker.js +113 -0
- package/lib/cjs/attribution/campaign-tracker.js.map +1 -0
- package/lib/cjs/attribution/constants.d.ts +17 -0
- package/lib/cjs/attribution/constants.d.ts.map +1 -0
- package/lib/cjs/attribution/constants.js +28 -0
- package/lib/cjs/attribution/constants.js.map +1 -0
- package/lib/cjs/cookie-name.d.ts +3 -0
- package/lib/cjs/cookie-name.d.ts.map +1 -0
- package/lib/cjs/cookie-name.js +14 -0
- package/lib/cjs/cookie-name.js.map +1 -0
- package/lib/cjs/index.d.ts +12 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +26 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/language.d.ts +2 -0
- package/lib/cjs/language.d.ts.map +1 -0
- package/lib/cjs/language.js +12 -0
- package/lib/cjs/language.js.map +1 -0
- package/lib/cjs/plugins/identity.d.ts +9 -0
- package/lib/cjs/plugins/identity.d.ts.map +1 -0
- package/lib/cjs/plugins/identity.js +30 -0
- package/lib/cjs/plugins/identity.js.map +1 -0
- package/lib/cjs/query-params.d.ts +3 -0
- package/lib/cjs/query-params.d.ts.map +1 -0
- package/lib/cjs/query-params.js +32 -0
- package/lib/cjs/query-params.js.map +1 -0
- package/lib/cjs/session-manager.d.ts +28 -0
- package/lib/cjs/session-manager.d.ts.map +1 -0
- package/lib/cjs/session-manager.js +84 -0
- package/lib/cjs/session-manager.js.map +1 -0
- package/lib/cjs/storage/cookie.d.ts +12 -0
- package/lib/cjs/storage/cookie.d.ts.map +1 -0
- package/lib/cjs/storage/cookie.js +146 -0
- package/lib/cjs/storage/cookie.js.map +1 -0
- package/lib/cjs/storage/utm-cookie.d.ts +6 -0
- package/lib/cjs/storage/utm-cookie.d.ts.map +1 -0
- package/lib/cjs/storage/utm-cookie.js +50 -0
- package/lib/cjs/storage/utm-cookie.js.map +1 -0
- package/lib/cjs/transports/fetch.d.ts +6 -0
- package/lib/cjs/transports/fetch.d.ts.map +1 -0
- package/lib/cjs/transports/fetch.js +42 -0
- package/lib/cjs/transports/fetch.js.map +1 -0
- package/lib/esm/analytics-connector.d.ts +3 -0
- package/lib/esm/analytics-connector.d.ts.map +1 -0
- package/lib/esm/analytics-connector.js +5 -0
- package/lib/esm/analytics-connector.js.map +1 -0
- package/lib/esm/attribution/campaign-parser.d.ts +10 -0
- package/lib/esm/attribution/campaign-parser.d.ts.map +1 -0
- package/lib/esm/attribution/campaign-parser.js +81 -0
- package/lib/esm/attribution/campaign-parser.js.map +1 -0
- package/lib/esm/attribution/campaign-tracker.d.ts +75 -0
- package/lib/esm/attribution/campaign-tracker.d.ts.map +1 -0
- package/lib/esm/attribution/campaign-tracker.js +111 -0
- package/lib/esm/attribution/campaign-tracker.js.map +1 -0
- package/lib/esm/attribution/constants.d.ts +17 -0
- package/lib/esm/attribution/constants.d.ts.map +1 -0
- package/lib/esm/attribution/constants.js +26 -0
- package/lib/esm/attribution/constants.js.map +1 -0
- package/lib/esm/cookie-name.d.ts +3 -0
- package/lib/esm/cookie-name.d.ts.map +1 -0
- package/lib/esm/cookie-name.js +10 -0
- package/lib/esm/cookie-name.js.map +1 -0
- package/lib/esm/index.d.ts +12 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +12 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/language.d.ts +2 -0
- package/lib/esm/language.d.ts.map +1 -0
- package/lib/esm/language.js +9 -0
- package/lib/esm/language.js.map +1 -0
- package/lib/esm/plugins/identity.d.ts +9 -0
- package/lib/esm/plugins/identity.d.ts.map +1 -0
- package/lib/esm/plugins/identity.js +28 -0
- package/lib/esm/plugins/identity.js.map +1 -0
- package/lib/esm/query-params.d.ts +3 -0
- package/lib/esm/query-params.d.ts.map +1 -0
- package/lib/esm/query-params.js +28 -0
- package/lib/esm/query-params.js.map +1 -0
- package/lib/esm/session-manager.d.ts +28 -0
- package/lib/esm/session-manager.d.ts.map +1 -0
- package/lib/esm/session-manager.js +82 -0
- package/lib/esm/session-manager.js.map +1 -0
- package/lib/esm/storage/cookie.d.ts +12 -0
- package/lib/esm/storage/cookie.d.ts.map +1 -0
- package/lib/esm/storage/cookie.js +144 -0
- package/lib/esm/storage/cookie.js.map +1 -0
- package/lib/esm/storage/utm-cookie.d.ts +6 -0
- package/lib/esm/storage/utm-cookie.d.ts.map +1 -0
- package/lib/esm/storage/utm-cookie.js +48 -0
- package/lib/esm/storage/utm-cookie.js.map +1 -0
- package/lib/esm/transports/fetch.d.ts +6 -0
- package/lib/esm/transports/fetch.d.ts.map +1 -0
- package/lib/esm/transports/fetch.js +40 -0
- package/lib/esm/transports/fetch.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
+
var CookieStorage = /** @class */ (function () {
|
|
3
|
+
function CookieStorage(options) {
|
|
4
|
+
this.options = __assign({}, options);
|
|
5
|
+
}
|
|
6
|
+
CookieStorage.prototype.isEnabled = function () {
|
|
7
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8
|
+
var random, testStrorage, testKey, value, _a;
|
|
9
|
+
return __generator(this, function (_b) {
|
|
10
|
+
switch (_b.label) {
|
|
11
|
+
case 0:
|
|
12
|
+
/* istanbul ignore if */
|
|
13
|
+
if (typeof window === 'undefined') {
|
|
14
|
+
return [2 /*return*/, false];
|
|
15
|
+
}
|
|
16
|
+
random = String(Date.now());
|
|
17
|
+
testStrorage = new CookieStorage(this.options);
|
|
18
|
+
testKey = 'AMP_TEST';
|
|
19
|
+
_b.label = 1;
|
|
20
|
+
case 1:
|
|
21
|
+
_b.trys.push([1, 4, 5, 7]);
|
|
22
|
+
return [4 /*yield*/, testStrorage.set(testKey, random)];
|
|
23
|
+
case 2:
|
|
24
|
+
_b.sent();
|
|
25
|
+
return [4 /*yield*/, testStrorage.get(testKey)];
|
|
26
|
+
case 3:
|
|
27
|
+
value = _b.sent();
|
|
28
|
+
return [2 /*return*/, value === random];
|
|
29
|
+
case 4:
|
|
30
|
+
_a = _b.sent();
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
return [2 /*return*/, false];
|
|
33
|
+
case 5: return [4 /*yield*/, testStrorage.remove(testKey)];
|
|
34
|
+
case 6:
|
|
35
|
+
_b.sent();
|
|
36
|
+
return [7 /*endfinally*/];
|
|
37
|
+
case 7: return [2 /*return*/];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
CookieStorage.prototype.get = function (key) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var value;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0: return [4 /*yield*/, this.getRaw(key)];
|
|
48
|
+
case 1:
|
|
49
|
+
value = _a.sent();
|
|
50
|
+
if (!value) {
|
|
51
|
+
return [2 /*return*/, undefined];
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
try {
|
|
55
|
+
value = decodeURIComponent(atob(value));
|
|
56
|
+
}
|
|
57
|
+
catch (_b) {
|
|
58
|
+
// value not encoded
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
61
|
+
return [2 /*return*/, JSON.parse(value)];
|
|
62
|
+
}
|
|
63
|
+
catch (_c) {
|
|
64
|
+
/* istanbul ignore next */
|
|
65
|
+
return [2 /*return*/, undefined];
|
|
66
|
+
}
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
CookieStorage.prototype.getRaw = function (key) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var cookie, match;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
cookie = window.document.cookie.split('; ');
|
|
77
|
+
match = cookie.find(function (c) { return c.indexOf(key + '=') === 0; });
|
|
78
|
+
if (!match) {
|
|
79
|
+
return [2 /*return*/, undefined];
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/, match.substring(key.length + 1)];
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
CookieStorage.prototype.set = function (key, value) {
|
|
86
|
+
var _a;
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
var expirationDays, expires, expireDate, date, str;
|
|
89
|
+
return __generator(this, function (_b) {
|
|
90
|
+
try {
|
|
91
|
+
expirationDays = (_a = this.options.expirationDays) !== null && _a !== void 0 ? _a : 0;
|
|
92
|
+
expires = value !== null ? expirationDays : -1;
|
|
93
|
+
expireDate = undefined;
|
|
94
|
+
if (expires) {
|
|
95
|
+
date = new Date();
|
|
96
|
+
date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
|
|
97
|
+
expireDate = date;
|
|
98
|
+
}
|
|
99
|
+
str = "".concat(key, "=").concat(btoa(encodeURIComponent(JSON.stringify(value))));
|
|
100
|
+
if (expireDate) {
|
|
101
|
+
str += "; expires=".concat(expireDate.toUTCString());
|
|
102
|
+
}
|
|
103
|
+
str += '; path=/';
|
|
104
|
+
if (this.options.domain) {
|
|
105
|
+
str += "; domain=".concat(this.options.domain);
|
|
106
|
+
}
|
|
107
|
+
if (this.options.secure) {
|
|
108
|
+
str += '; Secure';
|
|
109
|
+
}
|
|
110
|
+
if (this.options.sameSite) {
|
|
111
|
+
str += "; SameSite=".concat(this.options.sameSite);
|
|
112
|
+
}
|
|
113
|
+
window.document.cookie = str;
|
|
114
|
+
}
|
|
115
|
+
catch (_c) {
|
|
116
|
+
//
|
|
117
|
+
}
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
CookieStorage.prototype.remove = function (key) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0: return [4 /*yield*/, this.set(key, null)];
|
|
127
|
+
case 1:
|
|
128
|
+
_a.sent();
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
CookieStorage.prototype.reset = function () {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/];
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
return CookieStorage;
|
|
142
|
+
}());
|
|
143
|
+
export { CookieStorage };
|
|
144
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AAEA;IAGE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;4BACjC,sBAAO,KAAK,EAAC;yBACd;wBAEK,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GA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qBAC9C;oBACD,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;iBAC9B;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,AA7FD,IA6FC","sourcesContent":["import { Storage, CookieStorageOptions } from '@amplitude/analytics-types';\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 (typeof window === 'undefined') {\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 cookie = window.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 window.document.cookie = str;\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"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CookieStorage } from './cookie';
|
|
2
|
+
export declare class UTMCookie extends CookieStorage<Record<string, string | undefined>> {
|
|
3
|
+
get(key: string): Promise<Record<string, string | undefined> | undefined>;
|
|
4
|
+
set(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=utm-cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utm-cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/utm-cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,SAAU,SAAQ,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAoBzE,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __awaiter, __extends, __generator, __read } from "tslib";
|
|
2
|
+
import { CookieStorage } from './cookie';
|
|
3
|
+
var UTMCookie = /** @class */ (function (_super) {
|
|
4
|
+
__extends(UTMCookie, _super);
|
|
5
|
+
function UTMCookie() {
|
|
6
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
7
|
+
}
|
|
8
|
+
UTMCookie.prototype.get = function (key) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
10
|
+
var value, entries, _a;
|
|
11
|
+
return __generator(this, function (_b) {
|
|
12
|
+
switch (_b.label) {
|
|
13
|
+
case 0:
|
|
14
|
+
_b.trys.push([0, 2, , 3]);
|
|
15
|
+
return [4 /*yield*/, this.getRaw(key)];
|
|
16
|
+
case 1:
|
|
17
|
+
value = _b.sent();
|
|
18
|
+
if (!value) {
|
|
19
|
+
return [2 /*return*/, undefined];
|
|
20
|
+
}
|
|
21
|
+
entries = value.split('.').splice(-1)[0].split('|');
|
|
22
|
+
return [2 /*return*/, entries.reduce(function (acc, curr) {
|
|
23
|
+
var _a = __read(curr.split('=', 2), 2), key = _a[0], _b = _a[1], value = _b === void 0 ? '' : _b;
|
|
24
|
+
if (!value) {
|
|
25
|
+
return acc;
|
|
26
|
+
}
|
|
27
|
+
acc[key] = decodeURIComponent(value);
|
|
28
|
+
return acc;
|
|
29
|
+
}, {})];
|
|
30
|
+
case 2:
|
|
31
|
+
_a = _b.sent();
|
|
32
|
+
return [2 /*return*/, undefined];
|
|
33
|
+
case 3: return [2 /*return*/];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
UTMCookie.prototype.set = function () {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
return __generator(this, function (_a) {
|
|
41
|
+
return [2 /*return*/, undefined];
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return UTMCookie;
|
|
46
|
+
}(CookieStorage));
|
|
47
|
+
export { UTMCookie };
|
|
48
|
+
//# sourceMappingURL=utm-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utm-cookie.js","sourceRoot":"","sources":["../../../src/storage/utm-cookie.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;IAA+B,6BAAiD;IAAhF;;IAwBA,CAAC;IAvBO,uBAAG,GAAT,UAAU,GAAW;;;;;;;wBAEH,qBAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAA;;wBAA9B,KAAK,GAAG,SAAsB;wBACpC,IAAI,CAAC,KAAK,EAAE;4BACV,sBAAO,SAAS,EAAC;yBAClB;wBACK,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;wBAC1D,sBAAO,OAAO,CAAC,MAAM,CAAqC,UAAC,GAAG,EAAE,IAAI;gCAC5D,IAAA,KAAA,OAAoB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAA,EAArC,GAAG,QAAA,EAAE,UAAU,EAAV,KAAK,mBAAG,EAAE,KAAsB,CAAC;gCAC7C,IAAI,CAAC,KAAK,EAAE;oCACV,OAAO,GAAG,CAAC;iCACZ;gCACD,GAAG,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;gCACrC,OAAO,GAAG,CAAC;4BACb,CAAC,EAAE,EAAE,CAAC,EAAC;;;wBAEP,sBAAO,SAAS,EAAC;;;;;KAEpB;IAEK,uBAAG,GAAT;;;gBACE,sBAAO,SAAS,EAAC;;;KAClB;IACH,gBAAC;AAAD,CAAC,AAxBD,CAA+B,aAAa,GAwB3C","sourcesContent":["import { CookieStorage } from './cookie';\n\nexport class UTMCookie extends CookieStorage<Record<string, string | undefined>> {\n async get(key: string): Promise<Record<string, string | undefined> | undefined> {\n try {\n const value = await this.getRaw(key);\n if (!value) {\n return undefined;\n }\n const entries = value.split('.').splice(-1)[0].split('|');\n return entries.reduce<Record<string, string | undefined>>((acc, curr) => {\n const [key, value = ''] = curr.split('=', 2);\n if (!value) {\n return acc;\n }\n acc[key] = decodeURIComponent(value);\n return acc;\n }, {});\n } catch {\n return undefined;\n }\n }\n\n async set(): Promise<void> {\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
3
|
+
export declare class FetchTransport extends BaseTransport implements Transport {
|
|
4
|
+
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +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;CAkB1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
3
|
+
var FetchTransport = /** @class */ (function (_super) {
|
|
4
|
+
__extends(FetchTransport, _super);
|
|
5
|
+
function FetchTransport() {
|
|
6
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
7
|
+
}
|
|
8
|
+
FetchTransport.prototype.send = function (serverUrl, payload) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
10
|
+
var options, response, responsePayload;
|
|
11
|
+
return __generator(this, function (_a) {
|
|
12
|
+
switch (_a.label) {
|
|
13
|
+
case 0:
|
|
14
|
+
/* istanbul ignore if */
|
|
15
|
+
if (typeof fetch === 'undefined') {
|
|
16
|
+
throw new Error('FetchTransport is not supported');
|
|
17
|
+
}
|
|
18
|
+
options = {
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
Accept: '*/*',
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify(payload),
|
|
24
|
+
method: 'POST',
|
|
25
|
+
};
|
|
26
|
+
return [4 /*yield*/, fetch(serverUrl, options)];
|
|
27
|
+
case 1:
|
|
28
|
+
response = _a.sent();
|
|
29
|
+
return [4 /*yield*/, response.json()];
|
|
30
|
+
case 2:
|
|
31
|
+
responsePayload = _a.sent();
|
|
32
|
+
return [2 /*return*/, this.buildResponse(responsePayload)];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return FetchTransport;
|
|
38
|
+
}(BaseTransport));
|
|
39
|
+
export { FetchTransport };
|
|
40
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +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;;IAmBA,CAAC;IAlBO,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;wBAEH,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5D,eAAe,GAAwB,SAAqB;wBAClE,sBAAO,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,EAAC;;;;KAC5C;IACH,qBAAC;AAAD,CAAC,AAnBD,CAAoC,aAAa,GAmBhD","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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const responsePayload: Record<string, any> = await response.json();\n return this.buildResponse(responsePayload);\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amplitude/analytics-client-common",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "Amplitude Inc",
|
|
6
|
+
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/esm/index.d.ts",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn build:es5 && yarn build:esm",
|
|
20
|
+
"build:es5": "tsc -p ./tsconfig.es5.json",
|
|
21
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
22
|
+
"clean": "rimraf node_modules lib coverage",
|
|
23
|
+
"fix": "yarn fix:eslint & yarn fix:prettier",
|
|
24
|
+
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
25
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
26
|
+
"lint": "yarn lint:eslint & yarn lint:prettier",
|
|
27
|
+
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
28
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"typecheck": "tsc -p ./tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@amplitude/analytics-core": "^0.9.0",
|
|
37
|
+
"@amplitude/analytics-types": "^0.9.0",
|
|
38
|
+
"tslib": "^2.3.1"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"lib"
|
|
42
|
+
],
|
|
43
|
+
"gitHead": "b05595653967707fa6db014030f071ff5eca6e82"
|
|
44
|
+
}
|