@cofondateurauchomage/libs 1.0.46 → 1.0.48
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/build/const.d.ts +1 -0
- package/build/const.js +2 -1
- package/build/validate.d.ts +2 -3
- package/build/validate.js +4 -4
- 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 validateBodyForO<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.validateBodyForO = 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 validateBodyForO(route, body) {
|
|
114
|
+
return (0, validate_1.validateBody)(body, validatorsForAllRoutes[route]);
|
|
115
|
+
}
|
|
116
|
+
exports.validateBodyForO = validateBodyForO;
|
package/build/const.d.ts
CHANGED
package/build/const.js
CHANGED
package/build/validate.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BodyForO, CloudFunctionNames, RouteNames } from "./api";
|
|
2
1
|
export type ValidatorFn = (value: unknown) => boolean;
|
|
3
2
|
/**
|
|
4
3
|
* Class representing a custom validator.
|
|
@@ -79,7 +78,7 @@ export declare class ValidationError extends Error {
|
|
|
79
78
|
* Validate the request body against the provided validators.
|
|
80
79
|
* @param body - Body to validate.
|
|
81
80
|
* @param validators - validator for each key of the body.
|
|
82
|
-
* @returns {
|
|
81
|
+
* @returns {O} - The validated body.
|
|
83
82
|
* @throws {ValidationError} - Throws a ValidationError exception if validation fails.
|
|
84
83
|
*/
|
|
85
|
-
export declare function
|
|
84
|
+
export declare function validateBody<O extends Record<string, any>>(body: unknown, validators: Record<keyof O, Validator>): O;
|
package/build/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateBody = exports.ValidationError = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Class representing a custom validator.
|
|
6
6
|
*/
|
|
@@ -130,10 +130,10 @@ exports.ValidationError = ValidationError;
|
|
|
130
130
|
* Validate the request body against the provided validators.
|
|
131
131
|
* @param body - Body to validate.
|
|
132
132
|
* @param validators - validator for each key of the body.
|
|
133
|
-
* @returns {
|
|
133
|
+
* @returns {O} - The validated body.
|
|
134
134
|
* @throws {ValidationError} - Throws a ValidationError exception if validation fails.
|
|
135
135
|
*/
|
|
136
|
-
function
|
|
136
|
+
function validateBody(body, validators) {
|
|
137
137
|
if (typeof body !== "object" || body === null) {
|
|
138
138
|
throw new ValidationError(400, "Body non fourni ou invalide");
|
|
139
139
|
}
|
|
@@ -146,4 +146,4 @@ function validateBodyForO(body, validators) {
|
|
|
146
146
|
}
|
|
147
147
|
return result;
|
|
148
148
|
}
|
|
149
|
-
exports.
|
|
149
|
+
exports.validateBody = validateBody;
|