@happyvertical/smrt-users 0.31.0 → 0.31.1

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.
Files changed (29) hide show
  1. package/dist/chunks/{TerminalAuthService-DoAMQ_yn.js → TerminalAuthService-DsQBk1Hc.js} +161 -71
  2. package/dist/chunks/TerminalAuthService-DsQBk1Hc.js.map +1 -0
  3. package/dist/chunks/{index-DkoYIvIu.js → index-Cp33Tyha.js} +10 -10
  4. package/dist/chunks/{index-DkoYIvIu.js.map → index-Cp33Tyha.js.map} +1 -1
  5. package/dist/collections/GroupMemberCollection.d.ts +9 -0
  6. package/dist/collections/GroupMemberCollection.d.ts.map +1 -1
  7. package/dist/collections/SessionCollection.d.ts.map +1 -1
  8. package/dist/index.js +38 -100
  9. package/dist/index.js.map +1 -1
  10. package/dist/manifest.json +2 -2
  11. package/dist/smrt-knowledge.json +4 -4
  12. package/dist/svelte/components/InviteUserModal.svelte +72 -169
  13. package/dist/svelte/components/InviteUserModal.svelte.d.ts.map +1 -1
  14. package/dist/svelte/components/UserCard.svelte +2 -1
  15. package/dist/svelte/components/UserCard.svelte.d.ts.map +1 -1
  16. package/dist/svelte/components/UserForm.svelte +11 -4
  17. package/dist/svelte/components/UserForm.svelte.d.ts.map +1 -1
  18. package/dist/svelte/components/UserMenu.svelte +100 -25
  19. package/dist/svelte/components/UserMenu.svelte.d.ts +5 -4
  20. package/dist/svelte/components/UserMenu.svelte.d.ts.map +1 -1
  21. package/dist/svelte/components/__tests__/InviteUserModal.test.js +11 -0
  22. package/dist/svelte/components/__tests__/UserMenu.test.js +45 -0
  23. package/dist/svelte/components/__tests__/UserStatus.test.js +36 -0
  24. package/dist/sveltekit/index.d.ts +7 -1
  25. package/dist/sveltekit/index.d.ts.map +1 -1
  26. package/dist/sveltekit.js +15 -8
  27. package/dist/sveltekit.js.map +1 -1
  28. package/package.json +8 -8
  29. package/dist/chunks/TerminalAuthService-DoAMQ_yn.js.map +0 -1
@@ -6,14 +6,14 @@ import { MembershipStatus, OverrideEffect, SessionStatus, TenantStatus, TenantPe
6
6
  ObjectRegistry.registerPackageManifest(
7
7
  new URL("./manifest.json", import.meta.url)
8
8
  );
9
- var __defProp$9 = Object.defineProperty;
10
- var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
11
- var __decorateClass$a = (decorators, target, key, kind) => {
12
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
9
+ var __defProp$a = Object.defineProperty;
10
+ var __getOwnPropDesc$b = Object.getOwnPropertyDescriptor;
11
+ var __decorateClass$b = (decorators, target, key, kind) => {
12
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target;
13
13
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
14
14
  if (decorator = decorators[i])
15
15
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
16
- if (kind && result) __defProp$9(target, key, result);
16
+ if (kind && result) __defProp$a(target, key, result);
17
17
  return result;
18
18
  };
19
19
  let UsersCliAuthRequest = class extends SmrtObject {
@@ -26,31 +26,31 @@ let UsersCliAuthRequest = class extends SmrtObject {
26
26
  expiresAt = /* @__PURE__ */ new Date();
27
27
  approvedAt = null;
28
28
  };
29
- __decorateClass$a([
29
+ __decorateClass$b([
30
30
  field({ type: "text" })
31
31
  ], UsersCliAuthRequest.prototype, "userCode", 2);
32
- __decorateClass$a([
32
+ __decorateClass$b([
33
33
  field({ type: "text" })
34
34
  ], UsersCliAuthRequest.prototype, "deviceCodeHash", 2);
35
- __decorateClass$a([
35
+ __decorateClass$b([
36
36
  field({ type: "text" })
37
37
  ], UsersCliAuthRequest.prototype, "status", 2);
38
- __decorateClass$a([
38
+ __decorateClass$b([
39
39
  field({ type: "text" })
40
40
  ], UsersCliAuthRequest.prototype, "userId", 2);
41
- __decorateClass$a([
41
+ __decorateClass$b([
42
42
  field({ type: "text" })
43
43
  ], UsersCliAuthRequest.prototype, "tenantId", 2);
44
- __decorateClass$a([
44
+ __decorateClass$b([
45
45
  field({ type: "text" })
46
46
  ], UsersCliAuthRequest.prototype, "sessionId", 2);
47
- __decorateClass$a([
47
+ __decorateClass$b([
48
48
  field({ type: "datetime" })
49
49
  ], UsersCliAuthRequest.prototype, "expiresAt", 2);
50
- __decorateClass$a([
50
+ __decorateClass$b([
51
51
  field({ type: "datetime", nullable: true })
52
52
  ], UsersCliAuthRequest.prototype, "approvedAt", 2);
53
- UsersCliAuthRequest = __decorateClass$a([
53
+ UsersCliAuthRequest = __decorateClass$b([
54
54
  smrt({
55
55
  tableName: "users_cli_auth_requests",
56
56
  api: { include: [] },
@@ -98,6 +98,68 @@ class UsersCliAuthRequestCollection extends SmrtCollection {
98
98
  return count;
99
99
  }
100
100
  }
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;
105
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
106
+ if (decorator = decorators[i])
107
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
108
+ if (kind && result) __defProp$9(target, key, result);
109
+ return result;
110
+ };
111
+ let Group = class extends SmrtObject {
112
+ tenantId;
113
+ /**
114
+ * Display name for the group
115
+ */
116
+ name = "";
117
+ /**
118
+ * Description of the group
119
+ */
120
+ description = "";
121
+ constructor(options = {}) {
122
+ super(options);
123
+ if (options.tenantId !== void 0) this.tenantId = options.tenantId;
124
+ if (options.name !== void 0) this.name = options.name;
125
+ if (options.description !== void 0)
126
+ this.description = options.description;
127
+ }
128
+ };
129
+ __decorateClass$a([
130
+ foreignKey("Tenant", { required: true })
131
+ ], Group.prototype, "tenantId", 2);
132
+ Group = __decorateClass$a([
133
+ smrt({
134
+ // #1400: read-only generated surface — RBAC/identity writes go through
135
+ // permission-gated services, not auth-only generated CRUD.
136
+ api: { include: ["list", "get"] },
137
+ mcp: { include: ["list", "get"] },
138
+ cli: true
139
+ })
140
+ ], Group);
141
+ class GroupCollection extends SmrtCollection {
142
+ static _itemClass = Group;
143
+ /**
144
+ * Find all groups in a tenant
145
+ */
146
+ async findByTenant(tenantId) {
147
+ return await this.list({
148
+ where: { tenantId },
149
+ orderBy: "name ASC"
150
+ });
151
+ }
152
+ /**
153
+ * Find group by slug within a tenant
154
+ */
155
+ async findBySlug(slug, tenantId) {
156
+ const results = await this.list({
157
+ where: { slug, tenantId },
158
+ limit: 1
159
+ });
160
+ return results.length > 0 ? results[0] : null;
161
+ }
162
+ }
101
163
  var __defProp$8 = Object.defineProperty;
102
164
  var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
103
165
  var __decorateClass$9 = (decorators, target, key, kind) => {
@@ -135,6 +197,22 @@ GroupMember = __decorateClass$9([
135
197
  ], GroupMember);
136
198
  class GroupMemberCollection extends SmrtCollection {
137
199
  static _itemClass = GroupMember;
200
+ /** Memoized Group collection, used to resolve the Group table name. */
201
+ groupCollection;
202
+ /**
203
+ * Resolve the database table name for the `Group` model from the registry
204
+ * (via a shared-connection GroupCollection) rather than hardcoding `groups`.
205
+ * A `@smrt({ tableName })` override or table prefix on Group would otherwise
206
+ * make raw joins reference a non-existent or foreign table.
207
+ */
208
+ async getGroupTableName() {
209
+ if (!this.groupCollection) {
210
+ this.groupCollection = await GroupCollection.create({
211
+ db: this.options.db
212
+ });
213
+ }
214
+ return this.groupCollection.tableName;
215
+ }
138
216
  /**
139
217
  * Find all members of a group
140
218
  */
@@ -203,10 +281,11 @@ class GroupMemberCollection extends SmrtCollection {
203
281
  * This prevents cross-tenant permission leakage by filtering groups by tenant
204
282
  */
205
283
  async getGroupIdsForTenant(userId, tenantId) {
284
+ const groupTable = await this.getGroupTableName();
206
285
  const sql = `
207
286
  SELECT gm.group_id
208
287
  FROM ${this.tableName} gm
209
- INNER JOIN groups g ON g.id = gm.group_id
288
+ INNER JOIN ${groupTable} g ON g.id = gm.group_id
210
289
  WHERE gm.user_id = ? AND g.tenant_id = ?
211
290
  `;
212
291
  const result = await this.db.query(sql, userId, tenantId);
@@ -1047,8 +1126,17 @@ class SessionCollection extends SmrtCollection {
1047
1126
  if (!session) return null;
1048
1127
  if (!session.isValid()) {
1049
1128
  if (session.isExpired() && session.status === SessionStatus.ACTIVE) {
1050
- session.status = SessionStatus.EXPIRED;
1051
- await session.save();
1129
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1130
+ await this.db.query(
1131
+ `UPDATE ${this.tableName}
1132
+ SET status = ?, updated_at = ?
1133
+ WHERE id = ? AND status = ? AND expires_at < ?`,
1134
+ SessionStatus.EXPIRED,
1135
+ now,
1136
+ sessionId,
1137
+ SessionStatus.ACTIVE,
1138
+ now
1139
+ );
1052
1140
  }
1053
1141
  return null;
1054
1142
  }
@@ -5042,53 +5130,55 @@ class TerminalAuthRateLimitError extends TerminalAuthError {
5042
5130
  }
5043
5131
  }
5044
5132
  export {
5045
- JWSInvalid as $,
5046
- TenantPermissionOverride as A,
5047
- TenantPermissionOverrideCollection as B,
5048
- TerminalAuthError as C,
5133
+ checkKeyLength as $,
5134
+ Tenant as A,
5135
+ TenantHierarchyError as B,
5136
+ TenantPermissionOverride as C,
5049
5137
  DEFAULT_ROLES as D,
5050
- TerminalAuthRateLimitError as E,
5051
- TerminalAuthService as F,
5052
- GroupMember as G,
5053
- User as H,
5054
- UserCollection as I,
5055
- decodeOidcTransaction as J,
5056
- encodeOidcTransaction as K,
5057
- generateSessionId as L,
5138
+ TenantPermissionOverrideCollection as E,
5139
+ TerminalAuthError as F,
5140
+ Group as G,
5141
+ TerminalAuthRateLimitError as H,
5142
+ TerminalAuthService as I,
5143
+ User as J,
5144
+ UserCollection as K,
5145
+ decodeOidcTransaction as L,
5058
5146
  MembershipCollection as M,
5059
- getCurrentSessionPermissionContext as N,
5147
+ encodeOidcTransaction as N,
5060
5148
  OidcLoginError as O,
5061
5149
  PermissionCollection as P,
5062
- getRequestScopedDatabase as Q,
5150
+ generateSessionId as Q,
5063
5151
  RolePermission as R,
5064
5152
  Session as S,
5065
5153
  TenantCollection as T,
5066
5154
  UsersCliAuthRequest as U,
5067
- getUsersOidcConfig as V,
5068
- resolveOidcProviderConfig as W,
5069
- withSessionPermissionContext as X,
5070
- getSigKey as Y,
5071
- checkKeyLength as Z,
5072
- subtleAlgorithm as _,
5155
+ getCurrentSessionPermissionContext as V,
5156
+ getRequestScopedDatabase as W,
5157
+ getUsersOidcConfig as X,
5158
+ resolveOidcProviderConfig as Y,
5159
+ withSessionPermissionContext as Z,
5160
+ getSigKey as _,
5073
5161
  isValidPermissionSlug as a,
5074
- isDisjoint as a0,
5075
- validateCrit as a1,
5076
- checkKeyType as a2,
5077
- encode as a3,
5078
- encode$1 as a4,
5079
- concat as a5,
5080
- normalizeKey as a6,
5081
- JWTClaimsBuilder as a7,
5082
- JWTInvalid as a8,
5083
- errors as a9,
5084
- jwtVerify as aa,
5085
- compactVerify as ab,
5086
- createLocalJWKSet as ac,
5087
- createRemoteJWKSet as ad,
5088
- customFetch as ae,
5089
- flattenedVerify as af,
5090
- importJWK as ag,
5091
- jwksCache as ah,
5162
+ subtleAlgorithm as a0,
5163
+ JWSInvalid as a1,
5164
+ isDisjoint as a2,
5165
+ validateCrit as a3,
5166
+ checkKeyType as a4,
5167
+ encode as a5,
5168
+ encode$1 as a6,
5169
+ concat as a7,
5170
+ normalizeKey as a8,
5171
+ JWTClaimsBuilder as a9,
5172
+ JWTInvalid as aa,
5173
+ errors as ab,
5174
+ jwtVerify as ac,
5175
+ compactVerify as ad,
5176
+ createLocalJWKSet as ae,
5177
+ createRemoteJWKSet as af,
5178
+ customFetch as ag,
5179
+ flattenedVerify as ah,
5180
+ importJWK as ai,
5181
+ jwksCache as aj,
5092
5182
  DEFAULT_TENANT_POLICY as b,
5093
5183
  DEFAULT_ROLE_SLUGS as c,
5094
5184
  UsersCliAuthRequestCollection as d,
@@ -5097,22 +5187,22 @@ export {
5097
5187
  DEFAULT_CLI_SESSION_TTL_SECONDS as g,
5098
5188
  DEFAULT_SESSION_TTL as h,
5099
5189
  isValidEmail as i,
5100
- GroupMemberCollection as j,
5101
- GroupRole as k,
5102
- GroupRoleCollection as l,
5103
- MAX_TENANT_HIERARCHY_DEPTH as m,
5190
+ GroupCollection as j,
5191
+ GroupMember as k,
5192
+ GroupMemberCollection as l,
5193
+ GroupRole as m,
5104
5194
  normalizeEmail as n,
5105
- Membership as o,
5195
+ GroupRoleCollection as o,
5106
5196
  parsePermissionSlug as p,
5107
- MembershipOverride as q,
5108
- MembershipOverrideCollection as r,
5109
- OidcLoginService as s,
5110
- Permission as t,
5111
- PermissionResolver as u,
5112
- RolePermissionCollection as v,
5113
- SessionCollection as w,
5114
- SessionService as x,
5115
- Tenant as y,
5116
- TenantHierarchyError as z
5197
+ MAX_TENANT_HIERARCHY_DEPTH as q,
5198
+ Membership as r,
5199
+ MembershipOverride as s,
5200
+ MembershipOverrideCollection as t,
5201
+ OidcLoginService as u,
5202
+ Permission as v,
5203
+ PermissionResolver as w,
5204
+ RolePermissionCollection as x,
5205
+ SessionCollection as y,
5206
+ SessionService as z
5117
5207
  };
5118
- //# sourceMappingURL=TerminalAuthService-DoAMQ_yn.js.map
5208
+ //# sourceMappingURL=TerminalAuthService-DsQBk1Hc.js.map