@foundrykit/menu-plugin 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -109
- package/dist/cache.d.ts +4 -3
- package/dist/cache.js +13 -15
- package/dist/cache.js.map +1 -1
- package/dist/collections/Menus.d.ts +3 -1
- package/dist/collections/Menus.js +53 -24
- package/dist/collections/Menus.js.map +1 -1
- package/dist/endpoints/exportMenusHandler.d.ts +5 -0
- package/dist/endpoints/exportMenusHandler.js +20 -13
- package/dist/endpoints/exportMenusHandler.js.map +1 -1
- package/dist/endpoints/getMenuHandler.d.ts +6 -0
- package/dist/endpoints/getMenuHandler.js +45 -42
- package/dist/endpoints/getMenuHandler.js.map +1 -1
- package/dist/endpoints/importMenusHandler.d.ts +5 -0
- package/dist/endpoints/importMenusHandler.js +84 -48
- package/dist/endpoints/importMenusHandler.js.map +1 -1
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.js +1 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.d.ts +1 -1
- package/dist/exports/rsc.js +1 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/fetchMenu.d.ts +17 -0
- package/dist/fetchMenu.js +24 -0
- package/dist/fetchMenu.js.map +1 -0
- package/dist/fields/MenuItem.d.ts +1 -0
- package/dist/fields/MenuItem.js +9 -10
- package/dist/fields/MenuItem.js.map +1 -1
- package/dist/hooks/useMenu.d.ts +5 -6
- package/dist/hooks/useMenu.js +36 -19
- package/dist/hooks/useMenu.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +41 -29
- package/dist/index.js.map +1 -1
- package/dist/utilities/menuIdentity.d.ts +2 -0
- package/dist/utilities/menuIdentity.js +9 -0
- package/dist/utilities/menuIdentity.js.map +1 -0
- package/dist/utilities/requireAdminUser.d.ts +2 -0
- package/dist/utilities/requireAdminUser.js +20 -0
- package/dist/utilities/requireAdminUser.js.map +1 -0
- package/dist/utilities/sanitizeMenuDocument.d.ts +1 -0
- package/dist/utilities/sanitizeMenuDocument.js +6 -0
- package/dist/utilities/sanitizeMenuDocument.js.map +1 -0
- package/package.json +1 -1
package/dist/hooks/useMenu.js
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useConfig } from '@payloadcms/ui';
|
|
3
2
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { fetchMenu as requestMenu } from '../fetchMenu.js';
|
|
4
|
+
import { normalizeMenuLocale } from '../utilities/menuIdentity.js';
|
|
4
5
|
const clientCache = new Map();
|
|
5
6
|
const CACHE_TTL = 30_000;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const getDefaultBaseURL = ()=>{
|
|
8
|
+
if (typeof window === 'undefined') return undefined;
|
|
9
|
+
return window.location.origin;
|
|
10
|
+
};
|
|
11
|
+
const getCacheKey = ({ apiRoute = '/api', baseURL, depth = 0, locale, slug })=>{
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
apiRoute,
|
|
14
|
+
baseURL: baseURL || getDefaultBaseURL(),
|
|
15
|
+
depth,
|
|
16
|
+
locale: normalizeMenuLocale(locale),
|
|
17
|
+
slug
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export const useMenu = ({ apiRoute = '/api', baseURL, depth = 0, fetch: fetchImpl, locale, slug })=>{
|
|
8
21
|
const [menu, setMenu] = useState(null);
|
|
9
22
|
const [error, setError] = useState(null);
|
|
10
23
|
const [isLoading, setIsLoading] = useState(true);
|
|
11
24
|
const abortRef = useRef(null);
|
|
12
|
-
const cacheKey =
|
|
25
|
+
const cacheKey = getCacheKey({
|
|
26
|
+
apiRoute,
|
|
27
|
+
baseURL,
|
|
28
|
+
depth,
|
|
29
|
+
locale,
|
|
30
|
+
slug
|
|
31
|
+
});
|
|
13
32
|
const fetchMenu = useCallback(async ()=>{
|
|
14
|
-
// Check client-side cache
|
|
15
33
|
const cached = clientCache.get(cacheKey);
|
|
16
34
|
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
17
35
|
setMenu(cached.data);
|
|
@@ -25,20 +43,17 @@ export const useMenu = ({ slug, depth = 0, locale })=>{
|
|
|
25
43
|
setIsLoading(true);
|
|
26
44
|
setError(null);
|
|
27
45
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
const data = await requestMenu({
|
|
47
|
+
apiRoute,
|
|
48
|
+
baseURL: baseURL || getDefaultBaseURL(),
|
|
49
|
+
depth,
|
|
50
|
+
fetch: async (input, init)=>(fetchImpl || globalThis.fetch)(input, {
|
|
51
|
+
...init,
|
|
52
|
+
signal: controller.signal
|
|
53
|
+
}),
|
|
54
|
+
locale,
|
|
55
|
+
slug
|
|
36
56
|
});
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
const body = await response.json().catch(()=>({}));
|
|
39
|
-
throw new Error(body.error || `Failed to fetch menu: ${response.status}`);
|
|
40
|
-
}
|
|
41
|
-
const data = await response.json();
|
|
42
57
|
clientCache.set(cacheKey, {
|
|
43
58
|
data,
|
|
44
59
|
timestamp: Date.now()
|
|
@@ -52,9 +67,11 @@ export const useMenu = ({ slug, depth = 0, locale })=>{
|
|
|
52
67
|
setIsLoading(false);
|
|
53
68
|
}
|
|
54
69
|
}, [
|
|
70
|
+
apiRoute,
|
|
71
|
+
baseURL,
|
|
55
72
|
cacheKey,
|
|
56
|
-
config.routes?.api,
|
|
57
73
|
depth,
|
|
74
|
+
fetchImpl,
|
|
58
75
|
locale,
|
|
59
76
|
slug
|
|
60
77
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useMenu.ts"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useMenu.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { fetchMenu as requestMenu, type FetchMenuOptions, type MenuDocument } from '../fetchMenu.js'\nimport { normalizeMenuLocale } from '../utilities/menuIdentity.js'\n\ntype UseMenuOptions = Omit<FetchMenuOptions, 'fetch'> & {\n fetch?: typeof globalThis.fetch\n}\n\ntype UseMenuResult = {\n error: null | string\n isLoading: boolean\n menu: MenuDocument | null\n refetch: () => Promise<void>\n}\n\ntype ClientCacheEntry = {\n data: MenuDocument\n timestamp: number\n}\n\nconst clientCache = new Map<string, ClientCacheEntry>()\nconst CACHE_TTL = 30_000\n\nconst getDefaultBaseURL = (): string | undefined => {\n if (typeof window === 'undefined') return undefined\n return window.location.origin\n}\n\nconst getCacheKey = ({ apiRoute = '/api', baseURL, depth = 0, locale, slug }: UseMenuOptions): string => {\n return JSON.stringify({\n apiRoute,\n baseURL: baseURL || getDefaultBaseURL(),\n depth,\n locale: normalizeMenuLocale(locale),\n slug,\n })\n}\n\nexport const useMenu = ({\n apiRoute = '/api',\n baseURL,\n depth = 0,\n fetch: fetchImpl,\n locale,\n slug,\n}: UseMenuOptions): UseMenuResult => {\n const [menu, setMenu] = useState<MenuDocument | null>(null)\n const [error, setError] = useState<null | string>(null)\n const [isLoading, setIsLoading] = useState(true)\n const abortRef = useRef<AbortController | null>(null)\n\n const cacheKey = getCacheKey({ apiRoute, baseURL, depth, locale, slug })\n\n const fetchMenu = useCallback(async () => {\n const cached = clientCache.get(cacheKey)\n if (cached && Date.now() - cached.timestamp < CACHE_TTL) {\n setMenu(cached.data)\n setIsLoading(false)\n setError(null)\n return\n }\n\n abortRef.current?.abort()\n const controller = new AbortController()\n abortRef.current = controller\n\n setIsLoading(true)\n setError(null)\n\n try {\n const data = await requestMenu({\n apiRoute,\n baseURL: baseURL || getDefaultBaseURL(),\n depth,\n fetch: async (input, init) =>\n (fetchImpl || globalThis.fetch)(input, {\n ...init,\n signal: controller.signal,\n }),\n locale,\n slug,\n })\n\n clientCache.set(cacheKey, { data, timestamp: Date.now() })\n setMenu(data)\n } catch (err: any) {\n if (err.name !== 'AbortError') {\n setError(err.message)\n }\n } finally {\n setIsLoading(false)\n }\n }, [apiRoute, baseURL, cacheKey, depth, fetchImpl, locale, slug])\n\n useEffect(() => {\n void fetchMenu()\n return () => {\n abortRef.current?.abort()\n }\n }, [fetchMenu])\n\n return { error, isLoading, menu, refetch: fetchMenu }\n}\n"],"names":["useCallback","useEffect","useRef","useState","fetchMenu","requestMenu","normalizeMenuLocale","clientCache","Map","CACHE_TTL","getDefaultBaseURL","window","undefined","location","origin","getCacheKey","apiRoute","baseURL","depth","locale","slug","JSON","stringify","useMenu","fetch","fetchImpl","menu","setMenu","error","setError","isLoading","setIsLoading","abortRef","cacheKey","cached","get","Date","now","timestamp","data","current","abort","controller","AbortController","input","init","globalThis","signal","set","err","name","message","refetch"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,SAASC,aAAaC,WAAW,QAAkD,kBAAiB;AACpG,SAASC,mBAAmB,QAAQ,+BAA8B;AAkBlE,MAAMC,cAAc,IAAIC;AACxB,MAAMC,YAAY;AAElB,MAAMC,oBAAoB;IACxB,IAAI,OAAOC,WAAW,aAAa,OAAOC;IAC1C,OAAOD,OAAOE,QAAQ,CAACC,MAAM;AAC/B;AAEA,MAAMC,cAAc,CAAC,EAAEC,WAAW,MAAM,EAAEC,OAAO,EAAEC,QAAQ,CAAC,EAAEC,MAAM,EAAEC,IAAI,EAAkB;IAC1F,OAAOC,KAAKC,SAAS,CAAC;QACpBN;QACAC,SAASA,WAAWP;QACpBQ;QACAC,QAAQb,oBAAoBa;QAC5BC;IACF;AACF;AAEA,OAAO,MAAMG,UAAU,CAAC,EACtBP,WAAW,MAAM,EACjBC,OAAO,EACPC,QAAQ,CAAC,EACTM,OAAOC,SAAS,EAChBN,MAAM,EACNC,IAAI,EACW;IACf,MAAM,CAACM,MAAMC,QAAQ,GAAGxB,SAA8B;IACtD,MAAM,CAACyB,OAAOC,SAAS,GAAG1B,SAAwB;IAClD,MAAM,CAAC2B,WAAWC,aAAa,GAAG5B,SAAS;IAC3C,MAAM6B,WAAW9B,OAA+B;IAEhD,MAAM+B,WAAWlB,YAAY;QAAEC;QAAUC;QAASC;QAAOC;QAAQC;IAAK;IAEtE,MAAMhB,YAAYJ,YAAY;QAC5B,MAAMkC,SAAS3B,YAAY4B,GAAG,CAACF;QAC/B,IAAIC,UAAUE,KAAKC,GAAG,KAAKH,OAAOI,SAAS,GAAG7B,WAAW;YACvDkB,QAAQO,OAAOK,IAAI;YACnBR,aAAa;YACbF,SAAS;YACT;QACF;QAEAG,SAASQ,OAAO,EAAEC;QAClB,MAAMC,aAAa,IAAIC;QACvBX,SAASQ,OAAO,GAAGE;QAEnBX,aAAa;QACbF,SAAS;QAET,IAAI;YACF,MAAMU,OAAO,MAAMlC,YAAY;gBAC7BW;gBACAC,SAASA,WAAWP;gBACpBQ;gBACAM,OAAO,OAAOoB,OAAOC,OACnB,AAACpB,CAAAA,aAAaqB,WAAWtB,KAAK,AAAD,EAAGoB,OAAO;wBACrC,GAAGC,IAAI;wBACPE,QAAQL,WAAWK,MAAM;oBAC3B;gBACF5B;gBACAC;YACF;YAEAb,YAAYyC,GAAG,CAACf,UAAU;gBAAEM;gBAAMD,WAAWF,KAAKC,GAAG;YAAG;YACxDV,QAAQY;QACV,EAAE,OAAOU,KAAU;YACjB,IAAIA,IAAIC,IAAI,KAAK,cAAc;gBAC7BrB,SAASoB,IAAIE,OAAO;YACtB;QACF,SAAU;YACRpB,aAAa;QACf;IACF,GAAG;QAACf;QAAUC;QAASgB;QAAUf;QAAOO;QAAWN;QAAQC;KAAK;IAEhEnB,UAAU;QACR,KAAKG;QACL,OAAO;YACL4B,SAASQ,OAAO,EAAEC;QACpB;IACF,GAAG;QAACrC;KAAU;IAEd,OAAO;QAAEwB;QAAOE;QAAWJ;QAAM0B,SAAShD;IAAU;AACtD,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { CollectionSlug, Config } from 'payload';
|
|
2
2
|
export type MenuPluginConfig = {
|
|
3
3
|
baseUrl?: string;
|
|
4
|
+
cacheTTL?: number;
|
|
4
5
|
disabled?: boolean;
|
|
6
|
+
enableImportExport?: boolean;
|
|
5
7
|
maxDepth?: number;
|
|
6
8
|
relationTo?: CollectionSlug | CollectionSlug[];
|
|
9
|
+
requireAdminForImportExport?: boolean;
|
|
7
10
|
};
|
|
8
11
|
export declare const menuPlugin: (pluginOptions: MenuPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,49 @@
|
|
|
1
|
+
import { menuCache } from './cache.js';
|
|
1
2
|
import { createMenusCollection } from './collections/Menus.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createExportMenusHandler } from './endpoints/exportMenusHandler.js';
|
|
4
|
+
import { createGetMenuHandler } from './endpoints/getMenuHandler.js';
|
|
5
|
+
import { createImportMenusHandler } from './endpoints/importMenusHandler.js';
|
|
5
6
|
export const menuPlugin = (pluginOptions)=>(config)=>{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const cacheTTL = pluginOptions.cacheTTL ?? 60_000;
|
|
8
|
+
const enableImportExport = pluginOptions.enableImportExport ?? true;
|
|
9
|
+
const requireAdminForImportExport = pluginOptions.requireAdminForImportExport ?? true;
|
|
10
|
+
menuCache.configure(cacheTTL);
|
|
11
|
+
config.collections = [
|
|
12
|
+
...config.collections || [],
|
|
13
|
+
createMenusCollection({
|
|
14
|
+
baseUrl: pluginOptions.baseUrl,
|
|
15
|
+
disabled: pluginOptions.disabled,
|
|
16
|
+
maxDepth: pluginOptions.maxDepth,
|
|
17
|
+
relationTo: pluginOptions.relationTo
|
|
18
|
+
})
|
|
19
|
+
];
|
|
14
20
|
if (pluginOptions.disabled) {
|
|
15
21
|
return config;
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
config.endpoints
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
config.endpoints = [
|
|
24
|
+
...config.endpoints || [],
|
|
25
|
+
{
|
|
26
|
+
handler: createGetMenuHandler(),
|
|
27
|
+
method: 'get',
|
|
28
|
+
path: '/api/menus/:slug'
|
|
29
|
+
},
|
|
30
|
+
...enableImportExport ? [
|
|
31
|
+
{
|
|
32
|
+
handler: createExportMenusHandler({
|
|
33
|
+
requireAdmin: requireAdminForImportExport
|
|
34
|
+
}),
|
|
35
|
+
method: 'get',
|
|
36
|
+
path: '/api/menus-export'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
handler: createImportMenusHandler({
|
|
40
|
+
requireAdmin: requireAdminForImportExport
|
|
41
|
+
}),
|
|
42
|
+
method: 'post',
|
|
43
|
+
path: '/api/menus-import'
|
|
44
|
+
}
|
|
45
|
+
] : []
|
|
46
|
+
];
|
|
35
47
|
return config;
|
|
36
48
|
};
|
|
37
49
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config } from 'payload'\n\nimport { createMenusCollection } from './collections/Menus.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config } from 'payload'\n\nimport { menuCache } from './cache.js'\nimport { createMenusCollection } from './collections/Menus.js'\nimport { createExportMenusHandler } from './endpoints/exportMenusHandler.js'\nimport { createGetMenuHandler } from './endpoints/getMenuHandler.js'\nimport { createImportMenusHandler } from './endpoints/importMenusHandler.js'\n\nexport type MenuPluginConfig = {\n baseUrl?: string\n cacheTTL?: number\n disabled?: boolean\n enableImportExport?: boolean\n maxDepth?: number\n relationTo?: CollectionSlug | CollectionSlug[]\n requireAdminForImportExport?: boolean\n}\n\nexport const menuPlugin =\n (pluginOptions: MenuPluginConfig) =>\n (config: Config): Config => {\n const cacheTTL = pluginOptions.cacheTTL ?? 60_000\n const enableImportExport = pluginOptions.enableImportExport ?? true\n const requireAdminForImportExport = pluginOptions.requireAdminForImportExport ?? true\n\n menuCache.configure(cacheTTL)\n\n config.collections = [\n ...(config.collections || []),\n createMenusCollection({\n baseUrl: pluginOptions.baseUrl,\n disabled: pluginOptions.disabled,\n maxDepth: pluginOptions.maxDepth,\n relationTo: pluginOptions.relationTo,\n }),\n ]\n\n if (pluginOptions.disabled) {\n return config\n }\n\n config.endpoints = [\n ...(config.endpoints || []),\n {\n handler: createGetMenuHandler(),\n method: 'get',\n path: '/api/menus/:slug',\n },\n ...(enableImportExport\n ? [\n {\n handler: createExportMenusHandler({ requireAdmin: requireAdminForImportExport }),\n method: 'get' as const,\n path: '/api/menus-export',\n },\n {\n handler: createImportMenusHandler({ requireAdmin: requireAdminForImportExport }),\n method: 'post' as const,\n path: '/api/menus-import',\n },\n ]\n : []),\n ]\n\n return config\n }\n"],"names":["menuCache","createMenusCollection","createExportMenusHandler","createGetMenuHandler","createImportMenusHandler","menuPlugin","pluginOptions","config","cacheTTL","enableImportExport","requireAdminForImportExport","configure","collections","baseUrl","disabled","maxDepth","relationTo","endpoints","handler","method","path","requireAdmin"],"mappings":"AAEA,SAASA,SAAS,QAAQ,aAAY;AACtC,SAASC,qBAAqB,QAAQ,yBAAwB;AAC9D,SAASC,wBAAwB,QAAQ,oCAAmC;AAC5E,SAASC,oBAAoB,QAAQ,gCAA+B;AACpE,SAASC,wBAAwB,QAAQ,oCAAmC;AAY5E,OAAO,MAAMC,aACX,CAACC,gBACD,CAACC;QACC,MAAMC,WAAWF,cAAcE,QAAQ,IAAI;QAC3C,MAAMC,qBAAqBH,cAAcG,kBAAkB,IAAI;QAC/D,MAAMC,8BAA8BJ,cAAcI,2BAA2B,IAAI;QAEjFV,UAAUW,SAAS,CAACH;QAEpBD,OAAOK,WAAW,GAAG;eACfL,OAAOK,WAAW,IAAI,EAAE;YAC5BX,sBAAsB;gBACpBY,SAASP,cAAcO,OAAO;gBAC9BC,UAAUR,cAAcQ,QAAQ;gBAChCC,UAAUT,cAAcS,QAAQ;gBAChCC,YAAYV,cAAcU,UAAU;YACtC;SACD;QAED,IAAIV,cAAcQ,QAAQ,EAAE;YAC1B,OAAOP;QACT;QAEAA,OAAOU,SAAS,GAAG;eACbV,OAAOU,SAAS,IAAI,EAAE;YAC1B;gBACEC,SAASf;gBACTgB,QAAQ;gBACRC,MAAM;YACR;eACIX,qBACA;gBACE;oBACES,SAAShB,yBAAyB;wBAAEmB,cAAcX;oBAA4B;oBAC9ES,QAAQ;oBACRC,MAAM;gBACR;gBACA;oBACEF,SAASd,yBAAyB;wBAAEiB,cAAcX;oBAA4B;oBAC9ES,QAAQ;oBACRC,MAAM;gBACR;aACD,GACD,EAAE;SACP;QAED,OAAOb;IACT,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const normalizeMenuLocale = (locale)=>{
|
|
2
|
+
const normalized = locale?.trim().toLowerCase();
|
|
3
|
+
return normalized ? normalized : undefined;
|
|
4
|
+
};
|
|
5
|
+
export const buildMenuIdentityKey = (slug, locale)=>{
|
|
6
|
+
return `${slug}::${normalizeMenuLocale(locale) || '__default'}`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=menuIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/menuIdentity.ts"],"sourcesContent":["export const normalizeMenuLocale = (locale?: null | string): string | undefined => {\n const normalized = locale?.trim().toLowerCase()\n return normalized ? normalized : undefined\n}\n\nexport const buildMenuIdentityKey = (slug: string, locale?: null | string): string => {\n return `${slug}::${normalizeMenuLocale(locale) || '__default'}`\n}\n"],"names":["normalizeMenuLocale","locale","normalized","trim","toLowerCase","undefined","buildMenuIdentityKey","slug"],"mappings":"AAAA,OAAO,MAAMA,sBAAsB,CAACC;IAClC,MAAMC,aAAaD,QAAQE,OAAOC;IAClC,OAAOF,aAAaA,aAAaG;AACnC,EAAC;AAED,OAAO,MAAMC,uBAAuB,CAACC,MAAcN;IACjD,OAAO,GAAGM,KAAK,EAAE,EAAEP,oBAAoBC,WAAW,aAAa;AACjE,EAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const requireAdminUser = (req)=>{
|
|
2
|
+
const adminCollection = req.payload.config.admin?.user;
|
|
3
|
+
if (!req.user) {
|
|
4
|
+
return Response.json({
|
|
5
|
+
error: 'Authentication required'
|
|
6
|
+
}, {
|
|
7
|
+
status: 401
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
if (adminCollection && req.user.collection !== adminCollection) {
|
|
11
|
+
return Response.json({
|
|
12
|
+
error: 'Admin access required'
|
|
13
|
+
}, {
|
|
14
|
+
status: 403
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=requireAdminUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/requireAdminUser.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nexport const requireAdminUser = (req: PayloadRequest): Response | undefined => {\n const adminCollection = req.payload.config.admin?.user\n\n if (!req.user) {\n return Response.json({ error: 'Authentication required' }, { status: 401 })\n }\n\n if (adminCollection && req.user.collection !== adminCollection) {\n return Response.json({ error: 'Admin access required' }, { status: 403 })\n }\n\n return undefined\n}\n"],"names":["requireAdminUser","req","adminCollection","payload","config","admin","user","Response","json","error","status","collection","undefined"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,CAACC;IAC/B,MAAMC,kBAAkBD,IAAIE,OAAO,CAACC,MAAM,CAACC,KAAK,EAAEC;IAElD,IAAI,CAACL,IAAIK,IAAI,EAAE;QACb,OAAOC,SAASC,IAAI,CAAC;YAAEC,OAAO;QAA0B,GAAG;YAAEC,QAAQ;QAAI;IAC3E;IAEA,IAAIR,mBAAmBD,IAAIK,IAAI,CAACK,UAAU,KAAKT,iBAAiB;QAC9D,OAAOK,SAASC,IAAI,CAAC;YAAEC,OAAO;QAAwB,GAAG;YAAEC,QAAQ;QAAI;IACzE;IAEA,OAAOE;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeMenuDocument: <T extends Record<string, unknown>>(menu: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeMenuDocument.ts"],"sourcesContent":["export const sanitizeMenuDocument = <T extends Record<string, unknown>>(menu: T): T => {\n const { slugLocaleKey: _slugLocaleKey, ...sanitized } = menu\n return sanitized as T\n}\n"],"names":["sanitizeMenuDocument","menu","slugLocaleKey","_slugLocaleKey","sanitized"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB,CAAoCC;IACtE,MAAM,EAAEC,eAAeC,cAAc,EAAE,GAAGC,WAAW,GAAGH;IACxD,OAAOG;AACT,EAAC"}
|