@things-factory/edge 9.0.0-beta.25 → 9.0.0-beta.27
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/package.json +3 -3
- package/dist-client/bootstrap.d.ts +0 -1
- package/dist-client/bootstrap.js +0 -2
- package/dist-client/bootstrap.js.map +0 -1
- package/dist-client/index.d.ts +0 -0
- package/dist-client/index.js +0 -2
- package/dist-client/index.js.map +0 -1
- package/dist-client/pages/edge-status-page.d.ts +0 -39
- package/dist-client/pages/edge-status-page.js +0 -182
- package/dist-client/pages/edge-status-page.js.map +0 -1
- package/dist-client/route.d.ts +0 -1
- package/dist-client/route.js +0 -8
- package/dist-client/route.js.map +0 -1
- package/dist-client/tsconfig.tsbuildinfo +0 -1
- package/dist-server/controllers/connect-connections.d.ts +0 -1
- package/dist-server/controllers/connect-connections.js +0 -70
- package/dist-server/controllers/connect-connections.js.map +0 -1
- package/dist-server/controllers/disconnect-connections.d.ts +0 -1
- package/dist-server/controllers/disconnect-connections.js +0 -65
- package/dist-server/controllers/disconnect-connections.js.map +0 -1
- package/dist-server/controllers/log-aggregator.d.ts +0 -6
- package/dist-server/controllers/log-aggregator.js +0 -20
- package/dist-server/controllers/log-aggregator.js.map +0 -1
- package/dist-server/controllers/operato-client.d.ts +0 -2
- package/dist-server/controllers/operato-client.js +0 -88
- package/dist-server/controllers/operato-client.js.map +0 -1
- package/dist-server/controllers/run-task.d.ts +0 -1
- package/dist-server/controllers/run-task.js +0 -86
- package/dist-server/controllers/run-task.js.map +0 -1
- package/dist-server/controllers/sync-connections.d.ts +0 -1
- package/dist-server/controllers/sync-connections.js +0 -73
- package/dist-server/controllers/sync-connections.js.map +0 -1
- package/dist-server/index.d.ts +0 -1
- package/dist-server/index.js +0 -20
- package/dist-server/index.js.map +0 -1
- package/dist-server/service/connection/connection-query.d.ts +0 -4
- package/dist-server/service/connection/connection-query.js +0 -29
- package/dist-server/service/connection/connection-query.js.map +0 -1
- package/dist-server/service/connection/index.d.ts +0 -2
- package/dist-server/service/connection/index.js +0 -6
- package/dist-server/service/connection/index.js.map +0 -1
- package/dist-server/service/index.d.ts +0 -5
- package/dist-server/service/index.js +0 -19
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOperatoClient = getOperatoClient;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
require("cross-fetch/polyfill");
|
|
6
|
-
const core_1 = require("@apollo/client/core");
|
|
7
|
-
const context_1 = require("@apollo/client/link/context");
|
|
8
|
-
const ws_1 = tslib_1.__importDefault(require("ws"));
|
|
9
|
-
const graphql_ws_1 = require("graphql-ws");
|
|
10
|
-
const subscriptions_1 = require("@apollo/client/link/subscriptions");
|
|
11
|
-
const utilities_1 = require("@apollo/client/utilities");
|
|
12
|
-
const shell_1 = require("@things-factory/shell");
|
|
13
|
-
const auth_base_1 = require("@things-factory/auth-base");
|
|
14
|
-
const env_1 = require("@things-factory/env");
|
|
15
|
-
const OperatoConfig = env_1.config.get('operato', {});
|
|
16
|
-
const { endpoint: uri, domain: subdomain, authKey } = OperatoConfig;
|
|
17
|
-
const defaultOptions = {
|
|
18
|
-
watchQuery: {
|
|
19
|
-
fetchPolicy: 'no-cache',
|
|
20
|
-
errorPolicy: 'ignore'
|
|
21
|
-
},
|
|
22
|
-
query: {
|
|
23
|
-
fetchPolicy: 'no-cache', //'network-only'
|
|
24
|
-
errorPolicy: 'all'
|
|
25
|
-
},
|
|
26
|
-
mutate: {
|
|
27
|
-
errorPolicy: 'all'
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var client;
|
|
31
|
-
async function getOperatoClient() {
|
|
32
|
-
if (!client) {
|
|
33
|
-
if (!authKey || !subdomain) {
|
|
34
|
-
throw new Error('some operato config missing.');
|
|
35
|
-
}
|
|
36
|
-
const domain = await (0, shell_1.getRepository)(shell_1.Domain).findOne({
|
|
37
|
-
where: {
|
|
38
|
-
subdomain: 'system'
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const user = await (0, shell_1.getRepository)(auth_base_1.User).findOne({
|
|
42
|
-
where: {
|
|
43
|
-
id: domain.owner
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const httpLink = (0, core_1.createHttpLink)({
|
|
47
|
-
uri: uri
|
|
48
|
-
});
|
|
49
|
-
/*
|
|
50
|
-
CHECKPOINT:
|
|
51
|
-
1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.
|
|
52
|
-
따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.
|
|
53
|
-
|
|
54
|
-
2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.
|
|
55
|
-
*/
|
|
56
|
-
const wsLink = new subscriptions_1.GraphQLWsLink((0, graphql_ws_1.createClient)({
|
|
57
|
-
url: uri.replace(/^http/, 'ws'),
|
|
58
|
-
keepAlive: 10000,
|
|
59
|
-
retryAttempts: 1000000,
|
|
60
|
-
shouldRetry: e => true,
|
|
61
|
-
webSocketImpl: ws_1.default,
|
|
62
|
-
connectionParams: {
|
|
63
|
-
headers: {
|
|
64
|
-
'x-things-factory-domain': subdomain,
|
|
65
|
-
authorization: authKey ? `Bearer ${authKey}` : ''
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}));
|
|
69
|
-
const splitLink = (0, core_1.split)(({ query }) => {
|
|
70
|
-
const def = (0, utilities_1.getMainDefinition)(query);
|
|
71
|
-
return def.kind === 'OperationDefinition' && def.operation === 'subscription';
|
|
72
|
-
}, wsLink, (0, context_1.setContext)((_, { headers }) => {
|
|
73
|
-
return {
|
|
74
|
-
headers: Object.assign(Object.assign({}, headers), { 'x-things-factory-domain': subdomain, authorization: authKey ? `Bearer ${authKey}` : '' })
|
|
75
|
-
};
|
|
76
|
-
}).concat(httpLink));
|
|
77
|
-
const cache = new core_1.InMemoryCache({
|
|
78
|
-
addTypename: false
|
|
79
|
-
});
|
|
80
|
-
client = new core_1.ApolloClient({
|
|
81
|
-
defaultOptions,
|
|
82
|
-
cache,
|
|
83
|
-
link: splitLink
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return client;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=operato-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operato-client.js","sourceRoot":"","sources":["../../server/controllers/operato-client.ts"],"names":[],"mappings":";;AAiCA,4CA0EC;;AA3GD,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAE5D,iDAA6D;AAC7D,yDAAgD;AAChD,6CAA4C;AAE5C,MAAM,aAAa,GAAG,YAAM,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,aAAa,CAAA;AAEnE,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU,EAAE,gBAAgB;QACzC,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,IAAI,MAAM,CAAA;AAEH,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QACjD,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAa,EAAC,cAAM,CAAC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,CAAC,CAAC,EAAE,GAClD;aACF,CAAA;QACH,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CACpB,CAAA;QAED,MAAM,KAAK,GAAG,IAAI,oBAAa,CAAC;YAC9B,WAAW,EAAE,KAAK;SACnB,CAAC,CAAA;QAEF,MAAM,GAAG,IAAI,mBAAY,CAAC;YACxB,cAAc;YACd,KAAK;YACL,IAAI,EAAE,SAAS;SAChB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import 'cross-fetch/polyfill'\n\nimport { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'\nimport { setContext } from '@apollo/client/link/context'\n\nimport WebSocket from 'ws'\nimport { createClient } from 'graphql-ws'\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions'\nimport { getMainDefinition } from '@apollo/client/utilities'\n\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { config } from '@things-factory/env'\n\nconst OperatoConfig = config.get('operato', {})\nconst { endpoint: uri, domain: subdomain, authKey } = OperatoConfig\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nvar client\n\nexport async function getOperatoClient() {\n if (!client) {\n if (!authKey || !subdomain) {\n throw new Error('some operato config missing.')\n }\n\n const domain = await getRepository(Domain).findOne({\n where: {\n subdomain: 'system'\n }\n })\n\n const user = await getRepository(User).findOne({\n where: {\n id: domain.owner\n }\n })\n\n const httpLink = createHttpLink({\n uri: uri\n })\n\n /* \n CHECKPOINT: \n 1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.\n 따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.\n \n 2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.\n */\n const wsLink = new GraphQLWsLink(\n createClient({\n url: uri.replace(/^http/, 'ws'),\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n webSocketImpl: WebSocket,\n connectionParams: {\n headers: {\n 'x-things-factory-domain': subdomain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n })\n )\n\n const splitLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n setContext((_, { headers }) => {\n return {\n headers: {\n ...headers,\n 'x-things-factory-domain': subdomain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n }\n\n return client\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function initRunTaskSubscription(): Promise<void>;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initRunTaskSubscription = initRunTaskSubscription;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
-
const winston_1 = require("winston");
|
|
7
|
-
const env_1 = require("@things-factory/env");
|
|
8
|
-
const integration_base_1 = require("@things-factory/integration-base/");
|
|
9
|
-
const operato_client_1 = require("./operato-client");
|
|
10
|
-
const log_aggregator_1 = require("./log-aggregator");
|
|
11
|
-
async function initRunTaskSubscription() {
|
|
12
|
-
const client = await (0, operato_client_1.getOperatoClient)();
|
|
13
|
-
const subscription = client.subscribe({
|
|
14
|
-
query: (0, graphql_tag_1.default) `
|
|
15
|
-
subscription {
|
|
16
|
-
runTask {
|
|
17
|
-
id
|
|
18
|
-
step {
|
|
19
|
-
task
|
|
20
|
-
connection
|
|
21
|
-
params
|
|
22
|
-
}
|
|
23
|
-
context {
|
|
24
|
-
domain {
|
|
25
|
-
id
|
|
26
|
-
name
|
|
27
|
-
subdomain
|
|
28
|
-
}
|
|
29
|
-
data
|
|
30
|
-
variables
|
|
31
|
-
lng
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
`
|
|
36
|
-
});
|
|
37
|
-
subscription.subscribe({
|
|
38
|
-
next: async (subscription) => {
|
|
39
|
-
var _a;
|
|
40
|
-
const { id, step, context } = ((_a = subscription === null || subscription === void 0 ? void 0 : subscription.data) === null || _a === void 0 ? void 0 : _a.runTask) || {};
|
|
41
|
-
env_1.logger.info(`received run-task request: %s, %s, %s`, id, step, context);
|
|
42
|
-
await runTask(id, step, context);
|
|
43
|
-
},
|
|
44
|
-
error: error => {
|
|
45
|
-
env_1.logger.error(`operato subscription for runTask error: ${error}`);
|
|
46
|
-
},
|
|
47
|
-
complete: () => {
|
|
48
|
-
env_1.logger.info(`operato subscription for runTask complete`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async function runTask(id, step, context) {
|
|
53
|
-
var handler = integration_base_1.TaskRegistry.getTaskHandler(step.task);
|
|
54
|
-
if (!handler) {
|
|
55
|
-
throw new Error(`no task handler for step '${step.name}'(${step.id})`);
|
|
56
|
-
}
|
|
57
|
-
var error;
|
|
58
|
-
const logAggregator = new log_aggregator_1.LogAggregator({});
|
|
59
|
-
const logger = (0, winston_1.createLogger)({
|
|
60
|
-
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message, stack }) => `${timestamp} ${level}: ${stack || message}`)),
|
|
61
|
-
transports: [logAggregator]
|
|
62
|
-
});
|
|
63
|
-
try {
|
|
64
|
-
var out = await handler(Object.assign(Object.assign({}, step), { params: JSON.parse(step.params) }), Object.assign(Object.assign({}, context), { logger }));
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
error = (e === null || e === void 0 ? void 0 : e.stack) || e;
|
|
68
|
-
}
|
|
69
|
-
const client = await (0, operato_client_1.getOperatoClient)();
|
|
70
|
-
await client.mutate({
|
|
71
|
-
mutation: (0, graphql_tag_1.default) `
|
|
72
|
-
mutation RunTaskCallback($result: RunTaskCallbackInput!) {
|
|
73
|
-
runTaskCallback(result: $result)
|
|
74
|
-
}
|
|
75
|
-
`,
|
|
76
|
-
variables: {
|
|
77
|
-
result: {
|
|
78
|
-
id,
|
|
79
|
-
out,
|
|
80
|
-
logs: logAggregator.formatResults(),
|
|
81
|
-
error
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=run-task.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-task.js","sourceRoot":"","sources":["../../server/controllers/run-task.ts"],"names":[],"mappings":";;AAUA,0DAyCC;;AAnDD,sEAA6B;AAE7B,qCAA8C;AAE9C,6CAA4C;AAC5C,wEAA+E;AAE/E,qDAAmD;AACnD,qDAAgD;AAEzC,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,CAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,0CAAE,OAAO,KAAI,EAAE,CAAA;YAC7G,YAAM,CAAC,IAAI,CAAC,uCAAuC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;YACvE,MAAM,OAAO,CAAC,EAAE,EAAE,IAA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uBAAD,CAAC,CAAE,KAAK,KAAI,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'\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: %s, %s, %s`, 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 var handler = TaskRegistry.getTaskHandler(step.task)\n if (!handler) {\n throw new Error(`no task handler for step '${step.name}'(${step.id})`)\n }\n\n var error\n\n const logAggregator = new LogAggregator({})\n\n const logger = 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 var out: any = await handler(\n {\n ...step,\n params: JSON.parse(step.params)\n },\n {\n ...context,\n logger\n }\n )\n } catch (e) {\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function initSyncConnectionsSubscription(): Promise<void>;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initSyncConnectionsSubscription = initSyncConnectionsSubscription;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
-
const env_1 = require("@things-factory/env");
|
|
7
|
-
const integration_base_1 = require("@things-factory/integration-base");
|
|
8
|
-
const operato_client_1 = require("./operato-client");
|
|
9
|
-
async function initSyncConnectionsSubscription() {
|
|
10
|
-
const client = await (0, operato_client_1.getOperatoClient)();
|
|
11
|
-
const subscription = client.subscribe({
|
|
12
|
-
query: (0, graphql_tag_1.default) `
|
|
13
|
-
subscription {
|
|
14
|
-
syncConnections {
|
|
15
|
-
domain {
|
|
16
|
-
id
|
|
17
|
-
name
|
|
18
|
-
subdomain
|
|
19
|
-
}
|
|
20
|
-
id
|
|
21
|
-
type
|
|
22
|
-
name
|
|
23
|
-
description
|
|
24
|
-
endpoint
|
|
25
|
-
active
|
|
26
|
-
state
|
|
27
|
-
params
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
`
|
|
31
|
-
});
|
|
32
|
-
subscription.subscribe({
|
|
33
|
-
next: async (subscription) => {
|
|
34
|
-
var _a;
|
|
35
|
-
const connections = ((_a = subscription.data) === null || _a === void 0 ? void 0 : _a.syncConnections) || [];
|
|
36
|
-
await syncConnections(connections.map(connection => {
|
|
37
|
-
try {
|
|
38
|
-
const params = JSON.parse(connection.params);
|
|
39
|
-
return Object.assign(Object.assign({}, connection), { params });
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
return Object.assign(Object.assign({}, connection), { params: null });
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
},
|
|
46
|
-
error: error => {
|
|
47
|
-
env_1.logger.error(`operato subscription error: ${error}`);
|
|
48
|
-
},
|
|
49
|
-
complete: () => {
|
|
50
|
-
env_1.logger.info(`operato subscription complete`);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
async function syncConnections(connections) {
|
|
55
|
-
var _a;
|
|
56
|
-
console.log('syncConnections ...', connections);
|
|
57
|
-
if (connections.length == 0) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const domain = (_a = connections[0]) === null || _a === void 0 ? void 0 : _a.domain;
|
|
61
|
-
const oldConnections = integration_base_1.ConnectionManager.getConnectionInstances(domain);
|
|
62
|
-
Object.values(oldConnections).forEach(old => integration_base_1.ConnectionManager.removeConnectionInstance(old));
|
|
63
|
-
connections.forEach(connection => syncConnection(connection));
|
|
64
|
-
}
|
|
65
|
-
async function syncConnection(connection) {
|
|
66
|
-
const { type, state } = connection;
|
|
67
|
-
var connector = integration_base_1.ConnectionManager.getConnector(type);
|
|
68
|
-
if (!connector) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
await connector.connect(connection);
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=sync-connections.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-connections.js","sourceRoot":"","sources":["../../server/controllers/sync-connections.ts"],"names":[],"mappings":";;AAQA,0EAuDC;;AA/DD,sEAA6B;AAE7B,6CAA4C;AAC5C,uEAAkG;AAElG,qDAAmD;AAG5C,KAAK,UAAU,+BAA+B;IACnD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAgB,GAAE,CAAA;IAEvC,MAAM,YAAY,GAAG,MAA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AC,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,IAAI,SAAS,GAAG,oCAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACpD,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, ConnectionStatus } from '@things-factory/integration-base'\n\nimport { getOperatoClient } from './operato-client'\nimport { LogAggregator } from './log-aggregator'\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 console.log('syncConnections ...', 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 var connector = ConnectionManager.getConnector(type)\n if (!connector) {\n return\n }\n\n await connector.connect(connection)\n}\n"]}
|
package/dist-server/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './service';
|
package/dist-server/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./service"), exports);
|
|
5
|
-
const sync_connections_1 = require("./controllers/sync-connections");
|
|
6
|
-
const connect_connections_1 = require("./controllers/connect-connections");
|
|
7
|
-
const disconnect_connections_1 = require("./controllers/disconnect-connections");
|
|
8
|
-
const run_task_1 = require("./controllers/run-task");
|
|
9
|
-
process.on('bootstrap-module-start', async ({ app, config, client }) => {
|
|
10
|
-
try {
|
|
11
|
-
await (0, sync_connections_1.initSyncConnectionsSubscription)();
|
|
12
|
-
await (0, disconnect_connections_1.initDisconnectConnectionsSubscription)();
|
|
13
|
-
await (0, connect_connections_1.initConnectConnectionsSubscription)();
|
|
14
|
-
await (0, run_task_1.initRunTaskSubscription)();
|
|
15
|
-
}
|
|
16
|
-
catch (ex) {
|
|
17
|
-
console.error('Just has failed to initialize Edge Server.', ex);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/dist-server/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AAEzB,qEAAgF;AAChF,2EAAsF;AACtF,iFAA4F;AAC5F,qDAAgE;AAEhE,OAAO,CAAC,EAAE,CAAC,wBAA+B,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE;IACjF,IAAI,CAAC;QACH,MAAM,IAAA,kDAA+B,GAAE,CAAA;QACvC,MAAM,IAAA,8DAAqC,GAAE,CAAA;QAC7C,MAAM,IAAA,wDAAkC,GAAE,CAAA;QAC1C,MAAM,IAAA,kCAAuB,GAAE,CAAA;IACjC,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,EAAE,CAAC,CAAA;IACjE,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["export * from './service'\n\nimport { initSyncConnectionsSubscription } from './controllers/sync-connections'\nimport { initConnectConnectionsSubscription } from './controllers/connect-connections'\nimport { initDisconnectConnectionsSubscription } from './controllers/disconnect-connections'\nimport { initRunTaskSubscription } from './controllers/run-task'\n\nprocess.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {\n try {\n await initSyncConnectionsSubscription()\n await initDisconnectConnectionsSubscription()\n await initConnectConnectionsSubscription()\n await initRunTaskSubscription()\n } catch (ex) {\n console.error('Just has failed to initialize Edge Server.', ex)\n }\n})\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionQuery = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const type_graphql_1 = require("type-graphql");
|
|
6
|
-
const integration_base_1 = require("@things-factory/integration-base");
|
|
7
|
-
let ConnectionQuery = class ConnectionQuery {
|
|
8
|
-
async connectionsOnEdge(context) {
|
|
9
|
-
const entities = integration_base_1.ConnectionManager.getEntities();
|
|
10
|
-
const connections = Object.values(entities).reduce((sum, keyval) => {
|
|
11
|
-
const items = Object.values(keyval);
|
|
12
|
-
sum.push(...items);
|
|
13
|
-
return sum;
|
|
14
|
-
}, []);
|
|
15
|
-
return connections;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
exports.ConnectionQuery = ConnectionQuery;
|
|
19
|
-
tslib_1.__decorate([
|
|
20
|
-
(0, type_graphql_1.Query)(returns => [integration_base_1.Connection], { description: 'To fetch multiple connections' }),
|
|
21
|
-
tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
|
|
22
|
-
tslib_1.__metadata("design:type", Function),
|
|
23
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
24
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
25
|
-
], ConnectionQuery.prototype, "connectionsOnEdge", null);
|
|
26
|
-
exports.ConnectionQuery = ConnectionQuery = tslib_1.__decorate([
|
|
27
|
-
(0, type_graphql_1.Resolver)(integration_base_1.Connection)
|
|
28
|
-
], ConnectionQuery);
|
|
29
|
-
//# sourceMappingURL=connection-query.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAmF;AAKnF,uEAAgF;AAGzE,IAAM,eAAe,GAArB,MAAM,eAAe;IAEpB,AAAN,KAAK,CAAC,iBAAiB,CAAQ,OAAwB;QACrD,MAAM,QAAQ,GAA2D,oCAAiB,CAAC,WAAW,EAAE,CAAA;QACxG,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACjE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YACnC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;YAClB,OAAO,GAAG,CAAA;QACZ,CAAC,EAAE,EAAS,CAAC,CAAA;QAEb,OAAO,WAAW,CAAA;IACpB,CAAC;CACF,CAAA;AAZY,0CAAe;AAEpB;IADL,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;0BAXU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,6BAAU,CAAC;GACR,eAAe,CAY3B","sourcesContent":["import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { Appliance, User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ConnectionManager, Connection } from '@things-factory/integration-base'\n\n@Resolver(Connection)\nexport class ConnectionQuery {\n @Query(returns => [Connection], { description: 'To fetch multiple connections' })\n async connectionsOnEdge(@Ctx() context: ResolverContext): Promise<Connection[]> {\n const entities: { [domainId: string]: { [name: string]: Connection } } = ConnectionManager.getEntities()\n const connections = Object.values(entities).reduce((sum, keyval) => {\n const items = Object.values(keyval)\n sum.push(...items)\n return sum\n }, [] as any)\n\n return connections\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/connection/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAEvC,QAAA,SAAS,GAAG,CAAC,kCAAe,CAAC,CAAA","sourcesContent":["import { ConnectionQuery } from './connection-query'\n\nexport const resolvers = [ConnectionQuery]\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* EXPORT ENTITY TYPES */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.schema = exports.subscribers = exports.entities = void 0;
|
|
5
|
-
/* IMPORT ENTITIES AND RESOLVERS */
|
|
6
|
-
const connection_1 = require("./connection");
|
|
7
|
-
exports.entities = [
|
|
8
|
-
/* ENTITIES */
|
|
9
|
-
];
|
|
10
|
-
exports.subscribers = [
|
|
11
|
-
/* SUBSCRIBERS */
|
|
12
|
-
];
|
|
13
|
-
exports.schema = {
|
|
14
|
-
resolverClasses: [
|
|
15
|
-
/* RESOLVER CLASSES */
|
|
16
|
-
...connection_1.resolvers
|
|
17
|
-
]
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";AAAA,yBAAyB;;;AAEzB,mCAAmC;AACnC,6CAA+D;AAElD,QAAA,QAAQ,GAAG;AACtB,cAAc;CACf,CAAA;AAEY,QAAA,WAAW,GAAG;AACzB,iBAAiB;CAClB,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACtB,GAAG,sBAAmB;KACvB;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport { resolvers as ConnectionResolvers } from './connection'\n\nexport const entities = [\n /* ENTITIES */\n]\n\nexport const subscribers = [\n /* SUBSCRIBERS */\n]\n\nexport const schema = {\n resolverClasses: [\n /* RESOLVER CLASSES */\n ...ConnectionResolvers\n ]\n}\n"]}
|