@teleporthq/teleport-plugin-next-workflows 0.43.37 → 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.
@@ -1,4 +1,83 @@
1
1
  export function handlerToString(fn) {
2
2
  return fn.toString();
3
3
  }
4
+ // Resolves the name a handler's entry function is ACTUALLY declared with in
5
+ // `source`, rather than assuming it always equals the
6
+ // `nodeType.replace(/-/g, '_')` convention name.
7
+ //
8
+ // Handlers built from `handlerToString(fn)` on a real function embed
9
+ // `fn.toString()` — a snapshot of whatever `fn` was actually named at the
10
+ // moment it's read. When this package is bundled and minified by a consumer
11
+ // (e.g. teleport-gui's browser packer worker, built with Next.js/Terser), the
12
+ // minifier freely renames `fn`'s declaration: nothing in the bundle calls it
13
+ // by name, only this runtime `.toString()` read does, which is invisible to
14
+ // the minifier. Callers that then reference the embedded handler by the
15
+ // static convention name get a "Collecting page data"/prerender
16
+ // ReferenceError, since local dev never runs a minifier.
17
+ //
18
+ // Handlers composed from string-literal templates (not `fn.toString()`) are
19
+ // immune to that class of breakage — a minifier never rewrites the contents
20
+ // of a string literal — so the convention name is still correct for those;
21
+ // this only needs to look further when it's genuinely absent from `source`.
22
+ export function resolveHandlerEntryName(source, nodeType) {
23
+ const conventionName = nodeType.replace(/-/g, '_');
24
+ const conventionNameUsed = new RegExp(`(?:^|[^\\w$])${conventionName}\\s*\\(`).test(source);
25
+ if (conventionNameUsed) {
26
+ return conventionName;
27
+ }
28
+ // `source` came from `handlerToString(fn)`/`fn.toString()` on a real,
29
+ // possibly-minified function, and may be concatenated with OTHER
30
+ // `.toString()`'d functions:
31
+ // - payment-charge-user.ts puts the entry FIRST, its own helpers after
32
+ // (`handlerToString(payment_charge_user) + '\n' + chargeWithStripe.toString() + ...`).
33
+ // - ai-custom-prompt.ts puts shared AI-provider utils BEFORE the entry
34
+ // (`generateAIProviderUtils() + '\n\n' + ai_custom_prompt.toString()`),
35
+ // where each util is `wrapWithGuard`-wrapped: `var X = typeof X !==
36
+ // 'undefined' ? X : function Y() {...};` — a function EXPRESSION
37
+ // embedded in a ternary, not a statement-level declaration.
38
+ // So the entry is not reliably first or last by position across handlers,
39
+ // and helper functions can outnumber (or precede) the entry. What IS
40
+ // reliable: every real entry point has exactly the HandlerFn signature —
41
+ // 2 params (config, context) or 3 (config, context, streamCallback) — by
42
+ // contract, while a handler's OWN internal helpers only coincidentally
43
+ // share that arity (e.g. general-rate-limiter's __checkRateLimit takes 3
44
+ // params too). So: collect every statement-level function declaration
45
+ // (skipping ternary-embedded expressions like wrapWithGuard's), and prefer
46
+ // an exactly-2-param candidate, then an exactly-3-param one, falling back
47
+ // to positional order only if nothing matches the entry-point arity.
48
+ const declPattern = /(?:async\s+)?function\s+([A-Za-z0-9_$]+)\s*\(([^)]*)\)/g;
49
+ const candidates = [];
50
+ let twoParamCandidate;
51
+ let threeParamCandidate;
52
+ let declMatch = declPattern.exec(source);
53
+ while (declMatch !== null) {
54
+ const precedingNonSpace = source.slice(0, declMatch.index).trimEnd().slice(-1);
55
+ if (precedingNonSpace === ':' || precedingNonSpace === '?') {
56
+ declMatch = declPattern.exec(source);
57
+ continue; // function EXPRESSION embedded in a ternary (e.g. wrapWithGuard's re-declaration guard)
58
+ }
59
+ const name = declMatch[1];
60
+ candidates.push(name);
61
+ const params = declMatch[2].trim();
62
+ const paramCount = params === '' ? 0 : params.split(',').length;
63
+ if (paramCount === 2 && twoParamCandidate === undefined) {
64
+ twoParamCandidate = name;
65
+ }
66
+ else if (paramCount === 3 && threeParamCandidate === undefined) {
67
+ threeParamCandidate = name;
68
+ }
69
+ declMatch = declPattern.exec(source);
70
+ }
71
+ if (twoParamCandidate !== undefined) {
72
+ return twoParamCandidate;
73
+ }
74
+ if (threeParamCandidate !== undefined) {
75
+ return threeParamCandidate;
76
+ }
77
+ if (candidates.length > 0) {
78
+ return candidates[0];
79
+ }
80
+ throw new Error(`Could not resolve the entry function for workflow node type "${nodeType}" — ` +
81
+ `expected a "${conventionName}" declaration or a single toString()'d function, found neither.`);
82
+ }
4
83
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/nodes/types.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,EAAa;IAC3C,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAA;AACtB,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/nodes/types.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,EAAa;IAC3C,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAA;AACtB,CAAC;AAED,4EAA4E;AAC5E,sDAAsD;AACtD,iDAAiD;AACjD,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,wEAAwE;AACxE,gEAAgE;AAChE,yDAAyD;AACzD,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,MAAM,UAAU,uBAAuB,CAAC,MAAc,EAAE,QAAgB;IACtE,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAClD,MAAM,kBAAkB,GAAG,IAAI,MAAM,CAAC,gBAAgB,cAAc,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3F,IAAI,kBAAkB,EAAE;QACtB,OAAO,cAAc,CAAA;KACtB;IAED,sEAAsE;IACtE,iEAAiE;IACjE,6BAA6B;IAC7B,yEAAyE;IACzE,2FAA2F;IAC3F,yEAAyE;IACzE,4EAA4E;IAC5E,wEAAwE;IACxE,qEAAqE;IACrE,gEAAgE;IAChE,0EAA0E;IAC1E,qEAAqE;IACrE,yEAAyE;IACzE,yEAAyE;IACzE,uEAAuE;IACvE,yEAAyE;IACzE,sEAAsE;IACtE,2EAA2E;IAC3E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