@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.
- package/dist/cjs/client.d.ts +3 -1
- package/dist/cjs/client.js +28 -9
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +3 -1
- package/dist/esm/client.js +28 -9
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -2
- package/.github/workflows/publish.yml +0 -49
package/dist/cjs/client.d.ts
CHANGED
|
@@ -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.
|
package/dist/cjs/client.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(() =>
|
|
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) {
|
package/dist/cjs/types.d.ts
CHANGED
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.5";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/client.d.ts
CHANGED
|
@@ -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.
|
package/dist/esm/client.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(() =>
|
|
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) {
|
package/dist/esm/types.d.ts
CHANGED
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.5";
|
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.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
|