@objectstack/platform-objects 7.3.0 → 7.4.1

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 (51) hide show
  1. package/dist/apps/index.d.mts +45 -19
  2. package/dist/apps/index.d.ts +45 -19
  3. package/dist/apps/index.js +1434 -3406
  4. package/dist/apps/index.js.map +1 -1
  5. package/dist/apps/index.mjs +1434 -3407
  6. package/dist/apps/index.mjs.map +1 -1
  7. package/dist/audit/index.d.mts +4595 -26176
  8. package/dist/audit/index.d.ts +4595 -26176
  9. package/dist/audit/index.js +63 -1063
  10. package/dist/audit/index.js.map +1 -1
  11. package/dist/audit/index.mjs +64 -1057
  12. package/dist/audit/index.mjs.map +1 -1
  13. package/dist/identity/index.d.mts +839 -1281
  14. package/dist/identity/index.d.ts +839 -1281
  15. package/dist/index.d.mts +3 -8
  16. package/dist/index.d.ts +3 -8
  17. package/dist/index.js +2344 -6782
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +2343 -6767
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/integration/index.d.mts +1 -2947
  22. package/dist/integration/index.d.ts +1 -2947
  23. package/dist/integration/index.js +0 -136
  24. package/dist/integration/index.js.map +1 -1
  25. package/dist/integration/index.mjs +0 -135
  26. package/dist/integration/index.mjs.map +1 -1
  27. package/dist/metadata/index.d.mts +3924 -261
  28. package/dist/metadata/index.d.ts +3924 -261
  29. package/dist/metadata/index.js +101 -0
  30. package/dist/metadata/index.js.map +1 -1
  31. package/dist/metadata/index.mjs +101 -1
  32. package/dist/metadata/index.mjs.map +1 -1
  33. package/dist/metadata-translations/index.js +597 -505
  34. package/dist/metadata-translations/index.js.map +1 -1
  35. package/dist/metadata-translations/index.mjs +597 -505
  36. package/dist/metadata-translations/index.mjs.map +1 -1
  37. package/dist/plugin.js +1790 -3614
  38. package/dist/plugin.js.map +1 -1
  39. package/dist/plugin.mjs +1790 -3614
  40. package/dist/plugin.mjs.map +1 -1
  41. package/dist/security/index.d.mts +1 -18850
  42. package/dist/security/index.d.ts +1 -18850
  43. package/dist/security/index.js +0 -1531
  44. package/dist/security/index.js.map +1 -1
  45. package/dist/security/index.mjs +0 -1523
  46. package/dist/security/index.mjs.map +1 -1
  47. package/dist/system/index.d.mts +144 -212
  48. package/dist/system/index.d.ts +144 -212
  49. package/package.json +2 -2
  50. package/dist/state-machine.zod-BNanU03M.d-Ek3_yo9P.d.mts +0 -41
  51. package/dist/state-machine.zod-BNanU03M.d-Ek3_yo9P.d.ts +0 -41
@@ -1,1526 +1,3 @@
1
- import { ObjectSchema, Field } from '@objectstack/spec/data';
2
- import { PermissionSetSchema } from '@objectstack/spec/security';
3
1
 
4
- // src/security/sys-role.object.ts
5
- var SysRole = ObjectSchema.create({
6
- name: "sys_role",
7
- label: "Role",
8
- pluralLabel: "Roles",
9
- icon: "shield",
10
- isSystem: true,
11
- managedBy: "config",
12
- // ADR-0010 §3.7 — RBAC primitive; tenants may add custom rows
13
- // (created via UI / API) but the schema itself is locked.
14
- protection: {
15
- lock: "no-overlay",
16
- reason: "RBAC schema is platform-defined \u2014 see ADR-0010.",
17
- docsUrl: "https://docs.objectstack.ai/adr/0010-metadata-protection"
18
- },
19
- description: "Role definitions for RBAC access control",
20
- displayNameField: "label",
21
- titleFormat: "{label}",
22
- compactLayout: ["label", "name", "active", "is_default"],
23
- // Custom actions — system roles drive RBAC and are edited rarely but
24
- // require the four high-frequency sysadmin affordances every IdP
25
- // (Salesforce, ServiceNow, Okta) ships: activate/deactivate (lifecycle
26
- // without losing assignments), mark default (auto-assign to new users),
27
- // and clone (template for new roles). All operations hit the generic
28
- // data CRUD endpoint exposed by `apiEnabled` — no custom server route
29
- // required because `managedBy: 'config'` allows direct mutation.
30
- actions: [
31
- {
32
- name: "activate_role",
33
- label: "Activate Role",
34
- icon: "circle-check",
35
- variant: "secondary",
36
- mode: "custom",
37
- locations: ["list_item", "record_header"],
38
- type: "api",
39
- method: "PATCH",
40
- target: "/api/v1/data/sys_role/{id}",
41
- bodyExtra: { active: true },
42
- successMessage: "Role activated",
43
- refreshAfter: true
44
- },
45
- {
46
- name: "deactivate_role",
47
- label: "Deactivate Role",
48
- icon: "circle-off",
49
- variant: "danger",
50
- mode: "custom",
51
- locations: ["list_item", "record_header"],
52
- type: "api",
53
- method: "PATCH",
54
- target: "/api/v1/data/sys_role/{id}",
55
- bodyExtra: { active: false },
56
- confirmText: "Deactivate this role? Users with the role keep their assignment but the role stops granting permissions until re-activated.",
57
- successMessage: "Role deactivated",
58
- refreshAfter: true
59
- },
60
- {
61
- name: "set_default_role",
62
- label: "Set as Default",
63
- icon: "star",
64
- variant: "secondary",
65
- mode: "custom",
66
- locations: ["list_item", "record_header"],
67
- type: "api",
68
- method: "PATCH",
69
- target: "/api/v1/data/sys_role/{id}",
70
- bodyExtra: { is_default: true },
71
- confirmText: "Make this the default role for new users? Existing users are unaffected.",
72
- successMessage: "Default role updated",
73
- refreshAfter: true
74
- },
75
- {
76
- // Clone — POST a new sys_role row pre-filled from the source. The
77
- // dialog asks only for the new API name / label so the operator
78
- // can rename atomically; permissions JSON is copied wholesale via
79
- // defaultFromRow.
80
- name: "clone_role",
81
- label: "Clone Role",
82
- icon: "copy",
83
- variant: "secondary",
84
- mode: "custom",
85
- locations: ["list_item", "record_header"],
86
- type: "api",
87
- method: "POST",
88
- target: "/api/v1/data/sys_role",
89
- bodyExtra: { is_default: false, active: true },
90
- successMessage: "Role cloned",
91
- refreshAfter: true,
92
- params: [
93
- { name: "label", label: "New Display Name", type: "text", required: true },
94
- { name: "name", label: "New API Name", type: "text", required: true, helpText: "Unique snake_case machine name" },
95
- { field: "description", defaultFromRow: true },
96
- { field: "permissions", defaultFromRow: true }
97
- ]
98
- }
99
- ],
100
- listViews: {
101
- active: {
102
- type: "grid",
103
- name: "active",
104
- label: "Active",
105
- data: { provider: "object", object: "sys_role" },
106
- columns: ["label", "name", "is_default", "updated_at"],
107
- filter: [{ field: "active", operator: "equals", value: true }],
108
- sort: [{ field: "label", order: "asc" }],
109
- pagination: { pageSize: 50 }
110
- },
111
- default_roles: {
112
- type: "grid",
113
- name: "default_roles",
114
- label: "Default",
115
- data: { provider: "object", object: "sys_role" },
116
- columns: ["label", "name", "description", "active"],
117
- filter: [{ field: "is_default", operator: "equals", value: true }],
118
- sort: [{ field: "label", order: "asc" }],
119
- pagination: { pageSize: 50 }
120
- },
121
- custom: {
122
- type: "grid",
123
- name: "custom",
124
- label: "Custom",
125
- data: { provider: "object", object: "sys_role" },
126
- columns: ["label", "name", "active", "updated_at"],
127
- filter: [{ field: "is_default", operator: "equals", value: false }],
128
- sort: [{ field: "label", order: "asc" }],
129
- pagination: { pageSize: 50 }
130
- },
131
- all_roles: {
132
- type: "grid",
133
- name: "all_roles",
134
- label: "All",
135
- data: { provider: "object", object: "sys_role" },
136
- columns: ["label", "name", "active", "is_default", "updated_at"],
137
- sort: [{ field: "label", order: "asc" }],
138
- pagination: { pageSize: 50 }
139
- }
140
- },
141
- fields: {
142
- // ── Identity ─────────────────────────────────────────────────
143
- label: Field.text({
144
- label: "Display Name",
145
- required: true,
146
- searchable: true,
147
- maxLength: 255,
148
- group: "Identity"
149
- }),
150
- name: Field.text({
151
- label: "API Name",
152
- required: true,
153
- searchable: true,
154
- maxLength: 100,
155
- description: "Unique machine name for the role (e.g. admin, editor, viewer)",
156
- group: "Identity"
157
- }),
158
- description: Field.textarea({
159
- label: "Description",
160
- required: false,
161
- group: "Identity"
162
- }),
163
- // ── Configuration ────────────────────────────────────────────
164
- permissions: Field.textarea({
165
- label: "Permissions",
166
- required: false,
167
- description: "JSON-serialized array of permission strings",
168
- group: "Configuration"
169
- }),
170
- // ── Status ───────────────────────────────────────────────────
171
- active: Field.boolean({
172
- label: "Active",
173
- defaultValue: true,
174
- group: "Status"
175
- }),
176
- is_default: Field.boolean({
177
- label: "Default Role",
178
- defaultValue: false,
179
- description: "Automatically assigned to new users",
180
- group: "Status"
181
- }),
182
- // ── System ───────────────────────────────────────────────────
183
- id: Field.text({
184
- label: "Role ID",
185
- required: true,
186
- readonly: true,
187
- group: "System"
188
- }),
189
- created_at: Field.datetime({
190
- label: "Created At",
191
- defaultValue: "NOW()",
192
- readonly: true,
193
- group: "System"
194
- }),
195
- updated_at: Field.datetime({
196
- label: "Updated At",
197
- defaultValue: "NOW()",
198
- readonly: true,
199
- group: "System"
200
- })
201
- },
202
- indexes: [
203
- { fields: ["name"], unique: true },
204
- { fields: ["active"] }
205
- ],
206
- enable: {
207
- trackHistory: true,
208
- searchable: true,
209
- apiEnabled: true,
210
- apiMethods: ["get", "list", "create", "update", "delete"],
211
- trash: true,
212
- mru: true
213
- }
214
- });
215
- var SysPermissionSet = ObjectSchema.create({
216
- name: "sys_permission_set",
217
- label: "Permission Set",
218
- pluralLabel: "Permission Sets",
219
- icon: "lock",
220
- isSystem: true,
221
- managedBy: "config",
222
- // ADR-0010 §3.7 — RBAC primitive; tenants may add custom rows
223
- // (created via UI / API) but the schema itself is locked.
224
- protection: {
225
- lock: "no-overlay",
226
- reason: "RBAC schema is platform-defined \u2014 see ADR-0010.",
227
- docsUrl: "https://docs.objectstack.ai/adr/0010-metadata-protection"
228
- },
229
- description: "Named permission groupings for fine-grained access control",
230
- displayNameField: "label",
231
- titleFormat: "{label}",
232
- compactLayout: ["label", "name", "active"],
233
- // Custom actions — permission sets are templates assigned to roles or
234
- // users (via sys_role_permission_set / sys_user_permission_set). The
235
- // sysadmin operations that don't live on the parent-detail tabs are
236
- // lifecycle (activate/deactivate without losing assignments) and
237
- // clone (build a new permset by tweaking an existing one). Both hit
238
- // the generic data CRUD endpoint — managedBy: 'config' permits it.
239
- actions: [
240
- {
241
- name: "activate_permission_set",
242
- label: "Activate",
243
- icon: "circle-check",
244
- variant: "secondary",
245
- mode: "custom",
246
- locations: ["list_item", "record_header"],
247
- type: "api",
248
- method: "PATCH",
249
- target: "/api/v1/data/sys_permission_set/{id}",
250
- bodyExtra: { active: true },
251
- successMessage: "Permission set activated",
252
- refreshAfter: true
253
- },
254
- {
255
- name: "deactivate_permission_set",
256
- label: "Deactivate",
257
- icon: "circle-off",
258
- variant: "danger",
259
- mode: "custom",
260
- locations: ["list_item", "record_header"],
261
- type: "api",
262
- method: "PATCH",
263
- target: "/api/v1/data/sys_permission_set/{id}",
264
- bodyExtra: { active: false },
265
- confirmText: "Deactivate this permission set? Existing assignments stay in place but stop granting access until re-activated.",
266
- successMessage: "Permission set deactivated",
267
- refreshAfter: true
268
- },
269
- {
270
- name: "clone_permission_set",
271
- label: "Clone",
272
- icon: "copy",
273
- variant: "secondary",
274
- mode: "custom",
275
- locations: ["list_item", "record_header"],
276
- type: "api",
277
- method: "POST",
278
- target: "/api/v1/data/sys_permission_set",
279
- bodyExtra: { active: true },
280
- successMessage: "Permission set cloned",
281
- refreshAfter: true,
282
- params: [
283
- { name: "label", label: "New Display Name", type: "text", required: true },
284
- { name: "name", label: "New API Name", type: "text", required: true, helpText: "Unique snake_case machine name" },
285
- { field: "description", defaultFromRow: true },
286
- { field: "object_permissions", defaultFromRow: true },
287
- { field: "field_permissions", defaultFromRow: true }
288
- ]
289
- }
290
- ],
291
- listViews: {
292
- active: {
293
- type: "grid",
294
- name: "active",
295
- label: "Active",
296
- data: { provider: "object", object: "sys_permission_set" },
297
- columns: ["label", "name", "description", "updated_at"],
298
- filter: [{ field: "active", operator: "equals", value: true }],
299
- sort: [{ field: "label", order: "asc" }],
300
- pagination: { pageSize: 50 }
301
- },
302
- inactive: {
303
- type: "grid",
304
- name: "inactive",
305
- label: "Inactive",
306
- data: { provider: "object", object: "sys_permission_set" },
307
- columns: ["label", "name", "updated_at"],
308
- filter: [{ field: "active", operator: "equals", value: false }],
309
- sort: [{ field: "label", order: "asc" }],
310
- pagination: { pageSize: 50 }
311
- },
312
- all_permsets: {
313
- type: "grid",
314
- name: "all_permsets",
315
- label: "All",
316
- data: { provider: "object", object: "sys_permission_set" },
317
- columns: ["label", "name", "active", "updated_at"],
318
- sort: [{ field: "label", order: "asc" }],
319
- pagination: { pageSize: 50 }
320
- }
321
- },
322
- fields: {
323
- // ── Identity ─────────────────────────────────────────────────
324
- label: Field.text({
325
- label: "Display Name",
326
- required: true,
327
- searchable: true,
328
- maxLength: 255,
329
- group: "Identity"
330
- }),
331
- name: Field.text({
332
- label: "API Name",
333
- required: true,
334
- searchable: true,
335
- maxLength: 100,
336
- description: "Unique machine name for the permission set",
337
- group: "Identity"
338
- }),
339
- description: Field.textarea({
340
- label: "Description",
341
- required: false,
342
- group: "Identity"
343
- }),
344
- // ── Permissions ──────────────────────────────────────────────
345
- object_permissions: Field.textarea({
346
- label: "Object Permissions",
347
- required: false,
348
- description: "JSON-serialized object-level CRUD permissions",
349
- group: "Permissions"
350
- }),
351
- field_permissions: Field.textarea({
352
- label: "Field Permissions",
353
- required: false,
354
- description: "JSON-serialized field-level read/write permissions",
355
- group: "Permissions"
356
- }),
357
- system_permissions: Field.textarea({
358
- label: "System Permissions",
359
- required: false,
360
- description: 'JSON-serialized array of system capability names (e.g. ["setup.access","studio.access","manage_users"])',
361
- group: "Permissions"
362
- }),
363
- row_level_security: Field.textarea({
364
- label: "Row-Level Security",
365
- required: false,
366
- description: "JSON-serialized array of row-level security policies (USING/CHECK clauses)",
367
- group: "Permissions"
368
- }),
369
- tab_permissions: Field.textarea({
370
- label: "Tab Permissions",
371
- required: false,
372
- description: "JSON-serialized map of app tab visibility (visible | hidden | default_on | default_off)",
373
- group: "Permissions"
374
- }),
375
- // ── Status ───────────────────────────────────────────────────
376
- active: Field.boolean({
377
- label: "Active",
378
- defaultValue: true,
379
- group: "Status"
380
- }),
381
- // ── System ───────────────────────────────────────────────────
382
- id: Field.text({
383
- label: "Permission Set ID",
384
- required: true,
385
- readonly: true,
386
- group: "System"
387
- }),
388
- created_at: Field.datetime({
389
- label: "Created At",
390
- defaultValue: "NOW()",
391
- readonly: true,
392
- group: "System"
393
- }),
394
- updated_at: Field.datetime({
395
- label: "Updated At",
396
- defaultValue: "NOW()",
397
- readonly: true,
398
- group: "System"
399
- })
400
- },
401
- indexes: [
402
- { fields: ["name"], unique: true },
403
- { fields: ["active"] }
404
- ],
405
- enable: {
406
- trackHistory: true,
407
- searchable: true,
408
- apiEnabled: true,
409
- apiMethods: ["get", "list", "create", "update", "delete"],
410
- trash: true,
411
- mru: true
412
- }
413
- });
414
- var SysUserPermissionSet = ObjectSchema.create({
415
- name: "sys_user_permission_set",
416
- label: "User Permission Set",
417
- pluralLabel: "User Permission Sets",
418
- icon: "user-check",
419
- isSystem: true,
420
- managedBy: "system",
421
- description: "Direct assignment of a permission set to a user (optionally scoped to an organization).",
422
- titleFormat: "{user_id} \u2192 {permission_set_id}",
423
- compactLayout: ["user_id", "permission_set_id", "organization_id"],
424
- fields: {
425
- id: Field.text({
426
- label: "Assignment ID",
427
- required: true,
428
- readonly: true,
429
- description: "UUID of the assignment."
430
- }),
431
- user_id: Field.lookup("sys_user", {
432
- label: "User",
433
- required: true,
434
- description: "Foreign key to sys_user."
435
- }),
436
- permission_set_id: Field.lookup("sys_permission_set", {
437
- label: "Permission Set",
438
- required: true,
439
- description: "Foreign key to sys_permission_set."
440
- }),
441
- organization_id: Field.lookup("sys_organization", {
442
- label: "Organization",
443
- required: false,
444
- description: "Optional organization scope. NULL = applies in every org context."
445
- }),
446
- granted_by: Field.lookup("sys_user", {
447
- label: "Granted By",
448
- required: false,
449
- description: "User who granted this permission set."
450
- }),
451
- created_at: Field.datetime({
452
- label: "Created At",
453
- defaultValue: "NOW()",
454
- readonly: true
455
- }),
456
- updated_at: Field.datetime({
457
- label: "Updated At",
458
- defaultValue: "NOW()",
459
- readonly: true
460
- })
461
- },
462
- indexes: [
463
- { fields: ["user_id", "permission_set_id", "organization_id"], unique: true },
464
- { fields: ["user_id"] },
465
- { fields: ["organization_id"] },
466
- { fields: ["permission_set_id"] }
467
- ],
468
- enable: {
469
- trackHistory: true,
470
- searchable: true,
471
- apiEnabled: true,
472
- apiMethods: ["get", "list", "create", "update", "delete"],
473
- trash: true,
474
- mru: false
475
- }
476
- });
477
- var SysRolePermissionSet = ObjectSchema.create({
478
- name: "sys_role_permission_set",
479
- label: "Role Permission Set",
480
- pluralLabel: "Role Permission Sets",
481
- icon: "shield-plus",
482
- isSystem: true,
483
- managedBy: "system",
484
- description: "Binds a permission set to a role.",
485
- titleFormat: "{role_id} \u2192 {permission_set_id}",
486
- compactLayout: ["role_id", "permission_set_id"],
487
- fields: {
488
- id: Field.text({
489
- label: "Binding ID",
490
- required: true,
491
- readonly: true,
492
- description: "UUID of the role-permission-set binding."
493
- }),
494
- role_id: Field.lookup("sys_role", {
495
- label: "Role",
496
- required: true,
497
- description: "Foreign key to sys_role."
498
- }),
499
- permission_set_id: Field.lookup("sys_permission_set", {
500
- label: "Permission Set",
501
- required: true,
502
- description: "Foreign key to sys_permission_set."
503
- }),
504
- created_at: Field.datetime({
505
- label: "Created At",
506
- defaultValue: "NOW()",
507
- readonly: true
508
- }),
509
- updated_at: Field.datetime({
510
- label: "Updated At",
511
- defaultValue: "NOW()",
512
- readonly: true
513
- })
514
- },
515
- indexes: [
516
- { fields: ["role_id", "permission_set_id"], unique: true },
517
- { fields: ["role_id"] },
518
- { fields: ["permission_set_id"] }
519
- ],
520
- enable: {
521
- trackHistory: true,
522
- searchable: true,
523
- apiEnabled: true,
524
- apiMethods: ["get", "list", "create", "update", "delete"],
525
- trash: true,
526
- mru: false
527
- }
528
- });
529
- var SysRecordShare = ObjectSchema.create({
530
- name: "sys_record_share",
531
- label: "Record Share",
532
- pluralLabel: "Record Shares",
533
- icon: "share",
534
- isSystem: true,
535
- managedBy: "system",
536
- description: "Per-record sharing grant \u2014 extends OWD with explicit access",
537
- titleFormat: "{object_name}/{record_id} \u2192 {recipient_id} ({access_level})",
538
- compactLayout: ["object_name", "record_id", "recipient_id", "access_level", "source"],
539
- listViews: {
540
- granted_to_me: {
541
- type: "grid",
542
- name: "granted_to_me",
543
- label: "Granted to Me",
544
- data: { provider: "object", object: "sys_record_share" },
545
- columns: ["object_name", "record_id", "access_level", "source", "granted_by", "created_at"],
546
- filter: [
547
- { field: "recipient_type", operator: "equals", value: "user" },
548
- { field: "recipient_id", operator: "equals", value: "{current_user_id}" }
549
- ],
550
- sort: [{ field: "created_at", order: "desc" }],
551
- pagination: { pageSize: 50 }
552
- },
553
- granted_by_me: {
554
- type: "grid",
555
- name: "granted_by_me",
556
- label: "Granted by Me",
557
- data: { provider: "object", object: "sys_record_share" },
558
- columns: ["object_name", "record_id", "recipient_id", "access_level", "source", "created_at"],
559
- filter: [
560
- { field: "granted_by", operator: "equals", value: "{current_user_id}" }
561
- ],
562
- sort: [{ field: "created_at", order: "desc" }],
563
- pagination: { pageSize: 50 }
564
- },
565
- by_object: {
566
- type: "grid",
567
- name: "by_object",
568
- label: "By Object",
569
- data: { provider: "object", object: "sys_record_share" },
570
- columns: ["object_name", "record_id", "recipient_id", "access_level", "source", "created_at"],
571
- sort: [{ field: "object_name", order: "asc" }, { field: "created_at", order: "desc" }],
572
- grouping: { fields: [{ field: "object_name", order: "asc", collapsed: false }] },
573
- pagination: { pageSize: 100 }
574
- },
575
- manual_grants: {
576
- type: "grid",
577
- name: "manual_grants",
578
- label: "Manual Grants",
579
- data: { provider: "object", object: "sys_record_share" },
580
- columns: ["object_name", "record_id", "recipient_id", "access_level", "granted_by", "reason", "created_at"],
581
- filter: [{ field: "source", operator: "equals", value: "manual" }],
582
- sort: [{ field: "created_at", order: "desc" }],
583
- pagination: { pageSize: 50 }
584
- },
585
- rule_grants: {
586
- type: "grid",
587
- name: "rule_grants",
588
- label: "Rule Grants",
589
- data: { provider: "object", object: "sys_record_share" },
590
- columns: ["object_name", "record_id", "recipient_id", "access_level", "source_id", "created_at"],
591
- filter: [{ field: "source", operator: "in", value: ["rule", "team", "inherited"] }],
592
- sort: [{ field: "source_id", order: "asc" }, { field: "created_at", order: "desc" }],
593
- pagination: { pageSize: 50 }
594
- },
595
- all_shares: {
596
- type: "grid",
597
- name: "all_shares",
598
- label: "All",
599
- data: { provider: "object", object: "sys_record_share" },
600
- columns: ["object_name", "record_id", "recipient_type", "recipient_id", "access_level", "source", "created_at"],
601
- sort: [{ field: "created_at", order: "desc" }],
602
- pagination: { pageSize: 100 }
603
- }
604
- },
605
- fields: {
606
- id: Field.text({
607
- label: "Share ID",
608
- required: true,
609
- readonly: true,
610
- group: "System"
611
- }),
612
- // ── Target (which record is being shared) ────────────────────
613
- object_name: Field.text({
614
- label: "Object",
615
- required: true,
616
- maxLength: 100,
617
- description: "Short object name of the shared record",
618
- group: "Target"
619
- }),
620
- record_id: Field.text({
621
- label: "Record",
622
- required: true,
623
- maxLength: 100,
624
- description: "Primary key of the shared record within object_name",
625
- group: "Target"
626
- }),
627
- // ── Recipient (who receives access) ──────────────────────────
628
- recipient_type: Field.select(
629
- ["user", "group", "role", "role_and_subordinates", "guest"],
630
- {
631
- label: "Recipient Type",
632
- required: true,
633
- defaultValue: "user",
634
- description: "Kind of principal that holds the grant",
635
- group: "Recipient"
636
- }
637
- ),
638
- recipient_id: Field.text({
639
- label: "Recipient",
640
- required: true,
641
- maxLength: 100,
642
- description: "ID of the user/group/role that receives access",
643
- group: "Recipient"
644
- }),
645
- access_level: Field.select(
646
- ["read", "edit", "full"],
647
- {
648
- label: "Access Level",
649
- required: true,
650
- defaultValue: "read",
651
- description: "What the recipient can do \u2014 read | edit | full (transfer/share/delete)",
652
- group: "Recipient"
653
- }
654
- ),
655
- // ── Provenance ───────────────────────────────────────────────
656
- source: Field.select(
657
- ["manual", "rule", "team", "inherited"],
658
- {
659
- label: "Source",
660
- required: true,
661
- defaultValue: "manual",
662
- description: "Why this grant exists \u2014 used by the rule evaluator to reconcile",
663
- group: "Provenance"
664
- }
665
- ),
666
- source_id: Field.text({
667
- label: "Source ID",
668
- required: false,
669
- maxLength: 200,
670
- description: "Rule name / team id when source != manual",
671
- group: "Provenance"
672
- }),
673
- granted_by: Field.lookup("sys_user", {
674
- label: "Granted By",
675
- required: false,
676
- description: "User that created the grant (manual only)",
677
- group: "Provenance"
678
- }),
679
- reason: Field.text({
680
- label: "Reason",
681
- required: false,
682
- maxLength: 500,
683
- description: "Optional free-text explanation surfaced to the recipient",
684
- group: "Provenance"
685
- }),
686
- // ── Lifecycle ────────────────────────────────────────────────
687
- created_at: Field.datetime({
688
- label: "Created At",
689
- required: true,
690
- defaultValue: "NOW()",
691
- readonly: true,
692
- group: "System"
693
- }),
694
- updated_at: Field.datetime({
695
- label: "Updated At",
696
- required: false,
697
- group: "System"
698
- })
699
- },
700
- indexes: [
701
- // Hot path: "all records visible to user U on object O" — the
702
- // middleware reads (object_name, recipient_type, recipient_id) to
703
- // build the `id IN (...)` predicate on every find.
704
- { fields: ["object_name", "recipient_type", "recipient_id"] },
705
- // "all grants on this record" — used by the share-management UI
706
- // and by canEdit() to look up explicit grants.
707
- { fields: ["object_name", "record_id"] },
708
- // Reconciliation key for rule-driven shares.
709
- { fields: ["source", "source_id"] }
710
- ]
711
- });
712
- var SysSharingRule = ObjectSchema.create({
713
- name: "sys_sharing_rule",
714
- label: "Sharing Rule",
715
- pluralLabel: "Sharing Rules",
716
- icon: "shield-check",
717
- isSystem: true,
718
- managedBy: "config",
719
- // Sharing rules can now be authored visually via the Studio criteria
720
- // builder (apps/studio/src/components/SharingCriteriaBuilder.tsx).
721
- // We still recommend `defineSharingRule({...})` for repo-controlled
722
- // baselines, but admins can safely create/edit/delete from the UI.
723
- userActions: { create: true, edit: true, delete: true, import: false },
724
- description: "Declarative sharing rule that auto-materialises sys_record_share grants. Authored via defineSharingRule() in code or the Studio criteria builder.",
725
- displayNameField: "name",
726
- titleFormat: "{label}",
727
- compactLayout: ["name", "object_name", "recipient_type", "recipient_id", "access_level", "active"],
728
- listViews: {
729
- active: {
730
- type: "grid",
731
- name: "active",
732
- label: "Active",
733
- data: { provider: "object", object: "sys_sharing_rule" },
734
- columns: ["label", "object_name", "recipient_type", "recipient_id", "access_level", "updated_at"],
735
- filter: [{ field: "active", operator: "equals", value: true }],
736
- sort: [{ field: "object_name", order: "asc" }, { field: "label", order: "asc" }],
737
- pagination: { pageSize: 50 }
738
- },
739
- inactive: {
740
- type: "grid",
741
- name: "inactive",
742
- label: "Inactive",
743
- data: { provider: "object", object: "sys_sharing_rule" },
744
- columns: ["label", "object_name", "recipient_type", "recipient_id", "updated_at"],
745
- filter: [{ field: "active", operator: "equals", value: false }],
746
- sort: [{ field: "label", order: "asc" }],
747
- pagination: { pageSize: 50 }
748
- },
749
- by_object: {
750
- type: "grid",
751
- name: "by_object",
752
- label: "By Object",
753
- data: { provider: "object", object: "sys_sharing_rule" },
754
- columns: ["object_name", "label", "recipient_type", "access_level", "active"],
755
- sort: [{ field: "object_name", order: "asc" }, { field: "label", order: "asc" }],
756
- grouping: { fields: [{ field: "object_name", order: "asc", collapsed: false }] },
757
- pagination: { pageSize: 100 }
758
- },
759
- all_rules: {
760
- type: "grid",
761
- name: "all_rules",
762
- label: "All",
763
- data: { provider: "object", object: "sys_sharing_rule" },
764
- columns: ["label", "object_name", "recipient_type", "recipient_id", "access_level", "active", "updated_at"],
765
- sort: [{ field: "label", order: "asc" }],
766
- pagination: { pageSize: 50 }
767
- }
768
- },
769
- fields: {
770
- id: Field.text({ label: "Rule ID", required: true, readonly: true, group: "System" }),
771
- organization_id: Field.lookup("sys_organization", {
772
- label: "Organization",
773
- required: false,
774
- group: "System",
775
- description: "Tenant that owns this rule; null = global"
776
- }),
777
- name: Field.text({
778
- label: "Name",
779
- required: true,
780
- maxLength: 100,
781
- description: "Unique snake_case rule name",
782
- group: "Identity"
783
- }),
784
- label: Field.text({
785
- label: "Display Label",
786
- required: true,
787
- maxLength: 200,
788
- group: "Identity"
789
- }),
790
- description: Field.textarea({
791
- label: "Description",
792
- required: false,
793
- group: "Identity"
794
- }),
795
- object_name: Field.text({
796
- label: "Object",
797
- required: true,
798
- maxLength: 100,
799
- description: "Short object name (e.g. opportunity, account)",
800
- group: "Target"
801
- }),
802
- criteria_json: Field.textarea({
803
- label: "Criteria (FilterCondition JSON)",
804
- required: false,
805
- description: "JSON FilterCondition matched against records of object_name. Empty = match all.",
806
- group: "Target"
807
- }),
808
- recipient_type: Field.select(
809
- ["user", "team", "department", "role", "queue"],
810
- {
811
- label: "Recipient Type",
812
- required: true,
813
- defaultValue: "department",
814
- description: "Kind of principal that receives access \u2014 expanded to user grants at evaluation time. `department` walks the parent_department_id tree; `team` is flat (better-auth).",
815
- group: "Recipient"
816
- }
817
- ),
818
- recipient_id: Field.text({
819
- label: "Recipient",
820
- required: true,
821
- maxLength: 200,
822
- description: "department id / team id / role name / queue name / user id depending on recipient_type",
823
- group: "Recipient"
824
- }),
825
- access_level: Field.select(
826
- ["read", "edit", "full"],
827
- {
828
- label: "Access Level",
829
- required: true,
830
- defaultValue: "read",
831
- group: "Recipient"
832
- }
833
- ),
834
- active: Field.boolean({
835
- label: "Active",
836
- required: false,
837
- defaultValue: true,
838
- description: "Only active rules participate in lifecycle evaluation",
839
- group: "Lifecycle"
840
- }),
841
- created_at: Field.datetime({
842
- label: "Created At",
843
- required: true,
844
- defaultValue: "NOW()",
845
- readonly: true,
846
- group: "System"
847
- }),
848
- updated_at: Field.datetime({
849
- label: "Updated At",
850
- required: false,
851
- group: "System"
852
- })
853
- },
854
- indexes: [
855
- { fields: ["object_name", "active"] },
856
- { fields: ["name"], unique: true },
857
- { fields: ["organization_id"] }
858
- ]
859
- });
860
- var SysShareLink = ObjectSchema.create({
861
- name: "sys_share_link",
862
- label: "Share Link",
863
- pluralLabel: "Share Links",
864
- icon: "link-2",
865
- isSystem: true,
866
- managedBy: "system",
867
- description: "Opaque capability token granting access to a single record. Notion/Figma-style public link sharing.",
868
- titleFormat: "{object_name}/{record_id} ({permission})",
869
- compactLayout: ["object_name", "record_id", "permission", "audience", "expires_at", "revoked_at"],
870
- listViews: {
871
- active_links: {
872
- type: "grid",
873
- name: "active_links",
874
- label: "Active",
875
- data: { provider: "object", object: "sys_share_link" },
876
- columns: ["object_name", "record_id", "permission", "audience", "expires_at", "use_count", "last_used_at"],
877
- filter: [{ field: "revoked_at", operator: "isNull" }],
878
- sort: [{ field: "created_at", order: "desc" }],
879
- pagination: { pageSize: 100 }
880
- },
881
- by_me: {
882
- type: "grid",
883
- name: "by_me",
884
- label: "Created by Me",
885
- data: { provider: "object", object: "sys_share_link" },
886
- columns: ["object_name", "record_id", "permission", "audience", "expires_at", "revoked_at"],
887
- filter: [{ field: "created_by", operator: "equals", value: "{current_user_id}" }],
888
- sort: [{ field: "created_at", order: "desc" }],
889
- pagination: { pageSize: 100 }
890
- },
891
- revoked: {
892
- type: "grid",
893
- name: "revoked",
894
- label: "Revoked",
895
- data: { provider: "object", object: "sys_share_link" },
896
- columns: ["object_name", "record_id", "revoked_at", "created_by"],
897
- filter: [{ field: "revoked_at", operator: "isNotNull" }],
898
- sort: [{ field: "revoked_at", order: "desc" }],
899
- pagination: { pageSize: 50 }
900
- },
901
- all_links: {
902
- type: "grid",
903
- name: "all_links",
904
- label: "All",
905
- data: { provider: "object", object: "sys_share_link" },
906
- columns: ["object_name", "record_id", "permission", "audience", "expires_at", "revoked_at", "created_at"],
907
- sort: [{ field: "created_at", order: "desc" }],
908
- pagination: { pageSize: 200 }
909
- }
910
- },
911
- fields: {
912
- id: Field.text({
913
- label: "Link ID",
914
- required: true,
915
- readonly: true,
916
- group: "System"
917
- }),
918
- // ── Token (the secret) ───────────────────────────────────────
919
- token: Field.text({
920
- label: "Token",
921
- required: true,
922
- maxLength: 64,
923
- description: "Opaque URL-safe random token (\u2265 22 chars). The only secret in this row.",
924
- group: "Token"
925
- }),
926
- // ── Target ───────────────────────────────────────────────────
927
- object_name: Field.text({
928
- label: "Object",
929
- required: true,
930
- maxLength: 100,
931
- description: "Short object name of the shared record (e.g. ai_conversation, contracts_contract)",
932
- group: "Target"
933
- }),
934
- record_id: Field.text({
935
- label: "Record",
936
- required: true,
937
- maxLength: 100,
938
- description: "Primary key of the shared record within object_name",
939
- group: "Target"
940
- }),
941
- // ── Access Policy ────────────────────────────────────────────
942
- permission: Field.select(
943
- [
944
- { label: "View", value: "view" },
945
- { label: "Comment", value: "comment" },
946
- { label: "Edit", value: "edit" }
947
- ],
948
- {
949
- label: "Permission",
950
- required: true,
951
- defaultValue: "view",
952
- description: "What the link holder can do with the record",
953
- group: "Access Policy"
954
- }
955
- ),
956
- audience: Field.select(
957
- [
958
- { label: "Public (indexable)", value: "public" },
959
- { label: "Anyone with the link", value: "link_only" },
960
- { label: "Signed-in users", value: "signed_in" },
961
- { label: "Specific emails", value: "email" }
962
- ],
963
- {
964
- label: "Audience",
965
- required: true,
966
- defaultValue: "link_only",
967
- description: "Gating layer applied on top of the token check",
968
- group: "Access Policy"
969
- }
970
- ),
971
- expires_at: Field.datetime({
972
- label: "Expires At",
973
- description: "When set, resolveToken returns null after this timestamp",
974
- group: "Access Policy"
975
- }),
976
- email_allowlist: Field.json({
977
- label: "Email Allowlist",
978
- description: "Lowercased addresses checked when audience=email",
979
- group: "Access Policy"
980
- }),
981
- password_hash: Field.text({
982
- label: "Password Hash",
983
- maxLength: 256,
984
- description: "Argon2/bcrypt hash. When set, the UI prompts for a password before rendering.",
985
- group: "Access Policy"
986
- }),
987
- redact_fields: Field.json({
988
- label: "Per-Link Redactions",
989
- description: "Extra fields stripped from the response, on top of the object-default set",
990
- group: "Access Policy"
991
- }),
992
- label: Field.text({
993
- label: "Label",
994
- maxLength: 200,
995
- description: 'Free-text shown in the share dialog (e.g. "ACME Q3 contract")',
996
- group: "Metadata"
997
- }),
998
- // ── Lifecycle ────────────────────────────────────────────────
999
- revoked_at: Field.datetime({
1000
- label: "Revoked At",
1001
- readonly: true,
1002
- description: "When set, the link is permanently disabled",
1003
- group: "Lifecycle"
1004
- }),
1005
- created_by: Field.lookup("sys_user", {
1006
- label: "Created By",
1007
- readonly: true,
1008
- description: "Issuer of the link",
1009
- group: "Lifecycle"
1010
- }),
1011
- created_at: Field.datetime({
1012
- label: "Created At",
1013
- required: true,
1014
- defaultValue: "NOW()",
1015
- readonly: true,
1016
- group: "Lifecycle"
1017
- }),
1018
- last_used_at: Field.datetime({
1019
- label: "Last Used At",
1020
- readonly: true,
1021
- description: "Stamped by resolveToken; used by the dashboard to highlight active links",
1022
- group: "Lifecycle"
1023
- }),
1024
- use_count: Field.number({
1025
- label: "Use Count",
1026
- defaultValue: 0,
1027
- readonly: true,
1028
- description: "Incremented by resolveToken on every successful resolution",
1029
- group: "Lifecycle"
1030
- })
1031
- },
1032
- indexes: [
1033
- // Hot path: resolveToken — one row lookup per public request.
1034
- { fields: ["token"], unique: true },
1035
- // Management UI: "all links for this record".
1036
- { fields: ["object_name", "record_id"] },
1037
- // "Active links I issued".
1038
- { fields: ["created_by", "revoked_at"] },
1039
- // Reaper for expired rows (background sweep).
1040
- { fields: ["expires_at"] }
1041
- ],
1042
- enable: {
1043
- trackHistory: false,
1044
- searchable: false,
1045
- apiEnabled: true,
1046
- // The /api/v1/share-links endpoints are the authoritative surface;
1047
- // the generic data API is exposed read-only for the admin grid.
1048
- apiMethods: ["get", "list"],
1049
- trash: false,
1050
- mru: false,
1051
- clone: false
1052
- }
1053
- });
1054
- var BETTER_AUTH_MANAGED_OBJECTS = [
1055
- "sys_user",
1056
- "sys_account",
1057
- "sys_session",
1058
- "sys_organization",
1059
- "sys_member",
1060
- "sys_invitation",
1061
- "sys_team",
1062
- "sys_team_member",
1063
- "sys_api_key",
1064
- "sys_two_factor",
1065
- "sys_verification",
1066
- "sys_jwks",
1067
- "sys_device_code",
1068
- "sys_oauth_application",
1069
- "sys_oauth_access_token",
1070
- "sys_oauth_refresh_token",
1071
- "sys_oauth_consent"
1072
- ];
1073
- var denyWritesOnManagedObjects = () => Object.fromEntries(
1074
- BETTER_AUTH_MANAGED_OBJECTS.map((name) => [
1075
- name,
1076
- { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }
1077
- ])
1078
- );
1079
- var defaultPermissionSets = [
1080
- PermissionSetSchema.parse({
1081
- name: "admin_full_access",
1082
- label: "Administrator \u2014 Full Access",
1083
- isProfile: true,
1084
- objects: {
1085
- "*": {
1086
- allowRead: true,
1087
- allowCreate: true,
1088
- allowEdit: true,
1089
- allowDelete: true,
1090
- viewAllRecords: true,
1091
- modifyAllRecords: true
1092
- }
1093
- },
1094
- systemPermissions: [
1095
- "manage_users",
1096
- "manage_metadata",
1097
- "manage_platform_settings",
1098
- "setup.access",
1099
- "studio.access"
1100
- ]
1101
- }),
1102
- // ── Organization Administrator ──────────────────────────────────────
1103
- //
1104
- // Third tier between platform admin (`admin_full_access`) and rank-and-file
1105
- // member. Lives at the *organization* scope: full CRUD on business
1106
- // objects within their org (governed by `tenant_isolation` RLS), plus
1107
- // `setup.access` so the Setup app shell is reachable.
1108
- //
1109
- // **Deliberately withheld** vs `admin_full_access`:
1110
- // - `studio.access` — schema-design surfaces are platform-level (a
1111
- // tenant cannot mutate the shared metadata) and Studio is hidden.
1112
- // - `manage_metadata` — same reasoning.
1113
- // - `manage_platform_settings` — global settings manifests
1114
- // (mail / storage / AI / knowledge) and platform-only Setup pages
1115
- // (sharing rules, audit logs, OAuth apps, JWKS, …) require this
1116
- // and are hidden / 403'd for org admins. Tenant-scoped manifests
1117
- // (`branding`, `feature_flags`) keep using `setup.access` so org
1118
- // admins CAN configure their own org's branding.
1119
- //
1120
- // **Anti-escalation**: writes to the global RBAC tables
1121
- // (`sys_role`, `sys_permission_set`, `sys_role_permission_set`,
1122
- // `sys_user_permission_set`, `sys_user_role`) are denied. Allowing
1123
- // them would let an org admin bind `admin_full_access` (which has no
1124
- // RLS) to themselves and break out of tenant isolation. Reads are
1125
- // permitted so the Roles / Permission Sets nav entries still render.
1126
- //
1127
- // Auto-granted to every `sys_member` whose role contains `owner` or
1128
- // `admin` by `plugin-security/src/auto-org-admin-grant.ts`.
1129
- PermissionSetSchema.parse({
1130
- name: "organization_admin",
1131
- label: "Organization Administrator",
1132
- isProfile: true,
1133
- objects: {
1134
- "*": {
1135
- allowRead: true,
1136
- allowCreate: true,
1137
- allowEdit: true,
1138
- allowDelete: true,
1139
- viewAllRecords: true,
1140
- modifyAllRecords: true
1141
- },
1142
- // Identity tables — go through better-auth endpoints (invite,
1143
- // accept, remove-member, transfer, …) rather than raw CRUD.
1144
- ...denyWritesOnManagedObjects(),
1145
- // RBAC tables — read-only to prevent privilege escalation.
1146
- sys_role: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
1147
- sys_permission_set: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
1148
- sys_role_permission_set: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
1149
- sys_user_permission_set: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
1150
- sys_user_role: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }
1151
- },
1152
- systemPermissions: ["manage_org_users", "setup.access"],
1153
- rowLevelSecurity: [
1154
- {
1155
- name: "tenant_isolation",
1156
- object: "*",
1157
- operation: "all",
1158
- using: "organization_id = current_user.organization_id"
1159
- },
1160
- // ── better-auth system tables that lack `organization_id` and would
1161
- // otherwise be denied by the wildcard policy. Same self-only
1162
- // carve-outs as `member_default` — an org admin does not get to
1163
- // inspect cross-tenant identity rows.
1164
- {
1165
- name: "sys_organization_self",
1166
- object: "sys_organization",
1167
- operation: "all",
1168
- using: "id = current_user.organization_id"
1169
- },
1170
- {
1171
- name: "sys_user_self",
1172
- object: "sys_user",
1173
- operation: "select",
1174
- using: "id = current_user.id"
1175
- },
1176
- {
1177
- name: "sys_user_org_members",
1178
- object: "sys_user",
1179
- operation: "select",
1180
- using: "id IN (current_user.org_user_ids)"
1181
- },
1182
- {
1183
- name: "sys_session_self",
1184
- object: "sys_session",
1185
- operation: "all",
1186
- using: "user_id = current_user.id"
1187
- },
1188
- {
1189
- name: "sys_account_self",
1190
- object: "sys_account",
1191
- operation: "select",
1192
- using: "user_id = current_user.id"
1193
- },
1194
- {
1195
- name: "sys_team_member_self",
1196
- object: "sys_team_member",
1197
- operation: "select",
1198
- using: "user_id = current_user.id"
1199
- },
1200
- {
1201
- name: "sys_two_factor_self",
1202
- object: "sys_two_factor",
1203
- operation: "all",
1204
- using: "user_id = current_user.id"
1205
- },
1206
- {
1207
- name: "sys_user_preference_self",
1208
- object: "sys_user_preference",
1209
- operation: "all",
1210
- using: "user_id = current_user.id"
1211
- },
1212
- {
1213
- name: "sys_api_key_self",
1214
- object: "sys_api_key",
1215
- operation: "all",
1216
- using: "user_id = current_user.id"
1217
- },
1218
- {
1219
- name: "sys_device_code_self",
1220
- object: "sys_device_code",
1221
- operation: "all",
1222
- using: "user_id = current_user.id"
1223
- },
1224
- {
1225
- name: "sys_oauth_access_token_self",
1226
- object: "sys_oauth_access_token",
1227
- operation: "select",
1228
- using: "user_id = current_user.id"
1229
- },
1230
- {
1231
- name: "sys_oauth_refresh_token_self",
1232
- object: "sys_oauth_refresh_token",
1233
- operation: "select",
1234
- using: "user_id = current_user.id"
1235
- },
1236
- {
1237
- name: "sys_oauth_consent_self",
1238
- object: "sys_oauth_consent",
1239
- operation: "all",
1240
- using: "user_id = current_user.id"
1241
- },
1242
- // OAuth applications a user has registered themselves (self-service
1243
- // developer flow exposed in the Account app's Developer section).
1244
- // `sys_oauth_application` has no `organization_id` so the wildcard
1245
- // `tenant_isolation` policy would otherwise deny every row.
1246
- {
1247
- name: "sys_oauth_application_self",
1248
- object: "sys_oauth_application",
1249
- operation: "all",
1250
- using: "user_id = current_user.id"
1251
- },
1252
- // Org-scoped visibility for organization-owned identity-adjacent
1253
- // tables. Org admins may inspect their own org's invitations and
1254
- // memberships (read; writes still flow through better-auth).
1255
- {
1256
- name: "sys_member_org",
1257
- object: "sys_member",
1258
- operation: "select",
1259
- using: "organization_id = current_user.organization_id"
1260
- },
1261
- {
1262
- name: "sys_invitation_org",
1263
- object: "sys_invitation",
1264
- operation: "select",
1265
- using: "organization_id = current_user.organization_id"
1266
- },
1267
- {
1268
- name: "sys_team_org",
1269
- object: "sys_team",
1270
- operation: "select",
1271
- using: "organization_id = current_user.organization_id"
1272
- }
1273
- ]
1274
- }),
1275
- PermissionSetSchema.parse({
1276
- name: "member_default",
1277
- label: "Member \u2014 Standard Access",
1278
- isProfile: true,
1279
- objects: {
1280
- "*": {
1281
- allowRead: true,
1282
- allowCreate: true,
1283
- allowEdit: true,
1284
- allowDelete: true
1285
- },
1286
- // Identity tables are managed by better-auth — no direct writes.
1287
- ...denyWritesOnManagedObjects()
1288
- },
1289
- rowLevelSecurity: [
1290
- {
1291
- name: "tenant_isolation",
1292
- object: "*",
1293
- operation: "all",
1294
- using: "organization_id = current_user.organization_id"
1295
- },
1296
- {
1297
- name: "owner_only_writes",
1298
- object: "*",
1299
- operation: "update",
1300
- using: "owner_id = current_user.id"
1301
- },
1302
- {
1303
- name: "owner_only_deletes",
1304
- object: "*",
1305
- operation: "delete",
1306
- using: "owner_id = current_user.id"
1307
- },
1308
- // ── better-auth system tables that lack `organization_id` and would
1309
- // otherwise be left unprotected by the wildcard rule above. ────
1310
- //
1311
- // The security plugin's RLS injector treats wildcard policies that
1312
- // target a missing field as `RLS_DENY_FILTER` (zero rows) unless a
1313
- // per-object policy contributes an alternate match. Each `*_self`
1314
- // policy below restores per-user visibility on a better-auth table
1315
- // that has `user_id` but no `organization_id`. Tables without
1316
- // `user_id` (`sys_verification`, `sys_jwks`, empty `sys_passkey`)
1317
- // stay DENY for non-admins by design — only platform admins (via
1318
- // `admin_full_access`, which has no RLS) should inspect them.
1319
- {
1320
- name: "sys_organization_self",
1321
- object: "sys_organization",
1322
- operation: "all",
1323
- using: "id = current_user.organization_id"
1324
- },
1325
- {
1326
- name: "sys_user_self",
1327
- object: "sys_user",
1328
- operation: "select",
1329
- using: "id = current_user.id"
1330
- },
1331
- // Org collaborators: members can see other users in the same
1332
- // organization. Without this, owner/assignee lookups, @-mention
1333
- // suggestions, reviewer pickers and team-roster surfaces all
1334
- // collapse to just the current user. `org_user_ids` is
1335
- // pre-resolved by runtime/resolve-execution-context from
1336
- // `sys_member` for the active organization. Sensitive credential
1337
- // tables (`sys_account`, `sys_session`, `sys_api_key`, …) keep
1338
- // their stricter self-only carve-outs above.
1339
- {
1340
- name: "sys_user_org_members",
1341
- object: "sys_user",
1342
- operation: "select",
1343
- using: "id IN (current_user.org_user_ids)"
1344
- },
1345
- {
1346
- name: "sys_session_self",
1347
- object: "sys_session",
1348
- operation: "all",
1349
- using: "user_id = current_user.id"
1350
- },
1351
- {
1352
- name: "sys_account_self",
1353
- object: "sys_account",
1354
- operation: "select",
1355
- using: "user_id = current_user.id"
1356
- },
1357
- {
1358
- name: "sys_team_member_self",
1359
- object: "sys_team_member",
1360
- operation: "select",
1361
- using: "user_id = current_user.id"
1362
- },
1363
- {
1364
- name: "sys_two_factor_self",
1365
- object: "sys_two_factor",
1366
- operation: "all",
1367
- using: "user_id = current_user.id"
1368
- },
1369
- {
1370
- name: "sys_user_preference_self",
1371
- object: "sys_user_preference",
1372
- operation: "all",
1373
- using: "user_id = current_user.id"
1374
- },
1375
- {
1376
- name: "sys_api_key_self",
1377
- object: "sys_api_key",
1378
- operation: "all",
1379
- using: "user_id = current_user.id"
1380
- },
1381
- {
1382
- name: "sys_device_code_self",
1383
- object: "sys_device_code",
1384
- operation: "all",
1385
- using: "user_id = current_user.id"
1386
- },
1387
- {
1388
- name: "sys_oauth_access_token_self",
1389
- object: "sys_oauth_access_token",
1390
- operation: "select",
1391
- using: "user_id = current_user.id"
1392
- },
1393
- {
1394
- name: "sys_oauth_refresh_token_self",
1395
- object: "sys_oauth_refresh_token",
1396
- operation: "select",
1397
- using: "user_id = current_user.id"
1398
- },
1399
- {
1400
- name: "sys_oauth_consent_self",
1401
- object: "sys_oauth_consent",
1402
- operation: "all",
1403
- using: "user_id = current_user.id"
1404
- },
1405
- // OAuth applications a user has registered themselves (Account →
1406
- // Developer → OAuth Applications). `sys_oauth_application` has no
1407
- // `organization_id`, so without this carve-out the wildcard
1408
- // `tenant_isolation` policy returns zero rows even for the owner.
1409
- {
1410
- name: "sys_oauth_application_self",
1411
- object: "sys_oauth_application",
1412
- operation: "all",
1413
- using: "user_id = current_user.id"
1414
- }
1415
- ]
1416
- }),
1417
- PermissionSetSchema.parse({
1418
- name: "viewer_readonly",
1419
- label: "Viewer \u2014 Read-Only",
1420
- isProfile: true,
1421
- objects: {
1422
- "*": {
1423
- allowRead: true,
1424
- allowCreate: false,
1425
- allowEdit: false,
1426
- allowDelete: false
1427
- },
1428
- // Belt-and-suspenders: explicit deny on managed objects even though
1429
- // the wildcard already denies — keeps the policy readable when
1430
- // future relaxations might widen the wildcard.
1431
- ...denyWritesOnManagedObjects()
1432
- },
1433
- rowLevelSecurity: [
1434
- {
1435
- name: "tenant_isolation",
1436
- object: "*",
1437
- operation: "select",
1438
- using: "organization_id = current_user.organization_id"
1439
- },
1440
- {
1441
- name: "sys_organization_self",
1442
- object: "sys_organization",
1443
- operation: "select",
1444
- using: "id = current_user.organization_id"
1445
- },
1446
- {
1447
- name: "sys_user_self",
1448
- object: "sys_user",
1449
- operation: "select",
1450
- using: "id = current_user.id"
1451
- },
1452
- // Org collaborators (read-only): see `sys_user_org_members` in
1453
- // `member_default` for rationale.
1454
- {
1455
- name: "sys_user_org_members",
1456
- object: "sys_user",
1457
- operation: "select",
1458
- using: "id IN (current_user.org_user_ids)"
1459
- },
1460
- {
1461
- name: "sys_session_self",
1462
- object: "sys_session",
1463
- operation: "select",
1464
- using: "user_id = current_user.id"
1465
- },
1466
- {
1467
- name: "sys_account_self",
1468
- object: "sys_account",
1469
- operation: "select",
1470
- using: "user_id = current_user.id"
1471
- },
1472
- {
1473
- name: "sys_team_member_self",
1474
- object: "sys_team_member",
1475
- operation: "select",
1476
- using: "user_id = current_user.id"
1477
- },
1478
- {
1479
- name: "sys_two_factor_self",
1480
- object: "sys_two_factor",
1481
- operation: "select",
1482
- using: "user_id = current_user.id"
1483
- },
1484
- {
1485
- name: "sys_user_preference_self",
1486
- object: "sys_user_preference",
1487
- operation: "select",
1488
- using: "user_id = current_user.id"
1489
- },
1490
- {
1491
- name: "sys_api_key_self",
1492
- object: "sys_api_key",
1493
- operation: "select",
1494
- using: "user_id = current_user.id"
1495
- },
1496
- {
1497
- name: "sys_device_code_self",
1498
- object: "sys_device_code",
1499
- operation: "select",
1500
- using: "user_id = current_user.id"
1501
- },
1502
- {
1503
- name: "sys_oauth_access_token_self",
1504
- object: "sys_oauth_access_token",
1505
- operation: "select",
1506
- using: "user_id = current_user.id"
1507
- },
1508
- {
1509
- name: "sys_oauth_refresh_token_self",
1510
- object: "sys_oauth_refresh_token",
1511
- operation: "select",
1512
- using: "user_id = current_user.id"
1513
- },
1514
- {
1515
- name: "sys_oauth_consent_self",
1516
- object: "sys_oauth_consent",
1517
- operation: "select",
1518
- using: "user_id = current_user.id"
1519
- }
1520
- ]
1521
- })
1522
- ];
1523
-
1524
- export { SysPermissionSet, SysRecordShare, SysRole, SysRolePermissionSet, SysShareLink, SysSharingRule, SysUserPermissionSet, defaultPermissionSets };
1525
2
  //# sourceMappingURL=index.mjs.map
1526
3
  //# sourceMappingURL=index.mjs.map