@arifwidianto/rpc-agent
Version:
RPC Agent for both client and server, extends more methods easily
66 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const error_service_1 = require("../../services/error.service");
class EchoExtension {
name = "echo";
status = "active";
config = { enabled: true };
metadata = {
name: this.name,
version: "1.0.0",
description: "Simple echo service for testing",
};
methods = {
echo: async (params) => {
if (!this.config.enabled) {
throw error_service_1.ErrorService.serviceUnavailable("Extension is disabled", {
extension: this.name,
status: this.status,
source: "echo-extension",
});
}
if (params === null || typeof params !== "object") {
throw error_service_1.ErrorService.invalidParams("Invalid params: must be an object", undefined, {
receivedType: typeof params,
source: "echo-extension",
});
}
const allowedParams = new Set(["message"]);
const receivedParams = Object.keys(params);
const unknownParams = receivedParams.filter((param) => !allowedParams.has(param));
if (unknownParams.length > 0) {
throw error_service_1.ErrorService.invalidParams(`Invalid params: unknown parameter(s) '${unknownParams.join(", ")}'`, undefined, {
unknownParams,
allowedParams: Array.from(allowedParams),
source: "echo-extension",
});
}
const { message } = params;
if (typeof message !== "string") {
throw error_service_1.ErrorService.invalidParams("Invalid params: message must be a string", undefined, {
receivedType: typeof message,
source: "echo-extension",
});
}
return {
message: `📣: ${message || ""}`,
timestamp: new Date().toISOString(),
};
},
ping: async () => {
if (!this.config.enabled) {
throw error_service_1.ErrorService.serviceUnavailable("Extension is disabled", {
extension: this.name,
status: this.status,
source: "echo-extension",
});
}
return {
pong: true,
timestamp: new Date().toISOString(),
};
},
};
}
exports.default = EchoExtension;
//# sourceMappingURL=index.js.map