@pafi-dev/issuer 0.3.0-beta.7 → 0.3.0-beta.9

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.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Address, Hex, PublicClient, Chain, WalletClient } from 'viem';
2
- import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
2
+ import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey } from '@pafi-dev/core';
3
3
 
4
4
  /**
5
5
  * Lifecycle of a minting request as tracked by the issuer's point ledger.
@@ -1438,159 +1438,33 @@ declare class BalanceAggregator {
1438
1438
  }
1439
1439
 
1440
1440
  interface RetryConfig {
1441
- /**
1442
- * Max total attempts including the first try. Default: 1 (no retry).
1443
- * Set to 3 to get 2 retries after the initial call.
1444
- *
1445
- * Only applies when the server error body carries `safeToRetry: true`
1446
- * or the failure is a transient network/timeout error.
1447
- */
1448
1441
  maxAttempts?: number;
1449
- /**
1450
- * Initial backoff delay in ms. Default: 500. Each subsequent retry
1451
- * doubles this (exponential backoff) and adds ±20% jitter.
1452
- */
1453
1442
  initialDelayMs?: number;
1454
- /**
1455
- * Hard ceiling for a single backoff (ms). Default: 10_000.
1456
- */
1457
1443
  maxDelayMs?: number;
1458
- /**
1459
- * Upper bound on `retryAfter` from the server. If the server asks us
1460
- * to wait longer than this (e.g. rate limit until UTC midnight), the
1461
- * client gives up rather than blocking. Default: 30_000.
1462
- */
1463
1444
  maxRetryAfterMs?: number;
1464
1445
  }
1465
1446
  interface PafiBackendConfig {
1466
- /**
1467
- * PAFI Backend API base URL. Example:
1468
- * https://api.pacificfinance.org
1469
- * https://staging-api.pacificfinance.org
1470
- */
1471
1447
  url: string;
1472
- /** PAFI-assigned issuer ID (e.g., "gg56"). Sent in X-Issuer-Id header. */
1473
1448
  issuerId: string;
1474
- /** Per-issuer API key (or JWT) for the Authorization header. */
1475
1449
  apiKey: string;
1476
- /** Optional fetch override for tests. */
1477
1450
  fetchImpl?: typeof fetch;
1478
- /**
1479
- * Timeout (ms) for each request. Default: 10_000. PAFI Backend should
1480
- * respond in <1s for the happy path; this is just the sanity bound.
1481
- */
1482
1451
  timeoutMs?: number;
1483
- /**
1484
- * Retry policy for transient failures (5xx, 429, timeouts, network).
1485
- * Omit or pass `{ maxAttempts: 1 }` to disable retry entirely.
1486
- */
1487
1452
  retry?: RetryConfig;
1488
1453
  }
1489
- /** Paired with `POST /paymaster/sponsor`. See SPONSORED_PATH_FLOW.md §4.1 */
1490
- interface SponsorshipRequest {
1491
- chainId: number;
1492
- scenario: SponsorshipScenario;
1493
- userOp: PartialUserOperation;
1494
- target: {
1495
- /** The allowlisted contract this batch call targets. */
1496
- contract: Address;
1497
- /** Function selector / name — validated against allowlist. */
1498
- function: string;
1499
- /** The PointToken involved (for scenario context). */
1500
- pointToken?: Address;
1501
- };
1502
- }
1503
- interface SponsorshipResponse {
1504
- paymaster: Address;
1505
- paymasterData: Hex;
1506
- paymasterVerificationGasLimit: bigint;
1507
- paymasterPostOpGasLimit: bigint;
1508
- /** Unix seconds when this sponsorship expires. Re-request after. */
1509
- expiresAt: number;
1510
- }
1511
- /**
1512
- * Machine-readable error codes returned by PAFI Backend.
1513
- *
1514
- * Source of truth: `apps/paymaster-proxy` `CalldataValidationError`,
1515
- * `RateLimitError`, `CoinbaseClientError`. Keep in sync.
1516
- */
1517
- type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "CALLDATA_INVALID" | "CALLDATA_EMPTY_BATCH" | "TARGET_NOT_ALLOWLISTED" | "FUNCTION_NOT_ALLOWED" | "SCENARIO_MISMATCH" | "SCENARIO_DISABLED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "RATE_LIMITER_UNAVAILABLE" | "PAYMASTER_REJECTED" | "PAYMASTER_UNAVAILABLE" | "PAYMASTER_TIMEOUT" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
1454
+ type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
1518
1455
  declare class PafiBackendError extends Error {
1519
1456
  code: PafiBackendErrorCode;
1520
1457
  httpStatus: number;
1521
1458
  details?: unknown | undefined;
1522
- /**
1523
- * Seconds to wait before retry. Populated from the server body
1524
- * (e.g. rate limit returns the number of seconds until UTC midnight).
1525
- */
1526
1459
  readonly retryAfter?: number;
1527
- /**
1528
- * `safeToRetry` as reported by the server body. Prefer this over the
1529
- * code-based heuristic when available — the server knows more about
1530
- * whether the same request will succeed on retry.
1531
- */
1532
1460
  private readonly serverSafeToRetry?;
1533
1461
  constructor(code: PafiBackendErrorCode, message: string, httpStatus: number, details?: unknown | undefined, opts?: {
1534
1462
  retryAfter?: number;
1535
1463
  safeToRetry?: boolean;
1536
1464
  });
1537
- /**
1538
- * Whether the caller can safely retry the same request.
1539
- *
1540
- * If the server provided `safeToRetry` in the body, trust that.
1541
- * Otherwise fall back to a code-based heuristic.
1542
- */
1543
1465
  get safeToRetry(): boolean;
1544
1466
  }
1545
1467
 
1546
- /**
1547
- * HTTP client for the PAFI Backend paymaster proxy service. See
1548
- * [SPONSORED_PATH_FLOW.md] for the full flow + API contract.
1549
- *
1550
- * This client sits between `@pafi/issuer`'s RelayService and the
1551
- * PAFI Backend. It does NOT talk to Coinbase Paymaster directly —
1552
- * PAFI Backend holds that integration.
1553
- */
1554
- declare class PafiBackendClient {
1555
- private readonly url;
1556
- private readonly issuerId;
1557
- private readonly apiKey;
1558
- private readonly fetchImpl;
1559
- private readonly timeoutMs;
1560
- private readonly retry;
1561
- constructor(config: PafiBackendConfig);
1562
- /**
1563
- * Request paymaster sponsorship for a pre-built UserOperation.
1564
- * See [SPONSORED_PATH_FLOW.md §4.1] for the API contract.
1565
- *
1566
- * Retries automatically on transient failures (5xx, timeouts, network
1567
- * errors, and errors the server flags with `safeToRetry: true`) up to
1568
- * `retry.maxAttempts`. 4xx errors that are not `safeToRetry` fail fast.
1569
- *
1570
- * @throws PafiBackendError on final failure after exhausting retries
1571
- */
1572
- requestSponsorship(req: SponsorshipRequest): Promise<SponsorshipResponse>;
1573
- private postWithRetry;
1574
- /**
1575
- * Pick the delay before the next retry.
1576
- * - If the server sent `retryAfter` (seconds), honor it (capped by
1577
- * `maxRetryAfterMs`) — returns null if the server wait exceeds the
1578
- * cap, signalling the caller should give up.
1579
- * - Otherwise: exponential backoff with ±20% jitter, capped at
1580
- * `maxDelayMs`.
1581
- */
1582
- private computeBackoff;
1583
- private sleep;
1584
- private post;
1585
- /** JSON replacer that stringifies bigints. Paired with bigintReviver. */
1586
- private bigintReplacer;
1587
- /**
1588
- * JSON reviver that coerces specific numeric-string fields back to
1589
- * bigint. The server must send these fields as decimal strings.
1590
- */
1591
- private bigintReviver;
1592
- }
1593
-
1594
1468
  /**
1595
1469
  * Top-level configuration for `createIssuerService`.
1596
1470
  *
@@ -1687,4 +1561,4 @@ declare function createIssuerService(config: IssuerServiceConfig): IssuerService
1687
1561
  /** SDK package version — bumped on every release */
1688
1562
  declare const PAFI_ISSUER_SDK_VERSION = "0.1.0";
1689
1563
 
1690
- export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, PafiBackendClient, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type Session, type SponsorshipRequest, type SponsorshipResponse, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
1564
+ export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type RetryConfig, type Session, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Address, Hex, PublicClient, Chain, WalletClient } from 'viem';
2
- import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey, SponsorshipScenario } from '@pafi-dev/core';
2
+ import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey } from '@pafi-dev/core';
3
3
 
4
4
  /**
5
5
  * Lifecycle of a minting request as tracked by the issuer's point ledger.
@@ -1438,159 +1438,33 @@ declare class BalanceAggregator {
1438
1438
  }
1439
1439
 
1440
1440
  interface RetryConfig {
1441
- /**
1442
- * Max total attempts including the first try. Default: 1 (no retry).
1443
- * Set to 3 to get 2 retries after the initial call.
1444
- *
1445
- * Only applies when the server error body carries `safeToRetry: true`
1446
- * or the failure is a transient network/timeout error.
1447
- */
1448
1441
  maxAttempts?: number;
1449
- /**
1450
- * Initial backoff delay in ms. Default: 500. Each subsequent retry
1451
- * doubles this (exponential backoff) and adds ±20% jitter.
1452
- */
1453
1442
  initialDelayMs?: number;
1454
- /**
1455
- * Hard ceiling for a single backoff (ms). Default: 10_000.
1456
- */
1457
1443
  maxDelayMs?: number;
1458
- /**
1459
- * Upper bound on `retryAfter` from the server. If the server asks us
1460
- * to wait longer than this (e.g. rate limit until UTC midnight), the
1461
- * client gives up rather than blocking. Default: 30_000.
1462
- */
1463
1444
  maxRetryAfterMs?: number;
1464
1445
  }
1465
1446
  interface PafiBackendConfig {
1466
- /**
1467
- * PAFI Backend API base URL. Example:
1468
- * https://api.pacificfinance.org
1469
- * https://staging-api.pacificfinance.org
1470
- */
1471
1447
  url: string;
1472
- /** PAFI-assigned issuer ID (e.g., "gg56"). Sent in X-Issuer-Id header. */
1473
1448
  issuerId: string;
1474
- /** Per-issuer API key (or JWT) for the Authorization header. */
1475
1449
  apiKey: string;
1476
- /** Optional fetch override for tests. */
1477
1450
  fetchImpl?: typeof fetch;
1478
- /**
1479
- * Timeout (ms) for each request. Default: 10_000. PAFI Backend should
1480
- * respond in <1s for the happy path; this is just the sanity bound.
1481
- */
1482
1451
  timeoutMs?: number;
1483
- /**
1484
- * Retry policy for transient failures (5xx, 429, timeouts, network).
1485
- * Omit or pass `{ maxAttempts: 1 }` to disable retry entirely.
1486
- */
1487
1452
  retry?: RetryConfig;
1488
1453
  }
1489
- /** Paired with `POST /paymaster/sponsor`. See SPONSORED_PATH_FLOW.md §4.1 */
1490
- interface SponsorshipRequest {
1491
- chainId: number;
1492
- scenario: SponsorshipScenario;
1493
- userOp: PartialUserOperation;
1494
- target: {
1495
- /** The allowlisted contract this batch call targets. */
1496
- contract: Address;
1497
- /** Function selector / name — validated against allowlist. */
1498
- function: string;
1499
- /** The PointToken involved (for scenario context). */
1500
- pointToken?: Address;
1501
- };
1502
- }
1503
- interface SponsorshipResponse {
1504
- paymaster: Address;
1505
- paymasterData: Hex;
1506
- paymasterVerificationGasLimit: bigint;
1507
- paymasterPostOpGasLimit: bigint;
1508
- /** Unix seconds when this sponsorship expires. Re-request after. */
1509
- expiresAt: number;
1510
- }
1511
- /**
1512
- * Machine-readable error codes returned by PAFI Backend.
1513
- *
1514
- * Source of truth: `apps/paymaster-proxy` `CalldataValidationError`,
1515
- * `RateLimitError`, `CoinbaseClientError`. Keep in sync.
1516
- */
1517
- type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "CALLDATA_INVALID" | "CALLDATA_EMPTY_BATCH" | "TARGET_NOT_ALLOWLISTED" | "FUNCTION_NOT_ALLOWED" | "SCENARIO_MISMATCH" | "SCENARIO_DISABLED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "RATE_LIMITER_UNAVAILABLE" | "PAYMASTER_REJECTED" | "PAYMASTER_UNAVAILABLE" | "PAYMASTER_TIMEOUT" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
1454
+ type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
1518
1455
  declare class PafiBackendError extends Error {
1519
1456
  code: PafiBackendErrorCode;
1520
1457
  httpStatus: number;
1521
1458
  details?: unknown | undefined;
1522
- /**
1523
- * Seconds to wait before retry. Populated from the server body
1524
- * (e.g. rate limit returns the number of seconds until UTC midnight).
1525
- */
1526
1459
  readonly retryAfter?: number;
1527
- /**
1528
- * `safeToRetry` as reported by the server body. Prefer this over the
1529
- * code-based heuristic when available — the server knows more about
1530
- * whether the same request will succeed on retry.
1531
- */
1532
1460
  private readonly serverSafeToRetry?;
1533
1461
  constructor(code: PafiBackendErrorCode, message: string, httpStatus: number, details?: unknown | undefined, opts?: {
1534
1462
  retryAfter?: number;
1535
1463
  safeToRetry?: boolean;
1536
1464
  });
1537
- /**
1538
- * Whether the caller can safely retry the same request.
1539
- *
1540
- * If the server provided `safeToRetry` in the body, trust that.
1541
- * Otherwise fall back to a code-based heuristic.
1542
- */
1543
1465
  get safeToRetry(): boolean;
1544
1466
  }
1545
1467
 
1546
- /**
1547
- * HTTP client for the PAFI Backend paymaster proxy service. See
1548
- * [SPONSORED_PATH_FLOW.md] for the full flow + API contract.
1549
- *
1550
- * This client sits between `@pafi/issuer`'s RelayService and the
1551
- * PAFI Backend. It does NOT talk to Coinbase Paymaster directly —
1552
- * PAFI Backend holds that integration.
1553
- */
1554
- declare class PafiBackendClient {
1555
- private readonly url;
1556
- private readonly issuerId;
1557
- private readonly apiKey;
1558
- private readonly fetchImpl;
1559
- private readonly timeoutMs;
1560
- private readonly retry;
1561
- constructor(config: PafiBackendConfig);
1562
- /**
1563
- * Request paymaster sponsorship for a pre-built UserOperation.
1564
- * See [SPONSORED_PATH_FLOW.md §4.1] for the API contract.
1565
- *
1566
- * Retries automatically on transient failures (5xx, timeouts, network
1567
- * errors, and errors the server flags with `safeToRetry: true`) up to
1568
- * `retry.maxAttempts`. 4xx errors that are not `safeToRetry` fail fast.
1569
- *
1570
- * @throws PafiBackendError on final failure after exhausting retries
1571
- */
1572
- requestSponsorship(req: SponsorshipRequest): Promise<SponsorshipResponse>;
1573
- private postWithRetry;
1574
- /**
1575
- * Pick the delay before the next retry.
1576
- * - If the server sent `retryAfter` (seconds), honor it (capped by
1577
- * `maxRetryAfterMs`) — returns null if the server wait exceeds the
1578
- * cap, signalling the caller should give up.
1579
- * - Otherwise: exponential backoff with ±20% jitter, capped at
1580
- * `maxDelayMs`.
1581
- */
1582
- private computeBackoff;
1583
- private sleep;
1584
- private post;
1585
- /** JSON replacer that stringifies bigints. Paired with bigintReviver. */
1586
- private bigintReplacer;
1587
- /**
1588
- * JSON reviver that coerces specific numeric-string fields back to
1589
- * bigint. The server must send these fields as decimal strings.
1590
- */
1591
- private bigintReviver;
1592
- }
1593
-
1594
1468
  /**
1595
1469
  * Top-level configuration for `createIssuerService`.
1596
1470
  *
@@ -1687,4 +1561,4 @@ declare function createIssuerService(config: IssuerServiceConfig): IssuerService
1687
1561
  /** SDK package version — bumped on every release */
1688
1562
  declare const PAFI_ISSUER_SDK_VERSION = "0.1.0";
1689
1563
 
1690
- export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, PafiBackendClient, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type Session, type SponsorshipRequest, type SponsorshipResponse, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
1564
+ export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type RetryConfig, type Session, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
package/dist/index.js CHANGED
@@ -1807,28 +1807,11 @@ var PafiBackendError = class extends Error {
1807
1807
  code;
1808
1808
  httpStatus;
1809
1809
  details;
1810
- /**
1811
- * Seconds to wait before retry. Populated from the server body
1812
- * (e.g. rate limit returns the number of seconds until UTC midnight).
1813
- */
1814
1810
  retryAfter;
1815
- /**
1816
- * `safeToRetry` as reported by the server body. Prefer this over the
1817
- * code-based heuristic when available — the server knows more about
1818
- * whether the same request will succeed on retry.
1819
- */
1820
1811
  serverSafeToRetry;
1821
- /**
1822
- * Whether the caller can safely retry the same request.
1823
- *
1824
- * If the server provided `safeToRetry` in the body, trust that.
1825
- * Otherwise fall back to a code-based heuristic.
1826
- */
1827
1812
  get safeToRetry() {
1828
1813
  if (this.serverSafeToRetry !== void 0) return this.serverSafeToRetry;
1829
1814
  switch (this.code) {
1830
- case "PAYMASTER_UNAVAILABLE":
1831
- case "PAYMASTER_TIMEOUT":
1832
1815
  case "RATE_LIMITER_UNAVAILABLE":
1833
1816
  case "INTERNAL_ERROR":
1834
1817
  case "TIMEOUT":
@@ -1837,182 +1820,14 @@ var PafiBackendError = class extends Error {
1837
1820
  case "RATE_LIMIT_EXCEEDED":
1838
1821
  case "RATE_LIMIT_EXCEEDED_DAILY":
1839
1822
  case "RATE_LIMIT_EXCEEDED_PER_USER":
1823
+ case "ISSUER_BUDGET_EXCEEDED":
1840
1824
  return true;
1841
- // after retryAfter
1842
1825
  default:
1843
1826
  return false;
1844
1827
  }
1845
1828
  }
1846
1829
  };
1847
1830
 
1848
- // src/pafi-backend/pafiBackendClient.ts
1849
- var DEFAULT_TIMEOUT_MS = 1e4;
1850
- var RETRY_DEFAULTS = {
1851
- maxAttempts: 1,
1852
- initialDelayMs: 500,
1853
- maxDelayMs: 1e4,
1854
- maxRetryAfterMs: 3e4
1855
- };
1856
- var PafiBackendClient = class {
1857
- url;
1858
- issuerId;
1859
- apiKey;
1860
- fetchImpl;
1861
- timeoutMs;
1862
- retry;
1863
- constructor(config) {
1864
- if (!config.url) {
1865
- throw new Error("PafiBackendClient: url is required");
1866
- }
1867
- if (!config.issuerId) {
1868
- throw new Error("PafiBackendClient: issuerId is required");
1869
- }
1870
- if (!config.apiKey) {
1871
- throw new Error("PafiBackendClient: apiKey is required");
1872
- }
1873
- this.url = config.url.replace(/\/+$/, "");
1874
- this.issuerId = config.issuerId;
1875
- this.apiKey = config.apiKey;
1876
- this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
1877
- this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
1878
- this.retry = { ...RETRY_DEFAULTS, ...config.retry ?? {} };
1879
- if (!this.fetchImpl) {
1880
- throw new Error(
1881
- "PafiBackendClient: no fetch implementation available \u2014 pass `fetchImpl` or run on Node 18+"
1882
- );
1883
- }
1884
- if (this.retry.maxAttempts < 1) {
1885
- throw new Error("PafiBackendClient: retry.maxAttempts must be >= 1");
1886
- }
1887
- }
1888
- /**
1889
- * Request paymaster sponsorship for a pre-built UserOperation.
1890
- * See [SPONSORED_PATH_FLOW.md §4.1] for the API contract.
1891
- *
1892
- * Retries automatically on transient failures (5xx, timeouts, network
1893
- * errors, and errors the server flags with `safeToRetry: true`) up to
1894
- * `retry.maxAttempts`. 4xx errors that are not `safeToRetry` fail fast.
1895
- *
1896
- * @throws PafiBackendError on final failure after exhausting retries
1897
- */
1898
- async requestSponsorship(req) {
1899
- return this.postWithRetry(
1900
- "/paymaster/sponsor",
1901
- req
1902
- );
1903
- }
1904
- // -------------------------------------------------------------------------
1905
- // Internals
1906
- // -------------------------------------------------------------------------
1907
- async postWithRetry(path, body) {
1908
- let lastError;
1909
- for (let attempt = 1; attempt <= this.retry.maxAttempts; attempt++) {
1910
- try {
1911
- return await this.post(path, body);
1912
- } catch (err) {
1913
- if (!(err instanceof PafiBackendError)) throw err;
1914
- lastError = err;
1915
- const isLastAttempt = attempt >= this.retry.maxAttempts;
1916
- if (isLastAttempt || !err.safeToRetry) throw err;
1917
- const delay = this.computeBackoff(attempt, err.retryAfter);
1918
- if (delay === null) throw err;
1919
- await this.sleep(delay);
1920
- }
1921
- }
1922
- throw lastError;
1923
- }
1924
- /**
1925
- * Pick the delay before the next retry.
1926
- * - If the server sent `retryAfter` (seconds), honor it (capped by
1927
- * `maxRetryAfterMs`) — returns null if the server wait exceeds the
1928
- * cap, signalling the caller should give up.
1929
- * - Otherwise: exponential backoff with ±20% jitter, capped at
1930
- * `maxDelayMs`.
1931
- */
1932
- computeBackoff(attempt, retryAfter) {
1933
- if (retryAfter !== void 0) {
1934
- const serverMs = retryAfter * 1e3;
1935
- if (serverMs > this.retry.maxRetryAfterMs) return null;
1936
- return serverMs;
1937
- }
1938
- const exp = this.retry.initialDelayMs * 2 ** (attempt - 1);
1939
- const capped = Math.min(exp, this.retry.maxDelayMs);
1940
- const jitter = capped * (0.8 + Math.random() * 0.4);
1941
- return Math.round(jitter);
1942
- }
1943
- sleep(ms) {
1944
- return new Promise((resolve) => setTimeout(resolve, ms));
1945
- }
1946
- async post(path, body) {
1947
- const controller = new AbortController();
1948
- const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
1949
- let response;
1950
- try {
1951
- response = await this.fetchImpl(`${this.url}${path}`, {
1952
- method: "POST",
1953
- headers: {
1954
- "Content-Type": "application/json",
1955
- "Authorization": `Bearer ${this.apiKey}`,
1956
- "X-Issuer-Id": this.issuerId
1957
- },
1958
- body: JSON.stringify(body, this.bigintReplacer),
1959
- signal: controller.signal
1960
- });
1961
- } catch (err) {
1962
- if (err.name === "AbortError") {
1963
- throw new PafiBackendError(
1964
- "TIMEOUT",
1965
- `PAFI Backend request timed out after ${this.timeoutMs}ms`,
1966
- 0
1967
- );
1968
- }
1969
- throw new PafiBackendError(
1970
- "NETWORK_ERROR",
1971
- `PAFI Backend unreachable: ${err.message}`,
1972
- 0
1973
- );
1974
- } finally {
1975
- clearTimeout(timeoutId);
1976
- }
1977
- const text = await response.text();
1978
- if (!response.ok) {
1979
- let code = "INTERNAL_ERROR";
1980
- let message = text || response.statusText;
1981
- let details;
1982
- let retryAfter;
1983
- let serverSafeToRetry;
1984
- try {
1985
- const parsed = JSON.parse(text);
1986
- code = parsed.code ?? code;
1987
- message = parsed.message ?? message;
1988
- details = parsed.details;
1989
- if (typeof parsed.retryAfter === "number") retryAfter = parsed.retryAfter;
1990
- if (typeof parsed.safeToRetry === "boolean") serverSafeToRetry = parsed.safeToRetry;
1991
- } catch {
1992
- }
1993
- throw new PafiBackendError(code, message, response.status, details, {
1994
- ...retryAfter !== void 0 ? { retryAfter } : {},
1995
- ...serverSafeToRetry !== void 0 ? { safeToRetry: serverSafeToRetry } : {}
1996
- });
1997
- }
1998
- return JSON.parse(text, this.bigintReviver);
1999
- }
2000
- /** JSON replacer that stringifies bigints. Paired with bigintReviver. */
2001
- bigintReplacer = (_key, value) => {
2002
- return typeof value === "bigint" ? value.toString() : value;
2003
- };
2004
- /**
2005
- * JSON reviver that coerces specific numeric-string fields back to
2006
- * bigint. The server must send these fields as decimal strings.
2007
- */
2008
- bigintReviver = (key, value) => {
2009
- if (typeof value === "string" && (key.endsWith("GasLimit") || key === "nonce" || key === "callGasLimit" || key === "verificationGasLimit" || key === "preVerificationGas" || key === "maxFeePerGas" || key === "maxPriorityFeePerGas" || key === "paymasterVerificationGasLimit" || key === "paymasterPostOpGasLimit") && /^\d+$/.test(value)) {
2010
- return BigInt(value);
2011
- }
2012
- return value;
2013
- };
2014
- };
2015
-
2016
1831
  // src/config.ts
2017
1832
  import { getAddress as getAddress9 } from "viem";
2018
1833
  function createIssuerService(config) {
@@ -2124,7 +1939,6 @@ export {
2124
1939
  PAFI_ISSUER_SDK_VERSION,
2125
1940
  PTRedeemError,
2126
1941
  PTRedeemHandler,
2127
- PafiBackendClient,
2128
1942
  PafiBackendError,
2129
1943
  PointIndexer,
2130
1944
  PrivateKeySigner,