import {z} from 'zod' export type CreateProfileRequest = {name: string, profileType: 'IOS_APP_DEVELOPMENT' | 'IOS_APP_STORE' | 'IOS_APP_ADHOC' | 'MAC_APP_DEVELOPMENT' | 'MAC_APP_STORE' | 'MAC_APP_DIRECT' | 'MAC_CATALYST_APP_DEVELOPMENT' | 'MAC_CATALYST_APP_STORE' | 'MAC_CATALYST_APP_DIRECT', bundleIdAppleId: string, certificateIds: Array, deviceIds?: (Array | null) | undefined}; export type CreateApiAppsec70AppleProfilesArgs = {body: CreateProfileRequest}; export type CreateApiAppsec70AppleProfilesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const profileDTO = z.object({id: z.number().int().optional(), appleProfileId: z.string().nullable().optional(), name: z.string().optional(), profileType: z.string().optional(), bundleId: z.string().optional(), uuid: z.string().nullable().optional(), expiresAt: z.number().int().nullable().optional(), status: z.string().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 }; /** * Create a provisioning profile * * POST /appsec/7.0/apple/profiles */ export const createApiAppsec70AppleProfiles = async (args: CreateApiAppsec70AppleProfilesArgs, options?: CreateApiAppsec70AppleProfilesOptions) => { const {baseUrl = "https://cloud.codenameone.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/appsec/7.0/apple/profiles${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(profileDTO, await res.json()) };