@refinedev/core 4.55.0 → 4.57.1

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +169 -2
  2. package/README.md +6 -4
  3. package/dist/components/authenticated/index.d.cts +6 -1
  4. package/dist/components/authenticated/index.d.cts.map +1 -1
  5. package/dist/components/authenticated/index.d.mts +6 -1
  6. package/dist/components/authenticated/index.d.mts.map +6 -1
  7. package/dist/components/authenticated/index.d.ts +6 -1
  8. package/dist/components/authenticated/index.d.ts.map +1 -1
  9. package/dist/components/link/index.d.cts +3 -3
  10. package/dist/components/link/index.d.cts.map +1 -1
  11. package/dist/components/link/index.d.mts +3 -3
  12. package/dist/components/link/index.d.mts.map +3 -3
  13. package/dist/components/link/index.d.ts +3 -3
  14. package/dist/components/link/index.d.ts.map +1 -1
  15. package/dist/components/pages/auth/components/forgotPassword/index.d.cts.map +1 -1
  16. package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
  17. package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
  18. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  19. package/dist/components/pages/auth/components/register/index.d.cts.map +1 -1
  20. package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
  21. package/dist/components/pages/auth/components/updatePassword/index.d.cts.map +1 -1
  22. package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
  23. package/dist/components/pages/auth/types.d.cts +8 -0
  24. package/dist/components/pages/auth/types.d.cts.map +1 -1
  25. package/dist/components/pages/auth/types.d.mts +8 -0
  26. package/dist/components/pages/auth/types.d.mts.map +8 -0
  27. package/dist/components/pages/auth/types.d.ts +8 -0
  28. package/dist/components/pages/auth/types.d.ts.map +1 -1
  29. package/dist/contexts/metaContext/index.d.cts +18 -0
  30. package/dist/contexts/metaContext/index.d.cts.map +1 -0
  31. package/dist/contexts/metaContext/index.d.mts +18 -0
  32. package/dist/contexts/metaContext/index.d.mts.map +18 -0
  33. package/dist/contexts/metaContext/index.d.ts +18 -0
  34. package/dist/contexts/metaContext/index.d.ts.map +1 -0
  35. package/dist/hooks/auth/index.d.cts +1 -0
  36. package/dist/hooks/auth/index.d.cts.map +1 -1
  37. package/dist/hooks/auth/index.d.mts +1 -0
  38. package/dist/hooks/auth/index.d.mts.map +1 -0
  39. package/dist/hooks/auth/index.d.ts +1 -0
  40. package/dist/hooks/auth/index.d.ts.map +1 -1
  41. package/dist/hooks/navigation/index.d.cts.map +1 -1
  42. package/dist/hooks/navigation/index.d.ts.map +1 -1
  43. package/dist/hooks/router/use-link/index.d.cts +1 -1
  44. package/dist/hooks/router/use-link/index.d.mts +1 -1
  45. package/dist/hooks/router/use-link/index.d.mts.map +1 -1
  46. package/dist/hooks/router/use-link/index.d.ts +1 -1
  47. package/dist/hooks/useMeta/index.d.cts +2 -12
  48. package/dist/hooks/useMeta/index.d.cts.map +1 -1
  49. package/dist/hooks/useMeta/index.d.mts +2 -12
  50. package/dist/hooks/useMeta/index.d.mts.map +2 -12
  51. package/dist/hooks/useMeta/index.d.ts +2 -12
  52. package/dist/hooks/useMeta/index.d.ts.map +1 -1
  53. package/dist/index.cjs +18 -18
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.cts +1 -0
  56. package/dist/index.d.cts.map +1 -1
  57. package/dist/index.d.mts +1 -0
  58. package/dist/index.d.mts.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.mjs +18 -18
  62. package/dist/index.mjs.map +1 -1
  63. package/package.json +3 -3
  64. package/src/components/authenticated/index.tsx +9 -1
  65. package/src/components/link/index.tsx +6 -8
  66. package/src/components/pages/auth/components/forgotPassword/index.tsx +2 -1
  67. package/src/components/pages/auth/components/login/index.tsx +3 -1
  68. package/src/components/pages/auth/components/register/index.tsx +3 -1
  69. package/src/components/pages/auth/components/updatePassword/index.tsx +2 -0
  70. package/src/components/pages/auth/types.tsx +8 -0
  71. package/src/contexts/metaContext/index.tsx +45 -0
  72. package/src/hooks/auth/index.ts +1 -0
  73. package/src/hooks/data/useUpdate.ts +5 -5
  74. package/src/hooks/navigation/index.ts +5 -0
  75. package/src/hooks/useMeta/index.ts +16 -2
  76. package/src/index.tsx +5 -0
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@refinedev/core",
3
- "version": "4.55.0",
3
+ "version": "4.57.1",
4
4
  "private": false,
5
- "description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
5
+ "description": "Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/refinedev/refine.git",
@@ -27,7 +27,7 @@
27
27
  "module": "dist/index.mjs",
28
28
  "typings": "dist/index.d.ts",
29
29
  "dependencies": {
30
- "@refinedev/devtools-internal": "1.1.14",
30
+ "@refinedev/devtools-internal": "1.1.16",
31
31
  "@tanstack/react-query": "^4.10.1",
32
32
  "lodash": "^4.17.21",
33
33
  "lodash-es": "^4.17.21",
@@ -11,6 +11,8 @@ import {
11
11
  } from "@hooks";
12
12
  import type { GoConfig } from "../../contexts/router/types";
13
13
 
14
+ export type AuthCheckParams = any;
15
+
14
16
  export type AuthenticatedCommonProps = {
15
17
  /**
16
18
  * Unique key to identify the component.
@@ -44,9 +46,13 @@ export type AuthenticatedCommonProps = {
44
46
  */
45
47
  loading?: React.ReactNode;
46
48
  /**
47
- * Content to show if user is logged in
49
+ * Content to show if user is logged in.
48
50
  */
49
51
  children?: React.ReactNode;
52
+ /**
53
+ * optional params to be passed to the Auth Provider's check method via the useIsAuthenticated hook.
54
+ */
55
+ params?: AuthCheckParams;
50
56
  };
51
57
 
52
58
  export type LegacyAuthenticatedProps = {
@@ -97,6 +103,7 @@ export function Authenticated({
97
103
  children,
98
104
  fallback: fallbackContent,
99
105
  loading: loadingContent,
106
+ params,
100
107
  }: AuthenticatedProps | LegacyAuthenticatedProps): JSX.Element | null {
101
108
  const activeAuthProvider = useActiveAuthProvider();
102
109
  const routerType = useRouterType();
@@ -119,6 +126,7 @@ export function Authenticated({
119
126
  } = {},
120
127
  } = useIsAuthenticated({
121
128
  v3LegacyAuthProviderCompatible: isLegacyAuth,
129
+ params,
122
130
  });
123
131
 
124
132
  // Authentication status
@@ -13,9 +13,7 @@ type LinkPropsWithTo = {
13
13
  };
14
14
 
15
15
  export type LinkProps<TProps = {}> = React.PropsWithChildren<
16
- (LinkPropsWithGo | LinkPropsWithTo) &
17
- React.AnchorHTMLAttributes<HTMLAnchorElement> &
18
- TProps
16
+ (LinkPropsWithGo | LinkPropsWithTo) & TProps
19
17
  >;
20
18
 
21
19
  /**
@@ -25,7 +23,7 @@ export type LinkProps<TProps = {}> = React.PropsWithChildren<
25
23
  */
26
24
  const LinkComponent = <TProps = {}>(
27
25
  props: LinkProps<TProps>,
28
- ref: Ref<HTMLAnchorElement>,
26
+ ref: Ref<Element>,
29
27
  ) => {
30
28
  const routerContext = useContext(RouterContext);
31
29
  const LinkFromContext = routerContext?.Link;
@@ -33,9 +31,6 @@ const LinkComponent = <TProps = {}>(
33
31
  const goFunction = useGo();
34
32
 
35
33
  let resolvedTo = "";
36
- if ("to" in props) {
37
- resolvedTo = props.to;
38
- }
39
34
  if ("go" in props) {
40
35
  if (!routerContext?.go) {
41
36
  warnOnce(
@@ -45,6 +40,9 @@ const LinkComponent = <TProps = {}>(
45
40
  }
46
41
  resolvedTo = goFunction({ ...props.go, type: "path" }) as string;
47
42
  }
43
+ if ("to" in props) {
44
+ resolvedTo = props.to;
45
+ }
48
46
 
49
47
  if (LinkFromContext) {
50
48
  return (
@@ -70,5 +68,5 @@ const LinkComponent = <TProps = {}>(
70
68
  };
71
69
 
72
70
  export const Link = forwardRef(LinkComponent) as <T = {}>(
73
- props: LinkProps<T> & { ref?: Ref<HTMLAnchorElement> },
71
+ props: LinkProps<T> & { ref?: Ref<Element> },
74
72
  ) => ReturnType<typeof LinkComponent>;
@@ -27,6 +27,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
27
27
  renderContent,
28
28
  formProps,
29
29
  title = undefined,
30
+ mutationVariables,
30
31
  }) => {
31
32
  const translate = useTranslate();
32
33
  const routerType = useRouterType();
@@ -53,7 +54,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
53
54
  <form
54
55
  onSubmit={(e) => {
55
56
  e.preventDefault();
56
- forgotPassword({ email });
57
+ forgotPassword({ ...mutationVariables, email });
57
58
  }}
58
59
  {...formProps}
59
60
  >
@@ -25,6 +25,7 @@ export const LoginPage: React.FC<LoginProps> = ({
25
25
  formProps,
26
26
  title = undefined,
27
27
  hideForm,
28
+ mutationVariables,
28
29
  }) => {
29
30
  const routerType = useRouterType();
30
31
  const Link = useLink();
@@ -62,6 +63,7 @@ export const LoginPage: React.FC<LoginProps> = ({
62
63
  <button
63
64
  onClick={() =>
64
65
  login({
66
+ ...mutationVariables,
65
67
  providerName: provider.name,
66
68
  })
67
69
  }
@@ -91,7 +93,7 @@ export const LoginPage: React.FC<LoginProps> = ({
91
93
  <form
92
94
  onSubmit={(e) => {
93
95
  e.preventDefault();
94
- login({ email, password, remember });
96
+ login({ ...mutationVariables, email, password, remember });
95
97
  }}
96
98
  {...formProps}
97
99
  >
@@ -28,6 +28,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
28
28
  formProps,
29
29
  title = undefined,
30
30
  hideForm,
31
+ mutationVariables,
31
32
  }) => {
32
33
  const routerType = useRouterType();
33
34
  const Link = useLink();
@@ -64,6 +65,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
64
65
  <button
65
66
  onClick={() =>
66
67
  register({
68
+ ...mutationVariables,
67
69
  providerName: provider.name,
68
70
  })
69
71
  }
@@ -93,7 +95,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
93
95
  <form
94
96
  onSubmit={(e) => {
95
97
  e.preventDefault();
96
- register({ email, password });
98
+ register({ ...mutationVariables, email, password });
97
99
  }}
98
100
  {...formProps}
99
101
  >
@@ -21,6 +21,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
21
21
  renderContent,
22
22
  formProps,
23
23
  title = undefined,
24
+ mutationVariables,
24
25
  }) => {
25
26
  const translate = useTranslate();
26
27
 
@@ -43,6 +44,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
43
44
  onSubmit={(e) => {
44
45
  e.preventDefault();
45
46
  updatePassword({
47
+ ...mutationVariables,
46
48
  password: newPassword,
47
49
  confirmPassword,
48
50
  });
@@ -144,6 +144,10 @@ export type AuthPageProps<
144
144
  * @optional
145
145
  * */
146
146
  title?: React.ReactNode;
147
+ /**
148
+ * @description Can be used to pass additional variables to the mutation. This is useful when you need to pass other variables to the authProvider.
149
+ */
150
+ mutationVariables?: Record<string, any>;
147
151
  };
148
152
 
149
153
  /**
@@ -167,6 +171,7 @@ export type LoginPageProps<
167
171
  formProps?: TFormProps;
168
172
  title?: React.ReactNode;
169
173
  hideForm?: boolean;
174
+ mutationVariables?: Record<string, unknown>;
170
175
  }>;
171
176
 
172
177
  /**
@@ -188,6 +193,7 @@ export type RegisterPageProps<
188
193
  formProps?: TFormProps;
189
194
  title?: React.ReactNode;
190
195
  hideForm?: boolean;
196
+ mutationVariables?: Record<string, unknown>;
191
197
  }>;
192
198
 
193
199
  /**
@@ -207,6 +213,7 @@ export type ForgotPasswordPageProps<
207
213
  contentProps?: TContentProps;
208
214
  formProps?: TFormProps;
209
215
  title?: React.ReactNode;
216
+ mutationVariables?: Record<string, unknown>;
210
217
  }>;
211
218
 
212
219
  /**
@@ -225,4 +232,5 @@ export type UpdatePasswordPageProps<
225
232
  contentProps?: TContentProps;
226
233
  formProps?: TFormProps;
227
234
  title?: React.ReactNode;
235
+ mutationVariables?: Record<string, unknown>;
228
236
  }>;
@@ -0,0 +1,45 @@
1
+ import React, {
2
+ type ReactNode,
3
+ createContext,
4
+ useContext,
5
+ useMemo,
6
+ } from "react";
7
+
8
+ type MetaContextValue = Record<string, any>;
9
+
10
+ export const MetaContext = createContext<MetaContextValue>({});
11
+
12
+ /**
13
+ * Is used to provide meta data to the children components.
14
+ * @internal
15
+ */
16
+ export const MetaContextProvider = ({
17
+ children,
18
+ value,
19
+ }: { children: ReactNode; value: MetaContextValue }) => {
20
+ const currentValue = useMetaContext();
21
+
22
+ const metaContext = useMemo(() => {
23
+ return {
24
+ ...currentValue,
25
+ ...value,
26
+ };
27
+ }, [currentValue, value]);
28
+
29
+ return (
30
+ <MetaContext.Provider value={metaContext}>{children}</MetaContext.Provider>
31
+ );
32
+ };
33
+
34
+ /**
35
+ * @internal
36
+ * @returns The MetaContext value.
37
+ */
38
+ export const useMetaContext = () => {
39
+ const context = useContext(MetaContext);
40
+ if (!context) {
41
+ throw new Error("useMetaContext must be used within a MetaContextProvider");
42
+ }
43
+
44
+ return useContext(MetaContext);
45
+ };
@@ -8,3 +8,4 @@ export { useUpdatePassword } from "./useUpdatePassword";
8
8
  export { useAuthenticated, useIsAuthenticated } from "./useIsAuthenticated";
9
9
  export { useCheckError, useOnError } from "./useOnError";
10
10
  export { useIsExistAuthentication } from "./useIsExistAuthentication";
11
+ export { useInvalidateAuthStore } from "./useInvalidateAuthStore";
@@ -240,7 +240,7 @@ export const useUpdate = <
240
240
  metaData = metaDataFromProps,
241
241
  dataProviderName = dataProviderNameFromProps,
242
242
  }) => {
243
- if (!id) throw missingIdError;
243
+ if (typeof id === "undefined") throw missingIdError;
244
244
  if (!values) throw missingValuesError;
245
245
  if (!resourceName) throw missingResourceError;
246
246
 
@@ -321,7 +321,7 @@ export const useUpdate = <
321
321
  detail: true,
322
322
  },
323
323
  }) => {
324
- if (!id) throw missingIdError;
324
+ if (typeof id === "undefined") throw missingIdError;
325
325
  if (!values) throw missingValuesError;
326
326
  if (!resourceName) throw missingResourceError;
327
327
 
@@ -462,7 +462,7 @@ export const useUpdate = <
462
462
  dataProviderName = dataProviderNameFromProps,
463
463
  invalidates = invalidatesFromProps ?? ["list", "many", "detail"],
464
464
  } = variables;
465
- if (!id) throw missingIdError;
465
+ if (typeof id === "undefined") throw missingIdError;
466
466
  if (!resourceName) throw missingResourceError;
467
467
 
468
468
  const { identifier } = select(resourceName);
@@ -495,7 +495,7 @@ export const useUpdate = <
495
495
  meta = metaFromProps,
496
496
  metaData = metaDataFromProps,
497
497
  } = variables;
498
- if (!id) throw missingIdError;
498
+ if (typeof id === "undefined") throw missingIdError;
499
499
  if (!values) throw missingValuesError;
500
500
  if (!resourceName) throw missingResourceError;
501
501
 
@@ -586,7 +586,7 @@ export const useUpdate = <
586
586
  errorNotification = errorNotificationFromProps,
587
587
  values = valuesFromProps,
588
588
  } = variables;
589
- if (!id) throw missingIdError;
589
+ if (typeof id === "undefined") throw missingIdError;
590
590
  if (!values) throw missingValuesError;
591
591
  if (!resourceName) throw missingResourceError;
592
592
 
@@ -85,6 +85,7 @@ export const useNavigation = () => {
85
85
  return go({
86
86
  to: composeRoute(createActionRoute, resourceItem?.meta, parsed, meta),
87
87
  type: "path",
88
+ query: meta.query,
88
89
  }) as string;
89
90
  };
90
91
 
@@ -138,6 +139,7 @@ export const useNavigation = () => {
138
139
  id: encodedId,
139
140
  }),
140
141
  type: "path",
142
+ query: meta.query,
141
143
  }) as string;
142
144
  };
143
145
 
@@ -192,6 +194,7 @@ export const useNavigation = () => {
192
194
  id: encodedId,
193
195
  }),
194
196
  type: "path",
197
+ query: meta.query,
195
198
  }) as string;
196
199
  };
197
200
 
@@ -245,6 +248,7 @@ export const useNavigation = () => {
245
248
  id: encodedId,
246
249
  }),
247
250
  type: "path",
251
+ query: meta.query,
248
252
  }) as string;
249
253
  };
250
254
 
@@ -295,6 +299,7 @@ export const useNavigation = () => {
295
299
  return go({
296
300
  to: composeRoute(listActionRoute, resourceItem?.meta, parsed, meta),
297
301
  type: "path",
302
+ query: meta.query,
298
303
  }) as string;
299
304
  };
300
305
 
@@ -1,3 +1,4 @@
1
+ import { useMetaContext } from "@contexts/metaContext";
1
2
  import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
2
3
  import { useParsed } from "@hooks/router";
3
4
 
@@ -6,12 +7,14 @@ import type { IResourceItem } from "../../contexts/resource/types";
6
7
 
7
8
  /**
8
9
  * Hook that returns a function to get meta.
9
- * The meta is a combination of the resource meta, hook meta and query params.
10
+ * The meta is a combination of the resource meta, hook meta, query params and metaContext value.
10
11
  * @internal
11
12
  */
12
13
  export const useMeta = () => {
13
14
  const { params } = useParsed();
14
15
 
16
+ const metaContext = useMetaContext();
17
+
15
18
  const getMetaFn = ({
16
19
  resource,
17
20
  meta: metaFromProp,
@@ -30,7 +33,18 @@ export const useMeta = () => {
30
33
  ...additionalParams
31
34
  } = params ?? {};
32
35
 
33
- return { ...meta, ...additionalParams, ...metaFromProp };
36
+ const result: Record<string, unknown> = {
37
+ ...meta,
38
+ ...additionalParams,
39
+ ...metaFromProp,
40
+ };
41
+
42
+ // when MultiTenancyProvider from "@refinedev-ee/multi-tenancy" is provided, we need to add tenantId to the meta
43
+ if (metaContext?.tenantId) {
44
+ result["tenantId"] = metaContext.tenantId;
45
+ }
46
+
47
+ return result;
34
48
  };
35
49
 
36
50
  return getMetaFn;
package/src/index.tsx CHANGED
@@ -224,3 +224,8 @@ export {
224
224
  } from "./contexts/undoableQueue/types.js";
225
225
 
226
226
  export { IUnsavedWarnContext } from "./contexts/unsavedWarn/types.js";
227
+
228
+ export {
229
+ MetaContextProvider,
230
+ useMetaContext,
231
+ } from "./contexts/metaContext/index.js";