import {z} from 'zod' export type GetApiV1OrgsOrgIdUsersArgs = {sort?: (Array<'username' | '-username' | 'createdAt' | '-createdAt'> | 'username' | '-username' | 'createdAt' | '-createdAt') | undefined, 'page[size]'?: number | undefined, 'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'filter[username]'?: string | undefined, 'filter[username][eq]'?: string | undefined, 'filter[username][ne]'?: string | undefined, 'filter[username][gt]'?: string | undefined, 'filter[username][gte]'?: string | undefined, 'filter[username][lt]'?: string | undefined, 'filter[username][lte]'?: string | undefined, 'filter[username][like]'?: string | undefined, orgId: string, Authorization?: string | undefined}; export type GetApiV1OrgsOrgIdUsersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1OrgsOrgIdUsersResponse = z.object({links: z.object({self: z.string(), next: z.string().nullable(), prev: z.string().nullable()}), meta: z.object({count: z.number()}), data: z.array(z.object({id: z.string(), type: z.literal("user"), attributes: z.object({username: z.string(), createdAt: z.string()})}))}); 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 }; /** * Lists the members of an organization as users, with username filter and sorting. Only members of the organization can call it; returns 404 otherwise. * * GET /v1/orgs/{orgId}/users */ export const getApiV1OrgsOrgIdUsers = async (args: GetApiV1OrgsOrgIdUsersArgs, options?: GetApiV1OrgsOrgIdUsersOptions) => { const {baseUrl = "https://api.tessl.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sort != null) query.append("sort", String(args.sort)) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['filter[username]'] != null) query.append("filter[username]", String(args['filter[username]'])) if (args['filter[username][eq]'] != null) query.append("filter[username][eq]", String(args['filter[username][eq]'])) if (args['filter[username][ne]'] != null) query.append("filter[username][ne]", String(args['filter[username][ne]'])) if (args['filter[username][gt]'] != null) query.append("filter[username][gt]", String(args['filter[username][gt]'])) if (args['filter[username][gte]'] != null) query.append("filter[username][gte]", String(args['filter[username][gte]'])) if (args['filter[username][lt]'] != null) query.append("filter[username][lt]", String(args['filter[username][lt]'])) if (args['filter[username][lte]'] != null) query.append("filter[username][lte]", String(args['filter[username][lte]'])) if (args['filter[username][like]'] != null) query.append("filter[username][like]", String(args['filter[username][like]'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orgs/${encodeURIComponent(String(args.orgId))}/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(getApiV1OrgsOrgIdUsersResponse, await res.json()) };