@subscribeflow/sdk 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/README.md +379 -0
- package/dist/api-types.d.ts +4865 -0
- package/dist/api-types.d.ts.map +1 -0
- package/dist/api-types.js +6 -0
- package/dist/api-types.js.map +1 -0
- package/dist/index.d.ts +10313 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1029 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SubscribeFlow TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* A type-safe client for the SubscribeFlow API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { SubscribeFlowClient } from '@subscribeflow/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const client = new SubscribeFlowClient({
|
|
11
|
+
* apiKey: 'sf_live_your_api_key',
|
|
12
|
+
* baseUrl: 'https://api.subscribeflow.net', // optional
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Create a subscriber
|
|
16
|
+
* const subscriber = await client.subscribers.create({
|
|
17
|
+
* email: 'user@example.com',
|
|
18
|
+
* tags: ['newsletter', 'product-updates'],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // List all tags
|
|
22
|
+
* const tags = await client.tags.list();
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
import createClient from "openapi-fetch";
|
|
28
|
+
/**
|
|
29
|
+
* Error thrown by the SubscribeFlow client.
|
|
30
|
+
*/
|
|
31
|
+
export class SubscribeFlowError extends Error {
|
|
32
|
+
status;
|
|
33
|
+
type;
|
|
34
|
+
detail;
|
|
35
|
+
instance;
|
|
36
|
+
constructor(message, status, type, detail, instance) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.type = type;
|
|
40
|
+
this.detail = detail;
|
|
41
|
+
this.instance = instance;
|
|
42
|
+
this.name = "SubscribeFlowError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* SubscribeFlow API client.
|
|
47
|
+
*
|
|
48
|
+
* Provides type-safe access to all SubscribeFlow API endpoints.
|
|
49
|
+
*/
|
|
50
|
+
export class SubscribeFlowClient {
|
|
51
|
+
client;
|
|
52
|
+
config;
|
|
53
|
+
/**
|
|
54
|
+
* Create a new SubscribeFlow client.
|
|
55
|
+
*
|
|
56
|
+
* @param config - Client configuration
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const client = new SubscribeFlowClient({
|
|
61
|
+
* apiKey: process.env.SUBSCRIBEFLOW_API_KEY!,
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
constructor(config) {
|
|
66
|
+
this.config = {
|
|
67
|
+
baseUrl: "https://api.subscribeflow.net",
|
|
68
|
+
...config,
|
|
69
|
+
};
|
|
70
|
+
this.client = createClient({
|
|
71
|
+
baseUrl: this.config.baseUrl,
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Subscriber management operations.
|
|
80
|
+
*/
|
|
81
|
+
subscribers = {
|
|
82
|
+
/**
|
|
83
|
+
* Create a new subscriber.
|
|
84
|
+
*
|
|
85
|
+
* @param data - Subscriber data
|
|
86
|
+
* @returns The created subscriber
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const subscriber = await client.subscribers.create({
|
|
91
|
+
* email: 'user@example.com',
|
|
92
|
+
* tags: ['newsletter'],
|
|
93
|
+
* metadata: { source: 'website' },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
create: async (data) => {
|
|
98
|
+
const { data: result, error } = await this.client.POST("/api/v1/subscribers", {
|
|
99
|
+
body: data,
|
|
100
|
+
});
|
|
101
|
+
if (error) {
|
|
102
|
+
throw this.handleError(error);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* List all subscribers with optional filtering.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Query options
|
|
110
|
+
* @returns Paginated list of subscribers
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const { items, total, next_cursor } = await client.subscribers.list({
|
|
115
|
+
* limit: 50,
|
|
116
|
+
* status: 'active',
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
list: async (options) => {
|
|
121
|
+
const { data: result, error } = await this.client.GET("/api/v1/subscribers", {
|
|
122
|
+
params: { query: options },
|
|
123
|
+
});
|
|
124
|
+
if (error) {
|
|
125
|
+
throw this.handleError(error);
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Get a subscriber by ID.
|
|
131
|
+
*
|
|
132
|
+
* @param id - Subscriber ID (UUID)
|
|
133
|
+
* @returns The subscriber
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const subscriber = await client.subscribers.get('123e4567-e89b-...');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
get: async (id) => {
|
|
141
|
+
const { data: result, error } = await this.client.GET("/api/v1/subscribers/{subscriber_id}", {
|
|
142
|
+
params: { path: { subscriber_id: id } },
|
|
143
|
+
});
|
|
144
|
+
if (error) {
|
|
145
|
+
throw this.handleError(error);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Update a subscriber.
|
|
151
|
+
*
|
|
152
|
+
* @param id - Subscriber ID (UUID)
|
|
153
|
+
* @param data - Fields to update
|
|
154
|
+
* @returns The updated subscriber
|
|
155
|
+
*/
|
|
156
|
+
update: async (id, data) => {
|
|
157
|
+
const { data: result, error } = await this.client.PUT("/api/v1/subscribers/{subscriber_id}", {
|
|
158
|
+
params: { path: { subscriber_id: id } },
|
|
159
|
+
body: data,
|
|
160
|
+
});
|
|
161
|
+
if (error) {
|
|
162
|
+
throw this.handleError(error);
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Delete a subscriber.
|
|
168
|
+
*
|
|
169
|
+
* @param id - Subscriber ID (UUID)
|
|
170
|
+
*/
|
|
171
|
+
delete: async (id) => {
|
|
172
|
+
const { error } = await this.client.DELETE("/api/v1/subscribers/{subscriber_id}", {
|
|
173
|
+
params: { path: { subscriber_id: id } },
|
|
174
|
+
});
|
|
175
|
+
if (error) {
|
|
176
|
+
throw this.handleError(error);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Add tags to a subscriber.
|
|
181
|
+
*
|
|
182
|
+
* @param id - Subscriber UUID
|
|
183
|
+
* @param tagIds - Tag UUIDs to add
|
|
184
|
+
* @returns Updated tag list
|
|
185
|
+
*/
|
|
186
|
+
addTags: async (id, tagIds) => {
|
|
187
|
+
const { data: result, error } = await this.client.POST("/api/v1/subscribers/{subscriber_id}/tags", {
|
|
188
|
+
params: { path: { subscriber_id: id } },
|
|
189
|
+
body: { tag_ids: tagIds },
|
|
190
|
+
});
|
|
191
|
+
if (error)
|
|
192
|
+
throw this.handleError(error);
|
|
193
|
+
return result;
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* Remove a tag from a subscriber.
|
|
197
|
+
*
|
|
198
|
+
* @param id - Subscriber UUID
|
|
199
|
+
* @param tagId - Tag UUID to remove
|
|
200
|
+
*/
|
|
201
|
+
removeTag: async (id, tagId) => {
|
|
202
|
+
const { error } = await this.client.DELETE("/api/v1/subscribers/{subscriber_id}/tags/{tag_id}", {
|
|
203
|
+
params: {
|
|
204
|
+
path: { subscriber_id: id, tag_id: tagId },
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
if (error)
|
|
208
|
+
throw this.handleError(error);
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* List tags for a subscriber.
|
|
212
|
+
*
|
|
213
|
+
* @param id - Subscriber UUID
|
|
214
|
+
* @returns List of subscriber's tags
|
|
215
|
+
*/
|
|
216
|
+
listTags: async (id) => {
|
|
217
|
+
const { data: result, error } = await this.client.GET("/api/v1/subscribers/{subscriber_id}/tags", {
|
|
218
|
+
params: { path: { subscriber_id: id } },
|
|
219
|
+
});
|
|
220
|
+
if (error)
|
|
221
|
+
throw this.handleError(error);
|
|
222
|
+
return result;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Tag management operations.
|
|
227
|
+
*/
|
|
228
|
+
tags = {
|
|
229
|
+
/**
|
|
230
|
+
* Create a new tag.
|
|
231
|
+
*
|
|
232
|
+
* @param data - Tag data
|
|
233
|
+
* @returns The created tag
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const tag = await client.tags.create({
|
|
238
|
+
* name: 'Product Updates',
|
|
239
|
+
* slug: 'product-updates',
|
|
240
|
+
* description: 'Get notified about new features',
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
create: async (data) => {
|
|
245
|
+
const { data: result, error } = await this.client.POST("/api/v1/tags", {
|
|
246
|
+
body: data,
|
|
247
|
+
});
|
|
248
|
+
if (error) {
|
|
249
|
+
throw this.handleError(error);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
},
|
|
253
|
+
/**
|
|
254
|
+
* List all tags.
|
|
255
|
+
*
|
|
256
|
+
* @param options - Query options
|
|
257
|
+
* @returns Paginated list of tags
|
|
258
|
+
*/
|
|
259
|
+
list: async (options) => {
|
|
260
|
+
const { data: result, error } = await this.client.GET("/api/v1/tags", {
|
|
261
|
+
params: { query: options },
|
|
262
|
+
});
|
|
263
|
+
if (error) {
|
|
264
|
+
throw this.handleError(error);
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
},
|
|
268
|
+
/**
|
|
269
|
+
* Get a tag by ID.
|
|
270
|
+
*
|
|
271
|
+
* @param id - Tag ID (UUID)
|
|
272
|
+
* @returns The tag
|
|
273
|
+
*/
|
|
274
|
+
get: async (id) => {
|
|
275
|
+
const { data: result, error } = await this.client.GET("/api/v1/tags/{tag_id}", {
|
|
276
|
+
params: { path: { tag_id: id } },
|
|
277
|
+
});
|
|
278
|
+
if (error) {
|
|
279
|
+
throw this.handleError(error);
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
},
|
|
283
|
+
/**
|
|
284
|
+
* Update a tag.
|
|
285
|
+
*
|
|
286
|
+
* @param id - Tag ID (UUID)
|
|
287
|
+
* @param data - Fields to update
|
|
288
|
+
* @returns The updated tag
|
|
289
|
+
*/
|
|
290
|
+
update: async (id, data) => {
|
|
291
|
+
const { data: result, error } = await this.client.PUT("/api/v1/tags/{tag_id}", {
|
|
292
|
+
params: { path: { tag_id: id } },
|
|
293
|
+
body: data,
|
|
294
|
+
});
|
|
295
|
+
if (error) {
|
|
296
|
+
throw this.handleError(error);
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
},
|
|
300
|
+
/**
|
|
301
|
+
* Delete a tag.
|
|
302
|
+
*
|
|
303
|
+
* @param id - Tag ID (UUID)
|
|
304
|
+
*/
|
|
305
|
+
delete: async (id) => {
|
|
306
|
+
const { error } = await this.client.DELETE("/api/v1/tags/{tag_id}", {
|
|
307
|
+
params: { path: { tag_id: id } },
|
|
308
|
+
});
|
|
309
|
+
if (error) {
|
|
310
|
+
throw this.handleError(error);
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Webhook management operations.
|
|
316
|
+
*/
|
|
317
|
+
webhooks = {
|
|
318
|
+
/**
|
|
319
|
+
* Create a new webhook endpoint.
|
|
320
|
+
*
|
|
321
|
+
* @param data - Webhook endpoint data
|
|
322
|
+
* @returns The created webhook endpoint with signing secret
|
|
323
|
+
*/
|
|
324
|
+
create: async (data) => {
|
|
325
|
+
const { data: result, error } = await this.client.POST("/api/v1/webhooks", {
|
|
326
|
+
body: data,
|
|
327
|
+
});
|
|
328
|
+
if (error) {
|
|
329
|
+
throw this.handleError(error);
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
},
|
|
333
|
+
/**
|
|
334
|
+
* List all webhook endpoints.
|
|
335
|
+
*
|
|
336
|
+
* @param options - Query options
|
|
337
|
+
* @returns Paginated list of webhook endpoints
|
|
338
|
+
*/
|
|
339
|
+
list: async (options) => {
|
|
340
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks", {
|
|
341
|
+
params: { query: options },
|
|
342
|
+
});
|
|
343
|
+
if (error) {
|
|
344
|
+
throw this.handleError(error);
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
},
|
|
348
|
+
/**
|
|
349
|
+
* Get a webhook endpoint by ID.
|
|
350
|
+
*
|
|
351
|
+
* @param id - Webhook endpoint ID (UUID)
|
|
352
|
+
* @returns The webhook endpoint
|
|
353
|
+
*/
|
|
354
|
+
get: async (id) => {
|
|
355
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/{endpoint_id}", {
|
|
356
|
+
params: { path: { endpoint_id: id } },
|
|
357
|
+
});
|
|
358
|
+
if (error) {
|
|
359
|
+
throw this.handleError(error);
|
|
360
|
+
}
|
|
361
|
+
return result;
|
|
362
|
+
},
|
|
363
|
+
/**
|
|
364
|
+
* Delete a webhook endpoint.
|
|
365
|
+
*
|
|
366
|
+
* @param id - Webhook endpoint ID (UUID)
|
|
367
|
+
*/
|
|
368
|
+
delete: async (id) => {
|
|
369
|
+
const { error } = await this.client.DELETE("/api/v1/webhooks/{endpoint_id}", {
|
|
370
|
+
params: { path: { endpoint_id: id } },
|
|
371
|
+
});
|
|
372
|
+
if (error) {
|
|
373
|
+
throw this.handleError(error);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
/**
|
|
377
|
+
* Test a webhook endpoint by sending a test event.
|
|
378
|
+
*
|
|
379
|
+
* @param id - Webhook endpoint ID (UUID)
|
|
380
|
+
* @param eventType - Event type to test (defaults to subscriber.created)
|
|
381
|
+
* @returns Test delivery result
|
|
382
|
+
*/
|
|
383
|
+
test: async (id, eventType = "subscriber.created") => {
|
|
384
|
+
const { data: result, error } = await this.client.POST("/api/v1/webhooks/{endpoint_id}/test", {
|
|
385
|
+
params: { path: { endpoint_id: id } },
|
|
386
|
+
body: { event_type: eventType },
|
|
387
|
+
});
|
|
388
|
+
if (error) {
|
|
389
|
+
throw this.handleError(error);
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
},
|
|
393
|
+
/**
|
|
394
|
+
* Update a webhook endpoint.
|
|
395
|
+
*
|
|
396
|
+
* @param id - Webhook endpoint ID
|
|
397
|
+
* @param data - Fields to update
|
|
398
|
+
* @returns The updated endpoint
|
|
399
|
+
*/
|
|
400
|
+
update: async (id, data) => {
|
|
401
|
+
const { data: result, error } = await this.client.PUT(
|
|
402
|
+
// @ts-expect-error - path not yet in OpenAPI spec for PUT method
|
|
403
|
+
"/api/v1/webhooks/{endpoint_id}", {
|
|
404
|
+
params: { path: { endpoint_id: id } },
|
|
405
|
+
body: data,
|
|
406
|
+
});
|
|
407
|
+
if (error)
|
|
408
|
+
throw this.handleError(error);
|
|
409
|
+
return result;
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* Regenerate the signing secret for a webhook endpoint.
|
|
413
|
+
*
|
|
414
|
+
* @param id - Webhook endpoint ID
|
|
415
|
+
* @returns The endpoint with new secret
|
|
416
|
+
*/
|
|
417
|
+
regenerateSecret: async (id) => {
|
|
418
|
+
const { data: result, error } = await this.client.POST("/api/v1/webhooks/{endpoint_id}/regenerate-secret", { params: { path: { endpoint_id: id } } });
|
|
419
|
+
if (error)
|
|
420
|
+
throw this.handleError(error);
|
|
421
|
+
return result;
|
|
422
|
+
},
|
|
423
|
+
/**
|
|
424
|
+
* List deliveries for a webhook endpoint.
|
|
425
|
+
*
|
|
426
|
+
* @param id - Webhook endpoint ID
|
|
427
|
+
* @param options - Filter options
|
|
428
|
+
* @returns Paginated list of deliveries
|
|
429
|
+
*/
|
|
430
|
+
listDeliveries: async (id, options) => {
|
|
431
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/{endpoint_id}/deliveries", {
|
|
432
|
+
params: { path: { endpoint_id: id }, query: options },
|
|
433
|
+
});
|
|
434
|
+
if (error)
|
|
435
|
+
throw this.handleError(error);
|
|
436
|
+
return result;
|
|
437
|
+
},
|
|
438
|
+
/**
|
|
439
|
+
* Get a specific delivery with payload details.
|
|
440
|
+
*
|
|
441
|
+
* @param endpointId - Webhook endpoint ID
|
|
442
|
+
* @param deliveryId - Delivery ID
|
|
443
|
+
* @returns Detailed delivery record
|
|
444
|
+
*/
|
|
445
|
+
getDelivery: async (endpointId, deliveryId) => {
|
|
446
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/{endpoint_id}/deliveries/{delivery_id}", {
|
|
447
|
+
params: {
|
|
448
|
+
path: { endpoint_id: endpointId, delivery_id: deliveryId },
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
if (error)
|
|
452
|
+
throw this.handleError(error);
|
|
453
|
+
return result;
|
|
454
|
+
},
|
|
455
|
+
/**
|
|
456
|
+
* Retry a failed delivery.
|
|
457
|
+
*
|
|
458
|
+
* @param endpointId - Webhook endpoint ID
|
|
459
|
+
* @param deliveryId - Delivery ID
|
|
460
|
+
* @returns Retry result
|
|
461
|
+
*/
|
|
462
|
+
retryDelivery: async (endpointId, deliveryId) => {
|
|
463
|
+
const { data: result, error } = await this.client.POST("/api/v1/webhooks/{endpoint_id}/deliveries/{delivery_id}/retry", {
|
|
464
|
+
params: {
|
|
465
|
+
path: { endpoint_id: endpointId, delivery_id: deliveryId },
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
if (error)
|
|
469
|
+
throw this.handleError(error);
|
|
470
|
+
return result;
|
|
471
|
+
},
|
|
472
|
+
/**
|
|
473
|
+
* Get delivery statistics for a webhook endpoint.
|
|
474
|
+
*
|
|
475
|
+
* @param id - Webhook endpoint ID
|
|
476
|
+
* @param days - Number of days (default: 30)
|
|
477
|
+
* @returns Delivery statistics
|
|
478
|
+
*/
|
|
479
|
+
getStats: async (id, days) => {
|
|
480
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/{endpoint_id}/stats", {
|
|
481
|
+
params: { path: { endpoint_id: id }, query: { days: days ?? 30 } },
|
|
482
|
+
});
|
|
483
|
+
if (error)
|
|
484
|
+
throw this.handleError(error);
|
|
485
|
+
return result;
|
|
486
|
+
},
|
|
487
|
+
/**
|
|
488
|
+
* List deliveries across all webhook endpoints.
|
|
489
|
+
*
|
|
490
|
+
* @param options - Filter options
|
|
491
|
+
* @returns Paginated list of deliveries
|
|
492
|
+
*/
|
|
493
|
+
listAllDeliveries: async (options) => {
|
|
494
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/deliveries/all", { params: { query: options } });
|
|
495
|
+
if (error)
|
|
496
|
+
throw this.handleError(error);
|
|
497
|
+
return result;
|
|
498
|
+
},
|
|
499
|
+
/**
|
|
500
|
+
* Get delivery statistics across all endpoints.
|
|
501
|
+
*
|
|
502
|
+
* @param days - Number of days (default: 30)
|
|
503
|
+
* @returns Global delivery statistics
|
|
504
|
+
*/
|
|
505
|
+
getGlobalStats: async (days) => {
|
|
506
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/stats/all", { params: { query: { days: days ?? 30 } } });
|
|
507
|
+
if (error)
|
|
508
|
+
throw this.handleError(error);
|
|
509
|
+
return result;
|
|
510
|
+
},
|
|
511
|
+
/**
|
|
512
|
+
* List all available webhook event types.
|
|
513
|
+
*
|
|
514
|
+
* @returns Event types with descriptions
|
|
515
|
+
*/
|
|
516
|
+
listEventTypes: async () => {
|
|
517
|
+
const { data: result, error } = await this.client.GET("/api/v1/webhooks/event-types", {});
|
|
518
|
+
if (error)
|
|
519
|
+
throw this.handleError(error);
|
|
520
|
+
return result;
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
524
|
+
* Template management operations.
|
|
525
|
+
*/
|
|
526
|
+
templates = {
|
|
527
|
+
/**
|
|
528
|
+
* Create a new email template.
|
|
529
|
+
*
|
|
530
|
+
* @param data - Template data
|
|
531
|
+
* @returns The created template
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const template = await client.templates.create({
|
|
536
|
+
* name: 'Welcome Email',
|
|
537
|
+
* subject: 'Welcome to {{company}}!',
|
|
538
|
+
* mjml_content: '<mjml>...</mjml>',
|
|
539
|
+
* category: 'onboarding',
|
|
540
|
+
* });
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
create: async (data) => {
|
|
544
|
+
const { data: result, error } = await this.client.POST(
|
|
545
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
546
|
+
"/api/v1/templates", { body: data });
|
|
547
|
+
if (error)
|
|
548
|
+
throw this.handleError(error);
|
|
549
|
+
return result;
|
|
550
|
+
},
|
|
551
|
+
/**
|
|
552
|
+
* List all templates with optional filtering.
|
|
553
|
+
*
|
|
554
|
+
* @param options - Query options
|
|
555
|
+
* @returns Paginated list of templates
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const templates = await client.templates.list({ category: 'onboarding' });
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
list: async (options) => {
|
|
563
|
+
const { data: result, error } = await this.client.GET(
|
|
564
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
565
|
+
"/api/v1/templates", { params: { query: options } });
|
|
566
|
+
if (error)
|
|
567
|
+
throw this.handleError(error);
|
|
568
|
+
return result;
|
|
569
|
+
},
|
|
570
|
+
/**
|
|
571
|
+
* Get a template by slug.
|
|
572
|
+
*
|
|
573
|
+
* @param slug - Template slug
|
|
574
|
+
* @returns The template
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* const template = await client.templates.get('welcome-email');
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
get: async (slug) => {
|
|
582
|
+
const { data: result, error } = await this.client.GET(
|
|
583
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
584
|
+
"/api/v1/templates/{slug}", { params: { path: { slug } } });
|
|
585
|
+
if (error)
|
|
586
|
+
throw this.handleError(error);
|
|
587
|
+
return result;
|
|
588
|
+
},
|
|
589
|
+
/**
|
|
590
|
+
* Update a template.
|
|
591
|
+
*
|
|
592
|
+
* @param slug - Template slug
|
|
593
|
+
* @param data - Fields to update
|
|
594
|
+
* @returns The updated template
|
|
595
|
+
*/
|
|
596
|
+
update: async (slug, data) => {
|
|
597
|
+
const { data: result, error } = await this.client.PUT(
|
|
598
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
599
|
+
"/api/v1/templates/{slug}", {
|
|
600
|
+
params: { path: { slug } },
|
|
601
|
+
body: data,
|
|
602
|
+
});
|
|
603
|
+
if (error)
|
|
604
|
+
throw this.handleError(error);
|
|
605
|
+
return result;
|
|
606
|
+
},
|
|
607
|
+
/**
|
|
608
|
+
* Delete a template.
|
|
609
|
+
*
|
|
610
|
+
* @param slug - Template slug
|
|
611
|
+
*/
|
|
612
|
+
delete: async (slug) => {
|
|
613
|
+
const { error } = await this.client.DELETE(
|
|
614
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
615
|
+
"/api/v1/templates/{slug}", { params: { path: { slug } } });
|
|
616
|
+
if (error)
|
|
617
|
+
throw this.handleError(error);
|
|
618
|
+
},
|
|
619
|
+
/**
|
|
620
|
+
* Preview a rendered template with variables.
|
|
621
|
+
*
|
|
622
|
+
* @param slug - Template slug
|
|
623
|
+
* @param variables - Template variables to render
|
|
624
|
+
* @returns The rendered HTML preview
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```typescript
|
|
628
|
+
* const preview = await client.templates.preview('welcome-email', {
|
|
629
|
+
* company: 'Acme Inc',
|
|
630
|
+
* name: 'John',
|
|
631
|
+
* });
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
preview: async (slug, variables) => {
|
|
635
|
+
const { data: result, error } = await this.client.POST(
|
|
636
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
637
|
+
"/api/v1/templates/{slug}/preview", {
|
|
638
|
+
params: { path: { slug } },
|
|
639
|
+
body: { variables: variables ?? {} },
|
|
640
|
+
});
|
|
641
|
+
if (error)
|
|
642
|
+
throw this.handleError(error);
|
|
643
|
+
return result;
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
/**
|
|
647
|
+
* Email sending operations.
|
|
648
|
+
*/
|
|
649
|
+
emails = {
|
|
650
|
+
/**
|
|
651
|
+
* Send an email using a template.
|
|
652
|
+
*
|
|
653
|
+
* @param data - Email send data
|
|
654
|
+
* @returns The send result with message ID
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* const result = await client.emails.send({
|
|
659
|
+
* template_slug: 'welcome-email',
|
|
660
|
+
* to: 'user@example.com',
|
|
661
|
+
* variables: { name: 'John', company: 'Acme Inc' },
|
|
662
|
+
* idempotency_key: 'welcome-user-123',
|
|
663
|
+
* });
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
send: async (data) => {
|
|
667
|
+
const { data: result, error } = await this.client.POST(
|
|
668
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
669
|
+
"/api/v1/emails/send", { body: data });
|
|
670
|
+
if (error)
|
|
671
|
+
throw this.handleError(error);
|
|
672
|
+
return result;
|
|
673
|
+
},
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Campaign management operations.
|
|
677
|
+
*/
|
|
678
|
+
campaigns = {
|
|
679
|
+
/**
|
|
680
|
+
* Create a new campaign (draft status).
|
|
681
|
+
*
|
|
682
|
+
* @param data - Campaign data
|
|
683
|
+
* @returns The created campaign
|
|
684
|
+
*/
|
|
685
|
+
create: async (data) => {
|
|
686
|
+
const { data: result, error } = await this.client.POST(
|
|
687
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
688
|
+
"/api/v1/campaigns", { body: data });
|
|
689
|
+
if (error)
|
|
690
|
+
throw this.handleError(error);
|
|
691
|
+
return result;
|
|
692
|
+
},
|
|
693
|
+
/**
|
|
694
|
+
* List campaigns with optional filtering.
|
|
695
|
+
*
|
|
696
|
+
* @param options - Query options
|
|
697
|
+
* @returns Paginated list of campaigns
|
|
698
|
+
*/
|
|
699
|
+
list: async (options) => {
|
|
700
|
+
const { data: result, error } = await this.client.GET(
|
|
701
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
702
|
+
"/api/v1/campaigns", { params: { query: options } });
|
|
703
|
+
if (error)
|
|
704
|
+
throw this.handleError(error);
|
|
705
|
+
return result;
|
|
706
|
+
},
|
|
707
|
+
/**
|
|
708
|
+
* Get a campaign by ID.
|
|
709
|
+
*
|
|
710
|
+
* @param id - Campaign UUID
|
|
711
|
+
* @returns The campaign with statistics
|
|
712
|
+
*/
|
|
713
|
+
get: async (id) => {
|
|
714
|
+
const { data: result, error } = await this.client.GET(
|
|
715
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
716
|
+
"/api/v1/campaigns/{campaign_id}", { params: { path: { campaign_id: id } } });
|
|
717
|
+
if (error)
|
|
718
|
+
throw this.handleError(error);
|
|
719
|
+
return result;
|
|
720
|
+
},
|
|
721
|
+
/**
|
|
722
|
+
* Update a campaign (draft status only).
|
|
723
|
+
*
|
|
724
|
+
* @param id - Campaign UUID
|
|
725
|
+
* @param data - Fields to update
|
|
726
|
+
* @returns The updated campaign
|
|
727
|
+
*/
|
|
728
|
+
update: async (id, data) => {
|
|
729
|
+
const { data: result, error } = await this.client.PUT(
|
|
730
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
731
|
+
"/api/v1/campaigns/{campaign_id}", {
|
|
732
|
+
params: { path: { campaign_id: id } },
|
|
733
|
+
body: data,
|
|
734
|
+
});
|
|
735
|
+
if (error)
|
|
736
|
+
throw this.handleError(error);
|
|
737
|
+
return result;
|
|
738
|
+
},
|
|
739
|
+
/**
|
|
740
|
+
* Trigger campaign sending.
|
|
741
|
+
*
|
|
742
|
+
* @param id - Campaign UUID
|
|
743
|
+
* @param batchSize - Emails per batch (1-500, default: 50)
|
|
744
|
+
* @returns Send response with recipient count
|
|
745
|
+
*/
|
|
746
|
+
send: async (id, batchSize) => {
|
|
747
|
+
const { data: result, error } = await this.client.POST(
|
|
748
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
749
|
+
"/api/v1/campaigns/{campaign_id}/send", {
|
|
750
|
+
params: { path: { campaign_id: id } },
|
|
751
|
+
body: { batch_size: batchSize ?? 50 },
|
|
752
|
+
});
|
|
753
|
+
if (error)
|
|
754
|
+
throw this.handleError(error);
|
|
755
|
+
return result;
|
|
756
|
+
},
|
|
757
|
+
/**
|
|
758
|
+
* Cancel a sending campaign.
|
|
759
|
+
*
|
|
760
|
+
* @param id - Campaign UUID
|
|
761
|
+
* @returns The cancelled campaign
|
|
762
|
+
*/
|
|
763
|
+
cancel: async (id) => {
|
|
764
|
+
const { data: result, error } = await this.client.POST(
|
|
765
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
766
|
+
"/api/v1/campaigns/{campaign_id}/cancel", { params: { path: { campaign_id: id } } });
|
|
767
|
+
if (error)
|
|
768
|
+
throw this.handleError(error);
|
|
769
|
+
return result;
|
|
770
|
+
},
|
|
771
|
+
/**
|
|
772
|
+
* Count recipients matching a tag filter.
|
|
773
|
+
*
|
|
774
|
+
* @param tagFilter - Tag filter criteria
|
|
775
|
+
* @returns Number of matching recipients
|
|
776
|
+
*/
|
|
777
|
+
countRecipients: async (tagFilter) => {
|
|
778
|
+
const { data: result, error } = await this.client.POST(
|
|
779
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
780
|
+
"/api/v1/campaigns/count-recipients", { body: tagFilter });
|
|
781
|
+
if (error)
|
|
782
|
+
throw this.handleError(error);
|
|
783
|
+
return result;
|
|
784
|
+
},
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* Email trigger management operations.
|
|
788
|
+
*/
|
|
789
|
+
triggers = {
|
|
790
|
+
/**
|
|
791
|
+
* Create a new email trigger.
|
|
792
|
+
*
|
|
793
|
+
* @param data - Trigger data
|
|
794
|
+
* @returns The created trigger
|
|
795
|
+
*/
|
|
796
|
+
create: async (data) => {
|
|
797
|
+
const { data: result, error } = await this.client.POST(
|
|
798
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
799
|
+
"/api/v1/email-triggers", { body: data });
|
|
800
|
+
if (error)
|
|
801
|
+
throw this.handleError(error);
|
|
802
|
+
return result;
|
|
803
|
+
},
|
|
804
|
+
/**
|
|
805
|
+
* List all email triggers.
|
|
806
|
+
*
|
|
807
|
+
* @returns List of triggers
|
|
808
|
+
*/
|
|
809
|
+
list: async () => {
|
|
810
|
+
const { data: result, error } = await this.client.GET(
|
|
811
|
+
// @ts-expect-error - path not yet in OpenAPI spec
|
|
812
|
+
"/api/v1/email-triggers", {});
|
|
813
|
+
if (error)
|
|
814
|
+
throw this.handleError(error);
|
|
815
|
+
return result;
|
|
816
|
+
},
|
|
817
|
+
/**
|
|
818
|
+
* Get a trigger by ID.
|
|
819
|
+
*
|
|
820
|
+
* @param id - Trigger UUID
|
|
821
|
+
* @returns The trigger
|
|
822
|
+
*/
|
|
823
|
+
get: async (id) => {
|
|
824
|
+
const { data: result, error } = await this.client.GET(
|
|
825
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
826
|
+
"/api/v1/email-triggers/{trigger_id}", { params: { path: { trigger_id: id } } });
|
|
827
|
+
if (error)
|
|
828
|
+
throw this.handleError(error);
|
|
829
|
+
return result;
|
|
830
|
+
},
|
|
831
|
+
/**
|
|
832
|
+
* Update a trigger.
|
|
833
|
+
*
|
|
834
|
+
* @param id - Trigger UUID
|
|
835
|
+
* @param data - Fields to update
|
|
836
|
+
* @returns The updated trigger
|
|
837
|
+
*/
|
|
838
|
+
update: async (id, data) => {
|
|
839
|
+
const { data: result, error } = await this.client.PUT(
|
|
840
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
841
|
+
"/api/v1/email-triggers/{trigger_id}", {
|
|
842
|
+
params: { path: { trigger_id: id } },
|
|
843
|
+
body: data,
|
|
844
|
+
});
|
|
845
|
+
if (error)
|
|
846
|
+
throw this.handleError(error);
|
|
847
|
+
return result;
|
|
848
|
+
},
|
|
849
|
+
/**
|
|
850
|
+
* Delete a trigger.
|
|
851
|
+
*
|
|
852
|
+
* @param id - Trigger UUID
|
|
853
|
+
*/
|
|
854
|
+
delete: async (id) => {
|
|
855
|
+
const { error } = await this.client.DELETE(
|
|
856
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
857
|
+
"/api/v1/email-triggers/{trigger_id}", { params: { path: { trigger_id: id } } });
|
|
858
|
+
if (error)
|
|
859
|
+
throw this.handleError(error);
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* Subscriber note management operations.
|
|
864
|
+
*/
|
|
865
|
+
notes = {
|
|
866
|
+
/**
|
|
867
|
+
* Create a note for a subscriber.
|
|
868
|
+
*
|
|
869
|
+
* @param subscriberId - Subscriber UUID
|
|
870
|
+
* @param data - Note data
|
|
871
|
+
* @returns The created note
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const note = await client.notes.create('subscriber-uuid', {
|
|
876
|
+
* content: 'Customer inquiry about pricing.',
|
|
877
|
+
* source: 'contact_form',
|
|
878
|
+
* subject: 'SubscribeFlow',
|
|
879
|
+
* });
|
|
880
|
+
* ```
|
|
881
|
+
*/
|
|
882
|
+
create: async (subscriberId, data) => {
|
|
883
|
+
const { data: result, error } = await this.client.POST(
|
|
884
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
885
|
+
"/api/v1/subscribers/{subscriber_id}/notes", {
|
|
886
|
+
params: { path: { subscriber_id: subscriberId } },
|
|
887
|
+
body: data,
|
|
888
|
+
});
|
|
889
|
+
if (error)
|
|
890
|
+
throw this.handleError(error);
|
|
891
|
+
return result;
|
|
892
|
+
},
|
|
893
|
+
/**
|
|
894
|
+
* List notes for a subscriber.
|
|
895
|
+
*
|
|
896
|
+
* @param subscriberId - Subscriber UUID
|
|
897
|
+
* @param options - Filter and pagination options
|
|
898
|
+
* @returns Paginated list of notes
|
|
899
|
+
*/
|
|
900
|
+
list: async (subscriberId, options) => {
|
|
901
|
+
const { data: result, error } = await this.client.GET(
|
|
902
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
903
|
+
"/api/v1/subscribers/{subscriber_id}/notes", {
|
|
904
|
+
params: { path: { subscriber_id: subscriberId }, query: options },
|
|
905
|
+
});
|
|
906
|
+
if (error)
|
|
907
|
+
throw this.handleError(error);
|
|
908
|
+
return result;
|
|
909
|
+
},
|
|
910
|
+
/**
|
|
911
|
+
* Get a note by ID.
|
|
912
|
+
*
|
|
913
|
+
* @param subscriberId - Subscriber UUID
|
|
914
|
+
* @param noteId - Note UUID
|
|
915
|
+
* @returns The note
|
|
916
|
+
*/
|
|
917
|
+
get: async (subscriberId, noteId) => {
|
|
918
|
+
const { data: result, error } = await this.client.GET(
|
|
919
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
920
|
+
"/api/v1/subscribers/{subscriber_id}/notes/{note_id}", {
|
|
921
|
+
params: {
|
|
922
|
+
path: { subscriber_id: subscriberId, note_id: noteId },
|
|
923
|
+
},
|
|
924
|
+
});
|
|
925
|
+
if (error)
|
|
926
|
+
throw this.handleError(error);
|
|
927
|
+
return result;
|
|
928
|
+
},
|
|
929
|
+
/**
|
|
930
|
+
* Update a note.
|
|
931
|
+
*
|
|
932
|
+
* @param subscriberId - Subscriber UUID
|
|
933
|
+
* @param noteId - Note UUID
|
|
934
|
+
* @param data - Fields to update
|
|
935
|
+
* @returns The updated note
|
|
936
|
+
*/
|
|
937
|
+
update: async (subscriberId, noteId, data) => {
|
|
938
|
+
const { data: result, error } = await this.client.PUT(
|
|
939
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
940
|
+
"/api/v1/subscribers/{subscriber_id}/notes/{note_id}", {
|
|
941
|
+
params: {
|
|
942
|
+
path: { subscriber_id: subscriberId, note_id: noteId },
|
|
943
|
+
},
|
|
944
|
+
body: data,
|
|
945
|
+
});
|
|
946
|
+
if (error)
|
|
947
|
+
throw this.handleError(error);
|
|
948
|
+
return result;
|
|
949
|
+
},
|
|
950
|
+
/**
|
|
951
|
+
* Delete a note.
|
|
952
|
+
*
|
|
953
|
+
* @param subscriberId - Subscriber UUID
|
|
954
|
+
* @param noteId - Note UUID
|
|
955
|
+
*/
|
|
956
|
+
delete: async (subscriberId, noteId) => {
|
|
957
|
+
const { error } = await this.client.DELETE(
|
|
958
|
+
// @ts-expect-error - path will be available after OpenAPI spec regeneration
|
|
959
|
+
"/api/v1/subscribers/{subscriber_id}/notes/{note_id}", {
|
|
960
|
+
params: {
|
|
961
|
+
path: { subscriber_id: subscriberId, note_id: noteId },
|
|
962
|
+
},
|
|
963
|
+
});
|
|
964
|
+
if (error)
|
|
965
|
+
throw this.handleError(error);
|
|
966
|
+
},
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* Create a Preference Center client with JWT token auth.
|
|
970
|
+
*
|
|
971
|
+
* @param token - JWT token from subscribers.generateToken()
|
|
972
|
+
* @returns Object with preference center methods
|
|
973
|
+
*/
|
|
974
|
+
preferenceCenter(token) {
|
|
975
|
+
const baseUrl = this.config.baseUrl;
|
|
976
|
+
const pcClient = createClient({
|
|
977
|
+
baseUrl,
|
|
978
|
+
headers: { "Content-Type": "application/json" },
|
|
979
|
+
});
|
|
980
|
+
const handleErr = this.handleError.bind(this);
|
|
981
|
+
return {
|
|
982
|
+
getPreferences: async () => {
|
|
983
|
+
const { data: result, error } = await pcClient.GET("/preference-center", { params: { query: { token } } });
|
|
984
|
+
if (error)
|
|
985
|
+
throw handleErr(error);
|
|
986
|
+
return result;
|
|
987
|
+
},
|
|
988
|
+
subscribeTag: async (tagId) => {
|
|
989
|
+
const { data: result, error } = await pcClient.PUT("/preference-center/tags/{tag_id}", {
|
|
990
|
+
params: { path: { tag_id: tagId }, query: { token } },
|
|
991
|
+
});
|
|
992
|
+
if (error)
|
|
993
|
+
throw handleErr(error);
|
|
994
|
+
return result;
|
|
995
|
+
},
|
|
996
|
+
unsubscribeTag: async (tagId) => {
|
|
997
|
+
const { data: result, error } = await pcClient.DELETE("/preference-center/tags/{tag_id}", {
|
|
998
|
+
params: { path: { tag_id: tagId }, query: { token } },
|
|
999
|
+
});
|
|
1000
|
+
if (error)
|
|
1001
|
+
throw handleErr(error);
|
|
1002
|
+
return result;
|
|
1003
|
+
},
|
|
1004
|
+
exportData: async () => {
|
|
1005
|
+
const { data: result, error } = await pcClient.GET("/preference-center/data-export", { params: { query: { token } } });
|
|
1006
|
+
if (error)
|
|
1007
|
+
throw handleErr(error);
|
|
1008
|
+
return result;
|
|
1009
|
+
},
|
|
1010
|
+
deleteAccount: async () => {
|
|
1011
|
+
const { data: result, error } = await pcClient.DELETE("/preference-center/account", { params: { query: { token } } });
|
|
1012
|
+
if (error)
|
|
1013
|
+
throw handleErr(error);
|
|
1014
|
+
return result;
|
|
1015
|
+
},
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Handle API errors and convert to SubscribeFlowError.
|
|
1020
|
+
*/
|
|
1021
|
+
handleError(error) {
|
|
1022
|
+
if (typeof error === "object" && error !== null) {
|
|
1023
|
+
const err = error;
|
|
1024
|
+
return new SubscribeFlowError(String(err.title || err.detail || "Unknown error"), Number(err.status || 500), String(err.type || "unknown"), String(err.detail || "An error occurred"), err.instance);
|
|
1025
|
+
}
|
|
1026
|
+
return new SubscribeFlowError("Unknown error", 500, "unknown", String(error));
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
//# sourceMappingURL=index.js.map
|