@aneuhold/core-ts-api-lib 2.1.1 → 2.1.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.
- package/lib/services/DOFunctionService/DOFunction.d.ts +7 -0
- package/lib/services/DOFunctionService/DOFunction.d.ts.map +1 -1
- package/lib/services/DOFunctionService/DOFunction.js +14 -0
- package/lib/services/DOFunctionService/DOFunction.js.map +1 -1
- package/lib/services/DOFunctionService/DOFunction.ts +19 -0
- package/lib/services/DOFunctionService/DOFunctionService.d.ts +6 -5
- package/lib/services/DOFunctionService/DOFunctionService.d.ts.map +1 -1
- package/lib/services/DOFunctionService/DOFunctionService.js +56 -25
- package/lib/services/DOFunctionService/DOFunctionService.js.map +1 -1
- package/lib/services/DOFunctionService/DOFunctionService.ts +76 -27
- package/package.json +1 -1
|
@@ -69,6 +69,13 @@ export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
|
|
|
69
69
|
errors: string[];
|
|
70
70
|
data: TOutput;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Type guard to check if an input object conforms to the DOFunctionRawInput structure.
|
|
74
|
+
*
|
|
75
|
+
* @param input - The input object to check.
|
|
76
|
+
* @returns True if the input is DOFunctionRawInput, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isDOFunctionRawInput(input: unknown): input is DOFunctionRawInput;
|
|
72
79
|
/**
|
|
73
80
|
* An abstract class representing a Digital Ocean Function.
|
|
74
81
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunction.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE;QACJ;;WAEG;QAC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AAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAiBjE;;;;;OAKG;YACW,cAAc;CAmB7B"}
|
|
1
|
+
{"version":3,"file":"DOFunction.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE;QACJ;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE;YACP,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B;;eAEG;YACH,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;YAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;SACzB,CAAC;QACF;;WAEG;QACH,eAAe,EAAE,OAAO,CAAC;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP;;;;WAIG;QACH,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,gBAAgB;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAS7B;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CACtC,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB;IAEhC;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS;IAIT;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB;;;;;;;;OAQG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAiBjE;;;;;OAKG;YACW,cAAc;CAmB7B"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { BSON } from 'bson';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if an input object conforms to the DOFunctionRawInput structure.
|
|
4
|
+
*
|
|
5
|
+
* @param input - The input object to check.
|
|
6
|
+
* @returns True if the input is DOFunctionRawInput, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function isDOFunctionRawInput(input) {
|
|
9
|
+
return (!!input &&
|
|
10
|
+
typeof input === 'object' &&
|
|
11
|
+
'http' in input &&
|
|
12
|
+
typeof input.http === 'object' &&
|
|
13
|
+
'body' in input.http && // Check for essential http properties
|
|
14
|
+
'isBase64Encoded' in input.http);
|
|
15
|
+
}
|
|
2
16
|
/**
|
|
3
17
|
* An abstract class representing a Digital Ocean Function.
|
|
4
18
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunction.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA8E5B;;;;;GAKG;AACH,MAAM,C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EAAE,YAAY;gBACxB,cAAc,EAAE,0BAA0B;aAC3C;YACD,uEAAuE;YACvE,8FAA8F;YAC9F,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,CAAC,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC1B,QAAkB;QAElB,MAAM,MAAM,GACV,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,0BAA0B,CAAC;QACtE,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAkC,CAAC;QACvE,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAY,CAAC;YAClD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzC,IAAI,EAAE,EAAa;aACpB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -76,6 +76,25 @@ export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
|
|
|
76
76
|
data: TOutput;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Type guard to check if an input object conforms to the DOFunctionRawInput structure.
|
|
81
|
+
*
|
|
82
|
+
* @param input - The input object to check.
|
|
83
|
+
* @returns True if the input is DOFunctionRawInput, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
export function isDOFunctionRawInput(
|
|
86
|
+
input: unknown
|
|
87
|
+
): input is DOFunctionRawInput {
|
|
88
|
+
return (
|
|
89
|
+
!!input &&
|
|
90
|
+
typeof input === 'object' &&
|
|
91
|
+
'http' in input &&
|
|
92
|
+
typeof (input as DOFunctionRawInput).http === 'object' &&
|
|
93
|
+
'body' in (input as DOFunctionRawInput).http && // Check for essential http properties
|
|
94
|
+
'isBase64Encoded' in (input as DOFunctionRawInput).http
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
79
98
|
/**
|
|
80
99
|
* An abstract class representing a Digital Ocean Function.
|
|
81
100
|
*
|
|
@@ -28,16 +28,17 @@ export default class DOFunctionService {
|
|
|
28
28
|
* unexpected happened.
|
|
29
29
|
*
|
|
30
30
|
* @param functionName - The name to use for the root tracing span.
|
|
31
|
-
* @param
|
|
31
|
+
* @param rawInputFromDO - The raw input for the function.
|
|
32
32
|
* @param handler - The handler function to process the input.
|
|
33
33
|
* @returns The raw output of the function call.
|
|
34
34
|
*/
|
|
35
|
-
static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(functionName: string,
|
|
35
|
+
static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(functionName: string, rawInputFromDO: DOFunctionRawInput | TInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
|
|
36
36
|
/**
|
|
37
|
-
* Deserializes the raw input into a typed input object.
|
|
37
|
+
* Deserializes the raw input into a typed input object using type guards.
|
|
38
|
+
* Handles raw HTTP input, the DO UI wrapper, or already deserialized input.
|
|
38
39
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @returns The deserialized input object.
|
|
40
|
+
* @param inputFromDO - The raw input received from the DO environment.
|
|
41
|
+
* @returns The deserialized input object of type TInput.
|
|
41
42
|
*/
|
|
42
43
|
private static deserializeInput;
|
|
43
44
|
/**
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAEpB,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,cAAc,EAAE,kBAAkB,GAAG,MAAM,EAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;IAyE/B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA0E/B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DR } from '@aneuhold/core-ts-lib';
|
|
2
2
|
import { BSON } from 'bson';
|
|
3
|
+
import { isDOFunctionRawInput } from './DOFunction.js';
|
|
3
4
|
import AuthCheckPassword from './functions/authCheckPassword.js';
|
|
4
5
|
import AuthValidateUser from './functions/authValidateUser.js';
|
|
5
6
|
import ProjectDashboard from './functions/projectDashboard.js';
|
|
@@ -29,11 +30,11 @@ export default class DOFunctionService {
|
|
|
29
30
|
* unexpected happened.
|
|
30
31
|
*
|
|
31
32
|
* @param functionName - The name to use for the root tracing span.
|
|
32
|
-
* @param
|
|
33
|
+
* @param rawInputFromDO - The raw input for the function.
|
|
33
34
|
* @param handler - The handler function to process the input.
|
|
34
35
|
* @returns The raw output of the function call.
|
|
35
36
|
*/
|
|
36
|
-
static async handleApiRequest(functionName,
|
|
37
|
+
static async handleApiRequest(functionName, rawInputFromDO, handler) {
|
|
37
38
|
DR.logger.info(`[DOFunctionService] handleApiRequest called for "${functionName}".`); // Log entry
|
|
38
39
|
DR.logger.info(`[DOFunctionService] Calling DR.tracer.startSpan for "${functionName}"...`); // Log before startSpan
|
|
39
40
|
return DR.tracer.startSpan(functionName, async (span) => {
|
|
@@ -52,7 +53,7 @@ export default class DOFunctionService {
|
|
|
52
53
|
};
|
|
53
54
|
try {
|
|
54
55
|
DR.logger.info(`[DOFunctionService] Deserializing input for "${functionName}"...`); // Log before deserialize
|
|
55
|
-
const input = this.deserializeInput(
|
|
56
|
+
const input = this.deserializeInput(rawInputFromDO);
|
|
56
57
|
DR.logger.info(`[DOFunctionService] Calling handler function for "${functionName}"...`); // Log before handler
|
|
57
58
|
const output = await handler(input);
|
|
58
59
|
DR.logger.info(`[DOFunctionService] Handler function finished for "${functionName}".`); // Log after handler
|
|
@@ -83,33 +84,63 @@ export default class DOFunctionService {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
|
-
* Deserializes the raw input into a typed input object.
|
|
87
|
+
* Deserializes the raw input into a typed input object using type guards.
|
|
88
|
+
* Handles raw HTTP input, the DO UI wrapper, or already deserialized input.
|
|
87
89
|
*
|
|
88
|
-
* @param
|
|
89
|
-
* @returns The deserialized input object.
|
|
90
|
+
* @param inputFromDO - The raw input received from the DO environment.
|
|
91
|
+
* @returns The deserialized input object of type TInput.
|
|
90
92
|
*/
|
|
91
|
-
static deserializeInput(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
static deserializeInput(inputFromDO) {
|
|
94
|
+
DR.logger.info(`[DOFunctionService] deserializeInput received: ${JSON.stringify(inputFromDO)}`);
|
|
95
|
+
// 1. Check if it's the standard DOFunctionRawInput (from web: raw)
|
|
96
|
+
if (isDOFunctionRawInput(inputFromDO)) {
|
|
97
|
+
DR.logger.info('[DOFunctionService] Input matches DOFunctionRawInput (via type guard). Proceeding with raw deserialization.');
|
|
98
|
+
const { http } = inputFromDO;
|
|
99
|
+
const { body, isBase64Encoded, headers } = http;
|
|
100
|
+
let decodedBody;
|
|
101
|
+
if (isBase64Encoded) {
|
|
102
|
+
DR.logger.info('[DOFunctionService] Body is base64 encoded, decoding...');
|
|
103
|
+
decodedBody = Buffer.from(body, 'base64');
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
DR.logger.info('[DOFunctionService] Body is not base64 encoded, using utf8.');
|
|
107
|
+
decodedBody = Buffer.from(body, 'utf8');
|
|
108
|
+
}
|
|
109
|
+
const isBson = headers['content-type'] === 'application/octet-stream';
|
|
110
|
+
let requestData;
|
|
111
|
+
if (isBson) {
|
|
112
|
+
DR.logger.info('[DOFunctionService] Deserializing BSON body.');
|
|
113
|
+
try {
|
|
114
|
+
requestData = BSON.deserialize(decodedBody);
|
|
115
|
+
}
|
|
116
|
+
catch (bsonError) {
|
|
117
|
+
DR.logger.error(`[DOFunctionService] BSON deserialization failed: ${String(bsonError)}. Falling back to JSON parse.`);
|
|
118
|
+
try {
|
|
119
|
+
requestData = JSON.parse(decodedBody.toString('utf8'));
|
|
120
|
+
}
|
|
121
|
+
catch (jsonError) {
|
|
122
|
+
DR.logger.error(`[DOFunctionService] JSON fallback parse failed: ${String(jsonError)}`);
|
|
123
|
+
throw new Error('Failed to deserialize input body as BSON or JSON.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
DR.logger.info('[DOFunctionService] Deserializing non-BSON body (assuming JSON).');
|
|
129
|
+
try {
|
|
130
|
+
requestData = JSON.parse(decodedBody.toString('utf8'));
|
|
131
|
+
}
|
|
132
|
+
catch (jsonError) {
|
|
133
|
+
DR.logger.error(`[DOFunctionService] JSON parse failed: ${String(jsonError)}`);
|
|
134
|
+
throw new Error('Failed to deserialize input body as JSON.');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return requestData;
|
|
107
138
|
}
|
|
139
|
+
// 2. Assume it's already the correct TInput type
|
|
108
140
|
else {
|
|
109
|
-
|
|
110
|
-
|
|
141
|
+
DR.logger.info('[DOFunctionService] Input does not match RawInput or DataWrapper. Assuming input is already deserialized TInput.');
|
|
142
|
+
return inputFromDO;
|
|
111
143
|
}
|
|
112
|
-
return requestData;
|
|
113
144
|
}
|
|
114
145
|
/**
|
|
115
146
|
* Serializes the output object into a base64 string. This could be updated
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAC5B,OAAO,EAML,oBAAoB,E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AAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC/D,CAAC;YACH,CAAC;YACD,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,iDAAiD;aAC5C,CAAC;YACJ,EAAE,CAAC,MAAM,CAAC,IAAI,CACZ,kHAAkH,CACnH,CAAC;YACF,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,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"}
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
DOFunctionInput,
|
|
6
6
|
DOFunctionOutput,
|
|
7
7
|
DOFunctionRawInput,
|
|
8
|
-
DOFunctionRawOutput
|
|
8
|
+
DOFunctionRawOutput,
|
|
9
|
+
isDOFunctionRawInput
|
|
9
10
|
} from './DOFunction.js';
|
|
10
11
|
import AuthCheckPassword from './functions/authCheckPassword.js';
|
|
11
12
|
import AuthValidateUser from './functions/authValidateUser.js';
|
|
@@ -40,7 +41,7 @@ export default class DOFunctionService {
|
|
|
40
41
|
* unexpected happened.
|
|
41
42
|
*
|
|
42
43
|
* @param functionName - The name to use for the root tracing span.
|
|
43
|
-
* @param
|
|
44
|
+
* @param rawInputFromDO - The raw input for the function.
|
|
44
45
|
* @param handler - The handler function to process the input.
|
|
45
46
|
* @returns The raw output of the function call.
|
|
46
47
|
*/
|
|
@@ -49,7 +50,7 @@ export default class DOFunctionService {
|
|
|
49
50
|
TOutput extends DOFunctionOutput
|
|
50
51
|
>(
|
|
51
52
|
functionName: string,
|
|
52
|
-
|
|
53
|
+
rawInputFromDO: DOFunctionRawInput | TInput,
|
|
53
54
|
handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>
|
|
54
55
|
): Promise<DOFunctionRawOutput> {
|
|
55
56
|
DR.logger.info(
|
|
@@ -79,7 +80,7 @@ export default class DOFunctionService {
|
|
|
79
80
|
DR.logger.info(
|
|
80
81
|
`[DOFunctionService] Deserializing input for "${functionName}"...`
|
|
81
82
|
); // Log before deserialize
|
|
82
|
-
const input: TInput = this.deserializeInput(
|
|
83
|
+
const input: TInput = this.deserializeInput(rawInputFromDO);
|
|
83
84
|
DR.logger.info(
|
|
84
85
|
`[DOFunctionService] Calling handler function for "${functionName}"...`
|
|
85
86
|
); // Log before handler
|
|
@@ -125,36 +126,84 @@ export default class DOFunctionService {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
|
-
* Deserializes the raw input into a typed input object.
|
|
129
|
+
* Deserializes the raw input into a typed input object using type guards.
|
|
130
|
+
* Handles raw HTTP input, the DO UI wrapper, or already deserialized input.
|
|
129
131
|
*
|
|
130
|
-
* @param
|
|
131
|
-
* @returns The deserialized input object.
|
|
132
|
+
* @param inputFromDO - The raw input received from the DO environment.
|
|
133
|
+
* @returns The deserialized input object of type TInput.
|
|
132
134
|
*/
|
|
133
135
|
private static deserializeInput<TInput extends DOFunctionInput>(
|
|
134
|
-
|
|
136
|
+
inputFromDO: DOFunctionRawInput | TInput
|
|
135
137
|
): TInput {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
DR.logger.info(
|
|
139
|
+
`[DOFunctionService] deserializeInput received: ${JSON.stringify(inputFromDO)}`
|
|
140
|
+
);
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
// 1. Check if it's the standard DOFunctionRawInput (from web: raw)
|
|
143
|
+
if (isDOFunctionRawInput(inputFromDO)) {
|
|
144
|
+
DR.logger.info(
|
|
145
|
+
'[DOFunctionService] Input matches DOFunctionRawInput (via type guard). Proceeding with raw deserialization.'
|
|
146
|
+
);
|
|
147
|
+
const { http } = inputFromDO;
|
|
148
|
+
const { body, isBase64Encoded, headers } = http;
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
let decodedBody: Buffer;
|
|
151
|
+
if (isBase64Encoded) {
|
|
152
|
+
DR.logger.info(
|
|
153
|
+
'[DOFunctionService] Body is base64 encoded, decoding...'
|
|
154
|
+
);
|
|
155
|
+
decodedBody = Buffer.from(body, 'base64');
|
|
156
|
+
} else {
|
|
157
|
+
DR.logger.info(
|
|
158
|
+
'[DOFunctionService] Body is not base64 encoded, using utf8.'
|
|
159
|
+
);
|
|
160
|
+
decodedBody = Buffer.from(body, 'utf8');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const isBson = headers['content-type'] === 'application/octet-stream';
|
|
164
|
+
let requestData: TInput;
|
|
156
165
|
|
|
157
|
-
|
|
166
|
+
if (isBson) {
|
|
167
|
+
DR.logger.info('[DOFunctionService] Deserializing BSON body.');
|
|
168
|
+
try {
|
|
169
|
+
requestData = BSON.deserialize(decodedBody) as TInput;
|
|
170
|
+
} catch (bsonError) {
|
|
171
|
+
DR.logger.error(
|
|
172
|
+
`[DOFunctionService] BSON deserialization failed: ${String(bsonError)}. Falling back to JSON parse.`
|
|
173
|
+
);
|
|
174
|
+
try {
|
|
175
|
+
requestData = JSON.parse(decodedBody.toString('utf8')) as TInput;
|
|
176
|
+
} catch (jsonError) {
|
|
177
|
+
DR.logger.error(
|
|
178
|
+
`[DOFunctionService] JSON fallback parse failed: ${String(jsonError)}`
|
|
179
|
+
);
|
|
180
|
+
throw new Error(
|
|
181
|
+
'Failed to deserialize input body as BSON or JSON.'
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
DR.logger.info(
|
|
187
|
+
'[DOFunctionService] Deserializing non-BSON body (assuming JSON).'
|
|
188
|
+
);
|
|
189
|
+
try {
|
|
190
|
+
requestData = JSON.parse(decodedBody.toString('utf8')) as TInput;
|
|
191
|
+
} catch (jsonError) {
|
|
192
|
+
DR.logger.error(
|
|
193
|
+
`[DOFunctionService] JSON parse failed: ${String(jsonError)}`
|
|
194
|
+
);
|
|
195
|
+
throw new Error('Failed to deserialize input body as JSON.');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return requestData;
|
|
199
|
+
}
|
|
200
|
+
// 2. Assume it's already the correct TInput type
|
|
201
|
+
else {
|
|
202
|
+
DR.logger.info(
|
|
203
|
+
'[DOFunctionService] Input does not match RawInput or DataWrapper. Assuming input is already deserialized TInput.'
|
|
204
|
+
);
|
|
205
|
+
return inputFromDO;
|
|
206
|
+
}
|
|
158
207
|
}
|
|
159
208
|
|
|
160
209
|
/**
|
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.1.
|
|
5
|
+
"version": "2.1.3",
|
|
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",
|