kozz-module-maker 0.1.21 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +24 -0
- package/bun.lock +617 -0
- package/dist/InlineCommands/index.js +19 -11
- package/dist/Instance/Basic/index.d.ts +40 -0
- package/dist/Instance/Basic/index.js +43 -0
- package/dist/Instance/Basic/index.js.map +1 -0
- package/dist/Instance/BasicController/index.d.ts +40 -0
- package/dist/Instance/BasicController/index.js +43 -0
- package/dist/Instance/BasicController/index.js.map +1 -0
- package/dist/Instance/CommandHandler/index.d.ts +20 -0
- package/dist/Instance/CommandHandler/index.js +26 -0
- package/dist/Instance/CommandHandler/index.js.map +1 -0
- package/dist/Instance/Common/ResourceMap/index.js +17 -15
- package/dist/Instance/Common/UseFns/index.js +24 -19
- package/dist/Instance/Common/index.js +31 -9
- package/dist/Instance/Common/onEvent/index.js +82 -76
- package/dist/Instance/Common/onEvent/index.js.map +1 -1
- package/dist/Instance/GeneralHandler/index.d.ts +19 -0
- package/dist/Instance/GeneralHandler/index.js +49 -0
- package/dist/Instance/GeneralHandler/index.js.map +1 -0
- package/dist/Instance/GeneralModule/index.d.ts +1 -2
- package/dist/Instance/GeneralModule/index.js +83 -58
- package/dist/Instance/GeneralModule/index.js.map +1 -1
- package/dist/Instance/Handler/index.d.ts +23 -0
- package/dist/Instance/Handler/index.js +26 -0
- package/dist/Instance/Handler/index.js.map +1 -0
- package/dist/Instance/Proxy/index.d.ts +22 -0
- package/dist/Instance/Proxy/index.js +36 -0
- package/dist/Instance/Proxy/index.js.map +1 -0
- package/dist/Instance/index.d.ts +14 -0
- package/dist/Instance/index.js +20 -0
- package/dist/Instance/index.js.map +1 -0
- package/dist/Message/FromTemplate/index.js +53 -46
- package/dist/Message/PayloadCreation/Media.js +40 -36
- package/dist/Message/PayloadCreation/Media.js.map +1 -1
- package/dist/Message/PayloadCreation/React.js +11 -9
- package/dist/Message/PayloadCreation/Reply.js +37 -35
- package/dist/Message/PayloadCreation/Reply.js.map +1 -1
- package/dist/Message/PayloadCreation/ReplyWithSticker.d.ts +0 -0
- package/dist/Message/PayloadCreation/ReplyWithSticker.js +1 -0
- package/dist/Message/PayloadCreation/ReplyWithText.d.ts +2 -0
- package/dist/Message/PayloadCreation/ReplyWithText.js +15 -0
- package/dist/Message/PayloadCreation/deleteMessage.js +10 -8
- package/dist/Message/PayloadCreation/index.js +25 -17
- package/dist/Message/PayloadCreation/sendMessage.js +23 -21
- package/dist/Message/PayloadCreation/sendMessage.js.map +1 -1
- package/dist/Message/ProxiedMessage/index.d.ts +1 -1
- package/dist/Message/ProxiedMessage/index.js +17 -11
- package/dist/Message/RoutineCreation/AskResource/AskResourceApi/index.js +21 -16
- package/dist/Message/RoutineCreation/AskResource/index.js +58 -56
- package/dist/Message/RoutineCreation/DeleteMessage/index.js +18 -14
- package/dist/Message/RoutineCreation/Reply/WithMedia.js +32 -30
- package/dist/Message/RoutineCreation/Reply/WithSticke.d.ts +3 -0
- package/dist/Message/RoutineCreation/Reply/WithSticke.js +9 -0
- package/dist/Message/RoutineCreation/Reply/WithSticke.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/WithSticker.js +14 -8
- package/dist/Message/RoutineCreation/Reply/WithTemplate.js +15 -15
- package/dist/Message/RoutineCreation/Reply/index.js +25 -9
- package/dist/Message/RoutineCreation/SendMessage/index.js +25 -23
- package/dist/Message/RoutineCreation/SendMessage/index.js.map +1 -1
- package/dist/Message/RoutineCreation/reply.js +16 -14
- package/dist/Message/index.d.ts +1 -1
- package/dist/Message/index.js +49 -46
- package/dist/Message/kozz-md.parser/index.js +42 -92
- package/dist/Message/zap-md.parser/index.d.ts +1 -0
- package/dist/Message/zap-md.parser/index.js +2 -0
- package/dist/MessageTemplate/h.d.ts +3 -0
- package/dist/MessageTemplate/h.js +24 -0
- package/dist/MessageTemplate/h.js.map +1 -0
- package/dist/MessageTemplate/htm.d.ts +1 -0
- package/dist/MessageTemplate/htm.js +10 -0
- package/dist/MessageTemplate/htm.js.map +1 -0
- package/dist/MessageTemplate/renderer.d.ts +13 -0
- package/dist/MessageTemplate/renderer.js +62 -0
- package/dist/MessageTemplate/renderer.js.map +1 -0
- package/dist/MessageTemplate/types.d.ts +12 -0
- package/dist/MessageTemplate/types.js +5 -0
- package/dist/MessageTemplate/types.js.map +1 -0
- package/dist/Schema/index.js +11 -9
- package/dist/Socket/Events/Command.d.ts +3 -0
- package/dist/Socket/Events/Command.js +19 -0
- package/dist/Socket/Events/Command.js.map +1 -0
- package/dist/Socket/Events/Emit/ForwardEvent.js +19 -17
- package/dist/Socket/Events/Emit/Introduction.js +12 -10
- package/dist/Socket/Events/Emit/ProxyRequest.d.ts +0 -0
- package/dist/Socket/Events/Emit/ProxyRequest.js +2 -0
- package/dist/Socket/Events/Emit/ProxyRequest.js.map +1 -0
- package/dist/Socket/Events/Emit/RequestProxy.js +13 -10
- package/dist/Socket/Events/Emit/RevokeProxy.js +9 -7
- package/dist/Socket/Events/Handle/AskResource.js +27 -25
- package/dist/Socket/Events/Handle/Command.js +35 -38
- package/dist/Socket/Events/Handle/ProxiedMessage.js +11 -9
- package/dist/Socket/Events/Introduction.d.ts +3 -0
- package/dist/Socket/Events/Introduction.js +15 -0
- package/dist/Socket/Events/Introduction.js.map +1 -0
- package/dist/Socket/Events/ProxiedMessage.d.ts +2 -0
- package/dist/Socket/Events/ProxiedMessage.js +10 -0
- package/dist/Socket/Events/ProxiedMessage.js.map +1 -0
- package/dist/Socket/Messages/Command.d.ts +2 -0
- package/dist/Socket/Messages/Command.js +6 -0
- package/dist/Socket/Messages/Command.js.map +1 -0
- package/dist/Socket/Messages/Introduction.d.ts +3 -0
- package/dist/Socket/Messages/Introduction.js +15 -0
- package/dist/Socket/Messages/Introduction.js.map +1 -0
- package/dist/Socket/index.js +17 -15
- package/dist/StateMachine/index.js +44 -38
- package/dist/Validator/index.js +41 -38
- package/dist/debugIndex.d.ts +1 -0
- package/dist/debugIndex.js +73 -0
- package/dist/debugIndex.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime/MessageTemplating.js +51 -0
- package/dist/jsx-runtime/index.js +83 -0
- package/dist/messages.kozz.md +52 -0
- package/dist/util/index.js +63 -59
- package/dist/util/index.js.map +1 -1
- package/dist/util.d.ts +8 -0
- package/dist/util.js +36 -0
- package/dist/util.js.map +1 -0
- package/package.json +21 -17
- package/tsconfig.json +26 -97
- package/jest.config.ts +0 -196
- package/test.kozz.md +0 -81
package/dist/Schema/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.createMethod = void 0;
|
|
4
7
|
/**
|
|
5
8
|
* Creates a command that can be inserted in any command Handler
|
|
@@ -10,12 +13,11 @@ exports.createMethod = void 0;
|
|
|
10
13
|
*/
|
|
11
14
|
//@ts-ignore
|
|
12
15
|
const createMethod = (name, callback, args = {}) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return {
|
|
17
|
+
[name]: {
|
|
18
|
+
args,
|
|
19
|
+
func: callback
|
|
20
|
+
}
|
|
21
|
+
};
|
|
19
22
|
};
|
|
20
|
-
exports.createMethod = createMethod;
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
23
|
+
exports.createMethod = createMethod;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onCommand = void 0;
|
|
4
|
+
const Message_1 = require("../../Message");
|
|
5
|
+
const Validator_1 = require("../../Validator");
|
|
6
|
+
const util_1 = require("../../util");
|
|
7
|
+
const onCommand = (socket, methods, moduleUseFns, templatePath) => {
|
|
8
|
+
socket.on('command', (command) => {
|
|
9
|
+
if (Object.keys(methods).includes(command.method)) {
|
|
10
|
+
const actualMethod = methods[command.method];
|
|
11
|
+
if ((0, Validator_1.isArgsObjectValid)(command.namedArgs, actualMethod.args)) {
|
|
12
|
+
const message = (0, Message_1.createMessageObject)(socket, (0, util_1.runUse)(moduleUseFns, command), templatePath);
|
|
13
|
+
actualMethod.func(message, command.namedArgs);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.onCommand = onCommand;
|
|
19
|
+
//# sourceMappingURL=Command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/Socket/Events/Command.ts"],"names":[],"mappings":";;;AAGA,2CAAoD;AACpD,+CAAoD;AACpD,qCAAoC;AAE7B,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,OAAU,EACV,YAAqB,EACrB,YAAoB,EACnB,EAAE;IACH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;QACzC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAClD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7C,IAAI,IAAA,6BAAiB,EAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE;gBAC5D,MAAM,OAAO,GAAG,IAAA,6BAAmB,EAClC,MAAM,EACN,IAAA,aAAM,EAAC,YAAY,EAAE,OAAO,CAAC,EAC7B,YAAY,CACZ,CAAC;gBACF,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;aAC9C;SACD;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,SAAS,aAqBpB"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.listenBoundary = void 0;
|
|
4
|
-
const listenBoundary = (gatewaySocket, instanceName) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
eventName,
|
|
13
|
-
sourceId: boundaryId,
|
|
14
|
-
};
|
|
15
|
-
gatewaySocket.emit('event_forward_request', payload);
|
|
16
|
-
gatewaySocket.on(eventName, callback);
|
|
7
|
+
const listenBoundary = (gatewaySocket, instanceName) => boundaryId => {
|
|
8
|
+
return {
|
|
9
|
+
when: (eventName, callback) => {
|
|
10
|
+
const payload = {
|
|
11
|
+
destination: {
|
|
12
|
+
id: instanceName,
|
|
13
|
+
type: 'Handler'
|
|
17
14
|
},
|
|
18
|
-
|
|
15
|
+
eventName,
|
|
16
|
+
sourceId: boundaryId
|
|
17
|
+
};
|
|
18
|
+
gatewaySocket.emit('event_forward_request', payload);
|
|
19
|
+
gatewaySocket.on(eventName, callback);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
19
22
|
};
|
|
20
|
-
exports.listenBoundary = listenBoundary;
|
|
21
|
-
//# sourceMappingURL=ForwardEvent.js.map
|
|
23
|
+
exports.listenBoundary = listenBoundary;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.introduce = void 0;
|
|
4
|
-
|
|
7
|
+
var _util = require("../../../util");
|
|
5
8
|
/**
|
|
6
9
|
* Emits the introduction payload to the gateway
|
|
7
10
|
* @param socket
|
|
@@ -10,12 +13,11 @@ const util_1 = require("../../../util");
|
|
|
10
13
|
* @param signature
|
|
11
14
|
*/
|
|
12
15
|
const introduce = async (socket, handlerName, methods, signature) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const payload = {
|
|
17
|
+
methods: Object.keys(methods),
|
|
18
|
+
name: handlerName,
|
|
19
|
+
role: 'handler'
|
|
20
|
+
};
|
|
21
|
+
socket.emit('introduction', await (0, _util.signPayload)(payload, signature));
|
|
19
22
|
};
|
|
20
|
-
exports.introduce = introduce;
|
|
21
|
-
//# sourceMappingURL=Introduction.js.map
|
|
23
|
+
exports.introduce = introduce;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyRequest.js","sourceRoot":"","sources":["../../../../src/Socket/Events/Emit/ProxyRequest.ts"],"names":[],"mappings":""}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.requestProxy = void 0;
|
|
4
|
-
const createProxyRequestPayload =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const createProxyRequestPayload = proxyInitParams => {
|
|
8
|
+
return {
|
|
9
|
+
source: proxyInitParams.source,
|
|
10
|
+
keepAlive: proxyInitParams.keepProxyAlive,
|
|
11
|
+
destination: proxyInitParams.destinationOverride || proxyInitParams.name
|
|
12
|
+
};
|
|
10
13
|
};
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* Request proxy for a given
|
|
13
17
|
* @param socket
|
|
14
18
|
* @param proxyInitParams
|
|
15
19
|
*/
|
|
16
20
|
const requestProxy = (socket, proxyInitParams) => {
|
|
17
|
-
|
|
21
|
+
socket.emit('request_proxy', createProxyRequestPayload(proxyInitParams));
|
|
18
22
|
};
|
|
19
|
-
exports.requestProxy = requestProxy;
|
|
20
|
-
//# sourceMappingURL=RequestProxy.js.map
|
|
23
|
+
exports.requestProxy = requestProxy;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.revokeProxy = void 0;
|
|
4
7
|
/**
|
|
5
8
|
* Request the revoking of a proxy
|
|
@@ -7,10 +10,9 @@ exports.revokeProxy = void 0;
|
|
|
7
10
|
* @param source
|
|
8
11
|
*/
|
|
9
12
|
const revokeProxy = (socket, source) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const payload = {
|
|
14
|
+
source: source
|
|
15
|
+
};
|
|
16
|
+
socket.emit('revoke_proxy', payload);
|
|
14
17
|
};
|
|
15
|
-
exports.revokeProxy = revokeProxy;
|
|
16
|
-
//# sourceMappingURL=RevokeProxy.js.map
|
|
18
|
+
exports.revokeProxy = revokeProxy;
|
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.onAskResource = void 0;
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
12
|
/**
|
|
5
13
|
* Provide the resource asked
|
|
6
14
|
* @param socket
|
|
7
15
|
* @param resourceMap
|
|
8
16
|
*/
|
|
9
17
|
const onAskResource = (socket, resourceMap) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
...payload,
|
|
19
|
-
response: resource,
|
|
20
|
-
};
|
|
21
|
-
socket.emit('reply_resource', responsePayload);
|
|
22
|
-
});
|
|
18
|
+
socket.on('ask_resource', payload => {
|
|
19
|
+
const resourceGetter = resourceMap[payload.request.resource];
|
|
20
|
+
if (!resourceGetter) return socket.emit('reply_resource', _objectSpread({}, payload));
|
|
21
|
+
promisify(resourceGetter(payload.request.data)).then(resource => {
|
|
22
|
+
const responsePayload = _objectSpread(_objectSpread({}, payload), {}, {
|
|
23
|
+
response: resource
|
|
24
|
+
});
|
|
25
|
+
socket.emit('reply_resource', responsePayload);
|
|
23
26
|
});
|
|
27
|
+
});
|
|
24
28
|
};
|
|
25
29
|
exports.onAskResource = onAskResource;
|
|
26
|
-
const promisify =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=AskResource.js.map
|
|
30
|
+
const promisify = resource => {
|
|
31
|
+
return new Promise(resolve => {
|
|
32
|
+
if (resource instanceof Promise) {
|
|
33
|
+
resource.then(resp => resolve(resp));
|
|
34
|
+
} else {
|
|
35
|
+
resolve(resource);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.onCommand = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
var _Message = require("../../../Message");
|
|
8
|
+
var _Validator = require("../../../Validator");
|
|
9
|
+
var _util = require("../../../util");
|
|
7
10
|
/**
|
|
8
11
|
* Handles the command received. It will check if the boundary should have it's command handled,
|
|
9
12
|
* find the correct method, parse, typecheck the args, run the middlewares and try to run the method
|
|
@@ -15,38 +18,32 @@ const util_1 = require("../../../util");
|
|
|
15
18
|
* @param boundariesToHandle
|
|
16
19
|
*/
|
|
17
20
|
const onCommand = (socket, methods, moduleUseFns, handlerName, templatePath, boundariesToHandle) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
boundaryId: command.boundaryId,
|
|
46
|
-
emote: '❌',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
21
|
+
socket.on('command', command => {
|
|
22
|
+
// If the handler doesnt want to handle commands for the provided boundary
|
|
23
|
+
if (!boundariesToHandle.includes(command.boundaryName) && !boundariesToHandle.includes('*')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const actualMethod = methods[(0, _util.normalizeString)((0, _util.normalizeString)(command.method))] || methods['fallback'];
|
|
27
|
+
if (!actualMethod) return;
|
|
28
|
+
if ((0, _Validator.isArgsObjectValid)(command.namedArgs || {}, actualMethod.args)) {
|
|
29
|
+
const updatedCommand = (0, _util.runUse)(moduleUseFns, command);
|
|
30
|
+
if ('abort' in (updatedCommand.namedArgs ?? {})) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const message = (0, _Message.createMessageObject)(socket, command.message, handlerName, templatePath, command);
|
|
34
|
+
socket.emit('react_message', {
|
|
35
|
+
messageId: command.message.id,
|
|
36
|
+
boundaryId: command.boundaryId,
|
|
37
|
+
emote: '✔'
|
|
38
|
+
});
|
|
39
|
+
actualMethod.func(message, updatedCommand.namedArgs || {});
|
|
40
|
+
} else {
|
|
41
|
+
socket.emit('react_message', {
|
|
42
|
+
messageId: command.message.id,
|
|
43
|
+
boundaryId: command.boundaryId,
|
|
44
|
+
emote: '❌'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
50
48
|
};
|
|
51
|
-
exports.onCommand = onCommand;
|
|
52
|
-
//# sourceMappingURL=Command.js.map
|
|
49
|
+
exports.onCommand = onCommand;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.onProxiedMessage = void 0;
|
|
4
|
-
|
|
7
|
+
var _ProxiedMessage = require("../../../Message/ProxiedMessage");
|
|
5
8
|
/**
|
|
6
9
|
* Handles the message proxied to the handler
|
|
7
10
|
* @param socket
|
|
@@ -9,11 +12,10 @@ const ProxiedMessage_1 = require("../../../Message/ProxiedMessage");
|
|
|
9
12
|
* @param cb
|
|
10
13
|
*/
|
|
11
14
|
const onProxiedMessage = (socket, source, cb) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
socket.removeAllListeners('proxied_message');
|
|
16
|
+
socket.on('proxied_message', payload => {
|
|
17
|
+
const proxiedMessageObject = (0, _ProxiedMessage.createProxiedMessageOject)(socket, source, payload, source.split('/')[0]);
|
|
18
|
+
cb(proxiedMessageObject);
|
|
19
|
+
});
|
|
17
20
|
};
|
|
18
|
-
exports.onProxiedMessage = onProxiedMessage;
|
|
19
|
-
//# sourceMappingURL=ProxiedMessage.js.map
|
|
21
|
+
exports.onProxiedMessage = onProxiedMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.introduce = void 0;
|
|
4
|
+
const util_1 = require("src/util");
|
|
5
|
+
const introduce = (socket, handlerName, methods) => {
|
|
6
|
+
const payload = {
|
|
7
|
+
methods: Object.keys(methods),
|
|
8
|
+
name: handlerName,
|
|
9
|
+
role: 'handler',
|
|
10
|
+
timestamp: new Date().getTime(),
|
|
11
|
+
};
|
|
12
|
+
socket.emit('introduction', (0, util_1.signPayload)(payload));
|
|
13
|
+
};
|
|
14
|
+
exports.introduce = introduce;
|
|
15
|
+
//# sourceMappingURL=Introduction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Introduction.js","sourceRoot":"","sources":["../../../src/Socket/Events/Introduction.ts"],"names":[],"mappings":";;;AAGA,mCAAuC;AAEhC,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,WAAmB,EACnB,OAAU,EACT,EAAE;IACH,MAAM,OAAO,GAA8C;QAC1D,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KAC/B,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,IAAA,kBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onProxiedMessage = void 0;
|
|
4
|
+
const onProxiedMessage = (socket) => {
|
|
5
|
+
socket.on('proxied_message', payload => {
|
|
6
|
+
console.log(payload.body);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
exports.onProxiedMessage = onProxiedMessage;
|
|
10
|
+
//# sourceMappingURL=ProxiedMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxiedMessage.js","sourceRoot":"","sources":["../../../src/Socket/Events/ProxiedMessage.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAE,EAAE;IAClD,MAAM,CAAC,EAAE,CAAC,iBAAiB,EAAE,OAAO,CAAC,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/Socket/Messages/Command.ts"],"names":[],"mappings":";;;AAEO,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,QAAkB,EAAE,EAAE,GAAE,CAAC,CAAC;AAAvD,QAAA,SAAS,aAA8C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.introduce = void 0;
|
|
4
|
+
const util_1 = require("src/util");
|
|
5
|
+
const introduce = (socket, handlerName, methods) => {
|
|
6
|
+
const payload = {
|
|
7
|
+
methods: Object.keys(methods),
|
|
8
|
+
name: handlerName,
|
|
9
|
+
role: 'handler',
|
|
10
|
+
timestamp: new Date().getTime(),
|
|
11
|
+
};
|
|
12
|
+
socket.emit('introduction', (0, util_1.signPayload)(payload));
|
|
13
|
+
};
|
|
14
|
+
exports.introduce = introduce;
|
|
15
|
+
//# sourceMappingURL=Introduction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Introduction.js","sourceRoot":"","sources":["../../../src/Socket/Messages/Introduction.ts"],"names":[],"mappings":";;;AAKA,mCAAuC;AAEhC,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,WAAmB,EACnB,OAAU,EACT,EAAE;IACH,MAAM,OAAO,GAA8C;QAC1D,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KAC/B,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,IAAA,kBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB"}
|
package/dist/Socket/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.connect = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
var _socket = require("socket.io-client");
|
|
8
|
+
var _Command = require("./Events/Handle/Command");
|
|
6
9
|
const connect = (onConnect, address, moduleUseFns, templatePath, handlerName, boundariesToHandle, socketPath = '/socket.io/') => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const connectionObj = {
|
|
11
|
+
path: socketPath
|
|
12
|
+
};
|
|
13
|
+
const socket = (0, _socket.io)(address, connectionObj);
|
|
14
|
+
socket.on('connect', onConnect);
|
|
15
|
+
const registerMethods = methods => (0, _Command.onCommand)(socket, methods, moduleUseFns, handlerName, templatePath, boundariesToHandle);
|
|
16
|
+
return {
|
|
17
|
+
socket,
|
|
18
|
+
registerMethods
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
|
-
exports.connect = connect;
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
21
|
+
exports.connect = connect;
|
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.createStateMachine = exports.createNewStateMachineInstance = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
const createNewStateMachineInstance = stateMachineDescriptor => {
|
|
13
|
+
const stateMachine = _objectSpread(_objectSpread({}, stateMachineDescriptor), {}, {
|
|
14
|
+
currentState: stateMachineDescriptor.initialState,
|
|
15
|
+
setState: newState => {
|
|
16
|
+
stateMachine.currentState = newState;
|
|
17
|
+
},
|
|
18
|
+
reset: () => stateMachine.setState(stateMachine.initialState)
|
|
19
|
+
});
|
|
20
|
+
return stateMachine;
|
|
14
21
|
};
|
|
15
22
|
exports.createNewStateMachineInstance = createNewStateMachineInstance;
|
|
16
|
-
const createStateMachine =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
const createStateMachine = stateMachineDescriptor => {
|
|
24
|
+
const userStateMap = new Map();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* One single instance per contact.
|
|
28
|
+
* @param contactId
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
const getStateMachine = contactId => {
|
|
32
|
+
if (!userStateMap.get(contactId)) {
|
|
33
|
+
userStateMap.set(contactId,
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
createNewStateMachineInstance(stateMachineDescriptor));
|
|
36
|
+
}
|
|
37
|
+
return userStateMap.get(contactId);
|
|
38
|
+
};
|
|
39
|
+
return requester => {
|
|
40
|
+
const stateMachine = getStateMachine(requester.message.contact.id);
|
|
41
|
+
const oldState = stateMachine.currentState;
|
|
42
|
+
stateMachine.states[stateMachine.currentState].onMessage(requester, stateMachine);
|
|
43
|
+
const newState = stateMachine.currentState;
|
|
44
|
+
if (newState !== oldState) {
|
|
45
|
+
stateMachine.states[stateMachine.currentState].onStateEnable?.(requester, stateMachine);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
41
48
|
};
|
|
42
|
-
exports.createStateMachine = createStateMachine;
|
|
43
|
-
//# sourceMappingURL=index.js.map
|
|
49
|
+
exports.createStateMachine = createStateMachine;
|