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.
- package/dist/api/collection.d.ts +85 -24
- package/dist/api/collection.js +88 -29
- package/dist/api/index.d.ts +7 -7
- package/dist/api/index.js +9 -19
- package/dist/api/item.d.ts +141 -107
- package/dist/api/item.js +145 -125
- package/dist/api/meta.d.ts +16 -14
- package/dist/api/meta.js +20 -19
- package/dist/api/oauth.d.ts +38 -36
- package/dist/api/oauth.js +59 -59
- package/dist/api/site.d.ts +118 -43
- package/dist/api/site.js +131 -53
- package/dist/{wrapper/membership.d.ts → api/user.d.ts} +59 -47
- package/dist/api/user.js +103 -0
- package/dist/api/webhook.d.ts +77 -55
- package/dist/api/webhook.js +74 -61
- package/dist/core/error.d.ts +2 -0
- package/dist/core/error.js +8 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/response.d.ts +32 -0
- package/dist/core/response.js +26 -0
- package/dist/{webflow.d.ts → core/webflow.d.ts} +56 -59
- package/dist/{webflow.js → core/webflow.js} +101 -68
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +2 -4
- package/src/api/collection.ts +102 -35
- package/src/api/index.ts +7 -7
- package/src/api/item.ts +207 -176
- package/src/api/meta.ts +19 -18
- package/src/api/oauth.ts +62 -74
- package/src/api/site.ts +158 -55
- package/src/api/user.ts +152 -0
- package/src/api/webhook.ts +97 -80
- package/src/core/error.ts +8 -0
- package/src/core/index.ts +2 -2
- package/src/core/response.ts +50 -0
- package/src/{webflow.ts → core/webflow.ts} +131 -145
- package/src/index.ts +1 -1
- package/yarn.lock +0 -5
- package/dist/api/membership.d.ts +0 -114
- package/dist/api/membership.js +0 -96
- package/dist/core/client.d.ts +0 -27
- package/dist/core/client.js +0 -60
- package/dist/core/options.d.ts +0 -8
- package/dist/core/options.js +0 -5
- package/dist/wrapper/collection.d.ts +0 -85
- package/dist/wrapper/collection.js +0 -94
- package/dist/wrapper/index.d.ts +0 -6
- package/dist/wrapper/index.js +0 -22
- package/dist/wrapper/item.d.ts +0 -140
- package/dist/wrapper/item.js +0 -153
- package/dist/wrapper/membership.js +0 -123
- package/dist/wrapper/response.d.ts +0 -16
- package/dist/wrapper/response.js +0 -17
- package/dist/wrapper/site.d.ts +0 -168
- package/dist/wrapper/site.js +0 -191
- package/dist/wrapper/webhook.d.ts +0 -78
- package/dist/wrapper/webhook.js +0 -82
- package/src/api/membership.ts +0 -155
- package/src/core/client.ts +0 -82
- package/src/core/options.ts +0 -9
- package/src/wrapper/collection.ts +0 -115
- package/src/wrapper/index.ts +0 -6
- package/src/wrapper/item.ts +0 -218
- package/src/wrapper/membership.ts +0 -163
- package/src/wrapper/response.ts +0 -25
- package/src/wrapper/site.ts +0 -228
- 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
|
|
5
|
-
const api_1 = require("
|
|
6
|
-
|
|
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 =
|
|
17
|
+
this.client = axios_1.default.create(this.config);
|
|
14
18
|
}
|
|
15
19
|
// Set the Authentication token
|
|
16
20
|
set token(value) {
|
|
17
|
-
this.
|
|
21
|
+
this.options.token = value;
|
|
18
22
|
}
|
|
19
23
|
// clear the Authorization header
|
|
20
24
|
clearToken() {
|
|
21
|
-
this.
|
|
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
|
|
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
|
|
102
|
-
return
|
|
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
|
|
114
|
-
return
|
|
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
|
|
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
|
|
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(
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 }
|
|
185
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
207
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 }
|
|
280
|
+
async patchItem({ collectionId, itemId, ...fields }) {
|
|
248
281
|
const _params = { collectionId, itemId, fields };
|
|
249
|
-
|
|
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
|
-
|
|
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
|
|
271
|
-
return
|
|
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
|
|
283
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 }
|
|
360
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 "./
|
|
1
|
+
import { Webflow } from "./core";
|
|
2
2
|
export = Webflow;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
module.exports =
|
|
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.
|
|
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
|
|
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",
|
package/src/api/collection.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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 *
|
|
2
|
-
export *
|
|
3
|
-
export *
|
|
4
|
-
export *
|
|
5
|
-
export *
|
|
6
|
-
export *
|
|
7
|
-
export *
|
|
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";
|