Skip to content

Commit f0e5bfd

Browse files
committed
JSON parse args during Action.Call to adhere to protobuf standard
1 parent a094e2e commit f0e5bfd

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

src/server.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,30 @@ export function getServer(
185185
params: Joi.object().default({}),
186186
});
187187

188+
// Normalise payload coming from protobuf map<string, string>
189+
// to support JSON-encoded complex types for args/params
190+
const rawPayload = (call.request.payload ?? {}) as Record<string, unknown>;
191+
const preparedPayload: Record<string, unknown> = { ...rawPayload };
192+
try {
193+
if (typeof preparedPayload.args === "string") {
194+
preparedPayload.args = JSON.parse(preparedPayload.args as string);
195+
}
196+
if (typeof preparedPayload.params === "string") {
197+
preparedPayload.params = JSON.parse(preparedPayload.params as string);
198+
}
199+
} catch {
200+
return callback(
201+
{
202+
code: grpc.status.INVALID_ARGUMENT,
203+
message:
204+
"ValidationError: Failed to parse JSON for 'args' or 'params'",
205+
},
206+
null,
207+
);
208+
}
209+
188210
const { value: callValue, error: callError } = callSchema.validate(
189-
call.request.payload ?? {},
211+
preparedPayload,
190212
);
191213

192214
if (callError) {
@@ -204,7 +226,7 @@ export function getServer(
204226
const fn = (broker as unknown as Record<string, unknown>)[
205227
callValue.functionName
206228
];
207-
if (typeof fn !== "function") {
229+
if (typeof fn !== "function" || !broker.has[callValue.functionName]) {
208230
return callback(
209231
{
210232
code: grpc.status.INVALID_ARGUMENT,
@@ -776,11 +798,11 @@ export function getServer(
776798
type !== undefined ? type : SubscriptionType.ORDERBOOK;
777799

778800
log.info(
779-
`Request - Subscribe: ${JSON.stringify({
801+
`Request - Subscribe:`, {
780802
cex: request.cex,
781803
symbol: request.symbol,
782804
type: subscriptionType,
783-
})}`,
805+
}
784806
);
785807

786808
// Validate required fields

0 commit comments

Comments
 (0)