@taruvi/refine-providers 1.2.8 → 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 +25 -28
- 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 +26 -29
- 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,
|
|
@@ -948,14 +950,7 @@ function authProvider(client) {
|
|
|
948
950
|
if (!auth.isUserAuthenticated()) {
|
|
949
951
|
return { authenticated: false, redirectTo: "/login" };
|
|
950
952
|
}
|
|
951
|
-
|
|
952
|
-
const user = await auth.getCurrentUser();
|
|
953
|
-
if (user) {
|
|
954
|
-
return { authenticated: true };
|
|
955
|
-
}
|
|
956
|
-
} catch {
|
|
957
|
-
}
|
|
958
|
-
return { authenticated: false, redirectTo: "/login" };
|
|
953
|
+
return { authenticated: true };
|
|
959
954
|
},
|
|
960
955
|
onError: async (error) => {
|
|
961
956
|
const status = error?.statusCode || error?.status || error?.response?.status;
|
|
@@ -978,16 +973,15 @@ function authProvider(client) {
|
|
|
978
973
|
getIdentity: async () => {
|
|
979
974
|
const response = await auth.getCurrentUser();
|
|
980
975
|
if (!response) {
|
|
976
|
+
_cachedUser = null;
|
|
981
977
|
return null;
|
|
982
978
|
}
|
|
983
|
-
|
|
979
|
+
const user = response.data ?? response;
|
|
980
|
+
_cachedUser = user;
|
|
981
|
+
return user;
|
|
984
982
|
},
|
|
985
983
|
getPermissions: async () => {
|
|
986
|
-
const
|
|
987
|
-
if (!response) {
|
|
988
|
-
return null;
|
|
989
|
-
}
|
|
990
|
-
const user = response.data ?? response;
|
|
984
|
+
const user = _cachedUser;
|
|
991
985
|
if (!user) {
|
|
992
986
|
return null;
|
|
993
987
|
}
|
|
@@ -1007,9 +1001,16 @@ function accessControlProvider(client, options) {
|
|
|
1007
1001
|
const { batchDelayMs = 50 } = options ?? {};
|
|
1008
1002
|
const permissionLoader = new DataLoader(
|
|
1009
1003
|
async (checks) => {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
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) {
|
|
1013
1014
|
return checks.map(() => ({
|
|
1014
1015
|
can: false,
|
|
1015
1016
|
reason: "User not authenticated"
|
|
@@ -1021,8 +1022,7 @@ function accessControlProvider(client, options) {
|
|
|
1021
1022
|
const key = `${check.resource}:${recordId}`;
|
|
1022
1023
|
if (!uniqueResources.has(key)) {
|
|
1023
1024
|
uniqueResources.set(key, {
|
|
1024
|
-
|
|
1025
|
-
tableName: check.resource,
|
|
1025
|
+
resource: check.resource,
|
|
1026
1026
|
recordId,
|
|
1027
1027
|
attributes: check.params || {},
|
|
1028
1028
|
actions: /* @__PURE__ */ new Set()
|
|
@@ -1030,10 +1030,9 @@ function accessControlProvider(client, options) {
|
|
|
1030
1030
|
}
|
|
1031
1031
|
uniqueResources.get(key).actions.add(check.action);
|
|
1032
1032
|
}
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
tableName: entry.tableName,
|
|
1033
|
+
const uniqueEntries = Array.from(uniqueResources.values());
|
|
1034
|
+
const batchPayload = uniqueEntries.map((entry) => ({
|
|
1035
|
+
resource: entry.resource,
|
|
1037
1036
|
recordId: entry.recordId,
|
|
1038
1037
|
attributes: entry.attributes,
|
|
1039
1038
|
actions: Array.from(entry.actions)
|
|
@@ -1043,7 +1042,7 @@ function accessControlProvider(client, options) {
|
|
|
1043
1042
|
const resultsByResource = /* @__PURE__ */ new Map();
|
|
1044
1043
|
result?.results?.forEach((r, index) => {
|
|
1045
1044
|
const payload = batchPayload[index];
|
|
1046
|
-
const key = `${payload.
|
|
1045
|
+
const key = `${payload.resource}:${payload.recordId}`;
|
|
1047
1046
|
resultsByResource.set(key, r.actions || {});
|
|
1048
1047
|
});
|
|
1049
1048
|
return checks.map((check) => {
|
|
@@ -1075,12 +1074,10 @@ function accessControlProvider(client, options) {
|
|
|
1075
1074
|
if (!resource) {
|
|
1076
1075
|
return { can: false, reason: "Resource not specified" };
|
|
1077
1076
|
}
|
|
1078
|
-
const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
|
|
1079
1077
|
return permissionLoader.load({
|
|
1080
1078
|
resource,
|
|
1081
1079
|
action,
|
|
1082
|
-
params
|
|
1083
|
-
entityType
|
|
1080
|
+
params
|
|
1084
1081
|
});
|
|
1085
1082
|
},
|
|
1086
1083
|
options: {
|
|
@@ -1098,6 +1095,6 @@ function accessControlProvider(client, options) {
|
|
|
1098
1095
|
};
|
|
1099
1096
|
}
|
|
1100
1097
|
|
|
1101
|
-
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 };
|
|
1102
1099
|
//# sourceMappingURL=index.js.map
|
|
1103
1100
|
//# sourceMappingURL=index.js.map
|