openxiangda 1.0.103 → 1.0.104

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.103",
3
+ "version": "1.0.104",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -607,7 +607,7 @@ var require_react_is_development = __commonJS({
607
607
  var ContextProvider = REACT_PROVIDER_TYPE;
608
608
  var Element2 = REACT_ELEMENT_TYPE;
609
609
  var ForwardRef2 = REACT_FORWARD_REF_TYPE;
610
- var Fragment18 = REACT_FRAGMENT_TYPE2;
610
+ var Fragment19 = REACT_FRAGMENT_TYPE2;
611
611
  var Lazy = REACT_LAZY_TYPE;
612
612
  var Memo = REACT_MEMO_TYPE;
613
613
  var Portal = REACT_PORTAL_TYPE;
@@ -675,7 +675,7 @@ var require_react_is_development = __commonJS({
675
675
  exports.ContextProvider = ContextProvider;
676
676
  exports.Element = Element2;
677
677
  exports.ForwardRef = ForwardRef2;
678
- exports.Fragment = Fragment18;
678
+ exports.Fragment = Fragment19;
679
679
  exports.Lazy = Lazy;
680
680
  exports.Memo = Memo;
681
681
  exports.Portal = Portal;
@@ -842,6 +842,10 @@ __export(runtime_exports, {
842
842
  createReactPage: () => createReactPage,
843
843
  extractFieldsFromComponentsTree: () => extractFieldsFromComponentsTree,
844
844
  fetchBrowserRuntimeBootstrap: () => fetchBrowserRuntimeBootstrap,
845
+ getAuthErrorExtra: () => getAuthErrorExtra,
846
+ getAuthErrorReason: () => getAuthErrorReason,
847
+ isAuthChallengeRequired: () => isAuthChallengeRequired,
848
+ isAuthClientError: () => isAuthClientError,
845
849
  loadCustomPageModule: () => loadCustomPageModule,
846
850
  loadRuntimeScriptModules: () => loadRuntimeScriptModules,
847
851
  mountBrowserPageRuntime: () => mountBrowserPageRuntime,
@@ -2296,8 +2300,43 @@ var AuthClientError = class extends Error {
2296
2300
  this.status = options.status;
2297
2301
  this.code = options.code;
2298
2302
  this.payload = options.payload;
2303
+ this.extra = normalizeAuthErrorExtra(
2304
+ options.extra || getRecordValue(options.payload, "extra")
2305
+ );
2306
+ this.reason = this.extra?.reason || this.extra?.guardCode || (typeof options.code === "string" ? options.code : void 0);
2307
+ this.challenge = this.extra?.challenge;
2308
+ this.retryAfter = readNumber(
2309
+ this.extra?.retryAfter ?? this.extra?.retryAfterSeconds
2310
+ );
2311
+ this.remainingAttempts = readNumber(this.extra?.remainingAttempts);
2312
+ this.lockUntil = this.extra?.lockUntil ?? null;
2299
2313
  }
2300
2314
  };
2315
+ var isAuthClientError = (error) => {
2316
+ if (error instanceof AuthClientError) return true;
2317
+ return Boolean(
2318
+ error && typeof error === "object" && error.name === "AuthClientError"
2319
+ );
2320
+ };
2321
+ var getAuthErrorExtra = (error) => {
2322
+ if (!error || typeof error !== "object") return void 0;
2323
+ const record2 = error;
2324
+ return normalizeAuthErrorExtra(record2.extra || getRecordValue(record2.payload, "extra"));
2325
+ };
2326
+ var getAuthErrorReason = (error) => {
2327
+ if (!error || typeof error !== "object") return void 0;
2328
+ const record2 = error;
2329
+ const extra = getAuthErrorExtra(error);
2330
+ return extra?.reason || extra?.guardCode || (typeof record2.reason === "string" ? record2.reason : void 0) || (typeof record2.code === "string" ? record2.code : void 0);
2331
+ };
2332
+ var isAuthChallengeRequired = (error) => {
2333
+ if (!error || typeof error !== "object") return false;
2334
+ const record2 = error;
2335
+ const code = record2.code;
2336
+ const reason = getAuthErrorReason(error);
2337
+ const extra = getAuthErrorExtra(error);
2338
+ return code === 460 || code === "460" || code === "LOGIN_CHALLENGE_REQUIRED" || reason === "LOGIN_CHALLENGE_REQUIRED" || reason === "CHALLENGE_REQUIRED" || extra?.guardCode === "LOGIN_CHALLENGE_REQUIRED";
2339
+ };
2301
2340
  var createAuthClient = ({
2302
2341
  appType,
2303
2342
  servicePrefix = "/service",
@@ -2324,7 +2363,12 @@ var createAuthClient = ({
2324
2363
  if (!response.ok || success === false || !isSuccessCode2(code)) {
2325
2364
  throw new AuthClientError(
2326
2365
  String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
2327
- { status: response.status, code, payload }
2366
+ {
2367
+ status: response.status,
2368
+ code,
2369
+ payload,
2370
+ extra: normalizeAuthErrorExtra(getRecordValue(payload, "extra"))
2371
+ }
2328
2372
  );
2329
2373
  }
2330
2374
  return unwrapPayload(payload);
@@ -2374,6 +2418,27 @@ var getRecordValue = (value, key) => {
2374
2418
  if (!value || typeof value !== "object") return void 0;
2375
2419
  return value[key];
2376
2420
  };
2421
+ var normalizeAuthErrorExtra = (value) => {
2422
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
2423
+ const record2 = value;
2424
+ const challenge = record2.challenge && typeof record2.challenge === "object" && !Array.isArray(record2.challenge) ? record2.challenge : void 0;
2425
+ const reason = readString(record2.reason);
2426
+ const guardCode = readString(record2.guardCode);
2427
+ return {
2428
+ ...record2,
2429
+ ...reason ? { reason } : {},
2430
+ ...guardCode ? { guardCode } : {},
2431
+ ...challenge ? { challenge } : {},
2432
+ ...readNumber(record2.retryAfter) !== void 0 ? { retryAfter: readNumber(record2.retryAfter) } : {},
2433
+ ...readNumber(record2.retryAfterSeconds) !== void 0 ? { retryAfterSeconds: readNumber(record2.retryAfterSeconds) } : {},
2434
+ ...readNumber(record2.remainingAttempts) !== void 0 ? { remainingAttempts: readNumber(record2.remainingAttempts) } : {}
2435
+ };
2436
+ };
2437
+ var readString = (value) => typeof value === "string" ? value : void 0;
2438
+ var readNumber = (value) => {
2439
+ const numberValue = Number(value);
2440
+ return Number.isFinite(numberValue) ? numberValue : void 0;
2441
+ };
2377
2442
  var isSuccessCode2 = (code) => {
2378
2443
  if (code === void 0 || code === null || code === "") return true;
2379
2444
  const normalized = Number(code);
@@ -4114,6 +4179,7 @@ var LoginPage = ({
4114
4179
  "login"
4115
4180
  );
4116
4181
  const [phoneChallengeId, setPhoneChallengeId] = (0, import_react7.useState)("");
4182
+ const [passwordChallenge, setPasswordChallenge] = (0, import_react7.useState)(null);
4117
4183
  const [submitting, setSubmitting] = (0, import_react7.useState)(false);
4118
4184
  const [sendingCode, setSendingCode] = (0, import_react7.useState)(false);
4119
4185
  const [error, setError] = (0, import_react7.useState)(null);
@@ -4136,6 +4202,7 @@ var LoginPage = ({
4136
4202
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4137
4203
  PasswordLoginForm,
4138
4204
  {
4205
+ challenge: passwordChallenge,
4139
4206
  form: passwordForm,
4140
4207
  loading: submitting,
4141
4208
  onFinish: async (values) => {
@@ -4144,12 +4211,25 @@ var LoginPage = ({
4144
4211
  try {
4145
4212
  await handleSuccess(
4146
4213
  await auth.passwordLogin({
4214
+ challengeAnswer: passwordChallenge ? values.challengeAnswer : void 0,
4215
+ challengeId: readChallengeId(passwordChallenge),
4216
+ clientFingerprint: getOrCreateLoginFingerprint(auth.client),
4147
4217
  username: values.username,
4148
4218
  password: values.password
4149
4219
  })
4150
4220
  );
4221
+ setPasswordChallenge(null);
4151
4222
  } catch (loginError) {
4152
- setError(normalizeError(loginError).message);
4223
+ if (isAuthChallengeRequired(loginError)) {
4224
+ const nextChallenge = getAuthErrorExtra(loginError)?.challenge;
4225
+ if (nextChallenge) {
4226
+ setPasswordChallenge(nextChallenge);
4227
+ passwordForm.setFieldValue("challengeAnswer", "");
4228
+ }
4229
+ } else {
4230
+ setPasswordChallenge(null);
4231
+ }
4232
+ setError(formatAuthErrorMessage(loginError));
4153
4233
  } finally {
4154
4234
  setSubmitting(false);
4155
4235
  }
@@ -4219,6 +4299,7 @@ var LoginPage = ({
4219
4299
  allowRegister,
4220
4300
  auth,
4221
4301
  handleSuccess,
4302
+ passwordChallenge,
4222
4303
  passwordForm,
4223
4304
  passwordMethod,
4224
4305
  phoneChallengeId,
@@ -4372,7 +4453,7 @@ var LoginPage = ({
4372
4453
  }
4373
4454
  );
4374
4455
  };
4375
- var PasswordLoginForm = ({ form, loading, onFinish }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_antd2.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
4456
+ var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_antd2.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
4376
4457
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4377
4458
  import_antd2.Form.Item,
4378
4459
  {
@@ -4391,6 +4472,26 @@ var PasswordLoginForm = ({ form, loading, onFinish }) => /* @__PURE__ */ (0, imp
4391
4472
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Input.Password, { autoComplete: "current-password" })
4392
4473
  }
4393
4474
  ),
4475
+ challenge ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
4476
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4477
+ import_antd2.Alert,
4478
+ {
4479
+ showIcon: true,
4480
+ type: "warning",
4481
+ message: "\u8BF7\u5B8C\u6210\u989D\u5916\u9A8C\u8BC1",
4482
+ description: readChallengeQuestion(challenge) || "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801\u540E\u7EE7\u7EED\u767B\u5F55\u3002"
4483
+ }
4484
+ ),
4485
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4486
+ import_antd2.Form.Item,
4487
+ {
4488
+ label: "\u9A8C\u8BC1\u7B54\u6848",
4489
+ name: "challengeAnswer",
4490
+ rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7B54\u6848" }],
4491
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Input, { autoComplete: "one-time-code" })
4492
+ }
4493
+ )
4494
+ ] }) : null,
4394
4495
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Button, { block: true, htmlType: "submit", icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.LoginOutlined, {}), loading, type: "primary", children: "\u767B\u5F55" })
4395
4496
  ] });
4396
4497
  var PhoneCodeLoginForm = ({
@@ -4452,6 +4553,22 @@ var PhoneCodeLoginForm = ({
4452
4553
  ] });
4453
4554
  var findMethod = (methods, type4) => methods.find((method4) => method4.type === type4);
4454
4555
  var normalizeError = (error) => error instanceof Error ? error : new Error(String(error || "\u8BF7\u6C42\u5931\u8D25"));
4556
+ var formatAuthErrorMessage = (error) => {
4557
+ const normalized = normalizeError(error);
4558
+ const extra = getAuthErrorExtra(error);
4559
+ const reason = getAuthErrorReason(error);
4560
+ if (isAuthChallengeRequired(error)) {
4561
+ return extra?.challenge?.question ? "\u8BF7\u5B8C\u6210\u4E0B\u65B9\u9A8C\u8BC1\u540E\u518D\u767B\u5F55" : normalized.message || "\u8BF7\u5148\u5B8C\u6210\u989D\u5916\u9A8C\u8BC1\u540E\u518D\u5C1D\u8BD5\u767B\u5F55";
4562
+ }
4563
+ if (reason === "LOGIN_BLOCKED" || reason === "USERNAME_BLOCKED" || reason === "IP_BLOCKED" || reason === "ACCOUNT_LOCKED") {
4564
+ const retryAfter = Number(extra?.retryAfter ?? extra?.retryAfterSeconds);
4565
+ if (Number.isFinite(retryAfter) && retryAfter > 0) {
4566
+ const minutes = Math.ceil(retryAfter / 60);
4567
+ return `\u767B\u5F55\u53D7\u9650\uFF0C\u8BF7\u7EA6 ${minutes} \u5206\u949F\u540E\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458`;
4568
+ }
4569
+ }
4570
+ return normalized.message || "\u767B\u5F55\u5931\u8D25";
4571
+ };
4455
4572
  var getString = (value, key) => {
4456
4573
  if (!value || typeof value !== "object") return void 0;
4457
4574
  const result = value[key];
@@ -4485,7 +4602,21 @@ var getOrCreateGuestIdentifier = (client) => {
4485
4602
  window.localStorage.setItem(key, next);
4486
4603
  return next;
4487
4604
  };
4605
+ var getOrCreateLoginFingerprint = (client) => {
4606
+ const key = `openxiangda:${client.appType}:login_fingerprint`;
4607
+ if (typeof window === "undefined") return createGuestIdentifier();
4608
+ const current = window.localStorage.getItem(key);
4609
+ const id = current || createGuestIdentifier();
4610
+ if (!current) window.localStorage.setItem(key, id);
4611
+ return `${id}:${window.navigator?.userAgent || "unknown"}`;
4612
+ };
4488
4613
  var createGuestIdentifier = () => `guest_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
4614
+ var readChallengeId = (challenge) => {
4615
+ if (!challenge) return void 0;
4616
+ const id = challenge.id || challenge.challengeId;
4617
+ return typeof id === "string" && id.trim() ? id.trim() : void 0;
4618
+ };
4619
+ var readChallengeQuestion = (challenge) => typeof challenge.question === "string" ? challenge.question : void 0;
4489
4620
  var getCurrentHref3 = () => typeof window === "undefined" ? "" : window.location.href;
4490
4621
  var getCurrentHostname = () => typeof window === "undefined" ? "" : window.location.hostname;
4491
4622
  var getCallbackUrl = () => {