@adminforth/email-invite 1.1.12 → 1.2.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/dist/index.js +21 -5
- package/index.ts +24 -8
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -7,7 +7,15 @@ 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 AdminForth, { AdminForthPlugin, suggestIfTypo, Filters, afLogger } from "adminforth";
|
|
10
|
+
import AdminForth, { AdminForthPlugin, parseBody, 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,12 @@ 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
|
|
208
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
|
|
209
|
+
const parsed = parseBody(setPasswordBodySchema, body, response);
|
|
210
|
+
if ('error' in parsed)
|
|
211
|
+
return parsed.error;
|
|
212
|
+
const data = parsed.data;
|
|
213
|
+
const { token, password } = data;
|
|
202
214
|
try {
|
|
203
215
|
const decoded = yield this.adminforth.auth.verify(token, 'inviteUser', false);
|
|
204
216
|
if (!decoded || !decoded.inviteEmail) {
|
|
@@ -247,8 +259,12 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
247
259
|
server.endpoint({
|
|
248
260
|
method: 'POST',
|
|
249
261
|
path: `/plugin/${this.pluginInstanceId}/resend-invite`,
|
|
250
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
|
|
251
|
-
const
|
|
262
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
|
|
263
|
+
const parsed = parseBody(resendInviteBodySchema, body, response);
|
|
264
|
+
if ('error' in parsed)
|
|
265
|
+
return parsed.error;
|
|
266
|
+
const data = parsed.data;
|
|
267
|
+
const { recordId } = data;
|
|
252
268
|
try {
|
|
253
269
|
// Get the user record
|
|
254
270
|
const userRecord = yield this.adminforth.resource(this.authResource.resourceId).get(recordId);
|
package/index.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import AdminForth, { AdminForthPlugin, suggestIfTypo, Filters, afLogger } from "adminforth";
|
|
1
|
+
import AdminForth, { AdminForthPlugin, parseBody, 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,12 @@ 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
|
|
247
|
-
|
|
255
|
+
handler: async ({ body, response }) => {
|
|
256
|
+
const parsed = parseBody(setPasswordBodySchema, body, response);
|
|
257
|
+
if ('error' in parsed) return parsed.error;
|
|
258
|
+
const data = parsed.data;
|
|
259
|
+
const { token, password } = data;
|
|
260
|
+
|
|
248
261
|
try {
|
|
249
262
|
const decoded = await this.adminforth.auth.verify(token, 'inviteUser', false);
|
|
250
263
|
if (!decoded || !decoded.inviteEmail) {
|
|
@@ -308,12 +321,15 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
308
321
|
server.endpoint({
|
|
309
322
|
method: 'POST',
|
|
310
323
|
path: `/plugin/${this.pluginInstanceId}/resend-invite`,
|
|
311
|
-
handler: async ({ body, adminUser }) => {
|
|
312
|
-
const
|
|
313
|
-
|
|
324
|
+
handler: async ({ body, adminUser, response }) => {
|
|
325
|
+
const parsed = parseBody(resendInviteBodySchema, body, response);
|
|
326
|
+
if ('error' in parsed) return parsed.error;
|
|
327
|
+
const data = parsed.data;
|
|
328
|
+
const { recordId } = data;
|
|
329
|
+
|
|
314
330
|
try {
|
|
315
331
|
// Get the user record
|
|
316
|
-
const userRecord = await this.adminforth.resource(this.authResource.resourceId).get(recordId);
|
|
332
|
+
const userRecord = await this.adminforth.resource(this.authResource.resourceId).get(recordId as any);
|
|
317
333
|
if (!userRecord) {
|
|
318
334
|
return { error: 'User not found', ok: false };
|
|
319
335
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/email-invite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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.
|
|
24
|
+
"adminforth": "^3.7.1",
|
|
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.
|
|
30
|
+
"adminforth": "^3.7.1"
|
|
28
31
|
},
|
|
29
32
|
"publishConfig": {
|
|
30
33
|
"access": "public"
|