@taruvi/refine-providers 1.2.7 → 1.2.9
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/dist/index.cjs +27 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +28 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import DataLoader from 'dataloader';
|
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
|
-
version: "1.2.
|
|
8
|
+
version: "1.2.8"};
|
|
9
9
|
|
|
10
10
|
// src/utils.ts
|
|
11
11
|
var REFINE_OPERATOR_MAP = {
|
|
@@ -911,6 +911,7 @@ function analyticsDataProvider(client) {
|
|
|
911
911
|
}
|
|
912
912
|
};
|
|
913
913
|
}
|
|
914
|
+
var _cachedUser = null;
|
|
914
915
|
function authProvider(client) {
|
|
915
916
|
const auth = new Auth(client);
|
|
916
917
|
return {
|
|
@@ -938,6 +939,7 @@ function authProvider(client) {
|
|
|
938
939
|
},
|
|
939
940
|
logout: async (params = {}) => {
|
|
940
941
|
const { callbackUrl } = params;
|
|
942
|
+
_cachedUser = null;
|
|
941
943
|
await auth.logout(callbackUrl);
|
|
942
944
|
return {
|
|
943
945
|
success: true,
|
|
@@ -945,13 +947,10 @@ function authProvider(client) {
|
|
|
945
947
|
};
|
|
946
948
|
},
|
|
947
949
|
check: async () => {
|
|
948
|
-
if (auth.isUserAuthenticated()) {
|
|
949
|
-
return { authenticated:
|
|
950
|
+
if (!auth.isUserAuthenticated()) {
|
|
951
|
+
return { authenticated: false, redirectTo: "/login" };
|
|
950
952
|
}
|
|
951
|
-
return {
|
|
952
|
-
authenticated: false,
|
|
953
|
-
redirectTo: "/login"
|
|
954
|
-
};
|
|
953
|
+
return { authenticated: true };
|
|
955
954
|
},
|
|
956
955
|
onError: async (error) => {
|
|
957
956
|
const status = error?.statusCode || error?.status || error?.response?.status;
|
|
@@ -974,16 +973,15 @@ function authProvider(client) {
|
|
|
974
973
|
getIdentity: async () => {
|
|
975
974
|
const response = await auth.getCurrentUser();
|
|
976
975
|
if (!response) {
|
|
976
|
+
_cachedUser = null;
|
|
977
977
|
return null;
|
|
978
978
|
}
|
|
979
|
-
|
|
979
|
+
const user = response.data ?? response;
|
|
980
|
+
_cachedUser = user;
|
|
981
|
+
return user;
|
|
980
982
|
},
|
|
981
983
|
getPermissions: async () => {
|
|
982
|
-
const
|
|
983
|
-
if (!response) {
|
|
984
|
-
return null;
|
|
985
|
-
}
|
|
986
|
-
const user = response.data ?? response;
|
|
984
|
+
const user = _cachedUser;
|
|
987
985
|
if (!user) {
|
|
988
986
|
return null;
|
|
989
987
|
}
|
|
@@ -1003,9 +1001,16 @@ function accessControlProvider(client, options) {
|
|
|
1003
1001
|
const { batchDelayMs = 50 } = options ?? {};
|
|
1004
1002
|
const permissionLoader = new DataLoader(
|
|
1005
1003
|
async (checks) => {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1004
|
+
let currentUser = _cachedUser;
|
|
1005
|
+
if (!currentUser) {
|
|
1006
|
+
try {
|
|
1007
|
+
const response = await auth.getCurrentUser();
|
|
1008
|
+
currentUser = response ? response.data ?? response : null;
|
|
1009
|
+
} catch {
|
|
1010
|
+
currentUser = null;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
if (!currentUser) {
|
|
1009
1014
|
return checks.map(() => ({
|
|
1010
1015
|
can: false,
|
|
1011
1016
|
reason: "User not authenticated"
|
|
@@ -1017,8 +1022,7 @@ function accessControlProvider(client, options) {
|
|
|
1017
1022
|
const key = `${check.resource}:${recordId}`;
|
|
1018
1023
|
if (!uniqueResources.has(key)) {
|
|
1019
1024
|
uniqueResources.set(key, {
|
|
1020
|
-
|
|
1021
|
-
tableName: check.resource,
|
|
1025
|
+
resource: check.resource,
|
|
1022
1026
|
recordId,
|
|
1023
1027
|
attributes: check.params || {},
|
|
1024
1028
|
actions: /* @__PURE__ */ new Set()
|
|
@@ -1026,10 +1030,9 @@ function accessControlProvider(client, options) {
|
|
|
1026
1030
|
}
|
|
1027
1031
|
uniqueResources.get(key).actions.add(check.action);
|
|
1028
1032
|
}
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
tableName: entry.tableName,
|
|
1033
|
+
const uniqueEntries = Array.from(uniqueResources.values());
|
|
1034
|
+
const batchPayload = uniqueEntries.map((entry) => ({
|
|
1035
|
+
resource: entry.resource,
|
|
1033
1036
|
recordId: entry.recordId,
|
|
1034
1037
|
attributes: entry.attributes,
|
|
1035
1038
|
actions: Array.from(entry.actions)
|
|
@@ -1039,7 +1042,7 @@ function accessControlProvider(client, options) {
|
|
|
1039
1042
|
const resultsByResource = /* @__PURE__ */ new Map();
|
|
1040
1043
|
result?.results?.forEach((r, index) => {
|
|
1041
1044
|
const payload = batchPayload[index];
|
|
1042
|
-
const key = `${payload.
|
|
1045
|
+
const key = `${payload.resource}:${payload.recordId}`;
|
|
1043
1046
|
resultsByResource.set(key, r.actions || {});
|
|
1044
1047
|
});
|
|
1045
1048
|
return checks.map((check) => {
|
|
@@ -1071,12 +1074,10 @@ function accessControlProvider(client, options) {
|
|
|
1071
1074
|
if (!resource) {
|
|
1072
1075
|
return { can: false, reason: "Resource not specified" };
|
|
1073
1076
|
}
|
|
1074
|
-
const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
|
|
1075
1077
|
return permissionLoader.load({
|
|
1076
1078
|
resource,
|
|
1077
1079
|
action,
|
|
1078
|
-
params
|
|
1079
|
-
entityType
|
|
1080
|
+
params
|
|
1080
1081
|
});
|
|
1081
1082
|
},
|
|
1082
1083
|
options: {
|
|
@@ -1094,6 +1095,6 @@ function accessControlProvider(client, options) {
|
|
|
1094
1095
|
};
|
|
1095
1096
|
}
|
|
1096
1097
|
|
|
1097
|
-
export { REFINE_OPERATOR_MAP, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
|
|
1098
|
+
export { REFINE_OPERATOR_MAP, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
|
|
1098
1099
|
//# sourceMappingURL=index.js.map
|
|
1099
1100
|
//# sourceMappingURL=index.js.map
|