import {z} from 'zod' export type GetApiApiV1UsersInviteReceivedArgs = {cursor?: string | undefined, limit?: number | undefined, account_id: string}; export type GetApiApiV1UsersInviteReceivedOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1UsersInviteReceivedResponse = z.object({object: z.literal("InvitationList"), items: z.array(z.object({object: z.literal("InvitationReceived"), id: z.string().min(1), invited_user: z.union([z.string(), z.unknown()]), invited_user_id: z.union([z.string(), z.unknown()]), invited_user_public_id: z.union([z.string(), z.unknown()]), invited_user_description: z.union([z.string(), z.unknown()]), date: z.string(), parsed_datetime: z.union([z.string(), z.unknown()]), invitation_text: z.union([z.string(), z.unknown()]), inviter: z.object({inviter_name: z.string(), inviter_id: z.string(), inviter_public_identifier: z.string(), inviter_description: z.union([z.string(), z.unknown()])}).optional(), specifics: z.object({provider: z.literal("LINKEDIN"), shared_secret: z.string()}).optional()})), cursor: z.union([z.string(), z.unknown()])}); 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 }; /** * List all invitations received * * GET /api/v1/users/invite/received */ export const getApiApiV1UsersInviteReceived = async (args: GetApiApiV1UsersInviteReceivedArgs, options?: GetApiApiV1UsersInviteReceivedOptions) => { const {baseUrl = "https://api1.unipile.com:13111", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.account_id != null) query.append("account_id", String(args.account_id)) if (AccessToken !== undefined) headers.set("X-API-KEY", AccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/invite/received${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(getApiApiV1UsersInviteReceivedResponse, await res.json()) };