-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-service): plain cards fetch user organizations (#7268)
Co-authored-by: Dima Grossman <[email protected]>
- Loading branch information
1 parent
4e502b8
commit 4914945
Showing
11 changed files
with
322 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class PlainCustomer { | ||
@ApiProperty() | ||
id: string; | ||
|
||
@ApiProperty() | ||
externalId?: string; | ||
|
||
@ApiProperty() | ||
email?: string; | ||
} | ||
|
||
export class PlainTenant { | ||
@ApiProperty() | ||
id?: string; | ||
|
||
@ApiProperty() | ||
externalId?: string; | ||
} | ||
|
||
export class PlainThread { | ||
@ApiProperty() | ||
id?: string; | ||
|
||
@ApiProperty() | ||
externalId?: string; | ||
} | ||
|
||
export class PlainCardRequestDto { | ||
@ApiProperty() | ||
cardKeys?: string[]; | ||
|
||
@ApiProperty() | ||
customer?: PlainCustomer | null; | ||
|
||
@ApiProperty() | ||
tenant?: PlainTenant | null; | ||
|
||
@ApiProperty() | ||
thread?: PlainThread | null; | ||
|
||
@ApiProperty() | ||
timestamp: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import crypto from 'node:crypto'; | ||
|
||
@Injectable() | ||
export class PlainCardsGuard implements CanActivate { | ||
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
|
||
const requestBody = JSON.stringify(request.body); | ||
const plainCardsHMACSecretKey = process.env.PLAIN_CARDS_HMAC_SECRET_KEY as string; | ||
const incomingSignature = request.headers['plain-request-signature']; | ||
if (!incomingSignature) throw new UnauthorizedException('Plain request signature is missing'); | ||
const expectedSignature = crypto.createHmac('sha-256', plainCardsHMACSecretKey).update(requestBody).digest('hex'); | ||
|
||
return incomingSignature === expectedSignature; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SupportService } from '@novu/application-generic'; | ||
import { OrganizationRepository } from '@novu/dal'; | ||
import { SupportController } from './support.controller'; | ||
import { SharedModule } from '../shared/shared.module'; | ||
import { CreateSupportThreadUsecase } from './usecases/create-thread.usecase'; | ||
import { CreateSupportThreadUsecase, PlainCardsUsecase } from './usecases'; | ||
import { PlainCardsGuard } from './guards/plain-cards.guard'; | ||
|
||
@Module({ | ||
imports: [SharedModule], | ||
controllers: [SupportController], | ||
providers: [CreateSupportThreadUsecase, SupportService], | ||
providers: [CreateSupportThreadUsecase, PlainCardsUsecase, SupportService, OrganizationRepository, PlainCardsGuard], | ||
}) | ||
export class SupportModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './create-thread.usecase'; | ||
export * from './plain-cards.usecase'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BaseCommand } from '@novu/application-generic'; | ||
import { IsArray, IsDefined, IsOptional, IsString } from 'class-validator'; | ||
import { PlainCustomer, PlainTenant, PlainThread } from '../dto/plain-card.dto'; | ||
|
||
export class PlainCardsCommand extends BaseCommand { | ||
@IsOptional() | ||
@IsArray() | ||
cardKeys?: string[]; | ||
|
||
@IsOptional() | ||
customer?: PlainCustomer | null; | ||
|
||
@IsOptional() | ||
tenant?: PlainTenant | null; | ||
|
||
@IsOptional() | ||
thread?: PlainThread | null; | ||
|
||
@IsDefined() | ||
@IsString() | ||
timestamp: string; | ||
} |
Oops, something went wrong.