@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 CHANGED
@@ -60,33 +60,33 @@ type WriteResult = {
60
60
  writeTime: Timestamp;
61
61
  };
62
62
  export type ResponseForO<O extends CloudFunctionNames | RouteNames> = {
63
- createProject: Promise<WriteResult>;
64
- deleteProject: Promise<WriteResult>;
65
- updateProject: Promise<WriteResult>;
66
- createUser: Promise<WriteResult>;
67
- deleteUser: Promise<WriteResult>;
68
- updateUser: Promise<WriteResult>;
69
- updateVisibility: Promise<WriteResult>;
70
- addStripeId: Promise<WriteResult>;
71
- updatePlan: Promise<WriteResult>;
72
- addStatsAssociation: Promise<WriteResult>;
73
- updateNewsletter: Promise<WriteResult>;
74
- createProspect: Promise<{
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: Promise<IProspect>;
78
- updateProspect: Promise<WriteResult | null>;
79
- createReaction: Promise<WriteResult>;
80
- deleteReaction: Promise<WriteResult>;
81
- checkout_session: Promise<{
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: Promise<{
83
+ };
84
+ delete_customer: {
85
85
  success: boolean;
86
- }>;
87
- portal_session: Promise<{
86
+ };
87
+ portal_session: {
88
88
  url: string;
89
- }>;
90
- webhook: Promise<void>;
89
+ };
90
+ webhook: void;
91
91
  }[O];
92
92
  export {};
@@ -1,2 +1,3 @@
1
1
  export * from "./arrayUtils";
2
2
  export * from "./objectUtils";
3
+ export * from "./stringUtils";
@@ -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,7 @@
1
+ /**
2
+ * Capitalize the first letter of each words separated by a space or a hyphen
3
+ * and prevent double space
4
+ * @param str
5
+ * @returns
6
+ */
7
+ export declare function capitalize(str: string): string;
@@ -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
- throw new ValidationError(400, `${key} non fourni ou invalide`);
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, "Body non fourni ou invalide");
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.80",
3
+ "version": "1.1.84",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {