@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.
- package/README.md +4 -0
- package/dist/bento-node-sdk.cjs.development.js +222 -332
- 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 +222 -332
- package/dist/bento-node-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/sdk/batch/errors.d.ts +4 -0
- package/dist/sdk/batch/events.d.ts +71 -0
- package/dist/sdk/batch/index.d.ts +3 -3
- package/dist/sdk/batch/types.d.ts +21 -0
- package/dist/sdk/client/errors.d.ts +2 -0
- package/dist/sdk/client/index.d.ts +3 -3
- package/dist/sdk/client/types.d.ts +3 -0
- package/dist/sdk/commands/index.d.ts +3 -3
- package/dist/sdk/commands/types.d.ts +32 -0
- package/dist/sdk/experimental/index.d.ts +3 -3
- package/dist/sdk/experimental/types.d.ts +41 -0
- package/dist/sdk/fields/index.d.ts +2 -2
- package/dist/sdk/fields/types.d.ts +17 -0
- package/dist/sdk/forms/index.d.ts +2 -2
- package/dist/sdk/forms/types.d.ts +28 -0
- package/dist/sdk/interfaces.d.ts +13 -0
- package/dist/sdk/subscribers/index.d.ts +2 -2
- package/dist/sdk/subscribers/types.d.ts +25 -0
- package/dist/sdk/tags/index.d.ts +2 -2
- package/dist/sdk/tags/types.d.ts +17 -0
- package/dist/sdk/types.d.ts +41 -0
- package/dist/versions/v1/index.d.ts +4 -4
- package/dist/versions/v1/types.d.ts +31 -0
- package/package.json +5 -3
- package/src/index.ts +2 -2
- package/src/sdk/batch/errors.ts +27 -4
- package/src/sdk/batch/{events.d.ts → events.ts} +4 -5
- package/src/sdk/batch/index.ts +38 -50
- package/src/sdk/batch/{types.d.ts → types.ts} +2 -2
- package/src/sdk/client/errors.ts +13 -2
- package/src/sdk/client/index.ts +21 -15
- package/src/sdk/client/{types.d.ts → types.ts} +0 -0
- package/src/sdk/commands/index.ts +93 -121
- package/src/sdk/commands/{types.d.ts → types.ts} +1 -1
- package/src/sdk/experimental/index.ts +29 -45
- package/src/sdk/experimental/{types.d.ts → types.ts} +1 -1
- package/src/sdk/fields/index.ts +11 -19
- package/src/sdk/fields/{types.d.ts → types.ts} +1 -1
- package/src/sdk/forms/index.ts +11 -15
- package/src/sdk/forms/{types.d.ts → types.ts} +3 -3
- package/src/sdk/{interfaces.d.ts → interfaces.ts} +0 -0
- package/src/sdk/subscribers/index.ts +17 -25
- package/src/sdk/subscribers/{types.d.ts → types.ts} +1 -1
- package/src/sdk/tags/index.ts +11 -19
- package/src/sdk/tags/{types.d.ts → types.ts} +1 -1
- package/src/sdk/{types.d.ts → types.ts} +2 -0
- package/src/versions/v1/index.ts +65 -86
- package/src/versions/v1/{types.d.ts → types.ts} +4 -2
package/src/sdk/tags/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
31
|
+
const result = await this._client.post<DataResponse<Tag[]>>(this._url, {
|
|
32
|
+
tag: parameters,
|
|
33
|
+
});
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
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
|
}
|
package/src/versions/v1/index.ts
CHANGED
|
@@ -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<
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
238
|
+
const result = await this.Batch.importEvents({
|
|
239
|
+
events: [parameters],
|
|
240
|
+
});
|
|
259
241
|
|
|
260
|
-
|
|
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<
|
|
35
|
+
export type TrackParameters<S, E extends string> = BaseEvent<E> & {
|
|
36
|
+
fields: Partial<S>;
|
|
37
|
+
};
|