@messenger-box/platform-server 10.0.3-alpha.7 → 10.0.3-alpha.74

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.
Files changed (202) hide show
  1. package/lib/config/env-config.d.ts +7 -0
  2. package/lib/config/env-config.js +20 -0
  3. package/lib/config/env-config.js.map +1 -1
  4. package/lib/containers/containers.js +9 -1
  5. package/lib/containers/containers.js.map +1 -1
  6. package/lib/containers/context-services-from-container.d.ts +1 -1
  7. package/lib/containers/context-services-from-container.js +4 -2
  8. package/lib/containers/context-services-from-container.js.map +1 -1
  9. package/lib/graphql/resolvers/ai-fragment.d.ts +3 -0
  10. package/lib/graphql/resolvers/ai-fragment.js +276 -0
  11. package/lib/graphql/resolvers/ai-fragment.js.map +1 -0
  12. package/lib/graphql/resolvers/channel-member.d.ts +3 -2
  13. package/lib/graphql/resolvers/channel-member.js +30 -5
  14. package/lib/graphql/resolvers/channel-member.js.map +1 -1
  15. package/lib/graphql/resolvers/channel.d.ts +3 -2
  16. package/lib/graphql/resolvers/channel.js +308 -53
  17. package/lib/graphql/resolvers/channel.js.map +1 -1
  18. package/lib/graphql/resolvers/extended-token-account.d.ts +3 -2
  19. package/lib/graphql/resolvers/extended-token-account.js +90 -23
  20. package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
  21. package/lib/graphql/resolvers/index.d.ts +1 -1
  22. package/lib/graphql/resolvers/index.js +1 -1
  23. package/lib/graphql/resolvers/index.js.map +1 -1
  24. package/lib/graphql/resolvers/post-thread.d.ts +1 -1
  25. package/lib/graphql/resolvers/post-thread.js +294 -132
  26. package/lib/graphql/resolvers/post-thread.js.map +1 -1
  27. package/lib/graphql/resolvers/post.d.ts +2 -3
  28. package/lib/graphql/resolvers/post.js +874 -239
  29. package/lib/graphql/resolvers/post.js.map +1 -1
  30. package/lib/graphql/resolvers/reaction.d.ts +3 -2
  31. package/lib/graphql/resolvers/reaction.js +96 -14
  32. package/lib/graphql/resolvers/reaction.js.map +1 -1
  33. package/lib/graphql/schema/ai-fragment.graphql +311 -0
  34. package/lib/graphql/schema/ai-fragment.graphql.js +1 -0
  35. package/lib/graphql/schema/ai-fragment.graphql.js.map +1 -0
  36. package/lib/graphql/schema/channel-member.graphql +110 -21
  37. package/lib/graphql/schema/channel-member.graphql.js +1 -1
  38. package/lib/graphql/schema/channel.graphql +356 -38
  39. package/lib/graphql/schema/channel.graphql.js +1 -1
  40. package/lib/graphql/schema/index.js +2 -2
  41. package/lib/graphql/schema/index.js.map +1 -1
  42. package/lib/graphql/schema/post-thread.graphql +167 -21
  43. package/lib/graphql/schema/post-thread.graphql.js +1 -1
  44. package/lib/graphql/schema/post.graphql +360 -40
  45. package/lib/graphql/schema/post.graphql.js +1 -1
  46. package/lib/graphql/schema/reaction.graphql +71 -13
  47. package/lib/graphql/schema/reaction.graphql.js +1 -1
  48. package/lib/graphql/schema/services.graphql +21 -0
  49. package/lib/graphql/schema/users.graphql +76 -13
  50. package/lib/graphql/schema/users.graphql.js +1 -1
  51. package/lib/index.js +1 -1
  52. package/lib/index.js.map +1 -1
  53. package/lib/inngest/factory.d.ts +20 -0
  54. package/lib/inngest/factory.js +4 -0
  55. package/lib/inngest/factory.js.map +1 -0
  56. package/lib/inngest/functions.d.ts +235 -0
  57. package/lib/inngest/functions.js +1385 -0
  58. package/lib/inngest/functions.js.map +1 -0
  59. package/lib/inngest/index.d.ts +3 -0
  60. package/lib/inngest/prompt.d.ts +6 -0
  61. package/lib/inngest/prompt.js +871 -0
  62. package/lib/inngest/prompt.js.map +1 -0
  63. package/lib/inngest/utils.d.ts +5 -0
  64. package/lib/inngest/utils.js +32 -0
  65. package/lib/inngest/utils.js.map +1 -0
  66. package/lib/interfaces/index.d.ts +0 -1
  67. package/lib/interfaces/services.d.ts +1 -1
  68. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.d.ts +17 -0
  69. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js +44 -0
  70. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js.map +1 -0
  71. package/lib/migrations/dbMigrations/index.d.ts +1 -0
  72. package/lib/migrations/index.d.ts +1 -0
  73. package/lib/migrations/mail-template-migration.js +1 -1
  74. package/lib/migrations/message-notification-template-migration.d.ts +1 -1
  75. package/lib/migrations/message-notification-template-migration.js +1 -1
  76. package/lib/module.js +10 -3
  77. package/lib/module.js.map +1 -1
  78. package/lib/plugins/ai-fragment-moleculer-service.d.ts +29 -0
  79. package/lib/plugins/ai-fragment-moleculer-service.js +516 -0
  80. package/lib/plugins/ai-fragment-moleculer-service.js.map +1 -0
  81. package/lib/plugins/channel-moleculer-service.d.ts +21 -1
  82. package/lib/plugins/channel-moleculer-service.js +426 -115
  83. package/lib/plugins/channel-moleculer-service.js.map +1 -1
  84. package/lib/plugins/extended-token-account-moleculer-service.d.ts +25 -1
  85. package/lib/plugins/extended-token-account-moleculer-service.js +348 -22
  86. package/lib/plugins/extended-token-account-moleculer-service.js.map +1 -1
  87. package/lib/plugins/index.d.ts +1 -0
  88. package/lib/plugins/messenger-notification-moleculer-service.d.ts +27 -3
  89. package/lib/plugins/messenger-notification-moleculer-service.js +404 -58
  90. package/lib/plugins/messenger-notification-moleculer-service.js.map +1 -1
  91. package/lib/plugins/post-moleculer-service.d.ts +85 -21
  92. package/lib/plugins/post-moleculer-service.js +1102 -256
  93. package/lib/plugins/post-moleculer-service.js.map +1 -1
  94. package/lib/plugins/post-thread-moleculer-service.d.ts +33 -1
  95. package/lib/plugins/post-thread-moleculer-service.js +326 -8
  96. package/lib/plugins/post-thread-moleculer-service.js.map +1 -1
  97. package/lib/plugins/reaction-moleculer-service.js +1 -1
  98. package/lib/plugins/reaction-moleculer-service.js.map +1 -1
  99. package/lib/preferences/settings/post-settings.d.ts +2 -0
  100. package/lib/preferences/settings/post-settings.js +47 -9
  101. package/lib/preferences/settings/post-settings.js.map +1 -1
  102. package/lib/services/ai-fragment-service.d.ts +195 -0
  103. package/lib/services/ai-fragment-service.js +631 -0
  104. package/lib/services/ai-fragment-service.js.map +1 -0
  105. package/lib/services/channel-service.d.ts +181 -33
  106. package/lib/services/channel-service.js +842 -273
  107. package/lib/services/channel-service.js.map +1 -1
  108. package/lib/services/extended-token-account-service.d.ts +130 -14
  109. package/lib/services/extended-token-account-service.js +462 -52
  110. package/lib/services/extended-token-account-service.js.map +1 -1
  111. package/lib/services/index.d.ts +3 -0
  112. package/lib/services/messenger-notification-service.d.ts +106 -13
  113. package/lib/services/messenger-notification-service.js +824 -442
  114. package/lib/services/messenger-notification-service.js.map +1 -1
  115. package/lib/services/post-service.d.ts +189 -16
  116. package/lib/services/post-service.js +949 -113
  117. package/lib/services/post-service.js.map +1 -1
  118. package/lib/services/post-thread-service.d.ts +114 -5
  119. package/lib/services/post-thread-service.js +400 -13
  120. package/lib/services/post-thread-service.js.map +1 -1
  121. package/lib/services/proxy-services/ai-fragment-microservice.d.ts +23 -0
  122. package/lib/services/proxy-services/ai-fragment-microservice.js +78 -0
  123. package/lib/services/proxy-services/ai-fragment-microservice.js.map +1 -0
  124. package/lib/services/proxy-services/channel-microservice.d.ts +6 -3
  125. package/lib/services/proxy-services/channel-microservice.js +25 -10
  126. package/lib/services/proxy-services/channel-microservice.js.map +1 -1
  127. package/lib/services/proxy-services/index.d.ts +1 -0
  128. package/lib/services/proxy-services/messenger-notification-microservice.d.ts +128 -8
  129. package/lib/services/proxy-services/messenger-notification-microservice.js +324 -29
  130. package/lib/services/proxy-services/messenger-notification-microservice.js.map +1 -1
  131. package/lib/services/proxy-services/post-microservice.d.ts +207 -12
  132. package/lib/services/proxy-services/post-microservice.js +623 -54
  133. package/lib/services/proxy-services/post-microservice.js.map +1 -1
  134. package/lib/services/proxy-services/post-thread-microservice.d.ts +134 -3
  135. package/lib/services/proxy-services/post-thread-microservice.js +388 -6
  136. package/lib/services/proxy-services/post-thread-microservice.js.map +1 -1
  137. package/lib/services/proxy-services/reaction-microservice.d.ts +161 -3
  138. package/lib/services/proxy-services/reaction-microservice.js +474 -2
  139. package/lib/services/proxy-services/reaction-microservice.js.map +1 -1
  140. package/lib/services/reaction-service.d.ts +124 -4
  141. package/lib/services/reaction-service.js +415 -3
  142. package/lib/services/reaction-service.js.map +1 -1
  143. package/lib/services/redis-cache-manager.d.ts +18 -0
  144. package/lib/services/redis-cache-manager.js +83 -0
  145. package/lib/services/redis-cache-manager.js.map +1 -0
  146. package/lib/services/sandbox-error-service.d.ts +23 -0
  147. package/lib/services/sandbox-error-service.js +422 -0
  148. package/lib/services/sandbox-error-service.js.map +1 -0
  149. package/lib/store/models/account-token-store.d.ts +1 -1
  150. package/lib/store/models/account-token-store.js.map +1 -1
  151. package/lib/store/models/ai-fragment.d.ts +4 -0
  152. package/lib/store/models/ai-fragment.js +125 -0
  153. package/lib/store/models/ai-fragment.js.map +1 -0
  154. package/lib/store/models/channel.d.ts +2 -3
  155. package/lib/store/models/channel.js +185 -71
  156. package/lib/store/models/channel.js.map +1 -1
  157. package/lib/store/models/index.d.ts +1 -0
  158. package/lib/store/models/post-thread.d.ts +3 -3
  159. package/lib/store/models/post-thread.js +96 -14
  160. package/lib/store/models/post-thread.js.map +1 -1
  161. package/lib/store/models/post.d.ts +2 -3
  162. package/lib/store/models/post.js +143 -23
  163. package/lib/store/models/post.js.map +1 -1
  164. package/lib/store/models/reaction.d.ts +2 -3
  165. package/lib/store/models/reaction.js +67 -8
  166. package/lib/store/models/reaction.js.map +1 -1
  167. package/lib/store/repositories/__tests__/__fixtures__/team-repository.d.ts +3 -3
  168. package/lib/store/repositories/ai-fragment-repository.d.ts +15 -0
  169. package/lib/store/repositories/ai-fragment-repository.js +69 -0
  170. package/lib/store/repositories/ai-fragment-repository.js.map +1 -0
  171. package/lib/store/repositories/channel-repository.d.ts +6 -6
  172. package/lib/store/repositories/channel-repository.js +5 -2
  173. package/lib/store/repositories/channel-repository.js.map +1 -1
  174. package/lib/store/repositories/index.d.ts +1 -0
  175. package/lib/store/repositories/post-repository.d.ts +6 -6
  176. package/lib/store/repositories/post-repository.js +5 -2
  177. package/lib/store/repositories/post-repository.js.map +1 -1
  178. package/lib/store/repositories/post-thread-repository.d.ts +6 -6
  179. package/lib/store/repositories/post-thread-repository.js +5 -2
  180. package/lib/store/repositories/post-thread-repository.js.map +1 -1
  181. package/lib/store/repositories/reaction-repository.d.ts +6 -6
  182. package/lib/store/repositories/reaction-repository.js +5 -2
  183. package/lib/store/repositories/reaction-repository.js.map +1 -1
  184. package/lib/templates/constants/SERVER_TYPES.ts.template +4 -4
  185. package/lib/templates/repositories/AiFragmentRepository.ts.template +4 -0
  186. package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
  187. package/lib/templates/repositories/PostRepository.ts.template +3 -3
  188. package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
  189. package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
  190. package/lib/templates/services/AiFragmentService.ts.template +123 -0
  191. package/lib/templates/services/ChannelService.ts.template +290 -39
  192. package/lib/templates/services/ExtendedTokenAccountService.ts.template +104 -9
  193. package/lib/templates/services/MessengerNotificationService.ts.template +94 -19
  194. package/lib/templates/services/PostService.ts.template +265 -20
  195. package/lib/templates/services/PostThreadService.ts.template +151 -6
  196. package/lib/templates/services/ReactionService.ts.template +129 -3
  197. package/lib/templates/services/RedisCacheManager.ts.template +22 -0
  198. package/lib/templates/services/SandboxErrorService.ts.template +125 -0
  199. package/package.json +14 -7
  200. package/lib/interfaces/context.d.ts +0 -14
  201. package/lib/store/models/common-options.js +0 -20
  202. package/lib/store/models/common-options.js.map +0 -1
@@ -1,37 +1,45 @@
1
- import { IPost,IExpoNotificationData } from 'common';
1
+ /**
2
+ * Messenger Notification Service Interface
3
+ * --------------------------------------
4
+ *
5
+ * This interface defines the business logic layer for notification management within
6
+ * the messenger platform. It provides a comprehensive set of operations for
7
+ * handling various types of notifications including push notifications, message alerts,
8
+ * and Expo-specific notifications.
9
+ *
10
+ * Key capabilities:
11
+ * - Unread message notifications
12
+ * - Post-based notifications
13
+ * - Alert message handling
14
+ * - Expo push notification integration
15
+ * - Service message notifications
16
+ * - Support service configuration
17
+ */
18
+
19
+ import { IPost, IExpoNotificationData, IBaseService, AsDomainType, Disposable } from 'common/server';
20
+
2
21
  export enum NotificationDurationUnitEnum {
3
22
  days = 'days',
4
23
  hours = 'hours',
5
24
  minutes = 'minutes',
6
25
  seconds = 'seconds',
7
26
  }
27
+
8
28
  export type IExpoNotification = any;
9
29
  export type IExpoNotificationTo = string | string[];
10
- export type IExpoNotificationBodyData = {
30
+
31
+ export interface IExpoNotificationBodyData {
11
32
  url: string;
12
33
  params: object;
13
34
  title?: string;
14
35
  body?: string;
15
36
  screen?: string;
16
37
  senderId?: string;
17
- thread?: { id: string; extraParams?: object };
38
+ thread?: {
39
+ id: string;
40
+ extraParams?: object
41
+ };
18
42
  other?: object;
19
- };
20
- // export interface IExpoNotificationData {
21
- // to: IExpoNotificationTo;
22
- // data?: IExpoNotificationBodyData;
23
- // title: string;
24
- // body: any;
25
- // sound?: any;
26
- // }
27
- export interface IMessengerNotificationService {
28
- sendNotificationOfUnreadMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
29
- sendNotificationOnPost(post: IPost): Promise<Boolean>;
30
- sendNotificationOfAlertMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
31
- sendPushNotificationsExpo(data: IExpoNotificationData): Promise<IExpoNotification>;
32
- sendExpoNotificationOnPost(post: IPost, notificationData?: IExpoNotificationBodyData): Promise<Boolean>;
33
- sendNotificationOfUnreadServiceMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
34
- setSupportServiceConfig?(config: any): Promise<void>;
35
43
  }
36
44
 
37
45
  export interface ISupportServiceConfig {
@@ -39,3 +47,70 @@ export interface ISupportServiceConfig {
39
47
  templateId?: string;
40
48
  variables?: object;
41
49
  }
50
+
51
+ export interface IMessengerNotificationService extends IBaseService<IPost>, Disposable {
52
+ /**
53
+ * Sends notifications for unread messages based on duration
54
+ *
55
+ * @param {NotificationDurationUnitEnum} unit - Time unit for notification check
56
+ * @param {number} value - Duration value in specified unit
57
+ * @returns {Promise<void>}
58
+ */
59
+ sendNotificationOfUnreadMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
60
+
61
+ /**
62
+ * Sends a notification when a new post is created
63
+ *
64
+ * @param {AsDomainType<IPost>} post - The post that triggered the notification
65
+ * @returns {Promise<Boolean>}
66
+ */
67
+ sendNotificationOnPost(post: AsDomainType<IPost>): Promise<Boolean>;
68
+
69
+ /**
70
+ * Sends notifications for alert messages based on duration
71
+ *
72
+ * @param {NotificationDurationUnitEnum} unit - Time unit for alert check
73
+ * @param {number} value - Duration value in specified unit
74
+ * @returns {Promise<void>}
75
+ */
76
+ sendNotificationOfAlertMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
77
+
78
+ /**
79
+ * Sends push notifications through Expo service
80
+ *
81
+ * @param {IExpoNotificationData} data - The notification data to send
82
+ * @returns {Promise<IExpoNotification>}
83
+ */
84
+ sendPushNotificationsExpo(data: IExpoNotificationData): Promise<IExpoNotification>;
85
+
86
+ /**
87
+ * Sends an Expo notification for a specific post
88
+ *
89
+ * @param {AsDomainType<IPost>} post - The post to send notification for
90
+ * @param {IExpoNotificationBodyData} [notificationData] - Optional custom notification data
91
+ * @returns {Promise<Boolean>}
92
+ */
93
+ sendExpoNotificationOnPost(post: AsDomainType<IPost>, notificationData?: IExpoNotificationBodyData): Promise<Boolean>;
94
+
95
+ /**
96
+ * Sends notifications for unread service messages based on duration
97
+ *
98
+ * @param {NotificationDurationUnitEnum} unit - Time unit for service message check
99
+ * @param {number} value - Duration value in specified unit
100
+ * @returns {Promise<void>}
101
+ */
102
+ sendNotificationOfUnreadServiceMessages(unit: NotificationDurationUnitEnum, value: number): Promise<void>;
103
+
104
+ /**
105
+ * Configures the support service settings
106
+ *
107
+ * @param {ISupportServiceConfig} config - Support service configuration
108
+ * @returns {Promise<void>}
109
+ */
110
+ setSupportServiceConfig?(config: ISupportServiceConfig): Promise<void>;
111
+
112
+ /**
113
+ * Disposes of resources used by the service
114
+ */
115
+ dispose(): void;
116
+ }
@@ -1,42 +1,287 @@
1
- import { IBaseService } from '@common-stack/store-mongo';
2
- import { IFileInfo, IMessageIdentifier, IPost, IPostThread, IThreadMessageInput, IUploadedFileInput } from 'common';
1
+ /**
2
+ * Post Service Interface
3
+ * ----------------------
4
+ *
5
+ * This interface defines the business logic layer for post and message management
6
+ * within the messenger platform. It provides comprehensive operations for handling
7
+ * messages, file attachments, threading, and message state management across
8
+ * different channels and communication contexts.
9
+ *
10
+ * Key capabilities:
11
+ * - Post lifecycle management (creation, updates, deletion)
12
+ * - File upload and attachment handling (single and batch operations)
13
+ * - Message threading and conversation management
14
+ * - Message delivery and read status tracking
15
+ * - File management and cleanup operations
16
+ * - Cross-channel message coordination
17
+ * - Post-thread relationship management
18
+ * - Message state synchronization
19
+ *
20
+ * The service layer abstracts complex messaging operations and provides a
21
+ * cohesive API for post-related functionality throughout the messaging platform,
22
+ * handling file storage, threading logic, and message state consistency.
23
+ */
3
24
 
4
- export interface IPostServiceInput extends Omit<IPost, 'id' | 'files' | 'isRead' | 'isDelivered'> {
25
+ import {
26
+ IFileInfo,
27
+ IMessageIdentifier,
28
+ IPost,
29
+ IPostModel,
30
+ IPostThread,
31
+ IThreadMessageInput,
32
+ IUploadedFileInput,
33
+ Disposable,
34
+ AsDomainType,
35
+ IBaseService,
36
+ IFileUpdateResponse
37
+ } from 'common/server';
38
+
39
+ /**
40
+ * Code Agent Request Interface
41
+ *
42
+ * @description Input parameters for code agent operations,
43
+ * containing project details and configuration.
44
+ */
45
+ export enum AiAgentMessageRole {
46
+ USER = 'USER',
47
+ ASSISTANT = 'ASSISTANT',
48
+ }
49
+
50
+ export enum AiAgentMessageType {
51
+ RESULT = 'RESULT',
52
+ ERROR = 'ERROR',
53
+ }
54
+
55
+ export interface ICodeAgentRequest {
56
+ /** The input value or prompt for the code agent */
57
+ value: string;
58
+ /** The unique identifier of the project */
59
+ projectId: string;
60
+ /** Optional message identifier */
61
+ messageId?: string;
62
+ /** Owner of the project */
63
+ owner: string;
64
+ /** Organization name */
65
+ orgName: string;
66
+ /** Optional model configuration */
67
+ modelConfig?: any;
68
+ }
69
+
70
+ /**
71
+ * Post Service Input Interface
72
+ *
73
+ * @description Input parameters for post creation operations,
74
+ * excluding auto-generated and system-managed fields.
75
+ */
76
+ export interface IPostServiceInput extends Omit<IPostModel, 'id' | 'files' | 'isRead' | 'isDelivered' | '_id'> {
77
+ /** Array of file identifiers to attach to the post */
5
78
  files: string[];
79
+ /** Optional MongoDB ObjectId for the post */
6
80
  _id?: any;
7
81
  }
8
82
 
83
+ /**
84
+ * Post Thread Creation Options
85
+ *
86
+ * @description Configuration parameters for creating posts with associated threads.
87
+ */
9
88
  export type CreatePostThreadOptions = {
89
+ /** Thread message input data */
10
90
  threadMessageInput: IThreadMessageInput;
91
+ /** Channel identifier where the post will be created */
11
92
  channelId: string;
93
+ /** Optional responder user identifier */
12
94
  responderId?: string;
95
+ /** Optional parent post identifier for threading */
13
96
  postParentId?: string;
97
+ /** Optional existing post identifier */
14
98
  postId?: string;
99
+ /** Account identifier of the post creator */
15
100
  accountId: string;
101
+ /** Optional organization identifier */
16
102
  orgId?: string;
103
+ /** Optional existing post thread identifier */
17
104
  postThreadId?: string;
18
105
  };
19
106
 
20
- export interface IPostService extends IBaseService<IPost, IPostServiceInput, Partial<IPost>> {
21
- createFileUploadLink(postId: string, filename: string, userId: string): Promise<string>;
22
- attachUploadedFile(postId: string, file: IUploadedFileInput, createdBy: string): Promise<IFileInfo>;
107
+ /**
108
+ * Post Service Interface
109
+ *
110
+ * @description Provides comprehensive post and message management capabilities
111
+ * including file handling, threading, and message state management.
112
+ */
113
+ export interface IPostService extends IBaseService<IPostModel, IPostServiceInput, Partial<IPostModel>>, Disposable {
114
+ /**
115
+ * Creates a file upload link for a specific post
116
+ *
117
+ * @description Generates a secure upload URL for attaching a single file
118
+ * to an existing post, handling authentication and storage permissions.
119
+ *
120
+ * @param {string} postId - The unique identifier of the post
121
+ * @param {string} filename - The name of the file to upload
122
+ * @param {string} userId - The identifier of the user performing the upload
123
+ * @returns {Promise<string | Error>} - Upload URL or error
124
+ */
125
+ createFileUploadLink(postId: string, filename: string, userId: string): Promise<string | Error>;
126
+
127
+ /**
128
+ * Attaches an uploaded file to a post
129
+ *
130
+ * @description Associates a successfully uploaded file with a post,
131
+ * updating the post's file attachments and metadata.
132
+ *
133
+ * @param {string} postId - The unique identifier of the post
134
+ * @param {IUploadedFileInput} file - The uploaded file information
135
+ * @param {string} createdBy - The identifier of the user who uploaded the file
136
+ * @returns {Promise<IFileInfo | Error>} - File information or error
137
+ */
138
+ attachUploadedFile(postId: string, file: IUploadedFileInput, createdBy: string): Promise<IFileInfo | Error>;
139
+
140
+ /**
141
+ * Creates multiple file upload links for a post
142
+ *
143
+ * @description Generates secure upload URLs for attaching multiple files
144
+ * to an existing post in a single operation.
145
+ *
146
+ * @param {string} postId - The unique identifier of the post
147
+ * @param {string[]} filenames - Array of file names to upload
148
+ * @param {string} userId - The identifier of the user performing the upload
149
+ * @returns {Promise<string[] | Error>} - Array of upload URLs or error
150
+ */
151
+ createFilesUploadLink(postId: string, filenames: string[], userId: string): Promise<string[] | Error>;
152
+
153
+ /**
154
+ * Attaches multiple uploaded files to a post
155
+ *
156
+ * @description Associates multiple successfully uploaded files with a post
157
+ * in a single batch operation, optimizing performance and consistency.
158
+ *
159
+ * @param {string} postId - The unique identifier of the post
160
+ * @param {IUploadedFileInput[]} files - Array of uploaded file information
161
+ * @param {string} createdBy - The identifier of the user who uploaded the files
162
+ * @returns {Promise<IFileInfo[] | Error>} - Array of file information or error
163
+ */
164
+ attachUploadedFiles(postId: string, files: IUploadedFileInput[], createdBy: string): Promise<IFileInfo[] | Error>;
165
+
166
+ /**
167
+ * Deletes a file from storage
168
+ *
169
+ * @description Permanently removes a file from the storage system,
170
+ * typically used for cleanup or when files are no longer needed.
171
+ *
172
+ * @param {string} url - The URL or identifier of the file to delete
173
+ * @returns {Promise<boolean | Error>} - Success status or error
174
+ */
175
+ deleteFile(url: string): Promise<boolean | Error>;
176
+
177
+ /**
178
+ * Marks a message as read by a user
179
+ *
180
+ * @description Updates the read status of a message for a specific user,
181
+ * affecting unread counts and notification states.
182
+ *
183
+ * @param {IMessageIdentifier} messageId - The message identifier
184
+ * @param {string} user - The identifier of the user marking the message as read
185
+ * @returns {Promise<boolean | Error>} - Success status or error
186
+ */
187
+ readMessage(messageId: IMessageIdentifier, user: string): Promise<boolean | Error>;
188
+
189
+ /**
190
+ * Marks a message as delivered to a user
191
+ *
192
+ * @description Updates the delivery status of a message, indicating
193
+ * successful delivery to the target user's device or client.
194
+ *
195
+ * @param {IMessageIdentifier} messageId - The message identifier
196
+ * @param {string} user - The identifier of the user who received the message
197
+ * @returns {Promise<boolean | Error>} - Success status or error
198
+ */
199
+ deliverMessage(messageId: IMessageIdentifier, user: string): Promise<boolean | Error>;
200
+
201
+ /**
202
+ * Creates a post without triggering subscriptions
203
+ *
204
+ * @description Creates a new post while bypassing real-time subscription
205
+ * notifications, useful for bulk operations or system-generated content.
206
+ *
207
+ * @param {IPostServiceInput} data - The post creation data
208
+ * @returns {Promise<AsDomainType<IPostModel> | Error>} - Created post or error
209
+ */
210
+ createWithoutSubscription(data: IPostServiceInput): Promise<AsDomainType<IPostModel> | Error>;
211
+
212
+ /**
213
+ * Creates a post with an associated thread
214
+ *
215
+ * @description Creates both a post and its associated thread in a single
216
+ * transaction, ensuring data consistency and proper relationship setup.
217
+ *
218
+ * @param {CreatePostThreadOptions} options - The post and thread creation options
219
+ * @returns {Promise<{ post: AsDomainType<IPostModel>; postThread: IPostThread } | Error>} - Created post and thread or error
220
+ */
221
+ createPostWithPostThread(options: CreatePostThreadOptions): Promise<{ post: AsDomainType<IPostModel>; postThread: IPostThread } | Error>;
222
+
223
+ /**
224
+ * Retrieves the most recent message from a channel
225
+ *
226
+ * @description Fetches the latest post/message from a specific channel,
227
+ * useful for displaying channel previews and recent activity.
228
+ *
229
+ * @param {string} channelId - The unique identifier of the channel
230
+ * @returns {Promise<AsDomainType<IPostModel> | Error>} - Latest message or error
231
+ */
232
+ getLastMessage(channelId: string): Promise<AsDomainType<IPostModel> | Error>;
23
233
 
24
- createFilesUploadLink(postId: string, filenames: string[], userId: string): Promise<string[]>;
25
- attachUploadedFiles(postId: string, files: IUploadedFileInput[], createdBy: string): Promise<IFileInfo[]>;
234
+ /**
235
+ * Retrieves previous messages from a channel
236
+ *
237
+ * @description Fetches a specified number of recent messages from a channel,
238
+ * formatted for display with associated file attachments. Returns messages
239
+ * in reverse chronological order (newest to oldest).
240
+ *
241
+ * @param {string} channelId - The unique identifier of the channel
242
+ * @param {number} limit - Maximum number of messages to retrieve (default: 5)
243
+ * @returns {Promise<Array<IPostModel> | Error>} - Array of formatted messages or error
244
+ */
245
+ getPreviousMessagesByProjectId(projectId: string, limit?: number): Promise<Array<IPostModel> | Error>;
26
246
 
27
- deleteFile(url: string): Promise<boolean>;
247
+ /**
248
+ * Saves code agent result with comprehensive data
249
+ *
250
+ * @description Saves the result from a code agent operation including message creation,
251
+ * fragment generation, and project update publishing. Handles both success and error cases
252
+ * with proper message creation and fragment management.
253
+ *
254
+ * @param {ICodeAgentRequest} request - The code agent request containing project details
255
+ * @param {string} sandboxUrl - URL of the generated sandbox
256
+ * @param {string} fragmentTitle - Title for the generated fragment
257
+ * @param {string} responseContent - Content of the AI response
258
+ * @param {{ [path: string]: string }} files - Generated files with their paths and content
259
+ * @param {string} summary - Summary of the generated content
260
+ * @param {boolean} isError - Whether the operation resulted in an error
261
+ * @param {any[]} canvasLayers - Optional canvas layers for visual components
262
+ * @returns {Promise<any>} - Created message document or error
263
+ */
264
+ saveCodeAgentResult(
265
+ request: ICodeAgentRequest,
266
+ sandboxUrl: string,
267
+ fragmentTitle: string,
268
+ responseContent: string,
269
+ files: { [path: string]: string },
270
+ summary: string,
271
+ isError: boolean,
272
+ canvasLayers?: any[],
273
+ ): Promise<any>;
28
274
 
29
- readMessage(messageId: IMessageIdentifier, user: string): Promise<boolean>;
30
275
 
31
- deliverMessage(messageId: IMessageIdentifier, user: string): Promise<boolean>;
32
- createWithoutSubscription(data: IPostServiceInput): Promise<IPost>;
276
+ updateSandboxFile(
277
+ projectId: string,
278
+ messageId: string,
279
+ filePath: string,
280
+ content: string,
281
+ ): Promise<IFileUpdateResponse>;
33
282
 
34
- createPostWithPostThread({
35
- threadMessageInput,
36
- channelId,
37
- responderId,
38
- postParentId,
39
- postId,
40
- accountId,
41
- }: CreatePostThreadOptions): Promise<{ post: IPost; postThread: IPostThread }>;
283
+ /**
284
+ * Disposes of resources used by the service
285
+ */
286
+ dispose(): void;
42
287
  }
@@ -1,10 +1,155 @@
1
- import { IPostThread } from 'common';
2
- import { IBaseService } from '@common-stack/store-mongo';
1
+ /**
2
+ * Post Thread Service Interface
3
+ * -----------------------------
4
+ *
5
+ * This interface defines the business logic layer for post thread management
6
+ * within the messenger platform. It provides comprehensive operations for handling
7
+ * threaded conversations, reply management, and discussion organization across
8
+ * different channels and messaging contexts.
9
+ *
10
+ * Key capabilities:
11
+ * - Thread lifecycle management (creation, updates, deletion)
12
+ * - Reply and response tracking within threads
13
+ * - Thread participant management and notifications
14
+ * - Thread statistics and metrics collection
15
+ * - Nested conversation organization
16
+ * - Thread visibility and access control
17
+ * - Cross-channel thread coordination
18
+ * - Thread state synchronization
19
+ *
20
+ * The service layer abstracts complex threading operations and provides a
21
+ * cohesive API for thread-related functionality throughout the messaging platform,
22
+ * handling conversation hierarchies, participant tracking, and thread state management.
23
+ */
3
24
 
4
- export interface IPostThreadServiceInput extends Omit<IPostThread, 'id'> {}
25
+ import { IPostThreadModel, Disposable, AsDomainType,IBaseService } from 'common/server';
5
26
 
6
- // export type IPostThreadService = IBaseService<IPostThread>;
7
27
 
8
- export interface IPostThreadService extends IBaseService<IPostThread> {
9
- getPostThread(data: any): Promise<IPostThread>;
28
+ /**
29
+ * Post Thread Service Input Interface
30
+ *
31
+ * @description Input parameters for post thread creation and update operations,
32
+ * excluding auto-generated fields like ID. Used for operations that modify
33
+ * thread data before it becomes a domain object.
34
+ */
35
+ export interface IPostThreadServiceInput extends Omit<IPostThreadModel, 'id'> {
36
+ // Add any additional input-specific fields here if needed
37
+ }
38
+
39
+ /**
40
+ * Post Thread Service Interface
41
+ *
42
+ * @description Provides comprehensive post thread management capabilities
43
+ * including thread creation, participant tracking, and conversation organization.
44
+ * All operations return domain objects wrapped with AsDomainType for consistency.
45
+ */
46
+ export interface IPostThreadService extends IBaseService<IPostThreadModel>, Disposable {
47
+ /**
48
+ * Retrieves a specific post thread with its metadata
49
+ *
50
+ * @description Fetches a complete post thread including all replies,
51
+ * participant information, and thread statistics for display and interaction.
52
+ *
53
+ * @param {string} threadId - The ID of the thread to retrieve
54
+ * @returns {Promise<AsDomainType<IPostThreadModel> | Error>} - Post thread data or error
55
+ */
56
+ getPostThread(threadId: string): Promise<AsDomainType<IPostThreadModel> | Error>;
57
+
58
+ /**
59
+ * Retrieves the total count of posts within a thread
60
+ *
61
+ * @description Calculates and returns the number of posts/replies
62
+ * within a specific thread for pagination and display purposes.
63
+ *
64
+ * @param {string} threadId - The ID of the thread to count posts for
65
+ * @returns {Promise<number | Error>} - Thread post count or error
66
+ */
67
+ getPostThreadCount(threadId: string): Promise<number | Error>;
68
+
69
+ /**
70
+ * Updates a post thread
71
+ *
72
+ * @description Updates the specified thread with new data while maintaining
73
+ * thread integrity and participant notifications.
74
+ *
75
+ * @param {string} threadId - The ID of the thread to update
76
+ * @param {Partial<IPostThreadServiceInput>} updates - The updates to apply
77
+ * @returns {Promise<AsDomainType<IPostThreadModel> | Error>} - Updated thread or error
78
+ */
79
+ updateThread(threadId: string, updates: Partial<IPostThreadServiceInput>): Promise<AsDomainType<IPostThreadModel> | Error>;
80
+
81
+ /**
82
+ * Deletes a post thread
83
+ *
84
+ * @description Soft deletes a thread while maintaining data integrity
85
+ * and notifying participants.
86
+ *
87
+ * @param {string} threadId - The ID of the thread to delete
88
+ * @returns {Promise<boolean | Error>} - Success status or error
89
+ */
90
+ deleteThread(threadId: string): Promise<boolean | Error>;
91
+
92
+ /**
93
+ * Gets threads by post ID
94
+ *
95
+ * @description Retrieves all threads associated with a specific post,
96
+ * useful for viewing conversation context.
97
+ *
98
+ * @param {string} postId - The ID of the post
99
+ * @returns {Promise<Array<AsDomainType<IPostThreadModel>> | Error>} - Array of threads or error
100
+ */
101
+ getThreadsByPost(postId: string): Promise<Array<AsDomainType<IPostThreadModel>> | Error>;
102
+
103
+ /**
104
+ * Gets threads by channel with pagination
105
+ *
106
+ * @description Retrieves paginated threads for a specific channel,
107
+ * ordered by relevance or time.
108
+ *
109
+ * @param {string} channelId - The ID of the channel
110
+ * @param {number} [limit] - Maximum number of threads to return
111
+ * @param {number} [offset] - Number of threads to skip
112
+ * @returns {Promise<Array<AsDomainType<IPostThreadModel>> | Error>} - Array of threads or error
113
+ */
114
+ getThreadsByChannel(channelId: string, limit?: number, offset?: number): Promise<Array<AsDomainType<IPostThreadModel>> | Error>;
115
+
116
+ /**
117
+ * Gets thread participants
118
+ *
119
+ * @description Retrieves all participants in a thread, including
120
+ * their participation status and roles.
121
+ *
122
+ * @param {string} threadId - The ID of the thread
123
+ * @returns {Promise<Array<string> | Error>} - Array of participant IDs or error
124
+ */
125
+ getThreadParticipants(threadId: string): Promise<Array<string> | Error>;
126
+
127
+ /**
128
+ * Adds a participant to a thread
129
+ *
130
+ * @description Adds a user as a participant to a thread,
131
+ * enabling notifications and access.
132
+ *
133
+ * @param {string} threadId - The ID of the thread
134
+ * @param {string} userId - The ID of the user to add
135
+ * @returns {Promise<boolean | Error>} - Success status or error
136
+ */
137
+ addParticipant(threadId: string, userId: string): Promise<boolean | Error>;
138
+
139
+ /**
140
+ * Removes a participant from a thread
141
+ *
142
+ * @description Removes a user's participation from a thread,
143
+ * updating notifications and access accordingly.
144
+ *
145
+ * @param {string} threadId - The ID of the thread
146
+ * @param {string} userId - The ID of the user to remove
147
+ * @returns {Promise<boolean | Error>} - Success status or error
148
+ */
149
+ removeParticipant(threadId: string, userId: string): Promise<boolean | Error>;
150
+
151
+ /**
152
+ * Disposes of resources used by the service
153
+ */
154
+ dispose(): void;
10
155
  }