Files
product_inventory/src/global.ts
Ben Miller 7c35817313 Refactor Media Manager sync logic and fix duplication bugs
This major refactor addresses improper image matching and duplication:

- Implemented strict ID-based matching in 'MediaService', removing the greedy filename matching fallback.

- Redesigned synchronization pipeline to treat Google Drive as the Source of Truth, supporting orphan adoption (Shopify -> Drive) and secure uploads.

- Implemented 'gallery_order' using Drive file properties (supporting both v2 and v3 APIs) for stable, drag-and-drop global ordering.

- Added conditional file renaming using timestamps to enforce '_' naming convention without unnecessary renames.

- Fixed runtime errors in 'MediaService' loops and updated 'ShopifyMediaService' GraphQL mutations to match correctly schema.

- Rewrote 'MediaService.test.ts' with robust test cases for strict matching, adoption, sorting, and reordering.
2025-12-28 12:25:13 -07:00

67 lines
3.3 KiB
TypeScript

/// <reference types="@types/google-apps-script" />
import { onOpen } from "./onOpen"
import { matchProductToShopifyOnEditHandler } from "./OnEditHandler"
import { getShopifyProducts } from "./shopifyApi"
import { runShopifyOrders } from "./shopifyApi"
import {
initMenu,
matchProductToShopifyHandler,
updateShopifyProductHandler,
reauthorizeScript,
} from "./initMenu"
import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
import { reinstallTriggers } from "./triggers"
import { newSkuHandler } from "./newSku"
import { columnOnEditHandler, onEditHandler } from "./OnEditHandler"
import {
onEditQueue,
processBatchedEdits
} from "./onEditQueue"
import { fillProductFromTemplate } from "./fillProductFromTemplate"
import { showSidebar, getQueueStatus, setQueueEnabled, deleteEdit, pushEdit } from "./sidebar"
import { checkRecentSales, reconcileSalesHandler } from "./salesSync"
import { installSalesSyncTrigger } from "./triggers"
import { showMediaManager, getSelectedSku, getMediaForSku, saveFileToDrive, saveMediaChanges, getMediaDiagnostics, getPickerConfig, importFromPicker, debugScopes, createPhotoSession, checkPhotoSession, debugFolderAccess } from "./mediaHandlers"
import { runSystemDiagnostics } from "./verificationSuite"
// prettier-ignore
;(global as any).onOpen = onOpen
;(global as any).initMenu = initMenu
;(global as any).getShopifyProducts = getShopifyProducts
;(global as any).runShopifyOrders = runShopifyOrders
;(global as any).matchProductToShopifyHandler = matchProductToShopifyHandler
;(global as any).matchProductToShopifyOnEditHandler = matchProductToShopifyOnEditHandler
;(global as any).updateShopifyProductHandler = updateShopifyProductHandler
;(global as any).columnOnEditHandler = columnOnEditHandler
;(global as any).onEditHandler = onEditHandler
;(global as any).onEditQueue = onEditQueue
;(global as any).processBatchedEdits = processBatchedEdits
;(global as any).reauthorizeScript = reauthorizeScript
;(global as any).reinstallTriggers = reinstallTriggers
;(global as any).newSkuHandler = newSkuHandler
;(global as any).fillProductFromTemplate = fillProductFromTemplate
;(global as any).createMissingPhotoFolders = createMissingPhotoFolders
;(global as any).showSidebar = showSidebar
;(global as any).getQueueStatus = getQueueStatus
;(global as any).setQueueEnabled = setQueueEnabled
;(global as any).deleteEdit = deleteEdit
;(global as any).pushEdit = pushEdit
;(global as any).checkRecentSales = checkRecentSales
;(global as any).reconcileSalesHandler = reconcileSalesHandler
;(global as any).installSalesSyncTrigger = installSalesSyncTrigger
;(global as any).showMediaManager = showMediaManager
;(global as any).getSelectedSku = getSelectedSku
;(global as any).getMediaForSku = getMediaForSku
;(global as any).saveFileToDrive = saveFileToDrive
;(global as any).saveMediaChanges = saveMediaChanges
;(global as any).getMediaDiagnostics = getMediaDiagnostics
;(global as any).getPickerConfig = getPickerConfig
;(global as any).importFromPicker = importFromPicker
;(global as any).runSystemDiagnostics = runSystemDiagnostics
;(global as any).debugScopes = debugScopes
;(global as any).createPhotoSession = createPhotoSession
;(global as any).checkPhotoSession = checkPhotoSession
;(global as any).debugFolderAccess = debugFolderAccess