@tryghost/domain-validator 1.5.2 → 2.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2022 Ghost Foundation
3
+ Copyright (c) 2013-2026 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -18,4 +18,4 @@
18
18
 
19
19
  # Copyright & License
20
20
 
21
- Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
21
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
package/lib/pro.js CHANGED
@@ -150,19 +150,19 @@ _private.isCertificateError = error => /certificate/.test(error.context);
150
150
 
151
151
  // Checks a Pro site using the provided details, and returning a responseObject
152
152
  module.exports.validate = (proto, subdomain, customdomain, subdirectory, prodomain) => {
153
- const url = _private.buildUrl(proto, customdomain, subdirectory);
153
+ const firstAttemptUrl = _private.buildUrl(proto, customdomain, subdirectory);
154
154
 
155
- debug('Validating ' + url);
156
- return request.domain(url)
155
+ debug('Validating ' + firstAttemptUrl);
156
+ return request.domain(firstAttemptUrl)
157
157
  .then((result) => {
158
158
  debug('Response received');
159
159
  return _private.buildResponse(result, proto, subdomain, customdomain, subdirectory, prodomain);
160
160
  })
161
161
  .catch(() => {
162
- const url = _private.buildUrl('http', customdomain, subdirectory);
162
+ const secondAttemptUrl = _private.buildUrl('http', customdomain, subdirectory);
163
163
 
164
- debug('Validating ' + url);
165
- return request.domain(url)
164
+ debug('Validating ' + secondAttemptUrl);
165
+ return request.domain(secondAttemptUrl)
166
166
  .then((result) => {
167
167
  debug('HTTP response received');
168
168
  const response = _private.buildResponse(result, 'http', subdomain, customdomain, subdirectory, prodomain);
package/lib/request.js CHANGED
@@ -10,36 +10,51 @@ const https = require('https');
10
10
  const {Resolver} = require('dns').promises;
11
11
  const resolver = new Resolver();
12
12
  resolver.setServers(['1.1.1.1', '1.0.0.1']);
13
+ const semverMajor = require('semver/functions/major');
14
+ const nodeVersion = semverMajor(process.versions.node);
13
15
 
14
16
  const staticLookup = () => async (hostname, _options, callback) => {
15
17
  try {
16
18
  const ips = await resolver.resolve(hostname);
17
19
 
18
20
  if (ips.length === 0) {
19
- return callback(new Error(`Unable to resolve ${hostname}`));
21
+ return callback(new errors.InternalServerError({message: `Unable to resolve ${hostname}`}));
20
22
  }
21
23
 
22
- callback(null, ips[0], 4);
24
+ if (nodeVersion >= 20) {
25
+ // Node 20+ uses a different callback signature
26
+ callback(null, [{address: ips[0], family: 4}]);
27
+ } else {
28
+ // Node 18 and below use the old callback signature
29
+ callback(null, ips[0], 4);
30
+ }
23
31
  } catch (err) {
24
32
  return callback(err);
25
33
  }
26
34
  };
27
35
 
28
36
  module.exports.domain = (url) => {
29
- const httpModule = new URL(url).protocol === 'https:' ? https : http;
30
- const httpAgent = new httpModule.Agent({lookup: staticLookup()});
31
-
37
+ /**
38
+ * @type {import('got').Options}
39
+ */
32
40
  const options = {
33
41
  // We want to capture details of different hops
34
42
  followRedirect: false,
35
43
  // Don't allow the request to go on for more than 15 seconds
36
- timeout: 15000,
44
+ timeout: {
45
+ request: 15000
46
+ },
37
47
  // If the network errors, retry 1 time:
38
- retries: 1,
48
+ retry: {
49
+ limit: 1
50
+ },
39
51
  headers: {
40
52
  'X-Ghost-Proxy': true
41
53
  },
42
- agent: httpAgent
54
+ agent: {
55
+ http: new http.Agent({lookup: staticLookup()}),
56
+ https: new https.Agent({lookup: staticLookup()})
57
+ }
43
58
  };
44
59
 
45
60
  const responses = [];
@@ -51,11 +66,11 @@ module.exports.domain = (url) => {
51
66
  const statusCode = res.statusCode;
52
67
  const headers = {};
53
68
 
54
- _.reduce(res.headers, (headers, value, name) => {
69
+ _.reduce(res.headers, (updatedHeaders = {}, value, name) => {
55
70
  if (_.startsWith(name, 'x-ghost') || _.includes(['server', 'location', 'x-amz-cf-id'], name)) {
56
- headers[name] = value;
71
+ updatedHeaders[name] = value;
57
72
  }
58
- return headers;
73
+ return updatedHeaders;
59
74
  }, headers);
60
75
 
61
76
  responses.push({statusCode, headers});
@@ -78,9 +93,12 @@ module.exports.domain = (url) => {
78
93
  .then(handleResponse)
79
94
  .then(() => resolve(responses))
80
95
  .catch((error) => {
81
- reject(new errors.BadRequestError(
82
- _.merge({message: 'Domain could not be requested', property: url, context: error.message}, error)
83
- ));
96
+ reject(new errors.BadRequestError({
97
+ message: 'Domain could not be requested',
98
+ property: url,
99
+ context: error.message,
100
+ code: error.code
101
+ }));
84
102
  });
85
103
  });
86
104
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/domain-validator",
3
- "version": "1.5.2",
3
+ "version": "2.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "ssh://git@github.com/TryGhost/Pro",
@@ -25,18 +25,18 @@
25
25
  "test": "NODE_ENV=testing mocha -- $(find test -name '*.test.js')"
26
26
  },
27
27
  "devDependencies": {
28
- "mocha": "8.4.0",
28
+ "mocha": "11.7.5",
29
29
  "should": "13.2.3",
30
- "sinon": "9.2.4"
30
+ "sinon": "21.0.3"
31
31
  },
32
32
  "dependencies": {
33
- "@tryghost/debug": "0.1.17",
34
- "@tryghost/dns": "^0.5.0",
35
- "@tryghost/errors": "1.2.14",
36
- "@tryghost/pretty-cli": "1.2.9",
33
+ "@tryghost/debug": "2.0.3",
34
+ "@tryghost/dns": "^0.6.0",
35
+ "@tryghost/errors": "3.0.3",
36
+ "@tryghost/pretty-cli": "3.0.3",
37
37
  "bluebird": "3.7.2",
38
- "got": "8.3.2",
39
- "lodash": "4.17.21"
38
+ "got": "11.8.6",
39
+ "lodash": "4.17.23"
40
40
  },
41
- "gitHead": "d66598b08a0088858aaf9e15a37dfa22d1872e26"
41
+ "gitHead": "ef060c71be33d265e7d97e4579ed83c3e3fdac09"
42
42
  }