@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 CHANGED
@@ -11,7 +11,7 @@ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
11
11
 
12
12
  // package.json
13
13
  var package_default = {
14
- version: "1.2.7"};
14
+ version: "1.2.8"};
15
15
 
16
16
  // src/utils.ts
17
17
  var REFINE_OPERATOR_MAP = {
@@ -917,6 +917,7 @@ function analyticsDataProvider(client) {
917
917
  }
918
918
  };
919
919
  }
920
+ exports._cachedUser = null;
920
921
  function authProvider(client) {
921
922
  const auth = new sdk.Auth(client);
922
923
  return {
@@ -944,6 +945,7 @@ function authProvider(client) {
944
945
  },
945
946
  logout: async (params = {}) => {
946
947
  const { callbackUrl } = params;
948
+ exports._cachedUser = null;
947
949
  await auth.logout(callbackUrl);
948
950
  return {
949
951
  success: true,
@@ -951,13 +953,10 @@ function authProvider(client) {
951
953
  };
952
954
  },
953
955
  check: async () => {
954
- if (auth.isUserAuthenticated()) {
955
- return { authenticated: true };
956
+ if (!auth.isUserAuthenticated()) {
957
+ return { authenticated: false, redirectTo: "/login" };
956
958
  }
957
- return {
958
- authenticated: false,
959
- redirectTo: "/login"
960
- };
959
+ return { authenticated: true };
961
960
  },
962
961
  onError: async (error) => {
963
962
  const status = error?.statusCode || error?.status || error?.response?.status;
@@ -980,16 +979,15 @@ function authProvider(client) {
980
979
  getIdentity: async () => {
981
980
  const response = await auth.getCurrentUser();
982
981
  if (!response) {
982
+ exports._cachedUser = null;
983
983
  return null;
984
984
  }
985
- return response.data ?? response;
985
+ const user = response.data ?? response;
986
+ exports._cachedUser = user;
987
+ return user;
986
988
  },
987
989
  getPermissions: async () => {
988
- const response = await auth.getCurrentUser();
989
- if (!response) {
990
- return null;
991
- }
992
- const user = response.data ?? response;
990
+ const user = exports._cachedUser;
993
991
  if (!user) {
994
992
  return null;
995
993
  }
@@ -1009,9 +1007,16 @@ function accessControlProvider(client, options) {
1009
1007
  const { batchDelayMs = 50 } = options ?? {};
1010
1008
  const permissionLoader = new DataLoader__default.default(
1011
1009
  async (checks) => {
1012
- const response = await auth.getCurrentUser();
1013
- const user = response ? response.data ?? response : null;
1014
- if (!user) {
1010
+ let currentUser = exports._cachedUser;
1011
+ if (!currentUser) {
1012
+ try {
1013
+ const response = await auth.getCurrentUser();
1014
+ currentUser = response ? response.data ?? response : null;
1015
+ } catch {
1016
+ currentUser = null;
1017
+ }
1018
+ }
1019
+ if (!currentUser) {
1015
1020
  return checks.map(() => ({
1016
1021
  can: false,
1017
1022
  reason: "User not authenticated"
@@ -1023,8 +1028,7 @@ function accessControlProvider(client, options) {
1023
1028
  const key = `${check.resource}:${recordId}`;
1024
1029
  if (!uniqueResources.has(key)) {
1025
1030
  uniqueResources.set(key, {
1026
- entityType: check.entityType,
1027
- tableName: check.resource,
1031
+ resource: check.resource,
1028
1032
  recordId,
1029
1033
  attributes: check.params || {},
1030
1034
  actions: /* @__PURE__ */ new Set()
@@ -1032,10 +1036,9 @@ function accessControlProvider(client, options) {
1032
1036
  }
1033
1037
  uniqueResources.get(key).actions.add(check.action);
1034
1038
  }
1035
- const batchPayload = Array.from(uniqueResources.values()).map((entry) => ({
1036
- entityType: entry.entityType ?? entry.tableName,
1037
- // Default to tableName if entityType not specified
1038
- tableName: entry.tableName,
1039
+ const uniqueEntries = Array.from(uniqueResources.values());
1040
+ const batchPayload = uniqueEntries.map((entry) => ({
1041
+ resource: entry.resource,
1039
1042
  recordId: entry.recordId,
1040
1043
  attributes: entry.attributes,
1041
1044
  actions: Array.from(entry.actions)
@@ -1045,7 +1048,7 @@ function accessControlProvider(client, options) {
1045
1048
  const resultsByResource = /* @__PURE__ */ new Map();
1046
1049
  result?.results?.forEach((r, index) => {
1047
1050
  const payload = batchPayload[index];
1048
- const key = `${payload.tableName}:${payload.recordId}`;
1051
+ const key = `${payload.resource}:${payload.recordId}`;
1049
1052
  resultsByResource.set(key, r.actions || {});
1050
1053
  });
1051
1054
  return checks.map((check) => {
@@ -1077,12 +1080,10 @@ function accessControlProvider(client, options) {
1077
1080
  if (!resource) {
1078
1081
  return { can: false, reason: "Resource not specified" };
1079
1082
  }
1080
- const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
1081
1083
  return permissionLoader.load({
1082
1084
  resource,
1083
1085
  action,
1084
- params,
1085
- entityType
1086
+ params
1086
1087
  });
1087
1088
  },
1088
1089
  options: {