/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { FathomCore } from "../core.js"; import { encodeJSON, encodeSimple } from "../lib/encodings.js"; import * as M from "../lib/matchers.js"; import { compactMap } from "../lib/primitives.js"; import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; import { FathomError } from "../sdk/models/errors/fathomerror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../sdk/models/errors/httpclienterrors.js"; import { ResponseValidationError } from "../sdk/models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../sdk/models/errors/sdkvalidationerror.js"; import * as operations from "../sdk/models/operations/index.js"; import * as shared from "../sdk/models/shared/index.js"; import { APICall, APIPromise } from "../sdk/types/async.js"; import { Result } from "../sdk/types/fp.js"; /** * Request a download * * @remarks * Starts asynchronous generation of a downloadable file for the recording and returns a * `download_id` to poll. Video recordings are generated in the background; audio-only * recordings complete immediately, so the response may already carry `status: completed` * with the file payload. * * Downloads are private to the API client that created them, and their URLs expire * roughly 24 hours after generation - request a new download when one expires. * * Downloading requires more access than viewing: the recording's owner, teammates who * can view the recording, and people it was shared with at standard or admin level can * download it. Limited-access shares receive `403 Forbidden`. * * Receive the result either by polling the download status endpoint, or by sending * `destination_url` - when the download completes, Fathom POSTs the same payload the * status endpoint returns to it, signed like our webhooks. */ export function createRecordingDownload( client: FathomCore, request: operations.CreateRecordingDownloadRequest, options?: RequestOptions, ): APIPromise< Result< shared.RecordingDownload, | FathomError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: FathomCore, request: operations.CreateRecordingDownloadRequest, options?: RequestOptions, ): Promise< [ Result< shared.RecordingDownload, | FathomError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => operations.CreateRecordingDownloadRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = encodeJSON("body", payload.RequestBody, { explode: true }); const pathParams = { recording_id: encodeSimple("recording_id", payload.recording_id, { explode: false, charEncoding: "percent", }), }; const path = pathToFunc("/recordings/{recording_id}/download")(pathParams); const headers = new Headers(compactMap({ "Content-Type": "application/json", Accept: "application/json", })); const securityInput = await extractSecurity(client._options.security); const requestSecurity = resolveGlobalSecurity(securityInput); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "createRecordingDownload", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: client._options.security, retryConfig: options?.retries || client._options.retryConfig || { strategy: "backoff", backoff: { initialInterval: 500, maxInterval: 60000, exponent: 1.5, maxElapsedTime: 300000, }, retryConnectionErrors: true, } || { strategy: "none" }, retryCodes: options?.retryCodes || ["429"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "POST", baseURL: options?.serverURL, path: path, headers: headers, body: body, userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return [requestRes, { status: "invalid" }]; } const req = requestRes.value; const doResult = await client._do(req, { context, errorCodes: ["401", "403", "404", "422", "429", "4XX", "5XX"], retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return [doResult, { status: "request-error", request: req }]; } const response = doResult.value; const [result] = await M.match< shared.RecordingDownload, | FathomError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(202, shared.RecordingDownload$inboundSchema), M.fail([401, 403, 404, 422, 429, "4XX"]), M.fail("5XX"), )(response, req); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } return [result, { status: "complete", request: req, response }]; }