Skip to content

Commit 5644d3b

Browse files
committed
refactor: make the zenstackhq/plugin-policy as the dependencies of zenstack CLI project
1 parent 12bf3f4 commit 5644d3b

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@zenstackhq/orm": "workspace:*",
4646
"@zenstackhq/schema": "workspace:*",
4747
"@zenstackhq/sdk": "workspace:*",
48+
"@zenstackhq/plugin-policy": "workspace:*",
4849
"@zenstackhq/server": "workspace:*",
4950
"chokidar": "^5.0.0",
5051
"colors": "1.4.0",
@@ -72,7 +73,6 @@
7273
"@types/semver": "^7.7.0",
7374
"@types/tmp": "catalog:",
7475
"@zenstackhq/eslint-config": "workspace:*",
75-
"@zenstackhq/plugin-policy": "workspace:*",
7676
"@zenstackhq/testtools": "workspace:*",
7777
"@zenstackhq/tsdown-config": "workspace:*",
7878
"@zenstackhq/typescript-config": "workspace:*",

packages/cli/src/actions/proxy.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { MysqlDialect } from '@zenstackhq/orm/dialects/mysql';
1212
import { PostgresDialect } from '@zenstackhq/orm/dialects/postgres';
1313
import { SqliteDialect } from '@zenstackhq/orm/dialects/sqlite';
1414
import type { SchemaDef } from '@zenstackhq/orm/schema';
15+
import { PolicyPlugin } from '@zenstackhq/plugin-policy';
1516
import { RPCApiHandler } from '@zenstackhq/server/api';
1617
import { ZenStackMiddleware } from '@zenstackhq/server/express';
1718
import type BetterSqlite3 from 'better-sqlite3';
@@ -113,20 +114,11 @@ export async function run(options: Options) {
113114
throw new CliError(`Failed to connect to the database: ${err instanceof Error ? err.message : String(err)}`);
114115
}
115116

116-
// If a publicAPIKey is provided, try to create an authDb with the policy plugin
117+
// If a publicAPIKey is provided, create an authDb with the policy plugin
117118
let authDb: ClientContract<SchemaDef> | undefined;
118119
if (options.publicAPIKey) {
119-
try {
120-
const { PolicyPlugin } = await import('@zenstackhq/plugin-policy');
121-
authDb = db.$use(new PolicyPlugin()) as ClientContract<SchemaDef>;
122-
console.log(colors.gray('Access policy plugin enabled for authorization.'));
123-
} catch {
124-
console.log(
125-
colors.yellow(
126-
'Warning: @zenstackhq/plugin-policy is not installed. Authorization (per-user access control) will be disabled.',
127-
),
128-
);
129-
}
120+
authDb = db.$use(new PolicyPlugin()) as ClientContract<SchemaDef>;
121+
console.log(colors.gray('Access policy plugin enabled for authorization.'));
130122
}
131123

132124
startServer(db, schemaModule.schema, options, authDb);

0 commit comments

Comments
 (0)