@buoy-gg/impersonate 7.0.41 → 7.0.43
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/README.md +12 -80
- package/lib/commonjs/impersonate/components/DataNukeSettings.js +8 -675
- package/lib/commonjs/impersonate/components/ImpersonateBanner.js +1 -221
- package/lib/commonjs/impersonate/components/ImpersonateHistoryList.js +1 -181
- package/lib/commonjs/impersonate/components/ImpersonateModal.js +1 -319
- package/lib/commonjs/impersonate/components/ImpersonateOverlay.js +1 -26
- package/lib/commonjs/impersonate/components/ImpersonateStatusBar.js +1 -130
- package/lib/commonjs/impersonate/components/UserAvatar.js +1 -146
- package/lib/commonjs/impersonate/components/UserCard.js +1 -201
- package/lib/commonjs/impersonate/components/UserSearchView.js +1 -227
- package/lib/commonjs/impersonate/hooks/asyncStoragePeer.js +1 -17
- package/lib/commonjs/impersonate/hooks/asyncStoragePeer.web.js +1 -11
- package/lib/commonjs/impersonate/hooks/useAutoClearAsyncStorage.js +1 -134
- package/lib/commonjs/impersonate/hooks/useAutoClearReactQuery.js +1 -155
- package/lib/commonjs/impersonate/hooks/useAutoClearReactQuery.web.js +1 -20
- package/lib/commonjs/impersonate/hooks/useAutoClearRedux.js +1 -188
- package/lib/commonjs/impersonate/hooks/useAutoClearRedux.web.js +1 -27
- package/lib/commonjs/impersonate/hooks/useImpersonate.js +1 -215
- package/lib/commonjs/impersonate/hooks/useImpersonateHistory.js +1 -56
- package/lib/commonjs/impersonate/types/index.js +1 -16
- package/lib/commonjs/impersonate/types/types.js +1 -1
- package/lib/commonjs/impersonate/utils/impersonateListener.js +1 -350
- package/lib/commonjs/impersonate/utils/impersonateStore.js +1 -689
- package/lib/commonjs/index.js +1 -150
- package/lib/commonjs/preset.js +1 -232
- package/lib/commonjs/sync/impersonateSyncAdapter.js +1 -170
- package/lib/module/impersonate/components/DataNukeSettings.js +8 -670
- package/lib/module/impersonate/components/ImpersonateBanner.js +1 -215
- package/lib/module/impersonate/components/ImpersonateHistoryList.js +1 -176
- package/lib/module/impersonate/components/ImpersonateModal.js +1 -314
- package/lib/module/impersonate/components/ImpersonateOverlay.js +1 -21
- package/lib/module/impersonate/components/ImpersonateStatusBar.js +1 -125
- package/lib/module/impersonate/components/UserAvatar.js +1 -140
- package/lib/module/impersonate/components/UserCard.js +1 -196
- package/lib/module/impersonate/components/UserSearchView.js +1 -222
- package/lib/module/impersonate/hooks/asyncStoragePeer.js +1 -13
- package/lib/module/impersonate/hooks/asyncStoragePeer.web.js +1 -6
- package/lib/module/impersonate/hooks/useAutoClearAsyncStorage.js +1 -130
- package/lib/module/impersonate/hooks/useAutoClearReactQuery.js +1 -151
- package/lib/module/impersonate/hooks/useAutoClearReactQuery.web.js +1 -16
- package/lib/module/impersonate/hooks/useAutoClearRedux.js +1 -183
- package/lib/module/impersonate/hooks/useAutoClearRedux.web.js +1 -22
- package/lib/module/impersonate/hooks/useImpersonate.js +1 -212
- package/lib/module/impersonate/hooks/useImpersonateHistory.js +1 -52
- package/lib/module/impersonate/types/index.js +1 -3
- package/lib/module/impersonate/types/types.js +1 -1
- package/lib/module/impersonate/utils/impersonateListener.js +1 -341
- package/lib/module/impersonate/utils/impersonateStore.js +1 -686
- package/lib/module/index.js +1 -117
- package/lib/module/preset.js +1 -216
- package/lib/module/sync/impersonateSyncAdapter.js +1 -162
- package/lib/web/index.mjs +7 -8
- package/package.json +3 -6
- package/lib/typescript/impersonate/components/DataNukeSettings.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/ImpersonateBanner.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/ImpersonateHistoryList.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/ImpersonateModal.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/ImpersonateOverlay.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/ImpersonateStatusBar.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/UserAvatar.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/UserCard.d.ts.map +0 -1
- package/lib/typescript/impersonate/components/UserSearchView.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/asyncStoragePeer.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/asyncStoragePeer.web.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useAutoClearAsyncStorage.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useAutoClearReactQuery.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useAutoClearReactQuery.web.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useAutoClearRedux.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useAutoClearRedux.web.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useImpersonate.d.ts.map +0 -1
- package/lib/typescript/impersonate/hooks/useImpersonateHistory.d.ts.map +0 -1
- package/lib/typescript/impersonate/types/index.d.ts.map +0 -1
- package/lib/typescript/impersonate/types/types.d.ts.map +0 -1
- package/lib/typescript/impersonate/utils/impersonateListener.d.ts.map +0 -1
- package/lib/typescript/impersonate/utils/impersonateStore.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/sync/impersonateSyncAdapter.d.ts.map +0 -1
|
@@ -1,155 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useAutoClearReactQuery = useAutoClearReactQuery;
|
|
7
|
-
exports.useReactQueryAvailability = useReactQueryAvailability;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
/**
|
|
10
|
-
* useAutoClearReactQuery Hook
|
|
11
|
-
*
|
|
12
|
-
* Auto-detects React Query and provides a clear function.
|
|
13
|
-
* Uses the same pattern as @buoy-gg/redux's useAutoInstrumentRedux.
|
|
14
|
-
*
|
|
15
|
-
* This hook:
|
|
16
|
-
* 1. Dynamically requires @tanstack/react-query
|
|
17
|
-
* 2. Uses useQueryClient() to get the client from context
|
|
18
|
-
* 3. Returns a clearCache function that clears queries + mutations
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// ============================================
|
|
22
|
-
// Types
|
|
23
|
-
// ============================================
|
|
24
|
-
|
|
25
|
-
// Flag to prevent double-firing (synchronous check)
|
|
26
|
-
let isClearing = false;
|
|
27
|
-
// ============================================
|
|
28
|
-
// Safe Module Loading
|
|
29
|
-
// ============================================
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Safely attempt to load @tanstack/react-query and get useQueryClient hook
|
|
33
|
-
*/
|
|
34
|
-
function getReactQueryUseQueryClient() {
|
|
35
|
-
try {
|
|
36
|
-
// Dynamic require to handle cases where react-query isn't installed
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
38
|
-
const reactQuery = require("@tanstack/react-query");
|
|
39
|
-
return reactQuery.useQueryClient;
|
|
40
|
-
} catch {
|
|
41
|
-
// @tanstack/react-query not available
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ============================================
|
|
47
|
-
// Main Hook
|
|
48
|
-
// ============================================
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Hook to auto-detect React Query and provide cache clearing functionality.
|
|
52
|
-
*
|
|
53
|
-
* This mirrors how the react-query package's QueryBrowserModal.tsx clears cache:
|
|
54
|
-
* `queryClient.getQueryCache().clear()`
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```tsx
|
|
58
|
-
* function MyComponent() {
|
|
59
|
-
* const { isAvailable, clearCache } = useAutoClearReactQuery();
|
|
60
|
-
*
|
|
61
|
-
* if (isAvailable && clearCache) {
|
|
62
|
-
* // Can clear React Query cache
|
|
63
|
-
* clearCache();
|
|
64
|
-
* }
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
function useAutoClearReactQuery() {
|
|
69
|
-
// Check if @tanstack/react-query is available
|
|
70
|
-
const useQueryClientHook = getReactQueryUseQueryClient();
|
|
71
|
-
const isReactQueryInstalled = useQueryClientHook !== null;
|
|
72
|
-
|
|
73
|
-
// Try to get the query client using react-query's useQueryClient
|
|
74
|
-
// This must be called unconditionally due to hooks rules
|
|
75
|
-
let queryClient = null;
|
|
76
|
-
let clientError = null;
|
|
77
|
-
if (useQueryClientHook) {
|
|
78
|
-
try {
|
|
79
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
80
|
-
queryClient = useQueryClientHook();
|
|
81
|
-
} catch (e) {
|
|
82
|
-
// Not inside a QueryClientProvider or other error
|
|
83
|
-
clientError = e instanceof Error ? e.message : "Failed to access QueryClient. Make sure your app is wrapped in a QueryClientProvider.";
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
clientError = "@tanstack/react-query is not installed";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Create the clearCache function with guard to prevent double-firing
|
|
90
|
-
const clearCache = (0, _react.useCallback)(() => {
|
|
91
|
-
// Synchronous guard - set flag immediately before any async work
|
|
92
|
-
if (isClearing) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
isClearing = true;
|
|
96
|
-
if (queryClient) {
|
|
97
|
-
// Clear both query and mutation caches
|
|
98
|
-
// This is the same approach used in @buoy-gg/react-query
|
|
99
|
-
queryClient.getQueryCache().clear();
|
|
100
|
-
queryClient.getMutationCache().clear();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Reset flag after a short delay to allow next legitimate call
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
isClearing = false;
|
|
106
|
-
}, 100);
|
|
107
|
-
}, [queryClient]);
|
|
108
|
-
|
|
109
|
-
// Memoize result
|
|
110
|
-
const result = (0, _react.useMemo)(() => {
|
|
111
|
-
if (!isReactQueryInstalled || clientError || !queryClient) {
|
|
112
|
-
return {
|
|
113
|
-
isAvailable: false,
|
|
114
|
-
error: clientError,
|
|
115
|
-
clearCache: null
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
isAvailable: true,
|
|
120
|
-
error: null,
|
|
121
|
-
clearCache
|
|
122
|
-
};
|
|
123
|
-
}, [isReactQueryInstalled, clientError, queryClient, clearCache]);
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Lightweight hook to just check if React Query is available
|
|
129
|
-
* without getting the client
|
|
130
|
-
*/
|
|
131
|
-
function useReactQueryAvailability() {
|
|
132
|
-
const useQueryClientHook = getReactQueryUseQueryClient();
|
|
133
|
-
if (!useQueryClientHook) {
|
|
134
|
-
return {
|
|
135
|
-
isInstalled: false,
|
|
136
|
-
isConnected: false,
|
|
137
|
-
error: "@tanstack/react-query is not installed"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
142
|
-
const client = useQueryClientHook();
|
|
143
|
-
return {
|
|
144
|
-
isInstalled: true,
|
|
145
|
-
isConnected: client !== null && client !== undefined,
|
|
146
|
-
error: null
|
|
147
|
-
};
|
|
148
|
-
} catch (e) {
|
|
149
|
-
return {
|
|
150
|
-
isInstalled: true,
|
|
151
|
-
isConnected: false,
|
|
152
|
-
error: e instanceof Error ? e.message : "Not inside a QueryClientProvider"
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useAutoClearReactQuery=useAutoClearReactQuery;exports.useReactQueryAvailability=useReactQueryAvailability;var _react=require("react");let isClearing=false;function getReactQueryUseQueryClient(){try{const e=require("@tanstack/react-query");return e.useQueryClient}catch{return null}}function useAutoClearReactQuery(){const e=getReactQueryUseQueryClient();const r=e!==null;let t=null;let l=null;if(e){try{t=e()}catch(n){l=n instanceof Error?n.message:"Failed to access QueryClient. Make sure your app is wrapped in a QueryClientProvider."}}else{l="@tanstack/react-query is not installed"}const a=(0,_react.useCallback)(()=>{if(isClearing){return}isClearing=true;if(t){t.getQueryCache().clear();t.getMutationCache().clear()}setTimeout(()=>{isClearing=false},100)},[t]);const u=(0,_react.useMemo)(()=>{if(!r||l||!t){return{isAvailable:false,error:l,clearCache:null}}return{isAvailable:true,error:null,clearCache:a}},[r,l,t,a]);return u}function useReactQueryAvailability(){const e=getReactQueryUseQueryClient();if(!e){return{isInstalled:false,isConnected:false,error:"@tanstack/react-query is not installed"}}try{const r=e();return{isInstalled:true,isConnected:r!==null&&r!==void 0,error:null}}catch(r){return{isInstalled:true,isConnected:false,error:r instanceof Error?r.message:"Not inside a QueryClientProvider"}}}
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useAutoClearReactQuery = useAutoClearReactQuery;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
9
|
-
function useAutoClearReactQuery() {
|
|
10
|
-
const available = Boolean((0, _sharedUi.getToolAdapters)().query);
|
|
11
|
-
const clearCache = (0, _react.useCallback)(async () => {
|
|
12
|
-
await (0, _sharedUi.dispatchToolAction)('query', 'clearQueryCache');
|
|
13
|
-
await (0, _sharedUi.dispatchToolAction)('query', 'clearMutationCache');
|
|
14
|
-
}, []);
|
|
15
|
-
return {
|
|
16
|
-
isAvailable: available,
|
|
17
|
-
error: available ? null : 'Connect React Query to Buoy or provide onClearReactQuery.',
|
|
18
|
-
clearCache: available ? clearCache : null
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useAutoClearReactQuery=useAutoClearReactQuery;var _react=require("react");var _sharedUi=require("@buoy-gg/shared-ui");function useAutoClearReactQuery(){const e=Boolean((0,_sharedUi.getToolAdapters)().query);const a=(0,_react.useCallback)(async()=>{await(0,_sharedUi.dispatchToolAction)("query","clearQueryCache");await(0,_sharedUi.dispatchToolAction)("query","clearMutationCache")},[]);return{isAvailable:e,error:e?null:"Connect React Query to Buoy or provide onClearReactQuery.",clearCache:e?a:null}}
|
|
@@ -1,188 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.REDUX_RESET_ACTION_TYPE = void 0;
|
|
7
|
-
exports.useAutoClearRedux = useAutoClearRedux;
|
|
8
|
-
exports.useReduxAvailability = useReduxAvailability;
|
|
9
|
-
var _react = require("react");
|
|
10
|
-
/**
|
|
11
|
-
* useAutoClearRedux Hook
|
|
12
|
-
*
|
|
13
|
-
* Auto-detects Redux store and provides a reset function.
|
|
14
|
-
* Uses the same pattern as @buoy-gg/redux's useAutoInstrumentRedux.
|
|
15
|
-
*
|
|
16
|
-
* This hook:
|
|
17
|
-
* 1. Dynamically requires react-redux
|
|
18
|
-
* 2. Uses useStore() to get the store from context
|
|
19
|
-
* 3. Returns a resetStore function that dispatches a reset action
|
|
20
|
-
*
|
|
21
|
-
* IMPORTANT: Unlike React Query which has a universal .clear() method,
|
|
22
|
-
* Redux reset requires the app's reducer to handle the reset action.
|
|
23
|
-
* The default action type is '@@RESET' but can be customized.
|
|
24
|
-
*
|
|
25
|
-
* Example reducer handling:
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const rootReducer = (state, action) => {
|
|
28
|
-
* if (action.type === '@@RESET') {
|
|
29
|
-
* return undefined; // Returns to initial state
|
|
30
|
-
* }
|
|
31
|
-
* return appReducer(state, action);
|
|
32
|
-
* };
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
// ============================================
|
|
37
|
-
// Types
|
|
38
|
-
// ============================================
|
|
39
|
-
|
|
40
|
-
// Flag to prevent double-firing (synchronous check)
|
|
41
|
-
let isDispatching = false;
|
|
42
|
-
|
|
43
|
-
/** The default action type dispatched to reset Redux state */
|
|
44
|
-
const REDUX_RESET_ACTION_TYPE = exports.REDUX_RESET_ACTION_TYPE = "@@RESET";
|
|
45
|
-
// ============================================
|
|
46
|
-
// Safe Module Loading
|
|
47
|
-
// ============================================
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Safely attempt to load react-redux and get useStore hook
|
|
51
|
-
*/
|
|
52
|
-
function getReactReduxUseStore() {
|
|
53
|
-
try {
|
|
54
|
-
// Dynamic require to handle cases where react-redux isn't installed
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
-
const reactRedux = require("react-redux");
|
|
57
|
-
return reactRedux.useStore;
|
|
58
|
-
} catch {
|
|
59
|
-
// react-redux not available
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ============================================
|
|
65
|
-
// Main Hook
|
|
66
|
-
// ============================================
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Hook to auto-detect Redux store and provide state reset functionality.
|
|
70
|
-
*
|
|
71
|
-
* This dispatches a reset action (default: '@@RESET') to the store.
|
|
72
|
-
* Your app's root reducer must handle this action to actually reset state.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```tsx
|
|
76
|
-
* // In your component:
|
|
77
|
-
* function MyComponent() {
|
|
78
|
-
* const { isAvailable, resetStore } = useAutoClearRedux();
|
|
79
|
-
*
|
|
80
|
-
* if (isAvailable && resetStore) {
|
|
81
|
-
* resetStore(); // Dispatches { type: '@@RESET' }
|
|
82
|
-
* }
|
|
83
|
-
* }
|
|
84
|
-
*
|
|
85
|
-
* // In your root reducer:
|
|
86
|
-
* const rootReducer = (state, action) => {
|
|
87
|
-
* if (action.type === '@@RESET') {
|
|
88
|
-
* // Return undefined to reset to initial state
|
|
89
|
-
* // Or return a specific "logged out" state
|
|
90
|
-
* return undefined;
|
|
91
|
-
* }
|
|
92
|
-
* return appReducer(state, action);
|
|
93
|
-
* };
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
function useAutoClearRedux(options = {}) {
|
|
97
|
-
const {
|
|
98
|
-
resetActionType = REDUX_RESET_ACTION_TYPE
|
|
99
|
-
} = options;
|
|
100
|
-
|
|
101
|
-
// Check if react-redux is available
|
|
102
|
-
const useStoreHook = getReactReduxUseStore();
|
|
103
|
-
const isReactReduxInstalled = useStoreHook !== null;
|
|
104
|
-
|
|
105
|
-
// Try to get the store using react-redux's useStore
|
|
106
|
-
// This must be called unconditionally due to hooks rules
|
|
107
|
-
let store = null;
|
|
108
|
-
let storeError = null;
|
|
109
|
-
if (useStoreHook) {
|
|
110
|
-
try {
|
|
111
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
112
|
-
store = useStoreHook();
|
|
113
|
-
} catch (e) {
|
|
114
|
-
// Not inside a Provider or other error
|
|
115
|
-
storeError = e instanceof Error ? e.message : "Failed to access Redux store. Make sure your app is wrapped in a Redux Provider.";
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
storeError = "react-redux is not installed";
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Create the resetStore function with guard to prevent double-firing
|
|
122
|
-
const resetStore = (0, _react.useCallback)(() => {
|
|
123
|
-
// Synchronous guard - set flag immediately before any async work
|
|
124
|
-
if (isDispatching) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
isDispatching = true;
|
|
128
|
-
if (store) {
|
|
129
|
-
// Dispatch the reset action
|
|
130
|
-
// The app's root reducer must handle this to actually reset state
|
|
131
|
-
store.dispatch({
|
|
132
|
-
type: resetActionType
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Reset flag after a short delay to allow next legitimate call
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
isDispatching = false;
|
|
139
|
-
}, 100);
|
|
140
|
-
}, [store, resetActionType]);
|
|
141
|
-
|
|
142
|
-
// Memoize result
|
|
143
|
-
const result = (0, _react.useMemo)(() => {
|
|
144
|
-
if (!isReactReduxInstalled || storeError || !store) {
|
|
145
|
-
return {
|
|
146
|
-
isAvailable: false,
|
|
147
|
-
error: storeError,
|
|
148
|
-
resetStore: null
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
isAvailable: true,
|
|
153
|
-
error: null,
|
|
154
|
-
resetStore
|
|
155
|
-
};
|
|
156
|
-
}, [isReactReduxInstalled, storeError, store, resetStore]);
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Lightweight hook to just check if Redux is available
|
|
162
|
-
* without getting the store
|
|
163
|
-
*/
|
|
164
|
-
function useReduxAvailability() {
|
|
165
|
-
const useStoreHook = getReactReduxUseStore();
|
|
166
|
-
if (!useStoreHook) {
|
|
167
|
-
return {
|
|
168
|
-
isInstalled: false,
|
|
169
|
-
isConnected: false,
|
|
170
|
-
error: "react-redux is not installed"
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
175
|
-
const store = useStoreHook();
|
|
176
|
-
return {
|
|
177
|
-
isInstalled: true,
|
|
178
|
-
isConnected: store !== null && store !== undefined,
|
|
179
|
-
error: null
|
|
180
|
-
};
|
|
181
|
-
} catch (e) {
|
|
182
|
-
return {
|
|
183
|
-
isInstalled: true,
|
|
184
|
-
isConnected: false,
|
|
185
|
-
error: e instanceof Error ? e.message : "Not inside a Redux Provider"
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.REDUX_RESET_ACTION_TYPE=void 0;exports.useAutoClearRedux=useAutoClearRedux;exports.useReduxAvailability=useReduxAvailability;var _react=require("react");let isDispatching=false;const REDUX_RESET_ACTION_TYPE=exports.REDUX_RESET_ACTION_TYPE="@@RESET";function getReactReduxUseStore(){try{const r=require("react-redux");return r.useStore}catch{return null}}function useAutoClearRedux(r={}){const{resetActionType:e=REDUX_RESET_ACTION_TYPE}=r;const o=getReactReduxUseStore();const u=o!==null;let t=null;let s=null;if(o){try{t=o()}catch(l){s=l instanceof Error?l.message:"Failed to access Redux store. Make sure your app is wrapped in a Redux Provider."}}else{s="react-redux is not installed"}const n=(0,_react.useCallback)(()=>{if(isDispatching){return}isDispatching=true;if(t){t.dispatch({type:e})}setTimeout(()=>{isDispatching=false},100)},[t,e]);const a=(0,_react.useMemo)(()=>{if(!u||s||!t){return{isAvailable:false,error:s,resetStore:null}}return{isAvailable:true,error:null,resetStore:n}},[u,s,t,n]);return a}function useReduxAvailability(){const r=getReactReduxUseStore();if(!r){return{isInstalled:false,isConnected:false,error:"react-redux is not installed"}}try{const e=r();return{isInstalled:true,isConnected:e!==null&&e!==void 0,error:null}}catch(e){return{isInstalled:true,isConnected:false,error:e instanceof Error?e.message:"Not inside a Redux Provider"}}}
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.REDUX_RESET_ACTION_TYPE = void 0;
|
|
7
|
-
exports.useAutoClearRedux = useAutoClearRedux;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
10
|
-
const REDUX_RESET_ACTION_TYPE = exports.REDUX_RESET_ACTION_TYPE = '@@RESET';
|
|
11
|
-
function useAutoClearRedux({
|
|
12
|
-
resetActionType = REDUX_RESET_ACTION_TYPE
|
|
13
|
-
} = {}) {
|
|
14
|
-
const available = Boolean((0, _sharedUi.getToolAdapters)().redux);
|
|
15
|
-
const resetStore = (0, _react.useCallback)(async () => {
|
|
16
|
-
await (0, _sharedUi.dispatchToolAction)('redux', 'dispatch', {
|
|
17
|
-
action: {
|
|
18
|
-
type: resetActionType
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}, [resetActionType]);
|
|
22
|
-
return {
|
|
23
|
-
isAvailable: available,
|
|
24
|
-
error: available ? null : 'Connect Redux to Buoy or provide onClearRedux.',
|
|
25
|
-
resetStore: available ? resetStore : null
|
|
26
|
-
};
|
|
27
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.REDUX_RESET_ACTION_TYPE=void 0;exports.useAutoClearRedux=useAutoClearRedux;var _react=require("react");var _sharedUi=require("@buoy-gg/shared-ui");const REDUX_RESET_ACTION_TYPE=exports.REDUX_RESET_ACTION_TYPE="@@RESET";function useAutoClearRedux({resetActionType:r=REDUX_RESET_ACTION_TYPE}={}){const e=Boolean((0,_sharedUi.getToolAdapters)().redux);const o=(0,_react.useCallback)(async()=>{await(0,_sharedUi.dispatchToolAction)("redux","dispatch",{action:{type:r}})},[r]);return{isAvailable:e,error:e?null:"Connect Redux to Buoy or provide onClearRedux.",resetStore:e?o:null}}
|
|
@@ -1,215 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useImpersonate = useImpersonate;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _impersonateStore = require("../utils/impersonateStore");
|
|
9
|
-
var _impersonateListener = require("../utils/impersonateListener");
|
|
10
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /**
|
|
11
|
-
* useImpersonate Hook
|
|
12
|
-
*
|
|
13
|
-
* Main hook for managing impersonation state and actions.
|
|
14
|
-
* Provides all the controls needed to search users, start/stop
|
|
15
|
-
* impersonation, and manage settings.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Hook for managing impersonation
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* function ImpersonatePanel() {
|
|
23
|
-
* const {
|
|
24
|
-
* isActive,
|
|
25
|
-
* currentUser,
|
|
26
|
-
* searchUsers,
|
|
27
|
-
* searchResults,
|
|
28
|
-
* startImpersonation,
|
|
29
|
-
* stopImpersonation,
|
|
30
|
-
* } = useImpersonate({
|
|
31
|
-
* onSearchUsers: async (query) => api.searchUsers(query),
|
|
32
|
-
* onClearReactQuery: () => queryClient.clear(),
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* return (
|
|
36
|
-
* <View>
|
|
37
|
-
* {isActive ? (
|
|
38
|
-
* <Text>Impersonating: {currentUser?.email}</Text>
|
|
39
|
-
* ) : (
|
|
40
|
-
* <Text>Not impersonating</Text>
|
|
41
|
-
* )}
|
|
42
|
-
* </View>
|
|
43
|
-
* );
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
function useImpersonate(options = {}) {
|
|
48
|
-
const [searchQuery, setSearchQuery] = (0, _react.useState)("");
|
|
49
|
-
const [searchResults, setSearchResults] = (0, _react.useState)([]);
|
|
50
|
-
const [isSearching, setIsSearching] = (0, _react.useState)(false);
|
|
51
|
-
const [searchError, setSearchError] = (0, _react.useState)(null);
|
|
52
|
-
|
|
53
|
-
// Subscribe to store state using useSyncExternalStore
|
|
54
|
-
const state = (0, _react.useSyncExternalStore)(_impersonateStore.impersonateStore.subscribe, _impersonateStore.impersonateStore.getSnapshot, _impersonateStore.impersonateStore.getSnapshot // Server snapshot (same for SSR)
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// Register nuke callbacks when they change
|
|
58
|
-
(0, _react.useEffect)(() => {
|
|
59
|
-
_impersonateStore.impersonateStore.registerNukeCallbacks({
|
|
60
|
-
reactQuery: options.onClearReactQuery,
|
|
61
|
-
redux: options.onClearRedux,
|
|
62
|
-
asyncStorage: options.onClearAsyncStorage,
|
|
63
|
-
mmkv: options.onClearMMKV
|
|
64
|
-
});
|
|
65
|
-
}, [options.onClearReactQuery, options.onClearRedux, options.onClearAsyncStorage, options.onClearMMKV]);
|
|
66
|
-
|
|
67
|
-
// Set up AsyncStorage reference immediately for writes, then load persisted state
|
|
68
|
-
(0, _react.useEffect)(() => {
|
|
69
|
-
let isMounted = true;
|
|
70
|
-
const setupAsyncStorage = async () => {
|
|
71
|
-
try {
|
|
72
|
-
// Dynamically import AsyncStorage
|
|
73
|
-
const AsyncStorage = await Promise.resolve().then(() => _interopRequireWildcard(require("@react-native-async-storage/async-storage"))).then(m => m.default);
|
|
74
|
-
const storageAdapter = {
|
|
75
|
-
getItem: key => AsyncStorage.getItem(key),
|
|
76
|
-
setItem: (key, value) => AsyncStorage.setItem(key, value)
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// Set storage reference FIRST so writes work immediately
|
|
80
|
-
_impersonateStore.impersonateStore.setAsyncStorage(storageAdapter);
|
|
81
|
-
|
|
82
|
-
// Then load persisted state
|
|
83
|
-
if (isMounted) {
|
|
84
|
-
await _impersonateStore.impersonateStore.initializeAsync(storageAdapter);
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// AsyncStorage not available - using localStorage fallback (web)
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
setupAsyncStorage();
|
|
91
|
-
|
|
92
|
-
// Start listener
|
|
93
|
-
if (!(0, _impersonateListener.impersonateListener)().isListening) {
|
|
94
|
-
(0, _impersonateListener.impersonateListener)().startListening();
|
|
95
|
-
}
|
|
96
|
-
return () => {
|
|
97
|
-
isMounted = false;
|
|
98
|
-
};
|
|
99
|
-
// Don't stop listener on unmount - headers should keep being injected
|
|
100
|
-
}, []);
|
|
101
|
-
|
|
102
|
-
// Search users
|
|
103
|
-
const searchUsers = (0, _react.useCallback)(async query => {
|
|
104
|
-
setSearchQuery(query);
|
|
105
|
-
setSearchError(null);
|
|
106
|
-
if (!query.trim()) {
|
|
107
|
-
setSearchResults([]);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (!options.onSearchUsers) {
|
|
111
|
-
setSearchError("Search not configured");
|
|
112
|
-
setSearchResults([]);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
setIsSearching(true);
|
|
116
|
-
try {
|
|
117
|
-
const results = await options.onSearchUsers(query);
|
|
118
|
-
setSearchResults(results);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
setSearchError(error instanceof Error ? error.message : "Search failed");
|
|
121
|
-
setSearchResults([]);
|
|
122
|
-
} finally {
|
|
123
|
-
setIsSearching(false);
|
|
124
|
-
}
|
|
125
|
-
}, [options.onSearchUsers]);
|
|
126
|
-
|
|
127
|
-
// Clear search
|
|
128
|
-
const clearSearch = (0, _react.useCallback)(() => {
|
|
129
|
-
setSearchQuery("");
|
|
130
|
-
setSearchResults([]);
|
|
131
|
-
setSearchError(null);
|
|
132
|
-
}, []);
|
|
133
|
-
|
|
134
|
-
// Start impersonation
|
|
135
|
-
const startImpersonation = (0, _react.useCallback)(async user => {
|
|
136
|
-
await _impersonateStore.impersonateStore.startImpersonation(user);
|
|
137
|
-
}, []);
|
|
138
|
-
|
|
139
|
-
// Stop impersonation
|
|
140
|
-
const stopImpersonation = (0, _react.useCallback)(async () => {
|
|
141
|
-
await _impersonateStore.impersonateStore.stopImpersonation();
|
|
142
|
-
}, []);
|
|
143
|
-
|
|
144
|
-
// Quick switch
|
|
145
|
-
const quickSwitch = (0, _react.useCallback)(async user => {
|
|
146
|
-
await _impersonateStore.impersonateStore.quickSwitch(user);
|
|
147
|
-
}, []);
|
|
148
|
-
|
|
149
|
-
// Update header key
|
|
150
|
-
const updateHeaderKey = (0, _react.useCallback)(async key => {
|
|
151
|
-
await _impersonateStore.impersonateStore.updateSettings({
|
|
152
|
-
headerKey: key
|
|
153
|
-
});
|
|
154
|
-
}, []);
|
|
155
|
-
|
|
156
|
-
// Update ignore patterns
|
|
157
|
-
const updateIgnorePatterns = (0, _react.useCallback)(async patterns => {
|
|
158
|
-
await _impersonateStore.impersonateStore.updateSettings({
|
|
159
|
-
ignorePatterns: patterns
|
|
160
|
-
});
|
|
161
|
-
}, []);
|
|
162
|
-
|
|
163
|
-
// Update data nuke settings
|
|
164
|
-
const updateDataNukeSettings = (0, _react.useCallback)(async settings => {
|
|
165
|
-
await _impersonateStore.impersonateStore.updateSettings({
|
|
166
|
-
dataNukeSettings: settings
|
|
167
|
-
});
|
|
168
|
-
}, []);
|
|
169
|
-
|
|
170
|
-
// Update show banner
|
|
171
|
-
const updateShowBanner = (0, _react.useCallback)(async show => {
|
|
172
|
-
await _impersonateStore.impersonateStore.updateSettings({
|
|
173
|
-
showBanner: show
|
|
174
|
-
});
|
|
175
|
-
}, []);
|
|
176
|
-
|
|
177
|
-
// Remove from history
|
|
178
|
-
const removeFromHistory = (0, _react.useCallback)(async userId => {
|
|
179
|
-
await _impersonateStore.impersonateStore.removeFromHistory(userId);
|
|
180
|
-
}, []);
|
|
181
|
-
|
|
182
|
-
// Clear history
|
|
183
|
-
const clearHistory = (0, _react.useCallback)(async () => {
|
|
184
|
-
await _impersonateStore.impersonateStore.clearHistory();
|
|
185
|
-
}, []);
|
|
186
|
-
return {
|
|
187
|
-
// State
|
|
188
|
-
isActive: state.isActive,
|
|
189
|
-
currentUser: state.currentUser,
|
|
190
|
-
headerKey: state.headerKey,
|
|
191
|
-
ignorePatterns: state.ignorePatterns,
|
|
192
|
-
dataNukeSettings: state.dataNukeSettings,
|
|
193
|
-
showBanner: state.showBanner,
|
|
194
|
-
history: state.history,
|
|
195
|
-
// Search
|
|
196
|
-
searchQuery,
|
|
197
|
-
searchResults,
|
|
198
|
-
isSearching,
|
|
199
|
-
searchError,
|
|
200
|
-
searchUsers,
|
|
201
|
-
clearSearch,
|
|
202
|
-
// Actions
|
|
203
|
-
startImpersonation,
|
|
204
|
-
stopImpersonation,
|
|
205
|
-
quickSwitch,
|
|
206
|
-
// Settings
|
|
207
|
-
updateHeaderKey,
|
|
208
|
-
updateIgnorePatterns,
|
|
209
|
-
updateDataNukeSettings,
|
|
210
|
-
updateShowBanner,
|
|
211
|
-
// History
|
|
212
|
-
removeFromHistory,
|
|
213
|
-
clearHistory
|
|
214
|
-
};
|
|
215
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useImpersonate=useImpersonate;var _react=require("react");var _impersonateStore=require("../utils/impersonateStore");var _impersonateListener=require("../utils/impersonateListener");function _interopRequireWildcard(a,S){if("function"==typeof WeakMap)var u=new WeakMap,p=new WeakMap;return(_interopRequireWildcard=function(e,l){if(!l&&e&&e.__esModule)return e;var n,o,s={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return s;if(n=l?p:u){if(n.has(e))return n.get(e);n.set(e,s)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((o=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(o.get||o.set)?n(s,r,o):s[r]=e[r]);return s})(a,S)}function useImpersonate(a={}){const[S,u]=(0,_react.useState)("");const[p,e]=(0,_react.useState)([]);const[l,n]=(0,_react.useState)(false);const[o,s]=(0,_react.useState)(null);const r=(0,_react.useSyncExternalStore)(_impersonateStore.impersonateStore.subscribe,_impersonateStore.impersonateStore.getSnapshot,_impersonateStore.impersonateStore.getSnapshot);(0,_react.useEffect)(()=>{_impersonateStore.impersonateStore.registerNukeCallbacks({reactQuery:a.onClearReactQuery,redux:a.onClearRedux,asyncStorage:a.onClearAsyncStorage,mmkv:a.onClearMMKV})},[a.onClearReactQuery,a.onClearRedux,a.onClearAsyncStorage,a.onClearMMKV]);(0,_react.useEffect)(()=>{let t=true;const c=async()=>{try{const y=await Promise.resolve().then(()=>_interopRequireWildcard(require("@react-native-async-storage/async-storage"))).then(i=>i.default);const m={getItem:i=>y.getItem(i),setItem:(i,M)=>y.setItem(i,M)};_impersonateStore.impersonateStore.setAsyncStorage(m);if(t){await _impersonateStore.impersonateStore.initializeAsync(m)}}catch{}};c();if(!(0,_impersonateListener.impersonateListener)().isListening){(0,_impersonateListener.impersonateListener)().startListening()}return()=>{t=false}},[]);const f=(0,_react.useCallback)(async t=>{u(t);s(null);if(!t.trim()){e([]);return}if(!a.onSearchUsers){s("Search not configured");e([]);return}n(true);try{const c=await a.onSearchUsers(t);e(c)}catch(c){s(c instanceof Error?c.message:"Search failed");e([])}finally{n(false)}},[a.onSearchUsers]);const g=(0,_react.useCallback)(()=>{u("");e([]);s(null)},[]);const h=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.startImpersonation(t)},[]);const d=(0,_react.useCallback)(async()=>{await _impersonateStore.impersonateStore.stopImpersonation()},[]);const k=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.quickSwitch(t)},[]);const w=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.updateSettings({headerKey:t})},[]);const C=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.updateSettings({ignorePatterns:t})},[]);const b=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.updateSettings({dataNukeSettings:t})},[]);const v=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.updateSettings({showBanner:t})},[]);const I=(0,_react.useCallback)(async t=>{await _impersonateStore.impersonateStore.removeFromHistory(t)},[]);const _=(0,_react.useCallback)(async()=>{await _impersonateStore.impersonateStore.clearHistory()},[]);return{isActive:r.isActive,currentUser:r.currentUser,headerKey:r.headerKey,ignorePatterns:r.ignorePatterns,dataNukeSettings:r.dataNukeSettings,showBanner:r.showBanner,history:r.history,searchQuery:S,searchResults:p,isSearching:l,searchError:o,searchUsers:f,clearSearch:g,startImpersonation:h,stopImpersonation:d,quickSwitch:k,updateHeaderKey:w,updateIgnorePatterns:C,updateDataNukeSettings:b,updateShowBanner:v,removeFromHistory:I,clearHistory:_}}
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useImpersonateHistory = useImpersonateHistory;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _impersonateStore = require("../utils/impersonateStore");
|
|
9
|
-
/**
|
|
10
|
-
* useImpersonateHistory Hook
|
|
11
|
-
*
|
|
12
|
-
* Specialized hook for working with impersonation history.
|
|
13
|
-
* Use this when you only need history functionality.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Hook for managing impersonation history
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* function HistoryList() {
|
|
22
|
-
* const { history, currentUserId, quickSwitch } = useImpersonateHistory();
|
|
23
|
-
*
|
|
24
|
-
* return (
|
|
25
|
-
* <FlatList
|
|
26
|
-
* data={history}
|
|
27
|
-
* renderItem={({ item }) => (
|
|
28
|
-
* <TouchableOpacity onPress={() => quickSwitch(item)}>
|
|
29
|
-
* <Text>{item.email}</Text>
|
|
30
|
-
* {currentUserId === item.id && <Badge>Active</Badge>}
|
|
31
|
-
* </TouchableOpacity>
|
|
32
|
-
* )}
|
|
33
|
-
* />
|
|
34
|
-
* );
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
function useImpersonateHistory() {
|
|
39
|
-
const state = (0, _react.useSyncExternalStore)(_impersonateStore.impersonateStore.subscribe, _impersonateStore.impersonateStore.getSnapshot, _impersonateStore.impersonateStore.getSnapshot);
|
|
40
|
-
const quickSwitch = (0, _react.useCallback)(async user => {
|
|
41
|
-
await _impersonateStore.impersonateStore.quickSwitch(user);
|
|
42
|
-
}, []);
|
|
43
|
-
const removeFromHistory = (0, _react.useCallback)(async userId => {
|
|
44
|
-
await _impersonateStore.impersonateStore.removeFromHistory(userId);
|
|
45
|
-
}, []);
|
|
46
|
-
const clearHistory = (0, _react.useCallback)(async () => {
|
|
47
|
-
await _impersonateStore.impersonateStore.clearHistory();
|
|
48
|
-
}, []);
|
|
49
|
-
return {
|
|
50
|
-
history: state.history,
|
|
51
|
-
currentUserId: state.currentUser?.id ?? null,
|
|
52
|
-
quickSwitch,
|
|
53
|
-
removeFromHistory,
|
|
54
|
-
clearHistory
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useImpersonateHistory=useImpersonateHistory;var _react=require("react");var _impersonateStore=require("../utils/impersonateStore");function useImpersonateHistory(){const r=(0,_react.useSyncExternalStore)(_impersonateStore.impersonateStore.subscribe,_impersonateStore.impersonateStore.getSnapshot,_impersonateStore.impersonateStore.getSnapshot);const t=(0,_react.useCallback)(async e=>{await _impersonateStore.impersonateStore.quickSwitch(e)},[]);const s=(0,_react.useCallback)(async e=>{await _impersonateStore.impersonateStore.removeFromHistory(e)},[]);const o=(0,_react.useCallback)(async()=>{await _impersonateStore.impersonateStore.clearHistory()},[]);return{history:r.history,currentUserId:r.currentUser?.id??null,quickSwitch:t,removeFromHistory:s,clearHistory:o}}
|