@dvmkit/sdk 0.1.0-rc.3 → 0.1.0-rc.4
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-FT7IM66W.js → chunk-2K6UXDAN.js} +1 -1
- package/dist/{chunk-C2DC4FKR.js → chunk-4UVRXDNY.js} +330 -9
- package/dist/{chunk-XY5Y5REG.js → chunk-AAJNGQMC.js} +1 -1
- package/dist/{chunk-YD3TZNXV.js → chunk-EDU6COY2.js} +17 -2
- package/dist/{chunk-5SO7ZVOH.js → chunk-F2L6KIMD.js} +5 -0
- package/dist/{chunk-RHP3BRTH.js → chunk-GJD7PVWY.js} +3 -3
- package/dist/{credit-menu-DONAtGVf.d.ts → credit-menu-ClA1JyYW.d.ts} +2 -2
- package/dist/{fx-Bq4cvn16.d.ts → fx-ptKVFOwq.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/internal/index.d.ts +158 -7
- package/dist/internal/index.js +34 -6
- package/dist/{job-store-m2pYmvbr.d.ts → job-store-DxFqDPYq.d.ts} +6 -1
- package/dist/server/index.d.ts +5 -5
- package/dist/server/index.js +5 -213
- package/dist/testing/index.d.ts +1 -1
- package/dist/{usd-DjVAPMlf.d.ts → usd-Cha_j80I.d.ts} +1 -1
- package/dist/{x402-5EVIUSEP.js → x402-XXFQQAAD.js} +4 -4
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
CreditEnvelopeError,
|
|
21
21
|
DEFAULT_LOCK_PUBKEY_GRACE_SECONDS,
|
|
22
22
|
DVM_PROTOCOL_VERSION,
|
|
23
|
+
HttpTransport,
|
|
23
24
|
JobManager,
|
|
24
25
|
MemoryConsumedCredentialStore,
|
|
25
26
|
MemoryX402ExactSettlementStore,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
NwcError,
|
|
28
29
|
PostgresX402ExactSettlementStore,
|
|
29
30
|
REQUEST_ID_FIELD,
|
|
31
|
+
SpanWriter,
|
|
30
32
|
X402ExactIntentConflictError,
|
|
31
33
|
X402ExactSettlementEvidenceMissingError,
|
|
32
34
|
X402ExactSettlementNotReadyError,
|
|
@@ -71,17 +73,17 @@ import {
|
|
|
71
73
|
unknownRouteNotFound,
|
|
72
74
|
validateX402Env,
|
|
73
75
|
withNwcPool
|
|
74
|
-
} from "../chunk-
|
|
76
|
+
} from "../chunk-4UVRXDNY.js";
|
|
75
77
|
import {
|
|
76
78
|
X402_DEFAULT_FACILITATOR,
|
|
77
79
|
X402_DEFAULT_NETWORK,
|
|
78
80
|
assertSupportedX402Network,
|
|
79
81
|
x402NetworkToCaip2
|
|
80
|
-
} from "../chunk-
|
|
82
|
+
} from "../chunk-AAJNGQMC.js";
|
|
81
83
|
import {
|
|
82
84
|
IMPLICIT_CREDIT_TTL_MS,
|
|
83
85
|
resolveRpcOverride
|
|
84
|
-
} from "../chunk-
|
|
86
|
+
} from "../chunk-F2L6KIMD.js";
|
|
85
87
|
import {
|
|
86
88
|
MemoryCreditLedger
|
|
87
89
|
} from "../chunk-EXHBXA4U.js";
|
|
@@ -218,216 +220,6 @@ function isTestMintUrl(url) {
|
|
|
218
220
|
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1"]);
|
|
219
221
|
var TEST_MINT_HOSTS = /* @__PURE__ */ new Set(["testnut.cashu.space"]);
|
|
220
222
|
|
|
221
|
-
// src/observability/span-writer.ts
|
|
222
|
-
var noop = () => {
|
|
223
|
-
};
|
|
224
|
-
var MAX_BUFFERED_SPANS = 1e4;
|
|
225
|
-
var MAX_ROW_JSONB_BYTES = 64 * 1024;
|
|
226
|
-
var MAX_STRING_VALUE_BYTES = 4 * 1024;
|
|
227
|
-
var FLUSH_THRESHOLD = 1e3;
|
|
228
|
-
var MAX_BACKOFF_EXPONENT = 6;
|
|
229
|
-
var SpanWriter = class {
|
|
230
|
-
constructor(transport, flushIntervalMs = 1e4) {
|
|
231
|
-
this.transport = transport;
|
|
232
|
-
this.flushIntervalMs = flushIntervalMs;
|
|
233
|
-
}
|
|
234
|
-
transport;
|
|
235
|
-
flushIntervalMs;
|
|
236
|
-
buffer = [];
|
|
237
|
-
flushTimer = null;
|
|
238
|
-
flushing = false;
|
|
239
|
-
dropCount = 0;
|
|
240
|
-
truncatedSpanCount = 0;
|
|
241
|
-
consecutiveFailures = 0;
|
|
242
|
-
backoffTimer = null;
|
|
243
|
-
/** Enqueue a span row. Non-blocking — truncates oversize JSONB and appends to buffer. */
|
|
244
|
-
enqueue(row) {
|
|
245
|
-
const originalBytes = JSON.stringify({
|
|
246
|
-
attributes: row.attributes,
|
|
247
|
-
dimensions: row.dimensions
|
|
248
|
-
}).length;
|
|
249
|
-
if (originalBytes > MAX_ROW_JSONB_BYTES) {
|
|
250
|
-
row = this.truncateForSize(row, originalBytes);
|
|
251
|
-
}
|
|
252
|
-
if (this.buffer.length >= MAX_BUFFERED_SPANS) {
|
|
253
|
-
this.dropCount++;
|
|
254
|
-
if (this.dropCount === 1 || this.dropCount % 1e3 === 0) {
|
|
255
|
-
console.error(
|
|
256
|
-
JSON.stringify({
|
|
257
|
-
event: "span_buffer_drop",
|
|
258
|
-
reason: "buffer_full",
|
|
259
|
-
total_dropped: this.dropCount,
|
|
260
|
-
buffer_size: this.buffer.length
|
|
261
|
-
})
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
this.buffer.push(row);
|
|
267
|
-
if (this.buffer.length >= FLUSH_THRESHOLD && !this.flushing) {
|
|
268
|
-
void this.flush().catch(noop);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
/** Start periodic flush to the transport. */
|
|
272
|
-
startFlush() {
|
|
273
|
-
this.flushTimer = setInterval(() => {
|
|
274
|
-
void this.flush().catch(noop);
|
|
275
|
-
}, this.flushIntervalMs);
|
|
276
|
-
}
|
|
277
|
-
/** Stop periodic flush. */
|
|
278
|
-
stopFlush() {
|
|
279
|
-
if (this.flushTimer) {
|
|
280
|
-
clearInterval(this.flushTimer);
|
|
281
|
-
this.flushTimer = null;
|
|
282
|
-
}
|
|
283
|
-
if (this.backoffTimer) {
|
|
284
|
-
clearTimeout(this.backoffTimer);
|
|
285
|
-
this.backoffTimer = null;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
/** Flush buffered spans. Single-flight: concurrent calls exit early. */
|
|
289
|
-
async flush() {
|
|
290
|
-
if (this.flushing) return;
|
|
291
|
-
if (this.buffer.length === 0) return;
|
|
292
|
-
this.flushing = true;
|
|
293
|
-
const batch = this.buffer;
|
|
294
|
-
this.buffer = [];
|
|
295
|
-
try {
|
|
296
|
-
await this.transport.send(batch);
|
|
297
|
-
this.consecutiveFailures = 0;
|
|
298
|
-
} catch (err) {
|
|
299
|
-
this.consecutiveFailures++;
|
|
300
|
-
console.error(
|
|
301
|
-
JSON.stringify({
|
|
302
|
-
event: "span_flush_failed",
|
|
303
|
-
error: err instanceof Error ? err.message : String(err),
|
|
304
|
-
batch_size: batch.length,
|
|
305
|
-
consecutive_failures: this.consecutiveFailures
|
|
306
|
-
})
|
|
307
|
-
);
|
|
308
|
-
const room = MAX_BUFFERED_SPANS - this.buffer.length;
|
|
309
|
-
if (room > 0) {
|
|
310
|
-
this.buffer.unshift(...batch.slice(0, room));
|
|
311
|
-
}
|
|
312
|
-
if (this.consecutiveFailures > 1) {
|
|
313
|
-
const exponent = Math.min(this.consecutiveFailures - 1, MAX_BACKOFF_EXPONENT);
|
|
314
|
-
const backoffMs = this.flushIntervalMs * Math.pow(2, exponent);
|
|
315
|
-
this.stopFlush();
|
|
316
|
-
this.backoffTimer = setTimeout(() => {
|
|
317
|
-
this.backoffTimer = null;
|
|
318
|
-
this.startFlush();
|
|
319
|
-
}, backoffMs);
|
|
320
|
-
}
|
|
321
|
-
} finally {
|
|
322
|
-
this.flushing = false;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/** Flush remaining spans on shutdown. */
|
|
326
|
-
async shutdown() {
|
|
327
|
-
this.stopFlush();
|
|
328
|
-
await this.flush();
|
|
329
|
-
}
|
|
330
|
-
/** Number of spans dropped due to buffer overflow. */
|
|
331
|
-
getDropCount() {
|
|
332
|
-
return this.dropCount;
|
|
333
|
-
}
|
|
334
|
-
/** Number of spans truncated due to oversized JSONB payload. */
|
|
335
|
-
getTruncatedSpanCount() {
|
|
336
|
-
return this.truncatedSpanCount;
|
|
337
|
-
}
|
|
338
|
-
/** Current buffer size. */
|
|
339
|
-
getBufferSize() {
|
|
340
|
-
return this.buffer.length;
|
|
341
|
-
}
|
|
342
|
-
/** Consecutive flush failures; resets to 0 on the next successful flush. */
|
|
343
|
-
getConsecutiveFailures() {
|
|
344
|
-
return this.consecutiveFailures;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Two-pass truncation: cap individual string values, then fall back to
|
|
348
|
-
* wholesale attribute replacement if the blob is still over the limit.
|
|
349
|
-
*/
|
|
350
|
-
truncateForSize(row, originalBytes) {
|
|
351
|
-
const truncatedAttrs = {};
|
|
352
|
-
for (const [key, value] of Object.entries(row.attributes)) {
|
|
353
|
-
if (typeof value === "string" && value.length > MAX_STRING_VALUE_BYTES) {
|
|
354
|
-
const omitted = value.length - MAX_STRING_VALUE_BYTES;
|
|
355
|
-
truncatedAttrs[key] = `${value.slice(0, MAX_STRING_VALUE_BYTES)}\u2026 [truncated, ${omitted} chars omitted]`;
|
|
356
|
-
} else {
|
|
357
|
-
truncatedAttrs[key] = value;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const afterStringPass = JSON.stringify({
|
|
361
|
-
attributes: truncatedAttrs,
|
|
362
|
-
dimensions: row.dimensions
|
|
363
|
-
}).length;
|
|
364
|
-
let mode;
|
|
365
|
-
if (afterStringPass <= MAX_ROW_JSONB_BYTES) {
|
|
366
|
-
row = { ...row, attributes: truncatedAttrs };
|
|
367
|
-
mode = "string_pass";
|
|
368
|
-
} else {
|
|
369
|
-
const dimSize = JSON.stringify(row.dimensions).length;
|
|
370
|
-
if (dimSize > MAX_ROW_JSONB_BYTES) {
|
|
371
|
-
console.error(
|
|
372
|
-
JSON.stringify({
|
|
373
|
-
event: "span_dimension_oversized",
|
|
374
|
-
name: row.name,
|
|
375
|
-
dataset: row.dataset,
|
|
376
|
-
dimension_bytes: dimSize
|
|
377
|
-
})
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
row = {
|
|
381
|
-
...row,
|
|
382
|
-
attributes: {
|
|
383
|
-
_truncated: true,
|
|
384
|
-
original_bytes: originalBytes,
|
|
385
|
-
original_keys: Object.keys(row.attributes).sort()
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
mode = "wholesale_fallback";
|
|
389
|
-
}
|
|
390
|
-
this.truncatedSpanCount++;
|
|
391
|
-
if (this.truncatedSpanCount === 1 || this.truncatedSpanCount % 100 === 0) {
|
|
392
|
-
console.error(
|
|
393
|
-
JSON.stringify({
|
|
394
|
-
event: "span_truncated",
|
|
395
|
-
name: row.name,
|
|
396
|
-
dataset: row.dataset,
|
|
397
|
-
original_bytes: originalBytes,
|
|
398
|
-
after_string_pass_bytes: afterStringPass,
|
|
399
|
-
mode,
|
|
400
|
-
total_truncated: this.truncatedSpanCount
|
|
401
|
-
})
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
return row;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
var HttpTransport = class {
|
|
408
|
-
constructor(platformUrl, serviceToken) {
|
|
409
|
-
this.platformUrl = platformUrl;
|
|
410
|
-
this.serviceToken = serviceToken;
|
|
411
|
-
}
|
|
412
|
-
platformUrl;
|
|
413
|
-
serviceToken;
|
|
414
|
-
async send(rows) {
|
|
415
|
-
if (rows.length === 0) return;
|
|
416
|
-
const resp = await fetch(`${this.platformUrl.replace(/\/$/, "")}/_internal/spans`, {
|
|
417
|
-
method: "POST",
|
|
418
|
-
headers: {
|
|
419
|
-
"Content-Type": "application/json",
|
|
420
|
-
Authorization: `Bearer ${this.serviceToken}`
|
|
421
|
-
},
|
|
422
|
-
body: JSON.stringify({ spans: rows })
|
|
423
|
-
});
|
|
424
|
-
if (!resp.ok) {
|
|
425
|
-
const text = await resp.text().catch(() => "");
|
|
426
|
-
throw new Error(`Span ingestion failed: ${resp.status} ${text}`);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
223
|
// src/sdk/server/lightning-rail-health.ts
|
|
432
224
|
var LIGHTNING_RAIL_HEALTH_REFRESH_TTL_MS = 5 * 60 * 1e3;
|
|
433
225
|
var LIGHTNING_RAIL_HEALTH_MAX_STALENESS_MS = 3 * 60 * 60 * 1e3;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c8 as StreamableJobStore, c9 as ReceiptIssuingStore, J as JobRecord, ca as RequestIdClaim, cb as RequestIdClaimResult, _ as JobReceipt, as as OutgoingMessage, cc as AppendOutgoingOptions, cd as PaymentCreditDelta, ce as VerifyAndCreditResult, cf as JobCounters, a2 as Message, a3 as MessageType, K as KVStore, L as Logger, v as ResponseContent, P as PaymentContent, S as SDKJobContext } from '../job-store-DxFqDPYq.js';
|
|
2
2
|
import '@cashu/cashu-ts';
|
|
3
3
|
import 'mppx';
|
|
4
4
|
import '@x402/core/server';
|
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
tryX402Payment,
|
|
12
12
|
verifyX402Payment,
|
|
13
13
|
x402WrongAssetHint
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-GJD7PVWY.js";
|
|
15
|
+
import "./chunk-2K6UXDAN.js";
|
|
16
16
|
import {
|
|
17
17
|
X402_DEFAULT_FACILITATOR,
|
|
18
18
|
X402_DEFAULT_NETWORK,
|
|
@@ -37,8 +37,8 @@ import {
|
|
|
37
37
|
x402NetworkListForCopy,
|
|
38
38
|
x402NetworkToCaip2,
|
|
39
39
|
x402SupportedNetworksHint
|
|
40
|
-
} from "./chunk-
|
|
41
|
-
import "./chunk-
|
|
40
|
+
} from "./chunk-AAJNGQMC.js";
|
|
41
|
+
import "./chunk-F2L6KIMD.js";
|
|
42
42
|
import "./chunk-66HGCPBU.js";
|
|
43
43
|
import "./chunk-FUJ36YDV.js";
|
|
44
44
|
import "./chunk-AT6V3SY7.js";
|