@nesalia/cli 1.0.3 → 1.0.4

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/auth/login.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAgB1C,CAAC"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/login.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAyB1C,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { log } from "@clack/prompts";
2
2
  import { saveCredentials, startDeviceFlow } from "../../lib/auth/index.js";
3
+ import { AuthFlowError } from "../../lib/auth/device-flow/errors.js";
3
4
  export const login = async () => {
4
5
  try {
5
6
  const result = await startDeviceFlow();
@@ -12,7 +13,18 @@ export const login = async () => {
12
13
  log.success("Successfully logged in!");
13
14
  }
14
15
  catch (error) {
15
- log.error(error instanceof Error ? error.message : "Unknown error");
16
+ if (error instanceof AuthFlowError) {
17
+ if (error.isNetwork) {
18
+ log.error(`Network error: ${error.message}`);
19
+ log.step("Make sure the auth server is running and accessible.");
20
+ }
21
+ else {
22
+ log.error(`Auth error: ${error.message}`);
23
+ }
24
+ }
25
+ else {
26
+ log.error(error instanceof Error ? error.message : "Unknown error");
27
+ }
16
28
  process.exit(1);
17
29
  }
18
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/commands/auth/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,eAAe,EAA0B,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAEnG,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,IAAmB,EAAE;IAC7C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,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yBAAyB,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACnC,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACpB,GAAG,CAAC,KAAK,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC7C,GAAG,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,KAAK,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ const args = process.argv.includes("-v")
8
8
  const program = new Command();
9
9
  program
10
10
  .name("nesalia")
11
- .version("1.0.3")
11
+ .version("1.0.4")
12
12
  .description("@nesalia/cli — Manage your account authentication");
13
13
  program
14
14
  .command("auth", { isDefault: false })
@@ -1 +1 @@
1
- {"version":3,"file":"device-code.d.ts","sourceRoot":"","sources":["../../../../src/lib/auth/device-flow/device-code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,iBAAiB,GAAU,QAAQ,UAAU,KAAG,OAAO,CAAC,gBAAgB,CAmBpF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,IAAI,CAI3D,CAAC"}
1
+ {"version":3,"file":"device-code.d.ts","sourceRoot":"","sources":["../../../../src/lib/auth/device-flow/device-code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,iBAAiB,GAAU,QAAQ,UAAU,KAAG,OAAO,CAAC,gBAAgB,CA0CpF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,IAAI,CAI3D,CAAC"}
@@ -1,16 +1,32 @@
1
1
  import { log } from "@clack/prompts";
2
2
  import open from "open";
3
3
  import { CLIENT_ID, SCOPE } from "./config.js";
4
- import { AuthFlowError } from "./errors.js";
4
+ import { AuthFlowError, isTransientError } from "./errors.js";
5
5
  export const requestDeviceCode = async (client) => {
6
6
  log.info("Requesting device authorization...");
7
- const { data, error } = await client.device.code({
8
- client_id: CLIENT_ID,
9
- scope: SCOPE,
10
- });
11
- if (error || !data) {
12
- const msg = error?.error_description ?? "Failed to get device code";
13
- throw new AuthFlowError(msg);
7
+ let data;
8
+ let error;
9
+ try {
10
+ const result = await client.device.code({
11
+ client_id: CLIENT_ID,
12
+ scope: SCOPE,
13
+ });
14
+ data = result.data;
15
+ error = result.error;
16
+ }
17
+ catch (err) {
18
+ if (isTransientError(err)) {
19
+ throw AuthFlowError.network(`Cannot reach the auth server. Check your internet connection or the server may be down.`);
20
+ }
21
+ throw AuthFlowError.network(`Network error while requesting device code: ${err.message}`);
22
+ }
23
+ if (error) {
24
+ const code = error.error ?? "unknown_error";
25
+ const desc = error.error_description ?? "No description provided";
26
+ throw new AuthFlowError(`[${code}] ${desc}`);
27
+ }
28
+ if (!data) {
29
+ throw new AuthFlowError("Empty response from server. The auth server may be misconfigured.");
14
30
  }
15
31
  return {
16
32
  deviceCode: data.device_code,
@@ -1 +1 @@
1
- {"version":3,"file":"device-code.js","sourceRoot":"","sources":["../../../../src/lib/auth/device-flow/device-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,MAAkB,EAA6B,EAAE;IACvF,GAAG,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAE/C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC/C,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,MAAM,GAAG,GAAG,KAAK,EAAE,iBAAiB,IAAI,2BAA2B,CAAC;QACpE,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,WAAW;QAC5B,QAAQ,EAAE,IAAI,CAAC,SAAS;QACxB,eAAe,EAAE,IAAI,CAAC,yBAAyB;QAC/C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,GAAW,EAAiB,EAAE;IAC9D,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QACzB,kEAAkE;IACpE,CAAC,CAAC,CAAC;AACL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EAAE,CAAC;QACV,MAAM,IAAI,aAAa,CACrB,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,WAAW;QAC5B,QAAQ,EAAE,IAAI,CAAC,SAAS;QACxB,eAAe,EAAE,IAAI,CAAC,yBAAyB;QAC/C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,GAAW,EAAiB,EAAE;IAC9D,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QACzB,kEAAkE;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nesalia/cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Nesalia CLI — Manage your account and organizations",
6
6
  "license": "MIT",
@@ -1,5 +1,6 @@
1
1
  import { log } from "@clack/prompts";
2
2
  import { saveCredentials, type StoredCredentials, startDeviceFlow } from "../../lib/auth/index.js";
3
+ import { AuthFlowError } from "../../lib/auth/device-flow/errors.js";
3
4
 
4
5
  export const login = async (): Promise<void> => {
5
6
  try {
@@ -14,7 +15,16 @@ export const login = async (): Promise<void> => {
14
15
  saveCredentials(credentials);
15
16
  log.success("Successfully logged in!");
16
17
  } catch (error) {
17
- log.error(error instanceof Error ? error.message : "Unknown error");
18
+ if (error instanceof AuthFlowError) {
19
+ if (error.isNetwork) {
20
+ log.error(`Network error: ${error.message}`);
21
+ log.step("Make sure the auth server is running and accessible.");
22
+ } else {
23
+ log.error(`Auth error: ${error.message}`);
24
+ }
25
+ } else {
26
+ log.error(error instanceof Error ? error.message : "Unknown error");
27
+ }
18
28
  process.exit(1);
19
29
  }
20
30
  };
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ const program = new Command();
12
12
 
13
13
  program
14
14
  .name("nesalia")
15
- .version("1.0.3")
15
+ .version("1.0.4")
16
16
  .description("@nesalia/cli — Manage your account authentication");
17
17
 
18
18
  program
@@ -2,7 +2,7 @@ import { log } from "@clack/prompts";
2
2
  import open from "open";
3
3
  import type { AuthClient } from "../client.js";
4
4
  import { CLIENT_ID, SCOPE } from "./config.js";
5
- import { AuthFlowError } from "./errors.js";
5
+ import { AuthFlowError, isTransientError } from "./errors.js";
6
6
 
7
7
  export interface DeviceCodeResult {
8
8
  deviceCode: string;
@@ -14,14 +14,37 @@ export interface DeviceCodeResult {
14
14
  export const requestDeviceCode = async (client: AuthClient): Promise<DeviceCodeResult> => {
15
15
  log.info("Requesting device authorization...");
16
16
 
17
- const { data, error } = await client.device.code({
18
- client_id: CLIENT_ID,
19
- scope: SCOPE,
20
- });
17
+ let data: Awaited<ReturnType<AuthClient["device"]["code"]>>["data"];
18
+ let error: Awaited<ReturnType<AuthClient["device"]["code"]>>["error"];
19
+
20
+ try {
21
+ const result = await client.device.code({
22
+ client_id: CLIENT_ID,
23
+ scope: SCOPE,
24
+ });
25
+ data = result.data;
26
+ error = result.error;
27
+ } catch (err) {
28
+ if (isTransientError(err)) {
29
+ throw AuthFlowError.network(
30
+ `Cannot reach the auth server. Check your internet connection or the server may be down.`,
31
+ );
32
+ }
33
+ throw AuthFlowError.network(
34
+ `Network error while requesting device code: ${(err as Error).message}`,
35
+ );
36
+ }
37
+
38
+ if (error) {
39
+ const code = error.error ?? "unknown_error";
40
+ const desc = error.error_description ?? "No description provided";
41
+ throw new AuthFlowError(`[${code}] ${desc}`);
42
+ }
21
43
 
22
- if (error || !data) {
23
- const msg = error?.error_description ?? "Failed to get device code";
24
- throw new AuthFlowError(msg);
44
+ if (!data) {
45
+ throw new AuthFlowError(
46
+ "Empty response from server. The auth server may be misconfigured.",
47
+ );
25
48
  }
26
49
 
27
50
  return {