import {z} from 'zod' export type ActivateUserDto = {userId: string, token: string, password?: string | undefined, recaptchaToken?: string | undefined, lastTermsCheck?: string | undefined}; export type CreateApiResourcesUsersV1ActivateArgs = {'frontegg-vendor-host': string, body: ActivateUserDto}; export type CreateApiResourcesUsersV1ActivateOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userMFAWebAuthnDeviceResponse = z.object({id: z.string(), deviceType: z.enum(["Platform", "CrossPlatform"]), name: z.string()}); export const userMFAPhoneDeviceResponse = z.object({id: z.string(), phoneNumber: z.string()}); export const userMFAAuthenticatorAppResponse = z.object({id: z.string()}); export const userMFAEmailCodeResponse = z.object({email: z.string()}); export const userMFADevicesResponse = z.object({webauthn: z.array(userMFAWebAuthnDeviceResponse), phones: z.array(userMFAPhoneDeviceResponse), authenticators: z.array(userMFAAuthenticatorAppResponse), emails: z.array(userMFAEmailCodeResponse)}); export const authenticationResponseDto = z.object({tokenType: z.string().optional(), mfaRequired: z.boolean(), mfaToken: z.string().optional(), mfaEnrolled: z.boolean().optional(), mfaDevices: userMFADevicesResponse.optional(), mfaStrategies: z.object({}).optional(), qrCode: z.string().optional(), recoveryCode: z.string().optional(), accessToken: z.string(), refreshToken: z.string(), expiresIn: z.number(), expires: z.string(), userId: z.string().optional(), userEmail: z.string().optional(), emailVerified: z.boolean().optional(), isBreachedPassword: z.boolean().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 }; /** * Activate user * * POST /resources/users/v1/activate */ export const createApiResourcesUsersV1Activate = async (args: CreateApiResourcesUsersV1ActivateArgs, options?: CreateApiResourcesUsersV1ActivateOptions) => { const {baseUrl = "http://localhost:8181", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['frontegg-vendor-host'] != null) headers.set("frontegg-vendor-host", String(args['frontegg-vendor-host'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/resources/users/v1/activate${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(authenticationResponseDto, await res.json()) };