@spooky-sync/client-solid 0.0.1-canary.262 → 0.0.1-canary.264
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/AGENTS.md +1 -1
- package/dist/index.cjs +13 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +16 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +15 -1
- package/src/lib/use-impersonation.ts +16 -2
package/src/index.ts
CHANGED
|
@@ -46,7 +46,11 @@ export { useQuery } from './lib/use-query';
|
|
|
46
46
|
export { createPreload } from './lib/create-preload';
|
|
47
47
|
export type { PreloadOptions, PreloadRefresh } from '@spooky-sync/core';
|
|
48
48
|
export { useSyncStatus, type UseSyncStatus } from './lib/use-sync-status';
|
|
49
|
-
export {
|
|
49
|
+
export {
|
|
50
|
+
useImpersonation,
|
|
51
|
+
type UseImpersonation,
|
|
52
|
+
type UseImpersonationOptions,
|
|
53
|
+
} from './lib/use-impersonation';
|
|
50
54
|
export type {
|
|
51
55
|
SyncHealth,
|
|
52
56
|
SyncHealthStatus,
|
|
@@ -286,6 +290,16 @@ export class SyncedDb<S extends SchemaStructure> {
|
|
|
286
290
|
await this.signOut();
|
|
287
291
|
}
|
|
288
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Tell the client that this app's own impersonation banner is on screen.
|
|
295
|
+
* Only needed with `impersonationBanner: { mode: 'custom' }`; the
|
|
296
|
+
* `useImpersonation({ rendersBanner: true })` hook calls it for you.
|
|
297
|
+
*/
|
|
298
|
+
public acknowledgeImpersonationBanner(): void {
|
|
299
|
+
if (!this.sp00ky) throw new Error('SyncedDb not initialized');
|
|
300
|
+
this.sp00ky.acknowledgeImpersonationBanner();
|
|
301
|
+
}
|
|
302
|
+
|
|
289
303
|
/**
|
|
290
304
|
* Sign out, clear session and local storage
|
|
291
305
|
*/
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { createSignal, onCleanup, type Accessor } from 'solid-js';
|
|
1
|
+
import { createEffect, createSignal, onCleanup, type Accessor } from 'solid-js';
|
|
2
2
|
import { useDb } from './context';
|
|
3
3
|
import type { ImpersonationInfo } from '@spooky-sync/core';
|
|
4
4
|
|
|
5
|
+
export interface UseImpersonationOptions {
|
|
6
|
+
/**
|
|
7
|
+
* This component renders the app's own impersonation banner. Required with
|
|
8
|
+
* `impersonationBanner: { mode: 'custom' }`: it acknowledges the banner, so
|
|
9
|
+
* the client does not fall back to its built-in one.
|
|
10
|
+
*/
|
|
11
|
+
rendersBanner?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
export interface UseImpersonation {
|
|
6
15
|
/** The active impersonation, or `null`. */
|
|
7
16
|
impersonation: Accessor<ImpersonationInfo | null>;
|
|
@@ -16,12 +25,17 @@ export interface UseImpersonation {
|
|
|
16
25
|
* such as hiding actions an admin should not take on someone's behalf.
|
|
17
26
|
* Must be used within a `<Sp00kyProvider>`.
|
|
18
27
|
*/
|
|
19
|
-
export function useImpersonation(): UseImpersonation {
|
|
28
|
+
export function useImpersonation(options: UseImpersonationOptions = {}): UseImpersonation {
|
|
20
29
|
const db = useDb();
|
|
21
30
|
const [impersonation, setImpersonation] = createSignal<ImpersonationInfo | null>(
|
|
22
31
|
db.auth.impersonation
|
|
23
32
|
);
|
|
24
33
|
onCleanup(db.auth.subscribeImpersonation(setImpersonation));
|
|
34
|
+
// Re-acknowledged per session: a new impersonation restarts the client's
|
|
35
|
+
// fallback timer, and this component is what cancels it.
|
|
36
|
+
createEffect(() => {
|
|
37
|
+
if (options.rendersBanner && impersonation()) db.acknowledgeImpersonationBanner();
|
|
38
|
+
});
|
|
25
39
|
return {
|
|
26
40
|
impersonation,
|
|
27
41
|
isImpersonating: () => impersonation() !== null,
|