@cofondateurauchomage/libs 1.1.80 → 1.1.84
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.d.ts +24 -24
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +1 -0
- package/build/utils/stringUtils.d.ts +7 -0
- package/build/utils/stringUtils.js +21 -0
- package/build/validate.js +12 -6
- package/package.json +1 -1
package/build/api.d.ts
CHANGED
|
@@ -60,33 +60,33 @@ type WriteResult = {
|
|
|
60
60
|
writeTime: Timestamp;
|
|
61
61
|
};
|
|
62
62
|
export type ResponseForO<O extends CloudFunctionNames | RouteNames> = {
|
|
63
|
-
createProject:
|
|
64
|
-
deleteProject:
|
|
65
|
-
updateProject:
|
|
66
|
-
createUser:
|
|
67
|
-
deleteUser:
|
|
68
|
-
updateUser:
|
|
69
|
-
updateVisibility:
|
|
70
|
-
addStripeId:
|
|
71
|
-
updatePlan:
|
|
72
|
-
addStatsAssociation:
|
|
73
|
-
updateNewsletter:
|
|
74
|
-
createProspect:
|
|
63
|
+
createProject: WriteResult;
|
|
64
|
+
deleteProject: WriteResult;
|
|
65
|
+
updateProject: WriteResult;
|
|
66
|
+
createUser: WriteResult;
|
|
67
|
+
deleteUser: WriteResult;
|
|
68
|
+
updateUser: WriteResult;
|
|
69
|
+
updateVisibility: WriteResult;
|
|
70
|
+
addStripeId: WriteResult;
|
|
71
|
+
updatePlan: WriteResult;
|
|
72
|
+
addStatsAssociation: WriteResult;
|
|
73
|
+
updateNewsletter: WriteResult;
|
|
74
|
+
createProspect: {
|
|
75
75
|
id: string;
|
|
76
|
-
} | null
|
|
77
|
-
getProspect:
|
|
78
|
-
updateProspect:
|
|
79
|
-
createReaction:
|
|
80
|
-
deleteReaction:
|
|
81
|
-
checkout_session:
|
|
76
|
+
} | null;
|
|
77
|
+
getProspect: IProspect;
|
|
78
|
+
updateProspect: WriteResult | null;
|
|
79
|
+
createReaction: WriteResult;
|
|
80
|
+
deleteReaction: WriteResult;
|
|
81
|
+
checkout_session: {
|
|
82
82
|
sessionId: string;
|
|
83
|
-
}
|
|
84
|
-
delete_customer:
|
|
83
|
+
};
|
|
84
|
+
delete_customer: {
|
|
85
85
|
success: boolean;
|
|
86
|
-
}
|
|
87
|
-
portal_session:
|
|
86
|
+
};
|
|
87
|
+
portal_session: {
|
|
88
88
|
url: string;
|
|
89
|
-
}
|
|
90
|
-
webhook:
|
|
89
|
+
};
|
|
90
|
+
webhook: void;
|
|
91
91
|
}[O];
|
|
92
92
|
export {};
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./arrayUtils"), exports);
|
|
18
18
|
__exportStar(require("./objectUtils"), exports);
|
|
19
|
+
__exportStar(require("./stringUtils"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Capitalize the first letter of each words separated by a space or a hyphen
|
|
6
|
+
* and prevent double space
|
|
7
|
+
* @param str
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function capitalize(str) {
|
|
11
|
+
return str
|
|
12
|
+
.toLowerCase()
|
|
13
|
+
.split(" ")
|
|
14
|
+
.map((w) => w && w[0].toUpperCase() + w.slice(1))
|
|
15
|
+
.join(" ")
|
|
16
|
+
.split("-")
|
|
17
|
+
.map((w) => w && w[0].toUpperCase() + w.slice(1))
|
|
18
|
+
.join("-")
|
|
19
|
+
.replace(" ", " ");
|
|
20
|
+
}
|
|
21
|
+
exports.capitalize = capitalize;
|
package/build/validate.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//////////////
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.validateBody = exports.ValidationError = exports.isMatchEnum = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
5
6
|
const arrayUtils_1 = require("./utils/arrayUtils");
|
|
6
7
|
/**
|
|
7
8
|
* Class representing a custom validator.
|
|
@@ -32,7 +33,12 @@ class Validator {
|
|
|
32
33
|
return true;
|
|
33
34
|
}
|
|
34
35
|
if (!this.fn(value)) {
|
|
35
|
-
|
|
36
|
+
if (!value) {
|
|
37
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} requis`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} invalide`);
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
if (this.min !== undefined || this.max !== undefined) {
|
|
38
44
|
return this.checkMinMax(key, value, this.min, this.max);
|
|
@@ -71,13 +77,13 @@ class Validator {
|
|
|
71
77
|
const nb = typeof value === "string" ? value.length : value;
|
|
72
78
|
if (min !== undefined && nb < min) {
|
|
73
79
|
throw new ValidationError(400, typeof value === "string"
|
|
74
|
-
? `Le texte ${key} n'est pas assez long, il manque ${min - nb} caractères`
|
|
75
|
-
: `La valeur de ${key} est trop basse, minimum: ${min}`);
|
|
80
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} n'est pas assez long, il manque ${min - nb} caractères`
|
|
81
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop basse, minimum: ${min}`);
|
|
76
82
|
}
|
|
77
83
|
if (max !== undefined && nb > max) {
|
|
78
84
|
throw new ValidationError(400, typeof value === "string"
|
|
79
|
-
? `Le texte ${key} est trop long, il y a ${nb - max} caractères en trop`
|
|
80
|
-
: `La valeur de ${key} est trop haute, maximum: ${max}`);
|
|
85
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} est trop long, il y a ${nb - max} caractères en trop`
|
|
86
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop haute, maximum: ${max}`);
|
|
81
87
|
}
|
|
82
88
|
return true;
|
|
83
89
|
}
|
|
@@ -143,7 +149,7 @@ exports.ValidationError = ValidationError;
|
|
|
143
149
|
*/
|
|
144
150
|
function validateBody(body, validators) {
|
|
145
151
|
if (typeof body !== "object" || body === null) {
|
|
146
|
-
throw new ValidationError(400, "
|
|
152
|
+
throw new ValidationError(400, "Le payload est requis");
|
|
147
153
|
}
|
|
148
154
|
const result = {};
|
|
149
155
|
for (const [key, validator] of Object.entries(validators)) {
|