@medplum/core 0.9.28 → 0.9.31

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/cache.d.ts +34 -0
  3. package/dist/cjs/client.d.ts +1095 -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 +89 -47
  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 +245 -0
  28. package/dist/esm/client.d.ts +17 -15
  29. package/dist/esm/client.js +40 -35
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/fhirpath/utils.js +3 -3
  32. package/dist/esm/fhirpath/utils.js.map +1 -1
  33. package/dist/esm/index.js +2 -2
  34. package/dist/esm/index.min.js +1 -1
  35. package/dist/esm/index.min.js.map +1 -1
  36. package/dist/esm/outcomes.d.ts +2 -1
  37. package/dist/esm/outcomes.js +27 -10
  38. package/dist/esm/outcomes.js.map +1 -1
  39. package/dist/esm/utils.d.ts +21 -0
  40. package/dist/esm/utils.js +18 -1
  41. package/dist/esm/utils.js.map +1 -1
  42. package/package.json +3 -3
@@ -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,21 +145,22 @@ 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;
151
153
  readonly recaptchaSiteKey?: string;
152
154
  readonly remember?: boolean;
155
+ readonly projectId?: string;
153
156
  }
154
157
  export interface NewProjectRequest {
158
+ readonly login: string;
155
159
  readonly projectName: string;
156
- readonly firstName: string;
157
- readonly lastName: string;
158
160
  }
159
161
  export interface NewPatientRequest {
162
+ readonly login: string;
160
163
  readonly projectId: string;
161
- readonly firstName: string;
162
- readonly lastName: string;
163
164
  }
164
165
  export interface GoogleCredentialResponse {
165
166
  readonly clientId: string;
@@ -168,9 +169,11 @@ export interface GoogleCredentialResponse {
168
169
  export interface GoogleLoginRequest {
169
170
  readonly googleClientId: string;
170
171
  readonly googleCredential: string;
172
+ readonly projectId?: string;
171
173
  readonly clientId?: string;
172
174
  readonly scope?: string;
173
175
  readonly nonce?: string;
176
+ readonly createUser?: boolean;
174
177
  }
175
178
  export interface LoginAuthenticationResponse {
176
179
  readonly login: string;
@@ -425,20 +428,18 @@ export declare class MedplumClient extends EventTarget {
425
428
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
426
429
  *
427
430
  * @param newProjectRequest Register request including email and password.
428
- * @param login The partial login to complete. This should come from the `startNewUser` method.
429
431
  * @returns Promise to the authentication response.
430
432
  */
431
- startNewProject(newProjectRequest: NewProjectRequest, login: LoginAuthenticationResponse): Promise<LoginAuthenticationResponse>;
433
+ startNewProject(newProjectRequest: NewProjectRequest): Promise<LoginAuthenticationResponse>;
432
434
  /**
433
435
  * Initiates a new patient flow.
434
436
  *
435
437
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
436
438
  *
437
439
  * @param newPatientRequest Register request including email and password.
438
- * @param login The partial login to complete. This should come from the `startNewUser` method.
439
440
  * @returns Promise to the authentication response.
440
441
  */
441
- startNewPatient(newPatientRequest: NewPatientRequest, login: LoginAuthenticationResponse): Promise<LoginAuthenticationResponse>;
442
+ startNewPatient(newPatientRequest: NewPatientRequest): Promise<LoginAuthenticationResponse>;
442
443
  /**
443
444
  * Initiates a user login flow.
444
445
  * @category Authentication
@@ -460,14 +461,14 @@ export declare class MedplumClient extends EventTarget {
460
461
  * Does not invalidate tokens with the server.
461
462
  * @category Authentication
462
463
  */
463
- signOut(): Promise<void>;
464
+ signOut(): void;
464
465
  /**
465
466
  * Tries to sign in the user.
466
467
  * Returns true if the user is signed in.
467
468
  * This may result in navigating away to the sign in page.
468
469
  * @category Authentication
469
470
  */
470
- signInWithRedirect(): Promise<ProfileResource | void> | undefined;
471
+ signInWithRedirect(): Promise<ProfileResource | void>;
471
472
  /**
472
473
  * Tries to sign out the user.
473
474
  * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
@@ -735,7 +736,6 @@ export declare class MedplumClient extends EventTarget {
735
736
  *
736
737
  * ```typescript
737
738
  * const result = await medplum.createResourceIfNoneExist(
738
- * 'Patient?identifier=123',
739
739
  * {
740
740
  * resourceType: 'Patient',
741
741
  * identifier: [{
@@ -746,14 +746,16 @@ export declare class MedplumClient extends EventTarget {
746
746
  * family: 'Smith',
747
747
  * given: ['John']
748
748
  * }]
749
- * });
749
+ * },
750
+ * 'identifier=123'
751
+ * );
750
752
  * console.log(result.id);
751
753
  * ```
752
754
  *
753
755
  * This method is syntactic sugar for:
754
756
  *
755
757
  * ```typescript
756
- * return searchOne(query) ?? createResource(resource);
758
+ * return searchOne(resourceType, query) ?? createResource(resource);
757
759
  * ```
758
760
  *
759
761
  * The query parameter only contains the search parameters (what would be in the URL following the "?").
@@ -762,7 +764,7 @@ export declare class MedplumClient extends EventTarget {
762
764
  *
763
765
  * @category Create
764
766
  * @param resource The FHIR resource to create.
765
- * @param query The search query for an equivalent resource.
767
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
766
768
  * @returns The result of the create operation.
767
769
  */
768
770
  createResourceIfNoneExist<T extends Resource>(resource: T, query: string): Promise<T>;
@@ -8,7 +8,7 @@ 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/';
@@ -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");
@@ -292,12 +289,11 @@ class MedplumClient extends EventTarget {
292
289
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
293
290
  *
294
291
  * @param newProjectRequest Register request including email and password.
295
- * @param login The partial login to complete. This should come from the `startNewUser` method.
296
292
  * @returns Promise to the authentication response.
297
293
  */
298
- startNewProject(newProjectRequest, login) {
294
+ startNewProject(newProjectRequest) {
299
295
  return __awaiter(this, void 0, void 0, function* () {
300
- return this.post('auth/newproject', Object.assign(Object.assign({}, newProjectRequest), login));
296
+ return this.post('auth/newproject', newProjectRequest);
301
297
  });
302
298
  }
303
299
  /**
@@ -306,12 +302,11 @@ class MedplumClient extends EventTarget {
306
302
  * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
307
303
  *
308
304
  * @param newPatientRequest Register request including email and password.
309
- * @param login The partial login to complete. This should come from the `startNewUser` method.
310
305
  * @returns Promise to the authentication response.
311
306
  */
312
- startNewPatient(newPatientRequest, login) {
307
+ startNewPatient(newPatientRequest) {
313
308
  return __awaiter(this, void 0, void 0, function* () {
314
- return this.post('auth/newpatient', Object.assign(Object.assign({}, newPatientRequest), login));
309
+ return this.post('auth/newpatient', newPatientRequest);
315
310
  });
316
311
  }
317
312
  /**
@@ -349,7 +344,6 @@ class MedplumClient extends EventTarget {
349
344
  */
350
345
  signOut() {
351
346
  this.clear();
352
- return Promise.resolve();
353
347
  }
354
348
  /**
355
349
  * Tries to sign in the user.
@@ -358,15 +352,17 @@ class MedplumClient extends EventTarget {
358
352
  * @category Authentication
359
353
  */
360
354
  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
- }
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ const urlParams = new URLSearchParams(window.location.search);
357
+ const code = urlParams.get('code');
358
+ if (!code) {
359
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
360
+ return undefined;
361
+ }
362
+ else {
363
+ return this.processCode(code);
364
+ }
365
+ });
370
366
  }
371
367
  /**
372
368
  * Tries to sign out the user.
@@ -757,7 +753,6 @@ class MedplumClient extends EventTarget {
757
753
  *
758
754
  * ```typescript
759
755
  * const result = await medplum.createResourceIfNoneExist(
760
- * 'Patient?identifier=123',
761
756
  * {
762
757
  * resourceType: 'Patient',
763
758
  * identifier: [{
@@ -768,14 +763,16 @@ class MedplumClient extends EventTarget {
768
763
  * family: 'Smith',
769
764
  * given: ['John']
770
765
  * }]
771
- * });
766
+ * },
767
+ * 'identifier=123'
768
+ * );
772
769
  * console.log(result.id);
773
770
  * ```
774
771
  *
775
772
  * This method is syntactic sugar for:
776
773
  *
777
774
  * ```typescript
778
- * return searchOne(query) ?? createResource(resource);
775
+ * return searchOne(resourceType, query) ?? createResource(resource);
779
776
  * ```
780
777
  *
781
778
  * The query parameter only contains the search parameters (what would be in the URL following the "?").
@@ -784,7 +781,7 @@ class MedplumClient extends EventTarget {
784
781
  *
785
782
  * @category Create
786
783
  * @param resource The FHIR resource to create.
787
- * @param query The search query for an equivalent resource.
784
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
788
785
  * @returns The result of the create operation.
789
786
  */
790
787
  createResourceIfNoneExist(resource, query) {
@@ -1365,16 +1362,18 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
1365
1362
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
1366
1363
  });
1367
1364
  }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
1368
- __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());
1365
+ return __awaiter(this, void 0, void 0, function* () {
1366
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1367
+ const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
1368
+ url.searchParams.set('response_type', 'code');
1369
+ url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
1370
+ url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
1371
+ url.searchParams.set('redirect_uri', getBaseUrl());
1372
+ url.searchParams.set('scope', DEFAULT_SCOPE);
1373
+ url.searchParams.set('code_challenge_method', 'S256');
1374
+ url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
1375
+ window.location.assign(url.toString());
1376
+ });
1378
1377
  }, _MedplumClient_refresh = function _MedplumClient_refresh() {
1379
1378
  return __awaiter(this, void 0, void 0, function* () {
1380
1379
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
@@ -1450,6 +1449,12 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
1450
1449
  function getBaseUrl() {
1451
1450
  return window.location.protocol + '//' + window.location.host + '/';
1452
1451
  }
1452
+ function ensureTrailingSlash(url) {
1453
+ if (!url) {
1454
+ return url;
1455
+ }
1456
+ return url.endsWith('/') ? url : url + '/';
1457
+ }
1453
1458
 
1454
1459
  export { MedplumClient };
1455
1460
  //# sourceMappingURL=client.js.map