webflow-api 0.5.4 → 0.6.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 (2) hide show
  1. package/index.d.ts +338 -0
  2. package/package.json +3 -2
package/index.d.ts ADDED
@@ -0,0 +1,338 @@
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.CollectionItem[]>;
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
+ type WebhookTriggerType =
301
+ | "form_submission"
302
+ | "site_publish"
303
+ | "ecomm_new_order"
304
+ | "ecomm_order_changed"
305
+ | "ecomm_inventory_changed"
306
+ | "collection_item_created"
307
+ | "collection_item_changed"
308
+ | "collection_item_deleted";
309
+
310
+ interface Webhook {
311
+ _id: string;
312
+ triggerType: WebhookTriggerType;
313
+ triggerId: string;
314
+ site: string;
315
+ filter: string;
316
+ lastUsed: string;
317
+ createdOn: string;
318
+
319
+ remove: OmitFirstArgOfFunction<Webflow["removeWebhook"]>;
320
+ }
321
+ }
322
+ }
323
+
324
+ export = Webflow;
325
+
326
+ type OmitFirstArgOfFunction<Fn> = Fn extends (
327
+ x: any,
328
+ ...args: infer Args
329
+ ) => infer R
330
+ ? (...args: Args) => R
331
+ : never;
332
+
333
+ type OmitPropertyFromFirstArgOfFunction<Fn, P extends string> = Fn extends (
334
+ x: infer A,
335
+ ...args: infer Args
336
+ ) => infer R
337
+ ? (x: Omit<A, P>, ...args: Args) => R
338
+ : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webflow-api",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
4
4
  "description": "SDK for the Webflow CMS API",
5
5
  "main": "dist/index.js",
6
6
  "jsnext:main": "src/index.js",
@@ -14,7 +14,8 @@
14
14
  "dist",
15
15
  "src",
16
16
  "LICENSE",
17
- "yarn.lock"
17
+ "yarn.lock",
18
+ "index.d.ts"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "BABEL_ENV=production babel --out-dir dist src/",