@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,81 @@
|
|
|
1
|
+
import type { HttpClient } from '../../http.js';
|
|
2
|
+
import type { NanoID } from '../../types.js';
|
|
3
|
+
/** Where a feature's availability comes from, resolved most-specific-wins. */
|
|
4
|
+
export type FeatureSource = 'server' | 'egg' | 'node';
|
|
5
|
+
/** Where an effective setting value comes from. `server` is a client override, `feature` is the default. */
|
|
6
|
+
export type FeatureSettingSource = 'server' | 'feature';
|
|
7
|
+
/** One resolved setting of an effective feature. */
|
|
8
|
+
export interface FeatureSetting {
|
|
9
|
+
/** The effective resolved value. */
|
|
10
|
+
value: unknown;
|
|
11
|
+
/** Whether the value is a client override (`server`) or the feature default (`feature`). */
|
|
12
|
+
source: FeatureSettingSource;
|
|
13
|
+
/** The feature's code-defined default for this setting. */
|
|
14
|
+
default: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** A feature as it applies to a specific server, with its resolved settings. */
|
|
17
|
+
export interface EffectiveFeature {
|
|
18
|
+
/** The feature key, e.g. `"minecraft.players"`. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Whether the feature is enabled for this server. */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** When `true`, the enabled state is fixed and cannot be toggled. */
|
|
23
|
+
locked: boolean;
|
|
24
|
+
/** Where the feature's availability is granted from. */
|
|
25
|
+
source: FeatureSource;
|
|
26
|
+
/** The selected variant, or `null` when the feature has none. */
|
|
27
|
+
variant: string | null;
|
|
28
|
+
/** Resolved settings, keyed by setting name. */
|
|
29
|
+
settings: Record<string, FeatureSetting>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Manages the feature configuration of a specific server.
|
|
33
|
+
*
|
|
34
|
+
* Access via `server.features`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts ignore
|
|
38
|
+
* const features = await server.features.list();
|
|
39
|
+
* await server.features.setEnabled('minecraft.players', true);
|
|
40
|
+
* await server.features.update('minecraft.players', { settings: { show_players_online: false } });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class ServerFeaturesManager {
|
|
44
|
+
private readonly serverId;
|
|
45
|
+
private readonly http;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(serverId: NanoID, http: HttpClient);
|
|
48
|
+
/** List the features available to this server, with their resolved state. */
|
|
49
|
+
list(): Promise<EffectiveFeature[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch a single feature's resolved state.
|
|
52
|
+
*
|
|
53
|
+
* @throws {@link ApiError} with `isNotFound === true` if the feature is not available to the server.
|
|
54
|
+
*/
|
|
55
|
+
get(feature: string): Promise<EffectiveFeature>;
|
|
56
|
+
/**
|
|
57
|
+
* Update a feature's settings or variant.
|
|
58
|
+
*
|
|
59
|
+
* A `null` setting value, or a `null` variant, resets it to the feature default.
|
|
60
|
+
*
|
|
61
|
+
* @param feature The feature key.
|
|
62
|
+
* @param payload The settings and/or variant to change.
|
|
63
|
+
*/
|
|
64
|
+
update(feature: string, payload: {
|
|
65
|
+
settings?: Record<string, unknown>;
|
|
66
|
+
variant?: string | null;
|
|
67
|
+
}): Promise<EffectiveFeature>;
|
|
68
|
+
/**
|
|
69
|
+
* Enable or disable a feature.
|
|
70
|
+
*
|
|
71
|
+
* @throws {@link ApiError} with `isForbidden === true` if the feature is locked.
|
|
72
|
+
*/
|
|
73
|
+
setEnabled(feature: string, enabled: boolean): Promise<EffectiveFeature>;
|
|
74
|
+
/**
|
|
75
|
+
* Enable or disable several features at once.
|
|
76
|
+
*
|
|
77
|
+
* @param features A map of feature key to desired enabled state.
|
|
78
|
+
*/
|
|
79
|
+
setEnabledBulk(features: Record<string, boolean>): Promise<EffectiveFeature[]>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEtD,4GAA4G;AAC5G,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExD,oDAAoD;AACpD,MAAM,WAAW,cAAc;IAC9B,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,4FAA4F;IAC5F,MAAM,EAAE,oBAAoB,CAAC;IAC7B,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAChC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,wDAAwD;IACxD,MAAM,EAAE,aAAa,CAAC;IACtB,iEAAiE;IACjE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAqB;IAGhC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHtB,gBAAgB;gBAEE,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU;IAGlC,6EAA6E;IACtE,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI1C;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAItD;;;;;;;OAOG;IACI,MAAM,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACtE,OAAO,CAAC,gBAAgB,CAAC;IAO5B;;;;OAIG;IACI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAO/E;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAGrF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the feature configuration of a specific server.
|
|
3
|
+
*
|
|
4
|
+
* Access via `server.features`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts ignore
|
|
8
|
+
* const features = await server.features.list();
|
|
9
|
+
* await server.features.setEnabled('minecraft.players', true);
|
|
10
|
+
* await server.features.update('minecraft.players', { settings: { show_players_online: false } });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export class ServerFeaturesManager {
|
|
14
|
+
serverId;
|
|
15
|
+
http;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(serverId, http) {
|
|
18
|
+
this.serverId = serverId;
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/** List the features available to this server, with their resolved state. */
|
|
22
|
+
list() {
|
|
23
|
+
return this.http.get(`/servers/${this.serverId}/features`);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch a single feature's resolved state.
|
|
27
|
+
*
|
|
28
|
+
* @throws {@link ApiError} with `isNotFound === true` if the feature is not available to the server.
|
|
29
|
+
*/
|
|
30
|
+
get(feature) {
|
|
31
|
+
return this.http.get(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Update a feature's settings or variant.
|
|
35
|
+
*
|
|
36
|
+
* A `null` setting value, or a `null` variant, resets it to the feature default.
|
|
37
|
+
*
|
|
38
|
+
* @param feature The feature key.
|
|
39
|
+
* @param payload The settings and/or variant to change.
|
|
40
|
+
*/
|
|
41
|
+
update(feature, payload) {
|
|
42
|
+
return this.http.patch(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`, payload);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Enable or disable a feature.
|
|
46
|
+
*
|
|
47
|
+
* @throws {@link ApiError} with `isForbidden === true` if the feature is locked.
|
|
48
|
+
*/
|
|
49
|
+
setEnabled(feature, enabled) {
|
|
50
|
+
return this.http.post(`/servers/${this.serverId}/features/${encodeURIComponent(feature)}`, { enabled });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Enable or disable several features at once.
|
|
54
|
+
*
|
|
55
|
+
* @param features A map of feature key to desired enabled state.
|
|
56
|
+
*/
|
|
57
|
+
setEnabledBulk(features) {
|
|
58
|
+
return this.http.post(`/servers/${this.serverId}/features`, { features });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ServerJob } from './jobs.js';
|
|
2
|
+
import type { NodeClient } from './node-client.js';
|
|
2
3
|
import type { FileEntryData } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* A single file or directory entry in a server's file system.
|
|
@@ -26,58 +27,42 @@ export declare class FileEntry {
|
|
|
26
27
|
constructor(data: FileEntryData);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
* Manages file system operations for a specific server via the Whisker node daemon
|
|
30
|
+
* Manages file system operations for a specific server via the Whisker node daemon.
|
|
30
31
|
*
|
|
31
|
-
* File operations communicate directly with the node daemon.
|
|
32
|
-
*
|
|
32
|
+
* File operations communicate directly with the node daemon. Archive operations
|
|
33
|
+
* (`compress`/`decompress`) may run as a background {@link ServerJob} when they exceed
|
|
34
|
+
* the daemon's fast-path window.
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
37
|
* ```ts ignore
|
|
36
38
|
* const entries = await server.files.list('/');
|
|
37
|
-
*
|
|
38
|
-
* await server.files.
|
|
39
|
-
*
|
|
40
|
-
* await server.files.delete(['/backup.zip']);
|
|
39
|
+
* await server.files.write('/motd.txt', 'Hello World');
|
|
40
|
+
* const result = await server.files.compress(['/world'], '/');
|
|
41
|
+
* if (result instanceof ServerJob) await result.wait();
|
|
41
42
|
* ```
|
|
42
43
|
*/
|
|
43
44
|
export declare class ServerFilesManager {
|
|
44
|
-
private readonly
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* @param serverId The server's NanoID.
|
|
50
|
-
* @param token Bearer token for node authentication.
|
|
51
|
-
* @param resolveNodeUrl Async function that returns the daemon base URL for this server's node.
|
|
52
|
-
*/
|
|
53
|
-
constructor(serverId: NanoID, token: string, resolveNodeUrl: () => Promise<string>);
|
|
54
|
-
/** Lazily resolve and cache the node daemon URL. */
|
|
55
|
-
private getNodeUrl;
|
|
56
|
-
/** Build a full node API URL for a file path endpoint. */
|
|
57
|
-
private buildFileUrl;
|
|
58
|
-
/** Shared auth headers for node requests. */
|
|
59
|
-
private get authHeaders();
|
|
60
|
-
/** Perform a raw fetch to the node and throw on non-2xx. */
|
|
61
|
-
private nodeFetch;
|
|
45
|
+
private readonly node;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(node: NodeClient);
|
|
48
|
+
/** Normalize a path to an absolute `/files` endpoint. */
|
|
49
|
+
private endpoint;
|
|
62
50
|
/**
|
|
63
51
|
* List the contents of a directory.
|
|
64
52
|
*
|
|
65
53
|
* @param path Absolute path to the directory, e.g. `"/"` or `"/plugins"`.
|
|
66
|
-
* @returns An array of {@link FileEntry} objects.
|
|
67
54
|
*/
|
|
68
55
|
list(path: string): Promise<FileEntry[]>;
|
|
69
56
|
/**
|
|
70
57
|
* Read the text content of a file.
|
|
71
58
|
*
|
|
72
59
|
* @param path Absolute path to the file, e.g. `"/server.properties"`.
|
|
73
|
-
* @returns The file content as a UTF-8 string.
|
|
74
60
|
*/
|
|
75
61
|
read(path: string): Promise<string>;
|
|
76
62
|
/**
|
|
77
63
|
* Read the raw binary content of a file.
|
|
78
64
|
*
|
|
79
65
|
* @param path Absolute path to the file.
|
|
80
|
-
* @returns The file content as an `ArrayBuffer`.
|
|
81
66
|
*/
|
|
82
67
|
readBinary(path: string): Promise<ArrayBuffer>;
|
|
83
68
|
/**
|
|
@@ -106,56 +91,59 @@ export declare class ServerFilesManager {
|
|
|
106
91
|
*
|
|
107
92
|
* @param from Absolute source path.
|
|
108
93
|
* @param to Absolute destination path.
|
|
94
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
109
95
|
*/
|
|
110
|
-
move(from: string, to: string): Promise<void>;
|
|
96
|
+
move(from: string, to: string, root?: string): Promise<void>;
|
|
111
97
|
/**
|
|
112
|
-
* Copy a file or directory to a new
|
|
98
|
+
* Copy a file or directory to a new path.
|
|
113
99
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
100
|
+
* @param from Absolute source path.
|
|
101
|
+
* @param to Absolute destination path.
|
|
102
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
116
103
|
*/
|
|
117
|
-
copy(
|
|
104
|
+
copy(from: string, to: string, root?: string): Promise<void>;
|
|
118
105
|
/**
|
|
119
106
|
* Create an empty file or directory.
|
|
120
107
|
*
|
|
121
108
|
* @param path Absolute path of the new file or directory.
|
|
122
109
|
* @param directory When `true`, creates a directory instead of a file.
|
|
110
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
123
111
|
*/
|
|
124
|
-
create(path: string, directory?: boolean): Promise<void>;
|
|
112
|
+
create(path: string, directory?: boolean, root?: string): Promise<void>;
|
|
125
113
|
/**
|
|
126
|
-
* Compress one or more
|
|
114
|
+
* Compress one or more paths into a server-named archive.
|
|
115
|
+
*
|
|
116
|
+
* Resolves to a {@link FileEntry} for the created archive when the daemon finishes
|
|
117
|
+
* within its fast-path window, or a {@link ServerJob} to track when it runs longer.
|
|
127
118
|
*
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @param rootPath Root directory for resolving relative paths. Defaults to `"/"`.
|
|
119
|
+
* @param paths Absolute paths to include in the archive.
|
|
120
|
+
* @param root Root directory for resolving the paths. Defaults to `"/"`.
|
|
131
121
|
*/
|
|
132
|
-
compress(
|
|
122
|
+
compress(paths: string[], root?: string): Promise<FileEntry | ServerJob>;
|
|
133
123
|
/**
|
|
134
124
|
* Decompress (extract) an archive file.
|
|
135
125
|
*
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
126
|
+
* Resolves to `null` when the daemon finishes within its fast-path window, or a
|
|
127
|
+
* {@link ServerJob} to track when it runs longer.
|
|
128
|
+
*
|
|
129
|
+
* @param path Absolute path to the archive to extract.
|
|
130
|
+
* @param root Directory to extract the archive into. Defaults to `"/"`.
|
|
138
131
|
*/
|
|
139
|
-
decompress(
|
|
132
|
+
decompress(path: string, root?: string): Promise<ServerJob | null>;
|
|
140
133
|
/**
|
|
141
134
|
* Change the permissions (chmod) of one or more files.
|
|
142
135
|
*
|
|
143
|
-
* @param entries
|
|
144
|
-
* @param
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts ignore
|
|
148
|
-
* await server.files.chmod([{ file: 'start.sh', mode: '755' }]);
|
|
149
|
-
* ```
|
|
136
|
+
* @param entries Array of `{ file, mode }` objects, e.g. `[{ file: 'start.sh', mode: '755' }]`.
|
|
137
|
+
* @param root Root directory for resolving paths. Defaults to `"/"`.
|
|
150
138
|
*/
|
|
151
139
|
chmod(entries: {
|
|
152
140
|
file: string;
|
|
153
141
|
mode: string;
|
|
154
|
-
}[],
|
|
142
|
+
}[], root?: string): Promise<void>;
|
|
155
143
|
/**
|
|
156
|
-
* Upload a file
|
|
144
|
+
* Upload a file using multipart form data.
|
|
157
145
|
*
|
|
158
|
-
* @param path Absolute directory path to upload
|
|
146
|
+
* @param path Absolute directory path to upload into.
|
|
159
147
|
* @param filename The name for the uploaded file.
|
|
160
148
|
* @param content The file content as a `Blob`, `File`, or `ArrayBuffer`.
|
|
161
149
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/files.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServerJob } from './jobs.js';
|
|
2
2
|
/**
|
|
3
3
|
* A single file or directory entry in a server's file system.
|
|
4
4
|
*/
|
|
@@ -35,77 +35,37 @@ export class FileEntry {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Manages file system operations for a specific server via the Whisker node daemon
|
|
38
|
+
* Manages file system operations for a specific server via the Whisker node daemon.
|
|
39
39
|
*
|
|
40
|
-
* File operations communicate directly with the node daemon.
|
|
41
|
-
*
|
|
40
|
+
* File operations communicate directly with the node daemon. Archive operations
|
|
41
|
+
* (`compress`/`decompress`) may run as a background {@link ServerJob} when they exceed
|
|
42
|
+
* the daemon's fast-path window.
|
|
42
43
|
*
|
|
43
44
|
* @example
|
|
44
45
|
* ```ts ignore
|
|
45
46
|
* const entries = await server.files.list('/');
|
|
46
|
-
*
|
|
47
|
-
* await server.files.
|
|
48
|
-
*
|
|
49
|
-
* await server.files.delete(['/backup.zip']);
|
|
47
|
+
* await server.files.write('/motd.txt', 'Hello World');
|
|
48
|
+
* const result = await server.files.compress(['/world'], '/');
|
|
49
|
+
* if (result instanceof ServerJob) await result.wait();
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export class ServerFilesManager {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param serverId The server's NanoID.
|
|
59
|
-
* @param token Bearer token for node authentication.
|
|
60
|
-
* @param resolveNodeUrl Async function that returns the daemon base URL for this server's node.
|
|
61
|
-
*/
|
|
62
|
-
constructor(serverId, token, resolveNodeUrl) {
|
|
63
|
-
this.serverId = serverId;
|
|
64
|
-
this.token = token;
|
|
65
|
-
this.resolveNodeUrl = resolveNodeUrl;
|
|
66
|
-
}
|
|
67
|
-
/** Lazily resolve and cache the node daemon URL. */
|
|
68
|
-
async getNodeUrl() {
|
|
69
|
-
if (!this.nodeUrl)
|
|
70
|
-
this.nodeUrl = await this.resolveNodeUrl();
|
|
71
|
-
return this.nodeUrl;
|
|
72
|
-
}
|
|
73
|
-
/** Build a full node API URL for a file path endpoint. */
|
|
74
|
-
async buildFileUrl(endpoint) {
|
|
75
|
-
const base = await this.getNodeUrl();
|
|
76
|
-
return `${base}/api/servers/${this.serverId}/files${endpoint}`;
|
|
77
|
-
}
|
|
78
|
-
/** Shared auth headers for node requests. */
|
|
79
|
-
get authHeaders() {
|
|
80
|
-
return { 'Authorization': `Bearer ${this.token}` };
|
|
53
|
+
node;
|
|
54
|
+
/** @internal */
|
|
55
|
+
constructor(node) {
|
|
56
|
+
this.node = node;
|
|
81
57
|
}
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...init,
|
|
86
|
-
headers: { ...this.authHeaders, ...init.headers },
|
|
87
|
-
});
|
|
88
|
-
if (!res.ok) {
|
|
89
|
-
let message = `HTTP ${res.status}`;
|
|
90
|
-
try {
|
|
91
|
-
const body = await res.json();
|
|
92
|
-
if (typeof body.error === 'string')
|
|
93
|
-
message = body.error;
|
|
94
|
-
}
|
|
95
|
-
catch { /* ignore */ }
|
|
96
|
-
throw new ApiError({ message, status: res.status });
|
|
97
|
-
}
|
|
98
|
-
return res;
|
|
58
|
+
/** Normalize a path to an absolute `/files` endpoint. */
|
|
59
|
+
endpoint(path) {
|
|
60
|
+
return '/files' + (path.startsWith('/') ? path : `/${path}`);
|
|
99
61
|
}
|
|
100
62
|
/**
|
|
101
63
|
* List the contents of a directory.
|
|
102
64
|
*
|
|
103
65
|
* @param path Absolute path to the directory, e.g. `"/"` or `"/plugins"`.
|
|
104
|
-
* @returns An array of {@link FileEntry} objects.
|
|
105
66
|
*/
|
|
106
67
|
async list(path) {
|
|
107
|
-
const
|
|
108
|
-
const res = await this.nodeFetch(url);
|
|
68
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
109
69
|
const data = await res.json();
|
|
110
70
|
return data.map((e) => new FileEntry(e));
|
|
111
71
|
}
|
|
@@ -113,22 +73,18 @@ export class ServerFilesManager {
|
|
|
113
73
|
* Read the text content of a file.
|
|
114
74
|
*
|
|
115
75
|
* @param path Absolute path to the file, e.g. `"/server.properties"`.
|
|
116
|
-
* @returns The file content as a UTF-8 string.
|
|
117
76
|
*/
|
|
118
77
|
async read(path) {
|
|
119
|
-
const
|
|
120
|
-
const res = await this.nodeFetch(url);
|
|
78
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
121
79
|
return res.text();
|
|
122
80
|
}
|
|
123
81
|
/**
|
|
124
82
|
* Read the raw binary content of a file.
|
|
125
83
|
*
|
|
126
84
|
* @param path Absolute path to the file.
|
|
127
|
-
* @returns The file content as an `ArrayBuffer`.
|
|
128
85
|
*/
|
|
129
86
|
async readBinary(path) {
|
|
130
|
-
const
|
|
131
|
-
const res = await this.nodeFetch(url);
|
|
87
|
+
const res = await this.node.fetch(this.endpoint(path));
|
|
132
88
|
return res.arrayBuffer();
|
|
133
89
|
}
|
|
134
90
|
/**
|
|
@@ -138,8 +94,7 @@ export class ServerFilesManager {
|
|
|
138
94
|
* @param content The UTF-8 text content to write.
|
|
139
95
|
*/
|
|
140
96
|
async write(path, content) {
|
|
141
|
-
|
|
142
|
-
await this.nodeFetch(url, {
|
|
97
|
+
await this.node.fetch(this.endpoint(path), {
|
|
143
98
|
method: 'PUT',
|
|
144
99
|
body: content,
|
|
145
100
|
headers: { 'Content-Type': 'text/plain' },
|
|
@@ -153,9 +108,8 @@ export class ServerFilesManager {
|
|
|
153
108
|
* @param contentType MIME type of the content.
|
|
154
109
|
*/
|
|
155
110
|
async writeBinary(path, content, contentType) {
|
|
156
|
-
const url = await this.buildFileUrl(path.startsWith('/') ? path : `/${path}`);
|
|
157
111
|
const body = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
|
|
158
|
-
await this.
|
|
112
|
+
await this.node.fetch(this.endpoint(path), {
|
|
159
113
|
method: 'PUT',
|
|
160
114
|
body: body,
|
|
161
115
|
headers: { 'Content-Type': contentType },
|
|
@@ -167,38 +121,33 @@ export class ServerFilesManager {
|
|
|
167
121
|
* @param paths An array of absolute paths to delete.
|
|
168
122
|
*/
|
|
169
123
|
async delete(paths) {
|
|
170
|
-
|
|
171
|
-
await this.nodeFetch(url, {
|
|
172
|
-
method: 'DELETE',
|
|
173
|
-
body: JSON.stringify({ root: '/', files: paths }),
|
|
174
|
-
headers: { 'Content-Type': 'application/json' },
|
|
175
|
-
});
|
|
124
|
+
await Promise.all(paths.map((p) => this.node.fetch(this.endpoint(p), { method: 'DELETE' })));
|
|
176
125
|
}
|
|
177
126
|
/**
|
|
178
127
|
* Move (rename) a file or directory.
|
|
179
128
|
*
|
|
180
129
|
* @param from Absolute source path.
|
|
181
130
|
* @param to Absolute destination path.
|
|
131
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
182
132
|
*/
|
|
183
|
-
async move(from, to) {
|
|
184
|
-
|
|
185
|
-
await this.nodeFetch(url, {
|
|
133
|
+
async move(from, to, root = '/') {
|
|
134
|
+
await this.node.fetch('/files/move', {
|
|
186
135
|
method: 'POST',
|
|
187
|
-
body: JSON.stringify({
|
|
136
|
+
body: JSON.stringify({ root, Paths: { [from]: to } }),
|
|
188
137
|
headers: { 'Content-Type': 'application/json' },
|
|
189
138
|
});
|
|
190
139
|
}
|
|
191
140
|
/**
|
|
192
|
-
* Copy a file or directory to a new
|
|
141
|
+
* Copy a file or directory to a new path.
|
|
193
142
|
*
|
|
194
|
-
* @param
|
|
195
|
-
* @param
|
|
143
|
+
* @param from Absolute source path.
|
|
144
|
+
* @param to Absolute destination path.
|
|
145
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
196
146
|
*/
|
|
197
|
-
async copy(
|
|
198
|
-
|
|
199
|
-
await this.nodeFetch(url, {
|
|
147
|
+
async copy(from, to, root = '/') {
|
|
148
|
+
await this.node.fetch('/files/copy', {
|
|
200
149
|
method: 'POST',
|
|
201
|
-
body: JSON.stringify({
|
|
150
|
+
body: JSON.stringify({ root, Paths: { [from]: to } }),
|
|
202
151
|
headers: { 'Content-Type': 'application/json' },
|
|
203
152
|
});
|
|
204
153
|
}
|
|
@@ -207,75 +156,84 @@ export class ServerFilesManager {
|
|
|
207
156
|
*
|
|
208
157
|
* @param path Absolute path of the new file or directory.
|
|
209
158
|
* @param directory When `true`, creates a directory instead of a file.
|
|
159
|
+
* @param root Root directory for resolving relative paths. Defaults to `"/"`.
|
|
210
160
|
*/
|
|
211
|
-
async create(path, directory = false) {
|
|
212
|
-
|
|
213
|
-
await this.nodeFetch(url, {
|
|
161
|
+
async create(path, directory = false, root = '/') {
|
|
162
|
+
await this.node.fetch('/files/create', {
|
|
214
163
|
method: 'POST',
|
|
215
|
-
body: JSON.stringify({
|
|
164
|
+
body: JSON.stringify({ root, Paths: { [path]: { type: directory ? 'directory' : 'file' } } }),
|
|
216
165
|
headers: { 'Content-Type': 'application/json' },
|
|
217
166
|
});
|
|
218
167
|
}
|
|
219
168
|
/**
|
|
220
|
-
* Compress one or more
|
|
169
|
+
* Compress one or more paths into a server-named archive.
|
|
170
|
+
*
|
|
171
|
+
* Resolves to a {@link FileEntry} for the created archive when the daemon finishes
|
|
172
|
+
* within its fast-path window, or a {@link ServerJob} to track when it runs longer.
|
|
221
173
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @param
|
|
224
|
-
* @param rootPath Root directory for resolving relative paths. Defaults to `"/"`.
|
|
174
|
+
* @param paths Absolute paths to include in the archive.
|
|
175
|
+
* @param root Root directory for resolving the paths. Defaults to `"/"`.
|
|
225
176
|
*/
|
|
226
|
-
async compress(
|
|
227
|
-
const
|
|
228
|
-
await this.nodeFetch(url, {
|
|
177
|
+
async compress(paths, root = '/') {
|
|
178
|
+
const res = await this.node.fetch('/files/compress', {
|
|
229
179
|
method: 'POST',
|
|
230
|
-
body: JSON.stringify({
|
|
180
|
+
body: JSON.stringify({ root, paths }),
|
|
231
181
|
headers: { 'Content-Type': 'application/json' },
|
|
232
182
|
});
|
|
183
|
+
if (res.status === 202) {
|
|
184
|
+
const { job_id } = await res.json();
|
|
185
|
+
return new ServerJob({ id: job_id }, this.node);
|
|
186
|
+
}
|
|
187
|
+
return new FileEntry(await res.json());
|
|
233
188
|
}
|
|
234
189
|
/**
|
|
235
190
|
* Decompress (extract) an archive file.
|
|
236
191
|
*
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
192
|
+
* Resolves to `null` when the daemon finishes within its fast-path window, or a
|
|
193
|
+
* {@link ServerJob} to track when it runs longer.
|
|
194
|
+
*
|
|
195
|
+
* @param path Absolute path to the archive to extract.
|
|
196
|
+
* @param root Directory to extract the archive into. Defaults to `"/"`.
|
|
239
197
|
*/
|
|
240
|
-
async decompress(
|
|
241
|
-
const
|
|
242
|
-
await this.nodeFetch(url, {
|
|
198
|
+
async decompress(path, root = '/') {
|
|
199
|
+
const res = await this.node.fetch('/files/decompress', {
|
|
243
200
|
method: 'POST',
|
|
244
|
-
body: JSON.stringify({
|
|
201
|
+
body: JSON.stringify({ root, path }),
|
|
245
202
|
headers: { 'Content-Type': 'application/json' },
|
|
246
203
|
});
|
|
204
|
+
if (res.status === 202) {
|
|
205
|
+
const { job_id } = await res.json();
|
|
206
|
+
return new ServerJob({ id: job_id }, this.node);
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
247
209
|
}
|
|
248
210
|
/**
|
|
249
211
|
* Change the permissions (chmod) of one or more files.
|
|
250
212
|
*
|
|
251
|
-
* @param entries
|
|
252
|
-
* @param
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```ts ignore
|
|
256
|
-
* await server.files.chmod([{ file: 'start.sh', mode: '755' }]);
|
|
257
|
-
* ```
|
|
213
|
+
* @param entries Array of `{ file, mode }` objects, e.g. `[{ file: 'start.sh', mode: '755' }]`.
|
|
214
|
+
* @param root Root directory for resolving paths. Defaults to `"/"`.
|
|
258
215
|
*/
|
|
259
|
-
async chmod(entries,
|
|
260
|
-
const
|
|
261
|
-
|
|
216
|
+
async chmod(entries, root = '/') {
|
|
217
|
+
const paths = {};
|
|
218
|
+
for (const entry of entries)
|
|
219
|
+
paths[entry.file] = { mode: entry.mode };
|
|
220
|
+
await this.node.fetch('/files/chmod', {
|
|
262
221
|
method: 'POST',
|
|
263
|
-
body: JSON.stringify({
|
|
222
|
+
body: JSON.stringify({ root, paths }),
|
|
264
223
|
headers: { 'Content-Type': 'application/json' },
|
|
265
224
|
});
|
|
266
225
|
}
|
|
267
226
|
/**
|
|
268
|
-
* Upload a file
|
|
227
|
+
* Upload a file using multipart form data.
|
|
269
228
|
*
|
|
270
|
-
* @param path Absolute directory path to upload
|
|
229
|
+
* @param path Absolute directory path to upload into.
|
|
271
230
|
* @param filename The name for the uploaded file.
|
|
272
231
|
* @param content The file content as a `Blob`, `File`, or `ArrayBuffer`.
|
|
273
232
|
*/
|
|
274
233
|
async upload(path, filename, content) {
|
|
275
|
-
const url = await this.buildFileUrl(`/upload?directory=${encodeURIComponent(path)}`);
|
|
276
234
|
const form = new FormData();
|
|
277
235
|
const blob = content instanceof ArrayBuffer ? new Blob([content]) : content;
|
|
278
236
|
form.append('files', blob, filename);
|
|
279
|
-
await this.
|
|
237
|
+
await this.node.fetch(`/files/upload?directory=${encodeURIComponent(path)}`, { method: 'POST', body: form });
|
|
280
238
|
}
|
|
281
239
|
}
|