@aneuhold/core-ts-api-lib 2.0.13 → 2.1.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/lib/services/DOFunctionService/DOFunctionService.d.ts +4 -2
- package/lib/services/DOFunctionService/DOFunctionService.d.ts.map +1 -1
- package/lib/services/DOFunctionService/DOFunctionService.js +51 -32
- package/lib/services/DOFunctionService/DOFunctionService.js.map +1 -1
- package/lib/services/DOFunctionService/DOFunctionService.ts +74 -30
- package/package.json +12 -12
|
@@ -22,15 +22,17 @@ export default class DOFunctionService {
|
|
|
22
22
|
* A generic method to handle any API request on the backend. This has
|
|
23
23
|
* no use on the frontend.
|
|
24
24
|
*
|
|
25
|
-
* This will take care of returning the error if the handler throws
|
|
25
|
+
* This will take care of returning the error if the handler throws, and
|
|
26
|
+
* managing tracing spans via the registered ITracer.
|
|
26
27
|
* Ideally the handler should not throw though unless something really
|
|
27
28
|
* unexpected happened.
|
|
28
29
|
*
|
|
30
|
+
* @param functionName - The name to use for the root tracing span.
|
|
29
31
|
* @param rawInput - The raw input for the function.
|
|
30
32
|
* @param handler - The handler function to process the input.
|
|
31
33
|
* @returns The raw output of the function call.
|
|
32
34
|
*/
|
|
33
|
-
static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(rawInput: DOFunctionRawInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
|
|
35
|
+
static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(functionName: string, rawInput: DOFunctionRawInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
|
|
34
36
|
/**
|
|
35
37
|
* Deserializes the raw input into a typed input object.
|
|
36
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AACjE,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACH,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAmC;IAE9E;;OAEG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAkC;IAE3E;;OAEG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAkC;IAE3E;;;;;;;;;;;;;OAaG;WACU,gBAAgB,CAC3B,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,EAEhC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;IAyE/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA2B/B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DR } from '@aneuhold/core-ts-lib';
|
|
1
2
|
import { BSON } from 'bson';
|
|
2
3
|
import AuthCheckPassword from './functions/authCheckPassword.js';
|
|
3
4
|
import AuthValidateUser from './functions/authValidateUser.js';
|
|
@@ -22,46 +23,64 @@ export default class DOFunctionService {
|
|
|
22
23
|
* A generic method to handle any API request on the backend. This has
|
|
23
24
|
* no use on the frontend.
|
|
24
25
|
*
|
|
25
|
-
* This will take care of returning the error if the handler throws
|
|
26
|
+
* This will take care of returning the error if the handler throws, and
|
|
27
|
+
* managing tracing spans via the registered ITracer.
|
|
26
28
|
* Ideally the handler should not throw though unless something really
|
|
27
29
|
* unexpected happened.
|
|
28
30
|
*
|
|
31
|
+
* @param functionName - The name to use for the root tracing span.
|
|
29
32
|
* @param rawInput - The raw input for the function.
|
|
30
33
|
* @param handler - The handler function to process the input.
|
|
31
34
|
* @returns The raw output of the function call.
|
|
32
35
|
*/
|
|
33
|
-
static async handleApiRequest(rawInput, handler) {
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
static async handleApiRequest(functionName, rawInput, handler) {
|
|
37
|
+
DR.logger.info(`[DOFunctionService] handleApiRequest called for "${functionName}".`); // Log entry
|
|
38
|
+
DR.logger.info(`[DOFunctionService] Calling DR.tracer.startSpan for "${functionName}"...`); // Log before startSpan
|
|
39
|
+
return DR.tracer.startSpan(functionName, async (span) => {
|
|
40
|
+
DR.logger.info(`[DOFunctionService] Tracer span callback started for "${functionName}".`); // Log span callback start
|
|
41
|
+
const rawOutput = {
|
|
42
|
+
body: '',
|
|
43
|
+
statusCode: 200,
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/octet-stream'
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const defaultOutput = {
|
|
49
|
+
success: false,
|
|
50
|
+
errors: [],
|
|
51
|
+
data: {}
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
DR.logger.info(`[DOFunctionService] Deserializing input for "${functionName}"...`); // Log before deserialize
|
|
55
|
+
const input = this.deserializeInput(rawInput);
|
|
56
|
+
DR.logger.info(`[DOFunctionService] Calling handler function for "${functionName}"...`); // Log before handler
|
|
57
|
+
const output = await handler(input);
|
|
58
|
+
DR.logger.info(`[DOFunctionService] Handler function finished for "${functionName}".`); // Log after handler
|
|
59
|
+
DR.logger.info(`[DOFunctionService] Serializing output for "${functionName}"...`); // Log before serialize
|
|
60
|
+
rawOutput.body = this.serializeOutput(output);
|
|
61
|
+
if (!output.success) {
|
|
62
|
+
DR.logger.failure(`[DOFunctionService] Handler reported failure for "${functionName}". Setting status code 400.`); // Log handler failure
|
|
63
|
+
rawOutput.statusCode = 400;
|
|
64
|
+
span?.setStatus({ code: 2, message: 'handler_error' });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
DR.logger.success(`[DOFunctionService] Handler reported success for "${functionName}". Setting status code 200.`); // Log handler success
|
|
68
|
+
span?.setStatus({ code: 1, message: 'ok' });
|
|
69
|
+
}
|
|
40
70
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
rawOutput.body = this.serializeOutput(output);
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
// Serialize as JSON if something fails to simplify in case the error
|
|
58
|
-
// happened in the normal serialization.
|
|
59
|
-
const error = e;
|
|
60
|
-
defaultOutput.errors.push(JSON.stringify(error, null, 2));
|
|
61
|
-
rawOutput.body = JSON.stringify(defaultOutput);
|
|
62
|
-
rawOutput.headers['Content-Type'] = 'application/json';
|
|
63
|
-
}
|
|
64
|
-
return rawOutput;
|
|
71
|
+
catch (e) {
|
|
72
|
+
DR.logger.error(`[DOFunctionService] Error caught in handleApiRequest for "${functionName}": ${String(e)}`); // Log error
|
|
73
|
+
DR.tracer.captureException(e);
|
|
74
|
+
span?.setStatus({ code: 2, message: 'internal_error' });
|
|
75
|
+
const error = e;
|
|
76
|
+
defaultOutput.errors.push(JSON.stringify(error, null, 2));
|
|
77
|
+
rawOutput.body = JSON.stringify(defaultOutput);
|
|
78
|
+
rawOutput.headers['Content-Type'] = 'application/json';
|
|
79
|
+
rawOutput.statusCode = 500;
|
|
80
|
+
}
|
|
81
|
+
DR.logger.info(`[DOFunctionService] Tracer span callback finished for "${functionName}". Returning rawOutput.`); // Log span callback end
|
|
82
|
+
return rawOutput;
|
|
83
|
+
});
|
|
65
84
|
}
|
|
66
85
|
/**
|
|
67
86
|
* Deserializes the raw input into a typed input object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunctionService.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAQ5B,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AACjE,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACH,MAAM,CAAC,iBAAiB,GAAsB,iBAAiB,CAAC,WAAW,EAAE,CAAC;IAE9E;;OAEG;IACH,MAAM,CAAC,gBAAgB,GAAqB,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAE3E;;OAEG;IACH,MAAM,CAAC,gBAAgB,GAAqB,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAE3E
|
|
1
|
+
{"version":3,"file":"DOFunctionService.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAQ5B,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AACjE,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACH,MAAM,CAAC,iBAAiB,GAAsB,iBA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AU,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DR } from '@aneuhold/core-ts-lib';
|
|
1
2
|
import { BSON } from 'bson';
|
|
2
3
|
import {
|
|
3
4
|
DOFunctionCallOutput,
|
|
@@ -33,10 +34,12 @@ export default class DOFunctionService {
|
|
|
33
34
|
* A generic method to handle any API request on the backend. This has
|
|
34
35
|
* no use on the frontend.
|
|
35
36
|
*
|
|
36
|
-
* This will take care of returning the error if the handler throws
|
|
37
|
+
* This will take care of returning the error if the handler throws, and
|
|
38
|
+
* managing tracing spans via the registered ITracer.
|
|
37
39
|
* Ideally the handler should not throw though unless something really
|
|
38
40
|
* unexpected happened.
|
|
39
41
|
*
|
|
42
|
+
* @param functionName - The name to use for the root tracing span.
|
|
40
43
|
* @param rawInput - The raw input for the function.
|
|
41
44
|
* @param handler - The handler function to process the input.
|
|
42
45
|
* @returns The raw output of the function call.
|
|
@@ -45,39 +48,80 @@ export default class DOFunctionService {
|
|
|
45
48
|
TInput extends DOFunctionInput,
|
|
46
49
|
TOutput extends DOFunctionOutput
|
|
47
50
|
>(
|
|
51
|
+
functionName: string,
|
|
48
52
|
rawInput: DOFunctionRawInput,
|
|
49
53
|
handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>
|
|
50
54
|
): Promise<DOFunctionRawOutput> {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
DR.logger.info(
|
|
56
|
+
`[DOFunctionService] handleApiRequest called for "${functionName}".`
|
|
57
|
+
); // Log entry
|
|
58
|
+
DR.logger.info(
|
|
59
|
+
`[DOFunctionService] Calling DR.tracer.startSpan for "${functionName}"...`
|
|
60
|
+
); // Log before startSpan
|
|
61
|
+
return DR.tracer.startSpan(functionName, async (span) => {
|
|
62
|
+
DR.logger.info(
|
|
63
|
+
`[DOFunctionService] Tracer span callback started for "${functionName}".`
|
|
64
|
+
); // Log span callback start
|
|
65
|
+
const rawOutput: DOFunctionRawOutput = {
|
|
66
|
+
body: '',
|
|
67
|
+
statusCode: 200,
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/octet-stream'
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const defaultOutput: DOFunctionCallOutput<TOutput> = {
|
|
73
|
+
success: false,
|
|
74
|
+
errors: [],
|
|
75
|
+
data: {} as TOutput
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
DR.logger.info(
|
|
80
|
+
`[DOFunctionService] Deserializing input for "${functionName}"...`
|
|
81
|
+
); // Log before deserialize
|
|
82
|
+
const input: TInput = this.deserializeInput(rawInput);
|
|
83
|
+
DR.logger.info(
|
|
84
|
+
`[DOFunctionService] Calling handler function for "${functionName}"...`
|
|
85
|
+
); // Log before handler
|
|
86
|
+
const output = await handler(input);
|
|
87
|
+
DR.logger.info(
|
|
88
|
+
`[DOFunctionService] Handler function finished for "${functionName}".`
|
|
89
|
+
); // Log after handler
|
|
90
|
+
DR.logger.info(
|
|
91
|
+
`[DOFunctionService] Serializing output for "${functionName}"...`
|
|
92
|
+
); // Log before serialize
|
|
93
|
+
rawOutput.body = this.serializeOutput(output);
|
|
94
|
+
|
|
95
|
+
if (!output.success) {
|
|
96
|
+
DR.logger.failure(
|
|
97
|
+
`[DOFunctionService] Handler reported failure for "${functionName}". Setting status code 400.`
|
|
98
|
+
); // Log handler failure
|
|
99
|
+
rawOutput.statusCode = 400;
|
|
100
|
+
span?.setStatus({ code: 2, message: 'handler_error' });
|
|
101
|
+
} else {
|
|
102
|
+
DR.logger.success(
|
|
103
|
+
`[DOFunctionService] Handler reported success for "${functionName}". Setting status code 200.`
|
|
104
|
+
); // Log handler success
|
|
105
|
+
span?.setStatus({ code: 1, message: 'ok' });
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
DR.logger.error(
|
|
109
|
+
`[DOFunctionService] Error caught in handleApiRequest for "${functionName}": ${String(e)}`
|
|
110
|
+
); // Log error
|
|
111
|
+
DR.tracer.captureException(e);
|
|
112
|
+
span?.setStatus({ code: 2, message: 'internal_error' });
|
|
113
|
+
|
|
114
|
+
const error = e as Error;
|
|
115
|
+
defaultOutput.errors.push(JSON.stringify(error, null, 2));
|
|
116
|
+
rawOutput.body = JSON.stringify(defaultOutput);
|
|
117
|
+
rawOutput.headers['Content-Type'] = 'application/json';
|
|
118
|
+
rawOutput.statusCode = 500;
|
|
57
119
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
data: {} as TOutput
|
|
64
|
-
};
|
|
65
|
-
try {
|
|
66
|
-
// Deserialize the input
|
|
67
|
-
const input: TInput = this.deserializeInput(rawInput);
|
|
68
|
-
// Call the handler
|
|
69
|
-
const output = await handler(input);
|
|
70
|
-
// Serialize the output
|
|
71
|
-
rawOutput.body = this.serializeOutput(output);
|
|
72
|
-
} catch (e) {
|
|
73
|
-
// Serialize as JSON if something fails to simplify in case the error
|
|
74
|
-
// happened in the normal serialization.
|
|
75
|
-
const error = e as Error;
|
|
76
|
-
defaultOutput.errors.push(JSON.stringify(error, null, 2));
|
|
77
|
-
rawOutput.body = JSON.stringify(defaultOutput);
|
|
78
|
-
rawOutput.headers['Content-Type'] = 'application/json';
|
|
79
|
-
}
|
|
80
|
-
return rawOutput;
|
|
120
|
+
DR.logger.info(
|
|
121
|
+
`[DOFunctionService] Tracer span callback finished for "${functionName}". Returning rawOutput.`
|
|
122
|
+
); // Log span callback end
|
|
123
|
+
return rawOutput;
|
|
124
|
+
});
|
|
81
125
|
}
|
|
82
126
|
|
|
83
127
|
/**
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@aneuhold/core-ts-api-lib",
|
|
3
3
|
"author": "Anton G. Neuhold Jr.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.1.1",
|
|
6
6
|
"description": "A library for interacting with the backend and defining the backend API for personal projects.",
|
|
7
7
|
"packageManager": "yarn@4.6.0",
|
|
8
8
|
"type": "module",
|
|
@@ -43,20 +43,20 @@
|
|
|
43
43
|
"TypeScript"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@aneuhold/core-ts-db-lib": "^2.0.
|
|
47
|
-
"@aneuhold/core-ts-lib": "^2.0
|
|
46
|
+
"@aneuhold/core-ts-db-lib": "^2.0.26",
|
|
47
|
+
"@aneuhold/core-ts-lib": "^2.1.0",
|
|
48
48
|
"bson": "^6.2.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@aneuhold/eslint-config": "^1.0.
|
|
52
|
-
"@aneuhold/main-scripts": "^2.0.
|
|
53
|
-
"@types/node": "^22.
|
|
54
|
-
"eslint": "^9.
|
|
55
|
-
"jsr": "^0.13.
|
|
56
|
-
"prettier": "^3.
|
|
51
|
+
"@aneuhold/eslint-config": "^1.0.88",
|
|
52
|
+
"@aneuhold/main-scripts": "^2.0.13",
|
|
53
|
+
"@types/node": "^22.15.2",
|
|
54
|
+
"eslint": "^9.25.1",
|
|
55
|
+
"jsr": "^0.13.4",
|
|
56
|
+
"prettier": "^3.5.3",
|
|
57
57
|
"rimraf": "^6.0.1",
|
|
58
|
-
"tsx": "^4.19.
|
|
59
|
-
"typescript": "^5.
|
|
60
|
-
"vitest": "^3.
|
|
58
|
+
"tsx": "^4.19.3",
|
|
59
|
+
"typescript": "^5.8.3",
|
|
60
|
+
"vitest": "^3.1.2"
|
|
61
61
|
}
|
|
62
62
|
}
|