import {z} from 'zod' export type EditCatalogEntity = {name?: string | undefined, logo?: string | undefined}; export type UpdateApiV2CatalogCatalogSlugItemItemIdArgs = {catalog_slug: string, item_id: string, authorization: string, body: EditCatalogEntity}; export type UpdateApiV2CatalogCatalogSlugItemItemIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const value = z.object({name: z.string(), description: z.string().optional(), color: z.string().optional()}); export const actorType = z.enum(["USER", "TEAM", "ROLE"]); export const accessType = z.enum(["READ", "WRITE", "OWNER", "BLOCKED", "SEARCH"]); export const collaboratorResponse = z.object({id: z.string(), auth_role: z.string().optional(), type: actorType, name: z.string().optional(), email: z.string().optional(), access_modes: z.array(accessType).optional()}); export const servicesAppcatalogTypesTableTableType = z.enum(["TABLE", "TASK"]); export const entityTypeResponse = z.object({slug: z.string(), name: z.string(), is_catalog: z.boolean(), is_hidden: z.boolean()}); export const tableWithRowResponse = z.object({id: z.string(), slug: z.string(), type: servicesAppcatalogTypesTableTableType, page_size: z.number().int(), entity_type: entityTypeResponse, row_id: z.array(z.string()), is_highlighted: z.array(z.boolean()), total: z.number().int(), page: z.number().int()}); export const servicesAppcatalogTypesItemItemType = z.enum(["OBJECTID", "TEXT", "RICHTEXT", "HIGHLIGHTEXT", "DATEDELTA", "DATE", "SINGLESELECT", "BINARY", "MULTISELECT", "PHONE", "EMAIL", "USER", "TEAM", "NUMBER", "FILE", "URL", "CURRENCY", "ACTION", "TABLE", "CATEGORIES", "ENTITYRELATION", "TAGS", "PICKLISTSELECT", "IDENTITY", "IDENTITYLIST", "CLAUSE", "RISKSEVERITY", "DASHBOARD", "TABLE_LOOKUP", "ENTITY_REFERENCE", "CHILD_ENTITY", "DOCUMENT_SUBTYPE"]); export const tableResponse = z.object({id: z.string(), slug: z.string(), type: servicesAppcatalogTypesTableTableType, page_size: z.number().int().optional(), entity_type: entityTypeResponse}); export const servicesAppcatalogModelComputationTypeComputationType = z.enum(["NONE", "FORMULA", "CONDITION", "TABLE_LOOKUP", "AI_PROMPT"]); export const computationArgsResponse = z.object({type: servicesAppcatalogModelComputationTypeComputationType, args: z.object({}).optional()}); export const itemResponse = z.object({id: z.string(), slug: z.string(), db_field: z.string(), name: z.string(), type: servicesAppcatalogTypesItemItemType, args: z.object({}).optional(), is_default: z.boolean(), is_required: z.boolean(), entity_type: entityTypeResponse.optional(), table: z.union([tableResponse, z.string()]).optional(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().optional(), computation: computationArgsResponse.optional()}); export const createPosition = z.object({placeholder_id: z.string().optional(), grid: z.object({}).optional(), sequence: z.number().int().optional(), size: z.number().int().optional()}); export const entityFieldResponse = z.object({id: z.string().optional(), name: z.string(), item_slug: z.string().optional(), is_table: z.boolean().optional(), item_type: servicesAppcatalogTypesItemItemType.optional(), item_args: z.object({}).optional(), description: z.string().optional(), generate_ai_summary: z.boolean().optional(), is_hidden: z.boolean().optional(), is_summary: z.boolean().optional(), item: itemResponse, position: createPosition, value: z.unknown()}); export const entitySectionResponse = z.object({id: z.string(), name: z.string(), table: tableWithRowResponse.optional(), sequence: z.number().int(), is_hidden: z.boolean().optional(), created_at: z.string(), updated_at: z.string(), fields: z.array(entityFieldResponse), access_modes: z.array(accessType), collaborators: z.array(collaboratorResponse), is_editable: z.boolean().optional(), is_collaborator_editable: z.boolean().optional()}); export const entityPageResponse = z.object({id: z.string(), slug: z.string(), name: z.string(), sections: z.array(entitySectionResponse), sequence: z.number().int(), created_at: z.string(), updated_at: z.string(), is_hidden: z.boolean(), access_modes: z.array(accessType), collaborators: z.array(collaboratorResponse), is_editable: z.boolean().optional(), is_collaborator_editable: z.boolean().optional()}); export const exhausetiveCatalogEntityExternalResponse = z.object({id: z.string(), name: z.string(), logo: z.string().optional(), slug: z.string(), entity_type: z.string(), tags: z.array(value).optional(), vendor_managers: z.array(collaboratorResponse).optional(), field_matches: z.array(z.string()).optional(), pages: z.array(entityPageResponse)}); 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 Item * * PUT /v2/catalog/{catalog_slug}/item/{item_id} */ export const updateApiV2CatalogCatalogSlugItemItemId = async (args: UpdateApiV2CatalogCatalogSlugItemItemIdArgs, options: UpdateApiV2CatalogCatalogSlugItemItemIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/catalog/${encodeURIComponent(String(args.catalog_slug))}/item/${encodeURIComponent(String(args.item_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(exhausetiveCatalogEntityExternalResponse, await res.json()) };