webflow-api 1.2.0 → 1.2.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.
- package/README.md +41 -17
- package/dist/api/collection.d.ts +3 -3
- package/dist/api/item.d.ts +1 -1
- package/dist/api/item.js +1 -1
- package/dist/api/oauth.d.ts +1 -1
- package/dist/api/oauth.js +1 -1
- package/dist/api/user.d.ts +26 -0
- package/dist/api/user.js +16 -0
- package/dist/core/error.d.ts +1 -1
- package/dist/core/webflow.d.ts +17 -2
- package/dist/core/webflow.js +18 -2
- package/package.json +12 -6
- package/src/api/collection.ts +3 -3
- package/src/api/item.ts +19 -9
- package/src/api/oauth.ts +13 -4
- package/src/api/site.ts +4 -1
- package/src/api/user.ts +42 -2
- package/src/api/webhook.ts +9 -3
- package/src/core/error.ts +1 -1
- package/src/core/webflow.ts +45 -3
- package/yarn.lock +4 -4
package/README.md
CHANGED
|
@@ -9,18 +9,20 @@ $ npm install webflow-api
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
using yarn
|
|
12
|
+
|
|
12
13
|
```
|
|
13
14
|
$ yarn add webflow-api
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
## Usage
|
|
18
|
+
|
|
17
19
|
The constructor takes in a few optional parameters to initialize the API client
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
- `token` - the access token to use
|
|
22
|
+
- `headers` - additional headers to add to the request
|
|
23
|
+
- `version` - the version of the API you wish to use
|
|
22
24
|
|
|
23
|
-
```
|
|
25
|
+
```javascript
|
|
24
26
|
const Webflow = require("webflow-api");
|
|
25
27
|
|
|
26
28
|
// initialize the client with the access token
|
|
@@ -31,12 +33,15 @@ const webflow = new Webflow({
|
|
|
31
33
|
token: "[ACCESS TOKEN]",
|
|
32
34
|
version: "1.0.0",
|
|
33
35
|
headers: {
|
|
34
|
-
"User-Agent": "My Webflow App / 1.0"
|
|
35
|
-
}
|
|
36
|
+
"User-Agent": "My Webflow App / 1.0",
|
|
37
|
+
},
|
|
36
38
|
});
|
|
37
39
|
```
|
|
40
|
+
|
|
38
41
|
## Basic Usage
|
|
42
|
+
|
|
39
43
|
### Chaining Calls
|
|
44
|
+
|
|
40
45
|
You can retrieve child resources by chaining calls on the parent object.
|
|
41
46
|
|
|
42
47
|
```javascript
|
|
@@ -54,6 +59,7 @@ const item = await collection.items({ itemId: "[ITEM ID]" });
|
|
|
54
59
|
```
|
|
55
60
|
|
|
56
61
|
### Pagination
|
|
62
|
+
|
|
57
63
|
To paginate results, pass in the `limit` and `offset` options.
|
|
58
64
|
|
|
59
65
|
```javascript
|
|
@@ -65,6 +71,7 @@ const page2 = await collection.items({ limit: 20, offset: 20 });
|
|
|
65
71
|
```
|
|
66
72
|
|
|
67
73
|
### Rate Limit
|
|
74
|
+
|
|
68
75
|
Check rate limit status on each call by checking the `_meta` property.
|
|
69
76
|
|
|
70
77
|
```javascript
|
|
@@ -74,7 +81,9 @@ const site = await webflow.site({ siteId: "[SITE ID]" });
|
|
|
74
81
|
// check rate limit
|
|
75
82
|
const { rateLimit } = site._meta; // { limit: 60, remaining: 56 }
|
|
76
83
|
```
|
|
84
|
+
|
|
77
85
|
### Update Token
|
|
86
|
+
|
|
78
87
|
If you need to update the access token, you can set the `token` property at any time.
|
|
79
88
|
|
|
80
89
|
```javascript
|
|
@@ -87,7 +96,9 @@ webflow.token = "[ACCESS TOKEN]";
|
|
|
87
96
|
// remove the token
|
|
88
97
|
webflow.clearToken();
|
|
89
98
|
```
|
|
99
|
+
|
|
90
100
|
### Calling APIs Directly
|
|
101
|
+
|
|
91
102
|
All Webflow API endpoints can be called directly using the `get`, `post`, `put`, and `delete` methods.
|
|
92
103
|
|
|
93
104
|
```javascript
|
|
@@ -96,14 +107,16 @@ const sites = await webflow.get("/sites");
|
|
|
96
107
|
|
|
97
108
|
// post to an endpoint directly
|
|
98
109
|
const result = await webflow.post("/sites/[SITE ID]/publish", {
|
|
99
|
-
domains: ["hello-webflow.com"]
|
|
110
|
+
domains: ["hello-webflow.com"],
|
|
100
111
|
});
|
|
101
112
|
```
|
|
102
113
|
|
|
103
114
|
## OAuth
|
|
115
|
+
|
|
104
116
|
To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.
|
|
105
117
|
|
|
106
118
|
### Authorize
|
|
119
|
+
|
|
107
120
|
The first step in OAuth is to generate an authorization url to redirect the user to.
|
|
108
121
|
|
|
109
122
|
```javascript
|
|
@@ -111,7 +124,7 @@ The first step in OAuth is to generate an authorization url to redirect the user
|
|
|
111
124
|
const url = webflow.authorizeUrl({
|
|
112
125
|
client_id: "[CLIENT ID]",
|
|
113
126
|
state: "1234567890", // optional
|
|
114
|
-
redirect_uri: "https://my.server.com/oauth/callback" // optional
|
|
127
|
+
redirect_uri: "https://my.server.com/oauth/callback", // optional
|
|
115
128
|
});
|
|
116
129
|
|
|
117
130
|
// redirect user from your server route
|
|
@@ -119,6 +132,7 @@ res.redirect(url);
|
|
|
119
132
|
```
|
|
120
133
|
|
|
121
134
|
### Access Token
|
|
135
|
+
|
|
122
136
|
Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a `code`. Use this to get an access token.
|
|
123
137
|
|
|
124
138
|
```javascript
|
|
@@ -126,7 +140,7 @@ const auth = await webflow.accessToken({
|
|
|
126
140
|
client_id,
|
|
127
141
|
client_secret,
|
|
128
142
|
code,
|
|
129
|
-
redirect_uri // optional - required if used in the authorize step
|
|
143
|
+
redirect_uri, // optional - required if used in the authorize step
|
|
130
144
|
});
|
|
131
145
|
|
|
132
146
|
// you now have the user's access token to make API requests with
|
|
@@ -137,21 +151,24 @@ const authenticatedUser = await userWF.authenticatedUser();
|
|
|
137
151
|
```
|
|
138
152
|
|
|
139
153
|
### Revoke Token
|
|
154
|
+
|
|
140
155
|
If the user decides to disconnect from your server, you should call revoke token to remove the authorization.
|
|
141
156
|
|
|
142
157
|
```javascript
|
|
143
158
|
const result = await webflow.revokeToken({
|
|
144
159
|
client_id,
|
|
145
160
|
client_secret,
|
|
146
|
-
access_token
|
|
161
|
+
access_token,
|
|
147
162
|
});
|
|
148
163
|
|
|
149
164
|
// ensure it went through
|
|
150
|
-
result.didRevoke === true
|
|
165
|
+
result.didRevoke === true;
|
|
151
166
|
```
|
|
152
167
|
|
|
153
168
|
## Examples
|
|
169
|
+
|
|
154
170
|
### Sites
|
|
171
|
+
|
|
155
172
|
Get all sites available or lookup by site id.
|
|
156
173
|
|
|
157
174
|
```javascript
|
|
@@ -163,7 +180,9 @@ const site = await webflow.sites({ siteId: "[SITE ID]" });
|
|
|
163
180
|
```
|
|
164
181
|
|
|
165
182
|
### Collections
|
|
183
|
+
|
|
166
184
|
Get all collections available for a site or lookup by collection id.
|
|
185
|
+
|
|
167
186
|
```javascript
|
|
168
187
|
// Get a site's collection from the site
|
|
169
188
|
const collections = await site.collections();
|
|
@@ -176,7 +195,9 @@ const collection = await webflow.collection({ collectionId: "[COLLECTION ID]" })
|
|
|
176
195
|
```
|
|
177
196
|
|
|
178
197
|
### Collection Items
|
|
198
|
+
|
|
179
199
|
Get all collection items available for a collection or lookup by item id.
|
|
200
|
+
|
|
180
201
|
```javascript
|
|
181
202
|
// Get the items from a collection
|
|
182
203
|
const items = await collection.items();
|
|
@@ -187,7 +208,9 @@ const items = await collection.items({ limit: 10, offset: 2 });
|
|
|
187
208
|
// Get a single item
|
|
188
209
|
const item = await webflow.item({ collectionId: "[COLLECTION ID]", itemId: "[ITEM ID]" });
|
|
189
210
|
```
|
|
211
|
+
|
|
190
212
|
### Update an Item
|
|
213
|
+
|
|
191
214
|
```javascript
|
|
192
215
|
// Set the fields to update
|
|
193
216
|
const fields = {
|
|
@@ -206,19 +229,20 @@ const updatedItem = await webflow.updateItem({
|
|
|
206
229
|
```
|
|
207
230
|
|
|
208
231
|
### Memberships
|
|
232
|
+
|
|
209
233
|
```javascript
|
|
210
234
|
// Get a site's users from the site
|
|
211
235
|
const users = await site.users();
|
|
212
236
|
|
|
213
237
|
// Get a site's users with a site id
|
|
214
238
|
const users = await webflow.users({
|
|
215
|
-
siteId: "[SITE ID]"
|
|
239
|
+
siteId: "[SITE ID]",
|
|
216
240
|
});
|
|
217
241
|
|
|
218
242
|
// Get a single user
|
|
219
243
|
const user = await site.user({
|
|
220
244
|
siteId: "[SITE ID]",
|
|
221
|
-
userId: "[USER ID]"
|
|
245
|
+
userId: "[USER ID]",
|
|
222
246
|
});
|
|
223
247
|
|
|
224
248
|
// Get a site's access groups
|
|
@@ -226,11 +250,12 @@ const accessGroups = await site.accessGroups();
|
|
|
226
250
|
|
|
227
251
|
// Get a site's access groups with a site id
|
|
228
252
|
const accessGroups = await webflow.accessGroups({
|
|
229
|
-
siteId: "[SITE ID]"
|
|
253
|
+
siteId: "[SITE ID]",
|
|
230
254
|
});
|
|
231
255
|
```
|
|
232
256
|
|
|
233
257
|
### Webhooks
|
|
258
|
+
|
|
234
259
|
```javascript
|
|
235
260
|
// get webhooks for a site
|
|
236
261
|
const webhooks = await site.webhooks();
|
|
@@ -238,18 +263,17 @@ const webhooks = await site.webhooks();
|
|
|
238
263
|
// create a webhook
|
|
239
264
|
const webhook = await site.createWebhook({
|
|
240
265
|
triggerType: "form_submission",
|
|
241
|
-
url: "https://webhook.site"
|
|
266
|
+
url: "https://webhook.site",
|
|
242
267
|
});
|
|
243
|
-
|
|
244
268
|
```
|
|
245
269
|
|
|
246
270
|
### Authenticated User
|
|
271
|
+
|
|
247
272
|
```javascript
|
|
248
273
|
// pull information for the authenticated user
|
|
249
274
|
const authenticatedUser = await webflow.authenticatedUser();
|
|
250
275
|
```
|
|
251
276
|
|
|
252
|
-
|
|
253
277
|
## Contributing
|
|
254
278
|
|
|
255
279
|
Contributions are welcome - feel free to open an issue or pull request.
|
package/dist/api/collection.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare type CollectionField = {
|
|
|
12
12
|
name: string;
|
|
13
13
|
required: boolean;
|
|
14
14
|
editable: boolean;
|
|
15
|
-
validations?:
|
|
15
|
+
validations?: Record<string, string | number | boolean | object>;
|
|
16
16
|
};
|
|
17
17
|
/**************************************************************
|
|
18
18
|
* Interfaces
|
|
@@ -97,7 +97,7 @@ export declare class Collection extends WebflowRecord<ICollection> implements IC
|
|
|
97
97
|
* @param fields The Item fields to create
|
|
98
98
|
* @returns The created Item
|
|
99
99
|
*/
|
|
100
|
-
createItem(fields:
|
|
100
|
+
createItem(fields: object): Promise<Item>;
|
|
101
101
|
/**
|
|
102
102
|
* Update a single Item
|
|
103
103
|
* @param params The params for the request
|
|
@@ -107,6 +107,6 @@ export declare class Collection extends WebflowRecord<ICollection> implements IC
|
|
|
107
107
|
*/
|
|
108
108
|
updateItem({ itemId, fields }: {
|
|
109
109
|
itemId: string;
|
|
110
|
-
fields:
|
|
110
|
+
fields: object;
|
|
111
111
|
}): Promise<Item>;
|
|
112
112
|
}
|
package/dist/api/item.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ export declare class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
153
153
|
* @param client The Axios client instance
|
|
154
154
|
* @returns The result of the publish
|
|
155
155
|
*/
|
|
156
|
-
static publish({ itemIds, live, collectionId }: {
|
|
156
|
+
static publish({ itemIds, live, collectionId, }: {
|
|
157
157
|
live?: boolean;
|
|
158
158
|
itemIds: string[];
|
|
159
159
|
collectionId: string;
|
package/dist/api/item.js
CHANGED
|
@@ -119,7 +119,7 @@ class Item extends core_1.WebflowRecord {
|
|
|
119
119
|
* @param client The Axios client instance
|
|
120
120
|
* @returns The result of the publish
|
|
121
121
|
*/
|
|
122
|
-
static publish({ itemIds, live = false, collectionId }, client) {
|
|
122
|
+
static publish({ itemIds, live = false, collectionId, }, client) {
|
|
123
123
|
(0, core_1.requireArgs)({ collectionId, itemIds });
|
|
124
124
|
const params = { live };
|
|
125
125
|
const path = `/collections/${collectionId}/items/publish`;
|
package/dist/api/oauth.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class OAuth {
|
|
|
55
55
|
* @param client The Axios client instance
|
|
56
56
|
* @returns An access token
|
|
57
57
|
*/
|
|
58
|
-
static accessToken({ grant_type, client_secret, redirect_uri, client_id, code }: IAccessTokenParams, client: AxiosInstance): Promise<import("axios").AxiosResponse<IAccessToken, any>>;
|
|
58
|
+
static accessToken({ grant_type, client_secret, redirect_uri, client_id, code, }: IAccessTokenParams, client: AxiosInstance): Promise<import("axios").AxiosResponse<IAccessToken, any>>;
|
|
59
59
|
/**
|
|
60
60
|
* Revoke an access token
|
|
61
61
|
* @param params The params for the request
|
package/dist/api/oauth.js
CHANGED
|
@@ -40,7 +40,7 @@ class OAuth {
|
|
|
40
40
|
* @param client The Axios client instance
|
|
41
41
|
* @returns An access token
|
|
42
42
|
*/
|
|
43
|
-
static accessToken({ grant_type = "authorization_code", client_secret, redirect_uri, client_id, code }, client) {
|
|
43
|
+
static accessToken({ grant_type = "authorization_code", client_secret, redirect_uri, client_id, code, }, client) {
|
|
44
44
|
(0, core_1.requireArgs)({ client_id, client_secret, code });
|
|
45
45
|
const path = "/oauth/access_token";
|
|
46
46
|
const data = { client_secret, redirect_uri, grant_type, client_id, code };
|
package/dist/api/user.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export interface IUser {
|
|
|
10
10
|
_id: string;
|
|
11
11
|
data: any;
|
|
12
12
|
}
|
|
13
|
+
export interface IAcessGroup {
|
|
14
|
+
_id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
shortId: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
createdOn: string;
|
|
19
|
+
}
|
|
13
20
|
export interface IUserDelete {
|
|
14
21
|
deleted: number;
|
|
15
22
|
}
|
|
@@ -19,6 +26,9 @@ export interface IUserDelete {
|
|
|
19
26
|
export declare type PaginatedUsers = PaginatedData & {
|
|
20
27
|
users: IUser[];
|
|
21
28
|
};
|
|
29
|
+
export declare type PaginatedAccessGroups = PaginatedData & {
|
|
30
|
+
accessGroups: IAcessGroup[];
|
|
31
|
+
};
|
|
22
32
|
export declare type UserIdParam = {
|
|
23
33
|
siteId: string;
|
|
24
34
|
userId: string;
|
|
@@ -100,6 +110,22 @@ export declare class User extends WebflowRecord<IUser> implements IUser {
|
|
|
100
110
|
siteId: string;
|
|
101
111
|
userId: string;
|
|
102
112
|
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IUserDelete, any>>;
|
|
113
|
+
/**
|
|
114
|
+
* Get a list of User Access Groups
|
|
115
|
+
* @param params The params for the request
|
|
116
|
+
* @param params.siteId The site ID
|
|
117
|
+
* @param params.limit The number of items to return (optional)
|
|
118
|
+
* @param params.offset The number of items to skip (optional)
|
|
119
|
+
* @param params.sort The sort order of the groups (optional)
|
|
120
|
+
* @param client The Axios client instance
|
|
121
|
+
* @returns A list of Access Groups
|
|
122
|
+
*/
|
|
123
|
+
static accessGroups({ siteId, limit, offset, sort, }: {
|
|
124
|
+
siteId: string;
|
|
125
|
+
limit?: number;
|
|
126
|
+
offset?: number;
|
|
127
|
+
sort?: string;
|
|
128
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<PaginatedAccessGroups, any>>;
|
|
103
129
|
/**************************************************************
|
|
104
130
|
* Instance Methods
|
|
105
131
|
**************************************************************/
|
package/dist/api/user.js
CHANGED
|
@@ -77,6 +77,22 @@ class User extends core_1.WebflowRecord {
|
|
|
77
77
|
const path = `/sites/${siteId}/users/${userId}`;
|
|
78
78
|
return client.delete(path);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Get a list of User Access Groups
|
|
82
|
+
* @param params The params for the request
|
|
83
|
+
* @param params.siteId The site ID
|
|
84
|
+
* @param params.limit The number of items to return (optional)
|
|
85
|
+
* @param params.offset The number of items to skip (optional)
|
|
86
|
+
* @param params.sort The sort order of the groups (optional)
|
|
87
|
+
* @param client The Axios client instance
|
|
88
|
+
* @returns A list of Access Groups
|
|
89
|
+
*/
|
|
90
|
+
static accessGroups({ siteId, limit, offset, sort, }, client) {
|
|
91
|
+
(0, core_1.requireArgs)({ siteId });
|
|
92
|
+
const params = { limit, offset, sort };
|
|
93
|
+
const path = `/sites/${siteId}/accessgroups`;
|
|
94
|
+
return client.get(path, { params });
|
|
95
|
+
}
|
|
80
96
|
/**************************************************************
|
|
81
97
|
* Instance Methods
|
|
82
98
|
**************************************************************/
|
package/dist/core/error.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export declare class ArgumentError extends Error {
|
|
|
18
18
|
constructor(name: string);
|
|
19
19
|
}
|
|
20
20
|
export declare function requireArgs(args: object): void;
|
|
21
|
-
export declare function ErrorInterceptor(res: AxiosResponse): AxiosResponse<
|
|
21
|
+
export declare function ErrorInterceptor(res: AxiosResponse<IRequestError>): AxiosResponse<IRequestError, any>;
|
package/dist/core/webflow.d.ts
CHANGED
|
@@ -243,7 +243,7 @@ export declare class Webflow {
|
|
|
243
243
|
* @param params.live Update the live version
|
|
244
244
|
* @returns The unpublished Collection Item result
|
|
245
245
|
*/
|
|
246
|
-
deleteItems({ collectionId, itemIds, live }: {
|
|
246
|
+
deleteItems({ collectionId, itemIds, live, }: {
|
|
247
247
|
collectionId: string;
|
|
248
248
|
itemIds: string[];
|
|
249
249
|
live?: boolean;
|
|
@@ -256,7 +256,7 @@ export declare class Webflow {
|
|
|
256
256
|
* @param params.live Update the live version
|
|
257
257
|
* @returns The Published Collection Item result
|
|
258
258
|
*/
|
|
259
|
-
publishItems({ collectionId, itemIds, live }: {
|
|
259
|
+
publishItems({ collectionId, itemIds, live, }: {
|
|
260
260
|
collectionId: string;
|
|
261
261
|
itemIds: string[];
|
|
262
262
|
live?: boolean;
|
|
@@ -319,6 +319,21 @@ export declare class Webflow {
|
|
|
319
319
|
siteId: string;
|
|
320
320
|
userId: string;
|
|
321
321
|
}): Promise<import("../api").IUserDelete>;
|
|
322
|
+
/**
|
|
323
|
+
* Get a list of User Access Groups
|
|
324
|
+
* @param params The params for the request
|
|
325
|
+
* @param params.siteId The site ID
|
|
326
|
+
* @param params.limit The number of items to return (optional)
|
|
327
|
+
* @param params.offset The number of items to skip (optional)
|
|
328
|
+
* @param params.sort The sort order of the groups (optional)
|
|
329
|
+
* @returns A list of Access Groups
|
|
330
|
+
*/
|
|
331
|
+
accessGroups({ siteId, limit, offset, sort, }: {
|
|
332
|
+
siteId: string;
|
|
333
|
+
limit?: number;
|
|
334
|
+
offset?: number;
|
|
335
|
+
sort?: string;
|
|
336
|
+
}): Promise<import("../api").PaginatedAccessGroups>;
|
|
322
337
|
/**************************************************************
|
|
323
338
|
* Webhook Endpoints
|
|
324
339
|
**************************************************************/
|
package/dist/core/webflow.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Webflow = exports.USER_AGENT = exports.DEFAULT_HOST = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const core_1 = require("../core");
|
|
8
9
|
const api_1 = require("../api");
|
|
9
10
|
exports.DEFAULT_HOST = "webflow.com";
|
|
10
11
|
exports.USER_AGENT = "Webflow Javascript SDK / 1.0";
|
|
@@ -15,6 +16,7 @@ class Webflow {
|
|
|
15
16
|
constructor(options = {}) {
|
|
16
17
|
this.options = options;
|
|
17
18
|
this.client = axios_1.default.create(this.config);
|
|
19
|
+
this.client.interceptors.response.use(core_1.ErrorInterceptor);
|
|
18
20
|
}
|
|
19
21
|
// Set the Authentication token
|
|
20
22
|
set token(value) {
|
|
@@ -301,7 +303,7 @@ class Webflow {
|
|
|
301
303
|
* @param params.live Update the live version
|
|
302
304
|
* @returns The unpublished Collection Item result
|
|
303
305
|
*/
|
|
304
|
-
async deleteItems({ collectionId, itemIds, live }) {
|
|
306
|
+
async deleteItems({ collectionId, itemIds, live, }) {
|
|
305
307
|
const res = await api_1.Item.unpublish({ collectionId, itemIds, live }, this.client);
|
|
306
308
|
return res.data;
|
|
307
309
|
}
|
|
@@ -313,7 +315,7 @@ class Webflow {
|
|
|
313
315
|
* @param params.live Update the live version
|
|
314
316
|
* @returns The Published Collection Item result
|
|
315
317
|
*/
|
|
316
|
-
async publishItems({ collectionId, itemIds, live }) {
|
|
318
|
+
async publishItems({ collectionId, itemIds, live, }) {
|
|
317
319
|
const res = await api_1.Item.publish({ collectionId, itemIds, live }, this.client);
|
|
318
320
|
return res.data;
|
|
319
321
|
}
|
|
@@ -376,6 +378,20 @@ class Webflow {
|
|
|
376
378
|
const res = await api_1.User.remove({ siteId, userId }, this.client);
|
|
377
379
|
return res.data;
|
|
378
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Get a list of User Access Groups
|
|
383
|
+
* @param params The params for the request
|
|
384
|
+
* @param params.siteId The site ID
|
|
385
|
+
* @param params.limit The number of items to return (optional)
|
|
386
|
+
* @param params.offset The number of items to skip (optional)
|
|
387
|
+
* @param params.sort The sort order of the groups (optional)
|
|
388
|
+
* @returns A list of Access Groups
|
|
389
|
+
*/
|
|
390
|
+
async accessGroups({ siteId, limit, offset, sort, }) {
|
|
391
|
+
const params = { siteId, limit, offset, sort };
|
|
392
|
+
const res = await api_1.User.accessGroups(params, this.client);
|
|
393
|
+
return res.data;
|
|
394
|
+
}
|
|
379
395
|
/**************************************************************
|
|
380
396
|
* Webhook Endpoints
|
|
381
397
|
**************************************************************/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webflow-api",
|
|
3
3
|
"description": "Webflow's official Node.js SDK for Data APIs",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"contributors": [
|
|
@@ -19,15 +19,21 @@
|
|
|
19
19
|
"yarn.lock"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"test": "yarn build && jest",
|
|
23
|
+
"build": "yarn clean && tsc",
|
|
24
|
+
"lint": "eslint src --ext .ts",
|
|
25
|
+
"test:snapshot": "yarn test --updateSnapshot",
|
|
26
|
+
"test:coverage": "yarn test --collectCoverage",
|
|
27
|
+
"test:ci": "yarn test --ci --coverage --forceExit",
|
|
28
|
+
"format": "prettier --write .",
|
|
29
|
+
"format:check": "prettier --check .",
|
|
24
30
|
"prepublish": "yarn build",
|
|
25
|
-
"watch": "tsc
|
|
31
|
+
"watch": "tsc --watch",
|
|
26
32
|
"clean": "rm -rf dist",
|
|
27
|
-
"
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
|
-
"@types/jest": "^29.2.
|
|
36
|
+
"@types/jest": "^29.2.3",
|
|
31
37
|
"@types/node": "^18.11.9",
|
|
32
38
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
33
39
|
"@typescript-eslint/parser": "^5.42.0",
|
package/src/api/collection.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type CollectionField = {
|
|
|
32
32
|
required: boolean;
|
|
33
33
|
editable: boolean;
|
|
34
34
|
// TODO: add a better type
|
|
35
|
-
validations?:
|
|
35
|
+
validations?: Record<string, string | number | boolean | object>;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/**************************************************************
|
|
@@ -134,7 +134,7 @@ export class Collection extends WebflowRecord<ICollection> implements ICollectio
|
|
|
134
134
|
* @param fields The Item fields to create
|
|
135
135
|
* @returns The created Item
|
|
136
136
|
*/
|
|
137
|
-
async createItem(fields:
|
|
137
|
+
async createItem(fields: object) {
|
|
138
138
|
const res = await Item.create({ collectionId: this._id, fields }, this.client);
|
|
139
139
|
return new Item(this.client, res);
|
|
140
140
|
}
|
|
@@ -146,7 +146,7 @@ export class Collection extends WebflowRecord<ICollection> implements ICollectio
|
|
|
146
146
|
* @param params.fields The fields to update
|
|
147
147
|
* @returns The updated Item
|
|
148
148
|
*/
|
|
149
|
-
async updateItem({ itemId, fields }: { itemId: string; fields:
|
|
149
|
+
async updateItem({ itemId, fields }: { itemId: string; fields: object }) {
|
|
150
150
|
const params = { itemId, collectionId: this._id, fields };
|
|
151
151
|
const res = await Item.update(params, this.client);
|
|
152
152
|
return new Item(this.client, res);
|
package/src/api/item.ts
CHANGED
|
@@ -70,7 +70,10 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
70
70
|
* @param client The Axios client instance
|
|
71
71
|
* @returns A single Item
|
|
72
72
|
*/
|
|
73
|
-
static getOne(
|
|
73
|
+
static getOne(
|
|
74
|
+
{ collectionId, itemId }: { collectionId: string; itemId: string },
|
|
75
|
+
client: AxiosInstance,
|
|
76
|
+
) {
|
|
74
77
|
requireArgs({ collectionId, itemId });
|
|
75
78
|
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
76
79
|
// The API returns a paginated list with one record :(
|
|
@@ -88,7 +91,7 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
88
91
|
*/
|
|
89
92
|
static list(
|
|
90
93
|
{ collectionId, limit, offset }: { collectionId: string; limit?: number; offset?: number },
|
|
91
|
-
client: AxiosInstance
|
|
94
|
+
client: AxiosInstance,
|
|
92
95
|
) {
|
|
93
96
|
requireArgs({ collectionId });
|
|
94
97
|
const params = { limit, offset };
|
|
@@ -104,7 +107,10 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
104
107
|
* @param client The Axios client instance
|
|
105
108
|
* @returns The created Item
|
|
106
109
|
*/
|
|
107
|
-
static create(
|
|
110
|
+
static create(
|
|
111
|
+
{ collectionId, fields }: { fields: any; collectionId: string },
|
|
112
|
+
client: AxiosInstance,
|
|
113
|
+
) {
|
|
108
114
|
requireArgs({ collectionId });
|
|
109
115
|
const path = `/collections/${collectionId}/items`;
|
|
110
116
|
return client.post<IItem>(path, { fields });
|
|
@@ -129,7 +135,7 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
129
135
|
itemId: string;
|
|
130
136
|
collectionId: string;
|
|
131
137
|
},
|
|
132
|
-
client: AxiosInstance
|
|
138
|
+
client: AxiosInstance,
|
|
133
139
|
) {
|
|
134
140
|
requireArgs({ collectionId, itemId });
|
|
135
141
|
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
@@ -155,7 +161,7 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
155
161
|
itemId: string;
|
|
156
162
|
collectionId: string;
|
|
157
163
|
},
|
|
158
|
-
client: AxiosInstance
|
|
164
|
+
client: AxiosInstance,
|
|
159
165
|
) {
|
|
160
166
|
requireArgs({ collectionId, itemId });
|
|
161
167
|
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
@@ -178,7 +184,7 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
178
184
|
itemId: string;
|
|
179
185
|
collectionId: string;
|
|
180
186
|
},
|
|
181
|
-
client: AxiosInstance
|
|
187
|
+
client: AxiosInstance,
|
|
182
188
|
) {
|
|
183
189
|
requireArgs({ collectionId, itemId });
|
|
184
190
|
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
@@ -203,7 +209,7 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
203
209
|
itemIds: string[];
|
|
204
210
|
collectionId: string;
|
|
205
211
|
},
|
|
206
|
-
client: AxiosInstance
|
|
212
|
+
client: AxiosInstance,
|
|
207
213
|
) {
|
|
208
214
|
requireArgs({ collectionId, itemIds });
|
|
209
215
|
const params = { live };
|
|
@@ -226,8 +232,12 @@ export class Item extends WebflowRecord<IItem> implements IItem {
|
|
|
226
232
|
* @returns The result of the publish
|
|
227
233
|
*/
|
|
228
234
|
static publish(
|
|
229
|
-
{
|
|
230
|
-
|
|
235
|
+
{
|
|
236
|
+
itemIds,
|
|
237
|
+
live = false,
|
|
238
|
+
collectionId,
|
|
239
|
+
}: { live?: boolean; itemIds: string[]; collectionId: string },
|
|
240
|
+
client: AxiosInstance,
|
|
231
241
|
) {
|
|
232
242
|
requireArgs({ collectionId, itemIds });
|
|
233
243
|
const params = { live };
|
package/src/api/oauth.ts
CHANGED
|
@@ -53,7 +53,7 @@ export class OAuth {
|
|
|
53
53
|
*/
|
|
54
54
|
static authorizeUrl(
|
|
55
55
|
{ response_type = "code", redirect_uri, client_id, state, scope }: IAuthorizeUrlParams,
|
|
56
|
-
client: AxiosInstance
|
|
56
|
+
client: AxiosInstance,
|
|
57
57
|
) {
|
|
58
58
|
requireArgs({ client_id });
|
|
59
59
|
|
|
@@ -78,8 +78,14 @@ export class OAuth {
|
|
|
78
78
|
* @returns An access token
|
|
79
79
|
*/
|
|
80
80
|
static accessToken(
|
|
81
|
-
{
|
|
82
|
-
|
|
81
|
+
{
|
|
82
|
+
grant_type = "authorization_code",
|
|
83
|
+
client_secret,
|
|
84
|
+
redirect_uri,
|
|
85
|
+
client_id,
|
|
86
|
+
code,
|
|
87
|
+
}: IAccessTokenParams,
|
|
88
|
+
client: AxiosInstance,
|
|
83
89
|
) {
|
|
84
90
|
requireArgs({ client_id, client_secret, code });
|
|
85
91
|
|
|
@@ -97,7 +103,10 @@ export class OAuth {
|
|
|
97
103
|
* @param client The Axios client instance
|
|
98
104
|
* @returns The result of the revoke
|
|
99
105
|
*/
|
|
100
|
-
static revokeToken(
|
|
106
|
+
static revokeToken(
|
|
107
|
+
{ client_secret, access_token, client_id }: IRevokeTokenParams,
|
|
108
|
+
client: AxiosInstance,
|
|
109
|
+
) {
|
|
101
110
|
requireArgs({ client_id, client_secret, access_token });
|
|
102
111
|
|
|
103
112
|
const path = "/oauth/revoke_authorization";
|
package/src/api/site.ts
CHANGED
|
@@ -71,7 +71,10 @@ export class Site extends WebflowRecord<ISite> implements ISite {
|
|
|
71
71
|
* @param client The Axios client instance
|
|
72
72
|
* @returns The publish result
|
|
73
73
|
*/
|
|
74
|
-
static publish(
|
|
74
|
+
static publish(
|
|
75
|
+
{ siteId, domains }: { siteId: string; domains: string[] },
|
|
76
|
+
client: AxiosInstance,
|
|
77
|
+
) {
|
|
75
78
|
requireArgs({ siteId, domains });
|
|
76
79
|
const path = `/sites/${siteId}/publish`;
|
|
77
80
|
return client.post<IPublishSite>(path, { domains });
|
package/src/api/user.ts
CHANGED
|
@@ -12,6 +12,14 @@ export interface IUser {
|
|
|
12
12
|
data: any;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export interface IAcessGroup {
|
|
16
|
+
_id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
shortId: string;
|
|
19
|
+
slug: string;
|
|
20
|
+
createdOn: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
export interface IUserDelete {
|
|
16
24
|
deleted: number;
|
|
17
25
|
}
|
|
@@ -23,6 +31,10 @@ export type PaginatedUsers = PaginatedData & {
|
|
|
23
31
|
users: IUser[];
|
|
24
32
|
};
|
|
25
33
|
|
|
34
|
+
export type PaginatedAccessGroups = PaginatedData & {
|
|
35
|
+
accessGroups: IAcessGroup[];
|
|
36
|
+
};
|
|
37
|
+
|
|
26
38
|
export type UserIdParam = { siteId: string; userId: string };
|
|
27
39
|
|
|
28
40
|
/**************************************************************
|
|
@@ -50,7 +62,10 @@ export class User extends WebflowRecord<IUser> implements IUser {
|
|
|
50
62
|
* @param client The Axios client instance
|
|
51
63
|
* @returns A list of Users
|
|
52
64
|
*/
|
|
53
|
-
static list(
|
|
65
|
+
static list(
|
|
66
|
+
{ siteId, limit, offset }: { siteId: string; limit?: number; offset?: number },
|
|
67
|
+
client: AxiosInstance,
|
|
68
|
+
) {
|
|
54
69
|
requireArgs({ siteId });
|
|
55
70
|
const params = { limit, offset };
|
|
56
71
|
const path = `/sites/${siteId}/users`;
|
|
@@ -90,7 +105,7 @@ export class User extends WebflowRecord<IUser> implements IUser {
|
|
|
90
105
|
siteId: string;
|
|
91
106
|
userId: string;
|
|
92
107
|
},
|
|
93
|
-
client: AxiosInstance
|
|
108
|
+
client: AxiosInstance,
|
|
94
109
|
) {
|
|
95
110
|
requireArgs({ siteId, userId });
|
|
96
111
|
const path = `/sites/${siteId}/users/${userId}`;
|
|
@@ -125,6 +140,31 @@ export class User extends WebflowRecord<IUser> implements IUser {
|
|
|
125
140
|
return client.delete<IUserDelete>(path);
|
|
126
141
|
}
|
|
127
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Get a list of User Access Groups
|
|
145
|
+
* @param params The params for the request
|
|
146
|
+
* @param params.siteId The site ID
|
|
147
|
+
* @param params.limit The number of items to return (optional)
|
|
148
|
+
* @param params.offset The number of items to skip (optional)
|
|
149
|
+
* @param params.sort The sort order of the groups (optional)
|
|
150
|
+
* @param client The Axios client instance
|
|
151
|
+
* @returns A list of Access Groups
|
|
152
|
+
*/
|
|
153
|
+
static accessGroups(
|
|
154
|
+
{
|
|
155
|
+
siteId,
|
|
156
|
+
limit,
|
|
157
|
+
offset,
|
|
158
|
+
sort,
|
|
159
|
+
}: { siteId: string; limit?: number; offset?: number; sort?: string },
|
|
160
|
+
client: AxiosInstance,
|
|
161
|
+
) {
|
|
162
|
+
requireArgs({ siteId });
|
|
163
|
+
const params = { limit, offset, sort };
|
|
164
|
+
const path = `/sites/${siteId}/accessgroups`;
|
|
165
|
+
return client.get<PaginatedAccessGroups>(path, { params });
|
|
166
|
+
}
|
|
167
|
+
|
|
128
168
|
/**************************************************************
|
|
129
169
|
* Instance Methods
|
|
130
170
|
**************************************************************/
|
package/src/api/webhook.ts
CHANGED
|
@@ -75,7 +75,10 @@ export class Webhook extends WebflowRecord<IWebhook> implements IWebhook {
|
|
|
75
75
|
* @param client The Axios client instance
|
|
76
76
|
* @returns A single Webhook
|
|
77
77
|
*/
|
|
78
|
-
static getOne(
|
|
78
|
+
static getOne(
|
|
79
|
+
{ siteId, webhookId }: { siteId: string; webhookId: string },
|
|
80
|
+
client: AxiosInstance,
|
|
81
|
+
) {
|
|
79
82
|
requireArgs({ siteId, webhookId });
|
|
80
83
|
const path = `/sites/${siteId}/webhooks/${webhookId}`;
|
|
81
84
|
return client.get<IWebhook>(path);
|
|
@@ -104,7 +107,7 @@ export class Webhook extends WebflowRecord<IWebhook> implements IWebhook {
|
|
|
104
107
|
filter?: WebhookFilter;
|
|
105
108
|
triggerType: TriggerType;
|
|
106
109
|
},
|
|
107
|
-
client: AxiosInstance
|
|
110
|
+
client: AxiosInstance,
|
|
108
111
|
) {
|
|
109
112
|
requireArgs({ siteId, triggerType, url });
|
|
110
113
|
const path = `/sites/${siteId}/webhooks`;
|
|
@@ -120,7 +123,10 @@ export class Webhook extends WebflowRecord<IWebhook> implements IWebhook {
|
|
|
120
123
|
* @param client The Axios client instance
|
|
121
124
|
* @returns The result of the removal
|
|
122
125
|
*/
|
|
123
|
-
static remove(
|
|
126
|
+
static remove(
|
|
127
|
+
{ siteId, webhookId }: { siteId: string; webhookId: string },
|
|
128
|
+
client: AxiosInstance,
|
|
129
|
+
) {
|
|
124
130
|
requireArgs({ siteId, webhookId });
|
|
125
131
|
const path = `/sites/${siteId}/webhooks/${webhookId}`;
|
|
126
132
|
return client.delete<IRemoveResult>(path);
|
package/src/core/error.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function requireArgs(args: object) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// throw an error if Webflow error
|
|
37
|
-
export function ErrorInterceptor(res: AxiosResponse) {
|
|
37
|
+
export function ErrorInterceptor(res: AxiosResponse<IRequestError>) {
|
|
38
38
|
if (res.data.err) throw new RequestError(res.data);
|
|
39
39
|
return res;
|
|
40
40
|
}
|
package/src/core/webflow.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
-
import { PaginationFilter } from "../core";
|
|
2
|
+
import { PaginationFilter, ErrorInterceptor } from "../core";
|
|
3
3
|
import {
|
|
4
4
|
Collection,
|
|
5
5
|
IAccessTokenParams,
|
|
@@ -31,6 +31,7 @@ export class Webflow {
|
|
|
31
31
|
private client: AxiosInstance;
|
|
32
32
|
constructor(public options: Options = {}) {
|
|
33
33
|
this.client = axios.create(this.config);
|
|
34
|
+
this.client.interceptors.response.use(ErrorInterceptor);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
// Set the Authentication token
|
|
@@ -334,7 +335,15 @@ export class Webflow {
|
|
|
334
335
|
* @param params.live Update the live version
|
|
335
336
|
* @returns The unpublished Collection Item result
|
|
336
337
|
*/
|
|
337
|
-
async deleteItems({
|
|
338
|
+
async deleteItems({
|
|
339
|
+
collectionId,
|
|
340
|
+
itemIds,
|
|
341
|
+
live,
|
|
342
|
+
}: {
|
|
343
|
+
collectionId: string;
|
|
344
|
+
itemIds: string[];
|
|
345
|
+
live?: boolean;
|
|
346
|
+
}) {
|
|
338
347
|
const res = await Item.unpublish({ collectionId, itemIds, live }, this.client);
|
|
339
348
|
return res.data;
|
|
340
349
|
}
|
|
@@ -346,7 +355,15 @@ export class Webflow {
|
|
|
346
355
|
* @param params.live Update the live version
|
|
347
356
|
* @returns The Published Collection Item result
|
|
348
357
|
*/
|
|
349
|
-
async publishItems({
|
|
358
|
+
async publishItems({
|
|
359
|
+
collectionId,
|
|
360
|
+
itemIds,
|
|
361
|
+
live,
|
|
362
|
+
}: {
|
|
363
|
+
collectionId: string;
|
|
364
|
+
itemIds: string[];
|
|
365
|
+
live?: boolean;
|
|
366
|
+
}) {
|
|
350
367
|
const res = await Item.publish({ collectionId, itemIds, live }, this.client);
|
|
351
368
|
return res.data;
|
|
352
369
|
}
|
|
@@ -416,6 +433,31 @@ export class Webflow {
|
|
|
416
433
|
return res.data;
|
|
417
434
|
}
|
|
418
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Get a list of User Access Groups
|
|
438
|
+
* @param params The params for the request
|
|
439
|
+
* @param params.siteId The site ID
|
|
440
|
+
* @param params.limit The number of items to return (optional)
|
|
441
|
+
* @param params.offset The number of items to skip (optional)
|
|
442
|
+
* @param params.sort The sort order of the groups (optional)
|
|
443
|
+
* @returns A list of Access Groups
|
|
444
|
+
*/
|
|
445
|
+
async accessGroups({
|
|
446
|
+
siteId,
|
|
447
|
+
limit,
|
|
448
|
+
offset,
|
|
449
|
+
sort,
|
|
450
|
+
}: {
|
|
451
|
+
siteId: string;
|
|
452
|
+
limit?: number;
|
|
453
|
+
offset?: number;
|
|
454
|
+
sort?: string;
|
|
455
|
+
}) {
|
|
456
|
+
const params = { siteId, limit, offset, sort };
|
|
457
|
+
const res = await User.accessGroups(params, this.client);
|
|
458
|
+
return res.data;
|
|
459
|
+
}
|
|
460
|
+
|
|
419
461
|
/**************************************************************
|
|
420
462
|
* Webhook Endpoints
|
|
421
463
|
**************************************************************/
|
package/yarn.lock
CHANGED
|
@@ -673,10 +673,10 @@
|
|
|
673
673
|
dependencies:
|
|
674
674
|
"@types/istanbul-lib-report" "*"
|
|
675
675
|
|
|
676
|
-
"@types/jest@^29.2.
|
|
677
|
-
"integrity" "sha512-
|
|
678
|
-
"resolved" "https://registry.npmjs.org/@types/jest/-/jest-29.2.
|
|
679
|
-
"version" "29.2.
|
|
676
|
+
"@types/jest@^29.2.3":
|
|
677
|
+
"integrity" "sha512-6XwoEbmatfyoCjWRX7z0fKMmgYKe9+/HrviJ5k0X/tjJWHGAezZOfYaxqQKuzG/TvQyr+ktjm4jgbk0s4/oF2w=="
|
|
678
|
+
"resolved" "https://registry.npmjs.org/@types/jest/-/jest-29.2.3.tgz"
|
|
679
|
+
"version" "29.2.3"
|
|
680
680
|
dependencies:
|
|
681
681
|
"expect" "^29.0.0"
|
|
682
682
|
"pretty-format" "^29.0.0"
|