@dvmkit/sdk 0.17.1 → 0.19.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.
Files changed (31) hide show
  1. package/dist/{chunk-ORBWKYDE.js → chunk-34H4ZKBM.js} +1 -1
  2. package/dist/{chunk-WMGXJQI3.js → chunk-5RGZN6WQ.js} +1 -1
  3. package/dist/{chunk-3KRFFLAT.js → chunk-C65P6MGZ.js} +1 -1
  4. package/dist/{chunk-C5XNZLZ7.js → chunk-DJRTYBEE.js} +1 -1
  5. package/dist/{chunk-B5MPLDRC.js → chunk-I5MXADJS.js} +1 -1
  6. package/dist/{chunk-EIDRCGTY.js → chunk-INYFUPXV.js} +41 -13
  7. package/dist/{chunk-5CCQEAQV.js → chunk-MXESSBXF.js} +47 -0
  8. package/dist/{chunk-YRQMDRI4.js → chunk-NLMRNLKA.js} +14270 -13793
  9. package/dist/{chunk-62FI3NJF.js → chunk-NUDHO4HV.js} +4 -2
  10. package/dist/{chunk-VKFR5PCW.js → chunk-OTNHKRHA.js} +2 -2
  11. package/dist/{content-retention-B_hOQS36.d.ts → content-retention-sUCPlA1J.d.ts} +1 -1
  12. package/dist/{credit-ledger-5HMJ6VUX.js → credit-ledger-ZCJXJG6R.js} +2 -2
  13. package/dist/{credit-menu-D-h0zJCZ.d.ts → credit-menu-D88XuTLU.d.ts} +145 -6
  14. package/dist/{fx-CpqQaIfg.d.ts → fx-QoVA2oBc.d.ts} +1 -1
  15. package/dist/index.d.ts +5 -5
  16. package/dist/index.js +18 -3
  17. package/dist/internal/caller.d.ts +12 -8
  18. package/dist/internal/caller.js +3 -3
  19. package/dist/internal/server.d.ts +7 -7
  20. package/dist/internal/server.js +9 -9
  21. package/dist/{job-store-CgXT79tS.d.ts → job-store-Dy-ogco6.d.ts} +1 -1
  22. package/dist/{lightning-backend-B1hRUIOb.d.ts → lightning-backend-B2wMBR-x.d.ts} +1 -1
  23. package/dist/{memory-credit-ledger-ME6FH462.js → memory-credit-ledger-N4PZKTT5.js} +3 -3
  24. package/dist/server/index.d.ts +10 -10
  25. package/dist/server/index.js +10 -10
  26. package/dist/{step-cache-Bezn-_ZL.d.ts → step-cache-B83Y9T9p.d.ts} +73 -9
  27. package/dist/{tempo-session-store-EWBE5HJM.js → tempo-session-store-XJE6GIXN.js} +2 -2
  28. package/dist/testing/index.d.ts +3 -3
  29. package/dist/{usd-CJwU3-A4.d.ts → usd-g9kCw86F.d.ts} +1 -1
  30. package/dist/{x402-HVCUEWWU.js → x402-XLFD43RF.js} +4 -4
  31. package/package.json +1 -1
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-COYKJRMM.js";
8
8
  import {
9
9
  withPostgresTransactionRecovery
10
- } from "./chunk-EIDRCGTY.js";
10
+ } from "./chunk-INYFUPXV.js";
11
11
 
12
12
  // src/sdk/server/tempo-session-store.ts
13
13
  import { AsyncLocalStorage } from "async_hooks";
@@ -2,7 +2,7 @@ import {
2
2
  X402_DEFAULT_NETWORK,
3
3
  resolveRpcHttpTransportOptions,
4
4
  resolveRpcOverride
5
- } from "./chunk-62FI3NJF.js";
5
+ } from "./chunk-NUDHO4HV.js";
6
6
  import {
7
7
  redactUrl,
8
8
  redactUrlsInText
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  X402_DEFAULT_FACILITATOR
3
- } from "./chunk-62FI3NJF.js";
3
+ } from "./chunk-NUDHO4HV.js";
4
4
  import {
5
5
  callerLoggers
6
6
  } from "./chunk-66HGCPBU.js";
@@ -18,7 +18,7 @@ import {
18
18
  refundAssetDelta,
19
19
  refundRequest,
20
20
  x402SettlementPending
21
- } from "./chunk-B5MPLDRC.js";
21
+ } from "./chunk-I5MXADJS.js";
22
22
 
23
23
  // src/sdk/server/memory-credit-ledger.ts
24
24
  import { randomUUID } from "crypto";
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-5UC7TOQC.js";
11
11
  import {
12
12
  applyRetryToPool
13
- } from "./chunk-EIDRCGTY.js";
13
+ } from "./chunk-INYFUPXV.js";
14
14
  import {
15
15
  x402NetworkByCaip2
16
16
  } from "./chunk-BPYMEMQX.js";
@@ -5,6 +5,7 @@ import {
5
5
  // src/lib/pg-retry.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
7
7
  var postgresRecovery = new AsyncLocalStorage();
8
+ var queryingPool = new AsyncLocalStorage();
8
9
  function withPostgresRecoveryContext(context, operation) {
9
10
  return postgresRecovery.run(context, operation);
10
11
  }
@@ -46,18 +47,39 @@ function applyRetryToPool(pool, label = "pg-pool") {
46
47
  });
47
48
  const p = pool;
48
49
  const origQuery = p.query.bind(pool);
49
- p.query = (...args) => withTransportRecovery(pool, label, "pool.query", () => origQuery(...args));
50
- const origConnect = p.connect.bind(pool);
51
- p.connect = async (...args) => {
52
- const client = await withTransportRecovery(
53
- pool,
54
- label,
55
- "pool.connect",
56
- () => origConnect(...args)
50
+ p.query = (...args) => withTransportRecovery(
51
+ pool,
52
+ label,
53
+ "pool.query",
54
+ () => queryingPool.run(pool, () => origQuery(...args))
55
+ );
56
+ const origConnect = pool.connect.bind(pool);
57
+ pool.connect = ((callback) => {
58
+ if (queryingPool.getStore() === pool) {
59
+ return queryingPool.exit(() => callback ? origConnect(callback) : origConnect());
60
+ }
61
+ const pending = withTransportRecovery(pool, label, "pool.connect", async () => {
62
+ const client = await origConnect();
63
+ guardCheckedOutClient(client, label);
64
+ const remainingMs = (postgresRecovery.getStore()?.deadlineMs ?? Infinity) - Date.now();
65
+ const probe = {
66
+ text: "SELECT 1",
67
+ query_timeout: Math.max(1, Math.min(connectionTimeoutMs(pool), remainingMs))
68
+ };
69
+ try {
70
+ await client.query(probe);
71
+ return client;
72
+ } catch (error) {
73
+ client.release(asError(error));
74
+ throw error;
75
+ }
76
+ });
77
+ if (!callback) return pending;
78
+ void pending.then(
79
+ (client) => callback(void 0, client, client.release),
80
+ (error) => callback(asError(error), void 0, () => void 0)
57
81
  );
58
- guardCheckedOutClient(client, label);
59
- return client;
60
- };
82
+ });
61
83
  }
62
84
  function withPostgresTransactionRecovery(pool, label, operation, callback) {
63
85
  return withTransportRecovery(pool, label, operation, async () => {
@@ -79,8 +101,9 @@ function withPostgresTransactionRecovery(pool, label, operation, callback) {
79
101
  }
80
102
  async function withTransportRecovery(pool, label, operation, callback) {
81
103
  const context = postgresRecovery.getStore();
82
- const maxAttempts = context?.drainPool ? hostPoolSize(pool) + 1 : 2;
104
+ const maxAttempts = context?.drainPool === false ? 2 : hostPoolSize(pool) + 1;
83
105
  const startedAt = Date.now();
106
+ const deadlineMs = context?.deadlineMs ?? startedAt + connectionTimeoutMs(pool);
84
107
  let firstError;
85
108
  for (let attempt = 1; ; attempt += 1) {
86
109
  try {
@@ -101,7 +124,7 @@ async function withTransportRecovery(pool, label, operation, callback) {
101
124
  if (!isTransportError(error)) throw error;
102
125
  firstError ??= asError(error);
103
126
  const elapsedMs = Date.now() - startedAt;
104
- if (attempt >= maxAttempts || context !== void 0 && Date.now() >= context.deadlineMs) {
127
+ if (attempt >= maxAttempts || Date.now() >= deadlineMs) {
105
128
  logTransportRecovery({
106
129
  context,
107
130
  label,
@@ -116,6 +139,10 @@ async function withTransportRecovery(pool, label, operation, callback) {
116
139
  }
117
140
  }
118
141
  }
142
+ function connectionTimeoutMs(pool) {
143
+ const configured = pool.options.connectionTimeoutMillis;
144
+ return typeof configured === "number" && Number.isFinite(configured) && configured > 0 ? configured : 1e4;
145
+ }
119
146
  function hostPoolSize(pool) {
120
147
  const configured = pool.options.max;
121
148
  return typeof configured === "number" && Number.isSafeInteger(configured) && configured > 0 ? configured : 10;
@@ -161,6 +188,7 @@ function truncateUtf8(value, maxBytes) {
161
188
 
162
189
  export {
163
190
  withPostgresRecoveryContext,
191
+ isTransportError,
164
192
  withInitRetry,
165
193
  applyRetryToPool,
166
194
  withPostgresTransactionRecovery
@@ -314,7 +314,54 @@ function createDefaultReplayStore() {
314
314
  }
315
315
  var SATURATION_WARN_INTERVAL_SECONDS = 60;
316
316
 
317
+ // src/sdk/cashu-locktime.ts
318
+ var CASHU_MIN_LOCKTIME_SECONDS = 604800;
319
+ var CASHU_LOCKTIME_RESUME_MARGIN_SECONDS = 86400;
320
+ var CASHU_LOCKTIME_FLOOR_MINIMUM_SECONDS = 3600;
321
+ var CASHU_SIGNED_LOCKTIME_FLOOR_MINIMUM_SECONDS = CASHU_LOCKTIME_RESUME_MARGIN_SECONDS + CASHU_LOCKTIME_FLOOR_MINIMUM_SECONDS;
322
+ var DEFAULT_CASHU_LOCK_WINDOW_SECONDS = CASHU_MIN_LOCKTIME_SECONDS - CASHU_LOCKTIME_RESUME_MARGIN_SECONDS;
323
+ function signedCashuLockWindowSeconds(cashu) {
324
+ return (cashu?.minLocktimeSeconds ?? CASHU_MIN_LOCKTIME_SECONDS) - CASHU_LOCKTIME_RESUME_MARGIN_SECONDS;
325
+ }
326
+ function unsignedCashuLockWindowSeconds(cashu) {
327
+ return cashu?.unsignedMinLocktimeSeconds ?? DEFAULT_CASHU_LOCK_WINDOW_SECONDS;
328
+ }
329
+ function shortestCashuLockWindowSeconds(cashu, servesUnsigned) {
330
+ const signed = signedCashuLockWindowSeconds(cashu);
331
+ return servesUnsigned ? Math.min(signed, unsignedCashuLockWindowSeconds(cashu)) : signed;
332
+ }
333
+ function resolveCashuConfig(cashu) {
334
+ if (cashu === void 0) return void 0;
335
+ if (typeof cashu !== "object" || cashu === null || Array.isArray(cashu)) {
336
+ throw new Error(`configureDVM: cashu must be an object of refund-locktime floors; received ${JSON.stringify(cashu)}`);
337
+ }
338
+ const minLocktimeSeconds = validFloor(cashu.minLocktimeSeconds, "minLocktimeSeconds", CASHU_SIGNED_LOCKTIME_FLOOR_MINIMUM_SECONDS) ?? CASHU_MIN_LOCKTIME_SECONDS;
339
+ const unsignedMinLocktimeSeconds = validFloor(cashu.unsignedMinLocktimeSeconds, "unsignedMinLocktimeSeconds", CASHU_LOCKTIME_FLOOR_MINIMUM_SECONDS) ?? minLocktimeSeconds - CASHU_LOCKTIME_RESUME_MARGIN_SECONDS;
340
+ const signedWindow = minLocktimeSeconds - CASHU_LOCKTIME_RESUME_MARGIN_SECONDS;
341
+ if (unsignedMinLocktimeSeconds > signedWindow) {
342
+ throw new Error(
343
+ `configureDVM: cashu.unsignedMinLocktimeSeconds (${unsignedMinLocktimeSeconds}) must not exceed cashu.minLocktimeSeconds less 86400 (${signedWindow}); a payer without a signature can take the signed floor instead by sending X-Cashu-Request-Id`
344
+ );
345
+ }
346
+ return { minLocktimeSeconds, unsignedMinLocktimeSeconds };
347
+ }
348
+ function validFloor(value, field, minimum) {
349
+ if (value === void 0) return void 0;
350
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
351
+ throw new Error(
352
+ `configureDVM: cashu.${field} must be a whole number of seconds, at least ${minimum}; received ${JSON.stringify(value)}`
353
+ );
354
+ }
355
+ return value;
356
+ }
357
+
317
358
  export {
359
+ CASHU_MIN_LOCKTIME_SECONDS,
360
+ DEFAULT_CASHU_LOCK_WINDOW_SECONDS,
361
+ signedCashuLockWindowSeconds,
362
+ unsignedCashuLockWindowSeconds,
363
+ shortestCashuLockWindowSeconds,
364
+ resolveCashuConfig,
318
365
  humanizeZodError,
319
366
  humanizeZodIssues,
320
367
  zodIssuesOf,