@agent-score/commerce 1.8.1 → 2.0.0
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 +73 -9
- package/dist/{_response-9yp6Fit2.d.mts → _response-BFYN3b6i.d.mts} +17 -19
- package/dist/{_response-CC6jNb8q.d.ts → _response-_iPD5AIj.d.ts} +17 -19
- package/dist/challenge/index.d.mts +106 -198
- package/dist/challenge/index.d.ts +106 -198
- package/dist/challenge/index.js +238 -111
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +238 -111
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/checkout-BoFwnVsj.d.ts +931 -0
- package/dist/checkout-DRbQ0Fsh.d.mts +931 -0
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/discovery/index.d.mts +453 -51
- package/dist/discovery/index.d.ts +453 -51
- package/dist/discovery/index.js +1092 -58
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +1060 -57
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +3 -3
- package/dist/identity/express.d.ts +3 -3
- package/dist/identity/express.js +30 -19
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +30 -19
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +4 -4
- package/dist/identity/fastify.d.ts +4 -4
- package/dist/identity/fastify.js +30 -19
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +30 -19
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +3 -3
- package/dist/identity/hono.d.ts +3 -3
- package/dist/identity/hono.js +30 -19
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +30 -19
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +6 -7
- package/dist/identity/nextjs.d.ts +6 -7
- package/dist/identity/nextjs.js +30 -19
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +30 -19
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.d.mts +41 -4
- package/dist/identity/policy.d.ts +41 -4
- package/dist/identity/policy.js +3662 -18
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +3648 -3
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +3 -3
- package/dist/identity/web.d.ts +3 -3
- package/dist/identity/web.js +30 -19
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +30 -19
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +72 -329
- package/dist/index.d.ts +72 -329
- package/dist/index.js +3651 -373
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3628 -361
- package/dist/index.mjs.map +1 -1
- package/dist/payment/index.d.mts +256 -265
- package/dist/payment/index.d.ts +256 -265
- package/dist/payment/index.js +586 -149
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +573 -148
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{agent_instructions-DiMSGkdm.d.mts → pricing-CQ9DIFaw.d.ts} +109 -56
- package/dist/{agent_instructions-DiMSGkdm.d.ts → pricing-CxzwyiO6.d.mts} +109 -56
- package/dist/rail_spec-XP0wKgJV.d.mts +132 -0
- package/dist/rail_spec-XP0wKgJV.d.ts +132 -0
- package/dist/{signer-CFVQsWjL.d.mts → signer-3FAit11j.d.mts} +27 -1
- package/dist/{signer-CFVQsWjL.d.ts → signer-3FAit11j.d.ts} +27 -1
- package/dist/solana-Cds87OTu.d.mts +67 -0
- package/dist/solana-Cds87OTu.d.ts +67 -0
- package/dist/stripe-multichain/index.d.mts +55 -66
- package/dist/stripe-multichain/index.d.ts +55 -66
- package/dist/stripe-multichain/index.js +68 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +68 -41
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{wwwauthenticate-CU1eNvMQ.d.mts → wwwauthenticate-D_FMnPgU.d.mts} +9 -10
- package/dist/{wwwauthenticate-CU1eNvMQ.d.ts → wwwauthenticate-D_FMnPgU.d.ts} +9 -10
- package/dist/x402_server-hgQzWQwB.d.mts +81 -0
- package/dist/x402_server-hgQzWQwB.d.ts +81 -0
- package/package.json +9 -7
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from '../rail_spec-XP0wKgJV.js';
|
|
2
|
+
import { A as AgentInstructions, P as PricingBlock } from '../pricing-CQ9DIFaw.js';
|
|
3
|
+
export { C as CompatibleClients, H as HowToPayBlock, a as HowToPayRailEntry, b as HowToPayRails, c as HowToPayStripeEntry, R as RailKey, d as buildAgentInstructions, e as buildHowToPay, f as buildPricingBlock, g as compatibleClientsByRails } from '../pricing-CQ9DIFaw.js';
|
|
3
4
|
import { AgentMemoryHint } from '../core.js';
|
|
4
5
|
export { buildAgentMemoryHint } from '../core.js';
|
|
5
|
-
import {
|
|
6
|
-
import '../signer-
|
|
6
|
+
import { p as paymentRequiredHeader } from '../wwwauthenticate-D_FMnPgU.js';
|
|
7
|
+
import '../signer-3FAit11j.js';
|
|
7
8
|
|
|
8
9
|
interface TempoMethodEntry {
|
|
9
10
|
method: 'tempo/charge';
|
|
@@ -30,7 +31,6 @@ interface SolanaMppMethodEntry {
|
|
|
30
31
|
symbol: string;
|
|
31
32
|
decimals: number;
|
|
32
33
|
pay_to: string;
|
|
33
|
-
fee_payer_key?: string;
|
|
34
34
|
}
|
|
35
35
|
interface StripeMethodEntry {
|
|
36
36
|
method: 'stripe/charge';
|
|
@@ -38,42 +38,19 @@ interface StripeMethodEntry {
|
|
|
38
38
|
profile_id: string | null;
|
|
39
39
|
}
|
|
40
40
|
type AcceptedMethodEntry = TempoMethodEntry | X402MethodEntry | SolanaMppMethodEntry | StripeMethodEntry;
|
|
41
|
-
interface BuildAcceptedMethodsInput {
|
|
42
|
-
tempo?: {
|
|
43
|
-
recipient: string;
|
|
44
|
-
network?: string;
|
|
45
|
-
chainId?: number;
|
|
46
|
-
token?: string;
|
|
47
|
-
symbol?: string;
|
|
48
|
-
decimals?: number;
|
|
49
|
-
};
|
|
50
|
-
x402_base?: {
|
|
51
|
-
recipient: string;
|
|
52
|
-
network?: string;
|
|
53
|
-
chainId?: number;
|
|
54
|
-
token?: string;
|
|
55
|
-
symbol?: string;
|
|
56
|
-
decimals?: number;
|
|
57
|
-
};
|
|
58
|
-
solana_mpp?: {
|
|
59
|
-
recipient: string;
|
|
60
|
-
network?: string;
|
|
61
|
-
token?: string;
|
|
62
|
-
symbol?: string;
|
|
63
|
-
decimals?: number;
|
|
64
|
-
feePayerKey?: string;
|
|
65
|
-
};
|
|
66
|
-
stripe?: {
|
|
67
|
-
profileId?: string | null;
|
|
68
|
-
rails?: ('card' | 'link' | 'shared_payment_token')[];
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
41
|
/**
|
|
72
|
-
* Build the `accepted_methods[]` array for an enriched 402 body. Each rail entry
|
|
73
|
-
* conditionally included
|
|
74
|
-
*
|
|
42
|
+
* Build the `accepted_methods[]` array for an enriched 402 body. Each rail entry
|
|
43
|
+
* is conditionally included when the vendor passes a `*RailSpec` for that rail.
|
|
44
|
+
* Each spec's `recipient` is resolved via `resolveRecipient` so per-order
|
|
45
|
+
* factories (e.g. Stripe-multichain mints fresh deposits per PaymentIntent)
|
|
46
|
+
* flow through identically to static-treasury strings.
|
|
75
47
|
*/
|
|
76
|
-
declare function buildAcceptedMethods(
|
|
48
|
+
declare function buildAcceptedMethods({ tempo, x402_base, solana_mpp, stripe, }: {
|
|
49
|
+
tempo?: TempoRailSpec;
|
|
50
|
+
x402_base?: X402BaseRailSpec;
|
|
51
|
+
solana_mpp?: SolanaMppRailSpec;
|
|
52
|
+
stripe?: StripeRailSpec;
|
|
53
|
+
}): Promise<AcceptedMethodEntry[]>;
|
|
77
54
|
|
|
78
55
|
type IdentityMode = 'wallet' | 'operator_token';
|
|
79
56
|
interface SignerMatchResultLike {
|
|
@@ -82,18 +59,6 @@ interface SignerMatchResultLike {
|
|
|
82
59
|
actualSigner?: string;
|
|
83
60
|
linkedWallets?: string[];
|
|
84
61
|
}
|
|
85
|
-
interface IdentityMetadataInput {
|
|
86
|
-
/** Current request's identity mode. */
|
|
87
|
-
mode: IdentityMode;
|
|
88
|
-
/** Claimed wallet address (when mode === 'wallet'). */
|
|
89
|
-
wallet?: string;
|
|
90
|
-
/** Projected signer_match verdict (from `getSignerVerdict(ctx).signer_match`). */
|
|
91
|
-
signerMatchResult?: SignerMatchResultLike;
|
|
92
|
-
/** Same-operator linked wallets (from assess response). */
|
|
93
|
-
linkedWallets?: string[];
|
|
94
|
-
/** Optional explicit constraint description (overrides the auto-generated one). */
|
|
95
|
-
signerConstraint?: string;
|
|
96
|
-
}
|
|
97
62
|
interface IdentityMetadataBlock {
|
|
98
63
|
identity_mode: IdentityMode;
|
|
99
64
|
required_signer?: string;
|
|
@@ -106,7 +71,13 @@ interface IdentityMetadataBlock {
|
|
|
106
71
|
* before signing — specifically, on wallet-auth rails the agent MUST sign with one
|
|
107
72
|
* of the wallets in linked_wallets (all resolve to the same operator).
|
|
108
73
|
*/
|
|
109
|
-
declare function buildIdentityMetadata(
|
|
74
|
+
declare function buildIdentityMetadata({ mode, wallet, signerMatchResult, linkedWallets, signerConstraint, }: {
|
|
75
|
+
mode: IdentityMode;
|
|
76
|
+
wallet?: string;
|
|
77
|
+
signerMatchResult?: SignerMatchResultLike;
|
|
78
|
+
linkedWallets?: string[];
|
|
79
|
+
signerConstraint?: string;
|
|
80
|
+
}): IdentityMetadataBlock;
|
|
110
81
|
|
|
111
82
|
/**
|
|
112
83
|
* Helpers for emitting the cross-merchant `agent_memory` hint on merchant 402 responses.
|
|
@@ -129,14 +100,6 @@ declare function buildIdentityMetadata(input: IdentityMetadataInput): IdentityMe
|
|
|
129
100
|
* every merchant emits the same shape.
|
|
130
101
|
*/
|
|
131
102
|
|
|
132
|
-
interface FirstEncounterAgentMemoryInput {
|
|
133
|
-
/**
|
|
134
|
-
* Whether this is a first encounter for this operator/wallet/IP at this merchant.
|
|
135
|
-
* Merchant-determined (DB lookup, cache flag, etc.). Pass `false` to suppress emission
|
|
136
|
-
* cleanly without wrapping the call in an `if`.
|
|
137
|
-
*/
|
|
138
|
-
firstEncounter: boolean;
|
|
139
|
-
}
|
|
140
103
|
/**
|
|
141
104
|
* Returns the `agent_memory` hint when this is a first encounter, otherwise `undefined`.
|
|
142
105
|
* Use directly with the `agentMemory` field of `build402Body`:
|
|
@@ -150,77 +113,27 @@ interface FirstEncounterAgentMemoryInput {
|
|
|
150
113
|
* });
|
|
151
114
|
* ```
|
|
152
115
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
116
|
+
* `firstEncounter` is merchant-determined (DB lookup, cache flag, etc.); pass `false` to
|
|
117
|
+
* suppress emission cleanly without wrapping the call in an `if`. Returning `undefined`
|
|
118
|
+
* means `build402Body` cleanly skips the field instead of emitting `agent_memory: null`
|
|
119
|
+
* (which would imply "I tried but failed" rather than "didn't apply").
|
|
155
120
|
*/
|
|
156
|
-
declare function firstEncounterAgentMemory(
|
|
121
|
+
declare function firstEncounterAgentMemory({ firstEncounter, }: {
|
|
122
|
+
firstEncounter: boolean;
|
|
123
|
+
}): AgentMemoryHint | undefined;
|
|
157
124
|
|
|
158
125
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* — current and future commerce-platform plugins (Commerce7, WooCommerce, Shopify) —
|
|
164
|
-
* surfaces the same shape to agents.
|
|
165
|
-
*
|
|
166
|
-
* Shipping is included by default because most physical-goods merchants carry it; pass
|
|
167
|
-
* `shippingCents: 0` (or omit) for digital goods / services. Tax is optional for
|
|
168
|
-
* merchants outside taxable jurisdictions.
|
|
169
|
-
*/
|
|
170
|
-
interface PricingBlock {
|
|
171
|
-
/** Pre-tax, pre-shipping subtotal as a dollar-string (e.g. `"250.00"`). */
|
|
172
|
-
subtotal: string;
|
|
173
|
-
/** Tax amount as a dollar-string. Always present even if `"0.00"`. */
|
|
174
|
-
tax: string;
|
|
175
|
-
/** Shipping cost as a dollar-string. Always present even if `"0.00"`. */
|
|
176
|
-
shipping?: string;
|
|
177
|
-
/** Final total = subtotal + tax + shipping, dollar-string. */
|
|
178
|
-
total: string;
|
|
179
|
-
/** Tax rate as a decimal fraction (e.g. `0.0775` for 7.75%). Optional — omit for tax-free merchants. */
|
|
180
|
-
tax_rate?: number;
|
|
181
|
-
/** ISO-3166-2 state code or jurisdiction name used for tax calc. Optional. */
|
|
182
|
-
tax_state?: string;
|
|
183
|
-
/** ISO-4217 currency code. Default `"USD"`. */
|
|
184
|
-
currency?: string;
|
|
185
|
-
}
|
|
186
|
-
interface BuildPricingBlockInput {
|
|
187
|
-
/** Pre-tax, pre-shipping subtotal in the smallest currency unit (cents, satoshi, etc.). */
|
|
188
|
-
subtotalCents: number;
|
|
189
|
-
/** Tax amount in the smallest currency unit. Default `0`. */
|
|
190
|
-
taxCents?: number;
|
|
191
|
-
/** Shipping cost in the smallest currency unit. Default `0`. */
|
|
192
|
-
shippingCents?: number;
|
|
193
|
-
/** Override the computed total. By default `subtotalCents + taxCents + shippingCents`. */
|
|
194
|
-
totalCents?: number;
|
|
195
|
-
/** Tax rate as a decimal fraction (e.g. `0.0775`). */
|
|
196
|
-
taxRate?: number;
|
|
197
|
-
/** Tax jurisdiction (state code, country, etc.). */
|
|
198
|
-
taxState?: string;
|
|
199
|
-
/** ISO-4217 currency. Default `"USD"`. */
|
|
200
|
-
currency?: string;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Compose a `PricingBlock` from cents-denominated inputs. Handles the cents → dollar-string
|
|
204
|
-
* conversion (always 2 decimals) and computes the total when not explicitly provided.
|
|
205
|
-
*
|
|
206
|
-
* Example:
|
|
207
|
-
* ```ts
|
|
208
|
-
* const pricing = buildPricingBlock({
|
|
209
|
-
* subtotalCents: 25000,
|
|
210
|
-
* taxCents: 1875,
|
|
211
|
-
* shippingCents: 999,
|
|
212
|
-
* taxRate: 0.075,
|
|
213
|
-
* taxState: 'CA',
|
|
214
|
-
* });
|
|
215
|
-
* // → { subtotal: '250.00', tax: '18.75', shipping: '9.99', total: '278.74', tax_rate: 0.075, tax_state: 'CA' }
|
|
216
|
-
* ```
|
|
126
|
+
* Assemble the full enriched 402 response body. Combines accepted_methods, agent_instructions,
|
|
127
|
+
* identity metadata, pricing, x402 compliance fields, and any vendor-specific extras into a
|
|
128
|
+
* single object suitable for `JSON.stringify`. Vendors pass only what they have; the builder
|
|
129
|
+
* conditionally includes each section.
|
|
217
130
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
131
|
+
* Pair this with a Response that sets:
|
|
132
|
+
* - 'content-type: application/json'
|
|
133
|
+
* - 'www-authenticate: <wwwAuthenticateHeader([...])>' from `payment/wwwauthenticate`
|
|
134
|
+
* - 'PAYMENT-REQUIRED: <paymentRequiredHeader({...})>' for x402 clients
|
|
220
135
|
*/
|
|
221
|
-
declare function
|
|
222
|
-
|
|
223
|
-
interface Build402BodyInput {
|
|
136
|
+
declare function build402Body({ acceptedMethods, agentInstructions, identityMetadata, agentMemory, pricing, amountUsd, currency, orderId, product, retryBody, recommended, x402, extra, }: {
|
|
224
137
|
/** From buildAcceptedMethods — list of MPP method entries. */
|
|
225
138
|
acceptedMethods: AcceptedMethodEntry[];
|
|
226
139
|
/** From buildAgentInstructions — wraps how_to_pay + warnings + recommended_tools. */
|
|
@@ -250,58 +163,58 @@ interface Build402BodyInput {
|
|
|
250
163
|
x402?: {
|
|
251
164
|
accepts: unknown[];
|
|
252
165
|
version?: 1 | 2;
|
|
166
|
+
/** x402 spec `extensions` field. Per-endpoint declared extensions (e.g.
|
|
167
|
+
* `bazaar` discovery schema from `createBazaarDiscovery({...})`). Surfaces
|
|
168
|
+
* on the 402 body as `extensions` so spec-compliant crawlers can read it. */
|
|
169
|
+
extensions?: Record<string, unknown>;
|
|
253
170
|
};
|
|
254
171
|
/** Vendor-specific extra fields merged at the top level. */
|
|
255
172
|
extra?: Record<string, unknown>;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Assemble the full enriched 402 response body. Combines accepted_methods, agent_instructions,
|
|
259
|
-
* identity metadata, pricing, x402 compliance fields, and any vendor-specific extras into a
|
|
260
|
-
* single object suitable for `JSON.stringify`. Vendors pass only what they have; the builder
|
|
261
|
-
* conditionally includes each section.
|
|
262
|
-
*
|
|
263
|
-
* Pair this with a Response that sets:
|
|
264
|
-
* - 'content-type: application/json'
|
|
265
|
-
* - 'www-authenticate: <wwwAuthenticateHeader([...])>' from `payment/wwwauthenticate`
|
|
266
|
-
* - 'PAYMENT-REQUIRED: <paymentRequiredHeader({...})>' for x402 clients
|
|
267
|
-
*/
|
|
268
|
-
declare function build402Body(input: Build402BodyInput): Record<string, unknown>;
|
|
173
|
+
}): Record<string, unknown>;
|
|
269
174
|
|
|
270
175
|
/**
|
|
271
|
-
* Canonical
|
|
176
|
+
* Canonical receipt shape returned to agents on the 200 after settlement.
|
|
177
|
+
*
|
|
178
|
+
* Universal across vendor types: goods merchants populate the shipping +
|
|
179
|
+
* fulfillment slots, API merchants populate only the core fields (id,
|
|
180
|
+
* created_at, pricing, payment_status, next_steps). All goods-only fields are
|
|
181
|
+
* optional.
|
|
272
182
|
*
|
|
273
|
-
* Merchants own their order schema, but converging on this shape across
|
|
274
|
-
* merchants means agents can render and post-process
|
|
275
|
-
*
|
|
183
|
+
* Merchants own their order schema, but converging on this shape across
|
|
184
|
+
* AgentScore-gated merchants means agents can render and post-process receipts
|
|
185
|
+
* consistently regardless of whether the seller ships product or returns API
|
|
186
|
+
* output. Lift this type, fill the fields you care about, and ignore (or
|
|
187
|
+
* extend via `extras`) what you don't.
|
|
276
188
|
*
|
|
277
|
-
* All money fields are dollar-strings (e.g. `"250.00"`). Use
|
|
278
|
-
* `@agent-score/commerce/challenge` to compose the
|
|
189
|
+
* All money fields are dollar-strings (e.g. `"250.00"`). Use
|
|
190
|
+
* `buildPricingBlock` from `@agent-score/commerce/challenge` to compose the
|
|
191
|
+
* pricing fields from cents.
|
|
279
192
|
*/
|
|
280
193
|
|
|
281
|
-
interface
|
|
282
|
-
/** Stable
|
|
194
|
+
interface Receipt {
|
|
195
|
+
/** Stable receipt id; order UUID for goods, request id for API merchants. */
|
|
283
196
|
id: string;
|
|
284
|
-
/** ISO-8601 timestamp of
|
|
197
|
+
/** ISO-8601 timestamp of settlement. */
|
|
285
198
|
created_at: string;
|
|
286
|
-
/**
|
|
199
|
+
/** Goods: units purchased. API: usage count (calls, tokens, requests). */
|
|
287
200
|
quantity?: number;
|
|
288
|
-
/**
|
|
201
|
+
/** Goods-shaped product info. Omit for API merchants (per-call billing has no product concept). */
|
|
289
202
|
product?: {
|
|
290
203
|
id?: string;
|
|
291
204
|
name?: string;
|
|
292
205
|
slug?: string;
|
|
293
206
|
};
|
|
294
|
-
/** Pricing block
|
|
207
|
+
/** Pricing block; same shape as the 402 advertised. Use `buildPricingBlock` to compose. */
|
|
295
208
|
pricing?: PricingBlock;
|
|
296
209
|
/** Buyer email if provided. */
|
|
297
210
|
email?: string;
|
|
298
|
-
/** Payment status
|
|
211
|
+
/** Payment status; typically `"completed"`, `"pending"`, `"failed"`. */
|
|
299
212
|
payment_status?: string;
|
|
300
|
-
/**
|
|
213
|
+
/** Goods-only. Typically `"pending"`, `"shipped"`, `"delivered"`, `"cancelled"`. */
|
|
301
214
|
fulfillment_status?: string;
|
|
302
|
-
/** Carrier tracking number when fulfillment_status >= shipped. */
|
|
215
|
+
/** Goods-only. Carrier tracking number when fulfillment_status >= shipped. */
|
|
303
216
|
tracking_number?: string | null;
|
|
304
|
-
/**
|
|
217
|
+
/** Goods-only. Omit for digital goods, services, or API receipts. */
|
|
305
218
|
shipping?: {
|
|
306
219
|
name?: string;
|
|
307
220
|
address_1?: string;
|
|
@@ -311,12 +224,13 @@ interface OrderReceipt {
|
|
|
311
224
|
zip?: string;
|
|
312
225
|
country?: string;
|
|
313
226
|
};
|
|
314
|
-
/**
|
|
227
|
+
/** Goods-only. Omit for API receipts. */
|
|
315
228
|
gift_note?: string | null;
|
|
316
|
-
/** Vendor-specific extras merged at the top level (loyalty points, warranty, etc.). */
|
|
229
|
+
/** Vendor-specific extras merged at the top level (loyalty points, warranty, per-call usage breakdown, etc.). */
|
|
317
230
|
extras?: Record<string, unknown>;
|
|
318
|
-
/** Next-steps block guiding the agent
|
|
231
|
+
/** Next-steps block guiding the agent post-settlement. Matches the shape returned by `buildSuccessNextSteps` so vendors can spread that helper's output verbatim. `order_status_url` works for both: goods → order detail route, API → usage / billing dashboard. `fulfillment_eta` is goods-only. */
|
|
319
232
|
next_steps?: {
|
|
233
|
+
action?: string;
|
|
320
234
|
user_message?: string;
|
|
321
235
|
order_status_url?: string;
|
|
322
236
|
fulfillment_eta?: string;
|
|
@@ -331,43 +245,46 @@ interface OrderReceipt {
|
|
|
331
245
|
* The seam is fiddly enough to get wrong by hand:
|
|
332
246
|
* - mppx's `compose()(req)` returns a 402 Response with WWW-Authenticate directives
|
|
333
247
|
* whose ids mppx's server-side validator REMEMBERS — they round-trip in client
|
|
334
|
-
* credentials. Overwriting that header
|
|
335
|
-
* breaks the round-trip.
|
|
248
|
+
* credentials. Overwriting that header breaks the round-trip.
|
|
336
249
|
* - x402 needs the binary-friendly `PAYMENT-REQUIRED` header (base64-encoded JSON
|
|
337
250
|
* of `{x402Version, accepts, resource}`) — mppx doesn't emit it.
|
|
338
251
|
* - Merchants want a richer JSON body (pricing, identity metadata, agent_instructions,
|
|
339
252
|
* agent_memory, retry_body, accepted_methods cross-reference) than the bare mppx body.
|
|
340
253
|
*
|
|
341
|
-
* `respond402` composes all three
|
|
342
|
-
*
|
|
343
|
-
* - ADDS PAYMENT-REQUIRED when x402 entries are present
|
|
344
|
-
* - REPLACES the body with the rich body via `build402Body`
|
|
254
|
+
* `respond402` composes all three and returns a framework-neutral `Respond402Result`
|
|
255
|
+
* (body + headers + status) that the merchant wraps in their framework's response shape.
|
|
345
256
|
*
|
|
346
257
|
* Usage:
|
|
347
258
|
* ```ts
|
|
348
|
-
* const
|
|
349
|
-
* if (
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
259
|
+
* const challenge = await m.compose(['tempo/charge', {...}], ['stripe/charge', {...}])(c.req.raw);
|
|
260
|
+
* if (challenge.status === 402) {
|
|
261
|
+
* const result = respond402({
|
|
262
|
+
* mppxChallengeHeaders: Object.fromEntries(challenge.headers),
|
|
263
|
+
* body: build402Body({ ... }),
|
|
264
|
+
* x402: { x402Version: 2, accepts: x402Accepts, resource: { url: c.req.url, mimeType: 'application/json' } },
|
|
354
265
|
* });
|
|
266
|
+
* return new Response(JSON.stringify(result.body), { status: result.status, headers: result.headers });
|
|
355
267
|
* }
|
|
356
268
|
* ```
|
|
357
269
|
*/
|
|
358
270
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
271
|
+
/** Framework-neutral 402 response shape — body + headers + status. */
|
|
272
|
+
interface Respond402Result {
|
|
273
|
+
body: Record<string, unknown>;
|
|
274
|
+
headers: Record<string, string>;
|
|
275
|
+
status: 402;
|
|
276
|
+
}
|
|
277
|
+
declare function respond402({ mppxChallengeHeaders, body, x402, }: {
|
|
278
|
+
/** Headers from mppx's 402 Response (`Object.fromEntries(challenge.headers)`). The
|
|
279
|
+
* `WWW-Authenticate` directives are preserved verbatim — mppx's server-side validator
|
|
280
|
+
* matches credentials to the ids it generated. */
|
|
281
|
+
mppxChallengeHeaders: Record<string, string>;
|
|
282
|
+
/** The already-built 402 body — call `build402Body({...})` to construct it. */
|
|
283
|
+
body: Record<string, unknown>;
|
|
366
284
|
/** When set, layers on the x402 PAYMENT-REQUIRED header (base64-encoded JSON).
|
|
367
285
|
* Omit for merchants that don't accept x402 (Base/Solana) — mppx-only setups. */
|
|
368
|
-
x402?:
|
|
369
|
-
}
|
|
370
|
-
declare function respond402(input: Respond402Input): Response;
|
|
286
|
+
x402?: Parameters<typeof paymentRequiredHeader>[0];
|
|
287
|
+
}): Respond402Result;
|
|
371
288
|
|
|
372
289
|
/**
|
|
373
290
|
* Build a structured 4xx validation-error body that pairs cleanly with the
|
|
@@ -380,22 +297,6 @@ declare function respond402(input: Respond402Input): Response;
|
|
|
380
297
|
* `Response.json(body, {status: 400})` for the Web Fetch path, etc.). Status
|
|
381
298
|
* stays the merchant's call because the same shape works for 400/404/409/422.
|
|
382
299
|
*/
|
|
383
|
-
interface BuildValidationErrorInput {
|
|
384
|
-
/** Machine-readable error code (e.g. 'bad_request', 'not_found', 'out_of_stock'). */
|
|
385
|
-
code: string;
|
|
386
|
-
/** Human-readable message — surfaced directly to the user via the agent. */
|
|
387
|
-
message: string;
|
|
388
|
-
/** Optional schema description of required body fields, keyed by field name. Surfaced
|
|
389
|
-
* so agents can self-correct without fetching docs. */
|
|
390
|
-
requiredFields?: Record<string, string>;
|
|
391
|
-
/** Optional concrete example body. Pairs with `requiredFields` for max self-serve. */
|
|
392
|
-
exampleBody?: unknown;
|
|
393
|
-
/** Optional next-step hint block (`{action, user_message?, ...vendor_extras}`). */
|
|
394
|
-
nextSteps?: Record<string, unknown>;
|
|
395
|
-
/** Vendor-specific top-level fields merged into the body (e.g. `available`,
|
|
396
|
-
* `blocked_states`, `max_length`). */
|
|
397
|
-
extra?: Record<string, unknown>;
|
|
398
|
-
}
|
|
399
300
|
interface ValidationErrorBody {
|
|
400
301
|
error: {
|
|
401
302
|
code: string;
|
|
@@ -421,6 +322,13 @@ interface ValidationErrorBody {
|
|
|
421
322
|
* }), 400);
|
|
422
323
|
* ```
|
|
423
324
|
*/
|
|
424
|
-
declare function buildValidationError(
|
|
325
|
+
declare function buildValidationError({ code, message, requiredFields, exampleBody, nextSteps, extra, }: {
|
|
326
|
+
code: string;
|
|
327
|
+
message: string;
|
|
328
|
+
requiredFields?: Record<string, string>;
|
|
329
|
+
exampleBody?: unknown;
|
|
330
|
+
nextSteps?: Record<string, unknown>;
|
|
331
|
+
extra?: Record<string, unknown>;
|
|
332
|
+
}): ValidationErrorBody;
|
|
425
333
|
|
|
426
|
-
export { type AcceptedMethodEntry, AgentInstructions, AgentMemoryHint, type
|
|
334
|
+
export { type AcceptedMethodEntry, AgentInstructions, AgentMemoryHint, type IdentityMetadataBlock, type IdentityMode, PricingBlock, type Receipt, type Respond402Result, type SignerMatchResultLike, type SolanaMppMethodEntry, type StripeMethodEntry, type TempoMethodEntry, type ValidationErrorBody, type X402MethodEntry, build402Body, buildAcceptedMethods, buildIdentityMetadata, buildValidationError, firstEncounterAgentMemory, respond402 };
|