import {z} from 'zod' export type MarketplaceWalletRequest = {marketplace: string, account: string, id?: string | undefined, magicCode?: string | undefined, proof?: string | undefined}; export type CreateApiWalletManagerMarketplaceWalletConnectionsArgs = {body: MarketplaceWalletRequest}; export type CreateApiWalletManagerMarketplaceWalletConnectionsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, authenticatedEncryption?: string | undefined, ethereum?: string | undefined, collabLandOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const walletProxyModel = z.object({proxyAddresses: z.array(z.string()).optional(), proxyAccounts: z.array(z.string()).optional(), proxyType: z.string().optional()}); export const platformCommunityUser = z.object({platform: z.string(), id: z.string(), userPk: z.string().optional(), name: z.string().optional(), communityId: z.string().optional(), communityPk: z.string().optional(), communityName: z.string().optional(), state: z.string().optional(), message: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const walletConnectionInfo = z.object({user: platformCommunityUser.optional(), walletType: z.string().optional(), address: z.string().optional(), accountId: z.string().optional()}); export const walletConnectionResponse = z.object({success: z.boolean().optional(), address: z.string().optional(), proxies: z.array(walletProxyModel).optional(), state: z.string().optional(), message: z.string().optional(), code: z.string().optional(), resetToken: z.string().optional(), connection: walletConnectionInfo.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 }; /** * POST /wallet-manager/marketplace-wallet-connections */ export const createApiWalletManagerMarketplaceWalletConnections = async (args: CreateApiWalletManagerMarketplaceWalletConnectionsArgs, options?: CreateApiWalletManagerMarketplaceWalletConnectionsOptions) => { const {baseUrl = "https://api.collab.land", fetch: fetchFn = fetch, apiKey, authenticatedEncryption, ethereum, collabLandOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("x-api-key", apiKey) if (authenticatedEncryption !== undefined) headers.set("Authorization", authenticatedEncryption) if (ethereum !== undefined) headers.set("Authorization", ethereum) if (collabLandOAuth2 !== undefined) headers.set('authorization', `Bearer ${collabLandOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/wallet-manager/marketplace-wallet-connections${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(walletConnectionResponse, await res.json()) };