@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,19 @@
|
|
|
1
|
+
/** The three layers, each building on the one before. */
|
|
2
|
+
export declare const KIT_LAYERS: readonly ["payments", "products", "pages"];
|
|
3
|
+
export type KitLayer = typeof KIT_LAYERS[number];
|
|
4
|
+
/** Where init records the layer, relative to the app's directory. */
|
|
5
|
+
export declare const KIT_CONFIG_FILE = "relyon/kit.json";
|
|
6
|
+
/** One line per layer, as init's question and help name them. */
|
|
7
|
+
export declare const KIT_LAYER_LABELS: Readonly<Record<KitLayer, string>>;
|
|
8
|
+
export interface KitConfig {
|
|
9
|
+
layer: KitLayer;
|
|
10
|
+
}
|
|
11
|
+
export declare function isKitLayer(value: unknown): value is KitLayer;
|
|
12
|
+
/** The file's exact content for a layer. */
|
|
13
|
+
export declare function kitConfigContent(config: KitConfig): string;
|
|
14
|
+
/**
|
|
15
|
+
* The app's recorded layer: null when there is no `relyon/kit.json` (a store
|
|
16
|
+
* kit install from before layers, judged as before) or it is not a small
|
|
17
|
+
* regular file naming a known layer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readKitConfig(projectDir: string): Promise<KitConfig | null>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// The kit's local configuration in the app: `relyon/kit.json`, written by
|
|
4
|
+
// init. It records which layer the app uses, so the doctor and `check` judge
|
|
5
|
+
// the app by that layer's rules. It holds no secrets.
|
|
6
|
+
/** The three layers, each building on the one before. */
|
|
7
|
+
export const KIT_LAYERS = ["payments", "products", "pages"];
|
|
8
|
+
/** Where init records the layer, relative to the app's directory. */
|
|
9
|
+
export const KIT_CONFIG_FILE = "relyon/kit.json";
|
|
10
|
+
/** One line per layer, as init's question and help name them. */
|
|
11
|
+
export const KIT_LAYER_LABELS = Object.freeze({
|
|
12
|
+
payments: "Payments: accept card payments in your own app (no Relyon product catalog or shopping pages)",
|
|
13
|
+
products: "Products and agents: also list products so AI shopping agents can find and buy them",
|
|
14
|
+
pages: "Shopping pages: also have Relyon's kit build the shopping pages for you",
|
|
15
|
+
});
|
|
16
|
+
export function isKitLayer(value) {
|
|
17
|
+
return typeof value === "string" && KIT_LAYERS.includes(value);
|
|
18
|
+
}
|
|
19
|
+
/** The file's exact content for a layer. */
|
|
20
|
+
export function kitConfigContent(config) {
|
|
21
|
+
return `${JSON.stringify({ layer: config.layer }, null, 2)}\n`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The app's recorded layer: null when there is no `relyon/kit.json` (a store
|
|
25
|
+
* kit install from before layers, judged as before) or it is not a small
|
|
26
|
+
* regular file naming a known layer.
|
|
27
|
+
*/
|
|
28
|
+
export async function readKitConfig(projectDir) {
|
|
29
|
+
const file = path.join(projectDir, KIT_CONFIG_FILE);
|
|
30
|
+
try {
|
|
31
|
+
const stat = await lstat(file);
|
|
32
|
+
if (!stat.isFile() || stat.size > 4096)
|
|
33
|
+
return null;
|
|
34
|
+
const data = JSON.parse(await readFile(file, "utf8"));
|
|
35
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
36
|
+
return null;
|
|
37
|
+
const layer = data.layer;
|
|
38
|
+
return isKitLayer(layer) ? { layer } : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface KitEnvironment {
|
|
2
|
+
apiKey: string | undefined;
|
|
3
|
+
baseUrl: string | undefined;
|
|
4
|
+
/** True only for RELYON_LIVE=true. */
|
|
5
|
+
live: boolean;
|
|
6
|
+
projectSpace: string | undefined;
|
|
7
|
+
/** PUBLIC_URL when it is an absolute http(s) URL, else STORE_PUBLIC_URL. */
|
|
8
|
+
publicUrl: string | undefined;
|
|
9
|
+
webhookSecret: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The app's public origin from the environment. PUBLIC_URL wins when it is an
|
|
13
|
+
* absolute http(s) URL; other tools also use PUBLIC_URL for a path prefix
|
|
14
|
+
* (such as "/"), and that value is not an origin, so STORE_PUBLIC_URL is
|
|
15
|
+
* used then.
|
|
16
|
+
*/
|
|
17
|
+
export declare function publicUrlFromEnv(env?: NodeJS.ProcessEnv): string | undefined;
|
|
18
|
+
/** The project space's ID from RELYON_PROJECT_SPACE, if set. */
|
|
19
|
+
export declare function projectSpaceFromEnv(env?: NodeJS.ProcessEnv): string | undefined;
|
|
20
|
+
export declare function kitEnvironment(env?: NodeJS.ProcessEnv): KitEnvironment;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The environment the kit reads, in project-space vocabulary. New names first,
|
|
2
|
+
// the store kit's names still accepted:
|
|
3
|
+
// PUBLIC_URL the app's public origin (else STORE_PUBLIC_URL)
|
|
4
|
+
// RELYON_PROJECT_SPACE the project space's ID (optional in a single-space workspace)
|
|
5
|
+
// RELYON_API_KEY, RELYON_BASE_URL, RELYON_LIVE, RELYON_WEBHOOK_SECRET as before.
|
|
6
|
+
const set = (value) => value?.trim() || undefined;
|
|
7
|
+
/**
|
|
8
|
+
* The app's public origin from the environment. PUBLIC_URL wins when it is an
|
|
9
|
+
* absolute http(s) URL; other tools also use PUBLIC_URL for a path prefix
|
|
10
|
+
* (such as "/"), and that value is not an origin, so STORE_PUBLIC_URL is
|
|
11
|
+
* used then.
|
|
12
|
+
*/
|
|
13
|
+
export function publicUrlFromEnv(env = process.env) {
|
|
14
|
+
const publicUrl = set(env.PUBLIC_URL);
|
|
15
|
+
if (publicUrl && /^https?:\/\//i.test(publicUrl))
|
|
16
|
+
return publicUrl;
|
|
17
|
+
return set(env.STORE_PUBLIC_URL);
|
|
18
|
+
}
|
|
19
|
+
/** The project space's ID from RELYON_PROJECT_SPACE, if set. */
|
|
20
|
+
export function projectSpaceFromEnv(env = process.env) {
|
|
21
|
+
return set(env.RELYON_PROJECT_SPACE);
|
|
22
|
+
}
|
|
23
|
+
export function kitEnvironment(env = process.env) {
|
|
24
|
+
return {
|
|
25
|
+
apiKey: set(env.RELYON_API_KEY),
|
|
26
|
+
baseUrl: set(env.RELYON_BASE_URL),
|
|
27
|
+
live: env.RELYON_LIVE?.trim().toLowerCase() === "true",
|
|
28
|
+
projectSpace: projectSpaceFromEnv(env),
|
|
29
|
+
publicUrl: publicUrlFromEnv(env),
|
|
30
|
+
webhookSecret: set(env.RELYON_WEBHOOK_SECRET),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Browser-safe advisory data. No registry lookup, readiness or payment authority. */
|
|
2
|
+
export interface KitVersionSnapshot {
|
|
3
|
+
installed: string | null;
|
|
4
|
+
declared: string | null;
|
|
5
|
+
latest: string | null;
|
|
6
|
+
status: "up_to_date" | "update_available" | "ahead" | "mismatch" | "unknown";
|
|
7
|
+
install_command: string | null;
|
|
8
|
+
package_manager: "npm" | "pnpm" | "yarn" | "bun" | null;
|
|
9
|
+
checked_at: string | null;
|
|
10
|
+
hold: {
|
|
11
|
+
minutes: number;
|
|
12
|
+
source_file: string;
|
|
13
|
+
installable_at: string;
|
|
14
|
+
} | null;
|
|
15
|
+
messages: string[];
|
|
16
|
+
}
|
|
17
|
+
export type KitVersionEvidence = {
|
|
18
|
+
state: "reported";
|
|
19
|
+
snapshot: KitVersionSnapshot;
|
|
20
|
+
} | {
|
|
21
|
+
state: "rejected";
|
|
22
|
+
snapshot: null;
|
|
23
|
+
};
|
|
24
|
+
export interface KitVersionObservation {
|
|
25
|
+
runId: string;
|
|
26
|
+
observedAt: string;
|
|
27
|
+
source: "merchant-reported";
|
|
28
|
+
evidence: KitVersionEvidence;
|
|
29
|
+
}
|
|
30
|
+
export interface KitReleaseNote {
|
|
31
|
+
version: string;
|
|
32
|
+
/** Historical dates not recorded in the original changelog remain explicitly unknown. */
|
|
33
|
+
date: string | null;
|
|
34
|
+
notable: "security" | "feature" | null;
|
|
35
|
+
summary: string;
|
|
36
|
+
details: string;
|
|
37
|
+
unpublished: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare const KIT_VERSION_HEADER = "Relyon-Kit-Diagnostic";
|
|
40
|
+
export declare const KIT_VERSION_EVIDENCE_BYTES = 6000;
|
|
41
|
+
/** Reject, never partially repair an untrusted report. Commands are display-only. */
|
|
42
|
+
export declare function validKitVersionSnapshot(v: unknown): v is KitVersionSnapshot;
|
|
43
|
+
export declare function encodeKitVersionSnapshot(value: KitVersionSnapshot): string | null;
|
|
44
|
+
export declare function parseKitVersionEvidence(wire: string | undefined): KitVersionEvidence | undefined;
|
|
45
|
+
/** Release relevance only; never diagnoses status or chooses an install target. */
|
|
46
|
+
export declare function relevantKitReleases(notes: readonly KitReleaseNote[], kit: KitVersionSnapshot | null): KitReleaseNote[];
|
|
47
|
+
export declare function lovableKitUpdate(kit: KitVersionSnapshot | null): string | null;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
import { KIT_VERSION_EVIDENCE_HEADER } from "./wire-names.js";
|
|
3
|
+
export const KIT_VERSION_HEADER = KIT_VERSION_EVIDENCE_HEADER;
|
|
4
|
+
export const KIT_VERSION_EVIDENCE_BYTES = 6000;
|
|
5
|
+
const version = (s) => typeof s === "string" && /^(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})(?:-[0-9A-Za-z.-]{1,60})?(?:\+[0-9A-Za-z.-]{1,60})?$/.test(s);
|
|
6
|
+
const record = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
7
|
+
const keys = (v, expected) => Object.keys(v).length === expected.length && expected.every(k => Object.hasOwn(v, k));
|
|
8
|
+
const safeText = (s, max) => typeof s === "string" && s.length <= max
|
|
9
|
+
&& !/[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(s)
|
|
10
|
+
&& !/(?:rly|rk|sk|pk|whsec|rly_whsec)_(?:test_|live_)?[A-Za-z0-9_-]{6,}|:\/\/|(?:^|[\s("'=])\/[A-Za-z0-9._-]|[A-Z]:\\/i.test(s)
|
|
11
|
+
&& !/\b(?:sk-ant-|sk-(?:proj-|svcacct-|admin-)?|gh[pousr]_|github_pat_|npm_)[A-Za-z0-9_-]{12,}|\bBearer\s+\S+|-----BEGIN .*PRIVATE KEY-----/i.test(s);
|
|
12
|
+
const timestamp = (s) => typeof s === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(s) && Number.isFinite(Date.parse(s));
|
|
13
|
+
/** Reject, never partially repair an untrusted report. Commands are display-only. */
|
|
14
|
+
export function validKitVersionSnapshot(v) {
|
|
15
|
+
if (!record(v) || !keys(v, ["installed", "declared", "latest", "status", "install_command", "package_manager", "checked_at", "hold", "messages"]))
|
|
16
|
+
return false;
|
|
17
|
+
if (![v.installed, v.latest].every(x => x === null || version(x)))
|
|
18
|
+
return false;
|
|
19
|
+
if (!(v.declared === null || (safeText(v.declared, 200) && /^[0-9A-Za-z.*^~<>=| +\-]+$/.test(v.declared))))
|
|
20
|
+
return false;
|
|
21
|
+
if (typeof v.status !== "string" || !["up_to_date", "update_available", "ahead", "mismatch", "unknown"].includes(v.status))
|
|
22
|
+
return false;
|
|
23
|
+
if (v.package_manager !== null && (typeof v.package_manager !== "string" || !["npm", "pnpm", "yarn", "bun"].includes(v.package_manager)))
|
|
24
|
+
return false;
|
|
25
|
+
if (v.checked_at !== null && !timestamp(v.checked_at))
|
|
26
|
+
return false;
|
|
27
|
+
if (!Array.isArray(v.messages) || v.messages.length > 16 || !v.messages.every(x => safeText(x, 700)))
|
|
28
|
+
return false;
|
|
29
|
+
if (v.install_command !== null) {
|
|
30
|
+
if (!v.latest || !v.package_manager || !safeText(v.install_command, 180))
|
|
31
|
+
return false;
|
|
32
|
+
const verb = v.package_manager === "npm" ? "install --save-exact" : v.package_manager === "pnpm" ? "add --save-exact" : "add --exact";
|
|
33
|
+
// The store kit, or the @relyon/kit package it now wraps.
|
|
34
|
+
if (![`${v.package_manager} ${verb} @relyon/store-kit@${v.latest}`, `${v.package_manager} ${verb} @relyon/kit@${v.latest}`].includes(v.install_command))
|
|
35
|
+
return false;
|
|
36
|
+
if (v.status === "ahead" || v.status === "up_to_date")
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (v.hold !== null && (!record(v.hold) || !keys(v.hold, ["minutes", "source_file", "installable_at"])
|
|
40
|
+
|| !Number.isSafeInteger(v.hold.minutes) || Number(v.hold.minutes) < 0
|
|
41
|
+
|| !safeText(v.hold.source_file, 200) || !/^(?:\.\.\/)*(?:pnpm-workspace\.yaml|\.npmrc|package\.json)$/.test(v.hold.source_file)
|
|
42
|
+
|| !timestamp(v.hold.installable_at)))
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
export function encodeKitVersionSnapshot(value) {
|
|
47
|
+
if (!validKitVersionSnapshot(value))
|
|
48
|
+
return null;
|
|
49
|
+
const wire = encodeURIComponent(JSON.stringify(value));
|
|
50
|
+
return wire.length <= KIT_VERSION_EVIDENCE_BYTES ? wire : null;
|
|
51
|
+
}
|
|
52
|
+
export function parseKitVersionEvidence(wire) {
|
|
53
|
+
if (wire === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
try {
|
|
56
|
+
if (wire.length > KIT_VERSION_EVIDENCE_BYTES)
|
|
57
|
+
throw Error();
|
|
58
|
+
const value = JSON.parse(decodeURIComponent(wire));
|
|
59
|
+
if (!validKitVersionSnapshot(value))
|
|
60
|
+
throw Error();
|
|
61
|
+
return { state: "reported", snapshot: value };
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return { state: "rejected", snapshot: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Release relevance only; never diagnoses status or chooses an install target. */
|
|
68
|
+
export function relevantKitReleases(notes, kit) {
|
|
69
|
+
if (!kit?.installed || !kit.latest || !kit.checked_at || kit.status === "ahead" || kit.status === "unknown"
|
|
70
|
+
|| !semver.valid(kit.installed) || !semver.valid(kit.latest))
|
|
71
|
+
return [];
|
|
72
|
+
return notes.filter(n => !!semver.valid(n.version) && semver.gt(n.version, kit.installed) && semver.lte(n.version, kit.latest));
|
|
73
|
+
}
|
|
74
|
+
export function lovableKitUpdate(kit) {
|
|
75
|
+
return kit?.latest && (kit.status === "update_available" || (kit.status === "mismatch" && !!kit.install_command))
|
|
76
|
+
? `Update @relyon/store-kit to exactly ${kit.latest} and run the doctor` : null;
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
2
|
+
export interface VersionProject {
|
|
3
|
+
installed: string | null;
|
|
4
|
+
declared: string | null;
|
|
5
|
+
packageManager: PackageManager | null;
|
|
6
|
+
registry: string | null;
|
|
7
|
+
age: {
|
|
8
|
+
minutes: number;
|
|
9
|
+
source_file: string;
|
|
10
|
+
} | null;
|
|
11
|
+
issues: string[];
|
|
12
|
+
mismatch: boolean;
|
|
13
|
+
notInstalled: boolean;
|
|
14
|
+
unsupportedDeclaration: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Bounded configuration reads; installed manifests deliberately follow Node's symlinks. */
|
|
17
|
+
export declare function smallFile(file: string): Promise<string | null>;
|
|
18
|
+
export declare function discoverVersionProject(project: string, env: NodeJS.ProcessEnv): Promise<VersionProject>;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { kitIdentity } from "./identity.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { lstat, readFile, realpath, stat } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { parseDocument } from "yaml";
|
|
6
|
+
import semver from "semver";
|
|
7
|
+
/** Bounded configuration reads; installed manifests deliberately follow Node's symlinks. */
|
|
8
|
+
export async function smallFile(file) {
|
|
9
|
+
try {
|
|
10
|
+
const stat = await lstat(file);
|
|
11
|
+
if (!stat.isFile() || stat.size > 1024 * 1024)
|
|
12
|
+
throw Error("not a small regular file");
|
|
13
|
+
return await readFile(file, "utf8");
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === "ENOENT")
|
|
17
|
+
return null;
|
|
18
|
+
throw Error("file unavailable");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const record = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
22
|
+
const manager = (v) => typeof v === "string" && /^(npm|pnpm|yarn|bun)(?:@|$)/.test(v) ? v.split("@")[0] : null;
|
|
23
|
+
export async function discoverVersionProject(project, env) {
|
|
24
|
+
const out = { installed: null, declared: null, packageManager: null, registry: "https://registry.npmjs.org/", age: null, issues: [], mismatch: false, notInstalled: false, unsupportedDeclaration: false };
|
|
25
|
+
const root = await realpath(project);
|
|
26
|
+
try {
|
|
27
|
+
// An explicit file anchor avoids resolving relative to the running/npx kit.
|
|
28
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
29
|
+
const kitName = kitIdentity().name;
|
|
30
|
+
let file;
|
|
31
|
+
try {
|
|
32
|
+
file = require.resolve(`${kitName}/package.json`);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code !== "ERR_PACKAGE_PATH_NOT_EXPORTED")
|
|
36
|
+
throw error;
|
|
37
|
+
// Older kits do not export package.json. Use Node's own package search
|
|
38
|
+
// paths, not the running kit location, retaining pnpm/workspace symlinks.
|
|
39
|
+
for (const base of require.resolve.paths(kitName) ?? []) {
|
|
40
|
+
const candidate = path.join(base, kitName, "package.json");
|
|
41
|
+
try {
|
|
42
|
+
await stat(candidate);
|
|
43
|
+
file = candidate;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e.code !== "ENOENT")
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!file || (await stat(file)).size > 1024 * 1024)
|
|
53
|
+
throw Error();
|
|
54
|
+
const pkg = JSON.parse(await readFile(file, "utf8"));
|
|
55
|
+
if (pkg.name !== kitName || typeof pkg.version !== "string" || !semver.valid(pkg.version))
|
|
56
|
+
throw Error();
|
|
57
|
+
out.installed = pkg.version;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
out.mismatch = true;
|
|
61
|
+
out.notInstalled = error.code === "MODULE_NOT_FOUND";
|
|
62
|
+
out.issues.push(out.notInstalled
|
|
63
|
+
? `${kitIdentity().name} is not installed in this store project. Restore the declared dependency with the project's normal package-manager install in this store package, then rerun doctor.`
|
|
64
|
+
: `The installed ${kitIdentity().name} package manifest could not be resolved or has an invalid version. Repair the dependency installation in this store package and rerun doctor; verify the installed version before choosing a replacement.`);
|
|
65
|
+
}
|
|
66
|
+
let registry;
|
|
67
|
+
let scoped;
|
|
68
|
+
let ageFound = false;
|
|
69
|
+
let projectManifestSeen = false;
|
|
70
|
+
const read = async (file) => {
|
|
71
|
+
try {
|
|
72
|
+
return await smallFile(file);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
out.issues.push(`Could not read ${path.basename(file)} settings.`);
|
|
76
|
+
out.registry = null;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const age = (value, file) => {
|
|
81
|
+
if (ageFound || value === undefined)
|
|
82
|
+
return;
|
|
83
|
+
ageFound = true;
|
|
84
|
+
if ((typeof value === "number" || typeof value === "string") && String(value).trim() !== "" && Number.isSafeInteger(Number(value)) && Number(value) >= 0) {
|
|
85
|
+
out.age = { minutes: Number(value), source_file: path.relative(root, file) || path.basename(file) };
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
out.issues.push("minimumReleaseAge is invalid; its hold cannot be determined. Fix the package setting.");
|
|
89
|
+
};
|
|
90
|
+
const npmrc = async (file) => {
|
|
91
|
+
const text = await read(file);
|
|
92
|
+
if (text === null)
|
|
93
|
+
return;
|
|
94
|
+
const values = {};
|
|
95
|
+
for (const line of text.split(/\r?\n/)) {
|
|
96
|
+
const match = /^\s*([^#;][^=]*?)\s*=\s*(.*?)\s*$/.exec(line);
|
|
97
|
+
if (match)
|
|
98
|
+
values[match[1]] = match[2].replace(/^(["'])(.*)\1$/, "$2").replace(/\$\{([^}]+)\}/g, (_, key) => env[key] ?? "${UNRESOLVED}");
|
|
99
|
+
}
|
|
100
|
+
scoped ??= values["@relyon:registry"];
|
|
101
|
+
registry ??= values.registry;
|
|
102
|
+
age(values["minimum-release-age"] ?? values.minimumReleaseAge, file);
|
|
103
|
+
};
|
|
104
|
+
// Nearest project/workspace settings win. Workspace YAML precedes legacy
|
|
105
|
+
// npmrc/package.json pnpm settings in the same directory.
|
|
106
|
+
let dir = root;
|
|
107
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
108
|
+
const workspaceFile = path.join(dir, "pnpm-workspace.yaml");
|
|
109
|
+
const yaml = await read(workspaceFile);
|
|
110
|
+
if (yaml !== null) {
|
|
111
|
+
try {
|
|
112
|
+
const doc = parseDocument(yaml);
|
|
113
|
+
if (doc.errors.length)
|
|
114
|
+
throw Error();
|
|
115
|
+
const value = doc.toJS({ maxAliasCount: 20 });
|
|
116
|
+
if (record(value))
|
|
117
|
+
age(value.minimumReleaseAge, workspaceFile);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
out.issues.push("pnpm-workspace.yaml is malformed; package-age settings are unavailable.");
|
|
121
|
+
ageFound = true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
await npmrc(path.join(dir, ".npmrc"));
|
|
125
|
+
const file = path.join(dir, "package.json");
|
|
126
|
+
const text = await read(file);
|
|
127
|
+
if (text !== null) {
|
|
128
|
+
try {
|
|
129
|
+
const pkg = JSON.parse(text);
|
|
130
|
+
if (!record(pkg))
|
|
131
|
+
throw Error();
|
|
132
|
+
if (dir === root) {
|
|
133
|
+
projectManifestSeen = true;
|
|
134
|
+
const declarations = ["dependencies", "devDependencies", "optionalDependencies"].flatMap(field => record(pkg[field]) && pkg[field][kitIdentity().name] !== undefined ? [pkg[field][kitIdentity().name]] : []);
|
|
135
|
+
if (!declarations.length) {
|
|
136
|
+
out.mismatch = true;
|
|
137
|
+
out.issues.push(`package.json does not declare ${kitIdentity().name}. Add it as a direct dependency.`);
|
|
138
|
+
}
|
|
139
|
+
else if (declarations.some(v => typeof v !== "string" || !v.trim() || v !== declarations[0])) {
|
|
140
|
+
out.mismatch = true;
|
|
141
|
+
out.issues.push("package.json has malformed or conflicting kit declarations. Set one compatible semver dependency.");
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const value = declarations[0];
|
|
145
|
+
// Never echo unsupported declarations: URLs/local paths can carry credentials.
|
|
146
|
+
if (!semver.validRange(value)) {
|
|
147
|
+
out.unsupportedDeclaration = true;
|
|
148
|
+
out.issues.push("The kit declaration is local or unsupported, not a semver range. Verify its source manually; no registry install is suggested.");
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
out.declared = value;
|
|
152
|
+
if (out.installed && !semver.satisfies(out.installed, value)) {
|
|
153
|
+
out.mismatch = true;
|
|
154
|
+
out.issues.push(`The installed kit (${out.installed}) does not satisfy package.json (${value}). Reconcile the declaration and reinstall in this store package.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
out.packageManager ??= manager(pkg.packageManager);
|
|
160
|
+
if (record(pkg.pnpm))
|
|
161
|
+
age(pkg.pnpm.minimumReleaseAge, file);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
out.mismatch = true;
|
|
165
|
+
out.issues.push("package.json is malformed. Fix it and reinstall the kit in the store package.");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!out.packageManager) {
|
|
169
|
+
for (const [lock, pm] of [["pnpm-lock.yaml", "pnpm"], ["yarn.lock", "yarn"], ["bun.lock", "bun"], ["bun.lockb", "bun"], ["package-lock.json", "npm"]]) {
|
|
170
|
+
try {
|
|
171
|
+
if ((await lstat(path.join(dir, lock))).isFile()) {
|
|
172
|
+
out.packageManager = pm;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch { /* absent lockfile is not evidence */ }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const parent = path.dirname(dir);
|
|
180
|
+
if (parent === dir)
|
|
181
|
+
break;
|
|
182
|
+
if (depth === 63) {
|
|
183
|
+
out.registry = null;
|
|
184
|
+
out.issues.push("Project ancestry exceeds the settings discovery limit.");
|
|
185
|
+
}
|
|
186
|
+
dir = parent;
|
|
187
|
+
}
|
|
188
|
+
if (!projectManifestSeen) {
|
|
189
|
+
out.mismatch = true;
|
|
190
|
+
out.issues.push("The store project's package.json is missing or unreadable. Create or fix it and declare the kit in this package.");
|
|
191
|
+
}
|
|
192
|
+
if (env.NPM_CONFIG_USERCONFIG || env.npm_config_userconfig || env.HOME) {
|
|
193
|
+
await npmrc(env.NPM_CONFIG_USERCONFIG ?? env.npm_config_userconfig ?? path.join(env.HOME, ".npmrc"));
|
|
194
|
+
}
|
|
195
|
+
if (env.NPM_CONFIG_GLOBALCONFIG || env.npm_config_globalconfig) {
|
|
196
|
+
await npmrc(env.NPM_CONFIG_GLOBALCONFIG ?? env.npm_config_globalconfig);
|
|
197
|
+
}
|
|
198
|
+
// npm selects the package scope's registry before the generic registry,
|
|
199
|
+
// including when the generic setting came from the environment.
|
|
200
|
+
const configured = scoped ?? env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY ?? registry ?? out.registry;
|
|
201
|
+
try {
|
|
202
|
+
if (!out.registry || !configured)
|
|
203
|
+
throw Error();
|
|
204
|
+
const url = new URL(configured);
|
|
205
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || configured.includes("${"))
|
|
206
|
+
throw Error();
|
|
207
|
+
out.registry = url.href.replace(/\/?$/, "/");
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
out.registry = null;
|
|
211
|
+
out.issues.push("The configured registry is invalid or unavailable. Check .npmrc; no registry credentials are printed.");
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type PackageManager } from "./kit-version-project.js";
|
|
2
|
+
import type { KitVersionSnapshot } from "./kit-updates.js";
|
|
3
|
+
/** All unavailable scalar evidence is null (never an omitted value or bundled-version guess). */
|
|
4
|
+
export interface KitVersionResult extends KitVersionSnapshot {
|
|
5
|
+
installed: string | null;
|
|
6
|
+
declared: string | null;
|
|
7
|
+
latest: string | null;
|
|
8
|
+
status: "up_to_date" | "update_available" | "ahead" | "mismatch" | "unknown";
|
|
9
|
+
install_command: string | null;
|
|
10
|
+
package_manager: PackageManager | null;
|
|
11
|
+
checked_at: string | null;
|
|
12
|
+
hold: {
|
|
13
|
+
minutes: number;
|
|
14
|
+
source_file: string;
|
|
15
|
+
installable_at: string;
|
|
16
|
+
} | null;
|
|
17
|
+
/** Safe explanations; never raw errors or registry configuration. */
|
|
18
|
+
messages: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface KitVersionCache {
|
|
21
|
+
read(): Promise<string | null>;
|
|
22
|
+
write(text: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface KitVersionOptions {
|
|
25
|
+
projectDir?: string | undefined;
|
|
26
|
+
env?: NodeJS.ProcessEnv;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
fetch?: typeof fetch;
|
|
29
|
+
cache?: KitVersionCache;
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare const KIT_VERSION_UNAVAILABLE = "Couldn't check for a newer kit version (offline?)";
|
|
33
|
+
export declare function unknownKitVersion(): KitVersionResult;
|
|
34
|
+
/** Advisory, read-only project diagnosis. Network and body reading share one hard deadline. */
|
|
35
|
+
export declare function diagnoseKitVersion(options?: KitVersionOptions): Promise<KitVersionResult>;
|
|
36
|
+
/** Legacy shape is optional string, derived only from this observation. */
|
|
37
|
+
export declare function legacyNewerKitVersion(result: KitVersionResult): string | undefined;
|