@cofondateurauchomage/libs 1.0.46 → 1.0.47
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/build/api.validate.d.ts +8 -21
- package/build/api.validate.js +35 -25
- package/package.json +1 -1
package/build/api.validate.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
deleteUserCall: (body: unknown) => {};
|
|
10
|
-
checkout_session: (body: unknown) => {
|
|
11
|
-
stripeId?: string | undefined;
|
|
12
|
-
email: string;
|
|
13
|
-
};
|
|
14
|
-
delete_customer: (body: unknown) => {
|
|
15
|
-
stripeId: string;
|
|
16
|
-
};
|
|
17
|
-
portal_session: (body: unknown) => {
|
|
18
|
-
stripeId: string;
|
|
19
|
-
};
|
|
20
|
-
webhook: (body: unknown) => {};
|
|
21
|
-
};
|
|
1
|
+
import { BodyForO, CloudFunctionNames, RouteNames } from "./api";
|
|
2
|
+
/**
|
|
3
|
+
* Validate the request body depending on the route.
|
|
4
|
+
* @param route - Route to know which validators to use.
|
|
5
|
+
* @param body - Body to validate.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateBody<O extends CloudFunctionNames | RouteNames>(route: O, body: unknown): BodyForO<O>;
|
package/build/api.validate.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateBody = void 0;
|
|
4
4
|
const const_1 = require("./const");
|
|
5
5
|
const regex_1 = require("./regex");
|
|
6
6
|
const validate_1 = require("./validate");
|
|
7
|
-
|
|
8
|
-
//
|
|
7
|
+
//////////////
|
|
8
|
+
// Validators
|
|
9
9
|
const business = (0, validate_1.isString)().setMin(10).setMax(300);
|
|
10
10
|
const city = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
11
11
|
const description = (0, validate_1.isString)().setMin(10).setMax(500);
|
|
@@ -26,10 +26,10 @@ const skills = new validate_1.Validator((value) => value &&
|
|
|
26
26
|
const stripeId = (0, validate_1.isString)().setMin(4).setMax(50);
|
|
27
27
|
const tel = (0, validate_1.isMatchRegex)(regex_1.RGX.Tel.regex).isOptional();
|
|
28
28
|
const zipCode = (0, validate_1.isNumber)().setMin(1000).setMax(97680);
|
|
29
|
-
|
|
29
|
+
const validatorsForAllRoutes = {
|
|
30
30
|
///////////////////
|
|
31
31
|
// Cloud functions
|
|
32
|
-
createProjectCall:
|
|
32
|
+
createProjectCall: {
|
|
33
33
|
city,
|
|
34
34
|
description,
|
|
35
35
|
email,
|
|
@@ -43,8 +43,8 @@ exports.ValidateBodyOf = {
|
|
|
43
43
|
skills,
|
|
44
44
|
tel,
|
|
45
45
|
zipCode,
|
|
46
|
-
}
|
|
47
|
-
setProjectCall:
|
|
46
|
+
},
|
|
47
|
+
setProjectCall: {
|
|
48
48
|
city,
|
|
49
49
|
description,
|
|
50
50
|
invest,
|
|
@@ -53,17 +53,17 @@ exports.ValidateBodyOf = {
|
|
|
53
53
|
skills,
|
|
54
54
|
tel,
|
|
55
55
|
zipCode,
|
|
56
|
-
}
|
|
57
|
-
deleteProjectCall:
|
|
58
|
-
setStripeIdProjectCall:
|
|
56
|
+
},
|
|
57
|
+
deleteProjectCall: {},
|
|
58
|
+
setStripeIdProjectCall: {
|
|
59
59
|
email,
|
|
60
60
|
stripeId,
|
|
61
|
-
}
|
|
62
|
-
setActiveProjectCall:
|
|
61
|
+
},
|
|
62
|
+
setActiveProjectCall: {
|
|
63
63
|
active: (0, validate_1.isBoolean)(),
|
|
64
64
|
stripeId,
|
|
65
|
-
}
|
|
66
|
-
createUserCall:
|
|
65
|
+
},
|
|
66
|
+
createUserCall: {
|
|
67
67
|
business,
|
|
68
68
|
city,
|
|
69
69
|
email,
|
|
@@ -77,8 +77,8 @@ exports.ValidateBodyOf = {
|
|
|
77
77
|
skills,
|
|
78
78
|
tel,
|
|
79
79
|
zipCode,
|
|
80
|
-
}
|
|
81
|
-
setUserCall:
|
|
80
|
+
},
|
|
81
|
+
setUserCall: {
|
|
82
82
|
business,
|
|
83
83
|
city,
|
|
84
84
|
invest,
|
|
@@ -88,19 +88,29 @@ exports.ValidateBodyOf = {
|
|
|
88
88
|
skills,
|
|
89
89
|
tel,
|
|
90
90
|
zipCode,
|
|
91
|
-
}
|
|
92
|
-
deleteUserCall:
|
|
91
|
+
},
|
|
92
|
+
deleteUserCall: {},
|
|
93
93
|
//////////
|
|
94
94
|
// Routes
|
|
95
|
-
checkout_session:
|
|
95
|
+
checkout_session: {
|
|
96
96
|
stripeId: stripeId.isOptional(),
|
|
97
97
|
email,
|
|
98
|
-
}
|
|
99
|
-
delete_customer:
|
|
98
|
+
},
|
|
99
|
+
delete_customer: {
|
|
100
100
|
stripeId,
|
|
101
|
-
}
|
|
102
|
-
portal_session:
|
|
101
|
+
},
|
|
102
|
+
portal_session: {
|
|
103
103
|
stripeId,
|
|
104
|
-
}
|
|
105
|
-
webhook:
|
|
104
|
+
},
|
|
105
|
+
webhook: {},
|
|
106
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Validate the request body depending on the route.
|
|
109
|
+
* @param route - Route to know which validators to use.
|
|
110
|
+
* @param body - Body to validate.
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
function validateBody(route, body) {
|
|
114
|
+
return (0, validate_1.validateBodyForO)(body, validatorsForAllRoutes[route]);
|
|
115
|
+
}
|
|
116
|
+
exports.validateBody = validateBody;
|