@elqnt/admin 2.3.0 → 2.3.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.
@@ -20,11 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // hooks/index.ts
21
21
  var hooks_exports = {};
22
22
  __export(hooks_exports, {
23
- useAnalyticsContext: () => useAnalyticsContext,
24
- useInvitesAdmin: () => useInvitesAdmin,
25
23
  useOrgAdmin: () => useOrgAdmin,
26
- useOrgSettings: () => useOrgSettings,
27
- useProductAnalytics: () => useProductAnalytics,
28
24
  useUsersAdmin: () => useUsersAdmin
29
25
  });
30
26
  module.exports = __toCommonJS(hooks_exports);
@@ -33,7 +29,7 @@ module.exports = __toCommonJS(hooks_exports);
33
29
  var import_react = require("react");
34
30
 
35
31
  // api/index.ts
36
- var import_browser5 = require("@elqnt/api-client/browser");
32
+ var import_browser4 = require("@elqnt/api-client/browser");
37
33
 
38
34
  // api/orgs.ts
39
35
  var import_browser = require("@elqnt/api-client/browser");
@@ -189,84 +185,6 @@ async function acceptInviteApi(inviteId, options) {
189
185
  });
190
186
  }
191
187
 
192
- // api/analytics.ts
193
- var import_browser4 = require("@elqnt/api-client/browser");
194
- function buildDateFilterParams(filter) {
195
- if (!filter) return "";
196
- const params = new URLSearchParams();
197
- if (filter.from) params.set("from", filter.from);
198
- if (filter.to) params.set("to", filter.to);
199
- const queryString = params.toString();
200
- return queryString ? `?${queryString}` : "";
201
- }
202
- async function getAnalyticsSummaryApi(filter, options) {
203
- const queryString = buildDateFilterParams(filter);
204
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/summary${queryString}`, {
205
- method: "GET",
206
- ...options
207
- });
208
- }
209
- async function getChatsAnalyticsApi(filter, agentId, options) {
210
- const params = new URLSearchParams();
211
- if (filter?.from) params.set("from", filter.from);
212
- if (filter?.to) params.set("to", filter.to);
213
- if (agentId) params.set("agent_id", agentId);
214
- const queryString = params.toString();
215
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/chats${queryString ? `?${queryString}` : ""}`, {
216
- method: "GET",
217
- ...options
218
- });
219
- }
220
- async function getAgentsAnalyticsApi(filter, options) {
221
- const queryString = buildDateFilterParams(filter);
222
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/agents${queryString}`, {
223
- method: "GET",
224
- ...options
225
- });
226
- }
227
- async function getUsageAnalyticsApi(filter, options) {
228
- const queryString = buildDateFilterParams(filter);
229
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/usage${queryString}`, {
230
- method: "GET",
231
- ...options
232
- });
233
- }
234
- async function getDailyAnalyticsApi(filter, options) {
235
- const queryString = buildDateFilterParams(filter);
236
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/daily${queryString}`, {
237
- method: "GET",
238
- ...options
239
- });
240
- }
241
- async function getAnalyticsEventsApi(filter, options) {
242
- const queryString = buildDateFilterParams(filter);
243
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/events${queryString}`, {
244
- method: "GET",
245
- ...options
246
- });
247
- }
248
- async function logAnalyticsEventApi(event, options) {
249
- return (0, import_browser4.browserApiRequest)("/api/v1/analytics/events", {
250
- method: "POST",
251
- body: event,
252
- ...options
253
- });
254
- }
255
- async function getGlobalSummaryApi(filter, options) {
256
- const queryString = buildDateFilterParams(filter);
257
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/global/summary${queryString}`, {
258
- method: "GET",
259
- ...options
260
- });
261
- }
262
- async function getGlobalOrgsAnalyticsApi(filter, options) {
263
- const queryString = buildDateFilterParams(filter);
264
- return (0, import_browser4.browserApiRequest)(`/api/v1/analytics/global/orgs${queryString}`, {
265
- method: "GET",
266
- ...options
267
- });
268
- }
269
-
270
188
  // api/index.ts
271
189
  function orgRowToSettings(orgId, row) {
272
190
  return {
@@ -296,7 +214,7 @@ function settingsToOrgRow(settings) {
296
214
  }
297
215
  async function getOrgSettingsApi(options) {
298
216
  const orgId = options.orgId ?? "";
299
- const response = await (0, import_browser5.browserApiRequest)(
217
+ const response = await (0, import_browser4.browserApiRequest)(
300
218
  `/api/v1/admin/orgs/${orgId}`,
301
219
  { method: "GET", ...options }
302
220
  );
@@ -316,7 +234,7 @@ async function createOrgSettingsApi(settings, options) {
316
234
  }
317
235
  async function updateOrgSettingsApi(settings, options) {
318
236
  const orgId = options.orgId ?? "";
319
- const response = await (0, import_browser5.browserApiRequest)(
237
+ const response = await (0, import_browser4.browserApiRequest)(
320
238
  `/api/v1/admin/orgs/${orgId}`,
321
239
  {
322
240
  method: "PUT",
@@ -457,6 +375,66 @@ function useOrgAdmin(options) {
457
375
  },
458
376
  [options]
459
377
  );
378
+ const getSettings = (0, import_react.useCallback)(async () => {
379
+ setLoading(true);
380
+ setError(null);
381
+ try {
382
+ const response = await getOrgSettingsApi(options);
383
+ if (response.error) {
384
+ setError(response.error);
385
+ return null;
386
+ }
387
+ return response.data?.settings || null;
388
+ } catch (err) {
389
+ const message = err instanceof Error ? err.message : "Failed to get organization settings";
390
+ setError(message);
391
+ return null;
392
+ } finally {
393
+ setLoading(false);
394
+ }
395
+ }, [options]);
396
+ const createSettings = (0, import_react.useCallback)(
397
+ async (settings) => {
398
+ setLoading(true);
399
+ setError(null);
400
+ try {
401
+ const response = await createOrgSettingsApi(settings, options);
402
+ if (response.error) {
403
+ setError(response.error);
404
+ return null;
405
+ }
406
+ return response.data?.settings || null;
407
+ } catch (err) {
408
+ const message = err instanceof Error ? err.message : "Failed to create organization settings";
409
+ setError(message);
410
+ return null;
411
+ } finally {
412
+ setLoading(false);
413
+ }
414
+ },
415
+ [options]
416
+ );
417
+ const updateSettings = (0, import_react.useCallback)(
418
+ async (settings) => {
419
+ setLoading(true);
420
+ setError(null);
421
+ try {
422
+ const response = await updateOrgSettingsApi(settings, options);
423
+ if (response.error) {
424
+ setError(response.error);
425
+ return null;
426
+ }
427
+ return response.data?.settings || null;
428
+ } catch (err) {
429
+ const message = err instanceof Error ? err.message : "Failed to update organization settings";
430
+ setError(message);
431
+ return null;
432
+ } finally {
433
+ setLoading(false);
434
+ }
435
+ },
436
+ [options]
437
+ );
460
438
  return {
461
439
  loading,
462
440
  error,
@@ -465,7 +443,11 @@ function useOrgAdmin(options) {
465
443
  getOrgInfo,
466
444
  createOrg,
467
445
  updateOrg,
468
- deleteOrg
446
+ deleteOrg,
447
+ // Org settings
448
+ getSettings,
449
+ createSettings,
450
+ updateSettings
469
451
  };
470
452
  }
471
453
 
@@ -660,27 +642,7 @@ function useUsersAdmin(options) {
660
642
  },
661
643
  [options]
662
644
  );
663
- return {
664
- loading,
665
- error,
666
- listUsers,
667
- getUser,
668
- getUserByEmail,
669
- getUserByPhone,
670
- createUser,
671
- updateUser,
672
- deleteUser,
673
- getUserSettings,
674
- updateUserSettings
675
- };
676
- }
677
-
678
- // hooks/use-invites-admin.ts
679
- var import_react3 = require("react");
680
- function useInvitesAdmin(options) {
681
- const [loading, setLoading] = (0, import_react3.useState)(false);
682
- const [error, setError] = (0, import_react3.useState)(null);
683
- const listInvites = (0, import_react3.useCallback)(async () => {
645
+ const listInvites = (0, import_react2.useCallback)(async () => {
684
646
  setLoading(true);
685
647
  setError(null);
686
648
  try {
@@ -698,7 +660,7 @@ function useInvitesAdmin(options) {
698
660
  setLoading(false);
699
661
  }
700
662
  }, [options]);
701
- const getInvite = (0, import_react3.useCallback)(
663
+ const getInvite = (0, import_react2.useCallback)(
702
664
  async (inviteId) => {
703
665
  setLoading(true);
704
666
  setError(null);
@@ -719,7 +681,7 @@ function useInvitesAdmin(options) {
719
681
  },
720
682
  [options]
721
683
  );
722
- const sendInvite = (0, import_react3.useCallback)(
684
+ const sendInvite = (0, import_react2.useCallback)(
723
685
  async (invite) => {
724
686
  setLoading(true);
725
687
  setError(null);
@@ -740,7 +702,7 @@ function useInvitesAdmin(options) {
740
702
  },
741
703
  [options]
742
704
  );
743
- const sendInvites = (0, import_react3.useCallback)(
705
+ const sendInvites = (0, import_react2.useCallback)(
744
706
  async (invites) => {
745
707
  setLoading(true);
746
708
  setError(null);
@@ -761,7 +723,7 @@ function useInvitesAdmin(options) {
761
723
  },
762
724
  [options]
763
725
  );
764
- const resendInvite = (0, import_react3.useCallback)(
726
+ const resendInvite = (0, import_react2.useCallback)(
765
727
  async (inviteId) => {
766
728
  setLoading(true);
767
729
  setError(null);
@@ -782,7 +744,7 @@ function useInvitesAdmin(options) {
782
744
  },
783
745
  [options]
784
746
  );
785
- const revokeInvite = (0, import_react3.useCallback)(
747
+ const revokeInvite = (0, import_react2.useCallback)(
786
748
  async (inviteId) => {
787
749
  setLoading(true);
788
750
  setError(null);
@@ -803,7 +765,7 @@ function useInvitesAdmin(options) {
803
765
  },
804
766
  [options]
805
767
  );
806
- const acceptInvite = (0, import_react3.useCallback)(
768
+ const acceptInvite = (0, import_react2.useCallback)(
807
769
  async (inviteId) => {
808
770
  setLoading(true);
809
771
  setError(null);
@@ -827,6 +789,16 @@ function useInvitesAdmin(options) {
827
789
  return {
828
790
  loading,
829
791
  error,
792
+ listUsers,
793
+ getUser,
794
+ getUserByEmail,
795
+ getUserByPhone,
796
+ createUser,
797
+ updateUser,
798
+ deleteUser,
799
+ getUserSettings,
800
+ updateUserSettings,
801
+ // Invitations
830
802
  listInvites,
831
803
  getInvite,
832
804
  sendInvite,
@@ -836,315 +808,9 @@ function useInvitesAdmin(options) {
836
808
  acceptInvite
837
809
  };
838
810
  }
839
-
840
- // hooks/use-org-settings.ts
841
- var import_react4 = require("react");
842
- function useOrgSettings(options) {
843
- const [loading, setLoading] = (0, import_react4.useState)(false);
844
- const [error, setError] = (0, import_react4.useState)(null);
845
- const getSettings = (0, import_react4.useCallback)(async () => {
846
- setLoading(true);
847
- setError(null);
848
- try {
849
- const response = await getOrgSettingsApi(options);
850
- if (response.error) {
851
- setError(response.error);
852
- return null;
853
- }
854
- return response.data?.settings || null;
855
- } catch (err) {
856
- const message = err instanceof Error ? err.message : "Failed to get organization settings";
857
- setError(message);
858
- return null;
859
- } finally {
860
- setLoading(false);
861
- }
862
- }, [options]);
863
- const createSettings = (0, import_react4.useCallback)(
864
- async (settings) => {
865
- setLoading(true);
866
- setError(null);
867
- try {
868
- const response = await createOrgSettingsApi(settings, options);
869
- if (response.error) {
870
- setError(response.error);
871
- return null;
872
- }
873
- return response.data?.settings || null;
874
- } catch (err) {
875
- const message = err instanceof Error ? err.message : "Failed to create organization settings";
876
- setError(message);
877
- return null;
878
- } finally {
879
- setLoading(false);
880
- }
881
- },
882
- [options]
883
- );
884
- const updateSettings = (0, import_react4.useCallback)(
885
- async (settings) => {
886
- setLoading(true);
887
- setError(null);
888
- try {
889
- const response = await updateOrgSettingsApi(settings, options);
890
- if (response.error) {
891
- setError(response.error);
892
- return null;
893
- }
894
- return response.data?.settings || null;
895
- } catch (err) {
896
- const message = err instanceof Error ? err.message : "Failed to update organization settings";
897
- setError(message);
898
- return null;
899
- } finally {
900
- setLoading(false);
901
- }
902
- },
903
- [options]
904
- );
905
- return {
906
- loading,
907
- error,
908
- getSettings,
909
- createSettings,
910
- updateSettings
911
- };
912
- }
913
-
914
- // hooks/use-product-analytics.ts
915
- var import_react5 = require("react");
916
- function useProductAnalytics(options) {
917
- const [state, setState] = (0, import_react5.useState)({
918
- summary: null,
919
- chats: [],
920
- agents: [],
921
- usage: [],
922
- daily: [],
923
- events: [],
924
- loading: false,
925
- error: null
926
- });
927
- const sessionIdRef = (0, import_react5.useRef)("");
928
- (0, import_react5.useEffect)(() => {
929
- if (typeof window !== "undefined") {
930
- let sessionId = sessionStorage.getItem("analytics_session_id");
931
- if (!sessionId) {
932
- sessionId = crypto.randomUUID();
933
- sessionStorage.setItem("analytics_session_id", sessionId);
934
- }
935
- sessionIdRef.current = sessionId;
936
- }
937
- }, []);
938
- const getSummary = (0, import_react5.useCallback)(
939
- async (filter) => {
940
- setState((prev) => ({ ...prev, loading: true, error: null }));
941
- try {
942
- const response = await getAnalyticsSummaryApi(filter, options);
943
- if (response.error) {
944
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
945
- return null;
946
- }
947
- const summary = response.data?.data || null;
948
- setState((prev) => ({ ...prev, loading: false, summary }));
949
- return summary;
950
- } catch (err) {
951
- const message = err instanceof Error ? err.message : "Failed to get analytics summary";
952
- setState((prev) => ({ ...prev, loading: false, error: message }));
953
- return null;
954
- }
955
- },
956
- [options]
957
- );
958
- const getChats = (0, import_react5.useCallback)(
959
- async (filter, agentId) => {
960
- setState((prev) => ({ ...prev, loading: true, error: null }));
961
- try {
962
- const response = await getChatsAnalyticsApi(filter, agentId, options);
963
- if (response.error) {
964
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
965
- return [];
966
- }
967
- const chats = response.data?.data || [];
968
- setState((prev) => ({ ...prev, loading: false, chats }));
969
- return chats;
970
- } catch (err) {
971
- const message = err instanceof Error ? err.message : "Failed to get chat analytics";
972
- setState((prev) => ({ ...prev, loading: false, error: message }));
973
- return [];
974
- }
975
- },
976
- [options]
977
- );
978
- const getAgents = (0, import_react5.useCallback)(
979
- async (filter) => {
980
- setState((prev) => ({ ...prev, loading: true, error: null }));
981
- try {
982
- const response = await getAgentsAnalyticsApi(filter, options);
983
- if (response.error) {
984
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
985
- return [];
986
- }
987
- const agents = response.data?.data || [];
988
- setState((prev) => ({ ...prev, loading: false, agents }));
989
- return agents;
990
- } catch (err) {
991
- const message = err instanceof Error ? err.message : "Failed to get agent analytics";
992
- setState((prev) => ({ ...prev, loading: false, error: message }));
993
- return [];
994
- }
995
- },
996
- [options]
997
- );
998
- const getUsage = (0, import_react5.useCallback)(
999
- async (filter) => {
1000
- setState((prev) => ({ ...prev, loading: true, error: null }));
1001
- try {
1002
- const response = await getUsageAnalyticsApi(filter, options);
1003
- if (response.error) {
1004
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
1005
- return [];
1006
- }
1007
- const usage = response.data?.data || [];
1008
- setState((prev) => ({ ...prev, loading: false, usage }));
1009
- return usage;
1010
- } catch (err) {
1011
- const message = err instanceof Error ? err.message : "Failed to get usage analytics";
1012
- setState((prev) => ({ ...prev, loading: false, error: message }));
1013
- return [];
1014
- }
1015
- },
1016
- [options]
1017
- );
1018
- const getDaily = (0, import_react5.useCallback)(
1019
- async (filter) => {
1020
- setState((prev) => ({ ...prev, loading: true, error: null }));
1021
- try {
1022
- const response = await getDailyAnalyticsApi(filter, options);
1023
- if (response.error) {
1024
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
1025
- return [];
1026
- }
1027
- const daily = response.data?.data || [];
1028
- setState((prev) => ({ ...prev, loading: false, daily }));
1029
- return daily;
1030
- } catch (err) {
1031
- const message = err instanceof Error ? err.message : "Failed to get daily analytics";
1032
- setState((prev) => ({ ...prev, loading: false, error: message }));
1033
- return [];
1034
- }
1035
- },
1036
- [options]
1037
- );
1038
- const getEvents = (0, import_react5.useCallback)(
1039
- async (filter) => {
1040
- setState((prev) => ({ ...prev, loading: true, error: null }));
1041
- try {
1042
- const response = await getAnalyticsEventsApi(filter, options);
1043
- if (response.error) {
1044
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
1045
- return [];
1046
- }
1047
- const events = response.data?.data || [];
1048
- setState((prev) => ({ ...prev, loading: false, events }));
1049
- return events;
1050
- } catch (err) {
1051
- const message = err instanceof Error ? err.message : "Failed to get analytics events";
1052
- setState((prev) => ({ ...prev, loading: false, error: message }));
1053
- return [];
1054
- }
1055
- },
1056
- [options]
1057
- );
1058
- const trackEvent = (0, import_react5.useCallback)(
1059
- async (eventType, eventCategory, properties) => {
1060
- try {
1061
- const event = {
1062
- sessionId: sessionIdRef.current,
1063
- userId: options.userId || "",
1064
- eventType,
1065
- eventCategory,
1066
- pagePath: typeof window !== "undefined" ? window.location.pathname : void 0,
1067
- properties
1068
- };
1069
- await logAnalyticsEventApi(event, options);
1070
- } catch {
1071
- console.debug("Failed to track analytics event:", eventType);
1072
- }
1073
- },
1074
- [options]
1075
- );
1076
- const trackPageView = (0, import_react5.useCallback)(
1077
- async (pageName) => {
1078
- await trackEvent("page_view", "navigation", {
1079
- pageName: pageName || (typeof window !== "undefined" ? document.title : "")
1080
- });
1081
- },
1082
- [trackEvent]
1083
- );
1084
- const getGlobalSummary = (0, import_react5.useCallback)(
1085
- async (filter) => {
1086
- setState((prev) => ({ ...prev, loading: true, error: null }));
1087
- try {
1088
- const response = await getGlobalSummaryApi(filter, options);
1089
- if (response.error) {
1090
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
1091
- return null;
1092
- }
1093
- setState((prev) => ({ ...prev, loading: false }));
1094
- return response.data?.data || null;
1095
- } catch (err) {
1096
- const message = err instanceof Error ? err.message : "Failed to get global summary";
1097
- setState((prev) => ({ ...prev, loading: false, error: message }));
1098
- return null;
1099
- }
1100
- },
1101
- [options]
1102
- );
1103
- const getGlobalOrgs = (0, import_react5.useCallback)(
1104
- async (filter) => {
1105
- setState((prev) => ({ ...prev, loading: true, error: null }));
1106
- try {
1107
- const response = await getGlobalOrgsAnalyticsApi(filter, options);
1108
- if (response.error) {
1109
- setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
1110
- return [];
1111
- }
1112
- setState((prev) => ({ ...prev, loading: false }));
1113
- return response.data?.data || [];
1114
- } catch (err) {
1115
- const message = err instanceof Error ? err.message : "Failed to get org analytics";
1116
- setState((prev) => ({ ...prev, loading: false, error: message }));
1117
- return [];
1118
- }
1119
- },
1120
- [options]
1121
- );
1122
- return {
1123
- // State
1124
- ...state,
1125
- // Query functions
1126
- getSummary,
1127
- getChats,
1128
- getAgents,
1129
- getUsage,
1130
- getDaily,
1131
- getEvents,
1132
- // Event tracking
1133
- trackEvent,
1134
- trackPageView,
1135
- // Global analytics (admin)
1136
- getGlobalSummary,
1137
- getGlobalOrgs
1138
- };
1139
- }
1140
- var useAnalyticsContext = useProductAnalytics;
1141
811
  // Annotate the CommonJS export names for ESM import in node:
1142
812
  0 && (module.exports = {
1143
- useAnalyticsContext,
1144
- useInvitesAdmin,
1145
813
  useOrgAdmin,
1146
- useOrgSettings,
1147
- useProductAnalytics,
1148
814
  useUsersAdmin
1149
815
  });
1150
816
  //# sourceMappingURL=index.cjs.map