webflow-api 1.1.2 → 1.2.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 (70) hide show
  1. package/dist/api/collection.d.ts +85 -24
  2. package/dist/api/collection.js +88 -29
  3. package/dist/api/index.d.ts +7 -7
  4. package/dist/api/index.js +9 -19
  5. package/dist/api/item.d.ts +141 -107
  6. package/dist/api/item.js +145 -125
  7. package/dist/api/meta.d.ts +16 -14
  8. package/dist/api/meta.js +20 -19
  9. package/dist/api/oauth.d.ts +38 -36
  10. package/dist/api/oauth.js +59 -59
  11. package/dist/api/site.d.ts +118 -43
  12. package/dist/api/site.js +131 -53
  13. package/dist/{wrapper/membership.d.ts → api/user.d.ts} +59 -47
  14. package/dist/api/user.js +103 -0
  15. package/dist/api/webhook.d.ts +77 -55
  16. package/dist/api/webhook.js +74 -61
  17. package/dist/core/error.d.ts +2 -0
  18. package/dist/core/error.js +8 -1
  19. package/dist/core/index.d.ts +2 -2
  20. package/dist/core/index.js +2 -2
  21. package/dist/core/response.d.ts +32 -0
  22. package/dist/core/response.js +26 -0
  23. package/dist/{webflow.d.ts → core/webflow.d.ts} +56 -59
  24. package/dist/{webflow.js → core/webflow.js} +101 -68
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +2 -2
  27. package/package.json +2 -4
  28. package/src/api/collection.ts +102 -35
  29. package/src/api/index.ts +7 -7
  30. package/src/api/item.ts +207 -176
  31. package/src/api/meta.ts +19 -18
  32. package/src/api/oauth.ts +62 -74
  33. package/src/api/site.ts +158 -55
  34. package/src/api/user.ts +152 -0
  35. package/src/api/webhook.ts +97 -80
  36. package/src/core/error.ts +8 -0
  37. package/src/core/index.ts +2 -2
  38. package/src/core/response.ts +50 -0
  39. package/src/{webflow.ts → core/webflow.ts} +131 -145
  40. package/src/index.ts +1 -1
  41. package/yarn.lock +0 -5
  42. package/dist/api/membership.d.ts +0 -114
  43. package/dist/api/membership.js +0 -96
  44. package/dist/core/client.d.ts +0 -27
  45. package/dist/core/client.js +0 -60
  46. package/dist/core/options.d.ts +0 -8
  47. package/dist/core/options.js +0 -5
  48. package/dist/wrapper/collection.d.ts +0 -85
  49. package/dist/wrapper/collection.js +0 -94
  50. package/dist/wrapper/index.d.ts +0 -6
  51. package/dist/wrapper/index.js +0 -22
  52. package/dist/wrapper/item.d.ts +0 -140
  53. package/dist/wrapper/item.js +0 -153
  54. package/dist/wrapper/membership.js +0 -123
  55. package/dist/wrapper/response.d.ts +0 -16
  56. package/dist/wrapper/response.js +0 -17
  57. package/dist/wrapper/site.d.ts +0 -168
  58. package/dist/wrapper/site.js +0 -191
  59. package/dist/wrapper/webhook.d.ts +0 -78
  60. package/dist/wrapper/webhook.js +0 -82
  61. package/src/api/membership.ts +0 -155
  62. package/src/core/client.ts +0 -82
  63. package/src/core/options.ts +0 -9
  64. package/src/wrapper/collection.ts +0 -115
  65. package/src/wrapper/index.ts +0 -6
  66. package/src/wrapper/item.ts +0 -218
  67. package/src/wrapper/membership.ts +0 -163
  68. package/src/wrapper/response.ts +0 -25
  69. package/src/wrapper/site.ts +0 -228
  70. package/src/wrapper/webhook.ts +0 -116
package/src/api/site.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { Client, QueryString, requireArgs } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { Webhook, Collection, WebhookFilter } from ".";
3
+ import { requireArgs, WebflowRecord } from "../core";
2
4
 
3
5
  /**************************************************************
4
6
  * Interfaces
@@ -24,63 +26,164 @@ export interface IPublishSite {
24
26
  }
25
27
 
26
28
  /**************************************************************
27
- * Functions
29
+ * Class
28
30
  **************************************************************/
29
31
 
30
- /**
31
- * Get a list of Sites
32
- * @param client The Webflow client
33
- * @param params The query string parameters (optional)
34
- * @returns
35
- */
36
- export function list(client: Client, params?: QueryString) {
37
- const path = "/sites";
38
- return client.get<ISite[]>(path, { params });
39
- }
32
+ export class Site extends WebflowRecord<ISite> implements ISite {
33
+ lastPublished: string;
34
+ previewUrl: string;
35
+ createdOn: string;
36
+ shortName: string;
37
+ timezone: string;
38
+ database: string;
39
+ name: string;
40
+ _id: string;
40
41
 
41
- /**
42
- * Get a single Site
43
- * @param client The Webflow client
44
- * @param params The params for the request
45
- * @param params.siteId The site ID
46
- * @param params.params The query string parameters (optional)
47
- * @returns A single Site
48
- */
49
- export function getOne(
50
- client: Client,
51
- { siteId, params }: { siteId: string; params?: QueryString }
52
- ) {
53
- requireArgs({ siteId });
54
- const path = `/sites/${siteId}`;
55
- return client.get<ISite>(path, { params });
56
- }
42
+ /**
43
+ * Get a list of Sites
44
+ * @param client The Axios client instance
45
+ * @returns a list of Sites
46
+ */
47
+ static list(client: AxiosInstance) {
48
+ const path = "/sites";
49
+ return client.get<ISite[]>(path);
50
+ }
57
51
 
58
- /**
59
- * Publish a site
60
- * @param client The Webflow client
61
- * @param params The params for the request
62
- * @param params.siteId The site ID
63
- * @param params.domains The domains to publish to
64
- * @returns The publish result
65
- */
66
- export function publish(
67
- client: Client,
68
- { siteId, domains }: { siteId: string; domains: string[] }
69
- ) {
70
- requireArgs({ siteId, domains });
71
- const path = `/sites/${siteId}/publish`;
72
- return client.post<IPublishSite>(path, { domains });
73
- }
52
+ /**
53
+ * Get a single Site
54
+ * @param params The params for the request
55
+ * @param params.siteId The site ID
56
+ * @param params.params The query string parameters (optional)
57
+ * @param client The Axios client instance
58
+ * @returns A single Site
59
+ */
60
+ static getOne({ siteId }: { siteId: string }, client: AxiosInstance) {
61
+ requireArgs({ siteId });
62
+ const path = `/sites/${siteId}`;
63
+ return client.get<ISite>(path);
64
+ }
65
+
66
+ /**
67
+ * Publish a site
68
+ * @param params The params for the request
69
+ * @param params.siteId The site ID
70
+ * @param params.domains The domains to publish to
71
+ * @param client The Axios client instance
72
+ * @returns The publish result
73
+ */
74
+ static publish({ siteId, domains }: { siteId: string; domains: string[] }, client: AxiosInstance) {
75
+ requireArgs({ siteId, domains });
76
+ const path = `/sites/${siteId}/publish`;
77
+ return client.post<IPublishSite>(path, { domains });
78
+ }
79
+
80
+ /**
81
+ * Get a list of domains for a site
82
+ * @param params The params for the request
83
+ * @param params.siteId The site ID
84
+ * @param client The Axios client instance
85
+ * @returns A list of domains
86
+ */
87
+ static domains({ siteId }: { siteId: string }, client: AxiosInstance) {
88
+ requireArgs({ siteId });
89
+ const path = `/sites/${siteId}/domains`;
90
+ return client.get<IDomain[]>(path);
91
+ }
92
+
93
+ /**************************************************************
94
+ * Instance Methods
95
+ **************************************************************/
96
+
97
+ /**
98
+ * Get a list of domains for a site
99
+ * @returns A list of domains
100
+ */
101
+ async domains() {
102
+ const res = await Site.domains({ siteId: this._id }, this.client);
103
+ return res.data;
104
+ }
105
+
106
+ /**
107
+ * Publish a site
108
+ * @param domains The domains to publish to
109
+ * @returns The publish result
110
+ */
111
+ async publishSite(domains: string[]) {
112
+ const res = await Site.publish({ siteId: this._id, domains }, this.client);
113
+ return res.data;
114
+ }
115
+
116
+ /**
117
+ * Get a single Collection
118
+ * @param params The params for the request
119
+ * @param params.collectionId The collection ID
120
+ * @returns A single Collection
121
+ */
122
+ async collection({ collectionId }: { collectionId: string }) {
123
+ const res = await Collection.getOne({ collectionId }, this.client);
124
+ return new Collection(this.client, res);
125
+ }
126
+
127
+ /**
128
+ * Get a list of Collections
129
+ * @returns A list of Collections
130
+ */
131
+ async collections() {
132
+ const res = await Collection.list({ siteId: this._id }, this.client);
133
+ return res.data.map((data) => new Collection(this.client, { ...res, data }));
134
+ }
135
+
136
+ /**
137
+ * Get a single Webhook
138
+ * @param params The params for the request
139
+ * @param params.webhookId The webhook ID
140
+ * @returns A single Webhook
141
+ */
142
+ async webhook({ webhookId }: { webhookId: string }) {
143
+ const res = await Webhook.getOne({ siteId: this._id, webhookId }, this.client);
144
+ return new Webhook(this.client, res);
145
+ }
146
+
147
+ /**
148
+ * Get a list of Webhooks
149
+ * @returns A list of Webhooks
150
+ */
151
+ async webhooks() {
152
+ const res = await Webhook.list({ siteId: this._id }, this.client);
153
+ return res.data.map((data) => new Webhook(this.client, { ...res, data }));
154
+ }
155
+
156
+ /**
157
+ * Remove a Webhook
158
+ * @param params The query string parameters (optional)
159
+ * @param params.webhookId The Webhook ID
160
+ * @returns The result of the removal
161
+ */
162
+ async removeWebhook({ webhookId }: { webhookId: string }) {
163
+ const res = await Webhook.remove({ siteId: this._id, webhookId }, this.client);
164
+ return res.data;
165
+ }
74
166
 
75
- /**
76
- * Get a list of domains for a site
77
- * @param client The Webflow client
78
- * @param params The params for the request
79
- * @param params.siteId The site ID
80
- * @returns A list of domains
81
- */
82
- export function domains(client: Client, { siteId }: { siteId: string }) {
83
- requireArgs({ siteId });
84
- const path = `/sites/${siteId}/domains`;
85
- return client.get<IDomain[]>(path);
167
+ /**
168
+ * Create a new Webhook
169
+ * @param params The params for the request
170
+ * @param params.url The URL to send the webhook to
171
+ * @param params.triggerType The event to trigger the webhook
172
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
173
+ * @returns The created webhook
174
+ */
175
+ async createWebhook({
176
+ triggerType,
177
+ filter,
178
+ url,
179
+ }: {
180
+ url: string;
181
+ siteId: string;
182
+ triggerType: string;
183
+ filter?: WebhookFilter;
184
+ }) {
185
+ const _params = { url, siteId: this._id, triggerType, filter };
186
+ const res = await Webhook.create(_params, this.client);
187
+ return new Webhook(this.client, res);
188
+ }
86
189
  }
@@ -0,0 +1,152 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { PaginatedData, requireArgs, WebflowRecord } from "../core";
3
+
4
+ /**************************************************************
5
+ * Interfaces
6
+ **************************************************************/
7
+ export interface IUser {
8
+ emailVerified: boolean;
9
+ lastUpdated?: string;
10
+ createdOn: string;
11
+ _id: string;
12
+ data: any;
13
+ }
14
+
15
+ export interface IUserDelete {
16
+ deleted: number;
17
+ }
18
+
19
+ /**************************************************************
20
+ * Types
21
+ **************************************************************/
22
+ export type PaginatedUsers = PaginatedData & {
23
+ users: IUser[];
24
+ };
25
+
26
+ export type UserIdParam = { siteId: string; userId: string };
27
+
28
+ /**************************************************************
29
+ * Class
30
+ **************************************************************/
31
+
32
+ export class User extends WebflowRecord<IUser> implements IUser {
33
+ emailVerified: boolean;
34
+ lastUpdated?: string;
35
+ createdOn: string;
36
+ siteId: string;
37
+ _id: string;
38
+ data: any;
39
+
40
+ /**************************************************************
41
+ * Static Methods
42
+ **************************************************************/
43
+
44
+ /**
45
+ * Get a list of Users
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
+ * @param client The Axios client instance
51
+ * @returns A list of Users
52
+ */
53
+ static list({ siteId, limit, offset }: { siteId: string; limit?: number; offset?: number }, client: AxiosInstance) {
54
+ requireArgs({ siteId });
55
+ const params = { limit, offset };
56
+ const path = `/sites/${siteId}/users`;
57
+ return client.get<PaginatedUsers>(path, { params });
58
+ }
59
+
60
+ /**
61
+ * Get a single User
62
+ * @param params The params for the request
63
+ * @param params.siteId The site ID
64
+ * @param params.userId The user ID
65
+ * @param client The Axios client instance
66
+ * @returns A single User
67
+ */
68
+ static getOne({ siteId, userId }: { siteId: string; userId: string }, client: AxiosInstance) {
69
+ requireArgs({ siteId, userId });
70
+ const path = `/sites/${siteId}/users/${userId}`;
71
+ return client.get<IUser>(path);
72
+ }
73
+
74
+ /**
75
+ * Update a User
76
+ * @param params The params for the request
77
+ * @param params.siteId The site ID
78
+ * @param params.userId The user ID
79
+ * @param params.data The data to update
80
+ * @param client The Axios client instance
81
+ * @returns The updated User
82
+ */
83
+ static update(
84
+ {
85
+ siteId,
86
+ userId,
87
+ data,
88
+ }: {
89
+ data: object;
90
+ siteId: string;
91
+ userId: string;
92
+ },
93
+ client: AxiosInstance
94
+ ) {
95
+ requireArgs({ siteId, userId });
96
+ const path = `/sites/${siteId}/users/${userId}`;
97
+ return client.patch<IUser>(path, data);
98
+ }
99
+
100
+ /**
101
+ * Invite a User to a site
102
+ * @param params The params for the request
103
+ * @param params.siteId The site ID
104
+ * @param params.email The email address of the user to invite
105
+ * @param client The Axios client instance
106
+ * @returns The newly created User
107
+ */
108
+ static async invite({ siteId, email }: { siteId: string; email: string }, client: AxiosInstance) {
109
+ requireArgs({ siteId, email });
110
+ const path = `/sites/${siteId}/users/invite`;
111
+ return client.post<IUser>(path, { email });
112
+ }
113
+
114
+ /**
115
+ * Remove a User
116
+ * @param params The params for the request
117
+ * @param params.siteId The site ID
118
+ * @param params.userId The user ID
119
+ * @param client The Axios client instance
120
+ * @returns The result of the remove
121
+ */
122
+ static remove({ siteId, userId }: { siteId: string; userId: string }, client: AxiosInstance) {
123
+ requireArgs({ siteId, userId });
124
+ const path = `/sites/${siteId}/users/${userId}`;
125
+ return client.delete<IUserDelete>(path);
126
+ }
127
+
128
+ /**************************************************************
129
+ * Instance Methods
130
+ **************************************************************/
131
+
132
+ /**
133
+ * Update a User
134
+ * @param data The data to update
135
+ * @returns The updated User
136
+ */
137
+ async update(data: any) {
138
+ const params = { siteId: this.siteId, userId: this._id, data };
139
+ const res = await User.update(params, this.client);
140
+ return new User(this.client, res);
141
+ }
142
+
143
+ /**
144
+ * Remove a User
145
+ * @returns The result of the remove
146
+ */
147
+ async remove() {
148
+ const params = { siteId: this.siteId, userId: this._id };
149
+ const res = await User.remove(params, this.client);
150
+ return res.data;
151
+ }
152
+ }
@@ -1,4 +1,5 @@
1
- import { Client, QueryString, requireArgs } from "../core";
1
+ import { AxiosInstance } from "axios";
2
+ import { requireArgs, WebflowRecord } from "../core";
2
3
 
3
4
  /**************************************************************
4
5
  * Types
@@ -14,7 +15,7 @@ export type TriggerType =
14
15
  | "collection_item_deleted"
15
16
  | string;
16
17
 
17
- export type Filter = {
18
+ export type WebhookFilter = {
18
19
  name: string;
19
20
  };
20
21
 
@@ -38,88 +39,104 @@ export interface IRemoveResult {
38
39
  }
39
40
 
40
41
  /**************************************************************
41
- * Functions
42
+ * Class
42
43
  **************************************************************/
44
+ export class Webhook extends WebflowRecord<IWebhook> implements IWebhook {
45
+ filter?: { name: string };
46
+ triggerType: string;
47
+ triggerId: string;
48
+ createdOn: string;
49
+ lastUsed?: string;
50
+ site: string;
51
+ _id: string;
43
52
 
44
- /**
45
- * Get a list of Webhooks
46
- * @param client The Webflow client
47
- * @param params1 The params for the request
48
- * @param params1.siteId The site ID
49
- * @param params The query string parameters (optional)
50
- * @returns A list of Webhooks
51
- */
52
- export function list(
53
- client: Client,
54
- { siteId }: { siteId: string },
55
- params?: QueryString
56
- ) {
57
- requireArgs({ siteId });
58
- const path = `/sites/${siteId}/webhooks`;
59
- return client.get<IWebhook[]>(path, { params });
60
- }
53
+ /**************************************************************
54
+ * Static Methods
55
+ **************************************************************/
61
56
 
62
- /**
63
- * Get a single Webhook
64
- * @param client The Webflow client
65
- * @param params The params for the request
66
- * @param params.siteId The site ID
67
- * @param params.webhookId The webhook ID
68
- * @returns A single Webhook
69
- */
70
- export function getOne(
71
- client: Client,
72
- { siteId, webhookId }: { siteId: string; webhookId: string }
73
- ) {
74
- requireArgs({ siteId, webhookId });
75
- const path = `/sites/${siteId}/webhooks/${webhookId}`;
76
- return client.get<IWebhook>(path);
77
- }
57
+ /**
58
+ * Get a list of Webhooks
59
+ * @param params The params for the request
60
+ * @param params.siteId The site ID
61
+ * @param client The Axios client instance
62
+ * @returns A list of Webhooks
63
+ */
64
+ static list({ siteId }: { siteId: string }, client: AxiosInstance) {
65
+ requireArgs({ siteId });
66
+ const path = `/sites/${siteId}/webhooks`;
67
+ return client.get<IWebhook[]>(path);
68
+ }
78
69
 
79
- /**
80
- * Create a new Webhook
81
- * @param client The Webflow client
82
- * @param params The params for the request
83
- * @param params.siteId The site ID
84
- * @param params.url The URL to send the webhook to
85
- * @param params.triggerType The event to trigger the webhook
86
- * @param params.filter The filter to apply to the webhook (optional: form_submission only)
87
- * @param params.params The query string parameters (optional)
88
- * @returns The created webhook
89
- */
90
- export function create(
91
- client: Client,
92
- {
93
- triggerType,
94
- siteId,
95
- filter,
96
- url,
97
- }: {
98
- url: string;
99
- siteId: string;
100
- filter?: Filter;
101
- triggerType: TriggerType;
70
+ /**
71
+ * Get a single Webhook
72
+ * @param params The params for the request
73
+ * @param params.siteId The site ID
74
+ * @param params.webhookId The webhook ID
75
+ * @param client The Axios client instance
76
+ * @returns A single Webhook
77
+ */
78
+ static getOne({ siteId, webhookId }: { siteId: string; webhookId: string }, client: AxiosInstance) {
79
+ requireArgs({ siteId, webhookId });
80
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
81
+ return client.get<IWebhook>(path);
82
+ }
83
+
84
+ /**
85
+ * Create a new Webhook
86
+ * @param params The params for the request
87
+ * @param params.siteId The site ID
88
+ * @param params.url The URL to send the webhook to
89
+ * @param params.triggerType The event to trigger the webhook
90
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
91
+ * @param params.params The query string parameters (optional)
92
+ * @param client The Axios client instance
93
+ * @returns The created webhook
94
+ */
95
+ static create(
96
+ {
97
+ triggerType,
98
+ siteId,
99
+ filter,
100
+ url,
101
+ }: {
102
+ url: string;
103
+ siteId: string;
104
+ filter?: WebhookFilter;
105
+ triggerType: TriggerType;
106
+ },
107
+ client: AxiosInstance
108
+ ) {
109
+ requireArgs({ siteId, triggerType, url });
110
+ const path = `/sites/${siteId}/webhooks`;
111
+ const data = { triggerType, url, filter };
112
+ return client.post<IWebhook>(path, data);
102
113
  }
103
- ) {
104
- requireArgs({ siteId, triggerType, url });
105
- const path = `/sites/${siteId}/webhooks`;
106
- const data = { triggerType, url, filter };
107
- return client.post<IWebhook>(path, data);
108
- }
109
114
 
110
- /**
111
- * Remove a Webhook
112
- * @param client The Webflow client
113
- * @param params The query string parameters (optional)
114
- * @param params.webhookId The Webhook ID
115
- * @param params.siteId The Site ID
116
- * @returns The result of the removal
117
- */
118
- export function remove(
119
- client: Client,
120
- { siteId, webhookId }: { siteId: string; webhookId: string }
121
- ) {
122
- requireArgs({ siteId, webhookId });
123
- const path = `/sites/${siteId}/webhooks/${webhookId}`;
124
- return client.delete<IRemoveResult>(path);
115
+ /**
116
+ * Remove a Webhook
117
+ * @param params The query string parameters (optional)
118
+ * @param params.webhookId The Webhook ID
119
+ * @param params.siteId The Site ID
120
+ * @param client The Axios client instance
121
+ * @returns The result of the removal
122
+ */
123
+ static remove({ siteId, webhookId }: { siteId: string; webhookId: string }, client: AxiosInstance) {
124
+ requireArgs({ siteId, webhookId });
125
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
126
+ return client.delete<IRemoveResult>(path);
127
+ }
128
+
129
+ /**************************************************************
130
+ * Instance Methods
131
+ **************************************************************/
132
+
133
+ /**
134
+ * Remove a Webhook
135
+ * @returns The result of the removal
136
+ */
137
+ async remove() {
138
+ const params = { siteId: this.site, webhookId: this._id };
139
+ const res = await Webhook.remove(params, this.client);
140
+ return res.data;
141
+ }
125
142
  }
package/src/core/error.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { AxiosResponse } from "axios";
2
+
1
3
  export interface IRequestError {
2
4
  msg: string;
3
5
  code: number;
@@ -30,3 +32,9 @@ export function requireArgs(args: object) {
30
32
  if (!args[key]) throw new ArgumentError(key);
31
33
  }
32
34
  }
35
+
36
+ // throw an error if Webflow error
37
+ export function ErrorInterceptor(res: AxiosResponse) {
38
+ if (res.data.err) throw new RequestError(res.data);
39
+ return res;
40
+ }
package/src/core/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./client";
2
1
  export * from "./error";
3
- export * from "./options";
2
+ export * from "./response";
3
+ export * from "./webflow";
@@ -0,0 +1,50 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+
3
+ /**************************************************************
4
+ * Types
5
+ **************************************************************/
6
+ export type PaginationFilter = { limit?: number; offset?: number };
7
+
8
+ export type WebflowHeaders = Record<string, any>;
9
+
10
+ /**************************************************************
11
+ * Interfaces
12
+ ************************************************************* */
13
+ export interface PaginatedData {
14
+ count: number;
15
+ limit: number;
16
+ offset: number;
17
+ total: number;
18
+ }
19
+
20
+ export class MetaResponse<T> {
21
+ rateLimit: {
22
+ limit: number;
23
+ remaining: number;
24
+ };
25
+
26
+ constructor(public response: AxiosResponse<T>) {
27
+ this.rateLimit = {
28
+ limit: parseInt(response.headers["x-ratelimit-limit"], 10),
29
+ remaining: parseInt(response.headers["x-ratelimit-remaining"], 10),
30
+ };
31
+ }
32
+ }
33
+
34
+ export class WebflowRecord<T> {
35
+ response: AxiosResponse<T>;
36
+ _meta: MetaResponse<T>;
37
+ client: AxiosInstance;
38
+
39
+ constructor(client: AxiosInstance, response: AxiosResponse<any>, record?: T, ...args: any[]) {
40
+ Object.assign(this, record || response.data, ...args); // Copy the record data
41
+
42
+ // dynamically add client and response to object
43
+ // without serializing during toString()
44
+ Object.defineProperties(this, {
45
+ client: { get: () => client },
46
+ response: { get: () => response },
47
+ _meta: { get: () => new MetaResponse(response) }, // legacy support
48
+ });
49
+ }
50
+ }