@jsenv/https-local 1.0.1 → 1.0.6

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,4 +1,8 @@
1
- import { assertAndNormalizeDirectoryUrl, resolveUrl, urlToFilename } from "@jsenv/filesystem"
1
+ import {
2
+ assertAndNormalizeDirectoryUrl,
3
+ resolveUrl,
4
+ urlToFilename,
5
+ } from "@jsenv/filesystem"
2
6
 
3
7
  export const getCertificateAuthorityFileUrls = () => {
4
8
  // we need a directory common to every instance of @jsenv/https-local
@@ -36,9 +40,15 @@ export const getRootCertificateSymlinkUrls = ({
36
40
  const serverCertificateDirectory = resolveUrl("./", serverCertificateFileUrl)
37
41
 
38
42
  const rootCertificateFilename = urlToFilename(rootCertificateFileUrl)
39
- const rootCertificateSymlinkUrl = resolveUrl(rootCertificateFilename, serverCertificateDirectory)
43
+ const rootCertificateSymlinkUrl = resolveUrl(
44
+ rootCertificateFilename,
45
+ serverCertificateDirectory,
46
+ )
40
47
  const rootPrivateKeyFilename = urlToFilename(rootPrivateKeyFileUrl)
41
- const rootPrivateKeySymlinkUrl = resolveUrl(rootPrivateKeyFilename, serverCertificateDirectory)
48
+ const rootPrivateKeySymlinkUrl = resolveUrl(
49
+ rootPrivateKeyFilename,
50
+ serverCertificateDirectory,
51
+ )
42
52
 
43
53
  return {
44
54
  rootCertificateSymlinkUrl,
@@ -64,12 +74,18 @@ const getJsenvApplicationDirectoryUrl = () => {
64
74
  assertAndNormalizeDirectoryUrl(process.env.XDG_CONFIG_HOME),
65
75
  )
66
76
  }
67
- return resolveUrl(`./.config/https_local/`, assertAndNormalizeDirectoryUrl(process.env.HOME))
77
+ return resolveUrl(
78
+ `./.config/https_local/`,
79
+ assertAndNormalizeDirectoryUrl(process.env.HOME),
80
+ )
68
81
  }
69
82
 
70
83
  if (platform === "win32") {
71
84
  if (process.env.LOCALAPPDATA) {
72
- return resolveUrl(`./https_local/`, assertAndNormalizeDirectoryUrl(process.env.LOCALAPPDATA))
85
+ return resolveUrl(
86
+ `./https_local/`,
87
+ assertAndNormalizeDirectoryUrl(process.env.LOCALAPPDATA),
88
+ )
73
89
  }
74
90
 
75
91
  return resolveUrl(
@@ -34,7 +34,9 @@ const isUrl = (value) => {
34
34
  }
35
35
  }
36
36
 
37
- export const extensionArrayFromExtensionDescription = (extensionDescription) => {
37
+ export const extensionArrayFromExtensionDescription = (
38
+ extensionDescription,
39
+ ) => {
38
40
  const extensionArray = []
39
41
  Object.keys(extensionDescription).forEach((key) => {
40
42
  const value = extensionDescription[key]
@@ -65,7 +67,9 @@ export const attributeDescriptionFromAttributeArray = (attributeArray) => {
65
67
  return attributeObject
66
68
  }
67
69
 
68
- export const attributeArrayFromAttributeDescription = (attributeDescription) => {
70
+ export const attributeArrayFromAttributeDescription = (
71
+ attributeDescription,
72
+ ) => {
69
73
  const attributeArray = []
70
74
  Object.keys(attributeDescription).forEach((key) => {
71
75
  const value = attributeDescription[key]
@@ -33,7 +33,9 @@ export const createAuthorityRootCertificate = async ({
33
33
  rootCertificateForgeObject.publicKey = rootCertificatePublicKeyForgeObject
34
34
  rootCertificateForgeObject.serialNumber = serialNumber.toString(16)
35
35
  rootCertificateForgeObject.validity.notBefore = new Date()
36
- rootCertificateForgeObject.validity.notAfter = new Date(Date.now() + validityDurationInMs)
36
+ rootCertificateForgeObject.validity.notAfter = new Date(
37
+ Date.now() + validityDurationInMs,
38
+ )
37
39
  rootCertificateForgeObject.setSubject(
38
40
  attributeArrayFromAttributeDescription({
39
41
  commonName,
@@ -109,7 +111,9 @@ export const requestCertificateFromAuthority = async ({
109
111
  )
110
112
  }
111
113
  if (typeof serialNumber !== "number") {
112
- throw new TypeError(`serialNumber must be a number but received ${serialNumber}`)
114
+ throw new TypeError(
115
+ `serialNumber must be a number but received ${serialNumber}`,
116
+ )
113
117
  }
114
118
 
115
119
  const forge = await importNodeForge()
@@ -122,16 +126,23 @@ export const requestCertificateFromAuthority = async ({
122
126
  certificateForgeObject.publicKey = certificatePublicKeyForgeObject
123
127
  certificateForgeObject.serialNumber = serialNumber.toString(16)
124
128
  certificateForgeObject.validity.notBefore = new Date()
125
- certificateForgeObject.validity.notAfter = new Date(Date.now() + validityDurationInMs)
129
+ certificateForgeObject.validity.notAfter = new Date(
130
+ Date.now() + validityDurationInMs,
131
+ )
126
132
 
127
133
  const attributeDescription = {
128
- ...attributeDescriptionFromAttributeArray(authorityCertificateForgeObject.subject.attributes),
134
+ ...attributeDescriptionFromAttributeArray(
135
+ authorityCertificateForgeObject.subject.attributes,
136
+ ),
129
137
  commonName,
130
138
  // organizationName: serverCertificateOrganizationName
131
139
  }
132
- const attributeArray = attributeArrayFromAttributeDescription(attributeDescription)
140
+ const attributeArray =
141
+ attributeArrayFromAttributeDescription(attributeDescription)
133
142
  certificateForgeObject.setSubject(attributeArray)
134
- certificateForgeObject.setIssuer(authorityCertificateForgeObject.subject.attributes)
143
+ certificateForgeObject.setIssuer(
144
+ authorityCertificateForgeObject.subject.attributes,
145
+ )
135
146
  certificateForgeObject.setExtensions(
136
147
  extensionArrayFromExtensionDescription({
137
148
  basicConstraints: {
@@ -159,7 +170,10 @@ export const requestCertificateFromAuthority = async ({
159
170
  },
160
171
  }),
161
172
  )
162
- certificateForgeObject.sign(auhtorityCertificatePrivateKeyForgeObject, forge.sha256.create())
173
+ certificateForgeObject.sign(
174
+ auhtorityCertificatePrivateKeyForgeObject,
175
+ forge.sha256.create(),
176
+ )
163
177
 
164
178
  return {
165
179
  certificateForgeObject,
@@ -4,5 +4,6 @@ const require = createRequire(import.meta.url)
4
4
 
5
5
  export const commandExists = async (command) => {
6
6
  const { sync } = require("command-exists")
7
- return sync(command)
7
+ const exists = sync(command)
8
+ return exists
8
9
  }
@@ -1,6 +1,9 @@
1
1
  import { exec as nodeExec } from "node:child_process"
2
2
 
3
- export const exec = (command, { cwd, input, onLog = () => {}, onErrorLog = () => {} } = {}) => {
3
+ export const exec = (
4
+ command,
5
+ { cwd, input, onLog = () => {}, onErrorLog = () => {} } = {},
6
+ ) => {
4
7
  return new Promise((resolve, reject) => {
5
8
  const commandProcess = nodeExec(
6
9
  command,
@@ -1,7 +1,10 @@
1
1
  const IS_WINDOWS = process.platform === "win32"
2
2
 
3
3
  // https://github.com/feross/hostile/blob/master/index.js
4
- export const parseHosts = (hosts, { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {}) => {
4
+ export const parseHosts = (
5
+ hosts,
6
+ { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {},
7
+ ) => {
5
8
  const lines = []
6
9
  hosts.split(/\r?\n/).forEach((line) => {
7
10
  const lineWithoutComments = line.replace(/#.*/, "")
@@ -22,7 +25,9 @@ export const parseHosts = (hosts, { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {}) =>
22
25
  if (line.type === "rule") {
23
26
  const { ip, hostnames } = line
24
27
  const existingHostnames = ipHostnames[ip]
25
- ipHostnames[ip] = existingHostnames ? [...existingHostnames, ...hostnames] : hostnames
28
+ ipHostnames[ip] = existingHostnames
29
+ ? [...existingHostnames, ...hostnames]
30
+ : hostnames
26
31
  }
27
32
  })
28
33
  return ipHostnames
@@ -40,7 +45,8 @@ export const parseHosts = (hosts, { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {}) =>
40
45
 
41
46
  const addIpHostname = (ip, host) => {
42
47
  const alreadyThere = lines.some(
43
- (line) => line.type === "rule" && line.ip === ip && line.hostnames.includes(host),
48
+ (line) =>
49
+ line.type === "rule" && line.ip === ip && line.hostnames.includes(host),
44
50
  )
45
51
  if (alreadyThere) {
46
52
  return false
@@ -96,7 +102,9 @@ export const parseHosts = (hosts, { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {}) =>
96
102
 
97
103
  const asFileContent = () => {
98
104
  let hostsFileContent = ""
99
- const ips = lines.filter((line) => line.type === "rule").map((line) => line.ip)
105
+ const ips = lines
106
+ .filter((line) => line.type === "rule")
107
+ .map((line) => line.ip)
100
108
  const longestIp = ips.reduce((previous, ip) => {
101
109
  const length = ip.length
102
110
  return length > previous ? length : previous
@@ -107,7 +115,9 @@ export const parseHosts = (hosts, { EOL = IS_WINDOWS ? "\r\n" : "\n" } = {}) =>
107
115
  const { ip, hostnames } = line
108
116
  const ipLength = ip.length
109
117
  const lengthDelta = longestIp - ipLength
110
- hostsFileContent += `${ip}${" ".repeat(lengthDelta)} ${hostnames.join(" ")}`
118
+ hostsFileContent += `${ip}${" ".repeat(lengthDelta)} ${hostnames.join(
119
+ " ",
120
+ )}`
111
121
  } else {
112
122
  hostsFileContent += line.value
113
123
  }
@@ -9,9 +9,17 @@ export const writeHostsFile = async (
9
9
  { hostsFilePath = HOSTS_FILE_PATH, onBeforeExecCommand = () => {} } = {},
10
10
  ) => {
11
11
  if (process.platform === "win32") {
12
- return writeHostsFileOnWindows({ hostsFileContent, hostsFilePath, onBeforeExecCommand })
12
+ return writeHostsFileOnWindows({
13
+ hostsFileContent,
14
+ hostsFilePath,
15
+ onBeforeExecCommand,
16
+ })
13
17
  }
14
- return writeHostsFileOnLinuxOrMac({ hostsFileContent, hostsFilePath, onBeforeExecCommand })
18
+ return writeHostsFileOnLinuxOrMac({
19
+ hostsFileContent,
20
+ hostsFilePath,
21
+ onBeforeExecCommand,
22
+ })
15
23
  }
16
24
 
17
25
  const writeHostsFileOnLinuxOrMac = async ({
@@ -42,15 +50,19 @@ const writeHostsFileOnWindows = async ({
42
50
  const sudoPrompt = require("sudo-prompt")
43
51
  onBeforeExecCommand(updateHostsFileCommand)
44
52
  await new Promise((resolve, reject) => {
45
- sudoPrompt.exec(updateHostsFileCommand, { name: "write hosts" }, (error, stdout, stderr) => {
46
- if (error) {
47
- reject(error)
48
- } else if (typeof stderr === "string" && stderr.trim().length > 0) {
49
- reject(stderr)
50
- } else {
51
- resolve(stdout)
52
- }
53
- })
53
+ sudoPrompt.exec(
54
+ updateHostsFileCommand,
55
+ { name: "write hosts" },
56
+ (error, stdout, stderr) => {
57
+ if (error) {
58
+ reject(error)
59
+ } else if (typeof stderr === "string" && stderr.trim().length > 0) {
60
+ reject(stderr)
61
+ } else {
62
+ resolve(stdout)
63
+ }
64
+ },
65
+ )
54
66
  })
55
67
  return
56
68
  }
@@ -10,13 +10,25 @@ export const writeLineInHostsFile = async (
10
10
  { hostsFilePath = HOSTS_FILE_PATH, onBeforeExecCommand = () => {} } = {},
11
11
  ) => {
12
12
  if (process.platform === "win32") {
13
- return appendToHostsFileOnWindows({ lineToAppend, hostsFilePath, onBeforeExecCommand })
13
+ return appendToHostsFileOnWindows({
14
+ lineToAppend,
15
+ hostsFilePath,
16
+ onBeforeExecCommand,
17
+ })
14
18
  }
15
- return appendToHostsFileOnLinuxOrMac({ lineToAppend, hostsFilePath, onBeforeExecCommand })
19
+ return appendToHostsFileOnLinuxOrMac({
20
+ lineToAppend,
21
+ hostsFilePath,
22
+ onBeforeExecCommand,
23
+ })
16
24
  }
17
25
 
18
26
  // https://renenyffenegger.ch/notes/Windows/dirs/Windows/System32/cmd_exe/commands/echo/index
19
- const appendToHostsFileOnWindows = async ({ lineToAppend, hostsFilePath, onBeforeExecCommand }) => {
27
+ const appendToHostsFileOnWindows = async ({
28
+ lineToAppend,
29
+ hostsFilePath,
30
+ onBeforeExecCommand,
31
+ }) => {
20
32
  const hostsFileContent = await readFile(hostsFilePath)
21
33
  const echoCommand =
22
34
  hostsFileContent.length > 0 && !hostsFileContent.endsWith("\r\n")
@@ -30,15 +42,19 @@ const appendToHostsFileOnWindows = async ({ lineToAppend, hostsFilePath, onBefor
30
42
  const sudoPrompt = require("sudo-prompt")
31
43
  onBeforeExecCommand(updateHostsFileCommand)
32
44
  await new Promise((resolve, reject) => {
33
- sudoPrompt.exec(updateHostsFileCommand, { name: "append hosts" }, (error, stdout, stderr) => {
34
- if (error) {
35
- reject(error)
36
- } else if (typeof stderr === "string" && stderr.trim().length > 0) {
37
- reject(stderr)
38
- } else {
39
- resolve(stdout)
40
- }
41
- })
45
+ sudoPrompt.exec(
46
+ updateHostsFileCommand,
47
+ { name: "append hosts" },
48
+ (error, stdout, stderr) => {
49
+ if (error) {
50
+ reject(error)
51
+ } else if (typeof stderr === "string" && stderr.trim().length > 0) {
52
+ reject(stderr)
53
+ } else {
54
+ resolve(stdout)
55
+ }
56
+ },
57
+ )
42
58
  })
43
59
  return
44
60
  }
@@ -2,7 +2,11 @@ import { existsSync } from "node:fs"
2
2
  import { execSync } from "node:child_process"
3
3
  import { resolveUrl, assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
4
 
5
- import { okSign, infoSign, warningSign } from "@jsenv/https-local/src/internal/logs.js"
5
+ import {
6
+ okSign,
7
+ infoSign,
8
+ warningSign,
9
+ } from "@jsenv/https-local/src/internal/logs.js"
6
10
  import {
7
11
  nssCommandName,
8
12
  detectIfNSSIsInstalled,
@@ -57,7 +61,9 @@ export const executeTrustQueryOnChrome = ({
57
61
  return
58
62
  }
59
63
 
60
- logger.warn(`${warningSign} waiting for you to close Chrome before resuming...`)
64
+ logger.warn(
65
+ `${warningSign} waiting for you to close Chrome before resuming...`,
66
+ )
61
67
  const next = async () => {
62
68
  await new Promise((resolve) => setTimeout(resolve, 50))
63
69
  if (isChromeOpen()) {
@@ -2,7 +2,11 @@ import { existsSync } from "node:fs"
2
2
  import { execSync } from "node:child_process"
3
3
  import { resolveUrl, assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
4
 
5
- import { okSign, infoSign, warningSign } from "@jsenv/https-local/src/internal/logs.js"
5
+ import {
6
+ okSign,
7
+ infoSign,
8
+ warningSign,
9
+ } from "@jsenv/https-local/src/internal/logs.js"
6
10
  import {
7
11
  nssCommandName,
8
12
  detectIfNSSIsInstalled,
@@ -57,7 +61,9 @@ export const executeTrustQueryOnFirefox = ({
57
61
  return
58
62
  }
59
63
 
60
- logger.warn(`${warningSign} waiting for you to close Firefox before resuming...`)
64
+ logger.warn(
65
+ `${warningSign} waiting for you to close Firefox before resuming...`,
66
+ )
61
67
  const next = async () => {
62
68
  await new Promise((resolve) => setTimeout(resolve, 50))
63
69
  if (isFirefoxOpen()) {
@@ -6,18 +6,31 @@ import { existsSync } from "node:fs"
6
6
  import { createDetailedMessage } from "@jsenv/logger"
7
7
  import { readFile, urlToFileSystemPath } from "@jsenv/filesystem"
8
8
 
9
- import { commandSign, okSign, infoSign, failureSign } from "@jsenv/https-local/src/internal/logs.js"
9
+ import {
10
+ commandSign,
11
+ okSign,
12
+ infoSign,
13
+ failureSign,
14
+ } from "@jsenv/https-local/src/internal/logs.js"
10
15
  import { exec } from "@jsenv/https-local/src/internal/exec.js"
11
- import { VERB_CHECK_TRUST, VERB_ADD_TRUST, VERB_REMOVE_TRUST } from "../trust_query.js"
16
+ import {
17
+ VERB_CHECK_TRUST,
18
+ VERB_ADD_TRUST,
19
+ VERB_REMOVE_TRUST,
20
+ } from "../trust_query.js"
12
21
 
13
- const REASON_NEW_AND_TRY_TO_TRUST_DISABLED = "certificate is new and tryToTrust is disabled"
22
+ const REASON_NEW_AND_TRY_TO_TRUST_DISABLED =
23
+ "certificate is new and tryToTrust is disabled"
14
24
  const REASON_NOT_FOUND_IN_LINUX = `not found in linux store`
15
25
  const REASON_OUTDATED_IN_LINUX = "certificate in linux store is outdated"
16
26
  const REASON_FOUND_IN_LINUX = "found in linux store"
17
27
  const REASON_ADD_COMMAND_FAILED = "command to add certificate to linux failed"
18
- const REASON_ADD_COMMAND_COMPLETED = "command to add certificate to linux completed"
19
- const REASON_REMOVE_COMMAND_FAILED = "command to remove certificate from linux failed"
20
- const REASON_REMOVE_COMMAND_COMPLETED = "command to remove certificate from linux completed"
28
+ const REASON_ADD_COMMAND_COMPLETED =
29
+ "command to add certificate to linux completed"
30
+ const REASON_REMOVE_COMMAND_FAILED =
31
+ "command to remove certificate from linux failed"
32
+ const REASON_REMOVE_COMMAND_COMPLETED =
33
+ "command to remove certificate from linux completed"
21
34
 
22
35
  const LINUX_CERTIFICATE_AUTHORITIES_DIRECTORY_PATH = `/usr/local/share/ca-certificates/`
23
36
  const JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH = `${LINUX_CERTIFICATE_AUTHORITIES_DIRECTORY_PATH}https_local_root_certificate.crt`
@@ -39,7 +52,9 @@ export const executeTrustQueryOnLinux = async ({
39
52
  }
40
53
 
41
54
  logger.info(`Check if certificate is in linux...`)
42
- logger.debug(`Searching certificate file at ${JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH}...`)
55
+ logger.debug(
56
+ `Searching certificate file at ${JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH}...`,
57
+ )
43
58
  const certificateFilePath = urlToFileSystemPath(certificateFileUrl)
44
59
  const certificateStatus = await getCertificateStatus({ certificate })
45
60
 
@@ -53,7 +68,9 @@ export const executeTrustQueryOnLinux = async ({
53
68
  return {
54
69
  status: "not_trusted",
55
70
  reason:
56
- certificateStatus === "missing" ? REASON_NOT_FOUND_IN_LINUX : REASON_OUTDATED_IN_LINUX,
71
+ certificateStatus === "missing"
72
+ ? REASON_NOT_FOUND_IN_LINUX
73
+ : REASON_OUTDATED_IN_LINUX,
57
74
  }
58
75
  }
59
76
 
@@ -73,9 +90,12 @@ export const executeTrustQueryOnLinux = async ({
73
90
  } catch (e) {
74
91
  console.error(e)
75
92
  logger.error(
76
- createDetailedMessage(`${failureSign} failed to add certificate to linux`, {
77
- "certificate file": certificateFilePath,
78
- }),
93
+ createDetailedMessage(
94
+ `${failureSign} failed to add certificate to linux`,
95
+ {
96
+ "certificate file": certificateFilePath,
97
+ },
98
+ ),
79
99
  )
80
100
  return {
81
101
  status: "not_trusted",
@@ -107,10 +127,13 @@ export const executeTrustQueryOnLinux = async ({
107
127
  }
108
128
  } catch (e) {
109
129
  logger.error(
110
- createDetailedMessage(`${failureSign} failed to remove certificate from linux`, {
111
- "error stack": e.stack,
112
- "certificate file": JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH,
113
- }),
130
+ createDetailedMessage(
131
+ `${failureSign} failed to remove certificate from linux`,
132
+ {
133
+ "error stack": e.stack,
134
+ "certificate file": JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH,
135
+ },
136
+ ),
114
137
  )
115
138
  return {
116
139
  status: "unknown",
@@ -124,7 +147,9 @@ const getCertificateStatus = async ({ certificate }) => {
124
147
  if (!certificateInStore) {
125
148
  return "missing"
126
149
  }
127
- const certificateInLinuxStore = await readFile(JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH)
150
+ const certificateInLinuxStore = await readFile(
151
+ JSENV_AUTHORITY_ROOT_CERTIFICATE_PATH,
152
+ )
128
153
  if (certificateInLinuxStore !== certificate) {
129
154
  return "outdated"
130
155
  }
@@ -1,5 +1,9 @@
1
1
  import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
2
- import { commandSign, infoSign, okSign } from "@jsenv/https-local/src/internal/logs.js"
2
+ import {
3
+ commandSign,
4
+ infoSign,
5
+ okSign,
6
+ } from "@jsenv/https-local/src/internal/logs.js"
3
7
  import { exec } from "@jsenv/https-local/src/internal/exec.js"
4
8
 
5
9
  export const nssCommandName = "libnss3-tools"
@@ -24,10 +28,12 @@ export const getCertutilBinPath = () => "certutil"
24
28
 
25
29
  export const getNSSDynamicInstallInfo = ({ logger }) => {
26
30
  return {
27
- nssIsInstallable: true,
28
- nssInstall: async () => {
31
+ isInstallable: true,
32
+ install: async () => {
29
33
  const aptInstallCommand = `sudo apt install libnss3-tools`
30
- logger.info(`"libnss3-tools" is not installed, trying to install "libnss3-tools"`)
34
+ logger.info(
35
+ `"libnss3-tools" is not installed, trying to install "libnss3-tools"`,
36
+ )
31
37
  logger.info(`${commandSign} ${aptInstallCommand}`)
32
38
  await exec(aptInstallCommand)
33
39
  },
@@ -2,7 +2,11 @@ import { existsSync } from "node:fs"
2
2
  import { execSync } from "node:child_process"
3
3
  import { resolveUrl, assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
4
 
5
- import { okSign, infoSign, warningSign } from "@jsenv/https-local/src/internal/logs.js"
5
+ import {
6
+ okSign,
7
+ infoSign,
8
+ warningSign,
9
+ } from "@jsenv/https-local/src/internal/logs.js"
6
10
 
7
11
  import { executeTrustQueryOnBrowserNSSDB } from "../nssdb_browser.js"
8
12
  import {
@@ -57,7 +61,9 @@ export const executeTrustQueryOnFirefox = ({
57
61
  return
58
62
  }
59
63
 
60
- logger.warn(`${warningSign} waiting for you to close firefox before resuming...`)
64
+ logger.warn(
65
+ `${warningSign} waiting for you to close firefox before resuming...`,
66
+ )
61
67
  const next = async () => {
62
68
  await new Promise((resolve) => setTimeout(resolve, 50))
63
69
  if (isFirefoxOpen()) {
@@ -3,15 +3,26 @@
3
3
  import { urlToFileSystemPath } from "@jsenv/filesystem"
4
4
  import { createDetailedMessage } from "@jsenv/logger"
5
5
 
6
- import { commandSign, okSign, infoSign, failureSign } from "@jsenv/https-local/src/internal/logs.js"
6
+ import {
7
+ commandSign,
8
+ okSign,
9
+ infoSign,
10
+ failureSign,
11
+ } from "@jsenv/https-local/src/internal/logs.js"
7
12
  import { exec } from "@jsenv/https-local/src/internal/exec.js"
8
13
  import { searchCertificateInCommandOutput } from "@jsenv/https-local/src/internal/search_certificate_in_command_output.js"
9
- import { VERB_CHECK_TRUST, VERB_ADD_TRUST, VERB_REMOVE_TRUST } from "../trust_query.js"
14
+ import {
15
+ VERB_CHECK_TRUST,
16
+ VERB_ADD_TRUST,
17
+ VERB_REMOVE_TRUST,
18
+ } from "../trust_query.js"
10
19
 
11
- const REASON_NEW_AND_TRY_TO_TRUST_DISABLED = "certificate is new and tryToTrust is disabled"
20
+ const REASON_NEW_AND_TRY_TO_TRUST_DISABLED =
21
+ "certificate is new and tryToTrust is disabled"
12
22
  const REASON_NOT_IN_KEYCHAIN = "certificate not found in mac keychain"
13
23
  const REASON_IN_KEYCHAIN = "certificate found in mac keychain"
14
- const REASON_ADD_TO_KEYCHAIN_COMMAND_FAILED = "command to add certificate in mac keychain failed"
24
+ const REASON_ADD_TO_KEYCHAIN_COMMAND_FAILED =
25
+ "command to add certificate in mac keychain failed"
15
26
  const REASON_ADD_TO_KEYCHAIN_COMMAND_COMPLETED =
16
27
  "command to add certificate in mac keychain completed"
17
28
  const REASON_REMOVE_FROM_KEYCHAIN_COMMAND_FAILED =
@@ -70,10 +81,13 @@ export const executeTrustQueryOnMacKeychain = async ({
70
81
  }
71
82
  } catch (e) {
72
83
  logger.error(
73
- createDetailedMessage(`${failureSign} failed to add certificate to mac keychain`, {
74
- "error stack": e.stack,
75
- "certificate file": certificateFilePath,
76
- }),
84
+ createDetailedMessage(
85
+ `${failureSign} failed to add certificate to mac keychain`,
86
+ {
87
+ "error stack": e.stack,
88
+ "certificate file": certificateFilePath,
89
+ },
90
+ ),
77
91
  )
78
92
  return {
79
93
  status: "not_trusted",
@@ -107,10 +121,13 @@ export const executeTrustQueryOnMacKeychain = async ({
107
121
  }
108
122
  } catch (e) {
109
123
  logger.error(
110
- createDetailedMessage(`${failureSign} failed to remove certificate from mac keychain`, {
111
- "error stack": e.stack,
112
- "certificate file url": certificateFileUrl,
113
- }),
124
+ createDetailedMessage(
125
+ `${failureSign} failed to remove certificate from mac keychain`,
126
+ {
127
+ "error stack": e.stack,
128
+ "certificate file url": certificateFileUrl,
129
+ },
130
+ ),
114
131
  )
115
132
  return {
116
133
  status: "not_trusted",
@@ -1,4 +1,8 @@
1
- import { assertAndNormalizeDirectoryUrl, resolveUrl, urlToFileSystemPath } from "@jsenv/filesystem"
1
+ import {
2
+ assertAndNormalizeDirectoryUrl,
3
+ resolveUrl,
4
+ urlToFileSystemPath,
5
+ } from "@jsenv/filesystem"
2
6
 
3
7
  import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
4
8
  import { exec } from "@jsenv/https-local/src/internal/exec.js"
@@ -24,7 +28,9 @@ export const detectIfNSSIsInstalled = async ({ logger }) => {
24
28
  export const getCertutilBinPath = memoize(async () => {
25
29
  const brewCommand = `brew --prefix nss`
26
30
  const brewCommandOutput = await exec(brewCommand)
27
- const nssCommandDirectoryUrl = assertAndNormalizeDirectoryUrl(brewCommandOutput.trim())
31
+ const nssCommandDirectoryUrl = assertAndNormalizeDirectoryUrl(
32
+ brewCommandOutput.trim(),
33
+ )
28
34
  const certutilBinUrl = resolveUrl(`./bin/certutil`, nssCommandDirectoryUrl)
29
35
  const certutilBinPath = urlToFileSystemPath(certutilBinUrl)
30
36
  return certutilBinPath
@@ -33,11 +39,13 @@ export const getCertutilBinPath = memoize(async () => {
33
39
  export const getNSSDynamicInstallInfo = () => {
34
40
  return {
35
41
  isInstallable: commandExists("brew"),
36
- nssNotInstallableReason: `"brew" is not available`,
37
- nssInstallFixSuggestion: `install "brew" on this mac`,
38
- installNss: async ({ logger }) => {
42
+ notInstallableReason: `"brew" is not available`,
43
+ suggestion: `install "brew" on this mac`,
44
+ install: async ({ logger }) => {
39
45
  const brewInstallCommand = `brew install nss`
40
- logger.info(`"nss" is not installed, trying to install "nss" via Homebrew`)
46
+ logger.info(
47
+ `"nss" is not installed, trying to install "nss" via Homebrew`,
48
+ )
41
49
  logger.info(`> ${brewInstallCommand}`)
42
50
  await exec(brewInstallCommand)
43
51
  },