@fabriktor/fx 0.0.93 → 0.0.94
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/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/users/email.d.ts +2 -0
- package/dist/src/users/email.js +11 -0
- package/dist/src/users/users.js +16 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./routes/routes.js";
|
|
|
25
25
|
export * from "./session/session.js";
|
|
26
26
|
export * from "./storage/storage.js";
|
|
27
27
|
export * from "./timesheets/timesheets.js";
|
|
28
|
+
export * from "./users/email.js";
|
|
28
29
|
export * from "./users/phone.js";
|
|
29
30
|
export * from "./users/username.js";
|
|
30
31
|
export * from "./users/users.js";
|
package/dist/src/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./routes/routes.js";
|
|
|
25
25
|
export * from "./session/session.js";
|
|
26
26
|
export * from "./storage/storage.js";
|
|
27
27
|
export * from "./timesheets/timesheets.js";
|
|
28
|
+
export * from "./users/email.js";
|
|
28
29
|
export * from "./users/phone.js";
|
|
29
30
|
export * from "./users/username.js";
|
|
30
31
|
export * from "./users/users.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
export function normalizeEmail(value) {
|
|
7
|
+
return value.trim();
|
|
8
|
+
}
|
|
9
|
+
export function isValidEmail(value) {
|
|
10
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizeEmail(value));
|
|
11
|
+
}
|
package/dist/src/users/users.js
CHANGED
|
@@ -8,12 +8,15 @@ import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
|
|
|
8
8
|
import { requiredOperationID } from "../core/id.js";
|
|
9
9
|
import { runSearch, } from "../core/search.js";
|
|
10
10
|
import { normalizePhone, normalizePhoneCode, validatePhone, validatePhoneCode, } from "./phone.js";
|
|
11
|
+
import { normalizeEmail, isValidEmail } from "./email.js";
|
|
11
12
|
import { normalizeUsername, validateUsernameFormat } from "./username.js";
|
|
12
13
|
const msgUnableToResolveUsername = "Unable to resolve username.";
|
|
13
14
|
const msgPhoneRequired = "Phone number is required.";
|
|
14
15
|
const msgPhoneCodeRequired = "Verification code is required.";
|
|
15
16
|
const msgFirstNameRequired = "First name is required.";
|
|
16
17
|
const msgLastNameRequired = "Last name is required.";
|
|
18
|
+
const msgEmailRequired = "Email is required.";
|
|
19
|
+
const msgEmailInvalid = "Email address is invalid.";
|
|
17
20
|
const msgAddressRequired = "A complete address is required.";
|
|
18
21
|
const msgUserMissingAfterUpdate = "User could not be resolved after the account update.";
|
|
19
22
|
const msgCreatedExternalUserIDMissing = "Created external user response did not contain an ID.";
|
|
@@ -207,6 +210,7 @@ function normalizeExternalUserInput(input) {
|
|
|
207
210
|
username: normalizeUsername(input.username),
|
|
208
211
|
first_name: input.first_name.trim(),
|
|
209
212
|
last_name: input.last_name.trim(),
|
|
213
|
+
email: normalizeEmail(input.email),
|
|
210
214
|
phone: input.phone.trim(),
|
|
211
215
|
company_name: input.company_name.trim(),
|
|
212
216
|
street: input.street.trim(),
|
|
@@ -232,6 +236,18 @@ function validateExternalUserInput(input) {
|
|
|
232
236
|
msg: msgLastNameRequired,
|
|
233
237
|
});
|
|
234
238
|
}
|
|
239
|
+
if (!input.email) {
|
|
240
|
+
throw errRequired({
|
|
241
|
+
field: "email",
|
|
242
|
+
msg: msgEmailRequired,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (!isValidEmail(input.email)) {
|
|
246
|
+
throw errValidation({
|
|
247
|
+
field: "email",
|
|
248
|
+
msg: msgEmailInvalid,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
235
251
|
if (input.phone && !validatePhone(input.phone)) {
|
|
236
252
|
throw errValidation({
|
|
237
253
|
field: "phone",
|