@things-factory/integration-base 6.0.133 → 6.0.142
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/engine/task/http-get.js +13 -4
- package/dist-server/engine/task/http-get.js.map +1 -1
- package/dist-server/engine/task/script.js +1 -0
- package/dist-server/engine/task/script.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/engine/task/http-get.ts +16 -4
- package/server/engine/task/script.ts +1 -0
@@ -1,13 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const tslib_1 = require("tslib");
|
4
|
-
const task_registry_1 = require("../task-registry");
|
5
|
-
const connection_manager_1 = require("../connection-manager");
|
6
4
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
5
|
+
const vm2_1 = require("vm2");
|
7
6
|
const url_1 = require("url");
|
8
|
-
const substitute_1 = require("./utils/substitute");
|
9
7
|
const https_1 = tslib_1.__importDefault(require("https"));
|
10
|
-
|
8
|
+
const task_registry_1 = require("../task-registry");
|
9
|
+
const connection_manager_1 = require("../connection-manager");
|
10
|
+
const substitute_1 = require("./utils/substitute");
|
11
|
+
async function HttpGet(step, { logger, data, domain, variables }) {
|
11
12
|
var { connection: connectionName, params: stepOptions } = step;
|
12
13
|
var { headers: requestHeaders, searchParams = {}, path } = stepOptions || {};
|
13
14
|
var connection = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
|
@@ -15,6 +16,14 @@ async function HttpGet(step, { logger, data, domain }) {
|
|
15
16
|
throw new Error(`connection '${connectionName}' is not established.`);
|
16
17
|
}
|
17
18
|
var { endpoint, params: connectionParams, authHeaders = {} } = connection;
|
19
|
+
const vm = new vm2_1.VM({
|
20
|
+
sandbox: {
|
21
|
+
domain,
|
22
|
+
data,
|
23
|
+
variables
|
24
|
+
}
|
25
|
+
});
|
26
|
+
path = vm.run('`' + path + '`');
|
18
27
|
var url = new url_1.URL(path, endpoint);
|
19
28
|
if (searchParams) {
|
20
29
|
Object.keys(searchParams).forEach(key => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"http-get.js","sourceRoot":"","sources":["../../../server/engine/task/http-get.ts"],"names":[],"mappings":";;;AAAA,oDAA+C;AAC/C,8DAAyD;AACzD,
|
1
|
+
{"version":3,"file":"http-get.js","sourceRoot":"","sources":["../../../server/engine/task/http-get.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,6BAAwB;AACxB,6BAAyB;AACzB,0DAAyB;AACzB,oDAA+C;AAC/C,8DAAyD;AACzD,mDAA+C;AAE/C,KAAK,UAAU,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE;IAC9D,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAC5E,IAAI,UAAU,GAAG,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAEtF,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;KACtE;IAED,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEzE,MAAM,EAAE,GAAG,IAAI,QAAE,CAAC;QAChB,OAAO,EAAE;YACP,MAAM;YACN,IAAI;YACJ,SAAS;SACV;KACF,CAAC,CAAA;IAEF,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC,CAAA;IAE/B,IAAI,GAAG,GAAG,IAAI,SAAG,C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;IACtB;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,eAAe;KACvB;CACF,CAAA;AAED,4BAAY,CAAC,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA","sourcesContent":["import fetch from 'node-fetch'\nimport { VM } from 'vm2'\nimport { URL } from 'url'\nimport https from 'https'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport { substitute } from './utils/substitute'\n\nasync function HttpGet(step, { logger, data, domain, variables }) {\n var { connection: connectionName, params: stepOptions } = step\n var { headers: requestHeaders, searchParams = {}, path } = stepOptions || {}\n var connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`connection '${connectionName}' is not established.`)\n }\n\n var { endpoint, params: connectionParams, authHeaders = {} } = connection\n\n const vm = new VM({\n sandbox: {\n domain,\n data,\n variables\n }\n })\n\n path = vm.run('`' + path + '`')\n\n var url = new URL(path, endpoint)\n if (searchParams) {\n Object.keys(searchParams).forEach(key => {\n let value = substitute(searchParams[key], data)\n url.searchParams.append(key, value)\n })\n }\n\n var fetchOptions: any = {\n method: 'GET',\n headers: {\n ...requestHeaders,\n ...authHeaders\n }\n }\n\n var { rejectUnauthorized } = connectionParams\n\n if (!rejectUnauthorized) {\n const httpsAgent = new https.Agent({\n rejectUnauthorized\n })\n fetchOptions.agent = httpsAgent\n }\n\n var response = await fetch(url, fetchOptions)\n\n var responseData = await response.text()\n\n const responseContentType = response.headers.get('content-type')\n if (responseContentType && responseContentType.indexOf('application/json') !== -1) {\n responseData = JSON.parse(responseData)\n }\n\n logger.info(`http-get : \\n${JSON.stringify(responseData, null, 2)}`)\n\n return {\n data: responseData\n }\n}\n\nHttpGet.parameterSpec = [\n {\n type: 'string',\n name: 'path',\n label: 'path'\n },\n {\n type: 'http-headers',\n name: 'headers',\n label: 'headers'\n },\n {\n type: 'http-parameters',\n name: 'searchParams',\n label: 'search-params'\n }\n]\n\nTaskRegistry.registerTaskHandler('http-get', HttpGet)\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../../server/engine/task/script.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,6BAA4B;AAE5B,KAAK,UAAU,MAAM,CAAC,IAAI,EAAE,OAAO;IACjC,IAAI,EACF,MAAM,EAAE,EAAE,MAAM,EAAE,EACnB,GAAG,IAAI,CAAA;IAER,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAE3C,MAAM,EAAE,GAAG,IAAI,YAAM,CAAC;QACpB,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE;YACP,MAAM;YACN,IAAI;YACJ,SAAS;SACV;KACF,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAE7B,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,MAAM,CAAC,aAAa,GAAG;IACrB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;KAChB;CACF,CAAA;AAED,MAAM,CAAC,aAAa,GAAG,IAAI,CAAA;AAC3B,MAAM,CAAC,IAAI,GAAG,yBAAyB,CAAA;AAEvC,4BAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '../task-registry'\nimport { NodeVM } from 'vm2'\n\nasync function Script(step, context) {\n var {\n params: { script }\n } = step\n\n const { domain, data, variables } = context\n\n const vm = new NodeVM({\n timeout: 5000,\n wrapper: 'none',\n console: 'inherit',\n sandbox: {\n domain,\n data,\n variables\n }\n })\n\n const result = vm.run(script)\n\n return {\n data: result\n }\n}\n\nScript.parameterSpec = [\n {\n type: 'textarea',\n name: 'script',\n label: 'script'\n }\n]\n\nScript.connectorFree = true\nScript.help = 'integration/task/script'\n\nTaskRegistry.registerTaskHandler('script', Script)\n"]}
|
1
|
+
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../../server/engine/task/script.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,6BAA4B;AAE5B,KAAK,UAAU,MAAM,CAAC,IAAI,EAAE,OAAO;IACjC,IAAI,EACF,MAAM,EAAE,EAAE,MAAM,EAAE,EACnB,GAAG,IAAI,CAAA;IAER,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAE3C,MAAM,EAAE,GAAG,IAAI,YAAM,CAAC;QACpB,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE;YACP,MAAM;YACN,IAAI;YACJ,SAAS;SACV;KACF,CAAC,CAAA;IAEF,iEAAiE;IACjE,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAE7B,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,MAAM,CAAC,aAAa,GAAG;IACrB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;KAChB;CACF,CAAA;AAED,MAAM,CAAC,aAAa,GAAG,IAAI,CAAA;AAC3B,MAAM,CAAC,IAAI,GAAG,yBAAyB,CAAA;AAEvC,4BAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '../task-registry'\nimport { NodeVM } from 'vm2'\n\nasync function Script(step, context) {\n var {\n params: { script }\n } = step\n\n const { domain, data, variables } = context\n\n const vm = new NodeVM({\n timeout: 5000,\n wrapper: 'none',\n console: 'inherit',\n sandbox: {\n domain,\n data,\n variables\n }\n })\n\n // const result = await vm.run(`(async () => {\\n${script}\\n})()`)\n const result = vm.run(script)\n\n return {\n data: result\n }\n}\n\nScript.parameterSpec = [\n {\n type: 'textarea',\n name: 'script',\n label: 'script'\n }\n]\n\nScript.connectorFree = true\nScript.help = 'integration/task/script'\n\nTaskRegistry.registerTaskHandler('script', Script)\n"]}
|