import {z} from 'zod' export type CcOrganizationContact = {first_name: string, last_name: string, email: string, job_title: string, telephone: string}; export type OrganizationDetails = {id?: string | undefined, name: string, address: string, address2: string, zip?: string | undefined, city?: string | undefined, state?: string | undefined, country: string, telephone?: string | undefined, organization_contact: CcOrganizationContact, authorized_representative: Array, organization_identifier?: string | undefined}; export type SsoConfigurationRequest = {authorization_endpoint?: string | undefined, token_endpoint?: string | undefined, jwks_endpoint?: string | undefined, client_id?: string | undefined, client_secret?: string | undefined, token_audience?: string | undefined, token_issuer?: string | undefined}; export type OnboardingAccountRequest = {account_name: string, locale: string, is_delegated: boolean, admin_user: {first_name: string, last_name: string, email: string, user_name: string, phone_number: string, locale: string, id: string}, service_user: {email: string}, organization_details: OrganizationDetails, sso_configuration?: SsoConfigurationRequest | undefined}; export type CreateApiApiV1OnboardSetupAccountArgs = {body: OnboardingAccountRequest}; export type CreateApiApiV1OnboardSetupAccountOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const onboardingAccountUserDetails = z.object({api_key: z.string().optional(), id: z.string().optional()}); export const onboardingOrganizationResponse = z.object({id: z.number().int().optional(), status: z.string().optional(), display_name: z.string().optional(), name: z.string().optional(), address: z.string().optional(), address2: z.string().optional(), zip: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional()}); export const ssoConfigurationResponse = z.object({callback_url: z.string().optional(), login_initiation_endpoint: z.string().optional(), logout_endpoint: z.string().optional()}); export const onboardingAccountResponse = z.object({id: z.string().optional(), service_user: onboardingAccountUserDetails.optional(), admin_user: onboardingAccountUserDetails.optional(), products: z.array(z.string()).optional(), account_id: z.string().optional(), organization: onboardingOrganizationResponse.optional(), sso_configuration: ssoConfigurationResponse.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 }; /** * Setup new onboarding account. * * POST /api/v1/onboard/setup-account */ export const createApiApiV1OnboardSetupAccount = async (args: CreateApiApiV1OnboardSetupAccountArgs, options?: CreateApiApiV1OnboardSetupAccountOptions) => { const {baseUrl = "https://one.digicert.com/documentmanager", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/onboard/setup-account${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(onboardingAccountResponse, await res.json()) };