@naturalcycles/nodejs-lib 15.107.3 → 15.108.0
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/bin/generate-build-info.js +2 -0
- package/bin/json2env.js +2 -0
- package/bin/kpy.js +2 -0
- package/bin/secrets-decrypt.js +2 -0
- package/bin/secrets-encrypt.js +2 -0
- package/bin/secrets-gen-key.js +2 -0
- package/bin/slack-this.js +2 -0
- package/dist/bin/generate-build-info.d.ts +0 -1
- package/dist/bin/generate-build-info.js +0 -1
- package/dist/bin/json2env.d.ts +0 -1
- package/dist/bin/json2env.js +0 -1
- package/dist/bin/kpy.d.ts +0 -1
- package/dist/bin/kpy.js +0 -1
- package/dist/bin/secrets-decrypt.d.ts +0 -1
- package/dist/bin/secrets-decrypt.js +0 -1
- package/dist/bin/secrets-encrypt.d.ts +0 -1
- package/dist/bin/secrets-encrypt.js +0 -1
- package/dist/bin/secrets-gen-key.d.ts +0 -1
- package/dist/bin/secrets-gen-key.js +0 -1
- package/dist/bin/slack-this.d.ts +0 -1
- package/dist/bin/slack-this.js +0 -1
- package/dist/validation/ajv/jSchema.js +31 -18
- package/package.json +9 -8
- package/src/bin/generate-build-info.ts +0 -2
- package/src/bin/json2env.ts +0 -2
- package/src/bin/kpy.ts +0 -2
- package/src/bin/secrets-decrypt.ts +0 -2
- package/src/bin/secrets-encrypt.ts +0 -2
- package/src/bin/secrets-gen-key.ts +0 -2
- package/src/bin/slack-this.ts +0 -2
- package/src/validation/ajv/jSchema.ts +38 -17
package/bin/json2env.js
ADDED
package/bin/kpy.js
ADDED
package/dist/bin/json2env.d.ts
CHANGED
package/dist/bin/json2env.js
CHANGED
package/dist/bin/kpy.d.ts
CHANGED
package/dist/bin/kpy.js
CHANGED
package/dist/bin/slack-this.d.ts
CHANGED
package/dist/bin/slack-this.js
CHANGED
|
@@ -1180,7 +1180,7 @@ function executeValidation(fn, builtSchema, input, opt = {}, defaultInputName) {
|
|
|
1180
1180
|
const dataVar = [inputName, inputId].filter(Boolean).join('.');
|
|
1181
1181
|
// Build fingerprint before applyImprovementsOnErrorMessages: after it, /items/0/name becomes
|
|
1182
1182
|
// .items[0].name, embedding the index into the segment and making it harder to strip without regex
|
|
1183
|
-
const fingerprint = buildAjvErrorFingerprint(errors[0], inputName);
|
|
1183
|
+
const fingerprint = buildAjvErrorFingerprint(errors[0], inputName, resolveCustomErrorMessage(builtSchema, errors[0]));
|
|
1184
1184
|
applyImprovementsOnErrorMessages(errors, builtSchema);
|
|
1185
1185
|
let message = getAjv().errorsText(errors, {
|
|
1186
1186
|
dataVar,
|
|
@@ -1204,33 +1204,46 @@ function applyImprovementsOnErrorMessages(errors, schema) {
|
|
|
1204
1204
|
if (!errors)
|
|
1205
1205
|
return;
|
|
1206
1206
|
filterNullableAnyOfErrors(errors, schema);
|
|
1207
|
-
const { errorMessages } = schema;
|
|
1208
1207
|
for (const error of errors) {
|
|
1209
|
-
const
|
|
1210
|
-
if (
|
|
1211
|
-
error.message =
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
else {
|
|
1217
|
-
const unwrapped = unwrapNullableAnyOf(schema);
|
|
1218
|
-
if (unwrapped?.errorMessages?.[error.keyword]) {
|
|
1219
|
-
error.message = unwrapped.errorMessages[error.keyword];
|
|
1220
|
-
}
|
|
1208
|
+
const customMessage = resolveCustomErrorMessage(schema, error);
|
|
1209
|
+
if (customMessage) {
|
|
1210
|
+
error.message = customMessage;
|
|
1211
|
+
// A custom `msg` signals "the underlying rule param is an implementation detail".
|
|
1212
|
+
// Drop params so consumers (e.g. HTTP responses, Sentry payloads) don't surface
|
|
1213
|
+
// the raw regex/limit/etc. — the custom message is now the canonical rule label.
|
|
1214
|
+
error.params = {};
|
|
1221
1215
|
}
|
|
1222
1216
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.');
|
|
1223
1217
|
}
|
|
1224
1218
|
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Looks up the user-provided custom error message (set via `{ msg }` / `{ name }`)
|
|
1221
|
+
* for a given AJV error, walking the schema along the error's instancePath and
|
|
1222
|
+
* falling back to top-level `errorMessages` (including through nullable wrappers).
|
|
1223
|
+
* Returns undefined if no custom message was registered for the failing keyword.
|
|
1224
|
+
*/
|
|
1225
|
+
function resolveCustomErrorMessage(schema, error) {
|
|
1226
|
+
const byPath = getErrorMessageForInstancePath(schema, error.instancePath, error.keyword);
|
|
1227
|
+
if (byPath)
|
|
1228
|
+
return byPath;
|
|
1229
|
+
if (schema.errorMessages?.[error.keyword])
|
|
1230
|
+
return schema.errorMessages[error.keyword];
|
|
1231
|
+
const unwrapped = unwrapNullableAnyOf(schema);
|
|
1232
|
+
return unwrapped?.errorMessages?.[error.keyword];
|
|
1233
|
+
}
|
|
1225
1234
|
/**
|
|
1226
1235
|
* Groups repeated validation errors by rule rather than by unique request content.
|
|
1227
1236
|
* Excludes instance-specific data like record IDs and array indices.
|
|
1237
|
+
*
|
|
1238
|
+
* When a custom error message is registered for the failing rule, prefer it over
|
|
1239
|
+
* the raw param value (e.g. regex source) — it is both stable across regex tweaks
|
|
1240
|
+
* and avoids leaking the underlying pattern into Sentry fingerprints.
|
|
1228
1241
|
*/
|
|
1229
|
-
function buildAjvErrorFingerprint(e, inputName) {
|
|
1230
|
-
const
|
|
1242
|
+
function buildAjvErrorFingerprint(e, inputName, customMessage) {
|
|
1243
|
+
const ruleValue = customMessage ?? Object.values(e.params || {})[0];
|
|
1231
1244
|
let rule = e.keyword;
|
|
1232
|
-
if (
|
|
1233
|
-
rule += `:${
|
|
1245
|
+
if (ruleValue !== undefined)
|
|
1246
|
+
rule += `:${ruleValue}`;
|
|
1234
1247
|
const path = e.instancePath
|
|
1235
1248
|
.split('/')
|
|
1236
1249
|
.filter(s => s && isNaN(Number(s)))
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.108.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@standard-schema/spec": "^1",
|
|
@@ -41,15 +41,16 @@
|
|
|
41
41
|
"./zip": "./dist/zip/zip2.js"
|
|
42
42
|
},
|
|
43
43
|
"bin": {
|
|
44
|
-
"kpy": "
|
|
45
|
-
"json2env": "
|
|
46
|
-
"generate-build-info": "
|
|
47
|
-
"slack-this": "
|
|
48
|
-
"secrets-gen-key": "
|
|
49
|
-
"secrets-encrypt": "
|
|
50
|
-
"secrets-decrypt": "
|
|
44
|
+
"kpy": "bin/kpy.js",
|
|
45
|
+
"json2env": "bin/json2env.js",
|
|
46
|
+
"generate-build-info": "bin/generate-build-info.js",
|
|
47
|
+
"slack-this": "bin/slack-this.js",
|
|
48
|
+
"secrets-gen-key": "bin/secrets-gen-key.js",
|
|
49
|
+
"secrets-encrypt": "bin/secrets-encrypt.js",
|
|
50
|
+
"secrets-decrypt": "bin/secrets-decrypt.js"
|
|
51
51
|
},
|
|
52
52
|
"files": [
|
|
53
|
+
"bin",
|
|
53
54
|
"dist",
|
|
54
55
|
"src",
|
|
55
56
|
"!src/test",
|
package/src/bin/json2env.ts
CHANGED
package/src/bin/kpy.ts
CHANGED
package/src/bin/slack-this.ts
CHANGED
|
@@ -1694,7 +1694,11 @@ function executeValidation<OUT>(
|
|
|
1694
1694
|
|
|
1695
1695
|
// Build fingerprint before applyImprovementsOnErrorMessages: after it, /items/0/name becomes
|
|
1696
1696
|
// .items[0].name, embedding the index into the segment and making it harder to strip without regex
|
|
1697
|
-
const fingerprint = buildAjvErrorFingerprint(
|
|
1697
|
+
const fingerprint = buildAjvErrorFingerprint(
|
|
1698
|
+
errors[0],
|
|
1699
|
+
inputName,
|
|
1700
|
+
resolveCustomErrorMessage(builtSchema, errors[0]),
|
|
1701
|
+
)
|
|
1698
1702
|
|
|
1699
1703
|
applyImprovementsOnErrorMessages(errors, builtSchema)
|
|
1700
1704
|
|
|
@@ -1731,34 +1735,51 @@ function applyImprovementsOnErrorMessages(
|
|
|
1731
1735
|
|
|
1732
1736
|
filterNullableAnyOfErrors(errors, schema)
|
|
1733
1737
|
|
|
1734
|
-
const { errorMessages } = schema
|
|
1735
|
-
|
|
1736
1738
|
for (const error of errors) {
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
if (
|
|
1740
|
-
error.message =
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
if (unwrapped?.errorMessages?.[error.keyword]) {
|
|
1746
|
-
error.message = unwrapped.errorMessages[error.keyword]
|
|
1747
|
-
}
|
|
1739
|
+
const customMessage = resolveCustomErrorMessage(schema, error)
|
|
1740
|
+
|
|
1741
|
+
if (customMessage) {
|
|
1742
|
+
error.message = customMessage
|
|
1743
|
+
// A custom `msg` signals "the underlying rule param is an implementation detail".
|
|
1744
|
+
// Drop params so consumers (e.g. HTTP responses, Sentry payloads) don't surface
|
|
1745
|
+
// the raw regex/limit/etc. — the custom message is now the canonical rule label.
|
|
1746
|
+
error.params = {}
|
|
1748
1747
|
}
|
|
1749
1748
|
|
|
1750
1749
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.')
|
|
1751
1750
|
}
|
|
1752
1751
|
}
|
|
1753
1752
|
|
|
1753
|
+
/**
|
|
1754
|
+
* Looks up the user-provided custom error message (set via `{ msg }` / `{ name }`)
|
|
1755
|
+
* for a given AJV error, walking the schema along the error's instancePath and
|
|
1756
|
+
* falling back to top-level `errorMessages` (including through nullable wrappers).
|
|
1757
|
+
* Returns undefined if no custom message was registered for the failing keyword.
|
|
1758
|
+
*/
|
|
1759
|
+
function resolveCustomErrorMessage(schema: JsonSchema, error: ErrorObject): string | undefined {
|
|
1760
|
+
const byPath = getErrorMessageForInstancePath(schema, error.instancePath, error.keyword)
|
|
1761
|
+
if (byPath) return byPath
|
|
1762
|
+
if (schema.errorMessages?.[error.keyword]) return schema.errorMessages[error.keyword]
|
|
1763
|
+
const unwrapped = unwrapNullableAnyOf(schema)
|
|
1764
|
+
return unwrapped?.errorMessages?.[error.keyword]
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1754
1767
|
/**
|
|
1755
1768
|
* Groups repeated validation errors by rule rather than by unique request content.
|
|
1756
1769
|
* Excludes instance-specific data like record IDs and array indices.
|
|
1770
|
+
*
|
|
1771
|
+
* When a custom error message is registered for the failing rule, prefer it over
|
|
1772
|
+
* the raw param value (e.g. regex source) — it is both stable across regex tweaks
|
|
1773
|
+
* and avoids leaking the underlying pattern into Sentry fingerprints.
|
|
1757
1774
|
*/
|
|
1758
|
-
function buildAjvErrorFingerprint(
|
|
1759
|
-
|
|
1775
|
+
function buildAjvErrorFingerprint(
|
|
1776
|
+
e: ErrorObject,
|
|
1777
|
+
inputName: string,
|
|
1778
|
+
customMessage: string | undefined,
|
|
1779
|
+
): string {
|
|
1780
|
+
const ruleValue = customMessage ?? Object.values(e.params || {})[0]
|
|
1760
1781
|
let rule = e.keyword
|
|
1761
|
-
if (
|
|
1782
|
+
if (ruleValue !== undefined) rule += `:${ruleValue}`
|
|
1762
1783
|
const path = e.instancePath
|
|
1763
1784
|
.split('/')
|
|
1764
1785
|
.filter(s => s && isNaN(Number(s)))
|