@objectstack/spec 0.3.3 → 0.4.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.
Files changed (304) hide show
  1. package/dist/ai/conversation.zod.d.ts +14 -14
  2. package/dist/ai/cost.zod.d.ts +112 -112
  3. package/dist/ai/model-registry.zod.d.ts +44 -44
  4. package/dist/ai/nlq.zod.d.ts +2 -2
  5. package/dist/ai/orchestration.zod.d.ts +6 -6
  6. package/dist/ai/predictive.zod.d.ts +8 -8
  7. package/dist/ai/rag-pipeline.zod.d.ts +62 -62
  8. package/dist/api/contract.zod.d.ts +92 -92
  9. package/dist/api/discovery.zod.d.ts +2 -2
  10. package/dist/api/index.d.ts +2 -0
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/api/index.js +2 -0
  13. package/dist/api/odata.zod.d.ts +482 -0
  14. package/dist/api/odata.zod.d.ts.map +1 -0
  15. package/dist/api/odata.zod.js +401 -0
  16. package/dist/api/router.zod.d.ts +4 -4
  17. package/dist/auth/config.zod.d.ts +21 -21
  18. package/dist/auth/index.d.ts +1 -0
  19. package/dist/auth/index.d.ts.map +1 -1
  20. package/dist/auth/index.js +1 -0
  21. package/dist/auth/organization.zod.d.ts +2 -2
  22. package/dist/auth/role.zod.d.ts +14 -0
  23. package/dist/auth/role.zod.d.ts.map +1 -1
  24. package/dist/auth/role.zod.js +16 -1
  25. package/dist/auth/scim.zod.d.ts +2732 -0
  26. package/dist/auth/scim.zod.d.ts.map +1 -0
  27. package/dist/auth/scim.zod.js +811 -0
  28. package/dist/automation/approval.zod.d.ts +643 -0
  29. package/dist/automation/approval.zod.d.ts.map +1 -0
  30. package/dist/automation/approval.zod.js +84 -0
  31. package/dist/automation/connector.zod.d.ts +1284 -0
  32. package/dist/automation/connector.zod.d.ts.map +1 -0
  33. package/dist/automation/connector.zod.js +500 -0
  34. package/dist/automation/etl.zod.d.ts +623 -0
  35. package/dist/automation/etl.zod.d.ts.map +1 -0
  36. package/dist/automation/etl.zod.js +359 -0
  37. package/dist/automation/flow.zod.d.ts +6 -6
  38. package/dist/automation/index.d.ts +4 -0
  39. package/dist/automation/index.d.ts.map +1 -1
  40. package/dist/automation/index.js +4 -0
  41. package/dist/automation/sync.zod.d.ts +854 -0
  42. package/dist/automation/sync.zod.d.ts.map +1 -0
  43. package/dist/automation/sync.zod.js +444 -0
  44. package/dist/automation/webhook.zod.d.ts +24 -1
  45. package/dist/automation/webhook.zod.d.ts.map +1 -1
  46. package/dist/automation/webhook.zod.js +27 -3
  47. package/dist/automation/workflow.zod.d.ts +14 -0
  48. package/dist/automation/workflow.zod.d.ts.map +1 -1
  49. package/dist/automation/workflow.zod.js +16 -1
  50. package/dist/data/field.zod.d.ts +338 -8
  51. package/dist/data/field.zod.d.ts.map +1 -1
  52. package/dist/data/field.zod.js +100 -16
  53. package/dist/data/mapping.zod.d.ts +22 -10
  54. package/dist/data/mapping.zod.d.ts.map +1 -1
  55. package/dist/data/mapping.zod.js +16 -3
  56. package/dist/data/object.zod.d.ts +116 -22
  57. package/dist/data/object.zod.d.ts.map +1 -1
  58. package/dist/data/object.zod.js +4 -4
  59. package/dist/data/validation.zod.d.ts +18 -18
  60. package/dist/hub/composer.zod.d.ts +43 -1940
  61. package/dist/hub/composer.zod.d.ts.map +1 -1
  62. package/dist/hub/composer.zod.js +1 -1
  63. package/dist/hub/license.zod.d.ts +2 -2
  64. package/dist/hub/marketplace.zod.d.ts +6 -6
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +6 -3
  68. package/dist/permission/index.d.ts +7 -5
  69. package/dist/permission/index.d.ts.map +1 -1
  70. package/dist/permission/index.js +7 -5
  71. package/dist/permission/permission.zod.d.ts +14 -0
  72. package/dist/permission/permission.zod.d.ts.map +1 -1
  73. package/dist/permission/permission.zod.js +16 -1
  74. package/dist/permission/rls.zod.d.ts +605 -0
  75. package/dist/permission/rls.zod.d.ts.map +1 -0
  76. package/dist/permission/rls.zod.js +615 -0
  77. package/dist/permission/territory.zod.d.ts +13 -0
  78. package/dist/permission/territory.zod.d.ts.map +1 -1
  79. package/dist/permission/territory.zod.js +15 -1
  80. package/dist/shared/identifiers.zod.d.ts +87 -0
  81. package/dist/shared/identifiers.zod.d.ts.map +1 -0
  82. package/dist/shared/identifiers.zod.js +101 -0
  83. package/dist/shared/index.d.ts +6 -0
  84. package/dist/shared/index.d.ts.map +1 -0
  85. package/dist/{driver → shared}/index.js +5 -4
  86. package/dist/stack.zod.d.ts +19869 -0
  87. package/dist/stack.zod.d.ts.map +1 -0
  88. package/dist/stack.zod.js +248 -0
  89. package/dist/system/audit.zod.d.ts +12 -12
  90. package/dist/{kernel → system}/context.zod.d.ts.map +1 -1
  91. package/dist/{driver → system}/datasource.zod.d.ts +2 -2
  92. package/dist/{driver → system}/datasource.zod.d.ts.map +1 -1
  93. package/dist/{driver → system/driver}/mongo.zod.d.ts +2 -2
  94. package/dist/system/driver/mongo.zod.d.ts.map +1 -0
  95. package/dist/{driver → system/driver}/postgres.zod.d.ts +4 -4
  96. package/dist/system/driver/postgres.zod.d.ts.map +1 -0
  97. package/dist/{driver → system}/driver.zod.d.ts +14 -14
  98. package/dist/{driver → system}/driver.zod.d.ts.map +1 -1
  99. package/dist/system/events.zod.d.ts +15 -12
  100. package/dist/system/events.zod.d.ts.map +1 -1
  101. package/dist/system/events.zod.js +5 -1
  102. package/dist/system/feature.zod.d.ts +131 -0
  103. package/dist/system/feature.zod.d.ts.map +1 -0
  104. package/dist/system/feature.zod.js +45 -0
  105. package/dist/system/index.d.ts +10 -0
  106. package/dist/system/index.d.ts.map +1 -1
  107. package/dist/system/index.js +12 -0
  108. package/dist/system/job.zod.d.ts +8 -8
  109. package/dist/{kernel → system}/logger.zod.d.ts +4 -4
  110. package/dist/{kernel → system}/logger.zod.d.ts.map +1 -1
  111. package/dist/system/manifest.zod.d.ts +518 -0
  112. package/dist/system/manifest.zod.d.ts.map +1 -0
  113. package/dist/{kernel → system}/manifest.zod.js +8 -17
  114. package/dist/{kernel → system}/plugin.zod.d.ts.map +1 -1
  115. package/dist/{kernel → system}/scoped-storage.zod.d.ts +2 -2
  116. package/dist/{kernel → system}/scoped-storage.zod.d.ts.map +1 -1
  117. package/dist/ui/action.zod.d.ts +35 -10
  118. package/dist/ui/action.zod.d.ts.map +1 -1
  119. package/dist/ui/action.zod.js +30 -1
  120. package/dist/ui/app.zod.d.ts +23 -8
  121. package/dist/ui/app.zod.d.ts.map +1 -1
  122. package/dist/ui/app.zod.js +32 -4
  123. package/dist/ui/block.zod.d.ts +265 -0
  124. package/dist/ui/block.zod.d.ts.map +1 -0
  125. package/dist/ui/block.zod.js +90 -0
  126. package/dist/ui/component.zod.d.ts +265 -0
  127. package/dist/ui/component.zod.d.ts.map +1 -0
  128. package/dist/ui/component.zod.js +90 -0
  129. package/dist/ui/dashboard.zod.d.ts +15 -15
  130. package/dist/ui/dashboard.zod.d.ts.map +1 -1
  131. package/dist/ui/dashboard.zod.js +18 -8
  132. package/dist/ui/index.d.ts +1 -0
  133. package/dist/ui/index.d.ts.map +1 -1
  134. package/dist/ui/index.js +1 -0
  135. package/dist/ui/page.zod.d.ts +21 -3
  136. package/dist/ui/page.zod.d.ts.map +1 -1
  137. package/dist/ui/page.zod.js +37 -4
  138. package/dist/ui/report.zod.d.ts +7 -7
  139. package/dist/ui/view.zod.d.ts +252 -240
  140. package/dist/ui/view.zod.d.ts.map +1 -1
  141. package/dist/ui/view.zod.js +32 -3
  142. package/dist/ui/widget.zod.d.ts +673 -5
  143. package/dist/ui/widget.zod.d.ts.map +1 -1
  144. package/dist/ui/widget.zod.js +294 -1
  145. package/json-schema/api/ODataError.json +65 -0
  146. package/json-schema/api/ODataFilterFunction.json +39 -0
  147. package/json-schema/api/ODataFilterOperator.json +24 -0
  148. package/json-schema/api/ODataMetadata.json +115 -0
  149. package/json-schema/api/ODataQuery.json +89 -0
  150. package/json-schema/api/ODataResponse.json +37 -0
  151. package/json-schema/auth/Role.json +3 -2
  152. package/json-schema/auth/SCIMAddress.json +50 -0
  153. package/json-schema/auth/SCIMEmail.json +38 -0
  154. package/json-schema/auth/SCIMEnterpriseUser.json +55 -0
  155. package/json-schema/auth/SCIMError.json +52 -0
  156. package/json-schema/auth/SCIMGroup.json +102 -0
  157. package/json-schema/auth/SCIMGroupReference.json +36 -0
  158. package/json-schema/auth/SCIMListResponse.json +606 -0
  159. package/json-schema/auth/SCIMMemberReference.json +36 -0
  160. package/json-schema/auth/SCIMMeta.json +35 -0
  161. package/json-schema/auth/SCIMName.json +36 -0
  162. package/json-schema/auth/SCIMPatchOperation.json +31 -0
  163. package/json-schema/auth/SCIMPatchRequest.json +56 -0
  164. package/json-schema/auth/SCIMPhoneNumber.json +40 -0
  165. package/json-schema/auth/SCIMUser.json +462 -0
  166. package/json-schema/automation/ApprovalAction.json +35 -0
  167. package/json-schema/automation/ApprovalActionType.json +15 -0
  168. package/json-schema/automation/ApprovalProcess.json +326 -0
  169. package/json-schema/automation/ApprovalStep.json +147 -0
  170. package/json-schema/automation/ApproverType.json +16 -0
  171. package/json-schema/automation/AuthField.json +73 -0
  172. package/json-schema/automation/Authentication.json +159 -0
  173. package/json-schema/automation/AuthenticationType.json +18 -0
  174. package/json-schema/automation/ConflictResolution.json +16 -0
  175. package/json-schema/automation/Connector.json +440 -0
  176. package/json-schema/automation/ConnectorCategory.json +26 -0
  177. package/json-schema/automation/ConnectorInstance.json +69 -0
  178. package/json-schema/automation/ConnectorOperation.json +117 -0
  179. package/json-schema/automation/ConnectorTrigger.json +54 -0
  180. package/json-schema/automation/DataDestinationConfig.json +89 -0
  181. package/json-schema/automation/DataSourceConfig.json +34 -0
  182. package/json-schema/automation/DataSyncConfig.json +355 -0
  183. package/json-schema/automation/ETLDestination.json +57 -0
  184. package/json-schema/automation/ETLEndpointType.json +19 -0
  185. package/json-schema/automation/ETLPipeline.json +252 -0
  186. package/json-schema/automation/ETLPipelineRun.json +107 -0
  187. package/json-schema/automation/ETLRunStatus.json +17 -0
  188. package/json-schema/automation/ETLSource.json +60 -0
  189. package/json-schema/automation/ETLSyncMode.json +14 -0
  190. package/json-schema/automation/ETLTransformation.json +46 -0
  191. package/json-schema/automation/ETLTransformationType.json +21 -0
  192. package/json-schema/automation/FieldMapping.json +36 -0
  193. package/json-schema/automation/OAuth2Config.json +43 -0
  194. package/json-schema/automation/OperationParameter.json +59 -0
  195. package/json-schema/automation/OperationType.json +17 -0
  196. package/json-schema/automation/SyncDirection.json +14 -0
  197. package/json-schema/automation/SyncExecutionResult.json +135 -0
  198. package/json-schema/automation/SyncExecutionStatus.json +17 -0
  199. package/json-schema/automation/SyncMode.json +14 -0
  200. package/json-schema/automation/Webhook.json +3 -1
  201. package/json-schema/automation/WebhookReceiver.json +3 -1
  202. package/json-schema/automation/WorkflowRule.json +3 -2
  203. package/json-schema/data/Field.json +62 -4
  204. package/json-schema/data/FieldType.json +12 -2
  205. package/json-schema/data/Object.json +62 -4
  206. package/json-schema/data/SelectOption.json +4 -2
  207. package/json-schema/data/VectorConfig.json +51 -0
  208. package/json-schema/hub/ComposerResponse.json +4 -2163
  209. package/json-schema/permission/PermissionSet.json +3 -1
  210. package/json-schema/permission/RLSConfig.json +59 -0
  211. package/json-schema/permission/RLSEvaluationResult.json +40 -0
  212. package/json-schema/permission/RLSOperation.json +16 -0
  213. package/json-schema/permission/RLSUserContext.json +51 -0
  214. package/json-schema/permission/RowLevelSecurityPolicy.json +77 -0
  215. package/json-schema/permission/Territory.json +3 -1
  216. package/json-schema/shared/EventName.json +12 -0
  217. package/json-schema/shared/SnakeCaseIdentifier.json +12 -0
  218. package/json-schema/shared/SystemIdentifier.json +12 -0
  219. package/json-schema/system/Event.json +3 -2
  220. package/json-schema/system/FeatureFlag.json +87 -0
  221. package/json-schema/system/FeatureStrategy.json +16 -0
  222. package/json-schema/system/Manifest.json +398 -0
  223. package/json-schema/ui/Action.json +25 -4
  224. package/json-schema/ui/ActionParam.json +12 -2
  225. package/json-schema/ui/App.json +18 -7
  226. package/json-schema/ui/ChartType.json +9 -1
  227. package/json-schema/ui/Dashboard.json +9 -1
  228. package/json-schema/ui/DashboardNavItem.json +3 -1
  229. package/json-schema/ui/DashboardWidget.json +9 -1
  230. package/json-schema/ui/FieldWidgetProps.json +62 -4
  231. package/json-schema/ui/FormView.json +4 -1
  232. package/json-schema/ui/GroupNavItem.json +3 -1
  233. package/json-schema/ui/ListView.json +7 -1
  234. package/json-schema/ui/NavigationItem.json +15 -5
  235. package/json-schema/ui/ObjectNavItem.json +3 -1
  236. package/json-schema/ui/Page.json +36 -4
  237. package/json-schema/ui/PageCardProps.json +32 -0
  238. package/json-schema/ui/PageComponent.json +33 -3
  239. package/json-schema/ui/PageComponentType.json +32 -0
  240. package/json-schema/ui/PageHeaderProps.json +39 -0
  241. package/json-schema/ui/PageNavItem.json +3 -1
  242. package/json-schema/ui/PageRegion.json +33 -3
  243. package/json-schema/ui/PageTabsProps.json +55 -0
  244. package/json-schema/ui/RecordDetailsProps.json +37 -0
  245. package/json-schema/ui/RecordHighlightsProps.json +24 -0
  246. package/json-schema/ui/RecordRelatedListProps.json +39 -0
  247. package/json-schema/ui/UrlNavItem.json +3 -1
  248. package/json-schema/ui/View.json +22 -4
  249. package/json-schema/ui/WidgetEvent.json +42 -0
  250. package/json-schema/ui/WidgetLifecycle.json +40 -0
  251. package/json-schema/ui/WidgetManifest.json +262 -0
  252. package/json-schema/ui/WidgetProperty.json +58 -0
  253. package/package.json +1 -1
  254. package/prompts/architecture.md +5 -5
  255. package/prompts/create-new-project.md +85 -0
  256. package/dist/driver/index.d.ts +0 -5
  257. package/dist/driver/index.d.ts.map +0 -1
  258. package/dist/driver/mongo.zod.d.ts.map +0 -1
  259. package/dist/driver/postgres.zod.d.ts.map +0 -1
  260. package/dist/kernel/index.d.ts +0 -12
  261. package/dist/kernel/index.d.ts.map +0 -1
  262. package/dist/kernel/index.js +0 -27
  263. package/dist/kernel/manifest.zod.d.ts +0 -2153
  264. package/dist/kernel/manifest.zod.d.ts.map +0 -1
  265. package/json-schema/kernel/Manifest.json +0 -2557
  266. /package/dist/{kernel → system}/context.zod.d.ts +0 -0
  267. /package/dist/{kernel → system}/context.zod.js +0 -0
  268. /package/dist/{driver → system}/datasource.zod.js +0 -0
  269. /package/dist/{driver → system/driver}/mongo.zod.js +0 -0
  270. /package/dist/{driver → system/driver}/postgres.zod.js +0 -0
  271. /package/dist/{driver → system}/driver.zod.js +0 -0
  272. /package/dist/{kernel → system}/logger.zod.js +0 -0
  273. /package/dist/{kernel → system}/plugin.zod.d.ts +0 -0
  274. /package/dist/{kernel → system}/plugin.zod.js +0 -0
  275. /package/dist/{kernel → system}/scoped-storage.zod.js +0 -0
  276. /package/json-schema/{driver → system}/Datasource.json +0 -0
  277. /package/json-schema/{driver → system}/DatasourceCapabilities.json +0 -0
  278. /package/json-schema/{driver → system}/DriverCapabilities.json +0 -0
  279. /package/json-schema/{driver → system}/DriverDefinition.json +0 -0
  280. /package/json-schema/{driver → system}/DriverInterface.json +0 -0
  281. /package/json-schema/{driver → system}/DriverOptions.json +0 -0
  282. /package/json-schema/{driver → system}/DriverType.json +0 -0
  283. /package/json-schema/{kernel → system}/FileMetadata.json +0 -0
  284. /package/json-schema/{kernel → system}/I18nContext.json +0 -0
  285. /package/json-schema/{kernel → system}/KernelContext.json +0 -0
  286. /package/json-schema/{kernel → system}/LogEntry.json +0 -0
  287. /package/json-schema/{kernel → system}/LogFormat.json +0 -0
  288. /package/json-schema/{kernel → system}/LogLevel.json +0 -0
  289. /package/json-schema/{kernel → system}/Logger.json +0 -0
  290. /package/json-schema/{kernel → system}/LoggerConfig.json +0 -0
  291. /package/json-schema/{driver → system}/MongoConfig.json +0 -0
  292. /package/json-schema/{kernel → system}/ObjectQLClient.json +0 -0
  293. /package/json-schema/{kernel → system}/Plugin.json +0 -0
  294. /package/json-schema/{kernel → system}/PluginContext.json +0 -0
  295. /package/json-schema/{kernel → system}/PluginLifecycle.json +0 -0
  296. /package/json-schema/{driver → system}/PostgresConfig.json +0 -0
  297. /package/json-schema/{kernel → system}/Router.json +0 -0
  298. /package/json-schema/{kernel → system}/RuntimeMode.json +0 -0
  299. /package/json-schema/{kernel → system}/Scheduler.json +0 -0
  300. /package/json-schema/{kernel → system}/ScopedStorage.json +0 -0
  301. /package/json-schema/{kernel → system}/ScopedStorageConfig.json +0 -0
  302. /package/json-schema/{kernel → system}/StorageAdapterType.json +0 -0
  303. /package/json-schema/{kernel → system}/StorageScope.json +0 -0
  304. /package/json-schema/{kernel → system}/SystemAPI.json +0 -0
@@ -0,0 +1,605 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * # Row-Level Security (RLS) Protocol
4
+ *
5
+ * Implements fine-grained record-level access control inspired by PostgreSQL RLS
6
+ * and Salesforce Criteria-Based Sharing Rules.
7
+ *
8
+ * ## Overview
9
+ *
10
+ * Row-Level Security (RLS) allows you to control which rows users can access
11
+ * in database tables based on their identity and role. Unlike object-level
12
+ * permissions (CRUD), RLS provides record-level filtering.
13
+ *
14
+ * ## Use Cases
15
+ *
16
+ * 1. **Multi-Tenant Data Isolation**
17
+ * - Users only see records from their organization
18
+ * - `using: "tenant_id = current_user.tenant_id"`
19
+ *
20
+ * 2. **Ownership-Based Access**
21
+ * - Users only see records they own
22
+ * - `using: "owner_id = current_user.id"`
23
+ *
24
+ * 3. **Department-Based Access**
25
+ * - Users only see records from their department
26
+ * - `using: "department = current_user.department"`
27
+ *
28
+ * 4. **Regional Access Control**
29
+ * - Sales reps only see accounts in their territory
30
+ * - `using: "region IN (current_user.assigned_regions)"`
31
+ *
32
+ * 5. **Time-Based Access**
33
+ * - Users can only access active records
34
+ * - `using: "status = 'active' AND expiry_date > NOW()"`
35
+ *
36
+ * ## PostgreSQL RLS Comparison
37
+ *
38
+ * PostgreSQL RLS Example:
39
+ * ```sql
40
+ * CREATE POLICY tenant_isolation ON accounts
41
+ * FOR SELECT
42
+ * USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
43
+ *
44
+ * CREATE POLICY account_insert ON accounts
45
+ * FOR INSERT
46
+ * WITH CHECK (tenant_id = current_setting('app.current_tenant_id')::uuid);
47
+ * ```
48
+ *
49
+ * ObjectStack RLS Equivalent:
50
+ * ```typescript
51
+ * {
52
+ * name: 'tenant_isolation',
53
+ * object: 'account',
54
+ * operation: 'select',
55
+ * using: 'tenant_id = current_user.tenant_id'
56
+ * }
57
+ * ```
58
+ *
59
+ * ## Salesforce Sharing Rules Comparison
60
+ *
61
+ * Salesforce uses "Sharing Rules" and "Role Hierarchy" for record-level access.
62
+ * ObjectStack RLS provides similar functionality with more flexibility.
63
+ *
64
+ * Salesforce:
65
+ * - Criteria-Based Sharing: Share records matching criteria with users/roles
66
+ * - Owner-Based Sharing: Share records based on owner's role
67
+ * - Manual Sharing: Individual record sharing
68
+ *
69
+ * ObjectStack RLS:
70
+ * - More flexible formula-based conditions
71
+ * - Direct SQL-like syntax
72
+ * - Supports complex logic with AND/OR/NOT
73
+ *
74
+ * ## Best Practices
75
+ *
76
+ * 1. **Always Define SELECT Policy**: Control what users can view
77
+ * 2. **Define INSERT/UPDATE CHECK Policies**: Prevent data leakage
78
+ * 3. **Use Role-Based Policies**: Apply different rules to different roles
79
+ * 4. **Test Thoroughly**: RLS can have complex interactions
80
+ * 5. **Monitor Performance**: Complex RLS policies can impact query performance
81
+ *
82
+ * ## Security Considerations
83
+ *
84
+ * 1. **Defense in Depth**: RLS is one layer; use with object permissions
85
+ * 2. **Default Deny**: If no policy matches, access is denied
86
+ * 3. **Policy Precedence**: More permissive policy wins (OR logic)
87
+ * 4. **Context Variables**: Ensure current_user context is always set
88
+ *
89
+ * @see https://www.postgresql.org/docs/current/ddl-rowsecurity.html
90
+ * @see https://help.salesforce.com/s/articleView?id=sf.security_sharing_rules.htm
91
+ */
92
+ /**
93
+ * RLS Operation Enum
94
+ * Specifies which database operation this policy applies to.
95
+ *
96
+ * - **select**: Controls which rows can be read (SELECT queries)
97
+ * - **insert**: Controls which rows can be inserted (INSERT statements)
98
+ * - **update**: Controls which rows can be updated (UPDATE statements)
99
+ * - **delete**: Controls which rows can be deleted (DELETE statements)
100
+ * - **all**: Shorthand for all operations (equivalent to defining 4 separate policies)
101
+ */
102
+ export declare const RLSOperation: z.ZodEnum<["select", "insert", "update", "delete", "all"]>;
103
+ export type RLSOperation = z.infer<typeof RLSOperation>;
104
+ /**
105
+ * Row-Level Security Policy Schema
106
+ *
107
+ * Defines a single RLS policy that filters records based on conditions.
108
+ * Multiple policies can be defined for the same object, and they are
109
+ * combined with OR logic (union of results).
110
+ *
111
+ * @example Multi-Tenant Isolation
112
+ * ```typescript
113
+ * {
114
+ * name: 'tenant_isolation',
115
+ * label: 'Multi-Tenant Data Isolation',
116
+ * object: 'account',
117
+ * operation: 'select',
118
+ * using: 'tenant_id = current_user.tenant_id',
119
+ * enabled: true
120
+ * }
121
+ * ```
122
+ *
123
+ * @example Owner-Based Access
124
+ * ```typescript
125
+ * {
126
+ * name: 'owner_access',
127
+ * label: 'Users Can View Their Own Records',
128
+ * object: 'opportunity',
129
+ * operation: 'select',
130
+ * using: 'owner_id = current_user.id',
131
+ * enabled: true
132
+ * }
133
+ * ```
134
+ *
135
+ * @example Manager Can View Team Records
136
+ * ```typescript
137
+ * {
138
+ * name: 'manager_team_access',
139
+ * label: 'Managers Can View Team Records',
140
+ * object: 'task',
141
+ * operation: 'select',
142
+ * using: 'assigned_to_id IN (SELECT id FROM users WHERE manager_id = current_user.id)',
143
+ * roles: ['manager', 'director'],
144
+ * enabled: true
145
+ * }
146
+ * ```
147
+ *
148
+ * @example Prevent Cross-Tenant Data Insertion
149
+ * ```typescript
150
+ * {
151
+ * name: 'tenant_insert_check',
152
+ * label: 'Prevent Cross-Tenant Data Creation',
153
+ * object: 'account',
154
+ * operation: 'insert',
155
+ * check: 'tenant_id = current_user.tenant_id',
156
+ * enabled: true
157
+ * }
158
+ * ```
159
+ *
160
+ * @example Regional Sales Access
161
+ * ```typescript
162
+ * {
163
+ * name: 'regional_sales_access',
164
+ * label: 'Sales Reps Access Regional Accounts',
165
+ * object: 'account',
166
+ * operation: 'select',
167
+ * using: 'region = current_user.region OR region IS NULL',
168
+ * roles: ['sales_rep'],
169
+ * enabled: true
170
+ * }
171
+ * ```
172
+ *
173
+ * @example Time-Based Access Control
174
+ * ```typescript
175
+ * {
176
+ * name: 'active_records_only',
177
+ * label: 'Users Only Access Active Records',
178
+ * object: 'contract',
179
+ * operation: 'select',
180
+ * using: 'status = "active" AND start_date <= NOW() AND end_date >= NOW()',
181
+ * enabled: true
182
+ * }
183
+ * ```
184
+ *
185
+ * @example Hierarchical Access (Role-Based)
186
+ * ```typescript
187
+ * {
188
+ * name: 'executive_full_access',
189
+ * label: 'Executives See All Records',
190
+ * object: 'account',
191
+ * operation: 'all',
192
+ * using: '1 = 1', // Always true - see everything
193
+ * roles: ['ceo', 'cfo', 'cto'],
194
+ * enabled: true
195
+ * }
196
+ * ```
197
+ */
198
+ export declare const RowLevelSecurityPolicySchema: z.ZodEffects<z.ZodObject<{
199
+ /**
200
+ * Unique identifier for this policy.
201
+ * Must be unique within the object.
202
+ * Use snake_case following ObjectStack naming conventions.
203
+ *
204
+ * @example "tenant_isolation", "owner_access", "manager_team_view"
205
+ */
206
+ name: z.ZodString;
207
+ /**
208
+ * Human-readable label for the policy.
209
+ * Used in admin UI and logs.
210
+ *
211
+ * @example "Multi-Tenant Data Isolation", "Owner-Based Access"
212
+ */
213
+ label: z.ZodOptional<z.ZodString>;
214
+ /**
215
+ * Description explaining what this policy does and why.
216
+ * Helps with governance and compliance.
217
+ *
218
+ * @example "Ensures users can only access records from their own tenant organization"
219
+ */
220
+ description: z.ZodOptional<z.ZodString>;
221
+ /**
222
+ * Target object (table) this policy applies to.
223
+ * Must reference a valid ObjectStack object name.
224
+ *
225
+ * @example "account", "opportunity", "contact", "custom_object"
226
+ */
227
+ object: z.ZodString;
228
+ /**
229
+ * Database operation(s) this policy applies to.
230
+ *
231
+ * - **select**: Controls read access (SELECT queries)
232
+ * - **insert**: Controls insert access (INSERT statements)
233
+ * - **update**: Controls update access (UPDATE statements)
234
+ * - **delete**: Controls delete access (DELETE statements)
235
+ * - **all**: Applies to all operations
236
+ *
237
+ * @example "select" - Most common, controls what users can view
238
+ * @example "all" - Apply same rule to all operations
239
+ */
240
+ operation: z.ZodEnum<["select", "insert", "update", "delete", "all"]>;
241
+ /**
242
+ * USING clause - Filter condition for SELECT/UPDATE/DELETE.
243
+ *
244
+ * This is a SQL-like expression evaluated for each row.
245
+ * Only rows where this expression returns TRUE are accessible.
246
+ *
247
+ * **Note**: For INSERT-only policies, USING is not required (only CHECK is needed).
248
+ * For SELECT/UPDATE/DELETE operations, USING is required.
249
+ *
250
+ * **Security Note**: RLS conditions are executed at the database level with
251
+ * parameterized queries. The implementation must use prepared statements
252
+ * to prevent SQL injection. Never concatenate user input directly into
253
+ * RLS conditions.
254
+ *
255
+ * **SQL Dialect**: Compatible with PostgreSQL SQL syntax. Implementations
256
+ * may adapt to other databases (MySQL, SQL Server, etc.) but should maintain
257
+ * semantic equivalence.
258
+ *
259
+ * Available context variables:
260
+ * - `current_user.id` - Current user's ID
261
+ * - `current_user.tenant_id` - Current user's tenant (maps to `tenantId` in RLSUserContext)
262
+ * - `current_user.role` - Current user's role
263
+ * - `current_user.department` - Current user's department
264
+ * - `current_user.*` - Any custom user field
265
+ * - `NOW()` - Current timestamp
266
+ * - `CURRENT_DATE` - Current date
267
+ * - `CURRENT_TIME` - Current time
268
+ *
269
+ * **Context Variable Mapping**: The RLSUserContext schema uses camelCase (e.g., `tenantId`),
270
+ * but expressions use snake_case with `current_user.` prefix (e.g., `current_user.tenant_id`).
271
+ * Implementations must handle this mapping.
272
+ *
273
+ * Supported operators:
274
+ * - Comparison: =, !=, <, >, <=, >=, <> (not equal)
275
+ * - Logical: AND, OR, NOT
276
+ * - NULL checks: IS NULL, IS NOT NULL
277
+ * - Set operations: IN, NOT IN
278
+ * - String: LIKE, NOT LIKE, ILIKE (case-insensitive)
279
+ * - Pattern matching: ~ (regex), !~ (not regex)
280
+ * - Subqueries: (SELECT ...)
281
+ * - Array operations: ANY, ALL
282
+ *
283
+ * **Prohibited**: Dynamic SQL, DDL statements, DML statements (INSERT/UPDATE/DELETE)
284
+ *
285
+ * @example "tenant_id = current_user.tenant_id"
286
+ * @example "owner_id = current_user.id OR created_by = current_user.id"
287
+ * @example "department IN (SELECT department FROM user_departments WHERE user_id = current_user.id)"
288
+ * @example "status = 'active' AND expiry_date > NOW()"
289
+ */
290
+ using: z.ZodOptional<z.ZodString>;
291
+ /**
292
+ * CHECK clause - Validation for INSERT/UPDATE operations.
293
+ *
294
+ * Similar to USING but applies to new/modified rows.
295
+ * Prevents users from creating/updating rows they wouldn't be able to see.
296
+ *
297
+ * **Default Behavior**: If not specified, implementations should use the
298
+ * USING clause as the CHECK clause. This ensures data integrity by preventing
299
+ * users from creating records they cannot view.
300
+ *
301
+ * Use cases:
302
+ * - Prevent cross-tenant data creation
303
+ * - Enforce mandatory field values
304
+ * - Validate data integrity rules
305
+ * - Restrict certain operations (e.g., only allow creating "draft" status)
306
+ *
307
+ * @example "tenant_id = current_user.tenant_id"
308
+ * @example "status IN ('draft', 'pending')" - Only allow certain statuses
309
+ * @example "created_by = current_user.id" - Must be the creator
310
+ */
311
+ check: z.ZodOptional<z.ZodString>;
312
+ /**
313
+ * Restrict this policy to specific roles.
314
+ * If specified, only users with these roles will have this policy applied.
315
+ * If omitted, policy applies to all users (except those with bypassRLS permission).
316
+ *
317
+ * Role names must match defined roles in the system.
318
+ *
319
+ * @example ["sales_rep", "account_manager"]
320
+ * @example ["employee"] - Apply to all employees
321
+ * @example ["guest"] - Special restrictions for guests
322
+ */
323
+ roles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
324
+ /**
325
+ * Whether this policy is currently active.
326
+ * Disabled policies are not evaluated.
327
+ * Useful for temporary policy changes without deletion.
328
+ *
329
+ * @default true
330
+ */
331
+ enabled: z.ZodDefault<z.ZodBoolean>;
332
+ /**
333
+ * Policy priority for conflict resolution.
334
+ * Higher numbers = higher priority.
335
+ * When multiple policies apply, the most permissive wins (OR logic).
336
+ * Priority is only used for ordering evaluation (performance).
337
+ *
338
+ * @default 0
339
+ */
340
+ priority: z.ZodDefault<z.ZodNumber>;
341
+ /**
342
+ * Tags for policy categorization and reporting.
343
+ * Useful for governance, compliance, and auditing.
344
+ *
345
+ * @example ["compliance", "gdpr", "pci"]
346
+ * @example ["multi-tenant", "security"]
347
+ */
348
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
349
+ }, "strip", z.ZodTypeAny, {
350
+ object: string;
351
+ name: string;
352
+ priority: number;
353
+ operation: "select" | "insert" | "update" | "delete" | "all";
354
+ enabled: boolean;
355
+ tags?: string[] | undefined;
356
+ label?: string | undefined;
357
+ description?: string | undefined;
358
+ roles?: string[] | undefined;
359
+ using?: string | undefined;
360
+ check?: string | undefined;
361
+ }, {
362
+ object: string;
363
+ name: string;
364
+ operation: "select" | "insert" | "update" | "delete" | "all";
365
+ tags?: string[] | undefined;
366
+ label?: string | undefined;
367
+ description?: string | undefined;
368
+ priority?: number | undefined;
369
+ roles?: string[] | undefined;
370
+ using?: string | undefined;
371
+ check?: string | undefined;
372
+ enabled?: boolean | undefined;
373
+ }>, {
374
+ object: string;
375
+ name: string;
376
+ priority: number;
377
+ operation: "select" | "insert" | "update" | "delete" | "all";
378
+ enabled: boolean;
379
+ tags?: string[] | undefined;
380
+ label?: string | undefined;
381
+ description?: string | undefined;
382
+ roles?: string[] | undefined;
383
+ using?: string | undefined;
384
+ check?: string | undefined;
385
+ }, {
386
+ object: string;
387
+ name: string;
388
+ operation: "select" | "insert" | "update" | "delete" | "all";
389
+ tags?: string[] | undefined;
390
+ label?: string | undefined;
391
+ description?: string | undefined;
392
+ priority?: number | undefined;
393
+ roles?: string[] | undefined;
394
+ using?: string | undefined;
395
+ check?: string | undefined;
396
+ enabled?: boolean | undefined;
397
+ }>;
398
+ /**
399
+ * RLS Configuration Schema
400
+ *
401
+ * Global configuration for the Row-Level Security system.
402
+ * Defines how RLS is enforced across the entire platform.
403
+ */
404
+ export declare const RLSConfigSchema: z.ZodObject<{
405
+ /**
406
+ * Global RLS enable/disable flag.
407
+ * When false, all RLS policies are ignored (use with caution!).
408
+ *
409
+ * @default true
410
+ */
411
+ enabled: z.ZodDefault<z.ZodBoolean>;
412
+ /**
413
+ * Default behavior when no policies match.
414
+ *
415
+ * - **deny**: Deny access (secure default)
416
+ * - **allow**: Allow access (permissive mode, not recommended)
417
+ *
418
+ * @default "deny"
419
+ */
420
+ defaultPolicy: z.ZodDefault<z.ZodEnum<["deny", "allow"]>>;
421
+ /**
422
+ * Whether to allow superusers to bypass RLS.
423
+ * Superusers include system administrators and service accounts.
424
+ *
425
+ * @default true
426
+ */
427
+ allowSuperuserBypass: z.ZodDefault<z.ZodBoolean>;
428
+ /**
429
+ * List of roles that can bypass RLS.
430
+ * Users with these roles see all records regardless of policies.
431
+ *
432
+ * @example ["system_admin", "data_auditor"]
433
+ */
434
+ bypassRoles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
435
+ /**
436
+ * Whether to log RLS policy evaluations.
437
+ * Useful for debugging and auditing.
438
+ * Can impact performance if enabled globally.
439
+ *
440
+ * @default false
441
+ */
442
+ logEvaluations: z.ZodDefault<z.ZodBoolean>;
443
+ /**
444
+ * Cache RLS policy evaluation results.
445
+ * Can improve performance for frequently accessed records.
446
+ * Cache is invalidated when policies change or user context changes.
447
+ *
448
+ * @default true
449
+ */
450
+ cacheResults: z.ZodDefault<z.ZodBoolean>;
451
+ /**
452
+ * Cache TTL in seconds.
453
+ * How long to cache RLS evaluation results.
454
+ *
455
+ * @default 300 (5 minutes)
456
+ */
457
+ cacheTtlSeconds: z.ZodDefault<z.ZodNumber>;
458
+ /**
459
+ * Performance optimization: Pre-fetch user context.
460
+ * Load user context once per request instead of per-query.
461
+ *
462
+ * @default true
463
+ */
464
+ prefetchUserContext: z.ZodDefault<z.ZodBoolean>;
465
+ }, "strip", z.ZodTypeAny, {
466
+ enabled: boolean;
467
+ defaultPolicy: "deny" | "allow";
468
+ allowSuperuserBypass: boolean;
469
+ logEvaluations: boolean;
470
+ cacheResults: boolean;
471
+ cacheTtlSeconds: number;
472
+ prefetchUserContext: boolean;
473
+ bypassRoles?: string[] | undefined;
474
+ }, {
475
+ enabled?: boolean | undefined;
476
+ defaultPolicy?: "deny" | "allow" | undefined;
477
+ allowSuperuserBypass?: boolean | undefined;
478
+ bypassRoles?: string[] | undefined;
479
+ logEvaluations?: boolean | undefined;
480
+ cacheResults?: boolean | undefined;
481
+ cacheTtlSeconds?: number | undefined;
482
+ prefetchUserContext?: boolean | undefined;
483
+ }>;
484
+ /**
485
+ * User Context Schema
486
+ *
487
+ * Represents the current user's context for RLS evaluation.
488
+ * This data is used to evaluate USING and CHECK clauses.
489
+ */
490
+ export declare const RLSUserContextSchema: z.ZodObject<{
491
+ /**
492
+ * User ID
493
+ */
494
+ id: z.ZodString;
495
+ /**
496
+ * User email
497
+ */
498
+ email: z.ZodOptional<z.ZodString>;
499
+ /**
500
+ * Tenant/Organization ID
501
+ */
502
+ tenantId: z.ZodOptional<z.ZodString>;
503
+ /**
504
+ * User role(s)
505
+ */
506
+ role: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
507
+ /**
508
+ * User department
509
+ */
510
+ department: z.ZodOptional<z.ZodString>;
511
+ /**
512
+ * Additional custom attributes
513
+ * Can include any custom user fields for RLS evaluation
514
+ */
515
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
516
+ }, "strip", z.ZodTypeAny, {
517
+ id: string;
518
+ email?: string | undefined;
519
+ tenantId?: string | undefined;
520
+ role?: string | string[] | undefined;
521
+ department?: string | undefined;
522
+ attributes?: Record<string, any> | undefined;
523
+ }, {
524
+ id: string;
525
+ email?: string | undefined;
526
+ tenantId?: string | undefined;
527
+ role?: string | string[] | undefined;
528
+ department?: string | undefined;
529
+ attributes?: Record<string, any> | undefined;
530
+ }>;
531
+ /**
532
+ * RLS Policy Evaluation Result
533
+ *
534
+ * Result of evaluating an RLS policy for a specific record.
535
+ * Used for debugging and audit logging.
536
+ */
537
+ export declare const RLSEvaluationResultSchema: z.ZodObject<{
538
+ /**
539
+ * Policy name that was evaluated
540
+ */
541
+ policyName: z.ZodString;
542
+ /**
543
+ * Whether access was granted
544
+ */
545
+ granted: z.ZodBoolean;
546
+ /**
547
+ * Evaluation duration in milliseconds
548
+ */
549
+ durationMs: z.ZodOptional<z.ZodNumber>;
550
+ /**
551
+ * Error message if evaluation failed
552
+ */
553
+ error: z.ZodOptional<z.ZodString>;
554
+ /**
555
+ * Evaluated USING clause result
556
+ */
557
+ usingResult: z.ZodOptional<z.ZodBoolean>;
558
+ /**
559
+ * Evaluated CHECK clause result (for INSERT/UPDATE)
560
+ */
561
+ checkResult: z.ZodOptional<z.ZodBoolean>;
562
+ }, "strip", z.ZodTypeAny, {
563
+ policyName: string;
564
+ granted: boolean;
565
+ error?: string | undefined;
566
+ durationMs?: number | undefined;
567
+ usingResult?: boolean | undefined;
568
+ checkResult?: boolean | undefined;
569
+ }, {
570
+ policyName: string;
571
+ granted: boolean;
572
+ error?: string | undefined;
573
+ durationMs?: number | undefined;
574
+ usingResult?: boolean | undefined;
575
+ checkResult?: boolean | undefined;
576
+ }>;
577
+ /**
578
+ * Type exports
579
+ */
580
+ export type RowLevelSecurityPolicy = z.infer<typeof RowLevelSecurityPolicySchema>;
581
+ export type RLSConfig = z.infer<typeof RLSConfigSchema>;
582
+ export type RLSUserContext = z.infer<typeof RLSUserContextSchema>;
583
+ export type RLSEvaluationResult = z.infer<typeof RLSEvaluationResultSchema>;
584
+ /**
585
+ * Helper factory for creating RLS policies
586
+ */
587
+ export declare const RLS: {
588
+ /**
589
+ * Create a simple owner-based policy
590
+ */
591
+ readonly ownerPolicy: (object: string, ownerField?: string) => RowLevelSecurityPolicy;
592
+ /**
593
+ * Create a tenant isolation policy
594
+ */
595
+ readonly tenantPolicy: (object: string, tenantField?: string) => RowLevelSecurityPolicy;
596
+ /**
597
+ * Create a role-based policy
598
+ */
599
+ readonly rolePolicy: (object: string, roles: string[], condition: string) => RowLevelSecurityPolicy;
600
+ /**
601
+ * Create a permissive policy (allow all for specific roles)
602
+ */
603
+ readonly allowAllPolicy: (object: string, roles: string[]) => RowLevelSecurityPolicy;
604
+ };
605
+ //# sourceMappingURL=rls.zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rls.zod.d.ts","sourceRoot":"","sources":["../../src/permission/rls.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,4DAA0D,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6FG;AACH,eAAO,MAAM,4BAA4B;IACvC;;;;;;OAMG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAIH;;;;;;;;;;;OAWG;;IAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;;IAKH;;;;;;;;;;;;;;;;;;;OAmBG;;IAKH;;;;;;;;;;OAUG;;IAKH;;;;;;OAMG;;IAKH;;;;;;;OAOG;;IAMH;;;;;;OAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBH,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;OAKG;;IAKH;;;;;;;OAOG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;;OAMG;;IAKH;;;;;;OAMG;;IAKH;;;;;OAKG;;IAOH;;;;;OAKG;;;;;;;;;;;;;;;;;;;;EAIH,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;OAEG;;IAIH;;OAEG;;IAMH;;OAEG;;IAKH;;OAEG;;IAQH;;OAEG;;IAKH;;;OAGG;;;;;;;;;;;;;;;;EAIH,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;IACpC;;OAEG;;IAIH;;OAEG;;IAIH;;OAEG;;IAKH;;OAEG;;IAKH;;OAEG;;IAKH;;OAEG;;;;;;;;;;;;;;;;EAIH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,GAAG;IACd;;OAEG;mCACmB,MAAM,eAAc,MAAM,KAAgB,sBAAsB;IAUtF;;OAEG;oCACoB,MAAM,gBAAe,MAAM,KAAiB,sBAAsB;IAWzF;;OAEG;kCACkB,MAAM,SAAS,MAAM,EAAE,aAAa,MAAM,KAAG,sBAAsB;IAWxF;;OAEG;sCACsB,MAAM,SAAS,MAAM,EAAE,KAAG,sBAAsB;CAUjE,CAAC"}