blob: 5ae74cbd22979d62be4872682f852b2b1abaea60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/**
* 결재 워크플로우 핸들러 레지스트리
*
* Saga 패턴에서 사용할 액션 핸들러들을 등록하고 관리합니다.
*
* 흐름:
* ApprovalSubmissionSaga → Knox 상신 → [폴링으로 상태 감지] → ApprovalExecutionSaga
*/
/**
* 액션 핸들러 타입 정의
* payload를 받아서 실제 비즈니스 로직을 수행하는 함수
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ActionHandler = (payload: any) => Promise<any>;
/**
* 액션 타입별 핸들러 저장소
* registerActionHandler()로 등록된 핸들러들이 여기 저장됨
*/
export const actionHandlers = new Map<string, ActionHandler>();
/**
* 특정 액션 타입에 대한 핸들러 등록
*
* @example
* registerActionHandler('vendor_investigation_request', async (payload) => {
* return await createInvestigation(payload);
* });
*/
export function registerActionHandler(actionType: string, handler: ActionHandler) {
actionHandlers.set(actionType, handler);
}
/**
* 등록된 핸들러 조회 (디버깅/테스트용)
*/
export function getRegisteredHandlers() {
return Array.from(actionHandlers.keys());
}
/**
* 핸들러 초기화 여부 추적 (Lazy Initialization용)
*/
let handlersInitialized = false;
/**
* 핸들러가 등록되어 있지 않으면 자동으로 초기화 (Lazy Initialization)
* Next.js 서버 액션의 격리된 실행 컨텍스트를 위한 안전장치
*/
export async function ensureHandlersInitialized() {
if (!handlersInitialized) {
console.log('[Approval Workflow] Lazy initializing handlers...');
const { initializeApprovalHandlers } = await import('./handlers-registry');
await initializeApprovalHandlers();
handlersInitialized = true;
}
}
|