Fork Horse repository, listed by its owner. Publisher snapshot.
packages/forkhorse-gatekeeper/src/configuration.ts
Snapshot at 34e3175
1export interface ConnectionDraft {
2 coreOrigin: string;
3 project: string;
4 agentCredential: string;
5}
6
7export interface DraftStatus {
8 coreOrigin: string;
9 project: string;
10 connectionAvailable: false;
11 message: string;
12}
13
14export const CONNECTION_HELD = "This fixture checks format only. Open the account connection popup to connect.";
15
16/** Format checking only. Never fetch, store, echo or infer identity from an entered credential. */
17export function checkConnectionDraft(draft: ConnectionDraft): DraftStatus {
18 if (!draft || typeof draft.coreOrigin !== "string" || draft.coreOrigin.length > 2048)
19 throw new Error("Enter a public HTTPS core origin.");
20 let url: URL;
21 try { url = new URL(draft.coreOrigin.trim()); }
22 catch { throw new Error("Enter a public HTTPS core origin."); }
23 if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash ||
24 url.pathname !== "/" || (url.port && url.port !== "443") ||
25 !url.hostname.includes(".") || /^[\d.]+$/.test(url.hostname) || url.hostname.includes(":") ||
26 /\.(localhost|local|internal|invalid)$/.test(url.hostname))
27 throw new Error("Enter a public HTTPS core origin without a path, credentials or query.");
28 if (typeof draft.project !== "string" || draft.project.length > 48 ||
29 !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(draft.project))
30 throw new Error("Enter a lowercase project ID of at most 48 characters.");
31 if (typeof draft.agentCredential !== "string" || !/^[A-Za-z0-9_-]{16,256}$/.test(draft.agentCredential))
32 throw new Error("Enter an enrolled agent credential without spaces (16 to 256 characters).");
33 return {
34 coreOrigin: url.origin,
35 project: draft.project,
36 connectionAvailable: false,
37 message: CONNECTION_HELD,
38 };
39}
40