adminforth 1.21.0 → 1.22.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.
@@ -1,6 +1,19 @@
1
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-readbale error if the configuration is invalid.
6
+ */
2
7
  validate(): Promise<void>;
3
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
+ */
4
17
  sendEmail(
5
18
  from: string,
6
19
  to: string,
@@ -15,8 +28,19 @@ export interface EmailAdapter {
15
28
 
16
29
  export interface CompletionAdapter {
17
30
 
31
+ /**
32
+ * This method is called to validate the configuration of the adapter
33
+ * and should throw a clear user-readbale error if the configuration is invalid.
34
+ */
18
35
  validate(): void;
19
36
 
37
+ /**
38
+ * This method should return a text completion based on the provided content and stop sequence.
39
+ * @param content - The input text to complete
40
+ * @param stop - An array of stop sequences to indicate where to stop the completion
41
+ * @param maxTokens - The maximum number of tokens to generate
42
+ * @returns A promise that resolves to an object containing the completed text and other metadata
43
+ */
20
44
  complete(
21
45
  content: string,
22
46
  stop: string[],
@@ -30,10 +54,14 @@ export interface CompletionAdapter {
30
54
 
31
55
  export interface ImageGenerationAdapter {
32
56
 
57
+ /**
58
+ * This method is called to validate the configuration of the adapter
59
+ * and should throw a clear user-readbale error if the configuration is invalid.
60
+ */
33
61
  validate(): void;
34
62
 
35
63
  /**
36
- * Return 1 or 10, or Infinity if the adapter supports multiple images
64
+ * Return max number of images which model can generate in one request
37
65
  */
38
66
  outputImagesMaxCountSupported(): number;
39
67
 
@@ -47,6 +75,14 @@ export interface ImageGenerationAdapter {
47
75
  */
48
76
  inputFileExtensionSupported(): string[];
49
77
 
78
+ /**
79
+ * This method should generate an image based on the provided prompt and input files.
80
+ * @param prompt - The prompt to generate the image
81
+ * @param inputFiles - An array of input file paths (optional)
82
+ * @param n - The number of images to generate (default is 1)
83
+ * @param size - The size of the generated image (default is the lowest dimension supported)
84
+ * @returns A promise that resolves to an object containing the generated image URLs and any error message
85
+ */
50
86
  generate({
51
87
  prompt,
52
88
  inputFiles,
@@ -68,11 +104,91 @@ export interface ImageGenerationAdapter {
68
104
  }
69
105
 
70
106
 
71
-
107
+ /**
108
+ * This interface is used to implement OAuth2 authentication adapters.
109
+ */
72
110
  export interface OAuth2Adapter {
111
+ /**
112
+ * This method should return navigatable URL to the OAuth2 provider authentication page.
113
+ */
73
114
  getAuthUrl(): string;
115
+
116
+ /**
117
+ * This method should return the token from the OAuth2 provider using the provided code and redirect URI.
118
+ * @param code - The authorization code received from the OAuth2 provider
119
+ * @param redirect_uri - The redirect URI used in the authentication request
120
+ * @returns A promise that resolves to an object containing the email address of the authenticated user
121
+ */
74
122
  getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>;
123
+
124
+ /**
125
+ * This method should return text (content) of SVG icon which will be used in the UI.
126
+ * Use official SVG icons with simplest possible conent, omit icons which have base64 encoded raster images inside.
127
+ */
75
128
  getIcon(): string;
129
+
130
+ /**
131
+ * This method should return the text to be displayed on the button in the UI
132
+ */
76
133
  getButtonText?(): string;
134
+
135
+ /**
136
+ * This method should return the name of the adapter
137
+ */
77
138
  getName?(): string;
78
139
  }
140
+
141
+
142
+ export interface StorageAdapter {
143
+ /**
144
+ * 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).
145
+ * 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.
146
+ * The PUT method should fail if the file already exists.
147
+ *
148
+ * Adapter user will always pass next parameters to the method:
149
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
150
+ * @param expiresIn - The expiration time in seconds for the presigned URL
151
+ * @param contentType - The content type of the file to be uploaded, e.g. "image/png"
152
+ *
153
+ * @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
154
+ */
155
+ getUploadSignedUrl(key: string, contentType: string, expiresIn?: number): Promise<{
156
+ uploadUrl: string;
157
+ uploadExtraParams?: Record<string, string>;
158
+ }>;
159
+
160
+ /**
161
+ * 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).
162
+ * If adapter configured to use public storage, this method should return the public URL of the file.
163
+ * If adapter configured to use private storage, this method should return the presigned URL for the file.
164
+ *
165
+ * @param key - The key of the file to be downloaded e.g. "uploads/file.txt"
166
+ * @param expiresIn - The expiration time in seconds for the presigned URL
167
+ */
168
+ getDownloadUrl(key: string, expiresIn?: number): Promise<string>;
169
+
170
+ /**
171
+ * This method should mark the file for deletion.
172
+ * If file is marked for delation and exists more then 24h (since creation date) it should be deleted.
173
+ * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
174
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
175
+ */
176
+ markKeyForDeletation(key: string): Promise<string>;
177
+
178
+
179
+ /**
180
+ * This method should mark the file to not be deleted.
181
+ * This method should be used to cancel the deletion of the file if it was marked for deletion.
182
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
183
+ */
184
+ markKeyForNotDeletation(key: string): Promise<string>;
185
+
186
+
187
+ /**
188
+ * This method can start needed schedullers, cron jobs, etc. to clean up the storage.
189
+ */
190
+ setupLifecycle(): Promise<void>;
191
+
192
+ }
193
+
194
+
@@ -30,9 +30,9 @@ export async function callApi({path, method, body=undefined}: {
30
30
  return null;
31
31
  }
32
32
  return await r.json();
33
- } catch(e){
33
+ } catch(e) {
34
34
  adminforth.alert({variant:'danger', message: window.i18n?.global?.t('Something went wrong, please try again later'),})
35
- console.error(`error in callApi ${path}`,e);
35
+ console.error(`error in callApi ${path}`, e);
36
36
  }
37
37
  }
38
38
 
@@ -1,12 +1,35 @@
1
1
  export interface EmailAdapter {
2
+ /**
3
+ * This method is called to validate the configuration of the adapter
4
+ * and should throw a clear user-readbale error if the configuration is invalid.
5
+ */
2
6
  validate(): Promise<void>;
7
+ /**
8
+ * This method should send an email using the adapter
9
+ * @param from - The sender's email address
10
+ * @param to - The recipient's email address
11
+ * @param text - The plain text version of the email
12
+ * @param html - The HTML version of the email
13
+ * @param subject - The subject of the email
14
+ */
3
15
  sendEmail(from: string, to: string, text: string, html: string, subject: string): Promise<{
4
16
  error?: string;
5
17
  ok?: boolean;
6
18
  }>;
7
19
  }
8
20
  export interface CompletionAdapter {
21
+ /**
22
+ * This method is called to validate the configuration of the adapter
23
+ * and should throw a clear user-readbale error if the configuration is invalid.
24
+ */
9
25
  validate(): void;
26
+ /**
27
+ * This method should return a text completion based on the provided content and stop sequence.
28
+ * @param content - The input text to complete
29
+ * @param stop - An array of stop sequences to indicate where to stop the completion
30
+ * @param maxTokens - The maximum number of tokens to generate
31
+ * @returns A promise that resolves to an object containing the completed text and other metadata
32
+ */
10
33
  complete(content: string, stop: string[], maxTokens: number): Promise<{
11
34
  content?: string;
12
35
  finishReason?: string;
@@ -14,9 +37,13 @@ export interface CompletionAdapter {
14
37
  }>;
15
38
  }
16
39
  export interface ImageGenerationAdapter {
40
+ /**
41
+ * This method is called to validate the configuration of the adapter
42
+ * and should throw a clear user-readbale error if the configuration is invalid.
43
+ */
17
44
  validate(): void;
18
45
  /**
19
- * Return 1 or 10, or Infinity if the adapter supports multiple images
46
+ * Return max number of images which model can generate in one request
20
47
  */
21
48
  outputImagesMaxCountSupported(): number;
22
49
  /**
@@ -27,6 +54,14 @@ export interface ImageGenerationAdapter {
27
54
  * Input file extension supported
28
55
  */
29
56
  inputFileExtensionSupported(): string[];
57
+ /**
58
+ * This method should generate an image based on the provided prompt and input files.
59
+ * @param prompt - The prompt to generate the image
60
+ * @param inputFiles - An array of input file paths (optional)
61
+ * @param n - The number of images to generate (default is 1)
62
+ * @param size - The size of the generated image (default is the lowest dimension supported)
63
+ * @returns A promise that resolves to an object containing the generated image URLs and any error message
64
+ */
30
65
  generate({ prompt, inputFiles, n, size, }: {
31
66
  prompt: string;
32
67
  inputFiles: string[];
@@ -37,13 +72,79 @@ export interface ImageGenerationAdapter {
37
72
  error?: string;
38
73
  }>;
39
74
  }
75
+ /**
76
+ * This interface is used to implement OAuth2 authentication adapters.
77
+ */
40
78
  export interface OAuth2Adapter {
79
+ /**
80
+ * This method should return navigatable URL to the OAuth2 provider authentication page.
81
+ */
41
82
  getAuthUrl(): string;
83
+ /**
84
+ * This method should return the token from the OAuth2 provider using the provided code and redirect URI.
85
+ * @param code - The authorization code received from the OAuth2 provider
86
+ * @param redirect_uri - The redirect URI used in the authentication request
87
+ * @returns A promise that resolves to an object containing the email address of the authenticated user
88
+ */
42
89
  getTokenFromCode(code: string, redirect_uri: string): Promise<{
43
90
  email: string;
44
91
  }>;
92
+ /**
93
+ * This method should return text (content) of SVG icon which will be used in the UI.
94
+ * Use official SVG icons with simplest possible conent, omit icons which have base64 encoded raster images inside.
95
+ */
45
96
  getIcon(): string;
97
+ /**
98
+ * This method should return the text to be displayed on the button in the UI
99
+ */
46
100
  getButtonText?(): string;
101
+ /**
102
+ * This method should return the name of the adapter
103
+ */
47
104
  getName?(): string;
48
105
  }
106
+ export interface StorageAdapter {
107
+ /**
108
+ * 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).
109
+ * 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.
110
+ * The PUT method should fail if the file already exists.
111
+ *
112
+ * Adapter user will always pass next parameters to the method:
113
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
114
+ * @param expiresIn - The expiration time in seconds for the presigned URL
115
+ * @param contentType - The content type of the file to be uploaded, e.g. "image/png"
116
+ *
117
+ * @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
118
+ */
119
+ getUploadSignedUrl(key: string, contentType: string, expiresIn?: number): Promise<{
120
+ uploadUrl: string;
121
+ uploadExtraParams?: Record<string, string>;
122
+ }>;
123
+ /**
124
+ * 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).
125
+ * If adapter configured to use public storage, this method should return the public URL of the file.
126
+ * If adapter configured to use private storage, this method should return the presigned URL for the file.
127
+ *
128
+ * @param key - The key of the file to be downloaded e.g. "uploads/file.txt"
129
+ * @param expiresIn - The expiration time in seconds for the presigned URL
130
+ */
131
+ getDownloadUrl(key: string, expiresIn?: number): Promise<string>;
132
+ /**
133
+ * This method should mark the file for deletion.
134
+ * If file is marked for delation and exists more then 24h (since creation date) it should be deleted.
135
+ * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
136
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
137
+ */
138
+ markKeyForDeletation(key: string): Promise<string>;
139
+ /**
140
+ * This method should mark the file to not be deleted.
141
+ * This method should be used to cancel the deletion of the file if it was marked for deletion.
142
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
143
+ */
144
+ markKeyForNotDeletation(key: string): Promise<string>;
145
+ /**
146
+ * This method can start needed schedullers, cron jobs, etc. to clean up the storage.
147
+ */
148
+ setupLifecycle(): Promise<void>;
149
+ }
49
150
  //# sourceMappingURL=Adapters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Adapters.d.ts","sourceRoot":"","sources":["../../types/Adapters.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,EAAE,CAAC,EAAE,OAAO,CAAC;KACd,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,iBAAiB;IAEhC,QAAQ,IAAI,IAAI,CAAC;IAEjB,QAAQ,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AKG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjF;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;OAEG;IACH,aAAa,CAAC,IAAI,MAAM,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,IAAI,MAAM,CAAC;CACpB;AAGD,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAChF,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC5C,CAAC,CAAC;IAEH;;;;;;;OAOG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAGnD;;;;OAIG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAGtD;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAEjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",