@vite-hub/cms 0.3.1 → 0.5.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/README.md +5 -5
- package/dist/access.d.ts +1 -1
- package/dist/access.js +1 -3
- package/dist/{index-eur9QR7_.d.ts → index-BCWEbTZ8.d.ts} +4 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -19
- package/dist/{options-CIxG4vtI.js → options-BCArcTOP.js} +6 -4
- package/dist/vite.d.ts +9 -8
- package/dist/vite.js +101 -103
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @vite-hub/cms
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@vite-hub/cms)
|
|
4
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
5
|
+
[](https://vitehub.dev/docs)
|
|
6
6
|
|
|
7
7
|
`@vite-hub/cms` is the CMS of ViteHub. It stores the editable collections of [`@vite-hub/content`](https://www.npmjs.com/package/@vite-hub/content) without wiring: Content is the primitive, collections on a Workspace, and the CMS adds that Workspace and its Database tables.
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ export default defineContent({
|
|
|
23
23
|
|
|
24
24
|
[`vite-hub`](https://www.npmjs.com/package/vite-hub) then turns on `workspace`, `database`, and `blob` if you left them unset, and registers `hubCms()`. A setting you pass wins, and `false` keeps a feature off. Without `vite-hub`, import `cms` from `@vite-hub/cms` and add `hubCms()` from `@vite-hub/cms/vite` next to the Workspace, Database, and Blob plugins.
|
|
25
25
|
|
|
26
|
-
At build time `hubCms()` reads `server/content.ts` without running it
|
|
26
|
+
At build time `hubCms()` reads `server/content.ts` without running it. Import the preset from `vite-hub/cms` or `@vite-hub/cms`, pass it as `extends: cms` or `extends: [cms, { ... }]`, and use literal options. Use the boolean literal `true` for `roles`. The build then:
|
|
27
27
|
|
|
28
28
|
- writes the Workspace Definition to `.vitehub/content/workspace.mjs` and contributes it as the `content` Workspace (option `workspace`);
|
|
29
29
|
- adds the `content-history` tables (Blob + Database store) and the `content-sessions` table to the default or only Database (option `database`);
|
|
@@ -58,7 +58,7 @@ export default defineAuth({ database: authDatabase(), plugins: [admin(cmsAccess)
|
|
|
58
58
|
| `publisher` | `read`, `read-draft`, `write`, `publish` | `read`, `create`, `resolve`, `delete` |
|
|
59
59
|
| `admin` | Everything, with the Better Auth admin permissions | Everything |
|
|
60
60
|
|
|
61
|
-
`user.role` holds one role, or several separated by commas. `cmsCan(user, { content: ["publish"] })` checks it without a request; a missing user or an unknown role is denied. Opt into the role policy with `extends: [cms, {
|
|
61
|
+
`user.role` holds one role, or several separated by commas. `cmsCan(user, { content: ["publish"] })` checks it without a request; a missing user or an unknown role is denied. Opt into the role policy with `extends: [cms, { roles: true }]` or `authorize: cmsContentAuthorize`. With `extends: cms` alone, every action stays denied, including for unrelated application roles. Your own `authorize` overrides the preset policy. `cmsCommentsAuthorize` and `cmsConsoleAuthorize` give Comments and the Console the same roles. `vitehub cms roles` prints the table. The role policy also decides `read`, the `/api/content/**` route, so visitors without a role get `401`. Set `defineContent({ access: "public" })` when visitors read that route. The roles still decide drafts, writes, and publishing.
|
|
62
62
|
|
|
63
63
|
## Inspect
|
|
64
64
|
|
package/dist/access.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare const cmsAccess: CmsAccessOptions;
|
|
|
48
48
|
export declare function cmsCan(user: CmsUser | null | undefined, permissions: CmsPermissions): boolean;
|
|
49
49
|
/**
|
|
50
50
|
* `defineContent({ authorize })` from the CMS roles: `content.can()` allows an action when a role of the user has
|
|
51
|
-
* `content:<action>`. `defineContent({ extends: [cms, {
|
|
51
|
+
* `content:<action>`. `defineContent({ extends: [cms, { roles: true }] })` uses it when the app sets no `authorize`.
|
|
52
52
|
* Only CMS roles have `content:read`, so `/api/content/**` needs `defineContent({ access: "public" })` to serve visitors.
|
|
53
53
|
*/
|
|
54
54
|
export declare const cmsContentAuthorize: ContentAuthorize;
|
package/dist/access.js
CHANGED
|
@@ -70,7 +70,6 @@ const cmsAccess = {
|
|
|
70
70
|
function isCmsRoleName(name) {
|
|
71
71
|
return Object.hasOwn(cmsRoles, name);
|
|
72
72
|
}
|
|
73
|
-
/** The known CMS roles of a user. `role` holds one role, or several separated by commas, as Better Auth stores them. */
|
|
74
73
|
function cmsRolesOf(user) {
|
|
75
74
|
const role = user?.role;
|
|
76
75
|
if (String(role) !== role) return [];
|
|
@@ -85,11 +84,10 @@ function cmsCan(user, permissions) {
|
|
|
85
84
|
}
|
|
86
85
|
/**
|
|
87
86
|
* `defineContent({ authorize })` from the CMS roles: `content.can()` allows an action when a role of the user has
|
|
88
|
-
* `content:<action>`. `defineContent({ extends: [cms, {
|
|
87
|
+
* `content:<action>`. `defineContent({ extends: [cms, { roles: true }] })` uses it when the app sets no `authorize`.
|
|
89
88
|
* Only CMS roles have `content:read`, so `/api/content/**` needs `defineContent({ access: "public" })` to serve visitors.
|
|
90
89
|
*/
|
|
91
90
|
const cmsContentAuthorize = ({ user, action }) => cmsCan(user, { content: [action] });
|
|
92
|
-
/** The `comment` permission of each Comments action. Only `publisher` and `admin` delete. */
|
|
93
91
|
const commentPermissions = {
|
|
94
92
|
read: "read",
|
|
95
93
|
write: "create",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ContentPreset } from "@vite-hub/content";
|
|
2
2
|
//#region src/index.d.ts
|
|
3
|
-
/** Options of the `cms` Content preset.
|
|
3
|
+
/** Options of the `cms` Content preset. Use literal values, such as `roles: true`, so the build can read them. */
|
|
4
4
|
interface CmsPresetOptions {
|
|
5
5
|
/** Opt into the CMS roles of `admin(cmsAccess)`. Without it, set `defineContent({ authorize })` to allow access. */
|
|
6
|
-
|
|
6
|
+
roles?: true;
|
|
7
|
+
/** Renamed to `roles: true`. The preset fails with `CONTENT_CMS_OPTION_INVALID` when it is set. */
|
|
8
|
+
access?: never;
|
|
7
9
|
/**
|
|
8
10
|
* Database that receives the Workspace history tables, and with the GitHub store only the editor sessions table.
|
|
9
11
|
* Defaults to the Database named `default`, or the only one. Without a Database Definition, the tables go to the
|
|
@@ -33,19 +35,6 @@ interface CmsPresetOptions {
|
|
|
33
35
|
/** GitHub store: how a publish reaches `branch`. `"commit"` (default) commits to it. `"pr"` opens a pull request from a `vitehub/publish/*` branch, which only Console access or a signed link previews. */
|
|
34
36
|
publish?: "commit" | "pr";
|
|
35
37
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Store editable collections without wiring. `vitehub()` turns on Workspace, Database, and Blob when they are unset.
|
|
38
|
-
* At build time `hubCms()` from `@vite-hub/cms/vite` adds a Workspace named `content` on the Blob + Database Store,
|
|
39
|
-
* using the `default` Blob store and the default or only Database, and adds the Workspace history tables to that
|
|
40
|
-
* Database. When the app has no Database Definition, that is the implicit `default` Database. `defineContent({ extends: cms })`
|
|
41
|
-
* then uses that Workspace.
|
|
42
|
-
*
|
|
43
|
-
* With `repo` (or `store: "github"`) the Workspace is a GitHub repository instead: published content on one branch, drafts on
|
|
44
|
-
* another, and no Blob store. The Database keeps editor sessions.
|
|
45
|
-
*
|
|
46
|
-
* With `access: "roles"` and no `authorize` in `defineContent()`, the CMS roles of the Better Auth `admin` plugin decide
|
|
47
|
-
* who reads drafts, writes, and publishes. See `cmsAccess` from `@vite-hub/cms/access`.
|
|
48
|
-
*/
|
|
49
38
|
declare const cms: ContentPreset<CmsPresetOptions>;
|
|
50
39
|
//#endregion
|
|
51
40
|
export { cms as n, CmsPresetOptions as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as cms, t as CmsPresetOptions } from "./index-
|
|
1
|
+
import { n as cms, t as CmsPresetOptions } from "./index-BCWEbTZ8.js";
|
|
2
2
|
export { CmsPresetOptions, cms, cms as default };
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as cmsRenamedAccessProblem, i as cmsOptionsProblem, n as cmsOptionKeys, o as cmsStoreOf, r as cmsOptionProblem, s as cmsErrorDiagnostics, t as cmsGitHubDefaults } from "./options-BCArcTOP.js";
|
|
2
2
|
import { defineContentPreset } from "@vite-hub/content";
|
|
3
3
|
//#region src/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* The policy for `access: "roles"` when the app sets no `authorize`. A user without a string role is denied before
|
|
6
|
-
* Better Auth loads. The preset never interprets application roles unless the app explicitly opts in.
|
|
7
|
-
*/
|
|
8
4
|
const cmsDefaultAuthorize = async (context) => {
|
|
9
5
|
if (String(context.user?.role) !== context.user?.role) return false;
|
|
10
6
|
const { cmsContentAuthorize } = await import("./access.js");
|
|
11
7
|
return await cmsContentAuthorize(context);
|
|
12
8
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Store editable collections without wiring. `vitehub()` turns on Workspace, Database, and Blob when they are unset.
|
|
15
|
-
* At build time `hubCms()` from `@vite-hub/cms/vite` adds a Workspace named `content` on the Blob + Database Store,
|
|
16
|
-
* using the `default` Blob store and the default or only Database, and adds the Workspace history tables to that
|
|
17
|
-
* Database. When the app has no Database Definition, that is the implicit `default` Database. `defineContent({ extends: cms })`
|
|
18
|
-
* then uses that Workspace.
|
|
19
|
-
*
|
|
20
|
-
* With `repo` (or `store: "github"`) the Workspace is a GitHub repository instead: published content on one branch, drafts on
|
|
21
|
-
* another, and no Blob store. The Database keeps editor sessions.
|
|
22
|
-
*
|
|
23
|
-
* With `access: "roles"` and no `authorize` in `defineContent()`, the CMS roles of the Better Auth `admin` plugin decide
|
|
24
|
-
* who reads drafts, writes, and publishes. See `cmsAccess` from `@vite-hub/cms/access`.
|
|
25
|
-
*/
|
|
26
9
|
const cms = defineContentPreset({
|
|
27
10
|
name: "cms",
|
|
28
11
|
options: {
|
|
@@ -33,11 +16,13 @@ const cms = defineContentPreset({
|
|
|
33
16
|
draftBranch: void 0,
|
|
34
17
|
publish: void 0,
|
|
35
18
|
repo: void 0,
|
|
19
|
+
roles: void 0,
|
|
36
20
|
root: void 0,
|
|
37
21
|
store: void 0,
|
|
38
22
|
workspace: "content"
|
|
39
23
|
},
|
|
40
24
|
configure(options) {
|
|
25
|
+
if (options.access !== void 0) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem: cmsRenamedAccessProblem });
|
|
41
26
|
for (const key of cmsOptionKeys) {
|
|
42
27
|
const problem = cmsOptionProblem(key, Reflect.get(options, key));
|
|
43
28
|
if (problem) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem: `option ${JSON.stringify(key)} ${problem}` });
|
|
@@ -51,7 +36,7 @@ const cms = defineContentPreset({
|
|
|
51
36
|
if (problem) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem });
|
|
52
37
|
return {
|
|
53
38
|
workspace: options.workspace,
|
|
54
|
-
...options.
|
|
39
|
+
...options.roles ? { authorize: cmsDefaultAuthorize } : {},
|
|
55
40
|
...github && options.publish === "pr" ? { publish: "pr" } : {},
|
|
56
41
|
...github ? { privateBranches: [options.draftBranch ?? cmsGitHubDefaults.draftBranch] } : {}
|
|
57
42
|
};
|
|
@@ -5,7 +5,7 @@ const cmsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
5
5
|
codes: {
|
|
6
6
|
CONTENT_B0001: {
|
|
7
7
|
why: ({ message }) => message === void 0 ? "" : String(message),
|
|
8
|
-
fix: "In the file that the message names, pass `extends: cms` or `extends: [cms, { ... }]` with
|
|
8
|
+
fix: "In the file that the message names, pass `extends: cms` or `extends: [cms, { ... }]` with literal options that the message accepts. Use the boolean literal `true` for `roles`."
|
|
9
9
|
},
|
|
10
10
|
CONTENT_B0002: {
|
|
11
11
|
why: ({ message }) => message === void 0 ? "" : String(message),
|
|
@@ -36,11 +36,13 @@ const cmsGitHubOptions = [
|
|
|
36
36
|
];
|
|
37
37
|
/** Every option of the `cms` preset. */
|
|
38
38
|
const cmsOptionKeys = [
|
|
39
|
-
"
|
|
39
|
+
"roles",
|
|
40
40
|
...cmsNameOptions,
|
|
41
41
|
"store",
|
|
42
42
|
...cmsGitHubOptions
|
|
43
43
|
];
|
|
44
|
+
/** Why the removed `access` option fails, worded to complete `Content cms preset ...`. */
|
|
45
|
+
const cmsRenamedAccessProblem = "option \"access\" was renamed. Replace `access: \"roles\"` with `roles: true`. `vitehub migrate` renames it.";
|
|
44
46
|
const cmsStores = ["blob-database", "github"];
|
|
45
47
|
const cmsPublishModes = ["commit", "pr"];
|
|
46
48
|
const namePattern = /^[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*$/i;
|
|
@@ -61,7 +63,7 @@ const cmsGitHubDefaults = {
|
|
|
61
63
|
function cmsOptionProblem(key, value) {
|
|
62
64
|
if (value === void 0) return;
|
|
63
65
|
const text = String(value) === value ? value : void 0;
|
|
64
|
-
if (key === "
|
|
66
|
+
if (key === "roles") return value === true ? void 0 : "must be true.";
|
|
65
67
|
if (cmsNameOptions.includes(key)) return text !== void 0 && namePattern.test(text) ? void 0 : "must be a name of letters, numbers, dots, underscores, dashes, and slashes.";
|
|
66
68
|
if (key === "store") return text !== void 0 && cmsStores.includes(text) ? void 0 : `must be "blob-database" or "github".`;
|
|
67
69
|
if (key === "repo") return text !== void 0 && repoPattern.test(text) ? void 0 : "must be a repository in owner/name format.";
|
|
@@ -93,4 +95,4 @@ function cmsOptionsProblem(options) {
|
|
|
93
95
|
if (branch === (get("draftBranch") ?? cmsGitHubDefaults.draftBranch)) return `option "draftBranch" must differ from "branch". Both are ${JSON.stringify(branch)}.`;
|
|
94
96
|
}
|
|
95
97
|
//#endregion
|
|
96
|
-
export {
|
|
98
|
+
export { cmsRenamedAccessProblem as a, cmsOptionsProblem as i, cmsOptionKeys as n, cmsStoreOf as o, cmsOptionProblem as r, cmsErrorDiagnostics as s, cmsGitHubDefaults as t };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { t as CmsPresetOptions } from "./index-
|
|
1
|
+
import { t as CmsPresetOptions } from "./index-BCWEbTZ8.js";
|
|
2
2
|
import "nostics";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
import { DatabaseContributionFactory } from "@vite-hub/database/vite";
|
|
5
5
|
import { WorkspaceContributionFactory } from "@vite-hub/workspace/vite";
|
|
6
|
-
//#region ../internal/dist/host-credentials-
|
|
6
|
+
//#region ../internal/dist/host-credentials-NQkTpoab.d.ts
|
|
7
7
|
interface HostCliRunResult {
|
|
8
8
|
exitCode: number | null;
|
|
9
9
|
stdout: string;
|
|
10
|
+
stderr?: string;
|
|
10
11
|
}
|
|
11
12
|
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
12
13
|
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
@@ -70,7 +71,6 @@ interface ProvisionStep {
|
|
|
70
71
|
}
|
|
71
72
|
//#endregion
|
|
72
73
|
//#region ../internal/dist/cli.d.ts
|
|
73
|
-
//#region src/cli.d.ts
|
|
74
74
|
interface ViteHubCliStreams {
|
|
75
75
|
stderr: {
|
|
76
76
|
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
@@ -217,6 +217,8 @@ interface ViteHubResourceSummary {
|
|
|
217
217
|
owner: string;
|
|
218
218
|
/** Absent when no id is known yet. */
|
|
219
219
|
source?: ViteHubResourceIdSource;
|
|
220
|
+
/** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
|
|
221
|
+
standalone?: boolean;
|
|
220
222
|
}
|
|
221
223
|
interface ViteHubInspectionContributor {
|
|
222
224
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
@@ -273,7 +275,7 @@ type ParseAst = (source: string, options: {
|
|
|
273
275
|
}) => unknown;
|
|
274
276
|
/**
|
|
275
277
|
* Read how `server/content.ts` selects the `cms` preset. The build cannot run the Definition, so the preset must be
|
|
276
|
-
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
278
|
+
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
277
279
|
* literal options. Returns undefined when the file does not import the preset.
|
|
278
280
|
*/
|
|
279
281
|
export declare function readCmsPresetUsage(source: string, file: string, projectRoot: string, parseAst: ParseAst): CmsPresetUsage | undefined;
|
|
@@ -295,8 +297,6 @@ interface CmsDatabaseChoices {
|
|
|
295
297
|
export declare function resolveCmsPresetPlan(usage: CmsPresetUsage, databases: CmsDatabaseChoices, projectRoot: string): CmsPresetPlan;
|
|
296
298
|
/** Import paths that the generated Workspace module uses. */
|
|
297
299
|
interface CmsWorkspaceImports {
|
|
298
|
-
/** Exports `blob`. */
|
|
299
|
-
blob: string;
|
|
300
300
|
/** Exports `createBlobDatabaseWorkspaceStore` and `workspaceHistorySchema`. */
|
|
301
301
|
blobDatabase: string;
|
|
302
302
|
/** Exports `contentSessionsSchema`, the presence and edit lease table that the preset adds to its Database. */
|
|
@@ -307,8 +307,9 @@ interface CmsWorkspaceImports {
|
|
|
307
307
|
workspace: string;
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
310
|
-
* The generated Workspace Definition module. It
|
|
311
|
-
*
|
|
310
|
+
* The generated Workspace Definition module. It creates a lazy store when it loads, so the build can load it to bundle
|
|
311
|
+
* Workspace assets. The Blob + Database Store looks up its Blob store and Database by name on first use, so durability
|
|
312
|
+
* can read both. The GitHub store reads its token on first use.
|
|
312
313
|
*/
|
|
313
314
|
export declare function renderCmsWorkspaceModule(plan: CmsPresetPlan, imports: CmsWorkspaceImports): string;
|
|
314
315
|
//#endregion
|
package/dist/vite.js
CHANGED
|
@@ -1,80 +1,10 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as cmsRenamedAccessProblem, i as cmsOptionsProblem, n as cmsOptionKeys, o as cmsStoreOf, r as cmsOptionProblem, s as cmsErrorDiagnostics, t as cmsGitHubDefaults } from "./options-BCArcTOP.js";
|
|
2
2
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { findContentEntry } from "@vite-hub/source/vite";
|
|
7
7
|
import { parseAst } from "vite";
|
|
8
|
-
//#region ../internal/dist/build/vite.js
|
|
9
|
-
const projectRootDirectoryMarkers = [
|
|
10
|
-
["server", "agents"],
|
|
11
|
-
["server", "channels"],
|
|
12
|
-
["server", "connections"],
|
|
13
|
-
["server", "browsers"],
|
|
14
|
-
["server", "emails"],
|
|
15
|
-
["server", "schedules"],
|
|
16
|
-
["server", "workspaces"]
|
|
17
|
-
];
|
|
18
|
-
const projectRootFileMarkers = [
|
|
19
|
-
["package.json"],
|
|
20
|
-
["nuxt.config.ts"],
|
|
21
|
-
["nuxt.config.mts"],
|
|
22
|
-
["nuxt.config.js"],
|
|
23
|
-
["nuxt.config.mjs"]
|
|
24
|
-
];
|
|
25
|
-
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
26
|
-
/**
|
|
27
|
-
* Server directories that ViteHub scans for Definitions. The first entry is the application.
|
|
28
|
-
* Later entries are Nuxt layers in Nuxt priority order.
|
|
29
|
-
*/
|
|
30
|
-
const VITEHUB_SERVER_DIRS = "__vitehubServerDirs";
|
|
31
|
-
function resolveViteHubProjectRoot(root, options = {}) {
|
|
32
|
-
const resolvedRoot = resolve(root);
|
|
33
|
-
const temporaryRoot = resolve(tmpdir());
|
|
34
|
-
const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
|
|
35
|
-
if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
|
|
36
|
-
if (basename(resolvedRoot) === "app") {
|
|
37
|
-
const parent = dirname(resolvedRoot);
|
|
38
|
-
if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
|
|
39
|
-
"nuxt.config.ts",
|
|
40
|
-
"nuxt.config.mts",
|
|
41
|
-
"nuxt.config.js",
|
|
42
|
-
"nuxt.config.mjs"
|
|
43
|
-
]))) return parent;
|
|
44
|
-
}
|
|
45
|
-
let current = resolvedRoot;
|
|
46
|
-
while (true) {
|
|
47
|
-
if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
|
|
48
|
-
if (hasProjectRootMarker(current)) return current;
|
|
49
|
-
const parent = dirname(current);
|
|
50
|
-
if (parent === current) return resolvedRoot;
|
|
51
|
-
current = parent;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function hasProjectRootDirectoryMarker(root) {
|
|
55
|
-
for (const marker of projectRootDirectoryMarkers) try {
|
|
56
|
-
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
if (error.code !== "ENOENT") throw error;
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
function hasProjectRootMarker(root) {
|
|
63
|
-
if (hasProjectRootDirectoryMarker(root)) return true;
|
|
64
|
-
return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
|
|
65
|
-
}
|
|
66
|
-
function hasProjectRootFileMarker(root, markers) {
|
|
67
|
-
for (const marker of markers) {
|
|
68
|
-
const path = Array.isArray(marker) ? marker : [marker];
|
|
69
|
-
try {
|
|
70
|
-
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
if (error.code !== "ENOENT") throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
8
|
//#region ../internal/dist/object.js
|
|
79
9
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
80
10
|
function isRecord(value) {
|
|
@@ -173,6 +103,88 @@ const relative$1 = function(from, to) {
|
|
|
173
103
|
return [..._from.map(() => ".."), ..._to].join("/");
|
|
174
104
|
};
|
|
175
105
|
//#endregion
|
|
106
|
+
//#region ../internal/dist/inspect.js
|
|
107
|
+
function relativeDefinitionFile(projectRoot, file) {
|
|
108
|
+
return relative$1(projectRoot, file).replaceAll("\\", "/");
|
|
109
|
+
}
|
|
110
|
+
const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
|
|
111
|
+
new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
|
|
112
|
+
new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region ../internal/dist/vite-DGZFNpcx.js
|
|
115
|
+
const projectRootDirectoryMarkers = [
|
|
116
|
+
["server", "agents"],
|
|
117
|
+
["server", "channels"],
|
|
118
|
+
["server", "connections"],
|
|
119
|
+
["server", "browsers"],
|
|
120
|
+
["server", "emails"],
|
|
121
|
+
["server", "schedules"],
|
|
122
|
+
["server", "workspaces"]
|
|
123
|
+
];
|
|
124
|
+
const projectRootFileMarkers = [
|
|
125
|
+
["package.json"],
|
|
126
|
+
["nuxt.config.ts"],
|
|
127
|
+
["nuxt.config.mts"],
|
|
128
|
+
["nuxt.config.js"],
|
|
129
|
+
["nuxt.config.mjs"]
|
|
130
|
+
];
|
|
131
|
+
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
132
|
+
/**
|
|
133
|
+
* Server directories that ViteHub scans for Definitions. The first entry is the application.
|
|
134
|
+
* Later entries are Nuxt layers in Nuxt priority order.
|
|
135
|
+
*/
|
|
136
|
+
const VITEHUB_SERVER_DIRS = "__vitehubServerDirs";
|
|
137
|
+
function resolveViteHubProjectRoot(root, options = {}) {
|
|
138
|
+
const resolvedRoot = resolve(root);
|
|
139
|
+
const temporaryRoot = resolve(tmpdir());
|
|
140
|
+
const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
|
|
141
|
+
if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
|
|
142
|
+
if (basename(resolvedRoot) === "app") {
|
|
143
|
+
const parent = dirname(resolvedRoot);
|
|
144
|
+
if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
|
|
145
|
+
"nuxt.config.ts",
|
|
146
|
+
"nuxt.config.mts",
|
|
147
|
+
"nuxt.config.js",
|
|
148
|
+
"nuxt.config.mjs"
|
|
149
|
+
]))) return parent;
|
|
150
|
+
}
|
|
151
|
+
let current = resolvedRoot;
|
|
152
|
+
while (true) {
|
|
153
|
+
if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
|
|
154
|
+
if (hasProjectRootMarker(current)) return current;
|
|
155
|
+
const parent = dirname(current);
|
|
156
|
+
if (parent === current) return resolvedRoot;
|
|
157
|
+
current = parent;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function hasProjectRootDirectoryMarker(root) {
|
|
161
|
+
for (const marker of projectRootDirectoryMarkers) try {
|
|
162
|
+
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
function hasProjectRootMarker(root) {
|
|
169
|
+
if (hasProjectRootDirectoryMarker(root)) return true;
|
|
170
|
+
return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
|
|
171
|
+
}
|
|
172
|
+
function hasProjectRootFileMarker(root, markers) {
|
|
173
|
+
for (const marker of markers) {
|
|
174
|
+
const path = Array.isArray(marker) ? marker : [marker];
|
|
175
|
+
try {
|
|
176
|
+
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
function isMissingProjectMarker(error) {
|
|
184
|
+
const code = error.code;
|
|
185
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
176
188
|
//#region ../internal/dist/contributions.js
|
|
177
189
|
function isThenable(value) {
|
|
178
190
|
return typeof value.then === "function";
|
|
@@ -201,14 +213,6 @@ async function flattenPluginOptions(plugins) {
|
|
|
201
213
|
return flattened;
|
|
202
214
|
}
|
|
203
215
|
//#endregion
|
|
204
|
-
//#region ../internal/dist/inspect.js
|
|
205
|
-
function relativeDefinitionFile(projectRoot, file) {
|
|
206
|
-
return relative$1(projectRoot, file).replaceAll("\\", "/");
|
|
207
|
-
}
|
|
208
|
-
const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
|
|
209
|
-
new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
|
|
210
|
-
new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
|
|
211
|
-
//#endregion
|
|
212
216
|
//#region src/database-lookup.injected.ts
|
|
213
217
|
/**
|
|
214
218
|
* Generated module source that reads the Database of the cms preset. The build loads the generated module without the
|
|
@@ -236,7 +240,6 @@ const cmsPresetModules = ["vite-hub/cms", "@vite-hub/cms"];
|
|
|
236
240
|
function isNode(value) {
|
|
237
241
|
return value !== null && Object(value) === value && String(Reflect.get(Object(value), "type")) === Reflect.get(Object(value), "type");
|
|
238
242
|
}
|
|
239
|
-
/** Drop type-only and grouping wrappers such as `x satisfies T`, `x as T`, and `(x)`. */
|
|
240
243
|
function unwrap(node) {
|
|
241
244
|
let current = node;
|
|
242
245
|
while (isNode(current) && [
|
|
@@ -255,6 +258,11 @@ function propertyName(node) {
|
|
|
255
258
|
if (key.type === "Identifier") return String(key.name);
|
|
256
259
|
if (key.type === "Literal" && String(key.value) === key.value) return key.value;
|
|
257
260
|
}
|
|
261
|
+
function literalValue(node) {
|
|
262
|
+
const value = unwrap(node);
|
|
263
|
+
if (isNode(value) && value.type === "Literal" && value.value === true) return true;
|
|
264
|
+
return stringValue(value);
|
|
265
|
+
}
|
|
258
266
|
function stringValue(node) {
|
|
259
267
|
const value = unwrap(node);
|
|
260
268
|
if (!isNode(value)) return;
|
|
@@ -268,7 +276,6 @@ function stringValue(node) {
|
|
|
268
276
|
function displayPath(file, projectRoot) {
|
|
269
277
|
return JSON.stringify(relative(projectRoot, file).replaceAll("\\", "/"));
|
|
270
278
|
}
|
|
271
|
-
/** The build cannot read how the Definition selects the preset. */
|
|
272
279
|
function presetError(file, projectRoot, message) {
|
|
273
280
|
return cmsErrorDiagnostics.CONTENT_B0001({ message: `[vitehub] ${displayPath(file, projectRoot)}: ${message}` });
|
|
274
281
|
}
|
|
@@ -278,13 +285,12 @@ function cmsRequirementError(file, projectRoot, message) {
|
|
|
278
285
|
}
|
|
279
286
|
/**
|
|
280
287
|
* Read how `server/content.ts` selects the `cms` preset. The build cannot run the Definition, so the preset must be
|
|
281
|
-
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
288
|
+
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
282
289
|
* literal options. Returns undefined when the file does not import the preset.
|
|
283
290
|
*/
|
|
284
291
|
function readCmsPresetUsage(source, file, projectRoot, parseAst) {
|
|
285
292
|
return readCmsPresetUsageInternal(source, file, projectRoot, parseAst, /* @__PURE__ */ new Set(), "default");
|
|
286
293
|
}
|
|
287
|
-
/** `exportName` is the export that holds the Content Definition: `default` in `server/content.ts`, or the name that it re-exports. */
|
|
288
294
|
function readCmsPresetUsageInternal(source, file, projectRoot, parseAst, seen, exportName) {
|
|
289
295
|
const resolvedFile = resolve(file);
|
|
290
296
|
if (seen.has(resolvedFile)) return;
|
|
@@ -472,12 +478,13 @@ function readCmsPresetUsageInternal(source, file, projectRoot, parseAst, seen, e
|
|
|
472
478
|
const options = {};
|
|
473
479
|
for (const property of Array.isArray(optionsNode.properties) ? optionsNode.properties : []) {
|
|
474
480
|
const key = isNode(property) ? propertyName(property) : void 0;
|
|
475
|
-
if (!isNode(property) || key === void 0 || property.kind !== "init" || property.method === true) throw presetError(file, projectRoot, "cms preset options must be plain properties with
|
|
481
|
+
if (!isNode(property) || key === void 0 || property.kind !== "init" || property.method === true) throw presetError(file, projectRoot, "cms preset options must be plain properties with literal values, because the build reads them without running the file.");
|
|
482
|
+
if (key === "access") throw presetError(file, projectRoot, `cms preset ${cmsRenamedAccessProblem}`);
|
|
476
483
|
if (!cmsOptionKeys.includes(key)) throw presetError(file, projectRoot, `unknown cms preset option ${JSON.stringify(key)}. Use ${cmsOptionKeys.join(", ")}.`);
|
|
477
484
|
const valueNode = unwrap(property.value);
|
|
478
485
|
if (isNode(valueNode) && valueNode.type === "Identifier" && valueNode.name === "undefined") continue;
|
|
479
|
-
const value =
|
|
480
|
-
if (value === void 0) throw presetError(file, projectRoot, `cms preset option ${JSON.stringify(key)} must be a string literal, because the build reads it without running the file.`);
|
|
486
|
+
const value = literalValue(valueNode);
|
|
487
|
+
if (value === void 0) throw presetError(file, projectRoot, `cms preset option ${JSON.stringify(key)} must be a ${key === "roles" ? "`true`" : "string"} literal, because the build reads it without running the file.`);
|
|
481
488
|
const problem = cmsOptionProblem(key, value);
|
|
482
489
|
if (problem) throw presetError(file, projectRoot, `cms preset option ${JSON.stringify(key)} ${problem}`);
|
|
483
490
|
Reflect.set(options, key, value);
|
|
@@ -578,24 +585,21 @@ let lastPresetCheck;
|
|
|
578
585
|
/** Export of the generated module that holds the Workspace Definition. */
|
|
579
586
|
const cmsWorkspaceExport = "contentWorkspace";
|
|
580
587
|
/**
|
|
581
|
-
* The generated Workspace Definition module. It
|
|
582
|
-
*
|
|
588
|
+
* The generated Workspace Definition module. It creates a lazy store when it loads, so the build can load it to bundle
|
|
589
|
+
* Workspace assets. The Blob + Database Store looks up its Blob store and Database by name on first use, so durability
|
|
590
|
+
* can read both. The GitHub store reads its token on first use.
|
|
583
591
|
*/
|
|
584
592
|
function renderCmsWorkspaceModule(plan, imports) {
|
|
585
593
|
if (plan.store === "github" && plan.github) return renderGitHubWorkspaceModule(plan, plan.github, imports);
|
|
586
594
|
return [
|
|
587
595
|
"// Generated by @vite-hub/cms for the cms preset in server/content.ts. Do not edit.",
|
|
588
|
-
`import { blob } from ${JSON.stringify(imports.blob)}`,
|
|
589
|
-
`import { useDatabase } from ${JSON.stringify(imports.database)}`,
|
|
590
596
|
`import { defineWorkspace } from ${JSON.stringify(imports.workspace)}`,
|
|
591
597
|
`import { createBlobDatabaseWorkspaceStore } from ${JSON.stringify(imports.blobDatabase)}`,
|
|
592
598
|
"",
|
|
593
|
-
...renderDatabaseLookup(plan.database),
|
|
594
|
-
"",
|
|
595
599
|
`export const ${cmsWorkspaceExport} = defineWorkspace({`,
|
|
596
600
|
" store: createBlobDatabaseWorkspaceStore({",
|
|
597
|
-
` blob:
|
|
598
|
-
|
|
601
|
+
` blob: ${JSON.stringify(plan.blob ?? "default")},`,
|
|
602
|
+
` database: ${JSON.stringify(plan.database)},`,
|
|
599
603
|
` workspace: ${JSON.stringify(plan.workspace)},`,
|
|
600
604
|
" }),",
|
|
601
605
|
"})",
|
|
@@ -614,7 +618,7 @@ function renderGitHubWorkspaceModule(plan, github, imports) {
|
|
|
614
618
|
`export const ${cmsWorkspaceExport} = defineWorkspace({`,
|
|
615
619
|
" store: {",
|
|
616
620
|
" driver: \"github\",",
|
|
617
|
-
...github.repo ? [`
|
|
621
|
+
...github.repo ? [` repo: ${JSON.stringify(github.repo)},`] : [],
|
|
618
622
|
` branch: ${JSON.stringify(github.branch)},`,
|
|
619
623
|
` root: ${JSON.stringify(github.root)},`,
|
|
620
624
|
` refs: { published: ${JSON.stringify(github.branch)}, draft: ${JSON.stringify(github.draftBranch)} },`,
|
|
@@ -699,7 +703,6 @@ function cmsStore(input) {
|
|
|
699
703
|
return cmsPresetStoreSync(input, parseAst);
|
|
700
704
|
}
|
|
701
705
|
const defaultImports = {
|
|
702
|
-
blob: "@vite-hub/blob",
|
|
703
706
|
blobDatabase: "@vite-hub/workspace/blob-database",
|
|
704
707
|
contentDatabase: "@vite-hub/content/database",
|
|
705
708
|
database: "@vite-hub/database",
|
|
@@ -734,14 +737,9 @@ function databaseDiscoveryRoot(plugins, fallback) {
|
|
|
734
737
|
}
|
|
735
738
|
return fallback;
|
|
736
739
|
}
|
|
737
|
-
/**
|
|
738
|
-
* The other plugins of the app. `vitehub()` nests the CMS plugin in an array, and the Database contributions that
|
|
739
|
-
* the hooks collect would call the hook again through that nested copy, so flatten first.
|
|
740
|
-
*/
|
|
741
740
|
async function pluginsWithoutCms(plugins) {
|
|
742
741
|
return (await flattenPluginOptions(plugins)).filter((plugin) => Reflect.get(plugin, "name") !== CMS_VITE_PLUGIN_NAME);
|
|
743
742
|
}
|
|
744
|
-
/** Store names of the Blob plugin, or false when Blob is off. */
|
|
745
743
|
function blobStoreNames(plugin) {
|
|
746
744
|
if (!plugin) return false;
|
|
747
745
|
const getConfig = Reflect.get(Object(Reflect.get(plugin, "api")), "getConfig");
|
|
@@ -815,7 +813,7 @@ function hubCms(options = {}) {
|
|
|
815
813
|
},
|
|
816
814
|
{
|
|
817
815
|
label: "Access",
|
|
818
|
-
value: usage.authorize === "unknown" ? "Indeterminate (object spread may supply authorize)" : usage.authorize ? "The app's defineContent({ authorize })" : usage.options.
|
|
816
|
+
value: usage.authorize === "unknown" ? "Indeterminate (object spread may supply authorize)" : usage.authorize ? "The app's defineContent({ authorize })" : usage.options.roles ? "CMS roles of the Better Auth admin plugin (vitehub cms roles)" : "No policy (all actions denied)"
|
|
819
817
|
}
|
|
820
818
|
],
|
|
821
819
|
file: relativeDefinitionFile(root, usage.file),
|
|
@@ -825,7 +823,7 @@ function hubCms(options = {}) {
|
|
|
825
823
|
}] };
|
|
826
824
|
},
|
|
827
825
|
async workspaces(context) {
|
|
828
|
-
const projectRoot = context.projectRoot
|
|
826
|
+
const projectRoot = context.projectRoot;
|
|
829
827
|
const otherPlugins = await pluginsWithoutCms(context.plugins);
|
|
830
828
|
const databaseRoot = databaseDiscoveryRoot(otherPlugins, projectRoot);
|
|
831
829
|
const { collectDatabaseContributions } = await import("@vite-hub/database/vite");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Editable Content collections on a generated ViteHub Workspace, in Blob and Database or in a GitHub repository.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
"./package.json": "./package.json"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@vite-hub/content": "0.
|
|
50
|
-
"@vite-hub/source": "0.
|
|
49
|
+
"@vite-hub/content": "0.5.0",
|
|
50
|
+
"@vite-hub/source": "0.5.0",
|
|
51
51
|
"nostics": "1.4.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@comark/html": "^0.9.0",
|
|
55
55
|
"@libsql/client": "^0.18.0",
|
|
56
56
|
"@types/node": "^24.19.1",
|
|
57
|
-
"@vite-hub/comments": "0.
|
|
58
|
-
"@vite-hub/database": "0.
|
|
57
|
+
"@vite-hub/comments": "0.5.0",
|
|
58
|
+
"@vite-hub/database": "0.5.0",
|
|
59
59
|
"@vite-hub/internal": "0.0.1",
|
|
60
|
-
"@vite-hub/workspace": "0.
|
|
60
|
+
"@vite-hub/workspace": "0.5.0",
|
|
61
61
|
"better-auth": "^1.7.15",
|
|
62
62
|
"comark": "^0.9.0",
|
|
63
63
|
"comark-ui": "^0.12.0",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@comark/html": "^0.9.0",
|
|
74
|
-
"@vite-hub/blob": "0.
|
|
75
|
-
"@vite-hub/comments": "0.
|
|
76
|
-
"@vite-hub/database": "0.
|
|
77
|
-
"@vite-hub/workspace": "0.
|
|
74
|
+
"@vite-hub/blob": "0.5.0",
|
|
75
|
+
"@vite-hub/comments": "0.5.0",
|
|
76
|
+
"@vite-hub/database": "0.5.0",
|
|
77
|
+
"@vite-hub/workspace": "0.5.0",
|
|
78
78
|
"better-auth": "^1.7.15",
|
|
79
79
|
"comark": "^0.9.0",
|
|
80
80
|
"comark-ui": "^0.12.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"engines": {
|
|
98
|
-
"node": ">=
|
|
98
|
+
"node": ">=24.15.0"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"build": "vp pack",
|