import { googleTriggerDefinitions as triggerDefinitions } from "@automate.ax/catalog/triggers/google" import { GOOGLE_SHEETS_CELLS_CHANGED_EVENT_SCHEMA, parseGoogleSheetsA1Range, normalizeGoogleSheetsSpreadsheetId, type GoogleSheetsTriggerRange, } from "@automate.ax/integration-contracts/google-sheets" import { createTrigger } from "../../automation/create-trigger" import type { IntegrationAccountReference } from "../../automation/integrations" export { GOOGLE_SHEETS_CELLS_CHANGED_EVENT_SCHEMA } /** Options for observing net cell value changes in a spreadsheet. */ export interface OnGoogleSheetsCellsChangedOptions { /** * Google account binding used to read and watch the spreadsheet. * * Omitting this value uses the project's default Google account binding. */ account?: string | IntegrationAccountReference<"google"> /** * Optional monitored range as A1 notation or one-based grid bounds. * * Omit this value to monitor every sheet in the spreadsheet. */ range?: GoogleSheetsTriggerRange /** Google Sheets spreadsheet ID or standard spreadsheet URL. */ spreadsheet: string } /** * Subscribes to batches of net formula and effective-value changes. * * Google supplies a file-change wake-up signal. Automate.ax reads the current * spreadsheet and compares it with the preceding complete observation. */ export const onGoogleSheetsCellsChanged = createTrigger( triggerDefinitions.googleSheetsCellsChanged, (options: OnGoogleSheetsCellsChangedOptions) => { if (typeof options.range === "string") { parseGoogleSheetsA1Range(options.range) } return { account: options.account, range: typeof options.range === "string" ? options.range.trim() : options.range, spreadsheetId: normalizeGoogleSheetsSpreadsheetId(options.spreadsheet), } }, )