import {z} from 'zod' export type CommunityParameters = {name: string, status?: (string | null) | undefined, private?: (boolean | null) | undefined, current_path?: (string | null) | undefined, logo_image_id?: (number | null) | undefined, social_image_id?: (number | null) | undefined, seo_title?: (string | null) | undefined, seo_description?: (string | null) | undefined, seo_indexable?: (boolean | null) | undefined, white_label?: (boolean | null) | undefined, allow_public_signup?: (boolean | null) | undefined, upgrade_url?: (string | null) | undefined, send_membership_email?: (boolean | null) | undefined, send_digest_email?: (boolean | null) | undefined, require_post_approvals?: (boolean | null) | undefined, require_comment_approvals?: (boolean | null) | undefined, anyone_can_invite?: (boolean | null) | undefined, invite_only?: (boolean | null) | undefined, enable_block_list?: (boolean | null) | undefined, notifications?: (string | null) | undefined}; export type CreateApiWorkspacesWorkspaceIdCommunitiesArgs = {workspace_id: string, body: {community?: CommunityParameters | undefined}}; export type CreateApiWorkspacesWorkspaceIdCommunitiesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const communityAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), site_id: z.number().int().optional(), workspace_id: z.number().int().optional(), name: z.string().nullable().optional(), status: z.string().nullable().optional(), private: z.boolean().optional(), current_path: z.string().nullable().optional(), logo_image_id: z.number().int().nullable().optional(), social_image_id: z.number().int().nullable().optional(), seo_title: z.string().nullable().optional(), seo_description: z.string().nullable().optional(), seo_indexable: z.boolean().optional(), white_label: z.boolean().optional(), allow_public_signup: z.boolean().optional(), upgrade_url: z.string().nullable().optional(), send_membership_email: z.boolean().nullable().optional(), send_digest_email: z.boolean().optional(), require_post_approvals: z.boolean().nullable().optional(), require_comment_approvals: z.boolean().nullable().optional(), anyone_can_invite: z.boolean().optional(), invite_only: z.boolean().optional(), enable_block_list: z.boolean().optional(), notifications: 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 }; /** * Create Community * * POST /workspaces/{workspace_id}/communities * * Also accepts auth: OAuth2 */ export const createApiWorkspacesWorkspaceIdCommunities = async (args: CreateApiWorkspacesWorkspaceIdCommunitiesArgs, options?: CreateApiWorkspacesWorkspaceIdCommunitiesOptions) => { 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(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/communities${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(communityAttributes, await res.json()) };