@nexys/user-management-client 0.1.0 → 0.2.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.
Files changed (64) hide show
  1. package/README.md +19 -0
  2. package/dist/endpoints/admin-users.d.ts +53 -23
  3. package/dist/endpoints/admin-users.d.ts.map +1 -1
  4. package/dist/endpoints/admin-users.js +56 -23
  5. package/dist/endpoints/admin-users.js.map +1 -1
  6. package/dist/endpoints/api-tokens.d.ts +23 -0
  7. package/dist/endpoints/api-tokens.d.ts.map +1 -0
  8. package/dist/endpoints/api-tokens.js +28 -0
  9. package/dist/endpoints/api-tokens.js.map +1 -0
  10. package/dist/endpoints/auth.d.ts +50 -7
  11. package/dist/endpoints/auth.d.ts.map +1 -1
  12. package/dist/endpoints/auth.js +33 -4
  13. package/dist/endpoints/auth.js.map +1 -1
  14. package/dist/endpoints/index.d.ts +4 -0
  15. package/dist/endpoints/index.d.ts.map +1 -1
  16. package/dist/endpoints/index.js +4 -0
  17. package/dist/endpoints/index.js.map +1 -1
  18. package/dist/endpoints/me.d.ts +14 -1
  19. package/dist/endpoints/me.d.ts.map +1 -1
  20. package/dist/endpoints/me.js +11 -0
  21. package/dist/endpoints/me.js.map +1 -1
  22. package/dist/endpoints/passkeys.d.ts +39 -0
  23. package/dist/endpoints/passkeys.d.ts.map +1 -0
  24. package/dist/endpoints/passkeys.js +53 -0
  25. package/dist/endpoints/passkeys.js.map +1 -0
  26. package/dist/endpoints/projects.d.ts +69 -0
  27. package/dist/endpoints/projects.d.ts.map +1 -0
  28. package/dist/endpoints/projects.js +73 -0
  29. package/dist/endpoints/projects.js.map +1 -0
  30. package/dist/endpoints/tenants.d.ts +72 -103
  31. package/dist/endpoints/tenants.d.ts.map +1 -1
  32. package/dist/endpoints/tenants.js +64 -82
  33. package/dist/endpoints/tenants.js.map +1 -1
  34. package/dist/endpoints/two-factor.d.ts +50 -0
  35. package/dist/endpoints/two-factor.d.ts.map +1 -0
  36. package/dist/endpoints/two-factor.js +64 -0
  37. package/dist/endpoints/two-factor.js.map +1 -0
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/types.d.ts +128 -44
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/package.json +7 -2
  47. package/src/endpoint.test.ts +158 -0
  48. package/src/endpoint.ts +123 -0
  49. package/src/endpoints/admin-audit.ts +60 -0
  50. package/src/endpoints/admin-keys.ts +37 -0
  51. package/src/endpoints/admin-users.ts +172 -0
  52. package/src/endpoints/api-tokens.ts +37 -0
  53. package/src/endpoints/auth.ts +203 -0
  54. package/src/endpoints/health.ts +50 -0
  55. package/src/endpoints/index.ts +12 -0
  56. package/src/endpoints/me.ts +79 -0
  57. package/src/endpoints/passkeys.ts +77 -0
  58. package/src/endpoints/projects.ts +117 -0
  59. package/src/endpoints/refresh-tokens.ts +25 -0
  60. package/src/endpoints/tenants.ts +313 -0
  61. package/src/endpoints/two-factor.ts +84 -0
  62. package/src/index.ts +26 -0
  63. package/src/result.ts +39 -0
  64. package/src/types.ts +285 -0
package/src/types.ts ADDED
@@ -0,0 +1,285 @@
1
+ /**
2
+ * Wire types matching the `user-management-rs` axum server.
3
+ * Field names are camelCase because the Rust wire.rs renames them
4
+ * with serde — keep this file byte-for-byte aligned with the server.
5
+ */
6
+
7
+ export type UserRole = "superadmin" | "useradmin" | "user" | (string & {});
8
+ export type TenantRole = "owner" | "admin" | "member" | (string & {});
9
+ export type UserStatus = "active" | "inactive" | "pending" | (string & {});
10
+ export type UserType = "human" | "service" | (string & {});
11
+ export type AuthSource = "cookie" | "jwt" | (string & {});
12
+
13
+ export interface SessionUser {
14
+ id: string;
15
+ email: string;
16
+ name: string;
17
+ image: string | null;
18
+ emailVerified: boolean;
19
+ role: UserRole;
20
+ banned: boolean;
21
+ banReason: string | null;
22
+ banExpires: string | null;
23
+ twoFactorEnabled: boolean;
24
+ status: UserStatus;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ }
28
+
29
+ export interface SessionRow {
30
+ id: string;
31
+ userId: string;
32
+ token: string;
33
+ expiresAt: string;
34
+ ipAddress: string | null;
35
+ userAgent: string | null;
36
+ impersonatedBy: string | null;
37
+ activeOrganizationId: string | null;
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ }
41
+
42
+ export interface AuthSuccess {
43
+ user: SessionUser;
44
+ session?: SessionRow;
45
+ }
46
+
47
+ /**
48
+ * Password sign-in for a 2FA-enrolled user returns this instead of
49
+ * {@link AuthSuccess}; complete the flow with `verifyTotp` or
50
+ * `verifyBackupCode`, echoing the token back.
51
+ */
52
+ export interface TwoFactorChallenge {
53
+ twoFactorRequired: true;
54
+ twoFactorToken: string;
55
+ }
56
+
57
+ export type SignInResult = AuthSuccess | TwoFactorChallenge;
58
+
59
+ export const isTwoFactorChallenge = (
60
+ r: SignInResult
61
+ ): r is TwoFactorChallenge =>
62
+ (r as TwoFactorChallenge).twoFactorRequired === true;
63
+
64
+ export interface TwoFactorEnableResponse {
65
+ /** Base32 TOTP secret, for manual authenticator entry. */
66
+ secret: string;
67
+ /** `otpauth://totp/...` URI — render as a QR code. */
68
+ uri: string;
69
+ /** 10 single-use backup codes, shown exactly once. */
70
+ backupCodes: string[];
71
+ }
72
+
73
+ export interface ApiTokenRow {
74
+ id: string;
75
+ name: string | null;
76
+ /** Display prefix of the plaintext ("um_a1b2c"). */
77
+ start: string | null;
78
+ status: "active" | "revoked" | "expired" | (string & {});
79
+ createdAt: string;
80
+ expiresAt: string | null;
81
+ revokedAt: string | null;
82
+ lastUsedAt: string | null;
83
+ }
84
+
85
+ export interface ApiTokenCreated {
86
+ id: string;
87
+ /** The full plaintext token — shown exactly once, never stored. */
88
+ token: string;
89
+ name: string;
90
+ start: string;
91
+ expiresAt: string | null;
92
+ }
93
+
94
+ export interface PasskeyItem {
95
+ id: string;
96
+ name: string | null;
97
+ createdAt: string | null;
98
+ deviceType: string;
99
+ backedUp: boolean;
100
+ transports: string | null;
101
+ }
102
+
103
+ /**
104
+ * WebAuthn ceremony start: `options` is the standard
105
+ * `PublicKeyCredential{Creation,Request}Options` JSON (base64url
106
+ * fields) for the browser; `challenge` is the opaque server handle to
107
+ * echo back on finish.
108
+ */
109
+ export interface WebAuthnCeremonyStart {
110
+ challenge: string;
111
+ options: Record<string, unknown>;
112
+ }
113
+
114
+ export interface MeResponse {
115
+ user: { id: string; email: string; name: string | null; role: UserRole };
116
+ session: { activeOrganizationId: string | null; tenantRoles: TenantRole[] };
117
+ authSource: AuthSource;
118
+ }
119
+
120
+ export interface TokenMintResponse {
121
+ accessToken: string;
122
+ accessTokenExpiresAt: string;
123
+ refreshToken: string;
124
+ refreshTokenExpiresAt: string;
125
+ kid: string;
126
+ token: string;
127
+ expiresAt: string;
128
+ }
129
+
130
+ export interface TokenRefreshResponse {
131
+ accessToken: string;
132
+ accessTokenExpiresAt: string;
133
+ refreshToken: string;
134
+ refreshTokenExpiresAt: string;
135
+ kid: string;
136
+ }
137
+
138
+ export interface RefreshToken {
139
+ id: string;
140
+ userId: string;
141
+ expiresAt: string;
142
+ ipAddress: string | null;
143
+ userAgent: string | null;
144
+ createdAt: string;
145
+ revokedAt: string | null;
146
+ current?: boolean;
147
+ }
148
+
149
+ export interface AdminUserRow {
150
+ id: string;
151
+ /** Display name — kept in sync with first/last when those are set. */
152
+ name: string;
153
+ firstName: string | null;
154
+ lastName: string | null;
155
+ email: string;
156
+ role: UserRole;
157
+ status: UserStatus;
158
+ type: UserType;
159
+ /** Linked auth providers — "credential" plus any social ids. */
160
+ providers: string[];
161
+ deletedAt: string | null;
162
+ createdAt: string;
163
+ updatedAt: string;
164
+ }
165
+
166
+ export interface AuthAccount {
167
+ id: string;
168
+ providerId: string;
169
+ createdAt: string;
170
+ }
171
+
172
+ export interface AuthPasskey {
173
+ id: string;
174
+ name: string | null;
175
+ deviceType: string;
176
+ createdAt: string | null;
177
+ }
178
+
179
+ export interface AuthMethodsResponse {
180
+ accounts: AuthAccount[];
181
+ passkeys: AuthPasskey[];
182
+ twoFactorEnabled: boolean;
183
+ }
184
+
185
+ export interface UserMembership {
186
+ memberId: string;
187
+ organizationId: string;
188
+ organizationName: string;
189
+ organizationSlug: string;
190
+ role: TenantRole;
191
+ createdAt: string;
192
+ }
193
+
194
+ export interface AdminUserListResponse {
195
+ total: number;
196
+ rows: AdminUserRow[];
197
+ }
198
+
199
+ export interface TenantRow {
200
+ id: string;
201
+ name: string;
202
+ slug: string;
203
+ /** Project the tenant lives in; null for legacy tenants. */
204
+ projectId?: string | null;
205
+ createdAt: string;
206
+ memberCount: number;
207
+ }
208
+
209
+ export type TenancyMode = "multi" | "single";
210
+
211
+ export interface ProjectRow {
212
+ id: string;
213
+ name: string;
214
+ slug: string;
215
+ ownerUserId: string;
216
+ tenancyMode: TenancyMode;
217
+ allowTenantCreation: boolean;
218
+ allowSignup: boolean;
219
+ metadata: Record<string, unknown> | null;
220
+ tenantCount?: number;
221
+ createdAt: string;
222
+ updatedAt: string;
223
+ }
224
+
225
+ export interface Member {
226
+ id: string;
227
+ organizationId: string;
228
+ userId: string;
229
+ role: TenantRole;
230
+ /** Custom tenant roles assigned to this member. */
231
+ roles?: MemberRoleRef[];
232
+ createdAt: string;
233
+ user: { name: string; email: string; image: string | null };
234
+ }
235
+
236
+ export interface MemberRoleRef {
237
+ id: string;
238
+ name: string;
239
+ }
240
+
241
+ export interface FullOrganization {
242
+ id: string;
243
+ name: string;
244
+ slug: string;
245
+ logo?: string | null;
246
+ /** Per-tenant settings blob; null when unset. */
247
+ metadata?: Record<string, unknown> | null;
248
+ members: Member[];
249
+ invitations: Invitation[];
250
+ }
251
+
252
+ export interface Invitation {
253
+ id: string;
254
+ email: string;
255
+ role: TenantRole;
256
+ status: "pending" | "accepted" | "rejected" | "expired" | (string & {});
257
+ organizationId: string;
258
+ expiresAt?: string;
259
+ createdAt?: string;
260
+ }
261
+
262
+ export interface RoleRow {
263
+ id: string;
264
+ name: string;
265
+ description: string | null;
266
+ /** Permission strings granted by this role (e.g. `invoices:read`). */
267
+ permissions: string[];
268
+ createdAt: string;
269
+ updatedAt: string;
270
+ }
271
+
272
+ export interface MyTenantPermissions {
273
+ /** Built-in membership role; null for a non-member superadmin. */
274
+ role: TenantRole | null;
275
+ /** Names of assigned custom roles. */
276
+ roles: string[];
277
+ /** Union of permissions granted by those roles, sorted. */
278
+ permissions: string[];
279
+ }
280
+
281
+ export interface ApiErrorBody {
282
+ code?: string;
283
+ error?: string;
284
+ message?: string;
285
+ }