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
@@ -1,24 +1,49 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Webflow = void 0;
4
- const core_1 = require("./core");
5
- const api_1 = require("./api");
6
- const wrapper_1 = require("./wrapper");
6
+ exports.Webflow = exports.USER_AGENT = exports.DEFAULT_HOST = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const core_1 = require("../core");
9
+ const api_1 = require("../api");
10
+ exports.DEFAULT_HOST = "webflow.com";
11
+ exports.USER_AGENT = "Webflow Javascript SDK / 1.0";
7
12
  /**************************************************************
8
13
  * Class
9
14
  **************************************************************/
10
15
  class Webflow {
11
16
  constructor(options = {}) {
12
17
  this.options = options;
13
- this.client = new core_1.Client(options);
18
+ this.client = axios_1.default.create(this.config);
19
+ this.client.interceptors.response.use(core_1.ErrorInterceptor);
14
20
  }
15
21
  // Set the Authentication token
16
22
  set token(value) {
17
- this.client.token = value;
23
+ this.options.token = value;
18
24
  }
19
25
  // clear the Authorization header
20
26
  clearToken() {
21
- this.client.clearToken();
27
+ delete this.options.token;
28
+ }
29
+ // The Axios configuration
30
+ get config() {
31
+ const { host = exports.DEFAULT_HOST, token, version, headers } = this.options;
32
+ const config = {
33
+ baseURL: `https://api.${host}/`,
34
+ headers: {
35
+ "Content-Type": "application/json",
36
+ "User-Agent": exports.USER_AGENT,
37
+ ...headers,
38
+ },
39
+ };
40
+ // Add the version to the headers if passed in
41
+ if (version)
42
+ config.headers["Accept-Version"] = version;
43
+ // Add the Authorization header if a token is set
44
+ if (token)
45
+ config.headers.Authorization = `Bearer ${token}`;
46
+ return config;
22
47
  }
23
48
  /**************************************************************
24
49
  * HTTP Methods
@@ -85,7 +110,7 @@ class Webflow {
85
110
  * @returns The url to redirect to
86
111
  */
87
112
  authorizeUrl(params) {
88
- return api_1.OAuth.authorizeUrl(this.client, params);
113
+ return api_1.OAuth.authorizeUrl(params, this.client);
89
114
  }
90
115
  /**
91
116
  * Create an OAuth Access Token
@@ -98,8 +123,8 @@ class Webflow {
98
123
  * @returns The access token
99
124
  */
100
125
  async accessToken(params) {
101
- const res = await api_1.OAuth.accessToken(this.client, params);
102
- return (0, wrapper_1.ResponseWrapper)(res);
126
+ const res = await api_1.OAuth.accessToken(params, this.client);
127
+ return res.data;
103
128
  }
104
129
  /**
105
130
  * Revoke an OAuth Access Token
@@ -110,8 +135,8 @@ class Webflow {
110
135
  * @returns The result of the revoked token
111
136
  */
112
137
  async revokeToken(params) {
113
- const res = await api_1.OAuth.revokeToken(this.client, params);
114
- return (0, wrapper_1.ResponseWrapper)(res);
138
+ const res = await api_1.OAuth.revokeToken(params, this.client);
139
+ return res.data;
115
140
  }
116
141
  /**************************************************************
117
142
  * Meta Endpoints
@@ -122,7 +147,7 @@ class Webflow {
122
147
  */
123
148
  async info() {
124
149
  const res = await api_1.Meta.info(this.client);
125
- return (0, wrapper_1.ResponseWrapper)(res);
150
+ return res.data;
126
151
  }
127
152
  /**
128
153
  * Get the current authenticated user
@@ -130,18 +155,18 @@ class Webflow {
130
155
  */
131
156
  async authenticatedUser() {
132
157
  const res = await api_1.Meta.user(this.client);
133
- return (0, wrapper_1.ResponseWrapper)(res);
158
+ return res.data;
134
159
  }
135
160
  /**************************************************************
136
161
  * Site Endpoints
137
162
  **************************************************************/
138
163
  /**
139
164
  * Get a list of Sites available
140
- * @param query The query parameters (optional)
141
165
  * @returns A list of Sites
142
166
  */
143
- async sites(query) {
144
- return wrapper_1.SiteWrapper.list(this.client, query);
167
+ async sites() {
168
+ const res = await api_1.Site.list(this.client);
169
+ return res.data.map((data) => new api_1.Site(this.client, { ...res, data }));
145
170
  }
146
171
  /**
147
172
  * Get a single Site
@@ -150,7 +175,8 @@ class Webflow {
150
175
  * @returns The Site
151
176
  */
152
177
  async site({ siteId }) {
153
- return wrapper_1.SiteWrapper.getOne(this.client, { siteId });
178
+ const res = await api_1.Site.getOne({ siteId }, this.client);
179
+ return new api_1.Site(this.client, res);
154
180
  }
155
181
  /**
156
182
  * Publish a Site
@@ -159,8 +185,9 @@ class Webflow {
159
185
  * @param params.domain The domains to publish
160
186
  * @returns The result of the publish
161
187
  */
162
- publishSite({ siteId, domains }) {
163
- return wrapper_1.SiteWrapper.publish(this.client, { siteId, domains });
188
+ async publishSite({ siteId, domains }) {
189
+ const res = await api_1.Site.publish({ siteId, domains }, this.client);
190
+ return res.data;
164
191
  }
165
192
  /**
166
193
  * Get a list of Domains for a Site
@@ -169,7 +196,8 @@ class Webflow {
169
196
  * @returns A list of Domains
170
197
  */
171
198
  async domains({ siteId }) {
172
- return wrapper_1.SiteWrapper.domains(this.client, { siteId });
199
+ const res = await api_1.Site.domains({ siteId }, this.client);
200
+ return res.data;
173
201
  }
174
202
  /**************************************************************
175
203
  * Collection Endpoints
@@ -178,11 +206,11 @@ class Webflow {
178
206
  * Get a list of Collections
179
207
  * @param params The Site information
180
208
  * @param params.siteId The Site ID
181
- * @param query The query parameters (optional)
182
209
  * @returns A list of Collections
183
210
  */
184
- async collections({ siteId }, query) {
185
- return wrapper_1.CollectionWrapper.list(this.client, { siteId }, query);
211
+ async collections({ siteId }) {
212
+ const res = await api_1.Collection.list({ siteId }, this.client);
213
+ return res.data.map((data) => new api_1.Collection(this.client, { ...res, data }));
186
214
  }
187
215
  /**
188
216
  * Get a single Collection
@@ -191,7 +219,8 @@ class Webflow {
191
219
  * @returns A single Collection
192
220
  */
193
221
  async collection({ collectionId }) {
194
- return wrapper_1.CollectionWrapper.getOne(this.client, { collectionId });
222
+ const res = await api_1.Collection.getOne({ collectionId }, this.client);
223
+ return new api_1.Collection(this.client, res);
195
224
  }
196
225
  /**************************************************************
197
226
  * Item Endpoints
@@ -200,11 +229,13 @@ class Webflow {
200
229
  * Get a list of Collection Items
201
230
  * @param params The Collection information
202
231
  * @param params.collectionId The Collection ID
203
- * @param pageParams The pagination parameters (optional)
232
+ * @param params.limit The number of items to return
233
+ * @param params.offset The number of items to skip
204
234
  * @returns A list of Items
205
235
  */
206
- async items({ collectionId }, pageParams) {
207
- return wrapper_1.ItemWrapper.list(this.client, { collectionId, ...pageParams });
236
+ async items({ collectionId, limit, offset }) {
237
+ const res = await api_1.Item.list({ collectionId, limit, offset }, this.client);
238
+ return res.data.items.map((data) => new api_1.Item(this.client, { ...res, data }));
208
239
  }
209
240
  /**
210
241
  * Get a single Collection Item
@@ -213,8 +244,10 @@ class Webflow {
213
244
  * @param params.itemId The Item ID
214
245
  * @returns A single Collection Item
215
246
  */
216
- async item({ itemId, collectionId, }) {
217
- return wrapper_1.ItemWrapper.getOne(this.client, { itemId, collectionId });
247
+ async item({ itemId, collectionId }) {
248
+ const res = await api_1.Item.getOne({ itemId, collectionId }, this.client);
249
+ const [item] = res.data.items.map((data) => new api_1.Item(this.client, { ...res, data }));
250
+ return item;
218
251
  }
219
252
  /**
220
253
  * Create a new Collection Item
@@ -222,31 +255,34 @@ class Webflow {
222
255
  * @param params.collectionId The Collection ID
223
256
  * @returns The created Collection Item
224
257
  */
225
- async createItem({ collectionId, fields, }) {
226
- return wrapper_1.ItemWrapper.create(this.client, { collectionId, fields });
258
+ async createItem({ collectionId, fields }) {
259
+ const res = await api_1.Item.create({ collectionId, fields }, this.client);
260
+ return new api_1.Item(this.client, res);
227
261
  }
228
262
  /**
229
263
  * Update a Collection Item
230
264
  * @param params The Item information
231
265
  * @param params.collectionId The Collection ID
232
266
  * @param params.itemId The Item ID
267
+ * @param query The query parameters (optional)
233
268
  * @returns The updated Collection Item
234
269
  */
235
- updateItem({ collectionId, itemId, ...fields }) {
270
+ async updateItem({ collectionId, itemId, ...fields }) {
236
271
  const _params = { collectionId, itemId, fields };
237
- return wrapper_1.ItemWrapper.update(this.client, _params);
272
+ const res = await api_1.Item.update(_params, this.client);
273
+ return new api_1.Item(this.client, res);
238
274
  }
239
275
  /**
240
276
  * Patch a Collection Item
241
277
  * @param params The Item information
242
278
  * @param params.collectionId The Collection ID
243
279
  * @param params.itemId The Item ID
244
- * @param query The query parameters (optional)
245
280
  * @returns The patched Collection Item
246
281
  */
247
- patchItem({ collectionId, itemId, ...fields }, query) {
282
+ async patchItem({ collectionId, itemId, ...fields }) {
248
283
  const _params = { collectionId, itemId, fields };
249
- return wrapper_1.ItemWrapper.patch(this.client, _params, query);
284
+ const res = await api_1.Item.patch(_params, this.client);
285
+ return new api_1.Item(this.client, res);
250
286
  }
251
287
  /**
252
288
  * Delete a Collection Item
@@ -255,8 +291,9 @@ class Webflow {
255
291
  * @param params.itemId The Item ID
256
292
  * @returns The deleted Collection Item result
257
293
  */
258
- removeItem({ collectionId, itemId, }) {
259
- return wrapper_1.ItemWrapper.remove(this.client, { collectionId, itemId });
294
+ async removeItem({ collectionId, itemId }) {
295
+ const res = await api_1.Item.remove({ collectionId, itemId }, this.client);
296
+ return res.data;
260
297
  }
261
298
  /**
262
299
  * Upublish a Collection Item
@@ -266,9 +303,9 @@ class Webflow {
266
303
  * @param params.live Update the live version
267
304
  * @returns The unpublished Collection Item result
268
305
  */
269
- deleteItems({ collectionId, itemIds, live, }) {
270
- const params = { collectionId, itemIds, live };
271
- return wrapper_1.ItemWrapper.unpublish(this.client, params);
306
+ async deleteItems({ collectionId, itemIds, live, }) {
307
+ const res = await api_1.Item.unpublish({ collectionId, itemIds, live }, this.client);
308
+ return res.data;
272
309
  }
273
310
  /**
274
311
  * Publish a Collection Item
@@ -278,9 +315,9 @@ class Webflow {
278
315
  * @param params.live Update the live version
279
316
  * @returns The Published Collection Item result
280
317
  */
281
- publishItems({ collectionId, itemIds, live, }) {
282
- const params = { collectionId, itemIds, live };
283
- return wrapper_1.ItemWrapper.publish(this.client, params);
318
+ async publishItems({ collectionId, itemIds, live, }) {
319
+ const res = await api_1.Item.publish({ collectionId, itemIds, live }, this.client);
320
+ return res.data;
284
321
  }
285
322
  /**************************************************************
286
323
  * Membership Endpoints
@@ -290,12 +327,11 @@ class Webflow {
290
327
  * @param params The Site information
291
328
  * @param params.siteId The Site ID
292
329
  * @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
295
330
  * @returns A list of User accounts
296
331
  */
297
332
  async users({ siteId }, pageParams) {
298
- return wrapper_1.MembershipWrapper.list(this.client, { siteId, ...pageParams });
333
+ const res = await api_1.User.list({ siteId, ...pageParams }, this.client);
334
+ return res.data.users.map((data) => new api_1.User(this.client, { ...res, data }));
299
335
  }
300
336
  /**
301
337
  * Get a single User account
@@ -305,7 +341,8 @@ class Webflow {
305
341
  * @returns The User information
306
342
  */
307
343
  async user({ siteId, userId }) {
308
- return wrapper_1.MembershipWrapper.getOne(this.client, { siteId, userId });
344
+ const res = await api_1.User.getOne({ siteId, userId }, this.client);
345
+ return new api_1.User(this.client, res, res.data, { siteId });
309
346
  }
310
347
  /**
311
348
  * Update a User account
@@ -316,7 +353,8 @@ class Webflow {
316
353
  */
317
354
  async updateUser({ siteId, userId, ...data }) {
318
355
  const _params = { siteId, userId, data };
319
- return wrapper_1.MembershipWrapper.update(this.client, _params);
356
+ const res = await api_1.User.update(_params, this.client);
357
+ return new api_1.User(this.client, res, res.data, { siteId });
320
358
  }
321
359
  /**
322
360
  * Invite a User to a Site
@@ -326,7 +364,8 @@ class Webflow {
326
364
  * @returns The created User account
327
365
  */
328
366
  async inviteUser({ siteId, email }) {
329
- return wrapper_1.MembershipWrapper.invite(this.client, { siteId, email });
367
+ const res = await api_1.User.invite({ siteId, email }, this.client);
368
+ return new api_1.User(this.client, res, res.data, { siteId });
330
369
  }
331
370
  /**
332
371
  * Remove a user from a Site
@@ -335,17 +374,23 @@ class Webflow {
335
374
  * @param params.userId The User ID
336
375
  * @returns The result from the remove request
337
376
  */
338
- removeUser({ siteId, userId }) {
339
- return wrapper_1.MembershipWrapper.remove(this.client, { siteId, userId });
377
+ async removeUser({ siteId, userId }) {
378
+ const res = await api_1.User.remove({ siteId, userId }, this.client);
379
+ return res.data;
340
380
  }
341
381
  /**
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
382
+ * Get a list of User Access Groups
383
+ * @param params The params for the request
384
+ * @param params.siteId The site ID
385
+ * @param params.limit The number of items to return (optional)
386
+ * @param params.offset The number of items to skip (optional)
387
+ * @param params.sort The sort order of the groups (optional)
388
+ * @returns A list of Access Groups
346
389
  */
347
- accessGroups({ siteId }) {
348
- return wrapper_1.MembershipWrapper.accessGroups(this.client, { siteId });
390
+ async accessGroups({ siteId, limit, offset, sort, }) {
391
+ const params = { siteId, limit, offset, sort };
392
+ const res = await api_1.User.accessGroups(params, this.client);
393
+ return res.data;
349
394
  }
350
395
  /**************************************************************
351
396
  * Webhook Endpoints
@@ -356,8 +401,9 @@ class Webflow {
356
401
  * @param params.siteId The Site ID
357
402
  * @returns A list of Webhooks
358
403
  */
359
- async webhooks({ siteId }, query) {
360
- return wrapper_1.WebhookWrapper.list(this.client, { siteId }, query);
404
+ async webhooks({ siteId }) {
405
+ const res = await api_1.Webhook.list({ siteId }, this.client);
406
+ return res.data.map((data) => new api_1.Webhook(this.client, { ...res, data }));
361
407
  }
362
408
  /**
363
409
  * Get a single Webhook
@@ -367,7 +413,8 @@ class Webflow {
367
413
  * @returns The Webhook
368
414
  */
369
415
  async webhook({ siteId, webhookId }) {
370
- return wrapper_1.WebhookWrapper.getOne(this.client, { siteId, webhookId });
416
+ const res = await api_1.Webhook.getOne({ siteId, webhookId }, this.client);
417
+ return new api_1.Webhook(this.client, res);
371
418
  }
372
419
  /**
373
420
  * Remove a Webhook
@@ -376,8 +423,9 @@ class Webflow {
376
423
  * @param params.webhookId The Webhook Id
377
424
  * @returns the result from the remove request
378
425
  */
379
- removeWebhook({ siteId, webhookId }) {
380
- return wrapper_1.WebhookWrapper.remove(this.client, { siteId, webhookId });
426
+ async removeWebhook({ siteId, webhookId }) {
427
+ const res = await api_1.Webhook.remove({ siteId, webhookId }, this.client);
428
+ return res.data;
381
429
  }
382
430
  /**
383
431
  * Create a Webhook
@@ -390,7 +438,8 @@ class Webflow {
390
438
  */
391
439
  async createWebhook({ url, siteId, triggerType, filter, }) {
392
440
  const _params = { url, siteId, triggerType, filter };
393
- return wrapper_1.WebhookWrapper.create(this.client, _params);
441
+ const res = await api_1.Webhook.create(_params, this.client);
442
+ return new api_1.Webhook(this.client, res);
394
443
  }
395
444
  }
396
445
  exports.Webflow = Webflow;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Webflow } from "./webflow";
1
+ import { Webflow } from "./core";
2
2
  export = Webflow;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- const webflow_1 = require("./webflow");
3
- module.exports = webflow_1.Webflow;
2
+ const core_1 = require("./core");
3
+ module.exports = core_1.Webflow;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webflow-api",
3
3
  "description": "Webflow's official Node.js SDK for Data APIs",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "contributors": [
@@ -19,17 +19,21 @@
19
19
  "yarn.lock"
20
20
  ],
21
21
  "scripts": {
22
- "build": "yarn clean && tsc -p ./",
23
- "lint": "eslint . --ext .ts,.tsx",
22
+ "test": "yarn build && jest",
23
+ "build": "yarn clean && tsc",
24
+ "lint": "eslint src --ext .ts",
25
+ "test:snapshot": "yarn test --updateSnapshot",
26
+ "test:coverage": "yarn test --collectCoverage",
27
+ "test:ci": "yarn test --ci --coverage --forceExit",
28
+ "format": "prettier --write .",
29
+ "format:check": "prettier --check .",
24
30
  "prepublish": "yarn build",
25
- "watch": "tsc -watch -p ./",
31
+ "watch": "tsc --watch",
26
32
  "clean": "rm -rf dist",
27
- "test": "jest"
33
+ "typecheck": "tsc --noEmit"
28
34
  },
29
35
  "devDependencies": {
30
- "@jest/globals": "^29.2.2",
31
- "@types/isomorphic-fetch": "^0.0.36",
32
- "@types/jest": "^29.2.1",
36
+ "@types/jest": "^29.2.3",
33
37
  "@types/node": "^18.11.9",
34
38
  "@typescript-eslint/eslint-plugin": "^5.42.0",
35
39
  "@typescript-eslint/parser": "^5.42.0",
@@ -1,4 +1,6 @@
1
- import { Client, QueryString, requireArgs } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { requireArgs, WebflowRecord } from "../core";
3
+ import { Item } from ".";
2
4
 
3
5
  /**************************************************************
4
6
  * Types
@@ -30,7 +32,7 @@ export type CollectionField = {
30
32
  required: boolean;
31
33
  editable: boolean;
32
34
  // TODO: add a better type
33
- validations?: any;
35
+ validations?: Record<string, string | number | boolean | object>;
34
36
  };
35
37
 
36
38
  /**************************************************************
@@ -47,41 +49,106 @@ export interface ICollection {
47
49
  }
48
50
 
49
51
  /**************************************************************
50
- * Functions
52
+ * Class
51
53
  **************************************************************/
54
+ export class Collection extends WebflowRecord<ICollection> implements ICollection {
55
+ fields: CollectionField[];
56
+ singularName: string;
57
+ lastUpdated: string;
58
+ createdOn: string;
59
+ _id: string;
60
+ name: string;
61
+ slug: string;
52
62
 
53
- /**
54
- * Get a list of Collections
55
- * @param client The Webflow client
56
- * @param params1 The params for the request
57
- * @param params1.siteId The site ID
58
- * @param params The query string parameters (optional)
59
- * @returns A list of Collections
60
- */
61
- export function list(
62
- client: Client,
63
- { siteId }: { siteId: string },
64
- params?: QueryString
65
- ) {
66
- requireArgs({ siteId });
67
- const path = `/sites/${siteId}/collections`;
68
- return client.get<ICollection[]>(path, { params });
69
- }
63
+ /**************************************************************
64
+ * Static Methods
65
+ **************************************************************/
66
+
67
+ /**
68
+ * Get a list of Collections
69
+ * @param params The params for the request
70
+ * @param params.siteId The site ID
71
+ * @param client The Axios client instance
72
+ * @returns A list of Collections
73
+ */
74
+ static list({ siteId }: { siteId: string }, client: AxiosInstance) {
75
+ requireArgs({ siteId });
76
+ const path = `/sites/${siteId}/collections`;
77
+ return client.get<ICollection[]>(path);
78
+ }
79
+
80
+ /**
81
+ * Get a single Collection
82
+ * @param params The params for the request
83
+ * @param params.collectionId The collection ID
84
+ * @param client The Axios client instance
85
+ * @returns A single Collection
86
+ */
87
+ static getOne({ collectionId }: { collectionId: string }, client: AxiosInstance) {
88
+ requireArgs({ collectionId });
89
+ const path = `/collections/${collectionId}`;
90
+ return client.get<ICollection>(path);
91
+ }
92
+
93
+ /**************************************************************
94
+ * Instance Methods
95
+ **************************************************************/
96
+
97
+ /**
98
+ * Get a single Item
99
+ * @param params The params for the request
100
+ * @param params.itemId The Item ID
101
+ * @returns A single Item
102
+ */
103
+ async item({ itemId }: { itemId: string }) {
104
+ const res = await Item.getOne({ itemId, collectionId: this._id }, this.client);
105
+ const [item] = res.data.items.map((data) => new Item(this.client, { ...res, data }));
106
+ return item;
107
+ }
108
+
109
+ /**
110
+ * Get a list of Items
111
+ * @param params The params for the request
112
+ * @param params.limit The number of items to return (optional)
113
+ * @param params.offset The number of items to skip (optional)
114
+ * @returns A list of Items
115
+ */
116
+ async items({ limit, offset }: { limit?: number; offset?: number } = {}) {
117
+ const res = await Item.list({ collectionId: this._id, limit, offset }, this.client);
118
+ return res.data.items.map((data) => new Item(this.client, { ...res, data }));
119
+ }
120
+
121
+ /**
122
+ * Remove a single Item
123
+ * @param params The params for the request
124
+ * @param params.itemId The Item ID
125
+ * @returns The result from the removal
126
+ */
127
+ async removeItem({ itemId }: { itemId: string }) {
128
+ const res = await Item.remove({ itemId, collectionId: this._id }, this.client);
129
+ return res.data;
130
+ }
131
+
132
+ /**
133
+ * Create a new Item
134
+ * @param fields The Item fields to create
135
+ * @returns The created Item
136
+ */
137
+ async createItem(fields: object) {
138
+ const res = await Item.create({ collectionId: this._id, fields }, this.client);
139
+ return new Item(this.client, res);
140
+ }
70
141
 
71
- /**
72
- * Get a single Collection
73
- * @param client The Webflow client
74
- * @param params The params for the request
75
- * @param params.collectionId The collection ID
76
- * @param params.params The query string parameters (optional)
77
- * @returns A single Collection
78
- */
79
- export function getOne(
80
- client: Client,
81
- { collectionId }: { collectionId: string },
82
- params?: QueryString
83
- ) {
84
- requireArgs({ collectionId });
85
- const path = `/collections/${collectionId}`;
86
- return client.get<ICollection>(path, { params });
142
+ /**
143
+ * Update a single Item
144
+ * @param params The params for the request
145
+ * @param params.itemId The Item ID
146
+ * @param params.fields The fields to update
147
+ * @returns The updated Item
148
+ */
149
+ async updateItem({ itemId, fields }: { itemId: string; fields: object }) {
150
+ const params = { itemId, collectionId: this._id, fields };
151
+ const res = await Item.update(params, this.client);
152
+ return new Item(this.client, res);
153
+ }
87
154
  }
package/src/api/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * as Membership from "./membership";
2
- export * as Collection from "./collection";
3
- export * as Webhook from "./webhook";
4
- export * as OAuth from "./oauth";
5
- export * as Item from "./item";
6
- export * as Site from "./site";
7
- export * as Meta from "./meta";
1
+ export * from "./collection";
2
+ export * from "./user";
3
+ export * from "./webhook";
4
+ export * from "./item";
5
+ export * from "./site";
6
+ export * from "./oauth";
7
+ export * from "./meta";