@messenger-box/platform-server 10.0.3-alpha.2 → 10.0.3-alpha.201

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 (303) hide show
  1. package/lib/channels/ack-reactions.d.ts +46 -0
  2. package/lib/channels/ack-reactions.js +48 -0
  3. package/lib/channels/ack-reactions.js.map +1 -0
  4. package/lib/channels/allowlist-match.d.ts +38 -0
  5. package/lib/channels/allowlist-match.js +67 -0
  6. package/lib/channels/allowlist-match.js.map +1 -0
  7. package/lib/channels/channel-config.d.ts +46 -0
  8. package/lib/channels/channel-config.js +63 -0
  9. package/lib/channels/channel-config.js.map +1 -0
  10. package/lib/channels/command-gating.d.ts +47 -0
  11. package/lib/channels/command-gating.js +52 -0
  12. package/lib/channels/command-gating.js.map +1 -0
  13. package/lib/channels/conversation-label.d.ts +23 -0
  14. package/lib/channels/conversation-label.js +43 -0
  15. package/lib/channels/conversation-label.js.map +1 -0
  16. package/lib/channels/index.d.ts +18 -0
  17. package/lib/channels/mention-gating.d.ts +50 -0
  18. package/lib/channels/mention-gating.js +72 -0
  19. package/lib/channels/mention-gating.js.map +1 -0
  20. package/lib/channels/registry.d.ts +23 -0
  21. package/lib/channels/registry.js +282 -0
  22. package/lib/channels/registry.js.map +1 -0
  23. package/lib/channels/sender-identity.d.ts +11 -0
  24. package/lib/channels/sender-identity.js +48 -0
  25. package/lib/channels/sender-identity.js.map +1 -0
  26. package/lib/channels/session.d.ts +63 -0
  27. package/lib/channels/session.js +29 -0
  28. package/lib/channels/session.js.map +1 -0
  29. package/lib/channels/types.d.ts +147 -0
  30. package/lib/channels/types.js +28 -0
  31. package/lib/channels/types.js.map +1 -0
  32. package/lib/channels/typing.d.ts +62 -0
  33. package/lib/channels/typing.js +37 -0
  34. package/lib/channels/typing.js.map +1 -0
  35. package/lib/channels/typing.test.d.ts +1 -0
  36. package/lib/config/env-config.d.ts +7 -0
  37. package/lib/config/env-config.js +21 -1
  38. package/lib/config/env-config.js.map +1 -1
  39. package/lib/constants/default-channel-props.d.ts +11 -0
  40. package/lib/constants/default-channel-props.js +32 -0
  41. package/lib/constants/default-channel-props.js.map +1 -0
  42. package/lib/constants/default-notify-props.js.map +1 -1
  43. package/lib/constants/index.d.ts +1 -0
  44. package/lib/constants/query.constants.js.map +1 -1
  45. package/lib/containers/containers.js +13 -7
  46. package/lib/containers/containers.js.map +1 -1
  47. package/lib/containers/context-services-from-container.d.ts +2 -2
  48. package/lib/containers/context-services-from-container.js +7 -7
  49. package/lib/containers/context-services-from-container.js.map +1 -1
  50. package/lib/gateway/channel-registry.d.ts +10 -0
  51. package/lib/gateway/gateway-service.d.ts +23 -0
  52. package/lib/gateway/index.d.ts +4 -0
  53. package/lib/gateway/message-router.d.ts +20 -0
  54. package/lib/gateway/types.d.ts +270 -0
  55. package/lib/graphql/resolvers/channel-capabilities.d.ts +13 -0
  56. package/lib/graphql/resolvers/channel-capabilities.js +179 -0
  57. package/lib/graphql/resolvers/channel-capabilities.js.map +1 -0
  58. package/lib/graphql/resolvers/channel-member.d.ts +3 -3
  59. package/lib/graphql/resolvers/channel-member.js +30 -5
  60. package/lib/graphql/resolvers/channel-member.js.map +1 -1
  61. package/lib/graphql/resolvers/channel.d.ts +3 -3
  62. package/lib/graphql/resolvers/channel.js +348 -55
  63. package/lib/graphql/resolvers/channel.js.map +1 -1
  64. package/lib/graphql/resolvers/chat-configuration.d.ts +59 -0
  65. package/lib/graphql/resolvers/chat-configuration.js +89 -0
  66. package/lib/graphql/resolvers/chat-configuration.js.map +1 -0
  67. package/lib/graphql/resolvers/extended-token-account.d.ts +3 -32
  68. package/lib/graphql/resolvers/extended-token-account.js +90 -23
  69. package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
  70. package/lib/graphql/resolvers/gateway.d.ts +18 -0
  71. package/lib/graphql/resolvers/index.d.ts +47 -26
  72. package/lib/graphql/resolvers/index.js +1 -1
  73. package/lib/graphql/resolvers/index.js.map +1 -1
  74. package/lib/graphql/resolvers/post-thread.d.ts +2 -3
  75. package/lib/graphql/resolvers/post-thread.js +294 -132
  76. package/lib/graphql/resolvers/post-thread.js.map +1 -1
  77. package/lib/graphql/resolvers/post.d.ts +2 -3
  78. package/lib/graphql/resolvers/post.js +764 -237
  79. package/lib/graphql/resolvers/post.js.map +1 -1
  80. package/lib/graphql/resolvers/reaction.d.ts +3 -3
  81. package/lib/graphql/resolvers/reaction.js +96 -14
  82. package/lib/graphql/resolvers/reaction.js.map +1 -1
  83. package/lib/graphql/resolvers/streaming.d.ts +20 -0
  84. package/lib/graphql/resolvers/streaming.js +147 -0
  85. package/lib/graphql/resolvers/streaming.js.map +1 -0
  86. package/lib/graphql/schema/channel-capabilities.graphql +492 -0
  87. package/lib/graphql/schema/channel-capabilities.graphql.js +1 -0
  88. package/lib/graphql/schema/channel-capabilities.graphql.js.map +1 -0
  89. package/lib/graphql/schema/channel-member.graphql +110 -21
  90. package/lib/graphql/schema/channel-member.graphql.js +1 -1
  91. package/lib/graphql/schema/channel.graphql +465 -24
  92. package/lib/graphql/schema/channel.graphql.js +1 -1
  93. package/lib/graphql/schema/chat-configuration.graphql +77 -0
  94. package/lib/graphql/schema/chat-configuration.graphql.js +1 -0
  95. package/lib/graphql/schema/chat-configuration.graphql.js.map +1 -0
  96. package/lib/graphql/schema/gateway.graphql +363 -0
  97. package/lib/graphql/schema/index.js +2 -2
  98. package/lib/graphql/schema/index.js.map +1 -1
  99. package/lib/graphql/schema/post-thread.graphql +167 -21
  100. package/lib/graphql/schema/post-thread.graphql.js +1 -1
  101. package/lib/graphql/schema/post.graphql +433 -36
  102. package/lib/graphql/schema/post.graphql.js +1 -1
  103. package/lib/graphql/schema/preferences.graphql +190 -3
  104. package/lib/graphql/schema/preferences.graphql.js +1 -1
  105. package/lib/graphql/schema/reaction.graphql +71 -13
  106. package/lib/graphql/schema/reaction.graphql.js +1 -1
  107. package/lib/graphql/schema/services.graphql +18 -0
  108. package/lib/graphql/schema/streaming.graphql +224 -0
  109. package/lib/graphql/schema/streaming.graphql.js +1 -0
  110. package/lib/graphql/schema/streaming.graphql.js.map +1 -0
  111. package/lib/graphql/schema/users.graphql +76 -13
  112. package/lib/graphql/schema/users.graphql.js +1 -1
  113. package/lib/graphql/schema/workflow-service.graphql +82 -0
  114. package/lib/index.d.ts +3 -1
  115. package/lib/index.js +1 -1
  116. package/lib/index.js.map +1 -1
  117. package/lib/interfaces/index.d.ts +0 -2
  118. package/lib/interfaces/services.d.ts +1 -3
  119. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.d.ts +42 -0
  120. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.js +60 -0
  121. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.js.map +1 -0
  122. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.d.ts +21 -0
  123. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.js +30 -0
  124. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.js.map +1 -0
  125. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.d.ts +17 -0
  126. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js +44 -0
  127. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js.map +1 -0
  128. package/lib/migrations/dbMigrations/index.d.ts +3 -0
  129. package/lib/migrations/index.d.ts +1 -0
  130. package/lib/migrations/mail-template-migration.d.ts +3 -6
  131. package/lib/migrations/mail-template-migration.js +8 -21
  132. package/lib/migrations/mail-template-migration.js.map +1 -1
  133. package/lib/migrations/message-notification-template-migration.d.ts +4 -7
  134. package/lib/migrations/message-notification-template-migration.js +8 -25
  135. package/lib/migrations/message-notification-template-migration.js.map +1 -1
  136. package/lib/module.d.ts +1 -1
  137. package/lib/module.js +3 -10
  138. package/lib/module.js.map +1 -1
  139. package/lib/plugins/ChannelMoleculerService.d.ts +39 -0
  140. package/lib/plugins/ChannelMoleculerService.js +58 -0
  141. package/lib/plugins/ChannelMoleculerService.js.map +1 -0
  142. package/lib/plugins/ExtendedTokenAccountMoleculerService.d.ts +65 -0
  143. package/lib/plugins/ExtendedTokenAccountMoleculerService.js +88 -0
  144. package/lib/plugins/ExtendedTokenAccountMoleculerService.js.map +1 -0
  145. package/lib/plugins/MessengerNotificationMoleculerService.d.ts +52 -0
  146. package/lib/plugins/MessengerNotificationMoleculerService.js +84 -0
  147. package/lib/plugins/MessengerNotificationMoleculerService.js.map +1 -0
  148. package/lib/plugins/PostMoleculerService.d.ts +65 -0
  149. package/lib/plugins/PostMoleculerService.js +87 -0
  150. package/lib/plugins/PostMoleculerService.js.map +1 -0
  151. package/lib/plugins/PostThreadMoleculerService.d.ts +40 -0
  152. package/lib/plugins/PostThreadMoleculerService.js +59 -0
  153. package/lib/plugins/PostThreadMoleculerService.js.map +1 -0
  154. package/lib/plugins/ReactionMoleculerService.d.ts +37 -0
  155. package/lib/plugins/ReactionMoleculerService.js +56 -0
  156. package/lib/plugins/ReactionMoleculerService.js.map +1 -0
  157. package/lib/plugins/index.d.ts +18 -6
  158. package/lib/preferences/permissions/inbox-permission-contribution.js +58 -97
  159. package/lib/preferences/permissions/inbox-permission-contribution.js.map +1 -1
  160. package/lib/preferences/permissions/inbox-roles-permission-overwrite.js +144 -144
  161. package/lib/preferences/permissions/inbox-roles-permission-overwrite.js.map +1 -1
  162. package/lib/preferences/settings/channel-settings.d.ts +39 -0
  163. package/lib/preferences/settings/channel-settings.js +180 -0
  164. package/lib/preferences/settings/channel-settings.js.map +1 -0
  165. package/lib/preferences/settings/chat-settings.d.ts +248 -0
  166. package/lib/preferences/settings/chat-settings.js +1152 -0
  167. package/lib/preferences/settings/chat-settings.js.map +1 -0
  168. package/lib/preferences/settings/index.d.ts +3 -0
  169. package/lib/preferences/settings/messenger-channels-contribution.d.ts +39 -0
  170. package/lib/preferences/settings/messenger-channels-contribution.js +355 -0
  171. package/lib/preferences/settings/messenger-channels-contribution.js.map +1 -0
  172. package/lib/preferences/settings/post-settings.d.ts +16 -0
  173. package/lib/preferences/settings/post-settings.js +75 -3
  174. package/lib/preferences/settings/post-settings.js.map +1 -1
  175. package/lib/services/channel-service.d.ts +215 -34
  176. package/lib/services/channel-service.js +1058 -273
  177. package/lib/services/channel-service.js.map +1 -1
  178. package/lib/services/extended-token-account-service.d.ts +175 -20
  179. package/lib/services/extended-token-account-service.js +636 -56
  180. package/lib/services/extended-token-account-service.js.map +1 -1
  181. package/lib/services/messenger-notification-service.d.ts +177 -17
  182. package/lib/services/messenger-notification-service.js +975 -421
  183. package/lib/services/messenger-notification-service.js.map +1 -1
  184. package/lib/services/post-service.d.ts +245 -18
  185. package/lib/services/post-service.js +1027 -113
  186. package/lib/services/post-service.js.map +1 -1
  187. package/lib/services/post-thread-service.d.ts +153 -6
  188. package/lib/services/post-thread-service.js +475 -9
  189. package/lib/services/post-thread-service.js.map +1 -1
  190. package/lib/services/proxy-services/ChannelProxyService.d.ts +27 -0
  191. package/lib/services/proxy-services/ChannelProxyService.js +31 -0
  192. package/lib/services/proxy-services/ChannelProxyService.js.map +1 -0
  193. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.d.ts +42 -0
  194. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.js +46 -0
  195. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.js.map +1 -0
  196. package/lib/services/proxy-services/MessengerNotificationProxyService.d.ts +44 -0
  197. package/lib/services/proxy-services/MessengerNotificationProxyService.js +54 -0
  198. package/lib/services/proxy-services/MessengerNotificationProxyService.js.map +1 -0
  199. package/lib/services/proxy-services/PostProxyService.d.ts +42 -0
  200. package/lib/services/proxy-services/PostProxyService.js +46 -0
  201. package/lib/services/proxy-services/PostProxyService.js.map +1 -0
  202. package/lib/services/proxy-services/PostThreadProxyService.d.ts +32 -0
  203. package/lib/services/proxy-services/PostThreadProxyService.js +36 -0
  204. package/lib/services/proxy-services/PostThreadProxyService.js.map +1 -0
  205. package/lib/services/proxy-services/ReactionProxyService.d.ts +41 -0
  206. package/lib/services/proxy-services/ReactionProxyService.js +45 -0
  207. package/lib/services/proxy-services/ReactionProxyService.js.map +1 -0
  208. package/lib/services/proxy-services/index.d.ts +17 -5
  209. package/lib/services/reaction-service.d.ts +124 -4
  210. package/lib/services/reaction-service.js +413 -3
  211. package/lib/services/reaction-service.js.map +1 -1
  212. package/lib/store/models/account-token-store.d.ts +1 -1
  213. package/lib/store/models/account-token-store.js.map +1 -1
  214. package/lib/store/models/channel.d.ts +2 -3
  215. package/lib/store/models/channel.js +216 -70
  216. package/lib/store/models/channel.js.map +1 -1
  217. package/lib/store/models/post-thread.d.ts +3 -3
  218. package/lib/store/models/post-thread.js +96 -14
  219. package/lib/store/models/post-thread.js.map +1 -1
  220. package/lib/store/models/post.d.ts +2 -3
  221. package/lib/store/models/post.js +143 -23
  222. package/lib/store/models/post.js.map +1 -1
  223. package/lib/store/models/reaction.d.ts +2 -3
  224. package/lib/store/models/reaction.js +67 -8
  225. package/lib/store/models/reaction.js.map +1 -1
  226. package/lib/store/repositories/__tests__/__fixtures__/team-repository.d.ts +3 -3
  227. package/lib/store/repositories/channel-repository.d.ts +6 -6
  228. package/lib/store/repositories/channel-repository.js +5 -2
  229. package/lib/store/repositories/channel-repository.js.map +1 -1
  230. package/lib/store/repositories/post-repository.d.ts +6 -6
  231. package/lib/store/repositories/post-repository.js +5 -2
  232. package/lib/store/repositories/post-repository.js.map +1 -1
  233. package/lib/store/repositories/post-thread-repository.d.ts +6 -6
  234. package/lib/store/repositories/post-thread-repository.js +5 -2
  235. package/lib/store/repositories/post-thread-repository.js.map +1 -1
  236. package/lib/store/repositories/reaction-repository.d.ts +6 -6
  237. package/lib/store/repositories/reaction-repository.js +5 -2
  238. package/lib/store/repositories/reaction-repository.js.map +1 -1
  239. package/lib/streaming/block-chunker.d.ts +40 -0
  240. package/lib/streaming/block-chunker.js +103 -0
  241. package/lib/streaming/block-chunker.js.map +1 -0
  242. package/lib/streaming/block-chunker.test.d.ts +1 -0
  243. package/lib/streaming/index.d.ts +4 -0
  244. package/lib/streaming/stream-service.d.ts +71 -0
  245. package/lib/streaming/stream-service.js +325 -0
  246. package/lib/streaming/stream-service.js.map +1 -0
  247. package/lib/streaming/stream-service.test.d.ts +16 -0
  248. package/lib/streaming/streaming-post.integration.test.d.ts +10 -0
  249. package/lib/streaming/types.d.ts +33 -0
  250. package/lib/streaming/types.js +37 -0
  251. package/lib/streaming/types.js.map +1 -0
  252. package/lib/templates/constants/CONTRIBUTION_POINTS.ts.template +78 -0
  253. package/lib/templates/constants/SERVER_TYPES.ts.template +1 -4
  254. package/lib/templates/constants/WorkflowNamespace.ts.template +10 -0
  255. package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
  256. package/lib/templates/repositories/PostRepository.ts.template +3 -3
  257. package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
  258. package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
  259. package/lib/templates/services/ChannelService.ts.template +290 -39
  260. package/lib/templates/services/ExtendedTokenAccountService.ts.template +107 -3
  261. package/lib/templates/services/MessengerNotificationService.ts.template +94 -19
  262. package/lib/templates/services/MessengerStreamService.ts.template +131 -0
  263. package/lib/templates/services/PostService.ts.template +228 -20
  264. package/lib/templates/services/PostThreadService.ts.template +151 -6
  265. package/lib/templates/services/ReactionService.ts.template +129 -3
  266. package/lib/templates/services/RedisCacheManager.ts.template +22 -0
  267. package/package.json +10 -6
  268. package/lib/interfaces/context.d.ts +0 -14
  269. package/lib/plugins/channel-moleculer-service.d.ts +0 -8
  270. package/lib/plugins/channel-moleculer-service.js +0 -129
  271. package/lib/plugins/channel-moleculer-service.js.map +0 -1
  272. package/lib/plugins/extended-token-account-moleculer-service.d.ts +0 -8
  273. package/lib/plugins/extended-token-account-moleculer-service.js +0 -47
  274. package/lib/plugins/extended-token-account-moleculer-service.js.map +0 -1
  275. package/lib/plugins/messenger-notification-moleculer-service.d.ts +0 -9
  276. package/lib/plugins/messenger-notification-moleculer-service.js +0 -116
  277. package/lib/plugins/messenger-notification-moleculer-service.js.map +0 -1
  278. package/lib/plugins/post-moleculer-service.d.ts +0 -35
  279. package/lib/plugins/post-moleculer-service.js +0 -393
  280. package/lib/plugins/post-moleculer-service.js.map +0 -1
  281. package/lib/plugins/post-thread-moleculer-service.d.ts +0 -8
  282. package/lib/plugins/post-thread-moleculer-service.js +0 -33
  283. package/lib/plugins/post-thread-moleculer-service.js.map +0 -1
  284. package/lib/plugins/reaction-moleculer-service.d.ts +0 -8
  285. package/lib/plugins/reaction-moleculer-service.js +0 -20
  286. package/lib/plugins/reaction-moleculer-service.js.map +0 -1
  287. package/lib/services/proxy-services/channel-microservice.d.ts +0 -44
  288. package/lib/services/proxy-services/channel-microservice.js +0 -199
  289. package/lib/services/proxy-services/channel-microservice.js.map +0 -1
  290. package/lib/services/proxy-services/messenger-notification-microservice.d.ts +0 -16
  291. package/lib/services/proxy-services/messenger-notification-microservice.js +0 -54
  292. package/lib/services/proxy-services/messenger-notification-microservice.js.map +0 -1
  293. package/lib/services/proxy-services/post-microservice.d.ts +0 -22
  294. package/lib/services/proxy-services/post-microservice.js +0 -64
  295. package/lib/services/proxy-services/post-microservice.js.map +0 -1
  296. package/lib/services/proxy-services/post-thread-microservice.d.ts +0 -10
  297. package/lib/services/proxy-services/post-thread-microservice.js +0 -15
  298. package/lib/services/proxy-services/post-thread-microservice.js.map +0 -1
  299. package/lib/services/proxy-services/reaction-microservice.d.ts +0 -9
  300. package/lib/services/proxy-services/reaction-microservice.js +0 -10
  301. package/lib/services/proxy-services/reaction-microservice.js.map +0 -1
  302. package/lib/store/models/common-options.js +0 -20
  303. package/lib/store/models/common-options.js.map +0 -1
@@ -1,4 +1,6 @@
1
- import {generateUri}from'@adminide-stack/core';import {ClientCacheTypeNames,SortEnum,PostTypeEnum,RoomType}from'common';import {get}from'lodash-es';import {GraphQLError}from'graphql';// export const postResolvers = ({ pubsub }): IResolvers<IContext> => ({
1
+ import {withFilter}from'graphql-subscriptions';import {RoomType,PostTypeEnum,SortEnum,ConfigCollectionName,Scheme,ClientCacheTypeNames}from'common/server';import {get}from'lodash-es';import {GraphQLError}from'graphql';import {generateResourceUri,DEFAULT_TENANT_ID,buildNodeContext}from'@adminide-stack/core/lib/index.js';// import { IContext } from '../../interfaces';
2
+ // export const postResolvers = ({ pubsub }): IResolvers<IContext> => ({
3
+ // export const postResolvers: (options: IResolverOptions) => IResolvers<IContext> = (options) => ({
2
4
  const postResolvers = options => ({
3
5
  // Temporary fix, until we have extension support in base module
4
6
  FileInfo: {
@@ -7,125 +9,298 @@ const postResolvers = options => ({
7
9
  }, args, {
8
10
  fileInfoService
9
11
  }) => {
10
- const basePath = fileInfoService.awsS3Service.basePath || 'aws';
11
- if (!url.includes(basePath)) {
12
- return url;
12
+ options.logger.trace('(FileInfo.url) url [%s]', url);
13
+ try {
14
+ if (!url) {
15
+ options.logger.warn('Missing URL in FileInfo');
16
+ return null;
17
+ }
18
+ const basePath = fileInfoService.awsS3Service.basePath || 'aws';
19
+ if (!url.includes(basePath)) {
20
+ return url;
21
+ }
22
+ return fileInfoService.getResizedImage(url, {
23
+ width: undefined,
24
+ height: undefined
25
+ });
26
+ } catch (error) {
27
+ options.logger.error('Error getting FileInfo URL: %o', error);
28
+ return url; // Fallback to original URL
13
29
  }
14
- return fileInfoService.getResizedImage(url, {
15
- width: undefined,
16
- height: undefined
17
- });
18
30
  },
19
31
  extension(src) {
20
- return src.mimeType.split('/')[1];
32
+ options.logger.trace('(FileInfo.extension) mimeType [%s]', src?.mimeType);
33
+ try {
34
+ if (!src?.mimeType || typeof src.mimeType !== 'string') {
35
+ options.logger.warn('Missing or invalid mimeType in FileInfo');
36
+ return null;
37
+ }
38
+ const parts = src.mimeType.split('/');
39
+ return parts.length > 1 ? parts[1] : null;
40
+ } catch (error) {
41
+ options.logger.error('Error getting FileInfo extension: %o', error);
42
+ return null;
43
+ }
21
44
  }
22
45
  },
23
46
  Post: {
24
47
  editedBy(src, args, {
25
- accountService
48
+ accountService,
49
+ accountUserDataLoader
26
50
  }) {
27
- return src?.editedBy ? accountService.findAccountById(src.editedBy.toString()) : null;
51
+ options.logger.trace('(Post.editedBy) editedBy [%s]', src?.editedBy);
52
+ try {
53
+ if (!src?.editedBy) {
54
+ return null;
55
+ }
56
+ return accountUserDataLoader.load(src.editedBy.toString());
57
+ } catch (error) {
58
+ options.logger.error('Error getting Post editedBy: %o', error);
59
+ return null;
60
+ }
28
61
  },
29
62
  deletedBy(src, args, {
30
- accountService
63
+ accountService,
64
+ accountUserDataLoader
31
65
  }) {
32
- return src?.deletedBy ? accountService.findAccountById(src?.deletedBy.toString()) : null;
66
+ options.logger.trace('(Post.deletedBy) deletedBy [%s]', src?.deletedBy);
67
+ try {
68
+ if (!src?.deletedBy) {
69
+ return null;
70
+ }
71
+ return accountUserDataLoader.load(src.deletedBy.toString());
72
+ } catch (error) {
73
+ options.logger.error('Error getting Post deletedBy: %o', error);
74
+ return null;
75
+ }
33
76
  },
34
77
  author(src, args, {
35
78
  accountService
36
79
  }) {
37
- const author = src.author?.toString();
38
- if (author) {
39
- return accountService.findAccountById(author);
80
+ options.logger.trace('(Post.author) author [%s], editedBy [%s]', src?.author, src?.editedBy);
81
+ try {
82
+ const author = src?.author?.toString();
83
+ if (author) {
84
+ return accountService.findAccountById(author);
85
+ }
86
+ // Fallback to editedBy if author is not available
87
+ if (src?.editedBy) {
88
+ return accountService.findAccountById(src.editedBy.toString());
89
+ }
90
+ return null;
91
+ } catch (error) {
92
+ options.logger.error('Error getting Post author: %o', error);
93
+ return null;
40
94
  }
41
- return src?.editedBy ? accountService.findAccountById(src.editedBy.toString()) : null;
42
95
  },
43
96
  channel(src, args, {
44
97
  channelService
45
98
  }) {
46
- return channelService.get(src.channel.toString());
99
+ options.logger.trace('(Post.channel) channel [%s]', src?.channel);
100
+ try {
101
+ if (!src?.channel) {
102
+ options.logger.warn('Missing channel in Post');
103
+ return null;
104
+ }
105
+ return channelService.get(src.channel.toString());
106
+ } catch (error) {
107
+ options.logger.error('Error getting Post channel: %o', error);
108
+ return null;
109
+ }
47
110
  },
48
111
  props(src, _, {
49
112
  userContext
50
113
  }) {
51
- return src?.props?.[`[${userContext.accountId}]`];
114
+ options.logger.trace('(Post.props) accountId [%s]', userContext?.accountId);
115
+ try {
116
+ if (!userContext?.accountId || !src?.props) {
117
+ return null;
118
+ }
119
+ return src.props[`[${userContext.accountId}]`] || null;
120
+ } catch (error) {
121
+ options.logger.error('Error getting Post props: %o', error);
122
+ return null;
123
+ }
52
124
  },
53
125
  isRead(src, _, {
54
126
  userContext
55
127
  }) {
56
- return get(src?.props?.[`[${userContext.accountId}]`], `messenger.posts.isRead`);
128
+ options.logger.trace('(Post.isRead) accountId [%s]', userContext?.accountId);
129
+ try {
130
+ if (!userContext?.accountId || !src?.props) {
131
+ return false;
132
+ }
133
+ return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isRead', false);
134
+ } catch (error) {
135
+ options.logger.error('Error getting Post isRead: %o', error);
136
+ return false;
137
+ }
57
138
  },
58
139
  isDelivered(src, _, {
59
140
  userContext
60
141
  }) {
61
- return get(src?.props?.[`[${userContext.accountId}]`], `messenger.posts.isDelivered`);
142
+ options.logger.trace('(Post.isDelivered) accountId [%s]', userContext?.accountId);
143
+ try {
144
+ if (!userContext?.accountId || !src?.props) {
145
+ return false;
146
+ }
147
+ return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isDelivered', false);
148
+ } catch (error) {
149
+ options.logger.error('Error getting Post isDelivered: %o', error);
150
+ return false;
151
+ }
62
152
  },
63
- propsConfiguration(src, args, {
64
- configurationService
153
+ async propsConfiguration(src, args, {
154
+ configurationService,
155
+ userContext
65
156
  }) {
66
- const resource = generateUri('messenger', {
67
- _id: src.id
68
- }, 'props');
69
- let data = '{}';
157
+ options.logger.trace('(Post.propsConfiguration) postId [%s], orgName [%s]', src?.id);
70
158
  try {
71
- data = JSON.stringify(src.props);
72
- } catch (err) {
73
- console.log('---Errr---', err);
159
+ // if (!src?.id || !userContext?.orgName) {
160
+ if (!src?.id) {
161
+ options.logger.warn('Missing required data for propsConfiguration');
162
+ throw new Error('Missing post ID or organization name');
163
+ }
164
+ // const { orgName } = userContext;
165
+ // options.logger.debug('Processing propsConfiguration for orgName: %s', orgName);
166
+ const resource = generateResourceUri(ConfigCollectionName.Post, {
167
+ _id: src.id
168
+ }, 'props', DEFAULT_TENANT_ID, {
169
+ scheme: Scheme.CDECODE_RESOURCE
170
+ });
171
+ let data = '{}';
172
+ try {
173
+ data = JSON.stringify(src.props || {});
174
+ } catch (err) {
175
+ options.logger.warn('Error serializing props data: %o', err);
176
+ data = '{}';
177
+ }
178
+ const nodeContext = buildNodeContext(userContext);
179
+ const machineModel = await configurationService.parser(resource.toString(), data, nodeContext, null, false);
180
+ if (machineModel instanceof Error) {
181
+ options.logger.error('Error parsing configuration: %o', machineModel);
182
+ throw machineModel;
183
+ }
184
+ return {
185
+ resource,
186
+ contents: machineModel.contents,
187
+ overrides: machineModel.overrides,
188
+ keys: machineModel.keys,
189
+ __typename: ClientCacheTypeNames.MachineConfiguration
190
+ };
191
+ } catch (error) {
192
+ options.logger.error('Error getting Post propsConfiguration: %o', error);
193
+ throw error;
74
194
  }
75
- const machineModel = configurationService.parser(resource.toString(), data);
76
- return {
77
- resource,
78
- contents: machineModel.contents,
79
- overrides: machineModel.overrides,
80
- keys: machineModel.keys,
81
- __typename: ClientCacheTypeNames.MachineConfiguration
82
- };
83
195
  },
84
196
  async files(src, args, {
85
197
  fileInfoService
86
198
  }) {
87
- const {
88
- data,
89
- totalCount
90
- } = await fileInfoService.getAllWithCount({
91
- ...args,
92
- criteria: {
93
- ...args.criteria,
94
- refType: 'Post',
95
- ref: src.id
96
- }
97
- });
98
- return {
99
- data: data.map(({
199
+ options.logger.trace('(Post.files) postId [%s], args [%j]', src?.id, args);
200
+ try {
201
+ if (!src?.id) {
202
+ options.logger.warn('Missing post ID for files');
203
+ return {
204
+ data: [],
205
+ totalCount: 0
206
+ };
207
+ }
208
+ if (!fileInfoService) {
209
+ options.logger.warn('FileInfoService not available');
210
+ return {
211
+ data: [],
212
+ totalCount: 0
213
+ };
214
+ }
215
+ const {
216
+ data,
217
+ totalCount
218
+ } = await fileInfoService.getAllWithCount({
219
+ ...args,
220
+ criteria: {
221
+ ...args.criteria,
222
+ refType: 'Post',
223
+ ref: src.id
224
+ }
225
+ });
226
+ const processedData = data.map(({
100
227
  url,
101
228
  ...rest
102
229
  }) => ({
103
230
  ...rest,
104
231
  url: fileInfoService.getThumbnailImage(url)
105
- })),
106
- totalCount
107
- };
232
+ }));
233
+ options.logger.debug('Retrieved %d files for post %s', processedData.length, src.id);
234
+ return {
235
+ data: processedData,
236
+ totalCount
237
+ };
238
+ } catch (error) {
239
+ options.logger.error('Error getting Post files: %o', error);
240
+ return {
241
+ data: [],
242
+ totalCount: 0
243
+ };
244
+ }
108
245
  },
109
246
  async replies(src, args, {
110
247
  postService
111
248
  }) {
112
- const {
113
- data,
114
- totalCount
115
- } = (await postService?.getAllWithCount({
116
- criteria: {
117
- channel: src.channel.toString(),
118
- parentId: src?.id.toString()
119
- },
120
- sort: {
121
- key: 'createdAt',
122
- value: SortEnum.Desc
249
+ options.logger.trace('(Post.replies) postId [%s], channelId [%s]', src?.id, src?.channel);
250
+ console.log('args...', args);
251
+ try {
252
+ if (!src?.id || !src?.channel) {
253
+ options.logger.warn('Missing post ID or channel for replies');
254
+ return {
255
+ data: [],
256
+ totalCount: 0
257
+ };
258
+ }
259
+ if (!postService) {
260
+ options.logger.warn('PostService not available');
261
+ return {
262
+ data: [],
263
+ totalCount: 0
264
+ };
123
265
  }
124
- })) ?? [];
125
- return {
126
- totalCount,
127
- data
128
- };
266
+ const totalRepliesCount = await postService?.count({
267
+ channel: src.channel.toString(),
268
+ parentId: src.id.toString()
269
+ });
270
+ const {
271
+ data,
272
+ totalCount
273
+ } = (await postService?.getAllWithCount({
274
+ criteria: {
275
+ channel: src.channel.toString(),
276
+ parentId: src.id.toString()
277
+ },
278
+ sort: {
279
+ key: 'createdAt',
280
+ value: SortEnum.Desc
281
+ },
282
+ limit: totalRepliesCount || 50
283
+ })) ?? {
284
+ data: [],
285
+ totalCount: 0
286
+ };
287
+ options.logger.debug('Retrieved %d replies for post %s', totalCount, src.id);
288
+ // Set default type to Simple if not specified
289
+ const processedData = data.map(post => ({
290
+ ...post,
291
+ type: (post.type === 'message' ? PostTypeEnum.Message : post.type) || PostTypeEnum.Simple
292
+ }));
293
+ return {
294
+ totalCount,
295
+ data: processedData
296
+ };
297
+ } catch (error) {
298
+ options.logger.error('Error getting Post replies: %o', error);
299
+ return {
300
+ data: [],
301
+ totalCount: 0
302
+ };
303
+ }
129
304
  }
130
305
  },
131
306
  Query: {
@@ -134,31 +309,79 @@ const postResolvers = options => ({
134
309
  parentId,
135
310
  limit,
136
311
  skip,
137
- sort
312
+ sort,
313
+ props
138
314
  }, {
139
315
  postService,
316
+ channelService,
140
317
  userContext
141
318
  }) {
142
- const sortBy = sort || {
143
- key: 'createdAt',
144
- value: SortEnum.Desc
145
- };
146
- const {
147
- data,
148
- totalCount
149
- } = await postService.getAllWithCount({
150
- criteria: {
151
- channel: channelId,
319
+ options.logger.trace('(Query.messages) channelId [%s], parentId [%s], limit [%d], skip [%d]', channelId, parentId, limit, skip);
320
+ try {
321
+ // if (projectId && !channelId) {
322
+ // const { data: channels } = (await channelService.getAllWithCount({
323
+ // criteria: {
324
+ // projectId: projectId?.toString?.(),
325
+ // type: RoomType.Aiassistant,
326
+ // },
327
+ // limit: 1,
328
+ // })) as unknown as { data: IChannel[]; totalCount: number };
329
+ // const channel = channels?.[0];
330
+ // channelId = channel?.id as string;
331
+ // }
332
+ if (!channelId && !props) {
333
+ options.logger.debug('No channelId provided in messages query — returning empty result');
334
+ return {
335
+ totalCount: 0,
336
+ data: []
337
+ };
338
+ }
339
+ if (!userContext?.accountId) {
340
+ options.logger.warn('Missing user context in messages query');
341
+ throw new Error('User authentication required');
342
+ }
343
+ if (!postService) {
344
+ options.logger.warn('PostService not available');
345
+ throw new Error('Post service unavailable');
346
+ }
347
+ const sortBy = sort || {
348
+ key: 'createdAt',
349
+ value: SortEnum.Desc
350
+ };
351
+ const channel = channelId || undefined;
352
+ // const projectId = props?.projectId ? `"props.projectId":"${props?.projectId}"` : undefined;
353
+ // console.log("server projectId",projectId)
354
+ const criteria = props ? {
355
+ channel,
356
+ parentId,
357
+ 'props.projectId': props?.projectId || undefined
358
+ } : {
359
+ channel,
152
360
  parentId
153
- },
154
- limit,
155
- skip,
156
- sort: sortBy
157
- });
158
- return {
159
- totalCount,
160
- data
161
- };
361
+ };
362
+ const {
363
+ data,
364
+ totalCount
365
+ } = await postService.getAllWithCount({
366
+ criteria,
367
+ limit,
368
+ skip,
369
+ sort: sortBy
370
+ });
371
+ options.logger.debug('Retrieved %d messages for channel %s', totalCount, channelId);
372
+ // Set default type to Simple if not specified
373
+ const processedData = data.map(post => ({
374
+ ...post,
375
+ type: (post.type === 'message' ? PostTypeEnum.Message : post.type) || PostTypeEnum.Simple
376
+ }));
377
+ return {
378
+ totalCount,
379
+ data: processedData
380
+ };
381
+ } catch (error) {
382
+ options.logger.error('Error in messages query: %o', error);
383
+ throw error;
384
+ }
162
385
  },
163
386
  async publicMessages(src, {
164
387
  channelId
@@ -166,23 +389,43 @@ const postResolvers = options => ({
166
389
  postService,
167
390
  userContext
168
391
  }) {
169
- const {
170
- data,
171
- totalCount
172
- } = await postService.getAllWithCount({
173
- criteria: {
174
- channel: channelId,
175
- type: PostTypeEnum.Public
176
- },
177
- sort: {
178
- key: 'createdAt',
179
- value: SortEnum.Desc
392
+ options.logger.trace('(Query.publicMessages) channelId [%s]', channelId);
393
+ try {
394
+ if (!channelId) {
395
+ options.logger.warn('Missing channelId in publicMessages query');
396
+ throw new Error('Channel ID is required');
180
397
  }
181
- });
182
- return {
183
- totalCount,
184
- data
185
- };
398
+ if (!postService) {
399
+ options.logger.warn('PostService not available');
400
+ throw new Error('Post service unavailable');
401
+ }
402
+ const {
403
+ data,
404
+ totalCount
405
+ } = await postService.getAllWithCount({
406
+ criteria: {
407
+ channel: channelId,
408
+ type: PostTypeEnum.Public
409
+ },
410
+ sort: {
411
+ key: 'createdAt',
412
+ value: SortEnum.Desc
413
+ }
414
+ });
415
+ options.logger.debug('Retrieved %d public messages for channel %s', totalCount, channelId);
416
+ // Set default type to Simple if not specified
417
+ const processedData = data.map(post => ({
418
+ ...post,
419
+ type: post.type || PostTypeEnum.Simple
420
+ }));
421
+ return {
422
+ totalCount,
423
+ data: processedData
424
+ };
425
+ } catch (error) {
426
+ options.logger.error('Error in publicMessages query: %o', error);
427
+ throw error;
428
+ }
186
429
  }
187
430
  },
188
431
  Mutation: {
@@ -191,14 +434,29 @@ const postResolvers = options => ({
191
434
  }, {
192
435
  postService
193
436
  }) {
194
- const {
195
- channelId,
196
- messageId: id
197
- } = messageId;
198
- return postService.delete({
199
- channel: channelId,
200
- id
201
- });
437
+ options.logger.trace('(Mutation.deleteMessage) messageId [%j]', messageId);
438
+ try {
439
+ if (!messageId?.channelId || !messageId?.messageId) {
440
+ options.logger.warn('Missing required messageId parameters');
441
+ throw new Error('Channel ID and Message ID are required');
442
+ }
443
+ if (!postService) {
444
+ options.logger.warn('PostService not available');
445
+ throw new Error('Post service unavailable');
446
+ }
447
+ const {
448
+ channelId,
449
+ messageId: id
450
+ } = messageId;
451
+ options.logger.debug('Deleting message %s from channel %s', id, channelId);
452
+ return postService.delete({
453
+ channel: channelId,
454
+ id
455
+ });
456
+ } catch (error) {
457
+ options.logger.error('Error deleting message: %o', error);
458
+ throw error;
459
+ }
202
460
  },
203
461
  editMessage(src, {
204
462
  messageId,
@@ -207,12 +465,45 @@ const postResolvers = options => ({
207
465
  postService,
208
466
  userContext
209
467
  }) {
210
- return postService.update(messageId.messageId, {
211
- message: messageInput.content,
212
- editedBy: userContext.accountId,
213
- channel: messageId.channelId,
214
- files: messageInput.files
215
- });
468
+ options.logger.trace('(Mutation.editMessage) messageId [%j], content length [%d]', messageId, messageInput?.content?.length || 0);
469
+ try {
470
+ if (!messageId?.messageId || !messageId?.channelId) {
471
+ options.logger.warn('Missing required messageId parameters');
472
+ throw new Error('Message ID and Channel ID are required');
473
+ }
474
+ if (!messageInput?.content) {
475
+ options.logger.warn('Missing message content');
476
+ throw new Error('Message content is required');
477
+ }
478
+ if (!userContext?.accountId) {
479
+ options.logger.warn('Missing user context');
480
+ throw new Error('User authentication required');
481
+ }
482
+ if (!postService) {
483
+ options.logger.warn('PostService not available');
484
+ throw new Error('Post service unavailable');
485
+ }
486
+ options.logger.debug('Editing message %s in channel %s', messageId.messageId, messageId.channelId);
487
+ const {
488
+ content,
489
+ files,
490
+ extraProps
491
+ } = messageInput;
492
+ return postService.update(messageId.messageId, {
493
+ message: content,
494
+ editedBy: userContext.accountId,
495
+ channel: messageId.channelId,
496
+ files,
497
+ ...(extraProps && {
498
+ props: {
499
+ extraProps
500
+ }
501
+ })
502
+ });
503
+ } catch (error) {
504
+ options.logger.error('Error editing message: %o', error);
505
+ throw error;
506
+ }
216
507
  },
217
508
  async sendMessage(src, {
218
509
  channelId,
@@ -222,49 +513,69 @@ const postResolvers = options => ({
222
513
  postService,
223
514
  userContext
224
515
  }) {
225
- const {
226
- content,
227
- files,
228
- createdBy,
229
- notificationParams
230
- } = messageInput;
231
- const {
232
- accountId
233
- } = userContext;
234
- let post;
235
- if (postId) {
236
- post = await postService.create({
237
- _id: postId,
238
- channel: channelId,
239
- message: content,
240
- editedBy: createdBy || accountId,
241
- author: createdBy || accountId,
516
+ options.logger.trace('(Mutation.sendMessage) channelId [%s], postId [%s], content length [%d]', channelId, postId, messageInput?.content?.length || 0);
517
+ try {
518
+ if (!channelId) {
519
+ options.logger.warn('Missing channelId');
520
+ throw new Error('Channel ID is required');
521
+ }
522
+ if (!messageInput?.content) {
523
+ options.logger.warn('Missing message content');
524
+ throw new Error('Message content is required');
525
+ }
526
+ if (!userContext?.accountId) {
527
+ options.logger.warn('Missing user context');
528
+ throw new Error('User authentication required');
529
+ }
530
+ if (!postService) {
531
+ options.logger.warn('PostService not available');
532
+ throw new Error('Post service unavailable');
533
+ }
534
+ const {
535
+ content,
242
536
  files,
243
- props: notificationParams ? {
244
- notificationParams
245
- } : undefined
246
- });
247
- } else {
248
- post = await postService.create({
537
+ createdBy,
538
+ notificationParams,
539
+ type,
540
+ extraProps
541
+ } = messageInput;
542
+ const {
543
+ accountId
544
+ } = userContext;
545
+ const postData = {
249
546
  channel: channelId,
250
547
  message: content,
251
548
  editedBy: createdBy || accountId,
252
549
  author: createdBy || accountId,
253
550
  files,
254
- props: notificationParams ? {
255
- notificationParams
256
- } : undefined
257
- });
551
+ props: notificationParams || extraProps ? {
552
+ ...(notificationParams && {
553
+ notificationParams
554
+ }),
555
+ ...(extraProps && {
556
+ ...extraProps
557
+ })
558
+ } : undefined,
559
+ type: type || PostTypeEnum.Simple
560
+ };
561
+ let post;
562
+ if (postId) {
563
+ options.logger.debug('Creating message with specific ID %s', postId);
564
+ post = await postService.create({
565
+ _id: postId,
566
+ ...postData
567
+ });
568
+ } else {
569
+ options.logger.debug('Creating new message in channel %s', channelId);
570
+ post = await postService.create(postData);
571
+ }
572
+ options.logger.debug('Message created successfully with ID %s', post?.id || post?._id);
573
+ //options.pubsub.publish(`POST_CREATED.${channelId}`, post);
574
+ return post;
575
+ } catch (error) {
576
+ options.logger.error('Error sending message: %o', error);
577
+ throw error;
258
578
  }
259
- // const post = await postService.create({
260
- // channel: channelId as any,
261
- // message: content,
262
- // editedBy: accountId as any,
263
- // author: accountId as any,
264
- // files,
265
- // });
266
- // options.pubsub.publish(`POST_CREATED.${channelId}`, post);
267
- return post;
268
579
  },
269
580
  async sendPublicMessage(src, {
270
581
  channelId,
@@ -275,46 +586,77 @@ const postResolvers = options => ({
275
586
  channelService,
276
587
  userContext
277
588
  }) {
278
- const {
279
- content,
280
- files,
281
- createdBy
282
- } = messageInput;
283
- const {
284
- accountId
285
- } = userContext;
286
- let post = null;
287
- const channelExits = await channelService.get(channelId);
288
- if (!channelExits) {
289
- const channel = await channelService.savePublicChannel({
290
- _id: channelId,
291
- type: RoomType.Public,
292
- title: `public-channel-${channelId}`
293
- });
294
- if (channel) {
295
- post = await postService.createWithoutSubscription({
296
- _id: postId || undefined,
297
- channel: channelId,
298
- message: content,
299
- editedBy: createdBy || accountId,
300
- author: createdBy || accountId,
301
- files,
302
- type: PostTypeEnum.Public
589
+ options.logger.trace('(Mutation.sendPublicMessage) channelId [%s], postId [%s]', channelId, postId);
590
+ try {
591
+ if (!channelId) {
592
+ options.logger.warn('Missing channelId');
593
+ throw new Error('Channel ID is required');
594
+ }
595
+ if (!messageInput?.content) {
596
+ options.logger.warn('Missing message content');
597
+ throw new Error('Message content is required');
598
+ }
599
+ if (!userContext?.accountId) {
600
+ options.logger.warn('Missing user context');
601
+ throw new Error('User authentication required');
602
+ }
603
+ if (!postService || !channelService) {
604
+ options.logger.warn('Required services not available');
605
+ throw new Error('Required services unavailable');
606
+ }
607
+ const {
608
+ content,
609
+ files,
610
+ createdBy,
611
+ extraProps
612
+ } = messageInput;
613
+ const {
614
+ accountId
615
+ } = userContext;
616
+ let post = null;
617
+ const channelExists = await channelService.get(channelId);
618
+ if (!channelExists) {
619
+ options.logger.debug('Creating public channel %s', channelId);
620
+ const channel = await channelService.savePublicChannel({
621
+ _id: channelId,
622
+ type: RoomType.Public,
623
+ title: `public-channel-${channelId}`
303
624
  });
625
+ if (!channel) {
626
+ options.logger.error('Failed to create public channel %s', channelId);
627
+ throw new Error('Failed to create public channel');
628
+ }
304
629
  }
305
- } else {
306
- post = await postService.createWithoutSubscription({
307
- _id: postId || undefined,
630
+ const postData = {
308
631
  channel: channelId,
309
632
  message: content,
310
633
  editedBy: createdBy || accountId,
311
634
  author: createdBy || accountId,
312
635
  files,
313
- type: PostTypeEnum.Public
314
- });
636
+ type: PostTypeEnum.Public,
637
+ ...(extraProps && {
638
+ props: {
639
+ extraProps
640
+ }
641
+ })
642
+ };
643
+ if (postId) {
644
+ post = await postService.createWithoutSubscription({
645
+ _id: postId,
646
+ ...postData
647
+ });
648
+ } else {
649
+ post = await postService.createWithoutSubscription(postData);
650
+ }
651
+ if (post) {
652
+ options.logger.debug('Publishing public post created event for channel %s', channelId);
653
+ options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
654
+ }
655
+ return post;
656
+ } catch (error) {
657
+ options.logger.error('Error sending public message: %o', error);
658
+ throw error;
315
659
  }
316
- if (post) options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
317
- return post;
318
660
  },
319
661
  async sendExpoNotificationOnPost(_, {
320
662
  postId,
@@ -324,9 +666,29 @@ const postResolvers = options => ({
324
666
  postService,
325
667
  userContext
326
668
  }) {
327
- const post = await postService.get(postId.toString());
328
- const res = await messengerNotificationService.sendExpoNotificationOnPost(post, notificationData);
329
- return res;
669
+ options.logger.trace('(Mutation.sendExpoNotificationOnPost) postId [%s]', postId);
670
+ try {
671
+ if (!postId) {
672
+ options.logger.warn('Missing postId');
673
+ throw new Error('Post ID is required');
674
+ }
675
+ if (!messengerNotificationService || !postService) {
676
+ options.logger.warn('Required services not available');
677
+ throw new Error('Required services unavailable');
678
+ }
679
+ const post = await postService.get(postId.toString());
680
+ if (!post) {
681
+ options.logger.warn('Post not found: %s', postId);
682
+ throw new Error('Post not found');
683
+ }
684
+ options.logger.debug('Sending expo notification for post %s', postId);
685
+ const result = await messengerNotificationService.sendExpoNotificationOnPost(post, notificationData);
686
+ options.logger.debug('Expo notification sent successfully for post %s', postId);
687
+ return result;
688
+ } catch (error) {
689
+ options.logger.error('Error sending expo notification: %o', error);
690
+ throw error;
691
+ }
330
692
  },
331
693
  createMessageFileUploadLink(_, {
332
694
  postId,
@@ -335,7 +697,25 @@ const postResolvers = options => ({
335
697
  postService,
336
698
  userContext
337
699
  }) {
338
- return postService.createFileUploadLink(postId, filename, userContext.accountId);
700
+ options.logger.trace('(Mutation.createMessageFileUploadLink) postId [%s], filename [%s]', postId, filename);
701
+ try {
702
+ if (!postId || !filename) {
703
+ options.logger.warn('Missing postId or filename');
704
+ throw new Error('Post ID and filename are required');
705
+ }
706
+ if (!userContext?.accountId) {
707
+ options.logger.warn('Missing user context');
708
+ throw new Error('User authentication required');
709
+ }
710
+ if (!postService) {
711
+ options.logger.warn('PostService not available');
712
+ throw new Error('Post service unavailable');
713
+ }
714
+ return postService.createFileUploadLink(postId, filename, userContext.accountId);
715
+ } catch (error) {
716
+ options.logger.error('Error creating file upload link: %o', error);
717
+ throw error;
718
+ }
339
719
  },
340
720
  attachUploadedFileToMessage(_, {
341
721
  postId,
@@ -344,7 +724,25 @@ const postResolvers = options => ({
344
724
  postService,
345
725
  userContext
346
726
  }) {
347
- return postService.attachUploadedFile(postId, file, userContext.accountId);
727
+ options.logger.trace('(Mutation.attachUploadedFileToMessage) postId [%s], filename [%s]', postId, file?.name);
728
+ try {
729
+ if (!postId || !file) {
730
+ options.logger.warn('Missing postId or file');
731
+ throw new Error('Post ID and file are required');
732
+ }
733
+ if (!userContext?.accountId) {
734
+ options.logger.warn('Missing user context');
735
+ throw new Error('User authentication required');
736
+ }
737
+ if (!postService) {
738
+ options.logger.warn('PostService not available');
739
+ throw new Error('Post service unavailable');
740
+ }
741
+ return postService.attachUploadedFile(postId, file, userContext.accountId);
742
+ } catch (error) {
743
+ options.logger.error('Error attaching uploaded file: %o', error);
744
+ throw error;
745
+ }
348
746
  },
349
747
  async createMessageFilesUploadLink(_, {
350
748
  postId,
@@ -353,7 +751,25 @@ const postResolvers = options => ({
353
751
  postService,
354
752
  userContext
355
753
  }) {
356
- return postService.createFilesUploadLink(postId, filenames, userContext.accountId);
754
+ options.logger.trace('(Mutation.createMessageFilesUploadLink) postId [%s], fileCount [%d]', postId, filenames?.length || 0);
755
+ try {
756
+ if (!postId || !filenames || !Array.isArray(filenames) || filenames.length === 0) {
757
+ options.logger.warn('Missing postId or filenames');
758
+ throw new Error('Post ID and filenames array are required');
759
+ }
760
+ if (!userContext?.accountId) {
761
+ options.logger.warn('Missing user context');
762
+ throw new Error('User authentication required');
763
+ }
764
+ if (!postService) {
765
+ options.logger.warn('PostService not available');
766
+ throw new Error('Post service unavailable');
767
+ }
768
+ return postService.createFilesUploadLink(postId, filenames, userContext.accountId);
769
+ } catch (error) {
770
+ options.logger.error('Error creating files upload links: %o', error);
771
+ throw error;
772
+ }
357
773
  },
358
774
  async attachUploadedFilesToMessage(_, {
359
775
  postId,
@@ -362,14 +778,46 @@ const postResolvers = options => ({
362
778
  postService,
363
779
  userContext
364
780
  }) {
365
- return postService.attachUploadedFiles(postId, files, userContext.accountId);
781
+ options.logger.trace('(Mutation.attachUploadedFilesToMessage) postId [%s], fileCount [%d]', postId, files?.length || 0);
782
+ try {
783
+ if (!postId || !files || !Array.isArray(files) || files.length === 0) {
784
+ options.logger.warn('Missing postId or files');
785
+ throw new Error('Post ID and files array are required');
786
+ }
787
+ if (!userContext?.accountId) {
788
+ options.logger.warn('Missing user context');
789
+ throw new Error('User authentication required');
790
+ }
791
+ if (!postService) {
792
+ options.logger.warn('PostService not available');
793
+ throw new Error('Post service unavailable');
794
+ }
795
+ return postService.attachUploadedFiles(postId, files, userContext.accountId);
796
+ } catch (error) {
797
+ options.logger.error('Error attaching uploaded files: %o', error);
798
+ throw error;
799
+ }
366
800
  },
367
801
  deleteMessageFile(_, {
368
802
  url
369
803
  }, {
370
804
  postService
371
805
  }) {
372
- return postService.deleteFile(url);
806
+ options.logger.trace('(Mutation.deleteMessageFile) url [%s]', url);
807
+ try {
808
+ if (!url) {
809
+ options.logger.warn('Missing URL');
810
+ throw new Error('File URL is required');
811
+ }
812
+ if (!postService) {
813
+ options.logger.warn('PostService not available');
814
+ throw new Error('Post service unavailable');
815
+ }
816
+ return postService.deleteFile(url);
817
+ } catch (error) {
818
+ options.logger.error('Error deleting message file: %o', error);
819
+ throw error;
820
+ }
373
821
  },
374
822
  async readMessage(src, {
375
823
  messageId
@@ -378,11 +826,30 @@ const postResolvers = options => ({
378
826
  userContext,
379
827
  channelService
380
828
  }) {
381
- const member = await channelService.isMember(messageId.channelId, userContext.accountId);
382
- if (!member) {
383
- throw new GraphQLError('Message does not belong to user');
829
+ options.logger.trace('(Mutation.readMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
830
+ try {
831
+ if (!messageId?.channelId || !messageId?.messageId) {
832
+ options.logger.warn('Missing messageId parameters');
833
+ throw new GraphQLError('Message ID and Channel ID are required');
834
+ }
835
+ if (!userContext?.accountId) {
836
+ options.logger.warn('Missing user context');
837
+ throw new GraphQLError('User authentication required');
838
+ }
839
+ if (!postService || !channelService) {
840
+ options.logger.warn('Required services not available');
841
+ throw new GraphQLError('Required services unavailable');
842
+ }
843
+ const member = await channelService.isMember(messageId.channelId, userContext.accountId);
844
+ if (!member) {
845
+ options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
846
+ throw new GraphQLError('Message does not belong to user');
847
+ }
848
+ return postService.readMessage(messageId, userContext.accountId);
849
+ } catch (error) {
850
+ options.logger.error('Error reading message: %o', error);
851
+ throw error;
384
852
  }
385
- return postService.readMessage(messageId, userContext.accountId);
386
853
  },
387
854
  async deliverMessage(src, {
388
855
  messageId
@@ -391,70 +858,130 @@ const postResolvers = options => ({
391
858
  userContext,
392
859
  channelService
393
860
  }) {
394
- const member = await channelService.isMember(messageId.channelId, userContext.accountId);
395
- if (!member) {
396
- throw new GraphQLError('Message does not belong to user');
861
+ options.logger.trace('(Mutation.deliverMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
862
+ try {
863
+ if (!messageId?.channelId || !messageId?.messageId) {
864
+ options.logger.warn('Missing messageId parameters');
865
+ throw new GraphQLError('Message ID and Channel ID are required');
866
+ }
867
+ if (!userContext?.accountId) {
868
+ options.logger.warn('Missing user context');
869
+ throw new GraphQLError('User authentication required');
870
+ }
871
+ if (!postService || !channelService) {
872
+ options.logger.warn('Required services not available');
873
+ throw new GraphQLError('Required services unavailable');
874
+ }
875
+ const member = await channelService.isMember(messageId.channelId, userContext.accountId);
876
+ if (!member) {
877
+ options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
878
+ throw new GraphQLError('Message does not belong to user');
879
+ }
880
+ return postService.deliverMessage(messageId, userContext.accountId);
881
+ } catch (error) {
882
+ options.logger.error('Error delivering message: %o', error);
883
+ throw error;
397
884
  }
398
- return postService.deliverMessage(messageId, userContext.accountId);
399
885
  },
400
- // uploadFile(src, { files, postId }, { fileInfoService, userContext }) {
401
- // const res = [];
402
- // files.map((file) =>
403
- // res.push(
404
- // fileInfoService.create({
405
- // refType: FileRefType.Post as never,
406
- // file,
407
- // createdBy: userContext.accountId,
408
- // ref: postId,
409
- // }),
410
- // ),
411
- // );
412
- // return res;
413
- // },
414
886
  async TestchatMessage(src, {
415
887
  channelId
416
888
  }, context) {
417
- // if (!context.logger) {
418
- // throw new Error('Logger is not defined in context');
419
- // }
420
- options.pubsub.publish(`CHAT_CREATED.${channelId}`, {
421
- chatMessageTest: {
889
+ options.logger.trace('(Mutation.TestchatMessage) channelId [%s]', channelId);
890
+ try {
891
+ if (!channelId) {
892
+ options.logger.warn('Missing channelId');
893
+ throw new Error('Channel ID is required');
894
+ }
895
+ const testData = {
422
896
  channelId,
423
897
  orgName: 'upadhyaytarun'
424
- }
425
- });
426
- return {
427
- channelId,
428
- orgName: 'upadhyaytarun'
429
- };
898
+ };
899
+ options.logger.debug('Publishing test chat message for channel %s', channelId);
900
+ options.pubsub.publish(`CHAT_CREATED.${channelId}`, {
901
+ chatMessageTest: testData
902
+ });
903
+ return testData;
904
+ } catch (error) {
905
+ options.logger.error('Error in TestchatMessage: %o', error);
906
+ throw error;
907
+ }
430
908
  }
431
909
  },
432
910
  Subscription: {
433
911
  chatMessageAdded: {
434
- // More on pubsub below
435
912
  subscribe: (_, {
436
913
  channelId,
437
914
  directTo
438
915
  }) => {
439
- return options.pubsub.asyncIterator([`POST_CREATED.${channelId}`]);
916
+ options.logger.trace('(Subscription.chatMessageAdded) channelId [%s], directTo [%s]', channelId, directTo);
917
+ try {
918
+ if (!channelId) {
919
+ throw new Error('Channel ID is required for subscription');
920
+ }
921
+ return options.pubsub.asyncIterator([`POST_CREATED.${channelId}`]);
922
+ } catch (error) {
923
+ options.logger.error('Error subscribing to chatMessageAdded: %o', error);
924
+ throw error;
925
+ }
440
926
  },
441
- resolve: payload => payload
927
+ resolve: payload => {
928
+ options.logger.trace('(Subscription.chatMessageAdded.resolve) payload received');
929
+ return payload;
930
+ }
442
931
  },
443
932
  chatMessageTest: {
444
- // More on pubsub below
445
933
  subscribe: (_, {
446
934
  channelId,
447
935
  directTo
448
936
  }) => {
449
- return options.pubsub.asyncIterator([`CHAT_CREATED.${channelId}`]);
937
+ options.logger.trace('(Subscription.chatMessageTest) channelId [%s], directTo [%s]', channelId, directTo);
938
+ try {
939
+ if (!channelId) {
940
+ throw new Error('Channel ID is required for subscription');
941
+ }
942
+ return options.pubsub.asyncIterator([`CHAT_CREATED.${channelId}`]);
943
+ } catch (error) {
944
+ options.logger.error('Error subscribing to chatMessageTest: %o', error);
945
+ throw error;
946
+ }
450
947
  },
451
- resolve: payload => payload
948
+ resolve: payload => {
949
+ options.logger.trace('(Subscription.chatMessageTest.resolve) payload received');
950
+ return payload;
951
+ }
452
952
  },
453
953
  publicPostAdded: {
454
954
  subscribe: (_, {
455
955
  channelId
456
- }) => options.pubsub.asyncIterator([`PUBLIC_POST_CREATED.${channelId}`]),
457
- resolve: payload => payload
956
+ }) => {
957
+ options.logger.trace('(Subscription.publicPostAdded) channelId [%s]', channelId);
958
+ try {
959
+ if (!channelId) {
960
+ throw new Error('Channel ID is required for subscription');
961
+ }
962
+ return options.pubsub.asyncIterator([`PUBLIC_POST_CREATED.${channelId}`]);
963
+ } catch (error) {
964
+ options.logger.error('Error subscribing to publicPostAdded: %o', error);
965
+ throw error;
966
+ }
967
+ },
968
+ resolve: payload => {
969
+ options.logger.trace('(Subscription.publicPostAdded.resolve) payload received');
970
+ return payload;
971
+ }
972
+ },
973
+ fileUpdated: {
974
+ subscribe: withFilter((_, __, context) => options.pubsub.asyncIterator(['FILE_UPDATED']), (payload, variables) => payload.fileUpdated.projectId === variables.projectId),
975
+ resolve: (payload, _args, context) => {
976
+ try {
977
+ if (!context.userContext) context.userContext = {};
978
+ if (!context.req) context.req = {};
979
+ return payload.fileUpdated;
980
+ } catch (error) {
981
+ options.logger.error('File update subscription resolve error: %o', error);
982
+ return payload.fileUpdated;
983
+ }
984
+ }
458
985
  }
459
986
  }
460
987
  });export{postResolvers};//# sourceMappingURL=post.js.map