@elqnt/admin 2.2.0 → 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.
@@ -23,7 +23,6 @@ __export(hooks_exports, {
23
23
  useAnalyticsContext: () => useAnalyticsContext,
24
24
  useInvitesAdmin: () => useInvitesAdmin,
25
25
  useOrgAdmin: () => useOrgAdmin,
26
- useOrgProvisioning: () => useOrgProvisioning,
27
26
  useOrgSettings: () => useOrgSettings,
28
27
  useProductAnalytics: () => useProductAnalytics,
29
28
  useUsersAdmin: () => useUsersAdmin
@@ -34,15 +33,15 @@ module.exports = __toCommonJS(hooks_exports);
34
33
  var import_react = require("react");
35
34
 
36
35
  // api/index.ts
37
- var import_browser6 = require("@elqnt/api-client/browser");
36
+ var import_browser5 = require("@elqnt/api-client/browser");
38
37
 
39
38
  // api/orgs.ts
40
39
  var import_browser = require("@elqnt/api-client/browser");
41
40
  async function listOrgsApi(filter, options) {
42
41
  const params = new URLSearchParams();
43
- if (filter?.product) params.set("product", filter.product);
44
42
  if (filter?.status) params.set("status", filter.status);
45
43
  if (filter?.type) params.set("type", filter.type);
44
+ if (filter?.product) params.set("product", filter.product);
46
45
  const queryString = params.toString();
47
46
  const url = queryString ? `/api/v1/admin/orgs?${queryString}` : "/api/v1/admin/orgs";
48
47
  return (0, import_browser.browserApiRequest)(url, {
@@ -82,13 +81,6 @@ async function getOrgInfoApi(orgId, options) {
82
81
  ...options
83
82
  });
84
83
  }
85
- async function createOrgWithSchemasApi(org, schemas, options) {
86
- return (0, import_browser.browserApiRequest)("/api/v1/admin/orgs/with-schemas", {
87
- method: "POST",
88
- body: { org, schemas },
89
- ...options
90
- });
91
- }
92
84
 
93
85
  // api/users.ts
94
86
  var import_browser2 = require("@elqnt/api-client/browser");
@@ -275,134 +267,67 @@ async function getGlobalOrgsAnalyticsApi(filter, options) {
275
267
  });
276
268
  }
277
269
 
278
- // api/provisioning.ts
279
- var import_browser5 = require("@elqnt/api-client/browser");
280
- async function createOrgWithProvisioningApi(request, options) {
281
- return (0, import_browser5.browserApiRequest)("/api/v1/admin/provisioning/orgs", {
282
- method: "POST",
283
- body: request,
284
- ...options
285
- });
286
- }
287
- async function getProvisioningStatusApi(orgId, options) {
288
- return (0, import_browser5.browserApiRequest)(`/api/v1/admin/orgs/${orgId}/provisioning`, {
289
- method: "GET",
290
- ...options
291
- });
292
- }
293
- async function retryProvisioningApi(orgId, request, options) {
294
- return (0, import_browser5.browserApiRequest)(`/api/v1/admin/orgs/${orgId}/provisioning/retry`, {
295
- method: "POST",
296
- body: request || {},
297
- ...options
298
- });
299
- }
300
- async function validateProvisioningApi(orgId, options) {
301
- return (0, import_browser5.browserApiRequest)(
302
- `/api/v1/admin/orgs/${orgId}/provisioning/validate`,
303
- {
304
- method: "POST",
305
- ...options
306
- }
307
- );
308
- }
309
- async function cancelProvisioningApi(orgId, options) {
310
- return (0, import_browser5.browserApiRequest)(
311
- `/api/v1/admin/orgs/${orgId}/provisioning/cancel`,
312
- {
313
- method: "POST",
314
- ...options
315
- }
316
- );
270
+ // api/index.ts
271
+ function orgRowToSettings(orgId, row) {
272
+ return {
273
+ id: row?.id ?? "",
274
+ org_id: orgId,
275
+ title: row?.title ?? "",
276
+ description: row?.description ?? "",
277
+ logo_url: row?.logoUrl ?? "",
278
+ default_lang: row?.defaultLang ?? "en",
279
+ timezone: row?.timezone ?? "UTC",
280
+ additional_settings: row?.settings ?? {},
281
+ created_at: "",
282
+ updated_at: "",
283
+ created_by: "",
284
+ updated_by: ""
285
+ };
317
286
  }
318
- async function cleanupProvisioningApi(orgId, options) {
319
- return (0, import_browser5.browserApiRequest)(`/api/v1/admin/orgs/${orgId}/provisioning`, {
320
- method: "DELETE",
321
- ...options
322
- });
287
+ function settingsToOrgRow(settings) {
288
+ return {
289
+ title: settings.title,
290
+ description: settings.description,
291
+ logoUrl: settings.logo_url,
292
+ defaultLang: settings.default_lang,
293
+ timezone: settings.timezone,
294
+ settings: settings.additional_settings
295
+ };
323
296
  }
324
- function streamProvisioningProgress(orgId, callbacks, options) {
325
- const url = new URL(
326
- `/api/v1/admin/orgs/${orgId}/provisioning/stream`,
327
- options.baseUrl
297
+ async function getOrgSettingsApi(options) {
298
+ const orgId = options.orgId ?? "";
299
+ const response = await (0, import_browser5.browserApiRequest)(
300
+ `/api/v1/admin/orgs/${orgId}`,
301
+ { method: "GET", ...options }
328
302
  );
329
- if (options.token) {
330
- url.searchParams.set("token", options.token);
303
+ if (response.error) {
304
+ return { error: response.error, status: response.status };
331
305
  }
332
- const eventSource = new EventSource(url.toString());
333
- eventSource.addEventListener("connected", (event) => {
334
- try {
335
- const data = JSON.parse(event.data);
336
- callbacks.onConnected?.(data.orgId);
337
- } catch (e) {
338
- console.error("Failed to parse connected event", e);
339
- }
340
- });
341
- eventSource.addEventListener("progress", (event) => {
342
- try {
343
- const progress = JSON.parse(event.data);
344
- callbacks.onProgress?.(progress);
345
- } catch (e) {
346
- console.error("Failed to parse progress event", e);
306
+ return {
307
+ status: response.status,
308
+ data: {
309
+ success: true,
310
+ settings: orgRowToSettings(orgId, response.data?.organization)
347
311
  }
348
- });
349
- eventSource.addEventListener("done", () => {
350
- callbacks.onDone?.();
351
- eventSource.close();
352
- });
353
- eventSource.addEventListener("timeout", () => {
354
- callbacks.onTimeout?.();
355
- eventSource.close();
356
- });
357
- eventSource.onerror = (error) => {
358
- callbacks.onError?.(new Error("SSE connection error"));
359
- eventSource.close();
360
312
  };
361
- return () => {
362
- eventSource.close();
363
- };
364
- }
365
- function calculateProgressPercentage(progress) {
366
- if (progress.totalArtifacts === 0) return 0;
367
- return Math.round(
368
- progress.completedArtifacts / progress.totalArtifacts * 100
369
- );
370
- }
371
- function isProvisioningComplete(progress) {
372
- return progress.status === "completed" || progress.status === "failed" || progress.status === "partial";
373
- }
374
- function isProvisioningSuccessful(progress) {
375
- return progress.status === "completed";
376
- }
377
- function getFailedArtifacts(progress) {
378
- return progress.artifacts.filter((a) => a.status === "failed");
379
- }
380
- function hasCriticalFailures(progress) {
381
- return progress.artifacts.some(
382
- (a) => a.status === "failed" && a.critical
383
- );
384
- }
385
-
386
- // api/index.ts
387
- async function getOrgSettingsApi(options) {
388
- return (0, import_browser6.browserApiRequest)("/api/v1/org/settings", {
389
- method: "GET",
390
- ...options
391
- });
392
313
  }
393
314
  async function createOrgSettingsApi(settings, options) {
394
- return (0, import_browser6.browserApiRequest)("/api/v1/org/settings", {
395
- method: "POST",
396
- body: settings,
397
- ...options
398
- });
315
+ return updateOrgSettingsApi(settings, options);
399
316
  }
400
317
  async function updateOrgSettingsApi(settings, options) {
401
- return (0, import_browser6.browserApiRequest)("/api/v1/org/settings", {
402
- method: "PUT",
403
- body: settings,
404
- ...options
405
- });
318
+ const orgId = options.orgId ?? "";
319
+ const response = await (0, import_browser5.browserApiRequest)(
320
+ `/api/v1/admin/orgs/${orgId}`,
321
+ {
322
+ method: "PUT",
323
+ body: settingsToOrgRow(settings),
324
+ ...options
325
+ }
326
+ );
327
+ if (response.error) {
328
+ return { error: response.error, status: response.status };
329
+ }
330
+ return getOrgSettingsApi(options);
406
331
  }
407
332
 
408
333
  // hooks/use-org-admin.ts
@@ -490,27 +415,6 @@ function useOrgAdmin(options) {
490
415
  },
491
416
  [options]
492
417
  );
493
- const createOrgWithSchemas = (0, import_react.useCallback)(
494
- async (org, schemas) => {
495
- setLoading(true);
496
- setError(null);
497
- try {
498
- const response = await createOrgWithSchemasApi(org, schemas, options);
499
- if (response.error) {
500
- setError(response.error);
501
- return null;
502
- }
503
- return response.data || null;
504
- } catch (err) {
505
- const message = err instanceof Error ? err.message : "Failed to create organization with schemas";
506
- setError(message);
507
- return null;
508
- } finally {
509
- setLoading(false);
510
- }
511
- },
512
- [options]
513
- );
514
418
  const updateOrg = (0, import_react.useCallback)(
515
419
  async (orgId, updates) => {
516
420
  setLoading(true);
@@ -560,7 +464,6 @@ function useOrgAdmin(options) {
560
464
  getOrg,
561
465
  getOrgInfo,
562
466
  createOrg,
563
- createOrgWithSchemas,
564
467
  updateOrg,
565
468
  deleteOrg
566
469
  };
@@ -1235,290 +1138,11 @@ function useProductAnalytics(options) {
1235
1138
  };
1236
1139
  }
1237
1140
  var useAnalyticsContext = useProductAnalytics;
1238
-
1239
- // hooks/use-org-provisioning.ts
1240
- var import_react6 = require("react");
1241
- function useOrgProvisioning(options) {
1242
- const [state, setState] = (0, import_react6.useState)({
1243
- status: "idle",
1244
- progress: null,
1245
- org: null,
1246
- error: null,
1247
- percentage: 0
1248
- });
1249
- const cleanupRef = (0, import_react6.useRef)(null);
1250
- (0, import_react6.useEffect)(() => {
1251
- return () => {
1252
- if (cleanupRef.current) {
1253
- cleanupRef.current();
1254
- }
1255
- };
1256
- }, []);
1257
- const createOrgWithProvisioning = (0, import_react6.useCallback)(
1258
- async (request) => {
1259
- setState((prev) => ({
1260
- ...prev,
1261
- status: "creating",
1262
- error: null,
1263
- progress: null,
1264
- percentage: 0
1265
- }));
1266
- try {
1267
- const response = await createOrgWithProvisioningApi(request, options);
1268
- if (response.error) {
1269
- setState((prev) => ({
1270
- ...prev,
1271
- status: "failed",
1272
- error: response.error || "Failed to create organization"
1273
- }));
1274
- return null;
1275
- }
1276
- const org = response.data?.organization || response.data?.org;
1277
- if (!org) {
1278
- setState((prev) => ({
1279
- ...prev,
1280
- status: "failed",
1281
- error: "No organization returned"
1282
- }));
1283
- return null;
1284
- }
1285
- setState((prev) => ({
1286
- ...prev,
1287
- status: "provisioning",
1288
- org
1289
- }));
1290
- const cleanup = streamProvisioningProgress(
1291
- org.id,
1292
- {
1293
- onProgress: (progress) => {
1294
- const percentage = calculateProgressPercentage(progress);
1295
- const status = isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning";
1296
- setState((prev) => ({
1297
- ...prev,
1298
- status,
1299
- progress,
1300
- percentage,
1301
- error: progress.error || null
1302
- }));
1303
- },
1304
- onDone: () => {
1305
- cleanupRef.current = null;
1306
- },
1307
- onError: (error) => {
1308
- setState((prev) => ({
1309
- ...prev,
1310
- status: "failed",
1311
- error: error.message
1312
- }));
1313
- cleanupRef.current = null;
1314
- },
1315
- onTimeout: () => {
1316
- setState((prev) => ({
1317
- ...prev,
1318
- error: "Provisioning timed out"
1319
- }));
1320
- cleanupRef.current = null;
1321
- }
1322
- },
1323
- { baseUrl: options.baseUrl }
1324
- );
1325
- cleanupRef.current = cleanup;
1326
- return org;
1327
- } catch (err) {
1328
- const message = err instanceof Error ? err.message : "Failed to create organization";
1329
- setState((prev) => ({
1330
- ...prev,
1331
- status: "failed",
1332
- error: message
1333
- }));
1334
- return null;
1335
- }
1336
- },
1337
- [options]
1338
- );
1339
- const getProvisioningStatus = (0, import_react6.useCallback)(
1340
- async (orgId) => {
1341
- try {
1342
- const response = await getProvisioningStatusApi(orgId, options);
1343
- if (response.error) {
1344
- setState((prev) => ({ ...prev, error: response.error || null }));
1345
- return null;
1346
- }
1347
- const progress = response.data?.progress || null;
1348
- if (progress) {
1349
- setState((prev) => ({
1350
- ...prev,
1351
- progress,
1352
- percentage: calculateProgressPercentage(progress),
1353
- status: isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning"
1354
- }));
1355
- }
1356
- return progress;
1357
- } catch (err) {
1358
- const message = err instanceof Error ? err.message : "Failed to get provisioning status";
1359
- setState((prev) => ({ ...prev, error: message }));
1360
- return null;
1361
- }
1362
- },
1363
- [options]
1364
- );
1365
- const retryProvisioning = (0, import_react6.useCallback)(
1366
- async (orgId, artifacts) => {
1367
- setState((prev) => ({
1368
- ...prev,
1369
- status: "provisioning",
1370
- error: null
1371
- }));
1372
- try {
1373
- const request = artifacts ? { artifacts } : void 0;
1374
- const response = await retryProvisioningApi(orgId, request, options);
1375
- if (response.error) {
1376
- setState((prev) => ({
1377
- ...prev,
1378
- status: "failed",
1379
- error: response.error || "Failed to retry provisioning"
1380
- }));
1381
- return false;
1382
- }
1383
- const cleanup = streamProvisioningProgress(
1384
- orgId,
1385
- {
1386
- onProgress: (progress) => {
1387
- const percentage = calculateProgressPercentage(progress);
1388
- const status = isProvisioningComplete(progress) ? isProvisioningSuccessful(progress) ? "completed" : progress.status === "partial" ? "partial" : "failed" : "provisioning";
1389
- setState((prev) => ({
1390
- ...prev,
1391
- status,
1392
- progress,
1393
- percentage,
1394
- error: progress.error || null
1395
- }));
1396
- },
1397
- onDone: () => {
1398
- cleanupRef.current = null;
1399
- },
1400
- onError: (error) => {
1401
- setState((prev) => ({
1402
- ...prev,
1403
- status: "failed",
1404
- error: error.message
1405
- }));
1406
- cleanupRef.current = null;
1407
- }
1408
- },
1409
- { baseUrl: options.baseUrl }
1410
- );
1411
- cleanupRef.current = cleanup;
1412
- return true;
1413
- } catch (err) {
1414
- const message = err instanceof Error ? err.message : "Failed to retry provisioning";
1415
- setState((prev) => ({
1416
- ...prev,
1417
- status: "failed",
1418
- error: message
1419
- }));
1420
- return false;
1421
- }
1422
- },
1423
- [options]
1424
- );
1425
- const validateProvisioning = (0, import_react6.useCallback)(
1426
- async (orgId) => {
1427
- try {
1428
- const response = await validateProvisioningApi(orgId, options);
1429
- if (response.error) {
1430
- setState((prev) => ({ ...prev, error: response.error || null }));
1431
- return null;
1432
- }
1433
- return response.data || null;
1434
- } catch (err) {
1435
- const message = err instanceof Error ? err.message : "Failed to validate provisioning";
1436
- setState((prev) => ({ ...prev, error: message }));
1437
- return null;
1438
- }
1439
- },
1440
- [options]
1441
- );
1442
- const cancelProvisioning = (0, import_react6.useCallback)(
1443
- async (orgId) => {
1444
- try {
1445
- if (cleanupRef.current) {
1446
- cleanupRef.current();
1447
- cleanupRef.current = null;
1448
- }
1449
- const response = await cancelProvisioningApi(orgId, options);
1450
- if (response.error) {
1451
- setState((prev) => ({ ...prev, error: response.error || null }));
1452
- return false;
1453
- }
1454
- setState((prev) => ({
1455
- ...prev,
1456
- status: "failed",
1457
- error: "Provisioning cancelled"
1458
- }));
1459
- return true;
1460
- } catch (err) {
1461
- const message = err instanceof Error ? err.message : "Failed to cancel provisioning";
1462
- setState((prev) => ({ ...prev, error: message }));
1463
- return false;
1464
- }
1465
- },
1466
- [options]
1467
- );
1468
- const cleanupOrg = (0, import_react6.useCallback)(
1469
- async (orgId) => {
1470
- try {
1471
- const response = await cleanupProvisioningApi(orgId, options);
1472
- if (response.error) {
1473
- setState((prev) => ({ ...prev, error: response.error || null }));
1474
- return false;
1475
- }
1476
- return true;
1477
- } catch (err) {
1478
- const message = err instanceof Error ? err.message : "Failed to cleanup organization";
1479
- setState((prev) => ({ ...prev, error: message }));
1480
- return false;
1481
- }
1482
- },
1483
- [options]
1484
- );
1485
- const reset = (0, import_react6.useCallback)(() => {
1486
- if (cleanupRef.current) {
1487
- cleanupRef.current();
1488
- cleanupRef.current = null;
1489
- }
1490
- setState({
1491
- status: "idle",
1492
- progress: null,
1493
- org: null,
1494
- error: null,
1495
- percentage: 0
1496
- });
1497
- }, []);
1498
- return {
1499
- state,
1500
- createOrgWithProvisioning,
1501
- getProvisioningStatus,
1502
- retryProvisioning,
1503
- validateProvisioning,
1504
- cancelProvisioning,
1505
- cleanupOrg,
1506
- reset,
1507
- // Helper functions
1508
- isComplete: state.status === "completed",
1509
- isFailed: state.status === "failed",
1510
- isPartial: state.status === "partial",
1511
- isProvisioning: state.status === "provisioning" || state.status === "creating",
1512
- failedArtifacts: state.progress ? getFailedArtifacts(state.progress) : [],
1513
- hasCriticalFailures: state.progress ? hasCriticalFailures(state.progress) : false
1514
- };
1515
- }
1516
1141
  // Annotate the CommonJS export names for ESM import in node:
1517
1142
  0 && (module.exports = {
1518
1143
  useAnalyticsContext,
1519
1144
  useInvitesAdmin,
1520
1145
  useOrgAdmin,
1521
- useOrgProvisioning,
1522
1146
  useOrgSettings,
1523
1147
  useProductAnalytics,
1524
1148
  useUsersAdmin