@dvmkit/sdk 0.1.3-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 +107 -8
- package/dist/{chunk-YDIYXGYL.js → chunk-E4EVGPDX.js} +16 -9
- package/dist/{chunk-EPNDZ5DH.js → chunk-EDDYHZ6W.js} +4 -4
- package/dist/{chunk-NFRM5QYP.js → chunk-EVBK675R.js} +5 -0
- package/dist/{chunk-3ZHMQCYP.js → chunk-QK3VJNCK.js} +329 -28
- package/dist/{chunk-LLXV32HA.js → chunk-SSSZUVWM.js} +96 -3
- package/dist/{chunk-4B56DEEV.js → chunk-U6M3ATSG.js} +7 -1
- package/dist/{chunk-2K7E3N2D.js → chunk-VRQDX5P4.js} +47 -14
- package/dist/{credit-menu-C7zAJElJ.d.ts → credit-menu-C1ezIFlJ.d.ts} +76 -4
- package/dist/{fx-BF_SG2i0.d.ts → fx-C6dl2LVI.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/internal/caller.d.ts +29 -17
- package/dist/internal/caller.js +150 -29
- package/dist/internal/server.d.ts +8 -8
- package/dist/internal/server.js +5 -5
- package/dist/{job-store-Bn23V3QU.d.ts → job-store-DHnW4Cg_.d.ts} +16 -1
- package/dist/{lightning-backend-C04nH94l.d.ts → lightning-backend-Ci1nogk_.d.ts} +1 -1
- package/dist/{postgres-job-store-TAONYLIF.js → postgres-job-store-3RAXMNSY.js} +1 -1
- package/dist/{revenue-reporter-XXSU5KVB.js → revenue-reporter-ASZ7SHHH.js} +1 -1
- package/dist/server/index.d.ts +22 -8
- package/dist/server/index.js +7 -7
- package/dist/{step-cache-3cT4Shk0.d.ts → step-cache-BLPZNizw.d.ts} +148 -3
- package/dist/testing/index.d.ts +13 -3
- package/dist/testing/index.js +31 -2
- package/dist/{usd-BnuXoFl5.d.ts → usd-BgOfZlk6.d.ts} +1 -1
- package/package.json +6 -4
|
@@ -4,8 +4,8 @@ import { FacilitatorClient } from '@x402/core/server';
|
|
|
4
4
|
import { AuthorizerSigner, ChannelStorage, AutoSettlementConfig, Channel, ChannelUpdateResult } from '@x402/evm/batch-settlement/server';
|
|
5
5
|
import { Account, Client, Hex } from 'viem';
|
|
6
6
|
import { Pool, PoolClient } from 'pg';
|
|
7
|
-
import { z } from 'zod';
|
|
8
7
|
import { PaymentPayload as PaymentPayload$1, PaymentRequirements as PaymentRequirements$1, SettleResponse as SettleResponse$1 } from '@x402/core/types';
|
|
8
|
+
import { z } from 'zod';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Currency-code identifier used throughout the SDK's pricing surface. Validated
|
|
@@ -1650,6 +1650,12 @@ interface RevenueReportPayload {
|
|
|
1650
1650
|
dvmId: string;
|
|
1651
1651
|
/** Required. Job identifier used by the platform to de-duplicate revenue rows and link to the job record. */
|
|
1652
1652
|
jobId: string;
|
|
1653
|
+
/**
|
|
1654
|
+
* Optional. Capability selected by dispatch for this job. Omitted for
|
|
1655
|
+
* reports from older SDKs and legacy persisted jobs that predate capability
|
|
1656
|
+
* dispatch; absence must not be rewritten as a capability name.
|
|
1657
|
+
*/
|
|
1658
|
+
capability?: string;
|
|
1653
1659
|
/** Required. Total amount paid by the caller in millisatoshis, across all credits that satisfied the job. */
|
|
1654
1660
|
paidMsats: number;
|
|
1655
1661
|
/** Optional. Cashu mint URL from which the payment tokens were issued. Set only for the `cashu` rail; omitted for all other rails. */
|
|
@@ -1686,6 +1692,28 @@ interface RevenueReportPayload {
|
|
|
1686
1692
|
* rows by source.
|
|
1687
1693
|
*/
|
|
1688
1694
|
cashuFlow?: string;
|
|
1695
|
+
/**
|
|
1696
|
+
* Optional. What the job cost the **builder** to serve, as declared by the
|
|
1697
|
+
* handler through `ctx.cost()` (internal-review) — the other half of the
|
|
1698
|
+
* margin the dashboard states. `amountMicro` is 1e-6 of `currency`, which
|
|
1699
|
+
* is the currency the builder incurred the cost in and need not be the
|
|
1700
|
+
* credit's.
|
|
1701
|
+
*
|
|
1702
|
+
* Never netted against `paidMsats` or `drawAmountMicro`: what the caller
|
|
1703
|
+
* paid and what serving them cost are two questions, so they are two fields.
|
|
1704
|
+
*
|
|
1705
|
+
* **Absent means unreported, not zero.** A handler that declares nothing
|
|
1706
|
+
* sends no `cost` key at all, and the platform shows the margin as unknown
|
|
1707
|
+
* rather than as 100%. A handler that declares `{ amount: 0 }` is making the
|
|
1708
|
+
* opposite, positive claim and sends `amountMicro: 0`.
|
|
1709
|
+
*
|
|
1710
|
+
* Additive on the wire: a platform build that does not read this key keeps
|
|
1711
|
+
* accepting the report unchanged.
|
|
1712
|
+
*/
|
|
1713
|
+
cost?: {
|
|
1714
|
+
amountMicro: number;
|
|
1715
|
+
currency: string;
|
|
1716
|
+
};
|
|
1689
1717
|
/**
|
|
1690
1718
|
* Optional. Credit this job's payment drew against (internal-review). Present on
|
|
1691
1719
|
* every job a ledger-backed payment satisfied; its presence is what tells
|
|
@@ -1714,6 +1742,43 @@ interface RevenueReportPayload {
|
|
|
1714
1742
|
*/
|
|
1715
1743
|
kind?: string;
|
|
1716
1744
|
}
|
|
1745
|
+
/**
|
|
1746
|
+
* JSON wire shape POSTed to the platform's `/_internal/job-cost` endpoint
|
|
1747
|
+
* when a terminal job incurred a declared builder cost but produced no
|
|
1748
|
+
* revenue report (internal-review).
|
|
1749
|
+
*
|
|
1750
|
+
* Unlike {@link RevenueReportPayload}, this event has no payment rail or
|
|
1751
|
+
* revenue amount: a failed, cancelled, or free job is not a sale. The
|
|
1752
|
+
* platform upserts it by `(dvmId, jobId)`, independently of the revenue
|
|
1753
|
+
* ledger's rail-keyed constraint. It replaces the stored value only when
|
|
1754
|
+
* `costRevision` is higher; equal revisions must be byte-identical. That rule
|
|
1755
|
+
* makes a persisted prefix and a later in-memory total converge regardless of
|
|
1756
|
+
* delivery order.
|
|
1757
|
+
*/
|
|
1758
|
+
interface JobCostReportPayload {
|
|
1759
|
+
/** Required. Platform DVM record ID (`dvms.id`); bound to the authenticating token. */
|
|
1760
|
+
dvmId: string;
|
|
1761
|
+
/** Required. Job identifier and the report's platform-side idempotency key. */
|
|
1762
|
+
jobId: string;
|
|
1763
|
+
/** Optional. Capability selected by dispatch; absent only on legacy persisted jobs. */
|
|
1764
|
+
capability?: string;
|
|
1765
|
+
/** Required. Terminal outcome that explains why this event carries no revenue. */
|
|
1766
|
+
outcome: "completed" | "failed" | "cancelled";
|
|
1767
|
+
/**
|
|
1768
|
+
* Required. Number of declarations incorporated into `cost`; the
|
|
1769
|
+
* platform keeps the payload with the highest revision for this job.
|
|
1770
|
+
*/
|
|
1771
|
+
costRevision: number;
|
|
1772
|
+
/**
|
|
1773
|
+
* The builder's cumulative declared cost, in millionths of its currency.
|
|
1774
|
+
* `null` at a higher revision invalidates an earlier prefix when the handler
|
|
1775
|
+
* switched currencies and the final total is therefore unreportable.
|
|
1776
|
+
*/
|
|
1777
|
+
cost: {
|
|
1778
|
+
amountMicro: number;
|
|
1779
|
+
currency: string;
|
|
1780
|
+
} | null;
|
|
1781
|
+
}
|
|
1717
1782
|
/**
|
|
1718
1783
|
* JSON wire shape POSTed to the platform's `/_internal/credit-deposit`
|
|
1719
1784
|
* endpoint (internal-review). A funding event is a **deposit** — a liability until
|
|
@@ -2109,6 +2174,8 @@ declare class RevenueReporter {
|
|
|
2109
2174
|
private tableColumns;
|
|
2110
2175
|
/** Persist a revenue report and attempt immediate delivery. */
|
|
2111
2176
|
report(payload: RevenueReportPayload): Promise<void>;
|
|
2177
|
+
/** Persist a zero-revenue job cost and attempt immediate delivery. */
|
|
2178
|
+
reportCost(payload: JobCostReportPayload): Promise<void>;
|
|
2112
2179
|
/**
|
|
2113
2180
|
* Join a credit deposit to the caller-owned rail transaction.
|
|
2114
2181
|
*
|
|
@@ -5583,6 +5650,33 @@ interface SDKPaymentRequestOpts {
|
|
|
5583
5650
|
challenges: MppxChallenge[];
|
|
5584
5651
|
};
|
|
5585
5652
|
}
|
|
5653
|
+
/**
|
|
5654
|
+
* What one job cost the builder to serve, as declared by the handler through
|
|
5655
|
+
* {@link SDKJobContext.cost}.
|
|
5656
|
+
*
|
|
5657
|
+
* The builder's own cost, in the currency they incurred it — a vendor API
|
|
5658
|
+
* call, a GPU minute, a per-request licence fee. It is never netted against
|
|
5659
|
+
* what the caller paid: revenue and cost are two different questions and the
|
|
5660
|
+
* platform keeps two different fields for them.
|
|
5661
|
+
*/
|
|
5662
|
+
interface JobCost {
|
|
5663
|
+
/**
|
|
5664
|
+
* Amount in **major** currency units, like every other money figure a
|
|
5665
|
+
* handler passes in (`ctx.requestPayment`, `QuoteResult.upfront`): `0.0003`
|
|
5666
|
+
* is three hundredths of a cent.
|
|
5667
|
+
*
|
|
5668
|
+
* Declarations are summed as major units and only the job's total is
|
|
5669
|
+
* rounded, to a millionth of a unit. So an individual charge finer than a
|
|
5670
|
+
* millionth — per-token LLM pricing, say — is not floored away on its own;
|
|
5671
|
+
* a thousand of them add up to a figure that gets reported.
|
|
5672
|
+
*
|
|
5673
|
+
* Must be finite and non-negative, and the job's total must not exceed
|
|
5674
|
+
* ~9e9 units; anything else is a `RangeError`.
|
|
5675
|
+
*/
|
|
5676
|
+
amount: number;
|
|
5677
|
+
/** ISO 4217 lowercase, e.g. `"usd"`. */
|
|
5678
|
+
currency: Currency;
|
|
5679
|
+
}
|
|
5586
5680
|
/** Extended job context provided by the SDK runtime to DVM handlers. */
|
|
5587
5681
|
interface SDKJobContext<State = Record<string, unknown>, Input = string> {
|
|
5588
5682
|
/** Server-assigned job ID. */
|
|
@@ -5652,6 +5746,53 @@ interface SDKJobContext<State = Record<string, unknown>, Input = string> {
|
|
|
5652
5746
|
fail(error: string, opts?: {
|
|
5653
5747
|
refund?: boolean;
|
|
5654
5748
|
}): void;
|
|
5749
|
+
/**
|
|
5750
|
+
* Declare what this job cost **you**, the builder, to serve (internal-review).
|
|
5751
|
+
*
|
|
5752
|
+
* The SDK reports it to the platform alongside the job's revenue, so the
|
|
5753
|
+
* dashboard can state a margin. Without it the margin is unknowable, and the
|
|
5754
|
+
* board says so rather than guessing:
|
|
5755
|
+
*
|
|
5756
|
+
* ```ts
|
|
5757
|
+
* const res = await ctx.fetch("https://api.vendor.example/v1/transcribe", { ... });
|
|
5758
|
+
* ctx.cost({ amount: 0.0004, currency: "usd" });
|
|
5759
|
+
* ```
|
|
5760
|
+
*
|
|
5761
|
+
* **Repeated calls add up.** Declare each cost where you incur it — once per
|
|
5762
|
+
* vendor call — rather than summing them yourself. Every call must name the
|
|
5763
|
+
* same currency; a job that mixes two reports no cost at all and logs an
|
|
5764
|
+
* error, because one number in two currencies is not a cost.
|
|
5765
|
+
*
|
|
5766
|
+
* **Nothing declared means nothing reported.** The cost field is absent from
|
|
5767
|
+
* the report, which is distinct from a declared cost of zero — "we don't
|
|
5768
|
+
* know" and "it was free" are different facts and the dashboard shows them
|
|
5769
|
+
* differently. `ctx.cost({ amount: 0, currency: "usd" })` is the way to say
|
|
5770
|
+
* a job genuinely cost you nothing.
|
|
5771
|
+
*
|
|
5772
|
+
* **Declare costs where they are incurred, including inside {@link step}.**
|
|
5773
|
+
* The step cache carries declarations with the result and applies them once
|
|
5774
|
+
* when a replay skips the body:
|
|
5775
|
+
*
|
|
5776
|
+
* ```ts
|
|
5777
|
+
* const r = await ctx.step("transcribe", async () => {
|
|
5778
|
+
* const result = await whisper(audio);
|
|
5779
|
+
* ctx.cost({ amount: result.seconds * 0.0001, currency: "usd" });
|
|
5780
|
+
* return result;
|
|
5781
|
+
* });
|
|
5782
|
+
* ```
|
|
5783
|
+
*
|
|
5784
|
+
* **Terminal jobs report declared cost.** A paid completion carries cost on
|
|
5785
|
+
* its revenue report. A free completion, failure, or cancellation uses a
|
|
5786
|
+
* separate cost report and does not create revenue. On multi-machine hosts,
|
|
5787
|
+
* cumulative declarations are revisioned so a later in-memory total replaces
|
|
5788
|
+
* an earlier persisted prefix regardless of delivery order.
|
|
5789
|
+
*
|
|
5790
|
+
* Throws `InvalidCurrencyError` for a currency that is not ISO 4217
|
|
5791
|
+
* lowercase, and `RangeError` for an amount that is not finite or is
|
|
5792
|
+
* negative. After the job is terminal the call is a no-op, like every other
|
|
5793
|
+
* context write.
|
|
5794
|
+
*/
|
|
5795
|
+
cost(cost: JobCost): void;
|
|
5655
5796
|
/**
|
|
5656
5797
|
* Cache the result of an async operation for durable replay.
|
|
5657
5798
|
*
|
|
@@ -6286,6 +6427,8 @@ interface StepRecord {
|
|
|
6286
6427
|
id: string;
|
|
6287
6428
|
/** Cached return value of the step function. */
|
|
6288
6429
|
value: unknown;
|
|
6430
|
+
/** Cost declarations made while the step body ran, replayed on cache hits. */
|
|
6431
|
+
costs?: JobCost[];
|
|
6289
6432
|
}
|
|
6290
6433
|
/**
|
|
6291
6434
|
* In-memory cache of step results for durable replay.
|
|
@@ -6301,12 +6444,14 @@ declare class StepCache {
|
|
|
6301
6444
|
has(id: string): boolean;
|
|
6302
6445
|
/** Get a cached step result. Throws if not present. */
|
|
6303
6446
|
get(id: string): unknown;
|
|
6447
|
+
/** Get a cached step record, including replay metadata. Throws if not present. */
|
|
6448
|
+
getRecord(id: string): StepRecord;
|
|
6304
6449
|
/** Cache a step result. */
|
|
6305
|
-
set(id: string, value: unknown): void;
|
|
6450
|
+
set(id: string, value: unknown, costs?: readonly JobCost[]): void;
|
|
6306
6451
|
/** Export all cached steps for persistence. */
|
|
6307
6452
|
serialize(): StepRecord[];
|
|
6308
6453
|
/** Restore a StepCache from persisted records. */
|
|
6309
6454
|
static deserialize(records: StepRecord[]): StepCache;
|
|
6310
6455
|
}
|
|
6311
6456
|
|
|
6312
|
-
export { type
|
|
6457
|
+
export { type X402Version as $, type ApprovalContent as A, SignedRequestError as B, type Currency as C, type DVMConfig as D, type SignedRequestFailure as E, type SignedRequestReplayStore as F, type SignedRequestSignOpts as G, type SignedRequestStatementHeader as H, type IncomingMessage as I, type JobCost as J, type KVStore as K, type Logger as L, type SignedRequestVerifier as M, createSignedRequestVerifier as N, isZodSchema as O, type PaymentContent as P, type QuoteConfig as Q, type ResolvedCreditConfig as R, type SDKJobContext as S, signedRequestStatementHeader as T, UnsupportedCurrencyError as U, validateCurrency as V, type JsonValue as W, type FundingReceipt as X, type JobReceipt as Y, type ZodLike as Z, type PaymentRequired as _, type DVMDescriptor as a, isDrainReceipt as a$, type MppxCredential as a0, type Message as a1, type MessageType as a2, type MppxChallenge as a3, X402_BATCH_SETTLEMENT_SCHEME as a4, X402_EXACT_SCHEME as a5, type ReceiptCredit as a6, type X402Wallet as a7, type ResourceInfo as a8, type BuildPaymentRequirementsOpts as a9, type UnsignedFundingReceipt as aA, type UnsignedJobReceipt as aB, type VerifyResponse as aC, type WorkingContent as aD, type X402Config as aE, type X402ResponseBody as aF, type X402SelfRelayRpcFailureReason as aG, X402_DEFAULT_NETWORK as aH, X402_V1_VERSION as aI, X402_VERSION as aJ, buildPaymentRequiredV2 as aK, buildPaymentRequirements as aL, caip2ToX402Network as aM, canonicalRequestPath as aN, canonicaliseForSigning as aO, canonicalize as aP, chainIdFromCaip2 as aQ, computeResultHash as aR, decodePayment as aS, decodePaymentRequiredHeader as aT, encodePayment as aU, encodePaymentRequiredHeader as aV, encodeSettleResponseHeader as aW, exactEvmAuthorization as aX, isArtifactMessage as aY, isCancelMessage as aZ, isCompleteMessage as a_, type CapabilityDescriptor as aa, type CashuMode as ab, type CompleteContent as ac, type DrainReceipt as ad, type DrainReceiptEvent as ae, type ExactEvmPayload as af, type ExactEvmPayloadAuthorization as ag, type FundingMethod as ah, type MessageFrom as ai, type PaymentPayload as aj, type PaymentPayloadV1 as ak, type PaymentPayloadV2 as al, type PaymentRequestContent as am, type PaymentRequiredV2 as an, type PaymentRequirements as ao, type PaymentRequirementsV1 as ap, type PaymentRequirementsV2 as aq, type PromptContent as ar, RAIL_REFUNDABLE as as, type ReceiptOutcome as at, type ReceiptPayment as au, type SettleResponse as av, StepCache as aw, type StepRecord as ax, type TextContent as ay, type UnsignedDrainReceipt as az, type ArtifactContent as b, type StalePendingDrawCursor as b$, isFundingReceipt as b0, isPaymentRequestMessage as b1, isPromptMessage as b2, isSignedJobReceipt as b3, isTextMessage as b4, isWorkingMessage as b5, paymentRequiredV2FromV1 as b6, signDrainReceipt as b7, signFundingReceipt as b8, signReceipt as b9, _testing as bA, createDefaultReplayStore as bB, depleteLots as bC, fifoOrder as bD, inKindDrawMsats as bE, isInKindDepletion as bF, isNonChannelBitcoinRail as bG, lotOwedSats as bH, netOwedSats as bI, wrapMppx as bJ, type CreditDrainEnqueue as bK, type DVMAuthScheme as bL, type CreditLedgerLike as bM, type X402RefundSettlementGate as bN, type CreditSnapshot as bO, type DrawResult as bP, type X402SettlementStatus as bQ, type X402UnresolvedRefund as bR, type GrownDrawResult as bS, type DrawResolution as bT, type FundingRecord as bU, type CreditInvoiceRecord as bV, type InvoiceSettlement as bW, type BlockedInvoiceCursor as bX, type InvoiceReconciliation as bY, type InvoiceWriteOff as bZ, type DrawRecord as b_, usdcContractByCaip2 as ba, usdcContractFor as bb, usdcDomainNameFor as bc, usdcDomainVersionFor as bd, verifyDrainReceipt as be, verifyFundingReceipt as bf, verifyReceipt as bg, x402NetworkToCaip2 as bh, type X402ExactVersionSupport as bi, type X402Receipt as bj, type TransactionalPayoutHook as bk, type CashuMeltCompleted as bl, type CreditDepositPayload as bm, type CreditDrainPayload as bn, type FundingLot as bo, type LotDebit as bp, type LotDepletion as bq, type MppxServer as br, NON_CHANNEL_BITCOIN_RAILS as bs, type NonChannelBitcoinRail as bt, PayoutReporter as bu, PostgresTempoSessionStore as bv, RevenueReporter as bw, SIGNED_ENVELOPE_FIELDS as bx, SIGNED_ENVELOPE_TYPES as by, type X402TrackedChannel as bz, type CancelContent as c, type TempoCreditLossEvidence as c0, type CreditLedgerQuerier as c1, type TempoCreditLoss as c2, type X402CreditLossEvidence as c3, type X402CreditLoss as c4, type DrainMethod as c5, type DrainRequestResult as c6, type BitcoinDepositLiability as c7, type CreditDrainRecord as c8, type ChannelDrainCursor as c9, type RevenueSkippedNoRailPayload as cA, type RevenueSkippedNoRailReason as cB, type Secp256k1AuthOpts as cC, type X402ChannelStorageOpts as cD, type X402RelayLockHolder as cE, type X402RelaySubmissionLock as cF, X402RelaySubmissionLockError as cG, allocateDrawValue as cH, clientCompatibilityAttributes as cI, clientCompatibilityMiddleware as cJ, clientUpgradeRequired as cK, parseClientCapabilities as cL, parseClientCompatibility as cM, parseDvmClient as cN, parseProtocolVersion as cO, requireClientCompatibility as cP, secp256k1Auth as cQ, signedRequestInput as cR, type X402SettlementIntent as cS, type X402SettlementCursor as cT, type X402SettlementWriteOff as cU, type X402FacilitatorAuth as cV, type X402BatchSettlementConfig as cW, type X402PayoutObserver as cX, type CreditDepositEnqueue as cY, type X402SettlementReconciliationReason as cZ, type CreditDrawReleaseEnqueue as c_, type DrainWriteOff as ca, type DrainReleaseResult as cb, type DrainFulfilment as cc, type DrainTransitionResult as cd, CLIENT_COMPATIBILITY_HEADERS as ce, type ClientCompatibility as cf, type ClientCompatibilityEnv as cg, type ClientCompatibilityGate as ch, type ClientCompatibilityRequirement as ci, type ClientSemVer as cj, type CreditFundingBasis as ck, type CreditInvoiceStatus as cl, CreditLedger as cm, CreditLedgerError as cn, type CreditLedgerErrorCode as co, type CreditLedgerErrorDetails as cp, type CreditLedgerPool as cq, type CreditStatus as cr, DRAIN_DELIVERY_RESERVE_SATS as cs, DVM_PROTOCOL_VERSION as ct, type DrainConflictReason as cu, type DrawRailValue as cv, type DrawStatus as cw, type JobCostReportPayload as cx, PostgresX402ChannelStorage as cy, type ReplayStoreBackend as cz, type CanonicalEnvelope as d, type CreateSignedRequestVerifierOpts as e, type CreditConfig as f, type CreditView as g, DEFAULT_CREDIT_MAX as h, DEFAULT_CREDIT_MIN as i, DEFAULT_CREDIT_TTL_SECONDS as j, DEFAULT_JOB_RETENTION_DAYS as k, type DVMRouteContext as l, type InputType as m, InvalidCurrencyError as n, type PaymentMethod as o, type PriceValue as p, type ProgressContent as q, type PromptOpts as r, type QuoteContext as s, type QuoteResult as t, type ResponseContent as u, type SDKPaymentRequestOpts as v, SIGNED_REQUEST_AUTH_ID as w, SIGNED_REQUEST_STATEMENT_VERSION as x, type SignedRequestAudience as y, type SignedRequestDomain as z };
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
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
3
|
import 'hono';
|
|
4
4
|
import 'mppx';
|
|
5
5
|
import '@x402/core/server';
|
|
6
6
|
import '@x402/evm/batch-settlement/server';
|
|
7
7
|
import 'viem';
|
|
8
8
|
import 'pg';
|
|
9
|
-
import 'zod';
|
|
10
9
|
import '@x402/core/types';
|
|
10
|
+
import 'zod';
|
|
11
11
|
import '@cashu/cashu-ts';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -131,6 +131,16 @@ interface TestJobContext<State = Record<string, unknown>, Input = string> extend
|
|
|
131
131
|
readonly summary: string | undefined;
|
|
132
132
|
/** The error string passed to fail(). */
|
|
133
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;
|
|
134
144
|
/**
|
|
135
145
|
* Cancel the job under test (internal-review) — aborts `ctx.signal` exactly as a
|
|
136
146
|
* caller cancel, idle timeout, or stale-sweep would in the real runtime, and
|
package/dist/testing/index.js
CHANGED
|
@@ -5,12 +5,16 @@ import {
|
|
|
5
5
|
JobCancelledError,
|
|
6
6
|
MemoryJobStore,
|
|
7
7
|
createInstrumentedFetch
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-U6M3ATSG.js";
|
|
9
9
|
import {
|
|
10
10
|
createNoopLogger
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-E4EVGPDX.js";
|
|
12
12
|
import "../chunk-66HGCPBU.js";
|
|
13
13
|
import "../chunk-FUJ36YDV.js";
|
|
14
|
+
import {
|
|
15
|
+
validateCurrency
|
|
16
|
+
} from "../chunk-27V2ILSR.js";
|
|
17
|
+
import "../chunk-AT6V3SY7.js";
|
|
14
18
|
|
|
15
19
|
// src/sdk/testing/test-context.ts
|
|
16
20
|
function createTestContext(opts) {
|
|
@@ -22,6 +26,10 @@ function createTestContext(opts) {
|
|
|
22
26
|
let refundRequested = false;
|
|
23
27
|
let summary;
|
|
24
28
|
let failError;
|
|
29
|
+
let costAmount = 0;
|
|
30
|
+
let costMicro = 0;
|
|
31
|
+
let costCurrency;
|
|
32
|
+
let costPoisoned = false;
|
|
25
33
|
const state = opts?.state !== void 0 ? structuredClone(opts.state) : {};
|
|
26
34
|
const store = opts?.store ?? new MemoryKVStore();
|
|
27
35
|
const env = opts?.env ?? {};
|
|
@@ -54,6 +62,10 @@ function createTestContext(opts) {
|
|
|
54
62
|
get failError() {
|
|
55
63
|
return failError;
|
|
56
64
|
},
|
|
65
|
+
get reportedCost() {
|
|
66
|
+
if (costPoisoned || costCurrency === void 0) return void 0;
|
|
67
|
+
return { amountMicro: costMicro, currency: costCurrency };
|
|
68
|
+
},
|
|
57
69
|
// --- Messaging ---
|
|
58
70
|
text(message) {
|
|
59
71
|
if (cancelled) return;
|
|
@@ -136,6 +148,23 @@ function createTestContext(opts) {
|
|
|
136
148
|
cancelled = true;
|
|
137
149
|
abort.abort(new JobCancelledError(reason));
|
|
138
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
|
+
},
|
|
139
168
|
// --- Durable execution ---
|
|
140
169
|
async step(_id, fn) {
|
|
141
170
|
return fn();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
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",
|
|
46
|
+
"check:api": "node scripts/check-api-surface.mjs && node scripts/generate-api-reference.mjs --check",
|
|
47
47
|
"check:consumer": "node scripts/consumer-smoke.mjs",
|
|
48
48
|
"install-published-release": "node scripts/install-published-release.mjs",
|
|
49
49
|
"check:package": "node scripts/package-smoke.mjs",
|
|
@@ -53,15 +53,17 @@
|
|
|
53
53
|
"check:tree-shaking": "node scripts/check-internal-tree-shaking.mjs",
|
|
54
54
|
"clean-install-smoke": "node scripts/clean-install-smoke.mjs",
|
|
55
55
|
"lint": "eslint . --max-warnings 0",
|
|
56
|
+
"docs:api": "node scripts/generate-api-reference.mjs --write",
|
|
56
57
|
"release:tag": "node scripts/release-tag.mjs",
|
|
57
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",
|
|
58
60
|
"test:db": "vitest run --config vitest.db.config.ts",
|
|
59
61
|
"typecheck": "tsc --noEmit",
|
|
60
62
|
"typecheck:scripts": "tsc --noEmit --project tsconfig.scripts.json",
|
|
61
63
|
"verify": "node scripts/verify.mjs"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
|
-
"@cashu/cashu-ts": "4.2
|
|
66
|
+
"@cashu/cashu-ts": "4.10.2",
|
|
65
67
|
"@hono/node-server": "1.19.17",
|
|
66
68
|
"@noble/curves": "2.0.1",
|
|
67
69
|
"@noble/hashes": "2.0.1",
|