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/index.d.ts DELETED
@@ -1,430 +0,0 @@
1
- declare class Webflow {
2
- constructor(options: Webflow.Options);
3
- token: string;
4
-
5
- get<Result extends any>(
6
- path: string,
7
- query?: Webflow.QueryArg
8
- ): Promise<Result>;
9
- post<Data extends any, Result extends any>(
10
- path: string,
11
- data?: Data,
12
- query?: Webflow.QueryArg
13
- ): Promise<Result>;
14
- put<Data extends any, Result extends any>(
15
- path: string,
16
- data?: Data,
17
- query?: Webflow.QueryArg
18
- ): Promise<Result>;
19
- patch<Data extends any, Result extends any>(
20
- path: string,
21
- data?: Data,
22
- query?: Webflow.QueryArg
23
- ): Promise<Result>;
24
- delete<Result extends any>(
25
- path: string,
26
- query?: Webflow.QueryArg
27
- ): Promise<Result>;
28
-
29
- // meta
30
- info(): Promise<Webflow.ApiModel.Info>;
31
- authenticatedUser(): Promise<Webflow.ApiModel.AuthenticatedUser>;
32
-
33
- // oauth
34
- authorizeUrl(params: {
35
- client_id: string;
36
- redirect_uri?: string;
37
- state?: string;
38
- scope?: string;
39
- response_type?: string;
40
- }): string;
41
-
42
- accessToken(params: {
43
- client_id: string;
44
- client_secret: string;
45
- redirect_uri?: string;
46
- code: string;
47
- grant_type?: string;
48
- }): Promise<{
49
- token_type: string;
50
- access_token: string;
51
- }>;
52
-
53
- revokeToken(params: {
54
- client_id: string;
55
- client_secret: string;
56
- access_token: string;
57
- }): Promise<{ didRevoke: boolean }>;
58
-
59
- // sites
60
- sites(query?: Webflow.QueryArg): Promise<Webflow.ApiModel.Site[]>;
61
-
62
- site(
63
- params: {
64
- siteId: string;
65
- },
66
- query?: Webflow.QueryArg
67
- ): Promise<Webflow.ApiModel.Site>;
68
-
69
- publishSite(
70
- data: {
71
- siteId: string;
72
- domains: string[];
73
- },
74
- query?: Webflow.QueryArg
75
- ): Promise<{ queued: boolean }>;
76
-
77
- // Domains
78
-
79
- domains(
80
- data: {
81
- siteId: string;
82
- },
83
- query?: Webflow.QueryArg
84
- ): Promise<Webflow.ApiModel.Domain[]>;
85
-
86
- // Collections
87
-
88
- collections(
89
- data: {
90
- siteId: string;
91
- },
92
- query?: Webflow.QueryArg
93
- ): Promise<Webflow.ApiModel.Collection[]>;
94
- collection(
95
- data: {
96
- collectionId: string;
97
- },
98
- query?: Webflow.QueryArg
99
- ): Promise<Webflow.ApiModel.Collection>;
100
-
101
- // Users
102
- users(
103
- data: {
104
- siteId: string;
105
- },
106
- query?: Webflow.QueryArg
107
- ): Promise<Webflow.ApiModel.User[]>;
108
-
109
- user(
110
- data: {
111
- siteId: string;
112
- userId: string;
113
- },
114
- query?: Webflow.QueryArg
115
- ): Promise<Webflow.ApiModel.User>;
116
-
117
- updateUser(
118
- data: { siteId: string; userId: string } & Record<string, any>,
119
- query?: Webflow.QueryArg
120
- ): Promise<Webflow.ApiModel.User>;
121
-
122
- removeUser(
123
- data: { siteId: string; userId: string },
124
- query?: Webflow.QueryArg
125
- ): Promise<{ deleted: number }>;
126
-
127
- inviteUser(
128
- data: { siteId: string; email: string },
129
- query?: Webflow.QueryArg
130
- ): Promise<Webflow.ApiModel.User>;
131
-
132
- // Items
133
-
134
- items(
135
- data: {
136
- collectionId: string;
137
- },
138
- query?: Webflow.QueryArg
139
- ): Promise<Webflow.ApiModel.ItemsResponse>;
140
-
141
- item(
142
- data: {
143
- collectionId: string;
144
- itemId: string;
145
- },
146
- query?: Webflow.QueryArg
147
- ): Promise<Webflow.ApiModel.CollectionItem>;
148
-
149
- createItem(
150
- // TODO: add a better data type
151
- data: { collectionId: string } & Record<string, any>,
152
- query?: Webflow.QueryArg
153
- ): Promise<Webflow.ApiModel.CollectionItem>;
154
-
155
- updateItem(
156
- // TODO: add a better data type
157
- data: { collectionId: string; itemId: string } & Record<string, any>,
158
- query?: Webflow.QueryArg
159
- ): Promise<Webflow.ApiModel.CollectionItem>;
160
-
161
- removeItem(
162
- data: { collectionId: string; itemId: string },
163
- query?: Webflow.QueryArg
164
- ): Promise<{ deleted: number }>;
165
-
166
- patchItem(
167
- // TODO: add a better data type
168
- data: { collectionId: string; itemId: string } & Record<string, any>,
169
- query?: Webflow.QueryArg
170
- ): Promise<Webflow.ApiModel.CollectionItem>;
171
-
172
- // Webhooks
173
-
174
- webhooks(
175
- data: { siteId: string },
176
- query?: Webflow.QueryArg
177
- ): Promise<Webflow.ApiModel.Webhook[]>;
178
-
179
- webhook(
180
- data: { siteId: string; webhookId: string },
181
- query?: Webflow.QueryArg
182
- ): Promise<Webflow.ApiModel.Webhook>;
183
-
184
- createWebhook(
185
- // TODO: add a better data type
186
- data: { siteId: string } & Record<string, any>,
187
- query?: Webflow.QueryArg
188
- ): Promise<Webflow.ApiModel.Webhook>;
189
-
190
- removeWebhook(
191
- data: { siteId: string; webhookId: string },
192
- query?: Webflow.QueryArg
193
- ): Promise<{ deleted: number }>;
194
- }
195
-
196
- declare namespace Webflow {
197
- // other exported properties
198
- class WebflowError extends Error {}
199
-
200
- // helper types / namespaces
201
- type QueryArg = Record<string, any>;
202
-
203
- interface Options {
204
- token: string;
205
- endpoint?: string;
206
- version?: string;
207
- mode?: string;
208
- headers?: { [key: string]: string };
209
- }
210
-
211
- namespace ApiModel {
212
- interface AuthenticatedUser {
213
- user: {
214
- _id: string;
215
- email: string;
216
- firstName: string;
217
- lastName: string;
218
- };
219
- }
220
-
221
- interface InfoApplication {
222
- _id: string;
223
- description: string;
224
- homepage: string;
225
- name: string;
226
- owner: string;
227
- ownerType: string;
228
- }
229
-
230
- /**
231
- * https://developers.webflow.com/?javascript#get-current-authorization-info
232
- */
233
- interface Info {
234
- _id: string;
235
- createdOn: string;
236
- grantType: string;
237
- lastUsed: string;
238
- sites: string[];
239
- orgs: string[];
240
- users: string[];
241
- rateLimit: number;
242
- status: string;
243
- application: InfoApplication;
244
- }
245
- /**
246
- * https://developers.webflow.com/?javascript#sites
247
- */
248
- interface Site {
249
- _id: string;
250
- createdOn: string;
251
- name: string;
252
- shortName: string;
253
- lastPublished: string;
254
- previewUrl: string;
255
- timezone: string;
256
- database: string;
257
-
258
- collections: OmitFirstArgOfFunction<Webflow["collections"]>;
259
- webhooks: OmitFirstArgOfFunction<Webflow["webhooks"]>;
260
- domains: OmitFirstArgOfFunction<Webflow["domains"]>;
261
- webhook: OmitPropertyFromFirstArgOfFunction<Webflow["webhook"], "siteId">;
262
- createWebhook: OmitPropertyFromFirstArgOfFunction<
263
- Webflow["createWebhook"],
264
- "siteId"
265
- >;
266
- removeWebhook: OmitPropertyFromFirstArgOfFunction<
267
- Webflow["removeWebhook"],
268
- "siteId"
269
- >;
270
- publishSite: OmitPropertyFromFirstArgOfFunction<
271
- Webflow["publishSite"],
272
- "siteId"
273
- >;
274
- }
275
-
276
- /**
277
- * https://developers.webflow.com/?javascript#domains
278
- */
279
- interface Domain {
280
- _id: string;
281
- name: string;
282
- }
283
-
284
- interface User {
285
- _id: string;
286
- lastUpdated: string;
287
- createdOn: string;
288
- emailVerified: boolean;
289
- data: object;
290
- }
291
-
292
- /**
293
- * https://developers.webflow.com/?javascript#collections
294
- */
295
- interface Collection {
296
- _id: string;
297
- lastUpdated: string;
298
- createdOn: string;
299
- name: string;
300
- slug: string;
301
- singularName: string;
302
- fields: CollectionField[];
303
-
304
- items: OmitFirstArgOfFunction<Webflow["items"]>;
305
- item: OmitPropertyFromFirstArgOfFunction<Webflow["item"], "collectionId">;
306
- createItem: OmitPropertyFromFirstArgOfFunction<
307
- Webflow["createItem"],
308
- "collectionId"
309
- >;
310
- updateItem: OmitPropertyFromFirstArgOfFunction<
311
- Webflow["updateItem"],
312
- "collectionId"
313
- >;
314
- removeItem: OmitPropertyFromFirstArgOfFunction<
315
- Webflow["removeItem"],
316
- "collectionId"
317
- >;
318
- }
319
-
320
- type CollectionFieldType =
321
- | "Bool"
322
- | "Color"
323
- | "Date"
324
- | "ExtFileRef"
325
- | "Set"
326
- | "ImageRef"
327
- | "Set"
328
- | "ItemRef"
329
- | "ItemRefSet"
330
- | "Link"
331
- | "Number"
332
- | "Option"
333
- | "PlainText"
334
- | "RichText"
335
- | "Video"
336
- | "User";
337
-
338
- /**
339
- * https://developers.webflow.com/?javascript#fields
340
- */
341
- interface CollectionField {
342
- id: string;
343
- type: CollectionFieldType;
344
- slug: string;
345
- name: string;
346
- required: boolean;
347
- editable: boolean;
348
- // TODO: add a better type
349
- validations: any;
350
- }
351
-
352
- /**
353
- * https://developers.webflow.com/?javascript#items
354
- */
355
- interface CollectionItem extends Record<string, any> {
356
- _archived: boolean;
357
- _draft: boolean;
358
- _id: string;
359
- _cid: string;
360
- name: string;
361
- slug: string;
362
- "updated-on": string;
363
- "created-on": string;
364
- "published-on": string;
365
- "updated-by": string;
366
- "created-by": string;
367
- "published-by": string;
368
-
369
- update: OmitPropertyFromFirstArgOfFunction<
370
- Webflow["updateItem"],
371
- "collectionId" | "itemId"
372
- >;
373
- remove: OmitFirstArgOfFunction<Webflow["removeItem"]>;
374
- }
375
-
376
- interface ResponseMeta {
377
- rateLimit: {
378
- limit: number;
379
- remaining: number;
380
- };
381
- }
382
-
383
- interface ItemsResponse {
384
- items: CollectionItem[];
385
- count: number;
386
- limit: number;
387
- offset: number;
388
- total: number;
389
- _meta: ResponseMeta;
390
- }
391
-
392
- type WebhookTriggerType =
393
- | "form_submission"
394
- | "site_publish"
395
- | "ecomm_new_order"
396
- | "ecomm_order_changed"
397
- | "ecomm_inventory_changed"
398
- | "collection_item_created"
399
- | "collection_item_changed"
400
- | "collection_item_deleted";
401
-
402
- interface Webhook {
403
- _id: string;
404
- triggerType: WebhookTriggerType;
405
- triggerId: string;
406
- site: string;
407
- filter: string;
408
- lastUsed: string;
409
- createdOn: string;
410
-
411
- remove: OmitFirstArgOfFunction<Webflow["removeWebhook"]>;
412
- }
413
- }
414
- }
415
-
416
- export = Webflow;
417
-
418
- type OmitFirstArgOfFunction<Fn> = Fn extends (
419
- x: any,
420
- ...args: infer Args
421
- ) => infer R
422
- ? (...args: Args) => R
423
- : never;
424
-
425
- type OmitPropertyFromFirstArgOfFunction<Fn, P extends string> = Fn extends (
426
- x: infer A,
427
- ...args: infer Args
428
- ) => infer R
429
- ? (x: Omit<A, P>, ...args: Args) => R
430
- : never;
@@ -1,103 +0,0 @@
1
- export default class ResponseWrapper {
2
- constructor(api) {
3
- this.api = api;
4
- }
5
-
6
- site(site) {
7
- return {
8
- ...site,
9
-
10
- collections: this.api.collections.bind(this.api, { siteId: site._id }),
11
- webhooks: this.api.webhooks.bind(this.api, { siteId: site._id }),
12
- domains: this.api.domains.bind(this.api, { siteId: site._id }),
13
- webhook: (first, ...rest) => {
14
- return this.api.webhook({ ...first, siteId: site._id }, ...rest);
15
- },
16
- createWebhook: (first, ...rest) => {
17
- return this.api.createWebhook({ ...first, siteId: site._id }, ...rest);
18
- },
19
- removeWebhook: (first, ...rest) => {
20
- return this.api.removeWebhook({ ...first, siteId: site._id }, ...rest);
21
- },
22
- publishSite: (domains) => {
23
- return this.api.publishSite({ siteId: site._id, domains });
24
- },
25
- };
26
- }
27
-
28
- domain(domain) {
29
- return {
30
- ...domain,
31
- };
32
- }
33
-
34
- collection(collection) {
35
- return {
36
- ...collection,
37
-
38
- items: this.api.items.bind(this.api, { collectionId: collection._id }),
39
- item: (first, ...rest) => {
40
- return this.api.item(
41
- { ...first, collectionId: collection._id },
42
- ...rest
43
- );
44
- },
45
- createItem: (first, ...rest) => {
46
- return this.api.createItem(
47
- { ...first, collectionId: collection._id },
48
- ...rest
49
- );
50
- },
51
- updateItem: (first, ...rest) => {
52
- return this.api.updateItem(
53
- { ...first, collectionId: collection._id },
54
- ...rest
55
- );
56
- },
57
- removeItem: (first, ...rest) => {
58
- return this.api.removeItem(
59
- { ...first, collectionId: collection._id },
60
- ...rest
61
- );
62
- },
63
- };
64
- }
65
-
66
- item(item, collectionId) {
67
- const itemId = item._id;
68
- const ids = { itemId, collectionId };
69
- return {
70
- ...item,
71
-
72
- update: (itemData, query) => {
73
- return this.api.updateItem({ ...itemData, ...ids }, query);
74
- },
75
- remove: (query) => {
76
- return this.api.removeItem(ids, query);
77
- },
78
- };
79
- }
80
-
81
- user(user, siteId) {
82
- const userId = user._id;
83
- const ids = { userId, siteId };
84
-
85
- return {
86
- ...user,
87
- update: (userData) => {
88
- return this.api.updateUser({ ...ids, ...userData });
89
- },
90
- remove: this.api.removeUser.bind(this.api, ids),
91
- };
92
- }
93
-
94
- webhook(webhook, siteId) {
95
- const webhookId = webhook._id;
96
- const ids = { webhookId, siteId };
97
-
98
- return {
99
- ...webhook,
100
- remove: this.api.removeWebhook.bind(this.api, ids),
101
- };
102
- }
103
- }