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/esm/auth/Entities.js
CHANGED
|
@@ -4,17 +4,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var FFAuthProvider_1;
|
|
8
8
|
import { Entity, Fields, Relations, Validators, ValueListFieldType } from 'remult';
|
|
9
|
-
import {
|
|
10
|
-
export const
|
|
11
|
-
Admin: '
|
|
9
|
+
import { BaseEnum, FF_Role } from '../';
|
|
10
|
+
export const FF_Auth_Role = {
|
|
11
|
+
Admin: 'FF_Auth_Role.Admin',
|
|
12
12
|
};
|
|
13
|
-
let
|
|
13
|
+
let FFAuthUser = class FFAuthUser {
|
|
14
14
|
id;
|
|
15
15
|
createdAt;
|
|
16
16
|
updatedAt;
|
|
17
|
-
// @Fields.string<KitAuthUser>({
|
|
18
17
|
name;
|
|
19
18
|
roles = [];
|
|
20
19
|
accounts;
|
|
@@ -22,13 +21,13 @@ let KitAuthUser = class KitAuthUser {
|
|
|
22
21
|
};
|
|
23
22
|
__decorate([
|
|
24
23
|
Fields.cuid()
|
|
25
|
-
],
|
|
24
|
+
], FFAuthUser.prototype, "id", void 0);
|
|
26
25
|
__decorate([
|
|
27
26
|
Fields.createdAt()
|
|
28
|
-
],
|
|
27
|
+
], FFAuthUser.prototype, "createdAt", void 0);
|
|
29
28
|
__decorate([
|
|
30
29
|
Fields.updatedAt()
|
|
31
|
-
],
|
|
30
|
+
], FFAuthUser.prototype, "updatedAt", void 0);
|
|
32
31
|
__decorate([
|
|
33
32
|
Fields.string({
|
|
34
33
|
validate: [
|
|
@@ -39,7 +38,7 @@ __decorate([
|
|
|
39
38
|
},
|
|
40
39
|
],
|
|
41
40
|
})
|
|
42
|
-
],
|
|
41
|
+
], FFAuthUser.prototype, "name", void 0);
|
|
43
42
|
__decorate([
|
|
44
43
|
Fields.object({
|
|
45
44
|
valueConverter: {
|
|
@@ -47,71 +46,75 @@ __decorate([
|
|
|
47
46
|
fromDb: (x) => (x ? x.split(',') : undefined),
|
|
48
47
|
},
|
|
49
48
|
})
|
|
50
|
-
],
|
|
49
|
+
], FFAuthUser.prototype, "roles", void 0);
|
|
51
50
|
__decorate([
|
|
52
|
-
Relations.toMany(() =>
|
|
53
|
-
],
|
|
51
|
+
Relations.toMany(() => FFAuthAccount, 'userId')
|
|
52
|
+
], FFAuthUser.prototype, "accounts", void 0);
|
|
54
53
|
__decorate([
|
|
55
|
-
Relations.toMany(() =>
|
|
56
|
-
],
|
|
57
|
-
|
|
58
|
-
Entity('
|
|
59
|
-
allowApiCrud: [
|
|
60
|
-
|
|
54
|
+
Relations.toMany(() => FFAuthUserSession, 'userId')
|
|
55
|
+
], FFAuthUser.prototype, "sessions", void 0);
|
|
56
|
+
FFAuthUser = __decorate([
|
|
57
|
+
Entity('ff_auth.users', {
|
|
58
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
59
|
+
caption: 'Auth - Users',
|
|
61
60
|
})
|
|
62
|
-
],
|
|
63
|
-
export {
|
|
64
|
-
let
|
|
61
|
+
], FFAuthUser);
|
|
62
|
+
export { FFAuthUser };
|
|
63
|
+
let FFAuthAccount = class FFAuthAccount {
|
|
64
|
+
id;
|
|
65
65
|
createdAt;
|
|
66
66
|
updatedAt;
|
|
67
67
|
userId;
|
|
68
68
|
user;
|
|
69
|
-
provider =
|
|
69
|
+
provider = FFAuthProvider.PASSWORD.id;
|
|
70
70
|
providerUserId = '';
|
|
71
71
|
hashPassword;
|
|
72
72
|
token;
|
|
73
73
|
expiresAt;
|
|
74
74
|
lastVerifiedAt;
|
|
75
75
|
};
|
|
76
|
+
__decorate([
|
|
77
|
+
Fields.cuid()
|
|
78
|
+
], FFAuthAccount.prototype, "id", void 0);
|
|
76
79
|
__decorate([
|
|
77
80
|
Fields.createdAt()
|
|
78
|
-
],
|
|
81
|
+
], FFAuthAccount.prototype, "createdAt", void 0);
|
|
79
82
|
__decorate([
|
|
80
83
|
Fields.updatedAt()
|
|
81
|
-
],
|
|
84
|
+
], FFAuthAccount.prototype, "updatedAt", void 0);
|
|
82
85
|
__decorate([
|
|
83
86
|
Fields.string()
|
|
84
|
-
],
|
|
87
|
+
], FFAuthAccount.prototype, "userId", void 0);
|
|
85
88
|
__decorate([
|
|
86
|
-
Relations.toOne(() =>
|
|
87
|
-
],
|
|
89
|
+
Relations.toOne(() => FFAuthUser, 'userId')
|
|
90
|
+
], FFAuthAccount.prototype, "user", void 0);
|
|
88
91
|
__decorate([
|
|
89
92
|
Fields.string()
|
|
90
|
-
],
|
|
93
|
+
], FFAuthAccount.prototype, "provider", void 0);
|
|
91
94
|
__decorate([
|
|
92
95
|
Fields.string()
|
|
93
|
-
],
|
|
96
|
+
], FFAuthAccount.prototype, "providerUserId", void 0);
|
|
94
97
|
__decorate([
|
|
95
98
|
Fields.string({ includeInApi: false, allowNull: true })
|
|
96
|
-
],
|
|
99
|
+
], FFAuthAccount.prototype, "hashPassword", void 0);
|
|
97
100
|
__decorate([
|
|
98
101
|
Fields.string({ includeInApi: false, allowNull: true })
|
|
99
|
-
],
|
|
102
|
+
], FFAuthAccount.prototype, "token", void 0);
|
|
100
103
|
__decorate([
|
|
101
104
|
Fields.date({ includeInApi: false, allowNull: true })
|
|
102
|
-
],
|
|
105
|
+
], FFAuthAccount.prototype, "expiresAt", void 0);
|
|
103
106
|
__decorate([
|
|
104
107
|
Fields.date({ includeInApi: false, allowNull: true })
|
|
105
|
-
],
|
|
106
|
-
|
|
107
|
-
Entity('
|
|
108
|
-
allowApiCrud: [
|
|
109
|
-
|
|
110
|
-
id: { provider: true, userId: true },
|
|
108
|
+
], FFAuthAccount.prototype, "lastVerifiedAt", void 0);
|
|
109
|
+
FFAuthAccount = __decorate([
|
|
110
|
+
Entity('ff_auth.accounts', {
|
|
111
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
112
|
+
caption: 'Auth - Accounts',
|
|
113
|
+
// id: { provider: true, userId: true },
|
|
111
114
|
})
|
|
112
|
-
],
|
|
113
|
-
export {
|
|
114
|
-
let
|
|
115
|
+
], FFAuthAccount);
|
|
116
|
+
export { FFAuthAccount };
|
|
117
|
+
let FFAuthUserSession = class FFAuthUserSession {
|
|
115
118
|
id;
|
|
116
119
|
expiresAt;
|
|
117
120
|
userId;
|
|
@@ -119,36 +122,36 @@ let KitAuthUserSession = class KitAuthUserSession {
|
|
|
119
122
|
};
|
|
120
123
|
__decorate([
|
|
121
124
|
Fields.cuid()
|
|
122
|
-
],
|
|
125
|
+
], FFAuthUserSession.prototype, "id", void 0);
|
|
123
126
|
__decorate([
|
|
124
127
|
Fields.date()
|
|
125
|
-
],
|
|
128
|
+
], FFAuthUserSession.prototype, "expiresAt", void 0);
|
|
126
129
|
__decorate([
|
|
127
130
|
Fields.string()
|
|
128
|
-
],
|
|
129
|
-
__decorate([
|
|
130
|
-
Relations.toOne(() =>
|
|
131
|
-
],
|
|
132
|
-
|
|
133
|
-
Entity('
|
|
134
|
-
allowApiCrud: [
|
|
135
|
-
|
|
131
|
+
], FFAuthUserSession.prototype, "userId", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
Relations.toOne(() => FFAuthUser, 'userId')
|
|
134
|
+
], FFAuthUserSession.prototype, "user", void 0);
|
|
135
|
+
FFAuthUserSession = __decorate([
|
|
136
|
+
Entity('ff_auth.users_sessions', {
|
|
137
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
138
|
+
caption: 'Auth - Users sessions',
|
|
136
139
|
})
|
|
137
|
-
],
|
|
138
|
-
export {
|
|
139
|
-
let
|
|
140
|
-
static {
|
|
141
|
-
static DEMO = new
|
|
142
|
-
static PASSWORD = new
|
|
143
|
-
static OTP = new
|
|
144
|
-
static OAUTH = new
|
|
140
|
+
], FFAuthUserSession);
|
|
141
|
+
export { FFAuthUserSession };
|
|
142
|
+
let FFAuthProvider = class FFAuthProvider extends BaseEnum {
|
|
143
|
+
static { FFAuthProvider_1 = this; }
|
|
144
|
+
static DEMO = new FFAuthProvider_1('DEMO', { caption: 'Demo' });
|
|
145
|
+
static PASSWORD = new FFAuthProvider_1('PASSWORD', { caption: 'Password' });
|
|
146
|
+
static OTP = new FFAuthProvider_1('OTP', { caption: 'TOTP' });
|
|
147
|
+
static OAUTH = new FFAuthProvider_1('OAUTH', { caption: 'OAUTH' });
|
|
145
148
|
constructor(id, o) {
|
|
146
149
|
super(id, {
|
|
147
150
|
...o,
|
|
148
151
|
});
|
|
149
152
|
}
|
|
150
153
|
};
|
|
151
|
-
|
|
154
|
+
FFAuthProvider = FFAuthProvider_1 = __decorate([
|
|
152
155
|
ValueListFieldType()
|
|
153
|
-
],
|
|
154
|
-
export {
|
|
156
|
+
], FFAuthProvider);
|
|
157
|
+
export { FFAuthProvider };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClassType } from 'remult';
|
|
2
2
|
import { Log } from '@kitql/helpers';
|
|
3
|
-
import {
|
|
3
|
+
import { FFAuthUser } from './Entities';
|
|
4
4
|
/**
|
|
5
5
|
* will merge the roles and remove duplicates
|
|
6
6
|
* will return a new array & a status if the array was changed
|
|
@@ -9,4 +9,4 @@ export declare const mergeRoles: (existing: string[], newOnes: string[] | undefi
|
|
|
9
9
|
roles: string[];
|
|
10
10
|
changed: boolean;
|
|
11
11
|
};
|
|
12
|
-
export declare const initRoleFromEnv: (log: Log, userEntity: ClassType<
|
|
12
|
+
export declare const initRoleFromEnv: (log: Log, userEntity: ClassType<FFAuthUser>, envValue: string | undefined, role: string) => Promise<void>;
|
package/esm/auth/RoleHelpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { repo } from 'remult';
|
|
2
2
|
import { cyan, green, Log, yellow } from '@kitql/helpers';
|
|
3
|
-
import {
|
|
3
|
+
import { FFAuthUser } from './Entities';
|
|
4
4
|
/**
|
|
5
5
|
* will merge the roles and remove duplicates
|
|
6
6
|
* will return a new array & a status if the array was changed
|
package/esm/auth/client/Auth.js
CHANGED
|
@@ -86,7 +86,7 @@ export class Auth {
|
|
|
86
86
|
* _(popup example should work too, and a nice example/componant would be appreciated)_
|
|
87
87
|
*/
|
|
88
88
|
static async signInOAuthGetUrl(o) {
|
|
89
|
-
return await Auth.signInOAuthGetUrlFn(o
|
|
89
|
+
return await Auth.signInOAuthGetUrlFn(o);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
__decorate([
|
package/esm/auth/index.d.ts
CHANGED
|
@@ -3,43 +3,40 @@ import { Lucia, type SessionCookieOptions } from 'lucia';
|
|
|
3
3
|
import type { ClassType, UserInfo } from 'remult';
|
|
4
4
|
import { Log } from '@kitql/helpers';
|
|
5
5
|
import type { Module } from '../api';
|
|
6
|
-
import type { ResolvedType } from '../utils/types';
|
|
7
|
-
import {
|
|
8
|
-
import type { firstlyData } from './types';
|
|
6
|
+
import type { RecursivePartial, ResolvedType } from '../utils/types';
|
|
7
|
+
import { FFAuthAccount, FFAuthProvider, FFAuthUser, FFAuthUserSession } from './Entities';
|
|
8
|
+
import type { firstlyData, firstlyDataAuth } from './types';
|
|
9
9
|
export type { firstlyData };
|
|
10
|
-
export {
|
|
10
|
+
export { FFAuthUser, FFAuthAccount, FFAuthProvider, FFAuthUserSession };
|
|
11
11
|
export type AuthorizationURLOptions = Record<string, {
|
|
12
12
|
scopes?: string[];
|
|
13
13
|
}>;
|
|
14
|
-
export type DynamicAuthorizationURLOptions<T extends
|
|
14
|
+
export type DynamicAuthorizationURLOptions<T extends FFOAuth2Provider[] = FFOAuth2Provider[]> = T extends Array<infer O> ? O extends FFOAuth2Provider ? {
|
|
15
15
|
[P in O['name']]: ReturnType<O['authorizationURLOptions']>;
|
|
16
16
|
} : never : never;
|
|
17
17
|
export declare const logAuth: Log;
|
|
18
|
-
export {
|
|
18
|
+
export { FF_Auth_Role } from './Entities';
|
|
19
19
|
type OAuth2UserInfo = {
|
|
20
20
|
raw?: any;
|
|
21
21
|
providerUserId: string;
|
|
22
22
|
/** Will take the first option available */
|
|
23
23
|
nameOptions: string[];
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
25
|
+
export type FFOAuth2Provider<LitName extends string = string, T extends ArcticOAuth2Provider | ArcticOAuth2ProviderWithPKCE = ArcticOAuth2Provider> = {
|
|
26
26
|
name: LitName;
|
|
27
27
|
getArcticProvider: () => T;
|
|
28
28
|
isPKCE: T extends ArcticOAuth2Provider ? false : T extends ArcticOAuth2ProviderWithPKCE ? true : never;
|
|
29
29
|
authorizationURLOptions: () => T extends ArcticOAuth2Provider ? Parameters<T['createAuthorizationURL']>[1] : T extends ArcticOAuth2ProviderWithPKCE ? Parameters<T['createAuthorizationURL']>[2] : never;
|
|
30
30
|
getUserInfo(tokens: ResolvedType<ReturnType<T['validateAuthorizationCode']>>): Promise<OAuth2UserInfo>;
|
|
31
31
|
};
|
|
32
|
-
type AuthOptions<TUserEntity extends
|
|
32
|
+
type AuthOptions<TUserEntity extends FFAuthUser = FFAuthUser, TSessionEntity extends FFAuthUserSession = FFAuthUserSession, TAccountEntity extends FFAuthAccount = FFAuthAccount> = {
|
|
33
33
|
customEntities?: {
|
|
34
34
|
User?: ClassType<TUserEntity>;
|
|
35
35
|
Session?: ClassType<TSessionEntity>;
|
|
36
36
|
Account?: ClassType<TAccountEntity>;
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
base?: string;
|
|
41
|
-
};
|
|
42
|
-
} | false;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
ui?: false | RecursivePartial<firstlyDataAuth['ui']>;
|
|
43
40
|
/** in secondes @default 15 days */
|
|
44
41
|
sessionExpiresIn?: number;
|
|
45
42
|
sessionCookie?: SessionCookieOptions;
|
|
@@ -111,14 +108,14 @@ type AuthOptions<TUserEntity extends KitAuthUser = KitAuthUser, TSessionEntity e
|
|
|
111
108
|
uri: string;
|
|
112
109
|
}) => Promise<void>;
|
|
113
110
|
};
|
|
114
|
-
oAuths?:
|
|
111
|
+
oAuths?: FFOAuth2Provider[];
|
|
115
112
|
};
|
|
116
113
|
};
|
|
117
114
|
export declare let AUTH_OPTIONS: AuthOptions;
|
|
118
115
|
export declare const getSafeOptions: () => {
|
|
119
|
-
User: ClassType<
|
|
120
|
-
Session: ClassType<
|
|
121
|
-
Account: ClassType<
|
|
116
|
+
User: ClassType<FFAuthUser>;
|
|
117
|
+
Session: ClassType<FFAuthUserSession>;
|
|
118
|
+
Account: ClassType<FFAuthAccount>;
|
|
122
119
|
signUp: boolean;
|
|
123
120
|
password_enabled: boolean;
|
|
124
121
|
otp_enabled: boolean;
|
package/esm/auth/index.js
CHANGED
|
@@ -3,54 +3,59 @@ import { DEV } from 'esm-env';
|
|
|
3
3
|
import { Lucia, TimeSpan } from 'lucia';
|
|
4
4
|
import { remult } from 'remult';
|
|
5
5
|
import { Log, red } from '@kitql/helpers';
|
|
6
|
-
import { read } from '@kitql/internals';
|
|
7
|
-
import {
|
|
6
|
+
import { getRelativePackagePath, read } from '@kitql/internals';
|
|
7
|
+
import { env } from '$env/dynamic/private';
|
|
8
|
+
import { FF_Role } from '../';
|
|
8
9
|
import { RemultLuciaAdapter } from './Adapter';
|
|
9
10
|
import { AuthControllerServer } from './AuthController.server';
|
|
10
11
|
import { Auth } from './client';
|
|
11
|
-
import {
|
|
12
|
+
import { FF_Auth_Role, FFAuthAccount, FFAuthProvider, FFAuthUser, FFAuthUserSession, } from './Entities';
|
|
12
13
|
import { createSession } from './helper';
|
|
13
14
|
import { initRoleFromEnv } from './RoleHelpers';
|
|
14
|
-
export {
|
|
15
|
+
export { FFAuthUser, FFAuthAccount, FFAuthProvider, FFAuthUserSession };
|
|
15
16
|
export const logAuth = new Log('firstly | auth');
|
|
16
|
-
export {
|
|
17
|
-
export let AUTH_OPTIONS = {};
|
|
17
|
+
export { FF_Auth_Role } from './Entities';
|
|
18
|
+
export let AUTH_OPTIONS = { ui: {} };
|
|
19
|
+
const buildUrlOrDefault = (base, userSetting, fallback) => {
|
|
20
|
+
if (userSetting) {
|
|
21
|
+
return `${base}/${userSetting}`;
|
|
22
|
+
}
|
|
23
|
+
return `${base}/${fallback}`;
|
|
24
|
+
};
|
|
18
25
|
export const getSafeOptions = () => {
|
|
19
26
|
const signUp = AUTH_OPTIONS.signUp ?? true;
|
|
20
|
-
const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : AUTH_OPTIONS.ui?.paths?.base ?? '/
|
|
21
|
-
const oAuths =
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : AUTH_OPTIONS.ui?.paths?.base ?? '/ff/auth';
|
|
28
|
+
// const oAuths =
|
|
29
|
+
// AUTH_OPTIONS.providers?.oAuths?.map((o) => {
|
|
30
|
+
// return o.name
|
|
31
|
+
// }) ?? []
|
|
24
32
|
const firstlyData = {
|
|
25
33
|
module: 'auth',
|
|
34
|
+
debug: AUTH_OPTIONS.debug,
|
|
26
35
|
props: {
|
|
27
|
-
ui:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
verify_email: `${base}/verify-email`,
|
|
49
|
-
},
|
|
36
|
+
ui: AUTH_OPTIONS.ui === false
|
|
37
|
+
? undefined
|
|
38
|
+
: {
|
|
39
|
+
paths: {
|
|
40
|
+
base,
|
|
41
|
+
sign_up: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_up, 'sign-up'),
|
|
42
|
+
sign_in: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_in, 'sign-in'),
|
|
43
|
+
forgot_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.forgot_password, 'forgot-password'),
|
|
44
|
+
reset_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.reset_password, 'reset-password'),
|
|
45
|
+
verify_email: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.verify_email, 'verify-email'),
|
|
46
|
+
},
|
|
47
|
+
strings: {
|
|
48
|
+
email: AUTH_OPTIONS.ui?.strings?.email ?? 'Email',
|
|
49
|
+
email_placeholder: AUTH_OPTIONS.ui?.strings?.email_placeholder ?? 'Your email address',
|
|
50
|
+
password: AUTH_OPTIONS.ui?.strings?.password ?? 'Password',
|
|
51
|
+
btn_sign_up: AUTH_OPTIONS.ui?.strings?.btn_sign_up ?? 'Sign up',
|
|
52
|
+
btn_sign_in: AUTH_OPTIONS.ui?.strings?.btn_sign_in ?? 'Sign in',
|
|
53
|
+
forgot_password: AUTH_OPTIONS.ui?.strings?.forgot_password ?? 'Forgot your password?',
|
|
54
|
+
send_password_reset_instructions: AUTH_OPTIONS.ui?.strings?.send_password_reset_instructions ??
|
|
55
|
+
'Send password reset instructions',
|
|
56
|
+
back_to_sign_in: AUTH_OPTIONS.ui?.strings?.back_to_sign_in ?? 'Back to sign in',
|
|
50
57
|
},
|
|
51
|
-
oAuths,
|
|
52
58
|
},
|
|
53
|
-
},
|
|
54
59
|
},
|
|
55
60
|
};
|
|
56
61
|
let redirectUrl = AUTH_OPTIONS.defaultRedirect ?? '/';
|
|
@@ -59,9 +64,9 @@ export const getSafeOptions = () => {
|
|
|
59
64
|
redirectUrl = '/';
|
|
60
65
|
}
|
|
61
66
|
return {
|
|
62
|
-
User: AUTH_OPTIONS.customEntities?.User ??
|
|
63
|
-
Session: AUTH_OPTIONS.customEntities?.Session ??
|
|
64
|
-
Account: AUTH_OPTIONS.customEntities?.Account ??
|
|
67
|
+
User: AUTH_OPTIONS.customEntities?.User ?? FFAuthUser,
|
|
68
|
+
Session: AUTH_OPTIONS.customEntities?.Session ?? FFAuthUserSession,
|
|
69
|
+
Account: AUTH_OPTIONS.customEntities?.Account ?? FFAuthAccount,
|
|
65
70
|
signUp,
|
|
66
71
|
password_enabled: AUTH_OPTIONS.providers?.password ? true : false,
|
|
67
72
|
otp_enabled: AUTH_OPTIONS.providers?.otp ? true : false,
|
|
@@ -109,18 +114,18 @@ export const auth = (o) => {
|
|
|
109
114
|
}
|
|
110
115
|
},
|
|
111
116
|
earlyReturn: async ({ event, resolve }) => {
|
|
112
|
-
if (AUTH_OPTIONS.ui === false) {
|
|
113
|
-
|
|
114
|
-
}
|
|
117
|
+
// if (AUTH_OPTIONS.ui === false) {
|
|
118
|
+
// return { early: false }
|
|
119
|
+
// }
|
|
115
120
|
const oSafe = getSafeOptions();
|
|
116
|
-
if (event.url.pathname === oSafe.firstlyData.props.ui
|
|
121
|
+
if (event.url.pathname === oSafe.firstlyData.props.ui?.paths?.verify_email) {
|
|
117
122
|
const token = event.url.searchParams.get('token') ?? '';
|
|
118
123
|
if (!oSafe.password_enabled) {
|
|
119
124
|
throw Error('Password is not enabled!');
|
|
120
125
|
}
|
|
121
126
|
const account = await remult
|
|
122
127
|
.repo(oSafe.Account)
|
|
123
|
-
.findFirst({ token, provider:
|
|
128
|
+
.findFirst({ token, provider: FFAuthProvider.PASSWORD.id });
|
|
124
129
|
if (!account) {
|
|
125
130
|
throw new Error('Invalid token');
|
|
126
131
|
}
|
|
@@ -136,12 +141,15 @@ export const auth = (o) => {
|
|
|
136
141
|
await createSession(account.userId);
|
|
137
142
|
redirect(302, oSafe.redirectUrl);
|
|
138
143
|
}
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
// For users
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
// For lib author (us), it's good to have this local path.
|
|
145
|
+
let staticPath = './src/lib/auth/static/';
|
|
146
|
+
// For users, let's serve the static files from the installed package
|
|
147
|
+
const installedFirstlyPath = getRelativePackagePath('firstly');
|
|
148
|
+
if (installedFirstlyPath) {
|
|
149
|
+
staticPath = `${installedFirstlyPath}/esm/auth/static/`;
|
|
150
|
+
}
|
|
151
|
+
if (oSafe.firstlyData.props.ui?.paths?.base &&
|
|
152
|
+
event.url.pathname.startsWith(oSafe.firstlyData.props.ui.paths.base)) {
|
|
145
153
|
const content = read(`${staticPath}index.html`);
|
|
146
154
|
return {
|
|
147
155
|
early: true,
|
|
@@ -251,9 +259,8 @@ export const auth = (o) => {
|
|
|
251
259
|
return { early: false };
|
|
252
260
|
},
|
|
253
261
|
initApi: async () => {
|
|
254
|
-
|
|
255
|
-
await initRoleFromEnv(logAuth, oSafe.User,
|
|
256
|
-
await initRoleFromEnv(logAuth, oSafe.User, 'KIT_AUTH_ADMIN', KitAuthRole.Admin);
|
|
262
|
+
await initRoleFromEnv(logAuth, oSafe.User, env.FF_ADMIN, FF_Role.Admin);
|
|
263
|
+
await initRoleFromEnv(logAuth, oSafe.User, env.FF_AUTH_ADMIN, FF_Auth_Role.Admin);
|
|
257
264
|
},
|
|
258
265
|
};
|
|
259
266
|
};
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { GitHub } from 'arctic';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FFOAuth2Provider } from '../';
|
|
3
3
|
/**
|
|
4
|
-
* GitHub OAuth2 provider
|
|
4
|
+
* ## GitHub OAuth2 provider
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
* In your project add a `.env` file with the following:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
6
|
+
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
7
|
+
* 2. In GitHub, set your callback url to
|
|
8
|
+
* - [ ] dev: `http://localhost:5173/api/auth_callback`
|
|
9
|
+
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
10
|
+
* 3. In your project add a `.env` file with the following:
|
|
11
|
+
* ```bash
|
|
12
|
+
* GITHUB_CLIENT_ID = 'your-client-id'
|
|
13
|
+
* GITHUB_CLIENT_SECRET = 'your-client-secret'
|
|
14
|
+
* # GITHUB_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
|
|
15
15
|
* ```
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* 4. In your frontend, under a button click call something like:
|
|
17
|
+
* ```ts
|
|
18
|
+
* async function oauth() {
|
|
19
|
+
* window.location.href = await Auth.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
* 5. Enjoy 🥳
|
|
18
23
|
*/
|
|
19
24
|
export declare function github(options?: {
|
|
20
|
-
GITHUB_CLIENT_ID
|
|
21
|
-
GITHUB_CLIENT_SECRET
|
|
25
|
+
GITHUB_CLIENT_ID?: string;
|
|
26
|
+
GITHUB_CLIENT_SECRET?: string;
|
|
22
27
|
GITHUB_REDIRECT_URI?: string;
|
|
23
|
-
authorizationURLOptions?: ReturnType<
|
|
28
|
+
authorizationURLOptions?: ReturnType<FFOAuth2Provider<'github', GitHub>['authorizationURLOptions']>;
|
|
24
29
|
log?: boolean;
|
|
25
|
-
}):
|
|
30
|
+
}): FFOAuth2Provider<'github', GitHub>;
|
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
import { GitHub } from 'arctic';
|
|
2
2
|
import { remult } from 'remult';
|
|
3
|
+
import { env } from '$env/dynamic/private';
|
|
3
4
|
import { checkOAuthConfig } from '.';
|
|
4
5
|
import { logAuth } from '../';
|
|
6
|
+
//------------------------------
|
|
7
|
+
// For developers (future me ?), To do another OAuth2 provider:
|
|
8
|
+
// Replace GITHUB / Github / github
|
|
9
|
+
// update "https://github.com/settings/developers" to the correct URL (2 places)
|
|
10
|
+
// update "https://api.github.com/user" the fetch user info
|
|
11
|
+
//------------------------------
|
|
5
12
|
/**
|
|
6
|
-
* GitHub OAuth2 provider
|
|
13
|
+
* ## GitHub OAuth2 provider
|
|
7
14
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
* In your project add a `.env` file with the following:
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
16
|
+
* 2. In GitHub, set your callback url to
|
|
17
|
+
* - [ ] dev: `http://localhost:5173/api/auth_callback`
|
|
18
|
+
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
19
|
+
* 3. In your project add a `.env` file with the following:
|
|
20
|
+
* ```bash
|
|
21
|
+
* GITHUB_CLIENT_ID = 'your-client-id'
|
|
22
|
+
* GITHUB_CLIENT_SECRET = 'your-client-secret'
|
|
23
|
+
* # GITHUB_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
|
|
17
24
|
* ```
|
|
18
|
-
*
|
|
19
|
-
*
|
|
25
|
+
* 4. In your frontend, under a button click call something like:
|
|
26
|
+
* ```ts
|
|
27
|
+
* async function oauth() {
|
|
28
|
+
* window.location.href = await Auth.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
* 5. Enjoy 🥳
|
|
20
32
|
*/
|
|
21
33
|
export function github(options) {
|
|
22
34
|
const name = 'github';
|
|
23
|
-
const clientID = options?.GITHUB_CLIENT_ID ?? '';
|
|
24
|
-
const secret = options?.GITHUB_CLIENT_SECRET ?? '';
|
|
35
|
+
const clientID = options?.GITHUB_CLIENT_ID ?? env.GITHUB_CLIENT_ID ?? '';
|
|
36
|
+
const secret = options?.GITHUB_CLIENT_SECRET ?? env.GITHUB_CLIENT_SECRET ?? '';
|
|
25
37
|
const urlForKeys = 'https://github.com/settings/developers';
|
|
26
38
|
checkOAuthConfig(name, clientID, secret, urlForKeys, false);
|
|
27
39
|
return {
|
|
28
40
|
name,
|
|
29
41
|
isPKCE: false,
|
|
30
42
|
getArcticProvider: () => {
|
|
31
|
-
const redirectURI = options?.GITHUB_REDIRECT_URI
|
|
43
|
+
const redirectURI = options?.GITHUB_REDIRECT_URI ??
|
|
44
|
+
env.GITHUB_REDIRECT_URI ??
|
|
45
|
+
`${remult.context.url.origin}/api/auth_callback`;
|
|
32
46
|
checkOAuthConfig(name, clientID, secret, urlForKeys, true);
|
|
33
47
|
return new GitHub(clientID, secret, { redirectURI });
|
|
34
48
|
},
|