@yorun-ai/vrpc 0.9.2 → 0.10.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/README.zh-CN.md CHANGED
@@ -1,18 +1,39 @@
1
1
  # @yorun-ai/vrpc
2
2
 
3
- [![license](https://img.shields.io/github/license/yorun-ai/vrpc-ts)](https://github.com/yorun-ai/vrpc-ts/blob/main/LICENSE)
4
- [![version](https://img.shields.io/npm/v/%40yorun-ai%2Fvrpc?label=version&logo=npm)](https://www.npmjs.com/package/@yorun-ai/vrpc)
5
- [![CI](https://github.com/yorun-ai/vrpc-ts/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/yorun-ai/vrpc-ts/actions/workflows/ci.yml)
3
+ [![npm version](https://img.shields.io/npm/v/%40yorun-ai%2Fvrpc?label=version&logo=npm&style=flat-square)](https://www.npmjs.com/package/@yorun-ai/vrpc)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/yorun-ai/vrpc-ts/ci.yml?branch=main&label=CI&logo=github&style=flat-square)](https://github.com/yorun-ai/vrpc-ts/actions/workflows/ci.yml)
5
+ [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=%40yorun-ai%2Fvrpc&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.com/result?p=%40yorun-ai%2Fvrpc)
6
+ [![npm downloads](https://img.shields.io/npm/dm/%40yorun-ai%2Fvrpc?logo=npm&style=flat-square)](https://www.npmjs.com/package/@yorun-ai/vrpc)
7
+ [![npm types](https://img.shields.io/npm/types/%40yorun-ai%2Fvrpc?style=flat-square)](https://www.npmjs.com/package/@yorun-ai/vrpc)
8
+ [![license](https://img.shields.io/github/license/yorun-ai/vrpc-ts?style=flat-square)](https://github.com/yorun-ai/vrpc-ts/blob/main/LICENSE)
6
9
 
7
10
  [English](README.md) | **简体中文**
8
11
 
9
- 用于 Vine vRPC 与通用 HTTP 请求的客户端运行时。
12
+ 用于 [Vine](https://github.com/yorun-ai/vine) vRPC 与通用 HTTP 请求的轻量 TypeScript 客户端运行时。
10
13
 
11
- 项目仓库:[github.com/yorun-ai/vrpc-ts](https://github.com/yorun-ai/vrpc-ts)
14
+ ## 这是什么?
12
15
 
13
- ## 稳定性
16
+ 本包对外提供两种 client,它们共享同一套请求运行时:
17
+
18
+ - **vRPC client**:通过 HTTP 调用 Vine vRPC method。它会构造 vRPC path 与
19
+ envelope,生成 `vrpc-trace`、`vrpc-client`、`vrpc-options` Header,协商 JSON
20
+ 或 CBOR,并规范化 vRPC 响应。
21
+ - **通用 HTTP client**:调用普通 HTTP API,提供统一配置、interceptor、timeout、
22
+ 取消与规范化错误。它不感知 vRPC 协议。
23
+
24
+ 服务端是 Vine vRPC service 时使用 vRPC client,其他场景使用通用 HTTP client。
25
+ 两者都基于 Fetch,以浏览器为优先目标,并可在任何提供 `fetch` 的 JavaScript 运行时中运行。
26
+
27
+ ## 特性
14
28
 
15
- 本包从 `0.9.0` 开始发布,已经可以使用,但 `1.0.0` 之前暂不承诺公开 API 稳定。不兼容的 API 变更可以随新的 `0.x` minor 版本发布,并会提供迁移说明;`1.0.0` 将作为稳定 API 承诺的起点。
29
+ - TypeScript 优先的 API,每个入口都发布类型声明。
30
+ - 基于浏览器 Fetch 的 transport,可替换为自定义 transport。
31
+ - 同时提供 Vine vRPC 与通用 HTTP 两种 client。
32
+ - client 级默认值与单次请求覆盖。
33
+ - 支持请求、响应、错误生命周期的 interceptor。
34
+ - 规范化且可分类的错误,以及 `AbortSignal` 取消。
35
+ - 通过用户提供的 codec 可选集成 CBOR,不内置任何 codec 依赖。
36
+ - 提供 ESM 与 CommonJS 构建,并支持浏览器 ES module CDN 用法。
16
37
 
17
38
  ## 安装
18
39
 
@@ -20,20 +41,19 @@
20
41
  pnpm add @yorun-ai/vrpc
21
42
  ```
22
43
 
23
- ## 入口
44
+ ```bash
45
+ npm install @yorun-ai/vrpc
46
+ ```
24
47
 
25
- - `@yorun-ai/vrpc` / `@yorun-ai/vrpc/client`:vRPC client、协议 helper、共享 transport 和类型。
26
- - `@yorun-ai/vrpc/http`:通用 HTTP client。
48
+ ## 快速开始
27
49
 
28
- ## vRPC 快速开始
50
+ ### 1. 调用一个 vRPC method
29
51
 
30
52
  ```ts
31
- import { createVrpcClient, getClientInstanceId, isVrpcError } from "@yorun-ai/vrpc";
53
+ import { createVrpcClient, getClientInstanceId } from "@yorun-ai/vrpc";
32
54
 
33
55
  const client = createVrpcClient({
34
56
  prefixUrl: "https://api.example.com/invoke",
35
- timeoutMs: 15_000,
36
- suppressGlobalToast: false,
37
57
  clientInfo: {
38
58
  clientName: "demo.browser",
39
59
  clientVersion: "1.0.0",
@@ -41,132 +61,17 @@ const client = createVrpcClient({
41
61
  },
42
62
  });
43
63
 
44
- client.use({
45
- onError(error, context) {
46
- if (isVrpcError(error) && error.kind === "abort") {
47
- return;
48
- }
49
- if (context.options.suppressGlobalToast) {
50
- return;
51
- }
52
- console.error(error);
53
- },
54
- });
55
-
56
64
  const profile = await client.invoke<{ id: number; name: string }>({
57
65
  serviceName: "user.UserService",
58
66
  methodName: "getProfile",
59
67
  params: { userId: 1 },
60
- options: {
61
- timeoutMs: 3_000,
62
- suppressGlobalToast: true,
63
- },
64
68
  });
65
-
66
- // 无参 method 可以传 null 或空对象。
67
- await client.invoke({
68
- serviceName: "user.UserService",
69
- methodName: "ping",
70
- params: null,
71
- });
72
-
73
- try {
74
- await client.invoke({
75
- serviceName: "user.UserService",
76
- methodName: "missing",
77
- params: {},
78
- });
79
- } catch (error) {
80
- if (isVrpcError(error) && error.kind === "invoke") {
81
- console.error(error.status, error.vrpcStatus, error.code, error.reason);
82
- }
83
- }
84
- ```
85
-
86
- `traceMode` 只控制 runtime 自动生成的 `vrpc-trace` Header,不改变请求路由或 `prefixUrl`。经过 Vine Portal 时使用默认的 `"portal"` 模式,Header 只包含 id;应用直连 vRPC 服务时设置 `traceMode: "direct"`,runtime 同时生成 id 和 span。单次调用的 `options.trace` 会覆盖自动生成结果。
87
-
88
- ### 请求配置
89
-
90
- ```ts
91
- type VrpcRequestOptions = {
92
- headers?: HeadersInit;
93
- timeoutMs?: number;
94
- requestInit?: Omit<RequestInit, "method" | "body" | "headers">;
95
- suppressGlobalToast?: boolean;
96
- trace?: { id: string; span?: string };
97
- wire?: VrpcMethodWireSpec;
98
- };
99
69
  ```
100
70
 
101
- - create 时的 `suppressGlobalToast` 是默认值,单次调用的 `true` 或 `false` 会覆盖它。
102
- - `timeoutMs` 默认不启用;未配置时内置 transport 不创建本地 timeout,也不发送 `vrpc-options`。
103
- - `wire` 只能用于单次调用,并且不会进入 HTTP payload。
104
- - 无参 method 兼容 `params: null` 和 `params: {}`。
105
- - 浏览器 transport 默认 `credentials: "omit"`;需要 cookie 时使用 `requestInit.credentials`。
106
-
107
- ## 自动 CBOR
71
+ 最终 URL 为 `<prefixUrl>/<serviceName>/<methodName>`。无参 method 可以传
72
+ `params: null` 或 `params: {}`。
108
73
 
109
- runtime 不内置 CBOR 依赖。没有 `wire` 的 method 始终使用 JSON,也不需要 codec。生成的 client 会在 method 的 arguments 或 result 含 Binary 时附加稀疏 wire schema:
110
-
111
- ```ts
112
- import type { VrpcCborCodec, VrpcWireSchema } from "@yorun-ai/vrpc";
113
-
114
- const uploadArguments: VrpcWireSchema = {
115
- kind: "object",
116
- fields: {
117
- content: { kind: "binary" },
118
- },
119
- };
120
-
121
- const cborCodec: VrpcCborCodec = {
122
- encode: (value) => yourCborLibrary.encode(value),
123
- decode: (bytes) => yourCborLibrary.decode(bytes),
124
- };
125
-
126
- const client = createVrpcClient({
127
- prefixUrl: "https://api.example.com/invoke",
128
- clientInfo: {
129
- clientName: "demo.browser",
130
- clientVersion: "1.0.0",
131
- clientInstanceId: getClientInstanceId(),
132
- },
133
- cborCodec,
134
- });
135
-
136
- await client.invoke({
137
- serviceName: "file.FileService",
138
- methodName: "upload",
139
- params: { content: new Uint8Array([1, 2, 3]) },
140
- options: {
141
- wire: { arguments: uploadArguments },
142
- },
143
- });
144
- ```
145
-
146
- 自动选择规则
147
-
148
- - `wire.arguments`:请求 `content-type` 使用 `application/vrpc+cbor`。
149
- - `wire.result`:`accept` 使用 `application/vrpc+cbor, application/vrpc+json`。
150
- - 两者都没有:JSON。
151
- - wire 存在但没有 `cborCodec`:在网络请求前抛出配置错误。
152
-
153
- `VrpcWireSchema` 支持 Binary、nullable、list、object 和 `Map<Int|string, T>`。CBOR 中 Binary 保持原始 bytes;整数键 `Record` 转换为真正的整数键 CBOR Map。
154
-
155
- ## Vine Header
156
-
157
- runtime 自动生成
158
-
159
- ```text
160
- content-type: application/vrpc+json
161
- accept: application/vrpc+json
162
- vrpc-trace: id=<32hex>
163
- vrpc-client: name=demo.browser,version=1.0.0,instanceId=<uuid>
164
- vrpc-options: timeout=3000ms
165
- ```
166
-
167
- 自定义 `headers` 不能覆盖 `accept`、`content-type` 或任何 `vrpc-*` Header。显式配置 `timeoutMs` 时,它同时控制本地 `AbortController` 和 `vrpc-options`。
168
-
169
- ## 通用 HTTP client
74
+ ### 2. 调用普通 HTTP API
170
75
 
171
76
  ```ts
172
77
  import { createHttpClient } from "@yorun-ai/vrpc/http";
@@ -176,14 +81,7 @@ const http = createHttpClient({
176
81
  timeoutMs: 5_000,
177
82
  });
178
83
 
179
- const profile = await http.request<{ id: number }>({
180
- path: "/users/me",
181
- query: { withProfile: true },
182
- options: {
183
- requestInit: { credentials: "include" },
184
- suppressGlobalToast: true,
185
- },
186
- });
84
+ const profile = await http.request<{ id: number }>({ path: "/users/me" });
187
85
 
188
86
  await http.request({
189
87
  path: "/users",
@@ -192,139 +90,111 @@ await http.request({
192
90
  });
193
91
  ```
194
92
 
195
- HTTP interceptor 通过 `context.options` 读取合并后的请求配置。`json` 和 `body` 互斥。通用 HTTP 响应采用与 `content-type` 无关的宽松解析策略:空 body 返回 `null`,合法 JSON 返回解码结果,其他 body 返回文本。
196
-
197
- 请求 `path` 默认只能相对于 `prefixUrl`。绝对请求 URL 会在进入 transport 前被拒绝,避免不可信的 `path` 把 client 级 Header 转发到其他 origin。确实需要完整 URL 且输入可信时,可以在创建 HTTP client 时设置 `allowAbsoluteUrls: true`。该显式选项只接受 `http:` 和 `https:` URL,并会继续向目标 URL 发送已配置的 Header;`//example.com/path` 形式的协议相对 URL 始终不允许。
198
-
199
- ## 错误处理
93
+ JSON 请求体使用 `json`,`FormData` 等原始 `BodyInit` 使用 `body`。
200
94
 
201
- 业务只需要使用 `isVrpcError` 判断是否为 vRPC client 规范化错误,然后通过 `kind` 分类:
95
+ ### 3. 处理错误
202
96
 
203
97
  ```ts
204
98
  import { isVrpcError } from "@yorun-ai/vrpc";
205
99
 
206
- function handleError(error: unknown) {
207
- if (!isVrpcError(error)) {
208
- console.error(error);
209
- return;
210
- }
211
-
212
- if (error.kind === "abort") {
213
- return;
214
- }
215
-
216
- if (error.kind === "invoke") {
217
- console.error(error.vrpcStatus, error.code, error.reason, error.message);
218
- return;
100
+ try {
101
+ await client.invoke({
102
+ serviceName: "user.UserService",
103
+ methodName: "getProfile",
104
+ params: { userId: 1 },
105
+ });
106
+ } catch (error) {
107
+ if (isVrpcError(error) && error.kind === "invoke") {
108
+ // 服务端拒绝了本次调用。
109
+ console.error(error.vrpcStatus, error.code, error.reason);
219
110
  }
220
-
221
- console.error(error.kind, error.message, error.cause);
222
111
  }
223
112
  ```
224
113
 
225
- vRPC 的错误 kind 包括 `abort`、`timeout`、`transport`、`invoke` 和 `protocol`。通用 HTTP 入口提供等价的 `isHttpError`,其错误 kind 包括 `abort`、`timeout`、`transport` 和 `invoke`。adapter 或 vRPC 解码产生的原始异常会保留在 `cause` 中。对于 vRPC invoke 错误,`code` 和 `reason` 仍然是服务端业务字段,非空 `detail` 仍会拼接到 `message`。
114
+ 通用 HTTP client 提供等价的 `isHttpError`。
226
115
 
227
- 错误 class 会继续导出,供兼容代码和特定测试使用;业务错误策略通常只需要 guard 和 `kind`,无需再使用 `instanceof` 二次分类。
116
+ ## 浏览器 CDN
228
117
 
229
- ### 局部 `try/catch` 与 `suppressGlobalToast`
118
+ 不想安装依赖或配置打包工具时,可以直接使用发布的 ES module 构建:
230
119
 
231
- 当功能模块自行负责错误 UI 时,使用局部 `try/catch`,并为该请求设置 `suppressGlobalToast: true`,让全局 interceptor 跳过兜底 toast:
120
+ ```html
121
+ <script type="module">
122
+ import { createVrpcClient } from "https://cdn.jsdelivr.net/npm/@yorun-ai/vrpc@0.9.3/+esm";
232
123
 
233
- ```ts
234
- async function loadProfile() {
235
- try {
236
- return await client.invoke({
237
- serviceName: "user.UserService",
238
- methodName: "getProfile",
239
- params: { userId: 1 },
240
- options: { suppressGlobalToast: true },
241
- });
242
- } catch (error) {
243
- if (!isVrpcError(error)) {
244
- throw error;
245
- }
246
- if (error.kind === "abort") {
247
- return;
248
- }
249
- if (error.kind === "invoke" && error.code === "USER" && error.reason === "NOT_FOUND") {
250
- showToast(error.message);
251
- return;
252
- }
253
- showToast("加载用户资料失败,请稍后重试");
254
- }
255
- }
124
+ // ...
125
+ </script>
256
126
  ```
257
127
 
258
- `suppressGlobalToast` 只是提供给应用 interceptor 的策略元数据,包本身不会操作 UI。它不会跳过 `onError`,也不会吞掉错误;执行顺序仍然是先运行 `onError`,随后 Promise reject 并进入局部 `catch`。单次请求的值会覆盖 client 级默认值。
259
-
260
- ## 取消请求
128
+ 本包只发布 ES module,没有 global 构建,因此不能使用经典
129
+ `<script src="...">` 标签,标签必须带 `type="module"`。
261
130
 
262
- 通过 `requestInit.signal` 传入 `AbortSignal`。取消请求会 reject 一个 `kind` 为 `"abort"` 的错误,不会被转换成成功的 `undefined` 结果。
131
+ 完整 HTML 示例、通用 HTTP 入口、版本固定与常见问题见
132
+ [Browser CDN 使用指南](docs/guides/cdn.md)。
263
133
 
264
- ```ts
265
- import { isVrpcError } from "@yorun-ai/vrpc";
134
+ ## 入口
266
135
 
267
- const controller = new AbortController();
268
- const request = client.invoke({
269
- serviceName: "user.UserService",
270
- methodName: "getProfile",
271
- params: { userId: 1 },
272
- options: {
273
- requestInit: { signal: controller.signal },
274
- },
275
- });
136
+ | Import | 内容 |
137
+ | ----------------------- | ---------------------------------------------------- |
138
+ | `@yorun-ai/vrpc` | vRPC client、协议 helper、transport、错误与类型。 |
139
+ | `@yorun-ai/vrpc/client` | 显式 vRPC 入口,与包根入口一致。 |
140
+ | `@yorun-ai/vrpc/http` | 通用 HTTP client、Fetch transport、HTTP 错误与类型。 |
276
141
 
277
- controller.abort();
142
+ ## 配置概览
278
143
 
279
- try {
280
- await request;
281
- } catch (error) {
282
- if (!(isVrpcError(error) && error.kind === "abort")) {
283
- throw error;
284
- }
285
- }
286
- ```
144
+ 两种 client 都接受 `prefixUrl`、`headers`、`timeoutMs`、`requestInit`、
145
+ `suppressGlobalToast`、`fetchImpl`、`transport` 和 `interceptors`。vRPC client
146
+ 额外要求 `clientInfo`,并接受 `traceMode` 与 `cborCodec`。单次请求的 `options`
147
+ 会覆盖 client 默认值,`context.options` 始终是合并后的结果。
287
148
 
288
- 如果取消请求不需要展示 UI 错误,只需在全局 `onError` interceptor 中统一忽略 `abort`。超时保持为 `kind: "timeout"`,不会被误判为用户主动取消。
149
+ vRPC client 还提供两个请求选项:`trace` 覆盖自动生成的 `vrpc-trace` Header,
150
+ `wire` 为单次调用选择 JSON 或 CBOR。wire schema 永远不会被序列化进 HTTP body,
151
+ 但使用它必须配置 `cborCodec`。
289
152
 
290
- ## 协议 helper
153
+ ## 进阶能力
291
154
 
292
- ```ts
293
- import {
294
- buildVrpcHeaders,
295
- buildVrpcPath,
296
- buildVrpcRequestBody,
297
- generateVrpcId,
298
- } from "@yorun-ai/vrpc";
299
-
300
- const headers = buildVrpcHeaders({
301
- clientInfo: {
302
- clientName: "demo.browser",
303
- clientVersion: "1.0.0",
304
- clientInstanceId: getClientInstanceId(),
305
- },
306
- trace: { id: generateVrpcId() },
307
- timeoutMs: 3_000,
308
- });
155
+ - **Interceptor**:通过 `client.use()` 注册 `beforeRequest`、`afterResponse`
156
+ 和 `onError`。`onError` 在请求 Promise reject 之前执行,且不会吞掉错误。
157
+ - **取消请求**:通过 `requestInit.signal` 传入 `AbortSignal`。取消会 reject
158
+ 一个 `kind` 为 `"abort"` 的错误;超时保持 `kind: "timeout"`。
159
+ - **Trace**:`traceMode: "portal"`(默认)只生成 trace id,
160
+ `traceMode: "direct"` 还会生成 span。它不会改变路由或 `prefixUrl`。
161
+ - **CBOR**:当 arguments 或 result 含 `Binary` 时,提供 `cborCodec` 与单次调用的
162
+ `wire` schema。
163
+ - **自定义 transport**:实现 `VrpcTransport` 或 `HttpTransport`,用其他 I/O 层
164
+ 替换 Fetch。
165
+ - **`suppressGlobalToast`**:应用自定义错误 UI 的策略元数据。包本身不会展示 UI、
166
+ 不会跳过 `onError`,也不会吞掉 reject。
309
167
 
310
- const path = buildVrpcPath("user.UserService", "getProfile");
311
- const body = buildVrpcRequestBody({ userId: 1 });
312
- ```
168
+ 每项能力的具体示例见 [Usage 指南](docs/guides/usage.md)。
313
169
 
314
170
  ## 文档
315
171
 
316
- 使用指南:
172
+ ### 使用指南
317
173
 
318
- - [Usage(English)](./docs/guides/usage.md):HTTP/vRPC client 配置与扩展点。
319
- - [Axios integration(English)](./docs/guides/axios.md):自定义 Axios transport 与 JSON 协议 helper。
174
+ - [Usage(English)](docs/guides/usage.md):client 配置、请求选项、interceptor、
175
+ 错误、取消、CBOR 与自定义 transport。
176
+ - [Browser CDN(English)](docs/guides/cdn.md):CDN 加载方式与完整 HTML 示例。
177
+ - [Axios integration(English)](docs/guides/axios.md):自定义 Axios transport 与
178
+ JSON 协议 helper。
320
179
 
321
- 维护者文档:
180
+ ### Reference 与维护者文档
322
181
 
323
- - [Architecture(English)](./docs/maintainers/architecture.md):模块边界与请求数据流。
324
- - [vRPC protocol(English)](./docs/maintainers/protocol.md):path、envelope、Header、内容协商、wire schema 与生成 client 的要求。
325
- - [Releasing(English)](./docs/maintainers/releasing.md):版本管理与 npm 发布流程。
182
+ - [API Reference(English)](docs/reference/README.md):公开导出、类型、配置项、
183
+ 默认值与错误。
184
+ - [Architecture(English)](docs/maintainers/architecture.md):模块边界与请求数据流。
185
+ - [vRPC protocol(English)](docs/maintainers/protocol.md):path、envelope、Header、
186
+ 内容协商、wire schema 与生成 client 的要求。
187
+ - [Releasing(English)](docs/maintainers/releasing.md):版本管理与 npm 发布流程。
188
+ - [Contributing(English)](CONTRIBUTING.md):开发、测试、文档与 PR 流程。
189
+
190
+ 根 README 与 `docs/guides/` 面向包使用者;`docs/maintainers/` 面向仓库维护者,
191
+ 以及需要实现 transport 或 codegen 的接入方。
192
+
193
+ ## 稳定性
326
194
 
327
- 根 README 与 `docs/guides/` 面向包使用者;`docs/maintainers/` 面向仓库维护者,以及需要实现 transport 或 codegen 的接入方。公开导出、类型、默认值、Header、错误或请求行为变化时,必须同步更新面向使用者和维护者的文档。
195
+ 本包处于 `0.x` 发布阶段,已经可以使用,但 `1.0.0` 之前暂不承诺公开 API 稳定。
196
+ 不兼容的变更可以随新的 `0.x` minor 版本发布,并会提供迁移说明;`1.0.0` 将作为
197
+ 稳定 API 承诺的起点。
328
198
 
329
199
  ## License
330
200
 
package/dist/client.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_request_options = require("./request-options-m8_63jpk.cjs");
2
+ const require_request_options = require("./request-options-gljZwoeI.cjs");
3
3
  //#region src/protocol/id.ts
4
4
  var DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY = "vrpc-client-instance-id";
5
5
  function getRandomByteArray(length) {
@@ -259,7 +259,8 @@ async function decodeVrpcResponsePayload(response, cborCodec, resultSchema) {
259
259
  };
260
260
  } catch (cause) {
261
261
  if (cause instanceof require_request_options.VrpcProtocolError) throw cause;
262
- throw new require_request_options.VrpcProtocolError(response, cause instanceof Error ? cause.message : "Invalid vRPC response.", {}, { cause });
262
+ const message = cause instanceof Error ? cause.message : "Invalid vRPC response.";
263
+ throw new require_request_options.VrpcProtocolError(response, message, {}, { cause });
263
264
  }
264
265
  }
265
266
  function normalizeResponseHeaders(headers) {
package/dist/client.d.cts CHANGED
@@ -175,7 +175,6 @@ interface VrpcClient {
175
175
  //#endregion
176
176
  //#region src/contracts/errors.d.ts
177
177
  type HttpErrorPayload = {
178
- type?: string;
179
178
  code?: string;
180
179
  message?: string;
181
180
  reason?: string;
@@ -226,7 +225,6 @@ declare class VrpcProtocolError extends HttpClientError<"protocol"> {
226
225
  constructor(response: Response, message: string, requestMeta?: HttpErrorRequestMeta, options?: HttpClientErrorOptions);
227
226
  }
228
227
  declare class HttpInvokeError extends HttpClientError<"invoke"> {
229
- type?: string;
230
228
  code?: string;
231
229
  reason?: string;
232
230
  detail?: string;
package/dist/client.d.ts CHANGED
@@ -175,7 +175,6 @@ interface VrpcClient {
175
175
  //#endregion
176
176
  //#region src/contracts/errors.d.ts
177
177
  type HttpErrorPayload = {
178
- type?: string;
179
178
  code?: string;
180
179
  message?: string;
181
180
  reason?: string;
@@ -226,7 +225,6 @@ declare class VrpcProtocolError extends HttpClientError<"protocol"> {
226
225
  constructor(response: Response, message: string, requestMeta?: HttpErrorRequestMeta, options?: HttpClientErrorOptions);
227
226
  }
228
227
  declare class HttpInvokeError extends HttpClientError<"invoke"> {
229
- type?: string;
230
228
  code?: string;
231
229
  reason?: string;
232
230
  detail?: string;
package/dist/client.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as isVrpcError, c as HTTP_TIMEOUT_ERROR_CODE, d as HttpInvokeError, f as HttpTimeoutError, h as VrpcProtocolError, i as createFetchTransport, l as HttpAbortError, m as VrpcInvokeError, n as splitVrpcRequestOptions, o as buildRequestUrl, p as HttpTransportError, r as createClientCore, s as mergeHeaders, u as HttpClientError } from "./request-options-Bjy2LvRE.js";
1
+ import { _ as isVrpcError, c as HTTP_TIMEOUT_ERROR_CODE, d as HttpInvokeError, f as HttpTimeoutError, h as VrpcProtocolError, i as createFetchTransport, l as HttpAbortError, m as VrpcInvokeError, n as splitVrpcRequestOptions, o as buildRequestUrl, p as HttpTransportError, r as createClientCore, s as mergeHeaders, u as HttpClientError } from "./request-options-2g2EJjOi.js";
2
2
  //#region src/protocol/id.ts
3
3
  var DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY = "vrpc-client-instance-id";
4
4
  function getRandomByteArray(length) {
@@ -258,7 +258,8 @@ async function decodeVrpcResponsePayload(response, cborCodec, resultSchema) {
258
258
  };
259
259
  } catch (cause) {
260
260
  if (cause instanceof VrpcProtocolError) throw cause;
261
- throw new VrpcProtocolError(response, cause instanceof Error ? cause.message : "Invalid vRPC response.", {}, { cause });
261
+ const message = cause instanceof Error ? cause.message : "Invalid vRPC response.";
262
+ throw new VrpcProtocolError(response, message, {}, { cause });
262
263
  }
263
264
  }
264
265
  function normalizeResponseHeaders(headers) {
package/dist/http.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_request_options = require("./request-options-m8_63jpk.cjs");
2
+ const require_request_options = require("./request-options-gljZwoeI.cjs");
3
3
  //#region src/core/create-http-client.ts
4
4
  function resolveJsonBody(request) {
5
5
  if (request.json !== void 0 && request.body !== void 0) throw new Error("Request json and body cannot be used together.");
package/dist/http.d.cts CHANGED
@@ -62,7 +62,6 @@ type HttpClient = {
62
62
  //#endregion
63
63
  //#region src/contracts/errors.d.ts
64
64
  type HttpErrorPayload = {
65
- type?: string;
66
65
  code?: string;
67
66
  message?: string;
68
67
  reason?: string;
@@ -104,7 +103,6 @@ declare class HttpTransportError extends HttpClientError<"transport"> {
104
103
  constructor(requestMeta?: HttpErrorRequestMeta, options?: HttpClientErrorOptions);
105
104
  }
106
105
  declare class HttpInvokeError extends HttpClientError<"invoke"> {
107
- type?: string;
108
106
  code?: string;
109
107
  reason?: string;
110
108
  detail?: string;
package/dist/http.d.ts CHANGED
@@ -62,7 +62,6 @@ type HttpClient = {
62
62
  //#endregion
63
63
  //#region src/contracts/errors.d.ts
64
64
  type HttpErrorPayload = {
65
- type?: string;
66
65
  code?: string;
67
66
  message?: string;
68
67
  reason?: string;
@@ -104,7 +103,6 @@ declare class HttpTransportError extends HttpClientError<"transport"> {
104
103
  constructor(requestMeta?: HttpErrorRequestMeta, options?: HttpClientErrorOptions);
105
104
  }
106
105
  declare class HttpInvokeError extends HttpClientError<"invoke"> {
107
- type?: string;
108
106
  code?: string;
109
107
  reason?: string;
110
108
  detail?: string;
package/dist/http.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as appendQueryToUrl, c as HTTP_TIMEOUT_ERROR_CODE, d as HttpInvokeError, f as HttpTimeoutError, g as isHttpError, i as createFetchTransport, l as HttpAbortError, o as buildRequestUrl, p as HttpTransportError, r as createClientCore, s as mergeHeaders, t as splitHttpRequestOptions, u as HttpClientError } from "./request-options-Bjy2LvRE.js";
1
+ import { a as appendQueryToUrl, c as HTTP_TIMEOUT_ERROR_CODE, d as HttpInvokeError, f as HttpTimeoutError, g as isHttpError, i as createFetchTransport, l as HttpAbortError, o as buildRequestUrl, p as HttpTransportError, r as createClientCore, s as mergeHeaders, t as splitHttpRequestOptions, u as HttpClientError } from "./request-options-2g2EJjOi.js";
2
2
  //#region src/core/create-http-client.ts
3
3
  function resolveJsonBody(request) {
4
4
  if (request.json !== void 0 && request.body !== void 0) throw new Error("Request json and body cannot be used together.");
@@ -76,7 +76,6 @@ function readServerErrorStringField(payload, field) {
76
76
  return typeof value === "string" ? value : void 0;
77
77
  }
78
78
  var HttpInvokeError = class extends HttpClientError {
79
- type;
80
79
  code;
81
80
  reason;
82
81
  detail;
@@ -95,7 +94,6 @@ var HttpInvokeError = class extends HttpClientError {
95
94
  this.statusText = response.statusText;
96
95
  this.responseHeaders = response.headers;
97
96
  this.payload = payload;
98
- this.type = readServerErrorStringField(payload, "type");
99
97
  this.code = readServerErrorStringField(payload, "code");
100
98
  this.reason = readServerErrorStringField(payload, "reason");
101
99
  this.detail = readServerErrorStringField(payload, "detail");
@@ -76,7 +76,6 @@ function readServerErrorStringField(payload, field) {
76
76
  return typeof value === "string" ? value : void 0;
77
77
  }
78
78
  var HttpInvokeError = class extends HttpClientError {
79
- type;
80
79
  code;
81
80
  reason;
82
81
  detail;
@@ -95,7 +94,6 @@ var HttpInvokeError = class extends HttpClientError {
95
94
  this.statusText = response.statusText;
96
95
  this.responseHeaders = response.headers;
97
96
  this.payload = payload;
98
- this.type = readServerErrorStringField(payload, "type");
99
97
  this.code = readServerErrorStringField(payload, "code");
100
98
  this.reason = readServerErrorStringField(payload, "reason");
101
99
  this.detail = readServerErrorStringField(payload, "detail");
@@ -2,6 +2,9 @@
2
2
 
3
3
  Axios can send JSON vRPC directly or be wrapped as a runtime transport. When automatic CBOR, wire schemas, interceptors, and consistent error semantics are needed, wrap Axios as a transport and use it with `createVrpcClient`.
4
4
 
5
+ For client configuration shared by both options, see the [Usage guide](./usage.md)
6
+ and the [API Reference](../reference/README.md).
7
+
5
8
  ## Option A: send JSON vRPC directly
6
9
 
7
10
  ```ts