@objectstack/platform-objects 0.1.0 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var data = require('@objectstack/spec/data');
4
+ var security = require('@objectstack/spec/security');
4
5
  var ui = require('@objectstack/spec/ui');
5
6
 
6
7
  // src/identity/sys-user.object.ts
@@ -10,6 +11,7 @@ var SysUser = data.ObjectSchema.create({
10
11
  pluralLabel: "Users",
11
12
  icon: "user",
12
13
  isSystem: true,
14
+ managedBy: "better-auth",
13
15
  description: "User accounts for authentication",
14
16
  displayNameField: "name",
15
17
  titleFormat: "{name}",
@@ -95,6 +97,7 @@ var SysSession = data.ObjectSchema.create({
95
97
  pluralLabel: "Sessions",
96
98
  icon: "key",
97
99
  isSystem: true,
100
+ managedBy: "better-auth",
98
101
  description: "Active user sessions",
99
102
  displayNameField: "user_id",
100
103
  titleFormat: "Session \u2014 {user_id}",
@@ -186,6 +189,7 @@ var SysAccount = data.ObjectSchema.create({
186
189
  pluralLabel: "Accounts",
187
190
  icon: "link",
188
191
  isSystem: true,
192
+ managedBy: "better-auth",
189
193
  description: "OAuth and authentication provider accounts",
190
194
  titleFormat: "{provider_id} - {account_id}",
191
195
  compactLayout: ["provider_id", "user_id", "account_id"],
@@ -269,6 +273,7 @@ var SysVerification = data.ObjectSchema.create({
269
273
  pluralLabel: "Verifications",
270
274
  icon: "shield-check",
271
275
  isSystem: true,
276
+ managedBy: "better-auth",
272
277
  description: "Email and phone verification tokens",
273
278
  titleFormat: "Verification for {identifier}",
274
279
  compactLayout: ["identifier", "expires_at", "created_at"],
@@ -323,6 +328,7 @@ var SysOrganization = data.ObjectSchema.create({
323
328
  pluralLabel: "Organizations",
324
329
  icon: "building-2",
325
330
  isSystem: true,
331
+ managedBy: "better-auth",
326
332
  description: "Organizations for multi-tenant grouping",
327
333
  displayNameField: "name",
328
334
  titleFormat: "{name}",
@@ -396,6 +402,7 @@ var SysMember = data.ObjectSchema.create({
396
402
  pluralLabel: "Members",
397
403
  icon: "user-check",
398
404
  isSystem: true,
405
+ managedBy: "better-auth",
399
406
  description: "Organization membership records",
400
407
  titleFormat: "{user_id} in {organization_id}",
401
408
  compactLayout: ["user_id", "organization_id", "role"],
@@ -444,6 +451,7 @@ var SysInvitation = data.ObjectSchema.create({
444
451
  pluralLabel: "Invitations",
445
452
  icon: "mail",
446
453
  isSystem: true,
454
+ managedBy: "better-auth",
447
455
  description: "Organization invitations for user onboarding",
448
456
  titleFormat: "Invitation to {organization_id}",
449
457
  compactLayout: ["email", "organization_id", "status"],
@@ -513,6 +521,7 @@ var SysTeam = data.ObjectSchema.create({
513
521
  pluralLabel: "Teams",
514
522
  icon: "users",
515
523
  isSystem: true,
524
+ managedBy: "better-auth",
516
525
  description: "Teams within organizations for fine-grained grouping",
517
526
  displayNameField: "name",
518
527
  titleFormat: "{name}",
@@ -571,6 +580,7 @@ var SysTeamMember = data.ObjectSchema.create({
571
580
  pluralLabel: "Team Members",
572
581
  icon: "user-plus",
573
582
  isSystem: true,
583
+ managedBy: "better-auth",
574
584
  description: "Team membership records linking users to teams",
575
585
  titleFormat: "{user_id} in {team_id}",
576
586
  compactLayout: ["user_id", "team_id", "created_at"],
@@ -613,6 +623,7 @@ var SysApiKey = data.ObjectSchema.create({
613
623
  pluralLabel: "API Keys",
614
624
  icon: "key-round",
615
625
  isSystem: true,
626
+ managedBy: "better-auth",
616
627
  description: "API keys for programmatic access",
617
628
  displayNameField: "name",
618
629
  titleFormat: "{name}",
@@ -715,6 +726,7 @@ var SysTwoFactor = data.ObjectSchema.create({
715
726
  pluralLabel: "Two Factor Credentials",
716
727
  icon: "smartphone",
717
728
  isSystem: true,
729
+ managedBy: "better-auth",
718
730
  description: "Two-factor authentication credentials",
719
731
  titleFormat: "Two-factor for {user_id}",
720
732
  compactLayout: ["user_id", "created_at"],
@@ -767,6 +779,7 @@ var SysDeviceCode = data.ObjectSchema.create({
767
779
  pluralLabel: "Device Codes",
768
780
  icon: "key-round",
769
781
  isSystem: true,
782
+ managedBy: "better-auth",
770
783
  description: "OAuth 2.0 Device Authorization Grant (RFC 8628) pending requests",
771
784
  titleFormat: "{user_code}",
772
785
  compactLayout: ["user_code", "status", "client_id", "expires_at"],
@@ -910,6 +923,7 @@ var SysOauthApplication = data.ObjectSchema.create({
910
923
  pluralLabel: "OAuth Applications",
911
924
  icon: "key-round",
912
925
  isSystem: true,
926
+ managedBy: "better-auth",
913
927
  description: "Registered OAuth/OIDC client applications",
914
928
  displayNameField: "name",
915
929
  titleFormat: "{name}",
@@ -1125,6 +1139,7 @@ var SysOauthAccessToken = data.ObjectSchema.create({
1125
1139
  pluralLabel: "OAuth Access Tokens",
1126
1140
  icon: "ticket",
1127
1141
  isSystem: true,
1142
+ managedBy: "better-auth",
1128
1143
  description: "Opaque OAuth access tokens issued to client applications",
1129
1144
  compactLayout: ["client_id", "user_id", "expires_at"],
1130
1145
  fields: {
@@ -1202,6 +1217,7 @@ var SysOauthRefreshToken = data.ObjectSchema.create({
1202
1217
  pluralLabel: "OAuth Refresh Tokens",
1203
1218
  icon: "refresh-cw",
1204
1219
  isSystem: true,
1220
+ managedBy: "better-auth",
1205
1221
  description: "Opaque OAuth refresh tokens (linked to a session)",
1206
1222
  compactLayout: ["client_id", "user_id", "expires_at"],
1207
1223
  fields: {
@@ -1283,6 +1299,7 @@ var SysOauthConsent = data.ObjectSchema.create({
1283
1299
  pluralLabel: "OAuth Consents",
1284
1300
  icon: "shield-check",
1285
1301
  isSystem: true,
1302
+ managedBy: "better-auth",
1286
1303
  description: "User consent records for OAuth client applications",
1287
1304
  compactLayout: ["client_id", "user_id", "scopes"],
1288
1305
  fields: {
@@ -1342,6 +1359,7 @@ var SysJwks = data.ObjectSchema.create({
1342
1359
  pluralLabel: "JWKS Keys",
1343
1360
  icon: "key",
1344
1361
  isSystem: true,
1362
+ managedBy: "better-auth",
1345
1363
  description: "Asymmetric key pairs used to sign and verify issued JWTs",
1346
1364
  compactLayout: ["id", "created_at", "expires_at"],
1347
1365
  fields: {
@@ -1550,6 +1568,248 @@ var SysPermissionSet = data.ObjectSchema.create({
1550
1568
  mru: true
1551
1569
  }
1552
1570
  });
1571
+ var SysUserPermissionSet = data.ObjectSchema.create({
1572
+ name: "sys_user_permission_set",
1573
+ label: "User Permission Set",
1574
+ pluralLabel: "User Permission Sets",
1575
+ icon: "user-check",
1576
+ isSystem: true,
1577
+ description: "Direct assignment of a permission set to a user (optionally scoped to an organization).",
1578
+ titleFormat: "{user_id} \u2192 {permission_set_id}",
1579
+ compactLayout: ["user_id", "permission_set_id", "organization_id"],
1580
+ fields: {
1581
+ id: data.Field.text({
1582
+ label: "Assignment ID",
1583
+ required: true,
1584
+ readonly: true,
1585
+ description: "UUID of the assignment."
1586
+ }),
1587
+ user_id: data.Field.lookup("sys_user", {
1588
+ label: "User",
1589
+ required: true,
1590
+ description: "Foreign key to sys_user."
1591
+ }),
1592
+ permission_set_id: data.Field.lookup("sys_permission_set", {
1593
+ label: "Permission Set",
1594
+ required: true,
1595
+ description: "Foreign key to sys_permission_set."
1596
+ }),
1597
+ organization_id: data.Field.lookup("sys_organization", {
1598
+ label: "Organization",
1599
+ required: false,
1600
+ description: "Optional organization scope. NULL = applies in every org context."
1601
+ }),
1602
+ granted_by: data.Field.lookup("sys_user", {
1603
+ label: "Granted By",
1604
+ required: false,
1605
+ description: "User who granted this permission set."
1606
+ }),
1607
+ created_at: data.Field.datetime({
1608
+ label: "Created At",
1609
+ defaultValue: "NOW()",
1610
+ readonly: true
1611
+ }),
1612
+ updated_at: data.Field.datetime({
1613
+ label: "Updated At",
1614
+ defaultValue: "NOW()",
1615
+ readonly: true
1616
+ })
1617
+ },
1618
+ indexes: [
1619
+ { fields: ["user_id", "permission_set_id", "organization_id"], unique: true },
1620
+ { fields: ["user_id"] },
1621
+ { fields: ["organization_id"] },
1622
+ { fields: ["permission_set_id"] }
1623
+ ],
1624
+ enable: {
1625
+ trackHistory: true,
1626
+ searchable: true,
1627
+ apiEnabled: true,
1628
+ apiMethods: ["get", "list", "create", "update", "delete"],
1629
+ trash: true,
1630
+ mru: false
1631
+ }
1632
+ });
1633
+ var SysRolePermissionSet = data.ObjectSchema.create({
1634
+ name: "sys_role_permission_set",
1635
+ label: "Role Permission Set",
1636
+ pluralLabel: "Role Permission Sets",
1637
+ icon: "shield-plus",
1638
+ isSystem: true,
1639
+ description: "Binds a permission set to a role.",
1640
+ titleFormat: "{role_id} \u2192 {permission_set_id}",
1641
+ compactLayout: ["role_id", "permission_set_id"],
1642
+ fields: {
1643
+ id: data.Field.text({
1644
+ label: "Binding ID",
1645
+ required: true,
1646
+ readonly: true,
1647
+ description: "UUID of the role-permission-set binding."
1648
+ }),
1649
+ role_id: data.Field.lookup("sys_role", {
1650
+ label: "Role",
1651
+ required: true,
1652
+ description: "Foreign key to sys_role."
1653
+ }),
1654
+ permission_set_id: data.Field.lookup("sys_permission_set", {
1655
+ label: "Permission Set",
1656
+ required: true,
1657
+ description: "Foreign key to sys_permission_set."
1658
+ }),
1659
+ created_at: data.Field.datetime({
1660
+ label: "Created At",
1661
+ defaultValue: "NOW()",
1662
+ readonly: true
1663
+ }),
1664
+ updated_at: data.Field.datetime({
1665
+ label: "Updated At",
1666
+ defaultValue: "NOW()",
1667
+ readonly: true
1668
+ })
1669
+ },
1670
+ indexes: [
1671
+ { fields: ["role_id", "permission_set_id"], unique: true },
1672
+ { fields: ["role_id"] },
1673
+ { fields: ["permission_set_id"] }
1674
+ ],
1675
+ enable: {
1676
+ trackHistory: true,
1677
+ searchable: true,
1678
+ apiEnabled: true,
1679
+ apiMethods: ["get", "list", "create", "update", "delete"],
1680
+ trash: true,
1681
+ mru: false
1682
+ }
1683
+ });
1684
+ var BETTER_AUTH_MANAGED_OBJECTS = [
1685
+ "sys_user",
1686
+ "sys_account",
1687
+ "sys_session",
1688
+ "sys_organization",
1689
+ "sys_member",
1690
+ "sys_invitation",
1691
+ "sys_team",
1692
+ "sys_team_member",
1693
+ "sys_api_key",
1694
+ "sys_two_factor",
1695
+ "sys_verification",
1696
+ "sys_jwks",
1697
+ "sys_device_code",
1698
+ "sys_oauth_application",
1699
+ "sys_oauth_access_token",
1700
+ "sys_oauth_refresh_token",
1701
+ "sys_oauth_consent"
1702
+ ];
1703
+ var denyWritesOnManagedObjects = () => Object.fromEntries(
1704
+ BETTER_AUTH_MANAGED_OBJECTS.map((name) => [
1705
+ name,
1706
+ { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }
1707
+ ])
1708
+ );
1709
+ var defaultPermissionSets = [
1710
+ security.PermissionSetSchema.parse({
1711
+ name: "admin_full_access",
1712
+ label: "Administrator \u2014 Full Access",
1713
+ isProfile: true,
1714
+ objects: {
1715
+ "*": {
1716
+ allowRead: true,
1717
+ allowCreate: true,
1718
+ allowEdit: true,
1719
+ allowDelete: true,
1720
+ viewAllRecords: true,
1721
+ modifyAllRecords: true
1722
+ }
1723
+ },
1724
+ systemPermissions: ["manage_users", "manage_metadata", "setup.access"]
1725
+ }),
1726
+ security.PermissionSetSchema.parse({
1727
+ name: "member_default",
1728
+ label: "Member \u2014 Standard Access",
1729
+ isProfile: true,
1730
+ objects: {
1731
+ "*": {
1732
+ allowRead: true,
1733
+ allowCreate: true,
1734
+ allowEdit: true,
1735
+ allowDelete: true
1736
+ },
1737
+ // Identity tables are managed by better-auth — no direct writes.
1738
+ ...denyWritesOnManagedObjects()
1739
+ },
1740
+ rowLevelSecurity: [
1741
+ {
1742
+ name: "tenant_isolation",
1743
+ object: "*",
1744
+ operation: "all",
1745
+ using: "organization_id = current_user.organization_id"
1746
+ },
1747
+ {
1748
+ name: "owner_only_writes",
1749
+ object: "*",
1750
+ operation: "update",
1751
+ using: "owner_id = current_user.id"
1752
+ },
1753
+ {
1754
+ name: "owner_only_deletes",
1755
+ object: "*",
1756
+ operation: "delete",
1757
+ using: "owner_id = current_user.id"
1758
+ },
1759
+ // ── better-auth system tables that lack `organization_id` and would
1760
+ // otherwise be left unprotected by the wildcard rule above. ────
1761
+ {
1762
+ name: "sys_organization_self",
1763
+ object: "sys_organization",
1764
+ operation: "all",
1765
+ using: "id = current_user.organization_id"
1766
+ },
1767
+ {
1768
+ name: "sys_user_self",
1769
+ object: "sys_user",
1770
+ operation: "select",
1771
+ using: "id = current_user.id"
1772
+ }
1773
+ ]
1774
+ }),
1775
+ security.PermissionSetSchema.parse({
1776
+ name: "viewer_readonly",
1777
+ label: "Viewer \u2014 Read-Only",
1778
+ isProfile: true,
1779
+ objects: {
1780
+ "*": {
1781
+ allowRead: true,
1782
+ allowCreate: false,
1783
+ allowEdit: false,
1784
+ allowDelete: false
1785
+ },
1786
+ // Belt-and-suspenders: explicit deny on managed objects even though
1787
+ // the wildcard already denies — keeps the policy readable when
1788
+ // future relaxations might widen the wildcard.
1789
+ ...denyWritesOnManagedObjects()
1790
+ },
1791
+ rowLevelSecurity: [
1792
+ {
1793
+ name: "tenant_isolation",
1794
+ object: "*",
1795
+ operation: "select",
1796
+ using: "organization_id = current_user.organization_id"
1797
+ },
1798
+ {
1799
+ name: "sys_organization_self",
1800
+ object: "sys_organization",
1801
+ operation: "select",
1802
+ using: "id = current_user.organization_id"
1803
+ },
1804
+ {
1805
+ name: "sys_user_self",
1806
+ object: "sys_user",
1807
+ operation: "select",
1808
+ using: "id = current_user.id"
1809
+ }
1810
+ ]
1811
+ })
1812
+ ];
1553
1813
  var SysAuditLog = data.ObjectSchema.create({
1554
1814
  name: "sys_audit_log",
1555
1815
  label: "Audit Log",
@@ -3688,6 +3948,8 @@ var SETUP_APP = {
3688
3948
  { id: "nav_api_keys", type: "object", label: "API Keys", objectName: "sys_api_key", icon: "key" },
3689
3949
  { id: "nav_roles", type: "object", label: "Roles", objectName: "sys_role", icon: "shield-check" },
3690
3950
  { id: "nav_permission_sets", type: "object", label: "Permission Sets", objectName: "sys_permission_set", icon: "lock" },
3951
+ { id: "nav_user_permission_sets", type: "object", label: "User Permission Sets", objectName: "sys_user_permission_set", icon: "user-check" },
3952
+ { id: "nav_role_permission_sets", type: "object", label: "Role Permission Sets", objectName: "sys_role_permission_set", icon: "shield-plus" },
3691
3953
  { id: "nav_oauth_apps", type: "object", label: "OAuth Apps", objectName: "sys_oauth_application", icon: "app-window" },
3692
3954
  { id: "nav_jwks", type: "object", label: "Signing Keys", objectName: "sys_jwks", icon: "key-round" }
3693
3955
  ]
@@ -4194,16 +4456,19 @@ exports.SysProject = SysProject;
4194
4456
  exports.SysProjectCredential = SysProjectCredential;
4195
4457
  exports.SysProjectMember = SysProjectMember;
4196
4458
  exports.SysRole = SysRole;
4459
+ exports.SysRolePermissionSet = SysRolePermissionSet;
4197
4460
  exports.SysSession = SysSession;
4198
4461
  exports.SysTeam = SysTeam;
4199
4462
  exports.SysTeamMember = SysTeamMember;
4200
4463
  exports.SysTool = SysTool;
4201
4464
  exports.SysTwoFactor = SysTwoFactor;
4202
4465
  exports.SysUser = SysUser;
4466
+ exports.SysUserPermissionSet = SysUserPermissionSet;
4203
4467
  exports.SysUserPreference = SysUserPreference;
4204
4468
  exports.SysVerification = SysVerification;
4205
4469
  exports.SysView = SysView;
4206
4470
  exports.SystemOverviewDashboard = SystemOverviewDashboard;
4207
4471
  exports.UsersView = UsersView;
4472
+ exports.defaultPermissionSets = defaultPermissionSets;
4208
4473
  //# sourceMappingURL=index.js.map
4209
4474
  //# sourceMappingURL=index.js.map