@happyvertical/smrt-users 0.37.0 → 0.37.2

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.
@@ -1,11 +1,44 @@
1
- import { ObjectRegistry, field, smrt, SmrtObject, SmrtCollection, foreignKey, crossPackageRef } from "@happyvertical/smrt-core";
1
+ import { ObjectRegistry, crossPackageRef, field, smrt, SmrtObject, SmrtCollection, foreignKey } from "@happyvertical/smrt-core";
2
2
  import { getPackageConfig } from "@happyvertical/smrt-config";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { randomBytes, createHash } from "node:crypto";
5
- import { MembershipStatus, OverrideEffect, SessionStatus, TenantStatus, TenantPermissionEffect, UserStatus } from "@happyvertical/smrt-types";
5
+ import { UserStatus, MembershipStatus, OverrideEffect, SessionStatus, TenantStatus, TenantPermissionEffect } from "@happyvertical/smrt-types";
6
6
  ObjectRegistry.registerPackageManifest(
7
7
  new URL("./manifest.json", import.meta.url)
8
8
  );
9
+ const DEFAULT_ROLE_SLUGS = {
10
+ OWNER: "owner",
11
+ ADMIN: "admin",
12
+ MEMBER: "member",
13
+ VIEWER: "viewer"
14
+ };
15
+ const DEFAULT_ROLES = [
16
+ {
17
+ slug: DEFAULT_ROLE_SLUGS.OWNER,
18
+ name: "Owner",
19
+ description: "Full access to all resources"
20
+ },
21
+ {
22
+ slug: DEFAULT_ROLE_SLUGS.ADMIN,
23
+ name: "Administrator",
24
+ description: "Manage users and settings"
25
+ },
26
+ {
27
+ slug: DEFAULT_ROLE_SLUGS.MEMBER,
28
+ name: "Member",
29
+ description: "Standard access"
30
+ },
31
+ {
32
+ slug: DEFAULT_ROLE_SLUGS.VIEWER,
33
+ name: "Viewer",
34
+ description: "Read-only access"
35
+ }
36
+ ];
37
+ const DEFAULT_TENANT_POLICY = {
38
+ mode: "flexible",
39
+ maxTenants: 0,
40
+ defaultName: "Default Workspace"
41
+ };
9
42
  var __defProp$a = Object.defineProperty;
10
43
  var __getOwnPropDesc$b = Object.getOwnPropertyDescriptor;
11
44
  var __decorateClass$b = (decorators, target, key, kind) => {
@@ -16,6 +49,91 @@ var __decorateClass$b = (decorators, target, key, kind) => {
16
49
  if (kind && result) __defProp$a(target, key, result);
17
50
  return result;
18
51
  };
52
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
53
+ function isValidEmail(email) {
54
+ if (!email || typeof email !== "string") return false;
55
+ return EMAIL_REGEX.test(email.trim());
56
+ }
57
+ function normalizeEmail(email) {
58
+ if (!email || typeof email !== "string") return "";
59
+ return email.trim().toLowerCase();
60
+ }
61
+ let User = class extends SmrtObject {
62
+ profileId = "";
63
+ /**
64
+ * User's email address (unique, used for lookup)
65
+ */
66
+ email = "";
67
+ status = UserStatus.ACTIVE;
68
+ /**
69
+ * Last login timestamp
70
+ */
71
+ lastLoginAt = null;
72
+ constructor(options = {}) {
73
+ super(options);
74
+ if (options.profileId !== void 0) this.profileId = options.profileId;
75
+ if (options.email !== void 0) this.email = normalizeEmail(options.email);
76
+ if (options.status !== void 0) this.status = options.status;
77
+ if (options.lastLoginAt !== void 0)
78
+ this.lastLoginAt = options.lastLoginAt;
79
+ }
80
+ /**
81
+ * Validate the user's email format.
82
+ * @returns true if email is valid
83
+ */
84
+ hasValidEmail() {
85
+ return isValidEmail(this.email);
86
+ }
87
+ /**
88
+ * Check if user is active
89
+ */
90
+ isActive() {
91
+ return this.status === UserStatus.ACTIVE;
92
+ }
93
+ /**
94
+ * Check if user is suspended
95
+ */
96
+ isSuspended() {
97
+ return this.status === UserStatus.SUSPENDED;
98
+ }
99
+ /**
100
+ * Check if user is pending verification
101
+ */
102
+ isPending() {
103
+ return this.status === UserStatus.PENDING;
104
+ }
105
+ /**
106
+ * Record a login event
107
+ */
108
+ recordLogin() {
109
+ this.lastLoginAt = /* @__PURE__ */ new Date();
110
+ }
111
+ };
112
+ __decorateClass$b([
113
+ crossPackageRef("@happyvertical/smrt-profiles:Profile")
114
+ ], User.prototype, "profileId", 2);
115
+ __decorateClass$b([
116
+ field({ type: "text" })
117
+ ], User.prototype, "status", 2);
118
+ User = __decorateClass$b([
119
+ smrt({
120
+ // #1400: read-only generated surface — User is auth identity (email/status/
121
+ // profileId), provisioned via OIDC/magic-link, not arbitrary authed POST/PUT.
122
+ api: { include: ["list", "get"] },
123
+ mcp: { include: ["list", "get"] },
124
+ cli: true
125
+ })
126
+ ], User);
127
+ var __defProp$9 = Object.defineProperty;
128
+ var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
129
+ var __decorateClass$a = (decorators, target, key, kind) => {
130
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
131
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
132
+ if (decorator = decorators[i])
133
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
134
+ if (kind && result) __defProp$9(target, key, result);
135
+ return result;
136
+ };
19
137
  let UsersCliAuthRequest = class extends SmrtObject {
20
138
  userCode = "";
21
139
  deviceCodeHash = "";
@@ -26,31 +144,31 @@ let UsersCliAuthRequest = class extends SmrtObject {
26
144
  expiresAt = /* @__PURE__ */ new Date();
27
145
  approvedAt = null;
28
146
  };
29
- __decorateClass$b([
147
+ __decorateClass$a([
30
148
  field({ type: "text" })
31
149
  ], UsersCliAuthRequest.prototype, "userCode", 2);
32
- __decorateClass$b([
150
+ __decorateClass$a([
33
151
  field({ type: "text" })
34
152
  ], UsersCliAuthRequest.prototype, "deviceCodeHash", 2);
35
- __decorateClass$b([
153
+ __decorateClass$a([
36
154
  field({ type: "text" })
37
155
  ], UsersCliAuthRequest.prototype, "status", 2);
38
- __decorateClass$b([
156
+ __decorateClass$a([
39
157
  field({ type: "text" })
40
158
  ], UsersCliAuthRequest.prototype, "userId", 2);
41
- __decorateClass$b([
159
+ __decorateClass$a([
42
160
  field({ type: "text" })
43
161
  ], UsersCliAuthRequest.prototype, "tenantId", 2);
44
- __decorateClass$b([
162
+ __decorateClass$a([
45
163
  field({ type: "text" })
46
164
  ], UsersCliAuthRequest.prototype, "sessionId", 2);
47
- __decorateClass$b([
165
+ __decorateClass$a([
48
166
  field({ type: "datetime" })
49
167
  ], UsersCliAuthRequest.prototype, "expiresAt", 2);
50
- __decorateClass$b([
168
+ __decorateClass$a([
51
169
  field({ type: "datetime", nullable: true })
52
170
  ], UsersCliAuthRequest.prototype, "approvedAt", 2);
53
- UsersCliAuthRequest = __decorateClass$b([
171
+ UsersCliAuthRequest = __decorateClass$a([
54
172
  smrt({
55
173
  tableName: "users_cli_auth_requests",
56
174
  api: { include: [] },
@@ -98,14 +216,14 @@ class UsersCliAuthRequestCollection extends SmrtCollection {
98
216
  return count;
99
217
  }
100
218
  }
101
- var __defProp$9 = Object.defineProperty;
102
- var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
103
- var __decorateClass$a = (decorators, target, key, kind) => {
104
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
219
+ var __defProp$8 = Object.defineProperty;
220
+ var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
221
+ var __decorateClass$9 = (decorators, target, key, kind) => {
222
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
105
223
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
106
224
  if (decorator = decorators[i])
107
225
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
108
- if (kind && result) __defProp$9(target, key, result);
226
+ if (kind && result) __defProp$8(target, key, result);
109
227
  return result;
110
228
  };
111
229
  let Group = class extends SmrtObject {
@@ -126,10 +244,10 @@ let Group = class extends SmrtObject {
126
244
  this.description = options.description;
127
245
  }
128
246
  };
129
- __decorateClass$a([
247
+ __decorateClass$9([
130
248
  foreignKey("Tenant", { required: true })
131
249
  ], Group.prototype, "tenantId", 2);
132
- Group = __decorateClass$a([
250
+ Group = __decorateClass$9([
133
251
  smrt({
134
252
  // #1400: read-only generated surface — RBAC/identity writes go through
135
253
  // permission-gated services, not auth-only generated CRUD.
@@ -160,14 +278,14 @@ class GroupCollection extends SmrtCollection {
160
278
  return results.length > 0 ? results[0] : null;
161
279
  }
162
280
  }
163
- var __defProp$8 = Object.defineProperty;
164
- var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
165
- var __decorateClass$9 = (decorators, target, key, kind) => {
166
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
281
+ var __defProp$7 = Object.defineProperty;
282
+ var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
283
+ var __decorateClass$8 = (decorators, target, key, kind) => {
284
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
167
285
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
168
286
  if (decorator = decorators[i])
169
287
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
170
- if (kind && result) __defProp$8(target, key, result);
288
+ if (kind && result) __defProp$7(target, key, result);
171
289
  return result;
172
290
  };
173
291
  let GroupMember = class extends SmrtObject {
@@ -179,13 +297,13 @@ let GroupMember = class extends SmrtObject {
179
297
  if (options.userId !== void 0) this.userId = options.userId;
180
298
  }
181
299
  };
182
- __decorateClass$9([
300
+ __decorateClass$8([
183
301
  foreignKey("Group", { required: true })
184
302
  ], GroupMember.prototype, "groupId", 2);
185
- __decorateClass$9([
303
+ __decorateClass$8([
186
304
  foreignKey("User", { required: true })
187
305
  ], GroupMember.prototype, "userId", 2);
188
- GroupMember = __decorateClass$9([
306
+ GroupMember = __decorateClass$8([
189
307
  smrt({
190
308
  // #1400: read-only generated REST + MCP surface — RBAC/identity writes go
191
309
  // through permission-gated services, not auth-only generated CRUD. mcp must
@@ -301,14 +419,14 @@ class GroupMemberCollection extends SmrtCollection {
301
419
  return members.map((m) => m.userId);
302
420
  }
303
421
  }
304
- var __defProp$7 = Object.defineProperty;
305
- var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
306
- var __decorateClass$8 = (decorators, target, key, kind) => {
307
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
422
+ var __defProp$6 = Object.defineProperty;
423
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
424
+ var __decorateClass$7 = (decorators, target, key, kind) => {
425
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
308
426
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
309
427
  if (decorator = decorators[i])
310
428
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
311
- if (kind && result) __defProp$7(target, key, result);
429
+ if (kind && result) __defProp$6(target, key, result);
312
430
  return result;
313
431
  };
314
432
  let GroupRole = class extends SmrtObject {
@@ -320,13 +438,13 @@ let GroupRole = class extends SmrtObject {
320
438
  if (options.roleId !== void 0) this.roleId = options.roleId;
321
439
  }
322
440
  };
323
- __decorateClass$8([
441
+ __decorateClass$7([
324
442
  foreignKey("Group", { required: true })
325
443
  ], GroupRole.prototype, "groupId", 2);
326
- __decorateClass$8([
444
+ __decorateClass$7([
327
445
  foreignKey("Role", { required: true })
328
446
  ], GroupRole.prototype, "roleId", 2);
329
- GroupRole = __decorateClass$8([
447
+ GroupRole = __decorateClass$7([
330
448
  smrt({
331
449
  // #1400: read-only generated REST + MCP surface — RBAC/identity writes go
332
450
  // through permission-gated services, not auth-only generated CRUD. mcp must
@@ -401,47 +519,14 @@ class GroupRoleCollection extends SmrtCollection {
401
519
  return groupRoles.map((gr) => gr.roleId);
402
520
  }
403
521
  }
404
- const DEFAULT_ROLE_SLUGS = {
405
- OWNER: "owner",
406
- ADMIN: "admin",
407
- MEMBER: "member",
408
- VIEWER: "viewer"
409
- };
410
- const DEFAULT_ROLES = [
411
- {
412
- slug: DEFAULT_ROLE_SLUGS.OWNER,
413
- name: "Owner",
414
- description: "Full access to all resources"
415
- },
416
- {
417
- slug: DEFAULT_ROLE_SLUGS.ADMIN,
418
- name: "Administrator",
419
- description: "Manage users and settings"
420
- },
421
- {
422
- slug: DEFAULT_ROLE_SLUGS.MEMBER,
423
- name: "Member",
424
- description: "Standard access"
425
- },
426
- {
427
- slug: DEFAULT_ROLE_SLUGS.VIEWER,
428
- name: "Viewer",
429
- description: "Read-only access"
430
- }
431
- ];
432
- const DEFAULT_TENANT_POLICY = {
433
- mode: "flexible",
434
- maxTenants: 0,
435
- defaultName: "Default Workspace"
436
- };
437
- var __defProp$6 = Object.defineProperty;
438
- var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
439
- var __decorateClass$7 = (decorators, target, key, kind) => {
440
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
522
+ var __defProp$5 = Object.defineProperty;
523
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
524
+ var __decorateClass$6 = (decorators, target, key, kind) => {
525
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
441
526
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
442
527
  if (decorator = decorators[i])
443
528
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
444
- if (kind && result) __defProp$6(target, key, result);
529
+ if (kind && result) __defProp$5(target, key, result);
445
530
  return result;
446
531
  };
447
532
  let Membership = class extends SmrtObject {
@@ -469,19 +554,19 @@ let Membership = class extends SmrtObject {
469
554
  return this.status === MembershipStatus.PENDING;
470
555
  }
471
556
  };
472
- __decorateClass$7([
557
+ __decorateClass$6([
473
558
  foreignKey("User", { required: true })
474
559
  ], Membership.prototype, "userId", 2);
475
- __decorateClass$7([
560
+ __decorateClass$6([
476
561
  foreignKey("Tenant", { required: true })
477
562
  ], Membership.prototype, "tenantId", 2);
478
- __decorateClass$7([
563
+ __decorateClass$6([
479
564
  foreignKey("Role", { required: true })
480
565
  ], Membership.prototype, "roleId", 2);
481
- __decorateClass$7([
566
+ __decorateClass$6([
482
567
  field({ type: "text" })
483
568
  ], Membership.prototype, "status", 2);
484
- Membership = __decorateClass$7([
569
+ Membership = __decorateClass$6([
485
570
  smrt({
486
571
  // #1400: read-only generated surface — RBAC/identity writes go through
487
572
  // permission-gated services, not auth-only generated CRUD (requireRouteAuth
@@ -558,14 +643,14 @@ class MembershipCollection extends SmrtCollection {
558
643
  });
559
644
  }
560
645
  }
561
- var __defProp$5 = Object.defineProperty;
562
- var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
563
- var __decorateClass$6 = (decorators, target, key, kind) => {
564
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
646
+ var __defProp$4 = Object.defineProperty;
647
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
648
+ var __decorateClass$5 = (decorators, target, key, kind) => {
649
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
565
650
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
566
651
  if (decorator = decorators[i])
567
652
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
568
- if (kind && result) __defProp$5(target, key, result);
653
+ if (kind && result) __defProp$4(target, key, result);
569
654
  return result;
570
655
  };
571
656
  let MembershipOverride = class extends SmrtObject {
@@ -593,16 +678,16 @@ let MembershipOverride = class extends SmrtObject {
593
678
  return this.effect === OverrideEffect.DENY;
594
679
  }
595
680
  };
596
- __decorateClass$6([
681
+ __decorateClass$5([
597
682
  foreignKey("Membership", { required: true })
598
683
  ], MembershipOverride.prototype, "membershipId", 2);
599
- __decorateClass$6([
684
+ __decorateClass$5([
600
685
  foreignKey("Permission", { required: true })
601
686
  ], MembershipOverride.prototype, "permissionId", 2);
602
- __decorateClass$6([
687
+ __decorateClass$5([
603
688
  field({ type: "text" })
604
689
  ], MembershipOverride.prototype, "effect", 2);
605
- MembershipOverride = __decorateClass$6([
690
+ MembershipOverride = __decorateClass$5([
606
691
  smrt({
607
692
  // #1400: read-only generated REST + MCP surface — RBAC/identity writes go
608
693
  // through permission-gated services, not auth-only generated CRUD. mcp must
@@ -711,9 +796,9 @@ class MembershipOverrideCollection extends SmrtCollection {
711
796
  );
712
797
  }
713
798
  }
714
- var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
715
- var __decorateClass$5 = (decorators, target, key, kind) => {
716
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
799
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
800
+ var __decorateClass$4 = (decorators, target, key, kind) => {
801
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
717
802
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
718
803
  if (decorator = decorators[i])
719
804
  result = decorator(result) || result;
@@ -785,7 +870,7 @@ let Permission = class extends SmrtObject {
785
870
  return this.parseSlug().isValid;
786
871
  }
787
872
  };
788
- Permission = __decorateClass$5([
873
+ Permission = __decorateClass$4([
789
874
  smrt({
790
875
  // #1400: read-only generated surface — RBAC/identity writes go through
791
876
  // permission-gated services, not auth-only generated CRUD.
@@ -864,14 +949,14 @@ class PermissionCollection extends SmrtCollection {
864
949
  return permission;
865
950
  }
866
951
  }
867
- var __defProp$4 = Object.defineProperty;
868
- var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
869
- var __decorateClass$4 = (decorators, target, key, kind) => {
870
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
952
+ var __defProp$3 = Object.defineProperty;
953
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
954
+ var __decorateClass$3 = (decorators, target, key, kind) => {
955
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
871
956
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
872
957
  if (decorator = decorators[i])
873
958
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
874
- if (kind && result) __defProp$4(target, key, result);
959
+ if (kind && result) __defProp$3(target, key, result);
875
960
  return result;
876
961
  };
877
962
  let RolePermission = class extends SmrtObject {
@@ -884,13 +969,13 @@ let RolePermission = class extends SmrtObject {
884
969
  this.permissionId = options.permissionId;
885
970
  }
886
971
  };
887
- __decorateClass$4([
972
+ __decorateClass$3([
888
973
  foreignKey("Role", { required: true })
889
974
  ], RolePermission.prototype, "roleId", 2);
890
- __decorateClass$4([
975
+ __decorateClass$3([
891
976
  foreignKey("Permission", { required: true })
892
977
  ], RolePermission.prototype, "permissionId", 2);
893
- RolePermission = __decorateClass$4([
978
+ RolePermission = __decorateClass$3([
894
979
  smrt({
895
980
  // #1400: read-only generated REST + MCP surface — RBAC/identity writes go
896
981
  // through permission-gated services, not auth-only generated CRUD. mcp must
@@ -965,14 +1050,14 @@ class RolePermissionCollection extends SmrtCollection {
965
1050
  return rolePermissions.map((rp) => rp.permissionId);
966
1051
  }
967
1052
  }
968
- var __defProp$3 = Object.defineProperty;
969
- var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
970
- var __decorateClass$3 = (decorators, target, key, kind) => {
971
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1053
+ var __defProp$2 = Object.defineProperty;
1054
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1055
+ var __decorateClass$2 = (decorators, target, key, kind) => {
1056
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
972
1057
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
973
1058
  if (decorator = decorators[i])
974
1059
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
975
- if (kind && result) __defProp$3(target, key, result);
1060
+ if (kind && result) __defProp$2(target, key, result);
976
1061
  return result;
977
1062
  };
978
1063
  const DEFAULT_SESSION_TTL = 7 * 24 * 60 * 60;
@@ -1080,16 +1165,16 @@ let Session = class extends SmrtObject {
1080
1165
  delete this.data[key];
1081
1166
  }
1082
1167
  };
1083
- __decorateClass$3([
1168
+ __decorateClass$2([
1084
1169
  foreignKey("User")
1085
1170
  ], Session.prototype, "userId", 2);
1086
- __decorateClass$3([
1171
+ __decorateClass$2([
1087
1172
  foreignKey("Tenant", { nullable: true })
1088
1173
  ], Session.prototype, "tenantId", 2);
1089
- __decorateClass$3([
1174
+ __decorateClass$2([
1090
1175
  field({ type: "text" })
1091
1176
  ], Session.prototype, "status", 2);
1092
- Session = __decorateClass$3([
1177
+ Session = __decorateClass$2([
1093
1178
  smrt({
1094
1179
  // Sessions should not be exposed via public API for security
1095
1180
  api: { include: ["get", "delete"] },
@@ -1268,14 +1353,14 @@ class SessionCollection extends SmrtCollection {
1268
1353
  return session.getData(key);
1269
1354
  }
1270
1355
  }
1271
- var __defProp$2 = Object.defineProperty;
1272
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1273
- var __decorateClass$2 = (decorators, target, key, kind) => {
1274
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1356
+ var __defProp$1 = Object.defineProperty;
1357
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
1358
+ var __decorateClass$1 = (decorators, target, key, kind) => {
1359
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
1275
1360
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
1276
1361
  if (decorator = decorators[i])
1277
1362
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1278
- if (kind && result) __defProp$2(target, key, result);
1363
+ if (kind && result) __defProp$1(target, key, result);
1279
1364
  return result;
1280
1365
  };
1281
1366
  const MAX_TENANT_HIERARCHY_DEPTH = 10;
@@ -1382,13 +1467,13 @@ let Tenant = class extends SmrtObject {
1382
1467
  return this.hierarchyPath.split("/").filter((id) => id.length > 0);
1383
1468
  }
1384
1469
  };
1385
- __decorateClass$2([
1470
+ __decorateClass$1([
1386
1471
  field({ type: "text" })
1387
1472
  ], Tenant.prototype, "status", 2);
1388
- __decorateClass$2([
1473
+ __decorateClass$1([
1389
1474
  foreignKey("Tenant", { nullable: true })
1390
1475
  ], Tenant.prototype, "parentTenantId", 2);
1391
- Tenant = __decorateClass$2([
1476
+ Tenant = __decorateClass$1([
1392
1477
  smrt({
1393
1478
  tableStrategy: "sti",
1394
1479
  // #1400: read-only generated surface — tenant create/update (incl. the
@@ -1771,14 +1856,14 @@ class TenantCollection extends SmrtCollection {
1771
1856
  return super.create(options);
1772
1857
  }
1773
1858
  }
1774
- var __defProp$1 = Object.defineProperty;
1775
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
1776
- var __decorateClass$1 = (decorators, target, key, kind) => {
1777
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
1859
+ var __defProp = Object.defineProperty;
1860
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1861
+ var __decorateClass = (decorators, target, key, kind) => {
1862
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
1778
1863
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
1779
1864
  if (decorator = decorators[i])
1780
1865
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1781
- if (kind && result) __defProp$1(target, key, result);
1866
+ if (kind && result) __defProp(target, key, result);
1782
1867
  return result;
1783
1868
  };
1784
1869
  let TenantPermissionOverride = class extends SmrtObject {
@@ -1817,16 +1902,16 @@ let TenantPermissionOverride = class extends SmrtObject {
1817
1902
  return this.effect !== TenantPermissionEffect.INHERIT;
1818
1903
  }
1819
1904
  };
1820
- __decorateClass$1([
1905
+ __decorateClass([
1821
1906
  foreignKey("Tenant", { required: true })
1822
1907
  ], TenantPermissionOverride.prototype, "tenantId", 2);
1823
- __decorateClass$1([
1908
+ __decorateClass([
1824
1909
  foreignKey("Permission", { required: true })
1825
1910
  ], TenantPermissionOverride.prototype, "permissionId", 2);
1826
- __decorateClass$1([
1911
+ __decorateClass([
1827
1912
  field({ type: "text" })
1828
1913
  ], TenantPermissionOverride.prototype, "effect", 2);
1829
- TenantPermissionOverride = __decorateClass$1([
1914
+ TenantPermissionOverride = __decorateClass([
1830
1915
  smrt({
1831
1916
  // #1400: read-only generated REST + MCP surface — RBAC/identity writes go
1832
1917
  // through permission-gated services, not auth-only generated CRUD. mcp must
@@ -2062,91 +2147,6 @@ class TenantPermissionOverrideCollection extends SmrtCollection {
2062
2147
  return results;
2063
2148
  }
2064
2149
  }
2065
- var __defProp = Object.defineProperty;
2066
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2067
- var __decorateClass = (decorators, target, key, kind) => {
2068
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
2069
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
2070
- if (decorator = decorators[i])
2071
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2072
- if (kind && result) __defProp(target, key, result);
2073
- return result;
2074
- };
2075
- const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
2076
- function isValidEmail(email) {
2077
- if (!email || typeof email !== "string") return false;
2078
- return EMAIL_REGEX.test(email.trim());
2079
- }
2080
- function normalizeEmail(email) {
2081
- if (!email || typeof email !== "string") return "";
2082
- return email.trim().toLowerCase();
2083
- }
2084
- let User = class extends SmrtObject {
2085
- profileId = "";
2086
- /**
2087
- * User's email address (unique, used for lookup)
2088
- */
2089
- email = "";
2090
- status = UserStatus.ACTIVE;
2091
- /**
2092
- * Last login timestamp
2093
- */
2094
- lastLoginAt = null;
2095
- constructor(options = {}) {
2096
- super(options);
2097
- if (options.profileId !== void 0) this.profileId = options.profileId;
2098
- if (options.email !== void 0) this.email = normalizeEmail(options.email);
2099
- if (options.status !== void 0) this.status = options.status;
2100
- if (options.lastLoginAt !== void 0)
2101
- this.lastLoginAt = options.lastLoginAt;
2102
- }
2103
- /**
2104
- * Validate the user's email format.
2105
- * @returns true if email is valid
2106
- */
2107
- hasValidEmail() {
2108
- return isValidEmail(this.email);
2109
- }
2110
- /**
2111
- * Check if user is active
2112
- */
2113
- isActive() {
2114
- return this.status === UserStatus.ACTIVE;
2115
- }
2116
- /**
2117
- * Check if user is suspended
2118
- */
2119
- isSuspended() {
2120
- return this.status === UserStatus.SUSPENDED;
2121
- }
2122
- /**
2123
- * Check if user is pending verification
2124
- */
2125
- isPending() {
2126
- return this.status === UserStatus.PENDING;
2127
- }
2128
- /**
2129
- * Record a login event
2130
- */
2131
- recordLogin() {
2132
- this.lastLoginAt = /* @__PURE__ */ new Date();
2133
- }
2134
- };
2135
- __decorateClass([
2136
- crossPackageRef("@happyvertical/smrt-profiles:Profile")
2137
- ], User.prototype, "profileId", 2);
2138
- __decorateClass([
2139
- field({ type: "text" })
2140
- ], User.prototype, "status", 2);
2141
- User = __decorateClass([
2142
- smrt({
2143
- // #1400: read-only generated surface — User is auth identity (email/status/
2144
- // profileId), provisioned via OIDC/magic-link, not arbitrary authed POST/PUT.
2145
- api: { include: ["list", "get"] },
2146
- mcp: { include: ["list", "get"] },
2147
- cli: true
2148
- })
2149
- ], User);
2150
2150
  class UserCollection extends SmrtCollection {
2151
2151
  static _itemClass = User;
2152
2152
  /**
@@ -5184,17 +5184,17 @@ class TerminalAuthRateLimitError extends TerminalAuthError {
5184
5184
  }
5185
5185
  export {
5186
5186
  checkKeyLength as $,
5187
- Tenant as A,
5188
- TenantHierarchyError as B,
5189
- TenantPermissionOverride as C,
5187
+ SessionService as A,
5188
+ Tenant as B,
5189
+ TenantHierarchyError as C,
5190
5190
  DEFAULT_ROLES as D,
5191
- TenantPermissionOverrideCollection as E,
5192
- TerminalAuthError as F,
5191
+ TenantPermissionOverride as E,
5192
+ TenantPermissionOverrideCollection as F,
5193
5193
  Group as G,
5194
- TerminalAuthRateLimitError as H,
5195
- TerminalAuthService as I,
5196
- User as J,
5197
- UserCollection as K,
5194
+ TerminalAuthError as H,
5195
+ TerminalAuthRateLimitError as I,
5196
+ TerminalAuthService as J,
5197
+ User as K,
5198
5198
  decodeOidcTransaction as L,
5199
5199
  MembershipCollection as M,
5200
5200
  encodeOidcTransaction as N,
@@ -5204,14 +5204,14 @@ export {
5204
5204
  RolePermission as R,
5205
5205
  Session as S,
5206
5206
  TenantCollection as T,
5207
- UsersCliAuthRequest as U,
5207
+ UserCollection as U,
5208
5208
  getCurrentSessionPermissionContext as V,
5209
5209
  getRequestScopedDatabase as W,
5210
5210
  getUsersOidcConfig as X,
5211
5211
  resolveOidcProviderConfig as Y,
5212
5212
  withSessionPermissionContext as Z,
5213
5213
  getSigKey as _,
5214
- isValidPermissionSlug as a,
5214
+ DEFAULT_ROLE_SLUGS as a,
5215
5215
  subtleAlgorithm as a0,
5216
5216
  JWSInvalid as a1,
5217
5217
  isDisjoint as a2,
@@ -5232,30 +5232,30 @@ export {
5232
5232
  flattenedVerify as ah,
5233
5233
  importJWK as ai,
5234
5234
  jwksCache as aj,
5235
- DEFAULT_TENANT_POLICY as b,
5236
- DEFAULT_ROLE_SLUGS as c,
5237
- UsersCliAuthRequestCollection as d,
5238
- DEFAULT_CLI_AUTH_POLL_INTERVAL_SECONDS as e,
5239
- DEFAULT_CLI_AUTH_REQUEST_TTL_SECONDS as f,
5240
- DEFAULT_CLI_SESSION_TTL_SECONDS as g,
5241
- DEFAULT_SESSION_TTL as h,
5235
+ isValidPermissionSlug as b,
5236
+ DEFAULT_TENANT_POLICY as c,
5237
+ UsersCliAuthRequest as d,
5238
+ UsersCliAuthRequestCollection as e,
5239
+ DEFAULT_CLI_AUTH_POLL_INTERVAL_SECONDS as f,
5240
+ DEFAULT_CLI_AUTH_REQUEST_TTL_SECONDS as g,
5241
+ DEFAULT_CLI_SESSION_TTL_SECONDS as h,
5242
5242
  isValidEmail as i,
5243
- GroupCollection as j,
5244
- GroupMember as k,
5245
- GroupMemberCollection as l,
5246
- GroupRole as m,
5243
+ DEFAULT_SESSION_TTL as j,
5244
+ GroupCollection as k,
5245
+ GroupMember as l,
5246
+ GroupMemberCollection as m,
5247
5247
  normalizeEmail as n,
5248
- GroupRoleCollection as o,
5248
+ GroupRole as o,
5249
5249
  parsePermissionSlug as p,
5250
- MAX_TENANT_HIERARCHY_DEPTH as q,
5251
- Membership as r,
5252
- MembershipOverride as s,
5253
- MembershipOverrideCollection as t,
5254
- OidcLoginService as u,
5255
- Permission as v,
5256
- PermissionResolver as w,
5257
- RolePermissionCollection as x,
5258
- SessionCollection as y,
5259
- SessionService as z
5250
+ GroupRoleCollection as q,
5251
+ MAX_TENANT_HIERARCHY_DEPTH as r,
5252
+ Membership as s,
5253
+ MembershipOverride as t,
5254
+ MembershipOverrideCollection as u,
5255
+ OidcLoginService as v,
5256
+ Permission as w,
5257
+ PermissionResolver as x,
5258
+ RolePermissionCollection as y,
5259
+ SessionCollection as z
5260
5260
  };
5261
- //# sourceMappingURL=TerminalAuthService-bY1oWeAh.js.map
5261
+ //# sourceMappingURL=TerminalAuthService-DcgimQYo.js.map