@bentonow/bento-node-sdk 0.1.13 → 0.1.14

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 (56) hide show
  1. package/README.md +4 -0
  2. package/dist/bento-node-sdk.cjs.development.js +222 -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 +222 -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 +4 -0
  10. package/dist/sdk/batch/events.d.ts +71 -0
  11. package/dist/sdk/batch/index.d.ts +3 -3
  12. package/dist/sdk/batch/types.d.ts +21 -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 -3
  33. package/src/index.ts +2 -2
  34. package/src/sdk/batch/errors.ts +27 -4
  35. package/src/sdk/batch/{events.d.ts → events.ts} +4 -5
  36. package/src/sdk/batch/index.ts +38 -50
  37. package/src/sdk/batch/{types.d.ts → types.ts} +2 -2
  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
@@ -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
+ };