@tailor-platform/sdk 1.35.1 → 1.36.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/application-BB5TqXWY.mjs +4 -0
  3. package/dist/{application-BnJRroGX.mjs → application-BwboBFcU.mjs} +102 -17
  4. package/dist/application-BwboBFcU.mjs.map +1 -0
  5. package/dist/cli/index.mjs +303 -17
  6. package/dist/cli/index.mjs.map +1 -1
  7. package/dist/cli/lib.d.mts +190 -6
  8. package/dist/cli/lib.mjs +3 -3
  9. package/dist/{client-BmQP4kKS.mjs → client-B6icVEv4.mjs} +1 -1
  10. package/dist/{client-CA2NM_4R.mjs → client-CN15WgW2.mjs} +25 -8
  11. package/dist/client-CN15WgW2.mjs.map +1 -0
  12. package/dist/configure/index.d.mts +5 -5
  13. package/dist/configure/index.mjs +38 -9
  14. package/dist/configure/index.mjs.map +1 -1
  15. package/dist/{crash-report-Bd2T8BhU.mjs → crash-report-CB1UtT3O.mjs} +1 -1
  16. package/dist/{crash-report-CPkI2-cp.mjs → crash-report-CdxPj_SW.mjs} +2 -2
  17. package/dist/{crash-report-CPkI2-cp.mjs.map → crash-report-CdxPj_SW.mjs.map} +1 -1
  18. package/dist/{env-MSlwZt8l.d.mts → env-_ce3IYbl.d.mts} +2 -2
  19. package/dist/{index-B1Fgxi8D.d.mts → index-C7vIBAg8.d.mts} +2 -2
  20. package/dist/{index-wCoQup4y.d.mts → index-CYaunQeL.d.mts} +76 -6
  21. package/dist/{index-D-tMAFVp.d.mts → index-CxSLivW7.d.mts} +2 -2
  22. package/dist/{index-BG7YCyXF.d.mts → index-DDCyefuU.d.mts} +2 -2
  23. package/dist/{index-BBlE_vQF.d.mts → index-DZN1QFLM.d.mts} +2 -2
  24. package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
  25. package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
  26. package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
  27. package/dist/plugin/builtin/seed/index.d.mts +1 -1
  28. package/dist/plugin/index.d.mts +2 -2
  29. package/dist/{plugin-CZaJ3_QR.d.mts → plugin-CiPUxkyN.d.mts} +3 -2
  30. package/dist/{runtime-D4O-RfcH.mjs → runtime-C7RRDaB3.mjs} +230 -22
  31. package/dist/runtime-C7RRDaB3.mjs.map +1 -0
  32. package/dist/utils/test/index.d.mts +2 -2
  33. package/dist/{workflow.generated-IZ3kLjC_.d.mts → workflow.generated-8BeGQsVU.d.mts} +212 -4
  34. package/docs/cli/function.md +2 -2
  35. package/docs/services/idp.md +50 -0
  36. package/docs/services/resolver.md +1 -1
  37. package/docs/services/secret.md +25 -0
  38. package/docs/services/workflow.md +48 -0
  39. package/package.json +9 -8
  40. package/dist/application-BnJRroGX.mjs.map +0 -1
  41. package/dist/application-mGasp_EX.mjs +0 -4
  42. package/dist/client-CA2NM_4R.mjs.map +0 -1
  43. package/dist/runtime-D4O-RfcH.mjs.map +0 -1
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { D as FunctionExecution_Type, P as AuthInvokerSchema, V as PATScope, i as fetchAll, l as initOAuth2Client, m as userAgent, n as closeConnectionPool, o as fetchPlatformMachineUserToken, s as fetchUserInfo, u as initOperatorClient } from "../client-CA2NM_4R.mjs";
3
+ import { I as AuthInvokerSchema, U as PATScope, i as fetchAll, k as FunctionExecution_Type, l as initOAuth2Client, m as userAgent, n as closeConnectionPool, o as fetchPlatformMachineUserToken, s as fetchUserInfo, u as initOperatorClient } from "../client-CN15WgW2.mjs";
4
4
  import { n as logger, r as styles } from "../logger-qz-Y4sBV.mjs";
5
- import { At as functionExecutionStatusToString, B as updateCommand$3, Ct as startCommand, D as resumeCommand, Dt as executionsCommand, E as healthCommand, Ft as executeScript, I as showCommand, J as updateCommand$2, Jt as formatMigrationNumber, K as getCommand$4, L as logBetaWarning, M as truncateCommand, Mt as getCommand$1, P as generateCommand$1, Pt as apply, Q as getCommand$3, Qt as getMigrationFiles, Rt as parseMigrationLabelNumber, Tt as getCommand$5, U as treeCommand, W as listCommand$10, X as listCommand$9, Zt as getMigrationFilePath, _ as getCommand$6, _n as isVerbose, _t as listCommand$6, a as updateCommand$4, bt as jobsCommand, cn as sdkNameLabelKey, d as inviteCommand, en as isValidMigrationNumber, et as deleteCommand$3, fn as apiCommand, ft as generate, gn as deploymentArgs, h as listCommand$14, hn as confirmationArgs, ht as triggerCommand, i as isCLIError, it as listCommand$8, jt as formatKeyValueTable, k as listCommand$11, l as listCommand$13, ln as trnPrefix, lt as tokenCommand, mn as commonArgs, mt as webhookCommand, nt as createCommand$3, on as getNamespacesWithMigrations, ot as getCommand$2, p as restoreCommand, pn as defineAppCommand, r as queryCommand, s as removeCommand, sn as prompt, t as isNativeTypeScriptRuntime, tn as loadDiff, ut as listCommand$7, vn as workspaceArgs, w as listCommand$12, x as createCommand$4, y as deleteCommand$4, z as removeCommand$1 } from "../runtime-D4O-RfcH.mjs";
5
+ import { At as functionExecutionStatusToString, B as updateCommand$3, Ct as startCommand, D as resumeCommand, Dt as executionsCommand, E as healthCommand, Ft as executeScript, I as showCommand, J as updateCommand$2, Jt as formatMigrationNumber, K as getCommand$4, L as logBetaWarning, M as truncateCommand, Mt as getCommand$1, P as generateCommand$1, Pt as apply, Q as getCommand$3, Qt as getMigrationFiles, Rt as parseMigrationLabelNumber, Tt as getCommand$5, U as treeCommand, W as listCommand$10, X as listCommand$9, Zt as getMigrationFilePath, _ as getCommand$6, _n as isVerbose, _t as listCommand$6, a as updateCommand$4, bt as jobsCommand, cn as sdkNameLabelKey, d as inviteCommand, en as isValidMigrationNumber, et as deleteCommand$3, fn as apiCommand, ft as generate, gn as deploymentArgs, h as listCommand$14, hn as confirmationArgs, ht as triggerCommand, i as isCLIError, it as listCommand$8, jt as formatKeyValueTable, k as listCommand$11, l as listCommand$13, ln as trnPrefix, lt as tokenCommand, mn as commonArgs, mt as webhookCommand, nt as createCommand$3, on as getNamespacesWithMigrations, ot as getCommand$2, p as restoreCommand, pn as defineAppCommand, r as queryCommand, s as removeCommand, sn as prompt, t as isNativeTypeScriptRuntime, tn as loadDiff, ut as listCommand$7, vn as workspaceArgs, w as listCommand$12, x as createCommand$4, y as deleteCommand$4, z as removeCommand$1 } from "../runtime-C7RRDaB3.mjs";
6
6
  import { t as readPackageJson } from "../package-json-CfUqjJaQ.mjs";
7
- import { C as resolveTokens, S as readPlatformConfig, T as writePlatformConfig, a as loadConfig, b as loadAccessToken, g as getDistDir, i as resolveInlineSourcemap, l as ExecutorSchema, o as WorkflowJobSchema, s as ResolverSchema, v as deleteUserTokens, w as saveUserTokens, x as loadWorkspaceId, y as fetchLatestToken } from "../application-BnJRroGX.mjs";
8
- import { a as JSON_FOOTER_MARKER, i as CRASH_LOG_EXTENSION, o as parseCrashReportConfig, r as sendCrashReport, t as initCrashReporting } from "../crash-report-CPkI2-cp.mjs";
7
+ import { C as resolveTokens, S as readPlatformConfig, T as writePlatformConfig, a as loadConfig, b as loadAccessToken, g as getDistDir, i as resolveInlineSourcemap, l as ExecutorSchema, o as WorkflowJobSchema, s as ResolverSchema, v as deleteUserTokens, w as saveUserTokens, x as loadWorkspaceId, y as fetchLatestToken } from "../application-BwboBFcU.mjs";
8
+ import { a as JSON_FOOTER_MARKER, i as CRASH_LOG_EXTENSION, o as parseCrashReportConfig, r as sendCrashReport, t as initCrashReporting } from "../crash-report-CdxPj_SW.mjs";
9
9
  import { createRequire } from "node:module";
10
10
  import { arg, defineCommand, runCommand, runMain } from "politty";
11
11
  import { withCompletionCommand } from "politty/completion";
@@ -23,6 +23,7 @@ import ml from "multiline-ts";
23
23
  import * as rolldown from "rolldown";
24
24
  import { create } from "@bufbuild/protobuf";
25
25
  import open from "open";
26
+ import { TraceMap, generatedPositionFor, originalPositionFor } from "@jridgewell/trace-mapping";
26
27
  import { spawn, spawnSync } from "node:child_process";
27
28
  import * as fs from "fs";
28
29
  import { lookup } from "mime-types";
@@ -523,6 +524,238 @@ const logsCommand = defineAppCommand({
523
524
  }
524
525
  });
525
526
 
527
+ //#endregion
528
+ //#region src/cli/shared/stack-trace.ts
529
+ /**
530
+ * Stack trace parsing, sourcemap-based source identification, and
531
+ * formatted error display for the test-run command.
532
+ *
533
+ * The platform runtime automatically applies inline sourcemaps to V8
534
+ * stack traces, so frame positions are already original source positions.
535
+ * This module identifies which source file each frame belongs to via
536
+ * reverse lookup (generatedPositionFor), then produces human-readable
537
+ * output with file paths and code snippets.
538
+ */
539
+ const STACK_FRAME_REGEX = /^\s+at\s+(?:(.+?)\s+\()?(file:\/\/\/.+?):(\d+):(\d+)\)?$/;
540
+ const RPC_ERROR_PREFIX = "rpc error: code = Aborted desc = ";
541
+ /**
542
+ * Parse a V8 stack trace string into structured frames.
543
+ * Only frames with `file:///` URLs are included (eval frames are skipped).
544
+ * @param error - Raw error string potentially containing a V8 stack trace
545
+ * @returns Parsed error message and stack frames
546
+ */
547
+ function parseStackTrace(error) {
548
+ const lines = error.split("\n");
549
+ const messageLines = [];
550
+ const frameLines = [];
551
+ for (const line of lines) if (/^\s+at\s+/.test(line)) frameLines.push(line);
552
+ else if (frameLines.length === 0) messageLines.push(line);
553
+ let errorMessage = messageLines.join("\n");
554
+ if (errorMessage.startsWith(RPC_ERROR_PREFIX)) errorMessage = errorMessage.slice(33);
555
+ const frames = [];
556
+ for (const line of frameLines) {
557
+ const match = STACK_FRAME_REGEX.exec(line);
558
+ if (match) frames.push({
559
+ functionName: match[1] || "<anonymous>",
560
+ file: match[2],
561
+ line: Number(match[3]),
562
+ column: Number(match[4])
563
+ });
564
+ }
565
+ return {
566
+ errorMessage,
567
+ frames
568
+ };
569
+ }
570
+ const INLINE_SOURCEMAP_REGEX = /\/\/[#@]\s*sourceMappingURL=data:application\/json[^,]*;base64,(.+)$/m;
571
+ /**
572
+ * Extract an inline sourcemap from bundled code and return a TraceMap.
573
+ * @param bundledCode - Bundled JavaScript code potentially containing an inline sourcemap
574
+ * @returns TraceMap instance, or null if no valid inline sourcemap is found
575
+ */
576
+ function extractInlineSourcemap(bundledCode) {
577
+ const match = INLINE_SOURCEMAP_REGEX.exec(bundledCode);
578
+ if (!match) return null;
579
+ try {
580
+ const decoded = Buffer.from(match[1], "base64").toString("utf-8");
581
+ return new TraceMap(JSON.parse(decoded));
582
+ } catch {
583
+ return null;
584
+ }
585
+ }
586
+ /**
587
+ * Map parsed stack frames to their source files using a TraceMap.
588
+ *
589
+ * The platform runtime applies inline sourcemaps automatically, so V8
590
+ * reports already-mapped original source positions in stack traces.
591
+ * This function uses generatedPositionFor to reverse-lookup which source
592
+ * file each frame's line:column belongs to.
593
+ * @param frames - Parsed stack frames (positions are already original source positions)
594
+ * @param traceMap - TraceMap from inline sourcemap, or null
595
+ * @returns Frames with identified source files
596
+ */
597
+ function mapStackFrames(frames, traceMap) {
598
+ return frames.map((frame) => {
599
+ if (!traceMap) return {
600
+ original: frame,
601
+ mapped: null
602
+ };
603
+ try {
604
+ for (let i = traceMap.sources.length - 1; i >= 0; i--) {
605
+ const source = traceMap.sources[i];
606
+ if (source == null) continue;
607
+ const genPos = generatedPositionFor(traceMap, {
608
+ source,
609
+ line: frame.line,
610
+ column: frame.column - 1
611
+ });
612
+ if (genPos.line == null) continue;
613
+ const origPos = originalPositionFor(traceMap, {
614
+ line: genPos.line,
615
+ column: genPos.column
616
+ });
617
+ if (origPos.source !== source || origPos.line !== frame.line || origPos.column !== frame.column - 1) continue;
618
+ return {
619
+ original: frame,
620
+ mapped: {
621
+ source,
622
+ line: frame.line,
623
+ column: frame.column,
624
+ name: null
625
+ }
626
+ };
627
+ }
628
+ return {
629
+ original: frame,
630
+ mapped: null
631
+ };
632
+ } catch {
633
+ return {
634
+ original: frame,
635
+ mapped: null
636
+ };
637
+ }
638
+ });
639
+ }
640
+ /**
641
+ * Detect the URI scheme for opening files based on VISUAL/EDITOR env vars.
642
+ * @returns "vscode" if the editor looks like VS Code, otherwise null (use file://)
643
+ */
644
+ function detectEditorScheme() {
645
+ const editor = process.env.VISUAL || process.env.EDITOR || "";
646
+ if (/\bcode\b/.test(editor)) return "vscode";
647
+ return null;
648
+ }
649
+ /**
650
+ * Wrap text in an OSC 8 terminal hyperlink.
651
+ * @param uri - URI to open when the link is clicked
652
+ * @param text - Visible text displayed in the terminal
653
+ * @returns Escaped string with OSC 8 sequences
654
+ */
655
+ function osc8Link(uri, text) {
656
+ return `\x1b]8;;${uri}\x07${text}\x1b]8;;\x07`;
657
+ }
658
+ /**
659
+ * Build a clickable terminal link for a source location.
660
+ * Uses vscode:// URI if the editor is VS Code, otherwise file:// URI.
661
+ * @param displayPath - Path to display in the terminal
662
+ * @param absolutePath - Absolute file path for the URI
663
+ * @param line - 1-based line number
664
+ * @param column - 1-based column number
665
+ * @returns OSC 8 hyperlinked location string
666
+ */
667
+ function buildSourceLink(displayPath, absolutePath, line, column) {
668
+ const location = `${displayPath}:${line}:${column}`;
669
+ if (detectEditorScheme() === "vscode") return osc8Link(`vscode://file${absolutePath}:${line}:${column}`, location);
670
+ return osc8Link(`file://${absolutePath}`, location);
671
+ }
672
+ const SNIPPET_CONTEXT_LINES = 2;
673
+ /**
674
+ * Build a code snippet around a target line from source content.
675
+ * Shows SNIPPET_CONTEXT_LINES above and below with line numbers.
676
+ * The target line is marked with `>` and highlighted.
677
+ * @param content - Full source file content
678
+ * @param targetLine - 1-based line number to highlight
679
+ * @returns Formatted snippet string
680
+ */
681
+ function buildCodeSnippet(content, targetLine) {
682
+ const lines = content.split("\n");
683
+ const start = Math.max(0, targetLine - 1 - SNIPPET_CONTEXT_LINES);
684
+ const end = Math.min(lines.length, targetLine + SNIPPET_CONTEXT_LINES);
685
+ const gutterWidth = String(end).length;
686
+ const snippetLines = [];
687
+ for (let i = start; i < end; i++) {
688
+ const lineNum = i + 1;
689
+ const gutter = String(lineNum).padStart(gutterWidth);
690
+ const lineContent = lines[i];
691
+ if (lineNum === targetLine) snippetLines.push(` ${styles.error(">")} ${styles.error(`${gutter} | ${lineContent}`)}`);
692
+ else snippetLines.push(` ${styles.dim(`${gutter} | ${lineContent}`)}`);
693
+ }
694
+ return snippetLines.join("\n");
695
+ }
696
+ /**
697
+ * Format mapped stack frames into a human-readable error display.
698
+ * Includes file paths (clickable in terminals), code snippets, and
699
+ * falls back to raw frame info for unmapped frames.
700
+ * @param errorMessage - Cleaned error message
701
+ * @param frames - Mapped stack frames
702
+ * @param traceMap - TraceMap for retrieving source content (may be null)
703
+ * @param bundleDir - Absolute path to bundle output directory for resolving source paths
704
+ * @returns Formatted error string for display
705
+ */
706
+ function formatMappedError(errorMessage, frames, traceMap, bundleDir) {
707
+ const parts = [` ${styles.error(errorMessage)}`];
708
+ for (const frame of frames) if (frame.mapped) {
709
+ const { source, line, column, name } = frame.mapped;
710
+ const absolutePath = bundleDir ? path.resolve(bundleDir, source) : path.resolve(source);
711
+ const rel = path.relative(process.cwd(), absolutePath);
712
+ const displaySource = rel.startsWith(".") ? rel : `./${rel}`;
713
+ const fnName = name ?? frame.original.functionName;
714
+ const link = buildSourceLink(displaySource, absolutePath, line, column);
715
+ parts.push(`\n at ${fnName} (${link})`);
716
+ if (traceMap) {
717
+ const sourceIndex = traceMap.sources.indexOf(source);
718
+ if (sourceIndex !== -1) {
719
+ const content = traceMap.sourcesContent?.[sourceIndex];
720
+ if (content) parts.push(buildCodeSnippet(content, line));
721
+ }
722
+ }
723
+ } else {
724
+ const location = `${frame.original.file.replace(/^file:\/\/\//, "")}:${frame.original.line}:${frame.original.column}`;
725
+ parts.push(`\n ${styles.dim(`at ${frame.original.functionName} (${location})`)}`);
726
+ }
727
+ return parts.join("\n");
728
+ }
729
+ /**
730
+ * Format an error string with sourcemap-based source locations.
731
+ * This is the main entry point for test-run error display.
732
+ *
733
+ * The platform runtime applies inline sourcemaps automatically, so V8
734
+ * stack frames already contain original source positions. This function
735
+ * identifies which source file each frame belongs to and formats the
736
+ * error with file paths, line numbers, and code snippets.
737
+ *
738
+ * Returns null if sourcemap processing is not possible (no inline
739
+ * sourcemap, no stack trace, or processing error).
740
+ * @param error - Raw error string from script execution (may contain V8 stack trace)
741
+ * @param bundledCode - Bundled JavaScript code (may contain inline sourcemap)
742
+ * @param bundleDir - Absolute path to the bundle output directory (sourcemap paths are relative to this)
743
+ * @returns Formatted error string, or null to fall back to default display
744
+ */
745
+ function formatErrorWithSourcemap(error, bundledCode, bundleDir) {
746
+ try {
747
+ const { errorMessage, frames } = parseStackTrace(error);
748
+ if (frames.length === 0) return null;
749
+ const traceMap = extractInlineSourcemap(bundledCode);
750
+ if (!traceMap) return null;
751
+ const mappedFrames = mapStackFrames(frames, traceMap);
752
+ if (mappedFrames.some((f) => f.mapped !== null)) return formatMappedError(errorMessage, mappedFrames, traceMap, bundleDir);
753
+ return null;
754
+ } catch {
755
+ return null;
756
+ }
757
+ }
758
+
526
759
  //#endregion
527
760
  //#region src/cli/commands/function/bundle.ts
528
761
  /**
@@ -604,13 +837,11 @@ function generateEntry(detected, sourceFile, env, machineUser, workspaceId) {
604
837
  const _user = ${userExpr};
605
838
 
606
839
  const $tailor_resolver_body = async (context) => {
607
- const enrichedContext = { ...context, env: _env, user: _user };
608
-
609
840
  if (_internalResolver.input) {
610
841
  const result = t.object(_internalResolver.input).parse({
611
- value: enrichedContext.input,
612
- data: enrichedContext.input,
613
- user: enrichedContext.user,
842
+ value: context,
843
+ data: context,
844
+ user: _user,
614
845
  });
615
846
 
616
847
  if (result.issues) {
@@ -621,6 +852,7 @@ function generateEntry(detected, sourceFile, env, machineUser, workspaceId) {
621
852
  }
622
853
  }
623
854
 
855
+ const enrichedContext = { input: context, env: _env, user: _user };
624
856
  return _internalResolver.body(enrichedContext);
625
857
  };
626
858
 
@@ -704,10 +936,20 @@ async function detectFunctionType(options) {
704
936
  const { filePath, jobName } = options;
705
937
  const module = await import(pathToFileURL(filePath).href);
706
938
  const resolverResult = ResolverSchema.safeParse(module.default);
707
- if (resolverResult.success) return {
708
- type: "resolver",
709
- name: resolverResult.data.name
710
- };
939
+ if (resolverResult.success) {
940
+ const rawInput = module.default.input;
941
+ let inputSchema;
942
+ if (rawInput) {
943
+ const { t } = await import("@tailor-platform/sdk");
944
+ inputSchema = t.object(rawInput);
945
+ }
946
+ return {
947
+ type: "resolver",
948
+ name: resolverResult.data.name,
949
+ hasInput: rawInput != null,
950
+ inputSchema
951
+ };
952
+ }
711
953
  const executorResult = ExecutorSchema.safeParse(module.default);
712
954
  if (executorResult.success) {
713
955
  const { operation } = executorResult.data;
@@ -825,7 +1067,7 @@ When a \`.js\` file is provided, detection and bundling are skipped and the file
825
1067
  > Triggered jobs are not executed; only the target job's \`body\` function runs in isolation.`,
826
1068
  examples: [
827
1069
  {
828
- cmd: "resolvers/add.ts --arg '{\"input\":{\"a\":1,\"b\":2}}'",
1070
+ cmd: "resolvers/add.ts --arg '{\"a\":1,\"b\":2}'",
829
1071
  desc: "Run a resolver with input arguments"
830
1072
  },
831
1073
  {
@@ -833,7 +1075,7 @@ When a \`.js\` file is provided, detection and bundling are skipped and the file
833
1075
  desc: "Run a specific workflow job by name"
834
1076
  },
835
1077
  {
836
- cmd: "build/resolvers/add.js --arg '{\"input\":{\"a\":1,\"b\":2}}'",
1078
+ cmd: "build/resolvers/add.js --arg '{\"a\":1,\"b\":2}'",
837
1079
  desc: "Run a pre-bundled .js file directly"
838
1080
  }
839
1081
  ],
@@ -877,6 +1119,12 @@ When a \`.js\` file is provided, detection and bundling are skipped and the file
877
1119
  functionType = detected.type;
878
1120
  functionName = detected.name;
879
1121
  logger.info(`Detected: ${styles.bold(detected.type)} ${styles.info(`"${detected.name}"`)}`);
1122
+ if (detected.type === "resolver" && args.arg) {
1123
+ if (!detected.hasInput) {
1124
+ logger.warn("--arg is ignored because this resolver has no input schema. Define \"input\" in your resolver to use --arg.");
1125
+ args.arg = void 0;
1126
+ } else if (detected.inputSchema) args.arg = resolveResolverArg(args.arg, detected.inputSchema, machineUser, workspaceId);
1127
+ }
880
1128
  logger.info("Bundling...");
881
1129
  ({bundledCode, scriptName} = await bundleForTestRun({
882
1130
  detected,
@@ -928,7 +1176,9 @@ When a \`.js\` file is provided, detection and bundling are skipped and the file
928
1176
  }
929
1177
  if (result.error && !result.success) {
930
1178
  logger.log(styles.bold("\nError:"));
931
- logger.log(` ${styles.error(result.error)}`);
1179
+ const formatted = formatErrorWithSourcemap(result.error, bundledCode, process.cwd());
1180
+ if (formatted) logger.log(formatted);
1181
+ else logger.log(` ${styles.error(result.error)}`);
932
1182
  }
933
1183
  }
934
1184
  if (!result.success) process.exit(1);
@@ -993,6 +1243,42 @@ async function resolveMachineUser(options) {
993
1243
  attributeList
994
1244
  };
995
1245
  }
1246
+ /**
1247
+ * Resolve resolver arg format: detect and unwrap deprecated {"input":{...}} wrapper.
1248
+ * Tries new format (arg = input fields) first via schema parse.
1249
+ * If that fails and arg looks like old format, tries unwrapping.
1250
+ * @param argStr - JSON string of the arg
1251
+ * @param inputSchema - Pre-built schema object from detect (has .parse())
1252
+ * @param machineUser - Resolved machine user info
1253
+ * @param workspaceId - Workspace ID
1254
+ * @returns Resolved JSON string (unwrapped if old format)
1255
+ */
1256
+ function resolveResolverArg(argStr, inputSchema, machineUser, workspaceId) {
1257
+ const parsed = JSON.parse(argStr);
1258
+ const user = {
1259
+ id: machineUser.id,
1260
+ type: "machine_user",
1261
+ workspaceId,
1262
+ attributes: machineUser.attributes ?? null,
1263
+ attributeList: machineUser.attributeList ?? []
1264
+ };
1265
+ if (!inputSchema.parse({
1266
+ value: parsed,
1267
+ data: parsed,
1268
+ user
1269
+ }).issues) return argStr;
1270
+ if (Object.keys(parsed).length === 1 && parsed.input != null && typeof parsed.input === "object" && !Array.isArray(parsed.input)) {
1271
+ if (!inputSchema.parse({
1272
+ value: parsed.input,
1273
+ data: parsed.input,
1274
+ user
1275
+ }).issues) {
1276
+ logger.warn("[DEPRECATED] Wrapping args with \"input\" key (e.g. {\"input\":{...}}) is deprecated. Pass input fields directly (e.g. {\"a\":1}). The \"input\" wrapper will be removed in v2.");
1277
+ return JSON.stringify(parsed.input);
1278
+ }
1279
+ }
1280
+ return argStr;
1281
+ }
996
1282
 
997
1283
  //#endregion
998
1284
  //#region src/cli/commands/function/index.ts
@@ -3488,7 +3774,7 @@ runMain(mainCommand, {
3488
3774
  if (isVerbose() && error.stack) logger.debug(`\nStack trace:\n${error.stack}`);
3489
3775
  } else logger.error(`Unknown error: ${error}`);
3490
3776
  if (!isCLIError(error) && (!(error instanceof Error) || error instanceof TypeError || error instanceof RangeError)) {
3491
- const { reportCrash } = await import("../crash-report-Bd2T8BhU.mjs");
3777
+ const { reportCrash } = await import("../crash-report-CB1UtT3O.mjs");
3492
3778
  await reportCrash(error, "handledError");
3493
3779
  }
3494
3780
  }