alsabase 1.0.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/README.md +272 -0
- package/dist/Client.d.ts +60 -0
- package/dist/Client.js +220 -0
- package/dist/ClientResponseError.d.ts +25 -0
- package/dist/ClientResponseError.js +46 -0
- package/dist/index.cjs +1428 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1405 -0
- package/dist/services/BaseService.d.ts +7 -0
- package/dist/services/BaseService.js +9 -0
- package/dist/services/CollectionService.d.ts +42 -0
- package/dist/services/CollectionService.js +94 -0
- package/dist/services/FileService.d.ts +71 -0
- package/dist/services/FileService.js +119 -0
- package/dist/services/HooksService.d.ts +76 -0
- package/dist/services/HooksService.js +135 -0
- package/dist/services/LogService.d.ts +32 -0
- package/dist/services/LogService.js +63 -0
- package/dist/services/RealtimeService.d.ts +28 -0
- package/dist/services/RealtimeService.js +186 -0
- package/dist/services/RecordService.d.ts +105 -0
- package/dist/services/RecordService.js +287 -0
- package/dist/services/SuperuserService.d.ts +35 -0
- package/dist/services/SuperuserService.js +80 -0
- package/dist/stores/AsyncAuthStore.d.ts +13 -0
- package/dist/stores/AsyncAuthStore.js +32 -0
- package/dist/stores/BaseAuthStore.d.ts +18 -0
- package/dist/stores/BaseAuthStore.js +81 -0
- package/dist/stores/LocalAuthStore.d.ts +8 -0
- package/dist/stores/LocalAuthStore.js +43 -0
- package/dist/types.d.ts +241 -0
- package/dist/types.js +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AlsaBase } from "../Client";
|
|
2
|
+
import type { SendOptions } from "../types";
|
|
3
|
+
export declare abstract class BaseService {
|
|
4
|
+
readonly client: AlsaBase;
|
|
5
|
+
constructor(client: AlsaBase);
|
|
6
|
+
protected send<T = any>(path: string, options?: SendOptions): Promise<T>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
import type { CollectionModel, ListResult, ListOptions, CommonOptions } from "../types";
|
|
3
|
+
export declare class CollectionService extends BaseService {
|
|
4
|
+
/**
|
|
5
|
+
* Returns a list of all collections (Superuser required)
|
|
6
|
+
*/
|
|
7
|
+
getFullList(options?: CommonOptions): Promise<CollectionModel[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a paginated list of collections
|
|
10
|
+
*/
|
|
11
|
+
getList(page?: number, perPage?: number, options?: ListOptions): Promise<ListResult<CollectionModel>>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns a single collection schema by its name or ID (Superuser required)
|
|
14
|
+
*/
|
|
15
|
+
getOne(idOrName: string, options?: CommonOptions): Promise<CollectionModel>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the schema and column definitions of a table/collection (Superuser required)
|
|
18
|
+
* Alias for getOne()
|
|
19
|
+
*/
|
|
20
|
+
getSchema(idOrName: string, options?: CommonOptions): Promise<CollectionModel>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the schema of a table/collection (Superuser required)
|
|
23
|
+
* Alias for getOne()
|
|
24
|
+
*/
|
|
25
|
+
getTableSchema(idOrName: string, options?: CommonOptions): Promise<CollectionModel>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new collection schema
|
|
28
|
+
*/
|
|
29
|
+
create(data: Partial<CollectionModel>, options?: CommonOptions): Promise<CollectionModel>;
|
|
30
|
+
/**
|
|
31
|
+
* Updates an existing collection schema
|
|
32
|
+
*/
|
|
33
|
+
update(idOrName: string, data: Partial<CollectionModel>, options?: CommonOptions): Promise<CollectionModel>;
|
|
34
|
+
/**
|
|
35
|
+
* Deletes a collection schema
|
|
36
|
+
*/
|
|
37
|
+
delete(idOrName: string, options?: CommonOptions): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Truncates all records in a collection
|
|
40
|
+
*/
|
|
41
|
+
truncate(idOrName: string, options?: CommonOptions): Promise<boolean>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
export class CollectionService extends BaseService {
|
|
3
|
+
/**
|
|
4
|
+
* Returns a list of all collections (Superuser required)
|
|
5
|
+
*/
|
|
6
|
+
async getFullList(options) {
|
|
7
|
+
const res = await this.send("/api/collections", {
|
|
8
|
+
method: "GET",
|
|
9
|
+
...options,
|
|
10
|
+
});
|
|
11
|
+
return res.items || [];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns a paginated list of collections
|
|
15
|
+
*/
|
|
16
|
+
async getList(page = 1, perPage = 30, options) {
|
|
17
|
+
const all = await this.getFullList(options);
|
|
18
|
+
const start = (page - 1) * perPage;
|
|
19
|
+
const end = start + perPage;
|
|
20
|
+
const items = all.slice(start, end);
|
|
21
|
+
const total = all.length;
|
|
22
|
+
const totalPages = Math.ceil(total / perPage) || 1;
|
|
23
|
+
return {
|
|
24
|
+
page,
|
|
25
|
+
perPage,
|
|
26
|
+
totalItems: total,
|
|
27
|
+
totalPages,
|
|
28
|
+
items,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns a single collection schema by its name or ID (Superuser required)
|
|
33
|
+
*/
|
|
34
|
+
async getOne(idOrName, options) {
|
|
35
|
+
return this.send(`/api/collections/${encodeURIComponent(idOrName)}/schema`, {
|
|
36
|
+
method: "GET",
|
|
37
|
+
...options,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the schema and column definitions of a table/collection (Superuser required)
|
|
42
|
+
* Alias for getOne()
|
|
43
|
+
*/
|
|
44
|
+
async getSchema(idOrName, options) {
|
|
45
|
+
return this.getOne(idOrName, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the schema of a table/collection (Superuser required)
|
|
49
|
+
* Alias for getOne()
|
|
50
|
+
*/
|
|
51
|
+
async getTableSchema(idOrName, options) {
|
|
52
|
+
return this.getOne(idOrName, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new collection schema
|
|
56
|
+
*/
|
|
57
|
+
async create(data, options) {
|
|
58
|
+
return this.send("/api/collections", {
|
|
59
|
+
method: "POST",
|
|
60
|
+
body: data,
|
|
61
|
+
...options,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Updates an existing collection schema
|
|
66
|
+
*/
|
|
67
|
+
async update(idOrName, data, options) {
|
|
68
|
+
return this.send(`/api/collections/${encodeURIComponent(idOrName)}`, {
|
|
69
|
+
method: "PATCH",
|
|
70
|
+
body: data,
|
|
71
|
+
...options,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Deletes a collection schema
|
|
76
|
+
*/
|
|
77
|
+
async delete(idOrName, options) {
|
|
78
|
+
await this.send(`/api/collections/${encodeURIComponent(idOrName)}`, {
|
|
79
|
+
method: "DELETE",
|
|
80
|
+
...options,
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Truncates all records in a collection
|
|
86
|
+
*/
|
|
87
|
+
async truncate(idOrName, options) {
|
|
88
|
+
await this.send(`/api/collections/${encodeURIComponent(idOrName)}/truncate`, {
|
|
89
|
+
method: "DELETE",
|
|
90
|
+
...options,
|
|
91
|
+
});
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
import type { FileDetailResponse, TreeResponse, BatchUploadFileItem, BatchUploadResponse, CommonOptions } from "../types";
|
|
3
|
+
export declare class FileService extends BaseService {
|
|
4
|
+
/**
|
|
5
|
+
* Generates a URL for accessing an uploaded record file asset
|
|
6
|
+
*
|
|
7
|
+
* @param record Record object or record ID string
|
|
8
|
+
* @param filename Filename of the uploaded asset
|
|
9
|
+
* @param queryParams Optional query parameters (e.g. thumb, download)
|
|
10
|
+
*/
|
|
11
|
+
getUrl(record: {
|
|
12
|
+
id?: string;
|
|
13
|
+
collectionName?: string;
|
|
14
|
+
collectionId?: string;
|
|
15
|
+
} | string, filename: string, queryParams?: Record<string, any>): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a URL for a public website static asset hosted in _public
|
|
18
|
+
*
|
|
19
|
+
* @param relPath Relative path inside _public (e.g. 'images/banner.png' or 'maps/mafia/lost-heaven/')
|
|
20
|
+
*/
|
|
21
|
+
getPublicUrl(relPath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Lists all files in the _public directory
|
|
24
|
+
*/
|
|
25
|
+
listPublicFiles(options?: CommonOptions): Promise<{
|
|
26
|
+
items: any[];
|
|
27
|
+
total: number;
|
|
28
|
+
publicDir: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Gets a folder tree for the _public directory
|
|
32
|
+
*/
|
|
33
|
+
getPublicTree(dir?: string, options?: CommonOptions): Promise<TreeResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Reads a file's content from the _public directory
|
|
36
|
+
*/
|
|
37
|
+
readPublicFile(path: string, options?: CommonOptions): Promise<FileDetailResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Saves or updates a file in the _public directory (Superuser required)
|
|
40
|
+
*/
|
|
41
|
+
savePublicFile(name: string, content: string, isBase64?: boolean, options?: CommonOptions): Promise<{
|
|
42
|
+
name: string;
|
|
43
|
+
saved: boolean;
|
|
44
|
+
path: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Uploads a batch of files to the _public directory (Superuser required)
|
|
48
|
+
*/
|
|
49
|
+
uploadPublicBatch(files: BatchUploadFileItem[], options?: CommonOptions): Promise<BatchUploadResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Deletes a file in the _public directory (Superuser required)
|
|
52
|
+
*/
|
|
53
|
+
deletePublicFile(path: string, options?: CommonOptions): Promise<{
|
|
54
|
+
success: boolean;
|
|
55
|
+
message: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a folder inside the _public directory (Superuser required)
|
|
59
|
+
*/
|
|
60
|
+
createPublicFolder(path: string, options?: CommonOptions): Promise<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
path: string;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Deletes a folder and all its contents inside the _public directory (Superuser required)
|
|
66
|
+
*/
|
|
67
|
+
deletePublicFolder(path: string, options?: CommonOptions): Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
message: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
export class FileService extends BaseService {
|
|
3
|
+
/**
|
|
4
|
+
* Generates a URL for accessing an uploaded record file asset
|
|
5
|
+
*
|
|
6
|
+
* @param record Record object or record ID string
|
|
7
|
+
* @param filename Filename of the uploaded asset
|
|
8
|
+
* @param queryParams Optional query parameters (e.g. thumb, download)
|
|
9
|
+
*/
|
|
10
|
+
getUrl(record, filename, queryParams) {
|
|
11
|
+
if (!filename)
|
|
12
|
+
return "";
|
|
13
|
+
let fileUrlPath;
|
|
14
|
+
if (typeof record === "object" && record !== null) {
|
|
15
|
+
const col = record.collectionName || record.collectionId || "";
|
|
16
|
+
const id = record.id || "";
|
|
17
|
+
if (col && id) {
|
|
18
|
+
fileUrlPath = `/api/static-files/file/${encodeURIComponent(col)}/${encodeURIComponent(id)}/${encodeURIComponent(filename)}`;
|
|
19
|
+
}
|
|
20
|
+
else if (id) {
|
|
21
|
+
fileUrlPath = `/api/static-files/file/${encodeURIComponent(id)}/${encodeURIComponent(filename)}`;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
fileUrlPath = `/api/static-files/file/${encodeURIComponent(filename)}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (typeof record === "string" && record) {
|
|
28
|
+
fileUrlPath = `/api/static-files/file/${encodeURIComponent(record)}/${encodeURIComponent(filename)}`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
fileUrlPath = `/api/static-files/file/${encodeURIComponent(filename)}`;
|
|
32
|
+
}
|
|
33
|
+
return this.client.buildUrl(fileUrlPath, queryParams);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generates a URL for a public website static asset hosted in _public
|
|
37
|
+
*
|
|
38
|
+
* @param relPath Relative path inside _public (e.g. 'images/banner.png' or 'maps/mafia/lost-heaven/')
|
|
39
|
+
*/
|
|
40
|
+
getPublicUrl(relPath) {
|
|
41
|
+
const clean = relPath.replace(/^[\/\\]+/, "");
|
|
42
|
+
return `${this.client.baseUrl.replace(/\/+$/, "")}/${clean}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lists all files in the _public directory
|
|
46
|
+
*/
|
|
47
|
+
async listPublicFiles(options) {
|
|
48
|
+
return this.send("/api/static-files", {
|
|
49
|
+
method: "GET",
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets a folder tree for the _public directory
|
|
55
|
+
*/
|
|
56
|
+
async getPublicTree(dir = "", options) {
|
|
57
|
+
return this.send(`/api/static-files/tree?dir=${encodeURIComponent(dir)}`, {
|
|
58
|
+
method: "GET",
|
|
59
|
+
...options,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reads a file's content from the _public directory
|
|
64
|
+
*/
|
|
65
|
+
async readPublicFile(path, options) {
|
|
66
|
+
return this.send(`/api/static-files/file?path=${encodeURIComponent(path)}`, {
|
|
67
|
+
method: "GET",
|
|
68
|
+
...options,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Saves or updates a file in the _public directory (Superuser required)
|
|
73
|
+
*/
|
|
74
|
+
async savePublicFile(name, content, isBase64 = false, options) {
|
|
75
|
+
return this.send("/api/static-files/file", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: { name, content, isBase64 },
|
|
78
|
+
...options,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Uploads a batch of files to the _public directory (Superuser required)
|
|
83
|
+
*/
|
|
84
|
+
async uploadPublicBatch(files, options) {
|
|
85
|
+
return this.send("/api/static-files/upload-batch", {
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: { files },
|
|
88
|
+
...options,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Deletes a file in the _public directory (Superuser required)
|
|
93
|
+
*/
|
|
94
|
+
async deletePublicFile(path, options) {
|
|
95
|
+
return this.send(`/api/static-files/file?path=${encodeURIComponent(path)}`, {
|
|
96
|
+
method: "DELETE",
|
|
97
|
+
...options,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a folder inside the _public directory (Superuser required)
|
|
102
|
+
*/
|
|
103
|
+
async createPublicFolder(path, options) {
|
|
104
|
+
return this.send("/api/static-files/folder", {
|
|
105
|
+
method: "POST",
|
|
106
|
+
body: { path },
|
|
107
|
+
...options,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Deletes a folder and all its contents inside the _public directory (Superuser required)
|
|
112
|
+
*/
|
|
113
|
+
async deletePublicFolder(path, options) {
|
|
114
|
+
return this.send(`/api/static-files/folder?path=${encodeURIComponent(path)}`, {
|
|
115
|
+
method: "DELETE",
|
|
116
|
+
...options,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
import type { HooksOverview, FileDetailResponse, TreeResponse, BatchUploadFileItem, BatchUploadResponse, CommonOptions } from "../types";
|
|
3
|
+
export declare class HooksService extends BaseService {
|
|
4
|
+
/**
|
|
5
|
+
* Returns an overview of all active hooks, routes, crons, and commands (Superuser required)
|
|
6
|
+
*/
|
|
7
|
+
getOverview(options?: CommonOptions): Promise<HooksOverview>;
|
|
8
|
+
/**
|
|
9
|
+
* Lists all files in the _hooks directory (Superuser required)
|
|
10
|
+
*/
|
|
11
|
+
listFiles(options?: CommonOptions): Promise<{
|
|
12
|
+
items: any[];
|
|
13
|
+
total: number;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Gets a folder tree for the _hooks directory (Superuser required)
|
|
17
|
+
*/
|
|
18
|
+
getTree(dir?: string, options?: CommonOptions): Promise<TreeResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Reads a file's content from the _hooks directory (Superuser required)
|
|
21
|
+
*/
|
|
22
|
+
readFile(path: string, options?: CommonOptions): Promise<FileDetailResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Saves or updates a file in the _hooks directory (Superuser required)
|
|
25
|
+
*/
|
|
26
|
+
saveFile(name: string, content: string, isBase64?: boolean, options?: CommonOptions): Promise<{
|
|
27
|
+
name: string;
|
|
28
|
+
saved: boolean;
|
|
29
|
+
path: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Uploads a batch of files to the _hooks directory (Superuser required)
|
|
33
|
+
*/
|
|
34
|
+
uploadBatch(files: BatchUploadFileItem[], options?: CommonOptions): Promise<BatchUploadResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Deletes a file in the _hooks directory (Superuser required)
|
|
37
|
+
*/
|
|
38
|
+
deleteFile(path: string, options?: CommonOptions): Promise<{
|
|
39
|
+
success: boolean;
|
|
40
|
+
message: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a folder inside the _hooks directory (Superuser required)
|
|
44
|
+
*/
|
|
45
|
+
createFolder(path: string, options?: CommonOptions): Promise<{
|
|
46
|
+
success: boolean;
|
|
47
|
+
path: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Deletes a folder and all its contents inside the _hooks directory (Superuser required)
|
|
51
|
+
*/
|
|
52
|
+
deleteFolder(path: string, options?: CommonOptions): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
message: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Manually triggers execution of a scheduled cron job (Superuser required)
|
|
58
|
+
*/
|
|
59
|
+
triggerCron(name: string, options?: CommonOptions): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Cancels a running cron job (Superuser required)
|
|
62
|
+
*/
|
|
63
|
+
cancelCron(executionId?: string, name?: string, options?: CommonOptions): Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* Runs a custom hook CLI command (Superuser required)
|
|
66
|
+
*/
|
|
67
|
+
runCommand(name: string, args?: any, options?: CommonOptions): Promise<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Cancels a running CLI command (Superuser required)
|
|
70
|
+
*/
|
|
71
|
+
cancelCommand(executionId?: string, name?: string, options?: CommonOptions): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Reloads all hook files and re-registers custom routes (Superuser required)
|
|
74
|
+
*/
|
|
75
|
+
reload(options?: CommonOptions): Promise<any>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
export class HooksService extends BaseService {
|
|
3
|
+
/**
|
|
4
|
+
* Returns an overview of all active hooks, routes, crons, and commands (Superuser required)
|
|
5
|
+
*/
|
|
6
|
+
async getOverview(options) {
|
|
7
|
+
return this.send("/api/hooks", {
|
|
8
|
+
method: "GET",
|
|
9
|
+
...options,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Lists all files in the _hooks directory (Superuser required)
|
|
14
|
+
*/
|
|
15
|
+
async listFiles(options) {
|
|
16
|
+
return this.send("/api/hooks/files", {
|
|
17
|
+
method: "GET",
|
|
18
|
+
...options,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets a folder tree for the _hooks directory (Superuser required)
|
|
23
|
+
*/
|
|
24
|
+
async getTree(dir = "", options) {
|
|
25
|
+
return this.send(`/api/hooks/tree?dir=${encodeURIComponent(dir)}`, {
|
|
26
|
+
method: "GET",
|
|
27
|
+
...options,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads a file's content from the _hooks directory (Superuser required)
|
|
32
|
+
*/
|
|
33
|
+
async readFile(path, options) {
|
|
34
|
+
return this.send(`/api/hooks/files/file?path=${encodeURIComponent(path)}`, {
|
|
35
|
+
method: "GET",
|
|
36
|
+
...options,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Saves or updates a file in the _hooks directory (Superuser required)
|
|
41
|
+
*/
|
|
42
|
+
async saveFile(name, content, isBase64 = false, options) {
|
|
43
|
+
return this.send("/api/hooks/files", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: { name, content, isBase64 },
|
|
46
|
+
...options,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Uploads a batch of files to the _hooks directory (Superuser required)
|
|
51
|
+
*/
|
|
52
|
+
async uploadBatch(files, options) {
|
|
53
|
+
return this.send("/api/hooks/files/upload-batch", {
|
|
54
|
+
method: "POST",
|
|
55
|
+
body: { files },
|
|
56
|
+
...options,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Deletes a file in the _hooks directory (Superuser required)
|
|
61
|
+
*/
|
|
62
|
+
async deleteFile(path, options) {
|
|
63
|
+
return this.send(`/api/hooks/files/file?path=${encodeURIComponent(path)}`, {
|
|
64
|
+
method: "DELETE",
|
|
65
|
+
...options,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a folder inside the _hooks directory (Superuser required)
|
|
70
|
+
*/
|
|
71
|
+
async createFolder(path, options) {
|
|
72
|
+
return this.send("/api/hooks/files/folder", {
|
|
73
|
+
method: "POST",
|
|
74
|
+
body: { path },
|
|
75
|
+
...options,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Deletes a folder and all its contents inside the _hooks directory (Superuser required)
|
|
80
|
+
*/
|
|
81
|
+
async deleteFolder(path, options) {
|
|
82
|
+
return this.send(`/api/hooks/files/folder?path=${encodeURIComponent(path)}`, {
|
|
83
|
+
method: "DELETE",
|
|
84
|
+
...options,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Manually triggers execution of a scheduled cron job (Superuser required)
|
|
89
|
+
*/
|
|
90
|
+
async triggerCron(name, options) {
|
|
91
|
+
return this.send(`/api/hooks/cron/${encodeURIComponent(name)}/trigger`, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
...options,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Cancels a running cron job (Superuser required)
|
|
98
|
+
*/
|
|
99
|
+
async cancelCron(executionId, name, options) {
|
|
100
|
+
return this.send("/api/hooks/cron/cancel", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: { executionId, name },
|
|
103
|
+
...options,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Runs a custom hook CLI command (Superuser required)
|
|
108
|
+
*/
|
|
109
|
+
async runCommand(name, args, options) {
|
|
110
|
+
return this.send(`/api/hooks/commands/${encodeURIComponent(name)}/run`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
body: { args },
|
|
113
|
+
...options,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Cancels a running CLI command (Superuser required)
|
|
118
|
+
*/
|
|
119
|
+
async cancelCommand(executionId, name, options) {
|
|
120
|
+
return this.send("/api/hooks/commands/cancel", {
|
|
121
|
+
method: "POST",
|
|
122
|
+
body: { executionId, name },
|
|
123
|
+
...options,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reloads all hook files and re-registers custom routes (Superuser required)
|
|
128
|
+
*/
|
|
129
|
+
async reload(options) {
|
|
130
|
+
return this.send("/api/hooks/reload", {
|
|
131
|
+
method: "POST",
|
|
132
|
+
...options,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
import type { LogModel, LogListOptions, LogStats, LogTimelineItem, ListResult, CommonOptions } from "../types";
|
|
3
|
+
export declare class LogService extends BaseService {
|
|
4
|
+
/**
|
|
5
|
+
* Returns a paginated list of system access and error logs (Superuser required)
|
|
6
|
+
*/
|
|
7
|
+
getList(page?: number, perPage?: number, options?: LogListOptions): Promise<ListResult<LogModel>>;
|
|
8
|
+
/**
|
|
9
|
+
* Returns timeline distribution of system requests and errors
|
|
10
|
+
*/
|
|
11
|
+
getTimeline(options?: CommonOptions): Promise<{
|
|
12
|
+
timeline: LogTimelineItem[];
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns summary stats for server logs
|
|
16
|
+
*/
|
|
17
|
+
getStats(options?: CommonOptions): Promise<LogStats>;
|
|
18
|
+
/**
|
|
19
|
+
* Deletes a batch of logs by IDs or all matching filter criteria
|
|
20
|
+
*/
|
|
21
|
+
deleteBatch(params: {
|
|
22
|
+
ids?: string[];
|
|
23
|
+
all?: boolean;
|
|
24
|
+
level?: string;
|
|
25
|
+
search?: string;
|
|
26
|
+
includeSuperusers?: boolean;
|
|
27
|
+
}, options?: CommonOptions): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* Clears all system logs
|
|
30
|
+
*/
|
|
31
|
+
clear(options?: CommonOptions): Promise<boolean>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
export class LogService extends BaseService {
|
|
3
|
+
/**
|
|
4
|
+
* Returns a paginated list of system access and error logs (Superuser required)
|
|
5
|
+
*/
|
|
6
|
+
async getList(page = 1, perPage = 50, options) {
|
|
7
|
+
const query = {
|
|
8
|
+
page,
|
|
9
|
+
limit: perPage,
|
|
10
|
+
...options,
|
|
11
|
+
};
|
|
12
|
+
const res = await this.send("/api/logs", {
|
|
13
|
+
method: "GET",
|
|
14
|
+
query,
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
page: res.page,
|
|
19
|
+
perPage: res.limit,
|
|
20
|
+
totalItems: res.total,
|
|
21
|
+
totalPages: res.totalPages,
|
|
22
|
+
items: res.items,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns timeline distribution of system requests and errors
|
|
27
|
+
*/
|
|
28
|
+
async getTimeline(options) {
|
|
29
|
+
return this.send("/api/logs/timeline", {
|
|
30
|
+
method: "GET",
|
|
31
|
+
...options,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns summary stats for server logs
|
|
36
|
+
*/
|
|
37
|
+
async getStats(options) {
|
|
38
|
+
return this.send("/api/logs/stats", {
|
|
39
|
+
method: "GET",
|
|
40
|
+
...options,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deletes a batch of logs by IDs or all matching filter criteria
|
|
45
|
+
*/
|
|
46
|
+
async deleteBatch(params, options) {
|
|
47
|
+
return this.send("/api/logs/delete-batch", {
|
|
48
|
+
method: "POST",
|
|
49
|
+
body: params,
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Clears all system logs
|
|
55
|
+
*/
|
|
56
|
+
async clear(options) {
|
|
57
|
+
await this.send("/api/logs", {
|
|
58
|
+
method: "DELETE",
|
|
59
|
+
...options,
|
|
60
|
+
});
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService";
|
|
2
|
+
import type { RealtimeListener, UnsubscribeFunc } from "../types";
|
|
3
|
+
export declare class RealtimeService extends BaseService {
|
|
4
|
+
private subscriptions;
|
|
5
|
+
private socket;
|
|
6
|
+
private isConnecting;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if realtime is currently connected
|
|
9
|
+
*/
|
|
10
|
+
get isConnected(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Subscribes a listener callback to a specific topic or collection
|
|
13
|
+
*/
|
|
14
|
+
subscribe<T = any>(topic: string, listener: RealtimeListener<T>): Promise<UnsubscribeFunc>;
|
|
15
|
+
/**
|
|
16
|
+
* Unsubscribes all listeners or a specific listener from a topic
|
|
17
|
+
*/
|
|
18
|
+
unsubscribe(topic?: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Publishes a custom event to a realtime topic
|
|
21
|
+
*/
|
|
22
|
+
publish(topic: string, data: any, event?: string): Promise<void>;
|
|
23
|
+
private unsubscribeFromTopic;
|
|
24
|
+
private ensureConnection;
|
|
25
|
+
private connect;
|
|
26
|
+
private dispatchMessage;
|
|
27
|
+
private disconnect;
|
|
28
|
+
}
|