@medplum/core 2.0.1 → 2.0.2

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.
@@ -224,7 +224,7 @@ export interface BotEvent<T = Resource | Hl7Message | string | Record<string, an
224
224
  }
225
225
  /**
226
226
  * JSONPatch patch operation.
227
- * Compatible with fast-json-patch Operation.
227
+ * Compatible with fast-json-patch and rfc6902 Operation.
228
228
  */
229
229
  export interface PatchOperation {
230
230
  readonly op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test';
@@ -496,7 +496,7 @@ export declare class MedplumClient extends EventTarget {
496
496
  * Does not invalidate tokens with the server.
497
497
  * @category Authentication
498
498
  */
499
- signOut(): void;
499
+ signOut(): Promise<void>;
500
500
  /**
501
501
  * Tries to sign in the user.
502
502
  * Returns true if the user is signed in.
@@ -5945,6 +5945,30 @@
5945
5945
  type: 'reference',
5946
5946
  expression: resourceType + '.meta.compartment',
5947
5947
  },
5948
+ _profile: {
5949
+ base: [resourceType],
5950
+ code: '_profile',
5951
+ type: 'uri',
5952
+ expression: resourceType + '.meta.profile',
5953
+ },
5954
+ _security: {
5955
+ base: [resourceType],
5956
+ code: '_security',
5957
+ type: 'token',
5958
+ expression: resourceType + '.meta.security',
5959
+ },
5960
+ _source: {
5961
+ base: [resourceType],
5962
+ code: '_source',
5963
+ type: 'uri',
5964
+ expression: resourceType + '.meta.source',
5965
+ },
5966
+ _tag: {
5967
+ base: [resourceType],
5968
+ code: '_tag',
5969
+ type: 'token',
5970
+ expression: resourceType + '.meta.tag',
5971
+ },
5948
5972
  };
5949
5973
  }
5950
5974
  typeSchema.searchParams[searchParam.code] = searchParam;
@@ -6023,7 +6047,7 @@
6023
6047
  // PKCE auth based on:
6024
6048
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6025
6049
  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_request, _MedplumClient_executeAutoBatch, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6026
- const MEDPLUM_VERSION = "2.0.1-89a5b1c5";
6050
+ const MEDPLUM_VERSION = "2.0.2-2d479f42";
6027
6051
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6028
6052
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
6029
6053
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds
@@ -6113,7 +6137,7 @@
6113
6137
  throw new Error('Base URL must start with http or https');
6114
6138
  }
6115
6139
  }
6116
- __classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || window.fetch.bind(window), "f");
6140
+ __classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || getDefaultFetch(), "f");
6117
6141
  __classPrivateFieldSet(this, _MedplumClient_createPdf, options?.createPdf, "f");
6118
6142
  __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
6119
6143
  __classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(options?.resourceCacheSize ?? DEFAULT_RESOURCE_CACHE_SIZE), "f");
@@ -6405,7 +6429,8 @@
6405
6429
  * Does not invalidate tokens with the server.
6406
6430
  * @category Authentication
6407
6431
  */
6408
- signOut() {
6432
+ async signOut() {
6433
+ await this.post(__classPrivateFieldGet(this, _MedplumClient_logoutUrl, "f"), {});
6409
6434
  this.clear();
6410
6435
  }
6411
6436
  /**
@@ -7384,7 +7409,7 @@
7384
7409
  formBody.set('grant_type', 'authorization_code');
7385
7410
  formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7386
7411
  formBody.set('code', code);
7387
- formBody.set('redirect_uri', getBaseUrl());
7412
+ formBody.set('redirect_uri', getWindowOrigin());
7388
7413
  const codeVerifier = sessionStorage.getItem('codeVerifier');
7389
7414
  if (codeVerifier) {
7390
7415
  formBody.set('code_verifier', codeVerifier);
@@ -7562,7 +7587,7 @@
7562
7587
  url.searchParams.set('response_type', 'code');
7563
7588
  url.searchParams.set('state', sessionStorage.getItem('pkceState'));
7564
7589
  url.searchParams.set('client_id', loginRequest.clientId || __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7565
- url.searchParams.set('redirect_uri', loginRequest.redirectUri || getBaseUrl());
7590
+ url.searchParams.set('redirect_uri', loginRequest.redirectUri || getWindowOrigin());
7566
7591
  url.searchParams.set('code_challenge_method', loginRequest.codeChallengeMethod);
7567
7592
  url.searchParams.set('code_challenge', loginRequest.codeChallenge);
7568
7593
  url.searchParams.set('scope', loginRequest.scope || 'openid profile');
@@ -7645,12 +7670,34 @@
7645
7670
  // Silently ignore if this environment does not support storage events
7646
7671
  }
7647
7672
  };
7673
+ /**
7674
+ * Returns the current window if available.
7675
+ * All access to the current window should use this to support SSR such as Next.js.
7676
+ * @returns The current window or undefined if not available.
7677
+ */
7678
+ function getWindow() {
7679
+ return typeof window === 'undefined' ? undefined : window;
7680
+ }
7681
+ /**
7682
+ * Returns the default fetch method.
7683
+ * The default fetch is currently only available in browser environments.
7684
+ * If you want to use SSR such as Next.js, you should pass a custom fetch function.
7685
+ * @returns The default fetch function for the current environment.
7686
+ */
7687
+ function getDefaultFetch() {
7688
+ const window = getWindow();
7689
+ if (!window) {
7690
+ throw new Error('Fetch not available in this environment');
7691
+ }
7692
+ return window.fetch.bind(window);
7693
+ }
7648
7694
  /**
7649
7695
  * Returns the base URL for the current page.
7650
7696
  * @category HTTP
7651
7697
  */
7652
- function getBaseUrl() {
7653
- return window.location.protocol + '//' + window.location.host + '/';
7698
+ function getWindowOrigin() {
7699
+ const window = getWindow();
7700
+ return window ? window.location.protocol + '//' + window.location.host + '/' : '';
7654
7701
  }
7655
7702
  function ensureTrailingSlash(url) {
7656
7703
  if (!url) {