@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
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import { ResourceNamespace } from '../namespace.js';
|
|
3
|
+
import { ReactiveResource } from '../reactive.js';
|
|
4
|
+
import type { IncludeOptions, ResourceColor, ResourceWith } from '../types.js';
|
|
5
|
+
import { type ISODate, type NanoID, type Paginated } from '../types.js';
|
|
6
|
+
import { type PermissionGrant, type PermissionGrantInput } from './permissions.js';
|
|
7
|
+
/** A UI theme preference. */
|
|
8
|
+
export type UiTheme = 'system' | 'dark' | 'light';
|
|
9
|
+
/** Raw API shape for a user's preferences. @internal */
|
|
10
|
+
export interface UserPreferencesData {
|
|
11
|
+
theme: UiTheme;
|
|
12
|
+
language: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** Raw API shape for a user's identifiers. @internal */
|
|
15
|
+
export interface UserIdentifiersData {
|
|
16
|
+
password: {
|
|
17
|
+
created_at: ISODate;
|
|
18
|
+
last_used_at: ISODate | null;
|
|
19
|
+
} | null;
|
|
20
|
+
whmcs: {
|
|
21
|
+
whmcs_id: string;
|
|
22
|
+
email: string;
|
|
23
|
+
name: string;
|
|
24
|
+
sync_email: boolean;
|
|
25
|
+
sync_nickname: boolean;
|
|
26
|
+
last_used_at: ISODate | null;
|
|
27
|
+
created_at: ISODate;
|
|
28
|
+
updated_at: ISODate;
|
|
29
|
+
} | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Raw API response shape for a user.
|
|
33
|
+
*
|
|
34
|
+
* A direct `/users` response carries a bare `id`. When the same user is
|
|
35
|
+
* expanded as an issuer reference (e.g. an `owner`), `id` is the namespaced
|
|
36
|
+
* `"user:<id>"` form and `ref_id` holds the bare id.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export interface UserData {
|
|
40
|
+
id: string;
|
|
41
|
+
type?: string;
|
|
42
|
+
ref_id?: string;
|
|
43
|
+
email: string;
|
|
44
|
+
email_verified_at?: ISODate | null;
|
|
45
|
+
nickname: string | null;
|
|
46
|
+
avatar_uri: string | null;
|
|
47
|
+
disabled_at?: ISODate | null;
|
|
48
|
+
preferences?: UserPreferencesData | null;
|
|
49
|
+
permissions?: string[];
|
|
50
|
+
identifiers?: UserIdentifiersData | null;
|
|
51
|
+
created_at: ISODate;
|
|
52
|
+
updated_at: ISODate;
|
|
53
|
+
}
|
|
54
|
+
/** Display and locale preferences for a user. */
|
|
55
|
+
export interface UserPreferences {
|
|
56
|
+
/** The user's preferred UI theme. */
|
|
57
|
+
theme: UiTheme;
|
|
58
|
+
/** The user's preferred UI language code, or `null` to follow the default. */
|
|
59
|
+
language: string | null;
|
|
60
|
+
}
|
|
61
|
+
/** The password identifier on a user. */
|
|
62
|
+
export interface UserPasswordIdentifier {
|
|
63
|
+
/** When the password was first set. */
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
/** When the password was last used to log in, or `null`. */
|
|
66
|
+
lastUsedAt: Date | null;
|
|
67
|
+
}
|
|
68
|
+
/** The WHMCS link on a user. */
|
|
69
|
+
export interface UserWhmcsIdentifier {
|
|
70
|
+
/** The linked WHMCS client UUID. */
|
|
71
|
+
whmcsId: string;
|
|
72
|
+
/** Email cached from WHMCS. */
|
|
73
|
+
email: string;
|
|
74
|
+
/** Name cached from WHMCS. */
|
|
75
|
+
name: string;
|
|
76
|
+
/** Whether WHMCS email changes sync to the account. */
|
|
77
|
+
syncEmail: boolean;
|
|
78
|
+
/** Whether WHMCS name changes sync to the nickname. */
|
|
79
|
+
syncNickname: boolean;
|
|
80
|
+
/** When this link was last used to log in, or `null`. */
|
|
81
|
+
lastUsedAt: Date | null;
|
|
82
|
+
/** When this link was created. */
|
|
83
|
+
createdAt: Date;
|
|
84
|
+
/** When this link was last updated. */
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
}
|
|
87
|
+
/** A user's external identifiers. Requires `?include=identifiers`. */
|
|
88
|
+
export interface UserIdentifiers {
|
|
89
|
+
/** The password identifier, or `null` if the user has no password. */
|
|
90
|
+
password: UserPasswordIdentifier | null;
|
|
91
|
+
/** The WHMCS link, or `null` if the user is not linked. */
|
|
92
|
+
whmcs: UserWhmcsIdentifier | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A MeowPanel user account.
|
|
96
|
+
*
|
|
97
|
+
* Retrieved via {@link UsersNamespace.get} or {@link UsersNamespace.list}.
|
|
98
|
+
*/
|
|
99
|
+
export declare class User extends ReactiveResource {
|
|
100
|
+
/** The user's unique NanoID. */
|
|
101
|
+
readonly id: NanoID;
|
|
102
|
+
/** The issuer type, `'user'` for user accounts. */
|
|
103
|
+
issuerType: string;
|
|
104
|
+
/** The user's login email address. */
|
|
105
|
+
email: string;
|
|
106
|
+
/** When the user verified their email, or `null` if unverified. */
|
|
107
|
+
emailVerifiedAt: Date | null;
|
|
108
|
+
/** The user's display nickname. */
|
|
109
|
+
nickname: string | null;
|
|
110
|
+
/** URL of the user's avatar image, or `null` if no avatar is set. */
|
|
111
|
+
avatarUri: string | null;
|
|
112
|
+
/** When the user account was disabled, or `null` if active. */
|
|
113
|
+
disabledAt: Date | null;
|
|
114
|
+
/** Display and locale preferences. Requires `?include=preferences`. */
|
|
115
|
+
preferences: UserPreferences | null | undefined;
|
|
116
|
+
/** The user's assigned permission scopes. Requires `?include=permissions`. */
|
|
117
|
+
permissions: string[] | undefined;
|
|
118
|
+
/** The user's external identifiers. Requires `?include=identifiers`. */
|
|
119
|
+
identifiers: UserIdentifiers | undefined;
|
|
120
|
+
/** When this user account was created. */
|
|
121
|
+
createdAt: Date;
|
|
122
|
+
/** When this user account was last updated. */
|
|
123
|
+
updatedAt: Date;
|
|
124
|
+
/** @internal */
|
|
125
|
+
constructor(data: UserData);
|
|
126
|
+
/**
|
|
127
|
+
* Apply raw API data to this user instance, updating all mutable fields.
|
|
128
|
+
*
|
|
129
|
+
* Called by the constructor and by {@link UsersNamespace.update} to update the instance in-place.
|
|
130
|
+
*/
|
|
131
|
+
applyData(data: UserData): void;
|
|
132
|
+
}
|
|
133
|
+
/** Fields accepted when creating a user. */
|
|
134
|
+
export interface CreateUserPayload {
|
|
135
|
+
/** Login email address. */
|
|
136
|
+
email: string;
|
|
137
|
+
/** Display nickname. */
|
|
138
|
+
nickname?: string;
|
|
139
|
+
/** Mark the email as already verified. */
|
|
140
|
+
emailVerified?: boolean;
|
|
141
|
+
/** Link a WHMCS client at creation time. */
|
|
142
|
+
whmcs?: {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Fields that can be updated on a user. All fields are optional. */
|
|
148
|
+
export interface UpdateUserPayload {
|
|
149
|
+
/** New email address for the user. */
|
|
150
|
+
email?: string;
|
|
151
|
+
/** New display nickname. */
|
|
152
|
+
nickname?: string;
|
|
153
|
+
/** Preference updates (shallow-merged). */
|
|
154
|
+
preferences?: {
|
|
155
|
+
/** UI theme. */
|
|
156
|
+
theme?: UiTheme;
|
|
157
|
+
/** UI language code, or `null` to clear. */
|
|
158
|
+
language?: string | null;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** Result of syncing a WHMCS-linked user. */
|
|
162
|
+
export interface WhmcsSyncResult {
|
|
163
|
+
/** The updated user. */
|
|
164
|
+
user: User;
|
|
165
|
+
/** Fields that were not propagated to the account (sync disabled or overridden). */
|
|
166
|
+
skipped: string[];
|
|
167
|
+
}
|
|
168
|
+
/** Valid include keys for user endpoints. */
|
|
169
|
+
export type UserInclude = 'preferences' | 'permissions' | 'identifiers';
|
|
170
|
+
/** Maps each {@link UserInclude} key to the field(s) it guarantees on the {@link User} instance. */
|
|
171
|
+
interface UserIncludeMap {
|
|
172
|
+
preferences: {
|
|
173
|
+
preferences: UserPreferences | null;
|
|
174
|
+
};
|
|
175
|
+
permissions: {
|
|
176
|
+
permissions: string[];
|
|
177
|
+
};
|
|
178
|
+
identifiers: {
|
|
179
|
+
identifiers: UserIdentifiers;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** A {@link User} with specific include fields guaranteed to be populated. */
|
|
183
|
+
export type UserWith<I extends readonly UserInclude[] = []> = ResourceWith<User, UserIncludeMap, I>;
|
|
184
|
+
/** Typed events emitted by {@link UsersNamespace}. */
|
|
185
|
+
export interface UserEvents {
|
|
186
|
+
/** Fired after a user is created. */
|
|
187
|
+
created: User;
|
|
188
|
+
/** Fired after a user is successfully updated. */
|
|
189
|
+
updated: User;
|
|
190
|
+
}
|
|
191
|
+
/** A role assigned to a user, with its assignment order and scope. */
|
|
192
|
+
export interface UserRoleAssignment {
|
|
193
|
+
/** The role's NanoID. */
|
|
194
|
+
id: NanoID;
|
|
195
|
+
/** The role title. */
|
|
196
|
+
title: string;
|
|
197
|
+
/** The role description. */
|
|
198
|
+
description: string | null;
|
|
199
|
+
/** The role color. */
|
|
200
|
+
color: ResourceColor | null;
|
|
201
|
+
/** The assignment's sort order, or `null`. */
|
|
202
|
+
order: number | null;
|
|
203
|
+
/** The namespaced scope the assignment is narrowed to, or `null` for all. */
|
|
204
|
+
scope: string | null;
|
|
205
|
+
}
|
|
206
|
+
/** A role to assign to a user. */
|
|
207
|
+
export interface AssignRoleInput {
|
|
208
|
+
/** The role's NanoID. */
|
|
209
|
+
roleId: NanoID;
|
|
210
|
+
/** Narrow every permission the role confers to this namespaced scope (`"<type>:<id>"`). */
|
|
211
|
+
scope?: string;
|
|
212
|
+
/** Sort order for the assignment; must be unique per user. */
|
|
213
|
+
order?: number;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Manages a user's role assignments.
|
|
217
|
+
*
|
|
218
|
+
* Access via `api.users.roles(userId)`.
|
|
219
|
+
*/
|
|
220
|
+
export declare class UserRolesManager {
|
|
221
|
+
private readonly userId;
|
|
222
|
+
private readonly http;
|
|
223
|
+
/** @internal */
|
|
224
|
+
constructor(userId: NanoID, http: HttpClient);
|
|
225
|
+
/** List the roles assigned to the user. */
|
|
226
|
+
list(): Promise<UserRoleAssignment[]>;
|
|
227
|
+
/** Assign one or more roles to the user. */
|
|
228
|
+
assign(roles: AssignRoleInput | AssignRoleInput[]): Promise<void>;
|
|
229
|
+
/** Remove a role from the user. */
|
|
230
|
+
remove(roleId: NanoID): Promise<void>;
|
|
231
|
+
/** Change a role assignment's sort order. */
|
|
232
|
+
setOrder(roleId: NanoID, order: number): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Manages a user's direct permission grants.
|
|
236
|
+
*
|
|
237
|
+
* Access via `api.users.permissions(userId)`.
|
|
238
|
+
*/
|
|
239
|
+
export declare class UserPermissionsManager {
|
|
240
|
+
private readonly userId;
|
|
241
|
+
private readonly http;
|
|
242
|
+
/** @internal */
|
|
243
|
+
constructor(userId: NanoID, http: HttpClient);
|
|
244
|
+
/** List the user's direct permission grants. */
|
|
245
|
+
list(): Promise<PermissionGrant[]>;
|
|
246
|
+
/**
|
|
247
|
+
* Grant one or more permissions to the user.
|
|
248
|
+
*
|
|
249
|
+
* You cannot grant a permission you do not hold yourself at the target scope.
|
|
250
|
+
*/
|
|
251
|
+
grant(grants: PermissionGrantInput | PermissionGrantInput[]): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Revoke a permission from the user.
|
|
254
|
+
*
|
|
255
|
+
* @param permission The permission name to revoke.
|
|
256
|
+
* @param scope The namespaced scope (`"<type>:<id>"`) to revoke at, or omit for the global grant.
|
|
257
|
+
*/
|
|
258
|
+
revoke(permission: string, scope?: string): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Namespace for user management.
|
|
262
|
+
*
|
|
263
|
+
* Access via `api.users`.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts ignore
|
|
267
|
+
* const users = await api.users.list();
|
|
268
|
+
* const user = await api.users.get(id);
|
|
269
|
+
* await api.users.update(id, { nickname: 'newname' });
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export declare class UsersNamespace extends ResourceNamespace<User, UserEvents> {
|
|
273
|
+
/** @internal */
|
|
274
|
+
constructor(http: HttpClient);
|
|
275
|
+
/**
|
|
276
|
+
* Fetch a paginated list of all users.
|
|
277
|
+
*
|
|
278
|
+
* @param opts Pagination, search, and include options.
|
|
279
|
+
*/
|
|
280
|
+
list<const I extends readonly UserInclude[] = []>(opts?: {
|
|
281
|
+
page?: number;
|
|
282
|
+
perPage?: number;
|
|
283
|
+
search?: string;
|
|
284
|
+
} & IncludeOptions<UserInclude, I>): Promise<Paginated<UserWith<I>>>;
|
|
285
|
+
/**
|
|
286
|
+
* Fetch a single user by ID.
|
|
287
|
+
*
|
|
288
|
+
* @param id The user's NanoID.
|
|
289
|
+
* @param opts Include options.
|
|
290
|
+
*/
|
|
291
|
+
get<const I extends readonly UserInclude[] = []>(id: NanoID, opts?: IncludeOptions<UserInclude, I>): Promise<UserWith<I>>;
|
|
292
|
+
/** Create a user. */
|
|
293
|
+
create(payload: CreateUserPayload): Promise<User>;
|
|
294
|
+
/**
|
|
295
|
+
* Update a user's profile fields.
|
|
296
|
+
*
|
|
297
|
+
* @param id The user's NanoID.
|
|
298
|
+
* @param payload The fields to update.
|
|
299
|
+
*/
|
|
300
|
+
update(id: NanoID, payload: UpdateUserPayload): Promise<User>;
|
|
301
|
+
/** Disable a user, blocking them from authenticating. */
|
|
302
|
+
disable(id: NanoID): Promise<void>;
|
|
303
|
+
/** Re-enable a disabled user. */
|
|
304
|
+
enable(id: NanoID): Promise<void>;
|
|
305
|
+
/**
|
|
306
|
+
* Propagate WHMCS-sourced changes to the linked user.
|
|
307
|
+
*
|
|
308
|
+
* @param whmcsId The linked WHMCS client UUID.
|
|
309
|
+
* @param payload The WHMCS-side email and/or name.
|
|
310
|
+
*/
|
|
311
|
+
syncWhmcs(whmcsId: string, payload: {
|
|
312
|
+
email?: string;
|
|
313
|
+
name?: string;
|
|
314
|
+
}): Promise<WhmcsSyncResult>;
|
|
315
|
+
/**
|
|
316
|
+
* Unlink a WHMCS-linked user.
|
|
317
|
+
*
|
|
318
|
+
* @param whmcsId The linked WHMCS client UUID.
|
|
319
|
+
* @param opts `unlink: true` only removes the link; otherwise the user is also disabled.
|
|
320
|
+
*/
|
|
321
|
+
unlinkWhmcs(whmcsId: string, opts?: {
|
|
322
|
+
unlink?: boolean;
|
|
323
|
+
}): Promise<User>;
|
|
324
|
+
/** Manage a user's role assignments. */
|
|
325
|
+
roles(userId: NanoID): UserRolesManager;
|
|
326
|
+
/** Manage a user's direct permission grants. */
|
|
327
|
+
permissions(userId: NanoID): UserPermissionsManager;
|
|
328
|
+
}
|
|
329
|
+
export {};
|
|
330
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/src/resources/users.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,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,KAAK,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,SAAS,EAA4B,MAAM,aAAa,CAAC;AAChH,OAAO,EAGN,KAAK,eAAe,EAEpB,KAAK,oBAAoB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,6BAA6B;AAC7B,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACvE,KAAK,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,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I,CAAC;IAc9D;;;;;OAKG;IACU,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1E,yDAAyD;IAC5C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,iCAAiC;IACpB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;;;;OAKG;IACU,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ7G;;;;;OAKG;IACU,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzF,wCAAwC;IACjC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAI9C,gDAAgD;IACzC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;CAG1D"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsersNamespace = exports.UserPermissionsManager = exports.UserRolesManager = exports.User = void 0;
|
|
4
|
+
const namespace_js_1 = require("../namespace.js");
|
|
5
|
+
const reactive_js_1 = require("../reactive.js");
|
|
6
|
+
const types_js_1 = require("../types.js");
|
|
7
|
+
const permissions_js_1 = require("./permissions.js");
|
|
8
|
+
/**
|
|
9
|
+
* A MeowPanel user account.
|
|
10
|
+
*
|
|
11
|
+
* Retrieved via {@link UsersNamespace.get} or {@link UsersNamespace.list}.
|
|
12
|
+
*/
|
|
13
|
+
class User extends reactive_js_1.ReactiveResource {
|
|
14
|
+
/** The user's unique NanoID. */
|
|
15
|
+
id;
|
|
16
|
+
/** The issuer type, `'user'` for user accounts. */
|
|
17
|
+
issuerType;
|
|
18
|
+
/** The user's login email address. */
|
|
19
|
+
email;
|
|
20
|
+
/** When the user verified their email, or `null` if unverified. */
|
|
21
|
+
emailVerifiedAt;
|
|
22
|
+
/** The user's display nickname. */
|
|
23
|
+
nickname;
|
|
24
|
+
/** URL of the user's avatar image, or `null` if no avatar is set. */
|
|
25
|
+
avatarUri;
|
|
26
|
+
/** When the user account was disabled, or `null` if active. */
|
|
27
|
+
disabledAt;
|
|
28
|
+
/** Display and locale preferences. Requires `?include=preferences`. */
|
|
29
|
+
preferences;
|
|
30
|
+
/** The user's assigned permission scopes. Requires `?include=permissions`. */
|
|
31
|
+
permissions;
|
|
32
|
+
/** The user's external identifiers. Requires `?include=identifiers`. */
|
|
33
|
+
identifiers;
|
|
34
|
+
/** When this user account was created. */
|
|
35
|
+
createdAt;
|
|
36
|
+
/** When this user account was last updated. */
|
|
37
|
+
updatedAt;
|
|
38
|
+
/** @internal */
|
|
39
|
+
constructor(data) {
|
|
40
|
+
super();
|
|
41
|
+
this.id = data.ref_id ? (0, types_js_1.toNanoID)(data.ref_id) : (0, types_js_1.parseIssuerRef)(data.id).id;
|
|
42
|
+
this.applyData(data);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Apply raw API data to this user instance, updating all mutable fields.
|
|
46
|
+
*
|
|
47
|
+
* Called by the constructor and by {@link UsersNamespace.update} to update the instance in-place.
|
|
48
|
+
*/
|
|
49
|
+
applyData(data) {
|
|
50
|
+
this.issuerType = data.type ?? 'user';
|
|
51
|
+
this.email = data.email;
|
|
52
|
+
this.emailVerifiedAt = data.email_verified_at ? new Date(data.email_verified_at) : null;
|
|
53
|
+
this.nickname = data.nickname;
|
|
54
|
+
this.avatarUri = data.avatar_uri;
|
|
55
|
+
this.disabledAt = data.disabled_at ? new Date(data.disabled_at) : null;
|
|
56
|
+
this.preferences = data.preferences ?? undefined;
|
|
57
|
+
this.permissions = data.permissions;
|
|
58
|
+
this.identifiers = data.identifiers ? parseIdentifiers(data.identifiers) : undefined;
|
|
59
|
+
this.createdAt = new Date(data.created_at);
|
|
60
|
+
this.updatedAt = new Date(data.updated_at);
|
|
61
|
+
this.notify();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.User = User;
|
|
65
|
+
function parseIdentifiers(data) {
|
|
66
|
+
return {
|
|
67
|
+
password: data.password
|
|
68
|
+
? {
|
|
69
|
+
createdAt: new Date(data.password.created_at),
|
|
70
|
+
lastUsedAt: data.password.last_used_at ? new Date(data.password.last_used_at) : null,
|
|
71
|
+
}
|
|
72
|
+
: null,
|
|
73
|
+
whmcs: data.whmcs
|
|
74
|
+
? {
|
|
75
|
+
whmcsId: data.whmcs.whmcs_id,
|
|
76
|
+
email: data.whmcs.email,
|
|
77
|
+
name: data.whmcs.name,
|
|
78
|
+
syncEmail: data.whmcs.sync_email,
|
|
79
|
+
syncNickname: data.whmcs.sync_nickname,
|
|
80
|
+
lastUsedAt: data.whmcs.last_used_at ? new Date(data.whmcs.last_used_at) : null,
|
|
81
|
+
createdAt: new Date(data.whmcs.created_at),
|
|
82
|
+
updatedAt: new Date(data.whmcs.updated_at),
|
|
83
|
+
}
|
|
84
|
+
: null,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Manages a user's role assignments.
|
|
89
|
+
*
|
|
90
|
+
* Access via `api.users.roles(userId)`.
|
|
91
|
+
*/
|
|
92
|
+
class UserRolesManager {
|
|
93
|
+
userId;
|
|
94
|
+
http;
|
|
95
|
+
/** @internal */
|
|
96
|
+
constructor(userId, http) {
|
|
97
|
+
this.userId = userId;
|
|
98
|
+
this.http = http;
|
|
99
|
+
}
|
|
100
|
+
/** List the roles assigned to the user. */
|
|
101
|
+
async list() {
|
|
102
|
+
const data = await this.http.get(`/users/${this.userId}/roles`);
|
|
103
|
+
return data.map((d) => ({
|
|
104
|
+
id: (0, types_js_1.toNanoID)(d.id),
|
|
105
|
+
title: d.title,
|
|
106
|
+
description: d.description,
|
|
107
|
+
color: d.color,
|
|
108
|
+
order: d.order,
|
|
109
|
+
scope: d.scope,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
/** Assign one or more roles to the user. */
|
|
113
|
+
async assign(roles) {
|
|
114
|
+
const body = (Array.isArray(roles) ? roles : [roles]).map((r) => ({
|
|
115
|
+
role_id: r.roleId,
|
|
116
|
+
scope: r.scope,
|
|
117
|
+
order: r.order,
|
|
118
|
+
}));
|
|
119
|
+
await this.http.post(`/users/${this.userId}/roles`, body);
|
|
120
|
+
}
|
|
121
|
+
/** Remove a role from the user. */
|
|
122
|
+
async remove(roleId) {
|
|
123
|
+
await this.http.delete(`/users/${this.userId}/roles/${roleId}`);
|
|
124
|
+
}
|
|
125
|
+
/** Change a role assignment's sort order. */
|
|
126
|
+
async setOrder(roleId, order) {
|
|
127
|
+
await this.http.patch(`/users/${this.userId}/roles/${roleId}`, { order });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.UserRolesManager = UserRolesManager;
|
|
131
|
+
/**
|
|
132
|
+
* Manages a user's direct permission grants.
|
|
133
|
+
*
|
|
134
|
+
* Access via `api.users.permissions(userId)`.
|
|
135
|
+
*/
|
|
136
|
+
class UserPermissionsManager {
|
|
137
|
+
userId;
|
|
138
|
+
http;
|
|
139
|
+
/** @internal */
|
|
140
|
+
constructor(userId, http) {
|
|
141
|
+
this.userId = userId;
|
|
142
|
+
this.http = http;
|
|
143
|
+
}
|
|
144
|
+
/** List the user's direct permission grants. */
|
|
145
|
+
async list() {
|
|
146
|
+
const data = await this.http.get(`/users/${this.userId}/permissions`);
|
|
147
|
+
return data.map(permissions_js_1.parseGrant);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Grant one or more permissions to the user.
|
|
151
|
+
*
|
|
152
|
+
* You cannot grant a permission you do not hold yourself at the target scope.
|
|
153
|
+
*/
|
|
154
|
+
async grant(grants) {
|
|
155
|
+
await this.http.post(`/users/${this.userId}/permissions`, (0, permissions_js_1.grantsToBody)(grants));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Revoke a permission from the user.
|
|
159
|
+
*
|
|
160
|
+
* @param permission The permission name to revoke.
|
|
161
|
+
* @param scope The namespaced scope (`"<type>:<id>"`) to revoke at, or omit for the global grant.
|
|
162
|
+
*/
|
|
163
|
+
async revoke(permission, scope) {
|
|
164
|
+
const params = scope ? { scope } : undefined;
|
|
165
|
+
await this.http.delete(`/users/${this.userId}/permissions/${encodeURIComponent(permission)}`, { params });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.UserPermissionsManager = UserPermissionsManager;
|
|
169
|
+
/**
|
|
170
|
+
* Namespace for user management.
|
|
171
|
+
*
|
|
172
|
+
* Access via `api.users`.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts ignore
|
|
176
|
+
* const users = await api.users.list();
|
|
177
|
+
* const user = await api.users.get(id);
|
|
178
|
+
* await api.users.update(id, { nickname: 'newname' });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
class UsersNamespace extends namespace_js_1.ResourceNamespace {
|
|
182
|
+
/** @internal */
|
|
183
|
+
constructor(http) {
|
|
184
|
+
super(http);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Fetch a paginated list of all users.
|
|
188
|
+
*
|
|
189
|
+
* @param opts Pagination, search, and include options.
|
|
190
|
+
*/
|
|
191
|
+
async list(opts = {}) {
|
|
192
|
+
const extra = {};
|
|
193
|
+
const include = (0, types_js_1.joinIncludes)(opts);
|
|
194
|
+
if (include)
|
|
195
|
+
extra['include'] = include;
|
|
196
|
+
const result = await this.http.list('/users', opts, extra);
|
|
197
|
+
const users = result.data.map((d) => new User(d));
|
|
198
|
+
this.setCache(users);
|
|
199
|
+
return { ...result, data: users };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Fetch a single user by ID.
|
|
203
|
+
*
|
|
204
|
+
* @param id The user's NanoID.
|
|
205
|
+
* @param opts Include options.
|
|
206
|
+
*/
|
|
207
|
+
async get(id, opts = {}) {
|
|
208
|
+
const params = {};
|
|
209
|
+
const include = (0, types_js_1.joinIncludes)(opts);
|
|
210
|
+
if (include)
|
|
211
|
+
params['include'] = include;
|
|
212
|
+
const data = await this.http.get(`/users/${id}`, { params });
|
|
213
|
+
return new User(data);
|
|
214
|
+
}
|
|
215
|
+
/** Create a user. */
|
|
216
|
+
async create(payload) {
|
|
217
|
+
const body = {
|
|
218
|
+
email: payload.email,
|
|
219
|
+
nickname: payload.nickname,
|
|
220
|
+
email_verified: payload.emailVerified,
|
|
221
|
+
identifiers: payload.whmcs ? { whmcs: { id: payload.whmcs.id, name: payload.whmcs.name } } : undefined,
|
|
222
|
+
};
|
|
223
|
+
const data = await this.http.post('/users', body);
|
|
224
|
+
const user = new User(data);
|
|
225
|
+
this.addToCache(user);
|
|
226
|
+
this.emit('created', user);
|
|
227
|
+
return user;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Update a user's profile fields.
|
|
231
|
+
*
|
|
232
|
+
* @param id The user's NanoID.
|
|
233
|
+
* @param payload The fields to update.
|
|
234
|
+
*/
|
|
235
|
+
async update(id, payload) {
|
|
236
|
+
const data = await this.http.patch(`/users/${id}`, payload);
|
|
237
|
+
const existing = this.cache.find((u) => u.id === id);
|
|
238
|
+
if (existing) {
|
|
239
|
+
existing.applyData(data);
|
|
240
|
+
this.upsertCache(existing);
|
|
241
|
+
this.emit('updated', existing);
|
|
242
|
+
return existing;
|
|
243
|
+
}
|
|
244
|
+
const user = new User(data);
|
|
245
|
+
this.upsertCache(user);
|
|
246
|
+
this.emit('updated', user);
|
|
247
|
+
return user;
|
|
248
|
+
}
|
|
249
|
+
/** Disable a user, blocking them from authenticating. */
|
|
250
|
+
async disable(id) {
|
|
251
|
+
await this.http.post(`/users/${id}/disable`);
|
|
252
|
+
}
|
|
253
|
+
/** Re-enable a disabled user. */
|
|
254
|
+
async enable(id) {
|
|
255
|
+
await this.http.post(`/users/${id}/enable`);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Propagate WHMCS-sourced changes to the linked user.
|
|
259
|
+
*
|
|
260
|
+
* @param whmcsId The linked WHMCS client UUID.
|
|
261
|
+
* @param payload The WHMCS-side email and/or name.
|
|
262
|
+
*/
|
|
263
|
+
async syncWhmcs(whmcsId, payload) {
|
|
264
|
+
const data = await this.http.patch(`/users/whmcs/${encodeURIComponent(whmcsId)}`, payload);
|
|
265
|
+
return { user: new User(data.user), skipped: data.skipped };
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Unlink a WHMCS-linked user.
|
|
269
|
+
*
|
|
270
|
+
* @param whmcsId The linked WHMCS client UUID.
|
|
271
|
+
* @param opts `unlink: true` only removes the link; otherwise the user is also disabled.
|
|
272
|
+
*/
|
|
273
|
+
async unlinkWhmcs(whmcsId, opts = {}) {
|
|
274
|
+
const params = opts.unlink ? { unlink: 'true' } : undefined;
|
|
275
|
+
const data = await this.http.delete(`/users/whmcs/${encodeURIComponent(whmcsId)}`, { params });
|
|
276
|
+
return new User(data);
|
|
277
|
+
}
|
|
278
|
+
/** Manage a user's role assignments. */
|
|
279
|
+
roles(userId) {
|
|
280
|
+
return new UserRolesManager(userId, this.http);
|
|
281
|
+
}
|
|
282
|
+
/** Manage a user's direct permission grants. */
|
|
283
|
+
permissions(userId) {
|
|
284
|
+
return new UserPermissionsManager(userId, this.http);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.UsersNamespace = UsersNamespace;
|
package/script/src/types.d.ts
CHANGED
|
@@ -22,6 +22,23 @@ export type NanoID = string & {
|
|
|
22
22
|
export declare function toNanoID(raw: string): NanoID;
|
|
23
23
|
/** ISO 8601 date-time string as returned by the MeowPanel API, e.g. `"2024-01-15T12:00:00.000Z"`. */
|
|
24
24
|
export type ISODate = string;
|
|
25
|
+
/** A UI color label used for visual grouping (hosts, roles). */
|
|
26
|
+
export type ResourceColor = 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink' | 'brown' | 'black' | 'white';
|
|
27
|
+
/** A namespaced issuer reference, e.g. `"user:abc123def456"`. */
|
|
28
|
+
export type IssuerRef = string;
|
|
29
|
+
/** The parsed parts of an {@link IssuerRef}. */
|
|
30
|
+
export interface ParsedIssuer {
|
|
31
|
+
/** The issuer type token, e.g. `"user"`, `"system"`, `"api_key"`, `"node"`. */
|
|
32
|
+
type: string;
|
|
33
|
+
/** The bare resource NanoID. */
|
|
34
|
+
id: NanoID;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Split a namespaced issuer reference (`"<type>:<id>"`) into its type and bare id.
|
|
38
|
+
*
|
|
39
|
+
* A bare id with no prefix yields an empty `type`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseIssuerRef(ref: string): ParsedIssuer;
|
|
25
42
|
/** Options for paginated list requests. */
|
|
26
43
|
export interface ListOptions {
|
|
27
44
|
/** Page number (1-based). Defaults to 1. */
|
|
@@ -122,5 +139,5 @@ export type ServerRestrictedState = 'installing' | 'install_failed' | 'restoring
|
|
|
122
139
|
/**
|
|
123
140
|
* An SFTP permission scope that can be assigned to a path pattern for an SFTP user.
|
|
124
141
|
*/
|
|
125
|
-
export type SftpPermission = '
|
|
142
|
+
export type SftpPermission = 'server.file.list' | 'server.file.read' | 'server.file.create' | 'server.file.manage' | 'server.file.delete';
|
|
126
143
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAEnE;;;;;;;GAOG;AACH,wBAAgB,QAAQ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