@wrelik/errors 0.2.1 → 2.0.1

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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +26 -28
  2. package/.turbo/turbo-lint.log +35 -0
  3. package/.turbo/turbo-test.log +16 -0
  4. package/.turbo/turbo-typecheck.log +4 -0
  5. package/CHANGELOG.md +18 -0
  6. package/dist/{chunk-EARDCOC4.mjs → chunk-SK2GZ7XR.mjs} +30 -7
  7. package/dist/client/index.d.mts +1 -0
  8. package/dist/client/index.d.ts +1 -0
  9. package/dist/client/index.js +70 -0
  10. package/dist/client/index.mjs +6 -0
  11. package/dist/server/index.d.mts +13 -0
  12. package/dist/server/index.d.ts +13 -0
  13. package/dist/{react-native.js → server/index.js} +38 -47
  14. package/dist/server/index.mjs +31 -0
  15. package/dist/shared/index.d.mts +29 -0
  16. package/dist/shared/index.d.ts +29 -0
  17. package/dist/{node.js → shared/index.js} +31 -46
  18. package/dist/shared/index.mjs +16 -0
  19. package/package.json +34 -18
  20. package/src/client/index.test.ts +18 -0
  21. package/src/client/index.ts +2 -0
  22. package/src/server/index.test.ts +40 -0
  23. package/src/server/index.ts +26 -0
  24. package/src/shared/index.test.ts +37 -0
  25. package/src/shared/index.ts +9 -0
  26. package/src/shared/types.ts +78 -0
  27. package/tsconfig.json +2 -1
  28. package/dist/browser.d.mts +0 -10
  29. package/dist/browser.d.ts +0 -10
  30. package/dist/browser.js +0 -115
  31. package/dist/browser.mjs +0 -40
  32. package/dist/node.d.mts +0 -10
  33. package/dist/node.d.ts +0 -10
  34. package/dist/node.mjs +0 -40
  35. package/dist/react-native.d.mts +0 -13
  36. package/dist/react-native.d.ts +0 -13
  37. package/dist/react-native.mjs +0 -40
  38. package/dist/shared-DXFP3J32.d.mts +0 -20
  39. package/dist/shared-DXFP3J32.d.ts +0 -20
  40. package/src/browser.ts +0 -31
  41. package/src/node.ts +0 -31
  42. package/src/react-native.ts +0 -28
  43. package/src/shared.ts +0 -49
package/dist/node.mjs DELETED
@@ -1,40 +0,0 @@
1
- import {
2
- AppError,
3
- AuthRequiredError,
4
- PermissionDeniedError,
5
- TenantRequiredError,
6
- ValidationError
7
- } from "./chunk-EARDCOC4.mjs";
8
-
9
- // src/node.ts
10
- import * as Sentry from "@sentry/node";
11
- function captureError(err, context) {
12
- if (err instanceof AppError) {
13
- console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
14
- if (err.statusCode >= 500) {
15
- Sentry.captureException(err, { extra: { ...err.context, ...context } });
16
- }
17
- } else {
18
- console.error("Unexpected error:", err);
19
- Sentry.captureException(err, { extra: context });
20
- }
21
- }
22
- function setUserContext(user) {
23
- Sentry.setUser(user);
24
- }
25
- function initErrors(dsn) {
26
- Sentry.init({
27
- dsn,
28
- tracesSampleRate: 1
29
- });
30
- }
31
- export {
32
- AppError,
33
- AuthRequiredError,
34
- PermissionDeniedError,
35
- TenantRequiredError,
36
- ValidationError,
37
- captureError,
38
- initErrors,
39
- setUserContext
40
- };
@@ -1,13 +0,0 @@
1
- export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.mjs';
2
-
3
- declare function initErrors(config: {
4
- dsn: string;
5
- environment?: string;
6
- }): void;
7
- declare function setUserContext(user: {
8
- id: string;
9
- email?: string;
10
- } | null): void;
11
- declare function captureError(err: unknown, context?: Record<string, any>): void;
12
-
13
- export { captureError, initErrors, setUserContext };
@@ -1,13 +0,0 @@
1
- export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.js';
2
-
3
- declare function initErrors(config: {
4
- dsn: string;
5
- environment?: string;
6
- }): void;
7
- declare function setUserContext(user: {
8
- id: string;
9
- email?: string;
10
- } | null): void;
11
- declare function captureError(err: unknown, context?: Record<string, any>): void;
12
-
13
- export { captureError, initErrors, setUserContext };
@@ -1,40 +0,0 @@
1
- import {
2
- AppError,
3
- AuthRequiredError,
4
- PermissionDeniedError,
5
- TenantRequiredError,
6
- ValidationError
7
- } from "./chunk-EARDCOC4.mjs";
8
-
9
- // src/react-native.ts
10
- import * as Sentry from "@sentry/react-native";
11
- function initErrors(config) {
12
- Sentry.init({
13
- dsn: config.dsn,
14
- environment: config.environment || "production"
15
- });
16
- }
17
- function setUserContext(user) {
18
- Sentry.setUser(user);
19
- }
20
- function captureError(err, context) {
21
- if (err instanceof AppError) {
22
- if (err.statusCode >= 500) {
23
- Sentry.captureException(err, { extra: { ...err.context, ...context } });
24
- } else {
25
- console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
26
- }
27
- } else {
28
- Sentry.captureException(err, { extra: context });
29
- }
30
- }
31
- export {
32
- AppError,
33
- AuthRequiredError,
34
- PermissionDeniedError,
35
- TenantRequiredError,
36
- ValidationError,
37
- captureError,
38
- initErrors,
39
- setUserContext
40
- };
@@ -1,20 +0,0 @@
1
- declare class AppError extends Error {
2
- readonly code: string;
3
- readonly statusCode: number;
4
- readonly context?: Record<string, any>;
5
- constructor(message: string, code: string, statusCode?: number, context?: Record<string, any>);
6
- }
7
- declare class AuthRequiredError extends AppError {
8
- constructor(message?: string, context?: Record<string, any>);
9
- }
10
- declare class TenantRequiredError extends AppError {
11
- constructor(message?: string, context?: Record<string, any>);
12
- }
13
- declare class PermissionDeniedError extends AppError {
14
- constructor(message?: string, context?: Record<string, any>);
15
- }
16
- declare class ValidationError extends AppError {
17
- constructor(message: string, context?: Record<string, any>);
18
- }
19
-
20
- export { AppError as A, PermissionDeniedError as P, TenantRequiredError as T, ValidationError as V, AuthRequiredError as a };
@@ -1,20 +0,0 @@
1
- declare class AppError extends Error {
2
- readonly code: string;
3
- readonly statusCode: number;
4
- readonly context?: Record<string, any>;
5
- constructor(message: string, code: string, statusCode?: number, context?: Record<string, any>);
6
- }
7
- declare class AuthRequiredError extends AppError {
8
- constructor(message?: string, context?: Record<string, any>);
9
- }
10
- declare class TenantRequiredError extends AppError {
11
- constructor(message?: string, context?: Record<string, any>);
12
- }
13
- declare class PermissionDeniedError extends AppError {
14
- constructor(message?: string, context?: Record<string, any>);
15
- }
16
- declare class ValidationError extends AppError {
17
- constructor(message: string, context?: Record<string, any>);
18
- }
19
-
20
- export { AppError as A, PermissionDeniedError as P, TenantRequiredError as T, ValidationError as V, AuthRequiredError as a };
package/src/browser.ts DELETED
@@ -1,31 +0,0 @@
1
- import * as Sentry from '@sentry/browser';
2
- import { AppError } from './shared';
3
-
4
- export * from './shared';
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- export function captureError(err: unknown, context?: Record<string, any>) {
8
- if (err instanceof AppError) {
9
- // Basic logging for expected app errors
10
- console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
11
- // Still capture if it's 500 or critical? Maybe optional.
12
- if (err.statusCode >= 500) {
13
- Sentry.captureException(err, { extra: { ...err.context, ...context } });
14
- }
15
- } else {
16
- // Unexpected errors
17
- console.error('Unexpected error:', err);
18
- Sentry.captureException(err, { extra: context });
19
- }
20
- }
21
-
22
- export function setUserContext(user: { id: string; email?: string } | null) {
23
- Sentry.setUser(user);
24
- }
25
-
26
- export function initErrors(dsn: string) {
27
- Sentry.init({
28
- dsn,
29
- tracesSampleRate: 1.0,
30
- });
31
- }
package/src/node.ts DELETED
@@ -1,31 +0,0 @@
1
- import * as Sentry from '@sentry/node';
2
- import { AppError } from './shared';
3
-
4
- export * from './shared';
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- export function captureError(err: unknown, context?: Record<string, any>) {
8
- if (err instanceof AppError) {
9
- // Basic logging for expected app errors
10
- console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
11
- // Still capture if it's 500 or critical? Maybe optional.
12
- if (err.statusCode >= 500) {
13
- Sentry.captureException(err, { extra: { ...err.context, ...context } });
14
- }
15
- } else {
16
- // Unexpected errors
17
- console.error('Unexpected error:', err);
18
- Sentry.captureException(err, { extra: context });
19
- }
20
- }
21
-
22
- export function setUserContext(user: { id: string; email?: string } | null) {
23
- Sentry.setUser(user);
24
- }
25
-
26
- export function initErrors(dsn: string) {
27
- Sentry.init({
28
- dsn,
29
- tracesSampleRate: 1.0,
30
- });
31
- }
@@ -1,28 +0,0 @@
1
- import * as Sentry from '@sentry/react-native';
2
- import { AppError } from './shared';
3
-
4
- export * from './shared';
5
-
6
- export function initErrors(config: { dsn: string; environment?: string }) {
7
- Sentry.init({
8
- dsn: config.dsn,
9
- environment: config.environment || 'production',
10
- });
11
- }
12
-
13
- export function setUserContext(user: { id: string; email?: string } | null) {
14
- Sentry.setUser(user);
15
- }
16
-
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- export function captureError(err: unknown, context?: Record<string, any>) {
19
- if (err instanceof AppError) {
20
- if (err.statusCode >= 500) {
21
- Sentry.captureException(err, { extra: { ...err.context, ...context } });
22
- } else {
23
- console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
24
- }
25
- } else {
26
- Sentry.captureException(err, { extra: context });
27
- }
28
- }
package/src/shared.ts DELETED
@@ -1,49 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
- export class AppError extends Error {
3
- public readonly code: string;
4
- public readonly statusCode: number;
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- public readonly context?: Record<string, any>;
7
-
8
- constructor(
9
- message: string,
10
- code: string,
11
- statusCode: number = 500,
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
- context?: Record<string, any>,
14
- ) {
15
- super(message);
16
- this.name = 'AppError';
17
- this.code = code;
18
- this.statusCode = statusCode;
19
- this.context = context;
20
- }
21
- }
22
-
23
- export class AuthRequiredError extends AppError {
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- constructor(message = 'Authentication required', context?: Record<string, any>) {
26
- super(message, 'AUTH_REQUIRED', 401, context);
27
- }
28
- }
29
-
30
- export class TenantRequiredError extends AppError {
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- constructor(message = 'Tenant context required', context?: Record<string, any>) {
33
- super(message, 'TENANT_REQUIRED', 400, context);
34
- }
35
- }
36
-
37
- export class PermissionDeniedError extends AppError {
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- constructor(message = 'Permission denied', context?: Record<string, any>) {
40
- super(message, 'PERMISSION_DENIED', 403, context);
41
- }
42
- }
43
-
44
- export class ValidationError extends AppError {
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- constructor(message: string, context?: Record<string, any>) {
47
- super(message, 'VALIDATION_ERROR', 400, context);
48
- }
49
- }