Files
klz-cables.com/.pnpm-store/v10/files/ae/e4377a0fc2e9dddcc7fd3f015bf16f40c9b601852ada114ef3d7c4e8ec454758958be24d58fea83acf7e5991e1c9195a55008fb55cbcef93cab7a530a77124
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

110 lines
2.8 KiB
Plaintext

import { initI18n } from '@payloadcms/translations';
import { headers as getHeaders } from 'next/headers.js';
import { createLocalReq, executeAuthStrategies, getAccessResults, getPayload, getRequestLanguage, parseCookies } from 'payload';
import { getRequestLocale } from './getRequestLocale.js';
import { selectiveCache } from './selectiveCache.js';
// Create cache instances for different parts of our application
const partialReqCache = selectiveCache('partialReq');
const reqCache = selectiveCache('req');
/**
* Initializes a full request object, including the `req` object and access control.
* As access control and getting the request locale is dependent on the current URL and
*/
export const initReq = async function ({
canSetHeaders,
configPromise,
importMap,
key,
overrides
}) {
const headers = await getHeaders();
const cookies = parseCookies(headers);
const partialResult = await partialReqCache.get(async () => {
const config = await configPromise;
const payload = await getPayload({
config,
cron: true,
importMap
});
const languageCode = getRequestLanguage({
config,
cookies,
headers
});
const i18n = await initI18n({
config: config.i18n,
context: 'client',
language: languageCode
});
const {
responseHeaders,
user
} = await executeAuthStrategies({
canSetHeaders,
headers,
payload
});
return {
i18n,
languageCode,
payload,
responseHeaders,
user
};
}, 'global');
return reqCache.get(async () => {
const {
i18n,
languageCode,
payload,
responseHeaders,
user
} = partialResult;
const {
req: reqOverrides,
...optionsOverrides
} = overrides || {};
const req = await createLocalReq({
req: {
headers,
host: headers.get('host'),
i18n: i18n,
responseHeaders,
user,
...(reqOverrides || {})
},
...(optionsOverrides || {})
}, payload);
const locale = await getRequestLocale({
req
});
req.locale = locale?.code;
const permissions = await getAccessResults({
req
});
return {
cookies,
headers,
languageCode,
locale,
permissions,
req
};
}, key).then(result => {
// CRITICAL: Create a shallow copy of req before returning to prevent
// mutations from propagating to the cached req object.
// This ensures parallel operations using the same cache key don't affect each other.
return {
...result,
req: {
...result.req,
...(result.req?.context ? {
context: {
...result.req.context
}
} : {})
}
};
});
};
//# sourceMappingURL=initReq.js.map