UNPKG

@sap-ai-sdk/core

Version:

**This package is designed for internal usage and should not be consumed directly.**

44 lines 1.97 kB
import { OpenApiRequestBuilder as CloudSDKOpenApiRequestBuilder } from '@sap-cloud-sdk/openapi'; import { executeRequest } from './http-client.js'; /** * Request builder for OpenAPI requests. * @typeParam ResponseT - Type of the response for the request. */ export class OpenApiRequestBuilder extends CloudSDKOpenApiRequestBuilder { constructor(method, pathPattern, parameters, basePath) { super(method, pathPattern, parameters, basePath); } /** * Execute request and get the response data. Use this to conveniently access the data of a service without technical information about the response. * @param destination - The destination to execute the request against. * @returns A promise resolving to an HttpResponse. */ async executeRaw(destination) { const { url, data, ...rest } = await this.requestConfig(); // TODO: Remove explicit url! once we updated the type in the Cloud SDK, since url is always defined. return executeRequest({ url: url }, data, { ...rest, headers: { ...rest.headers?.requestConfig, ...rest.headers?.custom }, params: { ...rest.params?.requestConfig, ...rest.params?.custom } }, destination); } /** * Execute request and get the response data. Use this to conveniently access the data of a service without technical information about the response. * @param destination - The destination to execute the request against. * @returns A promise resolving to the requested return type. */ async execute(destination) { const response = await this.executeRaw(destination); if ('data' in response) { return response.data; } throw new Error('Could not access response data. Response was not an axios response.'); } } //# sourceMappingURL=openapi-request-builder.js.map