@dvmkit/sdk 0.3.0-rc.9 → 0.3.2-rc.10
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-MD3H3BF7.js → chunk-2A33VHYM.js} +1 -1
- package/dist/{chunk-AJNFXR7J.js → chunk-3KYLYVY4.js} +4 -1
- package/dist/{chunk-YO56VCTQ.js → chunk-BWGRKGKG.js} +190 -75
- package/dist/{chunk-MMCE7XSR.js → chunk-C2AGARLM.js} +1 -13
- package/dist/chunk-D42FMCLJ.js +1423 -0
- package/dist/{chunk-QX52F6IB.js → chunk-DSVGYW3B.js} +7 -4
- package/dist/{chunk-LTAIBLS2.js → chunk-HNIKSOI2.js} +524 -408
- package/dist/{chunk-4A2RAKCW.js → chunk-IBDDIG4K.js} +7 -3
- package/dist/{chunk-D7YQYLLM.js → chunk-J7PW2U6P.js} +1 -1
- package/dist/{chunk-FDKRXOZO.js → chunk-KL4C3LQV.js} +57 -49
- package/dist/{chunk-VA7GT6C6.js → chunk-LHN75BTX.js} +56 -53
- package/dist/{chunk-C3MTFLC6.js → chunk-M4RSKQAV.js} +14 -12
- package/dist/{chunk-U5VNEALI.js → chunk-PPHE7XUU.js} +1 -1
- package/dist/{chunk-GAIPXGM3.js → chunk-SP42AI5T.js} +1 -1
- package/dist/{chunk-N5B66UOS.js → chunk-U2EYIPFX.js} +4 -1
- package/dist/{chunk-H2MEFVH6.js → chunk-UQCK5VMA.js} +7 -4
- package/dist/{chunk-XMDQOXHO.js → chunk-Y7JZLO5J.js} +4 -1
- package/dist/{chunk-HHTL3ZFT.js → chunk-YEO5GW7U.js} +16 -13
- package/dist/{chunk-O6D72KYA.js → chunk-YRDA7EWN.js} +1 -1
- package/dist/{chunk-VIVXB4CD.js → chunk-YYQG4R7T.js} +1 -1
- package/dist/{chunk-FPOLJRBF.js → chunk-Z3EHBW2G.js} +2 -2
- package/dist/{chunk-2D75MNNG.js → chunk-ZHTUITDW.js} +8 -5
- package/dist/{chunk-XZ7LW4S5.js → chunk-ZUTI56L7.js} +20 -16
- package/dist/{credit-ledger-MHA652TV.js → credit-ledger-4CCHRJE2.js} +3 -2
- package/dist/{credit-menu-BlCL7gZx.d.ts → credit-menu-0-UtJ3hh.d.ts} +5 -1
- package/dist/index.js +4 -3
- package/dist/internal/caller.d.ts +38 -3
- package/dist/internal/caller.js +59 -19
- package/dist/internal/index.js +1 -1
- package/dist/internal/server.d.ts +2 -2
- package/dist/internal/server.js +16 -15
- package/dist/memory-credit-ledger-TERNM5T6.js +10 -0
- package/dist/{mpp-setup-MPP3ST5X.js → mpp-setup-OQ4OV7A5.js} +2 -1
- package/dist/{payout-reporter-KEMUXEUO.js → payout-reporter-TQ3YIFLZ.js} +2 -1
- package/dist/{postgres-consumed-credential-store-6N2V5MJN.js → postgres-consumed-credential-store-LFQNC7LD.js} +4 -1
- package/dist/{postgres-job-store-VE2JRUEC.js → postgres-job-store-FGOJ7UIX.js} +2 -1
- package/dist/{postgres-replay-store-ZF4JNZOW.js → postgres-replay-store-DFQSXPCG.js} +2 -1
- package/dist/{pricing-MU5GNUJZ.js → pricing-UJAPJLOM.js} +2 -1
- package/dist/{revenue-reporter-O75BGYFK.js → revenue-reporter-VN4WYN74.js} +2 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +112 -112
- package/dist/{tempo-charge-store-SDTUNTKA.js → tempo-charge-store-EA66LSVJ.js} +2 -1
- package/dist/{tempo-lifecycle-G5SB4HFC.js → tempo-lifecycle-TJ62A7UX.js} +3 -3
- package/dist/{tempo-session-store-WF3VZXNF.js → tempo-session-store-65NA77KJ.js} +3 -2
- package/dist/{tempo-wallet-ZFNUDFVO.js → tempo-wallet-RCGBBAJH.js} +1 -1
- package/dist/testing/index.js +4 -3
- package/dist/{x402-CI6PSHNO.js → x402-S47Q77UE.js} +2 -2
- package/package.json +2 -2
- package/dist/memory-credit-ledger-BYBATRN3.js +0 -9
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticConsole
|
|
3
|
+
} from "./chunk-D42FMCLJ.js";
|
|
4
|
+
|
|
1
5
|
// src/sdk/pricing/currency.ts
|
|
2
6
|
var InvalidCurrencyError = class extends Error {
|
|
3
7
|
code = "invalid_currency";
|
|
@@ -212,14 +216,14 @@ function warnPartialRates(source, snapshot, episode) {
|
|
|
212
216
|
if (carried.length === 0 && unavailable.length === 0) return null;
|
|
213
217
|
const key = `${carried.join(",")}|${unavailable.join(",")}`;
|
|
214
218
|
if (key === episode) return episode;
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
diagnosticConsole.warn(
|
|
220
|
+
{
|
|
217
221
|
level: "warn",
|
|
218
222
|
event: "fx_rates_partial",
|
|
219
223
|
source,
|
|
220
224
|
...carried.length > 0 && { carried_forward: carried },
|
|
221
225
|
...unavailable.length > 0 && { unavailable }
|
|
222
|
-
}
|
|
226
|
+
}
|
|
223
227
|
);
|
|
224
228
|
return key;
|
|
225
229
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callerLoggers
|
|
3
3
|
} from "./chunk-66HGCPBU.js";
|
|
4
|
+
import {
|
|
5
|
+
diagnosticConsole,
|
|
6
|
+
projectSpanRow
|
|
7
|
+
} from "./chunk-D42FMCLJ.js";
|
|
4
8
|
|
|
5
9
|
// src/lib/x402/env.ts
|
|
6
10
|
import { isAddress } from "viem";
|
|
@@ -136,6 +140,9 @@ var SpanWriter = class {
|
|
|
136
140
|
backoffTimer = null;
|
|
137
141
|
/** Enqueue a span row. Non-blocking — truncates oversize JSONB and appends to buffer. */
|
|
138
142
|
enqueue(row) {
|
|
143
|
+
const projected = projectSpanRow(row);
|
|
144
|
+
if (!projected.ok) return;
|
|
145
|
+
row = projected.row;
|
|
139
146
|
const originalBytes = JSON.stringify({
|
|
140
147
|
attributes: row.attributes,
|
|
141
148
|
dimensions: row.dimensions
|
|
@@ -146,14 +153,12 @@ var SpanWriter = class {
|
|
|
146
153
|
if (this.buffer.length >= MAX_BUFFERED_SPANS) {
|
|
147
154
|
this.dropCount++;
|
|
148
155
|
if (this.dropCount === 1 || this.dropCount % 1e3 === 0) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
})
|
|
156
|
-
);
|
|
156
|
+
diagnosticConsole.error({
|
|
157
|
+
event: "span_buffer_drop",
|
|
158
|
+
reason: "buffer_full",
|
|
159
|
+
total_dropped: this.dropCount,
|
|
160
|
+
buffer_size: this.buffer.length
|
|
161
|
+
});
|
|
157
162
|
}
|
|
158
163
|
return;
|
|
159
164
|
}
|
|
@@ -182,24 +187,26 @@ var SpanWriter = class {
|
|
|
182
187
|
if (this.flushing) return;
|
|
183
188
|
if (this.buffer.length === 0) return;
|
|
184
189
|
this.flushing = true;
|
|
185
|
-
const
|
|
190
|
+
const queuedBatch = this.buffer;
|
|
186
191
|
this.buffer = [];
|
|
187
192
|
try {
|
|
193
|
+
const batch = queuedBatch.flatMap((row) => {
|
|
194
|
+
const projected = projectSpanRow(row);
|
|
195
|
+
return projected.ok ? [projected.row] : [];
|
|
196
|
+
});
|
|
188
197
|
await this.transport.send(batch);
|
|
189
198
|
this.consecutiveFailures = 0;
|
|
190
|
-
} catch (
|
|
199
|
+
} catch (_err) {
|
|
191
200
|
this.consecutiveFailures++;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
})
|
|
199
|
-
);
|
|
201
|
+
diagnosticConsole.error({
|
|
202
|
+
event: "span_flush_failed",
|
|
203
|
+
error: void 0,
|
|
204
|
+
batch_size: queuedBatch.length,
|
|
205
|
+
consecutive_failures: this.consecutiveFailures
|
|
206
|
+
});
|
|
200
207
|
const room = MAX_BUFFERED_SPANS - this.buffer.length;
|
|
201
208
|
if (room > 0) {
|
|
202
|
-
this.buffer.unshift(...
|
|
209
|
+
this.buffer.unshift(...queuedBatch.slice(0, room));
|
|
203
210
|
}
|
|
204
211
|
if (this.consecutiveFailures > 1) {
|
|
205
212
|
const exponent = Math.min(this.consecutiveFailures - 1, MAX_BACKOFF_EXPONENT);
|
|
@@ -252,43 +259,36 @@ var SpanWriter = class {
|
|
|
252
259
|
}).length;
|
|
253
260
|
let mode;
|
|
254
261
|
if (afterStringPass <= MAX_ROW_JSONB_BYTES) {
|
|
255
|
-
row =
|
|
262
|
+
row.attributes = truncatedAttrs;
|
|
256
263
|
mode = "string_pass";
|
|
257
264
|
} else {
|
|
258
265
|
const dimSize = JSON.stringify(row.dimensions).length;
|
|
259
266
|
if (dimSize > MAX_ROW_JSONB_BYTES) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
})
|
|
267
|
-
);
|
|
267
|
+
diagnosticConsole.error({
|
|
268
|
+
event: "span_dimension_oversized",
|
|
269
|
+
name: row.name,
|
|
270
|
+
dataset: row.dataset,
|
|
271
|
+
dimension_bytes: dimSize
|
|
272
|
+
});
|
|
268
273
|
}
|
|
269
|
-
row = {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
original_bytes: originalBytes,
|
|
274
|
-
original_keys: Object.keys(row.attributes).sort()
|
|
275
|
-
}
|
|
274
|
+
row.attributes = {
|
|
275
|
+
_truncated: true,
|
|
276
|
+
original_bytes: originalBytes,
|
|
277
|
+
original_keys: Object.keys(row.attributes).sort()
|
|
276
278
|
};
|
|
277
279
|
mode = "wholesale_fallback";
|
|
278
280
|
}
|
|
279
281
|
this.truncatedSpanCount++;
|
|
280
282
|
if (this.truncatedSpanCount === 1 || this.truncatedSpanCount % 100 === 0) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
})
|
|
291
|
-
);
|
|
283
|
+
diagnosticConsole.error({
|
|
284
|
+
event: "span_truncated",
|
|
285
|
+
name: row.name,
|
|
286
|
+
dataset: row.dataset,
|
|
287
|
+
original_bytes: originalBytes,
|
|
288
|
+
after_string_pass_bytes: afterStringPass,
|
|
289
|
+
mode,
|
|
290
|
+
total_truncated: this.truncatedSpanCount
|
|
291
|
+
});
|
|
292
292
|
}
|
|
293
293
|
return row;
|
|
294
294
|
}
|
|
@@ -318,7 +318,10 @@ async function insertSpanBatch(pool, rows) {
|
|
|
318
318
|
const values = [];
|
|
319
319
|
const placeholders = [];
|
|
320
320
|
let idx = 1;
|
|
321
|
-
for (const
|
|
321
|
+
for (const candidate of rows) {
|
|
322
|
+
const projected = projectSpanRow(candidate);
|
|
323
|
+
if (!projected.ok) continue;
|
|
324
|
+
const row = projected.row;
|
|
322
325
|
const rowPlaceholders = [];
|
|
323
326
|
for (const col of SPAN_COLUMNS) {
|
|
324
327
|
let val = row[col] ?? null;
|
|
@@ -336,6 +339,7 @@ async function insertSpanBatch(pool, rows) {
|
|
|
336
339
|
}
|
|
337
340
|
placeholders.push(`(${rowPlaceholders.join(", ")})`);
|
|
338
341
|
}
|
|
342
|
+
if (placeholders.length === 0) return;
|
|
339
343
|
await pool.query(
|
|
340
344
|
`INSERT INTO observability.spans (${SPAN_COLUMNS.join(", ")})
|
|
341
345
|
VALUES ${placeholders.join(",\n")}
|
|
@@ -364,14 +368,18 @@ var HttpTransport = class {
|
|
|
364
368
|
platformUrl;
|
|
365
369
|
serviceToken;
|
|
366
370
|
async send(rows) {
|
|
367
|
-
|
|
371
|
+
const safeRows = rows.flatMap((row) => {
|
|
372
|
+
const projected = projectSpanRow(row);
|
|
373
|
+
return projected.ok ? [projected.row] : [];
|
|
374
|
+
});
|
|
375
|
+
if (safeRows.length === 0) return;
|
|
368
376
|
const resp = await fetch(`${this.platformUrl.replace(/\/$/, "")}/_internal/spans`, {
|
|
369
377
|
method: "POST",
|
|
370
378
|
headers: {
|
|
371
379
|
"Content-Type": "application/json",
|
|
372
380
|
Authorization: `Bearer ${this.serviceToken}`
|
|
373
381
|
},
|
|
374
|
-
body: JSON.stringify({ spans:
|
|
382
|
+
body: JSON.stringify({ spans: safeRows })
|
|
375
383
|
});
|
|
376
384
|
if (!resp.ok) {
|
|
377
385
|
const text = await resp.text().catch(() => "");
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withSdkInitLock
|
|
3
3
|
} from "./chunk-COYKJRMM.js";
|
|
4
|
+
import {
|
|
5
|
+
diagnosticConsole
|
|
6
|
+
} from "./chunk-D42FMCLJ.js";
|
|
4
7
|
|
|
5
8
|
// src/sdk/server/revenue-reporter.ts
|
|
6
9
|
import { randomUUID } from "crypto";
|
|
@@ -214,21 +217,21 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
214
217
|
signal: AbortSignal.timeout(1e4)
|
|
215
218
|
});
|
|
216
219
|
if (!res.ok) {
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
diagnosticConsole.warn(
|
|
221
|
+
{
|
|
219
222
|
level: "payout_pending_report_failed",
|
|
220
223
|
rail: payload.rail,
|
|
221
224
|
status: res.status
|
|
222
|
-
}
|
|
225
|
+
}
|
|
223
226
|
);
|
|
224
227
|
}
|
|
225
|
-
} catch (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
} catch (_err) {
|
|
229
|
+
diagnosticConsole.warn(
|
|
230
|
+
{
|
|
228
231
|
level: "payout_pending_report_failed",
|
|
229
232
|
rail: payload.rail,
|
|
230
|
-
error:
|
|
231
|
-
}
|
|
233
|
+
error: void 0
|
|
234
|
+
}
|
|
232
235
|
);
|
|
233
236
|
}
|
|
234
237
|
}
|
|
@@ -261,21 +264,21 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
261
264
|
signal: AbortSignal.timeout(1e4)
|
|
262
265
|
});
|
|
263
266
|
if (!res.ok) {
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
diagnosticConsole.warn(
|
|
268
|
+
{
|
|
266
269
|
level: "paid_job_death_report_failed",
|
|
267
270
|
jobId: payload.jobId,
|
|
268
271
|
status: res.status
|
|
269
|
-
}
|
|
272
|
+
}
|
|
270
273
|
);
|
|
271
274
|
}
|
|
272
|
-
} catch (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
+
} catch (_err) {
|
|
276
|
+
diagnosticConsole.warn(
|
|
277
|
+
{
|
|
275
278
|
level: "paid_job_death_report_failed",
|
|
276
279
|
jobId: payload.jobId,
|
|
277
|
-
error:
|
|
278
|
-
}
|
|
280
|
+
error: void 0
|
|
281
|
+
}
|
|
279
282
|
);
|
|
280
283
|
}
|
|
281
284
|
}
|
|
@@ -298,25 +301,25 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
298
301
|
signal: AbortSignal.timeout(1e4)
|
|
299
302
|
});
|
|
300
303
|
if (!res.ok) {
|
|
301
|
-
|
|
302
|
-
|
|
304
|
+
diagnosticConsole.warn(
|
|
305
|
+
{
|
|
303
306
|
level: "revenue_skipped_no_rail_report_failed",
|
|
304
307
|
jobId: payload.jobId,
|
|
305
308
|
drawId: payload.drawId,
|
|
306
309
|
reason: payload.reason,
|
|
307
310
|
status: res.status
|
|
308
|
-
}
|
|
311
|
+
}
|
|
309
312
|
);
|
|
310
313
|
}
|
|
311
|
-
} catch (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
+
} catch (_err) {
|
|
315
|
+
diagnosticConsole.warn(
|
|
316
|
+
{
|
|
314
317
|
level: "revenue_skipped_no_rail_report_failed",
|
|
315
318
|
jobId: payload.jobId,
|
|
316
319
|
drawId: payload.drawId,
|
|
317
320
|
reason: payload.reason,
|
|
318
|
-
error:
|
|
319
|
-
}
|
|
321
|
+
error: void 0
|
|
322
|
+
}
|
|
320
323
|
);
|
|
321
324
|
}
|
|
322
325
|
}
|
|
@@ -333,21 +336,21 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
333
336
|
signal: AbortSignal.timeout(1e4)
|
|
334
337
|
});
|
|
335
338
|
if (!res.ok) {
|
|
336
|
-
|
|
337
|
-
|
|
339
|
+
diagnosticConsole.warn(
|
|
340
|
+
{
|
|
338
341
|
level: "x402_self_relay_gas_balance_report_failed",
|
|
339
342
|
address: payload.address,
|
|
340
343
|
status: res.status
|
|
341
|
-
}
|
|
344
|
+
}
|
|
342
345
|
);
|
|
343
346
|
}
|
|
344
|
-
} catch (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
+
} catch (_err) {
|
|
348
|
+
diagnosticConsole.warn(
|
|
349
|
+
{
|
|
347
350
|
level: "x402_self_relay_gas_balance_report_failed",
|
|
348
351
|
address: payload.address,
|
|
349
|
-
error:
|
|
350
|
-
}
|
|
352
|
+
error: void 0
|
|
353
|
+
}
|
|
351
354
|
);
|
|
352
355
|
}
|
|
353
356
|
}
|
|
@@ -364,21 +367,21 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
364
367
|
signal: AbortSignal.timeout(1e4)
|
|
365
368
|
});
|
|
366
369
|
if (!res.ok) {
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
diagnosticConsole.warn(
|
|
371
|
+
{
|
|
369
372
|
level: "x402_self_relay_rpc_health_report_failed",
|
|
370
373
|
address: payload.address,
|
|
371
374
|
status: res.status
|
|
372
|
-
}
|
|
375
|
+
}
|
|
373
376
|
);
|
|
374
377
|
}
|
|
375
378
|
} catch {
|
|
376
|
-
|
|
377
|
-
|
|
379
|
+
diagnosticConsole.warn(
|
|
380
|
+
{
|
|
378
381
|
level: "x402_self_relay_rpc_health_report_failed",
|
|
379
382
|
address: payload.address,
|
|
380
383
|
reason: "transport"
|
|
381
|
-
}
|
|
384
|
+
}
|
|
382
385
|
);
|
|
383
386
|
}
|
|
384
387
|
}
|
|
@@ -401,23 +404,23 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
401
404
|
signal: AbortSignal.timeout(1e4)
|
|
402
405
|
});
|
|
403
406
|
if (!res.ok) {
|
|
404
|
-
|
|
405
|
-
|
|
407
|
+
diagnosticConsole.warn(
|
|
408
|
+
{
|
|
406
409
|
level: "tempo_settlement_readiness_report_failed",
|
|
407
410
|
kind,
|
|
408
411
|
address: payload.address,
|
|
409
412
|
status: res.status
|
|
410
|
-
}
|
|
413
|
+
}
|
|
411
414
|
);
|
|
412
415
|
}
|
|
413
416
|
} catch {
|
|
414
|
-
|
|
415
|
-
|
|
417
|
+
diagnosticConsole.warn(
|
|
418
|
+
{
|
|
416
419
|
level: "tempo_settlement_readiness_report_failed",
|
|
417
420
|
kind,
|
|
418
421
|
address: payload.address,
|
|
419
422
|
reason: "transport"
|
|
420
|
-
}
|
|
423
|
+
}
|
|
421
424
|
);
|
|
422
425
|
}
|
|
423
426
|
}
|
|
@@ -482,8 +485,8 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
482
485
|
const retryCount = row.retry_count + 1;
|
|
483
486
|
if (Date.now() - Number(row.created_at) >= _RevenueReporter.ABANDON_AFTER_MS) {
|
|
484
487
|
await this.markStale(row.id, "abandoned");
|
|
485
|
-
|
|
486
|
-
|
|
488
|
+
diagnosticConsole.warn(
|
|
489
|
+
{
|
|
487
490
|
level: "revenue_reporter_abandoned",
|
|
488
491
|
id: row.id,
|
|
489
492
|
kind: row.kind,
|
|
@@ -494,7 +497,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
494
497
|
// carries `rail`. An abandoned row is the one place an
|
|
495
498
|
// operator sees this payload at all, so don't log it blank.
|
|
496
499
|
rail: row.payload.rail ?? row.payload.method
|
|
497
|
-
}
|
|
500
|
+
}
|
|
498
501
|
);
|
|
499
502
|
continue;
|
|
500
503
|
}
|
|
@@ -511,7 +514,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
511
514
|
}
|
|
512
515
|
}
|
|
513
516
|
} catch (err) {
|
|
514
|
-
|
|
517
|
+
diagnosticConsole.error("[revenue-reporter] Retry loop error:", err);
|
|
515
518
|
}
|
|
516
519
|
}
|
|
517
520
|
async enqueue(kind, payload, label) {
|
|
@@ -543,31 +546,31 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
543
546
|
});
|
|
544
547
|
} catch (err) {
|
|
545
548
|
const reason = err instanceof Error ? err.message : String(err);
|
|
546
|
-
|
|
549
|
+
diagnosticConsole.warn(
|
|
547
550
|
`[revenue-reporter] delivery failed for ${id}: transport error (${reason}) \u2014 will retry`
|
|
548
551
|
);
|
|
549
552
|
throw err;
|
|
550
553
|
}
|
|
551
554
|
if (res.ok) {
|
|
552
555
|
await this.db.query(`DELETE FROM ${PENDING_DVM_REPORTS_TABLE} WHERE id = $1`, [id]);
|
|
553
|
-
|
|
556
|
+
diagnosticConsole.log(`[revenue-reporter] reported ${kind} ${label}`);
|
|
554
557
|
return;
|
|
555
558
|
}
|
|
556
559
|
if (res.status === 401) {
|
|
557
560
|
await this.markStale(id, "token_rotated");
|
|
558
|
-
|
|
561
|
+
diagnosticConsole.warn(
|
|
559
562
|
`[revenue-reporter] Report ${id} got 401 \u2014 marking stale (token likely rotated)`
|
|
560
563
|
);
|
|
561
564
|
return;
|
|
562
565
|
}
|
|
563
566
|
if (res.status >= 400 && res.status < 500) {
|
|
564
567
|
await this.markStale(id, `client_error:${res.status}`);
|
|
565
|
-
|
|
568
|
+
diagnosticConsole.warn(
|
|
566
569
|
`[revenue-reporter] Report ${id} got HTTP ${res.status} \u2014 marking stale (permanent client error, will not retry)`
|
|
567
570
|
);
|
|
568
571
|
return;
|
|
569
572
|
}
|
|
570
|
-
|
|
573
|
+
diagnosticConsole.warn(`[revenue-reporter] delivery failed for ${id}: HTTP ${res.status} \u2014 will retry`);
|
|
571
574
|
throw new Error(`Platform returned ${res.status}`);
|
|
572
575
|
}
|
|
573
576
|
async markStale(id, reason) {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticConsole
|
|
3
|
+
} from "./chunk-D42FMCLJ.js";
|
|
4
|
+
|
|
1
5
|
// src/lib/pg-retry.ts
|
|
2
6
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
7
|
var postgresRecovery = new AsyncLocalStorage();
|
|
@@ -19,9 +23,7 @@ async function withInitRetry(fn, label, delays = [1e3, 4e3, 15e3]) {
|
|
|
19
23
|
} catch (err) {
|
|
20
24
|
if (!isTransportError(err) || attempt >= delays.length) throw err;
|
|
21
25
|
const wait = delays[attempt];
|
|
22
|
-
|
|
23
|
-
`[${label}] DB init attempt ${attempt + 1} failed (${err.message}), retrying in ${wait / 1e3}s`
|
|
24
|
-
);
|
|
26
|
+
diagnosticConsole.warn();
|
|
25
27
|
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -39,8 +41,8 @@ function applyRetryToPool(pool, label = "pg-pool") {
|
|
|
39
41
|
if (patchedPools.has(pool)) return;
|
|
40
42
|
patchedPools.add(pool);
|
|
41
43
|
pool.options.application_name = formatPostgresApplicationName(label);
|
|
42
|
-
pool.on("error", (
|
|
43
|
-
|
|
44
|
+
pool.on("error", (_err) => {
|
|
45
|
+
diagnosticConsole.error();
|
|
44
46
|
});
|
|
45
47
|
const p = pool;
|
|
46
48
|
const origQuery = p.query.bind(pool);
|
|
@@ -119,8 +121,8 @@ function hostPoolSize(pool) {
|
|
|
119
121
|
return typeof configured === "number" && Number.isSafeInteger(configured) && configured > 0 ? configured : 10;
|
|
120
122
|
}
|
|
121
123
|
function logTransportRecovery(args) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
diagnosticConsole.warn(
|
|
125
|
+
{
|
|
124
126
|
level: "postgres_transport_recovery",
|
|
125
127
|
label: args.label,
|
|
126
128
|
route: args.context?.route,
|
|
@@ -129,20 +131,20 @@ function logTransportRecovery(args) {
|
|
|
129
131
|
attempts: args.attempts,
|
|
130
132
|
elapsed_ms: args.elapsedMs,
|
|
131
133
|
outcome: args.outcome,
|
|
132
|
-
error:
|
|
133
|
-
}
|
|
134
|
+
error: void 0
|
|
135
|
+
}
|
|
134
136
|
);
|
|
135
137
|
}
|
|
136
138
|
function asError(error) {
|
|
137
139
|
return error instanceof Error ? error : new Error(String(error));
|
|
138
140
|
}
|
|
139
|
-
function guardCheckedOutClient(client,
|
|
141
|
+
function guardCheckedOutClient(client, _label) {
|
|
140
142
|
if (client === null || typeof client !== "object") return;
|
|
141
143
|
const emitter = client;
|
|
142
144
|
if (typeof emitter.on !== "function" || guardedClients.has(client)) return;
|
|
143
145
|
guardedClients.add(client);
|
|
144
|
-
emitter.on("error", (
|
|
145
|
-
|
|
146
|
+
emitter.on("error", (_err) => {
|
|
147
|
+
diagnosticConsole.error();
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
function truncateUtf8(value, maxBytes) {
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
withSdkInitLock
|
|
7
7
|
} from "./chunk-COYKJRMM.js";
|
|
8
|
+
import {
|
|
9
|
+
diagnosticConsole
|
|
10
|
+
} from "./chunk-D42FMCLJ.js";
|
|
8
11
|
|
|
9
12
|
// src/sdk/server/tempo-charge-store.ts
|
|
10
13
|
var DEFAULT_TABLE_NAME = "mpp_tempo_charge_replays";
|
|
@@ -109,7 +112,7 @@ var PostgresTempoChargeStore = class {
|
|
|
109
112
|
maybeSweep(now) {
|
|
110
113
|
if (this.gcSampleRate <= 0 || Math.random() >= this.gcSampleRate) return;
|
|
111
114
|
this.pool.query(`DELETE FROM ${this.tableName} WHERE expires_at < $1`, [now]).catch((err) => {
|
|
112
|
-
|
|
115
|
+
diagnosticConsole.error("PostgresTempoChargeStore GC sweep failed:", err);
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
};
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
signedRequestStatementHeader,
|
|
6
6
|
testOnlySignedRequestDomain
|
|
7
7
|
} from "./chunk-KXZUCCEY.js";
|
|
8
|
+
import {
|
|
9
|
+
diagnosticConsole
|
|
10
|
+
} from "./chunk-D42FMCLJ.js";
|
|
8
11
|
|
|
9
12
|
// src/sdk/server/zod-error.ts
|
|
10
13
|
function humanizeZodError(err, opts) {
|
|
@@ -292,14 +295,14 @@ function createDefaultReplayStore() {
|
|
|
292
295
|
if (entries.size >= DEFAULT_REPLAY_CAP) {
|
|
293
296
|
if (t - lastSaturationWarnAt >= SATURATION_WARN_INTERVAL_SECONDS) {
|
|
294
297
|
lastSaturationWarnAt = t;
|
|
295
|
-
|
|
296
|
-
|
|
298
|
+
diagnosticConsole.warn(
|
|
299
|
+
{
|
|
297
300
|
level: "warn",
|
|
298
301
|
event: "signed_request_replay_store_saturated",
|
|
299
|
-
message:
|
|
302
|
+
message: void 0,
|
|
300
303
|
cap: DEFAULT_REPLAY_CAP,
|
|
301
304
|
window_seconds: DEFAULT_REPLAY_WINDOW_SECONDS
|
|
302
|
-
}
|
|
305
|
+
}
|
|
303
306
|
);
|
|
304
307
|
}
|
|
305
308
|
return Promise.resolve(true);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withSdkInitLock
|
|
3
3
|
} from "./chunk-COYKJRMM.js";
|
|
4
|
+
import {
|
|
5
|
+
diagnosticConsole
|
|
6
|
+
} from "./chunk-D42FMCLJ.js";
|
|
4
7
|
|
|
5
8
|
// src/sdk/server/payout-reporter.ts
|
|
6
9
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -719,7 +722,7 @@ function message(err) {
|
|
|
719
722
|
return err instanceof Error ? err.message : String(err);
|
|
720
723
|
}
|
|
721
724
|
function warn(level, fields) {
|
|
722
|
-
|
|
725
|
+
diagnosticConsole.warn({ level, ...fields });
|
|
723
726
|
}
|
|
724
727
|
|
|
725
728
|
export {
|