Skip to content

Commit 62eb65f

Browse files
authored
Merge branch 'next' into nv-5712-inbox-snooze-frontend-implementation-inbox
2 parents 54a2592 + 71c6acb commit 62eb65f

File tree

18 files changed

+130
-105
lines changed

18 files changed

+130
-105
lines changed

.source

apps/api/src/app/environments-v1/usecases/create-environment/create-environment.usecase.ts

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class CreateEnvironment {
108108
environmentId: environment._id,
109109
organizationId: environment._organizationId,
110110
userId: command.userId,
111+
name: environment.name,
111112
})
112113
);
113114

apps/api/src/app/events/events.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TerminusModule } from '@nestjs/terminus';
33

44
import { GetNovuProviderCredentials, StorageHelperService } from '@novu/application-generic';
55

6-
import { CommunityOrganizationRepository } from '@novu/dal';
6+
import { CommunityOrganizationRepository, CommunityUserRepository } from '@novu/dal';
77
import { EventsController } from './events.controller';
88
import { USE_CASES } from './usecases';
99

@@ -37,6 +37,6 @@ const PROVIDERS = [GetNovuProviderCredentials, StorageHelperService, CommunityOr
3737
BridgeModule,
3838
],
3939
controllers: [EventsController],
40-
providers: [...PROVIDERS, ...USE_CASES],
40+
providers: [...PROVIDERS, ...USE_CASES, CommunityUserRepository],
4141
})
4242
export class EventsModule {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { EnvironmentEnum } from '@novu/shared';
12
import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';
23

3-
export class CreateNovuIntegrationsCommand extends EnvironmentWithUserCommand {}
4+
export class CreateNovuIntegrationsCommand extends EnvironmentWithUserCommand {
5+
name: string | EnvironmentEnum;
6+
}

apps/api/src/app/integrations/usecases/create-novu-integrations/create-novu-integrations.usecase.ts

+6-43
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Injectable } from '@nestjs/common';
2+
import { areNovuEmailCredentialsSet, FeatureFlagsService } from '@novu/application-generic';
23
import { EnvironmentEntity, IntegrationRepository, OrganizationEntity, UserEntity } from '@novu/dal';
3-
import { areNovuEmailCredentialsSet, areNovuSmsCredentialsSet, FeatureFlagsService } from '@novu/application-generic';
44

55
import {
66
ChannelTypeEnum,
77
EmailProviderIdEnum,
8+
EnvironmentEnum,
89
FeatureFlagsKeysEnum,
910
InAppProviderIdEnum,
10-
SmsProviderIdEnum,
1111
} from '@novu/shared';
12-
import { CreateNovuIntegrationsCommand } from './create-novu-integrations.command';
13-
import { CreateIntegration } from '../create-integration/create-integration.usecase';
1412
import { CreateIntegrationCommand } from '../create-integration/create-integration.command';
15-
import { SetIntegrationAsPrimary } from '../set-integration-as-primary/set-integration-as-primary.usecase';
13+
import { CreateIntegration } from '../create-integration/create-integration.usecase';
1614
import { SetIntegrationAsPrimaryCommand } from '../set-integration-as-primary/set-integration-as-primary.command';
15+
import { SetIntegrationAsPrimary } from '../set-integration-as-primary/set-integration-as-primary.usecase';
16+
import { CreateNovuIntegrationsCommand } from './create-novu-integrations.command';
1717

1818
@Injectable()
1919
export class CreateNovuIntegrations {
@@ -25,7 +25,7 @@ export class CreateNovuIntegrations {
2525
) {}
2626

2727
private async createEmailIntegration(command: CreateNovuIntegrationsCommand) {
28-
if (!areNovuEmailCredentialsSet()) {
28+
if (!areNovuEmailCredentialsSet() || command.name !== EnvironmentEnum.DEVELOPMENT) {
2929
return;
3030
}
3131

@@ -60,42 +60,6 @@ export class CreateNovuIntegrations {
6060
}
6161
}
6262

63-
private async createSmsIntegration(command: CreateNovuIntegrationsCommand) {
64-
if (!areNovuSmsCredentialsSet()) {
65-
return;
66-
}
67-
68-
const smsIntegrationCount = await this.integrationRepository.count({
69-
providerId: SmsProviderIdEnum.Novu,
70-
channel: ChannelTypeEnum.SMS,
71-
_organizationId: command.organizationId,
72-
_environmentId: command.environmentId,
73-
});
74-
75-
if (smsIntegrationCount === 0) {
76-
const novuSmsIntegration = await this.createIntegration.execute(
77-
CreateIntegrationCommand.create({
78-
providerId: SmsProviderIdEnum.Novu,
79-
channel: ChannelTypeEnum.SMS,
80-
name: 'Novu SMS',
81-
active: true,
82-
check: false,
83-
userId: command.userId,
84-
environmentId: command.environmentId,
85-
organizationId: command.organizationId,
86-
})
87-
);
88-
await this.setIntegrationAsPrimary.execute(
89-
SetIntegrationAsPrimaryCommand.create({
90-
organizationId: command.organizationId,
91-
environmentId: command.environmentId,
92-
integrationId: novuSmsIntegration._id,
93-
userId: command.userId,
94-
})
95-
);
96-
}
97-
}
98-
9963
private async createInAppIntegration(command: CreateNovuIntegrationsCommand) {
10064
const inAppIntegrationCount = await this.integrationRepository.count({
10165
providerId: InAppProviderIdEnum.Novu,
@@ -131,7 +95,6 @@ export class CreateNovuIntegrations {
13195

13296
async execute(command: CreateNovuIntegrationsCommand): Promise<void> {
13397
await this.createEmailIntegration(command);
134-
await this.createSmsIntegration(command);
13598
await this.createInAppIntegration(command);
13699
}
137100
}

apps/api/src/app/organization/usecases/create-organization/sync-external-organization/sync-external-organization.usecase.ts

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class SyncExternalOrganization {
6060
environmentId: devEnv._id,
6161
organizationId: devEnv._organizationId,
6262
userId: user._id,
63+
name: devEnv.name,
6364
})
6465
);
6566

@@ -78,6 +79,7 @@ export class SyncExternalOrganization {
7879
environmentId: prodEnv._id,
7980
organizationId: prodEnv._organizationId,
8081
userId: user._id,
82+
name: prodEnv.name,
8183
})
8284
);
8385

apps/api/src/app/shared/framework/swagger/swagger.controller.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable max-len */
22
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger';
3+
import packageJson from '../../../../../package.json';
34
import { INestApplication } from '@nestjs/common';
45
import { SecuritySchemeObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
56
import { injectDocumentComponents } from './injection';
@@ -28,7 +29,7 @@ function buildBaseOptions() {
2829
const options = new DocumentBuilder()
2930
.setTitle('Novu API')
3031
.setDescription('Novu REST API. Please see https://docs.novu.co/api-reference for more details.')
31-
.setVersion('1.0')
32+
.setVersion(packageJson.version)
3233
.setContact('Novu Support', 'https://discord.gg/novu', '[email protected]')
3334
.setExternalDoc('Novu Documentation', 'https://docs.novu.co')
3435
.setTermsOfService('https://novu.co/terms')

apps/dashboard/src/components/integrations/components/integration-configuration.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,15 @@ export function IntegrationConfiguration({
143143
<InlineToast
144144
variant={'warning'}
145145
title="Demo Integration"
146-
description={`This is a demo integration intended for testing purposes only. It is limited to 300 ${
147-
provider?.channel === 'email' ? 'emails' : 'sms'
148-
} per month.`}
146+
description={`This is a demo ${
147+
provider?.channel === 'email' ? 'email' : 'SMS'
148+
} integration intended for testing purposes only. It is limited to 300 ${
149+
provider?.channel === 'email' ? 'messages' : 'SMS'
150+
} per month.${
151+
provider?.channel === 'email'
152+
? ' You can only send emails from it to the email address you are logged in with.'
153+
: ''
154+
}`}
149155
/>
150156
</div>
151157
) : (

apps/webhook/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ COPY --chown=1000:1000 --from=assets /usr/src/app .
4747
# Install production dependencies
4848
RUN --mount=type=cache,id=pnpm-store-webhook,target=/root/.pnpm-store \
4949
pnpm install --reporter=silent --filter "{${PACKAGE_PATH}}..." \
50-
--frozen-lockfile --unsafe-perm --prod --reporter=silent
50+
--frozen-lockfile --unsafe-perm --reporter=silent
5151

5252
# Set the working directory to the webhook app and start the application using pm2-runtime
5353
WORKDIR /usr/src/app/apps/webhook

apps/worker/src/app/workflow/usecases/send-message/send-message-email.usecase.ts

+32-26
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
import { Injectable, Logger } from '@nestjs/common';
22
import { ModuleRef } from '@nestjs/core';
3-
import inlineCss from 'inline-css';
43
import { addBreadcrumb } from '@sentry/node';
4+
import inlineCss from 'inline-css';
55

66
import {
7-
MessageRepository,
8-
SubscriberRepository,
7+
CompileEmailTemplate,
8+
CompileEmailTemplateCommand,
9+
CreateExecutionDetails,
10+
CreateExecutionDetailsCommand,
11+
DetailEnum,
12+
FeatureFlagsService,
13+
GetNovuProviderCredentials,
14+
InstrumentUsecase,
15+
MailFactory,
16+
SelectIntegration,
17+
SelectVariant,
18+
} from '@novu/application-generic';
19+
import {
20+
EnvironmentEntity,
921
EnvironmentRepository,
1022
IntegrationEntity,
11-
MessageEntity,
1223
LayoutRepository,
13-
EnvironmentEntity,
24+
MessageEntity,
25+
MessageRepository,
1426
OrganizationEntity,
27+
SubscriberRepository,
1528
UserEntity,
1629
} from '@novu/dal';
30+
import { EmailOutput } from '@novu/framework/internal';
1731
import {
1832
ChannelTypeEnum,
1933
EmailProviderIdEnum,
2034
ExecutionDetailsSourceEnum,
2135
ExecutionDetailsStatusEnum,
36+
FeatureFlagsKeysEnum,
2237
IAttachmentOptions,
2338
IEmailOptions,
24-
FeatureFlagsKeysEnum,
2539
} from '@novu/shared';
26-
import {
27-
InstrumentUsecase,
28-
DetailEnum,
29-
SelectIntegration,
30-
CompileEmailTemplate,
31-
CompileEmailTemplateCommand,
32-
MailFactory,
33-
GetNovuProviderCredentials,
34-
SelectVariant,
35-
CreateExecutionDetails,
36-
CreateExecutionDetailsCommand,
37-
FeatureFlagsService,
38-
} from '@novu/application-generic';
39-
import { EmailOutput } from '@novu/framework/internal';
4040

41-
import { SendMessageCommand } from './send-message.command';
42-
import { SendMessageBase } from './send-message.base';
4341
import { PlatformException } from '../../../shared/utils';
4442
import { SendMessageResult } from './send-message-type.usecase';
43+
import { SendMessageBase } from './send-message.base';
44+
import { SendMessageCommand } from './send-message.command';
4545

4646
const LOG_CONTEXT = 'SendMessageEmail';
4747

@@ -76,6 +76,8 @@ export class SendMessageEmail extends SendMessageBase {
7676
@InstrumentUsecase()
7777
public async execute(command: SendMessageCommand): Promise<SendMessageResult> {
7878
let integration: IntegrationEntity | undefined;
79+
const { subscriber } = command.compileContext;
80+
const email = command.overrides?.email?.toRecipient || subscriber.email;
7981

8082
const overrideSelectedIntegration = command.overrides?.email?.integrationIdentifier;
8183
try {
@@ -84,16 +86,23 @@ export class SendMessageEmail extends SendMessageBase {
8486
environmentId: command.environmentId,
8587
channelType: ChannelTypeEnum.EMAIL,
8688
userId: command.userId,
89+
recipientEmail: email,
8790
identifier: overrideSelectedIntegration as string,
8891
filterData: {
8992
tenant: command.job.tenant,
9093
},
9194
});
9295
} catch (e) {
96+
let detailEnum = DetailEnum.LIMIT_PASSED_NOVU_INTEGRATION;
97+
98+
if (e.message.includes('does not match the current logged-in user')) {
99+
detailEnum = DetailEnum.SUBSCRIBER_NOT_MEMBER_OF_ORGANIZATION;
100+
}
101+
93102
await this.createExecutionDetails.execute(
94103
CreateExecutionDetailsCommand.create({
95104
...CreateExecutionDetailsCommand.getDetailsFromJob(command.job),
96-
detail: DetailEnum.LIMIT_PASSED_NOVU_INTEGRATION,
105+
detail: detailEnum,
97106
source: ExecutionDetailsSourceEnum.INTERNAL,
98107
status: ExecutionDetailsStatusEnum.FAILED,
99108
raw: JSON.stringify({ message: e.message }),
@@ -113,9 +122,6 @@ export class SendMessageEmail extends SendMessageBase {
113122
if (!step) throw new PlatformException('Email channel step not found');
114123
if (!step.template) throw new PlatformException('Email channel template not found');
115124

116-
const { subscriber } = command.compileContext;
117-
const email = command.overrides?.email?.toRecipient || subscriber.email;
118-
119125
addBreadcrumb({
120126
message: 'Sending Email',
121127
});

apps/worker/src/app/workflow/usecases/send-message/send-message.base.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint-disable global-require */
2-
import i18next from 'i18next';
3-
import { ModuleRef } from '@nestjs/core';
42
import { Logger } from '@nestjs/common';
5-
import { format } from 'date-fns';
3+
import { ModuleRef } from '@nestjs/core';
64
import {
75
IntegrationEntity,
86
JobEntity,
@@ -19,6 +17,8 @@ import {
1917
ProvidersIdEnum,
2018
SmsProviderIdEnum,
2119
} from '@novu/shared';
20+
import { format } from 'date-fns';
21+
import i18next from 'i18next';
2222

2323
import {
2424
CreateExecutionDetails,
@@ -30,8 +30,8 @@ import {
3030
SelectVariant,
3131
SelectVariantCommand,
3232
} from '@novu/application-generic';
33-
import { SendMessageResult, SendMessageType } from './send-message-type.usecase';
3433
import { PlatformException } from '../../../shared/utils';
34+
import { SendMessageResult, SendMessageType } from './send-message-type.usecase';
3535
import { SendMessageCommand } from './send-message.command';
3636

3737
export abstract class SendMessageBase extends SendMessageType {
@@ -56,6 +56,7 @@ export abstract class SendMessageBase extends SendMessageType {
5656
environmentId: string;
5757
channelType: ChannelTypeEnum;
5858
userId: string;
59+
recipientEmail?: string;
5960
filterData: {
6061
tenant: ITenantDefine | undefined;
6162
};
@@ -73,6 +74,7 @@ export abstract class SendMessageBase extends SendMessageType {
7374
environmentId: integration._environmentId,
7475
organizationId: integration._organizationId,
7576
userId: params.userId,
77+
recipientEmail: params.recipientEmail,
7678
});
7779
}
7880

0 commit comments

Comments
 (0)