import {z} from 'zod' export type BrandGuideSections = {brand?: ({name: string, description: string, defaultLanguage: string, industry: string | null, geographicFocus: string | null, coverImage: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null}) | undefined, identity?: ({vision: string | null, mission: string | null, purpose: string | null, positioning: string | null, values: Array<{id: string, name: string, description: string}>, keyMessages: Array<{id: string, title: string, message: string}>, audiences: Array<{id: string, name: string, description: string, needs: Array}>}) | undefined, voice?: ({summary: string | null, traits: Array<{id: string, name: string, meaning: string, do: string, avoid: string}>, formality: number | null, sentenceStyle: string | null, examples: Array<{id: string, type: 'sounds_like_us' | 'not_like_us', text: string, explanation: string}>}) | undefined, writing?: ({preferredTerms: Array<{id: string, term: string, note: string}>, avoidTerms: Array<{id: string, term: string, alternative: string, reason: string}>, forbiddenTerms: Array<{id: string, term: string, reason: string}>, namingRules: Array<{id: string, rule: string, example: string}>, formattingRules: Array<{id: string, rule: string, example: string | null}>, prohibitedClaims: Array}) | undefined, visual_identity?: ({colors?: (Array<{id: string, name: string, role: string, description: string | null, usage: string | null, avoid: string | null, values: {hex: string, rgb: Array, cmyk: Array | null, pantone: string | null}, token: {id: string, cssVariable: string} | null}>) | undefined, typography?: ({usage: string | null, families: Array<{id: string, name: string, role: string, fallback: string, description: string | null, usage: string | null, avoid: string | null, source: 'google' | 'adobe' | 'system' | 'self_hosted', cssUrl: string | null, styles: Array<{name: string, weight: number, style: 'normal' | 'italic'}>, files: Array<{fileId: number, name: string, extension: 'woff2' | 'woff' | 'otf' | 'ttf', sizeBytes: number, weight: number, style: 'normal' | 'italic', url: string, weightMax?: (number | null) | undefined, width?: ('ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded') | undefined}>, token: {id: string, cssVariable: string} | null}>}) | undefined, logos?: (Array<{id: string, name: string, role: string, theme: 'light' | 'dark' | 'any', description: string | null, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined}, minSize: {digital: {value: number, unit: 'px' | 'mm', dimension: 'width' | 'height'} | null, print: {value: number, unit: 'px' | 'mm', dimension: 'width' | 'height'} | null}, clearSpace: {value: number | null, unit: 'logo_height' | 'logo_width' | 'element_height' | 'element_width' | 'px' | 'mm', description: string | null, element?: ({name: string | null, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined}, heightRatio: number} | null) | undefined} | null, approvedBackgroundColorIds: Array, rules: Array<{id: string, type: 'do' | 'dont', text: string, asset?: ({fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null) | undefined}>}>) | undefined, icons?: ({summary: string | null, rules: Array<{id: string, type: 'do' | 'dont', text: string, asset?: ({fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null) | undefined}>, items: Array<{id: string, name: string, meaning: string, category: string, style: string | null, keywords: Array, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined}}>}) | undefined, imagery?: ({summary: string | null, keywords: Array, rules: Array<{id: string, type: 'do' | 'dont', text: string, asset?: ({fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null) | undefined}>, goodExamples: Array<{note: string, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined}}>, avoidExamples: Array<{note: string, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined}}>}) | undefined, customSections?: (Array<{id: string, name: string, icon: string | null, summary: string | null, items: Array<{id: string, name: string, role: string | null, description: string | null, specs: Array<{id: string, label: string, value: string}>, asset: {fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null}>, rules: Array<{id: string, type: 'do' | 'dont', text: string, asset?: ({fileId: number, name?: (string | null) | undefined, extension?: (string | null) | undefined, previewUrl?: (string | null) | undefined, cdnUrl?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined} | null) | undefined}>}>) | undefined}) | undefined, rules?: (Array<{id: string, type: 'do' | 'dont' | 'rule', category: string, title: string, description: string}>) | undefined, ai_instructions?: ({systemGuidance: string | null, uncertainty: 'ask' | 'safest_default' | 'return_unknown', uncertaintyNote: string | null, assetSelection: string | null, isBrandIsolated: boolean, brandIsolationNote: string | null, sourceReference: 'never' | 'when_requested' | 'always'}) | undefined}; export type BrandGuideUpdateRequest = {data: {type: 'brand_guides', id: string, attributes: BrandGuideSections}, meta: {section_versions: {[key: string]: number}}}; export type PatchApiBrandGuidesBrandGuideIdArgs = {brand_guide_id: string, body: BrandGuideUpdateRequest}; export type PatchApiBrandGuidesBrandGuideIdOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const brandGuideAttributes = z.object({schema_version: z.string().optional(), governance: z.object({updatedAt: z.string().optional(), updatedBy: z.string().nullable().optional(), sectionVersions: z.record(z.string(), z.number().int().gte(0)).optional()}).optional(), brand: z.object({name: z.string(), description: z.string(), defaultLanguage: z.string(), industry: z.string().nullable(), geographicFocus: z.string().nullable(), coverImage: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable()}).optional(), identity: z.object({vision: z.string().nullable(), mission: z.string().nullable(), purpose: z.string().nullable(), positioning: z.string().nullable(), values: z.array(z.object({id: z.string(), name: z.string(), description: z.string()})), keyMessages: z.array(z.object({id: z.string(), title: z.string(), message: z.string()})), audiences: z.array(z.object({id: z.string(), name: z.string(), description: z.string(), needs: z.array(z.string())}))}).optional(), voice: z.object({summary: z.string().nullable(), traits: z.array(z.object({id: z.string(), name: z.string(), meaning: z.string(), do: z.string(), avoid: z.string()})), formality: z.number().int().nullable(), sentenceStyle: z.string().nullable(), examples: z.array(z.object({id: z.string(), type: z.enum(["sounds_like_us", "not_like_us"]), text: z.string(), explanation: z.string()}))}).optional(), writing: z.object({preferredTerms: z.array(z.object({id: z.string(), term: z.string(), note: z.string()})), avoidTerms: z.array(z.object({id: z.string(), term: z.string(), alternative: z.string(), reason: z.string()})), forbiddenTerms: z.array(z.object({id: z.string(), term: z.string(), reason: z.string()})), namingRules: z.array(z.object({id: z.string(), rule: z.string(), example: z.string()})), formattingRules: z.array(z.object({id: z.string(), rule: z.string(), example: z.string().nullable()})), prohibitedClaims: z.array(z.string())}).optional(), visual_identity: z.object({colors: z.array(z.object({id: z.string(), name: z.string(), role: z.string(), description: z.string().nullable(), usage: z.string().nullable(), avoid: z.string().nullable(), values: z.object({hex: z.string(), rgb: z.array(z.number().int()), cmyk: z.array(z.number().int()).nullable(), pantone: z.string().nullable()}), token: z.object({id: z.string(), cssVariable: z.string()}).nullable()})), typography: z.object({usage: z.string().nullable(), families: z.array(z.object({id: z.string(), name: z.string(), role: z.string(), fallback: z.string(), description: z.string().nullable(), usage: z.string().nullable(), avoid: z.string().nullable(), source: z.enum(["google", "adobe", "system", "self_hosted"]), cssUrl: z.string().nullable(), styles: z.array(z.object({name: z.string(), weight: z.number().int(), style: z.enum(["normal", "italic"])})), files: z.array(z.object({fileId: z.number().int(), name: z.string(), extension: z.enum(["woff2", "woff", "otf", "ttf"]), sizeBytes: z.number().int(), weight: z.number().int(), style: z.enum(["normal", "italic"]), url: z.string(), weightMax: z.number().int().nullable().optional(), width: z.enum(["ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded"]).optional()})), token: z.object({id: z.string(), cssVariable: z.string()}).nullable()}))}), logos: z.array(z.object({id: z.string(), name: z.string(), role: z.string(), theme: z.enum(["light", "dark", "any"]), description: z.string().nullable(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}), minSize: z.object({digital: z.object({value: z.number(), unit: z.enum(["px", "mm"]), dimension: z.enum(["width", "height"])}).nullable(), print: z.object({value: z.number(), unit: z.enum(["px", "mm"]), dimension: z.enum(["width", "height"])}).nullable()}), clearSpace: z.object({value: z.number().nullable(), unit: z.enum(["logo_height", "logo_width", "element_height", "element_width", "px", "mm"]), description: z.string().nullable(), element: z.object({name: z.string().nullable(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}), heightRatio: z.number()}).nullable().optional()}).nullable(), approvedBackgroundColorIds: z.array(z.string()), rules: z.array(z.object({id: z.string(), type: z.enum(["do", "dont"]), text: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable().optional()}))})), icons: z.object({summary: z.string().nullable(), rules: z.array(z.object({id: z.string(), type: z.enum(["do", "dont"]), text: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable().optional()})), items: z.array(z.object({id: z.string(), name: z.string(), meaning: z.string(), category: z.string(), style: z.string().nullable(), keywords: z.array(z.string()), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()})}))}), imagery: z.object({summary: z.string().nullable(), keywords: z.array(z.string()), rules: z.array(z.object({id: z.string(), type: z.enum(["do", "dont"]), text: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable().optional()})), goodExamples: z.array(z.object({note: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()})})), avoidExamples: z.array(z.object({note: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()})}))}), customSections: z.array(z.object({id: z.string(), name: z.string(), icon: z.string().nullable(), summary: z.string().nullable(), items: z.array(z.object({id: z.string(), name: z.string(), role: z.string().nullable(), description: z.string().nullable(), specs: z.array(z.object({id: z.string(), label: z.string(), value: z.string()})), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable()})), rules: z.array(z.object({id: z.string(), type: z.enum(["do", "dont"]), text: z.string(), asset: z.object({fileId: z.number().int(), name: z.string().nullable().optional(), extension: z.string().nullable().optional(), previewUrl: z.string().nullable().optional(), cdnUrl: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional()}).nullable().optional()}))}))}).optional(), rules: z.array(z.object({id: z.string(), type: z.enum(["do", "dont", "rule"]), category: z.string(), title: z.string(), description: z.string()})).optional(), ai_instructions: z.object({systemGuidance: z.string().nullable(), uncertainty: z.enum(["ask", "safest_default", "return_unknown"]), uncertaintyNote: z.string().nullable(), assetSelection: z.string().nullable(), isBrandIsolated: z.boolean(), brandIsolationNote: z.string().nullable(), sourceReference: z.enum(["never", "when_requested", "always"])}).optional(), markdown: z.string().optional()}); export const brandGuide = z.object({id: z.string().optional(), type: z.literal("brand_guides").optional(), attributes: brandGuideAttributes.optional(), links: z.object({self: z.string().optional()}).optional()}); export const brandGuideResponse = z.object({data: brandGuide.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 }; /** * Updates a brand guide * * PATCH /brand-guides/{brand_guide_id} */ export const patchApiBrandGuidesBrandGuideId = async (args: PatchApiBrandGuidesBrandGuideIdArgs, options: PatchApiBrandGuidesBrandGuideIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/brand-guides/${encodeURIComponent(String(args.brand_guide_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(brandGuideResponse, await res.json()) };