@amplitude/analytics-node 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +152 -0
- package/lib/cjs/config.d.ts +7 -0
- package/lib/cjs/config.d.ts.map +1 -0
- package/lib/cjs/config.js +23 -0
- package/lib/cjs/config.js.map +1 -0
- package/lib/cjs/index.d.ts +4 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +19 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/node-client.d.ts +138 -0
- package/lib/cjs/node-client.d.ts.map +1 -0
- package/lib/cjs/node-client.js +175 -0
- package/lib/cjs/node-client.js.map +1 -0
- package/lib/cjs/plugins/context.d.ts +11 -0
- package/lib/cjs/plugins/context.d.ts.map +1 -0
- package/lib/cjs/plugins/context.js +29 -0
- package/lib/cjs/plugins/context.js.map +1 -0
- package/lib/cjs/transports/http.d.ts +6 -0
- package/lib/cjs/transports/http.d.ts.map +1 -0
- package/lib/cjs/transports/http.js +66 -0
- package/lib/cjs/transports/http.js.map +1 -0
- package/lib/cjs/version.d.ts +2 -0
- package/lib/cjs/version.d.ts.map +1 -0
- package/lib/cjs/version.js +4 -0
- package/lib/cjs/version.js.map +1 -0
- package/lib/esm/config.d.ts +7 -0
- package/lib/esm/config.d.ts.map +1 -0
- package/lib/esm/config.js +20 -0
- package/lib/esm/config.js.map +1 -0
- package/lib/esm/index.d.ts +4 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/node-client.d.ts +138 -0
- package/lib/esm/node-client.d.ts.map +1 -0
- package/lib/esm/node-client.js +173 -0
- package/lib/esm/node-client.js.map +1 -0
- package/lib/esm/plugins/context.d.ts +11 -0
- package/lib/esm/plugins/context.d.ts.map +1 -0
- package/lib/esm/plugins/context.js +27 -0
- package/lib/esm/plugins/context.js.map +1 -0
- package/lib/esm/transports/http.d.ts +6 -0
- package/lib/esm/transports/http.d.ts.map +1 -0
- package/lib/esm/transports/http.js +64 -0
- package/lib/esm/transports/http.js.map +1 -0
- package/lib/esm/version.d.ts +2 -0
- package/lib/esm/version.d.ts.map +1 -0
- package/lib/esm/version.js +2 -0
- package/lib/esm/version.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.Http = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
|
+
var http = require("http");
|
|
6
|
+
var https = require("https");
|
|
7
|
+
var Http = /** @class */ (function (_super) {
|
|
8
|
+
(0, tslib_1.__extends)(Http, _super);
|
|
9
|
+
function Http() {
|
|
10
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
11
|
+
}
|
|
12
|
+
Http.prototype.send = function (serverUrl, payload) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
var protocol;
|
|
15
|
+
if (serverUrl.startsWith('http://')) {
|
|
16
|
+
protocol = http;
|
|
17
|
+
}
|
|
18
|
+
else if (serverUrl.startsWith('https://')) {
|
|
19
|
+
protocol = https;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new Error('Invalid server url');
|
|
23
|
+
}
|
|
24
|
+
var url = new URL(serverUrl);
|
|
25
|
+
var requestPayload = JSON.stringify(payload);
|
|
26
|
+
var options = {
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'Content-Length': Buffer.byteLength(requestPayload),
|
|
30
|
+
},
|
|
31
|
+
hostname: url.hostname,
|
|
32
|
+
method: 'POST',
|
|
33
|
+
path: url.pathname,
|
|
34
|
+
port: url.port,
|
|
35
|
+
protocol: url.protocol,
|
|
36
|
+
};
|
|
37
|
+
return new Promise(function (resolve) {
|
|
38
|
+
var req = protocol.request(options, function (res) {
|
|
39
|
+
res.setEncoding('utf8');
|
|
40
|
+
var responsePayload = '';
|
|
41
|
+
res.on('data', function (chunk) {
|
|
42
|
+
responsePayload += chunk;
|
|
43
|
+
});
|
|
44
|
+
res.on('end', function () {
|
|
45
|
+
if (res.complete && responsePayload.length > 0) {
|
|
46
|
+
try {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
48
|
+
var parsedResponsePayload = JSON.parse(responsePayload);
|
|
49
|
+
var result = _this.buildResponse(parsedResponsePayload);
|
|
50
|
+
resolve(result);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
catch (_a) {
|
|
54
|
+
resolve(null);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
req.on('error', _this.buildResponse.bind(_this));
|
|
60
|
+
req.end(requestPayload);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
return Http;
|
|
64
|
+
}(analytics_core_1.BaseTransport));
|
|
65
|
+
exports.Http = Http;
|
|
66
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";;;AACA,4DAA0D;AAC1D,2BAA6B;AAC7B,6BAA+B;AAE/B;IAA0B,qCAAa;IAAvC;;IAkDA,CAAC;IAjDC,mBAAI,GAAJ,UAAK,SAAiB,EAAE,OAAgB;QAAxC,iBAgDC;QA/CC,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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AC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAC;YAC/C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAlDD,CAA0B,8BAAa,GAkDtC;AAlDY,oBAAI","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport { BaseTransport } from '@amplitude/analytics-core';\nimport * as http from 'http';\nimport * as https from 'https';\n\nexport class Http extends BaseTransport implements Transport {\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 const req = protocol.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n\n res.on('end', () => {\n if (res.complete && responsePayload.length > 0) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', this.buildResponse.bind(this));\n req.end(requestPayload);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["export const VERSION = '0.3.4';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-types';
|
|
2
|
+
import { Config } from '@amplitude/analytics-core';
|
|
3
|
+
export declare class NodeConfig extends Config implements INodeConfig {
|
|
4
|
+
constructor(apiKey: string, options?: NodeOptions);
|
|
5
|
+
}
|
|
6
|
+
export declare const useNodeConfig: (apiKey: string, overrides?: NodeOptions | undefined) => INodeConfig;
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAGnD,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;gBAC/C,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAWlD;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,0CAA4B,WAEvE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __assign, __extends } from "tslib";
|
|
2
|
+
import { Config } from '@amplitude/analytics-core';
|
|
3
|
+
import { Http } from './transports/http';
|
|
4
|
+
var NodeConfig = /** @class */ (function (_super) {
|
|
5
|
+
__extends(NodeConfig, _super);
|
|
6
|
+
function NodeConfig(apiKey, options) {
|
|
7
|
+
var _a;
|
|
8
|
+
var _this = this;
|
|
9
|
+
var storageProvider = options === null || options === void 0 ? void 0 : options.storageProvider;
|
|
10
|
+
var transportProvider = (_a = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _a !== void 0 ? _a : new Http();
|
|
11
|
+
_this = _super.call(this, __assign(__assign({}, options), { apiKey: apiKey, storageProvider: storageProvider, transportProvider: transportProvider })) || this;
|
|
12
|
+
return _this;
|
|
13
|
+
}
|
|
14
|
+
return NodeConfig;
|
|
15
|
+
}(Config));
|
|
16
|
+
export { NodeConfig };
|
|
17
|
+
export var useNodeConfig = function (apiKey, overrides) {
|
|
18
|
+
return new NodeConfig(apiKey, overrides);
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC;IAAgC,8BAAM;IACpC,oBAAY,MAAc,EAAE,OAAqB;;QAAjD,iBAUC;QATC,IAAM,eAAe,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAC;QACjD,IAAM,iBAAiB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,IAAI,IAAI,EAAE,CAAC;QAEnE,QAAA,wCACK,OAAO,KACV,MAAM,QAAA,EACN,eAAe,iBAAA,EACf,iBAAiB,mBAAA,IACjB,SAAC;;IACL,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 { NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-types';\nimport { Config } from '@amplitude/analytics-core';\nimport { Http } from './transports/http';\n\nexport class NodeConfig extends Config implements INodeConfig {\n constructor(apiKey: string, options?: NodeOptions) {\n const storageProvider = options?.storageProvider;\n const transportProvider = options?.transportProvider ?? new Http();\n\n super({\n ...options,\n apiKey,\n storageProvider,\n transportProvider,\n });\n }\n}\n\nexport const useNodeConfig = (apiKey: string, overrides?: NodeOptions): INodeConfig => {\n return new NodeConfig(apiKey, overrides);\n};\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { add, groupIdentify, identify, init, logEvent, remove, revenue, setGroup, setOptOut, track, flush, } from './node-client';
|
|
2
|
+
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
3
|
+
export * as Types from '@amplitude/analytics-types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,EACL,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { add, groupIdentify, identify, init, logEvent, remove, revenue, setGroup, setOptOut, track, flush, } from './node-client';
|
|
2
|
+
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
3
|
+
import * as Types_1 from '@amplitude/analytics-types';
|
|
4
|
+
export { Types_1 as Types };
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,EACL,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;yBACvC,4BAA4B;oBAAvC,KAAK","sourcesContent":["export {\n add,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n revenue,\n setGroup,\n setOptOut,\n track,\n flush,\n} from './node-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\nexport * as Types from '@amplitude/analytics-types';\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { AmplitudeCore } from '@amplitude/analytics-core';
|
|
2
|
+
import { NodeConfig, NodeOptions } from '@amplitude/analytics-types';
|
|
3
|
+
export declare class AmplitudeNode extends AmplitudeCore<NodeConfig> {
|
|
4
|
+
init(apiKey: string, options?: NodeOptions): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the Amplitude SDK with your apiKey and optional configurations.
|
|
8
|
+
* This method must be called before any other operations.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const init: (apiKey: string, options?: NodeOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
15
|
+
/**
|
|
16
|
+
* Adds a new plugin.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const plugin = {...};
|
|
20
|
+
* add(plugin);
|
|
21
|
+
*
|
|
22
|
+
* // alternatively, this tracking method is awaitable
|
|
23
|
+
* await add(plugin).promise;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
27
|
+
/**
|
|
28
|
+
* Removes a plugin.
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* remove('myPlugin');
|
|
32
|
+
*
|
|
33
|
+
* // alternatively, this tracking method is awaitable
|
|
34
|
+
* await remove('myPlugin').promise;
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const remove: (pluginName: string) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
38
|
+
/**
|
|
39
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // event tracking with event type only
|
|
43
|
+
* track('Page Load');
|
|
44
|
+
*
|
|
45
|
+
* // event tracking with event type and additional event properties
|
|
46
|
+
* track('Page Load', { loadTime: 1000 });
|
|
47
|
+
*
|
|
48
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
49
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
50
|
+
*
|
|
51
|
+
* // alternatively, this tracking method is awaitable
|
|
52
|
+
* const result = await track('Page Load').promise;
|
|
53
|
+
* console.log(result.event); // {...}
|
|
54
|
+
* console.log(result.code); // 200
|
|
55
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const track: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
59
|
+
/**
|
|
60
|
+
* Alias for track()
|
|
61
|
+
*/
|
|
62
|
+
export declare const logEvent: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends an identify event containing user property operations
|
|
65
|
+
*
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const id = new Identify();
|
|
68
|
+
* id.set('colors', ['rose', 'gold']);
|
|
69
|
+
* identify(id);
|
|
70
|
+
*
|
|
71
|
+
* // alternatively, this tracking method is awaitable
|
|
72
|
+
* const result = await identify(id).promise;
|
|
73
|
+
* console.log(result.event); // {...}
|
|
74
|
+
* console.log(result.code); // 200
|
|
75
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
79
|
+
/**
|
|
80
|
+
* Sends a group identify event containing group property operations.
|
|
81
|
+
*
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const id = new Identify();
|
|
84
|
+
* id.set('skills', ['js', 'ts']);
|
|
85
|
+
* const groupType = 'org';
|
|
86
|
+
* const groupName = 'engineering';
|
|
87
|
+
* groupIdentify(groupType, groupName, id);
|
|
88
|
+
*
|
|
89
|
+
* // alternatively, this tracking method is awaitable
|
|
90
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
91
|
+
* console.log(result.event); // {...}
|
|
92
|
+
* console.log(result.code); // 200
|
|
93
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
97
|
+
export declare const setGroup: (groupType: string, groupName: string | string[]) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
98
|
+
/**
|
|
99
|
+
* Sends a revenue event containing revenue property operations.
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const rev = new Revenue();
|
|
103
|
+
* rev.setRevenue(100);
|
|
104
|
+
* revenue(rev);
|
|
105
|
+
*
|
|
106
|
+
* // alternatively, this tracking method is awaitable
|
|
107
|
+
* const result = await revenue(rev).promise;
|
|
108
|
+
* console.log(result.event); // {...}
|
|
109
|
+
* console.log(result.code); // 200
|
|
110
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare const revenue: (revenue: import("@amplitude/analytics-types").Revenue, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
114
|
+
/**
|
|
115
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
116
|
+
*
|
|
117
|
+
*```typescript
|
|
118
|
+
* // Stops tracking
|
|
119
|
+
* setOptOut(true);
|
|
120
|
+
*
|
|
121
|
+
* // Starts/resumes tracking
|
|
122
|
+
* setOptOut(false);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const setOptOut: (optOut: boolean) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Flush and send all the events which haven't been sent.
|
|
128
|
+
*
|
|
129
|
+
*```typescript
|
|
130
|
+
* // Send all the unsent events
|
|
131
|
+
* flush();
|
|
132
|
+
*
|
|
133
|
+
* // alternatively, this tracking method is awaitable
|
|
134
|
+
* await flush().promise;
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare const flush: () => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
138
|
+
//# sourceMappingURL=node-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-client.d.ts","sourceRoot":"","sources":["../../src/node-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8B,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIrE,qBAAa,aAAc,SAAQ,aAAa,CAAC,UAAU,CAAC;IACpD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAiBjD;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,4HAA0C,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,GAAG,8HAAyC,CAAC;AAE1D;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,6FAA4C,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,sTAA2C,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,QAAQ,sTAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,uPAA8C,CAAC;AAEpE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,wSAAmD,CAAC;AAC9E,eAAO,MAAM,QAAQ,iKAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,qPAA6C,CAAC;AAElE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,2BAAgC,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,2EAA2C,CAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { __assign, __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';
|
|
3
|
+
import { Context } from './plugins/context';
|
|
4
|
+
import { useNodeConfig } from './config';
|
|
5
|
+
var AmplitudeNode = /** @class */ (function (_super) {
|
|
6
|
+
__extends(AmplitudeNode, _super);
|
|
7
|
+
function AmplitudeNode() {
|
|
8
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
9
|
+
}
|
|
10
|
+
AmplitudeNode.prototype.init = function (apiKey, options) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12
|
+
var nodeOptions;
|
|
13
|
+
return __generator(this, function (_a) {
|
|
14
|
+
switch (_a.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
nodeOptions = useNodeConfig(apiKey, __assign({}, options));
|
|
17
|
+
return [4 /*yield*/, _super.prototype._init.call(this, nodeOptions)];
|
|
18
|
+
case 1:
|
|
19
|
+
_a.sent();
|
|
20
|
+
return [4 /*yield*/, this.add(new Context())];
|
|
21
|
+
case 2:
|
|
22
|
+
_a.sent();
|
|
23
|
+
return [4 /*yield*/, this.add(new Destination())];
|
|
24
|
+
case 3:
|
|
25
|
+
_a.sent();
|
|
26
|
+
// Set timeline ready for processing events
|
|
27
|
+
// Send existing events, which might be collected by track before init
|
|
28
|
+
this.timeline.isReady = true;
|
|
29
|
+
if (!this.config.optOut) {
|
|
30
|
+
this.timeline.scheduleApply(0);
|
|
31
|
+
}
|
|
32
|
+
return [2 /*return*/];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return AmplitudeNode;
|
|
38
|
+
}(AmplitudeCore));
|
|
39
|
+
export { AmplitudeNode };
|
|
40
|
+
var client = new AmplitudeNode();
|
|
41
|
+
/**
|
|
42
|
+
* Initializes the Amplitude SDK with your apiKey and optional configurations.
|
|
43
|
+
* This method must be called before any other operations.
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export var init = returnWrapper(client.init.bind(client));
|
|
50
|
+
/**
|
|
51
|
+
* Adds a new plugin.
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const plugin = {...};
|
|
55
|
+
* add(plugin);
|
|
56
|
+
*
|
|
57
|
+
* // alternatively, this tracking method is awaitable
|
|
58
|
+
* await add(plugin).promise;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export var add = returnWrapper(client.add.bind(client));
|
|
62
|
+
/**
|
|
63
|
+
* Removes a plugin.
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* remove('myPlugin');
|
|
67
|
+
*
|
|
68
|
+
* // alternatively, this tracking method is awaitable
|
|
69
|
+
* await remove('myPlugin').promise;
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export var remove = returnWrapper(client.remove.bind(client));
|
|
73
|
+
/**
|
|
74
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
75
|
+
*
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // event tracking with event type only
|
|
78
|
+
* track('Page Load');
|
|
79
|
+
*
|
|
80
|
+
* // event tracking with event type and additional event properties
|
|
81
|
+
* track('Page Load', { loadTime: 1000 });
|
|
82
|
+
*
|
|
83
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
84
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
85
|
+
*
|
|
86
|
+
* // alternatively, this tracking method is awaitable
|
|
87
|
+
* const result = await track('Page Load').promise;
|
|
88
|
+
* console.log(result.event); // {...}
|
|
89
|
+
* console.log(result.code); // 200
|
|
90
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export var track = returnWrapper(client.track.bind(client));
|
|
94
|
+
/**
|
|
95
|
+
* Alias for track()
|
|
96
|
+
*/
|
|
97
|
+
export var logEvent = returnWrapper(client.logEvent.bind(client));
|
|
98
|
+
/**
|
|
99
|
+
* Sends an identify event containing user property operations
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const id = new Identify();
|
|
103
|
+
* id.set('colors', ['rose', 'gold']);
|
|
104
|
+
* identify(id);
|
|
105
|
+
*
|
|
106
|
+
* // alternatively, this tracking method is awaitable
|
|
107
|
+
* const result = await identify(id).promise;
|
|
108
|
+
* console.log(result.event); // {...}
|
|
109
|
+
* console.log(result.code); // 200
|
|
110
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export var identify = returnWrapper(client.identify.bind(client));
|
|
114
|
+
/**
|
|
115
|
+
* Sends a group identify event containing group property operations.
|
|
116
|
+
*
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const id = new Identify();
|
|
119
|
+
* id.set('skills', ['js', 'ts']);
|
|
120
|
+
* const groupType = 'org';
|
|
121
|
+
* const groupName = 'engineering';
|
|
122
|
+
* groupIdentify(groupType, groupName, id);
|
|
123
|
+
*
|
|
124
|
+
* // alternatively, this tracking method is awaitable
|
|
125
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
126
|
+
* console.log(result.event); // {...}
|
|
127
|
+
* console.log(result.code); // 200
|
|
128
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export var groupIdentify = returnWrapper(client.groupIdentify.bind(client));
|
|
132
|
+
export var setGroup = returnWrapper(client.setGroup.bind(client));
|
|
133
|
+
/**
|
|
134
|
+
* Sends a revenue event containing revenue property operations.
|
|
135
|
+
*
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const rev = new Revenue();
|
|
138
|
+
* rev.setRevenue(100);
|
|
139
|
+
* revenue(rev);
|
|
140
|
+
*
|
|
141
|
+
* // alternatively, this tracking method is awaitable
|
|
142
|
+
* const result = await revenue(rev).promise;
|
|
143
|
+
* console.log(result.event); // {...}
|
|
144
|
+
* console.log(result.code); // 200
|
|
145
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export var revenue = returnWrapper(client.revenue.bind(client));
|
|
149
|
+
/**
|
|
150
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
151
|
+
*
|
|
152
|
+
*```typescript
|
|
153
|
+
* // Stops tracking
|
|
154
|
+
* setOptOut(true);
|
|
155
|
+
*
|
|
156
|
+
* // Starts/resumes tracking
|
|
157
|
+
* setOptOut(false);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export var setOptOut = client.setOptOut.bind(client);
|
|
161
|
+
/**
|
|
162
|
+
* Flush and send all the events which haven't been sent.
|
|
163
|
+
*
|
|
164
|
+
*```typescript
|
|
165
|
+
* // Send all the unsent events
|
|
166
|
+
* flush();
|
|
167
|
+
*
|
|
168
|
+
* // alternatively, this tracking method is awaitable
|
|
169
|
+
* await flush().promise;
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export var flush = returnWrapper(client.flush.bind(client));
|
|
173
|
+
//# sourceMappingURL=node-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-client.js","sourceRoot":"","sources":["../../src/node-client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAEtF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;IAAmC,iCAAyB;IAA5D;;IAkBA,CAAC;IAjBO,4BAAI,GAAV,UAAW,MAAc,EAAE,OAAqB;;;;;;wBACxC,WAAW,GAAG,aAAa,CAAC,MAAM,eACnC,OAAO,EACV,CAAC;wBAEH,qBAAM,iBAAM,KAAK,YAAC,WAAW,CAAC,EAAA;;wBAA9B,SAA8B,CAAC;wBAE/B,qBAAM,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,EAAA;;wBAA7B,SAA6B,CAAC;wBAC9B,qBAAM,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC,EAAA;;wBAAjC,SAAiC,CAAC;wBAElC,2CAA2C;wBAC3C,sEAAsE;wBACtE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;wBAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;4BACvB,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;yBAChC;;;;;K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AAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';\nimport { NodeConfig, NodeOptions } from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useNodeConfig } from './config';\n\nexport class AmplitudeNode extends AmplitudeCore<NodeConfig> {\n async init(apiKey: string, options?: NodeOptions) {\n const nodeOptions = useNodeConfig(apiKey, {\n ...options,\n });\n\n await super._init(nodeOptions);\n\n await this.add(new Context());\n await this.add(new Destination());\n\n // Set timeline ready for processing events\n // Send existing events, which might be collected by track before init\n this.timeline.isReady = true;\n if (!this.config.optOut) {\n this.timeline.scheduleApply(0);\n }\n }\n}\n\nconst client = new AmplitudeNode();\n\n/**\n * Initializes the Amplitude SDK with your apiKey and optional configurations.\n * This method must be called before any other operations.\n *\n * ```typescript\n * await init(API_KEY, USER_ID, options).promise;\n * ```\n */\nexport const init = returnWrapper(client.init.bind(client));\n\n/**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {...};\n * add(plugin);\n *\n * // alternatively, this tracking method is awaitable\n * await add(plugin).promise;\n * ```\n */\nexport const add = returnWrapper(client.add.bind(client));\n\n/**\n * Removes a plugin.\n *\n * ```typescript\n * remove('myPlugin');\n *\n * // alternatively, this tracking method is awaitable\n * await remove('myPlugin').promise;\n * ```\n */\nexport const remove = returnWrapper(client.remove.bind(client));\n\n/**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const track = returnWrapper(client.track.bind(client));\n\n/**\n * Alias for track()\n */\nexport const logEvent = returnWrapper(client.logEvent.bind(client));\n\n/**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const identify = returnWrapper(client.identify.bind(client));\n\n/**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const groupIdentify = returnWrapper(client.groupIdentify.bind(client));\nexport const setGroup = returnWrapper(client.setGroup.bind(client));\n\n/**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const revenue = returnWrapper(client.revenue.bind(client));\n\n/**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\nexport const setOptOut = client.setOptOut.bind(client);\n\n/**\n * Flush and send all the events which haven't been sent.\n *\n *```typescript\n * // Send all the unsent events\n * flush();\n *\n * // alternatively, this tracking method is awaitable\n * await flush().promise;\n * ```\n */\nexport const flush = returnWrapper(client.flush.bind(client));\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BeforePlugin, NodeConfig, Event, PluginType } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class Context implements BeforePlugin {
|
|
3
|
+
name: string;
|
|
4
|
+
type: PluginType.BEFORE;
|
|
5
|
+
config: NodeConfig;
|
|
6
|
+
eventId: number;
|
|
7
|
+
library: string;
|
|
8
|
+
setup(config: NodeConfig): Promise<undefined>;
|
|
9
|
+
execute(context: Event): Promise<Event>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugins/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAIzF,qBAAa,OAAQ,YAAW,YAAY;IAC1C,IAAI,SAAa;IACjB,IAAI,oBAA8B;IAKlC,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,SAAK;IACZ,OAAO,SAAkC;IAEzC,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAK7C,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAexC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { PluginType } from '@amplitude/analytics-types';
|
|
3
|
+
import { UUID } from '@amplitude/analytics-core';
|
|
4
|
+
import { VERSION } from '../version';
|
|
5
|
+
var Context = /** @class */ (function () {
|
|
6
|
+
function Context() {
|
|
7
|
+
this.name = 'context';
|
|
8
|
+
this.type = PluginType.BEFORE;
|
|
9
|
+
this.eventId = 0;
|
|
10
|
+
this.library = "amplitude-node-ts/".concat(VERSION);
|
|
11
|
+
}
|
|
12
|
+
Context.prototype.setup = function (config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
return Promise.resolve(undefined);
|
|
15
|
+
};
|
|
16
|
+
Context.prototype.execute = function (context) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
return new Promise(function (resolve) {
|
|
19
|
+
var time = new Date().getTime();
|
|
20
|
+
var contextEvent = __assign(__assign({ time: time, insert_id: UUID(), plan: _this.config.plan }, context), { event_id: _this.eventId++, library: _this.library });
|
|
21
|
+
return resolve(contextEvent);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
return Context;
|
|
25
|
+
}());
|
|
26
|
+
export { Context };
|
|
27
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/plugins/context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmC,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;IAAA;QACE,SAAI,GAAG,SAAS,CAAC;QACjB,SAAI,GAAG,UAAU,CAAC,MAAe,CAAC;QAMlC,YAAO,GAAG,CAAC,CAAC;QACZ,YAAO,GAAG,4BAAqB,OAAO,CAAE,CAAC;IAsB3C,CAAC;IApBC,uBAAK,GAAL,UAAM,MAAkB;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,yBAAO,GAAP,UAAQ,OAAc;QAAtB,iBAcC;QAbC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,IAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;YAElC,IAAM,YAAY,uBAChB,IAAI,MAAA,EACJ,SAAS,EAAE,IAAI,EAAE,EACjB,IAAI,EAAE,KAAI,CAAC,MAAM,CAAC,IAAI,IACnB,OAAO,KACV,QAAQ,EAAE,KAAI,CAAC,OAAO,EAAE,EACxB,OAAO,EAAE,KAAI,CAAC,OAAO,GACtB,CAAC;YACF,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,cAAC;AAAD,CAAC,AA/BD,IA+BC","sourcesContent":["import { BeforePlugin, NodeConfig, Event, PluginType } from '@amplitude/analytics-types';\nimport { UUID } from '@amplitude/analytics-core';\nimport { VERSION } from '../version';\n\nexport class Context implements BeforePlugin {\n name = 'context';\n type = PluginType.BEFORE as const;\n\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: NodeConfig;\n eventId = 0;\n library = `amplitude-node-ts/${VERSION}`;\n\n setup(config: NodeConfig): Promise<undefined> {\n this.config = config;\n return Promise.resolve(undefined);\n }\n\n execute(context: Event): Promise<Event> {\n return new Promise((resolve) => {\n const time = new Date().getTime();\n\n const contextEvent: Event = {\n time,\n insert_id: UUID(),\n plan: this.config.plan,\n ...context,\n event_id: this.eventId++,\n library: this.library,\n };\n return resolve(contextEvent);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
2
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
3
|
+
export declare class Http extends BaseTransport implements Transport {
|
|
4
|
+
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC1D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAiDpE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
import * as https from 'https';
|
|
5
|
+
var Http = /** @class */ (function (_super) {
|
|
6
|
+
__extends(Http, _super);
|
|
7
|
+
function Http() {
|
|
8
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
9
|
+
}
|
|
10
|
+
Http.prototype.send = function (serverUrl, payload) {
|
|
11
|
+
var _this = this;
|
|
12
|
+
var protocol;
|
|
13
|
+
if (serverUrl.startsWith('http://')) {
|
|
14
|
+
protocol = http;
|
|
15
|
+
}
|
|
16
|
+
else if (serverUrl.startsWith('https://')) {
|
|
17
|
+
protocol = https;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new Error('Invalid server url');
|
|
21
|
+
}
|
|
22
|
+
var url = new URL(serverUrl);
|
|
23
|
+
var requestPayload = JSON.stringify(payload);
|
|
24
|
+
var options = {
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
'Content-Length': Buffer.byteLength(requestPayload),
|
|
28
|
+
},
|
|
29
|
+
hostname: url.hostname,
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: url.pathname,
|
|
32
|
+
port: url.port,
|
|
33
|
+
protocol: url.protocol,
|
|
34
|
+
};
|
|
35
|
+
return new Promise(function (resolve) {
|
|
36
|
+
var req = protocol.request(options, function (res) {
|
|
37
|
+
res.setEncoding('utf8');
|
|
38
|
+
var responsePayload = '';
|
|
39
|
+
res.on('data', function (chunk) {
|
|
40
|
+
responsePayload += chunk;
|
|
41
|
+
});
|
|
42
|
+
res.on('end', function () {
|
|
43
|
+
if (res.complete && responsePayload.length > 0) {
|
|
44
|
+
try {
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
46
|
+
var parsedResponsePayload = JSON.parse(responsePayload);
|
|
47
|
+
var result = _this.buildResponse(parsedResponsePayload);
|
|
48
|
+
resolve(result);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
catch (_a) {
|
|
52
|
+
resolve(null);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
req.on('error', _this.buildResponse.bind(_this));
|
|
58
|
+
req.end(requestPayload);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return Http;
|
|
62
|
+
}(BaseTransport));
|
|
63
|
+
export { Http };
|
|
64
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;IAA0B,wBAAa;IAAvC;;IAkDA,CAAC;IAjDC,mBAAI,GAAJ,UAAK,SAAiB,EAAE,OAAgB;QAAxC,iBAgDC;QA/CC,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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CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAC;YAC/C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAlDD,CAA0B,aAAa,GAkDtC","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport { BaseTransport } from '@amplitude/analytics-core';\nimport * as http from 'http';\nimport * as https from 'https';\n\nexport class Http extends BaseTransport implements Transport {\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 const req = protocol.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n\n res.on('end', () => {\n if (res.complete && responsePayload.length > 0) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', this.buildResponse.bind(this));\n req.end(requestPayload);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["export const VERSION = '0.3.4';\n"]}
|