mtok-relay 0.2.6 → 0.2.7
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/mtok-relay.mjs +10 -5
- package/package.json +1 -1
package/dist/mtok-relay.mjs
CHANGED
|
@@ -5532,19 +5532,20 @@ function createServeCore({
|
|
|
5532
5532
|
const requestHash = hasRequestNonce ? await hash32({ request, requestNonce }) : await hash32(request);
|
|
5533
5533
|
const cacheKey = `${requestHashScheme}:${bookingId}:${n}:${requestHash}`;
|
|
5534
5534
|
const oldLegacyKey = hasRequestNonce ? null : `${bookingId}:${n}:${requestHash}`;
|
|
5535
|
+
const redemptionContext = { claimKey: cacheKey };
|
|
5535
5536
|
if (!dripContractAddress) {
|
|
5536
5537
|
return { status: 402, body: { error: "contract_mode_required", detail: "this relay only serves contract-mode draws; the platform is not reporting a dripContractAddress" } };
|
|
5537
5538
|
}
|
|
5538
5539
|
if (!drawPaidTxHash) return { status: 402, body: { error: "draw_payment_required", detail: "contract mode requires drawPaidTxHash before upstream delivery" } };
|
|
5539
5540
|
let storedKey = cacheKey;
|
|
5540
|
-
let redemptionState = await redemption.state(storedKey);
|
|
5541
|
+
let redemptionState = await redemption.state(storedKey, redemptionContext);
|
|
5541
5542
|
if (!redemptionState && oldLegacyKey) {
|
|
5542
|
-
const oldLegacyState = await redemption.state(oldLegacyKey);
|
|
5543
|
+
const oldLegacyState = await redemption.state(oldLegacyKey, redemptionContext);
|
|
5543
5544
|
if (oldLegacyState) {
|
|
5544
5545
|
storedKey = oldLegacyKey;
|
|
5545
5546
|
redemptionState = oldLegacyState;
|
|
5546
5547
|
} else {
|
|
5547
|
-
redemptionState = await redemption.state(cacheKey);
|
|
5548
|
+
redemptionState = await redemption.state(cacheKey, redemptionContext);
|
|
5548
5549
|
}
|
|
5549
5550
|
}
|
|
5550
5551
|
let paid;
|
|
@@ -5580,7 +5581,11 @@ function createServeCore({
|
|
|
5580
5581
|
return { status: 403, body: { error: "payer_denied", detail: "payer screening failed: " + e.message } };
|
|
5581
5582
|
}
|
|
5582
5583
|
}
|
|
5583
|
-
if (redemptionState === "complete")
|
|
5584
|
+
if (redemptionState === "complete") {
|
|
5585
|
+
const payload2 = await redemption.get(storedKey, redemptionContext);
|
|
5586
|
+
if (payload2 == null) return { status: 503, body: { error: "redemption_unavailable", detail: "saved completion is no longer readable; retry this same paid draw", _bookingId: bookingId } };
|
|
5587
|
+
return { status: 200, body: payload2 };
|
|
5588
|
+
}
|
|
5584
5589
|
if (redemptionState === "pending") {
|
|
5585
5590
|
return { status: 409, body: { error: "draw_pending", detail: "this paid draw was already claimed; refusing to run upstream again", _bookingId: bookingId } };
|
|
5586
5591
|
}
|
|
@@ -5611,7 +5616,7 @@ function createServeCore({
|
|
|
5611
5616
|
}
|
|
5612
5617
|
const safeRequest = { ...checked.safeRequest, model, max_tokens: bound.maxTok };
|
|
5613
5618
|
try {
|
|
5614
|
-
if (!await redemption.claim(cacheKey, oldLegacyKey ?? cacheKey)) {
|
|
5619
|
+
if (!await redemption.claim(cacheKey, oldLegacyKey ?? cacheKey, { paidAtMs: paid.paidAtMs })) {
|
|
5615
5620
|
return { status: 409, body: { error: "draw_pending", detail: "this paid draw was already claimed; refusing to run upstream again", _bookingId: bookingId } };
|
|
5616
5621
|
}
|
|
5617
5622
|
} catch (e) {
|
package/package.json
CHANGED