@proconnect-gouv/proconnect.debounce 1.0.0 → 1.0.2

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @proconnect-gouv/proconnect.debounce
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1904](https://github.com/proconnect-gouv/proconnect-identite/pull/1904) [`711aa2f`](https://github.com/proconnect-gouv/proconnect-identite/commit/711aa2fd16b19f6ff2baf5da4a40aaf2a313a42b) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - correction de memory leak
8
+
9
+ - [#1900](https://github.com/proconnect-gouv/proconnect-identite/pull/1900) [`dc33a64`](https://github.com/proconnect-gouv/proconnect-identite/commit/dc33a6428431f5cca6e7d0d554c5a141f8872935) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - ajoute une fonction de ping pour le package debounce
10
+
11
+ ## 1.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#1879](https://github.com/proconnect-gouv/proconnect-identite/pull/1879) [`64c12ba`](https://github.com/proconnect-gouv/proconnect-identite/commit/64c12bab1152970195acc6f03ee8ae9d5ae325c8) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - remplace axios par fetch natif
16
+
3
17
  ## 1.0.0
4
18
 
5
19
  ### Major Changes
@@ -2,20 +2,59 @@
2
2
 
3
3
  var axios = require('axios');
4
4
 
5
+ class FetchError extends Error {
6
+ }
7
+ async function request(url, options) {
8
+ try {
9
+ const res = await axios({
10
+ url,
11
+ headers: options?.headers,
12
+ method: options?.method,
13
+ timeout: options?.timeout ?? 3e4
14
+ });
15
+ return { data: res.data };
16
+ } catch (error) {
17
+ throw new FetchError(
18
+ error instanceof Error ? error.message : String(error)
19
+ );
20
+ }
21
+ }
22
+
5
23
  function singleValidationFactory(apiKey, config) {
6
24
  return async function singleValidation(email) {
7
25
  const {
8
26
  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
- });
27
+ } = await request(
28
+ `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
29
+ {
30
+ method: "get",
31
+ headers: {
32
+ accept: "application/json"
33
+ },
34
+ timeout: config?.timeout
35
+ }
36
+ );
37
+ return debounce;
38
+ };
39
+ }
40
+ function pingDebounceFactory(apiKey, config) {
41
+ return async function pingDebounce() {
42
+ const mockEmail = "user@example.com";
43
+ const {
44
+ data: { debounce }
45
+ } = await request(
46
+ `https://api.debounce.io/v1/?email=${mockEmail}&api=${apiKey}`,
47
+ {
48
+ method: "get",
49
+ headers: {
50
+ accept: "application/json"
51
+ },
52
+ timeout: config?.timeout
53
+ }
54
+ );
17
55
  return debounce;
18
56
  };
19
57
  }
20
58
 
59
+ exports.pingDebounceFactory = pingDebounceFactory;
21
60
  exports.singleValidationFactory = singleValidationFactory;
@@ -1,5 +1,3 @@
1
- import { AxiosRequestConfig } from 'axios';
2
-
3
1
  /**
4
2
  * Perform a single email validation request.
5
3
  *
@@ -8,7 +6,21 @@ import { AxiosRequestConfig } from 'axios';
8
6
  * @param config the Axios request config
9
7
  * @returns Debounce Single Validation response
10
8
  */
11
- declare function singleValidationFactory(apiKey: string, config?: AxiosRequestConfig): (email: string) => Promise<{
9
+ declare function singleValidationFactory(apiKey: string, config?: {
10
+ timeout?: number;
11
+ }): (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
+ declare function pingDebounceFactory(apiKey: string, config?: {
22
+ timeout?: number;
23
+ }): () => Promise<{
12
24
  email: string;
13
25
  code: string;
14
26
  role: string;
@@ -20,4 +32,6 @@ declare function singleValidationFactory(apiKey: string, config?: AxiosRequestCo
20
32
  }>;
21
33
  type SingleValidationHandler = ReturnType<typeof singleValidationFactory>;
22
34
 
23
- export { type SingleValidationHandler, singleValidationFactory };
35
+ export { pingDebounceFactory, singleValidationFactory };
36
+ export type { SingleValidationHandler };
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sources":["../../src/api/single-validation.ts"],"mappings":"AAOA;AANA;AACA;AACA;AACA;AACA;AACA;GAQG;iBACa,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,IAEU,OAAO,MAAM;AARtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;GAiBC;iBAEe,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE;AAhB/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;GA4BC;KAEW,uBAAuB,GAAG,UAAU,CAC9C,OAAO,uBAAuB,CAC/B,CAAC;;;;","names":[]}
package/dist/api/index.js CHANGED
@@ -1,19 +1,57 @@
1
1
  import axios from 'axios';
2
2
 
3
+ class FetchError extends Error {
4
+ }
5
+ async function request(url, options) {
6
+ try {
7
+ const res = await axios({
8
+ url,
9
+ headers: options?.headers,
10
+ method: options?.method,
11
+ timeout: options?.timeout ?? 3e4
12
+ });
13
+ return { data: res.data };
14
+ } catch (error) {
15
+ throw new FetchError(
16
+ error instanceof Error ? error.message : String(error)
17
+ );
18
+ }
19
+ }
20
+
3
21
  function singleValidationFactory(apiKey, config) {
4
22
  return async function singleValidation(email) {
5
23
  const {
6
24
  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
- });
25
+ } = await request(
26
+ `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
27
+ {
28
+ method: "get",
29
+ headers: {
30
+ accept: "application/json"
31
+ },
32
+ timeout: config?.timeout
33
+ }
34
+ );
35
+ return debounce;
36
+ };
37
+ }
38
+ function pingDebounceFactory(apiKey, config) {
39
+ return async function pingDebounce() {
40
+ const mockEmail = "user@example.com";
41
+ const {
42
+ data: { debounce }
43
+ } = await request(
44
+ `https://api.debounce.io/v1/?email=${mockEmail}&api=${apiKey}`,
45
+ {
46
+ method: "get",
47
+ headers: {
48
+ accept: "application/json"
49
+ },
50
+ timeout: config?.timeout
51
+ }
52
+ );
15
53
  return debounce;
16
54
  };
17
55
  }
18
56
 
19
- export { singleValidationFactory };
57
+ export { pingDebounceFactory, singleValidationFactory };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.debounce",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/debounce#readme",
5
5
  "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
6
  "repository": {
@@ -36,13 +36,13 @@
36
36
  "test": "tsx --test --test-reporter=spec src/**/*.test.ts"
37
37
  },
38
38
  "dependencies": {
39
- "axios": "^1.12.2",
40
- "zod": "^4.0.17"
39
+ "axios": "^1.15.0",
40
+ "zod": "^4.3.5"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
44
44
  "@types/node": "^22.18.6",
45
- "pkgroll": "^2.12.1",
45
+ "pkgroll": "^2.22.0",
46
46
  "tsx": "^4.20.3"
47
47
  },
48
48
  "publishConfig": {
@@ -0,0 +1,28 @@
1
+ import axios from "axios";
2
+
3
+ class FetchError extends Error {}
4
+
5
+ async function request<responseT>(
6
+ url: string,
7
+ options?: {
8
+ headers?: Record<string, string>;
9
+ method?: string;
10
+ timeout?: number;
11
+ },
12
+ ): Promise<{ data: responseT }> {
13
+ try {
14
+ const res = await axios({
15
+ url,
16
+ headers: options?.headers,
17
+ method: options?.method,
18
+ timeout: options?.timeout ?? 30000,
19
+ });
20
+ return { data: res.data as responseT };
21
+ } catch (error) {
22
+ throw new FetchError(
23
+ error instanceof Error ? error.message : String(error),
24
+ );
25
+ }
26
+ }
27
+
28
+ export { FetchError, request };
@@ -1,7 +1,7 @@
1
1
  //
2
2
 
3
3
  import type { DebounceSuccessResponse } from "#src/types";
4
- import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
4
+ import { request } from "./request.js";
5
5
 
6
6
  //
7
7
 
@@ -15,19 +15,44 @@ import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
15
15
  */
16
16
  export function singleValidationFactory(
17
17
  apiKey: string,
18
- config?: AxiosRequestConfig,
18
+ config?: { timeout?: number },
19
19
  ) {
20
20
  return async function singleValidation(email: string) {
21
21
  const {
22
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",
23
+ } = await request<DebounceSuccessResponse>(
24
+ `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
25
+ {
26
+ method: "get",
27
+ headers: {
28
+ accept: "application/json",
29
+ },
30
+ timeout: config?.timeout,
28
31
  },
29
- ...config,
30
- });
32
+ );
33
+
34
+ return debounce;
35
+ };
36
+ }
37
+
38
+ export function pingDebounceFactory(
39
+ apiKey: string,
40
+ config?: { timeout?: number },
41
+ ) {
42
+ return async function pingDebounce() {
43
+ const mockEmail = "user@example.com";
44
+ const {
45
+ data: { debounce },
46
+ } = await request<DebounceSuccessResponse>(
47
+ `https://api.debounce.io/v1/?email=${mockEmail}&api=${apiKey}`,
48
+ {
49
+ method: "get",
50
+ headers: {
51
+ accept: "application/json",
52
+ },
53
+ timeout: config?.timeout,
54
+ },
55
+ );
31
56
 
32
57
  return debounce;
33
58
  };