@things-factory/edge 10.1.113 → 10.1.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/connect-connections.js +2 -1
- package/dist-server/controllers/connect-connections.js.map +1 -1
- package/dist-server/controllers/describe-connections.d.ts +15 -0
- package/dist-server/controllers/describe-connections.js +24 -0
- package/dist-server/controllers/describe-connections.js.map +1 -0
- package/dist-server/controllers/disconnect-connections.js +2 -1
- package/dist-server/controllers/disconnect-connections.js.map +1 -1
- package/dist-server/controllers/run-task.js +2 -1
- package/dist-server/controllers/run-task.js.map +1 -1
- package/dist-server/controllers/sync-connections.js +2 -1
- package/dist-server/controllers/sync-connections.js.map +1 -1
- package/dist-server/service/connection/connection-query.d.ts +7 -0
- package/dist-server/service/connection/connection-query.js +13 -6
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -6,6 +6,7 @@ const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
|
6
6
|
const env_1 = require("@things-factory/env");
|
|
7
7
|
const integration_base_1 = require("@things-factory/integration-base");
|
|
8
8
|
const operato_client_1 = require("./operato-client");
|
|
9
|
+
const describe_connections_1 = require("./describe-connections");
|
|
9
10
|
async function initConnectConnectionsSubscription() {
|
|
10
11
|
const client = await (0, operato_client_1.getOperatoClient)();
|
|
11
12
|
const subscription = client.subscribe({
|
|
@@ -57,7 +58,7 @@ async function initConnectConnectionsSubscription() {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
async function connectConnections(connections) {
|
|
60
|
-
env_1.logger.info(
|
|
61
|
+
env_1.logger.info(`connectConnections ... ${(0, describe_connections_1.describeConnections)(connections)}`);
|
|
61
62
|
connections.forEach(connection => connectConnection(connection));
|
|
62
63
|
}
|
|
63
64
|
async function connectConnection(connection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-connections.js","sourceRoot":"","sources":["../../server/controllers/connect-connections.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"connect-connections.js","sourceRoot":"","sources":["../../server/controllers/connect-connections.ts"],"names":[],"mappings":";;AAQA,gFAqDC;;AA7DD,sEAA6B;AAE7B,6CAA4C;AAC5C,uEAAgF;AAEhF,qDAAmD;AACnD,iEAA4D;AAErD,KAAK,UAAU,kCAAkC;IACtD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAgB,GAAE,CAAA;IAEvC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC;QACpC,KAAK,EAAE,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;KAkBT;KACF,CAAC,CAAA;IAEF,YAAY,CAAC,SAAS,CAAC;QACrB,IAAI,EAAE,KAAK,EAAC,YAAY,EAAC,EAAE;YACzB,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,EAAE,kBAAkB,IAAI,EAAE,CAAA;YAC/D,MAAM,kBAAkB,CACtB,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBAC3B,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;oBAE5C,OAAO;wBACL,GAAG,UAAU;wBACb,MAAM;qBACP,CAAA;gBACH,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO;wBACL,GAAG,UAAU;wBACb,MAAM,EAAE,IAAI;qBACb,CAAA;gBACH,CAAC;YACH,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QACD,KAAK,EAAE,KAAK,CAAC,EAAE;YACb,YAAM,CAAC,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAA;QACtD,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,YAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;QAC9C,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,WAAyB;IACzD,YAAM,CAAC,IAAI,CAAC,0BAA0B,IAAA,0CAAmB,EAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAEzE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,UAAsB;IACrD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAA;IAE3B,MAAM,GAAG,GAAG,oCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;IAC/D,IAAI,GAAG,EAAE,CAAC;QACR,oCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,SAAS,GAAG,oCAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAM;IACR,CAAC;IAED,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import gql from 'graphql-tag'\n\nimport { logger } from '@things-factory/env'\nimport { Connection, ConnectionManager } from '@things-factory/integration-base'\n\nimport { getOperatoClient } from './operato-client'\nimport { describeConnections } from './describe-connections'\n\nexport async function initConnectConnectionsSubscription() {\n const client = await getOperatoClient()\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n connectConnections {\n domain {\n id\n name\n subdomain\n }\n id\n type\n name\n description\n endpoint\n active\n state\n params\n }\n }\n `\n })\n\n subscription.subscribe({\n next: async subscription => {\n const connections = subscription.data?.connectConnections || []\n await connectConnections(\n connections.map(connection => {\n try {\n const params = JSON.parse(connection.params)\n\n return {\n ...connection,\n params\n }\n } catch (e) {\n return {\n ...connection,\n params: null\n }\n }\n })\n )\n },\n error: error => {\n logger.error(`operato subscription error: ${error}`)\n },\n complete: () => {\n logger.info(`operato subscription complete`)\n }\n })\n}\n\nasync function connectConnections(connections: Connection[]) {\n logger.info(`connectConnections ... ${describeConnections(connections)}`)\n\n connections.forEach(connection => connectConnection(connection))\n}\n\nasync function connectConnection(connection: Connection) {\n const { type } = connection\n\n const old = ConnectionManager.getConnectionInstance(connection)\n if (old) {\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n const connector = ConnectionManager.getConnector(type)\n if (!connector) {\n return\n }\n\n await connector.connect(connection)\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Connection, Step } from '@things-factory/integration-base';
|
|
2
|
+
/**
|
|
3
|
+
* What the edge logs about the connections the host sends it: names and types, never `params`.
|
|
4
|
+
*
|
|
5
|
+
* The host hands the edge its connections with the secrets resolved - the edge has to connect with
|
|
6
|
+
* them - so logging the objects wrote passwords and tokens into the edge's log files (ADR-0112).
|
|
7
|
+
*/
|
|
8
|
+
export declare function describeConnections(connections: Connection[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* What the edge logs about a task the host sends it to run: the request, the task and the connection.
|
|
11
|
+
*
|
|
12
|
+
* The step carries its params and the context carries the scenario's data - a request header with a
|
|
13
|
+
* token among them - so logging the objects wrote them into the edge's log files (ADR-0112).
|
|
14
|
+
*/
|
|
15
|
+
export declare function describeRunTask(id: string, step: Partial<Step> | null | undefined, context: any): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeConnections = describeConnections;
|
|
4
|
+
exports.describeRunTask = describeRunTask;
|
|
5
|
+
/**
|
|
6
|
+
* What the edge logs about the connections the host sends it: names and types, never `params`.
|
|
7
|
+
*
|
|
8
|
+
* The host hands the edge its connections with the secrets resolved - the edge has to connect with
|
|
9
|
+
* them - so logging the objects wrote passwords and tokens into the edge's log files (ADR-0112).
|
|
10
|
+
*/
|
|
11
|
+
function describeConnections(connections) {
|
|
12
|
+
return (connections || []).map(connection => `${connection?.name}(${connection?.type})`).join(', ');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What the edge logs about a task the host sends it to run: the request, the task and the connection.
|
|
16
|
+
*
|
|
17
|
+
* The step carries its params and the context carries the scenario's data - a request header with a
|
|
18
|
+
* token among them - so logging the objects wrote them into the edge's log files (ADR-0112).
|
|
19
|
+
*/
|
|
20
|
+
function describeRunTask(id, step, context) {
|
|
21
|
+
const domain = context?.domain?.subdomain || context?.domain?.name || '';
|
|
22
|
+
return `${id} ${step?.task}(${step?.connection || ''})${domain ? ` domain=${domain}` : ''}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=describe-connections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe-connections.js","sourceRoot":"","sources":["../../server/controllers/describe-connections.ts"],"names":[],"mappings":";;AAQA,kDAEC;AAQD,0CAGC;AAnBD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,WAAyB;IAC3D,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,IAAI,IAAI,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACrG,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,EAAU,EAAE,IAAsC,EAAE,OAAY;IAC9F,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,EAAE,IAAI,IAAI,EAAE,CAAA;IACxE,OAAO,GAAG,EAAE,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,UAAU,IAAI,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;AAC7F,CAAC","sourcesContent":["import type { Connection, Step } from '@things-factory/integration-base'\n\n/**\n * What the edge logs about the connections the host sends it: names and types, never `params`.\n *\n * The host hands the edge its connections with the secrets resolved - the edge has to connect with\n * them - so logging the objects wrote passwords and tokens into the edge's log files (ADR-0112).\n */\nexport function describeConnections(connections: Connection[]): string {\n return (connections || []).map(connection => `${connection?.name}(${connection?.type})`).join(', ')\n}\n\n/**\n * What the edge logs about a task the host sends it to run: the request, the task and the connection.\n *\n * The step carries its params and the context carries the scenario's data - a request header with a\n * token among them - so logging the objects wrote them into the edge's log files (ADR-0112).\n */\nexport function describeRunTask(id: string, step: Partial<Step> | null | undefined, context: any): string {\n const domain = context?.domain?.subdomain || context?.domain?.name || ''\n return `${id} ${step?.task}(${step?.connection || ''})${domain ? ` domain=${domain}` : ''}`\n}\n"]}
|
|
@@ -6,6 +6,7 @@ const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
|
6
6
|
const env_1 = require("@things-factory/env");
|
|
7
7
|
const integration_base_1 = require("@things-factory/integration-base");
|
|
8
8
|
const operato_client_1 = require("./operato-client");
|
|
9
|
+
const describe_connections_1 = require("./describe-connections");
|
|
9
10
|
async function initDisconnectConnectionsSubscription() {
|
|
10
11
|
const client = await (0, operato_client_1.getOperatoClient)();
|
|
11
12
|
const subscription = client.subscribe({
|
|
@@ -57,7 +58,7 @@ async function initDisconnectConnectionsSubscription() {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
async function disconnectConnections(connections) {
|
|
60
|
-
env_1.logger.info(
|
|
61
|
+
env_1.logger.info(`disconnectConnections ... ${(0, describe_connections_1.describeConnections)(connections)}`);
|
|
61
62
|
connections.forEach(connection => disconnectConnection(connection));
|
|
62
63
|
}
|
|
63
64
|
async function disconnectConnection(connection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnect-connections.js","sourceRoot":"","sources":["../../server/controllers/disconnect-connections.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"disconnect-connections.js","sourceRoot":"","sources":["../../server/controllers/disconnect-connections.ts"],"names":[],"mappings":";;AAQA,sFAqDC;;AA7DD,sEAA6B;AAE7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AC,UAAU,CAAC,CAAC,CAAA;AACrE,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,UAAsB;IACxD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAA;IAE3B,MAAM,GAAG,GAAG,oCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;IAC/D,IAAI,GAAG,EAAE,CAAC;QACR,oCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;AACH,CAAC","sourcesContent":["import gql from 'graphql-tag'\n\nimport { logger } from '@things-factory/env'\nimport { Connection, ConnectionManager } from '@things-factory/integration-base'\n\nimport { getOperatoClient } from './operato-client'\nimport { describeConnections } from './describe-connections'\n\nexport async function initDisconnectConnectionsSubscription() {\n const client = await getOperatoClient()\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n disconnectConnections {\n domain {\n id\n name\n subdomain\n }\n id\n type\n name\n description\n endpoint\n active\n state\n params\n }\n }\n `\n })\n\n subscription.subscribe({\n next: async subscription => {\n const connections = subscription.data?.disconnectConnections || []\n await disconnectConnections(\n connections.map(connection => {\n try {\n const params = JSON.parse(connection.params)\n\n return {\n ...connection,\n params\n }\n } catch (e) {\n return {\n ...connection,\n params: null\n }\n }\n })\n )\n },\n error: error => {\n logger.error(`operato subscription error: ${error}`)\n },\n complete: () => {\n logger.info(`operato subscription complete`)\n }\n })\n}\n\nasync function disconnectConnections(connections: Connection[]) {\n logger.info(`disconnectConnections ... ${describeConnections(connections)}`)\n\n connections.forEach(connection => disconnectConnection(connection))\n}\n\nasync function disconnectConnection(connection: Connection) {\n const { type } = connection\n\n const old = ConnectionManager.getConnectionInstance(connection)\n if (old) {\n ConnectionManager.removeConnectionInstance(connection)\n }\n}\n"]}
|
|
@@ -8,6 +8,7 @@ const env_1 = require("@things-factory/env");
|
|
|
8
8
|
const integration_base_1 = require("@things-factory/integration-base/");
|
|
9
9
|
const operato_client_1 = require("./operato-client");
|
|
10
10
|
const log_aggregator_1 = require("./log-aggregator");
|
|
11
|
+
const describe_connections_1 = require("./describe-connections");
|
|
11
12
|
async function initRunTaskSubscription() {
|
|
12
13
|
const client = await (0, operato_client_1.getOperatoClient)();
|
|
13
14
|
const subscription = client.subscribe({
|
|
@@ -37,7 +38,7 @@ async function initRunTaskSubscription() {
|
|
|
37
38
|
subscription.subscribe({
|
|
38
39
|
next: async (subscription) => {
|
|
39
40
|
const { id, step, context } = subscription?.data?.runTask || {};
|
|
40
|
-
env_1.logger.info(`received run-task request:
|
|
41
|
+
env_1.logger.info(`received run-task request: ${(0, describe_connections_1.describeRunTask)(id, step, context)}`);
|
|
41
42
|
await runTask(id, step, context);
|
|
42
43
|
},
|
|
43
44
|
error: error => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-task.js","sourceRoot":"","sources":["../../server/controllers/run-task.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"run-task.js","sourceRoot":"","sources":["../../server/controllers/run-task.ts"],"names":[],"mappings":";;AAWA,0DAyCC;;AApDD,sEAA6B;AAE7B,qCAA8C;AAE9C,6CAA4C;AAC5C,wEAA+E;AAE/E,qDAAmD;AACnD,qDAAgD;AAChD,iEAAwD;AAEjD,KAAK,UAAU,uBAAuB;IAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAgB,GAAE,CAAA;IAEvC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC;QACpC,KAAK,EAAE,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;KAqBT;KACF,CAAC,CAAA;IAEF,YAAY,CAAC,SAAS,CAAC;QACrB,IAAI,EAAE,KAAK,EAAC,YAAY,EAAC,EAAE;YACzB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAiD,YAAY,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE,CAAA;YAC7G,YAAM,CAAC,IAAI,CAAC,8BAA8B,IAAA,sCAAe,EAAC,EAAE,EAAE,IAAI,E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AAI,CAAC,MAAM,IAAI,EAAE;SAC1B,EACD;YACE,GAAG,OAAO;YACV,MAAM,EAAE,UAAU;SACnB,CACF,CAAA;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAgB,GAAE,CAAA;IAEvC,MAAM,MAAM,CAAC,MAAM,CAAC;QAClB,QAAQ,EAAE,IAAA,qBAAG,EAAA;;;;KAIZ;QACD,SAAS,EAAE;YACT,MAAM,EAAE;gBACN,EAAE;gBACF,GAAG;gBACH,IAAI,EAAE,aAAa,CAAC,aAAa,EAAE;gBACnC,KAAK;aACN;SACF;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import gql from 'graphql-tag'\n\nimport { createLogger, format } from 'winston'\n\nimport { logger } from '@things-factory/env'\nimport { Step, Context, TaskRegistry } from '@things-factory/integration-base/'\n\nimport { getOperatoClient } from './operato-client'\nimport { LogAggregator } from './log-aggregator'\nimport { describeRunTask } from './describe-connections'\n\nexport async function initRunTaskSubscription() {\n const client = await getOperatoClient()\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n runTask {\n id\n step {\n task\n connection\n params\n }\n context {\n domain {\n id\n name\n subdomain\n }\n data\n variables\n lng\n }\n }\n }\n `\n })\n\n subscription.subscribe({\n next: async subscription => {\n const { id, step, context }: { id: string; step: Step; context: Context } = subscription?.data?.runTask || {}\n logger.info(`received run-task request: ${describeRunTask(id, step, context)}`)\n await runTask(id, step, context)\n },\n error: error => {\n logger.error(`operato subscription for runTask error: ${error}`)\n },\n complete: () => {\n logger.info(`operato subscription for runTask complete`)\n }\n })\n}\n\nasync function runTask(id: string, step: Step, context: Context) {\n const handler = step.task ? TaskRegistry.getTaskHandler(step.task) : null\n if (!handler) {\n throw new Error(`no task handler for step '${step.name}'(${step.id})`)\n }\n\n let error\n let out: any\n\n const logAggregator = new LogAggregator({})\n\n const taskLogger = createLogger({\n format: format.combine(\n format.timestamp(),\n format.printf(({ timestamp, level, message, stack }) => `${timestamp} ${level}: ${stack || message}`)\n ),\n transports: [logAggregator]\n })\n\n try {\n out = await handler(\n {\n ...step,\n params: step.params || {}\n },\n {\n ...context,\n logger: taskLogger\n }\n )\n } catch (e: any) {\n error = e?.stack || e\n }\n\n const client = await getOperatoClient()\n\n await client.mutate({\n mutation: gql`\n mutation RunTaskCallback($result: RunTaskCallbackInput!) {\n runTaskCallback(result: $result)\n }\n `,\n variables: {\n result: {\n id,\n out,\n logs: logAggregator.formatResults(),\n error\n }\n }\n })\n}\n"]}
|
|
@@ -6,6 +6,7 @@ const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
|
6
6
|
const env_1 = require("@things-factory/env");
|
|
7
7
|
const integration_base_1 = require("@things-factory/integration-base");
|
|
8
8
|
const operato_client_1 = require("./operato-client");
|
|
9
|
+
const describe_connections_1 = require("./describe-connections");
|
|
9
10
|
async function initSyncConnectionsSubscription() {
|
|
10
11
|
const client = await (0, operato_client_1.getOperatoClient)();
|
|
11
12
|
const subscription = client.subscribe({
|
|
@@ -59,7 +60,7 @@ async function initSyncConnectionsSubscription() {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
async function syncConnections(connections) {
|
|
62
|
-
env_1.logger.info(
|
|
63
|
+
env_1.logger.info(`syncConnections ... ${(0, describe_connections_1.describeConnections)(connections)}`);
|
|
63
64
|
if (connections.length === 0) {
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-connections.js","sourceRoot":"","sources":["../../server/controllers/sync-connections.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sync-connections.js","sourceRoot":"","sources":["../../server/controllers/sync-connections.ts"],"names":[],"mappings":";;AAQA,0EAuDC;;AA/DD,sEAA6B;AAE7B,6CAA4C;AAC5C,uEAAgF;AAEhF,qDAAm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,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAA;IACrC,MAAM,cAAc,GAAG,oCAAiB,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAA;IACvE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,oCAAiB,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAA;IAE7F,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAA;AAC/D,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,UAAsB;IAClD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,CAAA;IAElC,MAAM,SAAS,GAAG,oCAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAM;IACR,CAAC;IAED,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import gql from 'graphql-tag'\n\nimport { logger } from '@things-factory/env'\nimport { Connection, ConnectionManager } from '@things-factory/integration-base'\n\nimport { getOperatoClient } from './operato-client'\nimport { describeConnections } from './describe-connections'\n\nexport async function initSyncConnectionsSubscription() {\n const client = await getOperatoClient()\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n syncConnections {\n domain {\n id\n name\n subdomain\n }\n id\n type\n name\n description\n endpoint\n active\n state\n params\n }\n }\n `\n })\n\n subscription.subscribe({\n next: async subscription => {\n const connections = subscription.data?.syncConnections || []\n await syncConnections(\n connections.map(connection => {\n try {\n const params = JSON.parse(connection.params)\n\n return {\n // domain,\n ...connection,\n params\n }\n } catch (e) {\n return {\n // domain,\n ...connection,\n params: null\n }\n }\n })\n )\n },\n error: error => {\n logger.error(`operato subscription error: ${error}`)\n },\n complete: () => {\n logger.info(`operato subscription complete`)\n }\n })\n}\n\nasync function syncConnections(connections: Connection[]) {\n logger.info(`syncConnections ... ${describeConnections(connections)}`)\n\n if (connections.length === 0) {\n return\n }\n\n const domain = connections[0]?.domain\n const oldConnections = ConnectionManager.getConnectionInstances(domain)\n Object.values(oldConnections).forEach(old => ConnectionManager.removeConnectionInstance(old))\n\n connections.forEach(connection => syncConnection(connection))\n}\n\nasync function syncConnection(connection: Connection) {\n const { type, state } = connection\n\n const connector = ConnectionManager.getConnector(type)\n if (!connector) {\n return\n }\n\n await connector.connect(connection)\n}\n"]}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Connection } from '@things-factory/integration-base';
|
|
2
2
|
export declare class ConnectionQuery {
|
|
3
|
+
/**
|
|
4
|
+
* The connections this process holds for the request's domain.
|
|
5
|
+
*
|
|
6
|
+
* It used to carry no `@privilege` and return every domain's connections, `params` included -
|
|
7
|
+
* anyone signed in could read another tenant's connections (ADR-0112). It now asks the same
|
|
8
|
+
* privilege as `connections` and answers for the current domain only.
|
|
9
|
+
*/
|
|
3
10
|
connectionsOnEdge(context: ResolverContext): Promise<Connection[]>;
|
|
4
11
|
}
|
|
@@ -5,18 +5,25 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const integration_base_1 = require("@things-factory/integration-base");
|
|
7
7
|
let ConnectionQuery = class ConnectionQuery {
|
|
8
|
+
/**
|
|
9
|
+
* The connections this process holds for the request's domain.
|
|
10
|
+
*
|
|
11
|
+
* It used to carry no `@privilege` and return every domain's connections, `params` included -
|
|
12
|
+
* anyone signed in could read another tenant's connections (ADR-0112). It now asks the same
|
|
13
|
+
* privilege as `connections` and answers for the current domain only.
|
|
14
|
+
*/
|
|
8
15
|
async connectionsOnEdge(context) {
|
|
16
|
+
const { domain } = context.state;
|
|
17
|
+
if (!domain) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
9
20
|
const entities = integration_base_1.ConnectionManager.getEntities();
|
|
10
|
-
|
|
11
|
-
const items = Object.values(keyval);
|
|
12
|
-
sum.push(...items);
|
|
13
|
-
return sum;
|
|
14
|
-
}, []);
|
|
15
|
-
return connections;
|
|
21
|
+
return Object.values(entities[domain.id] || {});
|
|
16
22
|
}
|
|
17
23
|
};
|
|
18
24
|
exports.ConnectionQuery = ConnectionQuery;
|
|
19
25
|
tslib_1.__decorate([
|
|
26
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
|
20
27
|
(0, type_graphql_1.Query)(returns => [integration_base_1.Connection], { description: 'To fetch multiple connections' }),
|
|
21
28
|
tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
|
|
22
29
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8D;AAE9D,uEAAgF;AAGzE,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B;;;;;;OAMG;IAGG,AAAN,KAAK,CAAC,iBAAiB,CAAQ,OAAwB;QACrD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,QAAQ,GAA2D,oCAAiB,CAAC,WAAW,EAAE,CAAA;QAExG,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;IACjD,CAAC;CACF,CAAA;AApBY,0CAAe;AAUpB;IAFL,IAAA,wBAAS,EAAC,0GAA0G,CAAC;IACrH,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC,6BAAU,CAAC,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IACxD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;wDAS7B;0BAnBU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,6BAAU,CAAC;GACR,eAAe,CAoB3B","sourcesContent":["import { Ctx, Directive, Query, Resolver } from 'type-graphql'\n\nimport { ConnectionManager, Connection } from '@things-factory/integration-base'\n\n@Resolver(Connection)\nexport class ConnectionQuery {\n /**\n * The connections this process holds for the request's domain.\n *\n * It used to carry no `@privilege` and return every domain's connections, `params` included -\n * anyone signed in could read another tenant's connections (ADR-0112). It now asks the same\n * privilege as `connections` and answers for the current domain only.\n */\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => [Connection], { description: 'To fetch multiple connections' })\n async connectionsOnEdge(@Ctx() context: ResolverContext): Promise<Connection[]> {\n const { domain } = context.state\n if (!domain) {\n return []\n }\n\n const entities: { [domainId: string]: { [name: string]: Connection } } = ConnectionManager.getEntities()\n\n return Object.values(entities[domain.id] || {})\n }\n}\n"]}
|