Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IP Pool Name In Integration #3647

Merged
merged 2 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion apps/api/src/app/integrations/dtos/credentials.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsObject, IsOptional, IsString } from 'class-validator';
import { TransformToBoolean } from '../../shared/transformers/to-boolean';
import { ICredentials } from '@novu/shared';

export class CredentialsDto {
export class CredentialsDto implements ICredentials {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this addition implements:

  • is not helping with the compilation time with missing attributes because all of the attributes in ICredentials are optional.
  • it will alert in case we provide an invalid type.

@ApiPropertyOptional()
@IsString()
@IsOptional()
Expand Down Expand Up @@ -115,4 +116,24 @@ export class CredentialsDto {
@IsString()
@IsOptional()
webhookUrl?: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing attributes that i located due the implements ICredentials (in a hacky way)

@ApiPropertyOptional()
@IsString()
@IsOptional()
redirectUrl?: string;

@ApiPropertyOptional()
@IsBoolean()
@IsOptional()
hmac?: boolean;

@ApiPropertyOptional()
@IsString()
@IsOptional()
serviceAccount?: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
ipPoolName?: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IsDefined, IsOptional, IsString, IsBoolean } from 'class-validator';
import { ICredentials } from '@novu/dal';
import { IsDefined, IsString } from 'class-validator';
import { EnvironmentCommand } from '../../../shared/commands/project.command';
import { ChannelTypeEnum } from '@novu/shared';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';

export class CheckIntegrationCommand extends EnvironmentCommand {
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';

import { ChannelTypeEnum } from '@novu/stateless';
import { IntegrationEntity, IntegrationRepository, EnvironmentRepository, ICredentials } from '@novu/dal';
import { IntegrationEntity, IntegrationRepository, EnvironmentRepository, ICredentialsEntity } from '@novu/dal';

import { ChatOauthCommand } from './chat-oauth.command';
import { createHash } from '../../../shared/helpers/hmac.service';
Expand Down Expand Up @@ -60,7 +60,7 @@ export class ChatOauth {
return `${this.SLACK_OAUTH_URL}client_id=${clientId}&scope=incoming-webhook&user_scope=&redirect_uri=${redirectUri}`;
}

private async getCredentials(command: ChatOauthCommand): Promise<ICredentials> {
private async getCredentials(command: ChatOauthCommand): Promise<ICredentialsEntity> {
const query: Partial<IntegrationEntity> & { _environmentId: string } = {
_environmentId: command.environmentId,
channel: ChannelTypeEnum.CHAT,
Expand Down
29 changes: 2 additions & 27 deletions apps/web/src/pages/integrations/IntegrationsStoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InAppProviderIdEnum,
ProvidersIdEnum,
SmsProviderIdEnum,
ICredentials,
} from '@novu/shared';

import { useAuthController, useEnvController } from '../../hooks';
Expand All @@ -18,7 +19,7 @@ import { NovuInAppProviderModal } from './components/NovuInAppProviderModal';
import { ChannelGroup } from './components/Modal/ChannelGroup';
import { colors, shadows, Title } from '../../design-system';
import { ConnectIntegrationForm } from './components/Modal/ConnectIntegrationForm';
import { Close } from '../../design-system/icons/actions/Close';
import { Close } from '../../design-system/icons';
import { useProviders } from './useProviders';
import { useSegment } from '../../components/providers/SegmentProvider';
import { IntegrationsStoreModalAnalytics } from './constants';
Expand Down Expand Up @@ -328,32 +329,6 @@ export interface IIntegratedProvider {
novu?: boolean;
}

export interface ICredentials {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

apiKey?: string;
user?: string;
secretKey?: string;
domain?: string;
password?: string;
host?: string;
port?: string;
secure?: boolean;
region?: string;
accountSid?: string;
messageProfileId?: string;
token?: string;
from?: string;
senderName?: string;
applicationId?: string;
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
}

export interface IntegrationEntity {
_id?: string;

Expand Down
29 changes: 1 addition & 28 deletions apps/web/src/pages/integrations/IntegrationsStorePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InAppProviderIdEnum,
ProvidersIdEnum,
SmsProviderIdEnum,
ICredentials,
} from '@novu/shared';

import PageHeader from '../../components/layout/components/PageHeader';
Expand Down Expand Up @@ -152,34 +153,6 @@ export interface IIntegratedProvider {
novu?: boolean;
}

export interface ICredentials {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

apiKey?: string;
user?: string;
secretKey?: string;
domain?: string;
password?: string;
host?: string;
port?: string;
secure?: boolean;
region?: string;
accountSid?: string;
messageProfileId?: string;
token?: string;
from?: string;
senderName?: string;
applicationId?: string;
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
redirectUrl?: string;
hmac?: boolean;
}

export interface IntegrationEntity {
_id?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ChannelTypeEnum, ICredentialsDto, IConfigCredentials } from '@novu/shar
import { Button, colors, Input, Switch, Text } from '../../../design-system';
import { IIntegratedProvider } from '../IntegrationsStorePage';
import { createIntegration, getWebhookSupportStatus, updateIntegration } from '../../../api/integration';
import { Close } from '../../../design-system/icons/actions/Close';
import { Close } from '../../../design-system/icons';
import { IntegrationInput } from './IntegrationInput';
import { IS_DOCKER_HOSTED, WEBHOOK_URL } from '../../../config';
import { useEnvController, useAuthController } from '../../../hooks';
Expand Down
35 changes: 4 additions & 31 deletions libs/dal/src/repositories/integration/integration.entity.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
import { ChannelTypeEnum } from '@novu/shared';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';

import type { EnvironmentId } from '../environment';
import type { OrganizationId } from '../organization';
import { ChangePropsValueType } from '../../types/helpers';

export interface ICredentials {
apiKey?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

user?: string;
secretKey?: string;
domain?: string;
password?: string;
host?: string;
port?: string;
secure?: boolean;
region?: string;
accountSid?: string;
messageProfileId?: string;
token?: string;
from?: string;
senderName?: string;
applicationId?: string;
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
ipPoolName?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
redirectUrl?: string;
hmac?: boolean;
}

export class IntegrationEntity {
_id: string;

Expand All @@ -44,7 +15,7 @@ export class IntegrationEntity {

channel: ChannelTypeEnum;

credentials: ICredentials;
credentials: ICredentialsEntity;

active: boolean;

Expand All @@ -59,4 +30,6 @@ export class IntegrationEntity {
deletedBy: string;
}

export type ICredentialsEntity = ICredentials;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was not sure what to call this one :/
because it is basically a type of interface, i left the I for now.
any thoughts about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to keep the "Entity" separation so we will have it in code. because one can change while the other one may not.

export type IntegrationDBModel = ChangePropsValueType<IntegrationEntity, '_environmentId' | '_organizationId'>;
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const integrationSchema = new Schema<IntegrationDBModel>(
tlsOptions: Schema.Types.Mixed,
redirectUrl: Schema.Types.String,
hmac: Schema.Types.Boolean,
ipPoolName: Schema.Types.String,
},
active: {
type: Schema.Types.Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ export const sendgridConfig: IConfigCredentials[] = [
type: 'string',
required: true,
},
{
key: CredentialsKeyEnum.IpPoolName,
displayName: 'IP Pool Name',
type: 'string',
required: false,
},
...mailConfigBase,
];

Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/consts/providers/provider.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum CredentialsKeyEnum {
TlsOptions = 'tlsOptions',
RedirectUrl = 'redirectUrl',
Hmac = 'hmac',
IpPoolName = 'ipPoolName',
}

export enum EmailProviderIdEnum {
Expand Down
30 changes: 3 additions & 27 deletions libs/shared/src/dto/integration/construct-integration.interface.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
export interface ICredentialsDto {
apiKey?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

user?: string;
secretKey?: string;
domain?: string;
password?: string;
host?: string;
port?: string;
secure?: boolean;
hmac?: boolean;
region?: string;
accountSid?: string;
messageProfileId?: string;
token?: string;
from?: string;
senderName?: string;
applicationId?: string;
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
webhookUrl?: string;
redirectUrl?: string;
}
import { ICredentials } from '../../entities/integration';

export type ICredentialsDto = ICredentials;

export interface IConstructIntegrationDto {
credentials: ICredentialsDto;
Expand Down
28 changes: 28 additions & 0 deletions libs/shared/src/entities/integration/credential.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export interface ICredentials {
apiKey?: string;
user?: string;
secretKey?: string;
domain?: string;
password?: string;
host?: string;
port?: string;
secure?: boolean;
region?: string;
accountSid?: string;
messageProfileId?: string;
token?: string;
from?: string;
senderName?: string;
applicationId?: string;
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
redirectUrl?: string;
hmac?: boolean;
ipPoolName?: string;
}
1 change: 1 addition & 0 deletions libs/shared/src/entities/integration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './credential.interface';
1 change: 1 addition & 0 deletions libs/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './entities/subscriber-preference';
export * from './entities/subscriber';
export * from './entities/layout';
export * from './entities/notification-group';
export * from './entities/integration';
export * from './types';
export * from './dto';
export * from './consts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentials } from '@novu/dal';
import { ICredentials } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the shared one will do the work in the provider's packages.

import { BaseChatHandler } from './base.handler';
import { DiscordProvider } from '@novu/discord';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentials } from '@novu/dal';
import { ICredentials } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
import { BaseChatHandler } from './base.handler';
import { MattermostProvider } from '@novu/mattermost';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentials } from '@novu/dal';
import { ICredentials } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
import { BaseChatHandler } from './base.handler';
import { MsTeamsProvider } from '@novu/ms-teams';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentials } from '@novu/dal';
import { ICredentials } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
import { SlackProvider } from '@novu/slack';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IChatOptions, ISendMessageSuccessResponse } from '@novu/stateless';
import { ICredentials, IntegrationEntity } from '@novu/dal';
import { ChannelTypeEnum } from '@novu/shared';
import { IntegrationEntity } from '@novu/dal';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';

export interface IChatHandler {
canHandle(providerId: string, channelType: ChannelTypeEnum);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChannelTypeEnum } from '@novu/shared';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { EmailWebhookProvider } from '@novu/email-webhook';
import { ICredentials } from '@novu/dal';
import { BaseHandler } from './base.handler';
export class EmailWebhookHandler extends BaseHandler {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IEmailJsConfig } from '@novu/emailjs/build/main/lib/emailjs.config';
import { EmailJsProvider } from '@novu/emailjs';
import { ChannelTypeEnum } from '@novu/shared';
import { ICredentials } from '@novu/dal';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { BaseHandler } from './base.handler';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InfobipEmailProvider } from '@novu/infobip';
import { ChannelTypeEnum } from '@novu/shared';
import { ICredentials } from '@novu/dal';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { BaseHandler } from './base.handler';

export class InfobipEmailHandler extends BaseHandler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChannelTypeEnum } from '@novu/shared';
import { ICredentials } from '@novu/dal';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { MailersendEmailProvider } from '@novu/mailersend';

import { BaseHandler } from './base.handler';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MailgunEmailProvider } from '@novu/mailgun';
import { ChannelTypeEnum } from '@novu/shared';
import { ICredentials } from '@novu/dal';
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { BaseHandler } from './base.handler';

export class MailgunHandler extends BaseHandler {
Expand Down
Loading
Loading