@objectstack/spec 2.0.4 → 2.0.5

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.
Files changed (54) hide show
  1. package/dist/contracts/index.d.mts +2 -2
  2. package/dist/contracts/index.d.ts +2 -2
  3. package/dist/data/index.d.mts +2 -2
  4. package/dist/data/index.d.ts +2 -2
  5. package/dist/data/index.js +482 -453
  6. package/dist/data/index.js.map +1 -1
  7. package/dist/data/index.mjs +481 -453
  8. package/dist/data/index.mjs.map +1 -1
  9. package/dist/{driver.zod-DddW_4lJ.d.mts → driver.zod-DnOPgUGi.d.mts} +430 -1
  10. package/dist/{driver.zod-BJHWEbwG.d.ts → driver.zod-E3C6n0W-.d.ts} +430 -1
  11. package/dist/{index-yvEIvpa3.d.ts → index-BPhGHW32.d.ts} +4 -2
  12. package/dist/{index-C8xlxqpA.d.ts → index-C6p-2KXV.d.ts} +1 -1
  13. package/dist/index-CDN6TRx9.d.mts +765 -0
  14. package/dist/index-CDN6TRx9.d.ts +765 -0
  15. package/dist/{index-wFiQRott.d.mts → index-CVnGe2b8.d.mts} +1 -1
  16. package/dist/{index-Cp6xnrOM.d.mts → index-D-tf4nDV.d.mts} +4 -2
  17. package/dist/{index-DOuMlF5h.d.ts → index-DyawwLFZ.d.ts} +31 -2
  18. package/dist/{index-DPlvQwlz.d.mts → index-E1mP_eoE.d.mts} +31 -2
  19. package/dist/index.d.mts +38 -799
  20. package/dist/index.d.ts +38 -799
  21. package/dist/index.js +8585 -8556
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +8585 -8556
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/kernel/index.d.mts +1 -1
  26. package/dist/kernel/index.d.ts +1 -1
  27. package/dist/kernel/index.js +23 -0
  28. package/dist/kernel/index.js.map +1 -1
  29. package/dist/kernel/index.mjs +22 -0
  30. package/dist/kernel/index.mjs.map +1 -1
  31. package/dist/security/index.d.mts +2 -0
  32. package/dist/security/index.d.ts +2 -0
  33. package/dist/security/index.js +666 -0
  34. package/dist/security/index.js.map +1 -0
  35. package/dist/security/index.mjs +616 -0
  36. package/dist/security/index.mjs.map +1 -0
  37. package/json-schema/data/BaseEngineOptions.json +49 -0
  38. package/json-schema/data/DataEngineAggregateOptions.json +42 -0
  39. package/json-schema/data/DataEngineAggregateRequest.json +42 -0
  40. package/json-schema/data/DataEngineBatchRequest.json +294 -0
  41. package/json-schema/data/DataEngineCountOptions.json +42 -0
  42. package/json-schema/data/DataEngineCountRequest.json +42 -0
  43. package/json-schema/data/DataEngineDeleteOptions.json +42 -0
  44. package/json-schema/data/DataEngineDeleteRequest.json +42 -0
  45. package/json-schema/data/DataEngineFindOneRequest.json +42 -0
  46. package/json-schema/data/DataEngineFindRequest.json +42 -0
  47. package/json-schema/data/DataEngineInsertOptions.json +42 -0
  48. package/json-schema/data/DataEngineInsertRequest.json +42 -0
  49. package/json-schema/data/DataEngineQueryOptions.json +42 -0
  50. package/json-schema/data/DataEngineRequest.json +588 -0
  51. package/json-schema/data/DataEngineUpdateOptions.json +42 -0
  52. package/json-schema/data/DataEngineUpdateRequest.json +42 -0
  53. package/json-schema/kernel/ExecutionContext.json +43 -0
  54. package/package.json +6 -1
@@ -0,0 +1,765 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Entity (Object) Level Permissions
5
+ * Defines CRUD + VAMA (View All / Modify All) + Lifecycle access.
6
+ *
7
+ * Refined with enterprise data lifecycle controls:
8
+ * - Transfer (Ownership change)
9
+ * - Restore (Soft delete recovery)
10
+ * - Purge (Hard delete / Compliance)
11
+ */
12
+ declare const ObjectPermissionSchema: z.ZodObject<{
13
+ allowCreate: z.ZodDefault<z.ZodBoolean>;
14
+ allowRead: z.ZodDefault<z.ZodBoolean>;
15
+ allowEdit: z.ZodDefault<z.ZodBoolean>;
16
+ allowDelete: z.ZodDefault<z.ZodBoolean>;
17
+ allowTransfer: z.ZodDefault<z.ZodBoolean>;
18
+ allowRestore: z.ZodDefault<z.ZodBoolean>;
19
+ allowPurge: z.ZodDefault<z.ZodBoolean>;
20
+ viewAllRecords: z.ZodDefault<z.ZodBoolean>;
21
+ modifyAllRecords: z.ZodDefault<z.ZodBoolean>;
22
+ }, z.core.$strip>;
23
+ /**
24
+ * Field Level Security (FLS)
25
+ */
26
+ declare const FieldPermissionSchema: z.ZodObject<{
27
+ readable: z.ZodDefault<z.ZodBoolean>;
28
+ editable: z.ZodDefault<z.ZodBoolean>;
29
+ }, z.core.$strip>;
30
+ /**
31
+ * Permission Set Schema
32
+ * Defines a collection of permissions that can be assigned to users.
33
+ *
34
+ * DIFFERENTIATION:
35
+ * - Profile: The ONE primary functional definition of a user (e.g. Standard User).
36
+ * - Permission Set: Add-on capabilities assigned to users (e.g. Export Reports).
37
+ * - Role: (Defined in src/system/role.zod.ts) Defines data visibility hierarchy.
38
+ *
39
+ * **NAMING CONVENTION:**
40
+ * Permission set names MUST be lowercase snake_case to prevent security issues.
41
+ *
42
+ * @example Good permission set names
43
+ * - 'read_only'
44
+ * - 'system_admin'
45
+ * - 'standard_user'
46
+ * - 'api_access'
47
+ *
48
+ * @example Bad permission set names (will be rejected)
49
+ * - 'ReadOnly' (camelCase)
50
+ * - 'SystemAdmin' (mixed case)
51
+ * - 'Read Only' (spaces)
52
+ */
53
+ declare const PermissionSetSchema: z.ZodObject<{
54
+ name: z.ZodString;
55
+ label: z.ZodOptional<z.ZodString>;
56
+ isProfile: z.ZodDefault<z.ZodBoolean>;
57
+ objects: z.ZodRecord<z.ZodString, z.ZodObject<{
58
+ allowCreate: z.ZodDefault<z.ZodBoolean>;
59
+ allowRead: z.ZodDefault<z.ZodBoolean>;
60
+ allowEdit: z.ZodDefault<z.ZodBoolean>;
61
+ allowDelete: z.ZodDefault<z.ZodBoolean>;
62
+ allowTransfer: z.ZodDefault<z.ZodBoolean>;
63
+ allowRestore: z.ZodDefault<z.ZodBoolean>;
64
+ allowPurge: z.ZodDefault<z.ZodBoolean>;
65
+ viewAllRecords: z.ZodDefault<z.ZodBoolean>;
66
+ modifyAllRecords: z.ZodDefault<z.ZodBoolean>;
67
+ }, z.core.$strip>>;
68
+ fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
69
+ readable: z.ZodDefault<z.ZodBoolean>;
70
+ editable: z.ZodDefault<z.ZodBoolean>;
71
+ }, z.core.$strip>>>;
72
+ systemPermissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
73
+ rowLevelSecurity: z.ZodOptional<z.ZodArray<z.ZodObject<{
74
+ name: z.ZodString;
75
+ label: z.ZodOptional<z.ZodString>;
76
+ description: z.ZodOptional<z.ZodString>;
77
+ object: z.ZodString;
78
+ operation: z.ZodEnum<{
79
+ insert: "insert";
80
+ update: "update";
81
+ delete: "delete";
82
+ select: "select";
83
+ all: "all";
84
+ }>;
85
+ using: z.ZodOptional<z.ZodString>;
86
+ check: z.ZodOptional<z.ZodString>;
87
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ enabled: z.ZodDefault<z.ZodBoolean>;
89
+ priority: z.ZodDefault<z.ZodNumber>;
90
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
91
+ }, z.core.$strip>>>;
92
+ contextVariables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
93
+ }, z.core.$strip>;
94
+ type PermissionSet = z.infer<typeof PermissionSetSchema>;
95
+ type ObjectPermission = z.infer<typeof ObjectPermissionSchema>;
96
+ type FieldPermission = z.infer<typeof FieldPermissionSchema>;
97
+
98
+ /**
99
+ * Organization-Wide Defaults (OWD)
100
+ * The baseline security posture for an object.
101
+ */
102
+ declare const OWDModel: z.ZodEnum<{
103
+ private: "private";
104
+ public_read: "public_read";
105
+ public_read_write: "public_read_write";
106
+ controlled_by_parent: "controlled_by_parent";
107
+ }>;
108
+ /**
109
+ * Sharing Rule Type
110
+ * How is the data shared?
111
+ */
112
+ declare const SharingRuleType: z.ZodEnum<{
113
+ owner: "owner";
114
+ criteria: "criteria";
115
+ }>;
116
+ /**
117
+ * Sharing Level
118
+ * What access is granted?
119
+ */
120
+ declare const SharingLevel: z.ZodEnum<{
121
+ full: "full";
122
+ read: "read";
123
+ edit: "edit";
124
+ }>;
125
+ /**
126
+ * Recipient Type
127
+ * Who receives the access?
128
+ */
129
+ declare const ShareRecipientType: z.ZodEnum<{
130
+ role: "role";
131
+ user: "user";
132
+ group: "group";
133
+ role_and_subordinates: "role_and_subordinates";
134
+ guest: "guest";
135
+ }>;
136
+ /**
137
+ * 1. Criteria-Based Sharing Rule
138
+ * Share records that meet specific field criteria.
139
+ */
140
+ declare const CriteriaSharingRuleSchema: z.ZodObject<{
141
+ name: z.ZodString;
142
+ label: z.ZodOptional<z.ZodString>;
143
+ description: z.ZodOptional<z.ZodString>;
144
+ object: z.ZodString;
145
+ active: z.ZodDefault<z.ZodBoolean>;
146
+ accessLevel: z.ZodDefault<z.ZodEnum<{
147
+ full: "full";
148
+ read: "read";
149
+ edit: "edit";
150
+ }>>;
151
+ sharedWith: z.ZodObject<{
152
+ type: z.ZodEnum<{
153
+ role: "role";
154
+ user: "user";
155
+ group: "group";
156
+ role_and_subordinates: "role_and_subordinates";
157
+ guest: "guest";
158
+ }>;
159
+ value: z.ZodString;
160
+ }, z.core.$strip>;
161
+ type: z.ZodLiteral<"criteria">;
162
+ condition: z.ZodString;
163
+ }, z.core.$strip>;
164
+ /**
165
+ * 2. Owner-Based Sharing Rule
166
+ * Share records owned by a specific group of users.
167
+ */
168
+ declare const OwnerSharingRuleSchema: z.ZodObject<{
169
+ name: z.ZodString;
170
+ label: z.ZodOptional<z.ZodString>;
171
+ description: z.ZodOptional<z.ZodString>;
172
+ object: z.ZodString;
173
+ active: z.ZodDefault<z.ZodBoolean>;
174
+ accessLevel: z.ZodDefault<z.ZodEnum<{
175
+ full: "full";
176
+ read: "read";
177
+ edit: "edit";
178
+ }>>;
179
+ sharedWith: z.ZodObject<{
180
+ type: z.ZodEnum<{
181
+ role: "role";
182
+ user: "user";
183
+ group: "group";
184
+ role_and_subordinates: "role_and_subordinates";
185
+ guest: "guest";
186
+ }>;
187
+ value: z.ZodString;
188
+ }, z.core.$strip>;
189
+ type: z.ZodLiteral<"owner">;
190
+ ownedBy: z.ZodObject<{
191
+ type: z.ZodEnum<{
192
+ role: "role";
193
+ user: "user";
194
+ group: "group";
195
+ role_and_subordinates: "role_and_subordinates";
196
+ guest: "guest";
197
+ }>;
198
+ value: z.ZodString;
199
+ }, z.core.$strip>;
200
+ }, z.core.$strip>;
201
+ /**
202
+ * Master Sharing Rule Schema
203
+ */
204
+ declare const SharingRuleSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
205
+ name: z.ZodString;
206
+ label: z.ZodOptional<z.ZodString>;
207
+ description: z.ZodOptional<z.ZodString>;
208
+ object: z.ZodString;
209
+ active: z.ZodDefault<z.ZodBoolean>;
210
+ accessLevel: z.ZodDefault<z.ZodEnum<{
211
+ full: "full";
212
+ read: "read";
213
+ edit: "edit";
214
+ }>>;
215
+ sharedWith: z.ZodObject<{
216
+ type: z.ZodEnum<{
217
+ role: "role";
218
+ user: "user";
219
+ group: "group";
220
+ role_and_subordinates: "role_and_subordinates";
221
+ guest: "guest";
222
+ }>;
223
+ value: z.ZodString;
224
+ }, z.core.$strip>;
225
+ type: z.ZodLiteral<"criteria">;
226
+ condition: z.ZodString;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ name: z.ZodString;
229
+ label: z.ZodOptional<z.ZodString>;
230
+ description: z.ZodOptional<z.ZodString>;
231
+ object: z.ZodString;
232
+ active: z.ZodDefault<z.ZodBoolean>;
233
+ accessLevel: z.ZodDefault<z.ZodEnum<{
234
+ full: "full";
235
+ read: "read";
236
+ edit: "edit";
237
+ }>>;
238
+ sharedWith: z.ZodObject<{
239
+ type: z.ZodEnum<{
240
+ role: "role";
241
+ user: "user";
242
+ group: "group";
243
+ role_and_subordinates: "role_and_subordinates";
244
+ guest: "guest";
245
+ }>;
246
+ value: z.ZodString;
247
+ }, z.core.$strip>;
248
+ type: z.ZodLiteral<"owner">;
249
+ ownedBy: z.ZodObject<{
250
+ type: z.ZodEnum<{
251
+ role: "role";
252
+ user: "user";
253
+ group: "group";
254
+ role_and_subordinates: "role_and_subordinates";
255
+ guest: "guest";
256
+ }>;
257
+ value: z.ZodString;
258
+ }, z.core.$strip>;
259
+ }, z.core.$strip>], "type">;
260
+ type SharingRule = z.infer<typeof SharingRuleSchema>;
261
+ type CriteriaSharingRule = z.infer<typeof CriteriaSharingRuleSchema>;
262
+ type OwnerSharingRule = z.infer<typeof OwnerSharingRuleSchema>;
263
+
264
+ /**
265
+ * Territory Management Protocol
266
+ * Defines a matrix reporting structure that exists parallel to the Role Hierarchy.
267
+ *
268
+ * USE CASE:
269
+ * - Enterprise Sales Teams (Geo-based: "EMEA", "APAC")
270
+ * - Industry Verticals (Industry-based: "Healthcare", "Financial")
271
+ * - Strategic Accounts (Account-based: "Strategic Accounts")
272
+ *
273
+ * DIFFERENCE FROM ROLE:
274
+ * - Role: Hierarchy of PEOPLE (Who reports to whom). Stable. HR-driven.
275
+ * - Territory: Hierarchy of ACCOUNTS/REVENUE (Who owns which market). Flexible. Sales-driven.
276
+ * - One User can be assigned to MANY Territories (Matrix).
277
+ * - One User has only ONE Role (Tree).
278
+ */
279
+ declare const TerritoryType: z.ZodEnum<{
280
+ geography: "geography";
281
+ industry: "industry";
282
+ named_account: "named_account";
283
+ product_line: "product_line";
284
+ }>;
285
+ /**
286
+ * Territory Model Schema
287
+ * A container for a version of territory planning.
288
+ * (e.g. "Fiscal Year 2024 Planning" vs "Fiscal Year 2025 Planning")
289
+ */
290
+ declare const TerritoryModelSchema: z.ZodObject<{
291
+ name: z.ZodString;
292
+ state: z.ZodDefault<z.ZodEnum<{
293
+ active: "active";
294
+ planning: "planning";
295
+ archived: "archived";
296
+ }>>;
297
+ startDate: z.ZodOptional<z.ZodString>;
298
+ endDate: z.ZodOptional<z.ZodString>;
299
+ }, z.core.$strip>;
300
+ /**
301
+ * Territory Node Schema
302
+ * A single node in the territory tree.
303
+ *
304
+ * **NAMING CONVENTION:**
305
+ * Territory names are machine identifiers and must be lowercase snake_case.
306
+ *
307
+ * @example Good territory names
308
+ * - 'west_coast'
309
+ * - 'emea_region'
310
+ * - 'healthcare_vertical'
311
+ * - 'strategic_accounts'
312
+ *
313
+ * @example Bad territory names (will be rejected)
314
+ * - 'WestCoast' (PascalCase)
315
+ * - 'West Coast' (spaces)
316
+ */
317
+ declare const TerritorySchema: z.ZodObject<{
318
+ name: z.ZodString;
319
+ label: z.ZodString;
320
+ modelId: z.ZodString;
321
+ parent: z.ZodOptional<z.ZodString>;
322
+ type: z.ZodDefault<z.ZodEnum<{
323
+ geography: "geography";
324
+ industry: "industry";
325
+ named_account: "named_account";
326
+ product_line: "product_line";
327
+ }>>;
328
+ assignmentRule: z.ZodOptional<z.ZodString>;
329
+ assignedUsers: z.ZodOptional<z.ZodArray<z.ZodString>>;
330
+ accountAccess: z.ZodDefault<z.ZodEnum<{
331
+ read: "read";
332
+ edit: "edit";
333
+ }>>;
334
+ opportunityAccess: z.ZodDefault<z.ZodEnum<{
335
+ read: "read";
336
+ edit: "edit";
337
+ }>>;
338
+ caseAccess: z.ZodDefault<z.ZodEnum<{
339
+ read: "read";
340
+ edit: "edit";
341
+ }>>;
342
+ }, z.core.$strip>;
343
+ type Territory = z.infer<typeof TerritorySchema>;
344
+ type TerritoryModel = z.infer<typeof TerritoryModelSchema>;
345
+
346
+ /**
347
+ * # Row-Level Security (RLS) Protocol
348
+ *
349
+ * Implements fine-grained record-level access control inspired by PostgreSQL RLS
350
+ * and Salesforce Criteria-Based Sharing Rules.
351
+ *
352
+ * ## Overview
353
+ *
354
+ * Row-Level Security (RLS) allows you to control which rows users can access
355
+ * in database tables based on their identity and role. Unlike object-level
356
+ * permissions (CRUD), RLS provides record-level filtering.
357
+ *
358
+ * ## Use Cases
359
+ *
360
+ * 1. **Multi-Tenant Data Isolation**
361
+ * - Users only see records from their organization
362
+ * - `using: "tenant_id = current_user.tenant_id"`
363
+ *
364
+ * 2. **Ownership-Based Access**
365
+ * - Users only see records they own
366
+ * - `using: "owner_id = current_user.id"`
367
+ *
368
+ * 3. **Department-Based Access**
369
+ * - Users only see records from their department
370
+ * - `using: "department = current_user.department"`
371
+ *
372
+ * 4. **Regional Access Control**
373
+ * - Sales reps only see accounts in their territory
374
+ * - `using: "region IN (current_user.assigned_regions)"`
375
+ *
376
+ * 5. **Time-Based Access**
377
+ * - Users can only access active records
378
+ * - `using: "status = 'active' AND expiry_date > NOW()"`
379
+ *
380
+ * ## PostgreSQL RLS Comparison
381
+ *
382
+ * PostgreSQL RLS Example:
383
+ * ```sql
384
+ * CREATE POLICY tenant_isolation ON accounts
385
+ * FOR SELECT
386
+ * USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
387
+ *
388
+ * CREATE POLICY account_insert ON accounts
389
+ * FOR INSERT
390
+ * WITH CHECK (tenant_id = current_setting('app.current_tenant_id')::uuid);
391
+ * ```
392
+ *
393
+ * ObjectStack RLS Equivalent:
394
+ * ```typescript
395
+ * {
396
+ * name: 'tenant_isolation',
397
+ * object: 'account',
398
+ * operation: 'select',
399
+ * using: 'tenant_id = current_user.tenant_id'
400
+ * }
401
+ * ```
402
+ *
403
+ * ## Salesforce Sharing Rules Comparison
404
+ *
405
+ * Salesforce uses "Sharing Rules" and "Role Hierarchy" for record-level access.
406
+ * ObjectStack RLS provides similar functionality with more flexibility.
407
+ *
408
+ * Salesforce:
409
+ * - Criteria-Based Sharing: Share records matching criteria with users/roles
410
+ * - Owner-Based Sharing: Share records based on owner's role
411
+ * - Manual Sharing: Individual record sharing
412
+ *
413
+ * ObjectStack RLS:
414
+ * - More flexible formula-based conditions
415
+ * - Direct SQL-like syntax
416
+ * - Supports complex logic with AND/OR/NOT
417
+ *
418
+ * ## Best Practices
419
+ *
420
+ * 1. **Always Define SELECT Policy**: Control what users can view
421
+ * 2. **Define INSERT/UPDATE CHECK Policies**: Prevent data leakage
422
+ * 3. **Use Role-Based Policies**: Apply different rules to different roles
423
+ * 4. **Test Thoroughly**: RLS can have complex interactions
424
+ * 5. **Monitor Performance**: Complex RLS policies can impact query performance
425
+ *
426
+ * ## Security Considerations
427
+ *
428
+ * 1. **Defense in Depth**: RLS is one layer; use with object permissions
429
+ * 2. **Default Deny**: If no policy matches, access is denied
430
+ * 3. **Policy Precedence**: More permissive policy wins (OR logic)
431
+ * 4. **Context Variables**: Ensure current_user context is always set
432
+ *
433
+ * @see https://www.postgresql.org/docs/current/ddl-rowsecurity.html
434
+ * @see https://help.salesforce.com/s/articleView?id=sf.security_sharing_rules.htm
435
+ */
436
+ /**
437
+ * RLS Operation Enum
438
+ * Specifies which database operation this policy applies to.
439
+ *
440
+ * - **select**: Controls which rows can be read (SELECT queries)
441
+ * - **insert**: Controls which rows can be inserted (INSERT statements)
442
+ * - **update**: Controls which rows can be updated (UPDATE statements)
443
+ * - **delete**: Controls which rows can be deleted (DELETE statements)
444
+ * - **all**: Shorthand for all operations (equivalent to defining 4 separate policies)
445
+ */
446
+ declare const RLSOperation: z.ZodEnum<{
447
+ insert: "insert";
448
+ update: "update";
449
+ delete: "delete";
450
+ select: "select";
451
+ all: "all";
452
+ }>;
453
+ type RLSOperation = z.infer<typeof RLSOperation>;
454
+ /**
455
+ * Row-Level Security Policy Schema
456
+ *
457
+ * Defines a single RLS policy that filters records based on conditions.
458
+ * Multiple policies can be defined for the same object, and they are
459
+ * combined with OR logic (union of results).
460
+ *
461
+ * @example Multi-Tenant Isolation
462
+ * ```typescript
463
+ * {
464
+ * name: 'tenant_isolation',
465
+ * label: 'Multi-Tenant Data Isolation',
466
+ * object: 'account',
467
+ * operation: 'select',
468
+ * using: 'tenant_id = current_user.tenant_id',
469
+ * enabled: true
470
+ * }
471
+ * ```
472
+ *
473
+ * @example Owner-Based Access
474
+ * ```typescript
475
+ * {
476
+ * name: 'owner_access',
477
+ * label: 'Users Can View Their Own Records',
478
+ * object: 'opportunity',
479
+ * operation: 'select',
480
+ * using: 'owner_id = current_user.id',
481
+ * enabled: true
482
+ * }
483
+ * ```
484
+ *
485
+ * @example Manager Can View Team Records
486
+ * ```typescript
487
+ * {
488
+ * name: 'manager_team_access',
489
+ * label: 'Managers Can View Team Records',
490
+ * object: 'task',
491
+ * operation: 'select',
492
+ * using: 'assigned_to_id IN (SELECT id FROM users WHERE manager_id = current_user.id)',
493
+ * roles: ['manager', 'director'],
494
+ * enabled: true
495
+ * }
496
+ * ```
497
+ *
498
+ * @example Prevent Cross-Tenant Data Insertion
499
+ * ```typescript
500
+ * {
501
+ * name: 'tenant_insert_check',
502
+ * label: 'Prevent Cross-Tenant Data Creation',
503
+ * object: 'account',
504
+ * operation: 'insert',
505
+ * check: 'tenant_id = current_user.tenant_id',
506
+ * enabled: true
507
+ * }
508
+ * ```
509
+ *
510
+ * @example Regional Sales Access
511
+ * ```typescript
512
+ * {
513
+ * name: 'regional_sales_access',
514
+ * label: 'Sales Reps Access Regional Accounts',
515
+ * object: 'account',
516
+ * operation: 'select',
517
+ * using: 'region = current_user.region OR region IS NULL',
518
+ * roles: ['sales_rep'],
519
+ * enabled: true
520
+ * }
521
+ * ```
522
+ *
523
+ * @example Time-Based Access Control
524
+ * ```typescript
525
+ * {
526
+ * name: 'active_records_only',
527
+ * label: 'Users Only Access Active Records',
528
+ * object: 'contract',
529
+ * operation: 'select',
530
+ * using: 'status = "active" AND start_date <= NOW() AND end_date >= NOW()',
531
+ * enabled: true
532
+ * }
533
+ * ```
534
+ *
535
+ * @example Hierarchical Access (Role-Based)
536
+ * ```typescript
537
+ * {
538
+ * name: 'executive_full_access',
539
+ * label: 'Executives See All Records',
540
+ * object: 'account',
541
+ * operation: 'all',
542
+ * using: '1 = 1', // Always true - see everything
543
+ * roles: ['ceo', 'cfo', 'cto'],
544
+ * enabled: true
545
+ * }
546
+ * ```
547
+ */
548
+ declare const RowLevelSecurityPolicySchema: z.ZodObject<{
549
+ name: z.ZodString;
550
+ label: z.ZodOptional<z.ZodString>;
551
+ description: z.ZodOptional<z.ZodString>;
552
+ object: z.ZodString;
553
+ operation: z.ZodEnum<{
554
+ insert: "insert";
555
+ update: "update";
556
+ delete: "delete";
557
+ select: "select";
558
+ all: "all";
559
+ }>;
560
+ using: z.ZodOptional<z.ZodString>;
561
+ check: z.ZodOptional<z.ZodString>;
562
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
563
+ enabled: z.ZodDefault<z.ZodBoolean>;
564
+ priority: z.ZodDefault<z.ZodNumber>;
565
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
566
+ }, z.core.$strip>;
567
+ /**
568
+ * RLS Configuration Schema
569
+ *
570
+ * Global configuration for the Row-Level Security system.
571
+ * Defines how RLS is enforced across the entire platform.
572
+ */
573
+ declare const RLSConfigSchema: z.ZodObject<{
574
+ enabled: z.ZodDefault<z.ZodBoolean>;
575
+ defaultPolicy: z.ZodDefault<z.ZodEnum<{
576
+ deny: "deny";
577
+ allow: "allow";
578
+ }>>;
579
+ allowSuperuserBypass: z.ZodDefault<z.ZodBoolean>;
580
+ bypassRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
581
+ logEvaluations: z.ZodDefault<z.ZodBoolean>;
582
+ cacheResults: z.ZodDefault<z.ZodBoolean>;
583
+ cacheTtlSeconds: z.ZodDefault<z.ZodNumber>;
584
+ prefetchUserContext: z.ZodDefault<z.ZodBoolean>;
585
+ }, z.core.$strip>;
586
+ /**
587
+ * User Context Schema
588
+ *
589
+ * Represents the current user's context for RLS evaluation.
590
+ * This data is used to evaluate USING and CHECK clauses.
591
+ */
592
+ declare const RLSUserContextSchema: z.ZodObject<{
593
+ id: z.ZodString;
594
+ email: z.ZodOptional<z.ZodString>;
595
+ tenantId: z.ZodOptional<z.ZodString>;
596
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
597
+ department: z.ZodOptional<z.ZodString>;
598
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
599
+ }, z.core.$strip>;
600
+ /**
601
+ * RLS Policy Evaluation Result
602
+ *
603
+ * Result of evaluating an RLS policy for a specific record.
604
+ * Used for debugging and audit logging.
605
+ */
606
+ declare const RLSEvaluationResultSchema: z.ZodObject<{
607
+ policyName: z.ZodString;
608
+ granted: z.ZodBoolean;
609
+ durationMs: z.ZodOptional<z.ZodNumber>;
610
+ error: z.ZodOptional<z.ZodString>;
611
+ usingResult: z.ZodOptional<z.ZodBoolean>;
612
+ checkResult: z.ZodOptional<z.ZodBoolean>;
613
+ }, z.core.$strip>;
614
+ /**
615
+ * Type exports
616
+ */
617
+ type RowLevelSecurityPolicy = z.infer<typeof RowLevelSecurityPolicySchema>;
618
+ type RLSConfig = z.infer<typeof RLSConfigSchema>;
619
+ type RLSUserContext = z.infer<typeof RLSUserContextSchema>;
620
+ type RLSEvaluationResult = z.infer<typeof RLSEvaluationResultSchema>;
621
+ /**
622
+ * Helper factory for creating RLS policies
623
+ */
624
+ declare const RLS: {
625
+ /**
626
+ * Create a simple owner-based policy
627
+ */
628
+ readonly ownerPolicy: (object: string, ownerField?: string) => RowLevelSecurityPolicy;
629
+ /**
630
+ * Create a tenant isolation policy
631
+ */
632
+ readonly tenantPolicy: (object: string, tenantField?: string) => RowLevelSecurityPolicy;
633
+ /**
634
+ * Create a role-based policy
635
+ */
636
+ readonly rolePolicy: (object: string, roles: string[], condition: string) => RowLevelSecurityPolicy;
637
+ /**
638
+ * Create a permissive policy (allow all for specific roles)
639
+ */
640
+ readonly allowAllPolicy: (object: string, roles: string[]) => RowLevelSecurityPolicy;
641
+ };
642
+
643
+ /**
644
+ * Password Complexity Policy
645
+ */
646
+ declare const PasswordPolicySchema: z.ZodObject<{
647
+ minLength: z.ZodDefault<z.ZodNumber>;
648
+ requireUppercase: z.ZodDefault<z.ZodBoolean>;
649
+ requireLowercase: z.ZodDefault<z.ZodBoolean>;
650
+ requireNumbers: z.ZodDefault<z.ZodBoolean>;
651
+ requireSymbols: z.ZodDefault<z.ZodBoolean>;
652
+ expirationDays: z.ZodOptional<z.ZodNumber>;
653
+ historyCount: z.ZodDefault<z.ZodNumber>;
654
+ }, z.core.$strip>;
655
+ /**
656
+ * Network Access Policy (IP Whitelisting)
657
+ */
658
+ declare const NetworkPolicySchema: z.ZodObject<{
659
+ trustedRanges: z.ZodArray<z.ZodString>;
660
+ blockUnknown: z.ZodDefault<z.ZodBoolean>;
661
+ vpnRequired: z.ZodDefault<z.ZodBoolean>;
662
+ }, z.core.$strip>;
663
+ /**
664
+ * Session Policy
665
+ */
666
+ declare const SessionPolicySchema: z.ZodObject<{
667
+ idleTimeout: z.ZodDefault<z.ZodNumber>;
668
+ absoluteTimeout: z.ZodDefault<z.ZodNumber>;
669
+ forceMfa: z.ZodDefault<z.ZodBoolean>;
670
+ }, z.core.$strip>;
671
+ /**
672
+ * Audit Retention Policy
673
+ */
674
+ declare const AuditPolicySchema: z.ZodObject<{
675
+ logRetentionDays: z.ZodDefault<z.ZodNumber>;
676
+ sensitiveFields: z.ZodArray<z.ZodString>;
677
+ captureRead: z.ZodDefault<z.ZodBoolean>;
678
+ }, z.core.$strip>;
679
+ /**
680
+ * Security Policy Schema
681
+ * "The Cloud Compliance Contract"
682
+ */
683
+ declare const PolicySchema: z.ZodObject<{
684
+ name: z.ZodString;
685
+ password: z.ZodOptional<z.ZodObject<{
686
+ minLength: z.ZodDefault<z.ZodNumber>;
687
+ requireUppercase: z.ZodDefault<z.ZodBoolean>;
688
+ requireLowercase: z.ZodDefault<z.ZodBoolean>;
689
+ requireNumbers: z.ZodDefault<z.ZodBoolean>;
690
+ requireSymbols: z.ZodDefault<z.ZodBoolean>;
691
+ expirationDays: z.ZodOptional<z.ZodNumber>;
692
+ historyCount: z.ZodDefault<z.ZodNumber>;
693
+ }, z.core.$strip>>;
694
+ network: z.ZodOptional<z.ZodObject<{
695
+ trustedRanges: z.ZodArray<z.ZodString>;
696
+ blockUnknown: z.ZodDefault<z.ZodBoolean>;
697
+ vpnRequired: z.ZodDefault<z.ZodBoolean>;
698
+ }, z.core.$strip>>;
699
+ session: z.ZodOptional<z.ZodObject<{
700
+ idleTimeout: z.ZodDefault<z.ZodNumber>;
701
+ absoluteTimeout: z.ZodDefault<z.ZodNumber>;
702
+ forceMfa: z.ZodDefault<z.ZodBoolean>;
703
+ }, z.core.$strip>>;
704
+ audit: z.ZodOptional<z.ZodObject<{
705
+ logRetentionDays: z.ZodDefault<z.ZodNumber>;
706
+ sensitiveFields: z.ZodArray<z.ZodString>;
707
+ captureRead: z.ZodDefault<z.ZodBoolean>;
708
+ }, z.core.$strip>>;
709
+ isDefault: z.ZodDefault<z.ZodBoolean>;
710
+ assignedProfiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
711
+ }, z.core.$strip>;
712
+ type Policy = z.infer<typeof PolicySchema>;
713
+
714
+ /**
715
+ * Permission Protocol Exports
716
+ *
717
+ * Fine-grained Access Control
718
+ * - Permission Sets (CRUD + Field-Level Security)
719
+ * - Sharing Rules (Record Ownership)
720
+ * - Territory Management (Geographic/Hierarchical)
721
+ * - Row-Level Security (RLS - PostgreSQL-style)
722
+ */
723
+
724
+ declare const index_AuditPolicySchema: typeof AuditPolicySchema;
725
+ type index_CriteriaSharingRule = CriteriaSharingRule;
726
+ declare const index_CriteriaSharingRuleSchema: typeof CriteriaSharingRuleSchema;
727
+ type index_FieldPermission = FieldPermission;
728
+ declare const index_FieldPermissionSchema: typeof FieldPermissionSchema;
729
+ declare const index_NetworkPolicySchema: typeof NetworkPolicySchema;
730
+ declare const index_OWDModel: typeof OWDModel;
731
+ type index_ObjectPermission = ObjectPermission;
732
+ declare const index_ObjectPermissionSchema: typeof ObjectPermissionSchema;
733
+ type index_OwnerSharingRule = OwnerSharingRule;
734
+ declare const index_OwnerSharingRuleSchema: typeof OwnerSharingRuleSchema;
735
+ declare const index_PasswordPolicySchema: typeof PasswordPolicySchema;
736
+ type index_PermissionSet = PermissionSet;
737
+ declare const index_PermissionSetSchema: typeof PermissionSetSchema;
738
+ type index_Policy = Policy;
739
+ declare const index_PolicySchema: typeof PolicySchema;
740
+ declare const index_RLS: typeof RLS;
741
+ type index_RLSConfig = RLSConfig;
742
+ declare const index_RLSConfigSchema: typeof RLSConfigSchema;
743
+ type index_RLSEvaluationResult = RLSEvaluationResult;
744
+ declare const index_RLSEvaluationResultSchema: typeof RLSEvaluationResultSchema;
745
+ type index_RLSOperation = RLSOperation;
746
+ type index_RLSUserContext = RLSUserContext;
747
+ declare const index_RLSUserContextSchema: typeof RLSUserContextSchema;
748
+ type index_RowLevelSecurityPolicy = RowLevelSecurityPolicy;
749
+ declare const index_RowLevelSecurityPolicySchema: typeof RowLevelSecurityPolicySchema;
750
+ declare const index_SessionPolicySchema: typeof SessionPolicySchema;
751
+ declare const index_ShareRecipientType: typeof ShareRecipientType;
752
+ declare const index_SharingLevel: typeof SharingLevel;
753
+ type index_SharingRule = SharingRule;
754
+ declare const index_SharingRuleSchema: typeof SharingRuleSchema;
755
+ declare const index_SharingRuleType: typeof SharingRuleType;
756
+ type index_Territory = Territory;
757
+ type index_TerritoryModel = TerritoryModel;
758
+ declare const index_TerritoryModelSchema: typeof TerritoryModelSchema;
759
+ declare const index_TerritorySchema: typeof TerritorySchema;
760
+ declare const index_TerritoryType: typeof TerritoryType;
761
+ declare namespace index {
762
+ export { index_AuditPolicySchema as AuditPolicySchema, type index_CriteriaSharingRule as CriteriaSharingRule, index_CriteriaSharingRuleSchema as CriteriaSharingRuleSchema, type index_FieldPermission as FieldPermission, index_FieldPermissionSchema as FieldPermissionSchema, index_NetworkPolicySchema as NetworkPolicySchema, index_OWDModel as OWDModel, type index_ObjectPermission as ObjectPermission, index_ObjectPermissionSchema as ObjectPermissionSchema, type index_OwnerSharingRule as OwnerSharingRule, index_OwnerSharingRuleSchema as OwnerSharingRuleSchema, index_PasswordPolicySchema as PasswordPolicySchema, type index_PermissionSet as PermissionSet, index_PermissionSetSchema as PermissionSetSchema, type index_Policy as Policy, index_PolicySchema as PolicySchema, index_RLS as RLS, type index_RLSConfig as RLSConfig, index_RLSConfigSchema as RLSConfigSchema, type index_RLSEvaluationResult as RLSEvaluationResult, index_RLSEvaluationResultSchema as RLSEvaluationResultSchema, type index_RLSOperation as RLSOperation, type index_RLSUserContext as RLSUserContext, index_RLSUserContextSchema as RLSUserContextSchema, type index_RowLevelSecurityPolicy as RowLevelSecurityPolicy, index_RowLevelSecurityPolicySchema as RowLevelSecurityPolicySchema, index_SessionPolicySchema as SessionPolicySchema, index_ShareRecipientType as ShareRecipientType, index_SharingLevel as SharingLevel, type index_SharingRule as SharingRule, index_SharingRuleSchema as SharingRuleSchema, index_SharingRuleType as SharingRuleType, type index_Territory as Territory, type index_TerritoryModel as TerritoryModel, index_TerritoryModelSchema as TerritoryModelSchema, index_TerritorySchema as TerritorySchema, index_TerritoryType as TerritoryType };
763
+ }
764
+
765
+ export { SessionPolicySchema as A, AuditPolicySchema as B, CriteriaSharingRuleSchema as C, PolicySchema as D, type Policy as E, FieldPermissionSchema as F, NetworkPolicySchema as N, ObjectPermissionSchema as O, PermissionSetSchema as P, RLSOperation as R, SharingRuleType as S, TerritoryType as T, type PermissionSet as a, type ObjectPermission as b, type FieldPermission as c, OWDModel as d, SharingLevel as e, ShareRecipientType as f, OwnerSharingRuleSchema as g, SharingRuleSchema as h, index as i, type SharingRule as j, type CriteriaSharingRule as k, type OwnerSharingRule as l, TerritoryModelSchema as m, TerritorySchema as n, type Territory as o, type TerritoryModel as p, RowLevelSecurityPolicySchema as q, RLSConfigSchema as r, RLSUserContextSchema as s, RLSEvaluationResultSchema as t, type RowLevelSecurityPolicy as u, type RLSConfig as v, type RLSUserContext as w, type RLSEvaluationResult as x, RLS as y, PasswordPolicySchema as z };