@dvmkit/sdk 0.1.5-rc.9 → 0.2.1-rc.9
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 +14 -0
- package/dist/{chunk-MLRCSJYX.js → chunk-2D75MNNG.js} +178 -550
- package/dist/{chunk-BIFLRKMO.js → chunk-2KGG5ORW.js} +1 -1
- package/dist/{chunk-27V2ILSR.js → chunk-4A2RAKCW.js} +2 -2
- package/dist/{chunk-5URG56JJ.js → chunk-A4CM2BD3.js} +18 -2
- package/dist/{chunk-L4OYF4DQ.js → chunk-AJNFXR7J.js} +2 -2
- package/dist/{chunk-S3XAHZQY.js → chunk-COYKJRMM.js} +24 -3
- package/dist/{chunk-UP2F5RRT.js → chunk-D7YQYLLM.js} +1 -4
- package/dist/{chunk-CEOAHV2I.js → chunk-FDKRXOZO.js} +0 -5
- package/dist/{chunk-TQWGQCNV.js → chunk-FPOLJRBF.js} +5 -5
- package/dist/{chunk-BTZY7VPH.js → chunk-GAIPXGM3.js} +1 -1
- package/dist/{chunk-SSSZUVWM.js → chunk-JAHRF5X3.js} +89 -39
- package/dist/{chunk-5PBOA25N.js → chunk-JNKQZVZX.js} +472 -617
- package/dist/{chunk-U6M3ATSG.js → chunk-MD3H3BF7.js} +40 -6
- package/dist/{chunk-CGKZDODG.js → chunk-MG67KXU7.js} +0 -5
- package/dist/{chunk-KSQEFVFJ.js → chunk-MMCE7XSR.js} +1 -1
- package/dist/{chunk-JZWELPFH.js → chunk-N5B66UOS.js} +4 -16
- package/dist/{chunk-BIP6G74V.js → chunk-O6D72KYA.js} +10 -10
- package/dist/{chunk-KXCKFIJI.js → chunk-QX52F6IB.js} +1 -1
- package/dist/{chunk-RW5LP57K.js → chunk-SDK6KDJN.js} +0 -1
- package/dist/{chunk-KVEHHC7W.js → chunk-U5VNEALI.js} +24 -13
- package/dist/{chunk-FROTD5XQ.js → chunk-V5ZRATJH.js} +2 -3
- package/dist/{chunk-EVBK675R.js → chunk-VA7GT6C6.js} +31 -37
- package/dist/{chunk-2UUXIIOC.js → chunk-VIVXB4CD.js} +3 -3
- package/dist/{chunk-6BQM7TOW.js → chunk-XMDQOXHO.js} +11 -38
- package/dist/{chunk-DMNLFNTW.js → chunk-XRLKGCAW.js} +2 -2
- package/dist/{chunk-M7LHFJ5K.js → chunk-XZ7LW4S5.js} +2 -3
- package/dist/{chunk-E4EVGPDX.js → chunk-YO56VCTQ.js} +0 -6
- package/dist/{credit-ledger-2DFQHNLB.js → credit-ledger-MHA652TV.js} +2 -2
- package/dist/{credit-menu-enwMbn55.d.ts → credit-menu-kDA9RVzD.d.ts} +524 -1077
- package/dist/{fx-D860pZvP.d.ts → fx-DhyT1Cjh.d.ts} +38 -82
- package/dist/index.d.ts +11 -26
- package/dist/index.js +2 -2
- package/dist/internal/caller.d.ts +644 -2140
- package/dist/internal/caller.js +32 -66
- package/dist/internal/server.d.ts +40 -90
- package/dist/internal/server.js +16 -16
- package/dist/{job-store-BUGqvCfL.d.ts → job-store-D3CcZp_g.d.ts} +73 -66
- package/dist/{lightning-backend-BozcevPZ.d.ts → lightning-backend-BhsyrBLa.d.ts} +19 -41
- package/dist/{memory-credit-ledger-MNUOTQO5.js → memory-credit-ledger-BYBATRN3.js} +3 -3
- package/dist/{mpp-secret-state-WNAQQ6K4.js → mpp-secret-state-B5GCILVH.js} +1 -1
- package/dist/{mpp-setup-4FJD6ZHV.js → mpp-setup-MPP3ST5X.js} +1 -1
- package/dist/{payout-reporter-RG6XNGPI.js → payout-reporter-KEMUXEUO.js} +2 -2
- package/dist/{postgres-consumed-credential-store-VHBT4KEA.js → postgres-consumed-credential-store-6N2V5MJN.js} +2 -2
- package/dist/postgres-job-store-MZZZMS2B.js +7 -0
- package/dist/postgres-kv-store-DXGTKXLU.js +7 -0
- package/dist/{postgres-replay-store-UJXRT6VO.js → postgres-replay-store-ZF4JNZOW.js} +2 -2
- package/dist/{pricing-4CEB34RM.js → pricing-MU5GNUJZ.js} +1 -1
- package/dist/{processed-payment-store-HAA4SFNK.js → processed-payment-store-GKMAWOM3.js} +2 -2
- package/dist/revenue-reporter-O75BGYFK.js +7 -0
- package/dist/server/index.d.ts +47 -159
- package/dist/server/index.js +67 -138
- package/dist/{ssrf-DbFkpDv0.d.ts → ssrf-dMooihtY.d.ts} +1 -2
- package/dist/{step-cache-5dljDqrQ.d.ts → step-cache-v2yhyhSZ.d.ts} +617 -1532
- package/dist/{tempo-charge-store-RIFTALZK.js → tempo-charge-store-SDTUNTKA.js} +2 -2
- package/dist/{tempo-lifecycle-DFIXQ54Q.js → tempo-lifecycle-G5SB4HFC.js} +5 -5
- package/dist/{tempo-session-store-2JNOKJGX.js → tempo-session-store-WF3VZXNF.js} +2 -2
- package/dist/{tempo-wallet-4QKSV65O.js → tempo-wallet-ZFNUDFVO.js} +2 -2
- package/dist/testing/index.d.ts +5 -15
- package/dist/testing/index.js +4 -11
- package/dist/{usd-DoRuAckA.d.ts → usd-Cu9G6xv2.d.ts} +14 -16
- package/dist/{wallet-CJC8lwxx.d.ts → wallet-Dwjs5n_M.d.ts} +1 -1
- package/dist/{x402-5H27DCBE.js → x402-CI6PSHNO.js} +5 -5
- package/package.json +3 -2
- package/dist/postgres-job-store-3RAXMNSY.js +0 -7
- package/dist/postgres-kv-store-JFBDP5IP.js +0 -7
- package/dist/revenue-reporter-ASZ7SHHH.js +0 -7
package/dist/internal/server.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PostgresTempoSessionStore
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-D7YQYLLM.js";
|
|
4
4
|
import {
|
|
5
5
|
verifyX402Payment
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-2KGG5ORW.js";
|
|
7
7
|
import {
|
|
8
8
|
RevenueReporter
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-VA7GT6C6.js";
|
|
10
10
|
import {
|
|
11
11
|
PayoutReporter
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-XMDQOXHO.js";
|
|
13
13
|
import {
|
|
14
14
|
PostgresTempoChargeStore
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-N5B66UOS.js";
|
|
16
16
|
import "../chunk-YG7G4DPZ.js";
|
|
17
17
|
import {
|
|
18
18
|
DEFAULT_LOCK_PUBKEY_GRACE_SECONDS,
|
|
@@ -65,13 +65,13 @@ import {
|
|
|
65
65
|
verifyUpfrontPayment,
|
|
66
66
|
x402RequiredUsdcMicro,
|
|
67
67
|
x402SettledShare
|
|
68
|
-
} from "../chunk-
|
|
69
|
-
import "../chunk-
|
|
68
|
+
} from "../chunk-JNKQZVZX.js";
|
|
69
|
+
import "../chunk-XRLKGCAW.js";
|
|
70
70
|
import {
|
|
71
71
|
settleWithFacilitator,
|
|
72
72
|
verifyWithFacilitator
|
|
73
73
|
} from "../chunk-BQ2NMWKE.js";
|
|
74
|
-
import "../chunk-
|
|
74
|
+
import "../chunk-U5VNEALI.js";
|
|
75
75
|
import {
|
|
76
76
|
SIGNED_ENVELOPE_FIELDS,
|
|
77
77
|
SIGNED_ENVELOPE_TYPES,
|
|
@@ -88,18 +88,18 @@ import {
|
|
|
88
88
|
isYieldMessage,
|
|
89
89
|
providerMessage,
|
|
90
90
|
toJobRecord
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-MD3H3BF7.js";
|
|
92
92
|
import {
|
|
93
93
|
toLockPubkey
|
|
94
|
-
} from "../chunk-
|
|
94
|
+
} from "../chunk-QX52F6IB.js";
|
|
95
95
|
import "../chunk-Z4BNLUZF.js";
|
|
96
|
-
import "../chunk-
|
|
96
|
+
import "../chunk-A4CM2BD3.js";
|
|
97
97
|
import "../chunk-MKI6OVW4.js";
|
|
98
98
|
import "../chunk-KXZUCCEY.js";
|
|
99
|
-
import "../chunk-
|
|
99
|
+
import "../chunk-YO56VCTQ.js";
|
|
100
100
|
import "../chunk-66HGCPBU.js";
|
|
101
101
|
import "../chunk-FUJ36YDV.js";
|
|
102
|
-
import "../chunk-
|
|
102
|
+
import "../chunk-4A2RAKCW.js";
|
|
103
103
|
import "../chunk-AT6V3SY7.js";
|
|
104
104
|
import {
|
|
105
105
|
NON_CHANNEL_BITCOIN_RAILS,
|
|
@@ -110,13 +110,13 @@ import {
|
|
|
110
110
|
isNonChannelBitcoinRail,
|
|
111
111
|
lotOwedSats,
|
|
112
112
|
netOwedSats
|
|
113
|
-
} from "../chunk-
|
|
114
|
-
import "../chunk-
|
|
113
|
+
} from "../chunk-2D75MNNG.js";
|
|
114
|
+
import "../chunk-COYKJRMM.js";
|
|
115
115
|
import "../chunk-C3MTFLC6.js";
|
|
116
116
|
import {
|
|
117
117
|
_testing,
|
|
118
118
|
wrapMppx
|
|
119
|
-
} from "../chunk-
|
|
119
|
+
} from "../chunk-XZ7LW4S5.js";
|
|
120
120
|
export {
|
|
121
121
|
DEFAULT_LOCK_PUBKEY_GRACE_SECONDS,
|
|
122
122
|
JobCancelledError,
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ProofLike } from '@cashu/cashu-ts';
|
|
2
|
-
import { a1 as Message, ah as FundingMethod, X as FundingReceipt, bO as CreditSnapshot, Y as JobReceipt, ax as StepRecord, a2 as MessageType } from './step-cache-
|
|
2
|
+
import { a1 as Message, ah as FundingMethod, X as FundingReceipt, bO as CreditSnapshot, Y as JobReceipt, ax as StepRecord, a2 as MessageType } from './step-cache-v2yhyhSZ.js';
|
|
3
3
|
|
|
4
|
-
/** Job status values that can be persisted. */
|
|
5
4
|
type JobStatus = "processing" | "completed" | "failed" | "awaiting-input" | "cancelled" | "working";
|
|
6
|
-
/** Serializable snapshot of a job's persistent state. */
|
|
7
5
|
interface JobRecord {
|
|
8
6
|
id: string;
|
|
9
7
|
tags: string[];
|
|
10
8
|
/**
|
|
11
|
-
* Capability name this job dispatches to
|
|
9
|
+
* Capability name this job dispatches to. Populated from the
|
|
12
10
|
* `POST /v1/job` body's `capability` field at submission time; persisted
|
|
13
11
|
* so reactivation on another machine routes to the same handler.
|
|
14
12
|
*/
|
|
@@ -18,7 +16,7 @@ interface JobRecord {
|
|
|
18
16
|
requesterId: string;
|
|
19
17
|
/**
|
|
20
18
|
* SHA-256 hex of the per-job opaque token issued at creation time for
|
|
21
|
-
* anonymous requesters
|
|
19
|
+
* anonymous requesters. When set, all `/v1/job/:id/*` reads/writes
|
|
22
20
|
* gate on the caller presenting the matching `X-Job-Token` header — this is
|
|
23
21
|
* the mechanism that prevents cross-caller transcript leaks for free DVMs
|
|
24
22
|
* where every caller otherwise resolves to `requesterId === "anonymous"`.
|
|
@@ -27,7 +25,7 @@ interface JobRecord {
|
|
|
27
25
|
*/
|
|
28
26
|
requesterTokenHash?: string;
|
|
29
27
|
/**
|
|
30
|
-
* The `job_token` itself, in the clear
|
|
28
|
+
* The `job_token` itself, in the clear. Kept so a caller whose
|
|
31
29
|
* paid submit timed out can replay it and be handed back the very token the
|
|
32
30
|
* lost response carried — the alternative (minting a fresh one) would be
|
|
33
31
|
* rejected by whichever machine is still running the job, since its
|
|
@@ -41,14 +39,14 @@ interface JobRecord {
|
|
|
41
39
|
*/
|
|
42
40
|
requesterToken?: string;
|
|
43
41
|
/**
|
|
44
|
-
* Fingerprint of the submission that created this job
|
|
42
|
+
* Fingerprint of the submission that created this job — see
|
|
45
43
|
* `requestFingerprint`. The replay gate: a retried paid submit is handed the
|
|
46
44
|
* original job only when it reproduces this.
|
|
47
45
|
*/
|
|
48
46
|
requestFingerprint?: string;
|
|
49
47
|
/**
|
|
50
48
|
* secp256k1 x-only pubkey of the caller that signed the submission, on
|
|
51
|
-
* DVMs with descriptor-level auth
|
|
49
|
+
* DVMs with descriptor-level auth. Second half of the replay
|
|
52
50
|
* gate — the signature envelope is re-minted on every resume attempt, so
|
|
53
51
|
* the identity behind it is pinned here instead.
|
|
54
52
|
*/
|
|
@@ -58,32 +56,44 @@ interface JobRecord {
|
|
|
58
56
|
/** HTTP path whose live auth gate accepted the persisted caller proof. */
|
|
59
57
|
authRequestPath?: string;
|
|
60
58
|
status: JobStatus;
|
|
59
|
+
/** False on jobs accepted before complete lifecycle timing was available. */
|
|
60
|
+
timingKnown?: boolean;
|
|
61
|
+
/** SDK terminal attribution; never accepted from a handler. */
|
|
62
|
+
endedBy?: "caller" | "provider";
|
|
63
|
+
/** Unix ms when the terminal status committed; immutable afterwards. */
|
|
64
|
+
terminalAtMs?: number;
|
|
65
|
+
/** Accumulated awaiting-input time, excluding the currently open stretch. */
|
|
66
|
+
callerWaitMs?: number;
|
|
67
|
+
/** Unix ms at which the current awaiting-input stretch began. */
|
|
68
|
+
awaitingInputAtMs?: number;
|
|
61
69
|
summary?: string;
|
|
62
70
|
messages: Message[];
|
|
63
71
|
seq: number;
|
|
64
72
|
paidMsats: number;
|
|
65
73
|
paymentMint?: string;
|
|
66
|
-
/** Rail of the most recent successful credit (cashu / x402 /
|
|
74
|
+
/** Rail of the most recent successful credit (cashu / x402 / tempo). */
|
|
67
75
|
paymentRail?: FundingMethod;
|
|
68
76
|
/**
|
|
69
77
|
* Settlement reference threaded into the platform revenue ledger
|
|
70
78
|
* (`revenue_events.tx_hash`). EVM tx hash for x402, mppx `challenge.id`
|
|
71
|
-
* for mpp
|
|
72
|
-
* `X-Cashu-Request-Id` UUID
|
|
79
|
+
* for mpp; cashu accumulator path sets this to the
|
|
80
|
+
* `X-Cashu-Request-Id` UUID. Persisted so it survives durable
|
|
73
81
|
* replay.
|
|
74
82
|
*/
|
|
75
83
|
paymentTxHash?: string;
|
|
76
84
|
/** Chain transaction returned to callers recovering x402 or Tempo acceptance. */
|
|
77
85
|
paymentTransactionHash?: string;
|
|
78
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Accumulated same-rail stablecoin micro-units for Tempo/x402; resets when the rail changes.
|
|
88
|
+
* Cashu revenue uses paidMsats.
|
|
89
|
+
*/
|
|
79
90
|
nativeAmount?: number;
|
|
80
|
-
/** Native asset tag
|
|
91
|
+
/** Native asset tag paired with `nativeAmount`. */
|
|
81
92
|
nativeAsset?: "sats" | "usdc" | "usdc.e" | "usd-cents";
|
|
82
|
-
/** Cashu flow discriminator written into `revenue_events.metadata.cashu_flow` (internal-review). */
|
|
83
93
|
cashuFlow?: "p2pk_accumulator";
|
|
84
94
|
/**
|
|
85
95
|
* What this job cost the **builder** to serve, in 1e-6 of
|
|
86
|
-
* {@link JobRecord.costCurrency}
|
|
96
|
+
* {@link JobRecord.costCurrency}. Mirror of
|
|
87
97
|
* `ServerJob.costAmountMicro`; see that field. Absent means unreported,
|
|
88
98
|
* which the platform treats differently from a declared zero.
|
|
89
99
|
*/
|
|
@@ -97,12 +107,12 @@ interface JobRecord {
|
|
|
97
107
|
*/
|
|
98
108
|
costRevision?: number;
|
|
99
109
|
/**
|
|
100
|
-
* Credit the upfront payment funded/drew
|
|
110
|
+
* Credit the upfront payment funded/drew. The terminal funnel
|
|
101
111
|
* settles the draw on success and releases it on failure/cancel, and the
|
|
102
112
|
* receipt countersigns the `ReceiptCredit` block from it.
|
|
103
113
|
*/
|
|
104
114
|
creditId?: string;
|
|
105
|
-
/** The draw placed for this job on `creditId
|
|
115
|
+
/** The draw placed for this job on `creditId`. */
|
|
106
116
|
drawId?: string;
|
|
107
117
|
/** Funding-time evidence returned on explicit fund-and-draw submissions. */
|
|
108
118
|
fundingReceipt?: FundingReceipt;
|
|
@@ -110,11 +120,11 @@ interface JobRecord {
|
|
|
110
120
|
receivedProofs: ProofLike[];
|
|
111
121
|
pendingPaymentMsats?: number;
|
|
112
122
|
/**
|
|
113
|
-
* Per-job MPP credential binding
|
|
123
|
+
* Per-job MPP credential binding. Challenge ids issued in the
|
|
114
124
|
* most-recent `requestPayment` yield; the SDK rejects mid-job credentials
|
|
115
125
|
* whose `challenge.id` isn't in this set.
|
|
116
126
|
*
|
|
117
|
-
* Keeps its `mpp` spelling past
|
|
127
|
+
* Keeps its `mpp` spelling past rail rename. The ids
|
|
118
128
|
* are mppx challenge ids — objects of the MPP envelope the Tempo rail rides,
|
|
119
129
|
* which is not itself a rail — and this is server-internal anti-replay state
|
|
120
130
|
* that is never serialised to a caller. It persists as
|
|
@@ -122,7 +132,7 @@ interface JobRecord {
|
|
|
122
132
|
*/
|
|
123
133
|
pendingMppChallengeIds?: string[];
|
|
124
134
|
/**
|
|
125
|
-
* Per-job x402 credential binding
|
|
135
|
+
* Per-job x402 credential binding. 0x-prefixed 32-byte hex nonce
|
|
126
136
|
* issued in the most-recent `requestPayment` yield; the SDK rejects mid-job
|
|
127
137
|
* x402 payments whose decoded `authorization.nonce` differs from this value.
|
|
128
138
|
*/
|
|
@@ -135,7 +145,7 @@ interface JobRecord {
|
|
|
135
145
|
pendingX402AmountUsdcMicro?: string;
|
|
136
146
|
/**
|
|
137
147
|
* The outstanding `requestPayment` ask denominated in fiat micro-units, pinned
|
|
138
|
-
* when the payment-request was emitted
|
|
148
|
+
* when the payment-request was emitted — the mid-job analogue of
|
|
139
149
|
* `resolvePriceFiat` pinning the quote. The ledger is fiat-denominated, so the
|
|
140
150
|
* top-up's `fund` + `growDraw` need a figure that doesn't move with the BTC/USD
|
|
141
151
|
* rate between the ask and the payment. Absent when the ask couldn't be priced
|
|
@@ -146,7 +156,7 @@ interface JobRecord {
|
|
|
146
156
|
pendingPaymentFiatCurrency?: string;
|
|
147
157
|
/**
|
|
148
158
|
* What this job has **cumulatively** asked for mid-job, in fiat micro-units
|
|
149
|
-
* of {@link askedTopUpCurrency}
|
|
159
|
+
* of {@link askedTopUpCurrency} — the ceiling `growDraw` caps the
|
|
150
160
|
* job's draw growth at. Monotonic: written by the same Tx A that emits each
|
|
151
161
|
* payment-request, and never decremented, which is exactly what
|
|
152
162
|
* `pendingPaymentFiatMicro` is not (Tx C drains it as payments land). A cap
|
|
@@ -154,7 +164,7 @@ interface JobRecord {
|
|
|
154
164
|
* in the window before Tx C see a full ask that the winner had already
|
|
155
165
|
* bought.
|
|
156
166
|
*
|
|
157
|
-
* `-1` is a sticky "not expressible" sentinel — after
|
|
167
|
+
* `-1` is a sticky "not expressible" sentinel — after the one door
|
|
158
168
|
* left to it is an ask the rate provider was down for. Undefined means no
|
|
159
169
|
* mid-job ask has been recorded (including a row written before this
|
|
160
170
|
* existed). Either way the cap is skipped and growth is unbounded, as it was
|
|
@@ -163,13 +173,13 @@ interface JobRecord {
|
|
|
163
173
|
askedTopUpMicro?: number;
|
|
164
174
|
/**
|
|
165
175
|
* Currency of {@link askedTopUpMicro} (lowercase ISO-4217) — and, from
|
|
166
|
-
*
|
|
176
|
+
* the job's own ask denomination: first-write-wins, and read back
|
|
167
177
|
* by `ctx.requestPayment` so every later ask pins in it too. That is what
|
|
168
178
|
* makes a mid-job currency switch unexpressible rather than merely unlikely.
|
|
169
179
|
*/
|
|
170
180
|
askedTopUpCurrency?: string;
|
|
171
181
|
/**
|
|
172
|
-
* Why this job's draw growth is **not** capped, when it isn't
|
|
182
|
+
* Why this job's draw growth is **not** capped, when it isn't —
|
|
173
183
|
* the durable half of the `-1` sentinel, so an operator can list the affected
|
|
174
184
|
* jobs after the fact rather than reconstruct them from log lines. Sticky
|
|
175
185
|
* first-writer-wins, like the sentinel itself. Null on every job whose ceiling
|
|
@@ -179,7 +189,7 @@ interface JobRecord {
|
|
|
179
189
|
/** Price the job was charged at (msats). Used to detect overpayment for change/melt gating. */
|
|
180
190
|
requiredMsats?: number;
|
|
181
191
|
/**
|
|
182
|
-
* The DVM-signed proof of this job's outcome
|
|
192
|
+
* The DVM-signed proof of this job's outcome. Written once at the
|
|
183
193
|
* terminal transition via `saveReceipt` and never rewritten — `save` leaves
|
|
184
194
|
* the column alone so a stale in-memory snapshot can't clear it. Absent on
|
|
185
195
|
* non-terminal jobs, and on every job when the DVM has no receipt key wired.
|
|
@@ -194,8 +204,8 @@ interface JobRecord {
|
|
|
194
204
|
}
|
|
195
205
|
/**
|
|
196
206
|
* Counter snapshot used by the NOTIFY-driven resolver and the
|
|
197
|
-
* `verifyAndCredit` flow
|
|
198
|
-
* needed to decide whether a pending payment yield can resolve, plus
|
|
207
|
+
* `verifyAndCredit` flow. Carries just the handler-visible state
|
|
208
|
+
* needed to decide whether a pending payment yield can resolve, plus
|
|
199
209
|
* the terminal reason so a machine adopting another machine's cancel can hand
|
|
200
210
|
* the caller's own words to `ctx.signal.reason` and the `onCancel` hook.
|
|
201
211
|
*/
|
|
@@ -211,7 +221,7 @@ interface JobCounters {
|
|
|
211
221
|
summary?: string;
|
|
212
222
|
}
|
|
213
223
|
/**
|
|
214
|
-
* Credit delta written inside the Tx C transaction
|
|
224
|
+
* Credit delta written inside the Tx C transaction when an
|
|
215
225
|
* inbound payment verifies. Fields mirror what the rails produce in
|
|
216
226
|
* `payment.ts`; `paidMsatsDelta` is the only required key.
|
|
217
227
|
*/
|
|
@@ -230,7 +240,7 @@ interface PaymentCreditDelta {
|
|
|
230
240
|
/** Clear the pending nonce + advertised amount after an x402 credit succeeds. */
|
|
231
241
|
clearPendingX402Binding?: boolean;
|
|
232
242
|
/**
|
|
233
|
-
* Credit this payment funded
|
|
243
|
+
* Credit this payment funded. Only ever set when the mid-job
|
|
234
244
|
* top-up minted a *fresh* implicit credit — a free-then-paid job whose
|
|
235
245
|
* upfront leg placed no draw. Written set-if-null: a job already bound to a
|
|
236
246
|
* credit keeps that binding, because the top-up grew its existing draw
|
|
@@ -242,12 +252,14 @@ interface PaymentCreditDelta {
|
|
|
242
252
|
}
|
|
243
253
|
/** Atomic side effects applied with an outgoing provider message. */
|
|
244
254
|
interface AppendOutgoingOptions {
|
|
255
|
+
/** A suspending SDK prompt/payment yield; event-driven messages leave status unchanged. */
|
|
256
|
+
awaitingInput?: boolean;
|
|
245
257
|
pendingPaymentDelta?: number;
|
|
246
258
|
pendingMppChallengeIds?: string[];
|
|
247
259
|
pendingX402Nonce?: string;
|
|
248
260
|
pendingX402AmountUsdcMicro?: string;
|
|
249
261
|
/**
|
|
250
|
-
* Fiat envelope pinned for this ask
|
|
262
|
+
* Fiat envelope pinned for this ask. Accumulates alongside
|
|
251
263
|
* `pendingPaymentDelta` when the currency matches what's already recorded,
|
|
252
264
|
* and replaces it when it doesn't — the same shape `pending_payment_msats`
|
|
253
265
|
* uses, so stacked asks stay summable.
|
|
@@ -256,16 +268,16 @@ interface AppendOutgoingOptions {
|
|
|
256
268
|
pendingPaymentFiatCurrency?: string;
|
|
257
269
|
}
|
|
258
270
|
/**
|
|
259
|
-
* Why a job's cumulative ask total can't bound its draw growth
|
|
271
|
+
* Why a job's cumulative ask total can't bound its draw growth.
|
|
260
272
|
*
|
|
261
273
|
* - `ask_unpriceable` — an ask the rate provider was down for, or one whose
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
274
|
+
* fiat figure isn't a safe integer. The only door left after and
|
|
275
|
+
* deliberately still open: failing the charge to protect a ledger comparison
|
|
276
|
+
* would break a payment that doesn't need the rate to be quoted or collected.
|
|
265
277
|
* - `ask_currency_switch` — two asks on one job in different denominations.
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
278
|
+
* Unreachable through `ctx.requestPayment`, which pins every ask in the job's
|
|
279
|
+
* own sticky denomination; kept as the backstop for a record written by an
|
|
280
|
+
* older build, and because the accumulator must not silently sum two units.
|
|
269
281
|
*/
|
|
270
282
|
type TopUpCapUnenforcedReason = "ask_unpriceable" | "ask_currency_switch";
|
|
271
283
|
/**
|
|
@@ -278,7 +290,7 @@ interface VerifyAndCreditResult {
|
|
|
278
290
|
alreadyVerified: boolean;
|
|
279
291
|
/**
|
|
280
292
|
* The credit the job row holds **after** this call — the authoritative
|
|
281
|
-
* answer, read back rather than assumed
|
|
293
|
+
* answer, read back rather than assumed.
|
|
282
294
|
*
|
|
283
295
|
* {@link PaymentCreditDelta.creditId} is written set-if-null, so a caller
|
|
284
296
|
* that passes one cannot know whether it won the bind: on a free-then-paid
|
|
@@ -313,12 +325,10 @@ interface RequestIdClaimResult {
|
|
|
313
325
|
/** True when the durable identity binding existed before this lock acquisition. */
|
|
314
326
|
replayed: boolean;
|
|
315
327
|
}
|
|
316
|
-
/** Persistent backing store for job records. */
|
|
317
328
|
interface JobStore {
|
|
318
|
-
/** Retrieve a job record by ID. Returns undefined if not found. */
|
|
319
329
|
get(id: string): Promise<JobRecord | undefined>;
|
|
320
330
|
/**
|
|
321
|
-
* Retrieve the job a settlement reference paid for
|
|
331
|
+
* Retrieve the job a settlement reference paid for. On the cashu
|
|
322
332
|
* accumulator path `paymentTxHash` is the caller's `X-Cashu-Request-Id`, so
|
|
323
333
|
* this is what makes a retried paid submit idempotent: the replay finds the
|
|
324
334
|
* job its (already-spent) payment created instead of a bare 409.
|
|
@@ -345,9 +355,7 @@ interface JobStore {
|
|
|
345
355
|
* durable caller/fingerprint/job binding remains retained.
|
|
346
356
|
*/
|
|
347
357
|
releaseRequestIdClaim?(claim: RequestIdClaim): Promise<void>;
|
|
348
|
-
/** Upsert a job record. */
|
|
349
358
|
save(record: JobRecord): Promise<void>;
|
|
350
|
-
/** Delete a job record. */
|
|
351
359
|
delete(id: string): Promise<void>;
|
|
352
360
|
}
|
|
353
361
|
/** Total-order cursor for terminal job retention scans. */
|
|
@@ -356,7 +364,7 @@ interface JobRetentionCursor {
|
|
|
356
364
|
id: string;
|
|
357
365
|
}
|
|
358
366
|
/**
|
|
359
|
-
* JobStore extension for signed job receipts
|
|
367
|
+
* JobStore extension for signed job receipts. Implemented by both
|
|
360
368
|
* container-tier stores (`MemoryJobStore`, `PostgresJobStore`); the isolate
|
|
361
369
|
* tier's `IsolateJobStore` deliberately doesn't, which is what keeps the
|
|
362
370
|
* out-of-scope isolate gap a compile-time fact rather than a runtime surprise.
|
|
@@ -385,24 +393,24 @@ interface ReceiptIssuingStore {
|
|
|
385
393
|
saveReceipt(jobId: string, receipt: JobReceipt): Promise<JobReceipt | undefined>;
|
|
386
394
|
}
|
|
387
395
|
/**
|
|
388
|
-
* JobStore extension for cross-machine message streaming + the
|
|
396
|
+
* JobStore extension for cross-machine message streaming + the
|
|
389
397
|
* transactional model (Tx A / Tx B / Tx C).
|
|
390
398
|
*
|
|
391
399
|
* Tx A — outgoing message + immediate counter consequence (`appendOutgoing`).
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
400
|
+
* Single tx: server-allocate seq, append `job_messages` row with
|
|
401
|
+
* `status='verified'`, bump `pending_payment_msats` for payment-request
|
|
402
|
+
* messages, and `pg_notify`.
|
|
395
403
|
*
|
|
396
404
|
* Tx B — incoming message marked `pending-verification` (`recordInbound`).
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
405
|
+
* Single tx: server-allocate seq, append `job_messages` row with
|
|
406
|
+
* `status='pending-verification'`, and `pg_notify`. External verification
|
|
407
|
+
* (Cashu mint, x402 facilitator, MPP server) runs OUTSIDE the tx.
|
|
400
408
|
*
|
|
401
409
|
* Tx C — verification outcome + credit (`verifyAndCredit`). Single tx:
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
410
|
+
* flip the `job_messages.status` to `'verified'`, bump `paid_msats` /
|
|
411
|
+
* clear `pending_payment_msats` per the credit delta, and `pg_notify`.
|
|
412
|
+
* Idempotent — a repeat call returns `alreadyVerified: true` without
|
|
413
|
+
* re-crediting.
|
|
406
414
|
*/
|
|
407
415
|
interface StreamableJobStore extends JobStore {
|
|
408
416
|
/**
|
|
@@ -430,7 +438,7 @@ interface StreamableJobStore extends JobStore {
|
|
|
430
438
|
verifyAndCredit(jobId: string, seq: number, credit: PaymentCreditDelta | null): Promise<VerifyAndCreditResult>;
|
|
431
439
|
/**
|
|
432
440
|
* Read back what Tx C committed for an inbound message, without opening a
|
|
433
|
-
* transaction of its own
|
|
441
|
+
* transaction of its own.
|
|
434
442
|
*
|
|
435
443
|
* A `verifyAndCredit` that throws is ambiguous: the error may have been
|
|
436
444
|
* raised at or after its COMMIT, in which case the write is durable and the
|
|
@@ -454,7 +462,7 @@ interface StreamableJobStore extends JobStore {
|
|
|
454
462
|
/** Read the counters used by the resolver (status / paid / pending). */
|
|
455
463
|
getCounters(jobId: string): Promise<JobCounters | undefined>;
|
|
456
464
|
/**
|
|
457
|
-
* Single-execution claim
|
|
465
|
+
* Single-execution claim. Atomically flip a job from
|
|
458
466
|
* `awaiting-input` to `processing`, returning `true` only for the caller
|
|
459
467
|
* that won the transition. After a mid-job payment lands cross-machine, the
|
|
460
468
|
* live original handler (woken via NOTIFY) and a reactivation replay on the
|
|
@@ -490,13 +498,13 @@ interface StreamableJobStore extends JobStore {
|
|
|
490
498
|
/**
|
|
491
499
|
* Subscribe to raw NOTIFY events for a job. Fires once per `pg_notify`
|
|
492
500
|
* delivery; no message decoding. Used by `Context.requestPayment` to
|
|
493
|
-
* re-read counters when cross-machine credit lands
|
|
501
|
+
* re-read counters when cross-machine credit lands.
|
|
494
502
|
*/
|
|
495
503
|
subscribeNotifications(jobId: string, onNotify: () => void): Promise<() => void>;
|
|
496
504
|
/** Read messages from the `job_messages` table for a job. */
|
|
497
505
|
getMessages(jobId: string, afterSeq: number): Promise<Message[]>;
|
|
498
506
|
/**
|
|
499
|
-
* Find stale non-terminal jobs
|
|
507
|
+
* Find stale non-terminal jobs. Two status-aware
|
|
500
508
|
* cutoffs (both Unix ms): `processing`/`working` rows older than
|
|
501
509
|
* `processingThresholdMs` (worker-liveness watchdog — the SDK heartbeats
|
|
502
510
|
* live workers, so a frozen `last_activity_at` here means the worker died),
|
|
@@ -515,7 +523,7 @@ interface StreamableJobStore extends JobStore {
|
|
|
515
523
|
/**
|
|
516
524
|
* Atomically transition a stale job to `terminalStatus` (`failed` for a
|
|
517
525
|
* dead worker, `cancelled` for an idle caller-wait) and append a final
|
|
518
|
-
* `cancel` message in the same transaction
|
|
526
|
+
* `cancel` message in the same transaction. The
|
|
519
527
|
* `expectedActivityBefore` clause is an optimistic CAS — the flip only
|
|
520
528
|
* lands when the job is still non-terminal AND `last_activity_at <=
|
|
521
529
|
* expectedActivityBefore`. Returns true when this caller claimed the
|
|
@@ -525,8 +533,8 @@ interface StreamableJobStore extends JobStore {
|
|
|
525
533
|
*/
|
|
526
534
|
cancelStaleJob(jobId: string, expectedActivityBefore: number, reason: string, terminalStatus: "failed" | "cancelled"): Promise<boolean>;
|
|
527
535
|
/**
|
|
528
|
-
* Atomically cancel a job from a machine that isn't running its handler
|
|
529
|
-
*
|
|
536
|
+
* Atomically cancel a job from a machine that isn't running its handler.
|
|
537
|
+
* Same transaction shape as {@link cancelStaleJob} minus the
|
|
530
538
|
* activity cutoff — the CAS guards only on the job still being non-terminal,
|
|
531
539
|
* so this replaces the read-then-`save` the DELETE route used to do (a TOCTOU
|
|
532
540
|
* against a concurrent terminal write).
|
|
@@ -541,7 +549,7 @@ interface StreamableJobStore extends JobStore {
|
|
|
541
549
|
cancelJob(jobId: string, reason: string): Promise<boolean>;
|
|
542
550
|
/**
|
|
543
551
|
* Bump `last_activity_at` to `now` (Unix ms) for the given jobs that are
|
|
544
|
-
* still in `processing`/`working
|
|
552
|
+
* still in `processing`/`working`. Called on a
|
|
545
553
|
* tick by the `JobManager` for its locally-active jobs so a live worker's
|
|
546
554
|
* row stays fresh and the processing watchdog only fires when the process
|
|
547
555
|
* has actually died. A no-op for rows that have since gone terminal or
|
|
@@ -571,7 +579,7 @@ interface OutgoingMessage {
|
|
|
571
579
|
*/
|
|
572
580
|
declare function isStreamableJobStore(store: JobStore): store is StreamableJobStore;
|
|
573
581
|
/**
|
|
574
|
-
* The stale-job reaper surface
|
|
582
|
+
* The stale-job reaper surface — the two methods a sweeper needs to
|
|
575
583
|
* find and atomically reap worker-stranded jobs. A strict subset of
|
|
576
584
|
* `StreamableJobStore`: `MemoryJobStore` and `PostgresJobStore` satisfy it via
|
|
577
585
|
* the full streamable interface, and the platform's `IsolateJobStore` (a plain
|
|
@@ -585,7 +593,6 @@ interface StaleJobReapable {
|
|
|
585
593
|
/** See {@link StreamableJobStore.cancelStaleJob}. */
|
|
586
594
|
cancelStaleJob(jobId: string, expectedActivityBefore: number, reason: string, terminalStatus: "failed" | "cancelled"): Promise<boolean>;
|
|
587
595
|
}
|
|
588
|
-
/** Runtime type guard for StaleJobReapable. */
|
|
589
596
|
declare function isStaleJobReapable(store: JobStore): store is JobStore & StaleJobReapable;
|
|
590
597
|
|
|
591
598
|
export { type AppendOutgoingOptions as A, type JobRecord as J, type OutgoingMessage as O, type PaymentCreditDelta as P, type ReceiptIssuingStore as R, type StaleJobReapable as S, type TopUpCapUnenforcedReason as T, type VerifyAndCreditResult as V, type JobStatus as a, type JobStore as b, type StreamableJobStore as c, type RequestIdClaim as d, type RequestIdClaimResult as e, type JobRetentionCursor as f, type JobCounters as g, isStreamableJobStore as h, isStaleJobReapable as i };
|