@crmy/shared 0.5.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.
- package/package.json +22 -0
- package/src/errors.ts +49 -0
- package/src/index.ts +6 -0
- package/src/schemas.ts +858 -0
- package/src/types.ts +577 -0
- package/tsconfig.json +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crmy/shared",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Shared types, Zod schemas, and validation for CRMy",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^3.23.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0"
|
|
22
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2026 CRMy Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export type ErrorCode =
|
|
5
|
+
| 'VALIDATION_ERROR'
|
|
6
|
+
| 'NOT_FOUND'
|
|
7
|
+
| 'PERMISSION_DENIED'
|
|
8
|
+
| 'QUOTA_EXCEEDED'
|
|
9
|
+
| 'CONFLICT'
|
|
10
|
+
| 'UNAUTHORIZED'
|
|
11
|
+
| 'INTERNAL_ERROR';
|
|
12
|
+
|
|
13
|
+
export class CrmyError extends Error {
|
|
14
|
+
constructor(
|
|
15
|
+
public readonly code: ErrorCode,
|
|
16
|
+
message: string,
|
|
17
|
+
public readonly status: number = 400,
|
|
18
|
+
public readonly details?: Record<string, unknown>,
|
|
19
|
+
) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'CrmyError';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
type: `https://crmy.ai/errors/${this.code.toLowerCase()}`,
|
|
27
|
+
title: this.code.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()),
|
|
28
|
+
status: this.status,
|
|
29
|
+
detail: this.message,
|
|
30
|
+
...this.details,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function notFound(entity: string, id: string): CrmyError {
|
|
36
|
+
return new CrmyError('NOT_FOUND', `${entity} ${id} not found`, 404);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function validationError(message: string, errors?: { field: string; message: string }[]): CrmyError {
|
|
40
|
+
return new CrmyError('VALIDATION_ERROR', message, 422, errors ? { errors } : undefined);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function permissionDenied(message = 'Permission denied'): CrmyError {
|
|
44
|
+
return new CrmyError('PERMISSION_DENIED', message, 403);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function unauthorized(message = 'Unauthorized'): CrmyError {
|
|
48
|
+
return new CrmyError('UNAUTHORIZED', message, 401);
|
|
49
|
+
}
|