@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.
- package/lib/config/env-config.d.ts +7 -0
- package/lib/config/env-config.js +20 -0
- package/lib/config/env-config.js.map +1 -1
- package/lib/containers/containers.js +9 -1
- package/lib/containers/containers.js.map +1 -1
- package/lib/containers/context-services-from-container.d.ts +1 -1
- package/lib/containers/context-services-from-container.js +4 -2
- package/lib/containers/context-services-from-container.js.map +1 -1
- package/lib/graphql/resolvers/ai-fragment.d.ts +3 -0
- package/lib/graphql/resolvers/ai-fragment.js +276 -0
- package/lib/graphql/resolvers/ai-fragment.js.map +1 -0
- package/lib/graphql/resolvers/channel-member.d.ts +3 -2
- package/lib/graphql/resolvers/channel-member.js +30 -5
- package/lib/graphql/resolvers/channel-member.js.map +1 -1
- package/lib/graphql/resolvers/channel.d.ts +3 -2
- package/lib/graphql/resolvers/channel.js +308 -53
- package/lib/graphql/resolvers/channel.js.map +1 -1
- package/lib/graphql/resolvers/extended-token-account.d.ts +3 -2
- package/lib/graphql/resolvers/extended-token-account.js +90 -23
- package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
- package/lib/graphql/resolvers/index.d.ts +1 -1
- package/lib/graphql/resolvers/index.js +1 -1
- package/lib/graphql/resolvers/index.js.map +1 -1
- package/lib/graphql/resolvers/post-thread.d.ts +1 -1
- package/lib/graphql/resolvers/post-thread.js +294 -132
- package/lib/graphql/resolvers/post-thread.js.map +1 -1
- package/lib/graphql/resolvers/post.d.ts +2 -3
- package/lib/graphql/resolvers/post.js +874 -239
- package/lib/graphql/resolvers/post.js.map +1 -1
- package/lib/graphql/resolvers/reaction.d.ts +3 -2
- package/lib/graphql/resolvers/reaction.js +96 -14
- package/lib/graphql/resolvers/reaction.js.map +1 -1
- package/lib/graphql/schema/ai-fragment.graphql +311 -0
- package/lib/graphql/schema/ai-fragment.graphql.js +1 -0
- package/lib/graphql/schema/ai-fragment.graphql.js.map +1 -0
- package/lib/graphql/schema/channel-member.graphql +110 -21
- package/lib/graphql/schema/channel-member.graphql.js +1 -1
- package/lib/graphql/schema/channel.graphql +356 -38
- package/lib/graphql/schema/channel.graphql.js +1 -1
- package/lib/graphql/schema/index.js +2 -2
- package/lib/graphql/schema/index.js.map +1 -1
- package/lib/graphql/schema/post-thread.graphql +167 -21
- package/lib/graphql/schema/post-thread.graphql.js +1 -1
- package/lib/graphql/schema/post.graphql +360 -40
- package/lib/graphql/schema/post.graphql.js +1 -1
- package/lib/graphql/schema/reaction.graphql +71 -13
- package/lib/graphql/schema/reaction.graphql.js +1 -1
- package/lib/graphql/schema/services.graphql +21 -0
- package/lib/graphql/schema/users.graphql +76 -13
- package/lib/graphql/schema/users.graphql.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/inngest/factory.d.ts +20 -0
- package/lib/inngest/factory.js +4 -0
- package/lib/inngest/factory.js.map +1 -0
- package/lib/inngest/functions.d.ts +235 -0
- package/lib/inngest/functions.js +1385 -0
- package/lib/inngest/functions.js.map +1 -0
- package/lib/inngest/index.d.ts +3 -0
- package/lib/inngest/prompt.d.ts +6 -0
- package/lib/inngest/prompt.js +871 -0
- package/lib/inngest/prompt.js.map +1 -0
- package/lib/inngest/utils.d.ts +5 -0
- package/lib/inngest/utils.js +32 -0
- package/lib/inngest/utils.js.map +1 -0
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/interfaces/services.d.ts +1 -1
- package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.d.ts +17 -0
- package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js +44 -0
- package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js.map +1 -0
- package/lib/migrations/dbMigrations/index.d.ts +1 -0
- package/lib/migrations/index.d.ts +1 -0
- package/lib/migrations/mail-template-migration.js +1 -1
- package/lib/migrations/message-notification-template-migration.d.ts +1 -1
- package/lib/migrations/message-notification-template-migration.js +1 -1
- package/lib/module.js +10 -3
- package/lib/module.js.map +1 -1
- package/lib/plugins/ai-fragment-moleculer-service.d.ts +29 -0
- package/lib/plugins/ai-fragment-moleculer-service.js +516 -0
- package/lib/plugins/ai-fragment-moleculer-service.js.map +1 -0
- package/lib/plugins/channel-moleculer-service.d.ts +21 -1
- package/lib/plugins/channel-moleculer-service.js +426 -115
- package/lib/plugins/channel-moleculer-service.js.map +1 -1
- package/lib/plugins/extended-token-account-moleculer-service.d.ts +25 -1
- package/lib/plugins/extended-token-account-moleculer-service.js +348 -22
- package/lib/plugins/extended-token-account-moleculer-service.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/messenger-notification-moleculer-service.d.ts +27 -3
- package/lib/plugins/messenger-notification-moleculer-service.js +404 -58
- package/lib/plugins/messenger-notification-moleculer-service.js.map +1 -1
- package/lib/plugins/post-moleculer-service.d.ts +85 -21
- package/lib/plugins/post-moleculer-service.js +1102 -256
- package/lib/plugins/post-moleculer-service.js.map +1 -1
- package/lib/plugins/post-thread-moleculer-service.d.ts +33 -1
- package/lib/plugins/post-thread-moleculer-service.js +326 -8
- package/lib/plugins/post-thread-moleculer-service.js.map +1 -1
- package/lib/plugins/reaction-moleculer-service.js +1 -1
- package/lib/plugins/reaction-moleculer-service.js.map +1 -1
- package/lib/preferences/settings/post-settings.d.ts +2 -0
- package/lib/preferences/settings/post-settings.js +47 -9
- package/lib/preferences/settings/post-settings.js.map +1 -1
- package/lib/services/ai-fragment-service.d.ts +195 -0
- package/lib/services/ai-fragment-service.js +631 -0
- package/lib/services/ai-fragment-service.js.map +1 -0
- package/lib/services/channel-service.d.ts +181 -33
- package/lib/services/channel-service.js +842 -273
- package/lib/services/channel-service.js.map +1 -1
- package/lib/services/extended-token-account-service.d.ts +130 -14
- package/lib/services/extended-token-account-service.js +462 -52
- package/lib/services/extended-token-account-service.js.map +1 -1
- package/lib/services/index.d.ts +3 -0
- package/lib/services/messenger-notification-service.d.ts +106 -13
- package/lib/services/messenger-notification-service.js +824 -442
- package/lib/services/messenger-notification-service.js.map +1 -1
- package/lib/services/post-service.d.ts +189 -16
- package/lib/services/post-service.js +949 -113
- package/lib/services/post-service.js.map +1 -1
- package/lib/services/post-thread-service.d.ts +114 -5
- package/lib/services/post-thread-service.js +400 -13
- package/lib/services/post-thread-service.js.map +1 -1
- package/lib/services/proxy-services/ai-fragment-microservice.d.ts +23 -0
- package/lib/services/proxy-services/ai-fragment-microservice.js +78 -0
- package/lib/services/proxy-services/ai-fragment-microservice.js.map +1 -0
- package/lib/services/proxy-services/channel-microservice.d.ts +6 -3
- package/lib/services/proxy-services/channel-microservice.js +25 -10
- package/lib/services/proxy-services/channel-microservice.js.map +1 -1
- package/lib/services/proxy-services/index.d.ts +1 -0
- package/lib/services/proxy-services/messenger-notification-microservice.d.ts +128 -8
- package/lib/services/proxy-services/messenger-notification-microservice.js +324 -29
- package/lib/services/proxy-services/messenger-notification-microservice.js.map +1 -1
- package/lib/services/proxy-services/post-microservice.d.ts +207 -12
- package/lib/services/proxy-services/post-microservice.js +623 -54
- package/lib/services/proxy-services/post-microservice.js.map +1 -1
- package/lib/services/proxy-services/post-thread-microservice.d.ts +134 -3
- package/lib/services/proxy-services/post-thread-microservice.js +388 -6
- package/lib/services/proxy-services/post-thread-microservice.js.map +1 -1
- package/lib/services/proxy-services/reaction-microservice.d.ts +161 -3
- package/lib/services/proxy-services/reaction-microservice.js +474 -2
- package/lib/services/proxy-services/reaction-microservice.js.map +1 -1
- package/lib/services/reaction-service.d.ts +124 -4
- package/lib/services/reaction-service.js +415 -3
- package/lib/services/reaction-service.js.map +1 -1
- package/lib/services/redis-cache-manager.d.ts +18 -0
- package/lib/services/redis-cache-manager.js +83 -0
- package/lib/services/redis-cache-manager.js.map +1 -0
- package/lib/services/sandbox-error-service.d.ts +23 -0
- package/lib/services/sandbox-error-service.js +422 -0
- package/lib/services/sandbox-error-service.js.map +1 -0
- package/lib/store/models/account-token-store.d.ts +1 -1
- package/lib/store/models/account-token-store.js.map +1 -1
- package/lib/store/models/ai-fragment.d.ts +4 -0
- package/lib/store/models/ai-fragment.js +125 -0
- package/lib/store/models/ai-fragment.js.map +1 -0
- package/lib/store/models/channel.d.ts +2 -3
- package/lib/store/models/channel.js +185 -71
- package/lib/store/models/channel.js.map +1 -1
- package/lib/store/models/index.d.ts +1 -0
- package/lib/store/models/post-thread.d.ts +3 -3
- package/lib/store/models/post-thread.js +96 -14
- package/lib/store/models/post-thread.js.map +1 -1
- package/lib/store/models/post.d.ts +2 -3
- package/lib/store/models/post.js +143 -23
- package/lib/store/models/post.js.map +1 -1
- package/lib/store/models/reaction.d.ts +2 -3
- package/lib/store/models/reaction.js +67 -8
- package/lib/store/models/reaction.js.map +1 -1
- package/lib/store/repositories/__tests__/__fixtures__/team-repository.d.ts +3 -3
- package/lib/store/repositories/ai-fragment-repository.d.ts +15 -0
- package/lib/store/repositories/ai-fragment-repository.js +69 -0
- package/lib/store/repositories/ai-fragment-repository.js.map +1 -0
- package/lib/store/repositories/channel-repository.d.ts +6 -6
- package/lib/store/repositories/channel-repository.js +5 -2
- package/lib/store/repositories/channel-repository.js.map +1 -1
- package/lib/store/repositories/index.d.ts +1 -0
- package/lib/store/repositories/post-repository.d.ts +6 -6
- package/lib/store/repositories/post-repository.js +5 -2
- package/lib/store/repositories/post-repository.js.map +1 -1
- package/lib/store/repositories/post-thread-repository.d.ts +6 -6
- package/lib/store/repositories/post-thread-repository.js +5 -2
- package/lib/store/repositories/post-thread-repository.js.map +1 -1
- package/lib/store/repositories/reaction-repository.d.ts +6 -6
- package/lib/store/repositories/reaction-repository.js +5 -2
- package/lib/store/repositories/reaction-repository.js.map +1 -1
- package/lib/templates/constants/SERVER_TYPES.ts.template +4 -4
- package/lib/templates/repositories/AiFragmentRepository.ts.template +4 -0
- package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
- package/lib/templates/repositories/PostRepository.ts.template +3 -3
- package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
- package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
- package/lib/templates/services/AiFragmentService.ts.template +123 -0
- package/lib/templates/services/ChannelService.ts.template +290 -39
- package/lib/templates/services/ExtendedTokenAccountService.ts.template +104 -9
- package/lib/templates/services/MessengerNotificationService.ts.template +94 -19
- package/lib/templates/services/PostService.ts.template +265 -20
- package/lib/templates/services/PostThreadService.ts.template +151 -6
- package/lib/templates/services/ReactionService.ts.template +129 -3
- package/lib/templates/services/RedisCacheManager.ts.template +22 -0
- package/lib/templates/services/SandboxErrorService.ts.template +125 -0
- package/package.json +14 -7
- package/lib/interfaces/context.d.ts +0 -14
- package/lib/store/models/common-options.js +0 -20
- package/lib/store/models/common-options.js.map +0 -1
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import {__decorate,__param,__metadata}from'tslib';import {injectable,inject}from'inversify';import {ServiceBroker}from'moleculer';import {CommonType}from'@common-stack/core';import {MoleculerTopics,PostServiceCommands}from'common';import {BaseProxyService}from'@common-stack/store-mongo';import'@cdm-logger/core';
|
|
1
|
+
import {__decorate,__param,__metadata}from'tslib';import {injectable,inject}from'inversify';import {ServiceBroker}from'moleculer';import {CommonType}from'@common-stack/core';import {MoleculerTopics,PostServiceCommands}from'common/server';import {BaseProxyService}from'@common-stack/store-mongo';import'@cdm-logger/core';import {DisposableCollection}from'@adminide-stack/core';/**
|
|
2
|
+
* Post Microservice Implementation
|
|
3
|
+
*
|
|
4
|
+
* This microservice handles comprehensive post management within the messenger platform,
|
|
5
|
+
* providing operations for creating, updating, managing posts and their associated
|
|
6
|
+
* content including file attachments, notifications, threading, and real-time
|
|
7
|
+
* message delivery across channels and organizations through service broker delegation.
|
|
8
|
+
*
|
|
9
|
+
* Key capabilities:
|
|
10
|
+
* - Post lifecycle management (creation, updates, deletion)
|
|
11
|
+
* - File attachment handling and upload management
|
|
12
|
+
* - Real-time message delivery and notifications
|
|
13
|
+
* - Post threading and conversation management
|
|
14
|
+
* - Message status tracking (read, delivered)
|
|
15
|
+
* - Channel integration and message counting
|
|
16
|
+
* - Expo push notification integration
|
|
17
|
+
* - File upload link generation and management
|
|
18
|
+
*/
|
|
19
|
+
let PostProxyService = class PostProxyService extends BaseProxyService {
|
|
2
20
|
logger;
|
|
21
|
+
toDispose = new DisposableCollection();
|
|
3
22
|
topic = MoleculerTopics.PostService;
|
|
4
23
|
constructor(broker, logger) {
|
|
5
24
|
super(broker, logger.child({
|
|
@@ -7,58 +26,608 @@ import {__decorate,__param,__metadata}from'tslib';import {injectable,inject}from
|
|
|
7
26
|
}));
|
|
8
27
|
this.logger = logger;
|
|
9
28
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Disposes of resources used by the service
|
|
31
|
+
*/
|
|
32
|
+
dispose() {
|
|
33
|
+
this.toDispose.dispose();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a file upload link for a post
|
|
37
|
+
*
|
|
38
|
+
* @description Generates a secure upload URL for attaching files to posts
|
|
39
|
+
*
|
|
40
|
+
* @param {string} postId - The post identifier
|
|
41
|
+
* @param {string} filename - The name of the file to upload
|
|
42
|
+
* @param {string} userId - The user performing the upload
|
|
43
|
+
* @returns {Promise<string | Error>} - Upload URL or error
|
|
44
|
+
*/
|
|
45
|
+
async createFileUploadLink(postId, filename, userId) {
|
|
46
|
+
try {
|
|
47
|
+
this.logger.debug('Creating file upload link via microservice', {
|
|
48
|
+
postId,
|
|
49
|
+
filename,
|
|
50
|
+
userId
|
|
51
|
+
});
|
|
52
|
+
const result = await this.callAction(PostServiceCommands.CreateFileUploadLink, {
|
|
53
|
+
filename,
|
|
54
|
+
userId,
|
|
55
|
+
postId
|
|
56
|
+
});
|
|
57
|
+
if (!result) {
|
|
58
|
+
return new Error('Failed to create file upload link');
|
|
59
|
+
}
|
|
60
|
+
this.logger.debug('File upload link created successfully via microservice', {
|
|
61
|
+
postId,
|
|
62
|
+
filename,
|
|
63
|
+
userId
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
this.logger.error('Error creating file upload link via microservice: %o', error);
|
|
68
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while creating upload link');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Attaches an uploaded file to a post
|
|
73
|
+
*
|
|
74
|
+
* @description Processes and attaches a completed file upload to a post
|
|
75
|
+
*
|
|
76
|
+
* @param {string} postId - The post identifier
|
|
77
|
+
* @param {IUploadedFileInput} file - The uploaded file information
|
|
78
|
+
* @param {string} createdBy - The user who uploaded the file
|
|
79
|
+
* @returns {Promise<IFileInfo | Error>} - File information or error
|
|
80
|
+
*/
|
|
81
|
+
async attachUploadedFile(postId, file, createdBy) {
|
|
82
|
+
try {
|
|
83
|
+
this.logger.debug('Attaching uploaded file via microservice', {
|
|
84
|
+
postId,
|
|
85
|
+
file,
|
|
86
|
+
createdBy
|
|
87
|
+
});
|
|
88
|
+
const result = await this.callAction(PostServiceCommands.AttachUploadedFile, {
|
|
89
|
+
file,
|
|
90
|
+
createdBy,
|
|
91
|
+
postId
|
|
92
|
+
});
|
|
93
|
+
if (!result) {
|
|
94
|
+
return new Error('Failed to attach uploaded file');
|
|
95
|
+
}
|
|
96
|
+
this.logger.debug('File attached successfully via microservice', {
|
|
97
|
+
postId,
|
|
98
|
+
fileId: result.id,
|
|
99
|
+
createdBy
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
this.logger.error('Error attaching uploaded file via microservice: %o', error);
|
|
104
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while attaching file');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates upload links for multiple files
|
|
109
|
+
*
|
|
110
|
+
* @description Generates secure upload URLs for multiple files to be attached to a post
|
|
111
|
+
*
|
|
112
|
+
* @param {string} postId - The post identifier
|
|
113
|
+
* @param {string[]} filenames - Array of file names
|
|
114
|
+
* @param {string} userId - The user performing the uploads
|
|
115
|
+
* @returns {Promise<string[] | Error>} - Array of upload URLs or error
|
|
116
|
+
*/
|
|
117
|
+
async createFilesUploadLink(postId, filenames, userId) {
|
|
118
|
+
try {
|
|
119
|
+
this.logger.debug('Creating multiple file upload links via microservice', {
|
|
120
|
+
postId,
|
|
121
|
+
fileCount: filenames.length,
|
|
122
|
+
userId
|
|
123
|
+
});
|
|
124
|
+
const result = await this.callAction(PostServiceCommands.CreateFilesUploadLink, {
|
|
125
|
+
filenames,
|
|
126
|
+
userId,
|
|
127
|
+
postId
|
|
128
|
+
});
|
|
129
|
+
if (!Array.isArray(result)) {
|
|
130
|
+
return new Error('Invalid result from microservice');
|
|
131
|
+
}
|
|
132
|
+
this.logger.debug('Multiple file upload links created successfully via microservice', {
|
|
133
|
+
postId,
|
|
134
|
+
fileCount: result.length
|
|
135
|
+
});
|
|
136
|
+
return result;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
this.logger.error('Error creating multiple file upload links via microservice: %o', error);
|
|
139
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while creating upload links');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Attaches multiple uploaded files to a post
|
|
144
|
+
*
|
|
145
|
+
* @description Processes and attaches multiple completed file uploads to a post
|
|
146
|
+
*
|
|
147
|
+
* @param {string} postId - The post identifier
|
|
148
|
+
* @param {IUploadedFileInput[]} files - Array of uploaded file information
|
|
149
|
+
* @param {string} createdBy - The user who uploaded the files
|
|
150
|
+
* @returns {Promise<IFileInfo[] | Error>} - Array of file information or error
|
|
151
|
+
*/
|
|
152
|
+
async attachUploadedFiles(postId, files, createdBy) {
|
|
153
|
+
try {
|
|
154
|
+
this.logger.debug('Attaching multiple uploaded files via microservice', {
|
|
155
|
+
postId,
|
|
156
|
+
fileCount: files.length,
|
|
157
|
+
createdBy
|
|
158
|
+
});
|
|
159
|
+
const result = await this.callAction(PostServiceCommands.AttachUploadedFiles, {
|
|
160
|
+
files,
|
|
161
|
+
createdBy,
|
|
162
|
+
postId
|
|
163
|
+
});
|
|
164
|
+
if (!Array.isArray(result)) {
|
|
165
|
+
return new Error('Invalid result from microservice');
|
|
166
|
+
}
|
|
167
|
+
this.logger.debug('Multiple files attached successfully via microservice', {
|
|
168
|
+
postId,
|
|
169
|
+
fileCount: result.length
|
|
170
|
+
});
|
|
171
|
+
return result;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
this.logger.error('Error attaching multiple uploaded files via microservice: %o', error);
|
|
174
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while attaching files');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates a new post with full integration
|
|
179
|
+
*
|
|
180
|
+
* @description Creates a post with channel updates, notifications, and real-time publishing
|
|
181
|
+
*
|
|
182
|
+
* @param {IPostServiceInput} data - Post creation data
|
|
183
|
+
* @returns {Promise<AsDomainType<IPostModel> | Error>} - Created post or error
|
|
184
|
+
*/
|
|
185
|
+
// @ts-ignore - Enhanced error handling pattern with Error union type
|
|
186
|
+
async create(data) {
|
|
187
|
+
try {
|
|
188
|
+
this.logger.debug('Creating post via microservice', {
|
|
189
|
+
data
|
|
190
|
+
});
|
|
191
|
+
const result = await this.broker.call(`${this.topic}.create`, {
|
|
192
|
+
data
|
|
193
|
+
});
|
|
194
|
+
if (!result) {
|
|
195
|
+
return new Error('Failed to create post');
|
|
196
|
+
}
|
|
197
|
+
this.logger.debug('Post created successfully via microservice', {
|
|
198
|
+
postId: result.id,
|
|
199
|
+
channelId: data.channel
|
|
200
|
+
});
|
|
201
|
+
return result;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
this.logger.error('Error creating post via microservice: %o', error);
|
|
204
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while creating post');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Creates a post without real-time subscription
|
|
209
|
+
*
|
|
210
|
+
* @description Creates a post with channel updates but without real-time publishing
|
|
211
|
+
*
|
|
212
|
+
* @param {IPostServiceInput} data - Post creation data
|
|
213
|
+
* @returns {Promise<AsDomainType<IPostModel> | Error>} - Created post or error
|
|
214
|
+
*/
|
|
215
|
+
// @ts-ignore - Enhanced error handling pattern with Error union type
|
|
216
|
+
async createWithoutSubscription(data) {
|
|
217
|
+
try {
|
|
218
|
+
this.logger.debug('Creating post without subscription via microservice', {
|
|
219
|
+
data
|
|
220
|
+
});
|
|
221
|
+
const result = await this.callAction(PostServiceCommands.CreateWithoutSubscription, {
|
|
222
|
+
data
|
|
223
|
+
});
|
|
224
|
+
if (!result) {
|
|
225
|
+
return new Error('Failed to create post without subscription');
|
|
226
|
+
}
|
|
227
|
+
this.logger.debug('Post created without subscription successfully via microservice', {
|
|
228
|
+
postId: result.id
|
|
229
|
+
});
|
|
230
|
+
return result;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
this.logger.error('Error creating post without subscription via microservice: %o', error);
|
|
233
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while creating post');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Deletes a file by URL
|
|
238
|
+
*
|
|
239
|
+
* @description Removes a file from storage using its URL
|
|
240
|
+
*
|
|
241
|
+
* @param {string} url - The file URL to delete
|
|
242
|
+
* @returns {Promise<boolean | Error>} - Success status or error
|
|
243
|
+
*/
|
|
244
|
+
async deleteFile(url) {
|
|
245
|
+
try {
|
|
246
|
+
this.logger.debug('Deleting file via microservice', {
|
|
247
|
+
url
|
|
248
|
+
});
|
|
249
|
+
const result = await this.callAction(PostServiceCommands.DeleteFile, {
|
|
250
|
+
url
|
|
251
|
+
});
|
|
252
|
+
if (typeof result !== 'boolean') {
|
|
253
|
+
return new Error('Invalid result from microservice');
|
|
254
|
+
}
|
|
255
|
+
this.logger.debug('File deleted successfully via microservice', {
|
|
256
|
+
url,
|
|
257
|
+
success: result
|
|
258
|
+
});
|
|
259
|
+
return result;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this.logger.error('Error deleting file via microservice: %o', error);
|
|
262
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while deleting file');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Marks a message as read by a user
|
|
267
|
+
*
|
|
268
|
+
* @description Updates message status to indicate it has been read by a specific user
|
|
269
|
+
*
|
|
270
|
+
* @param {IMessageIdentifier} messageId - Message identifier
|
|
271
|
+
* @param {string} user - User ID who read the message
|
|
272
|
+
* @returns {Promise<boolean | Error>} - Success status or error
|
|
273
|
+
*/
|
|
274
|
+
async readMessage(messageId, user) {
|
|
275
|
+
try {
|
|
276
|
+
this.logger.debug('Marking message as read via microservice', {
|
|
277
|
+
messageId,
|
|
278
|
+
user
|
|
279
|
+
});
|
|
280
|
+
const result = await this.callAction(PostServiceCommands.ReadMessage, {
|
|
281
|
+
...messageId,
|
|
282
|
+
user
|
|
283
|
+
});
|
|
284
|
+
if (typeof result !== 'boolean') {
|
|
285
|
+
return new Error('Invalid result from microservice');
|
|
286
|
+
}
|
|
287
|
+
this.logger.debug('Message marked as read successfully via microservice', {
|
|
288
|
+
messageId,
|
|
289
|
+
user,
|
|
290
|
+
success: result
|
|
291
|
+
});
|
|
292
|
+
return result;
|
|
293
|
+
} catch (error) {
|
|
294
|
+
this.logger.error('Error marking message as read via microservice: %o', error);
|
|
295
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while marking message as read');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Marks a message as delivered to a user
|
|
300
|
+
*
|
|
301
|
+
* @description Updates message status to indicate it has been delivered to a specific user
|
|
302
|
+
*
|
|
303
|
+
* @param {IMessageIdentifier} messageId - Message identifier
|
|
304
|
+
* @param {string} user - User ID who received the message
|
|
305
|
+
* @returns {Promise<boolean | Error>} - Success status or error
|
|
306
|
+
*/
|
|
307
|
+
async deliverMessage(messageId, user) {
|
|
308
|
+
try {
|
|
309
|
+
this.logger.debug('Marking message as delivered via microservice', {
|
|
310
|
+
messageId,
|
|
311
|
+
user
|
|
312
|
+
});
|
|
313
|
+
const result = await this.callAction(PostServiceCommands.DeliverMessage, {
|
|
314
|
+
...messageId,
|
|
315
|
+
user
|
|
316
|
+
});
|
|
317
|
+
if (typeof result !== 'boolean') {
|
|
318
|
+
return new Error('Invalid result from microservice');
|
|
319
|
+
}
|
|
320
|
+
this.logger.debug('Message marked as delivered successfully via microservice', {
|
|
321
|
+
messageId,
|
|
322
|
+
user,
|
|
323
|
+
success: result
|
|
324
|
+
});
|
|
325
|
+
return result;
|
|
326
|
+
} catch (error) {
|
|
327
|
+
this.logger.error('Error marking message as delivered via microservice: %o', error);
|
|
328
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while marking message as delivered');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates a post with associated post thread
|
|
333
|
+
*
|
|
334
|
+
* @description Creates both a post and its associated thread for threaded conversations
|
|
335
|
+
*
|
|
336
|
+
* @param {CreatePostThreadOptions} data - Post and thread creation options
|
|
337
|
+
* @returns {Promise<{post: AsDomainType<IPostModel>; postThread: IPostThread} | Error>} - Created post and thread or error
|
|
338
|
+
*/
|
|
339
|
+
// @ts-ignore - Enhanced error handling pattern with Error union type
|
|
340
|
+
async createPostWithPostThread(data) {
|
|
341
|
+
try {
|
|
342
|
+
this.logger.debug('Creating post with thread via microservice', {
|
|
343
|
+
data
|
|
344
|
+
});
|
|
345
|
+
const result = await this.callAction(PostServiceCommands.CreatePostWithPostThread, data);
|
|
346
|
+
if (!result || !result.post || !result.postThread) {
|
|
347
|
+
return new Error('Failed to create post with thread');
|
|
348
|
+
}
|
|
349
|
+
this.logger.debug('Post with thread created successfully via microservice', {
|
|
350
|
+
postId: result.post.id,
|
|
351
|
+
threadId: result.postThread.id
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
post: result.post,
|
|
355
|
+
postThread: result.postThread
|
|
356
|
+
};
|
|
357
|
+
} catch (error) {
|
|
358
|
+
this.logger.error('Error creating post with thread via microservice: %o', error);
|
|
359
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while creating post with thread');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Retrieves the last message in a channel
|
|
364
|
+
*
|
|
365
|
+
* @description Gets the most recent post/message from a specific channel
|
|
366
|
+
*
|
|
367
|
+
* @param {string} channelId - The channel identifier
|
|
368
|
+
* @returns {Promise<AsDomainType<IPostModel> | Error>} - Last message or error
|
|
369
|
+
*/
|
|
370
|
+
// @ts-ignore - Enhanced error handling pattern with Error union type
|
|
371
|
+
async getLastMessage(channelId) {
|
|
372
|
+
try {
|
|
373
|
+
this.logger.debug('Getting last message via microservice', {
|
|
374
|
+
channelId
|
|
375
|
+
});
|
|
376
|
+
const result = await this.callAction(PostServiceCommands.GetLastMessage, {
|
|
377
|
+
channelId
|
|
378
|
+
});
|
|
379
|
+
if (!result) {
|
|
380
|
+
return new Error('No messages found in channel');
|
|
381
|
+
}
|
|
382
|
+
this.logger.debug('Last message retrieved successfully via microservice', {
|
|
383
|
+
channelId,
|
|
384
|
+
postId: result.id
|
|
385
|
+
});
|
|
386
|
+
return result;
|
|
387
|
+
} catch (error) {
|
|
388
|
+
this.logger.error('Error getting last message via microservice: %o', error);
|
|
389
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while getting last message');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Gets posts by channel with pagination
|
|
394
|
+
*
|
|
395
|
+
* @description Retrieves posts from a channel with pagination support
|
|
396
|
+
*
|
|
397
|
+
* @param {string} channelId - The channel identifier
|
|
398
|
+
* @param {number} limit - Maximum number of posts to return
|
|
399
|
+
* @param {number} offset - Number of posts to skip
|
|
400
|
+
* @returns {Promise<Array<AsDomainType<IPostModel>> | Error>} - Array of posts or error
|
|
401
|
+
*/
|
|
402
|
+
async getPostsByChannel(channelId, limit = 50, offset = 0) {
|
|
403
|
+
try {
|
|
404
|
+
this.logger.debug('Getting posts by channel via microservice', {
|
|
405
|
+
channelId,
|
|
406
|
+
limit,
|
|
407
|
+
offset
|
|
408
|
+
});
|
|
409
|
+
const result = await this.broker.call(`${this.topic}.getPostsByChannel`, {
|
|
410
|
+
channelId,
|
|
411
|
+
limit,
|
|
412
|
+
offset
|
|
413
|
+
});
|
|
414
|
+
if (!Array.isArray(result)) {
|
|
415
|
+
return new Error('Invalid result from microservice');
|
|
416
|
+
}
|
|
417
|
+
this.logger.debug('Posts by channel retrieved successfully via microservice', {
|
|
418
|
+
channelId,
|
|
419
|
+
count: result.length
|
|
420
|
+
});
|
|
421
|
+
return result;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
this.logger.error('Error getting posts by channel via microservice: %o', error);
|
|
424
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while getting posts by channel');
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Updates a post
|
|
429
|
+
*
|
|
430
|
+
* @description Updates post content and metadata
|
|
431
|
+
*
|
|
432
|
+
* @param {string} postId - The post identifier
|
|
433
|
+
* @param {Partial<IPostServiceInput>} updates - Update data
|
|
434
|
+
* @returns {Promise<AsDomainType<IPostModel> | Error>} - Updated post or error
|
|
435
|
+
*/
|
|
436
|
+
async updatePost(postId, updates) {
|
|
437
|
+
try {
|
|
438
|
+
this.logger.debug('Updating post via microservice', {
|
|
439
|
+
postId,
|
|
440
|
+
updates
|
|
441
|
+
});
|
|
442
|
+
const result = await this.broker.call(`${this.topic}.updatePost`, {
|
|
443
|
+
postId,
|
|
444
|
+
updates
|
|
445
|
+
});
|
|
446
|
+
if (!result) {
|
|
447
|
+
return new Error('Failed to update post');
|
|
448
|
+
}
|
|
449
|
+
this.logger.debug('Post updated successfully via microservice', {
|
|
450
|
+
postId
|
|
451
|
+
});
|
|
452
|
+
return result;
|
|
453
|
+
} catch (error) {
|
|
454
|
+
this.logger.error('Error updating post via microservice: %o', error);
|
|
455
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while updating post');
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Deletes a post
|
|
460
|
+
*
|
|
461
|
+
* @description Soft deletes a post and its associated data
|
|
462
|
+
*
|
|
463
|
+
* @param {string} postId - The post identifier
|
|
464
|
+
* @returns {Promise<boolean | Error>} - Success status or error
|
|
465
|
+
*/
|
|
466
|
+
async deletePost(postId) {
|
|
467
|
+
try {
|
|
468
|
+
this.logger.debug('Deleting post via microservice', {
|
|
469
|
+
postId
|
|
470
|
+
});
|
|
471
|
+
const result = await this.broker.call(`${this.topic}.deletePost`, {
|
|
472
|
+
postId
|
|
473
|
+
});
|
|
474
|
+
if (typeof result !== 'boolean') {
|
|
475
|
+
return new Error('Invalid result from microservice');
|
|
476
|
+
}
|
|
477
|
+
this.logger.debug('Post deleted successfully via microservice', {
|
|
478
|
+
postId,
|
|
479
|
+
success: result
|
|
480
|
+
});
|
|
481
|
+
return result;
|
|
482
|
+
} catch (error) {
|
|
483
|
+
this.logger.error('Error deleting post via microservice: %o', error);
|
|
484
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while deleting post');
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Validates post data for creation or updates
|
|
489
|
+
*
|
|
490
|
+
* @description Helper method to validate post data before processing
|
|
491
|
+
*
|
|
492
|
+
* @param {IPostServiceInput} data - Data to validate
|
|
493
|
+
* @returns {Promise<boolean | Error>} - Validation result or error
|
|
494
|
+
*/
|
|
495
|
+
async validatePostData(data) {
|
|
496
|
+
try {
|
|
497
|
+
if (!data) {
|
|
498
|
+
return new Error('Post data is required');
|
|
499
|
+
}
|
|
500
|
+
if (!data.channel) {
|
|
501
|
+
return new Error('Channel is required');
|
|
502
|
+
}
|
|
503
|
+
if (!data.author) {
|
|
504
|
+
return new Error('Author is required');
|
|
505
|
+
}
|
|
506
|
+
this.logger.debug('Post data validation passed', {
|
|
507
|
+
data
|
|
508
|
+
});
|
|
509
|
+
return true;
|
|
510
|
+
} catch (error) {
|
|
511
|
+
this.logger.error('Error validating post data: %o', error);
|
|
512
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while validating post data');
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Gets posts by author with pagination
|
|
517
|
+
*
|
|
518
|
+
* @description Convenience method to get posts created by a specific author
|
|
519
|
+
*
|
|
520
|
+
* @param {string} authorId - The author identifier
|
|
521
|
+
* @param {number} limit - Maximum number of posts to return
|
|
522
|
+
* @param {number} offset - Number of posts to skip
|
|
523
|
+
* @returns {Promise<Array<AsDomainType<IPostModel>> | Error>} - Array of posts or error
|
|
524
|
+
*/
|
|
525
|
+
async getPostsByAuthor(authorId, limit = 50, offset = 0) {
|
|
526
|
+
try {
|
|
527
|
+
this.logger.debug('Getting posts by author via microservice', {
|
|
528
|
+
authorId,
|
|
529
|
+
limit,
|
|
530
|
+
offset
|
|
531
|
+
});
|
|
532
|
+
const result = await this.broker.call(`${this.topic}.getPostsByAuthor`, {
|
|
533
|
+
authorId,
|
|
534
|
+
limit,
|
|
535
|
+
offset
|
|
536
|
+
});
|
|
537
|
+
if (!Array.isArray(result)) {
|
|
538
|
+
return new Error('Invalid result from microservice');
|
|
539
|
+
}
|
|
540
|
+
this.logger.debug('Posts by author retrieved successfully via microservice', {
|
|
541
|
+
authorId,
|
|
542
|
+
count: result.length
|
|
543
|
+
});
|
|
544
|
+
return result;
|
|
545
|
+
} catch (error) {
|
|
546
|
+
this.logger.error('Error getting posts by author via microservice: %o', error);
|
|
547
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while getting posts by author');
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Retrieves previous messages for a specific project
|
|
552
|
+
*
|
|
553
|
+
* @description Fetches the most recent messages from a project, formatted for AI agent context.
|
|
554
|
+
*
|
|
555
|
+
* @param {string} projectId - The unique identifier of the project
|
|
556
|
+
* @param {number} limit - Maximum number of messages to retrieve (default: 5)
|
|
557
|
+
* @returns {Promise<Array<IPostModel> | Error>} - Array of formatted messages or error
|
|
558
|
+
*/
|
|
559
|
+
// @ts-ignore - Enhanced error handling pattern with Error union type
|
|
560
|
+
async getPreviousMessagesByProjectId(projectId, limit) {
|
|
561
|
+
try {
|
|
562
|
+
this.logger.debug('Getting previous messages by project ID via microservice: %s', projectId);
|
|
563
|
+
const result = await this.callAction('getPreviousMessagesByProjectId', {
|
|
564
|
+
projectId,
|
|
565
|
+
limit
|
|
566
|
+
});
|
|
567
|
+
this.logger.debug('Successfully retrieved previous messages by project ID via microservice');
|
|
568
|
+
return result;
|
|
569
|
+
} catch (error) {
|
|
570
|
+
this.logger.error('Error getting previous messages by project ID via microservice: %o', error);
|
|
571
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while getting previous messages by project ID');
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Saves code agent result with comprehensive data
|
|
576
|
+
*
|
|
577
|
+
* @description Saves the result from a code agent operation including message creation,
|
|
578
|
+
* fragment generation, and project update publishing. Handles both success and error cases
|
|
579
|
+
* with proper message creation and fragment management.
|
|
580
|
+
*/
|
|
581
|
+
async saveCodeAgentResult(request, sandboxUrl, fragmentTitle, responseContent, files, summary, isError, canvasLayers) {
|
|
582
|
+
try {
|
|
583
|
+
this.logger.debug('Saving code agent result via microservice', {
|
|
584
|
+
request,
|
|
585
|
+
sandboxUrl,
|
|
586
|
+
fragmentTitle,
|
|
587
|
+
responseContent,
|
|
588
|
+
files,
|
|
589
|
+
summary,
|
|
590
|
+
isError,
|
|
591
|
+
canvasLayers
|
|
592
|
+
});
|
|
593
|
+
const result = await this.callAction('saveCodeAgentResult', {
|
|
594
|
+
request,
|
|
595
|
+
sandboxUrl,
|
|
596
|
+
fragmentTitle,
|
|
597
|
+
responseContent,
|
|
598
|
+
files,
|
|
599
|
+
summary,
|
|
600
|
+
isError,
|
|
601
|
+
canvasLayers
|
|
602
|
+
});
|
|
603
|
+
this.logger.debug('Successfully saved code agent result via microservice');
|
|
604
|
+
return result;
|
|
605
|
+
} catch (error) {
|
|
606
|
+
this.logger.error('Error saving code agent result via microservice: %o', error);
|
|
607
|
+
return error instanceof Error ? error : new Error('Unknown error occurred while saving code agent result');
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
async updateSandboxFile(projectId, messageId, filePath, content) {
|
|
611
|
+
try {
|
|
612
|
+
const result = await this.callAction('updateSandboxFile', {
|
|
613
|
+
projectId,
|
|
614
|
+
messageId,
|
|
615
|
+
filePath,
|
|
616
|
+
content
|
|
617
|
+
});
|
|
618
|
+
return result;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
this.logger.error('Error updating sandbox file via microservice: %o', error);
|
|
621
|
+
return {
|
|
622
|
+
success: false,
|
|
623
|
+
message: error instanceof Error ? error.message : 'Unknown error occurred while updating sandbox file',
|
|
624
|
+
filePath,
|
|
625
|
+
timestamp: new Date().toISOString(),
|
|
626
|
+
syncStatus: 'error'
|
|
627
|
+
};
|
|
628
|
+
}
|
|
62
629
|
}
|
|
63
630
|
};
|
|
64
|
-
PostProxyService = __decorate([injectable()
|
|
631
|
+
PostProxyService = __decorate([injectable()
|
|
632
|
+
// @ts-ignore - Type compatibility issue between BaseProxyService and IPostService
|
|
633
|
+
, __param(0, inject(CommonType.MOLECULER_BROKER)), __param(1, inject('Logger')), __metadata("design:paramtypes", [ServiceBroker, Object])], PostProxyService);export{PostProxyService};//# sourceMappingURL=post-microservice.js.map
|