@bentonow/bento-node-sdk 0.1.13 → 0.2.0

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 (57) hide show
  1. package/README.md +39 -2
  2. package/dist/bento-node-sdk.cjs.development.js +321 -332
  3. package/dist/bento-node-sdk.cjs.development.js.map +1 -1
  4. package/dist/bento-node-sdk.cjs.production.min.js +1 -1
  5. package/dist/bento-node-sdk.cjs.production.min.js.map +1 -1
  6. package/dist/bento-node-sdk.esm.js +321 -332
  7. package/dist/bento-node-sdk.esm.js.map +1 -1
  8. package/dist/index.d.ts +3 -3
  9. package/dist/sdk/batch/errors.d.ts +10 -0
  10. package/dist/sdk/batch/events.d.ts +71 -0
  11. package/dist/sdk/batch/index.d.ts +19 -3
  12. package/dist/sdk/batch/types.d.ts +37 -0
  13. package/dist/sdk/client/errors.d.ts +2 -0
  14. package/dist/sdk/client/index.d.ts +3 -3
  15. package/dist/sdk/client/types.d.ts +3 -0
  16. package/dist/sdk/commands/index.d.ts +3 -3
  17. package/dist/sdk/commands/types.d.ts +32 -0
  18. package/dist/sdk/experimental/index.d.ts +3 -3
  19. package/dist/sdk/experimental/types.d.ts +41 -0
  20. package/dist/sdk/fields/index.d.ts +2 -2
  21. package/dist/sdk/fields/types.d.ts +17 -0
  22. package/dist/sdk/forms/index.d.ts +2 -2
  23. package/dist/sdk/forms/types.d.ts +28 -0
  24. package/dist/sdk/interfaces.d.ts +13 -0
  25. package/dist/sdk/subscribers/index.d.ts +2 -2
  26. package/dist/sdk/subscribers/types.d.ts +25 -0
  27. package/dist/sdk/tags/index.d.ts +2 -2
  28. package/dist/sdk/tags/types.d.ts +17 -0
  29. package/dist/sdk/types.d.ts +41 -0
  30. package/dist/versions/v1/index.d.ts +4 -4
  31. package/dist/versions/v1/types.d.ts +31 -0
  32. package/package.json +5 -9
  33. package/src/index.ts +2 -2
  34. package/src/sdk/batch/errors.ts +41 -4
  35. package/src/sdk/batch/{events.d.ts → events.ts} +4 -5
  36. package/src/sdk/batch/index.ts +75 -46
  37. package/src/sdk/batch/types.ts +44 -0
  38. package/src/sdk/client/errors.ts +13 -2
  39. package/src/sdk/client/index.ts +21 -15
  40. package/src/sdk/client/{types.d.ts → types.ts} +0 -0
  41. package/src/sdk/commands/index.ts +93 -121
  42. package/src/sdk/commands/{types.d.ts → types.ts} +1 -1
  43. package/src/sdk/experimental/index.ts +29 -45
  44. package/src/sdk/experimental/{types.d.ts → types.ts} +1 -1
  45. package/src/sdk/fields/index.ts +11 -19
  46. package/src/sdk/fields/{types.d.ts → types.ts} +1 -1
  47. package/src/sdk/forms/index.ts +11 -15
  48. package/src/sdk/forms/{types.d.ts → types.ts} +3 -3
  49. package/src/sdk/{interfaces.d.ts → interfaces.ts} +0 -0
  50. package/src/sdk/subscribers/index.ts +17 -25
  51. package/src/sdk/subscribers/{types.d.ts → types.ts} +1 -1
  52. package/src/sdk/tags/index.ts +11 -19
  53. package/src/sdk/tags/{types.d.ts → types.ts} +1 -1
  54. package/src/sdk/{types.d.ts → types.ts} +2 -0
  55. package/src/versions/v1/index.ts +65 -86
  56. package/src/versions/v1/{types.d.ts → types.ts} +4 -2
  57. package/src/sdk/batch/types.d.ts +0 -25
@@ -1,4 +1,6 @@
1
- import {
1
+ import type { BentoClient } from '../client';
2
+ import type { LocationData } from '../types';
3
+ import type {
2
4
  BlacklistParameters,
3
5
  BlacklistResponse,
4
6
  GeolocateParameters,
@@ -8,8 +10,6 @@ import {
8
10
  ValidateEmailParameters,
9
11
  ValidateEmailResponse,
10
12
  } from './types';
11
- import { BentoClient } from '../client';
12
- import { LocationData } from '../types';
13
13
 
14
14
  export class BentoExperimental {
15
15
  private readonly _url = '/experimental';
@@ -32,21 +32,17 @@ export class BentoExperimental {
32
32
  public async validateEmail(
33
33
  parameters: ValidateEmailParameters
34
34
  ): Promise<boolean> {
35
- try {
36
- const result = await this._client.post<ValidateEmailResponse>(
37
- `${this._url}/validation`,
38
- {
39
- email: parameters.email,
40
- ip: parameters.ip,
41
- name: parameters.name,
42
- user_agent: parameters.userAgent,
43
- }
44
- );
35
+ const result = await this._client.post<ValidateEmailResponse>(
36
+ `${this._url}/validation`,
37
+ {
38
+ email: parameters.email,
39
+ ip: parameters.ip,
40
+ name: parameters.name,
41
+ user_agent: parameters.userAgent,
42
+ }
43
+ );
45
44
 
46
- return result.valid;
47
- } catch (error) {
48
- throw error;
49
- }
45
+ return result.valid;
50
46
  }
51
47
 
52
48
  /**
@@ -65,16 +61,12 @@ export class BentoExperimental {
65
61
  public async guessGender(
66
62
  parameters: GuessGenderParameters
67
63
  ): Promise<GuessGenderResponse> {
68
- try {
69
- const result = await this._client.post<GuessGenderResponse>(
70
- `${this._url}/gender`,
71
- parameters
72
- );
64
+ const result = await this._client.post<GuessGenderResponse>(
65
+ `${this._url}/gender`,
66
+ parameters
67
+ );
73
68
 
74
- return result;
75
- } catch (error) {
76
- throw error;
77
- }
69
+ return result;
78
70
  }
79
71
 
80
72
  /**
@@ -89,17 +81,13 @@ export class BentoExperimental {
89
81
  public async geolocate(
90
82
  parameters: GeolocateParameters
91
83
  ): Promise<LocationData | null> {
92
- try {
93
- const result = await this._client.get<GeolocateResponse>(
94
- `${this._url}/geolocation`,
95
- parameters
96
- );
84
+ const result = await this._client.get<GeolocateResponse>(
85
+ `${this._url}/geolocation`,
86
+ parameters
87
+ );
97
88
 
98
- if (Object.keys(result).length === 0) return null;
99
- return result as LocationData;
100
- } catch (error) {
101
- throw error;
102
- }
89
+ if (Object.keys(result).length === 0) return null;
90
+ return result as LocationData;
103
91
  }
104
92
 
105
93
  /**
@@ -115,15 +103,11 @@ export class BentoExperimental {
115
103
  public async checkBlacklist(
116
104
  parameters: BlacklistParameters
117
105
  ): Promise<BlacklistResponse> {
118
- try {
119
- const result = await this._client.get<BlacklistResponse>(
120
- `${this._url}/blacklist.json`,
121
- parameters
122
- );
106
+ const result = await this._client.get<BlacklistResponse>(
107
+ `${this._url}/blacklist.json`,
108
+ parameters
109
+ );
123
110
 
124
- return result;
125
- } catch (error) {
126
- throw error;
127
- }
111
+ return result;
128
112
  }
129
113
  }
@@ -1,4 +1,4 @@
1
- import { LocationData } from '../types';
1
+ import type { LocationData } from '../types';
2
2
 
3
3
  /**
4
4
  * Experimental Method Parameter Types
@@ -1,6 +1,6 @@
1
- import { BentoClient } from '../client';
2
- import { DataResponse } from '../client/types';
3
- import { CreateFieldParameters, Field } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { DataResponse } from '../client/types';
3
+ import type { CreateFieldParameters, Field } from './types';
4
4
 
5
5
  export class BentoFields {
6
6
  private readonly _url = '/fetch/fields';
@@ -13,14 +13,10 @@ export class BentoFields {
13
13
  * @returns Promise<Field[]>
14
14
  */
15
15
  public async getFields(): Promise<Field[] | null> {
16
- try {
17
- const result = await this._client.get<DataResponse<Field[]>>(this._url);
16
+ const result = await this._client.get<DataResponse<Field[]>>(this._url);
18
17
 
19
- if (Object.keys(result).length === 0 || !result.data) return null;
20
- return result.data;
21
- } catch (error) {
22
- throw error;
23
- }
18
+ if (Object.keys(result).length === 0 || !result.data) return null;
19
+ return result.data;
24
20
  }
25
21
 
26
22
  /**
@@ -41,15 +37,11 @@ export class BentoFields {
41
37
  public async createField(
42
38
  parameters: CreateFieldParameters
43
39
  ): Promise<Field[] | null> {
44
- try {
45
- const result = await this._client.post<DataResponse<Field[]>>(this._url, {
46
- field: parameters,
47
- });
40
+ const result = await this._client.post<DataResponse<Field[]>>(this._url, {
41
+ field: parameters,
42
+ });
48
43
 
49
- if (Object.keys(result).length === 0 || !result.data) return null;
50
- return result.data;
51
- } catch (error) {
52
- throw error;
53
- }
44
+ if (Object.keys(result).length === 0 || !result.data) return null;
45
+ return result.data;
54
46
  }
55
47
  }
@@ -1,4 +1,4 @@
1
- import { BaseEntity } from '../types';
1
+ import type { BaseEntity } from '../types';
2
2
 
3
3
  /**
4
4
  * Field Method Parameter Types
@@ -1,6 +1,6 @@
1
- import { BentoClient } from '../client';
2
- import { DataResponse } from '../client/types';
3
- import { FormResponse } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { DataResponse } from '../client/types';
3
+ import type { FormResponse } from './types';
4
4
 
5
5
  export class BentoForms {
6
6
  private readonly _url = '/fetch/responses';
@@ -16,18 +16,14 @@ export class BentoForms {
16
16
  public async getResponses(
17
17
  formIdentifier: string
18
18
  ): Promise<FormResponse[] | null> {
19
- try {
20
- const result = await this._client.get<DataResponse<FormResponse[]>>(
21
- this._url,
22
- {
23
- id: formIdentifier,
24
- }
25
- );
19
+ const result = await this._client.get<DataResponse<FormResponse[]>>(
20
+ this._url,
21
+ {
22
+ id: formIdentifier,
23
+ }
24
+ );
26
25
 
27
- if (Object.keys(result).length === 0 || !result.data) return null;
28
- return result.data;
29
- } catch (error) {
30
- throw error;
31
- }
26
+ if (Object.keys(result).length === 0 || !result.data) return null;
27
+ return result.data;
32
28
  }
33
29
  }
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  BaseEntity,
3
3
  BrowserData,
4
4
  IdentityData,
@@ -13,8 +13,8 @@ import {
13
13
  export type FormResponseData = {
14
14
  browser: BrowserData;
15
15
  date: string;
16
- details: { [key: string]: any };
17
- fields: { [key: string]: any };
16
+ details: { [key: string]: unknown };
17
+ fields: { [key: string]: unknown };
18
18
  id: string;
19
19
  identity: IdentityData;
20
20
  ip: string;
File without changes
@@ -1,6 +1,6 @@
1
- import { BentoClient } from '../client';
2
- import { DataResponse } from '../client/types';
3
- import {
1
+ import type { BentoClient } from '../client';
2
+ import type { DataResponse } from '../client/types';
3
+ import type {
4
4
  CreateSubscriberParameters,
5
5
  GetSubscribersParameters,
6
6
  Subscriber,
@@ -19,17 +19,13 @@ export class BentoSubscribers<S> {
19
19
  public async getSubscribers(
20
20
  parameters?: GetSubscribersParameters
21
21
  ): Promise<Subscriber<S> | null> {
22
- try {
23
- const result = await this._client.get<DataResponse<Subscriber<S>>>(
24
- this._url,
25
- parameters
26
- );
22
+ const result = await this._client.get<DataResponse<Subscriber<S>>>(
23
+ this._url,
24
+ parameters
25
+ );
27
26
 
28
- if (Object.keys(result).length === 0 || !result.data) return null;
29
- return result.data;
30
- } catch (error) {
31
- throw error;
32
- }
27
+ if (Object.keys(result).length === 0 || !result.data) return null;
28
+ return result.data;
33
29
  }
34
30
 
35
31
  /**
@@ -41,18 +37,14 @@ export class BentoSubscribers<S> {
41
37
  public async createSubscriber(
42
38
  parameters: CreateSubscriberParameters
43
39
  ): Promise<Subscriber<S> | null> {
44
- try {
45
- const result = await this._client.post<DataResponse<Subscriber<S>>>(
46
- this._url,
47
- {
48
- subscriber: parameters,
49
- }
50
- );
40
+ const result = await this._client.post<DataResponse<Subscriber<S>>>(
41
+ this._url,
42
+ {
43
+ subscriber: parameters,
44
+ }
45
+ );
51
46
 
52
- if (Object.keys(result).length === 0 || !result.data) return null;
53
- return result.data;
54
- } catch (error) {
55
- throw error;
56
- }
47
+ if (Object.keys(result).length === 0 || !result.data) return null;
48
+ return result.data;
57
49
  }
58
50
  }
@@ -1,4 +1,4 @@
1
- import { BaseEntity } from '../types';
1
+ import type { BaseEntity } from '../types';
2
2
 
3
3
  /**
4
4
  * Subscriber Method Parameter Types
@@ -1,6 +1,6 @@
1
- import { BentoClient } from '../client';
2
- import { DataResponse } from '../client/types';
3
- import { CreateTagParameters, Tag } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { DataResponse } from '../client/types';
3
+ import type { CreateTagParameters, Tag } from './types';
4
4
 
5
5
  export class BentoTags {
6
6
  private readonly _url = '/fetch/tags';
@@ -13,14 +13,10 @@ export class BentoTags {
13
13
  * @returns Promise\<Tag[] | null\>
14
14
  */
15
15
  public async getTags(): Promise<Tag[] | null> {
16
- try {
17
- const result = await this._client.get<DataResponse<Tag[]>>(this._url);
16
+ const result = await this._client.get<DataResponse<Tag[]>>(this._url);
18
17
 
19
- if (Object.keys(result).length === 0 || !result.data) return null;
20
- return result.data;
21
- } catch (error) {
22
- throw error;
23
- }
18
+ if (Object.keys(result).length === 0 || !result.data) return null;
19
+ return result.data;
24
20
  }
25
21
 
26
22
  /**
@@ -32,15 +28,11 @@ export class BentoTags {
32
28
  public async createTag(
33
29
  parameters: CreateTagParameters
34
30
  ): Promise<Tag[] | null> {
35
- try {
36
- const result = await this._client.post<DataResponse<Tag[]>>(this._url, {
37
- tag: parameters,
38
- });
31
+ const result = await this._client.post<DataResponse<Tag[]>>(this._url, {
32
+ tag: parameters,
33
+ });
39
34
 
40
- if (Object.keys(result).length === 0 || !result.data) return null;
41
- return result.data;
42
- } catch (error) {
43
- throw error;
44
- }
35
+ if (Object.keys(result).length === 0 || !result.data) return null;
36
+ return result.data;
45
37
  }
46
38
  }
@@ -1,4 +1,4 @@
1
- import { BaseEntity } from '../types';
1
+ import type { BaseEntity } from '../types';
2
2
 
3
3
  /**
4
4
  * Tag Method Parameter Types
@@ -2,6 +2,8 @@
2
2
  * Core Types
3
3
  */
4
4
 
5
+ import type { EntityType } from "./enums";
6
+
5
7
  export type BaseEntity<T> = {
6
8
  attributes: T;
7
9
  id: string;
@@ -9,8 +9,8 @@ import {
9
9
  BentoTags,
10
10
  } from '../../sdk';
11
11
  import { BentoEvents } from '../../sdk/batch/enums';
12
- import { AnalyticsOptions } from '../../sdk/interfaces';
13
- import {
12
+ import type { AnalyticsOptions } from '../../sdk/interfaces';
13
+ import type {
14
14
  AddSubscriberParameters,
15
15
  RemoveSubscriberParameters,
16
16
  TagSubscriberParameters,
@@ -19,7 +19,10 @@ import {
19
19
  UpdateFieldsParameters,
20
20
  } from './types';
21
21
 
22
- export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
22
+ export class BentoAPIV1<
23
+ S = { [key: string]: unknown },
24
+ E extends string = '$custom'
25
+ > {
23
26
  private readonly _client: BentoClient;
24
27
 
25
28
  public readonly Batch: BentoBatch<S, E>;
@@ -59,24 +62,20 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
59
62
  * @returns Promise\<boolean\>
60
63
  */
61
64
  async tagSubscriber(parameters: TagSubscriberParameters): Promise<boolean> {
62
- try {
63
- const result = await this.Batch.importEvents({
64
- events: [
65
- {
66
- date: parameters.date,
67
- details: {
68
- tag: parameters.tagName,
69
- },
70
- email: parameters.email,
71
- type: BentoEvents.TAG,
65
+ const result = await this.Batch.importEvents({
66
+ events: [
67
+ {
68
+ date: parameters.date,
69
+ details: {
70
+ tag: parameters.tagName,
72
71
  },
73
- ],
74
- });
72
+ email: parameters.email,
73
+ type: BentoEvents.TAG,
74
+ },
75
+ ],
76
+ });
75
77
 
76
- return result === 1;
77
- } catch (e) {
78
- throw e;
79
- }
78
+ return result === 1;
80
79
  }
81
80
 
82
81
  /**
@@ -102,22 +101,18 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
102
101
  async addSubscriber(
103
102
  parameters: AddSubscriberParameters<S>
104
103
  ): Promise<boolean> {
105
- try {
106
- const result = await this.Batch.importEvents({
107
- events: [
108
- {
109
- date: parameters.date,
110
- email: parameters.email,
111
- type: BentoEvents.SUBSCRIBE,
112
- fields: parameters.fields || {},
113
- },
114
- ],
115
- });
104
+ const result = await this.Batch.importEvents({
105
+ events: [
106
+ {
107
+ date: parameters.date,
108
+ email: parameters.email,
109
+ type: BentoEvents.SUBSCRIBE,
110
+ fields: parameters.fields || {},
111
+ },
112
+ ],
113
+ });
116
114
 
117
- return result === 1;
118
- } catch (e) {
119
- throw e;
120
- }
115
+ return result === 1;
121
116
  }
122
117
 
123
118
  /**
@@ -142,21 +137,17 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
142
137
  async removeSubscriber(
143
138
  parameters: RemoveSubscriberParameters
144
139
  ): Promise<boolean> {
145
- try {
146
- const result = await this.Batch.importEvents({
147
- events: [
148
- {
149
- date: parameters.date,
150
- email: parameters.email,
151
- type: BentoEvents.UNSUBSCRIBE,
152
- },
153
- ],
154
- });
140
+ const result = await this.Batch.importEvents({
141
+ events: [
142
+ {
143
+ date: parameters.date,
144
+ email: parameters.email,
145
+ type: BentoEvents.UNSUBSCRIBE,
146
+ },
147
+ ],
148
+ });
155
149
 
156
- return result === 1;
157
- } catch (e) {
158
- throw e;
159
- }
150
+ return result === 1;
160
151
  }
161
152
 
162
153
  /**
@@ -179,22 +170,18 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
179
170
  * @returns Promise\<boolean\>
180
171
  */
181
172
  async updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean> {
182
- try {
183
- const result = await this.Batch.importEvents({
184
- events: [
185
- {
186
- date: parameters.date,
187
- email: parameters.email,
188
- type: BentoEvents.UPDATE_FIELDS,
189
- fields: parameters.fields,
190
- },
191
- ],
192
- });
173
+ const result = await this.Batch.importEvents({
174
+ events: [
175
+ {
176
+ date: parameters.date,
177
+ email: parameters.email,
178
+ type: BentoEvents.UPDATE_FIELDS,
179
+ fields: parameters.fields,
180
+ },
181
+ ],
182
+ });
193
183
 
194
- return result === 1;
195
- } catch (e) {
196
- throw e;
197
- }
184
+ return result === 1;
198
185
  }
199
186
 
200
187
  /**
@@ -216,22 +203,18 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
216
203
  * @returns Promise\<boolean\>
217
204
  */
218
205
  async trackPurchase(parameters: TrackPurchaseParameters): Promise<boolean> {
219
- try {
220
- const result = await this.Batch.importEvents({
221
- events: [
222
- {
223
- date: parameters.date,
224
- email: parameters.email,
225
- type: BentoEvents.PURCHASE,
226
- details: parameters.purchaseDetails,
227
- },
228
- ],
229
- });
206
+ const result = await this.Batch.importEvents({
207
+ events: [
208
+ {
209
+ date: parameters.date,
210
+ email: parameters.email,
211
+ type: BentoEvents.PURCHASE,
212
+ details: parameters.purchaseDetails,
213
+ },
214
+ ],
215
+ });
230
216
 
231
- return result === 1;
232
- } catch (e) {
233
- throw e;
234
- }
217
+ return result === 1;
235
218
  }
236
219
 
237
220
  /**
@@ -252,14 +235,10 @@ export class BentoAPIV1<S = { [key: string]: any }, E = '$custom'> {
252
235
  * @returns Promise\<boolean\>
253
236
  */
254
237
  async track(parameters: TrackParameters<S, E>): Promise<boolean> {
255
- try {
256
- const result = await this.Batch.importEvents({
257
- events: [parameters],
258
- });
238
+ const result = await this.Batch.importEvents({
239
+ events: [parameters],
240
+ });
259
241
 
260
- return result === 1;
261
- } catch (e) {
262
- throw e;
263
- }
242
+ return result === 1;
264
243
  }
265
244
  }
@@ -1,4 +1,4 @@
1
- import { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
1
+ import type { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
2
2
 
3
3
  /**
4
4
  * API Method Parameter Types
@@ -32,4 +32,6 @@ export type UpdateFieldsParameters<S> = {
32
32
  fields: Partial<S>;
33
33
  };
34
34
 
35
- export type TrackParameters<S, E> = BaseEvent<S, E> & { fields: Partial<S> };
35
+ export type TrackParameters<S, E extends string> = BaseEvent<E> & {
36
+ fields: Partial<S>;
37
+ };
@@ -1,25 +0,0 @@
1
- import { BentoEvent } from './events';
2
-
3
- /**
4
- * Batch Method Parameter Types
5
- */
6
- export type BatchImportSubscribersParameter<S> = {
7
- subscribers: ({
8
- email: string;
9
- } & Partial<S>)[];
10
- };
11
-
12
- export type BatchImportEventsParameter<S, E> = {
13
- events: BentoEvent<S, E>[];
14
- };
15
-
16
- /**
17
- * Batch Method Response Types
18
- */
19
- export type BatchImportSubscribersResponse = {
20
- results: number;
21
- };
22
-
23
- export type BatchImportEventsResponse = {
24
- results: number;
25
- };