@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Client } from "openapi-fetch";
|
|
2
|
+
import type { paths, components, webhooks } from "./generated/public-api.js";
|
|
3
|
+
export type { paths, components, operations, webhooks } from "./generated/public-api.js";
|
|
4
|
+
export type Problem = components["schemas"]["Problem"];
|
|
5
|
+
export type Event = components["schemas"]["Event"];
|
|
6
|
+
export type EventPayload = webhooks["event"]["post"]["requestBody"]["content"]["application/json"];
|
|
7
|
+
export type Cart = components["schemas"]["Cart"];
|
|
8
|
+
export type PaymentCreate = components["schemas"]["PaymentCreate"];
|
|
9
|
+
export type Payment = components["schemas"]["Payment"];
|
|
10
|
+
export type AgentCheckoutRequest = components["schemas"]["AgentCheckoutRequest"];
|
|
11
|
+
export type AgentCheckoutResult = components["schemas"]["AgentCheckoutResult"];
|
|
12
|
+
export type AgentRules = components["schemas"]["AgentRules"];
|
|
13
|
+
export declare const DEFAULT_RELYON_VERSION = "2026-11-21";
|
|
14
|
+
export type RelyonClient = Client<paths>;
|
|
15
|
+
export interface RelyonClientOptions {
|
|
16
|
+
/** Explicit service origin, optionally including a gateway prefix or /v1. */
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
/** Publishable keys only have the capabilities granted by the public contract. */
|
|
19
|
+
apiKey: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
22
|
+
}
|
|
23
|
+
/** Portable Fetch client. No environment, auth SDK, retries, or Node imports. */
|
|
24
|
+
export declare function createRelyonClient(options: RelyonClientOptions): RelyonClient;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import createClient from "openapi-fetch";
|
|
2
|
+
export const DEFAULT_RELYON_VERSION = "2026-11-21";
|
|
3
|
+
/** Portable Fetch client. No environment, auth SDK, retries, or Node imports. */
|
|
4
|
+
export function createRelyonClient(options) {
|
|
5
|
+
const url = new URL(options.baseUrl);
|
|
6
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
|
|
7
|
+
throw new TypeError("baseUrl must be an HTTP(S) URL without credentials, query, or fragment");
|
|
8
|
+
}
|
|
9
|
+
if (!options.apiKey || options.apiKey.trim() !== options.apiKey || /[\r\n]/.test(options.apiKey)) {
|
|
10
|
+
throw new TypeError("apiKey must be a nonempty Bearer credential");
|
|
11
|
+
}
|
|
12
|
+
const apiKey = options.apiKey;
|
|
13
|
+
const version = options.version ?? DEFAULT_RELYON_VERSION;
|
|
14
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(version))
|
|
15
|
+
throw new TypeError("version must be YYYY-MM-DD");
|
|
16
|
+
// Generated paths already contain /v1. Accept an origin, gateway prefix, or
|
|
17
|
+
// versioned service root, without duplicating or dropping the version segment.
|
|
18
|
+
const baseUrl = url.href.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
19
|
+
const client = createClient({
|
|
20
|
+
baseUrl,
|
|
21
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
22
|
+
});
|
|
23
|
+
client.use({
|
|
24
|
+
onRequest({ request }) {
|
|
25
|
+
// Always use this client's credential. A per-operation version override is
|
|
26
|
+
// allowed by the generated Relyon-Version parameter.
|
|
27
|
+
request.headers.set("Authorization", `Bearer ${apiKey}`);
|
|
28
|
+
if (!request.headers.has("Relyon-Version"))
|
|
29
|
+
request.headers.set("Relyon-Version", version);
|
|
30
|
+
return request;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return client;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SignatureVerificationOptions {
|
|
2
|
+
/** Unix seconds, a nonnegative safe integer. Defaults to the current clock. */
|
|
3
|
+
nowSeconds?: number;
|
|
4
|
+
/** Maximum past AND future skew in seconds. Defaults to 300; zero means exact. */
|
|
5
|
+
toleranceSeconds?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SignatureInput extends SignatureVerificationOptions {
|
|
8
|
+
/** Original UTF-8 text or bytes, BEFORE JSON parsing or reserialization. */
|
|
9
|
+
rawBody: string | Uint8Array;
|
|
10
|
+
signature: string | null | undefined;
|
|
11
|
+
/** The secret issued for the event webhook endpoint. */
|
|
12
|
+
secret: string;
|
|
13
|
+
}
|
|
14
|
+
/** Fail-closed verification; does not parse payloads or provide replay storage. */
|
|
15
|
+
export declare function verifySignature(input: SignatureInput): boolean;
|
|
16
|
+
/** Use the secret issued for this event webhook endpoint. */
|
|
17
|
+
export declare function verifyEventSignature(input: SignatureInput): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
/** Fail-closed verification; does not parse payloads or provide replay storage. */
|
|
3
|
+
export function verifySignature(input) {
|
|
4
|
+
if (!input || typeof input !== "object")
|
|
5
|
+
return false;
|
|
6
|
+
const { rawBody, signature, secret } = input;
|
|
7
|
+
if (typeof secret !== "string" || secret.trim().length === 0 ||
|
|
8
|
+
typeof signature !== "string" ||
|
|
9
|
+
!(typeof rawBody === "string" || rawBody instanceof Uint8Array))
|
|
10
|
+
return false;
|
|
11
|
+
const now = input.nowSeconds === undefined ? Math.floor(Date.now() / 1000) : input.nowSeconds;
|
|
12
|
+
const tolerance = input.toleranceSeconds === undefined ? 300 : input.toleranceSeconds;
|
|
13
|
+
if (!Number.isSafeInteger(now) || now < 0 ||
|
|
14
|
+
!Number.isSafeInteger(tolerance) || tolerance < 0)
|
|
15
|
+
return false;
|
|
16
|
+
// Exact wire format: no whitespace, duplicate fields, uppercase hex, or suffix.
|
|
17
|
+
const match = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(signature);
|
|
18
|
+
if (!match || match[0] !== signature)
|
|
19
|
+
return false;
|
|
20
|
+
const token = match[1];
|
|
21
|
+
const timestamp = Number(token);
|
|
22
|
+
if (!Number.isSafeInteger(timestamp) || timestamp < 0 ||
|
|
23
|
+
Math.abs(now - timestamp) > tolerance)
|
|
24
|
+
return false;
|
|
25
|
+
// Sign the original timestamp token (including leading zeros), not Number(token).
|
|
26
|
+
const expected = createHmac("sha256", secret).update(token).update(".").update(rawBody).digest();
|
|
27
|
+
const actual = Buffer.from(match[2], "hex");
|
|
28
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
29
|
+
}
|
|
30
|
+
/** Use the secret issued for this event webhook endpoint. */
|
|
31
|
+
export function verifyEventSignature(input) {
|
|
32
|
+
return verifySignature(input);
|
|
33
|
+
}
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { components } from "./sdk/index.js";
|
|
2
|
+
import { type RelyonGateway } from "./relyon.js";
|
|
3
|
+
type Domain = components["schemas"]["Domain"];
|
|
4
|
+
/**
|
|
5
|
+
* A domain as the setup helpers return it. `forwarding` (and its one-time
|
|
6
|
+
* secret) belongs to the legacy forwarding integration, which the kit doesn't
|
|
7
|
+
* use, so it is never returned.
|
|
8
|
+
*/
|
|
9
|
+
export type StoreDomain = Omit<Domain, "forwarding">;
|
|
10
|
+
/**
|
|
11
|
+
* The project space's policies as Relyon answers them: `object` is
|
|
12
|
+
* `project_space_policies`, or `store_policies` from the deprecated alias
|
|
13
|
+
* (same fields). The kit keeps its `StorePolicies` name for compatibility.
|
|
14
|
+
*/
|
|
15
|
+
export type StorePolicies = components["schemas"]["ProjectSpacePolicies"] | components["schemas"]["StorePolicies"];
|
|
16
|
+
export type StorePoliciesInput = components["schemas"]["ProjectSpacePoliciesInput"];
|
|
17
|
+
/** Finds this store's domain for `hostname` in Relyon's list (every page). */
|
|
18
|
+
export declare function findDomain(gateway: RelyonGateway, hostname: string): Promise<Domain | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the store's domain for `hostname`, adding it when Relyon doesn't
|
|
21
|
+
* have it yet. The Idempotency-Key comes from the hostname, so a retried add
|
|
22
|
+
* never creates a second domain.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureDomain(gateway: RelyonGateway, hostname: string): Promise<{
|
|
25
|
+
domain: StoreDomain;
|
|
26
|
+
created: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/** Asks Relyon to check the domain now. Each call is a new check, with its own Idempotency-Key. */
|
|
29
|
+
export declare function verifyDomain(gateway: RelyonGateway, id: string): Promise<StoreDomain>;
|
|
30
|
+
export declare function readStorePolicies(gateway: RelyonGateway): Promise<StorePolicies>;
|
|
31
|
+
/**
|
|
32
|
+
* Replaces every policy field (an omitted field is cleared). Each call gets
|
|
33
|
+
* its own Idempotency-Key, so putting back an earlier document is applied,
|
|
34
|
+
* not answered from an old replay.
|
|
35
|
+
*/
|
|
36
|
+
export declare function replaceStorePolicies(gateway: RelyonGateway, input: StorePoliciesInput): Promise<StorePolicies>;
|
|
37
|
+
export {};
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DOMAINS_PATH, DOMAIN_OBJECT, DOMAIN_VERIFY_PATH, isProjectSpacePoliciesObject, LEGACY_PROJECT_SPACE_POLICIES_PATH, PROJECT_SPACE_POLICIES_PATH } from "./wire-names.js";
|
|
2
|
+
import { RelyonProblemError } from "./relyon.js";
|
|
3
|
+
import { isRecord, randomId, sha256 } from "./util.js";
|
|
4
|
+
const DOMAIN_STATUSES = new Set(["pending", "verified", "failed"]);
|
|
5
|
+
function isDomain(data) {
|
|
6
|
+
return isRecord(data) && data.object === DOMAIN_OBJECT && typeof data.id === "string" && typeof data.hostname === "string"
|
|
7
|
+
&& typeof data.livemode === "boolean" && typeof data.status === "string" && DOMAIN_STATUSES.has(data.status) && isRecord(data.verification)
|
|
8
|
+
&& typeof data.verification.record_value === "string";
|
|
9
|
+
}
|
|
10
|
+
function isDomainList(data) {
|
|
11
|
+
return isRecord(data) && Array.isArray(data.data) && typeof data.has_more === "boolean" && data.data.every(isDomain);
|
|
12
|
+
}
|
|
13
|
+
function isStorePolicies(data) {
|
|
14
|
+
return isRecord(data) && isProjectSpacePoliciesObject(data.object) && typeof data.livemode === "boolean"
|
|
15
|
+
&& typeof data.complete === "boolean" && Array.isArray(data.missing) && data.missing.every(field => typeof field === "string");
|
|
16
|
+
}
|
|
17
|
+
function withoutForwarding(domain) {
|
|
18
|
+
const { forwarding: _forwarding, ...rest } = domain;
|
|
19
|
+
return rest;
|
|
20
|
+
}
|
|
21
|
+
/** Finds this store's domain for `hostname` in Relyon's list (every page). */
|
|
22
|
+
export async function findDomain(gateway, hostname) {
|
|
23
|
+
let startingAfter;
|
|
24
|
+
const cursors = new Set();
|
|
25
|
+
for (let page = 0; page < 50; page += 1) {
|
|
26
|
+
const { data } = await gateway.call((client) => client.GET(DOMAINS_PATH, { params: { query: { limit: 100, ...(startingAfter ? { starting_after: startingAfter } : {}) } } }), isDomainList);
|
|
27
|
+
if (data.data.some(domain => domain.livemode !== gateway.livemode))
|
|
28
|
+
throw new Error("Relyon's domain list has the wrong Test/Live environment.");
|
|
29
|
+
const match = data.data.find((domain) => domain.hostname.toLowerCase() === hostname.toLowerCase());
|
|
30
|
+
if (match)
|
|
31
|
+
return match;
|
|
32
|
+
const last = data.data[data.data.length - 1];
|
|
33
|
+
if (!data.has_more)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (!last || cursors.has(last.id))
|
|
36
|
+
throw new Error("Relyon's domain list has malformed pagination.");
|
|
37
|
+
cursors.add(last.id);
|
|
38
|
+
startingAfter = last.id;
|
|
39
|
+
}
|
|
40
|
+
throw new Error("Relyon's domain lookup exceeded 50 pages; ownership could not be checked.");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the store's domain for `hostname`, adding it when Relyon doesn't
|
|
44
|
+
* have it yet. The Idempotency-Key comes from the hostname, so a retried add
|
|
45
|
+
* never creates a second domain.
|
|
46
|
+
*/
|
|
47
|
+
export async function ensureDomain(gateway, hostname) {
|
|
48
|
+
const existing = await findDomain(gateway, hostname);
|
|
49
|
+
if (existing)
|
|
50
|
+
return { domain: withoutForwarding(existing), created: false };
|
|
51
|
+
const { data } = await gateway.call((client) => client.POST(DOMAINS_PATH, {
|
|
52
|
+
params: { header: { "Idempotency-Key": `sk-dom-${sha256(hostname).slice(0, 40)}` } },
|
|
53
|
+
body: { hostname },
|
|
54
|
+
}), isDomain);
|
|
55
|
+
return { domain: withoutForwarding(data), created: true };
|
|
56
|
+
}
|
|
57
|
+
/** Asks Relyon to check the domain now. Each call is a new check, with its own Idempotency-Key. */
|
|
58
|
+
export async function verifyDomain(gateway, id) {
|
|
59
|
+
const { data } = await gateway.call((client) => client.POST(DOMAIN_VERIFY_PATH, {
|
|
60
|
+
params: { path: { id }, header: { "Idempotency-Key": randomId("sk-ver-") } },
|
|
61
|
+
}), isDomain);
|
|
62
|
+
return withoutForwarding(data);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Runs a policies call on `/v1/project_space_policies`. Only when Relyon
|
|
66
|
+
* answers that the route itself doesn't exist (404 `not_found`: an API from
|
|
67
|
+
* before the project-space rename) is the same call made once on the
|
|
68
|
+
* deprecated `/v1/store_policies`, which such an API serves. A 404 means
|
|
69
|
+
* nothing was read or written, so the retry never repeats a write.
|
|
70
|
+
*/
|
|
71
|
+
async function onPoliciesPath(run) {
|
|
72
|
+
try {
|
|
73
|
+
return await run(PROJECT_SPACE_POLICIES_PATH);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (!(error instanceof RelyonProblemError) || error.status !== 404 || error.code !== "not_found")
|
|
77
|
+
throw error;
|
|
78
|
+
return run(LEGACY_PROJECT_SPACE_POLICIES_PATH);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export async function readStorePolicies(gateway) {
|
|
82
|
+
return onPoliciesPath(async (path) => (await gateway.call((client) => client.GET(path, {}), isStorePolicies)).data);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Replaces every policy field (an omitted field is cleared). Each call gets
|
|
86
|
+
* its own Idempotency-Key, so putting back an earlier document is applied,
|
|
87
|
+
* not answered from an old replay.
|
|
88
|
+
*/
|
|
89
|
+
export async function replaceStorePolicies(gateway, input) {
|
|
90
|
+
return onPoliciesPath(async (path) => (await gateway.call((client) => client.PUT(path, {
|
|
91
|
+
params: { header: { "Idempotency-Key": randomId("sk-pol-") } },
|
|
92
|
+
body: input,
|
|
93
|
+
}), isStorePolicies)).data);
|
|
94
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
import type { AgentName } from "./types.js";
|
|
3
|
+
export type SignatureMethod = "web_bot_auth" | "visa_tap" | "mastercard_agent_pay";
|
|
4
|
+
export type SignatureNetwork = "visa_tap" | "mastercard_agent_pay";
|
|
5
|
+
export type SignatureFailure = "no_signature" | "malformed" | "unsupported_tag" | "unsupported_algorithm" | "missing_params" | "missing_component" | "unsupported_component" | "not_allowlisted" | "directory_unavailable" | "unknown_key" | "bad_signature" | "not_yet_valid" | "expired" | "too_old" | "window_too_long" | "replayed";
|
|
6
|
+
export type SignatureVerdict = {
|
|
7
|
+
status: "verified";
|
|
8
|
+
method: SignatureMethod;
|
|
9
|
+
/** The agent the allowlist names for this directory (`other_known` for card networks). */
|
|
10
|
+
name: AgentName;
|
|
11
|
+
keyId: string;
|
|
12
|
+
/** The key directory the key came from. */
|
|
13
|
+
directory: string;
|
|
14
|
+
label: string;
|
|
15
|
+
tag: string;
|
|
16
|
+
/** The `@authority` the signature covered (one of the store's hostnames). */
|
|
17
|
+
authority: string;
|
|
18
|
+
created: number;
|
|
19
|
+
expires: number;
|
|
20
|
+
} | {
|
|
21
|
+
status: "unverified";
|
|
22
|
+
reason: SignatureFailure;
|
|
23
|
+
method?: SignatureMethod;
|
|
24
|
+
detail?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Web Bot Auth directory origins the kit trusts by default, and the agent each
|
|
28
|
+
* one names. Only OpenAI's published ChatGPT agent directory is listed; confirm
|
|
29
|
+
* it against OpenAI's documentation before relying on it in Live.
|
|
30
|
+
*/
|
|
31
|
+
export declare const DEFAULT_WEB_BOT_AUTH_DIRECTORIES: Readonly<Record<string, AgentName>>;
|
|
32
|
+
export declare const WEB_BOT_AUTH_DIRECTORY_PATH = "/.well-known/http-message-signatures-directory";
|
|
33
|
+
export declare const WEB_BOT_AUTH_TAG = "web-bot-auth";
|
|
34
|
+
export declare const NETWORK_TAGS: readonly string[];
|
|
35
|
+
export interface NetworkDirectoryConfig {
|
|
36
|
+
/** The network's https key directory (a JWKS). */
|
|
37
|
+
directoryUrl: string;
|
|
38
|
+
/** Accepted tags. Default agent-browser-auth and agent-payer-auth. */
|
|
39
|
+
tags?: string[];
|
|
40
|
+
}
|
|
41
|
+
export interface NonceStore {
|
|
42
|
+
/** Records `nonce` for `scope` until `expiresAtMs`. false when it was already recorded (a replay) or can't be recorded. */
|
|
43
|
+
claim(scope: string, nonce: string, expiresAtMs: number, nowMs: number): boolean | Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
/** One process's nonces, bounded. When full of live nonces it refuses new ones rather than forgetting a live one. */
|
|
46
|
+
export declare class MemoryNonceStore implements NonceStore {
|
|
47
|
+
private readonly maxEntries;
|
|
48
|
+
private readonly entries;
|
|
49
|
+
constructor(maxEntries?: number);
|
|
50
|
+
claim(scope: string, nonce: string, expiresAtMs: number, nowMs: number): boolean;
|
|
51
|
+
}
|
|
52
|
+
export type DirectoryFetch = (url: string, init: {
|
|
53
|
+
method: "GET";
|
|
54
|
+
headers: Record<string, string>;
|
|
55
|
+
redirect: "error";
|
|
56
|
+
signal: AbortSignal;
|
|
57
|
+
}) => Promise<Response>;
|
|
58
|
+
export interface AgentVerificationOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Allowlisted Web Bot Auth directory origins (`https://host`) and the agent
|
|
61
|
+
* each names. Default `DEFAULT_WEB_BOT_AUTH_DIRECTORIES`; `{}` turns Web Bot Auth off.
|
|
62
|
+
*/
|
|
63
|
+
webBotAuth?: Record<string, AgentName>;
|
|
64
|
+
/** Visa TAP / Mastercard Agent Pay key directories. None by default. */
|
|
65
|
+
networks?: Partial<Record<SignatureNetwork, NetworkDirectoryConfig>>;
|
|
66
|
+
/** Oldest signature accepted, and longest created→expires window. Default 8 minutes. */
|
|
67
|
+
maxSignatureAgeMs?: number;
|
|
68
|
+
/** Tolerated clock difference for a `created` in the future. Default 30 s. */
|
|
69
|
+
clockSkewMs?: number;
|
|
70
|
+
/** How long a fetched directory is trusted. Default 10 minutes. */
|
|
71
|
+
directoryTtlMs?: number;
|
|
72
|
+
/** Least time between two fetches of one directory (bounds unknown-keyid refreshes). Default 60 s. */
|
|
73
|
+
directoryRefreshIntervalMs?: number;
|
|
74
|
+
/** A directory that doesn't answer within this is unavailable. Default 3 s. */
|
|
75
|
+
directoryTimeoutMs?: number;
|
|
76
|
+
/** Largest directory body read. Default 64 KiB. */
|
|
77
|
+
maxDirectoryBytes?: number;
|
|
78
|
+
fetch?: DirectoryFetch;
|
|
79
|
+
nonces?: NonceStore;
|
|
80
|
+
}
|
|
81
|
+
interface DirectoryKey {
|
|
82
|
+
keyId: string;
|
|
83
|
+
publicKey: KeyObject;
|
|
84
|
+
}
|
|
85
|
+
/** RFC 7638 thumbprint of an Ed25519 key: the Web Bot Auth keyid. */
|
|
86
|
+
export declare function ed25519Thumbprint(x: string): string;
|
|
87
|
+
/** Keeps only Ed25519 public signing keys, indexed by kid and by thumbprint. Throws when it's not a JWKS. */
|
|
88
|
+
export declare function parseEd25519Jwks(document: unknown): Map<string, DirectoryKey>;
|
|
89
|
+
/** The directory URL a Signature-Agent value names for a signature label, or null. */
|
|
90
|
+
export declare function signatureAgentUrl(header: string | null, label: string): string | null;
|
|
91
|
+
/** The store kit's local verifier. One per kit; directories and nonces are cached in memory. */
|
|
92
|
+
export declare class AgentSignatureVerifier {
|
|
93
|
+
private readonly now;
|
|
94
|
+
private readonly o;
|
|
95
|
+
private readonly allowlist;
|
|
96
|
+
private readonly networks;
|
|
97
|
+
private readonly directories;
|
|
98
|
+
private readonly nonces;
|
|
99
|
+
constructor(options?: AgentVerificationOptions, now?: () => number);
|
|
100
|
+
/** The allowlisted Web Bot Auth origins and the agent each names. */
|
|
101
|
+
get webBotAuthDirectories(): Record<string, AgentName>;
|
|
102
|
+
/**
|
|
103
|
+
* Verifies the request's agent signature against each candidate `@authority`
|
|
104
|
+
* (the store's public hostnames). Never throws.
|
|
105
|
+
*/
|
|
106
|
+
verify(request: Request, authorities: readonly string[]): Promise<SignatureVerdict>;
|
|
107
|
+
private verifyOne;
|
|
108
|
+
private directory;
|
|
109
|
+
/** How often each directory was fetched (diagnostics and tests). */
|
|
110
|
+
directoryFetches(): Record<string, number>;
|
|
111
|
+
}
|
|
112
|
+
export {};
|