From 0d019dd09d6c003767dc56c9dea8075464b23d84 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:33:44 +0000 Subject: [PATCH 1/2] examples: a Transport over axios, run through the conformance suite createAxiosTransport is the SDK's Transport over an axios instance; adapterFor makes the suite's server axios's network, so the nine checks exercise axios itself. axios is a dev dependency for this example only. AGENTS.md names client.search and client.deleted among the reads. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01Rgicmffzzwb2CzyeDSEhBm --- AGENTS.md | 3 +- CHANGELOG.md | 9 + README.md | 2 +- examples/11-axios-transport.ts | 124 ++++++++++++ examples/README.md | 3 +- package-lock.json | 359 +++++++++++++++++++++++++++++++++ package.json | 13 +- 7 files changed, 507 insertions(+), 6 deletions(-) create mode 100644 examples/11-axios-transport.ts diff --git a/AGENTS.md b/AGENTS.md index bcf75c2..21a661f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,7 +56,8 @@ Four paths, and `package.json`'s `exports` lists no others (spec 000 §5a): A new export goes on the lowest of these that serves it; the root grows only for something a client user writes or reads. On the client, reads are -`client.query` / `queryPage` / `get`, and writes are `client.send`, +`client.query` / `queryPage` / `get`, `client.search` across asset types +and `client.deleted`, and writes are `client.send`, `client.preview` and `client.sendGuarded` (a guarded write compares each asset's `Moment`; what matched nothing is a conflict, never a success: spec 000 §6). diff --git a/CHANGELOG.md b/CHANGELOG.md index 0819635..24197ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Unreleased + +Nothing in the package changes. + +- `examples/11-axios-transport.ts`: a `Transport` over an axios instance + and the adapter that runs `transportConformance` against it. axios is a + dev dependency of the repository for that example alone; the package + still depends on nothing. (a browser-app consumer.) + ## 1.0.0-alpha.9 ### Breaking diff --git a/README.md b/README.md index 30a81f4..b75f181 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ const stories = await client.query({ from: "Story", select: ["Name", "Estimate"] // stories[0].Estimate is a number | null; stories[0].Nmae does not compile ``` -Runnable examples, one per task (a first read, a write, a guarded write, a batch with an undo, errors, attachments, testing your own code, a transport of your own, a browser session that expires), are in [`examples/`](examples/README.md). +Runnable examples, one per task (a first read, a write, a guarded write, a batch with an undo, errors, attachments, testing your own code, a transport of your own, a browser session that expires, searching, a transport over axios), are in [`examples/`](examples/README.md). ## Working on the SDK diff --git a/examples/11-axios-transport.ts b/examples/11-axios-transport.ts new file mode 100644 index 0000000..4315f72 --- /dev/null +++ b/examples/11-axios-transport.ts @@ -0,0 +1,124 @@ +/** + * A Transport built on axios, and the conformance suite run against it. + * For an app that already talks HTTP through an axios instance (its + * interceptors, its cancellation) and wants the SDK to use the same one. + * + * Two parts, each to copy: `createAxiosTransport`, the Transport; and + * `adapterFor`, which lets the suite stand in for the network, so the + * checks exercise axios itself rather than a mock of it. In a test file + * the last lines become `for (const check of checks) it(check.name, check.run)`. + * + * Needs no instance and no credentials. axios is this repository's dev + * dependency for this example only; the SDK itself depends on nothing. + * + * node examples/11-axios-transport.ts + */ +import axios, { AxiosError, AxiosHeaders, CanceledError, type AxiosAdapter, type AxiosInstance, type InternalAxiosRequestConfig, type RawAxiosHeaders } from "axios"; +import { ApiError, apiErrorFromResponse } from "@versionone/agility-sdk"; +import type { RequestOptions, Transport } from "@versionone/agility-sdk"; +import { CONFORMANCE_BASE_URL, transportConformance, type ConformanceServer } from "@versionone/agility-sdk/testing"; + +const aborted = (cause?: unknown) => new ApiError("Request aborted", 0, "ABORTED", { cause }); +const isJson = (contentType: string) => /\bjson\b/i.test(contentType); + +/** What to send for a body, and the content type it implies: the SDK's rule, not axios's own guess. */ +function bodyOf(options: RequestOptions): { data: unknown; type?: string } { + const { body, contentType } = options; + if (body === undefined || body === null) return { data: undefined }; + if (typeof FormData !== "undefined" && body instanceof FormData) return { data: body }; // the runtime writes the boundary + if (typeof Blob !== "undefined" && body instanceof Blob) return { data: body, type: contentType ?? (body.type || "application/octet-stream") }; + if (body instanceof Uint8Array || body instanceof ArrayBuffer) return { data: body, type: contentType ?? "application/octet-stream" }; + if (typeof body === "string") return { data: body, type: contentType ?? "text/plain" }; + return { data: JSON.stringify(body), type: contentType ?? "application/json" }; +} + +/** A response body as the SDK reads a refusal's: parsed when it is JSON, else the text. */ +function readable(data: unknown, contentType: string): unknown { + const text = typeof data === "string" ? data : data instanceof ArrayBuffer ? new TextDecoder().decode(data) : data; + if (typeof text !== "string" || !isJson(contentType)) return text; + try { return JSON.parse(text); } catch { return text; } +} + +/** The SDK's Transport over an axios instance whose `baseURL` is the Agility instance. */ +export function createAxiosTransport(http: AxiosInstance): Transport { + return { + async request(options: RequestOptions): Promise { + // Nothing is sent for a request that was cancelled before it began. + if (options.signal?.aborted) throw aborted(options.signal.reason); + const { data, type } = bodyOf(options); + const bytes = options.responseType === "bytes"; + let response; + try { + response = await http.request({ + method: options.method, + url: options.path.replace(/^\/+/, ""), // relative, so it stays under baseURL's path + params: Object.fromEntries(Object.entries(options.query ?? {}).filter(([, value]) => value !== undefined && value !== null)), + headers: { ...options.headers, ...(type ? { "Content-Type": type } : {}) }, + data, + signal: options.signal, + responseType: bytes ? "arraybuffer" : "text", + transformRequest: [(body) => body], // already in the shape to send + transformResponse: [(body) => body], // read below, by the SDK's rules + validateStatus: (status) => (status >= 200 && status < 300) || (status === 304 && options.acceptNotModified === true) + }); + } catch (error) { + if (axios.isCancel(error) || options.signal?.aborted) throw aborted(error); + if (error instanceof AxiosError && error.response) { + // A refusal: the same error, word for word, as the SDK's own transport throws. + throw apiErrorFromResponse(error.response.status, readable(error.response.data, String(error.response.headers["content-type"] ?? ""))); + } + const timedOut = error instanceof AxiosError && (error.code === AxiosError.ECONNABORTED || error.code === AxiosError.ETIMEDOUT); + throw new ApiError(error instanceof Error ? error.message : String(error), 0, timedOut ? "TIMEOUT" : "NETWORK_ERROR", { cause: error }); + } + const headers = AxiosHeaders.from(response.headers as RawAxiosHeaders); + options.onResponse?.({ status: response.status, headers: { get: (name) => { const value = headers.get(name); return value == null ? null : String(value); } } }); + if (response.status === 304) return undefined as T; + if (bytes) return new Uint8Array(response.data as ArrayBuffer) as T; + const text = String(response.data ?? ""); + const wanted = options.responseType ?? "auto"; + if (wanted === "text" || (wanted === "auto" && !isJson(String(headers.get("content-type") ?? "")))) return text as T; + if (text === "") return undefined as T; // an empty body is no value, not a parse error + try { return JSON.parse(text) as T; } catch { throw new ApiError("Response is not JSON", response.status, "BAD_JSON", { body: text.slice(0, 500) }); } + } + }; +} + +/** axios as it is in an app, except that its network is the suite's server. */ +const adapterFor = (server: ConformanceServer): AxiosAdapter => async (config: InternalAxiosRequestConfig) => { + const signal = config.signal as AbortSignal | undefined; + if (signal?.aborted) throw new CanceledError(undefined, undefined, config); + const headers: Record = {}; + for (const [name, value] of Object.entries(AxiosHeaders.from(config.headers).toJSON())) { + if (value !== undefined && value !== null) headers[name.toLowerCase()] = String(value); + } + const answer = await server({ + method: (config.method ?? "get").toUpperCase(), + url: axios.getUri(config), // baseURL + url + params, as axios would send it + headers, + body: config.data, // after transformRequest: what axios would put on the wire + signal + }); + if (signal?.aborted) throw new CanceledError(undefined, undefined, config); + if (answer === "network-error") throw new AxiosError("Network Error", AxiosError.ERR_NETWORK, config); + const body = answer.body ?? ""; + const data = config.responseType === "arraybuffer" + ? (typeof body === "string" ? new TextEncoder().encode(body).buffer : body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength)) + : (typeof body === "string" ? body : new TextDecoder().decode(body)); + const response = { data, status: answer.status, statusText: "", headers: AxiosHeaders.from(answer.headers ?? {}), config, request: {} }; + // A custom adapter settles the response itself. Without this, a 304 and a refusal would pass the suite for the wrong reason. + if (!config.validateStatus || config.validateStatus(answer.status)) return response; + throw new AxiosError(`Request failed with status code ${answer.status}`, AxiosError.ERR_BAD_RESPONSE, config, {}, response); +}; + +const checks = transportConformance((server) => createAxiosTransport(axios.create({ baseURL: CONFORMANCE_BASE_URL, adapter: adapterFor(server) }))); +let broken = 0; +for (const check of checks) { + try { + await check.run(); + } catch (error) { + broken += 1; + console.log(`BROKEN: ${(error as Error).message}`); + } +} +console.log(`${checks.length - broken} of ${checks.length} conformance checks pass for the axios transport`); +if (broken) process.exitCode = 1; diff --git a/examples/README.md b/examples/README.md index 8e9b545..60db985 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ # Examples -Ten short programs, one per task, each runnable as it stands. Read them +Eleven short programs, one per task, each runnable as it stands. Read them in order; each says at the top what it does. | File | Shows | Writes? | @@ -15,6 +15,7 @@ in order; each says at the top what it does. | `08-custom-transport.ts` | A `Transport` of your own (a timed wrapper), checked with `transportConformance` | no; a live read only if an instance is set | | `09-browser-session.ts` | Cookie auth for a browser app: `credentials`, `onUnauthorized`, and when `"retry-write"` is yours to answer | no instance at all (a stand-in server) | | `10-search.ts` | `client.search` across asset types; `find` on an ordinary read within one family | no | +| `11-axios-transport.ts` | A `Transport` over an axios instance, and an axios adapter that lets `transportConformance` stand in for the network | no instance at all | ## Running one diff --git a/package-lock.json b/package-lock.json index 0ecf49e..d0ce167 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "devDependencies": { "@types/node": "^22.13.10", + "axios": "^1.21.1", "rimraf": "^6.0.1", "tsup": "^9.0.0", "typescript": "^5.8.2", @@ -1256,6 +1257,19 @@ "node": ">=0.4.0" } }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/any-promise": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", @@ -1273,6 +1287,26 @@ "node": ">=12" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.21.1.tgz", + "integrity": "sha512-6eI5Q/Y4u/Um9dDlsRoq5pY2rxnUTv+L4PpLitnbk/i4jb3MxLZ5CsN5Ih3IysbeRYK4pR+P7qfMsOQl9fwwFQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.16.2", + "form-data": "^4.0.6", + "https-proxy-agent": "^5.0.1", + "proxy-from-env": "^2.1.0" + } + }, "node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", @@ -1322,6 +1356,20 @@ "node": ">=20.19.0" } }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/chai": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", @@ -1348,6 +1396,19 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -1375,6 +1436,34 @@ "node": "^14.18.0 || >=16.10.0" } }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -1386,6 +1475,41 @@ "node": ">=8" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", @@ -1393,6 +1517,35 @@ "dev": true, "license": "MIT" }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/esbuild": { "version": "0.28.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", @@ -1485,6 +1638,44 @@ "rollup": "^4.34.8" } }, + "node_modules/follow-redirects": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.3.tgz", + "integrity": "sha512-toOSoqN6d51Wjf1aOFJYcoVv1aND9rj/CwjLU0Vz40oDuSpWDayCeKe4JpL5NL0WdFvoOOCI3BRo69HahjbR1A==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1500,6 +1691,55 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/glob": { "version": "14.0.4", "resolved": "https://registry.npmjs.org/glob/-/glob-14.0.4.tgz", @@ -1518,6 +1758,75 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/joycon": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", @@ -1851,6 +2160,39 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "11.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.5.tgz", @@ -1891,6 +2233,13 @@ "ufo": "^1.6.1" } }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, "node_modules/mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", @@ -2093,6 +2442,16 @@ } } }, + "node_modules/proxy-from-env": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", + "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + } + }, "node_modules/readdirp": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.1.1.tgz", diff --git a/package.json b/package.json index 9935b5f..df58336 100644 --- a/package.json +++ b/package.json @@ -61,9 +61,15 @@ }, "typesVersions": { "*": { - "wire": ["dist/wire.d.ts"], - "services": ["dist/services.d.ts"], - "testing": ["dist/testing.d.ts"] + "wire": [ + "dist/wire.d.ts" + ], + "services": [ + "dist/services.d.ts" + ], + "testing": [ + "dist/testing.d.ts" + ] } }, "files": [ @@ -88,6 +94,7 @@ }, "devDependencies": { "@types/node": "^22.13.10", + "axios": "^1.21.1", "rimraf": "^6.0.1", "tsup": "^9.0.0", "typescript": "^5.8.2", From 41426b958e234437149d048823a7367daa340029 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:34:29 +0000 Subject: [PATCH 2/2] examples: say what the axios transport does about timeouts, and why Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01Rgicmffzzwb2CzyeDSEhBm --- examples/11-axios-transport.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/11-axios-transport.ts b/examples/11-axios-transport.ts index 4315f72..2cd27db 100644 --- a/examples/11-axios-transport.ts +++ b/examples/11-axios-transport.ts @@ -67,6 +67,11 @@ export function createAxiosTransport(http: AxiosInstance): Transport { // A refusal: the same error, word for word, as the SDK's own transport throws. throw apiErrorFromResponse(error.response.status, readable(error.response.data, String(error.response.headers["content-type"] ?? ""))); } + // Timing is this transport's own business today: the client's `timeoutMs` binds only the SDK's built-in + // transport, so the axios instance needs its own `timeout`, and its timeout must be reported as TIMEOUT + // here for the client's resend rule to recognise it. Were the client to enforce `timeoutMs` above every + // transport (it would hand over a signal that fires when time is up), neither would be needed: honouring + // `signal`, as above, would be all a transport owes, and these two lines could go. const timedOut = error instanceof AxiosError && (error.code === AxiosError.ECONNABORTED || error.code === AxiosError.ETIMEDOUT); throw new ApiError(error instanceof Error ? error.message : String(error), 0, timedOut ? "TIMEOUT" : "NETWORK_ERROR", { cause: error }); }