@bentonow/bento-node-sdk 0.2.1 → 1.0.4

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 (75) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +494 -1077
  3. package/dist/index.d.ts +9 -9
  4. package/dist/index.js +1273 -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 +25 -0
  11. package/dist/sdk/broadcasts/types.d.ts +28 -0
  12. package/dist/sdk/client/errors.d.ts +9 -6
  13. package/dist/sdk/client/index.d.ts +74 -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 +13 -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 +164 -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 +13 -25
  46. package/src/sdk/broadcasts/index.ts +43 -0
  47. package/src/sdk/broadcasts/types.ts +34 -0
  48. package/src/sdk/client/errors.ts +7 -0
  49. package/src/sdk/client/index.ts +113 -30
  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/sequences/index.ts +21 -0
  61. package/src/sdk/sequences/types.ts +21 -0
  62. package/src/sdk/stats/index.ts +37 -0
  63. package/src/sdk/stats/types.ts +28 -0
  64. package/src/sdk/subscribers/index.ts +5 -15
  65. package/src/sdk/tags/index.ts +1 -3
  66. package/src/sdk/types.ts +1 -1
  67. package/src/sdk/workflows/index.ts +21 -0
  68. package/src/sdk/workflows/types.ts +21 -0
  69. package/src/versions/v1/index.ts +59 -10
  70. package/dist/bento-node-sdk.cjs.development.js +0 -2071
  71. package/dist/bento-node-sdk.cjs.development.js.map +0 -1
  72. package/dist/bento-node-sdk.cjs.production.min.js +0 -2
  73. package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
  74. package/dist/bento-node-sdk.esm.js +0 -2063
  75. package/dist/bento-node-sdk.esm.js.map +0 -1
package/README.md CHANGED
@@ -1,1295 +1,712 @@
1
- # Bento SDK for Node.JS
1
+ # Bento Node SDK
2
+ <img align="right" src="https://app.bentonow.com/brand/logoanim.gif">
2
3
 
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)
4
-
5
- 🍱 Simple, powerful analytics for Node.JS projects!
4
+ > [!TIP]
5
+ > Need help? Join our [Discord](https://discord.gg/ssXXFRmt5F) or email jesse@bentonow.com for personalized support.
6
6
 
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.
7
+ 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
8
 
9
- 👋 To get personalized support, please tweet @bento or email jesse@bentonow.com!
9
+ Get started with our [📚 integration guides](https://docs.bentonow.com), or [📘 browse the SDK reference](https://docs.bentonow.com/subscribers).
10
10
 
11
11
  🐶 Battle-tested by [NativShark](https://nativshark.com) Bento Production (a Bento customer)!
12
12
 
13
13
  ❤️ Thank you @HelloKashif from [IPInfo](https://ipinfo.io) for your contribution.
14
+
14
15
  ❤️ Thank you @jonsherrard from [Devular](https://www.devular.com/) for your contribution.
15
16
 
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.
17
+ [![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
18
 
66
- ```bash
67
- npm install @bentonow/bento-node-sdk --save
68
- ```
19
+ Table of contents
20
+ =================
69
21
 
70
- ## Getting Started
71
22
 
72
- To get started with tracking your users in Bento, simply initialize the client and go wild.
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)
73
33
 
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.
75
34
 
76
- ```ts
77
- import { Analytics } from '@bentonow/bento-node-sdk';
35
+ ## Features
78
36
 
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
- });
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.
87
43
 
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));
44
+ ## Requirements
99
45
 
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
- });
46
+ The Bento Node.js SDK requires Node.js version 12 or later.
110
47
 
111
- ```
48
+ Bento Account for a valid **SITE_UUID**, **BENTO_PUBLISHABLE_KEY** & **BENTO_SECRET_KEY**.
112
49
 
113
- Read on to see what all you can do with the SDK.
50
+ ## Getting started
114
51
 
115
- # Modules
52
+ ### Installation
116
53
 
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
+ Install the Bento SDK in your project folder:
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
+ ```bash
120
57
 
121
- ## Analytics (Base Module)
58
+ # Using npm
59
+ npm install @bentonow/bento-node-sdk --save
122
60
 
123
- ### `tagSubscriber(parameters: TagSubscriberParameters): Promise<boolean>`
61
+ # Using Bun
62
+ bun add @bentonow/bento-node-sdk
63
+ ```
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
+ ### Using Bun (Recommended)
66
+ ```bash
67
+ # Install dependencies
68
+ bun install
126
69
 
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.
70
+ # Run tests
71
+ bun test
128
72
 
129
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
73
+ # Run tests with coverage
74
+ bun test:coverage
130
75
 
131
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
76
+ # Build the package
77
+ bun run build
132
78
 
133
- Reference Types: [TagSubscriberParameters](#TagSubscriberParameters)
79
+ # Lint code
80
+ bun run lint
134
81
 
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));
82
+ # Format code
83
+ bun run format
142
84
  ```
143
85
 
144
- ---
86
+ ### Using npm
87
+ ```bash
88
+ # Install dependencies
89
+ npm install
145
90
 
146
- ### `addSubscriber(parameters: AddSubscriberParameters<S>): Promise<boolean>`
91
+ # Run tests
92
+ npm run test:npm
147
93
 
148
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.subscribe`](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null) method.
94
+ # Run tests with coverage
95
+ npm run test:coverage:npm
149
96
 
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.
97
+ # Build the package
98
+ npm run build:npm
151
99
 
152
- You may optionally pass any fields that you wish to be set on the subscriber during creation.
100
+ # Lint code
101
+ npm run lint
153
102
 
154
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
103
+ # Format code
104
+ npm run format
105
+ ```
155
106
 
156
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
107
+ ### Integration
157
108
 
158
- Reference Types: [AddSubscriberParameters\<S\>](#addsubscriberparameterss)
109
+ Initialize the Bento client and start tracking events:
159
110
 
160
- ```ts
161
- bento.V1.addSubscriber({
162
- email: 'test@bentonow.com',
163
- })
164
- .then(result => console.log(result))
165
- .catch(error => console.error(error));
111
+ ```javascript
112
+ import { Analytics } from '@bentonow/bento-node-sdk';
166
113
 
167
- bento.V1.addSubscriber({
168
- date: new Date('2021-08-20T01:32:57.530Z'),
169
- email: 'test@bentonow.com',
114
+ const bento = new Analytics({
115
+ authentication: {
116
+ publishableKey: 'bento-publishable-key',
117
+ secretKey: 'bento-secret-key',
118
+ },
119
+ siteUuid: 'bento-site-uuid',
120
+ });
121
+
122
+ bento.V1.track({
123
+ email: 'user@example.com',
124
+ type: '$formSubmitted',
170
125
  fields: {
171
- firstName: 'Test',
172
- lastName: 'Subscriber',
126
+ first_name: 'John',
127
+ last_name: 'Doe',
173
128
  },
174
- })
175
- .then(result => console.log(result))
176
- .catch(error => console.error(error));
129
+ details: {
130
+ fromCustomEvent: true,
131
+ },
132
+ }).then(result => console.log(result));
177
133
  ```
178
134
 
179
- ---
180
-
181
- ### `removeSubscriber(parameters: RemoveSubscriberParameters): Promise<boolean>`
182
-
183
- **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.unsubscribe`](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null) method.
184
135
 
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.
136
+ ## Modules
137
+ The Bento SDK provides several modules for different operations:
186
138
 
187
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
139
+ ### Analytics (Base Module)
188
140
 
189
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
141
+ Core functionality for tracking events and managing subscribers.
190
142
 
191
- Reference Types: [RemoveSubscriberParameters](#RemoveSubscriberParameters)
143
+ ### Convenience Helpers
144
+ #### tagSubscriber
145
+ Tags a subscriber with a specific tag.
192
146
 
193
- ```ts
194
- bento.V1.removeSubscriber({
195
- email: 'test@bentonow.com',
196
- })
197
- .then(result => console.log(result))
198
- .catch(error => console.error(error));
147
+ ```javascript
148
+ bento.V1.tagSubscriber({
149
+ email: 'user@example.com',
150
+ tagName: 'New Customer',
151
+ }).then(result => console.log(result));
199
152
  ```
200
153
 
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.
154
+ #### addSubscriber
155
+ Adds a new subscriber to your Bento account.
208
156
 
209
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
210
-
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',
157
+ ```javascript
158
+ bento.V1.addSubscriber({
159
+ email: 'newuser@example.com',
218
160
  fields: {
219
- firstName: 'Test',
161
+ firstName: 'John',
162
+ lastName: 'Doe',
220
163
  },
221
- })
222
- .then(result => console.log(result))
223
- .catch(error => console.error(error));
164
+ }).then(result => console.log(result));
224
165
  ```
225
166
 
226
- ---
227
-
228
- ### `trackPurchase(parameters: TrackPurchaseParameters): Promise<boolean>`
229
-
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.
167
+ #### removeSubscriber
168
+ Removes a subscriber from your Bento account.
235
169
 
236
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
170
+ ```javascript
171
+ bento.V1.removeSubscriber({
172
+ email: 'user@example.com',
173
+ }).then(result => console.log(result));
174
+ ```
237
175
 
238
- Reference Types: [TrackPurchaseParameters](#TrackPurchaseParameters)
176
+ #### upsertSubscriber
177
+ Updates existing subscriber or creates a new one if they don't exist:
239
178
 
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
- },
179
+ ```javascript
180
+ await analytics.V1.upsertSubscriber({
181
+ email: 'user@example.com',
182
+ fields: {
183
+ firstName: 'John',
184
+ lastName: 'Doe',
185
+ company: 'Acme Inc'
251
186
  },
252
- })
253
- .then(result => console.log(result))
254
- .catch(error => console.error(error));
187
+ tags: 'lead,mql',
188
+ remove_tags: 'customer'
189
+ });
255
190
  ```
256
191
 
257
- ---
258
-
259
- ### `track(parameters: TrackParameters<S, E>): Promise<boolean>`
260
192
 
261
- **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering automations.
262
193
 
263
- Tracks a custom event in Bento.
194
+ #### updateFields
195
+ Updates custom fields for a subscriber.
264
196
 
265
- Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
266
-
267
- Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
197
+ ```javascript
198
+ bento.V1.updateFields({
199
+ email: 'user@example.com',
200
+ fields: {
201
+ lastPurchaseDate: new Date(),
202
+ },
203
+ }).then(result => console.log(result));
204
+ ```
268
205
 
269
- Reference Types: [TrackParameters<S, E>](#trackparametersse)
206
+ #### track
207
+ Tracks a custom event for a subscriber.
270
208
 
271
- ```ts
209
+ ```javascript
272
210
  bento.V1.track({
273
- email: 'test@bentonow.com',
274
- type: '$custom.event',
275
- fields: {
276
- firstName: 'Custom Name',
277
- lastName: 'Custom Name',
278
- },
211
+ email: 'user@example.com',
212
+ type: '$pageView',
279
213
  details: {
280
- fromCustomEvent: true,
214
+ url: '/products',
281
215
  },
282
- })
283
- .then(result => console.log(result))
284
- .catch(error => console.error(error));
216
+ }).then(result => console.log(result));
285
217
  ```
286
218
 
287
- ## Batch
288
-
289
- ### `Batch.importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number>`
219
+ #### trackPurchase
220
+ Tracks a purchase event for a subscriber.
290
221
 
291
- **This does not trigger automations!** - If you wish to trigger automations, please batch import events.
292
-
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.
222
+ ```javascript
223
+ bento.V1.trackPurchase({
224
+ email: 'user@example.com',
225
+ purchaseDetails: {
226
+ unique: { key: 'order-123' },
227
+ value: { amount: 9999, currency: 'USD' },
228
+ },
229
+ }).then(result => console.log(result));
230
+ ```
294
231
 
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.
232
+ ### Low Level API calls
233
+ ### Batch
296
234
 
297
- Returns the number of subscribers that were imported.
235
+ Perform bulk operations for importing subscribers and events.
298
236
 
299
- Reference Types: [BatchImportSubscribersParameter\<S\>](#batchimportsubscribersparameters)
237
+ #### importSubscribers
238
+ Imports multiple subscribers in a single operation.
300
239
 
301
- ```ts
240
+ ```javascript
302
241
  bento.V1.Batch.importSubscribers({
303
242
  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
- },
243
+ { email: 'user1@example.com', firstName: 'Alice' },
244
+ { email: 'user2@example.com', firstName: 'Bob' },
317
245
  ],
318
- })
319
- .then(result => console.log(result))
320
- .catch(error => console.error(error));
246
+ }).then(result => console.log(result));
321
247
  ```
322
248
 
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,
249
+ #### importEvents
250
+ Imports multiple events in a single operation.
328
251
 
329
- Returns the number of events that were imported.
330
-
331
- Reference Types: [BatchImportEventsParameter<S, E>](#batchimporteventsparameterse)
332
-
333
- ```ts
252
+ ```javascript
334
253
  bento.V1.Batch.importEvents({
335
254
  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
- },
255
+ { email: 'user@example.com', type: '$login' },
256
+ { email: 'user@example.com', type: '$pageView', details: { url: '/home' } },
365
257
  ],
366
- })
367
- .then(result => console.log(result))
368
- .catch(error => console.error(error));
258
+ }).then(result => console.log(result));
369
259
  ```
370
260
 
371
- ---
372
-
373
- ### `Batch.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>`
374
261
 
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`.
262
+ ### Broadcast Management
376
263
 
377
- In addition you can add a `personalizations` object to provide liquid tags that will be injected into the email.
264
+ #### getBroadcasts
265
+ Retrieves all broadcasts:
378
266
 
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.
267
+ ```javascript
268
+ const broadcasts = await analytics.V1.Broadcasts.getBroadcasts();
269
+ ```
380
270
 
381
- Returns the number of emails that were imported.
271
+ #### createBroadcast
272
+ Creates new broadcast campaigns:
273
+
274
+ ```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'
283
+ },
284
+ inclusive_tags: 'lead,mql',
285
+ exclusive_tags: 'unsubscribed',
286
+ segment_id: 'segment_123',
287
+ batch_size_per_hour: 1000
288
+ }]);
289
+ ```
382
290
 
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.
395
- },
396
- ],
397
- })
398
- .then(result => console.log(result))
399
- .catch(error => console.error(error));
291
+ ### Transactional Emails
292
+
293
+ #### createEmails
294
+ Creates a new transactional email:
295
+
296
+ ```javascript
297
+ 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
+ }]
308
+ });
309
+ ```
310
+ ### Email Structure
311
+ Each email object requires:
312
+
313
+ - **to:** Recipient email address
314
+ - **from:** Sender email address
315
+ - **subject:** Email subject (supports liquid templates)
316
+ - **html_body:** HTML email content (supports liquid templates)
317
+ - **transactional:** true/false: defaults to false, must be true to send to unsubscribed users
318
+ - **personalizations:** Optional object for liquid template variables
319
+
320
+ #### Constraints
321
+
322
+ - **Batch size:** 1-100 emails per request
323
+ - **Errors:** Throws TooFewEmailsError or TooManyEmailsError for invalid counts
324
+ - **Returns:** Number of emails successfully queued
325
+
326
+
327
+ ### Statistics
328
+
329
+ #### getSiteStats
330
+ Retrieves overall site statistics:
331
+
332
+ ```javascript
333
+ const stats = await analytics.V1.Stats.getSiteStats();
334
+ // Returns:
335
+ // {
336
+ // total_subscribers: 1000,
337
+ // active_subscribers: 950,
338
+ // unsubscribed_count: 50,
339
+ // broadcast_count: 25,
340
+ // average_open_rate: 45.5,
341
+ // average_click_rate: 12.3
342
+ // }
400
343
  ```
401
344
 
402
- ## Commands
345
+ #### getSegmentStats
346
+ Retrieves statistics for a specific segment:
347
+
348
+ ```javascript
349
+ const segmentStats = await analytics.V1.Stats.getSegmentStats('segment_123');
350
+ // Returns:
351
+ // {
352
+ // segment_id: 'segment_123',
353
+ // subscriber_count: 500,
354
+ // growth_rate: 2.5,
355
+ // engagement_rate: 35.8,
356
+ // last_updated: '2024-01-01T00:00:00Z'
357
+ // }
358
+ ```
403
359
 
404
- ### `Commands.addTag(parameters: AddTagParameters): Promise<Subscriber<S> | null>`
360
+ #### getReportStats
361
+ Retrieves statistics for a specific report:
362
+
363
+ ```javascript
364
+ const reportStats = await analytics.V1.Stats.getReportStats('report_123');
365
+ // Returns:
366
+ // {
367
+ // report_id: 'report_123',
368
+ // total_sent: 1000,
369
+ // total_opens: 750,
370
+ // unique_opens: 500,
371
+ // total_clicks: 250,
372
+ // unique_clicks: 200,
373
+ // unsubscribes: 5,
374
+ // spam_reports: 1
375
+ // }
376
+ ```
405
377
 
406
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `tagSubscriber` method.
407
378
 
408
- Adds a tag to the subscriber with the matching email.
379
+ ### Commands
409
380
 
410
- Note that both the tag and the subscriber will be created if either is missing from system.
381
+ Execute specific commands for subscriber management.
411
382
 
412
- Reference Types: [AddTagParameters](#AddTagParameters), [Subscriber\<S\>](#subscribers)
383
+ #### addTag
384
+ Adds a tag to a subscriber.
413
385
 
414
- ```ts
386
+ ```javascript
415
387
  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));
388
+ email: 'user@example.com',
389
+ tagName: 'VIP',
390
+ }).then(result => console.log(result));
421
391
  ```
422
392
 
423
- ---
424
-
425
- ### `Commands.removeTag(parameters: RemoveTagParameters): Promise<Subscriber<S> | null>`
426
-
427
- Removes the specified tag from the subscriber with the matching email.
428
-
429
- Reference Types: [RemoveTagParameters](#RemoveTagParameters), [Subscriber\<S\>](#subscribers)
393
+ #### removeTag
394
+ Removes a tag from a subscriber.
430
395
 
431
- ```ts
396
+ ```javascript
432
397
  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));
398
+ email: 'user@example.com',
399
+ tagName: 'VIP',
400
+ }).then(result => console.log(result));
438
401
  ```
439
402
 
440
- ---
441
-
442
- ### `Commands.addField(parameters: AddFieldParameters<S>): Promise<Subscriber<S> | null>`
443
-
444
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `updateFields` method.
445
-
446
- Adds a field to the subscriber with the matching email.
447
-
448
- Note that both the field and the subscriber will be created if either is missing from system.
403
+ #### addField
404
+ Adds a custom field to a subscriber.
449
405
 
450
- Reference Types: [AddFieldParameters\<S\>](#addfieldparameterss), [Subscriber\<S\>](#subscribers)
451
-
452
- ```ts
406
+ ```javascript
453
407
  bento.V1.Commands.addField({
454
- email: 'test@bentonow.com',
408
+ email: 'user@example.com',
455
409
  field: {
456
- key: 'testKey',
457
- value: 'testValue',
410
+ key: 'favoriteColor',
411
+ value: 'blue',
458
412
  },
459
- })
460
- .then(result => console.log(result))
461
- .catch(error => console.error(error));
413
+ }).then(result => console.log(result));
462
414
  ```
463
415
 
464
- ---
465
-
466
- ### `Commands.removeField(parameters: RemoveFieldParameters<S>): Promise<Subscriber<S> | null>`
467
-
468
- Removes a field to the subscriber with the matching email.
416
+ #### removeField
417
+ Removes a custom field from a subscriber.
469
418
 
470
- Reference Types: [RemoveFieldParameters\<S\>](#removefieldparameterss), [Subscriber\<S\>](#subscribers)
471
-
472
- ```ts
419
+ ```javascript
473
420
  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));
479
- ```
480
-
481
- ---
482
-
483
- ### `Commands.subscribe(parameters: SubscribeParameters): Promise<Subscriber<S> | null>`
484
-
485
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `addSubscriber` method.
486
-
487
- Subscribes the supplied email to Bento. If the email does not exist, it is created.
488
-
489
- If the subscriber had previously unsubscribed, they will be re-subscribed.
490
-
491
- Reference Types: [SubscribeParameters](#SubscribeParameters), [Subscriber\<S\>](#subscribers)
492
-
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));
499
- ```
500
-
501
- ---
502
-
503
- ### `Commands.unsubscribe(parameters: UnsubscribeParameters): Promise<Subscriber<S> | null>`
504
-
505
- **This does not trigger automations!** - If you wish to trigger automations, please use the core module's `removeSubscriber` method.
506
-
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.
508
-
509
- Reference Types: [UnsubscribeParameters](#UnsubscribeParameters), [Subscriber\<S\>](#subscribers)
510
-
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));
421
+ email: 'user@example.com',
422
+ fieldName: 'favoriteColor',
423
+ }).then(result => console.log(result));
517
424
  ```
518
425
 
519
- ---
520
-
521
- ### `Commands.changeEmail(parameters: ChangeEmailParameters): Promise<Subscriber<S> | null>`
522
-
523
- Updates the email of a user in Bento.
524
-
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));
534
- ```
535
-
536
- ## Experimental
537
-
538
- ### `Experimental.validateEmail(parameters: ValidateEmailParameters): Promise<boolean>`
539
-
540
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
541
-
542
- Attempts to validate the email. You can provide additional information to further refine the validation.
426
+ ### Experimental
543
427
 
544
- If a name is provided, it compares it against the US Census Data, and so the results may be biased.
428
+ Access experimental features (use with caution).
545
429
 
546
- Reference Types: [ValidateEmailParameters](#ValidateEmailParameters)
430
+ #### validateEmail
431
+ Attempts to validate an email address.
547
432
 
548
- ```ts
433
+ ```javascript
549
434
  bento.V1.Experimental.validateEmail({
550
- email: 'test@bentonow.com',
551
- })
552
- .then(result => console.log(result))
553
- .catch(error => console.error(error));
435
+ email: 'user@example.com',
436
+ }).then(result => console.log(result));
554
437
  ```
555
438
 
556
- ---
439
+ #### guessGender
440
+ Attempts to guess the gender based on a given name.
557
441
 
558
- ### `Experimental.guessGender(parameters: GuessGenderParameters): Promise<GuessGenderResponse>`
559
-
560
- **EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
561
-
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
442
+ ```javascript
569
443
  bento.V1.Experimental.guessGender({
570
- name: 'Jesse',
571
- })
572
- .then(result => console.log(result))
573
- .catch(error => console.error(error));
444
+ name: 'Alex',
445
+ }).then(result => console.log(result));
574
446
  ```
575
447
 
576
- ---
577
-
578
- ### `Experimental.geolocate(parameters: GeolocateParameters): Promise<LocationData | null>`
579
-
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)
448
+ is blacklisted:
585
449
 
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));
450
+ ```javascript
451
+ const blacklistStatus = await analytics.V1.Experimental.getBlacklistStatus({
452
+ domain: 'example.com'
453
+ // or ipAddress: '192.168.1.1'
454
+ });
592
455
  ```
593
456
 
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.
599
-
600
- Looks up the provided URL or IP Address against various blacklists to see if the site has been blacklisted anywhere.
601
-
602
- Reference Types: [BlacklistParameters](#BlacklistParameters), [BlacklistResponse](#BlacklistResponse)
603
-
604
- ```ts
605
- bento.V1.Experimental.checkBlacklist({
606
- domain: 'bentonow.com',
607
- })
608
- .then(result => console.log(result))
609
- .catch(error => console.error(error));
457
+ #### getContentModeration
458
+ Performs content moderation on text:
459
+
460
+ ```javascript
461
+ const moderationResult = await analytics.V1.Experimental.getContentModeration(
462
+ 'Content to moderate'
463
+ );
464
+ // Returns:
465
+ // {
466
+ // flagged: boolean,
467
+ // categories: {
468
+ // hate: boolean,
469
+ // 'hate/threatening': boolean,
470
+ // 'self-harm': boolean,
471
+ // ...
472
+ // },
473
+ // category_scores: {
474
+ // hate: number,
475
+ // 'hate/threatening': number,
476
+ // ...
477
+ // }
478
+ // }
610
479
  ```
611
480
 
612
- ## Fields
613
-
614
- ### `Fields.getFields(): Promise<Field[] | null>`
615
-
616
- Returns all of the fields for the site.
617
-
618
- Reference Types: [Field](#Field)
619
-
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));
481
+ #### geoLocateIP
482
+ Gets detailed geolocation information for an IP address:
483
+
484
+ ```javascript
485
+ const location = await analytics.V1.Experimental.geoLocateIP('192.168.1.1');
486
+ // Returns:
487
+ // {
488
+ // city_name: 'San Francisco',
489
+ // country_name: 'United States',
490
+ // latitude: 37.7749,
491
+ // longitude: -122.4194,
492
+ // ...
493
+ // }
626
494
  ```
627
495
 
628
- ---
496
+ ### Fields
629
497
 
630
- ### `Fields.createField(parameters: CreateFieldParameters): Promise<Field[] | null>`
498
+ Manage custom fields for your subscribers.
631
499
 
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:
500
+ #### getFields
501
+ Retrieves all custom fields defined in your Bento account.
633
502
 
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'` |
503
+ ```javascript
504
+ bento.V1.Fields.getFields().then(fields => console.log(fields));
505
+ ```
640
506
 
641
- Reference Types: [CreateFieldParameters](#CreateFieldParameters), [Field](#Field)
507
+ #### createField
508
+ Creates a new custom field in your Bento account.
642
509
 
643
- ```ts
510
+ ```javascript
644
511
  bento.V1.Fields.createField({
645
- key: 'testKey',
646
- })
647
- .then(result => console.log(result))
648
- .catch(error => console.error(error));
512
+ key: 'loyaltyPoints',
513
+ }).then(result => console.log(result));
649
514
  ```
650
515
 
651
- ## Forms
516
+ ### Forms
652
517
 
653
- ### `Forms.getResponses(formIdentifier: string): Promise<FormResponse[] | null>`
518
+ Retrieve form responses.
654
519
 
655
- Returns all of the responses for the form with the specified identifier.
520
+ #### getResponses
521
+ Retrieves responses for a specific form.
656
522
 
657
- Reference Types: [FormResponse](#FormResponse)
658
-
659
- ```ts
660
- bento.V1.Forms.getResponses('test-formid-1234')
661
- .then(result => console.log(result))
662
- .catch(error => console.error(error));
523
+ ```javascript
524
+ bento.V1.Forms.getResponses('form-id-123').then(responses => console.log(responses));
663
525
  ```
664
526
 
665
- ## Subscribers
666
-
667
- ### `Subscribers.getSubscribers(parameters?: GetSubscribersParameters): Promise<Subscriber<S> | null>`
527
+ ### Subscribers
668
528
 
669
- Returns the subscriber with the specified email or UUID.
529
+ Manage individual subscribers.
670
530
 
671
- Reference Types: [GetSubscribersParameters](#GetSubscribersParameters), [Subscriber\<S\>](#subscribers)
531
+ #### getSubscribers
532
+ Retrieves subscriber information.
672
533
 
673
- ```ts
534
+ ```javascript
674
535
  bento.V1.Subscribers.getSubscribers({
675
- uuid: '1234',
676
- })
677
- .then(result => console.log(result))
678
- .catch(error => console.error(error));
679
-
680
- bento.V1.Subscribers.getSubscribers({
681
- email: 'test@bentonow.com',
682
- })
683
- .then(result => console.log(result))
684
- .catch(error => console.error(error));
536
+ email: 'user@example.com',
537
+ }).then(subscriber => console.log(subscriber));
685
538
  ```
686
539
 
687
- ---
688
-
689
- ### `Subscribers.createSubscriber(parameters: CreateSubscriberParameters): Promise<Subscriber<S> | null>`
690
-
691
- Creates a subscriber inside of Bento.
692
-
693
- Reference Types: [CreateSubscriberParameters](#CreateSubscriberParameters), [Subscriber\<S\>](#subscribers)
540
+ #### createSubscriber
541
+ Creates a new subscriber in your Bento account.
694
542
 
695
- ```ts
543
+ ```javascript
696
544
  bento.V1.Subscribers.createSubscriber({
697
- email: 'test@bentonow.com',
698
- })
699
- .then(result => console.log(result))
700
- .catch(error => console.error(error));
545
+ email: 'newuser@example.com',
546
+ }).then(result => console.log(result));
701
547
  ```
702
548
 
703
- ## Tags
549
+ ### Tags
704
550
 
705
- ### `Tags.getTags(): Promise<Tag[] | null>`
551
+ Create and manage tags for subscriber segmentation.
706
552
 
707
- Returns all of the fields for the site.
553
+ #### getTags
554
+ Retrieves all tags defined in your Bento account.
708
555
 
709
- Reference Types: [Tag](#Tag)
710
-
711
- ```ts
712
- bento.V1.Tags.getTags()
713
- .then(result => console.log(result))
714
- .catch(error => console.error(error));
556
+ ```javascript
557
+ bento.V1.Tags.getTags().then(tags => console.log(tags));
715
558
  ```
716
559
 
717
- ---
718
-
719
- ### `Tags.createTag(parameters: CreateTagParameters): Promise<Tag[] | null>`
720
-
721
- Creates a tag inside of Bento.
560
+ #### createTag
561
+ Creates a new tag in your Bento account.
722
562
 
723
- Reference Types: [Tag](#Tag)
724
-
725
- ```ts
563
+ ```javascript
726
564
  bento.V1.Tags.createTag({
727
- name: 'test tag',
728
- })
729
- .then(result => console.log(result))
730
- .catch(error => console.error(error));
565
+ name: 'Premium Customer',
566
+ }).then(result => console.log(result));
731
567
  ```
732
568
 
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_ | ✔️ |
569
+ For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
916
570
 
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_ | ✔️ |
1120
-
1121
- ---
1122
-
1123
- ### `RemoveTagParameters`
1124
-
1125
- | Property | Type | Default | Required |
1126
- | -------- | -------- | ------- | -------- |
1127
- | email | `string` | _none_ | ✔️ |
1128
- | tagName | `string` | _none_ | ✔️ |
1129
-
1130
- ---
1131
-
1132
- ### `SubscribeParameters`
1133
-
1134
- | Property | Type | Default | Required |
1135
- | -------- | -------- | ------- | -------- |
1136
- | email | `string` | _none_ | ✔️ |
1137
-
1138
- ---
1139
-
1140
- ### `Subscriber<S>`
1141
-
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.
571
+ ## Types Reference
1143
572
 
1144
- | Property | Type | Default | Required |
1145
- | ---------- | --------------------------------------------------- | ------- | -------- |
1146
- | attributes | [`SubscriberAttributes<S>`](#subscriberattributess) | _none_ | ✔️ |
1147
- | id | `string` | _none_ | ✔️ |
1148
- | type | [`EntityType.VISITOR`](#EntityType) | _none_ | ✔️ |
573
+ This section provides a detailed reference for the types used in the Bento Node.js SDK.
574
+ AddFieldParameters `<S>`
1149
575
 
1150
- ### `SubscriberAttributes<S>`
576
+ Parameters for adding a field to a subscriber.
1151
577
 
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.
578
+ | Property | Type | Required | Description |
579
+ |----------|------------------------------|----------|----------------------------|
580
+ | email | string | ✔️ | Subscriber's email address |
581
+ | field | { key: keyof S; value: any } | ✔️ | Field to add |
1153
582
 
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_ | ✔️ |
583
+ ### AddSubscriberParameters `<S>`
1161
584
 
1162
- ### `Tag`
585
+ Parameters for adding a new subscriber.
1163
586
 
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_ | ✔️ |
587
+ | Property | Type | Required | Description |
588
+ |----------|---------------|----------|--------------------------------------|
589
+ | date | Date | | Date of subscription |
590
+ | email | string | ✔️ | Subscriber's email address |
591
+ | fields | Partial `<S>` | | Additional fields for the subscriber |
1170
592
 
1171
- ---
593
+ ### AddTagParameters
1172
594
 
1173
- ### `TagAttributes`
595
+ Parameters for adding a tag to a subscriber.
1174
596
 
1175
- | Property | Type | Default | Required |
1176
- | ---------- | --------------------------------- | ------- | -------- |
1177
- | attributes | [`TagAttributes`](#TagAttributes) | _none_ | ✔️ |
1178
- | id | `string` | _none_ | ✔️ |
1179
- | type | [`EntityType.TAG`](#EntityType) | _none_ | ✔️ |
597
+ | Property | Type | Required | Description |
598
+ |----------|--------|----------|----------------------------|
599
+ | email | string | ✔️ | Subscriber's email address |
600
+ | tagName | string | ✔️ | Name of the tag to add |
1180
601
 
1181
- ---
602
+ ### BatchImportEventsParameter `<S>`, `<E>`
1182
603
 
1183
- ### `TagSubscriberParameters`
604
+ Parameters for batch importing events.
1184
605
 
1185
- | Property | Type | Default | Required |
1186
- | -------- | -------- | ------- | -------- |
1187
- | date | `Date` | _none_ | |
1188
- | email | `string` | _none_ | ✔️ |
1189
- | tagName | `string` | _none_ | ✔️ |
606
+ | Property | Type | Required | Description |
607
+ |----------|-------------------------|----------|---------------------------|
608
+ | events | BentoEvent `<S>`, `<E>` | ✔️ | Array of events to import |
1190
609
 
1191
- ---
610
+ ### BatchImportSubscribersParameter `<S>`
1192
611
 
1193
- ### `TrackParameters<S, E>`
612
+ Parameters for batch importing subscribers.
1194
613
 
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.
614
+ | Property | Type | Required | Description |
615
+ |-------------|---------------------------------------|----------|--------------------------------|
616
+ | subscribers | ({ email: string } & Partial `<S>`)[] | ✔️ | Array of subscribers to import |
1196
617
 
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.
618
+ ### BentoEvent `<S>`, `<E>`
619
+ Represents different types of events in Bento. It's a union of the following event types:
1198
620
 
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_ | ❌ |
621
+ - BaseEvent `<E>`
622
+ - PurchaseEvent
623
+ - SubscribeEvent `<S>`
624
+ - TagEvent
625
+ - UnsubscribeEvent
626
+ - UpdateFieldsEvent `<S>`
1205
627
 
1206
- ---
628
+ ### PurchaseDetails
1207
629
 
1208
- ### `TrackPurchaseParameters`
630
+ Details of a purchase event.
1209
631
 
1210
- | Property | Type | Default | Required |
1211
- | --------------- | ------------------------------------- | ------- | -------- |
1212
- | date | `Date` | _none_ | |
1213
- | email | `string` | _none_ | ✔️ |
1214
- | purchaseDetails | [`PurchaseDetails`](#PurchaseDetails) | _none_ | ✔️ |
632
+ | Property | Type | Required | Description |
633
+ |----------|--------------------------------------|----------|------------------------------------|
634
+ | unique | { key: string \| number } | ✔️ | Unique identifier for the purchase |
635
+ | value | { currency: string; amount: number } | ✔️ | Value of the purchase |
636
+ | cart | PurchaseCart | | Additional cart details |
1215
637
 
1216
- ---
638
+ ### ChangeEmailParameters
1217
639
 
1218
- ### `UnsubscribeParameters`
640
+ Parameters for changing a subscriber's email.
1219
641
 
1220
- | Property | Type | Default | Required |
1221
- | -------- | -------- | ------- | -------- |
1222
- | email | `string` | _none_ | ✔️ |
642
+ | Property | Type | Required | Description |
643
+ |----------|--------|----------|-----------------------|
644
+ | oldEmail | string | ✔️ | Current email address |
645
+ | newEmail | string | ✔️ | New email address |
1223
646
 
1224
- ---
647
+ ### CreateFieldParameters
1225
648
 
1226
- ### `UpdateFieldsParameters<S>`
649
+ Parameters for creating a new field.
1227
650
 
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.
651
+ | Property | Type | Required | Description |
652
+ |----------|--------|----------|----------------------|
653
+ | key | string | ✔️ | Key of the new field |
1229
654
 
1230
- | Property | Type | Default | Required |
1231
- | -------- | ------------ | ------- | -------- |
1232
- | date | `Date` | _none_ | ❌ |
1233
- | email | `string` | _none_ | ✔️ |
1234
- | fields | `Partial<S>` | _none_ | ✔️ |
655
+ ### CreateTagParameters
1235
656
 
1236
- ---
657
+ Parameters for creating a new tag.
1237
658
 
1238
- ### `ValidateEmailParameters`
659
+ | Property | Type | Required | Description |
660
+ |----------|--------|----------|---------------------|
661
+ | name | string | ✔️ | Name of the new tag |
1239
662
 
1240
- | Property | Type | Default | Required |
1241
- | --------- | -------- | ------- | -------- |
1242
- | email | `string` | _none_ | ✔️ |
1243
- | ip | `string` | _none_ | ❌ |
1244
- | name | `string` | _none_ | ❌ |
1245
- | userAgent | `string` | _none_ | ❌ |
663
+ ### Subscriber `<S>`
1246
664
 
1247
- ## TypeScript
665
+ Represents a subscriber in Bento.
1248
666
 
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.
667
+ | Property | Type | Required | Description |
668
+ |------------|----------------------------|----------|------------------------------|
669
+ | attributes | SubscriberAttributes `<S>` | ✔️ | Attributes of the subscriber |
670
+ | id | string | ✔️ | Unique identifier |
671
+ | type | EntityType.VISITOR | ✔️ | Type of the entity |
1250
672
 
1251
- ### Generics
673
+ ### TrackParameters `<S>`, `<E>`
1252
674
 
1253
- #### `S`
675
+ Parameters for tracking an event.
1254
676
 
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.
677
+ | Property | Type | Required | Description |
678
+ |----------|------------------------|----------|-------------------------------------|
679
+ | email | string | ✔️ | Subscriber's email address |
680
+ | 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 |
1256
683
 
1257
- To set this type, pass it as the first generic parameter when initializing your `Analytics` object.
684
+ ### ValidateEmailParameters
1258
685
 
1259
- ```ts
1260
- type MySubscriberFields = {
1261
- firstName: string;
1262
- lastName: string;
1263
- age: number;
1264
- };
686
+ Parameters for validating an email address.
1265
687
 
1266
- const bento = new Analytics<MySubscriberFields>({
1267
- // ... initialization options from above.
1268
- });
1269
- ```
688
+ | Property | Type | Required | Description |
689
+ |-----------|--------|----------|--------------------------------|
690
+ | 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 |
1270
694
 
1271
- #### `E`
695
+ 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.
1272
696
 
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.
1274
-
1275
- To set this type, pass it as the second generic parameter when initializing your `Analytics` object.
1276
-
1277
- ```ts
1278
- const bento = new Analytics<any, '$myPrefix.'>({
1279
- // ... initialization options from above.
1280
- });
1281
- ```
1282
697
 
1283
698
  ## Things to know
1284
699
 
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!
700
+ - All events must be identified with an email address.
701
+ - Most events are indexed within seconds in your Bento account.
702
+ - The SDK supports TypeScript with generics for custom fields and events.
703
+ - Batch operations are available for importing subscribers and events efficiently.
704
+ - The SDK doesn't currently support anonymous events (coming soon).
1288
705
 
1289
706
  ## Contributing
1290
707
 
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.
708
+ 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
709
 
1293
710
  ## License
1294
711
 
1295
- The package is available as open source under the terms of the MIT License.
712
+ The Bento SDK for Node.js is available as open source under the terms of the [MIT License](LICENSE.md).