@medplum/core 0.9.27 → 0.9.30

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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/cache.d.ts +34 -0
  3. package/dist/cjs/client.d.ts +1093 -0
  4. package/dist/cjs/crypto.d.ts +9 -0
  5. package/dist/cjs/eventtarget.d.ts +13 -0
  6. package/dist/cjs/fhirpath/atoms.d.ts +150 -0
  7. package/dist/cjs/fhirpath/date.d.ts +1 -0
  8. package/dist/cjs/fhirpath/functions.d.ts +5 -0
  9. package/dist/cjs/fhirpath/index.d.ts +4 -0
  10. package/dist/cjs/fhirpath/parse.d.ts +24 -0
  11. package/dist/cjs/fhirpath/tokenize.d.ts +5 -0
  12. package/dist/cjs/fhirpath/utils.d.ts +95 -0
  13. package/dist/cjs/format.d.ts +21 -0
  14. package/dist/cjs/hl7.d.ts +43 -0
  15. package/dist/cjs/index.d.ts +12 -0
  16. package/dist/cjs/index.js +257 -48
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/index.min.js +1 -1
  19. package/dist/cjs/index.min.js.map +1 -1
  20. package/dist/cjs/jwt.d.ts +5 -0
  21. package/dist/cjs/outcomes.d.ts +30 -0
  22. package/dist/cjs/readablepromise.d.ts +48 -0
  23. package/dist/cjs/search.d.ts +64 -0
  24. package/dist/cjs/searchparams.d.ts +35 -0
  25. package/dist/cjs/storage.d.ts +47 -0
  26. package/dist/cjs/types.d.ts +148 -0
  27. package/dist/cjs/utils.d.ts +239 -0
  28. package/dist/esm/client.d.ts +11 -11
  29. package/dist/esm/client.js +50 -38
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/fhirpath/utils.js +12 -3
  32. package/dist/esm/fhirpath/utils.js.map +1 -1
  33. package/dist/esm/format.d.ts +7 -1
  34. package/dist/esm/format.js +108 -1
  35. package/dist/esm/format.js.map +1 -1
  36. package/dist/esm/index.js +3 -3
  37. package/dist/esm/index.min.js +1 -1
  38. package/dist/esm/index.min.js.map +1 -1
  39. package/dist/esm/outcomes.d.ts +9 -1
  40. package/dist/esm/outcomes.js +63 -7
  41. package/dist/esm/outcomes.js.map +1 -1
  42. package/dist/esm/utils.d.ts +15 -0
  43. package/dist/esm/utils.js +18 -1
  44. package/dist/esm/utils.js.map +1 -1
  45. package/package.json +3 -3
  46. package/stats.html +4034 -0
@@ -15,7 +15,7 @@ export interface MedplumClientOptions {
15
15
  /**
16
16
  * Base server URL.
17
17
  *
18
- * Default value is "https://api.medplum.com/".
18
+ * Default value is https://api.medplum.com/
19
19
  *
20
20
  * Use this to point to a custom Medplum deployment.
21
21
  */
@@ -145,6 +145,8 @@ export interface LoginRequest {
145
145
  readonly nonce?: string;
146
146
  }
147
147
  export interface NewUserRequest {
148
+ readonly firstName: string;
149
+ readonly lastName: string;
148
150
  readonly email: string;
149
151
  readonly password: string;
150
152
  readonly recaptchaToken: string;
@@ -153,13 +155,9 @@ export interface NewUserRequest {
153
155
  }
154
156
  export interface NewProjectRequest {
155
157
  readonly projectName: string;
156
- readonly firstName: string;
157
- readonly lastName: string;
158
158
  }
159
159
  export interface NewPatientRequest {
160
160
  readonly projectId: string;
161
- readonly firstName: string;
162
- readonly lastName: string;
163
161
  }
164
162
  export interface GoogleCredentialResponse {
165
163
  readonly clientId: string;
@@ -168,6 +166,7 @@ export interface GoogleCredentialResponse {
168
166
  export interface GoogleLoginRequest {
169
167
  readonly googleClientId: string;
170
168
  readonly googleCredential: string;
169
+ readonly projectId?: string;
171
170
  readonly clientId?: string;
172
171
  readonly scope?: string;
173
172
  readonly nonce?: string;
@@ -460,14 +459,14 @@ export declare class MedplumClient extends EventTarget {
460
459
  * Does not invalidate tokens with the server.
461
460
  * @category Authentication
462
461
  */
463
- signOut(): Promise<void>;
462
+ signOut(): void;
464
463
  /**
465
464
  * Tries to sign in the user.
466
465
  * Returns true if the user is signed in.
467
466
  * This may result in navigating away to the sign in page.
468
467
  * @category Authentication
469
468
  */
470
- signInWithRedirect(): Promise<ProfileResource | void> | undefined;
469
+ signInWithRedirect(): Promise<ProfileResource | void>;
471
470
  /**
472
471
  * Tries to sign out the user.
473
472
  * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
@@ -735,7 +734,6 @@ export declare class MedplumClient extends EventTarget {
735
734
  *
736
735
  * ```typescript
737
736
  * const result = await medplum.createResourceIfNoneExist(
738
- * 'Patient?identifier=123',
739
737
  * {
740
738
  * resourceType: 'Patient',
741
739
  * identifier: [{
@@ -746,14 +744,16 @@ export declare class MedplumClient extends EventTarget {
746
744
  * family: 'Smith',
747
745
  * given: ['John']
748
746
  * }]
749
- * });
747
+ * },
748
+ * 'identifier=123'
749
+ * );
750
750
  * console.log(result.id);
751
751
  * ```
752
752
  *
753
753
  * This method is syntactic sugar for:
754
754
  *
755
755
  * ```typescript
756
- * return searchOne(query) ?? createResource(resource);
756
+ * return searchOne(resourceType, query) ?? createResource(resource);
757
757
  * ```
758
758
  *
759
759
  * The query parameter only contains the search parameters (what would be in the URL following the "?").
@@ -762,7 +762,7 @@ export declare class MedplumClient extends EventTarget {
762
762
  *
763
763
  * @category Create
764
764
  * @param resource The FHIR resource to create.
765
- * @param query The search query for an equivalent resource.
765
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
766
766
  * @returns The result of the create operation.
767
767
  */
768
768
  createResourceIfNoneExist<T extends Resource>(resource: T, query: string): Promise<T>;
@@ -8,13 +8,13 @@ import { ClientStorage } from './storage.js';
8
8
  import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.js';
9
9
  import { createReference, arrayBufferToBase64 } from './utils.js';
10
10
 
11
- // PKCE auth ased on:
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_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
14
14
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
15
15
  const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
16
16
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
17
- const DEFAULT_CACHE_TIME = 10000; // 10 seconds
17
+ const DEFAULT_CACHE_TIME = 60000; // 60 seconds
18
18
  const JSON_CONTENT_TYPE = 'application/json';
19
19
  const FHIR_CONTENT_TYPE = 'application/fhir+json';
20
20
  const PATCH_CONTENT_TYPE = 'application/json-patch+json';
@@ -91,16 +91,13 @@ class MedplumClient extends EventTarget {
91
91
  if (!options.baseUrl.startsWith('http')) {
92
92
  throw new Error('Base URL must start with http or https');
93
93
  }
94
- if (!options.baseUrl.endsWith('/')) {
95
- throw new Error('Base URL must end with a trailing slash');
96
- }
97
94
  }
98
95
  __classPrivateFieldSet(this, _MedplumClient_fetch, (options === null || options === void 0 ? void 0 : options.fetch) || window.fetch.bind(window), "f");
99
96
  __classPrivateFieldSet(this, _MedplumClient_createPdf, options === null || options === void 0 ? void 0 : options.createPdf, "f");
100
97
  __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
101
98
  __classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache((_a = options === null || options === void 0 ? void 0 : options.resourceCacheSize) !== null && _a !== void 0 ? _a : DEFAULT_RESOURCE_CACHE_SIZE), "f");
102
99
  __classPrivateFieldSet(this, _MedplumClient_cacheTime, (_b = options === null || options === void 0 ? void 0 : options.cacheTime) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME, "f");
103
- __classPrivateFieldSet(this, _MedplumClient_baseUrl, (options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
100
+ __classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
104
101
  __classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
105
102
  __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
106
103
  __classPrivateFieldSet(this, _MedplumClient_tokenUrl, (options === null || options === void 0 ? void 0 : options.tokenUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
@@ -349,7 +346,6 @@ class MedplumClient extends EventTarget {
349
346
  */
350
347
  signOut() {
351
348
  this.clear();
352
- return Promise.resolve();
353
349
  }
354
350
  /**
355
351
  * Tries to sign in the user.
@@ -358,15 +354,17 @@ class MedplumClient extends EventTarget {
358
354
  * @category Authentication
359
355
  */
360
356
  signInWithRedirect() {
361
- const urlParams = new URLSearchParams(window.location.search);
362
- const code = urlParams.get('code');
363
- if (!code) {
364
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
365
- return undefined;
366
- }
367
- else {
368
- return this.processCode(code);
369
- }
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ const urlParams = new URLSearchParams(window.location.search);
359
+ const code = urlParams.get('code');
360
+ if (!code) {
361
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
362
+ return undefined;
363
+ }
364
+ else {
365
+ return this.processCode(code);
366
+ }
367
+ });
370
368
  }
371
369
  /**
372
370
  * Tries to sign out the user.
@@ -757,7 +755,6 @@ class MedplumClient extends EventTarget {
757
755
  *
758
756
  * ```typescript
759
757
  * const result = await medplum.createResourceIfNoneExist(
760
- * 'Patient?identifier=123',
761
758
  * {
762
759
  * resourceType: 'Patient',
763
760
  * identifier: [{
@@ -768,14 +765,16 @@ class MedplumClient extends EventTarget {
768
765
  * family: 'Smith',
769
766
  * given: ['John']
770
767
  * }]
771
- * });
768
+ * },
769
+ * 'identifier=123'
770
+ * );
772
771
  * console.log(result.id);
773
772
  * ```
774
773
  *
775
774
  * This method is syntactic sugar for:
776
775
  *
777
776
  * ```typescript
778
- * return searchOne(query) ?? createResource(resource);
777
+ * return searchOne(resourceType, query) ?? createResource(resource);
779
778
  * ```
780
779
  *
781
780
  * The query parameter only contains the search parameters (what would be in the URL following the "?").
@@ -784,7 +783,7 @@ class MedplumClient extends EventTarget {
784
783
  *
785
784
  * @category Create
786
785
  * @param resource The FHIR resource to create.
787
- * @param query The search query for an equivalent resource.
786
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
788
787
  * @returns The result of the create operation.
789
788
  */
790
789
  createResourceIfNoneExist(resource, query) {
@@ -916,14 +915,19 @@ class MedplumClient extends EventTarget {
916
915
  * @returns The result of the update operation.
917
916
  */
918
917
  updateResource(resource) {
919
- if (!resource.resourceType) {
920
- throw new Error('Missing resourceType');
921
- }
922
- if (!resource.id) {
923
- throw new Error('Missing id');
924
- }
925
- this.invalidateSearches(resource.resourceType);
926
- return this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
918
+ return __awaiter(this, void 0, void 0, function* () {
919
+ if (!resource.resourceType) {
920
+ throw new Error('Missing resourceType');
921
+ }
922
+ if (!resource.id) {
923
+ throw new Error('Missing id');
924
+ }
925
+ this.invalidateSearches(resource.resourceType);
926
+ const result = yield this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
927
+ // On 304 not modified, result will be undefined
928
+ // Return the user input instead
929
+ return result !== null && result !== void 0 ? result : resource;
930
+ });
927
931
  }
928
932
  /**
929
933
  * Updates a FHIR resource using JSONPatch operations.
@@ -1360,16 +1364,18 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
1360
1364
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
1361
1365
  });
1362
1366
  }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
1363
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1364
- const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
1365
- url.searchParams.set('response_type', 'code');
1366
- url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
1367
- url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
1368
- url.searchParams.set('redirect_uri', getBaseUrl());
1369
- url.searchParams.set('scope', DEFAULT_SCOPE);
1370
- url.searchParams.set('code_challenge_method', 'S256');
1371
- url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
1372
- window.location.assign(url.toString());
1367
+ return __awaiter(this, void 0, void 0, function* () {
1368
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1369
+ const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
1370
+ url.searchParams.set('response_type', 'code');
1371
+ url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
1372
+ url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
1373
+ url.searchParams.set('redirect_uri', getBaseUrl());
1374
+ url.searchParams.set('scope', DEFAULT_SCOPE);
1375
+ url.searchParams.set('code_challenge_method', 'S256');
1376
+ url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
1377
+ window.location.assign(url.toString());
1378
+ });
1373
1379
  }, _MedplumClient_refresh = function _MedplumClient_refresh() {
1374
1380
  return __awaiter(this, void 0, void 0, function* () {
1375
1381
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
@@ -1445,6 +1451,12 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
1445
1451
  function getBaseUrl() {
1446
1452
  return window.location.protocol + '//' + window.location.host + '/';
1447
1453
  }
1454
+ function ensureTrailingSlash(url) {
1455
+ if (!url) {
1456
+ return url;
1457
+ }
1458
+ return url.endsWith('/') ? url : url + '/';
1459
+ }
1448
1460
 
1449
1461
  export { MedplumClient };
1450
1462
  //# sourceMappingURL=client.js.map