ttc-origin-server 0.1.0 → 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.
@@ -0,0 +1,12 @@
1
+ import express from 'express';
2
+ export declare const runServer: (config: {
3
+ name: string;
4
+ description?: string;
5
+ modules: any[];
6
+ port: number;
7
+ requireAuth?: boolean;
8
+ modifyable?: boolean;
9
+ authCb: (req: any) => Promise<boolean>;
10
+ app?: express.Express;
11
+ }) => void;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,eAAO,MAAM,SAAS,GAAI,QAAQ;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,CAAA;CACxB,SAkDA,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runServer = void 0;
7
+ const ttc_rpc_1 = require("ttc-rpc");
8
+ const express_1 = __importDefault(require("express"));
9
+ const runServer = (config) => {
10
+ const { modules, port, app } = config;
11
+ const appInstance = app || (0, express_1.default)();
12
+ config.name = config.name.replace(/\s+/g, '_').toLowerCase();
13
+ // authenticate to the ttc server
14
+ // the server will get the definition and Qualities and url etc
15
+ appInstance.get('/rpc/info', (req, res) => {
16
+ res.json({
17
+ name: config.name,
18
+ description: config.description || '',
19
+ requireAuth: config.requireAuth,
20
+ directory: config.modifyable ? process.cwd() : undefined
21
+ });
22
+ });
23
+ appInstance.get('/rpc/functions', (req, res) => {
24
+ const queryParams = req.query;
25
+ const assistant = queryParams.assistant;
26
+ console.log(`${assistant} is accessing the RPC definitions..`);
27
+ const info = (0, ttc_rpc_1.generateRPCMethodsInfo)();
28
+ const finalFunctions = [];
29
+ Object.keys(info).forEach((module) => {
30
+ const functions = info[module]?.map((func) => {
31
+ return {
32
+ ...func,
33
+ name: `${config.name}.${module}.${func.name}`
34
+ };
35
+ }) || [];
36
+ finalFunctions.push(...functions);
37
+ });
38
+ console.log(JSON.stringify(finalFunctions, null, 2));
39
+ res.json({
40
+ functions: finalFunctions
41
+ });
42
+ });
43
+ ttc_rpc_1.ttc.init({
44
+ app: appInstance,
45
+ modules: modules,
46
+ generate_client: false,
47
+ authCb: async (req) => {
48
+ // authorization for fetching functions will come through here
49
+ if (config.authCb) {
50
+ return await config.authCb(req);
51
+ }
52
+ },
53
+ socketCb: async (socket) => { }
54
+ }).listen(port);
55
+ };
56
+ exports.runServer = runServer;
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA0E;AAC1E,sDAA8B;AAIvB,MAAM,SAAS,GAAG,CAAC,MASzB,EAAE,EAAE;IACD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IACtC,MAAM,WAAW,GAAG,GAAG,IAAI,IAAA,iBAAO,GAAE,CAAC;IAErC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAE7D,iCAAiC;IACjC,+DAA+D;IAC/D,WAAW,CAA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I,CAAC;YACL,SAAS,EAAE,cAAc;SAC5B,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,aAAG,CAAC,IAAI,CAAC;QACL,GAAG,EAAE,WAAW;QAChB,OAAO,EAAE,OAAO;QAChB,eAAe,EAAE,KAAK;QACtB,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAClB,8DAA8D;YAC9D,IAAG,MAAM,CAAC,MAAM,EAAC,CAAC;gBACd,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC;KAClC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAA;AA3DY,QAAA,SAAS,aA2DrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttc-origin-server",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A lightweight server for TTC Origins - run RPC services with decorator-based endpoints",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.ts",