@adminforth/open-signup 1.2.26 → 1.3.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.
- package/dist/index.js +30 -7
- package/index.ts +34 -8
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -8,6 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import AdminForth, { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes } from "adminforth";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
const completeVerifiedSignupBodySchema = z.object({
|
|
13
|
+
token: z.string(),
|
|
14
|
+
password: z.string(),
|
|
15
|
+
}).strict();
|
|
16
|
+
const signupBodySchema = z.object({
|
|
17
|
+
email: z.string(),
|
|
18
|
+
url: z.string(),
|
|
19
|
+
password: z.string().optional(),
|
|
20
|
+
}).strict();
|
|
11
21
|
export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
12
22
|
constructor(options) {
|
|
13
23
|
super(options, import.meta.url);
|
|
@@ -129,19 +139,30 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
|
129
139
|
path: `/plugin/${this.pluginInstanceId}/password-constraints`,
|
|
130
140
|
noAuth: true,
|
|
131
141
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ tr }) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
if (!this.passwordField) {
|
|
143
|
+
throw new Error(`passwordField is not defined in plugin options`);
|
|
144
|
+
}
|
|
145
|
+
const objectToReturn = {};
|
|
146
|
+
if (this.passwordField.minLength) {
|
|
147
|
+
objectToReturn.minLength = this.passwordField.minLength;
|
|
148
|
+
}
|
|
149
|
+
if (this.passwordField.maxLength) {
|
|
150
|
+
objectToReturn.maxLength = this.passwordField.maxLength;
|
|
151
|
+
}
|
|
152
|
+
if (this.passwordField.validation) {
|
|
153
|
+
objectToReturn.validation = yield Promise.all(this.passwordField.validation.map((_a) => __awaiter(this, [_a], void 0, function* ({ regExp, message }) { return ({ regExp, message: yield tr(message, 'opensignup') }); })));
|
|
154
|
+
}
|
|
155
|
+
return objectToReturn;
|
|
137
156
|
})
|
|
138
157
|
});
|
|
139
158
|
server.endpoint({
|
|
140
159
|
method: 'POST',
|
|
141
160
|
path: `/plugin/${this.pluginInstanceId}/complete-verified-signup`,
|
|
142
161
|
noAuth: true,
|
|
162
|
+
request_schema: completeVerifiedSignupBodySchema,
|
|
143
163
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, headers, query, cookies, tr, requestUrl }) {
|
|
144
|
-
const
|
|
164
|
+
const data = body;
|
|
165
|
+
const { token, password } = data;
|
|
145
166
|
if (!token) {
|
|
146
167
|
return { error: yield tr('Invalid token', 'opensignup'), ok: false };
|
|
147
168
|
}
|
|
@@ -171,9 +192,11 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
|
171
192
|
method: 'POST',
|
|
172
193
|
path: `/plugin/${this.pluginInstanceId}/signup`,
|
|
173
194
|
noAuth: true,
|
|
195
|
+
request_schema: signupBodySchema,
|
|
174
196
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, headers, query, cookies, tr, requestUrl }) {
|
|
175
197
|
var _b, _c;
|
|
176
|
-
const
|
|
198
|
+
const data = body;
|
|
199
|
+
const { email, url, password } = data;
|
|
177
200
|
if (!email || typeof email !== 'string') {
|
|
178
201
|
return { error: yield tr('Email is required', 'opensignup'), ok: false };
|
|
179
202
|
}
|
package/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import AdminForth, { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes } from "adminforth";
|
|
2
2
|
import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResourceColumn, AdminForthResource, BeforeLoginConfirmationFunction, HttpExtra } from "adminforth";
|
|
3
3
|
import type { PluginOptions } from './types.js';
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
const completeVerifiedSignupBodySchema = z.object({
|
|
7
|
+
token: z.string(),
|
|
8
|
+
password: z.string(),
|
|
9
|
+
}).strict();
|
|
10
|
+
|
|
11
|
+
const signupBodySchema = z.object({
|
|
12
|
+
email: z.string(),
|
|
13
|
+
url: z.string(),
|
|
14
|
+
password: z.string().optional(),
|
|
15
|
+
}).strict();
|
|
4
16
|
|
|
5
17
|
|
|
6
18
|
export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
@@ -149,13 +161,23 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
|
149
161
|
path: `/plugin/${this.pluginInstanceId}/password-constraints`,
|
|
150
162
|
noAuth: true,
|
|
151
163
|
handler: async ({tr}) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
164
|
+
if (!this.passwordField) {
|
|
165
|
+
throw new Error(`passwordField is not defined in plugin options`);
|
|
166
|
+
}
|
|
167
|
+
const objectToReturn: any = {};
|
|
168
|
+
|
|
169
|
+
if (this.passwordField.minLength) {
|
|
170
|
+
objectToReturn.minLength = this.passwordField.minLength;
|
|
171
|
+
}
|
|
172
|
+
if (this.passwordField.maxLength) {
|
|
173
|
+
objectToReturn.maxLength = this.passwordField.maxLength;
|
|
174
|
+
}
|
|
175
|
+
if (this.passwordField.validation) {
|
|
176
|
+
objectToReturn.validation = await Promise.all(
|
|
156
177
|
this.passwordField.validation.map(async ({ regExp, message }) => ({ regExp, message: await tr(message, 'opensignup') }))
|
|
157
|
-
)
|
|
158
|
-
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return objectToReturn;
|
|
159
181
|
}
|
|
160
182
|
});
|
|
161
183
|
|
|
@@ -163,8 +185,10 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
|
163
185
|
method: 'POST',
|
|
164
186
|
path: `/plugin/${this.pluginInstanceId}/complete-verified-signup`,
|
|
165
187
|
noAuth: true,
|
|
188
|
+
request_schema: completeVerifiedSignupBodySchema,
|
|
166
189
|
handler: async ({ body, response, headers, query, cookies, tr, requestUrl }) => {
|
|
167
|
-
const
|
|
190
|
+
const data = body as z.infer<typeof completeVerifiedSignupBodySchema>;
|
|
191
|
+
const { token, password } = data;
|
|
168
192
|
if (!token) {
|
|
169
193
|
return { error: await tr('Invalid token', 'opensignup'), ok: false };
|
|
170
194
|
}
|
|
@@ -198,8 +222,10 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
|
|
|
198
222
|
method: 'POST',
|
|
199
223
|
path: `/plugin/${this.pluginInstanceId}/signup`,
|
|
200
224
|
noAuth: true,
|
|
225
|
+
request_schema: signupBodySchema,
|
|
201
226
|
handler: async ({ body, response, headers, query, cookies, tr, requestUrl }) => {
|
|
202
|
-
const
|
|
227
|
+
const data = body as z.infer<typeof signupBodySchema>;
|
|
228
|
+
const { email, url, password } = data;
|
|
203
229
|
if (!email || typeof email !== 'string') {
|
|
204
230
|
return { error: await tr('Email is required', 'opensignup'), ok: false };
|
|
205
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/open-signup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -23,14 +23,15 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"description": "Open signup for adminforth",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@aws-sdk/client-ses": "^3.654.0"
|
|
26
|
+
"@aws-sdk/client-ses": "^3.654.0",
|
|
27
|
+
"zod": "^4.3.6"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"adminforth": "^3.
|
|
30
|
+
"adminforth": "^3.8.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/node": "^22.10.7",
|
|
33
|
-
"adminforth": "^3.
|
|
34
|
+
"adminforth": "^3.8.2",
|
|
34
35
|
"semantic-release": "^24.2.1",
|
|
35
36
|
"semantic-release-slack-bot": "^4.0.2",
|
|
36
37
|
"typescript": "^5.7.3"
|