@nitrogenbuilder/connector-payload 0.1.18 → 0.1.20
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/LockedJsonField.d.ts +1 -2
- package/dist/components/LockedJsonField.js +6 -38
- package/dist/components/LockedJsonFieldRuntime.d.ts +10 -0
- package/dist/components/LockedJsonFieldRuntime.js +38 -0
- package/dist/components/NitrogenDataViewer.js +5 -345
- package/dist/components/NitrogenDataViewerRuntime.d.ts +3 -0
- package/dist/components/NitrogenDataViewerRuntime.js +353 -0
- package/dist/components/NitrogenEditButton.d.ts +1 -2
- package/dist/components/NitrogenEditButton.js +6 -86
- package/dist/components/NitrogenEditButtonRuntime.d.ts +4 -0
- package/dist/components/NitrogenEditButtonRuntime.js +75 -0
- package/dist/components/NitrogenViewButton.d.ts +1 -2
- package/dist/components/NitrogenViewButton.js +6 -55
- package/dist/components/NitrogenViewButtonRuntime.d.ts +4 -0
- package/dist/components/NitrogenViewButtonRuntime.js +43 -0
- 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
|
@@ -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