Files
klz-cables.com/.pnpm-store/v10/files/c3/4a29b6ee8e53f2c17a0ec53cfa6e2497e23d3114e13adee65dfff3e2f051f52ffa53a085f37dbd231874062f97d1e252c73ad9c04a1ff5b9dc518354c0c91d
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

1 line
4.4 KiB
Plaintext

{"version":3,"file":"handlePreview.js","names":["extractJWT","isPreviewEnabled","collectionConfig","globalConfig","Boolean","admin","preview","handlePreview","collectionSlug","config","data","globalSlug","operation","req","payload","collections","undefined","globals","find","g","slug","enabled","generatePreviewURL","token","previewURL","result","locale","err","logger","error","msg"],"sources":["../../src/utilities/handlePreview.ts"],"sourcesContent":["import {\n type CollectionConfig,\n extractJWT,\n type GlobalConfig,\n type Operation,\n type PayloadRequest,\n type SanitizedConfig,\n} from 'payload'\n\n/**\n * Multi-level check to determine whether live preview is enabled on a collection or global.\n * For example, live preview can be enabled at both the root config level, or on the entity's config.\n * If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,\n * or on the entity's own config.\n */\nexport const isPreviewEnabled = ({\n collectionConfig,\n globalConfig,\n}: {\n collectionConfig?: CollectionConfig\n globalConfig?: GlobalConfig\n}): boolean => {\n if (globalConfig) {\n return Boolean(globalConfig.admin?.preview)\n }\n\n if (collectionConfig) {\n return Boolean(collectionConfig.admin?.preview)\n }\n}\n\n/**\n * 1. Looks up the relevant live preview config, which could have been enabled:\n * a. At the root level, e.g. `collections: ['posts']`\n * b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`\n * 2. Determines if live preview is enabled, and if not, early returns.\n * 3. Merges the config with the root config, if necessary.\n * 4. Executes the `url` function, if necessary.\n *\n * Notice: internal function only. Subject to change at any time. Use at your own risk.\n */\nexport const handlePreview = async ({\n collectionSlug,\n config,\n data,\n globalSlug,\n operation,\n req,\n}: {\n collectionSlug?: string\n config: SanitizedConfig\n data: Record<string, unknown>\n globalSlug?: string\n operation?: Operation\n req: PayloadRequest\n}): Promise<{\n isPreviewEnabled?: boolean\n previewURL?: string\n}> => {\n const collectionConfig = collectionSlug\n ? req.payload.collections[collectionSlug]?.config\n : undefined\n\n const globalConfig = globalSlug ? config.globals.find((g) => g.slug === globalSlug) : undefined\n\n const enabled = isPreviewEnabled({\n collectionConfig,\n globalConfig,\n })\n\n if (!enabled) {\n return {}\n }\n\n const generatePreviewURL = collectionConfig?.admin?.preview || globalConfig?.admin?.preview\n const token = extractJWT(req)\n let previewURL: string | undefined\n\n if (typeof generatePreviewURL === 'function' && operation !== 'create') {\n try {\n const result = await generatePreviewURL(data, { locale: req.locale, req, token })\n\n if (typeof result === 'string') {\n previewURL = result\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `There was an error executing the live preview URL function for ${collectionSlug || globalSlug}`,\n })\n }\n }\n\n return { isPreviewEnabled: enabled, previewURL }\n}\n"],"mappings":"AAAA,SAEEA,UAAU,QAKL;AAEP;;;;;;AAMA,OAAO,MAAMC,gBAAA,GAAmBA,CAAC;EAC/BC,gBAAgB;EAChBC;AAAY,CAIb;EACC,IAAIA,YAAA,EAAc;IAChB,OAAOC,OAAA,CAAQD,YAAA,CAAaE,KAAK,EAAEC,OAAA;EACrC;EAEA,IAAIJ,gBAAA,EAAkB;IACpB,OAAOE,OAAA,CAAQF,gBAAA,CAAiBG,KAAK,EAAEC,OAAA;EACzC;AACF;AAEA;;;;;;;;;;AAUA,OAAO,MAAMC,aAAA,GAAgB,MAAAA,CAAO;EAClCC,cAAc;EACdC,MAAM;EACNC,IAAI;EACJC,UAAU;EACVC,SAAS;EACTC;AAAG,CAQJ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