-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from JCMais/ts-types
add TypeScript type definitions
- Loading branch information
Showing
2 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,338 @@ | ||
declare class Webflow { | ||
constructor(options: Webflow.WebflowOptions); | ||
|
||
get<Result extends any>( | ||
path: string, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Result>; | ||
post<Data extends any, Result extends any>( | ||
path: string, | ||
data?: Data, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Result>; | ||
put<Data extends any, Result extends any>( | ||
path: string, | ||
data?: Data, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Result>; | ||
patch<Data extends any, Result extends any>( | ||
path: string, | ||
data?: Data, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Result>; | ||
delete<Result extends any>( | ||
path: string, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Result>; | ||
|
||
info(query?: Webflow.WebflowQueryArg): Promise<Webflow.WebflowApiModel.Info>; | ||
|
||
// sites | ||
|
||
sites( | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Site[]>; | ||
|
||
site( | ||
params: { | ||
siteId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Site>; | ||
|
||
publishSite( | ||
data: { | ||
siteId: string; | ||
domains: string[]; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<{ queued: boolean }>; | ||
|
||
// Domains | ||
|
||
domains( | ||
data: { | ||
siteId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Domain[]>; | ||
|
||
// Collections | ||
|
||
collections( | ||
data: { | ||
siteId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Collection[]>; | ||
collection( | ||
data: { | ||
collectionId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Collection>; | ||
|
||
// Items | ||
|
||
items( | ||
data: { | ||
collectionId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.CollectionItem[]>; | ||
|
||
item( | ||
data: { | ||
collectionId: string; | ||
itemId: string; | ||
}, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.CollectionItem>; | ||
|
||
createItem( | ||
// TODO: add a better data type | ||
data: { collectionId: string } & Record<string, any>, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.CollectionItem>; | ||
|
||
updateItem( | ||
// TODO: add a better data type | ||
data: { collectionId: string; itemId: string } & Record<string, any>, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.CollectionItem>; | ||
|
||
removeItem( | ||
data: { collectionId: string; itemId: string }, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<{ deleted: number }>; | ||
|
||
patchItem( | ||
// TODO: add a better data type | ||
data: { collectionId: string; itemId: string } & Record<string, any>, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.CollectionItem>; | ||
|
||
// Webhooks | ||
|
||
webhooks( | ||
data: { siteId: string }, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Webhook[]>; | ||
|
||
webhook( | ||
data: { siteId: string; webhookId: string }, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Webhook>; | ||
|
||
createWebhook( | ||
// TODO: add a better data type | ||
data: { siteId: string } & Record<string, any>, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<Webflow.WebflowApiModel.Webhook>; | ||
|
||
removeWebhook( | ||
data: { siteId: string; webhookId: string }, | ||
query?: Webflow.WebflowQueryArg | ||
): Promise<{ deleted: number }>; | ||
} | ||
|
||
declare namespace Webflow { | ||
// other exported properties | ||
class WebflowError extends Error {} | ||
|
||
// helper types / namespaces | ||
type WebflowQueryArg = Record<string, any>; | ||
|
||
interface WebflowOptions { | ||
token: string; | ||
endpoint?: string; | ||
version?: string; | ||
} | ||
|
||
namespace WebflowApiModel { | ||
interface InfoApplication { | ||
_id: string; | ||
description: string; | ||
homepage: string; | ||
name: string; | ||
owner: string; | ||
ownerType: string; | ||
} | ||
|
||
/** | ||
* https://developers.webflow.com/?javascript#get-current-authorization-info | ||
*/ | ||
interface Info { | ||
_id: string; | ||
createdOn: string; | ||
grantType: string; | ||
lastUsed: string; | ||
sites: string[]; | ||
orgs: string[]; | ||
users: string[]; | ||
rateLimit: number; | ||
status: string; | ||
application: InfoApplication; | ||
} | ||
/** | ||
* https://developers.webflow.com/?javascript#sites | ||
*/ | ||
interface Site { | ||
_id: string; | ||
createdOn: string; | ||
name: string; | ||
shortName: string; | ||
lastPublished: string; | ||
previewUrl: string; | ||
timezone: string; | ||
database: string; | ||
|
||
collections: OmitFirstArgOfFunction<Webflow["collections"]>; | ||
webhooks: OmitFirstArgOfFunction<Webflow["webhooks"]>; | ||
domains: OmitFirstArgOfFunction<Webflow["domains"]>; | ||
webhook: OmitPropertyFromFirstArgOfFunction<Webflow["webhook"], "siteId">; | ||
createWebhook: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["createWebhook"], | ||
"siteId" | ||
>; | ||
removeWebhook: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["removeWebhook"], | ||
"siteId" | ||
>; | ||
publishSite: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["publishSite"], | ||
"siteId" | ||
>; | ||
} | ||
|
||
/** | ||
* https://developers.webflow.com/?javascript#domains | ||
*/ | ||
interface Domain { | ||
_id: string; | ||
name: string; | ||
} | ||
|
||
/** | ||
* https://developers.webflow.com/?javascript#collections | ||
*/ | ||
interface Collection { | ||
_id: string; | ||
lastUpdated: string; | ||
createdOn: string; | ||
name: string; | ||
slug: string; | ||
singularName: string; | ||
fields: CollectionField[]; | ||
|
||
items: OmitFirstArgOfFunction<Webflow["items"]>; | ||
item: OmitPropertyFromFirstArgOfFunction<Webflow["item"], "collectionId">; | ||
createItem: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["createItem"], | ||
"collectionId" | ||
>; | ||
updateItem: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["updateItem"], | ||
"collectionId" | ||
>; | ||
removeItem: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["removeItem"], | ||
"collectionId" | ||
>; | ||
} | ||
|
||
type CollectionFieldType = | ||
| "Bool" | ||
| "Color" | ||
| "Date" | ||
| "ExtFileRef" | ||
| "Set" | ||
| "ImageRef" | ||
| "Set" | ||
| "ItemRef" | ||
| "ItemRefSet" | ||
| "Link" | ||
| "Number" | ||
| "Option" | ||
| "PlainText" | ||
| "RichText" | ||
| "Video" | ||
| "User"; | ||
|
||
/** | ||
* https://developers.webflow.com/?javascript#fields | ||
*/ | ||
interface CollectionField { | ||
id: string; | ||
type: CollectionFieldType; | ||
slug: string; | ||
name: string; | ||
required: boolean; | ||
editable: boolean; | ||
// TODO: add a better type | ||
validations: any; | ||
} | ||
|
||
/** | ||
* https://developers.webflow.com/?javascript#items | ||
*/ | ||
interface CollectionItem extends Record<string, any> { | ||
_archived: boolean; | ||
_draft: boolean; | ||
_id: string; | ||
_cid: string; | ||
name: string; | ||
slug: string; | ||
"updated-on": string; | ||
"created-on": string; | ||
"published-on": string; | ||
"updated-by": string; | ||
"created-by": string; | ||
"published-by": string; | ||
|
||
update: OmitPropertyFromFirstArgOfFunction< | ||
Webflow["updateItem"], | ||
"collectionId" | "itemId" | ||
>; | ||
remove: OmitFirstArgOfFunction<Webflow["removeItem"]>; | ||
} | ||
|
||
type WebhookTriggerType = | ||
| "form_submission" | ||
| "site_publish" | ||
| "ecomm_new_order" | ||
| "ecomm_order_changed" | ||
| "ecomm_inventory_changed" | ||
| "collection_item_created" | ||
| "collection_item_changed" | ||
| "collection_item_deleted"; | ||
|
||
interface Webhook { | ||
_id: string; | ||
triggerType: WebhookTriggerType; | ||
triggerId: string; | ||
site: string; | ||
filter: string; | ||
lastUsed: string; | ||
createdOn: string; | ||
|
||
remove: OmitFirstArgOfFunction<Webflow["removeWebhook"]>; | ||
} | ||
} | ||
} | ||
|
||
export = Webflow; | ||
|
||
type OmitFirstArgOfFunction<Fn> = Fn extends ( | ||
x: any, | ||
...args: infer Args | ||
) => infer R | ||
? (...args: Args) => R | ||
: never; | ||
|
||
type OmitPropertyFromFirstArgOfFunction<Fn, P extends string> = Fn extends ( | ||
x: infer A, | ||
...args: infer Args | ||
) => infer R | ||
? (x: Omit<A, P>, ...args: Args) => R | ||
: never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"type": "git" | ||
}, | ||
"license": "MIT", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src", | ||
|