adminforth 2.4.0-next.24 → 2.4.0-next.240

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 (195) hide show
  1. package/commands/callTsProxy.js +14 -4
  2. package/commands/cli.js +10 -3
  3. package/commands/createApp/templates/custom/tsconfig.json.hbs +2 -3
  4. package/commands/createApp/templates/index.ts.hbs +10 -2
  5. package/commands/createApp/templates/package.json.hbs +1 -1
  6. package/commands/createApp/utils.js +27 -2
  7. package/commands/createCustomComponent/configLoader.js +17 -4
  8. package/commands/createCustomComponent/main.js +1 -0
  9. package/commands/createCustomComponent/templates/customCrud/beforeActionButtons.vue.hbs +38 -0
  10. package/commands/createPlugin/templates/custom/tsconfig.json.hbs +2 -5
  11. package/commands/createPlugin/templates/package.json.hbs +1 -1
  12. package/commands/generateModels.js +30 -22
  13. package/dist/auth.d.ts +9 -1
  14. package/dist/auth.d.ts.map +1 -1
  15. package/dist/auth.js +15 -2
  16. package/dist/auth.js.map +1 -1
  17. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  18. package/dist/dataConnectors/baseConnector.js +46 -15
  19. package/dist/dataConnectors/baseConnector.js.map +1 -1
  20. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  21. package/dist/dataConnectors/clickhouse.js +15 -0
  22. package/dist/dataConnectors/clickhouse.js.map +1 -1
  23. package/dist/dataConnectors/mongo.d.ts.map +1 -1
  24. package/dist/dataConnectors/mongo.js +50 -15
  25. package/dist/dataConnectors/mongo.js.map +1 -1
  26. package/dist/dataConnectors/mysql.d.ts.map +1 -1
  27. package/dist/dataConnectors/mysql.js +11 -0
  28. package/dist/dataConnectors/mysql.js.map +1 -1
  29. package/dist/dataConnectors/postgres.d.ts.map +1 -1
  30. package/dist/dataConnectors/postgres.js +11 -0
  31. package/dist/dataConnectors/postgres.js.map +1 -1
  32. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  33. package/dist/dataConnectors/sqlite.js +11 -0
  34. package/dist/dataConnectors/sqlite.js.map +1 -1
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +23 -9
  38. package/dist/index.js.map +1 -1
  39. package/dist/modules/codeInjector.d.ts +2 -0
  40. package/dist/modules/codeInjector.d.ts.map +1 -1
  41. package/dist/modules/codeInjector.js +52 -8
  42. package/dist/modules/codeInjector.js.map +1 -1
  43. package/dist/modules/configValidator.d.ts +6 -0
  44. package/dist/modules/configValidator.d.ts.map +1 -1
  45. package/dist/modules/configValidator.js +184 -19
  46. package/dist/modules/configValidator.js.map +1 -1
  47. package/dist/modules/restApi.d.ts.map +1 -1
  48. package/dist/modules/restApi.js +154 -26
  49. package/dist/modules/restApi.js.map +1 -1
  50. package/dist/modules/styles.d.ts +499 -13
  51. package/dist/modules/styles.d.ts.map +1 -1
  52. package/dist/modules/styles.js +555 -31
  53. package/dist/modules/styles.js.map +1 -1
  54. package/dist/modules/utils.d.ts +7 -15
  55. package/dist/modules/utils.d.ts.map +1 -1
  56. package/dist/modules/utils.js +45 -68
  57. package/dist/modules/utils.js.map +1 -1
  58. package/dist/servers/express.d.ts +5 -0
  59. package/dist/servers/express.d.ts.map +1 -1
  60. package/dist/servers/express.js +40 -1
  61. package/dist/servers/express.js.map +1 -1
  62. package/dist/spa/index.html +1 -1
  63. package/dist/spa/package-lock.json +5 -4
  64. package/dist/spa/package.json +1 -1
  65. package/dist/spa/src/App.vue +58 -173
  66. package/dist/spa/src/adminforth.ts +42 -18
  67. package/dist/spa/src/afcl/BarChart.vue +2 -2
  68. package/dist/spa/src/afcl/Button.vue +6 -6
  69. package/dist/spa/src/afcl/ButtonGroup.vue +91 -0
  70. package/dist/spa/src/afcl/Card.vue +25 -0
  71. package/dist/spa/src/afcl/Checkbox.vue +21 -13
  72. package/dist/spa/src/afcl/CountryFlag.vue +4 -1
  73. package/dist/spa/src/{components/CustomDatePicker.vue → afcl/DatePicker.vue} +95 -9
  74. package/dist/spa/src/afcl/Dialog.vue +47 -27
  75. package/dist/spa/src/afcl/Dropzone.vue +12 -12
  76. package/dist/spa/src/afcl/Input.vue +5 -5
  77. package/dist/spa/src/afcl/JsonViewer.vue +25 -0
  78. package/dist/spa/src/afcl/LinkButton.vue +3 -3
  79. package/dist/spa/src/afcl/PieChart.vue +5 -5
  80. package/dist/spa/src/afcl/ProgressBar.vue +7 -7
  81. package/dist/spa/src/afcl/Select.vue +68 -34
  82. package/dist/spa/src/afcl/Skeleton.vue +6 -6
  83. package/dist/spa/src/afcl/Table.vue +213 -74
  84. package/dist/spa/src/afcl/Textarea.vue +31 -0
  85. package/dist/spa/src/afcl/Toggle.vue +32 -0
  86. package/dist/spa/src/afcl/Tooltip.vue +26 -18
  87. package/dist/spa/src/afcl/VerticalTabs.vue +16 -7
  88. package/dist/spa/src/afcl/index.ts +6 -3
  89. package/dist/spa/src/components/AcceptModal.vue +7 -7
  90. package/dist/spa/src/components/Breadcrumbs.vue +5 -5
  91. package/dist/spa/src/components/ColumnValueInput.vue +38 -18
  92. package/dist/spa/src/components/ColumnValueInputWrapper.vue +4 -3
  93. package/dist/spa/src/components/CustomDateRangePicker.vue +9 -8
  94. package/dist/spa/src/components/CustomRangePicker.vue +37 -8
  95. package/dist/spa/src/components/ErrorMessage.vue +21 -0
  96. package/dist/spa/src/components/Filters.vue +85 -39
  97. package/dist/spa/src/components/GroupsTable.vue +9 -8
  98. package/dist/spa/src/components/MenuLink.vue +90 -23
  99. package/dist/spa/src/components/ResourceForm.vue +94 -51
  100. package/dist/spa/src/components/ResourceListTable.vue +90 -80
  101. package/dist/spa/src/components/ResourceListTableVirtual.vue +86 -76
  102. package/dist/spa/src/components/ShowTable.vue +21 -15
  103. package/dist/spa/src/components/Sidebar.vue +448 -0
  104. package/dist/spa/src/components/SingleSkeletLoader.vue +6 -6
  105. package/dist/spa/src/components/SkeleteLoader.vue +3 -3
  106. package/dist/spa/src/components/ThreeDotsMenu.vue +73 -14
  107. package/dist/spa/src/components/Toast.vue +27 -9
  108. package/dist/spa/src/components/UserMenuSettingsButton.vue +67 -0
  109. package/dist/spa/src/components/ValueRenderer.vue +43 -16
  110. package/dist/spa/src/controls/BoolToggle.vue +34 -0
  111. package/dist/spa/src/i18n.ts +1 -1
  112. package/dist/spa/src/renderers/CompactField.vue +1 -1
  113. package/dist/spa/src/renderers/CompactUUID.vue +1 -1
  114. package/dist/spa/src/router/index.ts +8 -0
  115. package/dist/spa/src/shims-vue.d.ts +5 -0
  116. package/dist/spa/src/spa_types/core.ts +13 -1
  117. package/dist/spa/src/stores/core.ts +1 -1
  118. package/dist/spa/src/stores/filters.ts +29 -2
  119. package/dist/spa/src/stores/modal.ts +6 -1
  120. package/dist/spa/src/stores/toast.ts +22 -3
  121. package/dist/spa/src/types/Back.ts +158 -22
  122. package/dist/spa/src/types/Common.ts +81 -32
  123. package/dist/spa/src/types/FrontendAPI.ts +31 -5
  124. package/dist/spa/src/types/adapters/CaptchaAdapter.ts +34 -0
  125. package/dist/spa/src/types/adapters/CompletionAdapter.ts +25 -0
  126. package/dist/spa/src/types/adapters/EmailAdapter.ts +27 -0
  127. package/dist/spa/src/types/adapters/ImageGenerationAdapter.ts +50 -0
  128. package/dist/spa/src/types/adapters/ImageVisionAdapter.ts +30 -0
  129. package/dist/spa/src/types/adapters/KeyValueAdapter.ts +16 -0
  130. package/dist/spa/src/types/adapters/OAuth2Adapter.ts +34 -0
  131. package/dist/spa/src/types/adapters/StorageAdapter.ts +73 -0
  132. package/dist/spa/src/types/adapters/index.ts +8 -0
  133. package/dist/spa/src/utils.ts +279 -9
  134. package/dist/spa/src/views/CreateView.vue +18 -19
  135. package/dist/spa/src/views/EditView.vue +25 -19
  136. package/dist/spa/src/views/ListView.vue +139 -86
  137. package/dist/spa/src/views/LoginView.vue +37 -37
  138. package/dist/spa/src/views/ResourceParent.vue +2 -2
  139. package/dist/spa/src/views/SettingsView.vue +121 -0
  140. package/dist/spa/src/views/ShowView.vue +59 -39
  141. package/dist/spa/src/websocket.ts +6 -1
  142. package/dist/spa/tsconfig.app.json +1 -1
  143. package/dist/spa/vite.config.ts +45 -2
  144. package/dist/types/Back.d.ts +134 -14
  145. package/dist/types/Back.d.ts.map +1 -1
  146. package/dist/types/Back.js +15 -0
  147. package/dist/types/Back.js.map +1 -1
  148. package/dist/types/Common.d.ts +96 -29
  149. package/dist/types/Common.d.ts.map +1 -1
  150. package/dist/types/Common.js.map +1 -1
  151. package/dist/types/FrontendAPI.d.ts +31 -3
  152. package/dist/types/FrontendAPI.d.ts.map +1 -1
  153. package/dist/types/FrontendAPI.js.map +1 -1
  154. package/dist/types/adapters/CaptchaAdapter.d.ts +30 -0
  155. package/dist/types/adapters/CaptchaAdapter.d.ts.map +1 -0
  156. package/dist/types/adapters/CaptchaAdapter.js +5 -0
  157. package/dist/types/adapters/CaptchaAdapter.js.map +1 -0
  158. package/dist/types/adapters/CompletionAdapter.d.ts +20 -0
  159. package/dist/types/adapters/CompletionAdapter.d.ts.map +1 -0
  160. package/dist/types/adapters/CompletionAdapter.js +2 -0
  161. package/dist/types/adapters/CompletionAdapter.js.map +1 -0
  162. package/dist/types/adapters/EmailAdapter.d.ts +20 -0
  163. package/dist/types/adapters/EmailAdapter.d.ts.map +1 -0
  164. package/dist/types/adapters/EmailAdapter.js +2 -0
  165. package/dist/types/adapters/EmailAdapter.js.map +1 -0
  166. package/dist/types/adapters/ImageGenerationAdapter.d.ts +37 -0
  167. package/dist/types/adapters/ImageGenerationAdapter.d.ts.map +1 -0
  168. package/dist/types/adapters/ImageGenerationAdapter.js +2 -0
  169. package/dist/types/adapters/ImageGenerationAdapter.js.map +1 -0
  170. package/dist/types/adapters/ImageVisionAdapter.d.ts +25 -0
  171. package/dist/types/adapters/ImageVisionAdapter.d.ts.map +1 -0
  172. package/dist/types/adapters/ImageVisionAdapter.js +2 -0
  173. package/dist/types/adapters/ImageVisionAdapter.js.map +1 -0
  174. package/dist/types/adapters/KeyValueAdapter.d.ts +10 -0
  175. package/dist/types/adapters/KeyValueAdapter.d.ts.map +1 -0
  176. package/dist/types/adapters/KeyValueAdapter.js +2 -0
  177. package/dist/types/adapters/KeyValueAdapter.js.map +1 -0
  178. package/dist/types/adapters/OAuth2Adapter.d.ts +32 -0
  179. package/dist/types/adapters/OAuth2Adapter.d.ts.map +1 -0
  180. package/dist/types/adapters/OAuth2Adapter.js +2 -0
  181. package/dist/types/adapters/OAuth2Adapter.js.map +1 -0
  182. package/dist/types/adapters/StorageAdapter.d.ts +63 -0
  183. package/dist/types/adapters/StorageAdapter.d.ts.map +1 -0
  184. package/dist/types/adapters/StorageAdapter.js +2 -0
  185. package/dist/types/adapters/StorageAdapter.js.map +1 -0
  186. package/dist/types/adapters/index.d.ts +9 -0
  187. package/dist/types/adapters/index.d.ts.map +1 -0
  188. package/dist/types/adapters/index.js +2 -0
  189. package/dist/types/adapters/index.js.map +1 -0
  190. package/package.json +4 -2
  191. package/dist/spa/src/types/Adapters.ts +0 -213
  192. package/dist/types/Adapters.d.ts +0 -168
  193. package/dist/types/Adapters.d.ts.map +0 -1
  194. package/dist/types/Adapters.js +0 -2
  195. package/dist/types/Adapters.js.map +0 -1
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Interface for Captcha adapters.
3
+ */
4
+
5
+ export interface CaptchaAdapter {
6
+ /**
7
+ * Returns the script source URL for the captcha widget.
8
+ */
9
+ getScriptSrc(): string;
10
+
11
+ /**
12
+ * Returns the site key for the captcha.
13
+ */
14
+ getSiteKey(): string;
15
+
16
+ /**
17
+ * Returns the widget ID for the captcha.
18
+ */
19
+ getWidgetId(): string;
20
+
21
+ /**
22
+ * Returns the script HTML for the captcha widget.
23
+ */
24
+ getRenderWidgetCode(): string;
25
+
26
+ /**
27
+ * Returns the function name to render the captcha widget.
28
+ */
29
+ getRenderWidgetFunctionName(): string;
30
+ /**
31
+ * Validates the captcha token.
32
+ */
33
+ validate(token: string, ip: string): Promise<Record<string, any>>;
34
+ }
@@ -0,0 +1,25 @@
1
+ export interface CompletionAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readbale error if the configuration is invalid.
6
+ */
7
+ validate(): void;
8
+
9
+ /**
10
+ * This method should return a text completion based on the provided content and stop sequence.
11
+ * @param content - The input text to complete
12
+ * @param stop - An array of stop sequences to indicate where to stop the completion
13
+ * @param maxTokens - The maximum number of tokens to generate
14
+ * @returns A promise that resolves to an object containing the completed text and other metadata
15
+ */
16
+ complete(
17
+ content: string,
18
+ stop: string[],
19
+ maxTokens: number,
20
+ ): Promise<{
21
+ content?: string;
22
+ finishReason?: string;
23
+ error?: string;
24
+ }>;
25
+ }
@@ -0,0 +1,27 @@
1
+ export interface EmailAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readable error if the configuration is invalid.
6
+ */
7
+ validate(): Promise<void>;
8
+
9
+ /**
10
+ * This method should send an email using the adapter
11
+ * @param from - The sender's email address
12
+ * @param to - The recipient's email address
13
+ * @param text - The plain text version of the email
14
+ * @param html - The HTML version of the email
15
+ * @param subject - The subject of the email
16
+ */
17
+ sendEmail(
18
+ from: string,
19
+ to: string,
20
+ text: string,
21
+ html: string,
22
+ subject: string
23
+ ): Promise<{
24
+ error?: string;
25
+ ok?: boolean;
26
+ }>;
27
+ }
@@ -0,0 +1,50 @@
1
+ export interface ImageGenerationAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readbale error if the configuration is invalid.
6
+ */
7
+ validate(): void;
8
+
9
+ /**
10
+ * Return max number of images which model can generate in one request
11
+ */
12
+ outputImagesMaxCountSupported(): number;
13
+
14
+ /**
15
+ * Return the list of supported dimensions in format ["100x500", "200x200"]
16
+ */
17
+ outputDimensionsSupported(): string[];
18
+
19
+ /**
20
+ * Input file extension supported
21
+ */
22
+ inputFileExtensionSupported(): string[];
23
+
24
+ /**
25
+ * This method should generate an image based on the provided prompt and input files.
26
+ * @param prompt - The prompt to generate the image
27
+ * @param inputFiles - An array of input file paths (optional)
28
+ * @param n - The number of images to generate (default is 1)
29
+ * @param size - The size of the generated image (default is the lowest dimension supported)
30
+ * @returns A promise that resolves to an object containing the generated image URLs and any error message
31
+ */
32
+ generate({
33
+ prompt,
34
+ inputFiles,
35
+ n,
36
+ size,
37
+ }: {
38
+ prompt: string,
39
+ inputFiles: string[],
40
+
41
+ // default = lowest dimension supported
42
+ size?: string,
43
+
44
+ // one by default
45
+ n?: number
46
+ }): Promise<{
47
+ imageURLs?: string[];
48
+ error?: string;
49
+ }>;
50
+ }
@@ -0,0 +1,30 @@
1
+ export interface ImageVisionAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readable error if the configuration is invalid.
6
+ */
7
+ validate(): void;
8
+
9
+ /**
10
+ * Input file extension supported
11
+ */
12
+ inputFileExtensionSupported(): string[];
13
+
14
+ /**
15
+ * This method should generate an image based on the provided prompt and input files.
16
+ * @param prompt - The prompt to generate the image
17
+ * @param inputFileUrls - An array of input file paths (optional)
18
+ * @returns A promise that resolves to an object containing the generated image and any error message
19
+ */
20
+ generate({
21
+ prompt,
22
+ inputFileUrls,
23
+ }: {
24
+ prompt: string,
25
+ inputFileUrls: string[],
26
+ }): Promise<{
27
+ response: string;
28
+ error?: string;
29
+ }>;
30
+ }
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * Might have implementations like RAM, Redis, Memcached,
4
+ *
5
+ */
6
+ export interface KeyValueAdapter {
7
+
8
+ get(key: string): Promise<string | null>;
9
+
10
+ set(key: string, value: string, expiresInSeconds?: number): Promise<void>;
11
+
12
+ delete(key: string): Promise<void>;
13
+
14
+ }
15
+
16
+
@@ -0,0 +1,34 @@
1
+
2
+ /**
3
+ * This interface is used to implement OAuth2 authentication adapters.
4
+ */
5
+ export interface OAuth2Adapter {
6
+ /**
7
+ * This method should return navigatable URL to the OAuth2 provider authentication page.
8
+ */
9
+ getAuthUrl(): string;
10
+
11
+ /**
12
+ * This method should return the token from the OAuth2 provider using the provided code and redirect URI.
13
+ * @param code - The authorization code received from the OAuth2 provider
14
+ * @param redirect_uri - The redirect URI used in the authentication request
15
+ * @returns A promise that resolves to an object containing the email address of the authenticated user
16
+ */
17
+ getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>;
18
+
19
+ /**
20
+ * This method should return text (content) of SVG icon which will be used in the UI.
21
+ * Use official SVG icons with simplest possible conent, omit icons which have base64 encoded raster images inside.
22
+ */
23
+ getIcon(): string;
24
+
25
+ /**
26
+ * This method should return the text to be displayed on the button in the UI
27
+ */
28
+ getButtonText?(): string;
29
+
30
+ /**
31
+ * This method should return the name of the adapter
32
+ */
33
+ getName?(): string;
34
+ }
@@ -0,0 +1,73 @@
1
+
2
+ /**
3
+ * Each storage adapter should support two ways of storing files:
4
+ * - publically (public URL) - the file can be accessed by anyone by HTTP GET / HEAD request with plain URL
5
+ * - privately (presigned URL) - the file can be accessed by anyone by HTTP GET / HEAD request only with presigned URLs, limited by expiration time
6
+ *
7
+ */
8
+ export interface StorageAdapter {
9
+ /**
10
+ * This method should return the presigned URL for the given key capable of upload (adapter user will call PUT multipart form data to this URL within expiresIn seconds after link generation).
11
+ * By default file which will be uploaded on PUT should be marked for deletion. So if during 24h it is not marked for not deletion, it adapter should delete it forever.
12
+ * The PUT method should fail if the file already exists.
13
+ *
14
+ * Adapter user will always pass next parameters to the method:
15
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
16
+ * @param expiresIn - The expiration time in seconds for the presigned URL
17
+ * @param contentType - The content type of the file to be uploaded, e.g. "image/png"
18
+ *
19
+ * @returns A promise that resolves to an object containing the upload URL and any extra parameters which should be sent with PUT multipart form data
20
+ */
21
+ getUploadSignedUrl(key: string, contentType: string, expiresIn?: number): Promise<{
22
+ uploadUrl: string;
23
+ uploadExtraParams?: Record<string, string>;
24
+ }>;
25
+
26
+ /**
27
+ * This method should return the URL for the given key capable of download (200 GET request with response body or 200 HEAD request without response body).
28
+ * If adapter configured to store objects publically, this method should return the public URL of the file.
29
+ * If adapter configured to no allow public storing of images, this method should return the presigned URL for the file.
30
+ *
31
+ * @param key - The key of the file to be downloaded e.g. "uploads/file.txt"
32
+ * @param expiresIn - The expiration time in seconds for the presigned URL
33
+ */
34
+ getDownloadUrl(key: string, expiresIn?: number): Promise<string>;
35
+
36
+ /**
37
+ * This method should mark the file for deletion.
38
+ * If file is marked for delation and exists more then 24h (since creation date) it should be deleted.
39
+ * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
40
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
41
+ */
42
+ markKeyForDeletation(key: string): Promise<void>;
43
+
44
+
45
+ /**
46
+ * This method should mark the file to not be deleted.
47
+ * This method should be used to cancel the deletion of the file if it was marked for deletion.
48
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
49
+ */
50
+ markKeyForNotDeletation(key: string): Promise<void>;
51
+
52
+
53
+ /**
54
+ * This method can start needed schedullers, cron jobs, etc. to clean up the storage.
55
+ * @param adapterUserUniqueRepresentation - The unique representation of the plugin instance which
56
+ * wil use this adapter. Might be handy if you need to distinguish between different instances of the same adapter.
57
+ */
58
+ setupLifecycle(adapterUserUniqueRepresentation: string): Promise<void>;
59
+
60
+ /**
61
+ * If adapter is configured to publically, this method should return true.
62
+ */
63
+ objectCanBeAccesedPublicly(): Promise<boolean>;
64
+
65
+ /**
66
+ * This method should return the key as a data URL (base64 encoded string).
67
+ * @param key - The key of the file to be converted to a data URL
68
+ * @returns A promise that resolves to a string containing the data URL
69
+ */
70
+ getKeyAsDataURL(key: string): Promise<string>;
71
+ }
72
+
73
+
@@ -0,0 +1,8 @@
1
+ export type { EmailAdapter } from './EmailAdapter.js';
2
+ export type { CompletionAdapter } from './CompletionAdapter.js';
3
+ export type { ImageGenerationAdapter } from './ImageGenerationAdapter.js';
4
+ export type { KeyValueAdapter } from './KeyValueAdapter.js';
5
+ export type { ImageVisionAdapter } from './ImageVisionAdapter.js';
6
+ export type { OAuth2Adapter } from './OAuth2Adapter.js';
7
+ export type { StorageAdapter } from './StorageAdapter.js';
8
+ export type { CaptchaAdapter } from './CaptchaAdapter.js';
@@ -1,24 +1,30 @@
1
1
  import { onMounted, ref, resolveComponent } from 'vue';
2
2
  import type { CoreConfig } from './spa_types/core';
3
- import type { ValidationObject } from './types/AdminForthConfig';
3
+ import type { ValidationObject } from './types/Common.js';
4
4
  import router from "./router";
5
5
  import { useCoreStore } from './stores/core';
6
6
  import { useUserStore } from './stores/user';
7
7
  import { Dropdown } from 'flowbite';
8
8
  import adminforth from './adminforth';
9
9
  import sanitizeHtml from 'sanitize-html'
10
+ import debounce from 'debounce';
11
+ import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
10
12
 
11
13
  const LS_LANG_KEY = `afLanguage`;
14
+ const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
15
+ const ITEMS_PER_PAGE_LIMIT = 100;
12
16
 
13
- export async function callApi({path, method, body=undefined}: {
17
+ export async function callApi({path, method, body, headers}: {
14
18
  path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
15
19
  body?: any
20
+ headers?: Record<string, string>
16
21
  }): Promise<any> {
17
22
  const options = {
18
23
  method,
19
24
  headers: {
20
25
  'Content-Type': 'application/json',
21
26
  'accept-language': localStorage.getItem(LS_LANG_KEY) || 'en',
27
+ ...headers
22
28
  },
23
29
  body: JSON.stringify(body),
24
30
  };
@@ -27,6 +33,7 @@ export async function callApi({path, method, body=undefined}: {
27
33
  const r = await fetch(fullPath, options);
28
34
  if (r.status == 401 ) {
29
35
  useUserStore().unauthorize();
36
+ useCoreStore().resetAdminUser();
30
37
  await router.push({ name: 'login' });
31
38
  return null;
32
39
  }
@@ -46,7 +53,7 @@ export async function callApi({path, method, body=undefined}: {
46
53
 
47
54
  export async function callAdminForthApi({ path, method, body=undefined, headers=undefined }: {
48
55
  path: string,
49
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
56
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
50
57
  body?: any,
51
58
  headers?: Record<string, string>
52
59
  }): Promise<any> {
@@ -92,13 +99,14 @@ export const loadFile = (file: string) => {
92
99
  }
93
100
 
94
101
  export function checkEmptyValues(value: any, viewType: 'show' | 'list' ) {
95
- const config: CoreConfig | {} = useCoreStore().config;
102
+ const config: CoreConfig | {} | null = useCoreStore().config;
96
103
  let emptyFieldPlaceholder = '';
97
- if (config.emptyFieldPlaceholder) {
98
- if(typeof config.emptyFieldPlaceholder === 'string') {
99
- emptyFieldPlaceholder = config.emptyFieldPlaceholder;
104
+ if (config && 'emptyFieldPlaceholder' in config) {
105
+ const efp = (config as CoreConfig).emptyFieldPlaceholder;
106
+ if(typeof efp === 'string') {
107
+ emptyFieldPlaceholder = efp;
100
108
  } else {
101
- emptyFieldPlaceholder = config.emptyFieldPlaceholder?.[viewType] || '';
109
+ emptyFieldPlaceholder = efp?.[viewType] || '';
102
110
  }
103
111
  if (value === null || value === undefined || value === '') {
104
112
  return emptyFieldPlaceholder;
@@ -179,7 +187,7 @@ export function verySimpleHash(str: string): string {
179
187
  return `${str.split('').reduce((a, b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0)}`;
180
188
  }
181
189
 
182
- export function humanifySize(size) {
190
+ export function humanifySize(size: number) {
183
191
  if (!size) {
184
192
  return '';
185
193
  }
@@ -208,4 +216,266 @@ export function protectAgainstXSS(value: string) {
208
216
  'img': [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]
209
217
  }
210
218
  });
219
+ }
220
+
221
+ export function isPolymorphicColumn(column: any): boolean {
222
+ return !!(column.foreignResource?.polymorphicResources && column.foreignResource.polymorphicResources.length > 0);
223
+ }
224
+
225
+ export function handleForeignResourcePagination(
226
+ column: any,
227
+ items: any[],
228
+ emptyResultsCount: number = 0,
229
+ isSearching: boolean = false
230
+ ): { hasMore: boolean; emptyResultsCount: number } {
231
+ const isPolymorphic = isPolymorphicColumn(column);
232
+
233
+ if (isPolymorphic) {
234
+ if (isSearching) {
235
+ return {
236
+ hasMore: items.length > 0,
237
+ emptyResultsCount: 0
238
+ };
239
+ } else {
240
+ if (items.length === 0) {
241
+ const newEmptyCount = emptyResultsCount + 1;
242
+ return {
243
+ hasMore: newEmptyCount < MAX_CONSECUTIVE_EMPTY_RESULTS, // Stop loading after 2 consecutive empty results
244
+ emptyResultsCount: newEmptyCount
245
+ };
246
+ } else {
247
+ return {
248
+ hasMore: true,
249
+ emptyResultsCount: 0
250
+ };
251
+ }
252
+ }
253
+ } else {
254
+ return {
255
+ hasMore: items.length === ITEMS_PER_PAGE_LIMIT,
256
+ emptyResultsCount: 0
257
+ };
258
+ }
259
+ }
260
+
261
+ export async function loadMoreForeignOptions({
262
+ columnName,
263
+ searchTerm = '',
264
+ columns,
265
+ resourceId,
266
+ columnOptions,
267
+ columnLoadingState,
268
+ columnOffsets,
269
+ columnEmptyResultsCount
270
+ }: {
271
+ columnName: string;
272
+ searchTerm?: string;
273
+ columns: any[];
274
+ resourceId: string;
275
+ columnOptions: any;
276
+ columnLoadingState: any;
277
+ columnOffsets: any;
278
+ columnEmptyResultsCount: any;
279
+ }) {
280
+ const column = columns?.find(c => c.name === columnName);
281
+ if (!column || !column.foreignResource) return;
282
+
283
+ const state = columnLoadingState[columnName];
284
+ if (state.loading || !state.hasMore) return;
285
+
286
+ state.loading = true;
287
+
288
+ try {
289
+ const list = await callAdminForthApi({
290
+ method: 'POST',
291
+ path: `/get_resource_foreign_data`,
292
+ body: {
293
+ resourceId,
294
+ column: columnName,
295
+ limit: 100,
296
+ offset: columnOffsets[columnName],
297
+ search: searchTerm,
298
+ },
299
+ });
300
+
301
+ if (!list || !Array.isArray(list.items)) {
302
+ console.warn(`Unexpected API response for column ${columnName}:`, list);
303
+ state.hasMore = false;
304
+ return;
305
+ }
306
+
307
+ if (!columnOptions.value) {
308
+ columnOptions.value = {};
309
+ }
310
+ if (!columnOptions.value[columnName]) {
311
+ columnOptions.value[columnName] = [];
312
+ }
313
+ columnOptions.value[columnName].push(...list.items);
314
+
315
+ columnOffsets[columnName] += 100;
316
+
317
+ const paginationResult = handleForeignResourcePagination(
318
+ column,
319
+ list.items,
320
+ columnEmptyResultsCount[columnName] || 0,
321
+ false // not searching
322
+ );
323
+
324
+ columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
325
+ state.hasMore = paginationResult.hasMore;
326
+
327
+ } catch (error) {
328
+ console.error('Error loading more options:', error);
329
+ } finally {
330
+ state.loading = false;
331
+ }
332
+ }
333
+
334
+ export async function searchForeignOptions({
335
+ columnName,
336
+ searchTerm,
337
+ columns,
338
+ resourceId,
339
+ columnOptions,
340
+ columnLoadingState,
341
+ columnOffsets,
342
+ columnEmptyResultsCount
343
+ }: {
344
+ columnName: string;
345
+ searchTerm: string;
346
+ columns: any[];
347
+ resourceId: string;
348
+ columnOptions: any;
349
+ columnLoadingState: any;
350
+ columnOffsets: any;
351
+ columnEmptyResultsCount: any;
352
+ }) {
353
+ const column = columns?.find(c => c.name === columnName);
354
+
355
+ if (!column || !column.foreignResource || !column.foreignResource.searchableFields) {
356
+ return;
357
+ }
358
+
359
+ const state = columnLoadingState[columnName];
360
+ if (state.loading) return;
361
+
362
+ state.loading = true;
363
+
364
+ try {
365
+ const list = await callAdminForthApi({
366
+ method: 'POST',
367
+ path: `/get_resource_foreign_data`,
368
+ body: {
369
+ resourceId,
370
+ column: columnName,
371
+ limit: 100,
372
+ offset: 0,
373
+ search: searchTerm,
374
+ },
375
+ });
376
+
377
+ if (!list || !Array.isArray(list.items)) {
378
+ console.warn(`Unexpected API response for column ${columnName}:`, list);
379
+ state.hasMore = false;
380
+ return;
381
+ }
382
+
383
+ if (!columnOptions.value) {
384
+ columnOptions.value = {};
385
+ }
386
+ columnOptions.value[columnName] = list.items;
387
+ columnOffsets[columnName] = 100;
388
+
389
+ const paginationResult = handleForeignResourcePagination(
390
+ column,
391
+ list.items,
392
+ columnEmptyResultsCount[columnName] || 0,
393
+ true // is searching
394
+ );
395
+
396
+ columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
397
+ state.hasMore = paginationResult.hasMore;
398
+
399
+ } catch (error) {
400
+ console.error('Error searching options:', error);
401
+ } finally {
402
+ state.loading = false;
403
+ }
404
+ }
405
+
406
+ export function createSearchInputHandlers(
407
+ columns: any[],
408
+ searchFunction: (columnName: string, searchTerm: string) => void,
409
+ getDebounceMs?: (column: any) => number
410
+ ) {
411
+ if (!columns) return {};
412
+
413
+ return columns.reduce((acc, c) => {
414
+ if (c.foreignResource && c.foreignResource.searchableFields) {
415
+ const debounceMs = getDebounceMs ? getDebounceMs(c) : 300;
416
+ return {
417
+ ...acc,
418
+ [c.name]: debounce((searchTerm: string) => {
419
+ searchFunction(c.name, searchTerm);
420
+ }, debounceMs),
421
+ };
422
+ }
423
+ return acc;
424
+ }, {} as Record<string, (searchTerm: string) => void>);
425
+ }
426
+
427
+ export function checkShowIf(c: AdminForthResourceColumnInputCommon, record: Record<string, any>) {
428
+ if (!c.showIf) return true;
429
+
430
+ const evaluatePredicate = (predicate: Predicate): boolean => {
431
+ const results: boolean[] = [];
432
+
433
+ if ("$and" in predicate) {
434
+ results.push(predicate.$and.every(evaluatePredicate));
435
+ }
436
+
437
+ if ("$or" in predicate) {
438
+ results.push(predicate.$or.some(evaluatePredicate));
439
+ }
440
+
441
+ const fieldEntries = Object.entries(predicate).filter(([key]) => !key.startsWith('$'));
442
+ if (fieldEntries.length > 0) {
443
+ const fieldResult = fieldEntries.every(([field, condition]) => {
444
+ const recordValue = record[field];
445
+
446
+ if (condition === undefined) {
447
+ return true;
448
+ }
449
+ if (typeof condition !== "object" || condition === null) {
450
+ return recordValue === condition;
451
+ }
452
+
453
+ if ("$eq" in condition) return recordValue === condition.$eq;
454
+ if ("$not" in condition) return recordValue !== condition.$not;
455
+ if ("$gt" in condition) return recordValue > condition.$gt;
456
+ if ("$gte" in condition) return recordValue >= condition.$gte;
457
+ if ("$lt" in condition) return recordValue < condition.$lt;
458
+ if ("$lte" in condition) return recordValue <= condition.$lte;
459
+ if ("$in" in condition) return (Array.isArray(condition.$in) && condition.$in.includes(recordValue));
460
+ if ("$nin" in condition) return (Array.isArray(condition.$nin) && !condition.$nin.includes(recordValue));
461
+ if ("$includes" in condition)
462
+ return (
463
+ Array.isArray(recordValue) &&
464
+ recordValue.includes(condition.$includes)
465
+ );
466
+ if ("$nincludes" in condition)
467
+ return (
468
+ Array.isArray(recordValue) &&
469
+ !recordValue.includes(condition.$nicludes)
470
+ );
471
+
472
+ return true;
473
+ });
474
+ results.push(fieldResult);
475
+ }
476
+
477
+ return results.every(result => result);
478
+ };
479
+
480
+ return evaluatePredicate(c.showIf);
211
481
  }