New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sentry/core

Package Overview
Dependencies
Maintainers
10
Versions
559
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/core - npm Package Compare versions

Comparing version 8.51.0 to 8.52.0

149

build/cjs/integrations/zoderrors.js

@@ -10,3 +10,5 @@ Object.defineProperty(exports, '__esModule', { value: true });

// Simplified ZodIssue type definition
/**
* Simplified ZodIssue type definition
*/

@@ -17,3 +19,3 @@ function originalExceptionIsZodError(originalException) {

originalException.name === 'ZodError' &&
Array.isArray((originalException ).errors)
Array.isArray((originalException ).issues)
);

@@ -24,5 +26,14 @@ }

* Formats child objects or arrays to a string
* That is preserved when sent to Sentry
* that is preserved when sent to Sentry.
*
* Without this, we end up with something like this in Sentry:
*
* [
* [Object],
* [Object],
* [Object],
* [Object]
* ]
*/
function formatIssueTitle(issue) {
function flattenIssue(issue) {
return {

@@ -37,2 +48,26 @@ ...issue,

/**
* Takes ZodError issue path array and returns a flattened version as a string.
* This makes it easier to display paths within a Sentry error message.
*
* Array indexes are normalized to reduce duplicate entries
*
* @param path ZodError issue path
* @returns flattened path
*
* @example
* flattenIssuePath([0, 'foo', 1, 'bar']) // -> '<array>.foo.<array>.bar'
*/
function flattenIssuePath(path) {
return path
.map(p => {
if (typeof p === 'number') {
return '<array>';
} else {
return p;
}
})
.join('.');
}
/**
* Zod error message is a stringified version of ZodError.issues

@@ -44,8 +79,23 @@ * This doesn't display well in the Sentry UI. Replace it with something shorter.

for (const iss of zodError.issues) {
if (iss.path && iss.path[0]) {
errorKeyMap.add(iss.path[0]);
const issuePath = flattenIssuePath(iss.path);
if (issuePath.length > 0) {
errorKeyMap.add(issuePath);
}
}
const errorKeys = Array.from(errorKeyMap);
if (errorKeys.length === 0) {
// If there are no keys, then we're likely validating the root
// variable rather than a key within an object. This attempts
// to extract what type it was that failed to validate.
// For example, z.string().parse(123) would return "string" here.
let rootExpectedType = 'variable';
if (zodError.issues.length > 0) {
const iss = zodError.issues[0];
if (iss !== undefined && 'expected' in iss && typeof iss.expected === 'string') {
rootExpectedType = iss.expected;
}
}
return `Failed to validate ${rootExpectedType}`;
}
return `Failed to validate keys: ${string.truncate(errorKeys.join(', '), 100)}`;

@@ -55,5 +105,10 @@ }

/**
* Applies ZodError issues to an event extras and replaces the error message
* Applies ZodError issues to an event extra and replaces the error message
*/
function applyZodErrorsToEvent(limit, event, hint) {
function applyZodErrorsToEvent(
limit,
saveZodIssuesAsAttachment = false,
event,
hint,
) {
if (

@@ -70,23 +125,57 @@ !event.exception ||

return {
...event,
exception: {
...event.exception,
values: [
{
...event.exception.values[0],
value: formatIssueMessage(hint.originalException),
try {
const issuesToFlatten = saveZodIssuesAsAttachment
? hint.originalException.issues
: hint.originalException.issues.slice(0, limit);
const flattenedIssues = issuesToFlatten.map(flattenIssue);
if (saveZodIssuesAsAttachment) {
// Sometimes having the full error details can be helpful.
// Attachments have much higher limits, so we can include the full list of issues.
if (!Array.isArray(hint.attachments)) {
hint.attachments = [];
}
hint.attachments.push({
filename: 'zod_issues.json',
data: JSON.stringify({
issues: flattenedIssues,
}),
});
}
return {
...event,
exception: {
...event.exception,
values: [
{
...event.exception.values[0],
value: formatIssueMessage(hint.originalException),
},
...event.exception.values.slice(1),
],
},
extra: {
...event.extra,
'zoderror.issues': flattenedIssues.slice(0, limit),
},
};
} catch (e) {
// Hopefully we never throw errors here, but record it
// with the event just in case.
return {
...event,
extra: {
...event.extra,
'zoderrors sentry integration parse error': {
message: 'an exception was thrown while processing ZodError within applyZodErrorsToEvent()',
error: e instanceof Error ? `${e.name}: ${e.message}\n${e.stack}` : 'unknown',
},
...event.exception.values.slice(1),
],
},
extra: {
...event.extra,
'zoderror.issues': hint.originalException.errors.slice(0, limit).map(formatIssueTitle),
},
};
},
};
}
}
const _zodErrorsIntegration = ((options = {}) => {
const limit = options.limit || DEFAULT_LIMIT;
const limit = typeof options.limit === 'undefined' ? DEFAULT_LIMIT : options.limit;

@@ -96,3 +185,3 @@ return {

processEvent(originalEvent, hint) {
const processedEvent = applyZodErrorsToEvent(limit, originalEvent, hint);
const processedEvent = applyZodErrorsToEvent(limit, options.saveZodIssuesAsAttachment, originalEvent, hint);
return processedEvent;

@@ -103,6 +192,12 @@ },

/**
* Sentry integration to process Zod errors, making them easier to work with in Sentry.
*/
const zodErrorsIntegration = integration.defineIntegration(_zodErrorsIntegration);
exports.applyZodErrorsToEvent = applyZodErrorsToEvent;
exports.flattenIssue = flattenIssue;
exports.flattenIssuePath = flattenIssuePath;
exports.formatIssueMessage = formatIssueMessage;
exports.zodErrorsIntegration = zodErrorsIntegration;
//# sourceMappingURL=zoderrors.js.map

10

build/cjs/scope.js

@@ -406,5 +406,9 @@ Object.defineProperty(exports, '__esModule', { value: true });

const breadcrumbs = this._breadcrumbs;
breadcrumbs.push(mergedBreadcrumb);
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
this._breadcrumbs.push(mergedBreadcrumb);
if (this._breadcrumbs.length > maxCrumbs) {
this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
if (this._client) {
this._client.recordDroppedEvent('buffer_overflow', 'log_item');
}
}

@@ -411,0 +415,0 @@ this._notifyScopeListeners();

@@ -48,5 +48,7 @@ Object.defineProperty(exports, '__esModule', { value: true });

* @param moduleName module name to require
* @param existingModule module to use for requiring
* @returns possibly required module
*/
function loadModule(moduleName) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function loadModule(moduleName, existingModule = module) {
let mod;

@@ -56,3 +58,3 @@

// eslint-disable-next-line deprecation/deprecation
mod = dynamicRequire(module, moduleName);
mod = dynamicRequire(existingModule, moduleName);
} catch (e) {

@@ -65,5 +67,5 @@ // no-empty

// eslint-disable-next-line deprecation/deprecation
const { cwd } = dynamicRequire(module, 'process');
const { cwd } = dynamicRequire(existingModule, 'process');
// eslint-disable-next-line deprecation/deprecation
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) ;
mod = dynamicRequire(existingModule, `${cwd()}/node_modules/${moduleName}`) ;
} catch (e) {

@@ -70,0 +72,0 @@ // no-empty

@@ -5,5 +5,5 @@ Object.defineProperty(exports, '__esModule', { value: true });

const SDK_VERSION = "8.51.0" ;
const SDK_VERSION = "8.52.0" ;
exports.SDK_VERSION = SDK_VERSION;
//# sourceMappingURL=version.js.map

@@ -8,3 +8,5 @@ import { defineIntegration } from '../integration.js';

// Simplified ZodIssue type definition
/**
* Simplified ZodIssue type definition
*/

@@ -15,3 +17,3 @@ function originalExceptionIsZodError(originalException) {

originalException.name === 'ZodError' &&
Array.isArray((originalException ).errors)
Array.isArray((originalException ).issues)
);

@@ -22,5 +24,14 @@ }

* Formats child objects or arrays to a string
* That is preserved when sent to Sentry
* that is preserved when sent to Sentry.
*
* Without this, we end up with something like this in Sentry:
*
* [
* [Object],
* [Object],
* [Object],
* [Object]
* ]
*/
function formatIssueTitle(issue) {
function flattenIssue(issue) {
return {

@@ -35,2 +46,26 @@ ...issue,

/**
* Takes ZodError issue path array and returns a flattened version as a string.
* This makes it easier to display paths within a Sentry error message.
*
* Array indexes are normalized to reduce duplicate entries
*
* @param path ZodError issue path
* @returns flattened path
*
* @example
* flattenIssuePath([0, 'foo', 1, 'bar']) // -> '<array>.foo.<array>.bar'
*/
function flattenIssuePath(path) {
return path
.map(p => {
if (typeof p === 'number') {
return '<array>';
} else {
return p;
}
})
.join('.');
}
/**
* Zod error message is a stringified version of ZodError.issues

@@ -42,8 +77,23 @@ * This doesn't display well in the Sentry UI. Replace it with something shorter.

for (const iss of zodError.issues) {
if (iss.path && iss.path[0]) {
errorKeyMap.add(iss.path[0]);
const issuePath = flattenIssuePath(iss.path);
if (issuePath.length > 0) {
errorKeyMap.add(issuePath);
}
}
const errorKeys = Array.from(errorKeyMap);
if (errorKeys.length === 0) {
// If there are no keys, then we're likely validating the root
// variable rather than a key within an object. This attempts
// to extract what type it was that failed to validate.
// For example, z.string().parse(123) would return "string" here.
let rootExpectedType = 'variable';
if (zodError.issues.length > 0) {
const iss = zodError.issues[0];
if (iss !== undefined && 'expected' in iss && typeof iss.expected === 'string') {
rootExpectedType = iss.expected;
}
}
return `Failed to validate ${rootExpectedType}`;
}
return `Failed to validate keys: ${truncate(errorKeys.join(', '), 100)}`;

@@ -53,5 +103,10 @@ }

/**
* Applies ZodError issues to an event extras and replaces the error message
* Applies ZodError issues to an event extra and replaces the error message
*/
function applyZodErrorsToEvent(limit, event, hint) {
function applyZodErrorsToEvent(
limit,
saveZodIssuesAsAttachment = false,
event,
hint,
) {
if (

@@ -68,23 +123,57 @@ !event.exception ||

return {
...event,
exception: {
...event.exception,
values: [
{
...event.exception.values[0],
value: formatIssueMessage(hint.originalException),
try {
const issuesToFlatten = saveZodIssuesAsAttachment
? hint.originalException.issues
: hint.originalException.issues.slice(0, limit);
const flattenedIssues = issuesToFlatten.map(flattenIssue);
if (saveZodIssuesAsAttachment) {
// Sometimes having the full error details can be helpful.
// Attachments have much higher limits, so we can include the full list of issues.
if (!Array.isArray(hint.attachments)) {
hint.attachments = [];
}
hint.attachments.push({
filename: 'zod_issues.json',
data: JSON.stringify({
issues: flattenedIssues,
}),
});
}
return {
...event,
exception: {
...event.exception,
values: [
{
...event.exception.values[0],
value: formatIssueMessage(hint.originalException),
},
...event.exception.values.slice(1),
],
},
extra: {
...event.extra,
'zoderror.issues': flattenedIssues.slice(0, limit),
},
};
} catch (e) {
// Hopefully we never throw errors here, but record it
// with the event just in case.
return {
...event,
extra: {
...event.extra,
'zoderrors sentry integration parse error': {
message: 'an exception was thrown while processing ZodError within applyZodErrorsToEvent()',
error: e instanceof Error ? `${e.name}: ${e.message}\n${e.stack}` : 'unknown',
},
...event.exception.values.slice(1),
],
},
extra: {
...event.extra,
'zoderror.issues': hint.originalException.errors.slice(0, limit).map(formatIssueTitle),
},
};
},
};
}
}
const _zodErrorsIntegration = ((options = {}) => {
const limit = options.limit || DEFAULT_LIMIT;
const limit = typeof options.limit === 'undefined' ? DEFAULT_LIMIT : options.limit;

@@ -94,3 +183,3 @@ return {

processEvent(originalEvent, hint) {
const processedEvent = applyZodErrorsToEvent(limit, originalEvent, hint);
const processedEvent = applyZodErrorsToEvent(limit, options.saveZodIssuesAsAttachment, originalEvent, hint);
return processedEvent;

@@ -101,5 +190,8 @@ },

/**
* Sentry integration to process Zod errors, making them easier to work with in Sentry.
*/
const zodErrorsIntegration = defineIntegration(_zodErrorsIntegration);
export { applyZodErrorsToEvent, zodErrorsIntegration };
export { applyZodErrorsToEvent, flattenIssue, flattenIssuePath, formatIssueMessage, zodErrorsIntegration };
//# sourceMappingURL=zoderrors.js.map

@@ -1,1 +0,1 @@

{"type":"module","version":"8.51.0","sideEffects":false}
{"type":"module","version":"8.52.0","sideEffects":false}

@@ -404,5 +404,9 @@ import { updateSession } from './session.js';

const breadcrumbs = this._breadcrumbs;
breadcrumbs.push(mergedBreadcrumb);
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
this._breadcrumbs.push(mergedBreadcrumb);
if (this._breadcrumbs.length > maxCrumbs) {
this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
if (this._client) {
this._client.recordDroppedEvent('buffer_overflow', 'log_item');
}
}

@@ -409,0 +413,0 @@ this._notifyScopeListeners();

@@ -46,5 +46,7 @@ import { isBrowserBundle } from './env.js';

* @param moduleName module name to require
* @param existingModule module to use for requiring
* @returns possibly required module
*/
function loadModule(moduleName) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function loadModule(moduleName, existingModule = module) {
let mod;

@@ -54,3 +56,3 @@

// eslint-disable-next-line deprecation/deprecation
mod = dynamicRequire(module, moduleName);
mod = dynamicRequire(existingModule, moduleName);
} catch (e) {

@@ -63,5 +65,5 @@ // no-empty

// eslint-disable-next-line deprecation/deprecation
const { cwd } = dynamicRequire(module, 'process');
const { cwd } = dynamicRequire(existingModule, 'process');
// eslint-disable-next-line deprecation/deprecation
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) ;
mod = dynamicRequire(existingModule, `${cwd()}/node_modules/${moduleName}`) ;
} catch (e) {

@@ -68,0 +70,0 @@ // no-empty

// This is a magic string replaced by rollup
const SDK_VERSION = "8.51.0" ;
const SDK_VERSION = "8.52.0" ;
export { SDK_VERSION };
//# sourceMappingURL=version.js.map
import { Event, EventHint } from '../types-hoist';
interface ZodErrorsOptions {
key?: string;
/**
* Limits the number of Zod errors inlined in each Sentry event.
*
* @default 10
*/
limit?: number;
/**
* Save full list of Zod issues as an attachment in Sentry
*
* @default false
*/
saveZodIssuesAsAttachment?: boolean;
}
/**
* Applies ZodError issues to an event extras and replaces the error message
* Simplified ZodIssue type definition
*/
export declare function applyZodErrorsToEvent(limit: number, event: Event, hint?: EventHint): Event;
interface ZodIssue {
path: (string | number)[];
message?: string;
expected?: unknown;
received?: unknown;
unionErrors?: unknown[];
keys?: unknown[];
invalid_literal?: unknown;
}
interface ZodError extends Error {
issues: ZodIssue[];
}
type SingleLevelZodIssue<T extends ZodIssue> = {
[P in keyof T]: T[P] extends string | number | undefined ? T[P] : T[P] extends unknown[] ? string | undefined : unknown;
};
/**
* Formats child objects or arrays to a string
* that is preserved when sent to Sentry.
*
* Without this, we end up with something like this in Sentry:
*
* [
* [Object],
* [Object],
* [Object],
* [Object]
* ]
*/
export declare function flattenIssue(issue: ZodIssue): SingleLevelZodIssue<ZodIssue>;
/**
* Takes ZodError issue path array and returns a flattened version as a string.
* This makes it easier to display paths within a Sentry error message.
*
* Array indexes are normalized to reduce duplicate entries
*
* @param path ZodError issue path
* @returns flattened path
*
* @example
* flattenIssuePath([0, 'foo', 1, 'bar']) // -> '<array>.foo.<array>.bar'
*/
export declare function flattenIssuePath(path: Array<string | number>): string;
/**
* Zod error message is a stringified version of ZodError.issues
* This doesn't display well in the Sentry UI. Replace it with something shorter.
*/
export declare function formatIssueMessage(zodError: ZodError): string;
/**
* Applies ZodError issues to an event extra and replaces the error message
*/
export declare function applyZodErrorsToEvent(limit: number, saveZodIssuesAsAttachment: boolean | undefined, event: Event, hint: EventHint): Event;
/**
* Sentry integration to process Zod errors, making them easier to work with in Sentry.
*/
export declare const zodErrorsIntegration: (options?: ZodErrorsOptions | undefined) => import("../types-hoist").Integration;
export {};
//# sourceMappingURL=zoderrors.d.ts.map
import { DataCategory } from './datacategory';
export type EventDropReason = 'before_send' | 'event_processor' | 'network_error' | 'queue_overflow' | 'ratelimit_backoff' | 'sample_rate' | 'send_error' | 'internal_sdk_error';
export type EventDropReason = 'before_send' | 'event_processor' | 'network_error' | 'queue_overflow' | 'ratelimit_backoff' | 'sample_rate' | 'send_error' | 'internal_sdk_error' | 'buffer_overflow';
export type Outcome = {

@@ -4,0 +4,0 @@ reason: EventDropReason;

@@ -1,2 +0,2 @@

export type DataCategory = 'default' | 'error' | 'transaction' | 'replay' | 'security' | 'attachment' | 'session' | 'internal' | 'profile' | 'monitor' | 'feedback' | 'metric_bucket' | 'span' | 'unknown';
export type DataCategory = 'default' | 'error' | 'transaction' | 'replay' | 'security' | 'attachment' | 'session' | 'internal' | 'profile' | 'monitor' | 'feedback' | 'metric_bucket' | 'span' | 'log_item' | 'log_byte' | 'unknown';
//# sourceMappingURL=datacategory.d.ts.map

@@ -29,5 +29,6 @@ /**

* @param moduleName module name to require
* @param existingModule module to use for requiring
* @returns possibly required module
*/
export declare function loadModule<T>(moduleName: string): T | undefined;
export declare function loadModule<T>(moduleName: string, existingModule?: any): T | undefined;
//# sourceMappingURL=node.d.ts.map
import type { Event, EventHint } from '../types-hoist';
interface ZodErrorsOptions {
key?: string;
/**
* Limits the number of Zod errors inlined in each Sentry event.
*
* @default 10
*/
limit?: number;
/**
* Save full list of Zod issues as an attachment in Sentry
*
* @default false
*/
saveZodIssuesAsAttachment?: boolean;
}
/**
* Applies ZodError issues to an event extras and replaces the error message
* Simplified ZodIssue type definition
*/
export declare function applyZodErrorsToEvent(limit: number, event: Event, hint?: EventHint): Event;
interface ZodIssue {
path: (string | number)[];
message?: string;
expected?: unknown;
received?: unknown;
unionErrors?: unknown[];
keys?: unknown[];
invalid_literal?: unknown;
}
interface ZodError extends Error {
issues: ZodIssue[];
}
type SingleLevelZodIssue<T extends ZodIssue> = {
[P in keyof T]: T[P] extends string | number | undefined ? T[P] : T[P] extends unknown[] ? string | undefined : unknown;
};
/**
* Formats child objects or arrays to a string
* that is preserved when sent to Sentry.
*
* Without this, we end up with something like this in Sentry:
*
* [
* [Object],
* [Object],
* [Object],
* [Object]
* ]
*/
export declare function flattenIssue(issue: ZodIssue): SingleLevelZodIssue<ZodIssue>;
/**
* Takes ZodError issue path array and returns a flattened version as a string.
* This makes it easier to display paths within a Sentry error message.
*
* Array indexes are normalized to reduce duplicate entries
*
* @param path ZodError issue path
* @returns flattened path
*
* @example
* flattenIssuePath([0, 'foo', 1, 'bar']) // -> '<array>.foo.<array>.bar'
*/
export declare function flattenIssuePath(path: Array<string | number>): string;
/**
* Zod error message is a stringified version of ZodError.issues
* This doesn't display well in the Sentry UI. Replace it with something shorter.
*/
export declare function formatIssueMessage(zodError: ZodError): string;
/**
* Applies ZodError issues to an event extra and replaces the error message
*/
export declare function applyZodErrorsToEvent(limit: number, saveZodIssuesAsAttachment: boolean | undefined, event: Event, hint: EventHint): Event;
/**
* Sentry integration to process Zod errors, making them easier to work with in Sentry.
*/
export declare const zodErrorsIntegration: (options?: ZodErrorsOptions | undefined) => import("../types-hoist").Integration;
export {};
//# sourceMappingURL=zoderrors.d.ts.map
import type { DataCategory } from './datacategory';
export type EventDropReason = 'before_send' | 'event_processor' | 'network_error' | 'queue_overflow' | 'ratelimit_backoff' | 'sample_rate' | 'send_error' | 'internal_sdk_error';
export type EventDropReason = 'before_send' | 'event_processor' | 'network_error' | 'queue_overflow' | 'ratelimit_backoff' | 'sample_rate' | 'send_error' | 'internal_sdk_error' | 'buffer_overflow';
export type Outcome = {

@@ -4,0 +4,0 @@ reason: EventDropReason;

@@ -1,2 +0,2 @@

export type DataCategory = 'default' | 'error' | 'transaction' | 'replay' | 'security' | 'attachment' | 'session' | 'internal' | 'profile' | 'monitor' | 'feedback' | 'metric_bucket' | 'span' | 'unknown';
export type DataCategory = 'default' | 'error' | 'transaction' | 'replay' | 'security' | 'attachment' | 'session' | 'internal' | 'profile' | 'monitor' | 'feedback' | 'metric_bucket' | 'span' | 'log_item' | 'log_byte' | 'unknown';
//# sourceMappingURL=datacategory.d.ts.map

@@ -29,5 +29,6 @@ /**

* @param moduleName module name to require
* @param existingModule module to use for requiring
* @returns possibly required module
*/
export declare function loadModule<T>(moduleName: string): T | undefined;
export declare function loadModule<T>(moduleName: string, existingModule?: any): T | undefined;
//# sourceMappingURL=node.d.ts.map
{
"name": "@sentry/core",
"version": "8.51.0",
"version": "8.52.0",
"description": "Base implementation for all Sentry JavaScript SDKs",

@@ -44,3 +44,4 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"@types/array.prototype.flat": "^1.2.1",
"array.prototype.flat": "^1.3.0"
"array.prototype.flat": "^1.3.0",
"zod": "^3.24.1"
},

@@ -47,0 +48,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc