import {z} from 'zod' export type ResourceDescriptorId = string; export type GetApiResourceDescriptorsResourceDescriptorIdFieldsArgs = {resourceDescriptorId: ResourceDescriptorId, page?: number | undefined, size?: number | undefined}; export type GetApiResourceDescriptorsResourceDescriptorIdFieldsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const retentionDeleteAction = z.enum(["DELETE", "ANONYMIZE", "PSEUDONYMIZE", "TOMBSTONE", "REVIEW"]); export const stringMap = z.record(z.string(), z.string()); export const retentionSpec = z.object({purpose: z.string().optional(), legalBasis: z.string().optional(), retentionPeriod: z.string().optional(), deleteAction: retentionDeleteAction.optional(), metadata: stringMap.optional()}); export const fieldDescriptorId = z.string(); export const fieldDescriptor = z.object({fieldPath: z.string(), displayName: z.string().optional(), valueType: z.string(), required: z.boolean().optional(), multiValued: z.boolean().optional(), semanticAttributeId: z.string().optional(), sensitivity: z.string().optional(), retention: retentionSpec.optional(), metadata: stringMap.optional(), fieldDescriptorId: fieldDescriptorId}); export const page = z.object({limit: z.number().int().gte(0), offset: z.number().int().gte(0), page: z.number().int().gte(0), size: z.number().int().gte(0), total: z.number().int().gte(0), totalPages: z.number().int().gte(0), hasMore: z.boolean()}); export const fieldDescriptorPage = z.object({data: z.array(fieldDescriptor), pagination: page}); 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 }; /** * List resource descriptor fields * * GET /resource/descriptors/{resourceDescriptorId}/fields */ export const getApiResourceDescriptorsResourceDescriptorIdFields = async (args: GetApiResourceDescriptorsResourceDescriptorIdFieldsArgs, options?: GetApiResourceDescriptorsResourceDescriptorIdFieldsOptions) => { const {baseUrl = "https://api.example.com/api/connector/v1", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/resource/descriptors/${encodeURIComponent(String(args.resourceDescriptorId))}/fields${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(fieldDescriptorPage, await res.json()) };