import {z} from 'zod' export type GoogleCloudContactcenterinsightsV1ExactMatchConfig = {caseSensitive?: boolean | undefined}; export type GoogleCloudContactcenterinsightsV1RegexMatchConfig = Record; export type GoogleCloudContactcenterinsightsV1PhraseMatchRuleConfig = {exactMatchConfig?: GoogleCloudContactcenterinsightsV1ExactMatchConfig | undefined, regexMatchConfig?: GoogleCloudContactcenterinsightsV1RegexMatchConfig | undefined}; export type GoogleCloudContactcenterinsightsV1PhraseMatchRule = {config?: GoogleCloudContactcenterinsightsV1PhraseMatchRuleConfig | undefined, negated?: boolean | undefined, query?: string | undefined}; export type GoogleCloudContactcenterinsightsV1PhraseMatchRuleGroup = {phraseMatchRules?: Array | undefined, type?: ('PHRASE_MATCH_RULE_GROUP_TYPE_UNSPECIFIED' | 'ALL_OF' | 'ANY_OF') | undefined}; export type GoogleCloudContactcenterinsightsV1PhraseMatcher = {activationUpdateTime?: unknown | undefined, active?: boolean | undefined, displayName?: string | undefined, name?: string | undefined, phraseMatchRuleGroups?: Array | undefined, revisionCreateTime?: unknown | undefined, revisionId?: string | undefined, roleMatch?: ('ROLE_UNSPECIFIED' | 'HUMAN_AGENT' | 'AUTOMATED_AGENT' | 'END_USER' | 'ANY_AGENT') | undefined, type?: ('PHRASE_MATCHER_TYPE_UNSPECIFIED' | 'ALL_OF' | 'ANY_OF') | undefined, updateTime?: unknown | undefined, versionTag?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPhraseMatchersArgs = {projectsId: string, locationsId: string, body: GoogleCloudContactcenterinsightsV1PhraseMatcher}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPhraseMatchersOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudContactcenterinsightsV1ExactMatchConfig = z.object({caseSensitive: z.boolean().optional()}); export const googleCloudContactcenterinsightsV1RegexMatchConfig = z.object({}); export const googleCloudContactcenterinsightsV1PhraseMatchRuleConfig = z.object({exactMatchConfig: googleCloudContactcenterinsightsV1ExactMatchConfig.optional(), regexMatchConfig: googleCloudContactcenterinsightsV1RegexMatchConfig.optional()}); export const googleCloudContactcenterinsightsV1PhraseMatchRule = z.object({config: googleCloudContactcenterinsightsV1PhraseMatchRuleConfig.optional(), negated: z.boolean().optional(), query: z.string().optional()}); export const googleCloudContactcenterinsightsV1PhraseMatchRuleGroup = z.object({phraseMatchRules: z.array(googleCloudContactcenterinsightsV1PhraseMatchRule).optional(), type: z.enum(["PHRASE_MATCH_RULE_GROUP_TYPE_UNSPECIFIED", "ALL_OF", "ANY_OF"]).optional()}); export const googleCloudContactcenterinsightsV1PhraseMatcher = z.object({activationUpdateTime: z.string().optional(), active: z.boolean().optional(), displayName: z.string().optional(), name: z.string().optional(), phraseMatchRuleGroups: z.array(googleCloudContactcenterinsightsV1PhraseMatchRuleGroup).optional(), revisionCreateTime: z.string().optional(), revisionId: z.string().optional(), roleMatch: z.enum(["ROLE_UNSPECIFIED", "HUMAN_AGENT", "AUTOMATED_AGENT", "END_USER", "ANY_AGENT"]).optional(), type: z.enum(["PHRASE_MATCHER_TYPE_UNSPECIFIED", "ALL_OF", "ANY_OF"]).optional(), updateTime: z.string().optional(), versionTag: 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 phrase matcher. * * POST /v1/projects/{projectsId}/locations/{locationsId}/phraseMatchers */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdPhraseMatchers = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPhraseMatchersArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPhraseMatchersOptions) => { const {baseUrl = "https://contactcenterinsights.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/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/phraseMatchers${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(googleCloudContactcenterinsightsV1PhraseMatcher, await res.json()) };