@dvmkit/sdk 0.1.2-rc.7 → 0.1.4-rc.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/README.md +121 -8
- package/dist/chunk-BIFLRKMO.js +87 -0
- package/dist/chunk-BQ2NMWKE.js +160 -0
- package/dist/{chunk-LDTWX7JW.js → chunk-BTZY7VPH.js} +13 -1
- package/dist/{chunk-FJDCFHW5.js → chunk-C6JHBLMW.js} +3 -81
- package/dist/{chunk-EXHBXA4U.js → chunk-DBCLBYHP.js} +13 -1
- package/dist/chunk-E4EVGPDX.js +391 -0
- package/dist/chunk-EDDYHZ6W.js +1010 -0
- package/dist/{chunk-2ABMGUDS.js → chunk-EVBK675R.js} +88 -10
- package/dist/{chunk-P4RUVDU7.js → chunk-H2MEFVH6.js} +12 -141
- package/dist/chunk-KXZUCCEY.js +142 -0
- package/dist/{chunk-LWUR4CGG.js → chunk-MLRCSJYX.js} +11 -3
- package/dist/{chunk-N4VTG3KH.js → chunk-QK3VJNCK.js} +930 -3011
- package/dist/chunk-RW5LP57K.js +44 -0
- package/dist/{chunk-6JZIX5WW.js → chunk-SSSZUVWM.js} +178 -8
- package/dist/{chunk-TKA6ZP4M.js → chunk-U6M3ATSG.js} +56 -426
- package/dist/chunk-VRQDX5P4.js +1742 -0
- package/dist/{chunk-JGGI65I3.js → chunk-Z4BNLUZF.js} +1 -150
- package/dist/{credit-ledger-ED6JXKVD.js → credit-ledger-2DFQHNLB.js} +2 -2
- package/dist/{credit-menu-BM4qCD5U.d.ts → credit-menu-C1ezIFlJ.d.ts} +1699 -1941
- package/dist/{fx-C-liI3oY.d.ts → fx-C6dl2LVI.d.ts} +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +8 -4
- package/dist/internal/caller.d.ts +10441 -0
- package/dist/internal/caller.js +10078 -0
- package/dist/internal/index.d.ts +2 -10816
- package/dist/internal/index.js +2 -10130
- package/dist/internal/server.d.ts +404 -0
- package/dist/internal/server.js +202 -0
- package/dist/job-store-DHnW4Cg_.d.ts +591 -0
- package/dist/lightning-backend-Ci1nogk_.d.ts +367 -0
- package/dist/{memory-credit-ledger-XJ5VQEVP.js → memory-credit-ledger-OP24Z2KO.js} +3 -3
- package/dist/{postgres-job-store-J5F4GUWU.js → postgres-job-store-3RAXMNSY.js} +1 -1
- package/dist/{revenue-reporter-JIKUPXOK.js → revenue-reporter-ASZ7SHHH.js} +1 -1
- package/dist/server/index.d.ts +41 -11
- package/dist/server/index.js +93 -69
- package/dist/{job-store-C53VQ5uu.d.ts → step-cache-BLPZNizw.d.ts} +176 -585
- package/dist/{tempo-session-store-DALMRIWN.js → tempo-session-store-2JNOKJGX.js} +2 -2
- package/dist/testing/index.d.ts +25 -3
- package/dist/testing/index.js +36 -3
- package/dist/{usd-gLcJB1ps.d.ts → usd-BgOfZlk6.d.ts} +1 -1
- package/dist/wallet-CJC8lwxx.d.ts +29 -0
- package/dist/{x402-FTG2GRAQ.js → x402-T2C5MX3T.js} +6 -3
- package/package.json +11 -5
- package/dist/{chunk-RU7SXHLO.js → chunk-UP2F5RRT.js} +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PostgresTempoSessionStore,
|
|
3
3
|
assertMonotonicTransition
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UP2F5RRT.js";
|
|
5
5
|
import "./chunk-YG7G4DPZ.js";
|
|
6
|
-
import "./chunk-C3MTFLC6.js";
|
|
7
6
|
import "./chunk-S3XAHZQY.js";
|
|
7
|
+
import "./chunk-C3MTFLC6.js";
|
|
8
8
|
export {
|
|
9
9
|
PostgresTempoSessionStore,
|
|
10
10
|
assertMonotonicTransition
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '
|
|
1
|
+
import { Y as JobReceipt, a1 as Message, a2 as MessageType, K as KVStore, L as Logger, u as ResponseContent, P as PaymentContent, S as SDKJobContext } from '../step-cache-BLPZNizw.js';
|
|
2
|
+
import { c as StreamableJobStore, R as ReceiptIssuingStore, J as JobRecord, d as RequestIdClaim, e as RequestIdClaimResult, f as JobRetentionCursor, O as OutgoingMessage, A as AppendOutgoingOptions, P as PaymentCreditDelta, V as VerifyAndCreditResult, g as JobCounters } from '../job-store-DHnW4Cg_.js';
|
|
3
|
+
import 'hono';
|
|
3
4
|
import 'mppx';
|
|
4
5
|
import '@x402/core/server';
|
|
5
6
|
import '@x402/evm/batch-settlement/server';
|
|
6
|
-
import 'hono';
|
|
7
7
|
import 'viem';
|
|
8
8
|
import 'pg';
|
|
9
9
|
import '@x402/core/types';
|
|
10
10
|
import 'zod';
|
|
11
|
+
import '@cashu/cashu-ts';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* In-memory JobStore implementing the transactional + streaming surface
|
|
@@ -34,6 +35,17 @@ declare class MemoryJobStore implements StreamableJobStore, ReceiptIssuingStore
|
|
|
34
35
|
releaseRequestIdClaim(claim: RequestIdClaim): Promise<void>;
|
|
35
36
|
save(record: JobRecord): Promise<void>;
|
|
36
37
|
delete(id: string): Promise<void>;
|
|
38
|
+
listJobsForRetention(args: {
|
|
39
|
+
lastActivityBeforeMs: number;
|
|
40
|
+
limit: number;
|
|
41
|
+
capabilities: string[] | null;
|
|
42
|
+
after?: JobRetentionCursor;
|
|
43
|
+
}): Promise<JobRecord[]>;
|
|
44
|
+
redactJob(args: {
|
|
45
|
+
jobId: string;
|
|
46
|
+
expectedLastActivityAt: number;
|
|
47
|
+
redactedAt: number;
|
|
48
|
+
}): Promise<boolean>;
|
|
37
49
|
claimReceiptSeq(jobId: string): Promise<number>;
|
|
38
50
|
saveReceipt(jobId: string, receipt: JobReceipt): Promise<JobReceipt | undefined>;
|
|
39
51
|
appendOutgoing(jobId: string, message: OutgoingMessage, opts?: AppendOutgoingOptions): Promise<number>;
|
|
@@ -119,6 +131,16 @@ interface TestJobContext<State = Record<string, unknown>, Input = string> extend
|
|
|
119
131
|
readonly summary: string | undefined;
|
|
120
132
|
/** The error string passed to fail(). */
|
|
121
133
|
readonly failError: string | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* What the handler declared through `ctx.cost()`, summed, in 1e-6 of
|
|
136
|
+
* `currency` — exactly what the runtime would report to the platform.
|
|
137
|
+
* `undefined` when the handler declared nothing, and also when it declared
|
|
138
|
+
* two different currencies, which the runtime refuses to report.
|
|
139
|
+
*/
|
|
140
|
+
readonly reportedCost: {
|
|
141
|
+
amountMicro: number;
|
|
142
|
+
currency: string;
|
|
143
|
+
} | undefined;
|
|
122
144
|
/**
|
|
123
145
|
* Cancel the job under test (internal-review) — aborts `ctx.signal` exactly as a
|
|
124
146
|
* caller cancel, idle timeout, or stale-sweep would in the real runtime, and
|
package/dist/testing/index.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MemoryKVStore
|
|
3
|
+
} from "../chunk-RW5LP57K.js";
|
|
1
4
|
import {
|
|
2
5
|
JobCancelledError,
|
|
3
6
|
MemoryJobStore,
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
createInstrumentedFetch
|
|
8
|
+
} from "../chunk-U6M3ATSG.js";
|
|
9
|
+
import {
|
|
6
10
|
createNoopLogger
|
|
7
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-E4EVGPDX.js";
|
|
8
12
|
import "../chunk-66HGCPBU.js";
|
|
9
13
|
import "../chunk-FUJ36YDV.js";
|
|
14
|
+
import {
|
|
15
|
+
validateCurrency
|
|
16
|
+
} from "../chunk-27V2ILSR.js";
|
|
17
|
+
import "../chunk-AT6V3SY7.js";
|
|
10
18
|
|
|
11
19
|
// src/sdk/testing/test-context.ts
|
|
12
20
|
function createTestContext(opts) {
|
|
@@ -18,6 +26,10 @@ function createTestContext(opts) {
|
|
|
18
26
|
let refundRequested = false;
|
|
19
27
|
let summary;
|
|
20
28
|
let failError;
|
|
29
|
+
let costAmount = 0;
|
|
30
|
+
let costMicro = 0;
|
|
31
|
+
let costCurrency;
|
|
32
|
+
let costPoisoned = false;
|
|
21
33
|
const state = opts?.state !== void 0 ? structuredClone(opts.state) : {};
|
|
22
34
|
const store = opts?.store ?? new MemoryKVStore();
|
|
23
35
|
const env = opts?.env ?? {};
|
|
@@ -50,6 +62,10 @@ function createTestContext(opts) {
|
|
|
50
62
|
get failError() {
|
|
51
63
|
return failError;
|
|
52
64
|
},
|
|
65
|
+
get reportedCost() {
|
|
66
|
+
if (costPoisoned || costCurrency === void 0) return void 0;
|
|
67
|
+
return { amountMicro: costMicro, currency: costCurrency };
|
|
68
|
+
},
|
|
53
69
|
// --- Messaging ---
|
|
54
70
|
text(message) {
|
|
55
71
|
if (cancelled) return;
|
|
@@ -132,6 +148,23 @@ function createTestContext(opts) {
|
|
|
132
148
|
cancelled = true;
|
|
133
149
|
abort.abort(new JobCancelledError(reason));
|
|
134
150
|
},
|
|
151
|
+
// --- Accounting ---
|
|
152
|
+
cost(declared) {
|
|
153
|
+
if (cancelled) return;
|
|
154
|
+
const currency = validateCurrency(declared.currency);
|
|
155
|
+
const total = costAmount + declared.amount;
|
|
156
|
+
const micro = Math.round(total * 1e6);
|
|
157
|
+
if (!Number.isFinite(declared.amount) || declared.amount < 0 || !Number.isSafeInteger(micro)) {
|
|
158
|
+
throw new RangeError(
|
|
159
|
+
`ctx.cost amounts must each be a finite, non-negative number of currency units, and must total no more than ${Math.floor(Number.MAX_SAFE_INTEGER / 1e6)}; got ${String(declared.amount)}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (costCurrency !== void 0 && costCurrency !== currency) costPoisoned = true;
|
|
163
|
+
costCurrency ??= currency;
|
|
164
|
+
if (costPoisoned) return;
|
|
165
|
+
costAmount = total;
|
|
166
|
+
costMicro = micro;
|
|
167
|
+
},
|
|
135
168
|
// --- Durable execution ---
|
|
136
169
|
async step(_id, fn) {
|
|
137
170
|
return fn();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Wallet } from '@cashu/cashu-ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get or create a cashu-ts Wallet for a mint, calling loadMint() once per
|
|
5
|
+
* session.
|
|
6
|
+
*
|
|
7
|
+
* When the agent has a mnemonic on disk at `~/.dvm/wallet.mnemonic` AND
|
|
8
|
+
* the wallet's `mnemonic_fingerprint` matches it (internal-review), NUT-13
|
|
9
|
+
* deterministic secrets are eligible: the constructor receives `bip39seed`
|
|
10
|
+
* derived via `mnemonicToSeedSync` and a {@link PersistentCounterSource}
|
|
11
|
+
* backed by `wallet.nut13_counters`.
|
|
12
|
+
*
|
|
13
|
+
* NUT-13 is resolved per mint. Deterministic derivation is unsafe over an
|
|
14
|
+
* selected V1 output keyset (`id` prefix `00`) — the 2026-01 keyset-ID-collision
|
|
15
|
+
* disclosure — so a wallet bound to V1 is degraded to random-secret mode for
|
|
16
|
+
* that mint alone, rather than refused. Retired V1 keysets remain published so
|
|
17
|
+
* their proofs can be verified and spent, but cannot produce new outputs; a
|
|
18
|
+
* V2-bound wallet (`id` prefix `01`) keeps NUT-13. The
|
|
19
|
+
* {@link assertNoKeysetCollision} guard only protects the derivation path, so
|
|
20
|
+
* it runs only for mints where NUT-13 stays active.
|
|
21
|
+
*
|
|
22
|
+
* When the agent wallet or its sibling mnemonic file is absent (e.g. on a
|
|
23
|
+
* DVM server, or a CLI process that only touches the builder-side
|
|
24
|
+
* cashu-proofs flow), NUT-13 stays inactive everywhere — `new Wallet(mintUrl)`
|
|
25
|
+
* with no options, random secrets.
|
|
26
|
+
*/
|
|
27
|
+
declare function getWallet(mintUrl: string): Promise<Wallet>;
|
|
28
|
+
|
|
29
|
+
export { getWallet as g };
|
|
@@ -9,11 +9,14 @@ import {
|
|
|
9
9
|
resolveX402Asset,
|
|
10
10
|
saveX402Wallet,
|
|
11
11
|
tryX402Payment,
|
|
12
|
-
verifyX402Payment,
|
|
13
12
|
x402WrongAssetHint
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-C6JHBLMW.js";
|
|
15
14
|
import "./chunk-KSQEFVFJ.js";
|
|
16
15
|
import "./chunk-TSWKITGR.js";
|
|
16
|
+
import {
|
|
17
|
+
verifyX402Payment
|
|
18
|
+
} from "./chunk-BIFLRKMO.js";
|
|
19
|
+
import "./chunk-BQ2NMWKE.js";
|
|
17
20
|
import {
|
|
18
21
|
X402_DEFAULT_FACILITATOR,
|
|
19
22
|
X402_DEFAULT_NETWORK,
|
|
@@ -38,7 +41,7 @@ import {
|
|
|
38
41
|
x402NetworkListForCopy,
|
|
39
42
|
x402NetworkToCaip2,
|
|
40
43
|
x402SupportedNetworksHint
|
|
41
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-Z4BNLUZF.js";
|
|
42
45
|
import "./chunk-5URG56JJ.js";
|
|
43
46
|
import "./chunk-MKI6OVW4.js";
|
|
44
47
|
import "./chunk-66HGCPBU.js";
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvmkit/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4-rc.7",
|
|
4
4
|
"description": "SDK for building accountless, pay-per-use Digital Vending Machines",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/dvmkit/sdk.git"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://dvmkit.
|
|
10
|
+
"homepage": "https://dvmkit.com/docs/sdk",
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/dvmkit/sdk/issues"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
+
"sideEffects": false,
|
|
17
18
|
"type": "module",
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
@@ -41,24 +42,28 @@
|
|
|
41
42
|
"node": ">=22"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
|
-
"build": "NODE_OPTIONS=--max-old-space-size=6144 tsup --config tsup.config.ts && node scripts/prune-sdk-dist.mjs",
|
|
45
|
-
"check:api": "node scripts/check-api-surface.mjs",
|
|
45
|
+
"build": "NODE_OPTIONS=--max-old-space-size=6144 tsup --config tsup.config.ts && node scripts/write-internal-entry.mjs && node scripts/prune-sdk-dist.mjs",
|
|
46
|
+
"check:api": "node scripts/check-api-surface.mjs && node scripts/generate-api-reference.mjs --check",
|
|
46
47
|
"check:consumer": "node scripts/consumer-smoke.mjs",
|
|
48
|
+
"install-published-release": "node scripts/install-published-release.mjs",
|
|
47
49
|
"check:package": "node scripts/package-smoke.mjs",
|
|
48
50
|
"check:public-safety": "node scripts/public-safety.mjs",
|
|
49
51
|
"check:release": "node scripts/check-release.mjs",
|
|
50
52
|
"check:toolchain": "node scripts/check-toolchain.mjs",
|
|
53
|
+
"check:tree-shaking": "node scripts/check-internal-tree-shaking.mjs",
|
|
51
54
|
"clean-install-smoke": "node scripts/clean-install-smoke.mjs",
|
|
52
55
|
"lint": "eslint . --max-warnings 0",
|
|
56
|
+
"docs:api": "node scripts/generate-api-reference.mjs --write",
|
|
53
57
|
"release:tag": "node scripts/release-tag.mjs",
|
|
54
58
|
"test": "vitest run --config vitest.config.ts",
|
|
59
|
+
"test:examples": "node --test examples/quickstart/handler.test.mjs examples/authenticated-route/handler.test.mjs examples/payments-and-lifecycle/handler.test.mjs",
|
|
55
60
|
"test:db": "vitest run --config vitest.db.config.ts",
|
|
56
61
|
"typecheck": "tsc --noEmit",
|
|
57
62
|
"typecheck:scripts": "tsc --noEmit --project tsconfig.scripts.json",
|
|
58
63
|
"verify": "node scripts/verify.mjs"
|
|
59
64
|
},
|
|
60
65
|
"dependencies": {
|
|
61
|
-
"@cashu/cashu-ts": "4.2
|
|
66
|
+
"@cashu/cashu-ts": "4.10.2",
|
|
62
67
|
"@hono/node-server": "1.19.17",
|
|
63
68
|
"@noble/curves": "2.0.1",
|
|
64
69
|
"@noble/hashes": "2.0.1",
|
|
@@ -86,6 +91,7 @@
|
|
|
86
91
|
"@types/pg": "8.18.0",
|
|
87
92
|
"@types/proper-lockfile": "4.1.4",
|
|
88
93
|
"@types/ws": "8.18.1",
|
|
94
|
+
"esbuild": "0.27.7",
|
|
89
95
|
"eslint": "10.9.1",
|
|
90
96
|
"globals": "17.11.0",
|
|
91
97
|
"tsup": "8.5.1",
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
parseStoreValue,
|
|
3
3
|
stringifyStoreValue
|
|
4
4
|
} from "./chunk-YG7G4DPZ.js";
|
|
5
|
-
import {
|
|
6
|
-
withPostgresTransactionRecovery
|
|
7
|
-
} from "./chunk-C3MTFLC6.js";
|
|
8
5
|
import {
|
|
9
6
|
withSdkInitLock
|
|
10
7
|
} from "./chunk-S3XAHZQY.js";
|
|
8
|
+
import {
|
|
9
|
+
withPostgresTransactionRecovery
|
|
10
|
+
} from "./chunk-C3MTFLC6.js";
|
|
11
11
|
|
|
12
12
|
// src/sdk/server/tempo-session-store.ts
|
|
13
13
|
import { AsyncLocalStorage } from "async_hooks";
|