@amplitude/analytics-node 1.5.69 → 1.5.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/config.d.ts +1 -0
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +6 -1
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/transports/http.d.ts +8 -0
- package/lib/cjs/transports/http.d.ts.map +1 -1
- package/lib/cjs/transports/http.js +66 -14
- package/lib/cjs/transports/http.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/config.d.ts +1 -0
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +7 -2
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/transports/http.d.ts +8 -0
- package/lib/esm/transports/http.d.ts.map +1 -1
- package/lib/esm/transports/http.js +65 -13
- package/lib/esm/transports/http.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/package.json +2 -2
package/lib/cjs/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Config, NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-core';
|
|
2
2
|
export declare class NodeConfig extends Config implements INodeConfig {
|
|
3
|
+
requestTimeoutMillis: number;
|
|
3
4
|
constructor(apiKey: string, options?: NodeOptions);
|
|
4
5
|
}
|
|
5
6
|
export declare const useNodeConfig: (apiKey: string, overrides?: NodeOptions) => INodeConfig;
|
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,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG3F,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG3F,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;IAC3D,oBAAoB,EAAE,MAAM,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CASlD;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,cAAc,WAAW,KAAG,WAEvE,CAAC"}
|
package/lib/cjs/config.js
CHANGED
|
@@ -7,7 +7,12 @@ var http_1 = require("./transports/http");
|
|
|
7
7
|
var NodeConfig = /** @class */ (function (_super) {
|
|
8
8
|
tslib_1.__extends(NodeConfig, _super);
|
|
9
9
|
function NodeConfig(apiKey, options) {
|
|
10
|
-
|
|
10
|
+
var _this = this;
|
|
11
|
+
var _a;
|
|
12
|
+
var requestTimeoutMillis = (_a = options === null || options === void 0 ? void 0 : options.requestTimeoutMillis) !== null && _a !== void 0 ? _a : http_1.DEFAULT_REQUEST_TIMEOUT_MILLIS;
|
|
13
|
+
_this = _super.call(this, tslib_1.__assign(tslib_1.__assign({ transportProvider: new http_1.Http(requestTimeoutMillis) }, options), { apiKey: apiKey })) || this;
|
|
14
|
+
_this.requestTimeoutMillis = requestTimeoutMillis;
|
|
15
|
+
return _this;
|
|
11
16
|
}
|
|
12
17
|
return NodeConfig;
|
|
13
18
|
}(analytics_core_1.Config));
|
package/lib/cjs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;;AAAA,4DAA2F;AAC3F,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;;AAAA,4DAA2F;AAC3F,0CAAyE;AAEzE;IAAgC,sCAAM;IAGpC,oBAAY,MAAc,EAAE,OAAqB;QAAjD,iBAQC;;QAPC,IAAM,oBAAoB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,mCAAI,qCAA8B,CAAC;gBAC7F,sDACE,iBAAiB,EAAE,IAAI,WAAI,CAAC,oBAAoB,CAAC,IAC9C,OAAO,KACV,MAAM,QAAA,IACN;QACF,KAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;;IACnD,CAAC;IACH,iBAAC;AAAD,CAAC,AAZD,CAAgC,uBAAM,GAYrC;AAZY,gCAAU;AAchB,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,SAAuB;IACnE,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB","sourcesContent":["import { Config, NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-core';\nimport { DEFAULT_REQUEST_TIMEOUT_MILLIS, Http } from './transports/http';\n\nexport class NodeConfig extends Config implements INodeConfig {\n requestTimeoutMillis: number;\n\n constructor(apiKey: string, options?: NodeOptions) {\n const requestTimeoutMillis = options?.requestTimeoutMillis ?? DEFAULT_REQUEST_TIMEOUT_MILLIS;\n super({\n transportProvider: new Http(requestTimeoutMillis),\n ...options,\n apiKey,\n });\n this.requestTimeoutMillis = requestTimeoutMillis;\n }\n}\n\nexport const useNodeConfig = (apiKey: string, overrides?: NodeOptions): INodeConfig => {\n return new NodeConfig(apiKey, overrides);\n};\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createInstance } from './node-client';
|
|
2
|
-
export declare const add: (plugin: import("@amplitude/analytics-core").Plugin<import("@amplitude/analytics-core").NodeClient, import("@amplitude/analytics-core").
|
|
2
|
+
export declare const add: (plugin: import("@amplitude/analytics-core").Plugin<import("@amplitude/analytics-core").NodeClient, import("@amplitude/analytics-core").NodeConfig>) => import("@amplitude/analytics-core").AmplitudeReturn<void>, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, identify: (identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, init: (apiKey: string, options?: import("@amplitude/analytics-core").NodeOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<void>, logEvent: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, remove: (pluginName: string) => import("@amplitude/analytics-core").AmplitudeReturn<void>, revenue: (revenue: import("@amplitude/analytics-core").IRevenue, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, setGroup: (groupType: string, groupName: string | string[], eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, setOptOut: (optOut: boolean) => void, track: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, flush: () => import("@amplitude/analytics-core").AmplitudeReturn<void>;
|
|
3
3
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
4
4
|
export * as Types from './types';
|
|
5
5
|
//# 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":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,eAAO,MAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,eAAO,MAAQ,GAAG,qNAAE,aAAa,8RAAE,QAAQ,6OAAE,IAAI,wJAAE,QAAQ,2SAAE,MAAM,qFAAE,OAAO,2OAAE,QAAQ,qOAAE,SAAS,6BAAE,KAAK,2SAAE,KAAK,iEACvG,CAAC;AACT,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAI9D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { BaseTransport, Payload, Response, Transport } from '@amplitude/analytics-core';
|
|
2
|
+
/**
|
|
3
|
+
* Node's HTTP client applies no timeout of its own, so without this a stalled or
|
|
4
|
+
* slow-trickling upload hangs forever. Matches the 10s network timeout used by
|
|
5
|
+
* the Amplitude Java and Python SDKs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;
|
|
2
8
|
export declare class Http extends BaseTransport implements Transport {
|
|
9
|
+
private readonly requestTimeoutMillis;
|
|
10
|
+
constructor(requestTimeoutMillis?: number);
|
|
3
11
|
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
4
12
|
}
|
|
5
13
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAIxF,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAIxF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,QAAQ,CAAC;AAQpD,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAApB,oBAAoB,GAAE,MAAuC;IAI1F,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA2FpE"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Http = void 0;
|
|
3
|
+
exports.Http = exports.DEFAULT_REQUEST_TIMEOUT_MILLIS = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
6
6
|
var http = tslib_1.__importStar(require("http"));
|
|
7
7
|
var https = tslib_1.__importStar(require("https"));
|
|
8
|
+
/**
|
|
9
|
+
* Node's HTTP client applies no timeout of its own, so without this a stalled or
|
|
10
|
+
* slow-trickling upload hangs forever. Matches the 10s network timeout used by
|
|
11
|
+
* the Amplitude Java and Python SDKs.
|
|
12
|
+
*/
|
|
13
|
+
exports.DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;
|
|
14
|
+
// buildResponse() maps 408 to Status.Timeout and 0 to Status.Unknown. Destination
|
|
15
|
+
// retries both with backoff, bounded by flushMaxRetries, rather than dropping the
|
|
16
|
+
// batch the way it does for a null response.
|
|
17
|
+
var REQUEST_TIMEOUT_STATUS_CODE = 408;
|
|
18
|
+
var INCOMPLETE_RESPONSE_STATUS_CODE = 0;
|
|
8
19
|
var Http = /** @class */ (function (_super) {
|
|
9
20
|
tslib_1.__extends(Http, _super);
|
|
10
|
-
function Http() {
|
|
11
|
-
|
|
21
|
+
function Http(requestTimeoutMillis) {
|
|
22
|
+
if (requestTimeoutMillis === void 0) { requestTimeoutMillis = exports.DEFAULT_REQUEST_TIMEOUT_MILLIS; }
|
|
23
|
+
var _this = _super.call(this) || this;
|
|
24
|
+
_this.requestTimeoutMillis = requestTimeoutMillis;
|
|
25
|
+
return _this;
|
|
12
26
|
}
|
|
13
27
|
Http.prototype.send = function (serverUrl, payload) {
|
|
14
28
|
var _this = this;
|
|
@@ -36,27 +50,65 @@ var Http = /** @class */ (function (_super) {
|
|
|
36
50
|
protocol: url.protocol,
|
|
37
51
|
};
|
|
38
52
|
return new Promise(function (resolve) {
|
|
53
|
+
// Every path below must settle exactly once. A send() that never settles
|
|
54
|
+
// leaves Destination.flushId set forever, which silently no-ops all later
|
|
55
|
+
// flushes while the event queue keeps growing. See SDK-188.
|
|
56
|
+
var settled = false;
|
|
57
|
+
// `timer` is declared below, once req exists. Safe to close over here
|
|
58
|
+
// because protocol.request() never invokes its response callback
|
|
59
|
+
// synchronously, so nothing can call settle() before that runs.
|
|
60
|
+
var settle = function (response) {
|
|
61
|
+
if (settled) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
settled = true;
|
|
65
|
+
clearTimeout(timer.deadline);
|
|
66
|
+
resolve(response);
|
|
67
|
+
};
|
|
68
|
+
// A connection that drops mid-response is transient, so retry rather than
|
|
69
|
+
// discard the batch. Amplitude dedupes on insert_id, making a replay of a
|
|
70
|
+
// batch the server may already have processed safe.
|
|
71
|
+
var settleAsIncomplete = function () { return settle(_this.buildResponse({ code: INCOMPLETE_RESPONSE_STATUS_CODE })); };
|
|
39
72
|
var req = protocol.request(options, function (res) {
|
|
40
73
|
res.setEncoding('utf8');
|
|
41
74
|
var responsePayload = '';
|
|
42
75
|
res.on('data', function (chunk) {
|
|
43
76
|
responsePayload += chunk;
|
|
44
77
|
});
|
|
78
|
+
res.on('aborted', settleAsIncomplete);
|
|
79
|
+
res.on('error', settleAsIncomplete);
|
|
45
80
|
res.on('end', function () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
// A truncated body tells us nothing about whether the server accepted
|
|
82
|
+
// the batch.
|
|
83
|
+
if (!res.complete) {
|
|
84
|
+
settleAsIncomplete();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
// An empty body lands here too, and falls back to the status line.
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
90
|
+
var parsedResponsePayload = JSON.parse(responsePayload);
|
|
91
|
+
settle(_this.buildResponse(parsedResponsePayload));
|
|
92
|
+
}
|
|
93
|
+
catch (_a) {
|
|
94
|
+
settle(_this.buildResponse({ code: res.statusCode }));
|
|
56
95
|
}
|
|
57
96
|
});
|
|
58
97
|
});
|
|
59
|
-
|
|
98
|
+
// Unlike the cases above, a request that never reached the server keeps its
|
|
99
|
+
// long-standing drop-on-error behavior.
|
|
100
|
+
req.on('error', function () { return settle(null); });
|
|
101
|
+
// An absolute deadline, not req.setTimeout()'s socket-inactivity timer:
|
|
102
|
+
// that resets on every byte of traffic, so a response trickled slower than
|
|
103
|
+
// requestTimeoutMillis but never finished would keep it from firing at all.
|
|
104
|
+
// unref() so it can't keep the event loop alive on its own.
|
|
105
|
+
var timer = {
|
|
106
|
+
deadline: setTimeout(function () {
|
|
107
|
+
req.destroy();
|
|
108
|
+
settle(_this.buildResponse({ code: REQUEST_TIMEOUT_STATUS_CODE }));
|
|
109
|
+
}, _this.requestTimeoutMillis),
|
|
110
|
+
};
|
|
111
|
+
timer.deadline.unref();
|
|
60
112
|
req.end(requestPayload);
|
|
61
113
|
});
|
|
62
114
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";;;;AAAA,4DAAwF;AACxF,iDAA6B;AAC7B,mDAA+B;AAE/B;IAA0B,gCAAa;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";;;;AAAA,4DAAwF;AACxF,iDAA6B;AAC7B,mDAA+B;AAE/B;;;;GAIG;AACU,QAAA,8BAA8B,GAAG,KAAK,CAAC;AAEpD,kFAAkF;AAClF,kFAAkF;AAClF,6CAA6C;AAC7C,IAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,IAAM,+BAA+B,GAAG,CAAC,CAAC;AAE1C;IAA0B,gCAAa;IACrC,cAA6B,oBAA6D;QAA7D,qCAAA,EAAA,uBAA+B,sCAA8B;QAA1F,YACE,iBAAO,SACR;QAF4B,0BAAoB,GAApB,oBAAoB,CAAyC;;IAE1F,CAAC;IAED,mBAAI,GAAJ,UAAK,SAAiB,EAAE,OAAgB;QAAxC,iBA0FC;QAzFC,IAAI,QAAoC,CAAC;QACzC,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YACnC,QAAQ,GAAG,IAAI,CAAC;SACjB;aAAM,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAC3C,QAAQ,GAAG,KAAK,CAAC;SAClB;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACvC;QAED,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,IAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAM,OAAO,GAAG;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;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AAC,EAAE,CAAC,KAAK,EAAE;oBACZ,sEAAsE;oBACtE,aAAa;oBACb,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;wBACjB,kBAAkB,EAAE,CAAC;wBACrB,OAAO;qBACR;oBACD,IAAI;wBACF,mEAAmE;wBACnE,mEAAmE;wBACnE,IAAM,qBAAqB,GAAwB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;wBAC/E,MAAM,CAAC,KAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC;qBACnD;oBAAC,WAAM;wBACN,MAAM,CAAC,KAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;qBACtD;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,4EAA4E;YAC5E,wCAAwC;YACxC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,cAAM,OAAA,MAAM,CAAC,IAAI,CAAC,EAAZ,CAAY,CAAC,CAAC;YAEpC,wEAAwE;YACxE,2EAA2E;YAC3E,4EAA4E;YAC5E,4DAA4D;YAC5D,IAAM,KAAK,GAAG;gBACZ,QAAQ,EAAE,UAAU,CAAC;oBACnB,GAAG,CAAC,OAAO,EAAE,CAAC;oBACd,MAAM,CAAC,KAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,2BAA2B,EAAE,CAAC,CAAC,CAAC;gBACpE,CAAC,EAAE,KAAI,CAAC,oBAAoB,CAAC;aAC9B,CAAC;YACF,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEvB,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAhGD,CAA0B,8BAAa,GAgGtC;AAhGY,oBAAI","sourcesContent":["import { BaseTransport, Payload, Response, Transport } from '@amplitude/analytics-core';\nimport * as http from 'http';\nimport * as https from 'https';\n\n/**\n * Node's HTTP client applies no timeout of its own, so without this a stalled or\n * slow-trickling upload hangs forever. Matches the 10s network timeout used by\n * the Amplitude Java and Python SDKs.\n */\nexport const DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;\n\n// buildResponse() maps 408 to Status.Timeout and 0 to Status.Unknown. Destination\n// retries both with backoff, bounded by flushMaxRetries, rather than dropping the\n// batch the way it does for a null response.\nconst REQUEST_TIMEOUT_STATUS_CODE = 408;\nconst INCOMPLETE_RESPONSE_STATUS_CODE = 0;\n\nexport class Http extends BaseTransport implements Transport {\n constructor(private readonly requestTimeoutMillis: number = DEFAULT_REQUEST_TIMEOUT_MILLIS) {\n super();\n }\n\n send(serverUrl: string, payload: Payload): Promise<Response | null> {\n let protocol: typeof http | typeof https;\n if (serverUrl.startsWith('http://')) {\n protocol = http;\n } else if (serverUrl.startsWith('https://')) {\n protocol = https;\n } else {\n throw new Error('Invalid server url');\n }\n\n const url = new URL(serverUrl);\n const requestPayload = JSON.stringify(payload);\n const options = {\n headers: {\n 'Content-Type': 'application/json',\n 'Content-Length': Buffer.byteLength(requestPayload),\n },\n hostname: url.hostname,\n method: 'POST',\n path: url.pathname,\n port: url.port,\n protocol: url.protocol,\n };\n return new Promise((resolve) => {\n // Every path below must settle exactly once. A send() that never settles\n // leaves Destination.flushId set forever, which silently no-ops all later\n // flushes while the event queue keeps growing. See SDK-188.\n let settled = false;\n // `timer` is declared below, once req exists. Safe to close over here\n // because protocol.request() never invokes its response callback\n // synchronously, so nothing can call settle() before that runs.\n const settle = (response: Response | null) => {\n if (settled) {\n return;\n }\n settled = true;\n clearTimeout(timer.deadline);\n resolve(response);\n };\n\n // A connection that drops mid-response is transient, so retry rather than\n // discard the batch. Amplitude dedupes on insert_id, making a replay of a\n // batch the server may already have processed safe.\n const settleAsIncomplete = () => settle(this.buildResponse({ code: INCOMPLETE_RESPONSE_STATUS_CODE }));\n\n const req = protocol.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n res.on('aborted', settleAsIncomplete);\n res.on('error', settleAsIncomplete);\n\n res.on('end', () => {\n // A truncated body tells us nothing about whether the server accepted\n // the batch.\n if (!res.complete) {\n settleAsIncomplete();\n return;\n }\n try {\n // An empty body lands here too, and falls back to the status line.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n settle(this.buildResponse(parsedResponsePayload));\n } catch {\n settle(this.buildResponse({ code: res.statusCode }));\n }\n });\n });\n\n // Unlike the cases above, a request that never reached the server keeps its\n // long-standing drop-on-error behavior.\n req.on('error', () => settle(null));\n\n // An absolute deadline, not req.setTimeout()'s socket-inactivity timer:\n // that resets on every byte of traffic, so a response trickled slower than\n // requestTimeoutMillis but never finished would keep it from firing at all.\n // unref() so it can't keep the event loop alive on its own.\n const timer = {\n deadline: setTimeout(() => {\n req.destroy();\n settle(this.buildResponse({ code: REQUEST_TIMEOUT_STATUS_CODE }));\n }, this.requestTimeoutMillis),\n };\n timer.deadline.unref();\n\n req.end(requestPayload);\n });\n }\n}\n"]}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.5.
|
|
1
|
+
export declare const VERSION = "1.5.71";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.5.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.5.71';\n"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Config, NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-core';
|
|
2
2
|
export declare class NodeConfig extends Config implements INodeConfig {
|
|
3
|
+
requestTimeoutMillis: number;
|
|
3
4
|
constructor(apiKey: string, options?: NodeOptions);
|
|
4
5
|
}
|
|
5
6
|
export declare const useNodeConfig: (apiKey: string, overrides?: NodeOptions) => INodeConfig;
|
package/lib/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG3F,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG3F,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;IAC3D,oBAAoB,EAAE,MAAM,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CASlD;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,cAAc,WAAW,KAAG,WAEvE,CAAC"}
|
package/lib/esm/config.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { __assign, __extends } from "tslib";
|
|
2
2
|
import { Config } from '@amplitude/analytics-core';
|
|
3
|
-
import { Http } from './transports/http';
|
|
3
|
+
import { DEFAULT_REQUEST_TIMEOUT_MILLIS, Http } from './transports/http';
|
|
4
4
|
var NodeConfig = /** @class */ (function (_super) {
|
|
5
5
|
__extends(NodeConfig, _super);
|
|
6
6
|
function NodeConfig(apiKey, options) {
|
|
7
|
-
|
|
7
|
+
var _this = this;
|
|
8
|
+
var _a;
|
|
9
|
+
var requestTimeoutMillis = (_a = options === null || options === void 0 ? void 0 : options.requestTimeoutMillis) !== null && _a !== void 0 ? _a : DEFAULT_REQUEST_TIMEOUT_MILLIS;
|
|
10
|
+
_this = _super.call(this, __assign(__assign({ transportProvider: new Http(requestTimeoutMillis) }, options), { apiKey: apiKey })) || this;
|
|
11
|
+
_this.requestTimeoutMillis = requestTimeoutMillis;
|
|
12
|
+
return _this;
|
|
8
13
|
}
|
|
9
14
|
return NodeConfig;
|
|
10
15
|
}(Config));
|
package/lib/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAA0C,MAAM,2BAA2B,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAA0C,MAAM,2BAA2B,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzE;IAAgC,8BAAM;IAGpC,oBAAY,MAAc,EAAE,OAAqB;QAAjD,iBAQC;;QAPC,IAAM,oBAAoB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,mCAAI,8BAA8B,CAAC;gBAC7F,sCACE,iBAAiB,EAAE,IAAI,IAAI,CAAC,oBAAoB,CAAC,IAC9C,OAAO,KACV,MAAM,QAAA,IACN;QACF,KAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;;IACnD,CAAC;IACH,iBAAC;AAAD,CAAC,AAZD,CAAgC,MAAM,GAYrC;;AAED,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,SAAuB;IACnE,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["import { Config, NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-core';\nimport { DEFAULT_REQUEST_TIMEOUT_MILLIS, Http } from './transports/http';\n\nexport class NodeConfig extends Config implements INodeConfig {\n requestTimeoutMillis: number;\n\n constructor(apiKey: string, options?: NodeOptions) {\n const requestTimeoutMillis = options?.requestTimeoutMillis ?? DEFAULT_REQUEST_TIMEOUT_MILLIS;\n super({\n transportProvider: new Http(requestTimeoutMillis),\n ...options,\n apiKey,\n });\n this.requestTimeoutMillis = requestTimeoutMillis;\n }\n}\n\nexport const useNodeConfig = (apiKey: string, overrides?: NodeOptions): INodeConfig => {\n return new NodeConfig(apiKey, overrides);\n};\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createInstance } from './node-client';
|
|
2
|
-
export declare const add: (plugin: import("@amplitude/analytics-core").Plugin<import("@amplitude/analytics-core").NodeClient, import("@amplitude/analytics-core").
|
|
2
|
+
export declare const add: (plugin: import("@amplitude/analytics-core").Plugin<import("@amplitude/analytics-core").NodeClient, import("@amplitude/analytics-core").NodeConfig>) => import("@amplitude/analytics-core").AmplitudeReturn<void>, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, identify: (identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, init: (apiKey: string, options?: import("@amplitude/analytics-core").NodeOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<void>, logEvent: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, remove: (pluginName: string) => import("@amplitude/analytics-core").AmplitudeReturn<void>, revenue: (revenue: import("@amplitude/analytics-core").IRevenue, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, setGroup: (groupType: string, groupName: string | string[], eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, setOptOut: (optOut: boolean) => void, track: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, flush: () => import("@amplitude/analytics-core").AmplitudeReturn<void>;
|
|
3
3
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
4
4
|
export * as Types from './types';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,eAAO,MAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,eAAO,MAAQ,GAAG,qNAAE,aAAa,8RAAE,QAAQ,6OAAE,IAAI,wJAAE,QAAQ,2SAAE,MAAM,qFAAE,OAAO,2OAAE,QAAQ,qOAAE,SAAS,6BAAE,KAAK,2SAAE,KAAK,iEACvG,CAAC;AACT,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAI9D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { BaseTransport, Payload, Response, Transport } from '@amplitude/analytics-core';
|
|
2
|
+
/**
|
|
3
|
+
* Node's HTTP client applies no timeout of its own, so without this a stalled or
|
|
4
|
+
* slow-trickling upload hangs forever. Matches the 10s network timeout used by
|
|
5
|
+
* the Amplitude Java and Python SDKs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;
|
|
2
8
|
export declare class Http extends BaseTransport implements Transport {
|
|
9
|
+
private readonly requestTimeoutMillis;
|
|
10
|
+
constructor(requestTimeoutMillis?: number);
|
|
3
11
|
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
4
12
|
}
|
|
5
13
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAIxF,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAIxF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,QAAQ,CAAC;AAQpD,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAApB,oBAAoB,GAAE,MAAuC;IAI1F,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA2FpE"}
|
|
@@ -2,10 +2,24 @@ import { __extends } from "tslib";
|
|
|
2
2
|
import { BaseTransport } from '@amplitude/analytics-core';
|
|
3
3
|
import * as http from 'http';
|
|
4
4
|
import * as https from 'https';
|
|
5
|
+
/**
|
|
6
|
+
* Node's HTTP client applies no timeout of its own, so without this a stalled or
|
|
7
|
+
* slow-trickling upload hangs forever. Matches the 10s network timeout used by
|
|
8
|
+
* the Amplitude Java and Python SDKs.
|
|
9
|
+
*/
|
|
10
|
+
export var DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;
|
|
11
|
+
// buildResponse() maps 408 to Status.Timeout and 0 to Status.Unknown. Destination
|
|
12
|
+
// retries both with backoff, bounded by flushMaxRetries, rather than dropping the
|
|
13
|
+
// batch the way it does for a null response.
|
|
14
|
+
var REQUEST_TIMEOUT_STATUS_CODE = 408;
|
|
15
|
+
var INCOMPLETE_RESPONSE_STATUS_CODE = 0;
|
|
5
16
|
var Http = /** @class */ (function (_super) {
|
|
6
17
|
__extends(Http, _super);
|
|
7
|
-
function Http() {
|
|
8
|
-
|
|
18
|
+
function Http(requestTimeoutMillis) {
|
|
19
|
+
if (requestTimeoutMillis === void 0) { requestTimeoutMillis = DEFAULT_REQUEST_TIMEOUT_MILLIS; }
|
|
20
|
+
var _this = _super.call(this) || this;
|
|
21
|
+
_this.requestTimeoutMillis = requestTimeoutMillis;
|
|
22
|
+
return _this;
|
|
9
23
|
}
|
|
10
24
|
Http.prototype.send = function (serverUrl, payload) {
|
|
11
25
|
var _this = this;
|
|
@@ -33,27 +47,65 @@ var Http = /** @class */ (function (_super) {
|
|
|
33
47
|
protocol: url.protocol,
|
|
34
48
|
};
|
|
35
49
|
return new Promise(function (resolve) {
|
|
50
|
+
// Every path below must settle exactly once. A send() that never settles
|
|
51
|
+
// leaves Destination.flushId set forever, which silently no-ops all later
|
|
52
|
+
// flushes while the event queue keeps growing. See SDK-188.
|
|
53
|
+
var settled = false;
|
|
54
|
+
// `timer` is declared below, once req exists. Safe to close over here
|
|
55
|
+
// because protocol.request() never invokes its response callback
|
|
56
|
+
// synchronously, so nothing can call settle() before that runs.
|
|
57
|
+
var settle = function (response) {
|
|
58
|
+
if (settled) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
settled = true;
|
|
62
|
+
clearTimeout(timer.deadline);
|
|
63
|
+
resolve(response);
|
|
64
|
+
};
|
|
65
|
+
// A connection that drops mid-response is transient, so retry rather than
|
|
66
|
+
// discard the batch. Amplitude dedupes on insert_id, making a replay of a
|
|
67
|
+
// batch the server may already have processed safe.
|
|
68
|
+
var settleAsIncomplete = function () { return settle(_this.buildResponse({ code: INCOMPLETE_RESPONSE_STATUS_CODE })); };
|
|
36
69
|
var req = protocol.request(options, function (res) {
|
|
37
70
|
res.setEncoding('utf8');
|
|
38
71
|
var responsePayload = '';
|
|
39
72
|
res.on('data', function (chunk) {
|
|
40
73
|
responsePayload += chunk;
|
|
41
74
|
});
|
|
75
|
+
res.on('aborted', settleAsIncomplete);
|
|
76
|
+
res.on('error', settleAsIncomplete);
|
|
42
77
|
res.on('end', function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
// A truncated body tells us nothing about whether the server accepted
|
|
79
|
+
// the batch.
|
|
80
|
+
if (!res.complete) {
|
|
81
|
+
settleAsIncomplete();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
// An empty body lands here too, and falls back to the status line.
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
87
|
+
var parsedResponsePayload = JSON.parse(responsePayload);
|
|
88
|
+
settle(_this.buildResponse(parsedResponsePayload));
|
|
89
|
+
}
|
|
90
|
+
catch (_a) {
|
|
91
|
+
settle(_this.buildResponse({ code: res.statusCode }));
|
|
53
92
|
}
|
|
54
93
|
});
|
|
55
94
|
});
|
|
56
|
-
|
|
95
|
+
// Unlike the cases above, a request that never reached the server keeps its
|
|
96
|
+
// long-standing drop-on-error behavior.
|
|
97
|
+
req.on('error', function () { return settle(null); });
|
|
98
|
+
// An absolute deadline, not req.setTimeout()'s socket-inactivity timer:
|
|
99
|
+
// that resets on every byte of traffic, so a response trickled slower than
|
|
100
|
+
// requestTimeoutMillis but never finished would keep it from firing at all.
|
|
101
|
+
// unref() so it can't keep the event loop alive on its own.
|
|
102
|
+
var timer = {
|
|
103
|
+
deadline: setTimeout(function () {
|
|
104
|
+
req.destroy();
|
|
105
|
+
settle(_this.buildResponse({ code: REQUEST_TIMEOUT_STATUS_CODE }));
|
|
106
|
+
}, _this.requestTimeoutMillis),
|
|
107
|
+
};
|
|
108
|
+
timer.deadline.unref();
|
|
57
109
|
req.end(requestPayload);
|
|
58
110
|
});
|
|
59
111
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAgC,MAAM,2BAA2B,CAAC;AACxF,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;IAA0B,wBAAa;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAgC,MAAM,2BAA2B,CAAC;AACxF,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;GAIG;AACH,MAAM,CAAC,IAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,kFAAkF;AAClF,kFAAkF;AAClF,6CAA6C;AAC7C,IAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,IAAM,+BAA+B,GAAG,CAAC,CAAC;AAE1C;IAA0B,wBAAa;IACrC,cAA6B,oBAA6D;QAA7D,qCAAA,EAAA,qDAA6D;QAA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AAC,CAAC;YAEpC,wEAAwE;YACxE,2EAA2E;YAC3E,4EAA4E;YAC5E,4DAA4D;YAC5D,IAAM,KAAK,GAAG;gBACZ,QAAQ,EAAE,UAAU,CAAC;oBACnB,GAAG,CAAC,OAAO,EAAE,CAAC;oBACd,MAAM,CAAC,KAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,2BAA2B,EAAE,CAAC,CAAC,CAAC;gBACpE,CAAC,EAAE,KAAI,CAAC,oBAAoB,CAAC;aAC9B,CAAC;YACF,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEvB,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAhGD,CAA0B,aAAa,GAgGtC","sourcesContent":["import { BaseTransport, Payload, Response, Transport } from '@amplitude/analytics-core';\nimport * as http from 'http';\nimport * as https from 'https';\n\n/**\n * Node's HTTP client applies no timeout of its own, so without this a stalled or\n * slow-trickling upload hangs forever. Matches the 10s network timeout used by\n * the Amplitude Java and Python SDKs.\n */\nexport const DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000;\n\n// buildResponse() maps 408 to Status.Timeout and 0 to Status.Unknown. Destination\n// retries both with backoff, bounded by flushMaxRetries, rather than dropping the\n// batch the way it does for a null response.\nconst REQUEST_TIMEOUT_STATUS_CODE = 408;\nconst INCOMPLETE_RESPONSE_STATUS_CODE = 0;\n\nexport class Http extends BaseTransport implements Transport {\n constructor(private readonly requestTimeoutMillis: number = DEFAULT_REQUEST_TIMEOUT_MILLIS) {\n super();\n }\n\n send(serverUrl: string, payload: Payload): Promise<Response | null> {\n let protocol: typeof http | typeof https;\n if (serverUrl.startsWith('http://')) {\n protocol = http;\n } else if (serverUrl.startsWith('https://')) {\n protocol = https;\n } else {\n throw new Error('Invalid server url');\n }\n\n const url = new URL(serverUrl);\n const requestPayload = JSON.stringify(payload);\n const options = {\n headers: {\n 'Content-Type': 'application/json',\n 'Content-Length': Buffer.byteLength(requestPayload),\n },\n hostname: url.hostname,\n method: 'POST',\n path: url.pathname,\n port: url.port,\n protocol: url.protocol,\n };\n return new Promise((resolve) => {\n // Every path below must settle exactly once. A send() that never settles\n // leaves Destination.flushId set forever, which silently no-ops all later\n // flushes while the event queue keeps growing. See SDK-188.\n let settled = false;\n // `timer` is declared below, once req exists. Safe to close over here\n // because protocol.request() never invokes its response callback\n // synchronously, so nothing can call settle() before that runs.\n const settle = (response: Response | null) => {\n if (settled) {\n return;\n }\n settled = true;\n clearTimeout(timer.deadline);\n resolve(response);\n };\n\n // A connection that drops mid-response is transient, so retry rather than\n // discard the batch. Amplitude dedupes on insert_id, making a replay of a\n // batch the server may already have processed safe.\n const settleAsIncomplete = () => settle(this.buildResponse({ code: INCOMPLETE_RESPONSE_STATUS_CODE }));\n\n const req = protocol.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n res.on('aborted', settleAsIncomplete);\n res.on('error', settleAsIncomplete);\n\n res.on('end', () => {\n // A truncated body tells us nothing about whether the server accepted\n // the batch.\n if (!res.complete) {\n settleAsIncomplete();\n return;\n }\n try {\n // An empty body lands here too, and falls back to the status line.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n settle(this.buildResponse(parsedResponsePayload));\n } catch {\n settle(this.buildResponse({ code: res.statusCode }));\n }\n });\n });\n\n // Unlike the cases above, a request that never reached the server keeps its\n // long-standing drop-on-error behavior.\n req.on('error', () => settle(null));\n\n // An absolute deadline, not req.setTimeout()'s socket-inactivity timer:\n // that resets on every byte of traffic, so a response trickled slower than\n // requestTimeoutMillis but never finished would keep it from firing at all.\n // unref() so it can't keep the event loop alive on its own.\n const timer = {\n deadline: setTimeout(() => {\n req.destroy();\n settle(this.buildResponse({ code: REQUEST_TIMEOUT_STATUS_CODE }));\n }, this.requestTimeoutMillis),\n };\n timer.deadline.unref();\n\n req.end(requestPayload);\n });\n }\n}\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.5.
|
|
1
|
+
export declare const VERSION = "1.5.71";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var VERSION = '1.5.
|
|
1
|
+
export var VERSION = '1.5.71';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.5.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.5.71';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-node",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.71",
|
|
4
4
|
"description": "Official Amplitude SDK for NodeJS",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"tslib": "^2.4.1",
|
|
25
|
-
"@amplitude/analytics-core": "2.
|
|
25
|
+
"@amplitude/analytics-core": "2.55.0"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"lib"
|