@small-tech/auto-encrypt 2.3.0 → 3.1.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/README.md +8 -10
- package/index.js +34 -37
- package/lib/Account.js +4 -6
- package/lib/AcmeRequest.js +29 -32
- package/lib/Authorisation.js +7 -9
- package/lib/Certificate.js +20 -26
- package/lib/Configuration.js +16 -11
- package/lib/Directory.js +24 -26
- package/lib/HttpServer.js +5 -7
- package/lib/Identity.js +6 -8
- package/lib/LetsEncryptServer.js +2 -4
- package/lib/Nonce.js +4 -6
- package/lib/Order.js +15 -17
- package/lib/acme-requests/AuthorisationRequest.js +3 -5
- package/lib/acme-requests/CertificateRequest.js +3 -5
- package/lib/acme-requests/CheckOrderStatusRequest.js +3 -5
- package/lib/acme-requests/FinaliseOrderRequest.js +3 -5
- package/lib/acme-requests/NewAccountRequest.js +2 -4
- package/lib/acme-requests/NewOrderRequest.js +3 -5
- package/lib/acme-requests/ReadyForChallengeValidationRequest.js +3 -5
- package/lib/acmeCsr.js +2 -2
- package/lib/identities/AccountIdentity.js +3 -5
- package/lib/identities/CertificateIdentity.js +3 -5
- package/lib/staging/monkeyPatchTls.js +7 -6
- package/lib/test-helpers/index.js +31 -39
- package/lib/util/Pluralise.js +1 -3
- package/lib/util/Throws.js +3 -7
- package/lib/util/async-foreach.js +1 -3
- package/lib/util/log.js +1 -3
- package/lib/util/waitFor.js +1 -3
- package/lib/x.509/rfc5280.js +84 -171
- package/package.json +20 -19
- package/typedefs/lib/AcmeRequest.js +1 -1
package/lib/HttpServer.js
CHANGED
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
//
|
|
26
26
|
////////////////////////////////////////////////////////////////////////////////
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
import http from 'http'
|
|
29
|
+
import encodeUrl from 'encodeurl'
|
|
30
|
+
import enableDestroy from 'server-destroy'
|
|
31
|
+
import log from './util/log.js'
|
|
32
32
|
|
|
33
|
-
class HttpServer {
|
|
33
|
+
export default class HttpServer {
|
|
34
34
|
//
|
|
35
35
|
// Singleton access (async).
|
|
36
36
|
//
|
|
@@ -169,5 +169,3 @@ class HttpServer {
|
|
|
169
169
|
})
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
module.exports = HttpServer
|
package/lib/Identity.js
CHANGED
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
//
|
|
15
15
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
import util from 'util'
|
|
18
|
+
import fs from 'fs'
|
|
19
|
+
import jose from 'jose'
|
|
20
|
+
import Throws from './util/Throws.js'
|
|
21
|
+
import log from './util/log.js'
|
|
22
22
|
|
|
23
23
|
const throws = new Throws({
|
|
24
24
|
[Symbol.for('UnsupportedIdentityType')]: identityFilePath => `The identity file path passed (${identityFilePath}) is for an unsupported identity type.`
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
class Identity {
|
|
27
|
+
export default class Identity {
|
|
28
28
|
|
|
29
29
|
constructor (configuration = throws.ifMissing(), identityFilePathKey = throws.ifMissing()) {
|
|
30
30
|
const identityFilePath = configuration[identityFilePathKey]
|
|
@@ -109,5 +109,3 @@ class Identity {
|
|
|
109
109
|
//
|
|
110
110
|
#identityFilePath = null
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
module.exports = Identity
|
package/lib/LetsEncryptServer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import util from 'util'
|
|
2
2
|
|
|
3
|
-
class LetsEncryptServer {
|
|
3
|
+
export default class LetsEncryptServer {
|
|
4
4
|
/**
|
|
5
5
|
* Enumeration.
|
|
6
6
|
*
|
|
@@ -54,5 +54,3 @@ class LetsEncryptServer {
|
|
|
54
54
|
'http://localhost:9829/directory'
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = LetsEncryptServer
|
package/lib/Nonce.js
CHANGED
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
//
|
|
21
21
|
////////////////////////////////////////////////////////////////////////////////
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
import prepareRequest from 'bent'
|
|
24
|
+
import log from './util/log.js'
|
|
25
|
+
import Throws from './util/Throws.js'
|
|
26
26
|
|
|
27
27
|
const throws = new Throws()
|
|
28
28
|
|
|
29
|
-
class Nonce {
|
|
29
|
+
export default class Nonce {
|
|
30
30
|
constructor (directory = throws.ifMissing()) {
|
|
31
31
|
this.#directory = directory
|
|
32
32
|
}
|
|
@@ -73,5 +73,3 @@ class Nonce {
|
|
|
73
73
|
#directory = null
|
|
74
74
|
#freshNonce = null
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
module.exports = Nonce
|
package/lib/Order.js
CHANGED
|
@@ -12,23 +12,23 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
import fsPromises from 'fs/promises'
|
|
16
|
+
import Authorisation from './Authorisation.js'
|
|
17
|
+
import HttpServer from './HttpServer.js'
|
|
18
|
+
import CertificateIdentity from './identities/CertificateIdentity.js'
|
|
19
|
+
import acmeCsr from './acmeCsr.js'
|
|
20
|
+
import asyncForEach from './util/async-foreach.js'
|
|
21
|
+
import log from './util/log.js'
|
|
22
|
+
import NewOrderRequest from './acme-requests/NewOrderRequest.js'
|
|
23
|
+
import FinaliseOrderRequest from './acme-requests/FinaliseOrderRequest.js'
|
|
24
|
+
import CheckOrderStatusRequest from './acme-requests/CheckOrderStatusRequest.js'
|
|
25
|
+
import CertificateRequest from './acme-requests/CertificateRequest.js'
|
|
26
|
+
import Throws from './util/Throws.js'
|
|
27
|
+
import waitFor from './util/waitFor.js'
|
|
28
28
|
|
|
29
29
|
const throws = new Throws()
|
|
30
30
|
|
|
31
|
-
class Order {
|
|
31
|
+
export default class Order {
|
|
32
32
|
#data = null
|
|
33
33
|
#headers = null
|
|
34
34
|
#order = null
|
|
@@ -193,7 +193,7 @@ class Order {
|
|
|
193
193
|
|
|
194
194
|
// Save the certificate.
|
|
195
195
|
try {
|
|
196
|
-
await
|
|
196
|
+
await fsPromises.writeFile(this.configuration.certificatePath, this.certificate, 'utf-8')
|
|
197
197
|
} catch (error) {
|
|
198
198
|
throw new Error(error)
|
|
199
199
|
}
|
|
@@ -214,5 +214,3 @@ class Order {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
module.exports = Order
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
//
|
|
12
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
15
|
+
import Throws from '../util/Throws.js'
|
|
16
16
|
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
class AuthorisationRequest extends AcmeRequest {
|
|
19
|
+
export default class AuthorisationRequest extends AcmeRequest {
|
|
20
20
|
async execute (authorisationUrl = throws.ifMissing()) {
|
|
21
21
|
// This is a POST-as-GET request so it doesn’t have a payload.
|
|
22
22
|
// See RFC 8555 § 6.3 (GET and POST-as-GET requests).
|
|
@@ -34,5 +34,3 @@ class AuthorisationRequest extends AcmeRequest {
|
|
|
34
34
|
return response
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
module.exports = AuthorisationRequest
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
16
|
+
import Throws from '../util/Throws.js'
|
|
17
17
|
|
|
18
18
|
const throws = new Throws()
|
|
19
19
|
|
|
20
|
-
class CertificateRequest extends AcmeRequest {
|
|
20
|
+
export default class CertificateRequest extends AcmeRequest {
|
|
21
21
|
async execute (certificateUrl = throws.ifMissing()) {
|
|
22
22
|
// This is a POST-as-GET request so it doesn’t have a payload.
|
|
23
23
|
// See RFC 8555 § 6.3 (GET and POST-as-GET requests).
|
|
@@ -37,5 +37,3 @@ class CertificateRequest extends AcmeRequest {
|
|
|
37
37
|
return response
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
module.exports = CertificateRequest
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
//
|
|
15
15
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
18
|
+
import Throws from '../util/Throws.js'
|
|
19
19
|
|
|
20
20
|
const throws = new Throws()
|
|
21
21
|
|
|
22
|
-
class CheckOrderStatusRequest extends AcmeRequest {
|
|
22
|
+
export default class CheckOrderStatusRequest extends AcmeRequest {
|
|
23
23
|
async execute (orderUrl = throws.ifMissing()) {
|
|
24
24
|
|
|
25
25
|
const payload = '' // POST-as-GET
|
|
@@ -35,5 +35,3 @@ class CheckOrderStatusRequest extends AcmeRequest {
|
|
|
35
35
|
return response
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
module.exports = CheckOrderStatusRequest
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
//
|
|
12
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
15
|
+
import Throws from '../util/Throws.js'
|
|
16
16
|
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
class FinaliseOrderRequest extends AcmeRequest {
|
|
19
|
+
export default class FinaliseOrderRequest extends AcmeRequest {
|
|
20
20
|
async execute (finaliseUrl = throws.ifMissing(), csr = throws.ifMissing()) {
|
|
21
21
|
|
|
22
22
|
const payload = { csr }
|
|
@@ -32,5 +32,3 @@ class FinaliseOrderRequest extends AcmeRequest {
|
|
|
32
32
|
return response
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
module.exports = FinaliseOrderRequest
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
16
16
|
|
|
17
|
-
class NewAccountRequest extends AcmeRequest {
|
|
17
|
+
export default class NewAccountRequest extends AcmeRequest {
|
|
18
18
|
async execute () {
|
|
19
19
|
// Set the only required element.
|
|
20
20
|
const payload = { termsOfServiceAgreed: true }
|
|
@@ -30,5 +30,3 @@ class NewAccountRequest extends AcmeRequest {
|
|
|
30
30
|
return account
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
module.exports = NewAccountRequest
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
16
|
+
import Throws from '../util/Throws.js'
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
class NewOrderRequest extends AcmeRequest {
|
|
19
|
+
export default class NewOrderRequest extends AcmeRequest {
|
|
20
20
|
async execute (configuration = throws.ifMissing()) {
|
|
21
21
|
const identifiers = configuration.domains.map(domain => { return { type: 'dns', value: domain} })
|
|
22
22
|
const payload = { identifiers }
|
|
@@ -25,5 +25,3 @@ class NewOrderRequest extends AcmeRequest {
|
|
|
25
25
|
return response
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
module.exports = NewOrderRequest
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
//
|
|
14
14
|
////////////////////////////////////////////////////////////////////////////////
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
import AcmeRequest from '../AcmeRequest.js'
|
|
17
|
+
import Throws from '../util/Throws.js'
|
|
18
18
|
|
|
19
19
|
const throws = new Throws()
|
|
20
20
|
|
|
21
|
-
class ReadyForChallengeValidationRequest extends AcmeRequest {
|
|
21
|
+
export default class ReadyForChallengeValidationRequest extends AcmeRequest {
|
|
22
22
|
async execute (challengeUrl = throws.ifMissing()) {
|
|
23
23
|
const emptyPayload = {}
|
|
24
24
|
|
|
@@ -33,5 +33,3 @@ class ReadyForChallengeValidationRequest extends AcmeRequest {
|
|
|
33
33
|
return response
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
module.exports = ReadyForChallengeValidationRequest
|
package/lib/acmeCsr.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// License: AGPLv3 or later.
|
|
13
13
|
//
|
|
14
14
|
////////////////////////////////////////////////////////////////////////////////
|
|
15
|
-
|
|
15
|
+
import forge from 'node-forge'
|
|
16
16
|
const DNS = 2 // The ANS.1 type for DNS name.
|
|
17
17
|
|
|
18
18
|
// Returns a valid ACME-formatted (RFC 8555) CSR.
|
|
@@ -24,7 +24,7 @@ const DNS = 2 // The ANS.1 type for DNS name.
|
|
|
24
24
|
* @param {JWK.rsaKey} key
|
|
25
25
|
* @returns {String} An ACME-formatted CSR in PEM format.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
export default function (domains, key) { return pemToAcmeCsr(csrAsPem(domains, key)) }
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a CSR given a list of domains and a Jose JWK.rsaKey.
|
|
@@ -12,14 +12,12 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
import Identity from '../Identity.js'
|
|
16
|
+
import Throws from '../util/Throws.js'
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
class AccountIdentity extends Identity {
|
|
19
|
+
export default class AccountIdentity extends Identity {
|
|
20
20
|
constructor (configuration = throws.ifMissing()) {
|
|
21
21
|
super(configuration, 'accountIdentityPath')
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
module.exports = AccountIdentity
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import Identity from '../Identity.js'
|
|
2
|
+
import Throws from '../util/Throws.js'
|
|
3
3
|
const throws = new Throws()
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,7 +13,7 @@ const throws = new Throws()
|
|
|
13
13
|
* @copyright Aral Balkan, Small Technology Foundation
|
|
14
14
|
* @license AGPLv3 or later
|
|
15
15
|
*/
|
|
16
|
-
class CertificateIdentity extends Identity {
|
|
16
|
+
export default class CertificateIdentity extends Identity {
|
|
17
17
|
/**
|
|
18
18
|
* Creates an instance of CertificateIdentity.
|
|
19
19
|
*
|
|
@@ -24,5 +24,3 @@ class CertificateIdentity extends Identity {
|
|
|
24
24
|
super(configuration, 'certificateIdentityPath')
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
module.exports = CertificateIdentity
|
|
@@ -7,16 +7,19 @@
|
|
|
7
7
|
* @copyright Copyright © 2020 Aral Balkan, Small Technology Foundation.
|
|
8
8
|
* @license AGPLv3 or later.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import fs from 'fs'
|
|
11
|
+
import tls from 'tls'
|
|
12
|
+
import path from 'path'
|
|
13
|
+
import { fileURLToPath } from 'url'
|
|
14
|
+
|
|
15
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Monkey patches the TLS module to accept the Let’s Encrypt staging certificate.
|
|
16
19
|
*
|
|
17
20
|
* @alias module:lib/MonkeyPatchTls
|
|
18
21
|
*/
|
|
19
|
-
function monkeyPatchTLS () {
|
|
22
|
+
export default function monkeyPatchTLS () {
|
|
20
23
|
const originalCreateSecureContext = tls.createSecureContext
|
|
21
24
|
|
|
22
25
|
let pem = fs
|
|
@@ -35,5 +38,3 @@ function monkeyPatchTLS () {
|
|
|
35
38
|
return context
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
module.exports = monkeyPatchTLS
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
//
|
|
5
5
|
//////////////////////////////////////////////////////////////////////
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
import fs from 'fs'
|
|
8
|
+
import os from 'os'
|
|
9
|
+
import path from 'path'
|
|
10
|
+
import http from 'http'
|
|
11
|
+
import enableServerDestroy from 'server-destroy'
|
|
12
|
+
import Configuration from '../Configuration.js'
|
|
13
|
+
import LetsEncryptServer from '../LetsEncryptServer.js'
|
|
14
|
+
import Throws from '../util/Throws.js'
|
|
15
|
+
import log from '../util/log.js'
|
|
16
16
|
|
|
17
17
|
//
|
|
18
18
|
// Server mocks.
|
|
@@ -22,7 +22,7 @@ const throws = new Throws({
|
|
|
22
22
|
[Symbol.for('MockServerCouldNotBeStartedError')]: details => `Mock server could not be started (${error})`
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
class MockServer {
|
|
25
|
+
export class MockServer {
|
|
26
26
|
static #isBeingInstantiatedViaAsyncFactoryMethod = false
|
|
27
27
|
|
|
28
28
|
static async getInstanceAsync (responseHandler = throws.ifMissing()) {
|
|
@@ -64,7 +64,7 @@ class MockServer {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async function httpServerWithResponse (mockResponse) {
|
|
67
|
+
export async function httpServerWithResponse (mockResponse) {
|
|
68
68
|
return new Promise((resolve, reject) => {
|
|
69
69
|
const server = http.createServer((request, response) => {
|
|
70
70
|
response.statusCode = mockResponse.statusCode
|
|
@@ -76,18 +76,26 @@ async function httpServerWithResponse (mockResponse) {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
//
|
|
80
|
+
// Pebble setup and teardown.
|
|
81
|
+
//
|
|
82
|
+
|
|
83
|
+
export class TestContext {
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
79
87
|
//
|
|
80
88
|
// Timing.
|
|
81
89
|
//
|
|
82
90
|
|
|
83
|
-
function timeIt(func) {
|
|
91
|
+
export function timeIt(func) {
|
|
84
92
|
const startTime = new Date()
|
|
85
93
|
const returnValue = func()
|
|
86
94
|
const endTime = new Date()
|
|
87
95
|
return { returnValue, duration: endTime - startTime }
|
|
88
96
|
}
|
|
89
97
|
|
|
90
|
-
async function timeItAsync(func) {
|
|
98
|
+
export async function timeItAsync(func) {
|
|
91
99
|
const startTime = new Date()
|
|
92
100
|
const returnValue = await func()
|
|
93
101
|
const endTime = new Date()
|
|
@@ -98,7 +106,7 @@ async function timeItAsync(func) {
|
|
|
98
106
|
// Error validation.
|
|
99
107
|
//
|
|
100
108
|
|
|
101
|
-
function symbolOfErrorThrownBy(func) {
|
|
109
|
+
export function symbolOfErrorThrownBy(func) {
|
|
102
110
|
try {
|
|
103
111
|
func()
|
|
104
112
|
return false
|
|
@@ -108,7 +116,7 @@ function symbolOfErrorThrownBy(func) {
|
|
|
108
116
|
}
|
|
109
117
|
}
|
|
110
118
|
|
|
111
|
-
async function symbolOfErrorThrownByAsync(func) {
|
|
119
|
+
export async function symbolOfErrorThrownByAsync(func) {
|
|
112
120
|
try {
|
|
113
121
|
await func()
|
|
114
122
|
return false
|
|
@@ -118,7 +126,7 @@ async function symbolOfErrorThrownByAsync(func) {
|
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
|
|
121
|
-
function throwsErrorOfType (func, errorSymbol) {
|
|
129
|
+
export function throwsErrorOfType (func, errorSymbol) {
|
|
122
130
|
try {
|
|
123
131
|
func()
|
|
124
132
|
} catch (error) {
|
|
@@ -129,7 +137,7 @@ function throwsErrorOfType (func, errorSymbol) {
|
|
|
129
137
|
return false
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
async function throwsErrorOfTypeAsync (asyncFunc, errorSymbol) {
|
|
140
|
+
export async function throwsErrorOfTypeAsync (asyncFunc, errorSymbol) {
|
|
133
141
|
try {
|
|
134
142
|
await asyncFunc()
|
|
135
143
|
} catch (error) {
|
|
@@ -140,18 +148,17 @@ async function throwsErrorOfTypeAsync (asyncFunc, errorSymbol) {
|
|
|
140
148
|
return false
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
|
|
144
|
-
function dehydrate (string) {
|
|
151
|
+
export function dehydrate (string) {
|
|
145
152
|
return string.replace(/\s/g, '')
|
|
146
153
|
}
|
|
147
154
|
|
|
148
|
-
function createTestSettingsPath () {
|
|
149
|
-
testSettingsPath = path.join(os.homedir(), '.small-tech.org', 'auto-encrypt', 'test')
|
|
150
|
-
fs.
|
|
155
|
+
export function createTestSettingsPath () {
|
|
156
|
+
const testSettingsPath = path.join(os.homedir(), '.small-tech.org', 'auto-encrypt', 'test')
|
|
157
|
+
fs.rmSync(testSettingsPath, { recursive: true, force: true })
|
|
151
158
|
return testSettingsPath
|
|
152
159
|
}
|
|
153
160
|
|
|
154
|
-
function initialiseStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
161
|
+
export function initialiseStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
155
162
|
Configuration.reset()
|
|
156
163
|
Configuration.initialise({
|
|
157
164
|
domains: ['dev.ar.al'],
|
|
@@ -160,21 +167,6 @@ function initialiseStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
|
160
167
|
})
|
|
161
168
|
}
|
|
162
169
|
|
|
163
|
-
function setupStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
170
|
+
export function setupStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
164
171
|
initialiseStagingConfigurationWithOneDomainAtTestSettingsPath()
|
|
165
172
|
}
|
|
166
|
-
|
|
167
|
-
module.exports = {
|
|
168
|
-
MockServer,
|
|
169
|
-
timeIt,
|
|
170
|
-
timeItAsync,
|
|
171
|
-
symbolOfErrorThrownByAsync,
|
|
172
|
-
symbolOfErrorThrownBy,
|
|
173
|
-
throwsErrorOfType,
|
|
174
|
-
throwsErrorOfTypeAsync,
|
|
175
|
-
dehydrate,
|
|
176
|
-
createTestSettingsPath,
|
|
177
|
-
initialiseStagingConfigurationWithOneDomainAtTestSettingsPath,
|
|
178
|
-
setupStagingConfigurationWithOneDomainAtTestSettingsPath,
|
|
179
|
-
httpServerWithResponse
|
|
180
|
-
}
|
package/lib/util/Pluralise.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Pluralise {
|
|
1
|
+
export default class Pluralise {
|
|
2
2
|
|
|
3
3
|
static requiresEs (word) {
|
|
4
4
|
// Note: this is not meant to be comprehensive. It doesn’t take into consideration
|
|
@@ -17,5 +17,3 @@ class Pluralise {
|
|
|
17
17
|
return array.length === 1 ? word : `${word}${this.requiresEs(word) ? 'es' : 's'}`
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
module.exports = Pluralise
|
package/lib/util/Throws.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
//
|
|
12
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
import fs from 'fs'
|
|
15
15
|
|
|
16
16
|
class SymbolicError extends Error {
|
|
17
17
|
symbol = null
|
|
@@ -21,7 +21,7 @@ class SymbolicError extends Error {
|
|
|
21
21
|
// at the end of the error message, in parentheses.
|
|
22
22
|
const hinted = (str, hint) => hint ? `${str} (${hint}).` : `${str}.`
|
|
23
23
|
|
|
24
|
-
class Throws {
|
|
24
|
+
export default class Throws {
|
|
25
25
|
// Define common global errors. These are mixed into a local ERRORS object
|
|
26
26
|
// if it exists on the object the mixin() method is called with a reference to.
|
|
27
27
|
static ERRORS = {
|
|
@@ -75,7 +75,6 @@ class Throws {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
ifMissing (parameterName) {
|
|
78
|
-
|
|
79
78
|
// Attempt to automatically get the argument name even if parameterName was not
|
|
80
79
|
// manually specified in the code.
|
|
81
80
|
//
|
|
@@ -87,7 +86,7 @@ class Throws {
|
|
|
87
86
|
const stack = new Error().stack;
|
|
88
87
|
Error.prepareStackTrace = copy;
|
|
89
88
|
|
|
90
|
-
const fileName = stack[1].getFileName();
|
|
89
|
+
const fileName = stack[1].getFileName().replace('file://', '');
|
|
91
90
|
const lineNumber = stack[1].getLineNumber() - 1;
|
|
92
91
|
const columnNumber = stack[1].getColumnNumber() - 1;
|
|
93
92
|
const line = fs.readFileSync(fileName, "utf8").split("\n")[lineNumber];
|
|
@@ -97,7 +96,6 @@ class Throws {
|
|
|
97
96
|
if (groups !== null) {
|
|
98
97
|
argumentName = groups[2]
|
|
99
98
|
}
|
|
100
|
-
|
|
101
99
|
this.error(Symbol.for('UndefinedOrNullError'), parameterName || argumentName || '<unknown>')
|
|
102
100
|
}
|
|
103
101
|
|
|
@@ -117,5 +115,3 @@ class Throws {
|
|
|
117
115
|
throw this.createError(symbol, ...args)
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
|
-
|
|
121
|
-
module.exports = Throws
|
|
@@ -20,10 +20,8 @@
|
|
|
20
20
|
//
|
|
21
21
|
////////////////////////////////////////////////////////////////////////////////
|
|
22
22
|
|
|
23
|
-
async function asyncForEach(array, callback) {
|
|
23
|
+
export default async function asyncForEach(array, callback) {
|
|
24
24
|
for (let index = 0; index < array.length; index++) {
|
|
25
25
|
await callback(array[index], index, array);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
module.exports = asyncForEach
|
package/lib/util/log.js
CHANGED
package/lib/util/waitFor.js
CHANGED