@dvrd/dvr-controls 1.0.51 → 1.0.53

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.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -30,7 +30,7 @@
30
30
  "react-router-dom": "6.15.0"
31
31
  },
32
32
  "dependencies": {
33
- "@dvrd/idate": "^1.6.1",
33
+ "@dvrd/idate": "^1.8.1",
34
34
  "@fortawesome/fontawesome-svg-core": "6.3.0",
35
35
  "@fortawesome/free-brands-svg-icons": "6.3.0",
36
36
  "@fortawesome/free-regular-svg-icons": "6.3.0",
@@ -19,7 +19,7 @@ export interface FetchOptions {
19
19
  data?: {};
20
20
  stringifyData?: boolean;
21
21
  headers?: OutgoingHttpHeaders;
22
- callback?: Function;
22
+ callback?: (data: ResponseData, response: Response) => void;
23
23
  errorCallback?: (response: Response | string) => void;
24
24
  credentials?: string;
25
25
  responseParser?: ResponseHandler;
@@ -67,22 +67,23 @@ function bigIntParser(_: string, value: any) {
67
67
  return value;
68
68
  }
69
69
 
70
- export function sendFetch(config: FetchOptions, legacySupport: boolean = false): AbortController | null {
70
+ export function sendFetch(config: FetchOptions): AbortController | null {
71
71
  const baseUrl = config.baseUrl || window.settings.platformUrl;
72
72
  if (!baseUrl) throw new Error('Base url is not set!');
73
73
 
74
- config = _prepareConfig(config, legacySupport);
74
+ config = _prepareConfig(config);
75
75
  const {url, method, headers, data} = config;
76
76
  const options: { [index: string]: any } = {
77
77
  headers,
78
78
  method,
79
79
  body: config.stringifyData === false ? data : JSON.stringify(data, bigIntParser),
80
80
  cache: 'no-store',
81
+ credentials: config.credentials,
82
+ mode: 'cors',
81
83
  };
82
84
  const abortController = getAbortController();
83
85
  if (abortController) options.signal = abortController.signal;
84
86
 
85
- options['mode'] = 'cors';
86
87
  fetch(baseUrl + url, options).then((response: Response) => {
87
88
  _handleResponse(response, config);
88
89
  }).catch((reason: any) => {
@@ -106,13 +107,13 @@ function _handleResponse(response: Response, config: FetchOptions) {
106
107
  if (data.message === 'Invalid rights') {
107
108
  showDialog('Je hebt niet genoeg rechten voor deze actie.');
108
109
  data.handled = true;
109
- if (config.callback) config.callback(data);
110
+ if (config.callback) config.callback(data, response);
110
111
  } else if (config.callback) {
111
112
  data.success = responseDataIsSuccess(data);
112
- config.callback(data);
113
+ config.callback(data, response);
113
114
  }
114
115
  });
115
- } else config.callback(response);
116
+ } else config.callback({status: 'success'}, response);
116
117
  } else
117
118
  _onErrorResponse(response, config);
118
119
  }
@@ -121,10 +122,13 @@ function _onErrorResponse(response: Response, config: FetchOptions) {
121
122
  if (config.errorHandler) config.errorHandler(response, config);
122
123
  else if (config.errorCallback) config.errorCallback(response);
123
124
  else if (defaultErrorHandler) defaultErrorHandler(response, config);
124
- else if (config.callback) config.callback({status: 'error', message: 'Er is iets misgegaan in het systeem.'});
125
+ else if (config.callback) config.callback({
126
+ status: 'error',
127
+ message: 'Er is iets misgegaan in het systeem.'
128
+ }, response);
125
129
  }
126
130
 
127
- function _prepareConfig(options: FetchOptions, legacySupport: boolean = true): FetchOptions {
131
+ function _prepareConfig(options: FetchOptions): FetchOptions {
128
132
  const fetchOptions: FetchOptions = Object.assign({}, options);
129
133
  if (!fetchOptions.method) fetchOptions.method = FetchMethod.GET;
130
134
  if (!fetchOptions.callback) fetchOptions.callback = voidFunction;
@@ -135,13 +139,6 @@ function _prepareConfig(options: FetchOptions, legacySupport: boolean = true): F
135
139
  warn('Cannot send data with GET requests, data will be ignored.');
136
140
 
137
141
  if (fetchOptions.credentials === undefined) fetchOptions.credentials = 'same-origin';
138
-
139
- if (legacySupport && fetchOptions.callback) {
140
- const legacyCallback = fetchOptions.callback;
141
- fetchOptions.callback = (data: ResponseData) => {
142
- legacyCallback({data});
143
- }
144
- }
145
142
  return setAuthHeader(fetchOptions);
146
143
  }
147
144