import {z} from 'zod' export type CommunitiesSpaceParametersUpdate = {name?: (string | null) | undefined, access?: (number | null) | undefined, current_path?: (string | null) | undefined, emoji?: (string | null) | undefined, card_image_id?: (number | null) | undefined, social_image_id?: (number | null) | undefined, members_can_post?: (boolean | null) | undefined, members_can_invite?: (boolean | null) | undefined, allow_post_titles?: (boolean | null) | undefined, allow_cover_images?: (boolean | null) | undefined, hide_from_featured?: (boolean | null) | undefined, layout_style?: (string | null) | undefined, default_tab?: (string | null) | undefined, default_post_sort?: (string | null) | undefined, default_comment_sort?: (string | null) | undefined, default_member_sort?: (string | null) | undefined, pinned_posts_label?: (string | null) | undefined, seo_title?: (string | null) | undefined, seo_description?: (string | null) | undefined, sort_order?: (number | null) | undefined, always_on?: (boolean | null) | undefined, upgrade_url?: (string | null) | undefined}; export type UpdateApiCommunitiesSpacesIdArgs = {id: string, body: {communities_space?: CommunitiesSpaceParametersUpdate | undefined}}; export type UpdateApiCommunitiesSpacesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const communitiesSpaceAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), space_group_id: z.number().int().optional(), workspace_id: z.number().int().optional(), name: z.string().nullable().optional(), access: z.enum(["is_open", "is_private", "is_secret"]).optional(), current_path: z.string().nullable().optional(), emoji: z.string().nullable().optional(), card_image_id: z.number().int().nullable().optional(), social_image_id: z.number().int().nullable().optional(), members_can_post: z.boolean().optional(), members_can_invite: z.boolean().nullable().optional(), allow_post_titles: z.boolean().nullable().optional(), allow_cover_images: z.boolean().nullable().optional(), hide_from_featured: z.boolean().nullable().optional(), layout_style: z.string().nullable().optional(), default_tab: z.string().nullable().optional(), default_post_sort: z.string().nullable().optional(), default_comment_sort: z.string().nullable().optional(), default_member_sort: z.string().nullable().optional(), pinned_posts_label: z.string().nullable().optional(), seo_title: z.string().nullable().optional(), seo_description: z.string().nullable().optional(), sort_order: z.number().int().nullable().optional(), always_on: z.boolean().nullable().optional(), upgrade_url: z.string().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().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 }; /** * Update Space * * PUT /communities/spaces/{id} * * Also accepts auth: OAuth2 */ export const updateApiCommunitiesSpacesId = async (args: UpdateApiCommunitiesSpacesIdArgs, options?: UpdateApiCommunitiesSpacesIdOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/communities/spaces/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(communitiesSpaceAttributes, await res.json()) };