5htp-core 0.0.8 → 0.1.0
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/package.json +1 -1
- package/src/client/assets/css/components/button.less +47 -44
- package/src/client/assets/css/components/card.less +43 -21
- package/src/client/assets/css/components/components.less +25 -0
- package/src/client/assets/css/components/lists.less +30 -15
- package/src/client/assets/css/components/other.less +9 -5
- package/src/client/assets/css/core.less +1 -0
- package/src/client/assets/css/layouts.less +25 -10
- package/src/client/assets/css/medias.less +3 -1
- package/src/client/assets/css/spacing.less +2 -1
- package/src/client/assets/css/text/icons.less +1 -1
- package/src/client/assets/css/text/text.less +17 -11
- package/src/client/assets/css/text/titres.less +5 -5
- package/src/client/assets/css/theme.less +15 -13
- package/src/client/components/Dialog/card.tsx +1 -1
- package/src/client/components/Dialog/index.less +4 -3
- package/src/client/components/Form/index.tsx +2 -2
- package/src/client/components/Select/index.tsx +58 -0
- package/src/client/components/button.tsx +1 -1
- package/src/client/components/chart/base.tsx +1 -1
- package/src/client/components/containers/Scrollbar/index.less +1 -1
- package/src/client/components/containers/tabs/index.tsx +2 -2
- package/src/client/components/data/progressbar/circular/index.tsx +1 -1
- package/src/client/components/data/progressbar/index.less +5 -3
- package/src/client/components/data/progressbar/index.tsx +3 -3
- package/src/client/components/dropdown/index.tsx +12 -21
- package/src/client/components/input/BaseV2/index.less +4 -3
- package/src/client/components/input/BaseV2/index.tsx +4 -2
- package/src/client/components/input/Slider/index.less +1 -1
- package/src/client/components/input/UploadImage/index.less +1 -1
- package/src/client/context/index.ts +45 -41
- package/src/client/router/component.tsx +1 -0
- package/src/client/router/index.tsx +10 -3
- package/src/client/router/request/index.ts +0 -0
- package/src/common/data/input/validate.ts +2 -2
- package/src/common/data/input/validators/basic.ts +18 -18
- package/src/common/data/input/validators/build.ts +2 -2
- package/src/common/data/number/percentage.ts +4 -2
- package/src/common/errors/index.ts +17 -13
- package/src/common/router/index.ts +1 -1
- package/src/server/app/index.ts +70 -17
- package/src/server/data/Cache.ts +10 -4
- package/src/server/data/Token.olg.ts +2 -2
- package/src/server/data/aes.ts +2 -2
- package/src/server/patch.ts +0 -11
- package/src/server/routes/auth.ts +6 -0
- package/src/server/services/auth/base.ts +20 -12
- package/src/server/services/console/bugReporter.ts +31 -27
- package/src/server/services/console/html.ts +0 -0
- package/src/server/services/console/index.ts +1 -1
- package/src/server/services/cron/index.ts +2 -2
- package/src/server/services/database/index.ts +9 -11
- package/src/server/services/email/index.ts +2 -5
- package/src/server/services/router/index.ts +2 -2
- package/src/server/services/router/request/index.ts +1 -1
- package/src/server/services/router/request/services/auth.ts +5 -5
- package/src/server/services/router/request/services/detect.ts +4 -4
- package/src/server/services/router/request/services/tracking.ts +2 -2
- package/src/server/services/router/response/index.ts +3 -3
- package/src/server/services/socket/index.ts +1 -1
|
@@ -133,7 +133,7 @@ export default ({
|
|
|
133
133
|
}, []);
|
|
134
134
|
|
|
135
135
|
let render = isToast ? (
|
|
136
|
-
<div class="card row
|
|
136
|
+
<div class="card row bg dark glass" onClick={() => isToast && !prison && close(true)}>
|
|
137
137
|
|
|
138
138
|
{icon}
|
|
139
139
|
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
> i {
|
|
63
63
|
color: @c1;
|
|
64
|
+
flex: 0 0 1em;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
h2 {
|
|
@@ -85,13 +86,13 @@
|
|
|
85
86
|
|
|
86
87
|
background: fade(#000, 30%);
|
|
87
88
|
backdrop-filter: blur(50px) saturate(2);
|
|
88
|
-
border-radius: @
|
|
89
|
+
border-radius: @radius;
|
|
89
90
|
|
|
90
91
|
// Desktop = vertically center the modal
|
|
91
|
-
|
|
92
|
+
/*@media (min-width: @responsive1) {
|
|
92
93
|
justify-content: center;
|
|
93
94
|
padding: @spacing;
|
|
94
|
-
}
|
|
95
|
+
}*/
|
|
95
96
|
|
|
96
97
|
// Pour les animations (ex: conffetis
|
|
97
98
|
> canvas {
|
|
@@ -8,7 +8,7 @@ import { ComponentChild, FunctionComponent } from 'preact';
|
|
|
8
8
|
import dottie from 'dottie';
|
|
9
9
|
|
|
10
10
|
// Libs
|
|
11
|
-
import { TListeErreursSaisie,
|
|
11
|
+
import { TListeErreursSaisie, InputErrorSchema } from '@common/errors';
|
|
12
12
|
import { propsDefautChampForm, TBasePropsChamp } from '@client/components/input/Base';
|
|
13
13
|
import { TSchema, TRetourValidation, initDonnees, validate as validerSchema, TSchemaChampComplet } from '@common/data/input/validate';
|
|
14
14
|
import { simpleDeepCopy, chemin } from '@common/data/objets';
|
|
@@ -280,7 +280,7 @@ export const useForm = <TDonnees extends TObjetDonnees>(
|
|
|
280
280
|
|
|
281
281
|
if (debug) console.log("RETOUR ERREURS API", e);
|
|
282
282
|
|
|
283
|
-
if (e instanceof
|
|
283
|
+
if (e instanceof InputErrorSchema) {
|
|
284
284
|
|
|
285
285
|
setState((stateA) => ({
|
|
286
286
|
...stateA,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
// Core
|
|
9
|
+
import Button from '@client/components/button';
|
|
10
|
+
import Dropdown, { TDialogControls, Props as DropdownProps } from '@client/components/dropdown';
|
|
11
|
+
|
|
12
|
+
/*----------------------------------
|
|
13
|
+
- CONST
|
|
14
|
+
----------------------------------*/
|
|
15
|
+
|
|
16
|
+
/*----------------------------------
|
|
17
|
+
- TYPES
|
|
18
|
+
----------------------------------*/
|
|
19
|
+
|
|
20
|
+
type Choices = string[]
|
|
21
|
+
|
|
22
|
+
type SearchResultsFunction = (keywords: string) => Choices
|
|
23
|
+
|
|
24
|
+
export type Props = DropdownProps & {
|
|
25
|
+
title: string,
|
|
26
|
+
choices: Choices,
|
|
27
|
+
value?: string,
|
|
28
|
+
onChange: (value: string) => void,
|
|
29
|
+
search?: true | SearchResultsFunction
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*----------------------------------
|
|
33
|
+
- COMONENT
|
|
34
|
+
----------------------------------*/
|
|
35
|
+
|
|
36
|
+
export default ({ title, choices, value, onChange, ...dropDownProps }: Props) => {
|
|
37
|
+
const refModal = React.useRef<TDialogControls>(null);
|
|
38
|
+
return (
|
|
39
|
+
<Dropdown {...dropDownProps} content={(
|
|
40
|
+
<ul class="card col menu">
|
|
41
|
+
{choices.map( jt => (
|
|
42
|
+
<li>
|
|
43
|
+
<Button active={jt === value} onClick={() => {
|
|
44
|
+
onChange(jt);
|
|
45
|
+
refModal.current?.close();
|
|
46
|
+
}}>
|
|
47
|
+
{jt}
|
|
48
|
+
</Button>
|
|
49
|
+
</li>
|
|
50
|
+
))}
|
|
51
|
+
</ul>
|
|
52
|
+
)} iconR="chevron-down" refModal={refModal}>
|
|
53
|
+
|
|
54
|
+
{value || title}
|
|
55
|
+
|
|
56
|
+
</Dropdown>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -382,7 +382,7 @@ export default function <TDonnee extends DonneesGraph, TTypeChartJs extends Char
|
|
|
382
382
|
|
|
383
383
|
// Default color
|
|
384
384
|
if (!dataset.colonne.color)
|
|
385
|
-
dataset.colonne.color = css.getPropertyValue('--
|
|
385
|
+
dataset.colonne.color = css.getPropertyValue('--cAccent');
|
|
386
386
|
|
|
387
387
|
return {
|
|
388
388
|
label: dataset.colonne.label,
|
|
@@ -55,7 +55,7 @@ export const MenuOnglets = (props: JSX.HTMLAttributes<HTMLDivElement>) => {
|
|
|
55
55
|
|
|
56
56
|
const onglets = React.useContext(ContexteOnglets);
|
|
57
57
|
if (onglets === null)
|
|
58
|
-
return <>Contexte onglets
|
|
58
|
+
return <>Contexte onglets NotFound</>;
|
|
59
59
|
|
|
60
60
|
return (
|
|
61
61
|
<ul {...props} className={"row tabs" + (props.className ? ' ' + props.className : '')}>
|
|
@@ -76,7 +76,7 @@ export const Onglet = ({ id, children, asDiv, ...props }: {
|
|
|
76
76
|
|
|
77
77
|
const onglets = React.useContext(ContexteOnglets);
|
|
78
78
|
if (onglets === null)
|
|
79
|
-
return <>Contexte onglets
|
|
79
|
+
return <>Contexte onglets NotFound</>;
|
|
80
80
|
|
|
81
81
|
if (id !== onglets.actuel)
|
|
82
82
|
return null;
|
|
@@ -12,7 +12,7 @@ div.progressbar {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
> .progress {
|
|
15
|
-
--cBg: var(--
|
|
15
|
+
--cBg: var(--cAccent);
|
|
16
16
|
background: var(--cBg);
|
|
17
17
|
width: 0%;
|
|
18
18
|
max-width: 100%;
|
|
@@ -99,8 +99,8 @@ div.progressbar_old {
|
|
|
99
99
|
.progressbar-svg {
|
|
100
100
|
|
|
101
101
|
position: relative;
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
width: @sizeComponent;
|
|
103
|
+
height: @sizeComponent;
|
|
104
104
|
|
|
105
105
|
> svg {
|
|
106
106
|
|
|
@@ -142,6 +142,8 @@ div.progressbar_old {
|
|
|
142
142
|
left: 0;
|
|
143
143
|
right: 0;
|
|
144
144
|
bottom: 0;
|
|
145
|
+
// Text should fit inside the progressbar
|
|
146
|
+
font-size: 0.8em;
|
|
145
147
|
|
|
146
148
|
> i,
|
|
147
149
|
> img {
|
|
@@ -39,9 +39,9 @@ const hsl = (h: number, s: number = 80, l: number = 70) => `hsl(${Math.floor(h)}
|
|
|
39
39
|
export const couleurViaPc = (pc: number, couleurs: [number, number], ecart: number) => {
|
|
40
40
|
|
|
41
41
|
return {
|
|
42
|
-
couleur1: 'var(--
|
|
43
|
-
couleur2: 'var(--
|
|
44
|
-
couleurTxt: 'var(--
|
|
42
|
+
couleur1: 'var(--cAccent)',
|
|
43
|
+
couleur2: 'var(--cAccent)',
|
|
44
|
+
couleurTxt: 'var(--cAccent)'
|
|
45
45
|
}
|
|
46
46
|
const [couleurMin, couleurMax] = couleurs;
|
|
47
47
|
const couleur = couleurMin + (pc * (couleurMax - couleurMin));
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
// Npm
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { ComponentChild } from 'preact';
|
|
7
|
+
import { ComponentChild, RefObject } from 'preact';
|
|
8
8
|
|
|
9
9
|
// Core
|
|
10
10
|
import Button, { Props as ButtonProps } from '../button';
|
|
11
|
+
import { TDialogControls } from '../Dialog/Manager';
|
|
12
|
+
export type { TDialogControls } from '../Dialog/Manager';
|
|
11
13
|
|
|
12
14
|
// Libs
|
|
13
15
|
import useContexte from '@client/context';
|
|
@@ -17,23 +19,8 @@ import useContexte from '@client/context';
|
|
|
17
19
|
----------------------------------*/
|
|
18
20
|
|
|
19
21
|
export type Props = ButtonProps & {
|
|
20
|
-
content: ComponentChild
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export type TAction<TDonnee> = {
|
|
24
|
-
icone?: TIcons,
|
|
25
|
-
label: ComponentChild,
|
|
26
|
-
multi?: boolean,
|
|
27
|
-
|
|
28
|
-
onClick?: (donnees: TDonnee, index: number) => void,
|
|
29
|
-
lien?: (donnees: TDonnee, index: number) => string,
|
|
30
|
-
bouton?: (donnees: TDonnee, index: number) => ButtonProps
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type TActionsPopover = {
|
|
34
|
-
show: () => void,
|
|
35
|
-
hide: () => void,
|
|
36
|
-
toggle: () => void
|
|
22
|
+
content: ComponentChild,
|
|
23
|
+
refModal?: RefObject<TDialogControls>
|
|
37
24
|
}
|
|
38
25
|
|
|
39
26
|
/*----------------------------------
|
|
@@ -45,15 +32,19 @@ export default (props: Props) => {
|
|
|
45
32
|
|
|
46
33
|
let {
|
|
47
34
|
content,
|
|
48
|
-
|
|
35
|
+
refModal,
|
|
49
36
|
...buttonProps
|
|
50
37
|
} = props;
|
|
51
38
|
|
|
52
39
|
const refButton = React.useRef<HTMLElement>(null);
|
|
53
40
|
|
|
54
|
-
const open = () =>
|
|
41
|
+
const open = () => {
|
|
42
|
+
const modalInstance = modal.show(() => content);
|
|
43
|
+
if (refModal)
|
|
44
|
+
refModal.current = modalInstance;
|
|
45
|
+
}
|
|
55
46
|
|
|
56
47
|
return (
|
|
57
|
-
<Button {...buttonProps} onClick={open} refElem={refButton} />
|
|
48
|
+
<Button {...buttonProps} onClick={(open)} refElem={refButton} />
|
|
58
49
|
)
|
|
59
50
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@import (reference) '~@/client/assets/theme.less';
|
|
2
2
|
|
|
3
|
-
@hInput: @sizeComponent
|
|
3
|
+
@hInput: @sizeComponent;
|
|
4
4
|
|
|
5
5
|
// TODO: Adapter textarea à input/basev2
|
|
6
6
|
.contChamp textarea {
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
border-radius: @radius;
|
|
25
25
|
|
|
26
26
|
--cBg2: #eee;
|
|
27
|
-
background: fade(#000, 5%);
|
|
28
27
|
//box-shadow: 1px 3px 0 fade(#000,4%), 0 1px 2px 0 fade(#000,2%);
|
|
29
28
|
|
|
30
29
|
> i {
|
|
31
30
|
margin-left: 0.5em;
|
|
31
|
+
color: var(--cTxtDesc);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
.contValue {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
@gapAround: (@hInput - @labelH) / 2;
|
|
43
43
|
> .btn:first-child { margin-left: 0 - @gapAround / 2; }
|
|
44
44
|
|
|
45
|
-
@labelH:
|
|
45
|
+
@labelH: 0.6em;
|
|
46
46
|
label {
|
|
47
47
|
position: absolute;
|
|
48
48
|
left: 0; width: 100%;
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
align-items: center;
|
|
52
52
|
|
|
53
53
|
height: @labelH;
|
|
54
|
+
font-size: 0.8em;
|
|
54
55
|
color: var(--cTxtDesc);
|
|
55
56
|
transition: all .1s ease-out;
|
|
56
57
|
}
|
|
@@ -57,8 +57,10 @@ export function useInput<TValue>(
|
|
|
57
57
|
// External value change
|
|
58
58
|
React.useEffect(() => {
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
if (externalValue !== undefined && externalValue !== state.value) {
|
|
61
|
+
console.log("External value change", externalValue);
|
|
62
|
+
setState({ value: externalValue, valueSource: 'external' })
|
|
63
|
+
}
|
|
62
64
|
|
|
63
65
|
}, [externalValue]);
|
|
64
66
|
|
|
@@ -7,7 +7,6 @@ import React from 'react';
|
|
|
7
7
|
import type { ComponentChild } from 'preact';
|
|
8
8
|
|
|
9
9
|
// Core
|
|
10
|
-
import { AuthRequise } from '@common/errors';
|
|
11
10
|
import { createDialog } from '@client/components/Dialog/Manager';
|
|
12
11
|
import BaseRequest from '@common/router/request';
|
|
13
12
|
import router, { TClientRoute } from '@client/router';
|
|
@@ -112,42 +111,6 @@ export class ClientContext {
|
|
|
112
111
|
this.request = request;
|
|
113
112
|
this.user = this.request.user || { ...GuestUser };
|
|
114
113
|
|
|
115
|
-
this.api.reload = (ids?: string | string[], params?: TObjetDonnees) => {
|
|
116
|
-
|
|
117
|
-
if (this.page === undefined)
|
|
118
|
-
throw new Error("context.page is missing");
|
|
119
|
-
|
|
120
|
-
if (ids === undefined)
|
|
121
|
-
ids = Object.keys(this.page.fetchers);
|
|
122
|
-
else if (typeof ids === 'string')
|
|
123
|
-
ids = [ids];
|
|
124
|
-
|
|
125
|
-
console.log("[api] Reload data", ids, params, this.page.fetchers);
|
|
126
|
-
|
|
127
|
-
for (const id of ids) {
|
|
128
|
-
|
|
129
|
-
const fetcher = this.page.fetchers[id];
|
|
130
|
-
if (fetcher === undefined)
|
|
131
|
-
return console.error(`Unable to reload ${id}: Request not found in fetchers list.`);
|
|
132
|
-
|
|
133
|
-
if (params !== undefined)
|
|
134
|
-
fetcher.data = { ...(fetcher.data || {}), ...params };
|
|
135
|
-
|
|
136
|
-
console.log("[api][reload]", id, fetcher.method, fetcher.path, fetcher.data);
|
|
137
|
-
const indicator = this.toast.loading("Loading ...");
|
|
138
|
-
|
|
139
|
-
this.request.fetchAsync(fetcher.method, fetcher.path, fetcher.data).then((data) => {
|
|
140
|
-
|
|
141
|
-
this.api.set({ [id]: data });
|
|
142
|
-
|
|
143
|
-
}).finally(() => {
|
|
144
|
-
|
|
145
|
-
indicator.close(true);
|
|
146
|
-
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
114
|
}
|
|
152
115
|
|
|
153
116
|
// Is overwrote by the native app
|
|
@@ -194,10 +157,51 @@ export class ClientContext {
|
|
|
194
157
|
|
|
195
158
|
// fetch doit appartenir à response, et non clientcontxt
|
|
196
159
|
// car la méthode varie selon client (http) ou serveur (router.resolve)
|
|
197
|
-
public api =
|
|
198
|
-
|
|
199
|
-
set: (
|
|
200
|
-
|
|
160
|
+
public api = {
|
|
161
|
+
...this.request.api,
|
|
162
|
+
set: (newData: TObjetDonnees) => {
|
|
163
|
+
|
|
164
|
+
console.log("[api] Update page data", newData);
|
|
165
|
+
if (this.page)
|
|
166
|
+
this.page.setAllData(curData => ({ ...curData, ...newData }));
|
|
167
|
+
|
|
168
|
+
},
|
|
169
|
+
reload: (ids?: string | string[], params?: TObjetDonnees) => {
|
|
170
|
+
|
|
171
|
+
if (this.page === undefined)
|
|
172
|
+
throw new Error("context.page is missing");
|
|
173
|
+
|
|
174
|
+
if (ids === undefined)
|
|
175
|
+
ids = Object.keys(this.page.fetchers);
|
|
176
|
+
else if (typeof ids === 'string')
|
|
177
|
+
ids = [ids];
|
|
178
|
+
|
|
179
|
+
console.log("[api] Reload data", ids, params, this.page.fetchers);
|
|
180
|
+
|
|
181
|
+
for (const id of ids) {
|
|
182
|
+
|
|
183
|
+
const fetcher = this.page.fetchers[id];
|
|
184
|
+
if (fetcher === undefined)
|
|
185
|
+
return console.error(`Unable to reload ${id}: Request not found in fetchers list.`);
|
|
186
|
+
|
|
187
|
+
if (params !== undefined)
|
|
188
|
+
fetcher.data = { ...(fetcher.data || {}), ...params };
|
|
189
|
+
|
|
190
|
+
console.log("[api][reload]", id, fetcher.method, fetcher.path, fetcher.data);
|
|
191
|
+
const indicator = this.toast.loading("Loading ...");
|
|
192
|
+
|
|
193
|
+
this.request.fetchAsync(fetcher.method, fetcher.path, fetcher.data).then((data) => {
|
|
194
|
+
|
|
195
|
+
this.api.set({ [id]: data });
|
|
196
|
+
|
|
197
|
+
}).finally(() => {
|
|
198
|
+
|
|
199
|
+
indicator.close(true);
|
|
200
|
+
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
201
205
|
|
|
202
206
|
public handleError(e: Error) {
|
|
203
207
|
switch (e.http) {
|
|
@@ -50,6 +50,7 @@ const Page = ({ page, isCurrent }: { page: PageResponse, isCurrent?: boolean })
|
|
|
50
50
|
id={page.id === undefined ? undefined : 'page_' + page.id}
|
|
51
51
|
>
|
|
52
52
|
|
|
53
|
+
{/* Make request parameters and api data accessible from the page component */}
|
|
53
54
|
{page.component ? (
|
|
54
55
|
|
|
55
56
|
<page.component {...gui.request.data} {...data} />
|
|
@@ -94,12 +94,19 @@ export const Link = ({ to, ...props }: {
|
|
|
94
94
|
className?: string
|
|
95
95
|
}) => {
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
// External = open in new tab by default
|
|
98
|
+
if (to[0] !== '/' || to.startsWith('//'))
|
|
99
|
+
props.target = '_blank';
|
|
100
|
+
// Otherwise, propagate to the router
|
|
101
|
+
else
|
|
102
|
+
props.onClick = (e) => {
|
|
99
103
|
history?.push(to);
|
|
100
104
|
e.preventDefault();
|
|
101
105
|
return false
|
|
102
|
-
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<a {...props} href={to} />
|
|
103
110
|
)
|
|
104
111
|
|
|
105
112
|
}
|
|
File without changes
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { ComponentChild } from 'preact'
|
|
9
9
|
|
|
10
10
|
// Libs
|
|
11
|
-
import { Erreur, TListeErreursSaisie,
|
|
11
|
+
import { Erreur, TListeErreursSaisie, InputErrorSchema } from '@common/errors';
|
|
12
12
|
|
|
13
13
|
import { EXCLURE_VALEUR } from './validators/build';
|
|
14
14
|
|
|
@@ -216,7 +216,7 @@ export const validate = async <TSchemaA extends TSchema, TDonnees extends TObjet
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
if (nbErreurs !== 0 && opts.critique === true) {
|
|
219
|
-
throw new
|
|
219
|
+
throw new InputErrorSchema(erreurs);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
debug && console.log('[schema][valider]', inputAvalider, '=>', output);
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'validator';
|
|
12
12
|
|
|
13
13
|
// Libs
|
|
14
|
-
import {
|
|
14
|
+
import { InputError } from '@common/errors';
|
|
15
15
|
import File from '@common/data/file';
|
|
16
16
|
|
|
17
17
|
// Libs métier
|
|
@@ -39,7 +39,7 @@ export const object = (opts: TSchemaChamp<object> & {} = {}) => champ<object>('o
|
|
|
39
39
|
}*/
|
|
40
40
|
|
|
41
41
|
if (typeof val !== 'object' || val.constructor !== Object)
|
|
42
|
-
throw new
|
|
42
|
+
throw new InputError("This value must be an object.");
|
|
43
43
|
|
|
44
44
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour) : val;
|
|
45
45
|
},
|
|
@@ -60,7 +60,7 @@ export const array = (subtype?: Schema<any> | TSchemaChamp<any[]>, { choix, ...o
|
|
|
60
60
|
//console.log('VALIDER ARRAY', items, donneesSaisie);
|
|
61
61
|
|
|
62
62
|
if (!Array.isArray(items))
|
|
63
|
-
throw new
|
|
63
|
+
throw new InputError("This value must be an array.");
|
|
64
64
|
|
|
65
65
|
// Verif items
|
|
66
66
|
if (subtype !== undefined) {
|
|
@@ -86,7 +86,7 @@ export const choice = (values: any[], opts: TSchemaChamp<any> & {} = {}) => cham
|
|
|
86
86
|
valider: async (val: any, donneesSaisie: TObjetDonnees, donneesRetour: TObjetDonnees) => {
|
|
87
87
|
|
|
88
88
|
if (!values.includes(val))
|
|
89
|
-
throw new
|
|
89
|
+
throw new InputError("Invalid value. Must be: " + values.join(', '));
|
|
90
90
|
|
|
91
91
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour) : val;
|
|
92
92
|
},
|
|
@@ -104,21 +104,21 @@ export const string = ({ min, max, ...opts }: TSchemaChamp<string> = {}) => cham
|
|
|
104
104
|
else if (typeof val === 'number')
|
|
105
105
|
return val.toString();
|
|
106
106
|
else if (typeof val !== 'string')
|
|
107
|
-
throw new
|
|
107
|
+
throw new InputError("This value must be a string.");
|
|
108
108
|
|
|
109
109
|
// Espaces blancs
|
|
110
110
|
val = trim(val);
|
|
111
111
|
|
|
112
112
|
// Taille min
|
|
113
113
|
if (val.length < min)
|
|
114
|
-
throw new
|
|
114
|
+
throw new InputError(`Must be at least ` + min + ' characters');
|
|
115
115
|
|
|
116
116
|
// Taille max
|
|
117
117
|
if (val.length > max)
|
|
118
118
|
if (corriger)
|
|
119
119
|
val = val.substring(0, max);
|
|
120
120
|
else
|
|
121
|
-
throw new
|
|
121
|
+
throw new InputError(`Must be up to ` + max + ' characters');
|
|
122
122
|
|
|
123
123
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour) : val;
|
|
124
124
|
},
|
|
@@ -131,7 +131,7 @@ export const url = (opts: TSchemaChamp<string> & {} = {}) => string({
|
|
|
131
131
|
if (!isURL(val, {
|
|
132
132
|
// https://www.npmjs.com/package/validator
|
|
133
133
|
}))
|
|
134
|
-
throw new
|
|
134
|
+
throw new InputError(`Please provide a valid URL.`);
|
|
135
135
|
|
|
136
136
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour, corriger) : val;
|
|
137
137
|
},
|
|
@@ -142,7 +142,7 @@ export const email = (opts: TSchemaChamp<string> & {} = {}) => string({
|
|
|
142
142
|
valider: async (val: any, donneesSaisie: TObjetDonnees, donneesRetour: TObjetDonnees, corriger?: boolean) => {
|
|
143
143
|
|
|
144
144
|
if (!isEmail(val))
|
|
145
|
-
throw new
|
|
145
|
+
throw new InputError("Please enter a valid email address.");
|
|
146
146
|
|
|
147
147
|
const retour = normalizeEmail(val);
|
|
148
148
|
|
|
@@ -177,7 +177,7 @@ const nombre = (float: boolean) => ({ ...opts }: TSchemaChamp<number> & {} = {})
|
|
|
177
177
|
if (corriger)
|
|
178
178
|
val = opts.min;
|
|
179
179
|
else
|
|
180
|
-
throw new
|
|
180
|
+
throw new InputError("This value must be a number.");
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// Minimum
|
|
@@ -185,14 +185,14 @@ const nombre = (float: boolean) => ({ ...opts }: TSchemaChamp<number> & {} = {})
|
|
|
185
185
|
if (corriger)
|
|
186
186
|
val = opts.min;
|
|
187
187
|
else
|
|
188
|
-
throw new
|
|
188
|
+
throw new InputError(`Must be at least ` + opts.min);
|
|
189
189
|
|
|
190
190
|
// Maximum
|
|
191
191
|
if (opts.max !== undefined && val > opts.max)
|
|
192
192
|
if (corriger)
|
|
193
193
|
val = opts.max;
|
|
194
194
|
else
|
|
195
|
-
throw new
|
|
195
|
+
throw new InputError(`Must be up to ` + opts.max);
|
|
196
196
|
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -210,7 +210,7 @@ export const bool = (opts: TSchemaChamp<boolean> & {} = {}) => champ<boolean>('b
|
|
|
210
210
|
valider: async (val: any, donneesSaisie: TObjetDonnees, donneesRetour: TObjetDonnees) => {
|
|
211
211
|
|
|
212
212
|
if (typeof val !== 'boolean' && !['true', 'false'].includes(val))
|
|
213
|
-
throw new
|
|
213
|
+
throw new InputError("This value must be a boolean.");
|
|
214
214
|
|
|
215
215
|
val = !!val;
|
|
216
216
|
|
|
@@ -233,12 +233,12 @@ export const date = (opts: TSchemaChamp<Date> & {} = {}) => champ<Date>('date',
|
|
|
233
233
|
if (chaine) {
|
|
234
234
|
|
|
235
235
|
if (!isISO8601(val))
|
|
236
|
-
throw new
|
|
236
|
+
throw new InputError("This value must be a date.");
|
|
237
237
|
|
|
238
238
|
val = toDate(val);
|
|
239
239
|
|
|
240
240
|
} else if (!(val instanceof Date))
|
|
241
|
-
throw new
|
|
241
|
+
throw new InputError("This value must be a date.");
|
|
242
242
|
|
|
243
243
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour) : val;
|
|
244
244
|
|
|
@@ -265,7 +265,7 @@ export const validateurFichier = async (
|
|
|
265
265
|
console.log('VALIDER FICHIER', type, val);
|
|
266
266
|
|
|
267
267
|
if (!(val instanceof NormalizedFile))
|
|
268
|
-
throw new
|
|
268
|
+
throw new InputError(`Must be a File (${typeof val} received)`);
|
|
269
269
|
|
|
270
270
|
// MIME
|
|
271
271
|
if (type !== undefined) {
|
|
@@ -284,7 +284,7 @@ export const validateurFichier = async (
|
|
|
284
284
|
// Vérification
|
|
285
285
|
const mimeFichier = val.type;
|
|
286
286
|
if (!mimetypes.includes(mimeFichier))
|
|
287
|
-
throw new
|
|
287
|
+
throw new InputError('Only the following formats are allowed: ' + mimetypes.join(', ') + '. The file you gave is ' + mimeFichier + '.');
|
|
288
288
|
|
|
289
289
|
}
|
|
290
290
|
|
|
@@ -292,7 +292,7 @@ export const validateurFichier = async (
|
|
|
292
292
|
if (taille) {
|
|
293
293
|
const tailleFichier = val.size / 1024 / 1024; // Mo
|
|
294
294
|
if (tailleFichier > taille)
|
|
295
|
-
throw new
|
|
295
|
+
throw new InputError(`Le fichier ne doit pas faire plus de ${taille} Mo (taille reçue: ${tailleFichier} Mo)`);
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
return opts.valider ? await opts.valider(val, donneesSaisie, donneesRetour) : val;
|