@vite-hub/cms 0.3.1 → 0.4.1
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 -1
- package/dist/{index-eur9QR7_.d.ts → index-BQk9e5ua.d.ts} +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/{options-CIxG4vtI.js → options-BCArcTOP.js} +6 -4
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +92 -85
- 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
|
@@ -85,7 +85,7 @@ function cmsCan(user, permissions) {
|
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* `defineContent({ authorize })` from the CMS roles: `content.can()` allows an action when a role of the user has
|
|
88
|
-
* `content:<action>`. `defineContent({ extends: [cms, {
|
|
88
|
+
* `content:<action>`. `defineContent({ extends: [cms, { roles: true }] })` uses it when the app sets no `authorize`.
|
|
89
89
|
* Only CMS roles have `content:read`, so `/api/content/**` needs `defineContent({ access: "public" })` to serve visitors.
|
|
90
90
|
*/
|
|
91
91
|
const cmsContentAuthorize = ({ user, action }) => cmsCan(user, { content: [action] });
|
|
@@ -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
|
|
@@ -43,7 +45,7 @@ interface CmsPresetOptions {
|
|
|
43
45
|
* With `repo` (or `store: "github"`) the Workspace is a GitHub repository instead: published content on one branch, drafts on
|
|
44
46
|
* another, and no Blob store. The Database keeps editor sessions.
|
|
45
47
|
*
|
|
46
|
-
* With `
|
|
48
|
+
* With `roles: true` and no `authorize` in `defineContent()`, the CMS roles of the Better Auth `admin` plugin decide
|
|
47
49
|
* who reads drafts, writes, and publishes. See `cmsAccess` from `@vite-hub/cms/access`.
|
|
48
50
|
*/
|
|
49
51
|
declare const cms: ContentPreset<CmsPresetOptions>;
|
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-BQk9e5ua.js";
|
|
2
2
|
export { CmsPresetOptions, cms, cms as default };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
4
|
/**
|
|
5
|
-
* The policy for `
|
|
5
|
+
* The policy for `roles: true` when the app sets no `authorize`. A user without a string role is denied before
|
|
6
6
|
* Better Auth loads. The preset never interprets application roles unless the app explicitly opts in.
|
|
7
7
|
*/
|
|
8
8
|
const cmsDefaultAuthorize = async (context) => {
|
|
@@ -20,7 +20,7 @@ const cmsDefaultAuthorize = async (context) => {
|
|
|
20
20
|
* With `repo` (or `store: "github"`) the Workspace is a GitHub repository instead: published content on one branch, drafts on
|
|
21
21
|
* another, and no Blob store. The Database keeps editor sessions.
|
|
22
22
|
*
|
|
23
|
-
* With `
|
|
23
|
+
* With `roles: true` and no `authorize` in `defineContent()`, the CMS roles of the Better Auth `admin` plugin decide
|
|
24
24
|
* who reads drafts, writes, and publishes. See `cmsAccess` from `@vite-hub/cms/access`.
|
|
25
25
|
*/
|
|
26
26
|
const cms = defineContentPreset({
|
|
@@ -33,11 +33,13 @@ const cms = defineContentPreset({
|
|
|
33
33
|
draftBranch: void 0,
|
|
34
34
|
publish: void 0,
|
|
35
35
|
repo: void 0,
|
|
36
|
+
roles: void 0,
|
|
36
37
|
root: void 0,
|
|
37
38
|
store: void 0,
|
|
38
39
|
workspace: "content"
|
|
39
40
|
},
|
|
40
41
|
configure(options) {
|
|
42
|
+
if (options.access !== void 0) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem: cmsRenamedAccessProblem });
|
|
41
43
|
for (const key of cmsOptionKeys) {
|
|
42
44
|
const problem = cmsOptionProblem(key, Reflect.get(options, key));
|
|
43
45
|
if (problem) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem: `option ${JSON.stringify(key)} ${problem}` });
|
|
@@ -51,7 +53,7 @@ const cms = defineContentPreset({
|
|
|
51
53
|
if (problem) throw cmsErrorDiagnostics.CONTENT_CMS_OPTION_INVALID({ problem });
|
|
52
54
|
return {
|
|
53
55
|
workspace: options.workspace,
|
|
54
|
-
...options.
|
|
56
|
+
...options.roles ? { authorize: cmsDefaultAuthorize } : {},
|
|
55
57
|
...github && options.publish === "pr" ? { publish: "pr" } : {},
|
|
56
58
|
...github ? { privateBranches: [options.draftBranch ?? cmsGitHubDefaults.draftBranch] } : {}
|
|
57
59
|
};
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { t as CmsPresetOptions } from "./index-
|
|
1
|
+
import { t as CmsPresetOptions } from "./index-BQk9e5ua.js";
|
|
2
2
|
import "nostics";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
import { DatabaseContributionFactory } from "@vite-hub/database/vite";
|
|
@@ -273,7 +273,7 @@ type ParseAst = (source: string, options: {
|
|
|
273
273
|
}) => unknown;
|
|
274
274
|
/**
|
|
275
275
|
* 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
|
|
276
|
+
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
277
277
|
* literal options. Returns undefined when the file does not import the preset.
|
|
278
278
|
*/
|
|
279
279
|
export declare function readCmsPresetUsage(source: string, file: string, projectRoot: string, parseAst: ParseAst): CmsPresetUsage | undefined;
|
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,84 @@ 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/build/vite.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 (error.code !== "ENOENT") 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 (error.code !== "ENOENT") throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
176
184
|
//#region ../internal/dist/contributions.js
|
|
177
185
|
function isThenable(value) {
|
|
178
186
|
return typeof value.then === "function";
|
|
@@ -201,14 +209,6 @@ async function flattenPluginOptions(plugins) {
|
|
|
201
209
|
return flattened;
|
|
202
210
|
}
|
|
203
211
|
//#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
212
|
//#region src/database-lookup.injected.ts
|
|
213
213
|
/**
|
|
214
214
|
* Generated module source that reads the Database of the cms preset. The build loads the generated module without the
|
|
@@ -255,6 +255,12 @@ function propertyName(node) {
|
|
|
255
255
|
if (key.type === "Identifier") return String(key.name);
|
|
256
256
|
if (key.type === "Literal" && String(key.value) === key.value) return key.value;
|
|
257
257
|
}
|
|
258
|
+
/** A string or `true` literal: the values that the cms preset options take. */
|
|
259
|
+
function literalValue(node) {
|
|
260
|
+
const value = unwrap(node);
|
|
261
|
+
if (isNode(value) && value.type === "Literal" && value.value === true) return true;
|
|
262
|
+
return stringValue(value);
|
|
263
|
+
}
|
|
258
264
|
function stringValue(node) {
|
|
259
265
|
const value = unwrap(node);
|
|
260
266
|
if (!isNode(value)) return;
|
|
@@ -278,7 +284,7 @@ function cmsRequirementError(file, projectRoot, message) {
|
|
|
278
284
|
}
|
|
279
285
|
/**
|
|
280
286
|
* 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
|
|
287
|
+
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with
|
|
282
288
|
* literal options. Returns undefined when the file does not import the preset.
|
|
283
289
|
*/
|
|
284
290
|
function readCmsPresetUsage(source, file, projectRoot, parseAst) {
|
|
@@ -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);
|
|
@@ -614,7 +621,7 @@ function renderGitHubWorkspaceModule(plan, github, imports) {
|
|
|
614
621
|
`export const ${cmsWorkspaceExport} = defineWorkspace({`,
|
|
615
622
|
" store: {",
|
|
616
623
|
" driver: \"github\",",
|
|
617
|
-
...github.repo ? [`
|
|
624
|
+
...github.repo ? [` repo: ${JSON.stringify(github.repo)},`] : [],
|
|
618
625
|
` branch: ${JSON.stringify(github.branch)},`,
|
|
619
626
|
` root: ${JSON.stringify(github.root)},`,
|
|
620
627
|
` refs: { published: ${JSON.stringify(github.branch)}, draft: ${JSON.stringify(github.draftBranch)} },`,
|
|
@@ -815,7 +822,7 @@ function hubCms(options = {}) {
|
|
|
815
822
|
},
|
|
816
823
|
{
|
|
817
824
|
label: "Access",
|
|
818
|
-
value: usage.authorize === "unknown" ? "Indeterminate (object spread may supply authorize)" : usage.authorize ? "The app's defineContent({ authorize })" : usage.options.
|
|
825
|
+
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
826
|
}
|
|
820
827
|
],
|
|
821
828
|
file: relativeDefinitionFile(root, usage.file),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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.4.1",
|
|
50
|
+
"@vite-hub/source": "0.4.1",
|
|
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.4.1",
|
|
58
|
+
"@vite-hub/database": "0.4.1",
|
|
59
59
|
"@vite-hub/internal": "0.0.1",
|
|
60
|
-
"@vite-hub/workspace": "0.
|
|
60
|
+
"@vite-hub/workspace": "0.4.1",
|
|
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.4.1",
|
|
75
|
+
"@vite-hub/comments": "0.4.1",
|
|
76
|
+
"@vite-hub/database": "0.4.1",
|
|
77
|
+
"@vite-hub/workspace": "0.4.1",
|
|
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",
|