webflow-api 1.1.2 → 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.
Files changed (72) hide show
  1. package/README.md +41 -17
  2. package/dist/api/collection.d.ts +86 -25
  3. package/dist/api/collection.js +88 -29
  4. package/dist/api/index.d.ts +7 -7
  5. package/dist/api/index.js +9 -19
  6. package/dist/api/item.d.ts +141 -107
  7. package/dist/api/item.js +145 -125
  8. package/dist/api/meta.d.ts +16 -14
  9. package/dist/api/meta.js +20 -19
  10. package/dist/api/oauth.d.ts +38 -36
  11. package/dist/api/oauth.js +59 -59
  12. package/dist/api/site.d.ts +118 -43
  13. package/dist/api/site.js +131 -53
  14. package/dist/api/user.d.ts +143 -0
  15. package/dist/api/user.js +119 -0
  16. package/dist/api/webhook.d.ts +77 -55
  17. package/dist/api/webhook.js +74 -61
  18. package/dist/core/error.d.ts +2 -0
  19. package/dist/core/error.js +8 -1
  20. package/dist/core/index.d.ts +2 -2
  21. package/dist/core/index.js +2 -2
  22. package/dist/core/response.d.ts +32 -0
  23. package/dist/core/response.js +26 -0
  24. package/dist/{webflow.d.ts → core/webflow.d.ts} +66 -54
  25. package/dist/{webflow.js → core/webflow.js} +114 -65
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +2 -2
  28. package/package.json +12 -8
  29. package/src/api/collection.ts +103 -36
  30. package/src/api/index.ts +7 -7
  31. package/src/api/item.ts +217 -176
  32. package/src/api/meta.ts +19 -18
  33. package/src/api/oauth.ts +71 -74
  34. package/src/api/site.ts +161 -55
  35. package/src/api/user.ts +192 -0
  36. package/src/api/webhook.ts +103 -80
  37. package/src/core/error.ts +8 -0
  38. package/src/core/index.ts +2 -2
  39. package/src/core/response.ts +50 -0
  40. package/src/{webflow.ts → core/webflow.ts} +153 -125
  41. package/src/index.ts +1 -1
  42. package/yarn.lock +4 -9
  43. package/dist/api/membership.d.ts +0 -114
  44. package/dist/api/membership.js +0 -96
  45. package/dist/core/client.d.ts +0 -27
  46. package/dist/core/client.js +0 -60
  47. package/dist/core/options.d.ts +0 -8
  48. package/dist/core/options.js +0 -5
  49. package/dist/wrapper/collection.d.ts +0 -85
  50. package/dist/wrapper/collection.js +0 -94
  51. package/dist/wrapper/index.d.ts +0 -6
  52. package/dist/wrapper/index.js +0 -22
  53. package/dist/wrapper/item.d.ts +0 -140
  54. package/dist/wrapper/item.js +0 -153
  55. package/dist/wrapper/membership.d.ts +0 -105
  56. package/dist/wrapper/membership.js +0 -123
  57. package/dist/wrapper/response.d.ts +0 -16
  58. package/dist/wrapper/response.js +0 -17
  59. package/dist/wrapper/site.d.ts +0 -168
  60. package/dist/wrapper/site.js +0 -191
  61. package/dist/wrapper/webhook.d.ts +0 -78
  62. package/dist/wrapper/webhook.js +0 -82
  63. package/src/api/membership.ts +0 -155
  64. package/src/core/client.ts +0 -82
  65. package/src/core/options.ts +0 -9
  66. package/src/wrapper/collection.ts +0 -115
  67. package/src/wrapper/index.ts +0 -6
  68. package/src/wrapper/item.ts +0 -218
  69. package/src/wrapper/membership.ts +0 -163
  70. package/src/wrapper/response.ts +0 -25
  71. package/src/wrapper/site.ts +0 -228
  72. package/src/wrapper/webhook.ts +0 -116
package/src/api/item.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Client, PaginatedData, requireArgs } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { PaginatedData, requireArgs, WebflowRecord } from "../core";
2
3
 
3
4
  /**************************************************************
4
5
  * Interfaces
@@ -40,192 +41,232 @@ export type PageinatedItems = PaginatedData & {
40
41
  };
41
42
 
42
43
  /**************************************************************
43
- * Functions
44
+ * Class
44
45
  **************************************************************/
45
46
 
46
- /**
47
- * Get a single Item
48
- * @param client The Webflow client
49
- * @param params The params for the request
50
- * @param params.collectionId The Collection ID
51
- * @param params.itemId The Item ID
52
- * @returns A single Item
53
- */
54
- export function getOne(
55
- client: Client,
56
- { collectionId, itemId }: { collectionId: string; itemId: string }
57
- ) {
58
- requireArgs({ collectionId, itemId });
59
- const path = `/collections/${collectionId}/items/${itemId}`;
60
- // The API returns a paginated list with one record :(
61
- return client.get<PageinatedItems>(path);
62
- }
47
+ export class Item extends WebflowRecord<IItem> implements IItem {
48
+ "published-on"?: string | null;
49
+ "published-by"?: string | null;
50
+ "updated-on": string;
51
+ "created-on": string;
52
+ "updated-by": string;
53
+ "created-by": string;
54
+ _archived: boolean;
55
+ _draft: boolean;
56
+ _cid: string;
57
+ name: string;
58
+ slug: string;
59
+ _id: string;
63
60
 
64
- /**
65
- * Get a list of Items
66
- * @param client The Webflow client
67
- * @param params The params for the request
68
- * @param params.collectionId The Collection ID
69
- * @param params.limit The number of items to return (optional)
70
- * @param params.offset The number of items to skip (optional)
71
- * @returns A list of Items
72
- */
73
- export function list(
74
- client: Client,
75
- {
76
- collectionId,
77
- limit,
78
- offset,
79
- }: { collectionId: string; limit?: number; offset?: number }
80
- ) {
81
- requireArgs({ collectionId });
82
- const params = { limit, offset };
83
- const path = `/collections/${collectionId}/items`;
84
- return client.get<PageinatedItems>(path, { params });
85
- }
61
+ /**************************************************************
62
+ * Static Methods
63
+ **************************************************************/
86
64
 
87
- /**
88
- * Create a new Item
89
- * @param client The Webflow client
90
- * @param params The params for the request
91
- * @param params.collectionId The Collection ID
92
- * @param params.fields The Item fields to create
93
- * @returns The created Item
94
- */
95
- export function create(
96
- client: Client,
97
- { collectionId, fields }: { fields: any; collectionId: string }
98
- ) {
99
- requireArgs({ collectionId });
100
- const path = `/collections/${collectionId}/items`;
101
- return client.post<IItem>(path, { fields });
102
- }
65
+ /**
66
+ * Get a single Item
67
+ * @param params The params for the request
68
+ * @param params.collectionId The Collection ID
69
+ * @param params.itemId The Item ID
70
+ * @param client The Axios client instance
71
+ * @returns A single Item
72
+ */
73
+ static getOne(
74
+ { collectionId, itemId }: { collectionId: string; itemId: string },
75
+ client: AxiosInstance,
76
+ ) {
77
+ requireArgs({ collectionId, itemId });
78
+ const path = `/collections/${collectionId}/items/${itemId}`;
79
+ // The API returns a paginated list with one record :(
80
+ return client.get<PageinatedItems>(path);
81
+ }
103
82
 
104
- /**
105
- * Update a single Item
106
- * @param client The Webflow client
107
- * @param params The params for the request
108
- * @param params.collectionId The Collection ID
109
- * @param params.itemId The Item ID
110
- * @param params.fields The fields to update
111
- * @returns The updated Item
112
- */
113
- export function update(
114
- client: Client,
115
- {
116
- collectionId,
117
- itemId,
118
- fields,
119
- }: {
120
- fields: any;
121
- itemId: string;
122
- collectionId: string;
83
+ /**
84
+ * Get a list of Items
85
+ * @param params The params for the request
86
+ * @param params.collectionId The Collection ID
87
+ * @param params.limit The number of items to return (optional)
88
+ * @param params.offset The number of items to skip (optional)
89
+ * @param client The Axios client instance
90
+ * @returns A list of Items
91
+ */
92
+ static list(
93
+ { collectionId, limit, offset }: { collectionId: string; limit?: number; offset?: number },
94
+ client: AxiosInstance,
95
+ ) {
96
+ requireArgs({ collectionId });
97
+ const params = { limit, offset };
98
+ const path = `/collections/${collectionId}/items`;
99
+ return client.get<PageinatedItems>(path, { params });
123
100
  }
124
- ) {
125
- requireArgs({ collectionId, itemId });
126
- const path = `/collections/${collectionId}/items/${itemId}`;
127
- return client.put<IItem>(path, { fields });
128
- }
129
101
 
130
- /**
131
- * Patch a single Item
132
- * @param client The Webflow client
133
- * @param params The params for the request
134
- * @param params.collectionId The Collection ID
135
- * @param params.itemId The Item ID
136
- * @param params.fields The fields to patch
137
- * @returns The patched Item
138
- */
139
- export function patch(
140
- client: Client,
141
- {
142
- collectionId,
143
- itemId,
144
- fields,
145
- }: {
146
- fields: any;
147
- itemId: string;
148
- collectionId: string;
102
+ /**
103
+ * Create a new Item
104
+ * @param params The params for the request
105
+ * @param params.collectionId The Collection ID
106
+ * @param params.fields The Item fields to create
107
+ * @param client The Axios client instance
108
+ * @returns The created Item
109
+ */
110
+ static create(
111
+ { collectionId, fields }: { fields: any; collectionId: string },
112
+ client: AxiosInstance,
113
+ ) {
114
+ requireArgs({ collectionId });
115
+ const path = `/collections/${collectionId}/items`;
116
+ return client.post<IItem>(path, { fields });
149
117
  }
150
- ) {
151
- requireArgs({ collectionId, itemId });
152
- const path = `/collections/${collectionId}/items/${itemId}`;
153
- return client.patch<IItem>(path, { fields });
154
- }
155
118
 
156
- /**
157
- * Remove a single Item
158
- * @param client The Webflow client
159
- * @param params The params for the request
160
- * @param params.collectionId The Collection ID
161
- * @param params.itemId The Item ID
162
- * @returns The result from the removal
163
- */
164
- export function remove(
165
- client: Client,
166
- {
167
- collectionId,
168
- itemId,
169
- }: {
170
- itemId: string;
171
- collectionId: string;
119
+ /**
120
+ * Update a single Item
121
+ * @param params The params for the request
122
+ * @param params.collectionId The Collection ID
123
+ * @param params.itemId The Item ID
124
+ * @param params.fields The fields to update
125
+ * @param client The Axios client instance
126
+ * @returns The updated Item
127
+ */
128
+ static update(
129
+ {
130
+ collectionId,
131
+ itemId,
132
+ fields,
133
+ }: {
134
+ fields: any;
135
+ itemId: string;
136
+ collectionId: string;
137
+ },
138
+ client: AxiosInstance,
139
+ ) {
140
+ requireArgs({ collectionId, itemId });
141
+ const path = `/collections/${collectionId}/items/${itemId}`;
142
+ return client.put<IItem>(path, { fields });
172
143
  }
173
- ) {
174
- requireArgs({ collectionId, itemId });
175
- const path = `/collections/${collectionId}/items/${itemId}`;
176
- return client.delete<IItemDelete>(path);
177
- }
178
144
 
179
- /**
180
- * Unpublishes a list of Items
181
- * @param client The Webflow client
182
- * @param params The params for the request
183
- * @param params.collectionId The Collection ID
184
- * @param params.live Unpublish from the live site
185
- * @returns The result of the unpublish
186
- */
187
- export function unpublish(
188
- client: Client,
189
- {
190
- collectionId,
191
- itemIds,
192
- live = false,
193
- }: {
194
- live?: boolean;
195
- itemIds: string[];
196
- collectionId: string;
145
+ /**
146
+ * Patch a single Item
147
+ * @param params The params for the request
148
+ * @param params.collectionId The Collection ID
149
+ * @param params.itemId The Item ID
150
+ * @param params.fields The fields to patch
151
+ * @param client The Axios client instance
152
+ * @returns The patched Item
153
+ */
154
+ static patch(
155
+ {
156
+ collectionId,
157
+ itemId,
158
+ fields,
159
+ }: {
160
+ fields: any;
161
+ itemId: string;
162
+ collectionId: string;
163
+ },
164
+ client: AxiosInstance,
165
+ ) {
166
+ requireArgs({ collectionId, itemId });
167
+ const path = `/collections/${collectionId}/items/${itemId}`;
168
+ return client.patch<IItem>(path, { fields });
197
169
  }
198
- ) {
199
- requireArgs({ collectionId, itemIds });
200
- const params = { live };
201
- const data = { itemIds };
202
- const url = `/collections/${collectionId}/items`;
203
- const _params = { method: "DELETE", url, data, params };
204
-
205
- // DELETE spec doesn't support body in delete
206
- // RFC-9110 https://tools.ietf.org/html/rfc9110
207
- return client.request<IDeletedItems>(_params);
208
- }
209
170
 
210
- /**
211
- * Publishes a list of Items
212
- * @param client The Webflow client
213
- * @param params The request parameters
214
- * @param params.collectionId The Collection ID
215
- * @param params.itemIds The list of Item IDs to publish
216
- * @param params.live Publish to live site
217
- * @returns The result of the publish
218
- */
219
- export function publish(
220
- client: Client,
221
- {
222
- itemIds,
223
- live = false,
224
- collectionId,
225
- }: { live?: boolean; itemIds: string[]; collectionId: string }
226
- ) {
227
- requireArgs({ collectionId, itemIds });
228
- const params = { live };
229
- const path = `/collections/${collectionId}/items/publish`;
230
- return client.put<IPublishItems>(path, { itemIds }, { params });
171
+ /**
172
+ * Remove a single Item
173
+ * @param params The params for the request
174
+ * @param params.collectionId The Collection ID
175
+ * @param params.itemId The Item ID
176
+ * @param client The Axios client instance
177
+ * @returns The result from the removal
178
+ */
179
+ static remove(
180
+ {
181
+ collectionId,
182
+ itemId,
183
+ }: {
184
+ itemId: string;
185
+ collectionId: string;
186
+ },
187
+ client: AxiosInstance,
188
+ ) {
189
+ requireArgs({ collectionId, itemId });
190
+ const path = `/collections/${collectionId}/items/${itemId}`;
191
+ return client.delete<IItemDelete>(path);
192
+ }
193
+
194
+ /**
195
+ * Unpublishes a list of Items
196
+ * @param params The params for the request
197
+ * @param params.collectionId The Collection ID
198
+ * @param params.live Unpublish from the live site
199
+ * @param client The Axios client instance
200
+ * @returns The result of the unpublish
201
+ */
202
+ static unpublish(
203
+ {
204
+ collectionId,
205
+ itemIds,
206
+ live = false,
207
+ }: {
208
+ live?: boolean;
209
+ itemIds: string[];
210
+ collectionId: string;
211
+ },
212
+ client: AxiosInstance,
213
+ ) {
214
+ requireArgs({ collectionId, itemIds });
215
+ const params = { live };
216
+ const data = { itemIds };
217
+ const url = `/collections/${collectionId}/items`;
218
+ const _params = { method: "DELETE", url, data, params };
219
+
220
+ // DELETE spec doesn't support body in delete
221
+ // RFC-9110 https://tools.ietf.org/html/rfc9110
222
+ return client.request<IDeletedItems>(_params);
223
+ }
224
+
225
+ /**
226
+ * Publishes a list of Items
227
+ * @param params The request parameters
228
+ * @param params.collectionId The Collection ID
229
+ * @param params.itemIds The list of Item IDs to publish
230
+ * @param params.live Publish to live site
231
+ * @param client The Axios client instance
232
+ * @returns The result of the publish
233
+ */
234
+ static publish(
235
+ {
236
+ itemIds,
237
+ live = false,
238
+ collectionId,
239
+ }: { live?: boolean; itemIds: string[]; collectionId: string },
240
+ client: AxiosInstance,
241
+ ) {
242
+ requireArgs({ collectionId, itemIds });
243
+ const params = { live };
244
+ const path = `/collections/${collectionId}/items/publish`;
245
+ return client.put<IPublishItems>(path, { itemIds }, { params });
246
+ }
247
+
248
+ /**************************************************************
249
+ * Instance Methods
250
+ **************************************************************/
251
+
252
+ /**
253
+ * Update a single Item
254
+ * @param fields The fields to update
255
+ * @returns The updated Item
256
+ */
257
+ async update({ ...fields }) {
258
+ const params = { collectionId: this._cid, itemId: this._id, fields };
259
+ const res = await Item.update(params, this.client);
260
+ return new Item(this.client, res);
261
+ }
262
+
263
+ /**
264
+ * Remove a single Item
265
+ * @returns The result from the removal
266
+ */
267
+ async remove() {
268
+ const params = { collectionId: this._cid, itemId: this._id };
269
+ const res = await Item.remove(params, this.client);
270
+ return res.data;
271
+ }
231
272
  }
package/src/api/meta.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Client } from "../core";
1
+ import { AxiosInstance } from "axios";
2
2
 
3
3
  /**************************************************************
4
4
  * Types
@@ -39,23 +39,24 @@ export interface IAuthentiationInfo {
39
39
  }
40
40
 
41
41
  /**************************************************************
42
- * Functions
42
+ * Class
43
43
  **************************************************************/
44
+ export class Meta {
45
+ /**
46
+ * Get the authentication info for the current token
47
+ * @param client The Axios client instance
48
+ * @returns The authentication info
49
+ */
50
+ static info(client: AxiosInstance) {
51
+ return client.get<IAuthentiationInfo>("/info");
52
+ }
44
53
 
45
- /**
46
- * Get the authentication info for the current token
47
- * @param client The Webflow client
48
- * @returns The authentication info
49
- */
50
- export function info(client: Client) {
51
- return client.get<IAuthentiationInfo>("/info");
52
- }
53
-
54
- /**
55
- * Get the authenticated user
56
- * @param client The Webflow client
57
- * @returns The authenticated user
58
- */
59
- export function user(client: Client) {
60
- return client.get<IAuthenticatedUser>("/user");
54
+ /**
55
+ * Get the authenticated user
56
+ * @param client The Axios client instance
57
+ * @returns The authenticated user
58
+ */
59
+ static user(client: AxiosInstance) {
60
+ return client.get<IAuthenticatedUser>("/user");
61
+ }
61
62
  }
package/src/api/oauth.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Client, requireArgs } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { requireArgs } from "../core";
2
3
 
3
4
  /**************************************************************
4
5
  * Interfaces
@@ -35,85 +36,81 @@ export interface IRevokeToken {
35
36
  }
36
37
 
37
38
  /**************************************************************
38
- * Functions
39
+ * Class
39
40
  **************************************************************/
40
41
 
41
- /**
42
- * Get the URL to authorize a user
43
- * @param client The Webflow client
44
- * @param params The params for the request
45
- * @param params.client_id The OAuth client ID
46
- * @param params.scope The scope (optional)
47
- * @param params.state The state (optional)
48
- * @param params.redirect_uri The redirect URI (optional)
49
- * @param params.response_type The response type (default: code)
50
- * @returns The URL to authorize a user
51
- */
52
- export function authorizeUrl(
53
- client: Client,
54
- {
55
- response_type = "code",
56
- redirect_uri,
57
- client_id,
58
- state,
59
- scope,
60
- }: IAuthorizeUrlParams
61
- ) {
62
- requireArgs({ client_id });
42
+ export class OAuth {
43
+ /**
44
+ * Get the URL to authorize a user
45
+ * @param params The params for the request
46
+ * @param params.client_id The OAuth client ID
47
+ * @param params.scope The scope (optional)
48
+ * @param params.state The state (optional)
49
+ * @param params.redirect_uri The redirect URI (optional)
50
+ * @param params.response_type The response type (default: code)
51
+ * @param client The Axios client instance
52
+ * @returns The URL to authorize a user
53
+ */
54
+ static authorizeUrl(
55
+ { response_type = "code", redirect_uri, client_id, state, scope }: IAuthorizeUrlParams,
56
+ client: AxiosInstance,
57
+ ) {
58
+ requireArgs({ client_id });
63
59
 
64
- const params = { response_type, client_id };
65
- if (redirect_uri) params["redirect_uri"] = redirect_uri;
66
- if (state) params["state"] = state;
67
- if (scope) params["scope"] = scope;
60
+ const params = { response_type, client_id };
61
+ if (redirect_uri) params["redirect_uri"] = redirect_uri;
62
+ if (state) params["state"] = state;
63
+ if (scope) params["scope"] = scope;
68
64
 
69
- const url = "/oauth/authorize";
70
- return client.getUri({ url, method: "GET", params });
71
- }
65
+ const url = "/oauth/authorize";
66
+ return client.getUri({ url, method: "GET", params });
67
+ }
72
68
 
73
- /**
74
- * Get an access token
75
- * @param client The Webflow client
76
- * @param params The params for the request
77
- * @param params.code The OAuth code
78
- * @param params.client_id The OAuth client ID
79
- * @param params.client_secret The OAuth client secret
80
- * @param params.redirect_uri The redirect URI (optional)
81
- * @param params.grant_type The grant type (default: "authorization_code")
82
- * @returns An access token
83
- */
84
- export function accessToken(
85
- client: Client,
86
- {
87
- grant_type = "authorization_code",
88
- client_secret,
89
- redirect_uri,
90
- client_id,
91
- code,
92
- }: IAccessTokenParams
93
- ) {
94
- requireArgs({ client_id, client_secret, code });
69
+ /**
70
+ * Get an access token
71
+ * @param params The params for the request
72
+ * @param params.code The OAuth code
73
+ * @param params.client_id The OAuth client ID
74
+ * @param params.client_secret The OAuth client secret
75
+ * @param params.redirect_uri The redirect URI (optional)
76
+ * @param params.grant_type The grant type (default: "authorization_code")
77
+ * @param client The Axios client instance
78
+ * @returns An access token
79
+ */
80
+ static accessToken(
81
+ {
82
+ grant_type = "authorization_code",
83
+ client_secret,
84
+ redirect_uri,
85
+ client_id,
86
+ code,
87
+ }: IAccessTokenParams,
88
+ client: AxiosInstance,
89
+ ) {
90
+ requireArgs({ client_id, client_secret, code });
95
91
 
96
- const path = "/oauth/access_token";
97
- const data = { client_secret, redirect_uri, grant_type, client_id, code };
98
- return client.post<IAccessToken>(path, data);
99
- }
92
+ const path = "/oauth/access_token";
93
+ const data = { client_secret, redirect_uri, grant_type, client_id, code };
94
+ return client.post<IAccessToken>(path, data);
95
+ }
100
96
 
101
- /**
102
- * Revoke an access token
103
- * @param client The Webflow client
104
- * @param params The params for the request
105
- * @param params.client_id The OAuth client ID
106
- * @param params.client_secret The OAuth client secret
107
- * @param params.access_token The OAuth access token
108
- * @returns The result of the revoke
109
- */
110
- export function revokeToken(
111
- client: Client,
112
- { client_secret, access_token, client_id }: IRevokeTokenParams
113
- ) {
114
- requireArgs({ client_id, client_secret, access_token });
97
+ /**
98
+ * Revoke an access token
99
+ * @param params The params for the request
100
+ * @param params.client_id The OAuth client ID
101
+ * @param params.client_secret The OAuth client secret
102
+ * @param params.access_token The OAuth access token
103
+ * @param client The Axios client instance
104
+ * @returns The result of the revoke
105
+ */
106
+ static revokeToken(
107
+ { client_secret, access_token, client_id }: IRevokeTokenParams,
108
+ client: AxiosInstance,
109
+ ) {
110
+ requireArgs({ client_id, client_secret, access_token });
115
111
 
116
- const path = "/oauth/revoke_authorization";
117
- const data = { client_secret, access_token, client_id };
118
- return client.post<IRevokeToken>(path, data);
112
+ const path = "/oauth/revoke_authorization";
113
+ const data = { client_secret, access_token, client_id };
114
+ return client.post<IRevokeToken>(path, data);
115
+ }
119
116
  }