diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea1619b2416..794e2d8b681 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ You can open a new issue with this [issue form](https://github.com/novuhq/novu/i ### Requirements -- Node.js version v14.19.3 +- Node.js version v16.15.1 - MongoDB - Redis. To install Redis on your O.S, please follow the below guides - [To install Redis on Windows](https://redis.io/docs/getting-started/installation/install-redis-on-windows/) diff --git a/apps/api/src/app/shared/helpers/content.service.spec.ts b/apps/api/src/app/shared/helpers/content.service.spec.ts index 1dd0833410d..70f80455447 100644 --- a/apps/api/src/app/shared/helpers/content.service.spec.ts +++ b/apps/api/src/app/shared/helpers/content.service.spec.ts @@ -335,4 +335,99 @@ describe('ContentService', function () { expect(extractVariables[0].name).to.include('lastName'); }); }); + + describe('extractStepVariables', () => { + it('should not fail if no filters available', () => { + const contentService = new ContentService(); + const messages = [ + { + template: { + type: StepTypeEnum.EMAIL, + subject: 'Test {{subscriber.firstName}}', + content: [ + { + content: 'Test of {{subscriber.firstName}} {{lastName}}', + type: 'text', + }, + ], + }, + }, + ] as INotificationTemplateStep[]; + const variables = contentService.extractStepVariables(messages); + + expect(variables.length).to.equal(0); + }); + + it('should not fail if filters are set as non array', () => { + const contentService = new ContentService(); + const messages = [ + { + template: { + type: StepTypeEnum.EMAIL, + subject: 'Test {{subscriber.firstName}}', + content: [ + { + content: 'Test of {{subscriber.firstName}} {{lastName}}', + type: 'text', + }, + ], + }, + filters: {}, + }, + ] as INotificationTemplateStep[]; + const variables = contentService.extractStepVariables(messages); + + expect(variables.length).to.equal(0); + }); + + it('should not fail if filters are an empty array', () => { + const contentService = new ContentService(); + const messages = [ + { + template: { + type: StepTypeEnum.EMAIL, + subject: 'Test {{subscriber.firstName}}', + content: [ + { + content: 'Test of {{subscriber.firstName}} {{lastName}}', + type: 'text', + }, + ], + }, + filters: [], + }, + ] as INotificationTemplateStep[]; + const variables = contentService.extractStepVariables(messages); + + expect(variables.length).to.equal(0); + }); + + it('should not fail if filters have some wrong settings like missing children in filters', () => { + const contentService = new ContentService(); + const messages = [ + { + template: { + type: StepTypeEnum.EMAIL, + subject: 'Test {{subscriber.firstName}}', + content: [ + { + content: 'Test of {{subscriber.firstName}} {{lastName}}', + type: 'text', + }, + ], + }, + filters: [ + { + isNegated: false, + type: 'GROUP', + value: 'AND', + }, + ], + }, + ] as INotificationTemplateStep[]; + const variables = contentService.extractStepVariables(messages); + + expect(variables.length).to.equal(0); + }); + }); }); diff --git a/apps/api/src/app/shared/helpers/content.service.ts b/apps/api/src/app/shared/helpers/content.service.ts index 6dfcff38f89..4e5c14d9730 100644 --- a/apps/api/src/app/shared/helpers/content.service.ts +++ b/apps/api/src/app/shared/helpers/content.service.ts @@ -73,17 +73,19 @@ export class ContentService { for (const message of messages) { if (message.filters) { - const filterVariables = message.filters.flatMap((filter) => - filter.children - .filter((item) => item.on === FilterPartTypeEnum.PAYLOAD) - .map((item: IFieldFilterPart) => { - return { - name: item.field, - type: TemplateVariableTypeEnum.STRING, - }; - }) - ); - variables.push(...filterVariables); + const filters = Array.isArray(message.filters) ? message.filters : []; + const filteredVariables = filters.flatMap((filter) => { + const filteredChildren = filter.children?.filter((item) => item.on === FilterPartTypeEnum.PAYLOAD) || []; + const mappedChildren = filteredChildren.map((item: IFieldFilterPart) => { + return { + name: item.field, + type: TemplateVariableTypeEnum.STRING, + }; + }); + + return mappedChildren; + }); + variables.push(...filteredVariables); } if (message.metadata?.type === DelayTypeEnum.SCHEDULED && message.metadata.delayPath) { diff --git a/providers/nodemailer/src/lib/nodemailer.provider.ts b/providers/nodemailer/src/lib/nodemailer.provider.ts index 7c52a221827..0d929257159 100644 --- a/providers/nodemailer/src/lib/nodemailer.provider.ts +++ b/providers/nodemailer/src/lib/nodemailer.provider.ts @@ -44,6 +44,7 @@ export class NodemailerProvider implements IEmailProvider { const tls: ConnectionOptions = this.getTlsOptions(); const smtpTransportOptions: SMTPTransport.Options = { + name: this.config.host, host: this.config.host, port: this.config.port, secure: this.config.secure,