@proconnect-gouv/proconnect.debounce 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # @proconnect-gouv/proconnect.debounce
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1455](https://github.com/proconnect-gouv/proconnect-identite/pull/1455) [`38fffb0`](https://github.com/proconnect-gouv/proconnect-identite/commit/38fffb00ca5a5d2341a662f684d2555bbfb5ff02) Thanks [@douglasduteil](https://github.com/douglasduteil)! - 📦 Première version officiel des packages `@proconnect-gouv/*`
8
+
9
+ ## 0.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#1385](https://github.com/proconnect-gouv/proconnect-identite/pull/1385) [`5906294`](https://github.com/proconnect-gouv/proconnect-identite/commit/5906294b6618d0d2cc1865a836886a35d740feb4) Thanks [@dependabot](https://github.com/apps/dependabot)! - feat: migration vers Zod v4
14
+
15
+ Migration de Zod v3 vers v4 - les utilisateurs du package doivent s'assurer que leur projet est compatible avec Zod v4 si ils importent des schémas ou types depuis ce package.
16
+
17
+ ## 0.4.3
18
+
19
+ ### Patch Changes
20
+
21
+ - [#975](https://github.com/proconnect-gouv/proconnect-identite/pull/975) [`8e57ecc`](https://github.com/proconnect-gouv/proconnect-identite/commit/8e57eccff4d3d614a4264b63f2583a63f82a88e6) Thanks [@douglasduteil](https://github.com/douglasduteil)! - 🚚 Renommage de moncomptepro en proconnect-identite
22
+
23
+ ## 0.4.2
24
+
25
+ ### Patch Changes
26
+
27
+ - [#964](https://github.com/proconnect-gouv/proconnect-identite/pull/964) [`eb63af3`](https://github.com/proconnect-gouv/proconnect-identite/commit/eb63af3bf33139adece820c1cfadf3ee387713f1) Thanks [@douglasduteil](https://github.com/douglasduteil)! - 🧑‍💻 Ajout du package @gouvfr-lasuite/proconnect.devtools.typescript
28
+
29
+ Partage de la configuration de TypeScript entre les packages.
30
+
31
+ ## 0.4.1
32
+
33
+ ### Patch Changes
34
+
35
+ - [#950](https://github.com/proconnect-gouv/proconnect-identite/pull/950) [`afaa477`](https://github.com/proconnect-gouv/proconnect-identite/commit/afaa477911ce350c69daac8a5fef56329e31b906) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ✨ Export du type de handler
36
+
37
+ ## 0.4.0
38
+
39
+ ### Minor Changes
40
+
41
+ - [#945](https://github.com/proconnect-gouv/proconnect-identite/pull/945) [`aa82ec5`](https://github.com/proconnect-gouv/proconnect-identite/commit/aa82ec57d314c9d82ce3ed13e62604d9c6825c63) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ♻️ Prélèvement d'un partie du connecteur Debounce
42
+
43
+ Dans le cadre de la suggestion d'email sur PCF, une partie du connecteur Debounce est maintenant dans le package `@gouvfr-lasuite/proconnect.debounce`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Direction Interministérielle du Numérique - Gouvernement Français
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # 📦 @proconnect-gouv/proconnect.debounce
2
+
3
+ > ⚡ Typed Debounce API for ProConnect
4
+
5
+ ## ⚙️ Installation
6
+
7
+ ```bash
8
+ npm install @proconnect-gouv/proconnect.debounce
9
+ ```
10
+
11
+ ## 📖 Usage
12
+
13
+ ### [Single Validation](https://developers.debounce.io/reference/single-validation)
14
+
15
+ ```ts
16
+ import { singleValidationFactory } from "@proconnect-gouv/proconnect.debounce/api";
17
+
18
+ const singleValidation = singleValidationFactory(DEBOUNCE_API_KEY);
19
+
20
+ const response = await singleValidation("test@test.com");
21
+ ```
22
+
23
+ ## 📖 License
24
+
25
+ [MIT](./LICENSE.md)
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+
5
+ function singleValidationFactory(apiKey, config) {
6
+ return async function singleValidation(email) {
7
+ const {
8
+ data: { debounce }
9
+ } = await axios({
10
+ method: "get",
11
+ url: `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
12
+ headers: {
13
+ accept: "application/json"
14
+ },
15
+ ...config
16
+ });
17
+ return debounce;
18
+ };
19
+ }
20
+
21
+ exports.singleValidationFactory = singleValidationFactory;
@@ -0,0 +1,23 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+
3
+ /**
4
+ * Perform a single email validation request.
5
+ *
6
+ * @see https://developers.debounce.io/reference/single-validation#response-parameters
7
+ * @param apiKey the debounce.io API key
8
+ * @param config the Axios request config
9
+ * @returns Debounce Single Validation response
10
+ */
11
+ declare function singleValidationFactory(apiKey: string, config?: AxiosRequestConfig): (email: string) => Promise<{
12
+ email: string;
13
+ code: string;
14
+ role: string;
15
+ free_email: string;
16
+ result: string;
17
+ reason: string;
18
+ send_transactional: string;
19
+ did_you_mean: string;
20
+ }>;
21
+ type SingleValidationHandler = ReturnType<typeof singleValidationFactory>;
22
+
23
+ export { type SingleValidationHandler, singleValidationFactory };
@@ -0,0 +1,19 @@
1
+ import axios from 'axios';
2
+
3
+ function singleValidationFactory(apiKey, config) {
4
+ return async function singleValidation(email) {
5
+ const {
6
+ data: { debounce }
7
+ } = await axios({
8
+ method: "get",
9
+ url: `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
10
+ headers: {
11
+ accept: "application/json"
12
+ },
13
+ ...config
14
+ });
15
+ return debounce;
16
+ };
17
+ }
18
+
19
+ export { singleValidationFactory };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@proconnect-gouv/proconnect.debounce",
3
+ "version": "1.0.0",
4
+ "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/debounce#readme",
5
+ "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/proconnect-gouv/proconnect-identite.git",
9
+ "directory": "packages/debounce"
10
+ },
11
+ "license": "MIT",
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "imports": {
15
+ "#src/types": "./src/types/index.ts"
16
+ },
17
+ "exports": {
18
+ "./api": {
19
+ "require": "./dist/api/index.cjs",
20
+ "import": "./dist/api/index.js",
21
+ "types": "./dist/api/index.d.ts"
22
+ }
23
+ },
24
+ "typesVersions": {
25
+ "*": {
26
+ "api": [
27
+ "./dist/api/index.d.ts"
28
+ ]
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "pkgroll --tsconfig=tsconfig.lib.json",
33
+ "check": "npm run build -- --noEmit",
34
+ "dev": "npm run build -- --watch --preserveWatchOutput",
35
+ "dev:test": "tsx --watch --test src/**/*.test.ts",
36
+ "test": "tsx --test --test-reporter=spec src/**/*.test.ts"
37
+ },
38
+ "dependencies": {
39
+ "axios": "^1.12.2",
40
+ "zod": "^4.0.17"
41
+ },
42
+ "devDependencies": {
43
+ "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
44
+ "@types/node": "^22.18.6",
45
+ "pkgroll": "^2.12.1",
46
+ "tsx": "^4.20.3"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ }
52
+ }
@@ -0,0 +1,3 @@
1
+ //
2
+
3
+ export * from "./single-validation.js";
@@ -0,0 +1,32 @@
1
+ //
2
+
3
+ import assert from "assert/strict";
4
+ import { describe, it } from "node:test";
5
+ import { singleValidationFactory } from "./single-validation.js";
6
+
7
+ //
8
+
9
+ const { DEBOUNCE_API_KEY } = process.env;
10
+ const singleValidation = singleValidationFactory(DEBOUNCE_API_KEY ?? "");
11
+
12
+ //
13
+
14
+ describe(
15
+ "singleValidationFactory",
16
+ { skip: DEBOUNCE_API_KEY === undefined },
17
+ () => {
18
+ it("should return a valid response", async function () {
19
+ const response = await singleValidation("test@test.com");
20
+ assert.partialDeepStrictEqual(response, {
21
+ code: "3",
22
+ did_you_mean: "test@toke.com",
23
+ email: "test@test.com",
24
+ free_email: "true",
25
+ reason: "Disposable, Role",
26
+ result: "Invalid",
27
+ role: "true",
28
+ send_transactional: "0",
29
+ });
30
+ });
31
+ },
32
+ );
@@ -0,0 +1,38 @@
1
+ //
2
+
3
+ import type { DebounceSuccessResponse } from "#src/types";
4
+ import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
5
+
6
+ //
7
+
8
+ /**
9
+ * Perform a single email validation request.
10
+ *
11
+ * @see https://developers.debounce.io/reference/single-validation#response-parameters
12
+ * @param apiKey the debounce.io API key
13
+ * @param config the Axios request config
14
+ * @returns Debounce Single Validation response
15
+ */
16
+ export function singleValidationFactory(
17
+ apiKey: string,
18
+ config?: AxiosRequestConfig,
19
+ ) {
20
+ return async function singleValidation(email: string) {
21
+ const {
22
+ data: { debounce },
23
+ }: AxiosResponse<DebounceSuccessResponse> = await axios({
24
+ method: "get",
25
+ url: `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
26
+ headers: {
27
+ accept: "application/json",
28
+ },
29
+ ...config,
30
+ });
31
+
32
+ return debounce;
33
+ };
34
+ }
35
+
36
+ export type SingleValidationHandler = ReturnType<
37
+ typeof singleValidationFactory
38
+ >;
@@ -0,0 +1,47 @@
1
+ //
2
+
3
+ /**
4
+ * @see https://developers.debounce.io/reference/responses#error-response
5
+ */
6
+ export interface DebounceErrorResponse {
7
+ debounce: {
8
+ error: string;
9
+ code: "0";
10
+ };
11
+ success: "0";
12
+ }
13
+
14
+ /**
15
+ * @see https://developers.debounce.io/reference/responses#success-response
16
+ */
17
+ export interface DebounceSuccessResponse {
18
+ debounce: {
19
+ // The email address you are requesting to validate.
20
+ // ex: 'test@wanadoo.rf'
21
+ email: string;
22
+ // DeBounce validation response code.
23
+ // ex: '6'
24
+ code: string;
25
+ // Is the email role-based or not. Role emails such as "sales@", "webmaster@" etc. are not suitable for sending marketing emails to.
26
+ // ['true', 'false']
27
+ role: string;
28
+ // Is the email from a free email provider - like Gmail - or not.
29
+ // ['true', 'false']
30
+ free_email: string;
31
+ // The final result of the validation process. This response will help to determine whether you should send marketing emails to a recipient or not.
32
+ // ['Invalid', 'Risky', 'Safe to Send', 'Unknown']
33
+ result: string;
34
+ // The reason why the result is given.
35
+ // ex: 'Bounce, Role'
36
+ reason: string;
37
+ // 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.
38
+ // ['0', '1']
39
+ send_transactional: string;
40
+ // If you use a misspelled email address like someemail@gmial.com, the validation engine tries to suggest you the corrected email address.
41
+ // ex: 'test@wanadoo.fr', ''
42
+ did_you_mean: string;
43
+ };
44
+
45
+ success: "1";
46
+ balance: `${number}`;
47
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "outDir": "./dist",
6
+ "rootDir": "src",
7
+ "types": ["node"]
8
+ },
9
+ "extends": "@proconnect-gouv/proconnect.devtools.typescript/base/tsconfig.json",
10
+ "references": []
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist",
4
+ "rootDir": "./src"
5
+ },
6
+ "exclude": ["src/**/*.test.ts"],
7
+ "extends": "./tsconfig.json",
8
+ "include": ["src"]
9
+ }