@stacksjs/buddy 0.75.522 → 0.75.524
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/commands/user.d.ts +16 -0
- package/dist/commands/user.js +1 -1
- package/package.json +55 -55
package/dist/commands/user.d.ts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
import type { CLI } from '@stacksjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* Make sure the column holds a hash of `password`, never the password.
|
|
4
|
+
*
|
|
5
|
+
* A model `create` runs the model's password setter; a query-builder
|
|
6
|
+
* `update` does not, and wrote the new password into the column as typed
|
|
7
|
+
* (2026-11-08: `--update` stored the password in plain text, which signs
|
|
8
|
+
* nobody in and sits readable in the database). So whatever wrote it, the
|
|
9
|
+
* column is read back: anything that is not a recognisable hash is replaced
|
|
10
|
+
* with one, and the result has to verify before the command says it worked.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureHashed(address: string, password: string, column?: PasswordColumn): Promise<void>;
|
|
2
13
|
export declare function user(buddy: CLI): void;
|
|
14
|
+
/** Reads and writes the stored password column, past the model (which hides it). */
|
|
15
|
+
export declare interface PasswordColumn {
|
|
16
|
+
read: (address: string) => Promise<string>
|
|
17
|
+
write: (address: string, hash: string) => Promise<void>
|
|
18
|
+
}
|
package/dist/commands/user.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{randomBytes}from"node:crypto";import process from"node:process";import{log}from"@stacksjs/cli";import{ExitCode}from"@stacksjs/types";function generatePassword(){return randomBytes(18).toString("base64url")}async function loadUserModel(){const{existsSync}=await import("node:fs");const{join}=await import("node:path");const candidates=[join(process.cwd(),"app/Models/User.ts"),join(process.cwd(),"storage/framework/defaults/app/Models/User.ts"),join(process.cwd(),"node_modules/@stacksjs/defaults/app/Models/User.ts")];for(const candidate of candidates){if(!existsSync(candidate))continue;const loaded=(await import(candidate)).default;if(loaded?.where)return loaded}const{User}=await import("@stacksjs/orm");if(User)return User;await log.error("Could not find a User model. Looked in app/Models, the framework defaults and @stacksjs/orm.");await log.flush();process.exit(ExitCode.FatalError)}export function user(buddy){buddy.command("user:add <email>","Create a user account (optionally an admin)").option("--name <name>","Display name. Defaults to the local part of the email.").option("--password <password>","Password. Generated and printed once if omitted.").option("--role <role>","Role to assign, e.g. admin. Seeds the default roles if the table is empty.").option("--update","If the account already exists, reset its password and ensure the role",{default:false}).example("buddy user:add chris@example.com --role admin").example("buddy user:add support@example.com --name Support --password s3cret").action(async(email,options)=>{const address=String(email||"").trim().toLowerCase();if(!address.includes("@")){await log.error(`\`${email}\` is not an email address.`);await log.flush();process.exit(ExitCode.FatalError)}const password=options.password||generatePassword();const generated=!options.password;const name=options.name||address.split("@")[0];const User=await loadUserModel();let account=await User.where("email",address).first();if(account&&!options.update){await log.error(`${address} already exists. Pass --update to reset its password and role.`);await log.flush();process.exit(ExitCode.FatalError)}
|
|
1
|
+
import{randomBytes}from"node:crypto";import process from"node:process";import{log}from"@stacksjs/cli";import{ExitCode}from"@stacksjs/types";function generatePassword(){return randomBytes(18).toString("base64url")}async function loadUserModel(){const{existsSync}=await import("node:fs");const{join}=await import("node:path");const candidates=[join(process.cwd(),"app/Models/User.ts"),join(process.cwd(),"storage/framework/defaults/app/Models/User.ts"),join(process.cwd(),"node_modules/@stacksjs/defaults/app/Models/User.ts")];for(const candidate of candidates){if(!existsSync(candidate))continue;const loaded=(await import(candidate)).default;if(loaded?.where)return loaded}const{User}=await import("@stacksjs/orm");if(User)return User;await log.error("Could not find a User model. Looked in app/Models, the framework defaults and @stacksjs/orm.");await log.flush();process.exit(ExitCode.FatalError)}const usersTable={async read(address){const{db}=await import("@stacksjs/database");const row=await db.selectFrom("users").select(["password"]).where("email","=",address).executeTakeFirst();return String(row?.password??"")},async write(address,hash){const{db}=await import("@stacksjs/database");await db.updateTable("users").set({password:hash}).where("email","=",address).execute()}};export async function ensureHashed(address,password,column=usersTable){const{check,detectAlgorithm,make}=await import("@stacksjs/security");if(detectAlgorithm(await column.read(address))==="unknown")await column.write(address,await make(password,{algorithm:"bcrypt"}));if(!await check(password,await column.read(address)))throw new Error(`The password stored for ${address} does not verify; it was not changed safely.`)}export function user(buddy){buddy.command("user:add <email>","Create a user account (optionally an admin)").option("--name <name>","Display name. Defaults to the local part of the email.").option("--password <password>","Password. Generated and printed once if omitted.").option("--role <role>","Role to assign, e.g. admin. Seeds the default roles if the table is empty.").option("--update","If the account already exists, reset its password and ensure the role",{default:false}).example("buddy user:add chris@example.com --role admin").example("buddy user:add support@example.com --name Support --password s3cret").action(async(email,options)=>{const address=String(email||"").trim().toLowerCase();if(!address.includes("@")){await log.error(`\`${email}\` is not an email address.`);await log.flush();process.exit(ExitCode.FatalError)}const password=options.password||generatePassword();const generated=!options.password;const name=options.name||address.split("@")[0];const User=await loadUserModel();let account=await User.where("email",address).first();if(account&&!options.update){await log.error(`${address} already exists. Pass --update to reset its password and role.`);await log.flush();process.exit(ExitCode.FatalError)}const existed=Boolean(account);if(existed){const{make}=await import("@stacksjs/security");await User.where("email",address).update({password:await make(password)})}else{await User.create({email:address,name,password});account=await User.where("email",address).first()}try{await ensureHashed(address,password)}catch(error){await log.error(error instanceof Error?error.message:String(error));await log.flush();process.exit(ExitCode.FatalError)}log.success(`${existed?"Updated":"Created"} ${address}`);if(options.role){const{createBqbRbacStore,Rbac,seedDefaultRoles}=await import("@stacksjs/auth");try{Rbac.setStore(createBqbRbacStore());await seedDefaultRoles();await Rbac.assignRole(account,options.role);log.success(`Assigned the ${options.role} role`)}catch(error){log.error(`Could not assign the ${options.role} role: ${error instanceof Error?error.message:String(error)}`);log.info("The account exists; assign the role once the roles tables are migrated.")}}if(generated){process.stdout.write(`
|
|
2
2
|
${address}
|
|
3
3
|
${password}
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/buddy",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.524",
|
|
6
6
|
"description": "Meet Buddy. The Stacks runtime.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -95,69 +95,69 @@
|
|
|
95
95
|
"prepublishOnly": "bun run build"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@stacksjs/actions": "0.75.
|
|
99
|
-
"@stacksjs/ai": "0.75.
|
|
100
|
-
"@stacksjs/alias": "0.75.
|
|
101
|
-
"@stacksjs/analytics": "0.75.
|
|
102
|
-
"@stacksjs/api": "0.75.
|
|
103
|
-
"@stacksjs/arrays": "0.75.
|
|
104
|
-
"@stacksjs/auth": "0.75.
|
|
105
|
-
"@stacksjs/browser-extension": "0.75.
|
|
106
|
-
"@stacksjs/build": "0.75.
|
|
98
|
+
"@stacksjs/actions": "0.75.524",
|
|
99
|
+
"@stacksjs/ai": "0.75.524",
|
|
100
|
+
"@stacksjs/alias": "0.75.524",
|
|
101
|
+
"@stacksjs/analytics": "0.75.524",
|
|
102
|
+
"@stacksjs/api": "0.75.524",
|
|
103
|
+
"@stacksjs/arrays": "0.75.524",
|
|
104
|
+
"@stacksjs/auth": "0.75.524",
|
|
105
|
+
"@stacksjs/browser-extension": "0.75.524",
|
|
106
|
+
"@stacksjs/build": "0.75.524",
|
|
107
107
|
"@stacksjs/bumpx": "^0.2.26",
|
|
108
|
-
"@stacksjs/cache": "0.75.
|
|
109
|
-
"@stacksjs/chat": "0.75.
|
|
108
|
+
"@stacksjs/cache": "0.75.524",
|
|
109
|
+
"@stacksjs/chat": "0.75.524",
|
|
110
110
|
"@stacksjs/clapp": "^0.2.16",
|
|
111
|
-
"@stacksjs/cli": "0.75.
|
|
112
|
-
"@stacksjs/cloud": "0.75.
|
|
113
|
-
"@stacksjs/cms": "0.75.
|
|
114
|
-
"@stacksjs/collections": "0.75.
|
|
115
|
-
"@stacksjs/commerce": "0.75.
|
|
116
|
-
"@stacksjs/config": "0.75.
|
|
117
|
-
"@stacksjs/database": "0.75.
|
|
118
|
-
"@stacksjs/desktop-build": "0.75.
|
|
119
|
-
"@stacksjs/dns": "0.75.
|
|
111
|
+
"@stacksjs/cli": "0.75.524",
|
|
112
|
+
"@stacksjs/cloud": "0.75.524",
|
|
113
|
+
"@stacksjs/cms": "0.75.524",
|
|
114
|
+
"@stacksjs/collections": "0.75.524",
|
|
115
|
+
"@stacksjs/commerce": "0.75.524",
|
|
116
|
+
"@stacksjs/config": "0.75.524",
|
|
117
|
+
"@stacksjs/database": "0.75.524",
|
|
118
|
+
"@stacksjs/desktop-build": "0.75.524",
|
|
119
|
+
"@stacksjs/dns": "0.75.524",
|
|
120
120
|
"@stacksjs/dnsx": "^0.2.3",
|
|
121
|
-
"@stacksjs/email": "0.75.
|
|
122
|
-
"@stacksjs/enums": "0.75.
|
|
123
|
-
"@stacksjs/env": "0.75.
|
|
124
|
-
"@stacksjs/error-handling": "0.75.
|
|
125
|
-
"@stacksjs/events": "0.75.
|
|
126
|
-
"@stacksjs/features": "0.75.
|
|
127
|
-
"@stacksjs/git": "0.75.
|
|
121
|
+
"@stacksjs/email": "0.75.524",
|
|
122
|
+
"@stacksjs/enums": "0.75.524",
|
|
123
|
+
"@stacksjs/env": "0.75.524",
|
|
124
|
+
"@stacksjs/error-handling": "0.75.524",
|
|
125
|
+
"@stacksjs/events": "0.75.524",
|
|
126
|
+
"@stacksjs/features": "0.75.524",
|
|
127
|
+
"@stacksjs/git": "0.75.524",
|
|
128
128
|
"@stacksjs/gitit": "^0.2.5",
|
|
129
|
-
"@stacksjs/health": "0.75.
|
|
129
|
+
"@stacksjs/health": "0.75.524",
|
|
130
130
|
"@stacksjs/httx": "^0.1.10",
|
|
131
|
-
"@stacksjs/image": "0.75.
|
|
132
|
-
"@stacksjs/lint": "0.75.
|
|
133
|
-
"@stacksjs/logging": "0.75.
|
|
134
|
-
"@stacksjs/notifications": "0.75.
|
|
135
|
-
"@stacksjs/objects": "0.75.
|
|
136
|
-
"@stacksjs/orm": "0.75.
|
|
137
|
-
"@stacksjs/path": "0.75.
|
|
138
|
-
"@stacksjs/payments": "0.75.
|
|
139
|
-
"@stacksjs/realtime": "0.75.
|
|
140
|
-
"@stacksjs/router": "0.75.
|
|
131
|
+
"@stacksjs/image": "0.75.524",
|
|
132
|
+
"@stacksjs/lint": "0.75.524",
|
|
133
|
+
"@stacksjs/logging": "0.75.524",
|
|
134
|
+
"@stacksjs/notifications": "0.75.524",
|
|
135
|
+
"@stacksjs/objects": "0.75.524",
|
|
136
|
+
"@stacksjs/orm": "0.75.524",
|
|
137
|
+
"@stacksjs/path": "0.75.524",
|
|
138
|
+
"@stacksjs/payments": "0.75.524",
|
|
139
|
+
"@stacksjs/realtime": "0.75.524",
|
|
140
|
+
"@stacksjs/router": "0.75.524",
|
|
141
141
|
"@stacksjs/rpx": "^0.11.54",
|
|
142
|
-
"@stacksjs/scheduler": "0.75.
|
|
143
|
-
"@stacksjs/search-engine": "0.75.
|
|
144
|
-
"@stacksjs/security": "0.75.
|
|
145
|
-
"@stacksjs/server": "0.75.
|
|
146
|
-
"@stacksjs/sites": "0.75.
|
|
147
|
-
"@stacksjs/skills": "0.75.
|
|
148
|
-
"@stacksjs/socials": "0.75.
|
|
149
|
-
"@stacksjs/storage": "0.75.
|
|
150
|
-
"@stacksjs/strings": "0.75.
|
|
142
|
+
"@stacksjs/scheduler": "0.75.524",
|
|
143
|
+
"@stacksjs/search-engine": "0.75.524",
|
|
144
|
+
"@stacksjs/security": "0.75.524",
|
|
145
|
+
"@stacksjs/server": "0.75.524",
|
|
146
|
+
"@stacksjs/sites": "0.75.524",
|
|
147
|
+
"@stacksjs/skills": "0.75.524",
|
|
148
|
+
"@stacksjs/socials": "0.75.524",
|
|
149
|
+
"@stacksjs/storage": "0.75.524",
|
|
150
|
+
"@stacksjs/strings": "0.75.524",
|
|
151
151
|
"@stacksjs/stx": "0.2.807",
|
|
152
|
-
"@stacksjs/testing": "0.75.
|
|
153
|
-
"@stacksjs/tinker": "0.75.
|
|
152
|
+
"@stacksjs/testing": "0.75.524",
|
|
153
|
+
"@stacksjs/tinker": "0.75.524",
|
|
154
154
|
"@stacksjs/tlsx": "^0.13.19",
|
|
155
155
|
"@stacksjs/ts-cloud": "^0.16.109",
|
|
156
|
-
"@stacksjs/tunnel": "0.75.
|
|
157
|
-
"@stacksjs/types": "0.75.
|
|
158
|
-
"@stacksjs/ui": "0.75.
|
|
159
|
-
"@stacksjs/utils": "0.75.
|
|
160
|
-
"@stacksjs/validation": "0.75.
|
|
156
|
+
"@stacksjs/tunnel": "0.75.524",
|
|
157
|
+
"@stacksjs/types": "0.75.524",
|
|
158
|
+
"@stacksjs/ui": "0.75.524",
|
|
159
|
+
"@stacksjs/utils": "0.75.524",
|
|
160
|
+
"@stacksjs/validation": "0.75.524",
|
|
161
161
|
"ajv": "^8.20.0",
|
|
162
162
|
"ajv-formats": "^3.0.1",
|
|
163
163
|
"bun-plugin-stx": "0.2.807",
|