import {z} from 'zod' export type IFaq = {question: string, answer: string, isCustom: boolean, index: number}; export type IWarehouseInfoUpdate = {id: string, name: string, editStatus: string, description?: string | undefined, address?: Record | undefined, contact?: Record | undefined, videoUrl?: string | undefined, videoDescription?: string | undefined, images?: Array> | undefined, capabilities?: Array | undefined, hoursOfOperation?: Record | undefined, storage?: Record | undefined, operations?: Record | undefined, hubspotRowId: string}; export type String = Record; export type IOrgProfileUpdate = {id: string, orgKey: string, status: string, editStatus: string, name: string, website: string, foundedIn: number, joinedExtensivIn: number, logo: string, contact?: Record | undefined, salesforceContactId?: string | undefined, salesforceAccountId: string, hubspotRowId: string, address?: Record | undefined, companySummary?: string | undefined, description?: string | undefined, faqs?: Array | undefined, warehouseInfo?: Array | undefined, expertise?: Array | undefined, lastUpdatedDate?: number | undefined, sortOrder?: number | undefined, preferredRegion?: string | undefined, featured?: boolean | undefined, defaultRecommendation?: boolean | undefined, pagePath?: string | undefined, capabilities?: Array | undefined}; export type UpdateApiOrgprofileOrgKeyArgs = {orgKey: string, body: IOrgProfileUpdate}; export type UpdateApiOrgprofileOrgKeyOptions = {baseUrl?: string | undefined, cognitoJwtAuthorizer?: string | undefined, fetch?: typeof fetch | undefined}; export const iFaq = z.object({question: z.string(), answer: z.string(), isCustom: z.boolean(), index: z.number()}); export const iWarehouseInfoUpdate = z.object({id: z.string(), name: z.string(), editStatus: z.string(), description: z.string().optional(), address: z.object({}).optional(), contact: z.object({}).optional(), videoUrl: z.string().optional(), videoDescription: z.string().optional(), images: z.array(z.object({})).optional(), capabilities: z.array(z.string()).optional(), hoursOfOperation: z.object({}).optional(), storage: z.object({}).optional(), operations: z.object({}).optional(), hubspotRowId: z.string()}); export const string = z.object({}); export const iOrgProfileUpdate = z.object({id: z.string(), orgKey: z.string(), status: z.string(), editStatus: z.string(), name: z.string(), website: z.string(), foundedIn: z.number(), joinedExtensivIn: z.number(), logo: z.string(), contact: z.object({}).optional(), salesforceContactId: z.string().optional(), salesforceAccountId: z.string(), hubspotRowId: z.string(), address: z.object({}).optional(), companySummary: z.string().optional(), description: z.string().optional(), faqs: z.array(iFaq).optional(), warehouseInfo: z.array(iWarehouseInfoUpdate).optional(), expertise: z.array(string).optional(), lastUpdatedDate: z.number().optional(), sortOrder: z.number().optional(), preferredRegion: z.string().optional(), featured: z.boolean().optional(), defaultRecommendation: z.boolean().optional(), pagePath: z.string().optional(), capabilities: z.array(z.string()).optional()}); export const updateApiOrgprofileOrgKeyResponse = z.object({data: iOrgProfileUpdate.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 }; /** * updateOrgProfile * * PUT /orgprofile/{orgKey} */ export const updateApiOrgprofileOrgKey = async (args: UpdateApiOrgprofileOrgKeyArgs, options?: UpdateApiOrgprofileOrgKeyOptions) => { const {baseUrl = "https://api-fm.extensiv.com", fetch: fetchFn = fetch, cognitoJwtAuthorizer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (cognitoJwtAuthorizer !== undefined) headers.set('authorization', `Bearer ${cognitoJwtAuthorizer}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgprofile/${encodeURIComponent(String(args.orgKey))}${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(updateApiOrgprofileOrgKeyResponse, await res.json()) };