@pafi-dev/issuer 0.7.9 → 0.9.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.
@@ -0,0 +1,112 @@
1
+ import { PafiErrorType, PafiSdkError } from '@pafi-dev/core';
2
+
3
+ /**
4
+ * Stripe-style HTTP error envelope shared by every PAFI service and
5
+ * issuer backend. The framework-agnostic `normalizeErrorToEnvelope`
6
+ * helper produces this from any thrown value; framework-specific
7
+ * filters (`@pafi-dev/issuer/nestjs`) call into it and write the
8
+ * result to their response object.
9
+ *
10
+ * Wire format:
11
+ *
12
+ * ```json
13
+ * {
14
+ * "success": false,
15
+ * "statusCode": 422,
16
+ * "error": {
17
+ * "type": "business_logic_error",
18
+ * "code": "REDEMPTION_POLICY_DENIED",
19
+ * "message": "redemption denied: amount 1 below per-tx minimum",
20
+ * "param": null,
21
+ * "metadata": { "policyDenialCode": "PER_TX_MIN" },
22
+ * "safeToRetry": false,
23
+ * "details": null
24
+ * },
25
+ * "meta": {
26
+ * "timestamp": "2026-05-07T...",
27
+ * "requestId": "...",
28
+ * "path": "/pt/redeem"
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+
34
+ /** Inner `error` block of the envelope. */
35
+ interface PafiErrorPayload {
36
+ type: PafiErrorType;
37
+ code: string;
38
+ message: string;
39
+ param?: string;
40
+ metadata?: Record<string, unknown>;
41
+ details?: unknown;
42
+ safeToRetry: boolean;
43
+ }
44
+ /** Outer envelope returned for any non-2xx response. */
45
+ interface PafiErrorEnvelope {
46
+ success: false;
47
+ statusCode: number;
48
+ error: PafiErrorPayload;
49
+ meta: {
50
+ timestamp: string;
51
+ requestId: string;
52
+ path: string;
53
+ };
54
+ }
55
+ /** Per-call request context the filter must collect from the host framework. */
56
+ interface NormalizeContext {
57
+ /** `req.url` or equivalent. */
58
+ path: string;
59
+ /** Resolved request id (header or generated). */
60
+ requestId: string;
61
+ /** Optional `now()` injection for deterministic tests. */
62
+ now?: () => Date;
63
+ }
64
+ /**
65
+ * Generic error duck-type. The filter passes a small descriptor for
66
+ * any framework exception so the normalizer doesn't depend on
67
+ * `@nestjs/common` or any specific HTTP library.
68
+ */
69
+ interface GenericHttpExceptionDescriptor {
70
+ /** HTTP status code carried by the exception. */
71
+ statusCode: number;
72
+ /**
73
+ * The body the framework would have serialized. For NestJS this is
74
+ * `exception.getResponse()`. May be a string or a record with
75
+ * `code`/`error`/`message`/`details`/`safeToRetry`/`type`/etc.
76
+ */
77
+ responseBody: unknown;
78
+ /** Exception class name, used as a last-resort `code` fallback. */
79
+ exceptionName: string;
80
+ /** Original `error.message`, used as a last-resort `message` fallback. */
81
+ fallbackMessage: string;
82
+ }
83
+ /**
84
+ * Convert a `PafiSdkError` directly to the inner `error` payload —
85
+ * skipping any framework exception wrapper. Used by frameworks that
86
+ * surface SDK errors without going through `createSdkErrorMapper`.
87
+ */
88
+ declare function payloadFromPafiSdkError(err: PafiSdkError): PafiErrorPayload;
89
+ /**
90
+ * Build the full envelope for any thrown value. The caller resolves
91
+ * `HttpException`-shaped exceptions and passes a descriptor; plain
92
+ * `Error` instances and unknown throws are handled directly.
93
+ */
94
+ declare function buildErrorEnvelope(input: {
95
+ status: number;
96
+ payload: PafiErrorPayload;
97
+ ctx: NormalizeContext;
98
+ }): PafiErrorEnvelope;
99
+ /**
100
+ * Normalize a known `HttpException`-shaped exception into a payload.
101
+ * Framework filters supply the descriptor; the rest is shape-agnostic.
102
+ */
103
+ declare function payloadFromHttpException(desc: GenericHttpExceptionDescriptor): PafiErrorPayload;
104
+ /**
105
+ * Normalize a generic `Error` (not an HttpException) — TypeORM
106
+ * `QueryFailedError`, viem revert errors, etc. Returns a redacted
107
+ * 500-class payload with no message bleed-through unless the error
108
+ * is recognizably benign.
109
+ */
110
+ declare function payloadFromGenericError(err: Error): PafiErrorPayload;
111
+
112
+ export { type GenericHttpExceptionDescriptor, type NormalizeContext, type PafiErrorEnvelope, type PafiErrorPayload, buildErrorEnvelope, payloadFromGenericError, payloadFromHttpException, payloadFromPafiSdkError };
@@ -0,0 +1,14 @@
1
+ import "../chunk-R4FYJZ2N.js";
2
+ import {
3
+ buildErrorEnvelope,
4
+ payloadFromGenericError,
5
+ payloadFromHttpException,
6
+ payloadFromPafiSdkError
7
+ } from "../chunk-U3WMORJG.js";
8
+ export {
9
+ buildErrorEnvelope,
10
+ payloadFromGenericError,
11
+ payloadFromHttpException,
12
+ payloadFromPafiSdkError
13
+ };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}