firstly 0.0.7 → 0.0.8

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 (56) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/esm/FF_Entity.js +20 -4
  3. package/esm/SqlDatabase/FF_LogToConsole.d.ts +4 -1
  4. package/esm/SqlDatabase/FF_LogToConsole.js +15 -8
  5. package/esm/api/index.d.ts +2 -2
  6. package/esm/api/index.js +9 -9
  7. package/esm/auth/Adapter.js +1 -9
  8. package/esm/auth/AuthController.server.d.ts +1 -2
  9. package/esm/auth/AuthController.server.js +21 -12
  10. package/esm/auth/RoleHelpers.d.ts +1 -1
  11. package/esm/auth/RoleHelpers.js +1 -1
  12. package/esm/auth/client/Auth.d.ts +11 -4
  13. package/esm/auth/client/Auth.js +12 -4
  14. package/esm/auth/{Entities.d.ts → client/Entities.d.ts} +2 -2
  15. package/esm/auth/{Entities.js → client/Entities.js} +28 -12
  16. package/esm/auth/client/index.d.ts +5 -0
  17. package/esm/auth/client/index.js +5 -0
  18. package/esm/auth/helper.d.ts +6 -1
  19. package/esm/auth/helper.js +11 -4
  20. package/esm/auth/index.d.ts +9 -11
  21. package/esm/auth/index.js +72 -68
  22. package/esm/auth/providers/github.js +2 -1
  23. package/esm/auth/providers/index.js +1 -1
  24. package/esm/auth/providers/strava.js +2 -1
  25. package/esm/auth/static/assets/{Page-RIbXHuZG.d.ts → Page-BEFYPjis.d.ts} +1 -1
  26. package/esm/auth/static/assets/{Page-RIbXHuZG.js → Page-BEFYPjis.js} +1 -1
  27. package/esm/auth/static/assets/Page-Cfysx_UV.d.ts +6 -0
  28. package/esm/auth/static/assets/Page-Cfysx_UV.js +18 -0
  29. package/esm/auth/static/assets/{Page-DBWJjlEQ.d.ts → Page-DtgkOCJs.d.ts} +1 -1
  30. package/esm/auth/static/assets/{Page-DBWJjlEQ.js → Page-DtgkOCJs.js} +1 -1
  31. package/esm/auth/static/assets/index-QypqCYwC.d.ts +63 -0
  32. package/esm/auth/static/assets/index-QypqCYwC.js +2 -0
  33. package/esm/auth/static/index.html +1 -1
  34. package/esm/auth/types.d.ts +7 -5
  35. package/esm/bin/cmd.js +28 -14
  36. package/esm/cellsBuildor.d.ts +1 -0
  37. package/esm/cellsBuildor.js +24 -12
  38. package/esm/changeLog/index.d.ts +23 -7
  39. package/esm/changeLog/index.js +24 -18
  40. package/esm/feedback/FeedbackController.d.ts +12 -3
  41. package/esm/feedback/FeedbackController.js +62 -11
  42. package/esm/feedback/index.d.ts +1 -0
  43. package/esm/feedback/ui/DialogIssue.svelte +28 -9
  44. package/esm/feedback/ui/DialogIssues.svelte +7 -2
  45. package/esm/handle/index.d.ts +1 -1
  46. package/esm/index.d.ts +4 -2
  47. package/esm/index.js +1 -1
  48. package/esm/ui/Field.svelte +2 -10
  49. package/esm/ui/GridPaginate.svelte +7 -7
  50. package/esm/ui/GridPaginate.svelte.d.ts +1 -1
  51. package/esm/vite/index.js +4 -1
  52. package/package.json +7 -7
  53. package/esm/auth/static/assets/Page-apb_xgZT.d.ts +0 -6
  54. package/esm/auth/static/assets/Page-apb_xgZT.js +0 -18
  55. package/esm/auth/static/assets/index-qfq98Nyd.d.ts +0 -63
  56. package/esm/auth/static/assets/index-qfq98Nyd.js +0 -2
package/esm/auth/index.js CHANGED
@@ -2,33 +2,29 @@ import { redirect } from '@sveltejs/kit';
2
2
  import { DEV } from 'esm-env';
3
3
  import { Lucia, TimeSpan } from 'lucia';
4
4
  import { remult } from 'remult';
5
- import { Log, red } from '@kitql/helpers';
5
+ import { red } from '@kitql/helpers';
6
6
  import { getRelativePackagePath, read } from '@kitql/internals';
7
7
  import { env } from '$env/dynamic/private';
8
8
  import { FF_Role } from '../';
9
9
  import { RemultLuciaAdapter } from './Adapter';
10
10
  import { AuthControllerServer } from './AuthController.server';
11
- import { Auth } from './client';
12
- import { FF_Auth_Role, FFAuthAccount, FFAuthProvider, FFAuthUser, FFAuthUserSession, } from './Entities';
13
- import { createSession } from './helper';
11
+ import { Auth, logAuth } from './client';
12
+ import { FF_Auth_Role, FFAuthAccount, FFAuthProvider, FFAuthUser, FFAuthUserSession, } from './client/Entities';
13
+ import { createOrExtendSession } from './helper';
14
14
  import { initRoleFromEnv } from './RoleHelpers';
15
- export { FFAuthUser, FFAuthAccount, FFAuthProvider, FFAuthUserSession };
16
- export const logAuth = new Log('firstly | auth');
17
- export { FF_Auth_Role } from './Entities';
18
15
  export let AUTH_OPTIONS = { ui: {} };
19
16
  const buildUrlOrDefault = (base, userSetting, fallback) => {
20
- if (userSetting) {
21
- return `${base}/${userSetting}`;
17
+ if (userSetting === false) {
18
+ return false;
22
19
  }
23
- return `${base}/${fallback}`;
20
+ if (userSetting === undefined) {
21
+ return `${base}/${fallback}`;
22
+ }
23
+ return `${base}/${userSetting}`;
24
24
  };
25
25
  export const getSafeOptions = () => {
26
26
  const signUp = AUTH_OPTIONS.signUp ?? true;
27
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
- // }) ?? []
32
28
  const firstlyData = {
33
29
  module: 'auth',
34
30
  debug: AUTH_OPTIONS.debug,
@@ -48,6 +44,8 @@ export const getSafeOptions = () => {
48
44
  email: AUTH_OPTIONS.ui?.strings?.email ?? 'Email',
49
45
  email_placeholder: AUTH_OPTIONS.ui?.strings?.email_placeholder ?? 'Your email address',
50
46
  password: AUTH_OPTIONS.ui?.strings?.password ?? 'Password',
47
+ confirm: AUTH_OPTIONS.ui?.strings?.confirm ?? 'Confirm',
48
+ reset: AUTH_OPTIONS.ui?.strings?.reset ?? 'Reset',
51
49
  btn_sign_up: AUTH_OPTIONS.ui?.strings?.btn_sign_up ?? 'Sign up',
52
50
  btn_sign_in: AUTH_OPTIONS.ui?.strings?.btn_sign_in ?? 'Sign in',
53
51
  forgot_password: AUTH_OPTIONS.ui?.strings?.forgot_password ?? 'Forgot your password?',
@@ -58,11 +56,45 @@ export const getSafeOptions = () => {
58
56
  },
59
57
  },
60
58
  };
59
+ let uiStaticPath = AUTH_OPTIONS.uiStaticPath ?? '';
60
+ if (!AUTH_OPTIONS.uiStaticPath) {
61
+ const installedFirstlyPath = getRelativePackagePath('firstly');
62
+ if (installedFirstlyPath) {
63
+ uiStaticPath = `${installedFirstlyPath}/esm/auth/static/`;
64
+ }
65
+ }
61
66
  let redirectUrl = AUTH_OPTIONS.defaultRedirect ?? '/';
62
67
  if (!redirectUrl.startsWith('/')) {
63
68
  logAuth.error(`Invalid redirect url ${red(redirectUrl)} (it should be a local one starting with /)`);
64
69
  redirectUrl = '/';
65
70
  }
71
+ let transformDbUserToClientUserToUse;
72
+ if (AUTH_OPTIONS.transformDbUserToClientUser) {
73
+ transformDbUserToClientUserToUse = AUTH_OPTIONS.transformDbUserToClientUser;
74
+ }
75
+ else {
76
+ // Need in src/app.d.ts this code to be able to have the correct transformDbUserToClientUser returned type.
77
+ // In the lib, let's force to this default
78
+ /**
79
+ * declare module 'remult' {
80
+ * export interface UserInfo {
81
+ * specificThing: string
82
+ * }
83
+ * }
84
+ */
85
+ // @ts-ignore
86
+ transformDbUserToClientUserToUse = (session, user) => {
87
+ return {
88
+ id: user.id,
89
+ name: user.identifier,
90
+ roles: user.roles,
91
+ session: {
92
+ id: session.id,
93
+ expiresAt: session.expiresAt,
94
+ },
95
+ };
96
+ };
97
+ }
66
98
  return {
67
99
  User: AUTH_OPTIONS.customEntities?.User ?? FFAuthUser,
68
100
  Session: AUTH_OPTIONS.customEntities?.Session ?? FFAuthUserSession,
@@ -73,6 +105,8 @@ export const getSafeOptions = () => {
73
105
  verifiedMethod: AUTH_OPTIONS.verifiedMethod ?? 'auto',
74
106
  redirectUrl,
75
107
  firstlyData,
108
+ transformDbUserToClientUser: transformDbUserToClientUserToUse,
109
+ uiStaticPath,
76
110
  };
77
111
  };
78
112
  /**
@@ -93,6 +127,23 @@ export const auth = (o) => {
93
127
  Auth.signInOTPFn = AuthControllerServer.signInOTP;
94
128
  Auth.verifyOtpFn = AuthControllerServer.verifyOtp;
95
129
  Auth.signInOAuthGetUrlFn = AuthControllerServer.signInOAuthGetUrl;
130
+ const adapter = new RemultLuciaAdapter();
131
+ const defaultExpiresIn = 60 * 60 * 24 * 30; // 30 days
132
+ const sessionExpiresIn = new TimeSpan(AUTH_OPTIONS.sessionExpiresIn ?? defaultExpiresIn, 's');
133
+ lucia = new Lucia(adapter, {
134
+ sessionExpiresIn,
135
+ sessionCookie: {
136
+ name: AUTH_OPTIONS.sessionCookie?.name ?? 'firstly_auth_session',
137
+ expires: AUTH_OPTIONS.sessionCookie?.expires,
138
+ attributes: {
139
+ // set to `true` when using HTTPS
140
+ secure: !DEV,
141
+ ...AUTH_OPTIONS.sessionCookie?.attributes,
142
+ },
143
+ },
144
+ getSessionAttributes: (attributes) => attributes,
145
+ getUserAttributes: (attributes) => attributes,
146
+ });
96
147
  return {
97
148
  name: 'auth',
98
149
  index: -777,
@@ -104,19 +155,12 @@ export const auth = (o) => {
104
155
  if (sessionId) {
105
156
  const { session, user } = await lucia.validateSession(sessionId);
106
157
  if (session && session.fresh) {
107
- const sessionCookie = lucia.createSessionCookie(session.id);
108
- event.cookies.set(sessionCookie.name, sessionCookie.value, {
109
- path: '/',
110
- ...sessionCookie.attributes,
111
- });
158
+ await createOrExtendSession(session.id, session);
112
159
  }
113
160
  remult.user = user ?? undefined;
114
161
  }
115
162
  },
116
163
  earlyReturn: async ({ event, resolve }) => {
117
- // if (AUTH_OPTIONS.ui === false) {
118
- // return { early: false }
119
- // }
120
164
  const oSafe = getSafeOptions();
121
165
  if (event.url.pathname === oSafe.firstlyData.props.ui?.paths?.verify_email) {
122
166
  const token = event.url.searchParams.get('token') ?? '';
@@ -138,19 +182,12 @@ export const auth = (o) => {
138
182
  account.expiresAt = undefined;
139
183
  account.lastVerifiedAt = new Date();
140
184
  await remult.repo(oSafe.Account).save(account);
141
- await createSession(account.userId);
185
+ await createOrExtendSession(account.userId);
142
186
  redirect(302, oSafe.redirectUrl);
143
187
  }
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
188
  if (oSafe.firstlyData.props.ui?.paths?.base &&
152
189
  event.url.pathname.startsWith(oSafe.firstlyData.props.ui.paths.base)) {
153
- const content = read(`${staticPath}index.html`);
190
+ const content = read(`${oSafe.uiStaticPath}index.html`);
154
191
  return {
155
192
  early: true,
156
193
  resolve: new Response(content + `<script>const firstlyData = ${JSON.stringify(oSafe.firstlyData)}</script>`, {
@@ -159,7 +196,7 @@ export const auth = (o) => {
159
196
  };
160
197
  }
161
198
  if (event.url.pathname.startsWith('/api/static')) {
162
- const content = read(`${staticPath}${event.url.pathname.replaceAll('/api/static/', '')}`);
199
+ const content = read(`${oSafe.uiStaticPath}${event.url.pathname.replaceAll('/api/static/', '')}`);
163
200
  if (content) {
164
201
  const seg = event.url.pathname.split('.');
165
202
  const map = {
@@ -250,7 +287,7 @@ export const auth = (o) => {
250
287
  account.token = tokens.accessToken;
251
288
  await remult.repo(oSafe.Account).save(account);
252
289
  }
253
- await createSession(account.userId);
290
+ await createOrExtendSession(account.userId);
254
291
  event.cookies.delete(`${keyState}_oauth_state`, { path: '/' });
255
292
  event.cookies.delete(`code_verifier`, { path: '/' });
256
293
  }
@@ -264,38 +301,5 @@ export const auth = (o) => {
264
301
  },
265
302
  };
266
303
  };
267
- const adapter = new RemultLuciaAdapter();
268
- const defaultExpiresIn = 60 * 60 * 24 * 15; // 15 days
269
- export const lucia = new Lucia(adapter, {
270
- sessionExpiresIn: new TimeSpan(AUTH_OPTIONS.sessionExpiresIn ?? defaultExpiresIn, 's'),
271
- sessionCookie: {
272
- name: AUTH_OPTIONS.sessionCookie?.name ?? 'remult_auth_session',
273
- expires: AUTH_OPTIONS.sessionCookie?.expires,
274
- attributes: {
275
- // set to `true` when using HTTPS
276
- secure: !DEV,
277
- ...AUTH_OPTIONS.sessionCookie?.attributes,
278
- },
279
- },
280
- getSessionAttributes: (attributes) => {
281
- return {
282
- ...attributes,
283
- };
284
- },
285
- getUserAttributes(attributes) {
286
- // @ts-expect-error
287
- delete attributes['createdAt'];
288
- // @ts-expect-error
289
- delete attributes['updatedAt'];
290
- // to remove relations
291
- for (const key in attributes) {
292
- if (attributes[key] === undefined) {
293
- delete attributes[key];
294
- }
295
- }
296
- return attributes;
297
- // return {
298
- // ...attributes,
299
- // }
300
- },
301
- });
304
+ // Maybe moving this to /auth/server.ts would be better, people will be able to import from firstly all the time
305
+ export let lucia;
@@ -2,7 +2,8 @@ import { GitHub } from 'arctic';
2
2
  import { remult } from 'remult';
3
3
  import { env } from '$env/dynamic/private';
4
4
  import { checkOAuthConfig } from '.';
5
- import { logAuth } from '../';
5
+ import {} from '../';
6
+ import { logAuth } from '../client';
6
7
  //------------------------------
7
8
  // For developers (future me ?), To do another OAuth2 provider:
8
9
  // Replace GITHUB / Github / github
@@ -1,6 +1,6 @@
1
1
  import { cyan, gray, green, italic, yellow } from '@kitql/helpers';
2
- import { logAuth } from '..';
3
2
  import { mask } from '../../formats/strings';
3
+ import { logAuth } from '../client';
4
4
  export const checkOAuthConfig = (name, clientId, secret, urlForKeys, withThrow) => {
5
5
  if (!clientId || !secret) {
6
6
  const msg = `Wrong configuration for ${green(name)} provider.
@@ -2,7 +2,8 @@ import { Strava } from 'arctic';
2
2
  import { remult } from 'remult';
3
3
  import { env } from '$env/dynamic/private';
4
4
  import { checkOAuthConfig } from '.';
5
- import { logAuth } from '../';
5
+ import {} from '../';
6
+ import { logAuth } from '../client';
6
7
  /**
7
8
  * ## Strava OAuth2 provider
8
9
  *
@@ -1,4 +1,4 @@
1
1
  export { v as default };
2
2
  declare class v extends l {
3
3
  }
4
- import { S as l } from "./index-qfq98Nyd.js";
4
+ import { S as l } from "./index-QypqCYwC.js";
@@ -1 +1 @@
1
- import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-qfq98Nyd.js";function c(s){let e;const n={c:function(){e=p("Hello from admin")},l:function(t){throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option")},m:function(t,o){u(t,e,o)},p:r,i:r,o:r,d:function(t){t&&h(e)}};return i("SvelteRegisterBlock",{block:n,id:c.name,type:"component",source:"",ctx:s}),n}function w(s,e){let{$$slots:n={},$$scope:a}=e;m("Page",n,[]);const t=[];return Object.keys(e).forEach(o=>{!~t.indexOf(o)&&o.slice(0,2)!=="$$"&&o!=="slot"&&console.warn(`<Page> was created with unknown prop '${o}'`)}),[]}class v extends l{constructor(e){super(e),d(this,e,w,c,f,{}),i("SvelteRegisterComponent",{component:this,tagName:"Page",options:e,id:c.name})}}export{v as default};
1
+ import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-QypqCYwC.js";function c(s){let e;const n={c:function(){e=p("Hello from admin")},l:function(t){throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option")},m:function(t,o){u(t,e,o)},p:r,i:r,o:r,d:function(t){t&&h(e)}};return i("SvelteRegisterBlock",{block:n,id:c.name,type:"component",source:"",ctx:s}),n}function w(s,e){let{$$slots:n={},$$scope:a}=e;m("Page",n,[]);const t=[];return Object.keys(e).forEach(o=>{!~t.indexOf(o)&&o.slice(0,2)!=="$$"&&o!=="slot"&&console.warn(`<Page> was created with unknown prop '${o}'`)}),[]}class v extends l{constructor(e){super(e),d(this,e,w,c,f,{}),i("SvelteRegisterComponent",{component:this,tagName:"Page",options:e,id:c.name})}}export{v as default};
@@ -0,0 +1,6 @@
1
+ export { Ca as default };
2
+ declare class Ca extends Ye {
3
+ set firstlyData(e: void);
4
+ get firstlyData(): void;
5
+ }
6
+ import { S as Ye } from "./index-QypqCYwC.js";