import {z} from 'zod' export type GetApiV1AccountsAccountsIdInvitationsArgs = {accountsId: string, filter?: string | undefined}; export type GetApiV1AccountsAccountsIdInvitationsOptions = {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 targetLocation = z.object({address: z.string().optional(), locationName: z.string().optional(), placeId: z.string().optional()}); export const invitation = z.object({name: z.string().optional(), role: z.enum(["ADMIN_ROLE_UNSPECIFIED", "PRIMARY_OWNER", "OWNER", "MANAGER", "SITE_MANAGER"]).optional(), targetAccount: account.optional(), targetLocation: targetLocation.optional(), targetType: z.enum(["TARGET_TYPE_UNSPECIFIED", "ACCOUNTS_ONLY", "LOCATIONS_ONLY"]).optional()}); export const listInvitationsResponse = z.object({invitations: z.array(invitation).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 }; /** * Lists pending invitations for the specified account. * * GET /v1/accounts/{accountsId}/invitations */ export const getApiV1AccountsAccountsIdInvitations = async (args: GetApiV1AccountsAccountsIdInvitationsArgs, options?: GetApiV1AccountsAccountsIdInvitationsOptions) => { const {baseUrl = "https://mybusinessaccountmanagement.googleapis.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountsId))}/invitations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listInvitationsResponse, await res.json()) };