@ninetailed/experience.js-node 2.2.9-beta.0 → 3.0.1-beta.3
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/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-beta.3",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"node-fetch": "^3.0.0",
|
|
6
6
|
"uuid": "^8.3.2",
|
|
7
|
-
"@ninetailed/experience.js-shared": "
|
|
7
|
+
"@ninetailed/experience.js-shared": "3.0.1-beta.3",
|
|
8
8
|
"ts-toolbelt": "^9.6.0",
|
|
9
|
+
"diary": "^0.3.1",
|
|
10
|
+
"zod": "^3.18.0",
|
|
9
11
|
"locale-enum": "^1.1.1",
|
|
10
12
|
"i18n-iso-countries": "^7.3.0"
|
|
11
13
|
},
|
|
@@ -2,6 +2,7 @@ import { Event, IdentifyEvent, Traits } from '@ninetailed/experience.js-shared';
|
|
|
2
2
|
declare type NinetailedAPIClientOptions = {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
url?: string;
|
|
5
|
+
environment?: string;
|
|
5
6
|
};
|
|
6
7
|
declare type SendEventOptions = {
|
|
7
8
|
anonymousId?: string;
|
|
@@ -10,9 +11,14 @@ declare type SendEventOptions = {
|
|
|
10
11
|
export declare class NinetailedAPIClient {
|
|
11
12
|
private readonly apiKey;
|
|
12
13
|
private readonly url;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
private readonly environmentSlug;
|
|
15
|
+
constructor({ apiKey, url, environment }: NinetailedAPIClientOptions);
|
|
16
|
+
ingestEvents(events: (Event & {
|
|
17
|
+
anonymousId: string;
|
|
18
|
+
})[]): Promise<void>;
|
|
19
|
+
createIdentifyEvent(userId: string, traits: Traits, options?: SendEventOptions): IdentifyEvent & {
|
|
20
|
+
anonymousId: string;
|
|
21
|
+
};
|
|
16
22
|
sendIdentifyEvent(userId: string, traits: Traits, options?: SendEventOptions): Promise<void>;
|
|
17
23
|
private buildRequestContext;
|
|
18
24
|
}
|
package/src/lib/Client/Client.js
CHANGED
|
@@ -19,18 +19,19 @@ function fetch(...args) {
|
|
|
19
19
|
return fetch(...args);
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
const BASE_URL = 'https://
|
|
22
|
+
const BASE_URL = 'https://experience.ninetailed.co';
|
|
23
23
|
class NinetailedAPIClient {
|
|
24
|
-
constructor({ apiKey, url = BASE_URL }) {
|
|
24
|
+
constructor({ apiKey, url = BASE_URL, environment = 'main' }) {
|
|
25
25
|
this.apiKey = apiKey;
|
|
26
26
|
this.url = url;
|
|
27
|
+
this.environmentSlug = environment;
|
|
27
28
|
}
|
|
28
29
|
ingestEvents(events) {
|
|
29
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
31
|
const payload = {
|
|
31
32
|
events,
|
|
32
33
|
};
|
|
33
|
-
const response = yield fetch(`${this.url}/events`, {
|
|
34
|
+
const response = yield fetch(`${this.url}/v2/organizations/${this.apiKey}/environments/${this.environmentSlug}/events`, {
|
|
34
35
|
method: 'POST',
|
|
35
36
|
headers: {
|
|
36
37
|
'Content-Type': 'application/json',
|
|
@@ -38,7 +39,11 @@ class NinetailedAPIClient {
|
|
|
38
39
|
},
|
|
39
40
|
body: JSON.stringify(payload),
|
|
40
41
|
});
|
|
41
|
-
const
|
|
42
|
+
const parsedResponse = experience_js_shared_1.UpsertManyProfilesResponse.safeParse(yield response.json());
|
|
43
|
+
if (!parsedResponse.success) {
|
|
44
|
+
throw new Error('Got invalid response from server.');
|
|
45
|
+
}
|
|
46
|
+
const { message, error } = parsedResponse.data;
|
|
42
47
|
if (error) {
|
|
43
48
|
throw new Error(message);
|
|
44
49
|
}
|
|
@@ -48,14 +53,13 @@ class NinetailedAPIClient {
|
|
|
48
53
|
const messageId = (0, uuid_1.v4)();
|
|
49
54
|
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || userId;
|
|
50
55
|
const timestamp = (options === null || options === void 0 ? void 0 : options.timestamp) || Date.now();
|
|
51
|
-
return (0, experience_js_shared_1.buildIdentifyEvent)({
|
|
56
|
+
return Object.assign(Object.assign({}, (0, experience_js_shared_1.buildIdentifyEvent)({
|
|
52
57
|
messageId,
|
|
53
58
|
ctx: this.buildRequestContext(),
|
|
54
59
|
userId,
|
|
55
60
|
traits,
|
|
56
|
-
anonymousId,
|
|
57
61
|
timestamp,
|
|
58
|
-
});
|
|
62
|
+
})), { anonymousId });
|
|
59
63
|
}
|
|
60
64
|
sendIdentifyEvent(userId, traits, options) {
|
|
61
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../../../packages/nodejs/src/lib/Client/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAkC;AAClC,2EAQ0C;AAE1C,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC,CAAC;AAE/E,SAAe,KAAK,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../../../packages/nodejs/src/lib/Client/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAkC;AAClC,2EAQ0C;AAE1C,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC,CAAC;AAE/E,SAAe,KAAK,CAAC,GAAG,IAAW;;QACjC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC;QAC9D,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACxB,CAAC;CAAA;AAaD,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAEpD,MAAa,mBAAmB;IAK9B,YAAY,EAAE,MAAM,EAAE,GAAG,GAAG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AC;QACnD,uCACK,IAAA,yCAAkB,EAAC;YACpB,SAAS;YACT,GAAG,EAAE,IAAI,CAAC,mBAAmB,EAAE;YAC/B,MAAM;YACN,MAAM;YACN,SAAS;SACV,CAAC,KACF,WAAW,IACX;IACJ,CAAC;IAEY,iBAAiB,CAC5B,MAAc,EACd,MAAc,EACd,OAA0B;;YAE1B,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAChE,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACnC,CAAC;KAAA;IAEO,mBAAmB;QACzB,MAAM,GAAG,GAA6B;YACpC,GAAG,EAAE,EAAE;YACP,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;SACd,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA1ED,kDA0EC"}
|
package/src/lib/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { NinetailedAPIClient } from './Client';
|
|
|
2
2
|
export declare type Options = {
|
|
3
3
|
url?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const ninetailed: (apiKey: string, options?: Options) => NinetailedAPIClient;
|
|
5
|
+
export declare const ninetailed: (apiKey: string, options?: Options | undefined) => NinetailedAPIClient;
|
|
6
6
|
export default ninetailed;
|