@bentonow/bento-node-sdk 0.1.9 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -111
- package/dist/bento-node-sdk.cjs.development.js +185 -26
- package/dist/bento-node-sdk.cjs.development.js.map +1 -1
- package/dist/bento-node-sdk.cjs.production.min.js +1 -1
- package/dist/bento-node-sdk.cjs.production.min.js.map +1 -1
- package/dist/bento-node-sdk.esm.js +186 -26
- package/dist/bento-node-sdk.esm.js.map +1 -1
- package/dist/sdk/batch/enums.d.ts +1 -0
- package/dist/sdk/client/errors.d.ts +0 -2
- package/dist/sdk/commands/enums.d.ts +1 -0
- package/dist/sdk/commands/index.d.ts +8 -1
- package/dist/versions/v1/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/sdk/batch/enums.ts +1 -0
- package/src/sdk/batch/events.d.ts +16 -1
- package/src/sdk/client/errors.ts +0 -1
- package/src/sdk/client/index.ts +22 -7
- package/src/sdk/commands/enums.ts +1 -0
- package/src/sdk/commands/index.ts +33 -4
- package/src/sdk/commands/types.d.ts +5 -0
- package/src/versions/v1/index.ts +2 -2
- package/src/versions/v1/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bento SDK for Node.JS
|
|
2
2
|
|
|
3
|
-
[](https://github.com/bentonow/bento-node-sdk/actions/workflows/main.yml)
|
|
4
4
|
|
|
5
5
|
🍱 Simple, powerful analytics for Node.JS projects!
|
|
6
6
|
|
|
@@ -10,6 +10,8 @@ Track events, update data, record LTV and more in Node.JS. Data is stored in you
|
|
|
10
10
|
|
|
11
11
|
🐶 Battle-tested by [NativShark](https://nativshark.com) Bento Production (a Bento customer)!
|
|
12
12
|
|
|
13
|
+
❤️ Thank you @HelloKashif from [IPInfo](https://ipinfo.io) for your contribution.
|
|
14
|
+
|
|
13
15
|
- [Installation](#Installation)
|
|
14
16
|
- [Get Started](#Get-Started)
|
|
15
17
|
- [Modules](#Modules)
|
|
@@ -25,6 +27,7 @@ Track events, update data, record LTV and more in Node.JS. Data is stored in you
|
|
|
25
27
|
- [Commands](#Commands)
|
|
26
28
|
- [.addTag(parameters: AddTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsaddtagparameters-addtagparameters-promisesubscribers--null)
|
|
27
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)
|
|
28
31
|
- [.removeField(parameters: RemoveFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsremovefieldparameters-removefieldparameterss-promisesubscribers--null)
|
|
29
32
|
- [.subscribe(parameters: SubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null)
|
|
30
33
|
- [.unsubscribe(parameters: UnsubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null)
|
|
@@ -45,53 +48,6 @@ Track events, update data, record LTV and more in Node.JS. Data is stored in you
|
|
|
45
48
|
- [.getTags(): Promise\<Tag[] | null\>](#tagsgettags-promisetag--null)
|
|
46
49
|
- [.createTag(parameters: CreateTagParameters): Promise\<Tag[] | null\>](#tagscreatetagparameters-createtagparameters-promisetag--null)
|
|
47
50
|
- [Types Reference](#Types-Reference)
|
|
48
|
-
- [AddFieldParameters\<S\>](#addfieldparameterss)
|
|
49
|
-
- [AddSubscriberParameters\<S\>](#addsubscriberparameterss)
|
|
50
|
-
- [AddTagParameters](#AddTagParameters)
|
|
51
|
-
- [BatchImportEventsParameter\<S, E\>](#batchimporteventsparameterse)
|
|
52
|
-
- [BatchImportSubscribersParameter\<S\>](#batchimportsubscribersparameters)
|
|
53
|
-
- [BentoEvent\<S, E\>](#bentoevents-e)
|
|
54
|
-
- [BaseEvent\<E\>](#baseevente)
|
|
55
|
-
- [PurchaseEvent](#PurchaseEvent)
|
|
56
|
-
- [SubscribeEvent](#SubscribeEvent)
|
|
57
|
-
- [TagEvent](#TagEvent)
|
|
58
|
-
- [UnsubscribeEvent](#UnsubscribeEvent)
|
|
59
|
-
- [UpdateFieldsEvent\<S\>](#updatefieldsevents)
|
|
60
|
-
- [BlacklistParameters](#BlacklistParameters)
|
|
61
|
-
- [BlacklistResponse](#BlacklistResponse)
|
|
62
|
-
- [BrowserData](#BrowserData)
|
|
63
|
-
- [CreateFieldParameters](#CreateFieldParameters)
|
|
64
|
-
- [CreateSubscriberParameters](#CreateSubscriberParameters)
|
|
65
|
-
- [CreateTagParameters](#CreateTagParameters)
|
|
66
|
-
- [EntityType](#EntityType)
|
|
67
|
-
- [Field](#Field)
|
|
68
|
-
- [FieldAttributes](#FieldAttributes)
|
|
69
|
-
- [FormResponse](#FormResponse)
|
|
70
|
-
- [FormResponseAttributes](#FormResponseAttributes)
|
|
71
|
-
- [FormResponseData](#FormResponseData)
|
|
72
|
-
- [GetSubscribersParameters](#GetSubscribersParameters)
|
|
73
|
-
- [GeolocateParameters](#GeolocateParameters)
|
|
74
|
-
- [GuessGenderParameters](#GuessGenderParameters)
|
|
75
|
-
- [GuessGenderResponse](#GuessGenderResponse)
|
|
76
|
-
- [IdentityData](#IdentityData)
|
|
77
|
-
- [LocationData](#LocationData)
|
|
78
|
-
- [PageData](#PageData)
|
|
79
|
-
- [PurchaseDetails](#PurchaseDetails)
|
|
80
|
-
- [PurchaseItem](#PurchaseItem)
|
|
81
|
-
- [RemoveFieldParameters\<S\>](#removefieldparameterss)
|
|
82
|
-
- [RemoveSubscriberParameters](#RemoveSubscriberParameters)
|
|
83
|
-
- [RemoveTagParameters](#RemoveTagParameters)
|
|
84
|
-
- [SubscribeParameters](#SubscribeParameters)
|
|
85
|
-
- [Subscriber\<S\>](#subscribers)
|
|
86
|
-
- [SubscriberAttributes\<S\>](#subscriberattributess)
|
|
87
|
-
- [Tag](#Tag)
|
|
88
|
-
- [TagAttributes](#TagAttributes)
|
|
89
|
-
- [TagSubscriberParameters](#TagSubscriberParameters)
|
|
90
|
-
- [TrackParameters\<S, E\>](#trackparametersse)
|
|
91
|
-
- [TrackPurchaseParameters](#TrackPurchaseParameters)
|
|
92
|
-
- [UnsubscribeParameters](#UnsubscribeParameters)
|
|
93
|
-
- [UpdateFieldsParameters\<S\>](#updatefieldsparameterss)
|
|
94
|
-
- [ValidateEmailParameters](#ValidateEmailParameters)
|
|
95
51
|
- [TypeScript](#TypeScript)
|
|
96
52
|
- [Generics](#Generics)
|
|
97
53
|
- [S](#s)
|
|
@@ -123,23 +79,32 @@ const bento = new Analytics({
|
|
|
123
79
|
siteUuid: 'siteUuid',
|
|
124
80
|
});
|
|
125
81
|
|
|
126
|
-
bento
|
|
127
|
-
.
|
|
128
|
-
|
|
129
|
-
})
|
|
82
|
+
bento.V1.addSubscriber({
|
|
83
|
+
email: 'test@bentonow.com',
|
|
84
|
+
})
|
|
130
85
|
.then(result => console.log(result))
|
|
131
86
|
.catch(error => console.error(error));
|
|
132
87
|
|
|
133
|
-
bento
|
|
134
|
-
.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
88
|
+
bento.V1.updateFields({
|
|
89
|
+
email: 'test@bentonow.com',
|
|
90
|
+
fields: {
|
|
91
|
+
firstName: 'Test',
|
|
92
|
+
lastName: 'User',
|
|
93
|
+
},
|
|
94
|
+
})
|
|
141
95
|
.then(result => console.log(result))
|
|
142
96
|
.catch(error => console.error(error));
|
|
97
|
+
|
|
98
|
+
bento.V1.trackPurchase({
|
|
99
|
+
email: 'test@bentonow.com',
|
|
100
|
+
purchaseDetails: {
|
|
101
|
+
unique: { key: 1234 },
|
|
102
|
+
value: { amount: 100, currency: 'USD' },
|
|
103
|
+
},
|
|
104
|
+
cart: {
|
|
105
|
+
abandoned_checkout_url: '',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
143
108
|
```
|
|
144
109
|
|
|
145
110
|
Read on to see what all you can do with the SDK.
|
|
@@ -165,11 +130,10 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
165
130
|
Reference Types: [TagSubscriberParameters](#TagSubscriberParameters)
|
|
166
131
|
|
|
167
132
|
```ts
|
|
168
|
-
bento
|
|
169
|
-
.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
})
|
|
133
|
+
bento.V1.tagSubscriber({
|
|
134
|
+
email: 'test@bentonow.com',
|
|
135
|
+
tagName: 'Test Tag',
|
|
136
|
+
})
|
|
173
137
|
.then(result => console.log(result))
|
|
174
138
|
.catch(error => console.error(error));
|
|
175
139
|
```
|
|
@@ -191,22 +155,20 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
191
155
|
Reference Types: [AddSubscriberParameters\<S\>](#addsubscriberparameterss)
|
|
192
156
|
|
|
193
157
|
```ts
|
|
194
|
-
bento
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
})
|
|
158
|
+
bento.V1.addSubscriber({
|
|
159
|
+
email: 'test@bentonow.com',
|
|
160
|
+
})
|
|
198
161
|
.then(result => console.log(result))
|
|
199
162
|
.catch(error => console.error(error));
|
|
200
163
|
|
|
201
|
-
bento
|
|
202
|
-
.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
})
|
|
164
|
+
bento.V1.addSubscriber({
|
|
165
|
+
date: new Date('2021-08-20T01:32:57.530Z'),
|
|
166
|
+
email: 'test@bentonow.com',
|
|
167
|
+
fields: {
|
|
168
|
+
firstName: 'Test',
|
|
169
|
+
lastName: 'Subscriber',
|
|
170
|
+
},
|
|
171
|
+
})
|
|
210
172
|
.then(result => console.log(result))
|
|
211
173
|
.catch(error => console.error(error));
|
|
212
174
|
```
|
|
@@ -226,10 +188,9 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
226
188
|
Reference Types: [RemoveSubscriberParameters](#RemoveSubscriberParameters)
|
|
227
189
|
|
|
228
190
|
```ts
|
|
229
|
-
bento
|
|
230
|
-
.
|
|
231
|
-
|
|
232
|
-
})
|
|
191
|
+
bento.V1.removeSubscriber({
|
|
192
|
+
email: 'test@bentonow.com',
|
|
193
|
+
})
|
|
233
194
|
.then(result => console.log(result))
|
|
234
195
|
.catch(error => console.error(error));
|
|
235
196
|
```
|
|
@@ -249,13 +210,12 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
249
210
|
Reference Types: [UpdateFieldsParameters\<S\>](#updatefieldsparameterss)
|
|
250
211
|
|
|
251
212
|
```ts
|
|
252
|
-
bento
|
|
253
|
-
.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
})
|
|
213
|
+
bento.V1.updateFields({
|
|
214
|
+
email: 'test@bentonow.com',
|
|
215
|
+
fields: {
|
|
216
|
+
firstName: 'Test',
|
|
217
|
+
},
|
|
218
|
+
})
|
|
259
219
|
.then(result => console.log(result))
|
|
260
220
|
.catch(error => console.error(error));
|
|
261
221
|
```
|
|
@@ -275,19 +235,18 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
275
235
|
Reference Types: [TrackPurchaseParameters](#TrackPurchaseParameters)
|
|
276
236
|
|
|
277
237
|
```ts
|
|
278
|
-
bento
|
|
279
|
-
.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
key: 1234,
|
|
284
|
-
},
|
|
285
|
-
value: {
|
|
286
|
-
amount: 100,
|
|
287
|
-
currency: 'USD',
|
|
288
|
-
},
|
|
238
|
+
bento.V1.trackPurchase({
|
|
239
|
+
email: 'test@bentonow.com',
|
|
240
|
+
purchaseDetails: {
|
|
241
|
+
unique: {
|
|
242
|
+
key: 1234,
|
|
289
243
|
},
|
|
290
|
-
|
|
244
|
+
value: {
|
|
245
|
+
amount: 100,
|
|
246
|
+
currency: 'USD',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
})
|
|
291
250
|
.then(result => console.log(result))
|
|
292
251
|
.catch(error => console.error(error));
|
|
293
252
|
```
|
|
@@ -307,14 +266,13 @@ Returns `true` if the event was successfully dispatched. Returns `false` otherwi
|
|
|
307
266
|
Reference Types: [TrackParameters<S, E>](#trackparametersse)
|
|
308
267
|
|
|
309
268
|
```ts
|
|
310
|
-
bento
|
|
311
|
-
.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
})
|
|
269
|
+
bento.V1.track({
|
|
270
|
+
email: 'test@bentonow.com',
|
|
271
|
+
type: '$custom.event',
|
|
272
|
+
details: {
|
|
273
|
+
fromCustomEvent: true,
|
|
274
|
+
},
|
|
275
|
+
})
|
|
318
276
|
.then(result => console.log(result))
|
|
319
277
|
.catch(error => console.error(error));
|
|
320
278
|
```
|
|
@@ -374,6 +332,20 @@ bento.V1.Batch.importEvents({
|
|
|
374
332
|
email: 'test@bentonow.com',
|
|
375
333
|
type: BentoEvents.UNSUBSCRIBE,
|
|
376
334
|
},
|
|
335
|
+
{
|
|
336
|
+
email: 'test@bentonow.com',
|
|
337
|
+
type: BentoEvents.REMOVE_TAG,
|
|
338
|
+
details: {
|
|
339
|
+
tag: 'tag_to_remove',
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
email: 'test@bentonow.com',
|
|
344
|
+
type: BentoEvents.TAG,
|
|
345
|
+
details: {
|
|
346
|
+
tag: 'tag_to_add',
|
|
347
|
+
},
|
|
348
|
+
},
|
|
377
349
|
{
|
|
378
350
|
email: 'test@bentonow.com',
|
|
379
351
|
details: {
|
|
@@ -504,6 +476,23 @@ bento.V1.Commands.unsubscribe({
|
|
|
504
476
|
.catch(error => console.error(error));
|
|
505
477
|
```
|
|
506
478
|
|
|
479
|
+
---
|
|
480
|
+
|
|
481
|
+
### `Commands.changeEmail(parameters: ChangeEmailParameters): Promise<Subscriber<S> | null>`
|
|
482
|
+
|
|
483
|
+
Updates the email of a user in Bento.
|
|
484
|
+
|
|
485
|
+
Reference Types: [ChangeEmailParameters](#changeemailparameters), [Subscriber\<S\>](#subscribers)
|
|
486
|
+
|
|
487
|
+
```ts
|
|
488
|
+
bento.V1.Commands.changeEmail({
|
|
489
|
+
oldEmail: 'test@bentonow.com',
|
|
490
|
+
newEmail: 'new@bentonow.com',
|
|
491
|
+
})
|
|
492
|
+
.then(result => console.log(result))
|
|
493
|
+
.catch(error => console.error(error));
|
|
494
|
+
```
|
|
495
|
+
|
|
507
496
|
## Experimental
|
|
508
497
|
|
|
509
498
|
### `Experimental.validateEmail(parameters: ValidateEmailParameters): Promise<boolean>`
|
|
@@ -701,7 +690,7 @@ bento.V1.Tags.createTag({
|
|
|
701
690
|
.catch(error => console.error(error));
|
|
702
691
|
```
|
|
703
692
|
|
|
704
|
-
## Types
|
|
693
|
+
## Types Reference
|
|
705
694
|
|
|
706
695
|
### `AddFieldParameters<S>`
|
|
707
696
|
|
|
@@ -856,6 +845,15 @@ The results is an object where the key is the name of the blacklist that was che
|
|
|
856
845
|
|
|
857
846
|
---
|
|
858
847
|
|
|
848
|
+
### `ChangeEmailParameters`
|
|
849
|
+
|
|
850
|
+
| Property | Type | Default | Required |
|
|
851
|
+
| -------- | -------- | ------- | -------- |
|
|
852
|
+
| oldEmail | `string` | _none_ | ✔️ |
|
|
853
|
+
| newEmail | `string` | _none_ | ✔️ |
|
|
854
|
+
|
|
855
|
+
---
|
|
856
|
+
|
|
859
857
|
### `CreateFieldParameters`
|
|
860
858
|
|
|
861
859
|
| Property | Type | Default | Required |
|
|
@@ -1029,13 +1027,22 @@ Note that this takes either `email` _or_ `uuid`, but never both.
|
|
|
1029
1027
|
|
|
1030
1028
|
---
|
|
1031
1029
|
|
|
1030
|
+
### `PurchaseCart`
|
|
1031
|
+
|
|
1032
|
+
| Property | Type | Default | Required |
|
|
1033
|
+
| ---------------------- | --------------------------------- | ------- | -------- |
|
|
1034
|
+
| abandoned_checkout_url | `string` | _none_ | ❌ |
|
|
1035
|
+
| items | [`PurchaseItem[]`](#PurchaseItem) | _none_ | ❌ |
|
|
1036
|
+
|
|
1037
|
+
---
|
|
1038
|
+
|
|
1032
1039
|
### `PurchaseDetails`
|
|
1033
1040
|
|
|
1034
1041
|
| Property | Type | Default | Required |
|
|
1035
1042
|
| -------- | --------------------------------------- | ------- | -------- |
|
|
1036
1043
|
| unique | `{ key: string \| number; }` | _none_ | ✔️ |
|
|
1037
1044
|
| value | `{ currency: string; amount: number; }` | _none_ | ✔️ |
|
|
1038
|
-
| cart | [`
|
|
1045
|
+
| cart | [`PurchaseCart`](#PurchaseCart) | _none_ | ❌ |
|
|
1039
1046
|
|
|
1040
1047
|
---
|
|
1041
1048
|
|
|
@@ -1154,6 +1161,7 @@ The `E` from above represents the prefix that is used to define your custom even
|
|
|
1154
1161
|
| email | `string` | _none_ | ✔️ |
|
|
1155
1162
|
| type | `string` | _none_ | ✔️ |
|
|
1156
1163
|
| details | `{ [key: string]: any }` | _none_ | ❌ |
|
|
1164
|
+
| fields | `Partial<S>` | _none_ | ❌ |
|
|
1157
1165
|
|
|
1158
1166
|
---
|
|
1159
1167
|
|
|
@@ -1113,15 +1113,6 @@ var NotAuthorizedError = /*#__PURE__*/function (_Error) {
|
|
|
1113
1113
|
|
|
1114
1114
|
return NotAuthorizedError;
|
|
1115
1115
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1116
|
-
var InternalServerError = /*#__PURE__*/function (_Error2) {
|
|
1117
|
-
_inheritsLoose(InternalServerError, _Error2);
|
|
1118
|
-
|
|
1119
|
-
function InternalServerError() {
|
|
1120
|
-
return _Error2.apply(this, arguments) || this;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
return InternalServerError;
|
|
1124
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1125
1116
|
|
|
1126
1117
|
var BentoClient = /*#__PURE__*/function () {
|
|
1127
1118
|
function BentoClient(options) {
|
|
@@ -1159,13 +1150,38 @@ var BentoClient = /*#__PURE__*/function () {
|
|
|
1159
1150
|
fetch("" + _this._baseUrl + endpoint + "?" + queryParameters, {
|
|
1160
1151
|
method: 'GET',
|
|
1161
1152
|
headers: _this._headers
|
|
1162
|
-
}).then(function (
|
|
1163
|
-
|
|
1164
|
-
return
|
|
1165
|
-
|
|
1153
|
+
}).then( /*#__PURE__*/function () {
|
|
1154
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(result) {
|
|
1155
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1156
|
+
while (1) {
|
|
1157
|
+
switch (_context.prev = _context.next) {
|
|
1158
|
+
case 0:
|
|
1159
|
+
if (!_this._isSuccessfulStatus(result.status)) {
|
|
1160
|
+
_context.next = 2;
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
return _context.abrupt("return", result.json());
|
|
1165
|
+
|
|
1166
|
+
case 2:
|
|
1167
|
+
_context.next = 4;
|
|
1168
|
+
return _this._getErrorForResponse(result);
|
|
1169
|
+
|
|
1170
|
+
case 4:
|
|
1171
|
+
throw _context.sent;
|
|
1172
|
+
|
|
1173
|
+
case 5:
|
|
1174
|
+
case "end":
|
|
1175
|
+
return _context.stop();
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}, _callee);
|
|
1179
|
+
}));
|
|
1166
1180
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1181
|
+
return function (_x) {
|
|
1182
|
+
return _ref.apply(this, arguments);
|
|
1183
|
+
};
|
|
1184
|
+
}()).then(function (data) {
|
|
1169
1185
|
return resolve(data);
|
|
1170
1186
|
})["catch"](function (error) {
|
|
1171
1187
|
return reject(error);
|
|
@@ -1198,13 +1214,38 @@ var BentoClient = /*#__PURE__*/function () {
|
|
|
1198
1214
|
'Content-Type': 'application/json'
|
|
1199
1215
|
}),
|
|
1200
1216
|
body: body
|
|
1201
|
-
}).then(function (
|
|
1202
|
-
|
|
1203
|
-
return
|
|
1204
|
-
|
|
1217
|
+
}).then( /*#__PURE__*/function () {
|
|
1218
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(result) {
|
|
1219
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1220
|
+
while (1) {
|
|
1221
|
+
switch (_context2.prev = _context2.next) {
|
|
1222
|
+
case 0:
|
|
1223
|
+
if (!_this2._isSuccessfulStatus(result.status)) {
|
|
1224
|
+
_context2.next = 2;
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
return _context2.abrupt("return", result.json());
|
|
1229
|
+
|
|
1230
|
+
case 2:
|
|
1231
|
+
_context2.next = 4;
|
|
1232
|
+
return _this2._getErrorForResponse(result);
|
|
1233
|
+
|
|
1234
|
+
case 4:
|
|
1235
|
+
throw _context2.sent;
|
|
1236
|
+
|
|
1237
|
+
case 5:
|
|
1238
|
+
case "end":
|
|
1239
|
+
return _context2.stop();
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}, _callee2);
|
|
1243
|
+
}));
|
|
1205
1244
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1245
|
+
return function (_x2) {
|
|
1246
|
+
return _ref2.apply(this, arguments);
|
|
1247
|
+
};
|
|
1248
|
+
}()).then(function (data) {
|
|
1208
1249
|
return resolve(data);
|
|
1209
1250
|
})["catch"](function (error) {
|
|
1210
1251
|
return reject(error);
|
|
@@ -1285,10 +1326,68 @@ var BentoClient = /*#__PURE__*/function () {
|
|
|
1285
1326
|
*/
|
|
1286
1327
|
;
|
|
1287
1328
|
|
|
1288
|
-
_proto._getErrorForResponse =
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1329
|
+
_proto._getErrorForResponse =
|
|
1330
|
+
/*#__PURE__*/
|
|
1331
|
+
function () {
|
|
1332
|
+
var _getErrorForResponse2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(response) {
|
|
1333
|
+
var contentType, responseMessage;
|
|
1334
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1335
|
+
while (1) {
|
|
1336
|
+
switch (_context3.prev = _context3.next) {
|
|
1337
|
+
case 0:
|
|
1338
|
+
if (!(response.status === 401)) {
|
|
1339
|
+
_context3.next = 2;
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
return _context3.abrupt("return", new NotAuthorizedError());
|
|
1344
|
+
|
|
1345
|
+
case 2:
|
|
1346
|
+
contentType = response.headers.get('Content-Type');
|
|
1347
|
+
responseMessage = '';
|
|
1348
|
+
_context3.t0 = contentType == null ? void 0 : contentType.toLocaleLowerCase();
|
|
1349
|
+
_context3.next = _context3.t0 === 'text/plain' ? 7 : _context3.t0 === 'application/json' ? 11 : 17;
|
|
1350
|
+
break;
|
|
1351
|
+
|
|
1352
|
+
case 7:
|
|
1353
|
+
_context3.next = 9;
|
|
1354
|
+
return response.text();
|
|
1355
|
+
|
|
1356
|
+
case 9:
|
|
1357
|
+
responseMessage = _context3.sent;
|
|
1358
|
+
return _context3.abrupt("break", 19);
|
|
1359
|
+
|
|
1360
|
+
case 11:
|
|
1361
|
+
_context3.t1 = JSON;
|
|
1362
|
+
_context3.next = 14;
|
|
1363
|
+
return response.json();
|
|
1364
|
+
|
|
1365
|
+
case 14:
|
|
1366
|
+
_context3.t2 = _context3.sent;
|
|
1367
|
+
responseMessage = _context3.t1.stringify.call(_context3.t1, _context3.t2);
|
|
1368
|
+
return _context3.abrupt("break", 19);
|
|
1369
|
+
|
|
1370
|
+
case 17:
|
|
1371
|
+
responseMessage = 'Unknown response from the Bento API.';
|
|
1372
|
+
return _context3.abrupt("break", 19);
|
|
1373
|
+
|
|
1374
|
+
case 19:
|
|
1375
|
+
return _context3.abrupt("return", new Error("[" + response.status + "] - " + responseMessage));
|
|
1376
|
+
|
|
1377
|
+
case 20:
|
|
1378
|
+
case "end":
|
|
1379
|
+
return _context3.stop();
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}, _callee3);
|
|
1383
|
+
}));
|
|
1384
|
+
|
|
1385
|
+
function _getErrorForResponse(_x3) {
|
|
1386
|
+
return _getErrorForResponse2.apply(this, arguments);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
return _getErrorForResponse;
|
|
1390
|
+
}();
|
|
1292
1391
|
|
|
1293
1392
|
return BentoClient;
|
|
1294
1393
|
}();
|
|
@@ -1301,6 +1400,7 @@ var CommandTypes;
|
|
|
1301
1400
|
(function (CommandTypes) {
|
|
1302
1401
|
CommandTypes["ADD_FIELD"] = "add_field";
|
|
1303
1402
|
CommandTypes["ADD_TAG"] = "add_tag";
|
|
1403
|
+
CommandTypes["CHANGE_EMAIL"] = "change_email";
|
|
1304
1404
|
CommandTypes["REMOVE_FIELD"] = "remove_field";
|
|
1305
1405
|
CommandTypes["REMOVE_TAG"] = "remove_tag";
|
|
1306
1406
|
CommandTypes["SUBSCRIBE"] = "subscribe";
|
|
@@ -1688,6 +1788,65 @@ var BentoCommands = /*#__PURE__*/function () {
|
|
|
1688
1788
|
}
|
|
1689
1789
|
|
|
1690
1790
|
return unsubscribe;
|
|
1791
|
+
}()
|
|
1792
|
+
/**
|
|
1793
|
+
* Updates the email of a user in Bento.
|
|
1794
|
+
*
|
|
1795
|
+
* @param parameters \{ oldEmail: string, newEmail: string \}
|
|
1796
|
+
* @returns Promise\<Subscriber | null\>
|
|
1797
|
+
*/
|
|
1798
|
+
;
|
|
1799
|
+
|
|
1800
|
+
_proto.changeEmail =
|
|
1801
|
+
/*#__PURE__*/
|
|
1802
|
+
function () {
|
|
1803
|
+
var _changeEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(parameters) {
|
|
1804
|
+
var result;
|
|
1805
|
+
return runtime_1.wrap(function _callee7$(_context7) {
|
|
1806
|
+
while (1) {
|
|
1807
|
+
switch (_context7.prev = _context7.next) {
|
|
1808
|
+
case 0:
|
|
1809
|
+
_context7.prev = 0;
|
|
1810
|
+
_context7.next = 3;
|
|
1811
|
+
return this._client.post(this._url, {
|
|
1812
|
+
command: {
|
|
1813
|
+
command: CommandTypes.CHANGE_EMAIL,
|
|
1814
|
+
email: parameters.oldEmail,
|
|
1815
|
+
query: parameters.newEmail
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
|
|
1819
|
+
case 3:
|
|
1820
|
+
result = _context7.sent;
|
|
1821
|
+
|
|
1822
|
+
if (!(Object.keys(result).length === 0 || !result.data)) {
|
|
1823
|
+
_context7.next = 6;
|
|
1824
|
+
break;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
return _context7.abrupt("return", null);
|
|
1828
|
+
|
|
1829
|
+
case 6:
|
|
1830
|
+
return _context7.abrupt("return", result.data);
|
|
1831
|
+
|
|
1832
|
+
case 9:
|
|
1833
|
+
_context7.prev = 9;
|
|
1834
|
+
_context7.t0 = _context7["catch"](0);
|
|
1835
|
+
throw _context7.t0;
|
|
1836
|
+
|
|
1837
|
+
case 12:
|
|
1838
|
+
case "end":
|
|
1839
|
+
return _context7.stop();
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}, _callee7, this, [[0, 9]]);
|
|
1843
|
+
}));
|
|
1844
|
+
|
|
1845
|
+
function changeEmail(_x7) {
|
|
1846
|
+
return _changeEmail.apply(this, arguments);
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
return changeEmail;
|
|
1691
1850
|
}();
|
|
1692
1851
|
|
|
1693
1852
|
return BentoCommands;
|
|
@@ -2355,6 +2514,7 @@ var BentoEvents;
|
|
|
2355
2514
|
BentoEvents["PURCHASE"] = "$purchase";
|
|
2356
2515
|
BentoEvents["SUBSCRIBE"] = "$subscribe";
|
|
2357
2516
|
BentoEvents["TAG"] = "$tag";
|
|
2517
|
+
BentoEvents["REMOVE_TAG"] = "$remove_tag";
|
|
2358
2518
|
BentoEvents["UNSUBSCRIBE"] = "$unsubscribe";
|
|
2359
2519
|
BentoEvents["UPDATE_FIELDS"] = "$update_fields";
|
|
2360
2520
|
})(BentoEvents || (BentoEvents = {}));
|
|
@@ -2766,6 +2926,5 @@ var Analytics = function Analytics(options) {
|
|
|
2766
2926
|
};
|
|
2767
2927
|
|
|
2768
2928
|
exports.Analytics = Analytics;
|
|
2769
|
-
exports.InternalServerError = InternalServerError;
|
|
2770
2929
|
exports.NotAuthorizedError = NotAuthorizedError;
|
|
2771
2930
|
//# sourceMappingURL=bento-node-sdk.cjs.development.js.map
|