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
@@ -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,8 +253,9 @@ 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
@@ -233,21 +265,22 @@ class Webflow {
233
265
  * @param query The query parameters (optional)
234
266
  * @returns The updated Collection Item
235
267
  */
236
- updateItem({ collectionId, itemId, ...fields }) {
268
+ async updateItem({ collectionId, itemId, ...fields }) {
237
269
  const _params = { collectionId, itemId, fields };
238
- 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);
239
272
  }
240
273
  /**
241
274
  * Patch a Collection Item
242
275
  * @param params The Item information
243
276
  * @param params.collectionId The Collection ID
244
277
  * @param params.itemId The Item ID
245
- * @param query The query parameters (optional)
246
278
  * @returns The patched Collection Item
247
279
  */
248
- patchItem({ collectionId, itemId, ...fields }, query) {
280
+ async patchItem({ collectionId, itemId, ...fields }) {
249
281
  const _params = { collectionId, itemId, fields };
250
- 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);
251
284
  }
252
285
  /**
253
286
  * Delete a Collection Item
@@ -256,34 +289,33 @@ class Webflow {
256
289
  * @param params.itemId The Item ID
257
290
  * @returns The deleted Collection Item result
258
291
  */
259
- removeItem({ collectionId, itemId, }) {
260
- 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;
261
295
  }
262
296
  /**
263
297
  * Upublish a Collection Item
264
298
  * @param params The Item information
265
299
  * @param params.collectionId The Collection ID
266
300
  * @param params.itemId The Item ID
267
- * @param query The query parameters (optional)
268
- * @param query.live Update the live version
301
+ * @param params.live Update the live version
269
302
  * @returns The unpublished Collection Item result
270
303
  */
271
- deleteItems({ collectionId, itemIds, live, }) {
272
- const params = { collectionId, itemIds, live };
273
- 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;
274
307
  }
275
308
  /**
276
309
  * Publish a Collection Item
277
310
  * @param params The Item information
278
311
  * @param params.collectionId The Collection ID
279
312
  * @param params.itemId The Item ID
280
- * @param query The query parameters (optional)
281
- * @param query.live Update the live version
313
+ * @param params.live Update the live version
282
314
  * @returns The Published Collection Item result
283
315
  */
284
- publishItems({ collectionId, itemIds, live, }) {
285
- const params = { collectionId, itemIds, live };
286
- 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;
287
319
  }
288
320
  /**************************************************************
289
321
  * Membership Endpoints
@@ -296,7 +328,8 @@ class Webflow {
296
328
  * @returns A list of User accounts
297
329
  */
298
330
  async users({ siteId }, pageParams) {
299
- 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 }));
300
333
  }
301
334
  /**
302
335
  * Get a single User account
@@ -306,7 +339,8 @@ class Webflow {
306
339
  * @returns The User information
307
340
  */
308
341
  async user({ siteId, userId }) {
309
- 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 });
310
344
  }
311
345
  /**
312
346
  * Update a User account
@@ -317,7 +351,8 @@ class Webflow {
317
351
  */
318
352
  async updateUser({ siteId, userId, ...data }) {
319
353
  const _params = { siteId, userId, data };
320
- 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 });
321
356
  }
322
357
  /**
323
358
  * Invite a User to a Site
@@ -327,7 +362,8 @@ class Webflow {
327
362
  * @returns The created User account
328
363
  */
329
364
  async inviteUser({ siteId, email }) {
330
- 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 });
331
367
  }
332
368
  /**
333
369
  * Remove a user from a Site
@@ -336,8 +372,9 @@ class Webflow {
336
372
  * @param params.userId The User ID
337
373
  * @returns The result from the remove request
338
374
  */
339
- removeUser({ siteId, userId }) {
340
- return wrapper_1.MembershipWrapper.remove(this.client, { siteId, userId });
375
+ async removeUser({ siteId, userId }) {
376
+ const res = await api_1.User.remove({ siteId, userId }, this.client);
377
+ return res.data;
341
378
  }
342
379
  /**************************************************************
343
380
  * Webhook Endpoints
@@ -348,8 +385,9 @@ class Webflow {
348
385
  * @param params.siteId The Site ID
349
386
  * @returns A list of Webhooks
350
387
  */
351
- async webhooks({ siteId }, query) {
352
- 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 }));
353
391
  }
354
392
  /**
355
393
  * Get a single Webhook
@@ -359,7 +397,8 @@ class Webflow {
359
397
  * @returns The Webhook
360
398
  */
361
399
  async webhook({ siteId, webhookId }) {
362
- 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);
363
402
  }
364
403
  /**
365
404
  * Remove a Webhook
@@ -368,8 +407,9 @@ class Webflow {
368
407
  * @param params.webhookId The Webhook Id
369
408
  * @returns the result from the remove request
370
409
  */
371
- removeWebhook({ siteId, webhookId }) {
372
- 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;
373
413
  }
374
414
  /**
375
415
  * Create a Webhook
@@ -382,7 +422,8 @@ class Webflow {
382
422
  */
383
423
  async createWebhook({ url, siteId, triggerType, filter, }) {
384
424
  const _params = { url, siteId, triggerType, filter };
385
- 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);
386
427
  }
387
428
  }
388
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.1",
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";