🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

caught-object-report-json

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caught-object-report-json - npm Package Compare versions

Comparing version

to
7.1.0

25

index.d.ts

@@ -122,3 +122,3 @@ export type CaughtObjectReportJson = {

*/
as_string_format?: CorjAsStringFormat;
as_string_format?: CorjAsStringFormat | null;
/**

@@ -130,3 +130,3 @@ * Indicates a method used to obtain the value of `as_json`.<br>

*/
as_json_format: CorjAsJsonFormat;
as_json_format: CorjAsJsonFormat | null;
/**

@@ -191,2 +191,7 @@ * Optional link to JSON schema this object conforms to.<br>

/**
*
*/
asJsonFormatsToApply: [CorjAsJsonFormat, ...CorjAsJsonFormat[]];
asStringFormatsToApply: [CorjAsStringFormat, ...CorjAsStringFormat[]];
/**
* Controls how much levels of nested errors will be included.

@@ -228,4 +233,4 @@ * For example

};
export type CorjAsStringFormat = typeof CORJ_AS_STRING_FORMAT_STRING_CONSTRUCTOR;
export type CorjAsJsonFormat = typeof CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1;
export type CorjAsStringFormat = typeof CORJ_AS_STRING_FORMAT_STRING_COERCION | typeof CORJ_AS_STRING_FORMAT_TO_CORJ_AS_STRING_METHOD;
export type CorjAsJsonFormat = typeof CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1 | typeof CORJ_AS_JSON_FORMAT_TO_CORJ_AS_JSON_METHOD;
export declare const CORJ_NESTED_OMITTED_REASONS: {

@@ -235,6 +240,8 @@ REACHED_MAX_DEPTH: (maxDepth: number) => string;

export declare const CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1 = "safe-stable-stringify@2.4.1";
export declare const CORJ_AS_STRING_FORMAT_STRING_CONSTRUCTOR = "String";
export declare const CORJ_VERSION = "corj/v0.7";
export declare const CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK = "https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-object.json";
export declare const CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK = "https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-array.json";
export declare const CORJ_AS_JSON_FORMAT_TO_CORJ_AS_JSON_METHOD = ".toCorjAsJson";
export declare const CORJ_AS_STRING_FORMAT_STRING_COERCION = "String";
export declare const CORJ_AS_STRING_FORMAT_TO_CORJ_AS_STRING_METHOD = ".toCorjAsString";
export declare const CORJ_VERSION = "corj/v0.8";
export declare const CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK: string;
export declare const CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK: string;
export declare const CORJ_MAKER_DEFAULT_OPTIONS: Readonly<{

@@ -255,2 +262,4 @@ metadataFields: {

};
asJsonFormatsToApply: [CorjAsJsonFormat, CorjAsJsonFormat];
asStringFormatsToApply: [CorjAsStringFormat, CorjAsStringFormat];
maxChildrenLevel: 5;

@@ -257,0 +266,0 @@ childrenSources: string[];

@@ -23,3 +23,3 @@ "use strict";

exports.__esModule = true;
exports.bakeCorjArray = exports.makeCaughtObjectReportJsonArray = exports.bakeCorj = exports.makeCaughtObjectReportJson = exports.CorjMaker = exports.CORJ_MAKER_DEFAULT_OPTIONS = exports.CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK = exports.CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK = exports.CORJ_VERSION = exports.CORJ_AS_STRING_FORMAT_STRING_CONSTRUCTOR = exports.CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1 = exports.CORJ_NESTED_OMITTED_REASONS = void 0;
exports.bakeCorjArray = exports.makeCaughtObjectReportJsonArray = exports.bakeCorj = exports.makeCaughtObjectReportJson = exports.CorjMaker = exports.CORJ_MAKER_DEFAULT_OPTIONS = exports.CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK = exports.CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK = exports.CORJ_VERSION = exports.CORJ_AS_STRING_FORMAT_TO_CORJ_AS_STRING_METHOD = exports.CORJ_AS_STRING_FORMAT_STRING_COERCION = exports.CORJ_AS_JSON_FORMAT_TO_CORJ_AS_JSON_METHOD = exports.CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1 = exports.CORJ_NESTED_OMITTED_REASONS = void 0;
var safe_stable_stringify_1 = require("safe-stable-stringify");

@@ -36,6 +36,8 @@ // ██████╗ ██████╗ ███╗ ██╗███████╗████████╗ █████╗ ███╗ ██╗████████╗███████╗

exports.CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1 = 'safe-stable-stringify@2.4.1';
exports.CORJ_AS_STRING_FORMAT_STRING_CONSTRUCTOR = 'String';
exports.CORJ_VERSION = 'corj/v0.7';
exports.CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK = 'https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-object.json';
exports.CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK = 'https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-array.json';
exports.CORJ_AS_JSON_FORMAT_TO_CORJ_AS_JSON_METHOD = '.toCorjAsJson';
exports.CORJ_AS_STRING_FORMAT_STRING_COERCION = 'String';
exports.CORJ_AS_STRING_FORMAT_TO_CORJ_AS_STRING_METHOD = '.toCorjAsString';
exports.CORJ_VERSION = 'corj/v0.8';
exports.CORJ_REPORT_OBJECT_JSON_SCHEMA_LINK = "https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/".concat(exports.CORJ_VERSION, "/report-object.json");
exports.CORJ_REPORT_ARRAY_JSON_SCHEMA_LINK = "https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/".concat(exports.CORJ_VERSION, "/report-array.json");
exports.CORJ_MAKER_DEFAULT_OPTIONS = Object.freeze({

@@ -56,2 +58,4 @@ metadataFields: {

},
asJsonFormatsToApply: ['.toCorjAsJson', 'safe-stable-stringify@2.4.1'],
asStringFormatsToApply: ['.toCorjAsString', 'String'],
maxChildrenLevel: 5,

@@ -116,3 +120,3 @@ childrenSources: ['cause', 'errors'],

function screenOptionsForAccessorErrors(options) {
var _a;
var _a, _b, _c;
if (options === exports.CORJ_MAKER_DEFAULT_OPTIONS) {

@@ -136,2 +140,6 @@ return options;

}
options.asJsonFormatsToApply;
(_a = options.asJsonFormatsToApply) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f; });
options.asStringFormatsToApply;
(_b = options.asStringFormatsToApply) === null || _b === void 0 ? void 0 : _b.forEach(function (f) { return f; });
options.makeReportId;

@@ -142,3 +150,3 @@ options.printWarningsOnUnhandledErrors;

options.childrenSources;
(_a = options.childrenSources) === null || _a === void 0 ? void 0 : _a.forEach(function (s) { return s; });
(_c = options.childrenSources) === null || _c === void 0 ? void 0 : _c.forEach(function (s) { return s; });
return options;

@@ -243,20 +251,69 @@ }

function makeProp_as_string(caught, options, nestedCfg) {
var format = exports.CORJ_AS_STRING_FORMAT_STRING_CONSTRUCTOR;
try {
return {
format: format,
value: String(caught)
};
var formats = options.asStringFormatsToApply;
for (var i = 0; i < formats.length; ++i) {
var format = formats[i];
try {
switch (format) {
case exports.CORJ_AS_STRING_FORMAT_STRING_COERCION:
return {
format: format,
value: String(caught)
};
case exports.CORJ_AS_STRING_FORMAT_TO_CORJ_AS_STRING_METHOD: {
if (!caught ||
typeof caught !== 'object' ||
!('toCorjAsString' in caught) ||
typeof caught['toCorjAsString'] !== 'function') {
if (i < formats.length - 1) {
continue;
}
else {
return {
format: format,
value: null
};
}
}
else {
var value = caught.toCorjAsString({ options: options, caught: caught, nestedCfg: nestedCfg });
if (typeof value !== 'string') {
if (i < formats.length - 1) {
continue;
}
else {
return {
format: format,
value: null
};
}
}
return {
format: format,
value: value
};
}
}
}
}
catch (caughtNew) {
if (i < formats.length - 1) {
continue;
}
else {
handleCaught(caughtNew, options, {
reason: 'error-converting-caught-to-json',
caughtObjectNestingInfo: nestedCfg,
caughtWhenProcessingReportKey: 'as_string'
});
return {
format: format,
value: null
};
}
}
}
catch (caughtNew) {
handleCaught(caughtNew, options, {
reason: 'error-converting-caught-to-json',
caughtObjectNestingInfo: nestedCfg,
caughtWhenProcessingReportKey: 'as_string'
});
return {
format: format,
value: null
};
}
return {
format: null,
value: null
};
}

@@ -301,32 +358,82 @@ function makeProp_as_string_format(format, options, nestedCfg) {

function makeProp_as_json(caught, options, nestedCfg) {
var format = exports.CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1;
try {
var jsonString = jsonStringify(caught, function (key, value) {
if (this === caught && options.childrenSources.includes(key)) {
return undefined;
var formats = options.asJsonFormatsToApply;
for (var i = 0; i < formats.length; ++i) {
var format = formats[i];
try {
switch (format) {
case exports.CORJ_AS_JSON_FORMAT_TO_CORJ_AS_JSON_METHOD: {
if (!caught ||
typeof caught !== 'object' ||
!('toCorjAsJson' in caught) ||
typeof caught['toCorjAsJson'] !== 'function') {
if (i < formats.length - 1) {
continue;
}
else {
return {
format: format,
value: null
};
}
}
else {
var value = jsonStringify(caught.toCorjAsJson({ options: options, caught: caught, nestedCfg: nestedCfg }));
if (value === undefined) {
if (i < formats.length - 1) {
continue;
}
else {
return {
format: format,
value: null
};
}
}
else {
return {
format: format,
value: JSON.parse(value)
};
}
}
}
case exports.CORJ_AS_JSON_FORMAT_SAFE_STABLE_STRINGIFY_2_4_1: {
var jsonString = jsonStringify(caught, function (key, value) {
if (this === caught && options.childrenSources.includes(key)) {
return undefined;
}
return value;
});
if (typeof jsonString !== 'string') {
var err = new Error("Could not convert caught object to json string using ".concat(format, "."));
err.originalCaught = caught;
err.originalCaughtStringifyResult = jsonString;
throw err;
}
return {
format: format,
value: JSON.parse(jsonString)
};
}
}
return value;
});
if (typeof jsonString !== 'string') {
var err = new Error("Could not convert caught object to json string using ".concat(format, "."));
err.originalCaught = caught;
err.originalCaughtStringifyResult = jsonString;
throw err;
}
return {
format: format,
value: JSON.parse(jsonString)
};
catch (caughtNew) {
if (i < formats.length - 1) {
continue;
}
handleCaught(caughtNew, options, {
reason: 'error-converting-caught-to-json',
caughtObjectNestingInfo: nestedCfg,
caughtWhenProcessingReportKey: 'as_json'
});
return {
format: format,
value: null
};
}
}
catch (caughtNew) {
handleCaught(caughtNew, options, {
reason: 'error-converting-caught-to-json',
caughtObjectNestingInfo: nestedCfg,
caughtWhenProcessingReportKey: 'as_json'
});
return {
format: format,
value: null
};
}
return {
format: null,
value: null
};
}

@@ -333,0 +440,0 @@ function makeProp_message(caught, options, nestedCfg) {

{
"name": "caught-object-report-json",
"version": "7.0.0",
"version": "7.1.0",
"description": "JS Error JSON representation",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -32,3 +32,3 @@ # Caught Object Report JSON

* [Deno Land](#deno-land)
* [CORJ JSON Schema - corj/v0.7](#corj-json-schema---corjv07)
* [CORJ JSON Schema - corj/v0.8](#corj-json-schema---corjv08)

@@ -630,6 +630,6 @@ # Motivation

##### CORJ JSON Schema - corj/v0.7
##### CORJ JSON Schema - corj/v0.8
- Definitions - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-definitions.json
- Report Object - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-object.json
- Report Array - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.7-report-array.json
- Definitions - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.8/definitions.json
- Report Object - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.8/report-object.json
- Report Array - https://raw.githubusercontent.com/dany-fedorov/caught-object-report-json/main/schema-versions/corj/v0.8/report-array.json