@auth-gate/rbac 0.9.0 → 0.9.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/{chunk-ZFKXT2MP.mjs → chunk-5CSBBETH.mjs} +6 -2
- package/dist/cli.cjs +120 -16
- package/dist/cli.mjs +117 -15
- package/dist/index.cjs +10 -2
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +5 -1
- package/package.json +4 -2
|
@@ -273,7 +273,6 @@ var CONFIG_FILENAMES = [
|
|
|
273
273
|
"authgate.rbac.mjs"
|
|
274
274
|
];
|
|
275
275
|
async function loadRbacConfig(cwd) {
|
|
276
|
-
var _a, _b;
|
|
277
276
|
let configPath = null;
|
|
278
277
|
for (const filename of CONFIG_FILENAMES) {
|
|
279
278
|
const candidate = resolve(cwd, filename);
|
|
@@ -288,8 +287,12 @@ async function loadRbacConfig(cwd) {
|
|
|
288
287
|
Run \`npx @auth-gate/rbac init\` to create one.`
|
|
289
288
|
);
|
|
290
289
|
}
|
|
290
|
+
return loadRbacConfigFromPath(configPath, cwd);
|
|
291
|
+
}
|
|
292
|
+
async function loadRbacConfigFromPath(configPath, cwd) {
|
|
293
|
+
var _a, _b;
|
|
291
294
|
const { createJiti } = await import("jiti");
|
|
292
|
-
const jiti = createJiti(cwd, { interopDefault: true });
|
|
295
|
+
const jiti = createJiti(cwd != null ? cwd : process.cwd(), { interopDefault: true });
|
|
293
296
|
const mod = await jiti.import(configPath);
|
|
294
297
|
const raw = (_b = (_a = mod.default) != null ? _a : mod.rbac) != null ? _b : mod;
|
|
295
298
|
const config = raw && typeof raw === "object" && "_config" in raw ? raw._config : raw;
|
|
@@ -649,6 +652,7 @@ export {
|
|
|
649
652
|
__spreadValues,
|
|
650
653
|
validateRbacConfig,
|
|
651
654
|
loadRbacConfig,
|
|
655
|
+
loadRbacConfigFromPath,
|
|
652
656
|
hashConditionSource,
|
|
653
657
|
computeRbacDiff,
|
|
654
658
|
formatRbacDiff,
|
package/dist/cli.cjs
CHANGED
|
@@ -291,7 +291,6 @@ var CONFIG_FILENAMES = [
|
|
|
291
291
|
"authgate.rbac.mjs"
|
|
292
292
|
];
|
|
293
293
|
async function loadRbacConfig(cwd) {
|
|
294
|
-
var _a, _b;
|
|
295
294
|
let configPath = null;
|
|
296
295
|
for (const filename of CONFIG_FILENAMES) {
|
|
297
296
|
const candidate = (0, import_path.resolve)(cwd, filename);
|
|
@@ -306,8 +305,12 @@ async function loadRbacConfig(cwd) {
|
|
|
306
305
|
Run \`npx @auth-gate/rbac init\` to create one.`
|
|
307
306
|
);
|
|
308
307
|
}
|
|
308
|
+
return loadRbacConfigFromPath(configPath, cwd);
|
|
309
|
+
}
|
|
310
|
+
async function loadRbacConfigFromPath(configPath, cwd) {
|
|
311
|
+
var _a, _b;
|
|
309
312
|
const { createJiti } = await import("jiti");
|
|
310
|
-
const jiti = createJiti(cwd, { interopDefault: true });
|
|
313
|
+
const jiti = createJiti(cwd != null ? cwd : process.cwd(), { interopDefault: true });
|
|
311
314
|
const mod = await jiti.import(configPath);
|
|
312
315
|
const raw = (_b = (_a = mod.default) != null ? _a : mod.rbac) != null ? _b : mod;
|
|
313
316
|
const config = raw && typeof raw === "object" && "_config" in raw ? raw._config : raw;
|
|
@@ -663,10 +666,76 @@ var RbacSyncClient = class {
|
|
|
663
666
|
}
|
|
664
667
|
};
|
|
665
668
|
|
|
669
|
+
// src/project-config-loader.ts
|
|
670
|
+
var import_path2 = require("path");
|
|
671
|
+
var import_fs2 = require("fs");
|
|
672
|
+
var CONFIG_FILENAMES2 = [
|
|
673
|
+
"authgate.config.ts",
|
|
674
|
+
"authgate.config.js",
|
|
675
|
+
"authgate.config.mjs"
|
|
676
|
+
];
|
|
677
|
+
var AUTO_ENV_FILES = [".env", ".env.local"];
|
|
678
|
+
async function resolveProjectConfig(cwd) {
|
|
679
|
+
var _a, _b, _c;
|
|
680
|
+
await autoLoadEnvFiles(cwd);
|
|
681
|
+
const config = await loadProjectConfigFile(cwd);
|
|
682
|
+
if (!config) {
|
|
683
|
+
return {
|
|
684
|
+
connection: {
|
|
685
|
+
baseUrl: process.env.AUTHGATE_BASE_URL,
|
|
686
|
+
apiKey: process.env.AUTHGATE_API_KEY
|
|
687
|
+
},
|
|
688
|
+
rbacConfigPath: null,
|
|
689
|
+
billingConfigPath: null
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
const rawConnection = (_a = config.connection) != null ? _a : {};
|
|
693
|
+
const connection = {
|
|
694
|
+
baseUrl: (_b = rawConnection.baseUrl) != null ? _b : process.env.AUTHGATE_BASE_URL,
|
|
695
|
+
apiKey: (_c = rawConnection.apiKey) != null ? _c : process.env.AUTHGATE_API_KEY
|
|
696
|
+
};
|
|
697
|
+
return {
|
|
698
|
+
connection,
|
|
699
|
+
rbacConfigPath: config.rbacConfig ? (0, import_path2.resolve)(cwd, config.rbacConfig) : null,
|
|
700
|
+
billingConfigPath: config.billingConfig ? (0, import_path2.resolve)(cwd, config.billingConfig) : null
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
async function loadProjectConfigFile(cwd) {
|
|
704
|
+
var _a;
|
|
705
|
+
let configPath = null;
|
|
706
|
+
for (const filename of CONFIG_FILENAMES2) {
|
|
707
|
+
const candidate = (0, import_path2.resolve)(cwd, filename);
|
|
708
|
+
if ((0, import_fs2.existsSync)(candidate)) {
|
|
709
|
+
configPath = candidate;
|
|
710
|
+
break;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (!configPath) return null;
|
|
714
|
+
const { createJiti } = await import("jiti");
|
|
715
|
+
const jiti = createJiti(cwd, { interopDefault: true });
|
|
716
|
+
const mod = await jiti.import(configPath);
|
|
717
|
+
const config = (_a = mod.default) != null ? _a : mod;
|
|
718
|
+
return config;
|
|
719
|
+
}
|
|
720
|
+
async function autoLoadEnvFiles(cwd) {
|
|
721
|
+
let dotenv;
|
|
722
|
+
try {
|
|
723
|
+
dotenv = await import("dotenv");
|
|
724
|
+
} catch (e) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
for (const file of AUTO_ENV_FILES) {
|
|
728
|
+
const filePath = (0, import_path2.resolve)(cwd, file);
|
|
729
|
+
if ((0, import_fs2.existsSync)(filePath)) {
|
|
730
|
+
dotenv.config({ path: filePath });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
666
735
|
// src/cli.ts
|
|
667
736
|
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
668
|
-
var
|
|
669
|
-
var
|
|
737
|
+
var import_fs3 = require("fs");
|
|
738
|
+
var import_path3 = require("path");
|
|
670
739
|
var HELP = `
|
|
671
740
|
Usage: @auth-gate/rbac <command> [options]
|
|
672
741
|
|
|
@@ -681,7 +750,14 @@ Options (sync):
|
|
|
681
750
|
--strict Treat warnings as errors (recommended for CI/CD)
|
|
682
751
|
--json Output diff as JSON
|
|
683
752
|
|
|
684
|
-
|
|
753
|
+
Options (init):
|
|
754
|
+
--config Generate a starter authgate.config.ts instead
|
|
755
|
+
|
|
756
|
+
Config file:
|
|
757
|
+
If authgate.config.ts exists, env vars and connection details are
|
|
758
|
+
loaded from it automatically. See defineConfig() for the API.
|
|
759
|
+
|
|
760
|
+
Environment (when no authgate.config.ts):
|
|
685
761
|
AUTHGATE_API_KEY Your project API key (required for sync)
|
|
686
762
|
AUTHGATE_BASE_URL AuthGate instance URL (required for sync)
|
|
687
763
|
`;
|
|
@@ -693,7 +769,8 @@ async function main() {
|
|
|
693
769
|
process.exit(0);
|
|
694
770
|
}
|
|
695
771
|
if (command === "init") {
|
|
696
|
-
|
|
772
|
+
const configFlag = args.includes("--config");
|
|
773
|
+
await runInit({ config: configFlag });
|
|
697
774
|
return;
|
|
698
775
|
}
|
|
699
776
|
if (command === "check") {
|
|
@@ -712,9 +789,29 @@ async function main() {
|
|
|
712
789
|
console.log(HELP);
|
|
713
790
|
process.exit(1);
|
|
714
791
|
}
|
|
715
|
-
async function runInit() {
|
|
716
|
-
|
|
717
|
-
|
|
792
|
+
async function runInit(opts) {
|
|
793
|
+
if (opts.config) {
|
|
794
|
+
const configPath2 = (0, import_path3.resolve)(process.cwd(), "authgate.config.ts");
|
|
795
|
+
if ((0, import_fs3.existsSync)(configPath2)) {
|
|
796
|
+
console.error(import_chalk2.default.yellow(`Config file already exists: ${configPath2}`));
|
|
797
|
+
process.exit(1);
|
|
798
|
+
}
|
|
799
|
+
const template2 = `import { defineConfig } from "@auth-gate/core";
|
|
800
|
+
|
|
801
|
+
export default defineConfig({
|
|
802
|
+
connection: {
|
|
803
|
+
baseUrl: process.env.AUTHGATE_URL,
|
|
804
|
+
apiKey: process.env.AUTHGATE_API_KEY,
|
|
805
|
+
},
|
|
806
|
+
});
|
|
807
|
+
`;
|
|
808
|
+
(0, import_fs3.writeFileSync)(configPath2, template2, "utf-8");
|
|
809
|
+
console.log(import_chalk2.default.green(`Created ${configPath2}`));
|
|
810
|
+
console.log(import_chalk2.default.dim("Edit connection details, then run: npx @auth-gate/rbac sync"));
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
const configPath = (0, import_path3.resolve)(process.cwd(), "authgate.rbac.ts");
|
|
814
|
+
if ((0, import_fs3.existsSync)(configPath)) {
|
|
718
815
|
console.error(import_chalk2.default.yellow(`Config file already exists: ${configPath}`));
|
|
719
816
|
process.exit(1);
|
|
720
817
|
}
|
|
@@ -760,14 +857,16 @@ export const rbac = defineRbac({
|
|
|
760
857
|
// Default export for CLI compatibility
|
|
761
858
|
export default rbac;
|
|
762
859
|
`;
|
|
763
|
-
(0,
|
|
860
|
+
(0, import_fs3.writeFileSync)(configPath, template, "utf-8");
|
|
764
861
|
console.log(import_chalk2.default.green(`Created ${configPath}`));
|
|
765
862
|
console.log(import_chalk2.default.dim("Edit your resources and roles, then run: npx @auth-gate/rbac sync"));
|
|
766
863
|
}
|
|
767
864
|
async function runCheck() {
|
|
865
|
+
const cwd = process.cwd();
|
|
866
|
+
const projectConfig = await resolveProjectConfig(cwd);
|
|
768
867
|
let config;
|
|
769
868
|
try {
|
|
770
|
-
config = await
|
|
869
|
+
config = projectConfig.rbacConfigPath ? await loadRbacConfigFromPath(projectConfig.rbacConfigPath, cwd) : await loadRbacConfig(cwd);
|
|
771
870
|
} catch (err) {
|
|
772
871
|
console.error(import_chalk2.default.red(`Config error: ${err.message}`));
|
|
773
872
|
process.exit(1);
|
|
@@ -782,19 +881,24 @@ async function runCheck() {
|
|
|
782
881
|
console.log(import_chalk2.default.dim(`${resourceCount} resource${resourceCount > 1 ? "s" : ""}, ${roleCount} role${roleCount > 1 ? "s" : ""}, ${permCount} permission${permCount > 1 ? "s" : ""}`));
|
|
783
882
|
}
|
|
784
883
|
async function runSync(opts) {
|
|
785
|
-
const
|
|
786
|
-
const
|
|
884
|
+
const cwd = process.cwd();
|
|
885
|
+
const projectConfig = await resolveProjectConfig(cwd);
|
|
886
|
+
const { baseUrl, apiKey } = projectConfig.connection;
|
|
787
887
|
if (!apiKey) {
|
|
788
|
-
console.error(import_chalk2.default.red(
|
|
888
|
+
console.error(import_chalk2.default.red(
|
|
889
|
+
"Missing API key. Set AUTHGATE_API_KEY or configure connection in authgate.config.ts."
|
|
890
|
+
));
|
|
789
891
|
process.exit(1);
|
|
790
892
|
}
|
|
791
893
|
if (!baseUrl) {
|
|
792
|
-
console.error(import_chalk2.default.red(
|
|
894
|
+
console.error(import_chalk2.default.red(
|
|
895
|
+
"Missing base URL. Set AUTHGATE_BASE_URL or configure connection in authgate.config.ts."
|
|
896
|
+
));
|
|
793
897
|
process.exit(1);
|
|
794
898
|
}
|
|
795
899
|
let config;
|
|
796
900
|
try {
|
|
797
|
-
config = await
|
|
901
|
+
config = projectConfig.rbacConfigPath ? await loadRbacConfigFromPath(projectConfig.rbacConfigPath, cwd) : await loadRbacConfig(cwd);
|
|
798
902
|
} catch (err) {
|
|
799
903
|
console.error(import_chalk2.default.red(`Config error: ${err.message}`));
|
|
800
904
|
process.exit(1);
|
package/dist/cli.mjs
CHANGED
|
@@ -4,13 +4,80 @@ import {
|
|
|
4
4
|
__spreadValues,
|
|
5
5
|
computeRbacDiff,
|
|
6
6
|
formatRbacDiff,
|
|
7
|
-
loadRbacConfig
|
|
8
|
-
|
|
7
|
+
loadRbacConfig,
|
|
8
|
+
loadRbacConfigFromPath
|
|
9
|
+
} from "./chunk-5CSBBETH.mjs";
|
|
10
|
+
|
|
11
|
+
// src/project-config-loader.ts
|
|
12
|
+
import { resolve } from "path";
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
var CONFIG_FILENAMES = [
|
|
15
|
+
"authgate.config.ts",
|
|
16
|
+
"authgate.config.js",
|
|
17
|
+
"authgate.config.mjs"
|
|
18
|
+
];
|
|
19
|
+
var AUTO_ENV_FILES = [".env", ".env.local"];
|
|
20
|
+
async function resolveProjectConfig(cwd) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
await autoLoadEnvFiles(cwd);
|
|
23
|
+
const config = await loadProjectConfigFile(cwd);
|
|
24
|
+
if (!config) {
|
|
25
|
+
return {
|
|
26
|
+
connection: {
|
|
27
|
+
baseUrl: process.env.AUTHGATE_BASE_URL,
|
|
28
|
+
apiKey: process.env.AUTHGATE_API_KEY
|
|
29
|
+
},
|
|
30
|
+
rbacConfigPath: null,
|
|
31
|
+
billingConfigPath: null
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const rawConnection = (_a = config.connection) != null ? _a : {};
|
|
35
|
+
const connection = {
|
|
36
|
+
baseUrl: (_b = rawConnection.baseUrl) != null ? _b : process.env.AUTHGATE_BASE_URL,
|
|
37
|
+
apiKey: (_c = rawConnection.apiKey) != null ? _c : process.env.AUTHGATE_API_KEY
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
connection,
|
|
41
|
+
rbacConfigPath: config.rbacConfig ? resolve(cwd, config.rbacConfig) : null,
|
|
42
|
+
billingConfigPath: config.billingConfig ? resolve(cwd, config.billingConfig) : null
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function loadProjectConfigFile(cwd) {
|
|
46
|
+
var _a;
|
|
47
|
+
let configPath = null;
|
|
48
|
+
for (const filename of CONFIG_FILENAMES) {
|
|
49
|
+
const candidate = resolve(cwd, filename);
|
|
50
|
+
if (existsSync(candidate)) {
|
|
51
|
+
configPath = candidate;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!configPath) return null;
|
|
56
|
+
const { createJiti } = await import("jiti");
|
|
57
|
+
const jiti = createJiti(cwd, { interopDefault: true });
|
|
58
|
+
const mod = await jiti.import(configPath);
|
|
59
|
+
const config = (_a = mod.default) != null ? _a : mod;
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
async function autoLoadEnvFiles(cwd) {
|
|
63
|
+
let dotenv;
|
|
64
|
+
try {
|
|
65
|
+
dotenv = await import("dotenv");
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const file of AUTO_ENV_FILES) {
|
|
70
|
+
const filePath = resolve(cwd, file);
|
|
71
|
+
if (existsSync(filePath)) {
|
|
72
|
+
dotenv.config({ path: filePath });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
9
76
|
|
|
10
77
|
// src/cli.ts
|
|
11
78
|
import chalk from "chalk";
|
|
12
|
-
import { writeFileSync, existsSync } from "fs";
|
|
13
|
-
import { resolve } from "path";
|
|
79
|
+
import { writeFileSync, existsSync as existsSync2 } from "fs";
|
|
80
|
+
import { resolve as resolve2 } from "path";
|
|
14
81
|
var HELP = `
|
|
15
82
|
Usage: @auth-gate/rbac <command> [options]
|
|
16
83
|
|
|
@@ -25,7 +92,14 @@ Options (sync):
|
|
|
25
92
|
--strict Treat warnings as errors (recommended for CI/CD)
|
|
26
93
|
--json Output diff as JSON
|
|
27
94
|
|
|
28
|
-
|
|
95
|
+
Options (init):
|
|
96
|
+
--config Generate a starter authgate.config.ts instead
|
|
97
|
+
|
|
98
|
+
Config file:
|
|
99
|
+
If authgate.config.ts exists, env vars and connection details are
|
|
100
|
+
loaded from it automatically. See defineConfig() for the API.
|
|
101
|
+
|
|
102
|
+
Environment (when no authgate.config.ts):
|
|
29
103
|
AUTHGATE_API_KEY Your project API key (required for sync)
|
|
30
104
|
AUTHGATE_BASE_URL AuthGate instance URL (required for sync)
|
|
31
105
|
`;
|
|
@@ -37,7 +111,8 @@ async function main() {
|
|
|
37
111
|
process.exit(0);
|
|
38
112
|
}
|
|
39
113
|
if (command === "init") {
|
|
40
|
-
|
|
114
|
+
const configFlag = args.includes("--config");
|
|
115
|
+
await runInit({ config: configFlag });
|
|
41
116
|
return;
|
|
42
117
|
}
|
|
43
118
|
if (command === "check") {
|
|
@@ -56,9 +131,29 @@ async function main() {
|
|
|
56
131
|
console.log(HELP);
|
|
57
132
|
process.exit(1);
|
|
58
133
|
}
|
|
59
|
-
async function runInit() {
|
|
60
|
-
|
|
61
|
-
|
|
134
|
+
async function runInit(opts) {
|
|
135
|
+
if (opts.config) {
|
|
136
|
+
const configPath2 = resolve2(process.cwd(), "authgate.config.ts");
|
|
137
|
+
if (existsSync2(configPath2)) {
|
|
138
|
+
console.error(chalk.yellow(`Config file already exists: ${configPath2}`));
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
const template2 = `import { defineConfig } from "@auth-gate/core";
|
|
142
|
+
|
|
143
|
+
export default defineConfig({
|
|
144
|
+
connection: {
|
|
145
|
+
baseUrl: process.env.AUTHGATE_URL,
|
|
146
|
+
apiKey: process.env.AUTHGATE_API_KEY,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
`;
|
|
150
|
+
writeFileSync(configPath2, template2, "utf-8");
|
|
151
|
+
console.log(chalk.green(`Created ${configPath2}`));
|
|
152
|
+
console.log(chalk.dim("Edit connection details, then run: npx @auth-gate/rbac sync"));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const configPath = resolve2(process.cwd(), "authgate.rbac.ts");
|
|
156
|
+
if (existsSync2(configPath)) {
|
|
62
157
|
console.error(chalk.yellow(`Config file already exists: ${configPath}`));
|
|
63
158
|
process.exit(1);
|
|
64
159
|
}
|
|
@@ -109,9 +204,11 @@ export default rbac;
|
|
|
109
204
|
console.log(chalk.dim("Edit your resources and roles, then run: npx @auth-gate/rbac sync"));
|
|
110
205
|
}
|
|
111
206
|
async function runCheck() {
|
|
207
|
+
const cwd = process.cwd();
|
|
208
|
+
const projectConfig = await resolveProjectConfig(cwd);
|
|
112
209
|
let config;
|
|
113
210
|
try {
|
|
114
|
-
config = await
|
|
211
|
+
config = projectConfig.rbacConfigPath ? await loadRbacConfigFromPath(projectConfig.rbacConfigPath, cwd) : await loadRbacConfig(cwd);
|
|
115
212
|
} catch (err) {
|
|
116
213
|
console.error(chalk.red(`Config error: ${err.message}`));
|
|
117
214
|
process.exit(1);
|
|
@@ -126,19 +223,24 @@ async function runCheck() {
|
|
|
126
223
|
console.log(chalk.dim(`${resourceCount} resource${resourceCount > 1 ? "s" : ""}, ${roleCount} role${roleCount > 1 ? "s" : ""}, ${permCount} permission${permCount > 1 ? "s" : ""}`));
|
|
127
224
|
}
|
|
128
225
|
async function runSync(opts) {
|
|
129
|
-
const
|
|
130
|
-
const
|
|
226
|
+
const cwd = process.cwd();
|
|
227
|
+
const projectConfig = await resolveProjectConfig(cwd);
|
|
228
|
+
const { baseUrl, apiKey } = projectConfig.connection;
|
|
131
229
|
if (!apiKey) {
|
|
132
|
-
console.error(chalk.red(
|
|
230
|
+
console.error(chalk.red(
|
|
231
|
+
"Missing API key. Set AUTHGATE_API_KEY or configure connection in authgate.config.ts."
|
|
232
|
+
));
|
|
133
233
|
process.exit(1);
|
|
134
234
|
}
|
|
135
235
|
if (!baseUrl) {
|
|
136
|
-
console.error(chalk.red(
|
|
236
|
+
console.error(chalk.red(
|
|
237
|
+
"Missing base URL. Set AUTHGATE_BASE_URL or configure connection in authgate.config.ts."
|
|
238
|
+
));
|
|
137
239
|
process.exit(1);
|
|
138
240
|
}
|
|
139
241
|
let config;
|
|
140
242
|
try {
|
|
141
|
-
config = await
|
|
243
|
+
config = projectConfig.rbacConfigPath ? await loadRbacConfigFromPath(projectConfig.rbacConfigPath, cwd) : await loadRbacConfig(cwd);
|
|
142
244
|
} catch (err) {
|
|
143
245
|
console.error(chalk.red(`Config error: ${err.message}`));
|
|
144
246
|
process.exit(1);
|
package/dist/index.cjs
CHANGED
|
@@ -33,10 +33,12 @@ __export(index_exports, {
|
|
|
33
33
|
RbacSyncClient: () => RbacSyncClient,
|
|
34
34
|
computeRbacDiff: () => computeRbacDiff,
|
|
35
35
|
createRoleManagement: () => createRoleManagement,
|
|
36
|
+
defineConfig: () => import_core.defineConfig,
|
|
36
37
|
defineRbac: () => defineRbac,
|
|
37
38
|
formatRbacDiff: () => formatRbacDiff,
|
|
38
39
|
hashConditionSource: () => hashConditionSource,
|
|
39
40
|
loadRbacConfig: () => loadRbacConfig,
|
|
41
|
+
loadRbacConfigFromPath: () => loadRbacConfigFromPath,
|
|
40
42
|
validateRbacConfig: () => validateRbacConfig
|
|
41
43
|
});
|
|
42
44
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -293,7 +295,6 @@ var CONFIG_FILENAMES = [
|
|
|
293
295
|
"authgate.rbac.mjs"
|
|
294
296
|
];
|
|
295
297
|
async function loadRbacConfig(cwd) {
|
|
296
|
-
var _a, _b;
|
|
297
298
|
let configPath = null;
|
|
298
299
|
for (const filename of CONFIG_FILENAMES) {
|
|
299
300
|
const candidate = (0, import_path.resolve)(cwd, filename);
|
|
@@ -308,8 +309,12 @@ async function loadRbacConfig(cwd) {
|
|
|
308
309
|
Run \`npx @auth-gate/rbac init\` to create one.`
|
|
309
310
|
);
|
|
310
311
|
}
|
|
312
|
+
return loadRbacConfigFromPath(configPath, cwd);
|
|
313
|
+
}
|
|
314
|
+
async function loadRbacConfigFromPath(configPath, cwd) {
|
|
315
|
+
var _a, _b;
|
|
311
316
|
const { createJiti } = await import("jiti");
|
|
312
|
-
const jiti = createJiti(cwd, { interopDefault: true });
|
|
317
|
+
const jiti = createJiti(cwd != null ? cwd : process.cwd(), { interopDefault: true });
|
|
313
318
|
const mod = await jiti.import(configPath);
|
|
314
319
|
const raw = (_b = (_a = mod.default) != null ? _a : mod.rbac) != null ? _b : mod;
|
|
315
320
|
const config = raw && typeof raw === "object" && "_config" in raw ? raw._config : raw;
|
|
@@ -752,6 +757,7 @@ function toRole(raw) {
|
|
|
752
757
|
}
|
|
753
758
|
|
|
754
759
|
// src/index.ts
|
|
760
|
+
var import_core = require("@auth-gate/core");
|
|
755
761
|
function defineRbac(config, opts) {
|
|
756
762
|
var _a;
|
|
757
763
|
if ((opts == null ? void 0 : opts.validate) !== false) {
|
|
@@ -791,9 +797,11 @@ function defineRbac(config, opts) {
|
|
|
791
797
|
RbacSyncClient,
|
|
792
798
|
computeRbacDiff,
|
|
793
799
|
createRoleManagement,
|
|
800
|
+
defineConfig,
|
|
794
801
|
defineRbac,
|
|
795
802
|
formatRbacDiff,
|
|
796
803
|
hashConditionSource,
|
|
797
804
|
loadRbacConfig,
|
|
805
|
+
loadRbacConfigFromPath,
|
|
798
806
|
validateRbacConfig
|
|
799
807
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { AuthGateConnection, AuthGateProjectConfig, defineConfig } from '@auth-gate/core';
|
|
2
|
+
|
|
1
3
|
/** A resource definition: declares available actions and optional scopes. */
|
|
2
4
|
interface ResourceConfig {
|
|
3
5
|
actions: readonly string[];
|
|
@@ -219,6 +221,11 @@ type ResourceKey<A> = A extends TypedRbac<infer T> ? InferResourceKeys<T> : stri
|
|
|
219
221
|
declare function validateRbacConfig(config: unknown): RbacConfig;
|
|
220
222
|
|
|
221
223
|
declare function loadRbacConfig(cwd: string): Promise<RbacConfig>;
|
|
224
|
+
/**
|
|
225
|
+
* Load RBAC config from a specific file path.
|
|
226
|
+
* Used when `authgate.config.ts` specifies `rbacConfig`.
|
|
227
|
+
*/
|
|
228
|
+
declare function loadRbacConfigFromPath(configPath: string, cwd?: string): Promise<RbacConfig>;
|
|
222
229
|
|
|
223
230
|
interface ServerResource {
|
|
224
231
|
id: string;
|
|
@@ -428,4 +435,4 @@ declare function defineRbac<const T extends DefineRbacConfig>(config: T & Valida
|
|
|
428
435
|
validate?: boolean;
|
|
429
436
|
}): TypedRbac<T>;
|
|
430
437
|
|
|
431
|
-
export { type ApplyResult, type ConditionContext, type ConditionFn, type ConditionOp, type CreateRoleInput, type DiffResult, type GrantValue, type InferActions, type InferConditionKeys, type InferPermissions, type InferResourceKeys, type InferRoleKeys, type InferScopes, type Permission, type RbacConfig, RbacSyncClient, type RbacSyncClientConfig, type ResourceConfig, type ResourceKey, type ResourceOp, type Role, type RoleConfig, type RoleKey, type RoleManagementClient, type RoleManagementConfig, type RoleOp, type ServerCondition, type ServerResource, type ServerRole, type ServerState, type TypedRbac, type UpdateRoleInput, computeRbacDiff, createRoleManagement, defineRbac, formatRbacDiff, hashConditionSource, loadRbacConfig, validateRbacConfig };
|
|
438
|
+
export { type ApplyResult, type ConditionContext, type ConditionFn, type ConditionOp, type CreateRoleInput, type DiffResult, type GrantValue, type InferActions, type InferConditionKeys, type InferPermissions, type InferResourceKeys, type InferRoleKeys, type InferScopes, type Permission, type RbacConfig, RbacSyncClient, type RbacSyncClientConfig, type ResourceConfig, type ResourceKey, type ResourceOp, type Role, type RoleConfig, type RoleKey, type RoleManagementClient, type RoleManagementConfig, type RoleOp, type ServerCondition, type ServerResource, type ServerRole, type ServerState, type TypedRbac, type UpdateRoleInput, computeRbacDiff, createRoleManagement, defineRbac, formatRbacDiff, hashConditionSource, loadRbacConfig, loadRbacConfigFromPath, validateRbacConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { AuthGateConnection, AuthGateProjectConfig, defineConfig } from '@auth-gate/core';
|
|
2
|
+
|
|
1
3
|
/** A resource definition: declares available actions and optional scopes. */
|
|
2
4
|
interface ResourceConfig {
|
|
3
5
|
actions: readonly string[];
|
|
@@ -219,6 +221,11 @@ type ResourceKey<A> = A extends TypedRbac<infer T> ? InferResourceKeys<T> : stri
|
|
|
219
221
|
declare function validateRbacConfig(config: unknown): RbacConfig;
|
|
220
222
|
|
|
221
223
|
declare function loadRbacConfig(cwd: string): Promise<RbacConfig>;
|
|
224
|
+
/**
|
|
225
|
+
* Load RBAC config from a specific file path.
|
|
226
|
+
* Used when `authgate.config.ts` specifies `rbacConfig`.
|
|
227
|
+
*/
|
|
228
|
+
declare function loadRbacConfigFromPath(configPath: string, cwd?: string): Promise<RbacConfig>;
|
|
222
229
|
|
|
223
230
|
interface ServerResource {
|
|
224
231
|
id: string;
|
|
@@ -428,4 +435,4 @@ declare function defineRbac<const T extends DefineRbacConfig>(config: T & Valida
|
|
|
428
435
|
validate?: boolean;
|
|
429
436
|
}): TypedRbac<T>;
|
|
430
437
|
|
|
431
|
-
export { type ApplyResult, type ConditionContext, type ConditionFn, type ConditionOp, type CreateRoleInput, type DiffResult, type GrantValue, type InferActions, type InferConditionKeys, type InferPermissions, type InferResourceKeys, type InferRoleKeys, type InferScopes, type Permission, type RbacConfig, RbacSyncClient, type RbacSyncClientConfig, type ResourceConfig, type ResourceKey, type ResourceOp, type Role, type RoleConfig, type RoleKey, type RoleManagementClient, type RoleManagementConfig, type RoleOp, type ServerCondition, type ServerResource, type ServerRole, type ServerState, type TypedRbac, type UpdateRoleInput, computeRbacDiff, createRoleManagement, defineRbac, formatRbacDiff, hashConditionSource, loadRbacConfig, validateRbacConfig };
|
|
438
|
+
export { type ApplyResult, type ConditionContext, type ConditionFn, type ConditionOp, type CreateRoleInput, type DiffResult, type GrantValue, type InferActions, type InferConditionKeys, type InferPermissions, type InferResourceKeys, type InferRoleKeys, type InferScopes, type Permission, type RbacConfig, RbacSyncClient, type RbacSyncClientConfig, type ResourceConfig, type ResourceKey, type ResourceOp, type Role, type RoleConfig, type RoleKey, type RoleManagementClient, type RoleManagementConfig, type RoleOp, type ServerCondition, type ServerResource, type ServerRole, type ServerState, type TypedRbac, type UpdateRoleInput, computeRbacDiff, createRoleManagement, defineRbac, formatRbacDiff, hashConditionSource, loadRbacConfig, loadRbacConfigFromPath, validateRbacConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
formatRbacDiff,
|
|
5
5
|
hashConditionSource,
|
|
6
6
|
loadRbacConfig,
|
|
7
|
+
loadRbacConfigFromPath,
|
|
7
8
|
validateRbacConfig
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5CSBBETH.mjs";
|
|
9
10
|
|
|
10
11
|
// src/role-management.ts
|
|
11
12
|
function createRoleManagement(config) {
|
|
@@ -94,6 +95,7 @@ function toRole(raw) {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
// src/index.ts
|
|
98
|
+
import { defineConfig } from "@auth-gate/core";
|
|
97
99
|
function defineRbac(config, opts) {
|
|
98
100
|
var _a;
|
|
99
101
|
if ((opts == null ? void 0 : opts.validate) !== false) {
|
|
@@ -132,9 +134,11 @@ export {
|
|
|
132
134
|
RbacSyncClient,
|
|
133
135
|
computeRbacDiff,
|
|
134
136
|
createRoleManagement,
|
|
137
|
+
defineConfig,
|
|
135
138
|
defineRbac,
|
|
136
139
|
formatRbacDiff,
|
|
137
140
|
hashConditionSource,
|
|
138
141
|
loadRbacConfig,
|
|
142
|
+
loadRbacConfigFromPath,
|
|
139
143
|
validateRbacConfig
|
|
140
144
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-gate/rbac",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"chalk": "^5.4.0",
|
|
23
|
-
"
|
|
23
|
+
"dotenv": "^17.2.4",
|
|
24
|
+
"jiti": "^2.4.0",
|
|
25
|
+
"@auth-gate/core": "0.9.1"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"tsup": "^8.0.0",
|