@adminforth/text-complete 2.0.24 → 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.
Files changed (3) hide show
  1. package/dist/index.js +11 -3
  2. package/index.ts +11 -3
  3. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -7,7 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { AdminForthPlugin, AdminForthDataTypes, RateLimiter } from "adminforth";
10
+ import { AdminForthPlugin, AdminForthDataTypes, RateLimiter, parseBody } from "adminforth";
11
+ import { z } from "zod";
12
+ const doCompleteBodySchema = z.object({
13
+ record: z.record(z.string(), z.any()),
14
+ }).strict();
11
15
  export default class TextCompletePlugin extends AdminForthPlugin {
12
16
  constructor(options) {
13
17
  var _a, _b;
@@ -66,8 +70,12 @@ export default class TextCompletePlugin extends AdminForthPlugin {
66
70
  server.endpoint({
67
71
  method: 'POST',
68
72
  path: `/plugin/${this.pluginInstanceId}/doComplete`,
69
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
73
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, response }) {
70
74
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
75
+ const parsed = parseBody(doCompleteBodySchema, body, response);
76
+ if ('error' in parsed)
77
+ return parsed.error;
78
+ const data = parsed.data;
71
79
  if (this.rateLimiter) {
72
80
  // rate limit
73
81
  // const { error } = RateLimiter.checkRateLimit(
@@ -81,7 +89,7 @@ export default class TextCompletePlugin extends AdminForthPlugin {
81
89
  };
82
90
  }
83
91
  }
84
- const { record } = body;
92
+ const { record } = data;
85
93
  if (!record) {
86
94
  return { completion: [] };
87
95
  }
package/index.ts CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
- import { IAdminForth, IHttpServer, AdminForthPlugin, AdminForthResource, AdminForthDataTypes, RateLimiter } from "adminforth";
2
+ import { IAdminForth, IHttpServer, AdminForthPlugin, AdminForthResource, AdminForthDataTypes, RateLimiter, parseBody } from "adminforth";
3
3
  import { PluginOptions } from './types.js';
4
+ import { z } from "zod";
5
+
6
+ const doCompleteBodySchema = z.object({
7
+ record: z.record(z.string(), z.any()),
8
+ }).strict();
4
9
 
5
10
 
6
11
  export default class TextCompletePlugin extends AdminForthPlugin {
@@ -82,7 +87,10 @@ export default class TextCompletePlugin extends AdminForthPlugin {
82
87
  server.endpoint({
83
88
  method: 'POST',
84
89
  path: `/plugin/${this.pluginInstanceId}/doComplete`,
85
- handler: async ({ body, headers }) => {
90
+ handler: async ({ body, headers, response }) => {
91
+ const parsed = parseBody(doCompleteBodySchema, body, response);
92
+ if ('error' in parsed) return parsed.error;
93
+ const data = parsed.data;
86
94
  if (this.rateLimiter) {
87
95
  // rate limit
88
96
  // const { error } = RateLimiter.checkRateLimit(
@@ -97,7 +105,7 @@ export default class TextCompletePlugin extends AdminForthPlugin {
97
105
  }
98
106
  }
99
107
 
100
- const { record } = body;
108
+ const { record } = data;
101
109
  if (!record) {
102
110
  return { completion: [] };
103
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/text-complete",
3
- "version": "2.0.24",
3
+ "version": "2.1.0",
4
4
  "description": "Text completion plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,9 +22,12 @@
22
22
  ],
23
23
  "author": "DevForth (https://devforth.io)",
24
24
  "license": "MIT",
25
+ "dependencies": {
26
+ "zod": "^4.3.6"
27
+ },
25
28
  "devDependencies": {
26
29
  "@types/node": "^22.10.7",
27
- "adminforth": "^3.6.21",
30
+ "adminforth": "^3.7.1",
28
31
  "semantic-release": "^24.2.1",
29
32
  "semantic-release-slack-bot": "^4.0.2",
30
33
  "typescript": "^5.7.3"
@@ -55,6 +58,6 @@
55
58
  ]
56
59
  },
57
60
  "peerDependencies": {
58
- "adminforth": "^3.6.21"
61
+ "adminforth": "^3.7.1"
59
62
  }
60
63
  }