@medplum/core 2.0.3 → 2.0.5

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 (82) hide show
  1. package/dist/cjs/index.cjs +477 -209
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.min.cjs +1 -1
  4. package/dist/esm/client.mjs +18 -21
  5. package/dist/esm/client.mjs.map +1 -1
  6. package/dist/esm/index.min.mjs +1 -1
  7. package/dist/esm/index.mjs +6 -5
  8. package/dist/esm/index.mjs.map +1 -1
  9. package/dist/esm/outcomes.mjs +17 -2
  10. package/dist/esm/outcomes.mjs.map +1 -1
  11. package/dist/esm/{searchparams.mjs → search/details.mjs} +9 -11
  12. package/dist/esm/search/details.mjs.map +1 -0
  13. package/dist/esm/{match.mjs → search/match.mjs} +16 -11
  14. package/dist/esm/search/match.mjs.map +1 -0
  15. package/dist/esm/search/parse.mjs +218 -0
  16. package/dist/esm/search/parse.mjs.map +1 -0
  17. package/dist/esm/{search.mjs → search/search.mjs} +0 -3
  18. package/dist/esm/search/search.mjs.map +1 -0
  19. package/dist/esm/types.mjs +63 -25
  20. package/dist/esm/types.mjs.map +1 -1
  21. package/dist/{esm → types}/client.d.ts +5 -3
  22. package/dist/{esm → types}/index.d.ts +4 -3
  23. package/dist/{esm → types}/outcomes.d.ts +7 -1
  24. package/dist/types/search/parse.d.ts +17 -0
  25. package/dist/{cjs → types}/types.d.ts +30 -7
  26. package/package.json +4 -4
  27. package/tsconfig.build.json +9 -0
  28. package/dist/cjs/client.d.ts +0 -1216
  29. package/dist/cjs/index.d.ts +0 -13
  30. package/dist/cjs/outcomes.d.ts +0 -31
  31. package/dist/esm/cache.d.ts +0 -34
  32. package/dist/esm/crypto.d.ts +0 -9
  33. package/dist/esm/eventtarget.d.ts +0 -13
  34. package/dist/esm/fhirlexer/index.d.ts +0 -2
  35. package/dist/esm/fhirlexer/parse.d.ts +0 -47
  36. package/dist/esm/fhirlexer/tokenize.d.ts +0 -14
  37. package/dist/esm/fhirmapper/parse.d.ts +0 -7
  38. package/dist/esm/fhirmapper/tokenize.d.ts +0 -2
  39. package/dist/esm/fhirpath/atoms.d.ts +0 -120
  40. package/dist/esm/fhirpath/date.d.ts +0 -1
  41. package/dist/esm/fhirpath/functions.d.ts +0 -6
  42. package/dist/esm/fhirpath/index.d.ts +0 -4
  43. package/dist/esm/fhirpath/parse.d.ts +0 -64
  44. package/dist/esm/fhirpath/tokenize.d.ts +0 -4
  45. package/dist/esm/fhirpath/utils.d.ts +0 -95
  46. package/dist/esm/format.d.ts +0 -118
  47. package/dist/esm/hl7.d.ts +0 -136
  48. package/dist/esm/jwt.d.ts +0 -5
  49. package/dist/esm/match.d.ts +0 -9
  50. package/dist/esm/match.mjs.map +0 -1
  51. package/dist/esm/readablepromise.d.ts +0 -48
  52. package/dist/esm/search.d.ts +0 -66
  53. package/dist/esm/search.mjs.map +0 -1
  54. package/dist/esm/searchparams.d.ts +0 -33
  55. package/dist/esm/searchparams.mjs.map +0 -1
  56. package/dist/esm/storage.d.ts +0 -47
  57. package/dist/esm/types.d.ts +0 -177
  58. package/dist/esm/utils.d.ts +0 -259
  59. /package/dist/{cjs → types}/cache.d.ts +0 -0
  60. /package/dist/{cjs → types}/crypto.d.ts +0 -0
  61. /package/dist/{cjs → types}/eventtarget.d.ts +0 -0
  62. /package/dist/{cjs → types}/fhirlexer/index.d.ts +0 -0
  63. /package/dist/{cjs → types}/fhirlexer/parse.d.ts +0 -0
  64. /package/dist/{cjs → types}/fhirlexer/tokenize.d.ts +0 -0
  65. /package/dist/{cjs → types}/fhirmapper/parse.d.ts +0 -0
  66. /package/dist/{cjs → types}/fhirmapper/tokenize.d.ts +0 -0
  67. /package/dist/{cjs → types}/fhirpath/atoms.d.ts +0 -0
  68. /package/dist/{cjs → types}/fhirpath/date.d.ts +0 -0
  69. /package/dist/{cjs → types}/fhirpath/functions.d.ts +0 -0
  70. /package/dist/{cjs → types}/fhirpath/index.d.ts +0 -0
  71. /package/dist/{cjs → types}/fhirpath/parse.d.ts +0 -0
  72. /package/dist/{cjs → types}/fhirpath/tokenize.d.ts +0 -0
  73. /package/dist/{cjs → types}/fhirpath/utils.d.ts +0 -0
  74. /package/dist/{cjs → types}/format.d.ts +0 -0
  75. /package/dist/{cjs → types}/hl7.d.ts +0 -0
  76. /package/dist/{cjs → types}/jwt.d.ts +0 -0
  77. /package/dist/{cjs → types}/readablepromise.d.ts +0 -0
  78. /package/dist/{cjs/searchparams.d.ts → types/search/details.d.ts} +0 -0
  79. /package/dist/{cjs → types/search}/match.d.ts +0 -0
  80. /package/dist/{cjs → types/search}/search.d.ts +0 -0
  81. /package/dist/{cjs → types}/storage.d.ts +0 -0
  82. /package/dist/{cjs → types}/utils.d.ts +0 -0
@@ -3,7 +3,7 @@ import { LRUCache } from './cache.mjs';
3
3
  import { getRandomString, encryptSHA256 } from './crypto.mjs';
4
4
  import { EventTarget } from './eventtarget.mjs';
5
5
  import { parseJWTPayload } from './jwt.mjs';
6
- import { isOk } from './outcomes.mjs';
6
+ import { OperationOutcomeError, normalizeOperationOutcome, isOk } from './outcomes.mjs';
7
7
  import { ReadablePromise } from './readablepromise.mjs';
8
8
  import { ClientStorage } from './storage.mjs';
9
9
  import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.mjs';
@@ -12,7 +12,7 @@ import { createReference, arrayBufferToBase64 } from './utils.mjs';
12
12
  // PKCE auth based on:
13
13
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
14
14
  var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_fhirBaseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_autoBatchTime, _MedplumClient_autoBatchQueue, _MedplumClient_clientId, _MedplumClient_clientSecret, _MedplumClient_autoBatchTimerId, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_cacheResource, _MedplumClient_deleteCacheEntry, _MedplumClient_request, _MedplumClient_fetchWithRetry, _MedplumClient_executeAutoBatch, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
15
- const MEDPLUM_VERSION = "2.0.3-e39c01ab";
15
+ const MEDPLUM_VERSION = "2.0.5-886af1d8";
16
16
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
17
17
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
18
18
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds
@@ -23,7 +23,7 @@ const system = { resourceType: 'Device', id: 'system', deviceName: [{ name: 'Sys
23
23
  /**
24
24
  * The MedplumClient class provides a client for the Medplum FHIR server.
25
25
  *
26
- * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
26
+ * The client can be used in the browser, in a Node.js application, or in a Medplum Bot.
27
27
  *
28
28
  * The client provides helpful methods for common operations such as:
29
29
  * 1) Authenticating
@@ -1404,6 +1404,7 @@ class MedplumClient extends EventTarget {
1404
1404
  /**
1405
1405
  * Starts a new PKCE flow.
1406
1406
  * These PKCE values are stateful, and must survive redirects and page refreshes.
1407
+ * @category Authentication
1407
1408
  */
1408
1409
  async startPkce() {
1409
1410
  const pkceState = getRandomString();
@@ -1419,6 +1420,7 @@ class MedplumClient extends EventTarget {
1419
1420
  * Processes an OAuth authorization code.
1420
1421
  * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
1421
1422
  * @param code The authorization code received by URL parameter.
1423
+ * @category Authentication
1422
1424
  */
1423
1425
  processCode(code) {
1424
1426
  const formBody = new URLSearchParams();
@@ -1426,9 +1428,11 @@ class MedplumClient extends EventTarget {
1426
1428
  formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
1427
1429
  formBody.set('code', code);
1428
1430
  formBody.set('redirect_uri', getWindowOrigin());
1429
- const codeVerifier = sessionStorage.getItem('codeVerifier');
1430
- if (codeVerifier) {
1431
- formBody.set('code_verifier', codeVerifier);
1431
+ if (typeof sessionStorage !== 'undefined') {
1432
+ const codeVerifier = sessionStorage.getItem('codeVerifier');
1433
+ if (codeVerifier) {
1434
+ formBody.set('code_verifier', codeVerifier);
1435
+ }
1432
1436
  }
1433
1437
  return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
1434
1438
  }
@@ -1523,7 +1527,7 @@ async function _MedplumClient_request(method, url, options = {}) {
1523
1527
  throw err;
1524
1528
  }
1525
1529
  if (response.status >= 400) {
1526
- throw obj;
1530
+ throw new OperationOutcomeError(normalizeOperationOutcome(obj));
1527
1531
  }
1528
1532
  return obj;
1529
1533
  }, _MedplumClient_fetchWithRetry = async function _MedplumClient_fetchWithRetry(url, options) {
@@ -1574,7 +1578,7 @@ async function _MedplumClient_executeAutoBatch() {
1574
1578
  const entry = entries[i];
1575
1579
  const responseEntry = response.entry?.[i];
1576
1580
  if (responseEntry?.response?.outcome && !isOk(responseEntry.response.outcome)) {
1577
- entry.reject(responseEntry.response.outcome);
1581
+ entry.reject(new OperationOutcomeError(responseEntry.response.outcome));
1578
1582
  }
1579
1583
  else {
1580
1584
  entry.resolve(responseEntry?.resource);
@@ -1718,14 +1722,6 @@ async function _MedplumClient_verifyTokens(tokens) {
1718
1722
  // Silently ignore if this environment does not support storage events
1719
1723
  }
1720
1724
  };
1721
- /**
1722
- * Returns the current window if available.
1723
- * All access to the current window should use this to support SSR such as Next.js.
1724
- * @returns The current window or undefined if not available.
1725
- */
1726
- function getWindow() {
1727
- return typeof window === 'undefined' ? undefined : window;
1728
- }
1729
1725
  /**
1730
1726
  * Returns the default fetch method.
1731
1727
  * The default fetch is currently only available in browser environments.
@@ -1733,19 +1729,20 @@ function getWindow() {
1733
1729
  * @returns The default fetch function for the current environment.
1734
1730
  */
1735
1731
  function getDefaultFetch() {
1736
- const window = getWindow();
1737
- if (!window) {
1732
+ if (!globalThis.fetch) {
1738
1733
  throw new Error('Fetch not available in this environment');
1739
1734
  }
1740
- return window.fetch.bind(window);
1735
+ return globalThis.fetch.bind(globalThis);
1741
1736
  }
1742
1737
  /**
1743
1738
  * Returns the base URL for the current page.
1744
1739
  * @category HTTP
1745
1740
  */
1746
1741
  function getWindowOrigin() {
1747
- const window = getWindow();
1748
- return window ? window.location.protocol + '//' + window.location.host + '/' : '';
1742
+ if (typeof window === 'undefined') {
1743
+ return '';
1744
+ }
1745
+ return window.location.protocol + '//' + window.location.host + '/';
1749
1746
  }
1750
1747
  function ensureTrailingSlash(url) {
1751
1748
  if (!url) {