@fairmint/canton-node-sdk
Version:
Canton Node SDK
76 lines • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createApiOperation = createApiOperation;
exports.createSimpleApiOperation = createSimpleApiOperation;
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 if (config.method === 'PATCH') {
response = await this.makePatchRequest(url, data, requestConfig);
}
else {
throw new Error(`Unsupported HTTP method: ${config.method}`);
}
}
// Transform response if needed
if (config.transformResponse) {
return config.transformResponse(response);
}
return response;
}
};
}
function createSimpleApiOperation(config) {
return class extends ApiOperation_1.SimpleApiOperation {
async execute(params) {
// Validate parameters
const validatedParams = this.validateParams(params, config.paramsSchema);
const url = config.buildUrl(validatedParams, this.getApiUrl(), this.client);
let response;
if (config.method === 'GET') {
response = await this.makeGetRequest(url);
}
else if (config.method === 'DELETE') {
response = await this.makeDeleteRequest(url);
}
else {
const data = await config.buildRequestData?.(validatedParams, this.client);
if (config.method === 'POST') {
response = await this.makePostRequest(url, data);
}
else if (config.method === 'PATCH') {
response = await this.makePatchRequest(url, data);
}
else {
throw new Error(`Unsupported HTTP method: ${config.method}`);
}
}
// Transform response if needed
if (config.transformResponse) {
return config.transformResponse(response);
}
return response;
}
};
}
//# sourceMappingURL=ApiOperationFactory.js.map