webflow-api 0.5.3 → 0.7.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/index.d.ts ADDED
@@ -0,0 +1,354 @@
1
+ declare class Webflow {
2
+ constructor(options: Webflow.WebflowOptions);
3
+
4
+ get<Result extends any>(
5
+ path: string,
6
+ query?: Webflow.WebflowQueryArg
7
+ ): Promise<Result>;
8
+ post<Data extends any, Result extends any>(
9
+ path: string,
10
+ data?: Data,
11
+ query?: Webflow.WebflowQueryArg
12
+ ): Promise<Result>;
13
+ put<Data extends any, Result extends any>(
14
+ path: string,
15
+ data?: Data,
16
+ query?: Webflow.WebflowQueryArg
17
+ ): Promise<Result>;
18
+ patch<Data extends any, Result extends any>(
19
+ path: string,
20
+ data?: Data,
21
+ query?: Webflow.WebflowQueryArg
22
+ ): Promise<Result>;
23
+ delete<Result extends any>(
24
+ path: string,
25
+ query?: Webflow.WebflowQueryArg
26
+ ): Promise<Result>;
27
+
28
+ info(query?: Webflow.WebflowQueryArg): Promise<Webflow.WebflowApiModel.Info>;
29
+
30
+ // sites
31
+
32
+ sites(
33
+ query?: Webflow.WebflowQueryArg
34
+ ): Promise<Webflow.WebflowApiModel.Site[]>;
35
+
36
+ site(
37
+ params: {
38
+ siteId: string;
39
+ },
40
+ query?: Webflow.WebflowQueryArg
41
+ ): Promise<Webflow.WebflowApiModel.Site>;
42
+
43
+ publishSite(
44
+ data: {
45
+ siteId: string;
46
+ domains: string[];
47
+ },
48
+ query?: Webflow.WebflowQueryArg
49
+ ): Promise<{ queued: boolean }>;
50
+
51
+ // Domains
52
+
53
+ domains(
54
+ data: {
55
+ siteId: string;
56
+ },
57
+ query?: Webflow.WebflowQueryArg
58
+ ): Promise<Webflow.WebflowApiModel.Domain[]>;
59
+
60
+ // Collections
61
+
62
+ collections(
63
+ data: {
64
+ siteId: string;
65
+ },
66
+ query?: Webflow.WebflowQueryArg
67
+ ): Promise<Webflow.WebflowApiModel.Collection[]>;
68
+ collection(
69
+ data: {
70
+ collectionId: string;
71
+ },
72
+ query?: Webflow.WebflowQueryArg
73
+ ): Promise<Webflow.WebflowApiModel.Collection>;
74
+
75
+ // Items
76
+
77
+ items(
78
+ data: {
79
+ collectionId: string;
80
+ },
81
+ query?: Webflow.WebflowQueryArg
82
+ ): Promise<Webflow.WebflowApiModel.ItemsResponse>;
83
+
84
+ item(
85
+ data: {
86
+ collectionId: string;
87
+ itemId: string;
88
+ },
89
+ query?: Webflow.WebflowQueryArg
90
+ ): Promise<Webflow.WebflowApiModel.CollectionItem>;
91
+
92
+ createItem(
93
+ // TODO: add a better data type
94
+ data: { collectionId: string } & Record<string, any>,
95
+ query?: Webflow.WebflowQueryArg
96
+ ): Promise<Webflow.WebflowApiModel.CollectionItem>;
97
+
98
+ updateItem(
99
+ // TODO: add a better data type
100
+ data: { collectionId: string; itemId: string } & Record<string, any>,
101
+ query?: Webflow.WebflowQueryArg
102
+ ): Promise<Webflow.WebflowApiModel.CollectionItem>;
103
+
104
+ removeItem(
105
+ data: { collectionId: string; itemId: string },
106
+ query?: Webflow.WebflowQueryArg
107
+ ): Promise<{ deleted: number }>;
108
+
109
+ patchItem(
110
+ // TODO: add a better data type
111
+ data: { collectionId: string; itemId: string } & Record<string, any>,
112
+ query?: Webflow.WebflowQueryArg
113
+ ): Promise<Webflow.WebflowApiModel.CollectionItem>;
114
+
115
+ // Webhooks
116
+
117
+ webhooks(
118
+ data: { siteId: string },
119
+ query?: Webflow.WebflowQueryArg
120
+ ): Promise<Webflow.WebflowApiModel.Webhook[]>;
121
+
122
+ webhook(
123
+ data: { siteId: string; webhookId: string },
124
+ query?: Webflow.WebflowQueryArg
125
+ ): Promise<Webflow.WebflowApiModel.Webhook>;
126
+
127
+ createWebhook(
128
+ // TODO: add a better data type
129
+ data: { siteId: string } & Record<string, any>,
130
+ query?: Webflow.WebflowQueryArg
131
+ ): Promise<Webflow.WebflowApiModel.Webhook>;
132
+
133
+ removeWebhook(
134
+ data: { siteId: string; webhookId: string },
135
+ query?: Webflow.WebflowQueryArg
136
+ ): Promise<{ deleted: number }>;
137
+ }
138
+
139
+ declare namespace Webflow {
140
+ // other exported properties
141
+ class WebflowError extends Error {}
142
+
143
+ // helper types / namespaces
144
+ type WebflowQueryArg = Record<string, any>;
145
+
146
+ interface WebflowOptions {
147
+ token: string;
148
+ endpoint?: string;
149
+ version?: string;
150
+ }
151
+
152
+ namespace WebflowApiModel {
153
+ interface InfoApplication {
154
+ _id: string;
155
+ description: string;
156
+ homepage: string;
157
+ name: string;
158
+ owner: string;
159
+ ownerType: string;
160
+ }
161
+
162
+ /**
163
+ * https://developers.webflow.com/?javascript#get-current-authorization-info
164
+ */
165
+ interface Info {
166
+ _id: string;
167
+ createdOn: string;
168
+ grantType: string;
169
+ lastUsed: string;
170
+ sites: string[];
171
+ orgs: string[];
172
+ users: string[];
173
+ rateLimit: number;
174
+ status: string;
175
+ application: InfoApplication;
176
+ }
177
+ /**
178
+ * https://developers.webflow.com/?javascript#sites
179
+ */
180
+ interface Site {
181
+ _id: string;
182
+ createdOn: string;
183
+ name: string;
184
+ shortName: string;
185
+ lastPublished: string;
186
+ previewUrl: string;
187
+ timezone: string;
188
+ database: string;
189
+
190
+ collections: OmitFirstArgOfFunction<Webflow["collections"]>;
191
+ webhooks: OmitFirstArgOfFunction<Webflow["webhooks"]>;
192
+ domains: OmitFirstArgOfFunction<Webflow["domains"]>;
193
+ webhook: OmitPropertyFromFirstArgOfFunction<Webflow["webhook"], "siteId">;
194
+ createWebhook: OmitPropertyFromFirstArgOfFunction<
195
+ Webflow["createWebhook"],
196
+ "siteId"
197
+ >;
198
+ removeWebhook: OmitPropertyFromFirstArgOfFunction<
199
+ Webflow["removeWebhook"],
200
+ "siteId"
201
+ >;
202
+ publishSite: OmitPropertyFromFirstArgOfFunction<
203
+ Webflow["publishSite"],
204
+ "siteId"
205
+ >;
206
+ }
207
+
208
+ /**
209
+ * https://developers.webflow.com/?javascript#domains
210
+ */
211
+ interface Domain {
212
+ _id: string;
213
+ name: string;
214
+ }
215
+
216
+ /**
217
+ * https://developers.webflow.com/?javascript#collections
218
+ */
219
+ interface Collection {
220
+ _id: string;
221
+ lastUpdated: string;
222
+ createdOn: string;
223
+ name: string;
224
+ slug: string;
225
+ singularName: string;
226
+ fields: CollectionField[];
227
+
228
+ items: OmitFirstArgOfFunction<Webflow["items"]>;
229
+ item: OmitPropertyFromFirstArgOfFunction<Webflow["item"], "collectionId">;
230
+ createItem: OmitPropertyFromFirstArgOfFunction<
231
+ Webflow["createItem"],
232
+ "collectionId"
233
+ >;
234
+ updateItem: OmitPropertyFromFirstArgOfFunction<
235
+ Webflow["updateItem"],
236
+ "collectionId"
237
+ >;
238
+ removeItem: OmitPropertyFromFirstArgOfFunction<
239
+ Webflow["removeItem"],
240
+ "collectionId"
241
+ >;
242
+ }
243
+
244
+ type CollectionFieldType =
245
+ | "Bool"
246
+ | "Color"
247
+ | "Date"
248
+ | "ExtFileRef"
249
+ | "Set"
250
+ | "ImageRef"
251
+ | "Set"
252
+ | "ItemRef"
253
+ | "ItemRefSet"
254
+ | "Link"
255
+ | "Number"
256
+ | "Option"
257
+ | "PlainText"
258
+ | "RichText"
259
+ | "Video"
260
+ | "User";
261
+
262
+ /**
263
+ * https://developers.webflow.com/?javascript#fields
264
+ */
265
+ interface CollectionField {
266
+ id: string;
267
+ type: CollectionFieldType;
268
+ slug: string;
269
+ name: string;
270
+ required: boolean;
271
+ editable: boolean;
272
+ // TODO: add a better type
273
+ validations: any;
274
+ }
275
+
276
+ /**
277
+ * https://developers.webflow.com/?javascript#items
278
+ */
279
+ interface CollectionItem extends Record<string, any> {
280
+ _archived: boolean;
281
+ _draft: boolean;
282
+ _id: string;
283
+ _cid: string;
284
+ name: string;
285
+ slug: string;
286
+ "updated-on": string;
287
+ "created-on": string;
288
+ "published-on": string;
289
+ "updated-by": string;
290
+ "created-by": string;
291
+ "published-by": string;
292
+
293
+ update: OmitPropertyFromFirstArgOfFunction<
294
+ Webflow["updateItem"],
295
+ "collectionId" | "itemId"
296
+ >;
297
+ remove: OmitFirstArgOfFunction<Webflow["removeItem"]>;
298
+ }
299
+
300
+ interface ResponseMeta {
301
+ rateLimit: {
302
+ limit: number;
303
+ remaining: number;
304
+ }
305
+ }
306
+
307
+ interface ItemsResponse {
308
+ items: CollectionItem[];
309
+ count: number;
310
+ limit: number;
311
+ offset: number;
312
+ total: number;
313
+ _meta: ResponseMeta;
314
+ }
315
+
316
+ type WebhookTriggerType =
317
+ | "form_submission"
318
+ | "site_publish"
319
+ | "ecomm_new_order"
320
+ | "ecomm_order_changed"
321
+ | "ecomm_inventory_changed"
322
+ | "collection_item_created"
323
+ | "collection_item_changed"
324
+ | "collection_item_deleted";
325
+
326
+ interface Webhook {
327
+ _id: string;
328
+ triggerType: WebhookTriggerType;
329
+ triggerId: string;
330
+ site: string;
331
+ filter: string;
332
+ lastUsed: string;
333
+ createdOn: string;
334
+
335
+ remove: OmitFirstArgOfFunction<Webflow["removeWebhook"]>;
336
+ }
337
+ }
338
+ }
339
+
340
+ export = Webflow;
341
+
342
+ type OmitFirstArgOfFunction<Fn> = Fn extends (
343
+ x: any,
344
+ ...args: infer Args
345
+ ) => infer R
346
+ ? (...args: Args) => R
347
+ : never;
348
+
349
+ type OmitPropertyFromFirstArgOfFunction<Fn, P extends string> = Fn extends (
350
+ x: infer A,
351
+ ...args: infer Args
352
+ ) => infer R
353
+ ? (x: Omit<A, P>, ...args: Args) => R
354
+ : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webflow-api",
3
- "version": "0.5.3",
3
+ "version": "0.7.0",
4
4
  "description": "SDK for the Webflow CMS API",
5
5
  "main": "dist/index.js",
6
6
  "jsnext:main": "src/index.js",
@@ -9,11 +9,13 @@
9
9
  "type": "git"
10
10
  },
11
11
  "license": "MIT",
12
+ "types": "index.d.ts",
12
13
  "files": [
13
14
  "dist",
14
15
  "src",
15
16
  "LICENSE",
16
- "yarn.lock"
17
+ "yarn.lock",
18
+ "index.d.ts"
17
19
  ],
18
20
  "scripts": {
19
21
  "build": "BABEL_ENV=production babel --out-dir dist src/",
@@ -25,29 +27,25 @@
25
27
  "watch:test": "npm run test -- --watch"
26
28
  },
27
29
  "devDependencies": {
28
- "ava": "^0.16.0",
29
- "babel-cli": "^6.18.0",
30
- "babel-core": "^6.18.2",
31
- "babel-eslint": "^7.1.0",
32
- "babel-plugin-add-module-exports": "^0.2.1",
33
- "babel-preset-es2015": "^6.18.0",
34
- "babel-preset-stage-1": "^6.16.0",
35
- "babel-register": "^6.18.0",
36
- "eslint": "^3.10.1",
37
- "eslint-config-airbnb-base": "^10.0.1",
38
- "eslint-plugin-import": "^2.2.0",
30
+ "@babel/cli": "^7.17.6",
31
+ "@babel/core": "^7.17.8",
32
+ "@babel/preset-env": "^7.16.11",
33
+ "@babel/register": "^7.17.7",
34
+ "ava": "^4.1.0",
35
+ "es6-error": "^4.0.0",
36
+ "eslint": "^8.12.0",
37
+ "eslint-config-airbnb-base": "^15.0.0",
38
+ "eslint-plugin-import": "^2.25.2",
39
39
  "nock": "^13.0.7",
40
- "nyc": "^9.0.1"
40
+ "nyc": "^15.1.0"
41
41
  },
42
42
  "dependencies": {
43
- "es6-error": "^4.0.0",
44
43
  "isomorphic-fetch": "^3.0.0",
45
44
  "qs": "^6.3.0"
46
45
  },
47
46
  "ava": {
48
47
  "require": [
49
- "babel-register"
50
- ],
51
- "babel": "inherit"
48
+ "@babel/register"
49
+ ]
52
50
  }
53
51
  }
package/src/Webflow.js CHANGED
@@ -179,7 +179,7 @@ export default class Webflow {
179
179
 
180
180
  item({ collectionId, itemId }, query = {}) {
181
181
  if (!collectionId) return Promise.reject(buildRequiredArgError('collectionId'));
182
- if (!itemId) return Promise.reject(buildRequiredArgError('siteId'));
182
+ if (!itemId) return Promise.reject(buildRequiredArgError('itemId'));
183
183
 
184
184
  return this.get(`/collections/${collectionId}/items/${itemId}`, query).then(
185
185
  res => this.responseWrapper.item(res.items[0], collectionId),
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- module.exports = require('./Webflow');
2
- module.exports.WebflowError = require('./WebflowError').default;
1
+ module.exports = require("./Webflow").default;
2
+ module.exports.WebflowError = require("./WebflowError").default;