@amplitude/analytics-core 0.2.4 → 0.3.0
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/config.d.ts +8 -9
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +34 -52
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/core-client.d.ts +17 -12
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +83 -84
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +6 -15
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/messages.d.ts +1 -1
- package/lib/cjs/messages.d.ts.map +1 -1
- package/lib/cjs/messages.js +1 -1
- package/lib/cjs/messages.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +4 -3
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/utils/event-builder.d.ts +2 -2
- package/lib/cjs/utils/event-builder.d.ts.map +1 -1
- package/lib/cjs/utils/event-builder.js +3 -2
- package/lib/cjs/utils/event-builder.js.map +1 -1
- package/lib/cjs/utils/response-builder.d.ts.map +1 -1
- package/lib/cjs/utils/response-builder.js +16 -15
- package/lib/cjs/utils/response-builder.js.map +1 -1
- package/lib/cjs/utils/return-wrapper.d.ts +3 -0
- package/lib/cjs/utils/return-wrapper.d.ts.map +1 -0
- package/lib/cjs/utils/return-wrapper.js +16 -0
- package/lib/cjs/utils/return-wrapper.js.map +1 -0
- package/lib/cjs/utils/valid-properties.d.ts.map +1 -1
- package/lib/cjs/utils/valid-properties.js +5 -1
- package/lib/cjs/utils/valid-properties.js.map +1 -1
- package/lib/esm/config.d.ts +8 -9
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +21 -38
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/core-client.d.ts +17 -12
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +82 -72
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/messages.d.ts +1 -1
- package/lib/esm/messages.d.ts.map +1 -1
- package/lib/esm/messages.js +1 -1
- package/lib/esm/messages.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +5 -4
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/utils/event-builder.d.ts +2 -2
- package/lib/esm/utils/event-builder.d.ts.map +1 -1
- package/lib/esm/utils/event-builder.js +3 -2
- package/lib/esm/utils/event-builder.js.map +1 -1
- package/lib/esm/utils/response-builder.d.ts.map +1 -1
- package/lib/esm/utils/response-builder.js +16 -15
- package/lib/esm/utils/response-builder.js.map +1 -1
- package/lib/esm/utils/return-wrapper.d.ts +3 -0
- package/lib/esm/utils/return-wrapper.d.ts.map +1 -0
- package/lib/esm/utils/return-wrapper.js +13 -0
- package/lib/esm/utils/return-wrapper.js.map +1 -0
- package/lib/esm/utils/valid-properties.d.ts.map +1 -1
- package/lib/esm/utils/valid-properties.js +5 -1
- package/lib/esm/utils/valid-properties.js.map +1 -1
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/cjs/config.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plugin, ServerZone } from '@amplitude/analytics-types';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
-
export declare const
|
|
4
|
-
US: (useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch";
|
|
5
|
-
EU: (useBatch: boolean) => "https://api.eu.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/batch";
|
|
6
|
-
};
|
|
7
|
-
export declare const defaultConfig: {
|
|
3
|
+
export declare const getDefaultConfig: () => {
|
|
8
4
|
flushMaxRetries: number;
|
|
9
5
|
flushQueueSize: number;
|
|
10
6
|
flushIntervalMillis: number;
|
|
@@ -12,12 +8,14 @@ export declare const defaultConfig: {
|
|
|
12
8
|
loggerProvider: Logger;
|
|
13
9
|
saveEvents: boolean;
|
|
14
10
|
optOut: boolean;
|
|
11
|
+
plugins: never[];
|
|
15
12
|
serverUrl: string;
|
|
16
13
|
serverZone: ServerZone;
|
|
17
14
|
useBatch: boolean;
|
|
18
15
|
};
|
|
19
16
|
export declare class Config implements IConfig {
|
|
20
17
|
apiKey: string;
|
|
18
|
+
appVersion?: string;
|
|
21
19
|
userId?: string;
|
|
22
20
|
deviceId?: string;
|
|
23
21
|
sessionId?: number;
|
|
@@ -37,8 +35,9 @@ export declare class Config implements IConfig {
|
|
|
37
35
|
useBatch: boolean;
|
|
38
36
|
constructor(options: InitOptions<IConfig>);
|
|
39
37
|
}
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
export declare const getServerUrl: (serverZone: ServerZone, useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch" | "https://api.eu.amplitude.com/batch";
|
|
39
|
+
export declare const createServerConfig: (serverZone?: ServerZone, useBatch?: boolean) => {
|
|
40
|
+
serverZone: ServerZone;
|
|
41
|
+
serverUrl: string;
|
|
42
|
+
};
|
|
44
43
|
//# sourceMappingURL=config.d.ts.map
|
package/lib/cjs/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,UAAU,EACX,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,UAAU,EACX,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAY3B,CAAC;AAEH,qBAAa,MAAO,YAAW,OAAO;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAClC,QAAQ,EAAE,OAAO,CAAC;gBAEN,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;CA2B1C;AAED,eAAO,MAAM,YAAY,eAAgB,UAAU,YAAY,OAAO,kKAKrE,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBACjB,UAAU,aACZ,OAAO;;;CAOlB,CAAC"}
|
package/lib/cjs/config.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
2
|
+
exports.createServerConfig = exports.getServerUrl = exports.Config = exports.getDefaultConfig = void 0;
|
|
4
3
|
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
5
4
|
var constants_1 = require("./constants");
|
|
6
5
|
var logger_1 = require("./logger");
|
|
7
|
-
var
|
|
8
|
-
var instances = {};
|
|
9
|
-
exports.serverUrls = (_a = {},
|
|
10
|
-
_a[analytics_types_1.ServerZone.US] = function (useBatch) { return (useBatch ? constants_1.AMPLITUDE_BATCH_SERVER_URL : constants_1.AMPLITUDE_SERVER_URL); },
|
|
11
|
-
_a[analytics_types_1.ServerZone.EU] = function (useBatch) { return (useBatch ? constants_1.EU_AMPLITUDE_BATCH_SERVER_URL : constants_1.EU_AMPLITUDE_SERVER_URL); },
|
|
12
|
-
_a);
|
|
13
|
-
exports.defaultConfig = {
|
|
6
|
+
var getDefaultConfig = function () { return ({
|
|
14
7
|
flushMaxRetries: 5,
|
|
15
8
|
flushQueueSize: 10,
|
|
16
9
|
flushIntervalMillis: 1000,
|
|
@@ -18,69 +11,58 @@ exports.defaultConfig = {
|
|
|
18
11
|
loggerProvider: new logger_1.Logger(),
|
|
19
12
|
saveEvents: true,
|
|
20
13
|
optOut: false,
|
|
14
|
+
plugins: [],
|
|
21
15
|
serverUrl: constants_1.AMPLITUDE_SERVER_URL,
|
|
22
16
|
serverZone: analytics_types_1.ServerZone.US,
|
|
23
17
|
useBatch: false,
|
|
24
|
-
};
|
|
18
|
+
}); };
|
|
19
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
25
20
|
var Config = /** @class */ (function () {
|
|
26
21
|
function Config(options) {
|
|
27
22
|
var _a, _b, _c, _d;
|
|
23
|
+
var defaultConfig = (0, exports.getDefaultConfig)();
|
|
28
24
|
this.apiKey = options.apiKey;
|
|
25
|
+
this.appVersion = options.appVersion;
|
|
29
26
|
this.userId = options.userId;
|
|
30
27
|
this.deviceId = options.deviceId;
|
|
31
28
|
this.sessionId = options.sessionId;
|
|
32
|
-
this.flushIntervalMillis = options.flushIntervalMillis ||
|
|
33
|
-
this.flushMaxRetries = options.flushMaxRetries ||
|
|
34
|
-
this.flushQueueSize = options.flushQueueSize ||
|
|
35
|
-
this.loggerProvider = options.loggerProvider ||
|
|
36
|
-
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a :
|
|
29
|
+
this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis;
|
|
30
|
+
this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;
|
|
31
|
+
this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;
|
|
32
|
+
this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;
|
|
33
|
+
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : defaultConfig.logLevel;
|
|
37
34
|
this.partnerId = options.partnerId;
|
|
38
|
-
this.plugins =
|
|
39
|
-
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b :
|
|
40
|
-
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c :
|
|
35
|
+
this.plugins = defaultConfig.plugins;
|
|
36
|
+
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut;
|
|
37
|
+
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents;
|
|
41
38
|
this.serverUrl = options.serverUrl;
|
|
42
|
-
this.serverZone = options.serverZone ||
|
|
39
|
+
this.serverZone = options.serverZone || defaultConfig.serverZone;
|
|
43
40
|
this.storageProvider = options.storageProvider;
|
|
44
41
|
this.transportProvider = options.transportProvider;
|
|
45
|
-
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d :
|
|
42
|
+
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch;
|
|
46
43
|
this.loggerProvider.enable(this.logLevel);
|
|
47
|
-
|
|
44
|
+
var serverConfig = (0, exports.createServerConfig)(options.serverZone, options.useBatch);
|
|
45
|
+
this.serverZone = serverConfig.serverZone;
|
|
46
|
+
this.serverUrl = serverConfig.serverUrl;
|
|
48
47
|
}
|
|
49
48
|
return Config;
|
|
50
49
|
}());
|
|
51
50
|
exports.Config = Config;
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
instances[DEFAULT_INSTANCE] = instances[DEFAULT_INSTANCE]
|
|
56
|
-
? Object.assign(instances[DEFAULT_INSTANCE], config)
|
|
57
|
-
: config;
|
|
58
|
-
return instances[DEFAULT_INSTANCE];
|
|
59
|
-
};
|
|
60
|
-
exports.createConfig = createConfig;
|
|
61
|
-
var getConfig = function () {
|
|
62
|
-
return instances[DEFAULT_INSTANCE];
|
|
63
|
-
};
|
|
64
|
-
exports.getConfig = getConfig;
|
|
65
|
-
var resetInstances = function () {
|
|
66
|
-
for (var name in instances) {
|
|
67
|
-
delete instances[name];
|
|
51
|
+
var getServerUrl = function (serverZone, useBatch) {
|
|
52
|
+
if (serverZone === analytics_types_1.ServerZone.EU) {
|
|
53
|
+
return useBatch ? constants_1.EU_AMPLITUDE_BATCH_SERVER_URL : constants_1.EU_AMPLITUDE_SERVER_URL;
|
|
68
54
|
}
|
|
55
|
+
return useBatch ? constants_1.AMPLITUDE_BATCH_SERVER_URL : constants_1.AMPLITUDE_SERVER_URL;
|
|
69
56
|
};
|
|
70
|
-
exports.
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
config.loggerProvider.warn("Unknown server zone \"".concat(config.serverZone, "\". Replaced with US server zone"));
|
|
80
|
-
config.serverZone = analytics_types_1.ServerZone.US;
|
|
81
|
-
}
|
|
82
|
-
config.serverUrl = exports.serverUrls[config.serverZone](config.useBatch);
|
|
83
|
-
}
|
|
84
|
-
return config.serverUrl;
|
|
57
|
+
exports.getServerUrl = getServerUrl;
|
|
58
|
+
var createServerConfig = function (serverZone, useBatch) {
|
|
59
|
+
if (serverZone === void 0) { serverZone = (0, exports.getDefaultConfig)().serverZone; }
|
|
60
|
+
if (useBatch === void 0) { useBatch = (0, exports.getDefaultConfig)().useBatch; }
|
|
61
|
+
var _serverZone = [analytics_types_1.ServerZone.US, analytics_types_1.ServerZone.EU].includes(serverZone) ? serverZone : (0, exports.getDefaultConfig)().serverZone;
|
|
62
|
+
return {
|
|
63
|
+
serverZone: _serverZone,
|
|
64
|
+
serverUrl: (0, exports.getServerUrl)(_serverZone, useBatch),
|
|
65
|
+
};
|
|
85
66
|
};
|
|
67
|
+
exports.createServerConfig = createServerConfig;
|
|
86
68
|
//# sourceMappingURL=config.js.map
|
package/lib/cjs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAAA,8DAUoC;AACpC,yCAKqB;AAErB,mCAAkC;AAE3B,IAAM,gBAAgB,GAAG,cAAM,OAAA,CAAC;IACrC,eAAe,EAAE,CAAC;IAClB,cAAc,EAAE,EAAE;IAClB,mBAAmB,EAAE,IAAI;IACzB,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,cAAc,EAAE,IAAI,eAAM,EAAE;IAC5B,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,gCAAoB;IAC/B,UAAU,EAAE,4BAAU,CAAC,EAAE;IACzB,QAAQ,EAAE,KAAK;CAChB,CAAC,EAZoC,CAYpC,CAAC;AAZU,QAAA,gBAAgB,oBAY1B;AAEH;IAqBE,gBAAY,OAA6B;;QACvC,IAAM,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC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O,CAAC,QAAQ,CAAC,CAAC;QAC9E,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;IAC1C,CAAC;IACH,aAAC;AAAD,CAAC,AAhDD,IAgDC;AAhDY,wBAAM;AAkDZ,IAAM,YAAY,GAAG,UAAC,UAAsB,EAAE,QAAiB;IACpE,IAAI,UAAU,KAAK,4BAAU,CAAC,EAAE,EAAE;QAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,yCAA6B,CAAC,CAAC,CAAC,mCAAuB,CAAC;KAC3E;IACD,OAAO,QAAQ,CAAC,CAAC,CAAC,sCAA0B,CAAC,CAAC,CAAC,gCAAoB,CAAC;AACtE,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEK,IAAM,kBAAkB,GAAG,UAChC,UAAsD,EACtD,QAA+C;IAD/C,2BAAA,EAAA,aAAyB,IAAA,wBAAgB,GAAE,CAAC,UAAU;IACtD,yBAAA,EAAA,WAAoB,IAAA,wBAAgB,GAAE,CAAC,QAAQ;IAE/C,IAAM,WAAW,GAAG,CAAC,4BAAU,CAAC,EAAE,EAAE,4BAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,wBAAgB,GAAE,CAAC,UAAU,CAAC;IACrH,OAAO;QACL,UAAU,EAAE,WAAW;QACvB,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,EAAE,QAAQ,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B","sourcesContent":["import {\n Event,\n Config as IConfig,\n Logger as ILogger,\n InitOptions,\n LogLevel,\n Storage,\n Transport,\n Plugin,\n ServerZone,\n} from '@amplitude/analytics-types';\nimport {\n AMPLITUDE_SERVER_URL,\n AMPLITUDE_BATCH_SERVER_URL,\n EU_AMPLITUDE_SERVER_URL,\n EU_AMPLITUDE_BATCH_SERVER_URL,\n} from './constants';\n\nimport { Logger } from './logger';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 5,\n flushQueueSize: 10,\n flushIntervalMillis: 1000,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n saveEvents: true,\n optOut: false,\n plugins: [],\n serverUrl: AMPLITUDE_SERVER_URL,\n serverZone: ServerZone.US,\n useBatch: false,\n});\n\nexport class Config implements IConfig {\n apiKey: string;\n appVersion?: string;\n userId?: string;\n deviceId?: string;\n sessionId?: number;\n flushIntervalMillis: number;\n flushMaxRetries: number;\n flushQueueSize: number;\n loggerProvider: ILogger;\n logLevel: LogLevel;\n partnerId?: string;\n plugins: Plugin[];\n optOut: boolean;\n saveEvents: boolean;\n serverUrl: string | undefined;\n serverZone: ServerZone;\n transportProvider: Transport;\n storageProvider: Storage<Event[]>;\n useBatch: boolean;\n\n constructor(options: InitOptions<IConfig>) {\n const defaultConfig = getDefaultConfig();\n this.apiKey = options.apiKey;\n this.appVersion = options.appVersion;\n this.userId = options.userId;\n this.deviceId = options.deviceId;\n this.sessionId = options.sessionId;\n this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis;\n this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;\n this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;\n this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;\n this.logLevel = options.logLevel ?? defaultConfig.logLevel;\n this.partnerId = options.partnerId;\n this.plugins = defaultConfig.plugins;\n this.optOut = options.optOut ?? defaultConfig.optOut;\n this.saveEvents = options.saveEvents ?? defaultConfig.saveEvents;\n this.serverUrl = options.serverUrl;\n this.serverZone = options.serverZone || defaultConfig.serverZone;\n this.storageProvider = options.storageProvider;\n this.transportProvider = options.transportProvider;\n this.useBatch = options.useBatch ?? defaultConfig.useBatch;\n this.loggerProvider.enable(this.logLevel);\n\n const serverConfig = createServerConfig(options.serverZone, options.useBatch);\n this.serverZone = serverConfig.serverZone;\n this.serverUrl = serverConfig.serverUrl;\n }\n}\n\nexport const getServerUrl = (serverZone: ServerZone, useBatch: boolean) => {\n if (serverZone === ServerZone.EU) {\n return useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL;\n }\n return useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL;\n};\n\nexport const createServerConfig = (\n serverZone: ServerZone = getDefaultConfig().serverZone,\n useBatch: boolean = getDefaultConfig().useBatch,\n) => {\n const _serverZone = [ServerZone.US, ServerZone.EU].includes(serverZone) ? serverZone : getDefaultConfig().serverZone;\n return {\n serverZone: _serverZone,\n serverUrl: getServerUrl(_serverZone, useBatch),\n };\n};\n"]}
|
package/lib/cjs/core-client.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { Config, Event, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class AmplitudeCore<T extends Config> {
|
|
3
|
+
name: string;
|
|
4
|
+
config: T;
|
|
5
|
+
constructor(name?: string);
|
|
6
|
+
init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>;
|
|
7
|
+
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
8
|
+
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
9
|
+
identify(identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>;
|
|
10
|
+
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string): Promise<import("@amplitude/analytics-types").Result>;
|
|
11
|
+
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
12
|
+
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
|
+
add(plugin: Plugin): Promise<void>;
|
|
14
|
+
remove(pluginName: string): Promise<void>;
|
|
15
|
+
dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>;
|
|
16
|
+
setOptOut(optOut: boolean): void;
|
|
17
|
+
}
|
|
13
18
|
//# sourceMappingURL=core-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAU/G,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM;IACzC,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;gBAEE,IAAI,SAAa;IAK7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC;IAKxE,KAAK,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxG,QAAQ,eALU,SAAS,GAAG,MAAM,sJAKH;IAEjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;IAK5F,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAC5B,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,YAAY,EAC3B,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM;IAMnB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAKxD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAKlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAKzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAgB3B,SAAS,CAAC,MAAM,EAAE,OAAO;CAI1B"}
|
package/lib/cjs/core-client.js
CHANGED
|
@@ -1,91 +1,90 @@
|
|
|
1
|
-
var _this = this;
|
|
2
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
2
|
+
exports.AmplitudeCore = void 0;
|
|
4
3
|
var tslib_1 = require("tslib");
|
|
5
|
-
var config_1 = require("./config");
|
|
6
4
|
var event_builder_1 = require("./utils/event-builder");
|
|
7
5
|
var timeline_1 = require("./timeline");
|
|
8
6
|
var result_builder_1 = require("./utils/result-builder");
|
|
9
|
-
var
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
7
|
+
var AmplitudeCore = /** @class */ (function () {
|
|
8
|
+
function AmplitudeCore(name) {
|
|
9
|
+
if (name === void 0) { name = '$default'; }
|
|
10
|
+
this.logEvent = this.track.bind(this);
|
|
11
|
+
this.name = name;
|
|
12
|
+
}
|
|
13
|
+
// NOTE: Do not use `_apiKey` and `_userId` here
|
|
14
|
+
AmplitudeCore.prototype.init = function (_apiKey, _userId, config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
};
|
|
18
|
+
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
|
|
19
|
+
var event = (0, event_builder_1.createTrackEvent)(eventInput, eventProperties, eventOptions);
|
|
20
|
+
return this.dispatch(event);
|
|
21
|
+
};
|
|
22
|
+
AmplitudeCore.prototype.identify = function (identify, eventOptions, userId, deviceId) {
|
|
23
|
+
var event = (0, event_builder_1.createIdentifyEvent)(userId, deviceId, identify, eventOptions);
|
|
24
|
+
return this.dispatch(event);
|
|
25
|
+
};
|
|
26
|
+
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions, userId, deviceId) {
|
|
27
|
+
var event = (0, event_builder_1.createGroupIdentifyEvent)(userId, deviceId, groupType, groupName, identify, eventOptions);
|
|
28
|
+
return this.dispatch(event);
|
|
29
|
+
};
|
|
30
|
+
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
31
|
+
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName);
|
|
32
|
+
return this.dispatch(event);
|
|
33
|
+
};
|
|
34
|
+
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
35
|
+
var event = (0, event_builder_1.createRevenueEvent)(revenue, eventOptions);
|
|
36
|
+
return this.dispatch(event);
|
|
37
|
+
};
|
|
38
|
+
AmplitudeCore.prototype.add = function (plugin) {
|
|
39
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
40
|
+
var config;
|
|
41
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
42
|
+
config = this.config;
|
|
43
|
+
return [2 /*return*/, (0, timeline_1.register)(plugin, config)];
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
AmplitudeCore.prototype.remove = function (pluginName) {
|
|
48
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
49
|
+
var config;
|
|
50
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
51
|
+
config = this.config;
|
|
52
|
+
return [2 /*return*/, (0, timeline_1.deregister)(pluginName, config)];
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
AmplitudeCore.prototype.dispatch = function (event) {
|
|
57
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
58
|
+
var result, e_1, message;
|
|
59
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
_a.trys.push([0, 2, , 3]);
|
|
63
|
+
return [4 /*yield*/, (0, timeline_1.push)(event, this.config)];
|
|
64
|
+
case 1:
|
|
65
|
+
result = _a.sent();
|
|
66
|
+
if (result.code === 200) {
|
|
67
|
+
this.config.loggerProvider.log(result.message);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.config.loggerProvider.error(result.message);
|
|
71
|
+
}
|
|
72
|
+
return [2 /*return*/, result];
|
|
73
|
+
case 2:
|
|
74
|
+
e_1 = _a.sent();
|
|
75
|
+
message = String(e_1);
|
|
76
|
+
this.config.loggerProvider.error(message);
|
|
77
|
+
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, message)];
|
|
78
|
+
case 3: return [2 /*return*/];
|
|
71
79
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}); };
|
|
85
|
-
exports.dispatch = dispatch;
|
|
86
|
-
var setOptOut = function (optOut) {
|
|
87
|
-
var config = (0, config_1.getConfig)();
|
|
88
|
-
config.optOut = Boolean(optOut);
|
|
89
|
-
};
|
|
90
|
-
exports.setOptOut = setOptOut;
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
AmplitudeCore.prototype.setOptOut = function (optOut) {
|
|
84
|
+
var config = this.config;
|
|
85
|
+
config.optOut = Boolean(optOut);
|
|
86
|
+
};
|
|
87
|
+
return AmplitudeCore;
|
|
88
|
+
}());
|
|
89
|
+
exports.AmplitudeCore = AmplitudeCore;
|
|
91
90
|
//# sourceMappingURL=core-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AACA,uDAM+B;AAC/B,uCAAwD;AACxD,yDAAqD;AACrD;IAME,uBAAY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,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACH,oBAAC;AAAD,CAAC,AAhFD,IAgFC;AAhFY,sCAAa","sourcesContent":["import { Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';\nimport {\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createTrackEvent,\n createRevenueEvent,\n createGroupEvent,\n} from './utils/event-builder';\nimport { deregister, push, register } from './timeline';\nimport { buildResult } from './utils/result-builder';\nexport class AmplitudeCore<T extends Config> {\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n\n constructor(name = '$default') {\n this.name = name;\n }\n\n // NOTE: Do not use `_apiKey` and `_userId` here\n init(_apiKey: string | undefined, _userId: string | undefined, config: T) {\n this.config = config;\n return Promise.resolve();\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions, userId?: string, deviceId?: string) {\n const event = createIdentifyEvent(userId, deviceId, identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(\n groupType: string,\n groupName: string | string[],\n identify: Identify,\n eventOptions?: EventOptions,\n userId?: string,\n deviceId?: string,\n ) {\n const event = createGroupIdentifyEvent(userId, deviceId, groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[]) {\n const event = createGroupEvent(groupType, groupName);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n const config = this.config;\n return register(plugin, config);\n }\n\n async remove(pluginName: string) {\n const config = this.config;\n return deregister(pluginName, config);\n }\n\n async dispatch(event: Event) {\n try {\n const result = await push(event, this.config);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\n this.config.loggerProvider.error(result.message);\n }\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n return buildResult(event, 0, message);\n }\n }\n\n setOptOut(optOut: boolean) {\n const config = this.config;\n config.optOut = Boolean(optOut);\n }\n}\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { getConfig } from './config';
|
|
1
|
+
export { AmplitudeCore } from './core-client';
|
|
3
2
|
export { buildResponse } from './utils/response-builder';
|
|
4
3
|
export { Identify } from './identify';
|
|
5
4
|
export { Revenue } from './revenue';
|
|
@@ -7,4 +6,5 @@ export { Destination } from './plugins/destination';
|
|
|
7
6
|
export { Config } from './config';
|
|
8
7
|
export { Logger } from './logger';
|
|
9
8
|
export { AMPLITUDE_PREFIX } from './constants';
|
|
9
|
+
export { returnWrapper } from './utils/return-wrapper';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.buildResponse = exports.
|
|
2
|
+
exports.returnWrapper = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.buildResponse = exports.AmplitudeCore = void 0;
|
|
3
3
|
var core_client_1 = require("./core-client");
|
|
4
|
-
Object.defineProperty(exports, "
|
|
5
|
-
Object.defineProperty(exports, "track", { enumerable: true, get: function () { return core_client_1.track; } });
|
|
6
|
-
Object.defineProperty(exports, "logEvent", { enumerable: true, get: function () { return core_client_1.logEvent; } });
|
|
7
|
-
Object.defineProperty(exports, "identify", { enumerable: true, get: function () { return core_client_1.identify; } });
|
|
8
|
-
Object.defineProperty(exports, "groupIdentify", { enumerable: true, get: function () { return core_client_1.groupIdentify; } });
|
|
9
|
-
Object.defineProperty(exports, "setGroup", { enumerable: true, get: function () { return core_client_1.setGroup; } });
|
|
10
|
-
Object.defineProperty(exports, "revenue", { enumerable: true, get: function () { return core_client_1.revenue; } });
|
|
11
|
-
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return core_client_1.add; } });
|
|
12
|
-
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return core_client_1.remove; } });
|
|
13
|
-
Object.defineProperty(exports, "setOptOut", { enumerable: true, get: function () { return core_client_1.setOptOut; } });
|
|
14
|
-
var config_1 = require("./config");
|
|
15
|
-
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
4
|
+
Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } });
|
|
16
5
|
var response_builder_1 = require("./utils/response-builder");
|
|
17
6
|
Object.defineProperty(exports, "buildResponse", { enumerable: true, get: function () { return response_builder_1.buildResponse; } });
|
|
18
7
|
var identify_1 = require("./identify");
|
|
@@ -21,10 +10,12 @@ var revenue_1 = require("./revenue");
|
|
|
21
10
|
Object.defineProperty(exports, "Revenue", { enumerable: true, get: function () { return revenue_1.Revenue; } });
|
|
22
11
|
var destination_1 = require("./plugins/destination");
|
|
23
12
|
Object.defineProperty(exports, "Destination", { enumerable: true, get: function () { return destination_1.Destination; } });
|
|
24
|
-
var
|
|
25
|
-
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return
|
|
13
|
+
var config_1 = require("./config");
|
|
14
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
26
15
|
var logger_1 = require("./logger");
|
|
27
16
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
28
17
|
var constants_1 = require("./constants");
|
|
29
18
|
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_1.AMPLITUDE_PREFIX; } });
|
|
19
|
+
var return_wrapper_1 = require("./utils/return-wrapper");
|
|
20
|
+
Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } });
|
|
30
21
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,6CAA8C;AAArC,4GAAA,aAAa,OAAA;AACtB,6DAAyD;AAAhD,iHAAA,aAAa,OAAA;AACtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,yDAAuD;AAA9C,+GAAA,aAAa,OAAA","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { buildResponse } from './utils/response-builder';\nexport { Identify } from './identify';\nexport { Revenue } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { Config } from './config';\nexport { Logger } from './logger';\nexport { AMPLITUDE_PREFIX } from './constants';\nexport { returnWrapper } from './utils/return-wrapper';\n"]}
|
package/lib/cjs/messages.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export declare const SUCCESS_MESSAGE = "Event tracked successfully";
|
|
|
2
2
|
export declare const UNEXPECTED_ERROR_MESSAGE = "Unexpected error occurred";
|
|
3
3
|
export declare const MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to exceeded retry count";
|
|
4
4
|
export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config";
|
|
5
|
-
export declare const MISSING_API_KEY_MESSAGE = "Event
|
|
5
|
+
export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
|
|
6
6
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC"}
|
package/lib/cjs/messages.js
CHANGED
|
@@ -4,5 +4,5 @@ exports.SUCCESS_MESSAGE = 'Event tracked successfully';
|
|
|
4
4
|
exports.UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';
|
|
5
5
|
exports.MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';
|
|
6
6
|
exports.OPT_OUT_MESSAGE = 'Event skipped due to optOut config';
|
|
7
|
-
exports.MISSING_API_KEY_MESSAGE = 'Event
|
|
7
|
+
exports.MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';
|
|
8
8
|
//# sourceMappingURL=messages.js.map
|
package/lib/cjs/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,uCAAuC,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\n"]}
|