{"version":3,"file":"workflow-Cs9ISw6j.mjs","names":[],"sources":["../src/runtime/workflow.ts"],"sourcesContent":["/**\n * Workflow utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.workflow` runtime API.\n * At runtime this delegates to `globalThis.tailor.workflow`. Use `mockWorkflow`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n *\n * `execJobFunction` blocks until the job finishes and returns its result, while\n * `startWorkflow` returns only an execution ID.\n * @example\n * import { workflow } from \"@tailor-platform/sdk/runtime\";\n *\n * const executionId = await workflow.startWorkflow(\"myWorkflow\", { data: \"value\" });\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Specifies the machine user that should be used to execute the workflow.\n * This allows workflows to run with specific authentication context.\n */\nexport interface Invoker {\n  /** The namespace where the machine user is defined */\n  namespace: string;\n  /** The name of the machine user to use for workflow execution */\n  machineUserName: string;\n}\n\n/** Options for {@link startWorkflow}. */\nexport interface StartWorkflowOptions {\n  /** Optional authentication invoker to specify which machine user should execute the workflow */\n  authInvoker?: Invoker;\n}\n\ndeclare const executionPolicyKeyBrand: unique symbol;\n\n/**\n * A concrete runtime key produced by an execution policy instance — either an\n * exact-match policy's `.key`, or a wildcard policy's `.keyFor(suffix)` (see\n * `defineWorkflowExecutionPolicies`). Branded so an arbitrary string that\n * wasn't derived from a declared policy can't be passed as `executionPolicyKey`.\n */\nexport type ExecutionPolicyKey = string & { readonly [executionPolicyKeyBrand]: never };\n\n/** Options for {@link execJobFunction}. */\nexport interface ExecJobFunctionOptions {\n  /**\n   * Execution policy key matched by the platform against the policies\n   * declared with `defineWorkflowExecutionPolicies` in `tailor.config.ts`.\n   */\n  executionPolicyKey?: ExecutionPolicyKey;\n}\n\n/**\n * Platform API surface for `tailor.workflow`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.workflow`.\n */\nexport interface PlatformWorkflowAPI {\n  /**\n   * Starts a workflow and returns its execution ID.\n   * @param workflowName - Workflow name as defined in tailor.config\n   * @param args - Arguments forwarded to the workflow's main job\n   * @param options - Optional start options (e.g. `authInvoker`)\n   * @returns The execution ID of the started workflow\n   */\n  startWorkflow(workflowName: string, args?: any, options?: StartWorkflowOptions): Promise<string>;\n\n  /**\n   * Resumes a failed or pending-retry workflow execution and returns its execution ID.\n   * @param executionId - The execution to resume\n   * @returns The execution ID of the resumed workflow\n   */\n  resumeWorkflowExecution(executionId: string): Promise<string>;\n\n  /**\n   * Executes a job function and returns its result via durable suspend/replay.\n   * @param jobName - Job name as defined in the workflow\n   * @param args - Arguments forwarded to the job\n   * @param options - Optional execution options (e.g. `executionPolicyKey`)\n   * @returns The job's return value\n   */\n  execJobFunction(jobName: string, args?: any, options?: ExecJobFunctionOptions): any;\n\n  /**\n   * Suspends the current workflow execution and waits for an external signal to resume.\n   * @param key - Wait point key\n   * @param payload - Optional payload to record with the wait point\n   * @returns The payload supplied by the corresponding `resolve` call\n   */\n  wait(key: string, payload?: any): any;\n\n  /**\n   * Resolves a waiting workflow execution, causing it to resume.\n   * @param executionId - The execution to resume\n   * @param key - Wait point key to resolve\n   * @param callback - Callback receiving the wait payload; its return value is forwarded to `wait`\n   * @returns A promise that resolves once the resolve has been recorded\n   */\n  resolve(executionId: string, key: string, callback: (waitPayload: any) => any): Promise<void>;\n}\n\nconst api = (): PlatformWorkflowAPI =>\n  (globalThis as unknown as { tailor: { workflow: PlatformWorkflowAPI } }).tailor.workflow;\n\n/**\n * See {@link PlatformWorkflowAPI.startWorkflow}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.startWorkflow}\n * @returns The execution ID of the started workflow\n */\nconst startWorkflow: PlatformWorkflowAPI[\"startWorkflow\"] = (...args) =>\n  api().startWorkflow(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.resumeWorkflowExecution}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.resumeWorkflowExecution}\n * @returns The execution ID of the resumed workflow\n */\nconst resumeWorkflowExecution: PlatformWorkflowAPI[\"resumeWorkflowExecution\"] = (...args) =>\n  api().resumeWorkflowExecution(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.execJobFunction}.\n *\n * @deprecated since 2.5.0 — call the target job's own `.start()` method\n * instead. codemod: v3/remove-workflow-exec-job-function\n * @param args - Forwarded to {@link PlatformWorkflowAPI.execJobFunction}\n * @returns The job's return value\n */\nconst execJobFunction: PlatformWorkflowAPI[\"execJobFunction\"] = (...args) =>\n  api().execJobFunction(...args);\n\nconst wait: PlatformWorkflowAPI[\"wait\"] = (...args) => api().wait(...args);\n\nconst resolve: PlatformWorkflowAPI[\"resolve\"] = (...args) => api().resolve(...args);\n\n/** Runtime wrapper namespace for `tailor.workflow`. */\nexport const workflow = {\n  startWorkflow,\n  resumeWorkflowExecution,\n  // oxlint-disable-next-line typescript/no-deprecated -- Keep the deprecated runtime export wired for backward compatibility.\n  execJobFunction,\n  wait,\n  resolve,\n} as const satisfies PlatformWorkflowAPI;\n"],"mappings":"AAqGA,MAAM,QACH,WAAwE,OAAO,SAkCrE,EAAW,CACtB,eA5B2D,GAAG,IAC9D,IAAI,CAAC,CAAC,cAAc,GAAG,CAAI,EA4B3B,yBArB+E,GAAG,IAClF,IAAI,CAAC,CAAC,wBAAwB,GAAG,CAAI,EAsBrC,iBAZ+D,GAAG,IAClE,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAI,EAY7B,MAVyC,GAAG,IAAS,IAAI,CAAC,CAAC,KAAK,GAAG,CAAI,EAWvE,SAT+C,GAAG,IAAS,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAI,CAUlF"}