@tencent-ai/workbuddy-cloud-sdk 0.1.1-dev.2eb913e.202609082341 → 0.1.1-dev.520de95.202609090209

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/lib/index.cjs CHANGED
@@ -619,7 +619,7 @@ var AuthModule = class {
619
619
  const body = {
620
620
  verification_token: credentials.verificationToken
621
621
  };
622
- if (credentials.phone) body.phone_number = credentials.phone;
622
+ if (credentials.phone) body.phone_number = normalizePhone(credentials.phone);
623
623
  if (credentials.email) body.email = credentials.email;
624
624
  if (credentials.password) body.password = credentials.password;
625
625
  return this.postForSession(AUTH_PATHS.signUp, body);
@@ -642,7 +642,7 @@ var AuthModule = class {
642
642
  async sendOtp(credentials) {
643
643
  const body = {};
644
644
  if (credentials.phone) {
645
- body.phone_number = credentials.phone;
645
+ body.phone_number = normalizePhone(credentials.phone);
646
646
  body.target = "ANY";
647
647
  } else if (credentials.email) {
648
648
  body.email = credentials.email;
@@ -677,6 +677,7 @@ var AuthModule = class {
677
677
  return fail(sent.error);
678
678
  }
679
679
  const { verificationId, isExistingUser } = sent.data;
680
+ const phone = credentials.phone ? normalizePhone(credentials.phone) : void 0;
680
681
  return ok({
681
682
  verificationId,
682
683
  isExistingUser,
@@ -685,7 +686,7 @@ var AuthModule = class {
685
686
  verificationId,
686
687
  token,
687
688
  email: credentials.email,
688
- phone: credentials.phone,
689
+ phone,
689
690
  isExistingUser,
690
691
  password
691
692
  }), "verify")
@@ -705,7 +706,7 @@ var AuthModule = class {
705
706
  * 承载邮箱/手机/用户名三种形态(runtime-auth-design §3.2)。
706
707
  */
707
708
  async verifyOtp(params) {
708
- const identifier = params.phone ?? params.email ?? "";
709
+ const identifier = params.phone ? normalizePhone(params.phone) : params.email ?? "";
709
710
  if (!params.verificationId || !params.token || !identifier) {
710
711
  return fail(badRequest("verifyOtp requires verificationId, token and either email or phone"));
711
712
  }
@@ -1106,6 +1107,17 @@ function badRequest(message) {
1106
1107
  };
1107
1108
  }
1108
1109
  __name(badRequest, "badRequest");
1110
+ function normalizePhone(phone) {
1111
+ const digits = phone.replace(/\D/g, "");
1112
+ let local = digits;
1113
+ if (local.startsWith("0086")) {
1114
+ local = local.slice(4);
1115
+ } else if (local.startsWith("86") && local.length === 13) {
1116
+ local = local.slice(2);
1117
+ }
1118
+ return /^1\d{10}$/.test(local) ? `+86 ${local}` : phone;
1119
+ }
1120
+ __name(normalizePhone, "normalizePhone");
1109
1121
  function isCloudError(v) {
1110
1122
  return !!v && typeof v === "object" && typeof v.kind === "string";
1111
1123
  }