@amplitude/analytics-core 0.5.0 → 0.6.2
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/config.d.ts +1 -3
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +0 -2
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/core-client.d.ts +2 -0
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +5 -7
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts +11 -9
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +63 -69
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/storage/memory.d.ts +6 -6
- package/lib/cjs/storage/memory.d.ts.map +1 -1
- package/lib/cjs/storage/memory.js +40 -7
- package/lib/cjs/storage/memory.js.map +1 -1
- package/lib/cjs/timeline.d.ts +12 -7
- package/lib/cjs/timeline.d.ts.map +1 -1
- package/lib/cjs/timeline.js +154 -138
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/cjs/utils/return-wrapper.d.ts +1 -1
- package/lib/cjs/utils/return-wrapper.d.ts.map +1 -1
- package/lib/cjs/utils/return-wrapper.js.map +1 -1
- package/lib/cjs/utils/valid-properties.d.ts.map +1 -1
- package/lib/cjs/utils/valid-properties.js +3 -0
- package/lib/cjs/utils/valid-properties.js.map +1 -1
- package/lib/esm/config.d.ts +1 -3
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +0 -2
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/core-client.d.ts +2 -0
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +6 -8
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts +11 -9
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +63 -69
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/storage/memory.d.ts +6 -6
- package/lib/esm/storage/memory.d.ts.map +1 -1
- package/lib/esm/storage/memory.js +40 -7
- package/lib/esm/storage/memory.js.map +1 -1
- package/lib/esm/timeline.d.ts +12 -7
- package/lib/esm/timeline.d.ts.map +1 -1
- package/lib/esm/timeline.js +153 -130
- package/lib/esm/timeline.js.map +1 -1
- package/lib/esm/utils/return-wrapper.d.ts +1 -1
- package/lib/esm/utils/return-wrapper.d.ts.map +1 -1
- package/lib/esm/utils/return-wrapper.js.map +1 -1
- package/lib/esm/utils/valid-properties.d.ts.map +1 -1
- package/lib/esm/utils/valid-properties.js +3 -0
- package/lib/esm/utils/valid-properties.js.map +1 -1
- package/package.json +3 -3
package/lib/esm/timeline.js
CHANGED
|
@@ -2,139 +2,162 @@ import { __assign, __awaiter, __generator, __read, __values } from "tslib";
|
|
|
2
2
|
import { PluginType, } from '@amplitude/analytics-types';
|
|
3
3
|
import { OPT_OUT_MESSAGE } from './messages';
|
|
4
4
|
import { buildResult } from './utils/result-builder';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
applying = true;
|
|
36
|
-
setTimeout(function () {
|
|
37
|
-
void apply().then(function () {
|
|
38
|
-
applying = false;
|
|
39
|
-
if (queue.length > 0) {
|
|
40
|
-
scheduleApply(0);
|
|
5
|
+
var Timeline = /** @class */ (function () {
|
|
6
|
+
function Timeline() {
|
|
7
|
+
this.queue = [];
|
|
8
|
+
this.applying = false;
|
|
9
|
+
this.flushing = false;
|
|
10
|
+
this.plugins = [];
|
|
11
|
+
}
|
|
12
|
+
Timeline.prototype.register = function (plugin, config) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
14
|
+
return __generator(this, function (_a) {
|
|
15
|
+
switch (_a.label) {
|
|
16
|
+
case 0: return [4 /*yield*/, plugin.setup(config)];
|
|
17
|
+
case 1:
|
|
18
|
+
_a.sent();
|
|
19
|
+
this.plugins.push(plugin);
|
|
20
|
+
return [2 /*return*/];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
Timeline.prototype.deregister = function (pluginName) {
|
|
26
|
+
this.plugins.splice(this.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
};
|
|
29
|
+
Timeline.prototype.push = function (event, config) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
return new Promise(function (resolve) {
|
|
32
|
+
if (config.optOut) {
|
|
33
|
+
resolve(buildResult(event, 0, OPT_OUT_MESSAGE));
|
|
34
|
+
return;
|
|
41
35
|
}
|
|
36
|
+
_this.queue.push([event, resolve]);
|
|
37
|
+
_this.scheduleApply(0);
|
|
42
38
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
39
|
+
};
|
|
40
|
+
Timeline.prototype.scheduleApply = function (timeout) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
if (this.applying)
|
|
43
|
+
return;
|
|
44
|
+
this.applying = true;
|
|
45
|
+
setTimeout(function () {
|
|
46
|
+
void _this.apply(_this.queue.shift()).then(function () {
|
|
47
|
+
_this.applying = false;
|
|
48
|
+
if (_this.queue.length > 0) {
|
|
49
|
+
_this.scheduleApply(0);
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
51
|
+
});
|
|
52
|
+
}, timeout);
|
|
53
|
+
};
|
|
54
|
+
Timeline.prototype.apply = function (item) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var _a, event, _b, resolve, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
|
|
57
|
+
var e_1, _c, e_2, _d;
|
|
58
|
+
return __generator(this, function (_e) {
|
|
59
|
+
switch (_e.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
if (!item) {
|
|
62
|
+
return [2 /*return*/];
|
|
63
|
+
}
|
|
64
|
+
_a = __read(item, 1), event = _a[0];
|
|
65
|
+
_b = __read(item, 2), resolve = _b[1];
|
|
66
|
+
before = this.plugins.filter(function (plugin) { return plugin.type === PluginType.BEFORE; });
|
|
67
|
+
_e.label = 1;
|
|
68
|
+
case 1:
|
|
69
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
70
|
+
before_1 = __values(before), before_1_1 = before_1.next();
|
|
71
|
+
_e.label = 2;
|
|
72
|
+
case 2:
|
|
73
|
+
if (!!before_1_1.done) return [3 /*break*/, 5];
|
|
74
|
+
plugin = before_1_1.value;
|
|
75
|
+
return [4 /*yield*/, plugin.execute(__assign({}, event))];
|
|
76
|
+
case 3:
|
|
77
|
+
event = _e.sent();
|
|
78
|
+
_e.label = 4;
|
|
79
|
+
case 4:
|
|
80
|
+
before_1_1 = before_1.next();
|
|
81
|
+
return [3 /*break*/, 2];
|
|
82
|
+
case 5: return [3 /*break*/, 8];
|
|
83
|
+
case 6:
|
|
84
|
+
e_1_1 = _e.sent();
|
|
85
|
+
e_1 = { error: e_1_1 };
|
|
86
|
+
return [3 /*break*/, 8];
|
|
87
|
+
case 7:
|
|
88
|
+
try {
|
|
89
|
+
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
|
|
90
|
+
}
|
|
91
|
+
finally { if (e_1) throw e_1.error; }
|
|
92
|
+
return [7 /*endfinally*/];
|
|
93
|
+
case 8:
|
|
94
|
+
enrichment = this.plugins.filter(function (plugin) { return plugin.type === PluginType.ENRICHMENT; });
|
|
95
|
+
_e.label = 9;
|
|
96
|
+
case 9:
|
|
97
|
+
_e.trys.push([9, 14, 15, 16]);
|
|
98
|
+
enrichment_1 = __values(enrichment), enrichment_1_1 = enrichment_1.next();
|
|
99
|
+
_e.label = 10;
|
|
100
|
+
case 10:
|
|
101
|
+
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
|
|
102
|
+
plugin = enrichment_1_1.value;
|
|
103
|
+
return [4 /*yield*/, plugin.execute(__assign({}, event))];
|
|
104
|
+
case 11:
|
|
105
|
+
event = _e.sent();
|
|
106
|
+
_e.label = 12;
|
|
107
|
+
case 12:
|
|
108
|
+
enrichment_1_1 = enrichment_1.next();
|
|
109
|
+
return [3 /*break*/, 10];
|
|
110
|
+
case 13: return [3 /*break*/, 16];
|
|
111
|
+
case 14:
|
|
112
|
+
e_2_1 = _e.sent();
|
|
113
|
+
e_2 = { error: e_2_1 };
|
|
114
|
+
return [3 /*break*/, 16];
|
|
115
|
+
case 15:
|
|
116
|
+
try {
|
|
117
|
+
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
|
|
118
|
+
}
|
|
119
|
+
finally { if (e_2) throw e_2.error; }
|
|
120
|
+
return [7 /*endfinally*/];
|
|
121
|
+
case 16:
|
|
122
|
+
destination = this.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
|
|
123
|
+
executeDestinations = destination.map(function (plugin) {
|
|
124
|
+
var eventClone = __assign({}, event);
|
|
125
|
+
return plugin.execute(eventClone).catch(function (e) { return buildResult(eventClone, 0, String(e)); });
|
|
126
|
+
});
|
|
127
|
+
void Promise.all(executeDestinations).then(function (_a) {
|
|
128
|
+
var _b = __read(_a, 1), result = _b[0];
|
|
129
|
+
resolve(result);
|
|
130
|
+
});
|
|
131
|
+
return [2 /*return*/];
|
|
81
132
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return [3 /*break*/, 16];
|
|
106
|
-
case 15:
|
|
107
|
-
try {
|
|
108
|
-
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
Timeline.prototype.flush = function () {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
var queue, destination, executeDestinations;
|
|
139
|
+
var _this = this;
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
switch (_a.label) {
|
|
142
|
+
case 0:
|
|
143
|
+
queue = this.queue;
|
|
144
|
+
this.queue = [];
|
|
145
|
+
return [4 /*yield*/, Promise.all(queue.map(function (item) { return _this.apply(item); }))];
|
|
146
|
+
case 1:
|
|
147
|
+
_a.sent();
|
|
148
|
+
destination = this.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
|
|
149
|
+
executeDestinations = destination.map(function (plugin) {
|
|
150
|
+
return plugin.flush && plugin.flush();
|
|
151
|
+
});
|
|
152
|
+
return [4 /*yield*/, Promise.all(executeDestinations)];
|
|
153
|
+
case 2:
|
|
154
|
+
_a.sent();
|
|
155
|
+
return [2 /*return*/];
|
|
109
156
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return plugin.execute(eventClone).catch(function (e) { return buildResult(eventClone, 0, String(e)); });
|
|
117
|
-
});
|
|
118
|
-
void Promise.all(executeDestinations).then(function (_a) {
|
|
119
|
-
var _b = __read(_a, 1), result = _b[0];
|
|
120
|
-
resolve(result);
|
|
121
|
-
});
|
|
122
|
-
return [2 /*return*/];
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}); };
|
|
126
|
-
export var flush = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
127
|
-
var destination, flushDestinations;
|
|
128
|
-
return __generator(this, function (_a) {
|
|
129
|
-
switch (_a.label) {
|
|
130
|
-
case 0:
|
|
131
|
-
destination = config.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
|
|
132
|
-
flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
|
|
133
|
-
return [4 /*yield*/, Promise.all(flushDestinations)];
|
|
134
|
-
case 1:
|
|
135
|
-
_a.sent();
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}); };
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
return Timeline;
|
|
161
|
+
}());
|
|
162
|
+
export { Timeline };
|
|
140
163
|
//# sourceMappingURL=timeline.js.map
|
package/lib/esm/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings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AAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAnGD,IAmGC","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { OPT_OUT_MESSAGE } from './messages';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n applying = false;\n flushing = false;\n plugins: Plugin[] = [];\n\n async register(plugin: Plugin, config: Config) {\n await plugin.setup(config);\n this.plugins.push(plugin);\n }\n\n deregister(pluginName: string) {\n this.plugins.splice(\n this.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n }\n\n push(event: Event, config: Config) {\n return new Promise<Result>((resolve) => {\n if (config.optOut) {\n resolve(buildResult(event, 0, OPT_OUT_MESSAGE));\n return;\n }\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === PluginType.BEFORE,\n );\n\n for (const plugin of before) {\n event = await plugin.execute({ ...event });\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === PluginType.ENRICHMENT,\n );\n\n for (const plugin of enrichment) {\n event = await plugin.execute({ ...event });\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n resolve(result);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AmplitudeReturn } from '@amplitude/analytics-types';
|
|
2
|
-
export declare const returnWrapper: <T extends (...args: any) => any>(fn: T) => (...args: Parameters<T>) => AmplitudeReturn<
|
|
2
|
+
export declare const returnWrapper: <T extends (...args: any) => any>(fn: T) => (...args: Parameters<T>) => AmplitudeReturn<ReturnType<T>>;
|
|
3
3
|
//# sourceMappingURL=return-wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,eAAO,MAAM,aAAa,uBACH,GAAG,KAAK,GAAG
|
|
1
|
+
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,eAAO,MAAM,aAAa,uBACH,GAAG,KAAK,GAAG,sEAG9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";AAEA,MAAM,CAAC,IAAM,aAAa,GACxB,UAAkC,EAAK;IACvC,OAAA;QAAC,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;
|
|
1
|
+
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";AAEA,MAAM,CAAC,IAAM,aAAa,GACxB,UAAkC,EAAK;IACvC,OAAA;QAAC,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;QAAqC,OAAA,CAAC;YAC3D,OAAO,EAAE,EAAE,wCAAI,IAAI,UAAkB;SACtC,CAAC;IAF0D,CAE1D;AAFF,CAEE,CAAC","sourcesContent":["import { AmplitudeReturn } from '@amplitude/analytics-types';\n\nexport const returnWrapper =\n <T extends (...args: any) => any>(fn: T) =>\n (...args: Parameters<T>): AmplitudeReturn<ReturnType<T>> => ({\n promise: fn(...args) as ReturnType<T>,\n });\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-properties.d.ts","sourceRoot":"","sources":["../../../src/utils/valid-properties.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa;;MAAyC,OAUlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAAc,MAAM,SAAS,GAAG,KAAG,
|
|
1
|
+
{"version":3,"file":"valid-properties.d.ts","sourceRoot":"","sources":["../../../src/utils/valid-properties.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa;;MAAyC,OAUlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAAc,MAAM,SAAS,GAAG,KAAG,OAyBhE,CAAC"}
|
|
@@ -43,6 +43,9 @@ export var isValidProperties = function (property, value) {
|
|
|
43
43
|
finally { if (e_1) throw e_1.error; }
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
else if (value === null || value === undefined) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
46
49
|
else if (typeof value === 'object') {
|
|
47
50
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
48
51
|
return isValidObject(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-properties.js","sourceRoot":"","sources":["../../../src/utils/valid-properties.ts"],"names":[],"mappings":";AAAA,IAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,UAAkC;IAC9D,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,iBAAiB,EAAE;QACtD,OAAO,KAAK,CAAC;KACd;IACD,KAAK,IAAM,GAAG,IAAI,UAAU,EAAE;QAC5B,mEAAmE;QACnE,IAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;KAClD;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,QAAgB,EAAE,KAAU;;IAC5D,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,IAAI,OAAO,GAAG,IAAI,CAAC;;YACnB,KAA2B,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE;gBAA7B,IAAM,YAAY,kBAAA;gBACrB,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;oBAC/B,OAAO,KAAK,CAAC;iBACd;qBAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;oBAC3C,OAAO,GAAG,OAAO,IAAI,aAAa,CAAC,YAAsB,CAAC,CAAC;iBAC5D;qBAAM,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,YAAY,CAAC,EAAE;oBAC9D,OAAO,KAAK,CAAC;iBACd;gBACD,IAAI,CAAC,OAAO,EAAE;oBACZ,OAAO,KAAK,CAAC;iBACd;aACF;;;;;;;;;KACF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,iEAAiE;QACjE,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;KAC7B;SAAM,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,EAAE;QAClE,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["const MAX_PROPERTY_KEYS = 1000;\n\nexport const isValidObject = (properties: { [key: string]: any }): boolean => {\n if (Object.keys(properties).length > MAX_PROPERTY_KEYS) {\n return false;\n }\n for (const key in properties) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const value = properties[key];\n if (!isValidProperties(key, value)) return false;\n }\n return true;\n};\n\nexport const isValidProperties = (property: string, value: any): boolean => {\n if (typeof property !== 'string') return false;\n if (Array.isArray(value)) {\n let isValid = true;\n for (const valueElement of value) {\n if (Array.isArray(valueElement)) {\n return false;\n } else if (typeof valueElement === 'object') {\n isValid = isValid && isValidObject(valueElement as object);\n } else if (!['number', 'string'].includes(typeof valueElement)) {\n return false;\n }\n if (!isValid) {\n return false;\n }\n }\n } else if (typeof value === 'object') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return isValidObject(value);\n } else if (!['number', 'string', 'boolean'].includes(typeof value)) {\n return false;\n }\n return true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"valid-properties.js","sourceRoot":"","sources":["../../../src/utils/valid-properties.ts"],"names":[],"mappings":";AAAA,IAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,UAAkC;IAC9D,IAAI,MAAM,CA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AC;KAC7B;SAAM,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,EAAE;QAClE,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["const MAX_PROPERTY_KEYS = 1000;\n\nexport const isValidObject = (properties: { [key: string]: any }): boolean => {\n if (Object.keys(properties).length > MAX_PROPERTY_KEYS) {\n return false;\n }\n for (const key in properties) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const value = properties[key];\n if (!isValidProperties(key, value)) return false;\n }\n return true;\n};\n\nexport const isValidProperties = (property: string, value: any): boolean => {\n if (typeof property !== 'string') return false;\n if (Array.isArray(value)) {\n let isValid = true;\n for (const valueElement of value) {\n if (Array.isArray(valueElement)) {\n return false;\n } else if (typeof valueElement === 'object') {\n isValid = isValid && isValidObject(valueElement as object);\n } else if (!['number', 'string'].includes(typeof valueElement)) {\n return false;\n }\n if (!isValid) {\n return false;\n }\n }\n } else if (value === null || value === undefined) {\n return false;\n } else if (typeof value === 'object') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return isValidObject(value);\n } else if (!['number', 'string', 'boolean'].includes(typeof value)) {\n return false;\n }\n return true;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@amplitude/analytics-types": "^0.
|
|
35
|
+
"@amplitude/analytics-types": "^0.5.1",
|
|
36
36
|
"tslib": "^2.3.1"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"lib"
|
|
40
40
|
],
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "4956aed5c5799b948bd9cdaa8ae2357eff823abb"
|
|
42
42
|
}
|