@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.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ObjectSchema, Field } from '@objectstack/spec/data';
2
+ import { PermissionSetSchema } from '@objectstack/spec/security';
2
3
  import { Dashboard } from '@objectstack/spec/ui';
3
4
 
4
5
  // src/identity/sys-user.object.ts
@@ -8,6 +9,7 @@ var SysUser = ObjectSchema.create({
8
9
  pluralLabel: "Users",
9
10
  icon: "user",
10
11
  isSystem: true,
12
+ managedBy: "better-auth",
11
13
  description: "User accounts for authentication",
12
14
  displayNameField: "name",
13
15
  titleFormat: "{name}",
@@ -93,6 +95,7 @@ var SysSession = ObjectSchema.create({
93
95
  pluralLabel: "Sessions",
94
96
  icon: "key",
95
97
  isSystem: true,
98
+ managedBy: "better-auth",
96
99
  description: "Active user sessions",
97
100
  displayNameField: "user_id",
98
101
  titleFormat: "Session \u2014 {user_id}",
@@ -184,6 +187,7 @@ var SysAccount = ObjectSchema.create({
184
187
  pluralLabel: "Accounts",
185
188
  icon: "link",
186
189
  isSystem: true,
190
+ managedBy: "better-auth",
187
191
  description: "OAuth and authentication provider accounts",
188
192
  titleFormat: "{provider_id} - {account_id}",
189
193
  compactLayout: ["provider_id", "user_id", "account_id"],
@@ -267,6 +271,7 @@ var SysVerification = ObjectSchema.create({
267
271
  pluralLabel: "Verifications",
268
272
  icon: "shield-check",
269
273
  isSystem: true,
274
+ managedBy: "better-auth",
270
275
  description: "Email and phone verification tokens",
271
276
  titleFormat: "Verification for {identifier}",
272
277
  compactLayout: ["identifier", "expires_at", "created_at"],
@@ -321,6 +326,7 @@ var SysOrganization = ObjectSchema.create({
321
326
  pluralLabel: "Organizations",
322
327
  icon: "building-2",
323
328
  isSystem: true,
329
+ managedBy: "better-auth",
324
330
  description: "Organizations for multi-tenant grouping",
325
331
  displayNameField: "name",
326
332
  titleFormat: "{name}",
@@ -394,6 +400,7 @@ var SysMember = ObjectSchema.create({
394
400
  pluralLabel: "Members",
395
401
  icon: "user-check",
396
402
  isSystem: true,
403
+ managedBy: "better-auth",
397
404
  description: "Organization membership records",
398
405
  titleFormat: "{user_id} in {organization_id}",
399
406
  compactLayout: ["user_id", "organization_id", "role"],
@@ -442,6 +449,7 @@ var SysInvitation = ObjectSchema.create({
442
449
  pluralLabel: "Invitations",
443
450
  icon: "mail",
444
451
  isSystem: true,
452
+ managedBy: "better-auth",
445
453
  description: "Organization invitations for user onboarding",
446
454
  titleFormat: "Invitation to {organization_id}",
447
455
  compactLayout: ["email", "organization_id", "status"],
@@ -511,6 +519,7 @@ var SysTeam = ObjectSchema.create({
511
519
  pluralLabel: "Teams",
512
520
  icon: "users",
513
521
  isSystem: true,
522
+ managedBy: "better-auth",
514
523
  description: "Teams within organizations for fine-grained grouping",
515
524
  displayNameField: "name",
516
525
  titleFormat: "{name}",
@@ -569,6 +578,7 @@ var SysTeamMember = ObjectSchema.create({
569
578
  pluralLabel: "Team Members",
570
579
  icon: "user-plus",
571
580
  isSystem: true,
581
+ managedBy: "better-auth",
572
582
  description: "Team membership records linking users to teams",
573
583
  titleFormat: "{user_id} in {team_id}",
574
584
  compactLayout: ["user_id", "team_id", "created_at"],
@@ -611,6 +621,7 @@ var SysApiKey = ObjectSchema.create({
611
621
  pluralLabel: "API Keys",
612
622
  icon: "key-round",
613
623
  isSystem: true,
624
+ managedBy: "better-auth",
614
625
  description: "API keys for programmatic access",
615
626
  displayNameField: "name",
616
627
  titleFormat: "{name}",
@@ -713,6 +724,7 @@ var SysTwoFactor = ObjectSchema.create({
713
724
  pluralLabel: "Two Factor Credentials",
714
725
  icon: "smartphone",
715
726
  isSystem: true,
727
+ managedBy: "better-auth",
716
728
  description: "Two-factor authentication credentials",
717
729
  titleFormat: "Two-factor for {user_id}",
718
730
  compactLayout: ["user_id", "created_at"],
@@ -765,6 +777,7 @@ var SysDeviceCode = ObjectSchema.create({
765
777
  pluralLabel: "Device Codes",
766
778
  icon: "key-round",
767
779
  isSystem: true,
780
+ managedBy: "better-auth",
768
781
  description: "OAuth 2.0 Device Authorization Grant (RFC 8628) pending requests",
769
782
  titleFormat: "{user_code}",
770
783
  compactLayout: ["user_code", "status", "client_id", "expires_at"],
@@ -908,6 +921,7 @@ var SysOauthApplication = ObjectSchema.create({
908
921
  pluralLabel: "OAuth Applications",
909
922
  icon: "key-round",
910
923
  isSystem: true,
924
+ managedBy: "better-auth",
911
925
  description: "Registered OAuth/OIDC client applications",
912
926
  displayNameField: "name",
913
927
  titleFormat: "{name}",
@@ -1123,6 +1137,7 @@ var SysOauthAccessToken = ObjectSchema.create({
1123
1137
  pluralLabel: "OAuth Access Tokens",
1124
1138
  icon: "ticket",
1125
1139
  isSystem: true,
1140
+ managedBy: "better-auth",
1126
1141
  description: "Opaque OAuth access tokens issued to client applications",
1127
1142
  compactLayout: ["client_id", "user_id", "expires_at"],
1128
1143
  fields: {
@@ -1200,6 +1215,7 @@ var SysOauthRefreshToken = ObjectSchema.create({
1200
1215
  pluralLabel: "OAuth Refresh Tokens",
1201
1216
  icon: "refresh-cw",
1202
1217
  isSystem: true,
1218
+ managedBy: "better-auth",
1203
1219
  description: "Opaque OAuth refresh tokens (linked to a session)",
1204
1220
  compactLayout: ["client_id", "user_id", "expires_at"],
1205
1221
  fields: {
@@ -1281,6 +1297,7 @@ var SysOauthConsent = ObjectSchema.create({
1281
1297
  pluralLabel: "OAuth Consents",
1282
1298
  icon: "shield-check",
1283
1299
  isSystem: true,
1300
+ managedBy: "better-auth",
1284
1301
  description: "User consent records for OAuth client applications",
1285
1302
  compactLayout: ["client_id", "user_id", "scopes"],
1286
1303
  fields: {
@@ -1340,6 +1357,7 @@ var SysJwks = ObjectSchema.create({
1340
1357
  pluralLabel: "JWKS Keys",
1341
1358
  icon: "key",
1342
1359
  isSystem: true,
1360
+ managedBy: "better-auth",
1343
1361
  description: "Asymmetric key pairs used to sign and verify issued JWTs",
1344
1362
  compactLayout: ["id", "created_at", "expires_at"],
1345
1363
  fields: {
@@ -1548,6 +1566,248 @@ var SysPermissionSet = ObjectSchema.create({
1548
1566
  mru: true
1549
1567
  }
1550
1568
  });
1569
+ var SysUserPermissionSet = ObjectSchema.create({
1570
+ name: "sys_user_permission_set",
1571
+ label: "User Permission Set",
1572
+ pluralLabel: "User Permission Sets",
1573
+ icon: "user-check",
1574
+ isSystem: true,
1575
+ description: "Direct assignment of a permission set to a user (optionally scoped to an organization).",
1576
+ titleFormat: "{user_id} \u2192 {permission_set_id}",
1577
+ compactLayout: ["user_id", "permission_set_id", "organization_id"],
1578
+ fields: {
1579
+ id: Field.text({
1580
+ label: "Assignment ID",
1581
+ required: true,
1582
+ readonly: true,
1583
+ description: "UUID of the assignment."
1584
+ }),
1585
+ user_id: Field.lookup("sys_user", {
1586
+ label: "User",
1587
+ required: true,
1588
+ description: "Foreign key to sys_user."
1589
+ }),
1590
+ permission_set_id: Field.lookup("sys_permission_set", {
1591
+ label: "Permission Set",
1592
+ required: true,
1593
+ description: "Foreign key to sys_permission_set."
1594
+ }),
1595
+ organization_id: Field.lookup("sys_organization", {
1596
+ label: "Organization",
1597
+ required: false,
1598
+ description: "Optional organization scope. NULL = applies in every org context."
1599
+ }),
1600
+ granted_by: Field.lookup("sys_user", {
1601
+ label: "Granted By",
1602
+ required: false,
1603
+ description: "User who granted this permission set."
1604
+ }),
1605
+ created_at: Field.datetime({
1606
+ label: "Created At",
1607
+ defaultValue: "NOW()",
1608
+ readonly: true
1609
+ }),
1610
+ updated_at: Field.datetime({
1611
+ label: "Updated At",
1612
+ defaultValue: "NOW()",
1613
+ readonly: true
1614
+ })
1615
+ },
1616
+ indexes: [
1617
+ { fields: ["user_id", "permission_set_id", "organization_id"], unique: true },
1618
+ { fields: ["user_id"] },
1619
+ { fields: ["organization_id"] },
1620
+ { fields: ["permission_set_id"] }
1621
+ ],
1622
+ enable: {
1623
+ trackHistory: true,
1624
+ searchable: true,
1625
+ apiEnabled: true,
1626
+ apiMethods: ["get", "list", "create", "update", "delete"],
1627
+ trash: true,
1628
+ mru: false
1629
+ }
1630
+ });
1631
+ var SysRolePermissionSet = ObjectSchema.create({
1632
+ name: "sys_role_permission_set",
1633
+ label: "Role Permission Set",
1634
+ pluralLabel: "Role Permission Sets",
1635
+ icon: "shield-plus",
1636
+ isSystem: true,
1637
+ description: "Binds a permission set to a role.",
1638
+ titleFormat: "{role_id} \u2192 {permission_set_id}",
1639
+ compactLayout: ["role_id", "permission_set_id"],
1640
+ fields: {
1641
+ id: Field.text({
1642
+ label: "Binding ID",
1643
+ required: true,
1644
+ readonly: true,
1645
+ description: "UUID of the role-permission-set binding."
1646
+ }),
1647
+ role_id: Field.lookup("sys_role", {
1648
+ label: "Role",
1649
+ required: true,
1650
+ description: "Foreign key to sys_role."
1651
+ }),
1652
+ permission_set_id: Field.lookup("sys_permission_set", {
1653
+ label: "Permission Set",
1654
+ required: true,
1655
+ description: "Foreign key to sys_permission_set."
1656
+ }),
1657
+ created_at: Field.datetime({
1658
+ label: "Created At",
1659
+ defaultValue: "NOW()",
1660
+ readonly: true
1661
+ }),
1662
+ updated_at: Field.datetime({
1663
+ label: "Updated At",
1664
+ defaultValue: "NOW()",
1665
+ readonly: true
1666
+ })
1667
+ },
1668
+ indexes: [
1669
+ { fields: ["role_id", "permission_set_id"], unique: true },
1670
+ { fields: ["role_id"] },
1671
+ { fields: ["permission_set_id"] }
1672
+ ],
1673
+ enable: {
1674
+ trackHistory: true,
1675
+ searchable: true,
1676
+ apiEnabled: true,
1677
+ apiMethods: ["get", "list", "create", "update", "delete"],
1678
+ trash: true,
1679
+ mru: false
1680
+ }
1681
+ });
1682
+ var BETTER_AUTH_MANAGED_OBJECTS = [
1683
+ "sys_user",
1684
+ "sys_account",
1685
+ "sys_session",
1686
+ "sys_organization",
1687
+ "sys_member",
1688
+ "sys_invitation",
1689
+ "sys_team",
1690
+ "sys_team_member",
1691
+ "sys_api_key",
1692
+ "sys_two_factor",
1693
+ "sys_verification",
1694
+ "sys_jwks",
1695
+ "sys_device_code",
1696
+ "sys_oauth_application",
1697
+ "sys_oauth_access_token",
1698
+ "sys_oauth_refresh_token",
1699
+ "sys_oauth_consent"
1700
+ ];
1701
+ var denyWritesOnManagedObjects = () => Object.fromEntries(
1702
+ BETTER_AUTH_MANAGED_OBJECTS.map((name) => [
1703
+ name,
1704
+ { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }
1705
+ ])
1706
+ );
1707
+ var defaultPermissionSets = [
1708
+ PermissionSetSchema.parse({
1709
+ name: "admin_full_access",
1710
+ label: "Administrator \u2014 Full Access",
1711
+ isProfile: true,
1712
+ objects: {
1713
+ "*": {
1714
+ allowRead: true,
1715
+ allowCreate: true,
1716
+ allowEdit: true,
1717
+ allowDelete: true,
1718
+ viewAllRecords: true,
1719
+ modifyAllRecords: true
1720
+ }
1721
+ },
1722
+ systemPermissions: ["manage_users", "manage_metadata", "setup.access"]
1723
+ }),
1724
+ PermissionSetSchema.parse({
1725
+ name: "member_default",
1726
+ label: "Member \u2014 Standard Access",
1727
+ isProfile: true,
1728
+ objects: {
1729
+ "*": {
1730
+ allowRead: true,
1731
+ allowCreate: true,
1732
+ allowEdit: true,
1733
+ allowDelete: true
1734
+ },
1735
+ // Identity tables are managed by better-auth — no direct writes.
1736
+ ...denyWritesOnManagedObjects()
1737
+ },
1738
+ rowLevelSecurity: [
1739
+ {
1740
+ name: "tenant_isolation",
1741
+ object: "*",
1742
+ operation: "all",
1743
+ using: "organization_id = current_user.organization_id"
1744
+ },
1745
+ {
1746
+ name: "owner_only_writes",
1747
+ object: "*",
1748
+ operation: "update",
1749
+ using: "owner_id = current_user.id"
1750
+ },
1751
+ {
1752
+ name: "owner_only_deletes",
1753
+ object: "*",
1754
+ operation: "delete",
1755
+ using: "owner_id = current_user.id"
1756
+ },
1757
+ // ── better-auth system tables that lack `organization_id` and would
1758
+ // otherwise be left unprotected by the wildcard rule above. ────
1759
+ {
1760
+ name: "sys_organization_self",
1761
+ object: "sys_organization",
1762
+ operation: "all",
1763
+ using: "id = current_user.organization_id"
1764
+ },
1765
+ {
1766
+ name: "sys_user_self",
1767
+ object: "sys_user",
1768
+ operation: "select",
1769
+ using: "id = current_user.id"
1770
+ }
1771
+ ]
1772
+ }),
1773
+ PermissionSetSchema.parse({
1774
+ name: "viewer_readonly",
1775
+ label: "Viewer \u2014 Read-Only",
1776
+ isProfile: true,
1777
+ objects: {
1778
+ "*": {
1779
+ allowRead: true,
1780
+ allowCreate: false,
1781
+ allowEdit: false,
1782
+ allowDelete: false
1783
+ },
1784
+ // Belt-and-suspenders: explicit deny on managed objects even though
1785
+ // the wildcard already denies — keeps the policy readable when
1786
+ // future relaxations might widen the wildcard.
1787
+ ...denyWritesOnManagedObjects()
1788
+ },
1789
+ rowLevelSecurity: [
1790
+ {
1791
+ name: "tenant_isolation",
1792
+ object: "*",
1793
+ operation: "select",
1794
+ using: "organization_id = current_user.organization_id"
1795
+ },
1796
+ {
1797
+ name: "sys_organization_self",
1798
+ object: "sys_organization",
1799
+ operation: "select",
1800
+ using: "id = current_user.organization_id"
1801
+ },
1802
+ {
1803
+ name: "sys_user_self",
1804
+ object: "sys_user",
1805
+ operation: "select",
1806
+ using: "id = current_user.id"
1807
+ }
1808
+ ]
1809
+ })
1810
+ ];
1551
1811
  var SysAuditLog = ObjectSchema.create({
1552
1812
  name: "sys_audit_log",
1553
1813
  label: "Audit Log",
@@ -3686,6 +3946,8 @@ var SETUP_APP = {
3686
3946
  { id: "nav_api_keys", type: "object", label: "API Keys", objectName: "sys_api_key", icon: "key" },
3687
3947
  { id: "nav_roles", type: "object", label: "Roles", objectName: "sys_role", icon: "shield-check" },
3688
3948
  { id: "nav_permission_sets", type: "object", label: "Permission Sets", objectName: "sys_permission_set", icon: "lock" },
3949
+ { id: "nav_user_permission_sets", type: "object", label: "User Permission Sets", objectName: "sys_user_permission_set", icon: "user-check" },
3950
+ { id: "nav_role_permission_sets", type: "object", label: "Role Permission Sets", objectName: "sys_role_permission_set", icon: "shield-plus" },
3689
3951
  { id: "nav_oauth_apps", type: "object", label: "OAuth Apps", objectName: "sys_oauth_application", icon: "app-window" },
3690
3952
  { id: "nav_jwks", type: "object", label: "Signing Keys", objectName: "sys_jwks", icon: "key-round" }
3691
3953
  ]
@@ -4155,6 +4417,6 @@ var SecurityOverviewDashboard = Dashboard.create({
4155
4417
  ]
4156
4418
  });
4157
4419
 
4158
- export { AuditLogsView, OrganizationsView, PackageInstallationsView, RolesView, SETUP_APP, SecurityOverviewDashboard, SessionsView, SysAccount, SysActivity, SysAgent, SysApiKey, SysApp, SysAuditLog, SysComment, SysDeviceCode, SysFlow, SysInvitation, SysJwks, SysMember, SysMetadataObject as SysMetadata, SysMetadataHistoryObject, SysMetadataObject, SysOauthAccessToken, SysOauthApplication, SysOauthConsent, SysOauthRefreshToken, SysObject, SysOrganization, SysPackage, SysPackageInstallation, SysPackageVersion, SysPermissionSet, SysPresence, SysProject, SysProjectCredential, SysProjectMember, SysRole, SysSession, SysTeam, SysTeamMember, SysTool, SysTwoFactor, SysUser, SysUserPreference, SysVerification, SysView, SystemOverviewDashboard, UsersView };
4420
+ export { AuditLogsView, OrganizationsView, PackageInstallationsView, RolesView, SETUP_APP, SecurityOverviewDashboard, SessionsView, SysAccount, SysActivity, SysAgent, SysApiKey, SysApp, SysAuditLog, SysComment, SysDeviceCode, SysFlow, SysInvitation, SysJwks, SysMember, SysMetadataObject as SysMetadata, SysMetadataHistoryObject, SysMetadataObject, SysOauthAccessToken, SysOauthApplication, SysOauthConsent, SysOauthRefreshToken, SysObject, SysOrganization, SysPackage, SysPackageInstallation, SysPackageVersion, SysPermissionSet, SysPresence, SysProject, SysProjectCredential, SysProjectMember, SysRole, SysRolePermissionSet, SysSession, SysTeam, SysTeamMember, SysTool, SysTwoFactor, SysUser, SysUserPermissionSet, SysUserPreference, SysVerification, SysView, SystemOverviewDashboard, UsersView, defaultPermissionSets };
4159
4421
  //# sourceMappingURL=index.mjs.map
4160
4422
  //# sourceMappingURL=index.mjs.map