@pafi-dev/issuer 0.31.0 → 0.32.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.
package/dist/index.cjs CHANGED
@@ -2414,11 +2414,23 @@ var PTRedeemHandler = class {
2414
2414
  );
2415
2415
  }
2416
2416
  if (this.redemptionService) {
2417
- const decision = await this.redemptionService.evaluate(
2418
- request.userAddress,
2419
- request.amount,
2420
- pointTokenAddress
2421
- );
2417
+ let decision;
2418
+ try {
2419
+ decision = await this.redemptionService.evaluate(
2420
+ request.userAddress,
2421
+ request.amount,
2422
+ pointTokenAddress
2423
+ );
2424
+ } catch (err) {
2425
+ const code = err && typeof err === "object" && "code" in err ? err.code : void 0;
2426
+ if (code === "POLICY_PROVIDER_UNAVAILABLE") {
2427
+ throw new PTRedeemError(
2428
+ "REDEMPTION_POLICY_UNAVAILABLE",
2429
+ "Redemption policy temporarily unavailable \u2014 please try again shortly."
2430
+ );
2431
+ }
2432
+ throw err;
2433
+ }
2422
2434
  if (!decision.allowed) {
2423
2435
  const denial = decision.denial;
2424
2436
  throw new PTRedeemError(
@@ -3872,10 +3884,6 @@ var IssuerApiAdapter = class {
3872
3884
  pointTokenAddress,
3873
3885
  redeemResponse.expiresInSeconds,
3874
3886
  input.eip7702Auth,
3875
- // Audit PACI5-21 — fallback path reserves a separate
3876
- // PendingCredit row for the full `amount`. Surface its lockId so
3877
- // mobile FE can poll the correct row + `handleMobileSubmit`
3878
- // routes the userOpHash bind to it on fallback submit.
3879
3887
  redeemResponse.fallback?.lockId
3880
3888
  );
3881
3889
  return {
@@ -4454,7 +4462,9 @@ var PafiBackendClient = class {
4454
4462
  if (!config.issuerId) throw new Error("PafiBackendClient: issuerId is required");
4455
4463
  if (!config.apiKey) throw new Error("PafiBackendClient: apiKey is required");
4456
4464
  this.config = config;
4457
- this.baseUrl = (0, import_core16.getPafiServiceUrls)(config.chainId).sponsorRelayer;
4465
+ this.baseUrl = (0, import_core16.getPafiServiceUrls)(config.chainId, {
4466
+ sponsorRelayer: config.baseUrl
4467
+ }).sponsorRelayer;
4458
4468
  }
4459
4469
  async requestSponsorship(request) {
4460
4470
  const maxAttempts = this.config.retry?.maxAttempts ?? 1;
@@ -4615,7 +4625,7 @@ var PafiBackendClient = class {
4615
4625
 
4616
4626
  // src/config.ts
4617
4627
  var import_viem15 = require("viem");
4618
- var import_core18 = require("@pafi-dev/core");
4628
+ var import_core19 = require("@pafi-dev/core");
4619
4629
 
4620
4630
  // src/redemption/evaluator.ts
4621
4631
  var SECONDS_PER_DAY = 24 * 60 * 60;
@@ -4719,6 +4729,9 @@ function nextBlackoutEndAfter(windows, nowUnixSec) {
4719
4729
  }
4720
4730
  var REDEMPTION_HISTORY_WINDOW_SEC = SECONDS_PER_DAY;
4721
4731
 
4732
+ // src/redemption/policyProvider.ts
4733
+ var import_core18 = require("@pafi-dev/core");
4734
+
4722
4735
  // src/redemption/settlementClient.ts
4723
4736
  var import_core17 = require("@pafi-dev/core");
4724
4737
  var DEFAULT_TIMEOUT_MS = 1e3;
@@ -4729,7 +4742,12 @@ var SettlementClient = class {
4729
4742
  if (!config.issuerId) throw new Error("SettlementClient: issuerId is required");
4730
4743
  if (!config.apiKey) throw new Error("SettlementClient: apiKey is required");
4731
4744
  this.config = {
4732
- baseUrl: (0, import_core17.getPafiServiceUrls)(config.chainId).issuerApi.replace(/\/+$/, ""),
4745
+ // Audit PACI5-17 — honor optional baseUrl override wired from
4746
+ // an env var (e.g. PAFI_ISSUER_API_URL). Empty / undefined →
4747
+ // ship-default for chainId.
4748
+ baseUrl: (0, import_core17.getPafiServiceUrls)(config.chainId, {
4749
+ issuerApi: config.baseUrl
4750
+ }).issuerApi.replace(/\/+$/, ""),
4733
4751
  issuerId: config.issuerId,
4734
4752
  apiKey: config.apiKey,
4735
4753
  fetchTimeoutMs: config.fetchTimeoutMs ?? DEFAULT_TIMEOUT_MS,
@@ -4833,10 +4851,23 @@ function defaultPolicyFor(issuerId) {
4833
4851
 
4834
4852
  // src/redemption/policyProvider.ts
4835
4853
  var DEFAULT_CACHE_TTL_MS3 = 5 * 60 * 1e3;
4854
+ var PolicyProviderUnavailableError = class extends import_core18.PafiSdkError {
4855
+ code = "POLICY_PROVIDER_UNAVAILABLE";
4856
+ httpStatus = "service_unavailable";
4857
+ details;
4858
+ constructor(issuerId, reason) {
4859
+ super(
4860
+ `Redemption policy provider unavailable for issuer ${issuerId}: ${reason}. Pre-flight redeem limit cannot be enforced \u2014 refusing to sign BurnRequest. Mobile FE: surface "try again shortly" and retry with backoff.`
4861
+ );
4862
+ this.details = { issuerId, reason };
4863
+ }
4864
+ };
4836
4865
  var PolicyProvider = class {
4837
4866
  client;
4838
4867
  issuerId;
4839
4868
  cacheTtlMs;
4869
+ onFetchFailure;
4870
+ onWarning;
4840
4871
  now;
4841
4872
  cache = null;
4842
4873
  inflight = null;
@@ -4844,6 +4875,8 @@ var PolicyProvider = class {
4844
4875
  this.client = new SettlementClient(config);
4845
4876
  this.issuerId = config.issuerId;
4846
4877
  this.cacheTtlMs = config.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS3;
4878
+ this.onFetchFailure = config.onFetchFailure ?? "fail-closed";
4879
+ this.onWarning = config.onWarning;
4847
4880
  this.now = config.now ?? (() => Date.now());
4848
4881
  }
4849
4882
  async getPolicy() {
@@ -4876,7 +4909,19 @@ var PolicyProvider = class {
4876
4909
  };
4877
4910
  return { policy: result.policy, source: "settlement" };
4878
4911
  }
4879
- return { policy: defaultPolicyFor(this.issuerId), source: "default" };
4912
+ const reason = "reason" in result && typeof result.reason === "string" ? result.reason : "unknown";
4913
+ if (this.onFetchFailure === "permissive-default") {
4914
+ this.onWarning?.(
4915
+ "PolicyProvider: settlement-api unreachable, falling back to permissive default. Pre-flight redeem limit is DEGRADED until settlement-api recovers.",
4916
+ {
4917
+ event: "policy_provider_fallback",
4918
+ issuerId: this.issuerId,
4919
+ reason
4920
+ }
4921
+ );
4922
+ return { policy: defaultPolicyFor(this.issuerId), source: "default" };
4923
+ }
4924
+ throw new PolicyProviderUnavailableError(this.issuerId, reason);
4880
4925
  }
4881
4926
  };
4882
4927
 
@@ -4966,7 +5011,7 @@ async function createIssuerService(config) {
4966
5011
  provider: config.provider
4967
5012
  });
4968
5013
  }
4969
- const sdkWrapperAddress = (0, import_core18.getContractAddresses)(config.chainId).mintFeeWrapper;
5014
+ const sdkWrapperAddress = (0, import_core19.getContractAddresses)(config.chainId).mintFeeWrapper;
4970
5015
  const wrapperOverride = config.indexer?.mintFeeWrapperAddress;
4971
5016
  const resolvedWrapperAddress = wrapperOverride !== void 0 ? wrapperOverride : sdkWrapperAddress;
4972
5017
  const baseCursorStore = config.indexer?.cursorStore;
@@ -5005,7 +5050,7 @@ async function createIssuerService(config) {
5005
5050
  }
5006
5051
  indexers.set(tokenAddress, new PointIndexer(indexerConfig));
5007
5052
  }
5008
- const chainAddresses = (0, import_core18.getContractAddresses)(config.chainId);
5053
+ const chainAddresses = (0, import_core19.getContractAddresses)(config.chainId);
5009
5054
  const resolvedContracts = {
5010
5055
  batchExecutor: chainAddresses.batchExecutor,
5011
5056
  usdt: chainAddresses.usdt,
@@ -5023,6 +5068,15 @@ async function createIssuerService(config) {
5023
5068
  issuerId: config.redemption.issuerId,
5024
5069
  apiKey: config.redemption.apiKey
5025
5070
  };
5071
+ if (config.redemption.baseUrl) {
5072
+ policyConfig.baseUrl = config.redemption.baseUrl;
5073
+ }
5074
+ if (config.redemption.onFetchFailure) {
5075
+ policyConfig.onFetchFailure = config.redemption.onFetchFailure;
5076
+ }
5077
+ if (config.redemption.onPolicyWarning) {
5078
+ policyConfig.onWarning = config.redemption.onPolicyWarning;
5079
+ }
5026
5080
  if (config.redemption.fetchImpl) policyConfig.fetchImpl = config.redemption.fetchImpl;
5027
5081
  if (config.redemption.fetchTimeoutMs !== void 0) {
5028
5082
  policyConfig.fetchTimeoutMs = config.redemption.fetchTimeoutMs;
@@ -5088,7 +5142,7 @@ async function createIssuerService(config) {
5088
5142
 
5089
5143
  // src/issuer-state/validator.ts
5090
5144
  var import_viem16 = require("viem");
5091
- var import_core19 = require("@pafi-dev/core");
5145
+ var import_core20 = require("@pafi-dev/core");
5092
5146
  var ISSUER_RECORD_TTL_MS = 3e4;
5093
5147
  var IssuerStateValidator = class _IssuerStateValidator {
5094
5148
  constructor(provider, registryAddress) {
@@ -5105,7 +5159,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
5105
5159
  * `CONTRACT_ADDRESSES` map for the given chain.
5106
5160
  */
5107
5161
  static forChain(provider, chainId) {
5108
- const { issuerRegistry } = (0, import_core19.getContractAddresses)(chainId);
5162
+ const { issuerRegistry } = (0, import_core20.getContractAddresses)(chainId);
5109
5163
  return new _IssuerStateValidator(provider, issuerRegistry);
5110
5164
  }
5111
5165
  /**
@@ -5134,7 +5188,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
5134
5188
  if (cached) return cached;
5135
5189
  const issuer = await this.provider.readContract({
5136
5190
  address: key,
5137
- abi: import_core19.POINT_TOKEN_ABI,
5191
+ abi: import_core20.POINT_TOKEN_ABI,
5138
5192
  functionName: "issuer"
5139
5193
  });
5140
5194
  this.pointTokenIssuerCache.set(key, (0, import_viem16.getAddress)(issuer));
@@ -5214,7 +5268,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
5214
5268
  const issuerAddr = await this.getIssuerAddressForPointToken(tokenAddr);
5215
5269
  const issuerStruct = await this.provider.readContract({
5216
5270
  address: this.registryAddress,
5217
- abi: import_core19.issuerRegistryAbi,
5271
+ abi: import_core20.issuerRegistryAbi,
5218
5272
  functionName: "getIssuer",
5219
5273
  args: [issuerAddr]
5220
5274
  });
@@ -5227,7 +5281,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
5227
5281
  };
5228
5282
  const equitySupply = await this.provider.readContract({
5229
5283
  address: tokenAddr,
5230
- abi: import_core19.POINT_TOKEN_ABI,
5284
+ abi: import_core20.POINT_TOKEN_ABI,
5231
5285
  functionName: "equitySupply"
5232
5286
  });
5233
5287
  const hardCap = issuer.capitalBase * BigInt(issuer.basisPoints) / 10000n;
@@ -5283,7 +5337,7 @@ var MemoryRedemptionHistoryStore = class {
5283
5337
  };
5284
5338
 
5285
5339
  // src/index.ts
5286
- var PAFI_ISSUER_SDK_VERSION = true ? "0.31.0" : "dev";
5340
+ var PAFI_ISSUER_SDK_VERSION = true ? "0.32.0" : "dev";
5287
5341
  // Annotate the CommonJS export names for ESM import in node:
5288
5342
  0 && (module.exports = {
5289
5343
  AdapterMisconfiguredError,