@basis-theory/basis-theory-reactor-formulas-sdk-js
Advanced tools
Comparing version 1.5.1 to 1.5.2
{ | ||
"name": "@basis-theory/basis-theory-reactor-formulas-sdk-js", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "Javascript SDK for building Basis Theory reactor formulas", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/Basis-Theory/basistheory-reactor-formulas-sdk-js", |
@@ -0,1 +1,19 @@ | ||
// this method avoids a TypeError if the error contains a circular reference, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value | ||
const safeStringify = (obj) => { | ||
const seen = new WeakSet(); | ||
return JSON.stringify(obj, (key, value) => { | ||
if (typeof value === 'object' && value !== undefined) { | ||
if (seen.has(value)) { | ||
// circular reference found, return a placeholder or skip it | ||
return '[Circular]'; | ||
} | ||
seen.add(value); | ||
} | ||
return value; | ||
}); | ||
}; | ||
const sanitizeErrors = (errors) => { | ||
@@ -7,34 +25,41 @@ const sanitizedErrors = {}; | ||
if (Array.isArray(errors)) { | ||
sanitizedErrors['error'] = errors; | ||
} else if (errors instanceof Error) { | ||
if (errors.message) { | ||
sanitizedErrors['error'] = [errors.message]; | ||
} else if (errors.name !== 'Error') { | ||
// "Error" is not helpful as a message | ||
sanitizedErrors['error'] = [errors.name]; | ||
try { | ||
const mapSanitizedError = (error) => | ||
error.map((e) => | ||
typeof e === 'object' | ||
? safeStringify(e) | ||
: e?.toString() ?? fallbackErrorMessage | ||
); | ||
if (Array.isArray(errors)) { | ||
sanitizedErrors['error'] = mapSanitizedError(errors); | ||
} else if (errors instanceof Error) { | ||
if (errors.message) { | ||
sanitizedErrors['error'] = [errors.message]; | ||
} else if (errors.name !== 'Error') { | ||
// "Error" is not helpful as a message | ||
sanitizedErrors['error'] = [errors.name]; | ||
} else { | ||
sanitizedErrors['error'] = [fallbackErrorMessage]; | ||
} | ||
} else if (typeof errors === 'object') { | ||
for (const property in errors) { | ||
if (Array.isArray(errors[property])) { | ||
sanitizedErrors[property] = mapSanitizedError(errors[property]); | ||
} else if (typeof errors[property] === 'object') { | ||
sanitizedErrors[property] = [safeStringify(errors[property])]; | ||
} else if (errors[property]) { | ||
sanitizedErrors[property] = [errors[property].toString()]; | ||
} else { | ||
sanitizedErrors[property] = [fallbackErrorMessage]; | ||
} | ||
} | ||
} else if (typeof errors === 'string') { | ||
sanitizedErrors['error'] = [errors]; | ||
} else if (errors) { | ||
sanitizedErrors['error'] = [errors.toString()]; | ||
} else { | ||
sanitizedErrors['error'] = [fallbackErrorMessage]; | ||
} | ||
} else if (typeof errors === 'object') { | ||
for (const property in errors) { | ||
if (Array.isArray(errors[property])) { | ||
sanitizedErrors[property] = errors[property].map((e) => | ||
typeof e === 'object' | ||
? JSON.stringify(e) | ||
: e?.toString() ?? fallbackErrorMessage | ||
); | ||
} else if (typeof errors[property] === 'object') { | ||
sanitizedErrors[property] = [JSON.stringify(errors[property])]; | ||
} else if (errors[property]) { | ||
sanitizedErrors[property] = [errors[property].toString()]; | ||
} else { | ||
sanitizedErrors[property] = [fallbackErrorMessage]; | ||
} | ||
} | ||
} else if (typeof errors === 'string') { | ||
sanitizedErrors['error'] = [errors]; | ||
} else if (errors) { | ||
sanitizedErrors['error'] = [errors.toString()]; | ||
} else { | ||
} catch { | ||
sanitizedErrors['error'] = [fallbackErrorMessage]; | ||
@@ -41,0 +66,0 @@ } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21138
230
1