@palbase/backend 10.0.0 → 10.1.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.cjs +28 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -852,6 +852,9 @@ function camelToUpperSnake(s) {
|
|
|
852
852
|
var TEST_USERS_CONFIG_KIND = "test-users";
|
|
853
853
|
var TEST_USER_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
854
854
|
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
855
|
+
var E164_RE = /^\+[1-9]\d{1,14}$/;
|
|
856
|
+
var OTP_LENGTH = 6;
|
|
857
|
+
var OTP_RE = /^\d{6}$/;
|
|
855
858
|
var MIN_PASSWORD_LENGTH = 8;
|
|
856
859
|
function isPlainObject(value) {
|
|
857
860
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -886,7 +889,7 @@ function normalizeSeed(seed, userName) {
|
|
|
886
889
|
}
|
|
887
890
|
function testUser(opts = {}) {
|
|
888
891
|
if (!isPlainObject(opts)) {
|
|
889
|
-
throw new Error("testUser() expects { email?, password?, seed? }");
|
|
892
|
+
throw new Error("testUser() expects { email?, password?, phone?, otp?, seed? }");
|
|
890
893
|
}
|
|
891
894
|
const hasEmail = opts.email !== void 0;
|
|
892
895
|
const hasPassword = opts.password !== void 0;
|
|
@@ -909,7 +912,30 @@ function testUser(opts = {}) {
|
|
|
909
912
|
email = opts.email;
|
|
910
913
|
password = opts.password;
|
|
911
914
|
}
|
|
912
|
-
|
|
915
|
+
const hasPhone = opts.phone !== void 0;
|
|
916
|
+
const hasOTP = opts.otp !== void 0;
|
|
917
|
+
if (hasPhone !== hasOTP) {
|
|
918
|
+
throw new Error(
|
|
919
|
+
"testUser() needs phone AND otp together \u2014 nothing can receive an SMS at a fabricated number, so a phone fixture without its fixed code can never be signed in as"
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
let phone = null;
|
|
923
|
+
let otp = null;
|
|
924
|
+
if (hasPhone) {
|
|
925
|
+
if (typeof opts.phone !== "string" || !E164_RE.test(opts.phone)) {
|
|
926
|
+
throw new Error(
|
|
927
|
+
`testUser phone ${JSON.stringify(opts.phone)} must be E.164, e.g. "+905551112233"`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
if (typeof opts.otp !== "string" || !OTP_RE.test(opts.otp)) {
|
|
931
|
+
throw new Error(
|
|
932
|
+
`testUser otp ${JSON.stringify(opts.otp)} must be ${OTP_LENGTH} digits`
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
phone = opts.phone;
|
|
936
|
+
otp = opts.otp;
|
|
937
|
+
}
|
|
938
|
+
return { email, password, phone, otp, seed: normalizeSeed(opts.seed, email ?? "<template>") };
|
|
913
939
|
}
|
|
914
940
|
function defineTestUsers(input) {
|
|
915
941
|
if (!isPlainObject(input) || !isPlainObject(input.users)) {
|