@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.
@@ -1,21 +1,8 @@
1
- export declare const ValidateBodyOf: {
2
- createProjectCall: (body: unknown) => Omit<import("./db.model").IProject, "active" | "clicks" | "creationDate" | "likes" | "stripeId">;
3
- setProjectCall: (body: unknown) => Pick<import("./db.model").IProject, "description" | "city" | "invest" | "linkedin" | "partner" | "skills" | "tel" | "zipCode">;
4
- deleteProjectCall: (body: unknown) => {};
5
- setStripeIdProjectCall: (body: unknown) => Pick<import("./db.model").IProject, "stripeId" | "email">;
6
- setActiveProjectCall: (body: unknown) => Pick<import("./db.model").IProject, "active" | "stripeId">;
7
- createUserCall: (body: unknown) => Omit<import("./db.model").IUser, "clicks" | "creationDate" | "likes">;
8
- setUserCall: (body: unknown) => Pick<import("./db.model").IUser, "city" | "invest" | "linkedin" | "partner" | "skills" | "tel" | "zipCode" | "business" | "motivations">;
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>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateBodyOf = void 0;
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
- // Utils
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
- exports.ValidateBodyOf = {
29
+ const validatorsForAllRoutes = {
30
30
  ///////////////////
31
31
  // Cloud functions
32
- createProjectCall: (body) => (0, validate_1.validateBodyForO)(body, {
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: (body) => (0, validate_1.validateBodyForO)(body, {
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: (body) => (0, validate_1.validateBodyForO)(body, {}),
58
- setStripeIdProjectCall: (body) => (0, validate_1.validateBodyForO)(body, {
56
+ },
57
+ deleteProjectCall: {},
58
+ setStripeIdProjectCall: {
59
59
  email,
60
60
  stripeId,
61
- }),
62
- setActiveProjectCall: (body) => (0, validate_1.validateBodyForO)(body, {
61
+ },
62
+ setActiveProjectCall: {
63
63
  active: (0, validate_1.isBoolean)(),
64
64
  stripeId,
65
- }),
66
- createUserCall: (body) => (0, validate_1.validateBodyForO)(body, {
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: (body) => (0, validate_1.validateBodyForO)(body, {
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: (body) => (0, validate_1.validateBodyForO)(body, {}),
91
+ },
92
+ deleteUserCall: {},
93
93
  //////////
94
94
  // Routes
95
- checkout_session: (body) => (0, validate_1.validateBodyForO)(body, {
95
+ checkout_session: {
96
96
  stripeId: stripeId.isOptional(),
97
97
  email,
98
- }),
99
- delete_customer: (body) => (0, validate_1.validateBodyForO)(body, {
98
+ },
99
+ delete_customer: {
100
100
  stripeId,
101
- }),
102
- portal_session: (body) => (0, validate_1.validateBodyForO)(body, {
101
+ },
102
+ portal_session: {
103
103
  stripeId,
104
- }),
105
- webhook: (body) => (0, validate_1.validateBodyForO)(body, {}),
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
@@ -1,2 +1,3 @@
1
1
  import { TSkill } from "./db.model";
2
+ export declare const EMAIL = "contact@cofondateurauchomage.fr";
2
3
  export declare const SKILLS: TSkill[];
package/build/const.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SKILLS = void 0;
3
+ exports.SKILLS = exports.EMAIL = void 0;
4
+ exports.EMAIL = "contact@cofondateurauchomage.fr";
4
5
  exports.SKILLS = [
5
6
  "Business",
6
7
  "Design",
@@ -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 {BodyForO<O>} - The validated body.
81
+ * @returns {O} - The validated body.
83
82
  * @throws {ValidationError} - Throws a ValidationError exception if validation fails.
84
83
  */
85
- export declare function validateBodyForO<O extends CloudFunctionNames | RouteNames>(body: unknown, validators: Record<keyof BodyForO<O>, Validator>): BodyForO<O>;
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.validateBodyForO = exports.ValidationError = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
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 {BodyForO<O>} - The validated body.
133
+ * @returns {O} - The validated body.
134
134
  * @throws {ValidationError} - Throws a ValidationError exception if validation fails.
135
135
  */
136
- function validateBodyForO(body, validators) {
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.validateBodyForO = validateBodyForO;
149
+ exports.validateBody = validateBody;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {