import {z} from 'zod' export type DeleteApiV1VideosIdPublishArgs = {id: string, destination: 'youtube' | 'youtube_shorts' | 'linkedin' | 'x' | 'instagram_post' | 'instagram_reel' | 'instagram_story' | 'facebook_post' | 'facebook_story' | 'facebook_reel', accountId?: string | undefined}; export type DeleteApiV1VideosIdPublishOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publication = z.object({accountId: z.string().nullable(), accountName: z.string().nullable(), captionsError: z.string().nullable(), createdAt: z.string(), destination: z.string(), error: z.string().nullable(), privacy: z.enum(["public", "unlisted", "private", "followers", "friends"]), providerVideoId: z.string().nullable(), scheduledAt: z.string().nullable(), status: z.enum(["queued", "running", "completed", "failed", "cancelled"]), title: z.string(), updatedAt: z.string(), url: z.string().nullable()}); export const publishVideoResponse = z.object({publication: publication}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Cancel a scheduled publish * * DELETE /v1/videos/{id}/publish */ export const deleteApiV1VideosIdPublish = async (args: DeleteApiV1VideosIdPublishArgs, options?: DeleteApiV1VideosIdPublishOptions) => { const {baseUrl = "https://api.tella.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.destination != null) query.append("destination", String(args.destination)) if (args.accountId != null) query.append("accountId", String(args.accountId)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.id))}/publish${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(publishVideoResponse, await res.json()) };