@adminforth/rich-editor 2.0.17 → 2.1.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.
- package/build.log +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -2
- package/index.ts +27 -2
- package/package.json +4 -3
package/build.log
CHANGED
|
@@ -10,5 +10,5 @@ custom/package.json
|
|
|
10
10
|
custom/quillEditor.vue
|
|
11
11
|
custom/tsconfig.json
|
|
12
12
|
|
|
13
|
-
sent 35,
|
|
14
|
-
total size is 35,118 speedup is 0.
|
|
13
|
+
sent 35,541 bytes received 115 bytes 71,312.00 bytes/sec
|
|
14
|
+
total size is 35,118 speedup is 0.98
|
package/dist/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
14
14
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
|
|
15
15
|
instanceUniqueRepresentation(pluginOptions: any): string;
|
|
16
16
|
generateRecordContext(record: any, maxFields: number, inputFieldLimit: number, partsCount: number): string;
|
|
17
|
+
private parseBody;
|
|
17
18
|
setupEndpoints(server: IHttpServer): void;
|
|
18
19
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AdminForthPlugin, Filters, RateLimiter } from "adminforth";
|
|
11
11
|
import * as cheerio from 'cheerio';
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
const doCompleteBodySchema = z.object({
|
|
14
|
+
record: z.record(z.string(), z.unknown()),
|
|
15
|
+
}).strict();
|
|
12
16
|
// options:
|
|
13
17
|
// attachments: {
|
|
14
18
|
// attachmentResource: 'description_images',
|
|
@@ -214,13 +218,24 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
214
218
|
});
|
|
215
219
|
return JSON.stringify(Object.fromEntries(fields));
|
|
216
220
|
}
|
|
221
|
+
parseBody(schema, body, response) {
|
|
222
|
+
const parsed = schema.safeParse(body !== null && body !== void 0 ? body : {});
|
|
223
|
+
if (!parsed.success) {
|
|
224
|
+
response.setStatus(422, parsed.error.message);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return parsed.data;
|
|
228
|
+
}
|
|
217
229
|
setupEndpoints(server) {
|
|
218
230
|
server.endpoint({
|
|
219
231
|
method: 'POST',
|
|
220
232
|
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
221
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
233
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, response }) {
|
|
222
234
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
223
|
-
const
|
|
235
|
+
const data = this.parseBody(doCompleteBodySchema, body, response);
|
|
236
|
+
if (!data)
|
|
237
|
+
return;
|
|
238
|
+
const { record } = data;
|
|
224
239
|
if (!record) {
|
|
225
240
|
return { completion: [] };
|
|
226
241
|
}
|
|
@@ -265,6 +280,11 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
265
280
|
maxTokens: (_o = (_m = (_l = this.options.completion) === null || _l === void 0 ? void 0 : _l.expert) === null || _m === void 0 ? void 0 : _m.maxTokens) !== null && _o !== void 0 ? _o : 50,
|
|
266
281
|
});
|
|
267
282
|
let suggestion = respContent;
|
|
283
|
+
if (!suggestion) {
|
|
284
|
+
return {
|
|
285
|
+
completion: []
|
|
286
|
+
};
|
|
287
|
+
}
|
|
268
288
|
if (suggestion.startsWith(currentVal)) {
|
|
269
289
|
suggestion = suggestion.slice(currentVal.length);
|
|
270
290
|
}
|
package/index.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { IAdminForth, IHttpServer, AdminForthResource, AdminUser, IAdminFor
|
|
|
3
3
|
import type { PluginOptions } from './types.js';
|
|
4
4
|
import { AdminForthPlugin, Filters, RateLimiter } from "adminforth";
|
|
5
5
|
import * as cheerio from 'cheerio';
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
const doCompleteBodySchema = z.object({
|
|
9
|
+
record: z.record(z.string(), z.unknown()),
|
|
10
|
+
}).strict();
|
|
6
11
|
|
|
7
12
|
|
|
8
13
|
// options:
|
|
@@ -270,12 +275,27 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
270
275
|
return JSON.stringify(Object.fromEntries(fields));
|
|
271
276
|
}
|
|
272
277
|
|
|
278
|
+
private parseBody<T>(
|
|
279
|
+
schema: z.ZodType<T>,
|
|
280
|
+
body: unknown,
|
|
281
|
+
response: { setStatus: (code: number, message: string) => void },
|
|
282
|
+
): T | null {
|
|
283
|
+
const parsed = schema.safeParse(body ?? {});
|
|
284
|
+
if (!parsed.success) {
|
|
285
|
+
response.setStatus(422, parsed.error.message);
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
return parsed.data;
|
|
289
|
+
}
|
|
290
|
+
|
|
273
291
|
setupEndpoints(server: IHttpServer) {
|
|
274
292
|
server.endpoint({
|
|
275
293
|
method: 'POST',
|
|
276
294
|
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
277
|
-
handler: async ({ body, headers }) => {
|
|
278
|
-
const
|
|
295
|
+
handler: async ({ body, headers, response }) => {
|
|
296
|
+
const data = this.parseBody(doCompleteBodySchema, body, response);
|
|
297
|
+
if (!data) return;
|
|
298
|
+
const { record } = data;
|
|
279
299
|
|
|
280
300
|
if (!record) {
|
|
281
301
|
return { completion: [] };
|
|
@@ -333,6 +353,11 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
333
353
|
maxTokens: this.options.completion?.expert?.maxTokens ?? 50,
|
|
334
354
|
});
|
|
335
355
|
let suggestion = respContent
|
|
356
|
+
if (!suggestion) {
|
|
357
|
+
return {
|
|
358
|
+
completion: []
|
|
359
|
+
};
|
|
360
|
+
}
|
|
336
361
|
if (suggestion.startsWith(currentVal)) {
|
|
337
362
|
suggestion = suggestion.slice(currentVal.length);
|
|
338
363
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/rich-editor",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Rich editor plugin for adminforth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,14 +23,15 @@
|
|
|
23
23
|
"author": "DevForth (https://devforth.io)",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"zod": "^4.3.6",
|
|
26
27
|
"cheerio": "^1.0.0"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"adminforth": "^3.6.
|
|
30
|
+
"adminforth": "^3.6.21"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/node": "^22.10.7",
|
|
33
|
-
"adminforth": "^3.6.
|
|
34
|
+
"adminforth": "^3.6.21",
|
|
34
35
|
"semantic-release": "^24.2.1",
|
|
35
36
|
"semantic-release-slack-bot": "^4.0.2",
|
|
36
37
|
"typescript": "^5.7.3"
|