import {z} from 'zod' export type GetApiV2EntityTypeFieldsIdArgs = {id: string}; export type GetApiV2EntityTypeFieldsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svstoreEntityTypeFieldDataType = z.enum(["DATA_TYPE_UNSPECIFIED", "TEXT", "NUMBER", "BOOL", "TIMESTAMP", "ENUM", "ENTITY_REF", "USER_REF", "UNIQUE", "MULTI_SELECT", "FILE"]); export const googleProtobufTimestamp = z.string(); export const svstoreEnumOption = z.object({id: z.string().optional(), value: z.string().optional(), displayName: z.string().optional(), displayOrder: z.number().int().optional()}); export const svstoreEntityTypeField = z.object({id: z.string().optional(), entityTypeId: z.string().optional(), key: z.string().optional(), name: z.string().optional(), dataType: svstoreEntityTypeFieldDataType.optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), createdByUserId: z.string().optional(), updatedByUserId: z.string().optional(), enumOptions: z.array(svstoreEnumOption).optional(), isKeyField: z.boolean().optional(), isNameField: z.boolean().optional(), refEntityTypeId: z.string().nullable().optional(), description: z.string().nullable().optional(), sourceEntityTypeId: z.string().nullable().optional(), sectionId: z.string().nullable().optional()}); export const svstorePublicapiGetEntityTypeFieldResponse = z.object({data: svstoreEntityTypeField.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 }; /** * Get Entity Type Field * * GET /v2/entity-type-fields/{id} */ export const getApiV2EntityTypeFieldsId = async (args: GetApiV2EntityTypeFieldsIdArgs, options?: GetApiV2EntityTypeFieldsIdOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/entity-type-fields/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(svstorePublicapiGetEntityTypeFieldResponse, await res.json()) };