wispjs 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +4 -4
  2. package/{wisp.ts → dist/wisp.d.ts} +11 -28
  3. package/dist/wisp.js +34 -0
  4. package/dist/wisp_api/apis/allocations.d.ts +55 -0
  5. package/dist/wisp_api/apis/allocations.js +32 -0
  6. package/dist/wisp_api/apis/audit_log.d.ts +68 -0
  7. package/dist/wisp_api/apis/audit_log.js +21 -0
  8. package/{wisp_api/apis/backups.ts → dist/wisp_api/apis/backups.d.ts} +13 -51
  9. package/dist/wisp_api/apis/backups.js +93 -0
  10. package/dist/wisp_api/apis/databases.d.ts +61 -0
  11. package/dist/wisp_api/apis/databases.js +43 -0
  12. package/dist/wisp_api/apis/fastdl.d.ts +19 -0
  13. package/dist/wisp_api/apis/fastdl.js +21 -0
  14. package/dist/wisp_api/apis/filesystem.d.ts +200 -0
  15. package/dist/wisp_api/apis/filesystem.js +182 -0
  16. package/dist/wisp_api/apis/index.d.ts +52 -0
  17. package/dist/wisp_api/apis/index.js +100 -0
  18. package/dist/wisp_api/apis/mods.d.ts +40 -0
  19. package/dist/wisp_api/apis/mods.js +30 -0
  20. package/dist/wisp_api/apis/schedules.d.ts +179 -0
  21. package/dist/wisp_api/apis/schedules.js +167 -0
  22. package/dist/wisp_api/apis/servers.d.ts +120 -0
  23. package/dist/wisp_api/apis/servers.js +76 -0
  24. package/dist/wisp_api/apis/startup.d.ts +52 -0
  25. package/dist/wisp_api/apis/startup.js +35 -0
  26. package/dist/wisp_api/apis/subusers.d.ts +106 -0
  27. package/dist/wisp_api/apis/subusers.js +87 -0
  28. package/dist/wisp_api/index.d.ts +39 -0
  29. package/dist/wisp_api/index.js +41 -0
  30. package/dist/wisp_socket/index.d.ts +161 -0
  31. package/{wisp_socket/index.ts → dist/wisp_socket/index.js} +130 -236
  32. package/dist/wisp_socket/pool.d.ts +183 -0
  33. package/dist/wisp_socket/pool.js +171 -0
  34. package/package.json +1 -1
  35. package/.github/workflows/release.yml +0 -72
  36. package/tsconfig.json +0 -19
  37. package/wisp_api/apis/allocations.ts +0 -71
  38. package/wisp_api/apis/audit_log.ts +0 -81
  39. package/wisp_api/apis/databases.ts +0 -80
  40. package/wisp_api/apis/fastdl.ts +0 -22
  41. package/wisp_api/apis/filesystem.ts +0 -291
  42. package/wisp_api/apis/index.ts +0 -135
  43. package/wisp_api/apis/mods.ts +0 -53
  44. package/wisp_api/apis/schedules.ts +0 -270
  45. package/wisp_api/apis/servers.ts +0 -155
  46. package/wisp_api/apis/startup.ts +0 -65
  47. package/wisp_api/apis/subusers.ts +0 -159
  48. package/wisp_api/index.ts +0 -57
  49. package/wisp_socket/pool.ts +0 -387
@@ -0,0 +1,106 @@
1
+ import { WispAPICore } from "./index";
2
+ import type { PaginationData } from "./index";
3
+ export type SupportPermissionType = "server:support.update";
4
+ export type ControlPermissionType = "server:control.console" | "server:control.command" | "server:control.start" | "server:control.stop" | "server:control.restart";
5
+ export type SubuserPermissionType = "server:subuser.read" | "server:subuser.update" | "server:subuser.create" | "server:subuser.delete";
6
+ export type AllocationPermissionType = "server:allocation.read" | "server:allocation.update";
7
+ export type StartupPermissionType = "server:startup.read" | "server:startup.update";
8
+ export type DatabasePermissionType = "server:database.read" | "server:database.update" | "server:database.create" | "server:database.update";
9
+ export type FilePermissionType = "server:file.sftp" | "server:file.list" | "server:file.read" | "server:file.write" | "server:file.delete" | "server:file.archive" | "server:file.git" | "server:file.steam_workshop";
10
+ export type SchedulePermissionType = "server:schedule.read" | "server:schedule.update" | "server:schedule.create" | "server:schedule.delete";
11
+ export type BackupPermissionType = "server:backup.read" | "server:backup.update" | "server:backup.create" | "server:backup.delete" | "server:backup.deploy" | "server:backup.download";
12
+ export type DetailsPermissionType = "server:details.read" | "server:details.update";
13
+ export type AuditPermissionType = "server:audit.read";
14
+ export type FastDLPermissionType = "server:fastdl.read" | "server:fastdl.update";
15
+ export type ModPermissionType = "server:mod.read" | "server:mod.update";
16
+ export type MonitorPermissionType = "server:monitor.read" | "server:monitor.update";
17
+ export type ReinstallPermissionType = "server:reinstall.update";
18
+ export type Permission = SupportPermissionType | ControlPermissionType | SubuserPermissionType | AllocationPermissionType | StartupPermissionType | DatabasePermissionType | FilePermissionType | SchedulePermissionType | BackupPermissionType | DetailsPermissionType | AuditPermissionType | FastDLPermissionType | ModPermissionType | MonitorPermissionType | ReinstallPermissionType;
19
+ export interface User {
20
+ object: "user";
21
+ attributes: {
22
+ email: string;
23
+ name_first: string;
24
+ naem_last: string;
25
+ has_2fa: boolean;
26
+ };
27
+ }
28
+ export interface Subuser {
29
+ object: "server_subuser";
30
+ attributes: {
31
+ id: number;
32
+ permissions: Permission[];
33
+ created_at: string;
34
+ updated_at: string;
35
+ relationships: {
36
+ user: User;
37
+ };
38
+ };
39
+ }
40
+ export interface GetSubusersResponse {
41
+ object: "list";
42
+ data: Subuser[];
43
+ meta: {
44
+ pagination: PaginationData;
45
+ };
46
+ }
47
+ export interface GetAllSubuserPermissionsResponse {
48
+ permissions: Permission[];
49
+ assignable: Permission[];
50
+ }
51
+ /**
52
+ * Handles interfacing with the Subusers API
53
+ *
54
+ * @public
55
+ */
56
+ export declare class SubusersAPI {
57
+ private core;
58
+ constructor(core: WispAPICore);
59
+ /**
60
+ * Lists all Subusers for the Server
61
+ *
62
+ * @public
63
+ */
64
+ List(): Promise<GetSubusersResponse>;
65
+ /**
66
+ * Retrieves the details for the Subuser
67
+ *
68
+ * @param id The ID of the Subuser
69
+ *
70
+ * @public
71
+ */
72
+ GetDetails(id: string): Promise<Subuser>;
73
+ /**
74
+ * Get all permissions available to Subusers
75
+ *
76
+ * @public
77
+ */
78
+ GetAllPermissions(): Promise<GetAllSubuserPermissionsResponse>;
79
+ /**
80
+ * Creates a new Subuser
81
+ *
82
+ * @param email The email for the Subuser
83
+ * @param permissions The Permissions to grant to the Subuser
84
+ *
85
+ * @public
86
+ */
87
+ Create(email: string, permissions: Permission[]): Promise<Subuser>;
88
+ /**
89
+ * Updates the Subuser
90
+ *
91
+ * @param id The ID of the Subuser
92
+ * @param email The new email of the Subuser
93
+ * @param permissions The new permissions for the Subuser
94
+ *
95
+ * @public
96
+ */
97
+ Update(id: string, email: string, permissions: Permission[]): Promise<Subuser>;
98
+ /**
99
+ * Deletes the Subuser
100
+ *
101
+ * @param id The ID of the Subuser
102
+ *
103
+ * @public
104
+ */
105
+ Delete(id: string): Promise<void>;
106
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Handles interfacing with the Subusers API
3
+ *
4
+ * @public
5
+ */
6
+ export class SubusersAPI {
7
+ constructor(core) {
8
+ this.core = core;
9
+ }
10
+ /**
11
+ * Lists all Subusers for the Server
12
+ *
13
+ * @public
14
+ */
15
+ async List() {
16
+ const response = await this.core.makeRequest("GET", "subusers", { include: "user" });
17
+ const data = await response.json();
18
+ return data;
19
+ }
20
+ /**
21
+ * Retrieves the details for the Subuser
22
+ *
23
+ * @param id The ID of the Subuser
24
+ *
25
+ * @public
26
+ */
27
+ async GetDetails(id) {
28
+ const response = await this.core.makeRequest("GET", `subusers/${id}`, { include: "user" });
29
+ const data = await response.json();
30
+ return data;
31
+ }
32
+ /**
33
+ * Get all permissions available to Subusers
34
+ *
35
+ * @public
36
+ */
37
+ async GetAllPermissions() {
38
+ const response = await this.core.makeRequest("GET", "subusers/permissions");
39
+ const data = await response.json();
40
+ return data;
41
+ }
42
+ /**
43
+ * Creates a new Subuser
44
+ *
45
+ * @param email The email for the Subuser
46
+ * @param permissions The Permissions to grant to the Subuser
47
+ *
48
+ * @public
49
+ */
50
+ async Create(email, permissions) {
51
+ const requestData = {
52
+ email: email,
53
+ permissions: permissions
54
+ };
55
+ const response = await this.core.makeRequest("POST", "subusers", requestData);
56
+ const data = await response.json();
57
+ return data;
58
+ }
59
+ /**
60
+ * Updates the Subuser
61
+ *
62
+ * @param id The ID of the Subuser
63
+ * @param email The new email of the Subuser
64
+ * @param permissions The new permissions for the Subuser
65
+ *
66
+ * @public
67
+ */
68
+ async Update(id, email, permissions) {
69
+ const data = {
70
+ email: email,
71
+ permissions: permissions
72
+ };
73
+ const response = await this.core.makeRequest("PATCH", `subusers/${id}`, data);
74
+ const responseData = await response.json();
75
+ return responseData;
76
+ }
77
+ /**
78
+ * Deletes the Subuser
79
+ *
80
+ * @param id The ID of the Subuser
81
+ *
82
+ * @public
83
+ */
84
+ async Delete(id) {
85
+ await this.core.makeRequest("DELETE", `subusers/${id}`);
86
+ }
87
+ }
@@ -0,0 +1,39 @@
1
+ import { AllocationsAPI } from "./apis/allocations.js";
2
+ import { AuditLogsAPI } from "./apis/audit_log.js";
3
+ import { BackupsAPI } from "./apis/backups.js";
4
+ import { DatabasesAPI } from "./apis/databases.js";
5
+ import { FastDLAPI } from "./apis/fastdl.js";
6
+ import { FilesystemAPI } from "./apis/filesystem.js";
7
+ import { ModsAPI } from "./apis/mods.js";
8
+ import { SchedulesAPI } from "./apis/schedules.js";
9
+ import { ServersAPI } from "./apis/servers.js";
10
+ import { StartupAPI } from "./apis/startup.js";
11
+ import { SubusersAPI } from "./apis/subusers.js";
12
+ /**
13
+ * An Interface for the Wisp HTTP API
14
+ *
15
+ * @public
16
+ */
17
+ export declare class WispAPI {
18
+ private core;
19
+ Allocations: AllocationsAPI;
20
+ AuditLogs: AuditLogsAPI;
21
+ Backups: BackupsAPI;
22
+ Databases: DatabasesAPI;
23
+ FastDL: FastDLAPI;
24
+ Filesystem: FilesystemAPI;
25
+ Mods: ModsAPI;
26
+ Schedules: SchedulesAPI;
27
+ Servers: ServersAPI;
28
+ Startup: StartupAPI;
29
+ Subusers: SubusersAPI;
30
+ /**
31
+ * @param domain The domain name for your panel
32
+ * @param uuid The UUID of the Server that all future API calls will reference
33
+ * @param token The panel API token to use for authorization
34
+ * @param logger The logger to use for all API logging
35
+ *
36
+ * @internal
37
+ */
38
+ constructor(domain: string, uuid: string, token: string, logger: any);
39
+ }
@@ -0,0 +1,41 @@
1
+ import { WispAPICore } from "./apis/index.js";
2
+ import { AllocationsAPI } from "./apis/allocations.js";
3
+ import { AuditLogsAPI } from "./apis/audit_log.js";
4
+ import { BackupsAPI } from "./apis/backups.js";
5
+ import { DatabasesAPI } from "./apis/databases.js";
6
+ import { FastDLAPI } from "./apis/fastdl.js";
7
+ import { FilesystemAPI } from "./apis/filesystem.js";
8
+ import { ModsAPI } from "./apis/mods.js";
9
+ import { SchedulesAPI } from "./apis/schedules.js";
10
+ import { ServersAPI } from "./apis/servers.js";
11
+ import { StartupAPI } from "./apis/startup.js";
12
+ import { SubusersAPI } from "./apis/subusers.js";
13
+ /**
14
+ * An Interface for the Wisp HTTP API
15
+ *
16
+ * @public
17
+ */
18
+ export class WispAPI {
19
+ /**
20
+ * @param domain The domain name for your panel
21
+ * @param uuid The UUID of the Server that all future API calls will reference
22
+ * @param token The panel API token to use for authorization
23
+ * @param logger The logger to use for all API logging
24
+ *
25
+ * @internal
26
+ */
27
+ constructor(domain, uuid, token, logger) {
28
+ this.core = new WispAPICore(domain, uuid, token, logger);
29
+ this.Allocations = new AllocationsAPI(this.core);
30
+ this.AuditLogs = new AuditLogsAPI(this.core);
31
+ this.Backups = new BackupsAPI(this.core);
32
+ this.Databases = new DatabasesAPI(this.core);
33
+ this.FastDL = new FastDLAPI(this.core);
34
+ this.Filesystem = new FilesystemAPI(this.core);
35
+ this.Mods = new ModsAPI(this.core);
36
+ this.Schedules = new SchedulesAPI(this.core);
37
+ this.Servers = new ServersAPI(this.core);
38
+ this.Startup = new StartupAPI(this.core);
39
+ this.Subusers = new SubusersAPI(this.core);
40
+ }
41
+ }
@@ -0,0 +1,161 @@
1
+ import { WebsocketPool } from "./pool.js";
2
+ import { FilesearchResults } from "./pool";
3
+ import type { WispAPI } from "../wisp_api/index.js";
4
+ /**
5
+ * The Websocket information returned from the API
6
+ *
7
+ * @param token The token to use when authenticating with the `auth` command in the Websocket
8
+ * @param url The actual URL of the Websocket
9
+ *
10
+ * @internal
11
+ */
12
+ export interface WebsocketInfo {
13
+ token: string;
14
+ url: string;
15
+ }
16
+ export type WebsocketDetailsPreprocessor = (info: WebsocketInfo) => void;
17
+ export interface WispSocket {
18
+ pool: WebsocketPool;
19
+ logger: any;
20
+ api: WispAPI;
21
+ url: string | undefined;
22
+ token: string | undefined;
23
+ ghToken: string | undefined;
24
+ consoleCallbacks: ((message: string) => void)[];
25
+ detailsPreprocessor: WebsocketDetailsPreprocessor | undefined;
26
+ }
27
+ /**
28
+ * The primary interface to the Websocket API
29
+ *
30
+ * @internal
31
+ */
32
+ export declare class WispSocket {
33
+ constructor(logger: any, api: any, ghToken: string | undefined);
34
+ /**
35
+ * Sets a callback to run on the Websocket Info before saving the details.
36
+ *
37
+ * @example
38
+ * ```js
39
+ * // Change the URL of the Websocket
40
+ * wisp.socket.setWebsocketDetailsPreprocessor((info) => {
41
+ * info.url = "wss://newurl.com"
42
+ * })
43
+ * ```
44
+ *
45
+ * @remarks
46
+ * ℹ️ This can be used to modify the URL or token after its retrieved from the API
47
+ *
48
+ * @param preprocessor The callback to run when the data is received from the API
49
+ *
50
+ * @public
51
+ */
52
+ setWebsocketDetailsPreprocessor(preprocessor: WebsocketDetailsPreprocessor): void;
53
+ /**
54
+ * Creates a new Websocket Pool
55
+ *
56
+ * @throws Throws an error if the URL or token are not set yet
57
+ * @internal
58
+ */
59
+ createPool(): void;
60
+ /**
61
+ * Requests and saves the Websocket details from the API
62
+ *
63
+ * @internal
64
+ */
65
+ setDetails(): Promise<void>;
66
+ /**
67
+ * Disconnects from the websocket
68
+ *
69
+ * @internal
70
+ */
71
+ disconnect(): Promise<void>;
72
+ /**
73
+ * Verifies that the pool is created and ready to use
74
+ *
75
+ * @internal
76
+ */
77
+ verifyPool(): Promise<void>;
78
+ /**
79
+ * Searches all file contents for the given query
80
+ *
81
+ * @param query The query string to search for
82
+ *
83
+ * @public
84
+ */
85
+ filesearch(query: string): Promise<FilesearchResults>;
86
+ /**
87
+ * Performs a git pull operation on the given directory
88
+ *
89
+ * @param dir The full directory path to perform a pull on
90
+ *
91
+ * @public
92
+ */
93
+ gitPull(dir: string, useAuth?: boolean): Promise<any>;
94
+ /**
95
+ * Clones a new Repo to the given directory
96
+ *
97
+ * @param url The HTTPS URL of the repository
98
+ * @param dir The full path of the directory to clone the repository to
99
+ * @param branch The branch of the repository to clone
100
+ *
101
+ * @public
102
+ */
103
+ gitClone(url: string, dir: string, branch: string): Promise<any>;
104
+ /**
105
+ * Sets up the console listener worker
106
+ *
107
+ * @internal
108
+ */
109
+ setupConsoleListener(): void;
110
+ /**
111
+ * Adds a new callback that will run any time a console message is rececived
112
+ *
113
+ * @param callback The callback to run, takes a single param, `message`, a string
114
+ *
115
+ * @public
116
+ */
117
+ addConsoleListener(callback: (message: string) => void): void;
118
+ /**
119
+ * Removes a previously added console message callback
120
+ *
121
+ * @param callback The callback function that was previously added
122
+ *
123
+ * @public
124
+ */
125
+ removeConsoleListener(callback: (message: string) => void): void;
126
+ /**
127
+ * Sends a command to the server and then waits until output with the given prefix is seen in a console message
128
+ *
129
+ * @example
130
+ * Runs a custom lua command that will prefix its output with our nonce, then prints the output from that command
131
+ * ```lua
132
+ * -- lua/autorun/server/nonce_example.lua
133
+ * concommand.Add( "myCommand", function( ply, _, args )
134
+ * if IsValid( ply ) then return end
135
+ *
136
+ * local nonce = args[1]
137
+ * print( nonce .. "Command output" )
138
+ * end )
139
+ * ```
140
+ * ```js
141
+ * const nonce = "abc123";
142
+ * const command = `myCommand "${nonce}"`;
143
+ * try {
144
+ * const output = await wisp.socket.sendCommandNonce(nonce, command);
145
+ * console.log("Output from command:", output);
146
+ * catch (error) {
147
+ * console.error(error);
148
+ * }
149
+ * ```
150
+ *
151
+ * @remarks
152
+ * ℹ️ This is useful if you run code on your Server that will print output with the same prefix, letting you run commands and also receive output for it
153
+ *
154
+ * @param nonce The short, unique string that your output will be prefixed with
155
+ * @param command The full command string to send
156
+ * @param timeout How long to wait for output before timing out
157
+ *
158
+ * @public
159
+ */
160
+ sendCommandNonce(nonce: string, command: string, timeout?: number): Promise<any>;
161
+ }