@openmrs/esm-api 5.3.3-pre.1237 → 5.3.3-pre.1247

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/jest.config.js CHANGED
@@ -1,17 +1,16 @@
1
1
  module.exports = {
2
2
  transform: {
3
- "^.+\\.tsx?$": ["@swc/jest"],
3
+ '^.+\\.tsx?$': ['@swc/jest'],
4
4
  },
5
5
  moduleNameMapper: {
6
- "lodash-es": "lodash",
7
- "@openmrs/esm-error-handling":
8
- "<rootDir>/__mocks__/openmrs-esm-error-handling.mock.ts",
9
- "@openmrs/esm-config": "<rootDir>/__mocks__/openmrs-esm-config.mock.ts",
10
- "single-spa": "<rootDir>/__mocks__/single-spa.mock.ts",
11
- dexie: require.resolve("dexie"),
6
+ 'lodash-es': 'lodash',
7
+ '@openmrs/esm-error-handling': '<rootDir>/__mocks__/openmrs-esm-error-handling.mock.ts',
8
+ '@openmrs/esm-config': '<rootDir>/__mocks__/openmrs-esm-config.mock.ts',
9
+ 'single-spa': '<rootDir>/__mocks__/single-spa.mock.ts',
10
+ dexie: require.resolve('dexie'),
12
11
  },
13
- testEnvironment: "jsdom",
12
+ testEnvironment: 'jsdom',
14
13
  testEnvironmentOptions: {
15
- url: "http://localhost/",
14
+ url: 'http://localhost/',
16
15
  },
17
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-api",
3
- "version": "5.3.3-pre.1237",
3
+ "version": "5.3.3-pre.1247",
4
4
  "license": "MPL-2.0",
5
5
  "description": "The javascript module for interacting with the OpenMRS API",
6
6
  "browser": "dist/openmrs-esm-api.js",
@@ -47,9 +47,9 @@
47
47
  "@openmrs/esm-offline": "5.x"
48
48
  },
49
49
  "devDependencies": {
50
- "@openmrs/esm-config": "5.3.3-pre.1237",
51
- "@openmrs/esm-error-handling": "5.3.3-pre.1237",
52
- "@openmrs/esm-state": "5.3.3-pre.1237",
50
+ "@openmrs/esm-config": "5.3.3-pre.1247",
51
+ "@openmrs/esm-error-handling": "5.3.3-pre.1247",
52
+ "@openmrs/esm-state": "5.3.3-pre.1247",
53
53
  "rxjs": "^6.5.3",
54
54
  "webpack": "^5.88.0"
55
55
  },
@@ -1,6 +1,3 @@
1
1
  export function isDevEnabled() {
2
- return (
3
- window.spaEnv === "development" ||
4
- localStorage.getItem("openmrs:devtools") === "true"
5
- );
2
+ return window.spaEnv === 'development' || localStorage.getItem('openmrs:devtools') === 'true';
6
3
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from "./types";
2
- export * from "./openmrs-fetch";
3
- export * from "./setup";
1
+ export * from './types';
2
+ export * from './openmrs-fetch';
3
+ export * from './setup';
4
4
 
5
- export * from "./shared-api-objects/current-user";
6
- export * from "./shared-api-objects/current-patient";
7
- export * from "./shared-api-objects/visit-utils";
8
- export * from "./shared-api-objects/visit-type";
9
- export * from "./shared-api-objects/location";
5
+ export * from './shared-api-objects/current-user';
6
+ export * from './shared-api-objects/current-patient';
7
+ export * from './shared-api-objects/visit-utils';
8
+ export * from './shared-api-objects/visit-type';
9
+ export * from './shared-api-objects/location';
10
10
 
11
- export * from "./openmrs-backend-dependencies";
11
+ export * from './openmrs-backend-dependencies';
@@ -1,4 +1,4 @@
1
1
  export const backendDependencies = {
2
- "webservices.rest": "2.24.0",
3
- fhir2: "1.0.0-SNAPSHOT",
2
+ 'webservices.rest': '2.24.0',
3
+ fhir2: '1.0.0-SNAPSHOT',
4
4
  };
@@ -1,19 +1,16 @@
1
- import { openmrsFetch, openmrsObservableFetch } from "./openmrs-fetch";
2
- import { isObservable } from "rxjs";
1
+ import { openmrsFetch, openmrsObservableFetch } from './openmrs-fetch';
2
+ import { isObservable } from 'rxjs';
3
3
 
4
- import {
5
- getConfig as mockGetConfig,
6
- navigate as mockNavigate,
7
- } from "@openmrs/esm-config";
4
+ import { getConfig as mockGetConfig, navigate as mockNavigate } from '@openmrs/esm-config';
8
5
 
9
- describe("openmrsFetch", () => {
6
+ describe('openmrsFetch', () => {
10
7
  beforeEach(() => {
11
8
  // @ts-ignore
12
- window.openmrsBase = "/openmrs";
9
+ window.openmrsBase = '/openmrs';
13
10
  // @ts-ignore
14
- window.getOpenmrsSpaBase = () => "/openmrs/spa/";
11
+ window.getOpenmrsSpaBase = () => '/openmrs/spa/';
15
12
  window.fetch = jest.fn();
16
- Object.defineProperty(window, "location", {
13
+ Object.defineProperty(window, 'location', {
17
14
  writable: true,
18
15
  value: { assign: jest.fn() },
19
16
  });
@@ -35,29 +32,27 @@ describe("openmrsFetch", () => {
35
32
 
36
33
  it(`throws an error if you pass in an invalid fetchInit object`, () => {
37
34
  // @ts-ignore
38
- expect(() => openmrsFetch("/session", "invalid second arg")).toThrowError(
39
- /second argument/
40
- );
35
+ expect(() => openmrsFetch('/session', 'invalid second arg')).toThrowError(/second argument/);
41
36
 
42
37
  // @ts-ignore
43
- expect(() => openmrsFetch("/session", 123)).toThrowError(/second argument/);
38
+ expect(() => openmrsFetch('/session', 123)).toThrowError(/second argument/);
44
39
  });
45
40
 
46
41
  it(`throws an Error if there is no openmrsBase`, () => {
47
42
  // @ts-ignore
48
43
  delete window.openmrsBase;
49
44
 
50
- expect(() => openmrsFetch("/session")).toThrowError(/openmrsBase/);
45
+ expect(() => openmrsFetch('/session')).toThrowError(/openmrsBase/);
51
46
  });
52
47
 
53
48
  it(`calls window.fetch with the correct arguments for a basic GET request`, () => {
54
49
  // @ts-ignore
55
50
  window.fetch.mockReturnValue(new Promise(() => {}));
56
- openmrsFetch("/ws/rest/v1/session");
57
- expect(window.fetch).toHaveBeenCalledWith("/openmrs/ws/rest/v1/session", {
51
+ openmrsFetch('/ws/rest/v1/session');
52
+ expect(window.fetch).toHaveBeenCalledWith('/openmrs/ws/rest/v1/session', {
58
53
  headers: {
59
- Accept: "application/json",
60
- "Disable-WWW-Authenticate": "true",
54
+ Accept: 'application/json',
55
+ 'Disable-WWW-Authenticate': 'true',
61
56
  },
62
57
  });
63
58
  });
@@ -65,34 +60,34 @@ describe("openmrsFetch", () => {
65
60
  it(`calls window.fetch correctly for requests that have a request body`, () => {
66
61
  // @ts-ignore
67
62
  window.fetch.mockReturnValue(new Promise(() => {}));
68
- const requestBody = { some: "json" };
69
- openmrsFetch("/ws/rest/v1/session", {
70
- method: "POST",
63
+ const requestBody = { some: 'json' };
64
+ openmrsFetch('/ws/rest/v1/session', {
65
+ method: 'POST',
71
66
  body: requestBody,
72
67
  });
73
- expect(window.fetch).toHaveBeenCalledWith("/openmrs/ws/rest/v1/session", {
68
+ expect(window.fetch).toHaveBeenCalledWith('/openmrs/ws/rest/v1/session', {
74
69
  headers: {
75
- Accept: "application/json",
76
- "Disable-WWW-Authenticate": "true",
70
+ Accept: 'application/json',
71
+ 'Disable-WWW-Authenticate': 'true',
77
72
  },
78
73
  body: JSON.stringify(requestBody),
79
- method: "POST",
74
+ method: 'POST',
80
75
  });
81
76
  });
82
77
 
83
78
  it(`allows you to specify your own Accept request header`, () => {
84
79
  // @ts-ignore
85
80
  window.fetch.mockReturnValue(new Promise(() => {}));
86
- const requestBody = { some: "json" };
87
- openmrsFetch("/ws/rest/v1/session", {
81
+ const requestBody = { some: 'json' };
82
+ openmrsFetch('/ws/rest/v1/session', {
88
83
  headers: {
89
- Accept: "application/xml",
84
+ Accept: 'application/xml',
90
85
  },
91
86
  });
92
- expect(window.fetch).toHaveBeenCalledWith("/openmrs/ws/rest/v1/session", {
87
+ expect(window.fetch).toHaveBeenCalledWith('/openmrs/ws/rest/v1/session', {
93
88
  headers: {
94
- Accept: "application/xml",
95
- "Disable-WWW-Authenticate": "true",
89
+ Accept: 'application/xml',
90
+ 'Disable-WWW-Authenticate': 'true',
96
91
  },
97
92
  });
98
93
  });
@@ -100,15 +95,15 @@ describe("openmrsFetch", () => {
100
95
  it(`allows you to specify no Accept request header to be sent`, () => {
101
96
  // @ts-ignore
102
97
  window.fetch.mockReturnValue(new Promise(() => {}));
103
- openmrsFetch("/ws/rest/v1/session", {
98
+ openmrsFetch('/ws/rest/v1/session', {
104
99
  headers: {
105
100
  // specifically null on purpose
106
101
  Accept: null,
107
102
  },
108
103
  });
109
- expect(window.fetch).toHaveBeenCalledWith("/openmrs/ws/rest/v1/session", {
104
+ expect(window.fetch).toHaveBeenCalledWith('/openmrs/ws/rest/v1/session', {
110
105
  headers: {
111
- "Disable-WWW-Authenticate": "true",
106
+ 'Disable-WWW-Authenticate': 'true',
112
107
  },
113
108
  });
114
109
  });
@@ -122,12 +117,12 @@ describe("openmrsFetch", () => {
122
117
  clone: () => ({
123
118
  text: () => Promise.resolve('{ "value": "hi" }'),
124
119
  }),
125
- })
120
+ }),
126
121
  );
127
122
 
128
- return openmrsFetch("/ws/rest/v1/session").then((response) => {
123
+ return openmrsFetch('/ws/rest/v1/session').then((response) => {
129
124
  expect(response.status).toBe(200);
130
- expect(response.data).toEqual({ value: "hi" });
125
+ expect(response.data).toEqual({ value: 'hi' });
131
126
  });
132
127
  });
133
128
 
@@ -138,10 +133,10 @@ describe("openmrsFetch", () => {
138
133
  ok: true,
139
134
  status: 204,
140
135
  json: () => Promise.reject(Error("No json for HTTP 204's!!")),
141
- })
136
+ }),
142
137
  );
143
138
 
144
- return openmrsFetch("/ws/rest/v1/session").then((response) => {
139
+ return openmrsFetch('/ws/rest/v1/session').then((response) => {
145
140
  expect(response.status).toBe(204);
146
141
  expect(response.data).toEqual(null);
147
142
  });
@@ -153,28 +148,26 @@ describe("openmrsFetch", () => {
153
148
  Promise.resolve({
154
149
  ok: false,
155
150
  status: 500,
156
- statusText: "Internal Server Error",
151
+ statusText: 'Internal Server Error',
157
152
  clone: () => ({
158
153
  text: () =>
159
154
  Promise.resolve(
160
155
  JSON.stringify({
161
- error: "The server is dead",
162
- })
156
+ error: 'The server is dead',
157
+ }),
163
158
  ),
164
159
  }),
165
- })
160
+ }),
166
161
  );
167
162
 
168
- return openmrsFetch("/ws/rest/v1/session")
163
+ return openmrsFetch('/ws/rest/v1/session')
169
164
  .then((data) => {
170
165
  fail("Promise shouldn't resolve when server responds with 500");
171
166
  })
172
167
  .catch((err) => {
173
- expect(err.message).toMatch(
174
- /Server responded with 500 \(Internal Server Error\)/
175
- );
168
+ expect(err.message).toMatch(/Server responded with 500 \(Internal Server Error\)/);
176
169
  expect(err.message).toMatch(/\/ws\/rest\/v1\/session/);
177
- expect(err.responseBody).toEqual({ error: "The server is dead" });
170
+ expect(err.responseBody).toEqual({ error: 'The server is dead' });
178
171
  expect(err.response.status).toBe(500);
179
172
  });
180
173
  });
@@ -185,23 +178,21 @@ describe("openmrsFetch", () => {
185
178
  Promise.resolve({
186
179
  ok: false,
187
180
  status: 400,
188
- statusText: "You goofed up",
181
+ statusText: 'You goofed up',
189
182
  clone: () => ({
190
- text: () => Promise.resolve("a string response body"),
183
+ text: () => Promise.resolve('a string response body'),
191
184
  }),
192
- })
185
+ }),
193
186
  );
194
187
 
195
- return openmrsFetch("/ws/rest/v1/session")
188
+ return openmrsFetch('/ws/rest/v1/session')
196
189
  .then((data) => {
197
190
  fail("Promise shouldn't resolve when server responds with 400");
198
191
  })
199
192
  .catch((err) => {
200
- expect(err.message).toMatch(
201
- /Server responded with 400 \(You goofed up\)/
202
- );
193
+ expect(err.message).toMatch(/Server responded with 400 \(You goofed up\)/);
203
194
  expect(err.message).toMatch(/\/ws\/rest\/v1\/session/);
204
- expect(err.responseBody).toEqual("a string response body");
195
+ expect(err.responseBody).toEqual('a string response body');
205
196
  expect(err.response.status).toBe(400);
206
197
  });
207
198
  });
@@ -210,7 +201,7 @@ describe("openmrsFetch", () => {
210
201
  (mockGetConfig as any).mockResolvedValueOnce({
211
202
  redirectAuthFailure: {
212
203
  enabled: true,
213
- url: "/openmrs/spa/login",
204
+ url: '/openmrs/spa/login',
214
205
  errors: [401],
215
206
  resolvePromise: true,
216
207
  },
@@ -221,24 +212,24 @@ describe("openmrsFetch", () => {
221
212
  Promise.resolve({
222
213
  ok: false,
223
214
  status: 401,
224
- statusText: "You are not authorized",
225
- text: () => Promise.resolve("a string response body"),
226
- })
215
+ statusText: 'You are not authorized',
216
+ text: () => Promise.resolve('a string response body'),
217
+ }),
227
218
  );
228
219
 
229
- return openmrsFetch("/ws/rest/v1/session").then((data) => {
220
+ return openmrsFetch('/ws/rest/v1/session').then((data) => {
230
221
  //@ts-ignore
231
222
  expect(mockNavigate.mock.calls[0][0]).toStrictEqual({
232
- to: "/openmrs/spa/login",
223
+ to: '/openmrs/spa/login',
233
224
  });
234
225
  });
235
226
  });
236
227
  });
237
228
 
238
- describe("openmrsObservableFetch", () => {
229
+ describe('openmrsObservableFetch', () => {
239
230
  beforeEach(() => {
240
231
  // @ts-ignore
241
- window.openmrsBase = "/openmrs";
232
+ window.openmrsBase = '/openmrs';
242
233
  window.fetch = jest.fn();
243
234
  });
244
235
 
@@ -251,40 +242,34 @@ describe("openmrsObservableFetch", () => {
251
242
  clone: () => ({
252
243
  text: () => Promise.resolve('{"value": "hi"}'),
253
244
  }),
254
- })
245
+ }),
255
246
  );
256
247
 
257
- const observable = openmrsObservableFetch("/ws/rest/v1/session");
248
+ const observable = openmrsObservableFetch('/ws/rest/v1/session');
258
249
  expect(isObservable(observable)).toBe(true);
259
250
 
260
251
  observable.subscribe(
261
252
  (response) => {
262
- expect(response.data).toEqual({ value: "hi" });
253
+ expect(response.data).toEqual({ value: 'hi' });
263
254
  done();
264
255
  },
265
256
  (err) => {
266
257
  done.fail(err);
267
- }
258
+ },
268
259
  );
269
260
 
270
261
  expect(window.fetch).toHaveBeenCalled();
271
262
  // @ts-ignore
272
- expect(window.fetch.mock.calls[0][0]).toEqual(
273
- "/openmrs/ws/rest/v1/session"
274
- );
263
+ expect(window.fetch.mock.calls[0][0]).toEqual('/openmrs/ws/rest/v1/session');
275
264
  // @ts-ignore
276
- expect(window.fetch.mock.calls[0][1].headers.Accept).toEqual(
277
- "application/json"
278
- );
265
+ expect(window.fetch.mock.calls[0][1].headers.Accept).toEqual('application/json');
279
266
  });
280
267
 
281
268
  it(`aborts the fetch request when subscription is unsubscribed`, () => {
282
269
  // @ts-ignore
283
270
  window.fetch.mockReturnValue(new Promise(() => {}));
284
271
 
285
- const subscription = openmrsObservableFetch(
286
- "/ws/rest/v1/session"
287
- ).subscribe();
272
+ const subscription = openmrsObservableFetch('/ws/rest/v1/session').subscribe();
288
273
  // @ts-ignore
289
274
  const abortSignal: AbortSignal = window.fetch.mock.calls[0][1].signal;
290
275
  expect(abortSignal.aborted).toBe(false);
@@ -1,12 +1,12 @@
1
1
  /** @module @category API */
2
- import { Observable } from "rxjs";
3
- import isPlainObject from "lodash-es/isPlainObject";
4
- import { getConfig, navigate } from "@openmrs/esm-config";
5
- import { FetchResponse } from "./types";
2
+ import { Observable } from 'rxjs';
3
+ import isPlainObject from 'lodash-es/isPlainObject';
4
+ import { getConfig, navigate } from '@openmrs/esm-config';
5
+ import { FetchResponse } from './types';
6
6
 
7
- export const restBaseUrl = "/ws/rest/v1/";
7
+ export const restBaseUrl = '/ws/rest/v1/';
8
8
 
9
- export const fhirBaseUrl = "/ws/fhir2/R4";
9
+ export const fhirBaseUrl = '/ws/fhir2/R4';
10
10
 
11
11
  export const sessionEndpoint = `${restBaseUrl}session`;
12
12
 
@@ -21,11 +21,11 @@ export const sessionEndpoint = `${restBaseUrl}session`;
21
21
  * ```
22
22
  */
23
23
  export function makeUrl(path: string) {
24
- if (path && path.startsWith("http")) {
24
+ if (path && path.startsWith('http')) {
25
25
  return path;
26
- } else if (path[0] !== "/") {
26
+ } else if (path[0] !== '/') {
27
27
  // ensure path starts with /
28
- path = "/" + path;
28
+ path = '/' + path;
29
29
  }
30
30
 
31
31
  return window.openmrsBase + path;
@@ -80,26 +80,19 @@ export function makeUrl(path: string) {
80
80
  *
81
81
  * @category API
82
82
  */
83
- export function openmrsFetch<T = any>(
84
- path: string,
85
- fetchInit: FetchConfig = {}
86
- ): Promise<FetchResponse<T>> {
87
- if (typeof path !== "string") {
88
- throw Error(
89
- "The first argument to @openmrs/api's openmrsFetch function must be a url string"
90
- );
83
+ export function openmrsFetch<T = any>(path: string, fetchInit: FetchConfig = {}): Promise<FetchResponse<T>> {
84
+ if (typeof path !== 'string') {
85
+ throw Error("The first argument to @openmrs/api's openmrsFetch function must be a url string");
91
86
  }
92
87
 
93
- if (typeof fetchInit !== "object") {
94
- throw Error(
95
- "The second argument to @openmrs/api's openmrsFetch function must be a plain object."
96
- );
88
+ if (typeof fetchInit !== 'object') {
89
+ throw Error("The second argument to @openmrs/api's openmrsFetch function must be a plain object.");
97
90
  }
98
91
 
99
92
  // @ts-ignore
100
93
  if (!window.openmrsBase) {
101
94
  throw Error(
102
- "@openmrs/api is running in a browser that doesn't have window.openmrsBase, which is provided by openmrs-module-spa's HTML file."
95
+ "@openmrs/api is running in a browser that doesn't have window.openmrsBase, which is provided by openmrs-module-spa's HTML file.",
103
96
  );
104
97
  }
105
98
 
@@ -124,8 +117,8 @@ export function openmrsFetch<T = any>(
124
117
  * If a different Accept header is preferred, pass it into the fetchInit.
125
118
  * If no Accept header is desired, pass it in explicitly as null.
126
119
  */
127
- if (typeof fetchInit.headers.Accept === "undefined") {
128
- fetchInit.headers.Accept = "application/json";
120
+ if (typeof fetchInit.headers.Accept === 'undefined') {
121
+ fetchInit.headers.Accept = 'application/json';
129
122
  }
130
123
 
131
124
  if (fetchInit.headers.Accept === null) {
@@ -136,17 +129,14 @@ export function openmrsFetch<T = any>(
136
129
  * header. Returning that header is useful when using the API, but
137
130
  * not from a UI.
138
131
  */
139
- if (
140
- path.startsWith(restBaseUrl) &&
141
- typeof fetchInit.headers["Disable-WWW-Authenticate"] === "undefined"
142
- ) {
143
- fetchInit.headers["Disable-WWW-Authenticate"] = "true";
132
+ if (path.startsWith(restBaseUrl) && typeof fetchInit.headers['Disable-WWW-Authenticate'] === 'undefined') {
133
+ fetchInit.headers['Disable-WWW-Authenticate'] = 'true';
144
134
  }
145
135
 
146
136
  if (path.startsWith(fhirBaseUrl)) {
147
137
  const urlUrl = new URL(url, window.location.toString());
148
- if (!urlUrl.searchParams.has("_summary")) {
149
- urlUrl.searchParams.set("_summary", "data");
138
+ if (!urlUrl.searchParams.has('_summary')) {
139
+ urlUrl.searchParams.set('_summary', 'data');
150
140
  url = urlUrl.toString();
151
141
  }
152
142
  }
@@ -194,12 +184,11 @@ export function openmrsFetch<T = any>(
194
184
  /*
195
185
  *Redirect to given url when redirect on auth failure is enabled
196
186
  */
197
- const { redirectAuthFailure } = await getConfig("@openmrs/esm-api");
187
+ const { redirectAuthFailure } = await getConfig('@openmrs/esm-api');
198
188
 
199
189
  if (
200
190
  (url === makeUrl(sessionEndpoint) && response.status === 403) ||
201
- (redirectAuthFailure.enabled &&
202
- redirectAuthFailure.errors.includes(response.status))
191
+ (redirectAuthFailure.enabled && redirectAuthFailure.errors.includes(response.status))
203
192
  ) {
204
193
  navigate({ to: redirectAuthFailure.url });
205
194
 
@@ -227,24 +216,14 @@ export function openmrsFetch<T = any>(
227
216
  /* Make the fetch promise go into "rejected" status, with the best
228
217
  * possible stacktrace and error message.
229
218
  */
230
- throw new OpenmrsFetchError(
231
- url,
232
- response,
233
- responseBody,
234
- requestStacktrace
235
- );
219
+ throw new OpenmrsFetchError(url, response, responseBody, requestStacktrace);
236
220
  },
237
221
  (err) => {
238
222
  /* We weren't able to download a response body for this error.
239
223
  * Time to just give the best possible stacktrace and error message.
240
224
  */
241
- throw new OpenmrsFetchError(
242
- url,
243
- response,
244
- null,
245
- requestStacktrace
246
- );
247
- }
225
+ throw new OpenmrsFetchError(url, response, null, requestStacktrace);
226
+ },
248
227
  );
249
228
  }
250
229
  }
@@ -280,14 +259,9 @@ export function openmrsFetch<T = any>(
280
259
  *
281
260
  * @category API
282
261
  */
283
- export function openmrsObservableFetch<T>(
284
- url: string,
285
- fetchInit: FetchConfig = {}
286
- ) {
287
- if (typeof fetchInit !== "object") {
288
- throw Error(
289
- "The second argument to openmrsObservableFetch must be either omitted or an object"
290
- );
262
+ export function openmrsObservableFetch<T>(url: string, fetchInit: FetchConfig = {}) {
263
+ if (typeof fetchInit !== 'object') {
264
+ throw Error('The second argument to openmrsObservableFetch must be either omitted or an object');
291
265
  }
292
266
 
293
267
  const abortController = new AbortController();
@@ -306,7 +280,7 @@ export function openmrsObservableFetch<T>(
306
280
  (err) => {
307
281
  hasResponse = true;
308
282
  observer.error(err);
309
- }
283
+ },
310
284
  );
311
285
 
312
286
  return () => {
@@ -318,12 +292,7 @@ export function openmrsObservableFetch<T>(
318
292
  }
319
293
 
320
294
  export class OpenmrsFetchError extends Error {
321
- constructor(
322
- url: string,
323
- response: Response,
324
- responseBody: ResponseBody | null,
325
- requestStacktrace: Error
326
- ) {
295
+ constructor(url: string, response: Response, responseBody: ResponseBody | null, requestStacktrace: Error) {
327
296
  super();
328
297
  this.message = `Server responded with ${response.status} (${response.statusText}) for url ${url}. Check err.responseBody or network tab in dev tools for more info`;
329
298
  requestStacktrace.message = this.message;
@@ -335,7 +304,7 @@ export class OpenmrsFetchError extends Error {
335
304
  responseBody: string | FetchResponseJson | null;
336
305
  }
337
306
 
338
- export interface FetchConfig extends Omit<RequestInit, "body" | "headers"> {
307
+ export interface FetchConfig extends Omit<RequestInit, 'body' | 'headers'> {
339
308
  headers?: FetchHeaders;
340
309
  body?: FetchBody | string;
341
310
  }
package/src/public.ts CHANGED
@@ -1,10 +1,10 @@
1
- export * from "./types";
2
- export * from "./openmrs-fetch";
1
+ export * from './types';
2
+ export * from './openmrs-fetch';
3
3
 
4
- export * from "./shared-api-objects/current-user";
5
- export * from "./shared-api-objects/current-patient";
6
- export * from "./shared-api-objects/visit-utils";
7
- export * from "./shared-api-objects/visit-type";
8
- export * from "./shared-api-objects/location";
4
+ export * from './shared-api-objects/current-user';
5
+ export * from './shared-api-objects/current-patient';
6
+ export * from './shared-api-objects/visit-utils';
7
+ export * from './shared-api-objects/visit-type';
8
+ export * from './shared-api-objects/location';
9
9
 
10
- export * from "./openmrs-backend-dependencies";
10
+ export * from './openmrs-backend-dependencies';
package/src/setup.ts CHANGED
@@ -1,21 +1,20 @@
1
- import { defineConfigSchema, Type, validators } from "@openmrs/esm-config";
2
- import { refetchCurrentUser } from "./shared-api-objects/current-user";
1
+ import { defineConfigSchema, Type, validators } from '@openmrs/esm-config';
2
+ import { refetchCurrentUser } from './shared-api-objects/current-user';
3
3
 
4
4
  /**
5
5
  * @internal
6
6
  */
7
7
  export function setupApiModule() {
8
- defineConfigSchema("@openmrs/esm-api", {
8
+ defineConfigSchema('@openmrs/esm-api', {
9
9
  redirectAuthFailure: {
10
10
  enabled: {
11
11
  _type: Type.Boolean,
12
12
  _default: true,
13
- _description:
14
- "Whether to redirect logged-out users to `redirectAuthFailure.url`",
13
+ _description: 'Whether to redirect logged-out users to `redirectAuthFailure.url`',
15
14
  },
16
15
  url: {
17
16
  _type: Type.String,
18
- _default: "${openmrsSpaBase}/login",
17
+ _default: '${openmrsSpaBase}/login',
19
18
  _validators: [validators.isUrl],
20
19
  },
21
20
  errors: {
@@ -25,7 +24,7 @@ export function setupApiModule() {
25
24
  _type: Type.Number,
26
25
  _validators: [validators.inRange(100, 600)],
27
26
  },
28
- _description: "The HTTP error codes for which users will be redirected",
27
+ _description: 'The HTTP error codes for which users will be redirected',
29
28
  },
30
29
  resolvePromise: {
31
30
  _type: Type.Boolean,