@lyxa.ai/core 1.4.65 → 1.4.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -154,18 +154,16 @@ async function registerLibraries(options) {
154
154
  typedi_1.Container.set(fcmService_1.FCMServiceForShop, fcmServiceInstanceForShop);
155
155
  typedi_1.Container.set(fcmService_1.FCMServiceForCpanel, fcmServiceInstanceForCpanel);
156
156
  console.log('Initialized everything');
157
- await (0, event_1.initEventBus)(rabbitmq_environments_1.RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType_1.EnvironmentConfigurationType.DEV]);
157
+ await (0, event_1.initRabbitMQConnection)(rabbitmq_environments_1.RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType_1.EnvironmentConfigurationType.DEV]);
158
158
  const allSubscriptions = SubscriptionRegistry_1.SubscriptionRegistry.getAllSubscriptions();
159
159
  const instantiatedServices = new Map();
160
- for (const { eventId, targetConstructor, methodName, opts } of allSubscriptions) {
160
+ for (const { eventId, targetConstructor, methodName } of allSubscriptions) {
161
161
  let instance = instantiatedServices.get(targetConstructor);
162
162
  if (!instance) {
163
163
  instance = typedi_1.Container.get(targetConstructor);
164
164
  instantiatedServices.set(targetConstructor, instance);
165
165
  }
166
- await (0, event_1.subscribeToEvent)(eventId, async (payload) => {
167
- return instance[methodName](payload);
168
- }, opts);
166
+ await (0, event_1.subscribeToEvent)(eventId, async (payload) => instance[methodName](payload));
169
167
  }
170
168
  }
171
169
  function getLibraries() {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,sCA0BC;AAED,8CA+GC;AAED,oCAEC;AAlLD,qFAAqF;AACrF,IAAA,0CAAqB,GAAE,CAAC;AACxB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;AACvF,+CA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AK,EAAC,OAAO,EAAC,EAAE;YACf,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,EACD,IAAI,CACJ,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\napplySoftDeletePlugin();\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initEventBus, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport {\n\tFCMService,\n\tFCMServiceForCpanel,\n\tFCMServiceForRider,\n\tFCMServiceForShop,\n\tFCMServiceForUser,\n} from './libraries/firebase/fcmService';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst firebaseService = getLibraries().getFirebaseService();\n\tconst fcmServiceInstance = new FCMService(firebaseService.superApp);\n\tconst fcmServiceInstanceForUser = new FCMService(firebaseService.userApp);\n\tconst fcmServiceInstanceForRider = new FCMService(firebaseService.riderApp);\n\tconst fcmServiceInstanceForShop = new FCMService(firebaseService.shopApp);\n\tconst fcmServiceInstanceForCpanel = new FCMService(firebaseService.cpanelApp);\n\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\n\tContainer.set(FCMServiceForCpanel, fcmServiceInstanceForCpanel);\n\n\tconsole.log('Initialized everything');\n\n\tawait initEventBus(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName, opts } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(\n\t\t\teventId,\n\t\t\tasync payload => {\n\t\t\t\treturn instance[methodName](payload);\n\t\t\t},\n\t\t\topts\n\t\t);\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,sCA0BC;AAED,8CAyGC;AAED,oCAEC;AA5KD,qFAAqF;AACrF,IAAA,0CAAqB,GAAE,CAAC;AACxB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;A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AAK,EAAC,OAAO,EAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\napplySoftDeletePlugin();\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initRabbitMQConnection, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport {\n\tFCMService,\n\tFCMServiceForCpanel,\n\tFCMServiceForRider,\n\tFCMServiceForShop,\n\tFCMServiceForUser,\n} from './libraries/firebase/fcmService';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst firebaseService = getLibraries().getFirebaseService();\n\tconst fcmServiceInstance = new FCMService(firebaseService.superApp);\n\tconst fcmServiceInstanceForUser = new FCMService(firebaseService.userApp);\n\tconst fcmServiceInstanceForRider = new FCMService(firebaseService.riderApp);\n\tconst fcmServiceInstanceForShop = new FCMService(firebaseService.shopApp);\n\tconst fcmServiceInstanceForCpanel = new FCMService(firebaseService.cpanelApp);\n\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\n\tContainer.set(FCMServiceForCpanel, fcmServiceInstanceForCpanel);\n\n\tconsole.log('Initialized everything');\n\n\tawait initRabbitMQConnection(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(eventId, async payload => instance[methodName](payload));\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
@@ -1,2 +1 @@
1
- import { RabbitMQEventOptions } from '../index';
2
- export declare function Subscribe(eventId: string, opts?: RabbitMQEventOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
1
+ export declare function Subscribe(eventId: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Subscribe = Subscribe;
4
4
  const SubscriptionRegistry_1 = require("../registry/SubscriptionRegistry");
5
- function Subscribe(eventId, opts) {
5
+ function Subscribe(eventId) {
6
6
  return function (target, propertyKey, descriptor) {
7
- SubscriptionRegistry_1.SubscriptionRegistry.register(eventId, target.constructor, propertyKey, opts);
7
+ SubscriptionRegistry_1.SubscriptionRegistry.register(eventId, target.constructor, propertyKey);
8
8
  };
9
9
  }
10
10
  //# sourceMappingURL=subscribe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe.js","sourceRoot":"/","sources":["libraries/event/decorators/subscribe.ts"],"names":[],"mappings":";;AAGA,8BAIC;AAPD,2EAAwE;AAGxE,SAAgB,SAAS,CAAC,OAAe,EAAE,IAA2B;IACrE,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAChF,2CAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAC/E,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SubscriptionRegistry } from '../registry/SubscriptionRegistry';\nimport { RabbitMQEventOptions } from '../index';\n\nexport function Subscribe(eventId: string, opts?: RabbitMQEventOptions) {\n\treturn function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n\t\tSubscriptionRegistry.register(eventId, target.constructor, propertyKey, opts);\n\t};\n}\n"]}
1
+ {"version":3,"file":"subscribe.js","sourceRoot":"/","sources":["libraries/event/decorators/subscribe.ts"],"names":[],"mappings":";;AAEA,8BAIC;AAND,2EAAwE;AAExE,SAAgB,SAAS,CAAC,OAAe;IACxC,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAChF,2CAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IACzE,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SubscriptionRegistry } from '../registry/SubscriptionRegistry';\n\nexport function Subscribe(eventId: string) {\n\treturn function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n\t\tSubscriptionRegistry.register(eventId, target.constructor, propertyKey);\n\t};\n}\n"]}
@@ -1,16 +1,11 @@
1
- import amqp from 'amqplib';
2
1
  import { BaseEvent } from './BaseEvent';
3
- export interface RabbitMQEventOptions {
4
- consumeImmediately?: boolean;
5
- }
6
- export declare const EXCHANGE_NAME = "lyxa.events";
7
- export declare const INSTANCE_ROUTE_PREFIX = "instance";
8
- export declare function initEventBus(rabbitUrl: string): Promise<void>;
9
- export declare function getChannel(): {
10
- pubChannel: amqp.ConfirmChannel;
11
- subChannel: amqp.Channel;
12
- };
2
+ export declare function initRabbitMQConnection(rabbitUrl: string): Promise<void>;
3
+ export declare function subscribeToQueue(queueName: string, routingKey: string, onMessage: (payload: unknown) => void | Promise<void>, options?: {
4
+ requeue?: boolean;
5
+ durable?: boolean;
6
+ }): Promise<void>;
7
+ export declare function publish(routingKey: string, payload: object): Promise<void>;
13
8
  export declare function publishEvent<TPayload extends object>(event: BaseEvent<TPayload>): Promise<void>;
14
- export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>, opts?: RabbitMQEventOptions): Promise<void>;
15
- export declare function consumeAllMessages<T>(queueName: string): Promise<T[]>;
16
- export declare function closeEventBus(): Promise<void>;
9
+ export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): Promise<void>;
10
+ export declare function pollEventMessages(eventId: string, onMessage: (payload: any) => Promise<void>, limit?: number): Promise<void>;
11
+ export declare function closeRabbitMQConnection(): Promise<void>;
@@ -3,133 +3,119 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.INSTANCE_ROUTE_PREFIX = exports.EXCHANGE_NAME = void 0;
7
- exports.initEventBus = initEventBus;
8
- exports.getChannel = getChannel;
6
+ exports.initRabbitMQConnection = initRabbitMQConnection;
7
+ exports.subscribeToQueue = subscribeToQueue;
8
+ exports.publish = publish;
9
9
  exports.publishEvent = publishEvent;
10
10
  exports.subscribeToEvent = subscribeToEvent;
11
- exports.consumeAllMessages = consumeAllMessages;
12
- exports.closeEventBus = closeEventBus;
13
- const amqplib_1 = __importDefault(require("amqplib"));
11
+ exports.pollEventMessages = pollEventMessages;
12
+ exports.closeRabbitMQConnection = closeRabbitMQConnection;
14
13
  const instance_utils_1 = require("../../utilities/instance.utils");
15
14
  const index_1 = require("../../index");
16
15
  const enum_1 = require("../../utilities/enum");
16
+ const amqp_connection_manager_1 = __importDefault(require("amqp-connection-manager"));
17
17
  let connection;
18
- let pubChannel;
19
- let subChannel;
20
- exports.EXCHANGE_NAME = 'lyxa.events';
21
- exports.INSTANCE_ROUTE_PREFIX = 'instance';
22
- async function initEventBus(rabbitUrl) {
23
- connection = await amqplib_1.default.connect(rabbitUrl);
24
- pubChannel = await connection.createConfirmChannel();
25
- attachGuards(pubChannel, 'pub');
26
- subChannel = await connection.createChannel();
27
- attachGuards(subChannel, 'sub');
28
- await pubChannel.assertExchange(exports.EXCHANGE_NAME, 'topic', { durable: true });
18
+ let pubChannelWrapper;
19
+ const pollChannels = new Map();
20
+ const EXCHANGE_NAME = 'lyxa.events';
21
+ const AMQP_PUBLISH_OPTIONS = {
22
+ contentType: 'application/json',
23
+ persistent: true,
24
+ };
25
+ async function initRabbitMQConnection(rabbitUrl) {
26
+ connection = amqp_connection_manager_1.default.connect([rabbitUrl]);
27
+ connection.on('connect', () => console.log('RabbitMQ connected'));
28
+ connection.on('disconnect', err => console.error('RabbitMQ disconnected', err));
29
+ pubChannelWrapper = connection.createChannel({
30
+ confirm: true,
31
+ setup: async (ch) => {
32
+ await ch.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });
33
+ },
34
+ });
35
+ await pubChannelWrapper.waitForConnect();
29
36
  console.log(`EventBus initialized with instance ID: ${(0, instance_utils_1.getInstanceId)()}`);
30
37
  }
31
- function getChannel() {
32
- if (!pubChannel)
33
- throw new Error('Channel not initialized. Call initEventBus first.');
34
- if (!subChannel)
35
- throw new Error('Channel not initialized. Call initEventBus first.');
36
- return {
37
- pubChannel,
38
- subChannel,
39
- };
40
- }
41
- async function publishEvent(event) {
42
- console.log('taking event', event);
43
- pubChannel = await connection.createConfirmChannel();
44
- const messageBuffer = Buffer.from(JSON.stringify(event.payload));
45
- pubChannel.publish(exports.EXCHANGE_NAME, event.eventId, messageBuffer, {
46
- contentType: 'application/json',
47
- persistent: true,
38
+ async function createQueueChannel(eventId) {
39
+ const wrapper = connection.createChannel({
40
+ setup: async (ch) => {
41
+ await ch.assertQueue(eventId, { durable: true, exclusive: false, autoDelete: false });
42
+ await ch.bindQueue(eventId, EXCHANGE_NAME, eventId);
43
+ },
48
44
  });
49
- await pubChannel.waitForConfirms();
45
+ await wrapper.waitForConnect();
46
+ return wrapper;
50
47
  }
51
- async function subscribeToEvent(eventId, onMessage, opts) {
52
- const ch = getChannel().subChannel;
53
- const queueName = `${eventId}`;
54
- await ch.assertQueue(queueName, {
55
- durable: true,
56
- exclusive: false,
57
- autoDelete: false,
48
+ async function handleMsg(wrapper, msg, handler, label, requeue = true) {
49
+ try {
50
+ const payload = JSON.parse(msg.content.toString());
51
+ await handler(payload);
52
+ wrapper.ack(msg);
53
+ return true;
54
+ }
55
+ catch (err) {
56
+ (0, index_1.getLibraries)()
57
+ .getLoggerKit()
58
+ .error(`Error handling [${label}]`, err, { tag: enum_1.LogTag.INFRA_QUEUE });
59
+ wrapper.nack(msg, false, requeue);
60
+ return false;
61
+ }
62
+ }
63
+ async function subscribeToQueue(queueName, routingKey, onMessage, options = {}) {
64
+ if (!connection) {
65
+ console.warn(`[RabbitMQ] subscribeToQueue called before connection initialized, skipping [${queueName}]`);
66
+ return;
67
+ }
68
+ const { requeue = true, durable = true } = options;
69
+ const wrapper = connection.createChannel({
70
+ setup: async (ch) => {
71
+ await ch.assertQueue(queueName, { durable });
72
+ await ch.bindQueue(queueName, EXCHANGE_NAME, routingKey);
73
+ },
58
74
  });
59
- await ch.bindQueue(queueName, exports.EXCHANGE_NAME, eventId);
60
- if (opts?.consumeImmediately !== false) {
61
- await ch.consume(queueName, async (msg) => {
62
- if (!msg)
63
- return;
64
- let processed = false;
65
- try {
66
- const payload = JSON.parse(msg.content.toString());
67
- await onMessage(payload);
68
- processed = true;
69
- }
70
- catch (err) {
71
- console.error(`Error handling event [${eventId}]`, err);
72
- }
73
- finally {
74
- if (processed)
75
- ch.ack(msg);
76
- else
77
- ch.nack(msg, false, true);
78
- }
79
- });
75
+ await wrapper.waitForConnect();
76
+ await wrapper.consume(queueName, msg => handleMsg(wrapper, msg, onMessage, queueName, requeue));
77
+ console.log(`Subscribed to queue [${queueName}]`);
78
+ }
79
+ async function publish(routingKey, payload) {
80
+ await pubChannelWrapper.publish(EXCHANGE_NAME, routingKey, Buffer.from(JSON.stringify(payload)), AMQP_PUBLISH_OPTIONS);
81
+ }
82
+ async function publishEvent(event) {
83
+ await publish(event.eventId, event.payload);
84
+ }
85
+ async function subscribeToEvent(eventId, onMessage) {
86
+ if (!connection) {
87
+ console.warn(`[RabbitMQ] subscribe called before connection initialized, skipping [${eventId}]`);
88
+ return;
80
89
  }
90
+ const wrapper = await createQueueChannel(eventId);
91
+ await wrapper.consume(eventId, msg => handleMsg(wrapper, msg, onMessage, eventId));
81
92
  console.log(`Subscribed to event [${eventId}]`);
82
93
  }
83
- async function consumeAllMessages(queueName) {
84
- const logger = (0, index_1.getLibraries)().getLoggerKit();
85
- const ch = getChannel().subChannel;
86
- const messages = [];
87
- while (true) {
88
- const msg = await ch.get(queueName, { noAck: false });
94
+ async function pollEventMessages(eventId, onMessage, limit) {
95
+ if (!connection) {
96
+ console.warn(`[RabbitMQ] poll called before connection initialized, skipping [${eventId}]`);
97
+ return;
98
+ }
99
+ if (!pollChannels.has(eventId)) {
100
+ pollChannels.set(eventId, await createQueueChannel(eventId));
101
+ }
102
+ const wrapper = pollChannels.get(eventId);
103
+ const max = limit ?? Infinity;
104
+ let count = 0;
105
+ while (count < max) {
106
+ const msg = await wrapper.get(eventId, { noAck: false });
89
107
  if (!msg)
90
108
  break;
91
- try {
92
- const payload = JSON.parse(msg.content.toString());
93
- messages.push(payload);
94
- ch.ack(msg);
95
- logger.debug(`Message consumed successfully for event ${queueName}`, {
96
- tag: enum_1.LogTag.INFRA_QUEUE,
97
- });
98
- }
99
- catch (err) {
100
- logger.error(`Error processing message for event ${queueName}:`, err, {
101
- tag: enum_1.LogTag.INFRA_QUEUE,
102
- });
103
- ch.nack(msg, false, true);
104
- }
109
+ if (await handleMsg(wrapper, msg, onMessage, eventId))
110
+ count++;
105
111
  }
106
- logger.debug(`Fetched ${messages.length} messages for event ${queueName}`, { tag: enum_1.LogTag.INFRA_QUEUE });
107
- return messages;
108
112
  }
109
- async function closeEventBus() {
110
- if (pubChannel)
111
- await pubChannel.close();
112
- if (subChannel)
113
- await subChannel.close();
113
+ async function closeRabbitMQConnection() {
114
+ if (pubChannelWrapper)
115
+ await pubChannelWrapper.close();
116
+ await Promise.all([...pollChannels.values()].map(ch => ch.close()));
114
117
  if (connection)
115
118
  await connection.close();
116
119
  console.log(`EventBus closed for instance [${(0, instance_utils_1.getInstanceId)()}]`);
117
120
  }
118
- function attachGuards(ch, type) {
119
- ch.on('close', async () => {
120
- console.error(`${type} channel closed, recreating...`);
121
- if (type === 'pub') {
122
- pubChannel = await connection.createConfirmChannel();
123
- await pubChannel.assertExchange(exports.EXCHANGE_NAME, 'topic', { durable: true });
124
- attachGuards(pubChannel, 'pub');
125
- }
126
- else {
127
- subChannel = await connection.createChannel();
128
- attachGuards(subChannel, 'sub');
129
- }
130
- });
131
- ch.on('error', err => {
132
- console.error(`${type} channel error`, err);
133
- });
134
- }
135
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AAiBA,oCAUC;AAED,gCAOC;AAED,oCAUC;AAED,4CAyCC;AAED,gDAyBC;AAED,sCAKC;AA7HD,sDAA2B;AAE3B,mEAA+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,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,aAAa;IAClC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAA,8BAAa,GAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,YAAY,CAAC,EAAsC,EAAE,IAAmB;IAChF,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,gCAAgC,CAAC,CAAC;QACvD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACpB,UAAU,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;YACrD,MAAM,UAAU,CAAC,cAAc,CAAC,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3E,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;YAC9C,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,gBAAgB,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nlet connection: amqp.ChannelModel;\nlet pubChannel: amqp.ConfirmChannel;\nlet subChannel: amqp.Channel;\n\nexport interface RabbitMQEventOptions {\n\tconsumeImmediately?: boolean;\n}\n\nexport const EXCHANGE_NAME = 'lyxa.events';\nexport const INSTANCE_ROUTE_PREFIX = 'instance'; // routing key: instance.{instanceName}.{eventType}\n\nexport async function initEventBus(rabbitUrl: string) {\n\tconnection = await amqp.connect(rabbitUrl);\n\tpubChannel = await connection.createConfirmChannel();\n\tattachGuards(pubChannel, 'pub');\n\n\tsubChannel = await connection.createChannel();\n\tattachGuards(subChannel, 'sub');\n\n\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport function getChannel(): { pubChannel: amqp.ConfirmChannel; subChannel: amqp.Channel } {\n\tif (!pubChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tif (!subChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\treturn {\n\t\tpubChannel,\n\t\tsubChannel,\n\t};\n}\n\nexport async function publishEvent<TPayload extends object>(event: BaseEvent<TPayload>): Promise<void> {\n\tconsole.log('taking event', event);\n\tpubChannel = await connection.createConfirmChannel();\n\t// const ch = getChannel().pubChannel;\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tpubChannel.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t});\n\tawait pubChannel.waitForConfirms();\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>,\n\topts?: RabbitMQEventOptions\n): Promise<void> {\n\tconst ch = getChannel().subChannel;\n\tconst queueName = `${eventId}`;\n\t// const queueName = `${eventId}.${getInstanceId()}`;\n\n\tawait ch.assertQueue(queueName, {\n\t\tdurable: true, // survive broker restart\n\t\texclusive: false, // Allow multiple consumers to attach. Only one connection can use it (each pod has own queue). Set to TRUE if each pod needs it's own queue\n\t\tautoDelete: false, // Queue removed when pod disconnects when set to TRUE\n\t\t// arguments: {\n\t\t// \t// Optional safety: limit queue size and TTL to prevent disk issues\n\t\t// \t'x-max-length': 50000, // max 50k messages\n\t\t// \t'x-message-ttl': 24 * 60 * 60 * 1000, // 24h TTL\n\t\t// \t'x-overflow': 'drop-head', // drop oldest messages if full\n\t\t// },\n\t});\n\n\tawait ch.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\tif (opts?.consumeImmediately !== false) {\n\t\tawait ch.consume(queueName, async msg => {\n\t\t\tif (!msg) return;\n\t\t\tlet processed = false;\n\t\t\ttry {\n\t\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\t\tawait onMessage(payload);\n\t\t\t\tprocessed = true;\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Error handling event [${eventId}]`, err);\n\t\t\t} finally {\n\t\t\t\tif (processed) ch.ack(msg);\n\t\t\t\telse ch.nack(msg, false, true); // retry\n\t\t\t}\n\t\t});\n\t}\n\n\t// console.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);\n\tconsole.log(`Subscribed to event [${eventId}]`);\n}\n\nexport async function consumeAllMessages<T>(queueName: string): Promise<T[]> {\n\tconst logger = getLibraries().getLoggerKit();\n\tconst ch = getChannel().subChannel;\n\tconst messages: T[] = [];\n\n\twhile (true) {\n\t\tconst msg = await ch.get(queueName, { noAck: false });\n\t\tif (!msg) break;\n\n\t\ttry {\n\t\t\tconst payload = JSON.parse(msg.content.toString()) as T;\n\t\t\tmessages.push(payload);\n\t\t\tch.ack(msg);\n\t\t\tlogger.debug(`Message consumed successfully for event ${queueName}`, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tlogger.error(`Error processing message for event ${queueName}:`, err, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t\tch.nack(msg, false, true);\n\t\t}\n\t}\n\tlogger.debug(`Fetched ${messages.length} messages for event ${queueName}`, { tag: LogTag.INFRA_QUEUE });\n\treturn messages;\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (pubChannel) await pubChannel.close();\n\tif (subChannel) await subChannel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}\n\nfunction attachGuards(ch: amqp.Channel | amqp.ConfirmChannel, type: 'pub' | 'sub') {\n\tch.on('close', async () => {\n\t\tconsole.error(`${type} channel closed, recreating...`);\n\t\tif (type === 'pub') {\n\t\t\tpubChannel = await connection.createConfirmChannel();\n\t\t\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\t\t\tattachGuards(pubChannel, 'pub');\n\t\t} else {\n\t\t\tsubChannel = await connection.createChannel();\n\t\t\tattachGuards(subChannel, 'sub');\n\t\t}\n\t});\n\n\tch.on('error', err => {\n\t\tconsole.error(`${type} channel error`, err);\n\t});\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;AAqBA,wDAcC;AAkCD,4CAuBC;AAED,0BAOC;AAED,oCAEC;AAED,4CAYC;AAED,8CAuBC;AAED,0DAKC;AArJD,mEAA+D;AAC/D,uCAA2C;AAC3C,+CAA8C;AAE9C,sFAA+E;AAG/E,IAAI,UAAkC,CAAC;AACvC,IAAI,iBAAiC,CAAC;AACtC,MAAM,YAAY,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEvD,MAAM,aAAa,GAAG,aAAa,CAAC;AAGpC,MAAM,oBAAoB,GAAG;IAC5B,WAAW,EAAE,kBAAkB;IAC/B,UAAU,EAAE,IAAI;CACqC,CAAC;AAEhD,KAAK,UAAU,sBAAsB,CAAC,SAAiB;IAC7D,UAAU,GAAG,iCAAW,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9C,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClE,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AAK,IAAI,QAAQ,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,KAAK,GAAG,GAAG,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG;YAAE,MAAM;QAChB,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;YAAE,KAAK,EAAE,CAAC;IAChE,CAAC;AACF,CAAC;AAEM,KAAK,UAAU,uBAAuB;IAC5C,IAAI,iBAAiB;QAAE,MAAM,iBAAiB,CAAC,KAAK,EAAE,CAAC;IACvD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACpE,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAA,8BAAa,GAAE,GAAG,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nimport amqpManager, { Channel, ChannelWrapper } from 'amqp-connection-manager';\nimport { IAmqpConnectionManager } from 'amqp-connection-manager/dist/types/AmqpConnectionManager';\n\nlet connection: IAmqpConnectionManager;\nlet pubChannelWrapper: ChannelWrapper;\nconst pollChannels = new Map<string, ChannelWrapper>();\n\nconst EXCHANGE_NAME = 'lyxa.events';\n\ntype PublishOptions = Parameters<ChannelWrapper['publish']>[3];\nconst AMQP_PUBLISH_OPTIONS = {\n\tcontentType: 'application/json',\n\tpersistent: true,\n} as amqp.Options.Publish as unknown as PublishOptions;\n\nexport async function initRabbitMQConnection(rabbitUrl: string): Promise<void> {\n\tconnection = amqpManager.connect([rabbitUrl]);\n\tconnection.on('connect', () => console.log('RabbitMQ connected'));\n\tconnection.on('disconnect', err => console.error('RabbitMQ disconnected', err));\n\n\tpubChannelWrapper = connection.createChannel({\n\t\tconfirm: true,\n\t\tsetup: async (ch: Channel) => {\n\t\t\tawait ch.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\t\t},\n\t});\n\n\tawait pubChannelWrapper.waitForConnect();\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nasync function createQueueChannel(eventId: string): Promise<ChannelWrapper> {\n\tconst wrapper = connection.createChannel({\n\t\tsetup: async (ch: Channel) => {\n\t\t\tawait ch.assertQueue(eventId, { durable: true, exclusive: false, autoDelete: false });\n\t\t\tawait ch.bindQueue(eventId, EXCHANGE_NAME, eventId);\n\t\t},\n\t});\n\tawait wrapper.waitForConnect();\n\treturn wrapper;\n}\n\nasync function handleMsg(\n\twrapper: ChannelWrapper,\n\tmsg: amqp.Message,\n\thandler: (payload: any) => void | Promise<void>,\n\tlabel: string,\n\trequeue = true\n): Promise<boolean> {\n\ttry {\n\t\tconst payload = JSON.parse(msg.content.toString());\n\t\tawait handler(payload);\n\t\twrapper.ack(msg);\n\t\treturn true;\n\t} catch (err) {\n\t\tgetLibraries()\n\t\t\t.getLoggerKit()\n\t\t\t.error(`Error handling [${label}]`, err, { tag: LogTag.INFRA_QUEUE });\n\t\twrapper.nack(msg, false, requeue);\n\t\treturn false;\n\t}\n}\n\nexport async function subscribeToQueue(\n\tqueueName: string,\n\troutingKey: string,\n\tonMessage: (payload: unknown) => void | Promise<void>,\n\toptions: { requeue?: boolean; durable?: boolean } = {}\n): Promise<void> {\n\tif (!connection) {\n\t\tconsole.warn(`[RabbitMQ] subscribeToQueue called before connection initialized, skipping [${queueName}]`);\n\t\treturn;\n\t}\n\n\tconst { requeue = true, durable = true } = options;\n\n\tconst wrapper = connection.createChannel({\n\t\tsetup: async (ch: Channel) => {\n\t\t\tawait ch.assertQueue(queueName, { durable });\n\t\t\tawait ch.bindQueue(queueName, EXCHANGE_NAME, routingKey);\n\t\t},\n\t});\n\tawait wrapper.waitForConnect();\n\n\tawait wrapper.consume(queueName, msg => handleMsg(wrapper, msg, onMessage, queueName, requeue));\n\tconsole.log(`Subscribed to queue [${queueName}]`);\n}\n\nexport async function publish(routingKey: string, payload: object): Promise<void> {\n\tawait pubChannelWrapper.publish(\n\t\tEXCHANGE_NAME,\n\t\troutingKey,\n\t\tBuffer.from(JSON.stringify(payload)),\n\t\tAMQP_PUBLISH_OPTIONS\n\t);\n}\n\nexport async function publishEvent<TPayload extends object>(event: BaseEvent<TPayload>): Promise<void> {\n\tawait publish(event.eventId, event.payload);\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>\n): Promise<void> {\n\tif (!connection) {\n\t\tconsole.warn(`[RabbitMQ] subscribe called before connection initialized, skipping [${eventId}]`);\n\t\treturn;\n\t}\n\n\tconst wrapper = await createQueueChannel(eventId);\n\tawait wrapper.consume(eventId, msg => handleMsg(wrapper, msg, onMessage, eventId));\n\tconsole.log(`Subscribed to event [${eventId}]`);\n}\n\nexport async function pollEventMessages(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>,\n\tlimit?: number\n): Promise<void> {\n\tif (!connection) {\n\t\tconsole.warn(`[RabbitMQ] poll called before connection initialized, skipping [${eventId}]`);\n\t\treturn;\n\t}\n\n\tif (!pollChannels.has(eventId)) {\n\t\tpollChannels.set(eventId, await createQueueChannel(eventId));\n\t}\n\n\tconst wrapper = pollChannels.get(eventId)!;\n\tconst max = limit ?? Infinity;\n\tlet count = 0;\n\n\twhile (count < max) {\n\t\tconst msg = await wrapper.get(eventId, { noAck: false });\n\t\tif (!msg) break;\n\t\tif (await handleMsg(wrapper, msg, onMessage, eventId)) count++;\n\t}\n}\n\nexport async function closeRabbitMQConnection(): Promise<void> {\n\tif (pubChannelWrapper) await pubChannelWrapper.close();\n\tawait Promise.all([...pollChannels.values()].map(ch => ch.close()));\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}"]}
@@ -1,13 +1,11 @@
1
- import { RabbitMQEventOptions } from '../index';
2
1
  interface SubscriptionMetadata {
3
2
  eventId: string;
4
3
  targetConstructor: Function;
5
4
  methodName: string;
6
- opts?: RabbitMQEventOptions;
7
5
  }
8
6
  export declare class SubscriptionRegistry {
9
7
  private static subscriptions;
10
- static register(eventId: string, targetConstructor: Function, methodName: string, opts?: RabbitMQEventOptions): void;
8
+ static register(eventId: string, targetConstructor: Function, methodName: string): void;
11
9
  static getAllSubscriptions(): SubscriptionMetadata[];
12
10
  }
13
11
  export {};
@@ -3,13 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubscriptionRegistry = void 0;
4
4
  class SubscriptionRegistry {
5
5
  static subscriptions = [];
6
- static register(eventId, targetConstructor, methodName, opts) {
7
- this.subscriptions.push({
8
- eventId,
9
- targetConstructor,
10
- methodName,
11
- opts: opts,
12
- });
6
+ static register(eventId, targetConstructor, methodName) {
7
+ this.subscriptions.push({ eventId, targetConstructor, methodName });
13
8
  }
14
9
  static getAllSubscriptions() {
15
10
  return [...this.subscriptions];
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionRegistry.js","sourceRoot":"/","sources":["libraries/event/registry/SubscriptionRegistry.ts"],"names":[],"mappings":";;;AASA,MAAa,oBAAoB;IACxB,MAAM,CAAC,aAAa,GAA2B,EAAE,CAAC;IAMnD,MAAM,CAAC,QAAQ,CACrB,OAAe,EACf,iBAA2B,EAC3B,UAAkB,EAClB,IAA2B;QAE3B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACvB,OAAO;YACP,iBAAiB;YACjB,UAAU;YACV,IAAI,EAAE,IAAI;SACV,CAAC,CAAC;IACJ,CAAC;IAMM,MAAM,CAAC,mBAAmB;QAChC,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;;AA3BF,oDA4BC","sourcesContent":["import { RabbitMQEventOptions } from '../index';\n\ninterface SubscriptionMetadata {\n\teventId: string;\n\ttargetConstructor: Function;\n\tmethodName: string;\n\topts?: RabbitMQEventOptions;\n}\n\nexport class SubscriptionRegistry {\n\tprivate static subscriptions: SubscriptionMetadata[] = [];\n\n\t/**\n\t * Called by the decorator to record which class method\n\t * is subscribed to which eventId.\n\t */\n\tpublic static register(\n\t\teventId: string,\n\t\ttargetConstructor: Function,\n\t\tmethodName: string,\n\t\topts?: RabbitMQEventOptions\n\t) {\n\t\tthis.subscriptions.push({\n\t\t\teventId,\n\t\t\ttargetConstructor,\n\t\t\tmethodName,\n\t\t\topts: opts,\n\t\t});\n\t}\n\n\t/**\n\t * Called at bootstrap to retrieve all known subscriptions\n\t * so we can actually wire them up.\n\t */\n\tpublic static getAllSubscriptions(): SubscriptionMetadata[] {\n\t\treturn [...this.subscriptions];\n\t}\n}\n"]}
1
+ {"version":3,"file":"SubscriptionRegistry.js","sourceRoot":"/","sources":["libraries/event/registry/SubscriptionRegistry.ts"],"names":[],"mappings":";;;AAMA,MAAa,oBAAoB;IACxB,MAAM,CAAC,aAAa,GAA2B,EAAE,CAAC;IAEnD,MAAM,CAAC,QAAQ,CAAC,OAAe,EAAE,iBAA2B,EAAE,UAAkB;QACtF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAChC,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;;AATF,oDAUC","sourcesContent":["interface SubscriptionMetadata {\n\teventId: string;\n\ttargetConstructor: Function;\n\tmethodName: string;\n}\n\nexport class SubscriptionRegistry {\n\tprivate static subscriptions: SubscriptionMetadata[] = [];\n\n\tpublic static register(eventId: string, targetConstructor: Function, methodName: string) {\n\t\tthis.subscriptions.push({ eventId, targetConstructor, methodName });\n\t}\n\n\tpublic static getAllSubscriptions(): SubscriptionMetadata[] {\n\t\treturn [...this.subscriptions];\n\t}\n}\n"]}
@@ -5,26 +5,10 @@ const instance_utils_1 = require("../../../utilities/instance.utils");
5
5
  const event_1 = require("../../event");
6
6
  const local_subscription_registry_1 = require("./local-subscription-registry");
7
7
  async function subscribeToSocketEvent() {
8
- const channel = (0, event_1.getChannel)().subChannel;
9
- const queueName = `socket-events-${(0, instance_utils_1.getInstanceId)()}`;
10
- await channel.assertQueue(queueName, { durable: true });
11
- await channel.bindQueue(queueName, event_1.EXCHANGE_NAME, `instance.${(0, instance_utils_1.getInstanceId)()}`);
12
- await channel.consume(queueName, msg => {
13
- if (!msg)
14
- return;
15
- try {
16
- const { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));
17
- local_subscription_registry_1.LocalSubs.emit(recipient, localKey, payload);
18
- channel.ack(msg);
19
- }
20
- catch (e) {
21
- console.error('[Socket] Failed to handle socket event:', {
22
- error: e instanceof Error ? e.message : e,
23
- queue: queueName,
24
- });
25
- channel.nack(msg, false, false);
26
- }
27
- });
28
- console.log(`Subscribed to socket events on queue [${queueName}]`);
8
+ const instanceId = (0, instance_utils_1.getInstanceId)();
9
+ await (0, event_1.subscribeToQueue)(`socket-events-${instanceId}`, `instance.${instanceId}`, (msg) => {
10
+ const { localKey, payload, recipient } = msg;
11
+ local_subscription_registry_1.LocalSubs.emit(recipient, localKey, payload);
12
+ }, { requeue: false });
29
13
  }
30
14
  //# sourceMappingURL=socket-event-consumer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-event-consumer.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-consumer.ts"],"names":[],"mappings":";;AAIA,wDAuBC;AA3BD,sEAAkE;AAClE,uCAAwD;AACxD,+EAA0D;AAEnD,KAAK,UAAU,sBAAsB;IAC3C,MAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC,UAAU,CAAC;IACxC,MAAM,SAAS,GAAG,iBAAiB,IAAA,8BAAa,GAAE,EAAE,CAAC;IAErD,MAAM,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,qBAAa,EAAE,YAAY,IAAA,8BAAa,GAAE,EAAE,CAAC,CAAC;IAEjF,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE;QACtC,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,IAAI,CAAC;YACJ,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YAClF,uCAAS,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE;gBACxD,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzC,KAAK,EAAE,SAAS;aAChB,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,yCAAyC,SAAS,GAAG,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { getInstanceId } from '../../../utilities/instance.utils';\nimport { EXCHANGE_NAME, getChannel } from '../../event';\nimport { LocalSubs } from './local-subscription-registry';\n\nexport async function subscribeToSocketEvent() {\n\tconst channel = getChannel().subChannel;\n\tconst queueName = `socket-events-${getInstanceId()}`;\n\n\tawait channel.assertQueue(queueName, { durable: true });\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, `instance.${getInstanceId()}`);\n\n\tawait channel.consume(queueName, msg => {\n\t\tif (!msg) return;\n\t\ttry {\n\t\t\tconst { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));\n\t\t\tLocalSubs.emit(recipient, localKey, payload);\n\t\t\tchannel.ack(msg);\n\t\t} catch (e) {\n\t\t\tconsole.error('[Socket] Failed to handle socket event:', {\n\t\t\t\terror: e instanceof Error ? e.message : e,\n\t\t\t\tqueue: queueName,\n\t\t\t});\n\t\t\tchannel.nack(msg, false, false); // Don't requeue malformed messages\n\t\t}\n\t});\n\n\tconsole.log(`Subscribed to socket events on queue [${queueName}]`);\n}\n"]}
1
+ {"version":3,"file":"socket-event-consumer.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-consumer.ts"],"names":[],"mappings":";;AAIA,wDAWC;AAfD,sEAAkE;AAClE,uCAA+C;AAC/C,+EAA0D;AAEnD,KAAK,UAAU,sBAAsB;IAC3C,MAAM,UAAU,GAAG,IAAA,8BAAa,GAAE,CAAC;IACnC,MAAM,IAAA,wBAAgB,EACrB,iBAAiB,UAAU,EAAE,EAC7B,YAAY,UAAU,EAAE,EACxB,CAAC,GAAY,EAAE,EAAE;QAChB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAA6D,CAAC;QACvG,uCAAS,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC,EACD,EAAE,OAAO,EAAE,KAAK,EAAE,CAClB,CAAC;AACH,CAAC","sourcesContent":["import { getInstanceId } from '../../../utilities/instance.utils';\nimport { subscribeToQueue } from '../../event';\nimport { LocalSubs } from './local-subscription-registry';\n\nexport async function subscribeToSocketEvent(): Promise<void> {\n\tconst instanceId = getInstanceId();\n\tawait subscribeToQueue(\n\t\t`socket-events-${instanceId}`,\n\t\t`instance.${instanceId}`,\n\t\t(msg: unknown) => {\n\t\t\tconst { localKey, payload, recipient } = msg as { localKey: string; payload: unknown; recipient: any };\n\t\t\tLocalSubs.emit(recipient, localKey, payload);\n\t\t},\n\t\t{ requeue: false }\n\t);\n}\n"]}
@@ -6,56 +6,35 @@ const __1 = require("../../..");
6
6
  const event_1 = require("../../event");
7
7
  const PushNotificationEvent_1 = require("../PushNotificationEvent");
8
8
  const connections_1 = require("../connections");
9
- const PUBLISH_OPTIONS = {
10
- contentType: 'application/json',
11
- persistent: true,
12
- };
13
- function publishToInstances(recipientsWithInstances, localKey, payload) {
9
+ function fanOutToInstances(recipientsWithInstances, localKey, payload) {
14
10
  if (recipientsWithInstances.length === 0)
15
11
  return;
16
- const channel = (0, event_1.getChannel)().pubChannel;
17
- const message = { localKey, payload, recipient: null };
18
- for (let i = 0; i < recipientsWithInstances.length; i++) {
19
- const { recipient, instances } = recipientsWithInstances[i];
20
- message.recipient = recipient;
21
- const messageStr = JSON.stringify(message);
22
- for (let j = 0; j < instances.length; j++) {
23
- const routingKey = `${event_1.INSTANCE_ROUTE_PREFIX}.${instances[j]}`;
24
- try {
25
- channel.publish(event_1.EXCHANGE_NAME, routingKey, Buffer.from(messageStr, 'utf8'), PUBLISH_OPTIONS);
26
- }
27
- catch (error) {
28
- console.error(`[Socket] Publish failed: ${routingKey}`, error);
29
- }
12
+ for (const { recipient, instances } of recipientsWithInstances) {
13
+ const message = { localKey, payload, recipient };
14
+ for (const instanceId of instances) {
15
+ (0, event_1.publish)(`instance.${instanceId}`, message).catch((error) => {
16
+ console.error(`[Socket] Publish failed for instance ${instanceId}`, error);
17
+ });
30
18
  }
31
19
  }
32
20
  }
33
21
  async function getActiveSubscribedRecipients(recipients, localKey) {
34
- if (recipients.length === 0) {
22
+ if (recipients.length === 0)
35
23
  return { subscribed: [], unsubscribed: [] };
36
- }
37
24
  const redis = (0, __1.getLibraries)().getRedisService();
38
25
  const subscribed = [];
39
26
  const unsubscribed = [];
40
27
  await Promise.all(recipients.map(async (recipient) => {
41
28
  const sockets = await redis.getSetMembers((0, connections_1.kEntityEventSockets)(recipient, localKey));
42
- if (sockets.length > 0) {
43
- const instanceSet = new Set();
44
- for (let i = 0; i < sockets.length; i++) {
45
- const [instanceId] = sockets[i].split('|');
46
- if (instanceId)
47
- instanceSet.add(instanceId);
48
- }
49
- if (instanceSet.size > 0) {
50
- subscribed.push({ recipient, instances: Array.from(instanceSet) });
51
- }
52
- else {
53
- unsubscribed.push(recipient);
54
- }
55
- }
56
- else {
29
+ if (sockets.length === 0) {
57
30
  unsubscribed.push(recipient);
31
+ return;
58
32
  }
33
+ const instances = [...new Set(sockets.map(s => s.split('|')[0]).filter(Boolean))];
34
+ if (instances.length > 0)
35
+ subscribed.push({ recipient, instances });
36
+ else
37
+ unsubscribed.push(recipient);
59
38
  }));
60
39
  return { subscribed, unsubscribed };
61
40
  }
@@ -69,17 +48,16 @@ async function publishSocketEvent(event, recipients) {
69
48
  logger.debug({ subscribed }, '[Socket] Subscribed recipients:');
70
49
  logger.debug({ unsubscribed }, '[Socket] Unsubscribed recipients:');
71
50
  if (subscribed.length > 0)
72
- publishToInstances(subscribed, localKey, payload);
51
+ fanOutToInstances(subscribed, localKey, payload);
73
52
  if (unsubscribed.length > 0) {
74
53
  logger.debug({ unsubscribed }, '[Socket] Processing unsubscribed recipients');
75
54
  if (event.notificationSettings?.isPushNotification) {
76
55
  const pushNotificationPayload = event.getPushNotificationPayload();
77
- const settings = event.notificationSettings;
78
- await (0, event_1.publishEvent)(new PushNotificationEvent_1.PushNotificationEvent(event.eventType(), pushNotificationPayload, unsubscribed, settings)).catch(err => console.error('[Socket] Push notification failed:', err));
56
+ await (0, event_1.publishEvent)(new PushNotificationEvent_1.PushNotificationEvent(event.eventType(), pushNotificationPayload, unsubscribed, event.notificationSettings)).catch(err => console.error('[Socket] Push notification failed:', err));
79
57
  }
80
58
  const socketNotificationPayload = event.getSocketNotificationEvent();
81
59
  logger.debug({ socketNotificationPayload }, '[Socket] Socket notification payload');
82
- if (event.getSocketNotificationEvent()) {
60
+ if (socketNotificationPayload) {
83
61
  await publishNotificationSocketEvent(socketNotificationPayload, unsubscribed);
84
62
  }
85
63
  }
@@ -92,20 +70,13 @@ async function publishNotificationSocketEvent(event, recipients) {
92
70
  const validInstances = [];
93
71
  await Promise.all(recipients.map(async (recipient) => {
94
72
  const sockets = await redis.getSetMembers((0, connections_1.kEntityEventSockets)(recipient, eventKey));
95
- if (sockets.length > 0) {
96
- const instanceSet = new Set();
97
- for (let i = 0; i < sockets.length; i++) {
98
- const [instanceId] = sockets[i].split('|');
99
- if (instanceId)
100
- instanceSet.add(instanceId);
101
- }
102
- if (instanceSet.size > 0) {
103
- validInstances.push({ recipient, instances: Array.from(instanceSet) });
104
- }
105
- }
73
+ if (sockets.length === 0)
74
+ return;
75
+ const instances = [...new Set(sockets.map(s => s.split('|')[0]).filter(Boolean))];
76
+ if (instances.length > 0)
77
+ validInstances.push({ recipient, instances });
106
78
  }));
107
- if (validInstances.length > 0) {
108
- publishToInstances(validInstances, eventKey, event.payload());
109
- }
79
+ if (validInstances.length > 0)
80
+ fanOutToInstances(validInstances, eventKey, event.payload());
110
81
  }
111
82
  //# sourceMappingURL=socket-event-publisher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-event-publisher.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-publisher.ts"],"names":[],"mappings":";;AAuFA,gDAmCC;AAED,wEA8BC;AA1JD,gCAAwC;AAGxC,uCAA6F;AAC7F,oEAAiE;AAEjE,gDAAyE;AAGzE,MAAM,eAAe,GAAG;IACvB,WAAW,EAAE,kBAAkB;IAC/B,UAAU,EAAE,IAAI;CACP,CAAC;AAGX,SAAS,kBAAkB,CAC1B,uBAAsF,EACtF,QAAgB,EAChB,OAAgB;IAEhB,IAAI,uBAAuB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAEjD,MAAM,OAAO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,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;AACF,CAAC","sourcesContent":["import { getLibraries } from '../../..';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { SocketNotificationEvent } from '../events';\nimport { EXCHANGE_NAME, getChannel, INSTANCE_ROUTE_PREFIX, publishEvent } from '../../event';\nimport { PushNotificationEvent } from '../PushNotificationEvent';\nimport type { ZodTypeAny } from 'zod';\nimport { EntitySubscription, kEntityEventSockets } from '../connections';\n\n// Reusable publish options\nconst PUBLISH_OPTIONS = {\n\tcontentType: 'application/json',\n\tpersistent: true,\n} as const;\n\n// Zero-overhead publishing - minimal allocations\nfunction publishToInstances(\n\trecipientsWithInstances: Array<{ recipient: EntitySubscription; instances: string[] }>,\n\tlocalKey: string,\n\tpayload: unknown\n): void {\n\tif (recipientsWithInstances.length === 0) return;\n\n\tconst channel = getChannel().pubChannel;\n\n\t// Pre-serialize message once\n\tconst message = { localKey, payload, recipient: null as any };\n\n\t// Fire-and-forget with minimal overhead\n\tfor (let i = 0; i < recipientsWithInstances.length; i++) {\n\t\tconst { recipient, instances } = recipientsWithInstances[i];\n\t\tmessage.recipient = recipient;\n\t\tconst messageStr = JSON.stringify(message);\n\n\t\tfor (let j = 0; j < instances.length; j++) {\n\t\t\tconst routingKey = `${INSTANCE_ROUTE_PREFIX}.${instances[j]}`;\n\n\t\t\ttry {\n\t\t\t\t// Direct publish - Buffer.from creates minimal overhead\n\t\t\t\tchannel.publish(EXCHANGE_NAME, routingKey, Buffer.from(messageStr, 'utf8'), PUBLISH_OPTIONS);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`[Socket] Publish failed: ${routingKey}`, error);\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Ultra-simple: Direct Redis lookups, no batch/cache/parsing!\nasync function getActiveSubscribedRecipients(\n\trecipients: EntitySubscription[],\n\tlocalKey: string\n): Promise<{\n\tsubscribed: Array<{ recipient: EntitySubscription; instances: string[] }>;\n\tunsubscribed: EntitySubscription[];\n}> {\n\tif (recipients.length === 0) {\n\t\treturn { subscribed: [], unsubscribed: [] };\n\t}\n\n\tconst redis = getLibraries().getRedisService();\n\tconst subscribed: Array<{ recipient: EntitySubscription; instances: string[] }> = [];\n\tconst unsubscribed: EntitySubscription[] = [];\n\n\t// Parallel lookups - one key per recipient\n\tawait Promise.all(\n\t\trecipients.map(async recipient => {\n\t\t\tconst sockets = await redis.getSetMembers(kEntityEventSockets(recipient, localKey));\n\t\t\tif (sockets.length > 0) {\n\t\t\t\tconst instanceSet = new Set<string>();\n\t\t\t\tfor (let i = 0; i < sockets.length; i++) {\n\t\t\t\t\tconst [instanceId] = sockets[i].split('|');\n\t\t\t\t\tif (instanceId) instanceSet.add(instanceId);\n\t\t\t\t}\n\t\t\t\tif (instanceSet.size > 0) {\n\t\t\t\t\tsubscribed.push({ recipient, instances: Array.from(instanceSet) });\n\t\t\t\t} else {\n\t\t\t\t\tunsubscribed.push(recipient);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tunsubscribed.push(recipient);\n\t\t\t}\n\t\t})\n\t);\n\n\treturn { subscribed, unsubscribed };\n}\n\n// Minimal overhead publish - early returns, lazy evaluation\nexport async function publishSocketEvent(\n\tevent: BaseSocketEvent<ZodTypeAny, ZodTypeAny, ZodTypeAny | undefined>,\n\trecipients: EntitySubscription[]\n): Promise<void> {\n\tconst logger = getLibraries().getLogger().logger;\n\tif (recipients.length === 0) return;\n\n\tconst localKey = event.getSubscriptionKey();\n\tconst payload = event.payload();\n\n\tconst { subscribed, unsubscribed } = await getActiveSubscribedRecipients(recipients, localKey);\n\n\tlogger.debug({ subscribed }, '[Socket] Subscribed recipients:');\n\tlogger.debug({ unsubscribed }, '[Socket] Unsubscribed recipients:');\n\n\tif (subscribed.length > 0) publishToInstances(subscribed, localKey, payload);\n\n\tif (unsubscribed.length > 0) {\n\t\tlogger.debug({ unsubscribed }, '[Socket] Processing unsubscribed recipients');\n\t\tif (event.notificationSettings?.isPushNotification) {\n\t\t\tconst pushNotificationPayload = event.getPushNotificationPayload();\n\t\t\tconst settings = event.notificationSettings;\n\t\t\tawait publishEvent(\n\t\t\t\tnew PushNotificationEvent(event.eventType(), pushNotificationPayload, unsubscribed, settings)\n\t\t\t).catch(err => console.error('[Socket] Push notification failed:', err));\n\t\t}\n\n\t\tconst socketNotificationPayload = event.getSocketNotificationEvent();\n\n\t\tlogger.debug({ socketNotificationPayload }, '[Socket] Socket notification payload');\n\n\t\tif (event.getSocketNotificationEvent()) {\n\t\t\tawait publishNotificationSocketEvent(socketNotificationPayload!, unsubscribed);\n\t\t}\n\t}\n}\n\nexport async function publishNotificationSocketEvent(\n\tevent: SocketNotificationEvent,\n\trecipients: EntitySubscription[]\n): Promise<void> {\n\tif (recipients.length === 0) return;\n\n\tconst eventKey = event.getSubscriptionKey();\n\tconst redis = getLibraries().getRedisService();\n\tconst validInstances: Array<{ recipient: EntitySubscription; instances: string[] }> = [];\n\n\t// Parallel direct lookups\n\tawait Promise.all(\n\t\trecipients.map(async recipient => {\n\t\t\tconst sockets = await redis.getSetMembers(kEntityEventSockets(recipient, eventKey));\n\t\t\tif (sockets.length > 0) {\n\t\t\t\tconst instanceSet = new Set<string>();\n\t\t\t\tfor (let i = 0; i < sockets.length; i++) {\n\t\t\t\t\tconst [instanceId] = sockets[i].split('|');\n\t\t\t\t\tif (instanceId) instanceSet.add(instanceId);\n\t\t\t\t}\n\t\t\t\tif (instanceSet.size > 0) {\n\t\t\t\t\tvalidInstances.push({ recipient, instances: Array.from(instanceSet) });\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t);\n\n\tif (validInstances.length > 0) {\n\t\tpublishToInstances(validInstances, eventKey, event.payload());\n\t}\n}\n"]}
1
+ {"version":3,"file":"socket-event-publisher.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-publisher.ts"],"names":[],"mappings":";;AAsDA,gDAkCC;AAED,wEAoBC;AA9GD,gCAAwC;AAGxC,uCA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AG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAClF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;YAAE,cAAc,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CACF,CAAC;IAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC;QAAE,iBAAiB,CAAC,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["import { getLibraries } from '../../..';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { SocketNotificationEvent } from '../events';\nimport { publish, publishEvent } from '../../event';\nimport { PushNotificationEvent } from '../PushNotificationEvent';\nimport type { ZodTypeAny } from 'zod';\nimport { EntitySubscription, kEntityEventSockets } from '../connections';\n\nfunction fanOutToInstances(\n\trecipientsWithInstances: Array<{ recipient: EntitySubscription; instances: string[] }>,\n\tlocalKey: string,\n\tpayload: unknown\n): void {\n\tif (recipientsWithInstances.length === 0) return;\n\n\tfor (const { recipient, instances } of recipientsWithInstances) {\n\t\tconst message = { localKey, payload, recipient };\n\t\tfor (const instanceId of instances) {\n\t\t\tpublish(`instance.${instanceId}`, message).catch((error: unknown) => {\n\t\t\t\tconsole.error(`[Socket] Publish failed for instance ${instanceId}`, error);\n\t\t\t});\n\t\t}\n\t}\n}\n\nasync function getActiveSubscribedRecipients(\n\trecipients: EntitySubscription[],\n\tlocalKey: string\n): Promise<{\n\tsubscribed: Array<{ recipient: EntitySubscription; instances: string[] }>;\n\tunsubscribed: EntitySubscription[];\n}> {\n\tif (recipients.length === 0) return { subscribed: [], unsubscribed: [] };\n\n\tconst redis = getLibraries().getRedisService();\n\tconst subscribed: Array<{ recipient: EntitySubscription; instances: string[] }> = [];\n\tconst unsubscribed: EntitySubscription[] = [];\n\n\tawait Promise.all(\n\t\trecipients.map(async recipient => {\n\t\t\tconst sockets = await redis.getSetMembers(kEntityEventSockets(recipient, localKey));\n\t\t\tif (sockets.length === 0) {\n\t\t\t\tunsubscribed.push(recipient);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst instances = [...new Set(sockets.map(s => s.split('|')[0]).filter(Boolean))];\n\t\t\tif (instances.length > 0) subscribed.push({ recipient, instances });\n\t\t\telse unsubscribed.push(recipient);\n\t\t})\n\t);\n\n\treturn { subscribed, unsubscribed };\n}\n\nexport async function publishSocketEvent(\n\tevent: BaseSocketEvent<ZodTypeAny, ZodTypeAny, ZodTypeAny | undefined>,\n\trecipients: EntitySubscription[]\n): Promise<void> {\n\tconst logger = getLibraries().getLogger().logger;\n\tif (recipients.length === 0) return;\n\n\tconst localKey = event.getSubscriptionKey();\n\tconst payload = event.payload();\n\n\tconst { subscribed, unsubscribed } = await getActiveSubscribedRecipients(recipients, localKey);\n\n\tlogger.debug({ subscribed }, '[Socket] Subscribed recipients:');\n\tlogger.debug({ unsubscribed }, '[Socket] Unsubscribed recipients:');\n\n\tif (subscribed.length > 0) fanOutToInstances(subscribed, localKey, payload);\n\n\tif (unsubscribed.length > 0) {\n\t\tlogger.debug({ unsubscribed }, '[Socket] Processing unsubscribed recipients');\n\n\t\tif (event.notificationSettings?.isPushNotification) {\n\t\t\tconst pushNotificationPayload = event.getPushNotificationPayload();\n\t\t\tawait publishEvent(\n\t\t\t\tnew PushNotificationEvent(event.eventType(), pushNotificationPayload, unsubscribed, event.notificationSettings)\n\t\t\t).catch(err => console.error('[Socket] Push notification failed:', err));\n\t\t}\n\n\t\tconst socketNotificationPayload = event.getSocketNotificationEvent();\n\t\tlogger.debug({ socketNotificationPayload }, '[Socket] Socket notification payload');\n\n\t\tif (socketNotificationPayload) {\n\t\t\tawait publishNotificationSocketEvent(socketNotificationPayload, unsubscribed);\n\t\t}\n\t}\n}\n\nexport async function publishNotificationSocketEvent(\n\tevent: SocketNotificationEvent,\n\trecipients: EntitySubscription[]\n): Promise<void> {\n\tif (recipients.length === 0) return;\n\n\tconst eventKey = event.getSubscriptionKey();\n\tconst redis = getLibraries().getRedisService();\n\tconst validInstances: Array<{ recipient: EntitySubscription; instances: string[] }> = [];\n\n\tawait Promise.all(\n\t\trecipients.map(async recipient => {\n\t\t\tconst sockets = await redis.getSetMembers(kEntityEventSockets(recipient, eventKey));\n\t\t\tif (sockets.length === 0) return;\n\t\t\tconst instances = [...new Set(sockets.map(s => s.split('|')[0]).filter(Boolean))];\n\t\t\tif (instances.length > 0) validInstances.push({ recipient, instances });\n\t\t})\n\t);\n\n\tif (validInstances.length > 0) fanOutToInstances(validInstances, eventKey, event.payload());\n}\n"]}
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
- req: import("http").IncomingMessage;
9
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
10
9
  tokenType: TokenType | undefined;
10
+ req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
4
4
  allowedRoles: string[];
5
5
  }
6
6
  export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
7
- req: import("http").IncomingMessage;
8
7
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
8
  tokenType: import("../../auth").TokenType | undefined;
9
+ req: import("http").IncomingMessage;
10
10
  requestId: string | undefined;
11
11
  entity: import("../context").EntityContext | undefined;
12
12
  usedRefreshToken: boolean | undefined;
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
3
3
  entityTypes: AuthEntityType[];
4
4
  }
5
5
  export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
6
- req: import("http").IncomingMessage;
7
6
  res: import("http").ServerResponse<import("http").IncomingMessage>;
8
7
  tokenType: import("../../auth").TokenType | undefined;
8
+ req: import("http").IncomingMessage;
9
9
  requestId: string | undefined;
10
10
  entity: import("../context").EntityContext | undefined;
11
11
  usedRefreshToken: boolean | undefined;
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
- req: import("http").IncomingMessage;
9
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
10
9
  tokenType: TokenType | undefined;
10
+ req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.4.65
25
+ Version: 1.4.66
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.4.65",
3
+ "version": "1.4.66",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- populate?: any;
30
29
  select?: Record<string, 0 | 1> | undefined;
30
+ populate?: any;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- populate?: any;
40
39
  select?: Record<string, 0 | 1> | undefined;
40
+ populate?: any;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -736,12 +736,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
736
736
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
737
737
  }, "strip", z.ZodTypeAny, {
738
738
  _id: import("mongoose").Types.ObjectId;
739
- populate?: any;
740
739
  select?: Record<string, 0 | 1> | undefined;
740
+ populate?: any;
741
741
  }, {
742
742
  _id: string | import("mongoose").Types.ObjectId;
743
- populate?: any;
744
743
  select?: Record<string, 0 | 1> | undefined;
744
+ populate?: any;
745
745
  }>;
746
746
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
747
747
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -754,12 +754,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
754
754
  _id: import("mongoose").Types.ObjectId;
755
755
  withAttributeHiddenItems: boolean;
756
756
  withAddonsHiddenItems: boolean;
757
- populate?: any;
758
757
  select?: Record<string, 0 | 1> | undefined;
758
+ populate?: any;
759
759
  }, {
760
760
  _id: string | import("mongoose").Types.ObjectId;
761
- populate?: any;
762
761
  select?: Record<string, 0 | 1> | undefined;
762
+ populate?: any;
763
763
  withAttributeHiddenItems?: boolean | undefined;
764
764
  withAddonsHiddenItems?: boolean | undefined;
765
765
  }>;
@@ -773,15 +773,15 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
773
773
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
774
774
  }, "strip", z.ZodTypeAny, {
775
775
  _id: import("mongoose").Types.ObjectId;
776
- populate?: any;
777
776
  select?: Record<string, 0 | 1> | undefined;
777
+ populate?: any;
778
778
  groupByCategories?: boolean | undefined;
779
779
  getParentCategory?: boolean | undefined;
780
780
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
781
781
  }, {
782
782
  _id: string | import("mongoose").Types.ObjectId;
783
- populate?: any;
784
783
  select?: Record<string, 0 | 1> | undefined;
784
+ populate?: any;
785
785
  groupByCategories?: boolean | undefined;
786
786
  getParentCategory?: boolean | undefined;
787
787
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
@@ -791,11 +791,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
791
791
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
792
792
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
793
793
  }, "strip", z.ZodTypeAny, {
794
- populate?: any;
795
794
  select?: Record<string, 0 | 1> | undefined;
796
- }, {
797
795
  populate?: any;
796
+ }, {
798
797
  select?: Record<string, 0 | 1> | undefined;
798
+ populate?: any;
799
799
  }>>;
800
800
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
801
801
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -803,12 +803,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
803
803
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
804
804
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
805
805
  }, "strip", z.ZodTypeAny, {
806
- populate?: any;
807
806
  select?: Record<string, 0 | 1> | undefined;
807
+ populate?: any;
808
808
  query?: Record<string, any> | undefined;
809
809
  }, {
810
- populate?: any;
811
810
  select?: Record<string, 0 | 1> | undefined;
811
+ populate?: any;
812
812
  query?: Record<string, any> | undefined;
813
813
  }>;
814
814
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.4.65",
3
+ "version": "1.4.66",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -29,9 +29,9 @@
29
29
  "@google-cloud/secret-manager": "^5.6.0",
30
30
  "@mapbox/polyline": "^1.2.1",
31
31
  "@typegoose/typegoose": "^12.10.1",
32
- "@types/amqplib": "^0.10.7",
33
32
  "@types/node": "^22.10.2",
34
33
  "@types/twilio": "^3.19.3",
34
+ "amqp-connection-manager": "^5.0.0",
35
35
  "amqplib": "^0.10.5",
36
36
  "bcryptjs": "^3.0.2",
37
37
  "bullmq": "^5.56.0",
@@ -62,6 +62,7 @@
62
62
  "devDependencies": {
63
63
  "@trpc/client": "^11.4.3",
64
64
  "@trpc/server": "^11.4.3",
65
+ "@types/amqplib": "^0.10.8",
65
66
  "@types/mapbox__polyline": "^1.0.5",
66
67
  "@types/mime-types": "^2.1.4",
67
68
  "@types/shortid": "^2.2.0",