@relyon/kit 0.0.0-stage → 1.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.
Files changed (225) hide show
  1. package/AGENTS.md +75 -0
  2. package/CHANGELOG.md +1053 -0
  3. package/LICENSE +21 -0
  4. package/QUICKSTART.md +239 -0
  5. package/README.md +117 -2
  6. package/dist/adapters/express.d.ts +39 -0
  7. package/dist/adapters/express.js +106 -0
  8. package/dist/adapters/hono.d.ts +16 -0
  9. package/dist/adapters/hono.js +15 -0
  10. package/dist/adapters/next.d.ts +29 -0
  11. package/dist/adapters/next.js +38 -0
  12. package/dist/agent-card.d.ts +14 -0
  13. package/dist/agent-card.js +58 -0
  14. package/dist/agent-docs.d.ts +36 -0
  15. package/dist/agent-docs.js +78 -0
  16. package/dist/agent-hooks.d.ts +66 -0
  17. package/dist/agent-hooks.js +280 -0
  18. package/dist/agents.d.ts +24 -0
  19. package/dist/agents.js +120 -0
  20. package/dist/api-key.d.ts +6 -0
  21. package/dist/api-key.js +33 -0
  22. package/dist/cache.d.ts +46 -0
  23. package/dist/cache.js +86 -0
  24. package/dist/cart-tokens.d.ts +31 -0
  25. package/dist/cart-tokens.js +58 -0
  26. package/dist/cart-transfer.d.ts +95 -0
  27. package/dist/cart-transfer.js +387 -0
  28. package/dist/catalog-enrichment.d.ts +6 -0
  29. package/dist/catalog-enrichment.js +71 -0
  30. package/dist/catalog-reads.d.ts +126 -0
  31. package/dist/catalog-reads.js +104 -0
  32. package/dist/catalog.d.ts +78 -0
  33. package/dist/catalog.js +288 -0
  34. package/dist/charge-claims.d.ts +11 -0
  35. package/dist/charge-claims.js +47 -0
  36. package/dist/check.d.ts +44 -0
  37. package/dist/check.js +152 -0
  38. package/dist/checklist-manifest.d.ts +72 -0
  39. package/dist/checklist-manifest.js +341 -0
  40. package/dist/checkout.d.ts +222 -0
  41. package/dist/checkout.js +353 -0
  42. package/dist/cli.d.ts +2 -0
  43. package/dist/cli.js +727 -0
  44. package/dist/confirmation.d.ts +78 -0
  45. package/dist/confirmation.js +124 -0
  46. package/dist/context.d.ts +81 -0
  47. package/dist/context.js +10 -0
  48. package/dist/discovery.d.ts +151 -0
  49. package/dist/discovery.js +346 -0
  50. package/dist/doctor-cart-transfer.d.ts +33 -0
  51. package/dist/doctor-cart-transfer.js +186 -0
  52. package/dist/doctor-catalog.d.ts +8 -0
  53. package/dist/doctor-catalog.js +47 -0
  54. package/dist/doctor-evidence.d.ts +22 -0
  55. package/dist/doctor-evidence.js +57 -0
  56. package/dist/doctor-merchant.d.ts +48 -0
  57. package/dist/doctor-merchant.js +74 -0
  58. package/dist/doctor-source.d.ts +5 -0
  59. package/dist/doctor-source.js +142 -0
  60. package/dist/doctor-variants.d.ts +70 -0
  61. package/dist/doctor-variants.js +102 -0
  62. package/dist/doctor.d.ts +215 -0
  63. package/dist/doctor.js +1689 -0
  64. package/dist/events.d.ts +95 -0
  65. package/dist/events.js +200 -0
  66. package/dist/feed-mapping.d.ts +114 -0
  67. package/dist/feed-mapping.js +152 -0
  68. package/dist/feed-values.d.ts +13 -0
  69. package/dist/feed-values.js +40 -0
  70. package/dist/feeds.d.ts +104 -0
  71. package/dist/feeds.js +366 -0
  72. package/dist/identify.d.ts +102 -0
  73. package/dist/identify.js +124 -0
  74. package/dist/identity.d.ts +37 -0
  75. package/dist/identity.js +54 -0
  76. package/dist/index.d.ts +42 -0
  77. package/dist/index.js +41 -0
  78. package/dist/init.d.ts +157 -0
  79. package/dist/init.js +912 -0
  80. package/dist/kit-config.d.ts +19 -0
  81. package/dist/kit-config.js +43 -0
  82. package/dist/kit-environment.d.ts +20 -0
  83. package/dist/kit-environment.js +32 -0
  84. package/dist/kit-updates.d.ts +47 -0
  85. package/dist/kit-updates.js +77 -0
  86. package/dist/kit-version-project.d.ts +18 -0
  87. package/dist/kit-version-project.js +214 -0
  88. package/dist/kit-version.d.ts +37 -0
  89. package/dist/kit-version.js +162 -0
  90. package/dist/kit.d.ts +516 -0
  91. package/dist/kit.js +1309 -0
  92. package/dist/layers/pages.d.ts +3 -0
  93. package/dist/layers/pages.js +5 -0
  94. package/dist/layers/payments.d.ts +7 -0
  95. package/dist/layers/payments.js +9 -0
  96. package/dist/layers/products.d.ts +10 -0
  97. package/dist/layers/products.js +13 -0
  98. package/dist/live.d.ts +13 -0
  99. package/dist/live.js +52 -0
  100. package/dist/mcp.d.ts +270 -0
  101. package/dist/mcp.js +312 -0
  102. package/dist/next-steps.d.ts +101 -0
  103. package/dist/next-steps.js +257 -0
  104. package/dist/order-pending.d.ts +57 -0
  105. package/dist/order-pending.js +127 -0
  106. package/dist/orders.d.ts +12 -0
  107. package/dist/orders.js +21 -0
  108. package/dist/payments-init.d.ts +19 -0
  109. package/dist/payments-init.js +70 -0
  110. package/dist/payments-routes.d.ts +54 -0
  111. package/dist/payments-routes.js +123 -0
  112. package/dist/payments.d.ts +165 -0
  113. package/dist/payments.js +192 -0
  114. package/dist/pnpm-workspace.d.ts +58 -0
  115. package/dist/pnpm-workspace.js +250 -0
  116. package/dist/policies.d.ts +111 -0
  117. package/dist/policies.js +317 -0
  118. package/dist/preview-hosts.d.ts +64 -0
  119. package/dist/preview-hosts.js +175 -0
  120. package/dist/private-config.d.ts +169 -0
  121. package/dist/private-config.js +820 -0
  122. package/dist/progress.d.ts +54 -0
  123. package/dist/progress.js +153 -0
  124. package/dist/protocol-inputs.d.ts +22 -0
  125. package/dist/protocol-inputs.js +151 -0
  126. package/dist/public-origin.d.ts +50 -0
  127. package/dist/public-origin.js +180 -0
  128. package/dist/refusals.d.ts +86 -0
  129. package/dist/refusals.js +157 -0
  130. package/dist/relay.d.ts +107 -0
  131. package/dist/relay.js +655 -0
  132. package/dist/release-notes.d.ts +2 -0
  133. package/dist/release-notes.js +290 -0
  134. package/dist/relyon-cart-tokens.d.ts +101 -0
  135. package/dist/relyon-cart-tokens.js +521 -0
  136. package/dist/relyon.d.ts +141 -0
  137. package/dist/relyon.js +238 -0
  138. package/dist/robots.d.ts +27 -0
  139. package/dist/robots.js +127 -0
  140. package/dist/rules.d.ts +144 -0
  141. package/dist/rules.js +347 -0
  142. package/dist/sdk/generated/public-api.d.ts +4816 -0
  143. package/dist/sdk/generated/public-api.js +1 -0
  144. package/dist/sdk/index.d.ts +24 -0
  145. package/dist/sdk/index.js +34 -0
  146. package/dist/sdk/signatures.d.ts +17 -0
  147. package/dist/sdk/signatures.js +33 -0
  148. package/dist/setup.d.ts +37 -0
  149. package/dist/setup.js +94 -0
  150. package/dist/signatures.d.ts +112 -0
  151. package/dist/signatures.js +443 -0
  152. package/dist/state.d.ts +185 -0
  153. package/dist/state.js +96 -0
  154. package/dist/store-payments.d.ts +48 -0
  155. package/dist/store-payments.js +143 -0
  156. package/dist/structured-fields.d.ts +26 -0
  157. package/dist/structured-fields.js +200 -0
  158. package/dist/templates.d.ts +19 -0
  159. package/dist/templates.js +193 -0
  160. package/dist/test-checkout-command.d.ts +32 -0
  161. package/dist/test-checkout-command.js +161 -0
  162. package/dist/test-checkout.d.ts +88 -0
  163. package/dist/test-checkout.js +292 -0
  164. package/dist/types.d.ts +103 -0
  165. package/dist/types.js +18 -0
  166. package/dist/ucp-versions.d.ts +57 -0
  167. package/dist/ucp-versions.js +129 -0
  168. package/dist/util.d.ts +23 -0
  169. package/dist/util.js +68 -0
  170. package/dist/variants.d.ts +67 -0
  171. package/dist/variants.js +146 -0
  172. package/dist/version.d.ts +9 -0
  173. package/dist/version.js +10 -0
  174. package/dist/waiting.d.ts +43 -0
  175. package/dist/waiting.js +57 -0
  176. package/dist/webhook-command.d.ts +48 -0
  177. package/dist/webhook-command.js +367 -0
  178. package/dist/webhook-registration.d.ts +47 -0
  179. package/dist/webhook-registration.js +69 -0
  180. package/dist/webmcp-schema.d.ts +14 -0
  181. package/dist/webmcp-schema.js +140 -0
  182. package/dist/webmcp-script.d.ts +3 -0
  183. package/dist/webmcp-script.js +176 -0
  184. package/dist/webmcp-store.d.ts +102 -0
  185. package/dist/webmcp-store.js +116 -0
  186. package/dist/webmcp.d.ts +242 -0
  187. package/dist/webmcp.js +866 -0
  188. package/dist/wire-names.d.ts +85 -0
  189. package/dist/wire-names.js +109 -0
  190. package/package.json +118 -4
  191. package/release-notes.json +290 -0
  192. package/scripts/install-notice.cjs +7 -0
  193. package/skills/relyon-agents/SKILL.md +327 -0
  194. package/skills/relyon-catalog/SKILL.md +499 -0
  195. package/skills/relyon-catalog/references/example-store.md +218 -0
  196. package/skills/relyon-checkout/SKILL.md +603 -0
  197. package/skills/relyon-checkout/references/checkout-flow.md +257 -0
  198. package/skills/relyon-checkout/references/checkout-page.md +315 -0
  199. package/skills/relyon-go-live/SKILL.md +344 -0
  200. package/skills/relyon-orders/SKILL.md +191 -0
  201. package/skills/relyon-orders/references/webhook-receiver.md +113 -0
  202. package/skills/relyon-payments/SKILL.md +117 -0
  203. package/skills/relyon-setup/SKILL.md +1061 -0
  204. package/skills/relyon-setup/references/QUICKSTART.md +239 -0
  205. package/skills/relyon-setup/references/durable-state.md +209 -0
  206. package/skills/relyon-setup/references/express-server.md +388 -0
  207. package/skills/relyon-setup/references/next-app-router.md +251 -0
  208. package/templates/common/STORE-README.md +67 -0
  209. package/templates/common/gitignore +8 -0
  210. package/templates/common/scripts/check-pricing.ts +22 -0
  211. package/templates/common/scripts/serve.mjs +13 -0
  212. package/templates/common/server/catalog.ts +79 -0
  213. package/templates/common/server/checkout-flow.d.ts +34 -0
  214. package/templates/common/server/pages.ts +184 -0
  215. package/templates/common/server/storage.ts +114 -0
  216. package/templates/common/server/store.ts +67 -0
  217. package/templates/express/server/express.ts +20 -0
  218. package/templates/express/tsconfig.build.json +6 -0
  219. package/templates/express/tsconfig.json +9 -0
  220. package/templates/next/app/[[...path]]/route.ts +24 -0
  221. package/templates/next/next.config.mjs +19 -0
  222. package/templates/next/tsconfig.json +12 -0
  223. package/templates/payments/express.ts +39 -0
  224. package/templates/payments/next.ts +38 -0
  225. package/templates/payments/node.ts +39 -0
@@ -0,0 +1,292 @@
1
+ import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
+ import { RelyonProblemError } from "./relyon.js";
3
+ import { StoreRefusal } from "./types.js";
4
+ import { isRecord, jsonResponse } from "./util.js";
5
+ import { defaultPurchasableItem, describeItem, itemForProduct, productVariants, resolveFeedItem } from "./variants.js";
6
+ // One Test purchase a coding agent can run itself: `npx @relyon/store-kit
7
+ // test-checkout --url <store>` posts to this kit route on the store. The route
8
+ // answers only in Test, with a usable rly_test_ key, and only to a request
9
+ // carrying a short-lived HMAC proof made with that same key (the key itself is
10
+ // never sent to the store). It prices one product with the store's own
11
+ // priceCart, opens a Relyon payment session and pays it through payAndConfirm
12
+ // with the Test mock processor's opaque token (what Test card fields return):
13
+ // no card number exists anywhere. The store's createOrder runs as for any
14
+ // checkout, and Relyon records the completed Test checkout.
15
+ /** The kit route the command posts to. Fixed, so the command can find it on any store. */
16
+ export const TEST_CHECKOUT_PATH = "/relyon/test-checkout";
17
+ /** The proof header: `t=<unix seconds>,n=<nonce>,v1=<hex HMAC-SHA256>`. */
18
+ export const TEST_CHECKOUT_PROOF_HEADER = "relyon-test-proof";
19
+ /** How far a proof's timestamp may be from the store's clock, in seconds. */
20
+ export const TEST_CHECKOUT_MAX_SKEW_SECONDS = 300;
21
+ /** The command doctor names for the checkout step. */
22
+ export const TEST_CHECKOUT_COMMAND = "npx @relyon/store-kit test-checkout";
23
+ /** One run's idempotency key: a retry with the same key never makes a second purchase. */
24
+ export const TEST_CHECKOUT_IDEMPOTENCY = /^[A-Za-z0-9_-]{8,64}$/;
25
+ const NONCE = /^[A-Za-z0-9_-]{16,64}$/;
26
+ const MAX_BODY_BYTES = 4096;
27
+ /** The address the Test cart is priced for. Clearly a Test fixture, never a shopper. */
28
+ export const TEST_CHECKOUT_ADDRESS = {
29
+ name: "Relyon Test checkout", line1: "1 Test Street", city: "San Francisco", region: "CA", postal_code: "94105", country: "US",
30
+ };
31
+ const sha256Hex = (text) => createHash("sha256").update(text, "utf8").digest("hex");
32
+ /** The exact text the proof signs. */
33
+ export function testCheckoutProofMessage(input) {
34
+ return ["relyon-test-checkout.v1", input.method.toUpperCase(), input.host.toLowerCase(), input.path, String(input.timestamp), input.nonce, sha256Hex(input.body)].join("\n");
35
+ }
36
+ /** The proof header value for one request. The key never leaves this function. */
37
+ export function signTestCheckout(key, input) {
38
+ const timestamp = input.timestamp ?? Math.floor(Date.now() / 1000);
39
+ const nonce = input.nonce ?? randomBytes(18).toString("base64url");
40
+ const mac = createHmac("sha256", key).update(testCheckoutProofMessage({ ...input, timestamp, nonce }), "utf8").digest("hex");
41
+ return `t=${timestamp},n=${nonce},v1=${mac}`;
42
+ }
43
+ /** Checks a proof against every host the request may have been addressed to. */
44
+ export function verifyTestCheckoutProof(key, header, input) {
45
+ const parts = Object.fromEntries(header.split(",").map((part) => {
46
+ const at = part.indexOf("=");
47
+ return at > 0 ? [part.slice(0, at).trim(), part.slice(at + 1).trim()] : ["", ""];
48
+ }));
49
+ const timestamp = /^\d{1,12}$/.test(parts.t ?? "") ? Number(parts.t) : NaN;
50
+ const nonce = parts.n ?? "";
51
+ const mac = parts.v1 ?? "";
52
+ if (!Number.isSafeInteger(timestamp) || !NONCE.test(nonce) || !/^[0-9a-f]{64}$/.test(mac))
53
+ return { ok: false };
54
+ if (Math.abs(Math.floor(input.now / 1000) - timestamp) > TEST_CHECKOUT_MAX_SKEW_SECONDS)
55
+ return { ok: false };
56
+ const given = Buffer.from(mac, "hex");
57
+ for (const host of new Set(input.hosts.map((h) => h.toLowerCase()).filter(Boolean))) {
58
+ const expected = createHmac("sha256", key).update(testCheckoutProofMessage({ method: input.method, host, path: input.path, timestamp, nonce, body: input.body }), "utf8").digest();
59
+ if (timingSafeEqual(expected, given))
60
+ return { ok: true, nonce, timestamp };
61
+ }
62
+ return { ok: false };
63
+ }
64
+ /** The processor a payment session's client token names ("mock" or "trx"); undefined when unreadable. */
65
+ export function clientTokenProvider(token) {
66
+ if (!token.startsWith("pst_"))
67
+ return undefined;
68
+ try {
69
+ const data = JSON.parse(Buffer.from(token.slice(4), "base64url").toString("utf8"));
70
+ if (!isRecord(data) || data.v !== 1 || typeof data.ps !== "string" || typeof data.provider !== "string")
71
+ return undefined;
72
+ return { provider: data.provider, paymentSession: data.ps };
73
+ }
74
+ catch {
75
+ return undefined;
76
+ }
77
+ }
78
+ const notFound = () => new Response("Not found.\n", { status: 404, headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } });
79
+ const unauthorized = () => jsonResponse(401, { error: "unauthorized" });
80
+ /**
81
+ * A refusal body. `message` and `detail` give the reason; when a field is at
82
+ * fault, `param` names it and `errors` lists each failing field.
83
+ */
84
+ const refused = (status, code, message, field, extra = {}) => jsonResponse(status, {
85
+ object: "test_checkout", status: "refused", code, message, detail: message,
86
+ ...(field ? { param: field.param, errors: field.errors ?? [{ param: field.param, code, message }] } : {}),
87
+ ...extra,
88
+ });
89
+ /** The field errors Relyon named in a problem body, kept small and printable. */
90
+ function problemFields(answer) {
91
+ const errors = (Array.isArray(answer.errors) ? answer.errors : []).filter(isRecord).slice(0, 10).map((row) => ({
92
+ param: typeof row.param === "string" ? row.param.slice(0, 200) : "",
93
+ code: typeof row.code === "string" ? row.code.slice(0, 100) : "invalid_value",
94
+ message: typeof row.message === "string" ? row.message.slice(0, 500) : "",
95
+ })).filter((row) => row.param);
96
+ const param = typeof answer.param === "string" && answer.param ? answer.param.slice(0, 200) : errors[0]?.param;
97
+ return param ? { param, errors: errors.length ? errors : [{ param, code: typeof answer.code === "string" ? answer.code : "invalid_value", message: "" }] } : undefined;
98
+ }
99
+ /** Reads at most MAX_BODY_BYTES, before any proof check; a larger or unreadable body is null (never buffered whole). */
100
+ async function boundedBody(request) {
101
+ const declared = request.headers.get("content-length");
102
+ if (declared !== null && !(Number(declared) <= MAX_BODY_BYTES))
103
+ return null;
104
+ if (!request.body)
105
+ return "";
106
+ const reader = request.body.getReader();
107
+ const chunks = [];
108
+ let size = 0;
109
+ try {
110
+ for (;;) {
111
+ const { done, value } = await reader.read();
112
+ if (done)
113
+ break;
114
+ size += value.byteLength;
115
+ if (size > MAX_BODY_BYTES) {
116
+ await reader.cancel().catch(() => undefined);
117
+ return null;
118
+ }
119
+ chunks.push(value);
120
+ }
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ return Buffer.concat(chunks).toString("utf8");
126
+ }
127
+ /** The hosts a request may have been signed for: its URL, Host and the first X-Forwarded-Host. */
128
+ function requestHosts(request) {
129
+ const forwarded = request.headers.get("x-forwarded-host")?.split(",")[0]?.trim();
130
+ return [new URL(request.url).host, request.headers.get("host") ?? "", forwarded ?? ""];
131
+ }
132
+ /** `POST /relyon/test-checkout`. Never throws. */
133
+ export async function handleTestCheckout(request, deps) {
134
+ // Live, or no Test key: the route doesn't exist.
135
+ if (deps.livemode || !deps.testKey || request.method.toUpperCase() !== "POST")
136
+ return notFound();
137
+ const header = request.headers.get(TEST_CHECKOUT_PROOF_HEADER);
138
+ if (!header)
139
+ return notFound();
140
+ const body = await boundedBody(request);
141
+ if (body === null)
142
+ return unauthorized();
143
+ const now = deps.now();
144
+ const proof = verifyTestCheckoutProof(deps.testKey, header, {
145
+ method: "POST", hosts: requestHosts(request), path: new URL(request.url).pathname, body, now,
146
+ });
147
+ if (!proof.ok)
148
+ return unauthorized();
149
+ for (const [nonce, expires] of deps.nonces)
150
+ if (expires <= now)
151
+ deps.nonces.delete(nonce);
152
+ if (deps.nonces.has(proof.nonce) || deps.nonces.size >= 10_000)
153
+ return unauthorized();
154
+ deps.nonces.set(proof.nonce, now + 2 * TEST_CHECKOUT_MAX_SKEW_SECONDS * 1000);
155
+ let input;
156
+ try {
157
+ const parsed = JSON.parse(body);
158
+ input = isRecord(parsed) ? parsed : undefined;
159
+ }
160
+ catch {
161
+ input = undefined;
162
+ }
163
+ const idempotencyKey = typeof input?.idempotency_key === "string" ? input.idempotency_key : "";
164
+ if (!TEST_CHECKOUT_IDEMPOTENCY.test(idempotencyKey) || (input?.product_id !== undefined && typeof input.product_id !== "string")) {
165
+ const param = !TEST_CHECKOUT_IDEMPOTENCY.test(idempotencyKey) ? "idempotency_key" : "product_id";
166
+ return refused(400, "invalid_request", `${param} is invalid: send {"idempotency_key": "<8-64 letters, digits, - or _>"}, optionally with a product_id string.`, { param });
167
+ }
168
+ const running = deps.inflight.get(idempotencyKey);
169
+ if (running)
170
+ return (await running).clone();
171
+ const run = purchase(deps, idempotencyKey, input?.product_id);
172
+ deps.inflight.set(idempotencyKey, run);
173
+ try {
174
+ return (await run).clone();
175
+ }
176
+ finally {
177
+ deps.inflight.delete(idempotencyKey);
178
+ }
179
+ }
180
+ /**
181
+ * The cart lines whose item doesn't name an agent-purchasable product of the
182
+ * kit's catalog (its merchant_product_id, a product of that group_id family,
183
+ * or one of its feed.variants IDs): the same item check Relyon runs on agent
184
+ * checkouts.
185
+ */
186
+ function unlistedItems(cart, purchasable) {
187
+ const ids = new Set(purchasable.flatMap((product) => [product.merchant_product_id, ...(typeof product.group_id === "string" && product.group_id ? [product.group_id] : []),
188
+ ...productVariants(product).map((variant) => variant.id)]));
189
+ return (Array.isArray(cart?.lines) ? cart.lines : []).flatMap((line, index) => {
190
+ const id = isRecord(line) && typeof line.merchant_product_id === "string" ? line.merchant_product_id : "";
191
+ if (ids.has(id))
192
+ return [];
193
+ const param = `cart.lines[${index}].merchant_product_id`;
194
+ return [{ param, code: "product_not_purchasable", message: `${param}: item ${JSON.stringify(id.slice(0, 128))} is not an agent-purchasable product in the store's synced catalog.` }];
195
+ });
196
+ }
197
+ async function purchase(deps, idempotencyKey, productId) {
198
+ try {
199
+ // Only products the merchant affirmatively enabled for agents (visible and purchasable).
200
+ const purchasable = (await deps.products()).filter((product) => product.agent?.visible === true && product.agent?.purchasable === true);
201
+ // A product without options first; else a product's first listed variant;
202
+ // else the first value of each option it declares (variants.ts).
203
+ const catalog = purchasable;
204
+ let item;
205
+ if (productId === undefined)
206
+ item = defaultPurchasableItem(catalog);
207
+ else {
208
+ // --product takes a product ID or a variant's feed ID.
209
+ const resolved = resolveFeedItem(catalog, productId);
210
+ item = !resolved ? null : resolved.options ? { ...resolved, source: "first_variant" } : itemForProduct(resolved.product);
211
+ }
212
+ if (!item) {
213
+ return refused(409, "no_purchasable_product", productId === undefined
214
+ ? "The kit's catalog has no agent-purchasable product. Mark one product agent.visible and agent.purchasable (relyon-catalog skill), restart the server, then rerun test-checkout."
215
+ : `product_id ${JSON.stringify(productId.slice(0, 128))} is not an agent-purchasable product (or a variant ID of one) in the kit's catalog.`, { param: productId === undefined ? "catalog" : "product_id" });
216
+ }
217
+ const options = item.options;
218
+ // What was tried, in every refusal: the product and the exact options sent.
219
+ const tried = { product_id: item.product_id, ...(options ? { options } : {}), ...(item.feed_id !== item.product_id ? { item_id: item.feed_id } : {}) };
220
+ const line = "cart.lines[0]";
221
+ let cart;
222
+ try {
223
+ cart = await deps.priceCart([{ product_id: item.product_id, quantity: 1, ...(options ? { options: { ...options } } : {}) }], TEST_CHECKOUT_ADDRESS, [], { protocol: "web", operation: "create", shippingOptionId: null, agentCheckoutId: null });
224
+ }
225
+ catch (error) {
226
+ const hint = item.source === "options_unreadable"
227
+ ? ` ${item.product_id} has options and lists no feed.variants, so test-checkout priced it without options; list its variants in feed.variants (relyon-catalog skill).`
228
+ : item.source === "first_option_values" ? ` ${item.product_id} lists no feed.variants, so test-checkout chose the first value of each option; list its variants in feed.variants (relyon-catalog skill).` : "";
229
+ const retry = ` To buy another product, rerun with --product <id>.`;
230
+ const what = `${line} (product ${describeItem(item.product_id, options)})`;
231
+ if (error instanceof StoreRefusal) {
232
+ const message = `The store's priceCart refused the Test cart line ${what}: ${error.message}${hint}${retry}`;
233
+ return refused(422, error.code, message, { param: line, errors: [{ param: line, code: error.code, message }] }, tried);
234
+ }
235
+ return refused(500, "price_cart_failed", `The store's priceCart threw while pricing the Test cart line ${what}. Check the server log.${hint}${retry}`, { param: line }, tried);
236
+ }
237
+ const amount = cart?.totals?.total;
238
+ const currency = typeof cart?.totals?.currency === "string" ? cart.totals.currency.toUpperCase() : undefined;
239
+ if (!Number.isSafeInteger(amount) || amount <= 0 || typeof currency !== "string") {
240
+ return refused(500, "price_cart_failed", "The store's priceCart returned a cart without a positive totals.total and a currency.", { param: !Number.isSafeInteger(amount) || amount <= 0 ? "cart.totals.total" : "cart.totals.currency" }, tried);
241
+ }
242
+ // The line must pass the item check Relyon runs on agent checkouts.
243
+ const unlisted = unlistedItems(cart, purchasable);
244
+ if (unlisted.length) {
245
+ return refused(422, "product_not_purchasable", `${unlisted[0].message} Return the product's merchant_product_id (or the variant's feed ID) from priceCart.`, { param: unlisted[0].param, errors: unlisted }, tried);
246
+ }
247
+ const orderReference = `relyon-test-${idempotencyKey}`;
248
+ const session = await deps.openSession({ amount, currency, orderReference, idempotencyKey: `sk-tc-ps-${idempotencyKey}` });
249
+ const token = typeof session.client_token === "string" ? clientTokenProvider(session.client_token) : undefined;
250
+ if (!token || token.provider !== "mock") {
251
+ return refused(409, "processor_not_mock", `This sandbox's Test payments use hosted card fields (such as a TRX sandbox account), not Relyon's Test mock processor, so test-checkout can't pay without a person. Complete one Test purchase on the store's checkout page instead: ${deps.checkoutUrl}`);
252
+ }
253
+ const paid = await deps.payAndConfirm({
254
+ cart, orderReference, channel: "web",
255
+ // The Test mock processor's opaque token, exactly what Test card fields return. No card data.
256
+ paymentMethod: { type: "hosted_card", payment_session: token.paymentSession, encrypted_data: "mock-encrypted-card", key_id: "mock-key" },
257
+ });
258
+ const summary = { ...tried, amount, currency, order_reference: orderReference };
259
+ if (paid.confirmation) {
260
+ return jsonResponse(200, { object: "test_checkout", status: "succeeded", livemode: false, ...summary,
261
+ payment_id: paid.confirmation.payment_id });
262
+ }
263
+ if (paid.orderPending) {
264
+ return jsonResponse(202, { object: "test_checkout", status: "order_pending", livemode: false, ...summary,
265
+ message: "The Test payment succeeded and the store's order is still being created. Resend the same request (same idempotency_key); it never pays twice." });
266
+ }
267
+ if (paid.outcomeUnknown) {
268
+ return jsonResponse(202, { object: "test_checkout", status: "outcome_unknown", livemode: false, ...summary,
269
+ message: "Relyon's answer was lost. Resend the same request (same idempotency_key); it never pays twice." });
270
+ }
271
+ let answer;
272
+ try {
273
+ answer = await paid.response.clone().json();
274
+ }
275
+ catch {
276
+ answer = undefined;
277
+ }
278
+ const detail = isRecord(answer) && isRecord(answer.order_refusal) ? answer.order_refusal : isRecord(answer) ? answer : {};
279
+ const code = typeof detail.code === "string" ? detail.code : "payment_refused";
280
+ const reason = typeof detail.detail === "string" ? detail.detail : typeof detail.message === "string" ? detail.message : "The Test payment was refused.";
281
+ return refused(paid.response.status >= 400 ? paid.response.status : 502, code, reason.slice(0, 500), problemFields(detail), summary);
282
+ }
283
+ catch (error) {
284
+ const code = isRecord(error) && typeof error.code === "string" ? error.code : "internal_error";
285
+ const status = isRecord(error) && typeof error.status === "number" && error.status >= 400 && error.status < 600 ? error.status : 500;
286
+ if (error instanceof RelyonProblemError) {
287
+ // Relyon's own refusal: its field and reason.
288
+ return refused(status, code, `Relyon refused the Test checkout: ${error.message}`.slice(0, 500), problemFields({ ...(error.problem ?? {}), code, ...(error.param ? { param: error.param } : {}) }));
289
+ }
290
+ return refused(status, code, "The Test checkout could not be completed. Check the store's server log, then resend the same request (same idempotency_key).");
291
+ }
292
+ }
@@ -0,0 +1,103 @@
1
+ import type { components } from "./sdk/index.js";
2
+ type Schemas = components["schemas"];
3
+ /** The cart exactly as the store priced it (the contract's `Cart`). */
4
+ export type Cart = Schemas["Cart"];
5
+ export type CartLine = Schemas["CartLine"];
6
+ export type Address = Schemas["Address"];
7
+ export type Payment = Schemas["Payment"];
8
+ export type PaymentSession = Schemas["PaymentSession"];
9
+ export type PaymentChannel = Schemas["PaymentChannel"];
10
+ export type FulfillmentUpdate = Schemas["FulfillmentUpdate"];
11
+ export type Order = Schemas["Order"];
12
+ export type AgentRules = Schemas["AgentRules"];
13
+ /** One agent a rule matches. (The generated type is `unknown` because the schema is an anyOf.) */
14
+ export interface AgentRuleAgent {
15
+ name?: Schemas["AgentName"];
16
+ network?: "visa_tap" | "mastercard_agent_pay" | "relyon";
17
+ key_id?: string;
18
+ source?: "platform" | "merchant";
19
+ }
20
+ export type AgentName = Schemas["AgentName"];
21
+ export type AgentEventType = Schemas["AgentEventType"];
22
+ export type AgentEventInput = Schemas["AgentEventInput"];
23
+ export type AgentProtocol = Schemas["AgentProtocol"];
24
+ export type CheckoutOperation = Schemas["AgentCheckoutOperation"];
25
+ export type ProductInput = Schemas["ProductInput"];
26
+ /** One product in the store's own catalog. `merchant_product_id` is required: it is the index ID. */
27
+ export type StoreProduct = ProductInput & {
28
+ merchant_product_id: string;
29
+ };
30
+ /** One line an agent or shopper asked for, before the store prices it. */
31
+ export interface CartLineInput {
32
+ /** The product ID the agent named (the catalog index ID, which is the store's `merchant_product_id` for kit-synced catalogs). */
33
+ product_id: string;
34
+ quantity: number;
35
+ /** Choices the agent passed for a configurable product. */
36
+ options?: Record<string, unknown>;
37
+ }
38
+ /** Everything the store needs to price a cart. */
39
+ export interface CartInputs {
40
+ lines: CartLineInput[];
41
+ address: Address | null;
42
+ coupons: string[];
43
+ /** The shipping option the agent chose, one of the IDs the store offered. */
44
+ shipping_option_id: string | null;
45
+ }
46
+ export interface PriceContext {
47
+ /** Where the cart is being priced: an agent protocol, or the store's own checkout when a handed-off shopper lands. */
48
+ protocol: AgentProtocol | "web";
49
+ /** `cart_transfer`: a UCP cart transfer (`POST <ucp prefix>/carts`), priced for a cart only, never an agent checkout. */
50
+ operation: CheckoutOperation | "landing" | "cart_transfer";
51
+ shippingOptionId: string | null;
52
+ /** The agent checkout the cart belongs to, once Relyon has named it. */
53
+ agentCheckoutId: string | null;
54
+ }
55
+ /**
56
+ * The store prices every cart. Return one cart line per input line, in the same
57
+ * order, and only totals that add up: Relyon charges exactly `totals.total`.
58
+ * Throw a `StoreRefusal` to turn the agent away with a protocol-format error.
59
+ */
60
+ export type PriceCart = (lines: CartLineInput[], address: Address | null, coupons: string[], context: PriceContext) => Promise<Cart> | Cart;
61
+ /** Payment as Relyon reports it. The kit passes through what Relyon returned. */
62
+ export type PaymentLike = Omit<Partial<Payment>, "id" | "status"> & {
63
+ id: string;
64
+ status: string;
65
+ } & Record<string, unknown>;
66
+ /** See `StoreKitOptions.paymentCartFormat`. */
67
+ export type PaymentCartFormat = "contract" | "server-legacy";
68
+ /** Called exactly once for each succeeded payment. */
69
+ export type CreateOrder = (cart: Cart, payment: PaymentLike) => Promise<unknown> | unknown;
70
+ /**
71
+ * Finds the store's existing order for a succeeded payment, by Relyon's payment
72
+ * ID (the `payment.id` `createOrder` received). Return the order (or its ID),
73
+ * or null when there is none. Read-only: it must never create an order.
74
+ */
75
+ export type FindOrderByPaymentId = (paymentId: string) => Promise<unknown> | unknown;
76
+ export interface StoreHooks {
77
+ priceCart: PriceCart;
78
+ createOrder: CreateOrder;
79
+ /** Optional: see `StoreKitOptions.findOrderByPaymentId`. */
80
+ findOrderByPaymentId?: FindOrderByPaymentId;
81
+ }
82
+ /** A refusal the store raises from `priceCart`; the agent gets it in its protocol's error format. */
83
+ export declare class StoreRefusal extends Error {
84
+ readonly code: string;
85
+ /** The HTTP status for protocols that answer refusals with one. */
86
+ readonly status: number;
87
+ constructor(code: string, message: string,
88
+ /** The HTTP status for protocols that answer refusals with one. */
89
+ status?: number);
90
+ }
91
+ export interface Logger {
92
+ warn(message: string, detail?: Record<string, unknown>): void;
93
+ error(message: string, detail?: Record<string, unknown>): void;
94
+ /** Informational lines (a successful sync's resolved store); optional so existing loggers keep working. */
95
+ info?(message: string, detail?: Record<string, unknown>): void;
96
+ }
97
+ export declare const consoleLogger: Logger;
98
+ /** Extra details the framework knows about a request. */
99
+ export interface RequestInfo {
100
+ /** The client IP the store saw. */
101
+ ip?: string;
102
+ }
103
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,18 @@
1
+ /** A refusal the store raises from `priceCart`; the agent gets it in its protocol's error format. */
2
+ export class StoreRefusal extends Error {
3
+ code;
4
+ status;
5
+ constructor(code, message,
6
+ /** The HTTP status for protocols that answer refusals with one. */
7
+ status = 422) {
8
+ super(message);
9
+ this.code = code;
10
+ this.status = status;
11
+ this.name = "StoreRefusal";
12
+ }
13
+ }
14
+ export const consoleLogger = {
15
+ warn: (message, detail) => console.warn(`[relyon-store-kit] ${message}`, detail ?? ""),
16
+ error: (message, detail) => console.error(`[relyon-store-kit] ${message}`, detail ?? ""),
17
+ info: (message, detail) => console.log(`[relyon-store-kit] ${message}`, detail ?? ""),
18
+ };
@@ -0,0 +1,57 @@
1
+ export declare const UCP_CURRENT_VERSION = "2026-08-25";
2
+ export declare const UCP_2026_04_08 = "2026-04-08";
3
+ export type StoreUcpVersion = typeof UCP_CURRENT_VERSION | typeof UCP_2026_04_08;
4
+ export declare const CART_CAPABILITY = "dev.ucp.shopping.cart";
5
+ /** Where the 2026-04-08 profile lives on the store's origin. */
6
+ export declare const UCP_2026_04_08_PROFILE_PATH = "/.well-known/ucp/2026-04-08";
7
+ /** The 2026-04-08 REST endpoint is the kit's UCP prefix plus this segment (for example `/ucp/2026-04-08`). */
8
+ export declare const UCP_2026_04_08_SEGMENT = "/2026-04-08";
9
+ /** The cart capability at 2026-08-25 (spec page with its trailing slash; no redirect). */
10
+ export declare const CART_CAPABILITY_2026_08_25: Readonly<{
11
+ version: "2026-08-25";
12
+ spec: "https://ucp.dev/2026-08-25/specification/shopping/cart/";
13
+ schema: "https://ucp.dev/2026-08-25/schemas/shopping/cart.json";
14
+ }>;
15
+ /**
16
+ * Capability → its 2026-04-08 spec page and schema. 2026-04-08 has no
17
+ * `shopping/` or `extensions/` segment in its specification paths; schemas
18
+ * keep their `shopping/<name>.json` names. Anything not listed is left out
19
+ * of the 2026-04-08 profile: AP2 (Relyon's UCP checkout negotiates it at
20
+ * 2026-08-25 only) and order (the kit serves no order reads under its 2026-04-08
21
+ * REST endpoint, and order webhooks stay 2026-08-25).
22
+ */
23
+ export declare const CAPABILITIES_2026_04_08: Readonly<Record<string, {
24
+ spec: string;
25
+ schema: string;
26
+ extends?: string;
27
+ }>>;
28
+ /** The 2026-04-08 REST shopping service's spec page and OpenAPI document. */
29
+ export declare const SHOPPING_REST_2026_04_08: Readonly<{
30
+ spec: "https://ucp.dev/2026-04-08/specification/overview/";
31
+ schema: "https://ucp.dev/2026-04-08/services/shopping/rest.openapi.json";
32
+ }>;
33
+ type Json = Record<string, unknown>;
34
+ export interface ProfileAdditions {
35
+ /** The store's public origin the profile is served on (its endpoints already moved there). */
36
+ origin: string;
37
+ /** The kit's UCP REST prefix, such as `/ucp`. */
38
+ ucpPath: string;
39
+ /** Cart transfer is enabled and callable. */
40
+ cart: boolean;
41
+ }
42
+ /**
43
+ * The 2026-04-08 profile derived from Relyon's 2026-08-25 body, or null when
44
+ * there is nothing to offer at 2026-04-08 (no REST shopping service at the
45
+ * kit's prefix, an unknown version, or no capability left). Signing keys are
46
+ * published as `signing_keys[]` (canonical at 2026-04-08) with the `keys[]`
47
+ * mirror. A store that requires AP2 checkout mandates gets no 2026-04-08
48
+ * checkout capabilities: Relyon would refuse a 2026-04-08 complete there.
49
+ */
50
+ export declare function profile20260408(body: unknown, additions: ProfileAdditions): Json | null;
51
+ /**
52
+ * The 2026-08-25 profile the store serves: Relyon's body plus the cart
53
+ * capability (when enabled and callable) and `supported_versions` (when a
54
+ * 2026-04-08 profile exists). Otherwise unchanged.
55
+ */
56
+ export declare function currentProfile(body: unknown, additions: ProfileAdditions): unknown;
57
+ export {};
@@ -0,0 +1,129 @@
1
+ import { isRecord } from "./util.js";
2
+ // UCP versions the store serves. Relyon's profile (GET /v1/agent_profiles/ucp)
3
+ // is UCP 2026-08-25. Google's live UCP surfaces also speak 2026-04-08, so the
4
+ // kit adds to the profile it serves:
5
+ //
6
+ // - `dev.ucp.shopping.cart` (cart transfer, answered by the kit itself), only
7
+ // while cart transfer is enabled and the profile's REST endpoint is the
8
+ // kit's own UCP prefix;
9
+ // - `supported_versions` naming a 2026-04-08 profile on the store's origin,
10
+ // derived from the same body with the fixed mapping below.
11
+ //
12
+ // So the store no longer serves Relyon's body byte for byte: the additions
13
+ // are additive, and every other member is passed through unchanged.
14
+ export const UCP_CURRENT_VERSION = "2026-08-25";
15
+ export const UCP_2026_04_08 = "2026-04-08";
16
+ export const CART_CAPABILITY = "dev.ucp.shopping.cart";
17
+ const SHOPPING_SERVICE = "dev.ucp.shopping";
18
+ const AP2_CAPABILITY = "dev.ucp.common.payment.ap2_mandate";
19
+ /** Where the 2026-04-08 profile lives on the store's origin. */
20
+ export const UCP_2026_04_08_PROFILE_PATH = "/.well-known/ucp/2026-04-08";
21
+ /** The 2026-04-08 REST endpoint is the kit's UCP prefix plus this segment (for example `/ucp/2026-04-08`). */
22
+ export const UCP_2026_04_08_SEGMENT = "/2026-04-08";
23
+ const CURRENT = `https://ucp.dev/${UCP_CURRENT_VERSION}`;
24
+ const V0408 = `https://ucp.dev/${UCP_2026_04_08}`;
25
+ /** The cart capability at 2026-08-25 (spec page with its trailing slash; no redirect). */
26
+ export const CART_CAPABILITY_2026_08_25 = Object.freeze({
27
+ version: UCP_CURRENT_VERSION,
28
+ spec: `${CURRENT}/specification/shopping/cart/`,
29
+ schema: `${CURRENT}/schemas/shopping/cart.json`,
30
+ });
31
+ /**
32
+ * Capability → its 2026-04-08 spec page and schema. 2026-04-08 has no
33
+ * `shopping/` or `extensions/` segment in its specification paths; schemas
34
+ * keep their `shopping/<name>.json` names. Anything not listed is left out
35
+ * of the 2026-04-08 profile: AP2 (Relyon's UCP checkout negotiates it at
36
+ * 2026-08-25 only) and order (the kit serves no order reads under its 2026-04-08
37
+ * REST endpoint, and order webhooks stay 2026-08-25).
38
+ */
39
+ export const CAPABILITIES_2026_04_08 = Object.freeze({
40
+ "dev.ucp.shopping.checkout": { spec: `${V0408}/specification/checkout/`, schema: `${V0408}/schemas/shopping/checkout.json` },
41
+ "dev.ucp.shopping.fulfillment": { spec: `${V0408}/specification/fulfillment/`, schema: `${V0408}/schemas/shopping/fulfillment.json`, extends: "dev.ucp.shopping.checkout" },
42
+ "dev.ucp.shopping.discount": { spec: `${V0408}/specification/discount/`, schema: `${V0408}/schemas/shopping/discount.json`, extends: "dev.ucp.shopping.checkout" },
43
+ [CART_CAPABILITY]: { spec: `${V0408}/specification/cart/`, schema: `${V0408}/schemas/shopping/cart.json` },
44
+ });
45
+ /** The 2026-04-08 REST shopping service's spec page and OpenAPI document. */
46
+ export const SHOPPING_REST_2026_04_08 = Object.freeze({
47
+ spec: `${V0408}/specification/overview/`,
48
+ schema: `${V0408}/services/shopping/rest.openapi.json`,
49
+ });
50
+ /** The checkout capabilities that only work together with the relayed checkout. */
51
+ const CHECKOUT_FAMILY = ["dev.ucp.shopping.checkout", "dev.ucp.shopping.fulfillment", "dev.ucp.shopping.discount"];
52
+ /** The profile's REST shopping service at exactly `endpoint`, or undefined. */
53
+ function restService(ucp, endpoint) {
54
+ const services = isRecord(ucp.services) ? ucp.services[SHOPPING_SERVICE] : undefined;
55
+ if (!Array.isArray(services))
56
+ return undefined;
57
+ return services.find((service) => isRecord(service) && service.transport === "rest" && service.endpoint === endpoint);
58
+ }
59
+ /**
60
+ * The 2026-04-08 profile derived from Relyon's 2026-08-25 body, or null when
61
+ * there is nothing to offer at 2026-04-08 (no REST shopping service at the
62
+ * kit's prefix, an unknown version, or no capability left). Signing keys are
63
+ * published as `signing_keys[]` (canonical at 2026-04-08) with the `keys[]`
64
+ * mirror. A store that requires AP2 checkout mandates gets no 2026-04-08
65
+ * checkout capabilities: Relyon would refuse a 2026-04-08 complete there.
66
+ */
67
+ export function profile20260408(body, additions) {
68
+ if (!isRecord(body) || !isRecord(body.ucp) || body.ucp.version !== UCP_CURRENT_VERSION)
69
+ return null;
70
+ const ucp = body.ucp;
71
+ const endpoint = `${additions.origin}${additions.ucpPath}`;
72
+ if (!restService(ucp, endpoint))
73
+ return null;
74
+ const current = isRecord(ucp.capabilities) ? ucp.capabilities : {};
75
+ const mandates = AP2_CAPABILITY in current;
76
+ const names = [
77
+ ...(mandates ? [] : CHECKOUT_FAMILY.filter((name) => Array.isArray(current[name]) && current[name].length > 0)),
78
+ ...(additions.cart ? [CART_CAPABILITY] : []),
79
+ ];
80
+ // Extensions only alongside the checkout they extend.
81
+ const kept = names.filter((name) => {
82
+ const parent = CAPABILITIES_2026_04_08[name].extends;
83
+ return !parent || names.includes(parent);
84
+ });
85
+ if (!kept.length)
86
+ return null;
87
+ const keys = Array.isArray(body.keys) ? body.keys.filter(isRecord) : [];
88
+ return {
89
+ ucp: {
90
+ version: UCP_2026_04_08,
91
+ services: {
92
+ [SHOPPING_SERVICE]: [{
93
+ version: UCP_2026_04_08, spec: SHOPPING_REST_2026_04_08.spec, transport: "rest",
94
+ endpoint: `${endpoint}${UCP_2026_04_08_SEGMENT}`, schema: SHOPPING_REST_2026_04_08.schema,
95
+ }],
96
+ },
97
+ capabilities: Object.fromEntries(kept.map((name) => {
98
+ const mapped = CAPABILITIES_2026_04_08[name];
99
+ return [name, [{ version: UCP_2026_04_08, spec: mapped.spec, schema: mapped.schema, ...(mapped.extends ? { extends: mapped.extends } : {}) }]];
100
+ })),
101
+ // Store-first profiles carry no payment handlers; none are mapped.
102
+ payment_handlers: {},
103
+ },
104
+ signing_keys: keys.map((key) => ({ ...key })),
105
+ keys: keys.map((key) => ({ ...key })),
106
+ };
107
+ }
108
+ /**
109
+ * The 2026-08-25 profile the store serves: Relyon's body plus the cart
110
+ * capability (when enabled and callable) and `supported_versions` (when a
111
+ * 2026-04-08 profile exists). Otherwise unchanged.
112
+ */
113
+ export function currentProfile(body, additions) {
114
+ if (!isRecord(body) || !isRecord(body.ucp) || body.ucp.version !== UCP_CURRENT_VERSION)
115
+ return body;
116
+ const endpoint = `${additions.origin}${additions.ucpPath}`;
117
+ if (!restService(body.ucp, endpoint))
118
+ return body;
119
+ const capabilities = isRecord(body.ucp.capabilities) ? body.ucp.capabilities : {};
120
+ const leaf = profile20260408(body, additions);
121
+ return {
122
+ ...body,
123
+ ucp: {
124
+ ...body.ucp,
125
+ ...(leaf ? { supported_versions: { ...(isRecord(body.ucp.supported_versions) ? body.ucp.supported_versions : {}), [UCP_2026_04_08]: `${additions.origin}${UCP_2026_04_08_PROFILE_PATH}` } } : {}),
126
+ capabilities: additions.cart ? { ...capabilities, [CART_CAPABILITY]: [{ ...CART_CAPABILITY_2026_08_25 }] } : capabilities,
127
+ },
128
+ };
129
+ }
package/dist/util.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** JSON with object keys sorted, so equal values always hash the same. */
2
+ export declare function canonicalJson(value: unknown): string;
3
+ export declare const sha256: (text: string | Uint8Array) => string;
4
+ /** A random ID that matches the contract's event ID pattern (`^[A-Za-z0-9._:-]+$`). */
5
+ export declare const randomId: (prefix: string) => string;
6
+ export declare const base64url: (bytes: Uint8Array) => string;
7
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
8
+ /** Every request header with its name in lower case. Repeated headers are already joined with ", " by `Headers`. */
9
+ export declare function lowerCaseHeaders(headers: Headers): Record<string, string>;
10
+ export declare const unixSeconds: (ms: number) => number;
11
+ export declare function jsonResponse(status: number, body: unknown, headers?: Record<string, string>): Response;
12
+ export declare function textResponse(status: number, body: string, contentType: string, headers?: Record<string, string>): Response;
13
+ export declare function escapeHtml(value: string): string;
14
+ export declare function escapeXml(value: string): string;
15
+ /** Parses JSON without throwing; `undefined` means it wasn't JSON. */
16
+ export declare function tryParseJson(text: string): unknown;
17
+ /** A three-letter currency code in any case, upper-cased; anything else unchanged (Relyon reports it). */
18
+ export declare function upperCurrency<T>(value: T): T;
19
+ /**
20
+ * The store's cart with its currency codes upper-cased ("usd" and "USD" are
21
+ * the same currency): the top-level `currency` and `totals.currency`.
22
+ */
23
+ export declare function withUpperCurrency<T>(cart: T): T;