@dvmkit/dvm-cli 0.4.1 → 0.5.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/README.md +8 -0
- package/dist/{chunk-24VB7FR7.js → chunk-3YE43JJR.js} +4 -4
- package/dist/{chunk-SKKZ4OAA.js → chunk-4KINCBHL.js} +53 -56
- package/dist/{chunk-XN4YSEO6.js → chunk-EE2MREOM.js} +152 -93
- package/dist/chunk-ERJFRCJO.js +150 -0
- package/dist/chunk-FL2ICZW5.js +383 -0
- package/dist/chunk-FSYEZERJ.js +1667 -0
- package/dist/{chunk-V2BE4E5V.js → chunk-ID5G54HJ.js} +223 -73
- package/dist/{chunk-4NWEJTAW.js → chunk-MJ4X4BEW.js} +7953 -8036
- package/dist/{chunk-Z75N4GTG.js → chunk-QICJRKB7.js} +23557 -16012
- package/dist/{chunk-ECEM3ZAS.js → chunk-R55XNXAR.js} +53 -185
- package/dist/{chunk-R4MSO2GX.js → chunk-SHZMNEXE.js} +65 -24
- package/dist/chunk-TZWZTS37.js +1517 -0
- package/dist/{chunk-VY277ROG.js → chunk-VOO5IAK7.js} +600 -97
- package/dist/{chunk-2VVVWBQA.js → chunk-WTM2EICO.js} +2 -352
- package/dist/chunk-XHOFQ3OS.js +717 -0
- package/dist/{chunk-YLWATJ7F.js → chunk-Z4CZUMUT.js} +937 -1599
- package/dist/{client-OWIOFBKS.js → client-RYDA62DU.js} +11 -8
- package/dist/{dist-2G3QBGID.js → dist-GKCEIY2A.js} +7 -4
- package/dist/dvm.js +478 -70
- package/dist/{internal-OBEYRHMV.js → internal-INUTGTXQ.js} +56 -33
- package/dist/{payout-reporter-RG6XNGPI-KNY74HLM.js → payout-reporter-3Y2U55ZX-CMKACKA3.js} +2 -2
- package/dist/{pocket-refill-NXTJIVB5.js → pocket-refill-K5T4LZF6.js} +18 -14
- package/dist/{revenue-reporter-ASZ7SHHH-ISAMJDZQ.js → revenue-reporter-MAERPYGK-CCPZXGFA.js} +2 -2
- package/dist/tempo-AXTE4ZEA.js +34 -0
- package/dist/{tempo-lifecycle-DFIXQ54Q-LNXPKWK5.js → tempo-lifecycle-ZBBLFBMH-HWI4PLYP.js} +11 -7
- package/dist/{tempo-wallet-4QKSV65O-J6ZZQAD7.js → tempo-wallet-B5XXV3YH-SRQBMYFV.js} +2 -2
- package/dist/{x402-5H27DCBE-UEQQQ5UY.js → x402-R6HPBY5D-VMSW7Z32.js} +3 -3
- package/package.json +2 -2
- package/skills/dvm/calling.md +2 -0
- package/skills/dvm/credit.md +2 -0
- package/dist/chunk-3SWX5BQP.js +0 -66
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
|
+
diagnosticConsole,
|
|
5
6
|
withSdkInitLock
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TZWZTS37.js";
|
|
7
8
|
|
|
8
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
9
|
+
// node_modules/@dvmkit/sdk/dist/chunk-Z4ZT5LNT.js
|
|
9
10
|
import { randomUUID } from "crypto";
|
|
10
11
|
var ENDPOINTS = {
|
|
12
|
+
job_terminal: "/_internal/job-terminal",
|
|
11
13
|
revenue: "/_internal/job-revenue",
|
|
12
14
|
cost: "/_internal/job-cost",
|
|
13
15
|
deposit: "/_internal/credit-deposit",
|
|
@@ -37,14 +39,16 @@ var PLATFORM_REPORT_TABLE_COLUMNS = [
|
|
|
37
39
|
];
|
|
38
40
|
var RevenueReporter = class _RevenueReporter {
|
|
39
41
|
// 24h of failed retries
|
|
40
|
-
constructor(db, platformUrl, platformToken) {
|
|
42
|
+
constructor(db, platformUrl, platformToken, hostedObligations) {
|
|
41
43
|
this.db = db;
|
|
42
44
|
this.platformUrl = platformUrl;
|
|
43
45
|
this.platformToken = platformToken;
|
|
46
|
+
this.hostedObligations = hostedObligations;
|
|
44
47
|
}
|
|
45
48
|
db;
|
|
46
49
|
platformUrl;
|
|
47
50
|
platformToken;
|
|
51
|
+
hostedObligations;
|
|
48
52
|
retryTimer = null;
|
|
49
53
|
static RETRY_INTERVAL_MS = 3e4;
|
|
50
54
|
static MAX_BACKOFF_MS = 3e5;
|
|
@@ -54,7 +58,6 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
54
58
|
async init() {
|
|
55
59
|
await withSdkInitLock(this.db, () => this.createTables());
|
|
56
60
|
}
|
|
57
|
-
/** The boot DDL itself — always runs under {@link withSdkInitLock} (internal-review). */
|
|
58
61
|
async createTables() {
|
|
59
62
|
await this.db.query(`
|
|
60
63
|
CREATE TABLE IF NOT EXISTS ${PENDING_DVM_REPORTS_TABLE} (
|
|
@@ -68,6 +71,10 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
68
71
|
kind TEXT NOT NULL DEFAULT 'revenue'
|
|
69
72
|
)
|
|
70
73
|
`);
|
|
74
|
+
await this.db.query(`CREATE TABLE IF NOT EXISTS reported_job_terminals (
|
|
75
|
+
dvm_id TEXT NOT NULL, job_id TEXT NOT NULL, created_at BIGINT NOT NULL,
|
|
76
|
+
PRIMARY KEY (dvm_id, job_id)
|
|
77
|
+
)`);
|
|
71
78
|
await this.assertSdkTableShape(PENDING_DVM_REPORTS_TABLE);
|
|
72
79
|
await this.db.query(
|
|
73
80
|
`ALTER TABLE ${PENDING_DVM_REPORTS_TABLE} ADD COLUMN IF NOT EXISTS stale_reason TEXT`
|
|
@@ -77,7 +84,6 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
77
84
|
);
|
|
78
85
|
await this.migrateLegacySdkOutbox();
|
|
79
86
|
}
|
|
80
|
-
/** Copy rows from the old SDK-owned table without touching the platform's table of that name. */
|
|
81
87
|
async migrateLegacySdkOutbox() {
|
|
82
88
|
const columns = await this.tableColumns(LEGACY_PENDING_REPORTS_TABLE);
|
|
83
89
|
if (columns.size === 0) return;
|
|
@@ -109,7 +115,6 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
109
115
|
)
|
|
110
116
|
`);
|
|
111
117
|
}
|
|
112
|
-
/** Refuse a pre-existing relation whose columns cannot safely serve as the SDK outbox. */
|
|
113
118
|
async assertSdkTableShape(tableName) {
|
|
114
119
|
this.assertSdkColumns(tableName, await this.tableColumns(tableName));
|
|
115
120
|
}
|
|
@@ -133,6 +138,21 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
133
138
|
async report(payload) {
|
|
134
139
|
return this.enqueue("revenue", payload, payload.jobId);
|
|
135
140
|
}
|
|
141
|
+
/** The permanent deduplication claim and outbox insert commit together.
|
|
142
|
+
* The claim survives successful delivery, including for custom job stores.
|
|
143
|
+
*/
|
|
144
|
+
async reportTerminal(payload) {
|
|
145
|
+
const id = randomUUID();
|
|
146
|
+
const { rowCount } = await this.db.query(
|
|
147
|
+
`WITH claimed AS (
|
|
148
|
+
INSERT INTO reported_job_terminals (dvm_id, job_id, created_at)
|
|
149
|
+
VALUES ($5, $1, $4) ON CONFLICT DO NOTHING RETURNING job_id
|
|
150
|
+
) INSERT INTO ${PENDING_DVM_REPORTS_TABLE} (id, payload, created_at, kind)
|
|
151
|
+
SELECT $2, $3::jsonb, $4, 'job_terminal' FROM claimed`,
|
|
152
|
+
[payload.jobId, id, JSON.stringify(payload), Date.now(), payload.dvmId]
|
|
153
|
+
);
|
|
154
|
+
if (rowCount) void this.attemptDelivery(id, payload, "job_terminal", payload.jobId).catch(() => void 0);
|
|
155
|
+
}
|
|
136
156
|
/** Persist a zero-revenue job cost and attempt immediate delivery. */
|
|
137
157
|
async reportCost(payload) {
|
|
138
158
|
return this.enqueue("cost", payload, payload.jobId);
|
|
@@ -152,23 +172,15 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
152
172
|
await this.insertPending(tx, "release", payload);
|
|
153
173
|
}
|
|
154
174
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* Same discipline as {@link enqueueDeposit} and the same reason: no network
|
|
158
|
-
* I/O here, only the durable queue row, written through `tx` so the report
|
|
159
|
-
* and the status CAS commit or roll back together. A drain whose row was
|
|
160
|
-
* lost between the two would overstate outstanding liability forever —
|
|
161
|
-
* the mirror image of a lost deposit.
|
|
162
|
-
*
|
|
163
|
-
* Named for the payload rather than the verb because `drain` already means
|
|
164
|
-
* "flush the queue" in this class (see {@link drainPending}).
|
|
175
|
+
* Await durable queue insertion through tx so the terminal drain and its
|
|
176
|
+
* report commit or roll back together; no network I/O here.
|
|
165
177
|
*/
|
|
166
178
|
async enqueueCreditDrain(tx, payload) {
|
|
167
179
|
await this.insertPending(tx, "drain", payload);
|
|
168
180
|
}
|
|
169
181
|
/**
|
|
170
182
|
* Join a payout to the transaction that commits the movement it reports
|
|
171
|
-
*
|
|
183
|
+
* the batch close, the accumulator mark, the drain booking.
|
|
172
184
|
* No network I/O, only the durable queue row through `tx`, the discipline
|
|
173
185
|
* {@link enqueueCreditDrain} set and for the same reason: the money has
|
|
174
186
|
* already moved on a rail this ledger does not own, so the platform row is
|
|
@@ -179,8 +191,44 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
179
191
|
* loop redelivers freely.
|
|
180
192
|
*/
|
|
181
193
|
async enqueuePayout(payload, tx) {
|
|
194
|
+
if (this.hostedObligations && (payload.rail === "x402" || payload.rail === "tempo") && await this.hostedObligations.hasCompleteHistory(tx ?? this.db)) {
|
|
195
|
+
throw new Error("Hosted channel payout requires its original settlement obligation");
|
|
196
|
+
}
|
|
182
197
|
await this.insertPending(tx ?? this.db, "payout", payload);
|
|
183
198
|
}
|
|
199
|
+
async enqueueHostedPayout(payload, obligationIds, tx) {
|
|
200
|
+
if (!this.hostedObligations || payload.rail !== "x402" && payload.rail !== "tempo") {
|
|
201
|
+
throw new Error("Hosted channel payout has no managed obligation recorder");
|
|
202
|
+
}
|
|
203
|
+
const enqueue = async (query) => {
|
|
204
|
+
if (await this.hostedObligations.hasOriginalReport(
|
|
205
|
+
obligationIds,
|
|
206
|
+
payload.payoutId,
|
|
207
|
+
payload,
|
|
208
|
+
query
|
|
209
|
+
)) return;
|
|
210
|
+
const reportId = await this.insertPending(query, "payout", payload);
|
|
211
|
+
await this.hostedObligations.queueReport(
|
|
212
|
+
obligationIds,
|
|
213
|
+
payload.payoutId,
|
|
214
|
+
reportId,
|
|
215
|
+
payload,
|
|
216
|
+
query
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
if (tx) return enqueue(tx);
|
|
220
|
+
const client = await this.db.connect();
|
|
221
|
+
try {
|
|
222
|
+
await client.query("BEGIN");
|
|
223
|
+
await enqueue(client);
|
|
224
|
+
await client.query("COMMIT");
|
|
225
|
+
} catch (error) {
|
|
226
|
+
await client.query("ROLLBACK").catch(() => void 0);
|
|
227
|
+
throw error;
|
|
228
|
+
} finally {
|
|
229
|
+
client.release();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
184
232
|
/**
|
|
185
233
|
* Report one landed payout on its own and try to deliver it at once — the
|
|
186
234
|
* live Tempo settlement, which has no dvmkit transaction to join. Durable
|
|
@@ -190,7 +238,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
190
238
|
return this.enqueue("payout", payload, payload.payoutId);
|
|
191
239
|
}
|
|
192
240
|
/**
|
|
193
|
-
* Report one rail's pending-pool snapshot
|
|
241
|
+
* Report one rail's pending-pool snapshot. Best-effort and
|
|
194
242
|
* fire-and-forget, deliberately unlike {@link reportPayout}: a snapshot is
|
|
195
243
|
* replaced by the next tick, so queueing a stale one behind an outage would
|
|
196
244
|
* only deliver figures the platform already has newer ones for.
|
|
@@ -208,39 +256,33 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
208
256
|
signal: AbortSignal.timeout(1e4)
|
|
209
257
|
});
|
|
210
258
|
if (!res.ok) {
|
|
211
|
-
|
|
212
|
-
|
|
259
|
+
diagnosticConsole.warn(
|
|
260
|
+
{
|
|
213
261
|
level: "payout_pending_report_failed",
|
|
214
262
|
rail: payload.rail,
|
|
215
263
|
status: res.status
|
|
216
|
-
}
|
|
264
|
+
}
|
|
217
265
|
);
|
|
218
266
|
}
|
|
219
|
-
} catch (
|
|
220
|
-
|
|
221
|
-
|
|
267
|
+
} catch (_err) {
|
|
268
|
+
diagnosticConsole.warn(
|
|
269
|
+
{
|
|
222
270
|
level: "payout_pending_report_failed",
|
|
223
271
|
rail: payload.rail,
|
|
224
|
-
error:
|
|
225
|
-
}
|
|
272
|
+
error: void 0
|
|
273
|
+
}
|
|
226
274
|
);
|
|
227
275
|
}
|
|
228
276
|
}
|
|
229
277
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* Same discipline as {@link enqueueCreditDrain}: no network I/O, only the
|
|
234
|
-
* durable queue row written through `tx`. A release whose row was lost after
|
|
235
|
-
* the sweep committed would understate committed value forever; a lost
|
|
236
|
-
* reversal would overstate it, which is the worse direction — the builder
|
|
237
|
-
* would see money as theirs that a revived credit can still buy work with.
|
|
278
|
+
* Await durable queue insertion through tx so expiry release or reversal and
|
|
279
|
+
* its report commit together. A missing reversal would overstate builder value.
|
|
238
280
|
*/
|
|
239
281
|
async enqueueCreditExpiryRelease(tx, payload) {
|
|
240
282
|
await this.insertPending(tx, "expiry_release", payload);
|
|
241
283
|
}
|
|
242
284
|
/**
|
|
243
|
-
* Report a reaper-force-failed paid job to the platform
|
|
285
|
+
* Report a reaper-force-failed paid job to the platform so the
|
|
244
286
|
* operator receives an ambient notice that a DVM died or wedged mid-job.
|
|
245
287
|
* Best-effort and fire-and-forget: unlike {@link report} there is no local
|
|
246
288
|
* durable queue — a non-2xx or transport failure is structured-logged
|
|
@@ -261,26 +303,26 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
261
303
|
signal: AbortSignal.timeout(1e4)
|
|
262
304
|
});
|
|
263
305
|
if (!res.ok) {
|
|
264
|
-
|
|
265
|
-
|
|
306
|
+
diagnosticConsole.warn(
|
|
307
|
+
{
|
|
266
308
|
level: "paid_job_death_report_failed",
|
|
267
309
|
jobId: payload.jobId,
|
|
268
310
|
status: res.status
|
|
269
|
-
}
|
|
311
|
+
}
|
|
270
312
|
);
|
|
271
313
|
}
|
|
272
|
-
} catch (
|
|
273
|
-
|
|
274
|
-
|
|
314
|
+
} catch (_err) {
|
|
315
|
+
diagnosticConsole.warn(
|
|
316
|
+
{
|
|
275
317
|
level: "paid_job_death_report_failed",
|
|
276
318
|
jobId: payload.jobId,
|
|
277
|
-
error:
|
|
278
|
-
}
|
|
319
|
+
error: void 0
|
|
320
|
+
}
|
|
279
321
|
);
|
|
280
322
|
}
|
|
281
323
|
}
|
|
282
324
|
/**
|
|
283
|
-
* Report a settled draw whose revenue event was skipped
|
|
325
|
+
* Report a settled draw whose revenue event was skipped.
|
|
284
326
|
* Best-effort and fire-and-forget: the SDK's structured
|
|
285
327
|
* `revenue_skipped_no_rail` log is the durable backstop, so a failed notice
|
|
286
328
|
* must never wedge terminal handling or the orphan-draw reconciler.
|
|
@@ -298,29 +340,28 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
298
340
|
signal: AbortSignal.timeout(1e4)
|
|
299
341
|
});
|
|
300
342
|
if (!res.ok) {
|
|
301
|
-
|
|
302
|
-
|
|
343
|
+
diagnosticConsole.warn(
|
|
344
|
+
{
|
|
303
345
|
level: "revenue_skipped_no_rail_report_failed",
|
|
304
346
|
jobId: payload.jobId,
|
|
305
347
|
drawId: payload.drawId,
|
|
306
348
|
reason: payload.reason,
|
|
307
349
|
status: res.status
|
|
308
|
-
}
|
|
350
|
+
}
|
|
309
351
|
);
|
|
310
352
|
}
|
|
311
|
-
} catch (
|
|
312
|
-
|
|
313
|
-
|
|
353
|
+
} catch (_err) {
|
|
354
|
+
diagnosticConsole.warn(
|
|
355
|
+
{
|
|
314
356
|
level: "revenue_skipped_no_rail_report_failed",
|
|
315
357
|
jobId: payload.jobId,
|
|
316
358
|
drawId: payload.drawId,
|
|
317
359
|
reason: payload.reason,
|
|
318
|
-
error:
|
|
319
|
-
}
|
|
360
|
+
error: void 0
|
|
361
|
+
}
|
|
320
362
|
);
|
|
321
363
|
}
|
|
322
364
|
}
|
|
323
|
-
/** Report the self-relay's Base gas gauge for platform-side paging and recovery. */
|
|
324
365
|
async reportX402SelfRelayGasBalance(payload) {
|
|
325
366
|
const url = `${this.platformUrl}/_internal/x402-self-relay-gas-balance`;
|
|
326
367
|
try {
|
|
@@ -334,25 +375,24 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
334
375
|
signal: AbortSignal.timeout(1e4)
|
|
335
376
|
});
|
|
336
377
|
if (!res.ok) {
|
|
337
|
-
|
|
338
|
-
|
|
378
|
+
diagnosticConsole.warn(
|
|
379
|
+
{
|
|
339
380
|
level: "x402_self_relay_gas_balance_report_failed",
|
|
340
381
|
address: payload.address,
|
|
341
382
|
status: res.status
|
|
342
|
-
}
|
|
383
|
+
}
|
|
343
384
|
);
|
|
344
385
|
}
|
|
345
|
-
} catch (
|
|
346
|
-
|
|
347
|
-
|
|
386
|
+
} catch (_err) {
|
|
387
|
+
diagnosticConsole.warn(
|
|
388
|
+
{
|
|
348
389
|
level: "x402_self_relay_gas_balance_report_failed",
|
|
349
390
|
address: payload.address,
|
|
350
|
-
error:
|
|
351
|
-
}
|
|
391
|
+
error: void 0
|
|
392
|
+
}
|
|
352
393
|
);
|
|
353
394
|
}
|
|
354
395
|
}
|
|
355
|
-
/** Report redacted self-relay RPC health for platform-side paging and recovery. */
|
|
356
396
|
async reportX402SelfRelayRpcHealth(payload) {
|
|
357
397
|
const url = `${this.platformUrl}/_internal/x402-self-relay-rpc-health`;
|
|
358
398
|
try {
|
|
@@ -366,29 +406,27 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
366
406
|
signal: AbortSignal.timeout(1e4)
|
|
367
407
|
});
|
|
368
408
|
if (!res.ok) {
|
|
369
|
-
|
|
370
|
-
|
|
409
|
+
diagnosticConsole.warn(
|
|
410
|
+
{
|
|
371
411
|
level: "x402_self_relay_rpc_health_report_failed",
|
|
372
412
|
address: payload.address,
|
|
373
413
|
status: res.status
|
|
374
|
-
}
|
|
414
|
+
}
|
|
375
415
|
);
|
|
376
416
|
}
|
|
377
417
|
} catch {
|
|
378
|
-
|
|
379
|
-
|
|
418
|
+
diagnosticConsole.warn(
|
|
419
|
+
{
|
|
380
420
|
level: "x402_self_relay_rpc_health_report_failed",
|
|
381
421
|
address: payload.address,
|
|
382
422
|
reason: "transport"
|
|
383
|
-
}
|
|
423
|
+
}
|
|
384
424
|
);
|
|
385
425
|
}
|
|
386
426
|
}
|
|
387
|
-
/** Report the Tempo operator's fee-token gauge for paging and recovery. */
|
|
388
427
|
async reportTempoSettlementBalance(payload) {
|
|
389
428
|
await this.postTempoSettlementReadiness("balance", payload);
|
|
390
429
|
}
|
|
391
|
-
/** Report a redacted operator fee rejection immediately. */
|
|
392
430
|
async reportTempoSettlementFailure(payload) {
|
|
393
431
|
await this.postTempoSettlementReadiness("failure", payload);
|
|
394
432
|
}
|
|
@@ -405,34 +443,32 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
405
443
|
signal: AbortSignal.timeout(1e4)
|
|
406
444
|
});
|
|
407
445
|
if (!res.ok) {
|
|
408
|
-
|
|
409
|
-
|
|
446
|
+
diagnosticConsole.warn(
|
|
447
|
+
{
|
|
410
448
|
level: "tempo_settlement_readiness_report_failed",
|
|
411
449
|
kind,
|
|
412
450
|
address: payload.address,
|
|
413
451
|
status: res.status
|
|
414
|
-
}
|
|
452
|
+
}
|
|
415
453
|
);
|
|
416
454
|
}
|
|
417
455
|
} catch {
|
|
418
|
-
|
|
419
|
-
|
|
456
|
+
diagnosticConsole.warn(
|
|
457
|
+
{
|
|
420
458
|
level: "tempo_settlement_readiness_report_failed",
|
|
421
459
|
kind,
|
|
422
460
|
address: payload.address,
|
|
423
461
|
reason: "transport"
|
|
424
|
-
}
|
|
462
|
+
}
|
|
425
463
|
);
|
|
426
464
|
}
|
|
427
465
|
}
|
|
428
|
-
/** Start the background retry loop. */
|
|
429
466
|
startRetryLoop() {
|
|
430
467
|
if (this.retryTimer) return;
|
|
431
468
|
this.retryTimer = setInterval(() => {
|
|
432
469
|
void this.drainPending();
|
|
433
470
|
}, _RevenueReporter.RETRY_INTERVAL_MS);
|
|
434
471
|
}
|
|
435
|
-
/** Stop the background retry loop. */
|
|
436
472
|
stop() {
|
|
437
473
|
if (this.retryTimer) {
|
|
438
474
|
clearInterval(this.retryTimer);
|
|
@@ -469,8 +505,8 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
469
505
|
/**
|
|
470
506
|
* Deliver one bounded batch from the durable queue.
|
|
471
507
|
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
508
|
+
* Processes due, non-stale rows; failures back off up to five minutes and
|
|
509
|
+
* become terminal after 24 hours. Successful deliveries remove their rows.
|
|
474
510
|
*/
|
|
475
511
|
async drainPending() {
|
|
476
512
|
try {
|
|
@@ -488,8 +524,8 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
488
524
|
const retryCount = row.retry_count + 1;
|
|
489
525
|
if (Date.now() - Number(row.created_at) >= _RevenueReporter.ABANDON_AFTER_MS) {
|
|
490
526
|
await this.markStale(row.id, "abandoned");
|
|
491
|
-
|
|
492
|
-
|
|
527
|
+
diagnosticConsole.warn(
|
|
528
|
+
{
|
|
493
529
|
level: "revenue_reporter_abandoned",
|
|
494
530
|
id: row.id,
|
|
495
531
|
kind: row.kind,
|
|
@@ -500,7 +536,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
500
536
|
// carries `rail`. An abandoned row is the one place an
|
|
501
537
|
// operator sees this payload at all, so don't log it blank.
|
|
502
538
|
rail: row.payload.rail ?? row.payload.method
|
|
503
|
-
}
|
|
539
|
+
}
|
|
504
540
|
);
|
|
505
541
|
continue;
|
|
506
542
|
}
|
|
@@ -517,16 +553,20 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
517
553
|
}
|
|
518
554
|
}
|
|
519
555
|
} catch (err) {
|
|
520
|
-
|
|
556
|
+
diagnosticConsole.error("[revenue-reporter] Retry loop error:", err);
|
|
521
557
|
}
|
|
522
558
|
}
|
|
523
|
-
/** Durably queue one report of either kind, then try it once immediately. */
|
|
524
559
|
async enqueue(kind, payload, label) {
|
|
560
|
+
if (kind === "payout" && this.hostedObligations) {
|
|
561
|
+
const rail = payload.rail;
|
|
562
|
+
if ((rail === "x402" || rail === "tempo") && await this.hostedObligations.hasCompleteHistory()) {
|
|
563
|
+
throw new Error("Hosted channel payout requires its original settlement obligation");
|
|
564
|
+
}
|
|
565
|
+
}
|
|
525
566
|
const id = await this.insertPending(this.db, kind, payload);
|
|
526
567
|
void this.attemptDelivery(id, payload, kind, label).catch(() => {
|
|
527
568
|
});
|
|
528
569
|
}
|
|
529
|
-
/** Insert one pending report through either the pool or an open transaction. */
|
|
530
570
|
async insertPending(q, kind, payload) {
|
|
531
571
|
const id = randomUUID();
|
|
532
572
|
await q.query(
|
|
@@ -537,6 +577,9 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
537
577
|
return id;
|
|
538
578
|
}
|
|
539
579
|
async attemptDelivery(id, payload, kind, label) {
|
|
580
|
+
if (kind === "payout" && this.hostedObligations && (payload.rail === "x402" || payload.rail === "tempo")) {
|
|
581
|
+
await this.hostedObligations.assertReportReady(id, payload);
|
|
582
|
+
}
|
|
540
583
|
const url = `${this.platformUrl}${ENDPOINTS[kind]}`;
|
|
541
584
|
let res;
|
|
542
585
|
try {
|
|
@@ -551,34 +594,50 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
551
594
|
});
|
|
552
595
|
} catch (err) {
|
|
553
596
|
const reason = err instanceof Error ? err.message : String(err);
|
|
554
|
-
|
|
597
|
+
diagnosticConsole.warn(
|
|
555
598
|
`[revenue-reporter] delivery failed for ${id}: transport error (${reason}) \u2014 will retry`
|
|
556
599
|
);
|
|
557
600
|
throw err;
|
|
558
601
|
}
|
|
559
602
|
if (res.ok) {
|
|
560
|
-
|
|
561
|
-
|
|
603
|
+
if (this.hostedObligations && kind === "payout") {
|
|
604
|
+
const client = await this.db.connect();
|
|
605
|
+
try {
|
|
606
|
+
await client.query("BEGIN");
|
|
607
|
+
const rail = payload.rail;
|
|
608
|
+
const requireLinked = (rail === "x402" || rail === "tempo") && await this.hostedObligations.hasCompleteHistory(client);
|
|
609
|
+
await this.hostedObligations.acknowledgeDelivered(id, client, requireLinked);
|
|
610
|
+
await client.query(`DELETE FROM ${PENDING_DVM_REPORTS_TABLE} WHERE id = $1`, [id]);
|
|
611
|
+
await client.query("COMMIT");
|
|
612
|
+
} catch (error) {
|
|
613
|
+
await client.query("ROLLBACK").catch(() => void 0);
|
|
614
|
+
throw error;
|
|
615
|
+
} finally {
|
|
616
|
+
client.release();
|
|
617
|
+
}
|
|
618
|
+
} else {
|
|
619
|
+
await this.db.query(`DELETE FROM ${PENDING_DVM_REPORTS_TABLE} WHERE id = $1`, [id]);
|
|
620
|
+
}
|
|
621
|
+
diagnosticConsole.log(`[revenue-reporter] reported ${kind} ${label}`);
|
|
562
622
|
return;
|
|
563
623
|
}
|
|
564
624
|
if (res.status === 401) {
|
|
565
625
|
await this.markStale(id, "token_rotated");
|
|
566
|
-
|
|
626
|
+
diagnosticConsole.warn(
|
|
567
627
|
`[revenue-reporter] Report ${id} got 401 \u2014 marking stale (token likely rotated)`
|
|
568
628
|
);
|
|
569
629
|
return;
|
|
570
630
|
}
|
|
571
631
|
if (res.status >= 400 && res.status < 500) {
|
|
572
632
|
await this.markStale(id, `client_error:${res.status}`);
|
|
573
|
-
|
|
633
|
+
diagnosticConsole.warn(
|
|
574
634
|
`[revenue-reporter] Report ${id} got HTTP ${res.status} \u2014 marking stale (permanent client error, will not retry)`
|
|
575
635
|
);
|
|
576
636
|
return;
|
|
577
637
|
}
|
|
578
|
-
|
|
638
|
+
diagnosticConsole.warn(`[revenue-reporter] delivery failed for ${id}: HTTP ${res.status} \u2014 will retry`);
|
|
579
639
|
throw new Error(`Platform returned ${res.status}`);
|
|
580
640
|
}
|
|
581
|
-
/** Mark a pending row terminal (stale) with a classification reason. */
|
|
582
641
|
async markStale(id, reason) {
|
|
583
642
|
await this.db.query(
|
|
584
643
|
`UPDATE ${PENDING_DVM_REPORTS_TABLE} SET stale = true, stale_reason = $1 WHERE id = $2`,
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
|
+
const require = __dvmCreateRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
Assets_exports,
|
|
6
|
+
Assets_exports2,
|
|
7
|
+
AuthorizationConfigSchema,
|
|
8
|
+
AuthorizationPayloadSchema,
|
|
9
|
+
Chains_exports,
|
|
10
|
+
ChargePayloadSchema,
|
|
11
|
+
ChargeRequestInputSchema,
|
|
12
|
+
ChargeRequestSchema,
|
|
13
|
+
MethodDetailsSchema,
|
|
14
|
+
Methods_exports,
|
|
15
|
+
Types_exports as Types_exports2,
|
|
16
|
+
authorizationDomain,
|
|
17
|
+
authorizationTypes,
|
|
18
|
+
challengeHash,
|
|
19
|
+
charge,
|
|
20
|
+
chargeIntent,
|
|
21
|
+
credentialTypes,
|
|
22
|
+
eip3009,
|
|
23
|
+
evmNetworkPrefix as evmNetworkPrefix2,
|
|
24
|
+
networkOf,
|
|
25
|
+
paymentMethod as paymentMethod2,
|
|
26
|
+
toSource
|
|
27
|
+
} from "./chunk-FL2ICZW5.js";
|
|
28
|
+
import {
|
|
29
|
+
ExactEip3009PayloadSchema,
|
|
30
|
+
ExactPayloadSchema,
|
|
31
|
+
ExactPermit2PayloadSchema,
|
|
32
|
+
ExactTransferSchema,
|
|
33
|
+
ExtensionSchema,
|
|
34
|
+
ExtensionsSchema,
|
|
35
|
+
Header_exports,
|
|
36
|
+
PaymentPayloadSchema,
|
|
37
|
+
PaymentRequiredSchema,
|
|
38
|
+
PaymentRequirementsSchema,
|
|
39
|
+
ResourceInfoSchema,
|
|
40
|
+
SettleResponseSchema,
|
|
41
|
+
Types_exports,
|
|
42
|
+
VerifyResponseSchema,
|
|
43
|
+
assetTransferMethods,
|
|
44
|
+
constantTimeEqual,
|
|
45
|
+
evmNetworkPrefix,
|
|
46
|
+
exactIntent,
|
|
47
|
+
paymentMethod,
|
|
48
|
+
paymentRequiredHeader,
|
|
49
|
+
paymentResponseHeader,
|
|
50
|
+
paymentSignatureHeader,
|
|
51
|
+
schemes,
|
|
52
|
+
syntheticChallengeIdPrefix,
|
|
53
|
+
toPaymentRequirements,
|
|
54
|
+
versions
|
|
55
|
+
} from "./chunk-WTM2EICO.js";
|
|
56
|
+
import {
|
|
57
|
+
Base64_exports
|
|
58
|
+
} from "./chunk-EZHT2RLJ.js";
|
|
59
|
+
import {
|
|
60
|
+
Hash_exports
|
|
61
|
+
} from "./chunk-LH3QPVN6.js";
|
|
62
|
+
import {
|
|
63
|
+
Bytes_exports
|
|
64
|
+
} from "./chunk-F55NNH2F.js";
|
|
65
|
+
import {
|
|
66
|
+
__export
|
|
67
|
+
} from "./chunk-IYHTITNZ.js";
|
|
68
|
+
|
|
69
|
+
// node_modules/mppx/dist/BodyDigest.js
|
|
70
|
+
var BodyDigest_exports = {};
|
|
71
|
+
__export(BodyDigest_exports, {
|
|
72
|
+
compute: () => compute,
|
|
73
|
+
verify: () => verify
|
|
74
|
+
});
|
|
75
|
+
function compute(body) {
|
|
76
|
+
const str = typeof body === "object" ? JSON.stringify(body) : body;
|
|
77
|
+
const bytes = Bytes_exports.fromString(str);
|
|
78
|
+
const hash = Hash_exports.sha256(bytes, { as: "Bytes" });
|
|
79
|
+
const base64 = Base64_exports.fromBytes(hash);
|
|
80
|
+
return `sha-256=${base64}`;
|
|
81
|
+
}
|
|
82
|
+
function verify(digest, body) {
|
|
83
|
+
return constantTimeEqual(compute(body), digest);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// node_modules/mppx/dist/evm/index.js
|
|
87
|
+
var evm_exports = {};
|
|
88
|
+
__export(evm_exports, {
|
|
89
|
+
Assets: () => Assets_exports2,
|
|
90
|
+
AuthorizationConfigSchema: () => AuthorizationConfigSchema,
|
|
91
|
+
AuthorizationPayloadSchema: () => AuthorizationPayloadSchema,
|
|
92
|
+
Chains: () => Chains_exports,
|
|
93
|
+
ChargePayloadSchema: () => ChargePayloadSchema,
|
|
94
|
+
ChargeRequestInputSchema: () => ChargeRequestInputSchema,
|
|
95
|
+
ChargeRequestSchema: () => ChargeRequestSchema,
|
|
96
|
+
MethodDetailsSchema: () => MethodDetailsSchema,
|
|
97
|
+
Methods: () => Methods_exports,
|
|
98
|
+
Types: () => Types_exports2,
|
|
99
|
+
assets: () => Assets_exports2,
|
|
100
|
+
authorizationDomain: () => authorizationDomain,
|
|
101
|
+
authorizationTypes: () => authorizationTypes,
|
|
102
|
+
chains: () => Chains_exports,
|
|
103
|
+
challengeHash: () => challengeHash,
|
|
104
|
+
charge: () => charge,
|
|
105
|
+
chargeIntent: () => chargeIntent,
|
|
106
|
+
credentialTypes: () => credentialTypes,
|
|
107
|
+
eip3009: () => eip3009,
|
|
108
|
+
evmNetworkPrefix: () => evmNetworkPrefix2,
|
|
109
|
+
networkOf: () => networkOf,
|
|
110
|
+
paymentMethod: () => paymentMethod2,
|
|
111
|
+
toSource: () => toSource
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// node_modules/mppx/dist/x402/index.js
|
|
115
|
+
var x402_exports = {};
|
|
116
|
+
__export(x402_exports, {
|
|
117
|
+
Assets: () => Assets_exports,
|
|
118
|
+
ExactEip3009PayloadSchema: () => ExactEip3009PayloadSchema,
|
|
119
|
+
ExactPayloadSchema: () => ExactPayloadSchema,
|
|
120
|
+
ExactPermit2PayloadSchema: () => ExactPermit2PayloadSchema,
|
|
121
|
+
ExactTransferSchema: () => ExactTransferSchema,
|
|
122
|
+
ExtensionSchema: () => ExtensionSchema,
|
|
123
|
+
ExtensionsSchema: () => ExtensionsSchema,
|
|
124
|
+
Header: () => Header_exports,
|
|
125
|
+
PaymentPayloadSchema: () => PaymentPayloadSchema,
|
|
126
|
+
PaymentRequiredSchema: () => PaymentRequiredSchema,
|
|
127
|
+
PaymentRequirementsSchema: () => PaymentRequirementsSchema,
|
|
128
|
+
ResourceInfoSchema: () => ResourceInfoSchema,
|
|
129
|
+
SettleResponseSchema: () => SettleResponseSchema,
|
|
130
|
+
Types: () => Types_exports,
|
|
131
|
+
VerifyResponseSchema: () => VerifyResponseSchema,
|
|
132
|
+
assetTransferMethods: () => assetTransferMethods,
|
|
133
|
+
assets: () => Assets_exports,
|
|
134
|
+
evmNetworkPrefix: () => evmNetworkPrefix,
|
|
135
|
+
exactIntent: () => exactIntent,
|
|
136
|
+
paymentMethod: () => paymentMethod,
|
|
137
|
+
paymentRequiredHeader: () => paymentRequiredHeader,
|
|
138
|
+
paymentResponseHeader: () => paymentResponseHeader,
|
|
139
|
+
paymentSignatureHeader: () => paymentSignatureHeader,
|
|
140
|
+
schemes: () => schemes,
|
|
141
|
+
syntheticChallengeIdPrefix: () => syntheticChallengeIdPrefix,
|
|
142
|
+
toPaymentRequirements: () => toPaymentRequirements,
|
|
143
|
+
versions: () => versions
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
BodyDigest_exports,
|
|
148
|
+
evm_exports,
|
|
149
|
+
x402_exports
|
|
150
|
+
};
|