@mountainpass/addressr 1.1.5 → 1.1.7
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 +16 -16
- package/api/swagger-2.yaml +3 -3
- package/api/swagger.yaml +9 -9
- package/lib/api/swagger-2.yaml +3 -3
- package/lib/api/swagger.yaml +9 -9
- package/lib/ci/build.js +5 -6
- package/lib/ci/pipeline.js +20 -21
- package/lib/deploy/create-deployment-archive.js +4 -5
- package/lib/loader.js +1 -1
- package/lib/service/DefaultService.js +4 -4
- package/lib/service/address-service.js +70 -82
- package/lib/src/waycharterServer.js +5 -5
- package/lib/swagger.js +8 -8
- package/lib/version.js +1 -1
- package/package.json +15 -32
- package/scripts/check-version.js +1 -2
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ Or for peace of mind for your mission critical solutions, get commercial support
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
NOTE: If you are running windows, you'll need to use [wsl](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
|
|
84
|
+
|
|
84
85
|
2. Start open search. For example run
|
|
85
86
|
|
|
86
87
|
```
|
|
@@ -123,7 +124,6 @@ Or for peace of mind for your mission critical solutions, get commercial support
|
|
|
123
124
|
```
|
|
124
125
|
|
|
125
126
|
Valid values are:
|
|
126
|
-
|
|
127
127
|
- ACT
|
|
128
128
|
- NSW
|
|
129
129
|
- NT
|
|
@@ -156,21 +156,21 @@ Or for peace of mind for your mission critical solutions, get commercial support
|
|
|
156
156
|
|
|
157
157
|
## Additional Settings
|
|
158
158
|
|
|
159
|
-
| Environment Variable
|
|
160
|
-
|
|
|
161
|
-
| ELASTIC_PROTOCOL
|
|
162
|
-
| ELASTIC_PROTOCOL
|
|
163
|
-
| ELASTIC_USERNAME
|
|
164
|
-
| ELASTIC_USERNAME
|
|
165
|
-
| ELASTIC_PASSWORD
|
|
166
|
-
| ELASTIC_PASSWORD
|
|
167
|
-
| PAGE_SIZE
|
|
168
|
-
| ADDRESSR_ACCESS_CONTROL_ALLOW_ORIGIN
|
|
169
|
-
| ADDRESSR_ACCESS_CONTROL_ALLOW_ORIGIN
|
|
170
|
-
| ADDRESSR_ACCESS_CONTROL_EXPOSE_HEADERS | _blank_
|
|
171
|
-
| ADDRESSR_ACCESS_CONTROL_EXPOSE_HEADERS | _non-blank_ | An `Access-Control-Expose-Headers` response header is returned with the value in the environment variable |
|
|
172
|
-
| ADDRESSR_ACCESS_CONTROL_ALLOW_HEADERS
|
|
173
|
-
| ADDRESSR_ACCESS_CONTROL_ALLOW_HEADERS
|
|
159
|
+
| Environment Variable | Value | Description | Default |
|
|
160
|
+
| -------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------- | ------- |
|
|
161
|
+
| ELASTIC_PROTOCOL | http | Connect to open search over http | ✅ |
|
|
162
|
+
| ELASTIC_PROTOCOL | https | Connect to open search over https | |
|
|
163
|
+
| ELASTIC_USERNAME | _blank_ | Connect to open search without authentication | ✅ |
|
|
164
|
+
| ELASTIC_USERNAME | _non-blank_ | Connect to open search with the specified username | |
|
|
165
|
+
| ELASTIC_PASSWORD | _blank_ | Connect to open search without authentication | ✅ |
|
|
166
|
+
| ELASTIC_PASSWORD | _non-blank_ | Connect to open search with the specified password | |
|
|
167
|
+
| PAGE_SIZE | 8 | Number or records to return in a search | ✅ |
|
|
168
|
+
| ADDRESSR_ACCESS_CONTROL_ALLOW_ORIGIN | _blank_ | An `Access-Control-Allow-Origin` response header is **not** returned | ✅ |
|
|
169
|
+
| ADDRESSR_ACCESS_CONTROL_ALLOW_ORIGIN | _non-blank_ | An `Access-Control-Allow-Origin` response header is returned with the value in the environment variable | |
|
|
170
|
+
| ADDRESSR_ACCESS_CONTROL_EXPOSE_HEADERS | _blank_ | An `Access-Control-Expose-Headers` response header is **not** returned | ✅ |
|
|
171
|
+
| ADDRESSR_ACCESS_CONTROL_EXPOSE_HEADERS | _non-blank_ | An `Access-Control-Expose-Headers` response header is returned with the value in the environment variable | |
|
|
172
|
+
| ADDRESSR_ACCESS_CONTROL_ALLOW_HEADERS | _blank_ | An `Access-Control-Allow-Headers` response header is **not** returned | ✅ |
|
|
173
|
+
| ADDRESSR_ACCESS_CONTROL_ALLOW_HEADERS | _non-blank_ | An `Access-Control-Allow-Headers` response header is returned with the value in the environment variable | |
|
|
174
174
|
|
|
175
175
|
NOTE: When adjusting PAGE_SIZE, you should take into account how quickly you want the initial results returned to the user. In many use cases, you want this to be as fast as possible. If you need show more results to the user, you are often better off leaving it a 8 and using the paging links to get more results while you are displaying the first 8.
|
|
176
176
|
|
package/api/swagger-2.yaml
CHANGED
|
@@ -40,7 +40,7 @@ paths:
|
|
|
40
40
|
503:
|
|
41
41
|
description: service unavailable
|
|
42
42
|
500:
|
|
43
|
-
description: unexpected error
|
|
43
|
+
description: unexpected error
|
|
44
44
|
/addresses:
|
|
45
45
|
get:
|
|
46
46
|
summary: Search for a list of addresses
|
|
@@ -79,7 +79,7 @@ paths:
|
|
|
79
79
|
503:
|
|
80
80
|
description: service unavailable
|
|
81
81
|
500:
|
|
82
|
-
description: unexpected error
|
|
82
|
+
description: unexpected error
|
|
83
83
|
/addresses/{addressId}:
|
|
84
84
|
get:
|
|
85
85
|
summary: Get Address
|
|
@@ -118,7 +118,7 @@ paths:
|
|
|
118
118
|
503:
|
|
119
119
|
description: service unavailable
|
|
120
120
|
500:
|
|
121
|
-
description: unexpected error
|
|
121
|
+
description: unexpected error
|
|
122
122
|
definitions:
|
|
123
123
|
Index:
|
|
124
124
|
type: object
|
package/api/swagger.yaml
CHANGED
|
@@ -43,11 +43,11 @@ paths:
|
|
|
43
43
|
503:
|
|
44
44
|
description: service unavailable
|
|
45
45
|
schema:
|
|
46
|
-
$ref:
|
|
46
|
+
$ref: '#/definitions/Error'
|
|
47
47
|
500:
|
|
48
|
-
description: unexpected error
|
|
48
|
+
description: unexpected error
|
|
49
49
|
schema:
|
|
50
|
-
$ref:
|
|
50
|
+
$ref: '#/definitions/Error'
|
|
51
51
|
/addresses:
|
|
52
52
|
get:
|
|
53
53
|
summary: Get List of Addresses
|
|
@@ -98,11 +98,11 @@ paths:
|
|
|
98
98
|
503:
|
|
99
99
|
description: service unavailable
|
|
100
100
|
schema:
|
|
101
|
-
$ref:
|
|
101
|
+
$ref: '#/definitions/Error'
|
|
102
102
|
500:
|
|
103
|
-
description: unexpected error
|
|
103
|
+
description: unexpected error
|
|
104
104
|
schema:
|
|
105
|
-
$ref:
|
|
105
|
+
$ref: '#/definitions/Error'
|
|
106
106
|
/addresses/{addressId}:
|
|
107
107
|
get:
|
|
108
108
|
summary: Get Address
|
|
@@ -141,11 +141,11 @@ paths:
|
|
|
141
141
|
503:
|
|
142
142
|
description: service unavailable
|
|
143
143
|
schema:
|
|
144
|
-
$ref:
|
|
144
|
+
$ref: '#/definitions/Error'
|
|
145
145
|
500:
|
|
146
|
-
description: unexpected error
|
|
146
|
+
description: unexpected error
|
|
147
147
|
schema:
|
|
148
|
-
$ref:
|
|
148
|
+
$ref: '#/definitions/Error'
|
|
149
149
|
definitions:
|
|
150
150
|
Root:
|
|
151
151
|
type: object
|
package/lib/api/swagger-2.yaml
CHANGED
|
@@ -40,7 +40,7 @@ paths:
|
|
|
40
40
|
503:
|
|
41
41
|
description: service unavailable
|
|
42
42
|
500:
|
|
43
|
-
description: unexpected error
|
|
43
|
+
description: unexpected error
|
|
44
44
|
/addresses:
|
|
45
45
|
get:
|
|
46
46
|
summary: Search for a list of addresses
|
|
@@ -79,7 +79,7 @@ paths:
|
|
|
79
79
|
503:
|
|
80
80
|
description: service unavailable
|
|
81
81
|
500:
|
|
82
|
-
description: unexpected error
|
|
82
|
+
description: unexpected error
|
|
83
83
|
/addresses/{addressId}:
|
|
84
84
|
get:
|
|
85
85
|
summary: Get Address
|
|
@@ -118,7 +118,7 @@ paths:
|
|
|
118
118
|
503:
|
|
119
119
|
description: service unavailable
|
|
120
120
|
500:
|
|
121
|
-
description: unexpected error
|
|
121
|
+
description: unexpected error
|
|
122
122
|
definitions:
|
|
123
123
|
Index:
|
|
124
124
|
type: object
|
package/lib/api/swagger.yaml
CHANGED
|
@@ -43,11 +43,11 @@ paths:
|
|
|
43
43
|
503:
|
|
44
44
|
description: service unavailable
|
|
45
45
|
schema:
|
|
46
|
-
$ref:
|
|
46
|
+
$ref: '#/definitions/Error'
|
|
47
47
|
500:
|
|
48
|
-
description: unexpected error
|
|
48
|
+
description: unexpected error
|
|
49
49
|
schema:
|
|
50
|
-
$ref:
|
|
50
|
+
$ref: '#/definitions/Error'
|
|
51
51
|
/addresses:
|
|
52
52
|
get:
|
|
53
53
|
summary: Get List of Addresses
|
|
@@ -98,11 +98,11 @@ paths:
|
|
|
98
98
|
503:
|
|
99
99
|
description: service unavailable
|
|
100
100
|
schema:
|
|
101
|
-
$ref:
|
|
101
|
+
$ref: '#/definitions/Error'
|
|
102
102
|
500:
|
|
103
|
-
description: unexpected error
|
|
103
|
+
description: unexpected error
|
|
104
104
|
schema:
|
|
105
|
-
$ref:
|
|
105
|
+
$ref: '#/definitions/Error'
|
|
106
106
|
/addresses/{addressId}:
|
|
107
107
|
get:
|
|
108
108
|
summary: Get Address
|
|
@@ -141,11 +141,11 @@ paths:
|
|
|
141
141
|
503:
|
|
142
142
|
description: service unavailable
|
|
143
143
|
schema:
|
|
144
|
-
$ref:
|
|
144
|
+
$ref: '#/definitions/Error'
|
|
145
145
|
500:
|
|
146
|
-
description: unexpected error
|
|
146
|
+
description: unexpected error
|
|
147
147
|
schema:
|
|
148
|
-
$ref:
|
|
148
|
+
$ref: '#/definitions/Error'
|
|
149
149
|
definitions:
|
|
150
150
|
Root:
|
|
151
151
|
type: object
|
package/lib/ci/build.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
+
var _dagger = require("@dagger.io/dagger");
|
|
3
4
|
// Use Node 16 or above to run this script.
|
|
4
5
|
// `node build.js` will run this script.
|
|
5
6
|
//
|
|
@@ -23,20 +24,18 @@ actions:
|
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
*/
|
|
26
|
-
"use strict";
|
|
27
27
|
|
|
28
|
-
var _dagger = require("@dagger.io/dagger");
|
|
29
28
|
// initialize Dagger client
|
|
30
29
|
console.log('starting...');
|
|
31
30
|
(0, _dagger.connect)(async client => {
|
|
32
31
|
// get reference to the local project
|
|
33
|
-
const source = client.host().directory(
|
|
32
|
+
const source = client.host().directory('.');
|
|
34
33
|
|
|
35
34
|
// get Node image
|
|
36
|
-
const node = client.container().from(
|
|
35
|
+
const node = client.container().from('node:12.11.0');
|
|
37
36
|
|
|
38
37
|
// mount cloned repository into Node image
|
|
39
38
|
const runner = client.container({
|
|
40
39
|
id: node
|
|
41
|
-
}).withMountedDirectory(
|
|
40
|
+
}).withMountedDirectory('/src', source).withWorkdir('/src').withExec(['npm', 'run', 'hello']);
|
|
42
41
|
});
|
package/lib/ci/pipeline.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
+
var _dagger = require("@dagger.io/dagger");
|
|
4
|
+
var _envPaths = require("env-paths");
|
|
5
|
+
var _envPaths2 = _interopRequireDefault(_envPaths);
|
|
6
|
+
var _nodeFs = require("node:fs");
|
|
7
|
+
var _nodeFs2 = _interopRequireDefault(_nodeFs);
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
3
9
|
// Use Node 16 or above to run this script.
|
|
4
10
|
// `node build.js` will run this script.
|
|
5
11
|
//
|
|
@@ -23,19 +29,12 @@ actions:
|
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
*/
|
|
26
|
-
"use strict";
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var _envPaths2 = _interopRequireDefault(_envPaths);
|
|
31
|
-
var _fs = require("fs");
|
|
32
|
-
var _fs2 = _interopRequireDefault(_fs);
|
|
33
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
34
|
-
const cacheDir = `${(0, _envPaths2.default)("", {
|
|
35
|
-
suffix: ""
|
|
33
|
+
const cacheDir = `${(0, _envPaths2.default)('', {
|
|
34
|
+
suffix: ''
|
|
36
35
|
}).cache}/dagger`;
|
|
37
36
|
const binLocation = `${cacheDir}/dagger-0.3.9`;
|
|
38
|
-
if (!process.env._EXPERIMENTAL_DAGGER_CLI_BIN &&
|
|
37
|
+
if (!process.env._EXPERIMENTAL_DAGGER_CLI_BIN && _nodeFs2.default.existsSync(binLocation)) {
|
|
39
38
|
process.env._EXPERIMENTAL_DAGGER_CLI_BIN = binLocation;
|
|
40
39
|
console.log(`using already downloaded '${binLocation}'`);
|
|
41
40
|
}
|
|
@@ -44,11 +43,11 @@ console.log('connecting...');
|
|
|
44
43
|
console.log('\t...connected');
|
|
45
44
|
// get reference to the local project
|
|
46
45
|
client.log;
|
|
47
|
-
const workspace = client.host().directory(
|
|
46
|
+
const workspace = client.host().directory('.'); //, { exclude: ["node_modules/"] })
|
|
48
47
|
|
|
49
48
|
// get Node image
|
|
50
|
-
const node = client.container().from(
|
|
51
|
-
console.log(await node.withExec([
|
|
49
|
+
const node = client.container().from('node:14.21.2').withMountedDirectory('/workspace', workspace).withWorkdir('/workspace');
|
|
50
|
+
console.log(await node.withExec(['npm', '--version']).stdout());
|
|
52
51
|
const installed = node;
|
|
53
52
|
// .withExec(["npm", "install"])
|
|
54
53
|
|
|
@@ -61,18 +60,18 @@ console.log('connecting...');
|
|
|
61
60
|
// print output
|
|
62
61
|
// console.log("Hello from Dagger and Node " + version)
|
|
63
62
|
|
|
64
|
-
await installed.withExec([
|
|
63
|
+
await installed.withExec(['npm', 'run', 'genversion']).file('version.js').export('dagger-version.js');
|
|
65
64
|
console.log(stdout);
|
|
66
65
|
console.error(stderr);
|
|
67
66
|
|
|
68
67
|
/*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
npm run genversion
|
|
69
|
+
npm run check-licenses
|
|
70
|
+
npm run cover:nodejs:nogeo
|
|
71
|
+
npm run cover:rest:nogeo
|
|
72
|
+
*/
|
|
74
73
|
|
|
75
|
-
installed.withExec([
|
|
74
|
+
installed.withExec(['npm', 'run', 'build']);
|
|
76
75
|
// await runner.exitCode()
|
|
77
76
|
// .directory("node_modules/")
|
|
78
77
|
// .export("./dagger_node_modules")
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
"use strict";
|
|
3
2
|
|
|
4
3
|
const fs = require('fs');
|
|
@@ -43,7 +42,7 @@ function createPackageJson(context, filepath) {
|
|
|
43
42
|
homepage
|
|
44
43
|
} = context;
|
|
45
44
|
const newPackageJson = {
|
|
46
|
-
|
|
45
|
+
name: `${name}-deployment`,
|
|
47
46
|
version,
|
|
48
47
|
description,
|
|
49
48
|
author,
|
|
@@ -55,11 +54,11 @@ function createPackageJson(context, filepath) {
|
|
|
55
54
|
repository,
|
|
56
55
|
bugs,
|
|
57
56
|
homepage,
|
|
58
|
-
|
|
57
|
+
scripts: {
|
|
59
58
|
// TODO: see if we can use the context.main as the start script
|
|
60
|
-
|
|
59
|
+
start: 'addressr-server-2'
|
|
61
60
|
},
|
|
62
|
-
|
|
61
|
+
dependencies: {
|
|
63
62
|
[name]: version
|
|
64
63
|
}
|
|
65
64
|
};
|
package/lib/loader.js
CHANGED
|
@@ -23,7 +23,7 @@ const start = process.hrtime();
|
|
|
23
23
|
logger('data loaded');
|
|
24
24
|
}).then(() => {
|
|
25
25
|
const end = process.hrtime(start);
|
|
26
|
-
logger(`Execution time: ${end[0]}s ${end[1] /
|
|
26
|
+
logger(`Execution time: ${end[0]}s ${end[1] / 1_000_000}ms`);
|
|
27
27
|
}).then(() => {
|
|
28
28
|
logger(`Fin`);
|
|
29
29
|
process.exit();
|
|
@@ -21,7 +21,7 @@ var logger = (0, _debug2.default)('api');
|
|
|
21
21
|
async function getApiRoot() {
|
|
22
22
|
const paths = Object.keys(global.swaggerDoc.paths).filter(p => global.swaggerDoc.paths[p].get !== undefined && global.swaggerDoc.paths[p].get['x-root-rel'] !== undefined);
|
|
23
23
|
const link = new _httpLinkHeader2.default();
|
|
24
|
-
|
|
24
|
+
for (const p of paths) {
|
|
25
25
|
const op = global.swaggerDoc.paths[p].get;
|
|
26
26
|
if (op.parameters && op.parameters.find(parameter => parameter.required === true)) {
|
|
27
27
|
// skip
|
|
@@ -32,7 +32,7 @@ async function getApiRoot() {
|
|
|
32
32
|
title: op.summary
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
link.set({
|
|
37
37
|
rel: 'describedby',
|
|
38
38
|
uri: '/docs/',
|
|
@@ -46,11 +46,11 @@ async function getApiRoot() {
|
|
|
46
46
|
type: 'application/json'
|
|
47
47
|
});
|
|
48
48
|
const linkTemplate = new _httpLinkHeader2.default();
|
|
49
|
-
|
|
49
|
+
for (const url of paths) {
|
|
50
50
|
const op = global.swaggerDoc.paths[url].get;
|
|
51
51
|
logger(op);
|
|
52
52
|
(0, _setLinkOptions.setLinkOptions)(op, url, linkTemplate);
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
return {
|
|
55
55
|
link: link,
|
|
56
56
|
body: {},
|
|
@@ -17,18 +17,18 @@ var _debug = require("debug");
|
|
|
17
17
|
var _debug2 = _interopRequireDefault(_debug);
|
|
18
18
|
var _directoryExists = require("directory-exists");
|
|
19
19
|
var _directoryExists2 = _interopRequireDefault(_directoryExists);
|
|
20
|
-
var
|
|
21
|
-
var
|
|
20
|
+
var _nodeFs = require("node:fs");
|
|
21
|
+
var _nodeFs2 = _interopRequireDefault(_nodeFs);
|
|
22
22
|
var _got = require("got");
|
|
23
23
|
var _got2 = _interopRequireDefault(_got);
|
|
24
24
|
var _httpLinkHeader = require("http-link-header");
|
|
25
25
|
var _httpLinkHeader2 = _interopRequireDefault(_httpLinkHeader);
|
|
26
26
|
var _papaparse = require("papaparse");
|
|
27
27
|
var _papaparse2 = _interopRequireDefault(_papaparse);
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
28
|
+
var _nodePath = require("node:path");
|
|
29
|
+
var _nodePath2 = _interopRequireDefault(_nodePath);
|
|
30
|
+
var _nodeStream = require("node:stream");
|
|
31
|
+
var _nodeStream2 = _interopRequireDefault(_nodeStream);
|
|
32
32
|
var _unzipStream = require("unzip-stream");
|
|
33
33
|
var _unzipStream2 = _interopRequireDefault(_unzipStream);
|
|
34
34
|
var _elasticsearch = require("../client/elasticsearch");
|
|
@@ -38,8 +38,8 @@ var _setLinkOptions = require("./setLinkOptions");
|
|
|
38
38
|
var _keyv = require("keyv");
|
|
39
39
|
var _keyv2 = _interopRequireDefault(_keyv);
|
|
40
40
|
var _keyvFile = require("keyv-file");
|
|
41
|
-
var
|
|
42
|
-
var
|
|
41
|
+
var _nodeCrypto = require("node:crypto");
|
|
42
|
+
var _nodeCrypto2 = _interopRequireDefault(_nodeCrypto);
|
|
43
43
|
var _globPromise = require("glob-promise");
|
|
44
44
|
var _globPromise2 = _interopRequireDefault(_globPromise);
|
|
45
45
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -48,7 +48,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
48
48
|
/* eslint-disable security/detect-object-injection */
|
|
49
49
|
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
50
50
|
|
|
51
|
-
const fsp =
|
|
51
|
+
const fsp = _nodeFs2.default.promises;
|
|
52
52
|
var logger = (0, _debug2.default)('api');
|
|
53
53
|
var error = (0, _debug2.default)('error');
|
|
54
54
|
const cache = new _keyv2.default({
|
|
@@ -59,11 +59,7 @@ const cache = new _keyv2.default({
|
|
|
59
59
|
const PAGE_SIZE = process.env.PAGE_SIZE || 8;
|
|
60
60
|
function getCoveredStates() {
|
|
61
61
|
const covered = process.env.COVERED_STATES || '';
|
|
62
|
-
|
|
63
|
-
return [];
|
|
64
|
-
} else {
|
|
65
|
-
return covered.split(',');
|
|
66
|
-
}
|
|
62
|
+
return covered == '' ? [] : covered.split(',');
|
|
67
63
|
}
|
|
68
64
|
const COVERED_STATES = getCoveredStates();
|
|
69
65
|
const ONE_DAY_S = 60 /*sec*/ * 60 /*min*/ * 24; /*hours*/
|
|
@@ -80,7 +76,7 @@ async function clearAddresses() {
|
|
|
80
76
|
async function setAddresses(addr) {
|
|
81
77
|
await clearAddresses();
|
|
82
78
|
const indexingBody = [];
|
|
83
|
-
|
|
79
|
+
for (const row of addr) {
|
|
84
80
|
indexingBody.push({
|
|
85
81
|
index: {
|
|
86
82
|
_index: ES_INDEX_NAME,
|
|
@@ -98,7 +94,7 @@ async function setAddresses(addr) {
|
|
|
98
94
|
structurted,
|
|
99
95
|
confidence: structurted.structurted.confidence
|
|
100
96
|
});
|
|
101
|
-
}
|
|
97
|
+
}
|
|
102
98
|
if (indexingBody.length > 0) {
|
|
103
99
|
await sendIndexRequest(indexingBody);
|
|
104
100
|
}
|
|
@@ -144,11 +140,9 @@ async function fetchPackageData() {
|
|
|
144
140
|
return response;
|
|
145
141
|
} catch (error_) {
|
|
146
142
|
// we were unable to fetch. if we have cached value that isn't stale, return in
|
|
147
|
-
if (cachedResponse !== undefined) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return cachedResponse;
|
|
151
|
-
}
|
|
143
|
+
if (cachedResponse !== undefined && age < THIRTY_DAYS_MS) {
|
|
144
|
+
cachedResponse.headers['warning'] = '110 custom/1.0 "Response is Stale"';
|
|
145
|
+
return cachedResponse;
|
|
152
146
|
}
|
|
153
147
|
// otherwise, throw the original network error
|
|
154
148
|
throw error_;
|
|
@@ -165,12 +159,12 @@ async function fetchGnafFile() {
|
|
|
165
159
|
logger('dataResource', JSON.stringify(dataResource, undefined, 2));
|
|
166
160
|
logger('url', dataResource.url);
|
|
167
161
|
logger('headers', JSON.stringify(response.headers, undefined, 2));
|
|
168
|
-
const basename =
|
|
162
|
+
const basename = _nodePath2.default.basename(dataResource.url);
|
|
169
163
|
logger('basename', basename);
|
|
170
164
|
const complete_path = GNAF_DIR;
|
|
171
165
|
const incomplete_path = `${complete_path}/incomplete`;
|
|
172
166
|
await new Promise((resolve, reject) => {
|
|
173
|
-
|
|
167
|
+
_nodeFs2.default.mkdir(incomplete_path, {
|
|
174
168
|
recursive: true
|
|
175
169
|
}, error_ => {
|
|
176
170
|
if (error_) reject(error_);else resolve();
|
|
@@ -178,7 +172,7 @@ async function fetchGnafFile() {
|
|
|
178
172
|
});
|
|
179
173
|
const destination = `${complete_path}/${basename}`;
|
|
180
174
|
await new Promise((resolve, reject) => {
|
|
181
|
-
|
|
175
|
+
_nodeFs2.default.mkdir(incomplete_path, {
|
|
182
176
|
recursive: true
|
|
183
177
|
}, error_ => {
|
|
184
178
|
if (error_) reject(error_);else resolve();
|
|
@@ -187,7 +181,7 @@ async function fetchGnafFile() {
|
|
|
187
181
|
// see if the file exists already
|
|
188
182
|
try {
|
|
189
183
|
await new Promise((resolve, reject) => {
|
|
190
|
-
|
|
184
|
+
_nodeFs2.default.access(destination, _nodeFs2.default.constants.R_OK, error_ => {
|
|
191
185
|
if (error_) reject(error_);else resolve();
|
|
192
186
|
});
|
|
193
187
|
});
|
|
@@ -208,8 +202,8 @@ async function fetchGnafFile() {
|
|
|
208
202
|
}
|
|
209
203
|
}
|
|
210
204
|
async function unzipFile(file) {
|
|
211
|
-
const extname =
|
|
212
|
-
const basenameWithoutExtention =
|
|
205
|
+
const extname = _nodePath2.default.extname(file);
|
|
206
|
+
const basenameWithoutExtention = _nodePath2.default.basename(file, extname);
|
|
213
207
|
const incomplete_path = `${GNAF_DIR}/incomplete/${basenameWithoutExtention}`;
|
|
214
208
|
const complete_path = `${GNAF_DIR}/${basenameWithoutExtention}`;
|
|
215
209
|
const exists = await (0, _directoryExists2.default)(complete_path);
|
|
@@ -219,21 +213,21 @@ async function unzipFile(file) {
|
|
|
219
213
|
return complete_path;
|
|
220
214
|
} else {
|
|
221
215
|
await new Promise((resolve, reject) => {
|
|
222
|
-
|
|
216
|
+
_nodeFs2.default.mkdir(incomplete_path, {
|
|
223
217
|
recursive: true
|
|
224
218
|
}, error_ => {
|
|
225
219
|
if (error_) reject(error_);else resolve();
|
|
226
220
|
});
|
|
227
221
|
});
|
|
228
|
-
const readStream =
|
|
222
|
+
const readStream = _nodeFs2.default.createReadStream(file);
|
|
229
223
|
logger('before pipe');
|
|
230
224
|
let prom = new Promise((resolve, reject) => {
|
|
231
|
-
readStream.pipe(_unzipStream2.default.Parse()).pipe(
|
|
225
|
+
readStream.pipe(_unzipStream2.default.Parse()).pipe(_nodeStream2.default.Transform({
|
|
232
226
|
objectMode: true,
|
|
233
227
|
transform: function (entry, encoding, callback) {
|
|
234
228
|
const entryPath = `${incomplete_path}/${entry.path}`;
|
|
235
229
|
if (entry.isDirectory) {
|
|
236
|
-
|
|
230
|
+
_nodeFs2.default.mkdir(entryPath, {
|
|
237
231
|
recursive: true
|
|
238
232
|
}, error_ => {
|
|
239
233
|
if (error_) {
|
|
@@ -245,15 +239,15 @@ async function unzipFile(file) {
|
|
|
245
239
|
}
|
|
246
240
|
});
|
|
247
241
|
} else {
|
|
248
|
-
const dirname =
|
|
249
|
-
|
|
242
|
+
const dirname = _nodePath2.default.dirname(entryPath);
|
|
243
|
+
_nodeFs2.default.mkdir(dirname, {
|
|
250
244
|
recursive: true
|
|
251
245
|
}, error_ => {
|
|
252
246
|
if (error_) {
|
|
253
247
|
entry.autodrain();
|
|
254
248
|
callback(error_);
|
|
255
249
|
} else {
|
|
256
|
-
|
|
250
|
+
_nodeFs2.default.stat(entryPath, (error_, stats) => {
|
|
257
251
|
if (error_ && error_.code !== 'ENOENT') {
|
|
258
252
|
logger('error statting file', error_);
|
|
259
253
|
entry.autodrain();
|
|
@@ -268,7 +262,7 @@ async function unzipFile(file) {
|
|
|
268
262
|
} else {
|
|
269
263
|
// size is different, so extract the file
|
|
270
264
|
logger('extracting', entryPath);
|
|
271
|
-
entry.pipe(
|
|
265
|
+
entry.pipe(_nodeFs2.default.createWriteStream(entryPath)).on('finish', () => {
|
|
272
266
|
logger('finished extracting', entryPath);
|
|
273
267
|
callback();
|
|
274
268
|
}).on('error', error => {
|
|
@@ -291,7 +285,7 @@ async function unzipFile(file) {
|
|
|
291
285
|
});
|
|
292
286
|
await prom;
|
|
293
287
|
return await new Promise((resolve, reject) => {
|
|
294
|
-
|
|
288
|
+
_nodeFs2.default.rename(incomplete_path, complete_path, error_ => {
|
|
295
289
|
if (error_) reject(error_);else resolve(complete_path);
|
|
296
290
|
});
|
|
297
291
|
});
|
|
@@ -423,14 +417,14 @@ function mapStreetLocality(l, context) {
|
|
|
423
417
|
function mapGeo(geoSite, context, geoDefault) {
|
|
424
418
|
let foundDefault = false;
|
|
425
419
|
if (geoSite && geoDefault) {
|
|
426
|
-
|
|
420
|
+
for (const geo of geoSite) {
|
|
427
421
|
if (geo.GEOCODE_TYPE_CODE === geoDefault[0].GEOCODE_TYPE_CODE && geo.LATITUDE === geoDefault[0].LATITUDE && geo.LONGITUDE === geoDefault[0].LONGITUDE) {
|
|
428
422
|
foundDefault = true;
|
|
429
423
|
geo.default = true;
|
|
430
424
|
} else {
|
|
431
425
|
geo.default = false;
|
|
432
426
|
}
|
|
433
|
-
}
|
|
427
|
+
}
|
|
434
428
|
}
|
|
435
429
|
const sites = geoSite ? geoSite.map(geo => {
|
|
436
430
|
if (geo.BOUNDARY_EXTENT !== '') {
|
|
@@ -525,8 +519,7 @@ function mapToMla(s) {
|
|
|
525
519
|
const streetType = s.street.type ? ` ${s.street.type.name}` : '';
|
|
526
520
|
const streetSuffix = s.street.suffix ? ` ${s.street.suffix.name}` : '';
|
|
527
521
|
const street = `${s.street.name}${streetType}${streetSuffix}`;
|
|
528
|
-
fla.push(`${number} ${street}`);
|
|
529
|
-
fla.push(`${s.locality.name} ${s.state.abbreviation} ${s.postcode}`);
|
|
522
|
+
fla.push(`${number} ${street}`, `${s.locality.name} ${s.state.abbreviation} ${s.postcode}`);
|
|
530
523
|
if (fla.length > 4) {
|
|
531
524
|
logger('FLA TOO LONG', fla, s);
|
|
532
525
|
throw new Error('FLA TOO LONG');
|
|
@@ -555,8 +548,7 @@ function mapToShortMla(s) {
|
|
|
555
548
|
const streetType = s.street.type ? ` ${s.street.type.name}` : '';
|
|
556
549
|
const streetSuffix = s.street.suffix ? ` ${s.street.suffix.code}` : '';
|
|
557
550
|
const street = `${s.street.name}${streetType}${streetSuffix}`;
|
|
558
|
-
fla.push(`${number} ${street}`);
|
|
559
|
-
fla.push(`${s.locality.name} ${s.state.abbreviation} ${s.postcode}`);
|
|
551
|
+
fla.push(`${number} ${street}`, `${s.locality.name} ${s.state.abbreviation} ${s.postcode}`);
|
|
560
552
|
if (fla.length > 4) {
|
|
561
553
|
logger('FLA TOO LONG', fla, s);
|
|
562
554
|
throw new Error('FLA TOO LONG');
|
|
@@ -565,7 +557,7 @@ function mapToShortMla(s) {
|
|
|
565
557
|
}
|
|
566
558
|
|
|
567
559
|
// eslint-disable-next-line complexity
|
|
568
|
-
function mapAddressDetails(d, context,
|
|
560
|
+
function mapAddressDetails(d, context, index, count) {
|
|
569
561
|
const streetLocality = context.streetLocalityIndexed[d.STREET_LOCALITY_PID];
|
|
570
562
|
const locality = context.localityIndexed[d.LOCALITY_PID];
|
|
571
563
|
const geoSite = context.geoIndexed ? context.geoIndexed[d.ADDRESS_SITE_PID] : undefined;
|
|
@@ -692,14 +684,14 @@ function mapAddressDetails(d, context, i, count) {
|
|
|
692
684
|
rval.ssla = mapToSla(rval.smla);
|
|
693
685
|
}
|
|
694
686
|
if (count) {
|
|
695
|
-
if (
|
|
687
|
+
if (index % Math.ceil(count / 100) === 0) {
|
|
696
688
|
logger('addr', JSON.stringify(rval, undefined, 2));
|
|
697
|
-
logger(`${
|
|
689
|
+
logger(`${index / count * 100}%`);
|
|
698
690
|
}
|
|
699
691
|
} else {
|
|
700
|
-
if (
|
|
692
|
+
if (index % 10_000 === 0) {
|
|
701
693
|
logger('addr', JSON.stringify(rval, undefined, 2));
|
|
702
|
-
logger(`${
|
|
694
|
+
logger(`${index} rows`);
|
|
703
695
|
}
|
|
704
696
|
}
|
|
705
697
|
return rval;
|
|
@@ -709,7 +701,7 @@ async function loadAddressDetails(file, expectedCount, context, {
|
|
|
709
701
|
} = {}) {
|
|
710
702
|
let actualCount = 0;
|
|
711
703
|
await new Promise((resolve, reject) => {
|
|
712
|
-
_papaparse2.default.parse(
|
|
704
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(file), {
|
|
713
705
|
header: true,
|
|
714
706
|
skipEmptyLines: true,
|
|
715
707
|
chunkSize: Number.parseInt(process.env.ADDRESSR_LOADING_CHUNK_SIZE || '10') * 1024 * 1024,
|
|
@@ -723,7 +715,7 @@ async function loadAddressDetails(file, expectedCount, context, {
|
|
|
723
715
|
});
|
|
724
716
|
}
|
|
725
717
|
const indexingBody = [];
|
|
726
|
-
chunk.data
|
|
718
|
+
for (const row of chunk.data) {
|
|
727
719
|
const item = mapAddressDetails(row, context, actualCount, expectedCount);
|
|
728
720
|
items.push(item);
|
|
729
721
|
actualCount += 1;
|
|
@@ -744,7 +736,7 @@ async function loadAddressDetails(file, expectedCount, context, {
|
|
|
744
736
|
structured,
|
|
745
737
|
confidence: structured.structured.confidence
|
|
746
738
|
});
|
|
747
|
-
}
|
|
739
|
+
}
|
|
748
740
|
if (indexingBody.length > 0) {
|
|
749
741
|
sendIndexRequest(indexingBody, undefined, {
|
|
750
742
|
refresh
|
|
@@ -946,7 +938,7 @@ async function sendIndexRequest(indexingBody, initialBackoff = Number.parseInt(p
|
|
|
946
938
|
}
|
|
947
939
|
async function getStateName(abbr, file) {
|
|
948
940
|
return await new Promise((resolve, reject) => {
|
|
949
|
-
_papaparse2.default.parse(
|
|
941
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(file), {
|
|
950
942
|
header: true,
|
|
951
943
|
delimiter: '|',
|
|
952
944
|
complete: results => {
|
|
@@ -982,7 +974,7 @@ const {
|
|
|
982
974
|
readdir
|
|
983
975
|
} = require('fs').promises;
|
|
984
976
|
async function getFiles(currentDir, baseDir) {
|
|
985
|
-
const dir =
|
|
977
|
+
const dir = _nodePath2.default.resolve(baseDir, currentDir);
|
|
986
978
|
logger(`reading ${dir} (${currentDir} in ${baseDir})`);
|
|
987
979
|
const dirents = await readdir(dir, {
|
|
988
980
|
withFileTypes: true
|
|
@@ -995,9 +987,9 @@ async function getFiles(currentDir, baseDir) {
|
|
|
995
987
|
}
|
|
996
988
|
function countFileLines(filePath) {
|
|
997
989
|
return new Promise((resolve, reject) => {
|
|
998
|
-
const readStream =
|
|
990
|
+
const readStream = _nodeFs2.default.createReadStream(filePath, 'utf-8');
|
|
999
991
|
let lines = 0;
|
|
1000
|
-
let last
|
|
992
|
+
let last;
|
|
1001
993
|
readStream.on('data', function (chunk) {
|
|
1002
994
|
lines += chunk.split('\n').length - 1;
|
|
1003
995
|
last = chunk[chunk.length - 1];
|
|
@@ -1008,8 +1000,8 @@ function countFileLines(filePath) {
|
|
|
1008
1000
|
}
|
|
1009
1001
|
resolve(lines);
|
|
1010
1002
|
});
|
|
1011
|
-
readStream.on('error', function (
|
|
1012
|
-
reject(
|
|
1003
|
+
readStream.on('error', function (error_) {
|
|
1004
|
+
reject(error_);
|
|
1013
1005
|
});
|
|
1014
1006
|
});
|
|
1015
1007
|
}
|
|
@@ -1048,7 +1040,7 @@ async function loadGnafData(directory, {
|
|
|
1048
1040
|
const addressDetailFiles = files.filter(f => f.match(/ADDRESS_DETAIL/) && f.match(/\/Standard\//));
|
|
1049
1041
|
logger('addressDetailFiles', addressDetailFiles);
|
|
1050
1042
|
for (const detailFile of addressDetailFiles) {
|
|
1051
|
-
const state =
|
|
1043
|
+
const state = _nodePath2.default.basename(detailFile, _nodePath2.default.extname(detailFile)).replace(/_.*/, '');
|
|
1052
1044
|
if (COVERED_STATES.length === 0 || COVERED_STATES.includes(state)) {
|
|
1053
1045
|
loadContext.state = state;
|
|
1054
1046
|
loadContext.stateName = await loadState(files, directory, state);
|
|
@@ -1093,17 +1085,17 @@ async function loadGnafData(directory, {
|
|
|
1093
1085
|
}
|
|
1094
1086
|
async function fileExists(countsFile) {
|
|
1095
1087
|
try {
|
|
1096
|
-
await fsp.access(countsFile,
|
|
1088
|
+
await fsp.access(countsFile, _nodeFs2.default.constants.F_OK);
|
|
1097
1089
|
return true;
|
|
1098
|
-
} catch (
|
|
1099
|
-
error(
|
|
1090
|
+
} catch (error_) {
|
|
1091
|
+
error(error_);
|
|
1100
1092
|
return false;
|
|
1101
1093
|
}
|
|
1102
1094
|
}
|
|
1103
1095
|
async function loadFileCounts(countsFile) {
|
|
1104
1096
|
const filesCounts = {};
|
|
1105
1097
|
await new Promise((resolve, reject) => {
|
|
1106
|
-
_papaparse2.default.parse(
|
|
1098
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(countsFile), {
|
|
1107
1099
|
header: true,
|
|
1108
1100
|
skipEmptyLines: true,
|
|
1109
1101
|
step: function (row) {
|
|
@@ -1150,7 +1142,7 @@ async function loadStreetLocality(files, directory, state) {
|
|
|
1150
1142
|
return [];
|
|
1151
1143
|
} else {
|
|
1152
1144
|
return await new Promise((resolve, reject) => {
|
|
1153
|
-
_papaparse2.default.parse(
|
|
1145
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(`${directory}/${localityFile}`), {
|
|
1154
1146
|
header: true,
|
|
1155
1147
|
delimiter: '|',
|
|
1156
1148
|
complete: results => {
|
|
@@ -1171,7 +1163,7 @@ async function loadLocality(files, directory, state) {
|
|
|
1171
1163
|
return [];
|
|
1172
1164
|
} else {
|
|
1173
1165
|
return await new Promise((resolve, reject) => {
|
|
1174
|
-
_papaparse2.default.parse(
|
|
1166
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(`${directory}/${localityFile}`), {
|
|
1175
1167
|
header: true,
|
|
1176
1168
|
delimiter: '|',
|
|
1177
1169
|
complete: results => {
|
|
@@ -1195,7 +1187,7 @@ async function loadSiteGeo(files, directory, state, loadContext, filesCounts) {
|
|
|
1195
1187
|
const expectedCount = filesCounts[geoFile];
|
|
1196
1188
|
let count = 0;
|
|
1197
1189
|
return await new Promise((resolve, reject) => {
|
|
1198
|
-
_papaparse2.default.parse(
|
|
1190
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(`${directory}/${geoFile}`), {
|
|
1199
1191
|
header: true,
|
|
1200
1192
|
delimiter: '|',
|
|
1201
1193
|
chunk: function (chunk, parser) {
|
|
@@ -1206,11 +1198,9 @@ async function loadSiteGeo(files, directory, state, loadContext, filesCounts) {
|
|
|
1206
1198
|
errors: chunk.errors
|
|
1207
1199
|
});
|
|
1208
1200
|
} else {
|
|
1209
|
-
chunk.data
|
|
1210
|
-
if (expectedCount) {
|
|
1211
|
-
|
|
1212
|
-
logger(`${Math.floor(count / expectedCount * 100)}% (${count}/ ${expectedCount})`);
|
|
1213
|
-
}
|
|
1201
|
+
for (const row of chunk.data) {
|
|
1202
|
+
if (expectedCount && count % Math.ceil(expectedCount / 100) === 0) {
|
|
1203
|
+
logger(`${Math.floor(count / expectedCount * 100)}% (${count}/ ${expectedCount})`);
|
|
1214
1204
|
}
|
|
1215
1205
|
const g = row;
|
|
1216
1206
|
if (loadContext.geoIndexed[g.ADDRESS_SITE_PID] === undefined) {
|
|
@@ -1219,7 +1209,7 @@ async function loadSiteGeo(files, directory, state, loadContext, filesCounts) {
|
|
|
1219
1209
|
loadContext.geoIndexed[g.ADDRESS_SITE_PID].push(g);
|
|
1220
1210
|
}
|
|
1221
1211
|
count += 1;
|
|
1222
|
-
}
|
|
1212
|
+
}
|
|
1223
1213
|
parser.resume();
|
|
1224
1214
|
}
|
|
1225
1215
|
},
|
|
@@ -1244,7 +1234,7 @@ async function loadDefaultGeo(files, directory, state, loadContext, filesCounts)
|
|
|
1244
1234
|
const expectedCount = filesCounts[geoFile];
|
|
1245
1235
|
let count = 0;
|
|
1246
1236
|
return await new Promise((resolve, reject) => {
|
|
1247
|
-
_papaparse2.default.parse(
|
|
1237
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(`${directory}/${geoFile}`), {
|
|
1248
1238
|
header: true,
|
|
1249
1239
|
delimiter: '|',
|
|
1250
1240
|
chunk: function (chunk, parser) {
|
|
@@ -1255,11 +1245,9 @@ async function loadDefaultGeo(files, directory, state, loadContext, filesCounts)
|
|
|
1255
1245
|
errors: chunk.errors
|
|
1256
1246
|
});
|
|
1257
1247
|
} else {
|
|
1258
|
-
chunk.data
|
|
1259
|
-
if (expectedCount) {
|
|
1260
|
-
|
|
1261
|
-
logger(`${Math.floor(count / expectedCount * 100)}% (${count}/ ${expectedCount})`);
|
|
1262
|
-
}
|
|
1248
|
+
for (const row of chunk.data) {
|
|
1249
|
+
if (expectedCount && count % Math.ceil(expectedCount / 100) === 0) {
|
|
1250
|
+
logger(`${Math.floor(count / expectedCount * 100)}% (${count}/ ${expectedCount})`);
|
|
1263
1251
|
}
|
|
1264
1252
|
const g = row;
|
|
1265
1253
|
if (loadContext.geoDefaultIndexed[g.ADDRESS_DETAIL_PID] === undefined) {
|
|
@@ -1268,7 +1256,7 @@ async function loadDefaultGeo(files, directory, state, loadContext, filesCounts)
|
|
|
1268
1256
|
loadContext.geoDefaultIndexed[g.ADDRESS_DETAIL_PID].push(g);
|
|
1269
1257
|
}
|
|
1270
1258
|
count += 1;
|
|
1271
|
-
}
|
|
1259
|
+
}
|
|
1272
1260
|
parser.resume();
|
|
1273
1261
|
}
|
|
1274
1262
|
},
|
|
@@ -1287,9 +1275,9 @@ async function loadAuthFiles(files, directory, loadContext, filesCounts) {
|
|
|
1287
1275
|
const authCodeFiles = files.filter(f => f.match(/Authority Code/));
|
|
1288
1276
|
logger('authCodeFiles', authCodeFiles);
|
|
1289
1277
|
for (const authFile of authCodeFiles) {
|
|
1290
|
-
const contextKey =
|
|
1278
|
+
const contextKey = _nodePath2.default.basename(authFile, _nodePath2.default.extname(authFile));
|
|
1291
1279
|
await new Promise((resolve, reject) => {
|
|
1292
|
-
_papaparse2.default.parse(
|
|
1280
|
+
_papaparse2.default.parse(_nodeFs2.default.createReadStream(`${directory}/${authFile}`), {
|
|
1293
1281
|
delimiter: '|',
|
|
1294
1282
|
header: true,
|
|
1295
1283
|
complete: function (results) {
|
|
@@ -1321,7 +1309,7 @@ async function loadGnaf({
|
|
|
1321
1309
|
logger('Data dir', unzipped);
|
|
1322
1310
|
const contents = await fsp.readdir(unzipped);
|
|
1323
1311
|
logger('Data dir contents', contents);
|
|
1324
|
-
if (contents.length
|
|
1312
|
+
if (contents.length === 0) {
|
|
1325
1313
|
throw new Error(`Data dir '${unzipped}' is empty`);
|
|
1326
1314
|
}
|
|
1327
1315
|
const gnafDir = await (0, _globPromise2.default)('**/G-NAF/', {
|
|
@@ -1331,7 +1319,7 @@ async function loadGnaf({
|
|
|
1331
1319
|
if (gnafDir.length === 0) {
|
|
1332
1320
|
throw new Error(`Cannot find 'G-NAF' directory in Data dir '${unzipped}'`);
|
|
1333
1321
|
}
|
|
1334
|
-
const mainDirectory =
|
|
1322
|
+
const mainDirectory = _nodePath2.default.dirname(`${unzipped}/${gnafDir[0].slice(0, -1)}`);
|
|
1335
1323
|
logger('Main Data dir', mainDirectory);
|
|
1336
1324
|
await loadGnafData(mainDirectory, {
|
|
1337
1325
|
refresh
|
|
@@ -1364,7 +1352,7 @@ async function getAddress(addressId) {
|
|
|
1364
1352
|
uri: `/addresses/${addressId}`
|
|
1365
1353
|
});
|
|
1366
1354
|
// TODO: store hash in address
|
|
1367
|
-
const hash =
|
|
1355
|
+
const hash = _nodeCrypto2.default.createHash('md5').update(JSON.stringify(json)).digest('hex');
|
|
1368
1356
|
return {
|
|
1369
1357
|
link,
|
|
1370
1358
|
json,
|
|
@@ -9,12 +9,12 @@ var _debug = require("debug");
|
|
|
9
9
|
var _debug2 = _interopRequireDefault(_debug);
|
|
10
10
|
var _express = require("express");
|
|
11
11
|
var _express2 = _interopRequireDefault(_express);
|
|
12
|
-
var
|
|
12
|
+
var _nodeHttp = require("node:http");
|
|
13
13
|
var _waycharter = require("@mountainpass/waycharter");
|
|
14
14
|
var _addressService = require("../service/address-service");
|
|
15
15
|
var _version = require("../version");
|
|
16
|
-
var
|
|
17
|
-
var
|
|
16
|
+
var _nodeCrypto = require("node:crypto");
|
|
17
|
+
var _nodeCrypto2 = _interopRequireDefault(_nodeCrypto);
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
19
|
//import connect from 'connect';
|
|
20
20
|
|
|
@@ -85,7 +85,7 @@ function startRest2Server() {
|
|
|
85
85
|
pid: h._id.replace('/addresses/', '')
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
|
-
const responseHash =
|
|
88
|
+
const responseHash = _nodeCrypto2.default.createHash('md5').update(JSON.stringify(body)).digest('hex');
|
|
89
89
|
return {
|
|
90
90
|
body,
|
|
91
91
|
hasMore: page < foundAddresses.body.hits.total.value / PAGE_SIZE - 1,
|
|
@@ -142,7 +142,7 @@ function startRest2Server() {
|
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
|
-
server = (0,
|
|
145
|
+
server = (0, _nodeHttp.createServer)(app);
|
|
146
146
|
return new Promise(resolve => {
|
|
147
147
|
server.listen(serverPort, function () {
|
|
148
148
|
logger('📡 Addressr is listening on port %d ( http://localhost:%d ) ', serverPort, serverPort);
|
package/lib/swagger.js
CHANGED
|
@@ -11,11 +11,11 @@ var _debug = require("debug");
|
|
|
11
11
|
var _debug2 = _interopRequireDefault(_debug);
|
|
12
12
|
var _express = require("express");
|
|
13
13
|
var _express2 = _interopRequireDefault(_express);
|
|
14
|
-
var
|
|
15
|
-
var
|
|
14
|
+
var _nodeFs = require("node:fs");
|
|
15
|
+
var _nodeHttp = require("node:http");
|
|
16
16
|
var _jsYaml = require("js-yaml");
|
|
17
|
-
var
|
|
18
|
-
var
|
|
17
|
+
var _nodePath = require("node:path");
|
|
18
|
+
var _nodePath2 = _interopRequireDefault(_nodePath);
|
|
19
19
|
var _swaggerTools = require("swagger-tools");
|
|
20
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
21
|
//import connect from 'connect';
|
|
@@ -28,13 +28,13 @@ error.log = console.error.bind(console); // eslint-disable-line no-console
|
|
|
28
28
|
|
|
29
29
|
// swaggerRouter configuration
|
|
30
30
|
var options = {
|
|
31
|
-
swaggerUi:
|
|
32
|
-
controllers:
|
|
31
|
+
swaggerUi: _nodePath2.default.join(__dirname, '/swagger.json'),
|
|
32
|
+
controllers: _nodePath2.default.join(__dirname, './controllers'),
|
|
33
33
|
useStubs: process.env.NODE_ENV === 'development' // Conditionally turn on stubs (mock mode)
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
|
|
37
|
-
var spec = (0,
|
|
37
|
+
var spec = (0, _nodeFs.readFileSync)(_nodePath2.default.join(__dirname, 'api/swagger.yaml'), 'utf8');
|
|
38
38
|
var swaggerDoc = exports.swaggerDoc = (0, _jsYaml.safeLoad)(spec);
|
|
39
39
|
global.swaggerDoc = swaggerDoc;
|
|
40
40
|
function swaggerInit() {
|
|
@@ -107,7 +107,7 @@ function startServer() {
|
|
|
107
107
|
// logger(app);
|
|
108
108
|
// logger(middleware);
|
|
109
109
|
|
|
110
|
-
server = (0,
|
|
110
|
+
server = (0, _nodeHttp.createServer)(app);
|
|
111
111
|
server.listen(serverPort, function () {
|
|
112
112
|
logger('📡 Addressr is listening on port %d ( http://localhost:%d ) ', serverPort, serverPort);
|
|
113
113
|
logger('📑 Swagger-ui is available on http://localhost:%d/docs', serverPort);
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mountainpass/addressr",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Australian Address Validation, Search and Autocomplete",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mountain Pass",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"predocker:push": "echo \"$DOCKER_ID_PASS\" | docker login --username \"$DOCKER_ID_USER\" --password-stdin",
|
|
117
117
|
"docker:push": "docker push \"mountainpass/addressr:${npm_package_version}\"",
|
|
118
118
|
"postdocker:push": "docker push \"mountainpass/addressr:latest\"",
|
|
119
|
-
"check-licenses": "license-checker --production --onlyAllow 'MIT;Apache-2.0;ISC;Custom: http://github.com/substack/node-bufferlist;Unlicense;BSD-2-Clause;BSD-3-Clause;WTFPL;0BSD;MIT
|
|
119
|
+
"check-licenses": "license-checker --production --onlyAllow 'MIT;Apache-2.0;ISC;Custom: http://github.com/substack/node-bufferlist;Unlicense;BSD-2-Clause;BSD-3-Clause;WTFPL;0BSD;MIT*;Python-2.0;MPL-2.0' --summary",
|
|
120
120
|
"pre-commit": "lint-staged && npm run check-licenses",
|
|
121
121
|
"check-deps": "dry-aged-deps --check",
|
|
122
122
|
"test:performance": "k6 run --out csv=target/stress.csv test/k6/script.js",
|
|
@@ -125,7 +125,8 @@
|
|
|
125
125
|
"ci:publish": "[ \"$CI\" = true ] && changeset publish || echo \"Dry run: changeset publish\"",
|
|
126
126
|
"push:watch": "bash scripts/push-and-watch.sh",
|
|
127
127
|
"release:watch": "bash scripts/release-watch.sh",
|
|
128
|
-
"test:hooks": "bats .claude/hooks/test/"
|
|
128
|
+
"test:hooks": "bats .claude/hooks/test/",
|
|
129
|
+
"prepare": "husky"
|
|
129
130
|
},
|
|
130
131
|
"bin": {
|
|
131
132
|
"addressr-loader": "lib/bin/addressr-loader.js",
|
|
@@ -202,29 +203,29 @@
|
|
|
202
203
|
"cucumber": "^5.1.0",
|
|
203
204
|
"dry-aged-deps": "^2.6.0",
|
|
204
205
|
"eslint": "^7.9.0",
|
|
205
|
-
"eslint-config-prettier": "^
|
|
206
|
+
"eslint-config-prettier": "^9.1.2",
|
|
206
207
|
"eslint-plugin-chai-friendly": "^0.7.1",
|
|
207
208
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
208
209
|
"eslint-plugin-import": "^2.22.0",
|
|
209
210
|
"eslint-plugin-node": "^11.1.0",
|
|
210
|
-
"eslint-plugin-prettier": "^
|
|
211
|
+
"eslint-plugin-prettier": "^4.2.5",
|
|
211
212
|
"eslint-plugin-promise": "^5.1.0",
|
|
212
213
|
"eslint-plugin-react": "^7.7.0",
|
|
213
214
|
"eslint-plugin-security": "^1.4.0",
|
|
214
215
|
"eslint-plugin-unicorn": "^34.0.1",
|
|
215
216
|
"genversion": "^3.0.0",
|
|
216
|
-
"husky": "^
|
|
217
|
-
"imagemin-lint-staged": "^0.
|
|
217
|
+
"husky": "^9.1.7",
|
|
218
|
+
"imagemin-lint-staged": "^0.5.1",
|
|
218
219
|
"istanbul": "^0.4.5",
|
|
219
220
|
"istanbul-middleware": "^0.2.2",
|
|
220
221
|
"license-checker": "^25.0.1",
|
|
221
|
-
"lint-staged": "^
|
|
222
|
+
"lint-staged": "^15.5.2",
|
|
222
223
|
"nodemon": "^2.0.4",
|
|
223
224
|
"npm-check": "^5.9.0",
|
|
224
225
|
"npm-run-all": "^4.1.5",
|
|
225
226
|
"nyc": "^15.1.0",
|
|
226
|
-
"prettier": "^
|
|
227
|
-
"prettier-config-standard": "^
|
|
227
|
+
"prettier": "^3.8.1",
|
|
228
|
+
"prettier-config-standard": "^7.0.0"
|
|
228
229
|
},
|
|
229
230
|
"repository": {
|
|
230
231
|
"type": "git",
|
|
@@ -235,27 +236,9 @@
|
|
|
235
236
|
},
|
|
236
237
|
"homepage": "https://addressr.io",
|
|
237
238
|
"lint-staged": {
|
|
238
|
-
"*.{js,jsx}":
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
"*.{json,css,md}": [
|
|
243
|
-
"prettier --write",
|
|
244
|
-
"git add"
|
|
245
|
-
],
|
|
246
|
-
"*.{png,jpeg,jpg,gif,svg}": [
|
|
247
|
-
"imagemin-lint-staged",
|
|
248
|
-
"git add"
|
|
249
|
-
],
|
|
250
|
-
".circleci/config.yml": [
|
|
251
|
-
"circleci config validate",
|
|
252
|
-
"git add"
|
|
253
|
-
]
|
|
254
|
-
},
|
|
255
|
-
"husky": {
|
|
256
|
-
"hooks": {
|
|
257
|
-
"pre-commit": "npm run pre-commit",
|
|
258
|
-
"pre-push": "npm run check-deps"
|
|
259
|
-
}
|
|
239
|
+
"*.{js,jsx}": "eslint --fix",
|
|
240
|
+
"*.{json,css,md}": "prettier --write",
|
|
241
|
+
"*.{png,jpeg,jpg,gif,svg}": "imagemin-lint-staged",
|
|
242
|
+
".circleci/config.yml": "circleci config validate"
|
|
260
243
|
}
|
|
261
244
|
}
|
package/scripts/check-version.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
2
|
const { satisfies } = require('semver');
|
|
4
3
|
const { engines } = require('../package');
|
|
5
4
|
|
|
6
5
|
const version = engines.node;
|
|
7
6
|
if (!satisfies(process.version, version)) {
|
|
8
7
|
console.log(
|
|
9
|
-
`Required node version ${version} not satisfied with current version ${process.version}
|
|
8
|
+
`Required node version ${version} not satisfied with current version ${process.version}.`,
|
|
10
9
|
);
|
|
11
10
|
process.exit(1);
|
|
12
11
|
}
|