@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.
- package/AGENTS.md +75 -0
- package/CHANGELOG.md +1053 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +239 -0
- package/README.md +117 -2
- package/dist/adapters/express.d.ts +39 -0
- package/dist/adapters/express.js +106 -0
- package/dist/adapters/hono.d.ts +16 -0
- package/dist/adapters/hono.js +15 -0
- package/dist/adapters/next.d.ts +29 -0
- package/dist/adapters/next.js +38 -0
- package/dist/agent-card.d.ts +14 -0
- package/dist/agent-card.js +58 -0
- package/dist/agent-docs.d.ts +36 -0
- package/dist/agent-docs.js +78 -0
- package/dist/agent-hooks.d.ts +66 -0
- package/dist/agent-hooks.js +280 -0
- package/dist/agents.d.ts +24 -0
- package/dist/agents.js +120 -0
- package/dist/api-key.d.ts +6 -0
- package/dist/api-key.js +33 -0
- package/dist/cache.d.ts +46 -0
- package/dist/cache.js +86 -0
- package/dist/cart-tokens.d.ts +31 -0
- package/dist/cart-tokens.js +58 -0
- package/dist/cart-transfer.d.ts +95 -0
- package/dist/cart-transfer.js +387 -0
- package/dist/catalog-enrichment.d.ts +6 -0
- package/dist/catalog-enrichment.js +71 -0
- package/dist/catalog-reads.d.ts +126 -0
- package/dist/catalog-reads.js +104 -0
- package/dist/catalog.d.ts +78 -0
- package/dist/catalog.js +288 -0
- package/dist/charge-claims.d.ts +11 -0
- package/dist/charge-claims.js +47 -0
- package/dist/check.d.ts +44 -0
- package/dist/check.js +152 -0
- package/dist/checklist-manifest.d.ts +72 -0
- package/dist/checklist-manifest.js +341 -0
- package/dist/checkout.d.ts +222 -0
- package/dist/checkout.js +353 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +727 -0
- package/dist/confirmation.d.ts +78 -0
- package/dist/confirmation.js +124 -0
- package/dist/context.d.ts +81 -0
- package/dist/context.js +10 -0
- package/dist/discovery.d.ts +151 -0
- package/dist/discovery.js +346 -0
- package/dist/doctor-cart-transfer.d.ts +33 -0
- package/dist/doctor-cart-transfer.js +186 -0
- package/dist/doctor-catalog.d.ts +8 -0
- package/dist/doctor-catalog.js +47 -0
- package/dist/doctor-evidence.d.ts +22 -0
- package/dist/doctor-evidence.js +57 -0
- package/dist/doctor-merchant.d.ts +48 -0
- package/dist/doctor-merchant.js +74 -0
- package/dist/doctor-source.d.ts +5 -0
- package/dist/doctor-source.js +142 -0
- package/dist/doctor-variants.d.ts +70 -0
- package/dist/doctor-variants.js +102 -0
- package/dist/doctor.d.ts +215 -0
- package/dist/doctor.js +1689 -0
- package/dist/events.d.ts +95 -0
- package/dist/events.js +200 -0
- package/dist/feed-mapping.d.ts +114 -0
- package/dist/feed-mapping.js +152 -0
- package/dist/feed-values.d.ts +13 -0
- package/dist/feed-values.js +40 -0
- package/dist/feeds.d.ts +104 -0
- package/dist/feeds.js +366 -0
- package/dist/identify.d.ts +102 -0
- package/dist/identify.js +124 -0
- package/dist/identity.d.ts +37 -0
- package/dist/identity.js +54 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +41 -0
- package/dist/init.d.ts +157 -0
- package/dist/init.js +912 -0
- package/dist/kit-config.d.ts +19 -0
- package/dist/kit-config.js +43 -0
- package/dist/kit-environment.d.ts +20 -0
- package/dist/kit-environment.js +32 -0
- package/dist/kit-updates.d.ts +47 -0
- package/dist/kit-updates.js +77 -0
- package/dist/kit-version-project.d.ts +18 -0
- package/dist/kit-version-project.js +214 -0
- package/dist/kit-version.d.ts +37 -0
- package/dist/kit-version.js +162 -0
- package/dist/kit.d.ts +516 -0
- package/dist/kit.js +1309 -0
- package/dist/layers/pages.d.ts +3 -0
- package/dist/layers/pages.js +5 -0
- package/dist/layers/payments.d.ts +7 -0
- package/dist/layers/payments.js +9 -0
- package/dist/layers/products.d.ts +10 -0
- package/dist/layers/products.js +13 -0
- package/dist/live.d.ts +13 -0
- package/dist/live.js +52 -0
- package/dist/mcp.d.ts +270 -0
- package/dist/mcp.js +312 -0
- package/dist/next-steps.d.ts +101 -0
- package/dist/next-steps.js +257 -0
- package/dist/order-pending.d.ts +57 -0
- package/dist/order-pending.js +127 -0
- package/dist/orders.d.ts +12 -0
- package/dist/orders.js +21 -0
- package/dist/payments-init.d.ts +19 -0
- package/dist/payments-init.js +70 -0
- package/dist/payments-routes.d.ts +54 -0
- package/dist/payments-routes.js +123 -0
- package/dist/payments.d.ts +165 -0
- package/dist/payments.js +192 -0
- package/dist/pnpm-workspace.d.ts +58 -0
- package/dist/pnpm-workspace.js +250 -0
- package/dist/policies.d.ts +111 -0
- package/dist/policies.js +317 -0
- package/dist/preview-hosts.d.ts +64 -0
- package/dist/preview-hosts.js +175 -0
- package/dist/private-config.d.ts +169 -0
- package/dist/private-config.js +820 -0
- package/dist/progress.d.ts +54 -0
- package/dist/progress.js +153 -0
- package/dist/protocol-inputs.d.ts +22 -0
- package/dist/protocol-inputs.js +151 -0
- package/dist/public-origin.d.ts +50 -0
- package/dist/public-origin.js +180 -0
- package/dist/refusals.d.ts +86 -0
- package/dist/refusals.js +157 -0
- package/dist/relay.d.ts +107 -0
- package/dist/relay.js +655 -0
- package/dist/release-notes.d.ts +2 -0
- package/dist/release-notes.js +290 -0
- package/dist/relyon-cart-tokens.d.ts +101 -0
- package/dist/relyon-cart-tokens.js +521 -0
- package/dist/relyon.d.ts +141 -0
- package/dist/relyon.js +238 -0
- package/dist/robots.d.ts +27 -0
- package/dist/robots.js +127 -0
- package/dist/rules.d.ts +144 -0
- package/dist/rules.js +347 -0
- package/dist/sdk/generated/public-api.d.ts +4816 -0
- package/dist/sdk/generated/public-api.js +1 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/index.js +34 -0
- package/dist/sdk/signatures.d.ts +17 -0
- package/dist/sdk/signatures.js +33 -0
- package/dist/setup.d.ts +37 -0
- package/dist/setup.js +94 -0
- package/dist/signatures.d.ts +112 -0
- package/dist/signatures.js +443 -0
- package/dist/state.d.ts +185 -0
- package/dist/state.js +96 -0
- package/dist/store-payments.d.ts +48 -0
- package/dist/store-payments.js +143 -0
- package/dist/structured-fields.d.ts +26 -0
- package/dist/structured-fields.js +200 -0
- package/dist/templates.d.ts +19 -0
- package/dist/templates.js +193 -0
- package/dist/test-checkout-command.d.ts +32 -0
- package/dist/test-checkout-command.js +161 -0
- package/dist/test-checkout.d.ts +88 -0
- package/dist/test-checkout.js +292 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.js +18 -0
- package/dist/ucp-versions.d.ts +57 -0
- package/dist/ucp-versions.js +129 -0
- package/dist/util.d.ts +23 -0
- package/dist/util.js +68 -0
- package/dist/variants.d.ts +67 -0
- package/dist/variants.js +146 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.js +10 -0
- package/dist/waiting.d.ts +43 -0
- package/dist/waiting.js +57 -0
- package/dist/webhook-command.d.ts +48 -0
- package/dist/webhook-command.js +367 -0
- package/dist/webhook-registration.d.ts +47 -0
- package/dist/webhook-registration.js +69 -0
- package/dist/webmcp-schema.d.ts +14 -0
- package/dist/webmcp-schema.js +140 -0
- package/dist/webmcp-script.d.ts +3 -0
- package/dist/webmcp-script.js +176 -0
- package/dist/webmcp-store.d.ts +102 -0
- package/dist/webmcp-store.js +116 -0
- package/dist/webmcp.d.ts +242 -0
- package/dist/webmcp.js +866 -0
- package/dist/wire-names.d.ts +85 -0
- package/dist/wire-names.js +109 -0
- package/package.json +118 -4
- package/release-notes.json +290 -0
- package/scripts/install-notice.cjs +7 -0
- package/skills/relyon-agents/SKILL.md +327 -0
- package/skills/relyon-catalog/SKILL.md +499 -0
- package/skills/relyon-catalog/references/example-store.md +218 -0
- package/skills/relyon-checkout/SKILL.md +603 -0
- package/skills/relyon-checkout/references/checkout-flow.md +257 -0
- package/skills/relyon-checkout/references/checkout-page.md +315 -0
- package/skills/relyon-go-live/SKILL.md +344 -0
- package/skills/relyon-orders/SKILL.md +191 -0
- package/skills/relyon-orders/references/webhook-receiver.md +113 -0
- package/skills/relyon-payments/SKILL.md +117 -0
- package/skills/relyon-setup/SKILL.md +1061 -0
- package/skills/relyon-setup/references/QUICKSTART.md +239 -0
- package/skills/relyon-setup/references/durable-state.md +209 -0
- package/skills/relyon-setup/references/express-server.md +388 -0
- package/skills/relyon-setup/references/next-app-router.md +251 -0
- package/templates/common/STORE-README.md +67 -0
- package/templates/common/gitignore +8 -0
- package/templates/common/scripts/check-pricing.ts +22 -0
- package/templates/common/scripts/serve.mjs +13 -0
- package/templates/common/server/catalog.ts +79 -0
- package/templates/common/server/checkout-flow.d.ts +34 -0
- package/templates/common/server/pages.ts +184 -0
- package/templates/common/server/storage.ts +114 -0
- package/templates/common/server/store.ts +67 -0
- package/templates/express/server/express.ts +20 -0
- package/templates/express/tsconfig.build.json +6 -0
- package/templates/express/tsconfig.json +9 -0
- package/templates/next/app/[[...path]]/route.ts +24 -0
- package/templates/next/next.config.mjs +19 -0
- package/templates/next/tsconfig.json +12 -0
- package/templates/payments/express.ts +39 -0
- package/templates/payments/next.ts +38 -0
- package/templates/payments/node.ts +39 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AgentIdentity, RelyonRuleRef } from "./identify.js";
|
|
2
|
+
import type { SignatureMethod } from "./signatures.js";
|
|
3
|
+
import type { AgentName, Cart, PaymentLike } from "./types.js";
|
|
4
|
+
export interface OrderConfirmation {
|
|
5
|
+
object: "order_confirmation";
|
|
6
|
+
order_reference: string;
|
|
7
|
+
/** Relyon's payment ID. */
|
|
8
|
+
payment_id: string;
|
|
9
|
+
/** The payment's status as Relyon reported it. */
|
|
10
|
+
status: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
currency: string;
|
|
13
|
+
lines: Array<{
|
|
14
|
+
title: string;
|
|
15
|
+
quantity: number;
|
|
16
|
+
amount: number;
|
|
17
|
+
}>;
|
|
18
|
+
totals: {
|
|
19
|
+
subtotal: number;
|
|
20
|
+
discount: number;
|
|
21
|
+
shipping: number;
|
|
22
|
+
tax: number;
|
|
23
|
+
total: number;
|
|
24
|
+
};
|
|
25
|
+
card: {
|
|
26
|
+
brand: string;
|
|
27
|
+
last4: string | null;
|
|
28
|
+
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* The agent as Relyon records it. Relyon's Payment doesn't carry the agent
|
|
31
|
+
* yet, so unless it does, this is the claim Relyon names from the forwarded
|
|
32
|
+
* shopper headers (`source: forwarded_claim`, always `claimed`).
|
|
33
|
+
*/
|
|
34
|
+
agent: {
|
|
35
|
+
name: AgentName | string | null;
|
|
36
|
+
verification: "verified" | "claimed" | null;
|
|
37
|
+
source: "relyon_payment" | "forwarded_claim";
|
|
38
|
+
};
|
|
39
|
+
/** The store kit's own edge check of the agent's signature. Not Relyon's naming. */
|
|
40
|
+
store_kit_verification: {
|
|
41
|
+
verified: boolean;
|
|
42
|
+
name: AgentName | null;
|
|
43
|
+
method: SignatureMethod | null;
|
|
44
|
+
};
|
|
45
|
+
/** Unix seconds. */
|
|
46
|
+
created: number;
|
|
47
|
+
}
|
|
48
|
+
export interface OrderRefusal {
|
|
49
|
+
object: "order_refusal";
|
|
50
|
+
order_reference: string;
|
|
51
|
+
/** `agent_refused`, `channel_paused`, `service_unavailable`, or the decline code (`card_declined`, ...). */
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
/** The Relyon rule behind an agent refusal. */
|
|
55
|
+
rule: string | null;
|
|
56
|
+
payment_id: string | null;
|
|
57
|
+
}
|
|
58
|
+
/** The confirmation for a payment of `cart` (the cart that was charged). */
|
|
59
|
+
export declare function orderConfirmation(input: {
|
|
60
|
+
cart: Cart;
|
|
61
|
+
orderReference: string;
|
|
62
|
+
payment: PaymentLike;
|
|
63
|
+
agent?: AgentIdentity | null;
|
|
64
|
+
now?: () => number;
|
|
65
|
+
}): OrderConfirmation;
|
|
66
|
+
export declare function orderRefusal(orderReference: string, code: string, message: string, rule?: RelyonRuleRef | null, paymentId?: string | null): OrderRefusal;
|
|
67
|
+
/** schema.org `orderStatus` for a payment status. */
|
|
68
|
+
export declare function schemaOrderStatus(status: string): string;
|
|
69
|
+
/** schema.org Order for the confirmation page. */
|
|
70
|
+
export declare function orderJsonLd(confirmation: OrderConfirmation): Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* The confirmation for the store's confirmation page: the JSON-LD and one
|
|
73
|
+
* `#relyon-order-confirmation` element whose data attributes carry the same
|
|
74
|
+
* values a person reads on the page.
|
|
75
|
+
*/
|
|
76
|
+
export declare function renderOrderConfirmation(confirmation: OrderConfirmation): string;
|
|
77
|
+
/** What the confirmation page shows instead when the payment was refused or declined. */
|
|
78
|
+
export declare function renderOrderRefusal(refusal: OrderRefusal): string;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { decimalAmount } from "./discovery.js";
|
|
2
|
+
import { escapeHtml, isRecord } from "./util.js";
|
|
3
|
+
function cardOf(payment) {
|
|
4
|
+
const card = payment.card;
|
|
5
|
+
if (!isRecord(card) || typeof card.brand !== "string")
|
|
6
|
+
return null;
|
|
7
|
+
const last4 = typeof card.last4 === "string" && /^[0-9]{4}$/.test(card.last4) ? card.last4 : null;
|
|
8
|
+
return { brand: card.brand.slice(0, 40), last4 };
|
|
9
|
+
}
|
|
10
|
+
function relyonAgent(payment, identity) {
|
|
11
|
+
const recorded = payment.agent;
|
|
12
|
+
if (isRecord(recorded) && typeof recorded.tier === "string") {
|
|
13
|
+
return {
|
|
14
|
+
name: typeof recorded.agent_name === "string" ? recorded.agent_name : null,
|
|
15
|
+
verification: recorded.tier === "unverified" ? "claimed" : "verified",
|
|
16
|
+
source: "relyon_payment",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const claimed = identity?.claim.name ?? null;
|
|
20
|
+
return { name: claimed, verification: claimed ? "claimed" : null, source: "forwarded_claim" };
|
|
21
|
+
}
|
|
22
|
+
/** The confirmation for a payment of `cart` (the cart that was charged). */
|
|
23
|
+
export function orderConfirmation(input) {
|
|
24
|
+
const { cart, payment } = input;
|
|
25
|
+
const identity = input.agent ?? null;
|
|
26
|
+
return {
|
|
27
|
+
object: "order_confirmation",
|
|
28
|
+
order_reference: input.orderReference,
|
|
29
|
+
payment_id: payment.id,
|
|
30
|
+
status: payment.status,
|
|
31
|
+
amount: typeof payment.amount === "number" ? payment.amount : cart.totals.total,
|
|
32
|
+
currency: (typeof payment.currency === "string" ? payment.currency : cart.currency).toUpperCase(),
|
|
33
|
+
lines: cart.lines.map((line) => ({ title: line.title, quantity: line.quantity, amount: line.amount })),
|
|
34
|
+
totals: {
|
|
35
|
+
subtotal: cart.totals.subtotal, discount: cart.totals.discount, shipping: cart.totals.shipping, tax: cart.totals.tax, total: cart.totals.total,
|
|
36
|
+
},
|
|
37
|
+
card: cardOf(payment),
|
|
38
|
+
agent: relyonAgent(payment, identity),
|
|
39
|
+
store_kit_verification: {
|
|
40
|
+
verified: identity?.verification === "verified",
|
|
41
|
+
name: identity?.verification === "verified" ? identity.name : null,
|
|
42
|
+
method: identity?.verification === "verified" ? identity.method : null,
|
|
43
|
+
},
|
|
44
|
+
created: typeof payment.created === "number" ? payment.created : Math.floor((input.now ?? Date.now)() / 1000),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function orderRefusal(orderReference, code, message, rule, paymentId) {
|
|
48
|
+
return { object: "order_refusal", order_reference: orderReference, code, message, rule: rule?.label ?? null, payment_id: paymentId ?? null };
|
|
49
|
+
}
|
|
50
|
+
/** schema.org `orderStatus` for a payment status. */
|
|
51
|
+
export function schemaOrderStatus(status) {
|
|
52
|
+
return status === "succeeded" ? "https://schema.org/OrderProcessing" : "https://schema.org/OrderPaymentDue";
|
|
53
|
+
}
|
|
54
|
+
/** schema.org Order for the confirmation page. */
|
|
55
|
+
export function orderJsonLd(confirmation) {
|
|
56
|
+
const money = (amount) => decimalAmount(amount, confirmation.currency);
|
|
57
|
+
return {
|
|
58
|
+
"@context": "https://schema.org",
|
|
59
|
+
"@type": "Order",
|
|
60
|
+
orderNumber: confirmation.order_reference,
|
|
61
|
+
orderStatus: schemaOrderStatus(confirmation.status),
|
|
62
|
+
orderDate: new Date(confirmation.created * 1000).toISOString(),
|
|
63
|
+
identifier: confirmation.payment_id,
|
|
64
|
+
price: money(confirmation.totals.total),
|
|
65
|
+
priceCurrency: confirmation.currency,
|
|
66
|
+
acceptedOffer: confirmation.lines.map((line) => ({
|
|
67
|
+
"@type": "Offer",
|
|
68
|
+
itemOffered: { "@type": "Product", name: line.title },
|
|
69
|
+
price: money(line.amount),
|
|
70
|
+
priceCurrency: confirmation.currency,
|
|
71
|
+
eligibleQuantity: { "@type": "QuantitativeValue", value: line.quantity },
|
|
72
|
+
})),
|
|
73
|
+
partOfInvoice: {
|
|
74
|
+
"@type": "Invoice",
|
|
75
|
+
totalPaymentDue: { "@type": "PriceSpecification", price: money(confirmation.totals.total), priceCurrency: confirmation.currency },
|
|
76
|
+
paymentStatus: confirmation.status === "succeeded" ? "https://schema.org/PaymentComplete" : "https://schema.org/PaymentDue",
|
|
77
|
+
},
|
|
78
|
+
...(confirmation.card ? { paymentMethod: { "@type": "PaymentMethod", name: `${confirmation.card.brand}${confirmation.card.last4 ? ` ending ${confirmation.card.last4}` : ""}` } } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function safeJson(value) {
|
|
82
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026")
|
|
83
|
+
.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
84
|
+
}
|
|
85
|
+
const attr = (name, value) => (value === null || value === undefined ? "" : ` data-${name}="${escapeHtml(String(value))}"`);
|
|
86
|
+
/**
|
|
87
|
+
* The confirmation for the store's confirmation page: the JSON-LD and one
|
|
88
|
+
* `#relyon-order-confirmation` element whose data attributes carry the same
|
|
89
|
+
* values a person reads on the page.
|
|
90
|
+
*/
|
|
91
|
+
export function renderOrderConfirmation(confirmation) {
|
|
92
|
+
const money = (amount) => `${decimalAmount(amount, confirmation.currency)} ${escapeHtml(confirmation.currency)}`;
|
|
93
|
+
const t = confirmation.totals;
|
|
94
|
+
const lines = confirmation.lines.map((line) => `<li class="relyon-order-line"${attr("title", line.title)}${attr("quantity", line.quantity)}${attr("amount", line.amount)}>${escapeHtml(line.title)} × ${line.quantity}: ${money(line.amount)}</li>`).join("");
|
|
95
|
+
const card = confirmation.card ? `${escapeHtml(confirmation.card.brand)}${confirmation.card.last4 ? ` ending ${escapeHtml(confirmation.card.last4)}` : ""}` : "";
|
|
96
|
+
const paid = confirmation.status === "succeeded";
|
|
97
|
+
return [
|
|
98
|
+
`<script type="application/ld+json" id="relyon-order-jsonld">${safeJson(orderJsonLd(confirmation))}</script>`,
|
|
99
|
+
`<section id="relyon-order-confirmation"`
|
|
100
|
+
+ attr("order-reference", confirmation.order_reference) + attr("payment-id", confirmation.payment_id) + attr("status", confirmation.status)
|
|
101
|
+
+ attr("order-status", schemaOrderStatus(confirmation.status)) + attr("amount", confirmation.amount) + attr("currency", confirmation.currency)
|
|
102
|
+
+ attr("subtotal", t.subtotal) + attr("discount", t.discount) + attr("shipping", t.shipping) + attr("tax", t.tax) + attr("total", t.total)
|
|
103
|
+
+ attr("card-brand", confirmation.card?.brand) + attr("card-last4", confirmation.card?.last4)
|
|
104
|
+
+ attr("agent-name", confirmation.agent.name) + attr("agent-verification", confirmation.agent.verification) + attr("agent-source", confirmation.agent.source)
|
|
105
|
+
+ attr("store-kit-verified", confirmation.store_kit_verification.verified ? "true" : "false")
|
|
106
|
+
+ attr("created", confirmation.created) + ">",
|
|
107
|
+
`<h1>${paid ? "Order confirmed" : "Payment due"}</h1>`,
|
|
108
|
+
`<p>Order <strong>${escapeHtml(confirmation.order_reference)}</strong> · payment ${escapeHtml(confirmation.payment_id)}</p>`,
|
|
109
|
+
`<ul>${lines}</ul>`,
|
|
110
|
+
`<p>Subtotal ${money(t.subtotal)} · Discount ${money(t.discount)} · Shipping ${money(t.shipping)} · Tax ${money(t.tax)}</p>`,
|
|
111
|
+
`<p><strong>Total ${money(t.total)}</strong>${card ? ` · Paid with ${card}` : ""}</p>`,
|
|
112
|
+
`</section>`,
|
|
113
|
+
].join("\n");
|
|
114
|
+
}
|
|
115
|
+
/** What the confirmation page shows instead when the payment was refused or declined. */
|
|
116
|
+
export function renderOrderRefusal(refusal) {
|
|
117
|
+
return [
|
|
118
|
+
`<section id="relyon-order-refusal" role="alert"${attr("order-reference", refusal.order_reference)}${attr("code", refusal.code)}${attr("rule", refusal.rule)}${attr("payment-id", refusal.payment_id)}>`,
|
|
119
|
+
`<h1>Not paid</h1>`,
|
|
120
|
+
`<p>${escapeHtml(refusal.message)}</p>`,
|
|
121
|
+
refusal.rule ? `<p>Rule: ${escapeHtml(refusal.rule)}</p>` : "",
|
|
122
|
+
`</section>`,
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { StorePolicyOptions } from "./policies.js";
|
|
2
|
+
import type { AgentEventQueue } from "./events.js";
|
|
3
|
+
import type { RelyonGateway } from "./relyon.js";
|
|
4
|
+
import type { AgentRulesCache } from "./rules.js";
|
|
5
|
+
import type { CheckoutStateStore } from "./state.js";
|
|
6
|
+
import type { CatalogHolder } from "./catalog.js";
|
|
7
|
+
import type { StoreCatalogReads } from "./catalog-reads.js";
|
|
8
|
+
import type { AgentIdentity } from "./identify.js";
|
|
9
|
+
import type { Cart, Logger, PaymentCartFormat, PaymentLike, StoreHooks } from "./types.js";
|
|
10
|
+
export interface KitPaths {
|
|
11
|
+
/** UCP REST prefix; the profile Relyon publishes points agents here. Default `/ucp`. */
|
|
12
|
+
ucp: string;
|
|
13
|
+
/** ACP REST prefix. Default `/acp`. */
|
|
14
|
+
acp: string;
|
|
15
|
+
/** MCP endpoint. Default `/mcp`. */
|
|
16
|
+
mcp: string;
|
|
17
|
+
/** Default `/llms.txt`. */
|
|
18
|
+
llmsTxt: string;
|
|
19
|
+
/** The product sitemap. Default `/sitemap-products.xml`. */
|
|
20
|
+
sitemap: string;
|
|
21
|
+
/** Where Relyon delivers webhooks (`agent_rules.updated`). Default `/relyon/webhooks`. */
|
|
22
|
+
webhook: string;
|
|
23
|
+
/** The store's own checkout page, where handed-off shoppers land. Default `/checkout`. */
|
|
24
|
+
checkout: string;
|
|
25
|
+
/** WebMCP checkout: the script at `<webmcp>.js`, endpoints under `<webmcp>/checkouts/`. Default `/relyon/webmcp`. */
|
|
26
|
+
webmcp: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const DEFAULT_PATHS: KitPaths;
|
|
29
|
+
export interface KitContext {
|
|
30
|
+
gateway: RelyonGateway;
|
|
31
|
+
hooks: StoreHooks;
|
|
32
|
+
state: CheckoutStateStore;
|
|
33
|
+
events: AgentEventQueue;
|
|
34
|
+
rules: AgentRulesCache;
|
|
35
|
+
catalog: CatalogHolder;
|
|
36
|
+
catalogReads?: StoreCatalogReads;
|
|
37
|
+
logger: Logger;
|
|
38
|
+
now: () => number;
|
|
39
|
+
paths: KitPaths;
|
|
40
|
+
paymentCartFormat: PaymentCartFormat;
|
|
41
|
+
/** The store's own policies (the kit `policies` option), added to checkout `links`. */
|
|
42
|
+
policies?: Readonly<StorePolicyOptions>;
|
|
43
|
+
/**
|
|
44
|
+
* Identifies the agent at a request (local signature check + claims).
|
|
45
|
+
* Cached per Request object, so a signature's nonce is spent only once.
|
|
46
|
+
*/
|
|
47
|
+
identify(request: Request, mcpClientName?: string): Promise<AgentIdentity>;
|
|
48
|
+
/** The store's public hostnames: candidate `@authority` values for agent signatures. */
|
|
49
|
+
hostnames: readonly string[];
|
|
50
|
+
/** Refuse identified agents' checkout steps and payments when the agent rules can't be read. */
|
|
51
|
+
failClosed: boolean;
|
|
52
|
+
/** The store's public hostname for this request (one of the configured ones). */
|
|
53
|
+
publicHost(request: Request): string;
|
|
54
|
+
/** The request's URL on the store's public https origin. */
|
|
55
|
+
publicUrl(request: Request): string;
|
|
56
|
+
/** The store's public address for agent-facing links (STORE_PUBLIC_URL, or the known host the request arrived on). */
|
|
57
|
+
publicOrigin(request: Request): string;
|
|
58
|
+
/**
|
|
59
|
+
* The store's published Live signing keys (`keys[]` of its Relyon UCP
|
|
60
|
+
* profile) for a hostname: a fresh cached copy, or a refetch when `refresh`.
|
|
61
|
+
* Throws when only a stale copy (or nothing) can be read.
|
|
62
|
+
*/
|
|
63
|
+
liveSigningKeys?(hostname: string, options: {
|
|
64
|
+
refresh: boolean;
|
|
65
|
+
}): Promise<readonly unknown[]>;
|
|
66
|
+
/** Runs `createOrder` exactly once per succeeded payment (see `OrderOnce`). */
|
|
67
|
+
createOrderOnce(cart: Cart, payment: PaymentLike): Promise<OrderOnce>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What `createOrderOnce` did. `created`: this call created the order.
|
|
71
|
+
* `already_created`: an earlier call did (its claim is marked created).
|
|
72
|
+
* `in_progress`: another call holds the claim and hasn't finished, or the
|
|
73
|
+
* state store can't say whether it did. `failed`: `createOrder` threw
|
|
74
|
+
* (`error`) and the claim was given back.
|
|
75
|
+
*/
|
|
76
|
+
export interface OrderOnce {
|
|
77
|
+
created: boolean;
|
|
78
|
+
status: "created" | "already_created" | "in_progress" | "failed";
|
|
79
|
+
order?: unknown;
|
|
80
|
+
error?: unknown;
|
|
81
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { type StorePolicyOptions } from "./policies.js";
|
|
2
|
+
import { StaleIfErrorCache } from "./cache.js";
|
|
3
|
+
import type { CatalogHolder } from "./catalog.js";
|
|
4
|
+
import { type RelyonGateway } from "./relyon.js";
|
|
5
|
+
import type { StoreProduct } from "./types.js";
|
|
6
|
+
import { escapeHtml } from "./util.js";
|
|
7
|
+
export type UcpProfile = {
|
|
8
|
+
ucp: {
|
|
9
|
+
version: string;
|
|
10
|
+
services: Record<string, unknown>;
|
|
11
|
+
capabilities: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
} & Record<string, unknown>;
|
|
14
|
+
type DomainSummary = {
|
|
15
|
+
hostname: string;
|
|
16
|
+
status: string;
|
|
17
|
+
record_value: string | null;
|
|
18
|
+
};
|
|
19
|
+
/** `/.well-known/ucp` and `/.well-known/relyon-verification`, from cached Relyon reads. */
|
|
20
|
+
export declare class DiscoveryReads {
|
|
21
|
+
private readonly now;
|
|
22
|
+
readonly profiles: StaleIfErrorCache<string, UcpProfile>;
|
|
23
|
+
readonly domains: StaleIfErrorCache<"all", DomainSummary[]>;
|
|
24
|
+
private lastMissRefresh;
|
|
25
|
+
private domainsFailure;
|
|
26
|
+
constructor(gateway: RelyonGateway, now: () => number);
|
|
27
|
+
/** This store just changed its domains through Relyon: the next read fetches the list, even during a failure backoff. */
|
|
28
|
+
domainsChanged(): void;
|
|
29
|
+
/**
|
|
30
|
+
* The store's UCP profile for one of its hostnames. `origin` (the store's
|
|
31
|
+
* public address for the request) replaces the profile's
|
|
32
|
+
* `https://<hostname>` endpoints when it differs, such as a Test loopback
|
|
33
|
+
* store on plain http with a port; otherwise the profile is served unchanged.
|
|
34
|
+
*/
|
|
35
|
+
ucpProfile(hostname: string, origin?: string): Promise<Response>;
|
|
36
|
+
/**
|
|
37
|
+
* The verification value of the matching domain (pending, verified or
|
|
38
|
+
* failed: a failed domain can be verified again), as text/plain with no
|
|
39
|
+
* trailing newline. This is the body Relyon's file check accepts
|
|
40
|
+
* (`relyon-domain-verification=<token>`). The contract itself still defines
|
|
41
|
+
* no file format. `hostname` is always one of the store's own hostnames.
|
|
42
|
+
*/
|
|
43
|
+
verification(hostname: string): Promise<Response>;
|
|
44
|
+
}
|
|
45
|
+
export interface StoreInfo {
|
|
46
|
+
/** The store's name, as agents should show it. */
|
|
47
|
+
name: string;
|
|
48
|
+
/** One or two sentences about the store. */
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Minor units → a decimal string, e.g. 2400 USD → "24.00", 2400 JPY → "2400". */
|
|
52
|
+
export declare function decimalAmount(amount: number, currency: string): string;
|
|
53
|
+
/** What a feed URL is, as llms.txt and the homepage head name it. */
|
|
54
|
+
export declare function feedLabel(url: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Where agents learn about the store, on its public address. `rebase` moves
|
|
57
|
+
* catalog links on the store's own hostnames (and dev addresses) onto
|
|
58
|
+
* `origin`; `acp` is the ACP checkout prefix to advertise; `agentCard`
|
|
59
|
+
* lists `/.well-known/agent-card.json`.
|
|
60
|
+
*/
|
|
61
|
+
export interface LlmsTxtExtras {
|
|
62
|
+
rebase?: {
|
|
63
|
+
hostnames: readonly string[];
|
|
64
|
+
};
|
|
65
|
+
acp?: string;
|
|
66
|
+
agentCard?: boolean;
|
|
67
|
+
/** The kit waits for a sandbox key: say so instead of promising checkout. */
|
|
68
|
+
waitingForSandboxKey?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export declare function llmsTxt(store: StoreInfo, origin: string, catalog: CatalogHolder, paths: {
|
|
71
|
+
mcp: string;
|
|
72
|
+
sitemap: string;
|
|
73
|
+
}, feedUrls?: readonly string[], policies?: StorePolicyOptions, extras?: LlmsTxtExtras): string;
|
|
74
|
+
/**
|
|
75
|
+
* The store's root sitemap index (`/sitemap.xml`): it lists the kit's product
|
|
76
|
+
* sitemap, so a crawler that only knows `/sitemap.xml` finds the products.
|
|
77
|
+
*/
|
|
78
|
+
export declare function sitemapIndex(origin: string, sitemapPaths: readonly string[]): string;
|
|
79
|
+
/** Policy page links on the store's own hostnames, moved onto `origin`. */
|
|
80
|
+
export declare function policiesOnOrigin(policies: StorePolicyOptions | undefined, origin: string, hostnames: readonly string[]): StorePolicyOptions | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The product pages as a sitemap `urlset`. With `rebase`, links on the
|
|
83
|
+
* store's own hostnames (and dev addresses) are moved onto `rebase.origin`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function productSitemap(catalog: CatalogHolder, rebase?: {
|
|
86
|
+
origin: string;
|
|
87
|
+
hostnames: readonly string[];
|
|
88
|
+
}): string;
|
|
89
|
+
/**
|
|
90
|
+
* The schema.org `Product` data productJsonLd returns. Typed, so a page can
|
|
91
|
+
* read `image?.[0]` or `offers?.price` and still pass a TypeScript build
|
|
92
|
+
* (such as `next build`).
|
|
93
|
+
*/
|
|
94
|
+
export type ProductJsonLd = {
|
|
95
|
+
"@context": "https://schema.org";
|
|
96
|
+
"@type": "Product";
|
|
97
|
+
name: string;
|
|
98
|
+
sku: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
image?: string[];
|
|
101
|
+
url?: string;
|
|
102
|
+
brand?: {
|
|
103
|
+
"@type": "Brand";
|
|
104
|
+
name: string;
|
|
105
|
+
};
|
|
106
|
+
gtin?: string;
|
|
107
|
+
mpn?: string;
|
|
108
|
+
category?: string;
|
|
109
|
+
inProductGroupWithID?: string;
|
|
110
|
+
offers?: {
|
|
111
|
+
"@type": "Offer";
|
|
112
|
+
price: string;
|
|
113
|
+
priceCurrency: string;
|
|
114
|
+
availability?: string;
|
|
115
|
+
url?: string;
|
|
116
|
+
hasMerchantReturnPolicy?: Record<string, unknown>;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* schema.org `Product` JSON-LD for a product page. Prices are display only
|
|
121
|
+
* ("from"). `gtin` and `mpn` appear only when the product has them. With
|
|
122
|
+
* `rebase`, page and image links on the store's own hostnames are moved onto
|
|
123
|
+
* `rebase.origin` (the store's public address).
|
|
124
|
+
*/
|
|
125
|
+
export declare function productJsonLd(product: StoreProduct, policies?: StorePolicyOptions, rebase?: {
|
|
126
|
+
origin: string;
|
|
127
|
+
hostnames: readonly string[];
|
|
128
|
+
}): ProductJsonLd;
|
|
129
|
+
/** A JSON value as a `<script type="application/ld+json">` tag, safe to place in HTML. */
|
|
130
|
+
export declare function jsonLdScript(value: unknown): string;
|
|
131
|
+
/** The JSON-LD as a `<script type="application/ld+json">` tag, safe to place in HTML. */
|
|
132
|
+
export declare function renderProductJsonLd(product: StoreProduct, policies?: StorePolicyOptions, rebase?: {
|
|
133
|
+
origin: string;
|
|
134
|
+
hostnames: readonly string[];
|
|
135
|
+
}): string;
|
|
136
|
+
/**
|
|
137
|
+
* schema.org `ItemList` JSON-LD for a page that lists products (the
|
|
138
|
+
* homepage): each entry is the product's full `Product` data, with name,
|
|
139
|
+
* price, currency, availability, brand and `sku` (and `gtin` / `mpn` only
|
|
140
|
+
* when supplied). At most 100 products.
|
|
141
|
+
*/
|
|
142
|
+
export declare function productListJsonLd(products: readonly StoreProduct[], policies?: StorePolicyOptions, rebase?: {
|
|
143
|
+
origin: string;
|
|
144
|
+
hostnames: readonly string[];
|
|
145
|
+
}): Record<string, unknown>;
|
|
146
|
+
/** The homepage product list as a `<script type="application/ld+json">` tag. */
|
|
147
|
+
export declare function renderProductListJsonLd(products: readonly StoreProduct[], policies?: StorePolicyOptions, rebase?: {
|
|
148
|
+
origin: string;
|
|
149
|
+
hostnames: readonly string[];
|
|
150
|
+
}): string;
|
|
151
|
+
export { escapeHtml };
|