{"version":3,"sources":["../../src/shared/shared.actions.ts","../../src/shared/shared.types.ts","../../src/modules/licenseKey/licenseKey.action.ts","../../src/modules/licenseKey/index.ts"],"sourcesContent":["import { fetch } from \"undici\";\nimport { join } from \"node:path\";\n\nimport { LemonsqueezyDataType } from \"~/shared\";\n\nimport type {\n  BaseLemonsqueezyResponse,\n  LemonsqueezyOptions,\n  PaginatedBaseLemonsqueezyResponse,\n} from \"~/shared\";\n\nexport async function requestLemonSqueeze<\n  TResponse extends\n    | BaseLemonsqueezyResponse<any>\n    | PaginatedBaseLemonsqueezyResponse<any>,\n  TData extends Record<string, any> = Record<string, any>\n>({\n  apiKey,\n  apiVersion = \"v1\",\n  baseUrl = \"https://api.lemonsqueezy.com\",\n  data,\n  headers,\n  include,\n  method = \"GET\",\n  page,\n  params,\n  path,\n}: LemonsqueezyOptions<TData>): Promise<TResponse> {\n  try {\n    const url = new URL(join(apiVersion, path), baseUrl);\n\n    if (include)\n      url.searchParams.append(\n        \"include\",\n        include.map((i) => LemonsqueezyDataType[i]).join(\",\")\n      );\n\n    if (page) url.searchParams.append(\"page\", page.toString());\n\n    if (params && method === \"GET\")\n      Object.entries(params).forEach(([key, value]) =>\n        url.searchParams.append(key, value)\n      );\n\n    const response = await fetch(url.href, {\n      headers: {\n        Accept: \"application/vnd.api+json\",\n        Authorization: `Bearer ${apiKey}`,\n        \"Content-Type\": \"application/vnd.api+json\",\n        ...headers,\n      },\n      method,\n      ...(data && method !== \"GET\"\n        ? {\n            body: JSON.stringify(data),\n          }\n        : {}),\n    });\n    if (!response.ok) {\n      const errorsJson = (await response.json()) as {\n        errors: Array<{\n          detail: string;\n          status: number;\n          title: string;\n        }>;\n      };\n      throw {\n        status: response.status,\n        message: response.statusText,\n        errors: errorsJson.errors,\n      };\n    }\n\n    const json = (await response.json()) as TResponse;\n    if (json.errors && json.errors.length > 0) throw json;\n\n    return json;\n  } catch (error) {\n    throw error;\n  }\n}\n","import type { RequestInit } from \"undici\";\n\nexport interface SharedModuleOptions {\n  apiKey: string;\n  page?: number;\n  include?: Array<keyof typeof LemonsqueezyDataType>;\n}\n\nexport interface SharedLemonsqueezyOptions {\n  apiVersion?: \"v1\";\n  baseUrl?: string;\n}\n\nexport interface LemonsqueezyOptions<\n  TData extends Record<string, any> = Record<string, any>\n> extends Omit<RequestInit, \"body\">,\n    SharedLemonsqueezyOptions,\n    SharedModuleOptions {\n  data?: TData;\n  params?: Record<string, any>;\n  method?:\n    | \"CONNECT\"\n    | \"DELETE\"\n    | \"GET\"\n    | \"HEAD\"\n    | \"OPTIONS\"\n    | \"PATCH\"\n    | \"POST\"\n    | \"PUT\"\n    | \"TRACE\";\n  path: string;\n}\n\nexport enum LemonsqueezyDataType {\n  checkouts = \"checkouts\",\n  customers = \"customers\",\n  discounts = \"discounts\",\n  files = \"files\",\n  license_key_instances = \"license-key-instances\",\n  license_keys = \"license-keys\",\n  order_items = \"order-items\",\n  orders = \"orders\",\n  products = \"products\",\n  stores = \"stores\",\n  subscriptions = \"subscriptions\",\n  subscription_invoices = \"subscription-invoices\",\n  users = \"users\",\n  variants = \"variants\",\n}\n\nexport interface BaseLemonsqueezyResponse<\n  TData,\n  TLinks = {\n    self: string;\n  }\n> {\n  data: TData;\n  errors?: Array<{\n    detail: string;\n    status: string | number;\n    title: string;\n  }>;\n  jsonapi: {\n    version: string;\n  };\n  links: TLinks;\n}\n\nexport interface PaginatedBaseLemonsqueezyResponse<\n  TData,\n  TLinks = {\n    first: string;\n    last: string;\n  }\n> extends BaseLemonsqueezyResponse<TData, TLinks> {\n  meta: {\n    page: {\n      currentPage: number;\n      from: number;\n      lastPage: number;\n      perPage: number;\n      to: number;\n      total: number;\n    };\n  };\n}\n","import { requestLemonSqueeze } from \"~/shared\";\n\nimport type {\n  ListAllLicenseKeysOptions,\n  ListAllLicenseKeysResult,\n  RetrieveLicenseKeyOptions,\n  RetrieveLicenseKeyResult,\n} from \"./licenseKey.types\";\nimport type { SharedModuleOptions } from \"~/shared\";\n\n/**\n * List all license keys\n *\n * @description Returns a paginated list of license keys\n *\n * @docs https://docs.lemonsqueezy.com/api/license-keys#list-all-license-keys\n *\n * @param {Object} [options]\n *\n * @returns Returns a paginated list of license key objects ordered by `id`\n */\nexport async function listAllLicenseKeys(\n  options: ListAllLicenseKeysOptions & SharedModuleOptions\n): Promise<ListAllLicenseKeysResult> {\n  const { orderId, orderItemId, productId, storeId, ...rest } = options;\n\n  return requestLemonSqueeze<ListAllLicenseKeysResult>({\n    params: {\n      ...(orderId ? { order_id: orderId } : {}),\n      ...(orderItemId ? { order_item_id: orderItemId } : {}),\n      ...(productId ? { product_id: productId } : {}),\n      ...(storeId ? { store_id: storeId } : {}),\n    },\n    path: \"/license-keys\",\n    ...rest,\n  });\n}\n\n/**\n * Retrieve license key\n *\n * @description Retrieves the license key with the given ID\n *\n * @docs https://docs.lemonsqueezy.com/api/license-keys#retrieve-a-license-key\n *\n * @param {String} options.id - The ID of the license key to retrieve\n *\n * @returns A license key object\n */\nexport async function retrieveLicenseKey(\n  options: RetrieveLicenseKeyOptions & SharedModuleOptions\n): Promise<RetrieveLicenseKeyResult> {\n  const { id, ...rest } = options;\n\n  return requestLemonSqueeze<RetrieveLicenseKeyResult>({\n    path: `/license-keys/${id}`,\n    ...rest,\n  });\n}\n","import { listAllLicenseKeys, retrieveLicenseKey } from \"./licenseKey.action\";\n\nexport { listAllLicenseKeys, retrieveLicenseKey };\n\nexport type {\n  LemonsqueezyLicenseKey,\n  ListAllLicenseKeysOptions,\n  ListAllLicenseKeysResult,\n  RetrieveLicenseKeyOptions,\n  RetrieveLicenseKeyResult,\n} from \"./licenseKey.types\";\n\nexport default {\n  listAllLicenseKeys,\n  retrieveLicenseKey,\n} as const;\n"],"mappings":"AAAA,OAAS,SAAAA,MAAa,SACtB,OAAS,QAAAC,MAAY,YAUrB,eAAsBC,EAKpB,CACA,OAAAC,EACA,WAAAC,EAAa,KACb,QAAAC,EAAU,+BACV,KAAAC,EACA,QAAAC,EACA,QAAAC,EACA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AAA,SAAW,WAdDA,OAAA,ICZZ,eAAsBC,EACpBC,EACmC,CACnC,GAAM,CAAE,QAAAC,EAAS,YAAAC,EAAa,UAAAC,EAAW,QAAAC,EAAS,GAAGC,CAAK,EAAIL,EAE9D,OAAOM,EAA8C,CACnD,OAAQ,CACN,GAAIL,EAAU,CAAE,SAAUA,CAAQ,EAAI,CAAC,EACvC,GAAIC,EAAc,CAAE,cAAeA,CAAY,EAAI,CAAC,EACpD,GAAIC,EAAY,CAAE,WAAYA,CAAU,EAAI,CAAC,EAC7C,GAAIC,EAAU,CAAE,SAAUA,CAAQ,EAAI,CAAC,CACzC,EACA,KAAM,gBACN,GAAGC,CACL,CAAC,CACH,CAaA,eAAsBE,EACpBP,EACmC,CACnC,GAAM,CAAE,GAAAQ,EAAI,GAAGH,CAAK,EAAIL,EAExB,OAAOM,EAA8C,CACnD,KAAM,iBAAiBE,CAAE,GACzB,GAAGH,CACL,CAAC,CACH,CC9CA,IAAOI,EAAQ,CACb,mBAAAC,EACA,mBAAAC,CACF","names":["fetch","join","requestLemonSqueeze","apiKey","apiVersion","baseUrl","data","headers","include","method","page","params","path","url","join","i","LemonsqueezyDataType","key","value","response","fetch","errorsJson","json","error","LemonsqueezyDataType","listAllLicenseKeys","options","orderId","orderItemId","productId","storeId","rest","requestLemonSqueeze","retrieveLicenseKey","id","licenseKey_default","listAllLicenseKeys","retrieveLicenseKey"]}