import {z} from 'zod' export type UpdateSettings = {default?: (boolean | null) | undefined, leadColor?: (string | null) | 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' | null) | undefined, position?: ('left' | 'right' | null) | undefined, triggerColor?: (string | null) | undefined, triggerPositionX?: ('left' | 'right' | null) | undefined, triggerPositionY?: ('top' | 'center' | 'bottom' | null) | undefined, triggerSize?: ('small' | 'medium' | 'big' | null) | undefined, triggerRadius?: ('50%' | '0' | '10px' | '5px' | null) | undefined, hideTrigger?: (boolean | null) | undefined, triggerOffsetX?: (number | null) | undefined, triggerOffsetY?: (number | null) | undefined, triggerIcon?: ('checkmark' | 'display' | 'display2' | 'display3' | 'help' | 'people' | 'people2' | 'settings' | 'settings2' | 'wheels' | 'wheels2' | null) | undefined, hideMobile?: (boolean | null) | undefined, mobile?: ({triggerPositionX?: ('left' | 'right' | null) | undefined, triggerPositionY?: ('top' | 'center' | 'bottom' | null) | undefined, triggerSize?: ('small' | 'medium' | 'big' | null) | undefined, triggerRadius?: ('50%' | '0' | '10px' | '5px' | null) | undefined, triggerOffsetX?: (number | null) | undefined, triggerOffsetY?: (number | null) | undefined} | null) | undefined, statementLink?: (string | null) | undefined, footerHtml?: (string | null) | undefined}; export type UpdateLicense = {domain: string, newDomain?: string | undefined, planSKU?: number | undefined, contactName?: string | undefined, contactEmail?: string | undefined, contactPhone?: string | undefined, contactCountryCode?: string | undefined, discountEnabled?: boolean | undefined, monthly?: boolean | undefined, activate?: boolean | undefined, disable?: boolean | undefined, settings?: UpdateSettings | undefined}; export type PatchApiAccountsAccountIdAccessWidgetLicensesLicenseIdArgs = {accountId: string, licenseId: string, body: UpdateLicense}; export type PatchApiAccountsAccountIdAccessWidgetLicensesLicenseIdOptions = {baseUrl: string, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const plan = z.object({name: z.string().optional(), planSKU: z.number().optional()}).nullable(); export const licenseCreateOrUpdateResponse = z.object({id: z.string().optional(), date: z.string().optional(), relatedAccountId: z.string().optional(), domain: z.string().optional(), status: z.enum(["active", "grace", "expired", "trial"]).optional(), price: z.number().optional(), licenseType: z.string().optional(), plan: plan.optional(), relatedBillingId: z.string().nullable().optional(), statementDate: z.string().optional(), dateTrialExpires: z.string().optional(), datePlanExpires: z.string().nullable().optional(), datePlanFirstActivated: z.string().nullable().optional(), lastSubscriptionPaymentId: z.string().nullable().optional(), enableGoogleAnalytics: z.boolean().optional(), enableRemediationReport: z.boolean().optional(), monthly: z.boolean().optional(), autoRenew: z.boolean().optional(), contactName: z.string().nullable().optional(), contactEmail: z.string().nullable().optional(), contactPhone: z.string().nullable().optional(), contactCountry: z.string().nullable().optional()}); export const patchApiAccountsAccountIdAccessWidgetLicensesLicenseIdResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: licenseCreateOrUpdateResponse.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 }; /** * Update an accessWidget license * * PATCH /accounts/{accountId}/access-widget-licenses/{licenseId} */ export const patchApiAccountsAccountIdAccessWidgetLicensesLicenseId = async (args: PatchApiAccountsAccountIdAccessWidgetLicensesLicenseIdArgs, options: PatchApiAccountsAccountIdAccessWidgetLicensesLicenseIdOptions) => { 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 (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.accountId))}/access-widget-licenses/${encodeURIComponent(String(args.licenseId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiAccountsAccountIdAccessWidgetLicensesLicenseIdResponse, await res.json()) };