openxiangda 1.0.88 → 1.0.89

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.
@@ -34,7 +34,7 @@ var require_classnames = __commonJS({
34
34
  "use strict";
35
35
  (function() {
36
36
  "use strict";
37
- var hasOwn2 = {}.hasOwnProperty;
37
+ var hasOwn3 = {}.hasOwnProperty;
38
38
  function classNames80() {
39
39
  var classes = "";
40
40
  for (var i2 = 0; i2 < arguments.length; i2++) {
@@ -60,7 +60,7 @@ var require_classnames = __commonJS({
60
60
  }
61
61
  var classes = "";
62
62
  for (var key in arg) {
63
- if (hasOwn2.call(arg, key) && arg[key]) {
63
+ if (hasOwn3.call(arg, key) && arg[key]) {
64
64
  classes = appendClass(classes, key);
65
65
  }
66
66
  }
@@ -1007,18 +1007,39 @@ var normalizeDynamicOrder = (value) => {
1007
1007
  }
1008
1008
  return `${value.id}:${value.isAsc === "n" ? "-" : "+"}`;
1009
1009
  };
1010
+ var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1011
+ var normalizeEnvelopeCode = (value) => {
1012
+ if (value === void 0 || value === null || value === "") {
1013
+ return 200;
1014
+ }
1015
+ const normalized = Number(value);
1016
+ return Number.isFinite(normalized) ? normalized : String(value);
1017
+ };
1018
+ var isSuccessCode = (value) => {
1019
+ if (value === void 0 || value === null || value === "") {
1020
+ return true;
1021
+ }
1022
+ const normalized = Number(value);
1023
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
1024
+ };
1025
+ var getEnvelopeCode = (rawResponse) => {
1026
+ if (isRecord(rawResponse) && hasOwn(rawResponse, "code")) {
1027
+ return rawResponse.code;
1028
+ }
1029
+ const nestedData = rawResponse?.data;
1030
+ if (isRecord(nestedData) && hasOwn(nestedData, "code")) {
1031
+ return nestedData.code;
1032
+ }
1033
+ return void 0;
1034
+ };
1010
1035
  var normalizeJsonResponse = (rawResponse) => {
1011
- const topLevelCode = Number(rawResponse?.code);
1012
- const nestedCode = Number(
1013
- rawResponse?.data?.code
1014
- );
1015
- const code = Number.isFinite(topLevelCode) ? topLevelCode : Number.isFinite(nestedCode) ? nestedCode : 200;
1036
+ const code = normalizeEnvelopeCode(getEnvelopeCode(rawResponse));
1016
1037
  const topLevelResult = isRecord(rawResponse) && "result" in rawResponse ? rawResponse.result : void 0;
1017
1038
  const nestedResult = isRecord(rawResponse?.data) && "result" in (rawResponse.data || {}) ? rawResponse.data?.result : void 0;
1018
1039
  const topLevelData = isRecord(rawResponse) && "data" in rawResponse ? rawResponse.data : void 0;
1019
1040
  const result = topLevelResult !== void 0 ? topLevelResult : nestedResult !== void 0 ? nestedResult : topLevelData !== void 0 ? topLevelData : isRecord(rawResponse) ? rawResponse : null;
1020
1041
  const nestedSuccess = typeof rawResponse?.data?.success === "boolean" ? rawResponse.data?.success : void 0;
1021
- const success = typeof rawResponse?.success === "boolean" ? Boolean(rawResponse.success) : typeof nestedSuccess === "boolean" ? Boolean(nestedSuccess) : code >= 200 && code < 300;
1042
+ const success = rawResponse?.success === false || nestedSuccess === false ? false : isSuccessCode(code);
1022
1043
  return {
1023
1044
  code,
1024
1045
  success,
@@ -1063,6 +1084,9 @@ var normalizeBinaryResponse = (rawResponse) => {
1063
1084
  };
1064
1085
  };
1065
1086
  var toSdkError = (input, payload) => {
1087
+ if (input instanceof Error && input.response) {
1088
+ return input;
1089
+ }
1066
1090
  const normalizedResponse = isRecord(input) ? normalizeJsonResponse(input) : void 0;
1067
1091
  const nextError = input instanceof Error ? input : new Error(
1068
1092
  normalizedResponse?.message || `\u8BF7\u6C42\u5931\u8D25: ${String(payload.method).toUpperCase()} ${payload.path}`
@@ -2202,7 +2226,8 @@ var createAuthClient = ({
2202
2226
  });
2203
2227
  const payload = await readPayload(response);
2204
2228
  const code = getRecordValue(payload, "code");
2205
- if (!response.ok || typeof code === "number" && code >= 400) {
2229
+ const success = getRecordValue(payload, "success");
2230
+ if (!response.ok || success === false || !isSuccessCode2(code)) {
2206
2231
  throw new AuthClientError(
2207
2232
  String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
2208
2233
  { status: response.status, code, payload }
@@ -2255,6 +2280,11 @@ var getRecordValue = (value, key) => {
2255
2280
  if (!value || typeof value !== "object") return void 0;
2256
2281
  return value[key];
2257
2282
  };
2283
+ var isSuccessCode2 = (code) => {
2284
+ if (code === void 0 || code === null || code === "") return true;
2285
+ const normalized = Number(code);
2286
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2287
+ };
2258
2288
  var resolveLoginUrl = (appType, {
2259
2289
  callbackUrl = getCurrentHref2(),
2260
2290
  callbackParamName = "callback",
@@ -2326,7 +2356,8 @@ var createPublicAccessClient = ({
2326
2356
  );
2327
2357
  const payload = await readPayload2(response);
2328
2358
  const code = getRecordValue2(payload, "code");
2329
- if (!response.ok || typeof code === "number" && code >= 400) {
2359
+ const success = getRecordValue2(payload, "success");
2360
+ if (!response.ok || success === false || !isSuccessCode3(code)) {
2330
2361
  throw new PublicAccessClientError(
2331
2362
  String(
2332
2363
  getRecordValue2(payload, "message") || `Public access session failed: ${response.status}`
@@ -2364,6 +2395,11 @@ var getRecordValue2 = (value, key) => {
2364
2395
  if (!value || typeof value !== "object") return void 0;
2365
2396
  return value[key];
2366
2397
  };
2398
+ var isSuccessCode3 = (code) => {
2399
+ if (code === void 0 || code === null || code === "") return true;
2400
+ const normalized = Number(code);
2401
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2402
+ };
2367
2403
  var getCurrentPathname = () => typeof window === "undefined" ? void 0 : window.location.pathname;
2368
2404
  var getCurrentDomain = () => typeof window === "undefined" ? void 0 : window.location.host;
2369
2405
  var getCurrentUserAgent = () => typeof navigator === "undefined" ? void 0 : navigator.userAgent;
@@ -4052,7 +4088,7 @@ var OpenXiangdaProvider = ({
4052
4088
  }
4053
4089
  );
4054
4090
  const payload = await readJsonPayload(response);
4055
- if (!response.ok || payload?.code >= 400) {
4091
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4056
4092
  throw createRuntimeHttpError(
4057
4093
  response,
4058
4094
  payload,
@@ -4187,7 +4223,7 @@ var useCanAccessRoute = (input) => {
4187
4223
  payload
4188
4224
  };
4189
4225
  if (!disposed) {
4190
- const shouldTreatAsError = !response.ok || typeof code === "number" && code >= 500;
4226
+ const shouldTreatAsError = !response.ok || isServerErrorCode(code);
4191
4227
  setState({
4192
4228
  data,
4193
4229
  loading: false,
@@ -4319,7 +4355,7 @@ var useRuntimeAuth = () => {
4319
4355
  }
4320
4356
  );
4321
4357
  const payload = await readJsonPayload(response);
4322
- if (!response.ok || payload?.code >= 400) {
4358
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4323
4359
  throw createRuntimeHttpError(
4324
4360
  response,
4325
4361
  payload,
@@ -4409,6 +4445,15 @@ var classifyRuntimeError = (status, code) => {
4409
4445
  const normalizedCode = typeof code === "string" ? Number(code) : code;
4410
4446
  if (status === 401 || normalizedCode === 401) return "unauthenticated";
4411
4447
  if (status === 403 || normalizedCode === 403) return "forbidden";
4448
+ if (typeof code === "string") {
4449
+ const normalizedText = code.toUpperCase();
4450
+ if (normalizedText.includes("DENIED") || normalizedText.includes("FORBIDDEN")) {
4451
+ return "forbidden";
4452
+ }
4453
+ if (normalizedText.includes("UNAUTH") || normalizedText.includes("LOGIN")) {
4454
+ return "unauthenticated";
4455
+ }
4456
+ }
4412
4457
  if (!status && !normalizedCode) return "network";
4413
4458
  return "unknown";
4414
4459
  };
@@ -4464,6 +4509,20 @@ var getRecordValue3 = (value, key) => {
4464
4509
  if (!value || typeof value !== "object") return void 0;
4465
4510
  return value[key];
4466
4511
  };
4512
+ var isSuccessCode4 = (code) => {
4513
+ if (code === void 0 || code === null || code === "") return true;
4514
+ const normalized = Number(code);
4515
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
4516
+ };
4517
+ var isRuntimeEnvelopeFailure = (response, payload) => {
4518
+ const code = getRecordValue3(payload, "code");
4519
+ const success = getRecordValue3(payload, "success");
4520
+ return !response.ok || success === false || !isSuccessCode4(code);
4521
+ };
4522
+ var isServerErrorCode = (code) => {
4523
+ const normalized = Number(code);
4524
+ return Number.isFinite(normalized) && normalized >= 500;
4525
+ };
4467
4526
  var getRecordString = (value, key) => {
4468
4527
  const result = getRecordValue3(value, key);
4469
4528
  return typeof result === "string" ? result : void 0;
@@ -4596,6 +4655,16 @@ var normalizeCssIsolation2 = (value) => {
4596
4655
  }
4597
4656
  return "none";
4598
4657
  };
4658
+ var normalizeEnvelopeCode2 = (value, fallback) => {
4659
+ if (value === void 0 || value === null || value === "") return fallback;
4660
+ const normalized = Number(value);
4661
+ return Number.isFinite(normalized) ? normalized : String(value);
4662
+ };
4663
+ var isSuccessCode5 = (value) => {
4664
+ if (value === void 0 || value === null || value === "") return true;
4665
+ const normalized = Number(value);
4666
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
4667
+ };
4599
4668
  var parseJsonResponse = async (response) => {
4600
4669
  const payload = await response.json().catch(() => null);
4601
4670
  if (!response.ok) {
@@ -4603,9 +4672,10 @@ var parseJsonResponse = async (response) => {
4603
4672
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4604
4673
  }
4605
4674
  if (payload && typeof payload === "object" && "code" in payload) {
4675
+ const code = normalizeEnvelopeCode2(payload.code, response.status);
4606
4676
  return {
4607
- code: Number(payload.code || response.status),
4608
- success: payload.success === true || payload.code === 200,
4677
+ code,
4678
+ success: payload.success !== false && isSuccessCode5(code),
4609
4679
  message: payload.message,
4610
4680
  result: payload.result ?? payload.data ?? null,
4611
4681
  data: payload.data,
@@ -4971,6 +5041,11 @@ var joinUrl = (baseUrl, url2) => {
4971
5041
  if (/^https?:\/\//i.test(url2)) return url2;
4972
5042
  return `${trimTrailingSlash2(baseUrl)}${url2.startsWith("/") ? url2 : `/${url2}`}`;
4973
5043
  };
5044
+ var isSuccessCode6 = (value) => {
5045
+ if (value === void 0 || value === null || value === "") return true;
5046
+ const code = Number(value);
5047
+ return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
5048
+ };
4974
5049
  var normalizeRuntimeFileUrl = (baseUrl, value) => {
4975
5050
  if (typeof value !== "string" || !value) return value;
4976
5051
  if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
@@ -4997,6 +5072,12 @@ var parseResponse = async (response) => {
4997
5072
  const message7 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
4998
5073
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4999
5074
  }
5075
+ if (typeof payload === "object" && payload) {
5076
+ const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
5077
+ if (payload.success === false || hasCode && !isSuccessCode6(payload.code)) {
5078
+ throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
5079
+ }
5080
+ }
5000
5081
  if (typeof payload === "object" && payload) {
5001
5082
  return payload;
5002
5083
  }
@@ -43427,20 +43508,20 @@ async function validateAndNotify(validateAllWithErrors) {
43427
43508
  import { useState as useState79, useEffect as useEffect91, useCallback as useCallback27, useRef as useRef87 } from "react";
43428
43509
 
43429
43510
  // packages/sdk/src/components/core/processApi.ts
43430
- var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
43431
- var isRuntimeEnvelope = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (hasOwn(value, "code") || hasOwn(value, "success") || hasOwn(value, "data") || hasOwn(value, "result") || hasOwn(value, "message") || hasOwn(value, "error"));
43432
- var isSuccessCode = (code) => {
43511
+ var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
43512
+ var isRuntimeEnvelope = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (hasOwn2(value, "code") || hasOwn2(value, "success") || hasOwn2(value, "data") || hasOwn2(value, "result") || hasOwn2(value, "message") || hasOwn2(value, "error"));
43513
+ var isSuccessCode7 = (code) => {
43433
43514
  if (code === void 0 || code === null || code === "") return true;
43434
43515
  const normalized = Number(code);
43435
43516
  return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
43436
43517
  };
43437
43518
  var unwrapRuntimeResponse = (response) => {
43438
43519
  if (!isRuntimeEnvelope(response)) return response;
43439
- if (response.success === false || !isSuccessCode(response.code)) {
43520
+ if (response.success === false || !isSuccessCode7(response.code)) {
43440
43521
  throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
43441
43522
  }
43442
- if (hasOwn(response, "data")) return response.data;
43443
- if (hasOwn(response, "result")) return response.result;
43523
+ if (hasOwn2(response, "data")) return response.data;
43524
+ if (hasOwn2(response, "result")) return response.result;
43444
43525
  return response;
43445
43526
  };
43446
43527
  var withInitiatorSelectedApprovers = (payload, initiatorSelectedApprovers) => {