openxiangda 1.0.87 → 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.
@@ -47,7 +47,7 @@ var require_classnames = __commonJS({
47
47
  init_cjs_shims();
48
48
  (function() {
49
49
  "use strict";
50
- var hasOwn2 = {}.hasOwnProperty;
50
+ var hasOwn3 = {}.hasOwnProperty;
51
51
  function classNames80() {
52
52
  var classes = "";
53
53
  for (var i2 = 0; i2 < arguments.length; i2++) {
@@ -73,7 +73,7 @@ var require_classnames = __commonJS({
73
73
  }
74
74
  var classes = "";
75
75
  for (var key in arg) {
76
- if (hasOwn2.call(arg, key) && arg[key]) {
76
+ if (hasOwn3.call(arg, key) && arg[key]) {
77
77
  classes = appendClass(classes, key);
78
78
  }
79
79
  }
@@ -1093,18 +1093,39 @@ var normalizeDynamicOrder = (value) => {
1093
1093
  }
1094
1094
  return `${value.id}:${value.isAsc === "n" ? "-" : "+"}`;
1095
1095
  };
1096
+ var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1097
+ var normalizeEnvelopeCode = (value) => {
1098
+ if (value === void 0 || value === null || value === "") {
1099
+ return 200;
1100
+ }
1101
+ const normalized = Number(value);
1102
+ return Number.isFinite(normalized) ? normalized : String(value);
1103
+ };
1104
+ var isSuccessCode = (value) => {
1105
+ if (value === void 0 || value === null || value === "") {
1106
+ return true;
1107
+ }
1108
+ const normalized = Number(value);
1109
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
1110
+ };
1111
+ var getEnvelopeCode = (rawResponse) => {
1112
+ if (isRecord(rawResponse) && hasOwn(rawResponse, "code")) {
1113
+ return rawResponse.code;
1114
+ }
1115
+ const nestedData = rawResponse?.data;
1116
+ if (isRecord(nestedData) && hasOwn(nestedData, "code")) {
1117
+ return nestedData.code;
1118
+ }
1119
+ return void 0;
1120
+ };
1096
1121
  var normalizeJsonResponse = (rawResponse) => {
1097
- const topLevelCode = Number(rawResponse?.code);
1098
- const nestedCode = Number(
1099
- rawResponse?.data?.code
1100
- );
1101
- const code = Number.isFinite(topLevelCode) ? topLevelCode : Number.isFinite(nestedCode) ? nestedCode : 200;
1122
+ const code = normalizeEnvelopeCode(getEnvelopeCode(rawResponse));
1102
1123
  const topLevelResult = isRecord(rawResponse) && "result" in rawResponse ? rawResponse.result : void 0;
1103
1124
  const nestedResult = isRecord(rawResponse?.data) && "result" in (rawResponse.data || {}) ? rawResponse.data?.result : void 0;
1104
1125
  const topLevelData = isRecord(rawResponse) && "data" in rawResponse ? rawResponse.data : void 0;
1105
1126
  const result = topLevelResult !== void 0 ? topLevelResult : nestedResult !== void 0 ? nestedResult : topLevelData !== void 0 ? topLevelData : isRecord(rawResponse) ? rawResponse : null;
1106
1127
  const nestedSuccess = typeof rawResponse?.data?.success === "boolean" ? rawResponse.data?.success : void 0;
1107
- const success = typeof rawResponse?.success === "boolean" ? Boolean(rawResponse.success) : typeof nestedSuccess === "boolean" ? Boolean(nestedSuccess) : code >= 200 && code < 300;
1128
+ const success = rawResponse?.success === false || nestedSuccess === false ? false : isSuccessCode(code);
1108
1129
  return {
1109
1130
  code,
1110
1131
  success,
@@ -1149,6 +1170,9 @@ var normalizeBinaryResponse = (rawResponse) => {
1149
1170
  };
1150
1171
  };
1151
1172
  var toSdkError = (input, payload) => {
1173
+ if (input instanceof Error && input.response) {
1174
+ return input;
1175
+ }
1152
1176
  const normalizedResponse = isRecord(input) ? normalizeJsonResponse(input) : void 0;
1153
1177
  const nextError = input instanceof Error ? input : new Error(
1154
1178
  normalizedResponse?.message || `\u8BF7\u6C42\u5931\u8D25: ${String(payload.method).toUpperCase()} ${payload.path}`
@@ -2295,7 +2319,8 @@ var createAuthClient = ({
2295
2319
  });
2296
2320
  const payload = await readPayload(response);
2297
2321
  const code = getRecordValue(payload, "code");
2298
- if (!response.ok || typeof code === "number" && code >= 400) {
2322
+ const success = getRecordValue(payload, "success");
2323
+ if (!response.ok || success === false || !isSuccessCode2(code)) {
2299
2324
  throw new AuthClientError(
2300
2325
  String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
2301
2326
  { status: response.status, code, payload }
@@ -2348,6 +2373,11 @@ var getRecordValue = (value, key) => {
2348
2373
  if (!value || typeof value !== "object") return void 0;
2349
2374
  return value[key];
2350
2375
  };
2376
+ var isSuccessCode2 = (code) => {
2377
+ if (code === void 0 || code === null || code === "") return true;
2378
+ const normalized = Number(code);
2379
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2380
+ };
2351
2381
  var resolveLoginUrl = (appType, {
2352
2382
  callbackUrl = getCurrentHref2(),
2353
2383
  callbackParamName = "callback",
@@ -2420,7 +2450,8 @@ var createPublicAccessClient = ({
2420
2450
  );
2421
2451
  const payload = await readPayload2(response);
2422
2452
  const code = getRecordValue2(payload, "code");
2423
- if (!response.ok || typeof code === "number" && code >= 400) {
2453
+ const success = getRecordValue2(payload, "success");
2454
+ if (!response.ok || success === false || !isSuccessCode3(code)) {
2424
2455
  throw new PublicAccessClientError(
2425
2456
  String(
2426
2457
  getRecordValue2(payload, "message") || `Public access session failed: ${response.status}`
@@ -2458,6 +2489,11 @@ var getRecordValue2 = (value, key) => {
2458
2489
  if (!value || typeof value !== "object") return void 0;
2459
2490
  return value[key];
2460
2491
  };
2492
+ var isSuccessCode3 = (code) => {
2493
+ if (code === void 0 || code === null || code === "") return true;
2494
+ const normalized = Number(code);
2495
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2496
+ };
2461
2497
  var getCurrentPathname = () => typeof window === "undefined" ? void 0 : window.location.pathname;
2462
2498
  var getCurrentDomain = () => typeof window === "undefined" ? void 0 : window.location.host;
2463
2499
  var getCurrentUserAgent = () => typeof navigator === "undefined" ? void 0 : navigator.userAgent;
@@ -4102,12 +4138,23 @@ var OpenXiangdaProvider = ({
4102
4138
  () => appType || resolveAppTypeFromLocation(),
4103
4139
  [appType]
4104
4140
  );
4141
+ const [accessToken, setAccessTokenState] = (0, import_react8.useState)(null);
4142
+ const setAccessToken = (0, import_react8.useCallback)(
4143
+ (nextAccessToken) => {
4144
+ setAccessTokenState(nextAccessToken || null);
4145
+ },
4146
+ []
4147
+ );
4148
+ const authorizedFetch = (0, import_react8.useMemo)(
4149
+ () => createAuthorizedFetch(resolvedFetch, accessToken),
4150
+ [accessToken, resolvedFetch]
4151
+ );
4105
4152
  const [state, setState] = (0, import_react8.useState)({
4106
4153
  data: null,
4107
4154
  loading: true,
4108
4155
  error: null
4109
4156
  });
4110
- const reload = (0, import_react8.useCallback)(async () => {
4157
+ const reload = (0, import_react8.useCallback)(async (options = {}) => {
4111
4158
  if (!resolvedAppType) {
4112
4159
  setState({
4113
4160
  data: null,
@@ -4120,8 +4167,9 @@ var OpenXiangdaProvider = ({
4120
4167
  return;
4121
4168
  }
4122
4169
  setState((prev) => ({ ...prev, loading: true, error: null }));
4170
+ const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(resolvedFetch, options.accessToken || null) : authorizedFetch;
4123
4171
  try {
4124
- const response = await resolvedFetch(
4172
+ const response = await requestFetch(
4125
4173
  buildServiceUrl3(
4126
4174
  servicePrefix,
4127
4175
  `/openxiangda-api/v1/apps/${encodeURIComponent(
@@ -4134,7 +4182,7 @@ var OpenXiangdaProvider = ({
4134
4182
  }
4135
4183
  );
4136
4184
  const payload = await readJsonPayload(response);
4137
- if (!response.ok || payload?.code >= 400) {
4185
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4138
4186
  throw createRuntimeHttpError(
4139
4187
  response,
4140
4188
  payload,
@@ -4153,7 +4201,7 @@ var OpenXiangdaProvider = ({
4153
4201
  error: normalizeRuntimeError(error)
4154
4202
  });
4155
4203
  }
4156
- }, [resolvedAppType, resolvedFetch, servicePrefix]);
4204
+ }, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
4157
4205
  (0, import_react8.useEffect)(() => {
4158
4206
  void reload();
4159
4207
  }, [reload]);
@@ -4162,10 +4210,11 @@ var OpenXiangdaProvider = ({
4162
4210
  ...state,
4163
4211
  appType: resolvedAppType,
4164
4212
  servicePrefix,
4165
- fetchImpl: resolvedFetch,
4166
- reload
4213
+ fetchImpl: authorizedFetch,
4214
+ reload,
4215
+ setAccessToken
4167
4216
  }),
4168
- [reload, resolvedAppType, resolvedFetch, servicePrefix, state]
4217
+ [authorizedFetch, reload, resolvedAppType, servicePrefix, state]
4169
4218
  );
4170
4219
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OpenXiangdaRuntimeContext.Provider, { value, children });
4171
4220
  };
@@ -4268,7 +4317,7 @@ var useCanAccessRoute = (input) => {
4268
4317
  payload
4269
4318
  };
4270
4319
  if (!disposed) {
4271
- const shouldTreatAsError = !response.ok || typeof code === "number" && code >= 500;
4320
+ const shouldTreatAsError = !response.ok || isServerErrorCode(code);
4272
4321
  setState({
4273
4322
  data,
4274
4323
  loading: false,
@@ -4400,7 +4449,7 @@ var useRuntimeAuth = () => {
4400
4449
  }
4401
4450
  );
4402
4451
  const payload = await readJsonPayload(response);
4403
- if (!response.ok || payload?.code >= 400) {
4452
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4404
4453
  throw createRuntimeHttpError(
4405
4454
  response,
4406
4455
  payload,
@@ -4432,6 +4481,19 @@ var buildServiceUrl3 = (servicePrefix, path) => {
4432
4481
  const suffix = path.startsWith("/") ? path : `/${path}`;
4433
4482
  return `${prefix2}${suffix}`;
4434
4483
  };
4484
+ var createAuthorizedFetch = (baseFetch, accessToken) => {
4485
+ if (!accessToken) return baseFetch;
4486
+ return ((input, init = {}) => {
4487
+ const headers = new Headers(init.headers || {});
4488
+ if (!headers.has("authorization")) {
4489
+ headers.set("authorization", `Bearer ${accessToken}`);
4490
+ }
4491
+ return baseFetch(input, {
4492
+ ...init,
4493
+ headers
4494
+ });
4495
+ });
4496
+ };
4435
4497
  var readJsonPayload = async (response) => {
4436
4498
  try {
4437
4499
  return await response.json();
@@ -4477,6 +4539,15 @@ var classifyRuntimeError = (status, code) => {
4477
4539
  const normalizedCode = typeof code === "string" ? Number(code) : code;
4478
4540
  if (status === 401 || normalizedCode === 401) return "unauthenticated";
4479
4541
  if (status === 403 || normalizedCode === 403) return "forbidden";
4542
+ if (typeof code === "string") {
4543
+ const normalizedText = code.toUpperCase();
4544
+ if (normalizedText.includes("DENIED") || normalizedText.includes("FORBIDDEN")) {
4545
+ return "forbidden";
4546
+ }
4547
+ if (normalizedText.includes("UNAUTH") || normalizedText.includes("LOGIN")) {
4548
+ return "unauthenticated";
4549
+ }
4550
+ }
4480
4551
  if (!status && !normalizedCode) return "network";
4481
4552
  return "unknown";
4482
4553
  };
@@ -4532,6 +4603,20 @@ var getRecordValue3 = (value, key) => {
4532
4603
  if (!value || typeof value !== "object") return void 0;
4533
4604
  return value[key];
4534
4605
  };
4606
+ var isSuccessCode4 = (code) => {
4607
+ if (code === void 0 || code === null || code === "") return true;
4608
+ const normalized = Number(code);
4609
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
4610
+ };
4611
+ var isRuntimeEnvelopeFailure = (response, payload) => {
4612
+ const code = getRecordValue3(payload, "code");
4613
+ const success = getRecordValue3(payload, "success");
4614
+ return !response.ok || success === false || !isSuccessCode4(code);
4615
+ };
4616
+ var isServerErrorCode = (code) => {
4617
+ const normalized = Number(code);
4618
+ return Number.isFinite(normalized) && normalized >= 500;
4619
+ };
4535
4620
  var getRecordString = (value, key) => {
4536
4621
  const result = getRecordValue3(value, key);
4537
4622
  return typeof result === "string" ? result : void 0;
@@ -4555,7 +4640,8 @@ var usePublicAccess = (options = {}) => {
4555
4640
  appType: runtimeAppType,
4556
4641
  servicePrefix: runtimeServicePrefix,
4557
4642
  fetchImpl: runtimeFetchImpl,
4558
- reload: reloadRuntime
4643
+ reload: reloadRuntime,
4644
+ setAccessToken
4559
4645
  } = runtime;
4560
4646
  const {
4561
4647
  appType = runtimeAppType,
@@ -4589,7 +4675,8 @@ var usePublicAccess = (options = {}) => {
4589
4675
  path: input.path || stableSessionInput.path || readPathFromLocation()
4590
4676
  });
4591
4677
  setSession(data);
4592
- await reloadRuntime();
4678
+ setAccessToken(data.accessToken);
4679
+ await reloadRuntime({ accessToken: data.accessToken });
4593
4680
  setLoading(false);
4594
4681
  return data;
4595
4682
  } catch (caught) {
@@ -4602,7 +4689,7 @@ var usePublicAccess = (options = {}) => {
4602
4689
  throw nextError;
4603
4690
  }
4604
4691
  },
4605
- [client, reloadRuntime, stableSessionInput]
4692
+ [client, reloadRuntime, setAccessToken, stableSessionInput]
4606
4693
  );
4607
4694
  (0, import_react9.useEffect)(() => {
4608
4695
  if (!autoStart) return;
@@ -4667,6 +4754,16 @@ var normalizeCssIsolation2 = (value) => {
4667
4754
  }
4668
4755
  return "none";
4669
4756
  };
4757
+ var normalizeEnvelopeCode2 = (value, fallback) => {
4758
+ if (value === void 0 || value === null || value === "") return fallback;
4759
+ const normalized = Number(value);
4760
+ return Number.isFinite(normalized) ? normalized : String(value);
4761
+ };
4762
+ var isSuccessCode5 = (value) => {
4763
+ if (value === void 0 || value === null || value === "") return true;
4764
+ const normalized = Number(value);
4765
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
4766
+ };
4670
4767
  var parseJsonResponse = async (response) => {
4671
4768
  const payload = await response.json().catch(() => null);
4672
4769
  if (!response.ok) {
@@ -4674,9 +4771,10 @@ var parseJsonResponse = async (response) => {
4674
4771
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4675
4772
  }
4676
4773
  if (payload && typeof payload === "object" && "code" in payload) {
4774
+ const code = normalizeEnvelopeCode2(payload.code, response.status);
4677
4775
  return {
4678
- code: Number(payload.code || response.status),
4679
- success: payload.success === true || payload.code === 200,
4776
+ code,
4777
+ success: payload.success !== false && isSuccessCode5(code),
4680
4778
  message: payload.message,
4681
4779
  result: payload.result ?? payload.data ?? null,
4682
4780
  data: payload.data,
@@ -5044,6 +5142,11 @@ var joinUrl = (baseUrl, url2) => {
5044
5142
  if (/^https?:\/\//i.test(url2)) return url2;
5045
5143
  return `${trimTrailingSlash2(baseUrl)}${url2.startsWith("/") ? url2 : `/${url2}`}`;
5046
5144
  };
5145
+ var isSuccessCode6 = (value) => {
5146
+ if (value === void 0 || value === null || value === "") return true;
5147
+ const code = Number(value);
5148
+ return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
5149
+ };
5047
5150
  var normalizeRuntimeFileUrl = (baseUrl, value) => {
5048
5151
  if (typeof value !== "string" || !value) return value;
5049
5152
  if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
@@ -5070,6 +5173,12 @@ var parseResponse = async (response) => {
5070
5173
  const message7 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
5071
5174
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
5072
5175
  }
5176
+ if (typeof payload === "object" && payload) {
5177
+ const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
5178
+ if (payload.success === false || hasCode && !isSuccessCode6(payload.code)) {
5179
+ throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
5180
+ }
5181
+ }
5073
5182
  if (typeof payload === "object" && payload) {
5074
5183
  return payload;
5075
5184
  }
@@ -44296,20 +44405,20 @@ var import_react267 = require("react");
44296
44405
 
44297
44406
  // packages/sdk/src/components/core/processApi.ts
44298
44407
  init_cjs_shims();
44299
- var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
44300
- 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"));
44301
- var isSuccessCode = (code) => {
44408
+ var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
44409
+ 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"));
44410
+ var isSuccessCode7 = (code) => {
44302
44411
  if (code === void 0 || code === null || code === "") return true;
44303
44412
  const normalized = Number(code);
44304
44413
  return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
44305
44414
  };
44306
44415
  var unwrapRuntimeResponse = (response) => {
44307
44416
  if (!isRuntimeEnvelope(response)) return response;
44308
- if (response.success === false || !isSuccessCode(response.code)) {
44417
+ if (response.success === false || !isSuccessCode7(response.code)) {
44309
44418
  throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
44310
44419
  }
44311
- if (hasOwn(response, "data")) return response.data;
44312
- if (hasOwn(response, "result")) return response.result;
44420
+ if (hasOwn2(response, "data")) return response.data;
44421
+ if (hasOwn2(response, "result")) return response.result;
44313
44422
  return response;
44314
44423
  };
44315
44424
  var withInitiatorSelectedApprovers = (payload, initiatorSelectedApprovers) => {