/** * Apimatic APILib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, FileWrapper, RequestOptions } from '../core.js'; import { ContentType, contentTypeSchema } from '../models/contentType.js'; import { PortalGenerationAsyncResponse, portalGenerationAsyncResponseSchema, } from '../models/portalGenerationAsyncResponse.js'; import { PortalGenerationStatusResponse, portalGenerationStatusResponseSchema, } from '../models/portalGenerationStatusResponse.js'; import { optional, string } from '../schema.js'; import { BaseController } from './baseController.js'; import { ApiError } from '@apimatic/core'; import { InternalServerErrorResponseError } from '../errors/internalServerErrorResponseError.js'; import { ProblemDetailsError } from '../errors/problemDetailsError.js'; import { UnauthorizedResponseError } from '../errors/unauthorizedResponseError.js'; export class DocsPortalGenerationAsyncController extends BaseController { /** * Create an async On-premise Documentation Portal Generation request by providing a Portal Build * Input * * @param contentType * @param file The input file to the Portal Generator. Must contain the build file. * @param xApiMaticCallbackUrl Optional header containing callback url. This url will be called by * the server once the portal generation completes * @return Response from the API call */ async generateOnPremPortalViaBuildInputAsync( contentType: ContentType, file: FileWrapper, xApiMaticCallbackUrl?: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST', '/portal/v2'); const mapped = req.prepareArgs({ contentType: [contentType, contentTypeSchema], xApiMaticCallbackUrl: [xApiMaticCallbackUrl, optional(string())], }); req.header('Content-Type', mapped.contentType); req.header('X-APIMatic-CallbackUrl', mapped.xApiMaticCallbackUrl); req.formData({ file: file }); req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsJson(portalGenerationAsyncResponseSchema, requestOptions); } /** * Get the status of a portal generation request * * @param id * @return Response from the API call */ async getPortalGenerationStatus( id: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ id: [id, string()] }); req.appendTemplatePath`/portal/v2/${mapped.id}/status`; req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsJson(portalGenerationStatusResponseSchema, requestOptions); } /** * Downloads the portal artifacts. The generated artifacts include: * * * 1. SDKs * * 2. Docs * * 3. API Specification files * * * The endpoint returns a zip file that contains a static Site and can be hosted on any Web Server. * * @param id * @return Response from the API call */ async downloadGeneratedPortal( id: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ id: [id, string()] }); req.appendTemplatePath`/portal/v2/${mapped.id}/download`; req.throwOn(400, ProblemDetailsError, 'Bad Request'); req.throwOn(401, UnauthorizedResponseError, 'Unauthorized'); req.throwOn( 422, ApiError, 'Unprocessable Entity - Contains error.zip for build issues' ); req.throwOn(500, InternalServerErrorResponseError, 'Internal Server Error'); req.authenticate([{ authorization: true }]); return req.callAsStream(requestOptions); } }