@teleporthq/teleport-plugin-next-workflows 0.43.38 → 0.43.39

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.
@@ -29,13 +29,56 @@ export function resolveHandlerEntryName(source: string, nodeType: string): strin
29
29
  return conventionName
30
30
  }
31
31
 
32
- // `source` came from `handlerToString(fn)` on a real, possibly-minified
33
- // function its ENTIRE text is that one function's declaration, so
34
- // whatever name follows the leading `function`/`async function` keyword is
35
- // the name it was actually assigned at runtime.
36
- const leadingDeclaration = source.match(/^(?:async\s+)?function\s*([A-Za-z0-9_$]+)\s*\(/)
37
- if (leadingDeclaration) {
38
- return leadingDeclaration[1]
32
+ // `source` came from `handlerToString(fn)`/`fn.toString()` on a real,
33
+ // possibly-minified function, and may be concatenated with OTHER
34
+ // `.toString()`'d functions:
35
+ // - payment-charge-user.ts puts the entry FIRST, its own helpers after
36
+ // (`handlerToString(payment_charge_user) + '\n' + chargeWithStripe.toString() + ...`).
37
+ // - ai-custom-prompt.ts puts shared AI-provider utils BEFORE the entry
38
+ // (`generateAIProviderUtils() + '\n\n' + ai_custom_prompt.toString()`),
39
+ // where each util is `wrapWithGuard`-wrapped: `var X = typeof X !==
40
+ // 'undefined' ? X : function Y() {...};` — a function EXPRESSION
41
+ // embedded in a ternary, not a statement-level declaration.
42
+ // So the entry is not reliably first or last by position across handlers,
43
+ // and helper functions can outnumber (or precede) the entry. What IS
44
+ // reliable: every real entry point has exactly the HandlerFn signature —
45
+ // 2 params (config, context) or 3 (config, context, streamCallback) — by
46
+ // contract, while a handler's OWN internal helpers only coincidentally
47
+ // share that arity (e.g. general-rate-limiter's __checkRateLimit takes 3
48
+ // params too). So: collect every statement-level function declaration
49
+ // (skipping ternary-embedded expressions like wrapWithGuard's), and prefer
50
+ // an exactly-2-param candidate, then an exactly-3-param one, falling back
51
+ // to positional order only if nothing matches the entry-point arity.
52
+ const declPattern = /(?:async\s+)?function\s+([A-Za-z0-9_$]+)\s*\(([^)]*)\)/g
53
+ const candidates: string[] = []
54
+ let twoParamCandidate: string | undefined
55
+ let threeParamCandidate: string | undefined
56
+ let declMatch: RegExpExecArray | null = declPattern.exec(source)
57
+ while (declMatch !== null) {
58
+ const precedingNonSpace = source.slice(0, declMatch.index).trimEnd().slice(-1)
59
+ if (precedingNonSpace === ':' || precedingNonSpace === '?') {
60
+ declMatch = declPattern.exec(source)
61
+ continue // function EXPRESSION embedded in a ternary (e.g. wrapWithGuard's re-declaration guard)
62
+ }
63
+ const name = declMatch[1]
64
+ candidates.push(name)
65
+ const params = declMatch[2].trim()
66
+ const paramCount = params === '' ? 0 : params.split(',').length
67
+ if (paramCount === 2 && twoParamCandidate === undefined) {
68
+ twoParamCandidate = name
69
+ } else if (paramCount === 3 && threeParamCandidate === undefined) {
70
+ threeParamCandidate = name
71
+ }
72
+ declMatch = declPattern.exec(source)
73
+ }
74
+ if (twoParamCandidate !== undefined) {
75
+ return twoParamCandidate
76
+ }
77
+ if (threeParamCandidate !== undefined) {
78
+ return threeParamCandidate
79
+ }
80
+ if (candidates.length > 0) {
81
+ return candidates[0]
39
82
  }
40
83
 
41
84
  throw new Error(