Skip to content

Commit

Permalink
Merge pull request #59 from webflow/users-api
Browse files Browse the repository at this point in the history
Adding Methods for Users API
  • Loading branch information
John Agan authored Jun 23, 2022
2 parents 3446ca5 + 2d6b8de commit 2305de2
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 96 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*]
max_line_length = 80
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "airbnb-base",
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"rules": {
"no-underscore-dangle": 0,
"class-methods-use-this": 0
"class-methods-use-this": 0,
"prettier/prettier": ["error"]
}
}
41 changes: 40 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ declare class Webflow {
query?: Webflow.WebflowQueryArg
): Promise<Webflow.WebflowApiModel.Collection>;

// Users
users(
data: {
siteId: string;
},
query?: Webflow.WebflowQueryArg
): Promise<Webflow.WebflowApiModel.User[]>;

user(
data: {
siteId: string;
userId: string;
},
query?: Webflow.WebflowQueryArg
): Promise<Webflow.WebflowApiModel.User>;

updateUser(
data: { siteId: string; userId: string } & Record<string, any>,
query?: Webflow.WebflowQueryArg
): Promise<Webflow.WebflowApiModel.User>;

removeUser(
data: { siteId: string; userId: string },
query?: Webflow.WebflowQueryArg
): Promise<{ deleted: number }>;

inviteUser(
data: { siteId: string; email: string },
query?: Webflow.WebflowQueryArg
): Promise<Webflow.WebflowApiModel.User>;

// Items

items(
Expand Down Expand Up @@ -213,6 +244,14 @@ declare namespace Webflow {
name: string;
}

interface User {
_id: string;
lastUpdated: string;
createdOn: string;
emailVerified: boolean;
data: object;
}

/**
* https://developers.webflow.com/?javascript#collections
*/
Expand Down Expand Up @@ -301,7 +340,7 @@ declare namespace Webflow {
rateLimit: {
limit: number;
remaining: number;
}
};
}

interface ItemsResponse {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webflow-api",
"version": "0.7.2",
"version": "0.8.0",
"description": "SDK for the Webflow CMS API",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
Expand Down Expand Up @@ -34,13 +34,14 @@
"ava": "^4.1.0",
"eslint": "^8.12.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.2",
"nock": "^13.0.7",
"nyc": "^15.1.0"
},
"dependencies": {
"isomorphic-fetch": "^3.0.0",
"es6-error": "^4.0.0",
"isomorphic-fetch": "^3.0.0",
"qs": "^6.3.0"
},
"ava": {
Expand Down
48 changes: 41 additions & 7 deletions src/ResponseWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,28 @@ export default class ResponseWrapper {

items: this.api.items.bind(this.api, { collectionId: collection._id }),
item(first, ...rest) {
return this.api.item({ ...first, collectionId: collection._id }, ...rest);
return this.api.item(
{ ...first, collectionId: collection._id },
...rest
);
},
createItem(first, ...rest) {
return this.api.createItem({ ...first, collectionId: collection._id }, ...rest);
return this.api.createItem(
{ ...first, collectionId: collection._id },
...rest
);
},
updateItem(first, ...rest) {
return this.api.updateItem({ ...first, collectionId: collection._id }, ...rest);
return this.api.updateItem(
{ ...first, collectionId: collection._id },
...rest
);
},
removeItem(first, ...rest) {
return this.api.removeItem({ ...first, collectionId: collection._id }, ...rest);
return this.api.removeItem(
{ ...first, collectionId: collection._id },
...rest
);
},
};
}
Expand All @@ -56,17 +68,39 @@ export default class ResponseWrapper {
...item,

update(first, ...rest) {
return this.api.updateItem({ ...first, collectionId, itemId: item._id }, ...rest);
return this.api.updateItem(
{ ...first, collectionId, itemId: item._id },
...rest
);
},
remove: this.api.updateItem.bind(this.api, {
collectionId,
itemId: item._id,
}),
};
}

user(user, siteId) {
return {
...user,

update(first, ...rest) {
return this.api.updateUser({ ...first, siteId }, ...rest);
},
remove(first, ...rest) {
return this.api.removeUser({ ...first, siteId }, ...rest);
},
remove: this.api.updateItem.bind(this.api, { collectionId, itemId: item._id }),
};
}

webhook(webhook, siteId) {
return {
...webhook,

remove: this.api.removeWebhook.bind(this.api, { siteId, webhookId: webhook._id }),
remove: this.api.removeWebhook.bind(this.api, {
siteId,
webhookId: webhook._id,
}),
};
}
}
Loading

0 comments on commit 2305de2

Please sign in to comment.