@adminforth/email-invite 1.1.12 → 1.2.1

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 +16 -4
  2. package/index.ts +21 -7
  3. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -8,6 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import AdminForth, { AdminForthPlugin, suggestIfTypo, Filters, afLogger } from "adminforth";
11
+ import { z } from "zod";
12
+ const setPasswordBodySchema = z.object({
13
+ token: z.string(),
14
+ password: z.string(),
15
+ }).strict();
16
+ const resendInviteBodySchema = z.object({
17
+ recordId: z.union([z.string(), z.number()]),
18
+ }).strict();
11
19
  export default class EmailInvitePlugin extends AdminForthPlugin {
12
20
  constructor(options) {
13
21
  super(options, import.meta.url);
@@ -197,8 +205,10 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
197
205
  method: 'POST',
198
206
  path: `/plugin/${this.pluginInstanceId}/set-password`,
199
207
  noAuth: true,
200
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
201
- const { token, password } = body;
208
+ request_schema: setPasswordBodySchema,
209
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
210
+ const data = body;
211
+ const { token, password } = data;
202
212
  try {
203
213
  const decoded = yield this.adminforth.auth.verify(token, 'inviteUser', false);
204
214
  if (!decoded || !decoded.inviteEmail) {
@@ -247,8 +257,10 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
247
257
  server.endpoint({
248
258
  method: 'POST',
249
259
  path: `/plugin/${this.pluginInstanceId}/resend-invite`,
250
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
251
- const { recordId } = body;
260
+ request_schema: resendInviteBodySchema,
261
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
262
+ const data = body;
263
+ const { recordId } = data;
252
264
  try {
253
265
  // Get the user record
254
266
  const userRecord = yield this.adminforth.resource(this.authResource.resourceId).get(recordId);
package/index.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  import AdminForth, { AdminForthPlugin, suggestIfTypo, Filters, afLogger } from "adminforth";
2
2
  import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource, AdminUser, HttpExtra } from "adminforth";
3
3
  import type { PluginOptions } from './types.js';
4
+ import { z } from "zod";
5
+
6
+ const setPasswordBodySchema = z.object({
7
+ token: z.string(),
8
+ password: z.string(),
9
+ }).strict();
10
+
11
+ const resendInviteBodySchema = z.object({
12
+ recordId: z.union([z.string(), z.number()]),
13
+ }).strict();
4
14
 
5
15
  export default class EmailInvitePlugin extends AdminForthPlugin {
6
16
  options: PluginOptions;
@@ -242,9 +252,11 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
242
252
  method: 'POST',
243
253
  path: `/plugin/${this.pluginInstanceId}/set-password`,
244
254
  noAuth: true,
245
- handler: async ({ body }) => {
246
- const { token, password } = body;
247
-
255
+ request_schema: setPasswordBodySchema,
256
+ handler: async ({ body, response }) => {
257
+ const data = body as z.infer<typeof setPasswordBodySchema>;
258
+ const { token, password } = data;
259
+
248
260
  try {
249
261
  const decoded = await this.adminforth.auth.verify(token, 'inviteUser', false);
250
262
  if (!decoded || !decoded.inviteEmail) {
@@ -308,12 +320,14 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
308
320
  server.endpoint({
309
321
  method: 'POST',
310
322
  path: `/plugin/${this.pluginInstanceId}/resend-invite`,
311
- handler: async ({ body, adminUser }) => {
312
- const { recordId } = body;
313
-
323
+ request_schema: resendInviteBodySchema,
324
+ handler: async ({ body, adminUser, response }) => {
325
+ const data = body as z.infer<typeof resendInviteBodySchema>;
326
+ const { recordId } = data;
327
+
314
328
  try {
315
329
  // Get the user record
316
- const userRecord = await this.adminforth.resource(this.authResource.resourceId).get(recordId);
330
+ const userRecord = await this.adminforth.resource(this.authResource.resourceId).get(recordId as any);
317
331
  if (!userRecord) {
318
332
  return { error: 'User not found', ok: false };
319
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/email-invite",
3
- "version": "1.1.12",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -16,15 +16,18 @@
16
16
  "author": "DevForth (https://devforth.io)",
17
17
  "license": "MIT",
18
18
  "description": "Email invite plugin for adminforth",
19
+ "dependencies": {
20
+ "zod": "^4.3.6"
21
+ },
19
22
  "devDependencies": {
20
23
  "@types/node": "^22.10.7",
21
- "adminforth": "^3.6.21",
24
+ "adminforth": "^3.8.2",
22
25
  "semantic-release": "^24.2.1",
23
26
  "semantic-release-slack-bot": "^4.0.2",
24
27
  "typescript": "^5.7.3"
25
28
  },
26
29
  "peerDependencies": {
27
- "adminforth": "^3.6.21"
30
+ "adminforth": "^3.8.2"
28
31
  },
29
32
  "publishConfig": {
30
33
  "access": "public"