import {z} from 'zod' export type GetApiCmsHubdb202603TablesTableIdOrNameRowsRowIdDraftArgs = {rowId: string, tableIdOrName: string, archived?: boolean | undefined}; export type GetApiCmsHubdb202603TablesTableIdOrNameRowsRowIdDraftOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const hubDbTableRowV3 = z.object({childTableId: z.string(), createdAt: z.string(), id: z.string(), name: z.string(), path: z.string(), publishedAt: z.string(), updatedAt: z.string(), values: z.record(z.string(), z.object({}))}); 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 a row from the draft table * * GET /cms/hubdb/2026-03/tables/{tableIdOrName}/rows/{rowId}/draft * * Also accepts auth: oauth2 */ export const getApiCmsHubdb202603TablesTableIdOrNameRowsRowIdDraft = async (args: GetApiCmsHubdb202603TablesTableIdOrNameRowsRowIdDraftArgs, options?: GetApiCmsHubdb202603TablesTableIdOrNameRowsRowIdDraftOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.archived != null) query.append("archived", String(args.archived)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/cms/hubdb/2026-03/tables/${encodeURIComponent(String(args.tableIdOrName))}/rows/${encodeURIComponent(String(args.rowId))}/draft${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(hubDbTableRowV3, await res.json()) };