@h-ai/core 0.1.0-alpha.68 → 0.1.0-alpha.69
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/README.en.md +27 -2
- package/README.ja.md +27 -2
- package/README.md +27 -2
- package/dist/browser.d.ts +7 -3
- package/dist/browser.js +21 -9
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-AWUFXC35.js → chunk-MUQFCAQ5.js} +316 -236
- package/dist/chunk-MUQFCAQ5.js.map +1 -0
- package/dist/{core-function-config.node-DJ6Hb1ee.d.ts → core-function-config.node-CGXWsohk.d.ts} +71 -2
- package/dist/node.d.ts +3 -3
- package/dist/node.js +19 -11
- package/dist/node.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-AWUFXC35.js.map +0 -1
|
@@ -19817,6 +19817,37 @@ var ConfigErrorInfo = {
|
|
|
19817
19817
|
};
|
|
19818
19818
|
var HaiConfigError = error62.buildHaiErrorsDef("core", ConfigErrorInfo);
|
|
19819
19819
|
|
|
19820
|
+
// src/functions/core-function-context.ts
|
|
19821
|
+
var storage;
|
|
19822
|
+
var synchronousContext = Object.freeze({});
|
|
19823
|
+
function installRequestContext(value) {
|
|
19824
|
+
storage = value;
|
|
19825
|
+
}
|
|
19826
|
+
var requestContext = {
|
|
19827
|
+
get() {
|
|
19828
|
+
return storage?.getStore() ?? synchronousContext;
|
|
19829
|
+
},
|
|
19830
|
+
run(value, operation) {
|
|
19831
|
+
const previousValue = requestContext.get();
|
|
19832
|
+
const merged = Object.freeze({
|
|
19833
|
+
requestId: Object.hasOwn(value, "requestId") ? value.requestId : previousValue.requestId,
|
|
19834
|
+
scopeId: Object.hasOwn(value, "scopeId") ? value.scopeId : previousValue.scopeId,
|
|
19835
|
+
userId: Object.hasOwn(value, "userId") ? value.userId : previousValue.userId,
|
|
19836
|
+
jobId: Object.hasOwn(value, "jobId") ? value.jobId : previousValue.jobId,
|
|
19837
|
+
suppressLogObservers: Object.hasOwn(value, "suppressLogObservers") ? value.suppressLogObservers : previousValue.suppressLogObservers
|
|
19838
|
+
});
|
|
19839
|
+
if (storage)
|
|
19840
|
+
return storage.run(merged, operation);
|
|
19841
|
+
const previous = synchronousContext;
|
|
19842
|
+
synchronousContext = merged;
|
|
19843
|
+
try {
|
|
19844
|
+
return operation();
|
|
19845
|
+
} finally {
|
|
19846
|
+
synchronousContext = previous;
|
|
19847
|
+
}
|
|
19848
|
+
}
|
|
19849
|
+
};
|
|
19850
|
+
|
|
19820
19851
|
// messages/en-US.json
|
|
19821
19852
|
var en_US_default = {
|
|
19822
19853
|
$schema: "https://inlang.com/schema/inlang-message-format",
|
|
@@ -19994,8 +20025,8 @@ var DEFAULT_LOCALES = [
|
|
|
19994
20025
|
var DEFAULT_LOCALE = "zh-CN";
|
|
19995
20026
|
var currentLocale = DEFAULT_LOCALE;
|
|
19996
20027
|
var requestLocales;
|
|
19997
|
-
function installRequestLocales(
|
|
19998
|
-
requestLocales =
|
|
20028
|
+
function installRequestLocales(storage2) {
|
|
20029
|
+
requestLocales = storage2;
|
|
19999
20030
|
}
|
|
20000
20031
|
function normalizeLocale(locale) {
|
|
20001
20032
|
return locale === "en" ? "en-US" : locale === "zh" ? "zh-CN" : locale === "ja" ? "ja-JP" : locale;
|
|
@@ -20173,6 +20204,283 @@ var id = {
|
|
|
20173
20204
|
}
|
|
20174
20205
|
};
|
|
20175
20206
|
|
|
20207
|
+
// src/utils/core-util-type.ts
|
|
20208
|
+
function isDefined(value) {
|
|
20209
|
+
return value !== void 0 && value !== null;
|
|
20210
|
+
}
|
|
20211
|
+
function isObject2(value) {
|
|
20212
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20213
|
+
}
|
|
20214
|
+
function isFunction(value) {
|
|
20215
|
+
return typeof value === "function";
|
|
20216
|
+
}
|
|
20217
|
+
function isPromise(value) {
|
|
20218
|
+
if (value instanceof Promise) {
|
|
20219
|
+
return true;
|
|
20220
|
+
}
|
|
20221
|
+
if (!isObject2(value)) {
|
|
20222
|
+
return false;
|
|
20223
|
+
}
|
|
20224
|
+
return isFunction(value.then);
|
|
20225
|
+
}
|
|
20226
|
+
function isString(value) {
|
|
20227
|
+
return typeof value === "string";
|
|
20228
|
+
}
|
|
20229
|
+
function isNumber(value) {
|
|
20230
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
20231
|
+
}
|
|
20232
|
+
function isBoolean(value) {
|
|
20233
|
+
return typeof value === "boolean";
|
|
20234
|
+
}
|
|
20235
|
+
function isArray(value) {
|
|
20236
|
+
return Array.isArray(value);
|
|
20237
|
+
}
|
|
20238
|
+
var typeUtils = {
|
|
20239
|
+
isDefined,
|
|
20240
|
+
isObject: isObject2,
|
|
20241
|
+
isFunction,
|
|
20242
|
+
isPromise,
|
|
20243
|
+
isString,
|
|
20244
|
+
isNumber,
|
|
20245
|
+
isBoolean,
|
|
20246
|
+
isArray
|
|
20247
|
+
};
|
|
20248
|
+
|
|
20249
|
+
// src/utils/core-util-sanitize.ts
|
|
20250
|
+
var DEFAULT_SENSITIVE_KEY_REGEX = /(?:^|_)(?:pass|passcode|password|secret|authorization|cookie|otp|session|token)$|(?:^|_)otp_code$|(?:^|_)private_key$|(?:^|_)access_key(?:_id|_secret)?$|(?:^|_)secret_access_key$|(?:^|_)api(?:_[a-z0-9]+)*_key$|^apikey$/i;
|
|
20251
|
+
var DEFAULT_SENSITIVE_REPLACEMENT = "[REDACTED]";
|
|
20252
|
+
var URL_LIKE_KEY_REGEX = /(?:^|_)(?:url|uri|endpoint)(?:_|$)/;
|
|
20253
|
+
var SENSITIVE_KEY_CACHE_LIMIT = 512;
|
|
20254
|
+
var ERROR_DIAGNOSTIC_MAX_DEPTH = 32;
|
|
20255
|
+
var normalizedKeyCache = /* @__PURE__ */ new Map();
|
|
20256
|
+
var urlLikeKeyCache = /* @__PURE__ */ new Map();
|
|
20257
|
+
var defaultSensitiveKeyCache = /* @__PURE__ */ new Map();
|
|
20258
|
+
function getCachedValue(cache, key, createValue) {
|
|
20259
|
+
const cachedValue = cache.get(key);
|
|
20260
|
+
if (cachedValue !== void 0) {
|
|
20261
|
+
return cachedValue;
|
|
20262
|
+
}
|
|
20263
|
+
const value = createValue();
|
|
20264
|
+
if (cache.size >= SENSITIVE_KEY_CACHE_LIMIT) {
|
|
20265
|
+
cache.clear();
|
|
20266
|
+
}
|
|
20267
|
+
cache.set(key, value);
|
|
20268
|
+
return value;
|
|
20269
|
+
}
|
|
20270
|
+
function normalizeKeyForMatching(key) {
|
|
20271
|
+
return getCachedValue(normalizedKeyCache, key, () => {
|
|
20272
|
+
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").replace(/_+/g, "_").toLowerCase();
|
|
20273
|
+
});
|
|
20274
|
+
}
|
|
20275
|
+
function matchesDefaultSensitiveKey(normalizedKey) {
|
|
20276
|
+
return getCachedValue(defaultSensitiveKeyCache, normalizedKey, () => {
|
|
20277
|
+
return DEFAULT_SENSITIVE_KEY_REGEX.test(normalizedKey);
|
|
20278
|
+
});
|
|
20279
|
+
}
|
|
20280
|
+
function isPlainRecord(value) {
|
|
20281
|
+
if (!typeUtils.isObject(value)) {
|
|
20282
|
+
return false;
|
|
20283
|
+
}
|
|
20284
|
+
const prototype = Object.getPrototypeOf(value);
|
|
20285
|
+
return prototype === Object.prototype || prototype === null;
|
|
20286
|
+
}
|
|
20287
|
+
function compileSensitiveKeyMatcher(matcher) {
|
|
20288
|
+
if (matcher instanceof RegExp) {
|
|
20289
|
+
if (matcher === DEFAULT_SENSITIVE_KEY_REGEX) {
|
|
20290
|
+
return (_key, normalizedKey) => matchesDefaultSensitiveKey(normalizedKey);
|
|
20291
|
+
}
|
|
20292
|
+
const safeMatcher = matcher.global || matcher.sticky ? new RegExp(matcher.source, matcher.flags.replace(/[gy]/g, "")) : matcher;
|
|
20293
|
+
return (_key, normalizedKey) => safeMatcher.test(normalizedKey);
|
|
20294
|
+
}
|
|
20295
|
+
if (Array.isArray(matcher)) {
|
|
20296
|
+
const normalizedKeys = new Set(matcher.map(normalizeKeyForMatching));
|
|
20297
|
+
return (_key, normalizedKey) => normalizedKeys.has(normalizedKey);
|
|
20298
|
+
}
|
|
20299
|
+
return (key) => matcher(key);
|
|
20300
|
+
}
|
|
20301
|
+
function isSensitiveKey(key, matcher = DEFAULT_SENSITIVE_KEY_REGEX) {
|
|
20302
|
+
const normalizedKey = normalizeKeyForMatching(key);
|
|
20303
|
+
return compileSensitiveKeyMatcher(matcher)(key, normalizedKey);
|
|
20304
|
+
}
|
|
20305
|
+
function isUrlLikeNormalizedKey(normalizedKey) {
|
|
20306
|
+
return getCachedValue(urlLikeKeyCache, normalizedKey, () => URL_LIKE_KEY_REGEX.test(normalizedKey));
|
|
20307
|
+
}
|
|
20308
|
+
function sanitizeUrl(url2, options = {}) {
|
|
20309
|
+
return sanitizeUrlWithContext(url2, createSanitizeSensitiveContext(options));
|
|
20310
|
+
}
|
|
20311
|
+
function sanitizeUrlParameters(parameters, context) {
|
|
20312
|
+
const sanitized = new URLSearchParams();
|
|
20313
|
+
for (const [key, value] of parameters) {
|
|
20314
|
+
sanitized.append(key, context.isSensitiveKey(key, normalizeKeyForMatching(key)) ? context.urlReplacement : value);
|
|
20315
|
+
}
|
|
20316
|
+
return sanitized;
|
|
20317
|
+
}
|
|
20318
|
+
function sanitizeUrlWithContext(url2, context) {
|
|
20319
|
+
try {
|
|
20320
|
+
const parsed = new URL(url2);
|
|
20321
|
+
if (parsed.username) {
|
|
20322
|
+
parsed.username = context.urlReplacement;
|
|
20323
|
+
}
|
|
20324
|
+
if (parsed.password) {
|
|
20325
|
+
parsed.password = context.urlReplacement;
|
|
20326
|
+
}
|
|
20327
|
+
parsed.search = sanitizeUrlParameters(parsed.searchParams, context).toString();
|
|
20328
|
+
if (parsed.hash.includes("="))
|
|
20329
|
+
parsed.hash = sanitizeUrlParameters(new URLSearchParams(parsed.hash.slice(1)), context).toString();
|
|
20330
|
+
return parsed.toString().replaceAll(encodeURIComponent(context.urlReplacement), context.urlReplacement);
|
|
20331
|
+
} catch {
|
|
20332
|
+
return "(invalid url)";
|
|
20333
|
+
}
|
|
20334
|
+
}
|
|
20335
|
+
function isProtectedPropertyKey(key) {
|
|
20336
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
20337
|
+
}
|
|
20338
|
+
function createSanitizeSensitiveContext(options = {}) {
|
|
20339
|
+
const replacement = options.replacement ?? DEFAULT_SENSITIVE_REPLACEMENT;
|
|
20340
|
+
return {
|
|
20341
|
+
replacement,
|
|
20342
|
+
urlReplacement: typeof replacement === "string" ? replacement : DEFAULT_SENSITIVE_REPLACEMENT,
|
|
20343
|
+
isSensitiveKey: compileSensitiveKeyMatcher(options.matcher ?? DEFAULT_SENSITIVE_KEY_REGEX)
|
|
20344
|
+
};
|
|
20345
|
+
}
|
|
20346
|
+
function sanitizeSensitiveValueWithContext(value, key, context, cache, errorPath, errorDepth = 0) {
|
|
20347
|
+
const isPlainObjectValue = isPlainRecord(value);
|
|
20348
|
+
const isErrorDiagnostic = errorPath !== void 0 || value instanceof Error;
|
|
20349
|
+
if (key !== null) {
|
|
20350
|
+
const normalizedKey = normalizeKeyForMatching(key);
|
|
20351
|
+
if (typeof value === "string" && isUrlLikeNormalizedKey(normalizedKey)) {
|
|
20352
|
+
return sanitizeUrlWithContext(value, context);
|
|
20353
|
+
}
|
|
20354
|
+
if (context.isSensitiveKey(key, normalizedKey) && !isPlainObjectValue) {
|
|
20355
|
+
return isErrorDiagnostic ? sanitizeSensitiveValueWithContext(context.replacement, null, context, cache, errorPath ?? /* @__PURE__ */ new WeakSet(), errorDepth) : context.replacement;
|
|
20356
|
+
}
|
|
20357
|
+
}
|
|
20358
|
+
if (isErrorDiagnostic) {
|
|
20359
|
+
if (typeof value === "bigint")
|
|
20360
|
+
return value.toString();
|
|
20361
|
+
if (typeof value === "function" || typeof value === "symbol")
|
|
20362
|
+
return void 0;
|
|
20363
|
+
if (value === null || typeof value !== "object")
|
|
20364
|
+
return value;
|
|
20365
|
+
const activePath = errorPath ?? /* @__PURE__ */ new WeakSet();
|
|
20366
|
+
if (activePath.has(value))
|
|
20367
|
+
return "[Circular]";
|
|
20368
|
+
if (errorDepth >= ERROR_DIAGNOSTIC_MAX_DEPTH)
|
|
20369
|
+
return "[MaxDepth]";
|
|
20370
|
+
activePath.add(value);
|
|
20371
|
+
try {
|
|
20372
|
+
if (Array.isArray(value)) {
|
|
20373
|
+
return value.map((item) => sanitizeSensitiveValueWithContext(item, null, context, cache, activePath, errorDepth + 1));
|
|
20374
|
+
}
|
|
20375
|
+
const fields = { ...value };
|
|
20376
|
+
if (value instanceof Error) {
|
|
20377
|
+
fields.name = value.name;
|
|
20378
|
+
fields.message = value.message;
|
|
20379
|
+
fields.stack = value.stack;
|
|
20380
|
+
if (Object.hasOwn(value, "cause"))
|
|
20381
|
+
fields.cause = value.cause;
|
|
20382
|
+
if (value instanceof AggregateError)
|
|
20383
|
+
fields.errors = value.errors;
|
|
20384
|
+
}
|
|
20385
|
+
const sanitized = {};
|
|
20386
|
+
for (const [childKey, childValue] of Object.entries(fields)) {
|
|
20387
|
+
if (!isProtectedPropertyKey(childKey))
|
|
20388
|
+
sanitized[childKey] = sanitizeSensitiveValueWithContext(childValue, childKey, context, cache, activePath, errorDepth + 1);
|
|
20389
|
+
}
|
|
20390
|
+
return sanitized;
|
|
20391
|
+
} finally {
|
|
20392
|
+
activePath.delete(value);
|
|
20393
|
+
}
|
|
20394
|
+
}
|
|
20395
|
+
if (Array.isArray(value)) {
|
|
20396
|
+
if (cache.has(value)) {
|
|
20397
|
+
return cache.get(value);
|
|
20398
|
+
}
|
|
20399
|
+
const sanitizedArray = [];
|
|
20400
|
+
cache.set(value, sanitizedArray);
|
|
20401
|
+
for (let index = 0; index < value.length; index++) {
|
|
20402
|
+
sanitizedArray[index] = sanitizeSensitiveValueWithContext(value[index], null, context, cache);
|
|
20403
|
+
}
|
|
20404
|
+
return sanitizedArray;
|
|
20405
|
+
}
|
|
20406
|
+
if (isPlainObjectValue) {
|
|
20407
|
+
if (cache.has(value)) {
|
|
20408
|
+
return cache.get(value);
|
|
20409
|
+
}
|
|
20410
|
+
const sanitized = {};
|
|
20411
|
+
cache.set(value, sanitized);
|
|
20412
|
+
for (const childKey in value) {
|
|
20413
|
+
if (!Object.hasOwn(value, childKey) || isProtectedPropertyKey(childKey)) {
|
|
20414
|
+
continue;
|
|
20415
|
+
}
|
|
20416
|
+
sanitized[childKey] = sanitizeSensitiveValueWithContext(value[childKey], childKey, context, cache);
|
|
20417
|
+
}
|
|
20418
|
+
return sanitized;
|
|
20419
|
+
}
|
|
20420
|
+
return value;
|
|
20421
|
+
}
|
|
20422
|
+
function sanitizeSensitiveValue(value, key, options = {}, cache = /* @__PURE__ */ new WeakMap()) {
|
|
20423
|
+
return sanitizeSensitiveValueWithContext(value, key, createSanitizeSensitiveContext(options), cache);
|
|
20424
|
+
}
|
|
20425
|
+
function sanitizeSensitiveFields(value, options = {}) {
|
|
20426
|
+
return sanitizeSensitiveValue(value, null, options);
|
|
20427
|
+
}
|
|
20428
|
+
var sanitize = {
|
|
20429
|
+
defaultSensitiveKeyRegex: DEFAULT_SENSITIVE_KEY_REGEX,
|
|
20430
|
+
defaultSensitiveReplacement: DEFAULT_SENSITIVE_REPLACEMENT,
|
|
20431
|
+
isSensitiveKey,
|
|
20432
|
+
sanitizeUrl,
|
|
20433
|
+
sanitizeSensitiveValue,
|
|
20434
|
+
sanitizeSensitiveFields
|
|
20435
|
+
};
|
|
20436
|
+
|
|
20437
|
+
// src/functions/core-function-log-observer.ts
|
|
20438
|
+
var observers = /* @__PURE__ */ new Set();
|
|
20439
|
+
var emitting = false;
|
|
20440
|
+
function observeLogs(observer) {
|
|
20441
|
+
observers.add(observer);
|
|
20442
|
+
return () => {
|
|
20443
|
+
observers.delete(observer);
|
|
20444
|
+
};
|
|
20445
|
+
}
|
|
20446
|
+
function emitLogRecord(record2) {
|
|
20447
|
+
if (emitting || observers.size === 0)
|
|
20448
|
+
return;
|
|
20449
|
+
emitting = true;
|
|
20450
|
+
try {
|
|
20451
|
+
for (const observer of observers) {
|
|
20452
|
+
try {
|
|
20453
|
+
const result = observer({ ...record2, context: sanitize.sanitizeSensitiveFields(record2.context) });
|
|
20454
|
+
if (result instanceof Promise)
|
|
20455
|
+
void result.catch(() => {
|
|
20456
|
+
});
|
|
20457
|
+
} catch {
|
|
20458
|
+
}
|
|
20459
|
+
}
|
|
20460
|
+
} finally {
|
|
20461
|
+
emitting = false;
|
|
20462
|
+
}
|
|
20463
|
+
}
|
|
20464
|
+
function sanitizeLogFields(value, paths) {
|
|
20465
|
+
const result = sanitize.sanitizeSensitiveFields(value);
|
|
20466
|
+
for (const path of paths)
|
|
20467
|
+
redactPath(result, path.match(/\*|[^.[\]"']+/g) ?? []);
|
|
20468
|
+
return result;
|
|
20469
|
+
}
|
|
20470
|
+
function redactPath(value, segments) {
|
|
20471
|
+
if (!value || typeof value !== "object" || segments.length === 0)
|
|
20472
|
+
return;
|
|
20473
|
+
const record2 = value;
|
|
20474
|
+
const [segment, ...rest] = segments;
|
|
20475
|
+
for (const key of segment === "*" ? Object.keys(record2) : [segment]) {
|
|
20476
|
+
if (!Object.hasOwn(record2, key) || ["__proto__", "constructor", "prototype"].includes(key))
|
|
20477
|
+
continue;
|
|
20478
|
+
if (rest.length === 0)
|
|
20479
|
+
record2[key] = "[REDACTED]";
|
|
20480
|
+
else redactPath(record2[key], rest);
|
|
20481
|
+
}
|
|
20482
|
+
}
|
|
20483
|
+
|
|
20176
20484
|
// src/i18n/core-zod-mapper.ts
|
|
20177
20485
|
function createPrefixedZodMessageGetter(prefix, getMessage) {
|
|
20178
20486
|
return (key, params) => getMessage(`${prefix}_${key}`, params);
|
|
@@ -20445,48 +20753,6 @@ function requiresSharedState(environment) {
|
|
|
20445
20753
|
return (environment.NODE_ENV === "production" || environment.HAI_CORE_ENV === "production") && environment.HAI_E2E !== "1" && environment.HAI_E2E_MOCK !== "1";
|
|
20446
20754
|
}
|
|
20447
20755
|
|
|
20448
|
-
// src/utils/core-util-type.ts
|
|
20449
|
-
function isDefined(value) {
|
|
20450
|
-
return value !== void 0 && value !== null;
|
|
20451
|
-
}
|
|
20452
|
-
function isObject2(value) {
|
|
20453
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20454
|
-
}
|
|
20455
|
-
function isFunction(value) {
|
|
20456
|
-
return typeof value === "function";
|
|
20457
|
-
}
|
|
20458
|
-
function isPromise(value) {
|
|
20459
|
-
if (value instanceof Promise) {
|
|
20460
|
-
return true;
|
|
20461
|
-
}
|
|
20462
|
-
if (!isObject2(value)) {
|
|
20463
|
-
return false;
|
|
20464
|
-
}
|
|
20465
|
-
return isFunction(value.then);
|
|
20466
|
-
}
|
|
20467
|
-
function isString(value) {
|
|
20468
|
-
return typeof value === "string";
|
|
20469
|
-
}
|
|
20470
|
-
function isNumber(value) {
|
|
20471
|
-
return typeof value === "number" && !Number.isNaN(value);
|
|
20472
|
-
}
|
|
20473
|
-
function isBoolean(value) {
|
|
20474
|
-
return typeof value === "boolean";
|
|
20475
|
-
}
|
|
20476
|
-
function isArray(value) {
|
|
20477
|
-
return Array.isArray(value);
|
|
20478
|
-
}
|
|
20479
|
-
var typeUtils = {
|
|
20480
|
-
isDefined,
|
|
20481
|
-
isObject: isObject2,
|
|
20482
|
-
isFunction,
|
|
20483
|
-
isPromise,
|
|
20484
|
-
isString,
|
|
20485
|
-
isNumber,
|
|
20486
|
-
isBoolean,
|
|
20487
|
-
isArray
|
|
20488
|
-
};
|
|
20489
|
-
|
|
20490
20756
|
// src/utils/core-util-object.ts
|
|
20491
20757
|
function deepClone(obj) {
|
|
20492
20758
|
return structuredClone(obj);
|
|
@@ -20551,194 +20817,6 @@ var object2 = {
|
|
|
20551
20817
|
fromEntries
|
|
20552
20818
|
};
|
|
20553
20819
|
|
|
20554
|
-
// src/utils/core-util-sanitize.ts
|
|
20555
|
-
var DEFAULT_SENSITIVE_KEY_REGEX = /(?:^|_)(?:pass|passcode|password|secret|authorization|cookie|otp|session|token)$|(?:^|_)otp_code$|(?:^|_)private_key$|(?:^|_)access_key(?:_id|_secret)?$|(?:^|_)secret_access_key$|(?:^|_)api(?:_[a-z0-9]+)*_key$|^apikey$/i;
|
|
20556
|
-
var DEFAULT_SENSITIVE_REPLACEMENT = "[REDACTED]";
|
|
20557
|
-
var URL_LIKE_KEY_REGEX = /(?:^|_)(?:url|uri|endpoint)(?:_|$)/;
|
|
20558
|
-
var SENSITIVE_KEY_CACHE_LIMIT = 512;
|
|
20559
|
-
var ERROR_DIAGNOSTIC_MAX_DEPTH = 32;
|
|
20560
|
-
var normalizedKeyCache = /* @__PURE__ */ new Map();
|
|
20561
|
-
var urlLikeKeyCache = /* @__PURE__ */ new Map();
|
|
20562
|
-
var defaultSensitiveKeyCache = /* @__PURE__ */ new Map();
|
|
20563
|
-
function getCachedValue(cache, key, createValue) {
|
|
20564
|
-
const cachedValue = cache.get(key);
|
|
20565
|
-
if (cachedValue !== void 0) {
|
|
20566
|
-
return cachedValue;
|
|
20567
|
-
}
|
|
20568
|
-
const value = createValue();
|
|
20569
|
-
if (cache.size >= SENSITIVE_KEY_CACHE_LIMIT) {
|
|
20570
|
-
cache.clear();
|
|
20571
|
-
}
|
|
20572
|
-
cache.set(key, value);
|
|
20573
|
-
return value;
|
|
20574
|
-
}
|
|
20575
|
-
function normalizeKeyForMatching(key) {
|
|
20576
|
-
return getCachedValue(normalizedKeyCache, key, () => {
|
|
20577
|
-
return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").replace(/_+/g, "_").toLowerCase();
|
|
20578
|
-
});
|
|
20579
|
-
}
|
|
20580
|
-
function matchesDefaultSensitiveKey(normalizedKey) {
|
|
20581
|
-
return getCachedValue(defaultSensitiveKeyCache, normalizedKey, () => {
|
|
20582
|
-
return DEFAULT_SENSITIVE_KEY_REGEX.test(normalizedKey);
|
|
20583
|
-
});
|
|
20584
|
-
}
|
|
20585
|
-
function isPlainRecord(value) {
|
|
20586
|
-
if (!typeUtils.isObject(value)) {
|
|
20587
|
-
return false;
|
|
20588
|
-
}
|
|
20589
|
-
const prototype = Object.getPrototypeOf(value);
|
|
20590
|
-
return prototype === Object.prototype || prototype === null;
|
|
20591
|
-
}
|
|
20592
|
-
function compileSensitiveKeyMatcher(matcher) {
|
|
20593
|
-
if (matcher instanceof RegExp) {
|
|
20594
|
-
if (matcher === DEFAULT_SENSITIVE_KEY_REGEX) {
|
|
20595
|
-
return (_key, normalizedKey) => matchesDefaultSensitiveKey(normalizedKey);
|
|
20596
|
-
}
|
|
20597
|
-
const safeMatcher = matcher.global || matcher.sticky ? new RegExp(matcher.source, matcher.flags.replace(/[gy]/g, "")) : matcher;
|
|
20598
|
-
return (_key, normalizedKey) => safeMatcher.test(normalizedKey);
|
|
20599
|
-
}
|
|
20600
|
-
if (Array.isArray(matcher)) {
|
|
20601
|
-
const normalizedKeys = new Set(matcher.map(normalizeKeyForMatching));
|
|
20602
|
-
return (_key, normalizedKey) => normalizedKeys.has(normalizedKey);
|
|
20603
|
-
}
|
|
20604
|
-
return (key) => matcher(key);
|
|
20605
|
-
}
|
|
20606
|
-
function isSensitiveKey(key, matcher = DEFAULT_SENSITIVE_KEY_REGEX) {
|
|
20607
|
-
const normalizedKey = normalizeKeyForMatching(key);
|
|
20608
|
-
return compileSensitiveKeyMatcher(matcher)(key, normalizedKey);
|
|
20609
|
-
}
|
|
20610
|
-
function isUrlLikeNormalizedKey(normalizedKey) {
|
|
20611
|
-
return getCachedValue(urlLikeKeyCache, normalizedKey, () => URL_LIKE_KEY_REGEX.test(normalizedKey));
|
|
20612
|
-
}
|
|
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) {
|
|
20624
|
-
try {
|
|
20625
|
-
const parsed = new URL(url2);
|
|
20626
|
-
if (parsed.username) {
|
|
20627
|
-
parsed.username = context.urlReplacement;
|
|
20628
|
-
}
|
|
20629
|
-
if (parsed.password) {
|
|
20630
|
-
parsed.password = context.urlReplacement;
|
|
20631
|
-
}
|
|
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);
|
|
20636
|
-
} catch {
|
|
20637
|
-
return "(invalid url)";
|
|
20638
|
-
}
|
|
20639
|
-
}
|
|
20640
|
-
function isProtectedPropertyKey(key) {
|
|
20641
|
-
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
20642
|
-
}
|
|
20643
|
-
function createSanitizeSensitiveContext(options = {}) {
|
|
20644
|
-
const replacement = options.replacement ?? DEFAULT_SENSITIVE_REPLACEMENT;
|
|
20645
|
-
return {
|
|
20646
|
-
replacement,
|
|
20647
|
-
urlReplacement: typeof replacement === "string" ? replacement : DEFAULT_SENSITIVE_REPLACEMENT,
|
|
20648
|
-
isSensitiveKey: compileSensitiveKeyMatcher(options.matcher ?? DEFAULT_SENSITIVE_KEY_REGEX)
|
|
20649
|
-
};
|
|
20650
|
-
}
|
|
20651
|
-
function sanitizeSensitiveValueWithContext(value, key, context, cache, errorPath, errorDepth = 0) {
|
|
20652
|
-
const isPlainObjectValue = isPlainRecord(value);
|
|
20653
|
-
const isErrorDiagnostic = errorPath !== void 0 || value instanceof Error;
|
|
20654
|
-
if (key !== null) {
|
|
20655
|
-
const normalizedKey = normalizeKeyForMatching(key);
|
|
20656
|
-
if (typeof value === "string" && isUrlLikeNormalizedKey(normalizedKey)) {
|
|
20657
|
-
return sanitizeUrlWithContext(value, context);
|
|
20658
|
-
}
|
|
20659
|
-
if (context.isSensitiveKey(key, normalizedKey) && !isPlainObjectValue) {
|
|
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);
|
|
20698
|
-
}
|
|
20699
|
-
}
|
|
20700
|
-
if (Array.isArray(value)) {
|
|
20701
|
-
if (cache.has(value)) {
|
|
20702
|
-
return cache.get(value);
|
|
20703
|
-
}
|
|
20704
|
-
const sanitizedArray = [];
|
|
20705
|
-
cache.set(value, sanitizedArray);
|
|
20706
|
-
for (let index = 0; index < value.length; index++) {
|
|
20707
|
-
sanitizedArray[index] = sanitizeSensitiveValueWithContext(value[index], null, context, cache);
|
|
20708
|
-
}
|
|
20709
|
-
return sanitizedArray;
|
|
20710
|
-
}
|
|
20711
|
-
if (isPlainObjectValue) {
|
|
20712
|
-
if (cache.has(value)) {
|
|
20713
|
-
return cache.get(value);
|
|
20714
|
-
}
|
|
20715
|
-
const sanitized = {};
|
|
20716
|
-
cache.set(value, sanitized);
|
|
20717
|
-
for (const childKey in value) {
|
|
20718
|
-
if (!Object.hasOwn(value, childKey) || isProtectedPropertyKey(childKey)) {
|
|
20719
|
-
continue;
|
|
20720
|
-
}
|
|
20721
|
-
sanitized[childKey] = sanitizeSensitiveValueWithContext(value[childKey], childKey, context, cache);
|
|
20722
|
-
}
|
|
20723
|
-
return sanitized;
|
|
20724
|
-
}
|
|
20725
|
-
return value;
|
|
20726
|
-
}
|
|
20727
|
-
function sanitizeSensitiveValue(value, key, options = {}, cache = /* @__PURE__ */ new WeakMap()) {
|
|
20728
|
-
return sanitizeSensitiveValueWithContext(value, key, createSanitizeSensitiveContext(options), cache);
|
|
20729
|
-
}
|
|
20730
|
-
function sanitizeSensitiveFields(value, options = {}) {
|
|
20731
|
-
return sanitizeSensitiveValue(value, null, options);
|
|
20732
|
-
}
|
|
20733
|
-
var sanitize = {
|
|
20734
|
-
defaultSensitiveKeyRegex: DEFAULT_SENSITIVE_KEY_REGEX,
|
|
20735
|
-
defaultSensitiveReplacement: DEFAULT_SENSITIVE_REPLACEMENT,
|
|
20736
|
-
isSensitiveKey,
|
|
20737
|
-
sanitizeUrl,
|
|
20738
|
-
sanitizeSensitiveValue,
|
|
20739
|
-
sanitizeSensitiveFields
|
|
20740
|
-
};
|
|
20741
|
-
|
|
20742
20820
|
// src/utils/core-util-string.ts
|
|
20743
20821
|
var LEADING_LOWERCASE_REGEX = /^[a-z]/;
|
|
20744
20822
|
function capitalize(str) {
|
|
@@ -20888,10 +20966,12 @@ function createCore(loggerFns) {
|
|
|
20888
20966
|
create: loggerFns.createLogger,
|
|
20889
20967
|
configure: loggerFns.configureLogger,
|
|
20890
20968
|
setLevel: loggerFns.setLogLevel,
|
|
20891
|
-
getLevel: loggerFns.getLogLevel
|
|
20969
|
+
getLevel: loggerFns.getLogLevel,
|
|
20970
|
+
observe: observeLogs
|
|
20892
20971
|
};
|
|
20893
20972
|
};
|
|
20894
20973
|
return {
|
|
20974
|
+
context: requestContext,
|
|
20895
20975
|
// ─── Logger ───
|
|
20896
20976
|
/**
|
|
20897
20977
|
* 默认 Logger(懒加载单例),同时提供 create / configure / setLevel / getLevel 管理方法。
|
|
@@ -21063,6 +21143,6 @@ function createCore(loggerFns) {
|
|
|
21063
21143
|
};
|
|
21064
21144
|
}
|
|
21065
21145
|
|
|
21066
|
-
export { CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, __commonJS, __toESM, createCore, err, i18n, installRequestLocales, ok, sanitize, typeUtils };
|
|
21067
|
-
//# sourceMappingURL=chunk-
|
|
21068
|
-
//# sourceMappingURL=chunk-
|
|
21146
|
+
export { CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, __commonJS, __toESM, createCore, emitLogRecord, err, i18n, installRequestContext, installRequestLocales, ok, requestContext, sanitize, sanitizeLogFields, typeUtils };
|
|
21147
|
+
//# sourceMappingURL=chunk-MUQFCAQ5.js.map
|
|
21148
|
+
//# sourceMappingURL=chunk-MUQFCAQ5.js.map
|