@veridia/node-sdk 1.0.2 → 1.0.5

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.
@@ -7,6 +7,7 @@ export declare class VeridiaClient {
7
7
  private readonly logger;
8
8
  private readonly baseUrl;
9
9
  private readonly region;
10
+ private readonly autoFlush;
10
11
  private readonly maxBufferSize;
11
12
  private readonly maxBufferTimeMs;
12
13
  private readonly retries;
@@ -38,9 +39,10 @@ export declare class VeridiaClient {
38
39
  *
39
40
  * @param identifierType - The type of user identifier ("userId" | "email").
40
41
  * @param identifierId - The unique ID or email.
42
+ * @param [noSegmentsOnError=true] - Whether to throw an error or to return empty array of segments. Defaults to true.
41
43
  * @returns A list of segment identifiers the user currently belongs to.
42
44
  */
43
- getUserSegments(identifierType: IdentifierPayload['type'], identifierId: string): Promise<string[]>;
45
+ getUserSegments(identifierType: IdentifierPayload['type'], identifierId: string, noSegmentsOnError?: boolean): Promise<string[]>;
44
46
  /**
45
47
  * Sends all queued identify and track data to the Veridia API immediately.
46
48
  * Automatically called when buffers reach their limit or after the configured time interval.
@@ -44,6 +44,7 @@ class VeridiaClient {
44
44
  this.identifyBuffer = [];
45
45
  this.baseUrl = options.endpoint ?? 'https://api.veridia.io/v1';
46
46
  this.region = options.region ?? 'default';
47
+ this.autoFlush = options.autoFlush ?? true;
47
48
  this.maxBufferSize = options.maxBufferSize ?? 500;
48
49
  this.maxBufferTimeMs = options.maxBufferTimeMs ?? 5000;
49
50
  this.retries = options.retries ?? 3;
@@ -67,7 +68,8 @@ class VeridiaClient {
67
68
  },
68
69
  attributes,
69
70
  });
70
- this.scheduleFlushIfNeeded(this.identifyBuffer);
71
+ if (this.autoFlush)
72
+ this.scheduleFlushIfNeeded('profiles', this.identifyBuffer);
71
73
  }
72
74
  /**
73
75
  * Sends a tracking event for the given user.
@@ -87,16 +89,18 @@ class VeridiaClient {
87
89
  eventTime,
88
90
  properties,
89
91
  });
90
- this.scheduleFlushIfNeeded(this.trackBuffer);
92
+ if (this.autoFlush)
93
+ this.scheduleFlushIfNeeded('events', this.trackBuffer);
91
94
  }
92
95
  /**
93
96
  * Retrieves the current segments for the given user.
94
97
  *
95
98
  * @param identifierType - The type of user identifier ("userId" | "email").
96
99
  * @param identifierId - The unique ID or email.
100
+ * @param [noSegmentsOnError=true] - Whether to throw an error or to return empty array of segments. Defaults to true.
97
101
  * @returns A list of segment identifiers the user currently belongs to.
98
102
  */
99
- async getUserSegments(identifierType, identifierId) {
103
+ async getUserSegments(identifierType, identifierId, noSegmentsOnError = true) {
100
104
  try {
101
105
  const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
102
106
  const url = `${this.baseUrl}${path}`;
@@ -118,7 +122,10 @@ class VeridiaClient {
118
122
  }).finally(() => clearTimeout(timeout));
119
123
  if (!res.ok) {
120
124
  this.logger?.error('segments', 'getUserSegments API call failed', { status: res.status });
121
- return [];
125
+ if (noSegmentsOnError)
126
+ return [];
127
+ else
128
+ throw new Error(`getUserSegments API call failed: ${res.status}`);
122
129
  }
123
130
  const data = (await res.json());
124
131
  if (data.status === 'success' && Array.isArray(data.data)) {
@@ -127,13 +134,19 @@ class VeridiaClient {
127
134
  this.logger?.error('segments', 'getUserSegments API returned invalid response', {
128
135
  data: data,
129
136
  });
130
- return [];
137
+ if (noSegmentsOnError)
138
+ return [];
139
+ else
140
+ throw new Error(`getUserSegments API returned invalid response: ${JSON.stringify(data)}`);
131
141
  }
132
142
  catch (err) {
133
143
  this.logger?.error('segments', 'getUserSegments encountered an error', {
134
144
  error: err,
135
145
  });
136
- return [];
146
+ if (noSegmentsOnError)
147
+ return [];
148
+ else
149
+ throw err;
137
150
  }
138
151
  }
139
152
  /**
@@ -157,12 +170,18 @@ class VeridiaClient {
157
170
  async close() {
158
171
  await this.flush();
159
172
  }
160
- scheduleFlushIfNeeded(buffer) {
173
+ scheduleFlushIfNeeded(service, buffer) {
161
174
  if (buffer.length >= this.maxBufferSize) {
162
- void this.flush();
175
+ this.flush().catch((error) => {
176
+ this.logger?.error(service, 'automatic flush failed', { error });
177
+ });
163
178
  }
164
179
  else if (!this.flushTimer) {
165
- this.flushTimer = setTimeout(() => this.flush(), this.maxBufferTimeMs);
180
+ this.flushTimer = setTimeout(() => {
181
+ this.flush().catch((error) => {
182
+ this.logger?.error(service, 'automatic flush failed', { error });
183
+ });
184
+ }, this.maxBufferTimeMs);
166
185
  }
167
186
  }
168
187
  async flushBatch(service, buffer) {
@@ -32,6 +32,7 @@ export type VeridiaClientOptions = {
32
32
  secretAccessKey: string;
33
33
  endpoint?: string;
34
34
  region?: string;
35
+ autoFlush?: boolean;
35
36
  maxBufferSize?: number;
36
37
  maxBufferTimeMs?: number;
37
38
  retries?: number;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.2";
1
+ export declare const SDK_VERSION = "1.0.5";
@@ -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.2';
4
+ exports.SDK_VERSION = '1.0.5';
5
5
  //# sourceMappingURL=version.js.map
@@ -7,6 +7,7 @@ export declare class VeridiaClient {
7
7
  private readonly logger;
8
8
  private readonly baseUrl;
9
9
  private readonly region;
10
+ private readonly autoFlush;
10
11
  private readonly maxBufferSize;
11
12
  private readonly maxBufferTimeMs;
12
13
  private readonly retries;
@@ -38,9 +39,10 @@ export declare class VeridiaClient {
38
39
  *
39
40
  * @param identifierType - The type of user identifier ("userId" | "email").
40
41
  * @param identifierId - The unique ID or email.
42
+ * @param [noSegmentsOnError=true] - Whether to throw an error or to return empty array of segments. Defaults to true.
41
43
  * @returns A list of segment identifiers the user currently belongs to.
42
44
  */
43
- getUserSegments(identifierType: IdentifierPayload['type'], identifierId: string): Promise<string[]>;
45
+ getUserSegments(identifierType: IdentifierPayload['type'], identifierId: string, noSegmentsOnError?: boolean): Promise<string[]>;
44
46
  /**
45
47
  * Sends all queued identify and track data to the Veridia API immediately.
46
48
  * Automatically called when buffers reach their limit or after the configured time interval.
@@ -44,6 +44,7 @@ class VeridiaClient {
44
44
  this.identifyBuffer = [];
45
45
  this.baseUrl = options.endpoint ?? 'https://api.veridia.io/v1';
46
46
  this.region = options.region ?? 'default';
47
+ this.autoFlush = options.autoFlush ?? true;
47
48
  this.maxBufferSize = options.maxBufferSize ?? 500;
48
49
  this.maxBufferTimeMs = options.maxBufferTimeMs ?? 5000;
49
50
  this.retries = options.retries ?? 3;
@@ -67,7 +68,8 @@ class VeridiaClient {
67
68
  },
68
69
  attributes,
69
70
  });
70
- this.scheduleFlushIfNeeded(this.identifyBuffer);
71
+ if (this.autoFlush)
72
+ this.scheduleFlushIfNeeded('profiles', this.identifyBuffer);
71
73
  }
72
74
  /**
73
75
  * Sends a tracking event for the given user.
@@ -87,16 +89,18 @@ class VeridiaClient {
87
89
  eventTime,
88
90
  properties,
89
91
  });
90
- this.scheduleFlushIfNeeded(this.trackBuffer);
92
+ if (this.autoFlush)
93
+ this.scheduleFlushIfNeeded('events', this.trackBuffer);
91
94
  }
92
95
  /**
93
96
  * Retrieves the current segments for the given user.
94
97
  *
95
98
  * @param identifierType - The type of user identifier ("userId" | "email").
96
99
  * @param identifierId - The unique ID or email.
100
+ * @param [noSegmentsOnError=true] - Whether to throw an error or to return empty array of segments. Defaults to true.
97
101
  * @returns A list of segment identifiers the user currently belongs to.
98
102
  */
99
- async getUserSegments(identifierType, identifierId) {
103
+ async getUserSegments(identifierType, identifierId, noSegmentsOnError = true) {
100
104
  try {
101
105
  const path = `/segments/${identifierType}/${encodeURIComponent(identifierId)}`;
102
106
  const url = `${this.baseUrl}${path}`;
@@ -118,7 +122,10 @@ class VeridiaClient {
118
122
  }).finally(() => clearTimeout(timeout));
119
123
  if (!res.ok) {
120
124
  this.logger?.error('segments', 'getUserSegments API call failed', { status: res.status });
121
- return [];
125
+ if (noSegmentsOnError)
126
+ return [];
127
+ else
128
+ throw new Error(`getUserSegments API call failed: ${res.status}`);
122
129
  }
123
130
  const data = (await res.json());
124
131
  if (data.status === 'success' && Array.isArray(data.data)) {
@@ -127,13 +134,19 @@ class VeridiaClient {
127
134
  this.logger?.error('segments', 'getUserSegments API returned invalid response', {
128
135
  data: data,
129
136
  });
130
- return [];
137
+ if (noSegmentsOnError)
138
+ return [];
139
+ else
140
+ throw new Error(`getUserSegments API returned invalid response: ${JSON.stringify(data)}`);
131
141
  }
132
142
  catch (err) {
133
143
  this.logger?.error('segments', 'getUserSegments encountered an error', {
134
144
  error: err,
135
145
  });
136
- return [];
146
+ if (noSegmentsOnError)
147
+ return [];
148
+ else
149
+ throw err;
137
150
  }
138
151
  }
139
152
  /**
@@ -157,12 +170,18 @@ class VeridiaClient {
157
170
  async close() {
158
171
  await this.flush();
159
172
  }
160
- scheduleFlushIfNeeded(buffer) {
173
+ scheduleFlushIfNeeded(service, buffer) {
161
174
  if (buffer.length >= this.maxBufferSize) {
162
- void this.flush();
175
+ this.flush().catch((error) => {
176
+ this.logger?.error(service, 'automatic flush failed', { error });
177
+ });
163
178
  }
164
179
  else if (!this.flushTimer) {
165
- this.flushTimer = setTimeout(() => this.flush(), this.maxBufferTimeMs);
180
+ this.flushTimer = setTimeout(() => {
181
+ this.flush().catch((error) => {
182
+ this.logger?.error(service, 'automatic flush failed', { error });
183
+ });
184
+ }, this.maxBufferTimeMs);
166
185
  }
167
186
  }
168
187
  async flushBatch(service, buffer) {
@@ -32,6 +32,7 @@ export type VeridiaClientOptions = {
32
32
  secretAccessKey: string;
33
33
  endpoint?: string;
34
34
  region?: string;
35
+ autoFlush?: boolean;
35
36
  maxBufferSize?: number;
36
37
  maxBufferTimeMs?: number;
37
38
  retries?: number;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.2";
1
+ export declare const SDK_VERSION = "1.0.5";
@@ -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.2';
4
+ exports.SDK_VERSION = '1.0.5';
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.2",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -41,5 +41,6 @@
41
41
  "repository": {
42
42
  "type": "git",
43
43
  "url": "https://github.com/veridia-io/veridia-node-sdk.git"
44
- }
44
+ },
45
+ "license": "MIT"
45
46
  }
@@ -1,49 +0,0 @@
1
- name: Build & Publish
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*.*.*' # triggers only for version tags (v1.0.0, v1.1.2, etc.)
7
-
8
- jobs:
9
- build-and-publish:
10
- name: Build and publish to npm
11
- runs-on: ubuntu-latest
12
- permissions:
13
- contents: write
14
-
15
- steps:
16
- - name: Checkout repository
17
- uses: actions/checkout@v4
18
-
19
- - name: Use Node.js 22
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: 22
23
- registry-url: 'https://registry.npmjs.org/'
24
-
25
- - name: Install dependencies
26
- run: npm ci
27
-
28
- - name: Lint
29
- run: npm run lint --if-present
30
-
31
- - name: Run tests
32
- run: npm test --if-present
33
-
34
- - name: Build SDK (CJS + ESM)
35
- run: npm run build
36
-
37
- - name: Verify package contents
38
- run: npm pack --dry-run
39
-
40
- - name: Publish to npm
41
- if: startsWith(github.ref, 'refs/tags/v')
42
- env:
43
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44
- run: npm publish --access public
45
-
46
- - name: Create GitHub Release
47
- uses: softprops/action-gh-release@v2
48
- with:
49
- generate_release_notes: true