@haku-sci/utils 2.7.0 → 2.7.2
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/TCP/tcp-param.decorator.d.ts +2 -0
- package/dist/TCP/tcp-param.decorator.js +13 -0
- package/dist/TCP/tcp-param.decorator.js.map +1 -0
- package/dist/TCP/tcp.service.d.ts +1 -0
- package/dist/TCP/tcp.service.js +50 -4
- package/dist/TCP/tcp.service.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/microservice/microservice.service.d.ts +0 -1
- package/dist/microservice/microservice.service.js +3 -25
- package/dist/microservice/microservice.service.js.map +1 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +32 -4
- package/dist/utils.js.map +1 -1
- package/dist/wss/bridge-registry.service.d.ts +15 -0
- package/dist/wss/bridge-registry.service.js +38 -0
- package/dist/wss/bridge-registry.service.js.map +1 -0
- package/dist/wss/canonical-key.d.ts +1 -0
- package/dist/wss/canonical-key.js +20 -0
- package/dist/wss/canonical-key.js.map +1 -0
- package/dist/wss/send-to-user.d.ts +8 -0
- package/dist/wss/send-to-user.js +29 -0
- package/dist/wss/send-to-user.js.map +1 -0
- package/dist/wss/ticket.controller.d.ts +3 -0
- package/dist/wss/ticket.controller.js +34 -0
- package/dist/wss/ticket.controller.js.map +1 -0
- package/dist/wss/ticket.module.d.ts +2 -0
- package/dist/wss/ticket.module.js +20 -0
- package/dist/wss/ticket.module.js.map +1 -0
- package/dist/wss/ticket.service.d.ts +11 -0
- package/dist/wss/ticket.service.js +39 -0
- package/dist/wss/ticket.service.js.map +1 -0
- package/dist/wss/utils.d.ts +11 -0
- package/dist/wss/utils.js +38 -0
- package/dist/wss/utils.js.map +1 -0
- package/dist/wss/wss-microservice.service.d.ts +26 -0
- package/dist/wss/wss-microservice.service.js +97 -0
- package/dist/wss/wss-microservice.service.js.map +1 -0
- package/dist/wss/wss.controller.d.ts +3 -0
- package/dist/wss/wss.controller.js +34 -0
- package/dist/wss/wss.controller.js.map +1 -0
- package/dist/wss/wss.module.d.ts +2 -0
- package/dist/wss/wss.module.js +20 -0
- package/dist/wss/wss.module.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCP_PARAM_METADATA_KEY = void 0;
|
|
4
|
+
exports.TcpParam = TcpParam;
|
|
5
|
+
exports.TCP_PARAM_METADATA_KEY = 'tcp:param';
|
|
6
|
+
function TcpParam(name) {
|
|
7
|
+
return (target, propertyKey, parameterIndex) => {
|
|
8
|
+
const existing = Reflect.getMetadata(exports.TCP_PARAM_METADATA_KEY, target, propertyKey) ?? [];
|
|
9
|
+
existing.push({ index: parameterIndex, name });
|
|
10
|
+
Reflect.defineMetadata(exports.TCP_PARAM_METADATA_KEY, existing, target, propertyKey);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=tcp-param.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tcp-param.decorator.js","sourceRoot":"","sources":["../../src/TCP/tcp-param.decorator.ts"],"names":[],"mappings":";;;AAEA,4BAOC;AATY,QAAA,sBAAsB,GAAG,WAAW,CAAC;AAElD,SAAgB,QAAQ,CAAC,IAAY;IACjC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC3C,MAAM,QAAQ,GACV,OAAO,CAAC,WAAW,CAAC,8BAAsB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,OAAO,CAAC,cAAc,CAAC,8BAAsB,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAClF,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -2,5 +2,6 @@ import { Logger } from '@nestjs/common';
|
|
|
2
2
|
export declare class TCPService {
|
|
3
3
|
static sendMessage(service: any, action: string, resource?: string, payload?: {}): Promise<any>;
|
|
4
4
|
static registerHakuSciMessageHandlers(app: any, logger: Logger): Promise<void>;
|
|
5
|
+
private static enablePatternRouting;
|
|
5
6
|
private static wrapHandler;
|
|
6
7
|
}
|
package/dist/TCP/tcp.service.js
CHANGED
|
@@ -9,6 +9,7 @@ var TCPService_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.TCPService = void 0;
|
|
11
11
|
const microservices_1 = require("@nestjs/microservices");
|
|
12
|
+
const tcp_param_decorator_1 = require("./tcp-param.decorator");
|
|
12
13
|
const rxjs_1 = require("rxjs");
|
|
13
14
|
const utils = require("../utils");
|
|
14
15
|
const consul_1 = require("../microservice/consul");
|
|
@@ -26,10 +27,14 @@ let TCPService = TCPService_1 = class TCPService {
|
|
|
26
27
|
try {
|
|
27
28
|
payload["sender"] = await utils.microServiceName();
|
|
28
29
|
let response$ = await client.send([resource, action].join("/"), payload).pipe((0, rxjs_1.catchError)(err => {
|
|
29
|
-
|
|
30
|
-
const status = err?.status || common_1.HttpStatus.BAD_REQUEST;
|
|
30
|
+
const inner = err?.error ?? err;
|
|
31
|
+
const status = inner?.status || inner?.statusCode || err?.status || common_1.HttpStatus.BAD_REQUEST;
|
|
32
|
+
const message = (typeof inner === 'object' ? inner?.message : inner) ||
|
|
33
|
+
err?.message ||
|
|
34
|
+
'Unknown error';
|
|
31
35
|
const payload = {
|
|
32
|
-
...(typeof
|
|
36
|
+
...(typeof inner === 'object' ? inner : {}),
|
|
37
|
+
message,
|
|
33
38
|
service,
|
|
34
39
|
};
|
|
35
40
|
return (0, rxjs_1.throwError)(() => new common_1.HttpException(payload, status));
|
|
@@ -70,12 +75,53 @@ let TCPService = TCPService_1 = class TCPService {
|
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
}
|
|
78
|
+
TCPService_1.enablePatternRouting(app.serverInstance);
|
|
73
79
|
logger.log("HakuSci Message Handlers initialized");
|
|
74
80
|
}
|
|
81
|
+
static enablePatternRouting(server) {
|
|
82
|
+
const handlers = server.messageHandlers;
|
|
83
|
+
const paramPatterns = [];
|
|
84
|
+
for (const key of handlers.keys()) {
|
|
85
|
+
if (!key.includes(':'))
|
|
86
|
+
continue;
|
|
87
|
+
const paramNames = [];
|
|
88
|
+
const regexStr = key.replace(/:([^/]+)/g, (_, name) => {
|
|
89
|
+
paramNames.push(name);
|
|
90
|
+
return '([^/]+)';
|
|
91
|
+
});
|
|
92
|
+
paramPatterns.push({ regex: new RegExp(`^${regexStr}$`), paramNames, registeredKey: key });
|
|
93
|
+
}
|
|
94
|
+
if (paramPatterns.length === 0)
|
|
95
|
+
return;
|
|
96
|
+
const originalGetHandler = server.getHandlerByPattern.bind(server);
|
|
97
|
+
server.getHandlerByPattern = (incomingPattern) => {
|
|
98
|
+
const exact = originalGetHandler(incomingPattern);
|
|
99
|
+
if (exact)
|
|
100
|
+
return exact;
|
|
101
|
+
for (const { regex, paramNames, registeredKey } of paramPatterns) {
|
|
102
|
+
const match = incomingPattern.match(regex);
|
|
103
|
+
if (!match)
|
|
104
|
+
continue;
|
|
105
|
+
const originalHandler = originalGetHandler(registeredKey);
|
|
106
|
+
if (!originalHandler)
|
|
107
|
+
continue;
|
|
108
|
+
const params = {};
|
|
109
|
+
paramNames.forEach((name, i) => { params[name] = match[i + 1]; });
|
|
110
|
+
return (data, ctx) => originalHandler({ ...data, params }, ctx);
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
75
115
|
static wrapHandler(instance, methodName, logger) {
|
|
116
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
117
|
+
const tcpParamMeta = Reflect.getMetadata(tcp_param_decorator_1.TCP_PARAM_METADATA_KEY, prototype, methodName) ?? [];
|
|
76
118
|
return async function boundHandler(data, context) {
|
|
77
119
|
try {
|
|
78
|
-
|
|
120
|
+
const { params, ...payload } = data ?? {};
|
|
121
|
+
const args = [tcpParamMeta.length > 0 ? payload : data];
|
|
122
|
+
for (const { index, name } of tcpParamMeta)
|
|
123
|
+
args[index] = params?.[name];
|
|
124
|
+
return await instance[methodName].apply(instance, args);
|
|
79
125
|
}
|
|
80
126
|
catch (err) {
|
|
81
127
|
const host = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp.service.js","sourceRoot":"","sources":["../../src/TCP/tcp.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yDAAmF;AACnF,+BAAsF;AACtF,kCAAiC;AACjC,mDAAgD;AAEhD,2CAA8F;AAC9F,qEAAsE;AACtE,+DAAmE;AACnE,wDAAyD;AACzD,kEAAgF;AAGzE,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACnB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAc,EAAE,QAAiB,EAAE,OAAO,GAAC,EAAE;QAC3E,MAAM,MAAM,GAAgB,MAAM,kCAAkB,CAAC,MAAM,CAAC;YACxD,SAAS,EAAE,yBAAS,CAAC,GAAG;YACxB,OAAO,EAAE,MAAM,eAAM,CAAC,aAAa,CAAC,OAAO,CAAC;SAC/C,CAAC,CAAC;QACH,IAAI,CAAC;YACD,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE,CAAA;YAClD,IAAI,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CACzE,IAAA,iBAAU,EAAC,GAAG,CAAC,EAAE;gBACb,
|
|
1
|
+
{"version":3,"file":"tcp.service.js","sourceRoot":"","sources":["../../src/TCP/tcp.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yDAAmF;AACn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,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;iBAEpD,CAAC;gBAGT,OAAO,IAAI,qCAAmB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC5D,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ,CAAA;AAlIY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;GACA,UAAU,CAkItB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,15 @@ export * from './microservice/microservice.service';
|
|
|
2
2
|
export * from './TCP/tcp.service';
|
|
3
3
|
export * from './TCP/tcp.module';
|
|
4
4
|
export * from './TCP/restrict-sender.decorator';
|
|
5
|
+
export * from './TCP/tcp-param.decorator';
|
|
5
6
|
export * from './TCP/restrict-sender.interceptor';
|
|
6
7
|
export * from './rabbit-mq/rabbit-mq.module';
|
|
7
8
|
export * from './rabbit-mq/rabbit-mq.service';
|
|
9
|
+
export * from './wss/canonical-key';
|
|
10
|
+
export * from './wss/ticket.service';
|
|
11
|
+
export * from './wss/wss.controller';
|
|
12
|
+
export * from './wss/wss.module';
|
|
13
|
+
export * from './wss/bridge-registry.service';
|
|
14
|
+
export * from './wss/utils';
|
|
15
|
+
export * from './wss/wss-microservice.service';
|
|
8
16
|
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,16 @@ __exportStar(require("./microservice/microservice.service"), exports);
|
|
|
18
18
|
__exportStar(require("./TCP/tcp.service"), exports);
|
|
19
19
|
__exportStar(require("./TCP/tcp.module"), exports);
|
|
20
20
|
__exportStar(require("./TCP/restrict-sender.decorator"), exports);
|
|
21
|
+
__exportStar(require("./TCP/tcp-param.decorator"), exports);
|
|
21
22
|
__exportStar(require("./TCP/restrict-sender.interceptor"), exports);
|
|
22
23
|
__exportStar(require("./rabbit-mq/rabbit-mq.module"), exports);
|
|
23
24
|
__exportStar(require("./rabbit-mq/rabbit-mq.service"), exports);
|
|
25
|
+
__exportStar(require("./wss/canonical-key"), exports);
|
|
26
|
+
__exportStar(require("./wss/ticket.service"), exports);
|
|
27
|
+
__exportStar(require("./wss/wss.controller"), exports);
|
|
28
|
+
__exportStar(require("./wss/wss.module"), exports);
|
|
29
|
+
__exportStar(require("./wss/bridge-registry.service"), exports);
|
|
30
|
+
__exportStar(require("./wss/utils"), exports);
|
|
31
|
+
__exportStar(require("./wss/wss-microservice.service"), exports);
|
|
24
32
|
__exportStar(require("./utils"), exports);
|
|
25
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,oDAAkC;AAClC,mDAAiC;AACjC,kEAAgD;AAChD,oEAAkD;AAClD,+DAA6C;AAC7C,gEAA8C;AAC9C,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,oDAAkC;AAClC,mDAAiC;AACjC,kEAAgD;AAChD,4DAA0C;AAC1C,oEAAkD;AAClD,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,uDAAqC;AACrC,uDAAqC;AACrC,mDAAiC;AACjC,gEAA8C;AAC9C,8CAA4B;AAC5B,iEAA+C;AAC/C,0CAAwB"}
|
|
@@ -3,7 +3,6 @@ export declare class Microservice {
|
|
|
3
3
|
private static serverAddress;
|
|
4
4
|
static logger: Logger;
|
|
5
5
|
static bootstrapMicroservice(appModule: any): Promise<void>;
|
|
6
|
-
private static isPortFree;
|
|
7
6
|
private static setServerAddress;
|
|
8
7
|
private static startTCPMicroService;
|
|
9
8
|
static get host(): string;
|
|
@@ -4,10 +4,8 @@ exports.Microservice = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const core_1 = require("@nestjs/core");
|
|
6
6
|
const microservices_1 = require("@nestjs/microservices");
|
|
7
|
-
const net = require("net");
|
|
8
7
|
const utils = require("../utils");
|
|
9
8
|
const exceptionFilter_1 = require("./exceptionFilter");
|
|
10
|
-
const os = require("os");
|
|
11
9
|
const consul_1 = require("./consul");
|
|
12
10
|
const tcp_service_1 = require("../TCP/tcp.service");
|
|
13
11
|
class Microservice {
|
|
@@ -22,30 +20,10 @@ class Microservice {
|
|
|
22
20
|
await tcp_service_1.TCPService.registerHakuSciMessageHandlers(app, this.logger);
|
|
23
21
|
consul_1.Consul.registerService(this.serverAddress, this.logger);
|
|
24
22
|
}
|
|
25
|
-
static isPortFree(port) {
|
|
26
|
-
return new Promise((resolve) => {
|
|
27
|
-
const server = net.createServer();
|
|
28
|
-
server.once('error', (err) => {
|
|
29
|
-
resolve(false);
|
|
30
|
-
});
|
|
31
|
-
server.once('listening', () => {
|
|
32
|
-
server.close(() => resolve(true));
|
|
33
|
-
});
|
|
34
|
-
server.listen(port, this.serverAddress.address);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
23
|
static async setServerAddress() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.address;
|
|
42
|
-
if (parseInt(process.env.TCP_PORT))
|
|
43
|
-
this.serverAddress.port = parseInt(process.env.TCP_PORT);
|
|
44
|
-
else
|
|
45
|
-
while (!await this.isPortFree(this.serverAddress.port))
|
|
46
|
-
this.serverAddress.port++;
|
|
47
|
-
this.logger.log("address to be listened to: " + this.serverAddress.address);
|
|
48
|
-
this.logger.log("port to be listened to: " + this.serverAddress.port);
|
|
24
|
+
const { address, port } = await utils.resolveServerAddress(this.serverAddress.port, 'TCP_PORT', this.logger);
|
|
25
|
+
this.serverAddress.address = address;
|
|
26
|
+
this.serverAddress.port = port;
|
|
49
27
|
}
|
|
50
28
|
static async startTCPMicroService(appModule) {
|
|
51
29
|
const app = await core_1.NestFactory.createMicroservice(appModule, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microservice.service.js","sourceRoot":"","sources":["../../src/microservice/microservice.service.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAC3D,uCAA2C;AAC3C,yDAAuE;
|
|
1
|
+
{"version":3,"file":"microservice.service.js","sourceRoot":"","sources":["../../src/microservice/microservice.service.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAC3D,uCAA2C;AAC3C,yDAAuE;AAEvE,kCAAiC;AAEjC,uDAAwD;AACxD,qCAAkC;AAClC,oDAAgD;AAEhD,MAAa,YAAY;IAIvB,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,SAAS;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAA;QACxD,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE9B,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YAC5C,MAAM,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;YACtD,eAAe,CAAC,yBAAyB,EAAE,CAAA;QAC7C,CAAC;QAGD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAGvD,MAAM,wBAAU,CAAC,8BAA8B,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAGlE,eAAM,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACzD,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,gBAAgB;QACnC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7G,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;QACrC,IAAI,CAAC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IACjC,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,SAAS;QACjD,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,kBAAkB,CAAsB,SAAS,EAC7E;YACE,SAAS,EAAE,yBAAS,CAAC,GAAG;YACxB,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;gBAC7B,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO;aACjC;SACF,CAEF,CAAC;QACF,GAAG,CAAC,gBAAgB,CAAC,IAAI,qCAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3D,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,KAAK,IAAI;QACb,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAA;IACnE,CAAC;;AA/CH,oCAgDC;AA/CgB,0BAAa,GAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
1
2
|
export declare const HAKU_SCI_RESOURCE = "haku:resource";
|
|
2
3
|
export declare const HAKU_SCI_ACTION = "haku:action";
|
|
3
4
|
export declare function executeFunction<F extends (...args: any[]) => any>(parent: any, funcName: string, params: Record<string, any>): ReturnType<F>;
|
|
4
5
|
export declare function getSortedParameters(func: Function, params: Record<string, any>): string[];
|
|
5
6
|
export declare function microServiceName(): Promise<string>;
|
|
6
7
|
export declare function getHttpRequestMaxSize(requestMaxSize?: string): number;
|
|
8
|
+
export interface ServerAddress {
|
|
9
|
+
address: string;
|
|
10
|
+
port: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveServerAddress(defaultPort: number, portEnvVar: string, logger?: Logger): Promise<ServerAddress>;
|
|
7
13
|
export declare function withWatchdog<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
|
package/dist/utils.js
CHANGED
|
@@ -5,10 +5,13 @@ exports.executeFunction = executeFunction;
|
|
|
5
5
|
exports.getSortedParameters = getSortedParameters;
|
|
6
6
|
exports.microServiceName = microServiceName;
|
|
7
7
|
exports.getHttpRequestMaxSize = getHttpRequestMaxSize;
|
|
8
|
+
exports.resolveServerAddress = resolveServerAddress;
|
|
8
9
|
exports.withWatchdog = withWatchdog;
|
|
9
10
|
const promises_1 = require("fs/promises");
|
|
10
11
|
const path = require("path");
|
|
11
12
|
const common_1 = require("@nestjs/common");
|
|
13
|
+
const net = require("net");
|
|
14
|
+
const os = require("os");
|
|
12
15
|
exports.HAKU_SCI_RESOURCE = 'haku:resource';
|
|
13
16
|
exports.HAKU_SCI_ACTION = 'haku:action';
|
|
14
17
|
function executeFunction(parent, funcName, params) {
|
|
@@ -31,17 +34,42 @@ function getFunctionParameterNames(func) {
|
|
|
31
34
|
.map(param => param.trim())
|
|
32
35
|
.filter(param => param);
|
|
33
36
|
}
|
|
37
|
+
let _msName;
|
|
34
38
|
async function microServiceName() {
|
|
35
|
-
if (!
|
|
36
|
-
|
|
39
|
+
if (!_msName) {
|
|
40
|
+
const data = await (0, promises_1.readFile)(path.join(process.cwd(), 'package.json'));
|
|
37
41
|
const { name } = JSON.parse(data.toString());
|
|
38
|
-
|
|
42
|
+
_msName = name;
|
|
39
43
|
}
|
|
40
|
-
return
|
|
44
|
+
return _msName;
|
|
41
45
|
}
|
|
42
46
|
function getHttpRequestMaxSize(requestMaxSize) {
|
|
43
47
|
return (parseInt(requestMaxSize ?? process.env.REQUEST_MAX_SIZE ?? '100', 10) - 10) * 1024;
|
|
44
48
|
}
|
|
49
|
+
function isPortFree(port, address) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const server = net.createServer();
|
|
52
|
+
server.once('error', () => resolve(false));
|
|
53
|
+
server.once('listening', () => server.close(() => resolve(true)));
|
|
54
|
+
server.listen(port, address);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function resolveServerAddress(defaultPort, portEnvVar, logger) {
|
|
58
|
+
const address = process.env.ADDRESS || (process.env.DEBUG && "127.0.0.1") || Object.values(os.networkInterfaces())
|
|
59
|
+
.flatMap((iface) => iface ?? [])
|
|
60
|
+
.find((addr) => addr.family === 'IPv4' && !addr.internal)
|
|
61
|
+
.address;
|
|
62
|
+
let port = defaultPort;
|
|
63
|
+
const envPort = parseInt(process.env[portEnvVar]);
|
|
64
|
+
if (!isNaN(envPort))
|
|
65
|
+
port = envPort;
|
|
66
|
+
else
|
|
67
|
+
while (!await isPortFree(port, address))
|
|
68
|
+
port++;
|
|
69
|
+
logger?.log("address to be listened to: " + address);
|
|
70
|
+
logger?.log("port to be listened to: " + port);
|
|
71
|
+
return { address, port };
|
|
72
|
+
}
|
|
45
73
|
function withWatchdog(promise, timeoutMs) {
|
|
46
74
|
return new Promise((resolve, reject) => {
|
|
47
75
|
const timer = setTimeout(() => {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAQA,0CAUC;AAED,kDAGC;AAiBD,4CAOC;AAED,sDAEC;AAkBD,oDAiBC;AAED,oCAgBC;AAxGD,0CAAuC;AACvC,6BAA6B;AAC7B,2CAAmE;AACnE,2BAA2B;AAC3B,yBAAyB;AACZ,QAAA,iBAAiB,GAAG,eAAe,CAAC;AACpC,QAAA,eAAe,GAAG,aAAa,CAAC;AAE7C,SAAgB,eAAe,CAC7B,MAAW,EACX,QAAgB,EAChB,MAA2B;IAE3B,MAAM,IAAI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GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QACjB,IAAI,GAAG,OAAO,CAAC;;QAEf,OAAO,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,CAAC;IAElD,MAAM,EAAE,GAAG,CAAC,6BAA6B,GAAG,OAAO,CAAC,CAAC;IACrD,MAAM,EAAE,GAAG,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAAC;IAE/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED,SAAgB,YAAY,CAAI,OAAmB,EAAE,SAAiB;IACpE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,MAAM,CAAC,IAAI,sBAAa,CAAC,iBAAiB,EAAE,mBAAU,CAAC,eAAe,CAAC,CAAC,CAAC;QAC3E,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,OAAO;aACJ,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
export interface BridgeContext {
|
|
3
|
+
id: any;
|
|
4
|
+
properties: Record<string, any>;
|
|
5
|
+
ws: WebSocket;
|
|
6
|
+
}
|
|
7
|
+
export declare class BridgeRegistry {
|
|
8
|
+
private static byId;
|
|
9
|
+
private static byWs;
|
|
10
|
+
static register(id: any, properties: Record<string, any>, ws: WebSocket): BridgeContext;
|
|
11
|
+
static unregister(ws: WebSocket): void;
|
|
12
|
+
static getByWs(ws: WebSocket): BridgeContext | undefined;
|
|
13
|
+
static getById(id: any): BridgeContext | undefined;
|
|
14
|
+
static get size(): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BridgeRegistry = void 0;
|
|
4
|
+
const canonical_key_1 = require("./canonical-key");
|
|
5
|
+
class BridgeRegistry {
|
|
6
|
+
static register(id, properties, ws) {
|
|
7
|
+
const key = (0, canonical_key_1.canonicalKey)(id);
|
|
8
|
+
const stale = this.byId.get(key);
|
|
9
|
+
if (stale)
|
|
10
|
+
this.unregister(stale.ws);
|
|
11
|
+
const context = { id, properties, ws };
|
|
12
|
+
this.byId.set(key, context);
|
|
13
|
+
this.byWs.set(ws, context);
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
static unregister(ws) {
|
|
17
|
+
const context = this.byWs.get(ws);
|
|
18
|
+
if (!context)
|
|
19
|
+
return;
|
|
20
|
+
this.byWs.delete(ws);
|
|
21
|
+
const key = (0, canonical_key_1.canonicalKey)(context.id);
|
|
22
|
+
if (this.byId.get(key) === context)
|
|
23
|
+
this.byId.delete(key);
|
|
24
|
+
}
|
|
25
|
+
static getByWs(ws) {
|
|
26
|
+
return this.byWs.get(ws);
|
|
27
|
+
}
|
|
28
|
+
static getById(id) {
|
|
29
|
+
return this.byId.get((0, canonical_key_1.canonicalKey)(id));
|
|
30
|
+
}
|
|
31
|
+
static get size() {
|
|
32
|
+
return this.byId.size;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.BridgeRegistry = BridgeRegistry;
|
|
36
|
+
BridgeRegistry.byId = new Map();
|
|
37
|
+
BridgeRegistry.byWs = new Map();
|
|
38
|
+
//# sourceMappingURL=bridge-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-registry.service.js","sourceRoot":"","sources":["../../src/wss/bridge-registry.service.ts"],"names":[],"mappings":";;;AACA,mDAA+C;AAQ/C,MAAa,cAAc;IAIzB,MAAM,CAAC,QAAQ,CAAC,EAAO,EAAE,UAA+B,EAAE,EAAa;QACrE,MAAM,GAAG,GAAG,IAAA,4BAAY,EAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,KAAK;YAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAErC,MAAM,OAAO,GAAkB,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,EAAa;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACrB,MAAM,GAAG,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACrC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,EAAa;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,EAAO;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAA,4BAAY,EAAC,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,KAAK,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;;AAjCH,wCAkCC;AAjCgB,mBAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;AACxC,mBAAI,GAAG,IAAI,GAAG,EAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function canonicalKey(id: any): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalKey = canonicalKey;
|
|
4
|
+
function canonicalKey(id) {
|
|
5
|
+
return typeof id === 'string' ? id : JSON.stringify(sortKeysDeep(id));
|
|
6
|
+
}
|
|
7
|
+
function sortKeysDeep(value) {
|
|
8
|
+
if (Array.isArray(value))
|
|
9
|
+
return value.map(sortKeysDeep);
|
|
10
|
+
if (value && typeof value === 'object') {
|
|
11
|
+
return Object.keys(value)
|
|
12
|
+
.sort()
|
|
13
|
+
.reduce((acc, key) => {
|
|
14
|
+
acc[key] = sortKeysDeep(value[key]);
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=canonical-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-key.js","sourceRoot":"","sources":["../../src/wss/canonical-key.ts"],"names":[],"mappings":";;AAAA,oCAEC;AAFD,SAAgB,YAAY,CAAC,EAAO;IAClC,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,YAAY,CAAC,KAAU;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtB,IAAI,EAAE;aACN,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACnB,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAyB,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendToUser = sendToUser;
|
|
4
|
+
const ws_1 = require("ws");
|
|
5
|
+
const bridge_registry_service_1 = require("./bridge-registry.service");
|
|
6
|
+
const DEFAULT_SEND_TIMEOUT_MS = 5000;
|
|
7
|
+
function sendToUser(id, message, timeoutMs = DEFAULT_SEND_TIMEOUT_MS) {
|
|
8
|
+
const context = bridge_registry_service_1.BridgeRegistry.getById(id);
|
|
9
|
+
if (!context || context.ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
10
|
+
return Promise.resolve({ ok: false, reason: 'not_connected' });
|
|
11
|
+
}
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
let settled = false;
|
|
14
|
+
const timer = setTimeout(() => {
|
|
15
|
+
if (settled)
|
|
16
|
+
return;
|
|
17
|
+
settled = true;
|
|
18
|
+
resolve({ ok: false, reason: 'timeout' });
|
|
19
|
+
}, timeoutMs);
|
|
20
|
+
context.ws.send(JSON.stringify(message), (error) => {
|
|
21
|
+
if (settled)
|
|
22
|
+
return;
|
|
23
|
+
settled = true;
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
resolve(error ? { ok: false, reason: 'send_failed', error } : { ok: true });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=send-to-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-to-user.js","sourceRoot":"","sources":["../../src/wss/send-to-user.ts"],"names":[],"mappings":";;AASA,gCAsBC;AA/BD,2BAA+B;AAC/B,uEAA2D;AAM3D,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC,SAAgB,UAAU,CAAC,EAAO,EAAE,OAAY,EAAE,SAAS,GAAG,uBAAuB;IACnF,MAAM,OAAO,GAAG,wCAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC,UAAU,KAAK,cAAS,CAAC,IAAI,EAAE,CAAC;QACzD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACjD,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TicketController = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
15
|
+
const ticket_service_1 = require("./ticket.service");
|
|
16
|
+
const wss_microservice_service_1 = require("./wss-microservice.service");
|
|
17
|
+
let TicketController = class TicketController {
|
|
18
|
+
async get(data) {
|
|
19
|
+
const { id, properties } = data;
|
|
20
|
+
const ticket = ticket_service_1.TicketService.create(id, properties);
|
|
21
|
+
return `${wss_microservice_service_1.WssMicroservice.url}?ticket=${ticket}`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.TicketController = TicketController;
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, microservices_1.MessagePattern)('get'),
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", [Object]),
|
|
29
|
+
__metadata("design:returntype", Promise)
|
|
30
|
+
], TicketController.prototype, "get", null);
|
|
31
|
+
exports.TicketController = TicketController = __decorate([
|
|
32
|
+
(0, common_1.Controller)('ticket')
|
|
33
|
+
], TicketController);
|
|
34
|
+
//# sourceMappingURL=ticket.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.controller.js","sourceRoot":"","sources":["../../src/wss/ticket.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAuD;AACvD,qDAAiD;AACjD,yEAA6D;AAGtD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAErB,AAAN,KAAK,CAAC,GAAG,CAAC,IAAyB;QACjC,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QAChC,MAAM,MAAM,GAAG,8BAAa,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;QACpD,OAAO,GAAG,0CAAe,CAAC,GAAG,WAAW,MAAM,EAAE,CAAC;IACnD,CAAC;CACF,CAAA;AAPY,4CAAgB;AAErB;IADL,IAAA,8BAAc,EAAC,KAAK,CAAC;;;;2CAKrB;2BANU,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,QAAQ,CAAC;GACR,gBAAgB,CAO5B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TicketModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const ticket_controller_1 = require("./ticket.controller");
|
|
12
|
+
let TicketModule = class TicketModule {
|
|
13
|
+
};
|
|
14
|
+
exports.TicketModule = TicketModule;
|
|
15
|
+
exports.TicketModule = TicketModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
controllers: [ticket_controller_1.TicketController],
|
|
18
|
+
})
|
|
19
|
+
], TicketModule);
|
|
20
|
+
//# sourceMappingURL=ticket.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.module.js","sourceRoot":"","sources":["../../src/wss/ticket.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AAKhD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IAHxB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,oCAAgB,CAAC;KAChC,CAAC;GACW,YAAY,CAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface TicketData {
|
|
2
|
+
id: any;
|
|
3
|
+
properties: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
export declare class TicketService {
|
|
6
|
+
private static tickets;
|
|
7
|
+
private static sweepInterval;
|
|
8
|
+
static create(id: any, properties?: Record<string, any>): string;
|
|
9
|
+
static consume(ticket: string): TicketData | null;
|
|
10
|
+
private static ensureSweep;
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TicketService = void 0;
|
|
4
|
+
const crypto = require("crypto");
|
|
5
|
+
const DEFAULT_TTL_MS = 5000;
|
|
6
|
+
const SWEEP_INTERVAL_MS = 1000;
|
|
7
|
+
class TicketService {
|
|
8
|
+
static create(id, properties = {}) {
|
|
9
|
+
this.ensureSweep();
|
|
10
|
+
const ticket = crypto.randomBytes(32).toString('hex');
|
|
11
|
+
this.tickets.set(ticket, { id, properties, expiresAt: Date.now() + DEFAULT_TTL_MS });
|
|
12
|
+
return ticket;
|
|
13
|
+
}
|
|
14
|
+
static consume(ticket) {
|
|
15
|
+
const entry = this.tickets.get(ticket);
|
|
16
|
+
if (!entry)
|
|
17
|
+
return null;
|
|
18
|
+
this.tickets.delete(ticket);
|
|
19
|
+
if (entry.expiresAt < Date.now())
|
|
20
|
+
return null;
|
|
21
|
+
return { id: entry.id, properties: entry.properties };
|
|
22
|
+
}
|
|
23
|
+
static ensureSweep() {
|
|
24
|
+
if (this.sweepInterval)
|
|
25
|
+
return;
|
|
26
|
+
this.sweepInterval = setInterval(() => {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
for (const [ticket, entry] of this.tickets) {
|
|
29
|
+
if (entry.expiresAt < now)
|
|
30
|
+
this.tickets.delete(ticket);
|
|
31
|
+
}
|
|
32
|
+
}, SWEEP_INTERVAL_MS);
|
|
33
|
+
this.sweepInterval.unref?.();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TicketService = TicketService;
|
|
37
|
+
TicketService.tickets = new Map();
|
|
38
|
+
TicketService.sweepInterval = null;
|
|
39
|
+
//# sourceMappingURL=ticket.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.service.js","sourceRoot":"","sources":["../../src/wss/ticket.service.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAWjC,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/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AI,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC;IAC/B,CAAC;;AA5BH,sCA6BC;AA5BgB,qBAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;AACzC,2BAAa,GAA0B,IAAI,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SendToUserResult = {
|
|
2
|
+
ok: true;
|
|
3
|
+
} | {
|
|
4
|
+
ok: false;
|
|
5
|
+
reason: 'not_connected' | 'timeout' | 'send_failed';
|
|
6
|
+
error?: Error;
|
|
7
|
+
};
|
|
8
|
+
export type MessageHandler = (id: any, properties: Record<string, any>, message: any) => void;
|
|
9
|
+
export declare function onMessage(handler: MessageHandler): void;
|
|
10
|
+
export declare function dispatchMessage(id: any, properties: Record<string, any>, message: any): void;
|
|
11
|
+
export declare function sendToUser(id: any, message: any, timeoutMs?: number): Promise<SendToUserResult>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onMessage = onMessage;
|
|
4
|
+
exports.dispatchMessage = dispatchMessage;
|
|
5
|
+
exports.sendToUser = sendToUser;
|
|
6
|
+
const ws_1 = require("ws");
|
|
7
|
+
const bridge_registry_service_1 = require("./bridge-registry.service");
|
|
8
|
+
const DEFAULT_SEND_TIMEOUT_MS = 5000;
|
|
9
|
+
let messageHandler = null;
|
|
10
|
+
function onMessage(handler) {
|
|
11
|
+
messageHandler = handler;
|
|
12
|
+
}
|
|
13
|
+
function dispatchMessage(id, properties, message) {
|
|
14
|
+
messageHandler?.(id, properties, message);
|
|
15
|
+
}
|
|
16
|
+
function sendToUser(id, message, timeoutMs = DEFAULT_SEND_TIMEOUT_MS) {
|
|
17
|
+
const context = bridge_registry_service_1.BridgeRegistry.getById(id);
|
|
18
|
+
if (!context || context.ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
19
|
+
return Promise.resolve({ ok: false, reason: 'not_connected' });
|
|
20
|
+
}
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
let settled = false;
|
|
23
|
+
const timer = setTimeout(() => {
|
|
24
|
+
if (settled)
|
|
25
|
+
return;
|
|
26
|
+
settled = true;
|
|
27
|
+
resolve({ ok: false, reason: 'timeout' });
|
|
28
|
+
}, timeoutMs);
|
|
29
|
+
context.ws.send(JSON.stringify(message), (error) => {
|
|
30
|
+
if (settled)
|
|
31
|
+
return;
|
|
32
|
+
settled = true;
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
resolve(error ? { ok: false, reason: 'send_failed', error } : { ok: true });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/wss/utils.ts"],"names":[],"mappings":";;AAaA,8BAEC;AAED,0CAEC;AAED,gCAsBC;AA3CD,2BAA+B;AAC/B,uEAA2D;AAQ3D,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC,IAAI,cAAc,GAA0B,IAAI,CAAC;AAEjD,SAAgB,SAAS,CAAC,OAAuB;IAC/C,cAAc,GAAG,OAAO,CAAC;AAC3B,CAAC;AAED,SAAgB,eAAe,CAAC,EAAO,EAAE,UAA+B,EAAE,OAAY;IACpF,cAAc,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,UAAU,CAAC,EAAO,EAAE,OAAY,EAAE,SAAS,GAAG,uBAAuB;IACnF,MAAM,OAAO,GAAG,wCAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC,UAAU,KAAK,cAAS,CAAC,IAAI,EAAE,CAAC;QACzD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACjD,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WebSocketServer } from 'ws';
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
import { BridgeContext } from './bridge-registry.service';
|
|
5
|
+
export interface WssSslOptions {
|
|
6
|
+
key: Buffer | string;
|
|
7
|
+
cert: Buffer | string;
|
|
8
|
+
}
|
|
9
|
+
export interface WssBootstrapOptions {
|
|
10
|
+
server?: http.Server | https.Server;
|
|
11
|
+
port?: number;
|
|
12
|
+
ssl?: WssSslOptions;
|
|
13
|
+
onDisconnect?: (context: BridgeContext) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class WssMicroservice {
|
|
16
|
+
private static logger;
|
|
17
|
+
private static wss;
|
|
18
|
+
private static publicHost;
|
|
19
|
+
private static publicPort;
|
|
20
|
+
private static ssl;
|
|
21
|
+
static bootstrap(options?: WssBootstrapOptions): Promise<WebSocketServer>;
|
|
22
|
+
static get url(): string;
|
|
23
|
+
private static resolveSsl;
|
|
24
|
+
private static handleHttpRequest;
|
|
25
|
+
private static handleConnection;
|
|
26
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WssMicroservice = void 0;
|
|
4
|
+
const ws_1 = require("ws");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const common_1 = require("@nestjs/common");
|
|
9
|
+
const utils = require("../utils");
|
|
10
|
+
const ticket_service_1 = require("./ticket.service");
|
|
11
|
+
const bridge_registry_service_1 = require("./bridge-registry.service");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
class WssMicroservice {
|
|
14
|
+
static async bootstrap(options = {}) {
|
|
15
|
+
let server = options.server;
|
|
16
|
+
if (!server) {
|
|
17
|
+
const address = process.env.ADDRESS || '0.0.0.0';
|
|
18
|
+
const port = Number(process.env.WSS_PORT) || options.port || 3001;
|
|
19
|
+
const ssl = options.ssl ?? await this.resolveSsl();
|
|
20
|
+
server = ssl ? https.createServer(ssl) : http.createServer();
|
|
21
|
+
server.on('request', (req, res) => this.handleHttpRequest(req, res));
|
|
22
|
+
server.listen(port, address);
|
|
23
|
+
this.logger.log(`address to be listened to: ${address}`);
|
|
24
|
+
this.logger.log(`port to be listened to: ${port}`);
|
|
25
|
+
this.logger.log(`ssl: ${ssl ? 'enabled' : 'disabled'}`);
|
|
26
|
+
this.publicHost = process.env.WSS_URL || address;
|
|
27
|
+
this.publicPort = Number(process.env.WSS_PUBLIC_PORT) || port;
|
|
28
|
+
this.ssl = !!ssl;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.publicHost = process.env.WSS_URL;
|
|
32
|
+
this.publicPort = Number(process.env.WSS_PUBLIC_PORT) || options.port;
|
|
33
|
+
this.ssl = !!options.ssl || server instanceof https.Server;
|
|
34
|
+
}
|
|
35
|
+
this.wss = new ws_1.WebSocketServer({ server });
|
|
36
|
+
this.wss.on('connection', (ws, req) => this.handleConnection(ws, req, options));
|
|
37
|
+
this.logger.log('WSS microservice started');
|
|
38
|
+
return this.wss;
|
|
39
|
+
}
|
|
40
|
+
static get url() {
|
|
41
|
+
if (!this.publicHost) {
|
|
42
|
+
throw new Error('WssMicroservice.url requested before bootstrap() (or WSS_URL is not set)');
|
|
43
|
+
}
|
|
44
|
+
return `${this.ssl ? 'wss' : 'ws'}://${this.publicHost}:${this.publicPort}`;
|
|
45
|
+
}
|
|
46
|
+
static async resolveSsl() {
|
|
47
|
+
const keyPath = process.env.WSS_SSL_KEY_PATH;
|
|
48
|
+
const certPath = process.env.WSS_SSL_CERT_PATH;
|
|
49
|
+
if (keyPath && certPath) {
|
|
50
|
+
return { key: (0, fs_1.readFileSync)(keyPath), cert: (0, fs_1.readFileSync)(certPath) };
|
|
51
|
+
}
|
|
52
|
+
if (process.env.DEBUG !== 'true')
|
|
53
|
+
return null;
|
|
54
|
+
const domain = `${await utils.microServiceName()}.haku-test.com`;
|
|
55
|
+
return {
|
|
56
|
+
key: (0, fs_1.readFileSync)(`./certificates/${domain}-key.pem`),
|
|
57
|
+
cert: (0, fs_1.readFileSync)(`./certificates/${domain}.pem`),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
static handleHttpRequest(req, res) {
|
|
61
|
+
const url = new URL(req.url ?? '', 'http://localhost');
|
|
62
|
+
if (url.pathname !== '/health') {
|
|
63
|
+
res.writeHead(404).end();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
67
|
+
res.end(JSON.stringify({ status: 'ok', connections: bridge_registry_service_1.BridgeRegistry.size }));
|
|
68
|
+
}
|
|
69
|
+
static handleConnection(ws, req, options) {
|
|
70
|
+
const url = new URL(req.url ?? '', 'http://localhost');
|
|
71
|
+
const ticket = url.searchParams.get('ticket');
|
|
72
|
+
const ticketData = ticket ? ticket_service_1.TicketService.consume(ticket) : null;
|
|
73
|
+
if (!ticketData) {
|
|
74
|
+
ws.close(4001, 'invalid or expired ticket');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const context = bridge_registry_service_1.BridgeRegistry.register(ticketData.id, ticketData.properties, ws);
|
|
78
|
+
ws.on('message', (raw) => {
|
|
79
|
+
(0, utils_1.dispatchMessage)(context.id, context.properties, parseMessage(raw.toString()));
|
|
80
|
+
});
|
|
81
|
+
ws.on('close', () => {
|
|
82
|
+
bridge_registry_service_1.BridgeRegistry.unregister(ws);
|
|
83
|
+
options.onDisconnect?.(context);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.WssMicroservice = WssMicroservice;
|
|
88
|
+
WssMicroservice.logger = new common_1.Logger('WssMicroservice');
|
|
89
|
+
function parseMessage(raw) {
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(raw);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return raw;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=wss-microservice.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wss-microservice.service.js","sourceRoot":"","sources":["../../src/wss/wss-microservice.service.ts"],"names":[],"mappings":";;;AAAA,2BAAgD;AAChD,6BAA6B;AAC7B,+BAA+B;AAC/B,2BAAkC;AAElC,2CAAwC;AACxC,kCAAkC;AAClC,qDAAiD;AACjD,uEAA0E;AAC1E,mCAA0C;AAc1C,MAAa,eAAe;IAO1B,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,UAA+B,EAAE;QACtD,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAA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AAU,EAAE,CAAC;YAChB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,2BAA2B,CAAC,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,wCAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAElF,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;YACvB,IAAA,uBAAe,EAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YAClB,wCAAc,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;;AApGH,0CAqGC;AApGgB,sBAAM,GAAG,IAAI,eAAM,CAAC,iBAAiB,CAAC,CAAC;AAsGxD,SAAS,YAAY,CAAC,GAAW;IAC/B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WssController = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
15
|
+
const ticket_service_1 = require("./ticket.service");
|
|
16
|
+
const wss_microservice_service_1 = require("./wss-microservice.service");
|
|
17
|
+
let WssController = class WssController {
|
|
18
|
+
async get(data) {
|
|
19
|
+
const { userId, properties } = data;
|
|
20
|
+
const ticket = ticket_service_1.TicketService.create(userId, properties);
|
|
21
|
+
return `${wss_microservice_service_1.WssMicroservice.url}?ticket=${ticket}`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.WssController = WssController;
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, microservices_1.MessagePattern)('get'),
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", [Object]),
|
|
29
|
+
__metadata("design:returntype", Promise)
|
|
30
|
+
], WssController.prototype, "get", null);
|
|
31
|
+
exports.WssController = WssController = __decorate([
|
|
32
|
+
(0, common_1.Controller)('wss')
|
|
33
|
+
], WssController);
|
|
34
|
+
//# sourceMappingURL=wss.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wss.controller.js","sourceRoot":"","sources":["../../src/wss/wss.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAuD;AACvD,qDAAiD;AACjD,yEAA6D;AAGtD,IAAM,aAAa,GAAnB,MAAM,aAAa;IAElB,AAAN,KAAK,CAAC,GAAG,CAAC,IAAyB;QACjC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QACpC,MAAM,MAAM,GAAG,8BAAa,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACxD,OAAO,GAAG,0CAAe,CAAC,GAAG,WAAW,MAAM,EAAE,CAAC;IACnD,CAAC;CACF,CAAA;AAPY,sCAAa;AAElB;IADL,IAAA,8BAAc,EAAC,KAAK,CAAC;;;;wCAKrB;wBANU,aAAa;IADzB,IAAA,mBAAU,EAAC,KAAK,CAAC;GACL,aAAa,CAOzB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WssModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const wss_controller_1 = require("./wss.controller");
|
|
12
|
+
let WssModule = class WssModule {
|
|
13
|
+
};
|
|
14
|
+
exports.WssModule = WssModule;
|
|
15
|
+
exports.WssModule = WssModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
controllers: [wss_controller_1.WssController],
|
|
18
|
+
})
|
|
19
|
+
], WssModule);
|
|
20
|
+
//# sourceMappingURL=wss.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wss.module.js","sourceRoot":"","sources":["../../src/wss/wss.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AAK1C,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAHrB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,8BAAa,CAAC;KAC7B,CAAC;GACW,SAAS,CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haku-sci/utils",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "utils from haku-sci. Library only",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
"amqp-connection-manager": "^4.1.14",
|
|
21
21
|
"amqplib": "^0.10.8",
|
|
22
22
|
"axios": "^1.9.0",
|
|
23
|
-
"rxjs": "7.8.2"
|
|
23
|
+
"rxjs": "7.8.2",
|
|
24
|
+
"ws": "^8.21.2"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@nestjs/testing": "^11.0.6",
|
|
27
28
|
"@types/jest": "^29.5.12",
|
|
28
29
|
"@types/pg": "^8.20.0",
|
|
30
|
+
"@types/ws": "^8.18.1",
|
|
29
31
|
"rimraf": "^6.0.1",
|
|
30
32
|
"typescript": "^5.7.3"
|
|
31
33
|
},
|