import {z} from 'zod' export type GetApiCmV1AuthUsersUserIdArgs = {user_id: string, include_role?: boolean | undefined}; export type GetApiCmV1AuthUsersUserIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const commonLocale = z.enum(["UNKNOWN_LOCALE", "EN_US", "KO_KR", "JA_JP"]); export const dspUser = z.object({email: z.string().optional(), id: z.string().optional(), name: z.string().optional(), last_name: z.string().optional(), company_name: z.string().optional(), terms_agreed: z.boolean().optional(), marketing_agreed: z.boolean().optional(), locale: commonLocale.optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const dspRoleType = z.enum(["WORKPLACE_OWNER", "AD_ACCOUNT_OWNER", "AD_ACCOUNT_MEMBER", "AD_ACCOUNT_VIEWER"]); export const dspRole = z.object({type: dspRoleType.optional(), workplace_id: z.string().optional(), ad_account_id: z.string().optional(), exchange_id: z.string().optional()}); export const messagesUserWithInfo = z.object({user: dspUser.optional(), signed_up: z.boolean().optional(), roles: z.array(dspRole).optional()}); export const messagesReadUserResponse = z.object({user_with_info: messagesUserWithInfo.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 }; /** * Read the user * * GET /cm/v1/auth/users/{user_id} */ export const getApiCmV1AuthUsersUserId = async (args: GetApiCmV1AuthUsersUserIdArgs, options?: GetApiCmV1AuthUsersUserIdOptions) => { const {baseUrl = "https://api.moloco.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_role != null) query.append("include_role", String(args.include_role)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/cm/v1/auth/users/${encodeURIComponent(String(args.user_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(messagesReadUserResponse, await res.json()) };