@aneuhold/core-ts-api-lib 2.0.12 → 2.1.0

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.
@@ -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":"AACA,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;;OAE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AAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;IAmD/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,67 @@ 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
- // Default raw output
35
- const rawOutput = {
36
- body: '',
37
- statusCode: 200,
38
- headers: {
39
- 'Content-Type': 'application/octet-stream'
36
+ static async handleApiRequest(functionName, rawInput, handler) {
37
+ return DR.tracer.startSpan(functionName, async (span) => {
38
+ // Default raw output
39
+ const rawOutput = {
40
+ body: '',
41
+ statusCode: 200,
42
+ headers: {
43
+ 'Content-Type': 'application/octet-stream'
44
+ }
45
+ };
46
+ // Default output
47
+ const defaultOutput = {
48
+ success: false,
49
+ errors: [],
50
+ data: {}
51
+ };
52
+ try {
53
+ // Deserialize the input
54
+ const input = this.deserializeInput(rawInput);
55
+ // Call the handler
56
+ const output = await handler(input);
57
+ // Serialize the output
58
+ rawOutput.body = this.serializeOutput(output);
59
+ if (!output.success) {
60
+ rawOutput.statusCode = 400; // Bad Request if handler indicates failure
61
+ span?.setStatus({ code: 2, message: 'handler_error' }); // Indicate error in span
62
+ }
63
+ else {
64
+ span?.setStatus({ code: 1, message: 'ok' }); // OK
65
+ }
40
66
  }
41
- };
42
- // Default output
43
- const defaultOutput = {
44
- success: false,
45
- errors: [],
46
- data: {}
47
- };
48
- try {
49
- // Deserialize the input
50
- const input = this.deserializeInput(rawInput);
51
- // Call the handler
52
- const output = await handler(input);
53
- // Serialize the output
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;
67
+ catch (e) {
68
+ // Capture unexpected errors
69
+ DR.tracer.captureException(e);
70
+ span?.setStatus({ code: 2, message: 'internal_error' }); // Internal Server Error
71
+ // Serialize as JSON if something fails to simplify in case the error
72
+ // happened in the normal serialization.
73
+ const error = e;
74
+ defaultOutput.errors.push(JSON.stringify(error, null, 2));
75
+ rawOutput.body = JSON.stringify(defaultOutput);
76
+ rawOutput.headers['Content-Type'] = 'application/json';
77
+ rawOutput.statusCode = 500;
78
+ }
79
+ finally {
80
+ // Ensure traces are flushed in serverless environments
81
+ if (DR.tracer.isEnabled()) {
82
+ await DR.tracer.flush(2000);
83
+ }
84
+ }
85
+ return rawOutput;
86
+ });
65
87
  }
66
88
  /**
67
89
  * 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;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C,gBAAgB,CAC7B,QAA4B;QAE5B,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEhD,IAAI,WAAmB,CAAC;QACxB,IAAI,eAAe,EAAE,CAAC;YACpB,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;QAED,iDAAiD;QACjD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,KAAK,0BAA0B,CAAC;QACtE,IAAI,WAAmB,CAAC;QACxB,IAAI,MAAM,EAAE,CAAC;YACX,wBAAwB;YACxB,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAW,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAW,CAAC;QACnE,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,eAAe,CAC5B,MAAqC;QAErC,MAAM,UAAU,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,58 @@ 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
- // Default raw output
52
- const rawOutput: DOFunctionRawOutput = {
53
- body: '',
54
- statusCode: 200,
55
- headers: {
56
- 'Content-Type': 'application/octet-stream'
55
+ return DR.tracer.startSpan(functionName, async (span) => {
56
+ // Default raw output
57
+ const rawOutput: DOFunctionRawOutput = {
58
+ body: '',
59
+ statusCode: 200,
60
+ headers: {
61
+ 'Content-Type': 'application/octet-stream'
62
+ }
63
+ };
64
+ // Default output
65
+ const defaultOutput: DOFunctionCallOutput<TOutput> = {
66
+ success: false,
67
+ errors: [],
68
+ data: {} as TOutput
69
+ };
70
+ try {
71
+ // Deserialize the input
72
+ const input: TInput = this.deserializeInput(rawInput);
73
+ // Call the handler
74
+ const output = await handler(input);
75
+ // Serialize the output
76
+ rawOutput.body = this.serializeOutput(output);
77
+ if (!output.success) {
78
+ rawOutput.statusCode = 400; // Bad Request if handler indicates failure
79
+ span?.setStatus({ code: 2, message: 'handler_error' }); // Indicate error in span
80
+ } else {
81
+ span?.setStatus({ code: 1, message: 'ok' }); // OK
82
+ }
83
+ } catch (e) {
84
+ // Capture unexpected errors
85
+ DR.tracer.captureException(e);
86
+ span?.setStatus({ code: 2, message: 'internal_error' }); // Internal Server Error
87
+
88
+ // Serialize as JSON if something fails to simplify in case the error
89
+ // happened in the normal serialization.
90
+ const error = e as Error;
91
+ defaultOutput.errors.push(JSON.stringify(error, null, 2));
92
+ rawOutput.body = JSON.stringify(defaultOutput);
93
+ rawOutput.headers['Content-Type'] = 'application/json';
94
+ rawOutput.statusCode = 500;
95
+ } finally {
96
+ // Ensure traces are flushed in serverless environments
97
+ if (DR.tracer.isEnabled()) {
98
+ await DR.tracer.flush(2000);
99
+ }
57
100
  }
58
- };
59
- // Default output
60
- const defaultOutput: DOFunctionCallOutput<TOutput> = {
61
- success: false,
62
- errors: [],
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;
101
+ return rawOutput;
102
+ });
81
103
  }
82
104
 
83
105
  /**
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.0.12",
5
+ "version": "2.1.0",
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.4",
47
- "@aneuhold/core-ts-lib": "^2.0.6",
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.54",
52
- "@aneuhold/main-scripts": "^2.0.6",
53
- "@types/node": "^20.17.1",
54
- "eslint": "^9.19.0",
55
- "jsr": "^0.13.3",
56
- "prettier": "^3.4.2",
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.2",
59
- "typescript": "^5.6.3",
60
- "vitest": "^2.1.3"
58
+ "tsx": "^4.19.3",
59
+ "typescript": "^5.8.3",
60
+ "vitest": "^3.1.2"
61
61
  }
62
62
  }