@medplum/core 2.0.2 → 2.0.3
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/README.md +7 -3
- package/dist/cjs/client.d.ts +11 -0
- package/dist/cjs/index.cjs +318 -225
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/outcomes.d.ts +1 -0
- package/dist/esm/base-schema.json.mjs +7 -0
- package/dist/esm/base-schema.json.mjs.map +1 -1
- package/dist/esm/client.d.ts +11 -0
- package/dist/esm/client.mjs +106 -22
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/outcomes.d.ts +1 -0
- package/dist/esm/outcomes.mjs +6 -4
- package/dist/esm/outcomes.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-schema.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-schema.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -517,8 +517,19 @@ export declare class MedplumClient extends EventTarget {
|
|
|
517
517
|
* @param clientId The external client ID.
|
|
518
518
|
* @param redirectUri The external identity provider redirect URI.
|
|
519
519
|
* @param baseLogin The Medplum login request.
|
|
520
|
+
* @category Authentication
|
|
520
521
|
*/
|
|
521
522
|
signInWithExternalAuth(authorizeUrl: string, clientId: string, redirectUri: string, baseLogin: BaseLoginRequest): Promise<void>;
|
|
523
|
+
/**
|
|
524
|
+
* Builds the external identity provider redirect URI.
|
|
525
|
+
* @param authorizeUrl The external authorization URL.
|
|
526
|
+
* @param clientId The external client ID.
|
|
527
|
+
* @param redirectUri The external identity provider redirect URI.
|
|
528
|
+
* @param loginRequest The Medplum login request.
|
|
529
|
+
* @returns The external identity provider redirect URI.
|
|
530
|
+
* @category Authentication
|
|
531
|
+
*/
|
|
532
|
+
getExternalAuthRedirectUri(authorizeUrl: string, clientId: string, redirectUri: string, loginRequest: BaseLoginRequest): string;
|
|
522
533
|
/**
|
|
523
534
|
* Builds a FHIR URL from a collection of URL path components.
|
|
524
535
|
* For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
|
package/dist/esm/client.mjs
CHANGED
|
@@ -3,6 +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
7
|
import { ReadablePromise } from './readablepromise.mjs';
|
|
7
8
|
import { ClientStorage } from './storage.mjs';
|
|
8
9
|
import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.mjs';
|
|
@@ -10,14 +11,15 @@ import { createReference, arrayBufferToBase64 } from './utils.mjs';
|
|
|
10
11
|
|
|
11
12
|
// PKCE auth based on:
|
|
12
13
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
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
|
+
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
16
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
16
17
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
17
18
|
const DEFAULT_CACHE_TIME = 60000; // 60 seconds
|
|
18
19
|
const JSON_CONTENT_TYPE = 'application/json';
|
|
19
20
|
const FHIR_CONTENT_TYPE = 'application/fhir+json';
|
|
20
21
|
const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
22
|
+
const system = { resourceType: 'Device', id: 'system', deviceName: [{ name: 'System' }] };
|
|
21
23
|
/**
|
|
22
24
|
* The MedplumClient class provides a client for the Medplum FHIR server.
|
|
23
25
|
*
|
|
@@ -429,16 +431,29 @@ class MedplumClient extends EventTarget {
|
|
|
429
431
|
* @param clientId The external client ID.
|
|
430
432
|
* @param redirectUri The external identity provider redirect URI.
|
|
431
433
|
* @param baseLogin The Medplum login request.
|
|
434
|
+
* @category Authentication
|
|
432
435
|
*/
|
|
433
436
|
async signInWithExternalAuth(authorizeUrl, clientId, redirectUri, baseLogin) {
|
|
434
437
|
const loginRequest = await this.ensureCodeChallenge(baseLogin);
|
|
438
|
+
window.location.assign(this.getExternalAuthRedirectUri(authorizeUrl, clientId, redirectUri, loginRequest));
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Builds the external identity provider redirect URI.
|
|
442
|
+
* @param authorizeUrl The external authorization URL.
|
|
443
|
+
* @param clientId The external client ID.
|
|
444
|
+
* @param redirectUri The external identity provider redirect URI.
|
|
445
|
+
* @param loginRequest The Medplum login request.
|
|
446
|
+
* @returns The external identity provider redirect URI.
|
|
447
|
+
* @category Authentication
|
|
448
|
+
*/
|
|
449
|
+
getExternalAuthRedirectUri(authorizeUrl, clientId, redirectUri, loginRequest) {
|
|
435
450
|
const url = new URL(authorizeUrl);
|
|
436
451
|
url.searchParams.set('response_type', 'code');
|
|
437
452
|
url.searchParams.set('client_id', clientId);
|
|
438
453
|
url.searchParams.set('redirect_uri', redirectUri);
|
|
439
454
|
url.searchParams.set('scope', 'openid profile email');
|
|
440
455
|
url.searchParams.set('state', JSON.stringify(loginRequest));
|
|
441
|
-
|
|
456
|
+
return url.toString();
|
|
442
457
|
}
|
|
443
458
|
/**
|
|
444
459
|
* Builds a FHIR URL from a collection of URL path components.
|
|
@@ -513,7 +528,23 @@ class MedplumClient extends EventTarget {
|
|
|
513
528
|
* @returns Promise to the search result bundle.
|
|
514
529
|
*/
|
|
515
530
|
search(resourceType, query, options = {}) {
|
|
516
|
-
|
|
531
|
+
const url = this.fhirSearchUrl(resourceType, query);
|
|
532
|
+
const cacheKey = url.toString() + '-search';
|
|
533
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, options);
|
|
534
|
+
if (cached) {
|
|
535
|
+
return cached.value;
|
|
536
|
+
}
|
|
537
|
+
const promise = new ReadablePromise((async () => {
|
|
538
|
+
const bundle = await this.get(url, options);
|
|
539
|
+
if (bundle.entry) {
|
|
540
|
+
for (const entry of bundle.entry) {
|
|
541
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_cacheResource).call(this, entry.resource);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return bundle;
|
|
545
|
+
})());
|
|
546
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
547
|
+
return promise;
|
|
517
548
|
}
|
|
518
549
|
/**
|
|
519
550
|
* Sends a FHIR search request for a single resource.
|
|
@@ -622,6 +653,9 @@ class MedplumClient extends EventTarget {
|
|
|
622
653
|
if (!refString) {
|
|
623
654
|
return undefined;
|
|
624
655
|
}
|
|
656
|
+
if (refString === 'system') {
|
|
657
|
+
return system;
|
|
658
|
+
}
|
|
625
659
|
const [resourceType, id] = refString.split('/');
|
|
626
660
|
if (!resourceType || !id) {
|
|
627
661
|
return undefined;
|
|
@@ -674,6 +708,9 @@ class MedplumClient extends EventTarget {
|
|
|
674
708
|
if (!refString) {
|
|
675
709
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
676
710
|
}
|
|
711
|
+
if (refString === 'system') {
|
|
712
|
+
return new ReadablePromise(Promise.resolve(system));
|
|
713
|
+
}
|
|
677
714
|
const [resourceType, id] = refString.split('/');
|
|
678
715
|
if (!resourceType || !id) {
|
|
679
716
|
return new ReadablePromise(Promise.reject(new Error('Invalid reference')));
|
|
@@ -698,11 +735,17 @@ class MedplumClient extends EventTarget {
|
|
|
698
735
|
* @param resourceType The FHIR resource type.
|
|
699
736
|
* @returns Promise to a schema with the requested resource type.
|
|
700
737
|
*/
|
|
701
|
-
|
|
738
|
+
requestSchema(resourceType) {
|
|
702
739
|
if (resourceType in globalSchema.types) {
|
|
703
|
-
return globalSchema;
|
|
740
|
+
return Promise.resolve(globalSchema);
|
|
741
|
+
}
|
|
742
|
+
const cacheKey = resourceType + '-requestSchema';
|
|
743
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, undefined);
|
|
744
|
+
if (cached) {
|
|
745
|
+
return cached.value;
|
|
704
746
|
}
|
|
705
|
-
const
|
|
747
|
+
const promise = new ReadablePromise((async () => {
|
|
748
|
+
const query = `{
|
|
706
749
|
StructureDefinitionList(name: "${resourceType}") {
|
|
707
750
|
name,
|
|
708
751
|
description,
|
|
@@ -731,14 +774,17 @@ class MedplumClient extends EventTarget {
|
|
|
731
774
|
target
|
|
732
775
|
}
|
|
733
776
|
}`.replace(/\s+/g, ' ');
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
777
|
+
const response = (await this.graphql(query));
|
|
778
|
+
for (const structureDefinition of response.data.StructureDefinitionList) {
|
|
779
|
+
indexStructureDefinition(structureDefinition);
|
|
780
|
+
}
|
|
781
|
+
for (const searchParameter of response.data.SearchParameterList) {
|
|
782
|
+
indexSearchParameter(searchParameter);
|
|
783
|
+
}
|
|
784
|
+
return globalSchema;
|
|
785
|
+
})());
|
|
786
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
787
|
+
return promise;
|
|
742
788
|
}
|
|
743
789
|
/**
|
|
744
790
|
* Reads resource history by resource type and ID.
|
|
@@ -1039,10 +1085,15 @@ class MedplumClient extends EventTarget {
|
|
|
1039
1085
|
throw new Error('Missing id');
|
|
1040
1086
|
}
|
|
1041
1087
|
this.invalidateSearches(resource.resourceType);
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1088
|
+
let result = await this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
1089
|
+
if (!result) {
|
|
1090
|
+
// On 304 not modified, result will be undefined
|
|
1091
|
+
// Return the user input instead
|
|
1092
|
+
// return result ?? resource;
|
|
1093
|
+
result = resource;
|
|
1094
|
+
}
|
|
1095
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_cacheResource).call(this, result);
|
|
1096
|
+
return result;
|
|
1046
1097
|
}
|
|
1047
1098
|
/**
|
|
1048
1099
|
* Updates a FHIR resource using JSONPatch operations.
|
|
@@ -1089,6 +1140,7 @@ class MedplumClient extends EventTarget {
|
|
|
1089
1140
|
* @returns The result of the delete operation.
|
|
1090
1141
|
*/
|
|
1091
1142
|
deleteResource(resourceType, id) {
|
|
1143
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_deleteCacheEntry).call(this, this.fhirUrl(resourceType, id).toString());
|
|
1092
1144
|
this.invalidateSearches(resourceType);
|
|
1093
1145
|
return this.delete(this.fhirUrl(resourceType, id));
|
|
1094
1146
|
}
|
|
@@ -1428,6 +1480,14 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
1428
1480
|
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
1429
1481
|
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
|
|
1430
1482
|
}
|
|
1483
|
+
}, _MedplumClient_cacheResource = function _MedplumClient_cacheResource(resource) {
|
|
1484
|
+
if (resource?.id) {
|
|
1485
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, this.fhirUrl(resource.resourceType, resource.id).toString(), new ReadablePromise(Promise.resolve(resource)));
|
|
1486
|
+
}
|
|
1487
|
+
}, _MedplumClient_deleteCacheEntry = function _MedplumClient_deleteCacheEntry(key) {
|
|
1488
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
1489
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").delete(key);
|
|
1490
|
+
}
|
|
1431
1491
|
}, _MedplumClient_request =
|
|
1432
1492
|
/**
|
|
1433
1493
|
* Makes an HTTP request.
|
|
@@ -1445,7 +1505,7 @@ async function _MedplumClient_request(method, url, options = {}) {
|
|
|
1445
1505
|
}
|
|
1446
1506
|
options.method = method;
|
|
1447
1507
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1448
|
-
const response = await __classPrivateFieldGet(this,
|
|
1508
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchWithRetry).call(this, url, options);
|
|
1449
1509
|
if (response.status === 401) {
|
|
1450
1510
|
// Refresh and try again
|
|
1451
1511
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
|
|
@@ -1454,11 +1514,30 @@ async function _MedplumClient_request(method, url, options = {}) {
|
|
|
1454
1514
|
// No content or change
|
|
1455
1515
|
return undefined;
|
|
1456
1516
|
}
|
|
1457
|
-
|
|
1517
|
+
let obj = undefined;
|
|
1518
|
+
try {
|
|
1519
|
+
obj = await response.json();
|
|
1520
|
+
}
|
|
1521
|
+
catch (err) {
|
|
1522
|
+
console.error('Error parsing response', response.status, err);
|
|
1523
|
+
throw err;
|
|
1524
|
+
}
|
|
1458
1525
|
if (response.status >= 400) {
|
|
1459
1526
|
throw obj;
|
|
1460
1527
|
}
|
|
1461
1528
|
return obj;
|
|
1529
|
+
}, _MedplumClient_fetchWithRetry = async function _MedplumClient_fetchWithRetry(url, options) {
|
|
1530
|
+
const maxRetries = 3;
|
|
1531
|
+
const retryDelay = 200;
|
|
1532
|
+
let response = undefined;
|
|
1533
|
+
for (let retry = 0; retry < maxRetries; retry++) {
|
|
1534
|
+
response = (await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options));
|
|
1535
|
+
if (response.status < 500) {
|
|
1536
|
+
return response;
|
|
1537
|
+
}
|
|
1538
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
1539
|
+
}
|
|
1540
|
+
return response;
|
|
1462
1541
|
}, _MedplumClient_executeAutoBatch =
|
|
1463
1542
|
/**
|
|
1464
1543
|
* Executes a batch of requests that were automatically batched together.
|
|
@@ -1494,7 +1573,12 @@ async function _MedplumClient_executeAutoBatch() {
|
|
|
1494
1573
|
for (let i = 0; i < entries.length; i++) {
|
|
1495
1574
|
const entry = entries[i];
|
|
1496
1575
|
const responseEntry = response.entry?.[i];
|
|
1497
|
-
|
|
1576
|
+
if (responseEntry?.response?.outcome && !isOk(responseEntry.response.outcome)) {
|
|
1577
|
+
entry.reject(responseEntry.response.outcome);
|
|
1578
|
+
}
|
|
1579
|
+
else {
|
|
1580
|
+
entry.resolve(responseEntry?.resource);
|
|
1581
|
+
}
|
|
1498
1582
|
}
|
|
1499
1583
|
}, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
|
|
1500
1584
|
if (!options.headers) {
|