@nitrogenbuilder/connector-payload 0.1.17 → 0.1.19
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/dist/components/NitrogenDataViewer.js +15 -1
- package/dist/components/NitrogenEditButton.js +17 -20
- package/dist/components/NitrogenViewButton.js +5 -14
- package/dist/components/nitrogenAdminButtonStyles.d.ts +8 -0
- package/dist/components/nitrogenAdminButtonStyles.js +50 -0
- package/dist/endpoints/all.js +1 -1
- package/dist/endpoints/batch.d.ts +1 -1
- package/dist/endpoints/batch.js +168 -19
- package/dist/endpoints/collection-endpoints.js +1 -1
- package/dist/endpoints/collections.d.ts +2 -0
- package/dist/endpoints/collections.js +31 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
|
@@ -292,6 +292,7 @@ function ensureStyles() {
|
|
|
292
292
|
const NitrogenDataViewer = ({ path, field }) => {
|
|
293
293
|
const { value, setValue } = useField({ path });
|
|
294
294
|
const [copied, setCopied] = useState(false);
|
|
295
|
+
const [pasted, setPasted] = useState(false);
|
|
295
296
|
const [forceOpen, setForceOpen] = useState(null);
|
|
296
297
|
const [treeKey, setTreeKey] = useState(0);
|
|
297
298
|
const [unlocked, setUnlocked] = useState(false);
|
|
@@ -311,6 +312,19 @@ const NitrogenDataViewer = ({ path, field }) => {
|
|
|
311
312
|
setTimeout(() => setCopied(false), 2000);
|
|
312
313
|
});
|
|
313
314
|
}, [jsonString]);
|
|
315
|
+
const handlePaste = useCallback(() => {
|
|
316
|
+
navigator.clipboard.readText().then((text) => {
|
|
317
|
+
try {
|
|
318
|
+
const parsed = JSON.parse(text);
|
|
319
|
+
setValue(parsed);
|
|
320
|
+
setPasted(true);
|
|
321
|
+
setTimeout(() => setPasted(false), 2000);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// ignore invalid JSON
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}, [setValue]);
|
|
314
328
|
const expandAll = useCallback(() => {
|
|
315
329
|
setForceOpen(true);
|
|
316
330
|
setTreeKey((k) => k + 1);
|
|
@@ -326,7 +340,7 @@ const NitrogenDataViewer = ({ path, field }) => {
|
|
|
326
340
|
onAddChild: (p) => setValue(addChildAtPath(parsed, p)),
|
|
327
341
|
};
|
|
328
342
|
const header = (_jsxs("span", { children: [typeof field.label === 'string' ? field.label : field.name, moduleCount !== null && (_jsxs("span", { style: { opacity: 0.5, fontWeight: 400, marginLeft: 8 }, children: ["(", moduleCount, " item", moduleCount !== 1 ? 's' : '', ")"] }))] }));
|
|
329
|
-
return (_jsxs("div", { className: "njv-root field-type", style: { marginBottom: '1.5rem' }, children: [_jsx(Collapsible, { header: header, initCollapsed: true, children: _jsxs("div", { style: { border: '1px solid var(--njv-border)', borderRadius: '0 0 4px 4px', overflow: 'hidden' }, children: [_jsxs("div", { className: "njv-toolbar", children: [_jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: handleCopy, children: copied ? '✓ Copied' : 'Copy' }), _jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: expandAll, children: "Expand All" }), _jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: collapseAll, children: "Collapse All" }), _jsx("button", { type: "button", onClick: () => setUnlocked((u) => !u), style: {
|
|
343
|
+
return (_jsxs("div", { className: "njv-root field-type", style: { marginBottom: '1.5rem' }, children: [_jsx(Collapsible, { header: header, initCollapsed: true, children: _jsxs("div", { style: { border: '1px solid var(--njv-border)', borderRadius: '0 0 4px 4px', overflow: 'hidden' }, children: [_jsxs("div", { className: "njv-toolbar", children: [_jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: handleCopy, children: copied ? '✓ Copied' : 'Copy' }), unlocked && (_jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: handlePaste, children: pasted ? '✓ Pasted' : 'Paste' })), _jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: expandAll, children: "Expand All" }), _jsx("button", { type: "button", className: "btn btn--size-small btn--style-secondary", onClick: collapseAll, children: "Collapse All" }), _jsx("button", { type: "button", onClick: () => setUnlocked((u) => !u), style: {
|
|
330
344
|
marginBlock: '12px',
|
|
331
345
|
marginLeft: 'auto',
|
|
332
346
|
padding: '4px 12px',
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button } from "@payloadcms/ui";
|
|
3
4
|
import { useState, useEffect } from "react";
|
|
5
|
+
import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenSecondaryButtonVars, nitrogenViewButtonVars, } from "./nitrogenAdminButtonStyles";
|
|
4
6
|
export const NitrogenEditButton = ({ collection }) => {
|
|
5
7
|
const [id, setId] = useState(undefined);
|
|
6
8
|
const [token, setToken] = useState(undefined);
|
|
7
9
|
const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
|
|
8
10
|
const [slug, setSlug] = useState(undefined);
|
|
9
11
|
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
12
|
+
const [instanceUrl, setInstanceUrl] = useState(undefined);
|
|
10
13
|
const [authorId, setAuthorId] = useState(undefined);
|
|
11
14
|
useEffect(() => {
|
|
12
15
|
const segments = window.location.pathname.split("/").filter(Boolean);
|
|
@@ -46,6 +49,9 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
46
49
|
if (data.developmentUrl) {
|
|
47
50
|
setHasDevelopmentUrl(true);
|
|
48
51
|
}
|
|
52
|
+
if (data.instanceUrl) {
|
|
53
|
+
setInstanceUrl(data.instanceUrl.replace(/\/$/, ""));
|
|
54
|
+
}
|
|
49
55
|
const url = data.frontendUrl;
|
|
50
56
|
if (url) {
|
|
51
57
|
setFrontendUrl(url.replace(/\/$/, ""));
|
|
@@ -58,24 +64,15 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
58
64
|
if (!id || !token || !authorId)
|
|
59
65
|
return null;
|
|
60
66
|
const param = collection === "nitrogen-templates" ? "templateId" : "pageId";
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fontWeight: 500,
|
|
73
|
-
};
|
|
74
|
-
return (_jsxs("div", { style: { display: "flex", gap: "8px", alignItems: "center" }, children: [slug && frontendUrl && (_jsx("a", { href: `${frontendUrl}/${slug}`, target: "_blank", rel: "noopener noreferrer", style: {
|
|
75
|
-
...buttonStyle,
|
|
76
|
-
background: "#10b981",
|
|
77
|
-
}, children: "View Page" })), hasDevelopmentUrl ? (_jsxs(_Fragment, { children: [_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit (Live)" }), _jsx("a", { href: `${baseHref}&development=true`, target: "_blank", rel: "noopener noreferrer", style: {
|
|
78
|
-
...buttonStyle,
|
|
79
|
-
background: "#374151",
|
|
80
|
-
}, children: "Edit (Dev)" })] })) : (_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit with Nitrogen" }))] }));
|
|
67
|
+
const editorBase = instanceUrl ?? "";
|
|
68
|
+
const baseHref = `${editorBase}/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}&authorId=${encodeURIComponent(authorId)}`;
|
|
69
|
+
return (_jsxs("div", { style: nitrogenButtonGroupStyle, children: [slug && frontendUrl && (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: `${frontendUrl}/${slug}`, extraButtonProps: {
|
|
70
|
+
style: nitrogenViewButtonVars,
|
|
71
|
+
}, children: "View Page" })), hasDevelopmentUrl ? (_jsxs(_Fragment, { children: [_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: baseHref, extraButtonProps: {
|
|
72
|
+
style: nitrogenEditLiveButtonVars,
|
|
73
|
+
}, children: "Edit (Live)" }), _jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: `${baseHref}&development=true`, extraButtonProps: {
|
|
74
|
+
style: nitrogenEditDevButtonVars,
|
|
75
|
+
}, children: "Edit (Dev)" })] })) : (_jsx(Button, { buttonStyle: "secondary", el: "anchor", margin: false, newTab: true, url: baseHref, extraButtonProps: {
|
|
76
|
+
style: nitrogenSecondaryButtonVars,
|
|
77
|
+
}, children: "Edit with Nitrogen" }))] }));
|
|
81
78
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Button } from "@payloadcms/ui";
|
|
3
4
|
import { useState, useEffect } from "react";
|
|
5
|
+
import { nitrogenViewButtonVars, } from "./nitrogenAdminButtonStyles";
|
|
4
6
|
export const NitrogenViewButton = ({ collection }) => {
|
|
5
7
|
const [slug, setSlug] = useState(undefined);
|
|
6
8
|
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
@@ -34,22 +36,11 @@ export const NitrogenViewButton = ({ collection }) => {
|
|
|
34
36
|
console.error("Failed to fetch nitrogen settings:", err);
|
|
35
37
|
});
|
|
36
38
|
}, [collection]);
|
|
37
|
-
console.log('[NitrogenViewButton] mounted', { slug, frontendUrl, collection });
|
|
38
39
|
if (!slug || !frontendUrl) {
|
|
39
|
-
|
|
40
|
-
return _jsx("span", { style: { color: 'red', fontSize: '12px' }, children: "View button: waiting for data..." });
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
42
|
const href = `${frontendUrl}/${slug}`;
|
|
43
|
-
return (_jsx(
|
|
44
|
-
|
|
45
|
-
alignItems: "center",
|
|
46
|
-
gap: "8px",
|
|
47
|
-
padding: "8px 16px",
|
|
48
|
-
background: "#10b981",
|
|
49
|
-
color: "#fff",
|
|
50
|
-
borderRadius: "4px",
|
|
51
|
-
textDecoration: "none",
|
|
52
|
-
fontSize: "14px",
|
|
53
|
-
fontWeight: 500,
|
|
43
|
+
return (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: href, extraButtonProps: {
|
|
44
|
+
style: nitrogenViewButtonVars,
|
|
54
45
|
}, children: "View Page" }));
|
|
55
46
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
type ButtonStyleVars = CSSProperties & Record<`--${string}`, string | number>;
|
|
3
|
+
export declare const nitrogenButtonGroupStyle: CSSProperties;
|
|
4
|
+
export declare const nitrogenViewButtonVars: ButtonStyleVars;
|
|
5
|
+
export declare const nitrogenEditLiveButtonVars: ButtonStyleVars;
|
|
6
|
+
export declare const nitrogenEditDevButtonVars: ButtonStyleVars;
|
|
7
|
+
export declare const nitrogenSecondaryButtonVars: ButtonStyleVars;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const monogenPalette = {
|
|
2
|
+
gray900: "#16191D",
|
|
3
|
+
gray700: "#21252C",
|
|
4
|
+
gray600: "#31383F",
|
|
5
|
+
gray400: "#4E5965",
|
|
6
|
+
gray350: "#647382",
|
|
7
|
+
gray200: "#E2E5E9",
|
|
8
|
+
hasVal: "#6EA6DE",
|
|
9
|
+
inheritVal: "#E08C38",
|
|
10
|
+
};
|
|
11
|
+
const createFilledButtonVars = ({ background, hoverBackground, text, border, }) => ({
|
|
12
|
+
"--bg-color": background,
|
|
13
|
+
"--color": text,
|
|
14
|
+
"--hover-bg": hoverBackground,
|
|
15
|
+
"--hover-color": text,
|
|
16
|
+
"--box-shadow": `inset 0 0 0 1px ${border}`,
|
|
17
|
+
"--hover-box-shadow": `inset 0 0 0 1px ${border}`,
|
|
18
|
+
"--btn-font-weight": 500,
|
|
19
|
+
});
|
|
20
|
+
export const nitrogenButtonGroupStyle = {
|
|
21
|
+
display: "flex",
|
|
22
|
+
flexWrap: "wrap",
|
|
23
|
+
gap: "8px",
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
};
|
|
26
|
+
export const nitrogenViewButtonVars = createFilledButtonVars({
|
|
27
|
+
background: monogenPalette.hasVal,
|
|
28
|
+
hoverBackground: "#5F97CF",
|
|
29
|
+
text: monogenPalette.gray900,
|
|
30
|
+
border: "rgba(22, 25, 29, 0.12)",
|
|
31
|
+
});
|
|
32
|
+
export const nitrogenEditLiveButtonVars = createFilledButtonVars({
|
|
33
|
+
background: monogenPalette.inheritVal,
|
|
34
|
+
hoverBackground: "#CC7B2B",
|
|
35
|
+
text: monogenPalette.gray900,
|
|
36
|
+
border: "rgba(22, 25, 29, 0.12)",
|
|
37
|
+
});
|
|
38
|
+
export const nitrogenEditDevButtonVars = createFilledButtonVars({
|
|
39
|
+
background: monogenPalette.gray700,
|
|
40
|
+
hoverBackground: monogenPalette.gray600,
|
|
41
|
+
text: monogenPalette.gray200,
|
|
42
|
+
border: "rgba(226, 229, 233, 0.08)",
|
|
43
|
+
});
|
|
44
|
+
export const nitrogenSecondaryButtonVars = {
|
|
45
|
+
"--color": monogenPalette.gray400,
|
|
46
|
+
"--hover-color": monogenPalette.gray350,
|
|
47
|
+
"--box-shadow": `inset 0 0 0 1px ${monogenPalette.gray400}`,
|
|
48
|
+
"--hover-box-shadow": `inset 0 0 0 1px ${monogenPalette.gray350}`,
|
|
49
|
+
"--btn-font-weight": 500,
|
|
50
|
+
};
|
package/dist/endpoints/all.js
CHANGED
|
@@ -20,7 +20,7 @@ export const allEndpoints = [
|
|
|
20
20
|
const collection = resolveCollection(postType);
|
|
21
21
|
const where = {};
|
|
22
22
|
if (!statuses.includes('any')) {
|
|
23
|
-
where.
|
|
23
|
+
where._status = { in: statuses };
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
26
|
const result = await payload.find({
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Endpoint } from
|
|
1
|
+
import type { Endpoint } from "payload";
|
|
2
2
|
export declare const batchEndpoints: Endpoint[];
|
package/dist/endpoints/batch.js
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
|
-
import { resolveCollection } from
|
|
2
|
-
import { getNitrogenSettings, buildDynamicData, buildPageResponse } from
|
|
1
|
+
import { resolveCollection } from "../collection-registry";
|
|
2
|
+
import { getNitrogenSettings, buildDynamicData, buildPageResponse, } from "./helpers";
|
|
3
|
+
function toArray(value) {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return value
|
|
6
|
+
.map((item) => String(item).trim())
|
|
7
|
+
.filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
return value
|
|
11
|
+
.split(",")
|
|
12
|
+
.map((item) => item.trim())
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
}
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
async function resolveRelationshipIds(payload, collection, values) {
|
|
18
|
+
if (values.length === 0)
|
|
19
|
+
return [];
|
|
20
|
+
const [slugMatches, titleMatches] = await Promise.all([
|
|
21
|
+
payload.find({
|
|
22
|
+
collection,
|
|
23
|
+
where: {
|
|
24
|
+
slug: { in: values },
|
|
25
|
+
},
|
|
26
|
+
limit: values.length,
|
|
27
|
+
depth: 0,
|
|
28
|
+
pagination: false,
|
|
29
|
+
}),
|
|
30
|
+
payload.find({
|
|
31
|
+
collection,
|
|
32
|
+
where: {
|
|
33
|
+
title: { in: values },
|
|
34
|
+
},
|
|
35
|
+
limit: values.length,
|
|
36
|
+
depth: 0,
|
|
37
|
+
pagination: false,
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
return [...slugMatches.docs, ...titleMatches.docs].map((doc) => doc.id);
|
|
41
|
+
}
|
|
3
42
|
export const batchEndpoints = [
|
|
4
43
|
// POST /api/nitrogen/v1/batch-data — Batch fetch multiple collections
|
|
5
44
|
{
|
|
6
|
-
path:
|
|
7
|
-
method:
|
|
45
|
+
path: "/nitrogen/v1/batch-data",
|
|
46
|
+
method: "post",
|
|
8
47
|
handler: async (req) => {
|
|
9
48
|
const { payload } = req;
|
|
10
49
|
const body = await req.json?.();
|
|
@@ -18,15 +57,122 @@ export const batchEndpoints = [
|
|
|
18
57
|
const { key, endpoint, params = {} } = batchReq;
|
|
19
58
|
try {
|
|
20
59
|
const collectionSlug = resolveCollection(endpoint);
|
|
21
|
-
const limit = params.posts_per_page ?? 10;
|
|
22
|
-
const page = params.paged ?? 1;
|
|
23
|
-
const statusParam = params.post_status ??
|
|
24
|
-
const statuses = statusParam
|
|
25
|
-
|
|
26
|
-
|
|
60
|
+
const limit = Number(params.posts_per_page ?? 10);
|
|
61
|
+
const page = Number(params.paged ?? 1);
|
|
62
|
+
const statusParam = params.post_status ?? "published";
|
|
63
|
+
const statuses = statusParam
|
|
64
|
+
.split(",")
|
|
65
|
+
.map((s) => s.trim());
|
|
66
|
+
const orderby = params.orderby || "createdAt";
|
|
67
|
+
const sort = params.order === "asc" ? orderby : `-${orderby}`;
|
|
68
|
+
const raw = params.raw === true || params.raw === "true";
|
|
69
|
+
const depthParam = params.depth;
|
|
70
|
+
const depth = depthParam !== undefined
|
|
71
|
+
? Number(depthParam)
|
|
72
|
+
: params.embed
|
|
73
|
+
? 1
|
|
74
|
+
: 0;
|
|
27
75
|
const where = {};
|
|
28
|
-
if (!statuses.includes(
|
|
29
|
-
where.
|
|
76
|
+
if (!statuses.includes("any")) {
|
|
77
|
+
where._status = { in: statuses };
|
|
78
|
+
}
|
|
79
|
+
const slugs = [
|
|
80
|
+
...toArray(params.slug),
|
|
81
|
+
...toArray(params.slugs),
|
|
82
|
+
];
|
|
83
|
+
if (slugs.length > 0) {
|
|
84
|
+
where.slug = { in: Array.from(new Set(slugs)) };
|
|
85
|
+
}
|
|
86
|
+
const titles = [
|
|
87
|
+
...toArray(params.title),
|
|
88
|
+
...toArray(params.titles),
|
|
89
|
+
];
|
|
90
|
+
if (titles.length > 0) {
|
|
91
|
+
where.title = { in: Array.from(new Set(titles)) };
|
|
92
|
+
}
|
|
93
|
+
const categoryIds = await resolveRelationshipIds(payload, "post-category", toArray(params.categories));
|
|
94
|
+
if (toArray(params.categories).length > 0) {
|
|
95
|
+
if (categoryIds.length === 0) {
|
|
96
|
+
results[key] = {
|
|
97
|
+
data: [],
|
|
98
|
+
total: 0,
|
|
99
|
+
totalPages: 0,
|
|
100
|
+
};
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
where.categories = { in: Array.from(new Set(categoryIds)) };
|
|
104
|
+
}
|
|
105
|
+
const excludedCategoryIds = await resolveRelationshipIds(payload, "post-category", toArray(params.categories_excluded));
|
|
106
|
+
if (excludedCategoryIds.length > 0) {
|
|
107
|
+
where.categories = {
|
|
108
|
+
...(where.categories ?? {}),
|
|
109
|
+
not_in: Array.from(new Set(excludedCategoryIds)),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const tagIds = await resolveRelationshipIds(payload, "tag", toArray(params.tags));
|
|
113
|
+
if (toArray(params.tags).length > 0) {
|
|
114
|
+
if (tagIds.length === 0) {
|
|
115
|
+
results[key] = {
|
|
116
|
+
data: [],
|
|
117
|
+
total: 0,
|
|
118
|
+
totalPages: 0,
|
|
119
|
+
};
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
where.tags = { in: Array.from(new Set(tagIds)) };
|
|
123
|
+
}
|
|
124
|
+
const excludedTagIds = await resolveRelationshipIds(payload, "tag", toArray(params.tags_excluded));
|
|
125
|
+
if (excludedTagIds.length > 0) {
|
|
126
|
+
where.tags = {
|
|
127
|
+
...(where.tags ?? {}),
|
|
128
|
+
not_in: Array.from(new Set(excludedTagIds)),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const featuredIds = await resolveRelationshipIds(payload, "featured-tag", toArray(params.featured));
|
|
132
|
+
if (toArray(params.featured).length > 0) {
|
|
133
|
+
if (featuredIds.length === 0) {
|
|
134
|
+
results[key] = {
|
|
135
|
+
data: [],
|
|
136
|
+
total: 0,
|
|
137
|
+
totalPages: 0,
|
|
138
|
+
};
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
where.featuredTags = { in: Array.from(new Set(featuredIds)) };
|
|
142
|
+
}
|
|
143
|
+
const excludedFeaturedIds = await resolveRelationshipIds(payload, "featured-tag", toArray(params.featured_excluded));
|
|
144
|
+
if (excludedFeaturedIds.length > 0) {
|
|
145
|
+
where.featuredTags = {
|
|
146
|
+
...(where.featuredTags ?? {}),
|
|
147
|
+
not_in: Array.from(new Set(excludedFeaturedIds)),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const authors = toArray(params.authors);
|
|
151
|
+
if (authors.length > 0) {
|
|
152
|
+
if (collectionSlug === "posts") {
|
|
153
|
+
const authorIds = await resolveRelationshipIds(payload, "author", authors);
|
|
154
|
+
const authorFilters = [];
|
|
155
|
+
if (authorIds.length > 0) {
|
|
156
|
+
authorFilters.push({
|
|
157
|
+
wpAuthors: { in: Array.from(new Set(authorIds)) },
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
authorFilters.push({
|
|
161
|
+
wpAuthorName: { in: authors },
|
|
162
|
+
});
|
|
163
|
+
if (authorFilters.length === 1) {
|
|
164
|
+
Object.assign(where, authorFilters[0]);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
where.or = [...(where.or ?? []), ...authorFilters];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
where.title = {
|
|
172
|
+
...(where.title ?? {}),
|
|
173
|
+
in: authors,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
30
176
|
}
|
|
31
177
|
const result = await payload.find({
|
|
32
178
|
collection: collectionSlug,
|
|
@@ -34,10 +180,13 @@ export const batchEndpoints = [
|
|
|
34
180
|
page,
|
|
35
181
|
limit,
|
|
36
182
|
sort,
|
|
37
|
-
depth
|
|
183
|
+
depth,
|
|
38
184
|
});
|
|
39
185
|
let data;
|
|
40
|
-
if (
|
|
186
|
+
if (raw) {
|
|
187
|
+
data = result.docs;
|
|
188
|
+
}
|
|
189
|
+
else if (params.embed) {
|
|
41
190
|
data = result.docs.map((doc) => {
|
|
42
191
|
const dynamicData = buildDynamicData(doc, settings);
|
|
43
192
|
return buildPageResponse(doc, settings, dynamicData);
|
|
@@ -48,10 +197,10 @@ export const batchEndpoints = [
|
|
|
48
197
|
const d = doc;
|
|
49
198
|
return {
|
|
50
199
|
id: d.id,
|
|
51
|
-
title: String(d.title ||
|
|
52
|
-
slug: String(d.slug ||
|
|
53
|
-
permalink: `${settings.frontendUrl ||
|
|
54
|
-
relative_permalink: `/${String(d.slug ||
|
|
200
|
+
title: String(d.title || ""),
|
|
201
|
+
slug: String(d.slug || ""),
|
|
202
|
+
permalink: `${settings.frontendUrl || ""}/${String(d.slug || "")}`,
|
|
203
|
+
relative_permalink: `/${String(d.slug || "")}`,
|
|
55
204
|
};
|
|
56
205
|
});
|
|
57
206
|
}
|
|
@@ -66,7 +215,7 @@ export const batchEndpoints = [
|
|
|
66
215
|
data: [],
|
|
67
216
|
total: 0,
|
|
68
217
|
totalPages: 0,
|
|
69
|
-
error: e instanceof Error ? e.message :
|
|
218
|
+
error: e instanceof Error ? e.message : "Unknown error",
|
|
70
219
|
};
|
|
71
220
|
}
|
|
72
221
|
}));
|
|
@@ -20,7 +20,7 @@ export function createCollectionEndpoints(collectionSlug, endpointPrefix) {
|
|
|
20
20
|
const statuses = statusParam.split(',').map((s) => s.trim());
|
|
21
21
|
const where = {};
|
|
22
22
|
if (!statuses.includes('any')) {
|
|
23
|
-
where.
|
|
23
|
+
where._status = { in: statuses };
|
|
24
24
|
}
|
|
25
25
|
const result = await payload.find({
|
|
26
26
|
collection,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function humanizeSlug(value) {
|
|
2
|
+
return value
|
|
3
|
+
.split(/[-_]+/)
|
|
4
|
+
.filter(Boolean)
|
|
5
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
6
|
+
.join(" ");
|
|
7
|
+
}
|
|
8
|
+
export const collectionsEndpoints = [
|
|
9
|
+
{
|
|
10
|
+
path: "/nitrogen/v1/collections",
|
|
11
|
+
method: "get",
|
|
12
|
+
handler: async (req) => {
|
|
13
|
+
const collections = (req.payload.config.collections ?? [])
|
|
14
|
+
.map((collection) => {
|
|
15
|
+
if (!collection?.slug)
|
|
16
|
+
return null;
|
|
17
|
+
const rawLabel = collection.labels?.plural ?? collection.labels?.singular;
|
|
18
|
+
const label = typeof rawLabel === "string"
|
|
19
|
+
? rawLabel
|
|
20
|
+
: humanizeSlug(collection.slug);
|
|
21
|
+
return {
|
|
22
|
+
value: collection.slug,
|
|
23
|
+
label,
|
|
24
|
+
};
|
|
25
|
+
})
|
|
26
|
+
.filter((collection) => collection !== null)
|
|
27
|
+
.sort((a, b) => a.label.localeCompare(b.label));
|
|
28
|
+
return Response.json(collections);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { templatesEndpoints } from "./endpoints/templates";
|
|
|
4
4
|
import { mediaEndpoints } from "./endpoints/media";
|
|
5
5
|
import { nitrogenSettingsEndpoints } from "./endpoints/nitrogen-settings";
|
|
6
6
|
import { allEndpoints } from "./endpoints/all";
|
|
7
|
+
import { collectionsEndpoints } from "./endpoints/collections";
|
|
7
8
|
import { menuEndpoints } from "./endpoints/menu";
|
|
8
9
|
import { createCollectionEndpoints } from "./endpoints/collection-endpoints";
|
|
9
10
|
import { batchEndpoints } from "./endpoints/batch";
|
|
@@ -47,6 +48,7 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
47
48
|
...mediaEndpoints,
|
|
48
49
|
...nitrogenSettingsEndpoints,
|
|
49
50
|
...allEndpoints,
|
|
51
|
+
...collectionsEndpoints,
|
|
50
52
|
...menuEndpoints,
|
|
51
53
|
...batchEndpoints,
|
|
52
54
|
];
|
package/package.json
CHANGED