{"version":3,"sources":["../src/client/revenuecat.ts","../src/index.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios'\nimport axios from 'axios'\n\nimport type { Attribute, Offerings, Subscribers, XPlatform } from '../types'\n\nexport default class Revenuecat {\n  private readonly secretKey: string\n  private readonly iosKey: string\n  private readonly androidKey: string\n  private readonly url = 'https://api.revenuecat.com/v1'\n  private axios: AxiosInstance\n\n  /**\n   * Construct a new Revenuecat instance\n   * @param token Revenuecat API token\n   */\n  constructor({ secretKey, iosKey, androidKey }: { secretKey: string; iosKey: string; androidKey: string }) {\n    this.secretKey = secretKey\n    this.iosKey = iosKey\n    this.androidKey = androidKey\n    this.axios = axios.create({\n      baseURL: this.url,\n    })\n  }\n\n  /**\n   * Creates authorization header\n   * @returns Authorization header value\n   */\n  private createAuthorizationHeader(platform?: XPlatform): string {\n    switch (platform) {\n      case 'ios':\n        return `Bearer ${this.iosKey}`\n      case 'android':\n        return `Bearer ${this.androidKey}`\n      default:\n        return `Bearer ${this.secretKey}`\n    }\n  }\n\n  //   Customers\n\n  /**\n   * Gets the offerings for your app.\n  */\n  getSubscriptions = async ({ userId, platform }: { userId: string; platform?: XPlatform }): Promise<Subscribers> => {\n    let headers = {\n      'Content-Type': 'application/json',\n      'Authorization': this.createAuthorizationHeader(platform),\n    }\n    if (platform)\n      headers = Object.assign(headers, { 'x-platform': platform })\n\n    const { data } = await this.axios.get(`/subscribers/${userId}`, {\n      headers,\n    })\n    return data\n  }\n\n  postSubscriptionsAttributes = async ({ userId, data }: { userId: string; platform?: XPlatform; data: Attribute }) => {\n    const headers = {\n      'Content-Type': 'application/json',\n      'Authorization': this.createAuthorizationHeader(),\n      'app_user_id': userId,\n    }\n\n    const { data: res } = await this.axios.post(`/subscribers/${userId}/attributes`, data, {\n      headers,\n    })\n    return res\n  }\n\n  getOfferings = async ({ userId, platform }: { userId: string; platform: XPlatform }): Promise<Offerings> => {\n    let headers = {\n      'Content-Type': 'application/json',\n      'Authorization': this.createAuthorizationHeader(platform),\n      'app_user_id': userId,\n    }\n    if (platform)\n      headers = Object.assign(headers, { 'x-platform': platform })\n\n    const { data } = await this.axios.get(`/subscribers/${userId}/offerings`, {\n      headers,\n    })\n    return data\n  }\n}\n","import Revenuecat from './client/revenuecat'\n\nexport * from './types'\nexport { Revenuecat }\nexport default Revenuecat\n"],"mappings":"AACA,OAAOA,MAAW,QAIlB,IAAqBC,EAArB,KAAgC,CACb,UACA,OACA,WACA,IAAM,gCACf,MAMR,YAAY,CAAE,UAAAC,EAAW,OAAAC,EAAQ,WAAAC,CAAW,EAA8D,CACxG,KAAK,UAAYF,EACjB,KAAK,OAASC,EACd,KAAK,WAAaC,EAClB,KAAK,MAAQJ,EAAM,OAAO,CACxB,QAAS,KAAK,GAChB,CAAC,CACH,CAMQ,0BAA0BK,EAA8B,CAC9D,OAAQA,EAAU,CAChB,IAAK,MACH,MAAO,UAAU,KAAK,SACxB,IAAK,UACH,MAAO,UAAU,KAAK,aACxB,QACE,MAAO,UAAU,KAAK,WAC1B,CACF,CAOA,iBAAmB,MAAO,CAAE,OAAAC,EAAQ,SAAAD,CAAS,IAAsE,CACjH,IAAIE,EAAU,CACZ,eAAgB,mBAChB,cAAiB,KAAK,0BAA0BF,CAAQ,CAC1D,EACIA,IACFE,EAAU,OAAO,OAAOA,EAAS,CAAE,aAAcF,CAAS,CAAC,GAE7D,GAAM,CAAE,KAAAG,CAAK,EAAI,MAAM,KAAK,MAAM,IAAI,gBAAgBF,IAAU,CAC9D,QAAAC,CACF,CAAC,EACD,OAAOC,CACT,EAEA,4BAA8B,MAAO,CAAE,OAAAF,EAAQ,KAAAE,CAAK,IAAiE,CACnH,IAAMD,EAAU,CACd,eAAgB,mBAChB,cAAiB,KAAK,0BAA0B,EAChD,YAAeD,CACjB,EAEM,CAAE,KAAMG,CAAI,EAAI,MAAM,KAAK,MAAM,KAAK,gBAAgBH,eAAqBE,EAAM,CACrF,QAAAD,CACF,CAAC,EACD,OAAOE,CACT,EAEA,aAAe,MAAO,CAAE,OAAAH,EAAQ,SAAAD,CAAS,IAAmE,CAC1G,IAAIE,EAAU,CACZ,eAAgB,mBAChB,cAAiB,KAAK,0BAA0BF,CAAQ,EACxD,YAAeC,CACjB,EACID,IACFE,EAAU,OAAO,OAAOA,EAAS,CAAE,aAAcF,CAAS,CAAC,GAE7D,GAAM,CAAE,KAAAG,CAAK,EAAI,MAAM,KAAK,MAAM,IAAI,gBAAgBF,cAAoB,CACxE,QAAAC,CACF,CAAC,EACD,OAAOC,CACT,CACF,EClFA,IAAOE,EAAQC","names":["axios","Revenuecat","secretKey","iosKey","androidKey","platform","userId","headers","data","res","src_default","Revenuecat"]}