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