import {z} from 'zod' export type GetApiIdeasIdArgs = {id: string}; export type GetApiIdeasIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const channelProfile = z.object({id: z.string().optional(), name: z.string().nullable().optional(), detail: z.string().nullable().optional()}); export const asset = z.object({id: z.string().optional(), name: z.string().optional(), url: z.string().optional(), mimetype: z.string().optional(), size: z.number().int().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional(), duration: z.number().nullable().optional()}); export const tikTokPrivacyLevel = z.enum(["PUBLIC_TO_EVERYONE", "FOLLOWER_OF_CREATOR", "MUTUAL_FOLLOW_FRIENDS", "SELF_ONLY"]); export const tikTokContent = z.object({profile: channelProfile.nullable().optional(), copy: z.string().optional(), assets: z.array(asset).optional(), privacyLevel: tikTokPrivacyLevel.optional(), isCommentDisabled: z.boolean().optional(), isDuetDisabled: z.boolean().optional(), isStitchDisabled: z.boolean().optional(), isPromotingBusiness: z.boolean().optional(), isPaidPartnership: z.boolean().optional(), videoCoverTimestampMs: z.number().int().nullable().optional()}).nullable(); export const youTubePrivacyStatus = z.enum(["public", "private", "unlisted"]); export const youTubeShortsContent = z.object({profile: channelProfile.nullable().optional(), title: z.string().nullable().optional(), description: z.string().nullable().optional(), assets: z.array(asset).optional(), privacyStatus: youTubePrivacyStatus.optional(), categoryId: z.string().nullable().optional(), notifySubscribers: z.boolean().optional(), isEmbeddable: z.boolean().optional(), isSelfDeclaredMadeForKids: z.boolean().optional()}).nullable(); export const idea = z.object({id: z.string().optional(), url: z.string().optional(), title: z.string().optional(), channels: z.array(z.string()).optional(), status: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), linkedIn: z.object({profile: channelProfile.nullable().optional(), copy: z.string().optional(), assets: z.array(asset).optional()}).nullable().optional(), x: z.object({profile: channelProfile.nullable().optional(), tweets: z.array(z.object({copy: z.string().optional(), assets: z.array(asset).optional()})).optional()}).nullable().optional(), tikTok: tikTokContent.optional(), youTubeShorts: youTubeShortsContent.optional()}); export const getApiIdeasIdResponse = z.object({idea: idea.optional()}); 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 }; /** * Get idea * * GET /ideas/{id} */ export const getApiIdeasId = async (args: GetApiIdeasIdArgs, options?: GetApiIdeasIdOptions) => { const {baseUrl = "https://app.tryordinal.com/api/v1/company", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ideas/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiIdeasIdResponse, await res.json()) };