import {z} from 'zod' export type CreateSettings = {leadColor?: string | undefined, language?: ('en' | 'es' | 'fr' | 'de' | 'pl' | 'it' | 'pt' | 'nl' | 'hu' | 'no' | 'sl' | 'sk' | 'sv' | 'cs' | 'tr' | 'ja' | 'tw' | 'zh' | 'he' | 'ru' | 'ar' | 'fi' | 'uk' | 'ro' | 'ga' | 'el' | 'sr' | 'bs' | 'hr' | 'lb' | 'sq' | 'da') | undefined, position?: ('left' | 'right') | undefined, triggerColor?: string | undefined, triggerPositionX?: ('left' | 'right') | undefined, triggerPositionY?: ('top' | 'center' | 'bottom') | undefined, triggerSize?: ('small' | 'medium' | 'big') | undefined, triggerRadius?: ('50%' | '0' | '10px' | '5px') | undefined, hideTrigger?: boolean | undefined, triggerOffsetX?: number | undefined, triggerOffsetY?: number | undefined, triggerIcon?: ('checkmark' | 'display' | 'display2' | 'display3' | 'help' | 'people' | 'people2' | 'settings' | 'settings2' | 'wheels' | 'wheels2') | undefined, hideMobile?: boolean | undefined, mobile?: ({triggerPositionX?: ('left' | 'right') | undefined, triggerPositionY?: ('top' | 'center' | 'bottom') | undefined, triggerSize?: ('small' | 'medium' | 'big') | undefined, triggerRadius?: ('50%' | '0' | '10px' | '5px') | undefined, triggerOffsetX?: number | undefined, triggerOffsetY?: number | undefined}) | undefined, statementLink?: string | undefined, footerHtml?: string | undefined}; export type CreateLicense = {domain: string, planSKU: number, contactName?: string | undefined, contactEmail?: string | undefined, contactPhone?: string | undefined, contactCountryCode?: string | undefined, discountEnabled?: boolean | undefined, monthly?: boolean | undefined, activate?: boolean | undefined, longTrial?: boolean | undefined, settings?: CreateSettings | undefined}; export type CreateApiAccountsAccountIdAccessWidgetLicensesBatchCreateArgs = {accountId: string, 'Idempotency-Key'?: string | undefined, body: {licenses?: Array | undefined}}; export type CreateApiAccountsAccountIdAccessWidgetLicensesBatchCreateOptions = {baseUrl: string, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAccountsAccountIdAccessWidgetLicensesBatchCreateResponse = z.object({success: z.boolean().optional(), data: z.object({batchId: z.string().optional(), status: z.enum(["processing", "completed"]).optional(), operation: z.enum(["create", "update"]).optional(), getBatchStatusURL: z.string().optional()}).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 multiple accessWidget licenses * * POST /accounts/{accountId}/access-widget-licenses/batch-create */ export const createApiAccountsAccountIdAccessWidgetLicensesBatchCreate = async (args: CreateApiAccountsAccountIdAccessWidgetLicensesBatchCreateArgs, options: CreateApiAccountsAccountIdAccessWidgetLicensesBatchCreateOptions) => { const {baseUrl, fetch: fetchFn = fetch, XAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.accountId))}/access-widget-licenses/batch-create${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(createApiAccountsAccountIdAccessWidgetLicensesBatchCreateResponse, await res.json()) };