import {z} from 'zod' export type SvstoreHelpAgentEntityVisibility = 'HELP_AGENT_ENTITY_VISIBILITY_UNSPECIFIED' | 'HELP_AGENT_ENTITY_VISIBILITY_NONE' | 'HELP_AGENT_ENTITY_VISIBILITY_REQUESTER_ASSOCIATED' | 'HELP_AGENT_ENTITY_VISIBILITY_ALWAYS'; export type UpdateApiV2EntityTypesIdArgs = {id: string, body: {name?: string | undefined, color?: (string | null) | undefined, iconSlug?: (string | null) | undefined, helpAgentVisibility?: SvstoreHelpAgentEntityVisibility | undefined}}; export type UpdateApiV2EntityTypesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const googleProtobufTimestamp = z.string(); export const svstoreHelpAgentEntityVisibility = z.enum(["HELP_AGENT_ENTITY_VISIBILITY_UNSPECIFIED", "HELP_AGENT_ENTITY_VISIBILITY_NONE", "HELP_AGENT_ENTITY_VISIBILITY_REQUESTER_ASSOCIATED", "HELP_AGENT_ENTITY_VISIBILITY_ALWAYS"]); export const svstoreEntityType = z.object({id: z.string().optional(), teamId: z.string().optional(), key: z.string().optional(), name: z.string().optional(), parentEntityTypeId: z.string().nullable().optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), createdByUserId: z.string().optional(), updatedByUserId: z.string().optional(), color: z.string().nullable().optional(), iconSlug: z.string().optional(), entitySchemaId: z.string().optional(), helpAgentVisibility: svstoreHelpAgentEntityVisibility.optional(), isEdgeType: z.boolean().optional(), description: z.string().nullable().optional()}); export const svstorePublicapiUpdateEntityTypeResponse = z.object({data: svstoreEntityType.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 }; /** * Update Entity Type * * PUT /v2/entity-types/{id} */ export const updateApiV2EntityTypesId = async (args: UpdateApiV2EntityTypesIdArgs, options?: UpdateApiV2EntityTypesIdOptions) => { 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-types/${encodeURIComponent(String(args.id))}${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(svstorePublicapiUpdateEntityTypeResponse, await res.json()) };