badmfck-api-server 3.9.8 → 3.9.9
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/dist/apiServer/APIService.d.ts +0 -1
- package/dist/apiServer/APIService.js +2 -3
- package/dist/apiServer/BaseEndpoint.js +2 -2
- package/dist/apiServer/DBService.d.ts +1 -1
- package/dist/apiServer/helper/UID.js +2 -2
- package/dist/apiServer/helper/Validator.d.ts +10 -4
- package/dist/apiServer/helper/Validator.js +29 -23
- package/dist/apiServer/helper/ZipUtils.d.ts +8 -0
- package/dist/apiServer/helper/ZipUtils.js +28 -0
- package/dist/apiServer/interceptors/IntHmacSha256.d.ts +5 -0
- package/dist/apiServer/interceptors/IntHmacSha256.js +22 -0
- package/dist/apiServer/structures/DefaultErrors.d.ts +4 -3
- package/dist/apiServer/structures/DefaultErrors.js +5 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/dist/apiServer/APIService.js.map +0 -1
- package/dist/apiServer/BaseEndpoint.js.map +0 -1
- package/dist/apiServer/BaseService.js.map +0 -1
- package/dist/apiServer/ClusterService.d.ts +0 -30
- package/dist/apiServer/ClusterService.js +0 -81
- package/dist/apiServer/ClusterService.js.map +0 -1
- package/dist/apiServer/DocumentService.js.map +0 -1
- package/dist/apiServer/HUBService.d.ts +0 -37
- package/dist/apiServer/HUBService.js +0 -132
- package/dist/apiServer/HUBService.js.map +0 -1
- package/dist/apiServer/LocalRequest.js.map +0 -1
- package/dist/apiServer/LogService.js.map +0 -1
- package/dist/apiServer/MysqlService.js.map +0 -1
- package/dist/apiServer/WSAPITransport.js.map +0 -1
- package/dist/apiServer/WebSocketHandler.js.map +0 -1
- package/dist/apiServer/Websocket.d.ts +0 -8
- package/dist/apiServer/Websocket.js +0 -15
- package/dist/apiServer/WebsocketService.d.ts +0 -8
- package/dist/apiServer/WebsocketService.js +0 -18
- package/dist/apiServer/WebsocketService.js.map +0 -1
- package/dist/apiServer/cluster/HUBConnection.d.ts +0 -39
- package/dist/apiServer/cluster/HUBConnection.js +0 -251
- package/dist/apiServer/cluster/HUBConnection.js.map +0 -1
- package/dist/apiServer/cluster/HUBHandlres.d.ts +0 -0
- package/dist/apiServer/cluster/HUBHandlres.js +0 -2
- package/dist/apiServer/cluster/HUBHandlres.js.map +0 -1
- package/dist/apiServer/deployment/Deployment.js.map +0 -1
- package/dist/apiServer/helper/DataProvider.js.map +0 -1
- package/dist/apiServer/helper/Sleep.js.map +0 -1
- package/dist/apiServer/helper/UID.js.map +0 -1
- package/dist/apiServer/helper/Validator.js.map +0 -1
- package/dist/apiServer/monitor/Monitor.js.map +0 -1
- package/dist/apiServer/routes/Liveness.js.map +0 -1
- package/dist/apiServer/routes/Monitor.d.ts +0 -9
- package/dist/apiServer/routes/Monitor.js +0 -77
- package/dist/apiServer/routes/Readiness.js.map +0 -1
- package/dist/apiServer/structures/DefaultErrors.js.map +0 -1
- package/dist/apiServer/structures/HTTPStatus.js.map +0 -1
- package/dist/apiServer/structures/Interfaces.js.map +0 -1
@@ -48,7 +48,6 @@ type InferInterceptor<T> = T extends IInterceptor<infer U> ? U : unknown;
|
|
48
48
|
export declare const getDefaultOptions: <I extends IInterceptor<any> | undefined>(overrides?: (Omit<Partial<APIServiceOptions<InferInterceptor<NonNullable<I>>>>, "interceptor"> & {
|
49
49
|
interceptor?: I | undefined;
|
50
50
|
}) | undefined) => APIServiceOptions<InferInterceptor<NonNullable<I>>>;
|
51
|
-
export declare const REQ_DEPREACTED_CREATE_NET_LOG: Req<void, APIServiceNetworkLogItem>;
|
52
51
|
export declare const REQ_HTTP_LOG: Req<void, APIServiceNetworkLogItem[]>;
|
53
52
|
export declare const REQ_HTTP_REQUESTS_COUNT: Req<void, number>;
|
54
53
|
export declare const REQ_HTTP_SERVER: Req<void, {
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.APIService = exports.Initializer = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.
|
29
|
+
exports.APIService = exports.Initializer = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
30
30
|
const express_1 = __importDefault(require("express"));
|
31
31
|
const BaseService_1 = require("./BaseService");
|
32
32
|
const cors_1 = __importDefault(require("cors"));
|
@@ -72,7 +72,6 @@ const getDefaultOptions = (overrides) => {
|
|
72
72
|
return { ...base, ...overrides };
|
73
73
|
};
|
74
74
|
exports.getDefaultOptions = getDefaultOptions;
|
75
|
-
exports.REQ_DEPREACTED_CREATE_NET_LOG = new badmfck_signal_1.Req(undefined, "REQ_CREATE_NET_LOG");
|
76
75
|
exports.REQ_HTTP_LOG = new badmfck_signal_1.Req(undefined, "REQ_HTTP_LOG");
|
77
76
|
exports.REQ_HTTP_REQUESTS_COUNT = new badmfck_signal_1.Req(undefined, "REQ_HTTP_REQUESTS_COUNT");
|
78
77
|
exports.REQ_HTTP_SERVER = new badmfck_signal_1.Req(undefined, "REQ_HTTP_SERVER");
|
@@ -93,7 +92,7 @@ async function Initializer(services) {
|
|
93
92
|
}
|
94
93
|
exports.Initializer = Initializer;
|
95
94
|
class APIService extends BaseService_1.BaseService {
|
96
|
-
version = "3.9.
|
95
|
+
version = "3.9.9";
|
97
96
|
options;
|
98
97
|
monitor = null;
|
99
98
|
started = new Date();
|
@@ -122,10 +122,10 @@ class BaseEndpoint {
|
|
122
122
|
if (!structure)
|
123
123
|
return;
|
124
124
|
if (typeof structure === "object" && (!req.data || typeof req.data !== "object"))
|
125
|
-
throw { ...DefaultErrors_1.default.
|
125
|
+
throw { ...DefaultErrors_1.default.WRONG_PARAMS, details: "empty or invalid request" };
|
126
126
|
const report = await Validator_1.Validator.validateStructure(structure, req.data);
|
127
127
|
if (report)
|
128
|
-
throw { ...DefaultErrors_1.default.
|
128
|
+
throw { ...DefaultErrors_1.default.WRONG_PARAMS, details: report };
|
129
129
|
Validator_1.Validator.filterStructure(structure, req.data);
|
130
130
|
}
|
131
131
|
createStream(req) {
|
@@ -12,7 +12,7 @@ export interface IDBQueryField {
|
|
12
12
|
fields?: Record<string, number | boolean | string | null>;
|
13
13
|
}
|
14
14
|
export interface IDBQueryFields {
|
15
|
-
[key: string]: string | number | boolean | IDBQueryField | null;
|
15
|
+
[key: string]: string | number | boolean | IDBQueryField | null | undefined;
|
16
16
|
}
|
17
17
|
export interface IDBQuery {
|
18
18
|
dbid?: string;
|
@@ -14,8 +14,8 @@ class UID {
|
|
14
14
|
+ ""
|
15
15
|
+ Math.round(Math.random() * 1000)).toString(16), 'hex').toString('base64');
|
16
16
|
uid = uid.replaceAll("=", "");
|
17
|
-
uid = uid.replaceAll("+", "
|
18
|
-
uid = uid.replaceAll("/", "
|
17
|
+
uid = uid.replaceAll("+", "pL");
|
18
|
+
uid = uid.replaceAll("/", "sl");
|
19
19
|
return uid;
|
20
20
|
}
|
21
21
|
static generateRandomNumberBase(count) {
|
@@ -8,6 +8,7 @@ export interface IStructureOptions {
|
|
8
8
|
min?: number;
|
9
9
|
max?: number;
|
10
10
|
details?: string;
|
11
|
+
type?: string;
|
11
12
|
}
|
12
13
|
export interface IValidatorOptions {
|
13
14
|
min?: number;
|
@@ -48,19 +49,24 @@ type ExtractOptionalFieldNames<T> = {
|
|
48
49
|
[K in (keyof T & string) as HasOptional<T, K> extends true ? K : never]: true;
|
49
50
|
};
|
50
51
|
type OptionalFields<T> = keyof ExtractOptionalFieldNames<T> & string;
|
51
|
-
type ValuesArr<T, K extends string> = `$__${K}_values` extends keyof T ? T[`$__${K}_values`] extends readonly (infer V)[] ? readonly V[] : never : `$__${K}` extends keyof T ? T[`$__${K}`] extends {
|
52
|
+
type ValuesArr<T, K extends string> = `$__${K}_values` extends keyof T ? T[`$__${K}_values`] extends readonly (infer V)[] ? readonly V[] : T[`$__${K}_values`] extends (infer V)[] ? readonly V[] : T[`$__${K}_values`] extends Record<string, infer V> ? readonly V[] : never : `$__${K}` extends keyof T ? T[`$__${K}`] extends {
|
52
53
|
values: readonly (infer V)[];
|
54
|
+
} ? readonly V[] : T[`$__${K}`] extends {
|
55
|
+
values: (infer V)[];
|
56
|
+
} ? readonly V[] : T[`$__${K}`] extends {
|
57
|
+
values: Record<string, infer V>;
|
53
58
|
} ? readonly V[] : never : never;
|
54
59
|
type ExtractEnumValues<T> = {
|
55
60
|
[K in (keyof T & string) as IsNever<ValuesArr<T, K>> extends true ? never : K]: ValuesArr<T, K> extends ReadonlyArray<infer V> ? V : never;
|
56
61
|
};
|
57
62
|
type EnumFieldNames<T> = keyof ExtractEnumValues<T> & string;
|
58
63
|
type EnumFieldValues<T> = ExtractEnumValues<T>;
|
59
|
-
type
|
64
|
+
type FieldOriginal<T, K extends PropertyKey> = K extends keyof T ? T[K] : never;
|
65
|
+
type ProcessValue<T, K extends keyof CleanFields<T>> = FieldOriginal<T, K> extends ReadonlyArray<infer Item> ? Item extends object ? ValidationModel<Item>[] : WidenLiteral<Item>[] : FieldOriginal<T, K> extends Array<infer Item> ? Item extends object ? ValidationModel<Item>[] : WidenLiteral<Item>[] : FieldOriginal<T, K> extends (...a: any[]) => any ? FieldOriginal<T, K> : FieldOriginal<T, K> extends object ? ValidationModel<FieldOriginal<T, K>> : WidenLiteral<FieldOriginal<T, K>>;
|
60
66
|
export type ValidationModel<T> = DeepMutable<{
|
61
|
-
[K in keyof CleanFields<T> as K extends OptionalFields<T> ? K : never]?: K extends EnumFieldNames<T> ? EnumFieldValues<T>[K] :
|
67
|
+
[K in keyof CleanFields<T> as K extends OptionalFields<T> ? K : never]?: K extends EnumFieldNames<T> ? EnumFieldValues<T>[K] : ProcessValue<T, K>;
|
62
68
|
} & {
|
63
|
-
[K in keyof CleanFields<T> as K extends OptionalFields<T> ? never : K]: K extends EnumFieldNames<T> ? EnumFieldValues<T>[K] :
|
69
|
+
[K in keyof CleanFields<T> as K extends OptionalFields<T> ? never : K]: K extends EnumFieldNames<T> ? EnumFieldValues<T>[K] : ProcessValue<T, K>;
|
64
70
|
}>;
|
65
71
|
export declare class Validator {
|
66
72
|
static validateObject(fields: string[], object: any): boolean;
|
@@ -31,30 +31,12 @@ class Validator {
|
|
31
31
|
for (let i in structure) {
|
32
32
|
if (i.startsWith("$__"))
|
33
33
|
continue;
|
34
|
-
let
|
35
|
-
let description = structure['$__' + i] || "";
|
34
|
+
let structureOptions = Validator.parseStructureOptions(i, structure);
|
36
35
|
let childs = undefined;
|
37
|
-
let optional = structure['$__' + i + "_optional"] || "";
|
38
|
-
let regex = structure['$__' + i + '_regex'] || undefined;
|
39
|
-
let min = structure['$__' + i + "_min"] || undefined;
|
40
|
-
let max = structure['$__' + i + "_max"] || undefined;
|
41
|
-
let values = structure['$__' + i + "_values"] || undefined;
|
42
|
-
if (optional === undefined)
|
43
|
-
optional = structure[i] === null || structure[i] === undefined;
|
44
|
-
if (type === "object" && Array.isArray(structure[i]))
|
45
|
-
type = "array";
|
46
36
|
if (typeof structure[i] === "object")
|
47
37
|
childs = this.documentStructure(structure[i]);
|
48
|
-
if (structure[i] === "@")
|
49
|
-
type = "email";
|
50
38
|
params[i] = {
|
51
|
-
|
52
|
-
description: description,
|
53
|
-
optional: optional,
|
54
|
-
regex: regex,
|
55
|
-
min: min,
|
56
|
-
max: max,
|
57
|
-
values: values,
|
39
|
+
...structureOptions,
|
58
40
|
childs: childs
|
59
41
|
};
|
60
42
|
}
|
@@ -80,6 +62,14 @@ class Validator {
|
|
80
62
|
}
|
81
63
|
if (s_options.max && isNaN(s_options.max))
|
82
64
|
s_options.max = undefined;
|
65
|
+
if (s_options && !s_options.type) {
|
66
|
+
let type = typeof structure[key];
|
67
|
+
if (type === "object" && Array.isArray(structure[key]))
|
68
|
+
type = "array";
|
69
|
+
if (structure[key] === "@")
|
70
|
+
type = "email";
|
71
|
+
s_options.type = type;
|
72
|
+
}
|
83
73
|
return {
|
84
74
|
...s_options,
|
85
75
|
optional: s_options.optional === undefined ? structure[k + 'optional'] ?? false : s_options.optional,
|
@@ -163,6 +153,20 @@ class Validator {
|
|
163
153
|
else
|
164
154
|
object[i] = num;
|
165
155
|
}
|
156
|
+
if (typeof structure[i] === "boolean") {
|
157
|
+
if (typeof object[i] === "number") {
|
158
|
+
if (object[i] === 1)
|
159
|
+
object[i] = true;
|
160
|
+
if (object[i] === 0)
|
161
|
+
object[i] = false;
|
162
|
+
}
|
163
|
+
if (typeof object[i] === "string") {
|
164
|
+
if (object[i].trim().toLowerCase() === "true")
|
165
|
+
object[i] = true;
|
166
|
+
if (object[i].trim().toLowerCase() === "false")
|
167
|
+
object[i] = false;
|
168
|
+
}
|
169
|
+
}
|
166
170
|
if (typeof object[i] !== typeof structure[i])
|
167
171
|
errors.push("wrong datatype for field '" + i + "' expected " + typeof structure[i] + " got " + typeof object[i]);
|
168
172
|
if (typeof structure[i] === "object" || typeof structure[i] === "function") {
|
@@ -198,8 +202,10 @@ class Validator {
|
|
198
202
|
if (!structureOptions.values.includes(object[i])) {
|
199
203
|
let caseValue = null;
|
200
204
|
for (let i of structureOptions.values) {
|
201
|
-
|
202
|
-
|
205
|
+
if (i === null || i === undefined)
|
206
|
+
continue;
|
207
|
+
const v = (i + "").toLowerCase().trim();
|
208
|
+
if (v === (object[i] + "").toLowerCase().trim()) {
|
203
209
|
caseValue = object[i];
|
204
210
|
break;
|
205
211
|
}
|
@@ -282,7 +288,7 @@ class Validator {
|
|
282
288
|
this.filterStructure(structure[0], i);
|
283
289
|
return;
|
284
290
|
}
|
285
|
-
for (let key
|
291
|
+
for (let key of Object.keys(object)) {
|
286
292
|
if (!(key in structure)) {
|
287
293
|
delete object[key];
|
288
294
|
continue;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
export declare class ZipUtils {
|
4
|
+
static zipBufferToBase64: (input: Buffer) => string;
|
5
|
+
static unzipBase64ToBuffer: (base64: string) => Buffer;
|
6
|
+
static zipStringToBase64: (input: string) => string;
|
7
|
+
static unzipBase64ToString: (base64: string) => string;
|
8
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.ZipUtils = void 0;
|
7
|
+
const zlib_1 = __importDefault(require("zlib"));
|
8
|
+
class ZipUtils {
|
9
|
+
static zipBufferToBase64 = (input) => {
|
10
|
+
const compressed = zlib_1.default.gzipSync(input);
|
11
|
+
return compressed.toString("base64");
|
12
|
+
};
|
13
|
+
static unzipBase64ToBuffer = (base64) => {
|
14
|
+
const compressed = Buffer.from(base64, "base64");
|
15
|
+
return zlib_1.default.gunzipSync(compressed);
|
16
|
+
};
|
17
|
+
static zipStringToBase64 = (input) => {
|
18
|
+
const buffer = Buffer.from(input, "utf-8");
|
19
|
+
const compressed = zlib_1.default.gzipSync(buffer);
|
20
|
+
return compressed.toString("base64");
|
21
|
+
};
|
22
|
+
static unzipBase64ToString = (base64) => {
|
23
|
+
const compressed = Buffer.from(base64, "base64");
|
24
|
+
const uncompressed = zlib_1.default.gunzipSync(compressed);
|
25
|
+
return uncompressed.toString("utf-8");
|
26
|
+
};
|
27
|
+
}
|
28
|
+
exports.ZipUtils = ZipUtils;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.IntHmacSha256 = void 0;
|
7
|
+
const DefaultErrors_1 = __importDefault(require("../structures/DefaultErrors"));
|
8
|
+
const _TAuthParams = {
|
9
|
+
v: 0,
|
10
|
+
ts: "",
|
11
|
+
nonce: "",
|
12
|
+
kid: "",
|
13
|
+
alg: "",
|
14
|
+
$__alg_optional: true,
|
15
|
+
sig: ""
|
16
|
+
};
|
17
|
+
class IntHmacSha256 {
|
18
|
+
async intercept(req) {
|
19
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Key not found" };
|
20
|
+
}
|
21
|
+
}
|
22
|
+
exports.IntHmacSha256 = IntHmacSha256;
|
@@ -15,15 +15,16 @@ declare class DefaultErrors {
|
|
15
15
|
static FORBIDDEN: IError;
|
16
16
|
static NOT_FOUND: IError;
|
17
17
|
static INTERNAL_SERVER_ERROR: IError;
|
18
|
-
static EXTERNAL_SERVICE_ERROR: IError;
|
19
|
-
static MAINTENANCE_MODE: IError;
|
20
|
-
static CONFLICT: IError;
|
21
18
|
static INVALID_TOKEN: IError;
|
22
19
|
static INVALID_CREDENTIALS: IError;
|
23
20
|
static INVALID_DATA: IError;
|
24
21
|
static INVALID_FILE: IError;
|
22
|
+
static EXTERNAL_SERVICE_ERROR: IError;
|
23
|
+
static MAINTENANCE_MODE: IError;
|
24
|
+
static CONFLICT: IError;
|
25
25
|
static WRONG_DATA_TYPE: IError;
|
26
26
|
static UPROCESSIABLE_CONTENT: IError;
|
27
|
+
static WRONG_PARAMS: IError;
|
27
28
|
}
|
28
29
|
export declare class ErrorUtils {
|
29
30
|
static isError(obj: any): obj is IError;
|
@@ -18,15 +18,16 @@ class DefaultErrors {
|
|
18
18
|
static FORBIDDEN = { code: 12, message: "Forbidden", httpStatus: 403 };
|
19
19
|
static NOT_FOUND = { code: 13, message: "Not found", httpStatus: 404 };
|
20
20
|
static INTERNAL_SERVER_ERROR = { code: 14, message: "Internal server error.", httpStatus: 500 };
|
21
|
-
static EXTERNAL_SERVICE_ERROR = { code: 19, message: "External service error", httpStatus: 502 };
|
22
|
-
static MAINTENANCE_MODE = { code: 21, message: "Service in maintenance mode", httpStatus: 503 };
|
23
|
-
static CONFLICT = { code: 22, message: "Conflict", httpStatus: 409 };
|
24
21
|
static INVALID_TOKEN = { code: 15, message: "Invalid token", httpStatus: 401 };
|
25
22
|
static INVALID_CREDENTIALS = { code: 16, message: "Invalid credentials", httpStatus: 401 };
|
26
23
|
static INVALID_DATA = { code: 17, message: "Invalid data", httpStatus: 422 };
|
27
24
|
static INVALID_FILE = { code: 18, message: "Invalid file", httpStatus: 422 };
|
25
|
+
static EXTERNAL_SERVICE_ERROR = { code: 19, message: "External service error", httpStatus: 502 };
|
26
|
+
static MAINTENANCE_MODE = { code: 21, message: "Service in maintenance mode", httpStatus: 503 };
|
27
|
+
static CONFLICT = { code: 22, message: "Conflict", httpStatus: 409 };
|
28
28
|
static WRONG_DATA_TYPE = { code: 23, message: "Wrong data type", httpStatus: 422 };
|
29
|
-
static UPROCESSIABLE_CONTENT = { code:
|
29
|
+
static UPROCESSIABLE_CONTENT = { code: 24, message: "Unprocessable content", httpStatus: 422 };
|
30
|
+
static WRONG_PARAMS = { code: 25, message: "Wrong params", httpStatus: 400 };
|
30
31
|
}
|
31
32
|
class ErrorUtils {
|
32
33
|
static isError(obj) {
|
package/dist/index.d.ts
CHANGED
@@ -12,4 +12,5 @@ import { DBService } from "./apiServer/DBService";
|
|
12
12
|
import { YYYYMMDDHH } from "./apiServer/helper/YYYYMMDDHH";
|
13
13
|
import { TimeframeService } from "./apiServer/TimeframeService";
|
14
14
|
import { JSONStableStringify } from "./apiServer/helper/JSONStableStringify";
|
15
|
-
|
15
|
+
import { ZipUtils } from "./apiServer/helper/ZipUtils";
|
16
|
+
export { ZipUtils, UID, YYYYMMDDHH, JSONStableStringify, APIService, Initializer, LocalRequest, ValidationModel, MysqlService, TimeframeService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, S_MONITOR_REGISTRATE_ACTION };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.S_MONITOR_REGISTRATE_ACTION = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = void 0;
|
3
|
+
exports.S_MONITOR_REGISTRATE_ACTION = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = void 0;
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
@@ -30,3 +30,5 @@ const TimeframeService_1 = require("./apiServer/TimeframeService");
|
|
30
30
|
Object.defineProperty(exports, "TimeframeService", { enumerable: true, get: function () { return TimeframeService_1.TimeframeService; } });
|
31
31
|
const JSONStableStringify_1 = require("./apiServer/helper/JSONStableStringify");
|
32
32
|
Object.defineProperty(exports, "JSONStableStringify", { enumerable: true, get: function () { return JSONStableStringify_1.JSONStableStringify; } });
|
33
|
+
const ZipUtils_1 = require("./apiServer/helper/ZipUtils");
|
34
|
+
Object.defineProperty(exports, "ZipUtils", { enumerable: true, get: function () { return ZipUtils_1.ZipUtils; } });
|
package/package.json
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"APIService.js","sourceRoot":"","sources":["../../src/apiServer/APIService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwD;AACxD,+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AO,MAAM,IAAI,IAAI,CAAC;IACvB,CAAC;;AAvcF,gCAycC","sourcesContent":["import express, { Application, Response } from 'express'\nimport { BaseService, IBaseService } from './BaseService'\nimport cors from 'cors'\nimport { IncomingMessage } from 'http'\nimport { BaseEndpoint, IBaseEndpoint } from './BaseEndpoint'\nimport DefaultErrors, { ErrorUtils } from './structures/DefaultErrors'\nimport { HTTPRequestVO, IError, TransferPacketVO } from './structures/Interfaces'\nimport {Req} from \"badmfck-signal\"\nimport { logCrit, logError, logInfo } from './LogService'\nimport { Monitor } from './monitor/Monitor'\nimport path from \"path\"\nimport crypto from \"crypto\";\nimport fs from \"fs\"\nimport fileUpload from 'express-fileupload'\nimport os from \"os\"\nimport { Liveness } from './routes/Liveness'\nimport { Readiness } from './routes/Readiness'\nimport http from 'http'\n\nexport interface APIServiceNetworkLogItem{\t\n\tid:number,\n\tcreated:number,\n\ttime:number,\n\treferer?:string,\n\trequest:{[key:string]:any},\n\tresponse:{[key:string]:any}\n\terror?:string|null\n}\n\nexport interface APIServiceOptions{\n\tport:number,\n\tbaseEndPoint:string // \"/api/\"\n\tcorsHostWhiteList:string[],\n\tendpoints:IBaseEndpoint[],\n\tjsonLimit:string // \"10mb\"\n\tonNetworkLog?:((log:APIServiceNetworkLogItem)=>void)|null\n\tonError?:((...rest:any[])=>void)|null\n\tisProductionEnvironment:boolean,\n\tinterceptor?:IBaseEndpoint,\n\tpostproducer?:(req:HTTPRequestVO|undefined|null,res:Response,data:TransferPacketVO<any>,requestTime:number,endpoint?:string,log?:APIServiceNetworkLogItem|null)=>Promise<TransferPacketVO>\n\tpreproducer?:(req:HTTPRequestVO|undefined|null)=>any\n\t\n\tmonitor?:{login:string,password:string}[]\n\t//deployment?:{login:string,password:string}\n\tappVersion?:string\n\n\tfileTempDir:string;\n\tfileLimit:number // b\n}\n\nexport function getDefaultOptions():APIServiceOptions{\n\treturn {\n\t\tport: 8091,\n\t\tbaseEndPoint: '/api/',\n\t\tcorsHostWhiteList: [\n\t\t\t'http://localhost:3000',\n\t\t],\n\t\tendpoints: [],\n\t\tjsonLimit:\"10mb\",\n\t\tonNetworkLog: function (log: APIServiceNetworkLogItem): void {\n\t\t\tlogInfo(\"${APIService.js}\",log)\n\t\t},\n\t\tonError:function(err:any){\n\t\t\tlogError(\"${APIService.js}\",err);\n\t\t},\n\t\tisProductionEnvironment:false,\n\t\tfileLimit:50*1024*1024,\n\t\tfileTempDir:path.resolve(os.tmpdir(),\"fileTempDir\")\n\t}\n}\n\nexport const REQ_CREATE_NET_LOG:Req<void,APIServiceNetworkLogItem> = new Req(undefined,\"REQ_CREATE_NET_LOG\");\nexport const REQ_HTTP_LOG:Req<void,APIServiceNetworkLogItem[]> = new Req(undefined,\"REQ_HTTP_LOG\");\nexport const REQ_HTTP_REQUESTS_COUNT:Req<void,number> = new Req(undefined,\"REQ_HTTP_REQUESTS_COUNT\");\nexport const REQ_HTTP_SERVER:Req<void,{express:Application,http:http.Server}> = new Req(undefined,\"REQ_HTTP_SERVER\");\nexport const REQ_INTERNAL_CALL:Req<HTTPRequestVO,IError|any> = new Req(undefined,\"REQ_INTERNAL_CALL\");\n\n\nconst activeServices:String[]=[]\nconst entryPoints:String[]=[]\n\nexport async function Initializer(services:IBaseService[]){\n for (let i of services) { await i.init();activeServices.push(i.getName()) }\n for (let i of services) { i.applicationReady() }\n}\n\nexport class APIService extends BaseService {\n\n\t// NET LOG\n\tprivate static nextLogID=0;\n\tprivate version = \"2.4.9\"\n\tprivate options:APIServiceOptions;\n\tprivate monitor?:Monitor\n\tprivate monitorIndexFile?:Buffer\n\tprivate started:Date = new Date();\n\tprivate requestsCount=0;\n\tprivate server=http\n\n\tnetLog:APIServiceNetworkLogItem[]=[];\n\n\tconstructor(options?:APIServiceOptions|null) {\n\t\tsuper('HTTP Service')\n\t\tthis.options=options ?? getDefaultOptions();\n\t\tif(!this.options.corsHostWhiteList)\n\t\t\tthis.options.corsHostWhiteList=[];\n\t\tconst self = \"http://localhost:\"+this.options.port;\n\t\tif(!this.options.corsHostWhiteList.find(val=>val===self))\n\t\t\tthis.options.corsHostWhiteList.push()\n\n\t\tif(this.options.monitor && this.options.monitor.length>0){\n\t\t\tthis.monitor=new Monitor();\n\t\t\tthis.options.endpoints.push(this.monitor)\n\t\t\tconsole.warn(\"Service Monitor initialized\")\n\t\t\tconsole.warn(\"monitor links:\")\n\t\t\tfor(let i of this.options.monitor){\n\t\t\t\tconst hash = crypto.createHash(\"sha256\").update(i.login+i.password).digest().toString(\"hex\")\n\t\t\t\tconsole.warn(i.login+\" -> /sm-\"+hash)\t\t\t\t\t\t\n\t\t\t}\n\t\t}\n\n\t\t// create liveness, readiness\n\t\tthis.options.endpoints.push(new Liveness(this.started),new Readiness(this.started))\n\t\tREQ_HTTP_REQUESTS_COUNT.listener = async () => this.requestsCount;\n\t}\n\n\n\toverride async init(): Promise<void> {\n\n\t\tREQ_HTTP_LOG.listener=async ignore=>this.netLog;\n\t\tREQ_CREATE_NET_LOG.listener = async ignore=>{\n\t\t\tconst log:APIServiceNetworkLogItem = {\n\t\t\t\tcreated: +new Date(),\n\t\t\t\ttime: 0,\n\t\t\t\trequest: {},\n\t\t\t\tresponse: {},\n\t\t\t\terror:null,\n\t\t\t\tid: APIService.nextLogID++\n\t\t\t}\n\t\t\tthis.netLog.push(log)\n\t\t\tif(this.netLog.length>1000)\n\t\t\t\tthis.netLog.shift()\n\t\t\treturn log;\n\t\t}\n\n\t\t// internal call\n\t\tREQ_INTERNAL_CALL.listener = async (req)=>{\n\t\t\tfor(let i of this.options.endpoints){\n\t\t\t\tif(!i || !i.endpoints)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(let j of i.endpoints){\n\t\t\t\t\tlet ep = BaseEndpoint.getEntryPoint()+j.endpoint;\n\t\t\t\t\tep = ep.replaceAll(\"//\",\"/\")\n\t\t\t\t\tif(ep=== req.endpoint){\n\t\t\t\t\t\tconst response = await i.execute(req)\n\t\t\t\t\t\tif(response.error)\n\t\t\t\t\t\t\treturn response.error;\n\t\t\t\t\t\treturn response.data;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {error:DefaultErrors.UNKNOWN_REQUEST,data:null,httpStatus:404}\n\t\t}\n\n\t\t// initialize express\n\t\tconst app = express()\n\t\tconst server = http.createServer(app);\n\n\t\tREQ_HTTP_SERVER.listener = async ignore=>{return {express:app,http:server}};\n\n\t\tif(this.options.isProductionEnvironment)\n\t\t\tapp.set(\"env\",'production');\n\n\t\tapp.use(express.json({ limit: '10mb' })) // for parsing application/json\n\t\tapp.use(express.urlencoded({ limit: '10mb', extended: true })) // for parsing application/x-www-form-urlencoded\n\n\t\tapp.use(fileUpload({\n\t\t\tlimitHandler: (req, res, next)=>{\n\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\terror:DefaultErrors.FILE_TOO_LARGE,\n\t\t\t\t\tdata:null,\n\t\t\t\t\thttpStatus:413,\n\t\t\t\t},+new Date(),req.path);\n\t\t\t},\n\t\t\tlimits: { fileSize: this.options.fileLimit },\n\t\t\tuseTempFiles: true,\n\t\t\turiDecodeFileNames: true,\n\t\t\ttempFileDir: this.options.fileTempDir,\n\t\t\t//safeFileNames: true,\n\t\t\tabortOnLimit:true\n\t\t}))\n\n\t\tapp.use(async (err:any,req:any,resp:any,next:any)=>{\n\t\t\t\n\t\t\tif(!err){\n\t\t\t\tnext();\n\t\t\t\treturn\n\t\t\t}\n\t\t\t\t//request start time\n\t\t\tconst tme = +new Date();\n\t\t\tconst log = await REQ_CREATE_NET_LOG.request();\n\t\t\tlog.request={\n\t\t\t\tmethod:req.method,\n\t\t\t\tdata:\"\",\n\t\t\t\tparams:req.params\n\t\t\t}\n\n\t\t\tlet responseError=DefaultErrors.UNKNOWN_REQUEST;\n\t\t\tif (typeof err === \"object\" && err.status === 400 && 'body' in err && err.type === 'entity.parse.failed') {\n\t\t\t\tresponseError = DefaultErrors.JSON_MALFORMED\n\t\t\t}\n \n\n\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",resp,{\n\t\t\t\terror:responseError,\n\t\t\t\tdata:null,\n\t\t\t\thttpStatus:400\n\t\t\t},tme,\"\",log)\n\n\t\t})\n\n\t\tconst corsOptions = {\n\t\t\torigin: (origin: any, callback: any) => {\n\t\t\t\tconst originIsWhitelisted = this.options.corsHostWhiteList.includes(origin)\n\t\t\t\tcallback(null, originIsWhitelisted)\n\t\t\t},\n\t\t\tcredentials: true\n\t\t}\n\t\tapp.use(cors(corsOptions))\n\n\t\t// registrate endpoints\n\t\tBaseEndpoint.setEntryPoint(this.options.baseEndPoint)\n\t\t\n\t\tfor(let i of this.options.endpoints){\n\t\t\tawait i.init();\n\t\t\tif(!i.endpoints)\n\t\t\t\tcontinue;\n\t\t\tfor(let j of i.endpoints){\n\t\t\t\tlet ep = BaseEndpoint.getEntryPoint()+j.endpoint;\n\t\t\t\tep = ep.replaceAll(\"//\",\"/\")\n\t\t\t\t\n\n\t\t\t\t// incoming request\n\t\t\t\tapp.all(ep,async (req,res)=>{\n\t\t\t\t\tthis.requestsCount++;\n\t\t\t\t\tconst tme = +new Date();\n\t\t\t\t\tlet log:APIServiceNetworkLogItem|null = null;\n\t\t\t\t\tif(!i.ignoreHttpLogging){\n\t\t\t\t\t\tlog = await REQ_CREATE_NET_LOG.request();\n\t\t\t\t\t\tlog.request={\n\t\t\t\t\t\t\turl:req.url,\n\t\t\t\t\t\t\tmethod:req.method,\n\t\t\t\t\t\t\tdata:this.checkDataLength(req.body),\n\t\t\t\t\t\t\tparams:this.checkDataLength(req.params)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst execute = async ()=>{\n\n\t\t\t\t\t\tconst body = req.body;\n\t\t\t\t\t\tif(req.query && typeof req.query === \"object\"){\n\t\t\t\t\t\t\tfor(let i in req.query){\n\t\t\t\t\t\t\t\tbody[i]=req.query[i];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst httpRequest:HTTPRequestVO = {\n\t\t\t\t\t\t\traw:req as IncomingMessage,\n\t\t\t\t\t\t\tmethod:req.method,\n\t\t\t\t\t\t\tdata:req.body,\n\t\t\t\t\t\t\tparams:req.params,\n\t\t\t\t\t\t\theaders:req.headers as any,\n\t\t\t\t\t\t\tendpoint:ep,\n\t\t\t\t\t\t\tfiles:req.files ?? null,\n\t\t\t\t\t\t\treferer:req.get(\"Referer\"),\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif(this.options.preproducer){\n\t\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\tconst preproducerResult = await this.options.preproducer(httpRequest);\n\t\t\t\t\t\t\tif(preproducerResult)\n\t\t\t\t\t\t\t\thttpRequest.preproducerResult = preproducerResult;\n\t\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{error:{code:10002,message:\"Internal server error\",details:`${e}`},data:null,httpStatus:500},tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet result\n\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\t// Execute interceptor if exists\n\t\t\t\t\t\t\tif(!j.ignoreInterceptor){\n\t\t\t\t\t\t\t\tlet interceptorResult;\n\t\t\t\t\t\t\t\tif(this.options.interceptor){\n\t\t\t\t\t\t\t\t\tinterceptorResult=await this.options.interceptor.execute(httpRequest);\n\t\t\t\t\t\t\t\t\tif(interceptorResult.error && !j.allowInterceptorError){\n\t\t\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,interceptorResult,tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\thttpRequest.interceptorResult = interceptorResult\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Precheck\n\t\t\t\t\t\t\tif(i === this.monitor)\n\t\t\t\t\t\t\t\thttpRequest.precheck={data:this.options.monitor}\n\n\t\t\t\t\t\t\tconst precheck=await i.precheck(httpRequest)\n\t\t\t\t\t\t\tif(precheck && precheck.error){\n\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,precheck,tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\thttpRequest.precheck=precheck;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t// If interceptor has no errors, execute main handler\n\t\t\t\t\t\t\tresult = await i.execute(httpRequest)\n\t\t\t\t\t\t\t \n\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\tconsole.error(e);\n\t\t\t\t\t\t\tif(this.options.onError)\n\t\t\t\t\t\t\t\tthis.options.onError(e)\n\t\t\t\t\t\t\tif(this.monitor)\n\t\t\t\t\t\t\t\tthis.monitor.registrateFatalError(ep);\n\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\t\t\t\thttpStatus:500,\n\t\t\t\t\t\t\t\terror:{\n\t\t\t\t\t\t\t\t\tcode:10002,\n\t\t\t\t\t\t\t\t\tmessage:\"Internal server error\",\n\t\t\t\t\t\t\t\t\tdetails:`${e}`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},tme,ep,log,httpRequest);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,result,tme,ep,log,httpRequest);\n\t\t\t\t\t}\n\n\t\t\t\t\texecute()\n\t\t\t\t});// handle incoming request\n\n\t\t\t}\n\t\t}\n\n\t\n\n\t\t// final handler\n\t\tapp.use((req, res, next) => {\n\t\t\t\n\t\t\tconst tme = +new Date()\n\n\t\t\tif(this.monitor && this.options && this.options.monitor){\n\t\t\t\t//check if requesting monitor\n\t\t\t\tif(req.method===\"GET\"){\n\t\t\t\t\t\n\t\t\t\t\tlet monitorRequest=false;\n\t\t\t\t\tfor(let i of this.options.monitor){\n\t\t\t\t\t\tconst hash = crypto.createHash(\"sha256\").update(i.login+i.password).digest().toString(\"hex\")\n\t\t\t\t\t\tif(req.originalUrl.endsWith(\"/sm-\"+hash)){\n\t\t\t\t\t\t\tmonitorRequest=true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif(monitorRequest){\n\t\t\t\t\t\t// send index Thu, 16 Nov 2023 23:33:35 GMT\n\t\t\t\t\t\tconst date = new Date();\n\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\tif(!this.monitorIndexFile)\n\t\t\t\t\t\t\tthis.monitorIndexFile = fs.readFileSync(path.resolve(__dirname,\"monitor\",\"index.html\"));\n\t\t\t\t\t\t\tres.setHeader(\"Content-Type\",\"text/html\")\n\t\t\t\t\t\t\tres.setHeader(\"Content-Length\",this.monitorIndexFile.byteLength)\n\t\t\t\t\t\t\tres.status(200).send(this.monitorIndexFile);\n\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\t\t\t\terror:{\n\t\t\t\t\t\t\t\t\tcode:10002,\n\t\t\t\t\t\t\t\t\tmessage:\"Internal server error\",\n\t\t\t\t\t\t\t\t\tdetails:`${e}`\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdata:null,\n\t\t\t\t\t\t\t\thttpStatus:500\n\t\t\t\t\t\t\t},tme,req.path);\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t\n\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\terror:DefaultErrors.UNKNOWN_REQUEST,\n\t\t\t\tdata:null,\n\t\t\t\thttpStatus:404\n\t\t\t},tme,req.path);\n\t\t})\n\n\t\tserver.listen(this.options.port, () => {\n\t\t\tlogCrit('${APIService.js}','API Service started at: '+this.options.port+\", with base endpoint:\"+this.options.baseEndPoint+\", ver.: \"+this.version)\n\t\t})\n\n\t\t/*app.listen(this.options.port, () => {\n\t\t\tlogCrit('${APIService.js}','API Service started at: '+this.options.port+\", with base endpoint:\"+this.options.baseEndPoint+\", ver.: \"+this.version)\n\t\t})*/\n\t}\n\n\tasync sendResponse(ref:string,res:Response,data:TransferPacketVO<any>,requestTime:number,endpoint?:string,log?:APIServiceNetworkLogItem|null,req?:HTTPRequestVO){\n\n\t\tif(this.options.postproducer){\n\t\t\ttry{\n\t\t\t\tdata = await this.options.postproducer(req,res,data,requestTime,endpoint,log);\n\t\t\t}catch(e){\n\t\t\t\tlogError(\"Postproducer error\",e)\n\t\t\t}\n\t\t}\n\n\t\tif(ErrorUtils.isError(data))\n\t\t\tdata = {error:data as IError,data:null}\n\t\t\n data.responseTime = (+new Date()) - requestTime;\n data.core = this.version\n data.endpoint = endpoint ?? \"no_endpoint\"\n\t\t\n\t\tif(this.options.appVersion)\n\t\t\tdata.version=this.options.appVersion\n\n\t\t\n\t\tif(log){\n\t\t\tlog.time = data.responseTime\n\t\t\tlog.referer=ref;\n\t\t}\n\n\t\tif(this.monitor)\n\t\t\tthis.monitor.registrateResponse(data.endpoint,data.responseTime)\n\n if(res.destroyed || res.closed){\n\n\t\t\tif(log)\n\t\t\t\tlog.error = \"Connection already closed, can't send response for: \"+data.endpoint\n\t\t\tif(this.options.onError)\n \tthis.options.onError(\"Connection already closed, can't send response: \"+data.endpoint,data)\n \n\t\t\tif(this.monitor)\n\t\t\t\tthis.monitor.registrateError(data.endpoint);\n\n }else{\n\t\t\ttry{\n\n\t\t\t\tif(data.file){\n\n\t\t\t\t\tres.sendFile(data.file,err=>{\n\t\t\t\t\t\tif(err){\n\t\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\t\tlog.error = \"Can't send file: \"+data.file\n\t\t\t\t\t\t\tif(this.options.onError)\n\t\t\t\t\t\t\t\tthis.options.onError(\"Can't send file: \"+data.file,err)\n\t\t\t\t\t\t\tif(this.monitor && data.endpoint)\n\t\t\t\t\t\t\t\tthis.monitor.registrateAPIError(data.endpoint);\n\n\t\t\t\t\t\t\tthis.sendResponse(ref,res,{\n\t\t\t\t\t\t\t\terror:DefaultErrors.CANT_SEND_FILE,\n\t\t\t\t\t\t\t\tdata:null,\n\t\t\t\t\t\t\t\thttpStatus:500\n\t\t\t\t\t\t\t},requestTime,data.endpoint);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t})\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(data.redirect){\n\t\t\t\t\tres.redirect(data.redirect);\n\t\t\t\t\tif(log)\n\t\t\t\t\t\tlog.response = {redirect:data.redirect}\n\t\t\t\t}else{\n\t\t\t\t\t// setup headers\n\t\t\t\t\tif(data.headers){\n\t\t\t\t\t\tfor(let i in data.headers)\n\t\t\t\t\t\t\tres.setHeader(i,data.headers[i]);\n\t\t\t\t\t}\n\n\t\t\t\t\tif(data.error && data.error.httpStatus && data.error.httpStatus>99)\n\t\t\t\t\t\tres.statusCode = data.error.httpStatus\n\t\t\t\t\telse\n\t\t\t\t\t\tres.statusCode=data.httpStatus ?? 200\n\t\t\t\t\t\n\t\t\t\t\tif(data.rawResponse){\n\t\t\t\t\t\tres.send(data.data)\n\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\tlog.response = this.checkDataLength(data)\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tres.send(data);\n\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\tlog.response = this.checkDataLength(data)\n\n\t\t\t\t\t\tif(data.error && this.monitor)\n\t\t\t\t\t\t\tthis.monitor.registrateAPIError(data.endpoint)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch(e){\n\t\t\t\tif(this.options.onError)\n\t\t\t\t\tthis.options.onError(\"Can't send response\",e);\n\t\t\t\tif(log)\n\t\t\t\t\tlog.error=\"Can't send response\"\n\t\t\t\tif(this.monitor)\n\t\t\t\t\tthis.monitor.registrateError(data.endpoint);\n\t\t\t}\n\t\t}\n\n\t\t// show log\n\t\tif(this.options.onNetworkLog && log)\n\t\t\tthis.options.onNetworkLog(log)\n }\n\n\n\tcheckDataLength(data:any,result?:any,lvl?:number):any{\n\t\t\n\t\tif(!lvl)\n\t\t\tlvl=0;\n\n\t\tif(typeof data !== \"object\"){\n\t\t\tif(typeof data===\"string\" && data.length>1024)\n\t\t\t\treturn data.substring(0,1000)+\"... (total:\" + data.length + \")\"\n\t\t\treturn data;\n\t\t}\n\n\t\tif(typeof data === \"object\"){\n\t\t\tif(!result)\n\t\t\t\tresult={};\n\t\t\tlet arrcnt = 100;\n\t\t\tfor(let i in data){\n\t\t\t\tresult[i]=this.checkDataLength(data[i],result[i],lvl+1);\n\t\t\t\tarrcnt--;\n\t\t\t\tif(arrcnt<=0){\n\t\t\t\t\tresult[\"...\"]=\"... total: \"+Array.isArray(data)?data.length:Object.keys(data).length;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result ?? null;\n\t}\n\n}\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"BaseEndpoint.js","sourceRoot":"","sources":["../../src/apiServer/BaseEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAyD;AACzD,+EAAuD;AAqBvD,MAAa,YAAY;IAEb,sBAAsB,GAAU,EAAE,CAAC;IAE3C,SAAS,CAAoB;IACtB,iBAAiB,GAAG,KAAK,CAAA;IACxB,MAAM,CAAC,UAAU,GAAQ,GAAG,CAAC;IAC7B,QAAQ,GAAC,EAAE,CAAA;IAInB,MAAM,CAAC,aAAa,GAAC,CAAC,EAAS,EAAC,EAAE;QAC9B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAG,CAAC,I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,KAAI,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,EAAC;gBACxB,IAAI,QAAQ,GAAG,YAAY,CAAC,UAAU,GAAC,CAAC,CAAC,QAAQ,CAAA;gBACjD,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAC,GAAG,CAAC,CAAA;gBACxC,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI,UAAU;oBACxE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAC,GAAG,CAAC,CAAA;aACtC;SACJ;QAED,IAAA,oBAAO,EAAC,oBAAoB,EAAC,wBAAwB,GAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAEpE,OAAO;YACH,KAAK,EAAC,uBAAa,CAAC,eAAe;YACnC,IAAI,EAAC,IAAI;SACZ,CAAA;IACL,CAAC;;AAzFL,oCA0FC","sourcesContent":["import { logCrit, logInfo, logWarn } from \"./LogService\";\nimport DefaultErrors from \"./structures/DefaultErrors\";\nimport { HTTPRequestVO, TransferPacketVO } from \"./structures/Interfaces\";\n\n\nexport interface IBaseEndpoint{\n endpoints?:IEndpointHandler[]\n execute:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>>\n precheck:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>|null>\n init:() => Promise<void>\n ignoreHttpLogging:boolean,\n}\n\nexport interface IEndpointHandler{\n endpoint:string,\n handler?:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>>\n ignoreInterceptor?:boolean\n independed?:boolean\n allowInterceptorError?:boolean\n httpMethod?:\"GET\"|\"POST\"|\"PUT\"|\"DELETE\"\n}\n\nexport class BaseEndpoint implements IBaseEndpoint{\n\n private inializedEndpointNames:String[]=[];\n\n endpoints?:IEndpointHandler[]\n public ignoreHttpLogging = false\n private static entrypoint:string=\"/\";\n private endpoint=\"\"\n \n\n // global entrypoint\n static setEntryPoint=(ep:string)=>{\n this.entrypoint = ep;\n if(!this.entrypoint.endsWith(\"/\")){\n this.entrypoint+=\"/\"\n }\n if(!ep.startsWith(\"/\"))\n this.entrypoint=\"/\"+ep;\n }\n static getEntryPoint=():string=>{\n return this.entrypoint;\n }\n \n constructor(endpoint:string){\n if(endpoint.startsWith(\"/\"))\n endpoint=endpoint.substring(1)\n if(!endpoint.endsWith(\"/\"))\n endpoint=endpoint+\"/\"\n this.endpoint=endpoint;\n }\n \n\n registerEndpoints(endpoints:IEndpointHandler[]){\n for(let i of endpoints){\n \n // base point\n if(i.endpoint===\"\" || i.endpoint===\"/\"){\n let empty=i.endpoint === \"\";\n i.endpoint=this.endpoint\n if(i.endpoint.endsWith(\"/\") && empty)\n i.endpoint=i.endpoint.substring(0,i.endpoint.length-1)\n continue;\n }\n\n if(i.endpoint.startsWith(\"/\"))\n i.endpoint = i.endpoint.substring(1)\n if(i.endpoint.endsWith(\"/\"))\n i.endpoint=i.endpoint.substring(0,i.endpoint.length-1)\n\n if(!i.independed)\n i.endpoint = this.endpoint+i.endpoint\n }\n this.endpoints =endpoints;\n }\n\n \n async init(){\n if(!this.endpoints){\n logCrit(\"${BaseEndpoint.js}\",\"No endpoints registered for \"+this.endpoint)\n return;\n }\n for(let i of this.endpoints){\n logInfo(\"${BaseEndpoint.js}\",\"endpoint: \"+i.endpoint+\" initalized, ignoreInterceptor: \"+(i.ignoreInterceptor ?? \"false\"));\n this.inializedEndpointNames.push(i.endpoint+\" ignore interceptor: \"+(i.ignoreInterceptor ?? \"false\"))\n }\n };\n\n getInitalizedEndpointNames():String[]{\n return this.inializedEndpointNames;\n }\n\n async precheck(req:HTTPRequestVO):Promise<TransferPacketVO<any>|null>{return null}\n\n async execute(req:HTTPRequestVO):Promise<TransferPacketVO<any>>{\n if(this.endpoints && this.endpoints.length>0){\n for(let i of this.endpoints){\n let targetEP = BaseEndpoint.entrypoint+i.endpoint\n targetEP = targetEP.replaceAll(\"//\",\"/\")\n if( targetEP === req.endpoint && i.handler && typeof i.handler ===\"function\")\n return i.handler.call(this,req)\n }\n }\n\n logWarn(\"${BaseEndpoint.js}\",\"Unhandled entrypoint: \"+this.endpoint)\n \n return {\n error:DefaultErrors.NOT_IMPLEMENTED,\n data:null\n }\n }\n}"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"BaseService.js","sourceRoot":"","sources":["../../src/apiServer/BaseService.ts"],"names":[],"mappings":";;;AAMA,MAAa,WAAW;IAEZ,IAAI,CAAQ;IACtB,YAAa,IAAY;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,CAAC,WAAW,GAAC,IAAI,CAAC,IAAI,GAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,gBAAgB,KAAY,CAAC;CAC9B;AAhBD,kCAgBC","sourcesContent":["export interface IBaseService {\n init: () => Promise<void>\n applicationReady: () => void\n getName: () => string\n}\n\nexport class BaseService implements IBaseService {\n\n protected name: string\n constructor (name: string) {\n this.name = name\n }\n\n async init (): Promise<void> { \n console.log(\"Service: \"+this.name+\" initialized\");\n }\n \n getName():string{\n return this.name;\n }\n\n applicationReady (): void { }\n}\n"]}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import { BaseService } from "./BaseService";
|
2
|
-
import { HUBConnection } from "./cluster/HUBConnection";
|
3
|
-
import Signal, { Req } from "badmfck-signal";
|
4
|
-
import { HUBServiceOptions, IWebsocketPacket } from "./external/ExternalService";
|
5
|
-
export interface IParty {
|
6
|
-
name: string;
|
7
|
-
handlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[];
|
8
|
-
}
|
9
|
-
export interface IPartyHost {
|
10
|
-
url: string;
|
11
|
-
publicKey: string;
|
12
|
-
id: string;
|
13
|
-
}
|
14
|
-
export interface ClusterServiceOptions extends HUBServiceOptions {
|
15
|
-
targetID: string;
|
16
|
-
targetPublicKey: string;
|
17
|
-
targetURL: string;
|
18
|
-
party: IParty[];
|
19
|
-
}
|
20
|
-
export declare class ClusterService extends BaseService {
|
21
|
-
options: ClusterServiceOptions;
|
22
|
-
ws: HUBConnection | null;
|
23
|
-
handlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[];
|
24
|
-
parites: Map<string, IPartyHost>;
|
25
|
-
constructor(opt: ClusterServiceOptions);
|
26
|
-
init(): Promise<void>;
|
27
|
-
close(): Promise<void>;
|
28
|
-
connectToHUB(): Promise<void>;
|
29
|
-
addPartyHost(party: IPartyHost): void;
|
30
|
-
}
|
@@ -1,81 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.ClusterService = void 0;
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
8
|
-
const BaseService_1 = require("./BaseService");
|
9
|
-
const LogService_1 = require("./LogService");
|
10
|
-
const HUBConnection_1 = require("./cluster/HUBConnection");
|
11
|
-
const badmfck_signal_1 = __importDefault(require("badmfck-signal"));
|
12
|
-
const DefaultErrors_1 = require("./structures/DefaultErrors");
|
13
|
-
const Sleep_1 = require("./helper/Sleep");
|
14
|
-
class ClusterService extends BaseService_1.BaseService {
|
15
|
-
options;
|
16
|
-
ws = null;
|
17
|
-
handlers = [];
|
18
|
-
parites = new Map();
|
19
|
-
constructor(opt) {
|
20
|
-
super("ClusterService");
|
21
|
-
this.options = opt;
|
22
|
-
this.handlers = [
|
23
|
-
new badmfck_signal_1.default("S_PARTY_AVAILABLE", undefined, async (req) => {
|
24
|
-
this.addPartyHost(req.data);
|
25
|
-
})
|
26
|
-
];
|
27
|
-
}
|
28
|
-
async init() {
|
29
|
-
(0, LogService_1.logInfo)("ClusterService: initialized");
|
30
|
-
this.connectToHUB();
|
31
|
-
}
|
32
|
-
async close() {
|
33
|
-
(0, LogService_1.logInfo)("ClusterService: closing");
|
34
|
-
if (this.ws)
|
35
|
-
this.ws.close();
|
36
|
-
this.parites.clear();
|
37
|
-
}
|
38
|
-
async connectToHUB() {
|
39
|
-
(0, LogService_1.logInfo)("ClusterService: connecting to HUB");
|
40
|
-
if (this.ws)
|
41
|
-
this.ws.close();
|
42
|
-
this.ws = new HUBConnection_1.HUBConnection({
|
43
|
-
direction: "outgoing",
|
44
|
-
ws: new ws_1.default(this.options.targetURL),
|
45
|
-
hostID: this.options.hostID,
|
46
|
-
hostPrivateKey: this.options.hostPrivateKey,
|
47
|
-
hostPublicKey: this.options.hostPublicKey,
|
48
|
-
hostURL: this.options.hostURL,
|
49
|
-
targetID: this.options.targetID,
|
50
|
-
targetPublicKey: this.options.targetPublicKey,
|
51
|
-
targetURL: this.options.targetURL,
|
52
|
-
handlers: this.handlers,
|
53
|
-
onAuthorized: async () => {
|
54
|
-
(0, LogService_1.logInfo)("ClusterService: connected to HUB");
|
55
|
-
await (0, Sleep_1.Sleep)(1000);
|
56
|
-
const parites = this.options.party.map((party) => party.name);
|
57
|
-
const response = await this.ws?.send({
|
58
|
-
method: "REQ_PARTY",
|
59
|
-
data: parites,
|
60
|
-
callbackID: 1
|
61
|
-
});
|
62
|
-
if (DefaultErrors_1.ErrorUtils.isError(response)) {
|
63
|
-
(0, LogService_1.logError)("ClusterService: error while registrating parties", response);
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
for (let i of response)
|
67
|
-
this.addPartyHost(i);
|
68
|
-
},
|
69
|
-
onClose: () => {
|
70
|
-
console.log("ClusterService: connection to HUB closed");
|
71
|
-
this.connectToHUB();
|
72
|
-
},
|
73
|
-
});
|
74
|
-
}
|
75
|
-
addPartyHost(party) {
|
76
|
-
(0, LogService_1.logInfo)("ClusterService: add party host", party);
|
77
|
-
this.parites.set(party.id, party);
|
78
|
-
}
|
79
|
-
}
|
80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IGFib3V0IHBhcnR5XG4gICAgICAgICAgICAgICAgdGhpcy5hZGRQYXJ0eUhvc3QocmVxLmRhdGEpO1xuICAgICAgICAgICAgfSkgICAgICAgICAgICBcbiAgICAgICAgXVxuICAgIFxuICAgIH1cblxuICAgIGFzeW5jIGluaXQoKXtcbiAgICAgICAgbG9nSW5mbyhcIkNsdXN0ZXJTZXJ2aWNlOiBpbml0aWFsaXplZFwiKVxuICAgICAgICB0aGlzLmNvbm5lY3RUb0hVQigpO1xuICAgIH1cblxuICAgIGFzeW5jIGNsb3NlKCl7XG4gICAgICAgIGxvZ0luZm8oXCJDbHVzdGVyU2VydmljZTogY2xvc2luZ1wiKVxuICAgICAgICBpZih0aGlzLndzKVxuICAgICAgICAgICAgdGhpcy53cy5jbG9zZSgpO1xuICAgICAgICB0aGlzLnBhcml0ZXMuY2xlYXIoKTtcbiAgICB9XG5cbiAgICBhc3luYyBjb25uZWN0VG9IVUIoKXtcblxuICAgICAgICBsb2dJbmZvKFwiQ2x1c3RlclNlcnZpY2U6IGNvbm5lY3RpbmcgdG8gSFVCXCIpXG5cbiAgICAgICAgaWYodGhpcy53cylcbiAgICAgICAgICAgIHRoaXMud3MuY2xvc2UoKTtcbiAgICAgICAgXG4gICAgICAgIHRoaXMud3MgPSBuZXcgSFVCQ29ubmVjdGlvbih7XG4gICAgICAgICAgICBkaXJlY3Rpb246XCJvdXRnb2luZ1wiLFxuICAgICAgICAgICAgd3M6bmV3IFdlYlNvY2tldCh0aGlzLm9wdGlvbnMudGFyZ2V0VVJMKSxcblxuICAgICAgICAgICAgaG9zdElEOnRoaXMub3B0aW9ucy5ob3N0SUQsXG4gICAgICAgICAgICBob3N0UHJpdmF0ZUtleTp0aGlzLm9wdGlvbnMuaG9zdFByaXZhdGVLZXksXG4gICAgICAgICAgICBob3N0UHVibGljS2V5OnRoaXMub3B0aW9ucy5ob3N0UHVibGljS2V5LFxuICAgICAgICAgICAgaG9zdFVSTDp0aGlzLm9wdGlvbnMuaG9zdFVSTCxcblxuICAgICAgICAgICAgdGFyZ2V0SUQ6dGhpcy5vcHRpb25zLnRhcmdldElELFxuICAgICAgICAgICAgdGFyZ2V0UHVibGljS2V5OnRoaXMub3B0aW9ucy50YXJnZXRQdWJsaWNLZXksXG4gICAgICAgICAgICB0YXJnZXRVUkw6dGhpcy5vcHRpb25zLnRhcmdldFVSTCxcblxuICAgICAgICAgICAgaGFuZGxlcnM6dGhpcy5oYW5kbGVycyxcblxuICAgICAgICAgICAgb25BdXRob3JpemVkOmFzeW5jICgpPT57XG4gICAgICAgICAgICAgICAgbG9nSW5mbyhcIkNsdXN0ZXJTZXJ2aWNlOiBjb25uZWN0ZWQgdG8gSFVCXCIpXG5cbiAgICAgICAgICAgICAgICBhd2FpdCBTbGVlcCgxMDAwKVxuXG4gICAgICAgICAgICAgICAgLy8gcmVnaXN0cmF0ZSBwYXJ0aWVzXG4gICAgICAgICAgICAgICAgY29uc3QgcGFyaXRlcyA9IHRoaXMub3B0aW9ucy5wYXJ0eS5tYXAoKHBhcnR5KT0+cGFydHkubmFtZSk7XG4gICAgICAgICAgICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLndzPy5zZW5kKHtcbiAgICAgICAgICAgICAgICAgICAgbWV0aG9kOiBcIlJFUV9QQVJUWVwiLFxuICAgICAgICAgICAgICAgICAgICBkYXRhOiBwYXJpdGVzLFxuICAgICAgICAgICAgICAgICAgICBjYWxsYmFja0lEOjFcbiAgICAgICAgICAgICAgICB9KSBhcyBJUGFydHlIb3N0W11cblxuICAgICAgICAgICAgICAgIGlmKEVycm9yVXRpbHMuaXNFcnJvcihyZXNwb25zZSkpe1xuICAgICAgICAgICAgICAgICAgICBsb2dFcnJvcihcIkNsdXN0ZXJTZXJ2aWNlOiBlcnJvciB3aGlsZSByZWdpc3RyYXRpbmcgcGFydGllc1wiLHJlc3BvbnNlKVxuICAgICAgICAgICAgICAgICAgICAvL3RvZG8gcmV0YWtlIHBhcml0ZXNcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBcbiAgICAgICAgICAgICAgICBmb3IobGV0IGkgb2YgcmVzcG9uc2UpXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuYWRkUGFydHlIb3N0KGkpO1xuICAgICAgICAgICAgfSxcblxuICAgICAgICAgICAgXG4gICAgICAgICAgICBvbkNsb3NlOigpPT57XG4gICAgICAgICAgICAgICAgY29uc29sZS5sb2coXCJDbHVzdGVyU2VydmljZTogY29ubmVjdGlvbiB0byBIVUIgY2xvc2VkXCIpXG4gICAgICAgICAgICAgICAgdGhpcy5jb25uZWN0VG9IVUIoKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgIH0pXG4gICAgfVxuXG5cbiAgICBhZGRQYXJ0eUhvc3QocGFydHk6SVBhcnR5SG9zdCl7XG4gICAgICAgIGxvZ0luZm8oXCJDbHVzdGVyU2VydmljZTogYWRkIHBhcnR5IGhvc3RcIixwYXJ0eSlcbiAgICAgICAgdGhpcy5wYXJpdGVzLnNldChwYXJ0eS5pZCxwYXJ0eSk7XG4gICAgfVxuXG59Il19
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ClusterService.js","sourceRoot":"","sources":["../../src/apiServer/ClusterService.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAwC;AACxC,+CAA4C;AAC5C,6CAAiD;AACjD,2DAAwE;AAIxE,8DAAwD;AACxD,0CAAuC;AA2BvC,MAAa,cAAe,SAAQ,yBAAW;IAG3C,OAAO,CAAuB;IAC9B,EAAE,GAAoB,IAAI,CAAC;IAE3B,OAAO,GAAsB,IAAI,GAAG,EAAE,CAAC;IAEvC,YAAY,GAAyB;QACjC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI;QACN,IAAA,oBAAO,EAAC,6BAA6B,CAAC,CAAA;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kDAAkD,EAAC,QAAQ,CAAC,CAAA;oBAErE,OAAO;iBACV;gBAED,KAAI,IAAI,CAAC,IAAI,QAAQ;oBACjB,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;YAGD,OAAO,EAAC,GAAE,EAAE;gBACR,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAA;gBACvD,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAGD,YAAY,CAAC,IAAe;QACxB,IAAA,oBAAO,EAAC,gCAAgC,EAAC,IAAI,CAAC,CAAA;IAClD,CAAC;CAEJ;AA5ED,wCA4EC","sourcesContent":["import WebSocket, { RawData } from \"ws\";\nimport { BaseService } from \"./BaseService\";\nimport { logError, logInfo } from \"./LogService\";\nimport { HUBConnection, IClusterPacket } from \"./cluster/HUBConnection\";\nimport { privateDecrypt } from \"crypto\";\nimport Signal, { Req } from \"badmfck-signal\";\nimport { HUBServiceOptions, IWebsocketPacket } from \"./HUBService\";\nimport { ErrorUtils } from \"./structures/DefaultErrors\";\nimport { Sleep } from \"./helper/Sleep\";\n\n\nexport interface IParty{\n name:string,\n handlers:(Signal<IWebsocketPacket>|Req<IWebsocketPacket,any>)[],\n}\n\nexport interface IPartyHost{\n url:string,\n\tpublicKey:string,\n\tid:string\t\n}\n\n/**\n * ClusterServiceOptions\n * id: string - id of the service, must be sha256 hash or stronger\n * \n */\nexport interface ClusterServiceOptions extends HUBServiceOptions{\n \n targetID:string,\n targetPublicKey:string,\n targetURL:string,\n party:IParty[], // list of ids of parties that I can connect to\n}\n\nexport class ClusterService extends BaseService{\n \n \n options:ClusterServiceOptions;\n ws:HUBConnection|null=null;\n\n parites:Map<string,IParty> = new Map();\n\n constructor(opt:ClusterServiceOptions){\n super(\"ClusterService\")\n this.options = opt;\n }\n\n async init(){\n logInfo(\"ClusterService: initialized\")\n this.connectToHUB();\n }\n\n async connectToHUB(){\n\n logInfo(\"ClusterService: connecting to HUB\")\n\n if(this.ws)\n this.ws.close();\n \n this.ws = new HUBConnection({\n direction:\"outgoing\",\n ws:new WebSocket(this.options.targetURL),\n\n hostID:this.options.hostID,\n hostPrivateKey:this.options.hostPrivateKey,\n hostPublicKey:this.options.hostPublicKey,\n hostURL:this.options.hostURL,\n\n targetID:this.options.targetID,\n targetPublicKey:this.options.targetPublicKey,\n targetURL:this.options.targetURL,\n\n handlers:[],\n\n onAuthorized:async ()=>{\n logInfo(\"ClusterService: connected to HUB\")\n\n await Sleep(1000)\n\n // registrate parties\n const parites = this.options.party.map((party)=>party.name);\n const response = await this.ws?.send({\n method: \"REQ_PARTY\",\n data: parites,\n callbackID:1\n }) as IPartyHost[]\n\n if(ErrorUtils.isError(response)){\n logError(\"ClusterService: error while registrating parties\",response)\n //todo retake parites\n return;\n }\n \n for(let i of response)\n this.addPartyHost(i);\n },\n\n \n onClose:()=>{\n console.log(\"ClusterService: connection to HUB closed\")\n this.connectToHUB();\n },\n })\n }\n\n\n addPartyHost(host:IPartyHost){\n logInfo(\"ClusterService: add party host\",host)\n }\n\n}"]}
|