quidproquo-dev-server 0.0.239 → 0.0.241

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.
Files changed (79) hide show
  1. package/lib/commonjs/actionProcessor/core/event/index.d.ts +1 -0
  2. package/lib/commonjs/actionProcessor/core/event/index.js +1 -0
  3. package/lib/commonjs/actionProcessor/core/event/queue/getEventMatchStoryActionProcessor.js +0 -1
  4. package/lib/commonjs/actionProcessor/core/event/ws/index.d.ts +1 -0
  5. package/lib/commonjs/actionProcessor/core/event/ws/index.js +17 -0
  6. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventAutoRespondActionProcessor.d.ts +2 -0
  7. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventAutoRespondActionProcessor.js +24 -0
  8. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventGetRecordsActionProcessor.d.ts +2 -0
  9. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventGetRecordsActionProcessor.js +53 -0
  10. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventGetStorySessionActionProcessor.d.ts +2 -0
  11. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventGetStorySessionActionProcessor.js +24 -0
  12. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventMatchStoryActionProcessor.d.ts +2 -0
  13. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventMatchStoryActionProcessor.js +41 -0
  14. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventTransformResponseResultActionProcessor.d.ts +2 -0
  15. package/lib/commonjs/actionProcessor/core/event/ws/websocket/getEventTransformResponseResultActionProcessor.js +29 -0
  16. package/lib/commonjs/actionProcessor/core/event/ws/websocket/index.d.ts +2 -0
  17. package/lib/commonjs/actionProcessor/core/event/ws/websocket/index.js +21 -0
  18. package/lib/commonjs/actionProcessor/core/event/ws/websocket/types.d.ts +8 -0
  19. package/lib/commonjs/actionProcessor/core/event/ws/websocket/types.js +2 -0
  20. package/lib/commonjs/actionProcessor/webserver/index.js +2 -1
  21. package/lib/commonjs/actionProcessor/webserver/websocket/getWebsocketSendMessageActionProcessor.d.ts +2 -0
  22. package/lib/commonjs/actionProcessor/webserver/websocket/getWebsocketSendMessageActionProcessor.js +35 -0
  23. package/lib/commonjs/actionProcessor/webserver/websocket/index.d.ts +2 -0
  24. package/lib/commonjs/actionProcessor/webserver/websocket/index.js +17 -0
  25. package/lib/commonjs/implementations/eventBusImplementation.js +55 -37
  26. package/lib/commonjs/implementations/index.d.ts +1 -0
  27. package/lib/commonjs/implementations/index.js +1 -0
  28. package/lib/commonjs/implementations/queueImplementation.js +45 -3
  29. package/lib/commonjs/implementations/webSocket/index.d.ts +2 -0
  30. package/lib/commonjs/implementations/webSocket/index.js +18 -0
  31. package/lib/commonjs/implementations/webSocket/types/WsEvent.d.ts +13 -0
  32. package/lib/commonjs/implementations/webSocket/types/WsEvent.js +2 -0
  33. package/lib/commonjs/implementations/webSocket/types/index.d.ts +1 -0
  34. package/lib/commonjs/implementations/webSocket/types/index.js +17 -0
  35. package/lib/commonjs/implementations/webSocket/webSocketImplementation.d.ts +3 -0
  36. package/lib/commonjs/implementations/webSocket/webSocketImplementation.js +134 -0
  37. package/lib/commonjs/logic/eventBus.js +3 -0
  38. package/lib/commonjs/main.js +1 -0
  39. package/lib/commonjs/types/DevServerConfig.d.ts +2 -1
  40. package/lib/esm/actionProcessor/core/event/index.d.ts +1 -0
  41. package/lib/esm/actionProcessor/core/event/index.js +1 -0
  42. package/lib/esm/actionProcessor/core/event/queue/getEventMatchStoryActionProcessor.js +0 -1
  43. package/lib/esm/actionProcessor/core/event/ws/index.d.ts +1 -0
  44. package/lib/esm/actionProcessor/core/event/ws/index.js +1 -0
  45. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventAutoRespondActionProcessor.d.ts +2 -0
  46. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventAutoRespondActionProcessor.js +9 -0
  47. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventGetRecordsActionProcessor.d.ts +2 -0
  48. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventGetRecordsActionProcessor.js +38 -0
  49. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventGetStorySessionActionProcessor.d.ts +2 -0
  50. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventGetStorySessionActionProcessor.js +9 -0
  51. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventMatchStoryActionProcessor.d.ts +2 -0
  52. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventMatchStoryActionProcessor.js +26 -0
  53. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventTransformResponseResultActionProcessor.d.ts +2 -0
  54. package/lib/esm/actionProcessor/core/event/ws/websocket/getEventTransformResponseResultActionProcessor.js +14 -0
  55. package/lib/esm/actionProcessor/core/event/ws/websocket/index.d.ts +2 -0
  56. package/lib/esm/actionProcessor/core/event/ws/websocket/index.js +12 -0
  57. package/lib/esm/actionProcessor/core/event/ws/websocket/types.d.ts +8 -0
  58. package/lib/esm/actionProcessor/core/event/ws/websocket/types.js +1 -0
  59. package/lib/esm/actionProcessor/webserver/index.js +2 -0
  60. package/lib/esm/actionProcessor/webserver/websocket/getWebsocketSendMessageActionProcessor.d.ts +2 -0
  61. package/lib/esm/actionProcessor/webserver/websocket/getWebsocketSendMessageActionProcessor.js +19 -0
  62. package/lib/esm/actionProcessor/webserver/websocket/index.d.ts +2 -0
  63. package/lib/esm/actionProcessor/webserver/websocket/index.js +4 -0
  64. package/lib/esm/implementations/eventBusImplementation.js +54 -34
  65. package/lib/esm/implementations/index.d.ts +1 -0
  66. package/lib/esm/implementations/index.js +1 -0
  67. package/lib/esm/implementations/queueImplementation.js +44 -4
  68. package/lib/esm/implementations/webSocket/index.d.ts +2 -0
  69. package/lib/esm/implementations/webSocket/index.js +2 -0
  70. package/lib/esm/implementations/webSocket/types/WsEvent.d.ts +13 -0
  71. package/lib/esm/implementations/webSocket/types/WsEvent.js +1 -0
  72. package/lib/esm/implementations/webSocket/types/index.d.ts +1 -0
  73. package/lib/esm/implementations/webSocket/types/index.js +1 -0
  74. package/lib/esm/implementations/webSocket/webSocketImplementation.d.ts +3 -0
  75. package/lib/esm/implementations/webSocket/webSocketImplementation.js +123 -0
  76. package/lib/esm/logic/eventBus.js +3 -0
  77. package/lib/esm/main.js +2 -1
  78. package/lib/esm/types/DevServerConfig.d.ts +2 -1
  79. package/package.json +7 -6
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.webSocketImplementation = exports.sendMessageToWebSocketConnection = void 0;
13
+ const quidproquo_core_1 = require("quidproquo-core");
14
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
15
+ const http_1 = require("http");
16
+ const ws_1 = require("ws");
17
+ const actionProcessor_1 = require("../../actionProcessor");
18
+ const logic_1 = require("../../logic");
19
+ const getDynamicModuleLoader = (qpqConfig, devServerConfig) => {
20
+ const serviceName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
21
+ return (runtime) => __awaiter(void 0, void 0, void 0, function* () { return devServerConfig.dynamicModuleLoader(serviceName, runtime); });
22
+ };
23
+ const globals = {
24
+ allServers: [],
25
+ };
26
+ const findConnection = (service, apiName) => {
27
+ const serverInfo = globals.allServers.find((s) => s.service === service && s.apiName === apiName);
28
+ return serverInfo;
29
+ };
30
+ const sendMessageToWebSocketConnection = (service, websocketApiName, connectionId, payload) => __awaiter(void 0, void 0, void 0, function* () {
31
+ var _a, _b;
32
+ const wsConnection = (_b = (_a = findConnection(service, websocketApiName)) === null || _a === void 0 ? void 0 : _a.connections) === null || _b === void 0 ? void 0 : _b[connectionId];
33
+ if (!wsConnection) {
34
+ return;
35
+ }
36
+ wsConnection.send(JSON.stringify(payload));
37
+ });
38
+ exports.sendMessageToWebSocketConnection = sendMessageToWebSocketConnection;
39
+ const startServer = (settingsMap, devServerConfig) => {
40
+ const webSocketServer = new ws_1.WebSocketServer({ noServer: true });
41
+ console.log(`WebSocket: ws://${devServerConfig.serverDomain}:${devServerConfig.webSocketPort}/${settingsMap.service}/${settingsMap.apiName}`);
42
+ webSocketServer.on('connection', (ws, req) => {
43
+ const connectionId = req.headers['sec-websocket-key'] || crypto.randomUUID();
44
+ const sourceIp = req.socket.remoteAddress === '::1' || !req.socket.remoteAddress ? '127.0.0.1' : req.socket.remoteAddress;
45
+ const userAgent = req.headers['user-agent'] || 'unknown agent';
46
+ const server = findConnection(settingsMap.service, settingsMap.apiName);
47
+ server.connections[connectionId] = ws;
48
+ const processWsEvent = (wsEvent) => (0, logic_1.processEvent)(wsEvent, settingsMap.qpqConfig, getDynamicModuleLoader(settingsMap.qpqConfig, devServerConfig), actionProcessor_1.getWsWebsocketEventEventProcessor, quidproquo_core_1.QpqRuntimeType.WEBSOCKET_EVENT);
49
+ const onConnectEvent = {
50
+ apiName: settingsMap.apiName,
51
+ service: settingsMap.service,
52
+ eventType: quidproquo_webserver_1.WebSocketEventType.Connect,
53
+ body: undefined,
54
+ messageId: crypto.randomUUID(),
55
+ connectionId: connectionId,
56
+ requestTimeEpoch: Date.now(),
57
+ sourceIp: sourceIp,
58
+ userAgent: userAgent,
59
+ };
60
+ processWsEvent(onConnectEvent);
61
+ ws.on('error', console.error);
62
+ ws.on('message', (data, isBinary) => {
63
+ console.log('isBinary: ', isBinary);
64
+ const onMessageEvent = {
65
+ apiName: settingsMap.apiName,
66
+ service: settingsMap.service,
67
+ eventType: quidproquo_webserver_1.WebSocketEventType.Message,
68
+ body: data,
69
+ messageId: crypto.randomUUID(),
70
+ connectionId: connectionId,
71
+ requestTimeEpoch: Date.now(),
72
+ sourceIp: sourceIp,
73
+ userAgent: userAgent,
74
+ };
75
+ processWsEvent(onMessageEvent);
76
+ });
77
+ ws.on('close', () => {
78
+ delete server.connections[connectionId];
79
+ const onCloseEvent = {
80
+ apiName: settingsMap.apiName,
81
+ service: settingsMap.service,
82
+ eventType: quidproquo_webserver_1.WebSocketEventType.Disconnect,
83
+ body: undefined,
84
+ messageId: crypto.randomUUID(),
85
+ connectionId: connectionId,
86
+ requestTimeEpoch: Date.now(),
87
+ sourceIp: sourceIp,
88
+ userAgent: userAgent,
89
+ };
90
+ processWsEvent(onCloseEvent);
91
+ });
92
+ });
93
+ return Object.assign(Object.assign({}, settingsMap), { server: webSocketServer, connections: {} });
94
+ };
95
+ const getWebSocketQPQWebServerConfigSettingMaps = (qpqConfigs) => {
96
+ return qpqConfigs
97
+ .flatMap((qpqConfig) => {
98
+ const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
99
+ return quidproquo_webserver_1.qpqWebServerUtils.getWebsocketSettings(qpqConfig).flatMap((wsc) => {
100
+ const item = {
101
+ apiName: wsc.apiName,
102
+ service,
103
+ setting: wsc,
104
+ qpqConfig,
105
+ };
106
+ return item;
107
+ });
108
+ })
109
+ .filter((item, index, arr) => { var _a, _b; return arr[index].apiName !== item.apiName || !((_a = item.setting.owner) === null || _a === void 0 ? void 0 : _a.module) || arr[index].service === ((_b = item.setting.owner) === null || _b === void 0 ? void 0 : _b.module); });
110
+ };
111
+ const webSocketImplementation = (devServerConfig) => __awaiter(void 0, void 0, void 0, function* () {
112
+ if (!devServerConfig.webSocketPort) {
113
+ return;
114
+ }
115
+ const webSocketQPQWebServerConfigSettingMaps = getWebSocketQPQWebServerConfigSettingMaps(devServerConfig.qpqConfigs);
116
+ const server = (0, http_1.createServer)();
117
+ globals.allServers = webSocketQPQWebServerConfigSettingMaps.map((x) => startServer(x, devServerConfig));
118
+ server.on('upgrade', (request, socket, head) => {
119
+ const { pathname } = new URL(request.url || '', 'wss://base.url');
120
+ const serverInfo = globals.allServers.find((s) => pathname === `/${s.service}/${s.apiName}`);
121
+ if (serverInfo) {
122
+ serverInfo.server.handleUpgrade(request, socket, head, (ws) => {
123
+ serverInfo.server.emit('connection', ws, request);
124
+ });
125
+ }
126
+ else {
127
+ socket.destroy();
128
+ }
129
+ });
130
+ server.listen(devServerConfig.webSocketPort, 'localhost');
131
+ // Never ends
132
+ yield new Promise(() => { });
133
+ });
134
+ exports.webSocketImplementation = webSocketImplementation;
@@ -38,6 +38,9 @@ class EventBus extends events_1.EventEmitter {
38
38
  }
39
39
  publish(eventType, payload) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
+ // console.log('------------------------------------------------------------');
42
+ // console.log('\n\nEventBus - publish: [', eventType, ']', '[', payload?.type, ']');
43
+ // console.log('------------------------------------------------------------');
41
44
  this.emit(eventType, payload);
42
45
  });
43
46
  }
@@ -33,6 +33,7 @@ const startDevServer = (devServerConfig) => __awaiter(void 0, void 0, void 0, fu
33
33
  (0, implementations_1.serviceFunctionImplementation)(devServerConfig),
34
34
  (0, implementations_1.eventBusImplementation)(devServerConfig),
35
35
  (0, implementations_1.queueImplementation)(devServerConfig),
36
+ (0, implementations_1.webSocketImplementation)(devServerConfig),
36
37
  ]);
37
38
  });
38
39
  exports.startDevServer = startDevServer;
@@ -1,7 +1,8 @@
1
1
  import { QPQConfig, QpqFunctionRuntime } from 'quidproquo-core';
2
2
  export type DevServerConfig = {
3
3
  serverDomain: 'localhost';
4
- serverPort: 8080;
4
+ serverPort: number;
5
+ webSocketPort?: number;
5
6
  dynamicModuleLoader: <T = any>(serviceName: string, modulePath: QpqFunctionRuntime) => Promise<T>;
6
7
  qpqConfigs: QPQConfig[];
7
8
  };
@@ -1,3 +1,4 @@
1
1
  export * from './express';
2
2
  export * from './node';
3
3
  export * from './queue';
4
+ export * from './ws';
@@ -1,3 +1,4 @@
1
1
  export * from './express';
2
2
  export * from './node';
3
3
  export * from './queue';
4
+ export * from './ws';
@@ -2,7 +2,6 @@ import { awsLambdaUtils } from 'quidproquo-actionprocessor-awslambda';
2
2
  import { actionResult, actionResultError, ErrorTypeEnum, EventActionType, qpqCoreUtils, } from 'quidproquo-core';
3
3
  const getProcessMatchStory = (qpqConfig) => {
4
4
  return async ({ qpqEventRecord, eventParams: [event] }) => {
5
- console.log('qpqEventRecord', JSON.stringify(qpqEventRecord, null, 2));
6
5
  const queueQueueProcessors = qpqCoreUtils.getQueueQueueProcessors(event.queueName, qpqConfig);
7
6
  const queueTypes = Object.keys(queueQueueProcessors).sort();
8
7
  // Find the most relevant match
@@ -0,0 +1 @@
1
+ export * from './websocket';
@@ -0,0 +1 @@
1
+ export * from './websocket';
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getEventAutoRespondActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,9 @@
1
+ import { actionResult, EventActionType, } from 'quidproquo-core';
2
+ const getProcessAutoRespond = (qpqConfig) => {
3
+ return async ({ qpqEventRecord, matchResult }) => {
4
+ return actionResult(null);
5
+ };
6
+ };
7
+ export const getEventAutoRespondActionProcessor = async (qpqConfig) => ({
8
+ [EventActionType.AutoRespond]: getProcessAutoRespond(qpqConfig),
9
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getEventGetRecordsActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,38 @@
1
+ import { actionResult, EventActionType, } from 'quidproquo-core';
2
+ function processBody(body) {
3
+ if (!body) {
4
+ return undefined; // If the body is undefined, return undefined
5
+ }
6
+ // Convert the body to a string
7
+ if (Array.isArray(body)) {
8
+ // Merge Buffer[] into a single Buffer and convert to string
9
+ return Buffer.concat(body).toString();
10
+ }
11
+ else if (body instanceof ArrayBuffer) {
12
+ // Convert ArrayBuffer to string
13
+ return Buffer.from(body).toString();
14
+ }
15
+ else if (Buffer.isBuffer(body)) {
16
+ return body.toString(); // Convert Buffer to string
17
+ }
18
+ throw new Error('Unsupported body type');
19
+ }
20
+ const getProcessGetRecords = (qpqConfig) => {
21
+ return async ({ eventParams: [wsEvent] }) => {
22
+ const internalEventRecord = {
23
+ eventType: wsEvent.eventType,
24
+ messageId: wsEvent.messageId,
25
+ connectionId: wsEvent.connectionId,
26
+ requestTimeEpoch: wsEvent.requestTimeEpoch,
27
+ sourceIp: wsEvent.sourceIp,
28
+ userAgent: wsEvent.userAgent,
29
+ requestTime: new Date(wsEvent.requestTimeEpoch).toISOString(),
30
+ body: processBody(wsEvent.body),
31
+ apiName: wsEvent.apiName,
32
+ };
33
+ return actionResult([internalEventRecord]);
34
+ };
35
+ };
36
+ export const getEventGetRecordsActionProcessor = async (qpqConfig) => ({
37
+ [EventActionType.GetRecords]: getProcessGetRecords(qpqConfig),
38
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getEventGetStorySessionActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,9 @@
1
+ import { actionResult, EventActionType, } from 'quidproquo-core';
2
+ const getProcessGetStorySession = (qpqConfig) => {
3
+ return async ({ qpqEventRecord, eventParams }) => {
4
+ return actionResult(void 0);
5
+ };
6
+ };
7
+ export const getEventGetStorySessionActionProcessor = async (qpqConfig) => ({
8
+ [EventActionType.GetStorySession]: getProcessGetStorySession(qpqConfig),
9
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getEventMatchStoryActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,26 @@
1
+ import { actionResult, actionResultError, ErrorTypeEnum, EventActionType, } from 'quidproquo-core';
2
+ import { qpqWebServerUtils, WebSocketEventType } from 'quidproquo-webserver';
3
+ const getProcessMatchStory = (qpqConfig) => {
4
+ return async ({ qpqEventRecord, eventParams }) => {
5
+ const webSocketConfig = qpqWebServerUtils.getWebsocketEntryByApiName(qpqEventRecord.apiName, qpqConfig);
6
+ switch (qpqEventRecord.eventType) {
7
+ case WebSocketEventType.Connect:
8
+ return actionResult({
9
+ runtime: webSocketConfig.eventProcessors.onConnect,
10
+ });
11
+ case WebSocketEventType.Disconnect:
12
+ return actionResult({
13
+ runtime: webSocketConfig.eventProcessors.onDisconnect,
14
+ });
15
+ case WebSocketEventType.Message:
16
+ return actionResult({
17
+ runtime: webSocketConfig.eventProcessors.onMessage,
18
+ });
19
+ default:
20
+ return actionResultError(ErrorTypeEnum.NotFound, `Websocket lambda not implemented for ${qpqEventRecord.eventType}`);
21
+ }
22
+ };
23
+ };
24
+ export const getEventMatchStoryActionProcessor = async (qpqConfig) => ({
25
+ [EventActionType.MatchStory]: getProcessMatchStory(qpqConfig),
26
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getEventTransformResponseResultActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,14 @@
1
+ import { actionResult, actionResultError, EventActionType, } from 'quidproquo-core';
2
+ const getProcessTransformResponseResult = (qpqConfig) => {
3
+ return async ({ eventParams, qpqEventRecordResponses }) => {
4
+ const [record] = qpqEventRecordResponses;
5
+ if (!record.success) {
6
+ return actionResultError(record.error.errorType, record.error.errorText, record.error.errorStack);
7
+ }
8
+ // Transform back to api gateway
9
+ return actionResult(void 0);
10
+ };
11
+ };
12
+ export const getEventTransformResponseResultActionProcessor = async (qpqConfig) => ({
13
+ [EventActionType.TransformResponseResult]: getProcessTransformResponseResult(qpqConfig),
14
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getWsWebsocketEventEventProcessor: ActionProcessorListResolver;
@@ -0,0 +1,12 @@
1
+ import { getEventAutoRespondActionProcessor } from './getEventAutoRespondActionProcessor';
2
+ import { getEventGetRecordsActionProcessor } from './getEventGetRecordsActionProcessor';
3
+ import { getEventGetStorySessionActionProcessor } from './getEventGetStorySessionActionProcessor';
4
+ import { getEventMatchStoryActionProcessor } from './getEventMatchStoryActionProcessor';
5
+ import { getEventTransformResponseResultActionProcessor } from './getEventTransformResponseResultActionProcessor';
6
+ export const getWsWebsocketEventEventProcessor = async (qpqConfig, dynamicModuleLoader) => ({
7
+ ...(await getEventAutoRespondActionProcessor(qpqConfig, dynamicModuleLoader)),
8
+ ...(await getEventGetRecordsActionProcessor(qpqConfig, dynamicModuleLoader)),
9
+ ...(await getEventGetStorySessionActionProcessor(qpqConfig, dynamicModuleLoader)),
10
+ ...(await getEventMatchStoryActionProcessor(qpqConfig, dynamicModuleLoader)),
11
+ ...(await getEventTransformResponseResultActionProcessor(qpqConfig, dynamicModuleLoader)),
12
+ });
@@ -0,0 +1,8 @@
1
+ import { MatchStoryResult } from 'quidproquo-core';
2
+ import { WebsocketEvent, WebsocketEventResponse } from 'quidproquo-webserver';
3
+ import { WsEvent } from '../../../../../implementations/webSocket';
4
+ export type EventInput = [WsEvent];
5
+ export type EventOutput = void;
6
+ export type InternalEventRecord = WebsocketEvent<string | Blob | ArrayBuffer>;
7
+ export type InternalEventOutput = WebsocketEventResponse;
8
+ export type MatchResult = MatchStoryResult<any, any>;
@@ -1,4 +1,6 @@
1
1
  import { getServiceFunctionActionProcessor } from './serviceFunctionOverride';
2
+ import { getWebsocketActionProcessor } from './websocket';
2
3
  export const getWebserverActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
3
4
  ...(await getServiceFunctionActionProcessor(qpqConfig, dynamicModuleLoader)),
5
+ ...(await getWebsocketActionProcessor(qpqConfig, dynamicModuleLoader)),
4
6
  });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getWebsocketSendMessageActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,19 @@
1
+ import { actionResult, actionResultErrorFromCaughtError, qpqCoreUtils, } from 'quidproquo-core';
2
+ import { qpqWebServerUtils, WebsocketActionType } from 'quidproquo-webserver';
3
+ import { sendMessageToWebSocketConnection } from '../../../implementations/webSocket/webSocketImplementation';
4
+ const getProcessSendMessage = (qpqConfig) => {
5
+ return async ({ connectionId, payload, websocketApiName }) => {
6
+ const websocketConfig = qpqWebServerUtils.getWebsocketEntryByApiName(websocketApiName, qpqConfig);
7
+ const service = websocketConfig.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig);
8
+ try {
9
+ await sendMessageToWebSocketConnection(service, websocketApiName, connectionId, payload);
10
+ return actionResult(void 0);
11
+ }
12
+ catch (error) {
13
+ return actionResultErrorFromCaughtError(error, {});
14
+ }
15
+ };
16
+ };
17
+ export const getWebsocketSendMessageActionProcessor = async (qpqConfig) => ({
18
+ [WebsocketActionType.SendMessage]: getProcessSendMessage(qpqConfig),
19
+ });
@@ -0,0 +1,2 @@
1
+ import { ActionProcessorListResolver } from 'quidproquo-core';
2
+ export declare const getWebsocketActionProcessor: ActionProcessorListResolver;
@@ -0,0 +1,4 @@
1
+ import { getWebsocketSendMessageActionProcessor } from './getWebsocketSendMessageActionProcessor';
2
+ export const getWebsocketActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
3
+ ...(await getWebsocketSendMessageActionProcessor(qpqConfig, dynamicModuleLoader)),
4
+ });
@@ -1,40 +1,60 @@
1
- import { EventBusActionType, qpqCoreUtils, QueueActionType } from 'quidproquo-core';
2
- import { v4 as uuidV4 } from 'uuid';
3
- import { eventBus } from '../logic';
4
- const processQueueEventBusSubscriptions = async (qpqConfig, ebMessage) => {
5
- const allEventBuses = qpqCoreUtils.getAllEventBusConfigs(qpqConfig).filter((ebc) => {
6
- return ((!ebc.owner?.application || ebc.owner?.application === ebMessage.targetApplication) &&
7
- (!ebc.owner?.environment || ebc.owner?.environment === ebMessage.targetEnvironment) &&
8
- (!ebc.owner?.module || ebc.owner?.module === ebMessage.targetModule) &&
9
- ((!ebc.owner?.feature && !ebMessage.targetFeature) || ebc.owner?.feature === ebMessage.targetFeature));
1
+ // import { EventBusActionType, QPQConfig, qpqCoreUtils, QpqFunctionRuntime, QueueActionType } from 'quidproquo-core';
2
+ /*
3
+ const processQueueEventBusSubscriptions = async (qpqConfig: QPQConfig, ebMessage: AnyEventBusMessageWithSession) => {
4
+ const allEventBuses = qpqCoreUtils.getAllEventBusConfigs(qpqConfig).filter((ebc) => {
5
+ const thisService = qpqCoreUtils.getApplicationModuleName(qpqConfig);
6
+
7
+ const srcApplication = ebc.owner?.application || qpqCoreUtils.getApplicationName(qpqConfig);
8
+ const srcEnvironment = ebc.owner?.environment || qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
9
+ const srcFeature = ebc.owner?.feature || qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
10
+ const srcModule = ebc.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig);
11
+
12
+ return (
13
+ srcApplication === ebMessage.targetApplication &&
14
+ srcEnvironment === ebMessage.targetEnvironment &&
15
+ thisService == srcModule &&
16
+ srcModule === ebMessage.targetModule &&
17
+ ((!srcFeature && !ebMessage.targetFeature) || srcFeature === ebMessage.targetFeature)
18
+ );
19
+ });
20
+
21
+ // All the queues that we should publish to
22
+ const queues = qpqCoreUtils.getQueues(qpqConfig).filter((q) => {
23
+ return !!q.eventBusSubscriptions.find((ebsub) => {
24
+ return allEventBuses.some((eb) => ebsub === eb.owner?.resourceNameOverride || (!eb.owner?.resourceNameOverride && ebsub === eb.name));
10
25
  });
11
- // All the queues that we should publish to
12
- const queues = qpqCoreUtils.getQueues(qpqConfig).filter((q) => {
13
- return !!q.eventBusSubscriptions.find((ebsub) => {
14
- return allEventBuses.some((eb) => ebsub === eb.owner?.resourceNameOverride || (!eb.owner?.resourceNameOverride && ebsub === eb.name));
15
- });
16
- });
17
- for (const queue of queues) {
18
- const queueMessage = {
19
- payload: ebMessage.payload,
20
- type: ebMessage.type,
21
- storySession: ebMessage.storySession,
22
- queueName: queue.name,
23
- targetApplication: queue.owner?.application || qpqCoreUtils.getApplicationName(qpqConfig),
24
- targetEnvironment: queue.owner?.environment || qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig),
25
- targetFeature: queue.owner?.feature || qpqCoreUtils.getApplicationModuleFeature(qpqConfig),
26
- targetModule: queue.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig),
27
- messageId: uuidV4(),
28
- };
29
- eventBus.publish(QueueActionType.SendMessages, queueMessage);
30
- }
26
+ });
27
+
28
+ console.log('allEventBuses: ', queues);
29
+
30
+ for (const queue of queues) {
31
+ const queueMessage: AnyQueueMessageWithSession = {
32
+ payload: ebMessage.payload,
33
+ type: ebMessage.type,
34
+
35
+ storySession: ebMessage.storySession,
36
+
37
+ queueName: queue.name,
38
+
39
+ targetApplication: queue.owner?.application || qpqCoreUtils.getApplicationName(qpqConfig),
40
+ targetEnvironment: queue.owner?.environment || qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig),
41
+ targetFeature: queue.owner?.feature || qpqCoreUtils.getApplicationModuleFeature(qpqConfig),
42
+ targetModule: queue.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig),
43
+
44
+ messageId: uuidV4(),
45
+ };
46
+
47
+ eventBus.publish(QueueActionType.SendMessages, queueMessage);
48
+ }
31
49
  };
50
+ */
32
51
  export const eventBusImplementation = async (devServerConfig) => {
33
- eventBus.on(EventBusActionType.SendMessages, async (payload, correlation) => {
34
- for (const qpqConfig of devServerConfig.qpqConfigs) {
35
- await processQueueEventBusSubscriptions(qpqConfig, payload);
36
- }
37
- });
52
+ // eventBus.on(EventBusActionType.SendMessages, async (payload: AnyEventBusMessageWithSession, correlation: string) => {
53
+ // console.log('Event Buss Ready to process!');
54
+ // for (const qpqConfig of devServerConfig.qpqConfigs) {
55
+ // await processQueueEventBusSubscriptions(qpqConfig, payload);
56
+ // }
57
+ // });
38
58
  // Never ends
39
59
  await new Promise(() => { });
40
60
  };
@@ -2,3 +2,4 @@ export * from './apiImplementation';
2
2
  export * from './eventBusImplementation';
3
3
  export * from './queueImplementation';
4
4
  export * from './serviceFunctionImplementation';
5
+ export * from './webSocket';
@@ -2,3 +2,4 @@ export * from './apiImplementation';
2
2
  export * from './eventBusImplementation';
3
3
  export * from './queueImplementation';
4
4
  export * from './serviceFunctionImplementation';
5
+ export * from './webSocket';
@@ -1,4 +1,5 @@
1
- import { qpqCoreUtils, QpqRuntimeType, QueueActionType } from 'quidproquo-core';
1
+ import { EventBusActionType, qpqCoreUtils, QpqRuntimeType, QueueActionType } from 'quidproquo-core';
2
+ import { v4 as uuidV4 } from 'uuid';
2
3
  import { getQueueEventProcessor } from '../actionProcessor/core/event/queue';
3
4
  import { eventBus, processEvent } from '../logic';
4
5
  const getDynamicModuleLoader = (qpqConfig, devServerConfig) => {
@@ -16,19 +17,58 @@ const processQueueMessages = async (qpqConfig, payload, devServerConfig) => {
16
17
  return;
17
18
  }
18
19
  const feature = qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
19
- if ((!!payload.targetFeature || !!feature) && payload.targetFeature !== qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig)) {
20
+ if ((!!payload.targetFeature || !!feature) && payload.targetFeature !== feature) {
20
21
  return;
21
22
  }
22
- console.log('Ready to process: ', JSON.stringify(payload, null, 2));
23
23
  await processEvent(payload, qpqConfig, getDynamicModuleLoader(qpqConfig, devServerConfig), getQueueEventProcessor, QpqRuntimeType.QUEUE_EVENT);
24
24
  };
25
+ const processQueueEventBusSubscriptions = async (qpqConfig, ebMessage) => {
26
+ const thisServiceName = qpqCoreUtils.getApplicationModuleName(qpqConfig);
27
+ const allEventBuses = qpqCoreUtils.getAllEventBusConfigs(qpqConfig).filter((ebc) => {
28
+ const srcApplication = ebc.owner?.application || qpqCoreUtils.getApplicationName(qpqConfig);
29
+ const srcEnvironment = ebc.owner?.environment || qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
30
+ const srcFeature = ebc.owner?.feature || qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
31
+ const srcModule = ebc.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig);
32
+ return (srcApplication === ebMessage.targetApplication &&
33
+ srcEnvironment === ebMessage.targetEnvironment &&
34
+ srcModule === ebMessage.targetModule &&
35
+ ((!srcFeature && !ebMessage.targetFeature) || srcFeature === ebMessage.targetFeature));
36
+ });
37
+ // All the queues that we should publish to
38
+ const queues = qpqCoreUtils
39
+ .getQueues(qpqConfig)
40
+ .filter((q) => {
41
+ return !!q.eventBusSubscriptions.find((ebsub) => {
42
+ return allEventBuses.some((eb) => ebsub === eb.name);
43
+ });
44
+ })
45
+ .filter((q) => !q.owner?.module || q.owner?.module === thisServiceName);
46
+ for (const queue of queues) {
47
+ const queueMessage = {
48
+ payload: ebMessage.payload,
49
+ type: ebMessage.type,
50
+ storySession: ebMessage.storySession,
51
+ queueName: queue.name,
52
+ targetApplication: queue.owner?.application || qpqCoreUtils.getApplicationName(qpqConfig),
53
+ targetEnvironment: queue.owner?.environment || qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig),
54
+ targetFeature: queue.owner?.feature || qpqCoreUtils.getApplicationModuleFeature(qpqConfig),
55
+ targetModule: queue.owner?.module || qpqCoreUtils.getApplicationModuleName(qpqConfig),
56
+ messageId: uuidV4(),
57
+ };
58
+ eventBus.publish(QueueActionType.SendMessages, queueMessage);
59
+ }
60
+ };
25
61
  export const queueImplementation = async (devServerConfig) => {
26
62
  eventBus.on(QueueActionType.SendMessages, async (payload, correlation) => {
27
- console.log('Got QUEUE send message event');
28
63
  for (const qpqConfig of devServerConfig.qpqConfigs) {
29
64
  await processQueueMessages(qpqConfig, payload, devServerConfig);
30
65
  }
31
66
  });
67
+ eventBus.on(EventBusActionType.SendMessages, async (payload, correlation) => {
68
+ for (const qpqConfig of devServerConfig.qpqConfigs) {
69
+ await processQueueEventBusSubscriptions(qpqConfig, payload);
70
+ }
71
+ });
32
72
  // Never ends
33
73
  await new Promise(() => { });
34
74
  };
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './webSocketImplementation';
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './webSocketImplementation';
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { WebSocketEventType } from 'quidproquo';
3
+ export type WsEvent = {
4
+ apiName: string;
5
+ service: string;
6
+ eventType: WebSocketEventType;
7
+ body?: ArrayBuffer | Buffer | Buffer[];
8
+ messageId: string;
9
+ connectionId: string;
10
+ requestTimeEpoch: number;
11
+ sourceIp: string;
12
+ userAgent: string;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './WsEvent';
@@ -0,0 +1 @@
1
+ export * from './WsEvent';
@@ -0,0 +1,3 @@
1
+ import { DevServerConfig } from '../../types';
2
+ export declare const sendMessageToWebSocketConnection: (service: string, websocketApiName: string, connectionId: string, payload: any) => Promise<void>;
3
+ export declare const webSocketImplementation: (devServerConfig: DevServerConfig) => Promise<void>;