import {z} from 'zod' export type SvstorePublicapiInitialFieldMapping = {internalFieldId?: string | undefined, externalFieldPath?: string | undefined}; export type SvstorePublicapiCreateEntityIngestionConfigRequest = {teamId?: string | undefined, appInstanceId?: string | undefined, workflowId?: string | undefined, enabled?: (boolean | null) | undefined, syncDeletions?: (boolean | null) | undefined, internalEntityTypeId?: string | undefined, initialFieldMappings?: Array | undefined, syncIntervalSeconds?: (number | unknown | null) | undefined}; export type CreateApiV2EntityIngestionConfigsArgs = {body: SvstorePublicapiCreateEntityIngestionConfigRequest}; export type CreateApiV2EntityIngestionConfigsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const googleProtobufTimestamp = z.string(); export const svstoreIngestionConfig = z.object({id: z.string().optional(), appInstanceId: z.string().optional(), workflowId: z.string().optional(), enabled: z.boolean().optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), teamId: z.string().optional(), serviceName: z.string().nullable().optional(), workflowName: z.string().nullable().optional(), isWorkflowPublished: z.boolean().optional(), hasIngestionContext: z.boolean().optional(), syncDeletions: z.boolean().optional(), internalEntityTypeId: z.string().optional(), syncIntervalSeconds: z.union([z.number().int(), z.string()]).nullable().optional()}); export const svstorePublicapiCreateEntityIngestionConfigResponse = z.object({data: svstoreIngestionConfig.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 }; /** * Create Entity Ingestion Config * * POST /v2/entity-ingestion-configs */ export const createApiV2EntityIngestionConfigs = async (args: CreateApiV2EntityIngestionConfigsArgs, options?: CreateApiV2EntityIngestionConfigsOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/entity-ingestion-configs${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(svstorePublicapiCreateEntityIngestionConfigResponse, await res.json()) };