@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,57 @@
|
|
|
1
|
+
import { KIT_VERIFIED_CHECK_IDS, checkIdForItem } from "./checklist-manifest.js";
|
|
2
|
+
/** Outcome-only advisory metadata. Never includes details, URLs or secrets. */
|
|
3
|
+
export { KIT_OUTCOMES_HEADER } from "./wire-names.js";
|
|
4
|
+
/**
|
|
5
|
+
* The wire vocabulary of a kit-reported outcome. Server-verified checks are
|
|
6
|
+
* excluded: Relyon observes those itself, and the evidence header is sent
|
|
7
|
+
* before the remote doctor's answer exists, so a kit-side verdict for them
|
|
8
|
+
* would be provisional — with one exception: the domain-gated rows the kit
|
|
9
|
+
* probes locally on the store (UCP profile, MCP, llms.txt, sitemap, feeds,
|
|
10
|
+
* robots.txt). On a preview address or a pending domain the server never
|
|
11
|
+
* probes the store, so its only verdict is not-applicable or absent; the
|
|
12
|
+
* kit's local verdict fills exactly that gap (server-observed outcomes stay
|
|
13
|
+
* authoritative whenever they exist). Keep in step with the server's
|
|
14
|
+
* fallback allowlist (kit-evidence.ts in the API server).
|
|
15
|
+
*/
|
|
16
|
+
export const KIT_FALLBACK_CHECK_IDS = [
|
|
17
|
+
"ucp-profile", "mcp-initialize", "llms-txt", "product-sitemap", "product-feeds", "robots-txt",
|
|
18
|
+
];
|
|
19
|
+
const KIT_IDS = new Set([...KIT_VERIFIED_CHECK_IDS, ...KIT_FALLBACK_CHECK_IDS]);
|
|
20
|
+
const STATUSES = new Set(["PASS", "FAIL", "WARN", "PENDING", "N/A", "UNVERIFIED", "NOT DONE"]);
|
|
21
|
+
/** The evidence caps: at most this many entries and this many bytes. */
|
|
22
|
+
export const KIT_EVIDENCE_LIMITS = { entries: 40, bytes: 4096 };
|
|
23
|
+
/**
|
|
24
|
+
* Maps a doctor item's printed status onto the stored outcome vocabulary
|
|
25
|
+
* (pass/fail/warn/pending/not_applicable/unverified). WARN and N/A keep their
|
|
26
|
+
* meaning. NOT DONE (a required step Relyon has not recorded yet) normalizes
|
|
27
|
+
* to "pending" — deliberately not "fail": it is unfinished work, not an
|
|
28
|
+
* observed defect, and legacy stored rows already use "pending" for it.
|
|
29
|
+
*/
|
|
30
|
+
function outcomeFor(status) {
|
|
31
|
+
switch (status) {
|
|
32
|
+
case "PASS": return "pass";
|
|
33
|
+
case "FAIL": return "fail";
|
|
34
|
+
case "WARN": return "warn";
|
|
35
|
+
case "PENDING": return "pending";
|
|
36
|
+
case "N/A": return "not_applicable";
|
|
37
|
+
case "UNVERIFIED": return "unverified";
|
|
38
|
+
case "NOT DONE": return "pending";
|
|
39
|
+
default: return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function kitOutcomeMetadata(items) {
|
|
43
|
+
const outcomes = [];
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
const id = item.checkId ?? checkIdForItem(item.name);
|
|
47
|
+
if (!id || !KIT_IDS.has(id))
|
|
48
|
+
continue;
|
|
49
|
+
const outcome = outcomeFor(item.status);
|
|
50
|
+
if (seen.has(id) || outcome === undefined || !STATUSES.has(item.status))
|
|
51
|
+
return undefined;
|
|
52
|
+
seen.add(id);
|
|
53
|
+
outcomes.push([id, outcome]);
|
|
54
|
+
}
|
|
55
|
+
const value = JSON.stringify(outcomes);
|
|
56
|
+
return outcomes.length <= KIT_EVIDENCE_LIMITS.entries && value.length <= KIT_EVIDENCE_LIMITS.bytes ? value : undefined;
|
|
57
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { StorePolicies } from "./setup.js";
|
|
2
|
+
declare const POLICY_FIXES: {
|
|
3
|
+
readonly returns: `Set returns with window_days (0-365) and cost (free, buyer_pays or fixed) in PUT ${string}.`;
|
|
4
|
+
readonly "returns.policy_url": `Set returns.policy_url to the absolute https:// URL of the store's public returns policy page in PUT ${string}.`;
|
|
5
|
+
readonly support: `Set support.email (an email address) or support.url (an absolute https:// URL) in PUT ${string}.`;
|
|
6
|
+
};
|
|
7
|
+
type PolicyField = keyof typeof POLICY_FIXES;
|
|
8
|
+
export declare const MERCHANT_QUESTIONS: Record<PolicyField, string>;
|
|
9
|
+
/** How every merchant-pending item starts: facts only the store's owner can give. */
|
|
10
|
+
export declare const OWNER_TO_FILL_IN = "Owner to fill in:";
|
|
11
|
+
/** The explicit line for coding agents next to merchant-pending items. */
|
|
12
|
+
export declare const DO_NOT_INVENT = "Agents: do not invent these (policies, support email, domain); ask the store's owner and leave them pending until the owner answers.";
|
|
13
|
+
/** Doctor's closing line for coding agents: owner to-dos go in the final chat message; no premature "shoppers can pay". */
|
|
14
|
+
export declare const FINAL_MESSAGE_TODOS = "Agents: in your final chat message to the owner (not only in a README), list the owner's to-dos: policies, support contact, domain and Live keys. Never tell the owner shoppers can pay until checkout is live.";
|
|
15
|
+
export declare const AGENT_CHECKOUT_OFF = "Agent checkout remains unavailable until merchant confirmation and policy setup; the kit never assumes free returns or a return cost.";
|
|
16
|
+
export declare function pendingPolicyFields(policies: StorePolicies | undefined, live: boolean): PolicyField[];
|
|
17
|
+
/** Match the entire projection AND its completeness fixes; no legacy, extra or invalid-field blockers are discarded. */
|
|
18
|
+
export declare function policyOnlyFailure(failure: {
|
|
19
|
+
check: string;
|
|
20
|
+
code: string;
|
|
21
|
+
explanation: string;
|
|
22
|
+
fix: string;
|
|
23
|
+
}, policies: StorePolicies | undefined): boolean;
|
|
24
|
+
/** The agent-step marking on every domain-verification PENDING line and its next-step action. */
|
|
25
|
+
export declare const AGENT_DOMAIN_STEP: (hostname: string) => string;
|
|
26
|
+
/** Match the entire pending-domain-only catalog projection; nothing else may be folded in. */
|
|
27
|
+
export declare function domainPendingOnlyFailure(failure: {
|
|
28
|
+
check: string;
|
|
29
|
+
code: string;
|
|
30
|
+
explanation: string;
|
|
31
|
+
fix: string;
|
|
32
|
+
}): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* A catalog check_unavailable whose explanation positively reads as the
|
|
35
|
+
* adapter's plain "could not complete" — and carries no store-first markers
|
|
36
|
+
* (Observed blocker / Unverified / Fixture only / Required condition:) and no
|
|
37
|
+
* legacy fold-in — is a transient condition (a slow first read, a restarting
|
|
38
|
+
* dependency), not an observed store defect. The kit retries it briefly and
|
|
39
|
+
* reports it UNVERIFIED, never FAIL; Core stores the matching "unverified"
|
|
40
|
+
* outcome. A marker-less projection in any other wording (a hand-trimmed
|
|
41
|
+
* policy blocker, an unknown adapter phrase) fails closed and stays FAIL.
|
|
42
|
+
*/
|
|
43
|
+
export declare function transientCatalogFailure(failure: {
|
|
44
|
+
check: string;
|
|
45
|
+
code: string;
|
|
46
|
+
explanation: string;
|
|
47
|
+
}): boolean;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { LEGACY_PROJECT_SPACE_POLICIES_PATH, PROJECT_SPACE_POLICIES_PATH } from "./wire-names.js";
|
|
2
|
+
// This is an intentionally exact reader of the existing public doctor's prose
|
|
3
|
+
// projection, not a new server contract. Unknown grammar stays a failure. The
|
|
4
|
+
// prose names the policies path under its new or its deprecated name; each
|
|
5
|
+
// projection is read under one name throughout, never a mix.
|
|
6
|
+
const policyFixes = (path) => ({
|
|
7
|
+
returns: `Set returns with window_days (0-365) and cost (free, buyer_pays or fixed) in PUT ${path}.`,
|
|
8
|
+
"returns.policy_url": `Set returns.policy_url to the absolute https:// URL of the store's public returns policy page in PUT ${path}.`,
|
|
9
|
+
support: `Set support.email (an email address) or support.url (an absolute https:// URL) in PUT ${path}.`,
|
|
10
|
+
});
|
|
11
|
+
const POLICY_FIXES = policyFixes(PROJECT_SPACE_POLICIES_PATH);
|
|
12
|
+
const POLICY_FIX_SPELLINGS = [POLICY_FIXES, policyFixes(LEGACY_PROJECT_SPACE_POLICIES_PATH)];
|
|
13
|
+
export const MERCHANT_QUESTIONS = {
|
|
14
|
+
returns: "What return window, eligible items and return cost does the merchant confirm?",
|
|
15
|
+
"returns.policy_url": "Which published HTTPS returns-policy page does the merchant confirm?",
|
|
16
|
+
support: "Which support contact or HTTPS contact page does the merchant confirm?",
|
|
17
|
+
};
|
|
18
|
+
/** How every merchant-pending item starts: facts only the store's owner can give. */
|
|
19
|
+
export const OWNER_TO_FILL_IN = "Owner to fill in:";
|
|
20
|
+
/** The explicit line for coding agents next to merchant-pending items. */
|
|
21
|
+
export const DO_NOT_INVENT = "Agents: do not invent these (policies, support email, domain); ask the store's owner and leave them pending until the owner answers.";
|
|
22
|
+
/** Doctor's closing line for coding agents: owner to-dos go in the final chat message; no premature "shoppers can pay". */
|
|
23
|
+
export const FINAL_MESSAGE_TODOS = "Agents: in your final chat message to the owner (not only in a README), list the owner's to-dos: policies, support contact, domain and Live keys. Never tell the owner shoppers can pay until checkout is live.";
|
|
24
|
+
export const AGENT_CHECKOUT_OFF = "Agent checkout remains unavailable until merchant confirmation and policy setup; the kit never assumes free returns or a return cost.";
|
|
25
|
+
export function pendingPolicyFields(policies, live) {
|
|
26
|
+
if (!policies || policies.livemode !== live || policies.complete !== false || !Array.isArray(policies.missing)
|
|
27
|
+
|| !policies.missing.length || new Set(policies.missing).size !== policies.missing.length
|
|
28
|
+
|| !policies.missing.every(field => Object.hasOwn(POLICY_FIXES, field)))
|
|
29
|
+
return [];
|
|
30
|
+
return policies.missing;
|
|
31
|
+
}
|
|
32
|
+
const PREVIEW_NOTE = "Test on preview address: the store runs agent checkout in Test on its preview address, so the domain checks don't apply yet."
|
|
33
|
+
+ " Live still needs a published, verified domain: publish the app, add and verify its domain in Relyon, then switch to a Live key only with the merchant's approval.";
|
|
34
|
+
const POLICY_BLOCKER = "Observed blocker; required condition not met: Required condition: Store return and support policies are complete and valid. Required evidence: Scoped policy validation and completeness assessment.";
|
|
35
|
+
/** Match the entire projection AND its completeness fixes; no legacy, extra or invalid-field blockers are discarded. */
|
|
36
|
+
export function policyOnlyFailure(failure, policies) {
|
|
37
|
+
const missing = pendingPolicyFields(policies, false);
|
|
38
|
+
return missing.length > 0 && failure.check === "catalog" && failure.code === "check_unavailable"
|
|
39
|
+
&& (failure.explanation === POLICY_BLOCKER || failure.explanation === `${PREVIEW_NOTE} ${POLICY_BLOCKER}`)
|
|
40
|
+
&& POLICY_FIX_SPELLINGS.some(fixes => failure.fix === missing.map(field => `${field} is missing: ${fixes[field]}`).join(" "));
|
|
41
|
+
}
|
|
42
|
+
/** The agent-step marking on every domain-verification PENDING line and its next-step action. */
|
|
43
|
+
export const AGENT_DOMAIN_STEP = (hostname) => `Agent step, not the owner's: run kit.ensureDomain() then kit.verifyDomain(${JSON.stringify(hostname)}) from the store now, then re-run the doctor. Do not hand this to the owner.`;
|
|
44
|
+
// The same exact-projection reader for the pending-domain catalog signal: the
|
|
45
|
+
// server marks it by replacing the domain_owned fix with the verifyDomain
|
|
46
|
+
// step only when it positively observed a registered, file-serving pending
|
|
47
|
+
// domain; any other content (legacy fold-ins, extra blockers, a transient
|
|
48
|
+
// check_unavailable) stays a failure.
|
|
49
|
+
// The collector marks the pending-domain finding by swapping its fix for the
|
|
50
|
+
// verifyDomain step; its status stays "fail" (the domain is positively
|
|
51
|
+
// registered but unverified), so the projection reads "Observed blocker".
|
|
52
|
+
const DOMAIN_BLOCKER = "Observed blocker; required condition not met: Required condition: One unambiguous store domain is verified. Required evidence: Exactly one scoped verified hostname; domain reads require a member session.";
|
|
53
|
+
const DOMAIN_PENDING_FIX = /^Run kit\.verifyDomain\("[^"]+"\), then rerun npx @relyon\/store-kit doctor\.$/;
|
|
54
|
+
/** Match the entire pending-domain-only catalog projection; nothing else may be folded in. */
|
|
55
|
+
export function domainPendingOnlyFailure(failure) {
|
|
56
|
+
return failure.check === "catalog" && failure.code === "check_unavailable"
|
|
57
|
+
&& (failure.explanation === DOMAIN_BLOCKER || failure.explanation === `${PREVIEW_NOTE} ${DOMAIN_BLOCKER}`)
|
|
58
|
+
&& DOMAIN_PENDING_FIX.test(failure.fix);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A catalog check_unavailable whose explanation positively reads as the
|
|
62
|
+
* adapter's plain "could not complete" — and carries no store-first markers
|
|
63
|
+
* (Observed blocker / Unverified / Fixture only / Required condition:) and no
|
|
64
|
+
* legacy fold-in — is a transient condition (a slow first read, a restarting
|
|
65
|
+
* dependency), not an observed store defect. The kit retries it briefly and
|
|
66
|
+
* reports it UNVERIFIED, never FAIL; Core stores the matching "unverified"
|
|
67
|
+
* outcome. A marker-less projection in any other wording (a hand-trimmed
|
|
68
|
+
* policy blocker, an unknown adapter phrase) fails closed and stays FAIL.
|
|
69
|
+
*/
|
|
70
|
+
export function transientCatalogFailure(failure) {
|
|
71
|
+
return failure.check === "catalog" && failure.code === "check_unavailable"
|
|
72
|
+
&& /could not complete/i.test(failure.explanation)
|
|
73
|
+
&& !/Observed blocker|Unverified|Fixture only|Required condition:|Legacy compatibility check/.test(failure.explanation);
|
|
74
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const GATED_KIT_WARNING = "Mount the kit always; it waits safely without a key.";
|
|
2
|
+
/** True when the source creates or mounts the kit only when RELYON_API_KEY is set. */
|
|
3
|
+
export declare function gatesKitOnKey(text: string): boolean;
|
|
4
|
+
/** Project-relative source files that gate the kit on RELYON_API_KEY. */
|
|
5
|
+
export declare function findGatedKitMounts(project: string): Promise<string[]>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { open, readdir } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Best-effort source check for the doctor: finds where the store's code
|
|
6
|
+
* creates or mounts the kit only when RELYON_API_KEY is set (an `if` on it, a
|
|
7
|
+
* `RELYON_API_KEY ? … : …` or `RELYON_API_KEY && …`, or an early return or
|
|
8
|
+
* throw on it before the kit is created). Such an app serves no kit route
|
|
9
|
+
* before a key exists, so its catch-all page answers them instead.
|
|
10
|
+
*
|
|
11
|
+
* Only reads: skips links found while listing, opens files without following
|
|
12
|
+
* a final link, skips dependencies, build output and hidden folders, and stops
|
|
13
|
+
* after a bounded number of directories, files and bytes. It returns
|
|
14
|
+
* project-relative file names, never file contents. (A folder swapped for a
|
|
15
|
+
* link while the scan runs can still be entered; the scan reports only names
|
|
16
|
+
* and runs on the developer's own project, so that is accepted.)
|
|
17
|
+
*/
|
|
18
|
+
const KIT_CALL = /\b(?:createStoreKit|storeKitMiddleware|storeKitRouteHandlers|storeKitFetch)\s*\(/g;
|
|
19
|
+
const SOURCE_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
20
|
+
// Dependencies, build output and tests: none of them is where the store mounts the kit.
|
|
21
|
+
const SKIPPED = new Set(["node_modules", "dist", "build", "out", "coverage", ".next", ".git", "test", "tests", "__tests__", "e2e", "fixtures"]);
|
|
22
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
|
|
23
|
+
const MAX_FILES = 3000;
|
|
24
|
+
const MAX_FILE_BYTES = 512 * 1024;
|
|
25
|
+
const MAX_DEPTH = 8;
|
|
26
|
+
const MAX_DIRS = 2000;
|
|
27
|
+
export const GATED_KIT_WARNING = "Mount the kit always; it waits safely without a key.";
|
|
28
|
+
/** The end index of the statement or block that starts at `from` (an `if` body). */
|
|
29
|
+
function bodyEnd(text, from) {
|
|
30
|
+
let index = from;
|
|
31
|
+
while (index < text.length && /\s/.test(text[index]))
|
|
32
|
+
index++;
|
|
33
|
+
if (text[index] !== "{") {
|
|
34
|
+
const end = text.indexOf(";", index);
|
|
35
|
+
const line = text.indexOf("\n", index);
|
|
36
|
+
return Math.max(end === -1 ? text.length : end, line === -1 ? text.length : line);
|
|
37
|
+
}
|
|
38
|
+
let depth = 0;
|
|
39
|
+
for (; index < text.length; index++) {
|
|
40
|
+
if (text[index] === "{")
|
|
41
|
+
depth++;
|
|
42
|
+
else if (text[index] === "}" && --depth === 0)
|
|
43
|
+
return index;
|
|
44
|
+
}
|
|
45
|
+
return text.length;
|
|
46
|
+
}
|
|
47
|
+
/** The end of an `if (` condition: the index just after its closing parenthesis. */
|
|
48
|
+
function conditionEnd(text, open) {
|
|
49
|
+
let depth = 0;
|
|
50
|
+
for (let index = open; index < text.length && index < open + 2000; index++) {
|
|
51
|
+
if (text[index] === "(")
|
|
52
|
+
depth++;
|
|
53
|
+
else if (text[index] === ")" && --depth === 0)
|
|
54
|
+
return index + 1;
|
|
55
|
+
}
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
/** True when the source creates or mounts the kit only when RELYON_API_KEY is set. */
|
|
59
|
+
export function gatesKitOnKey(text) {
|
|
60
|
+
if (!text.includes("RELYON_API_KEY"))
|
|
61
|
+
return false;
|
|
62
|
+
const calls = [...text.matchAll(KIT_CALL)].map((match) => match.index);
|
|
63
|
+
if (!calls.length)
|
|
64
|
+
return false;
|
|
65
|
+
for (const match of text.matchAll(/\bif\s*\(/g)) {
|
|
66
|
+
const open = match.index + match[0].length - 1;
|
|
67
|
+
const close = conditionEnd(text, open);
|
|
68
|
+
if (close === -1 || !text.slice(open, close).includes("RELYON_API_KEY"))
|
|
69
|
+
continue;
|
|
70
|
+
const end = bodyEnd(text, close);
|
|
71
|
+
const body = text.slice(close, end);
|
|
72
|
+
// The kit is created or mounted inside the condition.
|
|
73
|
+
if (calls.some((call) => call > close && call < end))
|
|
74
|
+
return true;
|
|
75
|
+
// Or the code leaves before the kit is created when there is no key.
|
|
76
|
+
const noKey = /!\s*(?:[\w$.]*\.)?RELYON_API_KEY\b|RELYON_API_KEY\s*[!=]==?\s*(?:undefined|null|""|'')/.test(text.slice(open, close));
|
|
77
|
+
if (noKey && /\b(?:return|throw)\b|process\.exit\s*\(/.test(body) && calls.some((call) => call > end))
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
// Same-line conditional forms: KEY ? createStoreKit(…) : …, KEY && app.use(storeKitMiddleware(…)).
|
|
81
|
+
for (const line of text.split("\n")) {
|
|
82
|
+
if (!line.includes("RELYON_API_KEY") || !/\b(?:createStoreKit|storeKitMiddleware|storeKitRouteHandlers|storeKitFetch)\s*\(/.test(line))
|
|
83
|
+
continue;
|
|
84
|
+
const after = line.slice(line.indexOf("RELYON_API_KEY"));
|
|
85
|
+
if (/^[^;]*?(?:&&|(?<!\?)\?(?![?.]))[^;]*\b(?:createStoreKit|storeKitMiddleware|storeKitRouteHandlers|storeKitFetch)\s*\(/.test(after))
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
/** Project-relative source files that gate the kit on RELYON_API_KEY. */
|
|
91
|
+
export async function findGatedKitMounts(project) {
|
|
92
|
+
const found = [];
|
|
93
|
+
let files = 0;
|
|
94
|
+
let dirs = 0;
|
|
95
|
+
const walk = async (dir, depth) => {
|
|
96
|
+
if (depth > MAX_DEPTH || files >= MAX_FILES || ++dirs > MAX_DIRS)
|
|
97
|
+
return;
|
|
98
|
+
let entries;
|
|
99
|
+
try {
|
|
100
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const entry of entries) {
|
|
106
|
+
if (files >= MAX_FILES)
|
|
107
|
+
return;
|
|
108
|
+
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
109
|
+
continue;
|
|
110
|
+
const full = path.join(dir, entry.name);
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
await walk(full, depth + 1);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!entry.isFile() || !SOURCE_FILE.test(entry.name) || /\.d\.[cm]?ts$/.test(entry.name) || TEST_FILE.test(entry.name))
|
|
116
|
+
continue;
|
|
117
|
+
files++;
|
|
118
|
+
try {
|
|
119
|
+
// O_NOFOLLOW + checks on the opened file: a file swapped for a link after
|
|
120
|
+
// readdir is not followed, and a file that grows is read only up to the cap.
|
|
121
|
+
const handle = await open(full, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
122
|
+
try {
|
|
123
|
+
const stat = await handle.stat();
|
|
124
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES)
|
|
125
|
+
continue;
|
|
126
|
+
const buffer = Buffer.alloc(MAX_FILE_BYTES + 1);
|
|
127
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
128
|
+
if (bytesRead > MAX_FILE_BYTES)
|
|
129
|
+
continue;
|
|
130
|
+
if (gatesKitOnKey(buffer.subarray(0, bytesRead).toString("utf8")))
|
|
131
|
+
found.push(path.relative(project, full).split(path.sep).join("/"));
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await handle.close();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch { /* unreadable or a link: skip */ }
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
await walk(project, 0);
|
|
141
|
+
return found.sort();
|
|
142
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** One product as the store's MCP search_products returns it (the fields doctor reads). */
|
|
2
|
+
export interface McpProductSummary {
|
|
3
|
+
product_id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
configurable: boolean;
|
|
6
|
+
/** false when agents may see but not buy it; absent from stores on kit 0.1.10 and earlier. */
|
|
7
|
+
purchasable?: boolean;
|
|
8
|
+
availability?: string;
|
|
9
|
+
price?: {
|
|
10
|
+
amount: number;
|
|
11
|
+
currency: string;
|
|
12
|
+
};
|
|
13
|
+
group_id?: string;
|
|
14
|
+
variants?: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
options: Record<string, unknown>;
|
|
17
|
+
price?: {
|
|
18
|
+
amount: number;
|
|
19
|
+
currency: string;
|
|
20
|
+
};
|
|
21
|
+
availability?: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
type Get = (path: string, init?: {
|
|
25
|
+
method?: string;
|
|
26
|
+
body?: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
status: number;
|
|
30
|
+
type: string;
|
|
31
|
+
text: string;
|
|
32
|
+
} | Error>;
|
|
33
|
+
/** The store's agent-visible products from `POST /mcp` search_products (up to 50), or an Error saying why not. */
|
|
34
|
+
export declare function readMcpProducts(get: Get): Promise<McpProductSummary[] | Error>;
|
|
35
|
+
/** At most this many items are tried before the cart-transfer row is NOT DONE. */
|
|
36
|
+
export declare const TRANSFER_ATTEMPTS = 5;
|
|
37
|
+
/**
|
|
38
|
+
* The items doctor may transfer, in the order it tries them: the first
|
|
39
|
+
* in-stock variant of each configurable product, then each product without
|
|
40
|
+
* options that is in stock. Items agents may not buy (`purchasable: false`)
|
|
41
|
+
* and configurable products without a usable variant are skipped, because
|
|
42
|
+
* /ucp/carts refuses them.
|
|
43
|
+
*/
|
|
44
|
+
export declare function transferCandidates(products: readonly McpProductSummary[]): Array<{
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
}>;
|
|
48
|
+
/** The first item doctor would transfer, or null when none can be sold. */
|
|
49
|
+
export declare function transferItem(products: readonly McpProductSummary[]): {
|
|
50
|
+
id: string;
|
|
51
|
+
label: string;
|
|
52
|
+
} | null;
|
|
53
|
+
/** The checkout page marker: the kit's card fields mount, and the cart item count attribute (null when absent). */
|
|
54
|
+
export declare function checkoutMarker(html: string): {
|
|
55
|
+
cardFields: boolean;
|
|
56
|
+
items: number | null;
|
|
57
|
+
};
|
|
58
|
+
/** The marker as doctor's details describe it. */
|
|
59
|
+
export declare const CHECKOUT_MARKER_FIX = "render data-relyon-cart-items=\"<number of items in the cart>\" (0 when empty) on an element of the checkout page, or the kit's <relyon-card-fields> mount. See \"Checkout page marker\" in the relyon-checkout skill.";
|
|
60
|
+
export interface VariantsRow {
|
|
61
|
+
status: "PASS" | "NOT DONE" | "N/A";
|
|
62
|
+
detail: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The variants row: NOT DONE (a warning for agents) when an agent-visible
|
|
66
|
+
* product has options but no feed.variants, or when options look flattened
|
|
67
|
+
* into separate ungrouped listings with different prices.
|
|
68
|
+
*/
|
|
69
|
+
export declare function variantsCheck(products: readonly McpProductSummary[] | Error): VariantsRow;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { CHECKOUT_CART_ITEMS_ATTRIBUTE } from "./checkout.js";
|
|
2
|
+
import { isRecord } from "./util.js";
|
|
3
|
+
/** The store's agent-visible products from `POST /mcp` search_products (up to 50), or an Error saying why not. */
|
|
4
|
+
export async function readMcpProducts(get) {
|
|
5
|
+
const result = await get("/mcp", {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
|
|
8
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: "doctor-products", method: "tools/call", params: { name: "search_products", arguments: { query: "", limit: 50 } } }),
|
|
9
|
+
});
|
|
10
|
+
if (result instanceof Error)
|
|
11
|
+
return new Error(`/mcp search_products: ${result.message}`);
|
|
12
|
+
if (result.status !== 200)
|
|
13
|
+
return new Error(`/mcp search_products answered ${result.status}`);
|
|
14
|
+
let message;
|
|
15
|
+
try {
|
|
16
|
+
message = result.type.includes("text/event-stream")
|
|
17
|
+
? JSON.parse(result.text.split("\n").find((line) => line.startsWith("data: "))?.slice(6) ?? "null")
|
|
18
|
+
: JSON.parse(result.text);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
message = undefined;
|
|
22
|
+
}
|
|
23
|
+
const structured = isRecord(message) && isRecord(message.result) && isRecord(message.result.structuredContent) ? message.result.structuredContent : undefined;
|
|
24
|
+
if (!structured || !Array.isArray(structured.products))
|
|
25
|
+
return new Error("/mcp search_products returned no structuredContent.products");
|
|
26
|
+
return structured.products.filter((product) => isRecord(product) && typeof product.product_id === "string" && typeof product.title === "string")
|
|
27
|
+
.map((product) => ({ ...product, configurable: product.configurable === true }));
|
|
28
|
+
}
|
|
29
|
+
/** At most this many items are tried before the cart-transfer row is NOT DONE. */
|
|
30
|
+
export const TRANSFER_ATTEMPTS = 5;
|
|
31
|
+
/**
|
|
32
|
+
* The items doctor may transfer, in the order it tries them: the first
|
|
33
|
+
* in-stock variant of each configurable product, then each product without
|
|
34
|
+
* options that is in stock. Items agents may not buy (`purchasable: false`)
|
|
35
|
+
* and configurable products without a usable variant are skipped, because
|
|
36
|
+
* /ucp/carts refuses them.
|
|
37
|
+
*/
|
|
38
|
+
export function transferCandidates(products) {
|
|
39
|
+
const sellable = products.filter((product) => product.purchasable !== false && product.availability !== "out_of_stock");
|
|
40
|
+
const variants = [];
|
|
41
|
+
for (const product of sellable) {
|
|
42
|
+
if (!product.configurable || !Array.isArray(product.variants))
|
|
43
|
+
continue;
|
|
44
|
+
const variant = product.variants.find((entry) => isRecord(entry) && typeof entry.id === "string" && entry.id !== "" && isRecord(entry.options) && entry.availability !== "out_of_stock");
|
|
45
|
+
if (variant)
|
|
46
|
+
variants.push({ id: variant.id, label: `variant ${JSON.stringify(variant.id)} of ${JSON.stringify(product.product_id)}` });
|
|
47
|
+
}
|
|
48
|
+
const plain = sellable.filter((product) => !product.configurable).map((product) => ({ id: product.product_id, label: `product ${JSON.stringify(product.product_id)}` }));
|
|
49
|
+
return [...variants, ...plain];
|
|
50
|
+
}
|
|
51
|
+
/** The first item doctor would transfer, or null when none can be sold. */
|
|
52
|
+
export function transferItem(products) {
|
|
53
|
+
return transferCandidates(products)[0] ?? null;
|
|
54
|
+
}
|
|
55
|
+
/** The checkout page marker: the kit's card fields mount, and the cart item count attribute (null when absent). */
|
|
56
|
+
export function checkoutMarker(html) {
|
|
57
|
+
const cardFields = /<relyon-card-fields[\s>]/i.test(html);
|
|
58
|
+
const match = new RegExp(`\\b${CHECKOUT_CART_ITEMS_ATTRIBUTE}\\s*=\\s*["']?(\\d{1,6})\\b`, "i").exec(html);
|
|
59
|
+
return { cardFields, items: match ? Number(match[1]) : null };
|
|
60
|
+
}
|
|
61
|
+
/** The marker as doctor's details describe it. */
|
|
62
|
+
export const CHECKOUT_MARKER_FIX = `render ${CHECKOUT_CART_ITEMS_ATTRIBUTE}="<number of items in the cart>" (0 when empty) on an element of the checkout page, or the kit's <relyon-card-fields> mount. See "Checkout page marker" in the relyon-checkout skill.`;
|
|
63
|
+
/** A listing title's base, when it ends in what reads as one option value ("Tee - XL", "Tee / Black", "Tee (2XL)"). */
|
|
64
|
+
function titleBase(title) {
|
|
65
|
+
const match = /^(.{2,}?)\s*(?:\s[-–—/|]\s|,\s|\s\()\s*([^-–—/|,()]{1,20})\)?\s*$/.exec(title.trim());
|
|
66
|
+
return match ? match[1].trim().toLowerCase() : null;
|
|
67
|
+
}
|
|
68
|
+
const VARIANT_FIX = "list each size/colour choice in the product's feed.variants (feed ID, options, price) on one configurable product, as in the relyon-catalog skill's Tee example";
|
|
69
|
+
/**
|
|
70
|
+
* The variants row: NOT DONE (a warning for agents) when an agent-visible
|
|
71
|
+
* product has options but no feed.variants, or when options look flattened
|
|
72
|
+
* into separate ungrouped listings with different prices.
|
|
73
|
+
*/
|
|
74
|
+
export function variantsCheck(products) {
|
|
75
|
+
if (products instanceof Error)
|
|
76
|
+
return { status: "N/A", detail: `Not checked: ${products.message}.` };
|
|
77
|
+
const bare = products.filter((product) => product.configurable && !(Array.isArray(product.variants) && product.variants.length));
|
|
78
|
+
const groups = new Map();
|
|
79
|
+
for (const product of products) {
|
|
80
|
+
if (product.configurable || product.group_id)
|
|
81
|
+
continue;
|
|
82
|
+
const base = titleBase(product.title);
|
|
83
|
+
if (base)
|
|
84
|
+
groups.set(base, [...groups.get(base) ?? [], product]);
|
|
85
|
+
}
|
|
86
|
+
const flattened = [...groups.values()].filter((group) => group.length > 1
|
|
87
|
+
&& new Set(group.map((product) => product.price ? `${product.price.amount} ${product.price.currency}` : "")).size > 1);
|
|
88
|
+
const problems = [];
|
|
89
|
+
if (bare.length) {
|
|
90
|
+
problems.push(`${bare.length} product${bare.length === 1 ? " has" : "s have"} options but no feed.variants (${bare.slice(0, 3).map((product) => JSON.stringify(product.product_id)).join(", ")}${bare.length > 3 ? ", …" : ""}), so agents can't choose or buy an option`);
|
|
91
|
+
}
|
|
92
|
+
if (flattened.length) {
|
|
93
|
+
problems.push(`options look flattened into separate listings with different prices (${flattened.slice(0, 2).map((group) => group.slice(0, 3).map((product) => JSON.stringify(product.title)).join(" / ")).join("; ")}), so agents see unrelated products`);
|
|
94
|
+
}
|
|
95
|
+
if (problems.length)
|
|
96
|
+
return { status: "NOT DONE", detail: `Warning for agents: ${problems.join("; ")}. Fix: ${VARIANT_FIX}.` };
|
|
97
|
+
const listed = products.filter((product) => product.configurable).length;
|
|
98
|
+
return {
|
|
99
|
+
status: "PASS",
|
|
100
|
+
detail: listed ? `${listed} product${listed === 1 ? " with options lists its" : "s with options list their"} variants.` : "No agent-visible product has options.",
|
|
101
|
+
};
|
|
102
|
+
}
|