@bentonow/bento-node-sdk 0.2.1 → 1.0.5

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 (76) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +604 -1031
  3. package/dist/index.d.ts +9 -9
  4. package/dist/index.js +1306 -5
  5. package/dist/sdk/batch/enums.d.ts +8 -8
  6. package/dist/sdk/batch/errors.d.ts +18 -18
  7. package/dist/sdk/batch/events.d.ts +71 -71
  8. package/dist/sdk/batch/index.d.ts +55 -55
  9. package/dist/sdk/batch/types.d.ts +37 -37
  10. package/dist/sdk/broadcasts/index.d.ts +26 -0
  11. package/dist/sdk/broadcasts/types.d.ts +32 -0
  12. package/dist/sdk/client/errors.d.ts +12 -6
  13. package/dist/sdk/client/index.d.ts +94 -64
  14. package/dist/sdk/client/types.d.ts +3 -3
  15. package/dist/sdk/commands/enums.d.ts +12 -12
  16. package/dist/sdk/commands/index.d.ts +79 -79
  17. package/dist/sdk/commands/types.d.ts +32 -32
  18. package/dist/sdk/email-templates/index.d.ts +21 -0
  19. package/dist/sdk/email-templates/types.d.ts +23 -0
  20. package/dist/sdk/enums.d.ts +12 -9
  21. package/dist/sdk/errors.d.ts +2 -2
  22. package/dist/sdk/experimental/index.d.ts +75 -57
  23. package/dist/sdk/experimental/types.d.ts +71 -41
  24. package/dist/sdk/fields/index.d.ts +29 -29
  25. package/dist/sdk/fields/types.d.ts +17 -17
  26. package/dist/sdk/forms/index.d.ts +14 -14
  27. package/dist/sdk/forms/types.d.ts +28 -28
  28. package/dist/sdk/index.d.ts +11 -8
  29. package/dist/sdk/interfaces.d.ts +17 -13
  30. package/dist/sdk/sequences/index.d.ts +13 -0
  31. package/dist/sdk/sequences/types.d.ts +18 -0
  32. package/dist/sdk/stats/index.d.ts +24 -0
  33. package/dist/sdk/stats/types.d.ts +26 -0
  34. package/dist/sdk/subscribers/index.d.ts +20 -20
  35. package/dist/sdk/subscribers/types.d.ts +25 -25
  36. package/dist/sdk/tags/index.d.ts +20 -20
  37. package/dist/sdk/tags/types.d.ts +17 -17
  38. package/dist/sdk/types.d.ts +41 -41
  39. package/dist/sdk/workflows/index.d.ts +13 -0
  40. package/dist/sdk/workflows/types.d.ts +18 -0
  41. package/dist/versions/v1/index.d.ts +168 -132
  42. package/dist/versions/v1/types.d.ts +31 -31
  43. package/package.json +31 -44
  44. package/src/sdk/batch/events.ts +1 -1
  45. package/src/sdk/batch/index.ts +15 -22
  46. package/src/sdk/broadcasts/index.ts +44 -0
  47. package/src/sdk/broadcasts/types.ts +38 -0
  48. package/src/sdk/client/errors.ts +14 -0
  49. package/src/sdk/client/index.ts +205 -49
  50. package/src/sdk/commands/index.ts +54 -89
  51. package/src/sdk/email-templates/index.ts +39 -0
  52. package/src/sdk/email-templates/types.ts +27 -0
  53. package/src/sdk/enums.ts +3 -0
  54. package/src/sdk/experimental/index.ts +44 -26
  55. package/src/sdk/experimental/types.ts +35 -0
  56. package/src/sdk/fields/index.ts +1 -3
  57. package/src/sdk/forms/index.ts +4 -9
  58. package/src/sdk/forms/types.ts +1 -7
  59. package/src/sdk/index.ts +3 -0
  60. package/src/sdk/interfaces.ts +4 -0
  61. package/src/sdk/sequences/index.ts +21 -0
  62. package/src/sdk/sequences/types.ts +21 -0
  63. package/src/sdk/stats/index.ts +37 -0
  64. package/src/sdk/stats/types.ts +28 -0
  65. package/src/sdk/subscribers/index.ts +5 -15
  66. package/src/sdk/tags/index.ts +1 -3
  67. package/src/sdk/types.ts +1 -1
  68. package/src/sdk/workflows/index.ts +21 -0
  69. package/src/sdk/workflows/types.ts +21 -0
  70. package/src/versions/v1/index.ts +65 -10
  71. package/dist/bento-node-sdk.cjs.development.js +0 -2071
  72. package/dist/bento-node-sdk.cjs.development.js.map +0 -1
  73. package/dist/bento-node-sdk.cjs.production.min.js +0 -2
  74. package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
  75. package/dist/bento-node-sdk.esm.js +0 -2063
  76. package/dist/bento-node-sdk.esm.js.map +0 -1
@@ -1,8 +1,8 @@
1
- export declare enum BentoEvents {
2
- PURCHASE = "$purchase",
3
- SUBSCRIBE = "$subscribe",
4
- TAG = "$tag",
5
- REMOVE_TAG = "$remove_tag",
6
- UNSUBSCRIBE = "$unsubscribe",
7
- UPDATE_FIELDS = "$update_fields"
8
- }
1
+ export declare enum BentoEvents {
2
+ PURCHASE = "$purchase",
3
+ SUBSCRIBE = "$subscribe",
4
+ TAG = "$tag",
5
+ REMOVE_TAG = "$remove_tag",
6
+ UNSUBSCRIBE = "$unsubscribe",
7
+ UPDATE_FIELDS = "$update_fields"
8
+ }
@@ -1,18 +1,18 @@
1
- export declare class TooFewSubscribersError extends Error {
2
- constructor(message?: string);
3
- }
4
- export declare class TooManySubscribersError extends Error {
5
- constructor(message?: string);
6
- }
7
- export declare class TooFewEventsError extends Error {
8
- constructor(message?: string);
9
- }
10
- export declare class TooManyEventsError extends Error {
11
- constructor(message?: string);
12
- }
13
- export declare class TooFewEmailsError extends Error {
14
- constructor(message?: string);
15
- }
16
- export declare class TooManyEmailsError extends Error {
17
- constructor(message?: string);
18
- }
1
+ export declare class TooFewSubscribersError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+ export declare class TooManySubscribersError extends Error {
5
+ constructor(message?: string);
6
+ }
7
+ export declare class TooFewEventsError extends Error {
8
+ constructor(message?: string);
9
+ }
10
+ export declare class TooManyEventsError extends Error {
11
+ constructor(message?: string);
12
+ }
13
+ export declare class TooFewEmailsError extends Error {
14
+ constructor(message?: string);
15
+ }
16
+ export declare class TooManyEmailsError extends Error {
17
+ constructor(message?: string);
18
+ }
@@ -1,71 +1,71 @@
1
- import type { BentoEvents } from './enums';
2
- export type PurchaseItem = {
3
- product_sku?: string;
4
- product_name?: string;
5
- quantity?: number;
6
- product_price?: number;
7
- product_id?: string;
8
- } & {
9
- [key: string]: string;
10
- };
11
- export type PurchaseCart = {
12
- abandoned_checkout_url?: string;
13
- items?: PurchaseItem[];
14
- };
15
- export type PurchaseDetails = {
16
- unique: {
17
- key: string | number;
18
- };
19
- value: {
20
- currency: string;
21
- amount: number;
22
- };
23
- cart?: PurchaseCart;
24
- };
25
- export type PurchaseEvent = {
26
- date?: Date;
27
- details: PurchaseDetails;
28
- email: string;
29
- type: BentoEvents.PURCHASE | '$purchase';
30
- };
31
- export type SubscribeEvent<S> = {
32
- date?: Date;
33
- email: string;
34
- fields?: Partial<S>;
35
- type: BentoEvents.SUBSCRIBE | '$subscribe';
36
- };
37
- export type TagEvent = {
38
- date?: Date;
39
- details: {
40
- tag: string;
41
- };
42
- email: string;
43
- type: BentoEvents.TAG | '$tag';
44
- };
45
- export type TagRemoveEvent = {
46
- date?: Date;
47
- details: {
48
- tag: string;
49
- };
50
- email: string;
51
- type: BentoEvents.REMOVE_TAG | '$remove_tag';
52
- };
53
- export type UnsubscribeEvent = {
54
- date?: Date;
55
- email: string;
56
- type: BentoEvents.UNSUBSCRIBE | '$unsubscribe';
57
- };
58
- export type UpdateFieldsEvent<S> = {
59
- date?: Date;
60
- email: string;
61
- type: BentoEvents.UPDATE_FIELDS | '$update_fields';
62
- fields: Partial<S>;
63
- };
64
- export type InternalEvents<S> = PurchaseEvent | SubscribeEvent<S> | TagEvent | TagRemoveEvent | UnsubscribeEvent | UpdateFieldsEvent<S>;
65
- export type BaseEvent<E extends string> = {
66
- date?: Date;
67
- details?: Record<string, unknown>;
68
- email: string;
69
- type: `${E}${string}`;
70
- };
71
- export type BentoEvent<S, E extends string> = InternalEvents<S> | BaseEvent<E>;
1
+ import type { BentoEvents } from './enums';
2
+ export type PurchaseItem = {
3
+ product_sku?: string;
4
+ product_name?: string;
5
+ quantity?: number;
6
+ product_price?: number;
7
+ product_id?: string;
8
+ } & {
9
+ [key: string]: string | number;
10
+ };
11
+ export type PurchaseCart = {
12
+ abandoned_checkout_url?: string;
13
+ items?: PurchaseItem[];
14
+ };
15
+ export type PurchaseDetails = {
16
+ unique: {
17
+ key: string | number;
18
+ };
19
+ value: {
20
+ currency: string;
21
+ amount: number;
22
+ };
23
+ cart?: PurchaseCart;
24
+ };
25
+ export type PurchaseEvent = {
26
+ date?: Date;
27
+ details: PurchaseDetails;
28
+ email: string;
29
+ type: BentoEvents.PURCHASE | '$purchase';
30
+ };
31
+ export type SubscribeEvent<S> = {
32
+ date?: Date;
33
+ email: string;
34
+ fields?: Partial<S>;
35
+ type: BentoEvents.SUBSCRIBE | '$subscribe';
36
+ };
37
+ export type TagEvent = {
38
+ date?: Date;
39
+ details: {
40
+ tag: string;
41
+ };
42
+ email: string;
43
+ type: BentoEvents.TAG | '$tag';
44
+ };
45
+ export type TagRemoveEvent = {
46
+ date?: Date;
47
+ details: {
48
+ tag: string;
49
+ };
50
+ email: string;
51
+ type: BentoEvents.REMOVE_TAG | '$remove_tag';
52
+ };
53
+ export type UnsubscribeEvent = {
54
+ date?: Date;
55
+ email: string;
56
+ type: BentoEvents.UNSUBSCRIBE | '$unsubscribe';
57
+ };
58
+ export type UpdateFieldsEvent<S> = {
59
+ date?: Date;
60
+ email: string;
61
+ type: BentoEvents.UPDATE_FIELDS | '$update_fields';
62
+ fields: Partial<S>;
63
+ };
64
+ export type InternalEvents<S> = PurchaseEvent | SubscribeEvent<S> | TagEvent | TagRemoveEvent | UnsubscribeEvent | UpdateFieldsEvent<S>;
65
+ export type BaseEvent<E extends string> = {
66
+ date?: Date;
67
+ details?: Record<string, unknown>;
68
+ email: string;
69
+ type: `${E}${string}`;
70
+ };
71
+ export type BentoEvent<S, E extends string> = InternalEvents<S> | BaseEvent<E>;
@@ -1,55 +1,55 @@
1
- import type { BentoClient } from '../client';
2
- import type { BatchSendTransactionalEmailsParameter, BatchImportEventsParameter, BatchImportSubscribersParameter } from './types';
3
- export declare class BentoBatch<S, E extends string> {
4
- private readonly _client;
5
- private readonly _maxEmailBatchSize;
6
- private readonly _maxBatchSize;
7
- private readonly _url;
8
- constructor(_client: BentoClient);
9
- /**
10
- * **This does not trigger automations!** - If you wish to trigger automations, please batch import
11
- * events with the type set to `BentoEvents.SUBSCRIBE`, or `$subscribe`. Note that the batch event import
12
- * cannot attach custom fields and will ignore everything except the email.
13
- *
14
- * Creates a batch job to import subscribers into the system. You can pass in
15
- * between 1 and 1,000 subscribers to import. Each subscriber must have an email,
16
- * and may optionally have any additional fields. The additional fields are added
17
- * as custom fields on the subscriber.
18
- *
19
- * This method is processed by the Bento import queues and it may take between 1 and
20
- * 5 minutes for the results to appear in your dashboard.
21
- *
22
- * Returns the number of subscribers that were imported.
23
- *
24
- * @param parameters
25
- * @returns Promise\<number\>
26
- */
27
- importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number>;
28
- /**
29
- * Creates a batch job to import events into the system. You can pass in
30
- * between 1 and 1,000 events to import. Each event must have an email and
31
- * a type. In addition to this, you my pass in additional data in the
32
- * `details` property.
33
- *
34
- * Returns the number of events that were imported.
35
- *
36
- * @param parameters
37
- * @returns Promise\<number\>
38
- */
39
- importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number>;
40
- /**
41
- * Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in
42
- * between 1 and 100 emails to send.
43
- *
44
- * Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
45
- * and `transactional: true`.
46
- * In addition you can add a `personalizations` object to provide
47
- * liquid tsags that will be injected into the email.
48
- *
49
- * Returns the number of events that were imported.
50
- *
51
- * @param parameters
52
- * @returns Promise\<number\>
53
- */
54
- sendTransactionalEmails(parameters: BatchSendTransactionalEmailsParameter): Promise<number>;
55
- }
1
+ import type { BentoClient } from '../client';
2
+ import type { BatchSendTransactionalEmailsParameter, BatchImportEventsParameter, BatchImportSubscribersParameter } from './types';
3
+ export declare class BentoBatch<S, E extends string> {
4
+ private readonly _client;
5
+ private readonly _maxEmailBatchSize;
6
+ private readonly _maxBatchSize;
7
+ private readonly _url;
8
+ constructor(_client: BentoClient);
9
+ /**
10
+ * **This does not trigger automations!** - If you wish to trigger automations, please batch import
11
+ * events with the type set to `BentoEvents.SUBSCRIBE`, or `$subscribe`. Note that the batch event import
12
+ * cannot attach custom fields and will ignore everything except the email.
13
+ *
14
+ * Creates a batch job to import subscribers into the system. You can pass in
15
+ * between 1 and 1,000 subscribers to import. Each subscriber must have an email,
16
+ * and may optionally have any additional fields. The additional fields are added
17
+ * as custom fields on the subscriber.
18
+ *
19
+ * This method is processed by the Bento import queues and it may take between 1 and
20
+ * 5 minutes for the results to appear in your dashboard.
21
+ *
22
+ * Returns the number of subscribers that were imported.
23
+ *
24
+ * @param parameters
25
+ * @returns Promise\<number\>
26
+ */
27
+ importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number>;
28
+ /**
29
+ * Creates a batch job to import events into the system. You can pass in
30
+ * between 1 and 1,000 events to import. Each event must have an email and
31
+ * a type. In addition to this, you my pass in additional data in the
32
+ * `details` property.
33
+ *
34
+ * Returns the number of events that were imported.
35
+ *
36
+ * @param parameters
37
+ * @returns Promise\<number\>
38
+ */
39
+ importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number>;
40
+ /**
41
+ * Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in
42
+ * between 1 and 100 emails to send.
43
+ *
44
+ * Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
45
+ * and `transactional: true`.
46
+ * In addition you can add a `personalizations` object to provide
47
+ * liquid tags that will be injected into the email.
48
+ *
49
+ * Returns the number of events that were imported.
50
+ *
51
+ * @param parameters
52
+ * @returns Promise\<number\>
53
+ */
54
+ sendTransactionalEmails(parameters: BatchSendTransactionalEmailsParameter): Promise<number>;
55
+ }
@@ -1,37 +1,37 @@
1
- import type { BentoEvent } from './events';
2
- /**
3
- * Batch Method Parameter Types
4
- */
5
- export type BatchImportSubscribersParameter<S> = {
6
- subscribers: ({
7
- email: string;
8
- } & Partial<S>)[];
9
- };
10
- export type BatchImportEventsParameter<S, E extends string> = {
11
- events: BentoEvent<S, E>[];
12
- };
13
- export type TransactionalEmail = {
14
- to: string;
15
- from: string;
16
- subject: string;
17
- html_body: string;
18
- transactional: boolean;
19
- personalizations?: {
20
- [key: string]: string | number | boolean;
21
- };
22
- };
23
- export type BatchSendTransactionalEmailsParameter = {
24
- emails: TransactionalEmail[];
25
- };
26
- /**
27
- * Batch Method Response Types
28
- */
29
- export type BatchImportSubscribersResponse = {
30
- results: number;
31
- };
32
- export type BatchImportEventsResponse = {
33
- results: number;
34
- };
35
- export type BatchsendTransactionalEmailsResponse = {
36
- results: number;
37
- };
1
+ import type { BentoEvent } from './events';
2
+ /**
3
+ * Batch Method Parameter Types
4
+ */
5
+ export type BatchImportSubscribersParameter<S> = {
6
+ subscribers: ({
7
+ email: string;
8
+ } & Partial<S>)[];
9
+ };
10
+ export type BatchImportEventsParameter<S, E extends string> = {
11
+ events: BentoEvent<S, E>[];
12
+ };
13
+ export type TransactionalEmail = {
14
+ to: string;
15
+ from: string;
16
+ subject: string;
17
+ html_body: string;
18
+ transactional: boolean;
19
+ personalizations?: {
20
+ [key: string]: string | number | boolean;
21
+ };
22
+ };
23
+ export type BatchSendTransactionalEmailsParameter = {
24
+ emails: TransactionalEmail[];
25
+ };
26
+ /**
27
+ * Batch Method Response Types
28
+ */
29
+ export type BatchImportSubscribersResponse = {
30
+ results: number;
31
+ };
32
+ export type BatchImportEventsResponse = {
33
+ results: number;
34
+ };
35
+ export type BatchsendTransactionalEmailsResponse = {
36
+ results: number;
37
+ };
@@ -0,0 +1,26 @@
1
+ import type { BentoClient } from '../client';
2
+ import type { Broadcast, CreateBroadcastInput, EmailData } from './types';
3
+ export declare class BentoBroadcasts {
4
+ private readonly _client;
5
+ private readonly _fetchUrl;
6
+ private readonly _batchUrl;
7
+ private readonly _emailsUrl;
8
+ constructor(_client: BentoClient);
9
+ /**
10
+ * Creates transactional emails in batch
11
+ * @param emails Array of email data to send
12
+ * @returns Promise<number> Number of emails successfully created
13
+ */
14
+ createEmails(emails: EmailData[]): Promise<number>;
15
+ /**
16
+ * Retrieves all broadcasts for the site
17
+ * @returns Promise<Broadcast[]>
18
+ */
19
+ getBroadcasts(): Promise<Broadcast[]>;
20
+ /**
21
+ * Creates new broadcast campaigns
22
+ * @param broadcasts Array of broadcast data to create
23
+ * @returns Promise<Broadcast[]>
24
+ */
25
+ createBroadcast(broadcasts: CreateBroadcastInput[]): Promise<Broadcast[]>;
26
+ }
@@ -0,0 +1,32 @@
1
+ import type { BaseEntity } from '../types';
2
+ export type BroadcastType = 'plain' | 'html' | 'markdown';
3
+ export type ContactData = {
4
+ name: string;
5
+ email: string;
6
+ };
7
+ export type BroadcastAttributes = {
8
+ name: string;
9
+ subject: string;
10
+ content: string;
11
+ type: BroadcastType;
12
+ from: ContactData;
13
+ inclusive_tags?: string;
14
+ exclusive_tags?: string;
15
+ segment_id?: string;
16
+ batch_size_per_hour: number;
17
+ created_at: string;
18
+ };
19
+ export type Broadcast = BaseEntity<BroadcastAttributes>;
20
+ export type CreateBroadcastInput = Omit<BroadcastAttributes, 'created_at'>;
21
+ /**
22
+ * Email data for transactional emails.
23
+ * Note: This is the same structure as TransactionalEmail in batch/types.ts
24
+ */
25
+ export type EmailData = {
26
+ to: string;
27
+ from: string;
28
+ subject: string;
29
+ html_body: string;
30
+ transactional: boolean;
31
+ personalizations?: Record<string, string | number | boolean>;
32
+ };
@@ -1,6 +1,12 @@
1
- export declare class NotAuthorizedError extends Error {
2
- constructor(message?: string);
3
- }
4
- export declare class RateLimitedError extends Error {
5
- constructor(message?: string);
6
- }
1
+ export declare class NotAuthorizedError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+ export declare class RateLimitedError extends Error {
5
+ constructor(message?: string);
6
+ }
7
+ export declare class AuthorNotAuthorizedError extends Error {
8
+ constructor(message?: string);
9
+ }
10
+ export declare class RequestTimeoutError extends Error {
11
+ constructor(message?: string);
12
+ }
@@ -1,64 +1,94 @@
1
- import type { AnalyticsOptions } from '../interfaces';
2
- export declare class BentoClient {
3
- private readonly _headers;
4
- private readonly _baseUrl;
5
- private readonly _siteUuid;
6
- private readonly _logErrors;
7
- constructor(options: AnalyticsOptions);
8
- /**
9
- * Wraps a GET request to the Bento API and automatically adds the required
10
- * headers.
11
- *
12
- * @param endpoint string
13
- * @param payload object
14
- * @returns Promise\<T\>
15
- * */
16
- get<T>(endpoint: string, payload?: Record<string, unknown>): Promise<T>;
17
- /**
18
- * Wraps a POST request to the Bento API and automatically adds the required
19
- * headers.
20
- *
21
- * @param endpoint string
22
- * @param payload object
23
- * @returns Promise\<T\>
24
- * */
25
- post<T>(endpoint: string, payload?: Record<string, unknown>): Promise<T>;
26
- /**
27
- * Extracts the `publishableKey` and `secretKey` from the `authentication` options and
28
- * adds the `Authorization` header.
29
- *
30
- * @param authentication AuthenticationOptions
31
- * @returns HeadersInit
32
- */
33
- private _extractHeaders;
34
- /**
35
- * Takes the existing payload and adds the `site_uuid` to it, then returns
36
- * it out as a JSON string so that it can be sent alongside the request.
37
- *
38
- * @param payload object
39
- * @returns string
40
- */
41
- private _getBody;
42
- /**
43
- * Takes the existing payload and adds the `site_uuid` to it, converts the
44
- * object to a query string so that it can be sent alongside a GET request.
45
- *
46
- * @param payload object
47
- * @returns string
48
- */
49
- private _getQueryParameters;
50
- /**
51
- * Filters down the status codes to those that are considered a 'success'.
52
- *
53
- * @param statusCode number
54
- * @returns boolean
55
- */
56
- private _isSuccessfulStatus;
57
- /**
58
- * Returns an appropriate error to be thrown given the received response.
59
- *
60
- * @param response Response
61
- * @returns Error
62
- */
63
- private _getErrorForResponse;
64
- }
1
+ import type { AnalyticsOptions } from '../interfaces';
2
+ interface RequestOptions {
3
+ timeout?: number | null;
4
+ }
5
+ export declare class BentoClient {
6
+ private readonly _headers;
7
+ private readonly _baseUrl;
8
+ private readonly _siteUuid;
9
+ private readonly _logErrors;
10
+ private readonly _timeout;
11
+ constructor(options: AnalyticsOptions);
12
+ /**
13
+ * Wraps a GET request to the Bento API and automatically adds the required
14
+ * headers.
15
+ *
16
+ * @param endpoint string
17
+ * @param payload object
18
+ * @returns Promise\<T\>
19
+ * */
20
+ get<T>(endpoint: string, payload?: Record<string, unknown>, requestOptions?: RequestOptions): Promise<T>;
21
+ /**
22
+ * Wraps a POST request to the Bento API and automatically adds the required
23
+ * headers.
24
+ *
25
+ * @param endpoint string
26
+ * @param payload object
27
+ * @returns Promise\<T\>
28
+ * */
29
+ post<T>(endpoint: string, payload?: Record<string, unknown>, requestOptions?: RequestOptions): Promise<T>;
30
+ /**
31
+ * Wraps a PATCH request to the Bento API and automatically adds the required
32
+ * headers.
33
+ *
34
+ * @param endpoint string
35
+ * @param payload object
36
+ * @returns Promise\<T\>
37
+ * */
38
+ patch<T>(endpoint: string, payload?: Record<string, unknown>, requestOptions?: RequestOptions): Promise<T>;
39
+ /**
40
+ * Performs a fetch request with a configurable timeout.
41
+ *
42
+ * @param url The URL to fetch
43
+ * @param options Fetch options
44
+ * @returns Promise<Response>
45
+ */
46
+ private _fetchWithTimeout;
47
+ /**
48
+ * Handles the response from a fetch request, parsing JSON or throwing appropriate errors.
49
+ *
50
+ * @param response The fetch Response object
51
+ * @returns Promise<T> The parsed response data
52
+ */
53
+ private _handleResponse;
54
+ /**
55
+ * Extracts the `publishableKey` and `secretKey` from the `authentication` options,
56
+ * adds the `Authorization` header, and includes a `User-Agent` header with the site UUID.
57
+ *
58
+ * @param authentication AuthenticationOptions
59
+ * @param siteUuid string The site UUID to be included in the User-Agent header
60
+ * @returns HeadersInit
61
+ */
62
+ private _extractHeaders;
63
+ /**
64
+ * Takes the existing payload and adds the `site_uuid` to it, then returns
65
+ * it out as a JSON string so that it can be sent alongside the request.
66
+ *
67
+ * @param payload object
68
+ * @returns string
69
+ */
70
+ private _getBody;
71
+ /**
72
+ * Takes the existing payload and adds the `site_uuid` to it, converts the
73
+ * object to a query string so that it can be sent alongside a GET request.
74
+ *
75
+ * @param payload object
76
+ * @returns string
77
+ */
78
+ private _getQueryParameters;
79
+ /**
80
+ * Filters down the status codes to those that are considered a 'success'.
81
+ *
82
+ * @param statusCode number
83
+ * @returns boolean
84
+ */
85
+ private _isSuccessfulStatus;
86
+ /**
87
+ * Returns an appropriate error to be thrown given the received response.
88
+ *
89
+ * @param response Response
90
+ * @returns Error
91
+ */
92
+ private _getErrorForResponse;
93
+ }
94
+ export {};
@@ -1,3 +1,3 @@
1
- export type DataResponse<T> = {
2
- data: T;
3
- };
1
+ export type DataResponse<T> = {
2
+ data: T;
3
+ };
@@ -1,12 +1,12 @@
1
- /**
2
- * Command Enums
3
- */
4
- export declare enum CommandTypes {
5
- ADD_FIELD = "add_field",
6
- ADD_TAG = "add_tag",
7
- CHANGE_EMAIL = "change_email",
8
- REMOVE_FIELD = "remove_field",
9
- REMOVE_TAG = "remove_tag",
10
- SUBSCRIBE = "subscribe",
11
- UNSUBSCRIBE = "unsubscribe"
12
- }
1
+ /**
2
+ * Command Enums
3
+ */
4
+ export declare enum CommandTypes {
5
+ ADD_FIELD = "add_field",
6
+ ADD_TAG = "add_tag",
7
+ CHANGE_EMAIL = "change_email",
8
+ REMOVE_FIELD = "remove_field",
9
+ REMOVE_TAG = "remove_tag",
10
+ SUBSCRIBE = "subscribe",
11
+ UNSUBSCRIBE = "unsubscribe"
12
+ }