import {z} from 'zod' export type GoogleAdsSearchads360V23CommonConsent = {adPersonalization?: ('UNSPECIFIED' | 'UNKNOWN' | 'GRANTED' | 'DENIED') | undefined, adUserData?: ('UNSPECIFIED' | 'UNKNOWN' | 'GRANTED' | 'DENIED') | undefined}; export type GoogleAdsSearchads360V23CommonCustomerMatchUserListMetadata = {consent?: GoogleAdsSearchads360V23CommonConsent | undefined, userList?: string | undefined}; export type GoogleAdsSearchads360V23ResourcesOfflineUserDataJobMetadata = {matchRateRange?: ('UNSPECIFIED' | 'UNKNOWN' | 'MATCH_RANGE_LESS_THAN_20' | 'MATCH_RANGE_20_TO_30' | 'MATCH_RANGE_31_TO_40' | 'MATCH_RANGE_41_TO_50' | 'MATCH_RANGE_51_TO_60' | 'MATCH_RANGE_61_TO_70' | 'MATCH_RANGE_71_TO_80' | 'MATCH_RANGE_81_TO_90' | 'MATCH_RANGE_91_TO_100') | undefined}; export type GoogleAdsSearchads360V23CommonStoreSalesThirdPartyMetadata = {advertiserUploadDateTime?: string | undefined, bridgeMapVersionId?: string | undefined, partnerId?: unknown | undefined, partnerMatchFraction?: number | undefined, partnerUploadFraction?: number | undefined, validTransactionFraction?: number | undefined}; export type GoogleAdsSearchads360V23CommonStoreSalesMetadata = {customKey?: string | undefined, loyaltyFraction?: number | undefined, thirdPartyMetadata?: GoogleAdsSearchads360V23CommonStoreSalesThirdPartyMetadata | undefined, transactionUploadFraction?: number | undefined}; export type GoogleAdsSearchads360V23ResourcesOfflineUserDataJob = {customerMatchUserListMetadata?: GoogleAdsSearchads360V23CommonCustomerMatchUserListMetadata | undefined, externalId?: unknown | undefined, failureReason?: ('UNSPECIFIED' | 'UNKNOWN' | 'INSUFFICIENT_MATCHED_TRANSACTIONS' | 'INSUFFICIENT_TRANSACTIONS' | 'HIGH_AVERAGE_TRANSACTION_VALUE' | 'LOW_AVERAGE_TRANSACTION_VALUE' | 'NEWLY_OBSERVED_CURRENCY_CODE') | undefined, id?: unknown | undefined, operationMetadata?: GoogleAdsSearchads360V23ResourcesOfflineUserDataJobMetadata | undefined, resourceName?: string | undefined, status?: ('UNSPECIFIED' | 'UNKNOWN' | 'PENDING' | 'RUNNING' | 'SUCCESS' | 'FAILED') | undefined, storeSalesMetadata?: GoogleAdsSearchads360V23CommonStoreSalesMetadata | undefined, type?: ('UNSPECIFIED' | 'UNKNOWN' | 'STORE_SALES_UPLOAD_FIRST_PARTY' | 'STORE_SALES_UPLOAD_THIRD_PARTY' | 'CUSTOMER_MATCH_USER_LIST' | 'CUSTOMER_MATCH_WITH_ATTRIBUTES') | undefined}; export type GoogleAdsSearchads360V23ServicesCreateOfflineUserDataJobRequest = {enableMatchRateRangePreview?: boolean | undefined, job?: GoogleAdsSearchads360V23ResourcesOfflineUserDataJob | undefined, validateOnly?: boolean | undefined}; export type CreateApiV23CustomersCustomersIdOfflineUserDataJobsCreateArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesCreateOfflineUserDataJobRequest}; export type CreateApiV23CustomersCustomersIdOfflineUserDataJobsCreateOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23ServicesCreateOfflineUserDataJobResponse = z.object({resourceName: 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 an offline user data job. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [NotAllowlistedError]() [OfflineUserDataJobError]() [QuotaError]() [RequestError]() * * POST /v23/customers/{customersId}/offlineUserDataJobs:create */ export const createApiV23CustomersCustomersIdOfflineUserDataJobsCreate = async (args: CreateApiV23CustomersCustomersIdOfflineUserDataJobsCreateArgs, options?: CreateApiV23CustomersCustomersIdOfflineUserDataJobsCreateOptions) => { const {baseUrl = "https://searchads360.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(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}/offlineUserDataJobs:create${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(googleAdsSearchads360V23ServicesCreateOfflineUserDataJobResponse, await res.json()) };