webflow-api 1.3.0 → 1.3.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 (54) hide show
  1. package/dist/api/collection.d.ts +112 -0
  2. package/dist/api/collection.js +94 -0
  3. package/dist/api/index.d.ts +7 -0
  4. package/dist/api/index.js +23 -0
  5. package/dist/api/item.d.ts +177 -0
  6. package/dist/api/item.js +151 -0
  7. package/dist/api/meta.d.ts +53 -0
  8. package/dist/api/meta.js +25 -0
  9. package/dist/api/oauth.d.ts +71 -0
  10. package/dist/api/oauth.js +71 -0
  11. package/dist/api/site.d.ts +140 -0
  12. package/dist/api/site.js +137 -0
  13. package/dist/api/user.d.ts +143 -0
  14. package/dist/api/user.js +119 -0
  15. package/dist/api/webhook.d.ts +102 -0
  16. package/dist/api/webhook.js +80 -0
  17. package/dist/core/error.d.ts +21 -0
  18. package/dist/core/error.js +30 -0
  19. package/dist/core/index.d.ts +3 -0
  20. package/dist/core/index.js +19 -0
  21. package/dist/core/response.d.ts +32 -0
  22. package/dist/core/response.js +26 -0
  23. package/dist/core/webflow.d.ts +390 -0
  24. package/dist/core/webflow.js +518 -0
  25. package/dist/index.d.ts +2 -0
  26. package/package.json +7 -1
  27. package/yarn.lock +2840 -0
  28. package/.eslintrc +0 -31
  29. package/.github/workflows/code-quality.yml +0 -102
  30. package/.github/workflows/npm-publish.yml +0 -21
  31. package/.github/workflows/semgrep.yml +0 -24
  32. package/.prettierignore +0 -5
  33. package/.prettierrc +0 -6
  34. package/jest.config.js +0 -17
  35. package/tests/api/collection.test.ts +0 -147
  36. package/tests/api/item.test.ts +0 -180
  37. package/tests/api/meta.test.ts +0 -38
  38. package/tests/api/oauth.test.ts +0 -44
  39. package/tests/api/site.test.ts +0 -202
  40. package/tests/api/user.test.ts +0 -139
  41. package/tests/api/webhook.test.ts +0 -82
  42. package/tests/core/error.test.ts +0 -19
  43. package/tests/core/response.test.ts +0 -36
  44. package/tests/core/webflow.test.ts +0 -540
  45. package/tests/fixtures/collection.fixture.ts +0 -374
  46. package/tests/fixtures/index.ts +0 -7
  47. package/tests/fixtures/item.fixture.ts +0 -193
  48. package/tests/fixtures/meta.fixture.ts +0 -34
  49. package/tests/fixtures/oauth.fixture.ts +0 -38
  50. package/tests/fixtures/site.fixture.ts +0 -78
  51. package/tests/fixtures/user.fixture.ts +0 -175
  52. package/tests/fixtures/webhook.fixture.ts +0 -69
  53. package/tsconfig.eslint.json +0 -7
  54. package/tsconfig.json +0 -14
@@ -0,0 +1,71 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { SupportedScope } from "../core";
3
+ /**************************************************************
4
+ * Interfaces
5
+ **************************************************************/
6
+ export interface IAuthorizeUrlParams {
7
+ state?: string;
8
+ scope?: string;
9
+ scopes?: SupportedScope[];
10
+ client_id: string;
11
+ redirect_uri?: string;
12
+ response_type?: string;
13
+ }
14
+ export interface IRevokeTokenParams {
15
+ client_secret: string;
16
+ access_token: string;
17
+ client_id: string;
18
+ }
19
+ export interface IAccessTokenParams {
20
+ code: string;
21
+ client_id: string;
22
+ grant_type?: string;
23
+ client_secret: string;
24
+ redirect_uri?: string;
25
+ }
26
+ export interface IAccessToken {
27
+ token_type: string;
28
+ access_token: string;
29
+ }
30
+ export interface IRevokeToken {
31
+ didRevoke: boolean;
32
+ }
33
+ /**************************************************************
34
+ * Class
35
+ **************************************************************/
36
+ export declare class OAuth {
37
+ /**
38
+ * Get the URL to authorize a user
39
+ * @param params The params for the request
40
+ * @param params.client_id The OAuth client ID
41
+ * @param params.scope The scope (optional)
42
+ * @param params.state The state (optional)
43
+ * @param params.redirect_uri The redirect URI (optional)
44
+ * @param params.response_type The response type (default: code)
45
+ * @param client The Axios client instance
46
+ * @returns The URL to authorize a user
47
+ */
48
+ static authorizeUrl({ response_type, redirect_uri, client_id, state, scope, scopes }: IAuthorizeUrlParams, client: AxiosInstance): string;
49
+ /**
50
+ * Get an access token
51
+ * @param params The params for the request
52
+ * @param params.code The OAuth code
53
+ * @param params.client_id The OAuth client ID
54
+ * @param params.client_secret The OAuth client secret
55
+ * @param params.redirect_uri The redirect URI (optional)
56
+ * @param params.grant_type The grant type (default: "authorization_code")
57
+ * @param client The Axios client instance
58
+ * @returns An access token
59
+ */
60
+ static accessToken({ grant_type, client_secret, redirect_uri, client_id, code, }: IAccessTokenParams, client: AxiosInstance): Promise<import("axios").AxiosResponse<IAccessToken, any>>;
61
+ /**
62
+ * Revoke an access token
63
+ * @param params The params for the request
64
+ * @param params.client_id The OAuth client ID
65
+ * @param params.client_secret The OAuth client secret
66
+ * @param params.access_token The OAuth access token
67
+ * @param client The Axios client instance
68
+ * @returns The result of the revoke
69
+ */
70
+ static revokeToken({ client_secret, access_token, client_id }: IRevokeTokenParams, client: AxiosInstance): Promise<import("axios").AxiosResponse<IRevokeToken, any>>;
71
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuth = void 0;
4
+ const core_1 = require("../core");
5
+ /**************************************************************
6
+ * Class
7
+ **************************************************************/
8
+ class OAuth {
9
+ /**
10
+ * Get the URL to authorize a user
11
+ * @param params The params for the request
12
+ * @param params.client_id The OAuth client ID
13
+ * @param params.scope The scope (optional)
14
+ * @param params.state The state (optional)
15
+ * @param params.redirect_uri The redirect URI (optional)
16
+ * @param params.response_type The response type (default: code)
17
+ * @param client The Axios client instance
18
+ * @returns The URL to authorize a user
19
+ */
20
+ static authorizeUrl({ response_type = "code", redirect_uri, client_id, state, scope, scopes }, client) {
21
+ (0, core_1.requireArgs)({ client_id });
22
+ if (scope && scopes) {
23
+ throw new Error("Please provide either 'scope' or 'scopes', but not both.");
24
+ }
25
+ const params = { response_type, client_id };
26
+ if (redirect_uri)
27
+ params["redirect_uri"] = redirect_uri;
28
+ if (state)
29
+ params["state"] = state;
30
+ if (scope)
31
+ params["scope"] = scope;
32
+ if (scopes && scopes.length > 0)
33
+ params["scope"] = scopes.join("+");
34
+ const url = "/oauth/authorize";
35
+ const baseURL = client.defaults.baseURL.replace("api.", "");
36
+ return client.getUri({ baseURL, url, method: "GET", params });
37
+ }
38
+ /**
39
+ * Get an access token
40
+ * @param params The params for the request
41
+ * @param params.code The OAuth code
42
+ * @param params.client_id The OAuth client ID
43
+ * @param params.client_secret The OAuth client secret
44
+ * @param params.redirect_uri The redirect URI (optional)
45
+ * @param params.grant_type The grant type (default: "authorization_code")
46
+ * @param client The Axios client instance
47
+ * @returns An access token
48
+ */
49
+ static accessToken({ grant_type = "authorization_code", client_secret, redirect_uri, client_id, code, }, client) {
50
+ (0, core_1.requireArgs)({ client_id, client_secret, code });
51
+ const path = "/oauth/access_token";
52
+ const data = { client_secret, redirect_uri, grant_type, client_id, code };
53
+ return client.post(path, data);
54
+ }
55
+ /**
56
+ * Revoke an access token
57
+ * @param params The params for the request
58
+ * @param params.client_id The OAuth client ID
59
+ * @param params.client_secret The OAuth client secret
60
+ * @param params.access_token The OAuth access token
61
+ * @param client The Axios client instance
62
+ * @returns The result of the revoke
63
+ */
64
+ static revokeToken({ client_secret, access_token, client_id }, client) {
65
+ (0, core_1.requireArgs)({ client_id, client_secret, access_token });
66
+ const path = "/oauth/revoke_authorization";
67
+ const data = { client_secret, access_token, client_id };
68
+ return client.post(path, data);
69
+ }
70
+ }
71
+ exports.OAuth = OAuth;
@@ -0,0 +1,140 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { Webhook, Collection, WebhookFilter } from ".";
3
+ import { WebflowRecord } from "../core";
4
+ /**************************************************************
5
+ * Interfaces
6
+ *************************************************************/
7
+ export interface IDomain {
8
+ _id: string;
9
+ name: string;
10
+ }
11
+ export interface ISite {
12
+ lastPublished: string;
13
+ previewUrl: string;
14
+ createdOn: string;
15
+ shortName: string;
16
+ timezone: string;
17
+ database: string;
18
+ name: string;
19
+ _id: string;
20
+ }
21
+ export interface IPublishSite {
22
+ queued: boolean;
23
+ }
24
+ /**************************************************************
25
+ * Class
26
+ **************************************************************/
27
+ export declare class Site extends WebflowRecord<ISite> implements ISite {
28
+ lastPublished: string;
29
+ previewUrl: string;
30
+ createdOn: string;
31
+ shortName: string;
32
+ timezone: string;
33
+ database: string;
34
+ name: string;
35
+ _id: string;
36
+ /**
37
+ * Get a list of Sites
38
+ * @param client The Axios client instance
39
+ * @returns a list of Sites
40
+ */
41
+ static list(client: AxiosInstance): Promise<import("axios").AxiosResponse<ISite[], any>>;
42
+ /**
43
+ * Get a single Site
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
+ * @param client The Axios client instance
48
+ * @returns A single Site
49
+ */
50
+ static getOne({ siteId }: {
51
+ siteId: string;
52
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<ISite, any>>;
53
+ /**
54
+ * Publish a site
55
+ * @param params The params for the request
56
+ * @param params.siteId The site ID
57
+ * @param params.domains The domains to publish to
58
+ * @param client The Axios client instance
59
+ * @returns The publish result
60
+ */
61
+ static publish({ siteId, domains }: {
62
+ siteId: string;
63
+ domains: string[];
64
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IPublishSite, any>>;
65
+ /**
66
+ * Get a list of domains for a site
67
+ * @param params The params for the request
68
+ * @param params.siteId The site ID
69
+ * @param client The Axios client instance
70
+ * @returns A list of domains
71
+ */
72
+ static domains({ siteId }: {
73
+ siteId: string;
74
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IDomain[], any>>;
75
+ /**************************************************************
76
+ * Instance Methods
77
+ **************************************************************/
78
+ /**
79
+ * Get a list of domains for a site
80
+ * @returns A list of domains
81
+ */
82
+ domains(): Promise<IDomain[]>;
83
+ /**
84
+ * Publish a site
85
+ * @param domains The domains to publish to
86
+ * @returns The publish result
87
+ */
88
+ publishSite(domains: string[]): Promise<IPublishSite>;
89
+ /**
90
+ * Get a single Collection
91
+ * @param params The params for the request
92
+ * @param params.collectionId The collection ID
93
+ * @returns A single Collection
94
+ */
95
+ collection({ collectionId }: {
96
+ collectionId: string;
97
+ }): Promise<Collection>;
98
+ /**
99
+ * Get a list of Collections
100
+ * @returns A list of Collections
101
+ */
102
+ collections(): Promise<Collection[]>;
103
+ /**
104
+ * Get a single Webhook
105
+ * @param params The params for the request
106
+ * @param params.webhookId The webhook ID
107
+ * @returns A single Webhook
108
+ */
109
+ webhook({ webhookId }: {
110
+ webhookId: string;
111
+ }): Promise<Webhook>;
112
+ /**
113
+ * Get a list of Webhooks
114
+ * @returns A list of Webhooks
115
+ */
116
+ webhooks(): Promise<Webhook[]>;
117
+ /**
118
+ * Remove a Webhook
119
+ * @param params The query string parameters (optional)
120
+ * @param params.webhookId The Webhook ID
121
+ * @returns The result of the removal
122
+ */
123
+ removeWebhook({ webhookId }: {
124
+ webhookId: string;
125
+ }): Promise<import("./webhook").IRemoveResult>;
126
+ /**
127
+ * Create a new Webhook
128
+ * @param params The params for the request
129
+ * @param params.url The URL to send the webhook to
130
+ * @param params.triggerType The event to trigger the webhook
131
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
132
+ * @returns The created webhook
133
+ */
134
+ createWebhook({ triggerType, filter, url, }: {
135
+ url: string;
136
+ siteId: string;
137
+ triggerType: string;
138
+ filter?: WebhookFilter;
139
+ }): Promise<Webhook>;
140
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Site = void 0;
4
+ const _1 = require(".");
5
+ const core_1 = require("../core");
6
+ /**************************************************************
7
+ * Class
8
+ **************************************************************/
9
+ class Site extends core_1.WebflowRecord {
10
+ /**
11
+ * Get a list of Sites
12
+ * @param client The Axios client instance
13
+ * @returns a list of Sites
14
+ */
15
+ static list(client) {
16
+ const path = "/sites";
17
+ return client.get(path);
18
+ }
19
+ /**
20
+ * Get a single Site
21
+ * @param params The params for the request
22
+ * @param params.siteId The site ID
23
+ * @param params.params The query string parameters (optional)
24
+ * @param client The Axios client instance
25
+ * @returns A single Site
26
+ */
27
+ static getOne({ siteId }, client) {
28
+ (0, core_1.requireArgs)({ siteId });
29
+ const path = `/sites/${siteId}`;
30
+ return client.get(path);
31
+ }
32
+ /**
33
+ * Publish a site
34
+ * @param params The params for the request
35
+ * @param params.siteId The site ID
36
+ * @param params.domains The domains to publish to
37
+ * @param client The Axios client instance
38
+ * @returns The publish result
39
+ */
40
+ static publish({ siteId, domains }, client) {
41
+ (0, core_1.requireArgs)({ siteId, domains });
42
+ const path = `/sites/${siteId}/publish`;
43
+ return client.post(path, { domains });
44
+ }
45
+ /**
46
+ * Get a list of domains for a site
47
+ * @param params The params for the request
48
+ * @param params.siteId The site ID
49
+ * @param client The Axios client instance
50
+ * @returns A list of domains
51
+ */
52
+ static domains({ siteId }, client) {
53
+ (0, core_1.requireArgs)({ siteId });
54
+ const path = `/sites/${siteId}/domains`;
55
+ return client.get(path);
56
+ }
57
+ /**************************************************************
58
+ * Instance Methods
59
+ **************************************************************/
60
+ /**
61
+ * Get a list of domains for a site
62
+ * @returns A list of domains
63
+ */
64
+ async domains() {
65
+ const res = await Site.domains({ siteId: this._id }, this.client);
66
+ return res.data;
67
+ }
68
+ /**
69
+ * Publish a site
70
+ * @param domains The domains to publish to
71
+ * @returns The publish result
72
+ */
73
+ async publishSite(domains) {
74
+ const res = await Site.publish({ siteId: this._id, domains }, this.client);
75
+ return res.data;
76
+ }
77
+ /**
78
+ * Get a single Collection
79
+ * @param params The params for the request
80
+ * @param params.collectionId The collection ID
81
+ * @returns A single Collection
82
+ */
83
+ async collection({ collectionId }) {
84
+ const res = await _1.Collection.getOne({ collectionId }, this.client);
85
+ return new _1.Collection(this.client, res);
86
+ }
87
+ /**
88
+ * Get a list of Collections
89
+ * @returns A list of Collections
90
+ */
91
+ async collections() {
92
+ const res = await _1.Collection.list({ siteId: this._id }, this.client);
93
+ return res.data.map((data) => new _1.Collection(this.client, { ...res, data }));
94
+ }
95
+ /**
96
+ * Get a single Webhook
97
+ * @param params The params for the request
98
+ * @param params.webhookId The webhook ID
99
+ * @returns A single Webhook
100
+ */
101
+ async webhook({ webhookId }) {
102
+ const res = await _1.Webhook.getOne({ siteId: this._id, webhookId }, this.client);
103
+ return new _1.Webhook(this.client, res);
104
+ }
105
+ /**
106
+ * Get a list of Webhooks
107
+ * @returns A list of Webhooks
108
+ */
109
+ async webhooks() {
110
+ const res = await _1.Webhook.list({ siteId: this._id }, this.client);
111
+ return res.data.map((data) => new _1.Webhook(this.client, { ...res, data }));
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
+ const res = await _1.Webhook.remove({ siteId: this._id, webhookId }, this.client);
121
+ return res.data;
122
+ }
123
+ /**
124
+ * Create a new Webhook
125
+ * @param params The params for the request
126
+ * @param params.url The URL to send the webhook to
127
+ * @param params.triggerType The event to trigger the webhook
128
+ * @param params.filter The filter to apply to the webhook (optional: form_submission only)
129
+ * @returns The created webhook
130
+ */
131
+ async createWebhook({ triggerType, filter, url, }) {
132
+ const _params = { url, siteId: this._id, triggerType, filter };
133
+ const res = await _1.Webhook.create(_params, this.client);
134
+ return new _1.Webhook(this.client, res);
135
+ }
136
+ }
137
+ exports.Site = Site;
@@ -0,0 +1,143 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { PaginatedData, WebflowRecord } from "../core";
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
+ export interface IAcessGroup {
14
+ _id: string;
15
+ name: string;
16
+ shortId: string;
17
+ slug: string;
18
+ createdOn: string;
19
+ }
20
+ export interface IUserDelete {
21
+ deleted: number;
22
+ }
23
+ /**************************************************************
24
+ * Types
25
+ **************************************************************/
26
+ export declare type PaginatedUsers = PaginatedData & {
27
+ users: IUser[];
28
+ };
29
+ export declare type PaginatedAccessGroups = PaginatedData & {
30
+ accessGroups: IAcessGroup[];
31
+ };
32
+ export declare type UserIdParam = {
33
+ siteId: string;
34
+ userId: string;
35
+ };
36
+ /**************************************************************
37
+ * Class
38
+ **************************************************************/
39
+ export declare class User extends WebflowRecord<IUser> implements IUser {
40
+ emailVerified: boolean;
41
+ lastUpdated?: string;
42
+ createdOn: string;
43
+ siteId: string;
44
+ _id: string;
45
+ data: any;
46
+ /**************************************************************
47
+ * Static Methods
48
+ **************************************************************/
49
+ /**
50
+ * Get a list of Users
51
+ * @param params The params for the request
52
+ * @param params.siteId The site ID
53
+ * @param params.limit The number of items to return (optional)
54
+ * @param params.offset The number of items to skip (optional)
55
+ * @param client The Axios client instance
56
+ * @returns A list of Users
57
+ */
58
+ static list({ siteId, limit, offset }: {
59
+ siteId: string;
60
+ limit?: number;
61
+ offset?: number;
62
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<PaginatedUsers, any>>;
63
+ /**
64
+ * Get a single User
65
+ * @param params The params for the request
66
+ * @param params.siteId The site ID
67
+ * @param params.userId The user ID
68
+ * @param client The Axios client instance
69
+ * @returns A single User
70
+ */
71
+ static getOne({ siteId, userId }: {
72
+ siteId: string;
73
+ userId: string;
74
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IUser, any>>;
75
+ /**
76
+ * Update a User
77
+ * @param params The params for the request
78
+ * @param params.siteId The site ID
79
+ * @param params.userId The user ID
80
+ * @param params.data The data to update
81
+ * @param client The Axios client instance
82
+ * @returns The updated User
83
+ */
84
+ static update({ siteId, userId, data, }: {
85
+ data: object;
86
+ siteId: string;
87
+ userId: string;
88
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IUser, any>>;
89
+ /**
90
+ * Invite a User to a site
91
+ * @param params The params for the request
92
+ * @param params.siteId The site ID
93
+ * @param params.email The email address of the user to invite
94
+ * @param client The Axios client instance
95
+ * @returns The newly created User
96
+ */
97
+ static invite({ siteId, email }: {
98
+ siteId: string;
99
+ email: string;
100
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IUser, any>>;
101
+ /**
102
+ * Remove a User
103
+ * @param params The params for the request
104
+ * @param params.siteId The site ID
105
+ * @param params.userId The user ID
106
+ * @param client The Axios client instance
107
+ * @returns The result of the remove
108
+ */
109
+ static remove({ siteId, userId }: {
110
+ siteId: string;
111
+ userId: string;
112
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<IUserDelete, any>>;
113
+ /**
114
+ * Get a list of User Access Groups
115
+ * @param params The params for the request
116
+ * @param params.siteId The site ID
117
+ * @param params.limit The number of items to return (optional)
118
+ * @param params.offset The number of items to skip (optional)
119
+ * @param params.sort The sort order of the groups (optional)
120
+ * @param client The Axios client instance
121
+ * @returns A list of Access Groups
122
+ */
123
+ static accessGroups({ siteId, limit, offset, sort, }: {
124
+ siteId: string;
125
+ limit?: number;
126
+ offset?: number;
127
+ sort?: string;
128
+ }, client: AxiosInstance): Promise<import("axios").AxiosResponse<PaginatedAccessGroups, any>>;
129
+ /**************************************************************
130
+ * Instance Methods
131
+ **************************************************************/
132
+ /**
133
+ * Update a User
134
+ * @param data The data to update
135
+ * @returns The updated User
136
+ */
137
+ update(data: any): Promise<User>;
138
+ /**
139
+ * Remove a User
140
+ * @returns The result of the remove
141
+ */
142
+ remove(): Promise<IUserDelete>;
143
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.User = void 0;
4
+ const core_1 = require("../core");
5
+ /**************************************************************
6
+ * Class
7
+ **************************************************************/
8
+ class User extends core_1.WebflowRecord {
9
+ /**************************************************************
10
+ * Static Methods
11
+ **************************************************************/
12
+ /**
13
+ * Get a list of Users
14
+ * @param params The params for the request
15
+ * @param params.siteId The site ID
16
+ * @param params.limit The number of items to return (optional)
17
+ * @param params.offset The number of items to skip (optional)
18
+ * @param client The Axios client instance
19
+ * @returns A list of Users
20
+ */
21
+ static list({ siteId, limit, offset }, client) {
22
+ (0, core_1.requireArgs)({ siteId });
23
+ const params = { limit, offset };
24
+ const path = `/sites/${siteId}/users`;
25
+ return client.get(path, { params });
26
+ }
27
+ /**
28
+ * Get a single User
29
+ * @param params The params for the request
30
+ * @param params.siteId The site ID
31
+ * @param params.userId The user ID
32
+ * @param client The Axios client instance
33
+ * @returns A single User
34
+ */
35
+ static getOne({ siteId, userId }, client) {
36
+ (0, core_1.requireArgs)({ siteId, userId });
37
+ const path = `/sites/${siteId}/users/${userId}`;
38
+ return client.get(path);
39
+ }
40
+ /**
41
+ * Update a User
42
+ * @param params The params for the request
43
+ * @param params.siteId The site ID
44
+ * @param params.userId The user ID
45
+ * @param params.data The data to update
46
+ * @param client The Axios client instance
47
+ * @returns The updated User
48
+ */
49
+ static update({ siteId, userId, data, }, client) {
50
+ (0, core_1.requireArgs)({ siteId, userId });
51
+ const path = `/sites/${siteId}/users/${userId}`;
52
+ return client.patch(path, data);
53
+ }
54
+ /**
55
+ * Invite a User to a site
56
+ * @param params The params for the request
57
+ * @param params.siteId The site ID
58
+ * @param params.email The email address of the user to invite
59
+ * @param client The Axios client instance
60
+ * @returns The newly created User
61
+ */
62
+ static async invite({ siteId, email }, client) {
63
+ (0, core_1.requireArgs)({ siteId, email });
64
+ const path = `/sites/${siteId}/users/invite`;
65
+ return client.post(path, { email });
66
+ }
67
+ /**
68
+ * Remove a User
69
+ * @param params The params for the request
70
+ * @param params.siteId The site ID
71
+ * @param params.userId The user ID
72
+ * @param client The Axios client instance
73
+ * @returns The result of the remove
74
+ */
75
+ static remove({ siteId, userId }, client) {
76
+ (0, core_1.requireArgs)({ siteId, userId });
77
+ const path = `/sites/${siteId}/users/${userId}`;
78
+ return client.delete(path);
79
+ }
80
+ /**
81
+ * Get a list of User Access Groups
82
+ * @param params The params for the request
83
+ * @param params.siteId The site ID
84
+ * @param params.limit The number of items to return (optional)
85
+ * @param params.offset The number of items to skip (optional)
86
+ * @param params.sort The sort order of the groups (optional)
87
+ * @param client The Axios client instance
88
+ * @returns A list of Access Groups
89
+ */
90
+ static accessGroups({ siteId, limit, offset, sort, }, client) {
91
+ (0, core_1.requireArgs)({ siteId });
92
+ const params = { limit, offset, sort };
93
+ const path = `/sites/${siteId}/accessgroups`;
94
+ return client.get(path, { params });
95
+ }
96
+ /**************************************************************
97
+ * Instance Methods
98
+ **************************************************************/
99
+ /**
100
+ * Update a User
101
+ * @param data The data to update
102
+ * @returns The updated User
103
+ */
104
+ async update(data) {
105
+ const params = { siteId: this.siteId, userId: this._id, data };
106
+ const res = await User.update(params, this.client);
107
+ return new User(this.client, res);
108
+ }
109
+ /**
110
+ * Remove a User
111
+ * @returns The result of the remove
112
+ */
113
+ async remove() {
114
+ const params = { siteId: this.siteId, userId: this._id };
115
+ const res = await User.remove(params, this.client);
116
+ return res.data;
117
+ }
118
+ }
119
+ exports.User = User;