@medplum/core 1.0.4 → 1.0.6
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 +9 -7
- package/dist/cjs/client.d.ts +1 -0
- package/dist/cjs/fhirlexer/parse.d.ts +18 -2
- package/dist/cjs/fhirmapper/parse.d.ts +2 -2
- package/dist/cjs/fhirpath/atoms.d.ts +28 -53
- package/dist/cjs/fhirpath/parse.d.ts +37 -0
- package/dist/cjs/format.d.ts +2 -1
- package/dist/cjs/{index.js → index.cjs} +999 -996
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.min.cjs +1 -0
- package/dist/cjs/search.d.ts +2 -1
- package/dist/esm/{base-schema.json.js → base-schema.json.mjs} +1 -1
- package/dist/esm/{base-schema.json.js.map → base-schema.json.mjs.map} +1 -1
- package/dist/esm/{cache.js → cache.mjs} +2 -2
- package/dist/esm/cache.mjs.map +1 -0
- package/dist/esm/client.d.ts +1 -0
- package/dist/esm/{client.js → client.mjs} +264 -268
- package/dist/esm/client.mjs.map +1 -0
- package/dist/esm/{crypto.js → crypto.mjs} +4 -7
- package/dist/esm/crypto.mjs.map +1 -0
- package/dist/esm/{eventtarget.js → eventtarget.mjs} +2 -2
- package/dist/esm/eventtarget.mjs.map +1 -0
- package/dist/esm/fhirlexer/parse.d.ts +18 -2
- package/dist/esm/fhirlexer/{parse.js → parse.mjs} +35 -10
- package/dist/esm/fhirlexer/parse.mjs.map +1 -0
- package/dist/esm/fhirlexer/{tokenize.js → tokenize.mjs} +12 -12
- package/dist/esm/fhirlexer/tokenize.mjs.map +1 -0
- package/dist/esm/fhirmapper/parse.d.ts +2 -2
- package/dist/esm/fhirpath/atoms.d.ts +28 -53
- package/dist/esm/fhirpath/{atoms.js → atoms.mjs} +79 -62
- package/dist/esm/fhirpath/atoms.mjs.map +1 -0
- package/dist/esm/fhirpath/{date.js → date.mjs} +1 -1
- package/dist/esm/fhirpath/date.mjs.map +1 -0
- package/dist/esm/fhirpath/{functions.js → functions.mjs} +16 -22
- package/dist/esm/fhirpath/functions.mjs.map +1 -0
- package/dist/esm/fhirpath/parse.d.ts +37 -0
- package/dist/esm/fhirpath/{parse.js → parse.mjs} +38 -42
- package/dist/esm/fhirpath/parse.mjs.map +1 -0
- package/dist/esm/fhirpath/{tokenize.js → tokenize.mjs} +4 -4
- package/dist/esm/fhirpath/tokenize.mjs.map +1 -0
- package/dist/esm/fhirpath/{utils.js → utils.mjs} +6 -7
- package/dist/esm/fhirpath/utils.mjs.map +1 -0
- package/dist/esm/format.d.ts +2 -1
- package/dist/esm/{format.js → format.mjs} +29 -21
- package/dist/esm/format.mjs.map +1 -0
- package/dist/esm/{hl7.js → hl7.mjs} +8 -9
- package/dist/esm/hl7.mjs.map +1 -0
- package/dist/esm/index.min.mjs +1 -0
- package/dist/esm/{index.js → index.mjs} +17 -17
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/{jwt.js → jwt.mjs} +1 -1
- package/dist/esm/jwt.mjs.map +1 -0
- package/dist/esm/{match.js → match.mjs} +12 -13
- package/dist/esm/match.mjs.map +1 -0
- package/dist/esm/node_modules/tslib/{tslib.es6.js → tslib.es6.mjs} +2 -12
- package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -0
- package/dist/esm/{outcomes.js → outcomes.mjs} +3 -5
- package/dist/esm/outcomes.mjs.map +1 -0
- package/dist/esm/{readablepromise.js → readablepromise.mjs} +2 -2
- package/dist/esm/readablepromise.mjs.map +1 -0
- package/dist/esm/search.d.ts +2 -1
- package/dist/esm/{search.js → search.mjs} +1 -1
- package/dist/esm/search.mjs.map +1 -0
- package/dist/esm/{searchparams.js → searchparams.mjs} +8 -9
- package/dist/esm/searchparams.mjs.map +1 -0
- package/dist/esm/{storage.js → storage.mjs} +4 -5
- package/dist/esm/storage.mjs.map +1 -0
- package/dist/esm/{types.js → types.mjs} +6 -9
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/{utils.js → utils.mjs} +15 -26
- package/dist/esm/utils.mjs.map +1 -0
- package/package.json +5 -5
- package/rollup.config.mjs +6 -7
- package/dist/cjs/fhirmapper/atoms.d.ts +0 -67
- package/dist/cjs/fhirmapper/testall.d.ts +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/index.min.js +0 -2
- package/dist/cjs/index.min.js.map +0 -1
- package/dist/esm/cache.js.map +0 -1
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/crypto.js.map +0 -1
- package/dist/esm/eventtarget.js.map +0 -1
- package/dist/esm/fhirlexer/parse.js.map +0 -1
- package/dist/esm/fhirlexer/tokenize.js.map +0 -1
- package/dist/esm/fhirmapper/atoms.d.ts +0 -67
- package/dist/esm/fhirmapper/testall.d.ts +0 -1
- package/dist/esm/fhirpath/atoms.js.map +0 -1
- package/dist/esm/fhirpath/date.js.map +0 -1
- package/dist/esm/fhirpath/functions.js.map +0 -1
- package/dist/esm/fhirpath/parse.js.map +0 -1
- package/dist/esm/fhirpath/tokenize.js.map +0 -1
- package/dist/esm/fhirpath/utils.js.map +0 -1
- package/dist/esm/format.js.map +0 -1
- package/dist/esm/hl7.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.min.js +0 -2
- package/dist/esm/index.min.js.map +0 -1
- package/dist/esm/jwt.js.map +0 -1
- package/dist/esm/match.js.map +0 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +0 -1
- package/dist/esm/outcomes.js.map +0 -1
- package/dist/esm/readablepromise.js.map +0 -1
- package/dist/esm/search.js.map +0 -1
- package/dist/esm/searchparams.js.map +0 -1
- package/dist/esm/storage.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { __classPrivateFieldSet, __classPrivateFieldGet
|
|
2
|
-
import { LRUCache } from './cache.
|
|
3
|
-
import { getRandomString, encryptSHA256 } from './crypto.
|
|
4
|
-
import { EventTarget } from './eventtarget.
|
|
5
|
-
import { parseJWTPayload } from './jwt.
|
|
6
|
-
import { ReadablePromise } from './readablepromise.
|
|
7
|
-
import { ClientStorage } from './storage.
|
|
8
|
-
import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.
|
|
9
|
-
import { createReference, arrayBufferToBase64 } from './utils.
|
|
1
|
+
import { __classPrivateFieldSet, __classPrivateFieldGet } from './node_modules/tslib/tslib.es6.mjs';
|
|
2
|
+
import { LRUCache } from './cache.mjs';
|
|
3
|
+
import { getRandomString, encryptSHA256 } from './crypto.mjs';
|
|
4
|
+
import { EventTarget } from './eventtarget.mjs';
|
|
5
|
+
import { parseJWTPayload } from './jwt.mjs';
|
|
6
|
+
import { ReadablePromise } from './readablepromise.mjs';
|
|
7
|
+
import { ClientStorage } from './storage.mjs';
|
|
8
|
+
import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.mjs';
|
|
9
|
+
import { createReference, arrayBufferToBase64 } from './utils.mjs';
|
|
10
10
|
|
|
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
|
-
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl,
|
|
14
|
-
const MEDPLUM_VERSION = "1.0.
|
|
13
|
+
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_clientId, _MedplumClient_clientSecret, _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_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
|
|
14
|
+
const MEDPLUM_VERSION = "1.0.6-5860113c";
|
|
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
|
|
@@ -72,7 +72,6 @@ const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
|
72
72
|
*/
|
|
73
73
|
class MedplumClient extends EventTarget {
|
|
74
74
|
constructor(options) {
|
|
75
|
-
var _a, _b;
|
|
76
75
|
super();
|
|
77
76
|
_MedplumClient_instances.add(this);
|
|
78
77
|
_MedplumClient_fetch.set(this, void 0);
|
|
@@ -81,33 +80,34 @@ class MedplumClient extends EventTarget {
|
|
|
81
80
|
_MedplumClient_requestCache.set(this, void 0);
|
|
82
81
|
_MedplumClient_cacheTime.set(this, void 0);
|
|
83
82
|
_MedplumClient_baseUrl.set(this, void 0);
|
|
84
|
-
_MedplumClient_clientId.set(this, void 0);
|
|
85
83
|
_MedplumClient_authorizeUrl.set(this, void 0);
|
|
86
84
|
_MedplumClient_tokenUrl.set(this, void 0);
|
|
87
85
|
_MedplumClient_logoutUrl.set(this, void 0);
|
|
88
86
|
_MedplumClient_onUnauthenticated.set(this, void 0);
|
|
87
|
+
_MedplumClient_clientId.set(this, void 0);
|
|
88
|
+
_MedplumClient_clientSecret.set(this, void 0);
|
|
89
89
|
_MedplumClient_accessToken.set(this, void 0);
|
|
90
90
|
_MedplumClient_refreshToken.set(this, void 0);
|
|
91
91
|
_MedplumClient_refreshPromise.set(this, void 0);
|
|
92
92
|
_MedplumClient_profilePromise.set(this, void 0);
|
|
93
93
|
_MedplumClient_profile.set(this, void 0);
|
|
94
94
|
_MedplumClient_config.set(this, void 0);
|
|
95
|
-
if (options
|
|
95
|
+
if (options?.baseUrl) {
|
|
96
96
|
if (!options.baseUrl.startsWith('http')) {
|
|
97
97
|
throw new Error('Base URL must start with http or https');
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
__classPrivateFieldSet(this, _MedplumClient_fetch,
|
|
101
|
-
__classPrivateFieldSet(this, _MedplumClient_createPdf, options
|
|
100
|
+
__classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || window.fetch.bind(window), "f");
|
|
101
|
+
__classPrivateFieldSet(this, _MedplumClient_createPdf, options?.createPdf, "f");
|
|
102
102
|
__classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
|
|
103
|
-
__classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(
|
|
104
|
-
__classPrivateFieldSet(this, _MedplumClient_cacheTime,
|
|
105
|
-
__classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options
|
|
106
|
-
__classPrivateFieldSet(this, _MedplumClient_clientId,
|
|
107
|
-
__classPrivateFieldSet(this, _MedplumClient_authorizeUrl,
|
|
108
|
-
__classPrivateFieldSet(this, _MedplumClient_tokenUrl,
|
|
109
|
-
__classPrivateFieldSet(this, _MedplumClient_logoutUrl,
|
|
110
|
-
__classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options
|
|
103
|
+
__classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(options?.resourceCacheSize ?? DEFAULT_RESOURCE_CACHE_SIZE), "f");
|
|
104
|
+
__classPrivateFieldSet(this, _MedplumClient_cacheTime, options?.cacheTime ?? DEFAULT_CACHE_TIME, "f");
|
|
105
|
+
__classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options?.baseUrl) || DEFAULT_BASE_URL, "f");
|
|
106
|
+
__classPrivateFieldSet(this, _MedplumClient_clientId, options?.clientId || '', "f");
|
|
107
|
+
__classPrivateFieldSet(this, _MedplumClient_authorizeUrl, options?.authorizeUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
|
|
108
|
+
__classPrivateFieldSet(this, _MedplumClient_tokenUrl, options?.tokenUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
|
|
109
|
+
__classPrivateFieldSet(this, _MedplumClient_logoutUrl, options?.logoutUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
|
|
110
|
+
__classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options?.onUnauthenticated, "f");
|
|
111
111
|
const activeLogin = this.getActiveLogin();
|
|
112
112
|
if (activeLogin) {
|
|
113
113
|
__classPrivateFieldSet(this, _MedplumClient_accessToken, activeLogin.accessToken, "f");
|
|
@@ -282,10 +282,12 @@ class MedplumClient extends EventTarget {
|
|
|
282
282
|
* @param newUserRequest Register request including email and password.
|
|
283
283
|
* @returns Promise to the authentication response.
|
|
284
284
|
*/
|
|
285
|
-
startNewUser(newUserRequest) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
285
|
+
async startNewUser(newUserRequest) {
|
|
286
|
+
await this.startPkce();
|
|
287
|
+
return this.post('auth/newuser', {
|
|
288
|
+
...newUserRequest,
|
|
289
|
+
codeChallengeMethod: 'S256',
|
|
290
|
+
codeChallenge: sessionStorage.getItem('codeChallenge'),
|
|
289
291
|
});
|
|
290
292
|
}
|
|
291
293
|
/**
|
|
@@ -296,10 +298,8 @@ class MedplumClient extends EventTarget {
|
|
|
296
298
|
* @param newProjectRequest Register request including email and password.
|
|
297
299
|
* @returns Promise to the authentication response.
|
|
298
300
|
*/
|
|
299
|
-
startNewProject(newProjectRequest) {
|
|
300
|
-
return
|
|
301
|
-
return this.post('auth/newproject', newProjectRequest);
|
|
302
|
-
});
|
|
301
|
+
async startNewProject(newProjectRequest) {
|
|
302
|
+
return this.post('auth/newproject', newProjectRequest);
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
305
|
* Initiates a new patient flow.
|
|
@@ -309,10 +309,8 @@ class MedplumClient extends EventTarget {
|
|
|
309
309
|
* @param newPatientRequest Register request including email and password.
|
|
310
310
|
* @returns Promise to the authentication response.
|
|
311
311
|
*/
|
|
312
|
-
startNewPatient(newPatientRequest) {
|
|
313
|
-
return
|
|
314
|
-
return this.post('auth/newpatient', newPatientRequest);
|
|
315
|
-
});
|
|
312
|
+
async startNewPatient(newPatientRequest) {
|
|
313
|
+
return this.post('auth/newpatient', newPatientRequest);
|
|
316
314
|
}
|
|
317
315
|
/**
|
|
318
316
|
* Initiates a user login flow.
|
|
@@ -320,12 +318,14 @@ class MedplumClient extends EventTarget {
|
|
|
320
318
|
* @param loginRequest Login request including email and password.
|
|
321
319
|
* @returns Promise to the authentication response.
|
|
322
320
|
*/
|
|
323
|
-
startLogin(loginRequest) {
|
|
324
|
-
|
|
325
|
-
return
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
321
|
+
async startLogin(loginRequest) {
|
|
322
|
+
const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
|
|
323
|
+
return this.post('auth/login', {
|
|
324
|
+
...loginRequest,
|
|
325
|
+
clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
|
|
326
|
+
scope: loginRequest.scope,
|
|
327
|
+
codeChallengeMethod,
|
|
328
|
+
codeChallenge,
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
331
|
/**
|
|
@@ -336,12 +336,14 @@ class MedplumClient extends EventTarget {
|
|
|
336
336
|
* @param loginRequest Login request including Google credential response.
|
|
337
337
|
* @returns Promise to the authentication response.
|
|
338
338
|
*/
|
|
339
|
-
startGoogleLogin(loginRequest) {
|
|
340
|
-
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
339
|
+
async startGoogleLogin(loginRequest) {
|
|
340
|
+
const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
|
|
341
|
+
return this.post('auth/google', {
|
|
342
|
+
...loginRequest,
|
|
343
|
+
clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
|
|
344
|
+
scope: loginRequest.scope,
|
|
345
|
+
codeChallengeMethod,
|
|
346
|
+
codeChallenge,
|
|
345
347
|
});
|
|
346
348
|
}
|
|
347
349
|
getCodeChallenge(loginRequest) {
|
|
@@ -374,18 +376,16 @@ class MedplumClient extends EventTarget {
|
|
|
374
376
|
* This may result in navigating away to the sign in page.
|
|
375
377
|
* @category Authentication
|
|
376
378
|
*/
|
|
377
|
-
signInWithRedirect() {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
});
|
|
379
|
+
async signInWithRedirect() {
|
|
380
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
381
|
+
const code = urlParams.get('code');
|
|
382
|
+
if (!code) {
|
|
383
|
+
await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
return this.processCode(code);
|
|
388
|
+
}
|
|
389
389
|
}
|
|
390
390
|
/**
|
|
391
391
|
* Tries to sign out the user.
|
|
@@ -501,7 +501,7 @@ class MedplumClient extends EventTarget {
|
|
|
501
501
|
if (cached) {
|
|
502
502
|
return cached.value;
|
|
503
503
|
}
|
|
504
|
-
const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) =>
|
|
504
|
+
const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) => b.entry?.[0]?.resource));
|
|
505
505
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
506
506
|
return promise;
|
|
507
507
|
}
|
|
@@ -534,7 +534,7 @@ class MedplumClient extends EventTarget {
|
|
|
534
534
|
if (cached) {
|
|
535
535
|
return cached.value;
|
|
536
536
|
}
|
|
537
|
-
const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) =>
|
|
537
|
+
const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) => b.entry?.map((e) => e.resource) ?? []));
|
|
538
538
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
539
539
|
return promise;
|
|
540
540
|
}
|
|
@@ -562,8 +562,7 @@ class MedplumClient extends EventTarget {
|
|
|
562
562
|
* @returns The resource if it is available in the cache; undefined otherwise.
|
|
563
563
|
*/
|
|
564
564
|
getCached(resourceType, id) {
|
|
565
|
-
|
|
566
|
-
const cached = (_a = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())) === null || _a === void 0 ? void 0 : _a.value;
|
|
565
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())?.value;
|
|
567
566
|
return cached && cached.isOk() ? cached.read() : undefined;
|
|
568
567
|
}
|
|
569
568
|
/**
|
|
@@ -626,7 +625,7 @@ class MedplumClient extends EventTarget {
|
|
|
626
625
|
* @returns The resource if available; undefined otherwise.
|
|
627
626
|
*/
|
|
628
627
|
readReference(reference, options = {}) {
|
|
629
|
-
const refString = reference
|
|
628
|
+
const refString = reference?.reference;
|
|
630
629
|
if (!refString) {
|
|
631
630
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
632
631
|
}
|
|
@@ -654,12 +653,11 @@ class MedplumClient extends EventTarget {
|
|
|
654
653
|
* @param resourceType The FHIR resource type.
|
|
655
654
|
* @returns Promise to a schema with the requested resource type.
|
|
656
655
|
*/
|
|
657
|
-
requestSchema(resourceType) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
const query = `{
|
|
656
|
+
async requestSchema(resourceType) {
|
|
657
|
+
if (resourceType in globalSchema.types) {
|
|
658
|
+
return globalSchema;
|
|
659
|
+
}
|
|
660
|
+
const query = `{
|
|
663
661
|
StructureDefinitionList(name: "${resourceType}") {
|
|
664
662
|
name,
|
|
665
663
|
description,
|
|
@@ -688,15 +686,14 @@ class MedplumClient extends EventTarget {
|
|
|
688
686
|
target
|
|
689
687
|
}
|
|
690
688
|
}`.replace(/\s+/g, ' ');
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
});
|
|
689
|
+
const response = (await this.graphql(query));
|
|
690
|
+
for (const structureDefinition of response.data.StructureDefinitionList) {
|
|
691
|
+
indexStructureDefinition(structureDefinition);
|
|
692
|
+
}
|
|
693
|
+
for (const searchParameter of response.data.SearchParameterList) {
|
|
694
|
+
indexSearchParameter(searchParameter);
|
|
695
|
+
}
|
|
696
|
+
return globalSchema;
|
|
700
697
|
}
|
|
701
698
|
/**
|
|
702
699
|
* Reads resource history by resource type and ID.
|
|
@@ -834,11 +831,8 @@ class MedplumClient extends EventTarget {
|
|
|
834
831
|
* @param query The search query for an equivalent resource (should not include resource type or "?").
|
|
835
832
|
* @returns The result of the create operation.
|
|
836
833
|
*/
|
|
837
|
-
createResourceIfNoneExist(resource, query) {
|
|
838
|
-
|
|
839
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
840
|
-
return ((_a = (yield this.searchOne(resource.resourceType, query))) !== null && _a !== void 0 ? _a : this.createResource(resource));
|
|
841
|
-
});
|
|
834
|
+
async createResourceIfNoneExist(resource, query) {
|
|
835
|
+
return ((await this.searchOne(resource.resourceType, query)) ?? this.createResource(resource));
|
|
842
836
|
}
|
|
843
837
|
/**
|
|
844
838
|
* Creates a FHIR `Binary` resource with the provided data content.
|
|
@@ -925,14 +919,12 @@ class MedplumClient extends EventTarget {
|
|
|
925
919
|
* @param docDefinition The PDF document definition.
|
|
926
920
|
* @returns The result of the create operation.
|
|
927
921
|
*/
|
|
928
|
-
createPdf(docDefinition, filename, tableLayouts, fonts) {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return this.createBinary(blob, filename, 'application/pdf');
|
|
935
|
-
});
|
|
922
|
+
async createPdf(docDefinition, filename, tableLayouts, fonts) {
|
|
923
|
+
if (!__classPrivateFieldGet(this, _MedplumClient_createPdf, "f")) {
|
|
924
|
+
throw new Error('PDF creation not enabled');
|
|
925
|
+
}
|
|
926
|
+
const blob = await __classPrivateFieldGet(this, _MedplumClient_createPdf, "f").call(this, docDefinition, tableLayouts, fonts);
|
|
927
|
+
return this.createBinary(blob, filename, 'application/pdf');
|
|
936
928
|
}
|
|
937
929
|
/**
|
|
938
930
|
* Creates a FHIR `Communication` resource with the provided data content.
|
|
@@ -994,20 +986,18 @@ class MedplumClient extends EventTarget {
|
|
|
994
986
|
* @param resource The FHIR resource to update.
|
|
995
987
|
* @returns The result of the update operation.
|
|
996
988
|
*/
|
|
997
|
-
updateResource(resource) {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
return result !== null && result !== void 0 ? result : resource;
|
|
1010
|
-
});
|
|
989
|
+
async updateResource(resource) {
|
|
990
|
+
if (!resource.resourceType) {
|
|
991
|
+
throw new Error('Missing resourceType');
|
|
992
|
+
}
|
|
993
|
+
if (!resource.id) {
|
|
994
|
+
throw new Error('Missing id');
|
|
995
|
+
}
|
|
996
|
+
this.invalidateSearches(resource.resourceType);
|
|
997
|
+
const result = await this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
998
|
+
// On 304 not modified, result will be undefined
|
|
999
|
+
// Return the user input instead
|
|
1000
|
+
return result ?? resource;
|
|
1011
1001
|
}
|
|
1012
1002
|
/**
|
|
1013
1003
|
* Updates a FHIR resource using JSONPatch operations.
|
|
@@ -1242,18 +1232,16 @@ class MedplumClient extends EventTarget {
|
|
|
1242
1232
|
/**
|
|
1243
1233
|
* @category Authentication
|
|
1244
1234
|
*/
|
|
1245
|
-
setActiveLogin(login) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
|
|
1256
|
-
});
|
|
1235
|
+
async setActiveLogin(login) {
|
|
1236
|
+
__classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
|
|
1237
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
|
|
1238
|
+
__classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
|
|
1239
|
+
__classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
|
|
1240
|
+
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
|
|
1241
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
|
|
1242
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").clear();
|
|
1243
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
|
|
1244
|
+
await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
|
|
1257
1245
|
}
|
|
1258
1246
|
/**
|
|
1259
1247
|
* @category Authentication
|
|
@@ -1274,8 +1262,7 @@ class MedplumClient extends EventTarget {
|
|
|
1274
1262
|
* @category Authentication
|
|
1275
1263
|
*/
|
|
1276
1264
|
getLogins() {
|
|
1277
|
-
|
|
1278
|
-
return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
|
|
1265
|
+
return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins') ?? [];
|
|
1279
1266
|
}
|
|
1280
1267
|
/**
|
|
1281
1268
|
* @category Authentication
|
|
@@ -1292,13 +1279,11 @@ class MedplumClient extends EventTarget {
|
|
|
1292
1279
|
/**
|
|
1293
1280
|
* @category User Profile
|
|
1294
1281
|
*/
|
|
1295
|
-
getProfileAsync() {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
return this.getProfile();
|
|
1301
|
-
});
|
|
1282
|
+
async getProfileAsync() {
|
|
1283
|
+
if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
|
|
1284
|
+
await __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
1285
|
+
}
|
|
1286
|
+
return this.getProfile();
|
|
1302
1287
|
}
|
|
1303
1288
|
/**
|
|
1304
1289
|
* @category User Profile
|
|
@@ -1313,30 +1298,26 @@ class MedplumClient extends EventTarget {
|
|
|
1313
1298
|
* @param url The URL to request.
|
|
1314
1299
|
* @returns Promise to the response body as a blob.
|
|
1315
1300
|
*/
|
|
1316
|
-
download(url, options = {}) {
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
return response.blob();
|
|
1324
|
-
});
|
|
1301
|
+
async download(url, options = {}) {
|
|
1302
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
1303
|
+
await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1304
|
+
}
|
|
1305
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1306
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
|
|
1307
|
+
return response.blob();
|
|
1325
1308
|
}
|
|
1326
1309
|
/**
|
|
1327
1310
|
* Starts a new PKCE flow.
|
|
1328
1311
|
* These PKCE values are stateful, and must survive redirects and page refreshes.
|
|
1329
1312
|
*/
|
|
1330
|
-
startPkce() {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
sessionStorage.setItem('codeChallenge', codeChallenge);
|
|
1339
|
-
});
|
|
1313
|
+
async startPkce() {
|
|
1314
|
+
const pkceState = getRandomString();
|
|
1315
|
+
sessionStorage.setItem('pkceState', pkceState);
|
|
1316
|
+
const codeVerifier = getRandomString();
|
|
1317
|
+
sessionStorage.setItem('codeVerifier', codeVerifier);
|
|
1318
|
+
const arrayHash = await encryptSHA256(codeVerifier);
|
|
1319
|
+
const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
1320
|
+
sessionStorage.setItem('codeChallenge', codeChallenge);
|
|
1340
1321
|
}
|
|
1341
1322
|
/**
|
|
1342
1323
|
* Processes an OAuth authorization code.
|
|
@@ -1363,37 +1344,35 @@ class MedplumClient extends EventTarget {
|
|
|
1363
1344
|
* @param clientSecret The client secret.
|
|
1364
1345
|
* @returns Promise that resolves to the client profile.
|
|
1365
1346
|
*/
|
|
1366
|
-
startClientLogin(clientId, clientSecret) {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1347
|
+
async startClientLogin(clientId, clientSecret) {
|
|
1348
|
+
__classPrivateFieldSet(this, _MedplumClient_clientId, clientId, "f");
|
|
1349
|
+
__classPrivateFieldSet(this, _MedplumClient_clientSecret, clientSecret, "f");
|
|
1350
|
+
const formBody = new URLSearchParams();
|
|
1351
|
+
formBody.set('grant_type', 'client_credentials');
|
|
1352
|
+
formBody.set('client_id', clientId);
|
|
1353
|
+
formBody.set('client_secret', clientSecret);
|
|
1354
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
1374
1355
|
}
|
|
1375
1356
|
}
|
|
1376
|
-
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(),
|
|
1377
|
-
const logins = this.getLogins().filter((login) =>
|
|
1357
|
+
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_clientSecret = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
|
|
1358
|
+
const logins = this.getLogins().filter((login) => login.profile?.reference !== newLogin.profile?.reference);
|
|
1378
1359
|
logins.push(newLogin);
|
|
1379
1360
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
|
|
1380
|
-
}, _MedplumClient_refreshProfile = function _MedplumClient_refreshProfile() {
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
1394
|
-
});
|
|
1361
|
+
}, _MedplumClient_refreshProfile = async function _MedplumClient_refreshProfile() {
|
|
1362
|
+
__classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
|
|
1363
|
+
this.get('auth/me')
|
|
1364
|
+
.then((result) => {
|
|
1365
|
+
__classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
|
|
1366
|
+
__classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
|
|
1367
|
+
__classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
|
|
1368
|
+
this.dispatchEvent({ type: 'change' });
|
|
1369
|
+
resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
|
|
1370
|
+
})
|
|
1371
|
+
.catch(reject);
|
|
1372
|
+
}), "f");
|
|
1373
|
+
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
1395
1374
|
}, _MedplumClient_getCacheEntry = function _MedplumClient_getCacheEntry(key, options) {
|
|
1396
|
-
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 ||
|
|
1375
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 || options?.cache === 'no-cache' || options?.cache === 'reload') {
|
|
1397
1376
|
return undefined;
|
|
1398
1377
|
}
|
|
1399
1378
|
const entry = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(key);
|
|
@@ -1405,31 +1384,37 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
1405
1384
|
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
1406
1385
|
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
|
|
1407
1386
|
}
|
|
1408
|
-
}, _MedplumClient_request =
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1387
|
+
}, _MedplumClient_request =
|
|
1388
|
+
/**
|
|
1389
|
+
* Makes an HTTP request.
|
|
1390
|
+
* @param {string} method
|
|
1391
|
+
* @param {string} url
|
|
1392
|
+
* @param {string=} contentType
|
|
1393
|
+
* @param {Object=} body
|
|
1394
|
+
*/
|
|
1395
|
+
async function _MedplumClient_request(method, url, options = {}) {
|
|
1396
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
1397
|
+
await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1398
|
+
}
|
|
1399
|
+
if (!url.startsWith('http')) {
|
|
1400
|
+
url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
|
|
1401
|
+
}
|
|
1402
|
+
options.method = method;
|
|
1403
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1404
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
|
|
1405
|
+
if (response.status === 401) {
|
|
1406
|
+
// Refresh and try again
|
|
1407
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
|
|
1408
|
+
}
|
|
1409
|
+
if (response.status === 204 || response.status === 304) {
|
|
1410
|
+
// No content or change
|
|
1411
|
+
return undefined;
|
|
1412
|
+
}
|
|
1413
|
+
const obj = await response.json();
|
|
1414
|
+
if (response.status >= 400) {
|
|
1415
|
+
throw obj;
|
|
1416
|
+
}
|
|
1417
|
+
return obj;
|
|
1433
1418
|
}, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
|
|
1434
1419
|
if (!options.headers) {
|
|
1435
1420
|
options.headers = {};
|
|
@@ -1465,82 +1450,93 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
1465
1450
|
options.body = JSON.stringify(data);
|
|
1466
1451
|
}
|
|
1467
1452
|
}, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
|
|
1468
|
-
|
|
1469
|
-
return __classPrivateFieldGet(this, _MedplumClient_instances, "m",
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1453
|
+
if (__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)) {
|
|
1454
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options);
|
|
1455
|
+
}
|
|
1456
|
+
this.clear();
|
|
1457
|
+
if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
|
|
1458
|
+
__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
|
|
1459
|
+
}
|
|
1460
|
+
return Promise.reject(new Error('Unauthenticated'));
|
|
1461
|
+
}, _MedplumClient_requestAuthorization =
|
|
1462
|
+
/**
|
|
1463
|
+
* Redirects the user to the login screen for authorization.
|
|
1464
|
+
* Clears all auth state including local storage and session storage.
|
|
1465
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
|
|
1466
|
+
*/
|
|
1467
|
+
async function _MedplumClient_requestAuthorization() {
|
|
1468
|
+
await this.startPkce();
|
|
1469
|
+
const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
|
|
1470
|
+
url.searchParams.set('response_type', 'code');
|
|
1471
|
+
url.searchParams.set('state', sessionStorage.getItem('pkceState'));
|
|
1472
|
+
url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
1473
|
+
url.searchParams.set('redirect_uri', getBaseUrl());
|
|
1474
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
1475
|
+
url.searchParams.set('code_challenge', sessionStorage.getItem('codeChallenge'));
|
|
1476
|
+
window.location.assign(url.toString());
|
|
1491
1477
|
}, _MedplumClient_refresh = function _MedplumClient_refresh() {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
if (!__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
|
|
1497
|
-
this.clear();
|
|
1498
|
-
throw new Error('Invalid refresh token');
|
|
1499
|
-
}
|
|
1478
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
1479
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1480
|
+
}
|
|
1481
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
|
|
1500
1482
|
const formBody = new URLSearchParams();
|
|
1501
1483
|
formBody.set('grant_type', 'refresh_token');
|
|
1502
1484
|
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
1503
1485
|
formBody.set('refresh_token', __classPrivateFieldGet(this, _MedplumClient_refreshToken, "f"));
|
|
1504
1486
|
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody), "f");
|
|
1505
|
-
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
return __classPrivateFieldGet(this,
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
const tokenPayload = parseJWTPayload(token);
|
|
1529
|
-
if (Date.now() >= tokenPayload.exp * 1000) {
|
|
1530
|
-
this.clear();
|
|
1531
|
-
throw new Error('Token expired');
|
|
1532
|
-
}
|
|
1533
|
-
// Verify app_client_id
|
|
1534
|
-
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
|
|
1535
|
-
this.clear();
|
|
1536
|
-
throw new Error('Token was not issued for this audience');
|
|
1487
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1488
|
+
}
|
|
1489
|
+
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")) {
|
|
1490
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, this.startClientLogin(__classPrivateFieldGet(this, _MedplumClient_clientId, "f"), __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")), "f");
|
|
1491
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1492
|
+
}
|
|
1493
|
+
return undefined;
|
|
1494
|
+
}, _MedplumClient_fetchTokens =
|
|
1495
|
+
/**
|
|
1496
|
+
* Makes a POST request to the tokens endpoint.
|
|
1497
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
|
|
1498
|
+
* @param formBody Token parameters in URL encoded format.
|
|
1499
|
+
*/
|
|
1500
|
+
async function _MedplumClient_fetchTokens(formBody) {
|
|
1501
|
+
return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
|
|
1502
|
+
method: 'POST',
|
|
1503
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1504
|
+
body: formBody,
|
|
1505
|
+
credentials: 'include',
|
|
1506
|
+
})
|
|
1507
|
+
.then((response) => {
|
|
1508
|
+
if (!response.ok) {
|
|
1509
|
+
throw new Error('Failed to fetch tokens');
|
|
1537
1510
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1511
|
+
return response.json();
|
|
1512
|
+
})
|
|
1513
|
+
.then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
|
|
1514
|
+
.then(() => this.getProfile());
|
|
1515
|
+
}, _MedplumClient_verifyTokens =
|
|
1516
|
+
/**
|
|
1517
|
+
* Verifies the tokens received from the auth server.
|
|
1518
|
+
* Validates the JWT against the JWKS.
|
|
1519
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
|
|
1520
|
+
* @param tokens
|
|
1521
|
+
*/
|
|
1522
|
+
async function _MedplumClient_verifyTokens(tokens) {
|
|
1523
|
+
const token = tokens.access_token;
|
|
1524
|
+
// Verify token has not expired
|
|
1525
|
+
const tokenPayload = parseJWTPayload(token);
|
|
1526
|
+
if (Date.now() >= tokenPayload.exp * 1000) {
|
|
1527
|
+
this.clear();
|
|
1528
|
+
throw new Error('Token expired');
|
|
1529
|
+
}
|
|
1530
|
+
// Verify app_client_id
|
|
1531
|
+
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
|
|
1532
|
+
this.clear();
|
|
1533
|
+
throw new Error('Token was not issued for this audience');
|
|
1534
|
+
}
|
|
1535
|
+
await this.setActiveLogin({
|
|
1536
|
+
accessToken: token,
|
|
1537
|
+
refreshToken: tokens.refresh_token,
|
|
1538
|
+
project: tokens.project,
|
|
1539
|
+
profile: tokens.profile,
|
|
1544
1540
|
});
|
|
1545
1541
|
}, _MedplumClient_setupStorageListener = function _MedplumClient_setupStorageListener() {
|
|
1546
1542
|
try {
|
|
@@ -1572,4 +1568,4 @@ function ensureTrailingSlash(url) {
|
|
|
1572
1568
|
}
|
|
1573
1569
|
|
|
1574
1570
|
export { MEDPLUM_VERSION, MedplumClient };
|
|
1575
|
-
//# sourceMappingURL=client.
|
|
1571
|
+
//# sourceMappingURL=client.mjs.map
|