@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
@@ -0,0 +1,21 @@
1
+ import type { BentoEvent } from './events';
2
+ /**
3
+ * Batch Method Parameter Types
4
+ */
5
+ export declare type BatchImportSubscribersParameter<S> = {
6
+ subscribers: ({
7
+ email: string;
8
+ } & Partial<S>)[];
9
+ };
10
+ export declare type BatchImportEventsParameter<S, E extends string> = {
11
+ events: BentoEvent<S, E>[];
12
+ };
13
+ /**
14
+ * Batch Method Response Types
15
+ */
16
+ export declare type BatchImportSubscribersResponse = {
17
+ results: number;
18
+ };
19
+ export declare type BatchImportEventsResponse = {
20
+ results: number;
21
+ };
@@ -1,4 +1,6 @@
1
1
  export declare class NotAuthorizedError extends Error {
2
+ constructor(message?: string);
2
3
  }
3
4
  export declare class RateLimitedError extends Error {
5
+ constructor(message?: string);
4
6
  }
@@ -1,4 +1,4 @@
1
- import { AnalyticsOptions } from '../interfaces';
1
+ import type { AnalyticsOptions } from '../interfaces';
2
2
  export declare class BentoClient {
3
3
  private readonly _headers;
4
4
  private readonly _baseUrl;
@@ -13,7 +13,7 @@ export declare class BentoClient {
13
13
  * @param payload object
14
14
  * @returns Promise\<T\>
15
15
  * */
16
- get<T>(endpoint: string, payload?: object): Promise<T>;
16
+ get<T>(endpoint: string, payload?: Record<string, unknown>): Promise<T>;
17
17
  /**
18
18
  * Wraps a POST request to the Bento API and automatically adds the required
19
19
  * headers.
@@ -22,7 +22,7 @@ export declare class BentoClient {
22
22
  * @param payload object
23
23
  * @returns Promise\<T\>
24
24
  * */
25
- post<T>(endpoint: string, payload?: object): Promise<T>;
25
+ post<T>(endpoint: string, payload?: Record<string, unknown>): Promise<T>;
26
26
  /**
27
27
  * Extracts the `publishableKey` and `secretKey` from the `authentication` options and
28
28
  * adds the `Authorization` header.
@@ -0,0 +1,3 @@
1
+ export declare type DataResponse<T> = {
2
+ data: T;
3
+ };
@@ -1,6 +1,6 @@
1
- import { BentoClient } from '../client';
2
- import { Subscriber } from '../subscribers/types';
3
- import { AddFieldParameters, AddTagParameters, ChangeEmailParameters, RemoveFieldParameters, RemoveTagParameters, SubscribeParameters, UnsubscribeParameters } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { Subscriber } from '../subscribers/types';
3
+ import type { AddFieldParameters, AddTagParameters, ChangeEmailParameters, RemoveFieldParameters, RemoveTagParameters, SubscribeParameters, UnsubscribeParameters } from './types';
4
4
  export declare class BentoCommands<S> {
5
5
  private readonly _client;
6
6
  private readonly _url;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Command Method Parameter Types
3
+ */
4
+ export declare type AddTagParameters = {
5
+ email: string;
6
+ tagName: string;
7
+ };
8
+ export declare type RemoveTagParameters = {
9
+ email: string;
10
+ tagName: string;
11
+ };
12
+ export declare type AddFieldParameters<S> = {
13
+ email: string;
14
+ field: {
15
+ key: keyof S;
16
+ value: unknown;
17
+ };
18
+ };
19
+ export declare type RemoveFieldParameters<S> = {
20
+ email: string;
21
+ fieldName: keyof S;
22
+ };
23
+ export declare type SubscribeParameters = {
24
+ email: string;
25
+ };
26
+ export declare type UnsubscribeParameters = {
27
+ email: string;
28
+ };
29
+ export declare type ChangeEmailParameters = {
30
+ oldEmail: string;
31
+ newEmail: string;
32
+ };
@@ -1,6 +1,6 @@
1
- import { BlacklistParameters, BlacklistResponse, GeolocateParameters, GuessGenderParameters, GuessGenderResponse, ValidateEmailParameters } from './types';
2
- import { BentoClient } from '../client';
3
- import { LocationData } from '../types';
1
+ import type { BentoClient } from '../client';
2
+ import type { LocationData } from '../types';
3
+ import type { BlacklistParameters, BlacklistResponse, GeolocateParameters, GuessGenderParameters, GuessGenderResponse, ValidateEmailParameters } from './types';
4
4
  export declare class BentoExperimental {
5
5
  private readonly _client;
6
6
  private readonly _url;
@@ -0,0 +1,41 @@
1
+ import type { LocationData } from '../types';
2
+ /**
3
+ * Experimental Method Parameter Types
4
+ */
5
+ export declare type ValidateEmailParameters = {
6
+ email: string;
7
+ ip?: string;
8
+ name?: string;
9
+ userAgent?: string;
10
+ };
11
+ export declare type GuessGenderParameters = {
12
+ name: string;
13
+ };
14
+ export declare type GeolocateParameters = {
15
+ ip: string;
16
+ };
17
+ export declare type BlacklistParameters = {
18
+ domain: string;
19
+ ip?: never;
20
+ } | {
21
+ domain?: never;
22
+ ip: string;
23
+ };
24
+ /**
25
+ * Experimental Method Response Types
26
+ */
27
+ export declare type ValidateEmailResponse = {
28
+ valid: boolean;
29
+ };
30
+ export declare type GuessGenderResponse = {
31
+ confidence: number | null;
32
+ gender: string | null;
33
+ };
34
+ export declare type GeolocateResponse = Partial<LocationData>;
35
+ export declare type BlacklistResponse = {
36
+ description: string;
37
+ query: string;
38
+ results: {
39
+ [key: string]: boolean;
40
+ };
41
+ };
@@ -1,5 +1,5 @@
1
- import { BentoClient } from '../client';
2
- import { CreateFieldParameters, Field } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { CreateFieldParameters, Field } from './types';
3
3
  export declare class BentoFields {
4
4
  private readonly _client;
5
5
  private readonly _url;
@@ -0,0 +1,17 @@
1
+ import type { BaseEntity } from '../types';
2
+ /**
3
+ * Field Method Parameter Types
4
+ */
5
+ export declare type CreateFieldParameters = {
6
+ key: string;
7
+ };
8
+ /**
9
+ * Core Field Types
10
+ */
11
+ export declare type FieldAttributes = {
12
+ created_at: string;
13
+ key: string;
14
+ name: string;
15
+ whitelisted: boolean | null;
16
+ };
17
+ export declare type Field = BaseEntity<FieldAttributes>;
@@ -1,5 +1,5 @@
1
- import { BentoClient } from '../client';
2
- import { FormResponse } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { FormResponse } from './types';
3
3
  export declare class BentoForms {
4
4
  private readonly _client;
5
5
  private readonly _url;
@@ -0,0 +1,28 @@
1
+ import type { BaseEntity, BrowserData, IdentityData, LocationData, PageData } from '../types';
2
+ /**
3
+ * Core Form Types
4
+ */
5
+ export declare type FormResponseData = {
6
+ browser: BrowserData;
7
+ date: string;
8
+ details: {
9
+ [key: string]: unknown;
10
+ };
11
+ fields: {
12
+ [key: string]: unknown;
13
+ };
14
+ id: string;
15
+ identity: IdentityData;
16
+ ip: string;
17
+ location: LocationData;
18
+ page: PageData;
19
+ site: string;
20
+ type: string;
21
+ visit: string;
22
+ visitor: string;
23
+ };
24
+ export declare type FormResponseAttributes = {
25
+ data: FormResponseData;
26
+ uuid: string;
27
+ };
28
+ export declare type FormResponse = BaseEntity<FormResponseAttributes>;
@@ -0,0 +1,13 @@
1
+ export interface AnalyticsOptions {
2
+ authentication: AuthenticationOptions;
3
+ clientOptions?: ClientOptions;
4
+ logErrors?: boolean;
5
+ siteUuid: string;
6
+ }
7
+ export interface AuthenticationOptions {
8
+ publishableKey: string;
9
+ secretKey: string;
10
+ }
11
+ export interface ClientOptions {
12
+ baseUrl?: string;
13
+ }
@@ -1,5 +1,5 @@
1
- import { BentoClient } from '../client';
2
- import { CreateSubscriberParameters, GetSubscribersParameters, Subscriber } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { CreateSubscriberParameters, GetSubscribersParameters, Subscriber } from './types';
3
3
  export declare class BentoSubscribers<S> {
4
4
  private readonly _client;
5
5
  private readonly _url;
@@ -0,0 +1,25 @@
1
+ import type { BaseEntity } from '../types';
2
+ /**
3
+ * Subscriber Method Parameter Types
4
+ */
5
+ export declare type GetSubscribersParameters = {
6
+ email?: never;
7
+ uuid: string;
8
+ } | {
9
+ email: string;
10
+ uuid?: never;
11
+ } | never;
12
+ export declare type CreateSubscriberParameters = {
13
+ email: string;
14
+ };
15
+ /**
16
+ * Core Subscriber Types
17
+ */
18
+ export declare type SubscriberAttributes<S> = {
19
+ cached_tag_ids: string[];
20
+ email: string;
21
+ fields: S | null;
22
+ unsubscribed_at: string | null;
23
+ uuid: string;
24
+ };
25
+ export declare type Subscriber<S> = BaseEntity<SubscriberAttributes<S>>;
@@ -1,5 +1,5 @@
1
- import { BentoClient } from '../client';
2
- import { CreateTagParameters, Tag } from './types';
1
+ import type { BentoClient } from '../client';
2
+ import type { CreateTagParameters, Tag } from './types';
3
3
  export declare class BentoTags {
4
4
  private readonly _client;
5
5
  private readonly _url;
@@ -0,0 +1,17 @@
1
+ import type { BaseEntity } from '../types';
2
+ /**
3
+ * Tag Method Parameter Types
4
+ */
5
+ export declare type CreateTagParameters = {
6
+ name: string;
7
+ };
8
+ /**
9
+ * Core Tag Types
10
+ */
11
+ export declare type TagAttributes = {
12
+ created_at: string;
13
+ discarded_at: string | null;
14
+ name: string | null;
15
+ site_id: number;
16
+ };
17
+ export declare type Tag = BaseEntity<TagAttributes>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Core Types
3
+ */
4
+ import type { EntityType } from "./enums";
5
+ export declare type BaseEntity<T> = {
6
+ attributes: T;
7
+ id: string;
8
+ type: EntityType;
9
+ };
10
+ /**
11
+ * Utility Types
12
+ */
13
+ export declare type BrowserData = {
14
+ height: string;
15
+ user_agent: string;
16
+ width: string;
17
+ };
18
+ export declare type IdentityData = {
19
+ email: string;
20
+ };
21
+ export declare type LocationData = {
22
+ city_name: string;
23
+ continent_code: string;
24
+ country_code2: string;
25
+ country_code3: string;
26
+ country_name: string;
27
+ ip: string;
28
+ latitude: number;
29
+ longitude: number;
30
+ postal_code: string;
31
+ real_region_name: string;
32
+ region_name: string;
33
+ request: string;
34
+ };
35
+ export declare type PageData = {
36
+ host: string;
37
+ path: string;
38
+ protocol: string;
39
+ referrer: string;
40
+ url: string;
41
+ };
@@ -1,9 +1,9 @@
1
1
  import { BentoBatch, BentoCommands, BentoExperimental, BentoFields, BentoForms, BentoSubscribers, BentoTags } from '../../sdk';
2
- import { AnalyticsOptions } from '../../sdk/interfaces';
3
- import { AddSubscriberParameters, RemoveSubscriberParameters, TagSubscriberParameters, TrackParameters, TrackPurchaseParameters, UpdateFieldsParameters } from './types';
2
+ import type { AnalyticsOptions } from '../../sdk/interfaces';
3
+ import type { AddSubscriberParameters, RemoveSubscriberParameters, TagSubscriberParameters, TrackParameters, TrackPurchaseParameters, UpdateFieldsParameters } from './types';
4
4
  export declare class BentoAPIV1<S = {
5
- [key: string]: any;
6
- }, E = '$custom'> {
5
+ [key: string]: unknown;
6
+ }, E extends string = '$custom'> {
7
7
  private readonly _client;
8
8
  readonly Batch: BentoBatch<S, E>;
9
9
  readonly Commands: BentoCommands<S>;
@@ -0,0 +1,31 @@
1
+ import type { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
2
+ /**
3
+ * API Method Parameter Types
4
+ */
5
+ export declare type TagSubscriberParameters = {
6
+ date?: Date;
7
+ email: string;
8
+ tagName: string;
9
+ };
10
+ export declare type AddSubscriberParameters<S> = {
11
+ date?: Date;
12
+ email: string;
13
+ fields?: Partial<S>;
14
+ };
15
+ export declare type RemoveSubscriberParameters = {
16
+ date?: Date;
17
+ email: string;
18
+ };
19
+ export declare type TrackPurchaseParameters = {
20
+ date?: Date;
21
+ email: string;
22
+ purchaseDetails: PurchaseDetails;
23
+ };
24
+ export declare type UpdateFieldsParameters<S> = {
25
+ date?: Date;
26
+ email: string;
27
+ fields: Partial<S>;
28
+ };
29
+ export declare type TrackParameters<S, E extends string> = BaseEvent<E> & {
30
+ fields: Partial<S>;
31
+ };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.13",
2
+ "version": "0.1.14",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -57,11 +57,13 @@
57
57
  "@size-limit/preset-small-lib": "^5.0.3",
58
58
  "@types/isomorphic-fetch": "^0.0.35",
59
59
  "@types/jest": "^27.0.1",
60
- "@typescript-eslint/eslint-plugin": "^4.29.2",
61
- "@typescript-eslint/parser": "^4.29.2",
60
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
61
+ "@typescript-eslint/parser": "^5.30.7",
62
62
  "@weiran.zsd/tsdx": "^0.15.2",
63
+ "eslint": "^7.32.0",
63
64
  "husky": "^7.0.1",
64
65
  "msw": "^0.34.0",
66
+ "prettier": "^2.7.1",
65
67
  "size-limit": "^5.0.3",
66
68
  "tslib": "^2.3.1",
67
69
  "typescript": "^4.3.5"
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { AnalyticsOptions } from './sdk/interfaces';
1
+ import type { AnalyticsOptions } from './sdk/interfaces';
2
2
  import { BentoAPIV1 } from './versions/v1';
3
3
 
4
- export class Analytics<S = { [key: string]: any }, E = '$custom'> {
4
+ export class Analytics<S = { [key: string]: unknown }, E extends string = ''> {
5
5
  public readonly V1: BentoAPIV1<S, E>;
6
6
 
7
7
  constructor(options: AnalyticsOptions) {
@@ -1,4 +1,27 @@
1
- export class TooFewSubscribersError extends Error {}
2
- export class TooManySubscribersError extends Error {}
3
- export class TooFewEventsError extends Error {}
4
- export class TooManyEventsError extends Error {}
1
+ export class TooFewSubscribersError extends Error {
2
+ constructor(message = 'Too few subscribers') {
3
+ super(message);
4
+ this.name = 'TooFewSubscribersError';
5
+ }
6
+ }
7
+
8
+ export class TooManySubscribersError extends Error {
9
+ constructor(message = 'Too many subscribers') {
10
+ super(message);
11
+ this.name = 'TooManySubscribersError';
12
+ }
13
+ }
14
+
15
+ export class TooFewEventsError extends Error {
16
+ constructor(message = 'Too few events') {
17
+ super(message);
18
+ this.name = 'TooFewEventsError';
19
+ }
20
+ }
21
+
22
+ export class TooManyEventsError extends Error {
23
+ constructor(message = 'Too many events') {
24
+ super(message);
25
+ this.name = 'TooManyEventsError';
26
+ }
27
+ }
@@ -1,4 +1,4 @@
1
- import { BentoEvents } from './enums';
1
+ import type { BentoEvents } from './enums';
2
2
 
3
3
  export type PurchaseItem = {
4
4
  product_sku?: string;
@@ -77,12 +77,11 @@ export type InternalEvents<S> =
77
77
  | UnsubscribeEvent
78
78
  | UpdateFieldsEvent<S>;
79
79
 
80
- export type BaseEvent<E> = {
80
+ export type BaseEvent<E extends string> = {
81
81
  date?: Date;
82
- details?: { [key: string]: any };
82
+ details?: Record<string, unknown>;
83
83
  email: string;
84
- /* eslint-disable */
85
84
  type: `${E}${string}`;
86
85
  };
87
86
 
88
- export type BentoEvent<S, E> = InternalEvents<S> | BaseEvent<E>;
87
+ export type BentoEvent<S, E extends string> = InternalEvents<S> | BaseEvent<E>;
@@ -1,18 +1,18 @@
1
- import {
2
- BatchImportEventsParameter,
3
- BatchImportEventsResponse,
4
- BatchImportSubscribersParameter,
5
- BatchImportSubscribersResponse,
6
- } from './types';
7
- import { BentoClient } from '../client';
1
+ import type { BentoClient } from '../client';
8
2
  import {
9
3
  TooFewEventsError,
10
4
  TooFewSubscribersError,
11
5
  TooManyEventsError,
12
6
  TooManySubscribersError,
13
7
  } from './errors';
8
+ import type {
9
+ BatchImportEventsParameter,
10
+ BatchImportEventsResponse,
11
+ BatchImportSubscribersParameter,
12
+ BatchImportSubscribersResponse,
13
+ } from './types';
14
14
 
15
- export class BentoBatch<S, E> {
15
+ export class BentoBatch<S, E extends string> {
16
16
  private readonly _maxBatchSize = 1000;
17
17
  private readonly _url = '/batch';
18
18
 
@@ -39,30 +39,26 @@ export class BentoBatch<S, E> {
39
39
  public async importSubscribers(
40
40
  parameters: BatchImportSubscribersParameter<S>
41
41
  ): Promise<number> {
42
- try {
43
- if (parameters.subscribers.length === 0) {
44
- throw new TooFewSubscribersError(
45
- `You must send between 1 and 1,000 subscribers.`
46
- );
47
- }
48
-
49
- if (parameters.subscribers.length > this._maxBatchSize) {
50
- throw new TooManySubscribersError(
51
- `You must send between 1 and 1,000 subscribers.`
52
- );
53
- }
54
-
55
- const result = await this._client.post<BatchImportSubscribersResponse>(
56
- `${this._url}/subscribers`,
57
- {
58
- subscribers: parameters.subscribers,
59
- }
42
+ if (parameters.subscribers.length === 0) {
43
+ throw new TooFewSubscribersError(
44
+ `You must send between 1 and 1,000 subscribers.`
60
45
  );
46
+ }
61
47
 
62
- return result.results;
63
- } catch (error) {
64
- throw error;
48
+ if (parameters.subscribers.length > this._maxBatchSize) {
49
+ throw new TooManySubscribersError(
50
+ `You must send between 1 and 1,000 subscribers.`
51
+ );
65
52
  }
53
+
54
+ const result = await this._client.post<BatchImportSubscribersResponse>(
55
+ `${this._url}/subscribers`,
56
+ {
57
+ subscribers: parameters.subscribers,
58
+ }
59
+ );
60
+
61
+ return result.results;
66
62
  }
67
63
 
68
64
  /**
@@ -79,29 +75,21 @@ export class BentoBatch<S, E> {
79
75
  public async importEvents(
80
76
  parameters: BatchImportEventsParameter<S, E>
81
77
  ): Promise<number> {
82
- try {
83
- if (parameters.events.length === 0) {
84
- throw new TooFewEventsError(
85
- `You must send between 1 and 1,000 events.`
86
- );
87
- }
78
+ if (parameters.events.length === 0) {
79
+ throw new TooFewEventsError(`You must send between 1 and 1,000 events.`);
80
+ }
88
81
 
89
- if (parameters.events.length > this._maxBatchSize) {
90
- throw new TooManyEventsError(
91
- `You must send between 1 and 1,000 events.`
92
- );
93
- }
82
+ if (parameters.events.length > this._maxBatchSize) {
83
+ throw new TooManyEventsError(`You must send between 1 and 1,000 events.`);
84
+ }
94
85
 
95
- const result = await this._client.post<BatchImportEventsResponse>(
96
- `${this._url}/events`,
97
- {
98
- events: parameters.events,
99
- }
100
- );
86
+ const result = await this._client.post<BatchImportEventsResponse>(
87
+ `${this._url}/events`,
88
+ {
89
+ events: parameters.events,
90
+ }
91
+ );
101
92
 
102
- return result.results;
103
- } catch (error) {
104
- throw error;
105
- }
93
+ return result.results;
106
94
  }
107
95
  }
@@ -1,4 +1,4 @@
1
- import { BentoEvent } from './events';
1
+ import type { BentoEvent } from './events';
2
2
 
3
3
  /**
4
4
  * Batch Method Parameter Types
@@ -9,7 +9,7 @@ export type BatchImportSubscribersParameter<S> = {
9
9
  } & Partial<S>)[];
10
10
  };
11
11
 
12
- export type BatchImportEventsParameter<S, E> = {
12
+ export type BatchImportEventsParameter<S, E extends string> = {
13
13
  events: BentoEvent<S, E>[];
14
14
  };
15
15
 
@@ -1,2 +1,13 @@
1
- export class NotAuthorizedError extends Error {}
2
- export class RateLimitedError extends Error {}
1
+ export class NotAuthorizedError extends Error {
2
+ constructor(message = 'Not authorized') {
3
+ super(message);
4
+ this.name = 'NotAuthorizedError';
5
+ }
6
+ }
7
+
8
+ export class RateLimitedError extends Error {
9
+ constructor(message = 'You are being rate limited') {
10
+ super(message);
11
+ this.name = 'RateLimitedError';
12
+ }
13
+ }