@h-ai/core 0.1.0-alpha.66 → 0.1.0-alpha.68

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.
@@ -19705,25 +19705,15 @@ var LoggingConfigSchema = external_exports.object({
19705
19705
  /** 要脱敏的字段路径列表(如 ['password', 'token'],默认 []) */
19706
19706
  redact: external_exports.array(external_exports.string()).default([])
19707
19707
  });
19708
- var IdConfigSchema = external_exports.object({
19709
- /** ID 前缀(可选,生成时自动拼接) */
19710
- prefix: external_exports.string().optional(),
19711
- /** ID 长度(范围 6-64,默认 21) */
19712
- length: external_exports.number().int().min(6).max(64).default(21)
19713
- });
19714
- var CoreConfigSchema = external_exports.object({
19708
+ var CoreConfigSchema = external_exports.strictObject({
19715
19709
  /** 应用名称(默认 'hai Admin') */
19716
19710
  name: external_exports.string().default("hai Admin"),
19717
19711
  /** 应用版本(默认 '0.1.0') */
19718
19712
  version: external_exports.string().default("0.1.0"),
19719
19713
  /** 运行环境(默认 'development') */
19720
19714
  env: EnvSchema.default("development"),
19721
- /** 是否调试模式(默认 false) */
19722
- debug: external_exports.boolean().default(false),
19723
19715
  /** 日志配置(可选) */
19724
19716
  logging: LoggingConfigSchema.optional(),
19725
- /** ID 生成器配置(可选) */
19726
- id: IdConfigSchema.optional(),
19727
19717
  /** 默认语言(默认 'zh-CN') */
19728
19718
  defaultLocale: external_exports.string().default("zh-CN")
19729
19719
  });
@@ -19826,131 +19816,6 @@ var ConfigErrorInfo = {
19826
19816
  CONFIG_NOT_LOADED: "014:500"
19827
19817
  };
19828
19818
  var HaiConfigError = error62.buildHaiErrorsDef("core", ConfigErrorInfo);
19829
- var DEFAULT_LENGTH = 21;
19830
- var SHORT_LENGTH = 10;
19831
- var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
19832
- var NANOID_REGEX_CACHE = /* @__PURE__ */ new Map();
19833
- function generateUUID() {
19834
- if (typeof crypto !== "undefined" && crypto.randomUUID) {
19835
- return crypto.randomUUID();
19836
- }
19837
- const bytes = new Uint8Array(16);
19838
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
19839
- crypto.getRandomValues(bytes);
19840
- } else {
19841
- for (let i = 0; i < 16; i++) {
19842
- bytes[i] = Math.floor(Math.random() * 256);
19843
- }
19844
- }
19845
- bytes[6] = bytes[6] & 15 | 64;
19846
- bytes[8] = bytes[8] & 63 | 128;
19847
- const hex3 = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
19848
- return `${hex3.slice(0, 8)}-${hex3.slice(8, 12)}-${hex3.slice(12, 16)}-${hex3.slice(16, 20)}-${hex3.slice(20)}`;
19849
- }
19850
- var id = {
19851
- /**
19852
- * 生成标准 nanoid(默认 21 字符)。
19853
- *
19854
- * @param length - ID 长度
19855
- * @returns nanoid 字符串
19856
- *
19857
- * @example
19858
- * ```ts
19859
- * const id = core.id.generate(16)
19860
- * ```
19861
- */
19862
- generate(length = DEFAULT_LENGTH) {
19863
- return nanoid$1(length);
19864
- },
19865
- /**
19866
- * 生成短 ID(10 字符)。
19867
- *
19868
- * @example
19869
- * ```ts
19870
- * const shortId = core.id.short()
19871
- * ```
19872
- */
19873
- short() {
19874
- return nanoid$1(SHORT_LENGTH);
19875
- },
19876
- /**
19877
- * 生成带前缀的 ID。
19878
- *
19879
- * @param prefix - 前缀
19880
- * @param length - ID 长度
19881
- *
19882
- * @example
19883
- * ```ts
19884
- * const userId = core.id.withPrefix('user_')
19885
- * ```
19886
- */
19887
- withPrefix(prefix, length = DEFAULT_LENGTH) {
19888
- return `${prefix}${nanoid$1(length)}`;
19889
- },
19890
- /**
19891
- * 生成 Trace ID。
19892
- *
19893
- * @example
19894
- * ```ts
19895
- * const traceId = core.id.trace()
19896
- * ```
19897
- */
19898
- trace() {
19899
- return `trace-${nanoid$1()}`;
19900
- },
19901
- /**
19902
- * 生成 Request ID。
19903
- *
19904
- * @example
19905
- * ```ts
19906
- * const requestId = core.id.request()
19907
- * ```
19908
- */
19909
- request() {
19910
- return `req-${nanoid$1()}`;
19911
- },
19912
- /**
19913
- * 生成 UUID v4。
19914
- *
19915
- * @example
19916
- * ```ts
19917
- * const uuid = core.id.uuid()
19918
- * ```
19919
- */
19920
- uuid() {
19921
- return generateUUID();
19922
- },
19923
- /**
19924
- * 验证是否为有效的 UUID v4。
19925
- *
19926
- * @example
19927
- * ```ts
19928
- * core.id.isValidUUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
19929
- * ```
19930
- */
19931
- isValidUUID(uuid3) {
19932
- return UUID_REGEX.test(uuid3);
19933
- },
19934
- /**
19935
- * 验证是否为有效的 nanoid。
19936
- *
19937
- * @param str - 待验证字符串
19938
- * @param length - 期望长度
19939
- *
19940
- * @example
19941
- * ```ts
19942
- * core.id.isValidNanoId('abc', 3)
19943
- * ```
19944
- */
19945
- isValidNanoId(str, length = DEFAULT_LENGTH) {
19946
- let regex = NANOID_REGEX_CACHE.get(length);
19947
- if (!regex) {
19948
- regex = new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
19949
- NANOID_REGEX_CACHE.set(length, regex);
19950
- }
19951
- return regex.test(str);
19952
- }
19953
- };
19954
19819
 
19955
19820
  // messages/en-US.json
19956
19821
  var en_US_default = {
@@ -20004,7 +19869,64 @@ var en_US_default = {
20004
19869
  core_configParseFailed: "Failed to parse config file: {filePath}",
20005
19870
  core_configValidationFailed: "Config validation failed",
20006
19871
  core_configNotLoaded: "Config '{name}' is not loaded",
20007
- core_configUnsupportedInBrowser: "Browser does not support file-based config; use core.config on the server or pass browser options through core.init({ logging })"
19872
+ core_configUnsupportedInBrowser: "Browser does not support file-based config; use core.config on the server or pass browser options through core.init({ logging })",
19873
+ core_cryptoRandomUnavailable: "Cryptographic random source is unavailable"
19874
+ };
19875
+
19876
+ // messages/ja-JP.json
19877
+ var ja_JP_default = {
19878
+ $schema: "https://inlang.com/schema/inlang-message-format",
19879
+ core_errorUnknown: "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC",
19880
+ core_errorNetwork: "\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC",
19881
+ core_errorTimeout: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F",
19882
+ core_errorNotFound: "\u30EA\u30BD\u30FC\u30B9\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",
19883
+ core_errorUnauthorized: "\u8A8D\u8A3C\u3055\u308C\u3066\u3044\u307E\u305B\u3093",
19884
+ core_errorForbidden: "\u30A2\u30AF\u30BB\u30B9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F",
19885
+ core_errorValidation: "\u5165\u529B\u5185\u5BB9\u306E\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
19886
+ core_errorInternal: "\u5185\u90E8\u30A8\u30E9\u30FC",
19887
+ core_actionConfirm: "\u78BA\u8A8D",
19888
+ core_actionCancel: "\u30AD\u30E3\u30F3\u30BB\u30EB",
19889
+ core_actionSave: "\u4FDD\u5B58",
19890
+ core_actionDelete: "\u524A\u9664",
19891
+ core_actionEdit: "\u7DE8\u96C6",
19892
+ core_actionCreate: "\u4F5C\u6210",
19893
+ core_actionUpdate: "\u66F4\u65B0",
19894
+ core_actionSearch: "\u691C\u7D22",
19895
+ core_actionReset: "\u30EA\u30BB\u30C3\u30C8",
19896
+ core_actionSubmit: "\u9001\u4FE1",
19897
+ core_actionLoading: "\u8AAD\u307F\u8FBC\u307F\u4E2D...",
19898
+ core_actionRetry: "\u518D\u8A66\u884C",
19899
+ core_statusSuccess: "\u6210\u529F",
19900
+ core_statusFailed: "\u5931\u6557",
19901
+ core_statusPending: "\u4FDD\u7559\u4E2D",
19902
+ core_statusProcessing: "\u51E6\u7406\u4E2D",
19903
+ core_statusCompleted: "\u5B8C\u4E86",
19904
+ core_statusCancelled: "\u30AD\u30E3\u30F3\u30BB\u30EB\u6E08\u307F",
19905
+ core_validationRequired: "{field}\u306F\u5FC5\u9808\u3067\u3059",
19906
+ core_validationMinLength: "{field}\u306F{min}\u6587\u5B57\u4EE5\u4E0A\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19907
+ core_validationMaxLength: "{field}\u306F{max}\u6587\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19908
+ core_validationEmail: "\u6709\u52B9\u306A\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19909
+ core_validationUrl: "\u6709\u52B9\u306AURL\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19910
+ core_validationNumber: "\u6709\u52B9\u306A\u6570\u5024\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19911
+ core_validationInteger: "\u6574\u6570\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19912
+ core_validationPositive: "\u6B63\u306E\u6570\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19913
+ core_validationPattern: "{field}\u306E\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",
19914
+ core_timeJustNow: "\u305F\u3063\u305F\u4ECA",
19915
+ core_timeSecondsAgo: "{n}\u79D2\u524D",
19916
+ core_timeMinutesAgo: "{n}\u5206\u524D",
19917
+ core_timeHoursAgo: "{n}\u6642\u9593\u524D",
19918
+ core_timeDaysAgo: "{n}\u65E5\u524D",
19919
+ core_timeWeeksAgo: "{n}\u9031\u9593\u524D",
19920
+ core_timeMonthsAgo: "{n}\u304B\u6708\u524D",
19921
+ core_timeYearsAgo: "{n}\u5E74\u524D",
19922
+ core_browserFeatureUnsupported: "\u3053\u306E\u30D6\u30E9\u30A6\u30B6\u30FC\u306F{feature}\u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093\u3002",
19923
+ core_configEnvVarMissing: "\u74B0\u5883\u5909\u6570\u300C{varName}\u300D\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u304A\u3089\u305A\u3001\u65E2\u5B9A\u5024\u3082\u3042\u308A\u307E\u305B\u3093",
19924
+ core_configFileNotExist: "\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u304C\u5B58\u5728\u3057\u307E\u305B\u3093: {filePath}",
19925
+ core_configParseFailed: "\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u306E\u89E3\u6790\u306B\u5931\u6557\u3057\u307E\u3057\u305F: {filePath}",
19926
+ core_configValidationFailed: "\u8A2D\u5B9A\u306E\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
19927
+ core_configNotLoaded: "\u8A2D\u5B9A\u300C{name}\u300D\u304C\u8AAD\u307F\u8FBC\u307E\u308C\u3066\u3044\u307E\u305B\u3093",
19928
+ core_configUnsupportedInBrowser: "\u30D6\u30E9\u30A6\u30B6\u30FC\u306F\u30D5\u30A1\u30A4\u30EB\u30D9\u30FC\u30B9\u306E\u8A2D\u5B9A\u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093\u3002\u30B5\u30FC\u30D0\u30FC\u5074\u3067core.config\u3092\u4F7F\u7528\u3059\u308B\u304B\u3001core.init({ logging })\u3067\u30D6\u30E9\u30A6\u30B6\u30FC\u7528\u306E\u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044",
19929
+ core_cryptoRandomUnavailable: "\u6697\u53F7\u5B66\u7684\u4E71\u6570\u306E\u751F\u6210\u5143\u3092\u5229\u7528\u3067\u304D\u307E\u305B\u3093"
20008
19930
  };
20009
19931
 
20010
19932
  // messages/zh-CN.json
@@ -20059,28 +19981,44 @@ var zh_CN_default2 = {
20059
19981
  core_configParseFailed: "\u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: {filePath}",
20060
19982
  core_configValidationFailed: "\u914D\u7F6E\u9A8C\u8BC1\u5931\u8D25",
20061
19983
  core_configNotLoaded: "\u914D\u7F6E '{name}' \u672A\u52A0\u8F7D",
20062
- core_configUnsupportedInBrowser: "\u6D4F\u89C8\u5668\u73AF\u5883\u4E0D\u652F\u6301\u6587\u4EF6\u914D\u7F6E\uFF0C\u8BF7\u5728\u670D\u52A1\u7AEF\u4F7F\u7528 core.config \u6216\u901A\u8FC7 core.init({ logging }) \u4F20\u5165\u6D4F\u89C8\u5668\u7AEF\u9009\u9879"
19984
+ core_configUnsupportedInBrowser: "\u6D4F\u89C8\u5668\u73AF\u5883\u4E0D\u652F\u6301\u6587\u4EF6\u914D\u7F6E\uFF0C\u8BF7\u5728\u670D\u52A1\u7AEF\u4F7F\u7528 core.config \u6216\u901A\u8FC7 core.init({ logging }) \u4F20\u5165\u6D4F\u89C8\u5668\u7AEF\u9009\u9879",
19985
+ core_cryptoRandomUnavailable: "\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u7F3A\u5C11\u5BC6\u7801\u5B66\u5B89\u5168\u7684\u968F\u673A\u6E90"
20063
19986
  };
20064
19987
 
20065
19988
  // src/i18n/core-i18n-utils.ts
20066
19989
  var DEFAULT_LOCALES = [
20067
19990
  { code: "zh-CN", label: "\u7B80\u4F53\u4E2D\u6587" },
20068
- { code: "en-US", label: "English" }
19991
+ { code: "en-US", label: "English" },
19992
+ { code: "ja-JP", label: "\u65E5\u672C\u8A9E" }
20069
19993
  ];
20070
19994
  var DEFAULT_LOCALE = "zh-CN";
20071
19995
  var currentLocale = DEFAULT_LOCALE;
19996
+ var requestLocales;
19997
+ function installRequestLocales(storage) {
19998
+ requestLocales = storage;
19999
+ }
20000
+ function normalizeLocale(locale) {
20001
+ return locale === "en" ? "en-US" : locale === "zh" ? "zh-CN" : locale === "ja" ? "ja-JP" : locale;
20002
+ }
20072
20003
  function getGlobalLocale() {
20073
- return currentLocale;
20004
+ return requestLocales?.getStore()?.locale ?? currentLocale;
20074
20005
  }
20075
20006
  function setGlobalLocale(locale) {
20076
- const normalized = locale === "en" ? "en-US" : locale === "zh" ? "zh-CN" : locale;
20077
- if (currentLocale !== normalized) {
20007
+ const normalized = normalizeLocale(locale);
20008
+ const request = requestLocales?.getStore();
20009
+ if (request)
20010
+ request.locale = normalized;
20011
+ else
20078
20012
  currentLocale = normalized;
20079
- }
20013
+ }
20014
+ function runWithLocale(locale, operation) {
20015
+ if (!requestLocales)
20016
+ throw new Error("Request locale context requires the Node.js entry");
20017
+ return requestLocales.run({ locale: normalizeLocale(locale) }, operation);
20080
20018
  }
20081
20019
  function createMessageGetter(messages) {
20082
20020
  return (key, options) => {
20083
- const requestLocale = options?.locale ?? currentLocale;
20021
+ const requestLocale = normalizeLocale(options?.locale ?? getGlobalLocale());
20084
20022
  const isSupported = DEFAULT_LOCALES.some((l) => l.code === requestLocale);
20085
20023
  const locale = isSupported ? requestLocale : DEFAULT_LOCALE;
20086
20024
  const dict = messages[locale] ?? messages[DEFAULT_LOCALE];
@@ -20099,16 +20037,141 @@ function createMessageGetter(messages) {
20099
20037
  }
20100
20038
  var coreM = createMessageGetter({
20101
20039
  "zh-CN": zh_CN_default2,
20102
- "en-US": en_US_default
20040
+ "en-US": en_US_default,
20041
+ "ja-JP": ja_JP_default
20103
20042
  });
20104
20043
  var i18n = {
20105
20044
  DEFAULT_LOCALES,
20106
20045
  DEFAULT_LOCALE,
20107
20046
  setGlobalLocale,
20108
20047
  getGlobalLocale,
20048
+ runWithLocale,
20109
20049
  createMessageGetter,
20110
20050
  coreM
20111
20051
  };
20052
+ var DEFAULT_LENGTH = 21;
20053
+ var SHORT_LENGTH = 10;
20054
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
20055
+ var NANOID_REGEX_CACHE = /* @__PURE__ */ new Map();
20056
+ function generateUUID() {
20057
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
20058
+ return crypto.randomUUID();
20059
+ }
20060
+ const bytes = new Uint8Array(16);
20061
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
20062
+ crypto.getRandomValues(bytes);
20063
+ } else {
20064
+ throw new Error(i18n.coreM("core_cryptoRandomUnavailable"));
20065
+ }
20066
+ bytes[6] = bytes[6] & 15 | 64;
20067
+ bytes[8] = bytes[8] & 63 | 128;
20068
+ const hex3 = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
20069
+ return `${hex3.slice(0, 8)}-${hex3.slice(8, 12)}-${hex3.slice(12, 16)}-${hex3.slice(16, 20)}-${hex3.slice(20)}`;
20070
+ }
20071
+ var id = {
20072
+ /**
20073
+ * 生成标准 nanoid(默认 21 字符)。
20074
+ *
20075
+ * @param length - ID 长度
20076
+ * @returns nanoid 字符串
20077
+ *
20078
+ * @example
20079
+ * ```ts
20080
+ * const id = core.id.generate(16)
20081
+ * ```
20082
+ */
20083
+ generate(length = DEFAULT_LENGTH) {
20084
+ return nanoid$1(length);
20085
+ },
20086
+ /**
20087
+ * 生成短 ID(10 字符)。
20088
+ *
20089
+ * @example
20090
+ * ```ts
20091
+ * const shortId = core.id.short()
20092
+ * ```
20093
+ */
20094
+ short() {
20095
+ return nanoid$1(SHORT_LENGTH);
20096
+ },
20097
+ /**
20098
+ * 生成带前缀的 ID。
20099
+ *
20100
+ * @param prefix - 前缀
20101
+ * @param length - ID 长度
20102
+ *
20103
+ * @example
20104
+ * ```ts
20105
+ * const userId = core.id.withPrefix('user_')
20106
+ * ```
20107
+ */
20108
+ withPrefix(prefix, length = DEFAULT_LENGTH) {
20109
+ return `${prefix}${nanoid$1(length)}`;
20110
+ },
20111
+ /**
20112
+ * 生成 Trace ID。
20113
+ *
20114
+ * @example
20115
+ * ```ts
20116
+ * const traceId = core.id.trace()
20117
+ * ```
20118
+ */
20119
+ trace() {
20120
+ return `trace-${nanoid$1()}`;
20121
+ },
20122
+ /**
20123
+ * 生成 Request ID。
20124
+ *
20125
+ * @example
20126
+ * ```ts
20127
+ * const requestId = core.id.request()
20128
+ * ```
20129
+ */
20130
+ request() {
20131
+ return `req-${nanoid$1()}`;
20132
+ },
20133
+ /**
20134
+ * 生成 UUID v4。
20135
+ *
20136
+ * @example
20137
+ * ```ts
20138
+ * const uuid = core.id.uuid()
20139
+ * ```
20140
+ */
20141
+ uuid() {
20142
+ return generateUUID();
20143
+ },
20144
+ /**
20145
+ * 验证是否为有效的 UUID v4。
20146
+ *
20147
+ * @example
20148
+ * ```ts
20149
+ * core.id.isValidUUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')
20150
+ * ```
20151
+ */
20152
+ isValidUUID(uuid3) {
20153
+ return UUID_REGEX.test(uuid3);
20154
+ },
20155
+ /**
20156
+ * 验证是否为有效的 nanoid。
20157
+ *
20158
+ * @param str - 待验证字符串
20159
+ * @param length - 期望长度
20160
+ *
20161
+ * @example
20162
+ * ```ts
20163
+ * core.id.isValidNanoId('abc', 3)
20164
+ * ```
20165
+ */
20166
+ isValidNanoId(str, length = DEFAULT_LENGTH) {
20167
+ let regex = NANOID_REGEX_CACHE.get(length);
20168
+ if (!regex) {
20169
+ regex = new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
20170
+ NANOID_REGEX_CACHE.set(length, regex);
20171
+ }
20172
+ return regex.test(str);
20173
+ }
20174
+ };
20112
20175
 
20113
20176
  // src/i18n/core-zod-mapper.ts
20114
20177
  function createPrefixedZodMessageGetter(prefix, getMessage) {
@@ -20118,6 +20181,8 @@ var ZOD_DEFAULT_MESSAGE_PATTERNS = [
20118
20181
  /^Too small:/,
20119
20182
  /^Too big:/,
20120
20183
  /^Invalid input:/,
20184
+ /^Invalid input$/,
20185
+ // Zod 4 custom/refine 未提供业务消息时的默认文案。
20121
20186
  /^Invalid option:/,
20122
20187
  /^Invalid string:/,
20123
20188
  /^Invalid email$/,
@@ -20376,6 +20441,9 @@ function createNotInitializedKit(codeOrDef, messageFn) {
20376
20441
  const proxy = (mode = "async") => new Proxy({}, { get: () => mode === "sync" ? syncOp : asyncOp });
20377
20442
  return { error: error63, result, proxy };
20378
20443
  }
20444
+ function requiresSharedState(environment) {
20445
+ return (environment.NODE_ENV === "production" || environment.HAI_CORE_ENV === "production") && environment.HAI_E2E !== "1" && environment.HAI_E2E_MOCK !== "1";
20446
+ }
20379
20447
 
20380
20448
  // src/utils/core-util-type.ts
20381
20449
  function isDefined(value) {
@@ -20488,6 +20556,7 @@ var DEFAULT_SENSITIVE_KEY_REGEX = /(?:^|_)(?:pass|passcode|password|secret|autho
20488
20556
  var DEFAULT_SENSITIVE_REPLACEMENT = "[REDACTED]";
20489
20557
  var URL_LIKE_KEY_REGEX = /(?:^|_)(?:url|uri|endpoint)(?:_|$)/;
20490
20558
  var SENSITIVE_KEY_CACHE_LIMIT = 512;
20559
+ var ERROR_DIAGNOSTIC_MAX_DEPTH = 32;
20491
20560
  var normalizedKeyCache = /* @__PURE__ */ new Map();
20492
20561
  var urlLikeKeyCache = /* @__PURE__ */ new Map();
20493
20562
  var defaultSensitiveKeyCache = /* @__PURE__ */ new Map();
@@ -20541,24 +20610,31 @@ function isSensitiveKey(key, matcher = DEFAULT_SENSITIVE_KEY_REGEX) {
20541
20610
  function isUrlLikeNormalizedKey(normalizedKey) {
20542
20611
  return getCachedValue(urlLikeKeyCache, normalizedKey, () => URL_LIKE_KEY_REGEX.test(normalizedKey));
20543
20612
  }
20544
- function sanitizeUrlCredentials(url2, replacement = DEFAULT_SENSITIVE_REPLACEMENT) {
20613
+ function sanitizeUrl(url2, options = {}) {
20614
+ return sanitizeUrlWithContext(url2, createSanitizeSensitiveContext(options));
20615
+ }
20616
+ function sanitizeUrlParameters(parameters, context) {
20617
+ const sanitized = new URLSearchParams();
20618
+ for (const [key, value] of parameters) {
20619
+ sanitized.append(key, context.isSensitiveKey(key, normalizeKeyForMatching(key)) ? context.urlReplacement : value);
20620
+ }
20621
+ return sanitized;
20622
+ }
20623
+ function sanitizeUrlWithContext(url2, context) {
20545
20624
  try {
20546
20625
  const parsed = new URL(url2);
20547
- let changed = false;
20548
20626
  if (parsed.username) {
20549
- parsed.username = replacement;
20550
- changed = true;
20627
+ parsed.username = context.urlReplacement;
20551
20628
  }
20552
20629
  if (parsed.password) {
20553
- parsed.password = replacement;
20554
- changed = true;
20555
- }
20556
- if (!changed) {
20557
- return parsed.toString();
20630
+ parsed.password = context.urlReplacement;
20558
20631
  }
20559
- return parsed.toString().replaceAll(encodeURIComponent(replacement), replacement);
20632
+ parsed.search = sanitizeUrlParameters(parsed.searchParams, context).toString();
20633
+ if (parsed.hash.includes("="))
20634
+ parsed.hash = sanitizeUrlParameters(new URLSearchParams(parsed.hash.slice(1)), context).toString();
20635
+ return parsed.toString().replaceAll(encodeURIComponent(context.urlReplacement), context.urlReplacement);
20560
20636
  } catch {
20561
- return url2;
20637
+ return "(invalid url)";
20562
20638
  }
20563
20639
  }
20564
20640
  function isProtectedPropertyKey(key) {
@@ -20572,15 +20648,53 @@ function createSanitizeSensitiveContext(options = {}) {
20572
20648
  isSensitiveKey: compileSensitiveKeyMatcher(options.matcher ?? DEFAULT_SENSITIVE_KEY_REGEX)
20573
20649
  };
20574
20650
  }
20575
- function sanitizeSensitiveValueWithContext(value, key, context, cache) {
20651
+ function sanitizeSensitiveValueWithContext(value, key, context, cache, errorPath, errorDepth = 0) {
20576
20652
  const isPlainObjectValue = isPlainRecord(value);
20653
+ const isErrorDiagnostic = errorPath !== void 0 || value instanceof Error;
20577
20654
  if (key !== null) {
20578
20655
  const normalizedKey = normalizeKeyForMatching(key);
20579
20656
  if (typeof value === "string" && isUrlLikeNormalizedKey(normalizedKey)) {
20580
- return sanitizeUrlCredentials(value, context.urlReplacement);
20657
+ return sanitizeUrlWithContext(value, context);
20581
20658
  }
20582
20659
  if (context.isSensitiveKey(key, normalizedKey) && !isPlainObjectValue) {
20583
- return context.replacement;
20660
+ return isErrorDiagnostic ? sanitizeSensitiveValueWithContext(context.replacement, null, context, cache, errorPath ?? /* @__PURE__ */ new WeakSet(), errorDepth) : context.replacement;
20661
+ }
20662
+ }
20663
+ if (isErrorDiagnostic) {
20664
+ if (typeof value === "bigint")
20665
+ return value.toString();
20666
+ if (typeof value === "function" || typeof value === "symbol")
20667
+ return void 0;
20668
+ if (value === null || typeof value !== "object")
20669
+ return value;
20670
+ const activePath = errorPath ?? /* @__PURE__ */ new WeakSet();
20671
+ if (activePath.has(value))
20672
+ return "[Circular]";
20673
+ if (errorDepth >= ERROR_DIAGNOSTIC_MAX_DEPTH)
20674
+ return "[MaxDepth]";
20675
+ activePath.add(value);
20676
+ try {
20677
+ if (Array.isArray(value)) {
20678
+ return value.map((item) => sanitizeSensitiveValueWithContext(item, null, context, cache, activePath, errorDepth + 1));
20679
+ }
20680
+ const fields = { ...value };
20681
+ if (value instanceof Error) {
20682
+ fields.name = value.name;
20683
+ fields.message = value.message;
20684
+ fields.stack = value.stack;
20685
+ if (Object.hasOwn(value, "cause"))
20686
+ fields.cause = value.cause;
20687
+ if (value instanceof AggregateError)
20688
+ fields.errors = value.errors;
20689
+ }
20690
+ const sanitized = {};
20691
+ for (const [childKey, childValue] of Object.entries(fields)) {
20692
+ if (!isProtectedPropertyKey(childKey))
20693
+ sanitized[childKey] = sanitizeSensitiveValueWithContext(childValue, childKey, context, cache, activePath, errorDepth + 1);
20694
+ }
20695
+ return sanitized;
20696
+ } finally {
20697
+ activePath.delete(value);
20584
20698
  }
20585
20699
  }
20586
20700
  if (Array.isArray(value)) {
@@ -20620,6 +20734,7 @@ var sanitize = {
20620
20734
  defaultSensitiveKeyRegex: DEFAULT_SENSITIVE_KEY_REGEX,
20621
20735
  defaultSensitiveReplacement: DEFAULT_SENSITIVE_REPLACEMENT,
20622
20736
  isSensitiveKey,
20737
+ sanitizeUrl,
20623
20738
  sanitizeSensitiveValue,
20624
20739
  sanitizeSensitiveFields
20625
20740
  };
@@ -20802,10 +20917,12 @@ function createCore(loggerFns) {
20802
20917
  *
20803
20918
  * @example
20804
20919
  * ```ts
20805
- * // 设置全局 locale(所有模块读取全局 locale)
20920
+ * // 配置浏览器语言或服务端启动默认值
20806
20921
  * core.i18n.setGlobalLocale('en-US')
20807
20922
  *
20808
- * // 获取当前全局 locale
20923
+ * // Node 请求应包裹实际异步处理过程
20924
+ * await core.i18n.runWithLocale('zh-CN', () => handleRequest())
20925
+ * // 获取当前请求语言或应用默认语言
20809
20926
  * core.i18n.getGlobalLocale()
20810
20927
  *
20811
20928
  * // 创建消息获取器(读取全局 locale)
@@ -20940,11 +21057,12 @@ function createCore(loggerFns) {
20940
21057
  * ```
20941
21058
  */
20942
21059
  module: {
20943
- createNotInitializedKit
21060
+ createNotInitializedKit,
21061
+ requiresSharedState
20944
21062
  }
20945
21063
  };
20946
21064
  }
20947
21065
 
20948
- export { CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, IdConfigSchema, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, __commonJS, __toESM, createCore, err, i18n, ok, sanitize, typeUtils };
20949
- //# sourceMappingURL=chunk-RXNSRXYF.js.map
20950
- //# sourceMappingURL=chunk-RXNSRXYF.js.map
21066
+ export { CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, __commonJS, __toESM, createCore, err, i18n, installRequestLocales, ok, sanitize, typeUtils };
21067
+ //# sourceMappingURL=chunk-AWUFXC35.js.map
21068
+ //# sourceMappingURL=chunk-AWUFXC35.js.map