washday-sdk 1.6.82 → 1.6.83

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.
@@ -29,7 +29,7 @@ export const getAxiosInstance = (env = 'PROD', clientId = '', clientSecret = '')
29
29
  });
30
30
  // Add interceptor to set token and other options for every request
31
31
  axiosInstance.interceptors.request.use((config) => {
32
- const { token, responseType = 'json', contentDisposition } = config.params || {};
32
+ const { token, responseType, contentDisposition } = config.params || {};
33
33
  const { Authorization } = config.headers || {};
34
34
  let contentType = config.headers['Content-Type'];
35
35
  if (contentType === null || contentType === undefined) {
@@ -44,6 +44,9 @@ export const getAxiosInstance = (env = 'PROD', clientId = '', clientSecret = '')
44
44
  if (responseType) {
45
45
  config.responseType = responseType;
46
46
  }
47
+ else if (!config.responseType) {
48
+ config.responseType = 'json';
49
+ }
47
50
  if (contentDisposition) {
48
51
  config.headers['Content-Disposition'] = contentDisposition;
49
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "1.6.82",
3
+ "version": "1.6.83",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -34,7 +34,7 @@ export const getAxiosInstance = (env: string = 'PROD', clientId: string = '', cl
34
34
  // Add interceptor to set token and other options for every request
35
35
  axiosInstance.interceptors.request.use(
36
36
  (config) => {
37
- const { token, responseType = 'json', contentDisposition } = config.params || {};
37
+ const { token, responseType, contentDisposition } = config.params || {};
38
38
  const { Authorization } = config.headers || {};
39
39
  let contentType = config.headers['Content-Type'];
40
40
  if (contentType === null || contentType === undefined) {
@@ -48,6 +48,8 @@ export const getAxiosInstance = (env: string = 'PROD', clientId: string = '', cl
48
48
  }
49
49
  if (responseType) {
50
50
  config.responseType = responseType;
51
+ } else if (!config.responseType) {
52
+ config.responseType = 'json';
51
53
  }
52
54
  if (contentDisposition) {
53
55
  config.headers['Content-Disposition'] = contentDisposition;
@@ -0,0 +1,38 @@
1
+ const mockUse = jest.fn();
2
+ const mockCreate = jest.fn(() => ({
3
+ interceptors: {
4
+ request: {
5
+ use: mockUse,
6
+ },
7
+ },
8
+ }));
9
+
10
+ jest.mock("axios", () => ({
11
+ __esModule: true,
12
+ default: {
13
+ create: mockCreate,
14
+ },
15
+ }));
16
+
17
+ describe("SDK axios instance request interceptor", () => {
18
+ beforeEach(() => {
19
+ mockUse.mockClear();
20
+ mockCreate.mockClear();
21
+ });
22
+
23
+ it("preserves top-level responseType for binary downloads", async () => {
24
+ const { getAxiosInstance } = await import("../src/api/axiosInstance");
25
+
26
+ getAxiosInstance("DEV", "web-pos", "");
27
+
28
+ const requestInterceptor = mockUse.mock.calls[0][0];
29
+ const config = requestInterceptor({
30
+ headers: {
31
+ Authorization: "Bearer token-123",
32
+ },
33
+ responseType: "arraybuffer",
34
+ });
35
+
36
+ expect(config.responseType).toBe("arraybuffer");
37
+ });
38
+ });