@medplum/core 0.9.14 → 0.9.15

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/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.
@@ -2396,8 +2247,8 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
2396
2247
  return undefined;
2397
2248
  }
2398
2249
  const obj = yield response.json();
2399
- if ((obj === null || obj === void 0 ? void 0 : obj.resourceType) === 'OperationOutcome' && !isOk(obj)) {
2400
- return Promise.reject(obj);
2250
+ if (response.status >= 400) {
2251
+ throw obj;
2401
2252
  }
2402
2253
  return obj;
2403
2254
  });
@@ -5186,6 +5037,155 @@ class Hl7Field {
5186
5037
  }
5187
5038
  }
5188
5039
 
5040
+ const OK_ID = 'ok';
5041
+ const CREATED_ID = 'created';
5042
+ const GONE_ID = 'gone';
5043
+ const NOT_MODIFIED_ID = 'not-modified';
5044
+ const NOT_FOUND_ID = 'not-found';
5045
+ const ACCESS_DENIED = 'access-denied';
5046
+ const allOk = {
5047
+ resourceType: 'OperationOutcome',
5048
+ id: OK_ID,
5049
+ issue: [
5050
+ {
5051
+ severity: 'information',
5052
+ code: 'information',
5053
+ details: {
5054
+ text: 'All OK',
5055
+ },
5056
+ },
5057
+ ],
5058
+ };
5059
+ const created = {
5060
+ resourceType: 'OperationOutcome',
5061
+ id: CREATED_ID,
5062
+ issue: [
5063
+ {
5064
+ severity: 'information',
5065
+ code: 'information',
5066
+ details: {
5067
+ text: 'Created',
5068
+ },
5069
+ },
5070
+ ],
5071
+ };
5072
+ const notModified = {
5073
+ resourceType: 'OperationOutcome',
5074
+ id: NOT_MODIFIED_ID,
5075
+ issue: [
5076
+ {
5077
+ severity: 'information',
5078
+ code: 'information',
5079
+ details: {
5080
+ text: 'Not Modified',
5081
+ },
5082
+ },
5083
+ ],
5084
+ };
5085
+ const notFound = {
5086
+ resourceType: 'OperationOutcome',
5087
+ id: NOT_FOUND_ID,
5088
+ issue: [
5089
+ {
5090
+ severity: 'error',
5091
+ code: 'not-found',
5092
+ details: {
5093
+ text: 'Not found',
5094
+ },
5095
+ },
5096
+ ],
5097
+ };
5098
+ const gone = {
5099
+ resourceType: 'OperationOutcome',
5100
+ id: GONE_ID,
5101
+ issue: [
5102
+ {
5103
+ severity: 'error',
5104
+ code: 'gone',
5105
+ details: {
5106
+ text: 'Gone',
5107
+ },
5108
+ },
5109
+ ],
5110
+ };
5111
+ const accessDenied = {
5112
+ resourceType: 'OperationOutcome',
5113
+ id: ACCESS_DENIED,
5114
+ issue: [
5115
+ {
5116
+ severity: 'error',
5117
+ code: 'access-denied',
5118
+ details: {
5119
+ text: 'Access Denied',
5120
+ },
5121
+ },
5122
+ ],
5123
+ };
5124
+ function badRequest(details, expression) {
5125
+ return {
5126
+ resourceType: 'OperationOutcome',
5127
+ issue: [
5128
+ {
5129
+ severity: 'error',
5130
+ code: 'invalid',
5131
+ details: {
5132
+ text: details,
5133
+ },
5134
+ expression: expression ? [expression] : undefined,
5135
+ },
5136
+ ],
5137
+ };
5138
+ }
5139
+ function isOk(outcome) {
5140
+ return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
5141
+ }
5142
+ function isNotFound(outcome) {
5143
+ return outcome.id === NOT_FOUND_ID;
5144
+ }
5145
+ function isGone(outcome) {
5146
+ return outcome.id === GONE_ID;
5147
+ }
5148
+ function getStatus(outcome) {
5149
+ if (outcome.id === OK_ID) {
5150
+ return 200;
5151
+ }
5152
+ else if (outcome.id === CREATED_ID) {
5153
+ return 201;
5154
+ }
5155
+ else if (outcome.id === NOT_MODIFIED_ID) {
5156
+ return 304;
5157
+ }
5158
+ else if (outcome.id === ACCESS_DENIED) {
5159
+ return 403;
5160
+ }
5161
+ else if (outcome.id === NOT_FOUND_ID) {
5162
+ return 404;
5163
+ }
5164
+ else if (outcome.id === GONE_ID) {
5165
+ return 410;
5166
+ }
5167
+ else {
5168
+ return 400;
5169
+ }
5170
+ }
5171
+ /**
5172
+ * Asserts that the operation completed successfully and that the resource is defined.
5173
+ * @param outcome The operation outcome.
5174
+ * @param resource The resource that may or may not have been returned.
5175
+ */
5176
+ function assertOk(outcome, resource) {
5177
+ if (!isOk(outcome) || resource === undefined) {
5178
+ throw new OperationOutcomeError(outcome);
5179
+ }
5180
+ }
5181
+ class OperationOutcomeError extends Error {
5182
+ constructor(outcome) {
5183
+ var _a, _b;
5184
+ 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);
5185
+ this.outcome = outcome;
5186
+ }
5187
+ }
5188
+
5189
5189
  const DEFAULT_SEARCH_COUNT = 20;
5190
5190
  /**
5191
5191
  * Search operators.