@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 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,
@@ -954,14 +956,7 @@ function authProvider(client) {
954
956
  if (!auth.isUserAuthenticated()) {
955
957
  return { authenticated: false, redirectTo: "/login" };
956
958
  }
957
- try {
958
- const user = await auth.getCurrentUser();
959
- if (user) {
960
- return { authenticated: true };
961
- }
962
- } catch {
963
- }
964
- return { authenticated: false, redirectTo: "/login" };
959
+ return { authenticated: true };
965
960
  },
966
961
  onError: async (error) => {
967
962
  const status = error?.statusCode || error?.status || error?.response?.status;
@@ -984,16 +979,15 @@ function authProvider(client) {
984
979
  getIdentity: async () => {
985
980
  const response = await auth.getCurrentUser();
986
981
  if (!response) {
982
+ exports._cachedUser = null;
987
983
  return null;
988
984
  }
989
- return response.data ?? response;
985
+ const user = response.data ?? response;
986
+ exports._cachedUser = user;
987
+ return user;
990
988
  },
991
989
  getPermissions: async () => {
992
- const response = await auth.getCurrentUser();
993
- if (!response) {
994
- return null;
995
- }
996
- const user = response.data ?? response;
990
+ const user = exports._cachedUser;
997
991
  if (!user) {
998
992
  return null;
999
993
  }
@@ -1013,9 +1007,16 @@ function accessControlProvider(client, options) {
1013
1007
  const { batchDelayMs = 50 } = options ?? {};
1014
1008
  const permissionLoader = new DataLoader__default.default(
1015
1009
  async (checks) => {
1016
- const response = await auth.getCurrentUser();
1017
- const user = response ? response.data ?? response : null;
1018
- 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) {
1019
1020
  return checks.map(() => ({
1020
1021
  can: false,
1021
1022
  reason: "User not authenticated"
@@ -1027,8 +1028,7 @@ function accessControlProvider(client, options) {
1027
1028
  const key = `${check.resource}:${recordId}`;
1028
1029
  if (!uniqueResources.has(key)) {
1029
1030
  uniqueResources.set(key, {
1030
- entityType: check.entityType,
1031
- tableName: check.resource,
1031
+ resource: check.resource,
1032
1032
  recordId,
1033
1033
  attributes: check.params || {},
1034
1034
  actions: /* @__PURE__ */ new Set()
@@ -1036,10 +1036,9 @@ function accessControlProvider(client, options) {
1036
1036
  }
1037
1037
  uniqueResources.get(key).actions.add(check.action);
1038
1038
  }
1039
- const batchPayload = Array.from(uniqueResources.values()).map((entry) => ({
1040
- entityType: entry.entityType ?? entry.tableName,
1041
- // Default to tableName if entityType not specified
1042
- tableName: entry.tableName,
1039
+ const uniqueEntries = Array.from(uniqueResources.values());
1040
+ const batchPayload = uniqueEntries.map((entry) => ({
1041
+ resource: entry.resource,
1043
1042
  recordId: entry.recordId,
1044
1043
  attributes: entry.attributes,
1045
1044
  actions: Array.from(entry.actions)
@@ -1049,7 +1048,7 @@ function accessControlProvider(client, options) {
1049
1048
  const resultsByResource = /* @__PURE__ */ new Map();
1050
1049
  result?.results?.forEach((r, index) => {
1051
1050
  const payload = batchPayload[index];
1052
- const key = `${payload.tableName}:${payload.recordId}`;
1051
+ const key = `${payload.resource}:${payload.recordId}`;
1053
1052
  resultsByResource.set(key, r.actions || {});
1054
1053
  });
1055
1054
  return checks.map((check) => {
@@ -1081,12 +1080,10 @@ function accessControlProvider(client, options) {
1081
1080
  if (!resource) {
1082
1081
  return { can: false, reason: "Resource not specified" };
1083
1082
  }
1084
- const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
1085
1083
  return permissionLoader.load({
1086
1084
  resource,
1087
1085
  action,
1088
- params,
1089
- entityType
1086
+ params
1090
1087
  });
1091
1088
  },
1092
1089
  options: {