import {z} from 'zod' export type HierarchyItemSelector = {contractID?: (string | null) | undefined, instanceID?: (string | null) | undefined, clientArtifactID?: (number | null) | undefined, matterArtifactID?: (number | null) | undefined, workspaceArtifactID?: (number | null) | undefined}; export type FieldFilter = {fieldName?: (string | null) | undefined, operator?: (string | null) | undefined, value?: (string | null) | undefined}; export type FieldOrder = {fieldName?: (string | null) | undefined, direction?: ('Asc' | 'Desc') | undefined}; export type PagingRequest = {top?: (number | null) | undefined, skip?: (number | null) | undefined, maxItemCount?: (number | null) | undefined, includeCount?: (boolean | null) | undefined, continuationToken?: (string | null) | undefined}; export type GetUsersDetailsRequest = {dateKey?: (string | null) | undefined, selectorLevel?: ('Workspace' | 'Matter' | 'Client' | 'Instance' | 'Contract') | undefined, itemSelectors?: (Array | null) | undefined, filters?: (Array | null) | undefined, order?: FieldOrder | undefined, pagingRequest?: PagingRequest | undefined, includeWorkspaceInfo?: boolean | undefined, shouldUnhashData?: boolean | undefined}; export type CreateApiApiV2BillingInsightsUsersDetailsArgs = {body: GetUsersDetailsRequest}; export type CreateApiApiV2BillingInsightsUsersDetailsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const instance = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), pricingVisibility: z.enum(["Visible", "HiddenResoldInstance", "HiddenFixedContract"]).optional()}); export const userInstanceSpecificData = z.object({instance: instance.optional(), artifactID: z.number().int().optional(), userRole: z.string().nullable().optional(), lastLoginUtc: z.string().nullable().optional()}); export const clientMatterData = z.object({clientArtifactId: z.number().int().optional(), matterArtifactId: z.number().int().optional()}); export const getUsersDetailsResponseItem = z.object({email: z.string().nullable().optional(), userRole: z.string().nullable().optional(), billableStatus: z.string().nullable().optional(), lastLoginUtc: z.string().nullable().optional(), userActivity: z.string().nullable().optional(), userType: z.string().nullable().optional(), anonymization: z.string().nullable().optional(), anonymizedFields: z.record(z.string(), z.string().nullable()).nullable().optional(), comment: z.string().nullable().optional(), instanceSpecificData: z.record(z.string(), userInstanceSpecificData).nullable().optional(), workspaces: z.record(z.string(), clientMatterData).nullable().optional(), collectionTimeUtc: z.string().nullable().optional()}); export const pagingResponse = z.object({totalRecordCount: z.number().int().nullable().optional(), continuationToken: z.string().nullable().optional()}); export const getUsersDetailsResponse = z.object({results: z.array(getUsersDetailsResponseItem).nullable().optional(), pagingResponse: pagingResponse.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 }; /** * Get a user list * * POST /api/v2/billing-insights/users-details */ export const createApiApiV2BillingInsightsUsersDetails = async (args: CreateApiApiV2BillingInsightsUsersDetailsArgs, options?: CreateApiApiV2BillingInsightsUsersDetailsOptions) => { const {baseUrl = "https://billing-insights.api.relativity.one/billing-drilldown-api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/billing-insights/users-details${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(getUsersDetailsResponse, await res.json()) };