@payload-kit/rbac 0.1.0-alpha.0 → 0.1.0-alpha.2

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@ Provides a type-safe, declarative capability engine and Payload Access combinato
5
5
 
6
6
  @packageDocumentation
7
7
  */
8
- import { Access, AccessArgs, FieldAccess, FieldAccess as FieldAccess$1, FieldAccessArgs, FieldAccessArgs as FieldAccessArgs$1, Plugin, TypeWithID, TypeWithID as TypeWithID$1, Where } from "payload";
8
+ import { Access, AccessArgs, FieldAccess, FieldAccess as FieldAccess$1, FieldAccessArgs, FieldAccessArgs as FieldAccessArgs$1, Plugin, SelectField, TypeWithID, TypeWithID as TypeWithID$1, Where } from "payload";
9
9
  /**
10
10
  Combines multiple access rules with logical OR.
11
11
 
@@ -35,11 +35,12 @@ export declare function or<TData = unknown>(...rules: readonly Access<TData>[]):
35
35
  Combines multiple access rules with logical AND.
36
36
 
37
37
  Evaluation semantics:
38
- 1. If any rule evaluates to `false` (denial), access is denied immediately (`false`).
39
- 2. If any rules return `Where` query constraints:
38
+ 1. If no rules are provided, fails closed by returning `false`.
39
+ 2. If any rule evaluates to `false` or an unexpected non-boolean, non-object value (e.g. `undefined`, `null`), access is denied immediately (`false`).
40
+ 3. If any rules return `Where` query constraints:
40
41
  - If exactly one `Where` constraint exists, it is returned directly.
41
42
  - If multiple `Where` constraints exist, they are merged via `{ and: [...] }`.
42
- 3. If all rules evaluate to `true` (and no `Where` constraints are returned), access is granted (`true`).
43
+ 4. If all rules evaluate to `true` (and no `Where` constraints are returned), access is granted (`true`).
43
44
 
44
45
  @param rules - One or more Payload Access rules to evaluate.
45
46
  @returns A composite Payload Access rule.
@@ -105,9 +106,9 @@ export declare function fieldOr<TData extends TypeWithID$1 = TypeWithID$1, TSibl
105
106
  Combines multiple field-level access rules with logical AND.
106
107
 
107
108
  Evaluation semantics:
108
- 1. If any rule evaluates to `false`, access to the field is denied (`false`).
109
- 2. If all rules evaluate to `true`, access to the field is granted (`true`).
110
- 3. If no rules are provided, returns `true`.
109
+ 1. If no rules are provided, fails closed by returning `false`.
110
+ 2. If any rule evaluates to `false`, access to the field is denied (`false`).
111
+ 3. If all rules evaluate to `true`, access to the field is granted (`true`).
111
112
 
112
113
  @param rules - One or more FieldAccess rules to evaluate.
113
114
  @returns A composite FieldAccess rule.
@@ -146,6 +147,26 @@ Inverts the outcome of a field-level access rule.
146
147
  */
147
148
  export declare function fieldNot<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(rule: FieldAccess$1<TData, TSiblingData>): FieldAccess$1<TData, TSiblingData>;
148
149
  /**
150
+ Evaluates whether a granted capability pattern satisfies a requested capability.
151
+
152
+ Supported pattern formats:
153
+ - `'*'`: Global wildcard, matches any requested capability.
154
+ - `'domain:*'`: Domain wildcard, matches any capability starting with `'domain:'` (e.g., `'orders:*'` matches `'orders:create'`).
155
+ - `'exact:match'`: Exact match against requested capability.
156
+
157
+ @param grantedPattern - The capability or wildcard pattern possessed by the role or user.
158
+ @param requestedCapability - The specific capability required for an operation.
159
+ @returns True if the pattern satisfies the requested capability, false otherwise.
160
+
161
+ @example
162
+ ```typescript
163
+ matchesCapability('*', 'orders:delete'); // true
164
+ matchesCapability('orders:*', 'orders:delete'); // true
165
+ matchesCapability('orders:read', 'orders:delete'); // false
166
+ ```
167
+ */
168
+ export declare function doesMatchCapability(grantedPattern: string, requestedCapability: string): boolean;
169
+ /**
149
170
  Wildcard capability tokens.
150
171
  - `'*'`: grants access to all capabilities.
151
172
  - `${string}:*`: grants access to all actions within a domain (e.g. `'orders:*'`).
@@ -184,12 +205,24 @@ Generic representation of a user entity with potential role and capability assig
184
205
  interface UserLike {
185
206
  readonly id?: string | number;
186
207
  readonly email?: string | null;
208
+ readonly collection?: string | null;
187
209
  readonly role?: string | null;
188
210
  readonly roles?: readonly (string | null | undefined)[] | null;
189
211
  readonly capabilities?: readonly string[] | null;
190
212
  readonly [key: string]: unknown;
191
213
  }
192
214
  /**
215
+ Options used to customize authentication checks.
216
+ */
217
+ interface AuthCheckOptions {
218
+ /**
219
+ Restricts authentication to users belonging to the specified Payload auth collection slug
220
+ (matched against `user.collection`). Pass `null` to disable collection filtering even when
221
+ a global `userCollectionSlug` is configured.
222
+ */
223
+ readonly userCollectionSlug?: string | null;
224
+ }
225
+ /**
193
226
  Options used to customize the behavior of capability checks.
194
227
  */
195
228
  interface CapabilityCheckOptions<TRole extends string = string, TCapability extends string = string> {
@@ -199,20 +232,35 @@ interface CapabilityCheckOptions<TRole extends string = string, TCapability exte
199
232
  readonly roles?: RolesConfig<TRole, TCapability>;
200
233
  /**
201
234
  Name of the role that automatically bypasses capability checks (grants all capabilities).
202
- @default 'admin'
235
+ Disabled by default (`undefined`/`null`); configure explicitly (e.g. `'admin'`) to enable bypass.
236
+ @default undefined
203
237
  */
204
238
  readonly superAdminRole?: TRole | null;
239
+ /**
240
+ Whether direct per-user capability overrides on `user.capabilities` are evaluated.
241
+ Disabled by default (`false`) to prevent privilege escalation if a user document
242
+ exposes an unprotected `capabilities` field.
243
+ @default false
244
+ */
245
+ readonly allowDirectUserCapabilities?: boolean;
205
246
  /**
206
247
  Name of the role representing unauthenticated/anonymous visitors.
207
248
  If provided and user is null/undefined, resolves capabilities from this role.
208
- @default 'public'
249
+ @default undefined
209
250
  */
210
251
  readonly anonymousRole?: TRole | null;
211
252
  /**
212
253
  Name of the field on the user object storing their role(s).
254
+ Pass `null` to use default `'role'`/`'roles'` lookup without inheriting global config.
213
255
  @default 'role'
214
256
  */
215
- readonly rolesFieldName?: string;
257
+ readonly rolesFieldName?: string | null;
258
+ /**
259
+ Restricts evaluation to users belonging to the specified Payload auth collection slug
260
+ (matched against `user.collection`). Pass `null` to disable collection filtering even when
261
+ a global `userCollectionSlug` is configured.
262
+ */
263
+ readonly userCollectionSlug?: string | null;
216
264
  }
217
265
  /**
218
266
  Options used to customize the behavior of role checks.
@@ -220,15 +268,22 @@ Options used to customize the behavior of role checks.
220
268
  interface RoleCheckOptions {
221
269
  /**
222
270
  Name of the field on the user object storing their role(s).
271
+ Pass `null` to use default `'role'`/`'roles'` lookup without inheriting global config.
223
272
  @default 'role'
224
273
  */
225
- readonly rolesFieldName?: string;
274
+ readonly rolesFieldName?: string | null;
226
275
  /**
227
276
  Name of the role representing unauthenticated/anonymous visitors.
228
277
  If provided and user is null/undefined, resolveUserRoles returns this role.
229
- @default 'public'
278
+ @default undefined
230
279
  */
231
280
  readonly anonymousRole?: string | null;
281
+ /**
282
+ Restricts evaluation to users belonging to the specified Payload auth collection slug
283
+ (matched against `user.collection`). Pass `null` to disable collection filtering even when
284
+ a global `userCollectionSlug` is configured.
285
+ */
286
+ readonly userCollectionSlug?: string | null;
232
287
  }
233
288
  /**
234
289
  Configuration options for the RBAC plugin.
@@ -248,19 +303,26 @@ interface RbacPluginOptions<TRole extends string = string, TCapability extends s
248
303
  readonly defaultRole?: NoInfer<TRole>;
249
304
  /**
250
305
  Role that bypasses all capability checks (has wildcard access).
251
- Set to `null` to disable super-admin bypass.
252
- @default 'admin'
306
+ Disabled by default; set explicitly (e.g. `'admin'`) to enable super-admin bypass.
307
+ @default undefined
253
308
  */
254
309
  readonly superAdminRole?: NoInfer<TRole> | null;
310
+ /**
311
+ Whether to also grant direct capabilities stored on `user.capabilities`.
312
+ Disabled by default (`false`); enable only when `user.capabilities` is strictly write-protected.
313
+ @default false
314
+ */
315
+ readonly allowDirectUserCapabilities?: boolean;
255
316
  /**
256
317
  Role representing unauthenticated/anonymous public visitors.
257
318
  When user is null/undefined, this role's capabilities are granted.
258
- @default 'public'
319
+ @default undefined
259
320
  */
260
321
  readonly anonymousRole?: NoInfer<TRole> | null;
261
322
  /**
262
- Slug of the user collection to integrate with.
263
- @default 'users'
323
+ Slug of the user collection enforced during runtime `user.collection` validation.
324
+ When set, role, capability, and auth guards fail closed for users from other auth collections.
325
+ @default undefined
264
326
  */
265
327
  readonly userCollectionSlug?: string;
266
328
  /**
@@ -268,12 +330,6 @@ interface RbacPluginOptions<TRole extends string = string, TCapability extends s
268
330
  @default 'role'
269
331
  */
270
332
  readonly rolesFieldName?: string;
271
- /**
272
- Whether to automatically synchronize the user collection's role field options
273
- with the roles configured in this plugin.
274
- @default false
275
- */
276
- readonly syncUserRolesField?: boolean;
277
333
  }
278
334
  /**
279
335
  Typed Payload Access function type alias for convenient readability.
@@ -296,169 +352,17 @@ Payload Where query condition.
296
352
  */
297
353
  type RbacWhere = Where;
298
354
  /**
299
- Additional options when checking capabilities via `requireCapability` or `requireFieldCapability`.
300
- */
301
- interface RequireCapabilityOptions<TRole extends string = string, TCapability extends string = string> extends CapabilityCheckOptions<TRole, TCapability> {
302
- /**
303
- When an array of capabilities is provided:
304
- - `'any'`: The user must satisfy at least one capability. (Default)
305
- - `'all'`: The user must satisfy all provided capabilities.
306
- @default 'any'
307
- */
308
- readonly mode?: "any" | "all";
309
- }
310
- /**
311
- Creates a field-level access rule requiring that the requesting client is an authenticated user.
312
-
313
- @returns A Payload FieldAccess function returning true if user is authenticated, false otherwise.
314
- */
315
- export declare function requireFieldAuth<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(): FieldAccess$1<TData, TSiblingData>;
316
- /**
317
- Creates a field-level access rule requiring that the requesting user possesses one or more specified roles.
318
-
319
- @param role - A single role name or array of acceptable roles.
320
- @param options - Custom options for role extraction.
321
- @returns A Payload FieldAccess rule returning boolean.
322
- */
323
- export declare function requireFieldRole<TRole extends string = string, TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(role: TRole | readonly TRole[], options?: RoleCheckOptions): FieldAccess$1<TData, TSiblingData>;
324
- /**
325
- Creates a field-level access rule requiring that the requesting user possesses one or more specified capabilities.
326
-
327
- @param capability - A single capability or array of capabilities.
328
- @param options - Options for capability verification, including matching mode (`'any'` | `'all'`).
329
- @returns A Payload FieldAccess rule returning boolean.
330
- */
331
- export declare function requireFieldCapability<TCapability extends string = string, TRole extends string = string, TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(capability: TCapability | readonly TCapability[], options?: RequireCapabilityOptions<TRole, TCapability>): FieldAccess$1<TData, TSiblingData>;
332
- /**
333
- Universal field access rule that strictly denies field access to everyone (public & authenticated).
334
-
335
- @returns Always returns `false`.
336
- */
337
- export declare const nobodyField: FieldAccess$1;
338
- /**
339
- Universal field access rule that permits field access to everyone.
340
-
341
- @returns Always returns `true`.
342
- */
343
- export declare const anyoneField: FieldAccess$1;
344
- /**
345
- Functional alias for `nobodyField`.
346
- */
347
- export declare const denyField: FieldAccess$1;
348
- /**
349
- Functional alias for `anyoneField`.
350
- */
351
- export declare const allowField: FieldAccess$1;
352
- /**
353
- Configures field access for a strictly read-only field (cannot be created or updated via API).
354
- The field remains readable according to the collection's read access rules, but API writes are denied.
355
-
356
- @returns Field access object with create and update set to `nobodyField`.
357
- */
358
- export declare function readOnlyField<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(): {
359
- create: FieldAccess$1<TData, TSiblingData>;
360
- update: FieldAccess$1<TData, TSiblingData>;
361
- };
362
- /**
363
- Configures field access for an internal system field that cannot be read, created, or updated via public API.
364
- Only local server operations (with `overrideAccess: true` or internal services) can access or modify it.
365
-
366
- @returns Field access object with create, read, and update set to `nobodyField`.
367
- */
368
- export declare function systemOnlyField<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(): {
369
- create: FieldAccess$1<TData, TSiblingData>;
370
- read: FieldAccess$1<TData, TSiblingData>;
371
- update: FieldAccess$1<TData, TSiblingData>;
372
- };
373
- /**
374
- Creates an access rule requiring that the requesting client is an authenticated user.
375
-
376
- @returns A Payload Access function returning true if user is present, false otherwise.
377
-
378
- @example
379
- ```typescript
380
- export const Orders = {
381
- access: {
382
- create: requireAuth(),
383
- },
384
- };
385
- ```
386
- */
387
- export declare function requireAuth<TData = unknown>(): Access<TData>;
388
- /**
389
- Creates an access rule requiring that the requesting user possesses one or more specified roles.
390
-
391
- @param role - A single role name or array of acceptable roles.
392
- @param options - Custom options for role extraction.
393
- @returns A Payload Access rule returning boolean.
394
-
395
- @example
396
- ```typescript
397
- access: {
398
- delete: requireRole('admin'),
399
- update: requireRole(['admin', 'operator']),
400
- }
401
- ```
402
- */
403
- export declare function requireRole<TRole extends string = string, TData = unknown>(role: TRole | readonly TRole[], options?: RoleCheckOptions): Access<TData>;
404
- /**
405
- Creates an access rule requiring that the requesting user possesses one or more specified capabilities.
406
-
407
- @param capability - A single capability or array of capabilities.
408
- @param options - Options for capability verification, including matching mode (`'any'` | `'all'`).
409
- @returns A Payload Access rule returning boolean.
410
-
411
- @example
412
- ```typescript
413
- access: {
414
- read: requireCapability('orders:read'),
415
- update: requireCapability(['orders:update', 'orders:manage'], { mode: 'any' }),
416
- }
417
- ```
418
- */
419
- export declare function requireCapability<TCapability extends string = string, TRole extends string = string, TData = unknown>(capability: TCapability | readonly TCapability[], options?: RequireCapabilityOptions<TRole, TCapability>): Access<TData>;
420
- /**
421
- Universal access rule that strictly denies collection or global access to everyone (public & authenticated).
422
- Ideal for immutable collections, disabled actions (e.g. `delete: nobody`), or server-only models.
423
-
424
- @returns Always returns `false`.
425
- */
426
- export declare const nobody: Access;
427
- /**
428
- Universal access rule that permits public access to everyone.
429
- Ideal for public-facing collections, marketing pages, site settings, or public legal documents.
430
-
431
- @returns Always returns `true`.
432
- */
433
- export declare const anyone: Access;
434
- /**
435
- Functional alias for `nobody`.
436
- */
437
- export declare const denyAll: Access;
438
- /**
439
- Functional alias for `anyone`.
440
- */
441
- export declare const allowAll: Access;
442
- /**
443
- Evaluates whether a granted capability pattern satisfies a requested capability.
444
-
445
- Supported pattern formats:
446
- - `'*'`: Global wildcard, matches any requested capability.
447
- - `'domain:*'`: Domain wildcard, matches any capability starting with `'domain:'` (e.g., `'orders:*'` matches `'orders:create'`).
448
- - `'exact:match'`: Exact match against requested capability.
355
+ Builds a write-protected Payload `select` field for user roles, ready to be placed
356
+ anywhere in your users collection (`fields`, `tabs`, `row`, or `sidebar`).
449
357
 
450
- @param grantedPattern - The capability or wildcard pattern possessed by the role or user.
451
- @param requestedCapability - The specific capability required for an operation.
452
- @returns True if the pattern satisfies the requested capability, false otherwise.
358
+ Defaults `access.create` and `access.update` to `superAdminRole` (or `nobodyField`
359
+ when no `superAdminRole` is configured), while preserving any custom access overrides.
453
360
 
454
- @example
455
- ```typescript
456
- matchesCapability('*', 'orders:delete'); // true
457
- matchesCapability('orders:*', 'orders:delete'); // true
458
- matchesCapability('orders:read', 'orders:delete'); // false
459
- ```
361
+ @param options - RBAC plugin options defining roles, default role, and field name.
362
+ @param overrides - Optional Payload `SelectField` overrides (e.g. `admin`, `hasMany`, `label`, `access`).
363
+ @returns A configured Payload `SelectField`.
460
364
  */
461
- export declare function doesMatchCapability(grantedPattern: string, requestedCapability: string): boolean;
365
+ export declare function createRoleField<TRole extends string = string, TCapability extends string = string>(options: RbacPluginOptions<TRole, TCapability>, overrides?: Partial<Omit<SelectField, "name" | "type">>): SelectField;
462
366
  /**
463
367
  Creates and initializes the Payload CMS RBAC (Role-Based Access Control) plugin.
464
368
 
@@ -505,6 +409,7 @@ const canEdit = rbac.hasCapability(user, 'articles:publish');
505
409
  export declare function createRbac<TRole extends string = string, TCapability extends string = string>(options: RbacPluginOptions<TRole, TCapability>): {
506
410
  options: RbacPluginOptions<TRole, TCapability>;
507
411
  plugin: () => Plugin;
412
+ roleField: (overrides?: Partial<Omit<SelectField, "name" | "type">>) => SelectField;
508
413
  resolveRoles: (user: UserLike | null | undefined) => readonly string[];
509
414
  hasRole: (user: UserLike | null | undefined, role: TRole | (string & {}), checkOptions?: RoleCheckOptions) => boolean;
510
415
  hasAnyRole: (user: UserLike | null | undefined, roles: readonly (TRole | (string & {}))[], checkOptions?: RoleCheckOptions) => boolean;
@@ -512,16 +417,16 @@ export declare function createRbac<TRole extends string = string, TCapability ex
512
417
  hasCapability: (user: UserLike | null | undefined, capability: TCapability | (string & {}), checkOptions?: CapabilityCheckOptions<TRole, TCapability>) => boolean;
513
418
  hasAnyCapability: (user: UserLike | null | undefined, capabilities: readonly (TCapability | (string & {}))[], checkOptions?: CapabilityCheckOptions<TRole, TCapability>) => boolean;
514
419
  hasAllCapabilities: (user: UserLike | null | undefined, capabilities: readonly (TCapability | (string & {}))[], checkOptions?: CapabilityCheckOptions<TRole, TCapability>) => boolean;
515
- requireAuth: typeof requireAuth;
420
+ requireAuth: <TData = unknown>(authOptions?: AuthCheckOptions) => import("payload").Access<TData>;
516
421
  requireRole: <TData = unknown>(role: TRole | readonly TRole[], checkOptions?: RoleCheckOptions) => import("payload").Access<TData>;
517
422
  requireCapability: <TData = unknown>(capability: TCapability | readonly TCapability[], guardOptions?: CapabilityCheckOptions<TRole, TCapability> & {
518
423
  mode?: "any" | "all";
519
424
  }) => import("payload").Access<TData>;
520
- requireFieldAuth: typeof requireFieldAuth;
521
- requireFieldRole: <TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(role: TRole | readonly TRole[], checkOptions?: RoleCheckOptions) => import("payload").FieldAccess<TData, TSiblingData>;
425
+ requireFieldAuth: <TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(authOptions?: AuthCheckOptions) => FieldAccess$1<TData, TSiblingData>;
426
+ requireFieldRole: <TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(role: TRole | readonly TRole[], checkOptions?: RoleCheckOptions) => FieldAccess$1<TData, TSiblingData>;
522
427
  requireFieldCapability: <TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(capability: TCapability | readonly TCapability[], guardOptions?: CapabilityCheckOptions<TRole, TCapability> & {
523
428
  mode?: "any" | "all";
524
- }) => import("payload").FieldAccess<TData, TSiblingData>;
429
+ }) => FieldAccess$1<TData, TSiblingData>;
525
430
  and: typeof and;
526
431
  or: typeof or;
527
432
  not: typeof not;
@@ -552,7 +457,7 @@ export declare function resetRbacConfig(): void;
552
457
  Extracts and normalizes the assigned roles of a user into an array of string identifiers.
553
458
 
554
459
  @param user - The user object to inspect, or null/undefined.
555
- @param rolesFieldName - Name of the field containing the role(s). Defaults to plugin config or `'role'`.
460
+ @param optionsOrFieldName - Role check options or explicit field name containing the role(s). Defaults to plugin config or `'role'`.
556
461
  @returns An array of trimmed, non-empty role identifiers.
557
462
 
558
463
  @example
@@ -689,5 +594,155 @@ const caps = resolveUserCapabilities(user, { roles: rolesConfig });
689
594
  ```
690
595
  */
691
596
  export declare function resolveUserCapabilities<TRole extends string = string, TCapability extends string = string>(user: UserLike | null | undefined, options?: CapabilityCheckOptions<TRole, TCapability>): Set<string>;
692
- export type { CapabilityCheckOptions, FieldAccess, FieldAccessArgs, RbacAccess, RbacAccessArguments, RbacFieldAccess, RbacFieldAccessArguments, RbacPluginOptions, RbacWhere, RequireCapabilityOptions, RoleCheckOptions, RoleDefinition, RolesConfig, TypeWithID, UserLike, WildcardCapability };
597
+ /**
598
+ Additional options when checking capabilities via `requireCapability` or `requireFieldCapability`.
599
+ */
600
+ interface RequireCapabilityOptions<TRole extends string = string, TCapability extends string = string> extends CapabilityCheckOptions<TRole, TCapability> {
601
+ /**
602
+ When an array of capabilities is provided:
603
+ - `'any'`: The user must satisfy at least one capability. (Default)
604
+ - `'all'`: The user must satisfy all provided capabilities.
605
+ @default 'any'
606
+ */
607
+ readonly mode?: "any" | "all";
608
+ }
609
+ /**
610
+ Creates an access rule requiring that the requesting client is an authenticated user.
611
+ When `userCollectionSlug` is configured (either in `options` or in the global RBAC config),
612
+ only users from that auth collection are accepted.
613
+
614
+ @param options - Optional authentication check overrides (e.g., `userCollectionSlug`).
615
+ @returns A Payload Access function returning true if an eligible user is present, false otherwise.
616
+
617
+ @example
618
+ ```typescript
619
+ export const Orders = {
620
+ access: {
621
+ create: requireAuth(),
622
+ },
623
+ };
624
+ ```
625
+ */
626
+ export declare function requireAuth<TData = unknown>(options?: AuthCheckOptions): Access<TData>;
627
+ /**
628
+ Creates an access rule requiring that the requesting user possesses one or more specified roles.
629
+
630
+ @param role - A single role name or array of acceptable roles.
631
+ @param options - Custom options for role extraction.
632
+ @returns A Payload Access rule returning boolean.
633
+
634
+ @example
635
+ ```typescript
636
+ access: {
637
+ delete: requireRole('admin'),
638
+ update: requireRole(['admin', 'operator']),
639
+ }
640
+ ```
641
+ */
642
+ export declare function requireRole<TRole extends string = string, TData = unknown>(role: TRole | readonly TRole[], options?: RoleCheckOptions): Access<TData>;
643
+ /**
644
+ Creates an access rule requiring that the requesting user possesses one or more specified capabilities.
645
+
646
+ @param capability - A single capability or array of capabilities.
647
+ @param options - Options for capability verification, including matching mode (`'any'` | `'all'`).
648
+ @returns A Payload Access rule returning boolean.
649
+
650
+ @example
651
+ ```typescript
652
+ access: {
653
+ read: requireCapability('orders:read'),
654
+ update: requireCapability(['orders:update', 'orders:manage'], { mode: 'any' }),
655
+ }
656
+ ```
657
+ */
658
+ export declare function requireCapability<TCapability extends string = string, TRole extends string = string, TData = unknown>(capability: TCapability | readonly TCapability[], options?: RequireCapabilityOptions<TRole, TCapability>): Access<TData>;
659
+ /**
660
+ Universal access rule that strictly denies collection or global access to everyone (public & authenticated).
661
+ Ideal for immutable collections, disabled actions (e.g. `delete: nobody`), or server-only models.
662
+
663
+ @returns Always returns `false`.
664
+ */
665
+ export declare const nobody: Access;
666
+ /**
667
+ Universal access rule that permits public access to everyone.
668
+ Ideal for public-facing collections, marketing pages, site settings, or public legal documents.
669
+
670
+ @returns Always returns `true`.
671
+ */
672
+ export declare const anyone: Access;
673
+ /**
674
+ Functional alias for `nobody`.
675
+ */
676
+ export declare const denyAll: Access;
677
+ /**
678
+ Functional alias for `anyone`.
679
+ */
680
+ export declare const allowAll: Access;
681
+ /**
682
+ Creates a field-level access rule requiring that the requesting client is an authenticated user.
683
+ When `userCollectionSlug` is configured (either in `options` or in the global RBAC config),
684
+ only users from that auth collection are accepted.
685
+
686
+ @param options - Optional authentication check overrides (e.g., `userCollectionSlug`).
687
+ @returns A Payload FieldAccess function returning true if an eligible user is authenticated, false otherwise.
688
+ */
689
+ export declare function requireFieldAuth<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(options?: AuthCheckOptions): FieldAccess$1<TData, TSiblingData>;
690
+ /**
691
+ Creates a field-level access rule requiring that the requesting user possesses one or more specified roles.
692
+
693
+ @param role - A single role name or array of acceptable roles.
694
+ @param options - Custom options for role extraction.
695
+ @returns A Payload FieldAccess rule returning boolean.
696
+ */
697
+ export declare function requireFieldRole<TRole extends string = string, TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(role: TRole | readonly TRole[], options?: RoleCheckOptions): FieldAccess$1<TData, TSiblingData>;
698
+ /**
699
+ Creates a field-level access rule requiring that the requesting user possesses one or more specified capabilities.
700
+
701
+ @param capability - A single capability or array of capabilities.
702
+ @param options - Options for capability verification, including matching mode (`'any'` | `'all'`).
703
+ @returns A Payload FieldAccess rule returning boolean.
704
+ */
705
+ export declare function requireFieldCapability<TCapability extends string = string, TRole extends string = string, TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(capability: TCapability | readonly TCapability[], options?: RequireCapabilityOptions<TRole, TCapability>): FieldAccess$1<TData, TSiblingData>;
706
+ /**
707
+ Universal field access rule that strictly denies field access to everyone (public & authenticated).
708
+
709
+ @returns Always returns `false`.
710
+ */
711
+ export declare const nobodyField: FieldAccess$1;
712
+ /**
713
+ Universal field access rule that permits field access to everyone.
714
+
715
+ @returns Always returns `true`.
716
+ */
717
+ export declare const anyoneField: FieldAccess$1;
718
+ /**
719
+ Functional alias for `nobodyField`.
720
+ */
721
+ export declare const denyField: FieldAccess$1;
722
+ /**
723
+ Functional alias for `anyoneField`.
724
+ */
725
+ export declare const allowField: FieldAccess$1;
726
+ /**
727
+ Configures field access for a strictly read-only field (cannot be created or updated via API).
728
+ The field remains readable according to the collection's read access rules, but API writes are denied.
729
+
730
+ @returns Field access object with create and update set to `nobodyField`.
731
+ */
732
+ export declare function readOnlyField<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(): {
733
+ create: FieldAccess$1<TData, TSiblingData>;
734
+ update: FieldAccess$1<TData, TSiblingData>;
735
+ };
736
+ /**
737
+ Configures field access for an internal system field that cannot be read, created, or updated via public API.
738
+ Only local server operations (with `overrideAccess: true` or internal services) can access or modify it.
739
+
740
+ @returns Field access object with create, read, and update set to `nobodyField`.
741
+ */
742
+ export declare function systemOnlyField<TData extends TypeWithID$1 = TypeWithID$1, TSiblingData = unknown>(): {
743
+ create: FieldAccess$1<TData, TSiblingData>;
744
+ read: FieldAccess$1<TData, TSiblingData>;
745
+ update: FieldAccess$1<TData, TSiblingData>;
746
+ };
747
+ export type { AuthCheckOptions, CapabilityCheckOptions, FieldAccess, FieldAccessArgs, RbacAccess, RbacAccessArguments, RbacFieldAccess, RbacFieldAccessArguments, RbacPluginOptions, RbacWhere, RequireCapabilityOptions, RoleCheckOptions, RoleDefinition, RolesConfig, TypeWithID, UserLike, WildcardCapability };
693
748
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["TypeWithID","FieldAccess","TypeWithID","FieldAccess","FieldAccessArgs","TypeWithID","FieldAccess","TypeWithID"],"sources":["../src/access/combinators.ts","../src/access/field-combinators.ts","../src/types.ts","../src/access/shared.ts","../src/access/field-guards.ts","../src/access/guards.ts","../src/capabilities/matcher.ts","../src/plugin.ts","../src/registry.ts","../src/roles/checker.ts","../src/capabilities/checker.ts","../src/capabilities/resolver.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0BgB,GAAG,oBAAoB,gBAAgB,OAAO,WAAW,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DhE,IAAI,oBAAoB,gBAAgB,OAAO,WAAW,OAAO;;;;;;;;;;;;;;;;;;;wBAwDjE,IAAI,iBAAiB,MAAM,OAAO,SAAS,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;wBCrHlD,QAAQ,cAAcA,eAAaA,cAAY,2BAC1D,gBAAgBC,cAAY,OAAO,kBACrCA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U,uBAAuB,OAAO,eACvC"}
1
+ {"version":3,"file":"index.d.ts","names":["TypeWithID","FieldAccess","TypeWithID","FieldAccess","FieldAccessArgs","TypeWithID","FieldAccess","TypeWithID","FieldAccess"],"sources":["../src/access/combinators.ts","../src/access/field-combinators.ts","../src/capabilities/matcher.ts","../src/types.ts","../src/plugin.ts","../src/registry.ts","../src/roles/checker.ts","../src/capabilities/checker.ts","../src/capabilities/resolver.ts","../src/access/shared.ts","../src/access/guards.ts","../src/access/field-guards.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0BgB,GAAG,oBAAoB,gBAAgB,OAAO,WAAW,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+DhE,IAAI,oBAAoB,gBAAgB,OAAO,WAAW,OAAO;;;;;;;;;;;;;;;;;;;wBA4DjE,IAAI,iBAAiB,MAAM,OAAO,SAAS,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;wBC1HlD,QAAQ,cAAcA,eAAaA,cAAY,2BAC1D,gBAAgBC,cAAY,OAAO,kBACrCA,cAAY,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCN,SAAS,cAAcD,eAAaA,cAAY,2BAC3D,gBAAgBC,cAAY,OAAO,kBACrCA,cAAY,OAAO;;;;;;;;;;;;;;;;;;wBAgCN,SAAS,cAAcD,eAAaA,cAAY,wBAC9D,MAAMC,cAAY,OAAO,gBACxBA,cAAY,OAAO;;;;;;;;;;;;;;;;;;;;wBCtFN,oBAAoB,wBAAwB;;;;;;KCZhD;;;;;UAMK,eACf,qCACA;;;;WAKS,iBAAiB;;;;WAKjB;;;;;WAMA,wBAAwB,cAAc;;;;WAKtC,oBAAoB,QAAQ;;;;;KAM3B,YACV,+BACA,uCACE,OAAO,OAAO,eAAe,aAAa,QAAQ;;;;UAKrC;WACN;WACA;WACA;WACA;WACA;WACA;YACC;;;;;UAMK;;;;;;WAMN;;;;;UAMM,uBACf,+BACA;;;;WAKS,QAAQ,YAA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