@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.d.cts CHANGED
@@ -707,6 +707,19 @@ type Seed = [keyof Tables] extends [never] ? SeedJson : SeedFor<Tables>;
707
707
  interface TestUserOptions {
708
708
  email?: string;
709
709
  password?: string;
710
+ /**
711
+ * A verified phone for this fixture, E.164 (`+905551112233`). Requires
712
+ * {@link TestUserOptions.otp}: nothing can receive an SMS at a fabricated
713
+ * number, so a phone fixture without a knowable code is one no test could
714
+ * ever sign in as.
715
+ */
716
+ phone?: string;
717
+ /**
718
+ * The fixed code this fixture's phone accepts. Honoured ONLY for the
719
+ * `is_test` user it belongs to — the real rail is untouched, and no
720
+ * verification is ever sent (or billed) for a fixture.
721
+ */
722
+ otp?: string;
710
723
  seed?: Seed;
711
724
  }
712
725
  /** The compiled, serializable test-user definition — the EXACT shape emitted to
@@ -716,6 +729,10 @@ interface TestUserDef {
716
729
  email: string | null;
717
730
  /** Fixed password (fixture), or `null` when the server should generate one. */
718
731
  password: string | null;
732
+ /** Verified phone in E.164, or `null` for an e-mail-only fixture. */
733
+ phone: string | null;
734
+ /** The code that phone accepts, or `null` when there is no phone. */
735
+ otp: string | null;
719
736
  /** The user's data tree; `{}` when nothing is seeded. */
720
737
  seed: SeedJson;
721
738
  }
package/dist/index.d.ts CHANGED
@@ -707,6 +707,19 @@ type Seed = [keyof Tables] extends [never] ? SeedJson : SeedFor<Tables>;
707
707
  interface TestUserOptions {
708
708
  email?: string;
709
709
  password?: string;
710
+ /**
711
+ * A verified phone for this fixture, E.164 (`+905551112233`). Requires
712
+ * {@link TestUserOptions.otp}: nothing can receive an SMS at a fabricated
713
+ * number, so a phone fixture without a knowable code is one no test could
714
+ * ever sign in as.
715
+ */
716
+ phone?: string;
717
+ /**
718
+ * The fixed code this fixture's phone accepts. Honoured ONLY for the
719
+ * `is_test` user it belongs to — the real rail is untouched, and no
720
+ * verification is ever sent (or billed) for a fixture.
721
+ */
722
+ otp?: string;
710
723
  seed?: Seed;
711
724
  }
712
725
  /** The compiled, serializable test-user definition — the EXACT shape emitted to
@@ -716,6 +729,10 @@ interface TestUserDef {
716
729
  email: string | null;
717
730
  /** Fixed password (fixture), or `null` when the server should generate one. */
718
731
  password: string | null;
732
+ /** Verified phone in E.164, or `null` for an e-mail-only fixture. */
733
+ phone: string | null;
734
+ /** The code that phone accepts, or `null` when there is no phone. */
735
+ otp: string | null;
719
736
  /** The user's data tree; `{}` when nothing is seeded. */
720
737
  seed: SeedJson;
721
738
  }
package/dist/index.js CHANGED
@@ -363,6 +363,9 @@ function camelToUpperSnake(s) {
363
363
  var TEST_USERS_CONFIG_KIND = "test-users";
364
364
  var TEST_USER_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
365
365
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
366
+ var E164_RE = /^\+[1-9]\d{1,14}$/;
367
+ var OTP_LENGTH = 6;
368
+ var OTP_RE = /^\d{6}$/;
366
369
  var MIN_PASSWORD_LENGTH = 8;
367
370
  function isPlainObject(value) {
368
371
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -397,7 +400,7 @@ function normalizeSeed(seed, userName) {
397
400
  }
398
401
  function testUser(opts = {}) {
399
402
  if (!isPlainObject(opts)) {
400
- throw new Error("testUser() expects { email?, password?, seed? }");
403
+ throw new Error("testUser() expects { email?, password?, phone?, otp?, seed? }");
401
404
  }
402
405
  const hasEmail = opts.email !== void 0;
403
406
  const hasPassword = opts.password !== void 0;
@@ -420,7 +423,30 @@ function testUser(opts = {}) {
420
423
  email = opts.email;
421
424
  password = opts.password;
422
425
  }
423
- return { email, password, seed: normalizeSeed(opts.seed, email ?? "<template>") };
426
+ const hasPhone = opts.phone !== void 0;
427
+ const hasOTP = opts.otp !== void 0;
428
+ if (hasPhone !== hasOTP) {
429
+ throw new Error(
430
+ "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"
431
+ );
432
+ }
433
+ let phone = null;
434
+ let otp = null;
435
+ if (hasPhone) {
436
+ if (typeof opts.phone !== "string" || !E164_RE.test(opts.phone)) {
437
+ throw new Error(
438
+ `testUser phone ${JSON.stringify(opts.phone)} must be E.164, e.g. "+905551112233"`
439
+ );
440
+ }
441
+ if (typeof opts.otp !== "string" || !OTP_RE.test(opts.otp)) {
442
+ throw new Error(
443
+ `testUser otp ${JSON.stringify(opts.otp)} must be ${OTP_LENGTH} digits`
444
+ );
445
+ }
446
+ phone = opts.phone;
447
+ otp = opts.otp;
448
+ }
449
+ return { email, password, phone, otp, seed: normalizeSeed(opts.seed, email ?? "<template>") };
424
450
  }
425
451
  function defineTestUsers(input) {
426
452
  if (!isPlainObject(input) || !isPlainObject(input.users)) {