firstly 0.0.16-next.0 → 0.0.16-next.2

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/esm/auth/Entities.d.ts +5 -0
  3. package/esm/auth/Entities.js +4 -0
  4. package/esm/auth/server/AuthController.server.js +26 -19
  5. package/esm/auth/server/handleAuth.js +5 -8
  6. package/esm/auth/server/module.d.ts +4 -8
  7. package/esm/auth/server/module.js +16 -0
  8. package/esm/auth/server/providers/github.d.ts +2 -2
  9. package/esm/auth/server/providers/github.js +1 -0
  10. package/esm/auth/static/assets/{Page-BgIgl-Te.d.ts → Page-BorYIfy9.d.ts} +2 -2
  11. package/esm/auth/static/assets/Page-BorYIfy9.js +1 -0
  12. package/esm/auth/static/assets/Page-Cm4MsdIa.d.ts +6 -0
  13. package/esm/auth/static/assets/Page-Cm4MsdIa.js +20 -0
  14. package/esm/auth/static/assets/{Page-f5pC21Yg.d.ts → Page-CqsLm8yQ.d.ts} +2 -2
  15. package/esm/auth/static/assets/{Page-BgIgl-Te.js → Page-CqsLm8yQ.js} +1 -1
  16. package/esm/auth/static/assets/Page-JfNiCSIG.css +1 -0
  17. package/esm/auth/static/assets/index-Borxa2ns.d.ts +234 -0
  18. package/esm/auth/static/assets/index-Borxa2ns.js +44 -0
  19. package/esm/auth/static/index.html +1 -2
  20. package/esm/auth/types.d.ts +15 -1
  21. package/esm/ui/Grid2.svelte +2 -2
  22. package/esm/ui/Grid2.svelte.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/esm/auth/static/assets/Page-HDnoBhpE.d.ts +0 -6
  25. package/esm/auth/static/assets/Page-HDnoBhpE.js +0 -20
  26. package/esm/auth/static/assets/Page-f5pC21Yg.js +0 -1
  27. package/esm/auth/static/assets/Page-mK42zGEw.css +0 -1
  28. package/esm/auth/static/assets/index-DAjei0Ie.d.ts +0 -151
  29. package/esm/auth/static/assets/index-DAjei0Ie.js +0 -42
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # firstly
2
2
 
3
+ ## 0.0.16-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#110](https://github.com/jycouet/firstly/pull/110)
8
+ [`0c66f11`](https://github.com/jycouet/firstly/commit/0c66f114dd95f65c0407abddbd647a66769142eb)
9
+ Thanks [@jycouet](https://github.com/jycouet)! - add github in default ui (if configured)
10
+
11
+ ## 0.0.16-next.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#108](https://github.com/jycouet/firstly/pull/108)
16
+ [`cf100f4`](https://github.com/jycouet/firstly/commit/cf100f40a8462eca51acff3ac5d8779da78816ec)
17
+ Thanks [@jycouet](https://github.com/jycouet)! - fix import paths
18
+
3
19
  ## 0.0.16-next.0
4
20
 
5
21
  ### Patch Changes
@@ -1,5 +1,7 @@
1
+ import type { OAuth2Tokens } from 'arctic';
1
2
  import { BaseEnum } from '..';
2
3
  import type { BaseEnumOptions } from '..';
4
+ import type { OAuth2UserInfo } from './types';
3
5
  export declare const FF_Role_Auth: {
4
6
  readonly FF_Role_Auth_Admin: "FF_Role_Auth.Admin";
5
7
  readonly FF_Role_Auth_Invite: "FF_Role_Auth.Invite";
@@ -25,6 +27,9 @@ export declare class FFAuthAccount {
25
27
  token?: string;
26
28
  expiresAt?: Date;
27
29
  lastVerifiedAt?: Date;
30
+ metadata?: OAuth2UserInfo & {
31
+ tokens_data: OAuth2Tokens['data'];
32
+ };
28
33
  }
29
34
  export declare class FFAuthUserSession {
30
35
  id: string;
@@ -84,6 +84,7 @@ let FFAuthAccount = class FFAuthAccount {
84
84
  token;
85
85
  expiresAt;
86
86
  lastVerifiedAt;
87
+ metadata;
87
88
  };
88
89
  __decorate([
89
90
  Fields.cuid()
@@ -118,6 +119,9 @@ __decorate([
118
119
  __decorate([
119
120
  Fields.date({ includeInApi: false, allowNull: true })
120
121
  ], FFAuthAccount.prototype, "lastVerifiedAt", void 0);
122
+ __decorate([
123
+ Fields.json({ includeInApi: false, allowNull: true })
124
+ ], FFAuthAccount.prototype, "metadata", void 0);
121
125
  FFAuthAccount = __decorate([
122
126
  FF_Entity('ff_auth.accounts', {
123
127
  allowApiCrud: [FF_Role_Auth.FF_Role_Auth_Admin, FF_Role.FF_Role_Admin],
@@ -170,22 +170,23 @@ export class AuthControllerServer {
170
170
  throw new EntityError({ message: "You can't signup twice !" });
171
171
  }
172
172
  const token = generateAndEncodeToken();
173
- await remult.dataProvider.transaction(async () => {
174
- const user = await repo(oSafe.User).insert({
175
- identifier: email,
176
- });
177
- await repo(oSafe.Account).insert({
178
- provider: FFAuthProvider.PASSWORD.id,
179
- providerUserId: email,
180
- userId: user.id,
181
- hashPassword: await oSafe.password.hash(password),
182
- token: oSafe.verifiedMethod === 'auto' ? undefined : token,
183
- expiresAt: oSafe.verifiedMethod === 'auto'
184
- ? undefined
185
- : createDate(AUTH_OPTIONS.providers?.password?.mail?.verify?.expiresIn ?? 5 * 60),
186
- lastVerifiedAt: oSafe.verifiedMethod === 'auto' ? new Date() : undefined,
187
- });
173
+ // REMULT: Do not put it in a transaction, as it will be called from a backendmethod that is already in a transaction! And nested transactions not allowed.
174
+ // await remult.dataProvider.transaction(async () => {
175
+ const user = await repo(oSafe.User).insert({
176
+ identifier: email,
177
+ });
178
+ await repo(oSafe.Account).insert({
179
+ provider: FFAuthProvider.PASSWORD.id,
180
+ providerUserId: email,
181
+ userId: user.id,
182
+ hashPassword: await oSafe.password.hash(password),
183
+ token: oSafe.verifiedMethod === 'auto' ? undefined : token,
184
+ expiresAt: oSafe.verifiedMethod === 'auto'
185
+ ? undefined
186
+ : createDate(AUTH_OPTIONS.providers?.password?.mail?.verify?.expiresIn ?? 5 * 60),
187
+ lastVerifiedAt: oSafe.verifiedMethod === 'auto' ? new Date() : undefined,
188
188
  });
189
+ // })
189
190
  if (oSafe.verifiedMethod === 'auto') {
190
191
  const user = await repo(oSafe.User).findFirst({
191
192
  identifier: email,
@@ -198,7 +199,7 @@ export class AuthControllerServer {
198
199
  };
199
200
  }
200
201
  }
201
- else {
202
+ else if (oSafe.verifiedMethod === 'email') {
202
203
  const url = `${remult.context.request.url.origin}${oSafe.firstlyData.props.ui?.paths.verify_email}?token=${token}`;
203
204
  if (AUTH_OPTIONS.providers?.password?.mail?.verify?.send) {
204
205
  await AUTH_OPTIONS.providers?.password.mail.verify.send({ email, url });
@@ -225,10 +226,14 @@ export class AuthControllerServer {
225
226
  });
226
227
  authModuleRaw.log.success(`${magenta('[verifyMailSend]')} (${yellow(url)})`);
227
228
  }
229
+ return {
230
+ message: 'We sent you a mail to verify your account.',
231
+ user: undefined,
232
+ };
228
233
  }
229
234
  return {
230
- message: 'ok',
231
- user: remult.user,
235
+ message: 'Someone needs to validate your account.',
236
+ user: undefined,
232
237
  };
233
238
  }
234
239
  /**
@@ -488,7 +493,9 @@ export class AuthControllerServer {
488
493
  catch (error) {
489
494
  // display error for the server only
490
495
  authModuleRaw.log.error(error);
491
- throw new EntityError({ message: `${selectedOAuth.name} not well configured!` });
496
+ throw new EntityError({
497
+ message: `${selectedOAuth.name} not well configured! Check server logs for more details.`,
498
+ });
492
499
  }
493
500
  }
494
501
  throw new EntityError({
@@ -118,19 +118,16 @@ export const handleAuth = async ({ event, resolve }) => {
118
118
  }
119
119
  const user = repo(oSafe.User).create();
120
120
  user.identifier = nameToUse;
121
+ await repo(oSafe.User).save(user);
121
122
  account = repo(oSafe.Account).create();
122
123
  account.provider = keyState;
123
124
  account.providerUserId = info.providerUserId;
124
- account.token = tokens.accessToken();
125
125
  account.userId = user.id;
126
- account.lastVerifiedAt = new Date();
127
- await repo(oSafe.User).save(user);
128
- await repo(oSafe.Account).save(account);
129
- }
130
- else {
131
- account.token = tokens.accessToken();
132
- await repo(oSafe.Account).save(account);
133
126
  }
127
+ account.lastVerifiedAt = new Date();
128
+ account.token = tokens.accessToken();
129
+ account.metadata = { ...info, tokens_data: tokens.data };
130
+ await repo(oSafe.Account).save(account);
134
131
  await ff_createSession(account.userId);
135
132
  event.cookies.delete(`${keyState}_oauth_state`, { path: '/' });
136
133
  event.cookies.delete(`code_verifier`, { path: '/' });
@@ -3,16 +3,12 @@ import type { ClassType, UserInfo } from 'remult';
3
3
  import { Module } from '../../server';
4
4
  import type { RecursivePartial } from '../../utils/types';
5
5
  import { FFAuthAccount, FFAuthUser, FFAuthUserSession } from '../Entities';
6
- import type { FirstlyData, FirstlyDataAuth, ProviderAuthorizationURLOptions } from '../types';
6
+ import type { FirstlyData, FirstlyDataAuth, OAuth2UserInfo, ProviderAuthorizationURLOptions } from '../types';
7
7
  import { initRoleFromEnv } from './helperRole';
8
- export type OAuth2UserInfo = {
9
- raw?: any;
10
- providerUserId: string;
11
- /** Will take the first option available */
12
- nameOptions: string[];
13
- };
14
8
  export type FFOAuth2Provider<T = any, LitName extends string = string> = {
15
9
  name: LitName;
10
+ caption: string;
11
+ raw_svg?: string;
16
12
  getArcticProvider: () => T;
17
13
  authorizationURLOptions: () => ProviderAuthorizationURLOptions;
18
14
  getUserInfo(tokens: OAuth2Tokens): Promise<OAuth2UserInfo>;
@@ -47,7 +43,7 @@ type AuthOptions<TUserEntity extends FFAuthUser = FFAuthUser, TSessionEntity ext
47
43
  /**
48
44
  * To be able to sign in user needs to be verified or not?
49
45
  * ```
50
- * `Auto` => noting will be checked
46
+ * `Auto` => noting will be checked
51
47
  * `Email` => users needs to click a link in an email
52
48
  * `Manual` => an admin needs to verify the user and set verifiedAt in the database
53
49
  * ```
@@ -59,11 +59,27 @@ export const getSafeOptions = () => {
59
59
  if (AUTH_OPTIONS.debug && !building) {
60
60
  authModuleRaw.log.info('ui', ui);
61
61
  }
62
+ const getProviderIcon = (name) => {
63
+ switch (name) {
64
+ case 'github':
65
+ return `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>`;
66
+ case 'google':
67
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><!-- Icon from Devicon by konpa - https://github.com/devicons/devicon/blob/master/LICENSE --><path fill="#fff" d="M44.59 4.21a63.28 63.28 0 0 0 4.33 120.9a67.6 67.6 0 0 0 32.36.35a57.13 57.13 0 0 0 25.9-13.46a57.44 57.44 0 0 0 16-26.26a74.3 74.3 0 0 0 1.61-33.58H65.27v24.69h34.47a29.72 29.72 0 0 1-12.66 19.52a36.2 36.2 0 0 1-13.93 5.5a41.3 41.3 0 0 1-15.1 0A37.2 37.2 0 0 1 44 95.74a39.3 39.3 0 0 1-14.5-19.42a38.3 38.3 0 0 1 0-24.63a39.25 39.25 0 0 1 9.18-14.91A37.17 37.17 0 0 1 76.13 27a34.3 34.3 0 0 1 13.64 8q5.83-5.8 11.64-11.63c2-2.09 4.18-4.08 6.15-6.22A61.2 61.2 0 0 0 87.2 4.59a64 64 0 0 0-42.61-.38"/><path fill="#e33629" d="M44.59 4.21a64 64 0 0 1 42.61.37a61.2 61.2 0 0 1 20.35 12.62c-2 2.14-4.11 4.14-6.15 6.22Q95.58 29.23 89.77 35a34.3 34.3 0 0 0-13.64-8a37.17 37.17 0 0 0-37.46 9.74a39.25 39.25 0 0 0-9.18 14.91L8.76 35.6A63.53 63.53 0 0 1 44.59 4.21"/><path fill="#f8bd00" d="M3.26 51.5a63 63 0 0 1 5.5-15.9l20.73 16.09a38.3 38.3 0 0 0 0 24.63q-10.36 8-20.73 16.08a63.33 63.33 0 0 1-5.5-40.9"/><path fill="#587dbd" d="M65.27 52.15h59.52a74.3 74.3 0 0 1-1.61 33.58a57.44 57.44 0 0 1-16 26.26c-6.69-5.22-13.41-10.4-20.1-15.62a29.72 29.72 0 0 0 12.66-19.54H65.27c-.01-8.22 0-16.45 0-24.68"/><path fill="#319f43" d="M8.75 92.4q10.37-8 20.73-16.08A39.3 39.3 0 0 0 44 95.74a37.2 37.2 0 0 0 14.08 6.08a41.3 41.3 0 0 0 15.1 0a36.2 36.2 0 0 0 13.93-5.5c6.69 5.22 13.41 10.4 20.1 15.62a57.13 57.13 0 0 1-25.9 13.47a67.6 67.6 0 0 1-32.36-.35a63 63 0 0 1-23-11.59A63.7 63.7 0 0 1 8.75 92.4"/></svg>`;
68
+ default:
69
+ return '';
70
+ }
71
+ };
72
+ const providers = AUTH_OPTIONS.providers?.oAuths?.map((o) => ({
73
+ name: o.name,
74
+ label: o.caption,
75
+ raw_svg: o.raw_svg ?? getProviderIcon(o.name),
76
+ })) ?? [];
62
77
  const firstlyData = {
63
78
  module: 'auth',
64
79
  debug: AUTH_OPTIONS.debug,
65
80
  props: {
66
81
  ui,
82
+ providers,
67
83
  },
68
84
  };
69
85
  let uiStaticPath = AUTH_OPTIONS.uiStaticPath ?? '';
@@ -1,7 +1,7 @@
1
1
  import type { OAuth2Tokens } from 'arctic';
2
2
  import { GitHub } from 'arctic';
3
- import type { ProviderAuthorizationURLOptions } from '../../types';
4
- import { type FFOAuth2Provider, type OAuth2UserInfo } from '../module';
3
+ import type { OAuth2UserInfo, ProviderAuthorizationURLOptions } from '../../types';
4
+ import { type FFOAuth2Provider } from '../module';
5
5
  /**
6
6
  * ## GitHub OAuth2 provider
7
7
  *
@@ -38,6 +38,7 @@ export function github(options) {
38
38
  checkOAuthConfig(name, clientID, secret, urlForKeys, false);
39
39
  return {
40
40
  name,
41
+ caption: 'GitHub',
41
42
  getArcticProvider: () => {
42
43
  const redirectURI = options?.GITHUB_REDIRECT_URI ??
43
44
  env.GITHUB_REDIRECT_URI ??
@@ -1,6 +1,6 @@
1
1
  export { a as default };
2
2
  declare function a(e: any, s: any): any;
3
3
  declare namespace a {
4
- let ______17210: string;
5
- export { ______17210 as __@$@17210 };
4
+ let ____A_17224: string;
5
+ export { ____A_17224 as __@A@17224 };
6
6
  }
@@ -0,0 +1 @@
1
+ import{D as r,E as m,am as l,S as o,T as d,U as n,V as p,W as u,Y as i}from"./index-Borxa2ns.js";p();a[u]="src/lib/modules/admin/Page.svelte";function a(e,s){r(new.target),m(s,!1,a);var t=l("Hello from admin");return o(e,t),d({...n()})}i(a);export{a as default};
@@ -0,0 +1,6 @@
1
+ export { re as default };
2
+ declare function re(n: any, e: any): any;
3
+ declare namespace re {
4
+ let ____A_17224: string;
5
+ export { ____A_17224 as __@A@17224 };
6
+ }