@adminforth/email-invite 2.0.2 → 2.0.4
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 +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -10
- package/index.ts +11 -10
- package/package.json +2 -2
- package/tsconfig.json +1 -1
package/build.log
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
6
6
|
authResource: AdminForthResource;
|
|
7
7
|
emailField: AdminForthResourceColumn;
|
|
8
8
|
emailConfirmedField?: AdminForthResourceColumn;
|
|
9
|
+
passwordHashField: string;
|
|
10
|
+
primaryKeyColumn: AdminForthResourceColumn;
|
|
9
11
|
constructor(options: PluginOptions);
|
|
10
12
|
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): Promise<void>;
|
|
11
13
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,8 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
49
49
|
throw new Error(`Resource with id config.auth.usersResourceId=${adminforth.config.auth.usersResourceId} not found`);
|
|
50
50
|
}
|
|
51
51
|
this.authResource = authResource;
|
|
52
|
+
this.passwordHashField = adminforth.config.auth.passwordHashField;
|
|
53
|
+
this.primaryKeyColumn = authResource.columns.find(c => c.primaryKey);
|
|
52
54
|
const emailField = authResource.columns.find(f => f.name === this.options.emailField);
|
|
53
55
|
if (!emailField) {
|
|
54
56
|
const similar = suggestIfTypo(authResource.columns.map(f => f.name), this.options.emailField);
|
|
@@ -130,8 +132,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
130
132
|
if ('password' in record) {
|
|
131
133
|
delete record.password;
|
|
132
134
|
}
|
|
133
|
-
|
|
134
|
-
record[passwordHashFieldName] = yield AdminForth.Utils.generatePasswordHash('TEMP_INVITE_PLACEHOLDER_' + randomUUID());
|
|
135
|
+
record[this.passwordHashField] = yield AdminForth.Utils.generatePasswordHash('TEMP_INVITE_PLACEHOLDER_' + randomUUID());
|
|
135
136
|
if (this.options.emailConfirmedField && this.emailConfirmedField) {
|
|
136
137
|
record[this.emailConfirmedField.name] = false;
|
|
137
138
|
}
|
|
@@ -148,7 +149,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
148
149
|
var _b, _c;
|
|
149
150
|
try {
|
|
150
151
|
const email = record[this.options.emailField];
|
|
151
|
-
const newRecordId = record[this.
|
|
152
|
+
const newRecordId = record[this.primaryKeyColumn.name];
|
|
152
153
|
if (!email || !/\S+@\S+\.\S+/.test(email)) {
|
|
153
154
|
console.warn('Email invite plugin: Invalid or missing email address');
|
|
154
155
|
return { ok: true }; // Don't fail user creation for email issues
|
|
@@ -158,7 +159,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
158
159
|
email,
|
|
159
160
|
recordId: newRecordId,
|
|
160
161
|
inviteEmail: true,
|
|
161
|
-
ph: this.passwordHashDigest(record[this.
|
|
162
|
+
ph: this.passwordHashDigest(record[this.passwordHashField])
|
|
162
163
|
}, 'inviteUser', '7d' // 7 days validity
|
|
163
164
|
);
|
|
164
165
|
const host = ((_b = extra === null || extra === void 0 ? void 0 : extra.headers) === null || _b === void 0 ? void 0 : _b.host) || 'localhost';
|
|
@@ -226,9 +227,9 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
226
227
|
const { email, recordId } = decoded;
|
|
227
228
|
let userRecord;
|
|
228
229
|
if (recordId) {
|
|
229
|
-
userRecord = yield this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.
|
|
230
|
+
userRecord = yield this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.primaryKeyColumn.name, recordId));
|
|
230
231
|
}
|
|
231
|
-
if (decoded.ph !== this.passwordHashDigest(userRecord[this.
|
|
232
|
+
if (decoded.ph !== this.passwordHashDigest(userRecord[this.passwordHashField])) {
|
|
232
233
|
return { error: 'Token has already been used', ok: false };
|
|
233
234
|
}
|
|
234
235
|
if (!userRecord && email) {
|
|
@@ -246,12 +247,10 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
246
247
|
if (!userEmail || userEmail.toLowerCase() !== tokenEmail.toLowerCase()) {
|
|
247
248
|
return { error: 'Email mismatch', ok: false };
|
|
248
249
|
}
|
|
249
|
-
const passwordHashFieldName = this.adminforth.config.auth.passwordHashField;
|
|
250
250
|
const newPasswordHash = yield AdminForth.Utils.generatePasswordHash(password);
|
|
251
|
-
const
|
|
252
|
-
const userRecordId = userRecord[primaryKeyField.name];
|
|
251
|
+
const userRecordId = userRecord[this.primaryKeyColumn.name];
|
|
253
252
|
const updateData = {
|
|
254
|
-
[
|
|
253
|
+
[this.passwordHashField]: newPasswordHash
|
|
255
254
|
};
|
|
256
255
|
if (this.options.emailConfirmedField && this.emailConfirmedField) {
|
|
257
256
|
updateData[this.emailConfirmedField.name] = true;
|
package/index.ts
CHANGED
|
@@ -18,6 +18,8 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
18
18
|
authResource!: AdminForthResource;
|
|
19
19
|
emailField!: AdminForthResourceColumn;
|
|
20
20
|
emailConfirmedField?: AdminForthResourceColumn;
|
|
21
|
+
passwordHashField!: string;
|
|
22
|
+
primaryKeyColumn!: AdminForthResourceColumn;
|
|
21
23
|
|
|
22
24
|
constructor(options: PluginOptions) {
|
|
23
25
|
super(options, import.meta.url);
|
|
@@ -54,6 +56,8 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
54
56
|
throw new Error(`Resource with id config.auth.usersResourceId=${adminforth.config.auth!.usersResourceId} not found`);
|
|
55
57
|
}
|
|
56
58
|
this.authResource = authResource;
|
|
59
|
+
this.passwordHashField = adminforth.config.auth.passwordHashField;
|
|
60
|
+
this.primaryKeyColumn = authResource.columns.find(c => c.primaryKey)!;
|
|
57
61
|
|
|
58
62
|
const emailField = authResource.columns.find(f => f.name === this.options.emailField);
|
|
59
63
|
if (!emailField) {
|
|
@@ -156,8 +160,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
156
160
|
delete record.password;
|
|
157
161
|
}
|
|
158
162
|
|
|
159
|
-
|
|
160
|
-
record[passwordHashFieldName] = await AdminForth.Utils.generatePasswordHash('TEMP_INVITE_PLACEHOLDER_' + randomUUID());
|
|
163
|
+
record[this.passwordHashField] = await AdminForth.Utils.generatePasswordHash('TEMP_INVITE_PLACEHOLDER_' + randomUUID());
|
|
161
164
|
|
|
162
165
|
if (this.options.emailConfirmedField && this.emailConfirmedField) {
|
|
163
166
|
record[this.emailConfirmedField.name] = false;
|
|
@@ -180,7 +183,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
180
183
|
}): Promise<{ok: boolean, error?: string}> {
|
|
181
184
|
try {
|
|
182
185
|
const email = record[this.options.emailField];
|
|
183
|
-
const newRecordId = record[this.
|
|
186
|
+
const newRecordId = record[this.primaryKeyColumn.name];
|
|
184
187
|
|
|
185
188
|
if (!email || !/\S+@\S+\.\S+/.test(email)) {
|
|
186
189
|
console.warn('Email invite plugin: Invalid or missing email address');
|
|
@@ -194,7 +197,7 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
194
197
|
email,
|
|
195
198
|
recordId: newRecordId,
|
|
196
199
|
inviteEmail: true,
|
|
197
|
-
ph: this.passwordHashDigest(record[this.
|
|
200
|
+
ph: this.passwordHashDigest(record[this.passwordHashField])
|
|
198
201
|
},
|
|
199
202
|
'inviteUser',
|
|
200
203
|
'7d' // 7 days validity
|
|
@@ -277,10 +280,10 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
277
280
|
let userRecord;
|
|
278
281
|
|
|
279
282
|
if (recordId) {
|
|
280
|
-
userRecord = await this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.
|
|
283
|
+
userRecord = await this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.primaryKeyColumn.name, recordId));
|
|
281
284
|
}
|
|
282
285
|
|
|
283
|
-
if (decoded.ph !== this.passwordHashDigest(userRecord[this.
|
|
286
|
+
if (decoded.ph !== this.passwordHashDigest(userRecord[this.passwordHashField])) {
|
|
284
287
|
return { error: 'Token has already been used', ok: false };
|
|
285
288
|
}
|
|
286
289
|
|
|
@@ -305,14 +308,12 @@ export default class EmailInvitePlugin extends AdminForthPlugin {
|
|
|
305
308
|
return { error: 'Email mismatch', ok: false };
|
|
306
309
|
}
|
|
307
310
|
|
|
308
|
-
const passwordHashFieldName = this.adminforth.config.auth.passwordHashField;
|
|
309
311
|
const newPasswordHash = await AdminForth.Utils.generatePasswordHash(password);
|
|
310
312
|
|
|
311
|
-
const
|
|
312
|
-
const userRecordId = userRecord[primaryKeyField!.name];
|
|
313
|
+
const userRecordId = userRecord[this.primaryKeyColumn.name];
|
|
313
314
|
|
|
314
315
|
const updateData: any = {
|
|
315
|
-
[
|
|
316
|
+
[this.passwordHashField]: newPasswordHash
|
|
316
317
|
};
|
|
317
318
|
|
|
318
319
|
if (this.options.emailConfirmedField && this.emailConfirmedField) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/email-invite",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.7.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"adminforth": "^4.
|
|
34
|
+
"adminforth": "^4.7.3"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
package/tsconfig.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
7
7
|
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
|
|
8
8
|
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
9
|
-
"strict":
|
|
9
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
10
10
|
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
11
11
|
},
|
|
12
12
|
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
|