@punks/backend-entity-manager 0.0.46 → 0.0.48

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.
@@ -0,0 +1,5 @@
1
+ export declare const GlobalEvents: {
2
+ Messaging: {
3
+ EmailSent: string;
4
+ };
5
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./globalEvents";
2
+ export * from "./types";
@@ -0,0 +1,10 @@
1
+ export interface MessagingEmailSentPayload {
2
+ from?: string;
3
+ to?: string[];
4
+ cc?: string[];
5
+ bcc?: string[];
6
+ subject?: string;
7
+ body?: string;
8
+ payload?: any;
9
+ request?: any;
10
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./abstractions";
2
2
  export * from "./models";
3
+ export * from "./events";
3
4
  export * from "./platforms";
4
5
  export * from "./templates";
5
6
  export * from "./settings";
@@ -3,6 +3,7 @@ import { SendgridEmailTemplateData } from "../../abstractions";
3
3
  export declare class SendgridEmailProvider implements IEmailProvider<SendgridEmailTemplateData> {
4
4
  private readonly client;
5
5
  private readonly logger;
6
+ private readonly eventsService;
6
7
  constructor();
7
8
  sendTemplatedEmail<TPayload, TAugmentedPayload>(input: TemplatedEmailInput<TPayload>, template: IEmailTemplate<SendgridEmailTemplateData, TPayload, TAugmentedPayload>): Promise<void>;
8
9
  sendHtmlEmail<TPayload>(input: HtmlEmailInput<TPayload>): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { EntityManagerRegistry } from "../../ioc";
2
+ export declare class EventsService {
3
+ private readonly registry;
4
+ constructor(registry: EntityManagerRegistry);
5
+ emitEvent<TEventPayload>(eventName: string, eventPayload: TEventPayload): Promise<void>;
6
+ private get eventEmitter();
7
+ }
@@ -2,3 +2,4 @@ export { AppSessionService } from "./session";
2
2
  export { AppHashingService } from "./hashing";
3
3
  export { EntityManagerService } from "./manager";
4
4
  export { EmailService } from "./email";
5
+ export { EventsService } from "./events";
@@ -1,5 +1,6 @@
1
1
  import { EmailService } from "./email";
2
+ import { EventsService } from "./events";
2
3
  import { AppHashingService } from "./hashing";
3
4
  import { EntityManagerService } from "./manager";
4
5
  import { AppSessionService } from "./session";
5
- export declare const Services: (typeof AppSessionService | typeof AppHashingService | typeof EntityManagerService | typeof EmailService)[];
6
+ export declare const Services: (typeof AppSessionService | typeof AppHashingService | typeof EntityManagerService | typeof EmailService | typeof EventsService)[];
package/dist/esm/index.js CHANGED
@@ -79,6 +79,12 @@ var SortDirection;
79
79
  SortDirection["Desc"] = "desc";
80
80
  })(SortDirection || (SortDirection = {}));
81
81
 
82
+ const GlobalEvents = {
83
+ Messaging: {
84
+ EmailSent: "messaging:email.sent",
85
+ },
86
+ };
87
+
82
88
  class NestEntityAuthorizationMiddleware {
83
89
  }
84
90
 
@@ -18909,6 +18915,25 @@ EmailService = __decorate([
18909
18915
  __metadata("design:paramtypes", [EntityManagerRegistry])
18910
18916
  ], EmailService);
18911
18917
 
18918
+ let EventsService = class EventsService {
18919
+ constructor(registry) {
18920
+ this.registry = registry;
18921
+ }
18922
+ async emitEvent(eventName, eventPayload) {
18923
+ await this.eventEmitter.emit(eventName, eventPayload);
18924
+ }
18925
+ get eventEmitter() {
18926
+ return this.registry
18927
+ .getContainer()
18928
+ .getEntitiesServicesLocator()
18929
+ .resolveEventEmitter();
18930
+ }
18931
+ };
18932
+ EventsService = __decorate([
18933
+ Injectable(),
18934
+ __metadata("design:paramtypes", [EntityManagerRegistry])
18935
+ ], EventsService);
18936
+
18912
18937
  let AuthenticationServicesResolver = class AuthenticationServicesResolver {
18913
18938
  registerUsersService(usersService) {
18914
18939
  this.usersService = usersService;
@@ -19462,6 +19487,7 @@ const Services = [
19462
19487
  AppHashingService,
19463
19488
  EntityManagerService,
19464
19489
  EmailService,
19490
+ EventsService,
19465
19491
  ];
19466
19492
 
19467
19493
  const IoC = [EntityManagerRegistry];
@@ -25068,6 +25094,14 @@ let SendgridEmailProvider = class SendgridEmailProvider {
25068
25094
  });
25069
25095
  }
25070
25096
  await this.client.send(request);
25097
+ await this.eventsService.emitEvent(GlobalEvents.Messaging.EmailSent, {
25098
+ from: request.from,
25099
+ to: request.to,
25100
+ cc: request.cc,
25101
+ bcc: request.bcc,
25102
+ payload: processedPayload,
25103
+ request,
25104
+ });
25071
25105
  if (sendgridSettings.value.loggingEnabled) {
25072
25106
  this.logger.info("Templated email sent", {
25073
25107
  input,
@@ -25101,6 +25135,15 @@ let SendgridEmailProvider = class SendgridEmailProvider {
25101
25135
  });
25102
25136
  }
25103
25137
  await this.client.send(request);
25138
+ await this.eventsService.emitEvent(GlobalEvents.Messaging.EmailSent, {
25139
+ from: request.from,
25140
+ to: request.to,
25141
+ cc: request.cc,
25142
+ bcc: request.bcc,
25143
+ body: request.html,
25144
+ subject: request.subject,
25145
+ request,
25146
+ });
25104
25147
  if (sendgridSettings.value.loggingEnabled) {
25105
25148
  this.logger.info("Html email sent", {
25106
25149
  input,
@@ -25170,5 +25213,5 @@ AppSessionMiddleware = __decorate([
25170
25213
  Injectable()
25171
25214
  ], AppSessionMiddleware);
25172
25215
 
25173
- export { AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthenticationEmailTemplates, AuthenticationError, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsEmailModule, AwsSesEmailTemplate, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, InvalidCredentialsError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationTokenMismatchError, QueryBuilderBase, ReplicationMode, SendgridEmailModule, SendgridEmailTemplate, SortDirection, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpSendgridEmailTemplate, WpUserService, getLocalizedText, newUuid, renderHandlebarsTemplate };
25216
+ export { AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthenticationEmailTemplates, AuthenticationError, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsEmailModule, AwsSesEmailTemplate, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EventsService, GlobalEvents, InvalidCredentialsError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationTokenMismatchError, QueryBuilderBase, ReplicationMode, SendgridEmailModule, SendgridEmailTemplate, SortDirection, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpSendgridEmailTemplate, WpUserService, getLocalizedText, newUuid, renderHandlebarsTemplate };
25174
25217
  //# sourceMappingURL=index.js.map