@xylabs/axios 5.0.11 → 5.0.12
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/dist/neutral/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/AxiosJson.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AxiosJson.ts","../../src/AxiosJsonUncompressed.ts","../../src/index.ts"],"sourcesContent":["import type { Logger } from '@xylabs/logger'\nimport type { AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { Axios, 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\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({\n
|
|
1
|
+
{"version":3,"sources":["../../src/AxiosJson.ts","../../src/AxiosJsonUncompressed.ts","../../src/index.ts"],"sourcesContent":["import type { Logger } from '@xylabs/logger'\nimport type { AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { Axios, 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\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({\n compressLength, headers, ...config\n }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.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\n private static 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","import type { Logger } from '@xylabs/logger'\nimport type { AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { Axios, AxiosHeaders } from 'axios'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestUncompressedConfig<D = any> = RawAxiosRequestConfig<D>\n\nexport class AxiosJsonUncompressed extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestUncompressedConfig) {\n super(AxiosJsonUncompressed.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ headers, ...config }: RawAxiosJsonRequestUncompressedConfig = {}): RawAxiosJsonRequestUncompressedConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data) => {\n const json = JSON.stringify(data)\n return JSON.stringify(json)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestUncompressedConfig['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","import { AxiosJson } from './AxiosJson.ts'\nimport { AxiosJsonUncompressed } from './AxiosJsonUncompressed.ts'\n\nexport * from './AxiosJson.ts'\nexport * from './AxiosJsonUncompressed.ts'\nexport { gzip } from 'pako'\n\nexport const axios = new AxiosJson()\nexport const axiosUncompressed = new AxiosJsonUncompressed()\n"],"mappings":";AAEA,SAAS,OAAO,oBAAoB;AACpC,SAAS,YAAY;AAKd,IAAM,YAAN,MAAM,mBAAkB,MAAM;AAAA,EACnC,OAAO;AAAA,EAEP,YAAY,QAAoC;AAC9C,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,UAAU,UAAyB;AACxC,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,WAAK,eAAe,KAAK,wCAAwC;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,OAAe,YAAY;AAAA,IACzB;AAAA,IAAgB;AAAA,IAAS,GAAG;AAAA,EAC9B,IAA+B,CAAC,GAA8B;AAC5D,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,MAAMA,aAAY;AACnC,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,YAAIA,aAAY,UAAa,QAAQ,KAAK,UAAU,kBAAkB,OAAO;AAC3E,UAAAA,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B,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAA2D;AACrF,UAAM,eAAe,IAAIC,cAAa;AACtC,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,CAAC,CAAC,EAAG,cAAa,IAAI,KAAK,KAAK;AACrF,WAAO;AAAA,EACT;AACF;;;AC9CA,SAAS,QAAAC,aAAY;AAEd,IAAM,QAAQ,IAAI,UAAU;AAC5B,IAAM,oBAAoB,IAAI,sBAAsB;","names":["headers","Axios","AxiosHeaders","gzip"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/axios",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"axios",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@xylabs/logger": "~5.0.
|
|
46
|
-
"axios": "~1.
|
|
45
|
+
"@xylabs/logger": "~5.0.12",
|
|
46
|
+
"axios": "~1.12.2",
|
|
47
47
|
"pako": "~2.1.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/pako": "~2.0.4",
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "~7.1.
|
|
52
|
-
"@xylabs/tsconfig": "~7.1.
|
|
53
|
-
"typescript": "~5.9.
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.8",
|
|
52
|
+
"@xylabs/tsconfig": "~7.1.8",
|
|
53
|
+
"typescript": "~5.9.3"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=18"
|
package/src/AxiosJson.ts
CHANGED
|
@@ -26,8 +26,8 @@ export class AxiosJson extends Axios {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
private static axiosConfig({
|
|
29
|
-
|
|
30
|
-
}: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {
|
|
29
|
+
compressLength, headers, ...config
|
|
30
|
+
}: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {
|
|
31
31
|
return {
|
|
32
32
|
headers: this.buildHeaders(headers),
|
|
33
33
|
transformRequest: (data, headers) => {
|