-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(debounce): extract debounce connector to individual pkg
- Loading branch information
1 parent
05994e4
commit a5056b6
Showing
16 changed files
with
298 additions
and
49 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 @@ | ||
--- | ||
"@gouvfr-lasuite/proconnect.debounce": minor | ||
--- | ||
|
||
♻️ Prélèvement d'un partie du connecteur Debounce | ||
|
||
Dans le cadres la suggestion d'email sur PCF, une partie du connecteur Debounce est maintenant dans le package `@gouvfr-lasuite/proconnect.debounce`. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Direction Interministérielle du Numérique - Gouvernement Français | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# 📦 @gouvfr-lasuite/proconnect.debounce | ||
|
||
> ⚡ Typed Debounce API for ProConnect | ||
## ⚙️ Installation | ||
|
||
```bash | ||
npm install @gouvfr-lasuite/proconnect.debounce | ||
``` | ||
|
||
## 📖 Usage | ||
|
||
### [Single Validation](https://developers.debounce.io/reference/single-validation) | ||
|
||
```ts | ||
import { singleValidationFactory } from "@gouvfr-lasuite/proconnect.debounce/api"; | ||
|
||
const singleValidation = singleValidationFactory(DEBOUNCE_API_KEY); | ||
|
||
const response = await singleValidation("[email protected]"); | ||
``` | ||
|
||
## 📖 License | ||
|
||
[MIT](./LICENSE.md) |
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,59 @@ | ||
{ | ||
"name": "@gouvfr-lasuite/proconnect.debounce", | ||
"version": "0.3.2", | ||
"homepage": "https://github.com/numerique-gouv/moncomptepro/tree/master/packages/debounce#readme", | ||
"bugs": "https://github.com/numerique-gouv/moncomptepro/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/numerique-gouv/moncomptepro.git", | ||
"directory": "packages/debounce" | ||
}, | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "module", | ||
"imports": {}, | ||
"exports": { | ||
"./api": { | ||
"require": "./dist/api/index.cjs", | ||
"import": "./dist/api/index.js", | ||
"types": "./dist/api/index.d.ts" | ||
} | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"api": [ | ||
"./dist/api/index.d.ts" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"build": "pkgroll --tsconfig=tsconfig.lib.json", | ||
"check": "npm run build -- --noEmit", | ||
"dev": "npm run build -- --watch --preserveWatchOutput", | ||
"test": "mocha" | ||
}, | ||
"mocha": { | ||
"reporter": "spec", | ||
"require": [ | ||
"tsx" | ||
], | ||
"spec": "src/**/*.test.ts" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.7.7", | ||
"zod": "^3.24.1" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node22": "^22.0.0", | ||
"@types/mocha": "^10.0.10", | ||
"@types/node": "^22.10.2", | ||
"chai": "^5.1.2", | ||
"mocha": "^11.0.1", | ||
"pkgroll": "^2.6.1", | ||
"tsx": "^4.19.2" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
} | ||
} |
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,3 @@ | ||
// | ||
|
||
export * from "./single-validation.js"; |
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,32 @@ | ||
// | ||
|
||
import { expect } from "chai"; | ||
import { before, describe } from "mocha"; | ||
import { singleValidationFactory } from "./single-validation.js"; | ||
|
||
// | ||
|
||
const { DEBOUNCE_API_KEY } = process.env; | ||
const singleValidation = singleValidationFactory(DEBOUNCE_API_KEY ?? ""); | ||
|
||
// | ||
|
||
describe("singleValidationFactory", () => { | ||
before(function () { | ||
if (!DEBOUNCE_API_KEY) this.skip(); | ||
}); | ||
|
||
it("should return a valid response", async function () { | ||
const response = await singleValidation("[email protected]"); | ||
expect(response).includes({ | ||
email: "[email protected]", | ||
code: "3", | ||
role: "true", | ||
free_email: "true", | ||
result: "Invalid", | ||
reason: "Disposable, Role", | ||
send_transactional: "0", | ||
did_you_mean: "[email protected]", | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
// | ||
|
||
import type { DebounceSuccessResponse } from "#src/types/index.js"; | ||
import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios"; | ||
|
||
// | ||
|
||
/** | ||
* Perform a single email validation request. | ||
* | ||
* @see https://developers.debounce.io/reference/single-validation#response-parameters | ||
* @param apiKey the debounce.io API key | ||
* @param config the Axios request config | ||
* @returns Debounce Single Validation response | ||
*/ | ||
export function singleValidationFactory( | ||
apiKey: string, | ||
config?: AxiosRequestConfig, | ||
) { | ||
return async function singleValidation(email: string) { | ||
const { | ||
data: { debounce }, | ||
}: AxiosResponse<DebounceSuccessResponse> = await axios({ | ||
method: "get", | ||
url: `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`, | ||
headers: { | ||
accept: "application/json", | ||
}, | ||
...config, | ||
}); | ||
|
||
return debounce; | ||
}; | ||
} |
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,48 @@ | ||
// | ||
|
||
/** | ||
* @see https://developers.debounce.io/reference/responses#error-response | ||
*/ | ||
|
||
export interface DebounceErrorResponse { | ||
debounce: { | ||
error: string; | ||
code: "0"; | ||
}; | ||
success: "0"; | ||
} | ||
|
||
/** | ||
* @see https://developers.debounce.io/reference/responses#success-response | ||
*/ | ||
export interface DebounceSuccessResponse { | ||
debounce: { | ||
// The email address you are requesting to validate. | ||
// ex: '[email protected]' | ||
email: string; | ||
// DeBounce validation response code. | ||
// ex: '6' | ||
code: string; | ||
// Is the email role-based or not. Role emails such as "sales@", "webmaster@" etc. are not suitable for sending marketing emails to. | ||
// ['true', 'false'] | ||
role: string; | ||
// Is the email from a free email provider - like Gmail - or not. | ||
// ['true', 'false'] | ||
free_email: string; | ||
// The final result of the validation process. This response will help to determine whether you should send marketing emails to a recipient or not. | ||
// ['Invalid', 'Risky', 'Safe to Send', 'Unknown'] | ||
result: string; | ||
// The reason why the result is given. | ||
// ex: 'Bounce, Role' | ||
reason: string; | ||
// Is it suggested that you send transactional emails to the recipient or not (0: no, 1: yes). Generally, it is suggested to send transactional emails to Valid, Accept-all, and Unknown emails. | ||
// ['0', '1'] | ||
send_transactional: string; | ||
// If you use a misspelled email address like someemail@gmial.com, the validation engine tries to suggest you the corrected email address. | ||
// ex: '[email protected]', '' | ||
did_you_mean: string; | ||
}; | ||
|
||
success: "1"; | ||
balance: `${number}`; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"outDir": "./dist", | ||
"rootDir": "src", | ||
"types": ["node"], | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"verbatimModuleSyntax": true, | ||
"paths": { | ||
"#src/*": ["./src/*"] | ||
} | ||
}, | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"references": [] | ||
} |
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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"exclude": ["src/**/*.test.ts"], | ||
"extends": "./tsconfig.json", | ||
"include": ["src"] | ||
} |
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
Oops, something went wrong.