firstly 0.0.12 → 0.0.14
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/CHANGELOG.md +16 -0
- package/esm/ROUTES.d.ts +2 -0
- package/esm/ROUTES.js +1 -0
- package/esm/api/index.d.ts +9 -0
- package/esm/api/index.js +3 -1
- package/esm/auth/AuthController.d.ts +12 -23
- package/esm/auth/AuthController.js +12 -31
- package/esm/auth/server/AuthController.server.d.ts +11 -11
- package/esm/auth/server/AuthController.server.js +99 -34
- package/esm/auth/server/handleGuard.d.ts +16 -0
- package/esm/auth/server/handleGuard.js +67 -0
- package/esm/auth/server/helperFirstly.d.ts +1 -1
- package/esm/auth/server/helperFirstly.js +1 -0
- package/esm/auth/server/index.d.ts +3 -1
- package/esm/auth/server/index.js +3 -1
- package/esm/auth/server/module.d.ts +105 -89
- package/esm/auth/server/module.js +55 -42
- package/esm/auth/server/providers/github.d.ts +4 -2
- package/esm/auth/server/providers/github.js +2 -2
- package/esm/auth/static/assets/Page-B0XXxe0N.d.ts +6 -0
- package/esm/auth/static/assets/Page-B0XXxe0N.js +1 -0
- package/esm/auth/static/assets/Page-DdKMiUZn.d.ts +6 -0
- package/esm/auth/static/assets/Page-DdKMiUZn.js +20 -0
- package/esm/auth/static/assets/Page-UV_hqY7I.d.ts +6 -0
- package/esm/auth/static/assets/Page-UV_hqY7I.js +1 -0
- package/esm/auth/static/assets/Page-mK42zGEw.css +1 -0
- package/esm/auth/static/assets/index-C9jzxOBu.d.ts +151 -0
- package/esm/auth/static/assets/index-C9jzxOBu.js +42 -0
- package/esm/auth/static/assets/index-DKWpA6v7.css +4 -0
- package/esm/auth/static/index.html +11 -11
- package/esm/auth/types.d.ts +26 -3
- package/esm/bin/cmd.js +423 -152
- package/esm/cellsBuildor.js +1 -1
- package/esm/common.d.ts +5 -0
- package/esm/common.js +8 -0
- package/esm/cron/server/index.js +1 -1
- package/esm/feedback/FeedbackController.js +58 -53
- package/esm/feedback/server/index.d.ts +6 -15
- package/esm/feedback/server/index.js +4 -5
- package/esm/feedback/types.d.ts +14 -0
- package/esm/feedback/types.js +4 -0
- package/esm/feedback/ui/DialogIssue.svelte +131 -119
- package/esm/feedback/ui/DialogIssue.svelte.d.ts +20 -18
- package/esm/feedback/ui/DialogIssues.svelte +108 -99
- package/esm/feedback/ui/DialogIssues.svelte.d.ts +20 -18
- package/esm/feedback/ui/DialogMilestones.svelte +40 -34
- package/esm/feedback/ui/DialogMilestones.svelte.d.ts +18 -16
- package/esm/feedback/ui/Feedback.svelte +11 -9
- package/esm/feedback/ui/Feedback.svelte.d.ts +16 -14
- package/esm/index.d.ts +2 -5
- package/esm/index.js +2 -8
- package/esm/mail/server/index.d.ts +9 -2
- package/esm/mail/server/index.js +3 -1
- package/esm/mail/templates/DefaultMail.svelte +81 -61
- package/esm/mail/templates/DefaultMail.svelte.d.ts +28 -26
- package/esm/server/index.d.ts +0 -0
- package/esm/server/index.js +1 -0
- package/esm/storeItem.d.ts +1 -4
- package/esm/storeItem.js +1 -1
- package/esm/storeList.d.ts +1 -4
- package/esm/sveltekit/server/index.d.ts +3 -9
- package/esm/sveltekit/server/index.js +3 -0
- package/esm/ui/Button.svelte +112 -89
- package/esm/ui/Button.svelte.d.ts +34 -24
- package/esm/ui/Clipboardable.svelte +24 -17
- package/esm/ui/Clipboardable.svelte.d.ts +34 -23
- package/esm/ui/Field.svelte +328 -285
- package/esm/ui/Field.svelte.d.ts +15 -8
- package/esm/ui/FieldGroup.svelte +112 -91
- package/esm/ui/FieldGroup.svelte.d.ts +17 -6
- package/esm/ui/Grid.svelte +322 -308
- package/esm/ui/Grid.svelte.d.ts +17 -6
- package/esm/ui/GridLoading.svelte +28 -27
- package/esm/ui/GridLoading.svelte.d.ts +19 -17
- package/esm/ui/GridPaginate.svelte +68 -61
- package/esm/ui/GridPaginate.svelte.d.ts +21 -19
- package/esm/ui/Icon.svelte +116 -80
- package/esm/ui/Icon.svelte.d.ts +52 -43
- package/esm/ui/Loading.svelte +10 -8
- package/esm/ui/Loading.svelte.d.ts +29 -18
- package/esm/ui/Tooltip.svelte +38 -35
- package/esm/ui/Tooltip.svelte.d.ts +30 -20
- package/esm/ui/dialog/DialogForm.svelte +70 -63
- package/esm/ui/dialog/DialogForm.svelte.d.ts +18 -16
- package/esm/ui/dialog/DialogManagement.svelte +74 -74
- package/esm/ui/dialog/DialogManagement.svelte.d.ts +22 -21
- package/esm/ui/dialog/DialogPrimitive.svelte +82 -76
- package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +35 -25
- package/esm/ui/dialog/FormEditAction.svelte +58 -50
- package/esm/ui/dialog/FormEditAction.svelte.d.ts +13 -6
- package/esm/ui/dialog/dialog.d.ts +1 -4
- package/esm/ui/internals/FieldContainer.svelte +24 -17
- package/esm/ui/internals/FieldContainer.svelte.d.ts +37 -28
- package/esm/ui/internals/Input.svelte +136 -102
- package/esm/ui/internals/Input.svelte.d.ts +34 -32
- package/esm/ui/internals/Textarea.svelte +60 -52
- package/esm/ui/internals/Textarea.svelte.d.ts +31 -28
- package/esm/ui/internals/select/MultiSelectMelt.svelte +243 -199
- package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +29 -27
- package/esm/ui/internals/select/SelectMelt.svelte +254 -219
- package/esm/ui/internals/select/SelectMelt.svelte.d.ts +34 -32
- package/esm/ui/internals/select/SelectRadio.svelte +39 -33
- package/esm/ui/internals/select/SelectRadio.svelte.d.ts +24 -22
- package/esm/ui/link/Link.svelte +25 -20
- package/esm/ui/link/Link.svelte.d.ts +31 -23
- package/esm/ui/link/LinkPlus.svelte +52 -51
- package/esm/ui/link/LinkPlus.svelte.d.ts +20 -18
- package/esm/vite/index.d.ts +2 -3
- package/esm/vite/index.js +33 -26
- package/package.json +16 -20
- package/esm/auth/static/assets/Page-Bb8bFlrP.d.ts +0 -4
- package/esm/auth/static/assets/Page-Bb8bFlrP.js +0 -1
- package/esm/auth/static/assets/Page-BxomFlZ8.d.ts +0 -4
- package/esm/auth/static/assets/Page-BxomFlZ8.js +0 -1
- package/esm/auth/static/assets/Page-CaIYu0-y.d.ts +0 -6
- package/esm/auth/static/assets/Page-CaIYu0-y.js +0 -19
- package/esm/auth/static/assets/Page-MkYglNtu.css +0 -1
- package/esm/auth/static/assets/index-Bl0Bk5u0.d.ts +0 -64
- package/esm/auth/static/assets/index-Bl0Bk5u0.js +0 -2
- package/esm/auth/static/assets/index-R27C_TlP.css +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# firstly
|
|
2
2
|
|
|
3
|
+
## 0.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#85](https://github.com/jycouet/firstly/pull/85)
|
|
8
|
+
[`993f733`](https://github.com/jycouet/firstly/commit/993f73374591f134d76e30f8b5e4402b4d3112d0)
|
|
9
|
+
Thanks [@jycouet](https://github.com/jycouet)! - prepare JYC 014
|
|
10
|
+
|
|
11
|
+
## 0.0.13
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#66](https://github.com/jycouet/firstly/pull/66)
|
|
16
|
+
[`7d8b323`](https://github.com/jycouet/firstly/commit/7d8b323b49d7d76b6d59ec887ed2e37a2238f201)
|
|
17
|
+
Thanks [@jycouet](https://github.com/jycouet)! - prepare JYC 013
|
|
18
|
+
|
|
3
19
|
## 0.0.12
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/esm/ROUTES.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ declare const AllObjs: {
|
|
|
33
33
|
}) => string;
|
|
34
34
|
"/": string;
|
|
35
35
|
"/auth": string;
|
|
36
|
+
"/demo/task": string;
|
|
36
37
|
"/mail": string;
|
|
37
38
|
"/ui/dialog": string;
|
|
38
39
|
"/ui/enum": string;
|
|
@@ -71,6 +72,7 @@ export type KIT_ROUTES = {
|
|
|
71
72
|
PAGES: {
|
|
72
73
|
'/': never;
|
|
73
74
|
'/auth': never;
|
|
75
|
+
'/demo/task': never;
|
|
74
76
|
'/mail': never;
|
|
75
77
|
'/ui/dialog': never;
|
|
76
78
|
'/ui/enum': never;
|
package/esm/ROUTES.js
CHANGED
package/esm/api/index.d.ts
CHANGED
|
@@ -28,9 +28,18 @@ export declare class Module {
|
|
|
28
28
|
type Options = RemultServerOptions<RequestEvent<Partial<Record<string, string>>, string | null>> & {
|
|
29
29
|
modules?: Module[] | undefined;
|
|
30
30
|
};
|
|
31
|
+
declare module 'remult' {
|
|
32
|
+
interface RemultContext {
|
|
33
|
+
request: RequestEvent;
|
|
34
|
+
setHeaders(headers: Record<string, string>): void;
|
|
35
|
+
setCookie(...args: Parameters<RequestEvent['cookies']['set']>): void;
|
|
36
|
+
deleteCookie(...args: Parameters<RequestEvent['cookies']['delete']>): void;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
export declare let entities: ClassType<any>[];
|
|
32
40
|
/**
|
|
33
41
|
* it's basically `remultSveltekit` with the `modules` option
|
|
42
|
+
* @deprecated will be done directly in remult when modules will be in 😉
|
|
34
43
|
*/
|
|
35
44
|
export declare const firstly: (o: Options) => import("remult/remult-sveltekit").RemultSveltekitServer;
|
|
36
45
|
/**
|
package/esm/api/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import {} from 'remult';
|
|
|
2
2
|
import { remultSveltekit } from 'remult/remult-sveltekit';
|
|
3
3
|
import { Log } from '@kitql/helpers';
|
|
4
4
|
import { building } from '$app/environment';
|
|
5
|
+
import { sveltekit } from '../sveltekit/server';
|
|
5
6
|
export class Module {
|
|
6
7
|
name;
|
|
7
8
|
log;
|
|
@@ -25,10 +26,11 @@ export class Module {
|
|
|
25
26
|
export let entities = [];
|
|
26
27
|
/**
|
|
27
28
|
* it's basically `remultSveltekit` with the `modules` option
|
|
29
|
+
* @deprecated will be done directly in remult when modules will be in 😉
|
|
28
30
|
*/
|
|
29
31
|
export const firstly = (o) => {
|
|
30
32
|
const modulesSorted = modulesFlatAndOrdered([
|
|
31
|
-
...(o.modules ?? []),
|
|
33
|
+
...[...(o.modules ?? []), sveltekit()],
|
|
32
34
|
new Module({
|
|
33
35
|
name: 'default',
|
|
34
36
|
entities: o.entities ?? [],
|
|
@@ -1,53 +1,42 @@
|
|
|
1
|
-
import type { ProviderConfigured } from './
|
|
1
|
+
import type { AuthServerAbstraction, ProviderConfigured } from './types';
|
|
2
2
|
export declare class AuthController {
|
|
3
3
|
#private;
|
|
4
|
-
static _setAbstraction(impl:
|
|
5
|
-
signOut: any;
|
|
6
|
-
signInDemo: any;
|
|
7
|
-
invite: any;
|
|
8
|
-
signUpPassword: any;
|
|
9
|
-
signInPassword: any;
|
|
10
|
-
forgotPassword: any;
|
|
11
|
-
resetPassword: any;
|
|
12
|
-
signInOTP: any;
|
|
13
|
-
verifyOtp: any;
|
|
14
|
-
signInOAuthGetUrl: any;
|
|
15
|
-
}): void;
|
|
4
|
+
static _setAbstraction(impl: AuthServerAbstraction): void;
|
|
16
5
|
/**
|
|
17
6
|
* Sign out the current user
|
|
18
7
|
*/
|
|
19
|
-
static signOut(): Promise<
|
|
8
|
+
static signOut(): Promise<import("./types").AuthResponse>;
|
|
20
9
|
/**
|
|
21
10
|
* Sign in with a demo account
|
|
22
11
|
* _(The easiest way to demo & test your application)_
|
|
23
12
|
*/
|
|
24
|
-
static signInDemo(name: string): Promise<
|
|
13
|
+
static signInDemo(name: string): Promise<import("./types").AuthResponse>;
|
|
25
14
|
/**
|
|
26
15
|
* This is for login / password authentication Invite someone
|
|
27
16
|
*/
|
|
28
|
-
static invite(email: string): Promise<
|
|
17
|
+
static invite(email: string): Promise<import("./types").AuthResponse>;
|
|
29
18
|
/**
|
|
30
19
|
* This is for login / password authentication SignUp
|
|
31
20
|
*/
|
|
32
|
-
static signUpPassword(email: string, password: string): Promise<
|
|
21
|
+
static signUpPassword(email: string, password: string): Promise<import("./types").AuthResponse>;
|
|
33
22
|
/**
|
|
34
23
|
* This is for login / password authentication SignIn
|
|
35
24
|
*/
|
|
36
|
-
static signInPassword(email: string, password: string): Promise<
|
|
25
|
+
static signInPassword(email: string, password: string): Promise<import("./types").AuthResponse>;
|
|
37
26
|
/**
|
|
38
27
|
* Forgot your password ? Send a mail to reset it.
|
|
39
28
|
*/
|
|
40
|
-
static forgotPassword(email: string): Promise<
|
|
29
|
+
static forgotPassword(email: string): Promise<import("./types").AuthResponse>;
|
|
41
30
|
/**
|
|
42
31
|
* Reset your password with a token
|
|
43
32
|
*/
|
|
44
|
-
static resetPassword(token: string, password: string): Promise<
|
|
33
|
+
static resetPassword(token: string, password: string): Promise<import("./types").AuthResponse>;
|
|
45
34
|
/** OTP */
|
|
46
|
-
static signInOTP(email: string): Promise<
|
|
35
|
+
static signInOTP(email: string): Promise<import("./types").AuthResponse>;
|
|
47
36
|
/**
|
|
48
37
|
* Verify the OTP code
|
|
49
38
|
*/
|
|
50
|
-
static verifyOtp(email: string, otp: string): Promise<
|
|
39
|
+
static verifyOtp(email: string, otp: string): Promise<import("./types").AuthResponse>;
|
|
51
40
|
/** OAUTH */
|
|
52
41
|
/**
|
|
53
42
|
* The the url to redirect to for the OAuth provider
|
|
@@ -65,5 +54,5 @@ export declare class AuthController {
|
|
|
65
54
|
provider: T;
|
|
66
55
|
options?: ProviderConfigured[T];
|
|
67
56
|
redirect?: string;
|
|
68
|
-
}): Promise<
|
|
57
|
+
}): Promise<string>;
|
|
69
58
|
}
|
|
@@ -7,82 +7,63 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { BackendMethod } from 'remult';
|
|
8
8
|
import { FF_Role_Auth } from './Entities';
|
|
9
9
|
export class AuthController {
|
|
10
|
-
|
|
11
|
-
static #signOutFn;
|
|
12
|
-
static #signInDemoFn;
|
|
13
|
-
static #inviteFn;
|
|
14
|
-
static #signUpPasswordFn;
|
|
15
|
-
static #signInPasswordFn;
|
|
16
|
-
static #forgotPasswordFn;
|
|
17
|
-
static #resetPasswordFn;
|
|
18
|
-
static #signInOTPFn;
|
|
19
|
-
static #verifyOtpFn;
|
|
20
|
-
static #signInOAuthGetUrlFn;
|
|
10
|
+
static #server;
|
|
21
11
|
// Internal setter method that can be used by the module
|
|
22
12
|
static _setAbstraction(impl) {
|
|
23
|
-
this.#
|
|
24
|
-
this.#signInDemoFn = impl.signInDemo;
|
|
25
|
-
this.#inviteFn = impl.invite;
|
|
26
|
-
this.#signUpPasswordFn = impl.signUpPassword;
|
|
27
|
-
this.#signInPasswordFn = impl.signInPassword;
|
|
28
|
-
this.#forgotPasswordFn = impl.forgotPassword;
|
|
29
|
-
this.#resetPasswordFn = impl.resetPassword;
|
|
30
|
-
this.#signInOTPFn = impl.signInOTP;
|
|
31
|
-
this.#verifyOtpFn = impl.verifyOtp;
|
|
32
|
-
this.#signInOAuthGetUrlFn = impl.signInOAuthGetUrl;
|
|
13
|
+
this.#server = impl;
|
|
33
14
|
}
|
|
34
15
|
/**
|
|
35
16
|
* Sign out the current user
|
|
36
17
|
*/
|
|
37
18
|
static async signOut() {
|
|
38
|
-
return await AuthController.#
|
|
19
|
+
return await AuthController.#server.signOut();
|
|
39
20
|
}
|
|
40
21
|
/**
|
|
41
22
|
* Sign in with a demo account
|
|
42
23
|
* _(The easiest way to demo & test your application)_
|
|
43
24
|
*/
|
|
44
25
|
static async signInDemo(name) {
|
|
45
|
-
return await AuthController.#
|
|
26
|
+
return await AuthController.#server.signInDemo(name);
|
|
46
27
|
}
|
|
47
28
|
/**
|
|
48
29
|
* This is for login / password authentication Invite someone
|
|
49
30
|
*/
|
|
50
31
|
static async invite(email) {
|
|
51
|
-
return await AuthController.#
|
|
32
|
+
return await AuthController.#server.invite(email);
|
|
52
33
|
}
|
|
53
34
|
/**
|
|
54
35
|
* This is for login / password authentication SignUp
|
|
55
36
|
*/
|
|
56
37
|
static async signUpPassword(email, password) {
|
|
57
|
-
return await AuthController.#
|
|
38
|
+
return await AuthController.#server.signUpPassword(email, password);
|
|
58
39
|
}
|
|
59
40
|
/**
|
|
60
41
|
* This is for login / password authentication SignIn
|
|
61
42
|
*/
|
|
62
43
|
static async signInPassword(email, password) {
|
|
63
|
-
return await AuthController.#
|
|
44
|
+
return await AuthController.#server.signInPassword(email, password);
|
|
64
45
|
}
|
|
65
46
|
/**
|
|
66
47
|
* Forgot your password ? Send a mail to reset it.
|
|
67
48
|
*/
|
|
68
49
|
static async forgotPassword(email) {
|
|
69
|
-
return await AuthController.#
|
|
50
|
+
return await AuthController.#server.forgotPassword(email);
|
|
70
51
|
}
|
|
71
52
|
/**
|
|
72
53
|
* Reset your password with a token
|
|
73
54
|
*/
|
|
74
55
|
static async resetPassword(token, password) {
|
|
75
|
-
return await AuthController.#
|
|
56
|
+
return await AuthController.#server.resetPassword(token, password);
|
|
76
57
|
}
|
|
77
58
|
/** OTP */
|
|
78
59
|
static async signInOTP(email) {
|
|
79
|
-
return await AuthController.#
|
|
60
|
+
return await AuthController.#server.signInOTP(email);
|
|
80
61
|
}
|
|
81
62
|
/**
|
|
82
63
|
* Verify the OTP code
|
|
83
64
|
*/
|
|
84
65
|
static async verifyOtp(email, otp) {
|
|
85
|
-
return await AuthController.#
|
|
66
|
+
return await AuthController.#server.verifyOtp(email, otp);
|
|
86
67
|
}
|
|
87
68
|
/** OAUTH */
|
|
88
69
|
/**
|
|
@@ -98,7 +79,7 @@ export class AuthController {
|
|
|
98
79
|
* _(popup example should work too, and a nice example/componant would be appreciated)_
|
|
99
80
|
*/
|
|
100
81
|
static async signInOAuthGetUrl(o) {
|
|
101
|
-
return await AuthController.#
|
|
82
|
+
return await AuthController.#server.signInOAuthGetUrl(o);
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
85
|
__decorate([
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AuthResponse, ProviderConfigured } from '../types.js';
|
|
2
2
|
export declare class AuthControllerServer {
|
|
3
3
|
/**
|
|
4
4
|
* Sign out the current user
|
|
5
5
|
*/
|
|
6
|
-
static signOut(): Promise<
|
|
6
|
+
static signOut(): Promise<AuthResponse>;
|
|
7
7
|
/**
|
|
8
8
|
* Sign in with a demo account
|
|
9
9
|
* _(The easiest way to demo & test your application)_
|
|
10
10
|
*/
|
|
11
|
-
static signInDemo(name: string): Promise<
|
|
11
|
+
static signInDemo(name: string): Promise<AuthResponse>;
|
|
12
12
|
/**
|
|
13
13
|
* This is for login / password authentication invite
|
|
14
14
|
*/
|
|
15
|
-
static invite(emailParam: string): Promise<
|
|
15
|
+
static invite(emailParam: string): Promise<AuthResponse>;
|
|
16
16
|
/**
|
|
17
17
|
* This is for login / password authentication SignUp
|
|
18
18
|
* _(The first param `email` can be "anything")_
|
|
19
19
|
*/
|
|
20
|
-
static signUpPassword(emailParam: string, password: string): Promise<
|
|
20
|
+
static signUpPassword(emailParam: string, password: string): Promise<AuthResponse>;
|
|
21
21
|
/**
|
|
22
22
|
* This is for login / password authentication SignIn
|
|
23
23
|
* _(The first param `email` can be "anything")_
|
|
24
24
|
*/
|
|
25
|
-
static signInPassword(emailParam: string, password: string): Promise<
|
|
25
|
+
static signInPassword(emailParam: string, password: string): Promise<AuthResponse>;
|
|
26
26
|
/**
|
|
27
27
|
* Forgot your password ? Send a mail to reset it.
|
|
28
28
|
*/
|
|
29
|
-
static forgotPassword(emailParam: string): Promise<
|
|
29
|
+
static forgotPassword(emailParam: string): Promise<AuthResponse>;
|
|
30
30
|
/**
|
|
31
31
|
* Reset your password with a token
|
|
32
32
|
*/
|
|
33
|
-
static resetPassword(token: string, password: string): Promise<
|
|
33
|
+
static resetPassword(token: string, password: string): Promise<AuthResponse>;
|
|
34
34
|
/** OTP */
|
|
35
|
-
static signInOTP(emailParam: string): Promise<
|
|
35
|
+
static signInOTP(emailParam: string): Promise<AuthResponse>;
|
|
36
36
|
/**
|
|
37
37
|
* Verify the OTP code
|
|
38
38
|
*/
|
|
39
|
-
static verifyOtp(emailParam: string, otp: string): Promise<
|
|
39
|
+
static verifyOtp(emailParam: string, otp: string): Promise<AuthResponse>;
|
|
40
40
|
/** OAUTH */
|
|
41
41
|
/**
|
|
42
42
|
* The the url to redirect to for the OAuth provider
|
|
@@ -54,5 +54,5 @@ export declare class AuthControllerServer {
|
|
|
54
54
|
provider: T;
|
|
55
55
|
options?: ProviderConfigured[T];
|
|
56
56
|
redirect?: string;
|
|
57
|
-
}): Promise<
|
|
57
|
+
}): Promise<string>;
|
|
58
58
|
}
|
|
@@ -2,8 +2,7 @@ import { decodeHex, encodeHexLowerCase } from '@oslojs/encoding';
|
|
|
2
2
|
import { createTOTPKeyURI, generateTOTP, verifyTOTPWithGracePeriod } from '@oslojs/otp';
|
|
3
3
|
import { generateState } from 'arctic';
|
|
4
4
|
import { EntityError, remult, repo } from 'remult';
|
|
5
|
-
import { green, magenta, yellow } from '@kitql/helpers';
|
|
6
|
-
import { sendMail } from '../../mail/server/index.js';
|
|
5
|
+
import { gray, green, magenta, red, yellow } from '@kitql/helpers';
|
|
7
6
|
import { FFAuthProvider } from '../Entities.js';
|
|
8
7
|
import { invalidateSession } from './helperDb.js';
|
|
9
8
|
import { ff_createSession } from './helperFirstly.js';
|
|
@@ -11,6 +10,25 @@ import { createDate, generateAndEncodeToken } from './helperOslo.js';
|
|
|
11
10
|
import { deleteSessionTokenCookie, setOAuthStateCookie, setRedirectCookie, } from './helperRemultServer.js';
|
|
12
11
|
import { mergeRoles } from './helperRole.js';
|
|
13
12
|
import { AUTH_OPTIONS, authModuleRaw, getSafeOptions } from './module.js';
|
|
13
|
+
const getSendMail = () => {
|
|
14
|
+
if (!remult.context.sendMail) {
|
|
15
|
+
authModuleRaw.log.error(`Missing ${green(`remult.context`)}.${red(`sendMail`)}`);
|
|
16
|
+
authModuleRaw.log.error('');
|
|
17
|
+
authModuleRaw.log.error(gray('Add this to your modules:'));
|
|
18
|
+
authModuleRaw.log.error('import { mail } from "firstly/mail/server"');
|
|
19
|
+
authModuleRaw.log.error('');
|
|
20
|
+
authModuleRaw.log.error('{');
|
|
21
|
+
authModuleRaw.log.error(` modules: [`);
|
|
22
|
+
authModuleRaw.log.error(` mail({`);
|
|
23
|
+
authModuleRaw.log.error(` // options`);
|
|
24
|
+
authModuleRaw.log.error(` })`);
|
|
25
|
+
authModuleRaw.log.error(` ]`);
|
|
26
|
+
authModuleRaw.log.error('}');
|
|
27
|
+
authModuleRaw.log.error('');
|
|
28
|
+
throw new EntityError({ message: 'Error: Contact your administrator.' });
|
|
29
|
+
}
|
|
30
|
+
return remult.context.sendMail;
|
|
31
|
+
};
|
|
14
32
|
export class AuthControllerServer {
|
|
15
33
|
/**
|
|
16
34
|
* Sign out the current user
|
|
@@ -20,6 +38,10 @@ export class AuthControllerServer {
|
|
|
20
38
|
await invalidateSession(remult.user?.session.id);
|
|
21
39
|
}
|
|
22
40
|
deleteSessionTokenCookie();
|
|
41
|
+
return {
|
|
42
|
+
message: 'signed out',
|
|
43
|
+
user: undefined,
|
|
44
|
+
};
|
|
23
45
|
}
|
|
24
46
|
/**
|
|
25
47
|
* Sign in with a demo account
|
|
@@ -43,8 +65,11 @@ export class AuthControllerServer {
|
|
|
43
65
|
const r = mergeRoles(user.roles, account.roles);
|
|
44
66
|
user.roles = r.roles;
|
|
45
67
|
await repo(oSafe.User).save(user);
|
|
46
|
-
await ff_createSession(user.id);
|
|
47
|
-
return
|
|
68
|
+
const session = await ff_createSession(user.id);
|
|
69
|
+
return {
|
|
70
|
+
message: `You're in with demo account!`,
|
|
71
|
+
user: oSafe.transformDbUserToClientUser(session, user),
|
|
72
|
+
};
|
|
48
73
|
}
|
|
49
74
|
/**
|
|
50
75
|
* This is for login / password authentication invite
|
|
@@ -68,23 +93,26 @@ export class AuthControllerServer {
|
|
|
68
93
|
// const user = await repo(oSafe.User).insert({
|
|
69
94
|
// identifier: email,
|
|
70
95
|
// })
|
|
71
|
-
oSafe.providers?.password?.verifyMailExpiresIn;
|
|
72
96
|
await repo(oSafe.Account).insert({
|
|
73
97
|
provider: FFAuthProvider.PASSWORD.id,
|
|
74
98
|
providerUserId: email,
|
|
75
99
|
// userId: user.id,
|
|
76
100
|
// hashPassword: await passwordHash(password),
|
|
77
101
|
token: token,
|
|
78
|
-
expiresAt: createDate(AUTH_OPTIONS.providers?.password?.
|
|
102
|
+
expiresAt: createDate(AUTH_OPTIONS.providers?.password?.mail?.verify?.expiresIn ?? 5 * 60),
|
|
79
103
|
lastVerifiedAt: undefined,
|
|
80
104
|
});
|
|
81
105
|
const url = `${remult.context.request.url.origin}${oSafe.firstlyData.props.ui?.paths.reset_password}?token=${token}`;
|
|
82
106
|
if (AUTH_OPTIONS?.invitationSend) {
|
|
83
107
|
await AUTH_OPTIONS?.invitationSend({ email, url });
|
|
84
108
|
authModuleRaw.log.success(`${green('[custom]')}${magenta('[invitationSend]')} (${yellow(url)})`);
|
|
85
|
-
return
|
|
109
|
+
return {
|
|
110
|
+
message: 'Mail sent !',
|
|
111
|
+
user: remult.user,
|
|
112
|
+
};
|
|
86
113
|
}
|
|
87
114
|
else {
|
|
115
|
+
const sendMail = getSendMail();
|
|
88
116
|
await sendMail('invitationSend', {
|
|
89
117
|
to: email,
|
|
90
118
|
subject: 'Invitation',
|
|
@@ -107,24 +135,31 @@ export class AuthControllerServer {
|
|
|
107
135
|
},
|
|
108
136
|
});
|
|
109
137
|
authModuleRaw.log.success(`${magenta('[invitationSend]')} (${yellow(url)})`);
|
|
110
|
-
return
|
|
138
|
+
return {
|
|
139
|
+
message: 'Demo Mail sent !',
|
|
140
|
+
user: remult.user,
|
|
141
|
+
};
|
|
111
142
|
}
|
|
112
143
|
}
|
|
113
|
-
return
|
|
144
|
+
return {
|
|
145
|
+
message: 'ok',
|
|
146
|
+
user: remult.user,
|
|
147
|
+
};
|
|
114
148
|
}
|
|
115
149
|
/**
|
|
116
150
|
* This is for login / password authentication SignUp
|
|
117
151
|
* _(The first param `email` can be "anything")_
|
|
118
152
|
*/
|
|
119
153
|
static async signUpPassword(emailParam, password) {
|
|
120
|
-
const email = emailParam.toLowerCase();
|
|
121
154
|
const oSafe = getSafeOptions();
|
|
122
155
|
if (!oSafe.signUp) {
|
|
123
|
-
throw new EntityError({ message:
|
|
156
|
+
throw new EntityError({ message: oSafe.strings.cannotSignUp });
|
|
124
157
|
}
|
|
125
158
|
if (!oSafe.password.enabled) {
|
|
126
159
|
throw new EntityError({ message: 'Password is not enabled!' });
|
|
127
160
|
}
|
|
161
|
+
const email = emailParam.toLowerCase();
|
|
162
|
+
oSafe.password.validateInput({ identifier: email, password });
|
|
128
163
|
const existingAccount = await repo(oSafe.Account).findOne({
|
|
129
164
|
where: {
|
|
130
165
|
providerUserId: email,
|
|
@@ -134,7 +169,6 @@ export class AuthControllerServer {
|
|
|
134
169
|
if (existingAccount) {
|
|
135
170
|
throw new EntityError({ message: "You can't signup twice !" });
|
|
136
171
|
}
|
|
137
|
-
oSafe.password.validatePassword(password);
|
|
138
172
|
const token = generateAndEncodeToken();
|
|
139
173
|
await remult.dataProvider.transaction(async () => {
|
|
140
174
|
const user = await repo(oSafe.User).insert({
|
|
@@ -144,11 +178,11 @@ export class AuthControllerServer {
|
|
|
144
178
|
provider: FFAuthProvider.PASSWORD.id,
|
|
145
179
|
providerUserId: email,
|
|
146
180
|
userId: user.id,
|
|
147
|
-
hashPassword: oSafe.password.
|
|
181
|
+
hashPassword: await oSafe.password.hash(password),
|
|
148
182
|
token: oSafe.verifiedMethod === 'auto' ? undefined : token,
|
|
149
183
|
expiresAt: oSafe.verifiedMethod === 'auto'
|
|
150
184
|
? undefined
|
|
151
|
-
: createDate(AUTH_OPTIONS.providers?.password?.
|
|
185
|
+
: createDate(AUTH_OPTIONS.providers?.password?.mail?.verify?.expiresIn ?? 5 * 60),
|
|
152
186
|
lastVerifiedAt: oSafe.verifiedMethod === 'auto' ? new Date() : undefined,
|
|
153
187
|
});
|
|
154
188
|
});
|
|
@@ -157,16 +191,21 @@ export class AuthControllerServer {
|
|
|
157
191
|
identifier: email,
|
|
158
192
|
});
|
|
159
193
|
if (user) {
|
|
160
|
-
await ff_createSession(user.id);
|
|
194
|
+
const session = await ff_createSession(user.id);
|
|
195
|
+
return {
|
|
196
|
+
message: 'ok',
|
|
197
|
+
user: oSafe.transformDbUserToClientUser(session, user),
|
|
198
|
+
};
|
|
161
199
|
}
|
|
162
200
|
}
|
|
163
201
|
else {
|
|
164
202
|
const url = `${remult.context.request.url.origin}${oSafe.firstlyData.props.ui?.paths.verify_email}?token=${token}`;
|
|
165
|
-
if (AUTH_OPTIONS.providers?.password?.
|
|
166
|
-
await AUTH_OPTIONS.providers?.password.
|
|
203
|
+
if (AUTH_OPTIONS.providers?.password?.mail?.verify?.send) {
|
|
204
|
+
await AUTH_OPTIONS.providers?.password.mail.verify.send({ email, url });
|
|
167
205
|
authModuleRaw.log.success(`${green('[custom]')}${magenta('[verifyMailSend]')} (${yellow(url)})`);
|
|
168
206
|
}
|
|
169
207
|
else {
|
|
208
|
+
const sendMail = getSendMail();
|
|
170
209
|
await sendMail('verifyMailSend', {
|
|
171
210
|
to: email,
|
|
172
211
|
subject: 'Wecome',
|
|
@@ -187,7 +226,10 @@ export class AuthControllerServer {
|
|
|
187
226
|
authModuleRaw.log.success(`${magenta('[verifyMailSend]')} (${yellow(url)})`);
|
|
188
227
|
}
|
|
189
228
|
}
|
|
190
|
-
return
|
|
229
|
+
return {
|
|
230
|
+
message: 'ok',
|
|
231
|
+
user: remult.user,
|
|
232
|
+
};
|
|
191
233
|
}
|
|
192
234
|
/**
|
|
193
235
|
* This is for login / password authentication SignIn
|
|
@@ -196,6 +238,7 @@ export class AuthControllerServer {
|
|
|
196
238
|
static async signInPassword(emailParam, password) {
|
|
197
239
|
const email = emailParam.toLowerCase();
|
|
198
240
|
const oSafe = getSafeOptions();
|
|
241
|
+
oSafe.password.validateInput({ identifier: email, password });
|
|
199
242
|
if (!oSafe.password.enabled) {
|
|
200
243
|
throw new EntityError({ message: 'Password is not enabled!' });
|
|
201
244
|
}
|
|
@@ -206,10 +249,13 @@ export class AuthControllerServer {
|
|
|
206
249
|
},
|
|
207
250
|
});
|
|
208
251
|
if (existingAccount) {
|
|
209
|
-
const validPassword = oSafe.password.
|
|
252
|
+
const validPassword = oSafe.password.verify(password ?? '', existingAccount?.hashPassword ?? '');
|
|
210
253
|
if (validPassword) {
|
|
211
|
-
await ff_createSession(existingAccount.userId);
|
|
212
|
-
return
|
|
254
|
+
const session = await ff_createSession(existingAccount.userId);
|
|
255
|
+
return {
|
|
256
|
+
message: 'ok',
|
|
257
|
+
user: oSafe.transformDbUserToClientUser(session, existingAccount.user),
|
|
258
|
+
};
|
|
213
259
|
}
|
|
214
260
|
authModuleRaw.log.error({ email, passwordLength: password.length });
|
|
215
261
|
throw new EntityError({ message: 'Incorrect username or password' });
|
|
@@ -235,15 +281,19 @@ export class AuthControllerServer {
|
|
|
235
281
|
if (existingAccount) {
|
|
236
282
|
const token = generateAndEncodeToken();
|
|
237
283
|
existingAccount.token = token;
|
|
238
|
-
existingAccount.expiresAt = createDate(AUTH_OPTIONS.providers?.password?.
|
|
284
|
+
existingAccount.expiresAt = createDate(AUTH_OPTIONS.providers?.password?.mail?.reset?.expiresIn ?? 5 * 60);
|
|
239
285
|
await repo(oSafe.Account).save(existingAccount);
|
|
240
286
|
const url = `${remult.context.request.url.origin}${oSafe.firstlyData.props.ui?.paths.reset_password}?token=${token}`;
|
|
241
|
-
if (AUTH_OPTIONS.providers?.password?.
|
|
242
|
-
await AUTH_OPTIONS.providers?.password.
|
|
287
|
+
if (AUTH_OPTIONS.providers?.password?.mail?.reset?.send) {
|
|
288
|
+
await AUTH_OPTIONS.providers?.password.mail.reset.send({ email, url });
|
|
243
289
|
authModuleRaw.log.success(`${green('[custom]')}${magenta('[resetPasswordSend]')} (${yellow(url)})`);
|
|
244
|
-
return
|
|
290
|
+
return {
|
|
291
|
+
message: oSafe.strings.resetPasswordSend,
|
|
292
|
+
user: remult.user,
|
|
293
|
+
};
|
|
245
294
|
}
|
|
246
295
|
else {
|
|
296
|
+
const sendMail = getSendMail();
|
|
247
297
|
await sendMail('resetPasswordSend', {
|
|
248
298
|
to: email,
|
|
249
299
|
subject: 'Reset your password',
|
|
@@ -266,10 +316,13 @@ export class AuthControllerServer {
|
|
|
266
316
|
},
|
|
267
317
|
});
|
|
268
318
|
authModuleRaw.log.success(`${magenta('[resetPasswordSend]')} (${yellow(url)})`);
|
|
269
|
-
return
|
|
319
|
+
return {
|
|
320
|
+
message: `Demo | ${oSafe.strings.resetPasswordSend}`,
|
|
321
|
+
user: remult.user,
|
|
322
|
+
};
|
|
270
323
|
}
|
|
271
324
|
}
|
|
272
|
-
throw new EntityError({ message:
|
|
325
|
+
throw new EntityError({ message: oSafe.strings.anErrorOccurred });
|
|
273
326
|
}
|
|
274
327
|
/**
|
|
275
328
|
* Reset your password with a token
|
|
@@ -279,6 +332,7 @@ export class AuthControllerServer {
|
|
|
279
332
|
if (!oSafe.password.enabled) {
|
|
280
333
|
throw new EntityError({ message: 'Password is not enabled!' });
|
|
281
334
|
}
|
|
335
|
+
oSafe.password.validateInput({ identifier: 'resetPassword', password });
|
|
282
336
|
const account = await remult
|
|
283
337
|
.repo(oSafe.Account)
|
|
284
338
|
.findFirst({ token, provider: FFAuthProvider.PASSWORD.id });
|
|
@@ -288,20 +342,22 @@ export class AuthControllerServer {
|
|
|
288
342
|
if (account.expiresAt && account.expiresAt < new Date()) {
|
|
289
343
|
throw new EntityError({ message: 'token expired' });
|
|
290
344
|
}
|
|
291
|
-
oSafe.password.validatePassword(password);
|
|
292
345
|
if (account.userId === undefined) {
|
|
293
346
|
const user = await repo(oSafe.User).insert({ identifier: account.providerUserId });
|
|
294
347
|
account.userId = user.id;
|
|
295
348
|
}
|
|
296
349
|
await invalidateSession(account.userId);
|
|
297
350
|
// update elements
|
|
298
|
-
account.hashPassword = oSafe.password.
|
|
351
|
+
account.hashPassword = await oSafe.password.hash(password);
|
|
299
352
|
account.token = undefined;
|
|
300
353
|
account.expiresAt = undefined;
|
|
301
354
|
account.lastVerifiedAt = new Date();
|
|
302
355
|
await repo(oSafe.Account).save(account);
|
|
303
356
|
await ff_createSession(account.userId);
|
|
304
|
-
return
|
|
357
|
+
return {
|
|
358
|
+
message: 'reseted',
|
|
359
|
+
user: remult.user,
|
|
360
|
+
};
|
|
305
361
|
}
|
|
306
362
|
/** OTP */
|
|
307
363
|
static async signInOTP(emailParam) {
|
|
@@ -338,12 +394,18 @@ export class AuthControllerServer {
|
|
|
338
394
|
await repo(oSafe.Account).save(account);
|
|
339
395
|
await AUTH_OPTIONS.providers.otp?.send({ name: email, otp, uri });
|
|
340
396
|
authModuleRaw.log.success(`name: ${yellow(email)}, otp: ${yellow(otp)}, uri: ${yellow(uri)}`);
|
|
341
|
-
return
|
|
397
|
+
return {
|
|
398
|
+
message: 'Mail sent !',
|
|
399
|
+
user: remult.user,
|
|
400
|
+
};
|
|
342
401
|
}
|
|
343
402
|
else {
|
|
344
403
|
authModuleRaw.log.error(`You need to provide a otp.send hook in the auth options!`);
|
|
345
404
|
}
|
|
346
|
-
return
|
|
405
|
+
return {
|
|
406
|
+
message: 'Hum, something went wrong !',
|
|
407
|
+
user: remult.user,
|
|
408
|
+
};
|
|
347
409
|
}
|
|
348
410
|
/**
|
|
349
411
|
* Verify the OTP code
|
|
@@ -378,8 +440,11 @@ export class AuthControllerServer {
|
|
|
378
440
|
account.token = undefined;
|
|
379
441
|
account.expiresAt = undefined;
|
|
380
442
|
await repo(oSafe.Account).save(account);
|
|
381
|
-
await ff_createSession(account.userId);
|
|
382
|
-
return
|
|
443
|
+
const session = await ff_createSession(account.userId);
|
|
444
|
+
return {
|
|
445
|
+
message: 'verified',
|
|
446
|
+
user: oSafe.transformDbUserToClientUser(session, user),
|
|
447
|
+
};
|
|
383
448
|
}
|
|
384
449
|
/** OAUTH */
|
|
385
450
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Handle } from '@sveltejs/kit';
|
|
2
|
+
export type RouteGuardConfig = {
|
|
3
|
+
anonymous?: string[];
|
|
4
|
+
authenticated: string[];
|
|
5
|
+
redirectToLogin: string;
|
|
6
|
+
redirectAuthenticated: string;
|
|
7
|
+
/**
|
|
8
|
+
* We need this import
|
|
9
|
+
*
|
|
10
|
+
* `import { redirect } from '@sveltejs/kit'` */
|
|
11
|
+
redirect: (status: number, url: string) => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a handle function with the provided route guard configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleGuard(config: RouteGuardConfig): Handle;
|