firstly 0.0.4 → 0.0.6
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 +21 -0
- package/esm/{KitBaseEnum.d.ts → BaseEnum.d.ts} +18 -9
- package/esm/{KitBaseEnum.js → BaseEnum.js} +2 -13
- package/esm/{KitEntity.d.ts → FF_Entity.d.ts} +1 -1
- package/esm/{KitEntity.js → FF_Entity.js} +9 -9
- package/esm/{KitFields.d.ts → FF_Fields.d.ts} +2 -3
- package/esm/{KitFields.js → FF_Fields.js} +13 -9
- package/esm/ROUTES.d.ts +3 -1
- package/esm/ROUTES.js +2 -1
- package/esm/SqlDatabase/FF_LogToConsole.d.ts +1 -0
- package/esm/SqlDatabase/{LogToConsoleCustom.js → FF_LogToConsole.js} +1 -1
- package/esm/api/index.d.ts +2 -1
- package/esm/auth/AuthController.server.js +59 -18
- package/esm/auth/Entities.d.ts +18 -17
- package/esm/auth/Entities.js +66 -63
- package/esm/auth/RoleHelpers.d.ts +2 -2
- package/esm/auth/RoleHelpers.js +1 -1
- package/esm/auth/client/Auth.js +1 -1
- package/esm/auth/index.d.ts +14 -17
- package/esm/auth/index.js +59 -52
- package/esm/auth/providers/github.d.ts +22 -17
- package/esm/auth/providers/github.js +29 -15
- package/esm/auth/providers/strava.d.ts +22 -17
- package/esm/auth/providers/strava.js +23 -15
- package/esm/auth/static/assets/Page-BGTO8LC5.css +1 -0
- package/esm/auth/static/assets/Page-DBWJjlEQ.d.ts +4 -0
- package/esm/auth/static/assets/Page-DBWJjlEQ.js +1 -0
- package/esm/auth/static/assets/Page-RIbXHuZG.d.ts +4 -0
- package/esm/auth/static/assets/Page-RIbXHuZG.js +1 -0
- package/esm/auth/static/assets/Page-apb_xgZT.d.ts +6 -0
- package/esm/auth/static/assets/Page-apb_xgZT.js +18 -0
- package/esm/auth/static/assets/{index-R27C_TlP.css → index-CR_3yNaJ.css} +1 -1
- package/esm/auth/static/assets/index-qfq98Nyd.d.ts +63 -0
- package/esm/auth/static/assets/index-qfq98Nyd.js +2 -0
- package/esm/auth/static/index.html +2 -2
- package/esm/auth/types.d.ts +16 -22
- package/esm/bin/cmd.js +181 -83
- package/esm/{kitCellsBuildor.d.ts → cellsBuildor.d.ts} +9 -9
- package/esm/{kitCellsBuildor.js → cellsBuildor.js} +9 -9
- package/esm/feedback/ui/DialogIssue.svelte +2 -2
- package/esm/formats/dates.js +2 -2
- package/esm/handle/index.d.ts +1 -0
- package/esm/helper.d.ts +8 -10
- package/esm/helper.js +13 -8
- package/esm/index.d.ts +38 -49
- package/esm/index.js +30 -27
- package/esm/mail/index.d.ts +23 -4
- package/esm/mail/index.js +38 -15
- package/esm/mail/templates/DefaultMail.svelte +66 -0
- package/esm/mail/templates/DefaultMail.svelte.d.ts +28 -0
- package/esm/{kitStoreItem.d.ts → storeItem.d.ts} +1 -1
- package/esm/{kitStoreItem.js → storeItem.js} +1 -1
- package/esm/{kitStoreList.d.ts → storeList.d.ts} +4 -4
- package/esm/{kitStoreList.js → storeList.js} +1 -1
- package/esm/ui/Button.svelte +1 -1
- package/esm/ui/Button.svelte.d.ts +2 -2
- package/esm/ui/Field.svelte.d.ts +2 -2
- package/esm/ui/FieldGroup.svelte +2 -2
- package/esm/ui/FieldGroup.svelte.d.ts +4 -4
- package/esm/ui/Grid.svelte.d.ts +5 -5
- package/esm/ui/dialog/DialogForm.svelte +4 -4
- package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +2 -2
- package/esm/ui/dialog/FormEditAction.svelte.d.ts +2 -2
- package/esm/ui/dialog/dialog.d.ts +5 -5
- package/esm/ui/index.d.ts +2 -2
- package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +3 -3
- package/esm/ui/internals/select/SelectMelt.svelte.d.ts +3 -3
- package/esm/ui/internals/select/SelectRadio.svelte.d.ts +2 -2
- package/esm/ui/link/LinkPlus.svelte.d.ts +2 -2
- package/esm/utils/types.d.ts +3 -15
- package/esm/utils/types.js +1 -17
- package/esm/virtual/Customer.js +2 -2
- package/esm/virtual/FilterEntity.js +1 -1
- package/esm/virtual/StateDemoEnum.d.ts +4 -4
- package/esm/virtual/StateDemoEnum.js +2 -2
- package/esm/virtual/UIEntity.js +4 -4
- package/esm/vite/index.js +1 -1
- package/package.json +5 -3
- package/esm/SqlDatabase/LogToConsoleCustom.d.ts +0 -1
- package/esm/auth/static/assets/Page-BYzkK4q3.d.ts +0 -5
- package/esm/auth/static/assets/Page-BYzkK4q3.js +0 -1
- package/esm/auth/static/assets/Page-ByIhtXVt.d.ts +0 -5
- package/esm/auth/static/assets/Page-ByIhtXVt.js +0 -18
- package/esm/auth/static/assets/Page-Do7F0Mzd.d.ts +0 -5
- package/esm/auth/static/assets/Page-Do7F0Mzd.js +0 -1
- package/esm/auth/static/assets/Page-gV58jf2r.css +0 -1
- package/esm/auth/static/assets/index-czJ1PA1n.d.ts +0 -53
- package/esm/auth/static/assets/index-czJ1PA1n.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# firstly
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#23](https://github.com/jycouet/firstly/pull/23)
|
|
8
|
+
[`c188eb3`](https://github.com/jycouet/firstly/commit/c188eb3d81a9e75b246387512621b5213bbe8dbd)
|
|
9
|
+
Thanks [@jycouet](https://github.com/jycouet)! - fix auth & mail (logs & co)
|
|
10
|
+
|
|
11
|
+
## 0.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#20](https://github.com/jycouet/firstly/pull/20)
|
|
16
|
+
[`5b365a4`](https://github.com/jycouet/firstly/commit/5b365a474619f611b0eb0bfe38bbbb262acb3a7e)
|
|
17
|
+
Thanks [@jycouet](https://github.com/jycouet)! - [BREAKING] Renaming almost all exports! (Some
|
|
18
|
+
`FF_` and `ff_` only when direct collision with other packages)
|
|
19
|
+
|
|
20
|
+
- [#20](https://github.com/jycouet/firstly/pull/20)
|
|
21
|
+
[`b1ea110`](https://github.com/jycouet/firstly/commit/b1ea1101c45c137e477a937a8c6d130b346b2bb9)
|
|
22
|
+
Thanks [@jycouet](https://github.com/jycouet)! - tweak cli, update github auth
|
|
23
|
+
|
|
3
24
|
## 0.0.4
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { type IdFilter } from 'remult';
|
|
2
|
-
import type {
|
|
3
|
-
export type
|
|
2
|
+
import type { FindOptionsBase, Repository } from 'remult';
|
|
3
|
+
export type FF_Icon = {
|
|
4
4
|
data?: string | string[];
|
|
5
5
|
size?: string | number;
|
|
6
6
|
class?: string | string[];
|
|
7
7
|
style?: string | string[];
|
|
8
8
|
caption?: string;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
10
|
+
export type BaseItem = BaseEnumOptions & {
|
|
11
|
+
id: string;
|
|
12
|
+
captionSub?: string | (string | undefined)[];
|
|
13
|
+
href?: string;
|
|
14
|
+
repo?: Repository<any>;
|
|
15
|
+
sub?: {
|
|
16
|
+
captionPre?: string;
|
|
17
|
+
repo?: Repository<any>;
|
|
18
|
+
item?: any;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type BaseEnumOptions<Entity = any> = {
|
|
11
22
|
caption?: string;
|
|
12
|
-
icon?:
|
|
23
|
+
icon?: FF_Icon;
|
|
13
24
|
where?: IdFilter<Entity> | FindOptionsBase<Entity>['where'];
|
|
14
25
|
class?: string;
|
|
15
26
|
};
|
|
16
|
-
export declare class
|
|
27
|
+
export declare class BaseEnum<Entity = any> {
|
|
17
28
|
id: string;
|
|
18
29
|
caption?: string;
|
|
19
|
-
icon?:
|
|
30
|
+
icon?: FF_Icon;
|
|
20
31
|
where?: IdFilter<Entity> | FindOptionsBase<Entity>['where'];
|
|
21
32
|
class?: string;
|
|
22
|
-
constructor(_id: string | number, options?:
|
|
33
|
+
constructor(_id: string | number, options?: BaseEnumOptions<Entity>);
|
|
23
34
|
getWhere: () => this | Entity[] | {
|
|
24
35
|
$ne?: Entity | Entity[] | undefined;
|
|
25
36
|
'!='?: Entity | Entity[] | undefined;
|
|
@@ -31,5 +42,3 @@ export declare class KitBaseEnum<Entity = any> {
|
|
|
31
42
|
} ? number : string>;
|
|
32
43
|
} | import("remult").EntityFilter<Entity> | NonNullable<Entity>;
|
|
33
44
|
}
|
|
34
|
-
export declare const getEnum: <T extends KitBaseEnum<any>>(baseEnum: ClassType<T>, id: string | undefined | null) => T | undefined;
|
|
35
|
-
export declare const getEnums: <T extends KitBaseEnum<any>>(baseEnum: ClassType<T>) => T[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class
|
|
1
|
+
import {} from 'remult';
|
|
2
|
+
export class BaseEnum {
|
|
3
3
|
id;
|
|
4
4
|
caption;
|
|
5
5
|
icon;
|
|
@@ -19,14 +19,3 @@ export class KitBaseEnum {
|
|
|
19
19
|
return this.where ? this.where : this;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
export const getEnum = (baseEnum, id) => {
|
|
23
|
-
if (!id) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
const found = getValueList(baseEnum).find((c) => c.id === id);
|
|
28
|
-
return found;
|
|
29
|
-
};
|
|
30
|
-
export const getEnums = (baseEnum) => {
|
|
31
|
-
return getValueList(baseEnum) || [];
|
|
32
|
-
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type EntityOptions } from 'remult';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function FF_Entity<entityType>(key: string, options: EntityOptions<entityType extends new (...args: any) => any ? InstanceType<entityType> : entityType>): (target: any, info?: import("remult/src/remult3/remult3").ClassDecoratorContextStub<entityType extends infer T ? T extends entityType ? T extends new (...args: any) => any ? T : never : never : never> | undefined) => any;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Entity } from 'remult';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (permission) {
|
|
5
|
-
|
|
6
|
-
return permission.map((p) => p.id);
|
|
7
|
-
}
|
|
8
|
-
return permission.id;
|
|
2
|
+
const toAllow = (permission) => {
|
|
3
|
+
if (permission) {
|
|
4
|
+
if (Array.isArray(permission)) {
|
|
5
|
+
return permission.map((p) => p.id);
|
|
9
6
|
}
|
|
10
|
-
return
|
|
11
|
-
}
|
|
7
|
+
return permission.id;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
|
11
|
+
export function FF_Entity(key, options) {
|
|
12
12
|
return Entity(key, {
|
|
13
13
|
...options,
|
|
14
14
|
allowApiCrud: options.allowApiCrud ?? toAllow(options.permissionApiCrud),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type FieldOptions, type
|
|
2
|
-
export declare
|
|
3
|
-
export declare class KitFields {
|
|
1
|
+
import { type FieldOptions, type StringFieldOptions } from 'remult';
|
|
2
|
+
export declare class FF_Fields {
|
|
4
3
|
static string<entityType = unknown, valueType = string>(o?: StringFieldOptions<entityType, valueType>): import("remult").ClassFieldDecorator<entityType, valueType | undefined>;
|
|
5
4
|
static currency<entityType = unknown>(o?: FieldOptions<entityType, number>): import("remult").ClassFieldDecorator<entityType, number | undefined>;
|
|
6
5
|
static dateOnly<entityType = any>(o?: FieldOptions<entityType, Date>): import("remult").ClassFieldDecorator<entityType, Date | undefined>;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Fields, Validators, } from 'remult';
|
|
2
2
|
import { displayCurrency } from './formats';
|
|
3
|
-
import { getEnums } from './
|
|
3
|
+
import { getEnums } from './helper';
|
|
4
4
|
// Translate default messages
|
|
5
5
|
// REMULT P3 JYC: I need to set this here the one of my app are not overwriting these...
|
|
6
6
|
// It look like I have 2 remult loaded... But even trying to remove one, I still have the issue
|
|
7
7
|
Validators.unique.defaultMessage = 'Existe déjà!';
|
|
8
8
|
Validators.required.defaultMessage = 'Obligatoire!';
|
|
9
|
-
export function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
// export function addValidators(
|
|
10
|
+
// validators: FieldOptions['validate'],
|
|
11
|
+
// newValidator: FieldOptions['validate'],
|
|
12
|
+
// atStart = false,
|
|
13
|
+
// ) {
|
|
14
|
+
// if (!newValidator) return validators
|
|
15
|
+
// const newValidators = Array.isArray(newValidator) ? newValidator : [newValidator]
|
|
16
|
+
// const validatorsArray = Array.isArray(validators) ? validators : validators ? [validators] : []
|
|
17
|
+
// return atStart ? [...newValidators, ...validatorsArray] : [...validatorsArray, ...newValidators]
|
|
18
|
+
// }
|
|
16
19
|
// REMULT P2: A/ Add in the doc that allowNull is false by default
|
|
17
20
|
// B/ Would be great to have a Validators.required automatically when allowNull is not true.
|
|
18
21
|
// C/ WARNING Validators.required is also checking for empty string
|
|
@@ -24,6 +27,7 @@ const validate_update_when_not_allow_null = (o) => {
|
|
|
24
27
|
(o.allowNull === undefined || o.allowNull === false) &&
|
|
25
28
|
// if require: false is explicitly set, then we don't need to add required validator
|
|
26
29
|
o.required !== false) {
|
|
30
|
+
// addValidators(o.validate, [Validators.required], true)
|
|
27
31
|
validate.push(Validators.required);
|
|
28
32
|
}
|
|
29
33
|
// let's add original validate if any
|
|
@@ -37,7 +41,7 @@ const validate_update_when_not_allow_null = (o) => {
|
|
|
37
41
|
}
|
|
38
42
|
return validate;
|
|
39
43
|
};
|
|
40
|
-
export class
|
|
44
|
+
export class FF_Fields {
|
|
41
45
|
static string(o) {
|
|
42
46
|
if (o === undefined) {
|
|
43
47
|
o = {};
|
package/esm/ROUTES.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare const AllObjs: {
|
|
|
32
32
|
repo?: (string | number);
|
|
33
33
|
}) => string;
|
|
34
34
|
"/": string;
|
|
35
|
+
"/mail": string;
|
|
35
36
|
"/remult": string;
|
|
36
37
|
"/remult/auth": string;
|
|
37
38
|
"/remult/enum": string;
|
|
@@ -40,7 +41,7 @@ declare const AllObjs: {
|
|
|
40
41
|
};
|
|
41
42
|
type AllTypes = typeof AllObjs;
|
|
42
43
|
export type Routes = keyof AllTypes extends `${string}/${infer Route}` ? `/${Route}` : keyof AllTypes;
|
|
43
|
-
export declare const routes: ("/" | "/remult" | "/remult/auth" | "/remult/enum" | "/remult/select" | "/ui" | "firstly_sign_in" | "remult_admin" | "github")[];
|
|
44
|
+
export declare const routes: ("/" | "/mail" | "/remult" | "/remult/auth" | "/remult/enum" | "/remult/select" | "/ui" | "firstly_sign_in" | "remult_admin" | "github")[];
|
|
44
45
|
/**
|
|
45
46
|
* To be used like this:
|
|
46
47
|
* ```ts
|
|
@@ -69,6 +70,7 @@ export declare function route<T extends NonFunctionKeys<AllTypes>>(key: T): stri
|
|
|
69
70
|
export type KIT_ROUTES = {
|
|
70
71
|
PAGES: {
|
|
71
72
|
'/': never;
|
|
73
|
+
'/mail': never;
|
|
72
74
|
'/remult': never;
|
|
73
75
|
'/remult/auth': never;
|
|
74
76
|
'/remult/enum': never;
|
package/esm/ROUTES.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
const PAGES = {
|
|
11
11
|
"/": `/`,
|
|
12
|
+
"/mail": `/mail`,
|
|
12
13
|
"/remult": `/remult`,
|
|
13
14
|
"/remult/auth": `/remult/auth`,
|
|
14
15
|
"/remult/enum": `/remult/enum`,
|
|
@@ -27,7 +28,7 @@ const ACTIONS = {};
|
|
|
27
28
|
* LINKS
|
|
28
29
|
*/
|
|
29
30
|
const LINKS = {
|
|
30
|
-
"firstly_sign_in": `/
|
|
31
|
+
"firstly_sign_in": `/ff/auth/sign-in`,
|
|
31
32
|
"remult_admin": `/api/admin`,
|
|
32
33
|
"github": (params) => {
|
|
33
34
|
params = params ?? {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FF_LogToConsole: (duration: number, query: string, args: Record<string, any>, short?: boolean) => string | undefined;
|
|
@@ -16,7 +16,7 @@ const typeQuery = new Map([
|
|
|
16
16
|
]);
|
|
17
17
|
const keys = ['FROM', 'WHERE', 'LIMIT', 'OFFSET'];
|
|
18
18
|
const typeQueryKey = Array.from(typeQuery.keys());
|
|
19
|
-
export const
|
|
19
|
+
export const FF_LogToConsole = (duration, query, args, short = true) => {
|
|
20
20
|
const rawSql = query
|
|
21
21
|
.replace(/(\r\n|\n|\r|\t)/gm, ' ')
|
|
22
22
|
.replace(/ +/g, ' ')
|
package/esm/api/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types=".pnpm/@sveltejs+kit@2.5.24_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.18_vite@5.4.1_@types+node@_vtylvkjv5lewhfcl4vq2py4rce/node_modules/@sveltejs/kit" />
|
|
1
2
|
import { type Handle, type MaybePromise, type RequestEvent } from '@sveltejs/kit';
|
|
2
3
|
import { type ClassType } from 'remult';
|
|
3
4
|
import type { RemultServerOptions } from 'remult/server';
|
|
@@ -25,7 +26,7 @@ export type Module = {
|
|
|
25
26
|
};
|
|
26
27
|
type Options = Omit<RemultServerOptions<RequestEvent<Partial<Record<string, string>>, string | null>> & {
|
|
27
28
|
modules?: Module[] | undefined;
|
|
28
|
-
mail?: MailOptions
|
|
29
|
+
mail?: MailOptions<any>;
|
|
29
30
|
}, 'entities' | 'controllers' | 'initRequest' | 'initApi'>;
|
|
30
31
|
/**
|
|
31
32
|
* it's basically `remultSveltekit` with the `modules` option
|
|
@@ -6,7 +6,7 @@ import { remult } from 'remult';
|
|
|
6
6
|
import { green, yellow } from '@kitql/helpers';
|
|
7
7
|
import { AUTH_OPTIONS, getSafeOptions, logAuth, lucia } from '.';
|
|
8
8
|
import { sendMail } from '../mail';
|
|
9
|
-
import {
|
|
9
|
+
import { FFAuthProvider } from './Entities.js';
|
|
10
10
|
import { createSession } from './helper';
|
|
11
11
|
import { mergeRoles } from './RoleHelpers';
|
|
12
12
|
async function getArgon() {
|
|
@@ -93,8 +93,23 @@ export class AuthControllerServer {
|
|
|
93
93
|
await sendMail('invite', {
|
|
94
94
|
to: email,
|
|
95
95
|
subject: 'Invitation',
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
templateProps: {
|
|
97
|
+
title: 'Invitation 👋',
|
|
98
|
+
previewText: 'This is the mail you were waiting for',
|
|
99
|
+
sections: [
|
|
100
|
+
{
|
|
101
|
+
text: 'Today is your lucky day !',
|
|
102
|
+
highlighted: true,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
text: 'You were invited to join the team',
|
|
106
|
+
cta: {
|
|
107
|
+
text: 'JOIN',
|
|
108
|
+
link: url,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
98
113
|
});
|
|
99
114
|
logAuth.success(`Done with ${green('sendMail')} (${url})`);
|
|
100
115
|
return 'Demo Mail sent !';
|
|
@@ -124,7 +139,7 @@ export class AuthControllerServer {
|
|
|
124
139
|
});
|
|
125
140
|
const token = generateId(40);
|
|
126
141
|
await remult.repo(oSafe.Account).insert({
|
|
127
|
-
provider:
|
|
142
|
+
provider: FFAuthProvider.PASSWORD.id,
|
|
128
143
|
providerUserId: email,
|
|
129
144
|
userId: user.id,
|
|
130
145
|
hashPassword: await passwordHash(password),
|
|
@@ -138,7 +153,7 @@ export class AuthControllerServer {
|
|
|
138
153
|
await createSession(user.id);
|
|
139
154
|
}
|
|
140
155
|
else {
|
|
141
|
-
const url = `${remult.context.url.origin}${oSafe.firstlyData.props.ui
|
|
156
|
+
const url = `${remult.context.url.origin}${oSafe.firstlyData.props.ui?.paths.verify_email}?token=${token}`;
|
|
142
157
|
if (AUTH_OPTIONS.providers?.password?.verifyMailSend) {
|
|
143
158
|
await AUTH_OPTIONS.providers?.password.verifyMailSend({ email, url });
|
|
144
159
|
logAuth.success(`Done with custom ${green('verifyMailSend')} (${yellow(url)})`);
|
|
@@ -146,9 +161,20 @@ export class AuthControllerServer {
|
|
|
146
161
|
else {
|
|
147
162
|
await sendMail('signUpPassword', {
|
|
148
163
|
to: email,
|
|
149
|
-
subject: 'Wecome
|
|
150
|
-
|
|
151
|
-
|
|
164
|
+
subject: 'Wecome',
|
|
165
|
+
templateProps: {
|
|
166
|
+
title: 'Wecome 👋',
|
|
167
|
+
previewText: 'This is the mail you were waiting for',
|
|
168
|
+
sections: [
|
|
169
|
+
{
|
|
170
|
+
text: 'You can validate your account',
|
|
171
|
+
cta: {
|
|
172
|
+
text: 'HERE',
|
|
173
|
+
link: url,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
152
178
|
});
|
|
153
179
|
logAuth.success(`Done with ${green('sendMail')} (${url})`);
|
|
154
180
|
}
|
|
@@ -167,7 +193,7 @@ export class AuthControllerServer {
|
|
|
167
193
|
const existingUser = await remult
|
|
168
194
|
.repo(oSafe.User)
|
|
169
195
|
.findOne({ where: { name: email }, include: { accounts: true } });
|
|
170
|
-
const accountPassword = existingUser?.accounts.find((c) => c.provider ===
|
|
196
|
+
const accountPassword = existingUser?.accounts.find((c) => c.provider === FFAuthProvider.PASSWORD.id);
|
|
171
197
|
if (accountPassword && existingUser) {
|
|
172
198
|
const validPassword = await passwordVerify(accountPassword?.hashPassword ?? '', password ?? '');
|
|
173
199
|
if (validPassword) {
|
|
@@ -194,14 +220,14 @@ export class AuthControllerServer {
|
|
|
194
220
|
if (!authAccount) {
|
|
195
221
|
authAccount = remult.repo(oSafe.Account).create();
|
|
196
222
|
authAccount.userId = u.id;
|
|
197
|
-
authAccount.provider =
|
|
223
|
+
authAccount.provider = FFAuthProvider.PASSWORD.id;
|
|
198
224
|
authAccount.providerUserId = email;
|
|
199
225
|
}
|
|
200
226
|
const token = generateId(40);
|
|
201
227
|
authAccount.token = token;
|
|
202
228
|
authAccount.expiresAt = createDate(new TimeSpan(AUTH_OPTIONS.providers?.password?.resetPasswordExpiresIn ?? 5 * 60, 's'));
|
|
203
229
|
await remult.repo(oSafe.Account).save(authAccount);
|
|
204
|
-
const url = `${remult.context.url.origin}${oSafe.firstlyData.props.ui
|
|
230
|
+
const url = `${remult.context.url.origin}${oSafe.firstlyData.props.ui?.paths.reset_password}?token=${token}`;
|
|
205
231
|
if (AUTH_OPTIONS.providers?.password?.resetPasswordSend) {
|
|
206
232
|
await AUTH_OPTIONS.providers?.password.resetPasswordSend({ email, url });
|
|
207
233
|
logAuth.success(`Done with custom ${green('resetPasswordSend')} (${yellow(url)})`);
|
|
@@ -211,8 +237,23 @@ export class AuthControllerServer {
|
|
|
211
237
|
await sendMail('forgotPassword', {
|
|
212
238
|
to: email,
|
|
213
239
|
subject: 'Reset your password',
|
|
214
|
-
|
|
215
|
-
|
|
240
|
+
templateProps: {
|
|
241
|
+
title: 'Reset your password 👋',
|
|
242
|
+
previewText: 'This is the mail you were waiting for',
|
|
243
|
+
sections: [
|
|
244
|
+
{
|
|
245
|
+
text: 'Did you forgot something ?',
|
|
246
|
+
highlighted: true,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
text: 'No worries, you can reset your password',
|
|
250
|
+
cta: {
|
|
251
|
+
text: 'HERE',
|
|
252
|
+
link: url,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
},
|
|
216
257
|
});
|
|
217
258
|
logAuth.success(`Done with ${green('sendMail')} (${url})`);
|
|
218
259
|
return 'Demo Mail sent !';
|
|
@@ -230,7 +271,7 @@ export class AuthControllerServer {
|
|
|
230
271
|
}
|
|
231
272
|
const account = await remult
|
|
232
273
|
.repo(oSafe.Account)
|
|
233
|
-
.findFirst({ token, provider:
|
|
274
|
+
.findFirst({ token, provider: FFAuthProvider.PASSWORD.id });
|
|
234
275
|
if (!account) {
|
|
235
276
|
throw new Error('Invalid token');
|
|
236
277
|
}
|
|
@@ -275,12 +316,12 @@ export class AuthControllerServer {
|
|
|
275
316
|
user = await remult.repo(oSafe.User).save(user);
|
|
276
317
|
let account = await remult
|
|
277
318
|
.repo(oSafe.Account)
|
|
278
|
-
.findFirst({ userId: user.id, provider:
|
|
319
|
+
.findFirst({ userId: user.id, provider: FFAuthProvider.OTP.id });
|
|
279
320
|
if (!account) {
|
|
280
321
|
account = remult.repo(oSafe.Account).create();
|
|
281
322
|
}
|
|
282
323
|
account.userId = user.id;
|
|
283
|
-
account.provider =
|
|
324
|
+
account.provider = FFAuthProvider.OTP.id;
|
|
284
325
|
account.token = otp;
|
|
285
326
|
account.hashPassword = secretEncoded;
|
|
286
327
|
await remult.repo(oSafe.Account).save(account);
|
|
@@ -299,7 +340,7 @@ export class AuthControllerServer {
|
|
|
299
340
|
static async verifyOtp(email, otp) {
|
|
300
341
|
const oSafe = getSafeOptions();
|
|
301
342
|
const accounts = await remult.repo(oSafe.Account).find({
|
|
302
|
-
where: { token: String(otp), provider:
|
|
343
|
+
where: { token: String(otp), provider: FFAuthProvider.OTP.id },
|
|
303
344
|
});
|
|
304
345
|
if (accounts.length === 0) {
|
|
305
346
|
throw new Error('Invalid otp');
|
|
@@ -393,6 +434,6 @@ export class AuthControllerServer {
|
|
|
393
434
|
throw new Error(`${o.provider} not well configured!`);
|
|
394
435
|
}
|
|
395
436
|
}
|
|
396
|
-
throw new Error(`${o.provider} is not configured
|
|
437
|
+
throw new Error(`${o.provider} is not configured! (Module: auth, section: providers.oAuths: [${o.provider}] missing)`);
|
|
397
438
|
}
|
|
398
439
|
}
|
package/esm/auth/Entities.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
export declare const
|
|
4
|
-
readonly Admin: "
|
|
1
|
+
import { BaseEnum } from '../';
|
|
2
|
+
import type { BaseEnumOptions } from '../';
|
|
3
|
+
export declare const FF_Auth_Role: {
|
|
4
|
+
readonly Admin: "FF_Auth_Role.Admin";
|
|
5
5
|
};
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class FFAuthUser {
|
|
7
7
|
id: string;
|
|
8
8
|
createdAt: Date;
|
|
9
9
|
updatedAt?: Date;
|
|
10
10
|
name: string;
|
|
11
11
|
roles: string[];
|
|
12
|
-
accounts:
|
|
13
|
-
sessions:
|
|
12
|
+
accounts: FFAuthAccount[];
|
|
13
|
+
sessions: FFAuthUserSession[];
|
|
14
14
|
}
|
|
15
|
-
export declare class
|
|
15
|
+
export declare class FFAuthAccount {
|
|
16
|
+
id: string;
|
|
16
17
|
createdAt: Date;
|
|
17
18
|
updatedAt?: Date;
|
|
18
19
|
userId: string;
|
|
19
|
-
user:
|
|
20
|
+
user: FFAuthUser;
|
|
20
21
|
provider: string;
|
|
21
22
|
providerUserId: string;
|
|
22
23
|
hashPassword?: string;
|
|
@@ -24,16 +25,16 @@ export declare class KitAuthAccount {
|
|
|
24
25
|
expiresAt?: Date;
|
|
25
26
|
lastVerifiedAt?: Date;
|
|
26
27
|
}
|
|
27
|
-
export declare class
|
|
28
|
+
export declare class FFAuthUserSession {
|
|
28
29
|
id: string;
|
|
29
30
|
expiresAt: Date;
|
|
30
31
|
userId: string;
|
|
31
|
-
user:
|
|
32
|
+
user: FFAuthUser;
|
|
32
33
|
}
|
|
33
|
-
export declare class
|
|
34
|
-
static DEMO:
|
|
35
|
-
static PASSWORD:
|
|
36
|
-
static OTP:
|
|
37
|
-
static OAUTH:
|
|
38
|
-
constructor(id: string, o?:
|
|
34
|
+
export declare class FFAuthProvider extends BaseEnum {
|
|
35
|
+
static DEMO: FFAuthProvider;
|
|
36
|
+
static PASSWORD: FFAuthProvider;
|
|
37
|
+
static OTP: FFAuthProvider;
|
|
38
|
+
static OAUTH: FFAuthProvider;
|
|
39
|
+
constructor(id: string, o?: BaseEnumOptions);
|
|
39
40
|
}
|