snipe-auth-rbac 0.1.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/dist/admin/index.cjs +515 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +346 -0
- package/dist/admin/index.d.ts +346 -0
- package/dist/admin/index.js +460 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/chunk-4WTV6J44.js +67 -0
- package/dist/chunk-4WTV6J44.js.map +1 -0
- package/dist/chunk-BRCJUCDG.js +55 -0
- package/dist/chunk-BRCJUCDG.js.map +1 -0
- package/dist/index.cjs +148 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +349 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +221 -0
- package/dist/react/index.d.ts +221 -0
- package/dist/react/index.js +227 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-BEc5SCIo.d.cts +69 -0
- package/dist/types-BEc5SCIo.d.ts +69 -0
- package/package.json +68 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { R as ResourceScope, F as FrontendConfig, a as ResourceDescriptor, A as Action } from '../types-BEc5SCIo.cjs';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Admin-side types — shapes returned by the admin SQL helpers.
|
|
6
|
+
* Mirrors the package's table layout so projects can ship a custom
|
|
7
|
+
* admin UI without re-defining shapes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface AdminRole {
|
|
11
|
+
id: string;
|
|
12
|
+
scope: ResourceScope;
|
|
13
|
+
/** null = system role OR company-scope template (no specific company). */
|
|
14
|
+
company_id: string | null;
|
|
15
|
+
name: string;
|
|
16
|
+
description: string | null;
|
|
17
|
+
is_system: boolean;
|
|
18
|
+
is_super: boolean;
|
|
19
|
+
frontend_config: FrontendConfig;
|
|
20
|
+
created_at: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
}
|
|
23
|
+
interface AdminRolePermission {
|
|
24
|
+
role_id: string;
|
|
25
|
+
resource: string;
|
|
26
|
+
can_read: boolean;
|
|
27
|
+
can_write: boolean;
|
|
28
|
+
can_update: boolean;
|
|
29
|
+
can_delete: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface AdminCompany {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
slug: string | null;
|
|
35
|
+
type: string | null;
|
|
36
|
+
parent_id: string | null;
|
|
37
|
+
metadata: Record<string, unknown>;
|
|
38
|
+
created_at: string;
|
|
39
|
+
}
|
|
40
|
+
interface AdminMember {
|
|
41
|
+
user_id: string;
|
|
42
|
+
email: string | null;
|
|
43
|
+
full_name: string | null;
|
|
44
|
+
/** Roles the member holds in the listed company. */
|
|
45
|
+
role_ids: string[];
|
|
46
|
+
invited_at: string | null;
|
|
47
|
+
/** "pending" | "accepted" — pending while Supabase Auth invite outstanding. */
|
|
48
|
+
invitation_status: "pending" | "accepted" | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adopter-supplied transport for admin reads + writes. The default
|
|
52
|
+
* Supabase implementation is exported as `createSupabaseAdminClient`
|
|
53
|
+
* — projects with a custom backend bring their own.
|
|
54
|
+
*/
|
|
55
|
+
interface AdminTransport {
|
|
56
|
+
/**
|
|
57
|
+
* Upsert resource descriptors into `auth_rbac_resources`. Call
|
|
58
|
+
* once at app boot (or behind a SuperAdmin button) so the
|
|
59
|
+
* permission matrix UI mirrors the host's typed resource
|
|
60
|
+
* registry. Returns the number of rows upserted.
|
|
61
|
+
*/
|
|
62
|
+
syncResources(resources: ReadonlyArray<ResourceDescriptor>): Promise<number>;
|
|
63
|
+
listRoles(args: {
|
|
64
|
+
scope: ResourceScope;
|
|
65
|
+
companyId?: string | null;
|
|
66
|
+
/** if true, returns only role TEMPLATES (company_id IS NULL). */
|
|
67
|
+
templatesOnly?: boolean;
|
|
68
|
+
}): Promise<AdminRole[]>;
|
|
69
|
+
listRolePermissions(roleId: string): Promise<AdminRolePermission[]>;
|
|
70
|
+
createRole(input: {
|
|
71
|
+
scope: ResourceScope;
|
|
72
|
+
companyId?: string | null;
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
frontend_config?: FrontendConfig;
|
|
76
|
+
}): Promise<AdminRole>;
|
|
77
|
+
updateRole(id: string, patch: Partial<Pick<AdminRole, "name" | "description" | "frontend_config">>): Promise<AdminRole>;
|
|
78
|
+
deleteRole(id: string): Promise<void>;
|
|
79
|
+
setRolePermissionCell(args: {
|
|
80
|
+
role_id: string;
|
|
81
|
+
resource: string;
|
|
82
|
+
action: Action;
|
|
83
|
+
value: boolean;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
listCompanies(): Promise<AdminCompany[]>;
|
|
86
|
+
createCompany(input: {
|
|
87
|
+
name: string;
|
|
88
|
+
slug?: string;
|
|
89
|
+
type?: string;
|
|
90
|
+
}): Promise<AdminCompany>;
|
|
91
|
+
listCompanyMembers(companyId: string): Promise<AdminMember[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Sends a Supabase Auth invite. The transport encodes the assigned
|
|
94
|
+
* role(s) into the invite metadata; on accept, a backend webhook
|
|
95
|
+
* is responsible for writing the assignment row.
|
|
96
|
+
*/
|
|
97
|
+
inviteCompanyMember(args: {
|
|
98
|
+
companyId: string;
|
|
99
|
+
email: string;
|
|
100
|
+
roleIds: string[];
|
|
101
|
+
}): Promise<{
|
|
102
|
+
invited: true;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Default Supabase implementation of the admin transport. Hits the
|
|
108
|
+
* package's tables directly via `from(...)` and the auth admin
|
|
109
|
+
* endpoint for invites.
|
|
110
|
+
*
|
|
111
|
+
* Projects that route admin writes through their own backend
|
|
112
|
+
* (e.g. for audit logging or extra validation) skip this and
|
|
113
|
+
* implement `AdminTransport` themselves.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
interface SupabaseAdmin {
|
|
117
|
+
from(table: string): {
|
|
118
|
+
select: (cols: string) => {
|
|
119
|
+
eq: (col: string, value: unknown) => any;
|
|
120
|
+
is: (col: string, value: unknown) => any;
|
|
121
|
+
order: (col: string, opts?: {
|
|
122
|
+
ascending: boolean;
|
|
123
|
+
}) => any;
|
|
124
|
+
};
|
|
125
|
+
insert: (row: Record<string, unknown>) => {
|
|
126
|
+
select: (cols: string) => {
|
|
127
|
+
single: () => any;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
update: (patch: Record<string, unknown>) => {
|
|
131
|
+
eq: (col: string, value: unknown) => {
|
|
132
|
+
select: (cols: string) => {
|
|
133
|
+
single: () => any;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
upsert: (row: Record<string, unknown> | Array<Record<string, unknown>>, opts?: {
|
|
138
|
+
onConflict: string;
|
|
139
|
+
}) => Promise<{
|
|
140
|
+
error: {
|
|
141
|
+
message: string;
|
|
142
|
+
} | null;
|
|
143
|
+
}>;
|
|
144
|
+
delete: () => {
|
|
145
|
+
eq: (col: string, value: unknown) => any;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
auth: {
|
|
149
|
+
admin: {
|
|
150
|
+
inviteUserByEmail: (email: string, opts?: {
|
|
151
|
+
data?: Record<string, unknown>;
|
|
152
|
+
redirectTo?: string;
|
|
153
|
+
}) => Promise<{
|
|
154
|
+
data: unknown;
|
|
155
|
+
error: {
|
|
156
|
+
message: string;
|
|
157
|
+
} | null;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
interface SupabaseAdminClientOptions {
|
|
163
|
+
supabase: SupabaseAdmin;
|
|
164
|
+
/** Where the invitee should land after setting their password. */
|
|
165
|
+
inviteRedirectUrl?: string;
|
|
166
|
+
}
|
|
167
|
+
declare function createSupabaseAdminClient(opts: SupabaseAdminClientOptions): AdminTransport;
|
|
168
|
+
|
|
169
|
+
interface AdminTransportProviderProps {
|
|
170
|
+
transport: AdminTransport;
|
|
171
|
+
children: React.ReactNode;
|
|
172
|
+
}
|
|
173
|
+
declare function AdminTransportProvider(props: AdminTransportProviderProps): react_jsx_runtime.JSX.Element;
|
|
174
|
+
declare function useAdminRoles(args: {
|
|
175
|
+
scope: ResourceScope;
|
|
176
|
+
companyId?: string | null;
|
|
177
|
+
templatesOnly?: boolean;
|
|
178
|
+
}): {
|
|
179
|
+
refresh: () => Promise<void>;
|
|
180
|
+
data: AdminRole[] | null;
|
|
181
|
+
isLoading: boolean;
|
|
182
|
+
error: Error | null;
|
|
183
|
+
};
|
|
184
|
+
declare function useAdminRolePermissions(roleId: string | null): {
|
|
185
|
+
refresh: () => Promise<void>;
|
|
186
|
+
data: AdminRolePermission[] | never[] | null;
|
|
187
|
+
isLoading: boolean;
|
|
188
|
+
error: Error | null;
|
|
189
|
+
};
|
|
190
|
+
declare function useAdminCompanies(): {
|
|
191
|
+
refresh: () => Promise<void>;
|
|
192
|
+
data: AdminCompany[] | null;
|
|
193
|
+
isLoading: boolean;
|
|
194
|
+
error: Error | null;
|
|
195
|
+
};
|
|
196
|
+
declare function useAdminCompanyMembers(companyId: string | null): {
|
|
197
|
+
refresh: () => Promise<void>;
|
|
198
|
+
data: AdminMember[] | never[] | null;
|
|
199
|
+
isLoading: boolean;
|
|
200
|
+
error: Error | null;
|
|
201
|
+
};
|
|
202
|
+
declare function useCreateRole(): {
|
|
203
|
+
isPending: boolean;
|
|
204
|
+
error: Error | null;
|
|
205
|
+
mutate: (input: {
|
|
206
|
+
scope: ResourceScope;
|
|
207
|
+
companyId?: string | null;
|
|
208
|
+
name: string;
|
|
209
|
+
description?: string;
|
|
210
|
+
frontend_config?: FrontendConfig;
|
|
211
|
+
}) => Promise<AdminRole>;
|
|
212
|
+
};
|
|
213
|
+
declare function useUpdateRole(): {
|
|
214
|
+
isPending: boolean;
|
|
215
|
+
error: Error | null;
|
|
216
|
+
mutate: (id: string, patch: Partial<Pick<AdminRole, "name" | "description" | "frontend_config">>) => Promise<AdminRole>;
|
|
217
|
+
};
|
|
218
|
+
declare function useDeleteRole(): {
|
|
219
|
+
isPending: boolean;
|
|
220
|
+
error: Error | null;
|
|
221
|
+
mutate: (id: string) => Promise<void>;
|
|
222
|
+
};
|
|
223
|
+
declare function useSetRolePermissionCell(): {
|
|
224
|
+
isPending: boolean;
|
|
225
|
+
error: Error | null;
|
|
226
|
+
mutate: (args: {
|
|
227
|
+
role_id: string;
|
|
228
|
+
resource: string;
|
|
229
|
+
action: Action;
|
|
230
|
+
value: boolean;
|
|
231
|
+
}) => Promise<void>;
|
|
232
|
+
};
|
|
233
|
+
declare function useCreateCompany(): {
|
|
234
|
+
isPending: boolean;
|
|
235
|
+
error: Error | null;
|
|
236
|
+
mutate: (input: {
|
|
237
|
+
name: string;
|
|
238
|
+
slug?: string;
|
|
239
|
+
type?: string;
|
|
240
|
+
}) => Promise<AdminCompany>;
|
|
241
|
+
};
|
|
242
|
+
declare function useInviteCompanyMember(): {
|
|
243
|
+
isPending: boolean;
|
|
244
|
+
error: Error | null;
|
|
245
|
+
mutate: (args: {
|
|
246
|
+
companyId: string;
|
|
247
|
+
email: string;
|
|
248
|
+
roleIds: string[];
|
|
249
|
+
}) => Promise<{
|
|
250
|
+
invited: true;
|
|
251
|
+
}>;
|
|
252
|
+
};
|
|
253
|
+
interface RolePermissionGrid {
|
|
254
|
+
[resource: string]: {
|
|
255
|
+
[A in Action]: boolean;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
declare function useRolePermissionGrid(roleId: string | null): {
|
|
259
|
+
grid: RolePermissionGrid;
|
|
260
|
+
isLoading: boolean;
|
|
261
|
+
error: Error | null;
|
|
262
|
+
refresh: () => Promise<void>;
|
|
263
|
+
updateCell: (resource: string, action: Action, value: boolean) => Promise<void>;
|
|
264
|
+
isUpdating: boolean;
|
|
265
|
+
updateError: Error | null;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
interface MatrixGroup {
|
|
269
|
+
group: string;
|
|
270
|
+
resources: ResourceDescriptor[];
|
|
271
|
+
}
|
|
272
|
+
interface MatrixRenderArgs {
|
|
273
|
+
/** Resources grouped by their `group` label, original insertion order. */
|
|
274
|
+
groups: MatrixGroup[];
|
|
275
|
+
/** Read a single cell from the current grid. */
|
|
276
|
+
isCellEnabled: (resource: string, action: Action) => boolean;
|
|
277
|
+
/** Write a single cell. Optimistic in the local cache + writes through. */
|
|
278
|
+
setCell: (resource: string, action: Action, value: boolean) => Promise<void>;
|
|
279
|
+
isLoading: boolean;
|
|
280
|
+
isUpdating: boolean;
|
|
281
|
+
error: Error | null;
|
|
282
|
+
/** All four actions, exposed for the consumer to render headers. */
|
|
283
|
+
actions: ReadonlyArray<Action>;
|
|
284
|
+
}
|
|
285
|
+
interface PermissionsMatrixProps {
|
|
286
|
+
roleId: string | null;
|
|
287
|
+
resources: ReadonlyArray<ResourceDescriptor>;
|
|
288
|
+
children: (args: MatrixRenderArgs) => React.ReactNode;
|
|
289
|
+
}
|
|
290
|
+
declare function PermissionsMatrix(props: PermissionsMatrixProps): react_jsx_runtime.JSX.Element;
|
|
291
|
+
|
|
292
|
+
interface RolesListRenderArgs {
|
|
293
|
+
roles: AdminRole[];
|
|
294
|
+
isLoading: boolean;
|
|
295
|
+
error: Error | null;
|
|
296
|
+
selectedRoleId: string | null;
|
|
297
|
+
selectRole: (id: string | null) => void;
|
|
298
|
+
createRole: (input: {
|
|
299
|
+
name: string;
|
|
300
|
+
description?: string;
|
|
301
|
+
}) => Promise<AdminRole>;
|
|
302
|
+
isCreating: boolean;
|
|
303
|
+
createError: Error | null;
|
|
304
|
+
deleteRole: (id: string) => Promise<void>;
|
|
305
|
+
isDeleting: boolean;
|
|
306
|
+
deleteError: Error | null;
|
|
307
|
+
refresh: () => Promise<void>;
|
|
308
|
+
}
|
|
309
|
+
interface RolesListProps {
|
|
310
|
+
scope: ResourceScope;
|
|
311
|
+
/** Required for company-scope. Pass `null` for templates. */
|
|
312
|
+
companyId?: string | null;
|
|
313
|
+
/** Pre-select the first role on load. Default: true. */
|
|
314
|
+
autoSelectFirst?: boolean;
|
|
315
|
+
children: (args: RolesListRenderArgs) => React.ReactNode;
|
|
316
|
+
}
|
|
317
|
+
declare function RolesList(props: RolesListProps): react_jsx_runtime.JSX.Element;
|
|
318
|
+
|
|
319
|
+
interface InviteMemberFormRenderArgs {
|
|
320
|
+
email: string;
|
|
321
|
+
setEmail: (v: string) => void;
|
|
322
|
+
selectedRoleIds: Set<string>;
|
|
323
|
+
toggleRole: (roleId: string) => void;
|
|
324
|
+
resetForm: () => void;
|
|
325
|
+
roles: AdminRole[];
|
|
326
|
+
rolesLoading: boolean;
|
|
327
|
+
rolesError: Error | null;
|
|
328
|
+
submit: () => Promise<void>;
|
|
329
|
+
isSubmitting: boolean;
|
|
330
|
+
submitError: Error | null;
|
|
331
|
+
submittedSuccessfully: boolean;
|
|
332
|
+
isValid: boolean;
|
|
333
|
+
errors: {
|
|
334
|
+
email?: string;
|
|
335
|
+
roles?: string;
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
interface InviteMemberFormProps {
|
|
339
|
+
companyId: string;
|
|
340
|
+
/** Called after a successful invite — typically clears a dialog. */
|
|
341
|
+
onSuccess?: () => void;
|
|
342
|
+
children: (args: InviteMemberFormRenderArgs) => React.ReactNode;
|
|
343
|
+
}
|
|
344
|
+
declare function InviteMemberForm(props: InviteMemberFormProps): react_jsx_runtime.JSX.Element;
|
|
345
|
+
|
|
346
|
+
export { type AdminCompany, type AdminMember, type AdminRole, type AdminRolePermission, type AdminTransport, AdminTransportProvider, type AdminTransportProviderProps, InviteMemberForm, type InviteMemberFormProps, type InviteMemberFormRenderArgs, type MatrixGroup, type MatrixRenderArgs, PermissionsMatrix, type PermissionsMatrixProps, type RolePermissionGrid, RolesList, type RolesListProps, type RolesListRenderArgs, type SupabaseAdminClientOptions, createSupabaseAdminClient, useAdminCompanies, useAdminCompanyMembers, useAdminRolePermissions, useAdminRoles, useCreateCompany, useCreateRole, useDeleteRole, useInviteCompanyMember, useRolePermissionGrid, useSetRolePermissionCell, useUpdateRole };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { R as ResourceScope, F as FrontendConfig, a as ResourceDescriptor, A as Action } from '../types-BEc5SCIo.js';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Admin-side types — shapes returned by the admin SQL helpers.
|
|
6
|
+
* Mirrors the package's table layout so projects can ship a custom
|
|
7
|
+
* admin UI without re-defining shapes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface AdminRole {
|
|
11
|
+
id: string;
|
|
12
|
+
scope: ResourceScope;
|
|
13
|
+
/** null = system role OR company-scope template (no specific company). */
|
|
14
|
+
company_id: string | null;
|
|
15
|
+
name: string;
|
|
16
|
+
description: string | null;
|
|
17
|
+
is_system: boolean;
|
|
18
|
+
is_super: boolean;
|
|
19
|
+
frontend_config: FrontendConfig;
|
|
20
|
+
created_at: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
}
|
|
23
|
+
interface AdminRolePermission {
|
|
24
|
+
role_id: string;
|
|
25
|
+
resource: string;
|
|
26
|
+
can_read: boolean;
|
|
27
|
+
can_write: boolean;
|
|
28
|
+
can_update: boolean;
|
|
29
|
+
can_delete: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface AdminCompany {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
slug: string | null;
|
|
35
|
+
type: string | null;
|
|
36
|
+
parent_id: string | null;
|
|
37
|
+
metadata: Record<string, unknown>;
|
|
38
|
+
created_at: string;
|
|
39
|
+
}
|
|
40
|
+
interface AdminMember {
|
|
41
|
+
user_id: string;
|
|
42
|
+
email: string | null;
|
|
43
|
+
full_name: string | null;
|
|
44
|
+
/** Roles the member holds in the listed company. */
|
|
45
|
+
role_ids: string[];
|
|
46
|
+
invited_at: string | null;
|
|
47
|
+
/** "pending" | "accepted" — pending while Supabase Auth invite outstanding. */
|
|
48
|
+
invitation_status: "pending" | "accepted" | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adopter-supplied transport for admin reads + writes. The default
|
|
52
|
+
* Supabase implementation is exported as `createSupabaseAdminClient`
|
|
53
|
+
* — projects with a custom backend bring their own.
|
|
54
|
+
*/
|
|
55
|
+
interface AdminTransport {
|
|
56
|
+
/**
|
|
57
|
+
* Upsert resource descriptors into `auth_rbac_resources`. Call
|
|
58
|
+
* once at app boot (or behind a SuperAdmin button) so the
|
|
59
|
+
* permission matrix UI mirrors the host's typed resource
|
|
60
|
+
* registry. Returns the number of rows upserted.
|
|
61
|
+
*/
|
|
62
|
+
syncResources(resources: ReadonlyArray<ResourceDescriptor>): Promise<number>;
|
|
63
|
+
listRoles(args: {
|
|
64
|
+
scope: ResourceScope;
|
|
65
|
+
companyId?: string | null;
|
|
66
|
+
/** if true, returns only role TEMPLATES (company_id IS NULL). */
|
|
67
|
+
templatesOnly?: boolean;
|
|
68
|
+
}): Promise<AdminRole[]>;
|
|
69
|
+
listRolePermissions(roleId: string): Promise<AdminRolePermission[]>;
|
|
70
|
+
createRole(input: {
|
|
71
|
+
scope: ResourceScope;
|
|
72
|
+
companyId?: string | null;
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
frontend_config?: FrontendConfig;
|
|
76
|
+
}): Promise<AdminRole>;
|
|
77
|
+
updateRole(id: string, patch: Partial<Pick<AdminRole, "name" | "description" | "frontend_config">>): Promise<AdminRole>;
|
|
78
|
+
deleteRole(id: string): Promise<void>;
|
|
79
|
+
setRolePermissionCell(args: {
|
|
80
|
+
role_id: string;
|
|
81
|
+
resource: string;
|
|
82
|
+
action: Action;
|
|
83
|
+
value: boolean;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
listCompanies(): Promise<AdminCompany[]>;
|
|
86
|
+
createCompany(input: {
|
|
87
|
+
name: string;
|
|
88
|
+
slug?: string;
|
|
89
|
+
type?: string;
|
|
90
|
+
}): Promise<AdminCompany>;
|
|
91
|
+
listCompanyMembers(companyId: string): Promise<AdminMember[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Sends a Supabase Auth invite. The transport encodes the assigned
|
|
94
|
+
* role(s) into the invite metadata; on accept, a backend webhook
|
|
95
|
+
* is responsible for writing the assignment row.
|
|
96
|
+
*/
|
|
97
|
+
inviteCompanyMember(args: {
|
|
98
|
+
companyId: string;
|
|
99
|
+
email: string;
|
|
100
|
+
roleIds: string[];
|
|
101
|
+
}): Promise<{
|
|
102
|
+
invited: true;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Default Supabase implementation of the admin transport. Hits the
|
|
108
|
+
* package's tables directly via `from(...)` and the auth admin
|
|
109
|
+
* endpoint for invites.
|
|
110
|
+
*
|
|
111
|
+
* Projects that route admin writes through their own backend
|
|
112
|
+
* (e.g. for audit logging or extra validation) skip this and
|
|
113
|
+
* implement `AdminTransport` themselves.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
interface SupabaseAdmin {
|
|
117
|
+
from(table: string): {
|
|
118
|
+
select: (cols: string) => {
|
|
119
|
+
eq: (col: string, value: unknown) => any;
|
|
120
|
+
is: (col: string, value: unknown) => any;
|
|
121
|
+
order: (col: string, opts?: {
|
|
122
|
+
ascending: boolean;
|
|
123
|
+
}) => any;
|
|
124
|
+
};
|
|
125
|
+
insert: (row: Record<string, unknown>) => {
|
|
126
|
+
select: (cols: string) => {
|
|
127
|
+
single: () => any;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
update: (patch: Record<string, unknown>) => {
|
|
131
|
+
eq: (col: string, value: unknown) => {
|
|
132
|
+
select: (cols: string) => {
|
|
133
|
+
single: () => any;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
upsert: (row: Record<string, unknown> | Array<Record<string, unknown>>, opts?: {
|
|
138
|
+
onConflict: string;
|
|
139
|
+
}) => Promise<{
|
|
140
|
+
error: {
|
|
141
|
+
message: string;
|
|
142
|
+
} | null;
|
|
143
|
+
}>;
|
|
144
|
+
delete: () => {
|
|
145
|
+
eq: (col: string, value: unknown) => any;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
auth: {
|
|
149
|
+
admin: {
|
|
150
|
+
inviteUserByEmail: (email: string, opts?: {
|
|
151
|
+
data?: Record<string, unknown>;
|
|
152
|
+
redirectTo?: string;
|
|
153
|
+
}) => Promise<{
|
|
154
|
+
data: unknown;
|
|
155
|
+
error: {
|
|
156
|
+
message: string;
|
|
157
|
+
} | null;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
interface SupabaseAdminClientOptions {
|
|
163
|
+
supabase: SupabaseAdmin;
|
|
164
|
+
/** Where the invitee should land after setting their password. */
|
|
165
|
+
inviteRedirectUrl?: string;
|
|
166
|
+
}
|
|
167
|
+
declare function createSupabaseAdminClient(opts: SupabaseAdminClientOptions): AdminTransport;
|
|
168
|
+
|
|
169
|
+
interface AdminTransportProviderProps {
|
|
170
|
+
transport: AdminTransport;
|
|
171
|
+
children: React.ReactNode;
|
|
172
|
+
}
|
|
173
|
+
declare function AdminTransportProvider(props: AdminTransportProviderProps): react_jsx_runtime.JSX.Element;
|
|
174
|
+
declare function useAdminRoles(args: {
|
|
175
|
+
scope: ResourceScope;
|
|
176
|
+
companyId?: string | null;
|
|
177
|
+
templatesOnly?: boolean;
|
|
178
|
+
}): {
|
|
179
|
+
refresh: () => Promise<void>;
|
|
180
|
+
data: AdminRole[] | null;
|
|
181
|
+
isLoading: boolean;
|
|
182
|
+
error: Error | null;
|
|
183
|
+
};
|
|
184
|
+
declare function useAdminRolePermissions(roleId: string | null): {
|
|
185
|
+
refresh: () => Promise<void>;
|
|
186
|
+
data: AdminRolePermission[] | never[] | null;
|
|
187
|
+
isLoading: boolean;
|
|
188
|
+
error: Error | null;
|
|
189
|
+
};
|
|
190
|
+
declare function useAdminCompanies(): {
|
|
191
|
+
refresh: () => Promise<void>;
|
|
192
|
+
data: AdminCompany[] | null;
|
|
193
|
+
isLoading: boolean;
|
|
194
|
+
error: Error | null;
|
|
195
|
+
};
|
|
196
|
+
declare function useAdminCompanyMembers(companyId: string | null): {
|
|
197
|
+
refresh: () => Promise<void>;
|
|
198
|
+
data: AdminMember[] | never[] | null;
|
|
199
|
+
isLoading: boolean;
|
|
200
|
+
error: Error | null;
|
|
201
|
+
};
|
|
202
|
+
declare function useCreateRole(): {
|
|
203
|
+
isPending: boolean;
|
|
204
|
+
error: Error | null;
|
|
205
|
+
mutate: (input: {
|
|
206
|
+
scope: ResourceScope;
|
|
207
|
+
companyId?: string | null;
|
|
208
|
+
name: string;
|
|
209
|
+
description?: string;
|
|
210
|
+
frontend_config?: FrontendConfig;
|
|
211
|
+
}) => Promise<AdminRole>;
|
|
212
|
+
};
|
|
213
|
+
declare function useUpdateRole(): {
|
|
214
|
+
isPending: boolean;
|
|
215
|
+
error: Error | null;
|
|
216
|
+
mutate: (id: string, patch: Partial<Pick<AdminRole, "name" | "description" | "frontend_config">>) => Promise<AdminRole>;
|
|
217
|
+
};
|
|
218
|
+
declare function useDeleteRole(): {
|
|
219
|
+
isPending: boolean;
|
|
220
|
+
error: Error | null;
|
|
221
|
+
mutate: (id: string) => Promise<void>;
|
|
222
|
+
};
|
|
223
|
+
declare function useSetRolePermissionCell(): {
|
|
224
|
+
isPending: boolean;
|
|
225
|
+
error: Error | null;
|
|
226
|
+
mutate: (args: {
|
|
227
|
+
role_id: string;
|
|
228
|
+
resource: string;
|
|
229
|
+
action: Action;
|
|
230
|
+
value: boolean;
|
|
231
|
+
}) => Promise<void>;
|
|
232
|
+
};
|
|
233
|
+
declare function useCreateCompany(): {
|
|
234
|
+
isPending: boolean;
|
|
235
|
+
error: Error | null;
|
|
236
|
+
mutate: (input: {
|
|
237
|
+
name: string;
|
|
238
|
+
slug?: string;
|
|
239
|
+
type?: string;
|
|
240
|
+
}) => Promise<AdminCompany>;
|
|
241
|
+
};
|
|
242
|
+
declare function useInviteCompanyMember(): {
|
|
243
|
+
isPending: boolean;
|
|
244
|
+
error: Error | null;
|
|
245
|
+
mutate: (args: {
|
|
246
|
+
companyId: string;
|
|
247
|
+
email: string;
|
|
248
|
+
roleIds: string[];
|
|
249
|
+
}) => Promise<{
|
|
250
|
+
invited: true;
|
|
251
|
+
}>;
|
|
252
|
+
};
|
|
253
|
+
interface RolePermissionGrid {
|
|
254
|
+
[resource: string]: {
|
|
255
|
+
[A in Action]: boolean;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
declare function useRolePermissionGrid(roleId: string | null): {
|
|
259
|
+
grid: RolePermissionGrid;
|
|
260
|
+
isLoading: boolean;
|
|
261
|
+
error: Error | null;
|
|
262
|
+
refresh: () => Promise<void>;
|
|
263
|
+
updateCell: (resource: string, action: Action, value: boolean) => Promise<void>;
|
|
264
|
+
isUpdating: boolean;
|
|
265
|
+
updateError: Error | null;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
interface MatrixGroup {
|
|
269
|
+
group: string;
|
|
270
|
+
resources: ResourceDescriptor[];
|
|
271
|
+
}
|
|
272
|
+
interface MatrixRenderArgs {
|
|
273
|
+
/** Resources grouped by their `group` label, original insertion order. */
|
|
274
|
+
groups: MatrixGroup[];
|
|
275
|
+
/** Read a single cell from the current grid. */
|
|
276
|
+
isCellEnabled: (resource: string, action: Action) => boolean;
|
|
277
|
+
/** Write a single cell. Optimistic in the local cache + writes through. */
|
|
278
|
+
setCell: (resource: string, action: Action, value: boolean) => Promise<void>;
|
|
279
|
+
isLoading: boolean;
|
|
280
|
+
isUpdating: boolean;
|
|
281
|
+
error: Error | null;
|
|
282
|
+
/** All four actions, exposed for the consumer to render headers. */
|
|
283
|
+
actions: ReadonlyArray<Action>;
|
|
284
|
+
}
|
|
285
|
+
interface PermissionsMatrixProps {
|
|
286
|
+
roleId: string | null;
|
|
287
|
+
resources: ReadonlyArray<ResourceDescriptor>;
|
|
288
|
+
children: (args: MatrixRenderArgs) => React.ReactNode;
|
|
289
|
+
}
|
|
290
|
+
declare function PermissionsMatrix(props: PermissionsMatrixProps): react_jsx_runtime.JSX.Element;
|
|
291
|
+
|
|
292
|
+
interface RolesListRenderArgs {
|
|
293
|
+
roles: AdminRole[];
|
|
294
|
+
isLoading: boolean;
|
|
295
|
+
error: Error | null;
|
|
296
|
+
selectedRoleId: string | null;
|
|
297
|
+
selectRole: (id: string | null) => void;
|
|
298
|
+
createRole: (input: {
|
|
299
|
+
name: string;
|
|
300
|
+
description?: string;
|
|
301
|
+
}) => Promise<AdminRole>;
|
|
302
|
+
isCreating: boolean;
|
|
303
|
+
createError: Error | null;
|
|
304
|
+
deleteRole: (id: string) => Promise<void>;
|
|
305
|
+
isDeleting: boolean;
|
|
306
|
+
deleteError: Error | null;
|
|
307
|
+
refresh: () => Promise<void>;
|
|
308
|
+
}
|
|
309
|
+
interface RolesListProps {
|
|
310
|
+
scope: ResourceScope;
|
|
311
|
+
/** Required for company-scope. Pass `null` for templates. */
|
|
312
|
+
companyId?: string | null;
|
|
313
|
+
/** Pre-select the first role on load. Default: true. */
|
|
314
|
+
autoSelectFirst?: boolean;
|
|
315
|
+
children: (args: RolesListRenderArgs) => React.ReactNode;
|
|
316
|
+
}
|
|
317
|
+
declare function RolesList(props: RolesListProps): react_jsx_runtime.JSX.Element;
|
|
318
|
+
|
|
319
|
+
interface InviteMemberFormRenderArgs {
|
|
320
|
+
email: string;
|
|
321
|
+
setEmail: (v: string) => void;
|
|
322
|
+
selectedRoleIds: Set<string>;
|
|
323
|
+
toggleRole: (roleId: string) => void;
|
|
324
|
+
resetForm: () => void;
|
|
325
|
+
roles: AdminRole[];
|
|
326
|
+
rolesLoading: boolean;
|
|
327
|
+
rolesError: Error | null;
|
|
328
|
+
submit: () => Promise<void>;
|
|
329
|
+
isSubmitting: boolean;
|
|
330
|
+
submitError: Error | null;
|
|
331
|
+
submittedSuccessfully: boolean;
|
|
332
|
+
isValid: boolean;
|
|
333
|
+
errors: {
|
|
334
|
+
email?: string;
|
|
335
|
+
roles?: string;
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
interface InviteMemberFormProps {
|
|
339
|
+
companyId: string;
|
|
340
|
+
/** Called after a successful invite — typically clears a dialog. */
|
|
341
|
+
onSuccess?: () => void;
|
|
342
|
+
children: (args: InviteMemberFormRenderArgs) => React.ReactNode;
|
|
343
|
+
}
|
|
344
|
+
declare function InviteMemberForm(props: InviteMemberFormProps): react_jsx_runtime.JSX.Element;
|
|
345
|
+
|
|
346
|
+
export { type AdminCompany, type AdminMember, type AdminRole, type AdminRolePermission, type AdminTransport, AdminTransportProvider, type AdminTransportProviderProps, InviteMemberForm, type InviteMemberFormProps, type InviteMemberFormRenderArgs, type MatrixGroup, type MatrixRenderArgs, PermissionsMatrix, type PermissionsMatrixProps, type RolePermissionGrid, RolesList, type RolesListProps, type RolesListRenderArgs, type SupabaseAdminClientOptions, createSupabaseAdminClient, useAdminCompanies, useAdminCompanyMembers, useAdminRolePermissions, useAdminRoles, useCreateCompany, useCreateRole, useDeleteRole, useInviteCompanyMember, useRolePermissionGrid, useSetRolePermissionCell, useUpdateRole };
|