import {z} from 'zod' export type CreateApiV1TenantTenantIdArgs = {tenant_id: string, body: {name: string, tenant_name?: string | undefined, parent_id?: (string | null) | undefined, blocked_channels?: (Array | null) | undefined, logo?: string | undefined, primary_color?: string | undefined, secondary_color?: string | undefined, tertiary_color?: string | undefined, embedded_preference_url?: string | undefined, social_links?: ({website?: string | undefined, facebook?: string | undefined, linkedin?: string | undefined, x?: string | undefined, instagram?: string | undefined, medium?: string | undefined, discord?: string | undefined, telegram?: string | undefined, youtube?: string | undefined, tiktok?: string | undefined}) | undefined, properties?: {[key: string]: string} | undefined}}; export type CreateApiV1TenantTenantIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1TenantTenantIdResponse = z.object({}); 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 / Update Tenants * * POST /v1/tenant/{tenant_id}/ */ export const createApiV1TenantTenantId = async (args: CreateApiV1TenantTenantIdArgs, options?: CreateApiV1TenantTenantIdOptions) => { const {baseUrl = "https://hub.suprsend.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(/\/+$/, '')}/v1/tenant/${encodeURIComponent(String(args.tenant_id))}/${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(createApiV1TenantTenantIdResponse, await res.json()) };