@xylabs/axios 5.0.83 → 5.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,19 +119,26 @@ static create(config?): Axios;
119
119
  ***
120
120
 
121
121
  ```ts
122
- function axiosJsonConfig(__namedParameters?): RawAxiosJsonRequestConfig;
122
+ function axiosJsonConfig(config?): RawAxiosJsonRequestConfig;
123
123
  ```
124
124
 
125
+ Creates an Axios config preconfigured for JSON requests with optional gzip compression.
126
+ Request bodies exceeding `compressLength` (default 1024 bytes) are automatically gzip-compressed.
127
+
125
128
  ## Parameters
126
129
 
127
- ### \_\_namedParameters?
130
+ ### config?
128
131
 
129
132
  `RawAxiosJsonRequestConfig` = `{}`
130
133
 
134
+ Base Axios config, optionally including a `compressLength` threshold
135
+
131
136
  ## Returns
132
137
 
133
138
  `RawAxiosJsonRequestConfig`
134
139
 
140
+ A fully configured Axios request config with JSON transforms
141
+
135
142
  ### variables
136
143
 
137
144
  ### <a id="axios"></a>axios
@@ -1,6 +1,13 @@
1
1
  import type { RawAxiosRequestConfig } from 'axios';
2
+ /** Axios request config extended with an optional gzip compression threshold. */
2
3
  export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
3
4
  compressLength?: number;
4
5
  };
6
+ /**
7
+ * Creates an Axios config preconfigured for JSON requests with optional gzip compression.
8
+ * Request bodies exceeding `compressLength` (default 1024 bytes) are automatically gzip-compressed.
9
+ * @param config - Base Axios config, optionally including a `compressLength` threshold
10
+ * @returns A fully configured Axios request config with JSON transforms
11
+ */
5
12
  export declare function axiosJsonConfig({ compressLength, headers, ...config }?: RawAxiosJsonRequestConfig): RawAxiosJsonRequestConfig;
6
13
  //# sourceMappingURL=axiosJsonConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"axiosJsonConfig.d.ts","sourceRoot":"","sources":["../../src/axiosJsonConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAKlD,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAUvG,wBAAgB,eAAe,CAAC,EAC9B,cAAc,EAAE,OAAO,EAAE,GAAG,MAAM,EACnC,GAAE,yBAA8B,GAAG,yBAAyB,CAoB5D"}
1
+ {"version":3,"file":"axiosJsonConfig.d.ts","sourceRoot":"","sources":["../../src/axiosJsonConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIlD,iFAAiF;AAEjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAUvG;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAC9B,cAAc,EAAE,OAAO,EAAE,GAAG,MAAM,EACnC,GAAE,yBAA8B,GAAG,yBAAyB,CAoB5D"}
@@ -1 +1 @@
1
- {"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// 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\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;AAKrB,SAAS,aAAa,SAA+C;AACnE,QAAM,eAAe,IAAI,aAAa;AACtC,eAAa,IAAI,UAAU,mCAAmC;AAC9D,eAAa,IAAI,gBAAgB,kBAAkB;AACnD,aAAW,CAAC,KAAK,KAAK,KAA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../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,KAAK,MAAM,IAAI;AAAA,MACxB,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACL;AACF;;;AC3CA,SAAS,aAAa;AAKtB,SAAS,WAAW,MAAc,IAAY,SAAiB,SAAS;AACtE,SAAO,KAAK,GAAG,IAAI,8BAA8B,EAAE,WAAW;AAChE;AAGO,IAAM,YAAN,MAAM,mBAAkB,MAAM;AAAA,EACnC,YAAY,QAAoC;AAC9C,eAAW,aAAa,iBAAiB;AAEzC,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,YAAY,SAAoC,CAAC,GAA8B;AACpF,WAAO,gBAAgB,MAAM;AAAA,EAC/B;AAAA,EAEA,OAAO,OAAO,QAAoC;AAChD,WAAO,IAAI,MAAM,KAAK,YAAY,MAAM,CAAC;AAAA,EAC3C;AACF;;;AFpBA,SAAS,QAAAC,aAAY;AAEd,IAAM,YAAY,IAAIC,OAAM,gBAAgB,CAAC;AAG7C,IAAM,QAAQ;","names":["Axios","headers","gzip","Axios"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/axios",
3
- "version": "5.0.83",
3
+ "version": "5.0.84",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "axios",
@@ -46,9 +46,9 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/pako": "~2.0.4",
49
- "@xylabs/logger": "~5.0.83",
50
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
51
- "@xylabs/tsconfig": "~7.4.11",
49
+ "@xylabs/logger": "~5.0.84",
50
+ "@xylabs/ts-scripts-yarn3": "~7.4.13",
51
+ "@xylabs/tsconfig": "~7.4.13",
52
52
  "axios": "^1.13.6",
53
53
  "typescript": "~5.9.3",
54
54
  "vitest": "~4.0.18"