headless.service.d.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { IUserPreferenceSettings, IStoreQuery, IUserGlobalPreferenceSettings } from '@novu/client';
  2. import { IOrganizationEntity, IMessage, IPaginatedResponse } from '@novu/shared';
  3. import type { ISession } from '../utils/types';
  4. import { FetchResult, IFeedId, IHeadlessServiceOptions, IMessageId, IUpdateActionVariables, IUpdateUserPreferencesVariables, IUpdateUserGlobalPreferencesVariables, UpdateResult } from './types';
  5. export declare const NOTIFICATION_CENTER_TOKEN_KEY = "nc_token";
  6. export declare class HeadlessService {
  7. private options;
  8. private api;
  9. private queryClient;
  10. private queryService;
  11. private session;
  12. private socket;
  13. private sessionQueryOptions;
  14. private organizationQueryOptions;
  15. private unseenCountQueryOptions;
  16. private unreadCountQueryOptions;
  17. private userPreferencesQueryOptions;
  18. private userGlobalPreferencesQueryOptions;
  19. constructor(options: IHeadlessServiceOptions);
  20. private assertSessionInitialized;
  21. private applyToken;
  22. private initializeSocket;
  23. private callFetchListener;
  24. private callFetchListenerWithPagination;
  25. private callUpdateListener;
  26. initializeSession({ listener, onSuccess, onError, }: {
  27. listener: (result: FetchResult<ISession>) => void;
  28. onSuccess?: (session: ISession) => void;
  29. onError?: (error: unknown) => void;
  30. }): () => void;
  31. fetchOrganization({ listener, onSuccess, onError, }: {
  32. listener: (result: FetchResult<IOrganizationEntity>) => void;
  33. onSuccess?: (session: IOrganizationEntity) => void;
  34. onError?: (error: unknown) => void;
  35. }): Promise<() => void>;
  36. fetchUnseenCount({ listener, onSuccess, onError, }: {
  37. listener: (result: FetchResult<{
  38. count: number;
  39. }>) => void;
  40. onSuccess?: (data: {
  41. count: number;
  42. }) => void;
  43. onError?: (error: unknown) => void;
  44. }): () => void;
  45. fetchUnreadCount({ listener, onSuccess, onError, }: {
  46. listener: (result: FetchResult<{
  47. count: number;
  48. }>) => void;
  49. onSuccess?: (data: {
  50. count: number;
  51. }) => void;
  52. onError?: (error: unknown) => void;
  53. }): () => void;
  54. listenNotificationReceive({ listener, }: {
  55. listener: (message: IMessage) => void;
  56. }): () => void;
  57. listenUnseenCountChange({ listener, }: {
  58. listener: (unseenCount: number) => void;
  59. }): () => void;
  60. listenUnreadCountChange({ listener, }: {
  61. listener: (unreadCount: number) => void;
  62. }): () => void;
  63. fetchNotifications({ page, storeId, query, listener, onSuccess, onError, }: {
  64. page?: number;
  65. storeId?: string;
  66. query?: IStoreQuery;
  67. listener: (result: FetchResult<IPaginatedResponse<IMessage>>) => void;
  68. onSuccess?: (messages: IPaginatedResponse<IMessage>) => void;
  69. onError?: (error: unknown) => void;
  70. }): () => void;
  71. fetchUserPreferences({ listener, onSuccess, onError, }: {
  72. listener: (result: FetchResult<IUserPreferenceSettings[]>) => void;
  73. onSuccess?: (settings: IUserPreferenceSettings[]) => void;
  74. onError?: (error: unknown) => void;
  75. }): () => void;
  76. fetchUserGlobalPreferences({ listener, onSuccess, onError, }: {
  77. listener: (result: FetchResult<IUserGlobalPreferenceSettings[]>) => void;
  78. onSuccess?: (settings: IUserGlobalPreferenceSettings[]) => void;
  79. onError?: (error: unknown) => void;
  80. }): () => void;
  81. updateUserPreferences({ templateId, channelType, checked, listener, onSuccess, onError, }: {
  82. templateId: IUpdateUserPreferencesVariables['templateId'];
  83. channelType: IUpdateUserPreferencesVariables['channelType'];
  84. checked: IUpdateUserPreferencesVariables['checked'];
  85. listener: (result: UpdateResult<IUserPreferenceSettings, unknown, IUpdateUserPreferencesVariables>) => void;
  86. onSuccess?: (settings: IUserPreferenceSettings) => void;
  87. onError?: (error: unknown) => void;
  88. }): Promise<void>;
  89. updateUserGlobalPreferences({ preferences, enabled, listener, onSuccess, onError, }: {
  90. preferences: IUpdateUserGlobalPreferencesVariables['preferences'];
  91. enabled?: IUpdateUserGlobalPreferencesVariables['enabled'];
  92. listener: (result: UpdateResult<IUserGlobalPreferenceSettings, unknown, IUpdateUserGlobalPreferencesVariables>) => void;
  93. onSuccess?: (settings: IUserGlobalPreferenceSettings) => void;
  94. onError?: (error: unknown) => void;
  95. }): Promise<void>;
  96. markNotificationsAsRead({ messageId, listener, onSuccess, onError, }: {
  97. messageId: IMessageId;
  98. listener: (result: UpdateResult<IMessage[], unknown, {
  99. messageId: IMessageId;
  100. }>) => void;
  101. onSuccess?: (message: IMessage[]) => void;
  102. onError?: (error: unknown) => void;
  103. }): Promise<void>;
  104. markNotificationsAsSeen({ messageId, listener, onSuccess, onError, }: {
  105. messageId: IMessageId;
  106. listener: (result: UpdateResult<IMessage[], unknown, {
  107. messageId: IMessageId;
  108. }>) => void;
  109. onSuccess?: (message: IMessage[]) => void;
  110. onError?: (error: unknown) => void;
  111. }): Promise<void>;
  112. markNotificationsAs({ messageId, mark, listener, onSuccess, onError, }: {
  113. messageId: IMessageId;
  114. mark: {
  115. seen?: boolean;
  116. read?: boolean;
  117. };
  118. listener: (result: UpdateResult<IMessage[], unknown, {
  119. messageId: IMessageId;
  120. }>) => void;
  121. onSuccess?: (message: IMessage[]) => void;
  122. onError?: (error: unknown) => void;
  123. }): Promise<void>;
  124. removeNotification({ messageId, listener, onSuccess, onError, }: {
  125. messageId: string;
  126. listener: (result: UpdateResult<IMessage, unknown, {
  127. messageId: string;
  128. }>) => void;
  129. onSuccess?: (message: IMessage) => void;
  130. onError?: (error: unknown) => void;
  131. }): Promise<void>;
  132. removeNotifications({ messageIds, listener, onSuccess, onError, }: {
  133. messageIds: string[];
  134. listener: (result: UpdateResult<void, unknown, {
  135. messageIds: string[];
  136. }>) => void;
  137. onSuccess?: (obj: void) => void;
  138. onError?: (error: unknown) => void;
  139. }): Promise<void>;
  140. updateAction({ messageId, actionButtonType, status, payload, listener, onSuccess, onError, }: {
  141. messageId: IUpdateActionVariables['messageId'];
  142. actionButtonType: IUpdateActionVariables['actionButtonType'];
  143. status: IUpdateActionVariables['status'];
  144. payload?: IUpdateActionVariables['payload'];
  145. listener: (result: UpdateResult<IMessage, unknown, IUpdateActionVariables>) => void;
  146. onSuccess?: (data: IMessage) => void;
  147. onError?: (error: unknown) => void;
  148. }): Promise<void>;
  149. markAllMessagesAsRead({ listener, onSuccess, onError, feedId, }: {
  150. listener: (result: UpdateResult<number, unknown, undefined>) => void;
  151. onSuccess?: (count: number) => void;
  152. onError?: (error: unknown) => void;
  153. feedId?: IFeedId;
  154. }): Promise<void>;
  155. markAllMessagesAsSeen({ listener, onSuccess, onError, feedId, }: {
  156. listener: (result: UpdateResult<number, unknown, undefined>) => void;
  157. onSuccess?: (count: number) => void;
  158. onError?: (error: unknown) => void;
  159. feedId?: IFeedId;
  160. }): Promise<void>;
  161. removeAllNotifications({ feedId, listener, onSuccess, onError, }: {
  162. feedId?: string;
  163. listener: (result: UpdateResult<void, unknown, undefined>) => void;
  164. onSuccess?: () => void;
  165. onError?: (error: unknown) => void;
  166. }): Promise<void>;
  167. }
  168. //# sourceMappingURL=headless.service.d.ts.map