webflow-api 1.1.2 → 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 (70) hide show
  1. package/dist/api/collection.d.ts +85 -24
  2. package/dist/api/collection.js +88 -29
  3. package/dist/api/index.d.ts +7 -7
  4. package/dist/api/index.js +9 -19
  5. package/dist/api/item.d.ts +141 -107
  6. package/dist/api/item.js +145 -125
  7. package/dist/api/meta.d.ts +16 -14
  8. package/dist/api/meta.js +20 -19
  9. package/dist/api/oauth.d.ts +38 -36
  10. package/dist/api/oauth.js +59 -59
  11. package/dist/api/site.d.ts +118 -43
  12. package/dist/api/site.js +131 -53
  13. package/dist/{wrapper/membership.d.ts → api/user.d.ts} +59 -47
  14. package/dist/api/user.js +103 -0
  15. package/dist/api/webhook.d.ts +77 -55
  16. package/dist/api/webhook.js +74 -61
  17. package/dist/core/error.d.ts +2 -0
  18. package/dist/core/error.js +8 -1
  19. package/dist/core/index.d.ts +2 -2
  20. package/dist/core/index.js +2 -2
  21. package/dist/core/response.d.ts +32 -0
  22. package/dist/core/response.js +26 -0
  23. package/dist/{webflow.d.ts → core/webflow.d.ts} +56 -59
  24. package/dist/{webflow.js → core/webflow.js} +101 -68
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +2 -2
  27. package/package.json +2 -4
  28. package/src/api/collection.ts +102 -35
  29. package/src/api/index.ts +7 -7
  30. package/src/api/item.ts +207 -176
  31. package/src/api/meta.ts +19 -18
  32. package/src/api/oauth.ts +62 -74
  33. package/src/api/site.ts +158 -55
  34. package/src/api/user.ts +152 -0
  35. package/src/api/webhook.ts +97 -80
  36. package/src/core/error.ts +8 -0
  37. package/src/core/index.ts +2 -2
  38. package/src/core/response.ts +50 -0
  39. package/src/{webflow.ts → core/webflow.ts} +131 -145
  40. package/src/index.ts +1 -1
  41. package/yarn.lock +0 -5
  42. package/dist/api/membership.d.ts +0 -114
  43. package/dist/api/membership.js +0 -96
  44. package/dist/core/client.d.ts +0 -27
  45. package/dist/core/client.js +0 -60
  46. package/dist/core/options.d.ts +0 -8
  47. package/dist/core/options.js +0 -5
  48. package/dist/wrapper/collection.d.ts +0 -85
  49. package/dist/wrapper/collection.js +0 -94
  50. package/dist/wrapper/index.d.ts +0 -6
  51. package/dist/wrapper/index.js +0 -22
  52. package/dist/wrapper/item.d.ts +0 -140
  53. package/dist/wrapper/item.js +0 -153
  54. package/dist/wrapper/membership.js +0 -123
  55. package/dist/wrapper/response.d.ts +0 -16
  56. package/dist/wrapper/response.js +0 -17
  57. package/dist/wrapper/site.d.ts +0 -168
  58. package/dist/wrapper/site.js +0 -191
  59. package/dist/wrapper/webhook.d.ts +0 -78
  60. package/dist/wrapper/webhook.js +0 -82
  61. package/src/api/membership.ts +0 -155
  62. package/src/core/client.ts +0 -82
  63. package/src/core/options.ts +0 -9
  64. package/src/wrapper/collection.ts +0 -115
  65. package/src/wrapper/index.ts +0 -6
  66. package/src/wrapper/item.ts +0 -218
  67. package/src/wrapper/membership.ts +0 -163
  68. package/src/wrapper/response.ts +0 -25
  69. package/src/wrapper/site.ts +0 -228
  70. package/src/wrapper/webhook.ts +0 -116
@@ -1,78 +0,0 @@
1
- import { Client, QueryString } from "../core";
2
- import { Webhook } from "../api";
3
- export declare type CreateWebhookParams = {
4
- url: string;
5
- siteId: string;
6
- triggerType: string;
7
- filter?: Webhook.Filter;
8
- };
9
- export declare class WebhookWrapper implements Webhook.IWebhook {
10
- private client;
11
- triggerType: Webhook.TriggerType;
12
- triggerId: string;
13
- createdOn: string;
14
- lastUsed?: string;
15
- site: string;
16
- _id: string;
17
- filter?: {
18
- name: string;
19
- };
20
- constructor(client: Client, webhook: Webhook.IWebhook);
21
- /**************************************************************
22
- * Static Methods
23
- **************************************************************/
24
- /**
25
- * Get a Webhook
26
- * @param client The Webflow client
27
- * @param params The Webhook params
28
- * @param params.siteId The Site ID
29
- * @param params.webhookId The Webhook ID
30
- * @returns The Webhook
31
- */
32
- static getOne(client: Client, { siteId, webhookId }: {
33
- siteId: string;
34
- webhookId: string;
35
- }): Promise<import("./response").MetaResponse<WebhookWrapper>>;
36
- /**
37
- * List Webhooks
38
- * @param client The Webflow client
39
- * @param param1 The Webhook params
40
- * @param param1.siteId The Site ID
41
- * @param params Query string params (optional)
42
- * @returns A list of Webhooks
43
- */
44
- static list(client: Client, { siteId }: {
45
- siteId: string;
46
- }, params?: QueryString): Promise<import("./response").MetaResponse<WebhookWrapper[]>>;
47
- /**
48
- * Remove a Webhook
49
- * @param client The Webflow client
50
- * @param params The Webhook params
51
- * @param params.siteId The Site ID
52
- * @param params.webhookId The Webhook ID
53
- * @returns The result of the removal
54
- */
55
- static remove(client: Client, { siteId, webhookId }: {
56
- siteId: string;
57
- webhookId: string;
58
- }): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
59
- /**
60
- * Create a Webhook
61
- * @param client The Webflow client
62
- * @param param1 The Webhook params
63
- * @param param1.siteId The Site ID
64
- * @param param1.url The URL to send the Webhook to
65
- * @param param1.triggerType The event to trigger the Webhook
66
- * @param param1.filter The filter to use (optional: form_submission only)
67
- * @returns The created Webhook
68
- */
69
- static create(client: Client, { triggerType, siteId, filter, url }: CreateWebhookParams): Promise<import("./response").MetaResponse<WebhookWrapper>>;
70
- /**************************************************************
71
- * Instance Methods
72
- **************************************************************/
73
- /**
74
- * Remove a Webhook
75
- * @returns The result of the removal
76
- */
77
- remove(): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
78
- }
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookWrapper = void 0;
4
- const _1 = require(".");
5
- const api_1 = require("../api");
6
- class WebhookWrapper {
7
- constructor(client, webhook) {
8
- this.client = client;
9
- Object.assign(this, webhook);
10
- }
11
- /**************************************************************
12
- * Static Methods
13
- **************************************************************/
14
- /**
15
- * Get a Webhook
16
- * @param client The Webflow client
17
- * @param params The Webhook params
18
- * @param params.siteId The Site ID
19
- * @param params.webhookId The Webhook ID
20
- * @returns The Webhook
21
- */
22
- static async getOne(client, { siteId, webhookId }) {
23
- const res = await api_1.Webhook.getOne(client, { siteId, webhookId });
24
- const webhook = new WebhookWrapper(client, res.data);
25
- return (0, _1.ResponseWrapper)(res, webhook);
26
- }
27
- /**
28
- * List Webhooks
29
- * @param client The Webflow client
30
- * @param param1 The Webhook params
31
- * @param param1.siteId The Site ID
32
- * @param params Query string params (optional)
33
- * @returns A list of Webhooks
34
- */
35
- static async list(client, { siteId }, params) {
36
- const res = await api_1.Webhook.list(client, { siteId }, params);
37
- const webhooks = res.data.map((w) => new WebhookWrapper(client, w));
38
- return (0, _1.ResponseWrapper)(res, webhooks);
39
- }
40
- /**
41
- * Remove a Webhook
42
- * @param client The Webflow client
43
- * @param params The Webhook params
44
- * @param params.siteId The Site ID
45
- * @param params.webhookId The Webhook ID
46
- * @returns The result of the removal
47
- */
48
- static async remove(client, { siteId, webhookId }) {
49
- const res = await api_1.Webhook.remove(client, { siteId, webhookId });
50
- return (0, _1.ResponseWrapper)(res);
51
- }
52
- /**
53
- * Create a Webhook
54
- * @param client The Webflow client
55
- * @param param1 The Webhook params
56
- * @param param1.siteId The Site ID
57
- * @param param1.url The URL to send the Webhook to
58
- * @param param1.triggerType The event to trigger the Webhook
59
- * @param param1.filter The filter to use (optional: form_submission only)
60
- * @returns The created Webhook
61
- */
62
- static async create(client, { triggerType, siteId, filter, url }) {
63
- const args = { triggerType, siteId, filter, url };
64
- const res = await api_1.Webhook.create(client, args);
65
- const _webhook = new WebhookWrapper(client, res.data);
66
- return (0, _1.ResponseWrapper)(res, _webhook);
67
- }
68
- /**************************************************************
69
- * Instance Methods
70
- **************************************************************/
71
- /**
72
- * Remove a Webhook
73
- * @returns The result of the removal
74
- */
75
- async remove() {
76
- return WebhookWrapper.remove(this.client, {
77
- webhookId: this._id,
78
- siteId: this.site,
79
- });
80
- }
81
- }
82
- exports.WebhookWrapper = WebhookWrapper;
@@ -1,155 +0,0 @@
1
- import { Client, PaginatedData, requireArgs } from "../core";
2
-
3
- /**************************************************************
4
- * Interfaces
5
- **************************************************************/
6
- export interface IUser {
7
- emailVerified: boolean;
8
- lastUpdated?: string;
9
- createdOn: string;
10
- _id: string;
11
- data: any;
12
- }
13
-
14
- export interface IAccessGroup {
15
- _id: string;
16
- name: string;
17
- shortId: string;
18
- slug: string;
19
- createdOn: string;
20
- }
21
-
22
- export interface IUserDelete {
23
- deleted: number;
24
- }
25
-
26
- /**************************************************************
27
- * Types
28
- **************************************************************/
29
- export type PaginatedUsers = PaginatedData & {
30
- users: IUser[];
31
- };
32
-
33
- export type PaginatedAccessGroups = PaginatedData & {
34
- accessGroups: IAccessGroup[];
35
- };
36
-
37
- export type UserIdParam = { siteId: string; userId: string };
38
-
39
- /**************************************************************
40
- * Functions
41
- **************************************************************/
42
-
43
- /**
44
- * Get a list of Users
45
- * @param client The Webflow client
46
- * @param params The params for the request
47
- * @param params.siteId The site ID
48
- * @param params.limit The number of items to return (optional)
49
- * @param params.offset The number of items to skip (optional)
50
- * @returns A list of Users
51
- */
52
- export function list(
53
- client: Client,
54
- { siteId, limit, offset }: { siteId: string; limit?: number; offset?: number }
55
- ) {
56
- requireArgs({ siteId });
57
- const params = { limit, offset };
58
- const path = `/sites/${siteId}/users`;
59
- return client.get<PaginatedUsers>(path, { params });
60
- }
61
-
62
- /**
63
- * Get a single User
64
- * @param client The Webflow client
65
- * @param params The params for the request
66
- * @param params.siteId The site ID
67
- * @param params.userId The user ID
68
- * @returns A single User
69
- */
70
- export function getOne(
71
- client: Client,
72
- { siteId, userId }: { siteId: string; userId: string }
73
- ) {
74
- requireArgs({ siteId, userId });
75
- const path = `/sites/${siteId}/users/${userId}`;
76
- return client.get<IUser>(path);
77
- }
78
-
79
- /**
80
- * Update a User
81
- * @param client The Webflow client
82
- * @param params The params for the request
83
- * @param params.siteId The site ID
84
- * @param params.userId The user ID
85
- * @param params.data The data to update
86
- * @returns The updated User
87
- */
88
- export function update(
89
- client: Client,
90
- {
91
- siteId,
92
- userId,
93
- ...data
94
- }: {
95
- siteId: string;
96
- userId: string;
97
- }
98
- ) {
99
- requireArgs({ siteId, userId });
100
- const path = `/sites/${siteId}/users/${userId}`;
101
- return client.patch<IUser>(path, data);
102
- }
103
-
104
- /**
105
- * Invite a User to a site
106
- * @param client The Webflow client
107
- * @param params The params for the request
108
- * @param params.siteId The site ID
109
- * @param params.email The email address of the user to invite
110
- * @returns The newly created User
111
- */
112
- export async function invite(
113
- client: Client,
114
- { siteId, email }: { siteId: string; email: string }
115
- ) {
116
- requireArgs({ siteId, email });
117
- const path = `/sites/${siteId}/users/invite`;
118
- return client.post<IUser>(path, { email });
119
- }
120
-
121
- /**
122
- * Remove a User
123
- * @param client The Webflow client
124
- * @param params The params for the request
125
- * @param params.siteId The site ID
126
- * @param params.userId The user ID
127
- * @returns The result of the remove
128
- */
129
- export function remove(
130
- client: Client,
131
- { siteId, userId }: { siteId: string; userId: string }
132
- ) {
133
- requireArgs({ siteId, userId });
134
- const path = `/sites/${siteId}/users/${userId}`;
135
- return client.delete<IUserDelete>(path);
136
- }
137
-
138
- /**
139
- * Get a list of Access Groups
140
- * @param client The Webflow client
141
- * @param params The params for the request
142
- * @param params.siteId The Site ID
143
- * @param params.limit The number of items to return (optional)
144
- * @param params.offset The number of items to skip (optional)
145
- * @returns A list of Access Groups
146
- */
147
- export function accessGroups(
148
- client: Client,
149
- { siteId, limit, offset }: { siteId: string; limit?: number; offset?: number }
150
- ) {
151
- requireArgs({ siteId });
152
- const params = { limit, offset };
153
- const path = `/sites/${siteId}/users/accessgroups`;
154
- return client.get<PaginatedAccessGroups>(path, { params });
155
- }
@@ -1,82 +0,0 @@
1
- import { Axios } from "axios";
2
- import { DEFAULT_HOST, USER_AGENT, Options, RequestError } from "../core";
3
-
4
- /**************************************************************
5
- * Types
6
- **************************************************************/
7
- export type QueryString = Record<string, any>;
8
- export type PaginationFilter = { limit?: number; offset?: number };
9
-
10
- /**************************************************************
11
- * Interfaces
12
- ************************************************************* */
13
- export interface PaginatedData {
14
- count: number;
15
- limit: number;
16
- offset: number;
17
- total: number;
18
- }
19
-
20
- /**************************************************************
21
- * Functions
22
- **************************************************************/
23
-
24
- /**
25
- * Transforms JSON response to an object
26
- * if the response is a Webflow error, it will throw an error
27
- * @param data JSON response
28
- * @returns response object
29
- */
30
- function transformResponse(data: any = {}) {
31
- // parse json if string
32
- if (String(data) === data) data = JSON.parse(data);
33
-
34
- // throw an error if Webflow returns an error obejct
35
- if (data.err) throw new RequestError(data);
36
- return data;
37
- }
38
-
39
- /**
40
- * Transforms POST/PUT/PATCH request data to JSON
41
- * @param data A JavaScript object
42
- * @returns JSON string
43
- */
44
- function transformRequest(data: any = {}) {
45
- return JSON.stringify(data);
46
- }
47
-
48
- /**************************************************************
49
- * Classes
50
- **************************************************************/
51
- export class Client extends Axios {
52
- constructor({
53
- host = DEFAULT_HOST,
54
- headers = {},
55
- version,
56
- token,
57
- }: Options = {}) {
58
- super({
59
- transformRequest: [transformRequest],
60
- transformResponse: [transformResponse],
61
- baseURL: `https://api.${host}/`,
62
- headers: {
63
- "Content-Type": "application/json",
64
- "User-Agent": USER_AGENT,
65
- "Accept-Version": version,
66
- ...headers,
67
- },
68
- });
69
-
70
- if (token) this.token = token;
71
- }
72
-
73
- // set the Authorization header
74
- set token(value: string) {
75
- this.defaults.headers["Authorization"] = `Bearer ${value}`;
76
- }
77
-
78
- // clear the Authorization header
79
- clearToken() {
80
- delete this.defaults.headers["Authorization"];
81
- }
82
- }
@@ -1,9 +0,0 @@
1
- export const DEFAULT_HOST = "webflow.com";
2
- export const USER_AGENT = "Webflow Javascript SDK / 1.0";
3
-
4
- export interface Options {
5
- host?: string;
6
- token?: string;
7
- version?: string;
8
- headers?: Record<string, string>;
9
- }
@@ -1,115 +0,0 @@
1
- import { ResponseWrapper, ItemWrapper } from ".";
2
- import { Client, QueryString } from "../core";
3
- import { Collection } from "../api";
4
-
5
- export class CollectionWrapper implements Collection.ICollection {
6
- fields: Collection.CollectionField[];
7
- singularName: string;
8
- lastUpdated: string;
9
- createdOn: string;
10
- _id: string;
11
- name: string;
12
- slug: string;
13
-
14
- constructor(private client: Client, collection: Collection.ICollection) {
15
- Object.assign(this, collection);
16
- }
17
-
18
- /**************************************************************
19
- * Static Methods
20
- **************************************************************/
21
-
22
- /**
23
- * Get a single Collection
24
- * @param client The Webflow client
25
- * @param params The Collection information
26
- * @param params.collectionId The Collection ID
27
- * @returns A single Collection
28
- */
29
- static async getOne(
30
- client: Client,
31
- { collectionId }: { collectionId: string }
32
- ) {
33
- const res = await Collection.getOne(client, { collectionId });
34
- const collection = new CollectionWrapper(client, res.data);
35
- return ResponseWrapper<typeof collection>(res, collection);
36
- }
37
-
38
- /**
39
- * Get a list of Collections
40
- * @param client The Webflow client
41
- * @param params1 The Site information
42
- * @param params1.siteId The Site ID
43
- * @param params The query parameters (optional)
44
- * @returns A list of Collections
45
- */
46
- static async list(
47
- client: Client,
48
- { siteId }: { siteId: string },
49
- params?: QueryString
50
- ) {
51
- const res = await Collection.list(client, { siteId }, params);
52
- const collections = res.data.map((c) => new CollectionWrapper(client, c));
53
- return ResponseWrapper<typeof collections>(res, collections);
54
- }
55
-
56
- /**************************************************************
57
- * Instance Methods
58
- **************************************************************/
59
-
60
- /**
61
- * Get a single Item
62
- * @param params The params for the request
63
- * @param params.itemId The Item ID
64
- * @returns A single Item
65
- */
66
- async item({ itemId }: { itemId: string }) {
67
- return ItemWrapper.getOne(this.client, { itemId, collectionId: this._id });
68
- }
69
-
70
- /**
71
- * Get a list of Items
72
- * @param params The params for the request
73
- * @param params.limit The number of items to return (optional)
74
- * @param params.offset The number of items to skip (optional)
75
- * @returns A list of Items
76
- */
77
- async items(params?: QueryString) {
78
- return ItemWrapper.list(this.client, { collectionId: this._id, ...params });
79
- }
80
-
81
- /**
82
- * Remove a single Item
83
- * @param params The params for the request
84
- * @param params.itemId The Item ID
85
- * @returns The result from the removal
86
- */
87
- async removeItem({ itemId }: { itemId: string }) {
88
- return ItemWrapper.remove(this.client, { itemId, collectionId: this._id });
89
- }
90
-
91
- /**
92
- * Create a new Item
93
- * @param params The params for the request
94
- * @param params.fields The Item fields to create
95
- * @returns The created Item
96
- */
97
- async createItem(fields: any) {
98
- return ItemWrapper.create(this.client, { collectionId: this._id, fields });
99
- }
100
-
101
- /**
102
- * Update a single Item
103
- * @param params The params for the request
104
- * @param params.itemId The Item ID
105
- * @param params.fields The fields to update
106
- * @returns The updated Item
107
- */
108
- async updateItem({ itemId, fields }: { itemId: string; fields: any }) {
109
- return ItemWrapper.update(this.client, {
110
- collectionId: this._id,
111
- itemId,
112
- fields,
113
- });
114
- }
115
- }
@@ -1,6 +0,0 @@
1
- export * from "./membership";
2
- export * from "./collection";
3
- export * from "./response";
4
- export * from "./webhook";
5
- export * from "./site";
6
- export * from "./item";