import {z} from 'zod' export type ManagementProjectsBrandingUpdateRequestBody = {brand?: ({name?: string | undefined, privacy_policy_url?: (string | null) | undefined, terms_of_use_url?: (string | null) | undefined, permission_reminder?: string | undefined, website_url?: (string | null) | undefined}) | undefined, address?: ({street?: string | undefined, city?: string | undefined, postal?: (string | null) | undefined, state?: string | undefined, country?: string | undefined}) | undefined, contact?: ({email?: string | undefined, phone?: (string | null) | undefined}) | undefined}; export type UpdateApiManagementV1ProjectsProjectIdBrandingBrandingIdArgs = {body: ManagementProjectsBrandingUpdateRequestBody}; export type UpdateApiManagementV1ProjectsProjectIdBrandingBrandingIdOptions = {baseUrl?: string | undefined, XManagementId?: string | undefined, XManagementToken?: string | undefined, fetch?: typeof fetch | undefined}; export const managementProjectsBrandingUpdateResponseBody = z.object({id: z.string(), brand: z.object({name: z.string(), privacy_policy_url: z.string().nullable(), terms_of_use_url: z.string().nullable(), permission_reminder: z.string(), website_url: z.string().nullable()}), address: z.object({street: z.string(), city: z.string(), postal: z.string().nullable(), state: z.string(), country: z.string()}), contact: z.object({email: z.string(), phone: z.string().nullable()})}); 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 Brand * * PUT /management/v1/projects/{projectId}/branding/{brandingId} */ export const updateApiManagementV1ProjectsProjectIdBrandingBrandingId = async (args: UpdateApiManagementV1ProjectsProjectIdBrandingBrandingIdArgs, options?: UpdateApiManagementV1ProjectsProjectIdBrandingBrandingIdOptions) => { const {baseUrl = "https://api.voucherify.io", fetch: fetchFn = fetch, XManagementId, XManagementToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (XManagementId !== undefined) headers.set("X-Management-Id", XManagementId) if (XManagementToken !== undefined) headers.set("X-Management-Token", XManagementToken) const url = `${baseUrl.replace(/\/+$/, '')}/management/v1/projects/${encodeURIComponent(String(args.projectId))}/branding/${encodeURIComponent(String(args.brandingId))}${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(managementProjectsBrandingUpdateResponseBody, await res.json()) };