import {z} from 'zod' export type IOrgProfileFilter = {status?: Array | undefined, region?: Array | undefined, expertise?: Array | undefined, featured?: boolean | undefined, defaultRecommendation?: boolean | undefined, certifications?: Array | undefined, capabilities?: Array | undefined, warehouseSize?: number | undefined, numberOfPallets?: number | undefined, includeDefaultPartners?: boolean | undefined}; export type UpdateApiOrgprofileArgs = {body: IOrgProfileFilter}; export type UpdateApiOrgprofileOptions = {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 iWarehouseInfo = 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().optional()}); export const string = z.object({}); export const iOrgProfile = 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().optional(), logo: z.string(), contact: z.object({}).optional(), salesforceContactId: z.string().optional(), salesforceAccountId: z.string().optional(), hubspotRowId: z.string().optional(), address: z.object({}).optional(), companySummary: z.string().optional(), description: z.string().optional(), faqs: z.array(iFaq).optional(), warehouseInfo: z.array(iWarehouseInfo).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 updateApiOrgprofileResponse = z.object({data: z.array(iOrgProfile).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 }; /** * getFilteredOrgProfileList * * PUT /orgprofile/ */ export const updateApiOrgprofile = async (args: UpdateApiOrgprofileArgs, options?: UpdateApiOrgprofileOptions) => { 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/${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(updateApiOrgprofileResponse, await res.json()) };