firstly 0.0.4 → 0.0.5

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 (64) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/esm/{KitBaseEnum.d.ts → BaseEnum.d.ts} +18 -9
  3. package/esm/{KitBaseEnum.js → BaseEnum.js} +2 -13
  4. package/esm/{KitEntity.d.ts → FF_Entity.d.ts} +1 -1
  5. package/esm/{KitEntity.js → FF_Entity.js} +9 -9
  6. package/esm/{KitFields.d.ts → FF_Fields.d.ts} +2 -3
  7. package/esm/{KitFields.js → FF_Fields.js} +13 -9
  8. package/esm/ROUTES.js +1 -1
  9. package/esm/SqlDatabase/FF_LogToConsole.d.ts +1 -0
  10. package/esm/SqlDatabase/{LogToConsoleCustom.js → FF_LogToConsole.js} +1 -1
  11. package/esm/api/index.d.ts +1 -0
  12. package/esm/auth/AuthController.server.js +9 -9
  13. package/esm/auth/Entities.d.ts +18 -17
  14. package/esm/auth/Entities.js +66 -63
  15. package/esm/auth/RoleHelpers.d.ts +2 -2
  16. package/esm/auth/RoleHelpers.js +1 -1
  17. package/esm/auth/client/Auth.js +1 -1
  18. package/esm/auth/index.d.ts +10 -10
  19. package/esm/auth/index.js +20 -18
  20. package/esm/auth/providers/github.d.ts +22 -17
  21. package/esm/auth/providers/github.js +29 -15
  22. package/esm/auth/providers/strava.d.ts +22 -17
  23. package/esm/auth/providers/strava.js +23 -15
  24. package/esm/auth/static/assets/Page-ByIhtXVt.d.ts +1 -1
  25. package/esm/auth/static/assets/Page-ByIhtXVt.js +8178 -6
  26. package/esm/bin/cmd.js +181 -83
  27. package/esm/{kitCellsBuildor.d.ts → cellsBuildor.d.ts} +9 -9
  28. package/esm/{kitCellsBuildor.js → cellsBuildor.js} +8 -8
  29. package/esm/feedback/ui/DialogIssue.svelte +2 -2
  30. package/esm/formats/dates.js +2 -2
  31. package/esm/handle/index.d.ts +1 -0
  32. package/esm/helper.d.ts +8 -10
  33. package/esm/helper.js +13 -8
  34. package/esm/index.d.ts +37 -49
  35. package/esm/index.js +29 -27
  36. package/esm/{kitStoreItem.d.ts → storeItem.d.ts} +1 -1
  37. package/esm/{kitStoreItem.js → storeItem.js} +1 -1
  38. package/esm/{kitStoreList.d.ts → storeList.d.ts} +4 -4
  39. package/esm/{kitStoreList.js → storeList.js} +1 -1
  40. package/esm/ui/Button.svelte +1 -1
  41. package/esm/ui/Button.svelte.d.ts +2 -2
  42. package/esm/ui/Field.svelte.d.ts +2 -2
  43. package/esm/ui/FieldGroup.svelte +2 -2
  44. package/esm/ui/FieldGroup.svelte.d.ts +4 -4
  45. package/esm/ui/Grid.svelte.d.ts +5 -5
  46. package/esm/ui/dialog/DialogForm.svelte +4 -4
  47. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +2 -2
  48. package/esm/ui/dialog/FormEditAction.svelte.d.ts +2 -2
  49. package/esm/ui/dialog/dialog.d.ts +5 -5
  50. package/esm/ui/index.d.ts +2 -2
  51. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +3 -3
  52. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +3 -3
  53. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +2 -2
  54. package/esm/ui/link/LinkPlus.svelte.d.ts +2 -2
  55. package/esm/utils/types.d.ts +0 -15
  56. package/esm/utils/types.js +1 -17
  57. package/esm/virtual/Customer.js +2 -2
  58. package/esm/virtual/FilterEntity.js +1 -1
  59. package/esm/virtual/StateDemoEnum.d.ts +4 -4
  60. package/esm/virtual/StateDemoEnum.js +2 -2
  61. package/esm/virtual/UIEntity.js +4 -4
  62. package/esm/vite/index.js +1 -1
  63. package/package.json +4 -3
  64. package/esm/SqlDatabase/LogToConsoleCustom.d.ts +0 -1
package/esm/auth/index.js CHANGED
@@ -3,21 +3,22 @@ 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 { KitRole } from '../';
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 { AuthProvider, KitAuthAccount, KitAuthRole, KitAuthUser, KitAuthUserSession, } from './Entities';
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 { KitAuthUser, KitAuthAccount, AuthProvider, KitAuthUserSession };
15
+ export { FFAuthUser, FFAuthAccount, FFAuthProvider, FFAuthUserSession };
15
16
  export const logAuth = new Log('firstly | auth');
16
- export { KitAuthRole } from './Entities';
17
+ export { FF_Auth_Role } from './Entities';
17
18
  export let AUTH_OPTIONS = {};
18
19
  export const getSafeOptions = () => {
19
20
  const signUp = AUTH_OPTIONS.signUp ?? true;
20
- const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : AUTH_OPTIONS.ui?.paths?.base ?? '/fly/auth';
21
+ const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : AUTH_OPTIONS.ui?.paths?.base ?? '/ff/auth';
21
22
  const oAuths = AUTH_OPTIONS.providers?.oAuths?.map((o) => {
22
23
  return o.name;
23
24
  }) ?? [];
@@ -59,9 +60,9 @@ export const getSafeOptions = () => {
59
60
  redirectUrl = '/';
60
61
  }
61
62
  return {
62
- User: AUTH_OPTIONS.customEntities?.User ?? KitAuthUser,
63
- Session: AUTH_OPTIONS.customEntities?.Session ?? KitAuthUserSession,
64
- Account: AUTH_OPTIONS.customEntities?.Account ?? KitAuthAccount,
63
+ User: AUTH_OPTIONS.customEntities?.User ?? FFAuthUser,
64
+ Session: AUTH_OPTIONS.customEntities?.Session ?? FFAuthUserSession,
65
+ Account: AUTH_OPTIONS.customEntities?.Account ?? FFAuthAccount,
65
66
  signUp,
66
67
  password_enabled: AUTH_OPTIONS.providers?.password ? true : false,
67
68
  otp_enabled: AUTH_OPTIONS.providers?.otp ? true : false,
@@ -120,7 +121,7 @@ export const auth = (o) => {
120
121
  }
121
122
  const account = await remult
122
123
  .repo(oSafe.Account)
123
- .findFirst({ token, provider: AuthProvider.PASSWORD.id });
124
+ .findFirst({ token, provider: FFAuthProvider.PASSWORD.id });
124
125
  if (!account) {
125
126
  throw new Error('Invalid token');
126
127
  }
@@ -136,11 +137,13 @@ export const auth = (o) => {
136
137
  await createSession(account.userId);
137
138
  redirect(302, oSafe.redirectUrl);
138
139
  }
139
- // When building firstly...
140
- // let staticPath = './src/lib/auth/static/'
141
- // For users...
142
- const staticPath = './node_modules/firstly/esm/auth/static/';
143
- // TODO: We can't use `DEV` switch because users are also in DEV mode... Maybe we should check if files exist?!?
140
+ // For lib author (us), it's good to have this local path.
141
+ let staticPath = './src/lib/auth/static/';
142
+ // For users, let's serve the static files from the installed package
143
+ const installedFirstlyPath = getRelativePackagePath('firstly');
144
+ if (installedFirstlyPath) {
145
+ staticPath = `${installedFirstlyPath}/esm/auth/static/`;
146
+ }
144
147
  if (event.url.pathname.startsWith(oSafe.firstlyData.props.ui.paths.base)) {
145
148
  const content = read(`${staticPath}index.html`);
146
149
  return {
@@ -251,9 +254,8 @@ export const auth = (o) => {
251
254
  return { early: false };
252
255
  },
253
256
  initApi: async () => {
254
- // Todo... need to pass env to options
255
- await initRoleFromEnv(logAuth, oSafe.User, 'KIT_ADMIN', KitRole.Admin);
256
- await initRoleFromEnv(logAuth, oSafe.User, 'KIT_AUTH_ADMIN', KitAuthRole.Admin);
257
+ await initRoleFromEnv(logAuth, oSafe.User, env.FF_ADMIN, FF_Role.Admin);
258
+ await initRoleFromEnv(logAuth, oSafe.User, env.FF_AUTH_ADMIN, FF_Auth_Role.Admin);
257
259
  },
258
260
  };
259
261
  };
@@ -1,25 +1,30 @@
1
1
  import { GitHub } from 'arctic';
2
- import { type KitOAuth2Provider } from '../';
2
+ import { type FFOAuth2Provider } from '../';
3
3
  /**
4
- * GitHub OAuth2 provider
4
+ * ## GitHub OAuth2 provider
5
5
  *
6
- * In GitHub, set your callback url to
7
- * - dev: `http://localhost:5173/api/auth_callback`
8
- * - prod: `https://MY_SUPER_SITE/api/auth_callback`
9
- *
10
- * In your project add a `.env` file with the following:
11
- *
12
- * ```env
13
- * GITHUB_CLIENT_ID= 'your-client-id'
14
- * GITHUB_CLIENT_SECRET= 'your-client-secret'
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
- * _FYI: GITHUB_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
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: string;
21
- GITHUB_CLIENT_SECRET: string;
25
+ GITHUB_CLIENT_ID?: string;
26
+ GITHUB_CLIENT_SECRET?: string;
22
27
  GITHUB_REDIRECT_URI?: string;
23
- authorizationURLOptions?: ReturnType<KitOAuth2Provider<'github', GitHub>['authorizationURLOptions']>;
28
+ authorizationURLOptions?: ReturnType<FFOAuth2Provider<'github', GitHub>['authorizationURLOptions']>;
24
29
  log?: boolean;
25
- }): KitOAuth2Provider<'github', GitHub>;
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
- * In GitHub, set your callback url to
9
- * - dev: `http://localhost:5173/api/auth_callback`
10
- * - prod: `https://MY_SUPER_SITE/api/auth_callback`
11
- *
12
- * In your project add a `.env` file with the following:
13
- *
14
- * ```env
15
- * GITHUB_CLIENT_ID= 'your-client-id'
16
- * GITHUB_CLIENT_SECRET= 'your-client-secret'
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
- * _FYI: GITHUB_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
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 || `${remult.context.url.origin}/api/auth_callback`;
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
  },
@@ -1,25 +1,30 @@
1
1
  import { Strava } from 'arctic';
2
- import { type KitOAuth2Provider } from '../';
2
+ import { type FFOAuth2Provider } from '../';
3
3
  /**
4
- * Strava OAuth2 provider
4
+ * ## Strava OAuth2 provider
5
5
  *
6
- * In Strava, set your callback url to
7
- * - dev: `http://localhost:5173/api/auth_callback`
8
- * - prod: `https://MY_SUPER_SITE/api/auth_callback`
9
- *
10
- * In your project add a `.env` file with the following:
11
- *
12
- * ```env
13
- * STRAVA_CLIENT_ID= 'your-client-id'
14
- * STRAVA_CLIENT_SECRET= 'your-client-secret'
6
+ * 1. Get your **id** & **secret** from [Strava (direct link)](https://www.strava.com/settings/api).
7
+ * 2. In Strava, 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
+ * STRAVA_CLIENT_ID = 'your-client-id'
13
+ * STRAVA_CLIENT_SECRET = 'your-client-secret'
14
+ * # STRAVA_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
15
15
  * ```
16
- *
17
- * _FYI: STRAVA_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
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: 'strava', redirect: window.location.pathname })
20
+ * }
21
+ * ```
22
+ * 5. Enjoy 🥳
18
23
  */
19
24
  export declare function strava(options?: {
20
- STRAVA_CLIENT_ID: string;
21
- STRAVA_CLIENT_SECRET: string;
25
+ STRAVA_CLIENT_ID?: string;
26
+ STRAVA_CLIENT_SECRET?: string;
22
27
  STRAVA_REDIRECT_URI?: string;
23
- authorizationURLOptions?: ReturnType<KitOAuth2Provider<'strava', Strava>['authorizationURLOptions']>;
28
+ authorizationURLOptions?: ReturnType<FFOAuth2Provider<'strava', Strava>['authorizationURLOptions']>;
24
29
  log?: boolean;
25
- }): KitOAuth2Provider<'strava', Strava>;
30
+ }): FFOAuth2Provider<'strava', Strava>;
@@ -1,34 +1,42 @@
1
1
  import { Strava } 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 '../';
5
6
  /**
6
- * Strava OAuth2 provider
7
+ * ## Strava OAuth2 provider
7
8
  *
8
- * In Strava, set your callback url to
9
- * - dev: `http://localhost:5173/api/auth_callback`
10
- * - prod: `https://MY_SUPER_SITE/api/auth_callback`
11
- *
12
- * In your project add a `.env` file with the following:
13
- *
14
- * ```env
15
- * STRAVA_CLIENT_ID= 'your-client-id'
16
- * STRAVA_CLIENT_SECRET= 'your-client-secret'
9
+ * 1. Get your **id** & **secret** from [Strava (direct link)](https://www.strava.com/settings/api).
10
+ * 2. In Strava, set your callback url to
11
+ * - [ ] dev: `http://localhost:5173/api/auth_callback`
12
+ * - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
13
+ * 3. In your project add a `.env` file with the following:
14
+ * ```bash
15
+ * STRAVA_CLIENT_ID = 'your-client-id'
16
+ * STRAVA_CLIENT_SECRET = 'your-client-secret'
17
+ * # STRAVA_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
17
18
  * ```
18
- *
19
- * _FYI: STRAVA_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
19
+ * 4. In your frontend, under a button click call something like:
20
+ * ```ts
21
+ * async function oauth() {
22
+ * window.location.href = await Auth.signInOAuthGetUrl({ provider: 'strava', redirect: window.location.pathname })
23
+ * }
24
+ * ```
25
+ * 5. Enjoy 🥳
20
26
  */
21
27
  export function strava(options) {
22
28
  const name = 'strava';
23
- const clientID = options?.STRAVA_CLIENT_ID ?? '';
24
- const secret = options?.STRAVA_CLIENT_SECRET ?? '';
29
+ const clientID = options?.STRAVA_CLIENT_ID ?? env.STRAVA_CLIENT_ID ?? '';
30
+ const secret = options?.STRAVA_CLIENT_SECRET ?? env.STRAVA_CLIENT_SECRET ?? '';
25
31
  const urlForKeys = 'https://www.strava.com/settings/api';
26
32
  checkOAuthConfig(name, clientID, secret, urlForKeys, false);
27
33
  return {
28
34
  name,
29
35
  isPKCE: false,
30
36
  getArcticProvider: () => {
31
- const redirectURI = options?.STRAVA_REDIRECT_URI || `${remult.context.url.origin}/api/auth_callback`;
37
+ const redirectURI = options?.STRAVA_REDIRECT_URI ??
38
+ env.STRAVA_REDIRECT_URI ??
39
+ `${remult.context.url.origin}/api/auth_callback`;
32
40
  checkOAuthConfig(name, clientID, secret, urlForKeys, true);
33
41
  return new Strava(clientID, secret, redirectURI);
34
42
  },
@@ -2,4 +2,4 @@ export { oo as default };
2
2
  declare class oo extends Je {
3
3
  constructor(e: any);
4
4
  }
5
- import { S as Je } from "./index-czJ1PA1n.js";
5
+ import { S as Je } from './index-czJ1PA1n.js';