@smartcrab/result 0.3.0 → 0.3.1-next-20261013030252
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/index.d.ts +2 -0
- package/dist/index.js +4 -3
- package/package.json +1 -1
- package/src/index.test.ts +1 -1
- package/src/index.ts +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface ProblemDetails {
|
|
|
25
25
|
readonly request_id?: string;
|
|
26
26
|
readonly [extension: string]: unknown;
|
|
27
27
|
}
|
|
28
|
+
/** RFC 9457 `type` URI for an error code; `_` becomes `-` in the slug. */
|
|
29
|
+
export declare const problemTypeUri: (code: string) => string;
|
|
28
30
|
export declare const statusForErrorType: (type: string) => number;
|
|
29
31
|
export interface ToProblemDetailsOptions {
|
|
30
32
|
/** Overrides the inferred HTTP status. */
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* - Structured JSON logger with secret redaction (design.md §32.6, §34.1).
|
|
8
8
|
*/
|
|
9
9
|
export { Result } from "@praha/byethrow";
|
|
10
|
-
const PROBLEM_TYPE_BASE = "https://docs.
|
|
10
|
+
const PROBLEM_TYPE_BASE = "https://docs.zeroword.smartcrab.ai/errors";
|
|
11
|
+
/** RFC 9457 `type` URI for an error code; `_` becomes `-` in the slug. */
|
|
12
|
+
export const problemTypeUri = (code) => `${PROBLEM_TYPE_BASE}/${code.replaceAll("_", "-")}`;
|
|
11
13
|
/** Default HTTP status inference from an error `type`. Domains may override. */
|
|
12
14
|
const DEFAULT_STATUS_BY_TYPE = {
|
|
13
15
|
validation_failed: 400,
|
|
@@ -57,9 +59,8 @@ const titleForStatus = (status) => {
|
|
|
57
59
|
/** Maps a typed domain error to an RFC 9457 Problem Details body. */
|
|
58
60
|
export const toProblemDetails = (error, options = {}) => {
|
|
59
61
|
const status = options.status ?? statusForErrorType(error.type);
|
|
60
|
-
const slug = error.type.replaceAll("_", "-");
|
|
61
62
|
return {
|
|
62
|
-
type:
|
|
63
|
+
type: problemTypeUri(error.type),
|
|
63
64
|
title: titleForStatus(status),
|
|
64
65
|
status,
|
|
65
66
|
code: error.type,
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -13,7 +13,7 @@ describe("problem details", () => {
|
|
|
13
13
|
const problem = toProblemDetails({ type: "invalid_redirect_uri" }, { requestId: "req_abc" });
|
|
14
14
|
expect(problem.status).toBe(400);
|
|
15
15
|
expect(problem.code).toBe("invalid_redirect_uri");
|
|
16
|
-
expect(problem.type).toBe("https://docs.
|
|
16
|
+
expect(problem.type).toBe("https://docs.zeroword.smartcrab.ai/errors/invalid-redirect-uri");
|
|
17
17
|
expect(problem.request_id).toBe("req_abc");
|
|
18
18
|
});
|
|
19
19
|
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,11 @@ export interface ProblemDetails {
|
|
|
36
36
|
readonly [extension: string]: unknown;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const PROBLEM_TYPE_BASE = "https://docs.
|
|
39
|
+
const PROBLEM_TYPE_BASE = "https://docs.zeroword.smartcrab.ai/errors";
|
|
40
|
+
|
|
41
|
+
/** RFC 9457 `type` URI for an error code; `_` becomes `-` in the slug. */
|
|
42
|
+
export const problemTypeUri = (code: string): string =>
|
|
43
|
+
`${PROBLEM_TYPE_BASE}/${code.replaceAll("_", "-")}`;
|
|
40
44
|
|
|
41
45
|
/** Default HTTP status inference from an error `type`. Domains may override. */
|
|
42
46
|
const DEFAULT_STATUS_BY_TYPE: Readonly<Record<string, number>> = {
|
|
@@ -105,9 +109,8 @@ export const toProblemDetails = (
|
|
|
105
109
|
options: ToProblemDetailsOptions = {},
|
|
106
110
|
): ProblemDetails => {
|
|
107
111
|
const status = options.status ?? statusForErrorType(error.type);
|
|
108
|
-
const slug = error.type.replaceAll("_", "-");
|
|
109
112
|
return {
|
|
110
|
-
type:
|
|
113
|
+
type: problemTypeUri(error.type),
|
|
111
114
|
title: titleForStatus(status),
|
|
112
115
|
status,
|
|
113
116
|
code: error.type,
|