ds-01 0.1.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.
@@ -0,0 +1,3 @@
1
+ [?9001h[?1004h]0;C:\WINDOWS\system32\cmd.exe[?25h[?25l
2
+ > @repo/cli@0.0.1 build C:\Web-dev 2.0\Personal Projects\ds01\packages\cli
3
+ > tsc[?25h[?9001l[?1004l
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare const login: Command;
3
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/command/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAcpC,eAAO,MAAM,KAAK,SA4Fd,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { Command } from "commander";
2
+ import ora from "ora";
3
+ import chalk from "chalk";
4
+ import open from "open";
5
+ import { machineIdSync } from "node-machine-id";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import os from "os";
9
+ // ⚠️ In production, replace with your actual deployed Vercel domain
10
+ const API_BASE_URL = process.env.DS01_API_URL || "http://localhost:3000";
11
+ const CONFIG_DIR = path.join(os.homedir(), ".ds01");
12
+ const AUTH_FILE = path.join(CONFIG_DIR, "auth.json");
13
+ export const login = new Command()
14
+ .name("login")
15
+ .description("Authenticate your terminal with DS01 via browser")
16
+ .action(async () => {
17
+ const spinner = ora("Initializing secure login flow...").start();
18
+ try {
19
+ // 1. Generate Hardware Fingerprint Hash (MAC/CPU bound)
20
+ const hardwareId = machineIdSync();
21
+ // 2. Request a new Device Code from the Next.js API
22
+ const initResponse = await fetch(`${API_BASE_URL}/api/auth/device/code`, {
23
+ method: "POST",
24
+ });
25
+ if (!initResponse.ok) {
26
+ throw new Error("Failed to reach DS01 authorization server.");
27
+ }
28
+ const { deviceCode, userCode, verificationUrl, interval } = await initResponse.json();
29
+ spinner.stop();
30
+ console.log("\n" + chalk.cyan.bold("=== DS01 Secure Terminal Login ==="));
31
+ console.log(`\nYour device pairing code is: ${chalk.bgCyan.black.bold(` ${userCode} `)}\n`);
32
+ console.log(`If your browser does not open automatically, visit:`);
33
+ console.log(chalk.underline.blue(verificationUrl) + "\n");
34
+ // 3. Automatically open the user's default browser
35
+ await open(verificationUrl);
36
+ spinner.start("Waiting for web approval...");
37
+ // 4. Poll the Token Endpoint
38
+ let token = null;
39
+ const pollInterval = (interval || 2) * 1000;
40
+ while (!token) {
41
+ // Wait before polling again
42
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
43
+ const tokenResponse = await fetch(`${API_BASE_URL}/api/auth/device/token`, {
44
+ method: "POST",
45
+ headers: { "Content-Type": "application/json" },
46
+ body: JSON.stringify({ deviceCode, machineId: hardwareId }),
47
+ });
48
+ const tokenData = await tokenResponse.json();
49
+ if (tokenResponse.ok && tokenData.accessToken) {
50
+ token = tokenData.accessToken;
51
+ }
52
+ else if (tokenData.error !== "authorization_pending") {
53
+ // If error is anything OTHER than pending, fail out.
54
+ spinner.fail(chalk.red("Authorization failed or expired."));
55
+ console.error(chalk.red(`Reason: ${tokenData.error}`));
56
+ process.exit(1);
57
+ }
58
+ }
59
+ // 5. Save Token & Machine ID to ~/.ds01/auth.json
60
+ if (!fs.existsSync(CONFIG_DIR)) {
61
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
62
+ }
63
+ fs.writeFileSync(AUTH_FILE, JSON.stringify({
64
+ token,
65
+ machineId: hardwareId,
66
+ updatedAt: new Date().toISOString(),
67
+ }, null, 2));
68
+ spinner.succeed(chalk.green.bold("Terminal paired successfully!"));
69
+ console.log(chalk.gray(`Session token bound to hardware signature and saved locally.`));
70
+ }
71
+ catch (error) {
72
+ spinner.fail(chalk.red("An error occurred during login."));
73
+ console.error(chalk.red(error.message));
74
+ process.exit(1);
75
+ }
76
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare const login: Command;
3
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,eAAO,MAAM,KAAK,SAgGd,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { Command } from "commander";
2
+ import ora from "ora";
3
+ import chalk from "chalk";
4
+ import open from "open";
5
+ import machineIdPkg from "node-machine-id";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import os from "os";
9
+ // ⚠️ In production, replace with your actual deployed Vercel domain
10
+ const API_BASE_URL = process.env.DS01_API_URL || "https://ds-01.vercel.app";
11
+ const CONFIG_DIR = path.join(os.homedir(), ".ds01");
12
+ const AUTH_FILE = path.join(CONFIG_DIR, "auth.json");
13
+ const { machineIdSync } = machineIdPkg;
14
+ export const login = new Command()
15
+ .name("login")
16
+ .description("Authenticate your terminal with DS01 via browser")
17
+ .action(async () => {
18
+ const spinner = ora("Initializing secure login flow...").start();
19
+ try {
20
+ // 1. Generate Hardware Fingerprint Hash (MAC/CPU bound)
21
+ const hardwareId = machineIdSync();
22
+ // 2. Request a new Device Code from the Next.js API
23
+ const initResponse = await fetch(`${API_BASE_URL}/api/auth/device/code`, {
24
+ method: "POST",
25
+ headers: {
26
+ "Content-Type": "application/json",
27
+ },
28
+ body: JSON.stringify({ machineId: hardwareId }), // <-- Send the machine ID to the server
29
+ });
30
+ if (!initResponse.ok) {
31
+ throw new Error("Failed to reach DS01 authorization server.");
32
+ }
33
+ const { deviceCode, userCode, verificationUrl, interval } = await initResponse.json();
34
+ spinner.stop();
35
+ console.log("\n" + chalk.cyan.bold("=== DS01 Secure Terminal Login ==="));
36
+ console.log(`\nYour device pairing code is: ${chalk.bgCyan.black.bold(` ${userCode} `)}\n`);
37
+ console.log(`If your browser does not open automatically, visit:`);
38
+ console.log(chalk.underline.blue(verificationUrl) + "\n");
39
+ // 3. Automatically open the user's default browser
40
+ await open(verificationUrl);
41
+ spinner.start("Waiting for web approval...");
42
+ // 4. Poll the Token Endpoint
43
+ let token = null;
44
+ const pollInterval = (interval || 2) * 1000;
45
+ while (!token) {
46
+ // Wait before polling again
47
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
48
+ const tokenResponse = await fetch(`${API_BASE_URL}/api/auth/device/token`, {
49
+ method: "POST",
50
+ headers: { "Content-Type": "application/json" },
51
+ body: JSON.stringify({ deviceCode, machineId: hardwareId }),
52
+ });
53
+ const tokenData = await tokenResponse.json();
54
+ if (tokenResponse.ok && tokenData.accessToken) {
55
+ token = tokenData.accessToken;
56
+ }
57
+ else if (tokenData.error !== "authorization_pending") {
58
+ // If error is anything OTHER than pending, fail out.
59
+ spinner.fail(chalk.red("Authorization failed or expired."));
60
+ console.error(chalk.red(`Reason: ${tokenData.error}`));
61
+ process.exit(1);
62
+ }
63
+ }
64
+ // 5. Save Token & Machine ID to ~/.ds01/auth.json
65
+ if (!fs.existsSync(CONFIG_DIR)) {
66
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
67
+ }
68
+ fs.writeFileSync(AUTH_FILE, JSON.stringify({
69
+ token,
70
+ machineId: hardwareId,
71
+ updatedAt: new Date().toISOString(),
72
+ }, null, 2));
73
+ spinner.succeed(chalk.green.bold("Terminal paired successfully!"));
74
+ console.log(chalk.gray(`Session token bound to hardware signature and saved locally.`));
75
+ }
76
+ catch (error) {
77
+ spinner.fail(chalk.red("An error occurred during login."));
78
+ console.error(chalk.red(error.message));
79
+ process.exit(1);
80
+ }
81
+ });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { login } from "./commands/login.js";
4
+ // Note: Add .js extension if you have module resolution issues, or keep it without depending on your tsconfig
5
+ const program = new Command();
6
+ program
7
+ .name("ds01")
8
+ .description("DS01 Custom Component Registry CLI")
9
+ .version("1.0.0");
10
+ // Register the login command
11
+ program.addCommand(login);
12
+ // Parse the arguments from the terminal
13
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "ds-01",
3
+ "version": "0.1.2",
4
+ "description": "Make your site best with DS01",
5
+ "type": "module",
6
+ "bin": {
7
+ "ds01": "dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "chalk": "^5",
17
+ "commander": "^14",
18
+ "node-machine-id": "^1",
19
+ "open": "^10",
20
+ "ora": "^8"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^24",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5"
26
+ }
27
+ }
@@ -0,0 +1,113 @@
1
+ import { Command } from "commander";
2
+ import ora from "ora";
3
+ import chalk from "chalk";
4
+ import open from "open";
5
+ import machineIdPkg from "node-machine-id";
6
+
7
+ import fs from "fs";
8
+ import path from "path";
9
+ import os from "os";
10
+
11
+ // ⚠️ In production, replace with your actual deployed Vercel domain
12
+ const API_BASE_URL = process.env.DS01_API_URL || "https://ds-01.vercel.app";
13
+ const CONFIG_DIR = path.join(os.homedir(), ".ds01");
14
+ const AUTH_FILE = path.join(CONFIG_DIR, "auth.json");
15
+ const { machineIdSync } = machineIdPkg;
16
+
17
+ export const login = new Command()
18
+ .name("login")
19
+ .description("Authenticate your terminal with DS01 via browser")
20
+ .action(async () => {
21
+ const spinner = ora("Initializing secure login flow...").start();
22
+
23
+ try {
24
+ // 1. Generate Hardware Fingerprint Hash (MAC/CPU bound)
25
+ const hardwareId = machineIdSync();
26
+
27
+ // 2. Request a new Device Code from the Next.js API
28
+ const initResponse = await fetch(`${API_BASE_URL}/api/auth/device/code`, {
29
+ method: "POST",
30
+ headers: {
31
+ "Content-Type": "application/json",
32
+ },
33
+ body: JSON.stringify({ machineId: hardwareId }), // <-- Send the machine ID to the server
34
+ });
35
+
36
+ if (!initResponse.ok) {
37
+ throw new Error("Failed to reach DS01 authorization server.");
38
+ }
39
+
40
+ const { deviceCode, userCode, verificationUrl, interval } =
41
+ await initResponse.json();
42
+
43
+ spinner.stop();
44
+ console.log("\n" + chalk.cyan.bold("=== DS01 Secure Terminal Login ==="));
45
+ console.log(
46
+ `\nYour device pairing code is: ${chalk.bgCyan.black.bold(` ${userCode} `)}\n`,
47
+ );
48
+ console.log(`If your browser does not open automatically, visit:`);
49
+ console.log(chalk.underline.blue(verificationUrl) + "\n");
50
+
51
+ // 3. Automatically open the user's default browser
52
+ await open(verificationUrl);
53
+ spinner.start("Waiting for web approval...");
54
+
55
+ // 4. Poll the Token Endpoint
56
+ let token = null;
57
+ const pollInterval = (interval || 2) * 1000;
58
+
59
+ while (!token) {
60
+ // Wait before polling again
61
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
62
+
63
+ const tokenResponse = await fetch(
64
+ `${API_BASE_URL}/api/auth/device/token`,
65
+ {
66
+ method: "POST",
67
+ headers: { "Content-Type": "application/json" },
68
+ body: JSON.stringify({ deviceCode, machineId: hardwareId }),
69
+ },
70
+ );
71
+
72
+ const tokenData = await tokenResponse.json();
73
+
74
+ if (tokenResponse.ok && tokenData.accessToken) {
75
+ token = tokenData.accessToken;
76
+ } else if (tokenData.error !== "authorization_pending") {
77
+ // If error is anything OTHER than pending, fail out.
78
+ spinner.fail(chalk.red("Authorization failed or expired."));
79
+ console.error(chalk.red(`Reason: ${tokenData.error}`));
80
+ process.exit(1);
81
+ }
82
+ }
83
+
84
+ // 5. Save Token & Machine ID to ~/.ds01/auth.json
85
+ if (!fs.existsSync(CONFIG_DIR)) {
86
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
87
+ }
88
+
89
+ fs.writeFileSync(
90
+ AUTH_FILE,
91
+ JSON.stringify(
92
+ {
93
+ token,
94
+ machineId: hardwareId,
95
+ updatedAt: new Date().toISOString(),
96
+ },
97
+ null,
98
+ 2,
99
+ ),
100
+ );
101
+
102
+ spinner.succeed(chalk.green.bold("Terminal paired successfully!"));
103
+ console.log(
104
+ chalk.gray(
105
+ `Session token bound to hardware signature and saved locally.`,
106
+ ),
107
+ );
108
+ } catch (error: any) {
109
+ spinner.fail(chalk.red("An error occurred during login."));
110
+ console.error(chalk.red(error.message));
111
+ process.exit(1);
112
+ }
113
+ });
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import { login } from "./commands/login.js";
5
+ // Note: Add .js extension if you have module resolution issues, or keep it without depending on your tsconfig
6
+
7
+ const program = new Command();
8
+
9
+ program
10
+ .name("ds01")
11
+ .description("DS01 Custom Component Registry CLI")
12
+ .version("1.0.0");
13
+
14
+ // Register the login command
15
+ program.addCommand(login);
16
+
17
+ // Parse the arguments from the terminal
18
+ program.parse(process.argv);
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "types": ["node"],
5
+ "moduleResolution": "NodeNext",
6
+ "module": "NodeNext",
7
+ "outDir": "dist",
8
+ "rootDir": "src"
9
+ },
10
+ "include": ["src"]
11
+ }