@vef-framework/core 1.0.62 → 1.0.64
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/es/api/api-client.js +543 -2
- package/es/api/api-context.js +94 -2
- package/es/api/index.js +4 -2
- package/es/api/query-client.js +30 -2
- package/es/api/request-client.js +243 -2
- package/es/auth/auth-context.js +35 -2
- package/es/auth/index.js +2 -2
- package/es/expr/compiler.js +299 -2
- package/es/expr/helpers.js +86 -2
- package/es/index.js +8 -2
- package/es/middleware/dispatcher.js +28 -2
- package/lib/api/api-client.cjs +548 -2
- package/lib/api/api-context.cjs +99 -2
- package/lib/api/index.cjs +19 -2
- package/lib/api/query-client.cjs +34 -2
- package/lib/api/request-client.cjs +248 -2
- package/lib/auth/auth-context.cjs +40 -2
- package/lib/auth/index.cjs +11 -2
- package/lib/expr/compiler.cjs +303 -2
- package/lib/expr/helpers.cjs +94 -2
- package/lib/index.cjs +26 -2
- package/lib/middleware/dispatcher.cjs +32 -2
- package/package.json +2 -2
package/lib/api/api-context.cjs
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
const Context = react.createContext(null);
|
|
10
|
+
const ApiContextProvider = ({
|
|
11
|
+
client,
|
|
12
|
+
dataDictionaryApi,
|
|
13
|
+
loginApi,
|
|
14
|
+
logoutApi,
|
|
15
|
+
fetchAuthenticatedUserApi,
|
|
16
|
+
children
|
|
17
|
+
}) => {
|
|
18
|
+
const apiContext = react.useMemo(() => {
|
|
19
|
+
const stubQueryApi = client.createQueryApi(
|
|
20
|
+
"_vefStubQueryApi",
|
|
21
|
+
() => (stubData) => Promise.resolve({
|
|
22
|
+
code: 0,
|
|
23
|
+
message: "ok",
|
|
24
|
+
data: stubData
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
const asyncFnQueryApi = client.createQueryApi(
|
|
28
|
+
"_vefAsyncFnQueryApi",
|
|
29
|
+
() => async ({ args, fn }) => ({
|
|
30
|
+
code: 0,
|
|
31
|
+
message: "ok",
|
|
32
|
+
data: await fn(...args)
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
const stubMutationApi = client.createMutationApi(
|
|
36
|
+
"_vefStubMutationApi",
|
|
37
|
+
() => (stubData) => Promise.resolve({
|
|
38
|
+
code: 0,
|
|
39
|
+
message: "ok",
|
|
40
|
+
data: stubData
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
const asyncFnMutationApi = client.createMutationApi(
|
|
44
|
+
"_vefAsyncFnMutationApi",
|
|
45
|
+
() => async ({ args, fn }) => ({
|
|
46
|
+
code: 0,
|
|
47
|
+
message: "ok",
|
|
48
|
+
data: await fn(...args)
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
useApiQuery: client.useApiQuery,
|
|
53
|
+
useSuspenseApiQuery: client.useSuspenseApiQuery,
|
|
54
|
+
useApiMutation: client.useApiMutation,
|
|
55
|
+
useIsFetching: client.useIsFetching,
|
|
56
|
+
useIsMutating: client.useIsMutating,
|
|
57
|
+
fetchApiQuery: client.fetchApiQuery.bind(client),
|
|
58
|
+
createQueryApi: client.createQueryApi.bind(client),
|
|
59
|
+
createMutationApi: client.createMutationApi.bind(client),
|
|
60
|
+
getApiQueryData: client.getApiQueryData.bind(client),
|
|
61
|
+
getApiQueriesData: client.getApiQueriesData.bind(client),
|
|
62
|
+
setApiQueryData: client.setApiQueryData.bind(client),
|
|
63
|
+
ensureApiQueryData: client.ensureApiQueryData.bind(client),
|
|
64
|
+
removeApiQueries: client.removeApiQueries.bind(client),
|
|
65
|
+
invalidateApiQueries: client.invalidateApiQueries.bind(client),
|
|
66
|
+
resetApiQueries: client.resetApiQueries.bind(client),
|
|
67
|
+
refetchApiQueries: client.refetchApiQueries.bind(client),
|
|
68
|
+
cancelApiQueries: client.cancelApiQueries.bind(client),
|
|
69
|
+
isFetching: client.isFetching.bind(client),
|
|
70
|
+
isMutating: client.isMutating.bind(client),
|
|
71
|
+
stubQueryApi,
|
|
72
|
+
asyncFnQueryApi,
|
|
73
|
+
stubMutationApi,
|
|
74
|
+
asyncFnMutationApi,
|
|
75
|
+
dataDictionaryApi,
|
|
76
|
+
loginApi,
|
|
77
|
+
logoutApi,
|
|
78
|
+
fetchAuthenticatedUserApi
|
|
79
|
+
});
|
|
80
|
+
}, [client, dataDictionaryApi, loginApi, logoutApi, fetchAuthenticatedUserApi]);
|
|
81
|
+
return react.createElement(
|
|
82
|
+
Context.Provider,
|
|
83
|
+
{ value: apiContext },
|
|
84
|
+
react.createElement(client.QueryClientProvider, {}, children)
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
function useApiContext() {
|
|
88
|
+
const context = react.useContext(Context);
|
|
89
|
+
if (context === null) {
|
|
90
|
+
throw new shared.VefError(
|
|
91
|
+
-1,
|
|
92
|
+
"Api context not found: Please ensure useApiContext is called within an ApiContextProvider"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.ApiContextProvider = ApiContextProvider;
|
|
99
|
+
exports.useApiContext = useApiContext;
|
|
3
100
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
package/lib/api/index.cjs
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const apiClient = require('./api-client.cjs');
|
|
7
|
+
const apiContext = require('./api-context.cjs');
|
|
8
|
+
const reactQuery = require('@tanstack/react-query');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.ApiClient = apiClient.ApiClient;
|
|
13
|
+
exports.createApiClient = apiClient.createApiClient;
|
|
14
|
+
exports.ApiContextProvider = apiContext.ApiContextProvider;
|
|
15
|
+
exports.useApiContext = apiContext.useApiContext;
|
|
16
|
+
Object.defineProperty(exports, "useQueryErrorResetBoundary", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => reactQuery.useQueryErrorResetBoundary
|
|
19
|
+
});
|
|
3
20
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
package/lib/api/query-client.cjs
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const reactQuery = require('@tanstack/react-query');
|
|
7
|
+
|
|
8
|
+
function createQueryClient(options) {
|
|
9
|
+
const staleTime = options?.staleTime ?? Infinity;
|
|
10
|
+
const gcTime = options?.gcTime ?? 10 * 60 * 1e3;
|
|
11
|
+
return new reactQuery.QueryClient({
|
|
12
|
+
defaultOptions: {
|
|
13
|
+
queries: {
|
|
14
|
+
networkMode: "always",
|
|
15
|
+
staleTime,
|
|
16
|
+
gcTime,
|
|
17
|
+
retry: false,
|
|
18
|
+
structuralSharing: true,
|
|
19
|
+
throwOnError: false,
|
|
20
|
+
refetchOnMount: false,
|
|
21
|
+
refetchOnReconnect: true,
|
|
22
|
+
refetchOnWindowFocus: true
|
|
23
|
+
},
|
|
24
|
+
mutations: {
|
|
25
|
+
networkMode: "always",
|
|
26
|
+
gcTime: staleTime,
|
|
27
|
+
retry: false,
|
|
28
|
+
throwOnError: false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.createQueryClient = createQueryClient;
|
|
3
35
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,249 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const axios = require('axios');
|
|
8
|
+
const qs = require('qs');
|
|
9
|
+
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
13
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
14
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
15
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
16
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
17
|
+
var _axiosInstance;
|
|
18
|
+
const pathParamRegex = /\{\w+\}/;
|
|
19
|
+
class RequestClient {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
/**
|
|
23
|
+
* The axios instance.
|
|
24
|
+
*/
|
|
25
|
+
__privateAdd(this, _axiosInstance);
|
|
26
|
+
const {
|
|
27
|
+
baseUrl,
|
|
28
|
+
timeout,
|
|
29
|
+
getAccessToken,
|
|
30
|
+
successCode = 0,
|
|
31
|
+
unauthorizedCode = 1e3,
|
|
32
|
+
accessDeniedCode = 1002,
|
|
33
|
+
tokenExpiredCode = 1001,
|
|
34
|
+
onUnauthorized,
|
|
35
|
+
onAccessDenied
|
|
36
|
+
} = options;
|
|
37
|
+
__privateSet(this, _axiosInstance, axios.create({
|
|
38
|
+
baseURL: baseUrl,
|
|
39
|
+
timeout: timeout ?? 1e3 * 30,
|
|
40
|
+
headers: {
|
|
41
|
+
"Content-Type": "application/json"
|
|
42
|
+
},
|
|
43
|
+
paramsSerializer: (params) => qs.stringify(
|
|
44
|
+
params,
|
|
45
|
+
{
|
|
46
|
+
arrayFormat: "repeat",
|
|
47
|
+
skipNulls: true,
|
|
48
|
+
charset: "utf-8"
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
responseType: "json",
|
|
52
|
+
validateStatus: () => true
|
|
53
|
+
}));
|
|
54
|
+
__privateGet(this, _axiosInstance).interceptors.request.use((config) => {
|
|
55
|
+
const token = getAccessToken?.();
|
|
56
|
+
if (token) {
|
|
57
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
58
|
+
}
|
|
59
|
+
const { url } = config;
|
|
60
|
+
if (url && pathParamRegex.test(url)) {
|
|
61
|
+
config.url = url.replace(pathParamRegex, (_, key) => {
|
|
62
|
+
const value = config.params?.[key];
|
|
63
|
+
if (shared.isNullish(value)) {
|
|
64
|
+
throw new Error(`Path parameter ${key} is nil`);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return config;
|
|
70
|
+
});
|
|
71
|
+
__privateGet(this, _axiosInstance).interceptors.response.use(
|
|
72
|
+
async (response) => {
|
|
73
|
+
const { code, message } = response.data;
|
|
74
|
+
if (code === successCode) {
|
|
75
|
+
return response;
|
|
76
|
+
} else if (code === unauthorizedCode) {
|
|
77
|
+
await onUnauthorized?.();
|
|
78
|
+
} else if (code === tokenExpiredCode) {
|
|
79
|
+
shared.showInfoMessage("\u767B\u5F55\u5DF2\u5931\u6548");
|
|
80
|
+
await onUnauthorized?.();
|
|
81
|
+
} else if (code === accessDeniedCode) {
|
|
82
|
+
shared.showWarningMessage(`${message}\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u4E3A\u60A8\u5F00\u901A`);
|
|
83
|
+
await onAccessDenied?.();
|
|
84
|
+
} else {
|
|
85
|
+
shared.showWarningMessage(message);
|
|
86
|
+
}
|
|
87
|
+
throw new shared.VefError(code, message);
|
|
88
|
+
},
|
|
89
|
+
(error) => {
|
|
90
|
+
if (error instanceof axios.CanceledError) {
|
|
91
|
+
return Promise.reject(error);
|
|
92
|
+
}
|
|
93
|
+
const { response, message } = error;
|
|
94
|
+
if (response?.data) {
|
|
95
|
+
const errorMessage = `\u5904\u7406\u8BF7\u6C42\u54CD\u5E94\u4FE1\u606F\u5F02\u5E38\uFF1A${message ?? "\u65E0"}`;
|
|
96
|
+
return Promise.reject(new shared.VefError(response.status, errorMessage));
|
|
97
|
+
} else {
|
|
98
|
+
let errorMessage = message ?? (shared.isString(error) ? error : "");
|
|
99
|
+
if (errorMessage === "Network Error") {
|
|
100
|
+
errorMessage = "\u63A5\u53E3\u8FDE\u63A5\u5F02\u5E38\u53EF\u80FD\u539F\u56E0\uFF1A\u7F51\u7EDC\u4E0D\u901A\u6216\u5B58\u5728\u8DE8\u57DF\u95EE\u9898\u3002";
|
|
101
|
+
} else if (errorMessage.includes("timeout")) {
|
|
102
|
+
errorMessage = "\u63A5\u53E3\u8BF7\u6C42\u8D85\u65F6";
|
|
103
|
+
} else if (errorMessage.includes("Request failed with status code")) {
|
|
104
|
+
const code = message.substring(message.length - 3);
|
|
105
|
+
errorMessage = `\u63A5\u53E3\u72B6\u6001\u7801\u5F02\u5E38\uFF1A${code}`;
|
|
106
|
+
} else {
|
|
107
|
+
errorMessage = "\u63A5\u53E3\u672A\u77E5\u5F02\u5E38";
|
|
108
|
+
}
|
|
109
|
+
shared.showErrorMessage(errorMessage);
|
|
110
|
+
return Promise.reject(new shared.VefError(-1, errorMessage));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Perform a GET request.
|
|
117
|
+
*
|
|
118
|
+
* @param url - The url.
|
|
119
|
+
* @param options - The request options.
|
|
120
|
+
* @returns The response data promise.
|
|
121
|
+
*/
|
|
122
|
+
async get(url, options) {
|
|
123
|
+
const response = await __privateGet(this, _axiosInstance).get(url, {
|
|
124
|
+
params: options?.params,
|
|
125
|
+
signal: options?.signal
|
|
126
|
+
});
|
|
127
|
+
return response.data;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Perform a POST request.
|
|
131
|
+
*
|
|
132
|
+
* @param url - The url.
|
|
133
|
+
* @param data - The request data.
|
|
134
|
+
* @param options - The request options.
|
|
135
|
+
* @returns The response data promise.
|
|
136
|
+
*/
|
|
137
|
+
async post(url, data, options) {
|
|
138
|
+
const response = await __privateGet(this, _axiosInstance).post(url, data, {
|
|
139
|
+
params: options?.params,
|
|
140
|
+
signal: options?.signal
|
|
141
|
+
});
|
|
142
|
+
return response.data;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Perform a PUT request.
|
|
146
|
+
*
|
|
147
|
+
* @param url - The url.
|
|
148
|
+
* @param data - The request data.
|
|
149
|
+
* @param options - The request options.
|
|
150
|
+
* @returns The response data promise.
|
|
151
|
+
*/
|
|
152
|
+
async put(url, data, options) {
|
|
153
|
+
const response = await __privateGet(this, _axiosInstance).put(url, data, {
|
|
154
|
+
params: options?.params,
|
|
155
|
+
signal: options?.signal
|
|
156
|
+
});
|
|
157
|
+
return response.data;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Perform a DELETE request.
|
|
161
|
+
*
|
|
162
|
+
* @param url - The url.
|
|
163
|
+
* @param options - The request options.
|
|
164
|
+
* @returns The response data promise.
|
|
165
|
+
*/
|
|
166
|
+
async delete(url, options) {
|
|
167
|
+
const response = await __privateGet(this, _axiosInstance).delete(url, {
|
|
168
|
+
params: options?.params,
|
|
169
|
+
signal: options?.signal
|
|
170
|
+
});
|
|
171
|
+
return response.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Perform a file upload request.
|
|
175
|
+
*
|
|
176
|
+
* @param url - The url.
|
|
177
|
+
* @param data - The file data.
|
|
178
|
+
* @param options - The request options.
|
|
179
|
+
* @returns The response data promise.
|
|
180
|
+
*/
|
|
181
|
+
async upload(url, data, options) {
|
|
182
|
+
const response = await __privateGet(this, _axiosInstance).postForm(
|
|
183
|
+
url,
|
|
184
|
+
data,
|
|
185
|
+
{
|
|
186
|
+
params: options?.params,
|
|
187
|
+
signal: options?.signal,
|
|
188
|
+
onUploadProgress: shared.isFunction(options?.onProgress) ? (progressEvent) => {
|
|
189
|
+
const total = progressEvent.lengthComputable ? progressEvent.total ?? 0 : 0;
|
|
190
|
+
const { loaded } = progressEvent;
|
|
191
|
+
const percent = Math.round(loaded / total * 100);
|
|
192
|
+
options.onProgress?.(percent);
|
|
193
|
+
} : void 0
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
return response.data;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Perform a file download request.
|
|
200
|
+
*
|
|
201
|
+
* @param url - The url.
|
|
202
|
+
* @param options - The request options.
|
|
203
|
+
*/
|
|
204
|
+
async download(url, options) {
|
|
205
|
+
const { data, headers } = await __privateGet(this, _axiosInstance).get(
|
|
206
|
+
url,
|
|
207
|
+
{
|
|
208
|
+
params: options?.params,
|
|
209
|
+
responseType: "blob",
|
|
210
|
+
onDownloadProgress: shared.isFunction(options?.onProgress) ? (progressEvent) => {
|
|
211
|
+
const total = progressEvent.lengthComputable ? progressEvent.total ?? 0 : 0;
|
|
212
|
+
const { loaded } = progressEvent;
|
|
213
|
+
const percent = Math.round(loaded / total * 100);
|
|
214
|
+
options.onProgress?.(percent);
|
|
215
|
+
} : void 0
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
let response = null;
|
|
219
|
+
try {
|
|
220
|
+
response = JSON.parse(await data.text());
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
if (response && response.code !== 0) {
|
|
224
|
+
throw new shared.VefError(response.code, response.message);
|
|
225
|
+
}
|
|
226
|
+
const contentDisposition = headers.get("content-disposition");
|
|
227
|
+
if (shared.isString(contentDisposition)) {
|
|
228
|
+
const fileNameRegex = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/;
|
|
229
|
+
const matches = fileNameRegex.exec(contentDisposition);
|
|
230
|
+
if (matches && matches.groups) {
|
|
231
|
+
const { name } = matches.groups;
|
|
232
|
+
const fileName = decodeURIComponent(name);
|
|
233
|
+
const a = document.createElement("a");
|
|
234
|
+
a.href = URL.createObjectURL(data);
|
|
235
|
+
a.download = shared.isFunction(options?.fileName) ? options.fileName(fileName) : options?.fileName ?? fileName;
|
|
236
|
+
a.click();
|
|
237
|
+
URL.revokeObjectURL(a.href);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
_axiosInstance = new WeakMap();
|
|
243
|
+
function createRequestClient(options) {
|
|
244
|
+
return Object.freeze(new RequestClient(options));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
exports.RequestClient = RequestClient;
|
|
248
|
+
exports.createRequestClient = createRequestClient;
|
|
3
249
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
const Context = react.createContext(null);
|
|
10
|
+
const AuthContextProvider = ({
|
|
11
|
+
permissionChecker,
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
const authContext = react.useMemo(() => ({
|
|
15
|
+
checkPermission: (token) => {
|
|
16
|
+
if (!permissionChecker) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (shared.isString(token)) {
|
|
20
|
+
return permissionChecker(token);
|
|
21
|
+
}
|
|
22
|
+
return permissionChecker(token.key);
|
|
23
|
+
}
|
|
24
|
+
}), [permissionChecker]);
|
|
25
|
+
return react.createElement(
|
|
26
|
+
Context.Provider,
|
|
27
|
+
{ value: authContext },
|
|
28
|
+
children
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
function useAuthContext() {
|
|
32
|
+
const context = react.useContext(Context);
|
|
33
|
+
if (context === null) {
|
|
34
|
+
throw new shared.VefError(-1, "useAuthContext must be used within a AuthContextProvider");
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.AuthContextProvider = AuthContextProvider;
|
|
40
|
+
exports.useAuthContext = useAuthContext;
|
|
3
41
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
package/lib/auth/index.cjs
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.64, build time: 2025-01-10T01:26:01.352Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const authContext = require('./auth-context.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.AuthContextProvider = authContext.AuthContextProvider;
|
|
11
|
+
exports.useAuthContext = authContext.useAuthContext;
|
|
3
12
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|