Skip to content

Commit 0763ea8

Browse files
authored
fix: regression of password hasing & fine tune default logging (#60)
1 parent 0315bb0 commit 0763ea8

File tree

12 files changed

+68
-49
lines changed

12 files changed

+68
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "0.2.12",
3+
"version": "0.2.15",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/internal/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/internal",
3-
"version": "0.2.12",
3+
"version": "0.2.15",
44
"displayName": "ZenStack Internal Library",
55
"description": "ZenStack internal runtime library. This package is for supporting runtime functionality of ZenStack and not supposed to be used directly.",
66
"repository": {
@@ -10,7 +10,8 @@
1010
"main": "lib/index.js",
1111
"types": "lib/index.d.ts",
1212
"scripts": {
13-
"build": "tsc",
13+
"clean": "rimraf lib",
14+
"build": "npm run clean && tsc",
1415
"watch": "tsc --watch",
1516
"lint": "eslint src --ext ts",
1617
"prepublishOnly": "pnpm build"
@@ -45,6 +46,7 @@
4546
"@types/uuid": "^8.3.4",
4647
"eslint": "^8.27.0",
4748
"jest": "^29.0.3",
49+
"rimraf": "^3.0.2",
4850
"ts-jest": "^29.0.1",
4951
"ts-node": "^10.9.1",
5052
"tsc-alias": "^1.7.0",

packages/internal/src/handler/data/handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export default class DataHandler<DbClient extends DbClientContract>
7878
break;
7979
}
8080
} catch (err: unknown) {
81-
this.service.error(`${method} ${model}: ${err}`);
82-
8381
if (err instanceof RequestHandlerError) {
82+
this.service.warn(`${method} ${model}: ${err}`);
83+
8484
// in case of errors thrown directly by ZenStack
8585
switch (err.code) {
8686
case ServerErrorCode.DENIED_BY_POLICY:
@@ -105,6 +105,8 @@ export default class DataHandler<DbClient extends DbClientContract>
105105
});
106106
}
107107
} else if (this.isPrismaClientKnownRequestError(err)) {
108+
this.service.warn(`${method} ${model}: ${err}`);
109+
108110
// errors thrown by Prisma, try mapping to a known error
109111
if (PRISMA_ERROR_MAPPING[err.code]) {
110112
res.status(400).send({
@@ -120,6 +122,8 @@ export default class DataHandler<DbClient extends DbClientContract>
120122
});
121123
}
122124
} else if (this.isPrismaClientValidationError(err)) {
125+
this.service.warn(`${method} ${model}: ${err}`);
126+
123127
// prisma validation error
124128
res.status(400).send({
125129
code: ServerErrorCode.INVALID_REQUEST_PARAMS,

packages/internal/src/handler/data/policy-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export async function preprocessWritePayload(
634634
const pwdAttr = fieldInfo.attributes?.find(
635635
(attr) => attr.name === '@password'
636636
);
637-
if (pwdAttr && fieldInfo.type !== 'String') {
637+
if (pwdAttr && fieldInfo.type === 'String') {
638638
// hash password value
639639
let salt: string | number | undefined = pwdAttr.args.find(
640640
(arg) => arg.name === 'salt'

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/runtime",
33
"displayName": "ZenStack Runtime Library",
4-
"version": "0.2.12",
4+
"version": "0.2.15",
55
"description": "This package contains runtime library for consuming client and server side code generated by ZenStack.",
66
"repository": {
77
"type": "git",

packages/schema/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack Language Tools",
55
"description": "ZenStack is a toolkit that simplifies full-stack development",
6-
"version": "0.2.12",
6+
"version": "0.2.15",
77
"author": {
88
"name": "ZenStack Team"
99
},
@@ -67,8 +67,9 @@
6767
"vscode:publish": "vsce publish --no-dependencies",
6868
"vscode:prepublish": "cp ../../README.md ./ && pnpm lint && pnpm build",
6969
"vscode:package": "vsce package --no-dependencies",
70+
"clean": "rimraf bundle",
7071
"build": "pnpm langium:generate && tsc --noEmit && pnpm bundle && cp -r src/res/* bundle/res/",
71-
"bundle": "node build/bundle.js --minify",
72+
"bundle": "npm run clean && node build/bundle.js --minify",
7273
"bundle-watch": "node build/bundle.js --watch",
7374
"ts:watch": "tsc --watch --noEmit",
7475
"tsc-alias:watch": "tsc-alias --watch",
@@ -77,7 +78,7 @@
7778
"langium:watch": "langium generate --watch",
7879
"watch": "concurrently --kill-others \"npm:langium:watch\" \"npm:bundle-watch\"",
7980
"test": "jest",
80-
"prepublishOnly": "cp ../../README.md ./ && pnpm build && pnpm bundle"
81+
"prepublishOnly": "cp ../../README.md ./ && pnpm build"
8182
},
8283
"dependencies": {
8384
"@zenstackhq/internal": "workspace:*",
@@ -112,6 +113,7 @@
112113
"eslint": "^8.27.0",
113114
"jest": "^29.2.1",
114115
"langium-cli": "^0.5.0",
116+
"rimraf": "^3.0.2",
115117
"tmp": "^0.2.1",
116118
"ts-jest": "^29.0.3",
117119
"ts-node": "^10.9.1",

packages/schema/src/res/stdlib.zmodel

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ attribute @@deny(_ operation: String, _ condition: Boolean)
104104
* Indicates that the field is a password field and needs to be hashed before persistence.
105105
*
106106
* ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
107-
* to configure length of salt, or use parameter to provide an explicit salt. By default, 12-byte
108-
* long salt is used.
107+
* to configure the cost of hashing, or use `salt` parameter to provide an explicit salt.
108+
* By default, salt length of 12 is used.
109109
*
110-
* @saltLength: length of salt to use
111-
* @salt: salt to use
110+
* @see https://www.npmjs.com/package/bcryptjs for details
111+
*
112+
* @saltLength: length of salt to use (cost factor for the hash function)
113+
* @salt: salt to use (a pregenerated valid salt)
112114
*/
113115
attribute @password(saltLength: Int?, salt: String?)
114116

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/todo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "todo",
3-
"version": "0.2.12",
3+
"version": "0.2.15",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

samples/todo/zenstack.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"log": ["info", "warn", "error"]
3+
}

0 commit comments

Comments
 (0)