webflow-api 1.3.0 → 1.3.1

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 (54) hide show
  1. package/dist/api/collection.d.ts +112 -0
  2. package/dist/api/collection.js +94 -0
  3. package/dist/api/index.d.ts +7 -0
  4. package/dist/api/index.js +23 -0
  5. package/dist/api/item.d.ts +177 -0
  6. package/dist/api/item.js +151 -0
  7. package/dist/api/meta.d.ts +53 -0
  8. package/dist/api/meta.js +25 -0
  9. package/dist/api/oauth.d.ts +71 -0
  10. package/dist/api/oauth.js +71 -0
  11. package/dist/api/site.d.ts +140 -0
  12. package/dist/api/site.js +137 -0
  13. package/dist/api/user.d.ts +143 -0
  14. package/dist/api/user.js +119 -0
  15. package/dist/api/webhook.d.ts +102 -0
  16. package/dist/api/webhook.js +80 -0
  17. package/dist/core/error.d.ts +21 -0
  18. package/dist/core/error.js +30 -0
  19. package/dist/core/index.d.ts +3 -0
  20. package/dist/core/index.js +19 -0
  21. package/dist/core/response.d.ts +32 -0
  22. package/dist/core/response.js +26 -0
  23. package/dist/core/webflow.d.ts +390 -0
  24. package/dist/core/webflow.js +518 -0
  25. package/dist/index.d.ts +2 -0
  26. package/package.json +7 -1
  27. package/yarn.lock +2840 -0
  28. package/.eslintrc +0 -31
  29. package/.github/workflows/code-quality.yml +0 -102
  30. package/.github/workflows/npm-publish.yml +0 -21
  31. package/.github/workflows/semgrep.yml +0 -24
  32. package/.prettierignore +0 -5
  33. package/.prettierrc +0 -6
  34. package/jest.config.js +0 -17
  35. package/tests/api/collection.test.ts +0 -147
  36. package/tests/api/item.test.ts +0 -180
  37. package/tests/api/meta.test.ts +0 -38
  38. package/tests/api/oauth.test.ts +0 -44
  39. package/tests/api/site.test.ts +0 -202
  40. package/tests/api/user.test.ts +0 -139
  41. package/tests/api/webhook.test.ts +0 -82
  42. package/tests/core/error.test.ts +0 -19
  43. package/tests/core/response.test.ts +0 -36
  44. package/tests/core/webflow.test.ts +0 -540
  45. package/tests/fixtures/collection.fixture.ts +0 -374
  46. package/tests/fixtures/index.ts +0 -7
  47. package/tests/fixtures/item.fixture.ts +0 -193
  48. package/tests/fixtures/meta.fixture.ts +0 -34
  49. package/tests/fixtures/oauth.fixture.ts +0 -38
  50. package/tests/fixtures/site.fixture.ts +0 -78
  51. package/tests/fixtures/user.fixture.ts +0 -175
  52. package/tests/fixtures/webhook.fixture.ts +0 -69
  53. package/tsconfig.eslint.json +0 -7
  54. package/tsconfig.json +0 -14
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Webflow = exports.SCOPES_ARRAY = exports.USER_AGENT = exports.DEFAULT_HOST = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const core_1 = require("../core");
9
+ const api_1 = require("../api");
10
+ exports.DEFAULT_HOST = "webflow.com";
11
+ exports.USER_AGENT = "Webflow Javascript SDK / 1.0";
12
+ exports.SCOPES_ARRAY = [
13
+ "assets:read",
14
+ "assets:write",
15
+ "authorized_user:read",
16
+ "cms:read",
17
+ "cms:write",
18
+ "custom_code:read",
19
+ "custom_code:write",
20
+ "forms:read",
21
+ "forms:write",
22
+ "pages:read",
23
+ "pages:write",
24
+ "sites:read",
25
+ "sites:write",
26
+ "users:read",
27
+ "users:write",
28
+ "ecommerce:read",
29
+ "ecommerce:write",
30
+ ];
31
+ /**************************************************************
32
+ * Class
33
+ **************************************************************/
34
+ class Webflow {
35
+ constructor(options = {}) {
36
+ this.options = options;
37
+ this.client = axios_1.default.create(this.config);
38
+ this.client.interceptors.response.use(core_1.ErrorInterceptor);
39
+ if (this.options.beta) {
40
+ this.removeNonBetaMethods();
41
+ }
42
+ }
43
+ removeNonBetaMethods() {
44
+ const methodsToRemove = [
45
+ "info",
46
+ "authenticatedUser",
47
+ "sites",
48
+ "site",
49
+ "publishSite",
50
+ "domains",
51
+ "collections",
52
+ "collection",
53
+ "items",
54
+ "item",
55
+ "createItem",
56
+ "updateItem",
57
+ "patchItem",
58
+ "removeItem",
59
+ "deleteItems",
60
+ "publishItems",
61
+ ];
62
+ methodsToRemove.forEach((method) => {
63
+ Object.defineProperty(this, method, {
64
+ value: function () {
65
+ throw new Error(`The method '${method}()' is not available in beta mode. Please disable the beta option to use this method.`);
66
+ },
67
+ enumerable: false,
68
+ configurable: true,
69
+ });
70
+ });
71
+ }
72
+ // Set the Authentication token
73
+ set token(value) {
74
+ this.options.token = value;
75
+ }
76
+ // clear the Authorization header
77
+ clearToken() {
78
+ delete this.options.token;
79
+ }
80
+ // The Axios configuration
81
+ get config() {
82
+ const { host = exports.DEFAULT_HOST, token, version, headers, beta = false } = this.options;
83
+ const effectiveHost = beta ? "webflow.com/beta" : host;
84
+ const config = {
85
+ baseURL: `https://api.${effectiveHost}/`,
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ "User-Agent": exports.USER_AGENT,
89
+ ...headers,
90
+ },
91
+ };
92
+ // Add the version to the headers if passed in
93
+ if (version)
94
+ config.headers["Accept-Version"] = version;
95
+ // Add the Authorization header if a token is set
96
+ if (token)
97
+ config.headers.Authorization = `Bearer ${token}`;
98
+ config.paramsSerializer = {
99
+ serialize: (params) => {
100
+ if (typeof params !== "object" || params === null) {
101
+ return "";
102
+ }
103
+ const parts = [];
104
+ for (const key in params) {
105
+ const value = params[key];
106
+ if (value === undefined)
107
+ continue;
108
+ const safeValue = typeof value === "string" || typeof value === "number" ? value : String(value);
109
+ if (key === "scope") {
110
+ parts.push(`${key}=${safeValue}`);
111
+ }
112
+ else {
113
+ parts.push(`${key}=${encodeURIComponent(safeValue)}`);
114
+ }
115
+ }
116
+ return parts.join("&");
117
+ },
118
+ };
119
+ return config;
120
+ }
121
+ /**************************************************************
122
+ * HTTP Methods
123
+ **************************************************************/
124
+ /**
125
+ * Send a GET request to the Webflow API
126
+ * @param path The path to the endpoint
127
+ * @param params The query parameters (optional)
128
+ * @returns The response from the Webflow API
129
+ */
130
+ get(path, params) {
131
+ return this.client.get(path, { params });
132
+ }
133
+ /**
134
+ * Send a DELETE request to the Webflow API
135
+ * @param path The path to the endpoint
136
+ * @param params The query parameters (optional)
137
+ * @returns The response from the Webflow API
138
+ */
139
+ delete(path, params) {
140
+ return this.client.delete(path, { params });
141
+ }
142
+ /**
143
+ * Send a POST request to create a new Collection
144
+ * @param path The path to the endpoint
145
+ * @param data The data to send
146
+ * @param params The query parameters (optional)
147
+ * @returns The response from the Webflow API
148
+ */
149
+ post(path, data, params) {
150
+ return this.client.post(path, data, { params });
151
+ }
152
+ /**
153
+ * Send a PUT request to create a new Collection
154
+ * @param path The path to the endpoint
155
+ * @param data The data to send
156
+ * @param params The query parameters (optional)
157
+ * @returns The response from the Webflow API
158
+ */
159
+ put(path, data, params) {
160
+ return this.client.put(path, data, { params });
161
+ }
162
+ /**
163
+ * Send a PATCH request to create a new Collection
164
+ * @param path The path to the endpoint
165
+ * @param data The data to send
166
+ * @param params The query parameters (optional)
167
+ * @returns The response from the Webflow API
168
+ */
169
+ patch(path, data, params) {
170
+ return this.client.patch(path, data, { params });
171
+ }
172
+ /**************************************************************
173
+ * OAuth Endpoints
174
+ **************************************************************/
175
+ /**
176
+ * Create an OAuth Authorization url
177
+ * @param params The OAuth information
178
+ * @param params.state The state parameter (optional)
179
+ * @param params.scope The scope parameter (optional)
180
+ * @param params.client_id The client_id parameter (optional)
181
+ * @param params.redirect_uri The redirect_uri parameter (optional)
182
+ * @param params.response_type The response_type parameter (default: "code")
183
+ * @returns The url to redirect to
184
+ */
185
+ authorizeUrl(params) {
186
+ return api_1.OAuth.authorizeUrl(params, this.client);
187
+ }
188
+ /**
189
+ * Create an OAuth Access Token
190
+ * @param params The OAuth information
191
+ * @param params.code The code parameter
192
+ * @param params.client_id The client_id parameter
193
+ * @param params.client_secret The client_secret parameter
194
+ * @param params.redirect_uri The redirect_uri parameter (optional)
195
+ * @param params.grant_type The grant_type parameter (default: "authorization_code")
196
+ * @returns The access token
197
+ */
198
+ async accessToken(params) {
199
+ const res = await api_1.OAuth.accessToken(params, this.client);
200
+ return res.data;
201
+ }
202
+ /**
203
+ * Revoke an OAuth Access Token
204
+ * @param params The access token information
205
+ * @param params.access_token The access token
206
+ * @param params.client_id The client_id parameter
207
+ * @param params.client_secret The client_secret parameter
208
+ * @returns The result of the revoked token
209
+ */
210
+ async revokeToken(params) {
211
+ const res = await api_1.OAuth.revokeToken(params, this.client);
212
+ return res.data;
213
+ }
214
+ /**************************************************************
215
+ * Meta Endpoints
216
+ **************************************************************/
217
+ /**
218
+ * Get the current authorization information
219
+ * @returns The authorization information
220
+ */
221
+ async info() {
222
+ const res = await api_1.Meta.info(this.client);
223
+ return res.data;
224
+ }
225
+ /**
226
+ * Get the current authenticated user
227
+ * @returns The current authenticated user
228
+ */
229
+ async authenticatedUser() {
230
+ const res = await api_1.Meta.user(this.client);
231
+ return res.data;
232
+ }
233
+ /**************************************************************
234
+ * Site Endpoints
235
+ **************************************************************/
236
+ /**
237
+ * Get a list of Sites available
238
+ * @returns A list of Sites
239
+ */
240
+ async sites() {
241
+ const res = await api_1.Site.list(this.client);
242
+ return res.data.map((data) => new api_1.Site(this.client, { ...res, data }));
243
+ }
244
+ /**
245
+ * Get a single Site
246
+ * @param params The Site information
247
+ * @param params.siteId The Site ID
248
+ * @returns The Site
249
+ */
250
+ async site({ siteId }) {
251
+ const res = await api_1.Site.getOne({ siteId }, this.client);
252
+ return new api_1.Site(this.client, res);
253
+ }
254
+ /**
255
+ * Publish a Site
256
+ * @param params The Site information
257
+ * @param params.siteId The Site ID
258
+ * @param params.domain The domains to publish
259
+ * @returns The result of the publish
260
+ */
261
+ async publishSite({ siteId, domains }) {
262
+ const res = await api_1.Site.publish({ siteId, domains }, this.client);
263
+ return res.data;
264
+ }
265
+ /**
266
+ * Get a list of Domains for a Site
267
+ * @param params The Site information
268
+ * @param params.siteId The Site ID
269
+ * @returns A list of Domains
270
+ */
271
+ async domains({ siteId }) {
272
+ const res = await api_1.Site.domains({ siteId }, this.client);
273
+ return res.data;
274
+ }
275
+ /**************************************************************
276
+ * Collection Endpoints
277
+ **************************************************************/
278
+ /**
279
+ * Get a list of Collections
280
+ * @param params The Site information
281
+ * @param params.siteId The Site ID
282
+ * @returns A list of Collections
283
+ */
284
+ async collections({ siteId }) {
285
+ const res = await api_1.Collection.list({ siteId }, this.client);
286
+ return res.data.map((data) => new api_1.Collection(this.client, { ...res, data }));
287
+ }
288
+ /**
289
+ * Get a single Collection
290
+ * @param params The Collection information
291
+ * @param params.collectionId The Collection ID
292
+ * @returns A single Collection
293
+ */
294
+ async collection({ collectionId }) {
295
+ const res = await api_1.Collection.getOne({ collectionId }, this.client);
296
+ return new api_1.Collection(this.client, res);
297
+ }
298
+ /**************************************************************
299
+ * Item Endpoints
300
+ **************************************************************/
301
+ /**
302
+ * Get a list of Collection Items
303
+ * @param params The Collection information
304
+ * @param params.collectionId The Collection ID
305
+ * @param params.limit The number of items to return
306
+ * @param params.offset The number of items to skip
307
+ * @returns A list of Items
308
+ */
309
+ async items({ collectionId, limit, offset }) {
310
+ const res = await api_1.Item.list({ collectionId, limit, offset }, this.client);
311
+ return res.data.items.map((data) => new api_1.Item(this.client, { ...res, data }));
312
+ }
313
+ /**
314
+ * Get a single Collection Item
315
+ * @param params The Item information
316
+ * @param params.collectionId The Collection ID
317
+ * @param params.itemId The Item ID
318
+ * @returns A single Collection Item
319
+ */
320
+ async item({ itemId, collectionId }) {
321
+ const res = await api_1.Item.getOne({ itemId, collectionId }, this.client);
322
+ const [item] = res.data.items.map((data) => new api_1.Item(this.client, { ...res, data }));
323
+ return item;
324
+ }
325
+ /**
326
+ * Create a new Collection Item
327
+ * @param params The Item information
328
+ * @param params.collectionId The Collection ID
329
+ * @returns The created Collection Item
330
+ */
331
+ async createItem({ collectionId, fields }) {
332
+ const res = await api_1.Item.create({ collectionId, fields }, this.client);
333
+ return new api_1.Item(this.client, res);
334
+ }
335
+ /**
336
+ * Update a Collection Item
337
+ * @param params The Item information
338
+ * @param params.collectionId The Collection ID
339
+ * @param params.itemId The Item ID
340
+ * @param query The query parameters (optional)
341
+ * @returns The updated Collection Item
342
+ */
343
+ async updateItem({ collectionId, itemId, ...fields }) {
344
+ const _params = { collectionId, itemId, fields };
345
+ const res = await api_1.Item.update(_params, this.client);
346
+ return new api_1.Item(this.client, res);
347
+ }
348
+ /**
349
+ * Patch a Collection Item
350
+ * @param params The Item information
351
+ * @param params.collectionId The Collection ID
352
+ * @param params.itemId The Item ID
353
+ * @returns The patched Collection Item
354
+ */
355
+ async patchItem({ collectionId, itemId, ...fields }) {
356
+ const _params = { collectionId, itemId, fields };
357
+ const res = await api_1.Item.patch(_params, this.client);
358
+ return new api_1.Item(this.client, res);
359
+ }
360
+ /**
361
+ * Delete a Collection Item
362
+ * @param params The Item information
363
+ * @param params.collectionId The Collection ID
364
+ * @param params.itemId The Item ID
365
+ * @returns The deleted Collection Item result
366
+ */
367
+ async removeItem({ collectionId, itemId }) {
368
+ const res = await api_1.Item.remove({ collectionId, itemId }, this.client);
369
+ return res.data;
370
+ }
371
+ /**
372
+ * Unpublish a Collection Item
373
+ * @param params The Item information
374
+ * @param params.collectionId The Collection ID
375
+ * @param params.itemId The Item ID
376
+ * @param params.live Update the live version
377
+ * @returns The unpublished Collection Item result
378
+ */
379
+ async deleteItems({ collectionId, itemIds, live, }) {
380
+ const res = await api_1.Item.unpublish({ collectionId, itemIds, live }, this.client);
381
+ return res.data;
382
+ }
383
+ /**
384
+ * Publish a Collection Item
385
+ * @param params The Item information
386
+ * @param params.collectionId The Collection ID
387
+ * @param params.itemId The Item ID
388
+ * @param params.live Update the live version
389
+ * @returns The Published Collection Item result
390
+ */
391
+ async publishItems({ collectionId, itemIds, live, }) {
392
+ const res = await api_1.Item.publish({ collectionId, itemIds, live }, this.client);
393
+ return res.data;
394
+ }
395
+ /**************************************************************
396
+ * Membership Endpoints
397
+ **************************************************************/
398
+ /**
399
+ * Get a list of User accounts
400
+ * @param params The Site information
401
+ * @param params.siteId The Site ID
402
+ * @param pageParams The pagination information (optional)
403
+ * @returns A list of User accounts
404
+ */
405
+ async users({ siteId }, pageParams) {
406
+ const res = await api_1.User.list({ siteId, ...pageParams }, this.client);
407
+ return res.data.users.map((data) => new api_1.User(this.client, { ...res, data }));
408
+ }
409
+ /**
410
+ * Get a single User account
411
+ * @param param The Site and User information
412
+ * @param param.siteId The Site ID
413
+ * @param param.userId The User ID
414
+ * @returns The User information
415
+ */
416
+ async user({ siteId, userId }) {
417
+ const res = await api_1.User.getOne({ siteId, userId }, this.client);
418
+ return new api_1.User(this.client, res, res.data, { siteId });
419
+ }
420
+ /**
421
+ * Update a User account
422
+ * @param params The Site and User information
423
+ * @param params.siteId The Site ID
424
+ * @param params.userId The User ID
425
+ * @returns The updated User
426
+ */
427
+ async updateUser({ siteId, userId, ...data }) {
428
+ const _params = { siteId, userId, data };
429
+ const res = await api_1.User.update(_params, this.client);
430
+ return new api_1.User(this.client, res, res.data, { siteId });
431
+ }
432
+ /**
433
+ * Invite a User to a Site
434
+ * @param params The Site and User information
435
+ * @param params.siteId The Site ID
436
+ * @param params.email The User's email address
437
+ * @returns The created User account
438
+ */
439
+ async inviteUser({ siteId, email }) {
440
+ const res = await api_1.User.invite({ siteId, email }, this.client);
441
+ return new api_1.User(this.client, res, res.data, { siteId });
442
+ }
443
+ /**
444
+ * Remove a user from a Site
445
+ * @param params The Site and User information
446
+ * @param params.siteId The Site ID
447
+ * @param params.userId The User ID
448
+ * @returns The result from the remove request
449
+ */
450
+ async removeUser({ siteId, userId }) {
451
+ const res = await api_1.User.remove({ siteId, userId }, this.client);
452
+ return res.data;
453
+ }
454
+ /**
455
+ * Get a list of User Access Groups
456
+ * @param params The params for the request
457
+ * @param params.siteId The site ID
458
+ * @param params.limit The number of items to return (optional)
459
+ * @param params.offset The number of items to skip (optional)
460
+ * @param params.sort The sort order of the groups (optional)
461
+ * @returns A list of Access Groups
462
+ */
463
+ async accessGroups({ siteId, limit, offset, sort, }) {
464
+ const params = { siteId, limit, offset, sort };
465
+ const res = await api_1.User.accessGroups(params, this.client);
466
+ return res.data;
467
+ }
468
+ /**************************************************************
469
+ * Webhook Endpoints
470
+ **************************************************************/
471
+ /**
472
+ * Get a list of webhooks for a Site
473
+ * @param params The site information to get the Webhooks from
474
+ * @param params.siteId The Site ID
475
+ * @returns A list of Webhooks
476
+ */
477
+ async webhooks({ siteId }) {
478
+ const res = await api_1.Webhook.list({ siteId }, this.client);
479
+ return res.data.map((data) => new api_1.Webhook(this.client, { ...res, data }));
480
+ }
481
+ /**
482
+ * Get a single Webhook
483
+ * @param params The Webhook and Site information
484
+ * @param params.siteId The Site Id
485
+ * @param params.webhookId The Webhook Id
486
+ * @returns The Webhook
487
+ */
488
+ async webhook({ siteId, webhookId }) {
489
+ const res = await api_1.Webhook.getOne({ siteId, webhookId }, this.client);
490
+ return new api_1.Webhook(this.client, res);
491
+ }
492
+ /**
493
+ * Remove a Webhook
494
+ * @param params The Webhook and Site information
495
+ * @param params.siteId The Site Id
496
+ * @param params.webhookId The Webhook Id
497
+ * @returns the result from the remove request
498
+ */
499
+ async removeWebhook({ siteId, webhookId }) {
500
+ const res = await api_1.Webhook.remove({ siteId, webhookId }, this.client);
501
+ return res.data;
502
+ }
503
+ /**
504
+ * Create a Webhook
505
+ * @param params The params to create a webhooks
506
+ * @param params.siteId The Site Id
507
+ * @param params.url The Url the Webhook should call on events
508
+ * @param params.triggerType The type of event that should trigger the Webhook
509
+ * @param params.filter The filter to apply to the Webhook (form_submission only)
510
+ * @returns The created webhook
511
+ */
512
+ async createWebhook({ url, siteId, triggerType, filter, }) {
513
+ const _params = { url, siteId, triggerType, filter };
514
+ const res = await api_1.Webhook.create(_params, this.client);
515
+ return new api_1.Webhook(this.client, res);
516
+ }
517
+ }
518
+ exports.Webflow = Webflow;
@@ -0,0 +1,2 @@
1
+ import { Webflow } from "./core";
2
+ export = 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.3.0",
4
+ "version": "1.3.1",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "contributors": [
@@ -13,6 +13,12 @@
13
13
  "type": "git"
14
14
  },
15
15
  "license": "MIT",
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "LICENSE",
20
+ "yarn.lock"
21
+ ],
16
22
  "scripts": {
17
23
  "test": "yarn build && jest",
18
24
  "build": "yarn clean && tsc",