learn-auth-sdk 0.1.0 → 0.1.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/bin/learn-auth.js +5 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +61 -0
- package/package.json +27 -5
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/cli/index.ts
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
|
|
4
|
+
// src/cli/commands/login.ts
|
|
5
|
+
async function loginCommand() {
|
|
6
|
+
console.log("Logging in... (Simulation: saved to ~/.learn/credentials.json)");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/cli/commands/init.ts
|
|
10
|
+
import fs from "fs";
|
|
11
|
+
async function initCommand() {
|
|
12
|
+
const defaultConfig = { roles: [], protectedPages: [] };
|
|
13
|
+
fs.writeFileSync("auth-config.json", JSON.stringify(defaultConfig, null, 2));
|
|
14
|
+
console.log("Initialized auth-config.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/cli/commands/config.ts
|
|
18
|
+
import fs2 from "fs";
|
|
19
|
+
async function configCommand(options) {
|
|
20
|
+
const configFile = "auth-config.json";
|
|
21
|
+
if (!fs2.existsSync(configFile)) {
|
|
22
|
+
console.error("Run learn-auth init first.");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const config = JSON.parse(fs2.readFileSync(configFile, "utf8"));
|
|
26
|
+
if (options.roles) {
|
|
27
|
+
config.roles = options.roles.split(",").map((r) => r.trim());
|
|
28
|
+
console.log("Updated roles:", config.roles);
|
|
29
|
+
}
|
|
30
|
+
if (options.protect && options.allowedRoles) {
|
|
31
|
+
const roles = options.allowedRoles.split(",").map((r) => r.trim());
|
|
32
|
+
const existing = config.protectedPages.find((p) => p.pattern === options.protect);
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing.allowedRoles = roles;
|
|
35
|
+
} else {
|
|
36
|
+
config.protectedPages.push({ pattern: options.protect, allowedRoles: roles });
|
|
37
|
+
}
|
|
38
|
+
console.log("Updated protected pages for:", options.protect);
|
|
39
|
+
}
|
|
40
|
+
fs2.writeFileSync(configFile, JSON.stringify(config, null, 2));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/cli/commands/deploy.ts
|
|
44
|
+
import fs3 from "fs";
|
|
45
|
+
async function deployCommand() {
|
|
46
|
+
if (!fs3.existsSync("auth-config.json")) {
|
|
47
|
+
console.error("Run learn-auth init first.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const config = JSON.parse(fs3.readFileSync("auth-config.json", "utf8"));
|
|
51
|
+
console.log("Deploying config to backend:", config);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/cli/index.ts
|
|
55
|
+
var program = new Command();
|
|
56
|
+
program.name("learn-auth").description("CLI tool for managing Auth settings").version("0.1.0");
|
|
57
|
+
program.command("login").description("Authenticate via browser").action(loginCommand);
|
|
58
|
+
program.command("init").description("Initialize auth config").action(initCommand);
|
|
59
|
+
program.command("config").description("Configure roles and protected pages").option("--roles <roles>", "Comma separated roles").option("--protect <page>", "Page URL to protect").option("--allowed-roles <roles>", "Roles allowed to view protected page").action(configCommand);
|
|
60
|
+
program.command("deploy").description("Deploy auth config live").action(deployCommand);
|
|
61
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "learn-auth-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Open-source Auth SDK for decentralized tenant backends",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"dist",
|
|
11
|
+
"bin"
|
|
11
12
|
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/carsontkempf/learn.git",
|
|
16
|
+
"directory": "packages/auth-sdk"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/carsontkempf/learn/tree/main/packages/auth-sdk",
|
|
19
|
+
"author": "Carson Kempf",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"auth",
|
|
22
|
+
"authentication",
|
|
23
|
+
"rbac",
|
|
24
|
+
"multi-tenant",
|
|
25
|
+
"better-auth",
|
|
26
|
+
"d1",
|
|
27
|
+
"cloudflare"
|
|
28
|
+
],
|
|
29
|
+
"bin": {
|
|
30
|
+
"learn-auth": "./bin/learn-auth.js"
|
|
31
|
+
},
|
|
12
32
|
"scripts": {
|
|
13
|
-
"build": "tsup src/index.ts --format esm,iife --dts --clean --minify --global-name AuthSDK",
|
|
14
|
-
"dev": "tsc --watch"
|
|
33
|
+
"build": "tsup src/index.ts --format esm,iife --dts --clean --minify --global-name AuthSDK && tsup src/cli/index.ts --format esm --dts --out-dir dist/cli --external commander",
|
|
34
|
+
"dev": "tsc --watch",
|
|
35
|
+
"prepublishOnly": "npm run build"
|
|
15
36
|
},
|
|
16
37
|
"dependencies": {
|
|
17
|
-
"better-auth": "^1.5.5"
|
|
38
|
+
"better-auth": "^1.5.5",
|
|
39
|
+
"commander": "^12.0.0"
|
|
18
40
|
},
|
|
19
41
|
"devDependencies": {
|
|
20
42
|
"tsup": "^8.5.1",
|