Files
klz-cables.com/.pnpm-store/v10/files/2c/47194bdc5bb7bf86d58aeab93fa40db11b17b8f434dfb6f29c290c94aa658635de79c1d152f2e9f1658b47d24269b5d7f7f711ad4824e745a7a38ab368a317
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
5.9 KiB
Plaintext

{"version":3,"sources":["../../src/utilities/checkDocumentLockStatus.ts"],"sourcesContent":["import type { TypeWithID } from '../collections/config/types.js'\nimport type { PaginatedDocs } from '../database/types.js'\nimport type { JsonObject, PayloadRequest } from '../types/index.js'\n\nimport { Locked } from '../errors/index.js'\nimport { lockedDocumentsCollectionSlug } from '../locked-documents/config.js'\n\ntype CheckDocumentLockStatusArgs = {\n collectionSlug?: string\n globalSlug?: string\n id?: number | string\n lockDurationDefault?: number\n lockErrorMessage?: string\n overrideLock?: boolean\n req: PayloadRequest\n}\n\nexport const checkDocumentLockStatus = async ({\n id,\n collectionSlug,\n globalSlug,\n lockDurationDefault = 300, // Default 5 minutes in seconds\n lockErrorMessage,\n overrideLock = true,\n req,\n}: CheckDocumentLockStatusArgs): Promise<void> => {\n const { payload } = req\n\n // Check if the locked-documents collection exists\n if (!payload.collections?.[lockedDocumentsCollectionSlug]) {\n // If the collection doesn't exist, locking is not available\n return\n }\n\n // Retrieve the lockDocuments property for either collection or global\n const lockDocumentsProp = collectionSlug\n ? payload.collections?.[collectionSlug]?.config?.lockDocuments\n : payload.config?.globals?.find((g) => g.slug === globalSlug)?.lockDocuments\n\n const isLockingEnabled = lockDocumentsProp !== false\n\n let lockedDocumentQuery = {}\n\n if (collectionSlug) {\n lockedDocumentQuery = {\n and: [\n { 'document.relationTo': { equals: collectionSlug } },\n { 'document.value': { equals: id } },\n ],\n }\n } else if (globalSlug) {\n lockedDocumentQuery = { globalSlug: { equals: globalSlug } }\n } else {\n throw new Error('Either collectionSlug or globalSlug must be provided.')\n }\n\n if (!isLockingEnabled) {\n return\n }\n\n // Only perform lock checks if overrideLock is false and locking is enabled\n if (!overrideLock) {\n const defaultLockErrorMessage = collectionSlug\n ? `Document with ID ${id} is currently locked by another user and cannot be modified.`\n : `Global document with slug \"${globalSlug}\" is currently locked by another user and cannot be modified.`\n\n const finalLockErrorMessage = lockErrorMessage || defaultLockErrorMessage\n\n const lockedDocumentResult: PaginatedDocs<JsonObject & TypeWithID> = await payload.db.find({\n collection: lockedDocumentsCollectionSlug,\n limit: 1,\n pagination: false,\n sort: '-updatedAt',\n where: lockedDocumentQuery,\n })\n\n // If there's a locked document, check lock conditions\n const lockedDoc = lockedDocumentResult?.docs[0]\n if (lockedDoc) {\n const lastEditedAt = new Date(lockedDoc?.updatedAt).getTime()\n const now = new Date().getTime()\n\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n\n const lockDurationInMilliseconds = lockDuration * 1000\n const currentUserId = req.user?.id\n\n // document is locked by another user and the lock hasn't expired\n if (\n lockedDoc.user?.value !== currentUserId &&\n now - lastEditedAt <= lockDurationInMilliseconds\n ) {\n throw new Locked(finalLockErrorMessage)\n }\n }\n }\n\n // Perform the delete operation regardless of overrideLock status\n await payload.db.deleteMany({\n collection: lockedDocumentsCollectionSlug,\n // Not passing req fails on postgres\n req: payload.db.name === 'mongoose' ? undefined : req,\n where: lockedDocumentQuery,\n })\n}\n"],"names":["Locked","lockedDocumentsCollectionSlug","checkDocumentLockStatus","id","collectionSlug","globalSlug","lockDurationDefault","lockErrorMessage","overrideLock","req","payload","collections","lockDocumentsProp","config","lockDocuments","globals","find","g","slug","isLockingEnabled","lockedDocumentQuery","and","equals","Error","defaultLockErrorMessage","finalLockErrorMessage","lockedDocumentResult","db","collection","limit","pagination","sort","where","lockedDoc","docs","lastEditedAt","Date","updatedAt","getTime","now","lockDuration","duration","lockDurationInMilliseconds","currentUserId","user","value","deleteMany","name","undefined"],"mappings":"AAIA,SAASA,MAAM,QAAQ,qBAAoB;AAC3C,SAASC,6BAA6B,QAAQ,gCAA+B;AAY7E,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,EAAE,EACFC,cAAc,EACdC,UAAU,EACVC,sBAAsB,GAAG,EACzBC,gBAAgB,EAChBC,eAAe,IAAI,EACnBC,GAAG,EACyB;IAC5B,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,kDAAkD;IAClD,IAAI,CAACC,QAAQC,WAAW,EAAE,CAACV,8BAA8B,EAAE;QACzD,4DAA4D;QAC5D;IACF;IAEA,sEAAsE;IACtE,MAAMW,oBAAoBR,iBACtBM,QAAQC,WAAW,EAAE,CAACP,eAAe,EAAES,QAAQC,gBAC/CJ,QAAQG,MAAM,EAAEE,SAASC,KAAK,CAACC,IAAMA,EAAEC,IAAI,KAAKb,aAAaS;IAEjE,MAAMK,mBAAmBP,sBAAsB;IAE/C,IAAIQ,sBAAsB,CAAC;IAE3B,IAAIhB,gBAAgB;QAClBgB,sBAAsB;YACpBC,KAAK;gBACH;oBAAE,uBAAuB;wBAAEC,QAAQlB;oBAAe;gBAAE;gBACpD;oBAAE,kBAAkB;wBAAEkB,QAAQnB;oBAAG;gBAAE;aACpC;QACH;IACF,OAAO,IAAIE,YAAY;QACrBe,sBAAsB;YAAEf,YAAY;gBAAEiB,QAAQjB;YAAW;QAAE;IAC7D,OAAO;QACL,MAAM,IAAIkB,MAAM;IAClB;IAEA,IAAI,CAACJ,kBAAkB;QACrB;IACF;IAEA,2EAA2E;IAC3E,IAAI,CAACX,cAAc;QACjB,MAAMgB,0BAA0BpB,iBAC5B,CAAC,iBAAiB,EAAED,GAAG,4DAA4D,CAAC,GACpF,CAAC,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