import {z} from 'zod' export type TrialExpirationDate = string; export type TrialNotes = string; export type UtmParameter = {[key: string]: unknown}; export type CreateEnterpriseTrialUserRequest = {email: string, name: string, organizationName?: string | undefined, expirationDate?: TrialExpirationDate | undefined, notes?: TrialNotes | undefined, useCase?: string | undefined, userHasMLModelsInProduction?: ('yes' | 'no' | 'no, but we will soon') | undefined, companyName?: string | undefined, companySize?: string | undefined, country?: string | undefined, stateOrProvince?: string | undefined, redirectUrlOrigin?: string | undefined, redirectUrlQueryParams?: string | undefined, username: string, privacyPolicy: boolean, password?: string | undefined, jobTitle?: string | undefined, utmParams?: Array | undefined, turnstileResponse: string}; export type CreateApiApiUserCreateEnterpriseTrialArgs = {body: CreateEnterpriseTrialUserRequest}; export type CreateApiApiUserCreateEnterpriseTrialOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createEnterpriseTrialResponse = z.object({success: z.boolean(), error: z.string().optional(), id: z.number().int(), userId: z.number().int().optional(), redirectUrl: z.string()}); 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 enterprise trial user * * POST /api-user-create-enterprise-trial */ export const createApiApiUserCreateEnterpriseTrial = async (args: CreateApiApiUserCreateEnterpriseTrialArgs, options?: CreateApiApiUserCreateEnterpriseTrialOptions) => { const {baseUrl = "https://studio.edgeimpulse.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api-user-create-enterprise-trial${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(createEnterpriseTrialResponse, await res.json()) };