@react-pakistan/util-functions 1.25.4 → 1.25.6
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/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/use-fetch.d.ts +7 -1
- package/hooks/use-fetch.js +15 -1
- package/hooks/use-module-entity-v2.d.ts +5 -5
- package/hooks/use-module-entity-v2.js +1 -0
- package/package.json +1 -1
package/hooks/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './use-force-render';
|
|
|
5
5
|
export * from './use-ip-geo-location';
|
|
6
6
|
export * from './use-is-mobile';
|
|
7
7
|
export * from './use-module-entity';
|
|
8
|
+
export * from './use-module-entity-v2';
|
|
8
9
|
export * from './use-phone-formatter';
|
|
9
10
|
export * from './use-position';
|
|
10
11
|
export * from './use-sticky';
|
package/hooks/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./use-force-render"), exports);
|
|
|
21
21
|
__exportStar(require("./use-ip-geo-location"), exports);
|
|
22
22
|
__exportStar(require("./use-is-mobile"), exports);
|
|
23
23
|
__exportStar(require("./use-module-entity"), exports);
|
|
24
|
+
__exportStar(require("./use-module-entity-v2"), exports);
|
|
24
25
|
__exportStar(require("./use-phone-formatter"), exports);
|
|
25
26
|
__exportStar(require("./use-position"), exports);
|
|
26
27
|
__exportStar(require("./use-sticky"), exports);
|
package/hooks/use-fetch.d.ts
CHANGED
|
@@ -4,9 +4,15 @@ export interface FetchResult {
|
|
|
4
4
|
status?: number;
|
|
5
5
|
ok?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export interface FetchConfig extends RequestInit {
|
|
7
|
+
export interface FetchConfig extends Omit<RequestInit, 'credentials'> {
|
|
8
8
|
autoFetch?: boolean;
|
|
9
9
|
callback?: (result: FetchResult) => void;
|
|
10
|
+
/**
|
|
11
|
+
* If `true`, the fetch will be invoked with `credentials: 'include'`.
|
|
12
|
+
* String values from the standard `RequestCredentials` are also supported
|
|
13
|
+
* (e.g. 'omit' | 'same-origin' | 'include').
|
|
14
|
+
*/
|
|
15
|
+
credentials?: boolean | RequestCredentials;
|
|
10
16
|
params?: Record<string, any>;
|
|
11
17
|
}
|
|
12
18
|
export interface Return {
|
package/hooks/use-fetch.js
CHANGED
|
@@ -93,7 +93,7 @@ var useFetch = function (url, config, deps) {
|
|
|
93
93
|
};
|
|
94
94
|
}, []);
|
|
95
95
|
var fetchNow = (0, react_1.useCallback)(function (overrideUrl, overrideOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
-
var finalUrl, _a, defaultParams, restDefaultOptions, _b, overrideParams, restOverrideOptions, mergedParams, finalOptions, method, hashIndex, hash, basePart, searchIndex, pathname, existingSearch, searchParams_1, newSearch, controller, response, parsed, _c, err, err_1;
|
|
96
|
+
var finalUrl, _a, defaultParams, restDefaultOptions, _b, overrideParams, restOverrideOptions, mergedParams, finalOptions, method, credOverride, credDefault, hashIndex, hash, basePart, searchIndex, pathname, existingSearch, searchParams_1, newSearch, controller, response, parsed, _c, err, err_1;
|
|
97
97
|
return __generator(this, function (_d) {
|
|
98
98
|
switch (_d.label) {
|
|
99
99
|
case 0:
|
|
@@ -105,6 +105,20 @@ var useFetch = function (url, config, deps) {
|
|
|
105
105
|
method = (finalOptions.method || 'GET')
|
|
106
106
|
.toString()
|
|
107
107
|
.toUpperCase();
|
|
108
|
+
credOverride = restOverrideOptions.credentials;
|
|
109
|
+
credDefault = restDefaultOptions.credentials;
|
|
110
|
+
if (typeof credOverride === 'string') {
|
|
111
|
+
finalOptions.credentials = credOverride;
|
|
112
|
+
}
|
|
113
|
+
else if (credOverride === true) {
|
|
114
|
+
finalOptions.credentials = 'include';
|
|
115
|
+
}
|
|
116
|
+
else if (typeof credDefault === 'string') {
|
|
117
|
+
finalOptions.credentials = credDefault;
|
|
118
|
+
}
|
|
119
|
+
else if (credDefault === true) {
|
|
120
|
+
finalOptions.credentials = 'include';
|
|
121
|
+
}
|
|
108
122
|
if (method === 'GET' &&
|
|
109
123
|
mergedParams &&
|
|
110
124
|
Object.keys(mergedParams).length) {
|
|
@@ -52,27 +52,27 @@
|
|
|
52
52
|
* });
|
|
53
53
|
*/
|
|
54
54
|
import { FetchConfig } from './use-fetch';
|
|
55
|
-
export interface
|
|
55
|
+
export interface CallbackParamsV2 {
|
|
56
56
|
data: any;
|
|
57
57
|
error: any;
|
|
58
58
|
status?: number;
|
|
59
59
|
ok?: boolean;
|
|
60
60
|
}
|
|
61
61
|
interface Params {
|
|
62
|
-
byIdCallback: (d:
|
|
62
|
+
byIdCallback: (d: CallbackParamsV2) => void;
|
|
63
63
|
byIdDeps?: Array<any> | Array<string>;
|
|
64
64
|
byIdParams: object;
|
|
65
|
-
deleteCallback?: (d:
|
|
65
|
+
deleteCallback?: (d: CallbackParamsV2) => void;
|
|
66
66
|
deleteDeps?: Array<any> | Array<string>;
|
|
67
67
|
deleteParams?: object;
|
|
68
|
-
listCallback: (d:
|
|
68
|
+
listCallback: (d: CallbackParamsV2) => void;
|
|
69
69
|
listDeps?: Array<any> | Array<string>;
|
|
70
70
|
listParams: object;
|
|
71
71
|
listUrl: string;
|
|
72
72
|
searchQuery: string;
|
|
73
73
|
unitByIdUrl: string;
|
|
74
74
|
unitUrl: string;
|
|
75
|
-
updateCallback: (d:
|
|
75
|
+
updateCallback: (d: CallbackParamsV2) => void;
|
|
76
76
|
updateDeps?: Array<any> | Array<string>;
|
|
77
77
|
updateParams: object;
|
|
78
78
|
}
|
|
@@ -83,6 +83,7 @@ var useModuleEntityV2 = function (_a) {
|
|
|
83
83
|
method: constants_1.API_METHODS.GET,
|
|
84
84
|
params: listParams,
|
|
85
85
|
callback: listCallback,
|
|
86
|
+
credentials: true,
|
|
86
87
|
}, __spreadArray([debouncedQuery, listParams], listDeps, true)), listError = _f.error, listFetchNow = _f.fetchNow, listLoading = _f.loading;
|
|
87
88
|
var refreshList = function (delay) {
|
|
88
89
|
if (delay === void 0) { delay = 300; }
|