@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,257 @@
|
|
|
1
|
+
import { formatStoreDoctor, redactSecrets, runStoreDoctor, terminalSafe } from "./doctor.js";
|
|
2
|
+
import { CHECKLIST_MANIFEST_VERSION, checkIdForItem } from "./checklist-manifest.js";
|
|
3
|
+
import { OFFICIAL_RELYON_ORIGIN, PROGRESS_ITEM, progressItem, progressUrl, readSandboxProgress } from "./progress.js";
|
|
4
|
+
import { KIT_VERSION } from "./version.js";
|
|
5
|
+
import { KEY_LOADING } from "./waiting.js";
|
|
6
|
+
import { TEST_CHECKOUT_COMMAND } from "./test-checkout.js";
|
|
7
|
+
import { FINAL_MESSAGE_TODOS } from "./doctor-merchant.js";
|
|
8
|
+
import { legacyNewerKitVersion, unknownKitVersion } from "./kit-version.js";
|
|
9
|
+
import { relevantKitReleases } from "./kit-updates.js";
|
|
10
|
+
import { KIT_RELEASE_NOTES } from "./release-notes.js";
|
|
11
|
+
import { forKitPackage, kitIdentity } from "./identity.js";
|
|
12
|
+
// The doctor's overall verdict for a coding agent: DONE only when a usable Test
|
|
13
|
+
// key is present, nothing FAILs, the store's checkout page and sampled product
|
|
14
|
+
// pages answer 200 on its origin, Relyon confirmed one completed Test checkout and
|
|
15
|
+
// the selected feeds are live. Anything else is NOT DONE, with an ordered list of
|
|
16
|
+
// imperative next steps built from the items' own fix text.
|
|
17
|
+
export const DOCTOR_COMMAND = "npx @relyon/store-kit doctor";
|
|
18
|
+
export const DONE_LINE = "DONE: Test integration verified by Relyon.";
|
|
19
|
+
/** Live runs have no Test checkout confirmation; DONE there means every Live check passed. */
|
|
20
|
+
export const LIVE_DONE_LINE = "DONE: Live checks passed.";
|
|
21
|
+
export const THEN_RUN = `Then run: ${DOCTOR_COMMAND}`;
|
|
22
|
+
/** The builder-facing hint the kit adds to waiting and setup errors (defined with the waiting body). */
|
|
23
|
+
export { DEVELOPER_HINT } from "./waiting.js";
|
|
24
|
+
/** Where the Test purchase is documented, as init copies it for every agent. */
|
|
25
|
+
export const CHECKOUT_SKILL_FILE = ".agents/skills/relyon-checkout/SKILL.md";
|
|
26
|
+
export const GET_KEY_URL = "https://core.getrelyon.com/get-sandbox-key";
|
|
27
|
+
/** Advisory only: a local key file is not the deployment's environment settings. */
|
|
28
|
+
export const HOST_ENVIRONMENT_ITEM = "Host environment key";
|
|
29
|
+
export const HOST_ENVIRONMENT_DETAIL = `Before publishing, add RELYON_API_KEY in the host's environment settings. This run uses a key saved only in a local file; that does not configure the published server. Get your Test key from the Relyon dashboard (${GET_KEY_URL}); never paste keys in chat.`;
|
|
30
|
+
const isFeed = (item) => item.name.startsWith("feed ");
|
|
31
|
+
/** Doctor's item when no feed is selected or advertised (an empty feed selection is not "live"). */
|
|
32
|
+
const NO_FEEDS_ITEM = "product feeds";
|
|
33
|
+
/** How doctor's "Relyon key" item starts when a saved Test key was withheld from a non-official Relyon base URL (L1). */
|
|
34
|
+
export const SAVED_KEY_WITHHELD_PREFIX = "The saved Test key was not sent";
|
|
35
|
+
export const SAVED_KEY_ALTERNATIVE = "Otherwise put the store's Test key in RELYON_API_KEY, or unset RELYON_BASE_URL (and --base-url) to use Relyon's own API.";
|
|
36
|
+
const KEY_ITEMS = new Set(["Relyon key", "Relyon doctor"]);
|
|
37
|
+
const COMMAND = /npx @relyon\/store-kit(?: [a-z][a-z-]*)(?: --[a-z][a-z-]*)*/;
|
|
38
|
+
/** Groups items that share the same detail: "name, name: detail". */
|
|
39
|
+
function grouped(items) {
|
|
40
|
+
const byDetail = new Map();
|
|
41
|
+
for (const item of items)
|
|
42
|
+
byDetail.set(item.detail, [...(byDetail.get(item.detail) ?? []), item.name]);
|
|
43
|
+
return [...byDetail].map(([detail, names]) => `${names.join(", ")}: ${detail}`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The overall verdict. `progress` is what Relyon's progress record said; when
|
|
47
|
+
* absent, the PROGRESS_ITEM in `result` decides (PASS means confirmed).
|
|
48
|
+
*/
|
|
49
|
+
export function doctorVerdict(result, context = {}) {
|
|
50
|
+
const live = context.live ?? result.items.some((item) => item.name === "store URL" && item.detail.endsWith("(Live mode)"));
|
|
51
|
+
const items = result.items;
|
|
52
|
+
const keyItem = items.find((item) => item.name === "Relyon key");
|
|
53
|
+
const testKey = keyItem?.status === "PASS";
|
|
54
|
+
const progress = items.find((item) => item.name === PROGRESS_ITEM);
|
|
55
|
+
const checkoutConfirmed = live || progress?.status === "PASS";
|
|
56
|
+
// Complete emission lists unselected feed formats as N/A; only selected
|
|
57
|
+
// feeds decide "feeds live" (an unselected format is not "not live").
|
|
58
|
+
const feeds = items.filter((item) => isFeed(item) && item.status !== "N/A");
|
|
59
|
+
// At least one selected feed, and every one PASS: none selected is not "live".
|
|
60
|
+
const feedsLive = feeds.length > 0 && feeds.every((item) => item.status === "PASS");
|
|
61
|
+
// UNVERIFIED anywhere except the feeds and the confirmation itself means doctor couldn't check everything.
|
|
62
|
+
// A NOT DONE store page (the checkout page or sampled product pages) also keeps doctor from passing.
|
|
63
|
+
const doctorPasses = !items.some((item) => item.status === "FAIL")
|
|
64
|
+
&& !items.some((item) => item.status === "UNVERIFIED" && !isFeed(item) && item.name !== PROGRESS_ITEM)
|
|
65
|
+
&& !items.some((item) => (item.checkId === "domain-verification" || item.name === "relyon-verification") && item.status === "PENDING")
|
|
66
|
+
&& !items.some((item) => item.status === "NOT DONE" && item.name !== PROGRESS_ITEM);
|
|
67
|
+
const conditions = { testKey, doctorPasses, checkoutConfirmed, feedsLive };
|
|
68
|
+
const required = live ? 3 : 4;
|
|
69
|
+
const remaining = [testKey, doctorPasses, feedsLive, ...(live ? [] : [checkoutConfirmed])].filter((met) => !met).length;
|
|
70
|
+
const read = context.progress?.kind === "read" ? context.progress.progress : undefined;
|
|
71
|
+
const confirmed = {
|
|
72
|
+
test_key_used: read?.test_key_used ?? false,
|
|
73
|
+
test_checkout_completed: read ? read.test_checkout_completed : !live && progress?.status === "PASS",
|
|
74
|
+
};
|
|
75
|
+
const status = remaining === 0 ? "done" : "not_done";
|
|
76
|
+
// Domain verification the agent runs itself is the only blocker: the
|
|
77
|
+
// verdict line says so instead of a generic NOT DONE count.
|
|
78
|
+
const blockers = items.filter((item) => item.status === "FAIL"
|
|
79
|
+
|| (item.status === "UNVERIFIED" && !isFeed(item) && item.name !== PROGRESS_ITEM)
|
|
80
|
+
|| ((item.checkId === "domain-verification" || item.name === "relyon-verification") && item.status === "PENDING")
|
|
81
|
+
|| (item.status === "NOT DONE" && item.name !== PROGRESS_ITEM));
|
|
82
|
+
const onlyDomainStep = status === "not_done" && remaining === 1 && !doctorPasses
|
|
83
|
+
&& blockers.length === 1 && blockers[0].status === "PENDING"
|
|
84
|
+
&& (blockers[0].checkId === "domain-verification" || blockers[0].name === "relyon-verification");
|
|
85
|
+
const actions = [];
|
|
86
|
+
if (status === "not_done") {
|
|
87
|
+
const withheld = keyItem?.status === "UNVERIFIED" && keyItem.detail.startsWith(SAVED_KEY_WITHHELD_PREFIX) ? keyItem : undefined;
|
|
88
|
+
if (!testKey && withheld) {
|
|
89
|
+
actions.push({ action: `${withheld.detail} ${SAVED_KEY_ALTERNATIVE}` });
|
|
90
|
+
}
|
|
91
|
+
else if (!testKey) {
|
|
92
|
+
actions.push(live
|
|
93
|
+
? { action: "Set RELYON_API_KEY in the server environment to the store's Live secret key (Relyon staff approve Live; agents never enable it)." }
|
|
94
|
+
: { action: `Get a Test key: run \`npx @relyon/store-kit init\` (it saves the key privately; never print it). If automatic setup is blocked, open ${GET_KEY_URL}, then run \`npx @relyon/store-kit init --key-from-stdin\`. ${KEY_LOADING}`,
|
|
95
|
+
command: "npx @relyon/store-kit init" });
|
|
96
|
+
}
|
|
97
|
+
// The aggregate "product feeds" verdict mirrors the per-feed rows; the
|
|
98
|
+
// per-feed rows already carry the fix actions, so the aggregate adds none.
|
|
99
|
+
const failing = items.filter((item) => item.status === "FAIL" && !isFeed(item) && item.name !== NO_FEEDS_ITEM);
|
|
100
|
+
for (const line of grouped(failing))
|
|
101
|
+
actions.push({ action: `Fix ${line}` });
|
|
102
|
+
for (const line of grouped(items.filter((item) => item.status === "NOT DONE" && item.name !== PROGRESS_ITEM)))
|
|
103
|
+
actions.push({ action: `Fix ${line}` });
|
|
104
|
+
for (const line of grouped(items.filter((item) => item.status === "WARN")))
|
|
105
|
+
actions.push({ action: `Fix ${line}` });
|
|
106
|
+
// Without a key, the key step resolves every "skipped" or "waiting" check: don't repeat them.
|
|
107
|
+
// The per-check "Relyon doctor: …" rows never add their own action either — the overall
|
|
108
|
+
// "Relyon doctor" row already carries it (one action, not six).
|
|
109
|
+
const unverified = items.filter((item) => item.status === "UNVERIFIED" && !isFeed(item) && item.name !== PROGRESS_ITEM && item.name !== NO_FEEDS_ITEM
|
|
110
|
+
&& !item.name.startsWith("Relyon doctor: ")
|
|
111
|
+
&& (testKey || (!KEY_ITEMS.has(item.name) && !/sandbox key|RELYON_API_KEY/.test(item.detail))));
|
|
112
|
+
for (const line of grouped(unverified))
|
|
113
|
+
actions.push({ action: `Make this check verifiable: ${line}` });
|
|
114
|
+
if (!live && !checkoutConfirmed) {
|
|
115
|
+
if (progress && progress.status === "UNVERIFIED" && testKey) {
|
|
116
|
+
actions.push({ action: `Get Relyon's confirmation: ${progress.detail}` });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const command = testCheckoutCommand(items);
|
|
120
|
+
actions.push({
|
|
121
|
+
action: `Complete one Test checkout yourself, now: run \`${command}\` (one Test purchase through the store kit with Relyon's Test mock processor; no card data, never pays twice), so Relyon confirms it. This is not a step for a person. If it says the sandbox uses hosted card fields, follow "Test purchases, end to end" in ${CHECKOUT_SKILL_FILE} instead.`,
|
|
122
|
+
command, file: CHECKOUT_SKILL_FILE,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// A public Test address with no Relyon domain yet is the agent's own step,
|
|
127
|
+
// never an owner to-do: add and verify the domain with the kit.
|
|
128
|
+
const domainPending = items.find((item) => item.name === "relyon-verification" && item.status === "PENDING" && !item.merchantTodo?.length);
|
|
129
|
+
if (domainPending) {
|
|
130
|
+
actions.push({
|
|
131
|
+
action: domainPending.detail,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// An agent-actionable pending webhook (a preview or loopback URL) is the agent's own step,
|
|
135
|
+
// never a merchant to-do: register the endpoint after publish.
|
|
136
|
+
const webhookPending = items.some((item) => item.name === "Relyon doctor: webhook" && item.status === "PENDING" && !item.merchantTodo?.length);
|
|
137
|
+
if (webhookPending) {
|
|
138
|
+
actions.push({
|
|
139
|
+
action: `Register the store's webhook endpoint yourself: publish the store as a separate detached background process (not inside your own session, which ends), then run \`npx @relyon/store-kit webhook\` (with an environment API key the signing secret is resolved at runtime and no file is written; only a local file key saves RELYON_WEBHOOK_SECRET to gitignored .env, 0600, never printed). Re-run it if the store's URL changes. This is not a step for a person.`,
|
|
140
|
+
command: "npx @relyon/store-kit webhook",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const notLive = feeds.filter((item) => item.status !== "PASS");
|
|
144
|
+
if (notLive.length)
|
|
145
|
+
actions.push({ action: `Make the feeds live (each selected feed must list the store's products): ${grouped(notLive).join(" ")}` });
|
|
146
|
+
else if (!feeds.length) {
|
|
147
|
+
const none = items.find((item) => item.name === NO_FEEDS_ITEM);
|
|
148
|
+
actions.push({ action: `Make the feeds live: add feeds: { formats: ["openai", "google"] } to createStoreKit so llms.txt advertises them, and make sure each lists the store's products${none ? ` (${NO_FEEDS_ITEM}: ${none.detail})` : ""}.` });
|
|
149
|
+
}
|
|
150
|
+
actions.push({ action: THEN_RUN, command: DOCTOR_COMMAND });
|
|
151
|
+
}
|
|
152
|
+
const nextSteps = actions.map((step, index) => {
|
|
153
|
+
const command = step.command ?? COMMAND.exec(step.action)?.[0];
|
|
154
|
+
return { order: index + 1, action: step.action, ...(command ? { command } : {}), ...(step.file ? { file: step.file } : {}) };
|
|
155
|
+
});
|
|
156
|
+
return { status, live, required, remaining, conditions, confirmed, nextSteps, ...(onlyDomainStep ? { onlyDomainStep } : {}) };
|
|
157
|
+
}
|
|
158
|
+
/** The test-checkout command for this run's store URL (from the "store URL" item). */
|
|
159
|
+
function testCheckoutCommand(items) {
|
|
160
|
+
const detail = items.find((item) => item.name === "store URL")?.detail ?? "";
|
|
161
|
+
const url = /^https?:\/\/[^\s]+/.exec(detail)?.[0];
|
|
162
|
+
return `${TEST_CHECKOUT_COMMAND} --url ${url ?? "<store URL>"}`;
|
|
163
|
+
}
|
|
164
|
+
/** The verdict line: "NOT DONE: n of m required steps remain.", the single-agent-step line, or the DONE line. */
|
|
165
|
+
export function verdictLine(verdict) {
|
|
166
|
+
if (verdict.status === "done")
|
|
167
|
+
return verdict.live ? LIVE_DONE_LINE : DONE_LINE;
|
|
168
|
+
if (verdict.onlyDomainStep)
|
|
169
|
+
return "1 agent step left: verify the domain";
|
|
170
|
+
return `NOT DONE: ${verdict.remaining} of ${verdict.required} required step${verdict.required === 1 ? "" : "s"} remain.`;
|
|
171
|
+
}
|
|
172
|
+
/** The verdict line and the numbered "Do this next" list, without the item table. */
|
|
173
|
+
export function formatNextSteps(verdict, secrets = []) {
|
|
174
|
+
const lines = [verdictLine(verdict)];
|
|
175
|
+
if (verdict.nextSteps.length) {
|
|
176
|
+
lines.push("", "Do this next:", ...verdict.nextSteps.map((step) => ` ${step.order}) ${terminalSafe(step.action)}`));
|
|
177
|
+
}
|
|
178
|
+
return redactSecrets(lines.join("\n"), secrets) + "\n";
|
|
179
|
+
}
|
|
180
|
+
/** The human doctor output: the verdict and the steps first, then every item. */
|
|
181
|
+
export function formatDoctorReport(report, secrets = []) {
|
|
182
|
+
const body = formatStoreDoctor(report, secrets, { nextSteps: false, verdict: report.verdict.status });
|
|
183
|
+
// The closing line for coding agents, once (the merchant to-do block already ends with it).
|
|
184
|
+
const closing = body.includes(FINAL_MESSAGE_TODOS) || (report.verdict.live && report.verdict.status === "done") ? "" : `\n${FINAL_MESSAGE_TODOS}\n`;
|
|
185
|
+
// All advisory version states use the same diagnostic, outside checklist items.
|
|
186
|
+
const notice = (report.kitVersion?.messages ?? []).map(text => redactSecrets(terminalSafe(text), secrets)).join("\n");
|
|
187
|
+
const delivery = report.kitVersionDelivery === "accepted"
|
|
188
|
+
? "Relyon accepted the kit-version snapshot for background recording; this does not confirm it was saved."
|
|
189
|
+
: report.kitVersionDelivery === "rejected" ? "Kit-version evidence was rejected by Relyon; it is unavailable in Core. The local diagnostic above is unchanged."
|
|
190
|
+
: "Kit-version evidence delivery to Core is unavailable; the last stored observation may be older. The local diagnostic above is unchanged.";
|
|
191
|
+
const releases = relevantKitReleases(kitIdentity().releaseNotes ?? KIT_RELEASE_NOTES, report.kitVersion ?? null);
|
|
192
|
+
const releaseText = releases.length ? `\nRelease notes:\n${releases.map(n => `${n.version}: ${n.summary}`).join("\n")}\n` : "";
|
|
193
|
+
// Library callers see the commands of the package running the kit, as the CLI prints them.
|
|
194
|
+
return forKitPackage(`${formatNextSteps(report.verdict, secrets)}${notice}\n${delivery}\n${releaseText}${body}${closing}`);
|
|
195
|
+
}
|
|
196
|
+
/** `doctor --json`: one object, every string redacted. */
|
|
197
|
+
export function doctorJson(report, secrets = []) {
|
|
198
|
+
const clean = (text) => redactSecrets(terminalSafe(text), secrets);
|
|
199
|
+
const kit = report.kitVersion ?? unknownKitVersion();
|
|
200
|
+
const newer = legacyNewerKitVersion(kit);
|
|
201
|
+
return {
|
|
202
|
+
status: report.verdict.status,
|
|
203
|
+
version: KIT_VERSION,
|
|
204
|
+
manifest_version: CHECKLIST_MANIFEST_VERSION,
|
|
205
|
+
kit_version: JSON.parse(JSON.stringify(kit, (_, value) => typeof value === "string" ? clean(value) : value)),
|
|
206
|
+
...(newer ? { newer_kit_version: newer } : {}),
|
|
207
|
+
checks: report.items.map((item) => ({
|
|
208
|
+
name: clean(item.name),
|
|
209
|
+
// Every known check carries its stable manifest id — even an item built
|
|
210
|
+
// without the add() stamping path falls back to the name mapping.
|
|
211
|
+
...(item.checkId ?? checkIdForItem(item.name) ? { id: item.checkId ?? checkIdForItem(item.name) } : {}),
|
|
212
|
+
status: item.status, detail: clean(item.detail),
|
|
213
|
+
})),
|
|
214
|
+
next_steps: report.verdict.nextSteps.map((step) => ({
|
|
215
|
+
order: step.order, action: clean(step.action),
|
|
216
|
+
...(step.command ? { command: clean(step.command) } : {}), ...(step.file ? { file: clean(step.file) } : {}),
|
|
217
|
+
})),
|
|
218
|
+
confirmed: { ...report.verdict.confirmed },
|
|
219
|
+
// Additive (kit 0.1.11): the owner's to-dos, for the agent's final chat message.
|
|
220
|
+
owner_todos: [...new Set(report.items.flatMap((item) => item.merchantTodo ?? []))].map(clean),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** 0 only when DONE, 1 on any FAIL, 2 when NOT DONE without a FAIL. */
|
|
224
|
+
export function doctorExitCode(report) {
|
|
225
|
+
if (report.items.some((item) => item.status === "FAIL"))
|
|
226
|
+
return 1;
|
|
227
|
+
return report.verdict.status === "done" ? 0 : 2;
|
|
228
|
+
}
|
|
229
|
+
/** Runs the doctor, adds Relyon's Test checkout confirmation, and computes the verdict. */
|
|
230
|
+
export async function runDoctorReport(options) {
|
|
231
|
+
const { keySource, readProgress, allowSavedKeyToBaseUrl, ...doctorOptions } = options;
|
|
232
|
+
// L1: a saved Test key goes only to Relyon's official https origin, for every request doctor
|
|
233
|
+
// makes, unless the merchant passed --allow-saved-key-to-base-url.
|
|
234
|
+
const withhold = keySource === "saved" && !!doctorOptions.apiKey && !allowSavedKeyToBaseUrl
|
|
235
|
+
&& progressUrl(doctorOptions.baseUrl ?? `${OFFICIAL_RELYON_ORIGIN}/api`, "saved") === null;
|
|
236
|
+
let progress;
|
|
237
|
+
const beforeRelyonDoctor = async (live) => {
|
|
238
|
+
// The same key the doctor used, only when it is a usable Test key and not in Live.
|
|
239
|
+
progress = await (readProgress ?? readSandboxProgress)({
|
|
240
|
+
apiKey: withhold ? undefined : options.apiKey,
|
|
241
|
+
// An explicit --allow-saved-key-to-base-url lets the saved key follow the chosen base URL, like RELYON_API_KEY.
|
|
242
|
+
keySource: keySource === "saved" && allowSavedKeyToBaseUrl ? "env" : keySource, baseUrl: options.baseUrl, live,
|
|
243
|
+
fetch: options.fetch, timeoutMs: options.timeoutMs,
|
|
244
|
+
});
|
|
245
|
+
return progressItem(progress);
|
|
246
|
+
};
|
|
247
|
+
const result = await runStoreDoctor({
|
|
248
|
+
...(withhold ? { ...doctorOptions, apiKey: undefined, savedKeyWithheld: true } : doctorOptions),
|
|
249
|
+
beforeRelyonDoctor,
|
|
250
|
+
});
|
|
251
|
+
const live = result.items.some((item) => item.name === "store URL" && item.detail.endsWith("(Live mode)"));
|
|
252
|
+
if (!live && !doctorOptions.live && keySource === "saved" && doctorOptions.apiKey) {
|
|
253
|
+
result.items.push({ name: HOST_ENVIRONMENT_ITEM, status: "WARN", detail: HOST_ENVIRONMENT_DETAIL });
|
|
254
|
+
}
|
|
255
|
+
const verdict = doctorVerdict(result, { live, ...(progress ? { progress } : {}) });
|
|
256
|
+
return { ...result, verdict };
|
|
257
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order-pending state: the payment succeeded, and the store's order isn't
|
|
3
|
+
* created yet (`createOrder` threw, or another request is still creating it).
|
|
4
|
+
* Every answer in this state says the payment went through and the order is
|
|
5
|
+
* being placed. None says `completed`, carries an order or says nothing was
|
|
6
|
+
* charged. A resent complete finishes the order without charging again.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ORDER_PENDING = "order_pending";
|
|
9
|
+
/** Retry-After (seconds) on order-pending answers; MCP carries it as `data.retry_after`. */
|
|
10
|
+
export declare const ORDER_PENDING_RETRY_AFTER = 5;
|
|
11
|
+
/** Response header carrying `pending` on the UCP and ACP order-pending answers (with `Payment-Status: succeeded`). */
|
|
12
|
+
export declare const ORDER_STATUS_HEADER = "order-status";
|
|
13
|
+
/** The store's own pay endpoint (`payAndConfirm`) answer's message. */
|
|
14
|
+
export declare const PAY_ORDER_PENDING_MESSAGE: string;
|
|
15
|
+
/**
|
|
16
|
+
* `payAndConfirm`'s message when the pending payment belongs to an earlier
|
|
17
|
+
* attempt of the order reference, or to another order reference for the same
|
|
18
|
+
* agent checkout (named by `paid_order_reference`/`paid_attempt`).
|
|
19
|
+
*/
|
|
20
|
+
export declare const PAY_ORDER_PENDING_EARLIER_MESSAGE: string;
|
|
21
|
+
/**
|
|
22
|
+
* The UCP or ACP checkout answer for an order-pending checkout, built from
|
|
23
|
+
* Relyon's answer for it (`body`, `headers`): `status` becomes
|
|
24
|
+
* `complete_in_progress`, `order` is removed, and an info message says the
|
|
25
|
+
* order is being placed (UCP: `code: "order_pending"`; ACP's MessageInfo has
|
|
26
|
+
* no code, so `Order-Status: pending` carries it). HTTP 200 with Retry-After.
|
|
27
|
+
* UCP's `ap2.merchant_authorization` signed Relyon's body, so it is removed.
|
|
28
|
+
* Headers tied to Relyon's body bytes (length, digests, etag, and a signature
|
|
29
|
+
* covering a digest) are dropped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function orderPendingCheckout(protocol: "ucp" | "acp", relayed: {
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
body: string;
|
|
34
|
+
}, sessionId: string | null): Response;
|
|
35
|
+
/** HTTP status of the order-pending error answer on UCP and ACP (MCP answers in-band with HTTP 200). */
|
|
36
|
+
export declare const ORDER_PENDING_ERROR_STATUS = 503;
|
|
37
|
+
/**
|
|
38
|
+
* The UCP or ACP order-pending answer when the kit has no checkout body to
|
|
39
|
+
* rewrite: it refused the step itself (agent checkout paused, the agent
|
|
40
|
+
* refused at the edge, Relyon unreachable or refusing, `priceCart` failing,
|
|
41
|
+
* the cart changed on a resend, or an unexpected error) on a checkout whose
|
|
42
|
+
* payment succeeded and whose order isn't created yet. Built like
|
|
43
|
+
* `paymentOutcomeUnknown`: UCP `{code, content}` plus `payment_status` and
|
|
44
|
+
* `status_url`; ACP's schema-exact Error `{type, code, message}`; both HTTP
|
|
45
|
+
* 503 with Retry-After, `Payment-Status: succeeded`, `Order-Status: pending`
|
|
46
|
+
* and a `Link: <url>; rel="status"` to the store's own checkout read. The
|
|
47
|
+
* code is `order_pending` (UCP's error_code and ACP's Error code are free
|
|
48
|
+
* strings). Never says nothing was charged, never shows an order.
|
|
49
|
+
*/
|
|
50
|
+
export declare function orderPendingError(protocol: "ucp" | "acp", options: {
|
|
51
|
+
statusUrl: string;
|
|
52
|
+
}): Response;
|
|
53
|
+
/**
|
|
54
|
+
* MCP's order-pending answer: an in-band JSON-RPC error (HTTP 200) with the
|
|
55
|
+
* stable code `order_pending`, naming the checkout and the tools to call.
|
|
56
|
+
*/
|
|
57
|
+
export declare function orderPendingMcp(id: unknown, checkoutId: string): Response;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { mcpErrorBody, PAYMENT_STATUS_HEADER } from "./refusals.js";
|
|
2
|
+
import { isRecord, jsonResponse, tryParseJson } from "./util.js";
|
|
3
|
+
/**
|
|
4
|
+
* The order-pending state: the payment succeeded, and the store's order isn't
|
|
5
|
+
* created yet (`createOrder` threw, or another request is still creating it).
|
|
6
|
+
* Every answer in this state says the payment went through and the order is
|
|
7
|
+
* being placed. None says `completed`, carries an order or says nothing was
|
|
8
|
+
* charged. A resent complete finishes the order without charging again.
|
|
9
|
+
*/
|
|
10
|
+
export const ORDER_PENDING = "order_pending";
|
|
11
|
+
/** Retry-After (seconds) on order-pending answers; MCP carries it as `data.retry_after`. */
|
|
12
|
+
export const ORDER_PENDING_RETRY_AFTER = 5;
|
|
13
|
+
/** Response header carrying `pending` on the UCP and ACP order-pending answers (with `Payment-Status: succeeded`). */
|
|
14
|
+
export const ORDER_STATUS_HEADER = "order-status";
|
|
15
|
+
const AGENT_MESSAGE = "The payment went through, and the store is placing the order. Resend this complete request (it doesn't charge again)"
|
|
16
|
+
+ " or read the checkout to see when the order is placed. Don't start a new checkout or re-enter payment.";
|
|
17
|
+
const MCP_MESSAGE = "The payment went through, and the store is placing the order. Call complete_checkout again with the same checkout_id"
|
|
18
|
+
+ " (it doesn't charge again) or read it with get_checkout. Don't start a new checkout or re-enter payment.";
|
|
19
|
+
/** The store's own pay endpoint (`payAndConfirm`) answer's message. */
|
|
20
|
+
export const PAY_ORDER_PENDING_MESSAGE = "The payment went through, and the store is placing the order. Don't pay again or re-enter the card:"
|
|
21
|
+
+ " send the same payment request again (same order reference and card payload) to finish the order without charging again,"
|
|
22
|
+
+ " or check the order status.";
|
|
23
|
+
/**
|
|
24
|
+
* `payAndConfirm`'s message when the pending payment belongs to an earlier
|
|
25
|
+
* attempt of the order reference, or to another order reference for the same
|
|
26
|
+
* agent checkout (named by `paid_order_reference`/`paid_attempt`).
|
|
27
|
+
*/
|
|
28
|
+
export const PAY_ORDER_PENDING_EARLIER_MESSAGE = "A payment for this order already went through, and the store is placing the order. Don't pay again or re-enter the card:"
|
|
29
|
+
+ " resend the payment request that paid (the order reference and attempt this answer names, with its original card payload) to finish the order"
|
|
30
|
+
+ " without charging again, or check the order status.";
|
|
31
|
+
/** Headers that describe the store's own connection; never copied onto the agent's response. */
|
|
32
|
+
const HOP_BY_HOP = new Set(["connection", "keep-alive", "transfer-encoding", "upgrade", "proxy-connection", "te", "trailer"]);
|
|
33
|
+
/** Headers that describe Relyon's body bytes, which the order-pending answer replaces. */
|
|
34
|
+
const BODY_BOUND = new Set(["content-length", "content-digest", "repr-digest", "digest", "content-md5", "etag"]);
|
|
35
|
+
/**
|
|
36
|
+
* The UCP or ACP checkout answer for an order-pending checkout, built from
|
|
37
|
+
* Relyon's answer for it (`body`, `headers`): `status` becomes
|
|
38
|
+
* `complete_in_progress`, `order` is removed, and an info message says the
|
|
39
|
+
* order is being placed (UCP: `code: "order_pending"`; ACP's MessageInfo has
|
|
40
|
+
* no code, so `Order-Status: pending` carries it). HTTP 200 with Retry-After.
|
|
41
|
+
* UCP's `ap2.merchant_authorization` signed Relyon's body, so it is removed.
|
|
42
|
+
* Headers tied to Relyon's body bytes (length, digests, etag, and a signature
|
|
43
|
+
* covering a digest) are dropped.
|
|
44
|
+
*/
|
|
45
|
+
export function orderPendingCheckout(protocol, relayed, sessionId) {
|
|
46
|
+
const parsed = tryParseJson(relayed.body);
|
|
47
|
+
const body = isRecord(parsed) ? { ...parsed } : { ...(sessionId ? { id: sessionId } : {}) };
|
|
48
|
+
delete body.order;
|
|
49
|
+
body.status = "complete_in_progress";
|
|
50
|
+
// UCP's AP2 merchant authorization is a detached signature over the
|
|
51
|
+
// checkout Relyon answered; it can't cover this changed body, and the
|
|
52
|
+
// kit can't sign, so it's removed rather than relayed stale.
|
|
53
|
+
if (protocol === "ucp" && isRecord(body.ap2) && "merchant_authorization" in body.ap2) {
|
|
54
|
+
const { merchant_authorization: _stale, ...ap2 } = body.ap2;
|
|
55
|
+
if (Object.keys(ap2).length > 0)
|
|
56
|
+
body.ap2 = ap2;
|
|
57
|
+
else
|
|
58
|
+
delete body.ap2;
|
|
59
|
+
}
|
|
60
|
+
const message = protocol === "ucp"
|
|
61
|
+
? { type: "info", code: ORDER_PENDING, content_type: "plain", content: AGENT_MESSAGE }
|
|
62
|
+
: { type: "info", severity: "info", resolution: "recoverable", content_type: "plain", content: AGENT_MESSAGE };
|
|
63
|
+
const existing = Array.isArray(body.messages) ? body.messages : [];
|
|
64
|
+
body.messages = [...existing.filter((item) => !(isRecord(item) && (item.code === ORDER_PENDING || item.content === AGENT_MESSAGE))), message];
|
|
65
|
+
const headers = {};
|
|
66
|
+
const signatureCoversBody = Object.entries(relayed.headers)
|
|
67
|
+
.some(([name, value]) => name.toLowerCase() === "signature-input" && /content-digest|repr-digest|digest/i.test(value));
|
|
68
|
+
for (const [name, value] of Object.entries(relayed.headers)) {
|
|
69
|
+
const lower = name.toLowerCase();
|
|
70
|
+
if (HOP_BY_HOP.has(lower) || BODY_BOUND.has(lower))
|
|
71
|
+
continue;
|
|
72
|
+
if (signatureCoversBody && (lower === "signature" || lower === "signature-input"))
|
|
73
|
+
continue;
|
|
74
|
+
headers[lower] = value;
|
|
75
|
+
}
|
|
76
|
+
return jsonResponse(200, body, {
|
|
77
|
+
...headers,
|
|
78
|
+
"content-type": headers["content-type"] ?? "application/json",
|
|
79
|
+
"cache-control": "no-store",
|
|
80
|
+
"retry-after": String(ORDER_PENDING_RETRY_AFTER),
|
|
81
|
+
[PAYMENT_STATUS_HEADER]: "succeeded",
|
|
82
|
+
[ORDER_STATUS_HEADER]: "pending",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** HTTP status of the order-pending error answer on UCP and ACP (MCP answers in-band with HTTP 200). */
|
|
86
|
+
export const ORDER_PENDING_ERROR_STATUS = 503;
|
|
87
|
+
/**
|
|
88
|
+
* The UCP or ACP order-pending answer when the kit has no checkout body to
|
|
89
|
+
* rewrite: it refused the step itself (agent checkout paused, the agent
|
|
90
|
+
* refused at the edge, Relyon unreachable or refusing, `priceCart` failing,
|
|
91
|
+
* the cart changed on a resend, or an unexpected error) on a checkout whose
|
|
92
|
+
* payment succeeded and whose order isn't created yet. Built like
|
|
93
|
+
* `paymentOutcomeUnknown`: UCP `{code, content}` plus `payment_status` and
|
|
94
|
+
* `status_url`; ACP's schema-exact Error `{type, code, message}`; both HTTP
|
|
95
|
+
* 503 with Retry-After, `Payment-Status: succeeded`, `Order-Status: pending`
|
|
96
|
+
* and a `Link: <url>; rel="status"` to the store's own checkout read. The
|
|
97
|
+
* code is `order_pending` (UCP's error_code and ACP's Error code are free
|
|
98
|
+
* strings). Never says nothing was charged, never shows an order.
|
|
99
|
+
*/
|
|
100
|
+
export function orderPendingError(protocol, options) {
|
|
101
|
+
const content = "The payment went through, and the store is placing the order. Resend the complete request (it doesn't charge again)"
|
|
102
|
+
+ ` or read the checkout at ${options.statusUrl} to see when the order is placed. Don't start a new checkout or re-enter payment.`;
|
|
103
|
+
const headers = {
|
|
104
|
+
"cache-control": "no-store",
|
|
105
|
+
"retry-after": String(ORDER_PENDING_RETRY_AFTER),
|
|
106
|
+
[PAYMENT_STATUS_HEADER]: "succeeded",
|
|
107
|
+
[ORDER_STATUS_HEADER]: "pending",
|
|
108
|
+
link: `<${options.statusUrl}>; rel="status"`,
|
|
109
|
+
};
|
|
110
|
+
return protocol === "ucp"
|
|
111
|
+
? jsonResponse(ORDER_PENDING_ERROR_STATUS, { code: ORDER_PENDING, content, payment_status: "succeeded", status_url: options.statusUrl }, headers)
|
|
112
|
+
: jsonResponse(ORDER_PENDING_ERROR_STATUS, { type: "processing_error", code: ORDER_PENDING, message: content }, headers);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* MCP's order-pending answer: an in-band JSON-RPC error (HTTP 200) with the
|
|
116
|
+
* stable code `order_pending`, naming the checkout and the tools to call.
|
|
117
|
+
*/
|
|
118
|
+
export function orderPendingMcp(id, checkoutId) {
|
|
119
|
+
return jsonResponse(200, mcpErrorBody(id, ORDER_PENDING, MCP_MESSAGE, {
|
|
120
|
+
payment_status: "succeeded",
|
|
121
|
+
order_status: "pending",
|
|
122
|
+
checkout_id: checkoutId,
|
|
123
|
+
check: { tool: "get_checkout", arguments: { checkout_id: checkoutId } },
|
|
124
|
+
retry: { tool: "complete_checkout", arguments: { checkout_id: checkoutId } },
|
|
125
|
+
retry_after: ORDER_PENDING_RETRY_AFTER,
|
|
126
|
+
}));
|
|
127
|
+
}
|
package/dist/orders.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RelyonGateway } from "./relyon.js";
|
|
2
|
+
import type { FulfillmentUpdate, Order } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reports a shipped, delivered or canceled order with `updateOrderFulfillment`.
|
|
5
|
+
* The Idempotency-Key comes from the order and the update, so resending the
|
|
6
|
+
* same report is safe. Relyon problems and outages are thrown to the caller;
|
|
7
|
+
* the store retries them on its own schedule.
|
|
8
|
+
*
|
|
9
|
+
* The contract has no operation for reporting refunds; Relyon records refunds
|
|
10
|
+
* it makes itself.
|
|
11
|
+
*/
|
|
12
|
+
export declare function reportFulfillment(gateway: RelyonGateway, orderId: string, update: FulfillmentUpdate): Promise<Order>;
|
package/dist/orders.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ORDER_FULFILLMENT_PATH, ORDER_OBJECT } from "./wire-names.js";
|
|
2
|
+
import { canonicalJson, isRecord, sha256 } from "./util.js";
|
|
3
|
+
function isOrder(data) {
|
|
4
|
+
return isRecord(data) && data.object === ORDER_OBJECT && typeof data.id === "string" && typeof data.fulfillment_status === "string";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Reports a shipped, delivered or canceled order with `updateOrderFulfillment`.
|
|
8
|
+
* The Idempotency-Key comes from the order and the update, so resending the
|
|
9
|
+
* same report is safe. Relyon problems and outages are thrown to the caller;
|
|
10
|
+
* the store retries them on its own schedule.
|
|
11
|
+
*
|
|
12
|
+
* The contract has no operation for reporting refunds; Relyon records refunds
|
|
13
|
+
* it makes itself.
|
|
14
|
+
*/
|
|
15
|
+
export async function reportFulfillment(gateway, orderId, update) {
|
|
16
|
+
const { data } = await gateway.call((client) => client.POST(ORDER_FULFILLMENT_PATH, {
|
|
17
|
+
params: { path: { id: orderId }, header: { "Idempotency-Key": `sk-ful-${sha256(`${orderId}\n${canonicalJson(update)}`)}` } },
|
|
18
|
+
body: update,
|
|
19
|
+
}), isOrder);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const PAYMENTS_FRAMEWORKS: readonly ["express", "next", "node"];
|
|
2
|
+
export type PaymentsFramework = typeof PAYMENTS_FRAMEWORKS[number];
|
|
3
|
+
/** Where the helpers go, relative to the app's directory. */
|
|
4
|
+
export declare const PAYMENTS_HELPER_FILE = "relyon/payments.ts";
|
|
5
|
+
/** The skill payments mode installs. */
|
|
6
|
+
export declare const PAYMENTS_SKILL = "relyon-payments";
|
|
7
|
+
/**
|
|
8
|
+
* The ask-first block, word for word as Relyon's agent entry points carry it
|
|
9
|
+
* (the kit's AGENTS.md and the payments agent-instructions block).
|
|
10
|
+
*/
|
|
11
|
+
export declare const ASK_FIRST = "Before building, ask the user: 'Do you want to (1) accept card payments in your own app \u2014 no Relyon product catalog or shopping pages; (2) also list products so AI shopping agents can find and buy them; or (3) also have Relyon's kit build the shopping pages for you?' Don't choose for them. Then follow the matching quickstart.";
|
|
12
|
+
/** The app's framework from its package.json: Next.js, else Express, else a plain Node server. */
|
|
13
|
+
export declare function detectPaymentsFramework(project: string): Promise<PaymentsFramework>;
|
|
14
|
+
/** The helper file for a framework, from this package's templates/payments/. */
|
|
15
|
+
export declare function paymentsHelper(framework: PaymentsFramework, templatesDir?: string): Promise<Buffer>;
|
|
16
|
+
/** How the helper is mounted, one line per framework. */
|
|
17
|
+
export declare const PAYMENTS_MOUNT: Readonly<Record<PaymentsFramework, string>>;
|
|
18
|
+
/** The agent-instructions block for a payments-only app. Same markers as the store pointer block. */
|
|
19
|
+
export declare function paymentsPointerBlock(skillsDir: string, framework: PaymentsFramework, skillInstalled: boolean): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { kitCommand } from "./identity.js";
|
|
5
|
+
// What `init --payments` (layer 1) writes: the payment helpers for the app's
|
|
6
|
+
// framework, the relyon-payments skill, and an agent-instructions block that
|
|
7
|
+
// carries the ask-first block. Nothing for a catalog, feeds, /cart or store
|
|
8
|
+
// hostnames.
|
|
9
|
+
export const PAYMENTS_FRAMEWORKS = ["express", "next", "node"];
|
|
10
|
+
/** Where the helpers go, relative to the app's directory. */
|
|
11
|
+
export const PAYMENTS_HELPER_FILE = "relyon/payments.ts";
|
|
12
|
+
/** The skill payments mode installs. */
|
|
13
|
+
export const PAYMENTS_SKILL = "relyon-payments";
|
|
14
|
+
/**
|
|
15
|
+
* The ask-first block, word for word as Relyon's agent entry points carry it
|
|
16
|
+
* (the kit's AGENTS.md and the payments agent-instructions block).
|
|
17
|
+
*/
|
|
18
|
+
export const ASK_FIRST = "Before building, ask the user: 'Do you want to (1) accept card payments in your own app — no Relyon product catalog or shopping pages; (2) also list products so AI shopping agents can find and buy them; or (3) also have Relyon's kit build the shopping pages for you?' Don't choose for them. Then follow the matching quickstart.";
|
|
19
|
+
/** The app's framework from its package.json: Next.js, else Express, else a plain Node server. */
|
|
20
|
+
export async function detectPaymentsFramework(project) {
|
|
21
|
+
try {
|
|
22
|
+
const file = path.join(project, "package.json");
|
|
23
|
+
const stat = await lstat(file);
|
|
24
|
+
if (!stat.isFile() || stat.size > 1024 * 1024)
|
|
25
|
+
return "node";
|
|
26
|
+
const pkg = JSON.parse(await readFile(file, "utf8"));
|
|
27
|
+
const has = (name) => ["dependencies", "devDependencies"].some((field) => {
|
|
28
|
+
const deps = pkg[field];
|
|
29
|
+
return !!deps && typeof deps === "object" && name in deps;
|
|
30
|
+
});
|
|
31
|
+
if (has("next"))
|
|
32
|
+
return "next";
|
|
33
|
+
if (has("express"))
|
|
34
|
+
return "express";
|
|
35
|
+
}
|
|
36
|
+
catch { /* no usable package.json: a plain Node server */ }
|
|
37
|
+
return "node";
|
|
38
|
+
}
|
|
39
|
+
/** The helper file for a framework, from this package's templates/payments/. */
|
|
40
|
+
export async function paymentsHelper(framework, templatesDir) {
|
|
41
|
+
const root = templatesDir ?? fileURLToPath(new URL("../templates/", import.meta.url));
|
|
42
|
+
return readFile(path.join(root, "payments", `${framework}.ts`));
|
|
43
|
+
}
|
|
44
|
+
/** How the helper is mounted, one line per framework. */
|
|
45
|
+
export const PAYMENTS_MOUNT = Object.freeze({
|
|
46
|
+
express: "Mount it before express.json(): app.use(relyonPayments) from ./relyon/payments.js.",
|
|
47
|
+
next: "Serve it from app/relyon/[...path]/route.ts: export { POST } from \"../../../relyon/payments\".",
|
|
48
|
+
node: "Call it first in your request handler: if (await relyonPayments(req, res)) return;",
|
|
49
|
+
});
|
|
50
|
+
const BEGIN = "<!-- BEGIN relyon (written by npx @relyon/store-kit init; edit outside this block) -->";
|
|
51
|
+
const END = "<!-- END relyon -->";
|
|
52
|
+
/** The agent-instructions block for a payments-only app. Same markers as the store pointer block. */
|
|
53
|
+
export function paymentsPointerBlock(skillsDir, framework, skillInstalled) {
|
|
54
|
+
const command = kitCommand();
|
|
55
|
+
return [
|
|
56
|
+
BEGIN,
|
|
57
|
+
ASK_FIRST,
|
|
58
|
+
"",
|
|
59
|
+
"This app chose (1): card payments in its own app with Relyon (payments only). Don't add a Relyon product catalog, product feeds, a /cart page or store hostnames unless the user asks for (2) or (3).",
|
|
60
|
+
skillInstalled
|
|
61
|
+
? `Read the ${PAYMENTS_SKILL} skill first (\`${skillsDir}/${PAYMENTS_SKILL}/SKILL.md\`).`
|
|
62
|
+
: `The ${PAYMENTS_SKILL} skill wasn't in this kit package; follow \`${PAYMENTS_HELPER_FILE}\` and the kit's README.`,
|
|
63
|
+
`The payment helpers are in \`${PAYMENTS_HELPER_FILE}\` (${framework}): payment session, card fields, charge, refund and webhook verification. ${PAYMENTS_MOUNT[framework]}`,
|
|
64
|
+
"Charge only the amount from the app's own order records, never one the browser sends. Pass the card fields' tokenize() result through unchanged; never handle card numbers.",
|
|
65
|
+
"Never read or print Relyon's private files (the saved key) or RELYON_API_KEY.",
|
|
66
|
+
"",
|
|
67
|
+
`Finish with \`${command} check\` and fix every step until it prints DONE.`,
|
|
68
|
+
END,
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RelyonPayments, type ChargeResult } from "./payments.js";
|
|
2
|
+
export interface PaymentRoutePaths {
|
|
3
|
+
/** POST `{ order_reference }` → `{ client_token, script_url, amount, currency }`. */
|
|
4
|
+
session: string;
|
|
5
|
+
/** POST `{ order_reference, payment_method, attempt? }` → the charge's outcome. */
|
|
6
|
+
charge: string;
|
|
7
|
+
/** POST from Relyon, signed: verified against the raw body. */
|
|
8
|
+
webhook: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_PAYMENT_ROUTES: Readonly<PaymentRoutePaths>;
|
|
11
|
+
export interface OrderAmount {
|
|
12
|
+
/** Minor units (cents). */
|
|
13
|
+
amount: number;
|
|
14
|
+
currency: string;
|
|
15
|
+
/** Shown on the payment's one cart line. */
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PaymentRoutesOptions {
|
|
19
|
+
/** Default: `createPayments()` from the environment. */
|
|
20
|
+
payments?: RelyonPayments;
|
|
21
|
+
/**
|
|
22
|
+
* The amount the order costs, from the app's own records; null when the
|
|
23
|
+
* order reference is unknown. Never trust an amount the browser sends.
|
|
24
|
+
*/
|
|
25
|
+
orderAmount: (orderReference: string) => OrderAmount | null | Promise<OrderAmount | null>;
|
|
26
|
+
/** Called after a charge succeeds (again on a replayed charge: make it idempotent). */
|
|
27
|
+
onPaid?: (payment: ChargeResult, orderReference: string) => void | Promise<void>;
|
|
28
|
+
/** Each webhook event whose signature verified. */
|
|
29
|
+
onEvent?: (event: Record<string, unknown>) => void | Promise<void>;
|
|
30
|
+
paths?: Partial<PaymentRoutePaths>;
|
|
31
|
+
/** Largest request body read, in bytes. Default 64 KiB. */
|
|
32
|
+
maxBodyBytes?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The payments-only routes as one Fetch handler. Mount it with
|
|
36
|
+
* `paymentsMiddleware` (Express), `paymentsRouteHandlers` (Next.js) or
|
|
37
|
+
* `paymentsNodeHandler` (a plain Node server).
|
|
38
|
+
*/
|
|
39
|
+
export declare class PaymentRoutes {
|
|
40
|
+
readonly payments: RelyonPayments;
|
|
41
|
+
readonly paths: Readonly<PaymentRoutePaths>;
|
|
42
|
+
readonly maxBodyBytes: number;
|
|
43
|
+
private readonly options;
|
|
44
|
+
constructor(options: PaymentRoutesOptions);
|
|
45
|
+
/** True for the three paths this handler answers. */
|
|
46
|
+
matches(pathname: string): boolean;
|
|
47
|
+
/** The route's answer, or null for any other path. */
|
|
48
|
+
handle(request: Request, _context?: {
|
|
49
|
+
ip?: string;
|
|
50
|
+
}): Promise<Response | null>;
|
|
51
|
+
private webhook;
|
|
52
|
+
}
|
|
53
|
+
/** Creates the payments-only routes (layer 1). */
|
|
54
|
+
export declare function createPaymentRoutes(options: PaymentRoutesOptions): PaymentRoutes;
|