@vizamodo/viza-dispatcher 1.5.21 → 1.5.24

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.
@@ -15,7 +15,7 @@ import { ArtifactInvalidTypeError, ArtifactNotFoundError, ArtifactTooLargeError
15
15
  export async function downloadArtifact(ref, options = {}) {
16
16
  const { maxSizeBytes = 50 * 1024 * 1024 } = options;
17
17
  if (!ref?.url) {
18
- throw new Error("Invalid artifact reference: missing url");
18
+ throw new Error("\nInvalid artifact reference: missing url");
19
19
  }
20
20
  const res = await fetch(ref.url);
21
21
  if (!res.ok) {
@@ -34,7 +34,7 @@ export async function downloadArtifact(ref, options = {}) {
34
34
  }
35
35
  const reader = res.body?.getReader();
36
36
  if (!reader) {
37
- throw new Error("Response body is not readable");
37
+ throw new Error("\nResponse body is not readable");
38
38
  }
39
39
  const chunks = [];
40
40
  let received = 0;
@@ -37,7 +37,7 @@ export function formatGhCliFailure(err, mode = "api") {
37
37
  hint = "🛠️ System: GitHub CLI is not ready.\n" +
38
38
  "✅ Try running `gh auth status` to check your connection.";
39
39
  }
40
- return `${hint}\n(diagnostic: ${sanitizedMsg || "unknown error"})`;
40
+ return `\n${hint}\n(diagnostic: ${sanitizedMsg || "unknown error"})`;
41
41
  }
42
42
  /**
43
43
  * Ensure GitHub CLI is authenticated and user is authorized.
@@ -62,11 +62,11 @@ export async function ensureGitHubAuth(options) {
62
62
  throw new Error(formatGhCliFailure(err, "api"));
63
63
  }
64
64
  if (!login) {
65
- throw new Error("GitHub user identity is empty.");
65
+ throw new Error("\nGitHub user identity is empty.");
66
66
  }
67
67
  const candidateTeams = options.allowedTeams || [];
68
68
  if (candidateTeams.length === 0) {
69
- throw new Error("No target teams provided for authorization.");
69
+ throw new Error("\nNo target teams provided for authorization.");
70
70
  }
71
71
  // Query 1 lần: lấy tất cả team mà user thuộc
72
72
  let userTeams;
@@ -102,7 +102,7 @@ export function getGitHubTokenFromGhCli() {
102
102
  });
103
103
  const token = String(out || "").trim();
104
104
  if (!token) {
105
- throw new Error("GitHub CLI login is required. Please run: gh auth login");
105
+ throw new Error("\nGitHub CLI login is required. Please run: gh auth login");
106
106
  }
107
107
  return token;
108
108
  }
@@ -21,7 +21,7 @@ export function getLocalGatewayConfigPath(runtimeEnv) {
21
21
  ? path.join(process.env.USERPROFILE, "AppData", "Roaming")
22
22
  : undefined);
23
23
  if (!appData) {
24
- throw new Error("Missing APPDATA/USERPROFILE env on Windows");
24
+ throw new Error("\nMissing APPDATA/USERPROFILE env on Windows");
25
25
  }
26
26
  return path.join(appData, "viza", `gateway-${runtimeEnv}.json`);
27
27
  }
@@ -93,10 +93,10 @@ export async function refreshGatewayConfigFromGitHub(runtimeEnv) {
93
93
  json = JSON.parse(out);
94
94
  }
95
95
  catch {
96
- throw new Error("GitHub API response is not valid JSON");
96
+ throw new Error("\nGitHub API response is not valid JSON");
97
97
  }
98
98
  if (!json?.content || typeof json.content !== "string") {
99
- throw new Error("GitHub API response missing file content");
99
+ throw new Error("\nGitHub API response missing file content");
100
100
  }
101
101
  let parsed;
102
102
  try {
@@ -68,7 +68,7 @@ export async function dispatcherDispatch(input, options, mode = "dispatch") {
68
68
  const req = buildGatewayReq(cfg);
69
69
  // encryption guard (bootstrap may be stale)
70
70
  if (!req.payload) {
71
- throw new Error("bootstrap_encryption_failed");
71
+ throw new Error("\nbootstrap_encryption_failed");
72
72
  }
73
73
  return dispatchToGateway(req, { endpoint: cfg.endpoint }, mode);
74
74
  };
@@ -128,7 +128,7 @@ export async function dispatcherDispatch(input, options, mode = "dispatch") {
128
128
  throw new DispatchRejectedError(`Dispatch request rejected by gateway${detail}`, { cause: err });
129
129
  }
130
130
  }
131
- console.log("[dispatcher] Refreshing bootstrap config and retrying once …");
131
+ console.log("\n[dispatcher] Refreshing bootstrap config and retrying once …");
132
132
  let retryErr = null;
133
133
  try {
134
134
  const fresh = await loadGatewayBootstrapConfig(options.auth.targetEnv, { forceRefresh: true });
@@ -188,15 +188,15 @@ export async function dispatcherDispatch(input, options, mode = "dispatch") {
188
188
  };
189
189
  const classified = classifyAccepted(accepted);
190
190
  if (classified.kind === "done") {
191
- console.log(`[${identity.login}] status: done (${classified.done.status})`);
191
+ console.log(`\n[${identity.login}] status: done (${classified.done.status})`);
192
192
  }
193
193
  else {
194
194
  // distinguish new dispatch vs reuse
195
195
  if (accepted.action === "reuse") {
196
- console.log(`[${identity.login}] ${chalk.gray(`status: reusing in-flight session`)} (${classified.sessionId}) …`);
196
+ console.log(`\n[${identity.login}] ${chalk.gray(`status: reusing in-flight session`)} (${classified.sessionId}) …`);
197
197
  }
198
198
  else {
199
- console.log(`[${identity.login}] ${chalk.gray(`status: dispatched new session`)} (${classified.sessionId}) …`);
199
+ console.log(`\n[${identity.login}] ${chalk.gray(`status: dispatched new session`)} (${classified.sessionId}) …`);
200
200
  }
201
201
  }
202
202
  return {
@@ -33,7 +33,7 @@ export async function dispatchToGateway(req, options, mode = "dispatch") {
33
33
  catch (err) {
34
34
  clearTimeout(timeout);
35
35
  if (err?.name === "AbortError") {
36
- throw new Error("Gateway dispatch request timed out");
36
+ throw new Error("\nGateway dispatch request timed out");
37
37
  }
38
38
  throw new Error(`Failed to reach gateway: ${err?.message ?? err}`);
39
39
  }
@@ -49,17 +49,17 @@ export async function dispatchToGateway(req, options, mode = "dispatch") {
49
49
  rawText = await res.text();
50
50
  }
51
51
  catch {
52
- throw new Error("Gateway returned unreadable body");
52
+ throw new Error("\nGateway returned unreadable body");
53
53
  }
54
54
  let json;
55
55
  try {
56
56
  json = JSON.parse(rawText);
57
57
  }
58
58
  catch {
59
- throw new Error("Gateway returned invalid JSON");
59
+ throw new Error("\nGateway returned invalid JSON");
60
60
  }
61
61
  if (!json || typeof json !== "object" || typeof json.ok !== "boolean") {
62
- throw new Error("Gateway response does not match dispatch contract");
62
+ throw new Error("\nGateway response does not match dispatch contract");
63
63
  }
64
64
  if (json.ok !== true) {
65
65
  const code = String(json?.error?.code || "dispatch_rejected");
@@ -70,7 +70,7 @@ export async function dispatchToGateway(req, options, mode = "dispatch") {
70
70
  if (!data ||
71
71
  typeof data !== "object" ||
72
72
  typeof data.action !== "string") {
73
- throw new Error("Gateway accepted response is malformed");
73
+ throw new Error("\nGateway accepted response is malformed");
74
74
  }
75
75
  return data;
76
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/viza-dispatcher",
3
- "version": "1.5.21",
3
+ "version": "1.5.24",
4
4
  "description": "Dispatcher module for GitHub workflow automation across Viza projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",