@molecule/app-http-axios 1.0.0
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/LICENSE +115 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +31 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +279 -0
- package/dist/provider.js.map +1 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Axios HTTP client provider for `@molecule/app-http`.
|
|
3
|
+
*
|
|
4
|
+
* This package provides an Axios-based implementation of the molecule HttpClient interface,
|
|
5
|
+
* allowing you to use molecule's HTTP abstractions with Axios.
|
|
6
|
+
*
|
|
7
|
+
* @module `@molecule/app-http-axios`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createAxiosClient } from '@molecule/app-http-axios'
|
|
12
|
+
* import { setClient } from '@molecule/app-http'
|
|
13
|
+
*
|
|
14
|
+
* const client = createAxiosClient({
|
|
15
|
+
* baseURL: 'https://api.example.com',
|
|
16
|
+
* timeout: 10000,
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* setClient(client)
|
|
20
|
+
*
|
|
21
|
+
* // Now use via `@molecule/app-http`
|
|
22
|
+
* import { get, post } from '@molecule/app-http'
|
|
23
|
+
* const users = await get('/users')
|
|
24
|
+
* const newUser = await post('/users', { name: 'John' })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* - **Call `setClient(...)` at startup, BEFORE any `get`/`post` from
|
|
29
|
+
* `@molecule/app-http` runs.** The core's `getClient()` lazily bonds its own
|
|
30
|
+
* fetch-based fallback on first use — requests issued before `setClient()`
|
|
31
|
+
* silently bypass the Axios client (no interceptors, no auth token).
|
|
32
|
+
* - `get()`/`post()`/… resolve to `HttpResponse<T>` — read `.data` for the
|
|
33
|
+
* body (`const { data: users } = await get('/users')`).
|
|
34
|
+
* - The exported `provider` constant is a pre-built default client (no baseURL,
|
|
35
|
+
* 30 s timeout); prefer `createAxiosClient({...})` so baseURL/credentials are
|
|
36
|
+
* explicit.
|
|
37
|
+
* - `instance`/`axiosConfig` accept raw Axios options — anything the app sets
|
|
38
|
+
* there couples it to Axios; keep app code on the `@molecule/app-http`
|
|
39
|
+
* interface so the bond stays swappable.
|
|
40
|
+
*/
|
|
41
|
+
export * from './provider.js';
|
|
42
|
+
export * from './types.js';
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Axios HTTP client provider for `@molecule/app-http`.
|
|
3
|
+
*
|
|
4
|
+
* This package provides an Axios-based implementation of the molecule HttpClient interface,
|
|
5
|
+
* allowing you to use molecule's HTTP abstractions with Axios.
|
|
6
|
+
*
|
|
7
|
+
* @module `@molecule/app-http-axios`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createAxiosClient } from '@molecule/app-http-axios'
|
|
12
|
+
* import { setClient } from '@molecule/app-http'
|
|
13
|
+
*
|
|
14
|
+
* const client = createAxiosClient({
|
|
15
|
+
* baseURL: 'https://api.example.com',
|
|
16
|
+
* timeout: 10000,
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* setClient(client)
|
|
20
|
+
*
|
|
21
|
+
* // Now use via `@molecule/app-http`
|
|
22
|
+
* import { get, post } from '@molecule/app-http'
|
|
23
|
+
* const users = await get('/users')
|
|
24
|
+
* const newUser = await post('/users', { name: 'John' })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* - **Call `setClient(...)` at startup, BEFORE any `get`/`post` from
|
|
29
|
+
* `@molecule/app-http` runs.** The core's `getClient()` lazily bonds its own
|
|
30
|
+
* fetch-based fallback on first use — requests issued before `setClient()`
|
|
31
|
+
* silently bypass the Axios client (no interceptors, no auth token).
|
|
32
|
+
* - `get()`/`post()`/… resolve to `HttpResponse<T>` — read `.data` for the
|
|
33
|
+
* body (`const { data: users } = await get('/users')`).
|
|
34
|
+
* - The exported `provider` constant is a pre-built default client (no baseURL,
|
|
35
|
+
* 30 s timeout); prefer `createAxiosClient({...})` so baseURL/credentials are
|
|
36
|
+
* explicit.
|
|
37
|
+
* - `instance`/`axiosConfig` accept raw Axios options — anything the app sets
|
|
38
|
+
* there couples it to Axios; keep app code on the `@molecule/app-http`
|
|
39
|
+
* interface so the bond stays swappable.
|
|
40
|
+
*/
|
|
41
|
+
export * from './provider.js';
|
|
42
|
+
export * from './types.js';
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Axios HTTP client provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { AxiosHttpClientConfig, HttpClient } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates an Axios-based HTTP client implementing the molecule `HttpClient` interface.
|
|
9
|
+
* Supports request/response/error interceptors, auth token management, and 401 error handlers.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createAxiosClient } from '@molecule/app-http-axios'
|
|
14
|
+
* import { setClient } from '@molecule/app-http'
|
|
15
|
+
*
|
|
16
|
+
* const client = createAxiosClient({
|
|
17
|
+
* baseURL: 'https://api.example.com',
|
|
18
|
+
* timeout: 10000,
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* setClient(client)
|
|
22
|
+
* const response = await client.get('/users')
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param config - Axios client configuration (base URL, headers, timeout, credentials, or an existing Axios instance).
|
|
26
|
+
* @returns An `HttpClient` backed by Axios with interceptor and auth token support.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createAxiosClient(config?: AxiosHttpClientConfig): HttpClient;
|
|
29
|
+
/** Default Axios-based HTTP client created with default options (no base URL, 30s timeout). */
|
|
30
|
+
export declare const provider: HttpClient;
|
|
31
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EACV,qBAAqB,EAGrB,UAAU,EAKX,MAAM,YAAY,CAAA;AAmDnB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,qBAA0B,GAAG,UAAU,CAkQhF;AAED,+FAA+F;AAC/F,eAAO,MAAM,QAAQ,YAAsB,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Axios HTTP client provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import { HttpError } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Converts a molecule `RequestConfig` to an Axios-compatible `AxiosRequestConfig`.
|
|
10
|
+
* @param config - The molecule request configuration.
|
|
11
|
+
* @returns An `AxiosRequestConfig` with mapped headers, params, timeout, and other options.
|
|
12
|
+
*/
|
|
13
|
+
function toAxiosConfig(config) {
|
|
14
|
+
return {
|
|
15
|
+
headers: config.headers,
|
|
16
|
+
params: config.params,
|
|
17
|
+
timeout: config.timeout,
|
|
18
|
+
withCredentials: config.withCredentials,
|
|
19
|
+
responseType: config.responseType,
|
|
20
|
+
signal: config.signal,
|
|
21
|
+
data: config.data,
|
|
22
|
+
...config.options,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts an `AxiosResponse` to the molecule `HttpResponse` interface. Normalizes
|
|
27
|
+
* headers from `AxiosHeaders` to a plain `Record<string, string>`.
|
|
28
|
+
* @param response - The raw Axios response.
|
|
29
|
+
* @param config - The original molecule request config (preserved in the response for tracing).
|
|
30
|
+
* @returns A normalized `HttpResponse` with data, status, headers, and config.
|
|
31
|
+
*/
|
|
32
|
+
function toHttpResponse(response, config) {
|
|
33
|
+
const headers = {};
|
|
34
|
+
// Convert AxiosHeaders to plain object
|
|
35
|
+
if (response.headers) {
|
|
36
|
+
for (const [key, value] of Object.entries(response.headers)) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
headers[key] = value;
|
|
39
|
+
}
|
|
40
|
+
else if (Array.isArray(value)) {
|
|
41
|
+
headers[key] = value.join(', ');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
data: response.data,
|
|
47
|
+
status: response.status,
|
|
48
|
+
statusText: response.statusText,
|
|
49
|
+
headers,
|
|
50
|
+
config,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates an Axios-based HTTP client implementing the molecule `HttpClient` interface.
|
|
55
|
+
* Supports request/response/error interceptors, auth token management, and 401 error handlers.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { createAxiosClient } from '@molecule/app-http-axios'
|
|
60
|
+
* import { setClient } from '@molecule/app-http'
|
|
61
|
+
*
|
|
62
|
+
* const client = createAxiosClient({
|
|
63
|
+
* baseURL: 'https://api.example.com',
|
|
64
|
+
* timeout: 10000,
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* setClient(client)
|
|
68
|
+
* const response = await client.get('/users')
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @param config - Axios client configuration (base URL, headers, timeout, credentials, or an existing Axios instance).
|
|
72
|
+
* @returns An `HttpClient` backed by Axios with interceptor and auth token support.
|
|
73
|
+
*/
|
|
74
|
+
export function createAxiosClient(config = {}) {
|
|
75
|
+
const { baseURL = '', defaultHeaders = {}, timeout = 30000, withCredentials = false, instance: existingInstance, axiosConfig = {}, } = config;
|
|
76
|
+
// Create or use existing Axios instance
|
|
77
|
+
const axiosInstance = existingInstance ??
|
|
78
|
+
axios.create({
|
|
79
|
+
baseURL,
|
|
80
|
+
timeout,
|
|
81
|
+
withCredentials,
|
|
82
|
+
headers: defaultHeaders,
|
|
83
|
+
...axiosConfig,
|
|
84
|
+
});
|
|
85
|
+
// Interceptor storage
|
|
86
|
+
const requestInterceptors = [];
|
|
87
|
+
const responseInterceptors = [];
|
|
88
|
+
const errorInterceptors = [];
|
|
89
|
+
const authErrorHandlers = new Set();
|
|
90
|
+
let authToken = null;
|
|
91
|
+
const currentDefaultHeaders = { ...defaultHeaders };
|
|
92
|
+
// Add Axios request interceptor to run molecule interceptors
|
|
93
|
+
axiosInstance.interceptors.request.use(async (axiosConfig) => {
|
|
94
|
+
let config = {
|
|
95
|
+
method: axiosConfig.method?.toUpperCase() ?? 'GET',
|
|
96
|
+
url: axiosConfig.url ?? '',
|
|
97
|
+
headers: axiosConfig.headers,
|
|
98
|
+
params: axiosConfig.params,
|
|
99
|
+
timeout: axiosConfig.timeout,
|
|
100
|
+
withCredentials: axiosConfig.withCredentials,
|
|
101
|
+
data: axiosConfig.data,
|
|
102
|
+
};
|
|
103
|
+
// Run request interceptors
|
|
104
|
+
for (const interceptor of requestInterceptors) {
|
|
105
|
+
config = await interceptor(config);
|
|
106
|
+
}
|
|
107
|
+
// Apply back to Axios config
|
|
108
|
+
axiosConfig.url = config.url;
|
|
109
|
+
axiosConfig.method = config.method.toLowerCase();
|
|
110
|
+
axiosConfig.headers.set(config.headers ?? {});
|
|
111
|
+
axiosConfig.params = config.params;
|
|
112
|
+
axiosConfig.timeout = config.timeout;
|
|
113
|
+
axiosConfig.withCredentials = config.withCredentials;
|
|
114
|
+
axiosConfig.data = config.data;
|
|
115
|
+
return axiosConfig;
|
|
116
|
+
});
|
|
117
|
+
// Add Axios response interceptor to run molecule interceptors
|
|
118
|
+
axiosInstance.interceptors.response.use(async (response) => {
|
|
119
|
+
const moleculeConfig = {
|
|
120
|
+
method: response.config.method?.toUpperCase() ?? 'GET',
|
|
121
|
+
url: response.config.url ?? '',
|
|
122
|
+
headers: response.config.headers,
|
|
123
|
+
data: response.config.data,
|
|
124
|
+
};
|
|
125
|
+
let httpResponse = toHttpResponse(response, moleculeConfig);
|
|
126
|
+
// Run response interceptors
|
|
127
|
+
for (const interceptor of responseInterceptors) {
|
|
128
|
+
httpResponse = await interceptor(httpResponse);
|
|
129
|
+
}
|
|
130
|
+
// Update response data
|
|
131
|
+
response.data = httpResponse.data;
|
|
132
|
+
return response;
|
|
133
|
+
}, async (error) => {
|
|
134
|
+
// Handle auth errors
|
|
135
|
+
if (error.response?.status === 401) {
|
|
136
|
+
authErrorHandlers.forEach((handler) => handler());
|
|
137
|
+
}
|
|
138
|
+
// Run error interceptors
|
|
139
|
+
const httpError = new HttpError(error.message, error.response?.status ?? 0, error.response
|
|
140
|
+
? toHttpResponse(error.response, {
|
|
141
|
+
method: error.config?.method?.toUpperCase() ?? 'GET',
|
|
142
|
+
url: error.config?.url ?? '',
|
|
143
|
+
headers: error.config?.headers,
|
|
144
|
+
data: error.config?.data,
|
|
145
|
+
})
|
|
146
|
+
: undefined, error.config
|
|
147
|
+
? {
|
|
148
|
+
method: error.config.method?.toUpperCase() ?? 'GET',
|
|
149
|
+
url: error.config.url ?? '',
|
|
150
|
+
headers: error.config.headers,
|
|
151
|
+
data: error.config.data,
|
|
152
|
+
}
|
|
153
|
+
: undefined);
|
|
154
|
+
for (const interceptor of errorInterceptors) {
|
|
155
|
+
try {
|
|
156
|
+
const result = await interceptor(httpError);
|
|
157
|
+
if (result) {
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (_error) {
|
|
162
|
+
// Intentional noop: an interceptor throwing must not abort the chain; the
|
|
163
|
+
// original httpError is still rethrown below, so swallowing this is safe.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
throw httpError;
|
|
167
|
+
});
|
|
168
|
+
const client = {
|
|
169
|
+
baseURL,
|
|
170
|
+
defaultHeaders: currentDefaultHeaders,
|
|
171
|
+
async request(config) {
|
|
172
|
+
const axiosConfig = {
|
|
173
|
+
method: config.method.toLowerCase(),
|
|
174
|
+
url: config.url,
|
|
175
|
+
data: config.data,
|
|
176
|
+
...toAxiosConfig(config),
|
|
177
|
+
};
|
|
178
|
+
const response = await axiosInstance.request(axiosConfig);
|
|
179
|
+
return toHttpResponse(response, config);
|
|
180
|
+
},
|
|
181
|
+
async get(url, config) {
|
|
182
|
+
const fullConfig = {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
url,
|
|
185
|
+
...config,
|
|
186
|
+
};
|
|
187
|
+
const response = await axiosInstance.get(url, toAxiosConfig(config ?? {}));
|
|
188
|
+
return toHttpResponse(response, fullConfig);
|
|
189
|
+
},
|
|
190
|
+
async post(url, data, config) {
|
|
191
|
+
const fullConfig = {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
url,
|
|
194
|
+
data,
|
|
195
|
+
...config,
|
|
196
|
+
};
|
|
197
|
+
const response = await axiosInstance.post(url, data, toAxiosConfig(config ?? {}));
|
|
198
|
+
return toHttpResponse(response, fullConfig);
|
|
199
|
+
},
|
|
200
|
+
async put(url, data, config) {
|
|
201
|
+
const fullConfig = {
|
|
202
|
+
method: 'PUT',
|
|
203
|
+
url,
|
|
204
|
+
data,
|
|
205
|
+
...config,
|
|
206
|
+
};
|
|
207
|
+
const response = await axiosInstance.put(url, data, toAxiosConfig(config ?? {}));
|
|
208
|
+
return toHttpResponse(response, fullConfig);
|
|
209
|
+
},
|
|
210
|
+
async patch(url, data, config) {
|
|
211
|
+
const fullConfig = {
|
|
212
|
+
method: 'PATCH',
|
|
213
|
+
url,
|
|
214
|
+
data,
|
|
215
|
+
...config,
|
|
216
|
+
};
|
|
217
|
+
const response = await axiosInstance.patch(url, data, toAxiosConfig(config ?? {}));
|
|
218
|
+
return toHttpResponse(response, fullConfig);
|
|
219
|
+
},
|
|
220
|
+
async delete(url, config) {
|
|
221
|
+
const fullConfig = {
|
|
222
|
+
method: 'DELETE',
|
|
223
|
+
url,
|
|
224
|
+
...config,
|
|
225
|
+
};
|
|
226
|
+
const response = await axiosInstance.delete(url, toAxiosConfig(config ?? {}));
|
|
227
|
+
return toHttpResponse(response, fullConfig);
|
|
228
|
+
},
|
|
229
|
+
addRequestInterceptor(interceptor) {
|
|
230
|
+
requestInterceptors.push(interceptor);
|
|
231
|
+
return () => {
|
|
232
|
+
const index = requestInterceptors.indexOf(interceptor);
|
|
233
|
+
if (index !== -1) {
|
|
234
|
+
requestInterceptors.splice(index, 1);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
addResponseInterceptor(interceptor) {
|
|
239
|
+
responseInterceptors.push(interceptor);
|
|
240
|
+
return () => {
|
|
241
|
+
const index = responseInterceptors.indexOf(interceptor);
|
|
242
|
+
if (index !== -1) {
|
|
243
|
+
responseInterceptors.splice(index, 1);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
addErrorInterceptor(interceptor) {
|
|
248
|
+
errorInterceptors.push(interceptor);
|
|
249
|
+
return () => {
|
|
250
|
+
const index = errorInterceptors.indexOf(interceptor);
|
|
251
|
+
if (index !== -1) {
|
|
252
|
+
errorInterceptors.splice(index, 1);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
setAuthToken(token) {
|
|
257
|
+
authToken = token;
|
|
258
|
+
if (token) {
|
|
259
|
+
axiosInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
260
|
+
currentDefaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
delete axiosInstance.defaults.headers.common['Authorization'];
|
|
264
|
+
delete currentDefaultHeaders['Authorization'];
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
getAuthToken() {
|
|
268
|
+
return authToken;
|
|
269
|
+
},
|
|
270
|
+
onAuthError(handler) {
|
|
271
|
+
authErrorHandlers.add(handler);
|
|
272
|
+
return () => authErrorHandlers.delete(handler);
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
return client;
|
|
276
|
+
}
|
|
277
|
+
/** Default Axios-based HTTP client created with default options (no base URL, 30s timeout). */
|
|
278
|
+
export const provider = createAxiosClient();
|
|
279
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAMN,MAAM,OAAO,CAAA;AAYd,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;GAIG;AACH,SAAS,aAAa,CAAC,MAAqB;IAC1C,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,MAAM,CAAC,OAAO;KAClB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAA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,CAAC,WAAW,CAAC,CAAA;YACnC,OAAO,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;gBACpD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;oBACjB,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC,CAAA;QACH,CAAC;QAED,YAAY,CAAC,KAAoB;YAC/B,SAAS,GAAG,KAAK,CAAA;YACjB,IAAI,KAAK,EAAE,CAAC;gBACV,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;gBAC1E,qBAAqB,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;YAC5D,CAAC;iBAAM,CAAC;gBACN,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;gBAC7D,OAAO,qBAAqB,CAAC,eAAe,CAAC,CAAA;YAC/C,CAAC;QACH,CAAC;QAED,YAAY;YACV,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,WAAW,CAAC,OAAmB;YAC7B,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC9B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Axios HTTP provider.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
7
|
+
export type { ErrorInterceptor, FullRequestConfig, HttpClient, HttpClientConfig, HttpMethod, HttpResponse, RequestConfig, RequestInterceptor, ResponseInterceptor, } from '@molecule/app-http';
|
|
8
|
+
export { HttpError } from '@molecule/app-http';
|
|
9
|
+
/**
|
|
10
|
+
* Axios-specific configuration.
|
|
11
|
+
*/
|
|
12
|
+
export interface AxiosHttpClientConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Base URL for all requests.
|
|
15
|
+
*/
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Default headers for all requests.
|
|
19
|
+
*/
|
|
20
|
+
defaultHeaders?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Default timeout in milliseconds.
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to include credentials by default.
|
|
27
|
+
*/
|
|
28
|
+
withCredentials?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Existing Axios instance to wrap (optional).
|
|
31
|
+
*/
|
|
32
|
+
instance?: AxiosInstance;
|
|
33
|
+
/**
|
|
34
|
+
* Additional Axios-specific config.
|
|
35
|
+
*/
|
|
36
|
+
axiosConfig?: AxiosRequestConfig;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAG9D,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEvC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAA;IAExB;;OAEG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-http-axios",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Axios HTTP client provider for @molecule/app-http",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"dev": "tsc --watch",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@molecule/app-http": "^1.0.0",
|
|
24
|
+
"axios": "^1.6.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "26.1.2",
|
|
28
|
+
"axios": "1.19.0",
|
|
29
|
+
"typescript": "6.0.3",
|
|
30
|
+
"vitest": "4.1.10"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
35
|
+
"directory": "packages/app/bonds/http/axios"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/bonds/http/axios",
|
|
38
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|