@veridia/node-sdk 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,8 +29,10 @@ yarn add @veridia/node-sdk
29
29
  import { VeridiaClient } from '@veridia/node-sdk';
30
30
 
31
31
  const client = new VeridiaClient({
32
- accessKeyId: 'your-access-key-id',
33
- secretAccessKey: 'your-secret-access-key',
32
+ credentials: {
33
+ accessKeyId: 'your-access-key-id',
34
+ secretAccessKey: 'your-secret-access-key',
35
+ },
34
36
  logger: {
35
37
  error: (service, msg, ctx) => console.error(`[ERROR] ${service}: ${msg}`, ctx),
36
38
  warn: (service, msg, ctx) => console.warn(`[WARN] ${service}: ${msg}`, ctx),
@@ -45,8 +47,10 @@ const client = new VeridiaClient({
45
47
  const { VeridiaClient } = require('@veridia/node-sdk');
46
48
 
47
49
  const client = new VeridiaClient({
48
- accessKeyId: 'your-access-key-id',
49
- secretAccessKey: 'your-secret-access-key',
50
+ credentials: {
51
+ accessKeyId: 'your-access-key-id',
52
+ secretAccessKey: 'your-secret-access-key',
53
+ },
50
54
  logger: { error: console.error },
51
55
  });
52
56
  ```
@@ -186,8 +190,10 @@ import pino from 'pino';
186
190
  const log = pino();
187
191
 
188
192
  const client = new VeridiaClient({
189
- accessKeyId: '...',
190
- secretAccessKey: '...',
193
+ credentials: {
194
+ accessKeyId: 'your-access-key-id',
195
+ secretAccessKey: 'your-secret-access-key',
196
+ },
191
197
  logger: {
192
198
  info: (s, m, c) => log.info({ service: s, context: c }, m),
193
199
  warn: (s, m, c) => log.warn({ service: s, context: c }, m),
@@ -211,8 +217,10 @@ Hover over any method in VS Code to see inline descriptions and parameter hints.
211
217
  import { VeridiaClient } from '@veridia/node-sdk';
212
218
 
213
219
  const client = new VeridiaClient({
214
- accessKeyId: 'test',
215
- secretAccessKey: 'test',
220
+ credentials: {
221
+ accessKeyId: 'your-access-key-id',
222
+ secretAccessKey: 'your-secret-access-key',
223
+ },
216
224
  logger: { error: console.error },
217
225
  });
218
226
 
@@ -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;
@@ -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 aws4 = __importStar(require("aws4"));
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.
@@ -104,20 +72,26 @@ class VeridiaClient {
104
72
  try {
105
73
  const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
106
74
  const url = new URL(`${this.baseUrl}${path}`);
107
- const req = {
108
- host: url.host,
75
+ const signer = new signature_v4_1.SignatureV4({
76
+ credentials: this.credentials,
77
+ region: this.region,
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,
109
85
  path: url.pathname,
86
+ query: Object.fromEntries(url.searchParams.entries()),
110
87
  method: 'GET',
111
- service: 'segments',
112
- region: this.region,
113
- headers: { 'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}` },
114
- };
115
- aws4.sign(req, this.options);
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
92
  const res = await (0, http_js_1.httpFetch)(url.toString(), {
119
- method: req.method,
120
- headers: req.headers,
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 opts = {
192
- host: urlObj.host,
193
- path: urlObj.pathname + urlObj.search,
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
- service,
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
- ...signedOpts,
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) {
@@ -27,9 +27,14 @@ export type VeridiaLogger = {
27
27
  */
28
28
  error: (service: string, message: string, context?: VeridiaLogContext) => void;
29
29
  };
30
- export type VeridiaClientOptions = {
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;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.12";
1
+ export declare const SDK_VERSION = "1.0.14";
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.0.12';
4
+ exports.SDK_VERSION = '1.0.14';
5
5
  //# sourceMappingURL=version.js.map
@@ -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;
@@ -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 aws4 = __importStar(require("aws4"));
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.
@@ -104,20 +72,26 @@ class VeridiaClient {
104
72
  try {
105
73
  const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
106
74
  const url = new URL(`${this.baseUrl}${path}`);
107
- const req = {
108
- host: url.host,
75
+ const signer = new signature_v4_1.SignatureV4({
76
+ credentials: this.credentials,
77
+ region: this.region,
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,
109
85
  path: url.pathname,
86
+ query: Object.fromEntries(url.searchParams.entries()),
110
87
  method: 'GET',
111
- service: 'segments',
112
- region: this.region,
113
- headers: { 'User-Agent': `veridia-node-sdk/${version_js_1.SDK_VERSION}` },
114
- };
115
- aws4.sign(req, this.options);
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
92
  const res = await (0, http_js_1.httpFetch)(url.toString(), {
119
- method: req.method,
120
- headers: req.headers,
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 opts = {
192
- host: urlObj.host,
193
- path: urlObj.pathname + urlObj.search,
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
- service,
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
- ...signedOpts,
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) {
@@ -27,9 +27,14 @@ export type VeridiaLogger = {
27
27
  */
28
28
  error: (service: string, message: string, context?: VeridiaLogContext) => void;
29
29
  };
30
- export type VeridiaClientOptions = {
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;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.12";
1
+ export declare const SDK_VERSION = "1.0.14";
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.0.12';
4
+ exports.SDK_VERSION = '1.0.14';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veridia/node-sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
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
- "aws4": "1.13.2",
27
- "node-fetch": "^3.3.2"
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",