nodecommons-esm-socket-io-pseudo-http 0.0.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.
@@ -0,0 +1,18 @@
1
+ import { ServerOptions } from 'socket.io';
2
+ import { CommonsStrictExpressServer, ICommonsExpressConfig } from 'nodecommons-esm-express';
3
+ import { CommonsAppSocketIoServer, CommonsSocketIoApp } from 'nodecommons-esm-app-socket-io';
4
+ declare class SocketIoServer extends CommonsAppSocketIoServer {
5
+ private registerAuthKey;
6
+ private pseudoDomains;
7
+ constructor(registerAuthKey: string, expressServer: CommonsStrictExpressServer, expressConfig: ICommonsExpressConfig, options?: Partial<ServerOptions>);
8
+ private handleRegister;
9
+ private handleRequest;
10
+ private handleResponse;
11
+ }
12
+ export declare class CommonsSocketIoPseudoStrictHttpHostApp extends CommonsSocketIoApp<SocketIoServer> {
13
+ private registerAuthKey;
14
+ setRegisterAuthKey(key: string): void;
15
+ protected buildSocketIoServer(_expressServer: CommonsStrictExpressServer, expressConfig: ICommonsExpressConfig): SocketIoServer;
16
+ protected buildHttpServer(): CommonsStrictExpressServer;
17
+ }
18
+ export {};
@@ -0,0 +1,104 @@
1
+ import { commonsBase62HasPropertyId, commonsTypeHasPropertyString } from 'tscommons-esm-core';
2
+ import { ECommonsHttpMethod } from 'tscommons-esm-http';
3
+ import { isTCommonsSocketIoPseudoQuery, isTCommonsSocketIoPseudoResponse } from 'tscommons-esm-socket-io-pseudo-http';
4
+ import { commonsExpressBuildDefaultServer, isICommonsExpressConfig } from 'nodecommons-esm-express';
5
+ import { CommonsAppSocketIoServer, CommonsSocketIoApp } from 'nodecommons-esm-app-socket-io';
6
+ import { commonsLogDebug, commonsLogError, commonsLogInfo } from 'nodecommons-esm-log';
7
+ class SocketIoServer extends CommonsAppSocketIoServer {
8
+ registerAuthKey;
9
+ pseudoDomains = new Map();
10
+ constructor(registerAuthKey, expressServer, expressConfig, options) {
11
+ super(expressServer, expressConfig, true, options);
12
+ this.registerAuthKey = registerAuthKey;
13
+ this.on('http/register', (data) => this.handleRegister(data));
14
+ this.on('http/request/head', (data) => this.handleRequest(ECommonsHttpMethod.HEAD, data));
15
+ this.on('http/request/get', (data) => this.handleRequest(ECommonsHttpMethod.GET, data));
16
+ this.on('http/request/post', (data) => this.handleRequest(ECommonsHttpMethod.POST, data));
17
+ this.on('http/request/put', (data) => this.handleRequest(ECommonsHttpMethod.PUT, data));
18
+ this.on('http/request/patch', (data) => this.handleRequest(ECommonsHttpMethod.PATCH, data));
19
+ this.on('http/request/delete', (data) => this.handleRequest(ECommonsHttpMethod.DELETE, data));
20
+ this.on('http/response', (data) => this.handleResponse(data));
21
+ }
22
+ handleRegister(data) {
23
+ commonsLogDebug('Handling incoming registration');
24
+ if (!commonsTypeHasPropertyString(data, 'registerAuthKey'))
25
+ return;
26
+ const registerAuthKey = data.registerAuthKey;
27
+ if (registerAuthKey !== this.registerAuthKey) {
28
+ commonsLogDebug('Invalid registerAuthKey supplied. Ignoring');
29
+ return;
30
+ }
31
+ if (!commonsTypeHasPropertyString(data, 'pseudoDomain'))
32
+ return;
33
+ const pseudoDomain = data.pseudoDomain;
34
+ if (!commonsTypeHasPropertyString(data, 'authorityKey'))
35
+ return;
36
+ const authorityKey = data.authorityKey;
37
+ const existing = this.pseudoDomains.get(pseudoDomain);
38
+ if (existing && existing.authorityKey !== authorityKey) {
39
+ // Refuse to replace a server without a corresponding authorityKey
40
+ // This isn't the best security, but prevents trivial 'replacement' of a handler, i.e. first one gets protected
41
+ // To replace it, have to manually restart the host server
42
+ commonsLogDebug('Pseudo domain already exists, and authorityKey does not match. Ignoring');
43
+ return;
44
+ }
45
+ if (!commonsBase62HasPropertyId(data, 'id'))
46
+ return;
47
+ const id = data.id;
48
+ commonsLogInfo(`Registering ${pseudoDomain} as handled by id ${id}`);
49
+ this.pseudoDomains.set(pseudoDomain, {
50
+ id: id,
51
+ authorityKey: authorityKey
52
+ });
53
+ }
54
+ handleRequest(method, data) {
55
+ commonsLogDebug(`Handling request for ${method}`);
56
+ if (!isTCommonsSocketIoPseudoQuery(data)) {
57
+ commonsLogError('Invalid request');
58
+ return;
59
+ }
60
+ const serverId = this.pseudoDomains.get(data.pseudoDomain);
61
+ if (!serverId) {
62
+ commonsLogError('No such server is registered');
63
+ return;
64
+ }
65
+ commonsLogDebug(`Identified server for ${data.pseudoDomain} to be ${serverId.id}`);
66
+ const socket = this.getSocketById(serverId.id);
67
+ if (!socket) {
68
+ commonsLogError('Unable to identify server socket. Maybe it has disconnected?');
69
+ return;
70
+ }
71
+ void this.direct(socket, `http/request/${method}`, data);
72
+ }
73
+ handleResponse(data) {
74
+ if (!isTCommonsSocketIoPseudoResponse(data)) {
75
+ commonsLogError('Invalid response');
76
+ return;
77
+ }
78
+ const socket = this.getSocketById(data.clientId);
79
+ if (!socket) {
80
+ commonsLogError('Unable to identify requester socket. Maybe it has disconnected?');
81
+ return;
82
+ }
83
+ commonsLogDebug(`Handling response for client ${data.clientId}, query ${data.queryUid}`);
84
+ void this.direct(socket, 'http/response', data);
85
+ }
86
+ }
87
+ export class CommonsSocketIoPseudoStrictHttpHostApp extends CommonsSocketIoApp {
88
+ registerAuthKey;
89
+ setRegisterAuthKey(key) {
90
+ this.registerAuthKey = key;
91
+ }
92
+ buildSocketIoServer(_expressServer, expressConfig) {
93
+ if (!this.registerAuthKey)
94
+ throw new Error('registerAuthKey has not been set');
95
+ return new SocketIoServer(this.registerAuthKey, this.httpServer, expressConfig);
96
+ }
97
+ buildHttpServer() {
98
+ const expressConfig = this.getConfigArea('express');
99
+ if (!isICommonsExpressConfig(expressConfig))
100
+ throw new Error('Invalid express config');
101
+ return commonsExpressBuildDefaultServer(this.httpConfig.port, expressConfig.bodyParserLimit);
102
+ }
103
+ }
104
+ //# sourceMappingURL=commons-socket-io-pseudo-strict-http-host.app.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commons-socket-io-pseudo-strict-http-host.app.mjs","sourceRoot":"","sources":["../../src/apps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tscommons-esm-core';
2
+ import { ECommonsHttpContentType, ECommonsHttpResponseDataType, ICommonsHttpClientImplementation, TCommonsHttpInternalRequestOptions, THttpHeaderOrParamObject } from 'tscommons-esm-http';
3
+ import { CommonsSocketIoClientService } from 'nodecommons-esm-socket-io';
4
+ export declare class CommonsSocketIoPseudoStrictHttpClientImplementation extends CommonsSocketIoClientService implements ICommonsHttpClientImplementation {
5
+ private pendings;
6
+ private selfId;
7
+ protected setupOns(): void;
8
+ init(waitAfterConnect?: number): Promise<void>;
9
+ private request;
10
+ internalHead(url: string, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, options: TCommonsHttpInternalRequestOptions): Promise<void>;
11
+ private responseRequest;
12
+ internalGet(url: string, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, responseDataType: ECommonsHttpResponseDataType, options: TCommonsHttpInternalRequestOptions): Promise<string | Uint8Array>;
13
+ private bodyRequest;
14
+ internalPost<B extends TEncodedObject = TEncodedObject>(url: string, body: B, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, bodyDataEncoding: ECommonsHttpContentType, responseDataType: ECommonsHttpResponseDataType, options: TCommonsHttpInternalRequestOptions): Promise<string | Uint8Array>;
15
+ internalPut<B extends TEncodedObject = TEncodedObject>(url: string, body: B, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, bodyDataEncoding: ECommonsHttpContentType, responseDataType: ECommonsHttpResponseDataType, options: TCommonsHttpInternalRequestOptions): Promise<string | Uint8Array>;
16
+ internalPatch<B extends TEncodedObject = TEncodedObject>(url: string, body: B, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, bodyDataEncoding: ECommonsHttpContentType, responseDataType: ECommonsHttpResponseDataType, options: TCommonsHttpInternalRequestOptions): Promise<string | Uint8Array>;
17
+ internalDelete(url: string, params: THttpHeaderOrParamObject, headers: THttpHeaderOrParamObject, responseDataType: ECommonsHttpResponseDataType, options: TCommonsHttpInternalRequestOptions): Promise<string | Uint8Array>;
18
+ }
@@ -0,0 +1,177 @@
1
+ import { commonsBase62GenerateRandomId, commonsTypeAttemptString, commonsTypeHasPropertyString, commonsTypeIsStringArray } from 'tscommons-esm-core';
2
+ import { commonsAsyncAbortTimeout, commonsAsyncTimeout } from 'tscommons-esm-async';
3
+ import { CommonsHttpError, ECommonsHttpContentType, ECommonsHttpMethod, ECommonsHttpResponseDataType } from 'tscommons-esm-http';
4
+ import { isTCommonsSocketIoPseudoResponse, isTCommonsSocketIoPseudoDecodedResponse } from 'tscommons-esm-socket-io-pseudo-http';
5
+ import { CommonsSocketIoClientService } from 'nodecommons-esm-socket-io';
6
+ import { commonsLogDebug } from 'nodecommons-esm-log';
7
+ const PSEUDO_URL_REGEX = /^pseudo:\/\/([-a-z0-9.]+)(?:\/([^?]*))(?:[?](.*))?$/;
8
+ function parsePseudoUrl(url) {
9
+ const regex = PSEUDO_URL_REGEX.exec(url);
10
+ if (!regex)
11
+ throw new Error('Invalid pseudo URL');
12
+ const parsed = {
13
+ pseudoDomain: regex[1],
14
+ url: `/${regex[2]}`,
15
+ query: undefined
16
+ };
17
+ if (regex[3] && regex[3] !== '') {
18
+ const pairs = regex[3]
19
+ .split('&')
20
+ .map((s) => s.split('='))
21
+ .filter((pair) => pair.length === 2);
22
+ parsed.query = {};
23
+ for (const pair of pairs) {
24
+ parsed.query[pair[0]] = pair[1];
25
+ }
26
+ }
27
+ return parsed;
28
+ }
29
+ function reduceAnyQueryArray(query) {
30
+ const rebuild = {};
31
+ for (const key of Object.keys(query)) {
32
+ const value = query[key];
33
+ if (commonsTypeIsStringArray(value)) {
34
+ // just use the first for now. Not ideal.
35
+ if (value.length > 0)
36
+ rebuild[key] = value[0];
37
+ }
38
+ else {
39
+ rebuild[key] = value;
40
+ }
41
+ }
42
+ return rebuild;
43
+ }
44
+ export class CommonsSocketIoPseudoStrictHttpClientImplementation extends CommonsSocketIoClientService {
45
+ pendings = new Map();
46
+ selfId;
47
+ setupOns() {
48
+ this.on('http/response', (data) => {
49
+ if (!isTCommonsSocketIoPseudoResponse(data)) {
50
+ commonsLogDebug('Invalid response data');
51
+ return;
52
+ }
53
+ if (data.clientId !== this.selfId) {
54
+ // shouldn't be possible due to the direct sockets, but in case
55
+ commonsLogDebug('Socket clientId/selfId mismatch. This shouldn\'t be possible.');
56
+ return;
57
+ }
58
+ const pending = this.pendings.get(data.queryUid);
59
+ if (!pending) {
60
+ commonsLogDebug('No such uid exists. May have timed out');
61
+ return;
62
+ }
63
+ const decoded = JSON.parse(data.result);
64
+ if (!isTCommonsSocketIoPseudoDecodedResponse(decoded)) {
65
+ commonsLogDebug('Invalid TDecodedResponse data');
66
+ return;
67
+ }
68
+ pending(decoded);
69
+ });
70
+ }
71
+ async init(waitAfterConnect = 500) {
72
+ this.enabled = true;
73
+ this.connect();
74
+ await commonsAsyncTimeout(waitAfterConnect);
75
+ const id = await this.getId();
76
+ if (!id)
77
+ throw new Error('Unable to fetch self-id');
78
+ this.selfId = id;
79
+ commonsLogDebug(`Self-id is ${this.selfId}`);
80
+ }
81
+ request(method, pseudoDomain, url, query, headers, body, timeout = 5000) {
82
+ if (!this.selfId)
83
+ throw new Error('Self-id hasn\'t been fetched yet.');
84
+ const queryUid = commonsBase62GenerateRandomId();
85
+ const pseudoQuery = {
86
+ pseudoDomain: pseudoDomain,
87
+ clientId: this.selfId,
88
+ queryUid: queryUid,
89
+ url: url,
90
+ query: query || {},
91
+ headers: headers || {},
92
+ body: body
93
+ };
94
+ return new Promise((resolve, reject) => {
95
+ this.pendings.set(queryUid, (data) => {
96
+ commonsAsyncAbortTimeout(`commonsSocketIoPseudoStrictHttpClientService_${queryUid}`);
97
+ this.pendings.delete(queryUid);
98
+ if (data.statusCode === 204) {
99
+ resolve();
100
+ return;
101
+ }
102
+ let responseBody;
103
+ if (commonsTypeHasPropertyString(data, 'body')) {
104
+ const typecast = data;
105
+ responseBody = commonsTypeAttemptString(JSON.parse(typecast.body));
106
+ }
107
+ if (data.statusCode >= 400) {
108
+ reject(new CommonsHttpError(responseBody || '', data.statusCode));
109
+ return;
110
+ }
111
+ resolve(responseBody || '');
112
+ });
113
+ void (async () => {
114
+ try {
115
+ await this.emit(`http/request/${method}`, pseudoQuery);
116
+ try {
117
+ await commonsAsyncTimeout(timeout, `commonsSocketIoPseudoStrictHttpClientService_${queryUid}`);
118
+ reject(new Error('Timeout'));
119
+ }
120
+ catch (_e) {
121
+ // do nothing
122
+ }
123
+ finally {
124
+ this.pendings.delete(queryUid);
125
+ }
126
+ }
127
+ catch (e) {
128
+ commonsAsyncAbortTimeout(`commonsSocketIoPseudoStrictHttpClientService_${queryUid}`);
129
+ reject(e);
130
+ }
131
+ })();
132
+ });
133
+ }
134
+ async internalHead(url, params, headers, options) {
135
+ const parsed = parsePseudoUrl(url);
136
+ await this.request(ECommonsHttpMethod.HEAD, parsed.pseudoDomain, parsed.url, { ...parsed.query, ...reduceAnyQueryArray(params) }, reduceAnyQueryArray(headers), undefined, options.timeout);
137
+ }
138
+ async responseRequest(method, url, body, params, headers, bodyDataEncoding, responseDataType, options) {
139
+ const parsed = parsePseudoUrl(url);
140
+ if (bodyDataEncoding) {
141
+ switch (bodyDataEncoding) {
142
+ case ECommonsHttpContentType.JSON:
143
+ break;
144
+ default:
145
+ throw new Error('Only JSON encoding is supported');
146
+ }
147
+ }
148
+ let response = await this.request(method, parsed.pseudoDomain, parsed.url, { ...parsed.query, ...reduceAnyQueryArray(params) }, reduceAnyQueryArray(headers), body, options.timeout);
149
+ if (!response)
150
+ response = '';
151
+ switch (responseDataType) {
152
+ case ECommonsHttpResponseDataType.STRING:
153
+ return response;
154
+ case ECommonsHttpResponseDataType.UINT8ARRAY:
155
+ return new TextEncoder().encode(response);
156
+ }
157
+ }
158
+ async internalGet(url, params, headers, responseDataType, options) {
159
+ return this.responseRequest(ECommonsHttpMethod.GET, url, undefined, params, headers, undefined, responseDataType, options);
160
+ }
161
+ async bodyRequest(method, url, body, params, headers, bodyDataEncoding, responseDataType, options) {
162
+ return this.responseRequest(method, url, body, params, headers, bodyDataEncoding, responseDataType, options);
163
+ }
164
+ async internalPost(url, body, params, headers, bodyDataEncoding, responseDataType, options) {
165
+ return this.bodyRequest(ECommonsHttpMethod.POST, url, body, params, headers, bodyDataEncoding, responseDataType, options);
166
+ }
167
+ async internalPut(url, body, params, headers, bodyDataEncoding, responseDataType, options) {
168
+ return this.bodyRequest(ECommonsHttpMethod.PUT, url, body, params, headers, bodyDataEncoding, responseDataType, options);
169
+ }
170
+ async internalPatch(url, body, params, headers, bodyDataEncoding, responseDataType, options) {
171
+ return this.bodyRequest(ECommonsHttpMethod.PATCH, url, body, params, headers, bodyDataEncoding, responseDataType, options);
172
+ }
173
+ async internalDelete(url, params, headers, responseDataType, options) {
174
+ return this.responseRequest(ECommonsHttpMethod.DELETE, url, undefined, params, headers, undefined, responseDataType, options);
175
+ }
176
+ }
177
+ //# sourceMappingURL=commons-socket-io-pseudo-strict-http-client-implementation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commons-socket-io-pseudo-strict-http-client-implementation.mjs","sourceRoot":"","sources":["../../src/classes/commons-socket-io-pseudo-strict-http-client-implementation.mts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,6BAA6B,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACxM,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,4BAA4B,EAAkG,MAAM,oBAAoB,CAAC;AACjO,OAAO,EAAyC,gCAAgC,EAAE,uCAAuC,EAA+B,MAAM,qCAAqC,CAAC;AAEpM,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,gBAAgB,GAAW,qDAAqD,CAAC;AAQvF,SAAS,cAAc,CAAC,GAAW;I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IAAI,EACJ,MAAM,EACN,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,CACR,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,GAAW,EACX,MAAgC,EAChC,OAAiC,EACjC,gBAA8C,EAC9C,OAA2C;QAE5C,OAAO,IAAI,CAAC,eAAe,CACzB,kBAAkB,CAAC,MAAM,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,OAAO,CACR,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ import { CommonsSocketIoPseudoStrictHttpHostApp } from './apps/commons-socket-io-pseudo-strict-http-host.app.mjs';
2
+ import { CommonsSocketIoPseudoStrictParamsRequest, CommonsSocketIoPseudoPseudoResponse, TRequestHandler, CommonsSocketIoPseudoStrictHttpServer } from './servers/commons-socket-io-pseudo-strict-http.server.mjs';
3
+ import { CommonsSocketIoPseudoStrictHttpClientImplementation } from './classes/commons-socket-io-pseudo-strict-http-client-implementation.mjs';
4
+ export { CommonsSocketIoPseudoStrictHttpHostApp, CommonsSocketIoPseudoStrictParamsRequest, CommonsSocketIoPseudoPseudoResponse, TRequestHandler, CommonsSocketIoPseudoStrictHttpServer, CommonsSocketIoPseudoStrictHttpClientImplementation };
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { CommonsSocketIoPseudoStrictHttpHostApp } from './apps/commons-socket-io-pseudo-strict-http-host.app.mjs';
2
+ import { CommonsSocketIoPseudoStrictParamsRequest, CommonsSocketIoPseudoPseudoResponse, CommonsSocketIoPseudoStrictHttpServer } from './servers/commons-socket-io-pseudo-strict-http.server.mjs';
3
+ import { CommonsSocketIoPseudoStrictHttpClientImplementation } from './classes/commons-socket-io-pseudo-strict-http-client-implementation.mjs';
4
+ export { CommonsSocketIoPseudoStrictHttpHostApp, CommonsSocketIoPseudoStrictParamsRequest, CommonsSocketIoPseudoPseudoResponse, CommonsSocketIoPseudoStrictHttpServer, CommonsSocketIoPseudoStrictHttpClientImplementation };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EACL,wCAAwC,EACxC,mCAAmC,EAEnC,qCAAqC,EACtC,MAAM,2DAA2D,CAAC;AACnE,OAAO,EAAE,mDAAmD,EAAE,MAAM,0EAA0E,CAAC;AAC/I,OAAO,EACN,sCAAsC,EACtC,wCAAwC,EACxC,mCAAmC,EAEnC,qCAAqC,EACrC,mDAAmD,EACnD,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { ManagerOptions } from 'socket.io-client';
2
+ import { TEncodedObject, TPrimativeObject, TPropertyObject } from 'tscommons-esm-core';
3
+ import { CommonsStrictHttpServer, ICommonsStrictParamsRequest, TCommonsHttpHandler, TCommonsHttpResponse, TCommonsStrictParamPropertyObject } from 'nodecommons-esm-http';
4
+ export declare class CommonsSocketIoPseudoStrictParamsRequest implements ICommonsStrictParamsRequest {
5
+ params: TPrimativeObject;
6
+ strictParams: TCommonsStrictParamPropertyObject;
7
+ query: TPrimativeObject;
8
+ headers: TPropertyObject<string>;
9
+ body: TEncodedObject;
10
+ constructor(params: TPrimativeObject, strictParams: TCommonsStrictParamPropertyObject, query: TPrimativeObject, headers: TPropertyObject<string>);
11
+ internalSetBody(body: TEncodedObject): void;
12
+ get(field: string): string | undefined;
13
+ }
14
+ export declare class CommonsSocketIoPseudoPseudoResponse implements TCommonsHttpResponse {
15
+ private headers;
16
+ private statusCode;
17
+ private body;
18
+ setHeader(key: string, value: string): this;
19
+ status(statusCode: number): this;
20
+ send(body?: string | number | boolean | object | Buffer): this;
21
+ encode(): string;
22
+ }
23
+ export type TRequestHandler = TCommonsHttpHandler<CommonsSocketIoPseudoStrictParamsRequest, CommonsSocketIoPseudoPseudoResponse>;
24
+ export declare class CommonsSocketIoPseudoStrictHttpServer implements CommonsStrictHttpServer<ICommonsStrictParamsRequest, TCommonsHttpResponse> {
25
+ private registerAuthKey;
26
+ private pseudoDomain;
27
+ private authorityKey;
28
+ private socketIoServerUrl;
29
+ private options?;
30
+ private client;
31
+ private handlers;
32
+ constructor(registerAuthKey: string, pseudoDomain: string, authorityKey: string, socketIoServerUrl: string, options?: Partial<ManagerOptions> | undefined);
33
+ init(): void;
34
+ private handle;
35
+ listen(): Promise<void>;
36
+ close(): void;
37
+ head(query: string, handler: TRequestHandler): void;
38
+ get(query: string, handler: TRequestHandler): void;
39
+ post(query: string, handler: TRequestHandler): void;
40
+ put(query: string, handler: TRequestHandler): void;
41
+ patch(query: string, handler: TRequestHandler): void;
42
+ delete(query: string, handler: TRequestHandler): void;
43
+ }
@@ -0,0 +1,286 @@
1
+ import { commonsTypeHasPropertyString, commonsTypeAttemptString, commonsBase62HasPropertyId } from 'tscommons-esm-core';
2
+ import { CommonsHttpError, ECommonsHttpMethod } from 'tscommons-esm-http';
3
+ import { commonsAsyncTimeout, commonsPromiseTimeout } from 'tscommons-esm-async';
4
+ import { isTCommonsSocketIoPseudoQuery } from 'tscommons-esm-socket-io-pseudo-http';
5
+ import { commonsExtractStrictParamsFromUrlPath } from 'nodecommons-esm-http';
6
+ import { CommonsSocketIoClientService } from 'nodecommons-esm-socket-io';
7
+ import { commonsLogDebug, commonsLogDoing, commonsLogError } from 'nodecommons-esm-log';
8
+ export class CommonsSocketIoPseudoStrictParamsRequest {
9
+ params;
10
+ strictParams;
11
+ query;
12
+ headers;
13
+ body = {};
14
+ constructor(params, strictParams, query, headers) {
15
+ this.params = params;
16
+ this.strictParams = strictParams;
17
+ this.query = query;
18
+ this.headers = headers;
19
+ }
20
+ internalSetBody(body) {
21
+ this.body = body;
22
+ }
23
+ get(field) {
24
+ return commonsTypeAttemptString(this.headers[field]);
25
+ }
26
+ }
27
+ export class CommonsSocketIoPseudoPseudoResponse {
28
+ headers = {};
29
+ statusCode;
30
+ body;
31
+ setHeader(key, value) {
32
+ this.headers[key] = value;
33
+ return this;
34
+ }
35
+ status(statusCode) {
36
+ this.statusCode = statusCode;
37
+ return this;
38
+ }
39
+ send(body) {
40
+ if (Buffer.isBuffer(body))
41
+ throw new Error('Buffer return types are not supported for PseudoResponse');
42
+ this.body = body;
43
+ if (!this.statusCode) {
44
+ if (this.body === undefined) {
45
+ this.status(204);
46
+ }
47
+ else {
48
+ this.status(200);
49
+ }
50
+ }
51
+ return this;
52
+ }
53
+ encode() {
54
+ const response = this.body === undefined ? {
55
+ isEmpty: true,
56
+ headers: this.headers,
57
+ statusCode: this.statusCode || 500
58
+ } : {
59
+ headers: this.headers,
60
+ statusCode: this.statusCode || 500,
61
+ body: JSON.stringify(this.body)
62
+ };
63
+ return JSON.stringify(response);
64
+ }
65
+ }
66
+ class SocketIoClientService extends CommonsSocketIoClientService {
67
+ registerAuthKey;
68
+ pseudoDomain;
69
+ authorityKey;
70
+ handler;
71
+ internalIsRegistered = false;
72
+ get isRegistered() {
73
+ return this.internalIsRegistered;
74
+ }
75
+ constructor(registerAuthKey, pseudoDomain, authorityKey, handler, url, options) {
76
+ super(url, true, options);
77
+ this.registerAuthKey = registerAuthKey;
78
+ this.pseudoDomain = pseudoDomain;
79
+ this.authorityKey = authorityKey;
80
+ this.handler = handler;
81
+ this.addConnectCallback(() => {
82
+ commonsLogDebug('Socket.io re/connected');
83
+ void (async () => {
84
+ const log = commonsLogDoing('SocketIoClientService', 'Attempting to acquire internal socket.io id from upwards server');
85
+ const id = await this.getId();
86
+ if (id) {
87
+ log.result(id);
88
+ const log2 = commonsLogDoing('SocketIoClientService', `Registering pseudoDomain ${this.pseudoDomain} for id ${id}`);
89
+ await this.registerPseudoDomain(id);
90
+ log2.success();
91
+ // assume it succeeded as there isn't really a way of checking
92
+ this.internalIsRegistered = true;
93
+ }
94
+ else {
95
+ log.fail('unobtainable. Pseudo server will probably not work');
96
+ this.internalIsRegistered = false;
97
+ }
98
+ })();
99
+ });
100
+ this.addDisconnectCallback(() => {
101
+ commonsLogDebug('Socket.io disconnected');
102
+ this.internalIsRegistered = false;
103
+ });
104
+ }
105
+ setupOns() {
106
+ this.on('http/request/head', (data) => this.handle(ECommonsHttpMethod.HEAD, data));
107
+ this.on('http/request/get', (data) => this.handle(ECommonsHttpMethod.GET, data));
108
+ this.on('http/request/post', (data) => this.handle(ECommonsHttpMethod.POST, data));
109
+ this.on('http/request/put', (data) => this.handle(ECommonsHttpMethod.PUT, data));
110
+ this.on('http/request/patch', (data) => this.handle(ECommonsHttpMethod.PATCH, data));
111
+ this.on('http/request/delete', (data) => this.handle(ECommonsHttpMethod.DELETE, data));
112
+ }
113
+ handle(method, data) {
114
+ if (!commonsTypeHasPropertyString(data, 'pseudoDomain'))
115
+ return; // cannot continue;
116
+ if (data.pseudoDomain !== this.pseudoDomain)
117
+ return; // for another
118
+ commonsLogDebug(`Received request to handle a ${method} query`);
119
+ void (async () => {
120
+ if (!commonsBase62HasPropertyId(data, 'clientId'))
121
+ return; // cannot continue;
122
+ commonsLogDebug(`Self ID is ${data.clientId}`);
123
+ if (!commonsBase62HasPropertyId(data, 'queryUid'))
124
+ return; // cannot continue;
125
+ commonsLogDebug(`Query UID is ${data.queryUid}`);
126
+ let response = new CommonsSocketIoPseudoPseudoResponse();
127
+ if (!isTCommonsSocketIoPseudoQuery(data)) {
128
+ response.status(500);
129
+ response.send('Invalid pseudo query data');
130
+ }
131
+ else {
132
+ response = await this.handler(method, data);
133
+ }
134
+ await this.emit('http/response', {
135
+ clientId: data.clientId,
136
+ queryUid: data.queryUid,
137
+ result: response.encode()
138
+ });
139
+ })();
140
+ }
141
+ async registerPseudoDomain(id) {
142
+ await this.emit('http/register', {
143
+ registerAuthKey: this.registerAuthKey,
144
+ pseudoDomain: this.pseudoDomain,
145
+ authorityKey: this.authorityKey,
146
+ id: id
147
+ });
148
+ }
149
+ }
150
+ export class CommonsSocketIoPseudoStrictHttpServer {
151
+ registerAuthKey;
152
+ pseudoDomain;
153
+ authorityKey;
154
+ socketIoServerUrl;
155
+ options;
156
+ client;
157
+ handlers = [];
158
+ constructor(registerAuthKey, pseudoDomain, authorityKey, socketIoServerUrl, options) {
159
+ this.registerAuthKey = registerAuthKey;
160
+ this.pseudoDomain = pseudoDomain;
161
+ this.authorityKey = authorityKey;
162
+ this.socketIoServerUrl = socketIoServerUrl;
163
+ this.options = options;
164
+ }
165
+ init() {
166
+ this.client = new SocketIoClientService(this.registerAuthKey, this.pseudoDomain, this.authorityKey, (method, data) => this.handle(method, data), this.socketIoServerUrl, this.options);
167
+ }
168
+ async handle(method, data) {
169
+ commonsLogDebug(`Received a pseudo request of ${method}: ${data.url}`);
170
+ const response = new CommonsSocketIoPseudoPseudoResponse();
171
+ try {
172
+ let success = false;
173
+ for (const handler of this.handlers) {
174
+ if (handler.method !== method)
175
+ continue;
176
+ const paramsMatch = commonsExtractStrictParamsFromUrlPath(handler.definition, data.url);
177
+ if (!paramsMatch)
178
+ continue;
179
+ commonsLogDebug(`Found a matching handler; the strict params resolved as: ${JSON.stringify(paramsMatch)}`);
180
+ const request = new CommonsSocketIoPseudoStrictParamsRequest(paramsMatch[0], paramsMatch[1], { ...data.query }, { ...data.headers });
181
+ if ([ECommonsHttpMethod.POST, ECommonsHttpMethod.PUT, ECommonsHttpMethod.PATCH].includes(method)) {
182
+ request.internalSetBody({ ...data.body || {} });
183
+ }
184
+ success = true;
185
+ await handler.handler(request, response);
186
+ break;
187
+ }
188
+ if (!success) {
189
+ commonsLogDebug('No matching handler could be found');
190
+ throw new Error('No such method');
191
+ }
192
+ }
193
+ catch (e) {
194
+ commonsLogDebug(`Error response: ${JSON.stringify(e)}`);
195
+ if (e instanceof CommonsHttpError) {
196
+ response.status(e.httpResponseCode);
197
+ }
198
+ else {
199
+ response.status(500);
200
+ }
201
+ response.send(e.message);
202
+ }
203
+ return response;
204
+ }
205
+ async listen() {
206
+ if (!this.client)
207
+ throw new Error('Client has not been initialised');
208
+ const log = commonsLogDoing('SocketIoClientService', 'Starting SocketIO based pseudo HTTP server');
209
+ this.client.connect();
210
+ log.success();
211
+ commonsLogDebug('Waiting for registration to complete');
212
+ let abortDueToTimeout = false;
213
+ try {
214
+ await commonsPromiseTimeout(async () => {
215
+ let ttl = 1000;
216
+ while (true) {
217
+ if (abortDueToTimeout)
218
+ break;
219
+ if (ttl-- < 0)
220
+ break;
221
+ if (this.client.isRegistered)
222
+ break;
223
+ await commonsAsyncTimeout(100);
224
+ }
225
+ }, 5000);
226
+ commonsLogDebug('Registration successful');
227
+ }
228
+ catch (e) {
229
+ if (e.message === 'Timeout') {
230
+ abortDueToTimeout = true;
231
+ commonsLogError('SocketIoClientService', 'Timeout waiting for registration');
232
+ }
233
+ else {
234
+ throw e;
235
+ }
236
+ }
237
+ }
238
+ close() {
239
+ if (!this.client)
240
+ throw new Error('Client has not been initialised');
241
+ this.client.disconnect();
242
+ }
243
+ head(query, handler) {
244
+ this.handlers.push({
245
+ method: ECommonsHttpMethod.HEAD,
246
+ definition: query,
247
+ handler: handler
248
+ });
249
+ }
250
+ get(query, handler) {
251
+ this.handlers.push({
252
+ method: ECommonsHttpMethod.GET,
253
+ definition: query,
254
+ handler: handler
255
+ });
256
+ }
257
+ post(query, handler) {
258
+ this.handlers.push({
259
+ method: ECommonsHttpMethod.POST,
260
+ definition: query,
261
+ handler: handler
262
+ });
263
+ }
264
+ put(query, handler) {
265
+ this.handlers.push({
266
+ method: ECommonsHttpMethod.PUT,
267
+ definition: query,
268
+ handler: handler
269
+ });
270
+ }
271
+ patch(query, handler) {
272
+ this.handlers.push({
273
+ method: ECommonsHttpMethod.PATCH,
274
+ definition: query,
275
+ handler: handler
276
+ });
277
+ }
278
+ delete(query, handler) {
279
+ this.handlers.push({
280
+ method: ECommonsHttpMethod.DELETE,
281
+ definition: query,
282
+ handler: handler
283
+ });
284
+ }
285
+ }
286
+ //# sourceMappingURL=commons-socket-io-pseudo-strict-http.server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commons-socket-io-pseudo-strict-http.server.mjs","sourceRoot":"","sources":["../../src/servers/commons-socket-io-pseudo-strict-http.server.mts"],"names":[],"mappings":"AAEA,OAAO,EAEL,4BAA4B,EAC5B,wBAAwB,EAExB,0BAA0B,EAE3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAsE,6BAA6B,EAAkC,MAAM,qCAAqC,CAAC;AAExL,OAAO,EAML,qCAAqC,EACtC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAsB,MAAM,qBAAqB,CAAC;AAE5G,MAAM,OAAO,wCAAwC;IAC7C,MAAM,CAAmB;IACzB,YAAY,CAAoC;IAChD,KAAK,CAAmB;IACxB,OAAO,CAA0B;IACjC,IAAI,GAAmB,EAAE,CAAC;IAEjC,YACE,MAAwB,EACxB,YAA+C,EAC/C,KAAuB,EACvB,OAAgC;QAEjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEM,eAAe,CAAC,IAAoB;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,GAAG,CAAC,KAAa;QACvB,OAAO,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,CAAC;CACD;AAED,MAAM,OAAO,mCAAmC;IACvC,OAAO,GAA4B,EAAE,CAAC;IACtC,UAAU,CAAmB;IAC7B,IAAI,CAAyC;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C,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM,EAAE,kBAAkB,CAAC,GAAG;YAC9B,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACJ,CAAC;IAEM,IAAI,CACT,KAAa,EACb,OAAwB;QAEzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM,EAAE,kBAAkB,CAAC,IAAI;YAC/B,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACJ,CAAC;IAEM,GAAG,CACR,KAAa,EACb,OAAwB;QAEzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM,EAAE,kBAAkB,CAAC,GAAG;YAC9B,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CACV,KAAa,EACb,OAAwB;QAEzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM,EAAE,kBAAkB,CAAC,KAAK;YAChC,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACJ,CAAC;IAEM,MAAM,CACX,KAAa,EACb,OAAwB;QAEzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM,EAAE,kBAAkB,CAAC,MAAM;YACjC,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACJ,CAAC;CACD"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "nodecommons-esm-socket-io-pseudo-http",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "scripts": {
6
+ "tsc": "./node_modules/typescript/bin/tsc",
7
+ "preprepare": "rm -rf ./dist; php ~/Dev/etim.php src/ && npm run tsc",
8
+ "publish-major": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version major && npm install && npm publish && git add . && git commit -m 'publish'",
9
+ "publish-minor": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version minor && npm install && npm publish && git add . && git commit -m 'publish'",
10
+ "publish-patch": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version patch && npm install && npm publish && git add . && git commit -m 'publish'"
11
+ },
12
+ "main": "dist/index.mjs",
13
+ "types": "dist/index.d.mjs",
14
+ "type": "module",
15
+ "author": "Pete Morris",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@stylistic/eslint-plugin-ts": "^2.11.0",
19
+ "@types/node": "^22.10.0",
20
+ "eslint-plugin-import": "^2.31.0",
21
+ "eslint-plugin-prefer-arrow-functions": "^3.4.1",
22
+ "typescript": "^5.7.2",
23
+ "typescript-eslint": "^8.16.0"
24
+ },
25
+ "files": [
26
+ "dist/**/*"
27
+ ],
28
+ "dependencies": {
29
+ "nodecommons-esm-app-socket-io": "^0.0.4",
30
+ "nodecommons-esm-express": "^0.0.8",
31
+ "nodecommons-esm-http": "^0.0.6",
32
+ "nodecommons-esm-log": "^0.0.6",
33
+ "nodecommons-esm-socket-io": "^0.0.4",
34
+ "tscommons-esm-async": "^0.0.5",
35
+ "tscommons-esm-core": "^0.0.4",
36
+ "tscommons-esm-http": "^0.0.5",
37
+ "tscommons-esm-socket-io-pseudo-http": "^0.0.4"
38
+ }
39
+ }