webflow-api 1.1.1 → 1.1.2
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 +12 -1
- package/dist/api/membership.d.ts +25 -2
- package/dist/api/membership.js +18 -2
- package/dist/core/client.d.ts +0 -13
- package/dist/core/client.js +28 -17
- package/dist/webflow.d.ts +13 -5
- package/dist/webflow.js +13 -5
- package/dist/wrapper/collection.d.ts +2 -2
- package/dist/wrapper/membership.d.ts +14 -0
- package/dist/wrapper/membership.js +18 -1
- package/dist/wrapper/site.d.ts +50 -1
- package/dist/wrapper/site.js +55 -0
- package/package.json +1 -1
- package/src/api/item.ts +1 -1
- package/src/api/membership.ts +33 -3
- package/src/core/client.ts +28 -22
- package/src/webflow.ts +14 -5
- package/src/wrapper/collection.ts +1 -1
- package/src/wrapper/membership.ts +26 -1
- package/src/wrapper/site.ts +64 -0
- package/src/wrapper/webhook.ts +1 -1
package/README.md
CHANGED
|
@@ -207,7 +207,10 @@ const updatedItem = await webflow.updateItem({
|
|
|
207
207
|
|
|
208
208
|
### Memberships
|
|
209
209
|
```javascript
|
|
210
|
-
// Get
|
|
210
|
+
// Get a site's users from the site
|
|
211
|
+
const users = await site.users();
|
|
212
|
+
|
|
213
|
+
// Get a site's users with a site id
|
|
211
214
|
const users = await webflow.users({
|
|
212
215
|
siteId: "[SITE ID]"
|
|
213
216
|
});
|
|
@@ -217,6 +220,14 @@ const user = await site.user({
|
|
|
217
220
|
siteId: "[SITE ID]",
|
|
218
221
|
userId: "[USER ID]"
|
|
219
222
|
});
|
|
223
|
+
|
|
224
|
+
// Get a site's access groups
|
|
225
|
+
const accessGroups = await site.accessGroups();
|
|
226
|
+
|
|
227
|
+
// Get a site's access groups with a site id
|
|
228
|
+
const accessGroups = await webflow.accessGroups({
|
|
229
|
+
siteId: "[SITE ID]"
|
|
230
|
+
});
|
|
220
231
|
```
|
|
221
232
|
|
|
222
233
|
### Webhooks
|
package/dist/api/membership.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export interface IUser {
|
|
|
9
9
|
_id: string;
|
|
10
10
|
data: any;
|
|
11
11
|
}
|
|
12
|
+
export interface IAccessGroup {
|
|
13
|
+
_id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
shortId: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
createdOn: string;
|
|
18
|
+
}
|
|
12
19
|
export interface IUserDelete {
|
|
13
20
|
deleted: number;
|
|
14
21
|
}
|
|
@@ -18,6 +25,9 @@ export interface IUserDelete {
|
|
|
18
25
|
export declare type PaginatedUsers = PaginatedData & {
|
|
19
26
|
users: IUser[];
|
|
20
27
|
};
|
|
28
|
+
export declare type PaginatedAccessGroups = PaginatedData & {
|
|
29
|
+
accessGroups: IAccessGroup[];
|
|
30
|
+
};
|
|
21
31
|
export declare type UserIdParam = {
|
|
22
32
|
siteId: string;
|
|
23
33
|
userId: string;
|
|
@@ -60,8 +70,7 @@ export declare function getOne(client: Client, { siteId, userId }: {
|
|
|
60
70
|
* @param params.data The data to update
|
|
61
71
|
* @returns The updated User
|
|
62
72
|
*/
|
|
63
|
-
export declare function update(client: Client, { siteId, userId, data
|
|
64
|
-
data: object;
|
|
73
|
+
export declare function update(client: Client, { siteId, userId, ...data }: {
|
|
65
74
|
siteId: string;
|
|
66
75
|
userId: string;
|
|
67
76
|
}): Promise<import("axios").AxiosResponse<IUser, any>>;
|
|
@@ -89,3 +98,17 @@ export declare function remove(client: Client, { siteId, userId }: {
|
|
|
89
98
|
siteId: string;
|
|
90
99
|
userId: string;
|
|
91
100
|
}): Promise<import("axios").AxiosResponse<IUserDelete, any>>;
|
|
101
|
+
/**
|
|
102
|
+
* Get a list of Access Groups
|
|
103
|
+
* @param client The Webflow client
|
|
104
|
+
* @param params The params for the request
|
|
105
|
+
* @param params.siteId The Site ID
|
|
106
|
+
* @param params.limit The number of items to return (optional)
|
|
107
|
+
* @param params.offset The number of items to skip (optional)
|
|
108
|
+
* @returns A list of Access Groups
|
|
109
|
+
*/
|
|
110
|
+
export declare function accessGroups(client: Client, { siteId, limit, offset }: {
|
|
111
|
+
siteId: string;
|
|
112
|
+
limit?: number;
|
|
113
|
+
offset?: number;
|
|
114
|
+
}): Promise<import("axios").AxiosResponse<PaginatedAccessGroups, any>>;
|
package/dist/api/membership.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remove = exports.invite = exports.update = exports.getOne = exports.list = void 0;
|
|
3
|
+
exports.accessGroups = exports.remove = exports.invite = exports.update = exports.getOne = exports.list = void 0;
|
|
4
4
|
const core_1 = require("../core");
|
|
5
5
|
/**************************************************************
|
|
6
6
|
* Functions
|
|
@@ -44,7 +44,7 @@ exports.getOne = getOne;
|
|
|
44
44
|
* @param params.data The data to update
|
|
45
45
|
* @returns The updated User
|
|
46
46
|
*/
|
|
47
|
-
function update(client, { siteId, userId, data
|
|
47
|
+
function update(client, { siteId, userId, ...data }) {
|
|
48
48
|
(0, core_1.requireArgs)({ siteId, userId });
|
|
49
49
|
const path = `/sites/${siteId}/users/${userId}`;
|
|
50
50
|
return client.patch(path, data);
|
|
@@ -78,3 +78,19 @@ function remove(client, { siteId, userId }) {
|
|
|
78
78
|
return client.delete(path);
|
|
79
79
|
}
|
|
80
80
|
exports.remove = remove;
|
|
81
|
+
/**
|
|
82
|
+
* Get a list of Access Groups
|
|
83
|
+
* @param client The Webflow client
|
|
84
|
+
* @param params The params for the request
|
|
85
|
+
* @param params.siteId The Site ID
|
|
86
|
+
* @param params.limit The number of items to return (optional)
|
|
87
|
+
* @param params.offset The number of items to skip (optional)
|
|
88
|
+
* @returns A list of Access Groups
|
|
89
|
+
*/
|
|
90
|
+
function accessGroups(client, { siteId, limit, offset }) {
|
|
91
|
+
(0, core_1.requireArgs)({ siteId });
|
|
92
|
+
const params = { limit, offset };
|
|
93
|
+
const path = `/sites/${siteId}/users/accessgroups`;
|
|
94
|
+
return client.get(path, { params });
|
|
95
|
+
}
|
|
96
|
+
exports.accessGroups = accessGroups;
|
package/dist/core/client.d.ts
CHANGED
|
@@ -17,24 +17,11 @@ export interface PaginatedData {
|
|
|
17
17
|
offset: number;
|
|
18
18
|
total: number;
|
|
19
19
|
}
|
|
20
|
-
export interface WebflowOptions {
|
|
21
|
-
host?: string;
|
|
22
|
-
token?: string;
|
|
23
|
-
version?: string;
|
|
24
|
-
headers?: Record<string, string>;
|
|
25
|
-
}
|
|
26
20
|
/**************************************************************
|
|
27
21
|
* Classes
|
|
28
22
|
**************************************************************/
|
|
29
23
|
export declare class Client extends Axios {
|
|
30
24
|
constructor({ host, headers, version, token, }?: Options);
|
|
31
|
-
/**
|
|
32
|
-
* Transforms JSON response to an object
|
|
33
|
-
* if the response is a Webflow error, it will throw an error
|
|
34
|
-
* @param data JSON response
|
|
35
|
-
* @returns response object
|
|
36
|
-
*/
|
|
37
|
-
private transformResponse;
|
|
38
25
|
set token(value: string);
|
|
39
26
|
clearToken(): void;
|
|
40
27
|
}
|
package/dist/core/client.js
CHANGED
|
@@ -3,13 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Client = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
5
|
const core_1 = require("../core");
|
|
6
|
+
/**************************************************************
|
|
7
|
+
* Functions
|
|
8
|
+
**************************************************************/
|
|
9
|
+
/**
|
|
10
|
+
* Transforms JSON response to an object
|
|
11
|
+
* if the response is a Webflow error, it will throw an error
|
|
12
|
+
* @param data JSON response
|
|
13
|
+
* @returns response object
|
|
14
|
+
*/
|
|
15
|
+
function transformResponse(data = {}) {
|
|
16
|
+
// parse json if string
|
|
17
|
+
if (String(data) === data)
|
|
18
|
+
data = JSON.parse(data);
|
|
19
|
+
// throw an error if Webflow returns an error obejct
|
|
20
|
+
if (data.err)
|
|
21
|
+
throw new core_1.RequestError(data);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Transforms POST/PUT/PATCH request data to JSON
|
|
26
|
+
* @param data A JavaScript object
|
|
27
|
+
* @returns JSON string
|
|
28
|
+
*/
|
|
29
|
+
function transformRequest(data = {}) {
|
|
30
|
+
return JSON.stringify(data);
|
|
31
|
+
}
|
|
6
32
|
/**************************************************************
|
|
7
33
|
* Classes
|
|
8
34
|
**************************************************************/
|
|
9
35
|
class Client extends axios_1.Axios {
|
|
10
36
|
constructor({ host = core_1.DEFAULT_HOST, headers = {}, version, token, } = {}) {
|
|
11
37
|
super({
|
|
12
|
-
transformRequest: [
|
|
38
|
+
transformRequest: [transformRequest],
|
|
39
|
+
transformResponse: [transformResponse],
|
|
13
40
|
baseURL: `https://api.${host}/`,
|
|
14
41
|
headers: {
|
|
15
42
|
"Content-Type": "application/json",
|
|
@@ -20,22 +47,6 @@ class Client extends axios_1.Axios {
|
|
|
20
47
|
});
|
|
21
48
|
if (token)
|
|
22
49
|
this.token = token;
|
|
23
|
-
// check for webflow errors
|
|
24
|
-
this.defaults.transformResponse = [this.transformResponse];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Transforms JSON response to an object
|
|
28
|
-
* if the response is a Webflow error, it will throw an error
|
|
29
|
-
* @param data JSON response
|
|
30
|
-
* @returns response object
|
|
31
|
-
*/
|
|
32
|
-
transformResponse(data = {}) {
|
|
33
|
-
// parse json if string
|
|
34
|
-
if (String(data) === data)
|
|
35
|
-
data = JSON.parse(data);
|
|
36
|
-
if (data.err)
|
|
37
|
-
throw new core_1.RequestError(data);
|
|
38
|
-
return data;
|
|
39
50
|
}
|
|
40
51
|
// set the Authorization header
|
|
41
52
|
set token(value) {
|
package/dist/webflow.d.ts
CHANGED
|
@@ -198,7 +198,6 @@ export declare class Webflow {
|
|
|
198
198
|
* @param params The Item information
|
|
199
199
|
* @param params.collectionId The Collection ID
|
|
200
200
|
* @param params.itemId The Item ID
|
|
201
|
-
* @param query The query parameters (optional)
|
|
202
201
|
* @returns The updated Collection Item
|
|
203
202
|
*/
|
|
204
203
|
updateItem({ collectionId, itemId, ...fields }: {
|
|
@@ -233,8 +232,7 @@ export declare class Webflow {
|
|
|
233
232
|
* @param params The Item information
|
|
234
233
|
* @param params.collectionId The Collection ID
|
|
235
234
|
* @param params.itemId The Item ID
|
|
236
|
-
* @param
|
|
237
|
-
* @param query.live Update the live version
|
|
235
|
+
* @param params.live Update the live version
|
|
238
236
|
* @returns The unpublished Collection Item result
|
|
239
237
|
*/
|
|
240
238
|
deleteItems({ collectionId, itemIds, live, }: {
|
|
@@ -247,8 +245,7 @@ export declare class Webflow {
|
|
|
247
245
|
* @param params The Item information
|
|
248
246
|
* @param params.collectionId The Collection ID
|
|
249
247
|
* @param params.itemId The Item ID
|
|
250
|
-
* @param
|
|
251
|
-
* @param query.live Update the live version
|
|
248
|
+
* @param params.live Update the live version
|
|
252
249
|
* @returns The Published Collection Item result
|
|
253
250
|
*/
|
|
254
251
|
publishItems({ collectionId, itemIds, live, }: {
|
|
@@ -264,6 +261,8 @@ export declare class Webflow {
|
|
|
264
261
|
* @param params The Site information
|
|
265
262
|
* @param params.siteId The Site ID
|
|
266
263
|
* @param pageParams The pagination information (optional)
|
|
264
|
+
* @param pageParams.limit The number of results to return
|
|
265
|
+
* @param pageParams.offset The number of results to skip
|
|
267
266
|
* @returns A list of User accounts
|
|
268
267
|
*/
|
|
269
268
|
users({ siteId }: {
|
|
@@ -314,6 +313,15 @@ export declare class Webflow {
|
|
|
314
313
|
siteId: string;
|
|
315
314
|
userId: string;
|
|
316
315
|
}): Promise<import("./wrapper").MetaResponse<import("./api/membership").IUserDelete>>;
|
|
316
|
+
/**
|
|
317
|
+
* Get a list of Access Groups
|
|
318
|
+
* @param params The Site and User information
|
|
319
|
+
* @param params.siteId The Site ID
|
|
320
|
+
* @returns The result from the remove request
|
|
321
|
+
*/
|
|
322
|
+
accessGroups({ siteId }: {
|
|
323
|
+
siteId: string;
|
|
324
|
+
}): Promise<import("./wrapper").MetaResponse<import("./api/membership").PaginatedAccessGroups>>;
|
|
317
325
|
/**************************************************************
|
|
318
326
|
* Webhook Endpoints
|
|
319
327
|
**************************************************************/
|
package/dist/webflow.js
CHANGED
|
@@ -230,7 +230,6 @@ class Webflow {
|
|
|
230
230
|
* @param params The Item information
|
|
231
231
|
* @param params.collectionId The Collection ID
|
|
232
232
|
* @param params.itemId The Item ID
|
|
233
|
-
* @param query The query parameters (optional)
|
|
234
233
|
* @returns The updated Collection Item
|
|
235
234
|
*/
|
|
236
235
|
updateItem({ collectionId, itemId, ...fields }) {
|
|
@@ -264,8 +263,7 @@ class Webflow {
|
|
|
264
263
|
* @param params The Item information
|
|
265
264
|
* @param params.collectionId The Collection ID
|
|
266
265
|
* @param params.itemId The Item ID
|
|
267
|
-
* @param
|
|
268
|
-
* @param query.live Update the live version
|
|
266
|
+
* @param params.live Update the live version
|
|
269
267
|
* @returns The unpublished Collection Item result
|
|
270
268
|
*/
|
|
271
269
|
deleteItems({ collectionId, itemIds, live, }) {
|
|
@@ -277,8 +275,7 @@ class Webflow {
|
|
|
277
275
|
* @param params The Item information
|
|
278
276
|
* @param params.collectionId The Collection ID
|
|
279
277
|
* @param params.itemId The Item ID
|
|
280
|
-
* @param
|
|
281
|
-
* @param query.live Update the live version
|
|
278
|
+
* @param params.live Update the live version
|
|
282
279
|
* @returns The Published Collection Item result
|
|
283
280
|
*/
|
|
284
281
|
publishItems({ collectionId, itemIds, live, }) {
|
|
@@ -293,6 +290,8 @@ class Webflow {
|
|
|
293
290
|
* @param params The Site information
|
|
294
291
|
* @param params.siteId The Site ID
|
|
295
292
|
* @param pageParams The pagination information (optional)
|
|
293
|
+
* @param pageParams.limit The number of results to return
|
|
294
|
+
* @param pageParams.offset The number of results to skip
|
|
296
295
|
* @returns A list of User accounts
|
|
297
296
|
*/
|
|
298
297
|
async users({ siteId }, pageParams) {
|
|
@@ -339,6 +338,15 @@ class Webflow {
|
|
|
339
338
|
removeUser({ siteId, userId }) {
|
|
340
339
|
return wrapper_1.MembershipWrapper.remove(this.client, { siteId, userId });
|
|
341
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Get a list of Access Groups
|
|
343
|
+
* @param params The Site and User information
|
|
344
|
+
* @param params.siteId The Site ID
|
|
345
|
+
* @returns The result from the remove request
|
|
346
|
+
*/
|
|
347
|
+
accessGroups({ siteId }) {
|
|
348
|
+
return wrapper_1.MembershipWrapper.accessGroups(this.client, { siteId });
|
|
349
|
+
}
|
|
342
350
|
/**************************************************************
|
|
343
351
|
* Webhook Endpoints
|
|
344
352
|
**************************************************************/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ItemWrapper } from ".";
|
|
2
2
|
import { Client, QueryString } from "../core";
|
|
3
|
-
import { Collection
|
|
3
|
+
import { Collection } from "../api";
|
|
4
4
|
export declare class CollectionWrapper implements Collection.ICollection {
|
|
5
5
|
private client;
|
|
6
6
|
fields: Collection.CollectionField[];
|
|
@@ -63,7 +63,7 @@ export declare class CollectionWrapper implements Collection.ICollection {
|
|
|
63
63
|
*/
|
|
64
64
|
removeItem({ itemId }: {
|
|
65
65
|
itemId: string;
|
|
66
|
-
}): Promise<import("./response").MetaResponse<
|
|
66
|
+
}): Promise<import("./response").MetaResponse<import("../api/item").IItemDelete>>;
|
|
67
67
|
/**
|
|
68
68
|
* Create a new Item
|
|
69
69
|
* @param params The params for the request
|
|
@@ -62,6 +62,20 @@ export declare class MembershipWrapper implements Membership.IUser {
|
|
|
62
62
|
siteId: string;
|
|
63
63
|
email: string;
|
|
64
64
|
}): Promise<import("./response").MetaResponse<Membership.IUser>>;
|
|
65
|
+
/**
|
|
66
|
+
* Get a list of Access Groups
|
|
67
|
+
* @param client The Webflow client
|
|
68
|
+
* @param params The params for the request
|
|
69
|
+
* @param params.siteId The Site ID
|
|
70
|
+
* @param params.limit The number of items to return (optional)
|
|
71
|
+
* @param params.offset The number of items to skip (optional)
|
|
72
|
+
* @returns A list of Access Groups
|
|
73
|
+
*/
|
|
74
|
+
static accessGroups(client: Client, { siteId, limit, offset, }: {
|
|
75
|
+
siteId: string;
|
|
76
|
+
limit?: number;
|
|
77
|
+
offset?: number;
|
|
78
|
+
}): Promise<import("./response").MetaResponse<Membership.PaginatedAccessGroups>>;
|
|
65
79
|
/**
|
|
66
80
|
* Remove a User
|
|
67
81
|
* @param client The Webflow client
|
|
@@ -49,7 +49,7 @@ class MembershipWrapper {
|
|
|
49
49
|
* @returns The updated User
|
|
50
50
|
*/
|
|
51
51
|
static async update(client, { userId, siteId, data }) {
|
|
52
|
-
const res = await api_1.Membership.update(client, { userId, siteId, data });
|
|
52
|
+
const res = await api_1.Membership.update(client, { userId, siteId, ...data });
|
|
53
53
|
const user = (0, _1.ResponseWrapper)(res);
|
|
54
54
|
return new MembershipWrapper(client, siteId, user);
|
|
55
55
|
}
|
|
@@ -65,6 +65,23 @@ class MembershipWrapper {
|
|
|
65
65
|
const res = await api_1.Membership.invite(client, { siteId, email });
|
|
66
66
|
return (0, _1.ResponseWrapper)(res);
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a list of Access Groups
|
|
70
|
+
* @param client The Webflow client
|
|
71
|
+
* @param params The params for the request
|
|
72
|
+
* @param params.siteId The Site ID
|
|
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 Access Groups
|
|
76
|
+
*/
|
|
77
|
+
static async accessGroups(client, { siteId, limit, offset, }) {
|
|
78
|
+
const res = await api_1.Membership.accessGroups(client, {
|
|
79
|
+
siteId,
|
|
80
|
+
limit,
|
|
81
|
+
offset,
|
|
82
|
+
});
|
|
83
|
+
return (0, _1.ResponseWrapper)(res);
|
|
84
|
+
}
|
|
68
85
|
/**
|
|
69
86
|
* Remove a User
|
|
70
87
|
* @param client The Webflow client
|
package/dist/wrapper/site.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateWebhookParams, CollectionWrapper, WebhookWrapper } from ".";
|
|
1
|
+
import { CreateWebhookParams, CollectionWrapper, WebhookWrapper, MembershipWrapper } from ".";
|
|
2
2
|
import { Client, QueryString } from "../core";
|
|
3
3
|
import { Site } from "../api";
|
|
4
4
|
export declare class SiteWrapper implements Site.ISite {
|
|
@@ -116,4 +116,53 @@ export declare class SiteWrapper implements Site.ISite {
|
|
|
116
116
|
* @returns The created webhook
|
|
117
117
|
*/
|
|
118
118
|
createWebhook({ triggerType, filter, url }: CreateWebhookParams): Promise<import("./response").MetaResponse<WebhookWrapper>>;
|
|
119
|
+
/**
|
|
120
|
+
* Get a list of Users
|
|
121
|
+
* @param params The params for the request
|
|
122
|
+
* @param params.limit The number of items to return (optional)
|
|
123
|
+
* @param params.offset The number of items to skip (optional)
|
|
124
|
+
* @returns A list of Users
|
|
125
|
+
*/
|
|
126
|
+
users({ limit, offset }?: {
|
|
127
|
+
limit?: number;
|
|
128
|
+
offset?: number;
|
|
129
|
+
}): Promise<import("./response").MetaResponse<MembershipWrapper[]>>;
|
|
130
|
+
/**
|
|
131
|
+
* Get a single User
|
|
132
|
+
* @param params The params for the request
|
|
133
|
+
* @param params.userId The user ID
|
|
134
|
+
* @returns A single User
|
|
135
|
+
*/
|
|
136
|
+
user({ userId }: {
|
|
137
|
+
userId: string;
|
|
138
|
+
}): Promise<MembershipWrapper>;
|
|
139
|
+
/**
|
|
140
|
+
* Invite a User to a site
|
|
141
|
+
* @param params The params for the request
|
|
142
|
+
* @param params.email The email address of the user to invite
|
|
143
|
+
* @returns The newly created User
|
|
144
|
+
*/
|
|
145
|
+
inviteUser({ email }: {
|
|
146
|
+
email: string;
|
|
147
|
+
}): Promise<import("./response").MetaResponse<import("../api/membership").IUser>>;
|
|
148
|
+
/**
|
|
149
|
+
* Get a list of Access Groups
|
|
150
|
+
* @param params The params for the request
|
|
151
|
+
* @param params.limit The number of items to return (optional)
|
|
152
|
+
* @param params.offset The number of items to skip (optional)
|
|
153
|
+
* @returns A list of Access Groups
|
|
154
|
+
*/
|
|
155
|
+
accessGroups({ limit, offset, }?: {
|
|
156
|
+
limit?: number;
|
|
157
|
+
offset?: number;
|
|
158
|
+
}): Promise<import("./response").MetaResponse<import("../api/membership").PaginatedAccessGroups>>;
|
|
159
|
+
/**
|
|
160
|
+
* Remove a User
|
|
161
|
+
* @param params The params for the request
|
|
162
|
+
* @param params.userId The user ID
|
|
163
|
+
* @returns The result of the remove
|
|
164
|
+
*/
|
|
165
|
+
removeUser({ userId }: {
|
|
166
|
+
userId: string;
|
|
167
|
+
}): Promise<import("./response").MetaResponse<import("../api/membership").IUserDelete>>;
|
|
119
168
|
}
|
package/dist/wrapper/site.js
CHANGED
|
@@ -132,5 +132,60 @@ class SiteWrapper {
|
|
|
132
132
|
const _params = { url, siteId: this._id, triggerType, filter };
|
|
133
133
|
return _1.WebhookWrapper.create(this.client, _params);
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Get a list of Users
|
|
137
|
+
* @param params The params for the request
|
|
138
|
+
* @param params.limit The number of items to return (optional)
|
|
139
|
+
* @param params.offset The number of items to skip (optional)
|
|
140
|
+
* @returns A list of Users
|
|
141
|
+
*/
|
|
142
|
+
async users({ limit, offset } = {}) {
|
|
143
|
+
return _1.MembershipWrapper.list(this.client, {
|
|
144
|
+
siteId: this._id,
|
|
145
|
+
limit,
|
|
146
|
+
offset,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get a single User
|
|
151
|
+
* @param params The params for the request
|
|
152
|
+
* @param params.userId The user ID
|
|
153
|
+
* @returns A single User
|
|
154
|
+
*/
|
|
155
|
+
async user({ userId }) {
|
|
156
|
+
return _1.MembershipWrapper.getOne(this.client, { siteId: this._id, userId });
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Invite a User to a site
|
|
160
|
+
* @param params The params for the request
|
|
161
|
+
* @param params.email The email address of the user to invite
|
|
162
|
+
* @returns The newly created User
|
|
163
|
+
*/
|
|
164
|
+
async inviteUser({ email }) {
|
|
165
|
+
return _1.MembershipWrapper.invite(this.client, { siteId: this._id, email });
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get a list of Access Groups
|
|
169
|
+
* @param params The params for the request
|
|
170
|
+
* @param params.limit The number of items to return (optional)
|
|
171
|
+
* @param params.offset The number of items to skip (optional)
|
|
172
|
+
* @returns A list of Access Groups
|
|
173
|
+
*/
|
|
174
|
+
async accessGroups({ limit, offset, } = {}) {
|
|
175
|
+
return _1.MembershipWrapper.accessGroups(this.client, {
|
|
176
|
+
siteId: this._id,
|
|
177
|
+
limit,
|
|
178
|
+
offset,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Remove a User
|
|
183
|
+
* @param params The params for the request
|
|
184
|
+
* @param params.userId The user ID
|
|
185
|
+
* @returns The result of the remove
|
|
186
|
+
*/
|
|
187
|
+
async removeUser({ userId }) {
|
|
188
|
+
return _1.MembershipWrapper.remove(this.client, { siteId: this._id, userId });
|
|
189
|
+
}
|
|
135
190
|
}
|
|
136
191
|
exports.SiteWrapper = SiteWrapper;
|
package/package.json
CHANGED
package/src/api/item.ts
CHANGED
package/src/api/membership.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, PaginatedData,
|
|
1
|
+
import { Client, PaginatedData, requireArgs } from "../core";
|
|
2
2
|
|
|
3
3
|
/**************************************************************
|
|
4
4
|
* Interfaces
|
|
@@ -11,6 +11,14 @@ export interface IUser {
|
|
|
11
11
|
data: any;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface IAccessGroup {
|
|
15
|
+
_id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
shortId: string;
|
|
18
|
+
slug: string;
|
|
19
|
+
createdOn: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export interface IUserDelete {
|
|
15
23
|
deleted: number;
|
|
16
24
|
}
|
|
@@ -22,6 +30,10 @@ export type PaginatedUsers = PaginatedData & {
|
|
|
22
30
|
users: IUser[];
|
|
23
31
|
};
|
|
24
32
|
|
|
33
|
+
export type PaginatedAccessGroups = PaginatedData & {
|
|
34
|
+
accessGroups: IAccessGroup[];
|
|
35
|
+
};
|
|
36
|
+
|
|
25
37
|
export type UserIdParam = { siteId: string; userId: string };
|
|
26
38
|
|
|
27
39
|
/**************************************************************
|
|
@@ -78,9 +90,8 @@ export function update(
|
|
|
78
90
|
{
|
|
79
91
|
siteId,
|
|
80
92
|
userId,
|
|
81
|
-
data
|
|
93
|
+
...data
|
|
82
94
|
}: {
|
|
83
|
-
data: object;
|
|
84
95
|
siteId: string;
|
|
85
96
|
userId: string;
|
|
86
97
|
}
|
|
@@ -123,3 +134,22 @@ export function remove(
|
|
|
123
134
|
const path = `/sites/${siteId}/users/${userId}`;
|
|
124
135
|
return client.delete<IUserDelete>(path);
|
|
125
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
|
+
}
|
package/src/core/client.ts
CHANGED
|
@@ -17,11 +17,32 @@ export interface PaginatedData {
|
|
|
17
17
|
total: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
46
|
}
|
|
26
47
|
|
|
27
48
|
/**************************************************************
|
|
@@ -35,7 +56,8 @@ export class Client extends Axios {
|
|
|
35
56
|
token,
|
|
36
57
|
}: Options = {}) {
|
|
37
58
|
super({
|
|
38
|
-
transformRequest: [
|
|
59
|
+
transformRequest: [transformRequest],
|
|
60
|
+
transformResponse: [transformResponse],
|
|
39
61
|
baseURL: `https://api.${host}/`,
|
|
40
62
|
headers: {
|
|
41
63
|
"Content-Type": "application/json",
|
|
@@ -46,22 +68,6 @@ export class Client extends Axios {
|
|
|
46
68
|
});
|
|
47
69
|
|
|
48
70
|
if (token) this.token = token;
|
|
49
|
-
|
|
50
|
-
// check for webflow errors
|
|
51
|
-
this.defaults.transformResponse = [this.transformResponse];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Transforms JSON response to an object
|
|
56
|
-
* if the response is a Webflow error, it will throw an error
|
|
57
|
-
* @param data JSON response
|
|
58
|
-
* @returns response object
|
|
59
|
-
*/
|
|
60
|
-
private transformResponse(data: any = {}) {
|
|
61
|
-
// parse json if string
|
|
62
|
-
if (String(data) === data) data = JSON.parse(data);
|
|
63
|
-
if (data.err) throw new RequestError(data);
|
|
64
|
-
return data;
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
// set the Authorization header
|
package/src/webflow.ts
CHANGED
|
@@ -265,7 +265,6 @@ export class Webflow {
|
|
|
265
265
|
* @param params The Item information
|
|
266
266
|
* @param params.collectionId The Collection ID
|
|
267
267
|
* @param params.itemId The Item ID
|
|
268
|
-
* @param query The query parameters (optional)
|
|
269
268
|
* @returns The updated Collection Item
|
|
270
269
|
*/
|
|
271
270
|
updateItem({
|
|
@@ -319,8 +318,7 @@ export class Webflow {
|
|
|
319
318
|
* @param params The Item information
|
|
320
319
|
* @param params.collectionId The Collection ID
|
|
321
320
|
* @param params.itemId The Item ID
|
|
322
|
-
* @param
|
|
323
|
-
* @param query.live Update the live version
|
|
321
|
+
* @param params.live Update the live version
|
|
324
322
|
* @returns The unpublished Collection Item result
|
|
325
323
|
*/
|
|
326
324
|
deleteItems({
|
|
@@ -340,8 +338,7 @@ export class Webflow {
|
|
|
340
338
|
* @param params The Item information
|
|
341
339
|
* @param params.collectionId The Collection ID
|
|
342
340
|
* @param params.itemId The Item ID
|
|
343
|
-
* @param
|
|
344
|
-
* @param query.live Update the live version
|
|
341
|
+
* @param params.live Update the live version
|
|
345
342
|
* @returns The Published Collection Item result
|
|
346
343
|
*/
|
|
347
344
|
publishItems({
|
|
@@ -366,6 +363,8 @@ export class Webflow {
|
|
|
366
363
|
* @param params The Site information
|
|
367
364
|
* @param params.siteId The Site ID
|
|
368
365
|
* @param pageParams The pagination information (optional)
|
|
366
|
+
* @param pageParams.limit The number of results to return
|
|
367
|
+
* @param pageParams.offset The number of results to skip
|
|
369
368
|
* @returns A list of User accounts
|
|
370
369
|
*/
|
|
371
370
|
async users({ siteId }: { siteId: string }, pageParams?: PaginationFilter) {
|
|
@@ -425,6 +424,16 @@ export class Webflow {
|
|
|
425
424
|
return MembershipWrapper.remove(this.client, { siteId, userId });
|
|
426
425
|
}
|
|
427
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Get a list of Access Groups
|
|
429
|
+
* @param params The Site and User information
|
|
430
|
+
* @param params.siteId The Site ID
|
|
431
|
+
* @returns The result from the remove request
|
|
432
|
+
*/
|
|
433
|
+
accessGroups({ siteId }: { siteId: string }) {
|
|
434
|
+
return MembershipWrapper.accessGroups(this.client, { siteId });
|
|
435
|
+
}
|
|
436
|
+
|
|
428
437
|
/**************************************************************
|
|
429
438
|
* Webhook Endpoints
|
|
430
439
|
**************************************************************/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ResponseWrapper, ItemWrapper } from ".";
|
|
2
2
|
import { Client, QueryString } from "../core";
|
|
3
|
-
import { Collection
|
|
3
|
+
import { Collection } from "../api";
|
|
4
4
|
|
|
5
5
|
export class CollectionWrapper implements Collection.ICollection {
|
|
6
6
|
fields: Collection.CollectionField[];
|
|
@@ -71,7 +71,7 @@ export class MembershipWrapper implements Membership.IUser {
|
|
|
71
71
|
client: Client,
|
|
72
72
|
{ userId, siteId, data }: { userId: string; siteId: string; data: any }
|
|
73
73
|
) {
|
|
74
|
-
const res = await Membership.update(client, { userId, siteId, data });
|
|
74
|
+
const res = await Membership.update(client, { userId, siteId, ...data });
|
|
75
75
|
const user = ResponseWrapper<typeof res.data>(res);
|
|
76
76
|
return new MembershipWrapper(client, siteId, user);
|
|
77
77
|
}
|
|
@@ -92,6 +92,31 @@ export class MembershipWrapper implements Membership.IUser {
|
|
|
92
92
|
return ResponseWrapper<typeof res.data>(res);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Get a list of Access Groups
|
|
97
|
+
* @param client The Webflow client
|
|
98
|
+
* @param params The params for the request
|
|
99
|
+
* @param params.siteId The Site ID
|
|
100
|
+
* @param params.limit The number of items to return (optional)
|
|
101
|
+
* @param params.offset The number of items to skip (optional)
|
|
102
|
+
* @returns A list of Access Groups
|
|
103
|
+
*/
|
|
104
|
+
static async accessGroups(
|
|
105
|
+
client: Client,
|
|
106
|
+
{
|
|
107
|
+
siteId,
|
|
108
|
+
limit,
|
|
109
|
+
offset,
|
|
110
|
+
}: { siteId: string; limit?: number; offset?: number }
|
|
111
|
+
) {
|
|
112
|
+
const res = await Membership.accessGroups(client, {
|
|
113
|
+
siteId,
|
|
114
|
+
limit,
|
|
115
|
+
offset,
|
|
116
|
+
});
|
|
117
|
+
return ResponseWrapper<typeof res.data>(res);
|
|
118
|
+
}
|
|
119
|
+
|
|
95
120
|
/**
|
|
96
121
|
* Remove a User
|
|
97
122
|
* @param client The Webflow client
|
package/src/wrapper/site.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
CollectionWrapper,
|
|
4
4
|
ResponseWrapper,
|
|
5
5
|
WebhookWrapper,
|
|
6
|
+
MembershipWrapper,
|
|
6
7
|
} from ".";
|
|
7
8
|
import { Client, QueryString } from "../core";
|
|
8
9
|
import { Site } from "../api";
|
|
@@ -161,4 +162,67 @@ export class SiteWrapper implements Site.ISite {
|
|
|
161
162
|
const _params = { url, siteId: this._id, triggerType, filter };
|
|
162
163
|
return WebhookWrapper.create(this.client, _params);
|
|
163
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get a list of Users
|
|
168
|
+
* @param params The params for the request
|
|
169
|
+
* @param params.limit The number of items to return (optional)
|
|
170
|
+
* @param params.offset The number of items to skip (optional)
|
|
171
|
+
* @returns A list of Users
|
|
172
|
+
*/
|
|
173
|
+
async users({ limit, offset }: { limit?: number; offset?: number } = {}) {
|
|
174
|
+
return MembershipWrapper.list(this.client, {
|
|
175
|
+
siteId: this._id,
|
|
176
|
+
limit,
|
|
177
|
+
offset,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get a single User
|
|
183
|
+
* @param params The params for the request
|
|
184
|
+
* @param params.userId The user ID
|
|
185
|
+
* @returns A single User
|
|
186
|
+
*/
|
|
187
|
+
async user({ userId }: { userId: string }) {
|
|
188
|
+
return MembershipWrapper.getOne(this.client, { siteId: this._id, userId });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Invite a User to a site
|
|
193
|
+
* @param params The params for the request
|
|
194
|
+
* @param params.email The email address of the user to invite
|
|
195
|
+
* @returns The newly created User
|
|
196
|
+
*/
|
|
197
|
+
async inviteUser({ email }: { email: string }) {
|
|
198
|
+
return MembershipWrapper.invite(this.client, { siteId: this._id, email });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get a list of Access Groups
|
|
203
|
+
* @param params The params for the request
|
|
204
|
+
* @param params.limit The number of items to return (optional)
|
|
205
|
+
* @param params.offset The number of items to skip (optional)
|
|
206
|
+
* @returns A list of Access Groups
|
|
207
|
+
*/
|
|
208
|
+
async accessGroups({
|
|
209
|
+
limit,
|
|
210
|
+
offset,
|
|
211
|
+
}: { limit?: number; offset?: number } = {}) {
|
|
212
|
+
return MembershipWrapper.accessGroups(this.client, {
|
|
213
|
+
siteId: this._id,
|
|
214
|
+
limit,
|
|
215
|
+
offset,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Remove a User
|
|
221
|
+
* @param params The params for the request
|
|
222
|
+
* @param params.userId The user ID
|
|
223
|
+
* @returns The result of the remove
|
|
224
|
+
*/
|
|
225
|
+
async removeUser({ userId }: { userId: string }) {
|
|
226
|
+
return MembershipWrapper.remove(this.client, { siteId: this._id, userId });
|
|
227
|
+
}
|
|
164
228
|
}
|