Skip to content

Commit 2305de2

Browse files
author
John Agan
authored
Merge pull request #59 from webflow/users-api
Adding Methods for Users API
2 parents 3446ca5 + 2d6b8de commit 2305de2

File tree

9 files changed

+237
-96
lines changed

9 files changed

+237
-96
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*]
2+
max_line_length = 80

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2-
"extends": "airbnb-base",
2+
"extends": ["airbnb-base", "prettier"],
3+
"plugins": ["prettier"],
34
"rules": {
45
"no-underscore-dangle": 0,
5-
"class-methods-use-this": 0
6+
"class-methods-use-this": 0,
7+
"prettier/prettier": ["error"]
68
}
79
}

index.d.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,37 @@ declare class Webflow {
7272
query?: Webflow.WebflowQueryArg
7373
): Promise<Webflow.WebflowApiModel.Collection>;
7474

75+
// Users
76+
users(
77+
data: {
78+
siteId: string;
79+
},
80+
query?: Webflow.WebflowQueryArg
81+
): Promise<Webflow.WebflowApiModel.User[]>;
82+
83+
user(
84+
data: {
85+
siteId: string;
86+
userId: string;
87+
},
88+
query?: Webflow.WebflowQueryArg
89+
): Promise<Webflow.WebflowApiModel.User>;
90+
91+
updateUser(
92+
data: { siteId: string; userId: string } & Record<string, any>,
93+
query?: Webflow.WebflowQueryArg
94+
): Promise<Webflow.WebflowApiModel.User>;
95+
96+
removeUser(
97+
data: { siteId: string; userId: string },
98+
query?: Webflow.WebflowQueryArg
99+
): Promise<{ deleted: number }>;
100+
101+
inviteUser(
102+
data: { siteId: string; email: string },
103+
query?: Webflow.WebflowQueryArg
104+
): Promise<Webflow.WebflowApiModel.User>;
105+
75106
// Items
76107

77108
items(
@@ -213,6 +244,14 @@ declare namespace Webflow {
213244
name: string;
214245
}
215246

247+
interface User {
248+
_id: string;
249+
lastUpdated: string;
250+
createdOn: string;
251+
emailVerified: boolean;
252+
data: object;
253+
}
254+
216255
/**
217256
* https://developers.webflow.com/?javascript#collections
218257
*/
@@ -301,7 +340,7 @@ declare namespace Webflow {
301340
rateLimit: {
302341
limit: number;
303342
remaining: number;
304-
}
343+
};
305344
}
306345

307346
interface ItemsResponse {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webflow-api",
3-
"version": "0.7.2",
3+
"version": "0.8.0",
44
"description": "SDK for the Webflow CMS API",
55
"main": "dist/index.js",
66
"jsnext:main": "src/index.js",
@@ -34,13 +34,14 @@
3434
"ava": "^4.1.0",
3535
"eslint": "^8.12.0",
3636
"eslint-config-airbnb-base": "^15.0.0",
37+
"eslint-config-prettier": "^8.5.0",
3738
"eslint-plugin-import": "^2.25.2",
3839
"nock": "^13.0.7",
3940
"nyc": "^15.1.0"
4041
},
4142
"dependencies": {
42-
"isomorphic-fetch": "^3.0.0",
4343
"es6-error": "^4.0.0",
44+
"isomorphic-fetch": "^3.0.0",
4445
"qs": "^6.3.0"
4546
},
4647
"ava": {

src/ResponseWrapper.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,28 @@ export default class ResponseWrapper {
3737

3838
items: this.api.items.bind(this.api, { collectionId: collection._id }),
3939
item(first, ...rest) {
40-
return this.api.item({ ...first, collectionId: collection._id }, ...rest);
40+
return this.api.item(
41+
{ ...first, collectionId: collection._id },
42+
...rest
43+
);
4144
},
4245
createItem(first, ...rest) {
43-
return this.api.createItem({ ...first, collectionId: collection._id }, ...rest);
46+
return this.api.createItem(
47+
{ ...first, collectionId: collection._id },
48+
...rest
49+
);
4450
},
4551
updateItem(first, ...rest) {
46-
return this.api.updateItem({ ...first, collectionId: collection._id }, ...rest);
52+
return this.api.updateItem(
53+
{ ...first, collectionId: collection._id },
54+
...rest
55+
);
4756
},
4857
removeItem(first, ...rest) {
49-
return this.api.removeItem({ ...first, collectionId: collection._id }, ...rest);
58+
return this.api.removeItem(
59+
{ ...first, collectionId: collection._id },
60+
...rest
61+
);
5062
},
5163
};
5264
}
@@ -56,17 +68,39 @@ export default class ResponseWrapper {
5668
...item,
5769

5870
update(first, ...rest) {
59-
return this.api.updateItem({ ...first, collectionId, itemId: item._id }, ...rest);
71+
return this.api.updateItem(
72+
{ ...first, collectionId, itemId: item._id },
73+
...rest
74+
);
75+
},
76+
remove: this.api.updateItem.bind(this.api, {
77+
collectionId,
78+
itemId: item._id,
79+
}),
80+
};
81+
}
82+
83+
user(user, siteId) {
84+
return {
85+
...user,
86+
87+
update(first, ...rest) {
88+
return this.api.updateUser({ ...first, siteId }, ...rest);
89+
},
90+
remove(first, ...rest) {
91+
return this.api.removeUser({ ...first, siteId }, ...rest);
6092
},
61-
remove: this.api.updateItem.bind(this.api, { collectionId, itemId: item._id }),
6293
};
6394
}
6495

6596
webhook(webhook, siteId) {
6697
return {
6798
...webhook,
6899

69-
remove: this.api.removeWebhook.bind(this.api, { siteId, webhookId: webhook._id }),
100+
remove: this.api.removeWebhook.bind(this.api, {
101+
siteId,
102+
webhookId: webhook._id,
103+
}),
70104
};
71105
}
72106
}

0 commit comments

Comments
 (0)