@elqnt/admin 2.0.5 → 2.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.
@@ -0,0 +1,735 @@
1
+ // hooks/use-org-admin.ts
2
+ import { useState, useCallback } from "react";
3
+
4
+ // api/index.ts
5
+ import { browserApiRequest as browserApiRequest4, clearGatewayTokenCache } from "@elqnt/api-client/browser";
6
+
7
+ // api/orgs.ts
8
+ import { browserApiRequest } from "@elqnt/api-client/browser";
9
+ async function listOrgsApi(options) {
10
+ return browserApiRequest("/api/v1/admin/orgs", {
11
+ method: "GET",
12
+ ...options
13
+ });
14
+ }
15
+ async function createOrgApi(org, options) {
16
+ return browserApiRequest("/api/v1/admin/orgs", {
17
+ method: "POST",
18
+ body: org,
19
+ ...options
20
+ });
21
+ }
22
+ async function getOrgApi(orgId, options) {
23
+ return browserApiRequest(`/api/v1/admin/orgs/${orgId}`, {
24
+ method: "GET",
25
+ ...options
26
+ });
27
+ }
28
+ async function updateOrgApi(orgId, updates, options) {
29
+ return browserApiRequest(`/api/v1/admin/orgs/${orgId}`, {
30
+ method: "PUT",
31
+ body: updates,
32
+ ...options
33
+ });
34
+ }
35
+ async function deleteOrgApi(orgId, options) {
36
+ return browserApiRequest(`/api/v1/admin/orgs/${orgId}`, {
37
+ method: "DELETE",
38
+ ...options
39
+ });
40
+ }
41
+ async function getOrgInfoApi(orgId, options) {
42
+ return browserApiRequest(`/api/v1/admin/orgs/${orgId}/info`, {
43
+ method: "GET",
44
+ ...options
45
+ });
46
+ }
47
+
48
+ // api/users.ts
49
+ import { browserApiRequest as browserApiRequest2 } from "@elqnt/api-client/browser";
50
+ async function listUsersApi(options) {
51
+ return browserApiRequest2("/api/v1/admin/users", {
52
+ method: "GET",
53
+ ...options
54
+ });
55
+ }
56
+ async function createUserApi(user, options) {
57
+ return browserApiRequest2("/api/v1/admin/users", {
58
+ method: "POST",
59
+ body: user,
60
+ ...options
61
+ });
62
+ }
63
+ async function getUserApi(userId, options) {
64
+ return browserApiRequest2(`/api/v1/admin/users/${userId}`, {
65
+ method: "GET",
66
+ ...options
67
+ });
68
+ }
69
+ async function getUserByEmailApi(email, options) {
70
+ return browserApiRequest2(`/api/v1/admin/users/by-email?email=${encodeURIComponent(email)}`, {
71
+ method: "GET",
72
+ ...options
73
+ });
74
+ }
75
+ async function updateUserApi(userId, updates, options) {
76
+ return browserApiRequest2(`/api/v1/admin/users/${userId}`, {
77
+ method: "PUT",
78
+ body: updates,
79
+ ...options
80
+ });
81
+ }
82
+ async function deleteUserApi(userId, options) {
83
+ return browserApiRequest2(`/api/v1/admin/users/${userId}`, {
84
+ method: "DELETE",
85
+ ...options
86
+ });
87
+ }
88
+ async function getUserSettingsApi(userId, options) {
89
+ return browserApiRequest2(`/api/v1/admin/users/${userId}/settings`, {
90
+ method: "GET",
91
+ ...options
92
+ });
93
+ }
94
+ async function updateUserSettingsApi(userId, settings, options) {
95
+ return browserApiRequest2(`/api/v1/admin/users/${userId}/settings`, {
96
+ method: "PUT",
97
+ body: settings,
98
+ ...options
99
+ });
100
+ }
101
+
102
+ // api/invites.ts
103
+ import { browserApiRequest as browserApiRequest3 } from "@elqnt/api-client/browser";
104
+ async function listInvitesApi(options) {
105
+ return browserApiRequest3("/api/v1/admin/invites", {
106
+ method: "GET",
107
+ ...options
108
+ });
109
+ }
110
+ async function sendInvitesApi(invites, options) {
111
+ return browserApiRequest3("/api/v1/admin/invites", {
112
+ method: "POST",
113
+ body: { invites },
114
+ ...options
115
+ });
116
+ }
117
+ async function sendInviteApi(invite, options) {
118
+ return browserApiRequest3("/api/v1/admin/invites/single", {
119
+ method: "POST",
120
+ body: invite,
121
+ ...options
122
+ });
123
+ }
124
+ async function getInviteApi(inviteId, options) {
125
+ return browserApiRequest3(`/api/v1/admin/invites/${inviteId}`, {
126
+ method: "GET",
127
+ ...options
128
+ });
129
+ }
130
+ async function resendInviteApi(inviteId, options) {
131
+ return browserApiRequest3(`/api/v1/admin/invites/${inviteId}/resend`, {
132
+ method: "POST",
133
+ ...options
134
+ });
135
+ }
136
+ async function revokeInviteApi(inviteId, options) {
137
+ return browserApiRequest3(`/api/v1/admin/invites/${inviteId}`, {
138
+ method: "DELETE",
139
+ ...options
140
+ });
141
+ }
142
+ async function acceptInviteApi(inviteId, options) {
143
+ return browserApiRequest3(`/api/v1/admin/invites/${inviteId}/accept`, {
144
+ method: "POST",
145
+ ...options
146
+ });
147
+ }
148
+
149
+ // api/index.ts
150
+ async function getOrgSettingsApi(options) {
151
+ return browserApiRequest4("/api/v1/org/settings", {
152
+ method: "GET",
153
+ ...options
154
+ });
155
+ }
156
+ async function createOrgSettingsApi(settings, options) {
157
+ return browserApiRequest4("/api/v1/org/settings", {
158
+ method: "POST",
159
+ body: settings,
160
+ ...options
161
+ });
162
+ }
163
+ async function updateOrgSettingsApi(settings, options) {
164
+ return browserApiRequest4("/api/v1/org/settings", {
165
+ method: "PUT",
166
+ body: settings,
167
+ ...options
168
+ });
169
+ }
170
+
171
+ // hooks/use-org-admin.ts
172
+ function useOrgAdmin(options) {
173
+ const [loading, setLoading] = useState(false);
174
+ const [error, setError] = useState(null);
175
+ const listOrgs = useCallback(async () => {
176
+ setLoading(true);
177
+ setError(null);
178
+ try {
179
+ const response = await listOrgsApi(options);
180
+ if (response.error) {
181
+ setError(response.error);
182
+ return [];
183
+ }
184
+ return response.data?.orgs || [];
185
+ } catch (err) {
186
+ const message = err instanceof Error ? err.message : "Failed to list organizations";
187
+ setError(message);
188
+ return [];
189
+ } finally {
190
+ setLoading(false);
191
+ }
192
+ }, [options]);
193
+ const getOrg = useCallback(
194
+ async (orgId) => {
195
+ setLoading(true);
196
+ setError(null);
197
+ try {
198
+ const response = await getOrgApi(orgId, options);
199
+ if (response.error) {
200
+ setError(response.error);
201
+ return null;
202
+ }
203
+ return response.data?.org || null;
204
+ } catch (err) {
205
+ const message = err instanceof Error ? err.message : "Failed to get organization";
206
+ setError(message);
207
+ return null;
208
+ } finally {
209
+ setLoading(false);
210
+ }
211
+ },
212
+ [options]
213
+ );
214
+ const getOrgInfo = useCallback(
215
+ async (orgId) => {
216
+ setLoading(true);
217
+ setError(null);
218
+ try {
219
+ const response = await getOrgInfoApi(orgId, options);
220
+ if (response.error) {
221
+ setError(response.error);
222
+ return null;
223
+ }
224
+ return response.data?.orgInfo || null;
225
+ } catch (err) {
226
+ const message = err instanceof Error ? err.message : "Failed to get organization info";
227
+ setError(message);
228
+ return null;
229
+ } finally {
230
+ setLoading(false);
231
+ }
232
+ },
233
+ [options]
234
+ );
235
+ const createOrg = useCallback(
236
+ async (org) => {
237
+ setLoading(true);
238
+ setError(null);
239
+ try {
240
+ const response = await createOrgApi(org, options);
241
+ if (response.error) {
242
+ setError(response.error);
243
+ return null;
244
+ }
245
+ return response.data?.org || null;
246
+ } catch (err) {
247
+ const message = err instanceof Error ? err.message : "Failed to create organization";
248
+ setError(message);
249
+ return null;
250
+ } finally {
251
+ setLoading(false);
252
+ }
253
+ },
254
+ [options]
255
+ );
256
+ const updateOrg = useCallback(
257
+ async (orgId, updates) => {
258
+ setLoading(true);
259
+ setError(null);
260
+ try {
261
+ const response = await updateOrgApi(orgId, updates, options);
262
+ if (response.error) {
263
+ setError(response.error);
264
+ return null;
265
+ }
266
+ return response.data?.org || null;
267
+ } catch (err) {
268
+ const message = err instanceof Error ? err.message : "Failed to update organization";
269
+ setError(message);
270
+ return null;
271
+ } finally {
272
+ setLoading(false);
273
+ }
274
+ },
275
+ [options]
276
+ );
277
+ const deleteOrg = useCallback(
278
+ async (orgId) => {
279
+ setLoading(true);
280
+ setError(null);
281
+ try {
282
+ const response = await deleteOrgApi(orgId, options);
283
+ if (response.error) {
284
+ setError(response.error);
285
+ return false;
286
+ }
287
+ return response.data?.success || false;
288
+ } catch (err) {
289
+ const message = err instanceof Error ? err.message : "Failed to delete organization";
290
+ setError(message);
291
+ return false;
292
+ } finally {
293
+ setLoading(false);
294
+ }
295
+ },
296
+ [options]
297
+ );
298
+ return {
299
+ loading,
300
+ error,
301
+ listOrgs,
302
+ getOrg,
303
+ getOrgInfo,
304
+ createOrg,
305
+ updateOrg,
306
+ deleteOrg
307
+ };
308
+ }
309
+
310
+ // hooks/use-users-admin.ts
311
+ import { useState as useState2, useCallback as useCallback2 } from "react";
312
+ function useUsersAdmin(options) {
313
+ const [loading, setLoading] = useState2(false);
314
+ const [error, setError] = useState2(null);
315
+ const listUsers = useCallback2(async () => {
316
+ setLoading(true);
317
+ setError(null);
318
+ try {
319
+ const response = await listUsersApi(options);
320
+ if (response.error) {
321
+ setError(response.error);
322
+ return [];
323
+ }
324
+ return response.data?.users || [];
325
+ } catch (err) {
326
+ const message = err instanceof Error ? err.message : "Failed to list users";
327
+ setError(message);
328
+ return [];
329
+ } finally {
330
+ setLoading(false);
331
+ }
332
+ }, [options]);
333
+ const getUser = useCallback2(
334
+ async (userId) => {
335
+ setLoading(true);
336
+ setError(null);
337
+ try {
338
+ const response = await getUserApi(userId, options);
339
+ if (response.error) {
340
+ setError(response.error);
341
+ return null;
342
+ }
343
+ return response.data?.user || null;
344
+ } catch (err) {
345
+ const message = err instanceof Error ? err.message : "Failed to get user";
346
+ setError(message);
347
+ return null;
348
+ } finally {
349
+ setLoading(false);
350
+ }
351
+ },
352
+ [options]
353
+ );
354
+ const getUserByEmail = useCallback2(
355
+ async (email) => {
356
+ setLoading(true);
357
+ setError(null);
358
+ try {
359
+ const response = await getUserByEmailApi(email, options);
360
+ if (response.error) {
361
+ setError(response.error);
362
+ return null;
363
+ }
364
+ return response.data?.user || null;
365
+ } catch (err) {
366
+ const message = err instanceof Error ? err.message : "Failed to get user by email";
367
+ setError(message);
368
+ return null;
369
+ } finally {
370
+ setLoading(false);
371
+ }
372
+ },
373
+ [options]
374
+ );
375
+ const createUser = useCallback2(
376
+ async (user) => {
377
+ setLoading(true);
378
+ setError(null);
379
+ try {
380
+ const response = await createUserApi(user, options);
381
+ if (response.error) {
382
+ setError(response.error);
383
+ return null;
384
+ }
385
+ return response.data?.user || null;
386
+ } catch (err) {
387
+ const message = err instanceof Error ? err.message : "Failed to create user";
388
+ setError(message);
389
+ return null;
390
+ } finally {
391
+ setLoading(false);
392
+ }
393
+ },
394
+ [options]
395
+ );
396
+ const updateUser = useCallback2(
397
+ async (userId, updates) => {
398
+ setLoading(true);
399
+ setError(null);
400
+ try {
401
+ const response = await updateUserApi(userId, updates, options);
402
+ if (response.error) {
403
+ setError(response.error);
404
+ return null;
405
+ }
406
+ return response.data?.user || null;
407
+ } catch (err) {
408
+ const message = err instanceof Error ? err.message : "Failed to update user";
409
+ setError(message);
410
+ return null;
411
+ } finally {
412
+ setLoading(false);
413
+ }
414
+ },
415
+ [options]
416
+ );
417
+ const deleteUser = useCallback2(
418
+ async (userId) => {
419
+ setLoading(true);
420
+ setError(null);
421
+ try {
422
+ const response = await deleteUserApi(userId, options);
423
+ if (response.error) {
424
+ setError(response.error);
425
+ return false;
426
+ }
427
+ return response.data?.success || false;
428
+ } catch (err) {
429
+ const message = err instanceof Error ? err.message : "Failed to delete user";
430
+ setError(message);
431
+ return false;
432
+ } finally {
433
+ setLoading(false);
434
+ }
435
+ },
436
+ [options]
437
+ );
438
+ const getUserSettings = useCallback2(
439
+ async (userId) => {
440
+ setLoading(true);
441
+ setError(null);
442
+ try {
443
+ const response = await getUserSettingsApi(userId, options);
444
+ if (response.error) {
445
+ setError(response.error);
446
+ return null;
447
+ }
448
+ return response.data || null;
449
+ } catch (err) {
450
+ const message = err instanceof Error ? err.message : "Failed to get user settings";
451
+ setError(message);
452
+ return null;
453
+ } finally {
454
+ setLoading(false);
455
+ }
456
+ },
457
+ [options]
458
+ );
459
+ const updateUserSettings = useCallback2(
460
+ async (userId, settings) => {
461
+ setLoading(true);
462
+ setError(null);
463
+ try {
464
+ const response = await updateUserSettingsApi(userId, settings, options);
465
+ if (response.error) {
466
+ setError(response.error);
467
+ return null;
468
+ }
469
+ return response.data || null;
470
+ } catch (err) {
471
+ const message = err instanceof Error ? err.message : "Failed to update user settings";
472
+ setError(message);
473
+ return null;
474
+ } finally {
475
+ setLoading(false);
476
+ }
477
+ },
478
+ [options]
479
+ );
480
+ return {
481
+ loading,
482
+ error,
483
+ listUsers,
484
+ getUser,
485
+ getUserByEmail,
486
+ createUser,
487
+ updateUser,
488
+ deleteUser,
489
+ getUserSettings,
490
+ updateUserSettings
491
+ };
492
+ }
493
+
494
+ // hooks/use-invites-admin.ts
495
+ import { useState as useState3, useCallback as useCallback3 } from "react";
496
+ function useInvitesAdmin(options) {
497
+ const [loading, setLoading] = useState3(false);
498
+ const [error, setError] = useState3(null);
499
+ const listInvites = useCallback3(async () => {
500
+ setLoading(true);
501
+ setError(null);
502
+ try {
503
+ const response = await listInvitesApi(options);
504
+ if (response.error) {
505
+ setError(response.error);
506
+ return [];
507
+ }
508
+ return response.data?.invites || [];
509
+ } catch (err) {
510
+ const message = err instanceof Error ? err.message : "Failed to list invites";
511
+ setError(message);
512
+ return [];
513
+ } finally {
514
+ setLoading(false);
515
+ }
516
+ }, [options]);
517
+ const getInvite = useCallback3(
518
+ async (inviteId) => {
519
+ setLoading(true);
520
+ setError(null);
521
+ try {
522
+ const response = await getInviteApi(inviteId, options);
523
+ if (response.error) {
524
+ setError(response.error);
525
+ return null;
526
+ }
527
+ return response.data?.invite || null;
528
+ } catch (err) {
529
+ const message = err instanceof Error ? err.message : "Failed to get invite";
530
+ setError(message);
531
+ return null;
532
+ } finally {
533
+ setLoading(false);
534
+ }
535
+ },
536
+ [options]
537
+ );
538
+ const sendInvite = useCallback3(
539
+ async (invite) => {
540
+ setLoading(true);
541
+ setError(null);
542
+ try {
543
+ const response = await sendInviteApi(invite, options);
544
+ if (response.error) {
545
+ setError(response.error);
546
+ return null;
547
+ }
548
+ return response.data?.invite || null;
549
+ } catch (err) {
550
+ const message = err instanceof Error ? err.message : "Failed to send invite";
551
+ setError(message);
552
+ return null;
553
+ } finally {
554
+ setLoading(false);
555
+ }
556
+ },
557
+ [options]
558
+ );
559
+ const sendInvites = useCallback3(
560
+ async (invites) => {
561
+ setLoading(true);
562
+ setError(null);
563
+ try {
564
+ const response = await sendInvitesApi(invites, options);
565
+ if (response.error) {
566
+ setError(response.error);
567
+ return null;
568
+ }
569
+ return response.data || null;
570
+ } catch (err) {
571
+ const message = err instanceof Error ? err.message : "Failed to send invites";
572
+ setError(message);
573
+ return null;
574
+ } finally {
575
+ setLoading(false);
576
+ }
577
+ },
578
+ [options]
579
+ );
580
+ const resendInvite = useCallback3(
581
+ async (inviteId) => {
582
+ setLoading(true);
583
+ setError(null);
584
+ try {
585
+ const response = await resendInviteApi(inviteId, options);
586
+ if (response.error) {
587
+ setError(response.error);
588
+ return null;
589
+ }
590
+ return response.data?.invite || null;
591
+ } catch (err) {
592
+ const message = err instanceof Error ? err.message : "Failed to resend invite";
593
+ setError(message);
594
+ return null;
595
+ } finally {
596
+ setLoading(false);
597
+ }
598
+ },
599
+ [options]
600
+ );
601
+ const revokeInvite = useCallback3(
602
+ async (inviteId) => {
603
+ setLoading(true);
604
+ setError(null);
605
+ try {
606
+ const response = await revokeInviteApi(inviteId, options);
607
+ if (response.error) {
608
+ setError(response.error);
609
+ return false;
610
+ }
611
+ return response.data?.success || false;
612
+ } catch (err) {
613
+ const message = err instanceof Error ? err.message : "Failed to revoke invite";
614
+ setError(message);
615
+ return false;
616
+ } finally {
617
+ setLoading(false);
618
+ }
619
+ },
620
+ [options]
621
+ );
622
+ const acceptInvite = useCallback3(
623
+ async (inviteId) => {
624
+ setLoading(true);
625
+ setError(null);
626
+ try {
627
+ const response = await acceptInviteApi(inviteId, options);
628
+ if (response.error) {
629
+ setError(response.error);
630
+ return null;
631
+ }
632
+ return response.data?.invite || null;
633
+ } catch (err) {
634
+ const message = err instanceof Error ? err.message : "Failed to accept invite";
635
+ setError(message);
636
+ return null;
637
+ } finally {
638
+ setLoading(false);
639
+ }
640
+ },
641
+ [options]
642
+ );
643
+ return {
644
+ loading,
645
+ error,
646
+ listInvites,
647
+ getInvite,
648
+ sendInvite,
649
+ sendInvites,
650
+ resendInvite,
651
+ revokeInvite,
652
+ acceptInvite
653
+ };
654
+ }
655
+
656
+ // hooks/use-org-settings.ts
657
+ import { useState as useState4, useCallback as useCallback4 } from "react";
658
+ function useOrgSettings(options) {
659
+ const [loading, setLoading] = useState4(false);
660
+ const [error, setError] = useState4(null);
661
+ const getSettings = useCallback4(async () => {
662
+ setLoading(true);
663
+ setError(null);
664
+ try {
665
+ const response = await getOrgSettingsApi(options);
666
+ if (response.error) {
667
+ setError(response.error);
668
+ return null;
669
+ }
670
+ return response.data?.settings || null;
671
+ } catch (err) {
672
+ const message = err instanceof Error ? err.message : "Failed to get organization settings";
673
+ setError(message);
674
+ return null;
675
+ } finally {
676
+ setLoading(false);
677
+ }
678
+ }, [options]);
679
+ const createSettings = useCallback4(
680
+ async (settings) => {
681
+ setLoading(true);
682
+ setError(null);
683
+ try {
684
+ const response = await createOrgSettingsApi(settings, options);
685
+ if (response.error) {
686
+ setError(response.error);
687
+ return null;
688
+ }
689
+ return response.data?.settings || null;
690
+ } catch (err) {
691
+ const message = err instanceof Error ? err.message : "Failed to create organization settings";
692
+ setError(message);
693
+ return null;
694
+ } finally {
695
+ setLoading(false);
696
+ }
697
+ },
698
+ [options]
699
+ );
700
+ const updateSettings = useCallback4(
701
+ async (settings) => {
702
+ setLoading(true);
703
+ setError(null);
704
+ try {
705
+ const response = await updateOrgSettingsApi(settings, options);
706
+ if (response.error) {
707
+ setError(response.error);
708
+ return null;
709
+ }
710
+ return response.data?.settings || null;
711
+ } catch (err) {
712
+ const message = err instanceof Error ? err.message : "Failed to update organization settings";
713
+ setError(message);
714
+ return null;
715
+ } finally {
716
+ setLoading(false);
717
+ }
718
+ },
719
+ [options]
720
+ );
721
+ return {
722
+ loading,
723
+ error,
724
+ getSettings,
725
+ createSettings,
726
+ updateSettings
727
+ };
728
+ }
729
+ export {
730
+ useInvitesAdmin,
731
+ useOrgAdmin,
732
+ useOrgSettings,
733
+ useUsersAdmin
734
+ };
735
+ //# sourceMappingURL=index.js.map