@things-factory/integration-base 9.2.24 → 9.2.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/dist-server/engine/connector/headless-connector.js +56 -8
- package/dist-server/engine/connector/headless-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +10 -2
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/task/utils/headless-request-with-recovery.js +44 -2
- package/dist-server/engine/task/utils/headless-request-with-recovery.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -43,6 +43,14 @@ class HeadlessConnector {
|
|
|
43
43
|
.filter(Boolean)
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
// 연결 시점의 인증 설정 상태 로깅 (자격증명 미해석으로 loginRequired=false가 되는 문제 진단용)
|
|
47
|
+
connection_manager_1.ConnectionManager.logger.info(`[HeadlessConnector] connect '${connection.name}' — loginRequired: ${loginInfo.loginRequired}, ` +
|
|
48
|
+
`loginPagePath: ${loginPagePath}, hasPassword: ${Boolean(password)}, ` +
|
|
49
|
+
`hasCachedCookies: ${Boolean(connection.cookies)}`);
|
|
50
|
+
if (!loginInfo.loginRequired) {
|
|
51
|
+
connection_manager_1.ConnectionManager.logger.warn(`[HeadlessConnector] connection '${connection.name}' has NO username — login will be SKIPPED entirely. ` +
|
|
52
|
+
`If this endpoint requires auth, check that credentials are resolved (getResolvedParameters).`);
|
|
53
|
+
}
|
|
46
54
|
async function acquireBrowser() {
|
|
47
55
|
try {
|
|
48
56
|
const pool = (0, headless_pool_1.getHeadlessPool)();
|
|
@@ -147,13 +155,36 @@ class HeadlessConnector {
|
|
|
147
155
|
connection_manager_1.ConnectionManager.logger.info('User is already logged in, skipping login process.');
|
|
148
156
|
return page;
|
|
149
157
|
}
|
|
158
|
+
// 캐시된 쿠키로 세션 복원 시도
|
|
159
|
+
// 주의: isCookieValid는 만료시간만 확인하므로, 서버측에서 무효화된(죽은) 쿠키도 통과함.
|
|
160
|
+
// 쿠키 적용 후 실제로 로그인 상태가 유지되는지(로그인 페이지로 튕기지 않는지) 반드시 검증하고,
|
|
161
|
+
// 실패하면 신규 로그인으로 폴백한다.
|
|
162
|
+
let sessionRestored = false;
|
|
150
163
|
if (cookies && isCookieValid(cookies)) {
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
try {
|
|
165
|
+
await this.applyCookiesAndVerifySession(page, cookies, loginInfo);
|
|
166
|
+
const urlAfterCookie = page.url();
|
|
167
|
+
const loginPagePaths = [loginInfo.loginPagePath, '/login', '/signin', '/intro.do'].filter(Boolean);
|
|
168
|
+
if (loginPagePaths.some(path => urlAfterCookie.includes(path))) {
|
|
169
|
+
connection_manager_1.ConnectionManager.logger.warn(`[Session] Cached cookies rejected by server for connection '${connection.name}' — ` +
|
|
170
|
+
`landed on login page after reload (URL: ${urlAfterCookie}). Falling back to fresh login.`);
|
|
171
|
+
connection.cookies = null;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
connection_manager_1.ConnectionManager.logger.info(`[Session] Session restored from ${cookies.length} cached cookies for connection '${connection.name}' (URL: ${urlAfterCookie})`);
|
|
175
|
+
sessionRestored = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (cookieError) {
|
|
179
|
+
connection_manager_1.ConnectionManager.logger.warn(`[Session] Cookie session reuse failed for connection '${connection.name}': ${cookieError.message}. Falling back to fresh login.`);
|
|
180
|
+
connection.cookies = null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!sessionRestored) {
|
|
184
|
+
await this.performLogin(page, uri, loginInfo);
|
|
185
|
+
cookies = await page.cookies();
|
|
186
|
+
connection.cookies = cookies;
|
|
153
187
|
}
|
|
154
|
-
await this.performLogin(page, uri, loginInfo);
|
|
155
|
-
cookies = await page.cookies();
|
|
156
|
-
connection.cookies = cookies;
|
|
157
188
|
}
|
|
158
189
|
else {
|
|
159
190
|
// 로그인이 필요하지 않은 경우에도 기본 페이지로 이동
|
|
@@ -469,7 +500,13 @@ class HeadlessConnector {
|
|
|
469
500
|
if (response) {
|
|
470
501
|
const status = response.status();
|
|
471
502
|
if (status >= 200 && status < 400) {
|
|
472
|
-
|
|
503
|
+
// 로그인 응답이 2xx/3xx여도 실제로는 실패 페이지(아이디/비밀번호 오류 등)로 떨어질 수 있으므로 최종 URL을 함께 기록
|
|
504
|
+
const postLoginUrl = page.url();
|
|
505
|
+
connection_manager_1.ConnectionManager.logger.info(`Login successful with status code: ${status} — post-login URL: ${postLoginUrl}`);
|
|
506
|
+
if (postLoginUrl.includes(loginInfo.loginPagePath)) {
|
|
507
|
+
connection_manager_1.ConnectionManager.logger.warn(`Login response was ${status} but page is still on login page (${postLoginUrl}) — ` +
|
|
508
|
+
`credentials may be wrong, or the site requires additional steps (captcha, keyboard security, OTP).`);
|
|
509
|
+
}
|
|
473
510
|
return;
|
|
474
511
|
}
|
|
475
512
|
else if (status >= 400) {
|
|
@@ -487,15 +524,26 @@ class HeadlessConnector {
|
|
|
487
524
|
}
|
|
488
525
|
}
|
|
489
526
|
catch (error) {
|
|
490
|
-
|
|
527
|
+
// 실패 시점의 페이지 상태(URL/타이틀)를 함께 기록하여 셀렉터 불일치, 보안모듈, 리디렉션 등 원인 추적 가능하게 함
|
|
528
|
+
let failureContext = '';
|
|
529
|
+
try {
|
|
530
|
+
const failUrl = page.url();
|
|
531
|
+
const failTitle = await page.title().catch(() => 'unknown');
|
|
532
|
+
failureContext = ` (URL: ${failUrl}, title: ${failTitle})`;
|
|
533
|
+
}
|
|
534
|
+
catch (contextError) {
|
|
535
|
+
failureContext = ' (failed to capture page state)';
|
|
536
|
+
}
|
|
537
|
+
connection_manager_1.ConnectionManager.logger.warn(`Login attempt ${attempt}/${loginInfo.retries} failed${failureContext}:`, error);
|
|
491
538
|
try {
|
|
492
539
|
await page.screenshot({ path: `logs/login-failure-attempt-${attempt}.png` });
|
|
540
|
+
connection_manager_1.ConnectionManager.logger.info(`Login failure screenshot saved: logs/login-failure-attempt-${attempt}.png`);
|
|
493
541
|
}
|
|
494
542
|
catch (error) {
|
|
495
543
|
connection_manager_1.ConnectionManager.logger.error('Failed to capture screenshot:', error);
|
|
496
544
|
}
|
|
497
545
|
if (attempt === loginInfo.retries) {
|
|
498
|
-
throw new Error(`Login failed after ${loginInfo.retries} attempts`);
|
|
546
|
+
throw new Error(`Login failed after ${loginInfo.retries} attempts: ${error.message}${failureContext}`);
|
|
499
547
|
}
|
|
500
548
|
}
|
|
501
549
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/headless-connector.ts"],"names":[],"mappings":";;;AAAA,8DAAyD;AAEzD,kEAA8E;AAG9E;;;;;;;;;;EAUE;AAEF,MAAa,iBAAiB;IAC5B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjE,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;IAC3E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAU;QACtB,MAAM,EACJ,QAAQ,EAAE,GAAG,GAAG,GAAG,EACnB,MAAM,EAAE,EACN,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,EAAE,EACb,aAAa,GAAG,QAAQ,EACxB,WAAW,GAAG,IAAI,EAClB,gBAAgB,GAAG,WAAW,EAC9B,gBAAgB,GAAG,WAAW,EAC9B,cAAc,GAAG,SAAS,EAC1B,eAAe,GAAG,IAAI,EACtB,kBAAkB,GAAG,EAAE,EAAE,uCAAuC;QAChE,OAAO,GAAG,KAAK,EAAE,iCAAiC;QAClD,OAAO,GAAG,CAAC,CAAC,sDAAsD;UACnE,GAAG,EAAE,EACP,GAAG,UAAU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AAE,kBAAkB;aAC1B;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,oBAAoB;gBAC1B,KAAK,EAAE,sBAAsB;aAC9B;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,KAAK;aACb;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,iBAAiB;gBACxB,KAAK,EAAE,CAAC;aACT;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,iDAAiD,CAAA;IAC1D,CAAC;IAED,IAAI,IAAI;QACN,OAAO,0CAA0C,CAAA;IACnD,CAAC;CACF;AA/qBD,8CA+qBC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,IAAI,iBAAiB,EAAE,CAAC,CAAA;AAElF,SAAS,aAAa,CAAC,OAAc;IACnC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,0BAA0B;IACxD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { getHeadlessPool, getPoolStats } from '../resource-pool/headless-pool'\nimport { Browser, Page } from 'puppeteer'\n\n/*\n Functionality of the headless-connector:\n - Provides a mechanism to acquire an active session page.\n - Performs login when necessary to obtain valid cookies.\n - Applies these cookies to the page for session management.\n - Pages are acquired from the `headlessPool`, which manages browser instances.\n - During the login process, pages from the pool are used for actions like form filling and navigation.\n - Valid cookies are saved after login and reused for subsequent page acquisitions.\n - Users must explicitly release the page after use through the `releasePage` method.\n - Released pages are returned to the `headlessPool` for reuse.\n*/\n\nexport class HeadlessConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n ConnectionManager.logger.info('headless-connector connections are ready')\n }\n\n async connect(connection) {\n const {\n endpoint: uri = '1',\n params: {\n username = '',\n password = '',\n loginPagePath = '/login',\n loginApiUrl = null,\n usernameSelector = '#username',\n passwordSelector = '#password',\n submitSelector = '#submit',\n successSelector = null,\n shadowDomSelectors = '', // Comma separated shadow DOM selectors\n timeout = 15000, // Default timeout for operations\n retries = 3 // Default number of retries for login or page actions\n } = {}\n } = connection\n\n const loginInfo = {\n loginRequired: Boolean(username), // Determine if login is required\n username,\n password,\n loginPagePath,\n loginApiUrl,\n timeout,\n retries,\n loginSelectors: {\n usernameSelector,\n passwordSelector,\n submitSelector,\n successSelector,\n shadowDomSelectors: shadowDomSelectors\n .split(',')\n .map(selector => selector.trim())\n .filter(Boolean)\n }\n }\n\n async function acquireBrowser() {\n try {\n const pool = getHeadlessPool()\n \n // Pool 상태 모니터링 (디버깅용)\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats before acquire - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats:', statsError)\n }\n \n const browser = await pool.acquire()\n ConnectionManager.logger.info('Browser acquired successfully from pool')\n return browser\n } catch (error) {\n ConnectionManager.logger.error('Failed to acquire browser from pool:', error)\n \n // 풀 상태 로깅으로 디버깅 도움\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.error(`Pool stats during acquire error - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}, max: ${stats.max}`)\n } catch (statsError) {\n ConnectionManager.logger.error('Failed to get pool stats during error:', statsError)\n }\n \n throw error\n }\n }\n\n async function releaseBrowser(browser: Browser) {\n if (!browser) {\n ConnectionManager.logger.warn('Attempted to release null/undefined browser')\n return\n }\n\n try {\n // 브라우저가 아직 연결되어 있는지 확인\n if (!browser.isConnected()) {\n ConnectionManager.logger.warn('Attempted to release disconnected browser')\n return\n }\n\n // Pool 상태 모니터링 (릴리즈 전)\n try {\n const statsBefore = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats before release - borrowed: ${statsBefore.borrowed}, available: ${statsBefore.available}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats before release:', statsError)\n }\n\n const pool = getHeadlessPool()\n await pool.release(browser)\n ConnectionManager.logger.info('Browser successfully released to pool')\n \n // Pool 상태 모니터링 (릴리즈 후)\n try {\n const statsAfter = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats after release - borrowed: ${statsAfter.borrowed}, available: ${statsAfter.available}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats after release:', statsError)\n }\n } catch (error) {\n ConnectionManager.logger.error('Failed to release browser to pool:', error)\n \n // 에러 발생시 풀 상태 로깅\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.error(`Pool stats during release error - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}`)\n } catch (statsError) {\n ConnectionManager.logger.error('Failed to get pool stats during release error:', statsError)\n }\n \n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser && browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser after pool release failure:', forceCloseError)\n }\n }\n }\n\n ConnectionManager.addConnectionInstance(connection, {\n endpoint: connection.endpoint,\n params: connection.params,\n acquireSessionPage: async () => {\n const browser = await acquireBrowser()\n let page\n let cookies = connection.cookies\n\n try {\n page = await browser.newPage()\n await this.setupPage(page, uri, timeout)\n\n if (loginInfo.loginRequired) {\n // 먼저 기본 페이지로 이동\n await page.goto(uri, { waitUntil: 'networkidle2', timeout })\n\n // 현재 세션의 Authorization 헤더 확인\n const headers = await page.evaluate(() => {\n return fetch(window.location.href, { method: 'GET' })\n .then(response => response.headers.get('Authorization'))\n .catch(() => null)\n })\n\n if (headers) {\n ConnectionManager.logger.info('User is already logged in, skipping login process.')\n return page\n }\n\n if (cookies && isCookieValid(cookies)) {\n await this.applyCookiesAndVerifySession(page, cookies, loginInfo)\n return page\n }\n\n await this.performLogin(page, uri, loginInfo)\n cookies = await page.cookies()\n connection.cookies = cookies\n } else {\n // 로그인이 필요하지 않은 경우에도 기본 페이지로 이동\n await page.goto(uri, { waitUntil: 'networkidle2', timeout })\n }\n\n return page\n } catch (error) {\n ConnectionManager.logger.error('Failed to acquire session page:', error)\n \n // CRITICAL: 에러 발생 시 확실한 리소스 정리\n if (page) {\n try {\n await page.close()\n ConnectionManager.logger.info('Page closed during acquireSessionPage error handling')\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page during acquireSessionPage error:', closeError)\n }\n }\n \n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released during acquireSessionPage error handling')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser during acquireSessionPage error:', releaseError)\n }\n \n throw error\n }\n },\n releasePage: async (page: Page) => {\n try {\n if (page && !page.isClosed()) {\n const browser = page.browser()\n \n // 페이지를 먼저 닫기\n try {\n await page.close()\n ConnectionManager.logger.info('Page closed successfully')\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page:', closeError)\n }\n \n // 브라우저를 풀에 반환\n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released successfully')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser:', releaseError)\n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser && browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser:', forceCloseError)\n }\n }\n }\n } catch (error) {\n ConnectionManager.logger.error('Critical error in releasePage:', error)\n }\n },\n // 세션 회복을 위한 재로그인 메서드\n reAuthenticateSession: async () => {\n ConnectionManager.logger.info(`Re-authenticating session for connection: ${connection.name}`)\n \n let browser = null\n let page = null\n\n try {\n browser = await acquireBrowser()\n page = await browser.newPage()\n await this.setupPage(page, uri, loginInfo.timeout)\n \n if (loginInfo.loginRequired) {\n await this.performLogin(page, uri, loginInfo)\n const newCookies = await page.cookies()\n connection.cookies = newCookies\n ConnectionManager.logger.info(`Session re-authenticated successfully for connection: ${connection.name}`)\n }\n \n // CRITICAL: 페이지와 함께 브라우저 정보도 반환하여 정확한 릴리즈 추적\n return {\n page,\n browser,\n requiresManualRelease: true // 수동 릴리즈 필요 표시\n }\n } catch (error) {\n ConnectionManager.logger.error(`Failed to re-authenticate session for connection: ${connection.name}`, error)\n \n // 에러 시 확실한 리소스 정리\n if (page) {\n try {\n if (!page.isClosed()) {\n await page.close()\n ConnectionManager.logger.info('Page closed during reauth error handling')\n }\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page during reauth error:', closeError)\n }\n }\n \n if (browser) {\n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released during reauth error handling')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser during reauth error:', releaseError)\n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser during reauth error due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser during reauth error:', forceCloseError)\n }\n }\n }\n \n throw error\n }\n },\n // 세션 유효성 검사\n validateSession: async (page: Page) => {\n try {\n if (!loginInfo.loginRequired) {\n return true\n }\n\n // 페이지가 닫혔거나 연결이 끊어진 경우\n if (!page || page.isClosed()) {\n ConnectionManager.logger.warn(`Page is closed or null for connection: ${connection.name}`)\n return false\n }\n\n // URL 기반 로그인 리디렉션 체크\n let currentUrl: string\n try {\n currentUrl = page.url()\n } catch (urlError) {\n ConnectionManager.logger.warn(`Cannot get page URL for connection: ${connection.name}`, urlError)\n return false\n }\n \n if (currentUrl.includes(loginInfo.loginPagePath) || \n currentUrl.includes('/login') || \n currentUrl.includes('/signin') || \n currentUrl.includes('/auth')) {\n ConnectionManager.logger.info(`Redirected to login page: ${currentUrl}`)\n return false\n }\n\n // 로그인 폼 요소 기반 체크\n const needsLogin = await page.evaluate(() => {\n try {\n // 로그인 페이지 특정 요소들이 있는지 확인\n const loginIndicators = ['#username', '#password', '.login-form', '[type=\"password\"]']\n return loginIndicators.some(selector => {\n const element = document.querySelector(selector) as HTMLElement\n return element && element.offsetParent !== null // 보이는 요소만 체크\n })\n } catch (evalError) {\n return true // 에러 시 안전하게 재로그인 필요로 간주\n }\n })\n\n // 추가 세션 검증: 간단한 API 호출로 인증 상태 확인\n try {\n const testResponse = await page.evaluate(async () => {\n try {\n const response = await fetch(window.location.origin, { \n method: 'HEAD',\n credentials: 'include'\n })\n return {\n status: response.status,\n ok: response.ok\n }\n } catch (fetchError) {\n return { status: 0, ok: false }\n }\n })\n \n // 인증이 필요한 엔드포인트에서 401/403 반환시 세션 무효\n if (testResponse.status === 401 || testResponse.status === 403) {\n ConnectionManager.logger.info(`Authentication failed with status ${testResponse.status} for connection: ${connection.name}`)\n return false\n }\n } catch (apiTestError) {\n ConnectionManager.logger.warn(`Session API test failed for connection: ${connection.name}`, apiTestError)\n // API 테스트 실패는 세션 무효로 간주하지 않음 (네트워크 문제일 수 있음)\n }\n\n return !needsLogin\n } catch (error) {\n ConnectionManager.logger.warn(`Session validation failed for connection: ${connection.name}`, error)\n return false\n }\n },\n acquireBrowser,\n releaseBrowser\n })\n\n ConnectionManager.logger.info(\n `headless-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async setupPage(page, uri, timeout) {\n await page.setRequestInterception(true)\n\n await page.setBypassCSP(true)\n\n await page.setUserAgent(\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.204 Safari/537.36'\n )\n\n await page.evaluateOnNewDocument(() => {\n Object.defineProperty(navigator, 'webdriver', { get: () => false })\n })\n\n await page.setExtraHTTPHeaders({\n 'Upgrade-Insecure-Requests': '0',\n 'accept-language': 'en-US,en;q=0.9',\n referer: uri\n })\n\n await page.setDefaultNavigationTimeout(timeout)\n\n page.on('console', async msg => {\n ConnectionManager.logger.info(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('request', request => {\n if (request.isInterceptResolutionHandled()) {\n return\n }\n\n const resourceType = request.resourceType()\n\n // fetch(), XMLHttpRequest 등의 API 호출은 항상 허용\n if (resourceType === 'fetch' || resourceType === 'xhr') {\n request.continue()\n return\n }\n\n const headers = request.headers()\n if (headers['access-control-request-headers']) {\n const filteredHeaders = headers['access-control-request-headers']\n .split(',')\n .map(header => header.trim())\n .filter(header => header.toLowerCase() !== 'upgrade-insecure-requests')\n\n if (filteredHeaders.length > 0) {\n headers['access-control-request-headers'] = filteredHeaders.join(', ')\n } else {\n delete headers['access-control-request-headers']\n }\n }\n\n if (headers['upgrade-insecure-requests']) {\n delete headers['upgrade-insecure-requests']\n }\n\n // 이미지, 스타일시트, 폰트는 차단하되 API 요청은 허용\n if (['image', 'stylesheet', 'font'].includes(resourceType)) {\n request.abort()\n } else {\n request.continue()\n }\n })\n\n page.on('requestfailed', request => {\n try {\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 if (request.postData()) {\n console.log(`- Post Data: ${request.postData()}`)\n }\n } catch (error) {\n console.error('Error in requestfailed handler:', error)\n }\n })\n }\n\n async applyCookiesAndVerifySession(page, cookies, loginInfo) {\n await page.setCookie(...cookies)\n await page.reload({ waitUntil: 'networkidle2', timeout: loginInfo.timeout })\n\n if (loginInfo.loginRequired && loginInfo.loginSelectors.successSelector) {\n const success = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.successSelector\n )\n if (!success) {\n throw new Error('Session invalid, login required')\n }\n }\n }\n\n async performLogin(page, uri, loginInfo) {\n for (let attempt = 1; attempt <= loginInfo.retries; attempt++) {\n try {\n await page.goto(`${uri}${loginInfo.loginPagePath}`, { waitUntil: 'networkidle2', timeout: loginInfo.timeout })\n\n const usernameInput = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.usernameSelector\n )\n const passwordInput = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.passwordSelector\n )\n const submitButton = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.submitSelector\n )\n\n if (!usernameInput || !passwordInput || !submitButton) {\n throw new Error('Failed to locate input elements in shadow DOM')\n }\n\n await usernameInput.type(loginInfo.username)\n await passwordInput.type(loginInfo.password)\n\n var loginApiUrl =\n loginInfo.loginApiUrl ||\n (await page.evaluate(button => {\n const form = button.closest('form')\n return form ? form.action : null\n }, submitButton))\n\n if (loginApiUrl && !loginApiUrl.startsWith('http')) {\n loginApiUrl = `${uri}${loginApiUrl}`\n }\n\n if (!loginApiUrl) {\n throw new Error('❌ Unable to detect login API URL!')\n }\n\n console.log('✅ Detected login API URL:', loginApiUrl)\n\n const [response] = await Promise.all([\n page.waitForResponse(response => {\n const url = response.url()\n const method = response.request().method()\n\n return url === loginApiUrl && method === 'POST' && [200, 201, 204, 302, 304].includes(response.status())\n }),\n page.evaluate(button => button.click(), submitButton),\n page.waitForNavigation({ waitUntil: 'networkidle2', timeout: loginInfo.timeout }) // 로그인 후 리디렉션 감지\n ])\n\n if (response) {\n const status = response.status()\n if (status >= 200 && status < 400) {\n ConnectionManager.logger.info(`Login successful with status code: ${status}`)\n return\n } else if (status >= 400) {\n throw new Error(`Login failed with status code: ${status}`)\n }\n } else {\n throw new Error('No response received during login')\n }\n\n if (loginInfo.loginSelectors.successSelector) {\n const success = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.successSelector\n )\n if (!success) {\n throw new Error('Login failed: Success selector not found')\n }\n }\n } catch (error) {\n ConnectionManager.logger.warn(`Login attempt ${attempt} failed:`, error)\n\n try {\n await page.screenshot({ path: `logs/login-failure-attempt-${attempt}.png` })\n } catch (error) {\n ConnectionManager.logger.error('Failed to capture screenshot:', error)\n }\n\n if (attempt === loginInfo.retries) {\n throw new Error(`Login failed after ${loginInfo.retries} attempts`)\n }\n }\n }\n }\n\n async resolveShadowDom(page, shadowSelectors, targetSelector) {\n let context\n\n if (!shadowSelectors || shadowSelectors.length === 0) {\n // No Shadow DOM path; use document root as the context\n context = page.mainFrame() // Puppeteer uses frames to represent document\n return context.$(targetSelector) // Search directly in the document root\n }\n\n context = page // Start with the page as the context\n for (const selector of shadowSelectors) {\n const shadowHost = await context.$(selector)\n if (!shadowHost) {\n throw new Error(`Shadow host not found: ${selector}`)\n }\n context = await page.evaluateHandle(host => host.shadowRoot, shadowHost)\n }\n return context.evaluateHandle((shadowRoot, selector) => shadowRoot.querySelector(selector), targetSelector)\n }\n\n async disconnect(connection) {\n try {\n // 연결 해제 전 리소스 정리 로그\n ConnectionManager.logger.info(`Starting disconnect process for connection: ${connection.name}`)\n \n // 풀 상태 확인 (정보성 로깅)\n try {\n const pool = getHeadlessPool()\n ConnectionManager.logger.info(`Pool status before disconnect - available resources exist: ${!!pool}`)\n } catch (poolError) {\n ConnectionManager.logger.warn(`Could not access pool during disconnect: ${poolError.message}`)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n ConnectionManager.logger.info(`headless-connector connection(${connection.name}) is disconnected`)\n } catch (error) {\n ConnectionManager.logger.error(`Error disconnecting headless-connector connection(${connection.name}):`, error)\n // Still try to remove the connection instance even if cleanup failed\n try {\n ConnectionManager.removeConnectionInstance(connection)\n } catch (removeError) {\n ConnectionManager.logger.error(`Failed to remove connection instance ${connection.name}:`, removeError)\n }\n }\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'username',\n label: 'username',\n useDomainAttribute: true\n },\n {\n type: 'secret',\n name: 'password',\n label: 'password',\n useDomainAttribute: true\n },\n {\n type: 'string',\n name: 'loginPagePath',\n label: 'login-page-path'\n },\n {\n type: 'string',\n name: 'loginApiUrl',\n label: 'login-api-url'\n },\n {\n type: 'string',\n name: 'usernameSelector',\n label: 'username-selector'\n },\n {\n type: 'string',\n name: 'passwordSelector',\n label: 'password-selector'\n },\n {\n type: 'string',\n name: 'submitSelector',\n label: 'submit-selector'\n },\n {\n type: 'string',\n name: 'successSelector',\n label: 'success-selector'\n },\n {\n type: 'string',\n name: 'shadowDomSelectors',\n label: 'shadow-dom-selectors'\n },\n {\n type: 'number',\n name: 'timeout',\n label: 'timeout',\n value: 15000\n },\n {\n type: 'number',\n name: 'retries',\n label: 'maximum-retries',\n value: 3\n }\n ]\n }\n\n get taskPrefixes() {\n return ['headless']\n }\n\n get description() {\n return 'Headless Pool Connector with login capabilities'\n }\n\n get help() {\n return 'integration/connector/headless-connector'\n }\n}\n\nConnectionManager.registerConnector('headless-connector', new HeadlessConnector())\n\nfunction isCookieValid(cookies: any[]): boolean {\n if (!cookies || cookies.length === 0) return false\n const now = Date.now() / 1000 // Current time in seconds\n return cookies.some((cookie: any) => cookie.expires && cookie.expires > now)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"headless-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/headless-connector.ts"],"names":[],"mappings":";;;AAAA,8DAAyD;AAEzD,kEAA8E;AAG9E;;;;;;;;;;EAUE;AAEF,MAAa,iBAAiB;IAC5B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,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AC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { getHeadlessPool, getPoolStats } from '../resource-pool/headless-pool'\nimport { Browser, Page } from 'puppeteer'\n\n/*\n Functionality of the headless-connector:\n - Provides a mechanism to acquire an active session page.\n - Performs login when necessary to obtain valid cookies.\n - Applies these cookies to the page for session management.\n - Pages are acquired from the `headlessPool`, which manages browser instances.\n - During the login process, pages from the pool are used for actions like form filling and navigation.\n - Valid cookies are saved after login and reused for subsequent page acquisitions.\n - Users must explicitly release the page after use through the `releasePage` method.\n - Released pages are returned to the `headlessPool` for reuse.\n*/\n\nexport class HeadlessConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n ConnectionManager.logger.info('headless-connector connections are ready')\n }\n\n async connect(connection) {\n const {\n endpoint: uri = '1',\n params: {\n username = '',\n password = '',\n loginPagePath = '/login',\n loginApiUrl = null,\n usernameSelector = '#username',\n passwordSelector = '#password',\n submitSelector = '#submit',\n successSelector = null,\n shadowDomSelectors = '', // Comma separated shadow DOM selectors\n timeout = 15000, // Default timeout for operations\n retries = 3 // Default number of retries for login or page actions\n } = {}\n } = connection\n\n const loginInfo = {\n loginRequired: Boolean(username), // Determine if login is required\n username,\n password,\n loginPagePath,\n loginApiUrl,\n timeout,\n retries,\n loginSelectors: {\n usernameSelector,\n passwordSelector,\n submitSelector,\n successSelector,\n shadowDomSelectors: shadowDomSelectors\n .split(',')\n .map(selector => selector.trim())\n .filter(Boolean)\n }\n }\n\n // 연결 시점의 인증 설정 상태 로깅 (자격증명 미해석으로 loginRequired=false가 되는 문제 진단용)\n ConnectionManager.logger.info(\n `[HeadlessConnector] connect '${connection.name}' — loginRequired: ${loginInfo.loginRequired}, ` +\n `loginPagePath: ${loginPagePath}, hasPassword: ${Boolean(password)}, ` +\n `hasCachedCookies: ${Boolean(connection.cookies)}`\n )\n if (!loginInfo.loginRequired) {\n ConnectionManager.logger.warn(\n `[HeadlessConnector] connection '${connection.name}' has NO username — login will be SKIPPED entirely. ` +\n `If this endpoint requires auth, check that credentials are resolved (getResolvedParameters).`\n )\n }\n\n async function acquireBrowser() {\n try {\n const pool = getHeadlessPool()\n \n // Pool 상태 모니터링 (디버깅용)\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats before acquire - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats:', statsError)\n }\n \n const browser = await pool.acquire()\n ConnectionManager.logger.info('Browser acquired successfully from pool')\n return browser\n } catch (error) {\n ConnectionManager.logger.error('Failed to acquire browser from pool:', error)\n \n // 풀 상태 로깅으로 디버깅 도움\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.error(`Pool stats during acquire error - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}, max: ${stats.max}`)\n } catch (statsError) {\n ConnectionManager.logger.error('Failed to get pool stats during error:', statsError)\n }\n \n throw error\n }\n }\n\n async function releaseBrowser(browser: Browser) {\n if (!browser) {\n ConnectionManager.logger.warn('Attempted to release null/undefined browser')\n return\n }\n\n try {\n // 브라우저가 아직 연결되어 있는지 확인\n if (!browser.isConnected()) {\n ConnectionManager.logger.warn('Attempted to release disconnected browser')\n return\n }\n\n // Pool 상태 모니터링 (릴리즈 전)\n try {\n const statsBefore = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats before release - borrowed: ${statsBefore.borrowed}, available: ${statsBefore.available}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats before release:', statsError)\n }\n\n const pool = getHeadlessPool()\n await pool.release(browser)\n ConnectionManager.logger.info('Browser successfully released to pool')\n \n // Pool 상태 모니터링 (릴리즈 후)\n try {\n const statsAfter = getPoolStats()\n ConnectionManager.logger.debug(`Pool stats after release - borrowed: ${statsAfter.borrowed}, available: ${statsAfter.available}`)\n } catch (statsError) {\n ConnectionManager.logger.warn('Failed to get pool stats after release:', statsError)\n }\n } catch (error) {\n ConnectionManager.logger.error('Failed to release browser to pool:', error)\n \n // 에러 발생시 풀 상태 로깅\n try {\n const stats = getPoolStats()\n ConnectionManager.logger.error(`Pool stats during release error - borrowed: ${stats.borrowed}, available: ${stats.available}, pending: ${stats.pending}`)\n } catch (statsError) {\n ConnectionManager.logger.error('Failed to get pool stats during release error:', statsError)\n }\n \n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser && browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser after pool release failure:', forceCloseError)\n }\n }\n }\n\n ConnectionManager.addConnectionInstance(connection, {\n endpoint: connection.endpoint,\n params: connection.params,\n acquireSessionPage: async () => {\n const browser = await acquireBrowser()\n let page\n let cookies = connection.cookies\n\n try {\n page = await browser.newPage()\n await this.setupPage(page, uri, timeout)\n\n if (loginInfo.loginRequired) {\n // 먼저 기본 페이지로 이동\n await page.goto(uri, { waitUntil: 'networkidle2', timeout })\n\n // 현재 세션의 Authorization 헤더 확인\n const headers = await page.evaluate(() => {\n return fetch(window.location.href, { method: 'GET' })\n .then(response => response.headers.get('Authorization'))\n .catch(() => null)\n })\n\n if (headers) {\n ConnectionManager.logger.info('User is already logged in, skipping login process.')\n return page\n }\n\n // 캐시된 쿠키로 세션 복원 시도\n // 주의: isCookieValid는 만료시간만 확인하므로, 서버측에서 무효화된(죽은) 쿠키도 통과함.\n // 쿠키 적용 후 실제로 로그인 상태가 유지되는지(로그인 페이지로 튕기지 않는지) 반드시 검증하고,\n // 실패하면 신규 로그인으로 폴백한다.\n let sessionRestored = false\n if (cookies && isCookieValid(cookies)) {\n try {\n await this.applyCookiesAndVerifySession(page, cookies, loginInfo)\n\n const urlAfterCookie = page.url()\n const loginPagePaths = [loginInfo.loginPagePath, '/login', '/signin', '/intro.do'].filter(Boolean)\n if (loginPagePaths.some(path => urlAfterCookie.includes(path))) {\n ConnectionManager.logger.warn(\n `[Session] Cached cookies rejected by server for connection '${connection.name}' — ` +\n `landed on login page after reload (URL: ${urlAfterCookie}). Falling back to fresh login.`\n )\n connection.cookies = null\n } else {\n ConnectionManager.logger.info(\n `[Session] Session restored from ${cookies.length} cached cookies for connection '${connection.name}' (URL: ${urlAfterCookie})`\n )\n sessionRestored = true\n }\n } catch (cookieError) {\n ConnectionManager.logger.warn(\n `[Session] Cookie session reuse failed for connection '${connection.name}': ${cookieError.message}. Falling back to fresh login.`\n )\n connection.cookies = null\n }\n }\n\n if (!sessionRestored) {\n await this.performLogin(page, uri, loginInfo)\n cookies = await page.cookies()\n connection.cookies = cookies\n }\n } else {\n // 로그인이 필요하지 않은 경우에도 기본 페이지로 이동\n await page.goto(uri, { waitUntil: 'networkidle2', timeout })\n }\n\n return page\n } catch (error) {\n ConnectionManager.logger.error('Failed to acquire session page:', error)\n \n // CRITICAL: 에러 발생 시 확실한 리소스 정리\n if (page) {\n try {\n await page.close()\n ConnectionManager.logger.info('Page closed during acquireSessionPage error handling')\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page during acquireSessionPage error:', closeError)\n }\n }\n \n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released during acquireSessionPage error handling')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser during acquireSessionPage error:', releaseError)\n }\n \n throw error\n }\n },\n releasePage: async (page: Page) => {\n try {\n if (page && !page.isClosed()) {\n const browser = page.browser()\n \n // 페이지를 먼저 닫기\n try {\n await page.close()\n ConnectionManager.logger.info('Page closed successfully')\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page:', closeError)\n }\n \n // 브라우저를 풀에 반환\n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released successfully')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser:', releaseError)\n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser && browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser:', forceCloseError)\n }\n }\n }\n } catch (error) {\n ConnectionManager.logger.error('Critical error in releasePage:', error)\n }\n },\n // 세션 회복을 위한 재로그인 메서드\n reAuthenticateSession: async () => {\n ConnectionManager.logger.info(`Re-authenticating session for connection: ${connection.name}`)\n \n let browser = null\n let page = null\n\n try {\n browser = await acquireBrowser()\n page = await browser.newPage()\n await this.setupPage(page, uri, loginInfo.timeout)\n \n if (loginInfo.loginRequired) {\n await this.performLogin(page, uri, loginInfo)\n const newCookies = await page.cookies()\n connection.cookies = newCookies\n ConnectionManager.logger.info(`Session re-authenticated successfully for connection: ${connection.name}`)\n }\n \n // CRITICAL: 페이지와 함께 브라우저 정보도 반환하여 정확한 릴리즈 추적\n return {\n page,\n browser,\n requiresManualRelease: true // 수동 릴리즈 필요 표시\n }\n } catch (error) {\n ConnectionManager.logger.error(`Failed to re-authenticate session for connection: ${connection.name}`, error)\n \n // 에러 시 확실한 리소스 정리\n if (page) {\n try {\n if (!page.isClosed()) {\n await page.close()\n ConnectionManager.logger.info('Page closed during reauth error handling')\n }\n } catch (closeError) {\n ConnectionManager.logger.error('Failed to close page during reauth error:', closeError)\n }\n }\n \n if (browser) {\n try {\n await releaseBrowser(browser)\n ConnectionManager.logger.info('Browser released during reauth error handling')\n } catch (releaseError) {\n ConnectionManager.logger.error('Failed to release browser during reauth error:', releaseError)\n // 풀 릴리즈가 실패한 경우 브라우저 강제 종료 시도\n try {\n if (browser.isConnected()) {\n await browser.close()\n ConnectionManager.logger.warn('Forcibly closed browser during reauth error due to pool release failure')\n }\n } catch (forceCloseError) {\n ConnectionManager.logger.error('Failed to force close browser during reauth error:', forceCloseError)\n }\n }\n }\n \n throw error\n }\n },\n // 세션 유효성 검사\n validateSession: async (page: Page) => {\n try {\n if (!loginInfo.loginRequired) {\n return true\n }\n\n // 페이지가 닫혔거나 연결이 끊어진 경우\n if (!page || page.isClosed()) {\n ConnectionManager.logger.warn(`Page is closed or null for connection: ${connection.name}`)\n return false\n }\n\n // URL 기반 로그인 리디렉션 체크\n let currentUrl: string\n try {\n currentUrl = page.url()\n } catch (urlError) {\n ConnectionManager.logger.warn(`Cannot get page URL for connection: ${connection.name}`, urlError)\n return false\n }\n \n if (currentUrl.includes(loginInfo.loginPagePath) || \n currentUrl.includes('/login') || \n currentUrl.includes('/signin') || \n currentUrl.includes('/auth')) {\n ConnectionManager.logger.info(`Redirected to login page: ${currentUrl}`)\n return false\n }\n\n // 로그인 폼 요소 기반 체크\n const needsLogin = await page.evaluate(() => {\n try {\n // 로그인 페이지 특정 요소들이 있는지 확인\n const loginIndicators = ['#username', '#password', '.login-form', '[type=\"password\"]']\n return loginIndicators.some(selector => {\n const element = document.querySelector(selector) as HTMLElement\n return element && element.offsetParent !== null // 보이는 요소만 체크\n })\n } catch (evalError) {\n return true // 에러 시 안전하게 재로그인 필요로 간주\n }\n })\n\n // 추가 세션 검증: 간단한 API 호출로 인증 상태 확인\n try {\n const testResponse = await page.evaluate(async () => {\n try {\n const response = await fetch(window.location.origin, { \n method: 'HEAD',\n credentials: 'include'\n })\n return {\n status: response.status,\n ok: response.ok\n }\n } catch (fetchError) {\n return { status: 0, ok: false }\n }\n })\n \n // 인증이 필요한 엔드포인트에서 401/403 반환시 세션 무효\n if (testResponse.status === 401 || testResponse.status === 403) {\n ConnectionManager.logger.info(`Authentication failed with status ${testResponse.status} for connection: ${connection.name}`)\n return false\n }\n } catch (apiTestError) {\n ConnectionManager.logger.warn(`Session API test failed for connection: ${connection.name}`, apiTestError)\n // API 테스트 실패는 세션 무효로 간주하지 않음 (네트워크 문제일 수 있음)\n }\n\n return !needsLogin\n } catch (error) {\n ConnectionManager.logger.warn(`Session validation failed for connection: ${connection.name}`, error)\n return false\n }\n },\n acquireBrowser,\n releaseBrowser\n })\n\n ConnectionManager.logger.info(\n `headless-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async setupPage(page, uri, timeout) {\n await page.setRequestInterception(true)\n\n await page.setBypassCSP(true)\n\n await page.setUserAgent(\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.204 Safari/537.36'\n )\n\n await page.evaluateOnNewDocument(() => {\n Object.defineProperty(navigator, 'webdriver', { get: () => false })\n })\n\n await page.setExtraHTTPHeaders({\n 'Upgrade-Insecure-Requests': '0',\n 'accept-language': 'en-US,en;q=0.9',\n referer: uri\n })\n\n await page.setDefaultNavigationTimeout(timeout)\n\n page.on('console', async msg => {\n ConnectionManager.logger.info(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('request', request => {\n if (request.isInterceptResolutionHandled()) {\n return\n }\n\n const resourceType = request.resourceType()\n\n // fetch(), XMLHttpRequest 등의 API 호출은 항상 허용\n if (resourceType === 'fetch' || resourceType === 'xhr') {\n request.continue()\n return\n }\n\n const headers = request.headers()\n if (headers['access-control-request-headers']) {\n const filteredHeaders = headers['access-control-request-headers']\n .split(',')\n .map(header => header.trim())\n .filter(header => header.toLowerCase() !== 'upgrade-insecure-requests')\n\n if (filteredHeaders.length > 0) {\n headers['access-control-request-headers'] = filteredHeaders.join(', ')\n } else {\n delete headers['access-control-request-headers']\n }\n }\n\n if (headers['upgrade-insecure-requests']) {\n delete headers['upgrade-insecure-requests']\n }\n\n // 이미지, 스타일시트, 폰트는 차단하되 API 요청은 허용\n if (['image', 'stylesheet', 'font'].includes(resourceType)) {\n request.abort()\n } else {\n request.continue()\n }\n })\n\n page.on('requestfailed', request => {\n try {\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 if (request.postData()) {\n console.log(`- Post Data: ${request.postData()}`)\n }\n } catch (error) {\n console.error('Error in requestfailed handler:', error)\n }\n })\n }\n\n async applyCookiesAndVerifySession(page, cookies, loginInfo) {\n await page.setCookie(...cookies)\n await page.reload({ waitUntil: 'networkidle2', timeout: loginInfo.timeout })\n\n if (loginInfo.loginRequired && loginInfo.loginSelectors.successSelector) {\n const success = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.successSelector\n )\n if (!success) {\n throw new Error('Session invalid, login required')\n }\n }\n }\n\n async performLogin(page, uri, loginInfo) {\n for (let attempt = 1; attempt <= loginInfo.retries; attempt++) {\n try {\n await page.goto(`${uri}${loginInfo.loginPagePath}`, { waitUntil: 'networkidle2', timeout: loginInfo.timeout })\n\n const usernameInput = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.usernameSelector\n )\n const passwordInput = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.passwordSelector\n )\n const submitButton = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.submitSelector\n )\n\n if (!usernameInput || !passwordInput || !submitButton) {\n throw new Error('Failed to locate input elements in shadow DOM')\n }\n\n await usernameInput.type(loginInfo.username)\n await passwordInput.type(loginInfo.password)\n\n var loginApiUrl =\n loginInfo.loginApiUrl ||\n (await page.evaluate(button => {\n const form = button.closest('form')\n return form ? form.action : null\n }, submitButton))\n\n if (loginApiUrl && !loginApiUrl.startsWith('http')) {\n loginApiUrl = `${uri}${loginApiUrl}`\n }\n\n if (!loginApiUrl) {\n throw new Error('❌ Unable to detect login API URL!')\n }\n\n console.log('✅ Detected login API URL:', loginApiUrl)\n\n const [response] = await Promise.all([\n page.waitForResponse(response => {\n const url = response.url()\n const method = response.request().method()\n\n return url === loginApiUrl && method === 'POST' && [200, 201, 204, 302, 304].includes(response.status())\n }),\n page.evaluate(button => button.click(), submitButton),\n page.waitForNavigation({ waitUntil: 'networkidle2', timeout: loginInfo.timeout }) // 로그인 후 리디렉션 감지\n ])\n\n if (response) {\n const status = response.status()\n if (status >= 200 && status < 400) {\n // 로그인 응답이 2xx/3xx여도 실제로는 실패 페이지(아이디/비밀번호 오류 등)로 떨어질 수 있으므로 최종 URL을 함께 기록\n const postLoginUrl = page.url()\n ConnectionManager.logger.info(\n `Login successful with status code: ${status} — post-login URL: ${postLoginUrl}`\n )\n if (postLoginUrl.includes(loginInfo.loginPagePath)) {\n ConnectionManager.logger.warn(\n `Login response was ${status} but page is still on login page (${postLoginUrl}) — ` +\n `credentials may be wrong, or the site requires additional steps (captcha, keyboard security, OTP).`\n )\n }\n return\n } else if (status >= 400) {\n throw new Error(`Login failed with status code: ${status}`)\n }\n } else {\n throw new Error('No response received during login')\n }\n\n if (loginInfo.loginSelectors.successSelector) {\n const success = await this.resolveShadowDom(\n page,\n loginInfo.loginSelectors.shadowDomSelectors,\n loginInfo.loginSelectors.successSelector\n )\n if (!success) {\n throw new Error('Login failed: Success selector not found')\n }\n }\n } catch (error) {\n // 실패 시점의 페이지 상태(URL/타이틀)를 함께 기록하여 셀렉터 불일치, 보안모듈, 리디렉션 등 원인 추적 가능하게 함\n let failureContext = ''\n try {\n const failUrl = page.url()\n const failTitle = await page.title().catch(() => 'unknown')\n failureContext = ` (URL: ${failUrl}, title: ${failTitle})`\n } catch (contextError) {\n failureContext = ' (failed to capture page state)'\n }\n ConnectionManager.logger.warn(`Login attempt ${attempt}/${loginInfo.retries} failed${failureContext}:`, error)\n\n try {\n await page.screenshot({ path: `logs/login-failure-attempt-${attempt}.png` })\n ConnectionManager.logger.info(`Login failure screenshot saved: logs/login-failure-attempt-${attempt}.png`)\n } catch (error) {\n ConnectionManager.logger.error('Failed to capture screenshot:', error)\n }\n\n if (attempt === loginInfo.retries) {\n throw new Error(`Login failed after ${loginInfo.retries} attempts: ${error.message}${failureContext}`)\n }\n }\n }\n }\n\n async resolveShadowDom(page, shadowSelectors, targetSelector) {\n let context\n\n if (!shadowSelectors || shadowSelectors.length === 0) {\n // No Shadow DOM path; use document root as the context\n context = page.mainFrame() // Puppeteer uses frames to represent document\n return context.$(targetSelector) // Search directly in the document root\n }\n\n context = page // Start with the page as the context\n for (const selector of shadowSelectors) {\n const shadowHost = await context.$(selector)\n if (!shadowHost) {\n throw new Error(`Shadow host not found: ${selector}`)\n }\n context = await page.evaluateHandle(host => host.shadowRoot, shadowHost)\n }\n return context.evaluateHandle((shadowRoot, selector) => shadowRoot.querySelector(selector), targetSelector)\n }\n\n async disconnect(connection) {\n try {\n // 연결 해제 전 리소스 정리 로그\n ConnectionManager.logger.info(`Starting disconnect process for connection: ${connection.name}`)\n \n // 풀 상태 확인 (정보성 로깅)\n try {\n const pool = getHeadlessPool()\n ConnectionManager.logger.info(`Pool status before disconnect - available resources exist: ${!!pool}`)\n } catch (poolError) {\n ConnectionManager.logger.warn(`Could not access pool during disconnect: ${poolError.message}`)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n ConnectionManager.logger.info(`headless-connector connection(${connection.name}) is disconnected`)\n } catch (error) {\n ConnectionManager.logger.error(`Error disconnecting headless-connector connection(${connection.name}):`, error)\n // Still try to remove the connection instance even if cleanup failed\n try {\n ConnectionManager.removeConnectionInstance(connection)\n } catch (removeError) {\n ConnectionManager.logger.error(`Failed to remove connection instance ${connection.name}:`, removeError)\n }\n }\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'username',\n label: 'username',\n useDomainAttribute: true\n },\n {\n type: 'secret',\n name: 'password',\n label: 'password',\n useDomainAttribute: true\n },\n {\n type: 'string',\n name: 'loginPagePath',\n label: 'login-page-path'\n },\n {\n type: 'string',\n name: 'loginApiUrl',\n label: 'login-api-url'\n },\n {\n type: 'string',\n name: 'usernameSelector',\n label: 'username-selector'\n },\n {\n type: 'string',\n name: 'passwordSelector',\n label: 'password-selector'\n },\n {\n type: 'string',\n name: 'submitSelector',\n label: 'submit-selector'\n },\n {\n type: 'string',\n name: 'successSelector',\n label: 'success-selector'\n },\n {\n type: 'string',\n name: 'shadowDomSelectors',\n label: 'shadow-dom-selectors'\n },\n {\n type: 'number',\n name: 'timeout',\n label: 'timeout',\n value: 15000\n },\n {\n type: 'number',\n name: 'retries',\n label: 'maximum-retries',\n value: 3\n }\n ]\n }\n\n get taskPrefixes() {\n return ['headless']\n }\n\n get description() {\n return 'Headless Pool Connector with login capabilities'\n }\n\n get help() {\n return 'integration/connector/headless-connector'\n }\n}\n\nConnectionManager.registerConnector('headless-connector', new HeadlessConnector())\n\nfunction isCookieValid(cookies: any[]): boolean {\n if (!cookies || cookies.length === 0) return false\n const now = Date.now() / 1000 // Current time in seconds\n return cookies.some((cookie: any) => cookie.expires && cookie.expires > now)\n}\n"]}
|
|
@@ -165,9 +165,17 @@ class OperatoConnector {
|
|
|
165
165
|
if (!tag) {
|
|
166
166
|
throw new Error(`tag is invalid - ${tag}`);
|
|
167
167
|
}
|
|
168
|
-
const
|
|
168
|
+
const subscription = subscriptions.find(subscription => subscription.tag === tag);
|
|
169
|
+
if (!subscription) {
|
|
170
|
+
throw new Error(`subscription is not found - ${tag}`);
|
|
171
|
+
}
|
|
172
|
+
/* 매번 DB에서 최신 시나리오를 조회하여 시나리오 수정 시 재연결 없이 반영 */
|
|
173
|
+
const scenario = await (0, shell_1.getRepository)(scenario_1.Scenario).findOne({
|
|
174
|
+
where: { id: subscription.scenario.id },
|
|
175
|
+
relations: ['steps', 'domain']
|
|
176
|
+
});
|
|
169
177
|
if (!scenario) {
|
|
170
|
-
throw new Error(`scenario is not found - ${tag}`);
|
|
178
|
+
throw new Error(`scenario is not found in DB - ${tag}`);
|
|
171
179
|
}
|
|
172
180
|
if (!(await (0, auth_base_1.checkUserHasRole)(scenario.roleId, domain, user))) {
|
|
173
181
|
throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAkE;AAElE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEnF,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;AAEY,QAAA,WAAW,GAAG,UAAU,CAAA;AACxB,QAAA,gBAAgB,GAAG,mBAAW,CAAA;AAQ3C,MAAa,gBAAgB;IAG3B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAA2B;QACvC,MAAM,EACJ,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,GAAG,EAAE,EAAE,EACvD,GAAG,UAAU,CAAA;QAEd,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;QACtD,C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AAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,iBAAiB,QAAQ,CAAC,IAAI,8BAA8B,CAAC,CAAA;QAC/E,CAAC;QAED,gCAAgC;QAChC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAC7D,MAAM,QAAQ,GAAG,IAAI,yCAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE;YAC5D,IAAI;YACJ,MAAM;YACN,SAAS;YACT,MAAM,EAAE,0BAAkB,CAAC,MAAM;SAClC,CAAC,CAAA;QAEF,eAAe;QACf,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAA;QACpB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,IAAI,aAAa;QACf,OAAO;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,UAAU;gBACjB,kBAAkB,EAAE,IAAI;aACzB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,QAAQ;aAChB;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AAtOD,4CAsOC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","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'\nimport gql from 'graphql-tag'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport { Scenario } from '../../service/scenario/scenario'\nimport { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'\n\nimport { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'\nimport { User, checkUserHasRole } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\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\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\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': domain,\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': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n const tags = Object.keys(subscriptionHandlers).filter(tag => tag && subscriptionHandlers[tag])\n\n /* 시나리오 조회 및 subscription 등록을 순차적으로 처리 */\n for (const tag of tags) {\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n /* 시나리오가 DB에 없으면 경고 로그를 남기고 건너뜀 */\n if (!selectedScenario) {\n ConnectionManager.logger.warn(\n `(${connection.name}) scenario not found for tag \"${tag}\" (scenarioName: \"${scenarioName}\") - skipping subscription`\n )\n continue\n }\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n /* subscription 수신 시 에러가 발생해도 프로세스가 죽지 않도록 catch 처리 */\n try {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n } catch (e) {\n ConnectionManager.logger.error(`(${connection.name}:${tag}) runScenario failed`, e)\n }\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(\n `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`\n )\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n }\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user } = this.context\n const { tag } = variables\n\n if (!tag) {\n throw new Error(`tag is invalid - ${tag}`)\n }\n\n const scenario = subscriptions.find(subscription => subscription.tag === tag)?.scenario\n if (!scenario) {\n throw new Error(`scenario is not found - ${tag}`)\n }\n\n if (!(await checkUserHasRole(scenario.roleId, domain, user))) {\n throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)\n }\n\n /* create a scenario instance */\n const instanceName = scenario.name + '-' + String(Date.now())\n const instance = new ScenarioInstance(instanceName, scenario, {\n user,\n domain,\n variables,\n client: GraphqlLocalClient.client\n })\n\n // run scenario\n await instance.run()\n return instance\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'authKey',\n label: 'auth-key',\n useDomainAttribute: true\n },\n {\n type: 'string',\n name: 'domain',\n label: 'domain'\n },\n {\n type: 'tag-scenarios',\n name: 'subscriptionHandlers',\n label: 'subscription-handlers'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get help() {\n return 'integration/connector/operato-connector'\n }\n\n get description() {\n return 'Operato Graphql Connector'\n }\n}\n\nConnectionManager.registerConnector('operato-connector', new OperatoConnector())\n"]}
|
|
1
|
+
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAkE;AAElE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEnF,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;AAEY,QAAA,WAAW,GAAG,UAAU,CAAA;AACxB,QAAA,gBAAgB,GAAG,mBAAW,CAAA;AAQ3C,MAAa,gBAAgB;IAG3B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;IAC1E,CA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AAK,EAAE,UAAU;gBACjB,kBAAkB,EAAE,IAAI;aACzB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,QAAQ;aAChB;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AAhPD,4CAgPC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","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'\nimport gql from 'graphql-tag'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport { Scenario } from '../../service/scenario/scenario'\nimport { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'\n\nimport { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'\nimport { User, checkUserHasRole } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\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\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\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': domain,\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': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n const tags = Object.keys(subscriptionHandlers).filter(tag => tag && subscriptionHandlers[tag])\n\n /* 시나리오 조회 및 subscription 등록을 순차적으로 처리 */\n for (const tag of tags) {\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n /* 시나리오가 DB에 없으면 경고 로그를 남기고 건너뜀 */\n if (!selectedScenario) {\n ConnectionManager.logger.warn(\n `(${connection.name}) scenario not found for tag \"${tag}\" (scenarioName: \"${scenarioName}\") - skipping subscription`\n )\n continue\n }\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n /* subscription 수신 시 에러가 발생해도 프로세스가 죽지 않도록 catch 처리 */\n try {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n } catch (e) {\n ConnectionManager.logger.error(`(${connection.name}:${tag}) runScenario failed`, e)\n }\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(\n `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`\n )\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n }\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user } = this.context\n const { tag } = variables\n\n if (!tag) {\n throw new Error(`tag is invalid - ${tag}`)\n }\n\n const subscription = subscriptions.find(subscription => subscription.tag === tag)\n if (!subscription) {\n throw new Error(`subscription is not found - ${tag}`)\n }\n\n /* 매번 DB에서 최신 시나리오를 조회하여 시나리오 수정 시 재연결 없이 반영 */\n const scenario = await getRepository(Scenario).findOne({\n where: { id: subscription.scenario.id },\n relations: ['steps', 'domain']\n })\n\n if (!scenario) {\n throw new Error(`scenario is not found in DB - ${tag}`)\n }\n\n if (!(await checkUserHasRole(scenario.roleId, domain, user))) {\n throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)\n }\n\n /* create a scenario instance */\n const instanceName = scenario.name + '-' + String(Date.now())\n const instance = new ScenarioInstance(instanceName, scenario as any, {\n user,\n domain,\n variables,\n client: GraphqlLocalClient.client\n })\n\n // run scenario\n await instance.run()\n return instance\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'authKey',\n label: 'auth-key',\n useDomainAttribute: true\n },\n {\n type: 'string',\n name: 'domain',\n label: 'domain'\n },\n {\n type: 'tag-scenarios',\n name: 'subscriptionHandlers',\n label: 'subscription-handlers'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get help() {\n return 'integration/connector/operato-connector'\n }\n\n get description() {\n return 'Operato Graphql Connector'\n }\n}\n\nConnectionManager.registerConnector('operato-connector', new OperatoConnector())\n"]}
|
|
@@ -503,6 +503,17 @@ async function performFullConnectionReset(domain, connectionName, logger, pageRe
|
|
|
503
503
|
if (!connector) {
|
|
504
504
|
throw new Error(`Connector not found for type: ${type}`);
|
|
505
505
|
}
|
|
506
|
+
// CRITICAL: 캐시된 엔티티에 남아있는 쿠키 제거
|
|
507
|
+
// 서버측에서 세션이 무효화된 경우 쿠키는 만료시간상 유효해 보여도 죽은 쿠키이므로,
|
|
508
|
+
// 이를 지우지 않으면 acquireSessionPage가 로그인을 건너뛰고 죽은 쿠키를 재사용하여 reset이 무의미해짐
|
|
509
|
+
const staleCookies = connectionEntity.cookies;
|
|
510
|
+
if (staleCookies) {
|
|
511
|
+
logger.info(`[Reset] Clearing ${Array.isArray(staleCookies) ? staleCookies.length : '?'} cached cookies on connection entity to force fresh login`);
|
|
512
|
+
connectionEntity.cookies = null;
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
logger.info(`[Reset] No cached cookies on connection entity — fresh login will be performed`);
|
|
516
|
+
}
|
|
506
517
|
// 기존 연결 완전 해제
|
|
507
518
|
await connector.disconnect(connectionEntity);
|
|
508
519
|
logger.info(`Connection '${connectionName}' disconnected for reset`);
|
|
@@ -511,8 +522,19 @@ async function performFullConnectionReset(domain, connectionName, logger, pageRe
|
|
|
511
522
|
// 코드에서는 즉시 연결을 시도하므로 명시적 대기 필요
|
|
512
523
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
513
524
|
// 새로운 연결 생성 (완전한 초기화)
|
|
514
|
-
|
|
515
|
-
|
|
525
|
+
// CRITICAL: connector.connect(entity)를 직접 호출하면 getResolvedParameters()를 거치지 않아
|
|
526
|
+
// 자격증명(username/password)이 해석되지 않은 채 연결될 수 있음 → loginRequired=false로 로그인 자체가 생략됨.
|
|
527
|
+
// 반드시 엔티티의 connect()를 사용하여 해석된 파라미터로 연결한다.
|
|
528
|
+
if (typeof connectionEntity.connect === 'function') {
|
|
529
|
+
await connectionEntity.connect();
|
|
530
|
+
logger.info(`Connection '${connectionName}' reconnected after reset (with resolved credentials)`);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
logger.warn(`[Reset] connectionEntity.connect() not available — falling back to raw connector.connect(). ` +
|
|
534
|
+
`Credentials may not be resolved (loginRequired could be false).`);
|
|
535
|
+
await connector.connect(connectionEntity);
|
|
536
|
+
logger.info(`Connection '${connectionName}' reconnected after reset`);
|
|
537
|
+
}
|
|
516
538
|
// 새 브라우저 인스턴스 초기화 대기
|
|
517
539
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
518
540
|
// 새로운 connection 인스턴스 가져오기
|
|
@@ -533,6 +555,26 @@ async function performFullConnectionReset(domain, connectionName, logger, pageRe
|
|
|
533
555
|
}
|
|
534
556
|
// 새 페이지 안정화 대기 (핵심!)
|
|
535
557
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
558
|
+
// [디버그] reset 후 페이지 상태 상세 검증
|
|
559
|
+
const postResetUrl = newPage.url();
|
|
560
|
+
const postResetCookies = await newPage.cookies();
|
|
561
|
+
logger.info(`[Debug][Reset] Post-reset page — URL: ${postResetUrl}, Cookies: ${postResetCookies.length} [${postResetCookies.map((c) => `${c.name}(${c.domain}, path=${c.path}, httpOnly=${c.httpOnly}, secure=${c.secure})`).join(', ')}]`);
|
|
562
|
+
// reset 후 로그인 페이지로 떨어져 있으면 connect() 자체가 인증 실패한 것
|
|
563
|
+
const loginPagePath = newConnection.params?.loginPagePath || '/login';
|
|
564
|
+
if (postResetUrl.includes(loginPagePath) ||
|
|
565
|
+
postResetUrl.includes('/login') ||
|
|
566
|
+
postResetUrl.includes('/signin') ||
|
|
567
|
+
postResetUrl.includes('/intro.do')) {
|
|
568
|
+
logger.error(`[Debug][Reset] connect() 후에도 로그인 페이지에 머물러 있음 — URL: ${postResetUrl}. connector.connect() 인증 실패 가능성 높음`);
|
|
569
|
+
}
|
|
570
|
+
// validateSession이 있으면 reset 직후 검증
|
|
571
|
+
if (newConnection.validateSession) {
|
|
572
|
+
const postResetValid = await newConnection.validateSession(newPage);
|
|
573
|
+
logger.info(`[Debug][Reset] Post-reset validateSession: ${postResetValid}`);
|
|
574
|
+
if (!postResetValid) {
|
|
575
|
+
logger.error(`[Debug][Reset] reset 완료 후에도 세션이 유효하지 않음 — connector.connect()의 로그인 처리 확인 필요`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
536
578
|
return { pageResource: newPageResource, page: newPage };
|
|
537
579
|
}
|
|
538
580
|
finally {
|