ds-01 0.1.6 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ds-01",
3
- "version": "0.1.6",
3
+ "version": "1.0.2",
4
4
  "description": "Make your site best with DS01",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,8 @@
18
18
  "commander": "^14",
19
19
  "node-machine-id": "^1",
20
20
  "open": "^10",
21
- "ora": "^8"
21
+ "ora": "^8",
22
+ "picocolors": "^1.1.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/node": "^24.13.3",
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare const login: Command;
3
- //# sourceMappingURL=login.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,76 +0,0 @@
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
- });