Skip to content
Open
Changes from 2 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
28 changes: 26 additions & 2 deletions apps/api/src/app/environments-v1/novu-bridge-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Inject } from '@nestjs/common';
import {
GetDecryptedSecretKey,
GetDecryptedSecretKeyCommand,
InMemoryLRUCacheService,
InMemoryLRUCacheStore,
} from '@novu/application-generic';
import { PostActionEnum, type Workflow } from '@novu/framework/internal';
import { Client, NovuHandler, NovuRequestHandler } from '@novu/framework/nest';
import { EnvironmentTypeEnum } from '@novu/shared';
Expand All @@ -18,7 +24,9 @@ export const frameworkName = 'novu-nest';
export class NovuBridgeClient {
constructor(
@Inject(NovuHandler) private novuHandler: NovuHandler,
private constructFrameworkWorkflow: ConstructFrameworkWorkflow
private constructFrameworkWorkflow: ConstructFrameworkWorkflow,
private getDecryptedSecretKey: GetDecryptedSecretKey,
private inMemoryLRUCacheService: InMemoryLRUCacheService
) {}

public async handleRequest(req: Request, res: Response) {
Expand Down Expand Up @@ -46,10 +54,26 @@ export class NovuBridgeClient {
workflows.push(programmaticallyConstructedWorkflow);
}

const environmentId = req.params.environmentId;
const secretKey = (await this.inMemoryLRUCacheService.get(
InMemoryLRUCacheStore.VALIDATOR,
`bridge-secret-key:${environmentId}`,
() =>
this.getDecryptedSecretKey.execute(
GetDecryptedSecretKeyCommand.create({
environmentId,
})
),
{
environmentId,
cacheVariant: 'bridge-secret-key',
}
)) as string;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const novuRequestHandler = new NovuRequestHandler({
frameworkName,
workflows,
client: new Client({ secretKey: 'INTERNAL_KEY', strictAuthentication: false, verbose: false }),
client: new Client({ secretKey, strictAuthentication: true, verbose: false }),
handler: this.novuHandler.handler,
});

Expand Down
Loading