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.
Files changed (88) hide show
  1. package/CHANGELOG.md +21 -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.d.ts +3 -1
  9. package/esm/ROUTES.js +2 -1
  10. package/esm/SqlDatabase/FF_LogToConsole.d.ts +1 -0
  11. package/esm/SqlDatabase/{LogToConsoleCustom.js → FF_LogToConsole.js} +1 -1
  12. package/esm/api/index.d.ts +2 -1
  13. package/esm/auth/AuthController.server.js +59 -18
  14. package/esm/auth/Entities.d.ts +18 -17
  15. package/esm/auth/Entities.js +66 -63
  16. package/esm/auth/RoleHelpers.d.ts +2 -2
  17. package/esm/auth/RoleHelpers.js +1 -1
  18. package/esm/auth/client/Auth.js +1 -1
  19. package/esm/auth/index.d.ts +14 -17
  20. package/esm/auth/index.js +59 -52
  21. package/esm/auth/providers/github.d.ts +22 -17
  22. package/esm/auth/providers/github.js +29 -15
  23. package/esm/auth/providers/strava.d.ts +22 -17
  24. package/esm/auth/providers/strava.js +23 -15
  25. package/esm/auth/static/assets/Page-BGTO8LC5.css +1 -0
  26. package/esm/auth/static/assets/Page-DBWJjlEQ.d.ts +4 -0
  27. package/esm/auth/static/assets/Page-DBWJjlEQ.js +1 -0
  28. package/esm/auth/static/assets/Page-RIbXHuZG.d.ts +4 -0
  29. package/esm/auth/static/assets/Page-RIbXHuZG.js +1 -0
  30. package/esm/auth/static/assets/Page-apb_xgZT.d.ts +6 -0
  31. package/esm/auth/static/assets/Page-apb_xgZT.js +18 -0
  32. package/esm/auth/static/assets/{index-R27C_TlP.css → index-CR_3yNaJ.css} +1 -1
  33. package/esm/auth/static/assets/index-qfq98Nyd.d.ts +63 -0
  34. package/esm/auth/static/assets/index-qfq98Nyd.js +2 -0
  35. package/esm/auth/static/index.html +2 -2
  36. package/esm/auth/types.d.ts +16 -22
  37. package/esm/bin/cmd.js +181 -83
  38. package/esm/{kitCellsBuildor.d.ts → cellsBuildor.d.ts} +9 -9
  39. package/esm/{kitCellsBuildor.js → cellsBuildor.js} +9 -9
  40. package/esm/feedback/ui/DialogIssue.svelte +2 -2
  41. package/esm/formats/dates.js +2 -2
  42. package/esm/handle/index.d.ts +1 -0
  43. package/esm/helper.d.ts +8 -10
  44. package/esm/helper.js +13 -8
  45. package/esm/index.d.ts +38 -49
  46. package/esm/index.js +30 -27
  47. package/esm/mail/index.d.ts +23 -4
  48. package/esm/mail/index.js +38 -15
  49. package/esm/mail/templates/DefaultMail.svelte +66 -0
  50. package/esm/mail/templates/DefaultMail.svelte.d.ts +28 -0
  51. package/esm/{kitStoreItem.d.ts → storeItem.d.ts} +1 -1
  52. package/esm/{kitStoreItem.js → storeItem.js} +1 -1
  53. package/esm/{kitStoreList.d.ts → storeList.d.ts} +4 -4
  54. package/esm/{kitStoreList.js → storeList.js} +1 -1
  55. package/esm/ui/Button.svelte +1 -1
  56. package/esm/ui/Button.svelte.d.ts +2 -2
  57. package/esm/ui/Field.svelte.d.ts +2 -2
  58. package/esm/ui/FieldGroup.svelte +2 -2
  59. package/esm/ui/FieldGroup.svelte.d.ts +4 -4
  60. package/esm/ui/Grid.svelte.d.ts +5 -5
  61. package/esm/ui/dialog/DialogForm.svelte +4 -4
  62. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +2 -2
  63. package/esm/ui/dialog/FormEditAction.svelte.d.ts +2 -2
  64. package/esm/ui/dialog/dialog.d.ts +5 -5
  65. package/esm/ui/index.d.ts +2 -2
  66. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +3 -3
  67. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +3 -3
  68. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +2 -2
  69. package/esm/ui/link/LinkPlus.svelte.d.ts +2 -2
  70. package/esm/utils/types.d.ts +3 -15
  71. package/esm/utils/types.js +1 -17
  72. package/esm/virtual/Customer.js +2 -2
  73. package/esm/virtual/FilterEntity.js +1 -1
  74. package/esm/virtual/StateDemoEnum.d.ts +4 -4
  75. package/esm/virtual/StateDemoEnum.js +2 -2
  76. package/esm/virtual/UIEntity.js +4 -4
  77. package/esm/vite/index.js +1 -1
  78. package/package.json +5 -3
  79. package/esm/SqlDatabase/LogToConsoleCustom.d.ts +0 -1
  80. package/esm/auth/static/assets/Page-BYzkK4q3.d.ts +0 -5
  81. package/esm/auth/static/assets/Page-BYzkK4q3.js +0 -1
  82. package/esm/auth/static/assets/Page-ByIhtXVt.d.ts +0 -5
  83. package/esm/auth/static/assets/Page-ByIhtXVt.js +0 -18
  84. package/esm/auth/static/assets/Page-Do7F0Mzd.d.ts +0 -5
  85. package/esm/auth/static/assets/Page-Do7F0Mzd.js +0 -1
  86. package/esm/auth/static/assets/Page-gV58jf2r.css +0 -1
  87. package/esm/auth/static/assets/index-czJ1PA1n.d.ts +0 -53
  88. package/esm/auth/static/assets/index-czJ1PA1n.js +0 -2
@@ -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 AuthProvider_1;
7
+ var FFAuthProvider_1;
8
8
  import { Entity, Fields, Relations, Validators, ValueListFieldType } from 'remult';
9
- import { KitBaseEnum, KitRole } from '../';
10
- export const KitAuthRole = {
11
- Admin: 'KitAuthAdmin',
9
+ import { BaseEnum, FF_Role } from '../';
10
+ export const FF_Auth_Role = {
11
+ Admin: 'FF_Auth_Role.Admin',
12
12
  };
13
- let KitAuthUser = class KitAuthUser {
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
- ], KitAuthUser.prototype, "id", void 0);
24
+ ], FFAuthUser.prototype, "id", void 0);
26
25
  __decorate([
27
26
  Fields.createdAt()
28
- ], KitAuthUser.prototype, "createdAt", void 0);
27
+ ], FFAuthUser.prototype, "createdAt", void 0);
29
28
  __decorate([
30
29
  Fields.updatedAt()
31
- ], KitAuthUser.prototype, "updatedAt", void 0);
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
- ], KitAuthUser.prototype, "name", void 0);
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
- ], KitAuthUser.prototype, "roles", void 0);
49
+ ], FFAuthUser.prototype, "roles", void 0);
51
50
  __decorate([
52
- Relations.toMany(() => KitAuthAccount, 'userId')
53
- ], KitAuthUser.prototype, "accounts", void 0);
51
+ Relations.toMany(() => FFAuthAccount, 'userId')
52
+ ], FFAuthUser.prototype, "accounts", void 0);
54
53
  __decorate([
55
- Relations.toMany(() => KitAuthUserSession, 'userId')
56
- ], KitAuthUser.prototype, "sessions", void 0);
57
- KitAuthUser = __decorate([
58
- Entity('kit_auth_user', {
59
- allowApiCrud: [KitAuthRole.Admin, KitRole.Admin],
60
- dbName: 'auth.kit_auth_user',
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
- ], KitAuthUser);
63
- export { KitAuthUser };
64
- let KitAuthAccount = class KitAuthAccount {
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 = AuthProvider.PASSWORD.id;
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
- ], KitAuthAccount.prototype, "createdAt", void 0);
81
+ ], FFAuthAccount.prototype, "createdAt", void 0);
79
82
  __decorate([
80
83
  Fields.updatedAt()
81
- ], KitAuthAccount.prototype, "updatedAt", void 0);
84
+ ], FFAuthAccount.prototype, "updatedAt", void 0);
82
85
  __decorate([
83
86
  Fields.string()
84
- ], KitAuthAccount.prototype, "userId", void 0);
87
+ ], FFAuthAccount.prototype, "userId", void 0);
85
88
  __decorate([
86
- Relations.toOne(() => KitAuthUser, 'userId')
87
- ], KitAuthAccount.prototype, "user", void 0);
89
+ Relations.toOne(() => FFAuthUser, 'userId')
90
+ ], FFAuthAccount.prototype, "user", void 0);
88
91
  __decorate([
89
92
  Fields.string()
90
- ], KitAuthAccount.prototype, "provider", void 0);
93
+ ], FFAuthAccount.prototype, "provider", void 0);
91
94
  __decorate([
92
95
  Fields.string()
93
- ], KitAuthAccount.prototype, "providerUserId", void 0);
96
+ ], FFAuthAccount.prototype, "providerUserId", void 0);
94
97
  __decorate([
95
98
  Fields.string({ includeInApi: false, allowNull: true })
96
- ], KitAuthAccount.prototype, "hashPassword", void 0);
99
+ ], FFAuthAccount.prototype, "hashPassword", void 0);
97
100
  __decorate([
98
101
  Fields.string({ includeInApi: false, allowNull: true })
99
- ], KitAuthAccount.prototype, "token", void 0);
102
+ ], FFAuthAccount.prototype, "token", void 0);
100
103
  __decorate([
101
104
  Fields.date({ includeInApi: false, allowNull: true })
102
- ], KitAuthAccount.prototype, "expiresAt", void 0);
105
+ ], FFAuthAccount.prototype, "expiresAt", void 0);
103
106
  __decorate([
104
107
  Fields.date({ includeInApi: false, allowNull: true })
105
- ], KitAuthAccount.prototype, "lastVerifiedAt", void 0);
106
- KitAuthAccount = __decorate([
107
- Entity('kit_auth_account', {
108
- allowApiCrud: [KitAuthRole.Admin, KitRole.Admin],
109
- dbName: 'auth.kit_auth_account',
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
- ], KitAuthAccount);
113
- export { KitAuthAccount };
114
- let KitAuthUserSession = class KitAuthUserSession {
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
- ], KitAuthUserSession.prototype, "id", void 0);
125
+ ], FFAuthUserSession.prototype, "id", void 0);
123
126
  __decorate([
124
127
  Fields.date()
125
- ], KitAuthUserSession.prototype, "expiresAt", void 0);
128
+ ], FFAuthUserSession.prototype, "expiresAt", void 0);
126
129
  __decorate([
127
130
  Fields.string()
128
- ], KitAuthUserSession.prototype, "userId", void 0);
129
- __decorate([
130
- Relations.toOne(() => KitAuthUser, 'userId')
131
- ], KitAuthUserSession.prototype, "user", void 0);
132
- KitAuthUserSession = __decorate([
133
- Entity('kit_auth_session', {
134
- allowApiCrud: [KitAuthRole.Admin, KitRole.Admin],
135
- dbName: 'auth.kit_auth_session',
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
- ], KitAuthUserSession);
138
- export { KitAuthUserSession };
139
- let AuthProvider = class AuthProvider extends KitBaseEnum {
140
- static { AuthProvider_1 = this; }
141
- static DEMO = new AuthProvider_1('DEMO', { caption: 'Demo' });
142
- static PASSWORD = new AuthProvider_1('PASSWORD', { caption: 'Password' });
143
- static OTP = new AuthProvider_1('OTP', { caption: 'TOTP' });
144
- static OAUTH = new AuthProvider_1('OAUTH', { caption: 'OAUTH' });
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
- AuthProvider = AuthProvider_1 = __decorate([
154
+ FFAuthProvider = FFAuthProvider_1 = __decorate([
152
155
  ValueListFieldType()
153
- ], AuthProvider);
154
- export { AuthProvider };
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 { KitAuthUser } from './Entities';
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<KitAuthUser>, envValue: string, role: string) => Promise<void>;
12
+ export declare const initRoleFromEnv: (log: Log, userEntity: ClassType<FFAuthUser>, envValue: string | undefined, role: string) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { repo } from 'remult';
2
2
  import { cyan, green, Log, yellow } from '@kitql/helpers';
3
- import { KitAuthUser } from './Entities';
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
@@ -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.provider, o.options, o.redirect);
89
+ return await Auth.signInOAuthGetUrlFn(o);
90
90
  }
91
91
  }
92
92
  __decorate([
@@ -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 { AuthProvider, KitAuthAccount, KitAuthUser, KitAuthUserSession } from './Entities';
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 { KitAuthUser, KitAuthAccount, AuthProvider, KitAuthUserSession };
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 KitOAuth2Provider[] = KitOAuth2Provider[]> = T extends Array<infer O> ? O extends KitOAuth2Provider ? {
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 { KitAuthRole } from './Entities';
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 KitOAuth2Provider<LitName extends string = string, T extends ArcticOAuth2Provider | ArcticOAuth2ProviderWithPKCE = ArcticOAuth2Provider> = {
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 KitAuthUser = KitAuthUser, TSessionEntity extends KitAuthUserSession = KitAuthUserSession, TAccountEntity extends KitAuthAccount = KitAuthAccount> = {
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
- ui?: {
39
- paths?: {
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?: KitOAuth2Provider[];
111
+ oAuths?: FFOAuth2Provider[];
115
112
  };
116
113
  };
117
114
  export declare let AUTH_OPTIONS: AuthOptions;
118
115
  export declare const getSafeOptions: () => {
119
- User: ClassType<KitAuthUser>;
120
- Session: ClassType<KitAuthUserSession>;
121
- Account: ClassType<KitAuthAccount>;
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 { 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 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 ?? '/fly/auth';
21
- const oAuths = AUTH_OPTIONS.providers?.oAuths?.map((o) => {
22
- return o.name;
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
- paths: {
29
- base,
30
- },
31
- providers: {
32
- password: {
33
- dico: {
34
- email: 'Email',
35
- email_placeholder: 'Your email address',
36
- password: 'Password',
37
- btn_sign_up: 'Sign up',
38
- btn_sign_in: 'Sign in',
39
- forgot_password: 'Forgot your password?',
40
- send_password_reset_instructions: 'Send password reset instructions',
41
- back_to_sign_in: 'Back to sign in',
42
- },
43
- paths: {
44
- sign_up: signUp ? `${base}/sign-up` : false,
45
- sign_in: `${base}/sign-in`,
46
- forgot_password: `${base}/forgot-password`,
47
- reset_password: `${base}/reset-password`,
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 ?? KitAuthUser,
63
- Session: AUTH_OPTIONS.customEntities?.Session ?? KitAuthUserSession,
64
- Account: AUTH_OPTIONS.customEntities?.Account ?? KitAuthAccount,
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
- return { early: false };
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.providers.password.paths.verify_email) {
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: AuthProvider.PASSWORD.id });
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
- // 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?!?
144
- if (event.url.pathname.startsWith(oSafe.firstlyData.props.ui.paths.base)) {
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
- // 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);
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 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
  },