moltspay 0.8.5 → 0.8.7

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.mjs CHANGED
@@ -30355,20 +30355,34 @@ var USDC_DOMAIN = {
30355
30355
  version: "2"
30356
30356
  };
30357
30357
  function loadEnvFiles() {
30358
- try {
30359
- const dotenv = __require("dotenv");
30360
- const envPaths = [
30361
- path2.join(process.cwd(), ".env"),
30362
- path2.join(process.env.HOME || "", ".moltspay", ".env")
30363
- ];
30364
- for (const envPath of envPaths) {
30365
- if (existsSync(envPath)) {
30366
- dotenv.config({ path: envPath });
30358
+ const envPaths = [
30359
+ path2.join(process.cwd(), ".env"),
30360
+ path2.join(process.env.HOME || "", ".moltspay", ".env")
30361
+ ];
30362
+ for (const envPath of envPaths) {
30363
+ if (existsSync(envPath)) {
30364
+ try {
30365
+ const content = readFileSync(envPath, "utf-8");
30366
+ for (const line of content.split("\n")) {
30367
+ const trimmed = line.trim();
30368
+ if (!trimmed || trimmed.startsWith("#")) continue;
30369
+ const eqIndex = trimmed.indexOf("=");
30370
+ if (eqIndex === -1) continue;
30371
+ const key = trimmed.slice(0, eqIndex).trim();
30372
+ let value = trimmed.slice(eqIndex + 1).trim();
30373
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
30374
+ value = value.slice(1, -1);
30375
+ }
30376
+ if (!process.env[key]) {
30377
+ process.env[key] = value;
30378
+ }
30379
+ }
30367
30380
  console.log(`[MoltsPay] Loaded config from ${envPath}`);
30368
30381
  break;
30382
+ } catch (err) {
30383
+ console.warn(`[MoltsPay] Failed to load ${envPath}:`, err);
30369
30384
  }
30370
30385
  }
30371
- } catch {
30372
30386
  }
30373
30387
  }
30374
30388
  function getCDPConfig() {
@@ -30935,10 +30949,18 @@ var MoltsPayClient = class {
30935
30949
  if (!req) {
30936
30950
  throw new Error(`No matching payment option for ${network}`);
30937
30951
  }
30938
- const amount = Number(req.maxAmountRequired) / 1e6;
30952
+ const amountRaw = req.amount || req.maxAmountRequired;
30953
+ if (!amountRaw) {
30954
+ throw new Error("Missing amount in payment requirements");
30955
+ }
30956
+ const amount = Number(amountRaw) / 1e6;
30939
30957
  this.checkLimits(amount);
30940
30958
  console.log(`[MoltsPay] Signing payment: $${amount} USDC (gasless)`);
30941
- const authorization = await this.signEIP3009(req.resource, amount, chain2);
30959
+ const payTo = req.payTo || req.resource;
30960
+ if (!payTo) {
30961
+ throw new Error("Missing payTo address in payment requirements");
30962
+ }
30963
+ const authorization = await this.signEIP3009(payTo, amount, chain2);
30942
30964
  const payload = {
30943
30965
  x402Version: X402_VERSION2,
30944
30966
  scheme: "exact",