@pol-studios/db 1.0.19 → 1.0.22
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/DataLayerContext-ZmLPYR_s.d.ts +825 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +48 -0
- package/dist/auth/context.js +2 -2
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-2T6WTCP4.js → chunk-3EVWXMUV.js} +54 -155
- package/dist/chunk-3EVWXMUV.js.map +1 -0
- package/dist/{chunk-YERWPV6B.js → chunk-3FHAKRDV.js} +145 -19
- package/dist/{chunk-YERWPV6B.js.map → chunk-3FHAKRDV.js.map} +1 -1
- package/dist/{chunk-X3HZLNBV.js → chunk-FKRACEHV.js} +2 -962
- package/dist/chunk-FKRACEHV.js.map +1 -0
- package/dist/{chunk-N26IEHZT.js → chunk-FZF26ZRB.js} +18 -2
- package/dist/{chunk-N26IEHZT.js.map → chunk-FZF26ZRB.js.map} +1 -1
- package/dist/chunk-HTJ2FQW5.js +963 -0
- package/dist/chunk-HTJ2FQW5.js.map +1 -0
- package/dist/{chunk-R5B2XMN5.js → chunk-I4BDZDHX.js} +1614 -2141
- package/dist/chunk-I4BDZDHX.js.map +1 -0
- package/dist/{chunk-36DVUMQD.js → chunk-LPC64MD4.js} +2 -2
- package/dist/{chunk-72WV3ALS.js → chunk-OUUQSI3Y.js} +2 -2
- package/dist/{chunk-RMRYGICS.js → chunk-WP6TIVPH.js} +4 -4
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +568 -0
- package/dist/database.types-ChFCG-4M.d.ts +8604 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +119 -0
- package/dist/hooks/index.js +1 -1
- package/dist/index-2YySlz7X.d.ts +433 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -95
- package/dist/index.native.d.ts +775 -0
- package/dist/index.native.js +17 -96
- package/dist/index.web.d.ts +438 -0
- package/dist/index.web.js +585 -46
- package/dist/index.web.js.map +1 -1
- package/dist/mutation/index.d.ts +58 -0
- package/dist/parser/index.d.ts +366 -0
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/powersync-bridge/index.js +1 -1
- package/dist/query/index.d.ts +723 -0
- package/dist/query/index.js +10 -8
- package/dist/realtime/index.d.ts +44 -0
- package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
- package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types-CYr9JiUE.d.ts +62 -0
- package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
- package/dist/useDbCount-s-aR9YeV.d.ts +1082 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
- package/dist/useResolveFeedback-DTGcHpCs.d.ts +882 -0
- package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
- package/dist/with-auth/index.d.ts +704 -0
- package/dist/with-auth/index.js +4 -4
- package/package.json +50 -1
- package/dist/chunk-2T6WTCP4.js.map +0 -1
- package/dist/chunk-R5B2XMN5.js.map +0 -1
- package/dist/chunk-X3HZLNBV.js.map +0 -1
- /package/dist/{chunk-36DVUMQD.js.map → chunk-LPC64MD4.js.map} +0 -0
- /package/dist/{chunk-72WV3ALS.js.map → chunk-OUUQSI3Y.js.map} +0 -0
- /package/dist/{chunk-RMRYGICS.js.map → chunk-WP6TIVPH.js.map} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type EntityType = 'Project' | 'Client' | 'ProjectDatabase';
|
|
2
|
+
type EntityPermissionLevel = 'ReadOnly' | 'AdminReadOnly' | 'ReadWrite' | 'Admin';
|
|
3
|
+
type PermissionEffect = 'allow' | 'deny';
|
|
4
|
+
type EntityAction = 'view' | 'adminView' | 'edit' | 'create' | 'delete' | 'share';
|
|
5
|
+
interface EntityPermissionCheck {
|
|
6
|
+
canView: boolean;
|
|
7
|
+
canAdminView: boolean;
|
|
8
|
+
canEdit: boolean;
|
|
9
|
+
canCreate: boolean;
|
|
10
|
+
canDelete: boolean;
|
|
11
|
+
canShare: boolean;
|
|
12
|
+
permissionLevel: EntityPermissionLevel | null;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
/** Whether access was explicitly denied */
|
|
15
|
+
isDenied?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface EntityAccessRecord {
|
|
18
|
+
id: number;
|
|
19
|
+
userId: string;
|
|
20
|
+
entityType: EntityType;
|
|
21
|
+
entityId: number;
|
|
22
|
+
permission: EntityPermissionLevel;
|
|
23
|
+
/** Permission effect - 'allow' grants access, 'deny' explicitly blocks */
|
|
24
|
+
effect: PermissionEffect;
|
|
25
|
+
inheritedFromClientId?: number | null;
|
|
26
|
+
inheritFromProject?: boolean;
|
|
27
|
+
/** User ID who granted this permission */
|
|
28
|
+
grantedBy?: string | null;
|
|
29
|
+
/** ISO timestamp when permission was granted */
|
|
30
|
+
grantedAt?: string;
|
|
31
|
+
/** ISO timestamp when permission expires, null for never */
|
|
32
|
+
expiresAt?: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type { EntityAccessRecord as E, PermissionEffect as P, EntityAction as a, EntityPermissionCheck as b, EntityPermissionLevel as c, EntityType as d };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Filter Configuration Type
|
|
3
|
+
*
|
|
4
|
+
* This is the canonical type for filter configuration across the codebase.
|
|
5
|
+
* Replaces both ValueOption and SimpleFilterConfig.
|
|
6
|
+
*/
|
|
7
|
+
type PropertyType = "string" | "number" | "boolean" | "date";
|
|
8
|
+
type ValueForPropertyType<T extends PropertyType> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "date" ? Date : never;
|
|
9
|
+
interface TableInfo {
|
|
10
|
+
tableName: string;
|
|
11
|
+
schemaName?: string;
|
|
12
|
+
outputProperty?: string;
|
|
13
|
+
innerProperty: string;
|
|
14
|
+
innerCast?: string;
|
|
15
|
+
}
|
|
16
|
+
interface SortConfig {
|
|
17
|
+
isSortable?: boolean;
|
|
18
|
+
properties?: string[];
|
|
19
|
+
}
|
|
20
|
+
interface FilterConfigOption<PT extends PropertyType = PropertyType> {
|
|
21
|
+
display: string;
|
|
22
|
+
value: ValueForPropertyType<PT>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Simple filter clause for WHERE conditions
|
|
26
|
+
* Used in edge function query building
|
|
27
|
+
*/
|
|
28
|
+
interface WhereFilter {
|
|
29
|
+
id: string;
|
|
30
|
+
field: string;
|
|
31
|
+
op: string;
|
|
32
|
+
value: string | number | string[] | number[] | boolean | null;
|
|
33
|
+
not?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* WhereClause can be either:
|
|
37
|
+
* - string: For edge function format like "tagId.eq.5"
|
|
38
|
+
* - WhereFilter: For complex filter objects
|
|
39
|
+
*/
|
|
40
|
+
type WhereClause = string | WhereFilter;
|
|
41
|
+
/**
|
|
42
|
+
* Unified FilterConfig - the canonical filter configuration type
|
|
43
|
+
*
|
|
44
|
+
* Uses `field` with dot notation for relationships.
|
|
45
|
+
* Examples: "name", "locationId.name", "locationId.tags.value"
|
|
46
|
+
*/
|
|
47
|
+
interface FilterConfig<EntityType = unknown, PT extends PropertyType = PropertyType> {
|
|
48
|
+
/**
|
|
49
|
+
* Field path using dot notation for relationships
|
|
50
|
+
* Examples: "name", "locationId.name", "locationId.tags.value"
|
|
51
|
+
*/
|
|
52
|
+
field?: string;
|
|
53
|
+
/** The property name on the entity */
|
|
54
|
+
property?: keyof EntityType | string;
|
|
55
|
+
/** Display label shown in UI */
|
|
56
|
+
display: string;
|
|
57
|
+
/**
|
|
58
|
+
* Data type of the field. Can be inferred from schema when using `field`.
|
|
59
|
+
*/
|
|
60
|
+
propertyType?: PT;
|
|
61
|
+
/** Whether this field is searchable via text search (default: true for strings) */
|
|
62
|
+
searchable?: boolean;
|
|
63
|
+
/** Additional WHERE clause for relationship filtering */
|
|
64
|
+
where?: WhereClause;
|
|
65
|
+
/** Relationship configuration for many-to-one joins */
|
|
66
|
+
manyToOneTableInfo?: TableInfo & {
|
|
67
|
+
innerTable?: TableInfo[];
|
|
68
|
+
};
|
|
69
|
+
/** Predefined dropdown options */
|
|
70
|
+
options?: FilterConfigOption<PT>[];
|
|
71
|
+
/** Sort configuration for this field */
|
|
72
|
+
sortOptions?: SortConfig;
|
|
73
|
+
/** Mark as metadata field (custom columns) */
|
|
74
|
+
isMetadata?: boolean;
|
|
75
|
+
/** Hide behind "Show More Filters" button */
|
|
76
|
+
advanced?: boolean;
|
|
77
|
+
/** Show in "Recommended" section */
|
|
78
|
+
recommended?: boolean;
|
|
79
|
+
/** Custom render function for display in filter dropdown */
|
|
80
|
+
renderOption?: (option: FilterConfig<EntityType, PT>) => string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Group of filter configs for organizing filters in UI
|
|
84
|
+
* Note: Named "Group" to avoid conflict with FilterGroup (AND/OR query groups)
|
|
85
|
+
*/
|
|
86
|
+
interface Group {
|
|
87
|
+
/** Title displayed for the group (used as 'label' in some contexts) */
|
|
88
|
+
title: string;
|
|
89
|
+
/** Optional nesting level for UI rendering */
|
|
90
|
+
level?: number;
|
|
91
|
+
/** Hide entire group by default behind "Show More Filters" button */
|
|
92
|
+
advanced?: boolean;
|
|
93
|
+
/** Show this group in the "Recommended" section at the top of the filter dropdown */
|
|
94
|
+
recommended?: boolean;
|
|
95
|
+
/** Child filter configs or nested groups */
|
|
96
|
+
children: (FilterConfig | Group)[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type { FilterConfigOption as F, Group as G, PropertyType as P, SortConfig as S, TableInfo as T, ValueForPropertyType as V, WhereFilter as W, FilterConfig as a, WhereClause as b };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { D as Database } from './useSupabase-DvWVuHHE.js';
|
|
5
|
+
|
|
6
|
+
declare function useLiveChangesIndicator(value: any, field: string | undefined): [boolean, string];
|
|
7
|
+
|
|
8
|
+
type UserMetadataRow = Database["core"]["Tables"]["UserMetadata"]["Row"];
|
|
9
|
+
type UserMetadataInsert = Database["core"]["Tables"]["UserMetadata"]["Insert"];
|
|
10
|
+
type UserMetadataUpdate = Database["core"]["Tables"]["UserMetadata"]["Update"];
|
|
11
|
+
interface UserMetadataContextType {
|
|
12
|
+
metadata: Record<string, string>;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
error: Error | null;
|
|
15
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
16
|
+
getMetadata: (key: string) => string | undefined;
|
|
17
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
18
|
+
refreshMetadata: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
declare const userMetadataContext: react.Context<UserMetadataContextType>;
|
|
21
|
+
declare function UserMetadataContextProvider({ children, }: {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}): react_jsx_runtime.JSX.Element;
|
|
24
|
+
declare function useUserMetadata(): UserMetadataContextType;
|
|
25
|
+
declare function useUserMetadataValue(key: string): string | undefined;
|
|
26
|
+
declare function useSetUserMetadata(): {
|
|
27
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
28
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
declare function useUserMetadataState<T>(key: string, defaultValue: T, options?: {
|
|
31
|
+
serialize?: (value: T) => string;
|
|
32
|
+
deserialize?: (value: string) => T;
|
|
33
|
+
}): [T, (value: T) => Promise<void>, boolean];
|
|
34
|
+
|
|
35
|
+
export { type UserMetadataRow as U, type UserMetadataInsert as a, type UserMetadataUpdate as b, type UserMetadataContextType as c, userMetadataContext as d, UserMetadataContextProvider as e, useUserMetadata as f, useUserMetadataValue as g, useSetUserMetadata as h, useUserMetadataState as i, useLiveChangesIndicator as u };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { D as Database } from './useSupabase-DvWVuHHE.js';
|
|
5
|
+
|
|
6
|
+
type UserMetadataRow = Database["core"]["Tables"]["UserMetadata"]["Row"];
|
|
7
|
+
type UserMetadataInsert = Database["core"]["Tables"]["UserMetadata"]["Insert"];
|
|
8
|
+
type UserMetadataUpdate = Database["core"]["Tables"]["UserMetadata"]["Update"];
|
|
9
|
+
interface UserMetadataContextType {
|
|
10
|
+
metadata: Record<string, string>;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
14
|
+
getMetadata: (key: string) => string | undefined;
|
|
15
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
16
|
+
refreshMetadata: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare const userMetadataContext: react.Context<UserMetadataContextType>;
|
|
19
|
+
declare function UserMetadataProvider({ children }: {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}): react_jsx_runtime.JSX.Element;
|
|
22
|
+
declare function useUserMetadata(): UserMetadataContextType;
|
|
23
|
+
declare function useUserMetadataValue(key: string): string | undefined;
|
|
24
|
+
declare function useSetUserMetadata(): {
|
|
25
|
+
setMetadata: (key: string, value: string) => Promise<void>;
|
|
26
|
+
removeMetadata: (key: string) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
declare function useUserMetadataState<T>(key: string, defaultValue: T, options?: {
|
|
29
|
+
serialize?: (value: T) => string;
|
|
30
|
+
deserialize?: (value: string) => T;
|
|
31
|
+
}): [T, (value: T) => Promise<void>, boolean];
|
|
32
|
+
|
|
33
|
+
export { type UserMetadataContextType as U, useUserMetadata as a, useUserMetadataState as b, useUserMetadataValue as c, userMetadataContext as d, type UserMetadataInsert as e, UserMetadataProvider as f, type UserMetadataRow as g, type UserMetadataUpdate as h, useSetUserMetadata as u };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export { c as Profile, P as ProfileStatus, a as SetupAuthContext, S as SetupAuthContextProvider, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-Kv-THH-h.js';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
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-DntmpK41.js';
|
|
7
|
+
import '@supabase/supabase-js';
|
|
8
|
+
import '../useSupabase-DvWVuHHE.js';
|
|
9
|
+
import '@supabase/supabase-js/dist/module/lib/types.js';
|
|
10
|
+
|
|
11
|
+
interface AuthProviderProps {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Enable entity-level permissions system (Project, Client, ProjectDatabase access control).
|
|
15
|
+
* When enabled, wraps children with PermissionProvider.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
enableEntityPermissions?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function AuthProvider({ children, enableEntityPermissions, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
interface EntityIdentifier {
|
|
23
|
+
entityType: EntityType;
|
|
24
|
+
entityId: number;
|
|
25
|
+
}
|
|
26
|
+
interface PermissionContextValue {
|
|
27
|
+
getPermission: (entityType: EntityType, entityId: number) => EntityPermissionCheck;
|
|
28
|
+
checkPermission: (entityType: EntityType, entityId: number, action: EntityAction) => boolean;
|
|
29
|
+
prefetchPermissions: (entities: EntityIdentifier[]) => Promise<void>;
|
|
30
|
+
invalidatePermission: (entityType: EntityType, entityId: number) => void;
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use permissionContext instead
|
|
35
|
+
*/
|
|
36
|
+
interface EntityPermissionContextValue extends PermissionContextValue {
|
|
37
|
+
}
|
|
38
|
+
declare const permissionContext: react.Context<PermissionContextValue>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use permissionContext instead
|
|
41
|
+
*/
|
|
42
|
+
declare const entityPermissionContext: react.Context<PermissionContextValue>;
|
|
43
|
+
declare function PermissionProvider({ children }: {
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
}): react_jsx_runtime.JSX.Element;
|
|
46
|
+
declare function usePermissions(): PermissionContextValue;
|
|
47
|
+
|
|
48
|
+
export { AuthProvider, type AuthProviderProps, type EntityPermissionContextValue, type PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions };
|
package/dist/auth/context.js
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
useUserMetadataState,
|
|
13
13
|
useUserMetadataValue,
|
|
14
14
|
userMetadataContext
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-OUUQSI3Y.js";
|
|
16
|
+
import "../chunk-3FHAKRDV.js";
|
|
17
17
|
import "../chunk-GC3TBUWE.js";
|
|
18
18
|
import "../chunk-J4ZVCXZ4.js";
|
|
19
19
|
import "../chunk-OQ7U6EQ3.js";
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { b as EntityPermissionCheck, a as EntityAction } from '../EntityPermissions-DwFt4tUd.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if a user has access to a specific permission key.
|
|
5
|
+
* Owners bypass all permission checks.
|
|
6
|
+
*
|
|
7
|
+
* @param accessKeys - Array of access keys the user has
|
|
8
|
+
* @param key - The access key to check for
|
|
9
|
+
* @param options - Additional options for the check
|
|
10
|
+
* @param options.isArchived - Whether the user is archived
|
|
11
|
+
* @param options.isSuspended - Whether the user is suspended
|
|
12
|
+
* @returns boolean - true if user has the specified access
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Basic usage
|
|
17
|
+
* const canAccess = hasAccess(['admin', 'viewer'], 'admin'); // true
|
|
18
|
+
* const cannotAccess = hasAccess(['viewer'], 'admin'); // false
|
|
19
|
+
*
|
|
20
|
+
* // Owner bypasses all checks
|
|
21
|
+
* const ownerAccess = hasAccess(['owner'], 'any-key'); // true
|
|
22
|
+
*
|
|
23
|
+
* // Empty key always returns true (no permission required)
|
|
24
|
+
* const noKeyRequired = hasAccess(['viewer'], ''); // true
|
|
25
|
+
*
|
|
26
|
+
* // Archived/suspended users have no access
|
|
27
|
+
* const archivedUser = hasAccess(['admin'], 'admin', { isArchived: true }); // false
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function hasAccess(accessKeys: string[] | undefined | null, key: string, options?: {
|
|
31
|
+
isArchived?: boolean;
|
|
32
|
+
isSuspended?: boolean;
|
|
33
|
+
}): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a user has any of the specified access keys.
|
|
36
|
+
*
|
|
37
|
+
* @param accessKeys - Array of access keys the user has
|
|
38
|
+
* @param keys - Array of access keys to check for (OR logic)
|
|
39
|
+
* @param options - Additional options for the check
|
|
40
|
+
* @returns boolean - true if user has any of the specified keys
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const hasAny = hasAnyAccess(['viewer'], ['admin', 'editor', 'viewer']); // true
|
|
45
|
+
* const hasNone = hasAnyAccess(['viewer'], ['admin', 'editor']); // false
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function hasAnyAccess(accessKeys: string[] | undefined | null, keys: string[], options?: {
|
|
49
|
+
isArchived?: boolean;
|
|
50
|
+
isSuspended?: boolean;
|
|
51
|
+
}): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a user has all of the specified access keys.
|
|
54
|
+
*
|
|
55
|
+
* @param accessKeys - Array of access keys the user has
|
|
56
|
+
* @param keys - Array of access keys to check for (AND logic)
|
|
57
|
+
* @param options - Additional options for the check
|
|
58
|
+
* @returns boolean - true if user has all of the specified keys
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const hasAll = hasAllAccess(['admin', 'editor'], ['admin', 'editor']); // true
|
|
63
|
+
* const hasPartial = hasAllAccess(['admin'], ['admin', 'editor']); // false
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function hasAllAccess(accessKeys: string[] | undefined | null, keys: string[], options?: {
|
|
67
|
+
isArchived?: boolean;
|
|
68
|
+
isSuspended?: boolean;
|
|
69
|
+
}): boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if a user has entity-level access based on permission check result.
|
|
73
|
+
* Owners (users with 'owner' access key) bypass entity permissions entirely.
|
|
74
|
+
*
|
|
75
|
+
* @param permission - The permission check result from getPermission/usePermission
|
|
76
|
+
* @param action - The action to check for
|
|
77
|
+
* @param options - Additional options for the check
|
|
78
|
+
* @param options.accessKeys - User's access keys (for owner check)
|
|
79
|
+
* @param options.isArchived - Whether the user is archived
|
|
80
|
+
* @param options.isSuspended - Whether the user is suspended
|
|
81
|
+
* @returns boolean - true if user has permission for the action
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Basic usage
|
|
86
|
+
* const permission = await getPermission('Project', 123);
|
|
87
|
+
* const canEdit = hasEntityAccess(permission, 'edit');
|
|
88
|
+
*
|
|
89
|
+
* // With owner bypass
|
|
90
|
+
* const canEditAsOwner = hasEntityAccess(permission, 'edit', {
|
|
91
|
+
* accessKeys: ['owner'],
|
|
92
|
+
* }); // true, owners bypass all checks
|
|
93
|
+
*
|
|
94
|
+
* // Check loading state
|
|
95
|
+
* if (permission.isLoading) {
|
|
96
|
+
* return false; // Wait for permission to load
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function hasEntityAccess(permission: EntityPermissionCheck | null | undefined, action: EntityAction, options?: {
|
|
101
|
+
accessKeys?: string[] | null;
|
|
102
|
+
isArchived?: boolean;
|
|
103
|
+
isSuspended?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a user has any of the specified entity actions.
|
|
107
|
+
*
|
|
108
|
+
* @param permission - The permission check result
|
|
109
|
+
* @param actions - Array of actions to check for (OR logic)
|
|
110
|
+
* @param options - Additional options for the check
|
|
111
|
+
* @returns boolean - true if user has permission for any of the actions
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const canEditOrDelete = hasAnyEntityAccess(permission, ['edit', 'delete']);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function hasAnyEntityAccess(permission: EntityPermissionCheck | null | undefined, actions: EntityAction[], options?: {
|
|
119
|
+
accessKeys?: string[] | null;
|
|
120
|
+
isArchived?: boolean;
|
|
121
|
+
isSuspended?: boolean;
|
|
122
|
+
}): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Check if a user has all of the specified entity actions.
|
|
125
|
+
*
|
|
126
|
+
* @param permission - The permission check result
|
|
127
|
+
* @param actions - Array of actions to check for (AND logic)
|
|
128
|
+
* @param options - Additional options for the check
|
|
129
|
+
* @returns boolean - true if user has permission for all of the actions
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* // Check if user can edit AND delete (admin-like permissions)
|
|
134
|
+
* const isAdmin = hasAllEntityAccess(permission, ['edit', 'delete', 'share']);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function hasAllEntityAccess(permission: EntityPermissionCheck | null | undefined, actions: EntityAction[], options?: {
|
|
138
|
+
accessKeys?: string[] | null;
|
|
139
|
+
isArchived?: boolean;
|
|
140
|
+
isSuspended?: boolean;
|
|
141
|
+
}): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if entity access was explicitly denied.
|
|
144
|
+
* Useful for distinguishing between "no permission" and "explicitly blocked".
|
|
145
|
+
*
|
|
146
|
+
* @param permission - The permission check result
|
|
147
|
+
* @returns boolean - true if access was explicitly denied
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const permission = await getPermission('Project', 123);
|
|
152
|
+
* if (isEntityAccessDenied(permission)) {
|
|
153
|
+
* showBlockedMessage('You have been explicitly denied access to this project');
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function isEntityAccessDenied(permission: EntityPermissionCheck | null | undefined): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Type guard to check if permission data is loaded and available.
|
|
160
|
+
*
|
|
161
|
+
* @param permission - The permission check result
|
|
162
|
+
* @returns boolean - true if permission data is loaded
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const permission = usePermission('Project', projectId);
|
|
167
|
+
*
|
|
168
|
+
* if (!isPermissionLoaded(permission)) {
|
|
169
|
+
* return <Spinner />;
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* // TypeScript knows permission is fully loaded here
|
|
173
|
+
* return permission.canEdit ? <Editor /> : <Viewer />;
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function isPermissionLoaded(permission: EntityPermissionCheck | null | undefined): permission is EntityPermissionCheck & {
|
|
177
|
+
isLoading: false;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export { hasAccess, hasAllAccess, hasAllEntityAccess, hasAnyAccess, hasAnyEntityAccess, hasEntityAccess, isEntityAccessDenied, isPermissionLoaded };
|