Skip to content

Commit 8b642be

Browse files
committed
tests #8
1 parent 470f6f0 commit 8b642be

40 files changed

+4987
-411
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ The Bulk Data Client uses `js` configuration files, but you can think of them as
128128
- *string* **`awsRegion`** - Example: `us-east-1`. Only used if `destination` points to S3. The AWS SDK will first look for this in the shared config file (`~/.aws/config`). Then the SDK will look for an `AWS_REGION` environment variable. Finally, you can override both of these if you set the `awsRegion` variable in your bulk-data client config file.
129129
- *string* **`awsAccessKeyId`** - Only used if `destination` points to S3. The AWS SDK will first look for this in the shared credentials file (`~/.aws/credentials`). You can override this if you set the `awsAccessKeyId` variable in your bulk-data client config file, but only if you also set the `awsSecretAccessKey`.
130130
- *string* **`awsSecretAccessKey`** - Only needed if `destination` points to S3. The AWS SDK will first look for this in the shared credentials file (`~/.aws/credentials`). You can override this if you set the `awsSecretAccessKey` variable in your bulk-data client config file, but only if you also set the `awsAccessKeyId`.
131+
- *object* **`log`** - Optional logging options (see below)
132+
- *boolean* **`log.enabled`** - Set this to false to disable logging. Optional (defaults to true).
133+
- *string* **`log.file`** - Path to the log file. Absolute, or relative to process CWD. If not provided, the file will be called log.ndjson and will be stored in the downloads folder.
134+
- *object* **`log.metadata`** - Key/value pairs to be added to every log entry. Can be used to add useful information (for example which site imported this data).
131135

132136

133137
### Environment Variables
@@ -194,5 +198,6 @@ Features
194198
- [x] Destination directory path
195199
- [x] Destination http
196200
- [x] multiple config files
197-
- [ ] tests
201+
- [ ] tests (~64% coverage)
198202
- [x] Custom kick-off params
203+
- [x] Logging

built/app.js

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const utils_1 = require("./lib/utils");
1212
const BulkDataClient_1 = __importDefault(require("./lib/BulkDataClient"));
1313
const cli_1 = __importDefault(require("./reporters/cli"));
1414
const text_1 = __importDefault(require("./reporters/text"));
15+
const loggers_1 = require("./loggers");
1516
const reporters = {
1617
cli: cli_1.default,
1718
text: text_1.default
@@ -79,9 +80,93 @@ APP.action(async (args) => {
7980
return;
8081
}
8182
}
82-
// console.log(args)
83+
options.log = {
84+
enabled: true,
85+
...(options.log || {})
86+
};
8387
const client = new BulkDataClient_1.default(options);
8488
const reporter = reporters[options.reporter](client);
89+
if (options.log.enabled) {
90+
const logger = (0, loggers_1.createLogger)(options.log);
91+
const startTime = Date.now();
92+
// kickoff -----------------------------------------------------------------
93+
client.on("kickOffEnd", ({ requestParameters, capabilityStatement, response }) => {
94+
logger.log("info", {
95+
eventId: "kickoff",
96+
eventDetail: {
97+
exportUrl: response.requestUrl,
98+
errorCode: response.statusCode >= 400 ? response.statusCode : null,
99+
errorBody: response.statusCode >= 400 ? response.body : null,
100+
softwareName: capabilityStatement.software?.name || null,
101+
softwareVersion: capabilityStatement.software?.version || null,
102+
softwareReleaseDate: capabilityStatement.software?.releaseDate || null,
103+
fhirVersion: capabilityStatement.fhirVersion || null,
104+
requestParameters
105+
}
106+
});
107+
});
108+
// status_progress ---------------------------------------------------------
109+
client.on("exportProgress", e => {
110+
if (!e.virtual) { // skip the artificially triggered 100% event
111+
logger.log("info", {
112+
eventId: "status_progress",
113+
eventDetail: {
114+
body: e.body,
115+
xProgress: e.xProgressHeader,
116+
retryAfter: e.retryAfterHeader
117+
}
118+
});
119+
}
120+
});
121+
// status_error ------------------------------------------------------------
122+
client.on("exportError", eventDetail => {
123+
logger.log("error", {
124+
eventId: "status_error",
125+
eventDetail
126+
});
127+
});
128+
// status_complete ---------------------------------------------------------
129+
client.on("exportComplete", manifest => {
130+
logger.log("info", {
131+
eventId: "status_complete",
132+
eventDetail: {
133+
transactionTime: manifest.transactionTime,
134+
outputFileCount: manifest.output.length,
135+
deletedFileCount: manifest.deleted?.length || 0,
136+
errorFileCount: manifest.error.length
137+
}
138+
});
139+
});
140+
// download_request --------------------------------------------------------
141+
client.on("downloadStart", eventDetail => {
142+
logger.log("info", { eventId: "download_request", eventDetail });
143+
});
144+
// download_complete -------------------------------------------------------
145+
client.on("downloadComplete", eventDetail => {
146+
logger.log("info", { eventId: "download_complete", eventDetail });
147+
});
148+
// download_error ----------------------------------------------------------
149+
client.on("downloadError", eventDetail => {
150+
logger.log("info", { eventId: "download_error", eventDetail });
151+
});
152+
// export_complete ---------------------------------------------------------
153+
client.on("allDownloadsComplete", downloads => {
154+
const eventDetail = {
155+
files: 0,
156+
resources: 0,
157+
bytes: 0,
158+
attachments: 0,
159+
duration: Date.now() - startTime
160+
};
161+
downloads.forEach(d => {
162+
eventDetail.files += 1;
163+
eventDetail.resources += d.resources;
164+
eventDetail.bytes += d.uncompressedBytes;
165+
eventDetail.attachments += d.attachments;
166+
});
167+
logger.log("info", { eventId: "export_complete", eventDetail });
168+
});
169+
}
85170
process.on("SIGINT", () => {
86171
console.log("\nExport canceled.".magenta.bold);
87172
reporter.detach();

built/lib/Broadcaster.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const events_1 = __importDefault(require("events"));
7+
class BroadCaster extends events_1.default {
8+
}
9+
exports.default = new BroadCaster();

0 commit comments

Comments
 (0)