import {z} from 'zod' export type AttachmentType = 'COMPANY_BANNER' | 'COMPANY_LOGO'; export type AttachmentInput = {fileName?: string | undefined, attachmentType?: AttachmentType | undefined, fileUrl?: string | undefined}; export type PatchBrandRequest = {displayName?: string | undefined, legalCompanyName?: string | undefined, dba?: string | undefined, entityType?: ('CORPORATION' | 'LLC' | 'PARTNERSHIP' | 'S_CORPORATION') | undefined, verticalType?: ('PROFESSIONAL' | 'REAL_ESTATE' | 'HEALTHCARE' | 'HUMAN_RESOURCES' | 'ENERGY' | 'ENTERTAINMENT' | 'RETAIL' | 'TRANSPORTATION' | 'AGRICULTURE' | 'INSURANCE' | 'POSTAL' | 'EDUCATION' | 'HOSPITALITY' | 'FINANCIAL' | 'POLITICAL' | 'GAMBLING' | 'LEGAL' | 'CONSTRUCTION' | 'NGO' | 'MANUFACTURING' | 'GOVERNMENT' | 'TECHNOLOGY' | 'COMMUNICATION') | undefined, programType?: ('STANDARD' | 'GOVERNMENT' | 'CHARITY' | 'POLITICAL') | undefined, registrationCountry?: string | undefined, registrationState?: string | undefined, stockMarketSymbol?: string | undefined, exchange?: string | undefined, website?: string | undefined, companyEmail?: string | undefined, estimatedAnnualRevenue?: string | undefined, country?: string | undefined, street?: string | undefined, street2?: string | undefined, city?: string | undefined, state?: string | undefined, stateCode?: string | undefined, zip?: string | undefined, taxCountry?: string | undefined, federalTaxId?: string | undefined, duns?: string | undefined, giin?: string | undefined, lei?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, phoneNumber?: string | undefined, phoneNumberExtension?: string | undefined, mobilePhoneNumber?: string | undefined, contactEmail?: string | undefined, politicalToken?: string | undefined, politicalType?: ('FEDERAL' | 'LOCAL' | 'TRIBAL' | 'STATE' | 'OTHER') | undefined, politicalUrl?: string | undefined, governmentWebsite?: string | undefined, governmentType?: ('FEDERAL' | 'LOCAL' | 'TRIBAL' | 'STATE' | 'OTHER') | undefined, governmentTypeOther?: string | undefined, charitableAccreditation?: string | undefined, scType?: ('VANITY' | 'RANDOM') | undefined, scText?: string | undefined, attachmentInputs?: Array | undefined}; export type PatchApiV1ProjectsProjectIdUsBrandsBrandIdArgs = {projectId: string, brandId: string, body: PatchBrandRequest}; export type PatchApiV1ProjectsProjectIdUsBrandsBrandIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const brandStatus = z.enum(["DRAFT", "ACTIVE", "ARCHIVED"]); export const attachmentType = z.enum(["COMPANY_BANNER", "COMPANY_LOGO"]); export const attachment = z.object({attachmentId: z.string().optional(), fileName: z.string().optional(), attachmentType: attachmentType.optional(), mimeType: z.string().optional(), uploadStatus: z.enum(["COMPLETED", "WAITING", "FAILED"]).optional(), createTime: z.string().optional(), updateTime: z.string().optional()}); export const brandLog = z.object({createTime: z.string().optional(), message: z.string().optional(), brandCurrentState: brandStatus.optional()}); export const channel = z.enum(["RCS", "SHORT_CODE", "TENDLC"]); export const brand = z.object({displayName: z.string(), legalCompanyName: z.string().optional(), dba: z.string().optional(), entityType: z.enum(["CORPORATION", "LLC", "PARTNERSHIP", "S_CORPORATION"]).optional(), verticalType: z.enum(["PROFESSIONAL", "REAL_ESTATE", "HEALTHCARE", "HUMAN_RESOURCES", "ENERGY", "ENTERTAINMENT", "RETAIL", "TRANSPORTATION", "AGRICULTURE", "INSURANCE", "POSTAL", "EDUCATION", "HOSPITALITY", "FINANCIAL", "POLITICAL", "GAMBLING", "LEGAL", "CONSTRUCTION", "NGO", "MANUFACTURING", "GOVERNMENT", "TECHNOLOGY", "COMMUNICATION"]).optional(), programType: z.enum(["STANDARD", "GOVERNMENT", "CHARITY", "POLITICAL"]).optional(), registrationCountry: z.string().optional(), registrationState: z.string().optional(), stockMarketSymbol: z.string().optional(), exchange: z.string().optional(), website: z.string().optional(), companyEmail: z.string().optional(), estimatedAnnualRevenue: z.string().optional(), country: z.string().optional(), street: z.string().optional(), street2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), stateCode: z.string().optional(), zip: z.string().optional(), taxCountry: z.string().optional(), federalTaxId: z.string().optional(), duns: z.string().optional(), giin: z.string().optional(), lei: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), phoneNumber: z.string().optional(), phoneNumberExtension: z.string().optional(), mobilePhoneNumber: z.string().optional(), contactEmail: z.string().optional(), politicalToken: z.string().optional(), politicalType: z.enum(["FEDERAL", "LOCAL", "TRIBAL", "STATE", "OTHER"]).optional(), politicalUrl: z.string().optional(), governmentWebsite: z.string().optional(), governmentType: z.enum(["FEDERAL", "LOCAL", "TRIBAL", "STATE", "OTHER"]).optional(), governmentTypeOther: z.string().optional(), charitableAccreditation: z.string().optional(), scType: z.enum(["VANITY", "RANDOM"]).optional(), scText: z.string().optional(), brandId: z.string(), status: brandStatus, contentProvider: z.boolean(), attachments: z.array(attachment).optional(), logs: z.array(brandLog).optional(), channels: z.array(channel).optional(), createTime: z.string(), updateTime: z.string()}); 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 }; /** * Patches an existing Brand in US with the request data. * * PATCH /v1/projects/{projectId}/us/brands/{brandId} */ export const patchApiV1ProjectsProjectIdUsBrandsBrandId = async (args: PatchApiV1ProjectsProjectIdUsBrandsBrandIdArgs, options?: PatchApiV1ProjectsProjectIdUsBrandsBrandIdOptions) => { const {baseUrl = "https://compliance.api.sinch.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/us/brands/${encodeURIComponent(String(args.brandId))}${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(brand, await res.json()) };