@proconnect-gouv/proconnect.debounce 1.0.0 → 1.0.1
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 +6 -0
- package/dist/api/index.cjs +33 -9
- package/dist/api/index.d.ts +6 -4
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +33 -9
- package/package.json +3 -4
- package/src/api/request.ts +32 -0
- package/src/api/single-validation.ts +11 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.debounce
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
3
9
|
## 1.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
package/dist/api/index.cjs
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class FetchError extends Error {
|
|
4
|
+
}
|
|
5
|
+
async function request(url, options) {
|
|
6
|
+
try {
|
|
7
|
+
const res = await fetch(url, {
|
|
8
|
+
headers: options?.headers,
|
|
9
|
+
method: options?.method,
|
|
10
|
+
signal: AbortSignal.timeout(options?.timeout ?? 3e4)
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
throw new FetchError(res.statusText);
|
|
14
|
+
}
|
|
15
|
+
const contentType = res.headers.get("content-type");
|
|
16
|
+
if (contentType?.includes("application/json")) {
|
|
17
|
+
return { data: await res.json() };
|
|
18
|
+
}
|
|
19
|
+
return { data: await res.text() };
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new FetchError(
|
|
22
|
+
error instanceof Error ? error.message : String(error)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
4
26
|
|
|
5
27
|
function singleValidationFactory(apiKey, config) {
|
|
6
28
|
return async function singleValidation(email) {
|
|
7
29
|
const {
|
|
8
30
|
data: { debounce }
|
|
9
|
-
} = await
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
} = await request(
|
|
32
|
+
`https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
|
|
33
|
+
{
|
|
34
|
+
method: "get",
|
|
35
|
+
headers: {
|
|
36
|
+
accept: "application/json"
|
|
37
|
+
},
|
|
38
|
+
timeout: config?.timeout
|
|
39
|
+
}
|
|
40
|
+
);
|
|
17
41
|
return debounce;
|
|
18
42
|
};
|
|
19
43
|
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -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,9 @@ 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?:
|
|
9
|
+
declare function singleValidationFactory(apiKey: string, config?: {
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}): (email: string) => Promise<{
|
|
12
12
|
email: string;
|
|
13
13
|
code: string;
|
|
14
14
|
role: string;
|
|
@@ -20,4 +20,6 @@ declare function singleValidationFactory(apiKey: string, config?: AxiosRequestCo
|
|
|
20
20
|
}>;
|
|
21
21
|
type SingleValidationHandler = ReturnType<typeof singleValidationFactory>;
|
|
22
22
|
|
|
23
|
-
export {
|
|
23
|
+
export { singleValidationFactory };
|
|
24
|
+
export type { SingleValidationHandler };
|
|
25
|
+
//# 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;KAEW,uBAAuB,GAAG,UAAU,CAC9C,OAAO,uBAAuB,CAC/B,CAAC;;;;","names":[]}
|
package/dist/api/index.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
class FetchError extends Error {
|
|
2
|
+
}
|
|
3
|
+
async function request(url, options) {
|
|
4
|
+
try {
|
|
5
|
+
const res = await fetch(url, {
|
|
6
|
+
headers: options?.headers,
|
|
7
|
+
method: options?.method,
|
|
8
|
+
signal: AbortSignal.timeout(options?.timeout ?? 3e4)
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok) {
|
|
11
|
+
throw new FetchError(res.statusText);
|
|
12
|
+
}
|
|
13
|
+
const contentType = res.headers.get("content-type");
|
|
14
|
+
if (contentType?.includes("application/json")) {
|
|
15
|
+
return { data: await res.json() };
|
|
16
|
+
}
|
|
17
|
+
return { data: await res.text() };
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new FetchError(
|
|
20
|
+
error instanceof Error ? error.message : String(error)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
2
24
|
|
|
3
25
|
function singleValidationFactory(apiKey, config) {
|
|
4
26
|
return async function singleValidation(email) {
|
|
5
27
|
const {
|
|
6
28
|
data: { debounce }
|
|
7
|
-
} = await
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
} = await request(
|
|
30
|
+
`https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
|
|
31
|
+
{
|
|
32
|
+
method: "get",
|
|
33
|
+
headers: {
|
|
34
|
+
accept: "application/json"
|
|
35
|
+
},
|
|
36
|
+
timeout: config?.timeout
|
|
37
|
+
}
|
|
38
|
+
);
|
|
15
39
|
return debounce;
|
|
16
40
|
};
|
|
17
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.debounce",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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,12 @@
|
|
|
36
36
|
"test": "tsx --test --test-reporter=spec src/**/*.test.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"zod": "^4.0.17"
|
|
39
|
+
"zod": "^4.3.5"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
44
43
|
"@types/node": "^22.18.6",
|
|
45
|
-
"pkgroll": "^2.
|
|
44
|
+
"pkgroll": "^2.22.0",
|
|
46
45
|
"tsx": "^4.20.3"
|
|
47
46
|
},
|
|
48
47
|
"publishConfig": {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class FetchError extends Error {}
|
|
2
|
+
|
|
3
|
+
async function request<responseT>(
|
|
4
|
+
url: string,
|
|
5
|
+
options?: {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
method?: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
},
|
|
10
|
+
): Promise<{ data: responseT }> {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fetch(url, {
|
|
13
|
+
headers: options?.headers,
|
|
14
|
+
method: options?.method,
|
|
15
|
+
signal: AbortSignal.timeout(options?.timeout ?? 30_000),
|
|
16
|
+
});
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
throw new FetchError(res.statusText);
|
|
19
|
+
}
|
|
20
|
+
const contentType = res.headers.get("content-type");
|
|
21
|
+
if (contentType?.includes("application/json")) {
|
|
22
|
+
return { data: (await res.json()) as responseT };
|
|
23
|
+
}
|
|
24
|
+
return { data: (await res.text()) as unknown as responseT };
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new FetchError(
|
|
27
|
+
error instanceof Error ? error.message : String(error),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { FetchError, request };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
import type { DebounceSuccessResponse } from "#src/types";
|
|
4
|
-
import
|
|
4
|
+
import { request } from "./request.js";
|
|
5
5
|
|
|
6
6
|
//
|
|
7
7
|
|
|
@@ -15,19 +15,21 @@ import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
|
|
|
15
15
|
*/
|
|
16
16
|
export function singleValidationFactory(
|
|
17
17
|
apiKey: string,
|
|
18
|
-
config?:
|
|
18
|
+
config?: { timeout?: number },
|
|
19
19
|
) {
|
|
20
20
|
return async function singleValidation(email: string) {
|
|
21
21
|
const {
|
|
22
22
|
data: { debounce },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
});
|
|
32
|
+
);
|
|
31
33
|
|
|
32
34
|
return debounce;
|
|
33
35
|
};
|