@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/client/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from 'isomorphic-fetch';
|
|
2
|
-
import { AnalyticsOptions, AuthenticationOptions } from '../interfaces';
|
|
2
|
+
import type { AnalyticsOptions, AuthenticationOptions } from '../interfaces';
|
|
3
3
|
import { NotAuthorizedError, RateLimitedError } from './errors';
|
|
4
4
|
|
|
5
5
|
export class BentoClient {
|
|
@@ -23,7 +23,10 @@ export class BentoClient {
|
|
|
23
23
|
* @param payload object
|
|
24
24
|
* @returns Promise\<T\>
|
|
25
25
|
* */
|
|
26
|
-
public get<T>(
|
|
26
|
+
public get<T>(
|
|
27
|
+
endpoint: string,
|
|
28
|
+
payload: Record<string, unknown> = {}
|
|
29
|
+
): Promise<T> {
|
|
27
30
|
return new Promise<T>((resolve, reject) => {
|
|
28
31
|
const queryParameters = this._getQueryParameters(payload);
|
|
29
32
|
|
|
@@ -31,15 +34,15 @@ export class BentoClient {
|
|
|
31
34
|
method: 'GET',
|
|
32
35
|
headers: this._headers,
|
|
33
36
|
})
|
|
34
|
-
.then(async result => {
|
|
37
|
+
.then(async (result) => {
|
|
35
38
|
if (this._isSuccessfulStatus(result.status)) {
|
|
36
39
|
return result.json();
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
throw await this._getErrorForResponse(result);
|
|
40
43
|
})
|
|
41
|
-
.then(data => resolve(data))
|
|
42
|
-
.catch(error => reject(error));
|
|
44
|
+
.then((data) => resolve(data))
|
|
45
|
+
.catch((error) => reject(error));
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -51,7 +54,10 @@ export class BentoClient {
|
|
|
51
54
|
* @param payload object
|
|
52
55
|
* @returns Promise\<T\>
|
|
53
56
|
* */
|
|
54
|
-
public post<T>(
|
|
57
|
+
public post<T>(
|
|
58
|
+
endpoint: string,
|
|
59
|
+
payload: Record<string, unknown> = {}
|
|
60
|
+
): Promise<T> {
|
|
55
61
|
return new Promise<T>((resolve, reject) => {
|
|
56
62
|
const body = this._getBody(payload);
|
|
57
63
|
|
|
@@ -63,15 +69,15 @@ export class BentoClient {
|
|
|
63
69
|
},
|
|
64
70
|
body,
|
|
65
71
|
})
|
|
66
|
-
.then(async result => {
|
|
72
|
+
.then(async (result) => {
|
|
67
73
|
if (this._isSuccessfulStatus(result.status)) {
|
|
68
74
|
return result.json();
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
throw await this._getErrorForResponse(result);
|
|
72
78
|
})
|
|
73
|
-
.then(data => resolve(data))
|
|
74
|
-
.catch(error => reject(error));
|
|
79
|
+
.then((data) => resolve(data))
|
|
80
|
+
.catch((error) => reject(error));
|
|
75
81
|
});
|
|
76
82
|
}
|
|
77
83
|
|
|
@@ -99,7 +105,7 @@ export class BentoClient {
|
|
|
99
105
|
* @param payload object
|
|
100
106
|
* @returns string
|
|
101
107
|
*/
|
|
102
|
-
private _getBody(payload:
|
|
108
|
+
private _getBody(payload: Record<string, unknown>): string {
|
|
103
109
|
return JSON.stringify({
|
|
104
110
|
...payload,
|
|
105
111
|
site_uuid: this._siteUuid,
|
|
@@ -113,7 +119,7 @@ export class BentoClient {
|
|
|
113
119
|
* @param payload object
|
|
114
120
|
* @returns string
|
|
115
121
|
*/
|
|
116
|
-
private _getQueryParameters(payload:
|
|
122
|
+
private _getQueryParameters(payload: Record<string, unknown>): string {
|
|
117
123
|
const body = {
|
|
118
124
|
...payload,
|
|
119
125
|
site_uuid: this._siteUuid,
|
|
@@ -146,6 +152,10 @@ export class BentoClient {
|
|
|
146
152
|
* @returns Error
|
|
147
153
|
*/
|
|
148
154
|
private async _getErrorForResponse(response: Response): Promise<Error> {
|
|
155
|
+
if (this._logErrors) {
|
|
156
|
+
console.error(response);
|
|
157
|
+
}
|
|
158
|
+
|
|
149
159
|
if (response.status === 401) return new NotAuthorizedError();
|
|
150
160
|
if (response.status === 429) return new RateLimitedError();
|
|
151
161
|
|
|
@@ -164,10 +174,6 @@ export class BentoClient {
|
|
|
164
174
|
break;
|
|
165
175
|
}
|
|
166
176
|
|
|
167
|
-
if (this._logErrors) {
|
|
168
|
-
console.error(response);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
177
|
return new Error(`[${response.status}] - ${responseMessage}`);
|
|
172
178
|
}
|
|
173
179
|
}
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BentoClient } from '../client';
|
|
2
|
-
import { DataResponse } from '../client/types';
|
|
3
|
-
import { Subscriber } from '../subscribers/types';
|
|
1
|
+
import type { BentoClient } from '../client';
|
|
2
|
+
import type { DataResponse } from '../client/types';
|
|
3
|
+
import type { Subscriber } from '../subscribers/types';
|
|
4
4
|
import { CommandTypes } from './enums';
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
AddFieldParameters,
|
|
7
7
|
AddTagParameters,
|
|
8
8
|
ChangeEmailParameters,
|
|
@@ -33,23 +33,19 @@ export class BentoCommands<S> {
|
|
|
33
33
|
public async addTag(
|
|
34
34
|
parameters: AddTagParameters
|
|
35
35
|
): Promise<Subscriber<S> | null> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
command:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return result.data;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
36
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
37
|
+
this._url,
|
|
38
|
+
{
|
|
39
|
+
command: {
|
|
40
|
+
command: CommandTypes.ADD_TAG,
|
|
41
|
+
email: parameters.email,
|
|
42
|
+
query: parameters.tagName,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
48
|
+
return result.data;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
/**
|
|
@@ -61,23 +57,19 @@ export class BentoCommands<S> {
|
|
|
61
57
|
public async removeTag(
|
|
62
58
|
parameters: RemoveTagParameters
|
|
63
59
|
): Promise<Subscriber<S> | null> {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{
|
|
68
|
-
command:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return result.data;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
60
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
61
|
+
this._url,
|
|
62
|
+
{
|
|
63
|
+
command: {
|
|
64
|
+
command: CommandTypes.REMOVE_TAG,
|
|
65
|
+
email: parameters.email,
|
|
66
|
+
query: parameters.tagName,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
72
|
+
return result.data;
|
|
81
73
|
}
|
|
82
74
|
|
|
83
75
|
/**
|
|
@@ -95,23 +87,19 @@ export class BentoCommands<S> {
|
|
|
95
87
|
public async addField(
|
|
96
88
|
parameters: AddFieldParameters<S>
|
|
97
89
|
): Promise<Subscriber<S> | null> {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
command:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return result.data;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
90
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
91
|
+
this._url,
|
|
92
|
+
{
|
|
93
|
+
command: {
|
|
94
|
+
command: CommandTypes.ADD_FIELD,
|
|
95
|
+
email: parameters.email,
|
|
96
|
+
query: parameters.field,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
102
|
+
return result.data;
|
|
115
103
|
}
|
|
116
104
|
|
|
117
105
|
/**
|
|
@@ -123,23 +111,19 @@ export class BentoCommands<S> {
|
|
|
123
111
|
public async removeField(
|
|
124
112
|
parameters: RemoveFieldParameters<S>
|
|
125
113
|
): Promise<Subscriber<S> | null> {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
command:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return result.data;
|
|
140
|
-
} catch (error) {
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
114
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
115
|
+
this._url,
|
|
116
|
+
{
|
|
117
|
+
command: {
|
|
118
|
+
command: CommandTypes.REMOVE_FIELD,
|
|
119
|
+
email: parameters.email,
|
|
120
|
+
query: parameters.fieldName,
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
126
|
+
return result.data;
|
|
143
127
|
}
|
|
144
128
|
|
|
145
129
|
/**
|
|
@@ -155,22 +139,18 @@ export class BentoCommands<S> {
|
|
|
155
139
|
public async subscribe(
|
|
156
140
|
parameters: SubscribeParameters
|
|
157
141
|
): Promise<Subscriber<S> | null> {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{
|
|
162
|
-
command:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return result.data;
|
|
171
|
-
} catch (error) {
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
142
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
143
|
+
this._url,
|
|
144
|
+
{
|
|
145
|
+
command: {
|
|
146
|
+
command: CommandTypes.SUBSCRIBE,
|
|
147
|
+
email: parameters.email,
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
153
|
+
return result.data;
|
|
174
154
|
}
|
|
175
155
|
|
|
176
156
|
/**
|
|
@@ -187,22 +167,18 @@ export class BentoCommands<S> {
|
|
|
187
167
|
public async unsubscribe(
|
|
188
168
|
parameters: UnsubscribeParameters
|
|
189
169
|
): Promise<Subscriber<S> | null> {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{
|
|
194
|
-
command:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return result.data;
|
|
203
|
-
} catch (error) {
|
|
204
|
-
throw error;
|
|
205
|
-
}
|
|
170
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
171
|
+
this._url,
|
|
172
|
+
{
|
|
173
|
+
command: {
|
|
174
|
+
command: CommandTypes.UNSUBSCRIBE,
|
|
175
|
+
email: parameters.email,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
181
|
+
return result.data;
|
|
206
182
|
}
|
|
207
183
|
|
|
208
184
|
/**
|
|
@@ -214,22 +190,18 @@ export class BentoCommands<S> {
|
|
|
214
190
|
public async changeEmail(
|
|
215
191
|
parameters: ChangeEmailParameters
|
|
216
192
|
): Promise<Subscriber<S> | null> {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{
|
|
221
|
-
command:
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return result.data;
|
|
231
|
-
} catch (error) {
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
193
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
194
|
+
this._url,
|
|
195
|
+
{
|
|
196
|
+
command: {
|
|
197
|
+
command: CommandTypes.CHANGE_EMAIL,
|
|
198
|
+
email: parameters.oldEmail,
|
|
199
|
+
query: parameters.newEmail,
|
|
200
|
+
},
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (Object.keys(result).length === 0 || !result.data) return null;
|
|
205
|
+
return result.data;
|
|
234
206
|
}
|
|
235
207
|
}
|
|
@@ -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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
64
|
+
const result = await this._client.post<GuessGenderResponse>(
|
|
65
|
+
`${this._url}/gender`,
|
|
66
|
+
parameters
|
|
67
|
+
);
|
|
73
68
|
|
|
74
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
);
|
|
84
|
+
const result = await this._client.get<GeolocateResponse>(
|
|
85
|
+
`${this._url}/geolocation`,
|
|
86
|
+
parameters
|
|
87
|
+
);
|
|
97
88
|
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
106
|
+
const result = await this._client.get<BlacklistResponse>(
|
|
107
|
+
`${this._url}/blacklist.json`,
|
|
108
|
+
parameters
|
|
109
|
+
);
|
|
123
110
|
|
|
124
|
-
|
|
125
|
-
} catch (error) {
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
111
|
+
return result;
|
|
128
112
|
}
|
|
129
113
|
}
|
package/src/sdk/fields/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -41,15 +37,11 @@ export class BentoFields {
|
|
|
41
37
|
public async createField(
|
|
42
38
|
parameters: CreateFieldParameters
|
|
43
39
|
): Promise<Field[] | null> {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
40
|
+
const result = await this._client.post<DataResponse<Field[]>>(this._url, {
|
|
41
|
+
field: parameters,
|
|
42
|
+
});
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
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
|
}
|
package/src/sdk/forms/index.ts
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
19
|
+
const result = await this._client.get<DataResponse<FormResponse[]>>(
|
|
20
|
+
this._url,
|
|
21
|
+
{
|
|
22
|
+
id: formIdentifier,
|
|
23
|
+
}
|
|
24
|
+
);
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
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]:
|
|
17
|
-
fields: { [key: string]:
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
22
|
+
const result = await this._client.get<DataResponse<Subscriber<S>>>(
|
|
23
|
+
this._url,
|
|
24
|
+
parameters
|
|
25
|
+
);
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
40
|
+
const result = await this._client.post<DataResponse<Subscriber<S>>>(
|
|
41
|
+
this._url,
|
|
42
|
+
{
|
|
43
|
+
subscriber: parameters,
|
|
44
|
+
}
|
|
45
|
+
);
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
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
|
}
|