@carecard/common-util 2.0.2 → 3.0.3

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 (2) hide show
  1. package/index.d.ts +72 -0
  2. package/package.json +9 -3
package/index.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Utility functions for object manipulation.
3
+ */
4
+ export const util: {
5
+ /**
6
+ * Creates a new object containing only the specified properties from the source object.
7
+ * @param obj - The source object.
8
+ * @param arrayOfProperties - An array of property names to extract.
9
+ * @returns A new object with the extracted properties.
10
+ */
11
+ extractObjectWithProperties: (obj: any, arrayOfProperties: string[]) => Record<string, any>;
12
+ };
13
+
14
+ /**
15
+ * Application-level error handlers and throwers.
16
+ */
17
+ export const error: {
18
+ /** Throws an Account_Suspended error. */
19
+ throwAccountSuspendedError: (userMessage?: string, details?: any) => never;
20
+ /** Throws an Account_Blocked error. */
21
+ throwAccountBlockedError: (userMessage?: string, details?: any) => never;
22
+ /** Throws an Account_Inactive error. */
23
+ throwAccountInactiveError: (userMessage?: string, details?: any) => never;
24
+ /** Middleware to handle 404 Not Found. */
25
+ notFound404: (req: any, res: any, next: any) => void;
26
+ /** Central application error handler middleware. */
27
+ appErrorHandler: (err: any, req: any, res: any, next: any) => void;
28
+ /** Throws a Validation_Failure error. */
29
+ throwValidationFailureError: (userMessage?: string, details?: any) => never;
30
+ /** Throws a Record_Exist error. */
31
+ throwRecordExistError: (userMessage?: string, details?: any) => never;
32
+ /** Throws a Wrong_Credentials error. */
33
+ throwWrongCredentialsError: (userMessage?: string, details?: any) => never;
34
+ /** Throws a Login_Required error. */
35
+ throwLoginRequiredError: (userMessage?: string, details?: any) => never;
36
+ /** Throws a Record_NotFound error. */
37
+ throwRecordNotFoundError: (userMessage?: string, details?: any) => never;
38
+ /** Throws a Record_NotSaved error. */
39
+ throwRecordNotSavedError: (userMessage?: string, details?: any) => never;
40
+ /** Throws an Update_Failed error. */
41
+ throwUpdateFailedError: (userMessage?: string, details?: any) => never;
42
+ /** Throws a Transaction_Failed error. */
43
+ throwTransactionFailedError: (userMessage?: string, details?: any) => never;
44
+ /** Throws a Used_Token error. */
45
+ throwUsedTokenError: (userMessage?: string, details?: any) => never;
46
+ /** Throws a Bad_Visitor_Token error. */
47
+ throwBadVisitorTokenError: (userMessage?: string, details?: any) => never;
48
+ /** Throws a File_Format_Not_Supported error. */
49
+ throwFileFormatNotSupportedError: (userMessage?: string, details?: any) => never;
50
+ /** Throws a Not_Authorized error. */
51
+ throwNotAuthorizedError: (userMessage?: string, details?: any) => never;
52
+ /** Throws a Bad_Input error. */
53
+ throwBadInputError: (userMessage?: string, details?: any) => never;
54
+ /** Throws an Input_Not_Uuid error. */
55
+ throwInputNotUuidError: (userMessage?: string, details?: any) => never;
56
+ /** Throws a File_Too_Large error. */
57
+ throwFileTooLargeError: (userMessage?: string, details?: any) => never;
58
+ /** Throws an Invalid_Time_Value error. */
59
+ throwInvalidTimeValueError: (userMessage?: string, details?: any) => never;
60
+ };
61
+
62
+ /**
63
+ * Utility functions for setting HTTP response status codes and headers.
64
+ */
65
+ export const resCode: {
66
+ /** Sets 200 OK status and optionally an ETag header. */
67
+ setOk200: (res: any, ETag?: string) => any;
68
+ /** Sets 201 Created status. */
69
+ setCreated201: (res: any) => any;
70
+ /** Sets 400 Bad Request status. */
71
+ setBadRequest400ClientError: (res: any) => any;
72
+ };
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@carecard/common-util",
3
- "version": "2.0.2",
3
+ "version": "3.0.3",
4
4
  "repository": "https://github.com/CareCard-ca/pkg-common-util",
5
5
  "description": "Common utility for MVC framework",
6
6
  "main": "index.js",
7
+ "types": "index.d.ts",
7
8
  "scripts": {
8
- "test": "export NODE_ENV=test && mocha --watch --recursive"
9
+ "test": "export NODE_ENV=test && mocha --watch --recursive",
10
+ "test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts"
9
11
  },
10
12
  "keywords": [
11
13
  "validate",
@@ -14,8 +16,12 @@
14
16
  "author": "CareCard team",
15
17
  "license": "ISC",
16
18
  "devDependencies": {
19
+ "@types/mocha": "10.0.10",
20
+ "@types/node": "25.5.0",
17
21
  "mocha": "11.7.5",
18
- "supertest": "7.1.4"
22
+ "supertest": "7.1.4",
23
+ "ts-node": "10.9.2",
24
+ "typescript": "5.9.3"
19
25
  },
20
26
  "dependencies": {
21
27
  "express": "5.1.0"