@proconnect-gouv/proconnect.debounce 1.0.2 → 1.0.3

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,11 @@
1
1
  # @proconnect-gouv/proconnect.debounce
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2585](https://github.com/proconnect-gouv/proconnect-identite/pull/2585) [`01ed18b`](https://github.com/proconnect-gouv/proconnect-identite/commit/01ed18bd538420e4736e29311e7f4bd63b1eecc6) Thanks [@douglasduteil](https://github.com/douglasduteil)! - 🔒 Publication via npm trusted publishing (OIDC) au lieu d'un jeton npm
8
+
3
9
  ## 1.0.2
4
10
 
5
11
  ### Patch Changes
@@ -20,12 +20,10 @@ async function request(url, options) {
20
20
  }
21
21
  }
22
22
 
23
- function singleValidationFactory(apiKey, config) {
24
- return async function singleValidation(email) {
25
- const {
26
- data: { debounce }
27
- } = await request(
28
- `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
23
+ function pingDebounceFactory(apiKey, config) {
24
+ return async function pingDebounce() {
25
+ await request(
26
+ `https://api.debounce.io/v1/balance?api=${apiKey}`,
29
27
  {
30
28
  method: "get",
31
29
  headers: {
@@ -34,16 +32,19 @@ function singleValidationFactory(apiKey, config) {
34
32
  timeout: config?.timeout
35
33
  }
36
34
  );
37
- return debounce;
35
+ return true;
38
36
  };
39
37
  }
40
- function pingDebounceFactory(apiKey, config) {
41
- return async function pingDebounce() {
42
- const mockEmail = "user@example.com";
38
+ function mockPingDebounce() {
39
+ return Promise.resolve(true);
40
+ }
41
+
42
+ function singleValidationFactory(apiKey, config) {
43
+ return async function singleValidation(email) {
43
44
  const {
44
45
  data: { debounce }
45
46
  } = await request(
46
- `https://api.debounce.io/v1/?email=${mockEmail}&api=${apiKey}`,
47
+ `https://api.debounce.io/v1/?email=${encodeURIComponent(email)}&api=${encodeURIComponent(apiKey)}`,
47
48
  {
48
49
  method: "get",
49
50
  headers: {
@@ -55,6 +56,42 @@ function pingDebounceFactory(apiKey, config) {
55
56
  return debounce;
56
57
  };
57
58
  }
59
+ function mockSingleValidation(email) {
60
+ const localPart = email.split("@")[0];
61
+ const domain = email.split("@")[1];
62
+ if (domain === "invalid-domain.com") {
63
+ return Promise.resolve({
64
+ send_transactional: "0",
65
+ did_you_mean: "",
66
+ code: "6"
67
+ });
68
+ }
69
+ if (domain === "ypomail.com") {
70
+ return Promise.resolve({
71
+ send_transactional: "0",
72
+ did_you_mean: `${localPart}@yopmail.com`,
73
+ code: "6"
74
+ });
75
+ }
76
+ return Promise.resolve({
77
+ send_transactional: "1",
78
+ did_you_mean: void 0,
79
+ code: "200"
80
+ });
81
+ }
82
+
83
+ const mockDebounceClientFactory = () => {
84
+ return {
85
+ singleValidation: mockSingleValidation,
86
+ ping: mockPingDebounce
87
+ };
88
+ };
89
+ const debounceClientFactory = (apiKey, config) => {
90
+ return {
91
+ singleValidation: singleValidationFactory(apiKey, config),
92
+ ping: pingDebounceFactory(apiKey, config)
93
+ };
94
+ };
58
95
 
59
- exports.pingDebounceFactory = pingDebounceFactory;
60
- exports.singleValidationFactory = singleValidationFactory;
96
+ exports.debounceClientFactory = debounceClientFactory;
97
+ exports.mockDebounceClientFactory = mockDebounceClientFactory;
@@ -1,37 +1,39 @@
1
+ import { DebounceSingleValidationSuccessResponse } from '#src/types';
2
+
3
+ declare function mockPingDebounce(): Promise<boolean>;
4
+
1
5
  /**
2
- * Perform a single email validation request.
6
+ * Mock single email validation response.
3
7
  *
4
- * @see https://developers.debounce.io/reference/single-validation#response-parameters
8
+ * @see https://developers.debounce.com/api-reference/endpoint/single-validation#single-email-validation
5
9
  * @param apiKey the debounce.io API key
6
10
  * @param config the Axios request config
7
11
  * @returns Debounce Single Validation response
8
12
  */
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?: {
13
+ declare function mockSingleValidation(email: string): Promise<DebounceSingleValidationSuccessResponse["debounce"]>;
14
+
15
+ declare const mockDebounceClientFactory: () => {
16
+ singleValidation: typeof mockSingleValidation;
17
+ ping: typeof mockPingDebounce;
18
+ };
19
+ declare const debounceClientFactory: (apiKey: string, config?: {
22
20
  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
- }>;
33
- type SingleValidationHandler = ReturnType<typeof singleValidationFactory>;
21
+ }) => {
22
+ singleValidation: (email: string) => Promise<{
23
+ email: string;
24
+ code: string;
25
+ role: string;
26
+ free_email: string;
27
+ result: string;
28
+ reason: string;
29
+ send_transactional: string;
30
+ did_you_mean: string;
31
+ }>;
32
+ ping: () => Promise<boolean>;
33
+ };
34
+
35
+ type DebounceClientType = ReturnType<typeof debounceClientFactory>;
34
36
 
35
- export { pingDebounceFactory, singleValidationFactory };
36
- export type { SingleValidationHandler };
37
+ export { debounceClientFactory, mockDebounceClientFactory };
38
+ export type { DebounceClientType };
37
39
  //# sourceMappingURL=index.d.ts.map
@@ -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;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":[]}
1
+ {"version":3,"file":"index.d.ts","sources":["../../src/api/ping.ts","../../src/api/single-validation.ts","../../src/api/index.ts"],"mappings":";;AAyBA,iBAAgB,gBAAgB;;ACYhC;;;;;;;;AASA,iBAAgB,oBAAoB,iBAEjC,OAAO,CAAC,uCAAuC;;ACxClD,cAAM,yBAAyB;;;;AAO/B,cAAM,qBAAqB;;;;;;;;;;;;;;;;AAWrB,KAAM,kBAAkB,GAAG,UAAU,QAAQ,qBAAqB","names":[]}
package/dist/api/index.js CHANGED
@@ -18,12 +18,10 @@ async function request(url, options) {
18
18
  }
19
19
  }
20
20
 
21
- function singleValidationFactory(apiKey, config) {
22
- return async function singleValidation(email) {
23
- const {
24
- data: { debounce }
25
- } = await request(
26
- `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
21
+ function pingDebounceFactory(apiKey, config) {
22
+ return async function pingDebounce() {
23
+ await request(
24
+ `https://api.debounce.io/v1/balance?api=${apiKey}`,
27
25
  {
28
26
  method: "get",
29
27
  headers: {
@@ -32,16 +30,19 @@ function singleValidationFactory(apiKey, config) {
32
30
  timeout: config?.timeout
33
31
  }
34
32
  );
35
- return debounce;
33
+ return true;
36
34
  };
37
35
  }
38
- function pingDebounceFactory(apiKey, config) {
39
- return async function pingDebounce() {
40
- const mockEmail = "user@example.com";
36
+ function mockPingDebounce() {
37
+ return Promise.resolve(true);
38
+ }
39
+
40
+ function singleValidationFactory(apiKey, config) {
41
+ return async function singleValidation(email) {
41
42
  const {
42
43
  data: { debounce }
43
44
  } = await request(
44
- `https://api.debounce.io/v1/?email=${mockEmail}&api=${apiKey}`,
45
+ `https://api.debounce.io/v1/?email=${encodeURIComponent(email)}&api=${encodeURIComponent(apiKey)}`,
45
46
  {
46
47
  method: "get",
47
48
  headers: {
@@ -53,5 +54,41 @@ function pingDebounceFactory(apiKey, config) {
53
54
  return debounce;
54
55
  };
55
56
  }
57
+ function mockSingleValidation(email) {
58
+ const localPart = email.split("@")[0];
59
+ const domain = email.split("@")[1];
60
+ if (domain === "invalid-domain.com") {
61
+ return Promise.resolve({
62
+ send_transactional: "0",
63
+ did_you_mean: "",
64
+ code: "6"
65
+ });
66
+ }
67
+ if (domain === "ypomail.com") {
68
+ return Promise.resolve({
69
+ send_transactional: "0",
70
+ did_you_mean: `${localPart}@yopmail.com`,
71
+ code: "6"
72
+ });
73
+ }
74
+ return Promise.resolve({
75
+ send_transactional: "1",
76
+ did_you_mean: void 0,
77
+ code: "200"
78
+ });
79
+ }
80
+
81
+ const mockDebounceClientFactory = () => {
82
+ return {
83
+ singleValidation: mockSingleValidation,
84
+ ping: mockPingDebounce
85
+ };
86
+ };
87
+ const debounceClientFactory = (apiKey, config) => {
88
+ return {
89
+ singleValidation: singleValidationFactory(apiKey, config),
90
+ ping: pingDebounceFactory(apiKey, config)
91
+ };
92
+ };
56
93
 
57
- export { pingDebounceFactory, singleValidationFactory };
94
+ export { debounceClientFactory, mockDebounceClientFactory };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.debounce",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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,8 +36,8 @@
36
36
  "test": "tsx --test --test-reporter=spec src/**/*.test.ts"
37
37
  },
38
38
  "dependencies": {
39
- "axios": "^1.15.0",
40
- "zod": "^4.3.5"
39
+ "axios": "^1.21.1",
40
+ "zod": "^4.6.7"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
package/src/api/index.ts CHANGED
@@ -1,3 +1,27 @@
1
1
  //
2
2
 
3
- export * from "./single-validation.js";
3
+ import { mockPingDebounce, pingDebounceFactory } from "./ping.js";
4
+ import {
5
+ mockSingleValidation,
6
+ singleValidationFactory,
7
+ } from "./single-validation.js";
8
+
9
+ const mockDebounceClientFactory = () => {
10
+ return {
11
+ singleValidation: mockSingleValidation,
12
+ ping: mockPingDebounce,
13
+ };
14
+ };
15
+
16
+ const debounceClientFactory = (
17
+ apiKey: string,
18
+ config?: { timeout?: number },
19
+ ) => {
20
+ return {
21
+ singleValidation: singleValidationFactory(apiKey, config),
22
+ ping: pingDebounceFactory(apiKey, config),
23
+ };
24
+ };
25
+
26
+ export { debounceClientFactory, mockDebounceClientFactory };
27
+ export type DebounceClientType = ReturnType<typeof debounceClientFactory>;
@@ -0,0 +1,28 @@
1
+ //
2
+
3
+ import type { DebounceBalanceSuccessResponse } from "#src/types";
4
+ import { request } from "./request.js";
5
+
6
+ export function pingDebounceFactory(
7
+ apiKey: string,
8
+ config?: { timeout?: number },
9
+ ) {
10
+ return async function pingDebounce() {
11
+ await request<DebounceBalanceSuccessResponse>(
12
+ `https://api.debounce.io/v1/balance?api=${apiKey}`,
13
+ {
14
+ method: "get",
15
+ headers: {
16
+ accept: "application/json",
17
+ },
18
+ timeout: config?.timeout,
19
+ },
20
+ );
21
+
22
+ return true;
23
+ };
24
+ }
25
+
26
+ export function mockPingDebounce() {
27
+ return Promise.resolve(true);
28
+ }
@@ -1,6 +1,6 @@
1
1
  //
2
2
 
3
- import type { DebounceSuccessResponse } from "#src/types";
3
+ import type { DebounceSingleValidationSuccessResponse } from "#src/types";
4
4
  import { request } from "./request.js";
5
5
 
6
6
  //
@@ -8,7 +8,7 @@ import { request } from "./request.js";
8
8
  /**
9
9
  * Perform a single email validation request.
10
10
  *
11
- * @see https://developers.debounce.io/reference/single-validation#response-parameters
11
+ * @see https://developers.debounce.com/api-reference/endpoint/single-validation#single-email-validation
12
12
  * @param apiKey the debounce.io API key
13
13
  * @param config the Axios request config
14
14
  * @returns Debounce Single Validation response
@@ -20,8 +20,8 @@ export function singleValidationFactory(
20
20
  return async function singleValidation(email: string) {
21
21
  const {
22
22
  data: { debounce },
23
- } = await request<DebounceSuccessResponse>(
24
- `https://api.debounce.io/v1/?email=${email}&api=${apiKey}`,
23
+ } = await request<DebounceSingleValidationSuccessResponse>(
24
+ `https://api.debounce.io/v1/?email=${encodeURIComponent(email)}&api=${encodeURIComponent(apiKey)}`,
25
25
  {
26
26
  method: "get",
27
27
  headers: {
@@ -35,27 +35,39 @@ 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
- );
38
+ /**
39
+ * Mock single email validation response.
40
+ *
41
+ * @see https://developers.debounce.com/api-reference/endpoint/single-validation#single-email-validation
42
+ * @param apiKey the debounce.io API key
43
+ * @param config the Axios request config
44
+ * @returns Debounce Single Validation response
45
+ */
56
46
 
57
- return debounce;
58
- };
47
+ export function mockSingleValidation(
48
+ email: string,
49
+ ): Promise<DebounceSingleValidationSuccessResponse["debounce"]> {
50
+ const localPart = email.split("@")[0];
51
+ const domain = email.split("@")[1];
52
+ if (domain === "invalid-domain.com") {
53
+ return Promise.resolve({
54
+ send_transactional: "0",
55
+ did_you_mean: "",
56
+ code: "6",
57
+ }) as any;
58
+ }
59
+ if (domain === "ypomail.com") {
60
+ return Promise.resolve({
61
+ send_transactional: "0",
62
+ did_you_mean: `${localPart}@yopmail.com`,
63
+ code: "6",
64
+ }) as any;
65
+ }
66
+ return Promise.resolve({
67
+ send_transactional: "1",
68
+ did_you_mean: undefined,
69
+ code: "200",
70
+ }) as any;
59
71
  }
60
72
 
61
73
  export type SingleValidationHandler = ReturnType<
@@ -14,7 +14,7 @@ export interface DebounceErrorResponse {
14
14
  /**
15
15
  * @see https://developers.debounce.io/reference/responses#success-response
16
16
  */
17
- export interface DebounceSuccessResponse {
17
+ export interface DebounceSingleValidationSuccessResponse {
18
18
  debounce: {
19
19
  // The email address you are requesting to validate.
20
20
  // ex: 'test@wanadoo.rf'
@@ -45,3 +45,7 @@ export interface DebounceSuccessResponse {
45
45
  success: "1";
46
46
  balance: `${number}`;
47
47
  }
48
+
49
+ export interface DebounceBalanceSuccessResponse {
50
+ balance: `${number}`;
51
+ }