webflow-api 1.1.2 → 1.2.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 (72) hide show
  1. package/README.md +41 -17
  2. package/dist/api/collection.d.ts +86 -25
  3. package/dist/api/collection.js +88 -29
  4. package/dist/api/index.d.ts +7 -7
  5. package/dist/api/index.js +9 -19
  6. package/dist/api/item.d.ts +141 -107
  7. package/dist/api/item.js +145 -125
  8. package/dist/api/meta.d.ts +16 -14
  9. package/dist/api/meta.js +20 -19
  10. package/dist/api/oauth.d.ts +38 -36
  11. package/dist/api/oauth.js +59 -59
  12. package/dist/api/site.d.ts +118 -43
  13. package/dist/api/site.js +131 -53
  14. package/dist/api/user.d.ts +143 -0
  15. package/dist/api/user.js +119 -0
  16. package/dist/api/webhook.d.ts +77 -55
  17. package/dist/api/webhook.js +74 -61
  18. package/dist/core/error.d.ts +2 -0
  19. package/dist/core/error.js +8 -1
  20. package/dist/core/index.d.ts +2 -2
  21. package/dist/core/index.js +2 -2
  22. package/dist/core/response.d.ts +32 -0
  23. package/dist/core/response.js +26 -0
  24. package/dist/{webflow.d.ts → core/webflow.d.ts} +66 -54
  25. package/dist/{webflow.js → core/webflow.js} +114 -65
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +2 -2
  28. package/package.json +12 -8
  29. package/src/api/collection.ts +103 -36
  30. package/src/api/index.ts +7 -7
  31. package/src/api/item.ts +217 -176
  32. package/src/api/meta.ts +19 -18
  33. package/src/api/oauth.ts +71 -74
  34. package/src/api/site.ts +161 -55
  35. package/src/api/user.ts +192 -0
  36. package/src/api/webhook.ts +103 -80
  37. package/src/core/error.ts +8 -0
  38. package/src/core/index.ts +2 -2
  39. package/src/core/response.ts +50 -0
  40. package/src/{webflow.ts → core/webflow.ts} +153 -125
  41. package/src/index.ts +1 -1
  42. package/yarn.lock +4 -9
  43. package/dist/api/membership.d.ts +0 -114
  44. package/dist/api/membership.js +0 -96
  45. package/dist/core/client.d.ts +0 -27
  46. package/dist/core/client.js +0 -60
  47. package/dist/core/options.d.ts +0 -8
  48. package/dist/core/options.js +0 -5
  49. package/dist/wrapper/collection.d.ts +0 -85
  50. package/dist/wrapper/collection.js +0 -94
  51. package/dist/wrapper/index.d.ts +0 -6
  52. package/dist/wrapper/index.js +0 -22
  53. package/dist/wrapper/item.d.ts +0 -140
  54. package/dist/wrapper/item.js +0 -153
  55. package/dist/wrapper/membership.d.ts +0 -105
  56. package/dist/wrapper/membership.js +0 -123
  57. package/dist/wrapper/response.d.ts +0 -16
  58. package/dist/wrapper/response.js +0 -17
  59. package/dist/wrapper/site.d.ts +0 -168
  60. package/dist/wrapper/site.js +0 -191
  61. package/dist/wrapper/webhook.d.ts +0 -78
  62. package/dist/wrapper/webhook.js +0 -82
  63. package/src/api/membership.ts +0 -155
  64. package/src/core/client.ts +0 -82
  65. package/src/core/options.ts +0 -9
  66. package/src/wrapper/collection.ts +0 -115
  67. package/src/wrapper/index.ts +0 -6
  68. package/src/wrapper/item.ts +0 -218
  69. package/src/wrapper/membership.ts +0 -163
  70. package/src/wrapper/response.ts +0 -25
  71. package/src/wrapper/site.ts +0 -228
  72. package/src/wrapper/webhook.ts +0 -116
@@ -1,191 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SiteWrapper = void 0;
4
- const _1 = require(".");
5
- const api_1 = require("../api");
6
- class SiteWrapper {
7
- constructor(client, site) {
8
- this.client = client;
9
- Object.assign(this, site);
10
- }
11
- /**************************************************************
12
- * Static Methods
13
- **************************************************************/
14
- /**
15
- * Get a single Site
16
- * @param client The Webflow client
17
- * @param params The Site information
18
- * @param params.siteId The Site ID
19
- * @returns The Site
20
- */
21
- static async getOne(client, { siteId }) {
22
- const res = await api_1.Site.getOne(client, { siteId });
23
- const site = new SiteWrapper(client, res.data);
24
- return (0, _1.ResponseWrapper)(res, site);
25
- }
26
- /**
27
- * Get a list of Sites available
28
- * @param client The Webflow client
29
- * @param params The query parameters (optional)
30
- * @returns A list of Sites
31
- */
32
- static async list(client, params) {
33
- const res = await api_1.Site.list(client, params);
34
- const sites = res.data.map((s) => new SiteWrapper(client, s));
35
- return (0, _1.ResponseWrapper)(res, sites);
36
- }
37
- /**
38
- * Get a list of Domains for a Site
39
- * @param client The Webflow client
40
- * @param params The Site information
41
- * @param params.siteId The Site ID
42
- * @returns A list of Domains
43
- */
44
- static async domains(client, { siteId }) {
45
- const res = await api_1.Site.domains(client, { siteId });
46
- return (0, _1.ResponseWrapper)(res, res.data);
47
- }
48
- /**
49
- * Publish a Site
50
- * @param client The Webflow client
51
- * @param params The Site information
52
- * @param params.siteId The Site ID
53
- * @param params.domain The domains to publish
54
- * @returns The result of the publish
55
- */
56
- static async publish(client, { siteId, domains }) {
57
- const res = await api_1.Site.publish(client, { siteId, domains });
58
- return (0, _1.ResponseWrapper)(res);
59
- }
60
- /**************************************************************
61
- * Instance Methods
62
- **************************************************************/
63
- /**
64
- * Get a list of domains for a site
65
- * @returns A list of domains
66
- */
67
- async domains() {
68
- const res = await api_1.Site.domains(this.client, { siteId: this._id });
69
- return (0, _1.ResponseWrapper)(res);
70
- }
71
- /**
72
- * Publish a site
73
- * @param domains The domains to publish to
74
- * @returns The publish result
75
- */
76
- async publishSite(domains) {
77
- const res = await api_1.Site.publish(this.client, { siteId: this._id, domains });
78
- return (0, _1.ResponseWrapper)(res);
79
- }
80
- /**
81
- * Get a single Collection
82
- * @param params The params for the request
83
- * @param params.collectionId The collection ID
84
- * @returns A single Collection
85
- */
86
- async collection({ collectionId }) {
87
- return _1.CollectionWrapper.getOne(this.client, { collectionId });
88
- }
89
- /**
90
- * Get a list of Collections
91
- * @returns A list of Collections
92
- */
93
- async collections() {
94
- return _1.CollectionWrapper.list(this.client, { siteId: this._id });
95
- }
96
- /**
97
- * Get a single Webhook
98
- * @param params The params for the request
99
- * @param params.webhookId The webhook ID
100
- * @returns A single Webhook
101
- */
102
- async webhook({ webhookId }) {
103
- return _1.WebhookWrapper.getOne(this.client, { siteId: this._id, webhookId });
104
- }
105
- /**
106
- * Get a list of Webhooks
107
- * @param params The query string parameters (optional)
108
- * @returns A list of Webhooks
109
- */
110
- async webhooks(params) {
111
- return _1.WebhookWrapper.list(this.client, { siteId: this._id }, params);
112
- }
113
- /**
114
- * Remove a Webhook
115
- * @param params The query string parameters (optional)
116
- * @param params.webhookId The Webhook ID
117
- * @returns The result of the removal
118
- */
119
- async removeWebhook({ webhookId }) {
120
- return _1.WebhookWrapper.remove(this.client, { siteId: this._id, webhookId });
121
- }
122
- /**
123
- * Create a new Webhook
124
- * @param params1 The params for the request
125
- * @param params1.url The URL to send the webhook to
126
- * @param params1.triggerType The event to trigger the webhook
127
- * @param params1.filter The filter to apply to the webhook (optional: form_submission only)
128
- * @param params The query string parameters (optional)
129
- * @returns The created webhook
130
- */
131
- async createWebhook({ triggerType, filter, url }) {
132
- const _params = { url, siteId: this._id, triggerType, filter };
133
- return _1.WebhookWrapper.create(this.client, _params);
134
- }
135
- /**
136
- * Get a list of Users
137
- * @param params The params for the request
138
- * @param params.limit The number of items to return (optional)
139
- * @param params.offset The number of items to skip (optional)
140
- * @returns A list of Users
141
- */
142
- async users({ limit, offset } = {}) {
143
- return _1.MembershipWrapper.list(this.client, {
144
- siteId: this._id,
145
- limit,
146
- offset,
147
- });
148
- }
149
- /**
150
- * Get a single User
151
- * @param params The params for the request
152
- * @param params.userId The user ID
153
- * @returns A single User
154
- */
155
- async user({ userId }) {
156
- return _1.MembershipWrapper.getOne(this.client, { siteId: this._id, userId });
157
- }
158
- /**
159
- * Invite a User to a site
160
- * @param params The params for the request
161
- * @param params.email The email address of the user to invite
162
- * @returns The newly created User
163
- */
164
- async inviteUser({ email }) {
165
- return _1.MembershipWrapper.invite(this.client, { siteId: this._id, email });
166
- }
167
- /**
168
- * Get a list of Access Groups
169
- * @param params The params for the request
170
- * @param params.limit The number of items to return (optional)
171
- * @param params.offset The number of items to skip (optional)
172
- * @returns A list of Access Groups
173
- */
174
- async accessGroups({ limit, offset, } = {}) {
175
- return _1.MembershipWrapper.accessGroups(this.client, {
176
- siteId: this._id,
177
- limit,
178
- offset,
179
- });
180
- }
181
- /**
182
- * Remove a User
183
- * @param params The params for the request
184
- * @param params.userId The user ID
185
- * @returns The result of the remove
186
- */
187
- async removeUser({ userId }) {
188
- return _1.MembershipWrapper.remove(this.client, { siteId: this._id, userId });
189
- }
190
- }
191
- exports.SiteWrapper = SiteWrapper;
@@ -1,78 +0,0 @@
1
- import { Client, QueryString } from "../core";
2
- import { Webhook } from "../api";
3
- export declare type CreateWebhookParams = {
4
- url: string;
5
- siteId: string;
6
- triggerType: string;
7
- filter?: Webhook.Filter;
8
- };
9
- export declare class WebhookWrapper implements Webhook.IWebhook {
10
- private client;
11
- triggerType: Webhook.TriggerType;
12
- triggerId: string;
13
- createdOn: string;
14
- lastUsed?: string;
15
- site: string;
16
- _id: string;
17
- filter?: {
18
- name: string;
19
- };
20
- constructor(client: Client, webhook: Webhook.IWebhook);
21
- /**************************************************************
22
- * Static Methods
23
- **************************************************************/
24
- /**
25
- * Get a Webhook
26
- * @param client The Webflow client
27
- * @param params The Webhook params
28
- * @param params.siteId The Site ID
29
- * @param params.webhookId The Webhook ID
30
- * @returns The Webhook
31
- */
32
- static getOne(client: Client, { siteId, webhookId }: {
33
- siteId: string;
34
- webhookId: string;
35
- }): Promise<import("./response").MetaResponse<WebhookWrapper>>;
36
- /**
37
- * List Webhooks
38
- * @param client The Webflow client
39
- * @param param1 The Webhook params
40
- * @param param1.siteId The Site ID
41
- * @param params Query string params (optional)
42
- * @returns A list of Webhooks
43
- */
44
- static list(client: Client, { siteId }: {
45
- siteId: string;
46
- }, params?: QueryString): Promise<import("./response").MetaResponse<WebhookWrapper[]>>;
47
- /**
48
- * Remove a Webhook
49
- * @param client The Webflow client
50
- * @param params The Webhook params
51
- * @param params.siteId The Site ID
52
- * @param params.webhookId The Webhook ID
53
- * @returns The result of the removal
54
- */
55
- static remove(client: Client, { siteId, webhookId }: {
56
- siteId: string;
57
- webhookId: string;
58
- }): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
59
- /**
60
- * Create a Webhook
61
- * @param client The Webflow client
62
- * @param param1 The Webhook params
63
- * @param param1.siteId The Site ID
64
- * @param param1.url The URL to send the Webhook to
65
- * @param param1.triggerType The event to trigger the Webhook
66
- * @param param1.filter The filter to use (optional: form_submission only)
67
- * @returns The created Webhook
68
- */
69
- static create(client: Client, { triggerType, siteId, filter, url }: CreateWebhookParams): Promise<import("./response").MetaResponse<WebhookWrapper>>;
70
- /**************************************************************
71
- * Instance Methods
72
- **************************************************************/
73
- /**
74
- * Remove a Webhook
75
- * @returns The result of the removal
76
- */
77
- remove(): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
78
- }
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookWrapper = void 0;
4
- const _1 = require(".");
5
- const api_1 = require("../api");
6
- class WebhookWrapper {
7
- constructor(client, webhook) {
8
- this.client = client;
9
- Object.assign(this, webhook);
10
- }
11
- /**************************************************************
12
- * Static Methods
13
- **************************************************************/
14
- /**
15
- * Get a Webhook
16
- * @param client The Webflow client
17
- * @param params The Webhook params
18
- * @param params.siteId The Site ID
19
- * @param params.webhookId The Webhook ID
20
- * @returns The Webhook
21
- */
22
- static async getOne(client, { siteId, webhookId }) {
23
- const res = await api_1.Webhook.getOne(client, { siteId, webhookId });
24
- const webhook = new WebhookWrapper(client, res.data);
25
- return (0, _1.ResponseWrapper)(res, webhook);
26
- }
27
- /**
28
- * List Webhooks
29
- * @param client The Webflow client
30
- * @param param1 The Webhook params
31
- * @param param1.siteId The Site ID
32
- * @param params Query string params (optional)
33
- * @returns A list of Webhooks
34
- */
35
- static async list(client, { siteId }, params) {
36
- const res = await api_1.Webhook.list(client, { siteId }, params);
37
- const webhooks = res.data.map((w) => new WebhookWrapper(client, w));
38
- return (0, _1.ResponseWrapper)(res, webhooks);
39
- }
40
- /**
41
- * Remove a Webhook
42
- * @param client The Webflow client
43
- * @param params The Webhook params
44
- * @param params.siteId The Site ID
45
- * @param params.webhookId The Webhook ID
46
- * @returns The result of the removal
47
- */
48
- static async remove(client, { siteId, webhookId }) {
49
- const res = await api_1.Webhook.remove(client, { siteId, webhookId });
50
- return (0, _1.ResponseWrapper)(res);
51
- }
52
- /**
53
- * Create a Webhook
54
- * @param client The Webflow client
55
- * @param param1 The Webhook params
56
- * @param param1.siteId The Site ID
57
- * @param param1.url The URL to send the Webhook to
58
- * @param param1.triggerType The event to trigger the Webhook
59
- * @param param1.filter The filter to use (optional: form_submission only)
60
- * @returns The created Webhook
61
- */
62
- static async create(client, { triggerType, siteId, filter, url }) {
63
- const args = { triggerType, siteId, filter, url };
64
- const res = await api_1.Webhook.create(client, args);
65
- const _webhook = new WebhookWrapper(client, res.data);
66
- return (0, _1.ResponseWrapper)(res, _webhook);
67
- }
68
- /**************************************************************
69
- * Instance Methods
70
- **************************************************************/
71
- /**
72
- * Remove a Webhook
73
- * @returns The result of the removal
74
- */
75
- async remove() {
76
- return WebhookWrapper.remove(this.client, {
77
- webhookId: this._id,
78
- siteId: this.site,
79
- });
80
- }
81
- }
82
- exports.WebhookWrapper = WebhookWrapper;
@@ -1,155 +0,0 @@
1
- import { Client, PaginatedData, requireArgs } from "../core";
2
-
3
- /**************************************************************
4
- * Interfaces
5
- **************************************************************/
6
- export interface IUser {
7
- emailVerified: boolean;
8
- lastUpdated?: string;
9
- createdOn: string;
10
- _id: string;
11
- data: any;
12
- }
13
-
14
- export interface IAccessGroup {
15
- _id: string;
16
- name: string;
17
- shortId: string;
18
- slug: string;
19
- createdOn: string;
20
- }
21
-
22
- export interface IUserDelete {
23
- deleted: number;
24
- }
25
-
26
- /**************************************************************
27
- * Types
28
- **************************************************************/
29
- export type PaginatedUsers = PaginatedData & {
30
- users: IUser[];
31
- };
32
-
33
- export type PaginatedAccessGroups = PaginatedData & {
34
- accessGroups: IAccessGroup[];
35
- };
36
-
37
- export type UserIdParam = { siteId: string; userId: string };
38
-
39
- /**************************************************************
40
- * Functions
41
- **************************************************************/
42
-
43
- /**
44
- * Get a list of Users
45
- * @param client The Webflow client
46
- * @param params The params for the request
47
- * @param params.siteId The site ID
48
- * @param params.limit The number of items to return (optional)
49
- * @param params.offset The number of items to skip (optional)
50
- * @returns A list of Users
51
- */
52
- export function list(
53
- client: Client,
54
- { siteId, limit, offset }: { siteId: string; limit?: number; offset?: number }
55
- ) {
56
- requireArgs({ siteId });
57
- const params = { limit, offset };
58
- const path = `/sites/${siteId}/users`;
59
- return client.get<PaginatedUsers>(path, { params });
60
- }
61
-
62
- /**
63
- * Get a single User
64
- * @param client The Webflow client
65
- * @param params The params for the request
66
- * @param params.siteId The site ID
67
- * @param params.userId The user ID
68
- * @returns A single User
69
- */
70
- export function getOne(
71
- client: Client,
72
- { siteId, userId }: { siteId: string; userId: string }
73
- ) {
74
- requireArgs({ siteId, userId });
75
- const path = `/sites/${siteId}/users/${userId}`;
76
- return client.get<IUser>(path);
77
- }
78
-
79
- /**
80
- * Update a User
81
- * @param client The Webflow client
82
- * @param params The params for the request
83
- * @param params.siteId The site ID
84
- * @param params.userId The user ID
85
- * @param params.data The data to update
86
- * @returns The updated User
87
- */
88
- export function update(
89
- client: Client,
90
- {
91
- siteId,
92
- userId,
93
- ...data
94
- }: {
95
- siteId: string;
96
- userId: string;
97
- }
98
- ) {
99
- requireArgs({ siteId, userId });
100
- const path = `/sites/${siteId}/users/${userId}`;
101
- return client.patch<IUser>(path, data);
102
- }
103
-
104
- /**
105
- * Invite a User to a site
106
- * @param client The Webflow client
107
- * @param params The params for the request
108
- * @param params.siteId The site ID
109
- * @param params.email The email address of the user to invite
110
- * @returns The newly created User
111
- */
112
- export async function invite(
113
- client: Client,
114
- { siteId, email }: { siteId: string; email: string }
115
- ) {
116
- requireArgs({ siteId, email });
117
- const path = `/sites/${siteId}/users/invite`;
118
- return client.post<IUser>(path, { email });
119
- }
120
-
121
- /**
122
- * Remove a User
123
- * @param client The Webflow client
124
- * @param params The params for the request
125
- * @param params.siteId The site ID
126
- * @param params.userId The user ID
127
- * @returns The result of the remove
128
- */
129
- export function remove(
130
- client: Client,
131
- { siteId, userId }: { siteId: string; userId: string }
132
- ) {
133
- requireArgs({ siteId, userId });
134
- const path = `/sites/${siteId}/users/${userId}`;
135
- return client.delete<IUserDelete>(path);
136
- }
137
-
138
- /**
139
- * Get a list of Access Groups
140
- * @param client The Webflow client
141
- * @param params The params for the request
142
- * @param params.siteId The Site ID
143
- * @param params.limit The number of items to return (optional)
144
- * @param params.offset The number of items to skip (optional)
145
- * @returns A list of Access Groups
146
- */
147
- export function accessGroups(
148
- client: Client,
149
- { siteId, limit, offset }: { siteId: string; limit?: number; offset?: number }
150
- ) {
151
- requireArgs({ siteId });
152
- const params = { limit, offset };
153
- const path = `/sites/${siteId}/users/accessgroups`;
154
- return client.get<PaginatedAccessGroups>(path, { params });
155
- }
@@ -1,82 +0,0 @@
1
- import { Axios } from "axios";
2
- import { DEFAULT_HOST, USER_AGENT, Options, RequestError } from "../core";
3
-
4
- /**************************************************************
5
- * Types
6
- **************************************************************/
7
- export type QueryString = Record<string, any>;
8
- export type PaginationFilter = { limit?: number; offset?: number };
9
-
10
- /**************************************************************
11
- * Interfaces
12
- ************************************************************* */
13
- export interface PaginatedData {
14
- count: number;
15
- limit: number;
16
- offset: number;
17
- total: number;
18
- }
19
-
20
- /**************************************************************
21
- * Functions
22
- **************************************************************/
23
-
24
- /**
25
- * Transforms JSON response to an object
26
- * if the response is a Webflow error, it will throw an error
27
- * @param data JSON response
28
- * @returns response object
29
- */
30
- function transformResponse(data: any = {}) {
31
- // parse json if string
32
- if (String(data) === data) data = JSON.parse(data);
33
-
34
- // throw an error if Webflow returns an error obejct
35
- if (data.err) throw new RequestError(data);
36
- return data;
37
- }
38
-
39
- /**
40
- * Transforms POST/PUT/PATCH request data to JSON
41
- * @param data A JavaScript object
42
- * @returns JSON string
43
- */
44
- function transformRequest(data: any = {}) {
45
- return JSON.stringify(data);
46
- }
47
-
48
- /**************************************************************
49
- * Classes
50
- **************************************************************/
51
- export class Client extends Axios {
52
- constructor({
53
- host = DEFAULT_HOST,
54
- headers = {},
55
- version,
56
- token,
57
- }: Options = {}) {
58
- super({
59
- transformRequest: [transformRequest],
60
- transformResponse: [transformResponse],
61
- baseURL: `https://api.${host}/`,
62
- headers: {
63
- "Content-Type": "application/json",
64
- "User-Agent": USER_AGENT,
65
- "Accept-Version": version,
66
- ...headers,
67
- },
68
- });
69
-
70
- if (token) this.token = token;
71
- }
72
-
73
- // set the Authorization header
74
- set token(value: string) {
75
- this.defaults.headers["Authorization"] = `Bearer ${value}`;
76
- }
77
-
78
- // clear the Authorization header
79
- clearToken() {
80
- delete this.defaults.headers["Authorization"];
81
- }
82
- }
@@ -1,9 +0,0 @@
1
- export const DEFAULT_HOST = "webflow.com";
2
- export const USER_AGENT = "Webflow Javascript SDK / 1.0";
3
-
4
- export interface Options {
5
- host?: string;
6
- token?: string;
7
- version?: string;
8
- headers?: Record<string, string>;
9
- }