firstly 0.0.1 → 0.0.3

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 (156) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +18 -0
  3. package/README.md +12 -0
  4. package/esm/KitBaseEnum.d.ts +35 -0
  5. package/esm/KitBaseEnum.js +32 -0
  6. package/esm/KitEntity.d.ts +2 -0
  7. package/esm/KitEntity.js +24 -0
  8. package/esm/KitFields.d.ts +10 -0
  9. package/esm/KitFields.js +196 -0
  10. package/esm/ROUTES.d.ts +88 -0
  11. package/esm/ROUTES.js +98 -0
  12. package/esm/SqlDatabase/LogToConsoleCustom.d.ts +1 -0
  13. package/esm/SqlDatabase/LogToConsoleCustom.js +102 -0
  14. package/esm/api/index.d.ts +42 -0
  15. package/esm/api/index.js +97 -0
  16. package/esm/auth/Adapter.d.ts +10 -0
  17. package/esm/auth/Adapter.js +54 -0
  18. package/esm/auth/AuthController.d.ts +59 -0
  19. package/esm/auth/AuthController.js +434 -0
  20. package/esm/auth/Entities.d.ts +39 -0
  21. package/esm/auth/Entities.js +154 -0
  22. package/esm/auth/RoleController.d.ts +14 -0
  23. package/esm/auth/RoleController.js +57 -0
  24. package/esm/auth/helper.d.ts +1 -0
  25. package/esm/auth/helper.js +7 -0
  26. package/esm/auth/index.d.ts +153 -0
  27. package/esm/auth/index.js +280 -0
  28. package/esm/auth/providers/github.d.ts +25 -0
  29. package/esm/auth/providers/github.js +51 -0
  30. package/esm/auth/providers/index.d.ts +3 -0
  31. package/esm/auth/providers/index.js +26 -0
  32. package/esm/auth/providers/strava.d.ts +25 -0
  33. package/esm/auth/providers/strava.js +51 -0
  34. package/esm/auth/static/assets/Page-BMFREPjF.d.ts +5 -0
  35. package/esm/auth/static/assets/Page-BMFREPjF.js +18 -0
  36. package/esm/auth/static/assets/Page-BMOLAIFx.d.ts +5 -0
  37. package/esm/auth/static/assets/Page-BMOLAIFx.js +1 -0
  38. package/esm/auth/static/assets/Page-BwHye0GW.d.ts +5 -0
  39. package/esm/auth/static/assets/Page-BwHye0GW.js +1 -0
  40. package/esm/auth/static/assets/Page-gV58jf2r.css +1 -0
  41. package/esm/auth/static/assets/index-CKmKKRRL.d.ts +53 -0
  42. package/esm/auth/static/assets/index-CKmKKRRL.js +2 -0
  43. package/esm/auth/static/assets/index-R27C_TlP.css +4 -0
  44. package/esm/auth/static/favicon.svg +79 -0
  45. package/esm/auth/static/index.html +14 -0
  46. package/esm/auth/types.d.ts +33 -0
  47. package/esm/auth/types.js +1 -0
  48. package/esm/bin/cmd.d.ts +1 -0
  49. package/esm/bin/cmd.js +418 -0
  50. package/esm/changeLog/index.d.ts +55 -0
  51. package/esm/changeLog/index.js +179 -0
  52. package/esm/cron/index.d.ts +60 -0
  53. package/esm/cron/index.js +102 -0
  54. package/esm/feedback/FeedbackController.d.ts +30 -0
  55. package/esm/feedback/FeedbackController.js +313 -0
  56. package/esm/feedback/index.d.ts +18 -0
  57. package/esm/feedback/index.js +14 -0
  58. package/esm/feedback/ui/DialogIssue.svelte +102 -0
  59. package/esm/feedback/ui/DialogIssue.svelte.d.ts +20 -0
  60. package/esm/feedback/ui/DialogIssues.svelte +91 -0
  61. package/esm/feedback/ui/DialogIssues.svelte.d.ts +20 -0
  62. package/esm/feedback/ui/DialogMilestones.svelte +38 -0
  63. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +18 -0
  64. package/esm/feedback/ui/Feedback.svelte +12 -0
  65. package/esm/feedback/ui/Feedback.svelte.d.ts +16 -0
  66. package/esm/formats/dates.d.ts +18 -0
  67. package/esm/formats/dates.js +35 -0
  68. package/esm/formats/index.d.ts +4 -0
  69. package/esm/formats/index.js +3 -0
  70. package/esm/formats/numbers.d.ts +4 -0
  71. package/esm/formats/numbers.js +34 -0
  72. package/esm/formats/strings.d.ts +11 -0
  73. package/esm/formats/strings.js +109 -0
  74. package/esm/handle/index.d.ts +7 -0
  75. package/esm/handle/index.js +40 -0
  76. package/esm/helper.d.ts +50 -0
  77. package/esm/helper.js +118 -0
  78. package/esm/index.d.ts +103 -0
  79. package/esm/index.js +42 -0
  80. package/esm/kitCellsBuildor.d.ts +45 -0
  81. package/esm/kitCellsBuildor.js +105 -0
  82. package/esm/kitStoreItem.d.ts +28 -0
  83. package/esm/kitStoreItem.js +170 -0
  84. package/esm/kitStoreList.d.ts +33 -0
  85. package/esm/kitStoreList.js +98 -0
  86. package/esm/mail/index.d.ts +11 -0
  87. package/esm/mail/index.js +51 -0
  88. package/esm/theme.d.ts +4 -0
  89. package/esm/theme.js +4 -0
  90. package/esm/ui/Button.svelte +102 -0
  91. package/esm/ui/Button.svelte.d.ts +27 -0
  92. package/esm/ui/Clipboardable.svelte +19 -0
  93. package/esm/ui/Clipboardable.svelte.d.ts +25 -0
  94. package/esm/ui/Field.svelte +288 -0
  95. package/esm/ui/Field.svelte.d.ts +29 -0
  96. package/esm/ui/FieldGroup.svelte +91 -0
  97. package/esm/ui/FieldGroup.svelte.d.ts +30 -0
  98. package/esm/ui/Grid.svelte +246 -0
  99. package/esm/ui/Grid.svelte.d.ts +46 -0
  100. package/esm/ui/GridLoading.svelte +32 -0
  101. package/esm/ui/GridLoading.svelte.d.ts +20 -0
  102. package/esm/ui/GridPaginate.svelte +66 -0
  103. package/esm/ui/GridPaginate.svelte.d.ts +22 -0
  104. package/esm/ui/Icon.svelte +86 -0
  105. package/esm/ui/Icon.svelte.d.ts +46 -0
  106. package/esm/ui/LibIcon.d.ts +23 -0
  107. package/esm/ui/LibIcon.js +28 -0
  108. package/esm/ui/Loading.svelte +11 -0
  109. package/esm/ui/Loading.svelte.d.ts +20 -0
  110. package/esm/ui/Tooltip.svelte +42 -0
  111. package/esm/ui/Tooltip.svelte.d.ts +22 -0
  112. package/esm/ui/dialog/DialogForm.svelte +70 -0
  113. package/esm/ui/dialog/DialogForm.svelte.d.ts +19 -0
  114. package/esm/ui/dialog/DialogManagement.svelte +87 -0
  115. package/esm/ui/dialog/DialogManagement.svelte.d.ts +25 -0
  116. package/esm/ui/dialog/DialogPrimitive.svelte +89 -0
  117. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +28 -0
  118. package/esm/ui/dialog/FormEditAction.svelte +54 -0
  119. package/esm/ui/dialog/FormEditAction.svelte.d.ts +24 -0
  120. package/esm/ui/dialog/dialog.d.ts +51 -0
  121. package/esm/ui/dialog/dialog.js +98 -0
  122. package/esm/ui/index.d.ts +5 -0
  123. package/esm/ui/index.js +19 -0
  124. package/esm/ui/internals/FieldContainer.svelte +22 -0
  125. package/esm/ui/internals/FieldContainer.svelte.d.ts +30 -0
  126. package/esm/ui/internals/Input.svelte +98 -0
  127. package/esm/ui/internals/Input.svelte.d.ts +35 -0
  128. package/esm/ui/internals/Textarea.svelte +61 -0
  129. package/esm/ui/internals/Textarea.svelte.d.ts +30 -0
  130. package/esm/ui/internals/select/MultiSelectMelt.svelte +217 -0
  131. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +30 -0
  132. package/esm/ui/internals/select/SelectMelt.svelte +238 -0
  133. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +35 -0
  134. package/esm/ui/internals/select/SelectRadio.svelte +37 -0
  135. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +25 -0
  136. package/esm/ui/link/Link.svelte +28 -0
  137. package/esm/ui/link/Link.svelte.d.ts +25 -0
  138. package/esm/ui/link/LinkPlus.svelte +44 -0
  139. package/esm/ui/link/LinkPlus.svelte.d.ts +21 -0
  140. package/esm/utils/tailwind.d.ts +2 -0
  141. package/esm/utils/tailwind.js +3 -0
  142. package/esm/utils/transition.d.ts +10 -0
  143. package/esm/utils/transition.js +33 -0
  144. package/esm/utils/types.d.ts +17 -0
  145. package/esm/utils/types.js +17 -0
  146. package/esm/virtual/Customer.d.ts +4 -0
  147. package/esm/virtual/Customer.js +24 -0
  148. package/esm/virtual/FilterEntity.d.ts +7 -0
  149. package/esm/virtual/FilterEntity.js +34 -0
  150. package/esm/virtual/StateDemoEnum.d.ts +9 -0
  151. package/esm/virtual/StateDemoEnum.js +42 -0
  152. package/esm/virtual/UIEntity.d.ts +16 -0
  153. package/esm/virtual/UIEntity.js +84 -0
  154. package/esm/vite/index.d.ts +8 -0
  155. package/esm/vite/index.js +47 -0
  156. package/package.json +94 -10
@@ -0,0 +1,42 @@
1
+ import { type Handle, type MaybePromise, type RequestEvent } from '@sveltejs/kit';
2
+ import { type ClassType } from 'remult';
3
+ import type { RemultServerOptions } from 'remult/server';
4
+ import { type MailOptions } from '../mail';
5
+ export type Module = {
6
+ /**
7
+ * The name of the module (usefull for logging and debugging purposes)
8
+ */
9
+ name: string;
10
+ index?: number;
11
+ entities?: ClassType<any>[];
12
+ controllers?: ClassType<any>[];
13
+ initApi?: RemultServerOptions<RequestEvent>['initApi'];
14
+ initRequest?: RemultServerOptions<RequestEvent>['initRequest'];
15
+ handlePreRemult?: Handle;
16
+ handlePosRemult?: Handle;
17
+ earlyReturn?: (input: Parameters<Handle>[0]) => MaybePromise<{
18
+ early: false;
19
+ resolve?: never;
20
+ } | {
21
+ early: true;
22
+ resolve: ReturnType<Handle>;
23
+ }>;
24
+ modules?: Module[];
25
+ };
26
+ type Options = Omit<RemultServerOptions<RequestEvent<Partial<Record<string, string>>, string | null>> & {
27
+ modules?: Module[] | undefined;
28
+ mail?: MailOptions;
29
+ }, 'entities' | 'controllers' | 'initRequest' | 'initApi'>;
30
+ /**
31
+ * it's basically `remultSveltekit` with the `modules` option
32
+ */
33
+ export declare const firstly: (o: Options) => {
34
+ modulesSorted: Module[];
35
+ entities: ClassType<any>[];
36
+ server: import("remult/remult-sveltekit").RemultSveltekitServer;
37
+ };
38
+ /**
39
+ * Full flat and ordered list by index and concatenaining the modules name
40
+ */
41
+ export declare const modulesFlatAndOrdered: (modules: Module[]) => Module[];
42
+ export {};
@@ -0,0 +1,97 @@
1
+ import {} from '@sveltejs/kit';
2
+ import nodemailer from 'nodemailer';
3
+ import { remult } from 'remult';
4
+ import { remultSveltekit } from 'remult/remult-sveltekit';
5
+ import { Log } from '@kitql/helpers';
6
+ import { building } from '$app/environment';
7
+ import { mailInit } from '../mail';
8
+ /**
9
+ * it's basically `remultSveltekit` with the `modules` option
10
+ */
11
+ export const firstly = (o) => {
12
+ const modulesSorted = modulesFlatAndOrdered(o.modules ?? []);
13
+ const entities = modulesSorted.flatMap((m) => m.entities ?? []);
14
+ mailInit(nodemailer, o.mail);
15
+ return {
16
+ modulesSorted: modulesSorted,
17
+ entities,
18
+ server: remultSveltekit({
19
+ // Changing the default default of remult
20
+ logApiEndPoints: false,
21
+ admin: true,
22
+ defaultGetLimit: 25,
23
+ error: o.error
24
+ ? o.error
25
+ : async (e) => {
26
+ // if 500 we move to 501 to avoid the default retry mechanism
27
+ if (e.httpStatusCode == 500) {
28
+ e.sendError(501, e.responseBody);
29
+ }
30
+ },
31
+ // Add user configuration
32
+ ...o,
33
+ // Module part
34
+ entities,
35
+ controllers: modulesSorted.flatMap((m) => m.controllers ?? []),
36
+ initRequest: async (kitEvent, op) => {
37
+ // usefull for later...
38
+ remult.context.url = kitEvent.url;
39
+ for (let i = 0; i < modulesSorted.length; i++) {
40
+ const f = modulesSorted[i].initRequest;
41
+ if (f) {
42
+ try {
43
+ await f(kitEvent, op);
44
+ }
45
+ catch (error) {
46
+ const log = new Log(`firstly | ${modulesSorted[i].name}`);
47
+ log.error(error);
48
+ }
49
+ }
50
+ }
51
+ remult.context.setHeaders = (headers) => {
52
+ kitEvent.setHeaders(headers);
53
+ };
54
+ remult.context.setCookie = (name, value, opts) => {
55
+ kitEvent.cookies.set(name, value, opts);
56
+ };
57
+ remult.context.deleteCookie = (name, opts) => {
58
+ kitEvent.cookies.delete(name, opts);
59
+ };
60
+ },
61
+ initApi: async (r) => {
62
+ if (!building) {
63
+ for (let i = 0; i < modulesSorted.length; i++) {
64
+ const f = modulesSorted[i].initApi;
65
+ if (f) {
66
+ try {
67
+ await f(r);
68
+ }
69
+ catch (error) {
70
+ const log = new Log(`firstly | ${modulesSorted[i].name}`);
71
+ log.error(error);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ },
77
+ }),
78
+ };
79
+ };
80
+ /**
81
+ * Full flat and ordered list by index and concatenaining the modules name
82
+ */
83
+ export const modulesFlatAndOrdered = (modules) => {
84
+ const flattenModules = (modules, parentName = '') => {
85
+ return modules.reduce((acc, module) => {
86
+ const fullName = parentName ? `${parentName}-${module.name}` : module.name;
87
+ // Create a new module object without the 'modules' property
88
+ const { modules: _, ...flatModule } = module;
89
+ const newModule = { ...flatModule, name: fullName };
90
+ const subModules = module.modules ? flattenModules(module.modules, fullName) : [];
91
+ return [...acc, newModule, ...subModules];
92
+ }, []);
93
+ };
94
+ const flatModules = flattenModules(modules);
95
+ flatModules.sort((a, b) => (a.index || 0) - (b.index || 0));
96
+ return flatModules;
97
+ };
@@ -0,0 +1,10 @@
1
+ import type { Adapter, DatabaseSession, DatabaseUser } from 'lucia';
2
+ export declare class RemultLuciaAdapter implements Adapter {
3
+ getSessionAndUser(sessionId: string): Promise<[session: DatabaseSession | null, user: DatabaseUser | null]>;
4
+ getUserSessions(userId: string): Promise<DatabaseSession[]>;
5
+ setSession(session: DatabaseSession): Promise<void>;
6
+ updateSessionExpiration(sessionId: string, expiresAt: Date): Promise<void>;
7
+ deleteSession(sessionId: string): Promise<void>;
8
+ deleteUserSessions(userId: string): Promise<void>;
9
+ deleteExpiredSessions(): Promise<void>;
10
+ }
@@ -0,0 +1,54 @@
1
+ import { remult } from 'remult';
2
+ import { getSafeOptions } from './index.js';
3
+ export class RemultLuciaAdapter {
4
+ async getSessionAndUser(sessionId) {
5
+ const oSafe = getSafeOptions();
6
+ const session = await remult.repo(oSafe.Session).findId(sessionId);
7
+ if (session) {
8
+ const user = await remult.repo(oSafe.User).findId(session.userId);
9
+ return [
10
+ { ...session, attributes: {} },
11
+ {
12
+ ...user,
13
+ attributes: {
14
+ ...user,
15
+ session: { id: session.id, expiresAt: session.expiresAt },
16
+ },
17
+ },
18
+ ];
19
+ }
20
+ return [null, null];
21
+ }
22
+ async getUserSessions(userId) {
23
+ const oSafe = getSafeOptions();
24
+ return (await remult.repo(oSafe.Session).find({ where: { userId } })).map((s) => {
25
+ return { ...s, attributes: {} };
26
+ });
27
+ }
28
+ async setSession(session) {
29
+ const oSafe = getSafeOptions();
30
+ await remult.repo(oSafe.Session).insert(session);
31
+ }
32
+ async updateSessionExpiration(sessionId, expiresAt) {
33
+ const oSafe = getSafeOptions();
34
+ await remult.repo(oSafe.Session).update(sessionId, { expiresAt });
35
+ }
36
+ async deleteSession(sessionId) {
37
+ const oSafe = getSafeOptions();
38
+ await remult.repo(oSafe.Session).delete(sessionId);
39
+ }
40
+ async deleteUserSessions(userId) {
41
+ const oSafe = getSafeOptions();
42
+ const all = await remult.repo(oSafe.Session).find({ where: { userId } });
43
+ for (const s of all) {
44
+ await remult.repo(oSafe.Session).delete(s);
45
+ }
46
+ }
47
+ async deleteExpiredSessions() {
48
+ const oSafe = getSafeOptions();
49
+ const all = await remult.repo(oSafe.Session).find({ where: { expiresAt: { $lt: new Date() } } });
50
+ for (const s of all) {
51
+ await remult.repo(oSafe.Session).delete(s);
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,59 @@
1
+ import { type AuthorizationURLOptions } from '.';
2
+ export declare class AuthController {
3
+ /**
4
+ * Sign out the current user
5
+ */
6
+ static signOut(): Promise<void>;
7
+ /**
8
+ * Sign in with a demo account
9
+ * _(The easiest way to demo & test your application)_
10
+ */
11
+ static signInDemo(name: string): Promise<string>;
12
+ /**
13
+ * This is for login / password authentication SignUp
14
+ * _(The first param `name` can be "anything")_
15
+ */
16
+ static invite(email: string): Promise<"Mail sent !" | "Demo Mail sent !" | "ok">;
17
+ /**
18
+ * This is for login / password authentication SignUp
19
+ * _(The first param `email` can be "anything")_
20
+ */
21
+ static signUpPassword(email: string, password: string): Promise<string>;
22
+ /**
23
+ * This is for login / password authentication SignIn
24
+ * _(The first param `email` can be "anything")_
25
+ */
26
+ static signInPassword(email: string, password: string): Promise<string>;
27
+ /**
28
+ * Forgot your password ? Send a mail to reset it.
29
+ */
30
+ static forgotPassword(email: string): Promise<"Mail sent !" | "Demo Mail sent !">;
31
+ /**
32
+ * Reset your password with a token
33
+ */
34
+ static resetPassword(token: string, password: string): Promise<string>;
35
+ /** OTP */
36
+ static signInOTP(email: string): Promise<"Mail sent !" | "Hum, something went wrong !">;
37
+ /**
38
+ * Verify the OTP code
39
+ */
40
+ static verifyOtp(email: string, otp: string | number): Promise<string>;
41
+ /** OAUTH */
42
+ /**
43
+ * The the url to redirect to for the OAuth provider
44
+ * @param provider Has to mach one of `AUTH_OPTIONS.providers.oAuths` your configured
45
+ *
46
+ * To be used like this for example:
47
+ * ```
48
+ * const url = await AuthController.signInOAuthGetUrl('github')
49
+ * window.location.href = url
50
+ * ```
51
+ *
52
+ * _(popup example should work too, and a nice example/componant would be appreciated)_
53
+ */
54
+ static signInOAuthGetUrl<T extends keyof AuthorizationURLOptions>(o: {
55
+ provider: T;
56
+ options?: AuthorizationURLOptions[T];
57
+ redirect?: string;
58
+ }): Promise<string>;
59
+ }