@things-factory/integration-base 9.1.19 → 10.0.0-beta.2
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/connector/graphql-connector.js +1 -3
- package/dist-server/engine/connector/graphql-connector.js.map +1 -1
- package/dist-server/engine/connector/headless-connector.js +9 -1
- package/dist-server/engine/connector/headless-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +1 -3
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/evaluate-template.d.ts +21 -0
- package/dist-server/engine/evaluate-template.js +36 -0
- package/dist-server/engine/evaluate-template.js.map +1 -0
- package/dist-server/engine/index.d.ts +1 -0
- package/dist-server/engine/index.js +1 -0
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/task/database-query.d.ts +1 -1
- package/dist-server/engine/task/database-query.js +2 -10
- package/dist-server/engine/task/database-query.js.map +1 -1
- package/dist-server/engine/task/graphql-mutate.d.ts +1 -1
- package/dist-server/engine/task/graphql-mutate.js +2 -10
- package/dist-server/engine/task/graphql-mutate.js.map +1 -1
- package/dist-server/engine/task/graphql-query.d.ts +1 -1
- package/dist-server/engine/task/graphql-query.js +2 -10
- package/dist-server/engine/task/graphql-query.js.map +1 -1
- package/dist-server/engine/task/headless-scrap.js +9 -1
- package/dist-server/engine/task/headless-scrap.js.map +1 -1
- package/dist-server/engine/task/http-get.d.ts +1 -1
- package/dist-server/engine/task/http-get.js +5 -14
- package/dist-server/engine/task/http-get.js.map +1 -1
- package/dist-server/engine/task/http-post.d.ts +1 -1
- package/dist-server/engine/task/http-post.js +4 -13
- package/dist-server/engine/task/http-post.js.map +1 -1
- package/dist-server/engine/task/local-graphql-mutate.d.ts +1 -1
- package/dist-server/engine/task/local-graphql-mutate.js +2 -10
- package/dist-server/engine/task/local-graphql-mutate.js.map +1 -1
- package/dist-server/engine/task/local-graphql-query.d.ts +1 -1
- package/dist-server/engine/task/local-graphql-query.js +2 -10
- package/dist-server/engine/task/local-graphql-query.js.map +1 -1
- package/dist-server/engine/task/log.d.ts +1 -1
- package/dist-server/engine/task/log.js +2 -10
- package/dist-server/engine/task/log.js.map +1 -1
- package/dist-server/engine/task/mssql-exec-query.d.ts +0 -1
- package/dist-server/engine/task/mssql-exec-query.js +2 -3
- package/dist-server/engine/task/mssql-exec-query.js.map +1 -1
- package/dist-server/engine/task/mssql-procedure.d.ts +1 -1
- package/dist-server/engine/task/mssql-procedure.js +2 -12
- package/dist-server/engine/task/mssql-procedure.js.map +1 -1
- package/dist-server/engine/task/oracle-procedure.d.ts +1 -1
- package/dist-server/engine/task/oracle-procedure.js +2 -12
- package/dist-server/engine/task/oracle-procedure.js.map +1 -1
- package/dist-server/engine/task/script.d.ts +1 -1
- package/dist-server/engine/task/script.js +18 -19
- package/dist-server/engine/task/script.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/scenario-instance/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -14
- /package/client/{index.js → index.ts} +0 -0
|
@@ -2,25 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
5
|
-
require("ses");
|
|
6
5
|
const utils_1 = require("@things-factory/utils");
|
|
7
6
|
const connection_manager_1 = require("../connection-manager");
|
|
7
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
8
8
|
const task_registry_1 = require("../task-registry");
|
|
9
9
|
async function GraphqlQuery(step, context) {
|
|
10
10
|
var { connection: connectionName, params: stepOptions } = step;
|
|
11
11
|
var { query, variables: variablesAccessorMap, headers } = stepOptions || {};
|
|
12
12
|
var { domain, user, data, variables, lng } = context;
|
|
13
|
-
const compartment = new Compartment({
|
|
14
|
-
domain,
|
|
15
|
-
user,
|
|
16
|
-
lng,
|
|
17
|
-
data,
|
|
18
|
-
variables,
|
|
19
|
-
console
|
|
20
|
-
});
|
|
21
13
|
let evalQuery;
|
|
22
14
|
try {
|
|
23
|
-
evalQuery =
|
|
15
|
+
evalQuery = (0, evaluate_template_1.evaluateTemplate)(query, { domain, user, lng, data, variables, console });
|
|
24
16
|
}
|
|
25
17
|
catch (err) {
|
|
26
18
|
throw new Error(`Failed to evaluate query: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-query.js","sourceRoot":"","sources":["../../../server/engine/task/graphql-query.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;
|
|
1
|
+
{"version":3,"file":"graphql-query.js","sourceRoot":"","sources":["../../../server/engine/task/graphql-query.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;AAE7B,iDAA8C;AAC9C,8DAAyD;AACzD,4DAAuD;AACvD,oDAA+C;AAI/C,KAAK,UAAU,YAAY,CAAC,IAAe,EAAE,OAAgB;IAC3D,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAC3E,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;IAEpD,IAAI,SAAS,CAAA;IACb,IAAI,CAAC;QACH,SAAS,GAAG,IAAA,oCAAgB,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;IACtF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IAC7D,CAAC;IAED,IAAI,MAAM,GAAG,MAAM,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAExF,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE;QACvF,MAAM,QAAQ,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAA;QAC1C,SAAS,CAAC,GAAG,CAAC,GAAG,IAAA,cAAM,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACvC,OAAO,SAAS,CAAA;IAClB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;QAC7C,KAAK,EAAE,IAAA,qBAAG,EAAA;QACN,SAAS;KACZ;QACD,SAAS,EAAE,cAAc;QACzB,OAAO;KACR,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,WAAW;KAClB,CAAA;AACH,CAAC;AAED,YAAY,CAAC,aAAa,GAAG;IAC3B;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE;YACR,eAAe,EAAE,IAAI;SACtB;QACD,MAAM,EAAE;YACN,IAAI,EAAE,CAAC;SACR;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;CACF,CAAA;AAED,YAAY,CAAC,IAAI,GAAG,gCAAgC,CAAA;AAEpD,4BAAY,CAAC,mBAAmB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nimport { access } from '@things-factory/utils'\nimport { ConnectionManager } from '../connection-manager'\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function GraphqlQuery(step: InputStep, context: Context) {\n var { connection: connectionName, params: stepOptions } = step\n var { query, variables: variablesAccessorMap, headers } = stepOptions || {}\n var { domain, user, data, variables, lng } = context\n\n let evalQuery\n try {\n evalQuery = evaluateTemplate(query, { domain, user, lng, data, variables, console })\n } catch (err) {\n throw new Error(`Failed to evaluate query: ${err.message}`)\n }\n\n var client = await ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n const queryVariables = Object.keys(variablesAccessorMap || {}).reduce((variables, key) => {\n const accessor = variablesAccessorMap[key]\n variables[key] = access(accessor, data)\n return variables\n }, {})\n\n var { data: queryResult } = await client.query({\n query: gql`\n ${evalQuery}\n `,\n variables: queryVariables,\n headers\n })\n\n return {\n data: queryResult\n }\n}\n\nGraphqlQuery.parameterSpec = [\n {\n type: 'graphql',\n name: 'query',\n label: 'query',\n property: {\n showLineNumbers: true\n },\n styles: {\n flex: 1\n }\n },\n {\n type: 'key-values',\n name: 'variables',\n label: 'variables'\n },\n {\n type: 'key-values',\n name: 'headers',\n label: 'headers'\n }\n]\n\nGraphqlQuery.help = 'integration/task/graphql-query'\n\nTaskRegistry.registerTaskHandler('graphql-query', GraphqlQuery)\n"]}
|
|
@@ -34,7 +34,15 @@ async function HeadlessScrap(step, { logger, data, domain }) {
|
|
|
34
34
|
pageResource = { page, requiresManualRelease: false };
|
|
35
35
|
}
|
|
36
36
|
page.on('console', async (msg) => {
|
|
37
|
-
|
|
37
|
+
const args = await Promise.all(msg.args().map(arg => arg.jsonValue().catch(() => undefined)));
|
|
38
|
+
if (args.some(a => a !== undefined)) {
|
|
39
|
+
console.log(`[browser ${msg.type()}]`, ...args.filter(a => a !== undefined));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const text = msg.text();
|
|
43
|
+
if (text)
|
|
44
|
+
console.log(`[browser ${msg.type()}]`, text);
|
|
45
|
+
}
|
|
38
46
|
});
|
|
39
47
|
page.on('requestfailed', request => {
|
|
40
48
|
console.log('Request failed:');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless-scrap.js","sourceRoot":"","sources":["../../../server/engine/task/headless-scrap.ts"],"names":[],"mappings":";;AAAA,6BAAyB;AAEzB,oDAA+C;AAC/C,8DAAyD;AACzD,2FAAgF;AAEhF,KAAK,UAAU,aAAa,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAChE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAE7H,MAAM,UAAU,GAAG,MAAM,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAE9F,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,WAAW,EAAE,eAAe,EAAE,qBAAqB,EAAE,GAAG,UAAU,CAAA;IAClI,MAAM,aAAa,GAAG,gBAAgB,EAAE,aAAa,IAAI,QAAQ,CAAA;IAEjE,MAAM,OAAO,GAAG;QACd,GAAG,cAAc;KAClB,CAAA;IAED,IAAI,IAAI,GAAG,IAAI,CAAA;IACf,IAAI,YAAY,GAAG,IAAI,CAAA,CAAE,YAAY;IACrC,IAAI,SAAS,GAAG,IAAI,CAAA;IAEpB,YAAY;IACZ,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,SAA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ionManager } from '../connection-manager'\nimport { safeReleasePageResource } from './utils/headless-request-with-recovery'\n\nasync function HeadlessScrap(step, { logger, data, domain }) {\n const { connection: connectionName, params: stepOptions } = step\n const { headers: requestHeaders, path, selectors = [], waitForSelectors, waitForTimeout, maxRetries = 2 } = stepOptions || {}\n\n const connection = await ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`Connection '${connectionName}' is not established.`)\n }\n\n const { endpoint, params: connectionParams, acquireSessionPage, releasePage, validateSession, reAuthenticateSession } = connection\n const loginPagePath = connectionParams?.loginPagePath || '/login'\n\n const headers = {\n ...requestHeaders\n }\n\n let page = null\n let pageResource = null // 리소스 추적 객체\n let lastError = null\n\n // 재시도 로직 추가\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n // 페이지 획득\n const sessionResult = await acquireSessionPage()\n \n // reAuthenticateSession의 반환 형태 확인\n if (sessionResult && typeof sessionResult === 'object' && sessionResult.page) {\n pageResource = sessionResult // {page, browser, requiresManualRelease}\n page = sessionResult.page\n } else {\n page = sessionResult\n pageResource = { page, requiresManualRelease: false }\n }\n\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:')\n console.log(`- URL: ${request.url()}`)\n console.log(`- Method: ${request.method()}`)\n console.log(`- Failure Text: ${request.failure()?.errorText}`)\n console.log(`- Headers:`, request.headers())\n\n // POST 데이터 (필요한 경우)\n if (request.postData()) {\n console.log(`- Post Data: ${request.postData()}`)\n }\n })\n\n // 302 리디렉션 감지 추가 - 이벤트 핸들러는 비동기 리소스 정리 불가하므로 단순 로깅만\n page.on('response', response => {\n try {\n if ([301, 302, 307, 308].includes(response.status())) {\n const location = response.headers()['location'] || ''\n if (location.includes(loginPagePath) || \n location.includes('/login') || \n location.includes('/signin') || \n location.includes('/auth')) {\n logger.warn(`Login redirect detected during response: ${location}`)\n // Note: Cannot throw from event handler - will be caught in main flow\n }\n }\n } catch (eventError) {\n logger.error('Error in response event handler:', eventError)\n }\n })\n\n // 세션 검증은 2번째 시도부터만 수행 (첫 번째는 새 페이지이므로 불필요)\n if (attempt > 0 && validateSession) {\n logger.debug(`Validating session for connection '${connectionName}' in HeadlessScrap (attempt: ${attempt + 1})`)\n const isSessionValid = await validateSession(page)\n if (!isSessionValid) {\n logger.warn(`Session invalid for connection '${connectionName}', attempting re-authentication (attempt: ${attempt + 1})`)\n await safeReleasePageResource(pageResource, releasePage, logger)\n \n try {\n const reauthResult = await reAuthenticateSession()\n if (reauthResult && typeof reauthResult === 'object' && reauthResult.page) {\n pageResource = reauthResult\n page = reauthResult.page\n } else {\n page = reauthResult\n pageResource = { page, requiresManualRelease: false }\n }\n logger.info(`Re-authentication successful for connection '${connectionName}' in HeadlessScrap`)\n } catch (reauthError) {\n logger.error(`Re-authentication failed for connection '${connectionName}' in HeadlessScrap:`, reauthError)\n // 재인증 실패 시 이번 시도는 실패로 처리하고 다음 시도로 넘어감\n if (attempt === maxRetries) {\n throw new Error(`Re-authentication failed in HeadlessScrap after ${maxRetries + 1} attempts: ${reauthError.message}`)\n }\n continue\n }\n }\n }\n\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n\n // 페이지 로드 후 로그인 페이지로 리디렉션되었는지 확인\n const currentUrl = page.url()\n if (currentUrl.includes(loginPagePath) || \n currentUrl.includes('/login') || \n currentUrl.includes('/signin') || \n currentUrl.includes('/auth')) {\n logger.warn(`Login redirect detected in HeadlessScrap: ${currentUrl}`)\n \n if (attempt < maxRetries) {\n logger.warn(`Attempting re-authentication due to login redirect (attempt: ${attempt + 1}/${maxRetries + 1})`)\n await safeReleasePageResource(pageResource, releasePage, logger)\n \n try {\n const reauthResult = await reAuthenticateSession()\n if (reauthResult && typeof reauthResult === 'object' && reauthResult.page) {\n pageResource = reauthResult\n page = reauthResult.page\n } else {\n page = reauthResult\n pageResource = { page, requiresManualRelease: false }\n }\n logger.info(`Re-authentication successful after login redirect in HeadlessScrap`)\n \n // 재인증 후 다시 페이지 이동\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n \n // 재인증 후에도 리디렉션이 발생하는지 확인\n const newUrl = page.url()\n if (newUrl.includes(loginPagePath) || \n newUrl.includes('/login') || \n newUrl.includes('/signin') || \n newUrl.includes('/auth')) {\n throw new Error(`Still redirected to login after re-authentication: ${newUrl}`)\n }\n } catch (reauthError) {\n logger.error(`Re-authentication failed after login redirect in HeadlessScrap:`, reauthError)\n if (attempt === maxRetries) {\n throw new Error(`Re-authentication failed after login redirect: ${reauthError.message}`)\n }\n continue\n }\n } else {\n throw new Error(`Login redirect after ${maxRetries + 1} attempts: ${currentUrl}`)\n }\n }\n\n // waitForSelectors, waitForTimeout 처리 추가\n if (waitForSelectors) {\n try {\n await page.waitForFunction(\n selectorsString => {\n const selectors = selectorsString.split(',').map(s => s.trim())\n return selectors.every(selector => {\n const el = document.querySelector(selector)\n return el && el.textContent && el.textContent.trim().length > 0\n })\n },\n { timeout: waitForTimeout ? Number(waitForTimeout) : 10000 },\n waitForSelectors // 콤마로 구분된 셀렉터 문자열\n )\n } catch (e) {\n logger.error(`waitForSelectors(${waitForSelectors}) 값이 모두 채워지지 않음:`, e)\n throw e\n }\n } else if (waitForTimeout) {\n await page.waitForTimeout(Number(waitForTimeout))\n }\n\n const result = {}\n\n // DOM 요소 추출 - 실패 시에도 안전한 처리\n try {\n for (const selector of selectors) {\n const { text, value } = selector\n \n try {\n result[text] = await page.$$eval(value, elements => {\n return elements.map(element => {\n if (\n element instanceof HTMLInputElement ||\n element instanceof HTMLTextAreaElement ||\n element instanceof HTMLSelectElement\n ) {\n return element.value\n } else {\n return element.textContent?.trim()\n }\n })\n })\n } catch (selectorError) {\n logger.warn(`Failed to extract data for selector '${value}' (${text}):`, selectorError)\n result[text] = [] // 빈 배열로 설정하여 스크래핑 계속 진행\n }\n }\n } catch (domError) {\n logger.error(`DOM extraction failed:`, domError)\n throw domError // 전체 DOM 추출 실패 시 에러 발생\n }\n\n // 성공시 페이지 릴리즈 후 결과 반환\n await safeReleasePageResource(pageResource, releasePage, logger)\n\n return {\n data: result\n }\n\n } catch (error) {\n lastError = error\n logger.error(`HeadlessScrap attempt ${attempt + 1} failed:`, error)\n\n await safeReleasePageResource(pageResource, releasePage, logger)\n page = null\n pageResource = null\n\n // 에러 분류 및 복구 가능성 판단 (HeadlessPost와 동일한 로직)\n const errorMessage = error.message?.toLowerCase() || ''\n const isRecoverableError = (\n errorMessage.includes('login') || \n errorMessage.includes('redirect') || \n errorMessage.includes('unauthorized') || \n errorMessage.includes('forbidden') || \n errorMessage.includes('session') ||\n errorMessage.includes('timeout') ||\n errorMessage.includes('network') ||\n errorMessage.includes('connection') ||\n errorMessage.includes('failed to fetch') ||\n errorMessage.includes('navigation') ||\n errorMessage.includes('authentication') ||\n error.name === 'TimeoutError'\n )\n\n // 복구 불가능한 에러이거나 최대 재시도 횟수에 도달한 경우\n if (!isRecoverableError || attempt === maxRetries) {\n if (isRecoverableError && attempt === maxRetries) {\n logger.error(`HeadlessScrap: Recoverable error but max retries (${maxRetries + 1}) reached: ${error.message}`)\n } else {\n logger.error(`HeadlessScrap: Non-recoverable error: ${error.message}`)\n }\n throw error\n }\n\n logger.info(`Retrying HeadlessScrap... (${attempt + 2}/${maxRetries + 1})`)\n }\n }\n\n // 모든 재시도가 실패한 경우 - 혹시 남은 리소스가 있으면 정리\n if (pageResource) {\n await safeReleasePageResource(pageResource, releasePage, logger)\n }\n throw lastError || new Error('HeadlessScrap failed after all retry attempts')\n}\n\nHeadlessScrap.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: 'options',\n name: 'selectors',\n label: 'selectors'\n },\n {\n type: 'string',\n name: 'waitForSelectors',\n label: 'wait-for-selectors'\n },\n {\n type: 'string',\n name: 'waitForTimeout',\n label: 'wait-for-timeout'\n },\n {\n type: 'number',\n name: 'maxRetries',\n label: 'maximum-retries',\n value: 2\n }\n]\n\nHeadlessScrap.help = 'integration/task/headless-scrap'\n\nTaskRegistry.registerTaskHandler('headless-scrap', HeadlessScrap)\n"]}
|
|
1
|
+
{"version":3,"file":"headless-scrap.js","sourceRoot":"","sources":["../../../server/engine/task/headless-scrap.ts"],"names":[],"mappings":";;AAAA,6BAAyB;AAEzB,oDAA+C;AAC/C,8DAAyD;AACzD,2FAAgF;AAEhF,KAAK,UAAU,aAAa,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAChE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAE7H,MAAM,UAAU,GAAG,MAAM,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAE9F,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,WAAW,EAAE,eAAe,EAAE,qBAAqB,EAAE,GAAG,UAAU,CAAA;IAClI,MAAM,aAAa,GAAG,gBAAgB,EAAE,aAAa,IAAI,QAAQ,CAAA;IAEjE,MAAM,OAAO,GAAG;QACd,GAAG,cAAc;KAClB,CAAA;IAED,IAAI,IAAI,GAAG,IAAI,CAAA;IACf,IAAI,YAAY,GAAG,IAAI,CAAA,CAAE,YAAY;IACrC,IAAI,SAAS,GAAG,IAAI,CAAA;IAEpB,YAAY;IACZ,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;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,SAAS;QACf,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,oBAAoB;KAC5B;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,kBAAkB;KAC1B;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,CAAC;KACT;CACF,CAAA;AAED,aAAa,CAAC,IAAI,GAAG,iCAAiC,CAAA;AAEtD,4BAAY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["import { URL } from 'url'\n\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport { safeReleasePageResource } from './utils/headless-request-with-recovery'\n\nasync function HeadlessScrap(step, { logger, data, domain }) {\n const { connection: connectionName, params: stepOptions } = step\n const { headers: requestHeaders, path, selectors = [], waitForSelectors, waitForTimeout, maxRetries = 2 } = stepOptions || {}\n\n const connection = await ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`Connection '${connectionName}' is not established.`)\n }\n\n const { endpoint, params: connectionParams, acquireSessionPage, releasePage, validateSession, reAuthenticateSession } = connection\n const loginPagePath = connectionParams?.loginPagePath || '/login'\n\n const headers = {\n ...requestHeaders\n }\n\n let page = null\n let pageResource = null // 리소스 추적 객체\n let lastError = null\n\n // 재시도 로직 추가\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n // 페이지 획득\n const sessionResult = await acquireSessionPage()\n \n // reAuthenticateSession의 반환 형태 확인\n if (sessionResult && typeof sessionResult === 'object' && sessionResult.page) {\n pageResource = sessionResult // {page, browser, requiresManualRelease}\n page = sessionResult.page\n } else {\n page = sessionResult\n pageResource = { page, requiresManualRelease: false }\n }\n\n page.on('console', async msg => {\n const args = await Promise.all(msg.args().map(arg => arg.jsonValue().catch(() => undefined)))\n\n if (args.some(a => a !== undefined)) {\n console.log(`[browser ${msg.type()}]`, ...args.filter(a => a !== undefined))\n } else {\n const text = msg.text()\n if (text) console.log(`[browser ${msg.type()}]`, text)\n }\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:')\n console.log(`- URL: ${request.url()}`)\n console.log(`- Method: ${request.method()}`)\n console.log(`- Failure Text: ${request.failure()?.errorText}`)\n console.log(`- Headers:`, request.headers())\n\n // POST 데이터 (필요한 경우)\n if (request.postData()) {\n console.log(`- Post Data: ${request.postData()}`)\n }\n })\n\n // 302 리디렉션 감지 추가 - 이벤트 핸들러는 비동기 리소스 정리 불가하므로 단순 로깅만\n page.on('response', response => {\n try {\n if ([301, 302, 307, 308].includes(response.status())) {\n const location = response.headers()['location'] || ''\n if (location.includes(loginPagePath) || \n location.includes('/login') || \n location.includes('/signin') || \n location.includes('/auth')) {\n logger.warn(`Login redirect detected during response: ${location}`)\n // Note: Cannot throw from event handler - will be caught in main flow\n }\n }\n } catch (eventError) {\n logger.error('Error in response event handler:', eventError)\n }\n })\n\n // 세션 검증은 2번째 시도부터만 수행 (첫 번째는 새 페이지이므로 불필요)\n if (attempt > 0 && validateSession) {\n logger.debug(`Validating session for connection '${connectionName}' in HeadlessScrap (attempt: ${attempt + 1})`)\n const isSessionValid = await validateSession(page)\n if (!isSessionValid) {\n logger.warn(`Session invalid for connection '${connectionName}', attempting re-authentication (attempt: ${attempt + 1})`)\n await safeReleasePageResource(pageResource, releasePage, logger)\n \n try {\n const reauthResult = await reAuthenticateSession()\n if (reauthResult && typeof reauthResult === 'object' && reauthResult.page) {\n pageResource = reauthResult\n page = reauthResult.page\n } else {\n page = reauthResult\n pageResource = { page, requiresManualRelease: false }\n }\n logger.info(`Re-authentication successful for connection '${connectionName}' in HeadlessScrap`)\n } catch (reauthError) {\n logger.error(`Re-authentication failed for connection '${connectionName}' in HeadlessScrap:`, reauthError)\n // 재인증 실패 시 이번 시도는 실패로 처리하고 다음 시도로 넘어감\n if (attempt === maxRetries) {\n throw new Error(`Re-authentication failed in HeadlessScrap after ${maxRetries + 1} attempts: ${reauthError.message}`)\n }\n continue\n }\n }\n }\n\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n\n // 페이지 로드 후 로그인 페이지로 리디렉션되었는지 확인\n const currentUrl = page.url()\n if (currentUrl.includes(loginPagePath) || \n currentUrl.includes('/login') || \n currentUrl.includes('/signin') || \n currentUrl.includes('/auth')) {\n logger.warn(`Login redirect detected in HeadlessScrap: ${currentUrl}`)\n \n if (attempt < maxRetries) {\n logger.warn(`Attempting re-authentication due to login redirect (attempt: ${attempt + 1}/${maxRetries + 1})`)\n await safeReleasePageResource(pageResource, releasePage, logger)\n \n try {\n const reauthResult = await reAuthenticateSession()\n if (reauthResult && typeof reauthResult === 'object' && reauthResult.page) {\n pageResource = reauthResult\n page = reauthResult.page\n } else {\n page = reauthResult\n pageResource = { page, requiresManualRelease: false }\n }\n logger.info(`Re-authentication successful after login redirect in HeadlessScrap`)\n \n // 재인증 후 다시 페이지 이동\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n \n // 재인증 후에도 리디렉션이 발생하는지 확인\n const newUrl = page.url()\n if (newUrl.includes(loginPagePath) || \n newUrl.includes('/login') || \n newUrl.includes('/signin') || \n newUrl.includes('/auth')) {\n throw new Error(`Still redirected to login after re-authentication: ${newUrl}`)\n }\n } catch (reauthError) {\n logger.error(`Re-authentication failed after login redirect in HeadlessScrap:`, reauthError)\n if (attempt === maxRetries) {\n throw new Error(`Re-authentication failed after login redirect: ${reauthError.message}`)\n }\n continue\n }\n } else {\n throw new Error(`Login redirect after ${maxRetries + 1} attempts: ${currentUrl}`)\n }\n }\n\n // waitForSelectors, waitForTimeout 처리 추가\n if (waitForSelectors) {\n try {\n await page.waitForFunction(\n selectorsString => {\n const selectors = selectorsString.split(',').map(s => s.trim())\n return selectors.every(selector => {\n const el = document.querySelector(selector)\n return el && el.textContent && el.textContent.trim().length > 0\n })\n },\n { timeout: waitForTimeout ? Number(waitForTimeout) : 10000 },\n waitForSelectors // 콤마로 구분된 셀렉터 문자열\n )\n } catch (e) {\n logger.error(`waitForSelectors(${waitForSelectors}) 값이 모두 채워지지 않음:`, e)\n throw e\n }\n } else if (waitForTimeout) {\n await page.waitForTimeout(Number(waitForTimeout))\n }\n\n const result = {}\n\n // DOM 요소 추출 - 실패 시에도 안전한 처리\n try {\n for (const selector of selectors) {\n const { text, value } = selector\n \n try {\n result[text] = await page.$$eval(value, elements => {\n return elements.map(element => {\n if (\n element instanceof HTMLInputElement ||\n element instanceof HTMLTextAreaElement ||\n element instanceof HTMLSelectElement\n ) {\n return element.value\n } else {\n return element.textContent?.trim()\n }\n })\n })\n } catch (selectorError) {\n logger.warn(`Failed to extract data for selector '${value}' (${text}):`, selectorError)\n result[text] = [] // 빈 배열로 설정하여 스크래핑 계속 진행\n }\n }\n } catch (domError) {\n logger.error(`DOM extraction failed:`, domError)\n throw domError // 전체 DOM 추출 실패 시 에러 발생\n }\n\n // 성공시 페이지 릴리즈 후 결과 반환\n await safeReleasePageResource(pageResource, releasePage, logger)\n\n return {\n data: result\n }\n\n } catch (error) {\n lastError = error\n logger.error(`HeadlessScrap attempt ${attempt + 1} failed:`, error)\n\n await safeReleasePageResource(pageResource, releasePage, logger)\n page = null\n pageResource = null\n\n // 에러 분류 및 복구 가능성 판단 (HeadlessPost와 동일한 로직)\n const errorMessage = error.message?.toLowerCase() || ''\n const isRecoverableError = (\n errorMessage.includes('login') || \n errorMessage.includes('redirect') || \n errorMessage.includes('unauthorized') || \n errorMessage.includes('forbidden') || \n errorMessage.includes('session') ||\n errorMessage.includes('timeout') ||\n errorMessage.includes('network') ||\n errorMessage.includes('connection') ||\n errorMessage.includes('failed to fetch') ||\n errorMessage.includes('navigation') ||\n errorMessage.includes('authentication') ||\n error.name === 'TimeoutError'\n )\n\n // 복구 불가능한 에러이거나 최대 재시도 횟수에 도달한 경우\n if (!isRecoverableError || attempt === maxRetries) {\n if (isRecoverableError && attempt === maxRetries) {\n logger.error(`HeadlessScrap: Recoverable error but max retries (${maxRetries + 1}) reached: ${error.message}`)\n } else {\n logger.error(`HeadlessScrap: Non-recoverable error: ${error.message}`)\n }\n throw error\n }\n\n logger.info(`Retrying HeadlessScrap... (${attempt + 2}/${maxRetries + 1})`)\n }\n }\n\n // 모든 재시도가 실패한 경우 - 혹시 남은 리소스가 있으면 정리\n if (pageResource) {\n await safeReleasePageResource(pageResource, releasePage, logger)\n }\n throw lastError || new Error('HeadlessScrap failed after all retry attempts')\n}\n\nHeadlessScrap.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: 'options',\n name: 'selectors',\n label: 'selectors'\n },\n {\n type: 'string',\n name: 'waitForSelectors',\n label: 'wait-for-selectors'\n },\n {\n type: 'string',\n name: 'waitForTimeout',\n label: 'wait-for-timeout'\n },\n {\n type: 'number',\n name: 'maxRetries',\n label: 'maximum-retries',\n value: 2\n }\n]\n\nHeadlessScrap.help = 'integration/task/headless-scrap'\n\nTaskRegistry.registerTaskHandler('headless-scrap', HeadlessScrap)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
5
|
-
require("ses");
|
|
6
5
|
const url_1 = require("url");
|
|
7
6
|
const https_1 = tslib_1.__importDefault(require("https"));
|
|
7
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
8
8
|
const task_registry_1 = require("../task-registry");
|
|
9
9
|
const connection_manager_1 = require("../connection-manager");
|
|
10
10
|
const substitute_1 = require("./utils/substitute");
|
|
@@ -16,27 +16,18 @@ async function HttpGet(step, { logger, data, domain, user, variables, lng }) {
|
|
|
16
16
|
throw new Error(`connection '${connectionName}' is not established.`);
|
|
17
17
|
}
|
|
18
18
|
var { endpoint, params: connectionParams, authHeaders = {} } = connection;
|
|
19
|
-
const
|
|
20
|
-
domain,
|
|
21
|
-
user,
|
|
22
|
-
lng,
|
|
23
|
-
data,
|
|
24
|
-
variables,
|
|
25
|
-
console
|
|
26
|
-
});
|
|
27
|
-
let evalPath;
|
|
19
|
+
const scope = { domain, user, lng, data, variables, console };
|
|
28
20
|
try {
|
|
29
|
-
|
|
21
|
+
path = (0, evaluate_template_1.evaluateTemplate)(path, scope);
|
|
30
22
|
}
|
|
31
23
|
catch (err) {
|
|
32
24
|
throw new Error(`Failed to evaluate path: ${err.message}`);
|
|
33
25
|
}
|
|
34
|
-
path = evalPath;
|
|
35
26
|
requestHeaders =
|
|
36
27
|
requestHeaders &&
|
|
37
28
|
Object.entries(requestHeaders).reduce((sum, [key, value]) => {
|
|
38
29
|
try {
|
|
39
|
-
sum[key] =
|
|
30
|
+
sum[key] = (0, evaluate_template_1.evaluateTemplate)(value, scope);
|
|
40
31
|
}
|
|
41
32
|
catch (err) {
|
|
42
33
|
throw new Error(`Failed to evaluate header value: ${err.message}`);
|
|
@@ -47,7 +38,7 @@ async function HttpGet(step, { logger, data, domain, user, variables, lng }) {
|
|
|
47
38
|
searchParams &&
|
|
48
39
|
Object.entries(searchParams).reduce((sum, [key, value]) => {
|
|
49
40
|
try {
|
|
50
|
-
sum[key] =
|
|
41
|
+
sum[key] = (0, evaluate_template_1.evaluateTemplate)(value, scope);
|
|
51
42
|
}
|
|
52
43
|
catch (err) {
|
|
53
44
|
throw new Error(`Failed to evaluate search param value: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-get.js","sourceRoot":"","sources":["../../../server/engine/task/http-get.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"http-get.js","sourceRoot":"","sources":["../../../server/engine/task/http-get.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,6BAAyB;AACzB,0DAAyB;AACzB,4DAAuD;AACvD,oDAA+C;AAC/C,8DAAyD;AACzD,mDAA+C;AAI/C,KAAK,UAAU,OAAO,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW;IAC7F,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,MAAM,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAE5F,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEzE,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAA;IAE7D,IAAI,CAAC;QACH,IAAI,GAAG,IAAA,oCAAgB,EAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI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import https from 'https'\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport { substitute } from './utils/substitute'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HttpGet(step: InputStep, { logger, data, domain, user, variables, lng }: Context) {\n var { connection: connectionName, params: stepOptions } = step\n var { headers: requestHeaders, searchParams = {}, path } = stepOptions || {}\n var connection = await 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 scope = { domain, user, lng, data, variables, console }\n\n try {\n path = evaluateTemplate(path, scope)\n } catch (err) {\n throw new Error(`Failed to evaluate path: ${err.message}`)\n }\n\n requestHeaders =\n requestHeaders &&\n Object.entries(requestHeaders as { [key: string]: string }).reduce((sum, [key, value]) => {\n try {\n sum[key] = evaluateTemplate(value, scope)\n } catch (err) {\n throw new Error(`Failed to evaluate header value: ${err.message}`)\n }\n return sum\n }, {})\n\n searchParams =\n searchParams &&\n Object.entries(searchParams as { [key: string]: string }).reduce((sum, [key, value]) => {\n try {\n sum[key] = evaluateTemplate(value, scope)\n } catch (err) {\n throw new Error(`Failed to evaluate search param value: ${err.message}`)\n }\n return sum\n }, {})\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 return {\n data:\n response.ok && response.headers.get('content-type').includes('application/json')\n ? await response.json()\n : await response.text()\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\nHttpGet.help = 'integration/task/http-get'\n\nTaskRegistry.registerTaskHandler('http-get', HttpGet)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
5
5
|
const url_1 = require("url");
|
|
6
|
-
require("ses");
|
|
7
6
|
const utils_1 = require("@things-factory/utils");
|
|
7
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
8
8
|
const task_registry_1 = require("../task-registry");
|
|
9
9
|
const connection_manager_1 = require("../connection-manager");
|
|
10
10
|
const https_1 = tslib_1.__importDefault(require("https"));
|
|
@@ -16,27 +16,18 @@ async function HttpPost(step, { logger, data, domain, user, variables, lng }) {
|
|
|
16
16
|
throw new Error(`connection '${connectionName}' is not established.`);
|
|
17
17
|
}
|
|
18
18
|
var { endpoint, params: connectionParams, authHeaders = {} } = connection;
|
|
19
|
-
const
|
|
20
|
-
domain,
|
|
21
|
-
user,
|
|
22
|
-
lng,
|
|
23
|
-
data,
|
|
24
|
-
variables,
|
|
25
|
-
console
|
|
26
|
-
});
|
|
27
|
-
let evalPath;
|
|
19
|
+
const scope = { domain, user, lng, data, variables, console };
|
|
28
20
|
try {
|
|
29
|
-
|
|
21
|
+
path = (0, evaluate_template_1.evaluateTemplate)(path, scope);
|
|
30
22
|
}
|
|
31
23
|
catch (err) {
|
|
32
24
|
throw new Error(`Failed to evaluate path: ${err.message}`);
|
|
33
25
|
}
|
|
34
|
-
path = evalPath;
|
|
35
26
|
requestHeaders =
|
|
36
27
|
requestHeaders &&
|
|
37
28
|
Object.entries(requestHeaders).reduce((sum, [key, value]) => {
|
|
38
29
|
try {
|
|
39
|
-
sum[key] =
|
|
30
|
+
sum[key] = (0, evaluate_template_1.evaluateTemplate)(value, scope);
|
|
40
31
|
}
|
|
41
32
|
catch (err) {
|
|
42
33
|
throw new Error(`Failed to evaluate header value: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-post.js","sourceRoot":"","sources":["../../../server/engine/task/http-post.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,6BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"http-post.js","sourceRoot":"","sources":["../../../server/engine/task/http-post.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,6BAAyB;AACzB,iDAA8C;AAC9C,4DAAuD;AACvD,oDAA+C;AAC/C,8DAAyD;AACzD,0DAAyB;AAIzB,KAAK,UAAU,QAAQ,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW;IAC9F,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAEhF,IAAI,UAAU,GAAG,MAAM,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAE5F,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEzE,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,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EAAE,EAAE;iBACV;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,KAAK,EAAE,kBAAkB;iBAC1B;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,KAAK,EAAE,YAAY;iBACpB;gBACD;oBACE,OAAO,EAAE,mCAAmC;oBAC5C,KAAK,EAAE,mCAAmC;iBAC3C;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,QAAQ,CAAC,IAAI,GAAG,4BAA4B,CAAA;AAE5C,4BAAY,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import fetch from 'node-fetch'\nimport { URL } from 'url'\nimport { access } from '@things-factory/utils'\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport https from 'https'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HttpPost(step: InputStep, { logger, data, domain, user, variables, lng }: Context) {\n var { connection: connectionName, params: stepOptions } = step\n var { headers: requestHeaders, contentType, path, accessor } = stepOptions || {}\n\n var connection = await 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 scope = { domain, user, lng, data, variables, console }\n\n try {\n path = evaluateTemplate(path, scope)\n } catch (err) {\n throw new Error(`Failed to evaluate path: ${err.message}`)\n }\n\n requestHeaders =\n requestHeaders &&\n Object.entries(requestHeaders as { [key: string]: string }).reduce((sum, [key, value]) => {\n try {\n sum[key] = evaluateTemplate(value, scope)\n } catch (err) {\n throw new Error(`Failed to evaluate header value: ${err.message}`)\n }\n return sum\n }, {})\n\n var url = new URL(path, endpoint)\n var headers = {\n ...authHeaders,\n ...requestHeaders\n }\n\n var body = access(accessor, data)\n if (contentType && body) {\n headers['content-type'] = contentType\n switch (contentType) {\n case 'text/plain':\n body = JSON.stringify(body)\n break\n case 'application/json':\n body = JSON.stringify(body)\n break\n case 'application/x-www-form-urlencoded':\n const searchParams = new URLSearchParams()\n for (const prop in body) {\n searchParams.set(prop, body[prop])\n }\n body = searchParams\n break\n }\n }\n\n var fetchOptions: any = {\n method: 'POST',\n headers,\n body\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 return {\n data:\n response.ok && response.headers.get('content-type').includes('application/json')\n ? await response.json()\n : await response.text()\n }\n}\n\nHttpPost.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: 'select',\n name: 'contentType',\n label: 'content-type',\n property: {\n options: [\n {\n display: '',\n value: ''\n },\n {\n display: 'application/json',\n value: 'application/json'\n },\n {\n display: 'text/plain',\n value: 'text/plain'\n },\n {\n display: 'application/x-www-form-urlencoded',\n value: 'application/x-www-form-urlencoded'\n }\n ]\n }\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n }\n]\n\nHttpPost.help = 'integration/task/http-post'\n\nTaskRegistry.registerTaskHandler('http-post', HttpPost)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
5
|
-
require("ses");
|
|
6
5
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
7
6
|
const shell_1 = require("@things-factory/shell");
|
|
8
7
|
const utils_1 = require("@things-factory/utils");
|
|
8
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
9
9
|
const task_registry_1 = require("../task-registry");
|
|
10
10
|
async function LocalGraphqlMutate(step, context) {
|
|
11
11
|
var { params, updaterId } = step;
|
|
@@ -17,17 +17,9 @@ async function LocalGraphqlMutate(step, context) {
|
|
|
17
17
|
where: { id: updaterId },
|
|
18
18
|
relations: ['domains']
|
|
19
19
|
}));
|
|
20
|
-
const compartment = new Compartment({
|
|
21
|
-
domain,
|
|
22
|
-
user,
|
|
23
|
-
lng,
|
|
24
|
-
data,
|
|
25
|
-
variables,
|
|
26
|
-
console
|
|
27
|
-
});
|
|
28
20
|
let evalMutation;
|
|
29
21
|
try {
|
|
30
|
-
evalMutation =
|
|
22
|
+
evalMutation = (0, evaluate_template_1.evaluateTemplate)(mutation, { domain, user, lng, data, variables, console });
|
|
31
23
|
}
|
|
32
24
|
catch (err) {
|
|
33
25
|
throw new Error(`Failed to evaluate mutation: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-graphql-mutate.js","sourceRoot":"","sources":["../../../server/engine/task/local-graphql-mutate.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;
|
|
1
|
+
{"version":3,"file":"local-graphql-mutate.js","sourceRoot":"","sources":["../../../server/engine/task/local-graphql-mutate.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;AAE7B,yDAAgD;AAChD,iDAAqD;AACrD,iDAA8C;AAE9C,4DAAuD;AACvD,oDAA+C;AAI/C,KAAK,UAAU,kBAAkB,CAAC,IAAe,EAAE,OAAgB;IACjE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;IAChC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IACzE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;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,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,YAAY;KACnB,CAAA;AACH,CAAC;AAED,kBAAkB,CAAC,aAAa,GAAG;IACjC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE;YACR,eAAe,EAAE,IAAI;SACtB;QACD,MAAM,EAAE;YACN,IAAI,EAAE,CAAC;SACR;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;CACF,CAAA;AAED,kBAAkB,CAAC,aAAa,GAAG,IAAI,CAAA;AACvC,kBAAkB,CAAC,IAAI,GAAG,uCAAuC,CAAA;AAEjE,4BAAY,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nimport { User } from '@things-factory/auth-base'\nimport { getRepository } from '@things-factory/shell'\nimport { access } from '@things-factory/utils'\n\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function LocalGraphqlMutate(step: InputStep, context: Context) {\n var { params, updaterId } = step\n var { mutation, variables: variablesAccessorMap, headers } = params || {}\n var { logger, client, domain, user, data, variables, lng } = context\n\n user =\n user ||\n (await getRepository(User).findOne({\n where: { id: updaterId },\n relations: ['domains']\n }))\n\n let evalMutation\n try {\n evalMutation = evaluateTemplate(mutation, { domain, user, lng, data, variables, console })\n } catch (err) {\n throw new Error(`Failed to evaluate mutation: ${err.message}`)\n }\n\n mutation = evalMutation\n\n const queryVariables = Object.keys(variablesAccessorMap || {}).reduce((variables, key) => {\n const accessor = variablesAccessorMap[key]\n variables[key] = access(accessor, data)\n return variables\n }, {})\n\n var { data: mutateResult, errors } = await client.mutate({\n mutation: gql`\n ${mutation}\n `,\n variables: queryVariables,\n headers,\n context: {\n state: {\n domain,\n user\n }\n }\n })\n\n if (errors) {\n errors.forEach(error => {\n logger.error('GraphQL Error: %s', error)\n })\n }\n\n return {\n data: mutateResult\n }\n}\n\nLocalGraphqlMutate.parameterSpec = [\n {\n type: 'graphql',\n name: 'mutation',\n label: 'mutation',\n property: {\n showLineNumbers: true\n },\n styles: {\n flex: 1\n }\n },\n {\n type: 'key-values',\n name: 'variables',\n label: 'variables'\n },\n {\n type: 'key-values',\n name: 'headers',\n label: 'headers'\n }\n]\n\nLocalGraphqlMutate.connectorFree = true\nLocalGraphqlMutate.help = 'integration/task/local-graphql-mutate'\n\nTaskRegistry.registerTaskHandler('local-graphql-mutate', LocalGraphqlMutate)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
5
|
-
require("ses");
|
|
6
5
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
7
6
|
const shell_1 = require("@things-factory/shell");
|
|
8
7
|
const utils_1 = require("@things-factory/utils");
|
|
8
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
9
9
|
const task_registry_1 = require("../task-registry");
|
|
10
10
|
async function LocalGraphqlQuery(step, context) {
|
|
11
11
|
var { params, updaterId } = step;
|
|
@@ -17,17 +17,9 @@ async function LocalGraphqlQuery(step, context) {
|
|
|
17
17
|
where: { id: updaterId },
|
|
18
18
|
relations: ['domains']
|
|
19
19
|
}));
|
|
20
|
-
const compartment = new Compartment({
|
|
21
|
-
domain,
|
|
22
|
-
user,
|
|
23
|
-
lng,
|
|
24
|
-
data,
|
|
25
|
-
variables,
|
|
26
|
-
console
|
|
27
|
-
});
|
|
28
20
|
let evalQuery;
|
|
29
21
|
try {
|
|
30
|
-
evalQuery =
|
|
22
|
+
evalQuery = (0, evaluate_template_1.evaluateTemplate)(query, { domain, user, lng, data, variables, console });
|
|
31
23
|
}
|
|
32
24
|
catch (err) {
|
|
33
25
|
throw new Error(`Failed to evaluate query: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-graphql-query.js","sourceRoot":"","sources":["../../../server/engine/task/local-graphql-query.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;
|
|
1
|
+
{"version":3,"file":"local-graphql-query.js","sourceRoot":"","sources":["../../../server/engine/task/local-graphql-query.ts"],"names":[],"mappings":";;;AAAA,sEAA6B;AAE7B,yDAAgD;AAChD,iDAAqD;AACrD,iDAA8C;AAE9C,4DAAuD;AACvD,oDAA+C;AAI/C,KAAK,UAAU,iBAAiB,CAAC,IAAe,EAAE,OAAgB;IAChE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;IAChC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IACtE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;IAEpE,IAAI;QACF,IAAI;YACJ,CAAC,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,OAAO,CAAC;gBACjC,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE;gBACxB,SAAS,EAAE,CAAC,SAAS,CAAC;aACvB,CAAC,CAAC,CAAA;IAEL,IAAI,SAAS,CAAA;IACb,IAAI,CAAC;QACH,SAAS,GAAG,IAAA,oCAAgB,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EA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EAAE,CAAC;SACR;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;CACF,CAAA;AAED,iBAAiB,CAAC,aAAa,GAAG,IAAI,CAAA;AACtC,iBAAiB,CAAC,IAAI,GAAG,sCAAsC,CAAA;AAE/D,4BAAY,CAAC,mBAAmB,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nimport { User } from '@things-factory/auth-base'\nimport { getRepository } from '@things-factory/shell'\nimport { access } from '@things-factory/utils'\n\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function LocalGraphqlQuery(step: InputStep, context: Context) {\n var { params, updaterId } = step\n var { query, variables: variablesAccessorMap, headers } = params || {}\n var { logger, client, domain, user, data, variables, lng } = context\n\n user =\n user ||\n (await getRepository(User).findOne({\n where: { id: updaterId },\n relations: ['domains']\n }))\n\n let evalQuery\n try {\n evalQuery = evaluateTemplate(query, { domain, user, lng, data, variables, console })\n } catch (err) {\n throw new Error(`Failed to evaluate query: ${err.message}`)\n }\n\n query = evalQuery\n\n const queryVariables = Object.keys(variablesAccessorMap || {}).reduce((variables, key) => {\n const accessor = variablesAccessorMap[key]\n variables[key] = access(accessor, data)\n return variables\n }, {})\n\n var { data: queryResult, errors } = await client.query({\n query: gql`\n ${query}\n `,\n variables: queryVariables,\n headers,\n context: {\n state: {\n domain,\n user\n }\n }\n })\n\n if (errors) {\n errors.forEach(error => {\n logger.error('GraphQL Error: %s', error)\n })\n }\n\n return {\n data: queryResult\n }\n}\n\nLocalGraphqlQuery.parameterSpec = [\n {\n type: 'graphql',\n name: 'query',\n label: 'query',\n property: {\n showLineNumbers: true\n },\n styles: {\n flex: 1\n }\n },\n {\n type: 'key-values',\n name: 'variables',\n label: 'variables'\n },\n {\n type: 'key-values',\n name: 'headers',\n label: 'headers'\n }\n]\n\nLocalGraphqlQuery.connectorFree = true\nLocalGraphqlQuery.help = 'integration/task/local-graphql-query'\n\nTaskRegistry.registerTaskHandler('local-graphql-query', LocalGraphqlQuery)\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("@things-factory/utils");
|
|
4
|
-
require("
|
|
4
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
5
5
|
const task_registry_1 = require("../task-registry");
|
|
6
6
|
async function Log(step, { logger, data, variables, domain, user, lng }) {
|
|
7
7
|
var { params: { message, accessor, level = 'info' } } = step;
|
|
8
8
|
if ((0, utils_1.hasTemplateExpression)(message)) {
|
|
9
|
-
const compartment = new Compartment({
|
|
10
|
-
domain,
|
|
11
|
-
user,
|
|
12
|
-
lng,
|
|
13
|
-
data,
|
|
14
|
-
variables,
|
|
15
|
-
console
|
|
16
|
-
});
|
|
17
9
|
try {
|
|
18
|
-
message =
|
|
10
|
+
message = (0, evaluate_template_1.evaluateTemplate)(message, { domain, user, lng, data, variables, console });
|
|
19
11
|
}
|
|
20
12
|
catch (err) {
|
|
21
13
|
throw new Error(`Failed to evaluate message: ${err.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../server/engine/task/log.ts"],"names":[],"mappings":";;AAAA,iDAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../server/engine/task/log.ts"],"names":[],"mappings":";;AAAA,iDAAqE;AACrE,4DAAuD;AACvD,oDAA+C;AAI/C,KAAK,UAAU,GAAG,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE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QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE;YACR,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;SACnC;KACF;CACF,CAAA;AAED,GAAG,CAAC,aAAa,GAAG,IAAI,CAAA;AACxB,GAAG,CAAC,IAAI,GAAG,sBAAsB,CAAA;AAEjC,4BAAY,CAAC,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA","sourcesContent":["import { access, hasTemplateExpression } from '@things-factory/utils'\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function Log(step: InputStep, { logger, data, variables, domain, user, lng }: Context) {\n var {\n params: { message, accessor, level = 'info' }\n } = step\n\n if (hasTemplateExpression(message)) {\n try {\n message = evaluateTemplate(message, { domain, user, lng, data, variables, console })\n } catch (err) {\n throw new Error(`Failed to evaluate message: ${err.message}`)\n }\n }\n\n accessor = access(accessor, data)\n\n if (accessor) {\n if (typeof accessor !== 'string') {\n accessor = JSON.stringify(accessor, null, 2)\n }\n message += ': ' + accessor\n }\n\n switch (level) {\n case 'error':\n logger.error(message)\n return\n case 'warn':\n logger.warn(message)\n return\n default:\n logger.info(message)\n }\n\n return {\n data: message\n }\n}\n\nLog.parameterSpec = [\n {\n type: 'string',\n name: 'message',\n label: 'message'\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n },\n {\n type: 'select',\n name: 'level',\n label: 'level',\n property: {\n options: ['info', 'warn', 'error']\n }\n }\n]\n\nLog.connectorFree = true\nLog.help = 'integration/task/log'\n\nTaskRegistry.registerTaskHandler('log', Log)\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MsSqlExecQuery = MsSqlExecQuery;
|
|
4
4
|
const connection_manager_1 = require("../connection-manager");
|
|
5
|
+
const evaluate_template_1 = require("../evaluate-template");
|
|
5
6
|
const task_registry_1 = require("../task-registry");
|
|
6
|
-
require("ses");
|
|
7
7
|
/** 결과셋 표준화 */
|
|
8
8
|
function normalizeRecordsets(raw, maxRowsPerSet) {
|
|
9
9
|
let sets = [];
|
|
@@ -32,9 +32,8 @@ async function MsSqlExecQuery(step, context) {
|
|
|
32
32
|
request.multiple = true;
|
|
33
33
|
request.timeout = 30000; // 30초
|
|
34
34
|
const maxRowsPerSet = 1000; // 결과셋별 최대 1000행
|
|
35
|
-
const compartment = new Compartment({ domain, user, lng, data, variables, console });
|
|
36
35
|
try {
|
|
37
|
-
const evalQuery =
|
|
36
|
+
const evalQuery = (0, evaluate_template_1.evaluateTemplate)(params.query.replace(/`/g, '\\`'), { domain, user, lng, data, variables, console });
|
|
38
37
|
const raw = await request.query(evalQuery);
|
|
39
38
|
const recordsets = normalizeRecordsets(raw, maxRowsPerSet);
|
|
40
39
|
return { data: recordsets }; // ✅ 전체 결과셋 배열만 반환
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mssql-exec-query.js","sourceRoot":"","sources":["../../../server/engine/task/mssql-exec-query.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mssql-exec-query.js","sourceRoot":"","sources":["../../../server/engine/task/mssql-exec-query.ts"],"names":[],"mappings":";;AA+DS,wCAAc;AA/DvB,8DAAyD;AACzD,4DAAuD;AACvD,oDAA+C;AAQ/C,cAAc;AACd,SAAS,mBAAmB,CAAC,GAAQ,EAAE,aAAqB;IAC1D,IAAI,IAAI,GAAY,EAAE,CAAA;IACtB,IAAI,GAAG,EAAE,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACrD,IAAI,GAAG,GAAG,CAAC,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IAAI,CAAA,CAAC,gBAAgB;IAE3C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAA,oCAAgB,EAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QACtH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC1C,MAAM,UAAU,GAAG,mBAAmB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QAC1D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA,CAAC,kBAAkB;IAChD,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC;AAED,cAAc,CAAC,aAAa,GAAG;IAC7B;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,YAAY;QACnB,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE;QACpD,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE;KACtB;CACF,CAAA;AAED,cAAc,CAAC,IAAI,GAAG,mCAAmC,CAAA;AAEzD,4BAAY,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAA","sourcesContent":["import { ConnectionManager } from '../connection-manager'\nimport { evaluateTemplate } from '../evaluate-template'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\ntype Params = {\n query: string // EXEC … 구문 전체 (WITH RESULT SETS 포함 가능)\n}\n\n/** 결과셋 표준화 */\nfunction normalizeRecordsets(raw: any, maxRowsPerSet: number): any[][] {\n let sets: any[][] = []\n if (raw?.recordsets && Array.isArray(raw.recordsets)) {\n sets = raw.recordsets\n } else if (Array.isArray(raw)) {\n sets = raw\n } else if (raw?.recordset) {\n sets = [raw.recordset]\n } else {\n sets = [[raw]]\n }\n return sets.map(s => (Array.isArray(s) ? s.slice(0, maxRowsPerSet) : s))\n}\n\nasync function MsSqlExecQuery(step: InputStep & { params: Params }, context: Context) {\n const { domain, user, data, variables, lng } = context\n const { connection: connectionName, params } = step\n\n const db = await ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n const sql = db.sql || require('mssql')\n const pool = db.pool || (await sql.connect(db.config))\n const request = pool.request()\n\n // ✅ 고정값 설정\n request.multiple = true\n request.timeout = 30000 // 30초\n const maxRowsPerSet = 1000 // 결과셋별 최대 1000행\n\n try {\n const evalQuery = evaluateTemplate(params.query.replace(/`/g, '\\\\`'), { domain, user, lng, data, variables, console })\n const raw = await request.query(evalQuery)\n const recordsets = normalizeRecordsets(raw, maxRowsPerSet)\n return { data: recordsets } // ✅ 전체 결과셋 배열만 반환\n } catch (err: any) {\n throw new Error(`MSSQL exec query failed: ${err.message}`)\n }\n}\n\nMsSqlExecQuery.parameterSpec = [\n {\n type: 'textarea',\n name: 'query',\n label: 'EXEC Query',\n property: { language: 'sql', showLineNumbers: true },\n styles: { flex: '1' }\n }\n]\n\nMsSqlExecQuery.help = 'integration/task/mssql-exec-query'\n\nTaskRegistry.registerTaskHandler('mssql-exec-query', MsSqlExecQuery)\n\nexport { MsSqlExecQuery }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|