@objectstack/platform-objects 11.0.0 → 11.1.0

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.
@@ -420,6 +420,25 @@ var SysUser = ObjectSchema.create({
420
420
  group: "Admin",
421
421
  description: "When set and in the future, sign-in is rejected (brute-force lockout). Auto-clears past this time; an admin can clear it early via Unlock."
422
422
  }),
423
+ // ADR-0069 D1 — last password change; drives password-expiry enforcement.
424
+ // Stamped on sign-up / change-password / reset-password. Null = never
425
+ // expires (until the user next changes their password).
426
+ password_changed_at: Field.datetime({
427
+ label: "Password Changed At",
428
+ required: false,
429
+ readonly: true,
430
+ group: "Admin",
431
+ description: "Timestamp of the last password change. Backs password_expiry_days; system-managed."
432
+ }),
433
+ // ADR-0069 D3 — when enforced MFA first applied to this user; starts the
434
+ // grace clock. Stamped lazily at session validation; system-managed.
435
+ mfa_required_at: Field.datetime({
436
+ label: "MFA Required At",
437
+ required: false,
438
+ readonly: true,
439
+ group: "Admin",
440
+ description: "When enforced MFA first applied to this user (grace-period clock). Backs mfa_required; system-managed."
441
+ }),
423
442
  ai_access: Field.boolean({
424
443
  label: "AI Access",
425
444
  defaultValue: false,
@@ -592,6 +611,29 @@ var SysSession = ObjectSchema.create({
592
611
  required: true,
593
612
  group: "Session"
594
613
  }),
614
+ // ── ADR-0069 D4 — session controls (idle / absolute / revoke) ──
615
+ last_activity_at: Field.datetime({
616
+ label: "Last Activity At",
617
+ required: false,
618
+ readonly: true,
619
+ group: "Session",
620
+ description: "Timestamp of the last request on this session; drives idle-timeout. System-managed."
621
+ }),
622
+ revoked_at: Field.datetime({
623
+ label: "Revoked At",
624
+ required: false,
625
+ readonly: true,
626
+ group: "Session",
627
+ description: "When set, this session was revoked (idle / absolute-max / concurrent-cap / admin). System-managed."
628
+ }),
629
+ revoke_reason: Field.text({
630
+ label: "Revoke Reason",
631
+ required: false,
632
+ maxLength: 64,
633
+ readonly: true,
634
+ group: "Session",
635
+ description: "Why the session was revoked (idle_timeout, absolute_max, concurrent_cap, \u2026)."
636
+ }),
595
637
  // ── Active context (multi-org/team) ──────────────────────────
596
638
  active_organization_id: Field.lookup("sys_organization", {
597
639
  label: "Active Organization",
@@ -1112,6 +1154,17 @@ var SysOrganization = ObjectSchema.create({
1112
1154
  description: "JSON-serialized organization metadata",
1113
1155
  group: "Configuration"
1114
1156
  }),
1157
+ // ADR-0069 D3 — per-org MFA tightening above the global floor. When true,
1158
+ // members of this org must enrol TOTP to access data (enforced at the
1159
+ // session-validation gate). An org can only tighten, never loosen, the
1160
+ // global `mfa_required` setting.
1161
+ require_mfa: Field.boolean({
1162
+ label: "Require Multi-Factor Auth",
1163
+ required: false,
1164
+ defaultValue: false,
1165
+ group: "Configuration",
1166
+ description: "When true, every member of this organization must enroll an authenticator app to access data."
1167
+ }),
1115
1168
  // ── System ───────────────────────────────────────────────────
1116
1169
  id: Field.text({
1117
1170
  label: "Organization ID",
@@ -3296,6 +3349,22 @@ var SysSsoProvider = ObjectSchema.create({
3296
3349
  icon: "shield-check",
3297
3350
  isSystem: true,
3298
3351
  managedBy: "better-auth",
3352
+ // ADR-0024 — env-global, ADMIN-ONLY identity config. Two orthogonal controls:
3353
+ // • `tenancy.enabled: false` — the env IS the tenant; providers are env-wide,
3354
+ // not org-partitioned. Opting out of multi-tenancy lets a platform admin's
3355
+ // `viewAllRecords` superuser bypass see every provider (without it, the
3356
+ // `member_default` wildcard `tenant_isolation` RLS denies every row, since
3357
+ // better-auth writes via its adapter with no tenantId → `organization_id`
3358
+ // is never stamped).
3359
+ // • `requiredPermissions: ['manage_platform_settings']` — object-level
3360
+ // capability gate (ADR-0066 D3) so ordinary members are denied entirely
3361
+ // (without it, tenancy-disabled + `member_default`'s `'*': allowRead` would
3362
+ // leak providers to every authenticated user).
3363
+ // Together: admins see all env providers; non-admins get 403. better-auth's
3364
+ // own endpoints already read via a system context. (Env-only object — no
3365
+ // control-plane cross-tenant risk.)
3366
+ tenancy: { enabled: false, strategy: "shared" },
3367
+ requiredPermissions: ["manage_platform_settings"],
3299
3368
  // ADR-0010 §3.7 — managed by better-auth; tenants may not edit schema.
3300
3369
  protection: {
3301
3370
  lock: "full",
@@ -3319,14 +3388,101 @@ var SysSsoProvider = ObjectSchema.create({
3319
3388
  locations: ["list_toolbar"],
3320
3389
  type: "api",
3321
3390
  method: "POST",
3322
- target: "/api/v1/auth/sso/register",
3391
+ // Routed through the env-side bridge (plugin-auth `auth-plugin.ts`), which
3392
+ // reshapes these FLAT form fields into the nested `oidcConfig` body that
3393
+ // `@better-auth/sso`'s /sso/register requires, then re-dispatches to it
3394
+ // (so the admin gate + discovery hydration run). Posting straight to
3395
+ // /sso/register would drop clientId/clientSecret (top-level → Zod-stripped)
3396
+ // and persist an unusable `oidc_config = null` provider.
3397
+ target: "/api/v1/auth/admin/sso/register",
3323
3398
  refreshAfter: true,
3324
3399
  params: [
3325
3400
  { name: "providerId", label: "Provider ID", type: "text", required: true, helpText: 'Stable identifier, e.g. "okta" or "acme-entra".' },
3326
- { name: "issuer", label: "Issuer URL", type: "text", required: true, helpText: "IdP issuer / discovery base, e.g. https://acme.okta.com." },
3327
- { name: "domain", label: "Email Domain", type: "text", required: true, helpText: "Users with this email domain are routed to this IdP." },
3328
- { name: "clientId", label: "Client ID", type: "text", required: true },
3329
- { name: "clientSecret", label: "Client Secret", type: "text", required: true }
3401
+ { name: "issuer", label: "Issuer URL", type: "text", required: true, helpText: "IdP issuer, e.g. https://acme.okta.com. Discovery is fetched from here unless an explicit URL is given below." },
3402
+ { name: "domain", label: "Email Domain", type: "text", required: true, helpText: "Users with this email domain are routed to this IdP, e.g. acme.com." },
3403
+ { name: "clientId", label: "Client ID", type: "text", required: true, helpText: "OAuth client ID issued by the IdP for this environment." },
3404
+ { name: "clientSecret", label: "Client Secret", type: "text", required: true, helpText: "OAuth client secret (stored encrypted by better-auth)." },
3405
+ { name: "discoveryEndpoint", label: "Discovery URL", type: "text", required: false, helpText: "Optional. OIDC discovery document URL. Leave blank to derive `<issuer>/.well-known/openid-configuration`." },
3406
+ { name: "scopes", label: "Scopes", type: "text", required: false, placeholder: "openid email profile", helpText: 'Optional. Space- or comma-separated OAuth scopes. Defaults to "openid email profile".' },
3407
+ { name: "mapId", label: "Map: User ID claim", type: "text", required: false, placeholder: "sub", helpText: 'Optional. ID-token claim mapped to the user ID. Defaults to "sub".' },
3408
+ { name: "mapEmail", label: "Map: Email claim", type: "text", required: false, placeholder: "email", helpText: 'Optional. Claim mapped to email. Defaults to "email".' },
3409
+ { name: "mapName", label: "Map: Name claim", type: "text", required: false, placeholder: "name", helpText: 'Optional. Claim mapped to display name. Defaults to "name".' }
3410
+ ]
3411
+ },
3412
+ {
3413
+ name: "register_saml_provider",
3414
+ label: "Register SAML Provider",
3415
+ icon: "shield",
3416
+ variant: "primary",
3417
+ mode: "create",
3418
+ locations: ["list_toolbar"],
3419
+ type: "api",
3420
+ method: "POST",
3421
+ // SAML 2.0 via @better-auth/sso (samlify-backed). Routed through the
3422
+ // env-side bridge (plugin-auth `auth-plugin.ts` → register-saml), which
3423
+ // reshapes these FLAT IdP fields into the nested `samlConfig` body that
3424
+ // @better-auth/sso's /sso/register requires (entryPoint/cert/callbackUrl/
3425
+ // spMetadata/identifierFormat), derives the per-provider ACS URL, and
3426
+ // re-dispatches to /sso/register (admin gate runs). The response returns
3427
+ // the SP ACS + metadata URLs to configure on the IdP.
3428
+ target: "/api/v1/auth/admin/sso/register-saml",
3429
+ refreshAfter: true,
3430
+ params: [
3431
+ { name: "providerId", label: "Provider ID", type: "text", required: true, helpText: 'Stable identifier, e.g. "acme-saml".' },
3432
+ { name: "issuer", label: "IdP Entity ID", type: "text", required: true, helpText: "The IdP\u2019s SAML EntityID (issuer), e.g. https://saml.acme.com/entityid." },
3433
+ { name: "domain", label: "Email Domain", type: "text", required: true, helpText: "Users with this email domain are routed to this IdP, e.g. acme.com." },
3434
+ { name: "entryPoint", label: "IdP SSO URL", type: "text", required: true, helpText: "The IdP\u2019s SAML single sign-on (redirect) endpoint that receives the SAMLRequest." },
3435
+ { name: "cert", label: "IdP Signing Certificate", type: "textarea", required: true, helpText: "The IdP\u2019s X.509 signing certificate (PEM body). Used to verify assertion signatures." },
3436
+ { name: "identifierFormat", label: "NameID Format", type: "text", required: false, placeholder: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", helpText: "Optional. Requested SAML NameID format. Defaults to the IdP\u2019s configured format." }
3437
+ ]
3438
+ },
3439
+ {
3440
+ name: "request_domain_verification",
3441
+ label: "Request Domain Verification",
3442
+ icon: "globe",
3443
+ variant: "secondary",
3444
+ locations: ["list_item", "record_header"],
3445
+ type: "api",
3446
+ method: "POST",
3447
+ // ADR-0024 ② (opt-in OS_SSO_DOMAIN_VERIFICATION). Asks @better-auth/sso
3448
+ // for a one-time DNS-TXT challenge and reveals the ready-to-paste record
3449
+ // ONCE via `resultDialog`. Routed through the env bridge (plugin-auth /
3450
+ // cloud AuthProxyPlugin) which reshapes the `{domainVerificationToken}`
3451
+ // response into the `{ data: { dnsRecordName, dnsRecordValue } }` envelope
3452
+ // the dialog reads. When the feature is OFF the bridge returns a clear
3453
+ // "not enabled for this environment" error instead of a bare 404.
3454
+ target: "/api/v1/auth/admin/sso/request-domain-verification",
3455
+ params: [
3456
+ { name: "providerId", field: "provider_id", defaultFromRow: true, required: true },
3457
+ { name: "domain", field: "domain", defaultFromRow: true, required: false }
3458
+ ],
3459
+ resultDialog: {
3460
+ title: "Verify your domain",
3461
+ description: "Add the DNS TXT record below at your domain\u2019s DNS provider, then run \u201CVerify Domain\u201D. The token is shown once.",
3462
+ acknowledge: "Done",
3463
+ fields: [
3464
+ { path: "data.dnsRecordType", label: "Record type", format: "text" },
3465
+ { path: "data.dnsRecordName", label: "Name / Host", format: "secret" },
3466
+ { path: "data.dnsRecordValue", label: "Value", format: "secret" }
3467
+ ]
3468
+ }
3469
+ },
3470
+ {
3471
+ name: "verify_domain",
3472
+ label: "Verify Domain",
3473
+ icon: "shield-check",
3474
+ variant: "secondary",
3475
+ locations: ["list_item", "record_header"],
3476
+ type: "api",
3477
+ method: "POST",
3478
+ // ADR-0024 ②. Re-checks the DNS-TXT record and flips `domain_verified`
3479
+ // on success. Routed through the env bridge, which maps @better-auth/sso's
3480
+ // empty 204 / 502 into a clear success/error toast.
3481
+ target: "/api/v1/auth/admin/sso/verify-domain",
3482
+ successMessage: "Domain ownership verified",
3483
+ refreshAfter: true,
3484
+ params: [
3485
+ { name: "providerId", field: "provider_id", defaultFromRow: true, required: true }
3330
3486
  ]
3331
3487
  },
3332
3488
  {
@@ -3353,9 +3509,17 @@ var SysSsoProvider = ObjectSchema.create({
3353
3509
  name: "all",
3354
3510
  label: "All",
3355
3511
  data: { provider: "object", object: "sys_sso_provider" },
3356
- columns: ["provider_id", "issuer", "domain", "created_at"],
3512
+ columns: ["provider_id", "issuer", "domain", "domain_verified", "created_at"],
3357
3513
  sort: [{ field: "provider_id", order: "asc" }],
3358
- pagination: { pageSize: 50 }
3514
+ pagination: { pageSize: 50 },
3515
+ // Per-object empty state — the shared identity-object copy ("created
3516
+ // automatically … cannot be added here") is wrong for this object, which
3517
+ // HAS a "Register SSO Provider" action. Point admins at it instead.
3518
+ emptyState: {
3519
+ title: "No SSO providers yet",
3520
+ message: "Register your organization\u2019s external IdP \u2014 OIDC (Okta, Entra, Auth0, \u2026) with \u201CRegister SSO Provider\u201D, or SAML 2.0 with \u201CRegister SAML Provider\u201D. Members whose email domain matches can then sign in through it.",
3521
+ icon: "log-in"
3522
+ }
3359
3523
  }
3360
3524
  },
3361
3525
  fields: {
@@ -3382,6 +3546,13 @@ var SysSsoProvider = ObjectSchema.create({
3382
3546
  description: "Email domain routed to this IdP (e.g. acme.com)",
3383
3547
  group: "Identity"
3384
3548
  }),
3549
+ domain_verified: Field.boolean({
3550
+ label: "Domain Verified",
3551
+ defaultValue: false,
3552
+ readonly: true,
3553
+ description: "Whether DNS ownership of the email domain has been proven (ADR-0024 \u2461). Set by \u201CVerify Domain\u201D after the DNS TXT record resolves. Managed by better-auth \u2014 not directly editable. Only enforced when domain verification is enabled for the environment.",
3554
+ group: "Identity"
3555
+ }),
3385
3556
  oidc_config: Field.textarea({
3386
3557
  label: "OIDC Config",
3387
3558
  required: false,