webflow-api 1.3.0 → 1.3.1

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 (54) hide show
  1. package/dist/api/collection.d.ts +112 -0
  2. package/dist/api/collection.js +94 -0
  3. package/dist/api/index.d.ts +7 -0
  4. package/dist/api/index.js +23 -0
  5. package/dist/api/item.d.ts +177 -0
  6. package/dist/api/item.js +151 -0
  7. package/dist/api/meta.d.ts +53 -0
  8. package/dist/api/meta.js +25 -0
  9. package/dist/api/oauth.d.ts +71 -0
  10. package/dist/api/oauth.js +71 -0
  11. package/dist/api/site.d.ts +140 -0
  12. package/dist/api/site.js +137 -0
  13. package/dist/api/user.d.ts +143 -0
  14. package/dist/api/user.js +119 -0
  15. package/dist/api/webhook.d.ts +102 -0
  16. package/dist/api/webhook.js +80 -0
  17. package/dist/core/error.d.ts +21 -0
  18. package/dist/core/error.js +30 -0
  19. package/dist/core/index.d.ts +3 -0
  20. package/dist/core/index.js +19 -0
  21. package/dist/core/response.d.ts +32 -0
  22. package/dist/core/response.js +26 -0
  23. package/dist/core/webflow.d.ts +390 -0
  24. package/dist/core/webflow.js +518 -0
  25. package/dist/index.d.ts +2 -0
  26. package/package.json +7 -1
  27. package/yarn.lock +2840 -0
  28. package/.eslintrc +0 -31
  29. package/.github/workflows/code-quality.yml +0 -102
  30. package/.github/workflows/npm-publish.yml +0 -21
  31. package/.github/workflows/semgrep.yml +0 -24
  32. package/.prettierignore +0 -5
  33. package/.prettierrc +0 -6
  34. package/jest.config.js +0 -17
  35. package/tests/api/collection.test.ts +0 -147
  36. package/tests/api/item.test.ts +0 -180
  37. package/tests/api/meta.test.ts +0 -38
  38. package/tests/api/oauth.test.ts +0 -44
  39. package/tests/api/site.test.ts +0 -202
  40. package/tests/api/user.test.ts +0 -139
  41. package/tests/api/webhook.test.ts +0 -82
  42. package/tests/core/error.test.ts +0 -19
  43. package/tests/core/response.test.ts +0 -36
  44. package/tests/core/webflow.test.ts +0 -540
  45. package/tests/fixtures/collection.fixture.ts +0 -374
  46. package/tests/fixtures/index.ts +0 -7
  47. package/tests/fixtures/item.fixture.ts +0 -193
  48. package/tests/fixtures/meta.fixture.ts +0 -34
  49. package/tests/fixtures/oauth.fixture.ts +0 -38
  50. package/tests/fixtures/site.fixture.ts +0 -78
  51. package/tests/fixtures/user.fixture.ts +0 -175
  52. package/tests/fixtures/webhook.fixture.ts +0 -69
  53. package/tsconfig.eslint.json +0 -7
  54. package/tsconfig.json +0 -14
@@ -0,0 +1,102 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { WebflowRecord } from "../core";
3
+ /**************************************************************
4
+ * Types
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;
7
+ export declare type WebhookFilter = {
8
+ name: string;
9
+ };
10
+ /**************************************************************
11
+ * Interfaces
12
+ **************************************************************/
13
+ export interface IWebhook {
14
+ triggerType: TriggerType;
15
+ triggerId: string;
16
+ createdOn: string;
17
+ lastUsed?: string;
18
+ site: string;
19
+ _id: string;
20
+ filter?: {
21
+ name: string;
22
+ };
23
+ }
24
+ export interface IRemoveResult {
25
+ deleted: number;
26
+ }
27
+ /**************************************************************
28
+ * Class
29
+ **************************************************************/
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
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webhook = void 0;
4
+ const core_1 = require("../core");
5
+ /**************************************************************
6
+ * Class
7
+ **************************************************************/
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
+ }
79
+ }
80
+ exports.Webhook = Webhook;
@@ -0,0 +1,21 @@
1
+ import { AxiosResponse } from "axios";
2
+ export interface IRequestError {
3
+ msg: string;
4
+ code: number;
5
+ name: string;
6
+ path: string;
7
+ err: string;
8
+ }
9
+ export declare class RequestError extends Error implements IRequestError {
10
+ msg: string;
11
+ code: number;
12
+ name: string;
13
+ path: string;
14
+ err: string;
15
+ constructor(error: IRequestError);
16
+ }
17
+ export declare class ArgumentError extends Error {
18
+ constructor(name: string);
19
+ }
20
+ export declare function requireArgs(args: object): void;
21
+ export declare function ErrorInterceptor(res: AxiosResponse<IRequestError>): AxiosResponse<IRequestError, any>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorInterceptor = exports.requireArgs = exports.ArgumentError = exports.RequestError = void 0;
4
+ class RequestError extends Error {
5
+ constructor(error) {
6
+ super(error.err ? error.err : "Unknown error occurred");
7
+ Object.assign(this, error);
8
+ }
9
+ }
10
+ exports.RequestError = RequestError;
11
+ class ArgumentError extends Error {
12
+ constructor(name) {
13
+ super(`Argument '${name}' is required but was not present`);
14
+ }
15
+ }
16
+ exports.ArgumentError = ArgumentError;
17
+ function requireArgs(args) {
18
+ for (const key in args) {
19
+ if (!args[key])
20
+ throw new ArgumentError(key);
21
+ }
22
+ }
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;
@@ -0,0 +1,3 @@
1
+ export * from "./error";
2
+ export * from "./response";
3
+ export * from "./webflow";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./error"), 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;