import {z} from 'zod' export type GetApiEntitiesEntityIdInfoRequestsRequestIdSchemaArgs = {request_id: string, entity_id: string}; export type GetApiEntitiesEntityIdInfoRequestsRequestIdSchemaOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dDElementType = z.enum(["text", "comment", "boolean", "dropdown", "checkbox", "number", "date", "country_select", "state_select", "text_list", "group", "repeat", "file_upload", "confirm"]); export const dDChoice = z.object({value: z.string(), label: z.string()}); export const dDOperator = z.enum(["eq", "neq", "contains", "contains_any", "not_empty"]); export const dDCondition = z.object({field: z.string(), operator: dDOperator, value: z.union([z.string(), z.boolean(), z.number().int(), z.number(), z.array(z.string())]).nullable().optional()}); export const dDLogicalOperator = z.enum(["and", "or"]); export const dDCompoundCondition: z.ZodType = z.object({logical_operator: dDLogicalOperator, conditions: z.array(z.union([dDCondition, z.lazy(() => dDCompoundCondition)]))}); export const dDValidation = z.object({min_length: z.number().int().nullable().optional(), max_length: z.number().int().nullable().optional(), min_value: z.number().nullable().optional(), max_value: z.number().nullable().optional()}); export const dDFileUploadConfig = z.object({accepted_types: z.array(z.string()), proof_type: z.string().nullable().optional(), max_files: z.number().int().optional()}); export const dDElement: z.ZodType = z.object({type: dDElementType, name: z.string(), title: z.string(), description: z.string().nullable().optional(), required: z.boolean().optional(), sensitive: z.boolean().optional(), default_value: z.union([z.string(), z.boolean(), z.number().int(), z.number(), z.array(z.string())]).nullable().optional(), choices: z.array(dDChoice).nullable().optional(), visible_when: z.union([dDCondition, dDCompoundCondition]).nullable().optional(), required_when: z.union([dDCondition, dDCompoundCondition]).nullable().optional(), validation: dDValidation.nullable().optional(), multiple: z.boolean().optional(), elements: z.array(z.lazy(() => dDElement)).nullable().optional(), min_items: z.number().int().nullable().optional(), max_items: z.number().int().nullable().optional(), file_upload_config: dDFileUploadConfig.nullable().optional(), input_format: z.enum(["currency", "percentage"]).nullable().optional(), component: z.string().nullable().optional(), exclude_countries: z.array(z.string()).nullable().optional()}); export const dDPage = z.object({name: z.string(), title: z.string(), elements: z.array(dDElement)}); export const tinKind = z.enum(["ein", "ssn", "itin", "foreign_tin"]); export const countryCodeAlpha2 = z.enum(["AW", "AF", "AO", "AI", "AX", "AL", "AD", "AE", "AR", "AM", "AS", "AQ", "TF", "AG", "AU", "AT", "AZ", "BI", "BE", "BJ", "BQ", "BF", "BD", "BG", "BH", "BS", "BA", "BL", "BY", "BZ", "BM", "BO", "BR", "BB", "BN", "BT", "BV", "BW", "CF", "CA", "CC", "CH", "CL", "CN", "CI", "CM", "CD", "CG", "CK", "CO", "KM", "CV", "CR", "CU", "CW", "CX", "KY", "CY", "CZ", "DE", "DJ", "DM", "DK", "DO", "DZ", "EC", "EG", "ER", "EH", "ES", "EE", "ET", "FI", "FJ", "FK", "FR", "FO", "FM", "GA", "GB", "GE", "GG", "GH", "GI", "GN", "GP", "GM", "GW", "GQ", "GR", "GD", "GL", "GT", "GF", "GU", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IM", "IN", "IO", "IE", "IR", "IQ", "IS", "IL", "IT", "JM", "JE", "JO", "JP", "KZ", "KE", "KG", "KH", "KI", "KN", "KR", "KW", "LA", "LB", "LR", "LY", "LC", "LI", "LK", "LS", "LT", "LU", "LV", "MO", "MF", "MA", "MC", "MD", "MG", "MV", "MX", "MH", "MK", "ML", "MT", "MM", "ME", "MN", "MP", "MZ", "MR", "MS", "MQ", "MU", "MW", "MY", "YT", "NA", "NC", "NE", "NF", "NG", "NI", "NU", "NL", "NO", "NP", "NR", "NZ", "OM", "PK", "PA", "PN", "PE", "PH", "PW", "PG", "PL", "PR", "KP", "PT", "PY", "PS", "PF", "QA", "RE", "RO", "RU", "RW", "SA", "SD", "SN", "SG", "GS", "SH", "SJ", "SB", "SL", "SV", "SM", "SO", "PM", "RS", "SS", "ST", "SR", "SK", "SI", "SE", "SZ", "SX", "SC", "SY", "TC", "TD", "TG", "TH", "TJ", "TK", "TM", "TL", "TO", "TT", "TN", "TR", "TV", "TW", "TZ", "UG", "UA", "UM", "UY", "US", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "ZA", "ZM", "ZW"]); export const tinSubjectType = z.enum(["business", "representative"]); export const tinCollectionResponse = z.object({kind: tinKind, country: countryCodeAlpha2, saved: z.boolean(), submitted: z.boolean(), subject_type: tinSubjectType, subject_name: z.string()}); export const entityInfoRequestSchema = z.object({title: z.string(), pages: z.array(dDPage), tin_collection: tinCollectionResponse.nullable().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 Info Request Form Schema * * GET /entities/{entity_id}/info-requests/{request_id}/schema */ export const getApiEntitiesEntityIdInfoRequestsRequestIdSchema = async (args: GetApiEntitiesEntityIdInfoRequestsRequestIdSchemaArgs, options?: GetApiEntitiesEntityIdInfoRequestsRequestIdSchemaOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/entities/${encodeURIComponent(String(args.entity_id))}/info-requests/${encodeURIComponent(String(args.request_id))}/schema${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(entityInfoRequestSchema, await res.json()) };