@cedarjs/cli 7.0.0-canary.3106 → 7.0.0-canary.3107
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.
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
3
4
|
const WEB_AUTH_EXTENSIONS = ["ts", "tsx", "js", "jsx"];
|
|
4
5
|
function hasWebAuthFile(webSrcPath) {
|
|
5
6
|
return WEB_AUTH_EXTENSIONS.some(
|
|
6
7
|
(extension) => fs.existsSync(path.join(webSrcPath, `auth.${extension}`))
|
|
7
8
|
);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"",
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
function authNotSetUpMessage() {
|
|
11
|
+
return [
|
|
12
|
+
"Auth is not set up in this project.",
|
|
13
|
+
"",
|
|
14
|
+
"Tenancy builds on your app's auth: it adds memberships to",
|
|
15
|
+
"`getCurrentUser`, and resolves the current organization from the",
|
|
16
|
+
"signed-in user's memberships. Set up auth first, then run this command",
|
|
17
|
+
"again:",
|
|
18
|
+
"",
|
|
19
|
+
` ${formatCedarCommand(["setup", "auth", "dbAuth"])}`,
|
|
20
|
+
"",
|
|
21
|
+
"Any provider works. See https://cedarjs.com/docs/authentication"
|
|
22
|
+
].join("\n");
|
|
23
|
+
}
|
|
21
24
|
function noUserModelMessage(schemaPath) {
|
|
22
25
|
return [
|
|
23
26
|
`No \`User\` model found in ${schemaPath}.`,
|
|
@@ -30,7 +33,7 @@ function noUserModelMessage(schemaPath) {
|
|
|
30
33
|
"provider's id in a column beside it, so memberships keep working if you",
|
|
31
34
|
"switch providers or add a second one.",
|
|
32
35
|
"",
|
|
33
|
-
|
|
36
|
+
`Add a model like this one, run \`${formatCedarCommand(["prisma", "migrate", "dev"])}\`, then`,
|
|
34
37
|
"run this command again:",
|
|
35
38
|
"",
|
|
36
39
|
" model User {",
|
|
@@ -40,7 +43,7 @@ function noUserModelMessage(schemaPath) {
|
|
|
40
43
|
].join("\n");
|
|
41
44
|
}
|
|
42
45
|
export {
|
|
43
|
-
|
|
46
|
+
authNotSetUpMessage,
|
|
44
47
|
hasWebAuthFile,
|
|
45
48
|
noUserModelMessage
|
|
46
49
|
};
|
package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template
CHANGED
|
@@ -10,8 +10,9 @@ const BATCH_SIZE = 100
|
|
|
10
10
|
* dbAuth, the signup handler). Every user without a membership gets one, in
|
|
11
11
|
* batches, using the same `ensureDefaultOrganization` new signups use.
|
|
12
12
|
*
|
|
13
|
-
* Run with `
|
|
14
|
-
* has applied the
|
|
13
|
+
* Run with `__DATA_MIGRATE_UP_COMMAND__`, after
|
|
14
|
+
* `__PRISMA_MIGRATE_DEV_COMMAND__` has applied the
|
|
15
|
+
* `Organization`/`Membership` migration.
|
|
15
16
|
*/
|
|
16
17
|
export default async ({ db }: { db: PrismaClient }) => {
|
|
17
18
|
let cursor: string | undefined
|
|
@@ -18,7 +18,7 @@ import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
|
|
|
18
18
|
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
19
19
|
import { runTransform } from "../../../lib/runTransform.js";
|
|
20
20
|
import {
|
|
21
|
-
|
|
21
|
+
authNotSetUpMessage,
|
|
22
22
|
hasWebAuthFile,
|
|
23
23
|
noUserModelMessage
|
|
24
24
|
} from "./preflight.js";
|
|
@@ -61,7 +61,7 @@ const SIGNUP_SNIPPET = `
|
|
|
61
61
|
const handler = async ({ tenantField, force }) => {
|
|
62
62
|
const paths = getPaths();
|
|
63
63
|
if (!hasWebAuthFile(paths.web.src)) {
|
|
64
|
-
console.error(c.error(
|
|
64
|
+
console.error(c.error(authNotSetUpMessage()));
|
|
65
65
|
process.exit(1);
|
|
66
66
|
}
|
|
67
67
|
const preflightSchemaPath = await getSchemaPath(paths.api.prismaConfig);
|
|
@@ -82,16 +82,13 @@ const handler = async ({ tenantField, force }) => {
|
|
|
82
82
|
const graphqlPath = path.join(paths.api.functions, `graphql.${ext}`);
|
|
83
83
|
const functionsAuthPath = path.join(paths.api.functions, `auth.${ext}`);
|
|
84
84
|
const isDbAuthProject = fs.existsSync(functionsAuthPath) && fs.readFileSync(functionsAuthPath, "utf-8").includes("DbAuthHandler");
|
|
85
|
-
const writeTemplateFile = async (templateFile, outputPath) => {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
encoding: "utf8",
|
|
93
|
-
flag: "r"
|
|
94
|
-
});
|
|
85
|
+
const writeTemplateFile = async (templateFile, outputPath, replacements = {}) => {
|
|
86
|
+
const dirname = import.meta.dirname;
|
|
87
|
+
const templatePath = path.resolve(dirname, "templates", templateFile);
|
|
88
|
+
let templateContent = fs.readFileSync(templatePath, "utf-8");
|
|
89
|
+
for (const [token, value] of Object.entries(replacements)) {
|
|
90
|
+
templateContent = templateContent.replaceAll(token, value);
|
|
91
|
+
}
|
|
95
92
|
const content = projectIsTypescript ? templateContent : await transformTSToJS(outputPath, templateContent);
|
|
96
93
|
return writeFile(outputPath, content, { overwriteExisting: force });
|
|
97
94
|
};
|
|
@@ -116,8 +113,10 @@ const handler = async ({ tenantField, force }) => {
|
|
|
116
113
|
} catch (e) {
|
|
117
114
|
const message = e instanceof Error ? e.message : String(e);
|
|
118
115
|
if (message === "CEDAR_TENANCY_ERR_NO_USER_MODEL") {
|
|
116
|
+
const authSetup = formatCedarCommand(["setup", "auth", "dbAuth"]);
|
|
117
|
+
const tenancySetup = formatCedarCommand(["setup", "tenancy"]);
|
|
119
118
|
throw new Error(
|
|
120
|
-
|
|
119
|
+
`No \`User\` model found in schema.prisma. Set up authentication first (e.g. \`${authSetup}\`) before running \`${tenancySetup}\`.`
|
|
121
120
|
);
|
|
122
121
|
}
|
|
123
122
|
if (message === "CEDAR_TENANCY_ERR_MODELS_EXIST") {
|
|
@@ -159,12 +158,13 @@ const handler = async ({ tenantField, force }) => {
|
|
|
159
158
|
});
|
|
160
159
|
if (transformResult.error) {
|
|
161
160
|
if (transformResult.error === "CEDAR_CODEMOD_ERR_OLD_FORMAT") {
|
|
161
|
+
const tenancySetup = formatCedarCommand(["setup", "tenancy"]);
|
|
162
162
|
throw new Error(
|
|
163
|
-
|
|
163
|
+
`It looks like your api/src/lib/db file is using the old format. Please update it as per the v8 upgrade guide, then run \`${tenancySetup}\` again.`
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
166
|
throw new Error(
|
|
167
|
-
"Could not add the tenancy Prisma extension. Please modify api/src/lib/db by hand: wrap the `db` export in `.$extends(createTenancyExtension({ models: { allExcept: ['user', 'organization', 'membership'] } }))`."
|
|
167
|
+
"Could not add the tenancy Prisma extension. Please modify `api/src/lib/db` by hand: wrap the `db` export in `.$extends(createTenancyExtension({ models: { allExcept: ['user', 'organization', 'membership'] } }))`."
|
|
168
168
|
);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
@@ -271,7 +271,18 @@ ${SIGNUP_SNIPPET}`;
|
|
|
271
271
|
path.join(
|
|
272
272
|
dataMigrationsPath,
|
|
273
273
|
`${timestamp}-ensure-default-organizations.${ext}`
|
|
274
|
-
)
|
|
274
|
+
),
|
|
275
|
+
{
|
|
276
|
+
__DATA_MIGRATE_UP_COMMAND__: formatCedarCommand([
|
|
277
|
+
"data-migrate",
|
|
278
|
+
"up"
|
|
279
|
+
]),
|
|
280
|
+
__PRISMA_MIGRATE_DEV_COMMAND__: formatCedarCommand([
|
|
281
|
+
"prisma",
|
|
282
|
+
"migrate",
|
|
283
|
+
"dev"
|
|
284
|
+
])
|
|
285
|
+
}
|
|
275
286
|
);
|
|
276
287
|
}
|
|
277
288
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3107",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
"@babel/preset-typescript": "7.29.7",
|
|
37
37
|
"@babel/traverse": "7.29.8",
|
|
38
38
|
"@babel/types": "7.29.8",
|
|
39
|
-
"@cedarjs/api-server": "7.0.0-canary.
|
|
40
|
-
"@cedarjs/babel-config": "7.0.0-canary.
|
|
41
|
-
"@cedarjs/cli-helpers": "7.0.0-canary.
|
|
42
|
-
"@cedarjs/internal": "7.0.0-canary.
|
|
43
|
-
"@cedarjs/prerender": "7.0.0-canary.
|
|
44
|
-
"@cedarjs/project-config": "7.0.0-canary.
|
|
45
|
-
"@cedarjs/structure": "7.0.0-canary.
|
|
46
|
-
"@cedarjs/telemetry": "7.0.0-canary.
|
|
47
|
-
"@cedarjs/utils": "7.0.0-canary.
|
|
48
|
-
"@cedarjs/vite": "7.0.0-canary.
|
|
49
|
-
"@cedarjs/web-server": "7.0.0-canary.
|
|
39
|
+
"@cedarjs/api-server": "7.0.0-canary.3107",
|
|
40
|
+
"@cedarjs/babel-config": "7.0.0-canary.3107",
|
|
41
|
+
"@cedarjs/cli-helpers": "7.0.0-canary.3107",
|
|
42
|
+
"@cedarjs/internal": "7.0.0-canary.3107",
|
|
43
|
+
"@cedarjs/prerender": "7.0.0-canary.3107",
|
|
44
|
+
"@cedarjs/project-config": "7.0.0-canary.3107",
|
|
45
|
+
"@cedarjs/structure": "7.0.0-canary.3107",
|
|
46
|
+
"@cedarjs/telemetry": "7.0.0-canary.3107",
|
|
47
|
+
"@cedarjs/utils": "7.0.0-canary.3107",
|
|
48
|
+
"@cedarjs/vite": "7.0.0-canary.3107",
|
|
49
|
+
"@cedarjs/web-server": "7.0.0-canary.3107",
|
|
50
50
|
"@listr2/prompt-adapter-enquirer": "4.3.1",
|
|
51
51
|
"@opentelemetry/api": "1.9.1",
|
|
52
52
|
"@opentelemetry/core": "1.30.1",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"yargs": "17.7.3"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
97
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3107",
|
|
98
98
|
"@prisma/dmmf": "7.10.0",
|
|
99
99
|
"@types/archiver": "^7.0.0",
|
|
100
100
|
"memfs": "4.68.2",
|