import {z} from 'zod' export type SystemDomainFromReferralCodeSchema = {admin_email?: string | undefined, admin_first_name?: string | undefined, admin_last_name?: string | undefined, admin_password?: string | undefined, billing_tier?: ('PAYGO' | 'PRO' | 'ENTERPRISE' | 'ENTERPRISE_LEGACY_2025' | 'PRO_LEGACY_2025') | undefined, country_code: string, date_created?: string | undefined, date_modified?: string | undefined, description?: string | undefined, id?: string | undefined, name: string}; export type CreateApiV1SystemDomainsReferralCodeReferralCodeArgs = {'App-ID': string, 'Auth-Token': string, referral_code: string, body: SystemDomainFromReferralCodeSchema}; export type CreateApiV1SystemDomainsReferralCodeReferralCodeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const systemDomainFromTemplateSchema = z.object({admin_email: z.string().optional(), admin_first_name: z.string().optional(), admin_id: z.string().optional(), admin_last_name: z.string().optional(), admin_password: z.string().optional(), base_url: z.string().optional(), billing_tier: z.enum(["PAYGO", "PRO", "ENTERPRISE", "ENTERPRISE_LEGACY_2025", "PRO_LEGACY_2025"]).optional(), custom_terms: z.boolean().optional(), date_created: z.string().optional(), date_modified: z.string().optional(), description: z.string().optional(), disable_ai_features: z.boolean().optional(), id: z.string().optional(), name: z.string(), status: z.enum(["ACTIVE", "WARNING", "FROZEN", "DEACTIVATED"]).optional(), type: z.enum(["TRIAL", "CUSTOMER", "PARTNER", "INTERNAL"]).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 new system domain from a referral code (That is associated to your domain) * * POST /v1/system_domains/referral_code/{referral_code}/ */ export const createApiV1SystemDomainsReferralCodeReferralCode = async (args: CreateApiV1SystemDomainsReferralCodeReferralCodeArgs, options: CreateApiV1SystemDomainsReferralCodeReferralCodeOptions) => { 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['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/system_domains/referral_code/${encodeURIComponent(String(args.referral_code))}/${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(systemDomainFromTemplateSchema, await res.json()) };