@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.
- package/README.md +24 -14
- package/SKILL.md +570 -0
- package/dist/{analytics-CZ0LmSlf.d.cts → admin-C1iVQe2d.d.cts} +6 -168
- package/dist/{analytics-CZ0LmSlf.d.ts → admin-C1iVQe2d.d.ts} +6 -168
- package/dist/api/index.cjs +29 -125
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.cts +4 -50
- package/dist/api/index.d.ts +4 -50
- package/dist/api/index.js +28 -115
- package/dist/api/index.js.map +1 -1
- package/dist/hooks/index.cjs +85 -419
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +66 -129
- package/dist/hooks/index.d.ts +66 -129
- package/dist/hooks/index.js +85 -415
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +32 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +30 -115
- package/dist/index.js.map +1 -1
- package/dist/models/index.cjs +3 -0
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -1
- package/dist/{orgs-BOVRgr8L.d.ts → orgs-BSHeYVe-.d.ts} +1 -1
- package/dist/{orgs-IvppiqI8.d.cts → orgs-Buu2Re0N.d.cts} +1 -1
- package/package.json +5 -4
package/dist/hooks/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useState, useCallback } from "react";
|
|
3
3
|
|
|
4
4
|
// api/index.ts
|
|
5
|
-
import { browserApiRequest as
|
|
5
|
+
import { browserApiRequest as browserApiRequest4, clearGatewayTokenCache } from "@elqnt/api-client/browser";
|
|
6
6
|
|
|
7
7
|
// api/orgs.ts
|
|
8
8
|
import { browserApiRequest } from "@elqnt/api-client/browser";
|
|
@@ -158,84 +158,6 @@ async function acceptInviteApi(inviteId, options) {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
// api/analytics.ts
|
|
162
|
-
import { browserApiRequest as browserApiRequest4 } from "@elqnt/api-client/browser";
|
|
163
|
-
function buildDateFilterParams(filter) {
|
|
164
|
-
if (!filter) return "";
|
|
165
|
-
const params = new URLSearchParams();
|
|
166
|
-
if (filter.from) params.set("from", filter.from);
|
|
167
|
-
if (filter.to) params.set("to", filter.to);
|
|
168
|
-
const queryString = params.toString();
|
|
169
|
-
return queryString ? `?${queryString}` : "";
|
|
170
|
-
}
|
|
171
|
-
async function getAnalyticsSummaryApi(filter, options) {
|
|
172
|
-
const queryString = buildDateFilterParams(filter);
|
|
173
|
-
return browserApiRequest4(`/api/v1/analytics/summary${queryString}`, {
|
|
174
|
-
method: "GET",
|
|
175
|
-
...options
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
async function getChatsAnalyticsApi(filter, agentId, options) {
|
|
179
|
-
const params = new URLSearchParams();
|
|
180
|
-
if (filter?.from) params.set("from", filter.from);
|
|
181
|
-
if (filter?.to) params.set("to", filter.to);
|
|
182
|
-
if (agentId) params.set("agent_id", agentId);
|
|
183
|
-
const queryString = params.toString();
|
|
184
|
-
return browserApiRequest4(`/api/v1/analytics/chats${queryString ? `?${queryString}` : ""}`, {
|
|
185
|
-
method: "GET",
|
|
186
|
-
...options
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async function getAgentsAnalyticsApi(filter, options) {
|
|
190
|
-
const queryString = buildDateFilterParams(filter);
|
|
191
|
-
return browserApiRequest4(`/api/v1/analytics/agents${queryString}`, {
|
|
192
|
-
method: "GET",
|
|
193
|
-
...options
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async function getUsageAnalyticsApi(filter, options) {
|
|
197
|
-
const queryString = buildDateFilterParams(filter);
|
|
198
|
-
return browserApiRequest4(`/api/v1/analytics/usage${queryString}`, {
|
|
199
|
-
method: "GET",
|
|
200
|
-
...options
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
async function getDailyAnalyticsApi(filter, options) {
|
|
204
|
-
const queryString = buildDateFilterParams(filter);
|
|
205
|
-
return browserApiRequest4(`/api/v1/analytics/daily${queryString}`, {
|
|
206
|
-
method: "GET",
|
|
207
|
-
...options
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
async function getAnalyticsEventsApi(filter, options) {
|
|
211
|
-
const queryString = buildDateFilterParams(filter);
|
|
212
|
-
return browserApiRequest4(`/api/v1/analytics/events${queryString}`, {
|
|
213
|
-
method: "GET",
|
|
214
|
-
...options
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
async function logAnalyticsEventApi(event, options) {
|
|
218
|
-
return browserApiRequest4("/api/v1/analytics/events", {
|
|
219
|
-
method: "POST",
|
|
220
|
-
body: event,
|
|
221
|
-
...options
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
async function getGlobalSummaryApi(filter, options) {
|
|
225
|
-
const queryString = buildDateFilterParams(filter);
|
|
226
|
-
return browserApiRequest4(`/api/v1/analytics/global/summary${queryString}`, {
|
|
227
|
-
method: "GET",
|
|
228
|
-
...options
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
async function getGlobalOrgsAnalyticsApi(filter, options) {
|
|
232
|
-
const queryString = buildDateFilterParams(filter);
|
|
233
|
-
return browserApiRequest4(`/api/v1/analytics/global/orgs${queryString}`, {
|
|
234
|
-
method: "GET",
|
|
235
|
-
...options
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
161
|
// api/index.ts
|
|
240
162
|
function orgRowToSettings(orgId, row) {
|
|
241
163
|
return {
|
|
@@ -265,7 +187,7 @@ function settingsToOrgRow(settings) {
|
|
|
265
187
|
}
|
|
266
188
|
async function getOrgSettingsApi(options) {
|
|
267
189
|
const orgId = options.orgId ?? "";
|
|
268
|
-
const response = await
|
|
190
|
+
const response = await browserApiRequest4(
|
|
269
191
|
`/api/v1/admin/orgs/${orgId}`,
|
|
270
192
|
{ method: "GET", ...options }
|
|
271
193
|
);
|
|
@@ -285,7 +207,7 @@ async function createOrgSettingsApi(settings, options) {
|
|
|
285
207
|
}
|
|
286
208
|
async function updateOrgSettingsApi(settings, options) {
|
|
287
209
|
const orgId = options.orgId ?? "";
|
|
288
|
-
const response = await
|
|
210
|
+
const response = await browserApiRequest4(
|
|
289
211
|
`/api/v1/admin/orgs/${orgId}`,
|
|
290
212
|
{
|
|
291
213
|
method: "PUT",
|
|
@@ -426,6 +348,66 @@ function useOrgAdmin(options) {
|
|
|
426
348
|
},
|
|
427
349
|
[options]
|
|
428
350
|
);
|
|
351
|
+
const getSettings = useCallback(async () => {
|
|
352
|
+
setLoading(true);
|
|
353
|
+
setError(null);
|
|
354
|
+
try {
|
|
355
|
+
const response = await getOrgSettingsApi(options);
|
|
356
|
+
if (response.error) {
|
|
357
|
+
setError(response.error);
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
return response.data?.settings || null;
|
|
361
|
+
} catch (err) {
|
|
362
|
+
const message = err instanceof Error ? err.message : "Failed to get organization settings";
|
|
363
|
+
setError(message);
|
|
364
|
+
return null;
|
|
365
|
+
} finally {
|
|
366
|
+
setLoading(false);
|
|
367
|
+
}
|
|
368
|
+
}, [options]);
|
|
369
|
+
const createSettings = useCallback(
|
|
370
|
+
async (settings) => {
|
|
371
|
+
setLoading(true);
|
|
372
|
+
setError(null);
|
|
373
|
+
try {
|
|
374
|
+
const response = await createOrgSettingsApi(settings, options);
|
|
375
|
+
if (response.error) {
|
|
376
|
+
setError(response.error);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
return response.data?.settings || null;
|
|
380
|
+
} catch (err) {
|
|
381
|
+
const message = err instanceof Error ? err.message : "Failed to create organization settings";
|
|
382
|
+
setError(message);
|
|
383
|
+
return null;
|
|
384
|
+
} finally {
|
|
385
|
+
setLoading(false);
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
[options]
|
|
389
|
+
);
|
|
390
|
+
const updateSettings = useCallback(
|
|
391
|
+
async (settings) => {
|
|
392
|
+
setLoading(true);
|
|
393
|
+
setError(null);
|
|
394
|
+
try {
|
|
395
|
+
const response = await updateOrgSettingsApi(settings, options);
|
|
396
|
+
if (response.error) {
|
|
397
|
+
setError(response.error);
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
return response.data?.settings || null;
|
|
401
|
+
} catch (err) {
|
|
402
|
+
const message = err instanceof Error ? err.message : "Failed to update organization settings";
|
|
403
|
+
setError(message);
|
|
404
|
+
return null;
|
|
405
|
+
} finally {
|
|
406
|
+
setLoading(false);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
[options]
|
|
410
|
+
);
|
|
429
411
|
return {
|
|
430
412
|
loading,
|
|
431
413
|
error,
|
|
@@ -434,7 +416,11 @@ function useOrgAdmin(options) {
|
|
|
434
416
|
getOrgInfo,
|
|
435
417
|
createOrg,
|
|
436
418
|
updateOrg,
|
|
437
|
-
deleteOrg
|
|
419
|
+
deleteOrg,
|
|
420
|
+
// Org settings
|
|
421
|
+
getSettings,
|
|
422
|
+
createSettings,
|
|
423
|
+
updateSettings
|
|
438
424
|
};
|
|
439
425
|
}
|
|
440
426
|
|
|
@@ -629,27 +615,7 @@ function useUsersAdmin(options) {
|
|
|
629
615
|
},
|
|
630
616
|
[options]
|
|
631
617
|
);
|
|
632
|
-
|
|
633
|
-
loading,
|
|
634
|
-
error,
|
|
635
|
-
listUsers,
|
|
636
|
-
getUser,
|
|
637
|
-
getUserByEmail,
|
|
638
|
-
getUserByPhone,
|
|
639
|
-
createUser,
|
|
640
|
-
updateUser,
|
|
641
|
-
deleteUser,
|
|
642
|
-
getUserSettings,
|
|
643
|
-
updateUserSettings
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// hooks/use-invites-admin.ts
|
|
648
|
-
import { useState as useState3, useCallback as useCallback3 } from "react";
|
|
649
|
-
function useInvitesAdmin(options) {
|
|
650
|
-
const [loading, setLoading] = useState3(false);
|
|
651
|
-
const [error, setError] = useState3(null);
|
|
652
|
-
const listInvites = useCallback3(async () => {
|
|
618
|
+
const listInvites = useCallback2(async () => {
|
|
653
619
|
setLoading(true);
|
|
654
620
|
setError(null);
|
|
655
621
|
try {
|
|
@@ -667,7 +633,7 @@ function useInvitesAdmin(options) {
|
|
|
667
633
|
setLoading(false);
|
|
668
634
|
}
|
|
669
635
|
}, [options]);
|
|
670
|
-
const getInvite =
|
|
636
|
+
const getInvite = useCallback2(
|
|
671
637
|
async (inviteId) => {
|
|
672
638
|
setLoading(true);
|
|
673
639
|
setError(null);
|
|
@@ -688,7 +654,7 @@ function useInvitesAdmin(options) {
|
|
|
688
654
|
},
|
|
689
655
|
[options]
|
|
690
656
|
);
|
|
691
|
-
const sendInvite =
|
|
657
|
+
const sendInvite = useCallback2(
|
|
692
658
|
async (invite) => {
|
|
693
659
|
setLoading(true);
|
|
694
660
|
setError(null);
|
|
@@ -709,7 +675,7 @@ function useInvitesAdmin(options) {
|
|
|
709
675
|
},
|
|
710
676
|
[options]
|
|
711
677
|
);
|
|
712
|
-
const sendInvites =
|
|
678
|
+
const sendInvites = useCallback2(
|
|
713
679
|
async (invites) => {
|
|
714
680
|
setLoading(true);
|
|
715
681
|
setError(null);
|
|
@@ -730,7 +696,7 @@ function useInvitesAdmin(options) {
|
|
|
730
696
|
},
|
|
731
697
|
[options]
|
|
732
698
|
);
|
|
733
|
-
const resendInvite =
|
|
699
|
+
const resendInvite = useCallback2(
|
|
734
700
|
async (inviteId) => {
|
|
735
701
|
setLoading(true);
|
|
736
702
|
setError(null);
|
|
@@ -751,7 +717,7 @@ function useInvitesAdmin(options) {
|
|
|
751
717
|
},
|
|
752
718
|
[options]
|
|
753
719
|
);
|
|
754
|
-
const revokeInvite =
|
|
720
|
+
const revokeInvite = useCallback2(
|
|
755
721
|
async (inviteId) => {
|
|
756
722
|
setLoading(true);
|
|
757
723
|
setError(null);
|
|
@@ -772,7 +738,7 @@ function useInvitesAdmin(options) {
|
|
|
772
738
|
},
|
|
773
739
|
[options]
|
|
774
740
|
);
|
|
775
|
-
const acceptInvite =
|
|
741
|
+
const acceptInvite = useCallback2(
|
|
776
742
|
async (inviteId) => {
|
|
777
743
|
setLoading(true);
|
|
778
744
|
setError(null);
|
|
@@ -796,6 +762,16 @@ function useInvitesAdmin(options) {
|
|
|
796
762
|
return {
|
|
797
763
|
loading,
|
|
798
764
|
error,
|
|
765
|
+
listUsers,
|
|
766
|
+
getUser,
|
|
767
|
+
getUserByEmail,
|
|
768
|
+
getUserByPhone,
|
|
769
|
+
createUser,
|
|
770
|
+
updateUser,
|
|
771
|
+
deleteUser,
|
|
772
|
+
getUserSettings,
|
|
773
|
+
updateUserSettings,
|
|
774
|
+
// Invitations
|
|
799
775
|
listInvites,
|
|
800
776
|
getInvite,
|
|
801
777
|
sendInvite,
|
|
@@ -805,314 +781,8 @@ function useInvitesAdmin(options) {
|
|
|
805
781
|
acceptInvite
|
|
806
782
|
};
|
|
807
783
|
}
|
|
808
|
-
|
|
809
|
-
// hooks/use-org-settings.ts
|
|
810
|
-
import { useState as useState4, useCallback as useCallback4 } from "react";
|
|
811
|
-
function useOrgSettings(options) {
|
|
812
|
-
const [loading, setLoading] = useState4(false);
|
|
813
|
-
const [error, setError] = useState4(null);
|
|
814
|
-
const getSettings = useCallback4(async () => {
|
|
815
|
-
setLoading(true);
|
|
816
|
-
setError(null);
|
|
817
|
-
try {
|
|
818
|
-
const response = await getOrgSettingsApi(options);
|
|
819
|
-
if (response.error) {
|
|
820
|
-
setError(response.error);
|
|
821
|
-
return null;
|
|
822
|
-
}
|
|
823
|
-
return response.data?.settings || null;
|
|
824
|
-
} catch (err) {
|
|
825
|
-
const message = err instanceof Error ? err.message : "Failed to get organization settings";
|
|
826
|
-
setError(message);
|
|
827
|
-
return null;
|
|
828
|
-
} finally {
|
|
829
|
-
setLoading(false);
|
|
830
|
-
}
|
|
831
|
-
}, [options]);
|
|
832
|
-
const createSettings = useCallback4(
|
|
833
|
-
async (settings) => {
|
|
834
|
-
setLoading(true);
|
|
835
|
-
setError(null);
|
|
836
|
-
try {
|
|
837
|
-
const response = await createOrgSettingsApi(settings, options);
|
|
838
|
-
if (response.error) {
|
|
839
|
-
setError(response.error);
|
|
840
|
-
return null;
|
|
841
|
-
}
|
|
842
|
-
return response.data?.settings || null;
|
|
843
|
-
} catch (err) {
|
|
844
|
-
const message = err instanceof Error ? err.message : "Failed to create organization settings";
|
|
845
|
-
setError(message);
|
|
846
|
-
return null;
|
|
847
|
-
} finally {
|
|
848
|
-
setLoading(false);
|
|
849
|
-
}
|
|
850
|
-
},
|
|
851
|
-
[options]
|
|
852
|
-
);
|
|
853
|
-
const updateSettings = useCallback4(
|
|
854
|
-
async (settings) => {
|
|
855
|
-
setLoading(true);
|
|
856
|
-
setError(null);
|
|
857
|
-
try {
|
|
858
|
-
const response = await updateOrgSettingsApi(settings, options);
|
|
859
|
-
if (response.error) {
|
|
860
|
-
setError(response.error);
|
|
861
|
-
return null;
|
|
862
|
-
}
|
|
863
|
-
return response.data?.settings || null;
|
|
864
|
-
} catch (err) {
|
|
865
|
-
const message = err instanceof Error ? err.message : "Failed to update organization settings";
|
|
866
|
-
setError(message);
|
|
867
|
-
return null;
|
|
868
|
-
} finally {
|
|
869
|
-
setLoading(false);
|
|
870
|
-
}
|
|
871
|
-
},
|
|
872
|
-
[options]
|
|
873
|
-
);
|
|
874
|
-
return {
|
|
875
|
-
loading,
|
|
876
|
-
error,
|
|
877
|
-
getSettings,
|
|
878
|
-
createSettings,
|
|
879
|
-
updateSettings
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// hooks/use-product-analytics.ts
|
|
884
|
-
import { useState as useState5, useCallback as useCallback5, useRef, useEffect } from "react";
|
|
885
|
-
function useProductAnalytics(options) {
|
|
886
|
-
const [state, setState] = useState5({
|
|
887
|
-
summary: null,
|
|
888
|
-
chats: [],
|
|
889
|
-
agents: [],
|
|
890
|
-
usage: [],
|
|
891
|
-
daily: [],
|
|
892
|
-
events: [],
|
|
893
|
-
loading: false,
|
|
894
|
-
error: null
|
|
895
|
-
});
|
|
896
|
-
const sessionIdRef = useRef("");
|
|
897
|
-
useEffect(() => {
|
|
898
|
-
if (typeof window !== "undefined") {
|
|
899
|
-
let sessionId = sessionStorage.getItem("analytics_session_id");
|
|
900
|
-
if (!sessionId) {
|
|
901
|
-
sessionId = crypto.randomUUID();
|
|
902
|
-
sessionStorage.setItem("analytics_session_id", sessionId);
|
|
903
|
-
}
|
|
904
|
-
sessionIdRef.current = sessionId;
|
|
905
|
-
}
|
|
906
|
-
}, []);
|
|
907
|
-
const getSummary = useCallback5(
|
|
908
|
-
async (filter) => {
|
|
909
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
910
|
-
try {
|
|
911
|
-
const response = await getAnalyticsSummaryApi(filter, options);
|
|
912
|
-
if (response.error) {
|
|
913
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
914
|
-
return null;
|
|
915
|
-
}
|
|
916
|
-
const summary = response.data?.data || null;
|
|
917
|
-
setState((prev) => ({ ...prev, loading: false, summary }));
|
|
918
|
-
return summary;
|
|
919
|
-
} catch (err) {
|
|
920
|
-
const message = err instanceof Error ? err.message : "Failed to get analytics summary";
|
|
921
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
922
|
-
return null;
|
|
923
|
-
}
|
|
924
|
-
},
|
|
925
|
-
[options]
|
|
926
|
-
);
|
|
927
|
-
const getChats = useCallback5(
|
|
928
|
-
async (filter, agentId) => {
|
|
929
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
930
|
-
try {
|
|
931
|
-
const response = await getChatsAnalyticsApi(filter, agentId, options);
|
|
932
|
-
if (response.error) {
|
|
933
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
934
|
-
return [];
|
|
935
|
-
}
|
|
936
|
-
const chats = response.data?.data || [];
|
|
937
|
-
setState((prev) => ({ ...prev, loading: false, chats }));
|
|
938
|
-
return chats;
|
|
939
|
-
} catch (err) {
|
|
940
|
-
const message = err instanceof Error ? err.message : "Failed to get chat analytics";
|
|
941
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
942
|
-
return [];
|
|
943
|
-
}
|
|
944
|
-
},
|
|
945
|
-
[options]
|
|
946
|
-
);
|
|
947
|
-
const getAgents = useCallback5(
|
|
948
|
-
async (filter) => {
|
|
949
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
950
|
-
try {
|
|
951
|
-
const response = await getAgentsAnalyticsApi(filter, options);
|
|
952
|
-
if (response.error) {
|
|
953
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
954
|
-
return [];
|
|
955
|
-
}
|
|
956
|
-
const agents = response.data?.data || [];
|
|
957
|
-
setState((prev) => ({ ...prev, loading: false, agents }));
|
|
958
|
-
return agents;
|
|
959
|
-
} catch (err) {
|
|
960
|
-
const message = err instanceof Error ? err.message : "Failed to get agent analytics";
|
|
961
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
962
|
-
return [];
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
[options]
|
|
966
|
-
);
|
|
967
|
-
const getUsage = useCallback5(
|
|
968
|
-
async (filter) => {
|
|
969
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
970
|
-
try {
|
|
971
|
-
const response = await getUsageAnalyticsApi(filter, options);
|
|
972
|
-
if (response.error) {
|
|
973
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
974
|
-
return [];
|
|
975
|
-
}
|
|
976
|
-
const usage = response.data?.data || [];
|
|
977
|
-
setState((prev) => ({ ...prev, loading: false, usage }));
|
|
978
|
-
return usage;
|
|
979
|
-
} catch (err) {
|
|
980
|
-
const message = err instanceof Error ? err.message : "Failed to get usage analytics";
|
|
981
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
982
|
-
return [];
|
|
983
|
-
}
|
|
984
|
-
},
|
|
985
|
-
[options]
|
|
986
|
-
);
|
|
987
|
-
const getDaily = useCallback5(
|
|
988
|
-
async (filter) => {
|
|
989
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
990
|
-
try {
|
|
991
|
-
const response = await getDailyAnalyticsApi(filter, options);
|
|
992
|
-
if (response.error) {
|
|
993
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
994
|
-
return [];
|
|
995
|
-
}
|
|
996
|
-
const daily = response.data?.data || [];
|
|
997
|
-
setState((prev) => ({ ...prev, loading: false, daily }));
|
|
998
|
-
return daily;
|
|
999
|
-
} catch (err) {
|
|
1000
|
-
const message = err instanceof Error ? err.message : "Failed to get daily analytics";
|
|
1001
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
1002
|
-
return [];
|
|
1003
|
-
}
|
|
1004
|
-
},
|
|
1005
|
-
[options]
|
|
1006
|
-
);
|
|
1007
|
-
const getEvents = useCallback5(
|
|
1008
|
-
async (filter) => {
|
|
1009
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1010
|
-
try {
|
|
1011
|
-
const response = await getAnalyticsEventsApi(filter, options);
|
|
1012
|
-
if (response.error) {
|
|
1013
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
1014
|
-
return [];
|
|
1015
|
-
}
|
|
1016
|
-
const events = response.data?.data || [];
|
|
1017
|
-
setState((prev) => ({ ...prev, loading: false, events }));
|
|
1018
|
-
return events;
|
|
1019
|
-
} catch (err) {
|
|
1020
|
-
const message = err instanceof Error ? err.message : "Failed to get analytics events";
|
|
1021
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
1022
|
-
return [];
|
|
1023
|
-
}
|
|
1024
|
-
},
|
|
1025
|
-
[options]
|
|
1026
|
-
);
|
|
1027
|
-
const trackEvent = useCallback5(
|
|
1028
|
-
async (eventType, eventCategory, properties) => {
|
|
1029
|
-
try {
|
|
1030
|
-
const event = {
|
|
1031
|
-
sessionId: sessionIdRef.current,
|
|
1032
|
-
userId: options.userId || "",
|
|
1033
|
-
eventType,
|
|
1034
|
-
eventCategory,
|
|
1035
|
-
pagePath: typeof window !== "undefined" ? window.location.pathname : void 0,
|
|
1036
|
-
properties
|
|
1037
|
-
};
|
|
1038
|
-
await logAnalyticsEventApi(event, options);
|
|
1039
|
-
} catch {
|
|
1040
|
-
console.debug("Failed to track analytics event:", eventType);
|
|
1041
|
-
}
|
|
1042
|
-
},
|
|
1043
|
-
[options]
|
|
1044
|
-
);
|
|
1045
|
-
const trackPageView = useCallback5(
|
|
1046
|
-
async (pageName) => {
|
|
1047
|
-
await trackEvent("page_view", "navigation", {
|
|
1048
|
-
pageName: pageName || (typeof window !== "undefined" ? document.title : "")
|
|
1049
|
-
});
|
|
1050
|
-
},
|
|
1051
|
-
[trackEvent]
|
|
1052
|
-
);
|
|
1053
|
-
const getGlobalSummary = useCallback5(
|
|
1054
|
-
async (filter) => {
|
|
1055
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1056
|
-
try {
|
|
1057
|
-
const response = await getGlobalSummaryApi(filter, options);
|
|
1058
|
-
if (response.error) {
|
|
1059
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
1060
|
-
return null;
|
|
1061
|
-
}
|
|
1062
|
-
setState((prev) => ({ ...prev, loading: false }));
|
|
1063
|
-
return response.data?.data || null;
|
|
1064
|
-
} catch (err) {
|
|
1065
|
-
const message = err instanceof Error ? err.message : "Failed to get global summary";
|
|
1066
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
1067
|
-
return null;
|
|
1068
|
-
}
|
|
1069
|
-
},
|
|
1070
|
-
[options]
|
|
1071
|
-
);
|
|
1072
|
-
const getGlobalOrgs = useCallback5(
|
|
1073
|
-
async (filter) => {
|
|
1074
|
-
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1075
|
-
try {
|
|
1076
|
-
const response = await getGlobalOrgsAnalyticsApi(filter, options);
|
|
1077
|
-
if (response.error) {
|
|
1078
|
-
setState((prev) => ({ ...prev, loading: false, error: response.error || null }));
|
|
1079
|
-
return [];
|
|
1080
|
-
}
|
|
1081
|
-
setState((prev) => ({ ...prev, loading: false }));
|
|
1082
|
-
return response.data?.data || [];
|
|
1083
|
-
} catch (err) {
|
|
1084
|
-
const message = err instanceof Error ? err.message : "Failed to get org analytics";
|
|
1085
|
-
setState((prev) => ({ ...prev, loading: false, error: message }));
|
|
1086
|
-
return [];
|
|
1087
|
-
}
|
|
1088
|
-
},
|
|
1089
|
-
[options]
|
|
1090
|
-
);
|
|
1091
|
-
return {
|
|
1092
|
-
// State
|
|
1093
|
-
...state,
|
|
1094
|
-
// Query functions
|
|
1095
|
-
getSummary,
|
|
1096
|
-
getChats,
|
|
1097
|
-
getAgents,
|
|
1098
|
-
getUsage,
|
|
1099
|
-
getDaily,
|
|
1100
|
-
getEvents,
|
|
1101
|
-
// Event tracking
|
|
1102
|
-
trackEvent,
|
|
1103
|
-
trackPageView,
|
|
1104
|
-
// Global analytics (admin)
|
|
1105
|
-
getGlobalSummary,
|
|
1106
|
-
getGlobalOrgs
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
var useAnalyticsContext = useProductAnalytics;
|
|
1110
784
|
export {
|
|
1111
|
-
useAnalyticsContext,
|
|
1112
|
-
useInvitesAdmin,
|
|
1113
785
|
useOrgAdmin,
|
|
1114
|
-
useOrgSettings,
|
|
1115
|
-
useProductAnalytics,
|
|
1116
786
|
useUsersAdmin
|
|
1117
787
|
};
|
|
1118
788
|
//# sourceMappingURL=index.js.map
|