-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export
BrevoContactsService
to enable the application to add own ro…
…utes for subscribing to the brevo-contacts (#55) * add public api route to subscribe to brevo * export brevo contacts service and implement demo controller for subscribing with REST * remove prop for enablePublicApiSubscriptionRoute and update changelog * Update .changeset/cool-walls-drop.md: put empty line between first and second sentence Co-authored-by: Johannes Obermair <[email protected]> * use IsValidRedirectUrl instead of Validate(IsValidRedirectUrlConstraint) * add a comment and adapt changelog to indicate that the application should take care of recaptcha --------- Co-authored-by: Johannes Obermair <[email protected]>
- Loading branch information
1 parent
85af17c
commit 31f1241
Showing
12 changed files
with
110 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@comet/brevo-api": minor | ||
--- | ||
|
||
Export `BrevoContactsService` so that it can be used in the application | ||
|
||
This allows, for example, adding a custom REST request in the application to subscribe to the newsletter. The application should then add reCAPTCHA before calling the BrevoContactsService to prevent problems with bots. |
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
21 changes: 21 additions & 0 deletions
21
demo/api/src/brevo-contact/brevo-contact-subscribe.controller.ts
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,21 @@ | ||
import { BrevoContactsService, SubscribeResponse } from "@comet/brevo-api"; | ||
import { DisableGlobalGuard } from "@comet/cms-api"; | ||
import { Body, Controller, Post } from "@nestjs/common"; | ||
|
||
import { BrevoContactSubscribeInput } from "./dto/brevo-contact-subscribe.input"; | ||
|
||
@Controller("brevo-contacts") | ||
export class BrevoContactSubscribeController { | ||
constructor(private readonly brevoContactsService: BrevoContactsService) {} | ||
|
||
@DisableGlobalGuard() | ||
@Post(`/subscribe`) | ||
async subscribe(@Body() data: BrevoContactSubscribeInput): Promise<SubscribeResponse> { | ||
// Here, the application should add logic to handle reCAPTCHA verification | ||
// This ensures that the request is coming from a human and not a bot | ||
|
||
const { scope, ...input } = data; | ||
|
||
return this.brevoContactsService.subscribeBrevoContact(input, data.scope); | ||
} | ||
} |
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,8 @@ | ||
import { Module } from "@nestjs/common"; | ||
|
||
import { BrevoContactSubscribeController } from "./brevo-contact-subscribe.controller"; | ||
|
||
@Module({ | ||
controllers: [BrevoContactSubscribeController], | ||
}) | ||
export class BrevoContactSubscribeModule {} |
25 changes: 25 additions & 0 deletions
25
demo/api/src/brevo-contact/dto/brevo-contact-subscribe.input.ts
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,25 @@ | ||
import { IsValidRedirectURL } from "@comet/brevo-api"; | ||
import { Type } from "class-transformer"; | ||
import { IsEmail, IsNotEmpty, IsUrl, ValidateNested } from "class-validator"; | ||
|
||
import { BrevoContactAttributes } from "./brevo-contact-attributes"; | ||
import { EmailContactSubscribeScope } from "./brevo-contact-subscribe.scope"; | ||
|
||
export class BrevoContactSubscribeInput { | ||
@IsEmail() | ||
email: string; | ||
|
||
@IsUrl({ require_tld: process.env.NODE_ENV === "production" }) | ||
@IsValidRedirectURL() | ||
redirectionUrl: string; | ||
|
||
@ValidateNested() | ||
@Type(() => EmailContactSubscribeScope) | ||
@IsNotEmpty() | ||
scope: EmailContactSubscribeScope; | ||
|
||
@ValidateNested() | ||
@Type(() => BrevoContactAttributes) | ||
@IsNotEmpty() | ||
attributes: BrevoContactAttributes; | ||
} |
11 changes: 11 additions & 0 deletions
11
demo/api/src/brevo-contact/dto/brevo-contact-subscribe.scope.ts
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,11 @@ | ||
import { IsString, MaxLength } from "class-validator"; | ||
|
||
export class EmailContactSubscribeScope { | ||
@IsString() | ||
@MaxLength(64) | ||
domain: string; | ||
|
||
@IsString() | ||
@MaxLength(64) | ||
language: 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
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
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
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 +1,4 @@ | ||
export { BrevoContactsService } from "./brevo-contact/brevo-contacts.service"; | ||
export { SubscribeResponse } from "./brevo-contact/dto/subscribe-response.enum"; | ||
export { IsValidRedirectURL } from "./brevo-contact/validator/redirect-url.validator"; | ||
export { BrevoModule } from "./brevo-module"; |