ds-01 1.0.6 → 1.0.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwBpC,eAAO,MAAM,KAAK,SAuTd,CAAC"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwBpC,eAAO,MAAM,KAAK,SA6Td,CAAC"}
@@ -16,23 +16,19 @@ export const login = new Command()
16
16
  intro(`${pc.bgWhite(pc.black(pc.bold(" DS01 ")))} ${pc.gray("v1.0.0 — Terminal Authentication")}`);
17
17
  const s = spinner();
18
18
  try {
19
- // --------------------------------------------------
20
- // 1. Create / load the device's secure key
21
- // --------------------------------------------------
19
+ // ==================================================
20
+ // 1. CREATE / LOAD SECURE DEVICE KEY
21
+ // ==================================================
22
22
  s.start("Preparing secure device identity...");
23
23
  await createDeviceKey();
24
- // Only the PUBLIC key/certificate leaves
25
- // the user's machine.
26
24
  const publicKey = await getDevicePublicKey();
27
- // Existing machine fingerprint.
28
25
  const hardwareId = machineIdSync();
29
- // Detect the cryptographic key type.
30
26
  const publicKeyType = process.platform === "win32"
31
27
  ? "windows-rsa"
32
28
  : "macos-ec";
33
- // --------------------------------------------------
34
- // 2. Start device authorization
35
- // --------------------------------------------------
29
+ // ==================================================
30
+ // 2. REQUEST DEVICE CODE
31
+ // ==================================================
36
32
  s.start("Requesting pairing code...");
37
33
  const initResponse = await fetch(`${API_BASE_URL}/api/auth/device/code`, {
38
34
  method: "POST",
@@ -57,21 +53,20 @@ export const login = new Command()
57
53
  throw new Error("Authorization server returned an invalid device response.");
58
54
  }
59
55
  s.stop(pc.green("Secure device identity registered."));
60
- // --------------------------------------------------
61
- // 3. Ask user to approve in browser
62
- // --------------------------------------------------
56
+ // ==================================================
57
+ // 3. SHOW BROWSER AUTHORIZATION
58
+ // ==================================================
63
59
  note(`${pc.bold("Pairing Code:")} ${pc.cyan(pc.bold(` ${userCode} `))}\n` +
64
60
  `${pc.bold("Verification URL:")} ${pc.underline(verificationUrl)}`, "Action Required");
65
61
  try {
66
62
  await open(verificationUrl);
67
63
  }
68
64
  catch {
69
- // Browser launch failure
70
- // is non-fatal.
65
+ // Browser launch failure is non-fatal.
71
66
  }
72
- // --------------------------------------------------
73
- // 4. Poll for authorization
74
- // --------------------------------------------------
67
+ // ==================================================
68
+ // 4. POLL FOR AUTHORIZATION
69
+ // ==================================================
75
70
  s.start("Waiting for web authorization...");
76
71
  const pollInterval = (interval || 5) * 1000;
77
72
  let token = null;
@@ -97,56 +92,64 @@ export const login = new Command()
97
92
  cancel("Unable to read authorization response.");
98
93
  process.exit(1);
99
94
  }
100
- // --------------------------------------------------
101
- // SUCCESS
102
- // --------------------------------------------------
95
+ // ==================================================
96
+ // AUTHORIZATION SUCCESS
97
+ // ==================================================
103
98
  if (tokenResponse.ok &&
104
99
  typeof tokenData.accessToken ===
105
100
  "string" &&
106
101
  tokenData.accessToken.length > 0) {
107
102
  token =
108
103
  tokenData.accessToken;
109
- // IMPORTANT:
110
- // Stop the spinner immediately.
111
- s.stop(pc.green("Hardware signature linked & token verified!"));
112
- // IMPORTANT:
113
- // Leave the polling loop immediately.
114
104
  break;
115
105
  }
116
- // --------------------------------------------------
106
+ // ==================================================
117
107
  // STILL WAITING
118
- // --------------------------------------------------
108
+ // ==================================================
119
109
  if (tokenData.error ===
120
110
  "authorization_pending") {
121
111
  continue;
122
112
  }
123
- // --------------------------------------------------
124
- // FAILED / EXPIRED
125
- // --------------------------------------------------
113
+ // ==================================================
114
+ // AUTHORIZATION FAILED
115
+ // ==================================================
126
116
  s.stop(pc.red("Authorization failed or expired."));
127
117
  cancel(`Reason: ${tokenData.error ||
128
118
  "Unknown authorization error"}`);
129
119
  process.exit(1);
130
120
  }
131
- // --------------------------------------------------
132
- // 5. Make absolutely sure token exists
133
- // --------------------------------------------------
121
+ // ==================================================
122
+ // 5. STOP POLLING SPINNER
123
+ // ==================================================
124
+ s.stop(pc.green("Hardware signature linked & token verified!"));
125
+ // ==================================================
126
+ // 6. ENSURE TOKEN EXISTS
127
+ // ==================================================
134
128
  if (!token) {
135
129
  throw new Error("Authorization completed without receiving an access token.");
136
130
  }
137
- // --------------------------------------------------
138
- // 6. Save CLI token + machine ID
139
- // --------------------------------------------------
131
+ // ==================================================
132
+ // 7. SAVE TOKEN
133
+ // ==================================================
140
134
  saveToken(token, hardwareId);
141
- // --------------------------------------------------
142
- // 7. Success
143
- // --------------------------------------------------
135
+ // ==================================================
136
+ // 8. SUCCESS
137
+ // ==================================================
144
138
  outro(`${pc.white("✔")} ${pc.bold("Terminal synced successfully")}\n` +
145
139
  pc.gray("Secure device key and session token are ready."));
140
+ // ==================================================
141
+ // 9. HARD EXIT
142
+ // ==================================================
143
+ //
144
+ // The login command is completely finished.
145
+ //
146
+ // This prevents any lingering CLI handles
147
+ // (spinner timers, readline handles, etc.)
148
+ // from keeping the Node process alive.
149
+ //
150
+ process.exit(0);
146
151
  }
147
152
  catch (error) {
148
- // Only stop the spinner if it is
149
- // still running.
150
153
  s.stop(pc.red("An error occurred during login."));
151
154
  cancel(pc.gray(error?.message ||
152
155
  "Unknown CLI Error"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ds-01",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Make your site best with DS01",
5
5
  "type": "module",
6
6
  "bin": {
@@ -43,9 +43,9 @@ export const login = new Command()
43
43
  const s = spinner();
44
44
 
45
45
  try {
46
- // --------------------------------------------------
47
- // 1. Create / load the device's secure key
48
- // --------------------------------------------------
46
+ // ==================================================
47
+ // 1. CREATE / LOAD SECURE DEVICE KEY
48
+ // ==================================================
49
49
 
50
50
  s.start(
51
51
  "Preparing secure device identity...",
@@ -53,24 +53,20 @@ export const login = new Command()
53
53
 
54
54
  await createDeviceKey();
55
55
 
56
- // Only the PUBLIC key/certificate leaves
57
- // the user's machine.
58
56
  const publicKey =
59
57
  await getDevicePublicKey();
60
58
 
61
- // Existing machine fingerprint.
62
59
  const hardwareId =
63
60
  machineIdSync();
64
61
 
65
- // Detect the cryptographic key type.
66
62
  const publicKeyType =
67
63
  process.platform === "win32"
68
64
  ? "windows-rsa"
69
65
  : "macos-ec";
70
66
 
71
- // --------------------------------------------------
72
- // 2. Start device authorization
73
- // --------------------------------------------------
67
+ // ==================================================
68
+ // 2. REQUEST DEVICE CODE
69
+ // ==================================================
74
70
 
75
71
  s.start(
76
72
  "Requesting pairing code...",
@@ -117,7 +113,8 @@ export const login = new Command()
117
113
  userCode,
118
114
  verificationUrl,
119
115
  interval,
120
- } = await initResponse.json();
116
+ } =
117
+ await initResponse.json();
121
118
 
122
119
  if (
123
120
  !deviceCode ||
@@ -135,9 +132,9 @@ export const login = new Command()
135
132
  ),
136
133
  );
137
134
 
138
- // --------------------------------------------------
139
- // 3. Ask user to approve in browser
140
- // --------------------------------------------------
135
+ // ==================================================
136
+ // 3. SHOW BROWSER AUTHORIZATION
137
+ // ==================================================
141
138
 
142
139
  note(
143
140
  `${pc.bold(
@@ -160,13 +157,12 @@ export const login = new Command()
160
157
  verificationUrl,
161
158
  );
162
159
  } catch {
163
- // Browser launch failure
164
- // is non-fatal.
160
+ // Browser launch failure is non-fatal.
165
161
  }
166
162
 
167
- // --------------------------------------------------
168
- // 4. Poll for authorization
169
- // --------------------------------------------------
163
+ // ==================================================
164
+ // 4. POLL FOR AUTHORIZATION
165
+ // ==================================================
170
166
 
171
167
  s.start(
172
168
  "Waiting for web authorization...",
@@ -225,9 +221,9 @@ export const login = new Command()
225
221
  process.exit(1);
226
222
  }
227
223
 
228
- // --------------------------------------------------
229
- // SUCCESS
230
- // --------------------------------------------------
224
+ // ==================================================
225
+ // AUTHORIZATION SUCCESS
226
+ // ==================================================
231
227
 
232
228
  if (
233
229
  tokenResponse.ok &&
@@ -238,22 +234,12 @@ export const login = new Command()
238
234
  token =
239
235
  tokenData.accessToken;
240
236
 
241
- // IMPORTANT:
242
- // Stop the spinner immediately.
243
- s.stop(
244
- pc.green(
245
- "Hardware signature linked & token verified!",
246
- ),
247
- );
248
-
249
- // IMPORTANT:
250
- // Leave the polling loop immediately.
251
237
  break;
252
238
  }
253
239
 
254
- // --------------------------------------------------
240
+ // ==================================================
255
241
  // STILL WAITING
256
- // --------------------------------------------------
242
+ // ==================================================
257
243
 
258
244
  if (
259
245
  tokenData.error ===
@@ -262,9 +248,9 @@ export const login = new Command()
262
248
  continue;
263
249
  }
264
250
 
265
- // --------------------------------------------------
266
- // FAILED / EXPIRED
267
- // --------------------------------------------------
251
+ // ==================================================
252
+ // AUTHORIZATION FAILED
253
+ // ==================================================
268
254
 
269
255
  s.stop(
270
256
  pc.red(
@@ -282,9 +268,19 @@ export const login = new Command()
282
268
  process.exit(1);
283
269
  }
284
270
 
285
- // --------------------------------------------------
286
- // 5. Make absolutely sure token exists
287
- // --------------------------------------------------
271
+ // ==================================================
272
+ // 5. STOP POLLING SPINNER
273
+ // ==================================================
274
+
275
+ s.stop(
276
+ pc.green(
277
+ "Hardware signature linked & token verified!",
278
+ ),
279
+ );
280
+
281
+ // ==================================================
282
+ // 6. ENSURE TOKEN EXISTS
283
+ // ==================================================
288
284
 
289
285
  if (!token) {
290
286
  throw new Error(
@@ -292,18 +288,18 @@ export const login = new Command()
292
288
  );
293
289
  }
294
290
 
295
- // --------------------------------------------------
296
- // 6. Save CLI token + machine ID
297
- // --------------------------------------------------
291
+ // ==================================================
292
+ // 7. SAVE TOKEN
293
+ // ==================================================
298
294
 
299
295
  saveToken(
300
296
  token,
301
297
  hardwareId,
302
298
  );
303
299
 
304
- // --------------------------------------------------
305
- // 7. Success
306
- // --------------------------------------------------
300
+ // ==================================================
301
+ // 8. SUCCESS
302
+ // ==================================================
307
303
 
308
304
  outro(
309
305
  `${pc.white(
@@ -315,9 +311,19 @@ export const login = new Command()
315
311
  "Secure device key and session token are ready.",
316
312
  ),
317
313
  );
314
+
315
+ // ==================================================
316
+ // 9. HARD EXIT
317
+ // ==================================================
318
+ //
319
+ // The login command is completely finished.
320
+ //
321
+ // This prevents any lingering CLI handles
322
+ // (spinner timers, readline handles, etc.)
323
+ // from keeping the Node process alive.
324
+ //
325
+ process.exit(0);
318
326
  } catch (error: any) {
319
- // Only stop the spinner if it is
320
- // still running.
321
327
  s.stop(
322
328
  pc.red(
323
329
  "An error occurred during login.",