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

feat: Add Push Webhook provider #3266

Merged
merged 19 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
85ca51b
feat(push-webhook): Adding Push webhook integration
TNAJanssen Apr 20, 2023
97aae52
feat(push-webhook): Adding Push webhook integration
TNAJanssen Apr 20, 2023
0eb5fd5
feat(push-webhook): Adding Push webhook integration
TNAJanssen Apr 20, 2023
b3cd620
feat(push-webhook): Adding Push webhook integration
TNAJanssen Apr 20, 2023
148cafa
feat(push-webhook): Adding Push webhook logo
TNAJanssen Apr 21, 2023
5d7ede4
feat(push-webhook): Adding tests
TNAJanssen Apr 21, 2023
57eb992
Merge branch 'next' into feature/webhook-push-provider
TNAJanssen Apr 21, 2023
11c2946
Merge remote-tracking branch 'origin/next' into feature/webhook-push-…
TNAJanssen Apr 28, 2023
9ff1102
Update providers/push-webhook/package.json
TNAJanssen May 2, 2023
c738678
feat(push-webhook): Make changes suggested with pull request
TNAJanssen May 3, 2023
98416f7
Update packages/application-generic/src/factories/push/handlers/push-…
TNAJanssen May 4, 2023
291626e
Merge branch 'next' into feature/webhook-push-provider
May 4, 2023
27d61f4
Update libs/shared/src/dto/integration/construct-integration.interfac…
May 4, 2023
09b85ca
Update providers/push-webhook/package.json
TNAJanssen May 4, 2023
4432380
Merge branch 'next' into feature/webhook-push-provider
TNAJanssen May 4, 2023
b2ee47b
Merge branch 'next' into feature/webhook-push-provider
TNAJanssen May 4, 2023
5f9bf24
Merge branch 'next' into feature/webhook-push-provider
May 4, 2023
05d75b0
Update libs/shared/src/consts/providers/credentials/provider-credenti…
May 4, 2023
e57e262
Update libs/shared/src/consts/providers/credentials/provider-credenti…
May 4, 2023
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
4 changes: 4 additions & 0 deletions apps/api/src/app/integrations/dtos/credentials.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ export class CredentialsDto {
ignoreTls?: boolean;
@ApiPropertyOptional()
tlsOptions?: Record<string, unknown>;
@ApiPropertyOptional()
baseUrl?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I find baseUrl could be a bit confusing. And as it is a specific credential property added for this feature what do you think of naming it pushWebhookUrl? I was going to suggest webhookUrl in case we wanted in the future something similar with the other channels, but not sure if that's a direction we will want to take.
@scopsy your thoughts about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah i used the same as the other webhook proposal. I can change it to whatever you prefer :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@p-fernandez iirc, I think it was listed as a credential property somewhere but not totally implemented. (this is why i used this property naming but could rename it to whatever you want btw)

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 changed to the already existing webhookUrl

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I realised that baseUrl is used for other purposes for the providers (for example when the provider needs to set a certain URL depending on the account / API key). So I think this change is a good one. 👍🏻

@ApiPropertyOptional()
webhookUrl?: string;
}
57 changes: 57 additions & 0 deletions apps/web/public/static/images/providers/dark/push-webhook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions apps/web/public/static/images/providers/light/push-webhook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/web/src/pages/integrations/IntegrationsStoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ export interface ICredentials {
clientId?: string;
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export interface ICredentials {
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ICredentials {
projectName?: string;
serviceAccount?: string;
baseUrl?: string;
webhookUrl?: string;
ipPoolName?: string;
requireTls?: boolean;
ignoreTls?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const integrationSchema = new Schema<IntegrationDBModel>(
projectName: Schema.Types.String,
serviceAccount: Schema.Types.String,
baseUrl: Schema.Types.String,
webhookUrl: Schema.Types.String,
requireTls: Schema.Types.Boolean,
ignoreTls: Schema.Types.Boolean,
tlsOptions: Schema.Types.Mixed,
Expand Down
11 changes: 10 additions & 1 deletion libs/shared/src/consts/providers/channels/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apnsConfig, fcmConfig, expoConfig } from '../credentials';
import { apnsConfig, fcmConfig, expoConfig, pushWebhookConfig } from '../credentials';
import { PushProviderIdEnum } from '../provider.enum';
import { IProviderConfig } from '../provider.interface';

Expand Down Expand Up @@ -30,4 +30,13 @@ export const pushProviders: IProviderConfig[] = [
logoFileName: { light: 'apns.png', dark: 'apns.png' },
betaVersion: true,
},
{
id: PushProviderIdEnum.PushWebhook,
displayName: 'Push Webhook',
channel: ChannelTypeEnum.PUSH,
credentials: pushWebhookConfig,
docReference: 'https://docs.novu.co/channels/push/webhook',
logoFileName: { light: 'push-webhook.svg', dark: 'push-webhook.svg' },
betaVersion: true,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,24 @@ export const expoConfig: IConfigCredentials[] = [
...pushConfigBase,
];

export const pushWebhookConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.WebhookUrl,
displayName: 'Webhook URL',
type: 'string',
description: 'the webhook URL to call to trigger push notifications',
required: true,
},
{
key: CredentialsKeyEnum.SecretKey,
displayName: 'Secret Hmac Key',
type: 'string',
description: 'the secret used to sign webhooks calls',
p-fernandez marked this conversation as resolved.
Show resolved Hide resolved
required: true,
},
...pushConfigBase,
];

export const apnsConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.SecretKey,
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 @@ -77,6 +77,7 @@ export enum PushProviderIdEnum {
FCM = 'fcm',
APNS = 'apns',
EXPO = 'expo',
PushWebhook = 'push-webhook',
}

export enum InAppProviderIdEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export interface ICredentialsDto {
requireTls?: boolean;
ignoreTls?: boolean;
tlsOptions?: Record<string, unknown>;
webhookUrl?: string;
redirectUrl?: string;
}

export interface IConstructIntegrationDto {
credentials: ICredentialsDto;

Expand Down
1 change: 1 addition & 0 deletions packages/application-generic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@novu/outlook365": "^0.14.0",
"@novu/plivo": "^0.14.0",
"@novu/postmark": "^0.14.0",
"@novu/push-webhook": "^0.14.0",
"@novu/resend": "^0.14.0",
"@novu/sendgrid": "^0.14.0",
"@novu/sendinblue": "^0.14.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './apns.handler';
export * from './expo.handler';
export * from './push-webhook.handler';
export * from './fcm.handler';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ChannelTypeEnum } from '@novu/shared';
import { PushWebhookPushProvider } from '@novu/push-webhook';
import { BasePushHandler } from './base.handler';
import { ICredentials } from '@novu/dal';

export class PushWebhookHandler extends BasePushHandler {
constructor() {
super('push-webhook', ChannelTypeEnum.PUSH);
}

buildProvider(credentials: ICredentials) {
if (!credentials.webhookUrl || !credentials.secretKey) {
throw Error('Config is not valid for push-webhook provider');
}

this.provider = new PushWebhookPushProvider({
webhookUrl: credentials.webhookUrl,
hmacSecretKey: credentials.secretKey,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { IntegrationEntity } from '@novu/dal';
import { IPushFactory, IPushHandler } from './interfaces';
import { APNSHandler, FCMHandler, ExpoHandler } from './handlers';
import {
APNSHandler,
FCMHandler,
ExpoHandler,
PushWebhookHandler,
} from './handlers';

export class PushFactory implements IPushFactory {
handlers: IPushHandler[] = [
new FCMHandler(),
new ExpoHandler(),
new APNSHandler(),
new PushWebhookHandler(),
];

getHandler(integration: IntegrationEntity) {
Expand Down
48 changes: 47 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion providers/postmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"dependencies": {
"@novu/stateless": "^0.14.0",
"postmark": "^2.7.8"
"postmark": "^2.7.8",
"axios": "^1.3.6"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "1.0.2",
Expand Down
3 changes: 3 additions & 0 deletions providers/push-webhook/.czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
3 changes: 3 additions & 0 deletions providers/push-webhook/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
9 changes: 9 additions & 0 deletions providers/push-webhook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/*
.nyc_output
build
node_modules
test
src/**.js
coverage
*.log
package-lock.json
Loading
Loading