import {z} from 'zod' export type HeldAccount = {accountId?: string | undefined, email?: string | undefined, firstName?: string | undefined, holdTime?: unknown | undefined, lastName?: string | undefined}; export type HeldOrgUnit = {holdTime?: unknown | undefined, orgUnitId?: string | undefined}; export type HeldCalendarQuery = Record; export type HeldDriveQuery = {includeSharedDriveFiles?: boolean | undefined, includeTeamDriveFiles?: boolean | undefined}; export type HeldGeminiQuery = Record; export type HeldGroupsQuery = {endTime?: unknown | undefined, startTime?: unknown | undefined, terms?: string | undefined}; export type HeldHangoutsChatQuery = {includeRooms?: boolean | undefined}; export type HeldMailQuery = {endTime?: unknown | undefined, startTime?: unknown | undefined, terms?: string | undefined}; export type HeldVoiceQuery = {coveredData?: (Array<'COVERED_DATA_UNSPECIFIED' | 'TEXT_MESSAGES' | 'VOICEMAILS' | 'CALL_LOGS'>) | undefined}; export type CorpusQuery = {calendarQuery?: HeldCalendarQuery | undefined, driveQuery?: HeldDriveQuery | undefined, geminiQuery?: HeldGeminiQuery | undefined, groupsQuery?: HeldGroupsQuery | undefined, hangoutsChatQuery?: HeldHangoutsChatQuery | undefined, mailQuery?: HeldMailQuery | undefined, voiceQuery?: HeldVoiceQuery | undefined}; export type Hold = {accounts?: Array | undefined, corpus?: ('CORPUS_TYPE_UNSPECIFIED' | 'DRIVE' | 'MAIL' | 'GROUPS' | 'HANGOUTS_CHAT' | 'VOICE' | 'CALENDAR' | 'GEMINI' | 'GEMINI_IN_WORKSPACE') | undefined, holdId?: string | undefined, name?: string | undefined, orgUnit?: HeldOrgUnit | undefined, query?: CorpusQuery | undefined, updateTime?: unknown | undefined}; export type CreateApiV1MattersMatterIdHoldsArgs = {matterId: string, body: Hold}; export type CreateApiV1MattersMatterIdHoldsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const heldAccount = z.object({accountId: z.string().optional(), email: z.string().optional(), firstName: z.string().optional(), holdTime: z.string().optional(), lastName: z.string().optional()}); export const heldOrgUnit = z.object({holdTime: z.string().optional(), orgUnitId: z.string().optional()}); export const heldCalendarQuery = z.object({}); export const heldDriveQuery = z.object({includeSharedDriveFiles: z.boolean().optional(), includeTeamDriveFiles: z.boolean().optional()}); export const heldGeminiQuery = z.object({}); export const heldGroupsQuery = z.object({endTime: z.string().optional(), startTime: z.string().optional(), terms: z.string().optional()}); export const heldHangoutsChatQuery = z.object({includeRooms: z.boolean().optional()}); export const heldMailQuery = z.object({endTime: z.string().optional(), startTime: z.string().optional(), terms: z.string().optional()}); export const heldVoiceQuery = z.object({coveredData: z.array(z.enum(["COVERED_DATA_UNSPECIFIED", "TEXT_MESSAGES", "VOICEMAILS", "CALL_LOGS"])).optional()}); export const corpusQuery = z.object({calendarQuery: heldCalendarQuery.optional(), driveQuery: heldDriveQuery.optional(), geminiQuery: heldGeminiQuery.optional(), groupsQuery: heldGroupsQuery.optional(), hangoutsChatQuery: heldHangoutsChatQuery.optional(), mailQuery: heldMailQuery.optional(), voiceQuery: heldVoiceQuery.optional()}); export const hold = z.object({accounts: z.array(heldAccount).optional(), corpus: z.enum(["CORPUS_TYPE_UNSPECIFIED", "DRIVE", "MAIL", "GROUPS", "HANGOUTS_CHAT", "VOICE", "CALENDAR", "GEMINI", "GEMINI_IN_WORKSPACE"]).optional(), holdId: z.string().optional(), name: z.string().optional(), orgUnit: heldOrgUnit.optional(), query: corpusQuery.optional(), updateTime: z.string().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 }; /** * Creates a hold in the specified matter. * * POST /v1/matters/{matterId}/holds */ export const createApiV1MattersMatterIdHolds = async (args: CreateApiV1MattersMatterIdHoldsArgs, options?: CreateApiV1MattersMatterIdHoldsOptions) => { const {baseUrl = "https://vault.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/matters/${encodeURIComponent(String(args.matterId))}/holds${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(hold, await res.json()) };