@medplum/agent 5.0.8 → 5.0.10

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.
Files changed (2) hide show
  1. package/dist/cjs/index.cjs +67 -34
  2. package/package.json +7 -7
@@ -54337,7 +54337,7 @@ var require_package = __commonJS({
54337
54337
  module2.exports = {
54338
54338
  name: "winston",
54339
54339
  description: "A logger for just about everything.",
54340
- version: "3.18.3",
54340
+ version: "3.19.0",
54341
54341
  author: "Charlie Robbins <charlie.robbins@gmail.com>",
54342
54342
  maintainers: [
54343
54343
  "David Hyde <dabh@alumni.stanford.edu>"
@@ -54383,9 +54383,8 @@ var require_package = __commonJS({
54383
54383
  "cross-spawn-async": "^2.2.5",
54384
54384
  eslint: "^8.57.0",
54385
54385
  hock: "^1.4.1",
54386
- mocha: "^10.3.0",
54387
- nyc: "^17.1.0",
54388
- rimraf: "5.0.1",
54386
+ jest: "^29.7.0",
54387
+ rimraf: "5.0.10",
54389
54388
  split2: "^4.1.0",
54390
54389
  "std-mocks": "^2.0.0",
54391
54390
  through2: "^4.0.2",
@@ -54396,11 +54395,12 @@ var require_package = __commonJS({
54396
54395
  types: "./index.d.ts",
54397
54396
  scripts: {
54398
54397
  lint: "eslint lib/*.js lib/winston/*.js lib/winston/**/*.js --resolve-plugins-relative-to ./node_modules/@dabh/eslint-config-populist",
54399
- test: "rimraf test/fixtures/logs/* && mocha",
54400
- "test:coverage": "nyc npm run test:unit",
54401
- "test:unit": "mocha test/unit",
54402
- "test:integration": "mocha test/integration",
54403
- build: "rimraf dist && babel lib -d dist",
54398
+ test: "jest",
54399
+ "test:unit": "jest -c test/jest.config.unit.js",
54400
+ "test:integration": "jest -c test/jest.config.integration.js",
54401
+ "test:typescript": "npx --package typescript tsc --project test",
54402
+ build: "babel lib -d dist",
54403
+ prebuild: "rimraf dist",
54404
54404
  prepublishOnly: "npm run build"
54405
54405
  },
54406
54406
  engines: {
@@ -59996,6 +59996,28 @@ var require_file = __commonJS({
59996
59996
  }
59997
59997
  }
59998
59998
  }
59999
+ /**
60000
+ * Called by Node.js Writable stream before emitting 'finish'.
60001
+ * Ensures all buffered data is flushed to the underlying file stream
60002
+ * before the transport signals completion.
60003
+ * @param {Function} callback - Callback to signal completion.
60004
+ * @private
60005
+ */
60006
+ _final(callback) {
60007
+ if (this._opening) {
60008
+ this.once("open", () => this._final(callback));
60009
+ return;
60010
+ }
60011
+ this._stream.end();
60012
+ if (!this._dest) {
60013
+ return callback();
60014
+ }
60015
+ if (this._dest.writableFinished) {
60016
+ return callback();
60017
+ }
60018
+ this._dest.once("finish", callback);
60019
+ this._dest.once("error", callback);
60020
+ }
59999
60021
  /**
60000
60022
  * Core logging method exposed to Winston. Metadata is optional.
60001
60023
  * @param {Object} info - TODO: add param description.
@@ -61669,6 +61691,7 @@ var require_logger = __commonJS({
61669
61691
  if (info instanceof Error) {
61670
61692
  infoClone.stack = info.stack;
61671
61693
  infoClone.message = info.message;
61694
+ infoClone.cause = info.cause;
61672
61695
  }
61673
61696
  logger.write(infoClone);
61674
61697
  }
@@ -67624,7 +67647,7 @@ var ur = class {
67624
67647
  }
67625
67648
  consumeAndParse(e = 1 / 0) {
67626
67649
  let t = this.consume(), n = this.prefixParselets[t.id];
67627
- if (!n) throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);
67650
+ if (!n) throw new Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);
67628
67651
  let i = n.parse(this, t);
67629
67652
  for (; e > this.getPrecedence(); ) {
67630
67653
  let o2 = this.consume();
@@ -67639,14 +67662,14 @@ var ur = class {
67639
67662
  return t ? t.precedence : 1 / 0;
67640
67663
  }
67641
67664
  consume(e, t) {
67642
- if (!this.tokens.length) throw Error("Cant consume unknown more tokens.");
67665
+ if (!this.tokens.length) throw new Error("Cant consume unknown more tokens.");
67643
67666
  if (e && this.peek()?.id !== e) {
67644
67667
  let n = this.peek();
67645
- throw Error(`Expected ${e} but got "${n.id}" (${n.value}) at line ${n.line} column ${n.column}.`);
67668
+ throw new Error(`Expected ${e} but got "${n.id}" (${n.value}) at line ${n.line} column ${n.column}.`);
67646
67669
  }
67647
67670
  if (t && this.peek()?.value !== t) {
67648
67671
  let n = this.peek();
67649
- throw Error(`Expected "${t}" but got "${n.value}" at line ${n.line} column ${n.column}.`);
67672
+ throw new Error(`Expected "${t}" but got "${n.value}" at line ${n.line} column ${n.column}.`);
67650
67673
  }
67651
67674
  return this.tokens.shift();
67652
67675
  }
@@ -68216,7 +68239,7 @@ function si(r6) {
68216
68239
  }
68217
68240
  function ai(r6) {
68218
68241
  let e = ci(r6), t = new Uint8Array(e), n = new Array(t.length);
68219
- for (let i = 0; i < t.length; i++) n[i] = String.fromCharCode(t[i]);
68242
+ for (let i = 0; i < t.length; i++) n[i] = String.fromCodePoint(t[i]);
68220
68243
  return window.btoa(n.join(""));
68221
68244
  }
68222
68245
  function ci(r6) {
@@ -68256,7 +68279,7 @@ function fi(r6) {
68256
68279
  return typeof r6 == "object" && !Array.isArray(r6) && !(r6 instanceof URLSearchParams) && (r6 = Object.fromEntries(Object.entries(r6).filter((e) => e[1] !== void 0))), new URLSearchParams(r6).toString();
68257
68280
  }
68258
68281
  var ds = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-_]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-_]*[A-Za-z0-9])$/;
68259
- function jl(r6) {
68282
+ function $l(r6) {
68260
68283
  return ds.test(r6);
68261
68284
  }
68262
68285
  function Xe(r6, e) {
@@ -68822,7 +68845,7 @@ var ie = { assign(r6) {
68822
68845
  } };
68823
68846
  function fa(r6) {
68824
68847
  if (q()) {
68825
- let t = window.atob(r6), n = Uint8Array.from(t, (i) => i.charCodeAt(0));
68848
+ let t = window.atob(r6), n = Uint8Array.from(t, (i) => i.codePointAt(0));
68826
68849
  return new window.TextDecoder().decode(n);
68827
68850
  }
68828
68851
  let e = Xr();
@@ -68831,7 +68854,7 @@ function fa(r6) {
68831
68854
  }
68832
68855
  function Wt(r6) {
68833
68856
  if (q()) {
68834
- let t = new window.TextEncoder().encode(r6), n = String.fromCharCode.apply(null, t);
68857
+ let t = new window.TextEncoder().encode(r6), n = String.fromCodePoint.apply(null, t);
68835
68858
  return window.btoa(n);
68836
68859
  }
68837
68860
  let e = Xr();
@@ -68851,7 +68874,7 @@ async function Vi(r6) {
68851
68874
  return crypto.subtle.digest("SHA-256", new TextEncoder().encode(r6));
68852
68875
  }
68853
68876
  function oe() {
68854
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g, (r6) => {
68877
+ return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g, (r6) => {
68855
68878
  let e = Math.trunc(Math.random() * 16);
68856
68879
  return (r6 === "x" ? e : e & 3 | 8).toString(16);
68857
68880
  });
@@ -69528,7 +69551,7 @@ var zt = class {
69528
69551
  return this.masterSubEmitter || (this.masterSubEmitter = new it(...Array.from(this.criteriaEntries.keys()))), this.masterSubEmitter;
69529
69552
  }
69530
69553
  };
69531
- var an = "5.0.8-2b1f5fb";
69554
+ var an = "5.0.10-1efb88d";
69532
69555
  var La = w.FHIR_JSON + ", */*; q=0.1";
69533
69556
  var Fa = "https://api.medplum.com/";
69534
69557
  var Na = 1e3;
@@ -69577,8 +69600,9 @@ var Jt = class extends Z {
69577
69600
  c(this, "initPromise");
69578
69601
  c(this, "initComplete", true);
69579
69602
  c(this, "keyValueClient");
69603
+ c(this, "logLevel");
69580
69604
  if (t?.baseUrl && !t.baseUrl.startsWith("http")) throw new Error("Base URL must start with http or https");
69581
- this.options = t ?? {}, this.fetch = t?.fetch ?? Ha(), this.storage = t?.storage ?? new nt(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Hr(t?.baseUrl ?? Fa), this.fhirBaseUrl = H(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = H(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = H(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = H(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = H(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.credentialsInHeader = t?.authCredentialsMethod === "header", this.defaultHeaders = t?.defaultHeaders ?? {}, this.onUnauthenticated = t?.onUnauthenticated, this.refreshGracePeriod = t?.refreshGracePeriod ?? Wa, this.cacheTime = t?.cacheTime ?? (q() ? Ua : Ba), this.cacheTime > 0 ? this.requestCache = new Ve(t?.resourceCacheSize ?? Na) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken && this.setAccessToken(t.accessToken), this.storage.getInitPromise === void 0 ? (t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initPromise = Promise.resolve(), this.dispatchEvent({ type: "storageInitialized" })) : (this.initComplete = false, this.initPromise = this.storage.getInitPromise(), this.initPromise.then(() => {
69605
+ this.options = t ?? {}, this.fetch = t?.fetch ?? Ha(), this.storage = t?.storage ?? new nt(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Hr(t?.baseUrl ?? Fa), this.fhirBaseUrl = H(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = H(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = H(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = H(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = H(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.credentialsInHeader = t?.authCredentialsMethod === "header", this.defaultHeaders = t?.defaultHeaders ?? {}, this.onUnauthenticated = t?.onUnauthenticated, this.refreshGracePeriod = t?.refreshGracePeriod ?? Wa, this.logLevel = this.initializeLogLevel(t), this.cacheTime = t?.cacheTime ?? (q() ? Ua : Ba), this.cacheTime > 0 ? this.requestCache = new Ve(t?.resourceCacheSize ?? Na) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken && this.setAccessToken(t.accessToken), this.storage.getInitPromise === void 0 ? (t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initPromise = Promise.resolve(), this.dispatchEvent({ type: "storageInitialized" })) : (this.initComplete = false, this.initPromise = this.storage.getInitPromise(), this.initPromise.then(() => {
69582
69606
  t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initComplete = true, this.dispatchEvent({ type: "storageInitialized" });
69583
69607
  }).catch((n) => {
69584
69608
  console.error(n), this.initComplete = true, this.dispatchEvent({ type: "storageInitFailed", payload: { error: n } });
@@ -69590,6 +69614,9 @@ var Jt = class extends Z {
69590
69614
  getInitPromise() {
69591
69615
  return this.initPromise;
69592
69616
  }
69617
+ initializeLogLevel(t) {
69618
+ return t?.logLevel ? t.logLevel : t?.verbose !== void 0 && t.verbose ? "verbose" : "none";
69619
+ }
69593
69620
  async attemptResumeActiveLogin() {
69594
69621
  let t = this.getActiveLogin();
69595
69622
  t && (this.setAccessToken(t.accessToken, t.refreshToken), await this.refreshProfile());
@@ -70111,9 +70138,9 @@ var Jt = class extends Z {
70111
70138
  t.startsWith("http") || (t = H(this.baseUrl, t));
70112
70139
  let i = n?.maxRetries ?? 2;
70113
70140
  for (let o2 = 0; o2 <= i; o2++) try {
70114
- this.options.verbose && this.logRequest(t, n);
70141
+ this.logLevel !== "none" && this.logRequest(t, n);
70115
70142
  let s = await this.fetch(t, n);
70116
- if (this.options.verbose && this.logResponse(s), this.setCurrentRateLimit(s), o2 >= i || !Ja(s)) return s;
70143
+ if (this.logLevel !== "none" && this.logResponse(s), this.setCurrentRateLimit(s), o2 >= i || !Ja(s)) return s;
70117
70144
  let a = this.getRetryDelay(o2), u2 = n.maxRetryTime ?? 2e3;
70118
70145
  if (a > u2) return s;
70119
70146
  await $r(a);
@@ -70123,13 +70150,13 @@ var Jt = class extends Z {
70123
70150
  throw new Error("Unreachable");
70124
70151
  }
70125
70152
  logRequest(t, n) {
70126
- if (console.log(`> ${n.method} ${t}`), n.headers) {
70153
+ if (console.log(`> ${n.method} ${t}`), this.logLevel === "verbose" && n.headers) {
70127
70154
  let i = n.headers;
70128
70155
  for (let o2 of Rt(Object.keys(i))) console.log(`> ${o2}: ${i[o2]}`);
70129
70156
  }
70130
70157
  }
70131
70158
  logResponse(t) {
70132
- console.log(`< ${t.status} ${t.statusText}`), t.headers && t.headers.forEach((n, i) => console.log(`< ${i}: ${n}`));
70159
+ console.log(`< ${t.status} ${t.statusText}`), this.logLevel === "verbose" && t.headers && t.headers.forEach((n, i) => console.log(`< ${i}: ${n}`));
70133
70160
  }
70134
70161
  setCurrentRateLimit(t) {
70135
70162
  if (!t?.headers || typeof t.headers.get != "function") return;
@@ -70242,8 +70269,14 @@ var Jt = class extends Z {
70242
70269
  setBasicAuth(t, n) {
70243
70270
  this.clientId = t, this.clientSecret = n, this.basicAuth = Wt(t + ":" + n);
70244
70271
  }
70272
+ setLogLevel(t) {
70273
+ this.logLevel = t, this.options.verbose = t === "verbose";
70274
+ }
70275
+ getLogLevel() {
70276
+ return this.logLevel;
70277
+ }
70245
70278
  setVerbose(t) {
70246
- this.options.verbose = t;
70279
+ this.logLevel = t ? "verbose" : "none", this.options.verbose = t;
70247
70280
  }
70248
70281
  async fhircastSubscribe(t, n) {
70249
70282
  if (!(typeof t == "string" && t !== "")) throw new f(g("Invalid topic provided. Topic must be a valid string."));
@@ -70555,7 +70588,7 @@ var mo = class r5 {
70555
70588
  this.write(JSON.stringify({ level: Fc[e], timestamp: (/* @__PURE__ */ new Date()).toISOString(), msg: this.prefix ? `${this.prefix}${t}` : t, ...i, ...this.metadata }));
70556
70589
  }
70557
70590
  };
70558
- function Zh(r6) {
70591
+ function em(r6) {
70559
70592
  let e = $e[r6.toUpperCase()];
70560
70593
  if (e === void 0) throw new Error(`Invalid log level: ${r6}`);
70561
70594
  return e;
@@ -70608,7 +70641,7 @@ async function xn(r6, e, t) {
70608
70641
  function Xc(r6) {
70609
70642
  return /^\d+\.\d+\.\d+(-[0-9a-z]{7})?$/.test(r6);
70610
70643
  }
70611
- async function Pm(r6, e) {
70644
+ async function wm(r6, e) {
70612
70645
  if (!Xc(e)) return false;
70613
70646
  try {
70614
70647
  await xn(r6, e);
@@ -70617,7 +70650,7 @@ async function Pm(r6, e) {
70617
70650
  }
70618
70651
  return true;
70619
70652
  }
70620
- async function wm(r6) {
70653
+ async function Am(r6) {
70621
70654
  let e = await xn(r6);
70622
70655
  if (!e.tag_name.startsWith("v")) throw new Error(`Invalid release name found. Release tag '${e.tag_name}' did not start with 'v'`);
70623
70656
  return e.tag_name.slice(1);
@@ -72160,7 +72193,7 @@ function parseLoggerConfigFromArgs(args) {
72160
72193
  let configValue;
72161
72194
  if (settingName === "logLevel") {
72162
72195
  try {
72163
- configValue = Zh(propVal);
72196
+ configValue = em(propVal);
72164
72197
  } catch (err) {
72165
72198
  warnings.push(`Error while parsing ${propName}: ${Me(err)}`);
72166
72199
  }
@@ -73089,7 +73122,7 @@ IPv6 is currently unsupported.`;
73089
73122
  this.log.error(errMsg);
73090
73123
  throw new Error(errMsg);
73091
73124
  }
73092
- if (!((0, import_node_net4.isIPv4)(message.remote) || jl(message.remote))) {
73125
+ if (!((0, import_node_net4.isIPv4)(message.remote) || $l(message.remote))) {
73093
73126
  const errMsg = `Attempted to ping an invalid host.
73094
73127
 
73095
73128
  "${message.remote}" is not a valid IPv4 address or a resolvable hostname.`;
@@ -73164,7 +73197,7 @@ ${result}`);
73164
73197
  return;
73165
73198
  }
73166
73199
  let child;
73167
- if (message.version && !await Pm("agent-upgrader", message.version)) {
73200
+ if (message.version && !await wm("agent-upgrader", message.version)) {
73168
73201
  const versionTag = message.version ? `v${message.version}` : "latest";
73169
73202
  const errMsg = `Error during upgrading to version '${versionTag}'. '${message.version}' is not a valid version`;
73170
73203
  this.log.error(errMsg);
@@ -73175,7 +73208,7 @@ ${result}`);
73175
73208
  });
73176
73209
  return;
73177
73210
  }
73178
- const targetVersion = message.version ?? await wm("agent-upgrader");
73211
+ const targetVersion = message.version ?? await Am("agent-upgrader");
73179
73212
  if (an.startsWith(targetVersion)) {
73180
73213
  if (!message?.force) {
73181
73214
  this.log.info(`Attempted to upgrade to version ${targetVersion}, but agent is already on that version`);
@@ -73463,7 +73496,7 @@ async function agentMain(argv) {
73463
73496
  for (const warning of warnings) {
73464
73497
  mainLogger.warn(warning);
73465
73498
  }
73466
- const app = new App(medplum, agentId, args.logLevel ? Zh(args.logLevel) : void 0, {
73499
+ const app = new App(medplum, agentId, args.logLevel ? em(args.logLevel) : void 0, {
73467
73500
  mainLogger,
73468
73501
  channelLogger
73469
73502
  });
@@ -73508,7 +73541,7 @@ async function upgraderMain(argv) {
73508
73541
  if (argv[3] && !Xc(argv[3])) {
73509
73542
  throw new Error("Invalid version specified");
73510
73543
  }
73511
- const version = argv[3] ?? await wm("agent-upgrader");
73544
+ const version = argv[3] ?? await Am("agent-upgrader");
73512
73545
  const binPath = getReleaseBinPath(version);
73513
73546
  if (!(0, import_node_fs6.existsSync)(binPath)) {
73514
73547
  globalLogger.info(`Could not find binary at "${binPath}". Downloading release from GitHub...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/agent",
3
- "version": "5.0.8",
3
+ "version": "5.0.10",
4
4
  "description": "Medplum Agent",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "bugs": {
@@ -26,18 +26,18 @@
26
26
  "test": "jest --runInBand"
27
27
  },
28
28
  "dependencies": {
29
- "@medplum/core": "5.0.8",
30
- "@medplum/hl7": "5.0.8",
29
+ "@medplum/core": "5.0.10",
30
+ "@medplum/hl7": "5.0.10",
31
31
  "dcmjs-dimse": "0.3.1",
32
- "iconv-lite": "0.7.0",
32
+ "iconv-lite": "0.7.1",
33
33
  "semver": "7.7.3",
34
- "winston": "3.18.3",
34
+ "winston": "3.19.0",
35
35
  "winston-daily-rotate-file": "5.0.0",
36
36
  "ws": "8.18.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@medplum/fhirtypes": "5.0.8",
40
- "@medplum/mock": "5.0.8",
39
+ "@medplum/fhirtypes": "5.0.10",
40
+ "@medplum/mock": "5.0.10",
41
41
  "@types/async-eventemitter": "0.2.4",
42
42
  "@types/ws": "8.18.1",
43
43
  "mock-socket": "9.3.1",