@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
package/dist/util.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
/** JSON with object keys sorted, so equal values always hash the same. */
|
|
3
|
+
export function canonicalJson(value) {
|
|
4
|
+
if (value === null || typeof value !== "object")
|
|
5
|
+
return JSON.stringify(value) ?? "null";
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return `[${value.map((item) => canonicalJson(item === undefined ? null : item)).join(",")}]`;
|
|
8
|
+
const entries = Object.entries(value)
|
|
9
|
+
.filter(([, item]) => item !== undefined)
|
|
10
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
11
|
+
return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${canonicalJson(item)}`).join(",")}}`;
|
|
12
|
+
}
|
|
13
|
+
export const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
14
|
+
/** A random ID that matches the contract's event ID pattern (`^[A-Za-z0-9._:-]+$`). */
|
|
15
|
+
export const randomId = (prefix) => `${prefix}${randomBytes(12).toString("hex")}`;
|
|
16
|
+
export const base64url = (bytes) => Buffer.from(bytes).toString("base64url");
|
|
17
|
+
export function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
/** Every request header with its name in lower case. Repeated headers are already joined with ", " by `Headers`. */
|
|
21
|
+
export function lowerCaseHeaders(headers) {
|
|
22
|
+
const out = {};
|
|
23
|
+
headers.forEach((value, name) => { out[name.toLowerCase()] = value; });
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
export const unixSeconds = (ms) => Math.floor(ms / 1000);
|
|
27
|
+
export function jsonResponse(status, body, headers = {}) {
|
|
28
|
+
return new Response(JSON.stringify(body), {
|
|
29
|
+
status,
|
|
30
|
+
headers: { "content-type": "application/json", "cache-control": "no-store", ...headers },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function textResponse(status, body, contentType, headers = {}) {
|
|
34
|
+
return new Response(body, { status, headers: { "content-type": contentType, ...headers } });
|
|
35
|
+
}
|
|
36
|
+
export function escapeHtml(value) {
|
|
37
|
+
return value.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]);
|
|
38
|
+
}
|
|
39
|
+
export function escapeXml(value) {
|
|
40
|
+
return value.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]);
|
|
41
|
+
}
|
|
42
|
+
/** Parses JSON without throwing; `undefined` means it wasn't JSON. */
|
|
43
|
+
export function tryParseJson(text) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(text);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** A three-letter currency code in any case, upper-cased; anything else unchanged (Relyon reports it). */
|
|
52
|
+
export function upperCurrency(value) {
|
|
53
|
+
return (typeof value === "string" && /^[A-Za-z]{3}$/.test(value) ? value.toUpperCase() : value);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The store's cart with its currency codes upper-cased ("usd" and "USD" are
|
|
57
|
+
* the same currency): the top-level `currency` and `totals.currency`.
|
|
58
|
+
*/
|
|
59
|
+
export function withUpperCurrency(cart) {
|
|
60
|
+
if (!isRecord(cart))
|
|
61
|
+
return cart;
|
|
62
|
+
const out = { ...cart };
|
|
63
|
+
if (out.currency !== undefined)
|
|
64
|
+
out.currency = upperCurrency(out.currency);
|
|
65
|
+
if (isRecord(out.totals) && out.totals.currency !== undefined)
|
|
66
|
+
out.totals = { ...out.totals, currency: upperCurrency(out.totals.currency) };
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { StoreCatalogProduct } from "./catalog-reads.js";
|
|
2
|
+
/** A feed ID as the store's priceCart sees it: the product it belongs to and the chosen options. */
|
|
3
|
+
export interface ResolvedFeedItem {
|
|
4
|
+
/** The product's own `merchant_product_id` (a variant's parent). */
|
|
5
|
+
product_id: string;
|
|
6
|
+
/** The variant's options; absent for a product without options. */
|
|
7
|
+
options?: Record<string, string>;
|
|
8
|
+
/** The feed ID this came from (a variant ID, or the product's own ID). */
|
|
9
|
+
feed_id: string;
|
|
10
|
+
/** The catalog product (the parent for a variant). */
|
|
11
|
+
product: StoreCatalogProduct;
|
|
12
|
+
}
|
|
13
|
+
/** A product's `feed.variants` that name an ID and options, in the store's order. */
|
|
14
|
+
export declare function productVariants(product: StoreCatalogProduct): Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
options: Record<string, string>;
|
|
17
|
+
amount?: number;
|
|
18
|
+
currency?: string;
|
|
19
|
+
availability?: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Maps a feed ID to `{product_id, options}`: a variant ID (from a product's
|
|
23
|
+
* `feed.variants`) maps to its parent's `merchant_product_id` plus that
|
|
24
|
+
* variant's options; a product's own ID maps to itself. Variants win over a
|
|
25
|
+
* product with the same ID. null when the catalog has neither.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveFeedItem(products: readonly StoreCatalogProduct[], feedId: string): ResolvedFeedItem | null;
|
|
28
|
+
/**
|
|
29
|
+
* The first value of each option a product declares, read best-effort from
|
|
30
|
+
* common shapes of its opaque `options`: `{size: ["S", "M"]}`,
|
|
31
|
+
* `{size: {values: ["S"]}}`, `{size: "S"}`, or a list of
|
|
32
|
+
* `{name, values}` under any key. undefined when nothing readable is there.
|
|
33
|
+
*/
|
|
34
|
+
export declare function firstOptionValues(options: unknown): Record<string, string> | undefined;
|
|
35
|
+
/** How the default item was chosen. */
|
|
36
|
+
export type DefaultItemSource = "no_options" | "first_variant" | "first_option_values" | "options_unreadable";
|
|
37
|
+
export interface DefaultItem extends ResolvedFeedItem {
|
|
38
|
+
source: DefaultItemSource;
|
|
39
|
+
}
|
|
40
|
+
/** The item for one product: itself, its first listed variant, or the first value of each declared option. */
|
|
41
|
+
export declare function itemForProduct(product: StoreCatalogProduct): DefaultItem;
|
|
42
|
+
/**
|
|
43
|
+
* The default purchasable item among `products` (already filtered to the
|
|
44
|
+
* ones that may be bought): a product without options first, else the first
|
|
45
|
+
* variant of a product's `feed.variants`, else the first value of each option
|
|
46
|
+
* the product declares. Ties go by product ID. null for an empty list.
|
|
47
|
+
*/
|
|
48
|
+
export declare function defaultPurchasableItem(products: readonly StoreCatalogProduct[]): DefaultItem | null;
|
|
49
|
+
/** A product ID and its options as printed in messages: `classic-tee {"size":"2XL","color":"white"}`. */
|
|
50
|
+
export declare function describeItem(productId: string, options?: Readonly<Record<string, unknown>>): string;
|
|
51
|
+
/**
|
|
52
|
+
* The options an agent never has to name because each has exactly one value,
|
|
53
|
+
* read from the product's variants (or its declared options when it has no
|
|
54
|
+
* variants). Multi-value options are never guessed: the store keeps refusing
|
|
55
|
+
* them with the choices listed.
|
|
56
|
+
*/
|
|
57
|
+
export declare function singleValueOptions(product: StoreCatalogProduct): Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* Fills in the single-value options a line omits, so an agent can check out a
|
|
60
|
+
* single-option product without naming the option. Options the agent named
|
|
61
|
+
* always win; products with multi-value options are returned unchanged for
|
|
62
|
+
* the store to refuse with its choice list.
|
|
63
|
+
*/
|
|
64
|
+
export declare function withSingleValueOptions<L extends {
|
|
65
|
+
product_id: string;
|
|
66
|
+
options?: Record<string, unknown>;
|
|
67
|
+
}>(line: L, product: StoreCatalogProduct | null | undefined): L;
|
package/dist/variants.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { isRecord } from "./util.js";
|
|
2
|
+
/** A product's `feed.variants` that name an ID and options, in the store's order. */
|
|
3
|
+
export function productVariants(product) {
|
|
4
|
+
const list = product.feed?.variants;
|
|
5
|
+
if (!Array.isArray(list))
|
|
6
|
+
return [];
|
|
7
|
+
return list.filter((variant) => isRecord(variant) && typeof variant.id === "string" && variant.id && isRecord(variant.options))
|
|
8
|
+
.map((variant) => ({
|
|
9
|
+
id: variant.id, options: { ...variant.options },
|
|
10
|
+
...(isRecord(variant.exactPrice) && Number.isSafeInteger(variant.exactPrice.amount) ? { amount: variant.exactPrice.amount, currency: variant.exactPrice.currency } : {}),
|
|
11
|
+
...(typeof variant.availability === "string" ? { availability: variant.availability } : {}),
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Maps a feed ID to `{product_id, options}`: a variant ID (from a product's
|
|
16
|
+
* `feed.variants`) maps to its parent's `merchant_product_id` plus that
|
|
17
|
+
* variant's options; a product's own ID maps to itself. Variants win over a
|
|
18
|
+
* product with the same ID. null when the catalog has neither.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveFeedItem(products, feedId) {
|
|
21
|
+
for (const product of products) {
|
|
22
|
+
const variant = productVariants(product).find((entry) => entry.id === feedId);
|
|
23
|
+
if (variant)
|
|
24
|
+
return { product_id: product.merchant_product_id, options: variant.options, feed_id: feedId, product };
|
|
25
|
+
}
|
|
26
|
+
const product = products.find((entry) => entry.merchant_product_id === feedId);
|
|
27
|
+
return product ? { product_id: product.merchant_product_id, feed_id: feedId, product } : null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The first value of each option a product declares, read best-effort from
|
|
31
|
+
* common shapes of its opaque `options`: `{size: ["S", "M"]}`,
|
|
32
|
+
* `{size: {values: ["S"]}}`, `{size: "S"}`, or a list of
|
|
33
|
+
* `{name, values}` under any key. undefined when nothing readable is there.
|
|
34
|
+
*/
|
|
35
|
+
export function firstOptionValues(options) {
|
|
36
|
+
const chosen = {};
|
|
37
|
+
const first = (value) => {
|
|
38
|
+
if (typeof value === "string" && value)
|
|
39
|
+
return value;
|
|
40
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
41
|
+
return String(value);
|
|
42
|
+
if (Array.isArray(value))
|
|
43
|
+
return first(value[0]) ?? (isRecord(value[0]) ? first(value[0].value ?? value[0].name ?? value[0].label) : undefined);
|
|
44
|
+
if (isRecord(value))
|
|
45
|
+
return first(value.values ?? value.choices ?? value.default ?? value.value);
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
if (!isRecord(options))
|
|
49
|
+
return undefined;
|
|
50
|
+
for (const [key, value] of Object.entries(options)) {
|
|
51
|
+
if (Array.isArray(value) && value.length && value.every((entry) => isRecord(entry) && typeof entry.name === "string")) {
|
|
52
|
+
// A list of {name, values} option groups.
|
|
53
|
+
for (const group of value) {
|
|
54
|
+
const pick = first(group.values ?? group.choices ?? group.options);
|
|
55
|
+
if (pick !== undefined)
|
|
56
|
+
chosen[String(group.name)] = pick;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const pick = first(value);
|
|
61
|
+
if (pick !== undefined)
|
|
62
|
+
chosen[key] = pick;
|
|
63
|
+
}
|
|
64
|
+
return Object.keys(chosen).length ? chosen : undefined;
|
|
65
|
+
}
|
|
66
|
+
const byId = (a, b) => a.merchant_product_id.localeCompare(b.merchant_product_id, "en");
|
|
67
|
+
/** The item for one product: itself, its first listed variant, or the first value of each declared option. */
|
|
68
|
+
export function itemForProduct(product) {
|
|
69
|
+
if (product.configurable !== true)
|
|
70
|
+
return { product_id: product.merchant_product_id, feed_id: product.merchant_product_id, product, source: "no_options" };
|
|
71
|
+
const variant = productVariants(product)[0];
|
|
72
|
+
if (variant)
|
|
73
|
+
return { product_id: product.merchant_product_id, options: variant.options, feed_id: variant.id, product, source: "first_variant" };
|
|
74
|
+
const options = firstOptionValues(product.options);
|
|
75
|
+
return options
|
|
76
|
+
? { product_id: product.merchant_product_id, options, feed_id: product.merchant_product_id, product, source: "first_option_values" }
|
|
77
|
+
: { product_id: product.merchant_product_id, feed_id: product.merchant_product_id, product, source: "options_unreadable" };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The default purchasable item among `products` (already filtered to the
|
|
81
|
+
* ones that may be bought): a product without options first, else the first
|
|
82
|
+
* variant of a product's `feed.variants`, else the first value of each option
|
|
83
|
+
* the product declares. Ties go by product ID. null for an empty list.
|
|
84
|
+
*/
|
|
85
|
+
export function defaultPurchasableItem(products) {
|
|
86
|
+
const sorted = [...products].sort(byId);
|
|
87
|
+
const plain = sorted.find((product) => product.configurable !== true);
|
|
88
|
+
if (plain)
|
|
89
|
+
return itemForProduct(plain);
|
|
90
|
+
const withVariants = sorted.find((product) => productVariants(product).length > 0);
|
|
91
|
+
if (withVariants)
|
|
92
|
+
return itemForProduct(withVariants);
|
|
93
|
+
return sorted[0] ? itemForProduct(sorted[0]) : null;
|
|
94
|
+
}
|
|
95
|
+
/** A product ID and its options as printed in messages: `classic-tee {"size":"2XL","color":"white"}`. */
|
|
96
|
+
export function describeItem(productId, options) {
|
|
97
|
+
const id = JSON.stringify(productId.slice(0, 128));
|
|
98
|
+
return options && Object.keys(options).length ? `${id} with options ${JSON.stringify(options).slice(0, 300)}` : `${id} (no options)`;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The options an agent never has to name because each has exactly one value,
|
|
102
|
+
* read from the product's variants (or its declared options when it has no
|
|
103
|
+
* variants). Multi-value options are never guessed: the store keeps refusing
|
|
104
|
+
* them with the choices listed.
|
|
105
|
+
*/
|
|
106
|
+
export function singleValueOptions(product) {
|
|
107
|
+
const values = {};
|
|
108
|
+
const variants = productVariants(product);
|
|
109
|
+
if (variants.length) {
|
|
110
|
+
for (const variant of variants) {
|
|
111
|
+
for (const [name, value] of Object.entries(variant.options)) {
|
|
112
|
+
const list = values[name] ??= [];
|
|
113
|
+
if (!list.includes(value))
|
|
114
|
+
list.push(value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (isRecord(product.options)) {
|
|
119
|
+
// Declared options without variants: a value is single only when it is a
|
|
120
|
+
// lone string or a one-entry list.
|
|
121
|
+
for (const [name, value] of Object.entries(product.options)) {
|
|
122
|
+
const raw = Array.isArray(value) && value.length === 1 ? value[0] : value;
|
|
123
|
+
if (typeof raw === "string" && raw)
|
|
124
|
+
values[name] = [raw];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const chosen = {};
|
|
128
|
+
for (const [name, list] of Object.entries(values)) {
|
|
129
|
+
if (list.length === 1)
|
|
130
|
+
chosen[name] = list[0];
|
|
131
|
+
}
|
|
132
|
+
return chosen;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Fills in the single-value options a line omits, so an agent can check out a
|
|
136
|
+
* single-option product without naming the option. Options the agent named
|
|
137
|
+
* always win; products with multi-value options are returned unchanged for
|
|
138
|
+
* the store to refuse with its choice list.
|
|
139
|
+
*/
|
|
140
|
+
export function withSingleValueOptions(line, product) {
|
|
141
|
+
if (!product || product.configurable !== true)
|
|
142
|
+
return line;
|
|
143
|
+
const defaults = singleValueOptions(product);
|
|
144
|
+
const merged = { ...defaults, ...(line.options ?? {}) };
|
|
145
|
+
return Object.keys(merged).length ? { ...line, options: merged } : line;
|
|
146
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The running package's version: `@relyon/kit`'s own, or the
|
|
3
|
+
* `@relyon/store-kit` wrapper's when the wrapper runs the kit.
|
|
4
|
+
*/
|
|
5
|
+
export declare const KIT_VERSION: string;
|
|
6
|
+
/** The running package's npm name. */
|
|
7
|
+
export declare const KIT_PACKAGE: string;
|
|
8
|
+
/** `@relyon/kit`'s own version, as in its package.json (a test keeps the two equal). */
|
|
9
|
+
export declare const RELYON_KIT_VERSION: string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { kitIdentity, RELYON_KIT_IDENTITY } from "./identity.js";
|
|
2
|
+
/**
|
|
3
|
+
* The running package's version: `@relyon/kit`'s own, or the
|
|
4
|
+
* `@relyon/store-kit` wrapper's when the wrapper runs the kit.
|
|
5
|
+
*/
|
|
6
|
+
export const KIT_VERSION = kitIdentity().version;
|
|
7
|
+
/** The running package's npm name. */
|
|
8
|
+
export const KIT_PACKAGE = kitIdentity().name;
|
|
9
|
+
/** `@relyon/kit`'s own version, as in its package.json (a test keeps the two equal). */
|
|
10
|
+
export const RELYON_KIT_VERSION = RELYON_KIT_IDENTITY.version;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the kit answers while it waits for a sandbox key (no usable
|
|
3
|
+
* RELYON_API_KEY, Test only). Every kit route still answers from the kit, so
|
|
4
|
+
* an app's catch-all page never stands in for it, and none of these answers
|
|
5
|
+
* advertises a checkout capability or reveals any configuration.
|
|
6
|
+
*
|
|
7
|
+
* - Checkout-bearing JSON routes (/.well-known/ucp, the verification file,
|
|
8
|
+
* the agent card, UCP/ACP checkout, the webhook): 503 with Retry-After and
|
|
9
|
+
* `{ "status": "waiting_for_sandbox_key", "code": "sandbox_key_pending", "message": …, "developer_hint": … }`
|
|
10
|
+
* (`message` is for shoppers; `developer_hint` is for the store's builder).
|
|
11
|
+
* - /mcp: a normal MCP server that lists only the browse tools; initialize
|
|
12
|
+
* says `waiting_for_sandbox_key` in its instructions and `_meta`.
|
|
13
|
+
* - llms.txt, robots.txt, the product sitemap and the RSS feeds: 200 with a
|
|
14
|
+
* `waiting_for_sandbox_key` line or comment; the JSON Lines feed: 200, with
|
|
15
|
+
* the status in the `x-relyon-status` header (every waiting discovery answer
|
|
16
|
+
* carries that header).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* How a server loads the saved Test key, and how an agent keeps it secret.
|
|
20
|
+
* Printed by init and in doctor's key step.
|
|
21
|
+
*/
|
|
22
|
+
export declare const KEY_LOADING = "A plain Node/Express server loads the key with `await loadTestConfig({ project: process.cwd() })` from @relyon/store-kit/server-config (or with dotenv); Next.js reads .env itself. Never cat or print .env, and never paste the key into a command.";
|
|
23
|
+
export declare const WAITING_STATUS = "waiting_for_sandbox_key";
|
|
24
|
+
export declare const WAITING_CODE = "sandbox_key_pending";
|
|
25
|
+
export declare const WAITING_STATUS_HEADER = "x-relyon-status";
|
|
26
|
+
export declare const WAITING_RETRY_AFTER_SECONDS = 300;
|
|
27
|
+
export declare const WAITING_MESSAGE = "This store's checkout is still being set up (waiting for a sandbox key). Browse the store's products; try checkout again later.";
|
|
28
|
+
/**
|
|
29
|
+
* For the store's builder (a person or coding agent), never shown to shoppers:
|
|
30
|
+
* setup isn't finished, and the doctor lists what to do next.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEVELOPER_HINT = "Store setup is not done. Run: npx @relyon/store-kit doctor";
|
|
33
|
+
/** A configuration TypeError (message unchanged) that also carries the builder-facing hint. */
|
|
34
|
+
export declare function setupError(message: string): TypeError & {
|
|
35
|
+
developer_hint: string;
|
|
36
|
+
};
|
|
37
|
+
/** The comment robots.txt starts with while the kit waits. */
|
|
38
|
+
export declare const WAITING_TEXT_MARKER = "# Relyon store kit: waiting_for_sandbox_key";
|
|
39
|
+
export declare function waitingResponse(): Response;
|
|
40
|
+
/** Adds an XML comment with the waiting status right after the XML declaration. */
|
|
41
|
+
export declare function withWaitingXmlMarker(xml: string, waiting: boolean): string;
|
|
42
|
+
/** True for a body the kit answers while waiting (used by the doctor). */
|
|
43
|
+
export declare function isWaitingBody(value: unknown): boolean;
|
package/dist/waiting.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsonResponse } from "./util.js";
|
|
2
|
+
/**
|
|
3
|
+
* What the kit answers while it waits for a sandbox key (no usable
|
|
4
|
+
* RELYON_API_KEY, Test only). Every kit route still answers from the kit, so
|
|
5
|
+
* an app's catch-all page never stands in for it, and none of these answers
|
|
6
|
+
* advertises a checkout capability or reveals any configuration.
|
|
7
|
+
*
|
|
8
|
+
* - Checkout-bearing JSON routes (/.well-known/ucp, the verification file,
|
|
9
|
+
* the agent card, UCP/ACP checkout, the webhook): 503 with Retry-After and
|
|
10
|
+
* `{ "status": "waiting_for_sandbox_key", "code": "sandbox_key_pending", "message": …, "developer_hint": … }`
|
|
11
|
+
* (`message` is for shoppers; `developer_hint` is for the store's builder).
|
|
12
|
+
* - /mcp: a normal MCP server that lists only the browse tools; initialize
|
|
13
|
+
* says `waiting_for_sandbox_key` in its instructions and `_meta`.
|
|
14
|
+
* - llms.txt, robots.txt, the product sitemap and the RSS feeds: 200 with a
|
|
15
|
+
* `waiting_for_sandbox_key` line or comment; the JSON Lines feed: 200, with
|
|
16
|
+
* the status in the `x-relyon-status` header (every waiting discovery answer
|
|
17
|
+
* carries that header).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* How a server loads the saved Test key, and how an agent keeps it secret.
|
|
21
|
+
* Printed by init and in doctor's key step.
|
|
22
|
+
*/
|
|
23
|
+
export const KEY_LOADING = "A plain Node/Express server loads the key with `await loadTestConfig({ project: process.cwd() })` from @relyon/store-kit/server-config (or with dotenv); Next.js reads .env itself. Never cat or print .env, and never paste the key into a command.";
|
|
24
|
+
export const WAITING_STATUS = "waiting_for_sandbox_key";
|
|
25
|
+
export const WAITING_CODE = "sandbox_key_pending";
|
|
26
|
+
export const WAITING_STATUS_HEADER = "x-relyon-status";
|
|
27
|
+
export const WAITING_RETRY_AFTER_SECONDS = 300;
|
|
28
|
+
export const WAITING_MESSAGE = "This store's checkout is still being set up (waiting for a sandbox key). Browse the store's products; try checkout again later.";
|
|
29
|
+
/**
|
|
30
|
+
* For the store's builder (a person or coding agent), never shown to shoppers:
|
|
31
|
+
* setup isn't finished, and the doctor lists what to do next.
|
|
32
|
+
*/
|
|
33
|
+
export const DEVELOPER_HINT = "Store setup is not done. Run: npx @relyon/store-kit doctor";
|
|
34
|
+
/** A configuration TypeError (message unchanged) that also carries the builder-facing hint. */
|
|
35
|
+
export function setupError(message) {
|
|
36
|
+
return Object.assign(new TypeError(message), { developer_hint: DEVELOPER_HINT });
|
|
37
|
+
}
|
|
38
|
+
/** The comment robots.txt starts with while the kit waits. */
|
|
39
|
+
export const WAITING_TEXT_MARKER = `# Relyon store kit: ${WAITING_STATUS}`;
|
|
40
|
+
export function waitingResponse() {
|
|
41
|
+
return jsonResponse(503, { status: WAITING_STATUS, code: WAITING_CODE, message: WAITING_MESSAGE, developer_hint: DEVELOPER_HINT }, {
|
|
42
|
+
"cache-control": "no-store", "retry-after": String(WAITING_RETRY_AFTER_SECONDS), [WAITING_STATUS_HEADER]: WAITING_STATUS,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Adds an XML comment with the waiting status right after the XML declaration. */
|
|
46
|
+
export function withWaitingXmlMarker(xml, waiting) {
|
|
47
|
+
if (!waiting)
|
|
48
|
+
return xml;
|
|
49
|
+
const declaration = /^<\?xml[^>]*\?>\n?/.exec(xml);
|
|
50
|
+
const comment = `<!-- relyon: ${WAITING_STATUS} -->\n`;
|
|
51
|
+
return declaration ? `${declaration[0]}${declaration[0].endsWith("\n") ? "" : "\n"}${comment}${xml.slice(declaration[0].length)}` : `${comment}${xml}`;
|
|
52
|
+
}
|
|
53
|
+
/** True for a body the kit answers while waiting (used by the doctor). */
|
|
54
|
+
export function isWaitingBody(value) {
|
|
55
|
+
return typeof value === "object" && value !== null && value.status === WAITING_STATUS
|
|
56
|
+
&& value.code === WAITING_CODE;
|
|
57
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type FetchLike } from "./relyon.js";
|
|
2
|
+
export { webhookRegistrationKey, webhookRotationKey, WEBHOOK_EVENTS } from "./webhook-registration.js";
|
|
3
|
+
export declare const WEBHOOK_COMMAND = "npx @relyon/store-kit webhook";
|
|
4
|
+
export declare const DEFAULT_WEBHOOK_PATH = "/relyon/webhooks";
|
|
5
|
+
export declare const WEBHOOK_NO_KEY_LIVE = "webhook in Live mode needs the store's Live key (rly_live_\u2026) set as RELYON_API_KEY in the host's environment settings \u2014 never a file, and never pasted into a command. (A Test key, a missing key, or a saved key file can't run Live.)";
|
|
6
|
+
export declare const WEBHOOK_NO_KEY = "webhook needs the store's Test key (rly_test_\u2026): run `npx @relyon/store-kit init` first (it saves the key privately). Never paste the key into a command.";
|
|
7
|
+
/** Init's line when registration couldn't run: deferred, never a failure. */
|
|
8
|
+
export declare const WEBHOOK_DEFERRED_LINE = "Webhook registration is deferred: after publish, run `npx @relyon/store-kit webhook` to register the store's webhook endpoint. With an environment API key nothing is saved; local file-key development saves the signing secret privately.";
|
|
9
|
+
export declare const WEBHOOK_RUNTIME_LINE = "Webhook registered. The signing secret is resolved at runtime from RELYON_API_KEY; nothing was saved to a file.";
|
|
10
|
+
/** Live rotation warning: rotating replaces the signing secret everywhere the old one is used. */
|
|
11
|
+
export declare const WEBHOOK_ROTATE_LIVE_WARNING = "Warning: rotating issues a new signing secret; anything else using the endpoint's old secret will stop verifying.";
|
|
12
|
+
export interface WebhookCommandOptions {
|
|
13
|
+
storeUrl: string;
|
|
14
|
+
/** RELYON_API_KEY as given (may be a placeholder, a Live key or absent). */
|
|
15
|
+
envKey?: string | undefined;
|
|
16
|
+
/** The saved Test key (init's private folder or .env); read by the caller only when not Live. */
|
|
17
|
+
savedKey?: string | undefined;
|
|
18
|
+
live: boolean;
|
|
19
|
+
baseUrl?: string | undefined;
|
|
20
|
+
webhookPath?: string | undefined;
|
|
21
|
+
/** Register a fresh endpoint and secret for the same URL (only when the saved secret was lost). */
|
|
22
|
+
rotate?: boolean | undefined;
|
|
23
|
+
allowSavedKeyToBaseUrl?: boolean | undefined;
|
|
24
|
+
/** The project whose .env receives the secret. Default: the current directory. */
|
|
25
|
+
project?: string | undefined;
|
|
26
|
+
/** Server environment. Default: process.env. */
|
|
27
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
28
|
+
fetch?: FetchLike | undefined;
|
|
29
|
+
timeoutMs?: number | undefined;
|
|
30
|
+
}
|
|
31
|
+
export interface WebhookCommandResult {
|
|
32
|
+
exitCode: 0 | 1 | 2;
|
|
33
|
+
lines: string[];
|
|
34
|
+
}
|
|
35
|
+
/** Runs the command. Never throws; every line is terminal-safe and redacted, and never holds the secret. */
|
|
36
|
+
export declare function runWebhookCommand(options: WebhookCommandOptions): Promise<WebhookCommandResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Init's best-effort registration when STORE_PUBLIC_URL is known: one outcome
|
|
39
|
+
* line (runtime resolution, local-dev saving, or the deferral). Never throws, never
|
|
40
|
+
* carries the secret, and never changes init's exit code.
|
|
41
|
+
*/
|
|
42
|
+
export declare function initWebhookRegistration(options: {
|
|
43
|
+
project: string;
|
|
44
|
+
storeUrl: string;
|
|
45
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
46
|
+
baseUrl?: string | undefined;
|
|
47
|
+
fetch?: FetchLike | undefined;
|
|
48
|
+
}): Promise<string>;
|