@xylabs/axios 5.0.83 → 5.0.86
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
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/axios**
|
|
@@ -23,16 +25,22 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Classes
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
| Class | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [~~AxiosJson~~](#classes/AxiosJson) | - |
|
|
27
31
|
|
|
28
32
|
## Variables
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
| Variable | Description |
|
|
35
|
+
| ------ | ------ |
|
|
36
|
+
| [axiosJson](#variables/axiosJson) | - |
|
|
37
|
+
| [~~axios~~](#variables/axios) | - |
|
|
32
38
|
|
|
33
39
|
## Functions
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
| Function | Description |
|
|
42
|
+
| ------ | ------ |
|
|
43
|
+
| [axiosJsonConfig](#functions/axiosJsonConfig) | Creates an Axios config preconfigured for JSON requests with optional gzip compression. Request bodies exceeding `compressLength` (default 1024 bytes) are automatically gzip-compressed. |
|
|
36
44
|
|
|
37
45
|
### classes
|
|
38
46
|
|
|
@@ -55,14 +63,14 @@ use axiosJsonConfig instead
|
|
|
55
63
|
### Constructor
|
|
56
64
|
|
|
57
65
|
```ts
|
|
58
|
-
new AxiosJson(config
|
|
66
|
+
new AxiosJson(config?: RawAxiosJsonRequestConfig): AxiosJson;
|
|
59
67
|
```
|
|
60
68
|
|
|
61
69
|
### Parameters
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
`RawAxiosJsonRequestConfig`
|
|
71
|
+
| Parameter | Type |
|
|
72
|
+
| ------ | ------ |
|
|
73
|
+
| `config?` | `RawAxiosJsonRequestConfig` |
|
|
66
74
|
|
|
67
75
|
### Returns
|
|
68
76
|
|
|
@@ -79,14 +87,14 @@ Axios.constructor
|
|
|
79
87
|
### ~~axiosConfig()~~
|
|
80
88
|
|
|
81
89
|
```ts
|
|
82
|
-
static axiosConfig(config
|
|
90
|
+
static axiosConfig(config?: RawAxiosJsonRequestConfig): RawAxiosJsonRequestConfig;
|
|
83
91
|
```
|
|
84
92
|
|
|
85
93
|
### Parameters
|
|
86
94
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
`
|
|
95
|
+
| Parameter | Type |
|
|
96
|
+
| ------ | ------ |
|
|
97
|
+
| `config` | `RawAxiosJsonRequestConfig` |
|
|
90
98
|
|
|
91
99
|
### Returns
|
|
92
100
|
|
|
@@ -97,14 +105,14 @@ static axiosConfig(config?): RawAxiosJsonRequestConfig;
|
|
|
97
105
|
### ~~create()~~
|
|
98
106
|
|
|
99
107
|
```ts
|
|
100
|
-
static create(config
|
|
108
|
+
static create(config?: RawAxiosJsonRequestConfig): Axios;
|
|
101
109
|
```
|
|
102
110
|
|
|
103
111
|
### Parameters
|
|
104
112
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`RawAxiosJsonRequestConfig`
|
|
113
|
+
| Parameter | Type |
|
|
114
|
+
| ------ | ------ |
|
|
115
|
+
| `config?` | `RawAxiosJsonRequestConfig` |
|
|
108
116
|
|
|
109
117
|
### Returns
|
|
110
118
|
|
|
@@ -119,19 +127,24 @@ static create(config?): Axios;
|
|
|
119
127
|
***
|
|
120
128
|
|
|
121
129
|
```ts
|
|
122
|
-
function axiosJsonConfig(
|
|
130
|
+
function axiosJsonConfig(config?: RawAxiosJsonRequestConfig): RawAxiosJsonRequestConfig;
|
|
123
131
|
```
|
|
124
132
|
|
|
125
|
-
|
|
133
|
+
Creates an Axios config preconfigured for JSON requests with optional gzip compression.
|
|
134
|
+
Request bodies exceeding `compressLength` (default 1024 bytes) are automatically gzip-compressed.
|
|
126
135
|
|
|
127
|
-
|
|
136
|
+
## Parameters
|
|
128
137
|
|
|
129
|
-
|
|
138
|
+
| Parameter | Type | Description |
|
|
139
|
+
| ------ | ------ | ------ |
|
|
140
|
+
| `config` | `RawAxiosJsonRequestConfig` | Base Axios config, optionally including a `compressLength` threshold |
|
|
130
141
|
|
|
131
142
|
## Returns
|
|
132
143
|
|
|
133
144
|
`RawAxiosJsonRequestConfig`
|
|
134
145
|
|
|
146
|
+
A fully configured Axios request config with JSON transforms
|
|
147
|
+
|
|
135
148
|
### variables
|
|
136
149
|
|
|
137
150
|
### <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;
|
|
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;
|
|
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/** 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,c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AAY,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.
|
|
3
|
+
"version": "5.0.86",
|
|
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.
|
|
50
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
51
|
-
"@xylabs/tsconfig": "~7.4.
|
|
49
|
+
"@xylabs/logger": "~5.0.86",
|
|
50
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.16",
|
|
51
|
+
"@xylabs/tsconfig": "~7.4.16",
|
|
52
52
|
"axios": "^1.13.6",
|
|
53
53
|
"typescript": "~5.9.3",
|
|
54
54
|
"vitest": "~4.0.18"
|