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