import {z} from 'zod' export type PostalAddress = {addressLines?: Array | undefined, administrativeArea?: string | undefined, languageCode?: string | undefined, locality?: string | undefined, organization?: string | undefined, postalCode?: string | undefined, recipients?: Array | undefined, regionCode?: string | undefined, revision?: number | undefined, sortingCode?: string | undefined, sublocality?: string | undefined}; export type OrganizationInfo = {address?: PostalAddress | undefined, phoneNumber?: string | undefined, registeredDomain?: string | undefined}; export type Account = {accountName?: string | undefined, accountNumber?: string | undefined, name?: string | undefined, organizationInfo?: OrganizationInfo | undefined, permissionLevel?: ('PERMISSION_LEVEL_UNSPECIFIED' | 'OWNER_LEVEL' | 'MEMBER_LEVEL') | undefined, primaryOwner?: string | undefined, role?: ('ACCOUNT_ROLE_UNSPECIFIED' | 'PRIMARY_OWNER' | 'OWNER' | 'MANAGER' | 'SITE_MANAGER') | undefined, type?: ('ACCOUNT_TYPE_UNSPECIFIED' | 'PERSONAL' | 'LOCATION_GROUP' | 'USER_GROUP' | 'ORGANIZATION') | undefined, verificationState?: ('VERIFICATION_STATE_UNSPECIFIED' | 'VERIFIED' | 'UNVERIFIED' | 'VERIFICATION_REQUESTED') | undefined, vettedState?: ('VETTED_STATE_UNSPECIFIED' | 'NOT_VETTED' | 'VETTED' | 'INVALID') | undefined}; export type PatchApiV1AccountsAccountsIdArgs = {accountsId: string, updateMask?: unknown | undefined, validateOnly?: boolean | undefined, body: Account}; export type PatchApiV1AccountsAccountsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const postalAddress = z.object({addressLines: z.array(z.string()).optional(), administrativeArea: z.string().optional(), languageCode: z.string().optional(), locality: z.string().optional(), organization: z.string().optional(), postalCode: z.string().optional(), recipients: z.array(z.string()).optional(), regionCode: z.string().optional(), revision: z.number().int().optional(), sortingCode: z.string().optional(), sublocality: z.string().optional()}); export const organizationInfo = z.object({address: postalAddress.optional(), phoneNumber: z.string().optional(), registeredDomain: z.string().optional()}); export const account = z.object({accountName: z.string().optional(), accountNumber: z.string().optional(), name: z.string().optional(), organizationInfo: organizationInfo.optional(), permissionLevel: z.enum(["PERMISSION_LEVEL_UNSPECIFIED", "OWNER_LEVEL", "MEMBER_LEVEL"]).optional(), primaryOwner: z.string().optional(), role: z.enum(["ACCOUNT_ROLE_UNSPECIFIED", "PRIMARY_OWNER", "OWNER", "MANAGER", "SITE_MANAGER"]).optional(), type: z.enum(["ACCOUNT_TYPE_UNSPECIFIED", "PERSONAL", "LOCATION_GROUP", "USER_GROUP", "ORGANIZATION"]).optional(), verificationState: z.enum(["VERIFICATION_STATE_UNSPECIFIED", "VERIFIED", "UNVERIFIED", "VERIFICATION_REQUESTED"]).optional(), vettedState: z.enum(["VETTED_STATE_UNSPECIFIED", "NOT_VETTED", "VETTED", "INVALID"]).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 }; /** * Updates the specified business account. Personal accounts cannot be updated using this method. * * PATCH /v1/accounts/{accountsId} */ export const patchApiV1AccountsAccountsId = async (args: PatchApiV1AccountsAccountsIdArgs, options?: PatchApiV1AccountsAccountsIdOptions) => { const {baseUrl = "https://mybusinessaccountmanagement.googleapis.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (args.validateOnly != null) query.append("validateOnly", String(args.validateOnly)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(account, await res.json()) };