import {z} from 'zod' export type GetApiUsersBetaFeaturesArgs = {id?: string | undefined, id__in?: string | undefined, organization?: string | undefined, organization__in?: string | undefined, referring_user?: string | undefined, referring_user__in?: string | undefined, current_sign_in_at__gt?: string | undefined, current_sign_in_at__lt?: string | undefined, current_sign_in_at__lte?: string | undefined, current_sign_in_at__gte?: string | undefined, search?: string | undefined, lineage?: string | undefined, roles?: string | undefined, role?: string | undefined, has_team?: string | undefined, no_team_incident?: string | undefined, sort?: ('created_at' | '-created_at' | 'updated_at' | '-updated_at') | undefined, recent_phone_users?: string | undefined, team_ids?: string | undefined, equipment?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiUsersBetaFeaturesOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; export const betaFeature = z.object({id: z.number().int().optional(), name: z.string().max(255).nullable().optional(), description: z.string().nullable().optional(), opt_in: z.boolean().nullable().optional()}); export const getApiUsersBetaFeaturesResponse = z.array(betaFeature); 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 }; /** * Get user's enabled beta features * * GET /users/beta_features */ export const getApiUsersBetaFeatures = async (args: GetApiUsersBetaFeaturesArgs, options?: GetApiUsersBetaFeaturesOptions) => { const {baseUrl = "https://crisiscleanup-3-api-production.up.railway.app", fetch: fetchFn = fetch, Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.id__in != null) query.append("id__in", String(args.id__in)) if (args.organization != null) query.append("organization", String(args.organization)) if (args.organization__in != null) query.append("organization__in", String(args.organization__in)) if (args.referring_user != null) query.append("referring_user", String(args.referring_user)) if (args.referring_user__in != null) query.append("referring_user__in", String(args.referring_user__in)) if (args.current_sign_in_at__gt != null) query.append("current_sign_in_at__gt", String(args.current_sign_in_at__gt)) if (args.current_sign_in_at__lt != null) query.append("current_sign_in_at__lt", String(args.current_sign_in_at__lt)) if (args.current_sign_in_at__lte != null) query.append("current_sign_in_at__lte", String(args.current_sign_in_at__lte)) if (args.current_sign_in_at__gte != null) query.append("current_sign_in_at__gte", String(args.current_sign_in_at__gte)) if (args.search != null) query.append("search", String(args.search)) if (args.lineage != null) query.append("lineage", String(args.lineage)) if (args.roles != null) query.append("roles", String(args.roles)) if (args.role != null) query.append("role", String(args.role)) if (args.has_team != null) query.append("has_team", String(args.has_team)) if (args.no_team_incident != null) query.append("no_team_incident", String(args.no_team_incident)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.recent_phone_users != null) query.append("recent_phone_users", String(args.recent_phone_users)) if (args.team_ids != null) query.append("team_ids", String(args.team_ids)) if (args.equipment != null) query.append("equipment", String(args.equipment)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/users/beta_features${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(getApiUsersBetaFeaturesResponse, await res.json()) };