{"version":3,"sources":["../../src/index.ts","../../src/axiosJsonConfig.ts","../../src/AxiosJson.ts"],"sourcesContent":["import { Axios } from 'axios'\n\nimport { axiosJsonConfig } from './axiosJsonConfig.ts'\n\nexport * from './AxiosJson.ts'\nexport { gzip } from 'pako'\n\nexport const axiosJson = new Axios(axiosJsonConfig())\n\n/** @deprecated use axiosJson instead */\nexport const axios = axiosJson\n\nexport { axiosJsonConfig } from './axiosJsonConfig.ts'\n","import type { RawAxiosRequestConfig } from 'axios'\nimport { AxiosHeaders } from 'axios'\nimport { gzip } from 'pako'\n\n/** Axios request config extended with an optional gzip compression threshold. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nfunction buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n  const axiosHeaders = new AxiosHeaders()\n  axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n  axiosHeaders.set('Content-Type', 'application/json')\n  for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)\n  return axiosHeaders\n}\n\n/**\n * Creates an Axios config preconfigured for JSON requests with optional gzip compression.\n * Request bodies exceeding `compressLength` (default 1024 bytes) are automatically gzip-compressed.\n * @param config - Base Axios config, optionally including a `compressLength` threshold\n * @returns A fully configured Axios request config with JSON transforms\n */\nexport function axiosJsonConfig({\n  compressLength, headers, ...config\n}: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n  return {\n    headers: buildHeaders(headers),\n    transformRequest: (data, headers) => {\n      const json = JSON.stringify(data)\n      if (headers !== undefined && data && json.length > (compressLength ?? 1024)) {\n        headers.set('Content-Encoding', 'gzip')\n        return gzip(json).buffer\n      }\n      return json\n    },\n    transformResponse: (data) => {\n      try {\n        return JSON.parse(data)\n      } catch {\n        return null\n      }\n    },\n    ...config,\n  }\n}\n","import type { Logger } from '@xylabs/logger'\nimport { Axios } from 'axios'\n\nimport type { RawAxiosJsonRequestConfig } from './axiosJsonConfig.ts'\nimport { axiosJsonConfig } from './axiosJsonConfig.ts'\n\nfunction deprecated(from: string, to: string, logger: Logger = console) {\n  logger.warn(`${from} is deprecated. Please use ${to} instead.`)\n}\n\n/** @deprecated use axiosJsonConfig instead */\nexport class AxiosJson extends Axios {\n  constructor(config?: RawAxiosJsonRequestConfig) {\n    deprecated('AxiosJson', 'axiosJsonConfig')\n    // eslint-disable-next-line sonarjs/deprecation, @typescript-eslint/no-deprecated\n    super(AxiosJson.axiosConfig(config))\n  }\n\n  static axiosConfig(config: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n    return axiosJsonConfig(config)\n  }\n\n  static create(config?: RawAxiosJsonRequestConfig) {\n    return new Axios(this.axiosConfig(config))\n  }\n}\n"],"mappings":";AAAA,SAAS,SAAAA,cAAa;;;ACCtB,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AAMrB,SAAS,aAAa,SAA+C;AACnE,QAAM,eAAe,IAAI,aAAa;AACtC,eAAa,IAAI,UAAU,mCAAmC;AAC9D,eAAa,IAAI,gBAAgB,kBAAkB;AACnD,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,CAAC,CAAC,EAAG,cAAa,IAAI,KAAK,KAAK;AACrF,SAAO;AACT;AAQO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EAAgB;AAAA,EAAS,GAAG;AAC9B,IAA+B,CAAC,GAA8B;AAC5D,SAAO;AAAA,IACL,SAAS,aAAa,OAAO;AAAA,IAC7B,kBAAkB,CAAC,MAAMC,aAAY;AACnC,YAAM,OAAO,KAAK,UAAU,IAAI;AAChC,UAAIA,aAAY,UAAa,QAAQ,KAAK,UAAU,kBAAkB,OAAO;AAC3E,QAAAA,SAAQ,IAAI,oBAAoB,MAAM;AACtC,eAAO,KAAK,IAAI,EAAE;AAAA,MACpB;AACA,aAAO;AAAA,IACT;AAAA,IACA,mBAAmB,CAAC,SAAS;AAC3B,UAAI;AACF,eAAO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