@lyxa.ai/core 1.3.144 → 1.3.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/index.js.map +1 -1
  3. package/dist/libraries/event/EventEnums.d.ts +2 -1
  4. package/dist/libraries/event/EventEnums.js +1 -0
  5. package/dist/libraries/event/EventEnums.js.map +1 -1
  6. package/dist/libraries/event/decorators/subscribe.d.ts +2 -1
  7. package/dist/libraries/event/decorators/subscribe.js +2 -2
  8. package/dist/libraries/event/decorators/subscribe.js.map +1 -1
  9. package/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event.d.ts +2 -1
  10. package/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event.js +1 -0
  11. package/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event.js.map +1 -1
  12. package/dist/libraries/event/events/sync-all-customized-shop-sections-cache-event.d.ts +8 -0
  13. package/dist/libraries/event/events/sync-all-customized-shop-sections-cache-event.js +14 -0
  14. package/dist/libraries/event/events/sync-all-customized-shop-sections-cache-event.js.map +1 -0
  15. package/dist/libraries/event/index.d.ts +5 -1
  16. package/dist/libraries/event/index.js +46 -15
  17. package/dist/libraries/event/index.js.map +1 -1
  18. package/dist/libraries/event/registry/SubscriptionRegistry.d.ts +3 -1
  19. package/dist/libraries/event/registry/SubscriptionRegistry.js +2 -1
  20. package/dist/libraries/event/registry/SubscriptionRegistry.js.map +1 -1
  21. package/dist/types/README.md +1 -1
  22. package/dist/types/package.json +1 -1
  23. package/dist/utilities/events-common-methods.d.ts +2 -0
  24. package/dist/utilities/events-common-methods.js +6 -0
  25. package/dist/utilities/events-common-methods.js.map +1 -1
  26. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -155,7 +155,7 @@ async function registerLibraries(options) {
155
155
  await (0, event_1.initEventBus)(rabbitmq_environments_1.RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType_1.EnvironmentConfigurationType.DEV]);
156
156
  const allSubscriptions = SubscriptionRegistry_1.SubscriptionRegistry.getAllSubscriptions();
157
157
  const instantiatedServices = new Map();
158
- for (const { eventId, targetConstructor, methodName } of allSubscriptions) {
158
+ for (const { eventId, targetConstructor, methodName, opts } of allSubscriptions) {
159
159
  let instance = instantiatedServices.get(targetConstructor);
160
160
  if (!instance) {
161
161
  instance = typedi_1.Container.get(targetConstructor);
@@ -163,7 +163,7 @@ async function registerLibraries(options) {
163
163
  }
164
164
  await (0, event_1.subscribeToEvent)(eventId, async (payload) => {
165
165
  return instance[methodName](payload);
166
- });
166
+ }, opts);
167
167
  }
168
168
  }
169
169
  function getLibraries() {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,sCA2BC;AAED,8CAyGC;AAED,oCAEC;AA/KD,qFAAqF;AACrF,IAAA,0CAAqB,GAAE,CAAC;AAExB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;AACvF,+CAAgD;AAChD,6CAAiD;AACjD,6CAAoF;AACpF,iDAA2D;AAC3D,uDAAgE;AAChE,+CAAmD;AACnD,mDAAuD;AACvD,6CAAmE;AACnE,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAC5F,+GAA4G;AAC5G,yDAAgE;AAChE,yFAA+E;AAC/E,4FAAuG;AACvG,uDAAuD;AAKvD,6GAA4G;AAAnG,4IAAA,4BAA4B,OAAA;AACrC,2CAAyD;AAAhD,6GAAA,oBAAoB,OAAA;AAEtB,KAAK,UAAU,aAAa,CAAC,OAA8B;IACjE,IAAI,CAAC;QACJ,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEjC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAA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AA4B,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7F,MAAM,gBAAgB,GAAG,2CAAoB,CAAC,mBAAmB,EAAE,CAAC;IAEpE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEtD,KAAK,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,gBAAgB,EAAE,CAAC;QAC3E,IAAI,QAAQ,GAAG,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,QAAQ,GAAG,kBAAS,CAAC,GAAG,CAAC,iBAAwB,CAAC,CAAC;YACnD,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;YAC/C,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACJ,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();\n\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\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\n\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\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\t\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\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\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 } 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 => {\n\t\t\treturn instance[methodName](payload);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,sCA2BC;AAED,8CA6GC;AAED,oCAEC;AAlLD,qFAAqF;AACrF,IAAA,0CAAqB,GAAE,CAAC;AACxB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;AACvF,+CAAgD;AAChD,6CAAiD;AACjD,6CAAoF;AACpF,iDAA2D;AAC3D,uDAAgE;AAChE,+CAAmD;AACnD,mDAAuD;AACvD,6CAAmE;AACnE,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAC5F,+GAA4G;AAC5G,yDAAgE;AAChE,yFAA+E;AAC/E,4FAAuG;AACvG,uDAAuD;AAKvD,6GAA4G;AAAnG,4IAAA,4BAA4B,OAAA;AACrC,2CAAyD;AAAhD,6GAAA,oBAAoB,OAAA;AAEtB,KAAK,UAAU,aAAa,CAAC,OAA8B;IACjE,IAAI,CAAC;QACJ,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEjC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QAE/E,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;YACnC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;YAChG,IAAI,OAAO,EAAE,YAAY,IAAI,QAAQ;gBAAE,MAAM,IAAA,uDAAiC,GAAE,CAAC;YACjF,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE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AAC,iBAAiB,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,QAAQ,GAAG,kBAAS,CAAC,GAAG,CAAC,iBAAwB,CAAC,CAAC;YACnD,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,IAAA,wBAAgB,EACrB,OAAO,EACP,KAAK,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\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\n\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\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\t\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\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\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"]}
@@ -12,5 +12,6 @@ export declare enum PublishEventEnums {
12
12
  SYNC_ALL_SHOPS_AVG_PREPARATION_TIME_EVENT = "sync_all_shops_avg_preperation_time_event",
13
13
  SYNC_SINGLE_SHOP_CACHE_EVENT = "sync_single_shop_cache_event",
14
14
  SYNC_SINGLE_SHOP_ORDER_AGAIN_CACHE_EVENT = "sync_single_shop_order_again_cache_event",
15
- SYNC_SINGLE_SHOP_SECTIONS_CACHE_EVENT = "sync_single_shop_sections_cache_event"
15
+ SYNC_SINGLE_SHOP_SECTIONS_CACHE_EVENT = "sync_single_shop_sections_cache_event",
16
+ SYNC_ALL_CUSTOMIZED_SHOP_SECTIONS_CACHE_EVENT = "sync_all_customized_shop_sections_cache_event"
16
17
  }
@@ -17,5 +17,6 @@ var PublishEventEnums;
17
17
  PublishEventEnums["SYNC_SINGLE_SHOP_CACHE_EVENT"] = "sync_single_shop_cache_event";
18
18
  PublishEventEnums["SYNC_SINGLE_SHOP_ORDER_AGAIN_CACHE_EVENT"] = "sync_single_shop_order_again_cache_event";
19
19
  PublishEventEnums["SYNC_SINGLE_SHOP_SECTIONS_CACHE_EVENT"] = "sync_single_shop_sections_cache_event";
20
+ PublishEventEnums["SYNC_ALL_CUSTOMIZED_SHOP_SECTIONS_CACHE_EVENT"] = "sync_all_customized_shop_sections_cache_event";
20
21
  })(PublishEventEnums || (exports.PublishEventEnums = PublishEventEnums = {}));
21
22
  //# sourceMappingURL=EventEnums.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EventEnums.js","sourceRoot":"/","sources":["libraries/event/EventEnums.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IAC5B,4EAAuD,CAAA;IACvD,sEAAiD,CAAA;IACjD,4EAAuD,CAAA;IACvD,sEAAiD,CAAA;IACjD,wGAAmF,CAAA;IACnF,sHAAiG,CAAA;IACjG,oGAA+E,CAAA;IAC/E,sFAAiE,CAAA;IACjE,8FAAyE,CAAA;IACzE,sHAAiG,CAAA;IACjG,4GAAuF,CAAA;IACvF,kFAA6D,CAAA;IAC7D,0GAAqF,CAAA;IACrF,oGAA+E,CAAA;AAChF,CAAC,EAfW,iBAAiB,iCAAjB,iBAAiB,QAe5B","sourcesContent":["export enum PublishEventEnums {\n\tADMIN_ACTIVITY_LOGS_EVENT = 'admin_activity_logs_event',\n\tMESSAGE_RECEIVED_EVENT = 'message_received_event',\n\tTICKET_NOTIFICATION_EVENT = 'ticket_notification_event',\n\tCART_ITEM_UPSERT_EVENT = 'cart_item_upsert_event',\n\tSHOP_ACTIVE_TIMINGS_BATCH_PROCESS_EVENT = 'shop_active_timings_batch_process_event',\n\tMONGO_STREAM_CHANGES_BATCH_PROCESS_SHOPS_EVENT = 'mongo_stream_changes_batch_process_shops_event',\n\tBULK_UPDATE_SHOPS_SEARCH_FIELDS_EVENT = 'bulk_update_shops_search_fields_event',\n\tSOCKET_PUSH_NOTIFICATION_EVENT = 'socket_push_notification_event',\n\tBULK_UPDATE_SHOP_ZONE_STATUS_EVENT = 'bulk_update_shop_zone_status_event',\n\tSYNC_ALL_PRODUCTS_PRODUCT_MARKETING_INFO_EVENT = 'sync_all_products_product_marketing_info_event',\n\tSYNC_ALL_SHOPS_AVG_PREPARATION_TIME_EVENT = 'sync_all_shops_avg_preperation_time_event',\n\tSYNC_SINGLE_SHOP_CACHE_EVENT = 'sync_single_shop_cache_event',\n\tSYNC_SINGLE_SHOP_ORDER_AGAIN_CACHE_EVENT = 'sync_single_shop_order_again_cache_event',\n\tSYNC_SINGLE_SHOP_SECTIONS_CACHE_EVENT = 'sync_single_shop_sections_cache_event'\n}\n"]}
1
+ {"version":3,"file":"EventEnums.js","sourceRoot":"/","sources":["libraries/event/EventEnums.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAgBX;AAhBD,WAAY,iBAAiB;IAC5B,4EAAuD,CAAA;IACvD,sEAAiD,CAAA;IACjD,4EAAuD,CAAA;IACvD,sEAAiD,CAAA;IACjD,wGAAmF,CAAA;IACnF,sHAAiG,CAAA;IACjG,oGAA+E,CAAA;IAC/E,sFAAiE,CAAA;IACjE,8FAAyE,CAAA;IACzE,sHAAiG,CAAA;IACjG,4GAAuF,CAAA;IACvF,kFAA6D,CAAA;IAC7D,0GAAqF,CAAA;IACrF,oGAA+E,CAAA;IAC/E,oHAA+F,CAAA;AAChG,CAAC,EAhBW,iBAAiB,iCAAjB,iBAAiB,QAgB5B","sourcesContent":["export enum PublishEventEnums {\n\tADMIN_ACTIVITY_LOGS_EVENT = 'admin_activity_logs_event',\n\tMESSAGE_RECEIVED_EVENT = 'message_received_event',\n\tTICKET_NOTIFICATION_EVENT = 'ticket_notification_event',\n\tCART_ITEM_UPSERT_EVENT = 'cart_item_upsert_event',\n\tSHOP_ACTIVE_TIMINGS_BATCH_PROCESS_EVENT = 'shop_active_timings_batch_process_event',\n\tMONGO_STREAM_CHANGES_BATCH_PROCESS_SHOPS_EVENT = 'mongo_stream_changes_batch_process_shops_event',\n\tBULK_UPDATE_SHOPS_SEARCH_FIELDS_EVENT = 'bulk_update_shops_search_fields_event',\n\tSOCKET_PUSH_NOTIFICATION_EVENT = 'socket_push_notification_event',\n\tBULK_UPDATE_SHOP_ZONE_STATUS_EVENT = 'bulk_update_shop_zone_status_event',\n\tSYNC_ALL_PRODUCTS_PRODUCT_MARKETING_INFO_EVENT = 'sync_all_products_product_marketing_info_event',\n\tSYNC_ALL_SHOPS_AVG_PREPARATION_TIME_EVENT = 'sync_all_shops_avg_preperation_time_event',\n\tSYNC_SINGLE_SHOP_CACHE_EVENT = 'sync_single_shop_cache_event',\n\tSYNC_SINGLE_SHOP_ORDER_AGAIN_CACHE_EVENT = 'sync_single_shop_order_again_cache_event',\n\tSYNC_SINGLE_SHOP_SECTIONS_CACHE_EVENT = 'sync_single_shop_sections_cache_event',\n\tSYNC_ALL_CUSTOMIZED_SHOP_SECTIONS_CACHE_EVENT = 'sync_all_customized_shop_sections_cache_event'\n}\n \n"]}
@@ -1 +1,2 @@
1
- export declare function Subscribe(eventId: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
1
+ import { RabbitMQEventOptions } from '../index';
2
+ export declare function Subscribe(eventId: string, opts?: RabbitMQEventOptions): (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) {
5
+ function Subscribe(eventId, opts) {
6
6
  return function (target, propertyKey, descriptor) {
7
- SubscriptionRegistry_1.SubscriptionRegistry.register(eventId, target.constructor, propertyKey);
7
+ SubscriptionRegistry_1.SubscriptionRegistry.register(eventId, target.constructor, propertyKey, opts);
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":";;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\n"]}
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"]}
@@ -12,7 +12,8 @@ export declare enum UpdateCollectionAtlasSearchEnum {
12
12
  TAGS = "tags",
13
13
  BRANDS = "brands",
14
14
  PRODUCTS = "products",
15
- CATEGORIES = "categories"
15
+ CATEGORIES = "categories",
16
+ USER_APP_SECTION_SETTING = "userAppSectionSetting"
16
17
  }
17
18
  declare const MongoStreamsBatchProcessShopsSchema: z.ZodObject<{
18
19
  operation: z.ZodNativeEnum<typeof ChangeStreamOperationTypes>;
@@ -19,6 +19,7 @@ var UpdateCollectionAtlasSearchEnum;
19
19
  UpdateCollectionAtlasSearchEnum["BRANDS"] = "brands";
20
20
  UpdateCollectionAtlasSearchEnum["PRODUCTS"] = "products";
21
21
  UpdateCollectionAtlasSearchEnum["CATEGORIES"] = "categories";
22
+ UpdateCollectionAtlasSearchEnum["USER_APP_SECTION_SETTING"] = "userAppSectionSetting";
22
23
  })(UpdateCollectionAtlasSearchEnum || (exports.UpdateCollectionAtlasSearchEnum = UpdateCollectionAtlasSearchEnum = {}));
23
24
  const baseFields = {
24
25
  operation: global_validation_1.ZodValidation.enumType(ChangeStreamOperationTypes, 'Mongo streams operation'),
@@ -1 +1 @@
1
- {"version":3,"file":"mongo-stream-changes-batch-process-shops-event.js","sourceRoot":"/","sources":["libraries/event/events/mongo-stream-changes-batch-process-shops-event.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,4CAAyC;AACzC,8CAAkD;AAClD,uFAA0G;AAE1G,IAAY,0BAKX;AALD,WAAY,0BAA0B;IACpC,+CAAiB,CAAA;IACjB,+CAAiB,CAAA;IACjB,iDAAmB,CAAA;IACnB,+CAAiB,CAAA;AACnB,CAAC,EALW,0BAA0B,0CAA1B,0BAA0B,QAKrC;AAED,IAAY,+BAMX;AAND,WAAY,+BAA+B;IACvC,kDAAe,CAAA;IACf,gDAAa,CAAA;IACb,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,4DAAyB,CAAA;AAC7B,CAAC,EANW,+BAA+B,+CAA/B,+BAA+B,QAM1C;AAED,MAAM,UAAU,GAAG;IACf,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,0BAA0B,EAAE,yBAAyB,CAAC;IACxF,gBAAgB,EAAE,iCAAa,CAAC,QAAQ,CAAC,+BAA+B,EAAE,oBAAoB,CAAC;IAC/F,aAAa,EAAE,OAAC,CAAC,GAAG,EAAE;IACtB,YAAY,EAAE,OAAC,CAAC,GAAG,EAAE;CACxB,CAAC;AACF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AACtD,MAAM,EACF,UAAU,EAAE,mCAAmC,GAClD,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAIrD,MAAa,kCAAmC,SAAQ,qBAAkC;IACtF,YAAY,OAAyC;QACjD,KAAK,CAAC,8BAAiB,CAAC,8CAA8C,EAAE,OAAkC,CAAC,CAAC;IAChH,CAAC;CACJ;AAJD,gFAIC","sourcesContent":["import { z } from 'zod';\nimport { BaseEvent } from '../BaseEvent';\nimport { PublishEventEnums } from '../EventEnums';\nimport { createSchemaBuilder, DTO, ZodValidation } from '../../../utilities/validation/global-validation';\n\nexport enum ChangeStreamOperationTypes {\n INSERT = \"insert\",\n UPDATE = \"update\",\n REPLACE = \"replace\",\n DELETE = \"delete\"\n}\n\nexport enum UpdateCollectionAtlasSearchEnum {\n SHOPS = 'shops',\n TAGS = 'tags',\n BRANDS = 'brands',\n PRODUCTS = 'products',\n CATEGORIES = 'categories'\n}\n\nconst baseFields = {\n operation: ZodValidation.enumType(ChangeStreamOperationTypes, 'Mongo streams operation'),\n updateCollection: ZodValidation.enumType(UpdateCollectionAtlasSearchEnum, 'Updated collection'),\n updatedFields: z.any(),\n fullDocument: z.any()\n};\nconst schemaBuilder = createSchemaBuilder(baseFields);\nconst {\n BaseSchema: MongoStreamsBatchProcessShopsSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nexport type MongoStreamsBatchProcessShopsDTO = DTO<typeof MongoStreamsBatchProcessShopsSchema>;\n\nexport class MongoStreamsBatchProcessShopsEvent extends BaseEvent<Record<string, unknown>> {\n constructor(payload: MongoStreamsBatchProcessShopsDTO) {\n super(PublishEventEnums.MONGO_STREAM_CHANGES_BATCH_PROCESS_SHOPS_EVENT, payload as Record<string, unknown>);\t\t\n }\n}"]}
1
+ {"version":3,"file":"mongo-stream-changes-batch-process-shops-event.js","sourceRoot":"/","sources":["libraries/event/events/mongo-stream-changes-batch-process-shops-event.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,4CAAyC;AACzC,8CAAkD;AAClD,uFAA0G;AAE1G,IAAY,0BAKX;AALD,WAAY,0BAA0B;IAClC,+CAAiB,CAAA;IACjB,+CAAiB,CAAA;IACjB,iDAAmB,CAAA;IACnB,+CAAiB,CAAA;AACrB,CAAC,EALW,0BAA0B,0CAA1B,0BAA0B,QAKrC;AAED,IAAY,+BAOX;AAPD,WAAY,+BAA+B;IACvC,kDAAe,CAAA;IACf,gDAAa,CAAA;IACb,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,4DAAyB,CAAA;IACzB,qFAAkD,CAAA;AACtD,CAAC,EAPW,+BAA+B,+CAA/B,+BAA+B,QAO1C;AAED,MAAM,UAAU,GAAG;IACf,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,0BAA0B,EAAE,yBAAyB,CAAC;IACxF,gBAAgB,EAAE,iCAAa,CAAC,QAAQ,CAAC,+BAA+B,EAAE,oBAAoB,CAAC;IAC/F,aAAa,EAAE,OAAC,CAAC,GAAG,EAAE;IACtB,YAAY,EAAE,OAAC,CAAC,GAAG,EAAE;CACxB,CAAC;AACF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AACtD,MAAM,EACF,UAAU,EAAE,mCAAmC,GAClD,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAIrD,MAAa,kCAAmC,SAAQ,qBAAkC;IACtF,YAAY,OAAyC;QACjD,KAAK,CAAC,8BAAiB,CAAC,8CAA8C,EAAE,OAAkC,CAAC,CAAC;IAChH,CAAC;CACJ;AAJD,gFAIC","sourcesContent":["import { z } from 'zod';\nimport { BaseEvent } from '../BaseEvent';\nimport { PublishEventEnums } from '../EventEnums';\nimport { createSchemaBuilder, DTO, ZodValidation } from '../../../utilities/validation/global-validation';\n\nexport enum ChangeStreamOperationTypes {\n INSERT = \"insert\",\n UPDATE = \"update\",\n REPLACE = \"replace\",\n DELETE = \"delete\"\n}\n\nexport enum UpdateCollectionAtlasSearchEnum {\n SHOPS = 'shops',\n TAGS = 'tags',\n BRANDS = 'brands',\n PRODUCTS = 'products',\n CATEGORIES = 'categories',\n USER_APP_SECTION_SETTING = 'userAppSectionSetting'\n}\n\nconst baseFields = {\n operation: ZodValidation.enumType(ChangeStreamOperationTypes, 'Mongo streams operation'),\n updateCollection: ZodValidation.enumType(UpdateCollectionAtlasSearchEnum, 'Updated collection'),\n updatedFields: z.any(),\n fullDocument: z.any()\n};\nconst schemaBuilder = createSchemaBuilder(baseFields);\nconst {\n BaseSchema: MongoStreamsBatchProcessShopsSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nexport type MongoStreamsBatchProcessShopsDTO = DTO<typeof MongoStreamsBatchProcessShopsSchema>;\n\nexport class MongoStreamsBatchProcessShopsEvent extends BaseEvent<Record<string, unknown>> {\n constructor(payload: MongoStreamsBatchProcessShopsDTO) {\n super(PublishEventEnums.MONGO_STREAM_CHANGES_BATCH_PROCESS_SHOPS_EVENT, payload as Record<string, unknown>);\n }\n}"]}
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { BaseEvent } from '../BaseEvent';
3
+ import { DTO } from '../../../utilities/validation/global-validation';
4
+ export declare const SynchronizeAllCustomizedShopSectionsCacheSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
+ export type SynchronizeAllCustomizedShopSectionsCacheDTO = DTO<typeof SynchronizeAllCustomizedShopSectionsCacheSchema>;
6
+ export declare class SynchronizeAllCustomizedShopSectionsCacheEvent extends BaseEvent<Record<string, unknown>> {
7
+ constructor(payload: SynchronizeAllCustomizedShopSectionsCacheDTO);
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SynchronizeAllCustomizedShopSectionsCacheEvent = exports.SynchronizeAllCustomizedShopSectionsCacheSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const BaseEvent_1 = require("../BaseEvent");
6
+ const EventEnums_1 = require("../EventEnums");
7
+ exports.SynchronizeAllCustomizedShopSectionsCacheSchema = zod_1.z.object({});
8
+ class SynchronizeAllCustomizedShopSectionsCacheEvent extends BaseEvent_1.BaseEvent {
9
+ constructor(payload) {
10
+ super(EventEnums_1.PublishEventEnums.SYNC_ALL_CUSTOMIZED_SHOP_SECTIONS_CACHE_EVENT, payload);
11
+ }
12
+ }
13
+ exports.SynchronizeAllCustomizedShopSectionsCacheEvent = SynchronizeAllCustomizedShopSectionsCacheEvent;
14
+ //# sourceMappingURL=sync-all-customized-shop-sections-cache-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-all-customized-shop-sections-cache-event.js","sourceRoot":"/","sources":["libraries/event/events/sync-all-customized-shop-sections-cache-event.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,4CAAyC;AACzC,8CAAkD;AAGrC,QAAA,+CAA+C,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAI3E,MAAa,8CAA+C,SAAQ,qBAAkC;IAClG,YAAY,OAAqD;QAC7D,KAAK,CAAC,8BAAiB,CAAC,6CAA6C,EAAE,OAAkC,CAAC,CAAC;IAC/G,CAAC;CACJ;AAJD,wGAIC","sourcesContent":["import { z } from 'zod';\nimport { BaseEvent } from '../BaseEvent';\nimport { PublishEventEnums } from '../EventEnums';\nimport { DTO } from '../../../utilities/validation/global-validation';\n\nexport const SynchronizeAllCustomizedShopSectionsCacheSchema = z.object({})\n \nexport type SynchronizeAllCustomizedShopSectionsCacheDTO = DTO<typeof SynchronizeAllCustomizedShopSectionsCacheSchema>;\n\nexport class SynchronizeAllCustomizedShopSectionsCacheEvent extends BaseEvent<Record<string, unknown>> {\n constructor(payload: SynchronizeAllCustomizedShopSectionsCacheDTO) {\n super(PublishEventEnums.SYNC_ALL_CUSTOMIZED_SHOP_SECTIONS_CACHE_EVENT, payload as Record<string, unknown>);\n }\n}"]}
@@ -1,5 +1,8 @@
1
1
  import amqp from 'amqplib';
2
2
  import { BaseEvent } from './BaseEvent';
3
+ export interface RabbitMQEventOptions {
4
+ consumeImmediately?: boolean;
5
+ }
3
6
  export declare const EXCHANGE_NAME = "lyxa.events";
4
7
  export declare const INSTANCE_ROUTE_PREFIX = "instance";
5
8
  export declare function initEventBus(rabbitUrl: string): Promise<void>;
@@ -8,5 +11,6 @@ export declare function getChannel(): {
8
11
  subChannel: amqp.Channel;
9
12
  };
10
13
  export declare function publishEvent<TPayload extends Record<string, unknown>>(event: BaseEvent<TPayload>): Promise<void>;
11
- export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): 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[]>;
12
16
  export declare function closeEventBus(): Promise<void>;
@@ -8,9 +8,12 @@ exports.initEventBus = initEventBus;
8
8
  exports.getChannel = getChannel;
9
9
  exports.publishEvent = publishEvent;
10
10
  exports.subscribeToEvent = subscribeToEvent;
11
+ exports.consumeAllMessages = consumeAllMessages;
11
12
  exports.closeEventBus = closeEventBus;
12
13
  const amqplib_1 = __importDefault(require("amqplib"));
13
14
  const instance_utils_1 = require("../../utilities/instance.utils");
15
+ const index_1 = require("../../index");
16
+ const enum_1 = require("../../utilities/enum");
14
17
  let connection;
15
18
  let pubChannel;
16
19
  let subChannel;
@@ -45,7 +48,7 @@ async function publishEvent(event) {
45
48
  });
46
49
  await ch.waitForConfirms();
47
50
  }
48
- async function subscribeToEvent(eventId, onMessage) {
51
+ async function subscribeToEvent(eventId, onMessage, opts) {
49
52
  const ch = getChannel().subChannel;
50
53
  const queueName = `${eventId}`;
51
54
  await ch.assertQueue(queueName, {
@@ -54,26 +57,54 @@ async function subscribeToEvent(eventId, onMessage) {
54
57
  autoDelete: false,
55
58
  });
56
59
  await ch.bindQueue(queueName, exports.EXCHANGE_NAME, eventId);
57
- await ch.consume(queueName, async (msg) => {
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
+ });
80
+ }
81
+ console.log(`Subscribed to event [${eventId}]`);
82
+ }
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 });
58
89
  if (!msg)
59
- return;
60
- let processed = false;
90
+ break;
61
91
  try {
62
92
  const payload = JSON.parse(msg.content.toString());
63
- await onMessage(payload);
64
- processed = true;
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
+ });
65
98
  }
66
99
  catch (err) {
67
- console.error(`Error handling event [${eventId}]`, 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);
68
104
  }
69
- finally {
70
- if (processed)
71
- ch.ack(msg);
72
- else
73
- ch.nack(msg, false, true);
74
- }
75
- });
76
- console.log(`Subscribed to event [${eventId}]`);
105
+ }
106
+ logger.debug(`Fetched ${messages.length} messages for event ${queueName}`, { tag: enum_1.LogTag.INFRA_QUEUE });
107
+ return messages;
77
108
  }
78
109
  async function closeEventBus() {
79
110
  if (pubChannel)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AAWA,oCAUC;AAED,gCAOC;AAED,oCAYC;AAED,4CAuCC;AAED,sCAKC;AA5FD,sDAA2B;AAE3B,mEAA+D;AAE/D,IAAI,UAA6B,CAAC;AAClC,IAAI,UAA+B,CAAC;AACpC,IAAI,UAAwB,CAAC;AAEhB,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,qBAAqB,GAAG,UAAU,CAAC;AAEzC,KAAK,UAAU,YAAY,CAAC,SAAiB;IACnD,UAAU,GAAG,MAAM,iBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;IACrD,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEhC,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;IAC9C,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEhC,MAAM,UAAU,CAAC,cAAc,CAAC,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE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;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';\n\nlet connection: amqp.ChannelModel;\nlet pubChannel: amqp.ConfirmChannel;\nlet subChannel: amqp.Channel;\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 Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tconsole.log('taking event', event);\n\n\tconst ch = getChannel().pubChannel;\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tch.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t});\n\tawait ch.waitForConfirms();\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>\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\n\tawait ch.consume(queueName, async msg => {\n\t\tif (!msg) return;\n\t\tlet processed = false;\n\t\ttry {\n\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\tawait onMessage(payload);\n\t\t\tprocessed = true;\n\t\t} catch (err) {\n\t\t\tconsole.error(`Error handling event [${eventId}]`, err);\n\t\t} finally {\n\t\t\tif (processed) ch.ack(msg);\n\t\t\telse ch.nack(msg, false, true); // retry\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 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":";;;;;;AAiBA,oCAUC;AAED,gCAOC;AAED,oCAYC;AAED,4CAyCC;AAED,gDAyBC;AAED,sCAKC;AA/HD,sDAA2B;AAE3B,mEAA+D;AAC/D,uCAA2C;AAC3C,+CAA8C;AAE9C,IAAI,UAA6B,CAAC;AAClC,IAAI,UAA+B,CAAC;AACpC,IAAI,UAAwB,CAAC;AAMhB,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,qBAAqB,GAAG,UAAU,CAAC;AAEzC,KAAK,UAAU,YAAY,CAAC,SAAiB;IACnD,UAAU,GAAG,MAAM,iBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;IACrD,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEhC,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;IAC9C,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEhC,MAAM,UAAU,CAAC,cAAc,CAAC,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,OAAO,CAAC,G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O,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 Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tconsole.log('taking event', event);\n\n\tconst ch = getChannel().pubChannel;\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tch.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t});\n\tawait ch.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,11 +1,13 @@
1
+ import { RabbitMQEventOptions } from '../index';
1
2
  interface SubscriptionMetadata {
2
3
  eventId: string;
3
4
  targetConstructor: Function;
4
5
  methodName: string;
6
+ opts?: RabbitMQEventOptions;
5
7
  }
6
8
  export declare class SubscriptionRegistry {
7
9
  private static subscriptions;
8
- static register(eventId: string, targetConstructor: Function, methodName: string): void;
10
+ static register(eventId: string, targetConstructor: Function, methodName: string, opts?: RabbitMQEventOptions): void;
9
11
  static getAllSubscriptions(): SubscriptionMetadata[];
10
12
  }
11
13
  export {};
@@ -3,11 +3,12 @@ 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) {
6
+ static register(eventId, targetConstructor, methodName, opts) {
7
7
  this.subscriptions.push({
8
8
  eventId,
9
9
  targetConstructor,
10
10
  methodName,
11
+ opts: opts,
11
12
  });
12
13
  }
13
14
  static getAllSubscriptions() {
@@ -1 +1 @@
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;IAMnD,MAAM,CAAC,QAAQ,CAAC,OAAe,EAAE,iBAA2B,EAAE,UAAkB;QACtF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACvB,OAAO;YACP,iBAAiB;YACjB,UAAU;SACV,CAAC,CAAC;IACJ,CAAC;IAMM,MAAM,CAAC,mBAAmB;QAChC,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;;AArBF,oDAsBC","sourcesContent":["interface SubscriptionMetadata {\n\teventId: string;\n\ttargetConstructor: Function;\n\tmethodName: string;\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(eventId: string, targetConstructor: Function, methodName: string) {\n\t\tthis.subscriptions.push({\n\t\t\teventId,\n\t\t\ttargetConstructor,\n\t\t\tmethodName,\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":";;;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"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.3.144
25
+ Version: 1.3.146
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.144",
3
+ "version": "1.3.146",
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",
@@ -7,6 +7,7 @@ import { SynchronizeAllShopsAvgPreparationTimeDTO } from '../libraries/event/eve
7
7
  import { SyncSingleShopCacheDTO } from '../libraries/event/events/sync-single-shop-in-cache-event';
8
8
  import { SyncSingleShopOrderAgainCacheDTO } from '../libraries/event/events/sync-order-again-sections-for-shop-event';
9
9
  import { SyncSingleShopSectionsInCacheDTO } from '../libraries/event/events/sync-single-shop-sections-in-cache-event';
10
+ import { SynchronizeAllCustomizedShopSectionsCacheDTO } from '../libraries/event/events/sync-all-customized-shop-sections-cache-event';
10
11
  export declare function getChangedFields<T extends Record<string, any>>(oldDoc: T, newDoc: T, payload?: Partial<T>): Record<keyof T, {
11
12
  old: any;
12
13
  new: any;
@@ -37,3 +38,4 @@ export declare function publishAllShopsAvgPreperationTimeSyncProcessEvent(payloa
37
38
  export declare function publishSyncSingleShopInCacheProcessEvent(payload: SyncSingleShopCacheDTO): Promise<void>;
38
39
  export declare function publishSyncSingleShopOrderAgainSectionsInCacheProcessEvent(payload: SyncSingleShopOrderAgainCacheDTO): Promise<void>;
39
40
  export declare function publishSyncSingleShopSectionsInCacheProcessEvent(payload: SyncSingleShopSectionsInCacheDTO): Promise<void>;
41
+ export declare function publishAllCustomizedShopSectionsCacheProcessEvent(payload: SynchronizeAllCustomizedShopSectionsCacheDTO): Promise<void>;
@@ -13,6 +13,7 @@ exports.publishAllShopsAvgPreperationTimeSyncProcessEvent = publishAllShopsAvgPr
13
13
  exports.publishSyncSingleShopInCacheProcessEvent = publishSyncSingleShopInCacheProcessEvent;
14
14
  exports.publishSyncSingleShopOrderAgainSectionsInCacheProcessEvent = publishSyncSingleShopOrderAgainSectionsInCacheProcessEvent;
15
15
  exports.publishSyncSingleShopSectionsInCacheProcessEvent = publishSyncSingleShopSectionsInCacheProcessEvent;
16
+ exports.publishAllCustomizedShopSectionsCacheProcessEvent = publishAllCustomizedShopSectionsCacheProcessEvent;
16
17
  const event_1 = require("../libraries/event");
17
18
  const mongo_stream_changes_batch_process_shops_event_1 = require("../libraries/event/events/mongo-stream-changes-batch-process-shops-event");
18
19
  const admin_logs_event_1 = require("../libraries/event/events/admin-logs-event");
@@ -24,6 +25,7 @@ const sync_avg_prep_time_in_all_shops_event_1 = require("../libraries/event/even
24
25
  const sync_single_shop_in_cache_event_1 = require("../libraries/event/events/sync-single-shop-in-cache-event");
25
26
  const sync_order_again_sections_for_shop_event_1 = require("../libraries/event/events/sync-order-again-sections-for-shop-event");
26
27
  const sync_single_shop_sections_in_cache_event_1 = require("../libraries/event/events/sync-single-shop-sections-in-cache-event");
28
+ const sync_all_customized_shop_sections_cache_event_1 = require("../libraries/event/events/sync-all-customized-shop-sections-cache-event");
27
29
  function getChangedFields(oldDoc, newDoc, payload) {
28
30
  const changes = {};
29
31
  const oldObj = typeof oldDoc.toObject === 'function' ? oldDoc.toObject() : oldDoc;
@@ -120,4 +122,8 @@ async function publishSyncSingleShopSectionsInCacheProcessEvent(payload) {
120
122
  const syncSingleShopSectionsInCacheSyncEvent = new sync_single_shop_sections_in_cache_event_1.SyncSingleShopSectionsInCacheEvent(payload);
121
123
  await (0, event_1.publishEvent)(syncSingleShopSectionsInCacheSyncEvent);
122
124
  }
125
+ async function publishAllCustomizedShopSectionsCacheProcessEvent(payload) {
126
+ const SyncAllCustomizedShopSectionsCacheProcessEvent = new sync_all_customized_shop_sections_cache_event_1.SynchronizeAllCustomizedShopSectionsCacheEvent({});
127
+ await (0, event_1.publishEvent)(SyncAllCustomizedShopSectionsCacheProcessEvent);
128
+ }
123
129
  //# sourceMappingURL=events-common-methods.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"events-common-methods.js","sourceRoot":"/","sources":["utilities/events-common-methods.ts"],"names":[],"mappings":";;AAuCA,4CAyBC;AAwCD,sDAaC;AAKD,wDAKC;AAED,sDAcC;AAED,gFAIC;AAED,gHAMC;AAED,wGAIC;AAED,oGAIC;AAED,gHAMC;AAED,8GAMC;AAED,4FAKC;AAED,gIAMC;AAED,4GAMC;AA/MD,8CAAkD;AAGlD,6IAGkF;AAClF,iFAAoF;AACpF,+HAAuH;AACvH,uJAA6I;AAC7I,6HAG0E;AAC1E,6IAGkF;AAClF,2HAGyE;AACzE,+GAGmE;AACnE,iIAG4E;AAC5E,iIAG4E;AAK5E,SAAgB,gBAAgB,CAC/B,MAAS,EACT,MAAS,EACT,OAAoB;IAEpB,MAAM,OAAO,GAAG,EAA6C,CAAC;IAE9D,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAClF,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAElF,MAAM,WAAW,GAAG,OAAO;QAC1B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzE,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,Q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,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,IAAA,oBAAY,EAAC,sCAAsC,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { mongoose } from '@typegoose/typegoose';\nimport { publishEvent } from '../libraries/event';\nimport { AdminLogsUpdatedFieldsType } from './enum';\nimport { BaseEvent } from '../libraries/event/BaseEvent';\nimport {\n\tMongoStreamsBatchProcessShopsDTO,\n\tMongoStreamsBatchProcessShopsEvent,\n} from '../libraries/event/events/mongo-stream-changes-batch-process-shops-event';\nimport { AdminActivityLogsEvent } from '../libraries/event/events/admin-logs-event';\nimport { ShopActiveTimingsBatchProcessEvent } from '../libraries/event/events/shop-active-timings-batch-process-event';\nimport { BulkUpdateShopsSearchFieldsBatchProcessEvent } from '../libraries/event/events/bulk-update-shops-search-fields-batch-process-event';\nimport {\n\tBulkUpdateShopsZoneStatusDTO,\n\tBulkUpdateShopsZoneStatusEvent,\n} from '../libraries/event/events/bulk-update-zone-status-in-shops-event';\nimport {\n\tSynchronizeAllProductsProductMarketingInfoDTO,\n\tSynchronizeAllProductsProductMarketingInfoEvent,\n} from '../libraries/event/events/sync-all-products-product-marketing-info-event';\nimport {\n\tSynchronizeAllShopsAvgPreparationTimeDTO,\n\tSynchronizeAllShopsAvgPreparationTimeEvent,\n} from '../libraries/event/events/sync-avg-prep-time-in-all-shops-event';\nimport {\n\tSyncSingleShopCacheDTO,\n\tSyncSingleShopInCacheEvent,\n} from '../libraries/event/events/sync-single-shop-in-cache-event';\nimport {\n\tSyncSingleShopOrderAgainCacheDTO,\n\tSyncSingleShopOrderAgainInCacheEvent,\n} from '../libraries/event/events/sync-order-again-sections-for-shop-event';\nimport {\n\tSyncSingleShopSectionsInCacheDTO,\n\tSyncSingleShopSectionsInCacheEvent,\n} from '../libraries/event/events/sync-single-shop-sections-in-cache-event';\n\n/**\n * Returns changed fields between two objects (shallow comparison).\n */\nexport function getChangedFields<T extends Record<string, any>>(\n\toldDoc: T,\n\tnewDoc: T,\n\tpayload?: Partial<T>\n): Record<keyof T, { old: any; new: any }> {\n\tconst changes = {} as Record<keyof T, { old: any; new: any }>;\n\n\tconst oldObj = typeof oldDoc.toObject === 'function' ? oldDoc.toObject() : oldDoc;\n\tconst newObj = typeof newDoc.toObject === 'function' ? newDoc.toObject() : newDoc;\n\n\tconst keysToCheck = payload\n\t\t? Object.keys(payload)\n\t\t: Array.from(new Set([...Object.keys(oldObj), ...Object.keys(newObj)]));\n\n\tfor (const key of keysToCheck) {\n\t\tconst oldValue = oldObj[key];\n\t\tconst newValue = newObj[key];\n\t\tconst cleanedOld = deepCleanSettingsValues(oldValue);\n\t\tconst cleanedNew = deepCleanSettingsValues(newValue);\n\t\tif (payload || JSON.stringify(cleanedOld) !== JSON.stringify(cleanedNew)) {\n\t\t\tchanges[key as keyof T] = { old: oldValue, new: newValue };\n\t\t}\n\t}\n\n\treturn changes;\n}\n\n// removes _id and deletedAt fields from objects, array of objects and prepares for data that has setting changes\nfunction deepCleanSettingsValues(value: any): any {\n\t// CASE 1: Array\n\tif (Array.isArray(value)) {\n\t\t// If array contains primitives → return as-is\n\t\tif (value.every(v => v === null || typeof v !== 'object')) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// If array contains objects → deep clean each object\n\t\treturn value.map(item => deepCleanSettingsValues(item));\n\t}\n\n\t// CASE 2: Null → return as is\n\tif (value === null) return value;\n\n\t// CASE 3: Plain Object\n\tif (typeof value === 'object') {\n\t\tconst cleanedObj: any = {};\n\n\t\tfor (const key in value) {\n\t\t\tif (key === '_id' || key === 'deletedAt' || value[key] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcleanedObj[key] = deepCleanSettingsValues(value[key]);\n\t\t}\n\n\t\treturn cleanedObj;\n\t}\n\n\t// CASE 4: Primitive (string, number, boolean)\n\treturn value;\n}\n\n/**\n * Filters changed fields to only those that exist in the payload.\n */\nexport function filterRelevantChanges<T>(\n\tallChanges: Record<string, { old: any; new: any }>,\n\tpayload: Partial<T>\n): Record<string, { old: any; new: any }> {\n\treturn Object.keys(payload).reduce(\n\t\t(acc, key) => {\n\t\t\tif (allChanges[key]) {\n\t\t\t\tacc[key] = allChanges[key];\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, { old: any; new: any }>\n\t);\n}\n\n/**\n * Extracts either 'old' or 'new' values from the changes object.\n */\nexport function extractChangedDocument(\n\tchanges: Record<string, { old: any; new: any }>,\n\ttype: 'old' | 'new'\n): Record<string, any> {\n\treturn Object.fromEntries(Object.entries(changes).map(([key, value]) => [key, value[type]]));\n}\n\nexport async function publishAdminLogsEvent(payload: {\n\tadmin: mongoose.Types.ObjectId;\n\tupdatedField: AdminLogsUpdatedFieldsType;\n\toldDoc: any;\n\tnewDoc: any;\n}) {\n\tconst { admin, updatedField, oldDoc, newDoc } = payload;\n\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\tadmin: admin,\n\t\tupdatedField: updatedField,\n\t\toldDocument: oldDoc,\n\t\tnewDocument: newDoc,\n\t});\n\tawait publishEvent(adminActivityLogsEvent);\n}\n\nexport async function publishShopActiveBatchProcessEvent() {\n\tconst shopActiveTimingsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew ShopActiveTimingsBatchProcessEvent({});\n\tawait publishEvent(shopActiveTimingsBatchProcessEvent);\n}\n\nexport async function publishMongodbStreamsChangesBatchProcessShopsEvent(\n\tpayload: MongoStreamsBatchProcessShopsDTO\n) {\n\tconst mongodbStreamsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew MongoStreamsBatchProcessShopsEvent(payload);\n\tawait publishEvent(mongodbStreamsBatchProcessEvent);\n}\n\nexport async function publishUpdateShopsSearchFieldsBulkProcessEvent(payload: any) {\n\tconst bulkUpdateShopsSearchFieldsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew BulkUpdateShopsSearchFieldsBatchProcessEvent(payload);\n\tawait publishEvent(bulkUpdateShopsSearchFieldsBatchProcessEvent);\n}\n\nexport async function publishBulkUpdateShopsZoneStatusProcessEvent(payload: BulkUpdateShopsZoneStatusDTO) {\n\tconst shopsZoneStatusBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew BulkUpdateShopsZoneStatusEvent(payload);\n\tawait publishEvent(shopsZoneStatusBatchProcessEvent);\n}\n\nexport async function publishAllProductsProductMarketingInfoProcessEvent(\n\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n) {\n\tconst SyncAllProductsProductMarketingInfoProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SynchronizeAllProductsProductMarketingInfoEvent({});\n\tawait publishEvent(SyncAllProductsProductMarketingInfoProcessEvent);\n}\n\nexport async function publishAllShopsAvgPreperationTimeSyncProcessEvent(\n\tpayload: SynchronizeAllShopsAvgPreparationTimeDTO\n) {\n\tconst SyncAllShopsAvgPreperationTimeSyncProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SynchronizeAllShopsAvgPreparationTimeEvent({});\n\tawait publishEvent(SyncAllShopsAvgPreperationTimeSyncProcessEvent);\n}\n\nexport async function publishSyncSingleShopInCacheProcessEvent(payload: SyncSingleShopCacheDTO) {\n\tconst syncSingleShopCacheSyncEvent: BaseEvent<Record<string, unknown>> = new SyncSingleShopInCacheEvent(\n\t\tpayload\n\t);\n\tawait publishEvent(syncSingleShopCacheSyncEvent);\n}\n\nexport async function publishSyncSingleShopOrderAgainSectionsInCacheProcessEvent(\n\tpayload: SyncSingleShopOrderAgainCacheDTO\n) {\n\tconst syncSingleShopOrderAgainInCacheSyncEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SyncSingleShopOrderAgainInCacheEvent(payload);\n\tawait publishEvent(syncSingleShopOrderAgainInCacheSyncEvent);\n}\n\nexport async function publishSyncSingleShopSectionsInCacheProcessEvent(\n\tpayload: SyncSingleShopSectionsInCacheDTO\n) {\n\tconst syncSingleShopSectionsInCacheSyncEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SyncSingleShopSectionsInCacheEvent(payload);\n\tawait publishEvent(syncSingleShopSectionsInCacheSyncEvent);\n}\n"]}
1
+ {"version":3,"file":"events-common-methods.js","sourceRoot":"/","sources":["utilities/events-common-methods.ts"],"names":[],"mappings":";;AAwCA,4CAyBC;AAwCD,sDAaC;AAKD,wDAKC;AAED,sDAcC;AAED,gFAIC;AAED,gHAMC;AAED,wGAIC;AAED,oGAIC;AAED,gHAMC;AAED,8GAMC;AAED,4FAKC;AAED,gIAMC;AAED,4GAMC;AAED,8GAMC;AAxND,8CAAkD;AAGlD,6IAGkF;AAClF,iFAAoF;AACpF,+HAAuH;AACvH,uJAA6I;AAC7I,6HAG0E;AAC1E,6IAGkF;AAClF,2HAGyE;AACzE,+GAGmE;AACnE,iIAG4E;AAC5E,iIAG4E;AAC5E,2IAAuL;AAKvL,SAAgB,gBAAgB,CAC/B,MAAS,EACT,MAAS,EACT,OAAoB;IAEpB,MAAM,OAAO,GAAG,EAA6C,CAAC;IAE9D,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAClF,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAElF,MAAM,WAAW,GAAG,OAAO;QAC1B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzE,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MA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IAEzC,MAAM,sCAAsC,GAC3C,IAAI,6EAAkC,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,IAAA,oBAAY,EAAC,sCAAsC,CAAC,CAAC;AAC5D,CAAC;AAEM,KAAK,UAAU,iDAAiD,CACtE,OAAqD;IAErD,MAAM,8CAA8C,GACnD,IAAI,8FAA8C,CAAC,EAAE,CAAC,CAAC;IACxD,MAAM,IAAA,oBAAY,EAAC,8CAA8C,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { mongoose } from '@typegoose/typegoose';\nimport { publishEvent } from '../libraries/event';\nimport { AdminLogsUpdatedFieldsType } from './enum';\nimport { BaseEvent } from '../libraries/event/BaseEvent';\nimport {\n\tMongoStreamsBatchProcessShopsDTO,\n\tMongoStreamsBatchProcessShopsEvent,\n} from '../libraries/event/events/mongo-stream-changes-batch-process-shops-event';\nimport { AdminActivityLogsEvent } from '../libraries/event/events/admin-logs-event';\nimport { ShopActiveTimingsBatchProcessEvent } from '../libraries/event/events/shop-active-timings-batch-process-event';\nimport { BulkUpdateShopsSearchFieldsBatchProcessEvent } from '../libraries/event/events/bulk-update-shops-search-fields-batch-process-event';\nimport {\n\tBulkUpdateShopsZoneStatusDTO,\n\tBulkUpdateShopsZoneStatusEvent,\n} from '../libraries/event/events/bulk-update-zone-status-in-shops-event';\nimport {\n\tSynchronizeAllProductsProductMarketingInfoDTO,\n\tSynchronizeAllProductsProductMarketingInfoEvent,\n} from '../libraries/event/events/sync-all-products-product-marketing-info-event';\nimport {\n\tSynchronizeAllShopsAvgPreparationTimeDTO,\n\tSynchronizeAllShopsAvgPreparationTimeEvent,\n} from '../libraries/event/events/sync-avg-prep-time-in-all-shops-event';\nimport {\n\tSyncSingleShopCacheDTO,\n\tSyncSingleShopInCacheEvent,\n} from '../libraries/event/events/sync-single-shop-in-cache-event';\nimport {\n\tSyncSingleShopOrderAgainCacheDTO,\n\tSyncSingleShopOrderAgainInCacheEvent,\n} from '../libraries/event/events/sync-order-again-sections-for-shop-event';\nimport {\n\tSyncSingleShopSectionsInCacheDTO,\n\tSyncSingleShopSectionsInCacheEvent,\n} from '../libraries/event/events/sync-single-shop-sections-in-cache-event';\nimport { SynchronizeAllCustomizedShopSectionsCacheDTO, SynchronizeAllCustomizedShopSectionsCacheEvent } from '../libraries/event/events/sync-all-customized-shop-sections-cache-event';\n\n/**\n * Returns changed fields between two objects (shallow comparison).\n */\nexport function getChangedFields<T extends Record<string, any>>(\n\toldDoc: T,\n\tnewDoc: T,\n\tpayload?: Partial<T>\n): Record<keyof T, { old: any; new: any }> {\n\tconst changes = {} as Record<keyof T, { old: any; new: any }>;\n\n\tconst oldObj = typeof oldDoc.toObject === 'function' ? oldDoc.toObject() : oldDoc;\n\tconst newObj = typeof newDoc.toObject === 'function' ? newDoc.toObject() : newDoc;\n\n\tconst keysToCheck = payload\n\t\t? Object.keys(payload)\n\t\t: Array.from(new Set([...Object.keys(oldObj), ...Object.keys(newObj)]));\n\n\tfor (const key of keysToCheck) {\n\t\tconst oldValue = oldObj[key];\n\t\tconst newValue = newObj[key];\n\t\tconst cleanedOld = deepCleanSettingsValues(oldValue);\n\t\tconst cleanedNew = deepCleanSettingsValues(newValue);\n\t\tif (payload || JSON.stringify(cleanedOld) !== JSON.stringify(cleanedNew)) {\n\t\t\tchanges[key as keyof T] = { old: oldValue, new: newValue };\n\t\t}\n\t}\n\n\treturn changes;\n}\n\n// removes _id and deletedAt fields from objects, array of objects and prepares for data that has setting changes\nfunction deepCleanSettingsValues(value: any): any {\n\t// CASE 1: Array\n\tif (Array.isArray(value)) {\n\t\t// If array contains primitives → return as-is\n\t\tif (value.every(v => v === null || typeof v !== 'object')) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// If array contains objects → deep clean each object\n\t\treturn value.map(item => deepCleanSettingsValues(item));\n\t}\n\n\t// CASE 2: Null → return as is\n\tif (value === null) return value;\n\n\t// CASE 3: Plain Object\n\tif (typeof value === 'object') {\n\t\tconst cleanedObj: any = {};\n\n\t\tfor (const key in value) {\n\t\t\tif (key === '_id' || key === 'deletedAt' || value[key] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcleanedObj[key] = deepCleanSettingsValues(value[key]);\n\t\t}\n\n\t\treturn cleanedObj;\n\t}\n\n\t// CASE 4: Primitive (string, number, boolean)\n\treturn value;\n}\n\n/**\n * Filters changed fields to only those that exist in the payload.\n */\nexport function filterRelevantChanges<T>(\n\tallChanges: Record<string, { old: any; new: any }>,\n\tpayload: Partial<T>\n): Record<string, { old: any; new: any }> {\n\treturn Object.keys(payload).reduce(\n\t\t(acc, key) => {\n\t\t\tif (allChanges[key]) {\n\t\t\t\tacc[key] = allChanges[key];\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, { old: any; new: any }>\n\t);\n}\n\n/**\n * Extracts either 'old' or 'new' values from the changes object.\n */\nexport function extractChangedDocument(\n\tchanges: Record<string, { old: any; new: any }>,\n\ttype: 'old' | 'new'\n): Record<string, any> {\n\treturn Object.fromEntries(Object.entries(changes).map(([key, value]) => [key, value[type]]));\n}\n\nexport async function publishAdminLogsEvent(payload: {\n\tadmin: mongoose.Types.ObjectId;\n\tupdatedField: AdminLogsUpdatedFieldsType;\n\toldDoc: any;\n\tnewDoc: any;\n}) {\n\tconst { admin, updatedField, oldDoc, newDoc } = payload;\n\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\tadmin: admin,\n\t\tupdatedField: updatedField,\n\t\toldDocument: oldDoc,\n\t\tnewDocument: newDoc,\n\t});\n\tawait publishEvent(adminActivityLogsEvent);\n}\n\nexport async function publishShopActiveBatchProcessEvent() {\n\tconst shopActiveTimingsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew ShopActiveTimingsBatchProcessEvent({});\n\tawait publishEvent(shopActiveTimingsBatchProcessEvent);\n}\n\nexport async function publishMongodbStreamsChangesBatchProcessShopsEvent(\n\tpayload: MongoStreamsBatchProcessShopsDTO\n) {\n\tconst mongodbStreamsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew MongoStreamsBatchProcessShopsEvent(payload);\n\tawait publishEvent(mongodbStreamsBatchProcessEvent);\n}\n\nexport async function publishUpdateShopsSearchFieldsBulkProcessEvent(payload: any) {\n\tconst bulkUpdateShopsSearchFieldsBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew BulkUpdateShopsSearchFieldsBatchProcessEvent(payload);\n\tawait publishEvent(bulkUpdateShopsSearchFieldsBatchProcessEvent);\n}\n\nexport async function publishBulkUpdateShopsZoneStatusProcessEvent(payload: BulkUpdateShopsZoneStatusDTO) {\n\tconst shopsZoneStatusBatchProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew BulkUpdateShopsZoneStatusEvent(payload);\n\tawait publishEvent(shopsZoneStatusBatchProcessEvent);\n}\n\nexport async function publishAllProductsProductMarketingInfoProcessEvent(\n\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n) {\n\tconst SyncAllProductsProductMarketingInfoProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SynchronizeAllProductsProductMarketingInfoEvent({});\n\tawait publishEvent(SyncAllProductsProductMarketingInfoProcessEvent);\n}\n\nexport async function publishAllShopsAvgPreperationTimeSyncProcessEvent(\n\tpayload: SynchronizeAllShopsAvgPreparationTimeDTO\n) {\n\tconst SyncAllShopsAvgPreperationTimeSyncProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SynchronizeAllShopsAvgPreparationTimeEvent({});\n\tawait publishEvent(SyncAllShopsAvgPreperationTimeSyncProcessEvent);\n}\n\nexport async function publishSyncSingleShopInCacheProcessEvent(payload: SyncSingleShopCacheDTO) {\n\tconst syncSingleShopCacheSyncEvent: BaseEvent<Record<string, unknown>> = new SyncSingleShopInCacheEvent(\n\t\tpayload\n\t);\n\tawait publishEvent(syncSingleShopCacheSyncEvent);\n}\n\nexport async function publishSyncSingleShopOrderAgainSectionsInCacheProcessEvent(\n\tpayload: SyncSingleShopOrderAgainCacheDTO\n) {\n\tconst syncSingleShopOrderAgainInCacheSyncEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SyncSingleShopOrderAgainInCacheEvent(payload);\n\tawait publishEvent(syncSingleShopOrderAgainInCacheSyncEvent);\n}\n\nexport async function publishSyncSingleShopSectionsInCacheProcessEvent(\n\tpayload: SyncSingleShopSectionsInCacheDTO\n) {\n\tconst syncSingleShopSectionsInCacheSyncEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SyncSingleShopSectionsInCacheEvent(payload);\n\tawait publishEvent(syncSingleShopSectionsInCacheSyncEvent);\n}\n\nexport async function publishAllCustomizedShopSectionsCacheProcessEvent(\n\tpayload: SynchronizeAllCustomizedShopSectionsCacheDTO\n) {\n\tconst SyncAllCustomizedShopSectionsCacheProcessEvent: BaseEvent<Record<string, unknown>> =\n\t\tnew SynchronizeAllCustomizedShopSectionsCacheEvent({});\n\tawait publishEvent(SyncAllCustomizedShopSectionsCacheProcessEvent);\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.3.144",
3
+ "version": "1.3.146",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",