webflow-api 1.1.1 → 1.2.0

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