@meowpanel/api 0.2.0 → 0.4.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.
- package/esm/mod.d.ts +39 -18
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +26 -8
- package/esm/src/client.d.ts +48 -11
- package/esm/src/client.d.ts.map +1 -1
- package/esm/src/client.js +53 -12
- package/esm/src/errors.d.ts +8 -0
- package/esm/src/errors.d.ts.map +1 -1
- package/esm/src/errors.js +10 -0
- package/esm/src/http.d.ts +2 -2
- package/esm/src/http.d.ts.map +1 -1
- package/esm/src/http.js +5 -2
- package/esm/src/namespace.d.ts +1 -1
- package/esm/src/namespace.js +1 -1
- package/esm/src/resources/account.d.ts +104 -19
- package/esm/src/resources/account.d.ts.map +1 -1
- package/esm/src/resources/account.js +112 -13
- package/esm/src/resources/api-keys.d.ts +16 -24
- package/esm/src/resources/api-keys.d.ts.map +1 -1
- package/esm/src/resources/api-keys.js +16 -20
- package/esm/src/resources/auth.d.ts +70 -4
- package/esm/src/resources/auth.d.ts.map +1 -1
- package/esm/src/resources/auth.js +47 -4
- package/esm/src/resources/eggs.d.ts +261 -22
- package/esm/src/resources/eggs.d.ts.map +1 -1
- package/esm/src/resources/eggs.js +261 -25
- package/esm/src/resources/features.d.ts +35 -0
- package/esm/src/resources/features.d.ts.map +1 -0
- package/esm/src/resources/features.js +21 -0
- package/esm/src/resources/hosts.d.ts +143 -18
- package/esm/src/resources/hosts.d.ts.map +1 -1
- package/esm/src/resources/hosts.js +145 -10
- package/esm/src/resources/logs.d.ts +39 -0
- package/esm/src/resources/logs.d.ts.map +1 -0
- package/esm/src/resources/logs.js +38 -0
- package/esm/src/resources/nodes.d.ts +106 -41
- package/esm/src/resources/nodes.d.ts.map +1 -1
- package/esm/src/resources/nodes.js +121 -28
- package/esm/src/resources/permissions.d.ts +45 -0
- package/esm/src/resources/permissions.d.ts.map +1 -0
- package/esm/src/resources/permissions.js +26 -0
- package/esm/src/resources/request-logs.d.ts +91 -0
- package/esm/src/resources/request-logs.d.ts.map +1 -0
- package/esm/src/resources/request-logs.js +70 -0
- package/esm/src/resources/roles.d.ts +128 -0
- package/esm/src/resources/roles.d.ts.map +1 -0
- package/esm/src/resources/roles.js +142 -0
- package/esm/src/resources/server-groups.d.ts +141 -7
- package/esm/src/resources/server-groups.d.ts.map +1 -1
- package/esm/src/resources/server-groups.js +157 -8
- package/esm/src/resources/servers/activity.d.ts +50 -8
- package/esm/src/resources/servers/activity.d.ts.map +1 -1
- package/esm/src/resources/servers/activity.js +54 -13
- package/esm/src/resources/servers/allocations.d.ts +3 -3
- package/esm/src/resources/servers/allocations.d.ts.map +1 -1
- package/esm/src/resources/servers/allocations.js +7 -7
- package/esm/src/resources/servers/backups.d.ts +46 -0
- package/esm/src/resources/servers/backups.d.ts.map +1 -0
- package/esm/src/resources/servers/backups.js +43 -0
- package/esm/src/resources/servers/connection.d.ts +27 -7
- package/esm/src/resources/servers/connection.d.ts.map +1 -1
- package/esm/src/resources/servers/connection.js +28 -7
- package/esm/src/resources/servers/features.d.ts +81 -0
- package/esm/src/resources/servers/features.d.ts.map +1 -0
- package/esm/src/resources/servers/features.js +60 -0
- package/esm/src/resources/servers/files.d.ts +41 -53
- package/esm/src/resources/servers/files.d.ts.map +1 -1
- package/esm/src/resources/servers/files.js +74 -116
- package/esm/src/resources/servers/index.d.ts +46 -27
- package/esm/src/resources/servers/index.d.ts.map +1 -1
- package/esm/src/resources/servers/index.js +26 -12
- package/esm/src/resources/servers/jobs.d.ts +88 -0
- package/esm/src/resources/servers/jobs.d.ts.map +1 -0
- package/esm/src/resources/servers/jobs.js +115 -0
- package/esm/src/resources/servers/node-client.d.ts +33 -0
- package/esm/src/resources/servers/node-client.d.ts.map +1 -0
- package/esm/src/resources/servers/node-client.js +61 -0
- package/esm/src/resources/servers/profiles.d.ts +45 -1
- package/esm/src/resources/servers/profiles.d.ts.map +1 -1
- package/esm/src/resources/servers/profiles.js +55 -2
- package/esm/src/resources/servers/server.d.ts +10 -25
- package/esm/src/resources/servers/server.d.ts.map +1 -1
- package/esm/src/resources/servers/server.js +18 -34
- package/esm/src/resources/servers/sftp.d.ts +21 -19
- package/esm/src/resources/servers/sftp.d.ts.map +1 -1
- package/esm/src/resources/servers/sftp.js +22 -14
- package/esm/src/resources/servers/sub-users.d.ts +99 -0
- package/esm/src/resources/servers/sub-users.d.ts.map +1 -0
- package/esm/src/resources/servers/sub-users.js +94 -0
- package/esm/src/resources/servers/types.d.ts +27 -25
- package/esm/src/resources/servers/types.d.ts.map +1 -1
- package/esm/src/resources/systems.d.ts +124 -0
- package/esm/src/resources/systems.d.ts.map +1 -0
- package/esm/src/resources/systems.js +139 -0
- package/esm/src/resources/users.d.ts +330 -0
- package/esm/src/resources/users.d.ts.map +1 -0
- package/esm/src/resources/users.js +280 -0
- package/esm/src/types.d.ts +18 -1
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/types.js +11 -0
- package/package.json +1 -1
- package/script/mod.d.ts +39 -18
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +52 -5
- package/script/src/client.d.ts +48 -11
- package/script/src/client.d.ts.map +1 -1
- package/script/src/client.js +53 -12
- package/script/src/errors.d.ts +8 -0
- package/script/src/errors.d.ts.map +1 -1
- package/script/src/errors.js +10 -0
- package/script/src/http.d.ts +2 -2
- package/script/src/http.d.ts.map +1 -1
- package/script/src/http.js +5 -2
- package/script/src/namespace.d.ts +1 -1
- package/script/src/namespace.js +1 -1
- package/script/src/resources/account.d.ts +104 -19
- package/script/src/resources/account.d.ts.map +1 -1
- package/script/src/resources/account.js +114 -13
- package/script/src/resources/api-keys.d.ts +16 -24
- package/script/src/resources/api-keys.d.ts.map +1 -1
- package/script/src/resources/api-keys.js +15 -19
- package/script/src/resources/auth.d.ts +70 -4
- package/script/src/resources/auth.d.ts.map +1 -1
- package/script/src/resources/auth.js +47 -4
- package/script/src/resources/eggs.d.ts +261 -22
- package/script/src/resources/eggs.d.ts.map +1 -1
- package/script/src/resources/eggs.js +267 -26
- package/script/src/resources/features.d.ts +35 -0
- package/script/src/resources/features.d.ts.map +1 -0
- package/script/src/resources/features.js +25 -0
- package/script/src/resources/hosts.d.ts +143 -18
- package/script/src/resources/hosts.d.ts.map +1 -1
- package/script/src/resources/hosts.js +146 -10
- package/script/src/resources/logs.d.ts +39 -0
- package/script/src/resources/logs.d.ts.map +1 -0
- package/script/src/resources/logs.js +42 -0
- package/script/src/resources/nodes.d.ts +106 -41
- package/script/src/resources/nodes.d.ts.map +1 -1
- package/script/src/resources/nodes.js +122 -28
- package/script/src/resources/permissions.d.ts +45 -0
- package/script/src/resources/permissions.d.ts.map +1 -0
- package/script/src/resources/permissions.js +31 -0
- package/script/src/resources/request-logs.d.ts +91 -0
- package/script/src/resources/request-logs.d.ts.map +1 -0
- package/script/src/resources/request-logs.js +75 -0
- package/script/src/resources/roles.d.ts +128 -0
- package/script/src/resources/roles.d.ts.map +1 -0
- package/script/src/resources/roles.js +148 -0
- package/script/src/resources/server-groups.d.ts +141 -7
- package/script/src/resources/server-groups.d.ts.map +1 -1
- package/script/src/resources/server-groups.js +158 -8
- package/script/src/resources/servers/activity.d.ts +50 -8
- package/script/src/resources/servers/activity.d.ts.map +1 -1
- package/script/src/resources/servers/activity.js +54 -12
- package/script/src/resources/servers/allocations.d.ts +3 -3
- package/script/src/resources/servers/allocations.d.ts.map +1 -1
- package/script/src/resources/servers/allocations.js +7 -7
- package/script/src/resources/servers/backups.d.ts +46 -0
- package/script/src/resources/servers/backups.d.ts.map +1 -0
- package/script/src/resources/servers/backups.js +47 -0
- package/script/src/resources/servers/connection.d.ts +27 -7
- package/script/src/resources/servers/connection.d.ts.map +1 -1
- package/script/src/resources/servers/connection.js +28 -7
- package/script/src/resources/servers/features.d.ts +81 -0
- package/script/src/resources/servers/features.d.ts.map +1 -0
- package/script/src/resources/servers/features.js +64 -0
- package/script/src/resources/servers/files.d.ts +41 -53
- package/script/src/resources/servers/files.d.ts.map +1 -1
- package/script/src/resources/servers/files.js +74 -116
- package/script/src/resources/servers/index.d.ts +46 -27
- package/script/src/resources/servers/index.d.ts.map +1 -1
- package/script/src/resources/servers/index.js +26 -12
- package/script/src/resources/servers/jobs.d.ts +88 -0
- package/script/src/resources/servers/jobs.d.ts.map +1 -0
- package/script/src/resources/servers/jobs.js +120 -0
- package/script/src/resources/servers/node-client.d.ts +33 -0
- package/script/src/resources/servers/node-client.d.ts.map +1 -0
- package/script/src/resources/servers/node-client.js +65 -0
- package/script/src/resources/servers/profiles.d.ts +45 -1
- package/script/src/resources/servers/profiles.d.ts.map +1 -1
- package/script/src/resources/servers/profiles.js +55 -2
- package/script/src/resources/servers/server.d.ts +10 -25
- package/script/src/resources/servers/server.d.ts.map +1 -1
- package/script/src/resources/servers/server.js +18 -34
- package/script/src/resources/servers/sftp.d.ts +21 -19
- package/script/src/resources/servers/sftp.d.ts.map +1 -1
- package/script/src/resources/servers/sftp.js +22 -14
- package/script/src/resources/servers/sub-users.d.ts +99 -0
- package/script/src/resources/servers/sub-users.d.ts.map +1 -0
- package/script/src/resources/servers/sub-users.js +99 -0
- package/script/src/resources/servers/types.d.ts +27 -25
- package/script/src/resources/servers/types.d.ts.map +1 -1
- package/script/src/resources/systems.d.ts +124 -0
- package/script/src/resources/systems.d.ts.map +1 -0
- package/script/src/resources/systems.js +145 -0
- package/script/src/resources/users.d.ts +330 -0
- package/script/src/resources/users.d.ts.map +1 -0
- package/script/src/resources/users.js +287 -0
- package/script/src/types.d.ts +18 -1
- package/script/src/types.d.ts.map +1 -1
- package/script/src/types.js +12 -0
- package/esm/src/resources/members.d.ts +0 -138
- package/esm/src/resources/members.d.ts.map +0 -1
- package/esm/src/resources/members.js +0 -122
- package/script/src/resources/members.d.ts +0 -138
- package/script/src/resources/members.d.ts.map +0 -1
- package/script/src/resources/members.js +0 -127
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ResourceNamespace } from '../namespace.js';
|
|
2
2
|
import { ReactiveResource } from '../reactive.js';
|
|
3
|
-
import { joinIncludes, toNanoID } from '../types.js';
|
|
4
|
-
import {
|
|
3
|
+
import { joinIncludes, parseIssuerRef, toNanoID } from '../types.js';
|
|
4
|
+
import { User } from './users.js';
|
|
5
|
+
import { Host } from './hosts.js';
|
|
5
6
|
import { ActivityLog } from './servers/activity.js';
|
|
6
7
|
/**
|
|
7
8
|
* A geographic location associated with one or more nodes.
|
|
@@ -13,10 +14,10 @@ export class NodeLocation extends ReactiveResource {
|
|
|
13
14
|
name;
|
|
14
15
|
/** Short code used in node name generation, e.g. `"use"`. */
|
|
15
16
|
short;
|
|
16
|
-
/** The
|
|
17
|
-
|
|
18
|
-
/** The full
|
|
19
|
-
|
|
17
|
+
/** The host's NanoID. Always present. */
|
|
18
|
+
hostId;
|
|
19
|
+
/** The full host object. Requires `?include=host`. */
|
|
20
|
+
host;
|
|
20
21
|
/** Internal notes. */
|
|
21
22
|
notes;
|
|
22
23
|
/** When this location was created. */
|
|
@@ -29,8 +30,8 @@ export class NodeLocation extends ReactiveResource {
|
|
|
29
30
|
this.id = toNanoID(data.id);
|
|
30
31
|
this.name = data.name;
|
|
31
32
|
this.short = data.short;
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
33
|
+
this.hostId = toNanoID(data.host_id);
|
|
34
|
+
this.host = data.host ? new Host(data.host) : undefined;
|
|
34
35
|
this.notes = data.notes;
|
|
35
36
|
this.createdAt = new Date(data.created_at);
|
|
36
37
|
this.updatedAt = new Date(data.updated_at);
|
|
@@ -46,10 +47,10 @@ export class NodeType extends ReactiveResource {
|
|
|
46
47
|
name;
|
|
47
48
|
/** Short code used in node name generation, e.g. `"a"`. */
|
|
48
49
|
short;
|
|
49
|
-
/** The
|
|
50
|
-
|
|
51
|
-
/** The full
|
|
52
|
-
|
|
50
|
+
/** The host's NanoID. Always present. */
|
|
51
|
+
hostId;
|
|
52
|
+
/** The full host object. Requires `?include=host`. */
|
|
53
|
+
host;
|
|
53
54
|
/** Internal notes. */
|
|
54
55
|
notes;
|
|
55
56
|
/** When this type was created. */
|
|
@@ -62,8 +63,8 @@ export class NodeType extends ReactiveResource {
|
|
|
62
63
|
this.id = toNanoID(data.id);
|
|
63
64
|
this.name = data.name;
|
|
64
65
|
this.short = data.short;
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
66
|
+
this.hostId = toNanoID(data.host_id);
|
|
67
|
+
this.host = data.host ? new Host(data.host) : undefined;
|
|
67
68
|
this.notes = data.notes;
|
|
68
69
|
this.createdAt = new Date(data.created_at);
|
|
69
70
|
this.updatedAt = new Date(data.updated_at);
|
|
@@ -112,7 +113,7 @@ export class NodeAllocationIp extends ReactiveResource {
|
|
|
112
113
|
super();
|
|
113
114
|
this.id = toNanoID(data.id);
|
|
114
115
|
this.ip = data.ip;
|
|
115
|
-
this.ipAlias = data.
|
|
116
|
+
this.ipAlias = data.ip_alias;
|
|
116
117
|
this.ports = data.ports.map((port) => new NodeAllocationPort(port));
|
|
117
118
|
this.nodeId = toNanoID(data.node_id);
|
|
118
119
|
this.node = data.node ? new Node(data.node) : undefined;
|
|
@@ -129,8 +130,6 @@ export class NodeAllocationIp extends ReactiveResource {
|
|
|
129
130
|
export class Node extends ReactiveResource {
|
|
130
131
|
/** The node's unique NanoID. */
|
|
131
132
|
id;
|
|
132
|
-
/** The issuer type, always `'node'`. */
|
|
133
|
-
issuerType;
|
|
134
133
|
/**
|
|
135
134
|
* Auto-generated display name in the format `{type}{num}{location}.{hostname}`,
|
|
136
135
|
* e.g. `"a001use.host.example.com"`.
|
|
@@ -138,8 +137,10 @@ export class Node extends ReactiveResource {
|
|
|
138
137
|
name;
|
|
139
138
|
/** Optional description of the node. */
|
|
140
139
|
description;
|
|
141
|
-
/** The owner's NanoID. Always present. */
|
|
140
|
+
/** The owner's bare NanoID (parsed from the namespaced `owner_id`). Always present. */
|
|
142
141
|
ownerId;
|
|
142
|
+
/** The owner's issuer type, e.g. `'user'` or `'system'`. */
|
|
143
|
+
ownerType;
|
|
143
144
|
/** The full owner object. Requires `?include=owner`. */
|
|
144
145
|
owner;
|
|
145
146
|
/** The location's NanoID. Always present. */
|
|
@@ -154,11 +155,6 @@ export class Node extends ReactiveResource {
|
|
|
154
155
|
num;
|
|
155
156
|
/** Resource limits configured for this node. */
|
|
156
157
|
limits;
|
|
157
|
-
/**
|
|
158
|
-
* Daemon authentication token row id. `null` while the node is unclaimed,
|
|
159
|
-
* populated once a daemon redeems its install token.
|
|
160
|
-
*/
|
|
161
|
-
authToken;
|
|
162
158
|
/** Lifecycle state. See {@link NodeStatus}. */
|
|
163
159
|
status;
|
|
164
160
|
/** Timestamp of the first successful claim. `null` until claimed. */
|
|
@@ -177,21 +173,24 @@ export class Node extends ReactiveResource {
|
|
|
177
173
|
canAutoDeploy;
|
|
178
174
|
/** `true` when the node is behind a reverse proxy. */
|
|
179
175
|
isBehindProxy;
|
|
180
|
-
/** Internal notes
|
|
176
|
+
/** Internal notes. Requires `node.notes.read`. */
|
|
181
177
|
notes;
|
|
182
178
|
/** When this node was registered. */
|
|
183
179
|
createdAt;
|
|
184
180
|
/** When this node was last updated. */
|
|
185
181
|
updatedAt;
|
|
182
|
+
/** When this node was soft-deleted, or `null` if active. */
|
|
183
|
+
deletedAt;
|
|
186
184
|
/** @internal */
|
|
187
185
|
constructor(data) {
|
|
188
186
|
super();
|
|
189
187
|
this.id = toNanoID(data.id);
|
|
190
|
-
this.issuerType = data.issuer_type;
|
|
191
188
|
this.name = data.name;
|
|
192
189
|
this.description = data.description;
|
|
193
|
-
|
|
194
|
-
this.
|
|
190
|
+
const owner = parseIssuerRef(data.owner_id);
|
|
191
|
+
this.ownerId = owner.id;
|
|
192
|
+
this.ownerType = owner.type;
|
|
193
|
+
this.owner = data.owner ? new User(data.owner) : undefined;
|
|
195
194
|
this.locationId = toNanoID(data.location_id);
|
|
196
195
|
this.location = data.location ? new NodeLocation(data.location) : undefined;
|
|
197
196
|
this.typeId = toNanoID(data.type_id);
|
|
@@ -204,7 +203,6 @@ export class Node extends ReactiveResource {
|
|
|
204
203
|
diskOverallocateMb: data.limits.disk_overallocate_mb,
|
|
205
204
|
uploadSizeMb: data.limits.upload_size_mb,
|
|
206
205
|
};
|
|
207
|
-
this.authToken = data.auth_token;
|
|
208
206
|
this.status = data.status;
|
|
209
207
|
this.claimedAt = data.claimed_at ? new Date(data.claimed_at) : null;
|
|
210
208
|
this.installTokenExpiresAt = data.install_token_expires_at === undefined
|
|
@@ -219,6 +217,7 @@ export class Node extends ReactiveResource {
|
|
|
219
217
|
this.notes = data.notes;
|
|
220
218
|
this.createdAt = new Date(data.created_at);
|
|
221
219
|
this.updatedAt = new Date(data.updated_at);
|
|
220
|
+
this.deletedAt = data.deleted_at ? new Date(data.deleted_at) : null;
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
223
|
/**
|
|
@@ -270,6 +269,48 @@ export class NodeAllocationsManager {
|
|
|
270
269
|
await this.http.delete(`/nodes/${this.nodeId}/allocations/${encodeURIComponent(allocationIp)}/ports/${port}`);
|
|
271
270
|
}
|
|
272
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* CRUD for a node classifier (location or type).
|
|
274
|
+
*
|
|
275
|
+
* Access via `api.nodes.locations` or `api.nodes.types`.
|
|
276
|
+
*/
|
|
277
|
+
export class NodeClassifierManager {
|
|
278
|
+
http;
|
|
279
|
+
path;
|
|
280
|
+
make;
|
|
281
|
+
/** @internal */
|
|
282
|
+
constructor(http, path, make) {
|
|
283
|
+
this.http = http;
|
|
284
|
+
this.path = path;
|
|
285
|
+
this.make = make;
|
|
286
|
+
}
|
|
287
|
+
/** Fetch a paginated list. */
|
|
288
|
+
async list(opts = {}) {
|
|
289
|
+
const result = await this.http.list(this.path, opts);
|
|
290
|
+
return { ...result, data: result.data.map((d) => this.make(d)) };
|
|
291
|
+
}
|
|
292
|
+
/** Fetch a single entry by ID. */
|
|
293
|
+
async get(id) {
|
|
294
|
+
return this.make(await this.http.get(`${this.path}/${id}`));
|
|
295
|
+
}
|
|
296
|
+
/** Create a new entry. */
|
|
297
|
+
async create(payload) {
|
|
298
|
+
return this.make(await this.http.post(this.path, {
|
|
299
|
+
name: payload.name,
|
|
300
|
+
short: payload.short,
|
|
301
|
+
host_id: payload.hostId,
|
|
302
|
+
notes: payload.notes,
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
/** Update an entry's name, short code, or notes. */
|
|
306
|
+
async update(id, payload) {
|
|
307
|
+
return this.make(await this.http.patch(`${this.path}/${id}`, payload));
|
|
308
|
+
}
|
|
309
|
+
/** Delete an entry. */
|
|
310
|
+
async delete(id) {
|
|
311
|
+
await this.http.delete(`${this.path}/${id}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
273
314
|
/**
|
|
274
315
|
* Namespace for node management.
|
|
275
316
|
*
|
|
@@ -283,9 +324,15 @@ export class NodeAllocationsManager {
|
|
|
283
324
|
* ```
|
|
284
325
|
*/
|
|
285
326
|
export class NodesNamespace extends ResourceNamespace {
|
|
327
|
+
/** Manage node locations. */
|
|
328
|
+
locations;
|
|
329
|
+
/** Manage node types. */
|
|
330
|
+
types;
|
|
286
331
|
/** @internal */
|
|
287
332
|
constructor(http) {
|
|
288
333
|
super(http);
|
|
334
|
+
this.locations = new NodeClassifierManager(http, '/nodes/locations', (d) => new NodeLocation(d));
|
|
335
|
+
this.types = new NodeClassifierManager(http, '/nodes/types', (d) => new NodeType(d));
|
|
289
336
|
}
|
|
290
337
|
/**
|
|
291
338
|
* Fetch a paginated list of nodes.
|
|
@@ -354,6 +401,52 @@ export class NodesNamespace extends ResourceNamespace {
|
|
|
354
401
|
installTokenExpiresAt: new Date(data.install_token_expires_at),
|
|
355
402
|
};
|
|
356
403
|
}
|
|
404
|
+
/** Update a node's connection details, placement, limits, or flags. */
|
|
405
|
+
async update(id, payload) {
|
|
406
|
+
const body = {};
|
|
407
|
+
if (payload.fqdn !== undefined)
|
|
408
|
+
body['fqdn'] = payload.fqdn;
|
|
409
|
+
if (payload.scheme !== undefined)
|
|
410
|
+
body['scheme'] = payload.scheme;
|
|
411
|
+
if (payload.apiPort !== undefined)
|
|
412
|
+
body['api_port'] = payload.apiPort;
|
|
413
|
+
if (payload.sftpPort !== undefined)
|
|
414
|
+
body['sftp_port'] = payload.sftpPort;
|
|
415
|
+
if (payload.locationId !== undefined)
|
|
416
|
+
body['location_id'] = payload.locationId;
|
|
417
|
+
if (payload.typeId !== undefined)
|
|
418
|
+
body['type_id'] = payload.typeId;
|
|
419
|
+
if (payload.num !== undefined)
|
|
420
|
+
body['num'] = payload.num;
|
|
421
|
+
if (payload.description !== undefined)
|
|
422
|
+
body['description'] = payload.description;
|
|
423
|
+
if (payload.notes !== undefined)
|
|
424
|
+
body['notes'] = payload.notes;
|
|
425
|
+
if (payload.isMaintenanceMode !== undefined)
|
|
426
|
+
body['is_maintenance_mode'] = payload.isMaintenanceMode;
|
|
427
|
+
if (payload.canAutoDeploy !== undefined)
|
|
428
|
+
body['can_auto_deploy'] = payload.canAutoDeploy;
|
|
429
|
+
if (payload.isBehindProxy !== undefined)
|
|
430
|
+
body['is_behind_proxy'] = payload.isBehindProxy;
|
|
431
|
+
if (payload.limits) {
|
|
432
|
+
body['limits'] = {
|
|
433
|
+
memory_mb: payload.limits.memoryMb,
|
|
434
|
+
memory_overallocate_mb: payload.limits.memoryOverallocateMb,
|
|
435
|
+
disk_mb: payload.limits.diskMb,
|
|
436
|
+
disk_overallocate_mb: payload.limits.diskOverallocateMb,
|
|
437
|
+
upload_size_mb: payload.limits.uploadSizeMb,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
const data = await this.http.patch(`/nodes/${id}`, body);
|
|
441
|
+
const node = new Node(data);
|
|
442
|
+
this.upsertCache(node);
|
|
443
|
+
return node;
|
|
444
|
+
}
|
|
445
|
+
/** Delete a node. */
|
|
446
|
+
async delete(id) {
|
|
447
|
+
await this.http.delete(`/nodes/${id}`);
|
|
448
|
+
this.removeFromCache(id);
|
|
449
|
+
}
|
|
357
450
|
/**
|
|
358
451
|
* Claim a node by redeeming its install token. Public endpoint, no
|
|
359
452
|
* Authorization header. Returns a permanent daemon token; the install
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ISODate } from '../types.js';
|
|
2
|
+
/** Raw API shape for a permission grant. @internal */
|
|
3
|
+
export interface PermissionGrantData {
|
|
4
|
+
permission: string;
|
|
5
|
+
is_allow: boolean;
|
|
6
|
+
scope: string | null;
|
|
7
|
+
expires_at: ISODate | null;
|
|
8
|
+
granted_at: ISODate;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A permission grant as returned by a grants endpoint.
|
|
12
|
+
*
|
|
13
|
+
* These are direct grants on the actor only, not role-derived and not expanded to
|
|
14
|
+
* ancestor scopes.
|
|
15
|
+
*/
|
|
16
|
+
export interface PermissionGrant {
|
|
17
|
+
/** The permission name, e.g. `"server.console.read"`. */
|
|
18
|
+
permission: string;
|
|
19
|
+
/** `true` for an allow grant, `false` for a deny. */
|
|
20
|
+
isAllow: boolean;
|
|
21
|
+
/** The namespaced scope (`"<type>:<id>"`), or `null` for a global grant. */
|
|
22
|
+
scope: string | null;
|
|
23
|
+
/** When the grant expires, or `null` if it never expires. */
|
|
24
|
+
expiresAt: Date | null;
|
|
25
|
+
/** When the grant was created. */
|
|
26
|
+
grantedAt: Date;
|
|
27
|
+
}
|
|
28
|
+
/** A permission grant to apply. */
|
|
29
|
+
export interface PermissionGrantInput {
|
|
30
|
+
/** The permission name, e.g. `"server.console.read"`. */
|
|
31
|
+
permission: string;
|
|
32
|
+
/** Namespaced scope (`"<type>:<id>"`). Omit for a global grant. */
|
|
33
|
+
scope?: string;
|
|
34
|
+
/** `false` to create a deny grant. Defaults to allow. */
|
|
35
|
+
isAllow?: boolean;
|
|
36
|
+
/** Expiry. `null` clears an existing expiry; omit to leave it unchanged. */
|
|
37
|
+
expiresAt?: Date | null;
|
|
38
|
+
}
|
|
39
|
+
/** Map a raw grant to its client shape. @internal */
|
|
40
|
+
export declare function parseGrant(data: PermissionGrantData): PermissionGrant;
|
|
41
|
+
/** Serialize a grant input to its request body. @internal */
|
|
42
|
+
export declare function grantToBody(input: PermissionGrantInput): Record<string, unknown>;
|
|
43
|
+
/** Normalize one-or-many grant inputs to the array body the grant endpoints accept. @internal */
|
|
44
|
+
export declare function grantsToBody(grants: PermissionGrantInput | PermissionGrantInput[]): Record<string, unknown>[];
|
|
45
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../src/src/resources/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,6DAA6D;IAC7D,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,kCAAkC;IAClC,SAAS,EAAE,IAAI,CAAC;CAChB;AAED,mCAAmC;AACnC,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED,qDAAqD;AACrD,wBAAgB,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,eAAe,CAQrE;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQhF;AAED,iGAAiG;AACjG,wBAAgB,YAAY,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAE7G"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Map a raw grant to its client shape. @internal */
|
|
2
|
+
export function parseGrant(data) {
|
|
3
|
+
return {
|
|
4
|
+
permission: data.permission,
|
|
5
|
+
isAllow: data.is_allow,
|
|
6
|
+
scope: data.scope,
|
|
7
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
8
|
+
grantedAt: new Date(data.granted_at),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Serialize a grant input to its request body. @internal */
|
|
12
|
+
export function grantToBody(input) {
|
|
13
|
+
const body = { permission: input.permission };
|
|
14
|
+
if (input.scope !== undefined)
|
|
15
|
+
body['scope'] = input.scope;
|
|
16
|
+
if (input.isAllow !== undefined)
|
|
17
|
+
body['is_allow'] = input.isAllow;
|
|
18
|
+
if (input.expiresAt !== undefined) {
|
|
19
|
+
body['expires_at'] = input.expiresAt === null ? null : input.expiresAt.toISOString();
|
|
20
|
+
}
|
|
21
|
+
return body;
|
|
22
|
+
}
|
|
23
|
+
/** Normalize one-or-many grant inputs to the array body the grant endpoints accept. @internal */
|
|
24
|
+
export function grantsToBody(grants) {
|
|
25
|
+
return (Array.isArray(grants) ? grants : [grants]).map(grantToBody);
|
|
26
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import { type ISODate, type NanoID, type Paginated } from '../types.js';
|
|
3
|
+
import { User, type UserData } from './users.js';
|
|
4
|
+
/** Raw API shape for a request-log line. @internal */
|
|
5
|
+
interface RequestLogLineData {
|
|
6
|
+
id: string;
|
|
7
|
+
level: string;
|
|
8
|
+
message: string;
|
|
9
|
+
elapsed_time: number;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
created_at: ISODate;
|
|
12
|
+
}
|
|
13
|
+
/** Raw API shape for a request log. @internal */
|
|
14
|
+
export interface RequestLogData {
|
|
15
|
+
id: string;
|
|
16
|
+
method: string;
|
|
17
|
+
path: string;
|
|
18
|
+
issuer_id?: string;
|
|
19
|
+
issuer?: UserData;
|
|
20
|
+
ip?: string | null;
|
|
21
|
+
client_request_id: string | null;
|
|
22
|
+
logs?: RequestLogLineData[];
|
|
23
|
+
created_at: ISODate;
|
|
24
|
+
}
|
|
25
|
+
/** One log line emitted while handling a request. */
|
|
26
|
+
export interface RequestLogLine {
|
|
27
|
+
id: NanoID;
|
|
28
|
+
/** Log level, e.g. `"info"`, `"error"`. */
|
|
29
|
+
level: string;
|
|
30
|
+
message: string;
|
|
31
|
+
/** Time elapsed at this line, in milliseconds. */
|
|
32
|
+
elapsedTime: number;
|
|
33
|
+
/** Structured metadata. Requires `application.logs.sensitive.read`. */
|
|
34
|
+
metadata: Record<string, unknown> | undefined;
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A logged HTTP request.
|
|
39
|
+
*
|
|
40
|
+
* The `clientRequestId` matches the `x-request-id` response header, so a client can
|
|
41
|
+
* correlate a response with its server-side log.
|
|
42
|
+
*
|
|
43
|
+
* Retrieved via `api.logs.requests` or `api.account.requestLogs`.
|
|
44
|
+
*/
|
|
45
|
+
export declare class RequestLog {
|
|
46
|
+
/** The request log's unique NanoID. */
|
|
47
|
+
readonly id: NanoID;
|
|
48
|
+
/** HTTP method, e.g. `"GET"`. */
|
|
49
|
+
readonly method: string;
|
|
50
|
+
/** Request path. */
|
|
51
|
+
readonly path: string;
|
|
52
|
+
/** The issuer's bare NanoID (parsed from the namespaced `issuer_id`), or `null` for an unauthenticated request. */
|
|
53
|
+
readonly issuerId: NanoID | null;
|
|
54
|
+
/** The issuer's type, e.g. `'user'`, `'system'`, or `null`. */
|
|
55
|
+
readonly issuerType: string | null;
|
|
56
|
+
/** The expanded issuer. Requires `?include=issuer`. */
|
|
57
|
+
readonly issuer: User | undefined;
|
|
58
|
+
/** The source IP. Requires `application.logs.sensitive.read`. */
|
|
59
|
+
readonly ip: string | null | undefined;
|
|
60
|
+
/** The client-supplied correlation id (matches the `x-request-id` header). */
|
|
61
|
+
readonly clientRequestId: string | null;
|
|
62
|
+
/** The request's log lines. Requires `?include=logs`. */
|
|
63
|
+
readonly logs: RequestLogLine[] | undefined;
|
|
64
|
+
/** When the request was received. */
|
|
65
|
+
readonly createdAt: Date;
|
|
66
|
+
/** @internal */
|
|
67
|
+
constructor(data: RequestLogData);
|
|
68
|
+
}
|
|
69
|
+
/** Which related data to include in a request-log response. */
|
|
70
|
+
export type RequestLogInclude = 'logs' | 'issuer';
|
|
71
|
+
/** Query options for a request-log feed. */
|
|
72
|
+
export interface RequestLogFeedOptions {
|
|
73
|
+
page?: number;
|
|
74
|
+
perPage?: number;
|
|
75
|
+
/** Sort order by creation time. Defaults to oldest-first. */
|
|
76
|
+
sort?: 'created_at_asc' | 'created_at_desc';
|
|
77
|
+
/** Filter by HTTP method. */
|
|
78
|
+
method?: string;
|
|
79
|
+
/** Filter by request path. */
|
|
80
|
+
path?: string;
|
|
81
|
+
/** Filter by the issuer's auth-issuer id. */
|
|
82
|
+
issuerId?: string;
|
|
83
|
+
/** Filter by the client correlation id. */
|
|
84
|
+
clientRequestId?: string;
|
|
85
|
+
/** Related data to include. */
|
|
86
|
+
include?: RequestLogInclude[];
|
|
87
|
+
}
|
|
88
|
+
/** Fetch a request-log feed and map the entries to {@link RequestLog} instances. @internal */
|
|
89
|
+
export declare function listRequestLogs(http: HttpClient, path: string, opts?: RequestLogFeedOptions): Promise<Paginated<RequestLog>>;
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=request-logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logs.d.ts","sourceRoot":"","sources":["../../../src/src/resources/request-logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,SAAS,EAA4B,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,sDAAsD;AACtD,UAAU,kBAAkB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC,MAAM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CAAC;IACzB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,8FAA8F;AAC9F,wBAAsB,eAAe,CACpC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,qBAA0B,GAC9B,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAYhC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { joinIncludes, parseIssuerRef, toNanoID } from '../types.js';
|
|
2
|
+
import { User } from './users.js';
|
|
3
|
+
function makeRequestLogLine(data) {
|
|
4
|
+
return {
|
|
5
|
+
id: toNanoID(data.id),
|
|
6
|
+
level: data.level,
|
|
7
|
+
message: data.message,
|
|
8
|
+
elapsedTime: data.elapsed_time,
|
|
9
|
+
metadata: data.metadata,
|
|
10
|
+
createdAt: new Date(data.created_at),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A logged HTTP request.
|
|
15
|
+
*
|
|
16
|
+
* The `clientRequestId` matches the `x-request-id` response header, so a client can
|
|
17
|
+
* correlate a response with its server-side log.
|
|
18
|
+
*
|
|
19
|
+
* Retrieved via `api.logs.requests` or `api.account.requestLogs`.
|
|
20
|
+
*/
|
|
21
|
+
export class RequestLog {
|
|
22
|
+
/** The request log's unique NanoID. */
|
|
23
|
+
id;
|
|
24
|
+
/** HTTP method, e.g. `"GET"`. */
|
|
25
|
+
method;
|
|
26
|
+
/** Request path. */
|
|
27
|
+
path;
|
|
28
|
+
/** The issuer's bare NanoID (parsed from the namespaced `issuer_id`), or `null` for an unauthenticated request. */
|
|
29
|
+
issuerId;
|
|
30
|
+
/** The issuer's type, e.g. `'user'`, `'system'`, or `null`. */
|
|
31
|
+
issuerType;
|
|
32
|
+
/** The expanded issuer. Requires `?include=issuer`. */
|
|
33
|
+
issuer;
|
|
34
|
+
/** The source IP. Requires `application.logs.sensitive.read`. */
|
|
35
|
+
ip;
|
|
36
|
+
/** The client-supplied correlation id (matches the `x-request-id` header). */
|
|
37
|
+
clientRequestId;
|
|
38
|
+
/** The request's log lines. Requires `?include=logs`. */
|
|
39
|
+
logs;
|
|
40
|
+
/** When the request was received. */
|
|
41
|
+
createdAt;
|
|
42
|
+
/** @internal */
|
|
43
|
+
constructor(data) {
|
|
44
|
+
this.id = toNanoID(data.id);
|
|
45
|
+
this.method = data.method;
|
|
46
|
+
this.path = data.path;
|
|
47
|
+
const issuer = data.issuer_id ? parseIssuerRef(data.issuer_id) : null;
|
|
48
|
+
this.issuerId = issuer ? issuer.id : null;
|
|
49
|
+
this.issuerType = issuer ? issuer.type : null;
|
|
50
|
+
this.issuer = data.issuer ? new User(data.issuer) : undefined;
|
|
51
|
+
this.ip = data.ip;
|
|
52
|
+
this.clientRequestId = data.client_request_id;
|
|
53
|
+
this.logs = data.logs?.map(makeRequestLogLine);
|
|
54
|
+
this.createdAt = new Date(data.created_at);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Fetch a request-log feed and map the entries to {@link RequestLog} instances. @internal */
|
|
58
|
+
export async function listRequestLogs(http, path, opts = {}) {
|
|
59
|
+
const include = joinIncludes(opts);
|
|
60
|
+
const params = {
|
|
61
|
+
sort: opts.sort,
|
|
62
|
+
method: opts.method,
|
|
63
|
+
path: opts.path,
|
|
64
|
+
issuer_id: opts.issuerId,
|
|
65
|
+
client_request_id: opts.clientRequestId,
|
|
66
|
+
include,
|
|
67
|
+
};
|
|
68
|
+
const result = await http.list(path, { page: opts.page, perPage: opts.perPage }, params);
|
|
69
|
+
return { ...result, data: result.data.map((d) => new RequestLog(d)) };
|
|
70
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import { ResourceNamespace } from '../namespace.js';
|
|
3
|
+
import { ReactiveResource } from '../reactive.js';
|
|
4
|
+
import { type ISODate, type NanoID, type Paginated, type ResourceColor } from '../types.js';
|
|
5
|
+
import { type PermissionGrant, type PermissionGrantInput } from './permissions.js';
|
|
6
|
+
/** Raw API shape for a role. @internal */
|
|
7
|
+
export interface RoleData {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
description: string | null;
|
|
11
|
+
color: ResourceColor | null;
|
|
12
|
+
/** Requires `permissions.roles.notes.read`. */
|
|
13
|
+
notes?: string | null;
|
|
14
|
+
created_at: ISODate;
|
|
15
|
+
updated_at: ISODate;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A named bundle of permissions that can be assigned to users.
|
|
19
|
+
*
|
|
20
|
+
* A role carries no permissions inline; fetch them via {@link RolesNamespace.permissions}.
|
|
21
|
+
* Its assignment scope and order live on the user-role link.
|
|
22
|
+
*
|
|
23
|
+
* Retrieved via {@link RolesNamespace.get} or {@link RolesNamespace.list}.
|
|
24
|
+
*/
|
|
25
|
+
export declare class Role extends ReactiveResource {
|
|
26
|
+
/** The role's unique NanoID. */
|
|
27
|
+
readonly id: NanoID;
|
|
28
|
+
/** Display title, e.g. `"Support"`. */
|
|
29
|
+
title: string;
|
|
30
|
+
/** Optional description. */
|
|
31
|
+
description: string | null;
|
|
32
|
+
/** Color used in the UI for grouping, or `null`. */
|
|
33
|
+
color: ResourceColor | null;
|
|
34
|
+
/** Internal notes. Requires `permissions.roles.notes.read`. */
|
|
35
|
+
notes: string | null | undefined;
|
|
36
|
+
/** When this role was created. */
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
/** When this role was last updated. */
|
|
39
|
+
updatedAt: Date;
|
|
40
|
+
/** @internal */
|
|
41
|
+
constructor(data: RoleData);
|
|
42
|
+
/** Apply raw API data to this role instance, updating all mutable fields. */
|
|
43
|
+
applyData(data: RoleData): void;
|
|
44
|
+
}
|
|
45
|
+
/** Fields accepted when creating a role. */
|
|
46
|
+
export interface CreateRolePayload {
|
|
47
|
+
title: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
color?: ResourceColor;
|
|
50
|
+
notes?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Fields accepted when updating a role. All optional. */
|
|
53
|
+
export interface UpdateRolePayload {
|
|
54
|
+
title?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
color?: ResourceColor;
|
|
57
|
+
notes?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Typed events emitted by {@link RolesNamespace}. */
|
|
60
|
+
export interface RoleEvents {
|
|
61
|
+
created: Role;
|
|
62
|
+
updated: Role;
|
|
63
|
+
deleted: NanoID;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Manages the permission grants attached to a specific role.
|
|
67
|
+
*
|
|
68
|
+
* Access via `api.roles.permissions(roleId)`.
|
|
69
|
+
*/
|
|
70
|
+
export declare class RolePermissionsManager {
|
|
71
|
+
private readonly roleId;
|
|
72
|
+
private readonly http;
|
|
73
|
+
/** @internal */
|
|
74
|
+
constructor(roleId: NanoID, http: HttpClient);
|
|
75
|
+
/** List the role's direct permission grants. */
|
|
76
|
+
list(): Promise<PermissionGrant[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Grant one or more permissions to the role.
|
|
79
|
+
*
|
|
80
|
+
* Re-granting an existing `(permission, scope)` updates it. You cannot grant a
|
|
81
|
+
* permission you do not hold yourself at the target scope.
|
|
82
|
+
*/
|
|
83
|
+
grant(grants: PermissionGrantInput | PermissionGrantInput[]): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Revoke a permission from the role.
|
|
86
|
+
*
|
|
87
|
+
* @param permission The permission name to revoke.
|
|
88
|
+
* @param scope The namespaced scope (`"<type>:<id>"`) to revoke at, or omit for the global grant.
|
|
89
|
+
*/
|
|
90
|
+
revoke(permission: string, scope?: string): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Namespace for role management.
|
|
94
|
+
*
|
|
95
|
+
* Access via `api.roles`.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts ignore
|
|
99
|
+
* const roles = await api.roles.list();
|
|
100
|
+
* const role = await api.roles.create({ title: 'Support', color: 'blue' });
|
|
101
|
+
* await api.roles.permissions(role.id).grant({ permission: 'server.console.read' });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare class RolesNamespace extends ResourceNamespace<Role, RoleEvents> {
|
|
105
|
+
/** @internal */
|
|
106
|
+
constructor(http: HttpClient);
|
|
107
|
+
/**
|
|
108
|
+
* Fetch a paginated list of roles.
|
|
109
|
+
*
|
|
110
|
+
* @param opts Pagination and search options.
|
|
111
|
+
*/
|
|
112
|
+
list(opts?: {
|
|
113
|
+
page?: number;
|
|
114
|
+
perPage?: number;
|
|
115
|
+
search?: string;
|
|
116
|
+
}): Promise<Paginated<Role>>;
|
|
117
|
+
/** Fetch a single role by ID. */
|
|
118
|
+
get(id: NanoID): Promise<Role>;
|
|
119
|
+
/** Create a new role. */
|
|
120
|
+
create(payload: CreateRolePayload): Promise<Role>;
|
|
121
|
+
/** Update a role's title, description, color, or notes. */
|
|
122
|
+
update(id: NanoID, payload: UpdateRolePayload): Promise<Role>;
|
|
123
|
+
/** Delete a role. Fails if the role is still assigned to any actor. */
|
|
124
|
+
delete(id: NanoID): Promise<void>;
|
|
125
|
+
/** Manage the permission grants attached to a role. */
|
|
126
|
+
permissions(roleId: NanoID): RolePermissionsManager;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../src/src/resources/roles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAY,MAAM,aAAa,CAAC;AACt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