@minimaltech/ra-core-infra 0.0.3-6 → 0.0.3-7

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.
@@ -7,6 +7,7 @@ export * from './use-copy-to-clipboard';
7
7
  export * from './use-debounce';
8
8
  export * from './use-document-title';
9
9
  export * from './use-injectable';
10
+ export * from './use-logout';
10
11
  export * from './use-sizer';
11
12
  export * from './use-translate';
12
13
  export * from './use-window-dimensions';
@@ -7,6 +7,7 @@ export * from './use-copy-to-clipboard';
7
7
  export * from './use-debounce';
8
8
  export * from './use-document-title';
9
9
  export * from './use-injectable';
10
+ export * from './use-logout';
10
11
  export * from './use-sizer';
11
12
  export * from './use-translate';
12
13
  export * from './use-window-dimensions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/hooks/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/hooks/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const useLogout: () => TLogout;
2
+ type TLogout = (params?: any, redirectTo?: string | false, redirectToCurrentLocationAfterLogin?: boolean) => Promise<any>;
3
+ export {};
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+ import { useQueryClient } from '@tanstack/react-query';
3
+ import { removeDoubleSlashes, useAuthProvider, useBasename } from 'ra-core';
4
+ import { useLocation, useNavigate } from 'react-router-dom';
5
+ const defaultAuthParams = {
6
+ loginUrl: '/login',
7
+ afterLoginUrl: '/',
8
+ };
9
+ export const useLogout = () => {
10
+ const authProvider = useAuthProvider();
11
+ const queryClient = useQueryClient();
12
+ const navigate = useNavigate();
13
+ const navigateRef = React.useRef(navigate);
14
+ const location = useLocation();
15
+ const locationRef = React.useRef(location);
16
+ const basename = useBasename();
17
+ const loginUrl = removeDoubleSlashes(`${basename}/${defaultAuthParams.loginUrl}`);
18
+ React.useEffect(() => {
19
+ locationRef.current = location;
20
+ navigateRef.current = navigate;
21
+ }, [location, navigate]);
22
+ const logout = React.useCallback((params = {}, redirectFromCaller, redirectToCurrentLocationAfterLogin = true) => {
23
+ if (authProvider) {
24
+ return authProvider.logout(params).then(redirectFromLogout => {
25
+ if (redirectFromLogout === false || redirectFromCaller === false) {
26
+ queryClient.clear();
27
+ return;
28
+ }
29
+ const finalRedirectTo = redirectFromCaller || redirectFromLogout || loginUrl;
30
+ if (finalRedirectTo?.startsWith('http')) {
31
+ queryClient.clear();
32
+ window.location.href = finalRedirectTo;
33
+ return finalRedirectTo;
34
+ }
35
+ const redirectToParts = finalRedirectTo.split('?');
36
+ const newLocation = {
37
+ pathname: redirectToParts[0],
38
+ };
39
+ let newLocationOptions = {};
40
+ if (redirectToCurrentLocationAfterLogin &&
41
+ locationRef.current &&
42
+ locationRef.current.pathname) {
43
+ newLocationOptions = {
44
+ state: {
45
+ nextPathname: locationRef.current.pathname,
46
+ nextSearch: locationRef.current.search,
47
+ },
48
+ };
49
+ }
50
+ if (redirectToParts[1]) {
51
+ newLocation.search = redirectToParts[1];
52
+ }
53
+ setTimeout(() => {
54
+ navigateRef.current(newLocation, newLocationOptions);
55
+ queryClient.clear();
56
+ }, 0);
57
+ return redirectFromLogout;
58
+ });
59
+ }
60
+ else {
61
+ navigateRef.current({
62
+ pathname: loginUrl,
63
+ }, {
64
+ state: {
65
+ nextPathname: locationRef.current && locationRef.current.pathname,
66
+ },
67
+ });
68
+ queryClient.clear();
69
+ return Promise.resolve();
70
+ }
71
+ }, [authProvider, loginUrl, queryClient]);
72
+ return logout;
73
+ };
74
+ //# sourceMappingURL=use-logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-logout.js","sourceRoot":"","sources":["../../../src/ui/hooks/use-logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAQ,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,iBAAiB,GAAG;IACxB,QAAQ,EAAE,QAAQ;IAClB,aAAa,EAAE,GAAG;CACnB,CAAC;AAKF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAY,EAAE;IACrC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAI/B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,WAA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B,CAAC;oBACD,kBAAkB,GAAG;wBACnB,KAAK,EAAE;4BACL,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,QAAQ;4BAC1C,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM;yBACvC;qBACF,CAAC;gBACJ,CAAC;gBACD,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;oBACvB,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;gBAC1C,CAAC;gBASD,UAAU,CAAC,GAAG,EAAE;oBACd,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;oBAGrD,WAAW,CAAC,KAAK,EAAE,CAAC;gBACtB,CAAC,EAAE,CAAC,CAAC,CAAC;gBAEN,OAAO,kBAAkB,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,OAAO,CACjB;gBACE,QAAQ,EAAE,QAAQ;aACnB,EACD;gBACE,KAAK,EAAE;oBACL,YAAY,EAAE,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ;iBAClE;aACF,CACF,CAAC;YAEF,WAAW,CAAC,KAAK,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC,EACD,CAAC,YAAY,EAAE,QAAQ,EAAE,WAAW,CAAC,CACtC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -2,11 +2,13 @@ export declare class ApplicationError extends Error {
2
2
  statusCode: number;
3
3
  messageCode?: string;
4
4
  payload?: any;
5
+ messageArgs?: any;
5
6
  constructor(opts: {
6
7
  statusCode?: number;
7
8
  messageCode?: string;
8
9
  message: string;
9
10
  payload?: any;
11
+ messageArgs?: any;
10
12
  });
11
13
  }
12
14
  export declare const getError: (opts: {
@@ -14,5 +16,6 @@ export declare const getError: (opts: {
14
16
  messageCode?: string;
15
17
  message: string;
16
18
  payload?: any;
19
+ messageArgs?: any;
17
20
  }) => ApplicationError;
18
21
  export declare const getClientError: (e: unknown) => ApplicationError;
@@ -2,12 +2,14 @@ export class ApplicationError extends Error {
2
2
  statusCode;
3
3
  messageCode;
4
4
  payload;
5
+ messageArgs;
5
6
  constructor(opts) {
6
- const { message, messageCode, statusCode = 400, payload } = opts;
7
+ const { message, messageCode, statusCode = 400, payload, messageArgs } = opts;
7
8
  super(message);
8
9
  this.statusCode = statusCode;
9
10
  this.messageCode = messageCode;
10
11
  this.payload = payload;
12
+ this.messageArgs = messageArgs;
11
13
  }
12
14
  }
13
15
  export const getError = (opts) => {
@@ -17,8 +19,10 @@ export const getError = (opts) => {
17
19
  export const getClientError = (e) => {
18
20
  if (e instanceof ApplicationError) {
19
21
  return new ApplicationError({
22
+ statusCode: e.statusCode,
20
23
  messageCode: e?.messageCode ?? e.message,
21
24
  message: e.message,
25
+ messageArgs: e.messageArgs,
22
26
  });
23
27
  }
24
28
  if (e instanceof Error) {
@@ -1 +1 @@
1
- {"version":3,"file":"error.utility.js","sourceRoot":"","sources":["../../src/utilities/error.utility.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,UAAU,CAAS;IACnB,WAAW,CAAU;IACrB,OAAO,CAAO;IAEd,YAAY,IAAmF;QAC7F,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAKxB,EAAE,EAAE;IACH,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACzC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GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAU,EAAE,EAAE;IAC3C,IAAI,CAAC,YAAY,gBAAgB,EAAE,CAAC;QAClC,OAAO,IAAI,gBAAgB,CAAC;YAC1B,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,WAAW,EAAE,CAAC,EAAE,WAAW,IAAI,CAAC,CAAC,OAAO;YACxC,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,WAAW,EAAE,CAAC,CAAC,WAAW;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,IAAI,gBAAgB,CAAC;YAC1B,WAAW,EAAE,CAAC,CAAC,OAAO;YACtB,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,gBAAgB,CAAC;QAC1B,WAAW,EAAE,GAAG,CAAC,EAAE;QACnB,OAAO,EAAE,GAAG,CAAC,EAAE;KAChB,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minimaltech/ra-core-infra",
3
- "version": "0.0.3-6",
3
+ "version": "0.0.3-7",
4
4
  "description": "Minimal Technology - ReactJS Core Infrastructure",
5
5
  "keywords": [
6
6
  "web",
@@ -78,6 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "@reduxjs/toolkit": "^2.9.1",
81
+ "@tanstack/react-query": "^5.99.0",
81
82
  "ra-i18n-polyglot": "^5.12.1",
82
83
  "react-router-dom": "^7.9.4"
83
84
  },