{"version":3,"sources":["../src/client-sdk/services/api-keys/api-keys-api.service.ts"],"sourcesContent":["import { formatApiErrorForOperation } from \"@/client-sdk/services/_shared/format-api-error\";\nimport { DEFAULT_ENDPOINT } from \"@/internal/constants\";\n\nexport interface RoleBinding {\n  id: string;\n  role: \"ADMIN\" | \"MEMBER\" | \"VIEWER\";\n  scopeType: \"ORGANIZATION\" | \"TEAM\" | \"PROJECT\";\n  scopeId: string;\n}\n\nexport interface ApiKeyInfo {\n  id: string;\n  name: string;\n  description: string | null;\n  createdAt: string;\n  expiresAt: string | null;\n  lastUsedAt: string | null;\n  revokedAt: string | null;\n  roleBindings: RoleBinding[];\n}\n\nexport interface CreateApiKeyInput {\n  keyType?: \"personal\" | \"service\";\n  name: string;\n  description?: string;\n  expiresAt?: string;\n  bindings?: Array<{\n    role: \"ADMIN\" | \"MEMBER\" | \"VIEWER\";\n    scopeType: \"ORGANIZATION\" | \"TEAM\" | \"PROJECT\";\n    scopeId: string;\n  }>;\n  projectIds?: string[];\n}\n\nexport interface CreatedApiKey {\n  token: string;\n  apiKey: {\n    id: string;\n    name: string;\n    createdAt: string;\n  };\n}\n\nexport class ApiKeysApiError extends Error {\n  constructor(\n    message: string,\n    public readonly operation: string,\n    public readonly originalError?: unknown,\n  ) {\n    super(message);\n    this.name = \"ApiKeysApiError\";\n  }\n}\n\nexport class ApiKeysApiService {\n  private readonly endpoint: string;\n  private readonly apiKey: string;\n\n  constructor(config?: { endpoint?: string; apiKey?: string }) {\n    this.endpoint = (config?.endpoint ?? process.env.LANGWATCH_ENDPOINT ?? DEFAULT_ENDPOINT).replace(/\\/+$/, \"\");\n    this.apiKey = config?.apiKey ?? process.env.LANGWATCH_API_KEY ?? \"\";\n  }\n\n  private headers(): Record<string, string> {\n    return {\n      Authorization: `Bearer ${this.apiKey}`,\n      \"Content-Type\": \"application/json\",\n    };\n  }\n\n  private async request<T>(operation: string, path: string, init?: RequestInit): Promise<T> {\n    const response = await fetch(`${this.endpoint}${path}`, {\n      ...init,\n      headers: { ...this.headers(), ...(init?.headers ?? {}) },\n    });\n    if (!response.ok) {\n      let parsedBody: unknown;\n      try {\n        parsedBody = await response.json();\n      } catch {\n        parsedBody = await response.text();\n      }\n      const message = formatApiErrorForOperation({\n        operation,\n        error: parsedBody,\n        options: { status: response.status },\n      });\n      throw new ApiKeysApiError(message, operation, parsedBody);\n    }\n    return (await response.json()) as T;\n  }\n\n  async list(): Promise<ApiKeyInfo[]> {\n    const { data } = await this.request<{ data: ApiKeyInfo[] }>(\n      \"list API keys\",\n      \"/api/api-keys\",\n    );\n    return data;\n  }\n\n  async create(input: CreateApiKeyInput): Promise<CreatedApiKey> {\n    return this.request<CreatedApiKey>(\n      \"create API key\",\n      \"/api/api-keys\",\n      { method: \"POST\", body: JSON.stringify(input) },\n    );\n  }\n\n  async revoke(id: string): Promise<{ success: boolean }> {\n    return this.request<{ success: boolean }>(\n      `revoke API key \"${id}\"`,\n      `/api/api-keys/${encodeURIComponent(id)}`,\n      { method: \"DELETE\" },\n    );\n  }\n}\n"],"mappings":";;;;;;;;;;;;AA2CO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACE,SACgB,WACA,eAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,oBAAN,MAAwB;AAAA,EAI7B,YAAY,QAAiD;AA1D/D;AA2DI,SAAK,aAAY,4CAAQ,aAAR,YAAoB,QAAQ,IAAI,uBAAhC,YAAsD,kBAAkB,QAAQ,QAAQ,EAAE;AAC3G,SAAK,UAAS,4CAAQ,WAAR,YAAkB,QAAQ,IAAI,sBAA9B,YAAmD;AAAA,EACnE;AAAA,EAEQ,UAAkC;AACxC,WAAO;AAAA,MACL,eAAe,UAAU,KAAK,MAAM;AAAA,MACpC,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,MAAc,QAAW,WAAmB,MAAc,MAAgC;AAtE5F;AAuEI,UAAM,WAAW,MAAM,MAAM,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