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.
- package/README.md +4 -4
- package/{wisp.ts → dist/wisp.d.ts} +11 -28
- package/dist/wisp.js +34 -0
- package/dist/wisp_api/apis/allocations.d.ts +55 -0
- package/dist/wisp_api/apis/allocations.js +32 -0
- package/dist/wisp_api/apis/audit_log.d.ts +68 -0
- package/dist/wisp_api/apis/audit_log.js +21 -0
- package/{wisp_api/apis/backups.ts → dist/wisp_api/apis/backups.d.ts} +13 -51
- package/dist/wisp_api/apis/backups.js +93 -0
- package/dist/wisp_api/apis/databases.d.ts +61 -0
- package/dist/wisp_api/apis/databases.js +43 -0
- package/dist/wisp_api/apis/fastdl.d.ts +19 -0
- package/dist/wisp_api/apis/fastdl.js +21 -0
- package/dist/wisp_api/apis/filesystem.d.ts +200 -0
- package/dist/wisp_api/apis/filesystem.js +182 -0
- package/dist/wisp_api/apis/index.d.ts +52 -0
- package/dist/wisp_api/apis/index.js +100 -0
- package/dist/wisp_api/apis/mods.d.ts +40 -0
- package/dist/wisp_api/apis/mods.js +30 -0
- package/dist/wisp_api/apis/schedules.d.ts +179 -0
- package/dist/wisp_api/apis/schedules.js +167 -0
- package/dist/wisp_api/apis/servers.d.ts +120 -0
- package/dist/wisp_api/apis/servers.js +76 -0
- package/dist/wisp_api/apis/startup.d.ts +52 -0
- package/dist/wisp_api/apis/startup.js +35 -0
- package/dist/wisp_api/apis/subusers.d.ts +106 -0
- package/dist/wisp_api/apis/subusers.js +87 -0
- package/dist/wisp_api/index.d.ts +39 -0
- package/dist/wisp_api/index.js +41 -0
- package/dist/wisp_socket/index.d.ts +161 -0
- package/{wisp_socket/index.ts → dist/wisp_socket/index.js} +130 -236
- package/dist/wisp_socket/pool.d.ts +183 -0
- package/dist/wisp_socket/pool.js +171 -0
- package/package.json +1 -1
- package/.github/workflows/release.yml +0 -72
- package/tsconfig.json +0 -19
- package/wisp_api/apis/allocations.ts +0 -71
- package/wisp_api/apis/audit_log.ts +0 -81
- package/wisp_api/apis/databases.ts +0 -80
- package/wisp_api/apis/fastdl.ts +0 -22
- package/wisp_api/apis/filesystem.ts +0 -291
- package/wisp_api/apis/index.ts +0 -135
- package/wisp_api/apis/mods.ts +0 -53
- package/wisp_api/apis/schedules.ts +0 -270
- package/wisp_api/apis/servers.ts +0 -155
- package/wisp_api/apis/startup.ts +0 -65
- package/wisp_api/apis/subusers.ts +0 -159
- package/wisp_api/index.ts +0 -57
- package/wisp_socket/pool.ts +0 -387
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
/**
|
|
3
|
+
* The struct used to define the events that can be sent from the server to the client
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface ServerToClientEvents {
|
|
8
|
+
"error": (message: string) => void;
|
|
9
|
+
"auth_success": (message: string) => void;
|
|
10
|
+
"filesearch-results": (data: FilesearchResults) => void;
|
|
11
|
+
"git-error": (data: string) => void;
|
|
12
|
+
"git-success": (message?: string) => void;
|
|
13
|
+
"git-clone": (data: GitCloneData) => void;
|
|
14
|
+
"git-pull": (data: GitPullData) => void;
|
|
15
|
+
"console": (message: ConsoleMessage) => void;
|
|
16
|
+
"initial status": (message: any) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The struct used to define the events that can be sent from the client to the server
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface ClientToServerEvents {
|
|
24
|
+
"auth": (token: string) => void;
|
|
25
|
+
"filesearch-start": (query: string) => void;
|
|
26
|
+
"git-clone": (data: GitCloneData) => void;
|
|
27
|
+
"git-pull": (data: GitPullData) => void;
|
|
28
|
+
"send command": (command: string) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The struct sent from the server containing console messages
|
|
32
|
+
*
|
|
33
|
+
* @param type The type of message. Currently unknown what varients exist
|
|
34
|
+
* @param line The actual content of the console messages
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export interface ConsoleMessage {
|
|
39
|
+
type: string;
|
|
40
|
+
line: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Struct used to initiate a Git Clone action
|
|
44
|
+
*
|
|
45
|
+
* @param dir The directory to clone into
|
|
46
|
+
* @param url The HTTPS URL to clone
|
|
47
|
+
* @param branch The repository branch
|
|
48
|
+
* @param authkey The authentication key to use when pulling
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export interface GitCloneData {
|
|
53
|
+
dir: string;
|
|
54
|
+
url: string;
|
|
55
|
+
branch: string;
|
|
56
|
+
authkey?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Return struct after finishing a Git Clone action
|
|
60
|
+
*
|
|
61
|
+
* @param isPrivate Whether or not the repository is private
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export interface GitCloneResult {
|
|
66
|
+
isPrivate: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Struct used to initiate a Git Pull action
|
|
70
|
+
*
|
|
71
|
+
* @param dir The directory to pull
|
|
72
|
+
* @param authkey The authentication key to use when pulling
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export interface GitPullData {
|
|
77
|
+
dir: string;
|
|
78
|
+
authkey?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Struct returned after a Git Pull action finishes
|
|
82
|
+
*
|
|
83
|
+
* @param output The actual output
|
|
84
|
+
* @param isPrivate Whether or not the repository is private
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export interface GitPullResult {
|
|
89
|
+
output: string;
|
|
90
|
+
isPrivate: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* An individual filesearch result
|
|
94
|
+
*
|
|
95
|
+
* @param results How many results are present in the file
|
|
96
|
+
* @param lines A map of line numbers to their contents. These lines include nearby context of matched lines
|
|
97
|
+
*
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
export interface FilesearchFile {
|
|
101
|
+
results: number;
|
|
102
|
+
lines: {
|
|
103
|
+
[key: string]: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The results of a file search
|
|
108
|
+
*
|
|
109
|
+
* @param files A map of file names to matched+context lines within each file
|
|
110
|
+
* @param tooMany Whether or not there were too many results to display
|
|
111
|
+
*
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export interface FilesearchResults {
|
|
115
|
+
files: {
|
|
116
|
+
[key: string]: FilesearchFile;
|
|
117
|
+
};
|
|
118
|
+
tooMany: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The events that can be sent from the server to the client
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export type WispWebsocket = Socket<ServerToClientEvents, ClientToServerEvents>;
|
|
125
|
+
/**
|
|
126
|
+
* A single worker in the Websocket Pool
|
|
127
|
+
*
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
interface PoolWorker {
|
|
131
|
+
pool: WebsocketPool;
|
|
132
|
+
socket: WispWebsocket;
|
|
133
|
+
idx: number;
|
|
134
|
+
token: string;
|
|
135
|
+
ready: boolean;
|
|
136
|
+
logger: {
|
|
137
|
+
log(...args: any[]): void;
|
|
138
|
+
error(...args: any[]): void;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A single Worker within a {@link WebsocketPool}
|
|
143
|
+
*
|
|
144
|
+
* @param pool The pool this worker is a part of
|
|
145
|
+
*
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
declare class PoolWorker {
|
|
149
|
+
constructor(pool: WebsocketPool);
|
|
150
|
+
available(): boolean;
|
|
151
|
+
connect(): Promise<void>;
|
|
152
|
+
disconnect(): Promise<void>;
|
|
153
|
+
run(work: (worker: PoolWorker) => Promise<any>): Promise<any>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Struct used to manage a pool of WebSocket workers
|
|
157
|
+
*/
|
|
158
|
+
export interface WebsocketPool {
|
|
159
|
+
workers: PoolWorker[];
|
|
160
|
+
token: string;
|
|
161
|
+
url: string;
|
|
162
|
+
maxWorkers: number;
|
|
163
|
+
queue: ((worker: PoolWorker) => Promise<any>)[];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A pool of {@link PoolWorker}s
|
|
167
|
+
*
|
|
168
|
+
* This is used to manage a pool of WebSocket workers that can be used to run tasks in parallel
|
|
169
|
+
* This alleviates the need to wait for every WebSocket instruction to fully complete before starting another
|
|
170
|
+
*
|
|
171
|
+
* @param url The WebSocket URL to connect to
|
|
172
|
+
* @param token The token to use for WebSocket authentication
|
|
173
|
+
*
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
export declare class WebsocketPool {
|
|
177
|
+
constructor(url: string, token: string);
|
|
178
|
+
createWorker(): Promise<PoolWorker>;
|
|
179
|
+
disconnect(): Promise<void>;
|
|
180
|
+
processQueue(): Promise<any>;
|
|
181
|
+
run(work: (worker: PoolWorker) => Promise<any>): Promise<any>;
|
|
182
|
+
}
|
|
183
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
/**
|
|
3
|
+
* A single Worker within a {@link WebsocketPool}
|
|
4
|
+
*
|
|
5
|
+
* @param pool The pool this worker is a part of
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
class PoolWorker {
|
|
10
|
+
constructor(pool) {
|
|
11
|
+
this.pool = pool;
|
|
12
|
+
this.ready = false;
|
|
13
|
+
this.idx = pool.workers.length;
|
|
14
|
+
this.token = pool.token;
|
|
15
|
+
this.socket = io(pool.url, {
|
|
16
|
+
forceNew: true,
|
|
17
|
+
transports: ["websocket"],
|
|
18
|
+
addTrailingSlash: true,
|
|
19
|
+
autoConnect: false
|
|
20
|
+
});
|
|
21
|
+
const logPrefix = `[Worker #${this.idx}]`;
|
|
22
|
+
this.logger = {
|
|
23
|
+
log: (...args) => console.log(logPrefix, args),
|
|
24
|
+
error: (...args) => console.error(logPrefix, args),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
available() {
|
|
28
|
+
return this.ready && this.socket.connected;
|
|
29
|
+
}
|
|
30
|
+
connect() {
|
|
31
|
+
const socket = this.socket;
|
|
32
|
+
const logger = this.logger;
|
|
33
|
+
socket.onAnyOutgoing(this.logger.log);
|
|
34
|
+
logger.log("Connecting to websocket...");
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
let connectedOnce = false;
|
|
37
|
+
const timeout = setTimeout(() => {
|
|
38
|
+
if (!connectedOnce) {
|
|
39
|
+
logger.error("Socket didn't connect in time");
|
|
40
|
+
reject("Connection Timeout");
|
|
41
|
+
}
|
|
42
|
+
}, 10000);
|
|
43
|
+
socket.on("connect", () => {
|
|
44
|
+
logger.log("Connected to WebSocket");
|
|
45
|
+
logger.log("Emitting:", "auth", this.token);
|
|
46
|
+
socket.emit("auth", this.token);
|
|
47
|
+
});
|
|
48
|
+
socket.on("error", (reason) => {
|
|
49
|
+
logger.error(`WebSocket error: ${reason}`);
|
|
50
|
+
});
|
|
51
|
+
socket.on("connect_error", (error) => {
|
|
52
|
+
logger.error(`WebSocket Connect error: ${error.toString()}`);
|
|
53
|
+
if (!connectedOnce) {
|
|
54
|
+
connectedOnce = true;
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
reject(`Connection error: ${error.toString()}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
socket.on("disconnect", (reason) => {
|
|
60
|
+
logger.log(`Disconnected from WebSocket: ${reason}`);
|
|
61
|
+
});
|
|
62
|
+
socket.on("auth_success", () => {
|
|
63
|
+
logger.log("Auth success");
|
|
64
|
+
if (!connectedOnce) {
|
|
65
|
+
connectedOnce = true;
|
|
66
|
+
this.ready = true;
|
|
67
|
+
clearTimeout(timeout);
|
|
68
|
+
resolve();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
socket.connect();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
disconnect() {
|
|
75
|
+
this.ready = false;
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const timeout = setTimeout(() => {
|
|
78
|
+
this.logger.error("Socket didn't disconnect in time");
|
|
79
|
+
reject();
|
|
80
|
+
}, 5000);
|
|
81
|
+
this.socket.once("disconnect", () => {
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
resolve();
|
|
84
|
+
});
|
|
85
|
+
this.socket.disconnect();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async run(work) {
|
|
89
|
+
this.ready = false;
|
|
90
|
+
// TODO: Verify that a finally is what we want here
|
|
91
|
+
try {
|
|
92
|
+
return await work(this);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
this.logger.error(e);
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
this.ready = true;
|
|
100
|
+
this.pool.processQueue();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A pool of {@link PoolWorker}s
|
|
106
|
+
*
|
|
107
|
+
* This is used to manage a pool of WebSocket workers that can be used to run tasks in parallel
|
|
108
|
+
* This alleviates the need to wait for every WebSocket instruction to fully complete before starting another
|
|
109
|
+
*
|
|
110
|
+
* @param url The WebSocket URL to connect to
|
|
111
|
+
* @param token The token to use for WebSocket authentication
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export class WebsocketPool {
|
|
116
|
+
constructor(url, token) {
|
|
117
|
+
this.maxWorkers = 5;
|
|
118
|
+
this.token = token;
|
|
119
|
+
this.url = url;
|
|
120
|
+
this.workers = [];
|
|
121
|
+
this.queue = [];
|
|
122
|
+
}
|
|
123
|
+
async createWorker() {
|
|
124
|
+
console.log("Creating a new Pool worker");
|
|
125
|
+
const worker = new PoolWorker(this);
|
|
126
|
+
this.workers.push(worker);
|
|
127
|
+
await worker.connect();
|
|
128
|
+
return worker;
|
|
129
|
+
}
|
|
130
|
+
async disconnect() {
|
|
131
|
+
await Promise.all(this.workers.map((worker) => worker.disconnect()));
|
|
132
|
+
}
|
|
133
|
+
async processQueue() {
|
|
134
|
+
if (this.queue.length == 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const work = this.queue.shift();
|
|
138
|
+
if (!work) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let worker;
|
|
142
|
+
if (this.workers.length == 0) {
|
|
143
|
+
worker = await this.createWorker();
|
|
144
|
+
}
|
|
145
|
+
worker = worker || this.workers.find((worker) => worker.available());
|
|
146
|
+
if (!worker) {
|
|
147
|
+
if (this.workers.length < this.maxWorkers) {
|
|
148
|
+
worker = await this.createWorker();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return await worker.run(work);
|
|
155
|
+
}
|
|
156
|
+
async run(work) {
|
|
157
|
+
return new Promise(async (resolve, reject) => {
|
|
158
|
+
this.queue.push(async (worker) => {
|
|
159
|
+
try {
|
|
160
|
+
const result = await work(worker);
|
|
161
|
+
resolve(result);
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
worker.logger.error("Failed to run a job!");
|
|
165
|
+
reject(e);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return this.processQueue();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
package/package.json
CHANGED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
name: Deploy
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
inputs:
|
|
6
|
-
version_tag:
|
|
7
|
-
description: "Version tag for the package"
|
|
8
|
-
required: true
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v4
|
|
15
|
-
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: 18
|
|
19
|
-
|
|
20
|
-
- name: Update package version
|
|
21
|
-
run: |
|
|
22
|
-
version=${{ inputs.version_tag }}
|
|
23
|
-
sed -i "s/\"version\": \".*\"/\"version\": \"$version\"/" package.json
|
|
24
|
-
|
|
25
|
-
- name: Install packages
|
|
26
|
-
run: |
|
|
27
|
-
npm ci
|
|
28
|
-
|
|
29
|
-
- name: Build
|
|
30
|
-
run: |
|
|
31
|
-
npm run build
|
|
32
|
-
|
|
33
|
-
- name: Generate Docs
|
|
34
|
-
run: |
|
|
35
|
-
npm run build-docs
|
|
36
|
-
mv docs ../docs_wip
|
|
37
|
-
|
|
38
|
-
- name: Remove Non-distributables
|
|
39
|
-
run: |
|
|
40
|
-
rm .gitignore
|
|
41
|
-
rm tsconfig.json
|
|
42
|
-
rm wisp.ts
|
|
43
|
-
rm -rf wisp_api wisp_socket .github
|
|
44
|
-
|
|
45
|
-
- name: Publish
|
|
46
|
-
uses: JS-DevTools/npm-publish@v3
|
|
47
|
-
with:
|
|
48
|
-
token: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
|
49
|
-
|
|
50
|
-
- name: Configure Git User
|
|
51
|
-
run: |
|
|
52
|
-
git config user.name github-actions
|
|
53
|
-
git config user.email github-actions@github.com
|
|
54
|
-
|
|
55
|
-
- name: Push package version change
|
|
56
|
-
run: |
|
|
57
|
-
git add package.json
|
|
58
|
-
git commit -m "Update package.json version to: ${{ inputs.version_tag }}" && \
|
|
59
|
-
git push --force-with-lease origin main || \
|
|
60
|
-
echo "Version tag unchanaged"
|
|
61
|
-
|
|
62
|
-
git tag "${{ inputs.version_tag }}"
|
|
63
|
-
git push --tags
|
|
64
|
-
|
|
65
|
-
- name: Publish Docs
|
|
66
|
-
run: |
|
|
67
|
-
rm -rf ./* ,/.*
|
|
68
|
-
|
|
69
|
-
mv ../docs_wip docs
|
|
70
|
-
git add .
|
|
71
|
-
git commit -m "Update Docs for version: ${{ inputs.version_tag }}"
|
|
72
|
-
git push --force origin HEAD:docs
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
|
|
6
|
-
"outDir": "./dist/",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
|
|
12
|
-
"strict": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"moduleResolution": "node"
|
|
15
|
-
},
|
|
16
|
-
"include": ["*.ts"],
|
|
17
|
-
"exclude": ["node_modules"]
|
|
18
|
-
}
|
|
19
|
-
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An Allocation object
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export interface Allocation {
|
|
10
|
-
object: "allocation";
|
|
11
|
-
attributes: {
|
|
12
|
-
id: number;
|
|
13
|
-
/** Whether or not this Allocation is the primary one for the Server */
|
|
14
|
-
primary: boolean;
|
|
15
|
-
ip: string;
|
|
16
|
-
port: number;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The response object from the GetAllocations call
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* Used in {@link AllocationsAPI.List}
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export interface GetAllocationsResponse {
|
|
29
|
-
object: "list";
|
|
30
|
-
data: Allocation[];
|
|
31
|
-
meta: {
|
|
32
|
-
pagination: PaginationData;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Handles the listing and updating of a Server's IP/Port Allocations
|
|
38
|
-
*
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
export class AllocationsAPI {
|
|
42
|
-
constructor(private core: WispAPICore) {}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Lists all Allocations for the Server
|
|
47
|
-
*
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
async List(): Promise<GetAllocationsResponse> {
|
|
51
|
-
const response = await this.core.makeRequest("GET", "allocations");
|
|
52
|
-
const data: GetAllocationsResponse = await response.json()
|
|
53
|
-
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sets the new primary Allocation for the server
|
|
60
|
-
*
|
|
61
|
-
* @param id Allocation ID of the new primary allocation
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
async Update(id: string): Promise<Allocation> {
|
|
66
|
-
const response = await this.core.makeRequest("PUT", `allocations/${id}`);
|
|
67
|
-
const data: Allocation = await response.json()
|
|
68
|
-
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Device information
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```json
|
|
9
|
-
* {
|
|
10
|
-
* "city_name": "Seattle",
|
|
11
|
-
* "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
12
|
-
* "country_name": "US",
|
|
13
|
-
* "country_iso_code": "US"
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export interface Device {
|
|
20
|
-
city_name: string;
|
|
21
|
-
user_agent: string;
|
|
22
|
-
country_name: string;
|
|
23
|
-
country_iso_code: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// TODO: Fully define the audit log type
|
|
27
|
-
/**
|
|
28
|
-
* An Audit Log struct
|
|
29
|
-
*
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
export interface AuditLog {
|
|
33
|
-
object: "audit_log";
|
|
34
|
-
attributes: {
|
|
35
|
-
action: string;
|
|
36
|
-
subaction: string;
|
|
37
|
-
device: Device | undefined;
|
|
38
|
-
metadata: any;
|
|
39
|
-
created_at: string;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The respones object from the GetAuditLogs call
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* Used in {@link AuditLogsAPI.List}
|
|
48
|
-
*
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export interface GetAuditLogsResponse {
|
|
52
|
-
object: "list";
|
|
53
|
-
data: AuditLog[];
|
|
54
|
-
meta: {
|
|
55
|
-
pagination: PaginationData;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Interface that handles Listing of all Audit Logs
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export class AuditLogsAPI {
|
|
66
|
-
constructor(private core: WispAPICore) {}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// TODO: Handle pagination
|
|
70
|
-
/**
|
|
71
|
-
* List all Audit Log events for the server
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
async List(): Promise<GetAuditLogsResponse> {
|
|
76
|
-
const response = await this.core.makeRequest("GET", "audit-logs");
|
|
77
|
-
const data: GetAuditLogsResponse = await response.json();
|
|
78
|
-
|
|
79
|
-
return data;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
import type { PaginationData } from "./index";
|
|
3
|
-
|
|
4
|
-
export interface DatabaseRelationship {
|
|
5
|
-
object: "database_host";
|
|
6
|
-
attributes: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
host: string;
|
|
10
|
-
port: number;
|
|
11
|
-
phpmyadmin_url: string | null;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Database {
|
|
16
|
-
object: "database";
|
|
17
|
-
attributes: {
|
|
18
|
-
id: number;
|
|
19
|
-
name: string;
|
|
20
|
-
remote: string;
|
|
21
|
-
username: string;
|
|
22
|
-
password: string;
|
|
23
|
-
relationships: DatabaseRelationship[];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export interface GetDatabasesResponse {
|
|
27
|
-
object: "list";
|
|
28
|
-
data: Database[];
|
|
29
|
-
meta: {
|
|
30
|
-
pagination: PaginationData;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Handles Creating, Listing, Updating, and Deleting of Databases for the Server
|
|
36
|
-
*
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export class DatabasesAPI {
|
|
40
|
-
constructor(private core: WispAPICore) {}
|
|
41
|
-
|
|
42
|
-
// TODO: Handle Pagination
|
|
43
|
-
/**
|
|
44
|
-
* Lists all Databases associated with the Server
|
|
45
|
-
*
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
async List(): Promise<GetDatabasesResponse> {
|
|
49
|
-
const response = await this.core.makeRequest("GET", "databases", { include: "hosts" });
|
|
50
|
-
const data: GetDatabasesResponse = await response.json();
|
|
51
|
-
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// TODO: verify response
|
|
57
|
-
/**
|
|
58
|
-
* Deletes the Database from the Server
|
|
59
|
-
*
|
|
60
|
-
* @param id The ID of the Backup
|
|
61
|
-
*
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
async Delete(id: string): Promise<Response> {
|
|
65
|
-
return await this.core.makeRequest("DELETE", `databases/${id}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// TODO: Verify response
|
|
70
|
-
/**
|
|
71
|
-
* Rotates the password for the Backup
|
|
72
|
-
*
|
|
73
|
-
* @param id The ID of the Backup
|
|
74
|
-
*
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
async RotatePassword(id: string): Promise<Response> {
|
|
78
|
-
return await this.core.makeRequest("POST", `databases/${id}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
package/wisp_api/apis/fastdl.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { WispAPICore } from "./index";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Handles the syncing of the FastDL feature
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export class FastDLAPI {
|
|
9
|
-
constructor(private core: WispAPICore) {}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Begins a FastDL Sync for the server
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* ⚠️ If a Sync is already in progress, this function will succeed even though the process will fail.
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
async Sync(): Promise<void> {
|
|
20
|
-
await this.core.makeRequest("POST", "fastdl");
|
|
21
|
-
}
|
|
22
|
-
}
|