@bentonow/bento-node-sdk 0.2.1 → 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.
Files changed (76) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +604 -1031
  3. package/dist/index.d.ts +9 -9
  4. package/dist/index.js +1306 -5
  5. package/dist/sdk/batch/enums.d.ts +8 -8
  6. package/dist/sdk/batch/errors.d.ts +18 -18
  7. package/dist/sdk/batch/events.d.ts +71 -71
  8. package/dist/sdk/batch/index.d.ts +55 -55
  9. package/dist/sdk/batch/types.d.ts +37 -37
  10. package/dist/sdk/broadcasts/index.d.ts +26 -0
  11. package/dist/sdk/broadcasts/types.d.ts +32 -0
  12. package/dist/sdk/client/errors.d.ts +12 -6
  13. package/dist/sdk/client/index.d.ts +94 -64
  14. package/dist/sdk/client/types.d.ts +3 -3
  15. package/dist/sdk/commands/enums.d.ts +12 -12
  16. package/dist/sdk/commands/index.d.ts +79 -79
  17. package/dist/sdk/commands/types.d.ts +32 -32
  18. package/dist/sdk/email-templates/index.d.ts +21 -0
  19. package/dist/sdk/email-templates/types.d.ts +23 -0
  20. package/dist/sdk/enums.d.ts +12 -9
  21. package/dist/sdk/errors.d.ts +2 -2
  22. package/dist/sdk/experimental/index.d.ts +75 -57
  23. package/dist/sdk/experimental/types.d.ts +71 -41
  24. package/dist/sdk/fields/index.d.ts +29 -29
  25. package/dist/sdk/fields/types.d.ts +17 -17
  26. package/dist/sdk/forms/index.d.ts +14 -14
  27. package/dist/sdk/forms/types.d.ts +28 -28
  28. package/dist/sdk/index.d.ts +11 -8
  29. package/dist/sdk/interfaces.d.ts +17 -13
  30. package/dist/sdk/sequences/index.d.ts +13 -0
  31. package/dist/sdk/sequences/types.d.ts +18 -0
  32. package/dist/sdk/stats/index.d.ts +24 -0
  33. package/dist/sdk/stats/types.d.ts +26 -0
  34. package/dist/sdk/subscribers/index.d.ts +20 -20
  35. package/dist/sdk/subscribers/types.d.ts +25 -25
  36. package/dist/sdk/tags/index.d.ts +20 -20
  37. package/dist/sdk/tags/types.d.ts +17 -17
  38. package/dist/sdk/types.d.ts +41 -41
  39. package/dist/sdk/workflows/index.d.ts +13 -0
  40. package/dist/sdk/workflows/types.d.ts +18 -0
  41. package/dist/versions/v1/index.d.ts +168 -132
  42. package/dist/versions/v1/types.d.ts +31 -31
  43. package/package.json +31 -44
  44. package/src/sdk/batch/events.ts +1 -1
  45. package/src/sdk/batch/index.ts +15 -22
  46. package/src/sdk/broadcasts/index.ts +44 -0
  47. package/src/sdk/broadcasts/types.ts +38 -0
  48. package/src/sdk/client/errors.ts +14 -0
  49. package/src/sdk/client/index.ts +205 -49
  50. package/src/sdk/commands/index.ts +54 -89
  51. package/src/sdk/email-templates/index.ts +39 -0
  52. package/src/sdk/email-templates/types.ts +27 -0
  53. package/src/sdk/enums.ts +3 -0
  54. package/src/sdk/experimental/index.ts +44 -26
  55. package/src/sdk/experimental/types.ts +35 -0
  56. package/src/sdk/fields/index.ts +1 -3
  57. package/src/sdk/forms/index.ts +4 -9
  58. package/src/sdk/forms/types.ts +1 -7
  59. package/src/sdk/index.ts +3 -0
  60. package/src/sdk/interfaces.ts +4 -0
  61. package/src/sdk/sequences/index.ts +21 -0
  62. package/src/sdk/sequences/types.ts +21 -0
  63. package/src/sdk/stats/index.ts +37 -0
  64. package/src/sdk/stats/types.ts +28 -0
  65. package/src/sdk/subscribers/index.ts +5 -15
  66. package/src/sdk/tags/index.ts +1 -3
  67. package/src/sdk/types.ts +1 -1
  68. package/src/sdk/workflows/index.ts +21 -0
  69. package/src/sdk/workflows/types.ts +21 -0
  70. package/src/versions/v1/index.ts +65 -10
  71. package/dist/bento-node-sdk.cjs.development.js +0 -2071
  72. package/dist/bento-node-sdk.cjs.development.js.map +0 -1
  73. package/dist/bento-node-sdk.cjs.production.min.js +0 -2
  74. package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
  75. package/dist/bento-node-sdk.esm.js +0 -2063
  76. package/dist/bento-node-sdk.esm.js.map +0 -1
package/README.md CHANGED
@@ -1,1295 +1,868 @@
1
- # Bento SDK for Node.JS
1
+ # Bento Node SDK
2
2
 
3
- [![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)
3
+ <img align="right" src="https://app.bentonow.com/brand/logoanim.gif">
4
4
 
5
- 🍱 Simple, powerful analytics for Node.JS projects!
5
+ > [!TIP]
6
+ > Need help? Join our [Discord](https://discord.gg/ssXXFRmt5F) or email jesse@bentonow.com for personalized support.
6
7
 
7
- Track events, update data, record LTV and more in Node.JS. Data is stored in your Bento account so you can easily research and investigate what's going on.
8
+ The Bento Node.js SDK makes it quick and easy to build an excellent analytics experience in your Node.js application. We provide powerful and customizable APIs that can be used out-of-the-box to track your users' behavior and manage subscribers. We also expose low-level APIs so that you can build fully custom experiences.
8
9
 
9
- 👋 To get personalized support, please tweet @bento or email jesse@bentonow.com!
10
+ Get started with our [📚 integration guides](https://docs.bentonow.com), or [📘 browse the SDK reference](https://docs.bentonow.com/subscribers).
10
11
 
11
12
  🐶 Battle-tested by [NativShark](https://nativshark.com) Bento Production (a Bento customer)!
12
13
 
13
14
  ❤️ Thank you @HelloKashif from [IPInfo](https://ipinfo.io) for your contribution.
15
+
14
16
  ❤️ Thank you @jonsherrard from [Devular](https://www.devular.com/) for your contribution.
15
17
 
16
- - [Installation](#Installation)
17
- - [Get Started](#Get-Started)
18
- - [Modules](#Modules)
19
- - [Analytics (Base Module)](#analytics-base-module)
20
- - [tagSubscriber(parameters: TagSubscriberParameters): Promise\<boolean\>](#tagsubscriberparameters-tagsubscriberparameters-promiseboolean)
21
- - [addSubscriber(parameters: AddSubscriberParameters): Promise\<boolean\>](#addsubscriberparameters-addsubscriberparameters-promiseboolean)
22
- - [removeSubscriber(parameters: RemoveSubscriberParameters): Promise\<boolean\>](#removesubscriberparameters-removesubscriberparameters-promiseboolean)
23
- - [updateFields(parameters: UpdateFieldsParameters\<S\>): Promise\<boolean\>](#updatefieldsparameters-updatefieldsparameterss-promiseboolean)
24
- - [track(parameters: TrackParameters<S, E>): Promise<boolean>](#trackparameters-trackparameterss-e-promiseboolean)
25
- - [trackPurchase(parameters: TrackPurchaseParameters): Promise\<boolean\>](#trackpurchaseparameters-trackpurchaseparameters-promiseboolean)
26
- - [Batch](#Batch)
27
- - [.importSubscribers(parameters: BatchImportSubscribersParameter\<S\>): Promise\<number\>](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber)
28
- - [.importEvents(parameters: BatchImportEventsParameter\<S, E\>): Promise\<number\>](#batchimporteventsparameters-batchimporteventsparameters-e-promisenumber)
29
- - [.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>](#batchsendtransactionalemailsparameters-batchsendtransactionalemailsparameters-e-promisenumber)
30
- - [Commands](#Commands)
31
- - [.addTag(parameters: AddTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsaddtagparameters-addtagparameters-promisesubscribers--null)
32
- - [.removeTag(parameters: RemoveTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsremovetagparameters-removetagparameters-promisesubscribers--null)
33
- - [.addField(parameters: AddFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsaddfieldparameters-addfieldparameterss-promisesubscribers--null)
34
- - [.removeField(parameters: RemoveFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsremovefieldparameters-removefieldparameterss-promisesubscribers--null)
35
- - [.subscribe(parameters: SubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null)
36
- - [.unsubscribe(parameters: UnsubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null)
37
- - [Experimental](#Experimental)
38
- - [.validateEmail(parameters: ValidateEmailParameters): Promise\<boolean\>](#experimentalvalidateemailparameters-validateemailparameters-promiseboolean)
39
- - [.guessGender(parameters: GuessGenderParameters): Promise\<GuessGenderResponse\>](#experimentalguessgenderparameters-guessgenderparameters-promiseguessgenderresponse)
40
- - [.geolocate(parameters: GeolocateParameters): Promise\<LocationData | null\>](#experimentalgeolocateparameters-geolocateparameters-promiselocationdata--null)
41
- - [.checkBlacklist(parameters: BlacklistParameters): Promise\<BlacklistResponse\>](#experimentalcheckblacklistparameters-blacklistparameters-promiseblacklistresponse)
42
- - [Fields](#Fields)
43
- - [.getFields(): Promise\<Field[] | null\>](#fieldsgetfields-promisefield--null)
44
- - [.createField(parameters: CreateFieldParameters): Promise\<Field[] | null\>](#fieldscreatefieldparameters-createfieldparameters-promisefield--null)
45
- - [Forms](#Forms)
46
- - [.getResponses(formIdentifier: string): Promise\<FormResponse[] | null\>](#formsgetresponsesformidentifier-string-promiseformresponse--null)
47
- - [Subscribers](#Subscribers)
48
- - [.getSubscribers(parameters?: GetSubscribersParameters): Promise\<Subscriber\<S\> | null\>](#subscribersgetsubscribersparameters-getsubscribersparameters-promisesubscribers--null)
49
- - [.createSubscriber(parameters: CreateSubscriberParameters): Promise\<Subscriber\<S\> | null\>](#subscriberscreatesubscriberparameters-createsubscriberparameters-promisesubscribers--null)
50
- - [Tags](#Tags)
51
- - [.getTags(): Promise\<Tag[] | null\>](#tagsgettags-promisetag--null)
52
- - [.createTag(parameters: CreateTagParameters): Promise\<Tag[] | null\>](#tagscreatetagparameters-createtagparameters-promisetag--null)
53
- - [Types Reference](#Types-Reference)
54
- - [TypeScript](#TypeScript)
55
- - [Generics](#Generics)
56
- - [S](#s)
57
- - [E](#e)
58
- - [Things to Know](#Things-to-Know)
59
- - [Contributing](#Contributing)
60
- - [License](#License)
61
-
62
- ## Installation
63
-
64
- Run the following command in your project folder.
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)
65
19
 
66
- ```bash
67
- npm install @bentonow/bento-node-sdk --save
68
- ```
20
+ # Table of contents
69
21
 
70
- ## Getting Started
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)
71
32
 
72
- To get started with tracking your users in Bento, simply initialize the client and go wild.
33
+ ## Features
73
34
 
74
- The below example showcases using `track` and `trackPurchase` which are the two recommended functions you should lean on as they can trigger automations. If you need to upload a lot of data but do not wish to trigger automations, like when you sign up, then use [importSubscribers](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber) instead.
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.
75
41
 
76
- ```ts
77
- import { Analytics } from '@bentonow/bento-node-sdk';
42
+ ## Requirements
78
43
 
79
- const bento = new Analytics({
80
- authentication: {
81
- publishableKey: 'publishableKey',
82
- secretKey: 'secretKey',
83
- },
84
- logErrors: false, // Set to true to see the HTTP errors logged
85
- siteUuid: 'siteUuid',
86
- });
44
+ The Bento Node.js SDK requires Node.js version 12 or later.
87
45
 
88
- bento.V1.track({
89
- email: 'test@bentonow.com',
90
- type: '$formSubmitted',
91
- fields: {
92
- first_name: 'Test',
93
- last_name: 'Test',
94
- },
95
- details: {
96
- fromCustomEvent: true,
97
- },
98
- }).then(result => console.log(result)).catch(error => console.error(error));
46
+ Bento Account for a valid **SITE_UUID**, **BENTO_PUBLISHABLE_KEY** & **BENTO_SECRET_KEY**.
99
47
 
100
- bento.V1.trackPurchase({
101
- email: 'test@bentonow.com',
102
- purchaseDetails: {
103
- unique: { key: 1234 }, // this key stops duplicate order values being tracked
104
- value: { amount: 100, currency: 'USD' },
105
- },
106
- cart: {
107
- abandoned_checkout_url: 'https://example.com',
108
- },
109
- });
48
+ ## Getting started
110
49
 
111
- ```
50
+ ### Installation
112
51
 
113
- Read on to see what all you can do with the SDK.
52
+ Install the Bento SDK in your project folder:
114
53
 
115
- # Modules
116
-
117
- In addition to the top-level Analytics object, we also provide access to other parts of the API behind their corresponding modules. You can access these off of the main `Analytics` object.
54
+ ```bash
118
55
 
119
- The `Analytics` module also provides access to various versions of the API (currently just `V1`), and each of those provides access to the corresponding modules documented below.
56
+ # Using npm
57
+ npm install @bentonow/bento-node-sdk --save
120
58
 
121
- ## Analytics (Base Module)
59
+ # Using Bun
60
+ bun add @bentonow/bento-node-sdk
61
+ ```
122
62
 
123
- ### `tagSubscriber(parameters: TagSubscriberParameters): Promise<boolean>`
63
+ ### Using Bun (Recommended)
124
64
 
125
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.addTag`](#commandsaddtagparameters-addtagparameters-promisesubscribers--null) method.
65
+ ```bash
66
+ # Install dependencies
67
+ bun install
126
68
 
127
- Tags a subscriber with the specified email and tag. If either the tag or the user do not exist, they will be created in the system. If the user already has the tag, another tag event will be sent, triggering any automations that take place upon a tag being added to a subscriber. Please be aware of the potential consequences.
69
+ # Run tests
70
+ bun test
128
71
 
129
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
72
+ # Run tests with coverage
73
+ bun test:coverage
130
74
 
131
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
75
+ # Build the package
76
+ bun run build
132
77
 
133
- Reference Types: [TagSubscriberParameters](#TagSubscriberParameters)
78
+ # Lint code
79
+ bun run lint
134
80
 
135
- ```ts
136
- bento.V1.tagSubscriber({
137
- email: 'test@bentonow.com',
138
- tagName: 'Test Tag',
139
- })
140
- .then(result => console.log(result))
141
- .catch(error => console.error(error));
81
+ # Format code
82
+ bun run format
142
83
  ```
143
84
 
144
- ---
85
+ ### Using npm
145
86
 
146
- ### `addSubscriber(parameters: AddSubscriberParameters<S>): Promise<boolean>`
87
+ ```bash
88
+ # Install dependencies
89
+ npm install
147
90
 
148
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.subscribe`](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null) method.
91
+ # Run tests
92
+ npm run test:npm
149
93
 
150
- Creates a subscriber in the system. If the subscriber already exists, another subscribe event will be sent, triggering any automations that take place upon subscription. Please be aware of the potential consequences.
94
+ # Run tests with coverage
95
+ npm run test:coverage:npm
151
96
 
152
- You may optionally pass any fields that you wish to be set on the subscriber during creation.
97
+ # Build the package
98
+ npm run build:npm
153
99
 
154
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
100
+ # Lint code
101
+ npm run lint
155
102
 
156
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
103
+ # Format code
104
+ npm run format
105
+ ```
157
106
 
158
- Reference Types: [AddSubscriberParameters\<S\>](#addsubscriberparameterss)
107
+ ### Integration
159
108
 
160
- ```ts
161
- bento.V1.addSubscriber({
162
- email: 'test@bentonow.com',
163
- })
164
- .then(result => console.log(result))
165
- .catch(error => console.error(error));
109
+ Initialize the Bento client and start tracking events:
166
110
 
167
- bento.V1.addSubscriber({
168
- date: new Date('2021-08-20T01:32:57.530Z'),
169
- email: 'test@bentonow.com',
111
+ ```javascript
112
+ import { Analytics } from '@bentonow/bento-node-sdk';
113
+
114
+ const bento = new Analytics({
115
+ authentication: {
116
+ publishableKey: 'bento-publishable-key',
117
+ secretKey: 'bento-secret-key',
118
+ },
119
+ siteUuid: 'bento-site-uuid',
120
+ // Optional: Configure request timeout (default: 30000ms)
121
+ clientOptions: {
122
+ timeout: 30000,
123
+ },
124
+ });
125
+
126
+ bento.V1.track({
127
+ email: 'user@example.com',
128
+ type: '$formSubmitted',
170
129
  fields: {
171
- firstName: 'Test',
172
- lastName: 'Subscriber',
130
+ first_name: 'John',
131
+ last_name: 'Doe',
132
+ },
133
+ details: {
134
+ fromCustomEvent: true,
173
135
  },
174
- })
175
- .then(result => console.log(result))
176
- .catch(error => console.error(error));
136
+ }).then((result) => console.log(result));
177
137
  ```
178
138
 
179
- ---
139
+ ## Modules
180
140
 
181
- ### `removeSubscriber(parameters: RemoveSubscriberParameters): Promise<boolean>`
141
+ The Bento SDK provides several modules for different operations:
182
142
 
183
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.unsubscribe`](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null) method.
143
+ ### Analytics (Base Module)
184
144
 
185
- Unsubscribes an email in the system. If the email is already unsubscribed, another unsubscribe event will be sent, triggering any automations that take place upon an unsubscribe happening. Please be aware of the potential consequences.
145
+ Core functionality for tracking events and managing subscribers.
186
146
 
187
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
147
+ ### Convenience Helpers
188
148
 
189
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
149
+ #### tagSubscriber
190
150
 
191
- Reference Types: [RemoveSubscriberParameters](#RemoveSubscriberParameters)
151
+ Tags a subscriber with a specific tag.
192
152
 
193
- ```ts
194
- bento.V1.removeSubscriber({
195
- email: 'test@bentonow.com',
196
- })
197
- .then(result => console.log(result))
198
- .catch(error => console.error(error));
153
+ ```javascript
154
+ bento.V1.tagSubscriber({
155
+ email: 'user@example.com',
156
+ tagName: 'New Customer',
157
+ }).then((result) => console.log(result));
199
158
  ```
200
159
 
201
- ---
202
-
203
- ### `updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean>`
204
-
205
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.addField`](#commandsaddfieldparameters-addfieldparameterss-promisesubscribers--null) method.
206
-
207
- Sets the passed-in custom fields on the subscriber, creating the subscriber if it does not exist. If the fields are already set on the subscriber, the event will be sent, triggering any automations that take place upon fields being updated. Please be aware of the potential consequences.
160
+ #### addSubscriber
208
161
 
209
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
162
+ Adds a new subscriber to your Bento account.
210
163
 
211
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
212
-
213
- Reference Types: [UpdateFieldsParameters\<S\>](#updatefieldsparameterss)
214
-
215
- ```ts
216
- bento.V1.updateFields({
217
- email: 'test@bentonow.com',
164
+ ```javascript
165
+ bento.V1.addSubscriber({
166
+ email: 'newuser@example.com',
218
167
  fields: {
219
- firstName: 'Test',
168
+ firstName: 'John',
169
+ lastName: 'Doe',
220
170
  },
221
- })
222
- .then(result => console.log(result))
223
- .catch(error => console.error(error));
171
+ }).then((result) => console.log(result));
224
172
  ```
225
173
 
226
- ---
174
+ #### removeSubscriber
227
175
 
228
- ### `trackPurchase(parameters: TrackPurchaseParameters): Promise<boolean>`
176
+ Removes a subscriber from your Bento account.
229
177
 
230
- **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering automations.
231
-
232
- Tracks a purchase in Bento, used to calculate LTV for your subscribers. The values that are received should be numbers, in cents. For example, `$1.00` should be `100`.
233
-
234
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
178
+ ```javascript
179
+ bento.V1.removeSubscriber({
180
+ email: 'user@example.com',
181
+ }).then((result) => console.log(result));
182
+ ```
235
183
 
236
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
184
+ #### upsertSubscriber
237
185
 
238
- Reference Types: [TrackPurchaseParameters](#TrackPurchaseParameters)
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.
239
188
 
240
- ```ts
241
- bento.V1.trackPurchase({
242
- email: 'test@bentonow.com',
243
- purchaseDetails: {
244
- unique: {
245
- key: 1234,
246
- },
247
- value: {
248
- amount: 100,
249
- currency: 'USD',
250
- },
189
+ ```javascript
190
+ const subscriber = await analytics.V1.upsertSubscriber({
191
+ email: 'user@example.com',
192
+ fields: {
193
+ firstName: 'John',
194
+ lastName: 'Doe',
195
+ company: 'Acme Inc',
251
196
  },
252
- })
253
- .then(result => console.log(result))
254
- .catch(error => console.error(error));
197
+ tags: 'lead,mql',
198
+ remove_tags: 'customer',
199
+ });
255
200
  ```
256
201
 
257
- ---
258
-
259
- ### `track(parameters: TrackParameters<S, E>): Promise<boolean>`
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`.
260
204
 
261
- **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering automations.
205
+ #### updateFields
262
206
 
263
- Tracks a custom event in Bento.
207
+ Updates custom fields for a subscriber.
264
208
 
265
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
209
+ ```javascript
210
+ bento.V1.updateFields({
211
+ email: 'user@example.com',
212
+ fields: {
213
+ lastPurchaseDate: new Date(),
214
+ },
215
+ }).then((result) => console.log(result));
216
+ ```
266
217
 
267
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
218
+ #### track
268
219
 
269
- Reference Types: [TrackParameters<S, E>](#trackparametersse)
220
+ Tracks a custom event for a subscriber.
270
221
 
271
- ```ts
222
+ ```javascript
272
223
  bento.V1.track({
273
- email: 'test@bentonow.com',
274
- type: '$custom.event',
275
- fields: {
276
- firstName: 'Custom Name',
277
- lastName: 'Custom Name',
278
- },
224
+ email: 'user@example.com',
225
+ type: '$pageView',
279
226
  details: {
280
- fromCustomEvent: true,
227
+ url: '/products',
281
228
  },
282
- })
283
- .then(result => console.log(result))
284
- .catch(error => console.error(error));
229
+ }).then((result) => console.log(result));
285
230
  ```
286
231
 
287
- ## Batch
232
+ #### trackPurchase
288
233
 
289
- ### `Batch.importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number>`
234
+ Tracks a purchase event for a subscriber.
290
235
 
291
- **This does not trigger automations!** - If you wish to trigger automations, please batch import events.
236
+ ```javascript
237
+ bento.V1.trackPurchase({
238
+ email: 'user@example.com',
239
+ purchaseDetails: {
240
+ unique: { key: 'order-123' },
241
+ value: { amount: 9999, currency: 'USD' },
242
+ },
243
+ }).then((result) => console.log(result));
244
+ ```
245
+
246
+ ### Low Level API calls
292
247
 
293
- Creates a batch job to import subscribers into the system. You can pass in between 1 and 1,000 subscribers to import. Each subscriber must have an email, and may optionally have any additional fields. The additional fields are added as custom fields on the subscriber.
248
+ ### Batch
294
249
 
295
- This method is processed by the Bento import queues and it may take between 1 and 5 minutes for the results to appear in your dashboard.
250
+ Perform bulk operations for importing subscribers and events.
296
251
 
297
- Returns the number of subscribers that were imported.
252
+ #### importSubscribers
298
253
 
299
- Reference Types: [BatchImportSubscribersParameter\<S\>](#batchimportsubscribersparameters)
254
+ Imports multiple subscribers in a single operation.
300
255
 
301
- ```ts
256
+ ```javascript
302
257
  bento.V1.Batch.importSubscribers({
303
258
  subscribers: [
304
- {
305
- email: 'test@bentonow.com',
306
- age: 21,
307
- },
308
- {
309
- email: 'test2@bentonow.com',
310
- some_custom_variable: 'tester-123',
311
- primary_user: true,
312
- },
313
- {
314
- email: 'test3@bentonow.com',
315
- name: 'Test User',
316
- },
259
+ { email: 'user1@example.com', firstName: 'Alice' },
260
+ { email: 'user2@example.com', firstName: 'Bob' },
317
261
  ],
318
- })
319
- .then(result => console.log(result))
320
- .catch(error => console.error(error));
262
+ }).then((result) => console.log(result));
321
263
  ```
322
264
 
323
- ---
324
-
325
- ### `Batch.importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number>`
326
-
327
- Creates a batch job to import events into the system. You can pass in between 1 and 100 events to import. Each event must have an email and a type. In addition to this, you my pass in additional data in the `details` property,
265
+ #### importEvents
328
266
 
329
- Returns the number of events that were imported.
267
+ Imports multiple events in a single operation.
330
268
 
331
- Reference Types: [BatchImportEventsParameter<S, E>](#batchimporteventsparameterse)
332
-
333
- ```ts
269
+ ```javascript
334
270
  bento.V1.Batch.importEvents({
335
271
  events: [
336
- {
337
- email: 'test@bentonow.com',
338
- type: BentoEvents.SUBSCRIBE,
339
- },
340
- {
341
- email: 'test@bentonow.com',
342
- type: BentoEvents.UNSUBSCRIBE,
343
- },
344
- {
345
- email: 'test@bentonow.com',
346
- type: BentoEvents.REMOVE_TAG,
347
- details: {
348
- tag: 'tag_to_remove',
349
- },
350
- },
351
- {
352
- email: 'test@bentonow.com',
353
- type: BentoEvents.TAG,
354
- details: {
355
- tag: 'tag_to_add',
356
- },
357
- },
358
- {
359
- email: 'test@bentonow.com',
360
- details: {
361
- customData: 'Used internally.',
362
- },
363
- type: '$custom.myEvent,
364
- },
272
+ { email: 'user@example.com', type: '$login' },
273
+ { email: 'user@example.com', type: '$pageView', details: { url: '/home' } },
365
274
  ],
366
- })
367
- .then(result => console.log(result))
368
- .catch(error => console.error(error));
275
+ }).then((result) => console.log(result));
369
276
  ```
370
277
 
371
- ---
278
+ ### Broadcast Management
372
279
 
373
- ### `Batch.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>`
280
+ #### getBroadcasts
374
281
 
375
- Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in between 1 and 100 emails to send. Each email must have a `to` address, a `from` address, a `subject`, an `html_body` and `transactional: true`.
282
+ Retrieves all broadcasts:
376
283
 
377
- In addition you can add a `personalizations` object to provide liquid tags that will be injected into the email.
284
+ ```javascript
285
+ const broadcasts = await analytics.V1.Broadcasts.getBroadcasts();
286
+ ```
378
287
 
379
- Requests are instant and queued into a priority queue. Most requests will be processed within 30 seconds. We currently limit this endpoint to 60 emails per minute.
288
+ #### createBroadcast
380
289
 
381
- Returns the number of emails that were imported.
290
+ Creates new broadcast campaigns:
382
291
 
383
- ```ts
384
- bento.V1.Batch.sendTransactionalEmails({
385
- emails: [
386
- {
387
- to: 'test@bentonow.com', // required — if no user with this email exists in your account they will be created.
388
- from: 'jesse@bentonow.com', // required — must be an email author in your account.
389
- subject: 'Reset Password', // required
390
- html_body: '<p>Here is a link to reset your password ... {{ link }}</p>', // required - can also use text_body if you want to use our plain text theme.
391
- transactional: true, // IMPORTANT — this bypasses the subscription status of a user. Abuse will lead to account shutdown.
392
- personalizations: {
393
- link: 'https://example.com/test',
394
- }, // optional — provide your own Liquid tags to be injected into the email.
292
+ ```javascript
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',
395
302
  },
396
- ],
397
- })
398
- .then(result => console.log(result))
399
- .catch(error => console.error(error));
303
+ inclusive_tags: 'lead,mql',
304
+ exclusive_tags: 'unsubscribed',
305
+ segment_id: 'segment_123',
306
+ batch_size_per_hour: 1000,
307
+ },
308
+ ]);
400
309
  ```
401
310
 
402
- ## Commands
311
+ ### Transactional Emails
403
312
 
404
- ### `Commands.addTag(parameters: AddTagParameters): Promise<Subscriber<S> | null>`
313
+ #### createEmails
405
314
 
406
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `tagSubscriber` method.
315
+ Creates a new transactional email:
407
316
 
408
- Adds a tag to the subscriber with the matching email.
409
-
410
- Note that both the tag and the subscriber will be created if either is missing from system.
411
-
412
- Reference Types: [AddTagParameters](#AddTagParameters), [Subscriber\<S\>](#subscribers)
413
-
414
- ```ts
415
- bento.V1.Commands.addTag({
416
- email: 'test@bentonow.com',
417
- tagName: 'Test Tag',
418
- })
419
- .then(result => console.log(result))
420
- .catch(error => console.error(error));
317
+ ```javascript
318
+ const result = await bento.V1.Batch.sendTransactionalEmails({
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
+ ],
331
+ });
421
332
  ```
422
333
 
423
- ---
424
-
425
- ### `Commands.removeTag(parameters: RemoveTagParameters): Promise<Subscriber<S> | null>`
426
-
427
- Removes the specified tag from the subscriber with the matching email.
334
+ ### Email Structure
428
335
 
429
- Reference Types: [RemoveTagParameters](#RemoveTagParameters), [Subscriber\<S\>](#subscribers)
336
+ Each email object requires:
430
337
 
431
- ```ts
432
- bento.V1.Commands.removeTag({
433
- email: 'test@bentonow.com',
434
- tagName: 'Test Tag',
435
- })
436
- .then(result => console.log(result))
437
- .catch(error => console.error(error));
438
- ```
439
-
440
- ---
338
+ - **to:** Recipient email address
339
+ - **from:** Sender email address
340
+ - **subject:** Email subject (supports liquid templates)
341
+ - **html_body:** HTML email content (supports liquid templates)
342
+ - **transactional:** true/false: defaults to false, must be true to send to unsubscribed users
343
+ - **personalizations:** Optional object for liquid template variables
441
344
 
442
- ### `Commands.addField(parameters: AddFieldParameters<S>): Promise<Subscriber<S> | null>`
345
+ #### Constraints
443
346
 
444
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `updateFields` method.
347
+ - **Batch size:** 1-100 emails per request
348
+ - **Errors:** Throws TooFewEmailsError or TooManyEmailsError for invalid counts
349
+ - **Returns:** Number of emails successfully queued
445
350
 
446
- Adds a field to the subscriber with the matching email.
351
+ ### Statistics
447
352
 
448
- Note that both the field and the subscriber will be created if either is missing from system.
353
+ #### getSiteStats
449
354
 
450
- Reference Types: [AddFieldParameters\<S\>](#addfieldparameterss), [Subscriber\<S\>](#subscribers)
355
+ Retrieves overall site statistics:
451
356
 
452
- ```ts
453
- bento.V1.Commands.addField({
454
- email: 'test@bentonow.com',
455
- field: {
456
- key: 'testKey',
457
- value: 'testValue',
458
- },
459
- })
460
- .then(result => console.log(result))
461
- .catch(error => console.error(error));
357
+ ```javascript
358
+ const stats = await analytics.V1.Stats.getSiteStats();
359
+ // Returns:
360
+ // {
361
+ // total_subscribers: 1000,
362
+ // active_subscribers: 950,
363
+ // unsubscribed_count: 50,
364
+ // broadcast_count: 25,
365
+ // average_open_rate: 45.5,
366
+ // average_click_rate: 12.3
367
+ // }
462
368
  ```
463
369
 
464
- ---
465
-
466
- ### `Commands.removeField(parameters: RemoveFieldParameters<S>): Promise<Subscriber<S> | null>`
370
+ #### getSegmentStats
467
371
 
468
- Removes a field to the subscriber with the matching email.
372
+ Retrieves statistics for a specific segment:
469
373
 
470
- Reference Types: [RemoveFieldParameters\<S\>](#removefieldparameterss), [Subscriber\<S\>](#subscribers)
471
-
472
- ```ts
473
- bento.V1.Commands.removeField({
474
- email: 'test@bentonow.com',
475
- fieldName: 'testField',
476
- })
477
- .then(result => console.log(result))
478
- .catch(error => console.error(error));
374
+ ```javascript
375
+ const segmentStats = await analytics.V1.Stats.getSegmentStats('segment_123');
376
+ // Returns:
377
+ // {
378
+ // segment_id: 'segment_123',
379
+ // subscriber_count: 500,
380
+ // growth_rate: 2.5,
381
+ // engagement_rate: 35.8,
382
+ // last_updated: '2024-01-01T00:00:00Z'
383
+ // }
479
384
  ```
480
385
 
481
- ---
482
-
483
- ### `Commands.subscribe(parameters: SubscribeParameters): Promise<Subscriber<S> | null>`
386
+ #### getReportStats
387
+
388
+ Retrieves statistics for a specific report:
389
+
390
+ ```javascript
391
+ const reportStats = await analytics.V1.Stats.getReportStats('report_123');
392
+ // Returns:
393
+ // {
394
+ // report_id: 'report_123',
395
+ // total_sent: 1000,
396
+ // total_opens: 750,
397
+ // unique_opens: 500,
398
+ // total_clicks: 250,
399
+ // unique_clicks: 200,
400
+ // unsubscribes: 5,
401
+ // spam_reports: 1
402
+ // }
403
+ ```
484
404
 
485
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `addSubscriber` method.
405
+ ### Commands
486
406
 
487
- Subscribes the supplied email to Bento. If the email does not exist, it is created.
407
+ Execute specific commands for subscriber management.
488
408
 
489
- If the subscriber had previously unsubscribed, they will be re-subscribed.
409
+ #### addTag
490
410
 
491
- Reference Types: [SubscribeParameters](#SubscribeParameters), [Subscriber\<S\>](#subscribers)
411
+ Adds a tag to a subscriber.
492
412
 
493
- ```ts
494
- bento.V1.Commands.subscribe({
495
- email: 'test@bentonow.com',
496
- })
497
- .then(result => console.log(result))
498
- .catch(error => console.error(error));
413
+ ```javascript
414
+ bento.V1.Commands.addTag({
415
+ email: 'user@example.com',
416
+ tagName: 'VIP',
417
+ }).then((result) => console.log(result));
499
418
  ```
500
419
 
501
- ---
420
+ #### removeTag
502
421
 
503
- ### `Commands.unsubscribe(parameters: UnsubscribeParameters): Promise<Subscriber<S> | null>`
422
+ Removes a tag from a subscriber.
504
423
 
505
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `removeSubscriber` method.
424
+ ```javascript
425
+ bento.V1.Commands.removeTag({
426
+ email: 'user@example.com',
427
+ tagName: 'VIP',
428
+ }).then((result) => console.log(result));
429
+ ```
506
430
 
507
- Unsubscribes the supplied email to Bento. If the email does not exist, it is created and immediately unsubscribed. If they had already unsubscribed, the `unsubscribed_at` property is updated.
431
+ #### addField
508
432
 
509
- Reference Types: [UnsubscribeParameters](#UnsubscribeParameters), [Subscriber\<S\>](#subscribers)
433
+ Adds a custom field to a subscriber.
510
434
 
511
- ```ts
512
- bento.V1.Commands.unsubscribe({
513
- email: 'test@bentonow.com',
514
- })
515
- .then(result => console.log(result))
516
- .catch(error => console.error(error));
435
+ ```javascript
436
+ bento.V1.Commands.addField({
437
+ email: 'user@example.com',
438
+ field: {
439
+ key: 'favoriteColor',
440
+ value: 'blue',
441
+ },
442
+ }).then((result) => console.log(result));
517
443
  ```
518
444
 
519
- ---
520
-
521
- ### `Commands.changeEmail(parameters: ChangeEmailParameters): Promise<Subscriber<S> | null>`
445
+ #### removeField
522
446
 
523
- Updates the email of a user in Bento.
447
+ Removes a custom field from a subscriber.
524
448
 
525
- Reference Types: [ChangeEmailParameters](#changeemailparameters), [Subscriber\<S\>](#subscribers)
526
-
527
- ```ts
528
- bento.V1.Commands.changeEmail({
529
- oldEmail: 'test@bentonow.com',
530
- newEmail: 'new@bentonow.com',
531
- })
532
- .then(result => console.log(result))
533
- .catch(error => console.error(error));
449
+ ```javascript
450
+ bento.V1.Commands.removeField({
451
+ email: 'user@example.com',
452
+ fieldName: 'favoriteColor',
453
+ }).then((result) => console.log(result));
534
454
  ```
535
455
 
536
- ## Experimental
537
-
538
- ### `Experimental.validateEmail(parameters: ValidateEmailParameters): Promise<boolean>`
456
+ ### Experimental
539
457
 
540
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
458
+ Access experimental features (use with caution).
541
459
 
542
- Attempts to validate the email. You can provide additional information to further refine the validation.
460
+ #### validateEmail
543
461
 
544
- If a name is provided, it compares it against the US Census Data, and so the results may be biased.
462
+ Attempts to validate an email address.
545
463
 
546
- Reference Types: [ValidateEmailParameters](#ValidateEmailParameters)
547
-
548
- ```ts
464
+ ```javascript
549
465
  bento.V1.Experimental.validateEmail({
550
- email: 'test@bentonow.com',
551
- })
552
- .then(result => console.log(result))
553
- .catch(error => console.error(error));
466
+ email: 'user@example.com',
467
+ }).then((result) => console.log(result));
554
468
  ```
555
469
 
556
- ---
557
-
558
- ### `Experimental.guessGender(parameters: GuessGenderParameters): Promise<GuessGenderResponse>`
470
+ #### guessGender
559
471
 
560
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
472
+ Attempts to guess the gender based on a given name.
561
473
 
562
- Attempts to guess the gender of the person given a provided name. It compares the name against the US Census Data, and so the results may be biased.
563
-
564
- It is possible for the gender to be unknown if the system cannot confidently conclude what gender it may be.
565
-
566
- Reference Types: [GuessGenderParameters](#GuessGenderParameters), [GuessGenderResponse](#GuessGenderResponse)
567
-
568
- ```ts
474
+ ```javascript
569
475
  bento.V1.Experimental.guessGender({
570
- name: 'Jesse',
571
- })
572
- .then(result => console.log(result))
573
- .catch(error => console.error(error));
476
+ name: 'Alex',
477
+ }).then((result) => console.log(result));
574
478
  ```
575
479
 
576
- ---
577
-
578
- ### `Experimental.geolocate(parameters: GeolocateParameters): Promise<LocationData | null>`
480
+ is blacklisted:
579
481
 
580
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
581
-
582
- Attempts to provide location data given a provided IP address.
583
-
584
- Reference Types: [GeolocateParameters](#GeolocateParameters), [LocationData](#LocationData)
585
-
586
- ```ts
587
- bento.V1.Experimental.geolocate({
588
- ip: '127.0.0.1',
589
- })
590
- .then(result => console.log(result))
591
- .catch(error => console.error(error));
482
+ ```javascript
483
+ const blacklistStatus = await analytics.V1.Experimental.getBlacklistStatus({
484
+ domain: 'example.com',
485
+ // or ipAddress: '192.168.1.1'
486
+ });
592
487
  ```
593
488
 
594
- ---
595
-
596
- ### `Experimental.checkBlacklist(parameters: BlacklistParameters): Promise<BlacklistResponse>`
597
-
598
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
489
+ #### getContentModeration
490
+
491
+ Performs content moderation on text:
492
+
493
+ ```javascript
494
+ const moderationResult =
495
+ await analytics.V1.Experimental.getContentModeration('Content to moderate');
496
+ // Returns:
497
+ // {
498
+ // flagged: boolean,
499
+ // categories: {
500
+ // hate: boolean,
501
+ // 'hate/threatening': boolean,
502
+ // 'self-harm': boolean,
503
+ // ...
504
+ // },
505
+ // category_scores: {
506
+ // hate: number,
507
+ // 'hate/threatening': number,
508
+ // ...
509
+ // }
510
+ // }
511
+ ```
599
512
 
600
- Looks up the provided URL or IP Address against various blacklists to see if the site has been blacklisted anywhere.
513
+ #### geoLocateIP
601
514
 
602
- Reference Types: [BlacklistParameters](#BlacklistParameters), [BlacklistResponse](#BlacklistResponse)
515
+ Gets detailed geolocation information for an IP address:
603
516
 
604
- ```ts
605
- bento.V1.Experimental.checkBlacklist({
606
- domain: 'bentonow.com',
607
- })
608
- .then(result => console.log(result))
609
- .catch(error => console.error(error));
517
+ ```javascript
518
+ const location = await analytics.V1.Experimental.geoLocateIP('192.168.1.1');
519
+ // Returns:
520
+ // {
521
+ // city_name: 'San Francisco',
522
+ // country_name: 'United States',
523
+ // latitude: 37.7749,
524
+ // longitude: -122.4194,
525
+ // ...
526
+ // }
610
527
  ```
611
528
 
612
- ## Fields
529
+ ### Fields
613
530
 
614
- ### `Fields.getFields(): Promise<Field[] | null>`
531
+ Manage custom fields for your subscribers.
615
532
 
616
- Returns all of the fields for the site.
533
+ #### getFields
617
534
 
618
- Reference Types: [Field](#Field)
535
+ Retrieves all custom fields defined in your Bento account.
619
536
 
620
- ```ts
621
- bento.V1.Experimental.validateEmail({
622
- email: 'test@bentonow.com',
623
- })
624
- .then(result => console.log(result))
625
- .catch(error => console.error(error));
537
+ ```javascript
538
+ bento.V1.Fields.getFields().then((fields) => console.log(fields));
626
539
  ```
627
540
 
628
- ---
629
-
630
- ### `Fields.createField(parameters: CreateFieldParameters): Promise<Field[] | null>`
631
-
632
- Creates a field inside of Bento. The name of the field is automatically generated from the key that is passed in upon creation. For example:
541
+ #### createField
633
542
 
634
- | Key | Name |
635
- | ----------------- | ----------------- |
636
- | `'thisIsAKey'` | `'This Is A Key'` |
637
- | `'this is a key'` | `'This Is A Key'` |
638
- | `'this-is-a-key'` | `'This Is A Key'` |
639
- | `'this_is_a_key'` | `'This Is A Key'` |
543
+ Creates a new custom field in your Bento account.
640
544
 
641
- Reference Types: [CreateFieldParameters](#CreateFieldParameters), [Field](#Field)
642
-
643
- ```ts
545
+ ```javascript
644
546
  bento.V1.Fields.createField({
645
- key: 'testKey',
646
- })
647
- .then(result => console.log(result))
648
- .catch(error => console.error(error));
547
+ key: 'loyaltyPoints',
548
+ }).then((result) => console.log(result));
649
549
  ```
650
550
 
651
- ## Forms
551
+ ### Forms
652
552
 
653
- ### `Forms.getResponses(formIdentifier: string): Promise<FormResponse[] | null>`
553
+ Retrieve form responses.
654
554
 
655
- Returns all of the responses for the form with the specified identifier.
555
+ #### getResponses
656
556
 
657
- Reference Types: [FormResponse](#FormResponse)
557
+ Retrieves responses for a specific form.
658
558
 
659
- ```ts
660
- bento.V1.Forms.getResponses('test-formid-1234')
661
- .then(result => console.log(result))
662
- .catch(error => console.error(error));
559
+ ```javascript
560
+ bento.V1.Forms.getResponses('form-id-123').then((responses) => console.log(responses));
663
561
  ```
664
562
 
665
- ## Subscribers
666
-
667
- ### `Subscribers.getSubscribers(parameters?: GetSubscribersParameters): Promise<Subscriber<S> | null>`
563
+ ### Subscribers
668
564
 
669
- Returns the subscriber with the specified email or UUID.
565
+ Manage individual subscribers.
670
566
 
671
- Reference Types: [GetSubscribersParameters](#GetSubscribersParameters), [Subscriber\<S\>](#subscribers)
567
+ #### getSubscribers
672
568
 
673
- ```ts
674
- bento.V1.Subscribers.getSubscribers({
675
- uuid: '1234',
676
- })
677
- .then(result => console.log(result))
678
- .catch(error => console.error(error));
569
+ Retrieves subscriber information.
679
570
 
571
+ ```javascript
680
572
  bento.V1.Subscribers.getSubscribers({
681
- email: 'test@bentonow.com',
682
- })
683
- .then(result => console.log(result))
684
- .catch(error => console.error(error));
573
+ email: 'user@example.com',
574
+ }).then((subscriber) => console.log(subscriber));
685
575
  ```
686
576
 
687
- ---
688
-
689
- ### `Subscribers.createSubscriber(parameters: CreateSubscriberParameters): Promise<Subscriber<S> | null>`
690
-
691
- Creates a subscriber inside of Bento.
577
+ #### createSubscriber
692
578
 
693
- Reference Types: [CreateSubscriberParameters](#CreateSubscriberParameters), [Subscriber\<S\>](#subscribers)
579
+ Creates a new subscriber in your Bento account.
694
580
 
695
- ```ts
581
+ ```javascript
696
582
  bento.V1.Subscribers.createSubscriber({
697
- email: 'test@bentonow.com',
698
- })
699
- .then(result => console.log(result))
700
- .catch(error => console.error(error));
583
+ email: 'newuser@example.com',
584
+ }).then((result) => console.log(result));
701
585
  ```
702
586
 
703
- ## Tags
587
+ ### Tags
704
588
 
705
- ### `Tags.getTags(): Promise<Tag[] | null>`
589
+ Create and manage tags for subscriber segmentation.
706
590
 
707
- Returns all of the fields for the site.
591
+ #### getTags
708
592
 
709
- Reference Types: [Tag](#Tag)
593
+ Retrieves all tags defined in your Bento account.
710
594
 
711
- ```ts
712
- bento.V1.Tags.getTags()
713
- .then(result => console.log(result))
714
- .catch(error => console.error(error));
595
+ ```javascript
596
+ bento.V1.Tags.getTags().then((tags) => console.log(tags));
715
597
  ```
716
598
 
717
- ---
599
+ #### createTag
718
600
 
719
- ### `Tags.createTag(parameters: CreateTagParameters): Promise<Tag[] | null>`
601
+ Creates a new tag in your Bento account.
720
602
 
721
- Creates a tag inside of Bento.
722
-
723
- Reference Types: [Tag](#Tag)
724
-
725
- ```ts
603
+ ```javascript
726
604
  bento.V1.Tags.createTag({
727
- name: 'test tag',
728
- })
729
- .then(result => console.log(result))
730
- .catch(error => console.error(error));
605
+ name: 'Premium Customer',
606
+ }).then((result) => console.log(result));
731
607
  ```
732
608
 
733
- ## Types Reference
734
-
735
- ### `AddFieldParameters<S>`
736
-
737
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
738
-
739
- | Property | Type | Default | Required |
740
- | -------- | ------------------------------ | ------- | -------- |
741
- | email | `string` | _none_ | ✔️ |
742
- | field | `{ key: keyof S; value: any }` | _none_ | ✔️ |
743
-
744
- ---
745
-
746
- ### `AddSubscriberParameters<S>`
747
-
748
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
749
-
750
- | Property | Type | Default | Required |
751
- | -------- | ------------ | ------- | -------- |
752
- | date | `Date` | _none_ | ❌ |
753
- | email | `string` | _none_ | ✔️ |
754
- | fields | `Partial<S>` | _none_ | ❌ |
755
-
756
- ---
757
-
758
- ### `AddTagParameters`
759
-
760
- | Property | Type | Default | Required |
761
- | -------- | -------- | ------- | -------- |
762
- | email | `string` | _none_ | ✔️ |
763
- | tagName | `string` | _none_ | ✔️ |
764
-
765
- ---
766
-
767
- ### `BatchImportEventsParameter<S, E>`
768
-
769
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
770
-
771
- The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
772
-
773
- | Property | Type | Default | Required |
774
- | -------- | ----------------------------------------- | ------- | -------- |
775
- | events | [`BentoEvent<S, E>[]`](#BentoEvent<S, E>) | _none_ | ✔️ |
776
-
777
- ---
778
-
779
- ### `BatchImportSubscribersParameter<S>`
780
-
781
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
782
-
783
- | Property | Type | Default | Required |
784
- | ----------- | ------------------------------------ | ------- | -------- |
785
- | subscribers | `({ email: string } & Partial<S>)[]` | _none_ | ✔️ |
786
-
787
- ---
788
-
789
- ### `BentoEvent<S, E>`
790
-
791
- This type is a discriminated union of a few different types. Each of these types are documented below:
792
-
793
- #### `BaseEvent<E>`
794
-
795
- The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
796
-
797
- | Property | Type | Default | Required |
798
- | -------- | ------------------------ | ------- | -------- |
799
- | date | `Date` | _none_ | ❌ |
800
- | details | `{ [key: string]: any }` | _none_ | ✔️ |
801
- | email | `string` | _none_ | ✔️ |
802
- | type | `string` | _none_ | ✔️ |
803
-
804
- #### `PurchaseEvent`
805
-
806
- | Property | Type | Default | Required |
807
- | -------- | --------------------------------------- | ------- | -------- |
808
- | date | `Date` | _none_ | ❌ |
809
- | details | [`PurchaseDetails`](#PurchaseDetails) | _none_ | ✔️ |
810
- | email | `string` | _none_ | ✔️ |
811
- | type | `BentoEvents.PURCHASE` \| `'$purchase'` | _none_ | ✔️ |
812
-
813
- #### `SubscribeEvent<S>`
814
-
815
- | Property | Type | Default | Required |
816
- | -------- | ----------------------------------------- | ------- | -------- |
817
- | date | `Date` | _none_ | ❌ |
818
- | email | `string` | _none_ | ✔️ |
819
- | fields | `Partial<S>` | _none_ | ❌ |
820
- | type | `BentoEvents.SUBSCRIBE` \| `'$subscribe'` | _none_ | ✔️ |
821
-
822
- #### `TagEvent`
823
-
824
- | Property | Type | Default | Required |
825
- | -------- | ----------------------------- | ------- | -------- |
826
- | date | `Date` | _none_ | ❌ |
827
- | details | `{ tag: string }` | _none_ | ✔️ |
828
- | email | `string` | _none_ | ✔️ |
829
- | type | `BentoEvents.TAG` \| `'$tag'` | _none_ | ✔️ |
830
-
831
- #### `UnsubscribeEvent`
832
-
833
- | Property | Type | Default | Required |
834
- | -------- | --------------------------------------------- | ------- | -------- |
835
- | date | `Date` | _none_ | ❌ |
836
- | email | `string` | _none_ | ✔️ |
837
- | type | `BentoEvents.UNSUBSCRIBE` \| `'$unsubscribe'` | _none_ | ✔️ |
838
-
839
- #### `UpdateFieldsEvent<S>`
840
-
841
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
842
-
843
- | Property | Type | Default | Required |
844
- | -------- | ------------------------------------------------- | ------- | -------- |
845
- | date | `Date` | _none_ | ❌ |
846
- | email | `string` | _none_ | ✔️ |
847
- | type | `BentoEvents.UPDATE_FIELDS` \| `'$update_fields'` | _none_ | ✔️ |
848
- | fields | `Partial<S>` | _none_ | ✔️ |
849
-
850
- ---
851
-
852
- ### `BlacklistParameters`
853
-
854
- Note that this takes either `domain` _or_ `ip`, but never both.
855
-
856
- | Property | Type | Default | Required |
857
- | -------- | -------- | ------- | -------- |
858
- | domain | `string` | _none_ | ✔️ |
859
-
860
- | Property | Type | Default | Required |
861
- | -------- | -------- | ------- | -------- |
862
- | ip | `string` | _none_ | ✔️ |
863
-
864
- ---
865
-
866
- ### `BlacklistResponse`
867
-
868
- The results is an object where the key is the name of the blacklist that was checked, and the value is whether or not the domain/IP appeared on that blacklist.
869
-
870
- | Property | Type | Default | Required |
871
- | ----------- | ---------------------------- | ------- | -------- |
872
- | description | `string` | _none_ | ✔️ |
873
- | query | `string` | _none_ | ✔️ |
874
- | results | `{ [key: string]: boolean }` | _none_ | ✔️ |
875
-
876
- ---
877
-
878
- ### `BrowserData`
879
-
880
- | Property | Type | Default | Required |
881
- | ---------- | -------- | ------- | -------- |
882
- | height | `string` | _none_ | ✔️ |
883
- | user_agent | `string` | _none_ | ✔️ |
884
- | width | `string` | _none_ | ✔️ |
885
-
886
- ---
887
-
888
- ### `ChangeEmailParameters`
889
-
890
- | Property | Type | Default | Required |
891
- | -------- | -------- | ------- | -------- |
892
- | oldEmail | `string` | _none_ | ✔️ |
893
- | newEmail | `string` | _none_ | ✔️ |
894
-
895
- ---
896
-
897
- ### `CreateFieldParameters`
898
-
899
- | Property | Type | Default | Required |
900
- | -------- | -------- | ------- | -------- |
901
- | key | `string` | _none_ | ✔️ |
902
-
903
- ---
904
-
905
- ### `CreateSubscriberParameters`
906
-
907
- | Property | Type | Default | Required |
908
- | -------- | -------- | ------- | -------- |
909
- | email | `string` | _none_ | ✔️ |
910
-
911
- ### `CreateTagParameters`
912
-
913
- | Property | Type | Default | Required |
914
- | -------- | -------- | ------- | -------- |
915
- | name | `string` | _none_ | ✔️ |
916
-
917
- ---
918
-
919
- ### `EntityType`
920
-
921
- This is an enum with the following values:
922
-
923
- | Name | Value |
924
- | --------------- | ------------------- |
925
- | EVENTS | `'events'` |
926
- | TAGS | `'tags'` |
927
- | VISITORS | `'visitors'` |
928
- | VISITORS_FIELDS | `'visitors-fields'` |
929
-
930
- ---
931
-
932
- ### `Field`
933
-
934
- | Property | Type | Default | Required |
935
- | ---------- | ------------------------------------------- | ------- | -------- |
936
- | attributes | [`FieldAttributes`](#FieldAttributes) | _none_ | ✔️ |
937
- | id | `string` | _none_ | ✔️ |
938
- | type | [`EntityType.VISITORS_FIELDS`](#EntityType) | _none_ | ✔️ |
939
-
940
- ---
941
-
942
- ### `FieldAttributes`
943
-
944
- | Property | Type | Default | Required |
945
- | ----------- | ------------------- | ------- | -------- |
946
- | created_at | `string` | _none_ | ✔️ |
947
- | key | `string` | _none_ | ✔️ |
948
- | name | `string` | _none_ | ✔️ |
949
- | whitelisted | `boolean` \| `null` | _none_ | ✔️ |
950
-
951
- ---
952
-
953
- ### `FormResponse`
954
-
955
- | Property | Type | Default | Required |
956
- | ---------- | --------------------------------------------------- | ------- | -------- |
957
- | attributes | [`FormResponseAttributes`](#FormResponseAttributes) | _none_ | ✔️ |
958
- | id | `string` | _none_ | ✔️ |
959
- | type | [`EntityType.EVENTS`](#EntityType) | _none_ | ✔️ |
960
-
961
- ---
962
-
963
- ### `FormResponseAttributes`
964
-
965
- | Property | Type | Default | Required |
966
- | -------- | --------------------------------------- | ------- | -------- |
967
- | data | [`FormResponseData`](#FormResponseData) | _none_ | ✔️ |
968
- | uuid | `string` | _none_ | ✔️ |
969
-
970
- ---
971
-
972
- ### `FormResponseData`
973
-
974
- | Property | Type | Default | Required |
975
- | -------- | ------------------------------- | ------- | -------- |
976
- | browser | [`BrowserData`](#BrowserData) | _none_ | ✔️ |
977
- | date | `string` | _none_ | ✔️ |
978
- | details | `{ [key: string]: any }` | _none_ | ✔️ |
979
- | fields | `{ [key: string]: any }` | _none_ | ✔️ |
980
- | id | `string` | _none_ | ✔️ |
981
- | identity | [`IdentityData`](#IdentityData) | _none_ | ✔️ |
982
- | ip | `string` | _none_ | ✔️ |
983
- | location | [`LocationData`](#LocationData) | _none_ | ✔️ |
984
- | page | [`PageData`](#PageData) | _none_ | ✔️ |
985
- | site | `string` | _none_ | ✔️ |
986
- | type | `string` | _none_ | ✔️ |
987
- | visit | `string` | _none_ | ✔️ |
988
- | visitor | `string` | _none_ | ✔️ |
989
-
990
- ---
991
-
992
- ### `GetSubscribersParameters`
993
-
994
- Note that this takes either `email` _or_ `uuid`, but never both.
995
-
996
- | Property | Type | Default | Required |
997
- | -------- | -------- | ------- | -------- |
998
- | email | `string` | _none_ | ✔️ |
999
-
1000
- | Property | Type | Default | Required |
1001
- | -------- | -------- | ------- | -------- |
1002
- | uuid | `string` | _none_ | ✔️ |
1003
-
1004
- ---
1005
-
1006
- ### `GeolocateParameters`
1007
-
1008
- | Property | Type | Default | Required |
1009
- | -------- | -------- | ------- | -------- |
1010
- | ip | `string` | _none_ | ✔️ |
1011
-
1012
- ---
1013
-
1014
- ### `GuessGenderParameters`
1015
-
1016
- | Property | Type | Default | Required |
1017
- | -------- | -------- | ------- | -------- |
1018
- | name | `string` | _none_ | ✔️ |
1019
-
1020
- ---
1021
-
1022
- ### `GuessGenderResponse`
1023
-
1024
- | Property | Type | Default | Required |
1025
- | ---------- | ------------------ | ------- | -------- |
1026
- | confidence | `number` \| `null` | _none_ | ✔️ |
1027
- | gender | `string` \| `null` | _none_ | ✔️ |
1028
-
1029
- ---
1030
-
1031
- ### `IdentityData`
1032
-
1033
- | Property | Type | Default | Required |
1034
- | -------- | -------- | ------- | -------- |
1035
- | email | `string` | _none_ | ✔️ |
1036
-
1037
- ---
1038
-
1039
- ### `LocationData`
1040
-
1041
- | Property | Type | Default | Required |
1042
- | ---------------- | -------- | ------- | -------- |
1043
- | city_name | `string` | _none_ | ❌ |
1044
- | continent_code | `string` | _none_ | ❌ |
1045
- | country_code2 | `string` | _none_ | ❌ |
1046
- | country_code3 | `string` | _none_ | ❌ |
1047
- | country_name | `string` | _none_ | ❌ |
1048
- | ip | `string` | _none_ | ❌ |
1049
- | latitude | `number` | _none_ | ❌ |
1050
- | longitude | `number` | _none_ | ❌ |
1051
- | postal_code | `string` | _none_ | ❌ |
1052
- | real_region_name | `string` | _none_ | ❌ |
1053
- | region_name | `string` | _none_ | ❌ |
1054
- | request | `string` | _none_ | ❌ |
1055
-
1056
- ---
1057
-
1058
- ### `PageData`
1059
-
1060
- | Property | Type | Default | Required |
1061
- | -------- | -------- | ------- | -------- |
1062
- | host | `string` | _none_ | ✔️ |
1063
- | path | `string` | _none_ | ✔️ |
1064
- | protocol | `string` | _none_ | ✔️ |
1065
- | referrer | `string` | _none_ | ✔️ |
1066
- | url | `string` | _none_ | ✔️ |
1067
-
1068
- ---
1069
-
1070
- ### `PurchaseCart`
1071
-
1072
- | Property | Type | Default | Required |
1073
- | ---------------------- | --------------------------------- | ------- | -------- |
1074
- | abandoned_checkout_url | `string` | _none_ | ❌ |
1075
- | items | [`PurchaseItem[]`](#PurchaseItem) | _none_ | ❌ |
1076
-
1077
- ---
1078
-
1079
- ### `PurchaseDetails`
1080
-
1081
- | Property | Type | Default | Required |
1082
- | -------- | --------------------------------------- | ------- | -------- |
1083
- | unique | `{ key: string \| number; }` | _none_ | ✔️ |
1084
- | value | `{ currency: string; amount: number; }` | _none_ | ✔️ |
1085
- | cart | [`PurchaseCart`](#PurchaseCart) | _none_ | ❌ |
1086
-
1087
- ---
1088
-
1089
- ### `PurchaseItem`
1090
-
1091
- In addition to the properties below, you can pass any other properties that you want as part of the `PurchaseItem`.
1092
-
1093
- | Property | Type | Default | Required |
1094
- | ------------- | -------- | ------- | -------- |
1095
- | product_sku | `string` | _none_ | ❌ |
1096
- | product_name | `string` | _none_ | ❌ |
1097
- | quantity | `number` | _none_ | ❌ |
1098
- | product_price | `number` | _none_ | ❌ |
1099
- | product_id | `string` | _none_ | ❌ |
1100
-
1101
- ---
1102
-
1103
- ### `RemoveFieldParameters<S>`
1104
-
1105
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
1106
-
1107
- | Property | Type | Default | Required |
1108
- | --------- | --------- | ------- | -------- |
1109
- | email | `string` | _none_ | ✔️ |
1110
- | fieldName | `keyof S` | _none_ | ✔️ |
1111
-
1112
- ---
1113
-
1114
- ### `RemoveSubscriberParameters`
1115
-
1116
- | Property | Type | Default | Required |
1117
- | -------- | -------- | ------- | -------- |
1118
- | date | `Date` | _none_ | ❌ |
1119
- | email | `string` | _none_ | ✔️ |
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
+ ```
1120
635
 
1121
- ---
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
+ ```
1122
662
 
1123
- ### `RemoveTagParameters`
663
+ ### Email Templates
1124
664
 
1125
- | Property | Type | Default | Required |
1126
- | -------- | -------- | ------- | -------- |
1127
- | email | `string` | _none_ | ✔️ |
1128
- | tagName | `string` | _none_ | ✔️ |
665
+ Retrieve and update email templates used in sequences and workflows.
1129
666
 
1130
- ---
667
+ #### getEmailTemplate
1131
668
 
1132
- ### `SubscribeParameters`
669
+ Retrieves a single email template by ID.
1133
670
 
1134
- | Property | Type | Default | Required |
1135
- | -------- | -------- | ------- | -------- |
1136
- | email | `string` | _none_ | ✔️ |
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
+ ```
1137
686
 
1138
- ---
687
+ #### updateEmailTemplate
1139
688
 
1140
- ### `Subscriber<S>`
689
+ Updates an email template's subject and/or HTML content.
1141
690
 
1142
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
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
+ });
697
+ ```
1143
698
 
1144
- | Property | Type | Default | Required |
1145
- | ---------- | --------------------------------------------------- | ------- | -------- |
1146
- | attributes | [`SubscriberAttributes<S>`](#subscriberattributess) | _none_ | ✔️ |
1147
- | id | `string` | _none_ | ✔️ |
1148
- | type | [`EntityType.VISITOR`](#EntityType) | _none_ | ✔️ |
699
+ For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
1149
700
 
1150
- ### `SubscriberAttributes<S>`
701
+ ## Types Reference
1151
702
 
1152
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
703
+ This section provides a detailed reference for the types used in the Bento Node.js SDK.
704
+ AddFieldParameters `<S>`
1153
705
 
1154
- | Property | Type | Default | Required |
1155
- | --------------- | ------------- | ------- | -------- |
1156
- | cached_tag_ids | `string[]` | _none_ | ✔️ |
1157
- | email | `string` | _none_ | ✔️ |
1158
- | fields | `S` \| `null` | _none_ | ✔️ |
1159
- | unsubscribed_at | `string` | _none_ | ✔️ |
1160
- | uuid | `string` | _none_ | ✔️ |
706
+ Parameters for adding a field to a subscriber.
1161
707
 
1162
- ### `Tag`
708
+ | Property | Type | Required | Description |
709
+ | -------- | ---------------------------- | -------- | -------------------------- |
710
+ | email | string | ✔️ | Subscriber's email address |
711
+ | field | { key: keyof S; value: any } | ✔️ | Field to add |
1163
712
 
1164
- | Property | Type | Default | Required |
1165
- | ------------ | ------------------ | ------- | -------- |
1166
- | created_at | `string` | _none_ | ✔️ |
1167
- | discarded_at | `string` \| `null` | _none_ | ✔️ |
1168
- | name | `string` \| `null` | _none_ | ✔️ |
1169
- | site_id | `string` | _none_ | ✔️ |
713
+ ### AddSubscriberParameters `<S>`
1170
714
 
1171
- ---
715
+ Parameters for adding a new subscriber.
1172
716
 
1173
- ### `TagAttributes`
717
+ | Property | Type | Required | Description |
718
+ | -------- | ------------- | -------- | ------------------------------------ |
719
+ | date | Date | ❌ | Date of subscription |
720
+ | email | string | ✔️ | Subscriber's email address |
721
+ | fields | Partial `<S>` | ❌ | Additional fields for the subscriber |
1174
722
 
1175
- | Property | Type | Default | Required |
1176
- | ---------- | --------------------------------- | ------- | -------- |
1177
- | attributes | [`TagAttributes`](#TagAttributes) | _none_ | ✔️ |
1178
- | id | `string` | _none_ | ✔️ |
1179
- | type | [`EntityType.TAG`](#EntityType) | _none_ | ✔️ |
723
+ ### AddTagParameters
1180
724
 
1181
- ---
725
+ Parameters for adding a tag to a subscriber.
1182
726
 
1183
- ### `TagSubscriberParameters`
727
+ | Property | Type | Required | Description |
728
+ | -------- | ------ | -------- | -------------------------- |
729
+ | email | string | ✔️ | Subscriber's email address |
730
+ | tagName | string | ✔️ | Name of the tag to add |
1184
731
 
1185
- | Property | Type | Default | Required |
1186
- | -------- | -------- | ------- | -------- |
1187
- | date | `Date` | _none_ | ❌ |
1188
- | email | `string` | _none_ | ✔️ |
1189
- | tagName | `string` | _none_ | ✔️ |
732
+ ### BatchImportEventsParameter `<S>`, `<E>`
1190
733
 
1191
- ---
734
+ Parameters for batch importing events.
1192
735
 
1193
- ### `TrackParameters<S, E>`
736
+ | Property | Type | Required | Description |
737
+ | -------- | ----------------------- | -------- | ------------------------- |
738
+ | events | BentoEvent `<S>`, `<E>` | ✔️ | Array of events to import |
1194
739
 
1195
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
740
+ ### BatchImportSubscribersParameter `<S>`
1196
741
 
1197
- The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
742
+ Parameters for batch importing subscribers.
1198
743
 
1199
- | Property | Type | Default | Required |
1200
- | -------- | ------------------------ | ------- | -------- |
1201
- | email | `string` | _none_ | ✔️ |
1202
- | type | `string` | _none_ | ✔️ |
1203
- | details | `{ [key: string]: any }` | _none_ | ❌ |
1204
- | fields | `Partial<S>` | _none_ | ❌ |
744
+ | Property | Type | Required | Description |
745
+ | ----------- | ------------------------------------- | -------- | ------------------------------ |
746
+ | subscribers | ({ email: string } & Partial `<S>`)[] | ✔️ | Array of subscribers to import |
1205
747
 
1206
- ---
748
+ ### BentoEvent `<S>`, `<E>`
1207
749
 
1208
- ### `TrackPurchaseParameters`
750
+ Represents different types of events in Bento. It's a union of the following event types:
1209
751
 
1210
- | Property | Type | Default | Required |
1211
- | --------------- | ------------------------------------- | ------- | -------- |
1212
- | date | `Date` | _none_ | ❌ |
1213
- | email | `string` | _none_ | ✔️ |
1214
- | purchaseDetails | [`PurchaseDetails`](#PurchaseDetails) | _none_ | ✔️ |
752
+ - BaseEvent `<E>`
753
+ - PurchaseEvent
754
+ - SubscribeEvent `<S>`
755
+ - TagEvent
756
+ - UnsubscribeEvent
757
+ - UpdateFieldsEvent `<S>`
1215
758
 
1216
- ---
759
+ ### PurchaseDetails
1217
760
 
1218
- ### `UnsubscribeParameters`
761
+ Details of a purchase event.
1219
762
 
1220
- | Property | Type | Default | Required |
1221
- | -------- | -------- | ------- | -------- |
1222
- | email | `string` | _none_ | ✔️ |
763
+ | Property | Type | Required | Description |
764
+ | -------- | ------------------------------------ | -------- | ---------------------------------- |
765
+ | unique | { key: string \| number } | ✔️ | Unique identifier for the purchase |
766
+ | value | { currency: string; amount: number } | ✔️ | Value of the purchase |
767
+ | cart | PurchaseCart | ❌ | Additional cart details |
1223
768
 
1224
- ---
769
+ ### ChangeEmailParameters
1225
770
 
1226
- ### `UpdateFieldsParameters<S>`
771
+ Parameters for changing a subscriber's email.
1227
772
 
1228
- The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
773
+ | Property | Type | Required | Description |
774
+ | -------- | ------ | -------- | --------------------- |
775
+ | oldEmail | string | ✔️ | Current email address |
776
+ | newEmail | string | ✔️ | New email address |
1229
777
 
1230
- | Property | Type | Default | Required |
1231
- | -------- | ------------ | ------- | -------- |
1232
- | date | `Date` | _none_ | ❌ |
1233
- | email | `string` | _none_ | ✔️ |
1234
- | fields | `Partial<S>` | _none_ | ✔️ |
778
+ ### CreateFieldParameters
1235
779
 
1236
- ---
780
+ Parameters for creating a new field.
1237
781
 
1238
- ### `ValidateEmailParameters`
782
+ | Property | Type | Required | Description |
783
+ | -------- | ------ | -------- | -------------------- |
784
+ | key | string | ✔️ | Key of the new field |
1239
785
 
1240
- | Property | Type | Default | Required |
1241
- | --------- | -------- | ------- | -------- |
1242
- | email | `string` | _none_ | ✔️ |
1243
- | ip | `string` | _none_ | ❌ |
1244
- | name | `string` | _none_ | ❌ |
1245
- | userAgent | `string` | _none_ | ❌ |
786
+ ### CreateTagParameters
1246
787
 
1247
- ## TypeScript
788
+ Parameters for creating a new tag.
1248
789
 
1249
- The Bento Node SDK is written entirely in TypeScript and, as such, has first-class support for projects written in TypeScript. It takes advantage of generics to make your code more bullet-proof and reduce bugs throughout your system.
790
+ | Property | Type | Required | Description |
791
+ | -------- | ------ | -------- | ------------------- |
792
+ | name | string | ✔️ | Name of the new tag |
1250
793
 
1251
- ### Generics
794
+ ### Subscriber `<S>`
1252
795
 
1253
- #### `S`
796
+ Represents a subscriber in Bento.
1254
797
 
1255
- The `S` generic is a type that represents the shape of the custom fields on your Bento subscribers. If this is provided, all of the methods that interact with these fields (including fetching the subscriber from the API) will be typed appropriately.
798
+ | Property | Type | Required | Description |
799
+ | ---------- | -------------------------- | -------- | ---------------------------- |
800
+ | attributes | SubscriberAttributes `<S>` | ✔️ | Attributes of the subscriber |
801
+ | id | string | ✔️ | Unique identifier |
802
+ | type | EntityType.VISITOR | ✔️ | Type of the entity |
1256
803
 
1257
- To set this type, pass it as the first generic parameter when initializing your `Analytics` object.
804
+ ### TrackParameters `<S>`, `<E>`
1258
805
 
1259
- ```ts
1260
- type MySubscriberFields = {
1261
- firstName: string;
1262
- lastName: string;
1263
- age: number;
1264
- };
806
+ Parameters for tracking an event.
1265
807
 
1266
- const bento = new Analytics<MySubscriberFields>({
1267
- // ... initialization options from above.
1268
- });
1269
- ```
808
+ | Property | Type | Required | Description |
809
+ | -------- | ---------------------- | -------- | ----------------------------------- |
810
+ | email | string | ✔️ | Subscriber's email address |
811
+ | type | string | ✔️ | Type of the event |
812
+ | details | { [key: string]: any } | ❌ | Additional details of the event |
813
+ | fields | Partial `<S>` | ❌ | Fields to update for the subscriber |
1270
814
 
1271
- #### `E`
815
+ ### ValidateEmailParameters
1272
816
 
1273
- The `E` generic is a string that represents the custom prefix used for your custom commands. This is used to ensure that you are not accidentally changing things on your subscribers that you do not intend to change. It also prevents clashes with using internal Bento events.
817
+ Parameters for validating an email address.
1274
818
 
1275
- To set this type, pass it as the second generic parameter when initializing your `Analytics` object.
819
+ | Property | Type | Required | Description |
820
+ | --------- | ------ | -------- | ------------------------------ |
821
+ | email | string | ✔️ | Email address to validate |
822
+ | ip | string | ❌ | IP address of the user |
823
+ | name | string | ❌ | Name associated with the email |
824
+ | userAgent | string | ❌ | User agent string |
1276
825
 
1277
- ```ts
1278
- const bento = new Analytics<any, '$myPrefix.'>({
1279
- // ... initialization options from above.
1280
- });
1281
- ```
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.
1282
827
 
1283
828
  ## Things to know
1284
829
 
1285
- 1. Tracking: All events must be identified. Anonymous support coming soon!
1286
- 2. Tracking: Most events and indexed inside Bento within a few seconds.
1287
- 3. If you need support, just let us know!
830
+ - All events must be identified with an email address.
831
+ - Most events are indexed within seconds in your Bento account.
832
+ - The SDK supports TypeScript with generics for custom fields and events.
833
+ - Batch operations are available for importing subscribers and events efficiently.
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
+ ```
1288
861
 
1289
862
  ## Contributing
1290
863
 
1291
- Bug reports and pull requests are welcome on GitHub at https://github.com/bentonow/bento-node-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
864
+ We welcome contributions! Please see our [contributing guidelines](CODE_OF_CONDUCT.md) for details on how to submit pull requests, report issues, and suggest improvements.
1292
865
 
1293
866
  ## License
1294
867
 
1295
- The package is available as open source under the terms of the MIT License.
868
+ The Bento SDK for Node.js is available as open source under the terms of the [MIT License](LICENSE.md).