webflow-api 1.1.1 → 1.2.0

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 (71) hide show
  1. package/README.md +12 -1
  2. package/dist/api/collection.d.ts +85 -24
  3. package/dist/api/collection.js +88 -29
  4. package/dist/api/index.d.ts +7 -7
  5. package/dist/api/index.js +9 -19
  6. package/dist/api/item.d.ts +141 -107
  7. package/dist/api/item.js +145 -125
  8. package/dist/api/meta.d.ts +16 -14
  9. package/dist/api/meta.js +20 -19
  10. package/dist/api/oauth.d.ts +38 -36
  11. package/dist/api/oauth.js +59 -59
  12. package/dist/api/site.d.ts +118 -43
  13. package/dist/api/site.js +131 -53
  14. package/dist/{wrapper/membership.d.ts → api/user.d.ts} +59 -33
  15. package/dist/api/user.js +103 -0
  16. package/dist/api/webhook.d.ts +77 -55
  17. package/dist/api/webhook.js +74 -61
  18. package/dist/core/error.d.ts +2 -0
  19. package/dist/core/error.js +8 -1
  20. package/dist/core/index.d.ts +2 -2
  21. package/dist/core/index.js +2 -2
  22. package/dist/core/response.d.ts +32 -0
  23. package/dist/core/response.js +26 -0
  24. package/dist/{webflow.d.ts → core/webflow.d.ts} +57 -52
  25. package/dist/{webflow.js → core/webflow.js} +102 -61
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +2 -2
  28. package/package.json +2 -4
  29. package/src/api/collection.ts +102 -35
  30. package/src/api/index.ts +7 -7
  31. package/src/api/item.ts +207 -176
  32. package/src/api/meta.ts +19 -18
  33. package/src/api/oauth.ts +62 -74
  34. package/src/api/site.ts +158 -55
  35. package/src/api/user.ts +152 -0
  36. package/src/api/webhook.ts +97 -80
  37. package/src/core/error.ts +8 -0
  38. package/src/core/index.ts +2 -2
  39. package/src/core/response.ts +50 -0
  40. package/src/{webflow.ts → core/webflow.ts} +132 -137
  41. package/src/index.ts +1 -1
  42. package/yarn.lock +0 -5
  43. package/dist/api/membership.d.ts +0 -91
  44. package/dist/api/membership.js +0 -80
  45. package/dist/core/client.d.ts +0 -40
  46. package/dist/core/client.js +0 -49
  47. package/dist/core/options.d.ts +0 -8
  48. package/dist/core/options.js +0 -5
  49. package/dist/wrapper/collection.d.ts +0 -85
  50. package/dist/wrapper/collection.js +0 -94
  51. package/dist/wrapper/index.d.ts +0 -6
  52. package/dist/wrapper/index.js +0 -22
  53. package/dist/wrapper/item.d.ts +0 -140
  54. package/dist/wrapper/item.js +0 -153
  55. package/dist/wrapper/membership.js +0 -106
  56. package/dist/wrapper/response.d.ts +0 -16
  57. package/dist/wrapper/response.js +0 -17
  58. package/dist/wrapper/site.d.ts +0 -119
  59. package/dist/wrapper/site.js +0 -136
  60. package/dist/wrapper/webhook.d.ts +0 -78
  61. package/dist/wrapper/webhook.js +0 -82
  62. package/src/api/membership.ts +0 -125
  63. package/src/core/client.ts +0 -76
  64. package/src/core/options.ts +0 -9
  65. package/src/wrapper/collection.ts +0 -115
  66. package/src/wrapper/index.ts +0 -6
  67. package/src/wrapper/item.ts +0 -218
  68. package/src/wrapper/membership.ts +0 -138
  69. package/src/wrapper/response.ts +0 -25
  70. package/src/wrapper/site.ts +0 -164
  71. package/src/wrapper/webhook.ts +0 -116
@@ -1,9 +1,10 @@
1
- import { Client, QueryString } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { WebflowRecord } from "../core";
2
3
  /**************************************************************
3
4
  * Types
4
5
  **************************************************************/
5
6
  export declare type TriggerType = "form_submission" | "site_publish" | "ecomm_new_order" | "ecomm_order_changed" | "ecomm_inventory_changed" | "collection_item_created" | "collection_item_changed" | "collection_item_deleted" | string;
6
- export declare type Filter = {
7
+ export declare type WebhookFilter = {
7
8
  name: string;
8
9
  };
9
10
  /**************************************************************
@@ -24,57 +25,78 @@ export interface IRemoveResult {
24
25
  deleted: number;
25
26
  }
26
27
  /**************************************************************
27
- * Functions
28
+ * Class
28
29
  **************************************************************/
29
- /**
30
- * Get a list of Webhooks
31
- * @param client The Webflow client
32
- * @param params1 The params for the request
33
- * @param params1.siteId The site ID
34
- * @param params The query string parameters (optional)
35
- * @returns A list of Webhooks
36
- */
37
- export declare function list(client: Client, { siteId }: {
38
- siteId: string;
39
- }, params?: QueryString): Promise<import("axios").AxiosResponse<IWebhook[], any>>;
40
- /**
41
- * Get a single Webhook
42
- * @param client The Webflow client
43
- * @param params The params for the request
44
- * @param params.siteId The site ID
45
- * @param params.webhookId The webhook ID
46
- * @returns A single Webhook
47
- */
48
- export declare function getOne(client: Client, { siteId, webhookId }: {
49
- siteId: string;
50
- webhookId: string;
51
- }): Promise<import("axios").AxiosResponse<IWebhook, any>>;
52
- /**
53
- * Create a new Webhook
54
- * @param client The Webflow client
55
- * @param params The params for the request
56
- * @param params.siteId The site ID
57
- * @param params.url The URL to send the webhook to
58
- * @param params.triggerType The event to trigger the webhook
59
- * @param params.filter The filter to apply to the webhook (optional: form_submission only)
60
- * @param params.params The query string parameters (optional)
61
- * @returns The created webhook
62
- */
63
- export declare function create(client: Client, { triggerType, siteId, filter, url, }: {
64
- url: string;
65
- siteId: string;
66
- filter?: Filter;
67
- triggerType: TriggerType;
68
- }): Promise<import("axios").AxiosResponse<IWebhook, any>>;
69
- /**
70
- * Remove a Webhook
71
- * @param client The Webflow client
72
- * @param params The query string parameters (optional)
73
- * @param params.webhookId The Webhook ID
74
- * @param params.siteId The Site ID
75
- * @returns The result of the removal
76
- */
77
- export declare function remove(client: Client, { siteId, webhookId }: {
78
- siteId: string;
79
- webhookId: string;
80
- }): Promise<import("axios").AxiosResponse<IRemoveResult, any>>;
30
+ export declare class Webhook extends WebflowRecord<IWebhook> implements IWebhook {
31
+ filter?: {
32
+ name: string;
33
+ };
34
+ triggerType: string;
35
+ triggerId: string;
36
+ createdOn: string;
37
+ lastUsed?: string;
38
+ site: string;
39
+ _id: string;
40
+ /**************************************************************
41
+ * Static Methods
42
+ **************************************************************/
43
+ /**
44
+ * Get a list of Webhooks
45
+ * @param params The params for the request
46
+ * @param params.siteId The site ID
47
+ * @param client The Axios client instance
48
+ * @returns A list of Webhooks
49
+ */
50
+ static list({ siteId }: {
51
+ siteId: string;
52
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IWebhook[], any>>;
53
+ /**
54
+ * Get a single Webhook
55
+ * @param params The params for the request
56
+ * @param params.siteId The site ID
57
+ * @param params.webhookId The webhook ID
58
+ * @param client The Axios client instance
59
+ * @returns A single Webhook
60
+ */
61
+ static getOne({ siteId, webhookId }: {
62
+ siteId: string;
63
+ webhookId: string;
64
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IWebhook, any>>;
65
+ /**
66
+ * Create a new Webhook
67
+ * @param params The params for the request
68
+ * @param params.siteId The site ID
69
+ * @param params.url The URL to send the webhook to
70
+ * @param params.triggerType The event to trigger the webhook
71
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
72
+ * @param params.params The query string parameters (optional)
73
+ * @param client The Axios client instance
74
+ * @returns The created webhook
75
+ */
76
+ static create({ triggerType, siteId, filter, url, }: {
77
+ url: string;
78
+ siteId: string;
79
+ filter?: WebhookFilter;
80
+ triggerType: TriggerType;
81
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IWebhook, any>>;
82
+ /**
83
+ * Remove a Webhook
84
+ * @param params The query string parameters (optional)
85
+ * @param params.webhookId The Webhook ID
86
+ * @param params.siteId The Site ID
87
+ * @param client The Axios client instance
88
+ * @returns The result of the removal
89
+ */
90
+ static remove({ siteId, webhookId }: {
91
+ siteId: string;
92
+ webhookId: string;
93
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IRemoveResult, any>>;
94
+ /**************************************************************
95
+ * Instance Methods
96
+ **************************************************************/
97
+ /**
98
+ * Remove a Webhook
99
+ * @returns The result of the removal
100
+ */
101
+ remove(): Promise<IRemoveResult>;
102
+ }
@@ -1,67 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.remove = exports.create = exports.getOne = exports.list = void 0;
3
+ exports.Webhook = void 0;
4
4
  const core_1 = require("../core");
5
5
  /**************************************************************
6
- * Functions
6
+ * Class
7
7
  **************************************************************/
8
- /**
9
- * Get a list of Webhooks
10
- * @param client The Webflow client
11
- * @param params1 The params for the request
12
- * @param params1.siteId The site ID
13
- * @param params The query string parameters (optional)
14
- * @returns A list of Webhooks
15
- */
16
- function list(client, { siteId }, params) {
17
- (0, core_1.requireArgs)({ siteId });
18
- const path = `/sites/${siteId}/webhooks`;
19
- return client.get(path, { params });
8
+ class Webhook extends core_1.WebflowRecord {
9
+ /**************************************************************
10
+ * Static Methods
11
+ **************************************************************/
12
+ /**
13
+ * Get a list of Webhooks
14
+ * @param params The params for the request
15
+ * @param params.siteId The site ID
16
+ * @param client The Axios client instance
17
+ * @returns A list of Webhooks
18
+ */
19
+ static list({ siteId }, client) {
20
+ (0, core_1.requireArgs)({ siteId });
21
+ const path = `/sites/${siteId}/webhooks`;
22
+ return client.get(path);
23
+ }
24
+ /**
25
+ * Get a single Webhook
26
+ * @param params The params for the request
27
+ * @param params.siteId The site ID
28
+ * @param params.webhookId The webhook ID
29
+ * @param client The Axios client instance
30
+ * @returns A single Webhook
31
+ */
32
+ static getOne({ siteId, webhookId }, client) {
33
+ (0, core_1.requireArgs)({ siteId, webhookId });
34
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
35
+ return client.get(path);
36
+ }
37
+ /**
38
+ * Create a new Webhook
39
+ * @param params The params for the request
40
+ * @param params.siteId The site ID
41
+ * @param params.url The URL to send the webhook to
42
+ * @param params.triggerType The event to trigger the webhook
43
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
44
+ * @param params.params The query string parameters (optional)
45
+ * @param client The Axios client instance
46
+ * @returns The created webhook
47
+ */
48
+ static create({ triggerType, siteId, filter, url, }, client) {
49
+ (0, core_1.requireArgs)({ siteId, triggerType, url });
50
+ const path = `/sites/${siteId}/webhooks`;
51
+ const data = { triggerType, url, filter };
52
+ return client.post(path, data);
53
+ }
54
+ /**
55
+ * Remove a Webhook
56
+ * @param params The query string parameters (optional)
57
+ * @param params.webhookId The Webhook ID
58
+ * @param params.siteId The Site ID
59
+ * @param client The Axios client instance
60
+ * @returns The result of the removal
61
+ */
62
+ static remove({ siteId, webhookId }, client) {
63
+ (0, core_1.requireArgs)({ siteId, webhookId });
64
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
65
+ return client.delete(path);
66
+ }
67
+ /**************************************************************
68
+ * Instance Methods
69
+ **************************************************************/
70
+ /**
71
+ * Remove a Webhook
72
+ * @returns The result of the removal
73
+ */
74
+ async remove() {
75
+ const params = { siteId: this.site, webhookId: this._id };
76
+ const res = await Webhook.remove(params, this.client);
77
+ return res.data;
78
+ }
20
79
  }
21
- exports.list = list;
22
- /**
23
- * Get a single Webhook
24
- * @param client The Webflow client
25
- * @param params The params for the request
26
- * @param params.siteId The site ID
27
- * @param params.webhookId The webhook ID
28
- * @returns A single Webhook
29
- */
30
- function getOne(client, { siteId, webhookId }) {
31
- (0, core_1.requireArgs)({ siteId, webhookId });
32
- const path = `/sites/${siteId}/webhooks/${webhookId}`;
33
- return client.get(path);
34
- }
35
- exports.getOne = getOne;
36
- /**
37
- * Create a new Webhook
38
- * @param client The Webflow client
39
- * @param params The params for the request
40
- * @param params.siteId The site ID
41
- * @param params.url The URL to send the webhook to
42
- * @param params.triggerType The event to trigger the webhook
43
- * @param params.filter The filter to apply to the webhook (optional: form_submission only)
44
- * @param params.params The query string parameters (optional)
45
- * @returns The created webhook
46
- */
47
- function create(client, { triggerType, siteId, filter, url, }) {
48
- (0, core_1.requireArgs)({ siteId, triggerType, url });
49
- const path = `/sites/${siteId}/webhooks`;
50
- const data = { triggerType, url, filter };
51
- return client.post(path, data);
52
- }
53
- exports.create = create;
54
- /**
55
- * Remove a Webhook
56
- * @param client The Webflow client
57
- * @param params The query string parameters (optional)
58
- * @param params.webhookId The Webhook ID
59
- * @param params.siteId The Site ID
60
- * @returns The result of the removal
61
- */
62
- function remove(client, { siteId, webhookId }) {
63
- (0, core_1.requireArgs)({ siteId, webhookId });
64
- const path = `/sites/${siteId}/webhooks/${webhookId}`;
65
- return client.delete(path);
66
- }
67
- exports.remove = remove;
80
+ exports.Webhook = Webhook;
@@ -1,3 +1,4 @@
1
+ import { AxiosResponse } from "axios";
1
2
  export interface IRequestError {
2
3
  msg: string;
3
4
  code: number;
@@ -17,3 +18,4 @@ export declare class ArgumentError extends Error {
17
18
  constructor(name: string);
18
19
  }
19
20
  export declare function requireArgs(args: object): void;
21
+ export declare function ErrorInterceptor(res: AxiosResponse): AxiosResponse<any, any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireArgs = exports.ArgumentError = exports.RequestError = void 0;
3
+ exports.ErrorInterceptor = exports.requireArgs = exports.ArgumentError = exports.RequestError = void 0;
4
4
  class RequestError extends Error {
5
5
  constructor(error) {
6
6
  super(error.err ? error.err : "Unknown error occured");
@@ -21,3 +21,10 @@ function requireArgs(args) {
21
21
  }
22
22
  }
23
23
  exports.requireArgs = requireArgs;
24
+ // throw an error if Webflow error
25
+ function ErrorInterceptor(res) {
26
+ if (res.data.err)
27
+ throw new RequestError(res.data);
28
+ return res;
29
+ }
30
+ exports.ErrorInterceptor = ErrorInterceptor;
@@ -1,3 +1,3 @@
1
- export * from "./client";
2
1
  export * from "./error";
3
- export * from "./options";
2
+ export * from "./response";
3
+ export * from "./webflow";
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./client"), exports);
18
17
  __exportStar(require("./error"), exports);
19
- __exportStar(require("./options"), exports);
18
+ __exportStar(require("./response"), exports);
19
+ __exportStar(require("./webflow"), exports);
@@ -0,0 +1,32 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+ /**************************************************************
3
+ * Types
4
+ **************************************************************/
5
+ export declare type PaginationFilter = {
6
+ limit?: number;
7
+ offset?: number;
8
+ };
9
+ export declare type WebflowHeaders = Record<string, any>;
10
+ /**************************************************************
11
+ * Interfaces
12
+ ************************************************************* */
13
+ export interface PaginatedData {
14
+ count: number;
15
+ limit: number;
16
+ offset: number;
17
+ total: number;
18
+ }
19
+ export declare class MetaResponse<T> {
20
+ response: AxiosResponse<T>;
21
+ rateLimit: {
22
+ limit: number;
23
+ remaining: number;
24
+ };
25
+ constructor(response: AxiosResponse<T>);
26
+ }
27
+ export declare class WebflowRecord<T> {
28
+ response: AxiosResponse<T>;
29
+ _meta: MetaResponse<T>;
30
+ client: AxiosInstance;
31
+ constructor(client: AxiosInstance, response: AxiosResponse<any>, record?: T, ...args: any[]);
32
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebflowRecord = exports.MetaResponse = void 0;
4
+ class MetaResponse {
5
+ constructor(response) {
6
+ this.response = response;
7
+ this.rateLimit = {
8
+ limit: parseInt(response.headers["x-ratelimit-limit"], 10),
9
+ remaining: parseInt(response.headers["x-ratelimit-remaining"], 10),
10
+ };
11
+ }
12
+ }
13
+ exports.MetaResponse = MetaResponse;
14
+ class WebflowRecord {
15
+ constructor(client, response, record, ...args) {
16
+ Object.assign(this, record || response.data, ...args); // Copy the record data
17
+ // dynamically add client and response to object
18
+ // without serializing during toString()
19
+ Object.defineProperties(this, {
20
+ client: { get: () => client },
21
+ response: { get: () => response },
22
+ _meta: { get: () => new MetaResponse(response) }, // legacy support
23
+ });
24
+ }
25
+ }
26
+ exports.WebflowRecord = WebflowRecord;