import {z} from 'zod' export type GetApiPlatformUsersLookupArgs = {email?: string | undefined, phone?: string | undefined, walletAddress?: string | undefined, walletExternalId?: string | undefined, smartWalletId?: string | undefined, customAuthId?: string | undefined, provider?: string | undefined, providerAccountId?: string | undefined, tenantId?: string | undefined}; export type GetApiPlatformUsersLookupOptions = {baseUrl?: string | undefined, platformKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPlatformUsersLookupResponse = z.object({ok: z.literal(true), data: z.object({user: z.object({userId: z.string().optional(), email: z.string().nullable().optional(), emailVerified: z.boolean().nullable().optional(), name: z.string().nullable().optional(), image: z.string().nullable().optional(), walletAddress: z.string().nullable().optional(), walletChain: z.string().nullable().optional(), customMetadata: z.record(z.string(), z.unknown()).optional(), deactivatedAt: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), tenantIds: z.array(z.string()).optional(), linkedAccounts: z.array(z.record(z.string(), z.unknown())).optional(), walletExternalIds: z.array(z.object({tenantId: z.string().optional(), walletExternalId: z.string().optional(), externalId: z.string().optional()})).optional()}).and(z.record(z.string(), z.unknown())).nullable().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 }; /** * Look up a platform user identity * * GET /platform/users/lookup */ export const getApiPlatformUsersLookup = async (args: GetApiPlatformUsersLookupArgs, options?: GetApiPlatformUsersLookupOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, platformKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.email != null) query.append("email", String(args.email)) if (args.phone != null) query.append("phone", String(args.phone)) if (args.walletAddress != null) query.append("walletAddress", String(args.walletAddress)) if (args.walletExternalId != null) query.append("walletExternalId", String(args.walletExternalId)) if (args.smartWalletId != null) query.append("smartWalletId", String(args.smartWalletId)) if (args.customAuthId != null) query.append("customAuthId", String(args.customAuthId)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.providerAccountId != null) query.append("providerAccountId", String(args.providerAccountId)) if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (platformKey !== undefined) headers.set("X-Steward-Platform-Key", platformKey) const url = `${baseUrl.replace(/\/+$/, '')}/platform/users/lookup${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(getApiPlatformUsersLookupResponse, await res.json()) };