@veridia/node-sdk 1.0.11 → 1.0.13
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/dist/cjs/client.d.ts +1 -1
- package/dist/cjs/client.js +38 -60
- package/dist/cjs/types.d.ts +6 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +38 -60
- package/dist/esm/types.d.ts +6 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +4 -4
package/dist/cjs/client.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IdentifierPayload, IdentifyPayload, TrackPayload, VeridiaClientOptions } from './types.js';
|
|
2
2
|
export declare class VeridiaClient {
|
|
3
|
-
private readonly options;
|
|
4
3
|
private trackBuffer;
|
|
5
4
|
private identifyBuffer;
|
|
6
5
|
private flushTimer?;
|
|
7
6
|
private readonly logger;
|
|
7
|
+
private readonly credentials;
|
|
8
8
|
private readonly baseUrl;
|
|
9
9
|
private readonly region;
|
|
10
10
|
private readonly autoFlush;
|
package/dist/cjs/client.js
CHANGED
|
@@ -1,45 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.VeridiaClient = void 0;
|
|
37
|
-
const
|
|
4
|
+
const sha256_js_1 = require("@aws-crypto/sha256-js");
|
|
5
|
+
const signature_v4_1 = require("@aws-sdk/signature-v4");
|
|
38
6
|
const http_js_1 = require("./http.js");
|
|
39
7
|
const version_js_1 = require("./version.js");
|
|
40
8
|
class VeridiaClient {
|
|
41
9
|
constructor(options) {
|
|
42
|
-
this.options = options;
|
|
43
10
|
this.trackBuffer = [];
|
|
44
11
|
this.identifyBuffer = [];
|
|
45
12
|
this.baseUrl = options.endpoint ?? 'https://api.veridia.io/v1';
|
|
@@ -52,6 +19,7 @@ class VeridiaClient {
|
|
|
52
19
|
this.timeoutMsGetUserSegments = options.timeoutMsGetUserSegments ?? 5000;
|
|
53
20
|
this.timeoutMsFlush = options.timeoutMsFlush ?? 30000;
|
|
54
21
|
this.logger = options.logger;
|
|
22
|
+
this.credentials = options.credentials;
|
|
55
23
|
}
|
|
56
24
|
/**
|
|
57
25
|
* Queues a user identification update to be flushed in batch.
|
|
@@ -103,21 +71,27 @@ class VeridiaClient {
|
|
|
103
71
|
async getUserSegments(identifierType, identifierId, noSegmentsOnError = true) {
|
|
104
72
|
try {
|
|
105
73
|
const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
|
|
106
|
-
const url = `${this.baseUrl}${path}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
path,
|
|
110
|
-
method: 'GET',
|
|
111
|
-
service: 'segments',
|
|
74
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
75
|
+
const signer = new signature_v4_1.SignatureV4({
|
|
76
|
+
credentials: this.credentials,
|
|
112
77
|
region: this.region,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
service: 'segments',
|
|
79
|
+
sha256: sha256_js_1.Sha256,
|
|
80
|
+
});
|
|
81
|
+
const signed = await signer.sign({
|
|
82
|
+
protocol: url.protocol,
|
|
83
|
+
hostname: url.hostname,
|
|
84
|
+
port: url.port !== '' ? +url.port : undefined,
|
|
85
|
+
path: url.pathname,
|
|
86
|
+
query: Object.fromEntries(url.searchParams.entries()),
|
|
87
|
+
method: 'GET',
|
|
88
|
+
headers: { Host: url.host, 'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}` },
|
|
89
|
+
});
|
|
116
90
|
const controller = new AbortController();
|
|
117
91
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMsGetUserSegments);
|
|
118
|
-
const res = await (0, http_js_1.httpFetch)(url, {
|
|
119
|
-
method:
|
|
120
|
-
headers:
|
|
92
|
+
const res = await (0, http_js_1.httpFetch)(url.toString(), {
|
|
93
|
+
method: signed.method,
|
|
94
|
+
headers: signed.headers,
|
|
121
95
|
signal: controller.signal,
|
|
122
96
|
}).finally(() => clearTimeout(timeout));
|
|
123
97
|
if (!res.ok) {
|
|
@@ -188,30 +162,34 @@ class VeridiaClient {
|
|
|
188
162
|
const batch = [...buffer];
|
|
189
163
|
buffer.length = 0; // clear buffer safely
|
|
190
164
|
const urlObj = new URL(this.baseUrl + '/' + service);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
165
|
+
const signer = new signature_v4_1.SignatureV4({
|
|
166
|
+
credentials: this.credentials,
|
|
167
|
+
region: this.region,
|
|
168
|
+
service,
|
|
169
|
+
sha256: sha256_js_1.Sha256,
|
|
170
|
+
});
|
|
171
|
+
const signed = await signer.sign({
|
|
172
|
+
protocol: urlObj.protocol,
|
|
173
|
+
hostname: urlObj.hostname,
|
|
174
|
+
port: urlObj.port !== '' ? +urlObj.port : undefined,
|
|
175
|
+
path: urlObj.pathname,
|
|
176
|
+
query: Object.fromEntries(urlObj.searchParams.entries()),
|
|
194
177
|
method: 'POST',
|
|
195
178
|
headers: {
|
|
179
|
+
Host: urlObj.host,
|
|
196
180
|
'Content-Type': 'application/json',
|
|
197
181
|
'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}`,
|
|
198
182
|
},
|
|
199
183
|
body: JSON.stringify({ [service]: batch }),
|
|
200
|
-
|
|
201
|
-
region: this.region,
|
|
202
|
-
};
|
|
203
|
-
aws4.sign(opts, this.options);
|
|
204
|
-
const signedOpts = {
|
|
205
|
-
method: opts.method,
|
|
206
|
-
headers: opts.headers,
|
|
207
|
-
body: opts.body,
|
|
208
|
-
};
|
|
184
|
+
});
|
|
209
185
|
for (let attempt = 1; attempt <= this.retries; attempt++) {
|
|
210
186
|
try {
|
|
211
187
|
const controller = new AbortController();
|
|
212
188
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMsFlush);
|
|
213
189
|
const res = await (0, http_js_1.httpFetch)(urlObj.toString(), {
|
|
214
|
-
|
|
190
|
+
method: signed.method,
|
|
191
|
+
headers: signed.headers,
|
|
192
|
+
body: signed.body,
|
|
215
193
|
signal: controller.signal,
|
|
216
194
|
}).finally(() => clearTimeout(timeout));
|
|
217
195
|
if (!res.ok) {
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -27,9 +27,14 @@ export type VeridiaLogger = {
|
|
|
27
27
|
*/
|
|
28
28
|
error: (service: string, message: string, context?: VeridiaLogContext) => void;
|
|
29
29
|
};
|
|
30
|
-
export type
|
|
30
|
+
export type VeridiaClientCredentials = {
|
|
31
31
|
accessKeyId: string;
|
|
32
32
|
secretAccessKey: string;
|
|
33
|
+
sessionToken?: string;
|
|
34
|
+
expiration?: Date;
|
|
35
|
+
};
|
|
36
|
+
export type VeridiaClientOptions = {
|
|
37
|
+
credentials: VeridiaClientCredentials;
|
|
33
38
|
endpoint?: string;
|
|
34
39
|
region?: string;
|
|
35
40
|
autoFlush?: boolean;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.13";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IdentifierPayload, IdentifyPayload, TrackPayload, VeridiaClientOptions } from './types.js';
|
|
2
2
|
export declare class VeridiaClient {
|
|
3
|
-
private readonly options;
|
|
4
3
|
private trackBuffer;
|
|
5
4
|
private identifyBuffer;
|
|
6
5
|
private flushTimer?;
|
|
7
6
|
private readonly logger;
|
|
7
|
+
private readonly credentials;
|
|
8
8
|
private readonly baseUrl;
|
|
9
9
|
private readonly region;
|
|
10
10
|
private readonly autoFlush;
|
package/dist/esm/client.js
CHANGED
|
@@ -1,45 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.VeridiaClient = void 0;
|
|
37
|
-
const
|
|
4
|
+
const sha256_js_1 = require("@aws-crypto/sha256-js");
|
|
5
|
+
const signature_v4_1 = require("@aws-sdk/signature-v4");
|
|
38
6
|
const http_js_1 = require("./http.js");
|
|
39
7
|
const version_js_1 = require("./version.js");
|
|
40
8
|
class VeridiaClient {
|
|
41
9
|
constructor(options) {
|
|
42
|
-
this.options = options;
|
|
43
10
|
this.trackBuffer = [];
|
|
44
11
|
this.identifyBuffer = [];
|
|
45
12
|
this.baseUrl = options.endpoint ?? 'https://api.veridia.io/v1';
|
|
@@ -52,6 +19,7 @@ class VeridiaClient {
|
|
|
52
19
|
this.timeoutMsGetUserSegments = options.timeoutMsGetUserSegments ?? 5_000;
|
|
53
20
|
this.timeoutMsFlush = options.timeoutMsFlush ?? 30_000;
|
|
54
21
|
this.logger = options.logger;
|
|
22
|
+
this.credentials = options.credentials;
|
|
55
23
|
}
|
|
56
24
|
/**
|
|
57
25
|
* Queues a user identification update to be flushed in batch.
|
|
@@ -103,21 +71,27 @@ class VeridiaClient {
|
|
|
103
71
|
async getUserSegments(identifierType, identifierId, noSegmentsOnError = true) {
|
|
104
72
|
try {
|
|
105
73
|
const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
|
|
106
|
-
const url = `${this.baseUrl}${path}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
path,
|
|
110
|
-
method: 'GET',
|
|
111
|
-
service: 'segments',
|
|
74
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
75
|
+
const signer = new signature_v4_1.SignatureV4({
|
|
76
|
+
credentials: this.credentials,
|
|
112
77
|
region: this.region,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
service: 'segments',
|
|
79
|
+
sha256: sha256_js_1.Sha256,
|
|
80
|
+
});
|
|
81
|
+
const signed = await signer.sign({
|
|
82
|
+
protocol: url.protocol,
|
|
83
|
+
hostname: url.hostname,
|
|
84
|
+
port: url.port !== '' ? +url.port : undefined,
|
|
85
|
+
path: url.pathname,
|
|
86
|
+
query: Object.fromEntries(url.searchParams.entries()),
|
|
87
|
+
method: 'GET',
|
|
88
|
+
headers: { Host: url.host, 'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}` },
|
|
89
|
+
});
|
|
116
90
|
const controller = new AbortController();
|
|
117
91
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMsGetUserSegments);
|
|
118
|
-
const res = await (0, http_js_1.httpFetch)(url, {
|
|
119
|
-
method:
|
|
120
|
-
headers:
|
|
92
|
+
const res = await (0, http_js_1.httpFetch)(url.toString(), {
|
|
93
|
+
method: signed.method,
|
|
94
|
+
headers: signed.headers,
|
|
121
95
|
signal: controller.signal,
|
|
122
96
|
}).finally(() => clearTimeout(timeout));
|
|
123
97
|
if (!res.ok) {
|
|
@@ -188,30 +162,34 @@ class VeridiaClient {
|
|
|
188
162
|
const batch = [...buffer];
|
|
189
163
|
buffer.length = 0; // clear buffer safely
|
|
190
164
|
const urlObj = new URL(this.baseUrl + '/' + service);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
165
|
+
const signer = new signature_v4_1.SignatureV4({
|
|
166
|
+
credentials: this.credentials,
|
|
167
|
+
region: this.region,
|
|
168
|
+
service,
|
|
169
|
+
sha256: sha256_js_1.Sha256,
|
|
170
|
+
});
|
|
171
|
+
const signed = await signer.sign({
|
|
172
|
+
protocol: urlObj.protocol,
|
|
173
|
+
hostname: urlObj.hostname,
|
|
174
|
+
port: urlObj.port !== '' ? +urlObj.port : undefined,
|
|
175
|
+
path: urlObj.pathname,
|
|
176
|
+
query: Object.fromEntries(urlObj.searchParams.entries()),
|
|
194
177
|
method: 'POST',
|
|
195
178
|
headers: {
|
|
179
|
+
Host: urlObj.host,
|
|
196
180
|
'Content-Type': 'application/json',
|
|
197
181
|
'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}`,
|
|
198
182
|
},
|
|
199
183
|
body: JSON.stringify({ [service]: batch }),
|
|
200
|
-
|
|
201
|
-
region: this.region,
|
|
202
|
-
};
|
|
203
|
-
aws4.sign(opts, this.options);
|
|
204
|
-
const signedOpts = {
|
|
205
|
-
method: opts.method,
|
|
206
|
-
headers: opts.headers,
|
|
207
|
-
body: opts.body,
|
|
208
|
-
};
|
|
184
|
+
});
|
|
209
185
|
for (let attempt = 1; attempt <= this.retries; attempt++) {
|
|
210
186
|
try {
|
|
211
187
|
const controller = new AbortController();
|
|
212
188
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMsFlush);
|
|
213
189
|
const res = await (0, http_js_1.httpFetch)(urlObj.toString(), {
|
|
214
|
-
|
|
190
|
+
method: signed.method,
|
|
191
|
+
headers: signed.headers,
|
|
192
|
+
body: signed.body,
|
|
215
193
|
signal: controller.signal,
|
|
216
194
|
}).finally(() => clearTimeout(timeout));
|
|
217
195
|
if (!res.ok) {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -27,9 +27,14 @@ export type VeridiaLogger = {
|
|
|
27
27
|
*/
|
|
28
28
|
error: (service: string, message: string, context?: VeridiaLogContext) => void;
|
|
29
29
|
};
|
|
30
|
-
export type
|
|
30
|
+
export type VeridiaClientCredentials = {
|
|
31
31
|
accessKeyId: string;
|
|
32
32
|
secretAccessKey: string;
|
|
33
|
+
sessionToken?: string;
|
|
34
|
+
expiration?: Date;
|
|
35
|
+
};
|
|
36
|
+
export type VeridiaClientOptions = {
|
|
37
|
+
credentials: VeridiaClientCredentials;
|
|
33
38
|
endpoint?: string;
|
|
34
39
|
region?: string;
|
|
35
40
|
autoFlush?: boolean;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.13";
|
package/dist/esm/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veridia/node-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"prepare": "husky install"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"node-fetch": "^3.3.2",
|
|
27
|
+
"@aws-sdk/signature-v4": "^3.374.0",
|
|
28
|
+
"@aws-crypto/sha256-js": "^5.2.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@types/aws4": "^1.11.6",
|
|
31
31
|
"@types/node": "^24.9.2",
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
33
33
|
"@typescript-eslint/parser": "^8.46.2",
|