@medplum/core 0.9.13 → 0.9.16
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/dist/cjs/index.js +184 -173
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +184 -173
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/client.d.ts +12 -0
- package/package.json +2 -2
- package/cody-pdf-test.js +0 -32
- package/wget-log +0 -6
package/dist/esm/index.js
CHANGED
|
@@ -814,155 +814,6 @@ function parseJWTPayload(token) {
|
|
|
814
814
|
return decodePayload(payload);
|
|
815
815
|
}
|
|
816
816
|
|
|
817
|
-
const OK_ID = 'ok';
|
|
818
|
-
const CREATED_ID = 'created';
|
|
819
|
-
const GONE_ID = 'gone';
|
|
820
|
-
const NOT_MODIFIED_ID = 'not-modified';
|
|
821
|
-
const NOT_FOUND_ID = 'not-found';
|
|
822
|
-
const ACCESS_DENIED = 'access-denied';
|
|
823
|
-
const allOk = {
|
|
824
|
-
resourceType: 'OperationOutcome',
|
|
825
|
-
id: OK_ID,
|
|
826
|
-
issue: [
|
|
827
|
-
{
|
|
828
|
-
severity: 'information',
|
|
829
|
-
code: 'information',
|
|
830
|
-
details: {
|
|
831
|
-
text: 'All OK',
|
|
832
|
-
},
|
|
833
|
-
},
|
|
834
|
-
],
|
|
835
|
-
};
|
|
836
|
-
const created = {
|
|
837
|
-
resourceType: 'OperationOutcome',
|
|
838
|
-
id: CREATED_ID,
|
|
839
|
-
issue: [
|
|
840
|
-
{
|
|
841
|
-
severity: 'information',
|
|
842
|
-
code: 'information',
|
|
843
|
-
details: {
|
|
844
|
-
text: 'Created',
|
|
845
|
-
},
|
|
846
|
-
},
|
|
847
|
-
],
|
|
848
|
-
};
|
|
849
|
-
const notModified = {
|
|
850
|
-
resourceType: 'OperationOutcome',
|
|
851
|
-
id: NOT_MODIFIED_ID,
|
|
852
|
-
issue: [
|
|
853
|
-
{
|
|
854
|
-
severity: 'information',
|
|
855
|
-
code: 'information',
|
|
856
|
-
details: {
|
|
857
|
-
text: 'Not Modified',
|
|
858
|
-
},
|
|
859
|
-
},
|
|
860
|
-
],
|
|
861
|
-
};
|
|
862
|
-
const notFound = {
|
|
863
|
-
resourceType: 'OperationOutcome',
|
|
864
|
-
id: NOT_FOUND_ID,
|
|
865
|
-
issue: [
|
|
866
|
-
{
|
|
867
|
-
severity: 'error',
|
|
868
|
-
code: 'not-found',
|
|
869
|
-
details: {
|
|
870
|
-
text: 'Not found',
|
|
871
|
-
},
|
|
872
|
-
},
|
|
873
|
-
],
|
|
874
|
-
};
|
|
875
|
-
const gone = {
|
|
876
|
-
resourceType: 'OperationOutcome',
|
|
877
|
-
id: GONE_ID,
|
|
878
|
-
issue: [
|
|
879
|
-
{
|
|
880
|
-
severity: 'error',
|
|
881
|
-
code: 'gone',
|
|
882
|
-
details: {
|
|
883
|
-
text: 'Gone',
|
|
884
|
-
},
|
|
885
|
-
},
|
|
886
|
-
],
|
|
887
|
-
};
|
|
888
|
-
const accessDenied = {
|
|
889
|
-
resourceType: 'OperationOutcome',
|
|
890
|
-
id: ACCESS_DENIED,
|
|
891
|
-
issue: [
|
|
892
|
-
{
|
|
893
|
-
severity: 'error',
|
|
894
|
-
code: 'access-denied',
|
|
895
|
-
details: {
|
|
896
|
-
text: 'Access Denied',
|
|
897
|
-
},
|
|
898
|
-
},
|
|
899
|
-
],
|
|
900
|
-
};
|
|
901
|
-
function badRequest(details, expression) {
|
|
902
|
-
return {
|
|
903
|
-
resourceType: 'OperationOutcome',
|
|
904
|
-
issue: [
|
|
905
|
-
{
|
|
906
|
-
severity: 'error',
|
|
907
|
-
code: 'invalid',
|
|
908
|
-
details: {
|
|
909
|
-
text: details,
|
|
910
|
-
},
|
|
911
|
-
expression: expression ? [expression] : undefined,
|
|
912
|
-
},
|
|
913
|
-
],
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
function isOk(outcome) {
|
|
917
|
-
return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
|
|
918
|
-
}
|
|
919
|
-
function isNotFound(outcome) {
|
|
920
|
-
return outcome.id === NOT_FOUND_ID;
|
|
921
|
-
}
|
|
922
|
-
function isGone(outcome) {
|
|
923
|
-
return outcome.id === GONE_ID;
|
|
924
|
-
}
|
|
925
|
-
function getStatus(outcome) {
|
|
926
|
-
if (outcome.id === OK_ID) {
|
|
927
|
-
return 200;
|
|
928
|
-
}
|
|
929
|
-
else if (outcome.id === CREATED_ID) {
|
|
930
|
-
return 201;
|
|
931
|
-
}
|
|
932
|
-
else if (outcome.id === NOT_MODIFIED_ID) {
|
|
933
|
-
return 304;
|
|
934
|
-
}
|
|
935
|
-
else if (outcome.id === ACCESS_DENIED) {
|
|
936
|
-
return 403;
|
|
937
|
-
}
|
|
938
|
-
else if (outcome.id === NOT_FOUND_ID) {
|
|
939
|
-
return 404;
|
|
940
|
-
}
|
|
941
|
-
else if (outcome.id === GONE_ID) {
|
|
942
|
-
return 410;
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
return 400;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Asserts that the operation completed successfully and that the resource is defined.
|
|
950
|
-
* @param outcome The operation outcome.
|
|
951
|
-
* @param resource The resource that may or may not have been returned.
|
|
952
|
-
*/
|
|
953
|
-
function assertOk(outcome, resource) {
|
|
954
|
-
if (!isOk(outcome) || resource === undefined) {
|
|
955
|
-
throw new OperationOutcomeError(outcome);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
class OperationOutcomeError extends Error {
|
|
959
|
-
constructor(outcome) {
|
|
960
|
-
var _a, _b;
|
|
961
|
-
super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
|
|
962
|
-
this.outcome = outcome;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
817
|
var _ReadablePromise_suspender, _ReadablePromise_status, _ReadablePromise_response, _ReadablePromise_error, _a;
|
|
967
818
|
/**
|
|
968
819
|
* The ReadablePromise class wraps a request promise suitable for React Suspense.
|
|
@@ -1327,10 +1178,11 @@ function getPropertyDisplayName(property) {
|
|
|
1327
1178
|
|
|
1328
1179
|
// PKCE auth ased on:
|
|
1329
1180
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
1330
|
-
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_schema, _MedplumClient_requestCache, _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_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
|
|
1181
|
+
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_schema, _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;
|
|
1331
1182
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
1332
1183
|
const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
|
|
1333
1184
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
1185
|
+
const DEFAULT_CACHE_TIME = 10000; // 10 seconds
|
|
1334
1186
|
const JSON_CONTENT_TYPE = 'application/json';
|
|
1335
1187
|
const FHIR_CONTENT_TYPE = 'application/fhir+json';
|
|
1336
1188
|
const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
@@ -1383,7 +1235,7 @@ const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
|
1383
1235
|
*/
|
|
1384
1236
|
class MedplumClient extends EventTarget {
|
|
1385
1237
|
constructor(options) {
|
|
1386
|
-
var _a;
|
|
1238
|
+
var _a, _b;
|
|
1387
1239
|
super();
|
|
1388
1240
|
_MedplumClient_instances.add(this);
|
|
1389
1241
|
_MedplumClient_fetch.set(this, void 0);
|
|
@@ -1391,6 +1243,7 @@ class MedplumClient extends EventTarget {
|
|
|
1391
1243
|
_MedplumClient_storage.set(this, void 0);
|
|
1392
1244
|
_MedplumClient_schema.set(this, void 0);
|
|
1393
1245
|
_MedplumClient_requestCache.set(this, void 0);
|
|
1246
|
+
_MedplumClient_cacheTime.set(this, void 0);
|
|
1394
1247
|
_MedplumClient_baseUrl.set(this, void 0);
|
|
1395
1248
|
_MedplumClient_clientId.set(this, void 0);
|
|
1396
1249
|
_MedplumClient_authorizeUrl.set(this, void 0);
|
|
@@ -1416,6 +1269,7 @@ class MedplumClient extends EventTarget {
|
|
|
1416
1269
|
__classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
|
|
1417
1270
|
__classPrivateFieldSet(this, _MedplumClient_schema, createSchema(), "f");
|
|
1418
1271
|
__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");
|
|
1272
|
+
__classPrivateFieldSet(this, _MedplumClient_cacheTime, (_b = options === null || options === void 0 ? void 0 : options.cacheTime) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME, "f");
|
|
1419
1273
|
__classPrivateFieldSet(this, _MedplumClient_baseUrl, (options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
|
|
1420
1274
|
__classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
|
|
1421
1275
|
__classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
|
|
@@ -1484,14 +1338,12 @@ class MedplumClient extends EventTarget {
|
|
|
1484
1338
|
*/
|
|
1485
1339
|
get(url, options = {}) {
|
|
1486
1340
|
url = url.toString();
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
return cached;
|
|
1491
|
-
}
|
|
1341
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, url, options);
|
|
1342
|
+
if (cached) {
|
|
1343
|
+
return cached.value;
|
|
1492
1344
|
}
|
|
1493
1345
|
const promise = new ReadablePromise(__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'GET', url, options));
|
|
1494
|
-
__classPrivateFieldGet(this,
|
|
1346
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, url, promise);
|
|
1495
1347
|
return promise;
|
|
1496
1348
|
}
|
|
1497
1349
|
/**
|
|
@@ -1731,14 +1583,12 @@ class MedplumClient extends EventTarget {
|
|
|
1731
1583
|
url.searchParams.set('_count', '1');
|
|
1732
1584
|
url.searchParams.sort();
|
|
1733
1585
|
const cacheKey = url.toString() + '-searchOne';
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
return cached;
|
|
1738
|
-
}
|
|
1586
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, options);
|
|
1587
|
+
if (cached) {
|
|
1588
|
+
return cached.value;
|
|
1739
1589
|
}
|
|
1740
1590
|
const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) => { var _a, _b; return (_b = (_a = b.entry) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.resource; }));
|
|
1741
|
-
__classPrivateFieldGet(this,
|
|
1591
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
1742
1592
|
return promise;
|
|
1743
1593
|
}
|
|
1744
1594
|
/**
|
|
@@ -1763,14 +1613,12 @@ class MedplumClient extends EventTarget {
|
|
|
1763
1613
|
searchResources(resourceType, query, options = {}) {
|
|
1764
1614
|
const url = this.fhirSearchUrl(resourceType, query);
|
|
1765
1615
|
const cacheKey = url.toString() + '-searchResources';
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
return cached;
|
|
1770
|
-
}
|
|
1616
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, options);
|
|
1617
|
+
if (cached) {
|
|
1618
|
+
return cached.value;
|
|
1771
1619
|
}
|
|
1772
1620
|
const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) => { var _a, _b; return (_b = (_a = b.entry) === null || _a === void 0 ? void 0 : _a.map((e) => e.resource)) !== null && _b !== void 0 ? _b : []; }));
|
|
1773
|
-
__classPrivateFieldGet(this,
|
|
1621
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
1774
1622
|
return promise;
|
|
1775
1623
|
}
|
|
1776
1624
|
/**
|
|
@@ -1793,7 +1641,8 @@ class MedplumClient extends EventTarget {
|
|
|
1793
1641
|
* @returns The resource if it is available in the cache; undefined otherwise.
|
|
1794
1642
|
*/
|
|
1795
1643
|
getCached(resourceType, id) {
|
|
1796
|
-
|
|
1644
|
+
var _a;
|
|
1645
|
+
const cached = (_a = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())) === null || _a === void 0 ? void 0 : _a.value;
|
|
1797
1646
|
return cached && !cached.isPending() ? cached.read() : undefined;
|
|
1798
1647
|
}
|
|
1799
1648
|
/**
|
|
@@ -2357,7 +2206,7 @@ class MedplumClient extends EventTarget {
|
|
|
2357
2206
|
});
|
|
2358
2207
|
}
|
|
2359
2208
|
}
|
|
2360
|
-
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_schema = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = 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) {
|
|
2209
|
+
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_schema = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = 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) {
|
|
2361
2210
|
const logins = this.getLogins().filter((login) => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.reference) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.reference); });
|
|
2362
2211
|
logins.push(newLogin);
|
|
2363
2212
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
|
|
@@ -2376,6 +2225,19 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
2376
2225
|
}), "f");
|
|
2377
2226
|
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
2378
2227
|
});
|
|
2228
|
+
}, _MedplumClient_getCacheEntry = function _MedplumClient_getCacheEntry(key, options) {
|
|
2229
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 || (options === null || options === void 0 ? void 0 : options.cache) === 'no-cache' || (options === null || options === void 0 ? void 0 : options.cache) === 'reload') {
|
|
2230
|
+
return undefined;
|
|
2231
|
+
}
|
|
2232
|
+
const entry = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(key);
|
|
2233
|
+
if (!entry || entry.requestTime + __classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") < Date.now()) {
|
|
2234
|
+
return undefined;
|
|
2235
|
+
}
|
|
2236
|
+
return entry;
|
|
2237
|
+
}, _MedplumClient_setCacheEntry = function _MedplumClient_setCacheEntry(key, value) {
|
|
2238
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
2239
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
|
|
2240
|
+
}
|
|
2379
2241
|
}, _MedplumClient_request = function _MedplumClient_request(method, url, options = {}) {
|
|
2380
2242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2381
2243
|
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
@@ -2396,8 +2258,8 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
2396
2258
|
return undefined;
|
|
2397
2259
|
}
|
|
2398
2260
|
const obj = yield response.json();
|
|
2399
|
-
if (
|
|
2400
|
-
|
|
2261
|
+
if (response.status >= 400) {
|
|
2262
|
+
throw obj;
|
|
2401
2263
|
}
|
|
2402
2264
|
return obj;
|
|
2403
2265
|
});
|
|
@@ -5186,6 +5048,155 @@ class Hl7Field {
|
|
|
5186
5048
|
}
|
|
5187
5049
|
}
|
|
5188
5050
|
|
|
5051
|
+
const OK_ID = 'ok';
|
|
5052
|
+
const CREATED_ID = 'created';
|
|
5053
|
+
const GONE_ID = 'gone';
|
|
5054
|
+
const NOT_MODIFIED_ID = 'not-modified';
|
|
5055
|
+
const NOT_FOUND_ID = 'not-found';
|
|
5056
|
+
const ACCESS_DENIED = 'access-denied';
|
|
5057
|
+
const allOk = {
|
|
5058
|
+
resourceType: 'OperationOutcome',
|
|
5059
|
+
id: OK_ID,
|
|
5060
|
+
issue: [
|
|
5061
|
+
{
|
|
5062
|
+
severity: 'information',
|
|
5063
|
+
code: 'information',
|
|
5064
|
+
details: {
|
|
5065
|
+
text: 'All OK',
|
|
5066
|
+
},
|
|
5067
|
+
},
|
|
5068
|
+
],
|
|
5069
|
+
};
|
|
5070
|
+
const created = {
|
|
5071
|
+
resourceType: 'OperationOutcome',
|
|
5072
|
+
id: CREATED_ID,
|
|
5073
|
+
issue: [
|
|
5074
|
+
{
|
|
5075
|
+
severity: 'information',
|
|
5076
|
+
code: 'information',
|
|
5077
|
+
details: {
|
|
5078
|
+
text: 'Created',
|
|
5079
|
+
},
|
|
5080
|
+
},
|
|
5081
|
+
],
|
|
5082
|
+
};
|
|
5083
|
+
const notModified = {
|
|
5084
|
+
resourceType: 'OperationOutcome',
|
|
5085
|
+
id: NOT_MODIFIED_ID,
|
|
5086
|
+
issue: [
|
|
5087
|
+
{
|
|
5088
|
+
severity: 'information',
|
|
5089
|
+
code: 'information',
|
|
5090
|
+
details: {
|
|
5091
|
+
text: 'Not Modified',
|
|
5092
|
+
},
|
|
5093
|
+
},
|
|
5094
|
+
],
|
|
5095
|
+
};
|
|
5096
|
+
const notFound = {
|
|
5097
|
+
resourceType: 'OperationOutcome',
|
|
5098
|
+
id: NOT_FOUND_ID,
|
|
5099
|
+
issue: [
|
|
5100
|
+
{
|
|
5101
|
+
severity: 'error',
|
|
5102
|
+
code: 'not-found',
|
|
5103
|
+
details: {
|
|
5104
|
+
text: 'Not found',
|
|
5105
|
+
},
|
|
5106
|
+
},
|
|
5107
|
+
],
|
|
5108
|
+
};
|
|
5109
|
+
const gone = {
|
|
5110
|
+
resourceType: 'OperationOutcome',
|
|
5111
|
+
id: GONE_ID,
|
|
5112
|
+
issue: [
|
|
5113
|
+
{
|
|
5114
|
+
severity: 'error',
|
|
5115
|
+
code: 'gone',
|
|
5116
|
+
details: {
|
|
5117
|
+
text: 'Gone',
|
|
5118
|
+
},
|
|
5119
|
+
},
|
|
5120
|
+
],
|
|
5121
|
+
};
|
|
5122
|
+
const accessDenied = {
|
|
5123
|
+
resourceType: 'OperationOutcome',
|
|
5124
|
+
id: ACCESS_DENIED,
|
|
5125
|
+
issue: [
|
|
5126
|
+
{
|
|
5127
|
+
severity: 'error',
|
|
5128
|
+
code: 'access-denied',
|
|
5129
|
+
details: {
|
|
5130
|
+
text: 'Access Denied',
|
|
5131
|
+
},
|
|
5132
|
+
},
|
|
5133
|
+
],
|
|
5134
|
+
};
|
|
5135
|
+
function badRequest(details, expression) {
|
|
5136
|
+
return {
|
|
5137
|
+
resourceType: 'OperationOutcome',
|
|
5138
|
+
issue: [
|
|
5139
|
+
{
|
|
5140
|
+
severity: 'error',
|
|
5141
|
+
code: 'invalid',
|
|
5142
|
+
details: {
|
|
5143
|
+
text: details,
|
|
5144
|
+
},
|
|
5145
|
+
expression: expression ? [expression] : undefined,
|
|
5146
|
+
},
|
|
5147
|
+
],
|
|
5148
|
+
};
|
|
5149
|
+
}
|
|
5150
|
+
function isOk(outcome) {
|
|
5151
|
+
return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
|
|
5152
|
+
}
|
|
5153
|
+
function isNotFound(outcome) {
|
|
5154
|
+
return outcome.id === NOT_FOUND_ID;
|
|
5155
|
+
}
|
|
5156
|
+
function isGone(outcome) {
|
|
5157
|
+
return outcome.id === GONE_ID;
|
|
5158
|
+
}
|
|
5159
|
+
function getStatus(outcome) {
|
|
5160
|
+
if (outcome.id === OK_ID) {
|
|
5161
|
+
return 200;
|
|
5162
|
+
}
|
|
5163
|
+
else if (outcome.id === CREATED_ID) {
|
|
5164
|
+
return 201;
|
|
5165
|
+
}
|
|
5166
|
+
else if (outcome.id === NOT_MODIFIED_ID) {
|
|
5167
|
+
return 304;
|
|
5168
|
+
}
|
|
5169
|
+
else if (outcome.id === ACCESS_DENIED) {
|
|
5170
|
+
return 403;
|
|
5171
|
+
}
|
|
5172
|
+
else if (outcome.id === NOT_FOUND_ID) {
|
|
5173
|
+
return 404;
|
|
5174
|
+
}
|
|
5175
|
+
else if (outcome.id === GONE_ID) {
|
|
5176
|
+
return 410;
|
|
5177
|
+
}
|
|
5178
|
+
else {
|
|
5179
|
+
return 400;
|
|
5180
|
+
}
|
|
5181
|
+
}
|
|
5182
|
+
/**
|
|
5183
|
+
* Asserts that the operation completed successfully and that the resource is defined.
|
|
5184
|
+
* @param outcome The operation outcome.
|
|
5185
|
+
* @param resource The resource that may or may not have been returned.
|
|
5186
|
+
*/
|
|
5187
|
+
function assertOk(outcome, resource) {
|
|
5188
|
+
if (!isOk(outcome) || resource === undefined) {
|
|
5189
|
+
throw new OperationOutcomeError(outcome);
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
5192
|
+
class OperationOutcomeError extends Error {
|
|
5193
|
+
constructor(outcome) {
|
|
5194
|
+
var _a, _b;
|
|
5195
|
+
super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
|
|
5196
|
+
this.outcome = outcome;
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
|
|
5189
5200
|
const DEFAULT_SEARCH_COUNT = 20;
|
|
5190
5201
|
/**
|
|
5191
5202
|
* Search operators.
|