@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.
Files changed (225) hide show
  1. package/AGENTS.md +75 -0
  2. package/CHANGELOG.md +1053 -0
  3. package/LICENSE +21 -0
  4. package/QUICKSTART.md +239 -0
  5. package/README.md +117 -2
  6. package/dist/adapters/express.d.ts +39 -0
  7. package/dist/adapters/express.js +106 -0
  8. package/dist/adapters/hono.d.ts +16 -0
  9. package/dist/adapters/hono.js +15 -0
  10. package/dist/adapters/next.d.ts +29 -0
  11. package/dist/adapters/next.js +38 -0
  12. package/dist/agent-card.d.ts +14 -0
  13. package/dist/agent-card.js +58 -0
  14. package/dist/agent-docs.d.ts +36 -0
  15. package/dist/agent-docs.js +78 -0
  16. package/dist/agent-hooks.d.ts +66 -0
  17. package/dist/agent-hooks.js +280 -0
  18. package/dist/agents.d.ts +24 -0
  19. package/dist/agents.js +120 -0
  20. package/dist/api-key.d.ts +6 -0
  21. package/dist/api-key.js +33 -0
  22. package/dist/cache.d.ts +46 -0
  23. package/dist/cache.js +86 -0
  24. package/dist/cart-tokens.d.ts +31 -0
  25. package/dist/cart-tokens.js +58 -0
  26. package/dist/cart-transfer.d.ts +95 -0
  27. package/dist/cart-transfer.js +387 -0
  28. package/dist/catalog-enrichment.d.ts +6 -0
  29. package/dist/catalog-enrichment.js +71 -0
  30. package/dist/catalog-reads.d.ts +126 -0
  31. package/dist/catalog-reads.js +104 -0
  32. package/dist/catalog.d.ts +78 -0
  33. package/dist/catalog.js +288 -0
  34. package/dist/charge-claims.d.ts +11 -0
  35. package/dist/charge-claims.js +47 -0
  36. package/dist/check.d.ts +44 -0
  37. package/dist/check.js +152 -0
  38. package/dist/checklist-manifest.d.ts +72 -0
  39. package/dist/checklist-manifest.js +341 -0
  40. package/dist/checkout.d.ts +222 -0
  41. package/dist/checkout.js +353 -0
  42. package/dist/cli.d.ts +2 -0
  43. package/dist/cli.js +727 -0
  44. package/dist/confirmation.d.ts +78 -0
  45. package/dist/confirmation.js +124 -0
  46. package/dist/context.d.ts +81 -0
  47. package/dist/context.js +10 -0
  48. package/dist/discovery.d.ts +151 -0
  49. package/dist/discovery.js +346 -0
  50. package/dist/doctor-cart-transfer.d.ts +33 -0
  51. package/dist/doctor-cart-transfer.js +186 -0
  52. package/dist/doctor-catalog.d.ts +8 -0
  53. package/dist/doctor-catalog.js +47 -0
  54. package/dist/doctor-evidence.d.ts +22 -0
  55. package/dist/doctor-evidence.js +57 -0
  56. package/dist/doctor-merchant.d.ts +48 -0
  57. package/dist/doctor-merchant.js +74 -0
  58. package/dist/doctor-source.d.ts +5 -0
  59. package/dist/doctor-source.js +142 -0
  60. package/dist/doctor-variants.d.ts +70 -0
  61. package/dist/doctor-variants.js +102 -0
  62. package/dist/doctor.d.ts +215 -0
  63. package/dist/doctor.js +1689 -0
  64. package/dist/events.d.ts +95 -0
  65. package/dist/events.js +200 -0
  66. package/dist/feed-mapping.d.ts +114 -0
  67. package/dist/feed-mapping.js +152 -0
  68. package/dist/feed-values.d.ts +13 -0
  69. package/dist/feed-values.js +40 -0
  70. package/dist/feeds.d.ts +104 -0
  71. package/dist/feeds.js +366 -0
  72. package/dist/identify.d.ts +102 -0
  73. package/dist/identify.js +124 -0
  74. package/dist/identity.d.ts +37 -0
  75. package/dist/identity.js +54 -0
  76. package/dist/index.d.ts +42 -0
  77. package/dist/index.js +41 -0
  78. package/dist/init.d.ts +157 -0
  79. package/dist/init.js +912 -0
  80. package/dist/kit-config.d.ts +19 -0
  81. package/dist/kit-config.js +43 -0
  82. package/dist/kit-environment.d.ts +20 -0
  83. package/dist/kit-environment.js +32 -0
  84. package/dist/kit-updates.d.ts +47 -0
  85. package/dist/kit-updates.js +77 -0
  86. package/dist/kit-version-project.d.ts +18 -0
  87. package/dist/kit-version-project.js +214 -0
  88. package/dist/kit-version.d.ts +37 -0
  89. package/dist/kit-version.js +162 -0
  90. package/dist/kit.d.ts +516 -0
  91. package/dist/kit.js +1309 -0
  92. package/dist/layers/pages.d.ts +3 -0
  93. package/dist/layers/pages.js +5 -0
  94. package/dist/layers/payments.d.ts +7 -0
  95. package/dist/layers/payments.js +9 -0
  96. package/dist/layers/products.d.ts +10 -0
  97. package/dist/layers/products.js +13 -0
  98. package/dist/live.d.ts +13 -0
  99. package/dist/live.js +52 -0
  100. package/dist/mcp.d.ts +270 -0
  101. package/dist/mcp.js +312 -0
  102. package/dist/next-steps.d.ts +101 -0
  103. package/dist/next-steps.js +257 -0
  104. package/dist/order-pending.d.ts +57 -0
  105. package/dist/order-pending.js +127 -0
  106. package/dist/orders.d.ts +12 -0
  107. package/dist/orders.js +21 -0
  108. package/dist/payments-init.d.ts +19 -0
  109. package/dist/payments-init.js +70 -0
  110. package/dist/payments-routes.d.ts +54 -0
  111. package/dist/payments-routes.js +123 -0
  112. package/dist/payments.d.ts +165 -0
  113. package/dist/payments.js +192 -0
  114. package/dist/pnpm-workspace.d.ts +58 -0
  115. package/dist/pnpm-workspace.js +250 -0
  116. package/dist/policies.d.ts +111 -0
  117. package/dist/policies.js +317 -0
  118. package/dist/preview-hosts.d.ts +64 -0
  119. package/dist/preview-hosts.js +175 -0
  120. package/dist/private-config.d.ts +169 -0
  121. package/dist/private-config.js +820 -0
  122. package/dist/progress.d.ts +54 -0
  123. package/dist/progress.js +153 -0
  124. package/dist/protocol-inputs.d.ts +22 -0
  125. package/dist/protocol-inputs.js +151 -0
  126. package/dist/public-origin.d.ts +50 -0
  127. package/dist/public-origin.js +180 -0
  128. package/dist/refusals.d.ts +86 -0
  129. package/dist/refusals.js +157 -0
  130. package/dist/relay.d.ts +107 -0
  131. package/dist/relay.js +655 -0
  132. package/dist/release-notes.d.ts +2 -0
  133. package/dist/release-notes.js +290 -0
  134. package/dist/relyon-cart-tokens.d.ts +101 -0
  135. package/dist/relyon-cart-tokens.js +521 -0
  136. package/dist/relyon.d.ts +141 -0
  137. package/dist/relyon.js +238 -0
  138. package/dist/robots.d.ts +27 -0
  139. package/dist/robots.js +127 -0
  140. package/dist/rules.d.ts +144 -0
  141. package/dist/rules.js +347 -0
  142. package/dist/sdk/generated/public-api.d.ts +4816 -0
  143. package/dist/sdk/generated/public-api.js +1 -0
  144. package/dist/sdk/index.d.ts +24 -0
  145. package/dist/sdk/index.js +34 -0
  146. package/dist/sdk/signatures.d.ts +17 -0
  147. package/dist/sdk/signatures.js +33 -0
  148. package/dist/setup.d.ts +37 -0
  149. package/dist/setup.js +94 -0
  150. package/dist/signatures.d.ts +112 -0
  151. package/dist/signatures.js +443 -0
  152. package/dist/state.d.ts +185 -0
  153. package/dist/state.js +96 -0
  154. package/dist/store-payments.d.ts +48 -0
  155. package/dist/store-payments.js +143 -0
  156. package/dist/structured-fields.d.ts +26 -0
  157. package/dist/structured-fields.js +200 -0
  158. package/dist/templates.d.ts +19 -0
  159. package/dist/templates.js +193 -0
  160. package/dist/test-checkout-command.d.ts +32 -0
  161. package/dist/test-checkout-command.js +161 -0
  162. package/dist/test-checkout.d.ts +88 -0
  163. package/dist/test-checkout.js +292 -0
  164. package/dist/types.d.ts +103 -0
  165. package/dist/types.js +18 -0
  166. package/dist/ucp-versions.d.ts +57 -0
  167. package/dist/ucp-versions.js +129 -0
  168. package/dist/util.d.ts +23 -0
  169. package/dist/util.js +68 -0
  170. package/dist/variants.d.ts +67 -0
  171. package/dist/variants.js +146 -0
  172. package/dist/version.d.ts +9 -0
  173. package/dist/version.js +10 -0
  174. package/dist/waiting.d.ts +43 -0
  175. package/dist/waiting.js +57 -0
  176. package/dist/webhook-command.d.ts +48 -0
  177. package/dist/webhook-command.js +367 -0
  178. package/dist/webhook-registration.d.ts +47 -0
  179. package/dist/webhook-registration.js +69 -0
  180. package/dist/webmcp-schema.d.ts +14 -0
  181. package/dist/webmcp-schema.js +140 -0
  182. package/dist/webmcp-script.d.ts +3 -0
  183. package/dist/webmcp-script.js +176 -0
  184. package/dist/webmcp-store.d.ts +102 -0
  185. package/dist/webmcp-store.js +116 -0
  186. package/dist/webmcp.d.ts +242 -0
  187. package/dist/webmcp.js +866 -0
  188. package/dist/wire-names.d.ts +85 -0
  189. package/dist/wire-names.js +109 -0
  190. package/package.json +118 -4
  191. package/release-notes.json +290 -0
  192. package/scripts/install-notice.cjs +7 -0
  193. package/skills/relyon-agents/SKILL.md +327 -0
  194. package/skills/relyon-catalog/SKILL.md +499 -0
  195. package/skills/relyon-catalog/references/example-store.md +218 -0
  196. package/skills/relyon-checkout/SKILL.md +603 -0
  197. package/skills/relyon-checkout/references/checkout-flow.md +257 -0
  198. package/skills/relyon-checkout/references/checkout-page.md +315 -0
  199. package/skills/relyon-go-live/SKILL.md +344 -0
  200. package/skills/relyon-orders/SKILL.md +191 -0
  201. package/skills/relyon-orders/references/webhook-receiver.md +113 -0
  202. package/skills/relyon-payments/SKILL.md +117 -0
  203. package/skills/relyon-setup/SKILL.md +1061 -0
  204. package/skills/relyon-setup/references/QUICKSTART.md +239 -0
  205. package/skills/relyon-setup/references/durable-state.md +209 -0
  206. package/skills/relyon-setup/references/express-server.md +388 -0
  207. package/skills/relyon-setup/references/next-app-router.md +251 -0
  208. package/templates/common/STORE-README.md +67 -0
  209. package/templates/common/gitignore +8 -0
  210. package/templates/common/scripts/check-pricing.ts +22 -0
  211. package/templates/common/scripts/serve.mjs +13 -0
  212. package/templates/common/server/catalog.ts +79 -0
  213. package/templates/common/server/checkout-flow.d.ts +34 -0
  214. package/templates/common/server/pages.ts +184 -0
  215. package/templates/common/server/storage.ts +114 -0
  216. package/templates/common/server/store.ts +67 -0
  217. package/templates/express/server/express.ts +20 -0
  218. package/templates/express/tsconfig.build.json +6 -0
  219. package/templates/express/tsconfig.json +9 -0
  220. package/templates/next/app/[[...path]]/route.ts +24 -0
  221. package/templates/next/next.config.mjs +19 -0
  222. package/templates/next/tsconfig.json +12 -0
  223. package/templates/payments/express.ts +39 -0
  224. package/templates/payments/next.ts +38 -0
  225. package/templates/payments/node.ts +39 -0
@@ -0,0 +1,6 @@
1
+ /** The key when it is a well-formed Relyon secret key, else undefined. */
2
+ export declare function usableApiKey(value: unknown): string | undefined;
3
+ /** True for a well-formed Test secret key (`rly_test_…`). */
4
+ export declare function usableTestKey(value: unknown): string | undefined;
5
+ /** True when a value is set but is not a usable key (a placeholder or malformed value). */
6
+ export declare function placeholderApiKey(value: unknown): boolean;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Which RELYON_API_KEY values count as a key. Relyon issues secret keys as
3
+ * `rly_test_` or `rly_live_` followed by letters and digits only. Anything
4
+ * else (empty, `your_key_here`, `rly_test_xxx`, `changeme`, a copied example
5
+ * value) is "no key": the kit waits for a sandbox key and init sets one up,
6
+ * instead of sending it to Relyon and failing with invalid_api_key.
7
+ *
8
+ * Never echo the value: callers report only that a key is missing or unusable.
9
+ */
10
+ const KEY_SHAPE = /^rly_(?:test|live)_[A-Za-z0-9]{16,200}$/;
11
+ // Words that only an example or placeholder contains. Each is long enough
12
+ // (6+ letters) that a randomly issued key practically never contains it.
13
+ const PLACEHOLDER = /x{6,}|changeme|placeholder|example|replace|yourkey|insertkey|redacted|secretkey|apikey/i;
14
+ /** The key when it is a well-formed Relyon secret key, else undefined. */
15
+ export function usableApiKey(value) {
16
+ if (typeof value !== "string")
17
+ return undefined;
18
+ const key = value.trim();
19
+ if (!KEY_SHAPE.test(key))
20
+ return undefined;
21
+ if (PLACEHOLDER.test(key.slice(key.indexOf("_", 4) + 1)))
22
+ return undefined;
23
+ return key;
24
+ }
25
+ /** True for a well-formed Test secret key (`rly_test_…`). */
26
+ export function usableTestKey(value) {
27
+ const key = usableApiKey(value);
28
+ return key?.startsWith("rly_test_") ? key : undefined;
29
+ }
30
+ /** True when a value is set but is not a usable key (a placeholder or malformed value). */
31
+ export function placeholderApiKey(value) {
32
+ return typeof value === "string" && value.trim() !== "" && usableApiKey(value) === undefined;
33
+ }
@@ -0,0 +1,46 @@
1
+ export interface Cached<T> {
2
+ value: T;
3
+ fetchedAt: number;
4
+ /** Milliseconds the copy is fresh for. */
5
+ ttlMs: number;
6
+ }
7
+ export interface CacheRead<T> {
8
+ value: T;
9
+ /** True when Relyon couldn't be reached and the last good copy was served. */
10
+ stale: boolean;
11
+ /** Seconds the copy stays fresh from now (0 when stale). */
12
+ freshForSeconds: number;
13
+ }
14
+ /**
15
+ * One cached discovery read with stale-if-error: a fresh copy is served from
16
+ * memory, an expired one is refreshed, and when the refresh fails because
17
+ * Relyon is unavailable the last good copy is served instead. Any other
18
+ * failure (a Problem, such as an unverified hostname) drops the copy and is
19
+ * thrown, because Relyon has answered that the copy is no longer right.
20
+ */
21
+ export declare class StaleIfErrorCache<K, T> {
22
+ private readonly load;
23
+ private readonly keyOf;
24
+ private readonly now;
25
+ private readonly entries;
26
+ private readonly inflight;
27
+ constructor(load: (key: K) => Promise<{
28
+ value: T;
29
+ ttlMs: number;
30
+ }>, keyOf: (key: K) => string, now: () => number);
31
+ read(key: K): Promise<CacheRead<T>>;
32
+ /**
33
+ * A copy fetched now (joining one already in flight), with no stale
34
+ * fallback: for reads that must not rely on an expired copy.
35
+ */
36
+ reload(key: K): Promise<CacheRead<T>>;
37
+ private refresh;
38
+ clear(): void;
39
+ /**
40
+ * Marks every copy expired: the next read refreshes it, and still serves the
41
+ * last good copy if Relyon is unavailable.
42
+ */
43
+ expire(): void;
44
+ }
45
+ /** `max-age` from a Cache-Control header, in seconds; undefined when absent. */
46
+ export declare function maxAgeSeconds(cacheControl: string | null): number | undefined;
package/dist/cache.js ADDED
@@ -0,0 +1,86 @@
1
+ import { RelyonUnavailableError } from "./relyon.js";
2
+ /**
3
+ * One cached discovery read with stale-if-error: a fresh copy is served from
4
+ * memory, an expired one is refreshed, and when the refresh fails because
5
+ * Relyon is unavailable the last good copy is served instead. Any other
6
+ * failure (a Problem, such as an unverified hostname) drops the copy and is
7
+ * thrown, because Relyon has answered that the copy is no longer right.
8
+ */
9
+ export class StaleIfErrorCache {
10
+ load;
11
+ keyOf;
12
+ now;
13
+ entries = new Map();
14
+ inflight = new Map();
15
+ constructor(load, keyOf, now) {
16
+ this.load = load;
17
+ this.keyOf = keyOf;
18
+ this.now = now;
19
+ }
20
+ async read(key) {
21
+ const id = this.keyOf(key);
22
+ const current = this.entries.get(id);
23
+ const now = this.now();
24
+ if (current && now - current.fetchedAt < current.ttlMs) {
25
+ return { value: current.value, stale: false, freshForSeconds: Math.max(0, Math.floor((current.fetchedAt + current.ttlMs - now) / 1000)) };
26
+ }
27
+ try {
28
+ const fresh = await this.refresh(key);
29
+ return { value: fresh.value, stale: false, freshForSeconds: Math.floor(fresh.ttlMs / 1000) };
30
+ }
31
+ catch (error) {
32
+ if (error instanceof RelyonUnavailableError && current) {
33
+ return { value: current.value, stale: true, freshForSeconds: 0 };
34
+ }
35
+ if (!(error instanceof RelyonUnavailableError))
36
+ this.entries.delete(id);
37
+ throw error;
38
+ }
39
+ }
40
+ /**
41
+ * A copy fetched now (joining one already in flight), with no stale
42
+ * fallback: for reads that must not rely on an expired copy.
43
+ */
44
+ async reload(key) {
45
+ try {
46
+ const fresh = await this.refresh(key);
47
+ return { value: fresh.value, stale: false, freshForSeconds: Math.floor(fresh.ttlMs / 1000) };
48
+ }
49
+ catch (error) {
50
+ if (!(error instanceof RelyonUnavailableError))
51
+ this.entries.delete(this.keyOf(key));
52
+ throw error;
53
+ }
54
+ }
55
+ refresh(key) {
56
+ const id = this.keyOf(key);
57
+ let pending = this.inflight.get(id);
58
+ if (!pending) {
59
+ pending = this.load(key).then(({ value, ttlMs }) => {
60
+ const entry = { value, ttlMs, fetchedAt: this.now() };
61
+ this.entries.set(id, entry);
62
+ return entry;
63
+ }).finally(() => this.inflight.delete(id));
64
+ this.inflight.set(id, pending);
65
+ }
66
+ return pending;
67
+ }
68
+ clear() {
69
+ this.entries.clear();
70
+ }
71
+ /**
72
+ * Marks every copy expired: the next read refreshes it, and still serves the
73
+ * last good copy if Relyon is unavailable.
74
+ */
75
+ expire() {
76
+ for (const [id, entry] of this.entries)
77
+ this.entries.set(id, { ...entry, ttlMs: 0 });
78
+ }
79
+ }
80
+ /** `max-age` from a Cache-Control header, in seconds; undefined when absent. */
81
+ export function maxAgeSeconds(cacheControl) {
82
+ if (!cacheControl)
83
+ return undefined;
84
+ const match = /(?:^|,)\s*max-age=(\d+)/i.exec(cacheControl);
85
+ return match ? Number(match[1]) : undefined;
86
+ }
@@ -0,0 +1,31 @@
1
+ import type { AgentProtocol, CartInputs } from "./types.js";
2
+ /** What a `relyon_cart` token stands for: one agent checkout and the cart the agent built. */
3
+ export interface ResolvedCart {
4
+ agentCheckoutId: string;
5
+ protocol: AgentProtocol;
6
+ inputs: CartInputs;
7
+ }
8
+ /**
9
+ * Mints and resolves `relyon_cart` tokens. The default seals the cart inside
10
+ * the token itself. Relyon-issued hand-off tokens are checked by the kit
11
+ * before this resolver runs (see `relyon-cart-tokens.ts`); a token the kit
12
+ * doesn't accept still reaches `resolve`. `resolve` returns null for any token
13
+ * it can't vouch for (tampered, expired, unknown); it never throws for a bad token.
14
+ */
15
+ export interface CartTokenResolver {
16
+ mint(cart: ResolvedCart): Promise<string> | string;
17
+ resolve(token: string): Promise<ResolvedCart | null> | ResolvedCart | null;
18
+ }
19
+ /**
20
+ * The kit's own token: `rc_test_` + AES-256-GCM sealed `{agent checkout, cart
21
+ * inputs, expiry}`. Sealed rather than only signed so the address inside never
22
+ * shows in URLs or logs. Bound to one agent checkout; expires after `ttlSeconds`.
23
+ */
24
+ export declare class SealedCartTokens implements CartTokenResolver {
25
+ private readonly now;
26
+ private readonly ttlSeconds;
27
+ private readonly key;
28
+ constructor(secret: string, now: () => number, ttlSeconds?: number);
29
+ mint(cart: ResolvedCart): string;
30
+ resolve(token: string): ResolvedCart | null;
31
+ }
@@ -0,0 +1,58 @@
1
+ import { createCipheriv, createDecipheriv, hkdfSync, randomBytes } from "node:crypto";
2
+ import { isRecord } from "./util.js";
3
+ const PREFIX = "rc_test_";
4
+ const MAX_LENGTH = 2000;
5
+ const PROTOCOLS = new Set(["ucp", "acp", "mcp"]);
6
+ /**
7
+ * The kit's own token: `rc_test_` + AES-256-GCM sealed `{agent checkout, cart
8
+ * inputs, expiry}`. Sealed rather than only signed so the address inside never
9
+ * shows in URLs or logs. Bound to one agent checkout; expires after `ttlSeconds`.
10
+ */
11
+ export class SealedCartTokens {
12
+ now;
13
+ ttlSeconds;
14
+ key;
15
+ constructor(secret, now, ttlSeconds = 24 * 60 * 60) {
16
+ this.now = now;
17
+ this.ttlSeconds = ttlSeconds;
18
+ if (secret.length < 16)
19
+ throw new TypeError("The cart token secret must be at least 16 characters.");
20
+ this.key = Buffer.from(hkdfSync("sha256", secret, "relyon-store-kit", "relyon_cart v1", 32));
21
+ }
22
+ mint(cart) {
23
+ const payload = JSON.stringify({
24
+ v: 1, ac: cart.agentCheckoutId, p: cart.protocol, i: cart.inputs, exp: Math.floor(this.now() / 1000) + this.ttlSeconds,
25
+ });
26
+ const iv = randomBytes(12);
27
+ const cipher = createCipheriv("aes-256-gcm", this.key, iv);
28
+ cipher.setAAD(Buffer.from(PREFIX));
29
+ const sealed = Buffer.concat([cipher.update(payload, "utf8"), cipher.final()]);
30
+ const token = PREFIX + Buffer.concat([iv, cipher.getAuthTag(), sealed]).toString("base64url");
31
+ if (token.length > MAX_LENGTH)
32
+ throw new RangeError("This cart is too large for a relyon_cart token.");
33
+ return token;
34
+ }
35
+ resolve(token) {
36
+ if (typeof token !== "string" || !token.startsWith(PREFIX) || token.length > MAX_LENGTH)
37
+ return null;
38
+ try {
39
+ const raw = Buffer.from(token.slice(PREFIX.length), "base64url");
40
+ if (raw.length < 29)
41
+ return null;
42
+ const decipher = createDecipheriv("aes-256-gcm", this.key, raw.subarray(0, 12));
43
+ decipher.setAAD(Buffer.from(PREFIX));
44
+ decipher.setAuthTag(raw.subarray(12, 28));
45
+ const payload = JSON.parse(Buffer.concat([decipher.update(raw.subarray(28)), decipher.final()]).toString("utf8"));
46
+ if (!isRecord(payload) || payload.v !== 1 || typeof payload.ac !== "string" || !PROTOCOLS.has(payload.p))
47
+ return null;
48
+ if (typeof payload.exp !== "number" || payload.exp <= Math.floor(this.now() / 1000))
49
+ return null;
50
+ if (!isRecord(payload.i) || !Array.isArray(payload.i.lines))
51
+ return null;
52
+ return { agentCheckoutId: payload.ac, protocol: payload.p, inputs: payload.i };
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,95 @@
1
+ import type { CatalogHolder } from "./catalog.js";
2
+ import type { StoreCatalogProduct, StoreCatalogReads } from "./catalog-reads.js";
3
+ import type { Landing } from "./checkout.js";
4
+ import { type CartLineInput, type Logger, type PriceCart } from "./types.js";
5
+ import { type StoreUcpVersion } from "./ucp-versions.js";
6
+ /** The kit's `cartTransfer` option. */
7
+ export type CartTransferOption = false | {
8
+ /**
9
+ * The caller key the merchant gives Google, checked against `X-API-Key`
10
+ * (constant time). At least 16 characters. Required in Live. Default: the
11
+ * `RELYON_CART_TRANSFER_KEY` environment variable.
12
+ */
13
+ apiKey?: string;
14
+ /** How long a cart's `continue_url` works. Default 24 hours. */
15
+ ttlSeconds?: number;
16
+ };
17
+ export declare const CART_TRANSFER_KEY_ENV = "RELYON_CART_TRANSFER_KEY";
18
+ export declare const CART_TRANSFER_KEY_HEADER = "x-api-key";
19
+ export declare const CART_TRANSFER_PARAM = "relyon_transfer";
20
+ export type CartTransferState = {
21
+ enabled: true;
22
+ apiKey: string | null;
23
+ ttlSeconds: number;
24
+ } | {
25
+ enabled: false;
26
+ reason: "switched_off" | "live_without_key" | "invalid_key";
27
+ };
28
+ /**
29
+ * Whether cart transfer runs, and with which caller key. Test: on by
30
+ * default, open without a key. Live: on only with a key. A key that is too
31
+ * short never opens the endpoint: cart transfer is off and a warning logged.
32
+ */
33
+ export declare function cartTransferState(option: CartTransferOption | undefined, livemode: boolean, env: Record<string, string | undefined>, logger: Logger): CartTransferState;
34
+ /** Compares the caller's key in constant time (hashes first, so lengths never leak). */
35
+ export declare function callerKeyMatches(expected: string, given: string): boolean;
36
+ /**
37
+ * The `relyon_transfer` token in a transferred cart's `continue_url`:
38
+ * AES-256-GCM sealed `{lines, expiry}`, its own key (HKDF info
39
+ * "relyon_transfer v1") and associated data, so it can never be read as a
40
+ * `relyon_cart` hand-off token or the other way round. Version 2 (kit
41
+ * 0.1.11) carries each line's options; version 1 tokens (kit 0.1.10, IDs and
42
+ * quantities only) are still read.
43
+ */
44
+ export declare class TransferTokens {
45
+ private readonly now;
46
+ private readonly ttlSeconds;
47
+ private readonly key;
48
+ constructor(secret: string, now: () => number, ttlSeconds: number);
49
+ /** Whether a link for these lines fits in a token (the size depends only on the lines). */
50
+ fits(lines: readonly CartLineInput[]): boolean;
51
+ private static payload;
52
+ mint(lines: readonly CartLineInput[]): {
53
+ token: string;
54
+ expiresAt: number;
55
+ };
56
+ /** Seals a raw payload (also how tests make a kit 0.1.10 token). */
57
+ seal(payload: string): string;
58
+ /**
59
+ * The token's lines and version, or null for a tampered, expired or foreign
60
+ * token. Never throws.
61
+ */
62
+ read(token: string): {
63
+ version: 1 | 2;
64
+ lines: CartLineInput[];
65
+ } | null;
66
+ /** The lines, or null for a tampered, expired or foreign token. Never throws. */
67
+ resolve(token: string): CartLineInput[] | null;
68
+ }
69
+ export interface CartTransferDeps {
70
+ state: CartTransferState;
71
+ tokens: TransferTokens | null;
72
+ /** The kit's catalog (the store's source when configured, else the mirror). */
73
+ products(): Promise<readonly StoreCatalogProduct[]>;
74
+ priceCart: PriceCart;
75
+ logger: Logger;
76
+ now: () => number;
77
+ }
78
+ /** The catalog entries cart transfer can sell, by feed ID: variants win over a product with the same ID. */
79
+ export declare function transferableItems(products: readonly StoreCatalogProduct[]): Map<string, StoreCatalogProduct>;
80
+ /**
81
+ * Answers `POST <ucp prefix>/carts` at `version`. `continueUrl` builds the
82
+ * store checkout link for a token. Never throws.
83
+ */
84
+ export declare function handleCartTransfer(deps: CartTransferDeps, request: Request, rawBody: string, version: StoreUcpVersion, continueUrl: (token: string) => string): Promise<Response>;
85
+ /**
86
+ * A shopper landing on the store's checkout with a `relyon_transfer` token:
87
+ * the transferred lines priced again by the store now. Never attributed to an
88
+ * agent checkout and never a payment authority. A bad, expired or tampered
89
+ * token is a normal, unattributed landing.
90
+ */
91
+ export declare function transferLanding(tokens: TransferTokens | null, priceCart: PriceCart, token: string, logger: Logger, products?: () => Promise<readonly StoreCatalogProduct[]>): Promise<Landing & {
92
+ transferred: boolean;
93
+ }>;
94
+ /** The kit's catalog read for cart transfer. */
95
+ export declare function catalogProducts(reads: StoreCatalogReads | undefined, mirror: CatalogHolder): () => Promise<readonly StoreCatalogProduct[]>;