@fiber-pay/runtime 0.1.0-rc.5 → 0.1.0-rc.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.js CHANGED
@@ -1401,6 +1401,19 @@ async function* runPaymentJob(job, rpc, policy, signal) {
1401
1401
  yield current;
1402
1402
  continue;
1403
1403
  }
1404
+ if (current.params.sendPaymentParams.dry_run) {
1405
+ current = transitionJobState(current, paymentStateMachine, "payment_success", {
1406
+ patch: {
1407
+ result: {
1408
+ paymentHash: sendResult.payment_hash,
1409
+ status: "DryRunSuccess",
1410
+ fee: sendResult.fee
1411
+ }
1412
+ }
1413
+ });
1414
+ yield current;
1415
+ return;
1416
+ }
1404
1417
  current = transitionJobState(current, paymentStateMachine, "payment_inflight");
1405
1418
  if (paymentHash) {
1406
1419
  current = {
@@ -2154,11 +2167,61 @@ var HealthMonitor = class extends BaseMonitor {
2154
2167
  };
2155
2168
 
2156
2169
  // src/monitors/tracker-utils.ts
2170
+ function isNotFoundError(error) {
2171
+ const haystack = collectErrorText(error);
2172
+ return /not found|does not exist|no such/i.test(haystack);
2173
+ }
2157
2174
  function isExpectedTrackerError(error) {
2158
- const message = error instanceof Error ? error.message : String(error);
2159
- return /not found|does not exist|no such|temporarily unavailable|connection refused|timed out|timeout/i.test(
2160
- message
2161
- );
2175
+ const haystack = collectErrorText(error);
2176
+ return /temporarily unavailable|connection refused|timed out|timeout/i.test(haystack);
2177
+ }
2178
+ function collectErrorText(error) {
2179
+ if (error === null || error === void 0) {
2180
+ return "";
2181
+ }
2182
+ const parts = [];
2183
+ const seen = /* @__PURE__ */ new Set();
2184
+ const walk = (value, depth) => {
2185
+ if (value === null || value === void 0) {
2186
+ return;
2187
+ }
2188
+ if (depth > 4) {
2189
+ return;
2190
+ }
2191
+ if (typeof value === "string") {
2192
+ parts.push(value);
2193
+ return;
2194
+ }
2195
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
2196
+ parts.push(String(value));
2197
+ return;
2198
+ }
2199
+ if (typeof value !== "object") {
2200
+ return;
2201
+ }
2202
+ if (seen.has(value)) {
2203
+ return;
2204
+ }
2205
+ seen.add(value);
2206
+ if (value instanceof Error) {
2207
+ parts.push(value.message);
2208
+ const valueWithData = value;
2209
+ walk(valueWithData.data, depth + 1);
2210
+ walk(valueWithData.cause, depth + 1);
2211
+ return;
2212
+ }
2213
+ if (Array.isArray(value)) {
2214
+ for (const item of value) {
2215
+ walk(item, depth + 1);
2216
+ }
2217
+ return;
2218
+ }
2219
+ for (const nested of Object.values(value)) {
2220
+ walk(nested, depth + 1);
2221
+ }
2222
+ };
2223
+ walk(error, 0);
2224
+ return parts.join(" ");
2162
2225
  }
2163
2226
 
2164
2227
  // src/monitors/invoice-tracker.ts
@@ -2230,6 +2293,21 @@ var InvoiceTracker = class extends BaseMonitor {
2230
2293
  }
2231
2294
  }
2232
2295
  } catch (error) {
2296
+ if (isNotFoundError(error)) {
2297
+ this.store.updateTrackedInvoice(invoice.paymentHash, "Cancelled");
2298
+ await this.alerts.emit({
2299
+ type: "invoice_cancelled",
2300
+ priority: "medium",
2301
+ source: this.name,
2302
+ data: {
2303
+ paymentHash: invoice.paymentHash,
2304
+ previousStatus: invoice.status,
2305
+ currentStatus: "Cancelled",
2306
+ reason: "not_found"
2307
+ }
2308
+ });
2309
+ continue;
2310
+ }
2233
2311
  if (isExpectedTrackerError(error)) {
2234
2312
  continue;
2235
2313
  }
@@ -2299,6 +2377,21 @@ var PaymentTracker = class extends BaseMonitor {
2299
2377
  }
2300
2378
  }
2301
2379
  } catch (error) {
2380
+ if (isNotFoundError(error)) {
2381
+ this.store.updateTrackedPayment(payment.paymentHash, "Failed");
2382
+ await this.alerts.emit({
2383
+ type: "outgoing_payment_failed",
2384
+ priority: "high",
2385
+ source: this.name,
2386
+ data: {
2387
+ paymentHash: payment.paymentHash,
2388
+ previousStatus: payment.status,
2389
+ currentStatus: "Failed",
2390
+ reason: "not_found"
2391
+ }
2392
+ });
2393
+ continue;
2394
+ }
2302
2395
  if (isExpectedTrackerError(error)) {
2303
2396
  continue;
2304
2397
  }
@@ -2537,7 +2630,8 @@ function collectJsonRpcMethods(requestBody) {
2537
2630
  const methods = /* @__PURE__ */ new Map();
2538
2631
  for (const item of normalizeJsonRpcRequest(requestBody)) {
2539
2632
  if (item.id !== void 0 && typeof item.method === "string") {
2540
- methods.set(item.id, item.method);
2633
+ const dryRun = isDryRunRequest(item);
2634
+ methods.set(item.id, { method: item.method, dryRun });
2541
2635
  }
2542
2636
  }
2543
2637
  return methods;
@@ -2548,17 +2642,17 @@ function captureTrackedHashes(methodById, responseBody, handlers) {
2548
2642
  if (message.error || message.id === void 0) {
2549
2643
  continue;
2550
2644
  }
2551
- const method = methodById.get(message.id);
2552
- if (!method) {
2645
+ const meta = methodById.get(message.id);
2646
+ if (!meta) {
2553
2647
  continue;
2554
2648
  }
2555
- if (method === "new_invoice") {
2649
+ if (meta.method === "new_invoice") {
2556
2650
  const paymentHash = extractInvoicePaymentHash(message.result);
2557
2651
  if (paymentHash) {
2558
2652
  handlers.onInvoiceTracked(paymentHash);
2559
2653
  }
2560
2654
  }
2561
- if (method === "send_payment") {
2655
+ if (meta.method === "send_payment" && !meta.dryRun) {
2562
2656
  const paymentHash = extractPaymentHash(message.result);
2563
2657
  if (paymentHash) {
2564
2658
  handlers.onPaymentTracked(paymentHash);
@@ -2610,6 +2704,13 @@ function extractPaymentHash(result) {
2610
2704
  }
2611
2705
  return typeof result.payment_hash === "string" ? result.payment_hash : void 0;
2612
2706
  }
2707
+ function isDryRunRequest(message) {
2708
+ if (!Array.isArray(message.params) || message.params.length === 0) {
2709
+ return false;
2710
+ }
2711
+ const firstParam = message.params[0];
2712
+ return isObject(firstParam) && firstParam.dry_run === true;
2713
+ }
2613
2714
 
2614
2715
  // src/proxy/monitor-routes.ts
2615
2716
  function handleMonitorEndpoint(req, res, deps) {
@@ -3374,6 +3475,8 @@ var FiberMonitorService = class extends EventEmitter2 {
3374
3475
  this.alerts.onEmit((alert) => {
3375
3476
  this.emit("alert", alert);
3376
3477
  });
3478
+ const jobManager = this.jobManager;
3479
+ const jobStore = this.jobStore;
3377
3480
  this.proxy = new RpcMonitorProxy(
3378
3481
  {
3379
3482
  listen: this.config.proxy.listen,
@@ -3390,13 +3493,13 @@ var FiberMonitorService = class extends EventEmitter2 {
3390
3493
  listTrackedPayments: () => this.store.listTrackedPayments(),
3391
3494
  listAlerts: (filters) => this.store.listAlerts(filters),
3392
3495
  getStatus: () => this.getStatus(),
3393
- createPaymentJob: this.jobManager ? (params, options) => this.jobManager.ensurePayment(params, options) : void 0,
3394
- createInvoiceJob: this.jobManager ? (params, options) => this.jobManager.manageInvoice(params, options) : void 0,
3395
- createChannelJob: this.jobManager ? (params, options) => this.jobManager.manageChannel(params, options) : void 0,
3396
- getJob: this.jobManager ? (id) => this.jobManager.getJob(id) : void 0,
3397
- listJobs: this.jobManager ? (filter) => this.jobManager.listJobs(filter) : void 0,
3398
- cancelJob: this.jobManager ? (id) => this.jobManager.cancelJob(id) : void 0,
3399
- listJobEvents: this.jobStore ? (jobId) => this.jobStore.listJobEvents(jobId) : void 0
3496
+ createPaymentJob: jobManager ? (params, options) => jobManager.ensurePayment(params, options) : void 0,
3497
+ createInvoiceJob: jobManager ? (params, options) => jobManager.manageInvoice(params, options) : void 0,
3498
+ createChannelJob: jobManager ? (params, options) => jobManager.manageChannel(params, options) : void 0,
3499
+ getJob: jobManager ? (id) => jobManager.getJob(id) : void 0,
3500
+ listJobs: jobManager ? (filter) => jobManager.listJobs(filter) : void 0,
3501
+ cancelJob: jobManager ? (id) => jobManager.cancelJob(id) : void 0,
3502
+ listJobEvents: jobStore ? (jobId) => jobStore.listJobEvents(jobId) : void 0
3400
3503
  }
3401
3504
  );
3402
3505
  }