@zenstackhq/cli 3.9.0 → 3.9.2
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/index.cjs +17 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +4 -154
- package/dist/index.mjs.map +1 -1
- package/dist/proxy-ByxBTLnf.cjs +251 -0
- package/dist/proxy-ByxBTLnf.cjs.map +1 -0
- package/dist/proxy-DV8jo5y1.mjs +163 -0
- package/dist/proxy-DV8jo5y1.mjs.map +1 -0
- package/dist/proxy.cjs +7 -0
- package/dist/proxy.d.cts +33 -0
- package/dist/proxy.d.mts +33 -0
- package/dist/proxy.mjs +2 -0
- package/package.json +27 -14
package/dist/index.cjs
CHANGED
|
@@ -1,56 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __exportAll = (all, no_symbols) => {
|
|
9
|
-
let target = {};
|
|
10
|
-
for (var name in all) __defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true
|
|
13
|
-
});
|
|
14
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
-
return target;
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
//#endregion
|
|
1
|
+
const require_proxy = require("./proxy-ByxBTLnf.cjs");
|
|
32
2
|
let _zenstackhq_language = require("@zenstackhq/language");
|
|
33
3
|
let colors = require("colors");
|
|
34
|
-
colors = __toESM(colors, 1);
|
|
4
|
+
colors = require_proxy.__toESM(colors, 1);
|
|
35
5
|
let commander = require("commander");
|
|
36
6
|
require("dotenv/config");
|
|
37
7
|
let _zenstackhq_language_ast = require("@zenstackhq/language/ast");
|
|
38
8
|
let node_path = require("node:path");
|
|
39
|
-
node_path = __toESM(node_path, 1);
|
|
9
|
+
node_path = require_proxy.__toESM(node_path, 1);
|
|
40
10
|
let _zenstackhq_common_helpers = require("@zenstackhq/common-helpers");
|
|
41
11
|
let _zenstackhq_sdk = require("@zenstackhq/sdk");
|
|
42
12
|
let jiti = require("jiti");
|
|
43
13
|
let node_crypto = require("node:crypto");
|
|
44
|
-
node_crypto = __toESM(node_crypto, 1);
|
|
14
|
+
node_crypto = require_proxy.__toESM(node_crypto, 1);
|
|
45
15
|
let node_fs = require("node:fs");
|
|
46
|
-
node_fs = __toESM(node_fs, 1);
|
|
16
|
+
node_fs = require_proxy.__toESM(node_fs, 1);
|
|
47
17
|
let node_module = require("node:module");
|
|
48
18
|
let node_url = require("node:url");
|
|
49
19
|
let terminal_link = require("terminal-link");
|
|
50
|
-
terminal_link = __toESM(terminal_link, 1);
|
|
20
|
+
terminal_link = require_proxy.__toESM(terminal_link, 1);
|
|
51
21
|
let zod = require("zod");
|
|
52
22
|
let ora = require("ora");
|
|
53
|
-
ora = __toESM(ora, 1);
|
|
23
|
+
ora = require_proxy.__toESM(ora, 1);
|
|
54
24
|
let child_process = require("child_process");
|
|
55
25
|
let url = require("url");
|
|
56
26
|
let _zenstackhq_language_factory = require("@zenstackhq/language/factory");
|
|
@@ -58,26 +28,22 @@ let langium = require("langium");
|
|
|
58
28
|
let _zenstackhq_language_utils = require("@zenstackhq/language/utils");
|
|
59
29
|
let chokidar = require("chokidar");
|
|
60
30
|
let semver = require("semver");
|
|
61
|
-
semver = __toESM(semver, 1);
|
|
31
|
+
semver = require_proxy.__toESM(semver, 1);
|
|
62
32
|
let package_manager_detector = require("package-manager-detector");
|
|
63
33
|
let execa = require("execa");
|
|
34
|
+
let _hono_node_server = require("@hono/node-server");
|
|
64
35
|
let _zenstackhq_orm = require("@zenstackhq/orm");
|
|
65
36
|
let _zenstackhq_orm_dialects_mysql = require("@zenstackhq/orm/dialects/mysql");
|
|
66
37
|
let _zenstackhq_orm_dialects_postgres = require("@zenstackhq/orm/dialects/postgres");
|
|
67
38
|
let _zenstackhq_orm_dialects_sqlite = require("@zenstackhq/orm/dialects/sqlite");
|
|
68
39
|
let _zenstackhq_plugin_policy = require("@zenstackhq/plugin-policy");
|
|
69
|
-
let _zenstackhq_server_api = require("@zenstackhq/server/api");
|
|
70
|
-
let _zenstackhq_server_hono = require("@zenstackhq/server/hono");
|
|
71
|
-
let _hono_node_server = require("@hono/node-server");
|
|
72
|
-
let hono = require("hono");
|
|
73
|
-
let hono_cors = require("hono/cors");
|
|
74
40
|
require("mixpanel");
|
|
75
41
|
let os = require("os");
|
|
76
|
-
os = __toESM(os, 1);
|
|
42
|
+
os = require_proxy.__toESM(os, 1);
|
|
77
43
|
let node_process = require("node:process");
|
|
78
|
-
node_process = __toESM(node_process, 1);
|
|
44
|
+
node_process = require_proxy.__toESM(node_process, 1);
|
|
79
45
|
let node_os = require("node:os");
|
|
80
|
-
node_os = __toESM(node_os, 1);
|
|
46
|
+
node_os = require_proxy.__toESM(node_os, 1);
|
|
81
47
|
//#region src/cli-error.ts
|
|
82
48
|
/**
|
|
83
49
|
* Indicating an error during CLI execution
|
|
@@ -2694,7 +2660,7 @@ const plugin = {
|
|
|
2694
2660
|
};
|
|
2695
2661
|
//#endregion
|
|
2696
2662
|
//#region src/plugins/index.ts
|
|
2697
|
-
var plugins_exports = /* @__PURE__ */ __exportAll({
|
|
2663
|
+
var plugins_exports = /* @__PURE__ */ require_proxy.__exportAll({
|
|
2698
2664
|
prisma: () => plugin$1,
|
|
2699
2665
|
typescript: () => plugin
|
|
2700
2666
|
});
|
|
@@ -3094,67 +3060,7 @@ function handleSubProcessError(err) {
|
|
|
3094
3060
|
else process.exit(1);
|
|
3095
3061
|
}
|
|
3096
3062
|
//#endregion
|
|
3097
|
-
//#region src/utils/version-utils.ts
|
|
3098
|
-
const CHECK_VERSION_TIMEOUT = 2e3;
|
|
3099
|
-
const VERSION_CHECK_TAG = "latest";
|
|
3100
|
-
function getVersion() {
|
|
3101
|
-
try {
|
|
3102
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname : node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
3103
|
-
return JSON.parse(node_fs.default.readFileSync(node_path.default.join(_dirname, "../package.json"), "utf8")).version;
|
|
3104
|
-
} catch {
|
|
3105
|
-
return;
|
|
3106
|
-
}
|
|
3107
|
-
}
|
|
3108
|
-
async function checkNewVersion() {
|
|
3109
|
-
const currVersion = getVersion();
|
|
3110
|
-
let latestVersion;
|
|
3111
|
-
let timer;
|
|
3112
|
-
try {
|
|
3113
|
-
const fetchPromise = getLatestVersion();
|
|
3114
|
-
fetchPromise.catch(() => {});
|
|
3115
|
-
latestVersion = await Promise.race([fetchPromise, new Promise((_, reject) => {
|
|
3116
|
-
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("version check timed out")), CHECK_VERSION_TIMEOUT + 1e3);
|
|
3117
|
-
})]);
|
|
3118
|
-
} catch {
|
|
3119
|
-
return;
|
|
3120
|
-
} finally {
|
|
3121
|
-
clearTimeout(timer);
|
|
3122
|
-
}
|
|
3123
|
-
if (latestVersion && currVersion && semver.default.gt(latestVersion, currVersion)) console.log(`A newer version ${colors.default.cyan(latestVersion)} is available.`);
|
|
3124
|
-
}
|
|
3125
|
-
async function getLatestVersion() {
|
|
3126
|
-
const fetchResult = await fetch(`https://registry.npmjs.org/@zenstackhq/cli/${VERSION_CHECK_TAG}`, {
|
|
3127
|
-
headers: { accept: "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*" },
|
|
3128
|
-
signal: AbortSignal.timeout(CHECK_VERSION_TIMEOUT)
|
|
3129
|
-
});
|
|
3130
|
-
if (fetchResult.ok) {
|
|
3131
|
-
const latestVersion = (await fetchResult.json())?.version;
|
|
3132
|
-
if (typeof latestVersion === "string" && semver.default.valid(latestVersion)) return latestVersion;
|
|
3133
|
-
}
|
|
3134
|
-
throw new Error("invalid npm registry response");
|
|
3135
|
-
}
|
|
3136
|
-
//#endregion
|
|
3137
3063
|
//#region src/actions/proxy.ts
|
|
3138
|
-
const ProxyAuthError = {
|
|
3139
|
-
MISSING_SIGNATURE_HEADER: "Missing x-zenstack-signature header",
|
|
3140
|
-
INVALID_TIMESTAMP: "Request timestamp is expired or invalid",
|
|
3141
|
-
INVALID_SIGNATURE_FORMAT: "Invalid x-zenstack-signature format"
|
|
3142
|
-
};
|
|
3143
|
-
function rejectAuth(c, code) {
|
|
3144
|
-
return c.json({
|
|
3145
|
-
code,
|
|
3146
|
-
message: ProxyAuthError[code]
|
|
3147
|
-
}, 401);
|
|
3148
|
-
}
|
|
3149
|
-
const UserClaimSchema = zod.z.discriminatedUnion("type", [zod.z.object({ type: zod.z.literal("superUser") }), zod.z.object({
|
|
3150
|
-
type: zod.z.literal("user"),
|
|
3151
|
-
data: zod.z.record(zod.z.string(), zod.z.unknown())
|
|
3152
|
-
})]);
|
|
3153
|
-
function normalizePublicKey(key) {
|
|
3154
|
-
key = key.trim();
|
|
3155
|
-
if (key.startsWith("-----BEGIN PUBLIC KEY-----")) return key;
|
|
3156
|
-
return `-----BEGIN PUBLIC KEY-----\n${key.replace(/-/g, "+").replace(/_/g, "/")}\n-----END PUBLIC KEY-----`;
|
|
3157
|
-
}
|
|
3158
3064
|
async function run(options) {
|
|
3159
3065
|
options = {
|
|
3160
3066
|
...options,
|
|
@@ -3252,96 +3158,9 @@ async function createDialect(provider, databaseUrl, schemaFilePath) {
|
|
|
3252
3158
|
default: throw new CliError(`Unsupported database provider: ${provider}`);
|
|
3253
3159
|
}
|
|
3254
3160
|
}
|
|
3255
|
-
function createProxyApp(optionsOrClient, schema, authDb, auth) {
|
|
3256
|
-
let options;
|
|
3257
|
-
if ("client" in optionsOrClient && "schema" in optionsOrClient) options = optionsOrClient;
|
|
3258
|
-
else options = {
|
|
3259
|
-
client: optionsOrClient,
|
|
3260
|
-
schema,
|
|
3261
|
-
authDb,
|
|
3262
|
-
auth
|
|
3263
|
-
};
|
|
3264
|
-
const app = new hono.Hono();
|
|
3265
|
-
app.use("*", (0, hono_cors.cors)(options.cors));
|
|
3266
|
-
if (options.auth?.studioAuthKey) {
|
|
3267
|
-
const toleranceSecs = options.auth.signatureToleranceSecs;
|
|
3268
|
-
const sigMiddleware = createSignatureMiddleware(normalizePublicKey(options.auth.studioAuthKey), toleranceSecs);
|
|
3269
|
-
app.use("/api/model/*", sigMiddleware);
|
|
3270
|
-
app.use("/api/schema", sigMiddleware);
|
|
3271
|
-
}
|
|
3272
|
-
app.use("/api/model/*", (0, _zenstackhq_server_hono.createHonoHandler)({
|
|
3273
|
-
apiHandler: new _zenstackhq_server_api.RPCApiHandler({ schema: options.schema }),
|
|
3274
|
-
getClient: (c) => resolveClient(options.client, options.authDb ?? options.client, c, !!options.auth?.studioAuthKey)
|
|
3275
|
-
}));
|
|
3276
|
-
app.get("/api/schema", (c) => {
|
|
3277
|
-
return c.json({
|
|
3278
|
-
...options.schema,
|
|
3279
|
-
zenstackVersion: getVersion()
|
|
3280
|
-
});
|
|
3281
|
-
});
|
|
3282
|
-
return app;
|
|
3283
|
-
}
|
|
3284
|
-
function createSignatureMiddleware(publicKey, toleranceSeconds) {
|
|
3285
|
-
let lastInvalidSigWarnAt = 0;
|
|
3286
|
-
const WARN_THROTTLE_SECS = 60;
|
|
3287
|
-
function warnInvalidSignature() {
|
|
3288
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
3289
|
-
if (now - lastInvalidSigWarnAt >= WARN_THROTTLE_SECS) {
|
|
3290
|
-
lastInvalidSigWarnAt = now;
|
|
3291
|
-
console.warn(colors.default.yellow("Warning: Received a request with an invalid signature. Please double-check whether you have the correct public API key configured."));
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
return async (c, next) => {
|
|
3295
|
-
const signatureHeader = c.req.header("x-zenstack-signature");
|
|
3296
|
-
if (!signatureHeader) return rejectAuth(c, "MISSING_SIGNATURE_HEADER");
|
|
3297
|
-
const parts = signatureHeader.split(",");
|
|
3298
|
-
const timestampPart = parts.find((p) => p.startsWith("t="));
|
|
3299
|
-
const sigPart = parts.find((p) => p.startsWith("v1="));
|
|
3300
|
-
if (!timestampPart || !sigPart) return rejectAuth(c, "INVALID_SIGNATURE_FORMAT");
|
|
3301
|
-
const timestamp = timestampPart.substring(2);
|
|
3302
|
-
const sig = sigPart.substring(3);
|
|
3303
|
-
const requestTime = parseInt(timestamp, 10);
|
|
3304
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
3305
|
-
if (isNaN(requestTime) || Math.abs(now - requestTime) > toleranceSeconds) return rejectAuth(c, "INVALID_TIMESTAMP");
|
|
3306
|
-
let payload;
|
|
3307
|
-
if (c.req.method === "GET" || c.req.method === "DELETE") {
|
|
3308
|
-
const rawUrl = c.req.url;
|
|
3309
|
-
const qMark = rawUrl.indexOf("?");
|
|
3310
|
-
payload = qMark >= 0 ? rawUrl.substring(qMark + 1) : "";
|
|
3311
|
-
} else payload = await c.req.text();
|
|
3312
|
-
const authHeader = c.req.header("authorization");
|
|
3313
|
-
const authorizationToken = authHeader && authHeader.startsWith("Bearer ") ? authHeader.substring(7) : void 0;
|
|
3314
|
-
const message = authorizationToken ? `${payload}${timestamp}${authorizationToken}` : `${payload}${timestamp}`;
|
|
3315
|
-
try {
|
|
3316
|
-
if (!(0, node_crypto.verify)(null, Buffer.from(message, "utf8"), publicKey, Buffer.from(sig, "base64url"))) {
|
|
3317
|
-
warnInvalidSignature();
|
|
3318
|
-
return rejectAuth(c, "INVALID_SIGNATURE_FORMAT");
|
|
3319
|
-
}
|
|
3320
|
-
} catch {
|
|
3321
|
-
warnInvalidSignature();
|
|
3322
|
-
return rejectAuth(c, "INVALID_SIGNATURE_FORMAT");
|
|
3323
|
-
}
|
|
3324
|
-
return next();
|
|
3325
|
-
};
|
|
3326
|
-
}
|
|
3327
|
-
function resolveClient(client, authDb, c, isAuthKeyEnabled) {
|
|
3328
|
-
const authHeader = c.req.header("authorization");
|
|
3329
|
-
if (!isAuthKeyEnabled && !authHeader) return client;
|
|
3330
|
-
if (!authHeader?.startsWith("Bearer ")) return authDb;
|
|
3331
|
-
const token = authHeader.substring(7);
|
|
3332
|
-
let claim;
|
|
3333
|
-
try {
|
|
3334
|
-
claim = UserClaimSchema.parse(JSON.parse(Buffer.from(token, "base64").toString("utf8")));
|
|
3335
|
-
} catch (err) {
|
|
3336
|
-
console.error(colors.default.red(`Failed to parse user claim from token: ${err instanceof Error ? err.message : String(err)}`));
|
|
3337
|
-
return authDb;
|
|
3338
|
-
}
|
|
3339
|
-
if (claim.type === "superUser") return client;
|
|
3340
|
-
else return authDb.$setAuth(claim.data);
|
|
3341
|
-
}
|
|
3342
3161
|
function startServer(client, schema, options, authDb) {
|
|
3343
3162
|
const server = (0, _hono_node_server.serve)({
|
|
3344
|
-
fetch: createProxyApp({
|
|
3163
|
+
fetch: require_proxy.createProxyApp({
|
|
3345
3164
|
client,
|
|
3346
3165
|
schema,
|
|
3347
3166
|
authDb,
|
|
@@ -3593,7 +3412,7 @@ var Telemetry = class {
|
|
|
3593
3412
|
_os_arch = os.arch();
|
|
3594
3413
|
_os_version = os.version();
|
|
3595
3414
|
_os_platform = os.platform();
|
|
3596
|
-
version = getVersion();
|
|
3415
|
+
version = require_proxy.getVersion();
|
|
3597
3416
|
prismaVersion = this.getPrismaVersion();
|
|
3598
3417
|
isDocker = isDocker();
|
|
3599
3418
|
isWsl = isWsl();
|
|
@@ -3709,7 +3528,7 @@ function triStateBooleanOption(flag, description) {
|
|
|
3709
3528
|
});
|
|
3710
3529
|
}
|
|
3711
3530
|
function createProgram() {
|
|
3712
|
-
const program = new commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
|
|
3531
|
+
const program = new commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(require_proxy.getVersion(), "-v --version", "Show CLI version");
|
|
3713
3532
|
const schemaExtensions = _zenstackhq_language.ZModelLanguageMetaData.fileExtensions.join(", ");
|
|
3714
3533
|
program.description(`${colors.default.bold.blue("ζ")} ZenStack is the modern data layer for TypeScript apps.\n\nDocumentation: https://zenstack.dev/docs`).showHelpAfterError().showSuggestionAfterError();
|
|
3715
3534
|
const schemaOption = new commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
|
|
@@ -3748,7 +3567,7 @@ Arguments following -- are passed to the seed script. E.g.: "zen db seed -- --us
|
|
|
3748
3567
|
})).addOption(new commander.Option("--introspect", "Introspect the database to generate a schema when no schema file is found")).addOption(noVersionCheckOption).action(proxyAction);
|
|
3749
3568
|
program.addHelpCommand("help [command]", "Display help for a command");
|
|
3750
3569
|
program.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
3751
|
-
if (actionCommand.getOptionValue("versionCheck") !== false) await checkNewVersion();
|
|
3570
|
+
if (actionCommand.getOptionValue("versionCheck") !== false) await require_proxy.checkNewVersion();
|
|
3752
3571
|
});
|
|
3753
3572
|
return program;
|
|
3754
3573
|
}
|