@buoy-gg/impersonate 1.0.3-beta.0
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/LICENSE +58 -0
- package/lib/commonjs/impersonate/components/DataNukeSettings.js +715 -0
- package/lib/commonjs/impersonate/components/ImpersonateBanner.js +217 -0
- package/lib/commonjs/impersonate/components/ImpersonateHistoryList.js +173 -0
- package/lib/commonjs/impersonate/components/ImpersonateModal.js +304 -0
- package/lib/commonjs/impersonate/components/ImpersonateStatusBar.js +130 -0
- package/lib/commonjs/impersonate/components/UserAvatar.js +146 -0
- package/lib/commonjs/impersonate/components/UserCard.js +200 -0
- package/lib/commonjs/impersonate/components/UserSearchView.js +227 -0
- package/lib/commonjs/impersonate/components/index.js +85 -0
- package/lib/commonjs/impersonate/hooks/index.js +64 -0
- package/lib/commonjs/impersonate/hooks/useAutoClearAsyncStorage.js +144 -0
- package/lib/commonjs/impersonate/hooks/useAutoClearReactQuery.js +155 -0
- package/lib/commonjs/impersonate/hooks/useAutoClearRedux.js +188 -0
- package/lib/commonjs/impersonate/hooks/useImpersonate.js +215 -0
- package/lib/commonjs/impersonate/hooks/useImpersonateHistory.js +56 -0
- package/lib/commonjs/impersonate/index.js +49 -0
- package/lib/commonjs/impersonate/types/index.js +16 -0
- package/lib/commonjs/impersonate/types/types.js +1 -0
- package/lib/commonjs/impersonate/utils/impersonateListener.js +280 -0
- package/lib/commonjs/impersonate/utils/impersonateStore.js +607 -0
- package/lib/commonjs/impersonate/utils/index.js +49 -0
- package/lib/commonjs/index.js +118 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/preset.js +214 -0
- package/lib/module/impersonate/components/DataNukeSettings.js +710 -0
- package/lib/module/impersonate/components/ImpersonateBanner.js +211 -0
- package/lib/module/impersonate/components/ImpersonateHistoryList.js +168 -0
- package/lib/module/impersonate/components/ImpersonateModal.js +300 -0
- package/lib/module/impersonate/components/ImpersonateStatusBar.js +125 -0
- package/lib/module/impersonate/components/UserAvatar.js +140 -0
- package/lib/module/impersonate/components/UserCard.js +195 -0
- package/lib/module/impersonate/components/UserSearchView.js +222 -0
- package/lib/module/impersonate/components/index.js +11 -0
- package/lib/module/impersonate/hooks/index.js +7 -0
- package/lib/module/impersonate/hooks/useAutoClearAsyncStorage.js +140 -0
- package/lib/module/impersonate/hooks/useAutoClearReactQuery.js +151 -0
- package/lib/module/impersonate/hooks/useAutoClearRedux.js +183 -0
- package/lib/module/impersonate/hooks/useImpersonate.js +212 -0
- package/lib/module/impersonate/hooks/useImpersonateHistory.js +52 -0
- package/lib/module/impersonate/index.js +13 -0
- package/lib/module/impersonate/types/index.js +3 -0
- package/lib/module/impersonate/types/types.js +1 -0
- package/lib/module/impersonate/utils/impersonateListener.js +271 -0
- package/lib/module/impersonate/utils/impersonateStore.js +604 -0
- package/lib/module/impersonate/utils/index.js +4 -0
- package/lib/module/index.js +103 -0
- package/lib/module/preset.js +209 -0
- package/lib/typescript/impersonate/components/DataNukeSettings.d.ts +37 -0
- package/lib/typescript/impersonate/components/DataNukeSettings.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/ImpersonateBanner.d.ts +40 -0
- package/lib/typescript/impersonate/components/ImpersonateBanner.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/ImpersonateHistoryList.d.ts +24 -0
- package/lib/typescript/impersonate/components/ImpersonateHistoryList.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/ImpersonateModal.d.ts +10 -0
- package/lib/typescript/impersonate/components/ImpersonateModal.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/ImpersonateStatusBar.d.ts +15 -0
- package/lib/typescript/impersonate/components/ImpersonateStatusBar.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/UserAvatar.d.ts +32 -0
- package/lib/typescript/impersonate/components/UserAvatar.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/UserCard.d.ts +28 -0
- package/lib/typescript/impersonate/components/UserCard.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/UserSearchView.d.ts +31 -0
- package/lib/typescript/impersonate/components/UserSearchView.d.ts.map +1 -0
- package/lib/typescript/impersonate/components/index.d.ts +16 -0
- package/lib/typescript/impersonate/components/index.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/index.d.ts +11 -0
- package/lib/typescript/impersonate/hooks/index.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/useAutoClearAsyncStorage.d.ts +48 -0
- package/lib/typescript/impersonate/hooks/useAutoClearAsyncStorage.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/useAutoClearReactQuery.d.ts +48 -0
- package/lib/typescript/impersonate/hooks/useAutoClearReactQuery.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/useAutoClearRedux.d.ts +78 -0
- package/lib/typescript/impersonate/hooks/useAutoClearRedux.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/useImpersonate.d.ts +76 -0
- package/lib/typescript/impersonate/hooks/useImpersonate.d.ts.map +1 -0
- package/lib/typescript/impersonate/hooks/useImpersonateHistory.d.ts +43 -0
- package/lib/typescript/impersonate/hooks/useImpersonateHistory.d.ts.map +1 -0
- package/lib/typescript/impersonate/index.d.ts +5 -0
- package/lib/typescript/impersonate/index.d.ts.map +1 -0
- package/lib/typescript/impersonate/types/index.d.ts +2 -0
- package/lib/typescript/impersonate/types/index.d.ts.map +1 -0
- package/lib/typescript/impersonate/types/types.d.ts +177 -0
- package/lib/typescript/impersonate/types/types.d.ts.map +1 -0
- package/lib/typescript/impersonate/utils/impersonateListener.d.ts +115 -0
- package/lib/typescript/impersonate/utils/impersonateListener.d.ts.map +1 -0
- package/lib/typescript/impersonate/utils/impersonateStore.d.ts +151 -0
- package/lib/typescript/impersonate/utils/impersonateStore.d.ts.map +1 -0
- package/lib/typescript/impersonate/utils/index.d.ts +3 -0
- package/lib/typescript/impersonate/utils/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +80 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts +71 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Impersonate Store - State Management with Persistence
|
|
3
|
+
*
|
|
4
|
+
* Singleton store for managing impersonation state. Uses a subscription
|
|
5
|
+
* pattern compatible with React's useSyncExternalStore.
|
|
6
|
+
*/
|
|
7
|
+
import type { User, DataNukeSettings, ImpersonationState, ImpersonateDefaults } from "../types";
|
|
8
|
+
type StateListener = (state: ImpersonationState) => void;
|
|
9
|
+
interface NukeCallbacks {
|
|
10
|
+
reactQuery?: () => void | Promise<void>;
|
|
11
|
+
redux?: () => void | Promise<void>;
|
|
12
|
+
asyncStorage?: () => void | Promise<void>;
|
|
13
|
+
mmkv?: () => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Singleton store for impersonation state
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Subscription pattern for React integration
|
|
20
|
+
* - Persistence of settings and history
|
|
21
|
+
* - Data nuking on impersonation change
|
|
22
|
+
* - Automatic sync with impersonateListener
|
|
23
|
+
*/
|
|
24
|
+
declare class ImpersonateStore {
|
|
25
|
+
private state;
|
|
26
|
+
private listeners;
|
|
27
|
+
private nukeCallbacks;
|
|
28
|
+
private isInitialized;
|
|
29
|
+
private asyncStorageRef;
|
|
30
|
+
private storageReadyPromise;
|
|
31
|
+
private resolveStorageReady;
|
|
32
|
+
private developerDefaults;
|
|
33
|
+
constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Load persisted state from storage (sync)
|
|
36
|
+
*/
|
|
37
|
+
private loadFromStorage;
|
|
38
|
+
/**
|
|
39
|
+
* Set async storage reference for persistence (call before initializeAsync)
|
|
40
|
+
* This ensures all writes use AsyncStorage even before load completes
|
|
41
|
+
*/
|
|
42
|
+
setAsyncStorage(asyncStorage: {
|
|
43
|
+
getItem: (key: string) => Promise<string | null>;
|
|
44
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
45
|
+
}): void;
|
|
46
|
+
/**
|
|
47
|
+
* Set developer-provided defaults
|
|
48
|
+
* These override hardcoded defaults but are overridden by persisted values
|
|
49
|
+
* Call this before the component mounts (in createImpersonateTool)
|
|
50
|
+
*/
|
|
51
|
+
setDeveloperDefaults(defaults: ImpersonateDefaults): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get effective defaults (developer defaults merged with hardcoded defaults)
|
|
54
|
+
*/
|
|
55
|
+
private getEffectiveDefaults;
|
|
56
|
+
/**
|
|
57
|
+
* Get developer defaults (for use in UI to show what the "default" values are)
|
|
58
|
+
*/
|
|
59
|
+
getDeveloperDefaults(): ImpersonateDefaults | null;
|
|
60
|
+
/**
|
|
61
|
+
* Initialize with async storage (for React Native)
|
|
62
|
+
* Call this in useEffect to load from AsyncStorage
|
|
63
|
+
*/
|
|
64
|
+
initializeAsync(asyncStorage?: {
|
|
65
|
+
getItem: (key: string) => Promise<string | null>;
|
|
66
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Register callbacks for data nuking
|
|
70
|
+
*/
|
|
71
|
+
registerNukeCallbacks(callbacks: NukeCallbacks): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get current state (creates a copy)
|
|
74
|
+
*/
|
|
75
|
+
getState(): ImpersonationState;
|
|
76
|
+
/**
|
|
77
|
+
* Get snapshot for useSyncExternalStore
|
|
78
|
+
* Returns the same reference if state hasn't changed
|
|
79
|
+
*/
|
|
80
|
+
getSnapshot: () => ImpersonationState;
|
|
81
|
+
/**
|
|
82
|
+
* Subscribe to state changes
|
|
83
|
+
* Returns unsubscribe function
|
|
84
|
+
*/
|
|
85
|
+
subscribe: (listener: StateListener) => (() => void);
|
|
86
|
+
/**
|
|
87
|
+
* Start impersonating a user
|
|
88
|
+
*
|
|
89
|
+
* This will:
|
|
90
|
+
* 1. Execute data nuking based on settings
|
|
91
|
+
* 2. Update state with new user
|
|
92
|
+
* 3. Add to history
|
|
93
|
+
* 4. Sync with impersonateListener
|
|
94
|
+
* 5. Persist settings
|
|
95
|
+
*/
|
|
96
|
+
startImpersonation(user: User): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Stop impersonating
|
|
99
|
+
*
|
|
100
|
+
* This will:
|
|
101
|
+
* 1. Execute data nuking based on settings
|
|
102
|
+
* 2. Clear impersonation state
|
|
103
|
+
* 3. Sync with impersonateListener
|
|
104
|
+
*/
|
|
105
|
+
stopImpersonation(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Pause impersonation (temporarily stop injecting headers)
|
|
108
|
+
*/
|
|
109
|
+
pauseImpersonation(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Resume impersonation (start injecting headers again)
|
|
112
|
+
*/
|
|
113
|
+
resumeImpersonation(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Quick switch to a user from history
|
|
116
|
+
*/
|
|
117
|
+
quickSwitch(user: User): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Update settings (header key, ignore patterns, data nuke settings, show banner)
|
|
120
|
+
*/
|
|
121
|
+
updateSettings(settings: Partial<Pick<ImpersonationState, "headerKey" | "ignorePatterns" | "showBanner"> & {
|
|
122
|
+
dataNukeSettings?: Partial<DataNukeSettings>;
|
|
123
|
+
}>): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Remove a user from history
|
|
126
|
+
*/
|
|
127
|
+
removeFromHistory(userId: string): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Clear all history
|
|
130
|
+
*/
|
|
131
|
+
clearHistory(): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Execute data nuking based on current settings
|
|
134
|
+
*/
|
|
135
|
+
private executeDataNuke;
|
|
136
|
+
/**
|
|
137
|
+
* Sync current state with the impersonateListener
|
|
138
|
+
*/
|
|
139
|
+
private syncWithListener;
|
|
140
|
+
/**
|
|
141
|
+
* Persist state to storage
|
|
142
|
+
*/
|
|
143
|
+
private persist;
|
|
144
|
+
/**
|
|
145
|
+
* Notify all listeners of state change
|
|
146
|
+
*/
|
|
147
|
+
private notify;
|
|
148
|
+
}
|
|
149
|
+
export declare const impersonateStore: ImpersonateStore;
|
|
150
|
+
export {};
|
|
151
|
+
//# sourceMappingURL=impersonateStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impersonateStore.d.ts","sourceRoot":"","sources":["../../../../src/impersonate/utils/impersonateStore.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/impersonate/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @buoy-gg/impersonate
|
|
3
|
+
*
|
|
4
|
+
* User impersonation tool for React Native DevTools.
|
|
5
|
+
* Injects custom headers into fetch/XHR requests when impersonating.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { createImpersonateTool } from '@buoy-gg/impersonate';
|
|
10
|
+
*
|
|
11
|
+
* const impersonateTool = createImpersonateTool({
|
|
12
|
+
* onSearchUsers: async (query) => {
|
|
13
|
+
* const res = await api.searchUsers(query);
|
|
14
|
+
* return res.users;
|
|
15
|
+
* },
|
|
16
|
+
* onClearReactQuery: () => queryClient.clear(),
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* <FloatingDevTools apps={[impersonateTool]} />
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { createImpersonateTool } from "./preset";
|
|
23
|
+
export { ImpersonateModal } from "./impersonate/components/ImpersonateModal";
|
|
24
|
+
export { ImpersonateBanner, ImpersonateBannerMinimal, } from "./impersonate/components/ImpersonateBanner";
|
|
25
|
+
export { UserSearchView } from "./impersonate/components/UserSearchView";
|
|
26
|
+
export { DataNukeSettings as DataNukeSettingsComponent } from "./impersonate/components/DataNukeSettings";
|
|
27
|
+
export { ImpersonateHistoryList } from "./impersonate/components/ImpersonateHistoryList";
|
|
28
|
+
export { ImpersonateStatusBar } from "./impersonate/components/ImpersonateStatusBar";
|
|
29
|
+
export { useImpersonate } from "./impersonate/hooks/useImpersonate";
|
|
30
|
+
export type { UseImpersonateOptions, UseImpersonateReturn, } from "./impersonate/hooks/useImpersonate";
|
|
31
|
+
export { useImpersonateHistory } from "./impersonate/hooks/useImpersonateHistory";
|
|
32
|
+
export type { UseImpersonateHistoryReturn } from "./impersonate/hooks/useImpersonateHistory";
|
|
33
|
+
export type { User, DataNukeSettings as DataNukeSettingsType, ImpersonationState, ImpersonateToolConfig, ImpersonateModalProps, ImpersonateBannerProps, ImpersonateListenerConfig, } from "./impersonate/types";
|
|
34
|
+
/**
|
|
35
|
+
* Direct access to the impersonation store singleton.
|
|
36
|
+
* Use this for custom integrations or debugging.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { impersonateStore } from '@buoy-gg/impersonate';
|
|
41
|
+
*
|
|
42
|
+
* // Check if impersonating
|
|
43
|
+
* const state = impersonateStore.getState();
|
|
44
|
+
* if (state.isActive) {
|
|
45
|
+
* console.log('Impersonating:', state.currentUser?.email);
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // Subscribe to changes
|
|
49
|
+
* const unsubscribe = impersonateStore.subscribe((state) => {
|
|
50
|
+
* console.log('Impersonation state changed:', state);
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export { impersonateStore } from "./impersonate/utils/impersonateStore";
|
|
55
|
+
/**
|
|
56
|
+
* Direct access to the impersonate listener for advanced control.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import {
|
|
61
|
+
* impersonateListener,
|
|
62
|
+
* startImpersonateListener,
|
|
63
|
+
* setImpersonateConfig,
|
|
64
|
+
* } from '@buoy-gg/impersonate';
|
|
65
|
+
*
|
|
66
|
+
* // Manually start the listener
|
|
67
|
+
* startImpersonateListener();
|
|
68
|
+
*
|
|
69
|
+
* // Configure impersonation
|
|
70
|
+
* setImpersonateConfig({
|
|
71
|
+
* headerKey: 'x-custom-impersonate-header',
|
|
72
|
+
* userId: 'user_123',
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Check status
|
|
76
|
+
* console.log('Listener active:', impersonateListener().isListening);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export { impersonateListener, startImpersonateListener, stopImpersonateListener, setImpersonateConfig, isImpersonating, getImpersonatedUserId, } from "./impersonate/utils/impersonateListener";
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAMjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,gBAAgB,IAAI,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC1G,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AAMrF,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,YAAY,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAM7F,YAAY,EACV,IAAI,EACJ,gBAAgB,IAAI,oBAAoB,EACxC,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAM7B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACtB,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Impersonate Tool Preset
|
|
3
|
+
*
|
|
4
|
+
* Factory function to create a configured impersonate tool for FloatingDevTools.
|
|
5
|
+
* No default preset is exported because configuration (onSearchUsers) is required.
|
|
6
|
+
*/
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { ImpersonateBanner } from "./impersonate/components/ImpersonateBanner";
|
|
9
|
+
import type { ImpersonateToolConfig } from "./impersonate/types";
|
|
10
|
+
/**
|
|
11
|
+
* Create an impersonate tool with custom configuration
|
|
12
|
+
*
|
|
13
|
+
* The tool automatically displays a floating banner when impersonation is active.
|
|
14
|
+
* This can be toggled in the Settings tab or via developer defaults.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { createImpersonateTool } from '@buoy-gg/impersonate';
|
|
19
|
+
* import { queryClient } from './queryClient';
|
|
20
|
+
*
|
|
21
|
+
* const impersonateTool = createImpersonateTool({
|
|
22
|
+
* onSearchUsers: async (query) => {
|
|
23
|
+
* const response = await api.searchUsers({ email: query });
|
|
24
|
+
* return response.users.map(u => ({
|
|
25
|
+
* id: u.id,
|
|
26
|
+
* displayName: u.name,
|
|
27
|
+
* email: u.email,
|
|
28
|
+
* metadata: { role: u.role, createdAt: u.createdAt }
|
|
29
|
+
* }));
|
|
30
|
+
* },
|
|
31
|
+
* onClearReactQuery: () => queryClient.clear(),
|
|
32
|
+
* onClearRedux: () => store.dispatch({ type: 'RESET' }),
|
|
33
|
+
*
|
|
34
|
+
* // Optional: Developer defaults (override hardcoded, overridden by persisted)
|
|
35
|
+
* defaults: {
|
|
36
|
+
* headerKey: 'x-admin-impersonate',
|
|
37
|
+
* showBanner: true, // Show floating banner when impersonating
|
|
38
|
+
* dataNukeSettings: {
|
|
39
|
+
* reactQuery: true,
|
|
40
|
+
* redux: false,
|
|
41
|
+
* },
|
|
42
|
+
* },
|
|
43
|
+
*
|
|
44
|
+
* // Optional: Hide settings tab for simple testing
|
|
45
|
+
* showSettingsTab: true,
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // In your app - banner is automatic, no extra setup needed!
|
|
49
|
+
* <FloatingDevTools apps={[impersonateTool]} />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createImpersonateTool(config: ImpersonateToolConfig): {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
slot: "both";
|
|
57
|
+
icon: ({ size }: {
|
|
58
|
+
size: number;
|
|
59
|
+
}) => React.JSX.Element;
|
|
60
|
+
component: (props: {
|
|
61
|
+
visible: boolean;
|
|
62
|
+
onClose: () => void;
|
|
63
|
+
onBack?: () => void;
|
|
64
|
+
onMinimize?: (state: unknown) => void;
|
|
65
|
+
}) => React.JSX.Element;
|
|
66
|
+
props: {
|
|
67
|
+
enableSharedModalDimensions: boolean;
|
|
68
|
+
};
|
|
69
|
+
Banner: typeof ImpersonateBanner;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=preset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/preset.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,OAAO,KAAK,EAAE,qBAAqB,EAAyB,MAAM,qBAAqB,CAAC;AA+FxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB;;;;;qBAyB9C;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;uBAGd;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;KAAE;;;;;EAmB3H"}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@buoy-gg/impersonate",
|
|
3
|
+
"version": "1.0.3-beta.0",
|
|
4
|
+
"description": "User impersonation tool for Buoy DevTools - inject custom headers for admin testing",
|
|
5
|
+
"main": "lib/commonjs/index.js",
|
|
6
|
+
"module": "lib/module/index.js",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "lib/module/index.js",
|
|
9
|
+
"source": "src/index.tsx",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"react-native": "./lib/module/index.js",
|
|
13
|
+
"import": {
|
|
14
|
+
"default": "./lib/module/index.js",
|
|
15
|
+
"types": "./lib/typescript/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"default": "./lib/commonjs/index.js",
|
|
19
|
+
"types": "./lib/typescript/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib"
|
|
26
|
+
],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@buoy-gg/shared-ui": "2.1.4-beta.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "*",
|
|
33
|
+
"react-native": "*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^19.1.0",
|
|
37
|
+
"@types/react-native": "^0.73.0",
|
|
38
|
+
"typescript": "~5.8.3"
|
|
39
|
+
},
|
|
40
|
+
"react-native-builder-bob": {
|
|
41
|
+
"source": "src",
|
|
42
|
+
"output": "lib",
|
|
43
|
+
"targets": [
|
|
44
|
+
[
|
|
45
|
+
"commonjs",
|
|
46
|
+
{
|
|
47
|
+
"sourceMaps": false
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
"module",
|
|
52
|
+
{
|
|
53
|
+
"sourceMaps": false
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"typescript"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/LovesWorking/react-native-buoy.git",
|
|
62
|
+
"directory": "packages/impersonate"
|
|
63
|
+
},
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/LovesWorking/react-native-buoy/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/LovesWorking/react-native-buoy/tree/main/packages/impersonate#readme",
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public",
|
|
70
|
+
"tag": "latest"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "bob build",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"clean": "rimraf lib",
|
|
76
|
+
"test": "pnpm run typecheck"
|
|
77
|
+
}
|
|
78
|
+
}
|