@proconnect-gouv/proconnect.debounce 1.0.1 → 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 +8 -0
- package/dist/api/index.cjs +25 -10
- package/dist/api/index.d.ts +13 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +25 -11
- package/package.json +2 -1
- package/src/api/request.ts +6 -10
- package/src/api/single-validation.ts +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 1.0.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/api/index.cjs
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
|
|
3
5
|
class FetchError extends Error {
|
|
4
6
|
}
|
|
5
7
|
async function request(url, options) {
|
|
6
8
|
try {
|
|
7
|
-
const res = await
|
|
9
|
+
const res = await axios({
|
|
10
|
+
url,
|
|
8
11
|
headers: options?.headers,
|
|
9
12
|
method: options?.method,
|
|
10
|
-
|
|
13
|
+
timeout: options?.timeout ?? 3e4
|
|
11
14
|
});
|
|
12
|
-
|
|
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() };
|
|
15
|
+
return { data: res.data };
|
|
20
16
|
} catch (error) {
|
|
21
17
|
throw new FetchError(
|
|
22
18
|
error instanceof Error ? error.message : String(error)
|
|
@@ -41,5 +37,24 @@ function singleValidationFactory(apiKey, config) {
|
|
|
41
37
|
return debounce;
|
|
42
38
|
};
|
|
43
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
|
+
);
|
|
55
|
+
return debounce;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
44
58
|
|
|
59
|
+
exports.pingDebounceFactory = pingDebounceFactory;
|
|
45
60
|
exports.singleValidationFactory = singleValidationFactory;
|
package/dist/api/index.d.ts
CHANGED
|
@@ -18,8 +18,20 @@ declare function singleValidationFactory(apiKey: string, config?: {
|
|
|
18
18
|
send_transactional: string;
|
|
19
19
|
did_you_mean: string;
|
|
20
20
|
}>;
|
|
21
|
+
declare function pingDebounceFactory(apiKey: string, config?: {
|
|
22
|
+
timeout?: number;
|
|
23
|
+
}): () => Promise<{
|
|
24
|
+
email: string;
|
|
25
|
+
code: string;
|
|
26
|
+
role: string;
|
|
27
|
+
free_email: string;
|
|
28
|
+
result: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
send_transactional: string;
|
|
31
|
+
did_you_mean: string;
|
|
32
|
+
}>;
|
|
21
33
|
type SingleValidationHandler = ReturnType<typeof singleValidationFactory>;
|
|
22
34
|
|
|
23
|
-
export { singleValidationFactory };
|
|
35
|
+
export { pingDebounceFactory, singleValidationFactory };
|
|
24
36
|
export type { SingleValidationHandler };
|
|
25
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +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":[]}
|
|
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,20 +1,16 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
1
3
|
class FetchError extends Error {
|
|
2
4
|
}
|
|
3
5
|
async function request(url, options) {
|
|
4
6
|
try {
|
|
5
|
-
const res = await
|
|
7
|
+
const res = await axios({
|
|
8
|
+
url,
|
|
6
9
|
headers: options?.headers,
|
|
7
10
|
method: options?.method,
|
|
8
|
-
|
|
11
|
+
timeout: options?.timeout ?? 3e4
|
|
9
12
|
});
|
|
10
|
-
|
|
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() };
|
|
13
|
+
return { data: res.data };
|
|
18
14
|
} catch (error) {
|
|
19
15
|
throw new FetchError(
|
|
20
16
|
error instanceof Error ? error.message : String(error)
|
|
@@ -39,5 +35,23 @@ function singleValidationFactory(apiKey, config) {
|
|
|
39
35
|
return debounce;
|
|
40
36
|
};
|
|
41
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
|
+
);
|
|
53
|
+
return debounce;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
42
56
|
|
|
43
|
-
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.
|
|
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,6 +36,7 @@
|
|
|
36
36
|
"test": "tsx --test --test-reporter=spec src/**/*.test.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"axios": "^1.15.0",
|
|
39
40
|
"zod": "^4.3.5"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
package/src/api/request.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
1
3
|
class FetchError extends Error {}
|
|
2
4
|
|
|
3
5
|
async function request<responseT>(
|
|
@@ -9,19 +11,13 @@ async function request<responseT>(
|
|
|
9
11
|
},
|
|
10
12
|
): Promise<{ data: responseT }> {
|
|
11
13
|
try {
|
|
12
|
-
const res = await
|
|
14
|
+
const res = await axios({
|
|
15
|
+
url,
|
|
13
16
|
headers: options?.headers,
|
|
14
17
|
method: options?.method,
|
|
15
|
-
|
|
18
|
+
timeout: options?.timeout ?? 30000,
|
|
16
19
|
});
|
|
17
|
-
|
|
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 };
|
|
20
|
+
return { data: res.data as responseT };
|
|
25
21
|
} catch (error) {
|
|
26
22
|
throw new FetchError(
|
|
27
23
|
error instanceof Error ? error.message : String(error),
|
|
@@ -35,6 +35,29 @@ export function singleValidationFactory(
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
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
|
+
);
|
|
56
|
+
|
|
57
|
+
return debounce;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
38
61
|
export type SingleValidationHandler = ReturnType<
|
|
39
62
|
typeof singleValidationFactory
|
|
40
63
|
>;
|