@amplitude/analytics-core 2.1.1 → 2.2.0-featadddiagnostics.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/README.md +1 -1
- package/lib/cjs/config.d.ts +4 -1
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +7 -1
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/diagnostics/constants.d.ts +12 -0
- package/lib/cjs/diagnostics/constants.d.ts.map +1 -0
- package/lib/cjs/diagnostics/constants.js +14 -0
- package/lib/cjs/diagnostics/constants.js.map +1 -0
- package/lib/cjs/diagnostics/diagnostic.d.ts +16 -0
- package/lib/cjs/diagnostics/diagnostic.d.ts.map +1 -0
- package/lib/cjs/diagnostics/diagnostic.js +72 -0
- package/lib/cjs/diagnostics/diagnostic.js.map +1 -0
- package/lib/cjs/diagnostics/typings.d.ts +14 -0
- package/lib/cjs/diagnostics/typings.d.ts.map +1 -0
- package/lib/cjs/diagnostics/typings.js +2 -0
- package/lib/cjs/diagnostics/typings.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +12 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts +1 -0
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +43 -0
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/esm/config.d.ts +4 -1
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +7 -1
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/diagnostics/constants.d.ts +12 -0
- package/lib/esm/diagnostics/constants.d.ts.map +1 -0
- package/lib/esm/diagnostics/constants.js +12 -0
- package/lib/esm/diagnostics/constants.js.map +1 -0
- package/lib/esm/diagnostics/diagnostic.d.ts +16 -0
- package/lib/esm/diagnostics/diagnostic.d.ts.map +1 -0
- package/lib/esm/diagnostics/diagnostic.js +70 -0
- package/lib/esm/diagnostics/diagnostic.js.map +1 -0
- package/lib/esm/diagnostics/typings.d.ts +14 -0
- package/lib/esm/diagnostics/typings.d.ts.map +1 -0
- package/lib/esm/diagnostics/typings.js +2 -0
- package/lib/esm/diagnostics/typings.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts +1 -0
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +43 -0
- package/lib/esm/plugins/destination.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
package/lib/cjs/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
|
|
1
|
+
import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
import { BaseDiagnostic } from './diagnostics/diagnostic';
|
|
3
4
|
export declare const getDefaultConfig: () => {
|
|
4
5
|
flushMaxRetries: number;
|
|
5
6
|
flushQueueSize: number;
|
|
@@ -11,6 +12,7 @@ export declare const getDefaultConfig: () => {
|
|
|
11
12
|
serverUrl: string;
|
|
12
13
|
serverZone: ServerZoneType;
|
|
13
14
|
useBatch: boolean;
|
|
15
|
+
diagnosticProvider: BaseDiagnostic;
|
|
14
16
|
};
|
|
15
17
|
export declare class Config implements IConfig {
|
|
16
18
|
apiKey: string;
|
|
@@ -28,6 +30,7 @@ export declare class Config implements IConfig {
|
|
|
28
30
|
transportProvider: Transport;
|
|
29
31
|
storageProvider?: Storage<Event[]>;
|
|
30
32
|
useBatch: boolean;
|
|
33
|
+
diagnosticProvider: Diagnostic;
|
|
31
34
|
protected _optOut: boolean;
|
|
32
35
|
get optOut(): boolean;
|
|
33
36
|
set optOut(optOut: boolean);
|
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,QAAQ,EACR,OAAO,EACP,SAAS,EACT,IAAI,EACJ,iBAAiB,EACjB,OAAO,EACP,cAAc,EACf,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,UAAU,EACV,MAAM,IAAI,OAAO,EACjB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,IAAI,EACJ,iBAAiB,EACjB,OAAO,EACP,cAAc,EACf,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAY3B,CAAC;AAEH,qBAAa,MAAO,YAAW,OAAO;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,UAAU,CAAC;IAE/B,SAAS,CAAC,OAAO,UAAS;IAC1B,IAAI,MAAM,IAGS,OAAO,CADzB;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAEzB;gBAEW,OAAO,EAAE,OAAO;CA8B7B;AAED,eAAO,MAAM,YAAY,eAAgB,cAAc,YAAY,OAAO,kKAKzE,CAAC;AAEF,eAAO,MAAM,kBAAkB,oCAEjB,cAAc,aAChB,OAAO;;;;;;CAUlB,CAAC"}
|
package/lib/cjs/config.js
CHANGED
|
@@ -3,6 +3,7 @@ exports.createServerConfig = exports.getServerUrl = exports.Config = exports.get
|
|
|
3
3
|
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
4
4
|
var constants_1 = require("./constants");
|
|
5
5
|
var logger_1 = require("./logger");
|
|
6
|
+
var diagnostic_1 = require("./diagnostics/diagnostic");
|
|
6
7
|
var getDefaultConfig = function () { return ({
|
|
7
8
|
flushMaxRetries: 12,
|
|
8
9
|
flushQueueSize: 200,
|
|
@@ -14,11 +15,12 @@ var getDefaultConfig = function () { return ({
|
|
|
14
15
|
serverUrl: constants_1.AMPLITUDE_SERVER_URL,
|
|
15
16
|
serverZone: 'US',
|
|
16
17
|
useBatch: false,
|
|
18
|
+
diagnosticProvider: new diagnostic_1.BaseDiagnostic(),
|
|
17
19
|
}); };
|
|
18
20
|
exports.getDefaultConfig = getDefaultConfig;
|
|
19
21
|
var Config = /** @class */ (function () {
|
|
20
22
|
function Config(options) {
|
|
21
|
-
var _a, _b, _c, _d;
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
22
24
|
this._optOut = false;
|
|
23
25
|
var defaultConfig = (0, exports.getDefaultConfig)();
|
|
24
26
|
this.apiKey = options.apiKey;
|
|
@@ -37,6 +39,10 @@ var Config = /** @class */ (function () {
|
|
|
37
39
|
this.storageProvider = options.storageProvider;
|
|
38
40
|
this.transportProvider = options.transportProvider;
|
|
39
41
|
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch;
|
|
42
|
+
this.diagnosticProvider = (_e = options.diagnosticProvider) !== null && _e !== void 0 ? _e : defaultConfig.diagnosticProvider;
|
|
43
|
+
if (!this.diagnosticProvider.apiKey) {
|
|
44
|
+
this.diagnosticProvider.apiKey = this.apiKey;
|
|
45
|
+
}
|
|
40
46
|
this.loggerProvider.enable(this.logLevel);
|
|
41
47
|
var serverConfig = (0, exports.createServerConfig)(options.serverUrl, options.serverZone, options.useBatch);
|
|
42
48
|
this.serverZone = serverConfig.serverZone;
|
package/lib/cjs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAAA,8DAYoC;AACpC,yCAKqB;AAErB,mCAAkC;AAClC,uDAA0D;AAEnD,IAAM,gBAAgB,GAAG,cAAM,OAAA,CAAC;IACrC,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,GAAG;IACnB,mBAAmB,EAAE,KAAK;IAC1B,YAAY,EAAE,mBAAmB;IACjC,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,cAAc,EAAE,IAAI,eAAM,EAAE;IAC5B,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,gCAAoB;IAC/B,UAAU,EAAE,IAAsB;IAClC,QAAQ,EAAE,KAAK;IACf,kBAAkB,EAAE,IAAI,2BAAc,EAAE;CACzC,CAAC,EAZoC,CAYpC,CAAC;AAZU,QAAA,gBAAgB,oBAY1B;AAEH;IA0BE,gB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AA,wBAAgB,GAAE,CAAC,QAAQ;IAE/C,IAAI,SAAS,EAAE;QACb,OAAO,EAAE,SAAS,WAAA,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KAC7C;IACD,IAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,wBAAgB,GAAE,CAAC,UAAU,CAAC;IACnG,OAAO;QACL,UAAU,EAAE,WAAW;QACvB,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,EAAE,QAAQ,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,kBAAkB,sBAa7B","sourcesContent":["import {\n Event,\n Config as IConfig,\n Diagnostic,\n Logger as ILogger,\n LogLevel,\n Storage,\n Transport,\n Plan,\n IngestionMetadata,\n Options,\n ServerZoneType,\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';\nimport { BaseDiagnostic } from './diagnostics/diagnostic';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 12,\n flushQueueSize: 200,\n flushIntervalMillis: 10000,\n instanceName: '$default_instance',\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n optOut: false,\n serverUrl: AMPLITUDE_SERVER_URL,\n serverZone: 'US' as ServerZoneType,\n useBatch: false,\n diagnosticProvider: new BaseDiagnostic(),\n});\n\nexport class Config implements IConfig {\n apiKey: string;\n flushIntervalMillis: number;\n flushMaxRetries: number;\n flushQueueSize: number;\n instanceName?: string;\n loggerProvider: ILogger;\n logLevel: LogLevel;\n minIdLength?: number;\n plan?: Plan;\n ingestionMetadata?: IngestionMetadata;\n serverUrl: string | undefined;\n serverZone?: ServerZoneType;\n transportProvider: Transport;\n storageProvider?: Storage<Event[]>;\n useBatch: boolean;\n diagnosticProvider: Diagnostic;\n\n protected _optOut = false;\n get optOut() {\n return this._optOut;\n }\n set optOut(optOut: boolean) {\n this._optOut = optOut;\n }\n\n constructor(options: Options) {\n const defaultConfig = getDefaultConfig();\n this.apiKey = options.apiKey;\n this.flushIntervalMillis = options.flushIntervalMillis ?? defaultConfig.flushIntervalMillis;\n this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;\n this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;\n this.instanceName = options.instanceName || defaultConfig.instanceName;\n this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;\n this.logLevel = options.logLevel ?? defaultConfig.logLevel;\n this.minIdLength = options.minIdLength;\n this.plan = options.plan;\n this.ingestionMetadata = options.ingestionMetadata;\n this.optOut = options.optOut ?? defaultConfig.optOut;\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\n this.diagnosticProvider = options.diagnosticProvider ?? defaultConfig.diagnosticProvider;\n if (!this.diagnosticProvider.apiKey) {\n this.diagnosticProvider.apiKey = this.apiKey;\n }\n\n this.loggerProvider.enable(this.logLevel);\n\n const serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch);\n this.serverZone = serverConfig.serverZone;\n this.serverUrl = serverConfig.serverUrl;\n }\n}\n\nexport const getServerUrl = (serverZone: ServerZoneType, useBatch: boolean) => {\n if (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 serverUrl = '',\n serverZone: ServerZoneType = getDefaultConfig().serverZone,\n useBatch: boolean = getDefaultConfig().useBatch,\n) => {\n if (serverUrl) {\n return { serverUrl, serverZone: undefined };\n }\n const _serverZone = ['US', 'EU'].includes(serverZone) ? serverZone : getDefaultConfig().serverZone;\n return {\n serverZone: _serverZone,\n serverUrl: getServerUrl(_serverZone, useBatch),\n };\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DIAGNOSTIC_METADATA_TYPE = "SDK_DIAGNOSTIC";
|
|
2
|
+
export declare const DIAGNOSTIC_ENDPOINT = "https://api-omni.stag2.amplitude.com/omni/metrics";
|
|
3
|
+
export declare const DIAGNOSTIC_MESSAGES: {
|
|
4
|
+
EXCEEDED_MAX_RETRY: string;
|
|
5
|
+
MISSING_API_KEY: string;
|
|
6
|
+
UNEXPECTED_ERROR: string;
|
|
7
|
+
INVALID_OR_MISSING_FIELDS: string;
|
|
8
|
+
EVENT_ERROR: string;
|
|
9
|
+
PAYLOAD_TOO_LARGE: string;
|
|
10
|
+
EXCEEDED_DAILY_QUOTA: string;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,mBAAmB,CAAC;AACzD,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AAEvF,eAAO,MAAM,mBAAmB;;;;;;;;CAQ/B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.DIAGNOSTIC_MESSAGES = exports.DIAGNOSTIC_ENDPOINT = exports.DIAGNOSTIC_METADATA_TYPE = void 0;
|
|
3
|
+
exports.DIAGNOSTIC_METADATA_TYPE = 'SDK_DIAGNOSTIC';
|
|
4
|
+
exports.DIAGNOSTIC_ENDPOINT = 'https://api-omni.stag2.amplitude.com/omni/metrics';
|
|
5
|
+
exports.DIAGNOSTIC_MESSAGES = {
|
|
6
|
+
EXCEEDED_MAX_RETRY: 'exceeded max retries',
|
|
7
|
+
MISSING_API_KEY: 'missing API key',
|
|
8
|
+
UNEXPECTED_ERROR: 'unexpected error',
|
|
9
|
+
INVALID_OR_MISSING_FIELDS: 'invalid or missing fields',
|
|
10
|
+
EVENT_ERROR: 'event error',
|
|
11
|
+
PAYLOAD_TOO_LARGE: 'payload too large',
|
|
12
|
+
EXCEEDED_DAILY_QUOTA: 'exceeded daily quota users or devices',
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/diagnostics/constants.ts"],"names":[],"mappings":";;AAAa,QAAA,wBAAwB,GAAG,gBAAgB,CAAC;AAC5C,QAAA,mBAAmB,GAAG,mDAAmD,CAAC;AAE1E,QAAA,mBAAmB,GAAG;IACjC,kBAAkB,EAAE,sBAAsB;IAC1C,eAAe,EAAE,iBAAiB;IAClC,gBAAgB,EAAE,kBAAkB;IACpC,yBAAyB,EAAE,2BAA2B;IACtD,WAAW,EAAE,aAAa;IAC1B,iBAAiB,EAAE,mBAAmB;IACtC,oBAAoB,EAAE,uCAAuC;CAC9D,CAAC","sourcesContent":["export const DIAGNOSTIC_METADATA_TYPE = 'SDK_DIAGNOSTIC';\nexport const DIAGNOSTIC_ENDPOINT = 'https://api-omni.stag2.amplitude.com/omni/metrics';\n\nexport const DIAGNOSTIC_MESSAGES = {\n EXCEEDED_MAX_RETRY: 'exceeded max retries',\n MISSING_API_KEY: 'missing API key',\n UNEXPECTED_ERROR: 'unexpected error',\n INVALID_OR_MISSING_FIELDS: 'invalid or missing fields',\n EVENT_ERROR: 'event error',\n PAYLOAD_TOO_LARGE: 'payload too large',\n EXCEEDED_DAILY_QUOTA: 'exceeded daily quota users or devices',\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOptions } from '@amplitude/analytics-types';
|
|
2
|
+
import { DiagnosticOmniMetrics } from './typings';
|
|
3
|
+
export declare class BaseDiagnostic implements Diagnostic {
|
|
4
|
+
isDisabled: boolean;
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
queue: DiagnosticOmniMetrics[];
|
|
8
|
+
private scheduled;
|
|
9
|
+
private delay;
|
|
10
|
+
constructor(options?: DiagnosticOptions);
|
|
11
|
+
track(eventCount: number, code: number, message: string): void;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
diagnosticRequestBuilder(eventCount: number, code: number, message: string): DiagnosticOmniMetrics;
|
|
14
|
+
requestPayloadBuilder(events: DiagnosticOmniMetrics[]): object;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=diagnostic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAGlD,qBAAa,cAAe,YAAW,UAAU;IAC/C,UAAU,UAAQ;IAClB,SAAS,EAAE,MAAM,CAAuB;IACxC,MAAM,SAAM;IACZ,KAAK,EAAE,qBAAqB,EAAE,CAAM;IAEpC,OAAO,CAAC,SAAS,CAA8C;IAG/D,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,CAAC,EAAE,iBAAiB;IAMvC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAcjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAYlG,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM;CAY/D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.BaseDiagnostic = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var constants_1 = require("../diagnostics/constants");
|
|
5
|
+
var constants_2 = require("./constants");
|
|
6
|
+
var BaseDiagnostic = /** @class */ (function () {
|
|
7
|
+
function BaseDiagnostic(options) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
this.isDisabled = true;
|
|
10
|
+
this.serverUrl = constants_1.DIAGNOSTIC_ENDPOINT;
|
|
11
|
+
this.apiKey = '';
|
|
12
|
+
this.queue = [];
|
|
13
|
+
this.scheduled = null;
|
|
14
|
+
// deault delay is 1 minute
|
|
15
|
+
// make it private to prevent users from changing it to smaller value
|
|
16
|
+
this.delay = 60000;
|
|
17
|
+
this.isDisabled = (_a = options === null || options === void 0 ? void 0 : options.isDisabled) !== null && _a !== void 0 ? _a : true;
|
|
18
|
+
this.serverUrl = (_b = options === null || options === void 0 ? void 0 : options.serverUrl) !== null && _b !== void 0 ? _b : constants_1.DIAGNOSTIC_ENDPOINT;
|
|
19
|
+
this.apiKey = (_c = options === null || options === void 0 ? void 0 : options.apiKey) !== null && _c !== void 0 ? _c : '';
|
|
20
|
+
}
|
|
21
|
+
BaseDiagnostic.prototype.track = function (eventCount, code, message) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
if (this.isDisabled) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.queue.push(this.diagnosticRequestBuilder(eventCount, code, message));
|
|
27
|
+
if (!this.scheduled) {
|
|
28
|
+
this.scheduled = setTimeout(function () {
|
|
29
|
+
void _this.flush();
|
|
30
|
+
}, this.delay);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
BaseDiagnostic.prototype.flush = function () {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
35
|
+
return tslib_1.__generator(this, function (_a) {
|
|
36
|
+
// send http request based on environment
|
|
37
|
+
// implemented in its child class
|
|
38
|
+
if (this.scheduled) {
|
|
39
|
+
clearTimeout(this.scheduled);
|
|
40
|
+
this.scheduled = null;
|
|
41
|
+
}
|
|
42
|
+
return [2 /*return*/];
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
BaseDiagnostic.prototype.diagnosticRequestBuilder = function (eventCount, code, message) {
|
|
47
|
+
return {
|
|
48
|
+
metadata_type: constants_2.DIAGNOSTIC_METADATA_TYPE,
|
|
49
|
+
library: 'amplitude-ts',
|
|
50
|
+
accounting_time_min: Math.floor(Date.now() / 60 / 1000),
|
|
51
|
+
response_code: code,
|
|
52
|
+
trigger: message,
|
|
53
|
+
action: 'drop events',
|
|
54
|
+
event_count: eventCount,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
BaseDiagnostic.prototype.requestPayloadBuilder = function (events) {
|
|
58
|
+
return {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
api_key: this.apiKey || '',
|
|
65
|
+
omni_metrics: events,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
return BaseDiagnostic;
|
|
70
|
+
}());
|
|
71
|
+
exports.BaseDiagnostic = BaseDiagnostic;
|
|
72
|
+
//# sourceMappingURL=diagnostic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../../../src/diagnostics/diagnostic.ts"],"names":[],"mappings":";;;AACA,sDAA+D;AAE/D,yCAAuD;AAEvD;IAWE,wBAAY,OAA2B;;QAVvC,eAAU,GAAG,IAAI,CAAC;QAClB,cAAS,GAAW,+BAAmB,CAAC;QACxC,WAAM,GAAG,EAAE,CAAC;QACZ,UAAK,GAA4B,EAAE,CA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E,GAAG,EAAE,GAAG,IAAI,CAAC;YACvD,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,aAAa;YACrB,WAAW,EAAE,UAAU;SACxB,CAAC;IACJ,CAAC;IAED,8CAAqB,GAArB,UAAsB,MAA+B;QACnD,OAAO;YACL,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;gBAC1B,YAAY,EAAE,MAAM;aACrB,CAAC;SACH,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AAjED,IAiEC;AAjEY,wCAAc","sourcesContent":["import { Diagnostic, DiagnosticOptions } from '@amplitude/analytics-types';\nimport { DIAGNOSTIC_ENDPOINT } from '../diagnostics/constants';\nimport { DiagnosticOmniMetrics } from './typings';\nimport { DIAGNOSTIC_METADATA_TYPE } from './constants';\n\nexport class BaseDiagnostic implements Diagnostic {\n isDisabled = true;\n serverUrl: string = DIAGNOSTIC_ENDPOINT;\n apiKey = '';\n queue: DiagnosticOmniMetrics[] = [];\n\n private scheduled: ReturnType<typeof setTimeout> | null = null;\n // deault delay is 1 minute\n // make it private to prevent users from changing it to smaller value\n private delay = 60000;\n\n constructor(options?: DiagnosticOptions) {\n this.isDisabled = options?.isDisabled ?? true;\n this.serverUrl = options?.serverUrl ?? DIAGNOSTIC_ENDPOINT;\n this.apiKey = options?.apiKey ?? '';\n }\n\n track(eventCount: number, code: number, message: string) {\n if (this.isDisabled) {\n return;\n }\n\n this.queue.push(this.diagnosticRequestBuilder(eventCount, code, message));\n\n if (!this.scheduled) {\n this.scheduled = setTimeout(() => {\n void this.flush();\n }, this.delay);\n }\n }\n\n async flush(): Promise<void> {\n // send http request based on environment\n // implemented in its child class\n\n if (this.scheduled) {\n clearTimeout(this.scheduled);\n this.scheduled = null;\n }\n }\n\n diagnosticRequestBuilder(eventCount: number, code: number, message: string): DiagnosticOmniMetrics {\n return {\n metadata_type: DIAGNOSTIC_METADATA_TYPE,\n library: 'amplitude-ts',\n accounting_time_min: Math.floor(Date.now() / 60 / 1000),\n response_code: code,\n trigger: message,\n action: 'drop events',\n event_count: eventCount,\n };\n }\n\n requestPayloadBuilder(events: DiagnosticOmniMetrics[]): object {\n return {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n api_key: this.apiKey || '',\n omni_metrics: events,\n }),\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DiagnosticOmniMetrics {
|
|
2
|
+
metadata_type: string;
|
|
3
|
+
library: string;
|
|
4
|
+
accounting_time_min: number;
|
|
5
|
+
response_code: number;
|
|
6
|
+
trigger: string;
|
|
7
|
+
action: string;
|
|
8
|
+
event_count: number;
|
|
9
|
+
}
|
|
10
|
+
export interface DiagnosticRequest {
|
|
11
|
+
api_key: string;
|
|
12
|
+
omni_metrics: DiagnosticOmniMetrics;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=typings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typings.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/typings.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,qBAAqB,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typings.js","sourceRoot":"","sources":["../../../src/diagnostics/typings.ts"],"names":[],"mappings":"","sourcesContent":["export interface DiagnosticOmniMetrics {\n metadata_type: string;\n library: string;\n accounting_time_min: number;\n response_code: number;\n trigger: string;\n action: string;\n event_count: number;\n}\n\nexport interface DiagnosticRequest {\n api_key: string;\n omni_metrics: DiagnosticOmniMetrics;\n}\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { AmplitudeCore } from './core-client';
|
|
|
2
2
|
export { Identify } from './identify';
|
|
3
3
|
export { Revenue } from './revenue';
|
|
4
4
|
export { Destination } from './plugins/destination';
|
|
5
|
+
export { BaseDiagnostic } from './diagnostics/diagnostic';
|
|
6
|
+
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants';
|
|
5
7
|
export { Config } from './config';
|
|
6
8
|
export { Logger } from './logger';
|
|
7
9
|
export { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './constants';
|
|
@@ -11,4 +13,5 @@ export { UUID } from './utils/uuid';
|
|
|
11
13
|
export { MemoryStorage } from './storage/memory';
|
|
12
14
|
export { BaseTransport } from './transports/base';
|
|
13
15
|
export { createIdentifyEvent } from './utils/event-builder';
|
|
16
|
+
export { buildResult } from './utils/result-builder';
|
|
14
17
|
//# 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,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,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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EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
|
|
2
|
+
exports.buildResult = exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.DIAGNOSTIC_ENDPOINT = exports.DIAGNOSTIC_METADATA_TYPE = exports.DIAGNOSTIC_MESSAGES = exports.BaseDiagnostic = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
|
|
3
3
|
var core_client_1 = require("./core-client");
|
|
4
4
|
Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } });
|
|
5
5
|
var identify_1 = require("./identify");
|
|
@@ -8,13 +8,19 @@ var revenue_1 = require("./revenue");
|
|
|
8
8
|
Object.defineProperty(exports, "Revenue", { enumerable: true, get: function () { return revenue_1.Revenue; } });
|
|
9
9
|
var destination_1 = require("./plugins/destination");
|
|
10
10
|
Object.defineProperty(exports, "Destination", { enumerable: true, get: function () { return destination_1.Destination; } });
|
|
11
|
+
var diagnostic_1 = require("./diagnostics/diagnostic");
|
|
12
|
+
Object.defineProperty(exports, "BaseDiagnostic", { enumerable: true, get: function () { return diagnostic_1.BaseDiagnostic; } });
|
|
13
|
+
var constants_1 = require("./diagnostics/constants");
|
|
14
|
+
Object.defineProperty(exports, "DIAGNOSTIC_MESSAGES", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_MESSAGES; } });
|
|
15
|
+
Object.defineProperty(exports, "DIAGNOSTIC_METADATA_TYPE", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_METADATA_TYPE; } });
|
|
16
|
+
Object.defineProperty(exports, "DIAGNOSTIC_ENDPOINT", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_ENDPOINT; } });
|
|
11
17
|
var config_1 = require("./config");
|
|
12
18
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
13
19
|
var logger_1 = require("./logger");
|
|
14
20
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
15
|
-
var
|
|
16
|
-
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return
|
|
17
|
-
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return
|
|
21
|
+
var constants_2 = require("./constants");
|
|
22
|
+
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_2.AMPLITUDE_PREFIX; } });
|
|
23
|
+
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return constants_2.STORAGE_PREFIX; } });
|
|
18
24
|
var return_wrapper_1 = require("./utils/return-wrapper");
|
|
19
25
|
Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } });
|
|
20
26
|
var debug_1 = require("./utils/debug");
|
|
@@ -29,4 +35,6 @@ var base_1 = require("./transports/base");
|
|
|
29
35
|
Object.defineProperty(exports, "BaseTransport", { enumerable: true, get: function () { return base_1.BaseTransport; } });
|
|
30
36
|
var event_builder_1 = require("./utils/event-builder");
|
|
31
37
|
Object.defineProperty(exports, "createIdentifyEvent", { enumerable: true, get: function () { return event_builder_1.createIdentifyEvent; } });
|
|
38
|
+
var result_builder_1 = require("./utils/result-builder");
|
|
39
|
+
Object.defineProperty(exports, "buildResult", { enumerable: true, get: function () { return result_builder_1.buildResult; } });
|
|
32
40
|
//# 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,6CAA8C;AAArC,4GAAA,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+D;AAAtD,6GAAA,gBAAgB,OAAA;AAAE,2GAAA,cAAc,OAAA;AACzC,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,uCAAkF;AAAzE,qGAAA,YAAY,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAC1D,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AACb,2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,0CAAkD;AAAzC,qGAAA,aAAa,OAAA;AACtB,uDAA4D;AAAnD,oHAAA,mBAAmB,OAAA","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { Identify } from './identify';\nexport { Revenue } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { Config } from './config';\nexport { Logger } from './logger';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './constants';\nexport { returnWrapper } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { MemoryStorage } from './storage/memory';\nexport { BaseTransport } from './transports/base';\nexport { createIdentifyEvent } from './utils/event-builder';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,6CAA8C;AAArC,4GAAA,aAAa,OAAA;AACtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,uDAA0D;AAAjD,4GAAA,cAAc,OAAA;AACvB,qDAA6G;AAApG,gHAAA,mBAAmB,OAAA;AAAE,qHAAA,wBAAwB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAC3E,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,yCAA+D;AAAtD,6GAAA,gBAAgB,OAAA;AAAE,2GAAA,cAAc,OAAA;AACzC,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,uCAAkF;AAAzE,qGAAA,YAAY,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAC1D,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AACb,2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,0CAAkD;AAAzC,qGAAA,aAAa,OAAA;AACtB,uDAA4D;AAAnD,oHAAA,mBAAmB,OAAA;AAC5B,yDAAqD;AAA5C,6GAAA,WAAW,OAAA","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { Identify } from './identify';\nexport { Revenue } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { BaseDiagnostic } from './diagnostics/diagnostic';\nexport { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants';\nexport { Config } from './config';\nexport { Logger } from './logger';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './constants';\nexport { returnWrapper } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { MemoryStorage } from './storage/memory';\nexport { BaseTransport } from './transports/base';\nexport { createIdentifyEvent } from './utils/event-builder';\nexport { buildResult } from './utils/result-builder';\n"]}
|
|
@@ -15,6 +15,7 @@ export declare class Destination implements DestinationPlugin {
|
|
|
15
15
|
schedule(timeout: number): void;
|
|
16
16
|
flush(useRetry?: boolean): Promise<void>;
|
|
17
17
|
send(list: Context[], useRetry?: boolean): Promise<void>;
|
|
18
|
+
processResponseDiagnostics(res: Response, list: Context[]): void;
|
|
18
19
|
handleResponse(res: Response, list: Context[]): void;
|
|
19
20
|
handleSuccessResponse(res: SuccessResponse, list: Context[]): void;
|
|
20
21
|
handleInvalidResponse(res: InvalidResponse, list: Context[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAmBpC,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,UAUlD;AAED,qBAAa,WAAY,YAAW,iBAAiB;IACnD,IAAI,SAAe;IACnB,IAAI,gBAA0B;IAE9B,YAAY,SAAQ;IACpB,eAAe,SAAS;IACxB,UAAU,SAAM;IAIhB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,SAAS,CAA8C;IAC/D,KAAK,EAAE,OAAO,EAAE,CAAM;IAEhB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAa/C,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAYtC,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IA2B7B,QAAQ,CAAC,OAAO,EAAE,MAAM;IAWlB,KAAK,CAAC,QAAQ,UAAQ;IAetB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,UAAO;IA4C3C,0BAA0B,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;IA2BzD,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;IA8B7C,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAI3D,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAoC3D,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE;IAc3E,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE;IAoC/D,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE;IASnC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK7D;;;;;OAKG;IACH,UAAU;CAOX"}
|
|
@@ -7,6 +7,7 @@ var constants_1 = require("../constants");
|
|
|
7
7
|
var chunk_1 = require("../utils/chunk");
|
|
8
8
|
var result_builder_1 = require("../utils/result-builder");
|
|
9
9
|
var config_1 = require("../config");
|
|
10
|
+
var constants_2 = require("../diagnostics/constants");
|
|
10
11
|
function getErrorMessage(error) {
|
|
11
12
|
if (error instanceof Error)
|
|
12
13
|
return error.message;
|
|
@@ -81,6 +82,7 @@ var Destination = /** @class */ (function () {
|
|
|
81
82
|
return true;
|
|
82
83
|
}
|
|
83
84
|
void _this.fulfillRequest([context], 500, messages_1.MAX_RETRIES_EXCEEDED_MESSAGE);
|
|
85
|
+
_this.config.diagnosticProvider.track(list.length, 500, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY);
|
|
84
86
|
return false;
|
|
85
87
|
});
|
|
86
88
|
tryable.forEach(function (context) {
|
|
@@ -163,6 +165,7 @@ var Destination = /** @class */ (function () {
|
|
|
163
165
|
case 2:
|
|
164
166
|
res = _a.sent();
|
|
165
167
|
if (res === null) {
|
|
168
|
+
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
|
|
166
169
|
this.fulfillRequest(list, 0, messages_1.UNEXPECTED_ERROR_MESSAGE);
|
|
167
170
|
return [2 /*return*/];
|
|
168
171
|
}
|
|
@@ -173,6 +176,7 @@ var Destination = /** @class */ (function () {
|
|
|
173
176
|
else {
|
|
174
177
|
this.fulfillRequest(list, res.statusCode, res.status);
|
|
175
178
|
}
|
|
179
|
+
this.processResponseDiagnostics(res, list);
|
|
176
180
|
return [2 /*return*/];
|
|
177
181
|
}
|
|
178
182
|
this.handleResponse(res, list);
|
|
@@ -182,12 +186,39 @@ var Destination = /** @class */ (function () {
|
|
|
182
186
|
errorMessage = getErrorMessage(e_1);
|
|
183
187
|
this.config.loggerProvider.error(errorMessage);
|
|
184
188
|
this.fulfillRequest(list, 0, errorMessage);
|
|
189
|
+
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
|
|
185
190
|
return [3 /*break*/, 4];
|
|
186
191
|
case 4: return [2 /*return*/];
|
|
187
192
|
}
|
|
188
193
|
});
|
|
189
194
|
});
|
|
190
195
|
};
|
|
196
|
+
Destination.prototype.processResponseDiagnostics = function (res, list) {
|
|
197
|
+
var status = res.status;
|
|
198
|
+
switch (status) {
|
|
199
|
+
case analytics_types_1.Status.Invalid: {
|
|
200
|
+
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) {
|
|
201
|
+
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR);
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case analytics_types_1.Status.PayloadTooLarge: {
|
|
209
|
+
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case analytics_types_1.Status.RateLimit: {
|
|
213
|
+
this.config.diagnosticProvider.track(list.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
default: {
|
|
217
|
+
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
191
222
|
Destination.prototype.handleResponse = function (res, list) {
|
|
192
223
|
var status = res.status;
|
|
193
224
|
switch (status) {
|
|
@@ -220,12 +251,18 @@ var Destination = /** @class */ (function () {
|
|
|
220
251
|
};
|
|
221
252
|
Destination.prototype.handleInvalidResponse = function (res, list) {
|
|
222
253
|
var _this = this;
|
|
254
|
+
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) {
|
|
255
|
+
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);
|
|
256
|
+
}
|
|
223
257
|
if (res.body.missingField || res.body.error.startsWith(messages_1.INVALID_API_KEY)) {
|
|
224
258
|
this.fulfillRequest(list, res.statusCode, res.body.error);
|
|
225
259
|
return;
|
|
226
260
|
}
|
|
227
261
|
var dropIndex = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(Object.values(res.body.eventsWithInvalidFields)), false), tslib_1.__read(Object.values(res.body.eventsWithMissingFields)), false), tslib_1.__read(Object.values(res.body.eventsWithInvalidIdLengths)), false), tslib_1.__read(res.body.silencedEvents), false).flat();
|
|
228
262
|
var dropIndexSet = new Set(dropIndex);
|
|
263
|
+
if (dropIndexSet.size) {
|
|
264
|
+
this.config.diagnosticProvider.track(dropIndexSet.size, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR);
|
|
265
|
+
}
|
|
229
266
|
var retry = list.filter(function (context, index) {
|
|
230
267
|
if (dropIndexSet.has(index)) {
|
|
231
268
|
_this.fulfillRequest([context], res.statusCode, res.body.error);
|
|
@@ -241,6 +278,7 @@ var Destination = /** @class */ (function () {
|
|
|
241
278
|
};
|
|
242
279
|
Destination.prototype.handlePayloadTooLargeResponse = function (res, list) {
|
|
243
280
|
if (list.length === 1) {
|
|
281
|
+
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);
|
|
244
282
|
this.fulfillRequest(list, res.statusCode, res.body.error);
|
|
245
283
|
return;
|
|
246
284
|
}
|
|
@@ -257,10 +295,12 @@ var Destination = /** @class */ (function () {
|
|
|
257
295
|
var dropUserIdsSet = new Set(dropUserIds);
|
|
258
296
|
var dropDeviceIdsSet = new Set(dropDeviceIds);
|
|
259
297
|
var throttledIndexSet = new Set(throttledIndex);
|
|
298
|
+
var dropList = [];
|
|
260
299
|
var retry = list.filter(function (context, index) {
|
|
261
300
|
if ((context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||
|
|
262
301
|
(context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))) {
|
|
263
302
|
_this.fulfillRequest([context], res.statusCode, res.body.error);
|
|
303
|
+
dropList.push(context);
|
|
264
304
|
return;
|
|
265
305
|
}
|
|
266
306
|
if (throttledIndexSet.has(index)) {
|
|
@@ -268,6 +308,9 @@ var Destination = /** @class */ (function () {
|
|
|
268
308
|
}
|
|
269
309
|
return true;
|
|
270
310
|
});
|
|
311
|
+
if (dropList.length > 0) {
|
|
312
|
+
this.config.diagnosticProvider.track(dropList.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);
|
|
313
|
+
}
|
|
271
314
|
if (retry.length > 0) {
|
|
272
315
|
// log intermediate event status before retry
|
|
273
316
|
this.config.loggerProvider.warn(getResponseBodyString(res));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAYoC;AACpC,wCAMqB;AACrB,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAgB,qBAAqB,CAAC,GAAa;IACjD,IAAI,kBAAkB,GAAG,EAAE,CAAC;IAC5B,IAAI;QACF,IAAI,MAAM,IAAI,GAAG,EAAE;YACjB,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;SACxD;KACF;IAAC,WAAM;QACN,8FAA8F;KAC/F;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAVD,sDAUC;AAED;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,aAAsB,CAAC;QAE9B,iBAAY,GAAG,IAAI,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACx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Aa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAzQD,IAyQC;AAzQY,kCAAW","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nfunction getErrorMessage(error: unknown) {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nexport function getResponseBodyString(res: Response) {\n let responseBodyString = '';\n try {\n if ('body' in res) {\n responseBodyString = JSON.stringify(res.body, null, 2);\n }\n } catch {\n // to avoid crash, but don't care about the error, add comment to avoid empty block lint error\n }\n return responseBodyString;\n}\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = 'destination' as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n private scheduled: ReturnType<typeof setTimeout> | null = null;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = setTimeout(() => {\n void this.flush(true).then(() => {\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n if (this.scheduled) {\n clearTimeout(this.scheduled);\n this.scheduled = null;\n }\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n client_upload_time: new Date().toISOString(),\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n if ('body' in res) {\n this.fulfillRequest(list, res.statusCode, `${res.status}: ${getResponseBodyString(res)}`);\n } else {\n this.fulfillRequest(list, res.statusCode, res.status);\n }\n return;\n }\n this.handleResponse(res, list);\n } catch (e) {\n const errorMessage = getErrorMessage(e);\n this.config.loggerProvider.error(errorMessage);\n this.fulfillRequest(list, 0, errorMessage);\n }\n }\n\n handleResponse(res: Response, list: Context[]) {\n const { status } = res;\n\n switch (status) {\n case Status.Success: {\n this.handleSuccessResponse(res, list);\n break;\n }\n case Status.Invalid: {\n this.handleInvalidResponse(res, list);\n break;\n }\n case Status.PayloadTooLarge: {\n this.handlePayloadTooLargeResponse(res, list);\n break;\n }\n case Status.RateLimit: {\n this.handleRateLimitResponse(res, list);\n break;\n }\n default: {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(`{code: 0, error: \"Status '${status}' provided for ${list.length} events\"}`);\n\n this.handleOtherResponse(list);\n break;\n }\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n if (retry.length > 0) {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n }\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n if (retry.length > 0) {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n }\n\n this.addToQueue(...retry);\n }\n\n handleOtherResponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAYoC;AACpC,wCAMqB;AACrB,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAC/C,sDAA+D;AAE/D,SAA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AAC,WACF;IACJ,CAAC;IAED,oCAAc,GAAd,UAAe,IAAe,EAAE,IAAY,EAAE,OAAe;QAC3D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,IAAA,4BAAW,EAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAtTD,IAsTC;AAtTY,kCAAW","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\nimport { DIAGNOSTIC_MESSAGES } from '../diagnostics/constants';\n\nfunction getErrorMessage(error: unknown) {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nexport function getResponseBodyString(res: Response) {\n let responseBodyString = '';\n try {\n if ('body' in res) {\n responseBodyString = JSON.stringify(res.body, null, 2);\n }\n } catch {\n // to avoid crash, but don't care about the error, add comment to avoid empty block lint error\n }\n return responseBodyString;\n}\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = 'destination' as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n private scheduled: ReturnType<typeof setTimeout> | null = null;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n this.config.diagnosticProvider.track(list.length, 500, DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = setTimeout(() => {\n void this.flush(true).then(() => {\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n if (this.scheduled) {\n clearTimeout(this.scheduled);\n this.scheduled = null;\n }\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n client_upload_time: new Date().toISOString(),\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n if ('body' in res) {\n this.fulfillRequest(list, res.statusCode, `${res.status}: ${getResponseBodyString(res)}`);\n } else {\n this.fulfillRequest(list, res.statusCode, res.status);\n }\n this.processResponseDiagnostics(res, list);\n return;\n }\n this.handleResponse(res, list);\n } catch (e) {\n const errorMessage = getErrorMessage(e);\n this.config.loggerProvider.error(errorMessage);\n this.fulfillRequest(list, 0, errorMessage);\n this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);\n }\n }\n\n processResponseDiagnostics(res: Response, list: Context[]) {\n const { status } = res;\n\n switch (status) {\n case Status.Invalid: {\n if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) {\n this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);\n } else {\n this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR);\n }\n break;\n }\n case Status.PayloadTooLarge: {\n this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);\n break;\n }\n case Status.RateLimit: {\n this.config.diagnosticProvider.track(list.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);\n break;\n }\n default: {\n this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR);\n break;\n }\n }\n }\n\n handleResponse(res: Response, list: Context[]) {\n const { status } = res;\n\n switch (status) {\n case Status.Success: {\n this.handleSuccessResponse(res, list);\n break;\n }\n case Status.Invalid: {\n this.handleInvalidResponse(res, list);\n break;\n }\n case Status.PayloadTooLarge: {\n this.handlePayloadTooLargeResponse(res, list);\n break;\n }\n case Status.RateLimit: {\n this.handleRateLimitResponse(res, list);\n break;\n }\n default: {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(`{code: 0, error: \"Status '${status}' provided for ${list.length} events\"}`);\n\n this.handleOtherResponse(list);\n break;\n }\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) {\n this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS);\n }\n\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n if (dropIndexSet.size) {\n this.config.diagnosticProvider.track(dropIndexSet.size, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR);\n }\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n if (retry.length > 0) {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n }\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE);\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n const dropList = [];\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n dropList.push(context);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n if (dropList.length > 0) {\n this.config.diagnosticProvider.track(dropList.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA);\n }\n\n if (retry.length > 0) {\n // log intermediate event status before retry\n this.config.loggerProvider.warn(getResponseBodyString(res));\n }\n\n this.addToQueue(...retry);\n }\n\n handleOtherResponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
|
|
1
|
+
import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
import { BaseDiagnostic } from './diagnostics/diagnostic';
|
|
3
4
|
export declare const getDefaultConfig: () => {
|
|
4
5
|
flushMaxRetries: number;
|
|
5
6
|
flushQueueSize: number;
|
|
@@ -11,6 +12,7 @@ export declare const getDefaultConfig: () => {
|
|
|
11
12
|
serverUrl: string;
|
|
12
13
|
serverZone: ServerZoneType;
|
|
13
14
|
useBatch: boolean;
|
|
15
|
+
diagnosticProvider: BaseDiagnostic;
|
|
14
16
|
};
|
|
15
17
|
export declare class Config implements IConfig {
|
|
16
18
|
apiKey: string;
|
|
@@ -28,6 +30,7 @@ export declare class Config implements IConfig {
|
|
|
28
30
|
transportProvider: Transport;
|
|
29
31
|
storageProvider?: Storage<Event[]>;
|
|
30
32
|
useBatch: boolean;
|
|
33
|
+
diagnosticProvider: Diagnostic;
|
|
31
34
|
protected _optOut: boolean;
|
|
32
35
|
get optOut(): boolean;
|
|
33
36
|
set optOut(optOut: boolean);
|