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