@cloudhal/cli 0.6.3 → 0.6.5
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/dist/assets/starters/blog/package.json +4 -4
- package/dist/assets/starters/blog/src/pages/[...path]/llms.txt.ts +2 -1
- package/dist/assets/starters/blog/src/pages/[...path]/rss.xml.ts +2 -1
- package/dist/assets/starters/blog/src/pages/[...path].astro +8 -1
- package/dist/assets/starters/blog/src/pages/llms.txt.ts +2 -1
- package/dist/assets/starters/blog/src/pages/rss.xml.ts +2 -1
- package/dist/assets/starters/blog/src/pages/sitemap.xml.ts +2 -1
- package/dist/assets/studio/assets/{AccountPage-Dgdy4H1z.js → AccountPage-ggS9UUIE.js} +2 -2
- package/dist/assets/studio/assets/{ActivityPage-Bu56R6E7.js → ActivityPage-CBHgQ-yG.js} +2 -2
- package/dist/assets/studio/assets/{AgentModes-D695kSbw.js → AgentModes-D6DVJBf9.js} +2 -2
- package/dist/assets/studio/assets/{AgentsPage-BWlLRFPH.js → AgentsPage-JU7ZRoat.js} +2 -2
- package/dist/assets/studio/assets/{AnalyticsPage-C0RPBuUR.js → AnalyticsPage-CGGGe6_b.js} +2 -2
- package/dist/assets/studio/assets/{ApprovalsPage-B1398iby.js → ApprovalsPage-DWFNM6Ze.js} +3 -3
- package/dist/assets/studio/assets/{ArticleEditorPage-jOUCZ_79.js → ArticleEditorPage-BelTx0Yd.js} +3 -3
- package/dist/assets/studio/assets/{ArticlesPage-CbpeF5qT.js → ArticlesPage-DVi_sUdb.js} +3 -3
- package/dist/assets/studio/assets/{AssetPage-DZr_G7__.js → AssetPage-yXEtQVZx.js} +2 -2
- package/dist/assets/studio/assets/{Audit-DrQvb5mu.js → Audit-Bj4hKGvX.js} +2 -2
- package/dist/assets/studio/assets/{AuditBadges-BVr05Xyt.js → AuditBadges-DsQypHU0.js} +2 -2
- package/dist/assets/studio/assets/{AutomationsPage-CfS05QHu.js → AutomationsPage-CSGJPSLD.js} +2 -2
- package/dist/assets/studio/assets/{BlockSection-Cy4Qt5cS.js → BlockSection-Di7jTvtZ.js} +2 -2
- package/dist/assets/studio/assets/{BodyChanges-Kz6YliT_.js → BodyChanges-C1-Xwvek.js} +2 -2
- package/dist/assets/studio/assets/{BodyEditor-Dk-GQfp9.js → BodyEditor-BVAGHfXr.js} +3 -3
- package/dist/assets/studio/assets/{BuildPage-ohS6E6nm.js → BuildPage-DcLLN1ma.js} +2 -2
- package/dist/assets/studio/assets/{CodeHighlighted-uUDbvdKY.js → CodeHighlighted-DOw6b1bt.js} +2 -2
- package/dist/assets/studio/assets/{CollectionSettingsPage-3e_npZNv.js → CollectionSettingsPage-BFeuG6sT.js} +3 -3
- package/dist/assets/studio/assets/{CollectionsPage-DqM5_dJR.js → CollectionsPage-phBheohi.js} +2 -2
- package/dist/assets/studio/assets/{CommandMenu-Cedh4xtl.js → CommandMenu-DS8HM4lA.js} +2 -2
- package/dist/assets/studio/assets/{CommentThreadControls-CmD52U5z.js → CommentThreadControls-DHa1bT8S.js} +2 -2
- package/dist/assets/studio/assets/{CommentThreadPage-CX87ADPi.js → CommentThreadPage-FzYqOoP3.js} +2 -2
- package/dist/assets/studio/assets/{CommenterPage-C-Vv0BQK.js → CommenterPage-Bl1qV3R2.js} +2 -2
- package/dist/assets/studio/assets/{Comments-4cWUXtON.js → Comments-BIVjghhz.js} +2 -2
- package/dist/assets/studio/assets/{CommentsPage-Bc2nVm6x.js → CommentsPage-DWSZXdHw.js} +2 -2
- package/dist/assets/studio/assets/{ConfirmDialog-DH2jGk29.js → ConfirmDialog-Bf659Mn7.js} +2 -2
- package/dist/assets/studio/assets/{ContentListQuery-BuxxdIsz.js → ContentListQuery-CIViU6IK.js} +2 -2
- package/dist/assets/studio/assets/{Crumbs-Bg-oOv-g.js → Crumbs-5tQR5Osw.js} +2 -2
- package/dist/assets/studio/assets/{DateTimeField-DlaSbbAW.js → DateTimeField-D1NFyyzi.js} +2 -2
- package/dist/assets/studio/assets/{EditorLayout-Dp_3DB2G.js → EditorLayout-DxQ1u__q.js} +2 -2
- package/dist/assets/studio/assets/{EditorPreview-CLPIy9Da.js → EditorPreview-CeTh-BQN.js} +2 -2
- package/dist/assets/studio/assets/{Elevation-CpzbzjZ1.js → Elevation-DVz-VGqG.js} +2 -2
- package/dist/assets/studio/assets/{ElevationRequest-DGZR_Qu7.js → ElevationRequest-DxXqYdb2.js} +2 -2
- package/dist/assets/studio/assets/{EndedBadge-CuESOF9v.js → EndedBadge-CK-X3wqB.js} +2 -2
- package/dist/assets/studio/assets/{EntryFieldsCard-DpfwTRoT.js → EntryFieldsCard-hMhYYmmw.js} +2 -2
- package/dist/assets/studio/assets/{EntryPath-DBK2nqWS.js → EntryPath-C7FxCw7K.js} +2 -2
- package/dist/assets/studio/assets/FieldsSection-Bvgduen-.js +2 -0
- package/dist/assets/studio/assets/{ForgotPasswordPage-4T_xsZc7.js → ForgotPasswordPage-CFRffUGl.js} +2 -2
- package/dist/assets/studio/assets/{Gating-BKw9x3OA.js → Gating-BkQJUYlE.js} +2 -2
- package/dist/assets/studio/assets/{GovernanceDialog-WI6muWSG.js → GovernanceDialog-jTEWGW2z.js} +2 -2
- package/dist/assets/studio/assets/{InvitePage-BWcoBszO.js → InvitePage-D15Yv4v5.js} +2 -2
- package/dist/assets/studio/assets/{ListFieldColumns-DLqDR_nL.js → ListFieldColumns-CR_tsgd3.js} +2 -2
- package/dist/assets/studio/assets/{ListToolbar-_lpYaeal.js → ListToolbar-CQucqlsm.js} +2 -2
- package/dist/assets/studio/assets/{ListingSections-lyTz_PaH.js → ListingSections-6bDGWjVe.js} +2 -2
- package/dist/assets/studio/assets/LoginPage-BefSOX9E.js +2 -0
- package/dist/assets/studio/assets/{MediaPage-DaCldFys.js → MediaPage-CtlG6jQp.js} +2 -2
- package/dist/assets/studio/assets/{MediaPicker-DYJj3Gtp.js → MediaPicker-DUPqmqrb.js} +2 -2
- package/dist/assets/studio/assets/{MediaUpload-DuQnkN1u.js → MediaUpload-CYAkvtRE.js} +2 -2
- package/dist/assets/studio/assets/{MembersPage-fMlwYa1x.js → MembersPage-CIf5O-RB.js} +2 -2
- package/dist/assets/studio/assets/{Menus-Dym_0ijH.js → Menus-CmH6vunK.js} +2 -2
- package/dist/assets/studio/assets/{NavigationPage-CTQt0njO.js → NavigationPage-qKIv_U8O.js} +2 -2
- package/dist/assets/studio/assets/{NewSiteDialog-DVWeKGsw.js → NewSiteDialog-CpO2fd2Q.js} +2 -2
- package/dist/assets/studio/assets/{NotificationItems--5FaR3tN.js → NotificationItems-HcSZxZEQ.js} +2 -2
- package/dist/assets/studio/assets/{PageEditorPage-BlG2sPAB.js → PageEditorPage-Bh5m9ie9.js} +3 -3
- package/dist/assets/studio/assets/{PagesPage-BXU3jxTQ.js → PagesPage-D0kir6Qa.js} +2 -2
- package/dist/assets/studio/assets/{PasswordField-1kzPgqLo.js → PasswordField-BwLcXkWe.js} +2 -2
- package/dist/assets/studio/assets/{PreviewPanel-3eVWgDDN.js → PreviewPanel-BGpAUen8.js} +2 -2
- package/dist/assets/studio/assets/{ProjectPage-CdYFYMv3.js → ProjectPage-BMQemtWA.js} +2 -2
- package/dist/assets/studio/assets/{Readers-BwBWWzB-.js → Readers-BgU1fsew.js} +3 -3
- package/dist/assets/studio/assets/{RedirectDialog-BqlclE-n.js → RedirectDialog-bPr8OErT.js} +2 -2
- package/dist/assets/studio/assets/{RedirectsPage-Bpnn14p_.js → RedirectsPage-DpGCP2H9.js} +2 -2
- package/dist/assets/studio/assets/{RelativeTime-B3WDq_Ti.js → RelativeTime-BoL63n83.js} +2 -2
- package/dist/assets/studio/assets/{ReleaseApproval-CEM7iJKI.js → ReleaseApproval-CiowWHD6.js} +2 -2
- package/dist/assets/studio/assets/{ReleasePage-B9db-dEu.js → ReleasePage-Cmn4XIN9.js} +2 -2
- package/dist/assets/studio/assets/{ReleaseParts-CI9sIfLw.js → ReleaseParts-BtPkXJe8.js} +2 -2
- package/dist/assets/studio/assets/{ResetPasswordPage-C24Mv9le.js → ResetPasswordPage-CU03agQd.js} +2 -2
- package/dist/assets/studio/assets/{RowMenu-CvvLvp2V.js → RowMenu-BpCKOA6h.js} +2 -2
- package/dist/assets/studio/assets/{ScheduleCard-CTZ7DyA9.js → ScheduleCard-OsQEonW7.js} +2 -2
- package/dist/assets/studio/assets/{ScheduleDialog-TQgKxIsr.js → ScheduleDialog-CkD7o8BA.js} +2 -2
- package/dist/assets/studio/assets/{ScheduleHistoryPage-9lUX1OC9.js → ScheduleHistoryPage-Dyx8zWBn.js} +2 -2
- package/dist/assets/studio/assets/{ScheduleStatusBadge-CLqNp1Rc.js → ScheduleStatusBadge-BD-R8Xhm.js} +2 -2
- package/dist/assets/studio/assets/{SchedulerStalled-mEbvw7Q_.js → SchedulerStalled-D-r-bG15.js} +2 -2
- package/dist/assets/studio/assets/{Schedules-7od0mh_y.js → Schedules-WRBznpP3.js} +2 -2
- package/dist/assets/studio/assets/{SchedulesPage-Cj-QwGdy.js → SchedulesPage-CeVUW7M1.js} +2 -2
- package/dist/assets/studio/assets/{ScopeBadge-J87LKFHA.js → ScopeBadge-DhZzXufT.js} +2 -2
- package/dist/assets/studio/assets/{Seo-YV7wVEPY.js → Seo-D0glat-v.js} +2 -2
- package/dist/assets/studio/assets/{SeoPreview-CAaNUyjg.js → SeoPreview-8x-utwvr.js} +2 -2
- package/dist/assets/studio/assets/{Settings-DX31HFBM.js → Settings-vhQ4tSVQ.js} +2 -2
- package/dist/assets/studio/assets/{SiteAccessField-DQaQg5ez.js → SiteAccessField-B6QH60a2.js} +2 -2
- package/dist/assets/studio/assets/{SiteOverviewPage-lk4wap0q.js → SiteOverviewPage-Cs2Ofrps.js} +3 -3
- package/dist/assets/studio/assets/{SiteSettingsPage-mCQPDJzA.js → SiteSettingsPage-Dp6lKKC8.js} +2 -2
- package/dist/assets/studio/assets/{SitesPage-gxcSR0ad.js → SitesPage-C0cnFUkv.js} +2 -2
- package/dist/assets/studio/assets/{SkillsPage-_ZUdPF2E.js → SkillsPage-CikouwvX.js} +2 -2
- package/dist/assets/studio/assets/{SnapshotsPage-DLUbZ563.js → SnapshotsPage-Bmf7BZj6.js} +2 -2
- package/dist/assets/studio/assets/{StatTile-KhE3fINB.js → StatTile-Dgy33jEu.js} +2 -2
- package/dist/assets/studio/assets/{Status-W9nLsw86.js → Status-WIcIPfpv.js} +2 -2
- package/dist/assets/studio/assets/{StatusActions-CqCXSQ46.js → StatusActions-CMVNwBJb.js} +3 -3
- package/dist/assets/studio/assets/{TableSkeleton-SmOOTzX3.js → TableSkeleton-kZirmJfM.js} +2 -2
- package/dist/assets/studio/assets/{TagsMigration-rd5JiDwq.js → TagsMigration-cyJ961N5.js} +2 -2
- package/dist/assets/studio/assets/{Taxonomy-CZjclj3o.js → Taxonomy-Ds_0dNU6.js} +2 -2
- package/dist/assets/studio/assets/{TaxonomyPage-DqlGIFcb.js → TaxonomyPage-DA-_Tzim.js} +2 -2
- package/dist/assets/studio/assets/{TaxonomySettingsDialog-Bn2QdsNY.js → TaxonomySettingsDialog-CwBMKZZ1.js} +2 -2
- package/dist/assets/studio/assets/{TermEditorPage-BoW7eXoX.js → TermEditorPage-CrKYv25t.js} +2 -2
- package/dist/assets/studio/assets/{TermPickers-BMXiPCa0.js → TermPickers-eqJn6_fi.js} +2 -2
- package/dist/assets/studio/assets/{TranslationList-7PC6LAd9.js → TranslationList-Yj7mW5L-.js} +2 -2
- package/dist/assets/studio/assets/{TranslationsPage--a62-gT6.js → TranslationsPage-DVHq8tG8.js} +2 -2
- package/dist/assets/studio/assets/{api-errors-tZYwLeo6.js → api-errors-CrlMh7Uh.js} +2 -2
- package/dist/assets/studio/assets/{ar-BUKtNVP6.js → ar-kwcrV10j.js} +2 -2
- package/dist/assets/studio/assets/auth-BzR8abXz.js +4 -0
- package/dist/assets/studio/assets/body-blocks-CZh36LZ-.js +6 -0
- package/dist/assets/studio/assets/{charts-DS4cDmaj.js → charts-DWHcHyjN.js} +2 -2
- package/dist/assets/studio/assets/{collapsible-l8g94on4w7qfosmn-ClVVSlmf.js → collapsible-l8g94on4w7qfosmn-D_uRnC33.js} +2 -2
- package/dist/assets/studio/assets/{collection-icons-D-IZFMkB.js → collection-icons-Bv8JHANh.js} +2 -2
- package/dist/assets/studio/assets/{combobox-hdxtsm2gqcxxgfju-DhX6ZIcI.js → combobox-hdxtsm2gqcxxgfju-aGVFBrpM.js} +2 -2
- package/dist/assets/studio/assets/{de-DWHO_HkU.js → de-C-Bbcibt.js} +2 -2
- package/dist/assets/studio/assets/{deleteLabels-DH7Oba8-.js → deleteLabels-CehHXeUA.js} +2 -2
- package/dist/assets/studio/assets/{editor-BrVbznPe.js → editor-BtMefDTK.js} +75 -69
- package/dist/assets/studio/assets/{es-C07OD_XS.js → es-DRXEyf0l.js} +2 -2
- package/dist/assets/studio/assets/{fa-Cgls-bgZ.js → fa-C1MtIlym.js} +2 -2
- package/dist/assets/studio/assets/{fields-BnrW0cTr.js → fields-DLi4pT7p.js} +2 -2
- package/dist/assets/studio/assets/{fields-3PygkO_o.js → fields-Hz5JsMmY.js} +2 -2
- package/dist/assets/studio/assets/{fr-QRT6iq33.js → fr-B396areL.js} +2 -2
- package/dist/assets/studio/assets/{he-CBKpkqQI.js → he-CZwil4jG.js} +2 -2
- package/dist/assets/studio/assets/{hi-eQ3OUtm4.js → hi-Crgk0N23.js} +2 -2
- package/dist/assets/studio/assets/{i18n-BsaF_Usk.js → i18n-Dab0ajqW.js} +3 -3
- package/dist/assets/studio/assets/{id-C93G1k_A.js → id-Z3wSQ21N.js} +2 -2
- package/dist/assets/studio/assets/{index-CRaauoqY.js → index-B2hMMgOI.js} +3 -3
- package/dist/assets/studio/assets/{it-DYqXpRiP.js → it-D_e5w1W5.js} +2 -2
- package/dist/assets/studio/assets/{ja-D9n_rxyV.js → ja-XexIMFCE.js} +2 -2
- package/dist/assets/studio/assets/{ko-hS1dOTFu.js → ko-BphIzzGa.js} +2 -2
- package/dist/assets/studio/assets/{layer-dialog-j5ywmzs46ccg6oqy-a5UYrx-X.js → layer-dialog-j5ywmzs46ccg6oqy-C3eIOyE1.js} +2 -2
- package/dist/assets/studio/assets/{listings-BBpJYnXK.js → listings-laPwX-2R.js} +2 -2
- package/dist/assets/studio/assets/media-B_VCak1g.js +21 -0
- package/dist/assets/studio/assets/names-CEhVexDU.js +2 -0
- package/dist/assets/studio/assets/{nl-Dh6z5Vys.js → nl-D2pGOej6.js} +2 -2
- package/dist/assets/studio/assets/{pl-ClD48bGQ.js → pl-BdQ-KeLm.js} +2 -2
- package/dist/assets/studio/assets/{pt-BR-B1t2IuB6.js → pt-BR-lI2va4Ax.js} +2 -2
- package/dist/assets/studio/assets/{ru-1Ypf-SpC.js → ru-BuBa5alG.js} +2 -2
- package/dist/assets/studio/assets/{tag-input-ohfybx5dbxy3houy-Bfh3Yb-x.js → tag-input-ohfybx5dbxy3houy-2CqNGu-I.js} +2 -2
- package/dist/assets/studio/assets/{taxonomy-S-y5xbUa.js → taxonomy--7w0Tr-W.js} +2 -2
- package/dist/assets/studio/assets/{tr-CYoHJpqA.js → tr-2tUDztjs.js} +2 -2
- package/dist/assets/studio/assets/{uk-UznF4_3D.js → uk-D-x13N_h.js} +2 -2
- package/dist/assets/studio/assets/{useAnalyticsCard-DkpiYb5T.js → useAnalyticsCard-3ehEghuO.js} +2 -2
- package/dist/assets/studio/assets/{useCollectionView-Cj_hlmHt.js → useCollectionView-BjScbQsQ.js} +3 -3
- package/dist/assets/studio/assets/{useLiveSite-BCjxnCp4.js → useLiveSite-BXT7Tep7.js} +2 -2
- package/dist/assets/studio/assets/{useMe-CxI04z9a.js → useMe-BQDOgqHt.js} +2 -2
- package/dist/assets/studio/assets/{usePaging-4q9qSaT2.js → usePaging-Mr18xaY2.js} +2 -2
- package/dist/assets/studio/assets/workflow-C0gUEP9L.js +2 -0
- package/dist/assets/studio/assets/{zh-Hans-3w2oZuI1.js → zh-Hans-hT5IaMLb.js} +2 -2
- package/dist/assets/studio/index.html +7 -7
- package/dist/src/cli/commands-local.js +4 -0
- package/dist/src/cli/help.d.ts +1 -2
- package/dist/src/cli/help.js +40 -13
- package/dist/src/commands/init.d.ts +12 -0
- package/dist/src/commands/init.js +28 -9
- package/dist/src/commands/studio-auth.d.ts +52 -0
- package/dist/src/commands/studio-auth.js +130 -0
- package/dist/src/commands/studio-options.d.ts +22 -6
- package/dist/src/commands/studio-options.js +79 -17
- package/dist/src/commands/studio.d.ts +17 -6
- package/dist/src/commands/studio.js +68 -22
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/package.json +13 -13
- package/dist/assets/studio/assets/FieldsSection-B-_c-cLU.js +0 -2
- package/dist/assets/studio/assets/LoginPage-blPVGXvN.js +0 -2
- package/dist/assets/studio/assets/auth-BsoY4NJQ.js +0 -4
- package/dist/assets/studio/assets/body-blocks-DCP3w1pD.js +0 -6
- package/dist/assets/studio/assets/media-f6By4NWo.js +0 -21
- package/dist/assets/studio/assets/names-R-Dypr9Y.js +0 -2
- package/dist/assets/studio/assets/workflow-D1TOv5ea.js +0 -2
package/dist/src/cli/help.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `cloudhal --help`; every command it names has an entry in `COMMANDS` (cli.ts). The usage text is
|
|
3
|
+
* in four pieces, each a readable size: the project on this machine, Cloudflare, content and sites,
|
|
4
|
+
* operations. `HELP` prints them in that order.
|
|
5
|
+
*/
|
|
6
|
+
/** init, dev, snapshot, build, studio, mcp: the project on this machine. */
|
|
7
|
+
const PROJECT = ` cloudhal init <dir> [--name <name>] [--starter blog] create a site project with a seeded local store
|
|
8
|
+
cloudhal dev [--port <n>] [--host [<addr>]] live preview (drafts visible); --host alone is
|
|
9
|
+
0.0.0.0, every IPv4 address (:: for IPv6 too)
|
|
7
10
|
cloudhal snapshot [--label <text>] [--publish] freeze the current graph (optionally publish)
|
|
8
11
|
cloudhal build [--snapshot <id>] static HTML from the published/latest snapshot
|
|
9
12
|
cloudhal studio [--port <n>] [--host [<addr>]] [--base-url <url>] [--behind-proxy] [--no-auth]
|
|
10
13
|
[--init-if-empty [--starter blog] [--name <name>]]
|
|
11
14
|
API + Studio UI for this project (default :8787);
|
|
15
|
+
while nobody has an account it prints a one-time
|
|
16
|
+
setup link for the owner (or set CLOUDHAL_SETUP_TOKEN:
|
|
17
|
+
32+ characters of A-Z a-z 0-9 - . _ ~); --no-auth
|
|
18
|
+
skips sign-in for local scripts and is refused
|
|
19
|
+
unless --host is loopback and --behind-proxy is off;
|
|
12
20
|
self-hosting: --host 0.0.0.0 (CLOUDHAL_HOST) listens
|
|
13
|
-
beyond this machine
|
|
14
|
-
is the
|
|
21
|
+
beyond this machine (alone: every IPv4 address),
|
|
22
|
+
--base-url (CLOUDHAL_BASE_URL) is the origin browsers
|
|
23
|
+
open Studio at, required behind a reverse proxy and
|
|
24
|
+
recommended whenever --host is not loopback (without
|
|
25
|
+
it sign-in accepts each request's own origin),
|
|
15
26
|
--behind-proxy (CLOUDHAL_BEHIND_PROXY=1) trusts its
|
|
16
|
-
X-Forwarded-Proto/Host
|
|
27
|
+
X-Forwarded-Proto/Host and the last X-Forwarded-For
|
|
28
|
+
hop and needs --base-url, --init-if-empty
|
|
17
29
|
(CLOUDHAL_INIT=<starter>) creates the project first
|
|
18
|
-
when the folder
|
|
30
|
+
when the folder is empty (lost+found aside) and has
|
|
31
|
+
no cloudhal.json
|
|
19
32
|
cloudhal mcp [--mode plan|manual|edits|auto|bypass] [--scopes a,b] [--skills <dir>] [--preview-url <url>]
|
|
20
33
|
MCP server over stdio for this project
|
|
21
|
-
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
/** deploy, domain, push, pull: the Cloudflare deployment. */
|
|
37
|
+
const CLOUDFLARE = ` cloudhal deploy [--name <base>] [--dry-run] [--jurisdiction eu] [--scheduler cron|alarm] [--plan free|paid]
|
|
22
38
|
[--force-downgrade] [--no-build-studio]
|
|
23
39
|
site + admin Workers on Cloudflare (uses wrangler login);
|
|
24
40
|
--jurisdiction eu keeps a newly created D1 database
|
|
@@ -36,7 +52,10 @@ Usage:
|
|
|
36
52
|
local site → deployment (refused while releases are
|
|
37
53
|
open unless --cancel-schedules cancels them)
|
|
38
54
|
cloudhal pull [--replace] [--admin-url <url>] deployment → local site
|
|
39
|
-
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
/** export, import, owner, site, migrate, fields: content and sites. */
|
|
58
|
+
const CONTENT = ` cloudhal export [--out <file>] [--site <id>] [--no-media] [--latest-only]
|
|
40
59
|
one site as a .cloudhal file (RFC-0039): its graph,
|
|
41
60
|
snapshots and media; never user accounts, comments,
|
|
42
61
|
analytics or secrets (its history names who made each
|
|
@@ -76,7 +95,10 @@ Usage:
|
|
|
76
95
|
change a collection's typed fields with their values
|
|
77
96
|
(RFC-0041): snapshotted, resumable; --dry-run reports
|
|
78
97
|
and greps the theme; revert <id> undoes a run
|
|
79
|
-
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
/** media, analytics, comments, schedules, ai, render, motion, tokens, chrome, search. */
|
|
101
|
+
const OPERATIONS = ` cloudhal media import-urls [--dry-run] [--include-markdown] [--allow-host <host>]… | --revert <id>
|
|
80
102
|
copy linked images into the media library
|
|
81
103
|
(RFC-0004); revertible
|
|
82
104
|
cloudhal media verify [<assetId>] recompute media checksums
|
|
@@ -120,3 +142,8 @@ Usage:
|
|
|
120
142
|
(publishing keeps it current; for restored backups)
|
|
121
143
|
cloudhal --help
|
|
122
144
|
`;
|
|
145
|
+
|
|
146
|
+
export const HELP = `cloudhal — agent-native sites
|
|
147
|
+
|
|
148
|
+
Usage:
|
|
149
|
+
${PROJECT}${CLOUDFLARE}${CONTENT}${OPERATIONS}`;
|
|
@@ -3,9 +3,21 @@ export interface InitOptions {
|
|
|
3
3
|
readonly name?: string;
|
|
4
4
|
readonly starter?: string;
|
|
5
5
|
readonly log?: (line: string) => void;
|
|
6
|
+
/**
|
|
7
|
+
* The folder the project will live in when `dir` is only a staging folder it is moved from
|
|
8
|
+
* (`cloudhal studio --init-if-empty`): relative `link:` paths to a source checkout are computed
|
|
9
|
+
* from here. Default: `dir`.
|
|
10
|
+
*/
|
|
11
|
+
readonly finalDir?: string;
|
|
6
12
|
}
|
|
7
13
|
/** Walks up from `dir` to find a pnpm workspace root (so copied starters keep `workspace:*` links). */
|
|
8
14
|
export declare function findWorkspaceRoot(dir: string): Promise<string | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* A package name from a site name: lowercase, every run of other characters one `-`, no `-` at
|
|
17
|
+
* either end, at most 64 characters. One pass, linear in the input (no backtracking regex: CodeQL
|
|
18
|
+
* js/polynomial-redos).
|
|
19
|
+
*/
|
|
20
|
+
export declare function slugify(s: string): string;
|
|
9
21
|
export interface InitResult {
|
|
10
22
|
readonly projectDir: string;
|
|
11
23
|
readonly siteId: string;
|
|
@@ -20,6 +20,12 @@ import { starterFilter } from "../starter-files.js";
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
async function exists(p ) {
|
|
@@ -42,14 +48,27 @@ export async function findWorkspaceRoot(dir )
|
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* A package name from a site name: lowercase, every run of other characters one `-`, no `-` at
|
|
53
|
+
* either end, at most 64 characters. One pass, linear in the input (no backtracking regex: CodeQL
|
|
54
|
+
* js/polynomial-redos).
|
|
55
|
+
*/
|
|
56
|
+
export function slugify(s ) {
|
|
57
|
+
let out = "";
|
|
58
|
+
let dash = false;
|
|
59
|
+
for (const ch of s.toLowerCase()) {
|
|
60
|
+
if ((ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")) {
|
|
61
|
+
if (dash && out) {
|
|
62
|
+
// a dash only when the character after it fits too: never a trailing "-"
|
|
63
|
+
if (out.length + 2 > 64) break;
|
|
64
|
+
out += "-";
|
|
65
|
+
}
|
|
66
|
+
dash = false;
|
|
67
|
+
out += ch;
|
|
68
|
+
if (out.length >= 64) break;
|
|
69
|
+
} else dash = true;
|
|
70
|
+
}
|
|
71
|
+
return out || "site";
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
|
|
@@ -96,7 +115,7 @@ export async function init(options ) {
|
|
|
96
115
|
const out = repo
|
|
97
116
|
? materializeDependencies(pkg, await monorepoVersions(repo), {
|
|
98
117
|
// real paths, so the relative link survives symlinked folders (macOS /var → /private/var)
|
|
99
|
-
linkFrom: await realpath(projectDir),
|
|
118
|
+
linkFrom: await realpath(options.finalDir ?? projectDir),
|
|
100
119
|
})
|
|
101
120
|
: pkg;
|
|
102
121
|
await writeFile(pkgPath, `${JSON.stringify(out, null, 2)}\n`);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `cloudhal studio` does about authentication where it does not run on the author's own
|
|
3
|
+
* machine (#165): `--no-auth` stays on this machine, the first account needs a one-time setup
|
|
4
|
+
* token (RFC-0005 §7; `CLOUDHAL_SETUP_TOKEN`, or one printed at start) so a fresh Studio on a
|
|
5
|
+
* network cannot be claimed by whoever reaches it first, and a Studio reachable beyond loopback
|
|
6
|
+
* without a public origin is warned about.
|
|
7
|
+
*/
|
|
8
|
+
import type { SqlDriver } from "@cloudhal/storage";
|
|
9
|
+
import type { StudioServer } from "./studio-options.js";
|
|
10
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
11
|
+
/** Loopback addresses: the default bind (`127.0.0.1`), and the only ones `--no-auth` may use. */
|
|
12
|
+
export declare function isLoopbackHost(host: string | undefined): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* `--no-auth` publishes every scope to whoever reaches the port (its only guard is a `Host` allow
|
|
15
|
+
* list any client can satisfy), so it is for this machine only: a loopback address and no proxy in
|
|
16
|
+
* front (#165).
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertNoAuthLocal(server: StudioServer): void;
|
|
19
|
+
/** The token the first account must present, and where it came from. */
|
|
20
|
+
export interface SetupToken {
|
|
21
|
+
readonly token: string;
|
|
22
|
+
readonly source: "env" | "generated";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The one-time token the first account must present (header `x-cloudhal-setup-token`; RFC-0005 §7,
|
|
26
|
+
* #165): `CLOUDHAL_SETUP_TOKEN` when set, else a fresh random one for this process. It is only
|
|
27
|
+
* asked for while nobody has an account.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveSetupToken(env?: Env): SetupToken;
|
|
30
|
+
/** Whether anybody has an account yet (Better Auth's `user` table, storage migration 0002). */
|
|
31
|
+
export declare function hasAccounts(sql: Pick<SqlDriver, "get">): Promise<boolean>;
|
|
32
|
+
/** The setup link `studio()` reports while nobody has an account. */
|
|
33
|
+
export interface StudioSetup {
|
|
34
|
+
/** `<studio url>login#setup=<token>`: the token travels in the fragment, never to a server. */
|
|
35
|
+
readonly url: string;
|
|
36
|
+
readonly tokenSource: "env" | "generated";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What `cloudhal studio` prints for a `StudioSetup` (an operator reads it from the container's
|
|
40
|
+
* log). A token the operator set themselves is not repeated: logs may be kept.
|
|
41
|
+
*/
|
|
42
|
+
export declare function describeSetup(setup: StudioSetup): string;
|
|
43
|
+
/**
|
|
44
|
+
* Behind a reverse proxy the public origin is known, and Better Auth needs it as its base URL: for
|
|
45
|
+
* `Secure` session cookies on https and for the one origin sign-in accepts. Without it the server
|
|
46
|
+
* would trust whatever origin the forwarded headers name, or (on loopback) refuse every sign-in, so
|
|
47
|
+
* `--behind-proxy` without `--base-url` is refused at start (#165).
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertProxyHasBaseUrl(server: StudioServer): void;
|
|
50
|
+
/** One line for a Studio reachable beyond this machine without a public origin (#165). */
|
|
51
|
+
export declare function noBaseUrlWarning(server: StudioServer): string | undefined;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `cloudhal studio` does about authentication where it does not run on the author's own
|
|
3
|
+
* machine (#165): `--no-auth` stays on this machine, the first account needs a one-time setup
|
|
4
|
+
* token (RFC-0005 §7; `CLOUDHAL_SETUP_TOKEN`, or one printed at start) so a fresh Studio on a
|
|
5
|
+
* network cannot be claimed by whoever reaches it first, and a Studio reachable beyond loopback
|
|
6
|
+
* without a public origin is warned about.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/** Loopback addresses: the default bind (`127.0.0.1`), and the only ones `--no-auth` may use. */
|
|
14
|
+
export function isLoopbackHost(host ) {
|
|
15
|
+
if (host === undefined) return true;
|
|
16
|
+
const h = host
|
|
17
|
+
.trim()
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/^\[(.*)\]$/, "$1");
|
|
20
|
+
return (
|
|
21
|
+
h === "localhost" ||
|
|
22
|
+
h === "::1" ||
|
|
23
|
+
h === "::ffff:127.0.0.1" ||
|
|
24
|
+
/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `--no-auth` publishes every scope to whoever reaches the port (its only guard is a `Host` allow
|
|
30
|
+
* list any client can satisfy), so it is for this machine only: a loopback address and no proxy in
|
|
31
|
+
* front (#165).
|
|
32
|
+
*/
|
|
33
|
+
export function assertNoAuthLocal(server ) {
|
|
34
|
+
if (isLoopbackHost(server.hostname) && !server.behindProxy) return;
|
|
35
|
+
const why = server.behindProxy ? "--behind-proxy is set" : `--host is ${server.hostname}`;
|
|
36
|
+
throw new Error(
|
|
37
|
+
`--no-auth is for this machine only: it needs a loopback --host (127.0.0.1, the default, or ::1) and no --behind-proxy, but ${why}. Run with authentication to serve Studio beyond localhost.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The token the first account must present, and where it came from. */
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/** A `CLOUDHAL_SETUP_TOKEN` must be hard to guess (the same floor `cloudhal deploy` asks for). */
|
|
48
|
+
const MIN_SETUP_TOKEN_LENGTH = 32;
|
|
49
|
+
/**
|
|
50
|
+
* The characters a token may use: it travels in a URL fragment, where Studio's login page reads
|
|
51
|
+
* `+` as a space and `%`, `&` or `#` change the value (base64url, hex and UUIDs fit).
|
|
52
|
+
*/
|
|
53
|
+
const SETUP_TOKEN_CHARS = /^[A-Za-z0-9._~-]+$/;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The one-time token the first account must present (header `x-cloudhal-setup-token`; RFC-0005 §7,
|
|
57
|
+
* #165): `CLOUDHAL_SETUP_TOKEN` when set, else a fresh random one for this process. It is only
|
|
58
|
+
* asked for while nobody has an account.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveSetupToken(env = process.env) {
|
|
61
|
+
const given = env.CLOUDHAL_SETUP_TOKEN?.trim();
|
|
62
|
+
if (given) {
|
|
63
|
+
if (given.length < MIN_SETUP_TOKEN_LENGTH)
|
|
64
|
+
throw new Error(
|
|
65
|
+
`CLOUDHAL_SETUP_TOKEN must be at least ${MIN_SETUP_TOKEN_LENGTH} characters (a random value); unset it and cloudhal studio prints a setup link instead`,
|
|
66
|
+
);
|
|
67
|
+
if (!SETUP_TOKEN_CHARS.test(given))
|
|
68
|
+
throw new Error(
|
|
69
|
+
"CLOUDHAL_SETUP_TOKEN may only use letters, digits and - . _ ~ (it travels in the setup link): use e.g. `openssl rand -hex 32`",
|
|
70
|
+
);
|
|
71
|
+
return { token: given, source: "env" };
|
|
72
|
+
}
|
|
73
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
74
|
+
return { token: Buffer.from(bytes).toString("base64url"), source: "generated" };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Whether anybody has an account yet (Better Auth's `user` table, storage migration 0002). */
|
|
78
|
+
export async function hasAccounts(sql ) {
|
|
79
|
+
const row = await sql.get ('SELECT COUNT(*) AS n FROM "user"');
|
|
80
|
+
return (row?.n ?? 0) > 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The setup link `studio()` reports while nobody has an account. */
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/** The setup link with the token replaced by its variable's name (a string search, no regex). */
|
|
91
|
+
function withoutToken(url ) {
|
|
92
|
+
const at = url.indexOf("#setup=");
|
|
93
|
+
return `${at === -1 ? url : url.slice(0, at)}#setup=<CLOUDHAL_SETUP_TOKEN>`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* What `cloudhal studio` prints for a `StudioSetup` (an operator reads it from the container's
|
|
98
|
+
* log). A token the operator set themselves is not repeated: logs may be kept.
|
|
99
|
+
*/
|
|
100
|
+
export function describeSetup(setup ) {
|
|
101
|
+
const fromEnv = setup.tokenSource === "env";
|
|
102
|
+
const link = fromEnv ? withoutToken(setup.url) : setup.url;
|
|
103
|
+
return [
|
|
104
|
+
"No account yet. Create the owner account (once) at this one-time setup link:",
|
|
105
|
+
` ${link}`,
|
|
106
|
+
fromEnv
|
|
107
|
+
? " (the token is the value of CLOUDHAL_SETUP_TOKEN; it is not printed)"
|
|
108
|
+
: " (printed only here; without it nobody can sign up)",
|
|
109
|
+
" If you open Studio at another address, keep the #setup=… part of the link.",
|
|
110
|
+
].join("\n");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Behind a reverse proxy the public origin is known, and Better Auth needs it as its base URL: for
|
|
115
|
+
* `Secure` session cookies on https and for the one origin sign-in accepts. Without it the server
|
|
116
|
+
* would trust whatever origin the forwarded headers name, or (on loopback) refuse every sign-in, so
|
|
117
|
+
* `--behind-proxy` without `--base-url` is refused at start (#165).
|
|
118
|
+
*/
|
|
119
|
+
export function assertProxyHasBaseUrl(server ) {
|
|
120
|
+
if (!server.behindProxy || server.baseUrl !== undefined) return;
|
|
121
|
+
throw new Error(
|
|
122
|
+
"--behind-proxy (CLOUDHAL_BEHIND_PROXY) needs --base-url: set CLOUDHAL_BASE_URL to the public origin browsers open Studio at, e.g. https://studio.example.com",
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** One line for a Studio reachable beyond this machine without a public origin (#165). */
|
|
127
|
+
export function noBaseUrlWarning(server ) {
|
|
128
|
+
if (server.baseUrl !== undefined || isLoopbackHost(server.hostname)) return undefined;
|
|
129
|
+
return `--host ${server.hostname} without --base-url: sign-in accepts the origin of each request; set --base-url (CLOUDHAL_BASE_URL) to the origin browsers open Studio at, e.g. http://<this machine's address>:${server.port}`;
|
|
130
|
+
}
|
|
@@ -2,9 +2,13 @@ type Env = Readonly<Record<string, string | undefined>>;
|
|
|
2
2
|
/** The flags `cloudhal studio` takes for where and how it is served. */
|
|
3
3
|
export interface StudioServerFlags {
|
|
4
4
|
readonly port?: number;
|
|
5
|
-
/** `--host`: the address to listen on (default `127.0.0.1`; `0.0.0.0` for every
|
|
5
|
+
/** `--host`: the address to listen on (default `127.0.0.1`; `0.0.0.0` for every IPv4 address). */
|
|
6
6
|
readonly host?: string;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* `--base-url`: the origin browsers open Studio at (scheme, host, port), e.g.
|
|
9
|
+
* `https://studio.example.com`; required behind a reverse proxy, recommended whenever `--host`
|
|
10
|
+
* is not loopback. Without it sign-in accepts each request's own origin (#165).
|
|
11
|
+
*/
|
|
8
12
|
readonly baseUrl?: string;
|
|
9
13
|
/** `--behind-proxy`: trust `X-Forwarded-Proto` / `X-Forwarded-Host`. */
|
|
10
14
|
readonly behindProxy?: boolean;
|
|
@@ -31,11 +35,16 @@ export declare function studioUrl(server: StudioServer, port: number): string;
|
|
|
31
35
|
* Better Auth's `baseURL` (the origin browsers use; its cookies are `Secure` for https) and the
|
|
32
36
|
* origins the API accepts state-changing requests from: the Studio dev server, the public origin
|
|
33
37
|
* (so a proxy that keeps the request on http still passes the API's CSRF check), and
|
|
34
|
-
* `CLOUDHAL_TRUSTED_ORIGINS`.
|
|
38
|
+
* `CLOUDHAL_TRUSTED_ORIGINS`. Without a public origin (#165) Better Auth also trusts the origin
|
|
39
|
+
* each request was made to, as the API's CSRF check does: any (`"any"`, a server listening beyond
|
|
40
|
+
* loopback, reached at `http://<lan-ip>:8787`), or on a loopback server only this machine's names
|
|
41
|
+
* (`"loopback"`: `localhost`, `127.0.0.1`, `[::1]`, so a rebound DNS name is not). With a public
|
|
42
|
+
* origin (`false`) only it and the list may sign in.
|
|
35
43
|
*/
|
|
36
44
|
export declare function studioAuthOrigins(server: StudioServer, env?: Env): {
|
|
37
45
|
baseURL: string;
|
|
38
46
|
trustedOrigins: string[];
|
|
47
|
+
trustRequestOrigin: "any" | "loopback" | false;
|
|
39
48
|
};
|
|
40
49
|
/** `--init-if-empty` and its `--starter` / `--name`; from the environment, `CLOUDHAL_INIT=<starter>`. */
|
|
41
50
|
export interface StudioInitFlags {
|
|
@@ -48,11 +57,18 @@ export declare function resolveStudioInit(flags: StudioInitFlags, env?: Env): {
|
|
|
48
57
|
starter: string;
|
|
49
58
|
name: string | undefined;
|
|
50
59
|
} | undefined;
|
|
60
|
+
/** The folder inside the project where `--init-if-empty` stages the scaffold before moving it up. */
|
|
61
|
+
export declare const INIT_STAGING_DIR = ".cloudhal-init";
|
|
51
62
|
/**
|
|
52
63
|
* Creates the project the way `cloudhal init` does when the folder has no `cloudhal.json` (a
|
|
53
|
-
* container starting on an empty volume). A folder that has other files but no config is
|
|
54
|
-
*
|
|
55
|
-
*
|
|
64
|
+
* container starting on an empty volume). A folder that has other files but no config is refused,
|
|
65
|
+
* as `init` refuses it, so a volume mounted at the wrong path is never written over. The scaffold
|
|
66
|
+
* is staged in `.cloudhal-init` inside the folder and moved up entry by entry, `cloudhal.json`
|
|
67
|
+
* last, so a container stopped at any point starts again cleanly: a staging folder without a
|
|
68
|
+
* complete config (missing, cut off, no `siteId`) is redone, one with a complete config is moved
|
|
69
|
+
* the rest of the way (#165; before, a stop mid-scaffold crash-looped on "is not empty"). A fresh
|
|
70
|
+
* ext4 volume's `lost+found` does not make the folder non-empty. Returns whether a project was
|
|
71
|
+
* created.
|
|
56
72
|
*/
|
|
57
73
|
export declare function initIfEmpty(projectDir: string, options: {
|
|
58
74
|
starter: string;
|
|
@@ -5,19 +5,24 @@
|
|
|
5
5
|
* Flags win over the environment: `CLOUDHAL_HOST`, `CLOUDHAL_BASE_URL`, `CLOUDHAL_BEHIND_PROXY`,
|
|
6
6
|
* `CLOUDHAL_INIT` (a starter name), `CLOUDHAL_SITE_NAME`.
|
|
7
7
|
*/
|
|
8
|
-
import { access } from "node:fs/promises";
|
|
8
|
+
import { access, mkdir, readdir, readFile, rename, rm } from "node:fs/promises";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { CONFIG_FILE } from "../config.js";
|
|
11
11
|
import { init } from "./init.js";
|
|
12
|
+
import { isLoopbackHost } from "./studio-auth.js";
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
/** The flags `cloudhal studio` takes for where and how it is served. */
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
|
|
21
|
+
|
|
22
|
+
|
|
20
23
|
|
|
24
|
+
|
|
25
|
+
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
|
|
@@ -96,12 +101,16 @@ export function studioUrl(server , port ) {
|
|
|
96
101
|
* Better Auth's `baseURL` (the origin browsers use; its cookies are `Secure` for https) and the
|
|
97
102
|
* origins the API accepts state-changing requests from: the Studio dev server, the public origin
|
|
98
103
|
* (so a proxy that keeps the request on http still passes the API's CSRF check), and
|
|
99
|
-
* `CLOUDHAL_TRUSTED_ORIGINS`.
|
|
104
|
+
* `CLOUDHAL_TRUSTED_ORIGINS`. Without a public origin (#165) Better Auth also trusts the origin
|
|
105
|
+
* each request was made to, as the API's CSRF check does: any (`"any"`, a server listening beyond
|
|
106
|
+
* loopback, reached at `http://<lan-ip>:8787`), or on a loopback server only this machine's names
|
|
107
|
+
* (`"loopback"`: `localhost`, `127.0.0.1`, `[::1]`, so a rebound DNS name is not). With a public
|
|
108
|
+
* origin (`false`) only it and the list may sign in.
|
|
100
109
|
*/
|
|
101
110
|
export function studioAuthOrigins(
|
|
102
111
|
server ,
|
|
103
112
|
env = process.env,
|
|
104
|
-
)
|
|
113
|
+
) {
|
|
105
114
|
const baseURL = server.baseUrl ?? `http://localhost:${server.port}`;
|
|
106
115
|
const trustedOrigins = [
|
|
107
116
|
// The Studio dev server (vite, :5173) proxies /api here during Studio development.
|
|
@@ -112,6 +121,8 @@ export function studioAuthOrigins(
|
|
|
112
121
|
return {
|
|
113
122
|
baseURL,
|
|
114
123
|
trustedOrigins: [...new Set(trustedOrigins.map((o) => o.trim()))].filter(Boolean),
|
|
124
|
+
trustRequestOrigin:
|
|
125
|
+
server.baseUrl !== undefined ? false : isLoopbackHost(server.hostname) ? "loopback" : "any",
|
|
115
126
|
};
|
|
116
127
|
}
|
|
117
128
|
|
|
@@ -135,27 +146,78 @@ export function resolveStudioInit(
|
|
|
135
146
|
};
|
|
136
147
|
}
|
|
137
148
|
|
|
149
|
+
async function exists(p ) {
|
|
150
|
+
try {
|
|
151
|
+
await access(p);
|
|
152
|
+
return true;
|
|
153
|
+
} catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The folder inside the project where `--init-if-empty` stages the scaffold before moving it up. */
|
|
159
|
+
export const INIT_STAGING_DIR = ".cloudhal-init";
|
|
160
|
+
|
|
138
161
|
/**
|
|
139
162
|
* Creates the project the way `cloudhal init` does when the folder has no `cloudhal.json` (a
|
|
140
|
-
* container starting on an empty volume). A folder that has other files but no config is
|
|
141
|
-
*
|
|
142
|
-
*
|
|
163
|
+
* container starting on an empty volume). A folder that has other files but no config is refused,
|
|
164
|
+
* as `init` refuses it, so a volume mounted at the wrong path is never written over. The scaffold
|
|
165
|
+
* is staged in `.cloudhal-init` inside the folder and moved up entry by entry, `cloudhal.json`
|
|
166
|
+
* last, so a container stopped at any point starts again cleanly: a staging folder without a
|
|
167
|
+
* complete config (missing, cut off, no `siteId`) is redone, one with a complete config is moved
|
|
168
|
+
* the rest of the way (#165; before, a stop mid-scaffold crash-looped on "is not empty"). A fresh
|
|
169
|
+
* ext4 volume's `lost+found` does not make the folder non-empty. Returns whether a project was
|
|
170
|
+
* created.
|
|
143
171
|
*/
|
|
144
172
|
export async function initIfEmpty(
|
|
145
173
|
projectDir ,
|
|
146
174
|
options ,
|
|
147
175
|
) {
|
|
176
|
+
if (await exists(path.join(projectDir, CONFIG_FILE))) return false;
|
|
177
|
+
await mkdir(projectDir, { recursive: true });
|
|
178
|
+
const staging = path.join(projectDir, INIT_STAGING_DIR);
|
|
179
|
+
const staged = await completeConfig(path.join(staging, CONFIG_FILE));
|
|
180
|
+
const others = (await readdir(projectDir)).filter(
|
|
181
|
+
(entry) => entry !== INIT_STAGING_DIR && entry !== LOST_AND_FOUND,
|
|
182
|
+
);
|
|
183
|
+
if (others.length > 0 && !staged) throw new Error(`${projectDir} is not empty`);
|
|
184
|
+
if (!staged) {
|
|
185
|
+
// whatever an earlier start left unfinished, then a fresh scaffold
|
|
186
|
+
await rm(staging, { recursive: true, force: true });
|
|
187
|
+
await init({
|
|
188
|
+
dir: staging,
|
|
189
|
+
finalDir: projectDir,
|
|
190
|
+
starter: options.starter,
|
|
191
|
+
name: options.name ?? path.basename(path.resolve(projectDir)),
|
|
192
|
+
...(options.log ? { log: options.log } : {}),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
for (const entry of (await readdir(staging)).filter((entry) => entry !== CONFIG_FILE))
|
|
196
|
+
await moveUp(staging, projectDir, entry);
|
|
197
|
+
await moveUp(staging, projectDir, CONFIG_FILE);
|
|
198
|
+
await rm(staging, { recursive: true, force: true });
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** What `mkfs.ext4` leaves at the root of a new file system (a Docker volume on a fresh disk). */
|
|
203
|
+
const LOST_AND_FOUND = "lost+found";
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether a staged `cloudhal.json` is the finished one `init` writes last: it parses and names a
|
|
207
|
+
* site. A file cut off by a stop while it was written (or empty) means the scaffold is redone.
|
|
208
|
+
*/
|
|
209
|
+
async function completeConfig(file ) {
|
|
148
210
|
try {
|
|
149
|
-
await
|
|
150
|
-
return
|
|
211
|
+
const cfg = JSON.parse(await readFile(file, "utf8")) ;
|
|
212
|
+
return typeof cfg.siteId === "string" && cfg.siteId.length > 0;
|
|
151
213
|
} catch {
|
|
152
|
-
|
|
214
|
+
return false;
|
|
153
215
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
160
|
-
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** One staged entry into the project; one that an earlier start already moved stays as it is. */
|
|
219
|
+
async function moveUp(staging , projectDir , entry ) {
|
|
220
|
+
const target = path.join(projectDir, entry);
|
|
221
|
+
if (await exists(target)) await rm(path.join(staging, entry), { recursive: true, force: true });
|
|
222
|
+
else await rename(path.join(staging, entry), target);
|
|
161
223
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { restTransport } from "@cloudhal/api";
|
|
2
|
+
import { type StudioSetup } from "./studio-auth.js";
|
|
2
3
|
import { type StudioInitFlags, type StudioServerFlags } from "./studio-options.js";
|
|
3
4
|
export interface StudioOptions extends StudioServerFlags, StudioInitFlags {
|
|
4
5
|
readonly projectDir: string;
|
|
@@ -6,7 +7,7 @@ export interface StudioOptions extends StudioServerFlags, StudioInitFlags {
|
|
|
6
7
|
readonly log?: (line: string) => void;
|
|
7
8
|
/** Directory of a built Studio (`apps/studio/dist`). Defaults to the monorepo build when present. */
|
|
8
9
|
readonly studioDist?: string;
|
|
9
|
-
/** Skip authentication (local scripts only). */
|
|
10
|
+
/** Skip authentication (local scripts only: a loopback `host` and no `behindProxy`, #165). */
|
|
10
11
|
readonly noAuth?: boolean;
|
|
11
12
|
/** Where printed mail goes (tests); default stdout (RFC-0011). */
|
|
12
13
|
readonly mailOut?: (text: string) => void;
|
|
@@ -14,6 +15,20 @@ export interface StudioOptions extends StudioServerFlags, StudioInitFlags {
|
|
|
14
15
|
readonly scheduler?: boolean;
|
|
15
16
|
/** @deprecated the comments job runs on the scheduler's tick; `false` skips the ticker. */
|
|
16
17
|
readonly commentsJob?: boolean;
|
|
18
|
+
/** The environment `CLOUDHAL_*` is read from (tests); default `process.env`. */
|
|
19
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
20
|
+
/** Tests: run Better Auth's Origin check under `NODE_ENV=test` too (`AuthOptions.originCheck`). */
|
|
21
|
+
readonly authOriginCheck?: "always";
|
|
22
|
+
}
|
|
23
|
+
/** A running `cloudhal studio`. */
|
|
24
|
+
export interface StudioHandle {
|
|
25
|
+
readonly url: string;
|
|
26
|
+
readonly port: number;
|
|
27
|
+
/** While nobody has an account: the one-time link that creates the owner (RFC-0005 §7, #165). */
|
|
28
|
+
readonly setup?: StudioSetup;
|
|
29
|
+
/** For the operator: a Studio reachable beyond this machine without `--base-url` (#165). */
|
|
30
|
+
readonly warnings: readonly string[];
|
|
31
|
+
stop(): Promise<void>;
|
|
17
32
|
}
|
|
18
33
|
/** Paths the API owns; never answered with the Studio SPA. */
|
|
19
34
|
export declare function isApiPath(pathname: string): boolean;
|
|
@@ -21,11 +36,7 @@ export declare function isApiPath(pathname: string): boolean;
|
|
|
21
36
|
* Runs the Cloudhal API (and, when built, the Studio UI) for the project on Node.
|
|
22
37
|
* Authentication is wired by `createAuthFor()` from `@cloudhal/api/auth` when available.
|
|
23
38
|
*/
|
|
24
|
-
export declare function studio(options: StudioOptions): Promise<
|
|
25
|
-
url: string;
|
|
26
|
-
port: number;
|
|
27
|
-
stop(): Promise<void>;
|
|
28
|
-
}>;
|
|
39
|
+
export declare function studio(options: StudioOptions): Promise<StudioHandle>;
|
|
29
40
|
/** Workers AI over REST from `CLOUDFLARE_ACCOUNT_ID` and `CLOUDHAL_AI_TOKEN` (RFC-0016 §1). */
|
|
30
41
|
export declare function localAiTransport(env?: Record<string, string | undefined>): {
|
|
31
42
|
transport?: ReturnType<typeof restTransport>;
|