@outfitter/contracts 0.4.1 → 0.5.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.
Files changed (100) hide show
  1. package/README.md +18 -15
  2. package/dist/actions.d.ts +8 -3
  3. package/dist/actions.js +25 -6
  4. package/dist/assert/index.d.ts +7 -3
  5. package/dist/assert/index.js +59 -6
  6. package/dist/capabilities.js +57 -8
  7. package/dist/context.d.ts +8 -3
  8. package/dist/context.js +1 -1
  9. package/dist/envelope.d.ts +6 -2
  10. package/dist/envelope.js +49 -7
  11. package/dist/errors.d.ts +6 -2
  12. package/dist/errors.js +7 -1
  13. package/dist/from-fetch.d.ts +7 -0
  14. package/dist/from-fetch.js +110 -0
  15. package/dist/handler.d.ts +7 -2
  16. package/dist/hints.d.ts +2 -0
  17. package/dist/index.d.ts +25 -14
  18. package/dist/index.js +17 -153
  19. package/dist/internal/error-base.d.ts +2 -0
  20. package/dist/internal/error-base.js +31 -0
  21. package/dist/internal/error-operational.d.ts +3 -0
  22. package/dist/internal/error-operational.js +125 -0
  23. package/dist/internal/error-serialization.d.ts +7 -0
  24. package/dist/{shared/@outfitter/contracts-3wj7xghe.js → internal/error-serialization.js} +28 -67
  25. package/dist/internal/error-taxonomy.d.ts +2 -0
  26. package/dist/internal/error-taxonomy.js +21 -0
  27. package/dist/internal/error-validation.d.ts +3 -0
  28. package/dist/internal/error-validation.js +121 -0
  29. package/dist/internal/safe-json.d.ts +7 -0
  30. package/dist/internal/safe-json.js +66 -0
  31. package/dist/internal/schema-converters.d.ts +26 -0
  32. package/dist/internal/schema-converters.js +12 -0
  33. package/dist/internal/schema-primitives.d.ts +10 -0
  34. package/dist/internal/schema-primitives.js +9 -0
  35. package/dist/internal/schema-types.d.ts +2 -0
  36. package/dist/internal/schema-types.js +9 -0
  37. package/dist/logging.js +11 -3
  38. package/dist/recovery.d.ts +6 -2
  39. package/dist/recovery.js +49 -6
  40. package/dist/resilience.d.ts +6 -2
  41. package/dist/resilience.js +80 -4
  42. package/dist/result/index.js +1 -16
  43. package/dist/result/utilities.js +29 -7
  44. package/dist/schema.d.ts +2 -1
  45. package/dist/schema.js +165 -2
  46. package/dist/serialization.d.ts +8 -2
  47. package/dist/serialization.js +1 -3
  48. package/dist/shared/@outfitter/{contracts-k71jqd1m.d.ts → contracts-10p5q75w.d.ts} +1 -1
  49. package/dist/shared/@outfitter/contracts-1zzcpfyg.d.ts +40 -0
  50. package/dist/shared/@outfitter/contracts-3f5k5tg5.d.ts +28 -0
  51. package/dist/shared/@outfitter/contracts-3qmyq81n.d.ts +78 -0
  52. package/dist/shared/@outfitter/contracts-3re9d4bp.js +114 -0
  53. package/dist/shared/@outfitter/contracts-735ecmbq.d.ts +107 -0
  54. package/dist/shared/@outfitter/contracts-7a0xmwbg.d.ts +11 -0
  55. package/dist/shared/@outfitter/contracts-8cmkh2db.d.ts +31 -0
  56. package/dist/shared/@outfitter/{contracts-agmt8915.js → contracts-c3qfce25.js} +3 -0
  57. package/dist/shared/@outfitter/{contracts-1waabxbk.d.ts → contracts-drwd9ywk.d.ts} +4 -1
  58. package/dist/shared/@outfitter/{contracts-0snpmkdt.js → contracts-hgh47193.js} +10 -4
  59. package/dist/shared/@outfitter/contracts-hrepwwne.js +62 -0
  60. package/dist/shared/@outfitter/contracts-jtn6b927.js +18 -0
  61. package/dist/shared/@outfitter/contracts-jtt6dnmg.js +2 -0
  62. package/dist/shared/@outfitter/contracts-jyhqr766.js +25 -0
  63. package/dist/shared/@outfitter/contracts-mehpmvwp.d.ts +164 -0
  64. package/dist/shared/@outfitter/contracts-msxdg52h.d.ts +125 -0
  65. package/dist/shared/@outfitter/{contracts-95cc3y06.d.ts → contracts-mt027fqj.d.ts} +2 -1
  66. package/dist/shared/@outfitter/contracts-njb2art4.d.ts +174 -0
  67. package/dist/shared/@outfitter/contracts-p77yjs4g.d.ts +46 -0
  68. package/dist/shared/@outfitter/contracts-qpbv29bg.d.ts +59 -0
  69. package/dist/shared/@outfitter/contracts-sawwfgb5.js +111 -0
  70. package/dist/shared/@outfitter/{contracts-e4m948m7.d.ts → contracts-t4txv24h.d.ts} +2 -1
  71. package/dist/shared/@outfitter/contracts-vbgt9rfn.d.ts +74 -0
  72. package/dist/shared/@outfitter/{contracts-56pcsavx.d.ts → contracts-vhajx4gg.d.ts} +8 -2
  73. package/dist/shared/@outfitter/contracts-vhr2ep6b.js +3 -0
  74. package/dist/shared/@outfitter/contracts-w7nvcwrp.d.ts +44 -0
  75. package/dist/shared/@outfitter/contracts-x0ppyt7e.d.ts +76 -0
  76. package/dist/shared/@outfitter/{contracts-0akf2sm6.d.ts → contracts-zma4mscd.d.ts} +16 -1
  77. package/dist/shared/@outfitter/contracts-zsgxsa91.d.ts +84 -0
  78. package/dist/stream.d.ts +2 -0
  79. package/dist/stream.js +1 -0
  80. package/dist/validation.d.ts +7 -3
  81. package/dist/validation.js +6 -2
  82. package/dist/wrap-error.d.ts +7 -0
  83. package/dist/wrap-error.js +71 -0
  84. package/package.json +44 -20
  85. package/dist/shared/@outfitter/contracts-31penhwa.d.ts +0 -81
  86. package/dist/shared/@outfitter/contracts-3gswmhb1.d.ts +0 -446
  87. package/dist/shared/@outfitter/contracts-4zaj7ejb.js +0 -52
  88. package/dist/shared/@outfitter/contracts-85nd53s9.js +0 -53
  89. package/dist/shared/@outfitter/contracts-9wtm5nsw.d.ts +0 -42
  90. package/dist/shared/@outfitter/contracts-cp5c6dws.js +0 -32
  91. package/dist/shared/@outfitter/contracts-d0tq2adf.js +0 -60
  92. package/dist/shared/@outfitter/contracts-mmg0npfk.d.ts +0 -30
  93. package/dist/shared/@outfitter/contracts-phjhz5q3.js +0 -293
  94. package/dist/shared/@outfitter/contracts-q0v44kef.js +0 -28
  95. package/dist/shared/@outfitter/contracts-r21yet6j.js +0 -80
  96. package/dist/shared/@outfitter/contracts-sm6vak1a.js +0 -14
  97. package/dist/shared/@outfitter/contracts-t79engf9.d.ts +0 -60
  98. package/dist/shared/@outfitter/contracts-wfht4q2b.js +0 -341
  99. package/dist/shared/@outfitter/contracts-zx72gyh1.js +0 -32
  100. /package/dist/{shared/@outfitter/contracts-37gpc56f.js → hints.js} +0 -0
@@ -0,0 +1,76 @@
1
+ import { ValidationError } from "./contracts-mehpmvwp.js";
2
+ import { Result } from "better-result";
3
+ import { z } from "zod";
4
+ /**
5
+ * Format Zod issues into a human-readable error message.
6
+ *
7
+ * @param issues - Array of Zod validation issues
8
+ * @returns Formatted error message string
9
+ */
10
+ declare function formatZodIssues(issues: z.ZodIssue[]): string;
11
+ /**
12
+ * Create a validator function from a Zod schema.
13
+ *
14
+ * @typeParam T - The validated output type
15
+ * @param schema - Zod schema to validate against
16
+ * @returns A function that validates input and returns Result
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const NoteSchema = z.object({
21
+ * id: z.string().uuid(),
22
+ * title: z.string().min(1),
23
+ * });
24
+ *
25
+ * const validateNote = createValidator(NoteSchema);
26
+ * const result = validateNote(input); // Result<Note, ValidationError>
27
+ * ```
28
+ */
29
+ declare function createValidator<T>(schema: z.ZodType<T>): (input: unknown) => Result<T, ValidationError>;
30
+ /**
31
+ * Validate input against a Zod schema.
32
+ *
33
+ * Standardized wrapper for Zod schemas that returns Result instead of throwing.
34
+ *
35
+ * @typeParam T - The validated output type
36
+ * @param schema - Zod schema to validate against
37
+ * @param input - Unknown input to validate
38
+ * @returns Result with validated data or ValidationError
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const result = validateInput(NoteSchema, userInput);
43
+ * if (result.isErr()) {
44
+ * console.error(result.unwrapErr().message);
45
+ * }
46
+ * ```
47
+ */
48
+ declare function validateInput<T>(schema: z.ZodType<T>, input: unknown): Result<T, ValidationError>;
49
+ /**
50
+ * Parse and validate data against a Zod schema, returning a Result.
51
+ *
52
+ * Wraps Zod's `safeParse` into `Result<T, ValidationError>` where `T` is
53
+ * automatically inferred from the schema — no manual type argument needed.
54
+ *
55
+ * @typeParam TSchema - The Zod schema type (inferred from `schema` argument)
56
+ * @param schema - Zod schema to parse/validate against
57
+ * @param data - Unknown data to parse
58
+ * @returns `Ok<z.infer<TSchema>>` for valid data, `Err<ValidationError>` for invalid data
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const UserSchema = z.object({
63
+ * name: z.string().min(1),
64
+ * email: z.string().email(),
65
+ * });
66
+ *
67
+ * const result = parseInput(UserSchema, input);
68
+ * // Result<{ name: string; email: string }, ValidationError>
69
+ *
70
+ * if (result.isOk()) {
71
+ * result.value.name; // string — fully typed, no manual annotation
72
+ * }
73
+ * ```
74
+ */
75
+ declare function parseInput<TSchema extends z.ZodType>(schema: TSchema, data: unknown): Result<z.infer<TSchema>, ValidationError>;
76
+ export { formatZodIssues, createValidator, validateInput, parseInput };
@@ -1,4 +1,5 @@
1
- import { OutfitterError } from "./contracts-3gswmhb1.js";
1
+ import { ProgressCallback } from "./contracts-msxdg52h.js";
2
+ import { OutfitterError } from "./contracts-7a0xmwbg.js";
2
3
  import { Logger } from "./contracts-rwzqy9rn.js";
3
4
  import { Result } from "better-result";
4
5
  /**
@@ -29,6 +30,20 @@ interface HandlerContext {
29
30
  env: Record<string, string | undefined>;
30
31
  /** Structured logger with automatic redaction */
31
32
  logger: Logger;
33
+ /**
34
+ * Optional streaming progress callback.
35
+ *
36
+ * When provided by a transport adapter, the handler can emit progress
37
+ * events without knowing which transport consumes them. When `undefined`,
38
+ * the handler does not stream — it simply returns its final result.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * ctx.progress?.({ type: "start", command: "check", ts: new Date().toISOString() });
43
+ * ctx.progress?.({ type: "progress", current: 5, total: 10 });
44
+ * ```
45
+ */
46
+ progress?: ProgressCallback;
32
47
  /** Unique request identifier for tracing (UUIDv7) */
33
48
  requestId: string;
34
49
  /** Abort signal for cancellation propagation */
@@ -0,0 +1,84 @@
1
+ import { OutfitterError } from "./contracts-7a0xmwbg.js";
2
+ /**
3
+ * An error mapper converts an unknown error into a typed OutfitterError.
4
+ *
5
+ * Return `undefined` if the mapper does not handle this error (pass to next mapper or default).
6
+ */
7
+ type ErrorMapper = (error: unknown) => OutfitterError | undefined;
8
+ /**
9
+ * Type guard: checks whether `value` is a typed Outfitter error (has a `category` field
10
+ * matching a known {@link ErrorCategory}).
11
+ */
12
+ declare function isOutfitterError(value: unknown): value is OutfitterError;
13
+ /**
14
+ * Extract a human-readable message from an unknown error value.
15
+ *
16
+ * Handles Error instances, plain strings, objects with a `message` property,
17
+ * and falls back to `"Unknown error"` for everything else.
18
+ */
19
+ declare function extractMessage(error: unknown): string;
20
+ /**
21
+ * Normalize an unknown error into a typed OutfitterError.
22
+ *
23
+ * - Typed Outfitter errors pass through unchanged (same reference, mapper NOT called).
24
+ * - Untyped errors go through optional mapper.
25
+ * - Without mapper or when mapper returns `undefined`, wraps as {@link InternalError}.
26
+ * - Plain strings are wrapped as InternalError with the string as message.
27
+ *
28
+ * @param error - The unknown error to normalize
29
+ * @param mapper - Optional mapper to convert untyped errors into typed OutfitterErrors
30
+ * @returns A typed OutfitterError
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Typed errors pass through
35
+ * const typed = new ValidationError({ message: "bad input" });
36
+ * wrapError(typed) === typed; // true — same reference
37
+ *
38
+ * // Untyped errors go through mapper
39
+ * const mapper: ErrorMapper = (err) => {
40
+ * if (err instanceof Error && err.message.includes("ECONNREFUSED")) {
41
+ * return new NetworkError({ message: err.message });
42
+ * }
43
+ * return undefined;
44
+ * };
45
+ * wrapError(new Error("ECONNREFUSED"), mapper); // NetworkError
46
+ *
47
+ * // Unmatched errors become InternalError
48
+ * wrapError(new Error("unknown")); // InternalError
49
+ *
50
+ * // Strings become InternalError with message
51
+ * wrapError("something failed"); // InternalError { message: "something failed" }
52
+ * ```
53
+ */
54
+ declare function wrapError(error: unknown, mapper?: ErrorMapper): OutfitterError;
55
+ /**
56
+ * Compose multiple error mappers into a single mapper.
57
+ *
58
+ * Mappers run in declared order and short-circuit on the first match
59
+ * (first mapper to return a non-`undefined` value wins).
60
+ *
61
+ * @param mappers - Error mappers to compose
62
+ * @returns A single composed error mapper
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const networkMapper: ErrorMapper = (err) => {
67
+ * if (err instanceof Error && err.message.includes("ECONNREFUSED")) {
68
+ * return new NetworkError({ message: err.message });
69
+ * }
70
+ * return undefined;
71
+ * };
72
+ * const timeoutMapper: ErrorMapper = (err) => {
73
+ * if (err instanceof Error && err.message.includes("ETIMEDOUT")) {
74
+ * return TimeoutError.create("request", 5000);
75
+ * }
76
+ * return undefined;
77
+ * };
78
+ *
79
+ * const composed = composeMappers(networkMapper, timeoutMapper);
80
+ * wrapError(new Error("ECONNREFUSED"), composed); // NetworkError
81
+ * ```
82
+ */
83
+ declare function composeMappers(...mappers: ErrorMapper[]): ErrorMapper;
84
+ export { ErrorMapper, isOutfitterError, extractMessage, wrapError, composeMappers };
@@ -0,0 +1,2 @@
1
+ import { ProgressCallback, StreamEvent, StreamProgressEvent, StreamStartEvent, StreamStepEvent } from "./shared/@outfitter/contracts-msxdg52h.js";
2
+ export { StreamStepEvent, StreamStartEvent, StreamProgressEvent, StreamEvent, ProgressCallback };
package/dist/stream.js ADDED
@@ -0,0 +1 @@
1
+ // @bun
@@ -1,3 +1,7 @@
1
- import { createValidator, validateInput } from "./shared/@outfitter/contracts-9wtm5nsw.js";
2
- import "./shared/@outfitter/contracts-3gswmhb1.js";
3
- export { validateInput, createValidator };
1
+ import { createValidator, formatZodIssues, parseInput, validateInput } from "./shared/@outfitter/contracts-x0ppyt7e.js";
2
+ import "./shared/@outfitter/contracts-7a0xmwbg.js";
3
+ import "./shared/@outfitter/contracts-735ecmbq.js";
4
+ import "./shared/@outfitter/contracts-mehpmvwp.js";
5
+ import "./shared/@outfitter/contracts-qpbv29bg.js";
6
+ import "./shared/@outfitter/contracts-njb2art4.js";
7
+ export { validateInput, parseInput, formatZodIssues, createValidator };
@@ -1,10 +1,14 @@
1
1
  // @bun
2
2
  import {
3
3
  createValidator,
4
+ formatZodIssues,
5
+ parseInput,
4
6
  validateInput
5
- } from "./shared/@outfitter/contracts-0snpmkdt.js";
6
- import"./shared/@outfitter/contracts-phjhz5q3.js";
7
+ } from "./shared/@outfitter/contracts-hgh47193.js";
8
+ import"./shared/@outfitter/contracts-vhr2ep6b.js";
7
9
  export {
8
10
  validateInput,
11
+ parseInput,
12
+ formatZodIssues,
9
13
  createValidator
10
14
  };
@@ -0,0 +1,7 @@
1
+ import { ErrorMapper, composeMappers, extractMessage, isOutfitterError, wrapError } from "./shared/@outfitter/contracts-zsgxsa91.js";
2
+ import "./shared/@outfitter/contracts-7a0xmwbg.js";
3
+ import "./shared/@outfitter/contracts-735ecmbq.js";
4
+ import "./shared/@outfitter/contracts-mehpmvwp.js";
5
+ import "./shared/@outfitter/contracts-qpbv29bg.js";
6
+ import "./shared/@outfitter/contracts-njb2art4.js";
7
+ export { wrapError, isOutfitterError, extractMessage, composeMappers, ErrorMapper };
@@ -0,0 +1,71 @@
1
+ // @bun
2
+ import {
3
+ InternalError
4
+ } from "./shared/@outfitter/contracts-vhr2ep6b.js";
5
+
6
+ // packages/contracts/src/wrap-error.ts
7
+ function isOutfitterError(value) {
8
+ if (!(value instanceof Error)) {
9
+ return false;
10
+ }
11
+ const candidate = value;
12
+ return typeof candidate["category"] === "string" && typeof candidate["message"] === "string" && typeof candidate["_tag"] === "string" && isErrorCategory(candidate["category"]);
13
+ }
14
+ var ERROR_CATEGORIES = new Set([
15
+ "validation",
16
+ "not_found",
17
+ "conflict",
18
+ "permission",
19
+ "timeout",
20
+ "rate_limit",
21
+ "network",
22
+ "internal",
23
+ "auth",
24
+ "cancelled"
25
+ ]);
26
+ function isErrorCategory(value) {
27
+ return ERROR_CATEGORIES.has(value);
28
+ }
29
+ function extractMessage(error) {
30
+ if (typeof error === "string") {
31
+ return error || "Unknown error";
32
+ }
33
+ if (error instanceof Error) {
34
+ return error.message || "Unknown error";
35
+ }
36
+ if (error != null && typeof error === "object" && "message" in error) {
37
+ const msg = error["message"];
38
+ return typeof msg === "string" && msg ? msg : "Unknown error";
39
+ }
40
+ return "Unknown error";
41
+ }
42
+ function wrapError(error, mapper) {
43
+ if (isOutfitterError(error)) {
44
+ return error;
45
+ }
46
+ if (mapper != null) {
47
+ const mapped = mapper(error);
48
+ if (mapped != null) {
49
+ return mapped;
50
+ }
51
+ }
52
+ const message = extractMessage(error);
53
+ return new InternalError({ message });
54
+ }
55
+ function composeMappers(...mappers) {
56
+ return (error) => {
57
+ for (const mapper of mappers) {
58
+ const result = mapper(error);
59
+ if (result != null) {
60
+ return result;
61
+ }
62
+ }
63
+ return;
64
+ };
65
+ }
66
+ export {
67
+ wrapError,
68
+ isOutfitterError,
69
+ extractMessage,
70
+ composeMappers
71
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@outfitter/contracts",
3
3
  "description": "Result/Error patterns, error taxonomy, and handler contracts for Outfitter",
4
- "version": "0.4.1",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -57,12 +57,24 @@
57
57
  "default": "./dist/errors.js"
58
58
  }
59
59
  },
60
+ "./from-fetch": {
61
+ "import": {
62
+ "types": "./dist/from-fetch.d.ts",
63
+ "default": "./dist/from-fetch.js"
64
+ }
65
+ },
60
66
  "./handler": {
61
67
  "import": {
62
68
  "types": "./dist/handler.d.ts",
63
69
  "default": "./dist/handler.js"
64
70
  }
65
71
  },
72
+ "./hints": {
73
+ "import": {
74
+ "types": "./dist/hints.d.ts",
75
+ "default": "./dist/hints.js"
76
+ }
77
+ },
66
78
  "./logging": {
67
79
  "import": {
68
80
  "types": "./dist/logging.d.ts",
@@ -112,35 +124,29 @@
112
124
  "default": "./dist/serialization.js"
113
125
  }
114
126
  },
127
+ "./stream": {
128
+ "import": {
129
+ "types": "./dist/stream.d.ts",
130
+ "default": "./dist/stream.js"
131
+ }
132
+ },
115
133
  "./validation": {
116
134
  "import": {
117
135
  "types": "./dist/validation.d.ts",
118
136
  "default": "./dist/validation.js"
119
137
  }
138
+ },
139
+ "./wrap-error": {
140
+ "import": {
141
+ "types": "./dist/wrap-error.d.ts",
142
+ "default": "./dist/wrap-error.js"
143
+ }
120
144
  }
121
145
  },
122
- "sideEffects": false,
123
- "scripts": {
124
- "build": "cd ../.. && bunup --filter @outfitter/contracts",
125
- "lint": "biome lint ./src",
126
- "lint:fix": "biome lint --write ./src",
127
- "test": "bun test",
128
- "typecheck": "tsc --noEmit",
129
- "clean": "rm -rf dist",
130
- "prepublishOnly": "bun ../../scripts/check-publish-manifest.ts"
131
- },
132
- "dependencies": {
133
- "better-result": "^2.5.0",
134
- "zod": "^4.3.5"
135
- },
136
- "devDependencies": {
137
- "@types/bun": "latest",
138
- "typescript": "^5.8.0"
139
- },
140
146
  "keywords": [
141
- "outfitter",
142
147
  "contracts",
143
148
  "errors",
149
+ "outfitter",
144
150
  "result",
145
151
  "typescript"
146
152
  ],
@@ -150,7 +156,25 @@
150
156
  "url": "https://github.com/outfitter-dev/outfitter.git",
151
157
  "directory": "packages/contracts"
152
158
  },
159
+ "sideEffects": false,
153
160
  "publishConfig": {
154
161
  "access": "public"
162
+ },
163
+ "scripts": {
164
+ "build": "cd ../.. && bash ./scripts/run-bunup-with-lock.sh bunup --filter @outfitter/contracts",
165
+ "lint": "oxlint ./src",
166
+ "lint:fix": "oxlint --fix ./src",
167
+ "test": "bun test",
168
+ "typecheck": "tsc --noEmit",
169
+ "clean": "rm -rf dist",
170
+ "prepublishOnly": "bun ../../scripts/check-publish-manifest.ts"
171
+ },
172
+ "dependencies": {
173
+ "better-result": "^2.5.1",
174
+ "zod": "^4.3.5"
175
+ },
176
+ "devDependencies": {
177
+ "@types/bun": "^1.3.9",
178
+ "typescript": "^5.9.3"
155
179
  }
156
180
  }
@@ -1,81 +0,0 @@
1
- import { OutfitterError, SerializedError, ValidationError } from "./contracts-3gswmhb1.js";
2
- import { Result } from "better-result";
3
- import { z } from "zod";
4
- /**
5
- * Options for error serialization.
6
- */
7
- interface SerializeErrorOptions {
8
- /** Include stack trace (default: false in production, true in development) */
9
- includeStack?: boolean;
10
- }
11
- /**
12
- * Serialize a OutfitterError to JSON-safe format.
13
- *
14
- * Strips stack traces in production, preserves in development.
15
- * Automatically redacts sensitive values from context.
16
- *
17
- * @param error - The error to serialize
18
- * @param options - Serialization options
19
- * @returns JSON-safe serialized error
20
- *
21
- * @example
22
- * ```typescript
23
- * const serialized = serializeError(new NotFoundError("note", "abc123"));
24
- * // { _tag: "NotFoundError", category: "not_found", message: "note not found: abc123", context: { resourceType: "note", resourceId: "abc123" } }
25
- * ```
26
- */
27
- declare function serializeError(error: OutfitterError, options?: SerializeErrorOptions): SerializedError;
28
- /**
29
- * Deserialize error from JSON (e.g., from MCP response).
30
- *
31
- * Returns a typed OutfitterError subclass based on _tag.
32
- *
33
- * @param data - Serialized error data
34
- * @returns Reconstructed OutfitterError instance
35
- *
36
- * @example
37
- * ```typescript
38
- * const error = deserializeError(jsonData);
39
- * if (error._tag === "NotFoundError") {
40
- * // TypeScript knows error.resourceType exists
41
- * }
42
- * ```
43
- */
44
- declare function deserializeError(data: SerializedError): OutfitterError;
45
- /**
46
- * Safely stringify any value to JSON.
47
- *
48
- * Handles circular references, BigInt, and other non-JSON-safe values.
49
- * Applies redaction to sensitive values.
50
- *
51
- * @param value - Value to stringify
52
- * @param space - Indentation (default: undefined for compact)
53
- * @returns JSON string
54
- *
55
- * @example
56
- * ```typescript
57
- * const json = safeStringify({ apiKey: "sk-secret", data: "safe" });
58
- * // '{"apiKey":"[REDACTED]","data":"safe"}'
59
- * ```
60
- */
61
- declare function safeStringify(value: unknown, space?: number): string;
62
- /**
63
- * Safely parse JSON string with optional schema validation.
64
- *
65
- * Returns Result instead of throwing on invalid JSON.
66
- *
67
- * @typeParam T - Expected parsed type (or unknown if no schema)
68
- * @param json - JSON string to parse
69
- * @param schema - Optional Zod schema for validation
70
- * @returns Result with parsed value or ValidationError
71
- *
72
- * @example
73
- * ```typescript
74
- * const result = safeParse<Config>('{"port": 3000}', ConfigSchema);
75
- * if (result.isOk()) {
76
- * const config = result.unwrap();
77
- * }
78
- * ```
79
- */
80
- declare function safeParse<T = unknown>(json: string, schema?: z.ZodType<T>): Result<T, ValidationError>;
81
- export { SerializeErrorOptions, serializeError, deserializeError, safeStringify, safeParse };