import {z} from 'zod' export type CreateApiApiV1AppsAppIdCvmsIsAllowedArgs = {app_id: string}; export type CreateApiApiV1AppsAppIdCvmsIsAllowedOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const cvmIsAllowedItemV20260121 = z.object({app_contract_address: z.string(), compose_hash: z.string(), device_id: z.string(), compose_hash_allowed: z.boolean(), allow_any_device: z.boolean(), device_id_allowed: z.boolean().nullable().optional(), is_allowed: z.boolean(), error: z.string().nullable().optional(), cvm_id: z.number().int()}); export const appCvmsBatchIsAllowedResponseV20260121 = z.object({is_onchain: z.boolean(), results: z.array(cvmIsAllowedItemV20260121).optional(), total: z.number().int().optional(), allowed_count: z.number().int().optional(), denied_count: z.number().int().optional(), error_count: z.number().int().optional(), skipped_cvm_ids: z.array(z.number().int()).optional()}); export const cvmIsAllowedItemV20260522 = z.object({app_contract_address: z.string(), compose_hash: z.string(), device_id: z.string(), compose_hash_allowed: z.boolean(), allow_any_device: z.boolean(), device_id_allowed: z.boolean().nullable().optional(), is_allowed: z.boolean(), error: z.string().nullable().optional(), cvm_id: z.string()}); export const appCvmsBatchIsAllowedResponseV20260522 = z.object({is_onchain: z.boolean(), results: z.array(cvmIsAllowedItemV20260522).optional(), total: z.number().int().optional(), allowed_count: z.number().int().optional(), denied_count: z.number().int().optional(), error_count: z.number().int().optional(), skipped_cvm_ids: z.array(z.string()).optional()}); export const createApiApiV1AppsAppIdCvmsIsAllowedResponse = z.union([appCvmsBatchIsAllowedResponseV20260121, appCvmsBatchIsAllowedResponseV20260522]); 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 }; /** * Batch check on-chain deployment allowance for all CVMs under an app * * POST /api/v1/apps/{app_id}/cvms/is-allowed */ export const createApiApiV1AppsAppIdCvmsIsAllowed = async (args: CreateApiApiV1AppsAppIdCvmsIsAllowedArgs, options?: CreateApiApiV1AppsAppIdCvmsIsAllowedOptions) => { const {baseUrl = "https://cloud-api.phala.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/apps/${encodeURIComponent(String(args.app_id))}/cvms/is-allowed${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AppsAppIdCvmsIsAllowedResponse, await res.json()) };