stitchkit 0.43.0 → 0.43.1
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/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +2 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/request-id.d.ts +3 -0
- package/dist/browser/request-id.d.ts.map +1 -0
- package/dist/index.js +15 -6
- package/dist/tools.js +13 -3
- package/llms-full.txt +12 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/browser/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAEL,KAAK,UAAU,IAAI,WAAW,EAG9B,KAAK,mBAAmB,EACzB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/browser/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAEL,KAAK,UAAU,IAAI,WAAW,EAG9B,KAAK,mBAAmB,EACzB,MAAM,QAAQ,CAAC;AA6ChB,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACnD;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CAAE,CAOxE;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACnD,KAAK,CAAC,OAAO,SAAS,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAEnE,SAAS,EAAE,CAAC,EACZ,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,OAAO,GACpB,wBAAwB,CAAC,CAAC,EAAE,OAAO,CAAC,CAOtC"}
|
package/dist/browser/http.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export declare class ApiError extends Error {
|
|
|
14
14
|
readonly status: number;
|
|
15
15
|
readonly details?: unknown;
|
|
16
16
|
readonly hint?: string | undefined;
|
|
17
|
-
|
|
17
|
+
readonly traceId?: string | undefined;
|
|
18
|
+
constructor(code: string, status?: number, details?: unknown, message?: string, hint?: string | undefined, traceId?: string | undefined);
|
|
18
19
|
static is(error: unknown): error is ApiError;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/browser/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/browser/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjD,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,MAAM,MAAM,gBAAgB,GAAG,CAAC,KA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E,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7D,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAC;IAClD,gFAAgF;IAChF,MAAM,IAAI,IAAI,CAAC;IACf,oEAAoE;IACpE,gBAAgB,IAAI,IAAI,CAAC;CAC1B;AAED,gFAAgF;AAChF,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,oBAAoB,CA4L/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id.d.ts","sourceRoot":"","sources":["../../src/browser/request-id.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAElF"}
|
package/dist/index.js
CHANGED
|
@@ -246,18 +246,26 @@ function childSpan(parent) {
|
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
// src/browser/request-id.ts
|
|
250
|
+
var REQUEST_ID_HEADER = "x-request-id";
|
|
251
|
+
function responseTraceId(response) {
|
|
252
|
+
return response?.headers.get(REQUEST_ID_HEADER) ?? undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
249
255
|
// src/browser/http.ts
|
|
250
256
|
class ApiError extends Error {
|
|
251
257
|
code;
|
|
252
258
|
status;
|
|
253
259
|
details;
|
|
254
260
|
hint;
|
|
255
|
-
|
|
261
|
+
traceId;
|
|
262
|
+
constructor(code, status = 0, details, message, hint, traceId) {
|
|
256
263
|
super(message ?? `API Error: ${code}`);
|
|
257
264
|
this.code = code;
|
|
258
265
|
this.status = status;
|
|
259
266
|
this.details = details;
|
|
260
267
|
this.hint = hint;
|
|
268
|
+
this.traceId = traceId;
|
|
261
269
|
this.name = "ApiError";
|
|
262
270
|
}
|
|
263
271
|
static is(error) {
|
|
@@ -330,7 +338,7 @@ function createHttpClient(config) {
|
|
|
330
338
|
if (body) {
|
|
331
339
|
const parsed = parseError(body);
|
|
332
340
|
if (parsed) {
|
|
333
|
-
throw new ApiError(parsed.code, response.status, parsed.details, parsed.message, parsed.hint);
|
|
341
|
+
throw new ApiError(parsed.code, response.status, parsed.details, parsed.message, parsed.hint, responseTraceId(response));
|
|
334
342
|
}
|
|
335
343
|
}
|
|
336
344
|
}
|
|
@@ -388,9 +396,10 @@ function createHttpClient(config) {
|
|
|
388
396
|
if (!isAbort) {
|
|
389
397
|
emit({ type: "network_error" });
|
|
390
398
|
}
|
|
391
|
-
const
|
|
399
|
+
const response = !isAbort && isHTTPError(error) ? error.response : undefined;
|
|
400
|
+
const status = response?.status ?? 0;
|
|
392
401
|
const msg = error instanceof Error ? error.message : undefined;
|
|
393
|
-
throw new ApiError("UNKNOWN_ERROR", status, msg ? { message: msg } : undefined);
|
|
402
|
+
throw new ApiError("UNKNOWN_ERROR", status, msg ? { message: msg } : undefined, undefined, undefined, responseTraceId(response));
|
|
394
403
|
}
|
|
395
404
|
}
|
|
396
405
|
return {
|
|
@@ -608,9 +617,9 @@ async function throwForErrorResponse(res, config, fallbackBody) {
|
|
|
608
617
|
config.onError?.(res.status, body);
|
|
609
618
|
const parsed = parseApiErrorBody(body);
|
|
610
619
|
if (parsed) {
|
|
611
|
-
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint);
|
|
620
|
+
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint, responseTraceId(res));
|
|
612
621
|
}
|
|
613
|
-
throw new ApiError("HTTP_ERROR", res.status, { body });
|
|
622
|
+
throw new ApiError("HTTP_ERROR", res.status, { body }, undefined, undefined, responseTraceId(res));
|
|
614
623
|
}
|
|
615
624
|
function createUrlBuilder(contract, source, contractConfig) {
|
|
616
625
|
const builder = {};
|
package/dist/tools.js
CHANGED
|
@@ -1587,17 +1587,27 @@ function joinClientBaseUrl(baseUrl, relativeUrl) {
|
|
|
1587
1587
|
|
|
1588
1588
|
// src/browser/http.ts
|
|
1589
1589
|
import ky, { isHTTPError } from "ky";
|
|
1590
|
+
|
|
1591
|
+
// src/browser/request-id.ts
|
|
1592
|
+
var REQUEST_ID_HEADER = "x-request-id";
|
|
1593
|
+
function responseTraceId(response) {
|
|
1594
|
+
return response?.headers.get(REQUEST_ID_HEADER) ?? undefined;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// src/browser/http.ts
|
|
1590
1598
|
class ApiError extends Error {
|
|
1591
1599
|
code;
|
|
1592
1600
|
status;
|
|
1593
1601
|
details;
|
|
1594
1602
|
hint;
|
|
1595
|
-
|
|
1603
|
+
traceId;
|
|
1604
|
+
constructor(code, status = 0, details, message, hint, traceId) {
|
|
1596
1605
|
super(message ?? `API Error: ${code}`);
|
|
1597
1606
|
this.code = code;
|
|
1598
1607
|
this.status = status;
|
|
1599
1608
|
this.details = details;
|
|
1600
1609
|
this.hint = hint;
|
|
1610
|
+
this.traceId = traceId;
|
|
1601
1611
|
this.name = "ApiError";
|
|
1602
1612
|
}
|
|
1603
1613
|
static is(error) {
|
|
@@ -1758,9 +1768,9 @@ async function throwForErrorResponse(res, config, fallbackBody) {
|
|
|
1758
1768
|
config.onError?.(res.status, body);
|
|
1759
1769
|
const parsed = parseApiErrorBody(body);
|
|
1760
1770
|
if (parsed) {
|
|
1761
|
-
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint);
|
|
1771
|
+
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint, responseTraceId(res));
|
|
1762
1772
|
}
|
|
1763
|
-
throw new ApiError("HTTP_ERROR", res.status, { body });
|
|
1773
|
+
throw new ApiError("HTTP_ERROR", res.status, { body }, undefined, undefined, responseTraceId(res));
|
|
1764
1774
|
}
|
|
1765
1775
|
|
|
1766
1776
|
// src/tools/remote.ts
|
package/llms-full.txt
CHANGED
|
@@ -1546,10 +1546,16 @@ try {
|
|
|
1546
1546
|
err.message // 'Note not found'
|
|
1547
1547
|
err.details // structured details, if any
|
|
1548
1548
|
err.hint // optional hint
|
|
1549
|
+
err.traceId // x-request-id — correlate this failure with backend logs
|
|
1549
1550
|
}
|
|
1550
1551
|
}
|
|
1551
1552
|
```
|
|
1552
1553
|
|
|
1554
|
+
`traceId` is present when the server returned `x-request-id`. A network error,
|
|
1555
|
+
timeout or abort without an HTTP response cannot carry one. Cross-origin
|
|
1556
|
+
browser code can read it through Stitchkit's default CORS expose list; a custom
|
|
1557
|
+
`cors.exposeHeaders` policy must keep `x-request-id` exposed.
|
|
1558
|
+
|
|
1553
1559
|
The error model is shared with the server — see [Auth & errors](./auth-and-errors.md).
|
|
1554
1560
|
|
|
1555
1561
|
## Auth events
|
|
@@ -3342,8 +3348,9 @@ Use the exported `zodIssues(error)` to build the same structured list from a
|
|
|
3342
3348
|
### On the client
|
|
3343
3349
|
|
|
3344
3350
|
The client parses that envelope back into an `ApiError` with the same `code`,
|
|
3345
|
-
`status`, `details` and `hint
|
|
3346
|
-
|
|
3351
|
+
`status`, `details` and `hint`, plus the response `x-request-id` as optional
|
|
3352
|
+
readonly `traceId` — see [Typed client → ApiError](./client.md#apierror). The
|
|
3353
|
+
error round-trips without adding correlation data to the response body.
|
|
3347
3354
|
|
|
3348
3355
|
### Stitch codes vs your codes
|
|
3349
3356
|
|
|
@@ -3701,7 +3708,8 @@ locally; you do not need to change `NODE_ENV` or deploy.
|
|
|
3701
3708
|
Every response the stitchkit handler produces carries the resolved id as
|
|
3702
3709
|
**`x-request-id`**. With `cors` configured it is in the default
|
|
3703
3710
|
`Access-Control-Expose-Headers`, so a browser client can read it and quote it in
|
|
3704
|
-
a bug report.
|
|
3711
|
+
a bug report. Stitchkit browser clients retain it as `ApiError.traceId` on
|
|
3712
|
+
response-backed failures. Note the deliberate asymmetry: inbound the id may arrive as
|
|
3705
3713
|
`X-Trace-Id` *or* `X-Request-Id`; outbound there is one name and no alias.
|
|
3706
3714
|
|
|
3707
3715
|
Log the same id from nginx and the two logs join on one key. `log_format` and
|
|
@@ -4839,7 +4847,7 @@ The browser-and-server entrypoint. Re-exports everything from
|
|
|
4839
4847
|
| `contractEndpointMatchers` | function | compile exact pathname matchers for selected HTTP contract operations and expected-401 policy |
|
|
4840
4848
|
| `PathPrefixArgs` | _type_ | required string-valued keys exposed to a typed dynamic `pathPrefix` callback |
|
|
4841
4849
|
| `createHttpClient` | function | the Ky-based HTTP transport — [guide](../guide/client.md#createhttpclient) |
|
|
4842
|
-
| `ApiError` | class | a non-2xx response, with `code` / `status` / `details` / `hint` |
|
|
4850
|
+
| `ApiError` | class | a non-2xx response, with `code` / `status` / `details` / `hint` and optional readonly `traceId` from `x-request-id` |
|
|
4843
4851
|
| `HttpClient` | _type_ | the transport interface `createClient` builds on |
|
|
4844
4852
|
| `ConfiguredHttpClient` | _type_ | a framework-created `HttpClient` carrying its readonly `baseUrl` for URL builders |
|
|
4845
4853
|
| `HttpClientConfig` | _type_ | config for `createHttpClient` |
|
package/package.json
CHANGED