@bentonow/bento-node-sdk 1.0.4 → 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 CHANGED
@@ -1,4 +1,5 @@
1
1
  # Bento Node SDK
2
+
2
3
  <img align="right" src="https://app.bentonow.com/brand/logoanim.gif">
3
4
 
4
5
  > [!TIP]
@@ -16,30 +17,27 @@ Get started with our [📚 integration guides](https://docs.bentonow.com), or [
16
17
 
17
18
  [![Tests](https://github.com/bentonow/bento-node-sdk/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/bentonow/bento-node-sdk/actions/workflows/main.yml)
18
19
 
19
- Table of contents
20
- =================
21
-
22
-
23
- * [Features](#features)
24
- * [Requirements](#requirements)
25
- * [Getting started](#getting-started)
26
- * [Installation](#installation)
27
- * [Integration](#integration)
28
- * [Modules](#modules)
29
- * [Type Reference](#types-reference)
30
- * [Things to know](#things-to-know)
31
- * [Contributing](#contributing)
32
- * [License](#license)
20
+ # Table of contents
33
21
 
22
+ - [Features](#features)
23
+ - [Requirements](#requirements)
24
+ - [Getting started](#getting-started)
25
+ - [Installation](#installation)
26
+ - [Integration](#integration)
27
+ - [Modules](#modules)
28
+ - [Type Reference](#types-reference)
29
+ - [Things to know](#things-to-know)
30
+ - [Contributing](#contributing)
31
+ - [License](#license)
34
32
 
35
33
  ## Features
36
34
 
37
- * **Simple event tracking**: We make it easy for you to track user events and behavior in your application.
38
- * **Subscriber management**: Easily add, update, and remove subscribers from your Bento account.
39
- * **Custom fields**: Track and update custom fields for your subscribers to store additional data.
40
- * **Purchase tracking**: Monitor customer purchases and calculate lifetime value (LTV) for your subscribers.
41
- * **Batch operations**: Perform bulk imports of subscribers and events for efficient data management.
42
- * **TypeScript support**: The SDK is written in TypeScript and provides type definitions for a better development experience.
35
+ - **Simple event tracking**: We make it easy for you to track user events and behavior in your application.
36
+ - **Subscriber management**: Easily add, update, and remove subscribers from your Bento account.
37
+ - **Custom fields**: Track and update custom fields for your subscribers to store additional data.
38
+ - **Purchase tracking**: Monitor customer purchases and calculate lifetime value (LTV) for your subscribers.
39
+ - **Batch operations**: Perform bulk imports of subscribers and events for efficient data management.
40
+ - **TypeScript support**: The SDK is written in TypeScript and provides type definitions for a better development experience.
43
41
 
44
42
  ## Requirements
45
43
 
@@ -63,6 +61,7 @@ bun add @bentonow/bento-node-sdk
63
61
  ```
64
62
 
65
63
  ### Using Bun (Recommended)
64
+
66
65
  ```bash
67
66
  # Install dependencies
68
67
  bun install
@@ -84,6 +83,7 @@ bun run format
84
83
  ```
85
84
 
86
85
  ### Using npm
86
+
87
87
  ```bash
88
88
  # Install dependencies
89
89
  npm install
@@ -114,9 +114,13 @@ import { Analytics } from '@bentonow/bento-node-sdk';
114
114
  const bento = new Analytics({
115
115
  authentication: {
116
116
  publishableKey: 'bento-publishable-key',
117
- secretKey: 'bento-secret-key',
117
+ secretKey: 'bento-secret-key',
118
118
  },
119
119
  siteUuid: 'bento-site-uuid',
120
+ // Optional: Configure request timeout (default: 30000ms)
121
+ clientOptions: {
122
+ timeout: 30000,
123
+ },
120
124
  });
121
125
 
122
126
  bento.V1.track({
@@ -129,11 +133,11 @@ bento.V1.track({
129
133
  details: {
130
134
  fromCustomEvent: true,
131
135
  },
132
- }).then(result => console.log(result));
136
+ }).then((result) => console.log(result));
133
137
  ```
134
138
 
135
-
136
139
  ## Modules
140
+
137
141
  The Bento SDK provides several modules for different operations:
138
142
 
139
143
  ### Analytics (Base Module)
@@ -141,17 +145,20 @@ The Bento SDK provides several modules for different operations:
141
145
  Core functionality for tracking events and managing subscribers.
142
146
 
143
147
  ### Convenience Helpers
148
+
144
149
  #### tagSubscriber
150
+
145
151
  Tags a subscriber with a specific tag.
146
152
 
147
153
  ```javascript
148
154
  bento.V1.tagSubscriber({
149
155
  email: 'user@example.com',
150
156
  tagName: 'New Customer',
151
- }).then(result => console.log(result));
157
+ }).then((result) => console.log(result));
152
158
  ```
153
159
 
154
160
  #### addSubscriber
161
+
155
162
  Adds a new subscriber to your Bento account.
156
163
 
157
164
  ```javascript
@@ -161,37 +168,42 @@ bento.V1.addSubscriber({
161
168
  firstName: 'John',
162
169
  lastName: 'Doe',
163
170
  },
164
- }).then(result => console.log(result));
171
+ }).then((result) => console.log(result));
165
172
  ```
166
173
 
167
174
  #### removeSubscriber
175
+
168
176
  Removes a subscriber from your Bento account.
169
177
 
170
178
  ```javascript
171
179
  bento.V1.removeSubscriber({
172
180
  email: 'user@example.com',
173
- }).then(result => console.log(result));
181
+ }).then((result) => console.log(result));
174
182
  ```
175
183
 
176
184
  #### upsertSubscriber
177
- Updates existing subscriber or creates a new one if they don't exist:
185
+
186
+ Creates or updates a subscriber. The SDK queues the import job and then attempts to fetch
187
+ the subscriber record once the job has been accepted.
178
188
 
179
189
  ```javascript
180
- await analytics.V1.upsertSubscriber({
190
+ const subscriber = await analytics.V1.upsertSubscriber({
181
191
  email: 'user@example.com',
182
192
  fields: {
183
193
  firstName: 'John',
184
194
  lastName: 'Doe',
185
- company: 'Acme Inc'
195
+ company: 'Acme Inc',
186
196
  },
187
197
  tags: 'lead,mql',
188
- remove_tags: 'customer'
198
+ remove_tags: 'customer',
189
199
  });
190
200
  ```
191
201
 
192
-
202
+ > **Note:** Imports are processed asynchronously by Bento and may take 1-5 minutes to
203
+ > complete. If the subscriber is not yet available, the method will return `null`.
193
204
 
194
205
  #### updateFields
206
+
195
207
  Updates custom fields for a subscriber.
196
208
 
197
209
  ```javascript
@@ -200,10 +212,11 @@ bento.V1.updateFields({
200
212
  fields: {
201
213
  lastPurchaseDate: new Date(),
202
214
  },
203
- }).then(result => console.log(result));
215
+ }).then((result) => console.log(result));
204
216
  ```
205
217
 
206
218
  #### track
219
+
207
220
  Tracks a custom event for a subscriber.
208
221
 
209
222
  ```javascript
@@ -213,10 +226,11 @@ bento.V1.track({
213
226
  details: {
214
227
  url: '/products',
215
228
  },
216
- }).then(result => console.log(result));
229
+ }).then((result) => console.log(result));
217
230
  ```
218
231
 
219
232
  #### trackPurchase
233
+
220
234
  Tracks a purchase event for a subscriber.
221
235
 
222
236
  ```javascript
@@ -226,15 +240,17 @@ bento.V1.trackPurchase({
226
240
  unique: { key: 'order-123' },
227
241
  value: { amount: 9999, currency: 'USD' },
228
242
  },
229
- }).then(result => console.log(result));
243
+ }).then((result) => console.log(result));
230
244
  ```
231
245
 
232
246
  ### Low Level API calls
247
+
233
248
  ### Batch
234
249
 
235
250
  Perform bulk operations for importing subscribers and events.
236
251
 
237
252
  #### importSubscribers
253
+
238
254
  Imports multiple subscribers in a single operation.
239
255
 
240
256
  ```javascript
@@ -243,10 +259,11 @@ bento.V1.Batch.importSubscribers({
243
259
  { email: 'user1@example.com', firstName: 'Alice' },
244
260
  { email: 'user2@example.com', firstName: 'Bob' },
245
261
  ],
246
- }).then(result => console.log(result));
262
+ }).then((result) => console.log(result));
247
263
  ```
248
264
 
249
265
  #### importEvents
266
+
250
267
  Imports multiple events in a single operation.
251
268
 
252
269
  ```javascript
@@ -255,13 +272,13 @@ bento.V1.Batch.importEvents({
255
272
  { email: 'user@example.com', type: '$login' },
256
273
  { email: 'user@example.com', type: '$pageView', details: { url: '/home' } },
257
274
  ],
258
- }).then(result => console.log(result));
275
+ }).then((result) => console.log(result));
259
276
  ```
260
277
 
261
-
262
278
  ### Broadcast Management
263
279
 
264
280
  #### getBroadcasts
281
+
265
282
  Retrieves all broadcasts:
266
283
 
267
284
  ```javascript
@@ -269,45 +286,53 @@ const broadcasts = await analytics.V1.Broadcasts.getBroadcasts();
269
286
  ```
270
287
 
271
288
  #### createBroadcast
289
+
272
290
  Creates new broadcast campaigns:
273
291
 
274
292
  ```javascript
275
- const broadcasts = await analytics.V1.Broadcasts.createBroadcast([{
276
- name: 'Weekly Newsletter',
277
- subject: 'Your Weekly Update',
278
- content: '<p>Hi {{ name }},</p>...',
279
- type: 'html',
280
- from: {
281
- name: 'John Doe',
282
- email: 'john@example.com'
293
+ const broadcasts = await analytics.V1.Broadcasts.createBroadcast([
294
+ {
295
+ name: 'Weekly Newsletter',
296
+ subject: 'Your Weekly Update',
297
+ content: '<p>Hi {{ name }},</p>...',
298
+ type: 'html',
299
+ from: {
300
+ name: 'John Doe',
301
+ email: 'john@example.com',
302
+ },
303
+ inclusive_tags: 'lead,mql',
304
+ exclusive_tags: 'unsubscribed',
305
+ segment_id: 'segment_123',
306
+ batch_size_per_hour: 1000,
283
307
  },
284
- inclusive_tags: 'lead,mql',
285
- exclusive_tags: 'unsubscribed',
286
- segment_id: 'segment_123',
287
- batch_size_per_hour: 1000
288
- }]);
308
+ ]);
289
309
  ```
290
310
 
291
311
  ### Transactional Emails
292
312
 
293
313
  #### createEmails
314
+
294
315
  Creates a new transactional email:
295
316
 
296
317
  ```javascript
297
318
  const result = await bento.V1.Batch.sendTransactionalEmails({
298
- emails: [{
299
- to: 'recipient@example.com', // just the email, recipient name is ignored.
300
- from: 'sender@example.com', // MUST be an existing Author in your account (Emails -> Authors)
301
- subject: 'Welcome {{ name }}',
302
- html_body: '<p>Hello {{ name }}, welcome to our service!</p>',
303
- transactional: false, // Set to true to send as a transactional email IF you want to ignore if the user has unsubscribed. USE WITH CAUTION!
304
- personalizations: {
305
- name: 'John Doe',
306
- }
307
- }]
319
+ emails: [
320
+ {
321
+ to: 'recipient@example.com', // just the email, recipient name is ignored.
322
+ from: 'sender@example.com', // MUST be an existing Author in your account (Emails -> Authors)
323
+ subject: 'Welcome {{ name }}',
324
+ html_body: '<p>Hello {{ name }}, welcome to our service!</p>',
325
+ transactional: false, // Set to true to send as a transactional email IF you want to ignore if the user has unsubscribed. USE WITH CAUTION!
326
+ personalizations: {
327
+ name: 'John Doe',
328
+ },
329
+ },
330
+ ],
308
331
  });
309
332
  ```
333
+
310
334
  ### Email Structure
335
+
311
336
  Each email object requires:
312
337
 
313
338
  - **to:** Recipient email address
@@ -323,10 +348,10 @@ Each email object requires:
323
348
  - **Errors:** Throws TooFewEmailsError or TooManyEmailsError for invalid counts
324
349
  - **Returns:** Number of emails successfully queued
325
350
 
326
-
327
351
  ### Statistics
328
352
 
329
353
  #### getSiteStats
354
+
330
355
  Retrieves overall site statistics:
331
356
 
332
357
  ```javascript
@@ -343,6 +368,7 @@ const stats = await analytics.V1.Stats.getSiteStats();
343
368
  ```
344
369
 
345
370
  #### getSegmentStats
371
+
346
372
  Retrieves statistics for a specific segment:
347
373
 
348
374
  ```javascript
@@ -358,6 +384,7 @@ const segmentStats = await analytics.V1.Stats.getSegmentStats('segment_123');
358
384
  ```
359
385
 
360
386
  #### getReportStats
387
+
361
388
  Retrieves statistics for a specific report:
362
389
 
363
390
  ```javascript
@@ -375,32 +402,34 @@ const reportStats = await analytics.V1.Stats.getReportStats('report_123');
375
402
  // }
376
403
  ```
377
404
 
378
-
379
405
  ### Commands
380
406
 
381
407
  Execute specific commands for subscriber management.
382
408
 
383
409
  #### addTag
410
+
384
411
  Adds a tag to a subscriber.
385
412
 
386
413
  ```javascript
387
414
  bento.V1.Commands.addTag({
388
415
  email: 'user@example.com',
389
416
  tagName: 'VIP',
390
- }).then(result => console.log(result));
417
+ }).then((result) => console.log(result));
391
418
  ```
392
419
 
393
420
  #### removeTag
421
+
394
422
  Removes a tag from a subscriber.
395
423
 
396
424
  ```javascript
397
425
  bento.V1.Commands.removeTag({
398
426
  email: 'user@example.com',
399
427
  tagName: 'VIP',
400
- }).then(result => console.log(result));
428
+ }).then((result) => console.log(result));
401
429
  ```
402
430
 
403
431
  #### addField
432
+
404
433
  Adds a custom field to a subscriber.
405
434
 
406
435
  ```javascript
@@ -410,17 +439,18 @@ bento.V1.Commands.addField({
410
439
  key: 'favoriteColor',
411
440
  value: 'blue',
412
441
  },
413
- }).then(result => console.log(result));
442
+ }).then((result) => console.log(result));
414
443
  ```
415
444
 
416
445
  #### removeField
446
+
417
447
  Removes a custom field from a subscriber.
418
448
 
419
449
  ```javascript
420
450
  bento.V1.Commands.removeField({
421
451
  email: 'user@example.com',
422
452
  fieldName: 'favoriteColor',
423
- }).then(result => console.log(result));
453
+ }).then((result) => console.log(result));
424
454
  ```
425
455
 
426
456
  ### Experimental
@@ -428,39 +458,41 @@ bento.V1.Commands.removeField({
428
458
  Access experimental features (use with caution).
429
459
 
430
460
  #### validateEmail
461
+
431
462
  Attempts to validate an email address.
432
463
 
433
464
  ```javascript
434
465
  bento.V1.Experimental.validateEmail({
435
466
  email: 'user@example.com',
436
- }).then(result => console.log(result));
467
+ }).then((result) => console.log(result));
437
468
  ```
438
469
 
439
470
  #### guessGender
471
+
440
472
  Attempts to guess the gender based on a given name.
441
473
 
442
474
  ```javascript
443
475
  bento.V1.Experimental.guessGender({
444
476
  name: 'Alex',
445
- }).then(result => console.log(result));
477
+ }).then((result) => console.log(result));
446
478
  ```
447
479
 
448
480
  is blacklisted:
449
481
 
450
482
  ```javascript
451
483
  const blacklistStatus = await analytics.V1.Experimental.getBlacklistStatus({
452
- domain: 'example.com'
484
+ domain: 'example.com',
453
485
  // or ipAddress: '192.168.1.1'
454
486
  });
455
487
  ```
456
488
 
457
489
  #### getContentModeration
490
+
458
491
  Performs content moderation on text:
459
492
 
460
493
  ```javascript
461
- const moderationResult = await analytics.V1.Experimental.getContentModeration(
462
- 'Content to moderate'
463
- );
494
+ const moderationResult =
495
+ await analytics.V1.Experimental.getContentModeration('Content to moderate');
464
496
  // Returns:
465
497
  // {
466
498
  // flagged: boolean,
@@ -479,6 +511,7 @@ const moderationResult = await analytics.V1.Experimental.getContentModeration(
479
511
  ```
480
512
 
481
513
  #### geoLocateIP
514
+
482
515
  Gets detailed geolocation information for an IP address:
483
516
 
484
517
  ```javascript
@@ -498,19 +531,21 @@ const location = await analytics.V1.Experimental.geoLocateIP('192.168.1.1');
498
531
  Manage custom fields for your subscribers.
499
532
 
500
533
  #### getFields
534
+
501
535
  Retrieves all custom fields defined in your Bento account.
502
536
 
503
537
  ```javascript
504
- bento.V1.Fields.getFields().then(fields => console.log(fields));
538
+ bento.V1.Fields.getFields().then((fields) => console.log(fields));
505
539
  ```
506
540
 
507
541
  #### createField
542
+
508
543
  Creates a new custom field in your Bento account.
509
544
 
510
545
  ```javascript
511
546
  bento.V1.Fields.createField({
512
547
  key: 'loyaltyPoints',
513
- }).then(result => console.log(result));
548
+ }).then((result) => console.log(result));
514
549
  ```
515
550
 
516
551
  ### Forms
@@ -518,10 +553,11 @@ bento.V1.Fields.createField({
518
553
  Retrieve form responses.
519
554
 
520
555
  #### getResponses
556
+
521
557
  Retrieves responses for a specific form.
522
558
 
523
559
  ```javascript
524
- bento.V1.Forms.getResponses('form-id-123').then(responses => console.log(responses));
560
+ bento.V1.Forms.getResponses('form-id-123').then((responses) => console.log(responses));
525
561
  ```
526
562
 
527
563
  ### Subscribers
@@ -529,21 +565,23 @@ bento.V1.Forms.getResponses('form-id-123').then(responses => console.log(respons
529
565
  Manage individual subscribers.
530
566
 
531
567
  #### getSubscribers
568
+
532
569
  Retrieves subscriber information.
533
570
 
534
571
  ```javascript
535
572
  bento.V1.Subscribers.getSubscribers({
536
573
  email: 'user@example.com',
537
- }).then(subscriber => console.log(subscriber));
574
+ }).then((subscriber) => console.log(subscriber));
538
575
  ```
539
576
 
540
577
  #### createSubscriber
578
+
541
579
  Creates a new subscriber in your Bento account.
542
580
 
543
581
  ```javascript
544
582
  bento.V1.Subscribers.createSubscriber({
545
583
  email: 'newuser@example.com',
546
- }).then(result => console.log(result));
584
+ }).then((result) => console.log(result));
547
585
  ```
548
586
 
549
587
  ### Tags
@@ -551,19 +589,111 @@ bento.V1.Subscribers.createSubscriber({
551
589
  Create and manage tags for subscriber segmentation.
552
590
 
553
591
  #### getTags
592
+
554
593
  Retrieves all tags defined in your Bento account.
555
594
 
556
595
  ```javascript
557
- bento.V1.Tags.getTags().then(tags => console.log(tags));
596
+ bento.V1.Tags.getTags().then((tags) => console.log(tags));
558
597
  ```
559
598
 
560
599
  #### createTag
600
+
561
601
  Creates a new tag in your Bento account.
562
602
 
563
603
  ```javascript
564
604
  bento.V1.Tags.createTag({
565
605
  name: 'Premium Customer',
566
- }).then(result => console.log(result));
606
+ }).then((result) => console.log(result));
607
+ ```
608
+
609
+ ### Sequences
610
+
611
+ Retrieve sequences and their associated email templates.
612
+
613
+ #### getSequences
614
+
615
+ Retrieves all sequences for the site, including their email templates.
616
+
617
+ ```javascript
618
+ const sequences = await bento.V1.Sequences.getSequences();
619
+ // Returns:
620
+ // [
621
+ // {
622
+ // id: '123',
623
+ // type: 'sequence',
624
+ // attributes: {
625
+ // name: 'Welcome Sequence',
626
+ // created_at: '2024-01-01T00:00:00Z',
627
+ // email_templates: [
628
+ // { id: 1, subject: 'Welcome!', stats: null },
629
+ // { id: 2, subject: 'Getting Started', stats: null }
630
+ // ]
631
+ // }
632
+ // }
633
+ // ]
634
+ ```
635
+
636
+ ### Workflows
637
+
638
+ Retrieve workflows and their associated email templates.
639
+
640
+ #### getWorkflows
641
+
642
+ Retrieves all workflows for the site, including their email templates.
643
+
644
+ ```javascript
645
+ const workflows = await bento.V1.Workflows.getWorkflows();
646
+ // Returns:
647
+ // [
648
+ // {
649
+ // id: '456',
650
+ // type: 'workflow',
651
+ // attributes: {
652
+ // name: 'Onboarding Workflow',
653
+ // created_at: '2024-01-01T00:00:00Z',
654
+ // email_templates: [
655
+ // { id: 3, subject: 'Step 1', stats: null },
656
+ // { id: 4, subject: 'Step 2', stats: null }
657
+ // ]
658
+ // }
659
+ // }
660
+ // ]
661
+ ```
662
+
663
+ ### Email Templates
664
+
665
+ Retrieve and update email templates used in sequences and workflows.
666
+
667
+ #### getEmailTemplate
668
+
669
+ Retrieves a single email template by ID.
670
+
671
+ ```javascript
672
+ const template = await bento.V1.EmailTemplates.getEmailTemplate({ id: 123 });
673
+ // Returns:
674
+ // {
675
+ // id: '123',
676
+ // type: 'email_template',
677
+ // attributes: {
678
+ // name: 'Welcome Email',
679
+ // subject: 'Welcome to our service!',
680
+ // html: '<p>Hello {{ name }}, welcome!</p>',
681
+ // created_at: '2024-01-01T00:00:00Z',
682
+ // stats: null
683
+ // }
684
+ // }
685
+ ```
686
+
687
+ #### updateEmailTemplate
688
+
689
+ Updates an email template's subject and/or HTML content.
690
+
691
+ ```javascript
692
+ const updatedTemplate = await bento.V1.EmailTemplates.updateEmailTemplate({
693
+ id: 123,
694
+ subject: 'Updated Subject Line',
695
+ html: '<p>Updated HTML content with {{ name }}</p>',
696
+ });
567
697
  ```
568
698
 
569
699
  For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
@@ -576,7 +706,7 @@ AddFieldParameters `<S>`
576
706
  Parameters for adding a field to a subscriber.
577
707
 
578
708
  | Property | Type | Required | Description |
579
- |----------|------------------------------|----------|----------------------------|
709
+ | -------- | ---------------------------- | -------- | -------------------------- |
580
710
  | email | string | ✔️ | Subscriber's email address |
581
711
  | field | { key: keyof S; value: any } | ✔️ | Field to add |
582
712
 
@@ -585,17 +715,17 @@ Parameters for adding a field to a subscriber.
585
715
  Parameters for adding a new subscriber.
586
716
 
587
717
  | Property | Type | Required | Description |
588
- |----------|---------------|----------|--------------------------------------|
589
- | date | Date | ❌ | Date of subscription |
718
+ | -------- | ------------- | -------- | ------------------------------------ |
719
+ | date | Date | ❌ | Date of subscription |
590
720
  | email | string | ✔️ | Subscriber's email address |
591
- | fields | Partial `<S>` | ❌ | Additional fields for the subscriber |
721
+ | fields | Partial `<S>` | ❌ | Additional fields for the subscriber |
592
722
 
593
723
  ### AddTagParameters
594
724
 
595
725
  Parameters for adding a tag to a subscriber.
596
726
 
597
727
  | Property | Type | Required | Description |
598
- |----------|--------|----------|----------------------------|
728
+ | -------- | ------ | -------- | -------------------------- |
599
729
  | email | string | ✔️ | Subscriber's email address |
600
730
  | tagName | string | ✔️ | Name of the tag to add |
601
731
 
@@ -604,7 +734,7 @@ Parameters for adding a tag to a subscriber.
604
734
  Parameters for batch importing events.
605
735
 
606
736
  | Property | Type | Required | Description |
607
- |----------|-------------------------|----------|---------------------------|
737
+ | -------- | ----------------------- | -------- | ------------------------- |
608
738
  | events | BentoEvent `<S>`, `<E>` | ✔️ | Array of events to import |
609
739
 
610
740
  ### BatchImportSubscribersParameter `<S>`
@@ -612,10 +742,11 @@ Parameters for batch importing events.
612
742
  Parameters for batch importing subscribers.
613
743
 
614
744
  | Property | Type | Required | Description |
615
- |-------------|---------------------------------------|----------|--------------------------------|
745
+ | ----------- | ------------------------------------- | -------- | ------------------------------ |
616
746
  | subscribers | ({ email: string } & Partial `<S>`)[] | ✔️ | Array of subscribers to import |
617
747
 
618
748
  ### BentoEvent `<S>`, `<E>`
749
+
619
750
  Represents different types of events in Bento. It's a union of the following event types:
620
751
 
621
752
  - BaseEvent `<E>`
@@ -630,17 +761,17 @@ Represents different types of events in Bento. It's a union of the following eve
630
761
  Details of a purchase event.
631
762
 
632
763
  | Property | Type | Required | Description |
633
- |----------|--------------------------------------|----------|------------------------------------|
764
+ | -------- | ------------------------------------ | -------- | ---------------------------------- |
634
765
  | unique | { key: string \| number } | ✔️ | Unique identifier for the purchase |
635
766
  | value | { currency: string; amount: number } | ✔️ | Value of the purchase |
636
- | cart | PurchaseCart | ❌ | Additional cart details |
767
+ | cart | PurchaseCart | ❌ | Additional cart details |
637
768
 
638
769
  ### ChangeEmailParameters
639
770
 
640
771
  Parameters for changing a subscriber's email.
641
772
 
642
773
  | Property | Type | Required | Description |
643
- |----------|--------|----------|-----------------------|
774
+ | -------- | ------ | -------- | --------------------- |
644
775
  | oldEmail | string | ✔️ | Current email address |
645
776
  | newEmail | string | ✔️ | New email address |
646
777
 
@@ -649,7 +780,7 @@ Parameters for changing a subscriber's email.
649
780
  Parameters for creating a new field.
650
781
 
651
782
  | Property | Type | Required | Description |
652
- |----------|--------|----------|----------------------|
783
+ | -------- | ------ | -------- | -------------------- |
653
784
  | key | string | ✔️ | Key of the new field |
654
785
 
655
786
  ### CreateTagParameters
@@ -657,7 +788,7 @@ Parameters for creating a new field.
657
788
  Parameters for creating a new tag.
658
789
 
659
790
  | Property | Type | Required | Description |
660
- |----------|--------|----------|---------------------|
791
+ | -------- | ------ | -------- | ------------------- |
661
792
  | name | string | ✔️ | Name of the new tag |
662
793
 
663
794
  ### Subscriber `<S>`
@@ -665,7 +796,7 @@ Parameters for creating a new tag.
665
796
  Represents a subscriber in Bento.
666
797
 
667
798
  | Property | Type | Required | Description |
668
- |------------|----------------------------|----------|------------------------------|
799
+ | ---------- | -------------------------- | -------- | ---------------------------- |
669
800
  | attributes | SubscriberAttributes `<S>` | ✔️ | Attributes of the subscriber |
670
801
  | id | string | ✔️ | Unique identifier |
671
802
  | type | EntityType.VISITOR | ✔️ | Type of the entity |
@@ -675,26 +806,25 @@ Represents a subscriber in Bento.
675
806
  Parameters for tracking an event.
676
807
 
677
808
  | Property | Type | Required | Description |
678
- |----------|------------------------|----------|-------------------------------------|
809
+ | -------- | ---------------------- | -------- | ----------------------------------- |
679
810
  | email | string | ✔️ | Subscriber's email address |
680
811
  | type | string | ✔️ | Type of the event |
681
- | details | { [key: string]: any } | ❌ | Additional details of the event |
682
- | fields | Partial `<S>` | ❌ | Fields to update for the subscriber |
812
+ | details | { [key: string]: any } | ❌ | Additional details of the event |
813
+ | fields | Partial `<S>` | ❌ | Fields to update for the subscriber |
683
814
 
684
815
  ### ValidateEmailParameters
685
816
 
686
817
  Parameters for validating an email address.
687
818
 
688
819
  | Property | Type | Required | Description |
689
- |-----------|--------|----------|--------------------------------|
820
+ | --------- | ------ | -------- | ------------------------------ |
690
821
  | email | string | ✔️ | Email address to validate |
691
- | ip | string | ❌ | IP address of the user |
692
- | name | string | ❌ | Name associated with the email |
693
- | userAgent | string | ❌ | User agent string |
822
+ | ip | string | ❌ | IP address of the user |
823
+ | name | string | ❌ | Name associated with the email |
824
+ | userAgent | string | ❌ | User agent string |
694
825
 
695
826
  Note: The `S` and `E` generic types are used for TypeScript support. `S` represents the type of your subscriber's custom fields, and `E` represents the prefix used for custom events. For more details, refer to the TypeScript section of the documentation.
696
827
 
697
-
698
828
  ## Things to know
699
829
 
700
830
  - All events must be identified with an email address.
@@ -702,6 +832,32 @@ Note: The `S` and `E` generic types are used for TypeScript support. `S` represe
702
832
  - The SDK supports TypeScript with generics for custom fields and events.
703
833
  - Batch operations are available for importing subscribers and events efficiently.
704
834
  - The SDK doesn't currently support anonymous events (coming soon).
835
+ - Requests have a default timeout of 30 seconds, configurable via `clientOptions.timeout`.
836
+
837
+ ## Error Handling
838
+
839
+ The SDK exports several error types for specific error conditions:
840
+
841
+ ```javascript
842
+ import {
843
+ NotAuthorizedError, // 401 - Invalid credentials
844
+ RateLimitedError, // 429 - Too many requests
845
+ AuthorNotAuthorizedError, // Author not permitted to send emails
846
+ RequestTimeoutError, // Request exceeded timeout
847
+ } from '@bentonow/bento-node-sdk';
848
+
849
+ try {
850
+ await bento.V1.Tags.getTags();
851
+ } catch (error) {
852
+ if (error instanceof RequestTimeoutError) {
853
+ // Handle timeout - maybe retry
854
+ } else if (error instanceof RateLimitedError) {
855
+ // Handle rate limiting - back off and retry
856
+ } else if (error instanceof NotAuthorizedError) {
857
+ // Handle auth error - check credentials
858
+ }
859
+ }
860
+ ```
705
861
 
706
862
  ## Contributing
707
863