import {z} from 'zod' export type GetApiPublicCommunitiesSubdomainUsersArgs = {subdomain: string, 'x-api-key': string, discordId?: string | undefined, discordHandle?: string | undefined, twitterUsername?: string | undefined, twitterId?: string | undefined, ethAddress?: string | undefined, email?: string | undefined, blockchainNetwork?: ('eth-mainnet' | 'opt-mainnet' | 'arb-mainnet' | 'polygon-mainnet' | 'base-mainnet' | 'sol-mainnet' | 'bnb-mainnet' | 'linea-mainnet' | 'avalanche-mainnet' | 'fantom-mainnet' | 'cronos-mainnet' | 'palm-mainnet' | 'gnosis-mainnet' | 'chiliz-mainnet' | 'moonbeam-mainnet' | 'polygonzkevm-mainnet' | 'zksync-mainnet' | 'ton-mainnet') | undefined, blockchainAddress?: string | undefined}; export type GetApiPublicCommunitiesSubdomainUsersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPublicCommunitiesSubdomainUsersResponse = z.object({discordHandle: z.string().nullable(), tiktokUsername: z.string().nullable(), twitterUsername: z.string().nullable(), verifiedBlockchainAddresses: z.record(z.string(), z.string()).nullable().optional(), unVerifiedBlockchainAddresses: z.record(z.string(), z.string()).nullable().optional(), connectedWallet: z.string().nullable(), email: z.string().nullable(), discordId: z.string().nullable(), twitterId: z.string().nullable(), id: z.string(), xp: z.number(), name: z.string().nullable(), createdAt: z.string(), rank: z.number(), invites: z.array(z.object({userId: z.string(), status: z.enum(["active", "pending", "consumed"]), joinedAt: z.string().nullable(), xp: z.number()})), role: z.enum(["admin", "editor", "banned", "guest", "reviewer"]), level: z.number(), isBanned: z.boolean(), karma: z.number(), referrerUrl: z.string().nullable(), referrerId: z.string().nullable(), banReason: z.string().nullable()}); 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 }; /** * Find a user by social id * * GET /public/communities/{subdomain}/users */ export const getApiPublicCommunitiesSubdomainUsers = async (args: GetApiPublicCommunitiesSubdomainUsersArgs, options?: GetApiPublicCommunitiesSubdomainUsersOptions) => { const {baseUrl = "https://api-v2.zealy.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (args.discordId != null) query.append("discordId", String(args.discordId)) if (args.discordHandle != null) query.append("discordHandle", String(args.discordHandle)) if (args.twitterUsername != null) query.append("twitterUsername", String(args.twitterUsername)) if (args.twitterId != null) query.append("twitterId", String(args.twitterId)) if (args.ethAddress != null) query.append("ethAddress", String(args.ethAddress)) if (args.email != null) query.append("email", String(args.email)) if (args.blockchainNetwork != null) query.append("blockchainNetwork", String(args.blockchainNetwork)) if (args.blockchainAddress != null) query.append("blockchainAddress", String(args.blockchainAddress)) const url = `${baseUrl.replace(/\/+$/, '')}/public/communities/${encodeURIComponent(String(args.subdomain))}/users${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(getApiPublicCommunitiesSubdomainUsersResponse, await res.json()) };