@veridia/node-sdk 1.0.5 → 1.0.7
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 +62 -38
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Veridia Node SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@veridia/node-sdk)
|
|
4
|
+
|
|
5
|
+
Official Node.js SDK for integrating with the [Veridia Platform](https://veridia.io).
|
|
6
|
+
It provides an easy way to identify users, send tracking events, retrieve user segments, and manage batching with retries and timeouts — all from your backend.
|
|
5
7
|
|
|
6
8
|
---
|
|
7
9
|
|
|
@@ -55,7 +57,8 @@ const client = new VeridiaClient({
|
|
|
55
57
|
|
|
56
58
|
### `identify(identifierType, identifierId, attributes)`
|
|
57
59
|
|
|
58
|
-
Identify a user and update their profile attributes.
|
|
60
|
+
Identify a user and update their profile attributes.
|
|
61
|
+
Provided attributes must match the Profile Attributes schema defined in your Veridia dashboard.
|
|
59
62
|
|
|
60
63
|
```ts
|
|
61
64
|
await client.identify('userId', '123', {
|
|
@@ -65,17 +68,18 @@ await client.identify('userId', '123', {
|
|
|
65
68
|
});
|
|
66
69
|
```
|
|
67
70
|
|
|
68
|
-
| Parameter | Type | Description
|
|
69
|
-
| ---------------- | ----------------------- |
|
|
70
|
-
| `identifierType` | `"userId"` \| `"email"` | How the user is identified.
|
|
71
|
-
| `identifierId` | `string` |
|
|
72
|
-
| `attributes` | `Record<string, any>` | Arbitrary user attributes.
|
|
71
|
+
| Parameter | Type | Description |
|
|
72
|
+
| ---------------- | ----------------------- | --------------------------- |
|
|
73
|
+
| `identifierType` | `"userId"` \| `"email"` | How the user is identified. |
|
|
74
|
+
| `identifierId` | `string` | Unique identifier value. |
|
|
75
|
+
| `attributes` | `Record<string, any>` | Arbitrary user attributes. |
|
|
73
76
|
|
|
74
77
|
---
|
|
75
78
|
|
|
76
79
|
### `track(identifierType, identifierId, eventType, eventId, eventTime, properties)`
|
|
77
80
|
|
|
78
|
-
Track an event performed by a user.
|
|
81
|
+
Track an event performed by a user.
|
|
82
|
+
Provided attributes must match the event attributes schema defined in your Veridia dashboard.
|
|
79
83
|
|
|
80
84
|
```ts
|
|
81
85
|
await client.track('userId', '123', 'purchase', 'evt-001', new Date().toISOString(), {
|
|
@@ -84,26 +88,34 @@ await client.track('userId', '123', 'purchase', 'evt-001', new Date().toISOStrin
|
|
|
84
88
|
});
|
|
85
89
|
```
|
|
86
90
|
|
|
87
|
-
| Parameter | Type | Description
|
|
88
|
-
| ---------------- | ----------------------- |
|
|
89
|
-
| `identifierType` | `"userId"` \| `"email"` | How the user is identified.
|
|
90
|
-
| `identifierId` | `string` | Unique identifier
|
|
91
|
-
| `eventType` | `string` |
|
|
92
|
-
| `eventId` | `string` | Unique event ID for idempotency.
|
|
93
|
-
| `eventTime` | `string` | ISO timestamp string.
|
|
94
|
-
| `properties` | `Record<string, any>` | Optional event properties.
|
|
91
|
+
| Parameter | Type | Description |
|
|
92
|
+
| ---------------- | ----------------------- | -------------------------------- |
|
|
93
|
+
| `identifierType` | `"userId"` \| `"email"` | How the user is identified. |
|
|
94
|
+
| `identifierId` | `string` | Unique user identifier. |
|
|
95
|
+
| `eventType` | `string` | Logical name of the event. |
|
|
96
|
+
| `eventId` | `string` | Unique event ID for idempotency. |
|
|
97
|
+
| `eventTime` | `string` | ISO timestamp string. |
|
|
98
|
+
| `properties` | `Record<string, any>` | Optional event properties. |
|
|
95
99
|
|
|
96
100
|
---
|
|
97
101
|
|
|
98
|
-
### `getUserSegments(identifierType, identifierId)`
|
|
102
|
+
### `getUserSegments(identifierType, identifierId, [noSegmentsOnError=true])`
|
|
99
103
|
|
|
100
104
|
Fetches the list of segments the specified user currently belongs to.
|
|
105
|
+
If the API call fails and `noSegmentsOnError` is set to `false`, it will throw an error.
|
|
106
|
+
Otherwise, it will return an empty array.
|
|
101
107
|
|
|
102
108
|
```ts
|
|
103
109
|
const segments = await client.getUserSegments('userId', '123');
|
|
104
110
|
console.log(segments); // ['617090ac-a1f6-4c70-a79e-40830a367324', '67f2c139-850f-469f-9ca4-a1c58e6d84ea']
|
|
105
111
|
```
|
|
106
112
|
|
|
113
|
+
| Parameter | Type | Default | Description |
|
|
114
|
+
| ------------------- | ---------- | --------- | --------------------------------------------------- |
|
|
115
|
+
| `identifierType` | `"userId"` | `"email"` | Type of user identifier. |
|
|
116
|
+
| `identifierId` | `string` | — | Unique user ID or email. |
|
|
117
|
+
| `noSegmentsOnError` | `boolean` | `true` | If true, returns `[]` instead of throwing an error. |
|
|
118
|
+
|
|
107
119
|
Returns:
|
|
108
120
|
`Promise<string[]>` — Array of segment identifiers.
|
|
109
121
|
|
|
@@ -112,6 +124,7 @@ Returns:
|
|
|
112
124
|
### `flush()`
|
|
113
125
|
|
|
114
126
|
Immediately sends all queued identify and track data.
|
|
127
|
+
Automatically called when buffers reach their configured limits or after the flush interval.
|
|
115
128
|
|
|
116
129
|
```ts
|
|
117
130
|
await client.flush();
|
|
@@ -119,8 +132,8 @@ await client.flush();
|
|
|
119
132
|
|
|
120
133
|
### `close()`
|
|
121
134
|
|
|
122
|
-
Flushes
|
|
123
|
-
Call this before
|
|
135
|
+
Flushes any remaining buffered data and closes the client gracefully.
|
|
136
|
+
Call this before application exit in workers or serverless environments.
|
|
124
137
|
|
|
125
138
|
```ts
|
|
126
139
|
await client.close();
|
|
@@ -130,31 +143,39 @@ await client.close();
|
|
|
130
143
|
|
|
131
144
|
## ⚙️ Configuration Options
|
|
132
145
|
|
|
133
|
-
| Option | Type | Default | Description
|
|
134
|
-
| -------------------------- | --------------- | --------------------------- |
|
|
135
|
-
| `accessKeyId` | `string` | — | Veridia API access key ID
|
|
136
|
-
| `secretAccessKey` | `string` | — | Veridia API secret
|
|
137
|
-
| `endpoint` | `string` | `https://api.veridia.io/v1` | API base URL
|
|
138
|
-
| `region` | `string` | `"default"` | API region
|
|
139
|
-
| `
|
|
140
|
-
| `
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
146
|
+
| Option | Type | Default | Description |
|
|
147
|
+
| -------------------------- | --------------- | --------------------------- | --------------------------------------------- |
|
|
148
|
+
| `accessKeyId` | `string` | — | Veridia API access key ID. |
|
|
149
|
+
| `secretAccessKey` | `string` | — | Veridia API secret. |
|
|
150
|
+
| `endpoint` | `string` | `https://api.veridia.io/v1` | API base URL. |
|
|
151
|
+
| `region` | `string` | `"default"` | API region. |
|
|
152
|
+
| `autoFlush` | `boolean` | `true` | Whether to automatically flush buffered data. |
|
|
153
|
+
| `maxBufferSize` | `number` | `500` | Max number of items before auto-flush. |
|
|
154
|
+
| `maxBufferTimeMs` | `number` | `5000` | Max time (ms) before auto-flush. |
|
|
155
|
+
| `retries` | `number` | `3` | Retry attempts on transient network errors. |
|
|
156
|
+
| `retryBaseDelayMs` | `number` | `500` | Base delay (ms) for exponential backoff. |
|
|
157
|
+
| `timeoutMsGetUserSegments` | `number` | `5000` | Timeout (ms) for `getUserSegments` calls. |
|
|
158
|
+
| `timeoutMsFlush` | `number` | `30000` | Timeout (ms) for batch flush requests. |
|
|
159
|
+
| `logger` | `VeridiaLogger` | — | Custom logger implementation. |
|
|
145
160
|
|
|
146
161
|
---
|
|
147
162
|
|
|
148
163
|
## 🧾 Logger Interface
|
|
149
164
|
|
|
150
|
-
The SDK supports pluggable logging.
|
|
151
165
|
You can integrate your own logger (e.g. Pino, Winston, Bunyan) by providing the following interface:
|
|
152
166
|
|
|
153
167
|
```ts
|
|
154
168
|
interface VeridiaLogger {
|
|
155
|
-
info(service: string, message: string, context?:
|
|
156
|
-
warn(service: string, message: string, context?:
|
|
157
|
-
error(service: string, message: string, context?:
|
|
169
|
+
info?(service: string, message: string, context?: VeridiaLogContext): void;
|
|
170
|
+
warn?(service: string, message: string, context?: VeridiaLogContext): void;
|
|
171
|
+
error(service: string, message: string, context?: VeridiaLogContext): void;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface VeridiaLogContext {
|
|
175
|
+
status?: number;
|
|
176
|
+
error?: unknown;
|
|
177
|
+
data?: unknown;
|
|
178
|
+
[key: string]: unknown;
|
|
158
179
|
}
|
|
159
180
|
```
|
|
160
181
|
|
|
@@ -179,8 +200,8 @@ const client = new VeridiaClient({
|
|
|
179
200
|
|
|
180
201
|
## 🧩 TypeScript Support
|
|
181
202
|
|
|
182
|
-
The SDK ships with full `.d.ts` declarations and JSDoc
|
|
183
|
-
Hover over any method in VS Code to see inline
|
|
203
|
+
The SDK ships with full `.d.ts` declarations and JSDoc documentation.
|
|
204
|
+
Hover over any method in VS Code to see inline descriptions and parameter hints.
|
|
184
205
|
|
|
185
206
|
---
|
|
186
207
|
|
|
@@ -198,6 +219,9 @@ const client = new VeridiaClient({
|
|
|
198
219
|
await client.identify('userId', '123', { plan: 'gold' });
|
|
199
220
|
await client.track('userId', '123', 'purchase', 'evt-123', new Date().toISOString());
|
|
200
221
|
await client.flush();
|
|
222
|
+
|
|
223
|
+
const segments = await client.getUserSegments('userId', '123');
|
|
224
|
+
console.log('Segments:', segments);
|
|
201
225
|
```
|
|
202
226
|
|
|
203
227
|
---
|
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.7";
|
package/dist/cjs/version.js
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.7";
|
package/dist/esm/version.js
CHANGED