@elqnt/admin 2.2.1 → 2.3.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.
@@ -1,6 +1,6 @@
1
1
  import { ApiClientOptions } from '@elqnt/api-client';
2
- import { Org, OrgInfo, OrgSchemaTypeTS, CreateOrgWithSchemasResponse, User, UserSettingsResponse, UserSettings, NotificationPreferences, Invite, InviteInput, InvitesResult, AnalyticsSummary, ChatAnalytics, AgentAnalytics, UsageAnalytics, DailyAnalytics, AnalyticsEvent, DateFilter, GlobalAnalyticsSummary, OrgAnalytics, CreateOrgRequest, OrgArtifactTypeTS } from '../models/index.js';
3
- import { L as ListOrgsFilter, P as ProvisioningProgress, V as ValidationResult } from '../provisioning-Il9t2jnH.js';
2
+ import { b as Org, aL as OrgInfo, bw as User, bB as UserSettingsResponse, bA as UserSettings, ap as NotificationPreferences, a6 as Invite, a7 as InviteInput, ai as InvitesResult, Q as AnalyticsSummary, W as ChatAnalytics, I as AgentAnalytics, bu as UsageAnalytics, _ as DailyAnalytics, P as AnalyticsEvent, a0 as DateFilter, a3 as GlobalAnalyticsSummary, aI as OrgAnalytics } from '../analytics-CZ0LmSlf.js';
3
+ import { L as ListOrgsFilter } from '../orgs-BOVRgr8L.js';
4
4
  import { OrgSettings } from '@elqnt/agents/models';
5
5
  import '@elqnt/types';
6
6
 
@@ -27,8 +27,9 @@ declare function useOrgAdmin(options: UseOrgAdminOptions): {
27
27
  listOrgs: (filter?: ListOrgsFilter) => Promise<Org[]>;
28
28
  getOrg: (orgId: string) => Promise<Org | null>;
29
29
  getOrgInfo: (orgId: string) => Promise<OrgInfo | null>;
30
- createOrg: (org: Partial<Org>) => Promise<Org | null>;
31
- createOrgWithSchemas: (org: Partial<Org>, schemas: OrgSchemaTypeTS[]) => Promise<CreateOrgWithSchemasResponse | null>;
30
+ createOrg: (org: Partial<Org> & {
31
+ product?: string;
32
+ }) => Promise<Org | null>;
32
33
  updateOrg: (orgId: string, updates: Partial<Org>) => Promise<Org | null>;
33
34
  deleteOrg: (orgId: string) => Promise<boolean>;
34
35
  };
@@ -189,61 +190,4 @@ declare function useProductAnalytics(options: UseProductAnalyticsOptions): {
189
190
  */
190
191
  declare const useAnalyticsContext: typeof useProductAnalytics;
191
192
 
192
- type UseOrgProvisioningOptions = ApiClientOptions;
193
- interface ProvisioningState {
194
- status: "idle" | "creating" | "provisioning" | "completed" | "failed" | "partial";
195
- progress: ProvisioningProgress | null;
196
- org: Org | null;
197
- error: string | null;
198
- percentage: number;
199
- }
200
- /**
201
- * Hook for organization provisioning with real-time progress
202
- *
203
- * @example
204
- * ```tsx
205
- * const {
206
- * state,
207
- * createOrgWithProvisioning,
208
- * retryProvisioning,
209
- * cancelProvisioning,
210
- * } = useOrgProvisioning({
211
- * baseUrl: apiGatewayUrl,
212
- * orgId: selectedOrgId,
213
- * });
214
- *
215
- * // Create org and track progress
216
- * await createOrgWithProvisioning({
217
- * title: "Acme Corp",
218
- * product: "eloquent",
219
- * });
220
- *
221
- * // state.progress will update in real-time
222
- * console.log(state.percentage); // 0-100
223
- * ```
224
- */
225
- declare function useOrgProvisioning(options: UseOrgProvisioningOptions): {
226
- state: ProvisioningState;
227
- createOrgWithProvisioning: (request: CreateOrgRequest) => Promise<Org | null>;
228
- getProvisioningStatus: (orgId: string) => Promise<ProvisioningProgress | null>;
229
- retryProvisioning: (orgId: string, artifacts?: OrgArtifactTypeTS[]) => Promise<boolean>;
230
- validateProvisioning: (orgId: string) => Promise<ValidationResult | null>;
231
- cancelProvisioning: (orgId: string) => Promise<boolean>;
232
- cleanupOrg: (orgId: string) => Promise<boolean>;
233
- reset: () => void;
234
- isComplete: boolean;
235
- isFailed: boolean;
236
- isPartial: boolean;
237
- isProvisioning: boolean;
238
- failedArtifacts: {
239
- type: OrgArtifactTypeTS;
240
- status: string;
241
- critical: boolean;
242
- error?: string;
243
- duration?: number;
244
- estimatedDuration?: number;
245
- }[];
246
- hasCriticalFailures: boolean;
247
- };
248
-
249
- export { type ProductAnalyticsState, type ProvisioningState, type UseInvitesAdminOptions, type UseOrgAdminOptions, type UseOrgProvisioningOptions, type UseOrgSettingsOptions, type UseProductAnalyticsOptions, type UseUsersAdminOptions, useAnalyticsContext, useInvitesAdmin, useOrgAdmin, useOrgProvisioning, useOrgSettings, useProductAnalytics, useUsersAdmin };
193
+ export { type ProductAnalyticsState, type UseInvitesAdminOptions, type UseOrgAdminOptions, type UseOrgSettingsOptions, type UseProductAnalyticsOptions, type UseUsersAdminOptions, useAnalyticsContext, useInvitesAdmin, useOrgAdmin, useOrgSettings, useProductAnalytics, useUsersAdmin };
@@ -2,15 +2,15 @@
2
2
  import { useState, useCallback } from "react";
3
3
 
4
4
  // api/index.ts
5
- import { browserApiRequest as browserApiRequest6, clearGatewayTokenCache } from "@elqnt/api-client/browser";
5
+ import { browserApiRequest as browserApiRequest5, clearGatewayTokenCache } from "@elqnt/api-client/browser";
6
6
 
7
7
  // api/orgs.ts
8
8
  import { browserApiRequest } from "@elqnt/api-client/browser";
9
9
  async function listOrgsApi(filter, options) {
10
10
  const params = new URLSearchParams();
11
- if (filter?.product) params.set("product", filter.product);
12
11
  if (filter?.status) params.set("status", filter.status);
13
12
  if (filter?.type) params.set("type", filter.type);
13
+ if (filter?.product) params.set("product", filter.product);
14
14
  const queryString = params.toString();
15
15
  const url = queryString ? `/api/v1/admin/orgs?${queryString}` : "/api/v1/admin/orgs";
16
16
  return browserApiRequest(url, {
@@ -50,13 +50,6 @@ async function getOrgInfoApi(orgId, options) {
50
50
  ...options
51
51
  });
52
52
  }
53
- async function createOrgWithSchemasApi(org, schemas, options) {
54
- return browserApiRequest("/api/v1/admin/orgs/with-schemas", {
55
- method: "POST",
56
- body: { org, schemas },
57
- ...options
58
- });
59
- }
60
53
 
61
54
  // api/users.ts
62
55
  import { browserApiRequest as browserApiRequest2 } from "@elqnt/api-client/browser";
@@ -243,134 +236,67 @@ async function getGlobalOrgsAnalyticsApi(filter, options) {
243
236
  });
244
237
  }
245
238
 
246
- // api/provisioning.ts
247
- import { browserApiRequest as browserApiRequest5 } from "@elqnt/api-client/browser";
248
- async function createOrgWithProvisioningApi(request, options) {
249
- return browserApiRequest5("/api/v1/admin/provisioning/orgs", {
250
- method: "POST",
251
- body: request,
252
- ...options
253
- });
254
- }
255
- async function getProvisioningStatusApi(orgId, options) {
256
- return browserApiRequest5(`/api/v1/admin/orgs/${orgId}/provisioning`, {
257
- method: "GET",
258
- ...options
259
- });
260
- }
261
- async function retryProvisioningApi(orgId, request, options) {
262
- return browserApiRequest5(`/api/v1/admin/orgs/${orgId}/provisioning/retry`, {
263
- method: "POST",
264
- body: request || {},
265
- ...options
266
- });
267
- }
268
- async function validateProvisioningApi(orgId, options) {
269
- return browserApiRequest5(
270
- `/api/v1/admin/orgs/${orgId}/provisioning/validate`,
271
- {
272
- method: "POST",
273
- ...options
274
- }
275
- );
276
- }
277
- async function cancelProvisioningApi(orgId, options) {
278
- return browserApiRequest5(
279
- `/api/v1/admin/orgs/${orgId}/provisioning/cancel`,
280
- {
281
- method: "POST",
282
- ...options
283
- }
284
- );
239
+ // api/index.ts
240
+ function orgRowToSettings(orgId, row) {
241
+ return {
242
+ id: row?.id ?? "",
243
+ org_id: orgId,
244
+ title: row?.title ?? "",
245
+ description: row?.description ?? "",
246
+ logo_url: row?.logoUrl ?? "",
247
+ default_lang: row?.defaultLang ?? "en",
248
+ timezone: row?.timezone ?? "UTC",
249
+ additional_settings: row?.settings ?? {},
250
+ created_at: "",
251
+ updated_at: "",
252
+ created_by: "",
253
+ updated_by: ""
254
+ };
285
255
  }
286
- async function cleanupProvisioningApi(orgId, options) {
287
- return browserApiRequest5(`/api/v1/admin/orgs/${orgId}/provisioning`, {
288
- method: "DELETE",
289
- ...options
290
- });
256
+ function settingsToOrgRow(settings) {
257
+ return {
258
+ title: settings.title,
259
+ description: settings.description,
260
+ logoUrl: settings.logo_url,
261
+ defaultLang: settings.default_lang,
262
+ timezone: settings.timezone,
263
+ settings: settings.additional_settings
264
+ };
291
265
  }
292
- function streamProvisioningProgress(orgId, callbacks, options) {
293
- const url = new URL(
294
- `/api/v1/admin/orgs/${orgId}/provisioning/stream`,
295
- options.baseUrl
266
+ async function getOrgSettingsApi(options) {
267
+ const orgId = options.orgId ?? "";
268
+ const response = await browserApiRequest5(
269
+ `/api/v1/admin/orgs/${orgId}`,
270
+ { method: "GET", ...options }
296
271
  );
297
- if (options.token) {
298
- url.searchParams.set("token", options.token);
272
+ if (response.error) {
273
+ return { error: response.error, status: response.status };
299
274
  }
300
- const eventSource = new EventSource(url.toString());
301
- eventSource.addEventListener("connected", (event) => {
302
- try {
303
- const data = JSON.parse(event.data);
304
- callbacks.onConnected?.(data.orgId);
305
- } catch (e) {
306
- console.error("Failed to parse connected event", e);
307
- }
308
- });
309
- eventSource.addEventListener("progress", (event) => {
310
- try {
311
- const progress = JSON.parse(event.data);
312
- callbacks.onProgress?.(progress);
313
- } catch (e) {
314
- console.error("Failed to parse progress event", e);
275
+ return {
276
+ status: response.status,
277
+ data: {
278
+ success: true,
279
+ settings: orgRowToSettings(orgId, response.data?.organization)
315
280
  }
316
- });
317
- eventSource.addEventListener("done", () => {
318
- callbacks.onDone?.();
319
- eventSource.close();
320
- });
321
- eventSource.addEventListener("timeout", () => {
322
- callbacks.onTimeout?.();
323
- eventSource.close();
324
- });
325
- eventSource.onerror = (error) => {
326
- callbacks.onError?.(new Error("SSE connection error"));
327
- eventSource.close();
328
- };
329
- return () => {
330
- eventSource.close();
331
281
  };
332
282
  }
333
- function calculateProgressPercentage(progress) {
334
- if (progress.totalArtifacts === 0) return 0;
335
- return Math.round(
336
- progress.completedArtifacts / progress.totalArtifacts * 100
337
- );
338
- }
339
- function isProvisioningComplete(progress) {
340
- return progress.status === "completed" || progress.status === "failed" || progress.status === "partial";
341
- }
342
- function isProvisioningSuccessful(progress) {
343
- return progress.status === "completed";
344
- }
345
- function getFailedArtifacts(progress) {
346
- return progress.artifacts.filter((a) => a.status === "failed");
347
- }
348
- function hasCriticalFailures(progress) {
349
- return progress.artifacts.some(
350
- (a) => a.status === "failed" && a.critical
351
- );
352
- }
353
-
354
- // api/index.ts
355
- async function getOrgSettingsApi(options) {
356
- return browserApiRequest6("/api/v1/org/settings", {
357
- method: "GET",
358
- ...options
359
- });
360
- }
361
283
  async function createOrgSettingsApi(settings, options) {
362
- return browserApiRequest6("/api/v1/org/settings", {
363
- method: "POST",
364
- body: settings,
365
- ...options
366
- });
284
+ return updateOrgSettingsApi(settings, options);
367
285
  }
368
286
  async function updateOrgSettingsApi(settings, options) {
369
- return browserApiRequest6("/api/v1/org/settings", {
370
- method: "PUT",
371
- body: settings,
372
- ...options
373
- });
287
+ const orgId = options.orgId ?? "";
288
+ const response = await browserApiRequest5(
289
+ `/api/v1/admin/orgs/${orgId}`,
290
+ {
291
+ method: "PUT",
292
+ body: settingsToOrgRow(settings),
293
+ ...options
294
+ }
295
+ );
296
+ if (response.error) {
297
+ return { error: response.error, status: response.status };
298
+ }
299
+ return getOrgSettingsApi(options);
374
300
  }
375
301
 
376
302
  // hooks/use-org-admin.ts
@@ -458,27 +384,6 @@ function useOrgAdmin(options) {
458
384
  },
459
385
  [options]
460
386
  );
461
- const createOrgWithSchemas = useCallback(
462
- async (org, schemas) => {
463
- setLoading(true);
464
- setError(null);
465
- try {
466
- const response = await createOrgWithSchemasApi(org, schemas, options);
467
- if (response.error) {
468
- setError(response.error);
469
- return null;
470
- }
471
- return response.data || null;
472
- } catch (err) {
473
- const message = err instanceof Error ? err.message : "Failed to create organization with schemas";
474
- setError(message);
475
- return null;
476
- } finally {
477
- setLoading(false);
478
- }
479
- },
480
- [options]
481
- );
482
387
  const updateOrg = useCallback(
483
388
  async (orgId, updates) => {
484
389
  setLoading(true);
@@ -528,7 +433,6 @@ function useOrgAdmin(options) {
528
433
  getOrg,
529
434
  getOrgInfo,
530
435
  createOrg,
531
- createOrgWithSchemas,
532
436
  updateOrg,
533
437
  deleteOrg
534
438
  };
@@ -1203,289 +1107,10 @@ function useProductAnalytics(options) {
1203
1107
  };
1204
1108
  }
1205
1109
  var useAnalyticsContext = useProductAnalytics;
1206
-
1207
- // hooks/use-org-provisioning.ts
1208
- import { useState as useState6, useCallback as useCallback6, useEffect as useEffect2, useRef as useRef2 } from "react";
1209
- function useOrgProvisioning(options) {
1210
- const [state, setState] = useState6({
1211
- status: "idle",
1212
- progress: null,
1213
- org: null,
1214
- error: null,
1215
- percentage: 0
1216
- });
1217
- const cleanupRef = useRef2(null);
1218
- useEffect2(() => {
1219
- return () => {
1220
- if (cleanupRef.current) {
1221
- cleanupRef.current();
1222
- }
1223
- };
1224
- }, []);
1225
- const createOrgWithProvisioning = useCallback6(
1226
- async (request) => {
1227
- setState((prev) => ({
1228
- ...prev,
1229
- status: "creating",
1230
- error: null,
1231
- progress: null,
1232
- percentage: 0
1233
- }));
1234
- try {
1235
- const response = await createOrgWithProvisioningApi(request, options);
1236
- if (response.error) {
1237
- setState((prev) => ({
1238
- ...prev,
1239
- status: "failed",
1240
- error: response.error || "Failed to create organization"
1241
- }));
1242
- return null;
1243
- }
1244
- const org = response.data?.organization || response.data?.org;
1245
- if (!org) {
1246
- setState((prev) => ({
1247
- ...prev,
1248
- status: "failed",
1249
- error: "No organization returned"
1250
- }));
1251
- return null;
1252
- }
1253
- setState((prev) => ({
1254
- ...prev,
1255
- status: "provisioning",
1256
- org
1257
- }));
1258
- const cleanup = streamProvisioningProgress(
1259
- org.id,
1260
- {
1261
- onProgress: (progress) => {
1262
- const percentage = calculateProgressPercentage(progress);
1263
- const status = isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning";
1264
- setState((prev) => ({
1265
- ...prev,
1266
- status,
1267
- progress,
1268
- percentage,
1269
- error: progress.error || null
1270
- }));
1271
- },
1272
- onDone: () => {
1273
- cleanupRef.current = null;
1274
- },
1275
- onError: (error) => {
1276
- setState((prev) => ({
1277
- ...prev,
1278
- status: "failed",
1279
- error: error.message
1280
- }));
1281
- cleanupRef.current = null;
1282
- },
1283
- onTimeout: () => {
1284
- setState((prev) => ({
1285
- ...prev,
1286
- error: "Provisioning timed out"
1287
- }));
1288
- cleanupRef.current = null;
1289
- }
1290
- },
1291
- { baseUrl: options.baseUrl }
1292
- );
1293
- cleanupRef.current = cleanup;
1294
- return org;
1295
- } catch (err) {
1296
- const message = err instanceof Error ? err.message : "Failed to create organization";
1297
- setState((prev) => ({
1298
- ...prev,
1299
- status: "failed",
1300
- error: message
1301
- }));
1302
- return null;
1303
- }
1304
- },
1305
- [options]
1306
- );
1307
- const getProvisioningStatus = useCallback6(
1308
- async (orgId) => {
1309
- try {
1310
- const response = await getProvisioningStatusApi(orgId, options);
1311
- if (response.error) {
1312
- setState((prev) => ({ ...prev, error: response.error || null }));
1313
- return null;
1314
- }
1315
- const progress = response.data?.progress || null;
1316
- if (progress) {
1317
- setState((prev) => ({
1318
- ...prev,
1319
- progress,
1320
- percentage: calculateProgressPercentage(progress),
1321
- status: isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning"
1322
- }));
1323
- }
1324
- return progress;
1325
- } catch (err) {
1326
- const message = err instanceof Error ? err.message : "Failed to get provisioning status";
1327
- setState((prev) => ({ ...prev, error: message }));
1328
- return null;
1329
- }
1330
- },
1331
- [options]
1332
- );
1333
- const retryProvisioning = useCallback6(
1334
- async (orgId, artifacts) => {
1335
- setState((prev) => ({
1336
- ...prev,
1337
- status: "provisioning",
1338
- error: null
1339
- }));
1340
- try {
1341
- const request = artifacts ? { artifacts } : void 0;
1342
- const response = await retryProvisioningApi(orgId, request, options);
1343
- if (response.error) {
1344
- setState((prev) => ({
1345
- ...prev,
1346
- status: "failed",
1347
- error: response.error || "Failed to retry provisioning"
1348
- }));
1349
- return false;
1350
- }
1351
- const cleanup = streamProvisioningProgress(
1352
- orgId,
1353
- {
1354
- onProgress: (progress) => {
1355
- const percentage = calculateProgressPercentage(progress);
1356
- const status = isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning";
1357
- setState((prev) => ({
1358
- ...prev,
1359
- status,
1360
- progress,
1361
- percentage,
1362
- error: progress.error || null
1363
- }));
1364
- },
1365
- onDone: () => {
1366
- cleanupRef.current = null;
1367
- },
1368
- onError: (error) => {
1369
- setState((prev) => ({
1370
- ...prev,
1371
- status: "failed",
1372
- error: error.message
1373
- }));
1374
- cleanupRef.current = null;
1375
- }
1376
- },
1377
- { baseUrl: options.baseUrl }
1378
- );
1379
- cleanupRef.current = cleanup;
1380
- return true;
1381
- } catch (err) {
1382
- const message = err instanceof Error ? err.message : "Failed to retry provisioning";
1383
- setState((prev) => ({
1384
- ...prev,
1385
- status: "failed",
1386
- error: message
1387
- }));
1388
- return false;
1389
- }
1390
- },
1391
- [options]
1392
- );
1393
- const validateProvisioning = useCallback6(
1394
- async (orgId) => {
1395
- try {
1396
- const response = await validateProvisioningApi(orgId, options);
1397
- if (response.error) {
1398
- setState((prev) => ({ ...prev, error: response.error || null }));
1399
- return null;
1400
- }
1401
- return response.data || null;
1402
- } catch (err) {
1403
- const message = err instanceof Error ? err.message : "Failed to validate provisioning";
1404
- setState((prev) => ({ ...prev, error: message }));
1405
- return null;
1406
- }
1407
- },
1408
- [options]
1409
- );
1410
- const cancelProvisioning = useCallback6(
1411
- async (orgId) => {
1412
- try {
1413
- if (cleanupRef.current) {
1414
- cleanupRef.current();
1415
- cleanupRef.current = null;
1416
- }
1417
- const response = await cancelProvisioningApi(orgId, options);
1418
- if (response.error) {
1419
- setState((prev) => ({ ...prev, error: response.error || null }));
1420
- return false;
1421
- }
1422
- setState((prev) => ({
1423
- ...prev,
1424
- status: "failed",
1425
- error: "Provisioning cancelled"
1426
- }));
1427
- return true;
1428
- } catch (err) {
1429
- const message = err instanceof Error ? err.message : "Failed to cancel provisioning";
1430
- setState((prev) => ({ ...prev, error: message }));
1431
- return false;
1432
- }
1433
- },
1434
- [options]
1435
- );
1436
- const cleanupOrg = useCallback6(
1437
- async (orgId) => {
1438
- try {
1439
- const response = await cleanupProvisioningApi(orgId, options);
1440
- if (response.error) {
1441
- setState((prev) => ({ ...prev, error: response.error || null }));
1442
- return false;
1443
- }
1444
- return true;
1445
- } catch (err) {
1446
- const message = err instanceof Error ? err.message : "Failed to cleanup organization";
1447
- setState((prev) => ({ ...prev, error: message }));
1448
- return false;
1449
- }
1450
- },
1451
- [options]
1452
- );
1453
- const reset = useCallback6(() => {
1454
- if (cleanupRef.current) {
1455
- cleanupRef.current();
1456
- cleanupRef.current = null;
1457
- }
1458
- setState({
1459
- status: "idle",
1460
- progress: null,
1461
- org: null,
1462
- error: null,
1463
- percentage: 0
1464
- });
1465
- }, []);
1466
- return {
1467
- state,
1468
- createOrgWithProvisioning,
1469
- getProvisioningStatus,
1470
- retryProvisioning,
1471
- validateProvisioning,
1472
- cancelProvisioning,
1473
- cleanupOrg,
1474
- reset,
1475
- // Helper functions
1476
- isComplete: state.status === "completed",
1477
- isFailed: state.status === "failed",
1478
- isPartial: state.status === "partial",
1479
- isProvisioning: state.status === "provisioning" || state.status === "creating",
1480
- failedArtifacts: state.progress ? getFailedArtifacts(state.progress) : [],
1481
- hasCriticalFailures: state.progress ? hasCriticalFailures(state.progress) : false
1482
- };
1483
- }
1484
1110
  export {
1485
1111
  useAnalyticsContext,
1486
1112
  useInvitesAdmin,
1487
1113
  useOrgAdmin,
1488
- useOrgProvisioning,
1489
1114
  useOrgSettings,
1490
1115
  useProductAnalytics,
1491
1116
  useUsersAdmin