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