@fairmint/canton-node-sdk
Version:
Canton Node SDK
40 lines • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createApiOperation = createApiOperation;
const ApiOperation_1 = require("./ApiOperation");
function createApiOperation(config) {
return class extends ApiOperation_1.ApiOperation {
async execute(params) {
// Validate parameters
const validatedParams = this.validateParams(params, config.paramsSchema);
const url = config.buildUrl(validatedParams, this.getApiUrl(), this.client);
const requestConfig = config.requestConfig ?? {
contentType: 'application/json',
includeBearerToken: true,
};
let response;
if (config.method === 'GET') {
response = await this.makeGetRequest(url, requestConfig);
}
else if (config.method === 'DELETE') {
response = await this.makeDeleteRequest(url, requestConfig);
}
else {
const data = await config.buildRequestData?.(validatedParams, this.client);
if (config.method === 'POST') {
response = await this.makePostRequest(url, data, requestConfig);
}
else {
// config.method === 'PATCH'
response = await this.makePatchRequest(url, data, requestConfig);
}
}
// Transform response if needed
if (config.transformResponse) {
return config.transformResponse(response);
}
return response;
}
};
}
//# sourceMappingURL=ApiOperationFactory.js.map