@frigear-nu/cli 0.2.0 → 0.2.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/dist/chunks/upgrade.mjs +84 -11
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/shared/{cli.BNukBQzw.mjs → cli.B9oeiTli.mjs} +1 -1
- package/package.json +2 -2
package/dist/chunks/upgrade.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
3
4
|
import { readFile, writeFile, readdir, stat } from 'node:fs/promises';
|
|
4
5
|
import { join, basename, relative, dirname, resolve } from 'node:path';
|
|
5
|
-
import { existsSync } from 'node:fs';
|
|
6
6
|
import { parseModule } from 'magicast';
|
|
7
7
|
import { getDefaultExportOptions } from 'magicast/helpers';
|
|
8
8
|
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.Cfkcp0w9.mjs';
|
|
@@ -74,10 +74,13 @@ const runMigrations = async (migrations, ctx) => {
|
|
|
74
74
|
for (const rule of migration.rules ?? []) {
|
|
75
75
|
if (rule.files && !rule.files.test(file)) continue;
|
|
76
76
|
if (rule.when && !rule.when.test(text)) continue;
|
|
77
|
+
if (rule.unless?.test(text)) continue;
|
|
77
78
|
for (const match of text.matchAll(rule.pattern)) {
|
|
78
79
|
const line = lineOf(text, match.index);
|
|
79
|
-
const
|
|
80
|
-
|
|
80
|
+
const hits = rule.replace === void 0 ? result.manual : result.applied;
|
|
81
|
+
const last = hits.at(-1);
|
|
82
|
+
if (last?.file === file && last.line === line && last.message === rule.message) continue;
|
|
83
|
+
hits.push({ file, line, text: lineText(text, line), message: rule.message });
|
|
81
84
|
}
|
|
82
85
|
if (rule.replace !== void 0) text = text.replace(rule.pattern, rule.replace);
|
|
83
86
|
}
|
|
@@ -173,7 +176,7 @@ const authPermissions = {
|
|
|
173
176
|
],
|
|
174
177
|
steps: [
|
|
175
178
|
"Mint API tokens again: a token issued before the upgrade has no frozen permissions and holds nothing.",
|
|
176
|
-
"Everything fails closed: an unregistered permission is a 403 (also for admins), and `*` never covers `:pii`
|
|
179
|
+
"Everything fails closed: an unregistered permission is a 403 (also for admins), and `*` never covers sensitive (`:pii`) permissions. Click through the staff areas before deploying."
|
|
177
180
|
],
|
|
178
181
|
async project({ root, files }) {
|
|
179
182
|
const manual = [];
|
|
@@ -225,15 +228,42 @@ const authorizationRoles = {
|
|
|
225
228
|
pattern: /\buseAuthorization\(\)/g,
|
|
226
229
|
when: /\bcan\(\s*(?!['"`])/,
|
|
227
230
|
message: "Check the `can(...)` calls in this file: `can(permission, record?)` takes a permission name now, not an ability."
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
pattern: /\b(?:effectiveRole|userHasRole|hasRole)\b/g,
|
|
234
|
+
message: "A role check of its own: access comes from roles that grant permissions now. Check the permission (`authorize` / `allows` on the server, `can()` in the client), and move an env allowlist to an `authorization:roles` hook that pushes the role (it is never stored)."
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
pattern: /\b(?:NUXT_ACL_ADMINS|NUXT_ADMIN_EMAILS|aclAdmins|adminEmails)\b/g,
|
|
238
|
+
unless: /authorization:roles/,
|
|
239
|
+
message: "An admin allowlist: give those users the role in an `authorization:roles` hook (`ctx.roles.push('admin')`, from `ctx.user`, verified addresses only) instead of a role on the session or the user row."
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
pattern: /\b\w*[uU]sers?\??\.role\b/g,
|
|
243
|
+
message: "`users.role` is copied once into `authorization_user_roles` and never read again: a read sees a stale value, a write is silently ignored (new users get no role). Read access with `can()` / `allows`, and assign roles with `setAuthUserRoles` (or the users admin)."
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
pattern: /\brole\s*:\s*['"`][\w-]+['"`]/g,
|
|
247
|
+
when: /\binsert\(\s*users\b|\b(?:createUser|findOrCreateUser|defineTask)\b/,
|
|
248
|
+
message: "Writes `users.role`, which is no longer read: assign the role with `setAuthUserRoles(userId, roles, { source: 'manual' })` instead."
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
pattern: /\brequireAuth\(\s*[\w.]+\s*,\s*\{[^}]*\bsessionOnly\b/g,
|
|
252
|
+
when: /\.role\b|effectiveRole|isAdmin/,
|
|
253
|
+
message: "A session-only route with a role check: register a `sessionOnly` permission granted to that role and check it with `authorize(event, permission)`."
|
|
228
254
|
}
|
|
229
255
|
],
|
|
230
256
|
steps: [
|
|
231
|
-
"Run the verification SQL of the migration guide: `users.role` is copied once into `authorization_user_roles` and no longer read."
|
|
257
|
+
"Run the verification SQL of the migration guide: `users.role` is copied once into `authorization_user_roles` and no longer read.",
|
|
258
|
+
"Roles add up: a user holds their assigned roles plus every `defaultRoles` role. Where a stored role used to replace the default (a `tenant` who is not a `user`), drop the default in an `authorization:roles` hook, or leave it out of `defaultRoles`."
|
|
232
259
|
],
|
|
233
260
|
async project({ root, files }) {
|
|
234
261
|
const manual = [];
|
|
235
262
|
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
236
263
|
const at = relative(root, file);
|
|
264
|
+
if (option(options, "authentication.settings.session.mapper") !== void 0) {
|
|
265
|
+
manual.push(`${at}: \`authentication.settings.session.mapper\` is set. If it puts \`role\` on the session user, remove that (or the mapper): access no longer reads it, and a stale role on the session only misleads the client.`);
|
|
266
|
+
}
|
|
237
267
|
const removed = ["abilities", "resolvers", "rbac"].filter((key) => option(options, `authorization.${key}`) !== void 0);
|
|
238
268
|
const roleKeys = ["hierarchy", "inherits", "grant", "revoke", "labels", "descriptions", "definitions", "defaultRole"].filter((key) => option(options, `authorization.roles.${key}`) !== void 0);
|
|
239
269
|
if (removed.length || roleKeys.length) {
|
|
@@ -393,6 +423,24 @@ const usersRoutes = {
|
|
|
393
423
|
]
|
|
394
424
|
};
|
|
395
425
|
|
|
426
|
+
const SERVER_AUTH = ["@frigear-nu/auth", "@frigear-nu/users", "@frigear-nu/oauth-server"];
|
|
427
|
+
const hasServerSessions = async (config, options) => {
|
|
428
|
+
if (option(options, "ssr") === false || option(options, "authentication.mode") === "client") return false;
|
|
429
|
+
const manifest = join(dirname(config), "package.json");
|
|
430
|
+
if (!existsSync(manifest)) return false;
|
|
431
|
+
const pkg = JSON.parse(await readFile(manifest, "utf-8"));
|
|
432
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
433
|
+
return SERVER_AUTH.some((name) => name in deps);
|
|
434
|
+
};
|
|
435
|
+
const addAppSecret = (text) => {
|
|
436
|
+
const entry = "# Seals the session cookie (32+ random characters).\nNUXT_APP_SECRET=";
|
|
437
|
+
const session = /^\s*NUXT_SESSION_PASSWORD\s*=.*$/m.exec(text);
|
|
438
|
+
if (!session) return `${text.replace(/\n*$/, "\n")}${entry}
|
|
439
|
+
`;
|
|
440
|
+
const end = session.index + session[0].length;
|
|
441
|
+
return `${text.slice(0, end)}
|
|
442
|
+
${entry}${text.slice(end)}`;
|
|
443
|
+
};
|
|
396
444
|
const authSessionSecret = {
|
|
397
445
|
id: "auth-session-secret",
|
|
398
446
|
package: "@frigear-nu/auth",
|
|
@@ -401,21 +449,26 @@ const authSessionSecret = {
|
|
|
401
449
|
docs: `${DOCS}/get-started/upgrading#breaking-changes-by-release`,
|
|
402
450
|
schema: true,
|
|
403
451
|
steps: [
|
|
404
|
-
"Set `NUXT_APP_SECRET` (32+ random characters) in every environment before deploying
|
|
452
|
+
"Set `NUXT_APP_SECRET` (32+ random characters) in every environment before deploying, and in any script that generates `.env`.",
|
|
453
|
+
"`NUXT_SESSION_PASSWORD` no longer seals sessions. Keep it only where the app stores OAuth or Frigear SSO tokens (it is their key) or reads it itself; otherwise remove it.",
|
|
405
454
|
"The session cookie is renamed (`nuxt-auth-session`): every user is signed out once after the deploy."
|
|
406
455
|
],
|
|
407
456
|
async project({ root, files, dryRun }) {
|
|
408
457
|
const applied = [];
|
|
409
|
-
|
|
458
|
+
const manual = [];
|
|
459
|
+
for (const { file: config, options } of await readNuxtConfigs(files)) {
|
|
460
|
+
if (option(options, "runtimeConfig.session.password") !== void 0) {
|
|
461
|
+
manual.push(`${relative(root, config)}: \`runtimeConfig.session.password\` is no longer read (and is a type error): sessions use \`NUXT_APP_SECRET\`. Remove it.`);
|
|
462
|
+
}
|
|
463
|
+
if (!await hasServerSessions(config, options)) continue;
|
|
410
464
|
const example = join(dirname(config), ".env.example");
|
|
411
465
|
if (!existsSync(example)) continue;
|
|
412
466
|
const text = await readFile(example, "utf-8");
|
|
413
467
|
if (/^\s*NUXT_APP_SECRET\s*=/m.test(text)) continue;
|
|
414
|
-
if (!dryRun) await writeFile(example,
|
|
415
|
-
`, "utf-8");
|
|
468
|
+
if (!dryRun) await writeFile(example, addAppSecret(text), "utf-8");
|
|
416
469
|
applied.push(`Added \`NUXT_APP_SECRET=\` to ${relative(root, example)}`);
|
|
417
470
|
}
|
|
418
|
-
return { applied };
|
|
471
|
+
return { applied, manual };
|
|
419
472
|
}
|
|
420
473
|
};
|
|
421
474
|
|
|
@@ -532,6 +585,14 @@ const currentVersions = (pins) => {
|
|
|
532
585
|
}
|
|
533
586
|
return versions;
|
|
534
587
|
};
|
|
588
|
+
const duplicateVersions = (lock) => {
|
|
589
|
+
const found = /* @__PURE__ */ new Map();
|
|
590
|
+
for (const match of lock.matchAll(/^ {2}'?(@frigear-nu\/[\w.-]+)@(\d[^'(:\s]*)/gm)) {
|
|
591
|
+
const versions = found.get(match[1]) ?? /* @__PURE__ */ new Set();
|
|
592
|
+
found.set(match[1], versions.add(match[2]));
|
|
593
|
+
}
|
|
594
|
+
return Object.fromEntries([...found].filter(([, versions]) => versions.size > 1).map(([name, versions]) => [name, [...versions].sort(compareVersions)]));
|
|
595
|
+
};
|
|
535
596
|
|
|
536
597
|
const REGISTRY = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
537
598
|
const latestVersion = async (name) => {
|
|
@@ -686,7 +747,19 @@ const upgrade = defineCommand({
|
|
|
686
747
|
logger.info(`${result.bumps.length} pins updated, ${applied} code changes made, ${manual} items to do by hand: ${reportPath}`);
|
|
687
748
|
if (args.install) {
|
|
688
749
|
logger.start("Installing");
|
|
689
|
-
|
|
750
|
+
try {
|
|
751
|
+
await installDeps(result.root);
|
|
752
|
+
} catch (error) {
|
|
753
|
+
logger.warn(`pnpm install failed: ${error instanceof Error ? error.message.split("\n")[0] : error}`);
|
|
754
|
+
logger.info(`Expected while the report still has items that fail the build (\`nuxt prepare\` runs on install). Work through ${reportPath}, then run \`pnpm install\` again.`);
|
|
755
|
+
process.exitCode = 1;
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const lock = join(result.root, "pnpm-lock.yaml");
|
|
759
|
+
const duplicates = existsSync(lock) ? duplicateVersions(await readFile(lock, "utf-8")) : {};
|
|
760
|
+
for (const [name, versions] of Object.entries(duplicates)) {
|
|
761
|
+
logger.warn(`${name} is installed in ${versions.length} versions (${versions.join(", ")}). Modules share build-time state through one copy: add \`'${name}': ^${result.to[name] ?? versions.at(-1)}\` to \`overrides\` in pnpm-workspace.yaml and run \`pnpm install\` again.`);
|
|
762
|
+
}
|
|
690
763
|
}
|
|
691
764
|
}
|
|
692
765
|
});
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -77,6 +77,8 @@ interface Rule {
|
|
|
77
77
|
files?: RegExp;
|
|
78
78
|
/** Only files whose text matches. */
|
|
79
79
|
when?: RegExp;
|
|
80
|
+
/** Not in files whose text matches (already migrated). */
|
|
81
|
+
unless?: RegExp;
|
|
80
82
|
}
|
|
81
83
|
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
84
|
interface ProjectResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ interface Rule {
|
|
|
77
77
|
files?: RegExp;
|
|
78
78
|
/** Only files whose text matches. */
|
|
79
79
|
when?: RegExp;
|
|
80
|
+
/** Not in files whose text matches (already migrated). */
|
|
81
|
+
unless?: RegExp;
|
|
80
82
|
}
|
|
81
83
|
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
84
|
interface ProjectResult {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { m as default, a as mainCmd } from './shared/cli.
|
|
1
|
+
export { m as default, a as mainCmd } from './shared/cli.B9oeiTli.mjs';
|
|
2
2
|
export { PLATFORMS, STARTERS, default as initCmd, resolveStarter } from './chunks/init.mjs';
|
|
3
3
|
export { m as migrations, u as upgradeWorkspace } from './chunks/upgrade.mjs';
|
|
4
4
|
import 'citty';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Frigear CLI: scaffold projects, apps and modules, and add Frigear modules to an app.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@frigear-nu/eslint-config": "^0.2.5",
|
|
48
48
|
"@types/node": "^26.6.6",
|
|
49
|
-
"eslint": "^10.
|
|
49
|
+
"eslint": "^10.15.0",
|
|
50
50
|
"jiti": "^2.7.0",
|
|
51
51
|
"typescript": "^6.0.3",
|
|
52
52
|
"unbuild": "^3.6.1",
|