import {z} from 'zod' export type IFaq = {question: string, answer: string, isCustom: boolean, index: number}; export type IWarehouseInfo = {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 | undefined}; export type String = Record; export type IOrgProfile = {id: string, orgKey: string, status: string, editStatus: string, name: string, website: string, foundedIn: number, joinedExtensivIn?: number | undefined, logo: string, contact?: Record | undefined, salesforceContactId?: string | undefined, salesforceAccountId?: string | undefined, hubspotRowId?: string | undefined, 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 CreateApiOrgprofileArgs = {body: IOrgProfile}; export type CreateApiOrgprofileOptions = {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 createApiOrgprofileResponse = z.object({data: 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 }; /** * createOrgProfile * * POST /orgprofile/ */ export const createApiOrgprofile = async (args: CreateApiOrgprofileArgs, options?: CreateApiOrgprofileOptions) => { 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: "POST", 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(createApiOrgprofileResponse, await res.json()) };