uniwind-pro 1.1.3 → 1.2.1

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": "uniwind-pro",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "Uniwind Pro CLI",
6
6
  "keywords": [
@@ -20,7 +20,8 @@
20
20
  "LICENSE"
21
21
  ],
22
22
  "scripts": {
23
- "postinstall": "node ./pre/postinstall/index.js"
23
+ "postinstall": "node ./pre/postinstall/index.js",
24
+ "test": "node --test tests/*.test.js"
24
25
  },
25
26
  "bin": {
26
27
  "uniwind-pro": "./pre/cli/index.js"
@@ -0,0 +1,57 @@
1
+ // Mask the secret last path segment (token / licenseUUID) so the failing
2
+ // endpoint and version stay visible without leaking credentials.
3
+ export const redactUrl = (url) => {
4
+ try {
5
+ const parsed = new URL(url)
6
+ const segments = parsed.pathname.split('/')
7
+ const secret = segments.at(-1)
8
+
9
+ if (secret) {
10
+ segments[segments.length - 1] = `${secret.slice(0, 2)}***`
11
+ parsed.pathname = segments.join('/')
12
+ }
13
+
14
+ return parsed.toString()
15
+ } catch {
16
+ return url
17
+ }
18
+ }
19
+
20
+ // Single source of truth for a failed HTTP download. Reads the body once as
21
+ // text (works for JSON, HTML and empty bodies) and marks the error as
22
+ // HTTP-originated via `error.http` so the top-level handler can show request
23
+ // metadata instead of a stacktrace.
24
+ export const buildDownloadError = async (response, cdnUrl) => {
25
+ const bodyText = await response.text().catch(() => '')
26
+ const error = new Error(`Download failed: ${response.status} ${response.statusText}`.trim())
27
+
28
+ error.http = {
29
+ status: response.status,
30
+ statusText: response.statusText,
31
+ url: redactUrl(cdnUrl),
32
+ body: bodyText,
33
+ contentType: response.headers.get('content-type'),
34
+ }
35
+
36
+ try {
37
+ error.reason = JSON.parse(bodyText)?.error
38
+ } catch {}
39
+
40
+ return error
41
+ }
42
+
43
+ // Format a captured response body for display: pretty-print JSON bodies, pass
44
+ // other bodies through as-is, and return null when there is nothing to show.
45
+ export const formatBody = (http) => {
46
+ if (!http.body) {
47
+ return null
48
+ }
49
+
50
+ if ((http.contentType || '').includes('application/json')) {
51
+ try {
52
+ return JSON.stringify(JSON.parse(http.body), null, 2)
53
+ } catch {}
54
+ }
55
+
56
+ return http.body
57
+ }
@@ -4,6 +4,7 @@ import { dirname, join, resolve } from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import { UNIWIND_AUTH_TOKEN, SERVICE, UNIWIND_WEB_URL, HELP_EMAIL } from '../consts.js'
6
6
  import { downloadFromCI, downloadFromCLI } from './install.js'
7
+ import { formatBody } from './errors.js'
7
8
 
8
9
  // Create bin symlinks for aliased package
9
10
  const createBinSymlinks = () => {
@@ -60,7 +61,25 @@ const main = async () => {
60
61
  }
61
62
 
62
63
  main().catch((error) => {
64
+ // Non-HTTP failure (filesystem, tar extraction, missing project, DNS/connection):
65
+ // the "Access denied" guidance would be misleading, so show the stacktrace instead.
66
+ if (!error.http) {
67
+ console.log(chalk.red.bold('Installation failed (unexpected error):\n'))
68
+ console.log(chalk.gray(error.stack || error.message))
69
+
70
+ if (error.code) {
71
+ console.log(chalk.gray(`\nCode: ${error.code}`))
72
+ }
73
+
74
+ process.exit(1)
75
+ }
76
+
63
77
  console.log(chalk.red.bold("Access denied: You don't have permission to install this package.\n"))
78
+
79
+ if (error.reason) {
80
+ console.log(chalk.red(`Reason: ${error.reason}\n`))
81
+ }
82
+
64
83
  console.log(
65
84
  chalk.red(
66
85
  `To get a license, visit ${chalk.bold.underline(UNIWIND_WEB_URL)}.\n` +
@@ -71,7 +90,15 @@ main().catch((error) => {
71
90
  )
72
91
  )
73
92
 
74
- console.log(chalk.gray(error.message))
93
+ const body = formatBody(error.http)
94
+
95
+ console.log(chalk.gray('Request failed:'))
96
+ console.log(chalk.gray(` Status: ${error.http.status} ${error.http.statusText}`.trimEnd()))
97
+ console.log(chalk.gray(` URL: ${error.http.url}`))
98
+
99
+ if (body) {
100
+ console.log(chalk.gray(` Response: ${body}`))
101
+ }
75
102
 
76
103
  process.exit(1)
77
104
  })
@@ -13,6 +13,7 @@ import {
13
13
  saveToCache,
14
14
  } from './cache.js'
15
15
  import { checkLatestVersion } from './checkLatestVersion.js'
16
+ import { buildDownloadError } from './errors.js'
16
17
 
17
18
  const __dirname = dirname(fileURLToPath(import.meta.url))
18
19
  const PKG_ROOT = join(__dirname, '../../')
@@ -148,7 +149,7 @@ export const downloadFromCI = async (licenseUUID) => {
148
149
  }
149
150
 
150
151
  if (!response.ok) {
151
- throw new Error(`Download failed: ${response.status} ${response.statusText}`)
152
+ throw await buildDownloadError(response, cdnUrl)
152
153
  }
153
154
 
154
155
  await install(response.body, packageVersion)
@@ -198,17 +199,13 @@ export const downloadFromCLI = async ({ account: handle, password: token }) => {
198
199
  }
199
200
 
200
201
  if (response.status === 401) {
201
- const { keyring } = await import('@zowe/secrets-for-zowe-sdk')
202
- await keyring.deleteCredentials(SERVICE)
202
+ try {
203
+ const { keyring } = await import('@zowe/secrets-for-zowe-sdk')
204
+ await keyring.deletePassword(SERVICE, handle)
205
+ } catch {}
203
206
  }
204
207
 
205
- try {
206
- const body = await response.json()
207
-
208
- throw new Error(`Download failed: ${response.status} ${body.error}`)
209
- } catch (e) {
210
- throw new Error(`Download failed: ${response.status} ${response.statusText}`)
211
- }
208
+ throw await buildDownloadError(response, cdnUrl)
212
209
  }
213
210
 
214
211
  const install = async (stream, packageVersion) => {