@heroku/heroku-cli-util 8.0.15 → 9.0.0-beta.0
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/LICENSE +15 -3
- package/README.md +44 -241
- package/dist/test-helpers/expect-output.d.ts +2 -0
- package/dist/test-helpers/expect-output.js +16 -0
- package/dist/test-helpers/init.d.ts +1 -0
- package/dist/test-helpers/init.js +18 -0
- package/dist/test-helpers/stub-output.d.ts +2 -0
- package/dist/test-helpers/stub-output.js +33 -0
- package/dist/types/errors/ambiguous.d.ts +15 -0
- package/dist/types/errors/ambiguous.js +14 -0
- package/dist/types/errors/not-found.d.ts +5 -0
- package/dist/types/errors/not-found.js +12 -0
- package/dist/types/pg/data-api.d.ts +17 -0
- package/dist/types/pg/data-api.js +2 -0
- package/dist/types/pg/tunnel.d.ts +22 -0
- package/dist/types/pg/tunnel.js +2 -0
- package/dist/utils/addons/resolve.d.ts +9 -0
- package/dist/utils/addons/resolve.js +39 -0
- package/dist/utils/pg/bastion.d.ts +30 -0
- package/dist/utils/pg/bastion.js +122 -0
- package/dist/utils/pg/config-vars.d.ts +8 -0
- package/dist/utils/pg/config-vars.js +34 -0
- package/dist/utils/pg/databases.d.ts +12 -0
- package/dist/utils/pg/databases.js +137 -0
- package/dist/utils/pg/host.d.ts +1 -0
- package/dist/utils/pg/host.js +7 -0
- package/dist/utils/pg/psql.d.ts +28 -0
- package/dist/utils/pg/psql.js +188 -0
- package/dist/ux/confirm.d.ts +1 -0
- package/dist/ux/confirm.js +7 -0
- package/dist/ux/prompt.d.ts +2 -0
- package/dist/ux/prompt.js +7 -0
- package/dist/ux/styled-header.d.ts +1 -0
- package/dist/ux/styled-header.js +7 -0
- package/dist/ux/styled-json.d.ts +1 -0
- package/dist/ux/styled-json.js +7 -0
- package/dist/ux/styled-object.d.ts +1 -0
- package/dist/ux/styled-object.js +7 -0
- package/dist/ux/table.d.ts +2 -0
- package/dist/ux/table.js +7 -0
- package/dist/ux/wait.d.ts +1 -0
- package/dist/ux/wait.js +7 -0
- package/package.json +54 -55
- package/index.js +0 -40
- package/lib/action.js +0 -54
- package/lib/auth.js +0 -207
- package/lib/command.js +0 -171
- package/lib/console.js +0 -105
- package/lib/date.js +0 -18
- package/lib/errors.js +0 -122
- package/lib/exit.js +0 -42
- package/lib/got.js +0 -153
- package/lib/linewrap.js +0 -783
- package/lib/mutex.js +0 -41
- package/lib/open.js +0 -22
- package/lib/preauth.js +0 -26
- package/lib/process.js +0 -14
- package/lib/prompt.js +0 -150
- package/lib/spinner.js +0 -147
- package/lib/spinners.json +0 -739
- package/lib/styled.js +0 -131
- package/lib/table.js +0 -132
- package/lib/util.js +0 -38
- package/lib/vars.js +0 -29
- package/lib/yubikey.js +0 -14
package/lib/date.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* formatDate will format a date in a standard Heroku format
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* let cli = require('heroku-cli-util')
|
|
8
|
-
* var d = new Date()
|
|
9
|
-
* cli.formatDate(d); // '2015-05-14T18:03:10.034Z'
|
|
10
|
-
*
|
|
11
|
-
* @param {Date} date the date to format
|
|
12
|
-
* @return {String} string representing the date
|
|
13
|
-
*/
|
|
14
|
-
function formatDate (date) {
|
|
15
|
-
return date.toISOString()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.formatDate = formatDate
|
package/lib/errors.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const stripAnsi = require('strip-ansi')
|
|
4
|
-
let cli = require('..')
|
|
5
|
-
let console = require('./console')
|
|
6
|
-
let linewrap = require('./linewrap')
|
|
7
|
-
let path = require('path')
|
|
8
|
-
let os = require('os')
|
|
9
|
-
|
|
10
|
-
function errtermwidth () {
|
|
11
|
-
if (global.columns) return global.columns
|
|
12
|
-
if (!process.stderr.isTTY || !process.stderr.getWindowSize) return 80
|
|
13
|
-
let width = process.stderr.getWindowSize()[0]
|
|
14
|
-
return width < 30 ? 30 : width
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function wrap (msg) {
|
|
18
|
-
return linewrap(6,
|
|
19
|
-
errtermwidth(), {
|
|
20
|
-
skipScheme: 'ansi-color',
|
|
21
|
-
skip: /^\$ .*$/
|
|
22
|
-
})(msg || '')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function bangify (msg, c) {
|
|
26
|
-
let lines = msg.split('\n')
|
|
27
|
-
for (let i = 0; i < lines.length; i++) {
|
|
28
|
-
let line = lines[i]
|
|
29
|
-
lines[i] = ' ' + c + line.substr(2, line.length)
|
|
30
|
-
}
|
|
31
|
-
return lines.join('\n')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getErrorMessage (err) {
|
|
35
|
-
if (err.body) {
|
|
36
|
-
// API error
|
|
37
|
-
if (err.body.message) {
|
|
38
|
-
return err.body.message
|
|
39
|
-
} else if (err.body.error) {
|
|
40
|
-
return err.body.error
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// Unhandled error
|
|
44
|
-
if (err.message && err.code) {
|
|
45
|
-
return `${err.code}: ${err.message}`
|
|
46
|
-
} else if (err.message) {
|
|
47
|
-
return err.message
|
|
48
|
-
}
|
|
49
|
-
return err
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let arrow = process.platform === 'win32' ? '!' : '▸'
|
|
53
|
-
|
|
54
|
-
function error (err) {
|
|
55
|
-
console.error(bangify(wrap(getErrorMessage(err)), cli.color.red(arrow)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function warn (msg) {
|
|
59
|
-
console.error(renderWarning(msg))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function renderWarning (msg) {
|
|
63
|
-
return bangify(wrap(msg), cli.color.yellow(arrow))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function logtimestamp () {
|
|
67
|
-
return new Date().toISOString()
|
|
68
|
-
.replace(/T/, ' ')
|
|
69
|
-
.replace(/-/g, '/')
|
|
70
|
-
.replace(/\..+/, '')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function cacheHome () {
|
|
74
|
-
let base
|
|
75
|
-
if (process.env.XDG_CACHE_HOME) base = process.env.XDG_CACHE_HOME
|
|
76
|
-
if (!base) {
|
|
77
|
-
if (process.platform === 'darwin') {
|
|
78
|
-
base = path.join(os.homedir(), 'Library', 'Caches')
|
|
79
|
-
} else if (process.platform === 'win32' && process.env.LOCALAPPDATA) {
|
|
80
|
-
base = process.env.LOCALAPPDATA
|
|
81
|
-
} else {
|
|
82
|
-
base = path.join(os.homedir(), '.cache')
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return path.join(base, 'heroku')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function log (msg) {
|
|
89
|
-
let fs = require('fs')
|
|
90
|
-
let logPath = path.join(cacheHome(), 'error.log')
|
|
91
|
-
fs.appendFileSync(logPath, logtimestamp() + ' ' + stripAnsi(msg) + '\n')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function errorHandler (options) {
|
|
95
|
-
options = options || {}
|
|
96
|
-
function exit () {
|
|
97
|
-
if (options.exit !== false) {
|
|
98
|
-
process.exit(1)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return function handleErr (err) {
|
|
102
|
-
if (cli.raiseErrors) throw err
|
|
103
|
-
try {
|
|
104
|
-
if (err !== '') error(err)
|
|
105
|
-
if (err.stack) {
|
|
106
|
-
log(err.stack)
|
|
107
|
-
if (options.debug) console.error(err.stack)
|
|
108
|
-
}
|
|
109
|
-
if (err.body) log(JSON.stringify(err.body))
|
|
110
|
-
exit()
|
|
111
|
-
} catch (err) {
|
|
112
|
-
console.error(err.stack)
|
|
113
|
-
process.exit(-1)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports.error = error
|
|
119
|
-
module.exports.warn = warn
|
|
120
|
-
module.exports.errorHandler = errorHandler
|
|
121
|
-
module.exports.renderWarning = renderWarning
|
|
122
|
-
module.exports.errtermwidth = errtermwidth
|
package/lib/exit.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var util = require('util')
|
|
4
|
-
var cli = require('./errors')
|
|
5
|
-
|
|
6
|
-
function ErrorExit (code, message) {
|
|
7
|
-
Error.call(this)
|
|
8
|
-
Error.captureStackTrace(this, this.constructor)
|
|
9
|
-
this.name = this.constructor.name
|
|
10
|
-
|
|
11
|
-
this.code = code
|
|
12
|
-
this.message = message
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
util.inherits(ErrorExit, Error)
|
|
16
|
-
|
|
17
|
-
var mocking
|
|
18
|
-
|
|
19
|
-
function exit (code, message) {
|
|
20
|
-
if (message) {
|
|
21
|
-
cli.error(message)
|
|
22
|
-
}
|
|
23
|
-
if (mocking) {
|
|
24
|
-
throw new ErrorExit(code, message)
|
|
25
|
-
} else {
|
|
26
|
-
process.exit(code)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
exit.mock = function (mock) {
|
|
31
|
-
if (mock === false) {
|
|
32
|
-
mocking = false
|
|
33
|
-
} else {
|
|
34
|
-
mocking = true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exit.ErrorExit = ErrorExit
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
exit
|
|
42
|
-
}
|
package/lib/got.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
let hush = require('./console').hush
|
|
4
|
-
|
|
5
|
-
function findProxy (urlParsed) {
|
|
6
|
-
let httpProxy = process.env.HTTP_PROXY || process.env.http_proxy
|
|
7
|
-
let httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy
|
|
8
|
-
|
|
9
|
-
if (urlParsed.protocol === 'https:') {
|
|
10
|
-
return httpsProxy || httpProxy
|
|
11
|
-
} else {
|
|
12
|
-
return httpProxy
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function findTunnel (urlParsed) {
|
|
17
|
-
let tunnel = require('tunnel-agent')
|
|
18
|
-
|
|
19
|
-
if (urlParsed.protocol === 'https:') {
|
|
20
|
-
return tunnel.httpsOverHttp
|
|
21
|
-
} else {
|
|
22
|
-
return tunnel.httpOverHttp
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function agent (urlParsed, proxyParsed, certs) {
|
|
27
|
-
let tunnelMethod = findTunnel(urlParsed)
|
|
28
|
-
let opts = {
|
|
29
|
-
proxy: {
|
|
30
|
-
host: proxyParsed.hostname,
|
|
31
|
-
port: proxyParsed.port || '8080'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (proxyParsed.auth) {
|
|
36
|
-
opts.proxy.proxyAuth = proxyParsed.auth
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (certs.length > 0) {
|
|
40
|
-
opts.ca = certs
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let tunnelAgent = tunnelMethod(opts)
|
|
44
|
-
if (urlParsed.protocol === 'https:') {
|
|
45
|
-
tunnelAgent.defaultPort = 443
|
|
46
|
-
}
|
|
47
|
-
return tunnelAgent
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function sslCertFile () {
|
|
51
|
-
return process.env.SSL_CERT_FILE ? [process.env.SSL_CERT_FILE] : []
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function sslCertDir () {
|
|
55
|
-
let certDir = process.env.SSL_CERT_DIR
|
|
56
|
-
if (certDir) {
|
|
57
|
-
const fs = require('fs')
|
|
58
|
-
const path = require('path')
|
|
59
|
-
return fs.readdirSync(certDir).map(f => path.join(certDir, f))
|
|
60
|
-
} else {
|
|
61
|
-
return []
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getCerts () {
|
|
66
|
-
let filenames = sslCertFile().concat(sslCertDir())
|
|
67
|
-
|
|
68
|
-
if (filenames.length > 0) {
|
|
69
|
-
hush('Adding the following trusted certificate authorities')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return filenames.map(function (filename) {
|
|
73
|
-
const fs = require('fs')
|
|
74
|
-
hush(' ' + filename)
|
|
75
|
-
return fs.readFileSync(filename)
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function addToOpts (url, opts) {
|
|
80
|
-
const urlLib = require('url')
|
|
81
|
-
|
|
82
|
-
let urlParsed = urlLib.parse(url)
|
|
83
|
-
let proxy = findProxy(urlParsed)
|
|
84
|
-
|
|
85
|
-
let certs = getCerts()
|
|
86
|
-
|
|
87
|
-
if (proxy) {
|
|
88
|
-
let proxyParsed = urlLib.parse(proxy)
|
|
89
|
-
opts = Object.assign({}, opts, { agent: agent(urlParsed, proxyParsed, certs) })
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (certs.length > 0) {
|
|
93
|
-
opts = Object.assign({}, opts, { ca: certs })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return opts
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let loadErrors
|
|
100
|
-
|
|
101
|
-
function got (url, opts) {
|
|
102
|
-
const gotDelegate = require('got')
|
|
103
|
-
loadErrors()
|
|
104
|
-
return gotDelegate(url, addToOpts(url, opts))
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
got.stream = function (url, opts) {
|
|
108
|
-
const gotDelegate = require('got')
|
|
109
|
-
loadErrors()
|
|
110
|
-
return gotDelegate.stream(url, addToOpts(url, opts))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const helpers = [
|
|
114
|
-
'get',
|
|
115
|
-
'post',
|
|
116
|
-
'put',
|
|
117
|
-
'patch',
|
|
118
|
-
'head',
|
|
119
|
-
'delete'
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
helpers.forEach(el => {
|
|
123
|
-
got[el] = (url, opts) => got(url, Object.assign({}, opts, { method: el }))
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
helpers.forEach(el => {
|
|
127
|
-
got.stream[el] = function (url, opts) {
|
|
128
|
-
return got.stream(url, Object.assign({}, opts, { method: el }))
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
loadErrors = () => {
|
|
133
|
-
const gotDelegate = require('got')
|
|
134
|
-
|
|
135
|
-
const errors = [
|
|
136
|
-
'CacheError',
|
|
137
|
-
'CancelError',
|
|
138
|
-
'UnsupportedProtocolError',
|
|
139
|
-
'HTTPError',
|
|
140
|
-
'MaxRedirectsError',
|
|
141
|
-
'ParseError',
|
|
142
|
-
'ReadError',
|
|
143
|
-
'RequestError',
|
|
144
|
-
'TimeoutError',
|
|
145
|
-
'UploadError'
|
|
146
|
-
]
|
|
147
|
-
|
|
148
|
-
errors.forEach(el => {
|
|
149
|
-
got[el] = gotDelegate[el]
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
module.exports = got
|