scribase 0.1.0 → 0.2.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/CHANGELOG.md +23 -0
- package/README.md +28 -10
- package/dist/cli/add.d.ts +98 -0
- package/dist/cli/add.d.ts.map +1 -0
- package/dist/cli/add.js +356 -0
- package/dist/cli/add.js.map +1 -0
- package/dist/cli/aliases.d.ts +9 -0
- package/dist/cli/aliases.d.ts.map +1 -0
- package/dist/cli/aliases.js +14 -0
- package/dist/cli/aliases.js.map +1 -0
- package/dist/cli/capabilities/ota.d.ts +80 -0
- package/dist/cli/capabilities/ota.d.ts.map +1 -0
- package/dist/cli/capabilities/ota.js +307 -0
- package/dist/cli/capabilities/ota.js.map +1 -0
- package/dist/cli/capabilities/railyard/ai.d.ts +14 -0
- package/dist/cli/capabilities/railyard/ai.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/ai.js +33 -0
- package/dist/cli/capabilities/railyard/ai.js.map +1 -0
- package/dist/cli/capabilities/railyard/analytics.d.ts +27 -0
- package/dist/cli/capabilities/railyard/analytics.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/analytics.js +72 -0
- package/dist/cli/capabilities/railyard/analytics.js.map +1 -0
- package/dist/cli/capabilities/railyard/billing.d.ts +14 -0
- package/dist/cli/capabilities/railyard/billing.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/billing.js +39 -0
- package/dist/cli/capabilities/railyard/billing.js.map +1 -0
- package/dist/cli/capabilities/railyard/consent-files.d.ts +16 -0
- package/dist/cli/capabilities/railyard/consent-files.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/consent-files.js +24 -0
- package/dist/cli/capabilities/railyard/consent-files.js.map +1 -0
- package/dist/cli/capabilities/railyard/consent.d.ts +12 -0
- package/dist/cli/capabilities/railyard/consent.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/consent.js +38 -0
- package/dist/cli/capabilities/railyard/consent.js.map +1 -0
- package/dist/cli/capabilities/railyard/deploy.d.ts +16 -0
- package/dist/cli/capabilities/railyard/deploy.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/deploy.js +68 -0
- package/dist/cli/capabilities/railyard/deploy.js.map +1 -0
- package/dist/cli/capabilities/railyard/flags.d.ts +18 -0
- package/dist/cli/capabilities/railyard/flags.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/flags.js +45 -0
- package/dist/cli/capabilities/railyard/flags.js.map +1 -0
- package/dist/cli/capabilities/railyard/index.d.ts +55 -0
- package/dist/cli/capabilities/railyard/index.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/index.js +217 -0
- package/dist/cli/capabilities/railyard/index.js.map +1 -0
- package/dist/cli/capabilities/railyard/uptime.d.ts +18 -0
- package/dist/cli/capabilities/railyard/uptime.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/uptime.js +47 -0
- package/dist/cli/capabilities/railyard/uptime.js.map +1 -0
- package/dist/cli/credentials.d.ts +8 -0
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +27 -0
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/doctor.d.ts +51 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +265 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/envfile.d.ts +11 -0
- package/dist/cli/envfile.d.ts.map +1 -1
- package/dist/cli/envfile.js +49 -0
- package/dist/cli/envfile.js.map +1 -1
- package/dist/cli/framework.d.ts +16 -1
- package/dist/cli/framework.d.ts.map +1 -1
- package/dist/cli/framework.js +95 -2
- package/dist/cli/framework.js.map +1 -1
- package/dist/cli/index.d.ts +4 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +166 -19
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +62 -7
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +203 -23
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/migrate.d.ts +70 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +264 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli/sql.d.ts +59 -0
- package/dist/cli/sql.d.ts.map +1 -0
- package/dist/cli/sql.js +174 -0
- package/dist/cli/sql.js.map +1 -0
- package/dist/types.gen.d.ts +11 -1
- package/dist/types.gen.d.ts.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { InitError } from '../../init.js';
|
|
2
|
+
const POLL_MS = 3_000;
|
|
3
|
+
function toSeconds(at) {
|
|
4
|
+
return typeof at === 'number' ? at : Math.floor(Date.parse(at) / 1000);
|
|
5
|
+
}
|
|
6
|
+
export async function billingConnect(result, io, options, ctx, readSlot) {
|
|
7
|
+
if (result.status !== 'live')
|
|
8
|
+
return result;
|
|
9
|
+
if (ctx.answer.state === 'live' && ctx.answer.proof)
|
|
10
|
+
return result;
|
|
11
|
+
if (ctx.answer.state === 'no_proof_yet') {
|
|
12
|
+
return { ...result, next: 'Connected. Add a product and make one test purchase in Environment > Add-ons > Billing.' };
|
|
13
|
+
}
|
|
14
|
+
const link = ctx.answer.connect_url;
|
|
15
|
+
if (!link || !/^https?:\/\//.test(link))
|
|
16
|
+
throw new InitError('invalid_response', 'the control plane did not return a connect link');
|
|
17
|
+
io.log(`Connect your payment account in the browser (nothing to type here): ${link}`);
|
|
18
|
+
if (options.browser)
|
|
19
|
+
io.openBrowser(link);
|
|
20
|
+
if (!options.wait) {
|
|
21
|
+
return { ...result, status: 'needs_connect', live: false, connect_url: link, next: 'connect your account on the page, then run `npx scribase add billing` again' };
|
|
22
|
+
}
|
|
23
|
+
io.log('Waiting for the connection...');
|
|
24
|
+
const deadline = io.now() + options.waitSeconds * 1_000;
|
|
25
|
+
for (;;) {
|
|
26
|
+
await io.sleep(POLL_MS);
|
|
27
|
+
const state = await readSlot(io, ctx);
|
|
28
|
+
if (state.state === 'live' && state.proof) {
|
|
29
|
+
return { ...result, live: true, proof: { kind: state.proof.kind, id: state.proof.id, at: toSeconds(state.proof.at) }, sent: true, next: null };
|
|
30
|
+
}
|
|
31
|
+
if (state.state === 'no_proof_yet') {
|
|
32
|
+
return { ...result, next: 'Connected. Add a product and make one test purchase in Environment > Add-ons > Billing.' };
|
|
33
|
+
}
|
|
34
|
+
if (io.now() >= deadline) {
|
|
35
|
+
throw new InitError('connect_timeout', `no account was connected within ${options.waitSeconds} s`, 'open the link again from `npx scribase add billing`');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/billing.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,OAAO,GAAG,KAAK,CAAC;AAItB,SAAS,SAAS,CAAC,EAAmB;IACpC,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAiB,EAAE,EAAS,EAAE,OAAmB,EAAE,GAAgB,EAAE,QAAkB;IAC1H,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC;IACnE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,cAAc,EAAE,CAAC;QACxC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,yFAAyF,EAAE,CAAC;IACxH,CAAC;IACD,MAAM,IAAI,GAAG,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Ac,EAAE,CAAC;YACnC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,yFAAyF,EAAE,CAAC;QACxH,CAAC;QACD,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,SAAS,CAAC,iBAAiB,EAAE,mCAAmC,OAAO,CAAC,WAAW,IAAI,EAAE,qDAAqD,CAAC,CAAC;QAC5J,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent templates `npx scribase add consent` copies into an app (Wave
|
|
3
|
+
* P PY2.5). Generated from `templates/consent/**`; railyard.test.mjs checks
|
|
4
|
+
* they stay byte-identical. Do not edit here: edit the template and copy.
|
|
5
|
+
*/
|
|
6
|
+
export interface TemplateFile {
|
|
7
|
+
/** Where it goes in the app folder. */
|
|
8
|
+
path: string;
|
|
9
|
+
/** The repository template it comes from. */
|
|
10
|
+
template: string;
|
|
11
|
+
/** Only for Next.js apps. */
|
|
12
|
+
next?: boolean;
|
|
13
|
+
contents: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const CONSENT_FILES: readonly TemplateFile[];
|
|
16
|
+
//# sourceMappingURL=consent-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-files.d.ts","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/consent-files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EAiB/C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent templates `npx scribase add consent` copies into an app (Wave
|
|
3
|
+
* P PY2.5). Generated from `templates/consent/**`; railyard.test.mjs checks
|
|
4
|
+
* they stay byte-identical. Do not edit here: edit the template and copy.
|
|
5
|
+
*/
|
|
6
|
+
export const CONSENT_FILES = Object.freeze([
|
|
7
|
+
{
|
|
8
|
+
path: "consent/consent-core.js",
|
|
9
|
+
template: "templates/consent/web/consent-core.js",
|
|
10
|
+
contents: "// Consent for your app (Scribase, the consent slot; Wave P PY2.5). No\n// dependencies. Categories follow the common consent-manager names\n// (necessary, measurement, marketing, functionality, experience), so another\n// banner can replace this one later without changing your checks.\n//\n// const consent = createConsent({ supabaseUrl, anonKey, policyVersion: '1' });\n// consent.allowed('measurement') // false until the person agrees\n// await consent.decide({ measurement: true, marketing: false });\n//\n// Every decision is stored on this device and added, with its time and the\n// policy version, to the insert-only consent_records table of your project.\n\nexport const CATEGORIES = ['necessary', 'measurement', 'marketing', 'functionality', 'experience'];\nconst STORE_KEY = 'scribase-consent';\n\nfunction randomId() {\n const bytes = new Uint8Array(16);\n globalThis.crypto.getRandomValues(bytes);\n return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n\nexport function createConsent({ supabaseUrl, anonKey, policyVersion = '1', storage = globalThis.localStorage, fetchImpl = globalThis.fetch?.bind(globalThis), source = 'web' } = {}) {\n if (!supabaseUrl || !anonKey) throw new Error('createConsent needs supabaseUrl and anonKey');\n const read = () => {\n try {\n const saved = JSON.parse(storage?.getItem(STORE_KEY) ?? 'null');\n return saved && saved.version === policyVersion ? saved : null;\n } catch {\n return null;\n }\n };\n let state = read();\n const listeners = new Set();\n const subject = () => {\n let id = null;\n try {\n id = storage?.getItem(`${STORE_KEY}:subject`) ?? null;\n if (!id) {\n id = randomId();\n storage?.setItem(`${STORE_KEY}:subject`, id);\n }\n } catch {\n id = id ?? randomId();\n }\n return id;\n };\n return {\n /** Whether the person decided under the current policy version. */\n decided: () => state !== null,\n /** `necessary` is always allowed; everything else only after a yes. */\n allowed: (category) => category === 'necessary' || state?.choices?.[category] === true,\n current: () => (state ? { ...state.choices } : null),\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n /** Saves the choice here and records it in your project. Resolves true when recorded. */\n async decide(choices) {\n const clean = Object.fromEntries(CATEGORIES.map((c) => [c, c === 'necessary' ? true : choices?.[c] === true]));\n state = { version: policyVersion, choices: clean, at: new Date().toISOString() };\n try {\n storage?.setItem(STORE_KEY, JSON.stringify(state));\n } catch {\n // Private mode: the choice holds for this page.\n }\n for (const l of listeners) l({ ...clean });\n if (!fetchImpl) return false;\n try {\n const res = await fetchImpl(`${supabaseUrl.replace(/\\/+$/, '')}/rest/v1/consent_records`, {\n method: 'POST',\n headers: { apikey: anonKey, authorization: `Bearer ${anonKey}`, 'content-type': 'application/json', prefer: 'return=minimal' },\n body: JSON.stringify({ subject_id: subject(), choices: clean, policy_version: policyVersion, source }),\n });\n return res.ok;\n } catch {\n return false;\n }\n },\n };\n}\n\n/**\n * Loads the analytics page tag only once measurement is allowed. Before that\n * (and after a no) no analytics request leaves the browser: the script is\n * never added to the page.\n */\nexport function loadAnalyticsWhenAllowed(consent, { scriptUrl, site, doc = globalThis.document }) {\n let loaded = false;\n const load = () => {\n if (loaded || !consent.allowed('measurement') || !doc) return;\n loaded = true;\n const s = doc.createElement('script');\n s.defer = true;\n s.src = scriptUrl;\n s.setAttribute('data-site', site);\n doc.head.appendChild(s);\n };\n load();\n const stop = consent.subscribe(load);\n return () => stop();\n}\n",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
path: "consent/banner.js",
|
|
14
|
+
template: "templates/consent/web/banner.js",
|
|
15
|
+
contents: "// A plain consent banner for any web page (Scribase, the consent slot).\n// Include after consent-core.js; it shows once, until the person decides.\n//\n// <script type=\"module\">\n// import { createConsent, loadAnalyticsWhenAllowed } from './consent/consent-core.js';\n// import { showBanner } from './consent/banner.js';\n// const consent = createConsent({ supabaseUrl: '...', anonKey: '...', policyVersion: '1' });\n// loadAnalyticsWhenAllowed(consent, { scriptUrl: '...', site: 'ry_site_...' });\n// showBanner(consent, { privacyUrl: '/privacy' });\n// </script>\n\nexport function showBanner(consent, { privacyUrl = '/privacy', doc = globalThis.document, text = {} } = {}) {\n if (!doc || consent.decided()) return null;\n const t = {\n body: 'We use cookies and similar tools to measure how the app is used. Choose what you allow.',\n accept: 'Allow all',\n reject: 'Only necessary',\n privacy: 'Privacy',\n ...text,\n };\n const box = doc.createElement('div');\n box.setAttribute('role', 'dialog');\n box.setAttribute('aria-label', 'Consent');\n box.style.cssText = 'position:fixed;left:16px;right:16px;bottom:16px;max-width:560px;margin:0 auto;padding:16px;border-radius:12px;background:#fff;color:#1b1f24;box-shadow:0 8px 30px rgba(0,0,0,.15);font:14px/1.5 system-ui,sans-serif;z-index:2147483000';\n const p = doc.createElement('p');\n p.textContent = `${t.body} `;\n const link = doc.createElement('a');\n link.href = privacyUrl;\n link.textContent = t.privacy;\n p.appendChild(link);\n const row = doc.createElement('div');\n row.style.cssText = 'display:flex;gap:8px;justify-content:flex-end;margin-top:8px';\n const button = (label, primary, choices) => {\n const b = doc.createElement('button');\n b.type = 'button';\n b.textContent = label;\n b.style.cssText = `padding:8px 14px;border-radius:8px;border:1px solid #1b1f24;cursor:pointer;${primary ? 'background:#1b1f24;color:#fff' : 'background:#fff;color:#1b1f24'}`;\n b.addEventListener('click', () => {\n box.remove();\n void consent.decide(choices);\n });\n return b;\n };\n row.appendChild(button(t.reject, false, {}));\n row.appendChild(button(t.accept, true, { measurement: true, marketing: true, functionality: true, experience: true }));\n box.appendChild(p);\n box.appendChild(row);\n doc.body.appendChild(box);\n return box;\n}\n",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path: "components/ConsentBanner.tsx",
|
|
19
|
+
template: "templates/consent/next/ConsentBanner.tsx",
|
|
20
|
+
next: true,
|
|
21
|
+
contents: "'use client';\n\n// A consent banner for Next.js apps (Scribase, the consent slot). The page\n// tag for analytics loads only after measurement is allowed.\n//\n// <ConsentBanner analyticsScript={process.env.NEXT_PUBLIC_ANALYTICS_SCRIPT_URL} analyticsSite={process.env.NEXT_PUBLIC_ANALYTICS_SITE} />\n\nimport { useEffect, useMemo, useState } from 'react';\n// @ts-expect-error: plain ESM module shipped next to this file\nimport { createConsent, loadAnalyticsWhenAllowed } from '../consent/consent-core.js';\n\nexport function ConsentBanner({ analyticsScript, analyticsSite, privacyUrl = '/privacy' }: { analyticsScript?: string; analyticsSite?: string; privacyUrl?: string }) {\n const consent = useMemo(\n () =>\n createConsent({\n supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,\n anonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,\n policyVersion: process.env.NEXT_PUBLIC_CONSENT_POLICY_VERSION ?? '1',\n }),\n [],\n );\n const [open, setOpen] = useState(false);\n useEffect(() => {\n setOpen(!consent.decided());\n if (analyticsScript && analyticsSite) return loadAnalyticsWhenAllowed(consent, { scriptUrl: analyticsScript, site: analyticsSite });\n return undefined;\n }, [consent, analyticsScript, analyticsSite]);\n if (!open) return null;\n const decide = (choices: Record<string, boolean>) => {\n setOpen(false);\n void consent.decide(choices);\n };\n return (\n <div role=\"dialog\" aria-label=\"Consent\" style={{ position: 'fixed', left: 16, right: 16, bottom: 16, maxWidth: 560, margin: '0 auto', padding: 16, borderRadius: 12, background: '#fff', color: '#1b1f24', boxShadow: '0 8px 30px rgba(0,0,0,.15)', zIndex: 2147483000 }}>\n <p style={{ margin: 0 }}>\n We use cookies and similar tools to measure how the app is used. Choose what you allow. <a href={privacyUrl}>Privacy</a>\n </p>\n <div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 8 }}>\n <button type=\"button\" onClick={() => decide({})}>\n Only necessary\n </button>\n <button type=\"button\" onClick={() => decide({ measurement: true, marketing: true, functionality: true, experience: true })}>\n Allow all\n </button>\n </div>\n </div>\n );\n}\n",
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
24
|
+
//# sourceMappingURL=consent-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-files.js","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/consent-files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,MAAM,CAAC,MAAM,aAAa,GAA4B,MAAM,CAAC,MAAM,CAAC;IAClE;QACE,IAAI,EAAE,yBAAyB;QAC/B,QAAQ,EAAE,uCAAuC;QACjD,QAAQ,EAAE,0/HAA0/H;KACrgI;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,iCAAiC;QAC3C,QAAQ,EAAE,m2EAAm2E;KAC92E;IACD;QACE,IAAI,EAAE,8BAA8B;QACpC,QAAQ,EAAE,0CAA0C;QACpD,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,6vEAA6vE;KACxwE;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase add consent` (Wave P PY2.5, SP-F3): the control plane creates
|
|
3
|
+
* the insert-only consent_records table in this environment's database; this
|
|
4
|
+
* machine copies the consent files into the app (the core, a plain banner,
|
|
5
|
+
* and the Next.js banner when the app uses Next.js). Existing files are never
|
|
6
|
+
* overwritten. The analytics tag then loads only after a yes. The proof is
|
|
7
|
+
* the first consent record from a visitor.
|
|
8
|
+
*/
|
|
9
|
+
import type { AddIo, AddOptions, AddResult } from '../../add.js';
|
|
10
|
+
import type { SlotContext } from './index.js';
|
|
11
|
+
export declare function consentFiles(result: AddResult, io: AddIo, options: AddOptions, ctx: SlotContext): Promise<AddResult>;
|
|
12
|
+
//# sourceMappingURL=consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/consent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAa9C,wBAAsB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAoB1H"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CONSENT_FILES } from './consent-files.js';
|
|
2
|
+
function isNext(io) {
|
|
3
|
+
const pkg = io.readFile(`${io.cwd.replace(/\/+$/, '')}/package.json`);
|
|
4
|
+
if (!pkg)
|
|
5
|
+
return false;
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(pkg);
|
|
8
|
+
return Boolean(parsed.dependencies?.next ?? parsed.devDependencies?.next);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function consentFiles(result, io, options, ctx) {
|
|
15
|
+
void options;
|
|
16
|
+
void ctx;
|
|
17
|
+
if (result.status !== 'live')
|
|
18
|
+
return result;
|
|
19
|
+
const next = isNext(io);
|
|
20
|
+
const root = io.cwd.replace(/\/+$/, '');
|
|
21
|
+
const written = [];
|
|
22
|
+
for (const file of CONSENT_FILES) {
|
|
23
|
+
if (file.next && !next)
|
|
24
|
+
continue;
|
|
25
|
+
const target = `${root}/${file.path}`;
|
|
26
|
+
if (io.readFile(target) !== null) {
|
|
27
|
+
io.log(`Kept your ${file.path} (already there).`);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
io.writeFile(target, file.contents);
|
|
31
|
+
written.push(file.path);
|
|
32
|
+
}
|
|
33
|
+
if (written.length)
|
|
34
|
+
io.log(`Added ${written.join(', ')}.`);
|
|
35
|
+
io.log(next ? 'Render <ConsentBanner /> in your root layout; analytics loads only after a yes.' : "Call showBanner() from consent/banner.js on your pages; analytics loads only after a yes.");
|
|
36
|
+
return { ...result, next: result.next ?? 'The first consent record from a visitor shows in the Consent tab.' };
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/consent.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,SAAS,MAAM,CAAC,EAAS;IACvB,MAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC;IACtE,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAwF,CAAC;QACtH,OAAO,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,IAAI,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAiB,EAAE,EAAS,EAAE,OAAmB,EAAE,GAAgB;IACpG,KAAK,OAAO,CAAC;IACb,KAAK,GAAG,CAAC;IACT,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACxB,MAAM,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;YAAE,SAAS;QACjC,MAAM,MAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;YACjC,EAAE,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,IAAI,mBAAmB,CAAC,CAAC;YAClD,SAAS;QACX,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,OAAO,CAAC,MAAM;QAAE,EAAE,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3D,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,iFAAiF,CAAC,CAAC,CAAC,2FAA2F,CAAC,CAAC;IAC/L,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,mEAAmE,EAAE,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AddIo, AddOptions, AddResult } from '../../add.js';
|
|
2
|
+
export declare const DEPLOY_CLI: readonly ["npx", "--yes", "railyard@0.1.0", "deploy"];
|
|
3
|
+
/** Runs the deploy in `cwd`; resolves with its exit code and every line it printed. */
|
|
4
|
+
export type RunDeploy = (io: AddIo) => Promise<{
|
|
5
|
+
code: number;
|
|
6
|
+
lines: string[];
|
|
7
|
+
}>;
|
|
8
|
+
/** Test seam: replaces the deploy runner; returns the previous one. */
|
|
9
|
+
export declare function setRunDeploy(next: RunDeploy): RunDeploy;
|
|
10
|
+
/** The live URL a deploy printed (`Live: https://<name>.<account>.workers.dev`). */
|
|
11
|
+
export declare function liveUrl(lines: readonly string[]): string | null;
|
|
12
|
+
/** Lines worth showing: the deploy's own progress, minus anything naming the vendor tool. */
|
|
13
|
+
export declare function shownLines(lines: readonly string[]): string[];
|
|
14
|
+
/** Link (done by the slot answer's claim), then deploy and prove with the live URL. */
|
|
15
|
+
export declare function deployAfterLink(linked: AddResult, io: AddIo, options: AddOptions): Promise<AddResult>;
|
|
16
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/deploy.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjE,eAAO,MAAM,UAAU,uDAAwD,CAAC;AAEhF,uFAAuF;AACvF,MAAM,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,KAAK,KAAK,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC;AAkBlF,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAIvD;AAED,oFAAoF;AACpF,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAE7D;AAED,uFAAuF;AACvF,wBAAsB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAgB3G"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase add deploy` (Wave P PY1.2): links this machine to the
|
|
3
|
+
* organization's deploy account with a one-time claim (never printed), then
|
|
4
|
+
* deploys the folder to the person's own Cloudflare account and answers with
|
|
5
|
+
* the live URL as the proof. The project's URL and anon key come from the env
|
|
6
|
+
* file `scribase init` wrote; nothing is pasted.
|
|
7
|
+
*
|
|
8
|
+
* The deploy runs the pinned deploy CLI (see `DEPLOY_CLI`); its lines are
|
|
9
|
+
* passed through, and the URL line becomes the proof.
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
import { InitError } from '../../init.js';
|
|
13
|
+
export const DEPLOY_CLI = ['npx', '--yes', 'railyard@0.1.0', 'deploy'];
|
|
14
|
+
const defaultRun = (io) => new Promise((resolve) => {
|
|
15
|
+
const [command, ...args] = io.env.SCRIBASE_RAILYARD_CLI ? [io.env.SCRIBASE_RAILYARD_CLI, 'deploy'] : DEPLOY_CLI;
|
|
16
|
+
const child = spawn(command, args, { cwd: io.cwd, env: io.env, stdio: ['inherit', 'pipe', 'pipe'] });
|
|
17
|
+
const lines = [];
|
|
18
|
+
const take = (chunk) => {
|
|
19
|
+
for (const line of String(chunk).split(/\r?\n/))
|
|
20
|
+
if (line.trim())
|
|
21
|
+
lines.push(line);
|
|
22
|
+
};
|
|
23
|
+
child.stdout.on('data', take);
|
|
24
|
+
child.stderr.on('data', take);
|
|
25
|
+
child.on('error', () => resolve({ code: 127, lines }));
|
|
26
|
+
child.on('close', (code) => resolve({ code: code ?? 1, lines }));
|
|
27
|
+
});
|
|
28
|
+
let run = defaultRun;
|
|
29
|
+
/** Test seam: replaces the deploy runner; returns the previous one. */
|
|
30
|
+
export function setRunDeploy(next) {
|
|
31
|
+
const previous = run;
|
|
32
|
+
run = next;
|
|
33
|
+
return previous;
|
|
34
|
+
}
|
|
35
|
+
/** The live URL a deploy printed (`Live: https://<name>.<account>.workers.dev`). */
|
|
36
|
+
export function liveUrl(lines) {
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
const match = /^Live: (https:\/\/[a-z0-9.-]+\.workers\.dev)\b/i.exec(line.trim());
|
|
39
|
+
if (match?.[1])
|
|
40
|
+
return match[1];
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
/** Lines worth showing: the deploy's own progress, minus anything naming the vendor tool. */
|
|
45
|
+
export function shownLines(lines) {
|
|
46
|
+
return lines.filter((line) => !/railyard/i.test(line));
|
|
47
|
+
}
|
|
48
|
+
/** Link (done by the slot answer's claim), then deploy and prove with the live URL. */
|
|
49
|
+
export async function deployAfterLink(linked, io, options) {
|
|
50
|
+
void options;
|
|
51
|
+
if (linked.status !== 'live')
|
|
52
|
+
return linked;
|
|
53
|
+
const { code, lines } = await run(io);
|
|
54
|
+
for (const line of shownLines(lines))
|
|
55
|
+
io.log(line);
|
|
56
|
+
const url = liveUrl(lines);
|
|
57
|
+
if (code !== 0 || !url) {
|
|
58
|
+
throw new InitError('deploy_failed', 'the deploy did not finish; the lines above say why', 'fix it, then run the same command again');
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...linked,
|
|
62
|
+
live: true,
|
|
63
|
+
proof: { kind: 'deploy', id: url, at: Math.floor(io.now() / 1000) },
|
|
64
|
+
sent: true,
|
|
65
|
+
next: null,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,CAAU,CAAC;AAKhF,MAAM,UAAU,GAAc,CAAC,EAAE,EAAE,EAAE,CACnC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GA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E,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;QACnE,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase add flags` (Wave P PY2.1): the control plane creates this
|
|
3
|
+
* project environment's flags on first use and answers with its public
|
|
4
|
+
* values for the env file (the flags key ships in the app, like an anon key).
|
|
5
|
+
* Then, results first: this machine reads the flags once the way the app's
|
|
6
|
+
* SDK does, and the command waits until that first read shows as the slot's
|
|
7
|
+
* proof. Flip flags in Environment > Add-ons > Flags; the app sees a flip on
|
|
8
|
+
* its next read, with no new build.
|
|
9
|
+
*/
|
|
10
|
+
import type { AddIo, AddOptions, AddResult } from '../../add.js';
|
|
11
|
+
import type { SlotAnswer, SlotContext } from './index.js';
|
|
12
|
+
export declare const WAIT_MS = 60000;
|
|
13
|
+
type ReadSlot = (io: AddIo, ctx: SlotContext) => Promise<SlotAnswer>;
|
|
14
|
+
/** How the app reads its flags (plain fetch; the SDK polls the same URL). */
|
|
15
|
+
export declare function readSnippet(envName: string): string;
|
|
16
|
+
export declare function flagsFirstRead(result: AddResult, io: AddIo, options: AddOptions, ctx: SlotContext, readSlot: ReadSlot): Promise<AddResult>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D,eAAO,MAAM,OAAO,QAAS,CAAC;AAG9B,KAAK,QAAQ,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAMrE,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CA6BhJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InitError } from '../../init.js';
|
|
2
|
+
export const WAIT_MS = 60_000;
|
|
3
|
+
const POLL_MS = 3_000;
|
|
4
|
+
function toSeconds(at) {
|
|
5
|
+
return typeof at === 'number' ? at : Math.floor(Date.parse(at) / 1000);
|
|
6
|
+
}
|
|
7
|
+
/** How the app reads its flags (plain fetch; the SDK polls the same URL). */
|
|
8
|
+
export function readSnippet(envName) {
|
|
9
|
+
return `const { flags } = await (await fetch(\`\${process.env.FLAGS_URL}?key=\${process.env.${envName}}\`)).json();`;
|
|
10
|
+
}
|
|
11
|
+
export async function flagsFirstRead(result, io, options, ctx, readSlot) {
|
|
12
|
+
if (result.status !== 'live')
|
|
13
|
+
return result;
|
|
14
|
+
if (ctx.answer.state === 'live' && ctx.answer.proof)
|
|
15
|
+
return result;
|
|
16
|
+
const env = ctx.answer.env ?? {};
|
|
17
|
+
const key = env.NEXT_PUBLIC_FLAGS_KEY ?? env.EXPO_PUBLIC_FLAGS_KEY ?? env.VITE_FLAGS_KEY;
|
|
18
|
+
const url = env.FLAGS_URL;
|
|
19
|
+
if (!key || !/^ry_flags_/.test(key) || !url || !/^https?:\/\//.test(url)) {
|
|
20
|
+
throw new InitError('invalid_response', 'the control plane did not return the flags key');
|
|
21
|
+
}
|
|
22
|
+
io.log(`Read flags in your app: ${readSnippet('NEXT_PUBLIC_FLAGS_KEY')}`);
|
|
23
|
+
let read;
|
|
24
|
+
try {
|
|
25
|
+
read = await io.fetch(`${url.replace(/\/+$/, '')}?key=${encodeURIComponent(key)}`, { method: 'GET', headers: { accept: 'application/json', 'user-agent': 'Scribase CLI (flags check)' } });
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new InitError('network_error', `could not read the flags: ${error.message}`);
|
|
29
|
+
}
|
|
30
|
+
if (read.status !== 200)
|
|
31
|
+
throw new InitError('proof_refused', `the flags read answered HTTP ${read.status}`);
|
|
32
|
+
io.log('Read the flags once, the way the app does; waiting for it to show...');
|
|
33
|
+
const deadline = io.now() + (options.wait ? WAIT_MS : 0);
|
|
34
|
+
for (;;) {
|
|
35
|
+
const state = await readSlot(io, ctx);
|
|
36
|
+
if (state.state === 'live' && state.proof) {
|
|
37
|
+
return { ...result, live: true, proof: { kind: state.proof.kind, id: state.proof.id, at: toSeconds(state.proof.at) }, sent: true, next: null };
|
|
38
|
+
}
|
|
39
|
+
if (io.now() >= deadline) {
|
|
40
|
+
return { ...result, next: 'The first read is recorded; it shows in the Flags tab shortly.' };
|
|
41
|
+
}
|
|
42
|
+
await io.sleep(POLL_MS);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/flags.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC;AAC9B,MAAM,OAAO,GAAG,KAAK,CAAC;AAItB,SAAS,SAAS,CAAC,EAAmB;IACpC,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,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, AddResult, Proof } from '../../add.js';
|
|
2
|
+
export type RailyardAddHandler = (options: AddOptions, io: AddIo) => Promise<AddResult>;
|
|
3
|
+
/** The Railyard slots this CLI dispatches (errors stays Scribase's own slot). */
|
|
4
|
+
export declare const RAILYARD_SLOTS: readonly ["deploy", "analytics", "ai", "flags", "uptime", "billing", "consent"];
|
|
5
|
+
/** The Railyard CLI that saves the linked token (pinned; the claim goes on stdin). */
|
|
6
|
+
export declare const RAILYARD_CLI: readonly ["npx", "--yes", "railyard@0.1.0", "link-scribase"];
|
|
7
|
+
interface ProjectState {
|
|
8
|
+
organization_id: string;
|
|
9
|
+
project_id: string;
|
|
10
|
+
environment_id: string;
|
|
11
|
+
api_url?: string;
|
|
12
|
+
}
|
|
13
|
+
/** The answer of the Railyard route (capability-state shape plus an optional claim). */
|
|
14
|
+
export interface SlotAnswer {
|
|
15
|
+
slot: string;
|
|
16
|
+
state: string;
|
|
17
|
+
live: boolean;
|
|
18
|
+
proof: Proof | {
|
|
19
|
+
kind: string;
|
|
20
|
+
id: string;
|
|
21
|
+
at: string;
|
|
22
|
+
} | null;
|
|
23
|
+
next: string | null;
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
/** A one-time link to a page where a credential is entered (never in the terminal). */
|
|
26
|
+
connect_url?: string | null;
|
|
27
|
+
claim?: {
|
|
28
|
+
claim: string;
|
|
29
|
+
console: string;
|
|
30
|
+
} | null;
|
|
31
|
+
}
|
|
32
|
+
/** Pipes a one-time claim to the Railyard CLI. Resolves with its exit code. */
|
|
33
|
+
export type LinkRailyard = (input: string, io: AddIo) => Promise<number>;
|
|
34
|
+
/** Test seam: replaces the Railyard CLI runner; returns the previous one. */
|
|
35
|
+
export declare function setLinkRailyard(next: LinkRailyard): LinkRailyard;
|
|
36
|
+
/** The control-plane path of one Railyard slot for this folder's environment. */
|
|
37
|
+
export declare function slotPath(project: ProjectState, slot: string): string;
|
|
38
|
+
declare function toProof(proof: SlotAnswer['proof']): Proof | null;
|
|
39
|
+
/** What a slot's follow-up step on this machine may use (never printed). */
|
|
40
|
+
export interface SlotContext {
|
|
41
|
+
/** The slot's control-plane URL. */
|
|
42
|
+
url: string;
|
|
43
|
+
token: string;
|
|
44
|
+
answer: SlotAnswer;
|
|
45
|
+
}
|
|
46
|
+
/** Follow-up steps: deploy runs the deploy, analytics sends a proof event and waits for it. */
|
|
47
|
+
export type AfterStep = (result: AddResult, io: AddIo, options: AddOptions, ctx: SlotContext) => Promise<AddResult>;
|
|
48
|
+
/** One Railyard slot, end to end. Never returns or logs a secret. */
|
|
49
|
+
export declare function addRailyardSlot(slot: string, options: AddOptions, io: AddIo): Promise<AddResult>;
|
|
50
|
+
/** Reads a slot's state again (the follow-up steps poll it). */
|
|
51
|
+
export declare function readSlot(io: AddIo, ctx: SlotContext): Promise<SlotAnswer>;
|
|
52
|
+
export { toProof };
|
|
53
|
+
/** The local handler for `slot`, or `null` when the generic path serves it. */
|
|
54
|
+
export declare function railyardAddHandler(slot: string): RailyardAddHandler | null;
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/capabilities/railyard/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAWxE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAExF,iFAAiF;AACjF,eAAO,MAAM,cAAc,iFAAiG,CAAC;AAI7H,sFAAsF;AACtF,eAAO,MAAM,YAAY,8DAA+D,CAAC;AAEzF,UAAU,YAAY;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CA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,UAAU,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAEpH,qEAAqE;AACrE,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAEtG;AA4CD,gEAAgE;AAChE,wBAAsB,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAI/E;AAED,OAAO,EAAE,OAAO,EAAE,CAAC;AA+BnB,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAE1E"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase add <slot>` handlers for the Railyard slots: deploy,
|
|
3
|
+
* analytics, flags, uptime, ai, billing, consent (Wave P carve-out, dispatch
|
|
4
|
+
* section 3.1; PY1.0 slot dispatcher).
|
|
5
|
+
*
|
|
6
|
+
* Owned by the PY lane. PS1.0 created this skeleton and its dispatch line in
|
|
7
|
+
* `src/cli/add.ts`; nobody in the PS lane edits this folder.
|
|
8
|
+
*
|
|
9
|
+
* Each slot calls the control plane's Railyard route
|
|
10
|
+
* (`POST .../environments/{env}/railyard/{slot}`), which answers in the
|
|
11
|
+
* capability-state shape `{slot, state, live, proof:{kind,id,at}, next, env}`.
|
|
12
|
+
* A slot whose package has not landed answers `arriving`, and this command says
|
|
13
|
+
* so and changes nothing. When a slot needs this machine linked to Railyard
|
|
14
|
+
* (deploy), the answer carries a one-time claim: it is piped on stdin to
|
|
15
|
+
* `railyard link-scribase`, which saves the token to Railyard's own credentials
|
|
16
|
+
* file (mode 600). The claim and the token are never printed, logged, or
|
|
17
|
+
* written to the project's env file.
|
|
18
|
+
*/
|
|
19
|
+
import { spawn } from 'node:child_process';
|
|
20
|
+
import { publicEnvOnly, mergeEnv, readEnvValue } from '../../envfile.js';
|
|
21
|
+
import { InitError, STATE_FILE } from '../../init.js';
|
|
22
|
+
import { deployAfterLink } from './deploy.js';
|
|
23
|
+
import { analyticsProof } from './analytics.js';
|
|
24
|
+
import { aiConnect } from './ai.js';
|
|
25
|
+
import { flagsFirstRead } from './flags.js';
|
|
26
|
+
import { uptimeBody, uptimeFirstResult } from './uptime.js';
|
|
27
|
+
import { billingConnect } from './billing.js';
|
|
28
|
+
import { consentFiles } from './consent.js';
|
|
29
|
+
/** The Railyard slots this CLI dispatches (errors stays Scribase's own slot). */
|
|
30
|
+
export const RAILYARD_SLOTS = Object.freeze(['deploy', 'analytics', 'ai', 'flags', 'uptime', 'billing', 'consent']);
|
|
31
|
+
const DEFAULT_API_URL = 'https://api.scribase.com';
|
|
32
|
+
const ENV_FILES = ['.env.local', '.env'];
|
|
33
|
+
/** The Railyard CLI that saves the linked token (pinned; the claim goes on stdin). */
|
|
34
|
+
export const RAILYARD_CLI = ['npx', '--yes', 'railyard@0.1.0', 'link-scribase'];
|
|
35
|
+
const defaultLink = (input, io) => new Promise((resolve) => {
|
|
36
|
+
const [command, ...args] = RAILYARD_CLI;
|
|
37
|
+
const child = spawn(command, args, { cwd: io.cwd, env: io.env, stdio: ['pipe', 'ignore', 'inherit'] });
|
|
38
|
+
child.on('error', () => resolve(127));
|
|
39
|
+
child.on('close', (code) => resolve(code ?? 1));
|
|
40
|
+
child.stdin.end(input);
|
|
41
|
+
});
|
|
42
|
+
let link = defaultLink;
|
|
43
|
+
/** Test seam: replaces the Railyard CLI runner; returns the previous one. */
|
|
44
|
+
export function setLinkRailyard(next) {
|
|
45
|
+
const previous = link;
|
|
46
|
+
link = next;
|
|
47
|
+
return previous;
|
|
48
|
+
}
|
|
49
|
+
function joinPath(root, relative) {
|
|
50
|
+
return `${root.replace(/\/+$/, '')}/${relative}`;
|
|
51
|
+
}
|
|
52
|
+
function readProject(io) {
|
|
53
|
+
const text = io.readFile(joinPath(io.cwd, STATE_FILE));
|
|
54
|
+
let state = null;
|
|
55
|
+
try {
|
|
56
|
+
state = text ? JSON.parse(text) : null;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
state = null;
|
|
60
|
+
}
|
|
61
|
+
if (!state?.organization_id || !state.project_id || !state.environment_id) {
|
|
62
|
+
throw new InitError('not_initialized', 'this folder is not connected to a Scribase project', 'run `npx scribase init` here first');
|
|
63
|
+
}
|
|
64
|
+
return state;
|
|
65
|
+
}
|
|
66
|
+
function findToken(io) {
|
|
67
|
+
const fromEnv = io.env.SCRIBASE_ACCESS_TOKEN?.trim();
|
|
68
|
+
if (fromEnv)
|
|
69
|
+
return fromEnv;
|
|
70
|
+
for (const file of ENV_FILES) {
|
|
71
|
+
const contents = io.readFile(joinPath(io.cwd, file));
|
|
72
|
+
const value = contents ? readEnvValue(contents, 'SCRIBASE_ACCESS_TOKEN')?.trim() : undefined;
|
|
73
|
+
if (value)
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
return io.credentials().token;
|
|
77
|
+
}
|
|
78
|
+
/** The control-plane path of one Railyard slot for this folder's environment. */
|
|
79
|
+
export function slotPath(project, slot) {
|
|
80
|
+
return (`/v1/organizations/${encodeURIComponent(project.organization_id)}` +
|
|
81
|
+
`/projects/${encodeURIComponent(project.project_id)}` +
|
|
82
|
+
`/environments/${encodeURIComponent(project.environment_id)}` +
|
|
83
|
+
`/railyard/${encodeURIComponent(slot)}`);
|
|
84
|
+
}
|
|
85
|
+
function asAnswer(body) {
|
|
86
|
+
const value = (body ?? {});
|
|
87
|
+
if (typeof value.slot !== 'string' || typeof value.state !== 'string' || typeof value.live !== 'boolean') {
|
|
88
|
+
throw new InitError('invalid_response', 'the control plane answered with an unexpected shape');
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
async function post(io, url, token, payload = {}) {
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await io.fetch(url, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: { accept: 'application/json', 'content-type': 'application/json', authorization: `Bearer ${token}`, 'user-agent': 'scribase-add' },
|
|
98
|
+
body: JSON.stringify(payload),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new InitError('network_error', `could not reach the control plane: ${error.message}`, 'check your connection or SCRIBASE_API_URL');
|
|
103
|
+
}
|
|
104
|
+
const text = await response.text();
|
|
105
|
+
let body = null;
|
|
106
|
+
try {
|
|
107
|
+
body = text ? JSON.parse(text) : null;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
body = { detail: text.slice(0, 200) };
|
|
111
|
+
}
|
|
112
|
+
if (response.status !== 200) {
|
|
113
|
+
const value = (body ?? {});
|
|
114
|
+
const code = typeof value.code === 'string' ? value.code : 'request_failed';
|
|
115
|
+
const detail = typeof value.detail === 'string' ? value.detail : 'the request failed';
|
|
116
|
+
const next = response.status === 402
|
|
117
|
+
? 'turn on the Portfolio add-on under Billing, Add-ons in the console'
|
|
118
|
+
: response.status === 401 || response.status === 403
|
|
119
|
+
? 'run `npx scribase login` (adding a slot needs an owner or admin)'
|
|
120
|
+
: undefined;
|
|
121
|
+
throw new InitError(code, `${detail} (HTTP ${response.status})`, next);
|
|
122
|
+
}
|
|
123
|
+
return asAnswer(body);
|
|
124
|
+
}
|
|
125
|
+
function envFileFor(io) {
|
|
126
|
+
for (const file of ENV_FILES) {
|
|
127
|
+
if (io.readFile(joinPath(io.cwd, file)) !== null)
|
|
128
|
+
return file;
|
|
129
|
+
}
|
|
130
|
+
return '.env';
|
|
131
|
+
}
|
|
132
|
+
function toProof(proof) {
|
|
133
|
+
if (!proof)
|
|
134
|
+
return null;
|
|
135
|
+
const at = typeof proof.at === 'number' ? proof.at : Math.floor(Date.parse(String(proof.at)) / 1000);
|
|
136
|
+
return { kind: proof.kind, id: proof.id, at: Number.isFinite(at) ? at : 0 };
|
|
137
|
+
}
|
|
138
|
+
/** One Railyard slot, end to end. Never returns or logs a secret. */
|
|
139
|
+
export async function addRailyardSlot(slot, options, io) {
|
|
140
|
+
return (await addWithContext(slot, options, io)).result;
|
|
141
|
+
}
|
|
142
|
+
async function addWithContext(slot, options, io) {
|
|
143
|
+
void options;
|
|
144
|
+
const project = readProject(io);
|
|
145
|
+
const token = findToken(io);
|
|
146
|
+
if (!token) {
|
|
147
|
+
throw new InitError('not_signed_in', 'no Scribase token for this folder', 'run `npx scribase login`, or `npx scribase init` here');
|
|
148
|
+
}
|
|
149
|
+
const base = (io.env.SCRIBASE_API_URL ?? project.api_url ?? io.credentials().apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
|
|
150
|
+
const url = `${base}${slotPath(project, slot)}`;
|
|
151
|
+
const answer = await post(io, url, token, BODY[slot]?.(io) ?? {});
|
|
152
|
+
if (answer.state === 'arriving') {
|
|
153
|
+
throw new InitError('capability_arriving', answer.next ?? `${slot} is arriving and cannot be turned on yet. Nothing was changed.`, 'run `npx scribase add --list`');
|
|
154
|
+
}
|
|
155
|
+
if (answer.claim) {
|
|
156
|
+
// The secure channel: stdin of the Railyard CLI only.
|
|
157
|
+
const code = await link(JSON.stringify({ claim: answer.claim.claim, console: answer.claim.console }), io);
|
|
158
|
+
if (code !== 0) {
|
|
159
|
+
throw new InitError('link_failed', 'this machine could not be linked to Railyard; nothing was printed', `run \`npx scribase add ${slot}\` again`);
|
|
160
|
+
}
|
|
161
|
+
io.log('This machine is linked to your organization for deploys (saved for your user only).');
|
|
162
|
+
}
|
|
163
|
+
const { safe, refused } = publicEnvOnly(answer.env ?? {});
|
|
164
|
+
const written = Object.keys(safe);
|
|
165
|
+
if (written.length > 0) {
|
|
166
|
+
const file = joinPath(io.cwd, envFileFor(io));
|
|
167
|
+
io.writeFile(file, mergeEnv(io.readFile(file) ?? '', safe));
|
|
168
|
+
}
|
|
169
|
+
const result = {
|
|
170
|
+
ok: true,
|
|
171
|
+
slot,
|
|
172
|
+
status: 'live',
|
|
173
|
+
live: answer.live,
|
|
174
|
+
provider: 'railyard',
|
|
175
|
+
proof: toProof(answer.proof),
|
|
176
|
+
sent: answer.proof !== null,
|
|
177
|
+
env_written: written,
|
|
178
|
+
env_refused: refused,
|
|
179
|
+
next: answer.next,
|
|
180
|
+
};
|
|
181
|
+
return { result, ctx: { url, token, answer } };
|
|
182
|
+
}
|
|
183
|
+
/** Reads a slot's state again (the follow-up steps poll it). */
|
|
184
|
+
export async function readSlot(io, ctx) {
|
|
185
|
+
const response = await io.fetch(ctx.url, { method: 'GET', headers: { accept: 'application/json', authorization: `Bearer ${ctx.token}`, 'user-agent': 'scribase-add' } });
|
|
186
|
+
if (response.status !== 200)
|
|
187
|
+
throw new InitError('request_failed', `the control plane answered HTTP ${response.status}`);
|
|
188
|
+
return asAnswer(JSON.parse(await response.text()));
|
|
189
|
+
}
|
|
190
|
+
export { toProof };
|
|
191
|
+
/** Slots whose add request carries a body (uptime: the app's address when known). */
|
|
192
|
+
const BODY = Object.freeze({
|
|
193
|
+
uptime: uptimeBody,
|
|
194
|
+
});
|
|
195
|
+
/** Slots that do more on this machine once the control plane answers (deploy runs the deploy). */
|
|
196
|
+
const AFTER = Object.freeze({
|
|
197
|
+
deploy: (result, io, options) => deployAfterLink(result, io, options),
|
|
198
|
+
analytics: (result, io, options, ctx) => analyticsProof(result, io, options, ctx, readSlot),
|
|
199
|
+
ai: (result, io, options, ctx) => aiConnect(result, io, options, ctx, readSlot),
|
|
200
|
+
flags: (result, io, options, ctx) => flagsFirstRead(result, io, options, ctx, readSlot),
|
|
201
|
+
uptime: (result, io, options, ctx) => uptimeFirstResult(result, io, options, ctx, readSlot),
|
|
202
|
+
billing: (result, io, options, ctx) => billingConnect(result, io, options, ctx, readSlot),
|
|
203
|
+
consent: (result, io, options, ctx) => consentFiles(result, io, options, ctx),
|
|
204
|
+
});
|
|
205
|
+
const HANDLERS = Object.freeze(Object.fromEntries(RAILYARD_SLOTS.map((slot) => [
|
|
206
|
+
slot,
|
|
207
|
+
async (options, io) => {
|
|
208
|
+
const { result, ctx } = await addWithContext(slot, options, io);
|
|
209
|
+
const after = AFTER[slot];
|
|
210
|
+
return after ? after(result, io, options, ctx) : result;
|
|
211
|
+
},
|
|
212
|
+
])));
|
|
213
|
+
/** The local handler for `slot`, or `null` when the generic path serves it. */
|
|
214
|
+
export function railyardAddHandler(slot) {
|
|
215
|
+
return Object.hasOwn(HANDLERS, slot) ? (HANDLERS[slot] ?? null) : null;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=index.js.map
|