@cofondateurauchomage/libs 1.1.111 → 1.1.113
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.js +1 -2
- package/build/db.model.js +1 -1
- package/build/src/api.d.ts +98 -0
- package/build/src/api.js +2 -0
- package/build/src/api.validate.d.ts +8 -0
- package/build/src/api.validate.js +221 -0
- package/build/src/const.d.ts +6 -0
- package/build/src/const.js +23 -0
- package/build/src/db.model.d.ts +125 -0
- package/build/src/db.model.js +16 -0
- package/build/src/index.d.ts +7 -0
- package/build/src/index.js +23 -0
- package/build/src/regex.d.ts +25 -0
- package/build/src/regex.js +36 -0
- package/build/src/utils/arrayUtils.d.ts +12 -0
- package/build/src/utils/arrayUtils.js +26 -0
- package/build/src/utils/index.d.ts +3 -0
- package/build/src/utils/index.js +19 -0
- package/build/src/utils/objectUtils.d.ts +25 -0
- package/build/src/utils/objectUtils.js +79 -0
- package/build/src/utils/stringUtils.d.ts +7 -0
- package/build/src/utils/stringUtils.js +20 -0
- package/build/src/validate.d.ts +89 -0
- package/build/src/validate.js +163 -0
- package/build/utils/arrayUtils.js +3 -3
- package/build/utils/objectUtils.js +7 -8
- package/build/utils/stringUtils.js +1 -2
- package/build/validate.js +2 -2
- package/package.json +3 -3
package/build/api.validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateBodyForO =
|
|
3
|
+
exports.validateBodyForO = validateBodyForO;
|
|
4
4
|
const const_1 = require("./const");
|
|
5
5
|
const regex_1 = require("./regex");
|
|
6
6
|
const validate_1 = require("./validate");
|
|
@@ -219,4 +219,3 @@ const validatorsForAllRoutes = {
|
|
|
219
219
|
function validateBodyForO(route, body) {
|
|
220
220
|
return (0, validate_1.validateBody)(body, validatorsForAllRoutes[route]);
|
|
221
221
|
}
|
|
222
|
-
exports.validateBodyForO = validateBodyForO;
|
package/build/db.model.js
CHANGED
|
@@ -13,4 +13,4 @@ var Collections;
|
|
|
13
13
|
Collections["reactions"] = "reactions";
|
|
14
14
|
Collections["visits"] = "visits";
|
|
15
15
|
Collections["blogHtmlArticles"] = "blog_html_articles";
|
|
16
|
-
})(Collections
|
|
16
|
+
})(Collections || (exports.Collections = Collections = {}));
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { IBlogHtmlArticle, IContact, INewsletter, IProject, IProspect, IReactionStatus, IUser, TPlan, TVisibility } from "./db.model";
|
|
2
|
+
export type CloudFunctionNames = "createProject" | "updateProject" | "deleteProject" | "createUser" | "updateUser" | "deleteUser" | "updateVisibility" | "addStripeId" | "updatePlan" | "addStatsAssociation" | "updateNewsletter" | "createProspect" | "getProspect" | "updateProspect" | "createReaction" | "deleteReaction" | "createBlogHtmlArticle";
|
|
3
|
+
export type RouteNames = "checkout_session" | "delete_customer" | "portal_session" | "webhook";
|
|
4
|
+
export type BodyForO<O extends CloudFunctionNames | RouteNames> = {
|
|
5
|
+
createProject: Omit<IProject, "id" | "plan" | "visibility" | "clicks" | "creationDate" | "lastConnection" | "likes" | "stripeId" | "active" | "referrer" | "postedOnLinkedInAt"> & IContact & {
|
|
6
|
+
newsletterMarketing?: boolean;
|
|
7
|
+
emailProspect: string;
|
|
8
|
+
};
|
|
9
|
+
deleteProject: {};
|
|
10
|
+
updateProject: Pick<IProject, "name" | "lastName" | "firstName" | "skills" | "yearsOfExperience" | "zipCode" | "city" | "invest" | "status" | "status_detail" | "turnover" | "description" | "partner" | "logo" | "availability"> & Omit<IContact, "email">;
|
|
11
|
+
createUser: Omit<IUser, "id" | "plan" | "visibility" | "clicks" | "creationDate" | "lastConnection" | "likes" | "stripeId" | "active" | "referrer"> & IContact & {
|
|
12
|
+
newsletterMarketing?: boolean;
|
|
13
|
+
emailProspect: string;
|
|
14
|
+
};
|
|
15
|
+
deleteUser: {};
|
|
16
|
+
updateUser: Pick<IUser, "lastName" | "firstName" | "skills" | "yearsOfExperience" | "zipCode" | "city" | "invest" | "motivations" | "partner" | "business" | "photo" | "availability"> & Omit<IContact, "email">;
|
|
17
|
+
updateVisibility: {
|
|
18
|
+
visibility: TVisibility;
|
|
19
|
+
};
|
|
20
|
+
addStripeId: {
|
|
21
|
+
apiSecretKey: string;
|
|
22
|
+
email: string;
|
|
23
|
+
stripeId: string;
|
|
24
|
+
};
|
|
25
|
+
updatePlan: {
|
|
26
|
+
apiSecretKey: string;
|
|
27
|
+
stripeId: string;
|
|
28
|
+
email: string;
|
|
29
|
+
plan: TPlan;
|
|
30
|
+
};
|
|
31
|
+
addStatsAssociation: {};
|
|
32
|
+
updateNewsletter: Omit<INewsletter, "new_profil_last_sent_date">;
|
|
33
|
+
createProspect: Pick<IProspect, "email" | "referrer">;
|
|
34
|
+
getProspect: Pick<IProspect, "email">;
|
|
35
|
+
updateProspect: Omit<IProspect, "creationDate" | "referrer">;
|
|
36
|
+
createReaction: {
|
|
37
|
+
toId: string;
|
|
38
|
+
status: IReactionStatus;
|
|
39
|
+
};
|
|
40
|
+
deleteReaction: {
|
|
41
|
+
toId: string;
|
|
42
|
+
};
|
|
43
|
+
createBlogHtmlArticle: Omit<IBlogHtmlArticle, "date"> & {
|
|
44
|
+
apiSecretKey: string;
|
|
45
|
+
};
|
|
46
|
+
checkout_session: {
|
|
47
|
+
stripeId?: string;
|
|
48
|
+
email: string;
|
|
49
|
+
type: "user" | "project";
|
|
50
|
+
planOption: "month" | "annual";
|
|
51
|
+
};
|
|
52
|
+
delete_customer: {
|
|
53
|
+
stripeId: string;
|
|
54
|
+
};
|
|
55
|
+
portal_session: {
|
|
56
|
+
stripeId: string;
|
|
57
|
+
};
|
|
58
|
+
webhook: {};
|
|
59
|
+
}[O];
|
|
60
|
+
type Timestamp = {
|
|
61
|
+
seconds: number;
|
|
62
|
+
nanoseconds: number;
|
|
63
|
+
};
|
|
64
|
+
type WriteResult = {
|
|
65
|
+
writeTime: Timestamp;
|
|
66
|
+
};
|
|
67
|
+
export type ResponseForO<O extends CloudFunctionNames | RouteNames> = {
|
|
68
|
+
createProject: WriteResult;
|
|
69
|
+
deleteProject: WriteResult;
|
|
70
|
+
updateProject: WriteResult;
|
|
71
|
+
createUser: WriteResult;
|
|
72
|
+
deleteUser: WriteResult;
|
|
73
|
+
updateUser: WriteResult;
|
|
74
|
+
updateVisibility: WriteResult;
|
|
75
|
+
addStripeId: WriteResult;
|
|
76
|
+
updatePlan: WriteResult;
|
|
77
|
+
addStatsAssociation: WriteResult;
|
|
78
|
+
updateNewsletter: WriteResult;
|
|
79
|
+
createProspect: {
|
|
80
|
+
id: string;
|
|
81
|
+
} | null;
|
|
82
|
+
getProspect: IProspect | null;
|
|
83
|
+
updateProspect: WriteResult | null;
|
|
84
|
+
createReaction: WriteResult;
|
|
85
|
+
deleteReaction: WriteResult;
|
|
86
|
+
createBlogHtmlArticle: WriteResult;
|
|
87
|
+
checkout_session: {
|
|
88
|
+
sessionId: string;
|
|
89
|
+
};
|
|
90
|
+
delete_customer: {
|
|
91
|
+
success: boolean;
|
|
92
|
+
};
|
|
93
|
+
portal_session: {
|
|
94
|
+
url: string;
|
|
95
|
+
};
|
|
96
|
+
webhook: void;
|
|
97
|
+
}[O];
|
|
98
|
+
export {};
|
package/build/src/api.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBodyForO = validateBodyForO;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const regex_1 = require("./regex");
|
|
6
|
+
const validate_1 = require("./validate");
|
|
7
|
+
//////////////
|
|
8
|
+
// Validators
|
|
9
|
+
const business = (0, validate_1.isString)().setMax(1000);
|
|
10
|
+
const city = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
11
|
+
const description = (0, validate_1.isString)().setMax(1000);
|
|
12
|
+
const email = (0, validate_1.isString)();
|
|
13
|
+
const firstName = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
14
|
+
const invest = (0, validate_1.isNumber)().setMin(0).setMax(1000000).isOptional();
|
|
15
|
+
const lastName = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
16
|
+
const linkedin = (0, validate_1.isMatchRegex)(regex_1.RGX.Linkedin.regex).isOptional();
|
|
17
|
+
const website = (0, validate_1.isString)().isOptional();
|
|
18
|
+
const motivations = (0, validate_1.isString)().setMax(1000).isOptional();
|
|
19
|
+
const name = (0, validate_1.isString)().setMax(50);
|
|
20
|
+
const partner = (0, validate_1.isString)().setMax(1000).isOptional();
|
|
21
|
+
const skills = new validate_1.Validator((value) => !!(value &&
|
|
22
|
+
Array.isArray(value) &&
|
|
23
|
+
value.length >= 1 &&
|
|
24
|
+
value.length <= 2 &&
|
|
25
|
+
value.every((skill) => const_1.SKILLS.includes(skill))));
|
|
26
|
+
const stripeId = (0, validate_1.isString)().setMax(50);
|
|
27
|
+
const zipCode = (0, validate_1.isNumber)().setMin(1000).setMax(97680);
|
|
28
|
+
const newsletterMarketing = (0, validate_1.isBoolean)().isOptional();
|
|
29
|
+
const status = (0, validate_1.isMatchEnum)(const_1.PROJECT_STATUS).isOptional();
|
|
30
|
+
const status_detail = (0, validate_1.isString)().setMax(1000).isOptional();
|
|
31
|
+
const photo = (0, validate_1.isString)().isOptional();
|
|
32
|
+
const logo = (0, validate_1.isString)().isOptional();
|
|
33
|
+
const plan = (0, validate_1.isMatchEnum)(["free", "pro", "premium"]);
|
|
34
|
+
const apiSecretKey = (0, validate_1.isString)();
|
|
35
|
+
const tel = (0, validate_1.isMatchRegex)(regex_1.RGX.Tel.regex).isOptional();
|
|
36
|
+
const reactionStatus = (0, validate_1.isMatchEnum)(["like", "dislike"]);
|
|
37
|
+
const turnover = (0, validate_1.isNumber)().setMin(0).isOptional();
|
|
38
|
+
const yearsOfExperience = (0, validate_1.isNumber)().setMin(0).setMax(100).isOptional();
|
|
39
|
+
const availability = (0, validate_1.isMatchEnum)(const_1.AVAILABILITY).isOptional();
|
|
40
|
+
const validatorsForAllRoutes = {
|
|
41
|
+
///////////////////
|
|
42
|
+
// Cloud functions
|
|
43
|
+
createProject: {
|
|
44
|
+
email,
|
|
45
|
+
emailProspect: email,
|
|
46
|
+
tel,
|
|
47
|
+
linkedin,
|
|
48
|
+
website,
|
|
49
|
+
name,
|
|
50
|
+
lastName,
|
|
51
|
+
firstName,
|
|
52
|
+
skills,
|
|
53
|
+
yearsOfExperience,
|
|
54
|
+
zipCode,
|
|
55
|
+
city,
|
|
56
|
+
invest,
|
|
57
|
+
status,
|
|
58
|
+
status_detail,
|
|
59
|
+
turnover,
|
|
60
|
+
description,
|
|
61
|
+
partner,
|
|
62
|
+
availability,
|
|
63
|
+
newsletterMarketing,
|
|
64
|
+
logo,
|
|
65
|
+
partner_swanbase: (0, validate_1.isBoolean)().isOptional(),
|
|
66
|
+
partner_iii: (0, validate_1.isBoolean)().isOptional(),
|
|
67
|
+
},
|
|
68
|
+
deleteProject: {},
|
|
69
|
+
updateProject: {
|
|
70
|
+
tel,
|
|
71
|
+
linkedin,
|
|
72
|
+
website,
|
|
73
|
+
name,
|
|
74
|
+
firstName,
|
|
75
|
+
lastName,
|
|
76
|
+
skills,
|
|
77
|
+
yearsOfExperience,
|
|
78
|
+
zipCode,
|
|
79
|
+
city,
|
|
80
|
+
invest,
|
|
81
|
+
status,
|
|
82
|
+
status_detail,
|
|
83
|
+
turnover,
|
|
84
|
+
description,
|
|
85
|
+
partner,
|
|
86
|
+
logo,
|
|
87
|
+
availability,
|
|
88
|
+
},
|
|
89
|
+
createUser: {
|
|
90
|
+
email,
|
|
91
|
+
emailProspect: email,
|
|
92
|
+
tel,
|
|
93
|
+
linkedin,
|
|
94
|
+
website,
|
|
95
|
+
lastName,
|
|
96
|
+
firstName,
|
|
97
|
+
business,
|
|
98
|
+
city,
|
|
99
|
+
invest,
|
|
100
|
+
joblessDate: (0, validate_1.isMatchRegex)(regex_1.RGX.Date.regex).isOptional(),
|
|
101
|
+
motivations,
|
|
102
|
+
partner,
|
|
103
|
+
skills,
|
|
104
|
+
yearsOfExperience,
|
|
105
|
+
zipCode,
|
|
106
|
+
newsletterMarketing,
|
|
107
|
+
photo,
|
|
108
|
+
availability,
|
|
109
|
+
},
|
|
110
|
+
deleteUser: {},
|
|
111
|
+
updateUser: {
|
|
112
|
+
tel,
|
|
113
|
+
linkedin,
|
|
114
|
+
website,
|
|
115
|
+
business,
|
|
116
|
+
city,
|
|
117
|
+
invest,
|
|
118
|
+
motivations,
|
|
119
|
+
partner,
|
|
120
|
+
skills,
|
|
121
|
+
yearsOfExperience,
|
|
122
|
+
zipCode,
|
|
123
|
+
photo,
|
|
124
|
+
firstName,
|
|
125
|
+
lastName,
|
|
126
|
+
availability,
|
|
127
|
+
},
|
|
128
|
+
updateVisibility: {
|
|
129
|
+
visibility: (0, validate_1.isMatchEnum)(["public", "limited", "private"]),
|
|
130
|
+
},
|
|
131
|
+
addStripeId: {
|
|
132
|
+
apiSecretKey,
|
|
133
|
+
email,
|
|
134
|
+
stripeId,
|
|
135
|
+
},
|
|
136
|
+
updatePlan: {
|
|
137
|
+
apiSecretKey,
|
|
138
|
+
stripeId,
|
|
139
|
+
email: (0, validate_1.isString)(),
|
|
140
|
+
plan,
|
|
141
|
+
},
|
|
142
|
+
addStatsAssociation: {},
|
|
143
|
+
updateNewsletter: {
|
|
144
|
+
match: (0, validate_1.isBoolean)().isOptional(),
|
|
145
|
+
marketing: (0, validate_1.isBoolean)().isOptional(),
|
|
146
|
+
notification: (0, validate_1.isBoolean)().isOptional(),
|
|
147
|
+
feature: (0, validate_1.isBoolean)().isOptional(),
|
|
148
|
+
new_profil: (0, validate_1.isBoolean)().isOptional(),
|
|
149
|
+
},
|
|
150
|
+
createProspect: {
|
|
151
|
+
email,
|
|
152
|
+
referrer: (0, validate_1.isString)().isOptional(),
|
|
153
|
+
},
|
|
154
|
+
getProspect: {
|
|
155
|
+
email,
|
|
156
|
+
},
|
|
157
|
+
updateProspect: {
|
|
158
|
+
email,
|
|
159
|
+
tel: tel.isOptional(),
|
|
160
|
+
linkedin: linkedin.isOptional(),
|
|
161
|
+
website: website.isOptional(),
|
|
162
|
+
lastName: lastName.isOptional(),
|
|
163
|
+
firstName: firstName.isOptional(),
|
|
164
|
+
business: business.isOptional(),
|
|
165
|
+
city: city.isOptional(),
|
|
166
|
+
invest: invest.isOptional(),
|
|
167
|
+
joblessDate: (0, validate_1.isMatchRegex)(regex_1.RGX.Date.regex).isOptional(),
|
|
168
|
+
motivations: motivations.isOptional(),
|
|
169
|
+
partner: partner.isOptional(),
|
|
170
|
+
skills: skills.isOptional(),
|
|
171
|
+
yearsOfExperience: yearsOfExperience.isOptional(),
|
|
172
|
+
zipCode: zipCode.isOptional(),
|
|
173
|
+
name: name.isOptional(),
|
|
174
|
+
status: status.isOptional(),
|
|
175
|
+
status_detail: status_detail.isOptional(),
|
|
176
|
+
turnover: turnover.isOptional(),
|
|
177
|
+
description: description.isOptional(),
|
|
178
|
+
partner_swanbase: (0, validate_1.isBoolean)().isOptional(),
|
|
179
|
+
partner_iii: (0, validate_1.isBoolean)().isOptional(),
|
|
180
|
+
availability: availability.isOptional(),
|
|
181
|
+
},
|
|
182
|
+
createReaction: {
|
|
183
|
+
toId: (0, validate_1.isString)(),
|
|
184
|
+
status: reactionStatus,
|
|
185
|
+
},
|
|
186
|
+
deleteReaction: {
|
|
187
|
+
toId: (0, validate_1.isString)(),
|
|
188
|
+
},
|
|
189
|
+
createBlogHtmlArticle: {
|
|
190
|
+
apiSecretKey,
|
|
191
|
+
title: (0, validate_1.isString)(),
|
|
192
|
+
description: (0, validate_1.isString)(),
|
|
193
|
+
slug: (0, validate_1.isString)(),
|
|
194
|
+
content: (0, validate_1.isString)(),
|
|
195
|
+
toc: (0, validate_1.isString)().isOptional(),
|
|
196
|
+
},
|
|
197
|
+
//////////
|
|
198
|
+
// Routes
|
|
199
|
+
checkout_session: {
|
|
200
|
+
stripeId: stripeId.isOptional(),
|
|
201
|
+
email,
|
|
202
|
+
type: (0, validate_1.isMatchEnum)(["user", "project"]),
|
|
203
|
+
planOption: (0, validate_1.isMatchEnum)(["month", "annual"]),
|
|
204
|
+
},
|
|
205
|
+
delete_customer: {
|
|
206
|
+
stripeId,
|
|
207
|
+
},
|
|
208
|
+
portal_session: {
|
|
209
|
+
stripeId,
|
|
210
|
+
},
|
|
211
|
+
webhook: {},
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Validate the request body depending on the route.
|
|
215
|
+
* @param route - Route to know which validators to use.
|
|
216
|
+
* @param body - Body to validate.
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
function validateBodyForO(route, body) {
|
|
220
|
+
return (0, validate_1.validateBody)(body, validatorsForAllRoutes[route]);
|
|
221
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TAvailability, TPlan, TProjectStatus, TSkill } from "./db.model";
|
|
2
|
+
export declare const EMAIL = "contact@cofondateurauchomage.fr";
|
|
3
|
+
export declare const SKILLS: TSkill[];
|
|
4
|
+
export declare const PROJECT_STATUS: TProjectStatus[];
|
|
5
|
+
export declare const PLANS: TPlan[];
|
|
6
|
+
export declare const AVAILABILITY: TAvailability[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVAILABILITY = exports.PLANS = exports.PROJECT_STATUS = exports.SKILLS = exports.EMAIL = void 0;
|
|
4
|
+
exports.EMAIL = "contact@cofondateurauchomage.fr";
|
|
5
|
+
exports.SKILLS = [
|
|
6
|
+
"Sales",
|
|
7
|
+
"Operation",
|
|
8
|
+
"Design",
|
|
9
|
+
"Marketing",
|
|
10
|
+
"Produit",
|
|
11
|
+
"Tech",
|
|
12
|
+
];
|
|
13
|
+
exports.PROJECT_STATUS = [
|
|
14
|
+
"idea",
|
|
15
|
+
"creation",
|
|
16
|
+
"launch",
|
|
17
|
+
"growth",
|
|
18
|
+
];
|
|
19
|
+
exports.PLANS = ["free", "pro"];
|
|
20
|
+
exports.AVAILABILITY = [
|
|
21
|
+
"full_time",
|
|
22
|
+
"part_time",
|
|
23
|
+
];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export declare enum Collections {
|
|
2
|
+
users = "users",
|
|
3
|
+
projects = "projects",
|
|
4
|
+
contacts = "contacts",
|
|
5
|
+
newsletters = "newsletters",
|
|
6
|
+
stats = "stats",
|
|
7
|
+
notifications = "notifications",
|
|
8
|
+
prospects = "prospects",
|
|
9
|
+
reactions = "reactions",
|
|
10
|
+
visits = "visits",
|
|
11
|
+
blogHtmlArticles = "blog_html_articles"
|
|
12
|
+
}
|
|
13
|
+
export type TSkill = "Sales" | "Operation" | "Design" | "Marketing" | "Produit" | "Tech";
|
|
14
|
+
export type TPlan = "free" | "pro" | "premium";
|
|
15
|
+
export type TVisibility = "public" | "limited" | "private";
|
|
16
|
+
export type TProjectStatus = "idea" | "creation" | "launch" | "growth";
|
|
17
|
+
export type TAvailability = "full_time" | "part_time";
|
|
18
|
+
export interface IClicks {
|
|
19
|
+
linkedin: number;
|
|
20
|
+
email: number;
|
|
21
|
+
card: number;
|
|
22
|
+
share: number;
|
|
23
|
+
website: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IUser {
|
|
26
|
+
id: string;
|
|
27
|
+
lastName: string;
|
|
28
|
+
firstName: string;
|
|
29
|
+
skills: TSkill[];
|
|
30
|
+
yearsOfExperience?: number;
|
|
31
|
+
zipCode: number;
|
|
32
|
+
city: string;
|
|
33
|
+
invest?: number;
|
|
34
|
+
joblessDate?: string;
|
|
35
|
+
motivations?: string;
|
|
36
|
+
partner?: string;
|
|
37
|
+
business: string;
|
|
38
|
+
availability?: TAvailability;
|
|
39
|
+
photo?: string;
|
|
40
|
+
plan: TPlan;
|
|
41
|
+
active?: boolean;
|
|
42
|
+
visibility: TVisibility;
|
|
43
|
+
clicks: IClicks;
|
|
44
|
+
creationDate: number;
|
|
45
|
+
lastConnection: number;
|
|
46
|
+
stripeId?: string;
|
|
47
|
+
referrer?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface IProject {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
lastName: string;
|
|
53
|
+
firstName: string;
|
|
54
|
+
skills: TSkill[];
|
|
55
|
+
yearsOfExperience?: number;
|
|
56
|
+
zipCode: number;
|
|
57
|
+
city: string;
|
|
58
|
+
invest?: number;
|
|
59
|
+
status?: TProjectStatus;
|
|
60
|
+
status_detail?: string;
|
|
61
|
+
turnover?: number;
|
|
62
|
+
description: string;
|
|
63
|
+
partner?: string;
|
|
64
|
+
availability?: TAvailability;
|
|
65
|
+
logo?: string;
|
|
66
|
+
plan: TPlan;
|
|
67
|
+
active?: boolean;
|
|
68
|
+
visibility: TVisibility;
|
|
69
|
+
clicks: IClicks;
|
|
70
|
+
creationDate: number;
|
|
71
|
+
lastConnection: number;
|
|
72
|
+
stripeId?: string;
|
|
73
|
+
partner_swanbase?: boolean;
|
|
74
|
+
partner_iii?: boolean;
|
|
75
|
+
referrer?: string;
|
|
76
|
+
postedOnLinkedInAt?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface IContact {
|
|
79
|
+
email: string;
|
|
80
|
+
linkedin?: string;
|
|
81
|
+
tel?: string;
|
|
82
|
+
website?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface INewsletter {
|
|
85
|
+
marketing?: boolean;
|
|
86
|
+
notification?: boolean;
|
|
87
|
+
feature?: boolean;
|
|
88
|
+
match?: boolean;
|
|
89
|
+
new_profil?: boolean;
|
|
90
|
+
new_profil_last_sent_date?: number;
|
|
91
|
+
}
|
|
92
|
+
export interface IStatsAssociation {
|
|
93
|
+
liste: string[];
|
|
94
|
+
}
|
|
95
|
+
export type TNotificationType = "match" | "like" | "new_profil";
|
|
96
|
+
export interface INotification {
|
|
97
|
+
type: TNotificationType;
|
|
98
|
+
uid: string;
|
|
99
|
+
createdAt: number;
|
|
100
|
+
isRead: boolean;
|
|
101
|
+
title: string;
|
|
102
|
+
body?: string;
|
|
103
|
+
link?: string;
|
|
104
|
+
}
|
|
105
|
+
export type IProspect = Partial<Omit<IUser, "id" | "plan" | "visibility" | "clicks" | "lastConnection" | "likes" | "stripeId" | "active" | "photo">> & Partial<Omit<IProject, "id" | "plan" | "visibility" | "clicks" | "creationDate" | "lastConnection" | "likes" | "stripeId" | "active" | "logo" | "postedOnLinkedInAt">> & Partial<IContact> & {
|
|
106
|
+
email: string;
|
|
107
|
+
};
|
|
108
|
+
export type IReactionStatus = "like" | "dislike";
|
|
109
|
+
export interface IReaction {
|
|
110
|
+
fromUserId: string;
|
|
111
|
+
toUserId: string;
|
|
112
|
+
status: IReactionStatus;
|
|
113
|
+
createdAt: number;
|
|
114
|
+
}
|
|
115
|
+
export interface IVisit {
|
|
116
|
+
visits: number;
|
|
117
|
+
}
|
|
118
|
+
export interface IBlogHtmlArticle {
|
|
119
|
+
slug: string;
|
|
120
|
+
title: string;
|
|
121
|
+
description: string;
|
|
122
|
+
date: string;
|
|
123
|
+
content: string;
|
|
124
|
+
toc?: string;
|
|
125
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collections = void 0;
|
|
4
|
+
var Collections;
|
|
5
|
+
(function (Collections) {
|
|
6
|
+
Collections["users"] = "users";
|
|
7
|
+
Collections["projects"] = "projects";
|
|
8
|
+
Collections["contacts"] = "contacts";
|
|
9
|
+
Collections["newsletters"] = "newsletters";
|
|
10
|
+
Collections["stats"] = "stats";
|
|
11
|
+
Collections["notifications"] = "notifications";
|
|
12
|
+
Collections["prospects"] = "prospects";
|
|
13
|
+
Collections["reactions"] = "reactions";
|
|
14
|
+
Collections["visits"] = "visits";
|
|
15
|
+
Collections["blogHtmlArticles"] = "blog_html_articles";
|
|
16
|
+
})(Collections || (exports.Collections = Collections = {}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api"), exports);
|
|
18
|
+
__exportStar(require("./api.validate"), exports);
|
|
19
|
+
__exportStar(require("./const"), exports);
|
|
20
|
+
__exportStar(require("./db.model"), exports);
|
|
21
|
+
__exportStar(require("./regex"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
__exportStar(require("./validate"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const RGX: {
|
|
2
|
+
Date: {
|
|
3
|
+
regex: RegExp;
|
|
4
|
+
};
|
|
5
|
+
Email: {
|
|
6
|
+
regex: RegExp;
|
|
7
|
+
pattern: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
Linkedin: {
|
|
11
|
+
regex: RegExp;
|
|
12
|
+
pattern: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
Name: {
|
|
16
|
+
regex: RegExp;
|
|
17
|
+
pattern: string;
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
Tel: {
|
|
21
|
+
regex: RegExp;
|
|
22
|
+
pattern: string;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGX = void 0;
|
|
4
|
+
const regex = {
|
|
5
|
+
date: /^([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))$/,
|
|
6
|
+
email: /^[\w.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
|
|
7
|
+
linkedin: /^(http(s)?:\/\/)?([\w]+\.)?linkedin\.com\/(pub|in|profile)\/.+$/,
|
|
8
|
+
name: /^[A-Za-zÜ-ü\s\-]{1,50}$/,
|
|
9
|
+
tel: /^([+][1-9]{2,3}[ .\-]?)?[0-9]{1,3}([ .\-]?[0-9]{2,3}){3,6}$/,
|
|
10
|
+
};
|
|
11
|
+
const pattern = (regex) => String(regex).replace("/^", "").replace("$/", "");
|
|
12
|
+
exports.RGX = {
|
|
13
|
+
Date: {
|
|
14
|
+
regex: regex.date,
|
|
15
|
+
},
|
|
16
|
+
Email: {
|
|
17
|
+
regex: regex.email,
|
|
18
|
+
pattern: pattern(regex.email),
|
|
19
|
+
message: `Veuillez entrer une adresse email valide.`,
|
|
20
|
+
},
|
|
21
|
+
Linkedin: {
|
|
22
|
+
regex: regex.linkedin,
|
|
23
|
+
pattern: pattern(regex.linkedin),
|
|
24
|
+
message: `Le lien doit être un URL LinkedIn valide. (ex: https://www.linkedin.com/in/valentin-lemaire/)`,
|
|
25
|
+
},
|
|
26
|
+
Name: {
|
|
27
|
+
regex: regex.name,
|
|
28
|
+
pattern: pattern(regex.name),
|
|
29
|
+
message: `Accepte les noms composés (espace ou -) et les accents jusqu'à 50 caractères. Les caractères spéciaux et les chiffres ne sont pas autorisés.`,
|
|
30
|
+
},
|
|
31
|
+
Tel: {
|
|
32
|
+
regex: regex.tel,
|
|
33
|
+
pattern: pattern(regex.tel),
|
|
34
|
+
message: `Veuillez entrer un numéro de téléphone valide.`,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Includes typé
|
|
3
|
+
*/
|
|
4
|
+
export declare function includes<T extends string>(array: T[], value: string): value is T;
|
|
5
|
+
/**
|
|
6
|
+
* Retourne un array sans valeurs null ou undefined
|
|
7
|
+
*/
|
|
8
|
+
export declare const compact: <T>(array: (T | null | undefined)[]) => T[];
|
|
9
|
+
/**
|
|
10
|
+
* Divise un tableau en lots de taille maximale
|
|
11
|
+
*/
|
|
12
|
+
export declare function chunkArray<T>(array: T[], size: number): T[][];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compact = void 0;
|
|
4
|
+
exports.includes = includes;
|
|
5
|
+
exports.chunkArray = chunkArray;
|
|
6
|
+
/**
|
|
7
|
+
* Includes typé
|
|
8
|
+
*/
|
|
9
|
+
function includes(array, value) {
|
|
10
|
+
return array.includes(value);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Retourne un array sans valeurs null ou undefined
|
|
14
|
+
*/
|
|
15
|
+
const compact = (array) => array.filter(Boolean);
|
|
16
|
+
exports.compact = compact;
|
|
17
|
+
/**
|
|
18
|
+
* Divise un tableau en lots de taille maximale
|
|
19
|
+
*/
|
|
20
|
+
function chunkArray(array, size) {
|
|
21
|
+
const result = [];
|
|
22
|
+
for (let i = 0; i < array.length; i += size) {
|
|
23
|
+
result.push(array.slice(i, i + size));
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./arrayUtils"), exports);
|
|
18
|
+
__exportStar(require("./objectUtils"), exports);
|
|
19
|
+
__exportStar(require("./stringUtils"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pick certaines clés d'un objet
|
|
3
|
+
*/
|
|
4
|
+
export declare function pickObject<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
|
|
5
|
+
/**
|
|
6
|
+
* Omit certaines clés d'un objet
|
|
7
|
+
*/
|
|
8
|
+
export declare function omitObject<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
|
|
9
|
+
export declare function typedKeys<T extends object>(obj: T): Array<keyof T>;
|
|
10
|
+
export declare function typedObjectEntries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
|
|
11
|
+
export declare function isObject(x: unknown): x is object;
|
|
12
|
+
type IsEmpty<T> = T extends undefined | null ? true : T extends "" ? true : T extends [] ? true : T extends Record<string, never> ? true : false;
|
|
13
|
+
type Cleaned<T> = {
|
|
14
|
+
[K in keyof T as IsEmpty<T[K]> extends true ? never : K]: Exclude<T[K], undefined | null | "">;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Permet de nettoyer un objet en supprimant les clés qui ont une valeur :
|
|
18
|
+
* '' / undefined / null / [] / {}
|
|
19
|
+
* @option recursive - si true, les objets sont nettoyés recursivement
|
|
20
|
+
*/
|
|
21
|
+
export declare function cleanObject<T extends object>(obj: T, options?: {
|
|
22
|
+
recursive?: boolean;
|
|
23
|
+
}): Cleaned<T>;
|
|
24
|
+
export declare function deepEqual<T>(obj1: T, obj2: T): boolean;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pickObject = pickObject;
|
|
4
|
+
exports.omitObject = omitObject;
|
|
5
|
+
exports.typedKeys = typedKeys;
|
|
6
|
+
exports.typedObjectEntries = typedObjectEntries;
|
|
7
|
+
exports.isObject = isObject;
|
|
8
|
+
exports.cleanObject = cleanObject;
|
|
9
|
+
exports.deepEqual = deepEqual;
|
|
10
|
+
const arrayUtils_1 = require("./arrayUtils");
|
|
11
|
+
/**
|
|
12
|
+
* Pick certaines clés d'un objet
|
|
13
|
+
*/
|
|
14
|
+
function pickObject(obj, ...keys) {
|
|
15
|
+
return Object.entries(obj).reduce((acc, [key, value]) => keys.includes(key) ? { ...acc, [key]: value } : acc, {});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Omit certaines clés d'un objet
|
|
19
|
+
*/
|
|
20
|
+
function omitObject(obj, ...keys) {
|
|
21
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
22
|
+
if (!keys.includes(key)) {
|
|
23
|
+
acc[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
}
|
|
28
|
+
function typedKeys(obj) {
|
|
29
|
+
return Object.keys(obj);
|
|
30
|
+
}
|
|
31
|
+
function typedObjectEntries(obj) {
|
|
32
|
+
return Object.entries(obj);
|
|
33
|
+
}
|
|
34
|
+
function isObject(x) {
|
|
35
|
+
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Permet de nettoyer un objet en supprimant les clés qui ont une valeur :
|
|
39
|
+
* '' / undefined / null / [] / {}
|
|
40
|
+
* @option recursive - si true, les objets sont nettoyés recursivement
|
|
41
|
+
*/
|
|
42
|
+
function cleanObject(obj, options) {
|
|
43
|
+
const result = {};
|
|
44
|
+
for (const [key, value] of typedObjectEntries(obj)) {
|
|
45
|
+
const cleanedValue = isObject(value) && options?.recursive
|
|
46
|
+
? cleanObject(value, { recursive: true })
|
|
47
|
+
: value;
|
|
48
|
+
if (cleanedValue !== "" &&
|
|
49
|
+
cleanedValue !== undefined &&
|
|
50
|
+
cleanedValue !== null &&
|
|
51
|
+
(!Array.isArray(cleanedValue) || (0, arrayUtils_1.compact)(cleanedValue).length > 0) &&
|
|
52
|
+
(!isObject(value) || Object.keys(cleanedValue).length > 0)) {
|
|
53
|
+
result[key] = cleanedValue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function deepEqual(obj1, obj2) {
|
|
59
|
+
if (obj1 === obj2) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (obj1 && typeof obj1 === "object" && obj2 && typeof obj2 === "object") {
|
|
63
|
+
const keys1 = typedKeys(obj1);
|
|
64
|
+
const keys2 = typedKeys(obj2);
|
|
65
|
+
if (keys1.length !== keys2.length) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
for (const key of keys1) {
|
|
69
|
+
if (!keys2.includes(key)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (!deepEqual(obj1[key], obj2[key])) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalize = capitalize;
|
|
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
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type ValidatorFn = (value: unknown) => boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a custom validator.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Validator {
|
|
6
|
+
private readonly fn;
|
|
7
|
+
/**
|
|
8
|
+
* Flag indicating if the field is required.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
private required;
|
|
12
|
+
private min?;
|
|
13
|
+
private max?;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new Validator.
|
|
16
|
+
* @param fn - The validator function for validate the value.
|
|
17
|
+
*/
|
|
18
|
+
constructor(fn: ValidatorFn);
|
|
19
|
+
/**
|
|
20
|
+
* Method to validate the value based on the validator function and the chainable methods called prior.
|
|
21
|
+
* @param value - Value to validate.
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
validate(key: string, value: any): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The value is not required.
|
|
27
|
+
*/
|
|
28
|
+
isOptional(): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the minimum allowable value or length.
|
|
31
|
+
* @param min - Minimum value for the length of the value or the value itself.
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
setMin(min: number): this;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the maximum allowable value or length.
|
|
37
|
+
* @param max - Maximum value for the length of the value or the value itself.
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
setMax(max: number): this;
|
|
41
|
+
private checkMinMax;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a new validator for a number.
|
|
45
|
+
*/
|
|
46
|
+
export declare const isNumber: () => Validator;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new validator for a string.
|
|
49
|
+
*/
|
|
50
|
+
export declare const isString: () => Validator;
|
|
51
|
+
/**
|
|
52
|
+
* Create a new validator for a boolean.
|
|
53
|
+
*/
|
|
54
|
+
export declare const isBoolean: () => Validator;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new validator for an array.
|
|
57
|
+
*/
|
|
58
|
+
export declare const isArray: () => Validator;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new validator that tests a string value against a given regex pattern.
|
|
61
|
+
* @param pattern - The regex pattern to test.
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export declare const isMatchRegex: (pattern: RegExp) => Validator;
|
|
65
|
+
/**
|
|
66
|
+
* Create a new validator for enum.
|
|
67
|
+
* @param values - The enum values.
|
|
68
|
+
*/
|
|
69
|
+
export declare const isMatchEnum: <T extends string>(values: T[]) => Validator;
|
|
70
|
+
/**
|
|
71
|
+
* Custom error class to handle validation errors.
|
|
72
|
+
*/
|
|
73
|
+
export declare class ValidationError extends Error {
|
|
74
|
+
code: number;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new ValidationError.
|
|
77
|
+
* @param code - The HTTP status code.
|
|
78
|
+
* @param message - The error message.
|
|
79
|
+
*/
|
|
80
|
+
constructor(code: number, message: string);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validate the request body against the provided validators.
|
|
84
|
+
* @param body - Body to validate.
|
|
85
|
+
* @param validators - validator for each key of the body.
|
|
86
|
+
* @returns {O} - The validated body.
|
|
87
|
+
* @throws {ValidationError} - Throws a ValidationError exception if validation fails.
|
|
88
|
+
*/
|
|
89
|
+
export declare function validateBody<O extends Record<string, any>>(body: unknown, validators: Record<keyof O, Validator>): O;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//////////////
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ValidationError = exports.isMatchEnum = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
|
|
5
|
+
exports.validateBody = validateBody;
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const arrayUtils_1 = require("./utils/arrayUtils");
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a custom validator.
|
|
10
|
+
*/
|
|
11
|
+
class Validator {
|
|
12
|
+
fn;
|
|
13
|
+
/**
|
|
14
|
+
* Flag indicating if the field is required.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
required = true;
|
|
18
|
+
min;
|
|
19
|
+
max;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new Validator.
|
|
22
|
+
* @param fn - The validator function for validate the value.
|
|
23
|
+
*/
|
|
24
|
+
constructor(fn) {
|
|
25
|
+
this.fn = fn;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Method to validate the value based on the validator function and the chainable methods called prior.
|
|
29
|
+
* @param value - Value to validate.
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
validate(key, value) {
|
|
33
|
+
if (!this.required && !value) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (!this.fn(value)) {
|
|
37
|
+
if (!value) {
|
|
38
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} requis`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} invalide`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (this.min !== undefined || this.max !== undefined) {
|
|
45
|
+
return this.checkMinMax(key, value, this.min, this.max);
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The value is not required.
|
|
51
|
+
*/
|
|
52
|
+
isOptional() {
|
|
53
|
+
this.required = false;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sets the minimum allowable value or length.
|
|
58
|
+
* @param min - Minimum value for the length of the value or the value itself.
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
setMin(min) {
|
|
62
|
+
this.min = min;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sets the maximum allowable value or length.
|
|
67
|
+
* @param max - Maximum value for the length of the value or the value itself.
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
setMax(max) {
|
|
71
|
+
this.max = max;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
checkMinMax(key, value, min, max) {
|
|
75
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
76
|
+
throw new ValidationError(400, `${key} n'est ni un nombre ni un texte`);
|
|
77
|
+
}
|
|
78
|
+
const nb = typeof value === "string" ? value.length : value;
|
|
79
|
+
if (min !== undefined && nb < min) {
|
|
80
|
+
throw new ValidationError(400, typeof value === "string"
|
|
81
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} n'est pas assez long, il manque ${min - nb} caractères`
|
|
82
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop basse, minimum: ${min}`);
|
|
83
|
+
}
|
|
84
|
+
if (max !== undefined && nb > max) {
|
|
85
|
+
throw new ValidationError(400, typeof value === "string"
|
|
86
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} est trop long, il y a ${nb - max} caractères en trop`
|
|
87
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop haute, maximum: ${max}`);
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Validator = Validator;
|
|
93
|
+
/**
|
|
94
|
+
* Create a new validator for a number.
|
|
95
|
+
*/
|
|
96
|
+
const isNumber = () => new Validator((value) => typeof value === "number");
|
|
97
|
+
exports.isNumber = isNumber;
|
|
98
|
+
/**
|
|
99
|
+
* Create a new validator for a string.
|
|
100
|
+
*/
|
|
101
|
+
const isString = () => new Validator((value) => typeof value === "string");
|
|
102
|
+
exports.isString = isString;
|
|
103
|
+
/**
|
|
104
|
+
* Create a new validator for a boolean.
|
|
105
|
+
*/
|
|
106
|
+
const isBoolean = () => new Validator((value) => typeof value === "boolean");
|
|
107
|
+
exports.isBoolean = isBoolean;
|
|
108
|
+
/**
|
|
109
|
+
* Create a new validator for an array.
|
|
110
|
+
*/
|
|
111
|
+
const isArray = () => new Validator((value) => Array.isArray(value));
|
|
112
|
+
exports.isArray = isArray;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new validator that tests a string value against a given regex pattern.
|
|
115
|
+
* @param pattern - The regex pattern to test.
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
const isMatchRegex = (pattern) => new Validator((value) => typeof value === "string" && pattern.test(value));
|
|
119
|
+
exports.isMatchRegex = isMatchRegex;
|
|
120
|
+
/**
|
|
121
|
+
* Create a new validator for enum.
|
|
122
|
+
* @param values - The enum values.
|
|
123
|
+
*/
|
|
124
|
+
const isMatchEnum = (values) => new Validator((value) => typeof value === "string" && (0, arrayUtils_1.includes)(values, value));
|
|
125
|
+
exports.isMatchEnum = isMatchEnum;
|
|
126
|
+
/////////////
|
|
127
|
+
// Validate
|
|
128
|
+
/**
|
|
129
|
+
* Custom error class to handle validation errors.
|
|
130
|
+
*/
|
|
131
|
+
class ValidationError extends Error {
|
|
132
|
+
code;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new ValidationError.
|
|
135
|
+
* @param code - The HTTP status code.
|
|
136
|
+
* @param message - The error message.
|
|
137
|
+
*/
|
|
138
|
+
constructor(code, message) {
|
|
139
|
+
super(message);
|
|
140
|
+
this.code = code;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.ValidationError = ValidationError;
|
|
144
|
+
/**
|
|
145
|
+
* Validate the request body against the provided validators.
|
|
146
|
+
* @param body - Body to validate.
|
|
147
|
+
* @param validators - validator for each key of the body.
|
|
148
|
+
* @returns {O} - The validated body.
|
|
149
|
+
* @throws {ValidationError} - Throws a ValidationError exception if validation fails.
|
|
150
|
+
*/
|
|
151
|
+
function validateBody(body, validators) {
|
|
152
|
+
if (typeof body !== "object" || body === null) {
|
|
153
|
+
throw new ValidationError(400, "Le payload est requis");
|
|
154
|
+
}
|
|
155
|
+
const result = {};
|
|
156
|
+
for (const [key, validator] of Object.entries(validators)) {
|
|
157
|
+
const value = body[key];
|
|
158
|
+
validator.validate(key, value);
|
|
159
|
+
if (value !== undefined)
|
|
160
|
+
result[key] = value;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.compact = void 0;
|
|
4
|
+
exports.includes = includes;
|
|
5
|
+
exports.chunkArray = chunkArray;
|
|
4
6
|
/**
|
|
5
7
|
* Includes typé
|
|
6
8
|
*/
|
|
7
9
|
function includes(array, value) {
|
|
8
10
|
return array.includes(value);
|
|
9
11
|
}
|
|
10
|
-
exports.includes = includes;
|
|
11
12
|
/**
|
|
12
13
|
* Retourne un array sans valeurs null ou undefined
|
|
13
14
|
*/
|
|
@@ -23,4 +24,3 @@ function chunkArray(array, size) {
|
|
|
23
24
|
}
|
|
24
25
|
return result;
|
|
25
26
|
}
|
|
26
|
-
exports.chunkArray = chunkArray;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.pickObject = pickObject;
|
|
4
|
+
exports.omitObject = omitObject;
|
|
5
|
+
exports.typedKeys = typedKeys;
|
|
6
|
+
exports.typedObjectEntries = typedObjectEntries;
|
|
7
|
+
exports.isObject = isObject;
|
|
8
|
+
exports.cleanObject = cleanObject;
|
|
9
|
+
exports.deepEqual = deepEqual;
|
|
4
10
|
const arrayUtils_1 = require("./arrayUtils");
|
|
5
11
|
/**
|
|
6
12
|
* Pick certaines clés d'un objet
|
|
@@ -8,7 +14,6 @@ const arrayUtils_1 = require("./arrayUtils");
|
|
|
8
14
|
function pickObject(obj, ...keys) {
|
|
9
15
|
return Object.entries(obj).reduce((acc, [key, value]) => keys.includes(key) ? { ...acc, [key]: value } : acc, {});
|
|
10
16
|
}
|
|
11
|
-
exports.pickObject = pickObject;
|
|
12
17
|
/**
|
|
13
18
|
* Omit certaines clés d'un objet
|
|
14
19
|
*/
|
|
@@ -20,19 +25,15 @@ function omitObject(obj, ...keys) {
|
|
|
20
25
|
return acc;
|
|
21
26
|
}, {});
|
|
22
27
|
}
|
|
23
|
-
exports.omitObject = omitObject;
|
|
24
28
|
function typedKeys(obj) {
|
|
25
29
|
return Object.keys(obj);
|
|
26
30
|
}
|
|
27
|
-
exports.typedKeys = typedKeys;
|
|
28
31
|
function typedObjectEntries(obj) {
|
|
29
32
|
return Object.entries(obj);
|
|
30
33
|
}
|
|
31
|
-
exports.typedObjectEntries = typedObjectEntries;
|
|
32
34
|
function isObject(x) {
|
|
33
35
|
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
34
36
|
}
|
|
35
|
-
exports.isObject = isObject;
|
|
36
37
|
/**
|
|
37
38
|
* Permet de nettoyer un objet en supprimant les clés qui ont une valeur :
|
|
38
39
|
* '' / undefined / null / [] / {}
|
|
@@ -54,7 +55,6 @@ function cleanObject(obj, options) {
|
|
|
54
55
|
}
|
|
55
56
|
return result;
|
|
56
57
|
}
|
|
57
|
-
exports.cleanObject = cleanObject;
|
|
58
58
|
function deepEqual(obj1, obj2) {
|
|
59
59
|
if (obj1 === obj2) {
|
|
60
60
|
return true;
|
|
@@ -77,4 +77,3 @@ function deepEqual(obj1, obj2) {
|
|
|
77
77
|
}
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
exports.deepEqual = deepEqual;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitalize =
|
|
3
|
+
exports.capitalize = capitalize;
|
|
4
4
|
/**
|
|
5
5
|
* Capitalize the first letter of each words separated by a space or a hyphen
|
|
6
6
|
* and prevent double space
|
|
@@ -18,4 +18,3 @@ function capitalize(str) {
|
|
|
18
18
|
.join("-")
|
|
19
19
|
.replace(" ", " ");
|
|
20
20
|
}
|
|
21
|
-
exports.capitalize = capitalize;
|
package/build/validate.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
//////////////
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.ValidationError = exports.isMatchEnum = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
|
|
5
|
+
exports.validateBody = validateBody;
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
7
|
const arrayUtils_1 = require("./utils/arrayUtils");
|
|
7
8
|
/**
|
|
@@ -160,4 +161,3 @@ function validateBody(body, validators) {
|
|
|
160
161
|
}
|
|
161
162
|
return result;
|
|
162
163
|
}
|
|
163
|
-
exports.validateBody = validateBody;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofondateurauchomage/libs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.113",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/jest": "^29.5.5",
|
|
19
19
|
"jest": "^29.7.0",
|
|
20
|
-
"ts-jest": "^29.
|
|
21
|
-
"typescript": "
|
|
20
|
+
"ts-jest": "^29.4.9",
|
|
21
|
+
"typescript": "6.0.2"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"build"
|