use installed triggers

cannot call external services from default triggers
This commit is contained in:
Ben Miller
2024-11-14 00:50:05 -07:00
parent a5c0a1176d
commit 9b01d6de8a
3 changed files with 34 additions and 5 deletions

View File

@ -1,13 +1,20 @@
/// <reference types="@types/google-apps-script" /> /// <reference types="@types/google-apps-script" />
import { onOpen } from "./onOpen" import { onOpen } from "./onOpen"
import { onEdit } from "./onEdit"
import { getShopifyProducts } from "./shopifyApi" import { getShopifyProducts } from "./shopifyApi"
import { runShopifyOrders } from "./shopifyApi" import { runShopifyOrders } from "./shopifyApi"
import { matchProductToShopifyHandler } from "./initMenu" import {
initMenu,
;(global as any).onOpen = () => onOpen() matchProductToShopifyHandler,
;(global as any).onEdit = (e: GoogleAppsScript.Events.SheetsOnEdit) => onEdit(e) reauthorizeScript,
} from "./initMenu"
import { reinstallTriggers } from "./triggers"
import { newSkuHandler } from "./newSku"
;(global as any).onOpen = onOpen
;(global as any).initMenu = initMenu
;(global as any).getShopifyProducts = getShopifyProducts ;(global as any).getShopifyProducts = getShopifyProducts
;(global as any).runShopifyOrders = runShopifyOrders ;(global as any).runShopifyOrders = runShopifyOrders
;(global as any).matchProductToShopifyHandler = matchProductToShopifyHandler ;(global as any).matchProductToShopifyHandler = matchProductToShopifyHandler
;(global as any).reauthorizeScript = reauthorizeScript
;(global as any).reinstallTriggers = reinstallTriggers
;(global as any).newSkuHandler = newSkuHandler

View File

@ -2,6 +2,7 @@ import { getShopifyProducts, runShopifyOrders } from "./shopifyApi"
import { fillProductFromTemplate } from "./fillProductFromTemplate" import { fillProductFromTemplate } from "./fillProductFromTemplate"
import { createMissingPhotoFolders } from "./createMissingPhotoFolders" import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
import { matchProductToShopify } from "./match" import { matchProductToShopify } from "./match"
import { reinstallTriggers } from "./triggers"
export function initMenu() { export function initMenu() {
let ui = SpreadsheetApp.getUi() let ui = SpreadsheetApp.getUi()
@ -20,6 +21,13 @@ export function initMenu() {
.addItem("Run Shopify Orders", runShopifyOrders.name) .addItem("Run Shopify Orders", runShopifyOrders.name)
.addItem("Get Shopify Products", getShopifyProducts.name) .addItem("Get Shopify Products", getShopifyProducts.name)
) )
.addSeparator()
.addSubMenu(
ui
.createMenu("Utilities...")
.addItem("Reauthorize script", reauthorizeScript.name)
.addItem("Reinstall triggers", reinstallTriggers.name)
)
.addToUi() .addToUi()
} }
@ -32,3 +40,7 @@ export function matchProductToShopifyHandler() {
let row = SpreadsheetApp.getCurrentCell().getRow() let row = SpreadsheetApp.getCurrentCell().getRow()
matchProductToShopify(row) matchProductToShopify(row)
} }
export function reauthorizeScript() {
ScriptApp.invalidateAuth()
}

10
src/triggers.ts Normal file
View File

@ -0,0 +1,10 @@
export function reinstallTriggers() {
let currentTriggers = ScriptApp.getProjectTriggers()
for (let i = 0; i < currentTriggers.length; i++) {
ScriptApp.deleteTrigger(currentTriggers[i])
}
let ss = SpreadsheetApp.getActive()
ScriptApp.newTrigger("newSkuHandler").forSpreadsheet(ss).onEdit().create()
ScriptApp.newTrigger("matchProductToShopifyHandler").forSpreadsheet(ss).onEdit().create()
}