From e82d15928c79e3c4506f54864a0bc307d85f8b40 Mon Sep 17 00:00:00 2001 From: chvarkov Date: Sat, 15 Apr 2023 01:19:19 +0000 Subject: [PATCH 1/3] docs: readme adjustments. --- README.md | 117 +++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index d14fe86..9a5ccd8 100644 --- a/README.md +++ b/README.md @@ -290,58 +290,9 @@ export class AppModule { ## Usage -### Validate in service - -```typescript -@Injectable() -export class SomeService { - constructor(private readonly recaptchaValidator: GoogleRecaptchaValidator) { - } - - async someAction(recaptchaToken: string): Promise { - const result = await this.recaptchaValidator.validate({ - response: recaptchaToken, - score: 0.8, - action: 'SomeAction', - }); - - if (!result.success) { - throw new GoogleRecaptchaException(result.errors); - } - // TODO: Your implemetation - } -} -``` - -### Validate in service (Enterprise) - -```typescript -@Injectable() -export class SomeService { - constructor(private readonly recaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator) { - } - - async someAction(recaptchaToken: string): Promise { - const result = await this.recaptchaEnterpriseValidator.validate({ - response: recaptchaToken, - score: 0.8, - action: 'SomeAction', - }); - - if (!result.success) { - throw new GoogleRecaptchaException(result.errors); - } - - const riskAnalytics = result.getEnterpriseRiskAnalytics(); - - // TODO: Your implemetation - } -} -``` - ### Usage in REST application -Use `@Recaptcha` decorator to protect your endpoints. +To protect your REST endpoints, you can use the `@Recaptcha` decorator.
Example: ```typescript @@ -356,7 +307,7 @@ export class FeedbackController { ``` -You can override default property that contain recaptcha for specific endpoint. +You can also override the default property that contains reCAPTCHA for a specific endpoint.
```typescript @@ -371,7 +322,7 @@ export class FeedbackController { ``` -Also you can override recaptcha v3 options. +Additionally, you can override reCAPTCHA v3 options.
```typescript @@ -386,7 +337,7 @@ export class FeedbackController { ``` -Get verification result +To get the verification result, you can use the @RecaptchaResult() decorator.
```typescript @@ -402,8 +353,7 @@ export class FeedbackController { ``` -If you want use google recaptcha guard in combination with another guards then you can use `@UseGuards` decorator. - +If you want to use the Google reCAPTCHA guard in combination with other guards, you can use the `@UseGuards` decorator.
```typescript @Controller('feedback') @@ -418,11 +368,11 @@ export class FeedbackController { ``` -Usage example you can find [here](https://github.com/chvarkov/google-recaptcha-example). +You can find a usage example in the following [link](https://github.com/chvarkov/google-recaptcha-example). ### Usage in Graphql application -Use `@Recaptcha` decorator to protect your resolver. +To protect your resolver, use the `@Recaptcha` decorator. ```typescript @Recaptcha() @@ -435,7 +385,7 @@ export class RecipesResolver { } ``` -Get verification result +Obtain verification result: ```typescript @Recaptcha() @@ -450,7 +400,7 @@ export class RecipesResolver { } ``` -You can override default property that contain recaptcha for specific query, mutation or subscription. +You can override the default recaptcha property for a specific endpoint. ```typescript @Recaptcha() @@ -470,6 +420,55 @@ export class RecipesResolver { } ``` +### Validate in service + +```typescript +@Injectable() +export class SomeService { + constructor(private readonly recaptchaValidator: GoogleRecaptchaValidator) { + } + + async someAction(recaptchaToken: string): Promise { + const result = await this.recaptchaValidator.validate({ + response: recaptchaToken, + score: 0.8, + action: 'SomeAction', + }); + + if (!result.success) { + throw new GoogleRecaptchaException(result.errors); + } + // TODO: Your implemetation + } +} +``` + +### Validate in service (Enterprise) + +```typescript +@Injectable() +export class SomeService { + constructor(private readonly recaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator) { + } + + async someAction(recaptchaToken: string): Promise { + const result = await this.recaptchaEnterpriseValidator.validate({ + response: recaptchaToken, + score: 0.8, + action: 'SomeAction', + }); + + if (!result.success) { + throw new GoogleRecaptchaException(result.errors); + } + + const riskAnalytics = result.getEnterpriseRiskAnalytics(); + + // TODO: Your implemetation + } +} +``` + ### Error handling **GoogleRecaptchaException** From 72ba10ccfa1a6a172f7324d4285a08cc2bb7e9a2 Mon Sep 17 00:00:00 2001 From: chvarkov Date: Sat, 15 Apr 2023 01:22:19 +0000 Subject: [PATCH 2/3] fix: build command. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cf517a..6a47d5b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "private": false, "main": "index.js", "scripts": { - "build": "rimraf dist && tsc && cp package.json dist && cp README.md dist && cp LICENSE dist && cp CONTRIBUTING.md dist", + "build": "rimraf dist && tsc && cp package.json dist && cp README.md dist && cp LICENSE dist && cp CONTRIBUTING.md dist && cp CHANGELOG.md dist", "format": "prettier \"**/*.ts\" \"**/*.json\" --ignore-path ./.prettierignore --write", "lint:fix": "eslint . --fix", "lint:check": "eslint . --max-warnings=0", From 77ad00d4bd936cf6727fb8105ff0a6fab230c931 Mon Sep 17 00:00:00 2001 From: chvarkov Date: Sat, 15 Apr 2023 01:28:37 +0000 Subject: [PATCH 3/3] release: v3.3.1. --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f101b..0f3a427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.3.1 +- Reworked readme docs. +- Added changelog file. + ## v3.3.0 - Reworked to use axios instead of @nestjs/axios. - Removed peer dependencies: diff --git a/package.json b/package.json index 6a47d5b..d7d1926 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nestlab/google-recaptcha", - "version": "3.3.0", + "version": "3.3.1", "description": "Google recaptcha module for NestJS.", "keywords": [ "nestjs",