@connectedxm/admin 2.8.20 → 2.8.21

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/dist/index.js CHANGED
@@ -17840,6 +17840,73 @@ var useGetThreadMembers = (threadId = "", params = {}, options = {}) => {
17840
17840
  );
17841
17841
  };
17842
17842
 
17843
+ // src/queries/useConnectedCursorQuery.ts
17844
+ import {
17845
+ useInfiniteQuery as useInfiniteQuery2
17846
+ } from "@tanstack/react-query";
17847
+ var useConnectedCursorQuery = (queryKeys, queryFn, params = {}, options = {
17848
+ shouldRedirect: false
17849
+ }, domain) => {
17850
+ if (typeof params.pageSize === "undefined") params.pageSize = 25;
17851
+ const {
17852
+ onModuleForbidden,
17853
+ onNotAuthorized,
17854
+ onNotFound,
17855
+ apiUrl,
17856
+ getToken,
17857
+ organizationId,
17858
+ getExecuteAs,
17859
+ queryClient
17860
+ } = useConnectedXM();
17861
+ const { allowed } = usePermission_default(domain, domain ? "read" : void 0);
17862
+ const getNextPageParam = (lastPage) => {
17863
+ if (lastPage.cursor) {
17864
+ return lastPage.cursor;
17865
+ }
17866
+ return null;
17867
+ };
17868
+ return useInfiniteQuery2({
17869
+ staleTime: 60 * 1e3,
17870
+ // 60 Seconds
17871
+ retry: (failureCount, error) => {
17872
+ if (error.response?.status === 404) {
17873
+ if (onNotFound) onNotFound(error, queryKeys, options.shouldRedirect || false);
17874
+ return false;
17875
+ }
17876
+ if (error.response?.status === 403 || error.response?.status === 460 || error.response?.status === 461) {
17877
+ if (onModuleForbidden) onModuleForbidden(error, queryKeys, options.shouldRedirect || false);
17878
+ return false;
17879
+ }
17880
+ if (error.response?.status === 401) {
17881
+ if (onNotAuthorized) onNotAuthorized(error, queryKeys, options.shouldRedirect || false);
17882
+ return false;
17883
+ }
17884
+ if (failureCount < 3) return true;
17885
+ return false;
17886
+ },
17887
+ ...options,
17888
+ queryKey: [
17889
+ ...queryKeys,
17890
+ ...GetBaseInfiniteQueryKeys(params?.search)
17891
+ ],
17892
+ queryFn: ({ pageParam }) => queryFn({
17893
+ ...params,
17894
+ pageSize: params.pageSize || 25,
17895
+ cursor: pageParam,
17896
+ queryClient,
17897
+ adminApiParams: {
17898
+ apiUrl,
17899
+ getToken,
17900
+ organizationId,
17901
+ getExecuteAs
17902
+ }
17903
+ }),
17904
+ initialPageParam: null,
17905
+ getNextPageParam,
17906
+ enabled: (!domain || allowed) && options.enabled
17907
+ });
17908
+ };
17909
+
17843
17910
  // src/utilities/AppendInfiniteQuery.ts
17844
17911
  import { produce } from "immer";
17845
17912
  var AppendInfiniteQuery = (queryClient, key, newData) => {
@@ -17963,7 +18030,7 @@ var THREAD_MESSAGES_QUERY_KEY = (threadId) => [
17963
18030
  ...THREAD_QUERY_KEY(threadId),
17964
18031
  "MESSAGES"
17965
18032
  ];
17966
- var SET_THREAD_MESSAGES_QUERY_DATA = (client, keyParams, response, baseKeys = ["en"]) => {
18033
+ var SET_THREAD_MESSAGES_QUERY_DATA = (client, keyParams, response, baseKeys = [""]) => {
17967
18034
  client.setQueryData(
17968
18035
  [
17969
18036
  ...THREAD_MESSAGES_QUERY_KEY(...keyParams),
@@ -17974,7 +18041,7 @@ var SET_THREAD_MESSAGES_QUERY_DATA = (client, keyParams, response, baseKeys = ["
17974
18041
  };
17975
18042
  var GetThreadMessages = async ({
17976
18043
  threadId,
17977
- pageParam,
18044
+ cursor,
17978
18045
  pageSize,
17979
18046
  orderBy,
17980
18047
  search,
@@ -17984,7 +18051,7 @@ var GetThreadMessages = async ({
17984
18051
  const adminApi = await GetAdminAPI(adminApiParams);
17985
18052
  const { data } = await adminApi.get(`/threads/${threadId}/messages`, {
17986
18053
  params: {
17987
- page: pageParam || void 0,
18054
+ cursor: cursor || void 0,
17988
18055
  pageSize: pageSize || void 0,
17989
18056
  orderBy: orderBy || void 0,
17990
18057
  search: search || void 0
@@ -18001,7 +18068,7 @@ var GetThreadMessages = async ({
18001
18068
  };
18002
18069
  var useGetThreadMessages = (threadId = "", params = {}, options = {}) => {
18003
18070
  const { authenticated } = useConnectedXM();
18004
- return useConnectedInfiniteQuery(
18071
+ return useConnectedCursorQuery(
18005
18072
  THREAD_MESSAGES_QUERY_KEY(threadId),
18006
18073
  (params2) => GetThreadMessages({ ...params2, threadId }),
18007
18074
  params,
@@ -18232,6 +18299,46 @@ var useGetThreadMessageVideos = (threadId, messageId, params = {}, options = {})
18232
18299
  );
18233
18300
  };
18234
18301
 
18302
+ // src/queries/threads/useGetThreadMessagesPoll.ts
18303
+ var THREAD_MESSAGES_POLL_QUERY_KEY = (threadId, lastMessageId) => [
18304
+ ...THREAD_QUERY_KEY(threadId),
18305
+ "MESSAGES",
18306
+ lastMessageId,
18307
+ "POLL"
18308
+ ];
18309
+ var SET_THREAD_MESSAGES_POLL_QUERY_DATA = (client, keyParams, response) => {
18310
+ client.setQueryData(THREAD_MESSAGES_POLL_QUERY_KEY(...keyParams), response);
18311
+ };
18312
+ var GetThreadMessagesPoll = async ({
18313
+ threadId,
18314
+ lastMessageId,
18315
+ adminApiParams
18316
+ }) => {
18317
+ const adminApi = await GetAdminAPI(adminApiParams);
18318
+ const { data } = await adminApi.get(`/threads/${threadId}/messages/poll`, {
18319
+ params: {
18320
+ lastMessageId: lastMessageId || void 0
18321
+ }
18322
+ });
18323
+ return data;
18324
+ };
18325
+ var useGetThreadMessagesPoll = (threadId = "", lastMessageId = "", options = {}) => {
18326
+ const { authenticated } = useConnectedXM();
18327
+ return useConnectedSingleQuery(
18328
+ THREAD_MESSAGES_POLL_QUERY_KEY(threadId, lastMessageId),
18329
+ (params) => GetThreadMessagesPoll({ ...params, threadId, lastMessageId }),
18330
+ {
18331
+ ...options,
18332
+ enabled: !!authenticated && !!threadId && !!lastMessageId && (options?.enabled ?? true),
18333
+ // Polling configuration - you can adjust these as needed
18334
+ refetchInterval: options.refetchInterval ?? 5e3,
18335
+ // Poll every 5 seconds
18336
+ refetchIntervalInBackground: options.refetchIntervalInBackground ?? false
18337
+ },
18338
+ "threads"
18339
+ );
18340
+ };
18341
+
18235
18342
  // src/queries/tiers/useGetTiers.ts
18236
18343
  var TIERS_QUERY_KEY = (type) => {
18237
18344
  const keys = ["TIERS"];
@@ -37078,6 +37185,7 @@ export {
37078
37185
  GetThreadMessageReactions,
37079
37186
  GetThreadMessageVideos,
37080
37187
  GetThreadMessages,
37188
+ GetThreadMessagesPoll,
37081
37189
  GetThreads,
37082
37190
  GetTier,
37083
37191
  GetTierAccounts,
@@ -37674,6 +37782,7 @@ export {
37674
37782
  SET_THREAD_CIRCLE_ACCOUNT_QUERY_DATA,
37675
37783
  SET_THREAD_CIRCLE_QUERY_DATA,
37676
37784
  SET_THREAD_CIRCLE_THREADS_QUERY_DATA,
37785
+ SET_THREAD_MESSAGES_POLL_QUERY_DATA,
37677
37786
  SET_THREAD_MESSAGES_QUERY_DATA,
37678
37787
  SET_THREAD_MESSAGE_FILES_QUERY_DATA,
37679
37788
  SET_THREAD_MESSAGE_IMAGES_QUERY_DATA,
@@ -37750,6 +37859,7 @@ export {
37750
37859
  THREAD_CIRCLE_QUERY_KEY,
37751
37860
  THREAD_CIRCLE_THREADS_QUERY_KEY,
37752
37861
  THREAD_MEMBERS_QUERY_KEY,
37862
+ THREAD_MESSAGES_POLL_QUERY_KEY,
37753
37863
  THREAD_MESSAGES_QUERY_KEY,
37754
37864
  THREAD_MESSAGE_FILES_QUERY_KEY,
37755
37865
  THREAD_MESSAGE_IMAGES_QUERY_KEY,
@@ -38007,6 +38117,7 @@ export {
38007
38117
  useCancelSubscription,
38008
38118
  useCloneEvent,
38009
38119
  useConfirmAccountLogin,
38120
+ useConnectedCursorQuery,
38010
38121
  useConnectedInfiniteQuery,
38011
38122
  useConnectedMutation,
38012
38123
  useConnectedSingleQuery,
@@ -38720,6 +38831,7 @@ export {
38720
38831
  useGetThreadMessageReactions,
38721
38832
  useGetThreadMessageVideos,
38722
38833
  useGetThreadMessages,
38834
+ useGetThreadMessagesPoll,
38723
38835
  useGetThreads,
38724
38836
  useGetTier,
38725
38837
  useGetTierAccounts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedxm/admin",
3
- "version": "2.8.20",
3
+ "version": "2.8.21",
4
4
  "description": "Admin API javascript SDK",
5
5
  "author": "ConnectedXM Inc.",
6
6
  "type": "module",