@dvrd/dvr-controls 1.1.35 → 1.1.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.1.35",
3
+ "version": "1.1.36",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -39,7 +39,6 @@
39
39
  "react": "*",
40
40
  "react-color": "^2.19.3",
41
41
  "react-dom": "*",
42
- "typescript": "5.9.3",
43
42
  "uuid": "*"
44
43
  },
45
44
  "dependencies": {
@@ -60,14 +59,14 @@
60
59
  "@fortawesome/free-solid-svg-icons": "*",
61
60
  "@fortawesome/react-fontawesome": "*",
62
61
  "@types/react": "*",
63
- "@types/react-color": "^3.0.13",
64
62
  "@types/react-dom": "*",
65
63
  "@types/react-router": "*",
64
+ "@types/react-color": "^3.0.13",
66
65
  "react": "*",
67
66
  "react-color": "^2.19.3",
68
67
  "react-dom": "*",
69
68
  "react-router": "*",
70
- "typescript": "*",
71
- "uuid": "*"
69
+ "uuid": "*",
70
+ "typescript": "*"
72
71
  }
73
- }
72
+ }
@@ -2,12 +2,11 @@
2
2
  * Copyright (c) 2024. Dave van Rijn Development
3
3
  */
4
4
 
5
- import {OutgoingHttpHeaders} from "http";
6
5
  import {showDialog} from './eventUtil';
7
- import {warn} from "./miscUtil";
6
+ import {warn} from './miscUtil';
8
7
  import {FetchMethod, ResponseData} from './interfaces';
9
8
  import {getJwt} from './jwtUtil';
10
- import {voidFunction} from "./controlUtil";
9
+ import {voidFunction} from './controlUtil';
11
10
 
12
11
  type ResponseHandler = (response: Response, config: FetchOptions) => void;
13
12
 
@@ -18,7 +17,7 @@ export interface FetchOptions {
18
17
  method?: FetchMethod;
19
18
  data?: {};
20
19
  stringifyData?: boolean;
21
- headers?: OutgoingHttpHeaders;
20
+ headers?: Headers;
22
21
  callback?: (data: ResponseData, response: Response) => void;
23
22
  errorCallback?: (response: Response | string) => void;
24
23
  credentials?: string;
@@ -28,7 +27,7 @@ export interface FetchOptions {
28
27
  }
29
28
 
30
29
  let abortController: AbortController;
31
- let defaultHeaders: OutgoingHttpHeaders = {};
30
+ let defaultHeaders: Headers = new Headers();
32
31
  let defaultErrorHandler: ResponseHandler | null = null;
33
32
 
34
33
  function getAbortController(): AbortController | null {
@@ -42,9 +41,9 @@ function getAbortController(): AbortController | null {
42
41
 
43
42
  const responseDataIsSuccess = (data: ResponseData): boolean => data.status === 'success';
44
43
 
45
- export const setDefaultHeaders = (headers: OutgoingHttpHeaders) => {
44
+ export const setDefaultHeaders = (headers: Headers) => {
46
45
  defaultHeaders = headers;
47
- }
46
+ };
48
47
 
49
48
  export function setDefaultErrorHandler(errorHandler: ResponseHandler | null) {
50
49
  defaultErrorHandler = errorHandler;
@@ -78,7 +77,7 @@ export function sendFetch(config: FetchOptions): AbortController | null {
78
77
  body: config.stringifyData === false ? data : JSON.stringify(data, bigIntParser),
79
78
  cache: 'no-store',
80
79
  credentials: config.credentials,
81
- mode: 'cors',
80
+ mode: 'cors'
82
81
  };
83
82
  const abortController = config.abortController ?? getAbortController();
84
83
  if (abortController) options.signal = abortController.signal;
@@ -142,10 +141,13 @@ function _prepareConfig(options: FetchOptions): FetchOptions {
142
141
  }
143
142
 
144
143
  function setAuthHeader(options: FetchOptions): FetchOptions {
145
- const headers: OutgoingHttpHeaders = Object.assign({}, defaultHeaders, options.headers || {});
144
+ const headers = new Headers(defaultHeaders);
145
+ const customHeaders = options.headers ?? new Headers();
146
+ for (const [key, value] of customHeaders.entries())
147
+ headers.set(key, value);
146
148
  const jwt = getJwt();
147
149
  if (jwt)
148
- headers.Authorization = `JWT ${jwt}`;
150
+ headers.set('Authorization', `JWT ${jwt}`);
149
151
  options.headers = headers;
150
152
  return options;
151
153
  }