{"version":3,"file":"context-D0QjfxzD.mjs","names":[],"sources":["../src/runtime/context.ts"],"sourcesContent":["/**\n * Execution context utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.context` runtime API.\n * At runtime this delegates to `globalThis.tailor.context`.\n * @example\n * import { context } from \"@tailor-platform/sdk/runtime\";\n *\n * const invoker = context.getInvoker();\n * if (invoker) {\n *   console.log(invoker.id, invoker.type, invoker.attributes, invoker.attributeList);\n * }\n */\n\nimport type { TailorPrincipal } from \"#/runtime/types\";\n\n/**\n * Information about the invoker of the current function execution.\n *\n * Matches the public `TailorPrincipal` shape — `attributes` is the attribute\n * map and `attributeList` is the array of attribute IDs.\n */\nexport type Invoker = TailorPrincipal;\n\n/**\n * Raw platform-side invoker payload returned by `tailor.context.getInvoker()`.\n * The wrapper normalizes this into {@link Invoker}.\n * @internal\n */\nexport interface ContextInvoker {\n  /** The invoker's ID */\n  id: string;\n  /** The invoker's type */\n  type: \"user\" | \"machine_user\";\n  /** The workspace ID */\n  workspaceId: string;\n  /** The invoker's attribute IDs */\n  attributes: string[];\n  /** The invoker's attribute map */\n  attributeMap: Record<string, unknown>;\n}\n\n/**\n * Platform API surface for `tailor.context`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.context`.\n * @internal\n */\nexport interface PlatformContextAPI {\n  getInvoker(): ContextInvoker | null;\n}\n\n/** Runtime wrapper API for execution context utilities. */\nexport interface TailorContextAPI {\n  /**\n   * Returns information about the current invoker.\n   * @returns Invoker details, or `null` for anonymous invocations\n   */\n  getInvoker(): Invoker | null;\n}\n\n/**\n * Returns information about the invoker of the current function execution,\n * or `null` for anonymous invocations.\n * @returns Invoker details, or `null` when the call is anonymous\n */\nfunction getInvoker(): Invoker | null {\n  const raw = (\n    globalThis as unknown as { tailor: { context: PlatformContextAPI } }\n  ).tailor.context.getInvoker();\n  if (!raw) return null;\n  return {\n    id: raw.id,\n    type: raw.type,\n    workspaceId: raw.workspaceId,\n    attributes: raw.attributeMap as Invoker[\"attributes\"],\n    attributeList: raw.attributes as Invoker[\"attributeList\"],\n  };\n}\n\n/** Runtime wrapper namespace for `tailor.context`. */\nexport const context = { getInvoker } as const satisfies TailorContextAPI;\n"],"mappings":"AAiEA,SAAS,YAA6B,CACpC,IAAM,EACJ,WACA,OAAO,QAAQ,WAAW,EAE5B,OADK,EACE,CACL,GAAI,EAAI,GACR,KAAM,EAAI,KACV,YAAa,EAAI,YACjB,WAAY,EAAI,aAChB,cAAe,EAAI,UACrB,EAPiB,IAQnB,CAGA,MAAa,EAAU,CAAE,UAAW"}