@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.
- package/dist/cjs/client.d.ts +2 -2
- package/dist/cjs/index.cjs +54 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/client.d.ts +2 -2
- package/dist/esm/client.mjs +30 -7
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/types.mjs +24 -0
- package/dist/esm/types.mjs.map +1 -1
- package/package.json +1 -1
package/dist/esm/client.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { createReference, arrayBufferToBase64 } from './utils.mjs';
|
|
|
11
11
|
// PKCE auth based on:
|
|
12
12
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
13
13
|
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;
|
|
14
|
-
const MEDPLUM_VERSION = "2.0.
|
|
14
|
+
const MEDPLUM_VERSION = "2.0.2-2d479f42";
|
|
15
15
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
16
16
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
17
17
|
const DEFAULT_CACHE_TIME = 60000; // 60 seconds
|
|
@@ -101,7 +101,7 @@ class MedplumClient extends EventTarget {
|
|
|
101
101
|
throw new Error('Base URL must start with http or https');
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
__classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch ||
|
|
104
|
+
__classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || getDefaultFetch(), "f");
|
|
105
105
|
__classPrivateFieldSet(this, _MedplumClient_createPdf, options?.createPdf, "f");
|
|
106
106
|
__classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
|
|
107
107
|
__classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(options?.resourceCacheSize ?? DEFAULT_RESOURCE_CACHE_SIZE), "f");
|
|
@@ -393,7 +393,8 @@ class MedplumClient extends EventTarget {
|
|
|
393
393
|
* Does not invalidate tokens with the server.
|
|
394
394
|
* @category Authentication
|
|
395
395
|
*/
|
|
396
|
-
signOut() {
|
|
396
|
+
async signOut() {
|
|
397
|
+
await this.post(__classPrivateFieldGet(this, _MedplumClient_logoutUrl, "f"), {});
|
|
397
398
|
this.clear();
|
|
398
399
|
}
|
|
399
400
|
/**
|
|
@@ -1372,7 +1373,7 @@ class MedplumClient extends EventTarget {
|
|
|
1372
1373
|
formBody.set('grant_type', 'authorization_code');
|
|
1373
1374
|
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
1374
1375
|
formBody.set('code', code);
|
|
1375
|
-
formBody.set('redirect_uri',
|
|
1376
|
+
formBody.set('redirect_uri', getWindowOrigin());
|
|
1376
1377
|
const codeVerifier = sessionStorage.getItem('codeVerifier');
|
|
1377
1378
|
if (codeVerifier) {
|
|
1378
1379
|
formBody.set('code_verifier', codeVerifier);
|
|
@@ -1550,7 +1551,7 @@ async function _MedplumClient_requestAuthorization(loginParams) {
|
|
|
1550
1551
|
url.searchParams.set('response_type', 'code');
|
|
1551
1552
|
url.searchParams.set('state', sessionStorage.getItem('pkceState'));
|
|
1552
1553
|
url.searchParams.set('client_id', loginRequest.clientId || __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
1553
|
-
url.searchParams.set('redirect_uri', loginRequest.redirectUri ||
|
|
1554
|
+
url.searchParams.set('redirect_uri', loginRequest.redirectUri || getWindowOrigin());
|
|
1554
1555
|
url.searchParams.set('code_challenge_method', loginRequest.codeChallengeMethod);
|
|
1555
1556
|
url.searchParams.set('code_challenge', loginRequest.codeChallenge);
|
|
1556
1557
|
url.searchParams.set('scope', loginRequest.scope || 'openid profile');
|
|
@@ -1633,12 +1634,34 @@ async function _MedplumClient_verifyTokens(tokens) {
|
|
|
1633
1634
|
// Silently ignore if this environment does not support storage events
|
|
1634
1635
|
}
|
|
1635
1636
|
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Returns the current window if available.
|
|
1639
|
+
* All access to the current window should use this to support SSR such as Next.js.
|
|
1640
|
+
* @returns The current window or undefined if not available.
|
|
1641
|
+
*/
|
|
1642
|
+
function getWindow() {
|
|
1643
|
+
return typeof window === 'undefined' ? undefined : window;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Returns the default fetch method.
|
|
1647
|
+
* The default fetch is currently only available in browser environments.
|
|
1648
|
+
* If you want to use SSR such as Next.js, you should pass a custom fetch function.
|
|
1649
|
+
* @returns The default fetch function for the current environment.
|
|
1650
|
+
*/
|
|
1651
|
+
function getDefaultFetch() {
|
|
1652
|
+
const window = getWindow();
|
|
1653
|
+
if (!window) {
|
|
1654
|
+
throw new Error('Fetch not available in this environment');
|
|
1655
|
+
}
|
|
1656
|
+
return window.fetch.bind(window);
|
|
1657
|
+
}
|
|
1636
1658
|
/**
|
|
1637
1659
|
* Returns the base URL for the current page.
|
|
1638
1660
|
* @category HTTP
|
|
1639
1661
|
*/
|
|
1640
|
-
function
|
|
1641
|
-
|
|
1662
|
+
function getWindowOrigin() {
|
|
1663
|
+
const window = getWindow();
|
|
1664
|
+
return window ? window.location.protocol + '//' + window.location.host + '/' : '';
|
|
1642
1665
|
}
|
|
1643
1666
|
function ensureTrailingSlash(url) {
|
|
1644
1667
|
if (!url) {
|