@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.
- package/dist/{chunk-ORBWKYDE.js → chunk-34H4ZKBM.js} +1 -1
- package/dist/{chunk-WMGXJQI3.js → chunk-5RGZN6WQ.js} +1 -1
- package/dist/{chunk-3KRFFLAT.js → chunk-C65P6MGZ.js} +1 -1
- package/dist/{chunk-C5XNZLZ7.js → chunk-DJRTYBEE.js} +1 -1
- package/dist/{chunk-B5MPLDRC.js → chunk-I5MXADJS.js} +1 -1
- package/dist/{chunk-EIDRCGTY.js → chunk-INYFUPXV.js} +41 -13
- package/dist/{chunk-5CCQEAQV.js → chunk-MXESSBXF.js} +47 -0
- package/dist/{chunk-YRQMDRI4.js → chunk-NLMRNLKA.js} +14270 -13793
- package/dist/{chunk-62FI3NJF.js → chunk-NUDHO4HV.js} +4 -2
- package/dist/{chunk-VKFR5PCW.js → chunk-OTNHKRHA.js} +2 -2
- package/dist/{content-retention-B_hOQS36.d.ts → content-retention-sUCPlA1J.d.ts} +1 -1
- package/dist/{credit-ledger-5HMJ6VUX.js → credit-ledger-ZCJXJG6R.js} +2 -2
- package/dist/{credit-menu-D-h0zJCZ.d.ts → credit-menu-D88XuTLU.d.ts} +145 -6
- package/dist/{fx-CpqQaIfg.d.ts → fx-QoVA2oBc.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +18 -3
- package/dist/internal/caller.d.ts +12 -8
- package/dist/internal/caller.js +3 -3
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +9 -9
- package/dist/{job-store-CgXT79tS.d.ts → job-store-Dy-ogco6.d.ts} +1 -1
- package/dist/{lightning-backend-B1hRUIOb.d.ts → lightning-backend-B2wMBR-x.d.ts} +1 -1
- package/dist/{memory-credit-ledger-ME6FH462.js → memory-credit-ledger-N4PZKTT5.js} +3 -3
- package/dist/server/index.d.ts +10 -10
- package/dist/server/index.js +10 -10
- package/dist/{step-cache-Bezn-_ZL.d.ts → step-cache-B83Y9T9p.d.ts} +73 -9
- package/dist/{tempo-session-store-EWBE5HJM.js → tempo-session-store-XJE6GIXN.js} +2 -2
- package/dist/testing/index.d.ts +3 -3
- package/dist/{usd-CJwU3-A4.d.ts → usd-g9kCw86F.d.ts} +1 -1
- package/dist/{x402-HVCUEWWU.js → x402-XLFD43RF.js} +4 -4
- package/package.json +1 -1
|
@@ -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(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
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
|
|
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 ||
|
|
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,
|