@molecule/app-http 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/client.d.ts +99 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +9 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +27 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +10 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/provider.d.ts +20 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +298 -0
- package/dist/provider.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/dist/unwrap.d.ts +66 -0
- package/dist/unwrap.d.ts.map +1 -0
- package/dist/unwrap.js +221 -0
- package/dist/unwrap.js.map +1 -0
- package/dist/utilities.d.ts +79 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +89 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +52 -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/client.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client interface definitions.
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract that all HTTP client implementations must follow.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { ErrorInterceptor, RequestInterceptor, ResponseInterceptor } from './interceptors.js';
|
|
9
|
+
import type { FullRequestConfig, HttpResponse, RequestConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* HTTP client interface.
|
|
12
|
+
*
|
|
13
|
+
* All HTTP providers must implement this interface.
|
|
14
|
+
*/
|
|
15
|
+
export interface HttpClient {
|
|
16
|
+
/**
|
|
17
|
+
* Base URL for all requests.
|
|
18
|
+
*/
|
|
19
|
+
baseURL: string;
|
|
20
|
+
/**
|
|
21
|
+
* Default headers for all requests.
|
|
22
|
+
*/
|
|
23
|
+
defaultHeaders: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Makes a generic HTTP request.
|
|
26
|
+
*/
|
|
27
|
+
request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>;
|
|
28
|
+
/**
|
|
29
|
+
* Makes a GET request.
|
|
30
|
+
*/
|
|
31
|
+
get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Makes a POST request.
|
|
34
|
+
*/
|
|
35
|
+
post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
36
|
+
/**
|
|
37
|
+
* Makes a PUT request.
|
|
38
|
+
*/
|
|
39
|
+
put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* Makes a PATCH request.
|
|
42
|
+
*/
|
|
43
|
+
patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
44
|
+
/**
|
|
45
|
+
* Makes a DELETE request.
|
|
46
|
+
*/
|
|
47
|
+
delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Adds a request interceptor.
|
|
50
|
+
* Returns a function to remove the interceptor.
|
|
51
|
+
*/
|
|
52
|
+
addRequestInterceptor(interceptor: RequestInterceptor): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Adds a response interceptor.
|
|
55
|
+
* Returns a function to remove the interceptor.
|
|
56
|
+
*/
|
|
57
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Adds an error interceptor.
|
|
60
|
+
* Returns a function to remove the interceptor.
|
|
61
|
+
*/
|
|
62
|
+
addErrorInterceptor(interceptor: ErrorInterceptor): () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Sets the authorization token.
|
|
65
|
+
*/
|
|
66
|
+
setAuthToken(token: string | null): void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the current authorization token, or `null` if not set.
|
|
69
|
+
*/
|
|
70
|
+
getAuthToken(): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Registers a handler for authentication errors (401).
|
|
73
|
+
*
|
|
74
|
+
* @returns An unsubscribe function.
|
|
75
|
+
*/
|
|
76
|
+
onAuthError(handler: () => void): () => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* HTTP client configuration.
|
|
80
|
+
*/
|
|
81
|
+
export interface HttpClientConfig {
|
|
82
|
+
/**
|
|
83
|
+
* Base URL for all requests.
|
|
84
|
+
*/
|
|
85
|
+
baseURL?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Default headers for all requests.
|
|
88
|
+
*/
|
|
89
|
+
defaultHeaders?: Record<string, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Default timeout in milliseconds.
|
|
92
|
+
*/
|
|
93
|
+
timeout?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Whether to include credentials by default.
|
|
96
|
+
*/
|
|
97
|
+
withCredentials?: boolean;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAClG,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhF;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEtC;;OAEG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAEzE;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/E;;OAEG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAEhG;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/F;;OAEG;IACH,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAEjG;;OAEG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAElF;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAAA;IAElE;;;OAGG;IACH,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAAA;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAA;IAE9D;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAExC;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;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;CAC1B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client HTTP interface for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified HTTP client API that works across different
|
|
5
|
+
* HTTP libraries (fetch, axios, ky, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // In a React component, get the configured client from context and call it.
|
|
10
|
+
* // The hook is exported by the framework binding (@molecule/app-react), not
|
|
11
|
+
* // this core package — never construct your own fetch/axios client.
|
|
12
|
+
* import { useHttpClient } from '@molecule/app-react'
|
|
13
|
+
*
|
|
14
|
+
* function Plants() {
|
|
15
|
+
* const http = useHttpClient()
|
|
16
|
+
* const load = async () => {
|
|
17
|
+
* const res = await http.get<Plant[]>('/plants') // baseURL ('/api') is prepended
|
|
18
|
+
* setPlants(res.data)
|
|
19
|
+
* }
|
|
20
|
+
* // http.post(url, body), http.put, http.delete are also available.
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Make ALL API calls through this client (via the framework hook `useHttpClient()` in
|
|
26
|
+
* React / the Vue composable) — it carries the configured `baseURL`, auth headers, and
|
|
27
|
+
* interceptors. Do NOT call `fetch()` / `axios` directly in components — that bypasses auth
|
|
28
|
+
* + base-URL config and breaks when the transport is swapped.
|
|
29
|
+
*
|
|
30
|
+
* Two mistakes that break in preview/production (seen in real imported apps):
|
|
31
|
+
* - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the `baseURL` `'/api'`
|
|
32
|
+
* is prepended), NOT `'/api/plants'`, and NEVER an absolute dev URL like
|
|
33
|
+
* `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on the author's
|
|
34
|
+
* machine, then fails cross-origin (CORS) in the preview and points at the wrong server in
|
|
35
|
+
* production. The base URL is configured ONCE (via `setClient`), not per call.
|
|
36
|
+
* - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
|
|
37
|
+
* key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
|
|
38
|
+
* stay in YOUR API; the browser calls your API and the API uses the secret server-side.
|
|
39
|
+
* Only a publishable/public key may ever be client-side.
|
|
40
|
+
*
|
|
41
|
+
* Auth (the bearer token / session cookie) is attached by the client's interceptors — do not
|
|
42
|
+
* read a token from `localStorage` or hand-attach it (the token is memory-only; see the user
|
|
43
|
+
* resource).
|
|
44
|
+
*
|
|
45
|
+
* @module
|
|
46
|
+
*/
|
|
47
|
+
export * from './client.js';
|
|
48
|
+
export * from './interceptors.js';
|
|
49
|
+
export * from './provider.js';
|
|
50
|
+
export * from './types.js';
|
|
51
|
+
export * from './unwrap.js';
|
|
52
|
+
export * from './utilities.js';
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client HTTP interface for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified HTTP client API that works across different
|
|
5
|
+
* HTTP libraries (fetch, axios, ky, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // In a React component, get the configured client from context and call it.
|
|
10
|
+
* // The hook is exported by the framework binding (@molecule/app-react), not
|
|
11
|
+
* // this core package — never construct your own fetch/axios client.
|
|
12
|
+
* import { useHttpClient } from '@molecule/app-react'
|
|
13
|
+
*
|
|
14
|
+
* function Plants() {
|
|
15
|
+
* const http = useHttpClient()
|
|
16
|
+
* const load = async () => {
|
|
17
|
+
* const res = await http.get<Plant[]>('/plants') // baseURL ('/api') is prepended
|
|
18
|
+
* setPlants(res.data)
|
|
19
|
+
* }
|
|
20
|
+
* // http.post(url, body), http.put, http.delete are also available.
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Make ALL API calls through this client (via the framework hook `useHttpClient()` in
|
|
26
|
+
* React / the Vue composable) — it carries the configured `baseURL`, auth headers, and
|
|
27
|
+
* interceptors. Do NOT call `fetch()` / `axios` directly in components — that bypasses auth
|
|
28
|
+
* + base-URL config and breaks when the transport is swapped.
|
|
29
|
+
*
|
|
30
|
+
* Two mistakes that break in preview/production (seen in real imported apps):
|
|
31
|
+
* - **Pass RELATIVE paths; never a hardcoded host.** Use `'/plants'` (the `baseURL` `'/api'`
|
|
32
|
+
* is prepended), NOT `'/api/plants'`, and NEVER an absolute dev URL like
|
|
33
|
+
* `'http://localhost:4000/api/…'`. A hardcoded `localhost`/host works on the author's
|
|
34
|
+
* machine, then fails cross-origin (CORS) in the preview and points at the wrong server in
|
|
35
|
+
* production. The base URL is configured ONCE (via `setClient`), not per call.
|
|
36
|
+
* - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
|
|
37
|
+
* key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
|
|
38
|
+
* stay in YOUR API; the browser calls your API and the API uses the secret server-side.
|
|
39
|
+
* Only a publishable/public key may ever be client-side.
|
|
40
|
+
*
|
|
41
|
+
* Auth (the bearer token / session cookie) is attached by the client's interceptors — do not
|
|
42
|
+
* read a token from `localStorage` or hand-attach it (the token is memory-only; see the user
|
|
43
|
+
* resource).
|
|
44
|
+
*
|
|
45
|
+
* @module
|
|
46
|
+
*/
|
|
47
|
+
export * from './client.js';
|
|
48
|
+
export * from './interceptors.js';
|
|
49
|
+
export * from './provider.js';
|
|
50
|
+
export * from './types.js';
|
|
51
|
+
export * from './unwrap.js';
|
|
52
|
+
export * from './utilities.js';
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP interceptor type definitions.
|
|
3
|
+
*
|
|
4
|
+
* Interceptors allow modification of requests and responses
|
|
5
|
+
* at various stages of the HTTP lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FullRequestConfig, HttpError, HttpResponse } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Intercepts outgoing requests to modify headers, URL, or body
|
|
12
|
+
* before the request is sent.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The full request configuration to transform.
|
|
15
|
+
*/
|
|
16
|
+
export type RequestInterceptor = (config: FullRequestConfig) => FullRequestConfig | Promise<FullRequestConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Intercepts incoming responses to transform data, check status,
|
|
19
|
+
* or perform side effects before the response reaches the caller.
|
|
20
|
+
*/
|
|
21
|
+
export type ResponseInterceptor<T = unknown> = (response: HttpResponse<T>) => HttpResponse<T> | Promise<HttpResponse<T>>;
|
|
22
|
+
/**
|
|
23
|
+
* Intercepts HTTP errors to transform, retry, or rethrow them.
|
|
24
|
+
* Throwing from this interceptor propagates the error to the caller.
|
|
25
|
+
*/
|
|
26
|
+
export type ErrorInterceptor = (error: HttpError) => HttpError | Promise<HttpError> | never;
|
|
27
|
+
//# sourceMappingURL=interceptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE5E;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,MAAM,EAAE,iBAAiB,KACtB,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAEnD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAC7C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,KACtB,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client provider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Contains concrete implementations of the HttpClient interface.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { HttpClient, HttpClientConfig } from './client.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a fetch-based HTTP client using the native Fetch API.
|
|
11
|
+
*
|
|
12
|
+
* Supports request/response/error interceptors, automatic JSON
|
|
13
|
+
* serialization, auth token injection, timeout via AbortController,
|
|
14
|
+
* and 401 error handler hooks.
|
|
15
|
+
*
|
|
16
|
+
* @param config - Client configuration including baseURL, default headers, timeout, and credentials.
|
|
17
|
+
* @returns A fully configured `HttpClient` instance.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createFetchClient: (config?: HttpClientConfig) => HttpClient;
|
|
20
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAK/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UAwVjE,CAAA"}
|