@springbrand/http 0.1.0-alpha.3 → 0.1.0-alpha.5
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/.agents/skills/dune-react-http/SKILL.md +2 -1
- package/README.md +1 -0
- package/dist/catalog.d.ts +1 -2
- package/dist/client.js +1 -0
- package/dist/hono.d.ts +4 -5
- package/dist/index.d.ts +1 -1
- package/package.json +4 -1
|
@@ -15,6 +15,7 @@ Read the installed declarations and README before configuring a client. Public e
|
|
|
15
15
|
| @springbrand/http/query | Optional TanStack React Query integration |
|
|
16
16
|
| @springbrand/http/catalog | Project error catalog: typed HttpError, Zod response schemas, client decoder (zod peer) |
|
|
17
17
|
| @springbrand/http/hono | Hono responders with TypedResponse types for zod-openapi (hono peer) |
|
|
18
|
+
| @springbrand/http/types | Type-only entry for every public type, so consumers emitting declarations stay portable |
|
|
18
19
|
| @springbrand/http/server | Standard Response helpers, bounded body reading, If-Match, Content-Disposition, log diagnostics and service authentication |
|
|
19
20
|
|
|
20
21
|
## Client setup
|
|
@@ -23,7 +24,7 @@ Create one client per trusted API origin. Inject getToken; do not copy Token sto
|
|
|
23
24
|
|
|
24
25
|
Pass params for query serialization and signal/timeoutMs for cancellation/deadlines. Null/undefined query values are omitted; use a string for literal null. Do not duplicate query encoding or timeout controllers in domain clients.
|
|
25
26
|
|
|
26
|
-
Use get/post/put/patch/delete for payloads, request for data plus status and headers. Explicitly choose json, text or blob for endpoints without the standard success envelope. FormData owns its boundary. Pass Query's signal through; do not wrap cancellation as network failure.
|
|
27
|
+
Use get/post/put/patch/delete for payloads, request for data plus status and headers. Explicitly choose json, text or blob for endpoints without the standard success envelope. FormData owns its boundary. The client sends no User-Agent of its own (Safari and Firefox would otherwise require every cross-origin API to allow it in CORS); set one explicitly only for a server-to-server call that needs it. Pass Query's signal through; do not wrap cancellation as network failure.
|
|
27
28
|
|
|
28
29
|
## Error handling
|
|
29
30
|
|
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ pnpm add @springbrand/http@alpha
|
|
|
20
20
|
| `@springbrand/http/query` | createHttpQueryClient、读取重试策略 |
|
|
21
21
|
| `@springbrand/http/catalog` | defineErrorCatalog:项目错误码目录、HttpError、Zod Schema、客户端解码 |
|
|
22
22
|
| `@springbrand/http/hono` | createHonoHttp:ok、httpError 等带 TypedResponse 类型的 Hono 响应 |
|
|
23
|
+
| `@springbrand/http/types` | 只含类型的入口:公共 API 用到的全部类型,供开启 declaration 的使用方生成可移植的声明文件 |
|
|
23
24
|
| `@springbrand/http/server` | ok、fail、toErrorResponse、请求体限长读取、If-Match、Content-Disposition、服务鉴权与日志诊断 |
|
|
24
25
|
|
|
25
26
|
客户端依赖 Axios。Query、catalog、hono 是独立入口,分别以 `@tanstack/react-query`、`zod`、`hono` 作为可选 peer;只用到哪个入口才需要安装对应依赖,核心和 server 入口都不需要。服务端要求标准 Request、Response 和 Web Crypto,建议 Node.js 24 或兼容运行时。
|
package/dist/catalog.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ServerErrorCode<D extends ErrorDefinitions> = {
|
|
|
16
16
|
export type DetailSchemas<D extends ErrorDefinitions> = {
|
|
17
17
|
readonly [K in ServerErrorCode<D>]?: z.ZodType;
|
|
18
18
|
};
|
|
19
|
-
type DetailsOf<S, C> = C extends keyof S ? S[C] extends z.ZodType ? z.output<S[C]> : undefined : undefined;
|
|
19
|
+
export type DetailsOf<S, C> = C extends keyof S ? S[C] extends z.ZodType ? z.output<S[C]> : undefined : undefined;
|
|
20
20
|
export type HttpErrorOptions<T> = ErrorOptions & {
|
|
21
21
|
errors?: FieldError[];
|
|
22
22
|
details?: T;
|
|
@@ -111,4 +111,3 @@ export declare function defineErrorCatalog<const D extends ErrorDefinitions & Re
|
|
|
111
111
|
}, z.core.$strip>;
|
|
112
112
|
};
|
|
113
113
|
export type ErrorCatalogOf<D extends ErrorDefinitions & Record<RequiredErrorCode, ErrorDefinition>, S extends DetailSchemas<D> = Record<never, never>> = ReturnType<typeof defineErrorCatalog<D, S>>;
|
|
114
|
-
export {};
|
package/dist/client.js
CHANGED
|
@@ -57,6 +57,7 @@ function createHttpClient(config) {
|
|
|
57
57
|
if (options.body instanceof FormData) headers.delete("Content-Type");
|
|
58
58
|
if (timeout > 0) timer = setTimeout(() => controller.abort(sdkError("REQUEST_TIMEOUT", { status: 0, kind: "timeout" })), timeout);
|
|
59
59
|
const requestHeaders = new axios.AxiosHeaders(Object.fromEntries(headers));
|
|
60
|
+
if (!requestHeaders.has("User-Agent")) requestHeaders.set("User-Agent", false);
|
|
60
61
|
if (options.body instanceof FormData) requestHeaders.setContentType("multipart/form-data");
|
|
61
62
|
const response = await transport.request({
|
|
62
63
|
url: url.href,
|
package/dist/hono.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ import type { ContentfulStatusCode } from "hono/utils/http-status";
|
|
|
4
4
|
import type { ErrorDefinition, ErrorDefinitions, RequiredErrorCode } from "./catalog.js";
|
|
5
5
|
import type { ApiError } from "./errors.js";
|
|
6
6
|
import type { FieldError } from "./types.js";
|
|
7
|
-
type CatalogError<D extends ErrorDefinitions, C extends keyof D & string> = ApiError & {
|
|
7
|
+
export type CatalogError<D extends ErrorDefinitions, C extends keyof D & string> = ApiError & {
|
|
8
8
|
readonly code: C;
|
|
9
9
|
readonly status: D[C]["status"];
|
|
10
10
|
};
|
|
11
|
-
type SuccessResponse<T, S extends 200 | 201 | 202> = Response & TypedResponse<JSONParsed<{
|
|
11
|
+
export type SuccessResponse<T, S extends 200 | 201 | 202> = Response & TypedResponse<JSONParsed<{
|
|
12
12
|
success: true;
|
|
13
13
|
msg: T;
|
|
14
14
|
errMsg: "";
|
|
15
15
|
code: "";
|
|
16
16
|
}>, S, "json">;
|
|
17
|
-
type ErrorStatus<D extends ErrorDefinitions, C extends keyof D> = D[C]["status"] & ContentfulStatusCode;
|
|
17
|
+
export type ErrorStatus<D extends ErrorDefinitions, C extends keyof D> = D[C]["status"] & ContentfulStatusCode;
|
|
18
18
|
/** 显式写出响应类型:让 Hono 在泛型 C 未确定时推导 JSONParsed,会在声明文件里丢掉 code 字段。 */
|
|
19
|
-
type ErrorResponse<D extends ErrorDefinitions, C extends keyof D & string> = Response & TypedResponse<{
|
|
19
|
+
export type ErrorResponse<D extends ErrorDefinitions, C extends keyof D & string> = Response & TypedResponse<{
|
|
20
20
|
errMsg: string;
|
|
21
21
|
code: C;
|
|
22
22
|
requestId?: string;
|
|
@@ -47,4 +47,3 @@ export declare function createHonoHttp<const D extends ErrorDefinitions & Record
|
|
|
47
47
|
httpInternalError: (c: Context, message?: string) => ErrorResponse<D, "INTERNAL_ERROR">;
|
|
48
48
|
httpValidationError(c: Context, errors: FieldError[]): ErrorResponse<D, "REQUEST_VALIDATION_FAILED">;
|
|
49
49
|
};
|
|
50
|
-
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ApiError, errorDefinitions, isApiError, isRequestCancelled, isTransientHttpError } from "./errors.js";
|
|
2
2
|
export type { ApiErrorOptions, ApiErrorKind } from "./errors.js";
|
|
3
|
-
export type { ApiSuccessResponse, HttpErrorResponse, FieldError, HttpResult, ErrorContext, RequestNotice, RequestFailure, HttpClientConfig, HttpMessages, HttpRequestOptions, HttpMethod, ResponseMode } from "./types.js";
|
|
3
|
+
export type { ApiSuccessResponse, HttpErrorResponse, FieldError, HttpResult, ErrorContext, RequestContext, RequestNotice, RequestFailure, ResponseInfo, HttpClientConfig, HttpMessages, HttpRequestOptions, HttpMethod, ResponseMode, Feedback, FeedbackOwner, QueryScalar, UploadProgress, } from "./types.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springbrand/http",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -53,6 +53,9 @@
|
|
|
53
53
|
"import": "./dist/server/index.js",
|
|
54
54
|
"default": "./dist/server/index.js"
|
|
55
55
|
},
|
|
56
|
+
"./types": {
|
|
57
|
+
"types": "./dist/types.d.ts"
|
|
58
|
+
},
|
|
56
59
|
"./package.json": "./package.json"
|
|
57
60
|
},
|
|
58
61
|
"dependencies": {
|