webflow-api 1.0.2 → 1.1.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 (74) hide show
  1. package/README.md +4 -5
  2. package/dist/api/collection.d.ts +51 -0
  3. package/dist/api/collection.js +35 -0
  4. package/dist/api/index.d.ts +7 -0
  5. package/dist/api/index.js +33 -0
  6. package/dist/api/item.d.ts +143 -0
  7. package/dist/api/item.js +131 -0
  8. package/dist/api/membership.d.ts +91 -0
  9. package/dist/api/membership.js +80 -0
  10. package/dist/api/meta.d.ts +51 -0
  11. package/dist/api/meta.js +24 -0
  12. package/dist/api/oauth.d.ts +67 -0
  13. package/dist/api/oauth.js +65 -0
  14. package/dist/api/site.d.ts +65 -0
  15. package/dist/api/site.js +59 -0
  16. package/dist/api/webhook.d.ts +80 -0
  17. package/dist/api/webhook.js +67 -0
  18. package/dist/core/client.d.ts +40 -0
  19. package/dist/core/client.js +49 -0
  20. package/dist/core/error.d.ts +19 -0
  21. package/dist/core/error.js +23 -0
  22. package/dist/core/index.d.ts +3 -0
  23. package/dist/core/index.js +19 -0
  24. package/dist/core/options.d.ts +8 -0
  25. package/dist/core/options.js +5 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +2 -9
  28. package/dist/webflow.d.ts +366 -0
  29. package/dist/webflow.js +388 -0
  30. package/dist/wrapper/collection.d.ts +85 -0
  31. package/dist/wrapper/collection.js +94 -0
  32. package/dist/wrapper/index.d.ts +6 -0
  33. package/dist/wrapper/index.js +22 -0
  34. package/dist/wrapper/item.d.ts +140 -0
  35. package/dist/wrapper/item.js +153 -0
  36. package/dist/wrapper/membership.d.ts +91 -0
  37. package/dist/wrapper/membership.js +106 -0
  38. package/dist/wrapper/response.d.ts +16 -0
  39. package/dist/wrapper/response.js +17 -0
  40. package/dist/wrapper/site.d.ts +119 -0
  41. package/dist/wrapper/site.js +136 -0
  42. package/dist/wrapper/webhook.d.ts +78 -0
  43. package/dist/wrapper/webhook.js +82 -0
  44. package/package.json +16 -17
  45. package/src/api/collection.ts +87 -0
  46. package/src/api/index.ts +7 -0
  47. package/src/api/item.ts +231 -0
  48. package/src/api/membership.ts +125 -0
  49. package/src/api/meta.ts +61 -0
  50. package/src/api/oauth.ts +119 -0
  51. package/src/api/site.ts +86 -0
  52. package/src/api/webhook.ts +125 -0
  53. package/src/core/client.ts +76 -0
  54. package/src/core/error.ts +32 -0
  55. package/src/core/index.ts +3 -0
  56. package/src/core/options.ts +9 -0
  57. package/src/index.ts +3 -0
  58. package/src/webflow.ts +487 -0
  59. package/src/wrapper/collection.ts +115 -0
  60. package/src/wrapper/index.ts +6 -0
  61. package/src/wrapper/item.ts +218 -0
  62. package/src/wrapper/membership.ts +138 -0
  63. package/src/wrapper/response.ts +25 -0
  64. package/src/wrapper/site.ts +164 -0
  65. package/src/wrapper/webhook.ts +116 -0
  66. package/yarn.lock +388 -1473
  67. package/dist/ResponseWrapper.js +0 -135
  68. package/dist/Webflow.js +0 -344
  69. package/dist/WebflowClient.js +0 -115
  70. package/index.d.ts +0 -430
  71. package/src/ResponseWrapper.js +0 -103
  72. package/src/Webflow.js +0 -301
  73. package/src/WebflowClient.js +0 -98
  74. package/src/index.js +0 -3
package/src/webflow.ts ADDED
@@ -0,0 +1,487 @@
1
+ import { QueryString, Options, Client, PaginationFilter } from "./core";
2
+ import { Meta, OAuth, Webhook } from "./api";
3
+ import {
4
+ MembershipWrapper,
5
+ CollectionWrapper,
6
+ WebhookWrapper,
7
+ SiteWrapper,
8
+ ItemWrapper,
9
+ ResponseWrapper,
10
+ } from "./wrapper";
11
+
12
+ /**************************************************************
13
+ * Class
14
+ **************************************************************/
15
+ export class Webflow {
16
+ client: Client;
17
+
18
+ constructor(public options: Options = {}) {
19
+ this.client = new Client(options);
20
+ }
21
+
22
+ // Set the Authentication token
23
+ set token(value: string) {
24
+ this.client.token = value;
25
+ }
26
+
27
+ // clear the Authorization header
28
+ clearToken() {
29
+ this.client.clearToken();
30
+ }
31
+
32
+ /**************************************************************
33
+ * HTTP Methods
34
+ **************************************************************/
35
+
36
+ /**
37
+ * Send a GET request to the Webflow API
38
+ * @param path The path to the endpoint
39
+ * @param params The query parameters (optional)
40
+ * @returns The response from the Webflow API
41
+ */
42
+ get(path: string, params?: QueryString) {
43
+ return this.client.get(path, { params });
44
+ }
45
+ /**
46
+ * Send a DELETE request to the Webflow API
47
+ * @param path The path to the endpoint
48
+ * @param params The query parameters (optional)
49
+ * @returns The response from the Webflow API
50
+ */
51
+ delete(path: string, params?: QueryString) {
52
+ return this.client.delete(path, { params });
53
+ }
54
+ /**
55
+ * Send a POST request to create a new Collection
56
+ * @param path The path to the endpoint
57
+ * @param data The data to send
58
+ * @param params The query parameters (optional)
59
+ * @returns The response from the Webflow API
60
+ */
61
+ post(path: string, data: any, params?: QueryString) {
62
+ return this.client.post(path, data, { params });
63
+ }
64
+ /**
65
+ * Send a PUT request to create a new Collection
66
+ * @param path The path to the endpoint
67
+ * @param data The data to send
68
+ * @param params The query parameters (optional)
69
+ * @returns The response from the Webflow API
70
+ */
71
+ put(path: string, data: any, params?: QueryString) {
72
+ return this.client.put(path, data, { params });
73
+ }
74
+ /**
75
+ * Send a PATCH request to create a new Collection
76
+ * @param path The path to the endpoint
77
+ * @param data The data to send
78
+ * @param params The query parameters (optional)
79
+ * @returns The response from the Webflow API
80
+ */
81
+ patch(path: string, data: any, params?: QueryString) {
82
+ return this.client.patch(path, data, { params });
83
+ }
84
+
85
+ /**************************************************************
86
+ * OAuth Endpoints
87
+ **************************************************************/
88
+
89
+ /**
90
+ * Create an OAuth Authorization url
91
+ * @param params The OAuth information
92
+ * @param params.state The state parameter (optional)
93
+ * @param params.scope The scope parameter (optional)
94
+ * @param params.client_id The client_id parameter (optional)
95
+ * @param params.redirect_uri The redirect_uri parameter (optional)
96
+ * @param params.response_type The response_type parameter (default: "code")
97
+ * @returns The url to redirect to
98
+ */
99
+ authorizeUrl(params: OAuth.IAuthorizeUrlParams) {
100
+ return OAuth.authorizeUrl(this.client, params);
101
+ }
102
+ /**
103
+ * Create an OAuth Access Token
104
+ * @param params The OAuth information
105
+ * @param params.code The code parameter
106
+ * @param params.client_id The client_id parameter
107
+ * @param params.client_secret The client_secret parameter
108
+ * @param params.redirect_uri The redirect_uri parameter (optional)
109
+ * @param params.grant_type The grant_type parameter (default: "authorization_code")
110
+ * @returns The access token
111
+ */
112
+ async accessToken(params: OAuth.IAccessTokenParams) {
113
+ const res = await OAuth.accessToken(this.client, params);
114
+ return ResponseWrapper<typeof res.data>(res);
115
+ }
116
+ /**
117
+ * Revoke an OAuth Access Token
118
+ * @param params The access token information
119
+ * @param params.access_token The access token
120
+ * @param params.client_id The client_id parameter
121
+ * @param params.client_secret The client_secret parameter
122
+ * @returns The result of the revoked token
123
+ */
124
+ async revokeToken(params: OAuth.IRevokeTokenParams) {
125
+ const res = await OAuth.revokeToken(this.client, params);
126
+ return ResponseWrapper<typeof res.data>(res);
127
+ }
128
+
129
+ /**************************************************************
130
+ * Meta Endpoints
131
+ **************************************************************/
132
+
133
+ /**
134
+ * Get the current authorization information
135
+ * @returns The authorization information
136
+ */
137
+ async info() {
138
+ const res = await Meta.info(this.client);
139
+ return ResponseWrapper<typeof res.data>(res);
140
+ }
141
+ /**
142
+ * Get the current authenticated user
143
+ * @returns The current authenticated user
144
+ */
145
+ async authenticatedUser() {
146
+ const res = await Meta.user(this.client);
147
+ return ResponseWrapper<typeof res.data>(res);
148
+ }
149
+
150
+ /**************************************************************
151
+ * Site Endpoints
152
+ **************************************************************/
153
+
154
+ /**
155
+ * Get a list of Sites available
156
+ * @param query The query parameters (optional)
157
+ * @returns A list of Sites
158
+ */
159
+ async sites(query?: QueryString) {
160
+ return SiteWrapper.list(this.client, query);
161
+ }
162
+ /**
163
+ * Get a single Site
164
+ * @param params The Site information
165
+ * @param params.siteId The Site ID
166
+ * @returns The Site
167
+ */
168
+ async site({ siteId }: { siteId: string }) {
169
+ return SiteWrapper.getOne(this.client, { siteId });
170
+ }
171
+ /**
172
+ * Publish a Site
173
+ * @param params The Site information
174
+ * @param params.siteId The Site ID
175
+ * @param params.domain The domains to publish
176
+ * @returns The result of the publish
177
+ */
178
+ publishSite({ siteId, domains }: { siteId: string } & { domains: string[] }) {
179
+ return SiteWrapper.publish(this.client, { siteId, domains });
180
+ }
181
+ /**
182
+ * Get a list of Domains for a Site
183
+ * @param params The Site information
184
+ * @param params.siteId The Site ID
185
+ * @returns A list of Domains
186
+ */
187
+ async domains({ siteId }: { siteId: string }) {
188
+ return SiteWrapper.domains(this.client, { siteId });
189
+ }
190
+
191
+ /**************************************************************
192
+ * Collection Endpoints
193
+ **************************************************************/
194
+
195
+ /**
196
+ * Get a list of Collections
197
+ * @param params The Site information
198
+ * @param params.siteId The Site ID
199
+ * @param query The query parameters (optional)
200
+ * @returns A list of Collections
201
+ */
202
+ async collections({ siteId }: { siteId: string }, query?: QueryString) {
203
+ return CollectionWrapper.list(this.client, { siteId }, query);
204
+ }
205
+ /**
206
+ * Get a single Collection
207
+ * @param params The Collection information
208
+ * @param params.collectionId The Collection ID
209
+ * @returns A single Collection
210
+ */
211
+ async collection({ collectionId }: { collectionId: string }) {
212
+ return CollectionWrapper.getOne(this.client, { collectionId });
213
+ }
214
+
215
+ /**************************************************************
216
+ * Item Endpoints
217
+ **************************************************************/
218
+
219
+ /**
220
+ * Get a list of Collection Items
221
+ * @param params The Collection information
222
+ * @param params.collectionId The Collection ID
223
+ * @param pageParams The pagination parameters (optional)
224
+ * @returns A list of Items
225
+ */
226
+ async items(
227
+ { collectionId }: { collectionId: string },
228
+ pageParams?: PaginationFilter
229
+ ) {
230
+ return ItemWrapper.list(this.client, { collectionId, ...pageParams });
231
+ }
232
+ /**
233
+ * Get a single Collection Item
234
+ * @param params The Item information
235
+ * @param params.collectionId The Collection ID
236
+ * @param params.itemId The Item ID
237
+ * @returns A single Collection Item
238
+ */
239
+ async item({
240
+ itemId,
241
+ collectionId,
242
+ }: {
243
+ itemId: string;
244
+ collectionId: string;
245
+ }) {
246
+ return ItemWrapper.getOne(this.client, { itemId, collectionId });
247
+ }
248
+ /**
249
+ * Create a new Collection Item
250
+ * @param params The Item information
251
+ * @param params.collectionId The Collection ID
252
+ * @returns The created Collection Item
253
+ */
254
+ async createItem({
255
+ collectionId,
256
+ fields,
257
+ }: {
258
+ collectionId: string;
259
+ fields: any;
260
+ }) {
261
+ return ItemWrapper.create(this.client, { collectionId, fields });
262
+ }
263
+ /**
264
+ * Update a Collection Item
265
+ * @param params The Item information
266
+ * @param params.collectionId The Collection ID
267
+ * @param params.itemId The Item ID
268
+ * @param query The query parameters (optional)
269
+ * @returns The updated Collection Item
270
+ */
271
+ updateItem({
272
+ collectionId,
273
+ itemId,
274
+ ...fields
275
+ }: {
276
+ itemId: string;
277
+ collectionId: string;
278
+ }) {
279
+ const _params = { collectionId, itemId, fields };
280
+ return ItemWrapper.update(this.client, _params);
281
+ }
282
+ /**
283
+ * Patch a Collection Item
284
+ * @param params The Item information
285
+ * @param params.collectionId The Collection ID
286
+ * @param params.itemId The Item ID
287
+ * @param query The query parameters (optional)
288
+ * @returns The patched Collection Item
289
+ */
290
+ patchItem(
291
+ {
292
+ collectionId,
293
+ itemId,
294
+ ...fields
295
+ }: { collectionId: string; itemId: string },
296
+ query?: QueryString
297
+ ) {
298
+ const _params = { collectionId, itemId, fields };
299
+ return ItemWrapper.patch(this.client, _params, query);
300
+ }
301
+ /**
302
+ * Delete a Collection Item
303
+ * @param params The Item information
304
+ * @param params.collectionId The Collection ID
305
+ * @param params.itemId The Item ID
306
+ * @returns The deleted Collection Item result
307
+ */
308
+ removeItem({
309
+ collectionId,
310
+ itemId,
311
+ }: {
312
+ itemId: string;
313
+ collectionId: string;
314
+ }) {
315
+ return ItemWrapper.remove(this.client, { collectionId, itemId });
316
+ }
317
+ /**
318
+ * Upublish a Collection Item
319
+ * @param params The Item information
320
+ * @param params.collectionId The Collection ID
321
+ * @param params.itemId The Item ID
322
+ * @param query The query parameters (optional)
323
+ * @param query.live Update the live version
324
+ * @returns The unpublished Collection Item result
325
+ */
326
+ deleteItems({
327
+ collectionId,
328
+ itemIds,
329
+ live,
330
+ }: {
331
+ collectionId: string;
332
+ itemIds: string[];
333
+ live?: boolean;
334
+ }) {
335
+ const params = { collectionId, itemIds, live };
336
+ return ItemWrapper.unpublish(this.client, params);
337
+ }
338
+ /**
339
+ * Publish a Collection Item
340
+ * @param params The Item information
341
+ * @param params.collectionId The Collection ID
342
+ * @param params.itemId The Item ID
343
+ * @param query The query parameters (optional)
344
+ * @param query.live Update the live version
345
+ * @returns The Published Collection Item result
346
+ */
347
+ publishItems({
348
+ collectionId,
349
+ itemIds,
350
+ live,
351
+ }: {
352
+ collectionId: string;
353
+ itemIds: string[];
354
+ live?: boolean;
355
+ }) {
356
+ const params = { collectionId, itemIds, live };
357
+ return ItemWrapper.publish(this.client, params);
358
+ }
359
+
360
+ /**************************************************************
361
+ * Membership Endpoints
362
+ **************************************************************/
363
+
364
+ /**
365
+ * Get a list of User accounts
366
+ * @param params The Site information
367
+ * @param params.siteId The Site ID
368
+ * @param pageParams The pagination information (optional)
369
+ * @returns A list of User accounts
370
+ */
371
+ async users({ siteId }: { siteId: string }, pageParams?: PaginationFilter) {
372
+ return MembershipWrapper.list(this.client, { siteId, ...pageParams });
373
+ }
374
+
375
+ /**
376
+ * Get a single User account
377
+ * @param param The Site and User information
378
+ * @param param.siteId The Site ID
379
+ * @param param.userId The User ID
380
+ * @returns The User information
381
+ */
382
+ async user({ siteId, userId }: { siteId: string; userId: string }) {
383
+ return MembershipWrapper.getOne(this.client, { siteId, userId });
384
+ }
385
+
386
+ /**
387
+ * Update a User account
388
+ * @param params The Site and User information
389
+ * @param params.siteId The Site ID
390
+ * @param params.userId The User ID
391
+ * @returns The updated User
392
+ */
393
+ async updateUser({
394
+ siteId,
395
+ userId,
396
+ ...data
397
+ }: {
398
+ siteId: string;
399
+ userId: string;
400
+ data: any;
401
+ }) {
402
+ const _params = { siteId, userId, data };
403
+ return MembershipWrapper.update(this.client, _params);
404
+ }
405
+
406
+ /**
407
+ * Invite a User to a Site
408
+ * @param params The Site and User information
409
+ * @param params.siteId The Site ID
410
+ * @param params.email The User's email address
411
+ * @returns The created User account
412
+ */
413
+ async inviteUser({ siteId, email }: { siteId: string; email: string }) {
414
+ return MembershipWrapper.invite(this.client, { siteId, email });
415
+ }
416
+
417
+ /**
418
+ * Remove a user from a Site
419
+ * @param params The Site and User information
420
+ * @param params.siteId The Site ID
421
+ * @param params.userId The User ID
422
+ * @returns The result from the remove request
423
+ */
424
+ removeUser({ siteId, userId }: { siteId: string; userId: string }) {
425
+ return MembershipWrapper.remove(this.client, { siteId, userId });
426
+ }
427
+
428
+ /**************************************************************
429
+ * Webhook Endpoints
430
+ **************************************************************/
431
+
432
+ /**
433
+ * Get a list of webhooks for a Site
434
+ * @param params The site information to get the Webhooks from
435
+ * @param params.siteId The Site ID
436
+ * @returns A list of Webhooks
437
+ */
438
+ async webhooks({ siteId }: { siteId: string }, query?: QueryString) {
439
+ return WebhookWrapper.list(this.client, { siteId }, query);
440
+ }
441
+
442
+ /**
443
+ * Get a single Webhook
444
+ * @param params The Webhook and Site information
445
+ * @param params.siteId The Site Id
446
+ * @param params.webhookId The Webhook Id
447
+ * @returns The Webhook
448
+ */
449
+ async webhook({ siteId, webhookId }: { siteId: string; webhookId: string }) {
450
+ return WebhookWrapper.getOne(this.client, { siteId, webhookId });
451
+ }
452
+
453
+ /**
454
+ * Remove a Webhook
455
+ * @param params The Webhook and Site information
456
+ * @param params.siteId The Site Id
457
+ * @param params.webhookId The Webhook Id
458
+ * @returns the result from the remove request
459
+ */
460
+ removeWebhook({ siteId, webhookId }: { siteId: string; webhookId: string }) {
461
+ return WebhookWrapper.remove(this.client, { siteId, webhookId });
462
+ }
463
+
464
+ /**
465
+ * Create a Webhook
466
+ * @param params The params to create a webhooks
467
+ * @param params.siteId The Site Id
468
+ * @param params.url The Url the Webhook should call on events
469
+ * @param params.triggerType The type of event that should trigger the Webhook
470
+ * @param params.filter The filter to apply to the Webhook (form_submssion only)
471
+ * @returns The created webhook
472
+ */
473
+ async createWebhook({
474
+ url,
475
+ siteId,
476
+ triggerType,
477
+ filter,
478
+ }: {
479
+ url: string;
480
+ siteId: string;
481
+ triggerType: string;
482
+ filter?: Webhook.Filter;
483
+ }) {
484
+ const _params = { url, siteId, triggerType, filter };
485
+ return WebhookWrapper.create(this.client, _params);
486
+ }
487
+ }
@@ -0,0 +1,115 @@
1
+ import { ResponseWrapper, ItemWrapper } from ".";
2
+ import { Client, QueryString } from "../core";
3
+ import { Collection, Item } from "../api";
4
+
5
+ export class CollectionWrapper implements Collection.ICollection {
6
+ fields: Collection.CollectionField[];
7
+ singularName: string;
8
+ lastUpdated: string;
9
+ createdOn: string;
10
+ _id: string;
11
+ name: string;
12
+ slug: string;
13
+
14
+ constructor(private client: Client, collection: Collection.ICollection) {
15
+ Object.assign(this, collection);
16
+ }
17
+
18
+ /**************************************************************
19
+ * Static Methods
20
+ **************************************************************/
21
+
22
+ /**
23
+ * Get a single Collection
24
+ * @param client The Webflow client
25
+ * @param params The Collection information
26
+ * @param params.collectionId The Collection ID
27
+ * @returns A single Collection
28
+ */
29
+ static async getOne(
30
+ client: Client,
31
+ { collectionId }: { collectionId: string }
32
+ ) {
33
+ const res = await Collection.getOne(client, { collectionId });
34
+ const collection = new CollectionWrapper(client, res.data);
35
+ return ResponseWrapper<typeof collection>(res, collection);
36
+ }
37
+
38
+ /**
39
+ * Get a list of Collections
40
+ * @param client The Webflow client
41
+ * @param params1 The Site information
42
+ * @param params1.siteId The Site ID
43
+ * @param params The query parameters (optional)
44
+ * @returns A list of Collections
45
+ */
46
+ static async list(
47
+ client: Client,
48
+ { siteId }: { siteId: string },
49
+ params?: QueryString
50
+ ) {
51
+ const res = await Collection.list(client, { siteId }, params);
52
+ const collections = res.data.map((c) => new CollectionWrapper(client, c));
53
+ return ResponseWrapper<typeof collections>(res, collections);
54
+ }
55
+
56
+ /**************************************************************
57
+ * Instance Methods
58
+ **************************************************************/
59
+
60
+ /**
61
+ * Get a single Item
62
+ * @param params The params for the request
63
+ * @param params.itemId The Item ID
64
+ * @returns A single Item
65
+ */
66
+ async item({ itemId }: { itemId: string }) {
67
+ return ItemWrapper.getOne(this.client, { itemId, collectionId: this._id });
68
+ }
69
+
70
+ /**
71
+ * Get a list of Items
72
+ * @param params The params for the request
73
+ * @param params.limit The number of items to return (optional)
74
+ * @param params.offset The number of items to skip (optional)
75
+ * @returns A list of Items
76
+ */
77
+ async items(params?: QueryString) {
78
+ return ItemWrapper.list(this.client, { collectionId: this._id, ...params });
79
+ }
80
+
81
+ /**
82
+ * Remove a single Item
83
+ * @param params The params for the request
84
+ * @param params.itemId The Item ID
85
+ * @returns The result from the removal
86
+ */
87
+ async removeItem({ itemId }: { itemId: string }) {
88
+ return ItemWrapper.remove(this.client, { itemId, collectionId: this._id });
89
+ }
90
+
91
+ /**
92
+ * Create a new Item
93
+ * @param params The params for the request
94
+ * @param params.fields The Item fields to create
95
+ * @returns The created Item
96
+ */
97
+ async createItem(fields: any) {
98
+ return ItemWrapper.create(this.client, { collectionId: this._id, fields });
99
+ }
100
+
101
+ /**
102
+ * Update a single Item
103
+ * @param params The params for the request
104
+ * @param params.itemId The Item ID
105
+ * @param params.fields The fields to update
106
+ * @returns The updated Item
107
+ */
108
+ async updateItem({ itemId, fields }: { itemId: string; fields: any }) {
109
+ return ItemWrapper.update(this.client, {
110
+ collectionId: this._id,
111
+ itemId,
112
+ fields,
113
+ });
114
+ }
115
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./membership";
2
+ export * from "./collection";
3
+ export * from "./response";
4
+ export * from "./webhook";
5
+ export * from "./site";
6
+ export * from "./item";