Refactor workflow auto-run to node graph
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createOpenAiMailRulesModule() {
|
||||
const SIGNUP_CODE_RULE_ID = 'openai-signup-code';
|
||||
const LOGIN_CODE_RULE_ID = 'openai-login-code';
|
||||
const SIGNUP_CODE_NODE_ID = 'fetch-signup-code';
|
||||
const LOGIN_CODE_NODE_ID = 'fetch-login-code';
|
||||
const OPENAI_CODE_PATTERNS = Object.freeze([
|
||||
Object.freeze({
|
||||
source: '(?:chatgpt\\s+log-?in\\s+code|enter\\s+this\\s+code)[^0-9]{0,24}(\\d{6})',
|
||||
@@ -56,10 +58,27 @@
|
||||
&& String(state?.mail2925Mode || '').trim().toLowerCase() === 'receive';
|
||||
}
|
||||
|
||||
function getRuleDefinition(step, state = {}) {
|
||||
const normalizedStep = Number(step) === 4 ? 4 : 8;
|
||||
function resolveVerificationNodeId(input) {
|
||||
const directNodeId = String(input?.nodeId || input || '').trim();
|
||||
if (directNodeId === SIGNUP_CODE_NODE_ID || directNodeId === LOGIN_CODE_NODE_ID) {
|
||||
return directNodeId;
|
||||
}
|
||||
return Number(input?.step ?? input) === 4 ? SIGNUP_CODE_NODE_ID : LOGIN_CODE_NODE_ID;
|
||||
}
|
||||
|
||||
function getVisibleStepForNode(nodeId, state = {}) {
|
||||
if (nodeId === SIGNUP_CODE_NODE_ID) {
|
||||
return 4;
|
||||
}
|
||||
const explicitStep = Number(state?.visibleStep || state?.step);
|
||||
return Number.isInteger(explicitStep) && explicitStep > 0 ? explicitStep : 8;
|
||||
}
|
||||
|
||||
function getRuleDefinition(input, state = {}) {
|
||||
const nodeId = resolveVerificationNodeId(input);
|
||||
const normalizedStep = getVisibleStepForNode(nodeId, state);
|
||||
const mail2925Provider = isMail2925Provider(state);
|
||||
const signupStep = normalizedStep === 4;
|
||||
const signupStep = nodeId === SIGNUP_CODE_NODE_ID;
|
||||
const targetEmail = signupStep
|
||||
? state?.email
|
||||
: (String(state?.step8VerificationTargetEmail || '').trim() || state?.email);
|
||||
@@ -67,6 +86,7 @@
|
||||
return {
|
||||
flowId: 'openai',
|
||||
ruleId: signupStep ? SIGNUP_CODE_RULE_ID : LOGIN_CODE_RULE_ID,
|
||||
nodeId,
|
||||
step: normalizedStep,
|
||||
artifactType: 'code',
|
||||
codePatterns: OPENAI_CODE_PATTERNS,
|
||||
@@ -90,22 +110,34 @@
|
||||
};
|
||||
}
|
||||
|
||||
function buildVerificationPollPayload(step, state = {}, overrides = {}) {
|
||||
function getRuleDefinitionForNode(nodeId, state = {}) {
|
||||
return getRuleDefinition({ nodeId }, state);
|
||||
}
|
||||
|
||||
function buildVerificationPollPayload(input, state = {}, overrides = {}) {
|
||||
return {
|
||||
...getRuleDefinition(step, state),
|
||||
...getRuleDefinition(input, state),
|
||||
...(overrides || {}),
|
||||
};
|
||||
}
|
||||
|
||||
function buildVerificationPollPayloadForNode(nodeId, state = {}, overrides = {}) {
|
||||
return buildVerificationPollPayload({ nodeId }, state, overrides);
|
||||
}
|
||||
|
||||
return {
|
||||
buildVerificationPollPayload,
|
||||
buildVerificationPollPayloadForNode,
|
||||
getRuleDefinition,
|
||||
getRuleDefinitionForNode,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
LOGIN_CODE_RULE_ID,
|
||||
LOGIN_CODE_NODE_ID,
|
||||
SIGNUP_CODE_RULE_ID,
|
||||
SIGNUP_CODE_NODE_ID,
|
||||
createOpenAiMailRules,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user