firstly 0.2.0 → 0.3.0

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 (135) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/esm/bin/cmd.js +3 -158
  3. package/esm/changeLog/index.d.ts +1 -6
  4. package/esm/feedback/FeedbackController.d.ts +6 -2
  5. package/esm/feedback/FeedbackController.js +145 -143
  6. package/esm/feedback/server/index.d.ts +2 -2
  7. package/esm/feedback/server/index.js +3 -3
  8. package/esm/feedback/types.d.ts +5 -0
  9. package/esm/feedback/ui/DialogIssue.svelte +5 -5
  10. package/esm/feedback/ui/DialogIssues.svelte +5 -5
  11. package/esm/feedback/ui/DialogMilestones.svelte +1 -1
  12. package/esm/internals/BaseEnum.d.ts +2 -1
  13. package/esm/internals/FF_Entity.js +1 -17
  14. package/esm/internals/FF_Fields.d.ts +4 -3
  15. package/esm/internals/FF_Fields.js +14 -55
  16. package/esm/internals/cellsBuildor.d.ts +2 -1
  17. package/esm/internals/cellsBuildor.js +5 -4
  18. package/esm/internals/index.d.ts +7 -12
  19. package/esm/internals/storeItem.d.ts +12 -20
  20. package/esm/internals/storeItem.js +20 -6
  21. package/esm/mail/server/index.d.ts +8 -2
  22. package/esm/mail/server/index.js +35 -7
  23. package/esm/server/index.d.ts +1 -1
  24. package/esm/svelte/FF_Cell.svelte +3 -5
  25. package/esm/svelte/FF_Cell.svelte.d.ts +4 -2
  26. package/esm/svelte/FF_Form.svelte +4 -5
  27. package/esm/svelte/FF_Grid.svelte +2 -2
  28. package/esm/svelte/FF_Layout.svelte +3 -3
  29. package/esm/svelte/FF_Repo.svelte.d.ts +9 -0
  30. package/esm/svelte/FF_Repo.svelte.js +39 -0
  31. package/esm/svelte/class/SP.svelte.js +14 -2
  32. package/esm/svelte/dialog/DialogManagement.svelte +2 -5
  33. package/esm/svelte/dialog/DialogPrimitive.svelte +1 -2
  34. package/esm/svelte/dialog/dialog.js +2 -2
  35. package/esm/svelte/ff_Config.svelte.js +2 -2
  36. package/esm/svelte/index.d.ts +2 -7
  37. package/esm/svelte/index.js +2 -7
  38. package/esm/ui/Button.svelte +34 -66
  39. package/esm/ui/Button.svelte.d.ts +9 -35
  40. package/esm/ui/Clipboardable.svelte +13 -17
  41. package/esm/ui/Clipboardable.svelte.d.ts +9 -33
  42. package/esm/ui/Field.svelte +48 -9
  43. package/esm/ui/FieldGroup.svelte.d.ts +1 -1
  44. package/esm/ui/Grid.svelte +13 -87
  45. package/esm/ui/Grid.svelte.d.ts +0 -1
  46. package/esm/ui/Grid2.svelte +26 -90
  47. package/esm/ui/Grid2.svelte.d.ts +1 -2
  48. package/esm/ui/GridPaginate.svelte +1 -1
  49. package/esm/ui/GridPaginate2.svelte +2 -2
  50. package/esm/ui/Icon.svelte +2 -18
  51. package/esm/ui/Icon.svelte.d.ts +0 -2
  52. package/esm/ui/LibIcon.js +2 -2
  53. package/esm/ui/Loading.svelte +1 -1
  54. package/esm/ui/dialog/DialogManagement.svelte +14 -5
  55. package/esm/ui/dialog/DialogPrimitive.svelte +3 -3
  56. package/esm/ui/dialog/FormEditAction.svelte +4 -4
  57. package/esm/ui/dialog/dialog.d.ts +5 -2
  58. package/esm/ui/dialog/dialog.js +2 -2
  59. package/esm/ui/index.d.ts +1 -0
  60. package/esm/ui/index.js +1 -0
  61. package/esm/ui/internals/FieldContainer.svelte +25 -14
  62. package/esm/ui/internals/FieldContainer.svelte.d.ts +9 -30
  63. package/esm/ui/internals/Input.svelte.d.ts +1 -1
  64. package/esm/ui/internals/Textarea.svelte +2 -5
  65. package/esm/ui/internals/select/MultiSelectMelt.svelte +10 -8
  66. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +1 -1
  67. package/esm/ui/internals/select/Select2.svelte +88 -0
  68. package/esm/ui/internals/select/Select2.svelte.d.ts +12 -0
  69. package/esm/ui/internals/select/SelectMelt.svelte +33 -24
  70. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +1 -1
  71. package/esm/ui/internals/select/SelectRadio.svelte +2 -2
  72. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +1 -1
  73. package/esm/ui/link/Link.svelte +1 -1
  74. package/esm/ui/link/LinkPlus.svelte +9 -5
  75. package/esm/ui/link/LinkPlus.svelte.d.ts +5 -19
  76. package/esm/virtual/Customer.js +1 -2
  77. package/esm/virtual/UIEntity.js +9 -5
  78. package/package.json +11 -25
  79. package/esm/auth/AuthController.d.ts +0 -58
  80. package/esm/auth/AuthController.js +0 -114
  81. package/esm/auth/Entities.d.ts +0 -47
  82. package/esm/auth/Entities.js +0 -182
  83. package/esm/auth/README.md +0 -3
  84. package/esm/auth/index.d.ts +0 -5
  85. package/esm/auth/index.js +0 -5
  86. package/esm/auth/server/AuthController.server.d.ts +0 -58
  87. package/esm/auth/server/AuthController.server.js +0 -498
  88. package/esm/auth/server/handleAuth.d.ts +0 -4
  89. package/esm/auth/server/handleAuth.js +0 -142
  90. package/esm/auth/server/handleGuard.d.ts +0 -22
  91. package/esm/auth/server/handleGuard.js +0 -34
  92. package/esm/auth/server/helperDb.d.ts +0 -10
  93. package/esm/auth/server/helperDb.js +0 -56
  94. package/esm/auth/server/helperFirstly.d.ts +0 -1
  95. package/esm/auth/server/helperFirstly.js +0 -9
  96. package/esm/auth/server/helperOslo.d.ts +0 -7
  97. package/esm/auth/server/helperOslo.js +0 -24
  98. package/esm/auth/server/helperRemultServer.d.ts +0 -5
  99. package/esm/auth/server/helperRemultServer.js +0 -44
  100. package/esm/auth/server/helperRole.d.ts +0 -19
  101. package/esm/auth/server/helperRole.js +0 -57
  102. package/esm/auth/server/index.d.ts +0 -8
  103. package/esm/auth/server/index.js +0 -8
  104. package/esm/auth/server/module.d.ts +0 -300
  105. package/esm/auth/server/module.js +0 -230
  106. package/esm/auth/server/providers/github.d.ts +0 -33
  107. package/esm/auth/server/providers/github.js +0 -87
  108. package/esm/auth/server/providers/helperProvider.d.ts +0 -1
  109. package/esm/auth/server/providers/helperProvider.js +0 -25
  110. package/esm/auth/static/assets/Page-9Ytj29NS.d.ts +0 -2
  111. package/esm/auth/static/assets/Page-9Ytj29NS.js +0 -1
  112. package/esm/auth/static/assets/Page-BHW08QWz.css +0 -1
  113. package/esm/auth/static/assets/Page-C1pM-UDt.d.ts +0 -2
  114. package/esm/auth/static/assets/Page-C1pM-UDt.js +0 -20
  115. package/esm/auth/static/assets/Page-CPz6KCw_.d.ts +0 -2
  116. package/esm/auth/static/assets/Page-CPz6KCw_.js +0 -1
  117. package/esm/auth/static/assets/index-AoBb9Ds5.d.ts +0 -232
  118. package/esm/auth/static/assets/index-AoBb9Ds5.js +0 -2
  119. package/esm/auth/static/assets/index-DKWpA6v7.css +0 -4
  120. package/esm/auth/static/favicon.svg +0 -79
  121. package/esm/auth/static/index.html +0 -13
  122. package/esm/auth/types.d.ts +0 -73
  123. package/esm/auth/types.js +0 -1
  124. package/esm/svelte/FF_Display.svelte +0 -51
  125. package/esm/svelte/FF_Display.svelte.d.ts +0 -29
  126. package/esm/svelte/FF_Edit.svelte +0 -104
  127. package/esm/svelte/FF_Edit.svelte.d.ts +0 -32
  128. package/esm/svelte/FF_Error.svelte +0 -23
  129. package/esm/svelte/FF_Error.svelte.d.ts +0 -29
  130. package/esm/svelte/FF_Field.svelte +0 -62
  131. package/esm/svelte/FF_Field.svelte.d.ts +0 -29
  132. package/esm/svelte/FF_Hint.svelte +0 -21
  133. package/esm/svelte/FF_Hint.svelte.d.ts +0 -29
  134. package/esm/svelte/FF_Label.svelte +0 -23
  135. package/esm/svelte/FF_Label.svelte.d.ts +0 -29
@@ -1,230 +0,0 @@
1
- import bcrypt from 'bcryptjs';
2
- import { EntityError, remult } from 'remult';
3
- import { red, yellow } from '@kitql/helpers';
4
- import { getRelativePackagePath } from '@kitql/internals';
5
- import { env } from '$env/dynamic/private';
6
- import { building } from '$app/environment';
7
- import { AuthController } from '..';
8
- import { ModuleFF } from '../../server';
9
- import { FFAuthAccount, FFAuthUser, FFAuthUserSession } from '../Entities';
10
- import { AuthControllerServer } from './AuthController.server';
11
- import { validateSessionToken } from './helperDb';
12
- import { setSessionTokenCookie } from './helperRemultServer';
13
- import { linkRoleToUsersFromEnv } from './helperRole';
14
- export let AUTH_OPTIONS = { ui: {} };
15
- const buildUrlOrDefault = (base, userSetting, fallback) => {
16
- if (userSetting === false) {
17
- return false;
18
- }
19
- if (userSetting === undefined) {
20
- return `${base}/${fallback}`;
21
- }
22
- return `${base}/${userSetting}`;
23
- };
24
- export const getSafeOptions = () => {
25
- const signUp = AUTH_OPTIONS.signUp ?? true;
26
- const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : (AUTH_OPTIONS.ui?.paths?.base ?? '/ff/auth');
27
- const ui = AUTH_OPTIONS.ui === false
28
- ? undefined
29
- : {
30
- paths: {
31
- base,
32
- sign_up: signUp ? buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_up, 'sign-up') : false,
33
- sign_in: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_in, 'sign-in'),
34
- forgot_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.forgot_password, 'forgot-password'),
35
- reset_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.reset_password, 'reset-password'),
36
- verify_email: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.verify_email, 'verify-email'),
37
- },
38
- strings: {
39
- app_name: AUTH_OPTIONS.ui?.strings?.app_name ?? '',
40
- email: AUTH_OPTIONS.ui?.strings?.email ?? 'Email',
41
- email_placeholder: AUTH_OPTIONS.ui?.strings?.email_placeholder ?? 'Your email address',
42
- password: AUTH_OPTIONS.ui?.strings?.password ?? 'Password',
43
- password_placeholder: AUTH_OPTIONS.ui?.strings?.password_placeholder ?? 'Your password',
44
- confirm: AUTH_OPTIONS.ui?.strings?.confirm ?? 'Confirm',
45
- reset: AUTH_OPTIONS.ui?.strings?.reset ?? 'Reset',
46
- btn_sign_up: AUTH_OPTIONS.ui?.strings?.btn_sign_up ?? 'Sign up',
47
- btn_sign_in: AUTH_OPTIONS.ui?.strings?.btn_sign_in ?? 'Sign in',
48
- forgot_password: AUTH_OPTIONS.ui?.strings?.forgot_password ?? 'Forgot your password?',
49
- send_password_reset_instructions: AUTH_OPTIONS.ui?.strings?.send_password_reset_instructions ??
50
- 'Send password reset instructions',
51
- back_to_sign_in: AUTH_OPTIONS.ui?.strings?.back_to_sign_in ?? 'Back to sign in',
52
- },
53
- images: {
54
- main: AUTH_OPTIONS.ui?.images?.main ?? '',
55
- },
56
- customHtmlHead: AUTH_OPTIONS.ui?.customHtmlHead ??
57
- '<title>Auth</title><link rel="icon" href="https://firstly.fun/favicon.svg" />',
58
- };
59
- if (AUTH_OPTIONS.debug && !building) {
60
- authModuleRaw.log.info('ui', ui);
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
- })) ?? [];
77
- const firstlyData = {
78
- module: 'auth',
79
- debug: AUTH_OPTIONS.debug,
80
- props: {
81
- ui,
82
- providers,
83
- },
84
- };
85
- let uiStaticPath = AUTH_OPTIONS.uiStaticPath ?? '';
86
- if (!AUTH_OPTIONS.uiStaticPath) {
87
- const installedFirstlyPath = getRelativePackagePath('firstly');
88
- if (installedFirstlyPath) {
89
- uiStaticPath = `${installedFirstlyPath}/esm/auth/static/`;
90
- }
91
- }
92
- let redirectUrl = AUTH_OPTIONS.defaultRedirect ?? '/';
93
- if (!redirectUrl.startsWith('/')) {
94
- authModuleRaw.log.error(`Invalid redirect url ${red(redirectUrl)} (it should be a local one starting with /)`);
95
- redirectUrl = '/';
96
- }
97
- let transformDbUserToClientUserToUse;
98
- if (AUTH_OPTIONS.transformDbUserToClientUser) {
99
- transformDbUserToClientUserToUse = AUTH_OPTIONS.transformDbUserToClientUser;
100
- }
101
- else {
102
- // @ts-ignore (I'm not sure why cadb-my-doc is failing check here if I don't do this!)
103
- transformDbUserToClientUserToUse = (session, user) => {
104
- return {
105
- id: user.id,
106
- name: user.name,
107
- roles: user.roles,
108
- session: {
109
- id: session.id,
110
- expiresAt: session.expiresAt,
111
- },
112
- };
113
- };
114
- }
115
- function validateInput({ identifier, password }) {
116
- if (typeof identifier !== 'string' || identifier.length === 0) {
117
- throw new EntityError({ message: 'Invalid identifier' });
118
- }
119
- if (typeof password !== 'string') {
120
- throw new EntityError({ message: 'Invalid password' });
121
- }
122
- if (password.length < 6 || password.length > 255) {
123
- throw new EntityError({ message: 'Password too short or too long!' });
124
- }
125
- }
126
- function passwordHash(password) {
127
- return bcrypt.hashSync(password, AUTH_OPTIONS.providers?.password?.algo?.bcrypt?.saltRounds ?? 10);
128
- }
129
- function passwordVerify(password, hash) {
130
- return bcrypt.compareSync(password, hash);
131
- }
132
- return {
133
- User: (AUTH_OPTIONS.customEntities?.User ?? FFAuthUser),
134
- Session: (AUTH_OPTIONS.customEntities?.Session ?? FFAuthUserSession),
135
- Account: (AUTH_OPTIONS.customEntities?.Account ?? FFAuthAccount),
136
- signUp,
137
- password: {
138
- enabled: AUTH_OPTIONS.providers?.password ? true : false,
139
- validateInput: AUTH_OPTIONS.providers?.password?.algo?.validateInput ?? validateInput,
140
- hash: AUTH_OPTIONS.providers?.password?.algo?.hash ?? passwordHash,
141
- verify: AUTH_OPTIONS.providers?.password?.algo?.verify ?? passwordVerify,
142
- },
143
- otp: { enabled: AUTH_OPTIONS.providers?.otp ? true : false },
144
- verifiedMethod: AUTH_OPTIONS.verifiedMethod ?? 'auto',
145
- redirectUrl,
146
- firstlyData,
147
- transformDbUserToClientUser: transformDbUserToClientUserToUse,
148
- uiStaticPath,
149
- session: {
150
- expiresInMs: AUTH_OPTIONS.session?.expiresIn ?? 1000 * 60 * 60 * 24 * 30, // 30 days,
151
- cookieName: AUTH_OPTIONS.session?.COOKIE_NAME ?? 'firstly_auth_session',
152
- },
153
- providers: AUTH_OPTIONS.providers,
154
- strings: {
155
- resetPasswordSend: AUTH_OPTIONS.strings?.resetPasswordSend ?? 'Mail sent ! You can now close this window.',
156
- resetPasswordUnknownUser: AUTH_OPTIONS.strings?.resetPasswordUnknownUser ??
157
- 'If your email is registered, you will receive an email with a link to reset your password.',
158
- anErrorOccurred: AUTH_OPTIONS.strings?.anErrorOccurred ?? 'An error occurred, contact the administrator.',
159
- cannotSignUp: AUTH_OPTIONS.strings?.cannotSignUp ??
160
- "You can't signup by yourself! Contact the administrator.",
161
- },
162
- ui,
163
- envRoles_AssignUsers: AUTH_OPTIONS.envRoles_AssignUsers ?? {},
164
- };
165
- };
166
- export const authModuleRaw = new ModuleFF({
167
- name: 'auth',
168
- priority: -777,
169
- });
170
- /**
171
- * To enable authentication in your app in a few lines of code.
172
- * _Info: index: -777_
173
- */
174
- export const auth = (o) => {
175
- // TODO should work ?
176
- // @ts-ignore
177
- AUTH_OPTIONS = o;
178
- const oSafe = getSafeOptions();
179
- // Replace the direct assignments with the new _setImplementation method
180
- AuthController._setAbstraction({
181
- signOut: AuthControllerServer.signOut,
182
- signInDemo: AuthControllerServer.signInDemo,
183
- invite: AuthControllerServer.invite,
184
- signUpPassword: AuthControllerServer.signUpPassword,
185
- signInPassword: AuthControllerServer.signInPassword,
186
- forgotPassword: AuthControllerServer.forgotPassword,
187
- resetPassword: AuthControllerServer.resetPassword,
188
- signInOTP: AuthControllerServer.signInOTP,
189
- verifyOtp: AuthControllerServer.verifyOtp,
190
- signInOAuthGetUrl: AuthControllerServer.signInOAuthGetUrl,
191
- });
192
- authModuleRaw.entities = [oSafe.User, oSafe.Session, oSafe.Account];
193
- authModuleRaw.controllers = [AuthController];
194
- authModuleRaw.initRequest = async (event) => {
195
- // REMULT: storing user in local should probably be done in remult directly
196
- if (event?.locals?.user) {
197
- remult.user = event.locals.user;
198
- }
199
- else {
200
- const sessionId = event.cookies.get(oSafe.session.cookieName);
201
- if (sessionId) {
202
- const { user, freshSession } = await validateSessionToken(sessionId);
203
- if (freshSession) {
204
- setSessionTokenCookie(freshSession.sessionToken, freshSession.expiresAt);
205
- }
206
- remult.user = user;
207
- if (event.locals) {
208
- event.locals.user = user;
209
- }
210
- }
211
- }
212
- };
213
- authModuleRaw.initApi = async () => {
214
- const oSafe = getSafeOptions();
215
- for (const [key, value] of Object.entries(oSafe.envRoles_AssignUsers)) {
216
- await linkRoleToUsersFromEnv({
217
- log: authModuleRaw.log,
218
- accountEntity: oSafe.Account,
219
- userEntity: oSafe.User,
220
- envKey: key.toUpperCase(),
221
- envValue: env[key.toUpperCase()] ?? '',
222
- roles: [value],
223
- });
224
- }
225
- if (Object.entries(oSafe.envRoles_AssignUsers).length === 0 && AUTH_OPTIONS.debug) {
226
- authModuleRaw.log.info(`set ${yellow('auth: { linkRoleToUsersFromEnv: ... }')} to assign roles to users via ${yellow('.env')}.`);
227
- }
228
- };
229
- return authModuleRaw;
230
- };
@@ -1,33 +0,0 @@
1
- import type { OAuth2Tokens } from 'arctic';
2
- import { GitHub } from 'arctic';
3
- import type { OAuth2UserInfo, ProviderAuthorizationURLOptions } from '../../types';
4
- import { type FFOAuth2Provider } from '../module';
5
- /**
6
- * ## GitHub OAuth2 provider
7
- *
8
- * 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
9
- * 2. In GitHub, set your callback url to
10
- * - [ ] dev: `http://_YOUR_LOCAL_URL:PORT_/api/auth_callback`
11
- * - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
12
- * 3. In your project add a `.env` file with the following:
13
- * ```bash
14
- * GITHUB_CLIENT_ID = 'your-client-id'
15
- * GITHUB_CLIENT_SECRET = 'your-client-secret'
16
- * # GITHUB_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
17
- * ```
18
- * 4. In your frontend, under a button click call something like:
19
- * ```ts
20
- * async function oauth() {
21
- * window.location.href = await Auth.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
22
- * }
23
- * ```
24
- * 5. Enjoy 🥳
25
- */
26
- export declare function github(options?: {
27
- GITHUB_CLIENT_ID?: string;
28
- GITHUB_CLIENT_SECRET?: string;
29
- GITHUB_REDIRECT_URI?: string;
30
- authorizationURLOptions?: ProviderAuthorizationURLOptions;
31
- getUserInfo?: (tokens: OAuth2Tokens) => Promise<OAuth2UserInfo>;
32
- log?: boolean;
33
- }): FFOAuth2Provider<GitHub, 'github'>;
@@ -1,87 +0,0 @@
1
- import { GitHub } from 'arctic';
2
- import { remult } from 'remult';
3
- import { env } from '$env/dynamic/private';
4
- import { authModuleRaw } from '../module';
5
- import { checkOAuthConfig } from './helperProvider';
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
- //------------------------------
12
- /**
13
- * ## GitHub OAuth2 provider
14
- *
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://_YOUR_LOCAL_URL:PORT_/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"
24
- * ```
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 🥳
32
- */
33
- export function github(options) {
34
- const name = 'github';
35
- const clientID = options?.GITHUB_CLIENT_ID ?? env.GITHUB_CLIENT_ID ?? '';
36
- const secret = options?.GITHUB_CLIENT_SECRET ?? env.GITHUB_CLIENT_SECRET ?? '';
37
- const urlForKeys = 'https://github.com/settings/developers';
38
- checkOAuthConfig(name, clientID, secret, urlForKeys, false);
39
- return {
40
- name,
41
- caption: 'GitHub',
42
- getArcticProvider: () => {
43
- const redirectURI = options?.GITHUB_REDIRECT_URI ??
44
- env.GITHUB_REDIRECT_URI ??
45
- `${remult.context.request.url.origin}/api/auth_callback`;
46
- checkOAuthConfig(name, clientID, secret, urlForKeys, true);
47
- const o = new GitHub(clientID, secret, redirectURI);
48
- return o;
49
- },
50
- authorizationURLOptions: () => {
51
- return options?.authorizationURLOptions ?? [];
52
- },
53
- getUserInfo: options?.getUserInfo
54
- ? options.getUserInfo
55
- : async (tokens) => {
56
- const res = await fetch('https://api.github.com/user', {
57
- headers: {
58
- Authorization: `Bearer ${tokens.accessToken()}`,
59
- },
60
- });
61
- const user = await res.json();
62
- const nameOptions = [user.login];
63
- const emailOptions = [];
64
- if ((options?.authorizationURLOptions ?? ['user:email']).includes('user:email')) {
65
- const res = await fetch('https://api.github.com/user/emails', {
66
- headers: {
67
- Authorization: `Bearer ${tokens.accessToken()}`,
68
- },
69
- });
70
- user.emails = await res.json();
71
- if (Array.isArray(user.emails)) {
72
- const primaryEmails = user.emails.filter((email) => email.primary === true);
73
- primaryEmails.forEach((email) => {
74
- if (email.email) {
75
- nameOptions.unshift(email.email);
76
- emailOptions.unshift(email.email);
77
- }
78
- });
79
- }
80
- }
81
- if (options?.log) {
82
- authModuleRaw.log.info(`user`, user);
83
- }
84
- return { raw: user, providerUserId: String(user.id), nameOptions, emailOptions };
85
- },
86
- };
87
- }
@@ -1 +0,0 @@
1
- export declare const checkOAuthConfig: (name: string, clientId: string, secret: string, urlForKeys: string, withThrow: boolean) => void;
@@ -1,25 +0,0 @@
1
- import { EntityError } from 'remult';
2
- import { cyan, gray, green, italic, yellow } from '@kitql/helpers';
3
- import { mask } from '../../../formats/strings';
4
- import { authModuleRaw } from '../module';
5
- export const checkOAuthConfig = (name, clientId, secret, urlForKeys, withThrow) => {
6
- if (!clientId || !secret) {
7
- const msg = `Wrong configuration for ${green(name)} provider.
8
- ${italic(`Config used ${gray(`(${'.env'} & ${'inferred'}):`)}`)}
9
- ${yellow('--------------- .env ---------------')}
10
- ${name.toUpperCase()}_CLIENT_ID = '${mask(clientId)}'
11
- ${name.toUpperCase()}_CLIENT_SECRET = '${mask(secret)}'
12
- ${yellow('------------------------------------')}
13
- Update your configuration to fix this error.
14
- ${gray(`By default, we check ${name.toUpperCase()}_CLIENT_ID and ${name.toUpperCase()}_CLIENT_SECRET.
15
- But you can also pass your keys as parameters.`)}
16
- Check ${cyan(urlForKeys)} to generate your keys.
17
- `;
18
- if (withThrow) {
19
- throw new EntityError({ message: msg });
20
- }
21
- else {
22
- authModuleRaw.log.error(msg);
23
- }
24
- }
25
- };
@@ -1,2 +0,0 @@
1
- export { f as default };
2
- declare function f(a: any): void;
@@ -1 +0,0 @@
1
- import{aa as e,U as o}from"./index-AoBb9Ds5.js";function f(a){var t=e("Hello from admin");o(a,t)}export{f as default};
@@ -1 +0,0 @@
1
- .oauth-container.svelte-1dwkktf{display:flex;flex-direction:column;gap:.5rem}.oauth-button-icon.svelte-1dwkktf{width:1.25rem;height:1.25rem}.oauth-button.svelte-1dwkktf{display:flex;align-items:center;justify-content:center;gap:.5rem;padding:.5rem 1rem;font-size:.875rem;font-weight:500}form.svelte-skcj83{display:flex;flex-direction:column}h1.svelte-1jjivcr{text-align:center;margin-bottom:2rem}.wrapper.svelte-1jjivcr{min-height:100vh;display:flex;justify-content:center;align-items:center;margin:0 auto}.centered-layout.svelte-1jjivcr{display:flex;justify-content:center;align-items:center;width:100%}.split-layout.svelte-1jjivcr{display:flex;width:100%;min-height:100vh}.form-side.svelte-1jjivcr{width:50%;display:flex;justify-content:center;align-items:center}.image-side.svelte-1jjivcr{width:50%;height:100vh;overflow:hidden}.image-side.svelte-1jjivcr img:where(.svelte-1jjivcr){width:100%;height:100%;object-fit:cover}.form.svelte-1jjivcr{max-width:360px;width:100%;padding:1rem;display:flex;flex-direction:column}.form-footer.svelte-1jjivcr{margin-top:1rem;display:flex;flex-direction:column;justify-content:center;align-items:center}.fallback.svelte-1jjivcr{display:flex;justify-content:center;align-items:center}@media (max-width: 768px){.split-layout.svelte-1jjivcr{flex-direction:column}.form-side.svelte-1jjivcr{width:100%;order:2}.image-side.svelte-1jjivcr{width:100%;height:50vh;order:1}.form.svelte-1jjivcr{max-width:100%}}
@@ -1,2 +0,0 @@
1
- export { Bo as default };
2
- declare function Bo(i: any, e: any): void;