import {z} from 'zod' export type BusinessesEnrichRequest = {request_context?: (Record | null) | undefined, parameters?: (Record | null) | undefined, business_id: string}; export type CreateApiV1BusinessesWorkforceTrendsEnrichArgs = {tenant?: string | undefined, body: BusinessesEnrichRequest}; export type CreateApiV1BusinessesWorkforceTrendsEnrichOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const requestStatus = z.enum(["success", "miss", "failure"]); export const responseContext = z.object({correlation_id: z.string(), request_status: requestStatus, time_took_in_seconds: z.number()}); export const workforceTrendsOutputSchema = z.object({change_in_real_estate_roles: z.number().optional(), perc_design_roles: z.number().optional(), profiles_found_per_quarter: z.number().optional(), perc_sales_roles: z.number().optional(), perc_hr_roles: z.number().optional(), perc_operations_roles: z.number().optional(), perc_pr_roles: z.number().optional(), perc_health_roles: z.number().optional(), perc_trades_roles: z.number().optional(), perc_engineering_roles: z.number().optional(), perc_finance_roles: z.number().optional(), perc_customer_service_roles: z.number().optional(), perc_legal_roles: z.number().optional(), perc_media_roles: z.number().optional(), perc_marketing_roles: z.number().optional(), perc_real_estate_roles: z.number().optional(), perc_education_roles: z.number().optional(), change_in_design_roles: z.number().optional(), change_in_education_roles: z.number().optional(), change_in_pr_roles: z.number().optional(), change_in_trades_roles: z.number().optional(), change_in_customer_service_roles: z.number().optional(), change_in_health_roles: z.number().optional(), change_in_operations_roles: z.number().optional(), change_in_sales_roles: z.number().optional(), change_in_legal_roles: z.number().optional(), change_in_roles_divisor: z.number().optional(), change_in_finance_roles: z.number().optional(), change_in_media_roles: z.number().optional(), change_in_hr_roles: z.number().optional(), change_in_marketing_roles: z.number().optional(), change_in_engineering_roles: z.number().optional(), quarters: z.string().optional()}); export const businessesEnrichResponseWorkforceTrendsOutputSchema = z.object({response_context: responseContext, data: z.union([workforceTrendsOutputSchema, z.array(workforceTrendsOutputSchema)]).optional(), entity_id: z.union([z.string(), z.string()]).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 }; /** * Workforce Trends * * POST /v1/businesses/workforce_trends/enrich * * Also accepts auth: APIKeyHeader */ export const createApiV1BusinessesWorkforceTrendsEnrich = async (args: CreateApiV1BusinessesWorkforceTrendsEnrichArgs, options?: CreateApiV1BusinessesWorkforceTrendsEnrichOptions) => { const {baseUrl = "https://api.explorium.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.tenant != null) headers.set("tenant", String(args.tenant)) if (APIKeyHeader !== undefined) headers.set("api_key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/businesses/workforce_trends/enrich${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(businessesEnrichResponseWorkforceTrendsOutputSchema, await res.json()) };