@pafi-dev/issuer 0.35.0 → 0.36.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,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 };
package/dist/index.cjs CHANGED
@@ -4437,6 +4437,7 @@ function createNativePtQuoter(config) {
4437
4437
  cacheTtlMs = 3e4,
4438
4438
  fallbackEthPriceUsd = 3e3,
4439
4439
  fallbackPtPriceUsdt = 0.1,
4440
+ failClosed = false,
4440
4441
  fetchImpl = globalThis.fetch,
4441
4442
  now = () => Date.now()
4442
4443
  } = config;
@@ -4461,6 +4462,11 @@ function createNativePtQuoter(config) {
4461
4462
  ethPriceCache = { value: answer, expiresAt: ts + cacheTtlMs };
4462
4463
  return answer;
4463
4464
  } catch (err) {
4465
+ if (failClosed) {
4466
+ throw new Error(
4467
+ `[nativePtQuoter] Chainlink unavailable in fail-closed mode: ${err.message}`
4468
+ );
4469
+ }
4464
4470
  console.warn("[nativePtQuoter] Chainlink unavailable, using fallback:", err.message);
4465
4471
  return BigInt(Math.round(fallbackEthPriceUsd * 1e8));
4466
4472
  }
@@ -4493,6 +4499,11 @@ function createNativePtQuoter(config) {
4493
4499
  ptPriceCache = { value, expiresAt: ts + cacheTtlMs };
4494
4500
  return value;
4495
4501
  } catch (err) {
4502
+ if (failClosed) {
4503
+ throw new Error(
4504
+ `[nativePtQuoter] subgraph miss for ${pointTokenAddress} in fail-closed mode: ${err.message}`
4505
+ );
4506
+ }
4496
4507
  console.warn("[nativePtQuoter] subgraph unavailable, using fallback:", err.message);
4497
4508
  const ptPerUsdtHuman = 1 / fallbackPtPriceUsdt;
4498
4509
  return parseBigDecimalTo18(ptPerUsdtHuman.toFixed(18));
@@ -5410,7 +5421,7 @@ var MemoryRedemptionHistoryStore = class {
5410
5421
  };
5411
5422
 
5412
5423
  // src/index.ts
5413
- var PAFI_ISSUER_SDK_VERSION = true ? "0.35.0" : "dev";
5424
+ var PAFI_ISSUER_SDK_VERSION = true ? "0.35.1" : "dev";
5414
5425
  // Annotate the CommonJS export names for ESM import in node:
5415
5426
  0 && (module.exports = {
5416
5427
  AdapterMisconfiguredError,