@medplum/core 0.9.28 → 0.9.31

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/cache.d.ts +34 -0
  3. package/dist/cjs/client.d.ts +1095 -0
  4. package/dist/cjs/crypto.d.ts +9 -0
  5. package/dist/cjs/eventtarget.d.ts +13 -0
  6. package/dist/cjs/fhirpath/atoms.d.ts +150 -0
  7. package/dist/cjs/fhirpath/date.d.ts +1 -0
  8. package/dist/cjs/fhirpath/functions.d.ts +5 -0
  9. package/dist/cjs/fhirpath/index.d.ts +4 -0
  10. package/dist/cjs/fhirpath/parse.d.ts +24 -0
  11. package/dist/cjs/fhirpath/tokenize.d.ts +5 -0
  12. package/dist/cjs/fhirpath/utils.d.ts +95 -0
  13. package/dist/cjs/format.d.ts +21 -0
  14. package/dist/cjs/hl7.d.ts +43 -0
  15. package/dist/cjs/index.d.ts +12 -0
  16. package/dist/cjs/index.js +89 -47
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/index.min.js +1 -1
  19. package/dist/cjs/index.min.js.map +1 -1
  20. package/dist/cjs/jwt.d.ts +5 -0
  21. package/dist/cjs/outcomes.d.ts +30 -0
  22. package/dist/cjs/readablepromise.d.ts +48 -0
  23. package/dist/cjs/search.d.ts +64 -0
  24. package/dist/cjs/searchparams.d.ts +35 -0
  25. package/dist/cjs/storage.d.ts +47 -0
  26. package/dist/cjs/types.d.ts +148 -0
  27. package/dist/cjs/utils.d.ts +245 -0
  28. package/dist/esm/client.d.ts +17 -15
  29. package/dist/esm/client.js +40 -35
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/fhirpath/utils.js +3 -3
  32. package/dist/esm/fhirpath/utils.js.map +1 -1
  33. package/dist/esm/index.js +2 -2
  34. package/dist/esm/index.min.js +1 -1
  35. package/dist/esm/index.min.js.map +1 -1
  36. package/dist/esm/outcomes.d.ts +2 -1
  37. package/dist/esm/outcomes.js +27 -10
  38. package/dist/esm/outcomes.js.map +1 -1
  39. package/dist/esm/utils.d.ts +21 -0
  40. package/dist/esm/utils.js +18 -1
  41. package/dist/esm/utils.js.map +1 -1
  42. package/package.json +3 -3
package/dist/cjs/index.js CHANGED
@@ -614,6 +614,23 @@
614
614
  }
615
615
  return true;
616
616
  }
617
+ /**
618
+ * Creates a deep clone of the input value.
619
+ *
620
+ * Limitations:
621
+ * - Only supports JSON primitives and arrays.
622
+ * - Does not support Functions, lambdas, etc.
623
+ * - Does not support circular references.
624
+ *
625
+ * See: https://web.dev/structured-clone/
626
+ * See: https://stackoverflow.com/questions/40488190/how-is-structured-clone-algorithm-different-from-deep-copy
627
+ *
628
+ * @param input The input to clone.
629
+ * @returns A deep clone of the input.
630
+ */
631
+ function deepClone(input) {
632
+ return JSON.parse(JSON.stringify(input));
633
+ }
617
634
  /**
618
635
  * Returns true if the input string is a UUID.
619
636
  * @param input The input string.
@@ -6196,7 +6213,7 @@
6196
6213
  */
6197
6214
  const globalSchema = baseSchema;
6198
6215
 
6199
- // PKCE auth ased on:
6216
+ // PKCE auth based on:
6200
6217
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6201
6218
  var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6202
6219
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
@@ -6279,16 +6296,13 @@
6279
6296
  if (!options.baseUrl.startsWith('http')) {
6280
6297
  throw new Error('Base URL must start with http or https');
6281
6298
  }
6282
- if (!options.baseUrl.endsWith('/')) {
6283
- throw new Error('Base URL must end with a trailing slash');
6284
- }
6285
6299
  }
6286
6300
  __classPrivateFieldSet(this, _MedplumClient_fetch, (options === null || options === void 0 ? void 0 : options.fetch) || window.fetch.bind(window), "f");
6287
6301
  __classPrivateFieldSet(this, _MedplumClient_createPdf, options === null || options === void 0 ? void 0 : options.createPdf, "f");
6288
6302
  __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
6289
6303
  __classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache((_a = options === null || options === void 0 ? void 0 : options.resourceCacheSize) !== null && _a !== void 0 ? _a : DEFAULT_RESOURCE_CACHE_SIZE), "f");
6290
6304
  __classPrivateFieldSet(this, _MedplumClient_cacheTime, (_b = options === null || options === void 0 ? void 0 : options.cacheTime) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME, "f");
6291
- __classPrivateFieldSet(this, _MedplumClient_baseUrl, (options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
6305
+ __classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
6292
6306
  __classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
6293
6307
  __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
6294
6308
  __classPrivateFieldSet(this, _MedplumClient_tokenUrl, (options === null || options === void 0 ? void 0 : options.tokenUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
@@ -6480,12 +6494,11 @@
6480
6494
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
6481
6495
  *
6482
6496
  * @param newProjectRequest Register request including email and password.
6483
- * @param login The partial login to complete. This should come from the `startNewUser` method.
6484
6497
  * @returns Promise to the authentication response.
6485
6498
  */
6486
- startNewProject(newProjectRequest, login) {
6499
+ startNewProject(newProjectRequest) {
6487
6500
  return __awaiter(this, void 0, void 0, function* () {
6488
- return this.post('auth/newproject', Object.assign(Object.assign({}, newProjectRequest), login));
6501
+ return this.post('auth/newproject', newProjectRequest);
6489
6502
  });
6490
6503
  }
6491
6504
  /**
@@ -6494,12 +6507,11 @@
6494
6507
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
6495
6508
  *
6496
6509
  * @param newPatientRequest Register request including email and password.
6497
- * @param login The partial login to complete. This should come from the `startNewUser` method.
6498
6510
  * @returns Promise to the authentication response.
6499
6511
  */
6500
- startNewPatient(newPatientRequest, login) {
6512
+ startNewPatient(newPatientRequest) {
6501
6513
  return __awaiter(this, void 0, void 0, function* () {
6502
- return this.post('auth/newpatient', Object.assign(Object.assign({}, newPatientRequest), login));
6514
+ return this.post('auth/newpatient', newPatientRequest);
6503
6515
  });
6504
6516
  }
6505
6517
  /**
@@ -6537,7 +6549,6 @@
6537
6549
  */
6538
6550
  signOut() {
6539
6551
  this.clear();
6540
- return Promise.resolve();
6541
6552
  }
6542
6553
  /**
6543
6554
  * Tries to sign in the user.
@@ -6546,15 +6557,17 @@
6546
6557
  * @category Authentication
6547
6558
  */
6548
6559
  signInWithRedirect() {
6549
- const urlParams = new URLSearchParams(window.location.search);
6550
- const code = urlParams.get('code');
6551
- if (!code) {
6552
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
6553
- return undefined;
6554
- }
6555
- else {
6556
- return this.processCode(code);
6557
- }
6560
+ return __awaiter(this, void 0, void 0, function* () {
6561
+ const urlParams = new URLSearchParams(window.location.search);
6562
+ const code = urlParams.get('code');
6563
+ if (!code) {
6564
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
6565
+ return undefined;
6566
+ }
6567
+ else {
6568
+ return this.processCode(code);
6569
+ }
6570
+ });
6558
6571
  }
6559
6572
  /**
6560
6573
  * Tries to sign out the user.
@@ -6945,7 +6958,6 @@
6945
6958
  *
6946
6959
  * ```typescript
6947
6960
  * const result = await medplum.createResourceIfNoneExist(
6948
- * 'Patient?identifier=123',
6949
6961
  * {
6950
6962
  * resourceType: 'Patient',
6951
6963
  * identifier: [{
@@ -6956,14 +6968,16 @@
6956
6968
  * family: 'Smith',
6957
6969
  * given: ['John']
6958
6970
  * }]
6959
- * });
6971
+ * },
6972
+ * 'identifier=123'
6973
+ * );
6960
6974
  * console.log(result.id);
6961
6975
  * ```
6962
6976
  *
6963
6977
  * This method is syntactic sugar for:
6964
6978
  *
6965
6979
  * ```typescript
6966
- * return searchOne(query) ?? createResource(resource);
6980
+ * return searchOne(resourceType, query) ?? createResource(resource);
6967
6981
  * ```
6968
6982
  *
6969
6983
  * The query parameter only contains the search parameters (what would be in the URL following the "?").
@@ -6972,7 +6986,7 @@
6972
6986
  *
6973
6987
  * @category Create
6974
6988
  * @param resource The FHIR resource to create.
6975
- * @param query The search query for an equivalent resource.
6989
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
6976
6990
  * @returns The result of the create operation.
6977
6991
  */
6978
6992
  createResourceIfNoneExist(resource, query) {
@@ -7553,16 +7567,18 @@
7553
7567
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
7554
7568
  });
7555
7569
  }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
7556
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
7557
- const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
7558
- url.searchParams.set('response_type', 'code');
7559
- url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
7560
- url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7561
- url.searchParams.set('redirect_uri', getBaseUrl());
7562
- url.searchParams.set('scope', DEFAULT_SCOPE);
7563
- url.searchParams.set('code_challenge_method', 'S256');
7564
- url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
7565
- window.location.assign(url.toString());
7570
+ return __awaiter(this, void 0, void 0, function* () {
7571
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
7572
+ const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
7573
+ url.searchParams.set('response_type', 'code');
7574
+ url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
7575
+ url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7576
+ url.searchParams.set('redirect_uri', getBaseUrl());
7577
+ url.searchParams.set('scope', DEFAULT_SCOPE);
7578
+ url.searchParams.set('code_challenge_method', 'S256');
7579
+ url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
7580
+ window.location.assign(url.toString());
7581
+ });
7566
7582
  }, _MedplumClient_refresh = function _MedplumClient_refresh() {
7567
7583
  return __awaiter(this, void 0, void 0, function* () {
7568
7584
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
@@ -7638,6 +7654,12 @@
7638
7654
  function getBaseUrl() {
7639
7655
  return window.location.protocol + '//' + window.location.host + '/';
7640
7656
  }
7657
+ function ensureTrailingSlash(url) {
7658
+ if (!url) {
7659
+ return url;
7660
+ }
7661
+ return url.endsWith('/') ? url : url + '/';
7662
+ }
7641
7663
 
7642
7664
  /**
7643
7665
  * Returns a single element array with a typed boolean value.
@@ -7747,7 +7769,7 @@
7747
7769
  }
7748
7770
  }
7749
7771
  }
7750
- if (resultValue === undefined) {
7772
+ if (isEmpty(resultValue)) {
7751
7773
  return undefined;
7752
7774
  }
7753
7775
  if (resultType === 'BackboneElement') {
@@ -7792,7 +7814,7 @@
7792
7814
  }
7793
7815
  }
7794
7816
  }
7795
- if (result === undefined) {
7817
+ if (isEmpty(result)) {
7796
7818
  return undefined;
7797
7819
  }
7798
7820
  if (Array.isArray(result)) {
@@ -10396,7 +10418,8 @@
10396
10418
  const GONE_ID = 'gone';
10397
10419
  const NOT_MODIFIED_ID = 'not-modified';
10398
10420
  const NOT_FOUND_ID = 'not-found';
10399
- const ACCESS_DENIED_ID = 'access-denied';
10421
+ const UNAUTHORIZED_ID = 'unauthorized';
10422
+ const FORBIDDEN_ID = 'forbidden';
10400
10423
  const TOO_MANY_REQUESTS_ID = 'too-many-requests';
10401
10424
  const allOk = {
10402
10425
  resourceType: 'OperationOutcome',
@@ -10450,28 +10473,41 @@
10450
10473
  },
10451
10474
  ],
10452
10475
  };
10453
- const gone = {
10476
+ const unauthorized = {
10454
10477
  resourceType: 'OperationOutcome',
10455
- id: GONE_ID,
10478
+ id: UNAUTHORIZED_ID,
10456
10479
  issue: [
10457
10480
  {
10458
10481
  severity: 'error',
10459
- code: 'gone',
10482
+ code: 'login',
10460
10483
  details: {
10461
- text: 'Gone',
10484
+ text: 'Unauthorized',
10462
10485
  },
10463
10486
  },
10464
10487
  ],
10465
10488
  };
10466
- const accessDenied = {
10489
+ const forbidden = {
10467
10490
  resourceType: 'OperationOutcome',
10468
- id: ACCESS_DENIED_ID,
10491
+ id: FORBIDDEN_ID,
10469
10492
  issue: [
10470
10493
  {
10471
10494
  severity: 'error',
10472
10495
  code: 'forbidden',
10473
10496
  details: {
10474
- text: 'Access Denied',
10497
+ text: 'Forbidden',
10498
+ },
10499
+ },
10500
+ ],
10501
+ };
10502
+ const gone = {
10503
+ resourceType: 'OperationOutcome',
10504
+ id: GONE_ID,
10505
+ issue: [
10506
+ {
10507
+ severity: 'error',
10508
+ code: 'gone',
10509
+ details: {
10510
+ text: 'Gone',
10475
10511
  },
10476
10512
  },
10477
10513
  ],
@@ -10523,7 +10559,10 @@
10523
10559
  else if (outcome.id === NOT_MODIFIED_ID) {
10524
10560
  return 304;
10525
10561
  }
10526
- else if (outcome.id === ACCESS_DENIED_ID) {
10562
+ else if (outcome.id === UNAUTHORIZED_ID) {
10563
+ return 401;
10564
+ }
10565
+ else if (outcome.id === FORBIDDEN_ID) {
10527
10566
  return 403;
10528
10567
  }
10529
10568
  else if (outcome.id === NOT_FOUND_ID) {
@@ -10957,7 +10996,6 @@
10957
10996
  exports.UnaryOperatorAtom = UnaryOperatorAtom;
10958
10997
  exports.UnionAtom = UnionAtom;
10959
10998
  exports.XorAtom = XorAtom;
10960
- exports.accessDenied = accessDenied;
10961
10999
  exports.allOk = allOk;
10962
11000
  exports.arrayBufferToBase64 = arrayBufferToBase64;
10963
11001
  exports.arrayBufferToHex = arrayBufferToHex;
@@ -10972,6 +11010,7 @@
10972
11010
  exports.createSchema = createSchema;
10973
11011
  exports.createTypeSchema = createTypeSchema;
10974
11012
  exports.created = created;
11013
+ exports.deepClone = deepClone;
10975
11014
  exports.deepEquals = deepEquals$1;
10976
11015
  exports.evalFhirPath = evalFhirPath;
10977
11016
  exports.evalFhirPathTyped = evalFhirPathTyped;
@@ -10983,6 +11022,7 @@
10983
11022
  exports.fhirPathNot = fhirPathNot;
10984
11023
  exports.findObservationInterval = findObservationInterval;
10985
11024
  exports.findObservationReferenceRange = findObservationReferenceRange;
11025
+ exports.forbidden = forbidden;
10986
11026
  exports.formatAddress = formatAddress;
10987
11027
  exports.formatDate = formatDate;
10988
11028
  exports.formatDateTime = formatDateTime;
@@ -11011,6 +11051,7 @@
11011
11051
  exports.indexSearchParameter = indexSearchParameter;
11012
11052
  exports.indexStructureDefinition = indexStructureDefinition;
11013
11053
  exports.indexStructureDefinitionBundle = indexStructureDefinitionBundle;
11054
+ exports.isEmpty = isEmpty;
11014
11055
  exports.isGone = isGone;
11015
11056
  exports.isLowerCase = isLowerCase;
11016
11057
  exports.isNotFound = isNotFound;
@@ -11043,6 +11084,7 @@
11043
11084
  exports.toTypedValue = toTypedValue;
11044
11085
  exports.tokenize = tokenize;
11045
11086
  exports.tooManyRequests = tooManyRequests;
11087
+ exports.unauthorized = unauthorized;
11046
11088
 
11047
11089
  Object.defineProperty(exports, '__esModule', { value: true });
11048
11090