@pol-studios/db 1.0.33 → 1.0.35
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/dist/UserMetadataContext-QLIv-mfF.d.ts +171 -0
- package/dist/auth/context.d.ts +52 -4
- package/dist/auth/context.js +26 -1
- package/dist/auth/hooks.d.ts +107 -3
- package/dist/auth/hooks.js +9 -2
- package/dist/auth/index.d.ts +5 -5
- package/dist/auth/index.js +40 -9
- package/dist/chunk-5HJLTYRA.js +355 -0
- package/dist/chunk-5HJLTYRA.js.map +1 -0
- package/dist/chunk-6KN7KLEG.js +1 -0
- package/dist/{chunk-PNC6CG5U.js → chunk-7NFMEDJW.js} +42 -9
- package/dist/chunk-7NFMEDJW.js.map +1 -0
- package/dist/{chunk-4EJ6LUH7.js → chunk-HFIGNQ7T.js} +6 -4
- package/dist/{chunk-4EJ6LUH7.js.map → chunk-HFIGNQ7T.js.map} +1 -1
- package/dist/{chunk-3XCW225W.js → chunk-NP34C3O3.js} +53 -256
- package/dist/chunk-NP34C3O3.js.map +1 -0
- package/dist/{chunk-E64B4PJZ.js → chunk-QHXN6BNL.js} +3 -3
- package/dist/{chunk-OUCPYEKC.js → chunk-U4BZKCBH.js} +4 -4
- package/dist/chunk-UBHORKBS.js +215 -0
- package/dist/chunk-UBHORKBS.js.map +1 -0
- package/dist/{chunk-E6JL3RUF.js → chunk-YQUNORJD.js} +176 -85
- package/dist/chunk-YQUNORJD.js.map +1 -0
- package/dist/hooks/index.js +9 -7
- package/dist/index.js +18 -15
- package/dist/index.native.js +18 -15
- package/dist/index.web.js +13 -10
- package/dist/index.web.js.map +1 -1
- package/dist/with-auth/index.js +7 -5
- package/dist/with-auth/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/UserMetadataContext-yLZQu24J.d.ts +0 -33
- package/dist/chunk-3XCW225W.js.map +0 -1
- package/dist/chunk-E6JL3RUF.js.map +0 -1
- package/dist/chunk-NSIAAYW3.js +0 -1
- package/dist/chunk-PNC6CG5U.js.map +0 -1
- /package/dist/{chunk-NSIAAYW3.js.map → chunk-6KN7KLEG.js.map} +0 -0
- /package/dist/{chunk-E64B4PJZ.js.map → chunk-QHXN6BNL.js.map} +0 -0
- /package/dist/{chunk-OUCPYEKC.js.map → chunk-U4BZKCBH.js.map} +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { User } from '@supabase/supabase-js';
|
|
5
|
+
import { D as Database } from './useSupabase-DSZNeXnF.js';
|
|
6
|
+
|
|
7
|
+
type ProfileStatus = "active" | "archived" | "suspended";
|
|
8
|
+
interface SimpleProfile {
|
|
9
|
+
id: string;
|
|
10
|
+
email?: string | null;
|
|
11
|
+
firstName?: string | null;
|
|
12
|
+
lastName?: string | null;
|
|
13
|
+
fullName?: string | null;
|
|
14
|
+
status?: ProfileStatus | null;
|
|
15
|
+
profilePath?: string | null;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface SimpleUserAccess {
|
|
19
|
+
id: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
accessKey: string;
|
|
22
|
+
}
|
|
23
|
+
interface SimpleAuthContextValue {
|
|
24
|
+
/** Supabase user (from auth session) */
|
|
25
|
+
user: User | null;
|
|
26
|
+
/** Profile from PowerSync (local SQLite) */
|
|
27
|
+
profile: SimpleProfile | null;
|
|
28
|
+
/** Access keys from PowerSync (local SQLite) */
|
|
29
|
+
accessKeys: string[];
|
|
30
|
+
/** Whether auth data is loading */
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
/** Whether profile is archived */
|
|
33
|
+
isArchived: boolean;
|
|
34
|
+
/** Whether profile is suspended */
|
|
35
|
+
isSuspended: boolean;
|
|
36
|
+
/** Profile status */
|
|
37
|
+
profileStatus: ProfileStatus | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Check if user has access to a resource.
|
|
40
|
+
* Supports wildcards: *:*:*, project:*:read, project:123:*
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* hasAccess("admin") // exact match
|
|
44
|
+
* hasAccess("project:123:read") // check specific resource
|
|
45
|
+
*/
|
|
46
|
+
hasAccess: (accessKey: string) => boolean;
|
|
47
|
+
/** Sign out the user */
|
|
48
|
+
signOut: () => Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Maps permission action strings to numeric levels for comparison.
|
|
52
|
+
* Higher numbers grant more access.
|
|
53
|
+
*/
|
|
54
|
+
declare function getPermissionLevel(action: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a user has at least the required permission level for a resource.
|
|
57
|
+
* Checks all matching access keys and returns true if any grants sufficient access.
|
|
58
|
+
*
|
|
59
|
+
* @param accessKeys - User's access keys
|
|
60
|
+
* @param resourceType - e.g., "project", "client", "database"
|
|
61
|
+
* @param resourceId - The ID of the resource
|
|
62
|
+
* @param requiredAction - e.g., "read", "edit", "admin"
|
|
63
|
+
*/
|
|
64
|
+
declare function hasResourceAccess(accessKeys: string[], resourceType: string, resourceId: string, requiredAction: string): boolean;
|
|
65
|
+
interface SimpleAuthProviderProps {
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
/** Supabase user from auth session */
|
|
68
|
+
user: User | null;
|
|
69
|
+
/** Profile from PowerSync query */
|
|
70
|
+
profile: SimpleProfile | null;
|
|
71
|
+
/** User access records from PowerSync query */
|
|
72
|
+
userAccess: SimpleUserAccess[] | null;
|
|
73
|
+
/** Whether the data is loading */
|
|
74
|
+
isLoading?: boolean;
|
|
75
|
+
/** Sign out function */
|
|
76
|
+
onSignOut: () => Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
declare function SimpleAuthProvider({ children, user, profile, userAccess, isLoading, onSignOut, }: SimpleAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
79
|
+
/**
|
|
80
|
+
* Hook to access auth state and hasAccess function.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* function MyComponent() {
|
|
85
|
+
* const { user, profile, hasAccess, isLoading } = useSimpleAuth();
|
|
86
|
+
*
|
|
87
|
+
* if (isLoading) return <Loading />;
|
|
88
|
+
* if (!user) return <Login />;
|
|
89
|
+
*
|
|
90
|
+
* // Check simple access
|
|
91
|
+
* if (hasAccess("admin")) {
|
|
92
|
+
* return <AdminPanel />;
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* // Check resource access
|
|
96
|
+
* if (hasAccess("project:123:edit")) {
|
|
97
|
+
* return <Editor />;
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* return <ReadOnlyView />;
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function useSimpleAuth(): SimpleAuthContextValue;
|
|
105
|
+
/**
|
|
106
|
+
* Hook that requires authentication.
|
|
107
|
+
* Throws if user is not authenticated.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* function ProtectedComponent() {
|
|
112
|
+
* const { user, hasAccess } = useRequireAuth();
|
|
113
|
+
* // user is guaranteed to be non-null here
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function useRequireAuth(): SimpleAuthContextValue & {
|
|
118
|
+
user: User;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Hook to check resource-level access with permission levels.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* function ProjectEditor({ projectId }: { projectId: string }) {
|
|
126
|
+
* const canEdit = useResourceAccess("project", projectId, "edit");
|
|
127
|
+
* const canDelete = useResourceAccess("project", projectId, "admin");
|
|
128
|
+
*
|
|
129
|
+
* return (
|
|
130
|
+
* <div>
|
|
131
|
+
* <button disabled={!canEdit}>Edit</button>
|
|
132
|
+
* <button disabled={!canDelete}>Delete</button>
|
|
133
|
+
* </div>
|
|
134
|
+
* );
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function useResourceAccess(resourceType: string, resourceId: string | number | undefined, requiredAction: string): boolean;
|
|
139
|
+
declare function useCanView(resourceType: string, resourceId: string | number | undefined): boolean;
|
|
140
|
+
declare function useCanEdit(resourceType: string, resourceId: string | number | undefined): boolean;
|
|
141
|
+
declare function useCanDelete(resourceType: string, resourceId: string | number | undefined): boolean;
|
|
142
|
+
declare function useCanShare(resourceType: string, resourceId: string | number | undefined): boolean;
|
|
143
|
+
|
|
144
|
+
type UserMetadataRow = Database["core"]["Tables"]["UserMetadata"]["Row"];
|
|
145
|
+
type UserMetadataInsert = Database["core"]["Tables"]["UserMetadata"]["Insert"];
|
|
146
|
+
type UserMetadataUpdate = Database["core"]["Tables"]["UserMetadata"]["Update"];
|
|
147
|
+
interface UserMetadataContextType {
|
|
148
|
+
metadata: Record<string, string>;
|
|
149
|
+
isLoading: boolean;
|
|
150
|
+
error: Error | null;
|
|
151
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
152
|
+
getMetadata: (key: string) => string | undefined;
|
|
153
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
154
|
+
refreshMetadata: () => Promise<void>;
|
|
155
|
+
}
|
|
156
|
+
declare const userMetadataContext: react.Context<UserMetadataContextType>;
|
|
157
|
+
declare function UserMetadataProvider({ children }: {
|
|
158
|
+
children: ReactNode;
|
|
159
|
+
}): react_jsx_runtime.JSX.Element;
|
|
160
|
+
declare function useUserMetadata(): UserMetadataContextType;
|
|
161
|
+
declare function useUserMetadataValue(key: string): string | undefined;
|
|
162
|
+
declare function useSetUserMetadata(): {
|
|
163
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
164
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
165
|
+
};
|
|
166
|
+
declare function useUserMetadataState<T>(key: string, defaultValue: T, options?: {
|
|
167
|
+
serialize?: (value: T) => string;
|
|
168
|
+
deserialize?: (value: string) => T;
|
|
169
|
+
}): [T, (value: T) => Promise<void>, boolean];
|
|
170
|
+
|
|
171
|
+
export { type ProfileStatus as P, SimpleAuthProvider as S, type UserMetadataContextType as U, useRequireAuth as a, useResourceAccess as b, useCanView as c, useCanEdit as d, useCanDelete as e, useCanShare as f, getPermissionLevel as g, hasResourceAccess as h, type SimpleAuthProviderProps as i, type SimpleAuthContextValue as j, type SimpleProfile as k, type SimpleUserAccess as l, useSetUserMetadata as m, useUserMetadata as n, useUserMetadataState as o, useUserMetadataValue as p, userMetadataContext as q, type UserMetadataInsert as r, UserMetadataProvider as s, type UserMetadataRow as t, useSimpleAuth as u, type UserMetadataUpdate as v };
|
package/dist/auth/context.d.ts
CHANGED
|
@@ -1,13 +1,61 @@
|
|
|
1
|
-
export { P as
|
|
1
|
+
export { j as SimpleAuthContextValue, S as SimpleAuthProvider, i as SimpleAuthProviderProps, k as SimpleProfile, P as SimpleProfileStatus, l as SimpleUserAccess, U as UserMetadataContextType, r as UserMetadataInsert, s as UserMetadataProvider, t as UserMetadataRow, v as UserMetadataUpdate, g as getPermissionLevel, h as hasResourceAccess, a as useRequireAuth, b as useResourceAccess, m as useSetUserMetadata, u as useSimpleAuth, e as useSimpleCanDelete, d as useSimpleCanEdit, f as useSimpleCanShare, c as useSimpleCanView, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue, q as userMetadataContext } from '../UserMetadataContext-QLIv-mfF.js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
+
import { User } from '@supabase/supabase-js';
|
|
6
|
+
export { P as Profile, a as ProfileStatus, S as SetupAuthContext, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-B76nbIP6.js';
|
|
5
7
|
import { d as EntityType, b as EntityPermissionCheck, a as EntityAction } from '../EntityPermissions-DwFt4tUd.js';
|
|
6
|
-
export { U as UserMetadataContextType, e as UserMetadataInsert, f as UserMetadataProvider, g as UserMetadataRow, h as UserMetadataUpdate, u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue, d as userMetadataContext } from '../UserMetadataContext-yLZQu24J.js';
|
|
7
|
-
import '@supabase/supabase-js';
|
|
8
8
|
import '../useSupabase-DSZNeXnF.js';
|
|
9
9
|
import '@supabase/supabase-js/dist/module/lib/types.js';
|
|
10
10
|
|
|
11
|
+
interface PowerSyncDB {
|
|
12
|
+
getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
|
|
13
|
+
getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
|
|
14
|
+
watch: (sql: string, params: any[], options: {
|
|
15
|
+
onResult: (result: any) => void;
|
|
16
|
+
}, abortOptions?: {
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
interface SupabaseClient {
|
|
21
|
+
auth: {
|
|
22
|
+
getUser: () => Promise<{
|
|
23
|
+
data: {
|
|
24
|
+
user: User | null;
|
|
25
|
+
};
|
|
26
|
+
error: any;
|
|
27
|
+
}>;
|
|
28
|
+
getSession: () => Promise<{
|
|
29
|
+
data: {
|
|
30
|
+
session: {
|
|
31
|
+
user: User;
|
|
32
|
+
} | null;
|
|
33
|
+
};
|
|
34
|
+
error: any;
|
|
35
|
+
}>;
|
|
36
|
+
signOut: () => Promise<{
|
|
37
|
+
error: any;
|
|
38
|
+
}>;
|
|
39
|
+
onAuthStateChange: (callback: (event: string, session: any) => void) => {
|
|
40
|
+
data: {
|
|
41
|
+
subscription: {
|
|
42
|
+
unsubscribe: () => void;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
interface OfflineAuthProviderProps {
|
|
49
|
+
children: ReactNode;
|
|
50
|
+
/** PowerSync database instance */
|
|
51
|
+
db: PowerSyncDB | null;
|
|
52
|
+
/** Supabase client for auth */
|
|
53
|
+
supabase: SupabaseClient;
|
|
54
|
+
/** Whether PowerSync is ready */
|
|
55
|
+
isDbReady?: boolean;
|
|
56
|
+
}
|
|
57
|
+
declare function OfflineAuthProvider({ children, db, supabase, isDbReady, }: OfflineAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
58
|
+
|
|
11
59
|
interface AuthProviderProps {
|
|
12
60
|
children: ReactNode;
|
|
13
61
|
/**
|
|
@@ -45,4 +93,4 @@ declare function PermissionProvider({ children }: {
|
|
|
45
93
|
}): react_jsx_runtime.JSX.Element;
|
|
46
94
|
declare function usePermissions(): PermissionContextValue;
|
|
47
95
|
|
|
48
|
-
export { AuthProvider, type AuthProviderProps, type EntityPermissionContextValue, type PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions };
|
|
96
|
+
export { AuthProvider, type AuthProviderProps, type EntityPermissionContextValue, OfflineAuthProvider, type OfflineAuthProviderProps, type PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions };
|
package/dist/auth/context.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OfflineAuthProvider,
|
|
3
|
+
SimpleAuthProvider,
|
|
4
|
+
getPermissionLevel,
|
|
5
|
+
hasResourceAccess,
|
|
6
|
+
useCanDelete,
|
|
7
|
+
useCanEdit,
|
|
8
|
+
useCanShare,
|
|
9
|
+
useCanView,
|
|
10
|
+
useRequireAuth,
|
|
11
|
+
useResourceAccess,
|
|
12
|
+
useSimpleAuth
|
|
13
|
+
} from "../chunk-5HJLTYRA.js";
|
|
1
14
|
import {
|
|
2
15
|
AuthProvider,
|
|
3
16
|
PermissionProvider,
|
|
@@ -11,7 +24,8 @@ import {
|
|
|
11
24
|
useUserMetadataState,
|
|
12
25
|
useUserMetadataValue,
|
|
13
26
|
userMetadataContext
|
|
14
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-YQUNORJD.js";
|
|
28
|
+
import "../chunk-UBHORKBS.js";
|
|
15
29
|
import "../chunk-J4ZVCXZ4.js";
|
|
16
30
|
import "../chunk-YUX6RGLZ.js";
|
|
17
31
|
import "../chunk-AKIRHA4Q.js";
|
|
@@ -19,13 +33,24 @@ import "../chunk-DMVUEJG2.js";
|
|
|
19
33
|
import "../chunk-7D4SUZUM.js";
|
|
20
34
|
export {
|
|
21
35
|
AuthProvider,
|
|
36
|
+
OfflineAuthProvider,
|
|
22
37
|
PermissionProvider,
|
|
38
|
+
SimpleAuthProvider,
|
|
23
39
|
UserMetadataProvider,
|
|
24
40
|
entityPermissionContext,
|
|
41
|
+
getPermissionLevel,
|
|
42
|
+
hasResourceAccess,
|
|
25
43
|
permissionContext,
|
|
26
44
|
setupAuthContext,
|
|
27
45
|
usePermissions,
|
|
46
|
+
useRequireAuth,
|
|
47
|
+
useResourceAccess,
|
|
28
48
|
useSetUserMetadata,
|
|
49
|
+
useSimpleAuth,
|
|
50
|
+
useCanDelete as useSimpleCanDelete,
|
|
51
|
+
useCanEdit as useSimpleCanEdit,
|
|
52
|
+
useCanShare as useSimpleCanShare,
|
|
53
|
+
useCanView as useSimpleCanView,
|
|
29
54
|
useUserMetadata,
|
|
30
55
|
useUserMetadataState,
|
|
31
56
|
useUserMetadataValue,
|
package/dist/auth/hooks.d.ts
CHANGED
|
@@ -1,12 +1,116 @@
|
|
|
1
1
|
import { User } from '@supabase/supabase-js';
|
|
2
|
+
import { k as SimpleProfile, l as SimpleUserAccess } from '../UserMetadataContext-QLIv-mfF.js';
|
|
3
|
+
export { m as useSetUserMetadata, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue } from '../UserMetadataContext-QLIv-mfF.js';
|
|
2
4
|
import { S as SetupAuthContext, E as EffectivePermission } from '../setupAuthContext-B76nbIP6.js';
|
|
3
5
|
import { d as EntityType, a as EntityAction, b as EntityPermissionCheck } from '../EntityPermissions-DwFt4tUd.js';
|
|
4
|
-
export { u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue } from '../UserMetadataContext-yLZQu24J.js';
|
|
5
|
-
import 'react';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
|
+
import 'react';
|
|
7
8
|
import '../useSupabase-DSZNeXnF.js';
|
|
8
9
|
import '@supabase/supabase-js/dist/module/lib/types.js';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* useOfflineAuth - Hook for offline-first authentication
|
|
13
|
+
*
|
|
14
|
+
* Reads Profile and UserAccess from PowerSync (local SQLite).
|
|
15
|
+
* Works 100% offline once data is synced.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { SimpleAuthProvider } from "@pol-studios/db";
|
|
20
|
+
* import { useOfflineAuth } from "@pol-studios/db";
|
|
21
|
+
*
|
|
22
|
+
* function AuthWrapper({ children }) {
|
|
23
|
+
* const authData = useOfflineAuth();
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <SimpleAuthProvider {...authData}>
|
|
27
|
+
* {children}
|
|
28
|
+
* </SimpleAuthProvider>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface OfflineAuthData {
|
|
35
|
+
/** Supabase user from auth session */
|
|
36
|
+
user: User | null;
|
|
37
|
+
/** Profile from PowerSync */
|
|
38
|
+
profile: SimpleProfile | null;
|
|
39
|
+
/** User access records from PowerSync */
|
|
40
|
+
userAccess: SimpleUserAccess[] | null;
|
|
41
|
+
/** Whether auth data is loading */
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
/** Sign out function */
|
|
44
|
+
onSignOut: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
interface UseOfflineAuthOptions {
|
|
47
|
+
/** Supabase client for auth operations */
|
|
48
|
+
supabase: {
|
|
49
|
+
auth: {
|
|
50
|
+
getUser: () => Promise<{
|
|
51
|
+
data: {
|
|
52
|
+
user: User | null;
|
|
53
|
+
};
|
|
54
|
+
error: any;
|
|
55
|
+
}>;
|
|
56
|
+
signOut: () => Promise<{
|
|
57
|
+
error: any;
|
|
58
|
+
}>;
|
|
59
|
+
onAuthStateChange: (callback: (event: string, session: any) => void) => {
|
|
60
|
+
data: {
|
|
61
|
+
subscription: {
|
|
62
|
+
unsubscribe: () => void;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/** PowerSync database for local queries */
|
|
69
|
+
db: {
|
|
70
|
+
getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
|
|
71
|
+
getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
|
|
72
|
+
} | null;
|
|
73
|
+
/** Whether PowerSync is ready */
|
|
74
|
+
isDbReady?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Query keys for React Query integration
|
|
78
|
+
*/
|
|
79
|
+
declare const offlineAuthQueryKeys: {
|
|
80
|
+
profile: (userId: string | undefined) => readonly ["profile", string];
|
|
81
|
+
userAccess: (userId: string | undefined) => readonly ["userAccess", string];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Query functions for React Query integration.
|
|
85
|
+
* Use these with useQuery from @tanstack/react-query.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* import { useQuery } from "@tanstack/react-query";
|
|
90
|
+
* import { offlineAuthQueries, offlineAuthQueryKeys } from "@pol-studios/db";
|
|
91
|
+
*
|
|
92
|
+
* function useProfile(db, userId) {
|
|
93
|
+
* return useQuery({
|
|
94
|
+
* queryKey: offlineAuthQueryKeys.profile(userId),
|
|
95
|
+
* queryFn: () => offlineAuthQueries.fetchProfile(db, userId),
|
|
96
|
+
* enabled: !!userId && !!db,
|
|
97
|
+
* });
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare const offlineAuthQueries: {
|
|
102
|
+
fetchProfile(db: {
|
|
103
|
+
getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
|
|
104
|
+
}, userId: string): Promise<SimpleProfile | null>;
|
|
105
|
+
fetchUserAccess(db: {
|
|
106
|
+
getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
|
|
107
|
+
}, userId: string): Promise<SimpleUserAccess[]>;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Extract access keys from UserAccess records.
|
|
111
|
+
*/
|
|
112
|
+
declare function extractAccessKeys(userAccess: SimpleUserAccess[] | null): string[];
|
|
113
|
+
|
|
10
114
|
/**
|
|
11
115
|
* Hook for authenticated users only.
|
|
12
116
|
* Throws an error if the user is not authenticated.
|
|
@@ -310,4 +414,4 @@ declare function useInvalidatePermission(): (entityType: EntityType, entityId: n
|
|
|
310
414
|
*/
|
|
311
415
|
declare function usePermissionLoading(): boolean;
|
|
312
416
|
|
|
313
|
-
export { EntityAction, EntityPermissionCheck, EntityType, type EntityWithPermission, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth };
|
|
417
|
+
export { EntityAction, EntityPermissionCheck, EntityType, type EntityWithPermission, type OfflineAuthData, type UseOfflineAuthOptions, extractAccessKeys, offlineAuthQueries, offlineAuthQueryKeys, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth };
|
package/dist/auth/hooks.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
extractAccessKeys,
|
|
3
|
+
offlineAuthQueries,
|
|
4
|
+
offlineAuthQueryKeys,
|
|
2
5
|
useAuth,
|
|
3
6
|
useCanCreate,
|
|
4
7
|
useCanDelete,
|
|
@@ -11,19 +14,23 @@ import {
|
|
|
11
14
|
usePermissionLoading,
|
|
12
15
|
usePermissionsBatch,
|
|
13
16
|
useSetupAuth
|
|
14
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-7NFMEDJW.js";
|
|
15
18
|
import {
|
|
16
19
|
useSetUserMetadata,
|
|
17
20
|
useUserMetadata,
|
|
18
21
|
useUserMetadataState,
|
|
19
22
|
useUserMetadataValue
|
|
20
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-YQUNORJD.js";
|
|
24
|
+
import "../chunk-UBHORKBS.js";
|
|
21
25
|
import "../chunk-J4ZVCXZ4.js";
|
|
22
26
|
import "../chunk-YUX6RGLZ.js";
|
|
23
27
|
import "../chunk-AKIRHA4Q.js";
|
|
24
28
|
import "../chunk-DMVUEJG2.js";
|
|
25
29
|
import "../chunk-7D4SUZUM.js";
|
|
26
30
|
export {
|
|
31
|
+
extractAccessKeys,
|
|
32
|
+
offlineAuthQueries,
|
|
33
|
+
offlineAuthQueryKeys,
|
|
27
34
|
useAuth,
|
|
28
35
|
useCanCreate,
|
|
29
36
|
useCanDelete,
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as SimpleAuthContextValue, S as SimpleAuthProvider, i as SimpleAuthProviderProps, k as SimpleProfile, P as SimpleProfileStatus, l as SimpleUserAccess, U as UserMetadataContextType, r as UserMetadataInsert, s as UserMetadataProvider, t as UserMetadataRow, v as UserMetadataUpdate, g as getPermissionLevel, h as hasResourceAccess, a as useRequireAuth, b as useResourceAccess, m as useSetUserMetadata, u as useSimpleAuth, e as useSimpleCanDelete, d as useSimpleCanEdit, f as useSimpleCanShare, c as useSimpleCanView, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue, q as userMetadataContext } from '../UserMetadataContext-QLIv-mfF.js';
|
|
2
|
+
export { EntityWithPermission, OfflineAuthData, UseOfflineAuthOptions, extractAccessKeys, offlineAuthQueries, offlineAuthQueryKeys, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth } from './hooks.js';
|
|
3
|
+
export { AuthProvider, AuthProviderProps, EntityPermissionContextValue, OfflineAuthProvider, OfflineAuthProviderProps, PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions } from './context.js';
|
|
2
4
|
export { P as Profile, a as ProfileStatus, S as SetupAuthContext, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-B76nbIP6.js';
|
|
3
|
-
export { AuthProvider, AuthProviderProps, EntityPermissionContextValue, PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions } from './context.js';
|
|
4
|
-
export { U as UserMetadataContextType, e as UserMetadataInsert, f as UserMetadataProvider, g as UserMetadataRow, h as UserMetadataUpdate, u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue, d as userMetadataContext } from '../UserMetadataContext-yLZQu24J.js';
|
|
5
5
|
export { hasAccess, hasAllAccess, hasAllEntityAccess, hasAnyAccess, hasAnyEntityAccess, hasEntityAccess, isEntityAccessDenied, isPermissionLoaded } from './guards.js';
|
|
6
6
|
export { E as EntityAccessRecord, a as EntityAction, b as EntityPermissionCheck, c as EntityPermissionLevel, d as EntityType, P as PermissionEffect } from '../EntityPermissions-DwFt4tUd.js';
|
|
7
|
-
import '@supabase/supabase-js';
|
|
8
|
-
import 'react';
|
|
9
7
|
import 'react/jsx-runtime';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@supabase/supabase-js';
|
|
10
10
|
import '../useSupabase-DSZNeXnF.js';
|
|
11
11
|
import '@supabase/supabase-js/dist/module/lib/types.js';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-6KN7KLEG.js";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
OfflineAuthProvider,
|
|
4
|
+
SimpleAuthProvider,
|
|
5
|
+
getPermissionLevel,
|
|
6
|
+
hasResourceAccess,
|
|
5
7
|
useCanDelete,
|
|
6
8
|
useCanEdit,
|
|
7
9
|
useCanShare,
|
|
8
10
|
useCanView,
|
|
11
|
+
useRequireAuth,
|
|
12
|
+
useResourceAccess,
|
|
13
|
+
useSimpleAuth
|
|
14
|
+
} from "../chunk-5HJLTYRA.js";
|
|
15
|
+
import {
|
|
16
|
+
extractAccessKeys,
|
|
17
|
+
offlineAuthQueries,
|
|
18
|
+
offlineAuthQueryKeys,
|
|
19
|
+
useAuth,
|
|
20
|
+
useCanCreate,
|
|
21
|
+
useCanDelete as useCanDelete2,
|
|
22
|
+
useCanEdit as useCanEdit2,
|
|
23
|
+
useCanShare as useCanShare2,
|
|
24
|
+
useCanView as useCanView2,
|
|
9
25
|
useInvalidatePermission,
|
|
10
26
|
usePermission,
|
|
11
27
|
usePermissionCheck,
|
|
12
28
|
usePermissionLoading,
|
|
13
29
|
usePermissionsBatch,
|
|
14
30
|
useSetupAuth
|
|
15
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-7NFMEDJW.js";
|
|
16
32
|
import {
|
|
17
33
|
AuthProvider,
|
|
18
34
|
PermissionProvider,
|
|
@@ -26,7 +42,8 @@ import {
|
|
|
26
42
|
useUserMetadataState,
|
|
27
43
|
useUserMetadataValue,
|
|
28
44
|
userMetadataContext
|
|
29
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-YQUNORJD.js";
|
|
46
|
+
import "../chunk-UBHORKBS.js";
|
|
30
47
|
import {
|
|
31
48
|
hasAccess,
|
|
32
49
|
hasAllAccess,
|
|
@@ -44,33 +61,47 @@ import "../chunk-DMVUEJG2.js";
|
|
|
44
61
|
import "../chunk-7D4SUZUM.js";
|
|
45
62
|
export {
|
|
46
63
|
AuthProvider,
|
|
64
|
+
OfflineAuthProvider,
|
|
47
65
|
PermissionProvider,
|
|
66
|
+
SimpleAuthProvider,
|
|
48
67
|
UserMetadataProvider,
|
|
49
68
|
entityPermissionContext,
|
|
69
|
+
extractAccessKeys,
|
|
70
|
+
getPermissionLevel,
|
|
50
71
|
hasAccess,
|
|
51
72
|
hasAllAccess,
|
|
52
73
|
hasAllEntityAccess,
|
|
53
74
|
hasAnyAccess,
|
|
54
75
|
hasAnyEntityAccess,
|
|
55
76
|
hasEntityAccess,
|
|
77
|
+
hasResourceAccess,
|
|
56
78
|
isEntityAccessDenied,
|
|
57
79
|
isPermissionLoaded,
|
|
80
|
+
offlineAuthQueries,
|
|
81
|
+
offlineAuthQueryKeys,
|
|
58
82
|
permissionContext,
|
|
59
83
|
setupAuthContext,
|
|
60
84
|
useAuth,
|
|
61
85
|
useCanCreate,
|
|
62
|
-
useCanDelete,
|
|
63
|
-
useCanEdit,
|
|
64
|
-
useCanShare,
|
|
65
|
-
useCanView,
|
|
86
|
+
useCanDelete2 as useCanDelete,
|
|
87
|
+
useCanEdit2 as useCanEdit,
|
|
88
|
+
useCanShare2 as useCanShare,
|
|
89
|
+
useCanView2 as useCanView,
|
|
66
90
|
useInvalidatePermission,
|
|
67
91
|
usePermission,
|
|
68
92
|
usePermissionCheck,
|
|
69
93
|
usePermissionLoading,
|
|
70
94
|
usePermissions,
|
|
71
95
|
usePermissionsBatch,
|
|
96
|
+
useRequireAuth,
|
|
97
|
+
useResourceAccess,
|
|
72
98
|
useSetUserMetadata,
|
|
73
99
|
useSetupAuth,
|
|
100
|
+
useSimpleAuth,
|
|
101
|
+
useCanDelete as useSimpleCanDelete,
|
|
102
|
+
useCanEdit as useSimpleCanEdit,
|
|
103
|
+
useCanShare as useSimpleCanShare,
|
|
104
|
+
useCanView as useSimpleCanView,
|
|
74
105
|
useUserMetadata,
|
|
75
106
|
useUserMetadataState,
|
|
76
107
|
useUserMetadataValue,
|