@medplum/core 2.0.18 → 2.0.19

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.
@@ -2,7 +2,7 @@ import { LRUCache } from './cache.mjs';
2
2
  import { getRandomString, encryptSHA256 } from './crypto.mjs';
3
3
  import { EventTarget } from './eventtarget.mjs';
4
4
  import { parseJWTPayload } from './jwt.mjs';
5
- import { OperationOutcomeError, normalizeOperationOutcome, notFound, isOk } from './outcomes.mjs';
5
+ import { OperationOutcomeError, notFound, normalizeOperationOutcome, isOk } from './outcomes.mjs';
6
6
  import { ReadablePromise } from './readablepromise.mjs';
7
7
  import { ClientStorage } from './storage.mjs';
8
8
  import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.mjs';
@@ -10,7 +10,8 @@ import { createReference, arrayBufferToBase64 } from './utils.mjs';
10
10
  import { encodeBase64 } from './base64.mjs';
11
11
 
12
12
  // PKCE auth based on:
13
- const MEDPLUM_VERSION = "2.0.18-e7b9bd9c" ;
13
+ // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
14
+ const MEDPLUM_VERSION = "2.0.19-40e6e27d" ;
14
15
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
15
16
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
16
17
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds
@@ -1512,6 +1513,26 @@ class MedplumClient extends EventTarget {
1512
1513
  const response = await this.fetch(url.toString(), options);
1513
1514
  return response.blob();
1514
1515
  }
1516
+ /**
1517
+ * Upload media to the server and create a Media instance for the uploaded content.
1518
+ * @param contents The contents of the media file, as a string, Uint8Array, File, or Blob.
1519
+ * @param contentType The media type of the content
1520
+ * @param filename The name of the file to be uploaded, or undefined if not applicable
1521
+ * @param additionalFields Additional fields for Media
1522
+ * @returns Promise that resolves to the created Media
1523
+ */
1524
+ async uploadMedia(contents, contentType, filename, additionalFields) {
1525
+ const binary = await this.createBinary(contents, filename, contentType);
1526
+ return this.createResource({
1527
+ ...additionalFields,
1528
+ resourceType: 'Media',
1529
+ content: {
1530
+ contentType: contentType,
1531
+ url: 'Binary/' + binary.id,
1532
+ title: filename,
1533
+ },
1534
+ });
1535
+ }
1515
1536
  //
1516
1537
  // Private helpers
1517
1538
  //
@@ -1587,7 +1608,10 @@ class MedplumClient extends EventTarget {
1587
1608
  return undefined;
1588
1609
  }
1589
1610
  if (response.status === 404) {
1590
- throw new OperationOutcomeError(normalizeOperationOutcome(notFound));
1611
+ const contentType = response.headers.get('content-type');
1612
+ if (!contentType?.includes('application/fhir+json')) {
1613
+ throw new OperationOutcomeError(notFound);
1614
+ }
1591
1615
  }
1592
1616
  let obj = undefined;
1593
1617
  try {