{"version":3,"sources":["../src/api/gateway.api.ts"],"names":["API_KEY_HEADER","GatewayApi","opts","filters","apiClient","ApiClient","url","urlAppendSearchParams","response","NaluriChatError","version_default"],"mappings":";+JAQA,IAAMA,EAAiB,YAUVC,EAAN,KAAiB,CACL,OACA,OACA,WACT,oBAER,YAAYC,EAAyB,CACnC,OAAO,OAAO,KAAMA,CAAI,CAC1B,CAEA,MAAM,aAAaC,EAA4B,CAC7C,IAAMC,EAAY,IAAIC,EAAU,KAAK,WAAY,KAAK,mBAAmB,EAEnEC,EAAMC,EAAsB,GAAG,KAAK,MAAM,0BAA2B,CACzE,OAAQ,KAAK,WAAW,UAAU,EAClC,UAAW,KAAK,WAAW,iBAAiB,EAC5C,GAAGJ,CACL,CAAC,EAEKK,EAAW,MAAMJ,EAAU,MAAME,EAAK,CAC1C,OAAQ,MACR,QAAS,KAAK,WAAW,CAC3B,CAAC,EAED,GAAI,CAACE,EAAS,GACZ,MAAM,IAAIC,EAAgB,CACxB,KAAM,OACN,QAAS,uBACX,CAAC,EAIH,OADc,MAAMD,EAAS,KAAK,CAEpC,CAEU,YAAa,CACrB,MAAO,CACL,CAACR,CAAc,EAAG,KAAK,OACvB,OAAQ,mBACR,eAAgB,mBAChB,aAAc,wBAAwBU,CAAO,KAC7C,mBAAoBA,CACtB,CACF,CACF","sourcesContent":["import { AccountApi } from '@/api/account.api';\nimport { NaluriChatError } from '@/errors';\nimport { CoachProfile } from '@/types';\nimport { CoachListFilters } from '@/types/gateway';\nimport { ApiClient } from '@/utils/apiClient';\nimport { urlAppendSearchParams } from '@/utils/url';\n\nimport version from '@/utils/version';\nconst API_KEY_HEADER = 'x-api-key';\n\nexport interface GatewayApiOptions {\n  apiUrl: string;\n  apiKey: string;\n  accountApi: AccountApi;\n  timeoutMs?: number;\n  onRefreshTokenError?: () => void | Promise<void>;\n}\n\nexport class GatewayApi {\n  private readonly apiUrl: string;\n  private readonly apiKey: string;\n  private readonly accountApi: AccountApi;\n  private onRefreshTokenError?: () => Promise<void>;\n\n  constructor(opts: GatewayApiOptions) {\n    Object.assign(this, opts);\n  }\n\n  async getCoachList(filters?: CoachListFilters) {\n    const apiClient = new ApiClient(this.accountApi, this.onRefreshTokenError);\n\n    const url = urlAppendSearchParams(`${this.apiUrl}/entitlement/coach-list`, {\n      userId: this.accountApi.getUserId(),\n      reference: this.accountApi.getUserReference(),\n      ...filters,\n    });\n\n    const response = await apiClient.fetch(url, {\n      method: 'GET',\n      headers: this.getHeaders(),\n    });\n\n    if (!response.ok) {\n      throw new NaluriChatError({\n        code: '4004',\n        message: 'Failed to get coaches',\n      });\n    }\n\n    const data = (await response.json()) as CoachProfile[];\n    return data;\n  }\n\n  protected getHeaders() {\n    return {\n      [API_KEY_HEADER]: this.apiKey,\n      Accept: 'application/json',\n      'Content-Type': 'application/json',\n      'User-Agent': `Naluri Chat SDK /JS (${version}})`,\n      'x-nl-sdk-version': version,\n    };\n  }\n}\n"]}