@nitrogenbuilder/connector-payload 0.1.53 → 1.1.0
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/NitrogenEditButtonRuntime.js +11 -15
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/editor/NitrogenEditorAssetsRoute.js +2 -0
- package/dist/editor/NitrogenEditorPage.js +33 -5
- package/dist/editor-assets/fa620pro/icons.json +1 -0
- package/dist/editor-assets/icons/ionicons.json +1 -0
- package/dist/editor-assets/icons/lucide.json +1 -0
- package/dist/endpoints/component-inventory.js +1 -1
- package/dist/index.js +3 -2
- package/dist/inventory/indexing.d.ts +6 -6
- package/dist/inventory/indexing.js +28 -21
- package/package.json +2 -2
|
@@ -203,7 +203,7 @@ export function createComponentInventoryEndpoints(args) {
|
|
|
203
203
|
const authError = requireAuth(req);
|
|
204
204
|
if (authError)
|
|
205
205
|
return authError;
|
|
206
|
-
const result = await reindexAllComponentInventory(req.payload, args.collections, args.componentManifest);
|
|
206
|
+
const result = await reindexAllComponentInventory(req.payload, args.collections, args.componentManifest, req);
|
|
207
207
|
return Response.json({
|
|
208
208
|
success: true,
|
|
209
209
|
...result,
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,8 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
57
57
|
const createAfterChangeHook = (collectionSlug) => {
|
|
58
58
|
return async ({ doc, req }) => {
|
|
59
59
|
if (doc) {
|
|
60
|
-
|
|
60
|
+
// Pass `req` so inventory writes join the caller's transaction.
|
|
61
|
+
await reindexDocumentUsage(req.payload, collectionSlug, doc, collectionSlug === 'nitrogen-templates' ? 'template' : 'document', req);
|
|
61
62
|
}
|
|
62
63
|
return doc;
|
|
63
64
|
};
|
|
@@ -66,7 +67,7 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
66
67
|
return async ({ doc, id, req, }) => {
|
|
67
68
|
const sourceId = doc?.id ?? id;
|
|
68
69
|
if (sourceId !== undefined) {
|
|
69
|
-
await deleteDocumentUsage(req.payload, collectionSlug, sourceId);
|
|
70
|
+
await deleteDocumentUsage(req.payload, collectionSlug, sourceId, req);
|
|
70
71
|
}
|
|
71
72
|
return doc;
|
|
72
73
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentManifestEntry } from '@nitrogenbuilder/types';
|
|
2
|
-
import type { Payload, Where } from 'payload';
|
|
2
|
+
import type { Payload, PayloadRequest, Where } from 'payload';
|
|
3
3
|
import type { NitrogenInventorySourceDoc } from '../types.js';
|
|
4
4
|
import { type NitrogenComponentManifestInput } from './manifest.js';
|
|
5
5
|
export declare const NITROGEN_COMPONENT_CATALOG_COLLECTION = "nitrogen-component-catalog";
|
|
@@ -23,9 +23,9 @@ export declare function findAllDocs<T extends object>(payload: Payload, collecti
|
|
|
23
23
|
limit?: number;
|
|
24
24
|
select?: Record<string, true>;
|
|
25
25
|
where?: Where;
|
|
26
|
-
}): Promise<T[]>;
|
|
27
|
-
export declare function syncComponentCatalog(payload: Payload, manifestInput?: NitrogenComponentManifestInput): Promise<ComponentManifestEntry[]>;
|
|
28
|
-
export declare function reindexDocumentUsage(payload: Payload, sourceCollection: string, doc: NitrogenInventorySourceDoc, sourceType?: 'document' | 'template'): Promise<number>;
|
|
29
|
-
export declare function deleteDocumentUsage(payload: Payload, sourceCollection: string, sourceDocumentId: string | number): Promise<void>;
|
|
30
|
-
export declare function reindexAllComponentInventory(payload: Payload, collections: string[], manifestInput?: NitrogenComponentManifestInput): Promise<ReindexResult>;
|
|
26
|
+
}, req?: PayloadRequest): Promise<T[]>;
|
|
27
|
+
export declare function syncComponentCatalog(payload: Payload, manifestInput?: NitrogenComponentManifestInput, req?: PayloadRequest): Promise<ComponentManifestEntry[]>;
|
|
28
|
+
export declare function reindexDocumentUsage(payload: Payload, sourceCollection: string, doc: NitrogenInventorySourceDoc, sourceType?: 'document' | 'template', req?: PayloadRequest): Promise<number>;
|
|
29
|
+
export declare function deleteDocumentUsage(payload: Payload, sourceCollection: string, sourceDocumentId: string | number, req?: PayloadRequest): Promise<void>;
|
|
30
|
+
export declare function reindexAllComponentInventory(payload: Payload, collections: string[], manifestInput?: NitrogenComponentManifestInput, req?: PayloadRequest): Promise<ReindexResult>;
|
|
31
31
|
export {};
|
|
@@ -62,7 +62,7 @@ export function extractComponentUsageRecords(modules) {
|
|
|
62
62
|
collectUsageFromTree(modules, 'modules', results);
|
|
63
63
|
return results;
|
|
64
64
|
}
|
|
65
|
-
export async function findAllDocs(payload, collection, options) {
|
|
65
|
+
export async function findAllDocs(payload, collection, options, req) {
|
|
66
66
|
const docs = [];
|
|
67
67
|
let page = 1;
|
|
68
68
|
let hasNextPage = true;
|
|
@@ -74,6 +74,7 @@ export async function findAllDocs(payload, collection, options) {
|
|
|
74
74
|
page,
|
|
75
75
|
overrideAccess: true,
|
|
76
76
|
pagination: true,
|
|
77
|
+
req,
|
|
77
78
|
select: options?.select,
|
|
78
79
|
where: options?.where,
|
|
79
80
|
});
|
|
@@ -83,16 +84,17 @@ export async function findAllDocs(payload, collection, options) {
|
|
|
83
84
|
}
|
|
84
85
|
return docs;
|
|
85
86
|
}
|
|
86
|
-
async function deleteUsageDocs(payload, docs) {
|
|
87
|
+
async function deleteUsageDocs(payload, docs, req) {
|
|
87
88
|
for (const doc of docs) {
|
|
88
89
|
await payload.delete({
|
|
89
90
|
collection: NITROGEN_COMPONENT_USAGE_COLLECTION,
|
|
90
91
|
id: doc.id,
|
|
91
92
|
overrideAccess: true,
|
|
93
|
+
req,
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
|
-
async function findUsageDocsForSource(payload, sourceCollection, sourceDocumentId) {
|
|
97
|
+
async function findUsageDocsForSource(payload, sourceCollection, sourceDocumentId, req) {
|
|
96
98
|
return findAllDocs(payload, NITROGEN_COMPONENT_USAGE_COLLECTION, {
|
|
97
99
|
limit: 100,
|
|
98
100
|
select: {
|
|
@@ -112,15 +114,16 @@ async function findUsageDocsForSource(payload, sourceCollection, sourceDocumentI
|
|
|
112
114
|
},
|
|
113
115
|
],
|
|
114
116
|
},
|
|
115
|
-
});
|
|
117
|
+
}, req);
|
|
116
118
|
}
|
|
117
|
-
async function createUsageDocs(payload, sourceCollection, sourceType, doc) {
|
|
119
|
+
async function createUsageDocs(payload, sourceCollection, sourceType, doc, req) {
|
|
118
120
|
const sourceDocumentId = String(doc.id);
|
|
119
121
|
const usageRecords = extractComponentUsageRecords(doc.nitrogenData);
|
|
120
122
|
for (const record of usageRecords) {
|
|
121
123
|
await payload.create({
|
|
122
124
|
collection: NITROGEN_COMPONENT_USAGE_COLLECTION,
|
|
123
125
|
overrideAccess: true,
|
|
126
|
+
req,
|
|
124
127
|
data: {
|
|
125
128
|
usageKey: `${sourceCollection}:${sourceDocumentId}:${record.moduleId}:${record.modulePath}:${record.componentName}`,
|
|
126
129
|
componentName: record.componentName,
|
|
@@ -141,10 +144,10 @@ async function createUsageDocs(payload, sourceCollection, sourceType, doc) {
|
|
|
141
144
|
}
|
|
142
145
|
return usageRecords.length;
|
|
143
146
|
}
|
|
144
|
-
export async function syncComponentCatalog(payload, manifestInput) {
|
|
147
|
+
export async function syncComponentCatalog(payload, manifestInput, req) {
|
|
145
148
|
const manifest = await resolveComponentManifest(manifestInput);
|
|
146
149
|
const entries = manifest.components || [];
|
|
147
|
-
const existingDocs = await findAllDocs(payload, NITROGEN_COMPONENT_CATALOG_COLLECTION);
|
|
150
|
+
const existingDocs = await findAllDocs(payload, NITROGEN_COMPONENT_CATALOG_COLLECTION, undefined, req);
|
|
148
151
|
const existingByName = new Map(existingDocs.map((doc) => [doc.componentName, doc]));
|
|
149
152
|
const nextNames = new Set(entries.map((entry) => entry.name));
|
|
150
153
|
for (const entry of entries) {
|
|
@@ -153,7 +156,8 @@ export async function syncComponentCatalog(payload, manifestInput) {
|
|
|
153
156
|
componentName: entry.name,
|
|
154
157
|
scope: entry.scope || '',
|
|
155
158
|
sidebarCategory: entry.sidebarCategory || '',
|
|
156
|
-
|
|
159
|
+
// Icons are no longer carried on the manifest entry; they're assigned in
|
|
160
|
+
// the editor (Settings > Component Icons) and stored in NitrogenSettings.
|
|
157
161
|
definition: entry,
|
|
158
162
|
source: manifest.source || '',
|
|
159
163
|
};
|
|
@@ -163,6 +167,7 @@ export async function syncComponentCatalog(payload, manifestInput) {
|
|
|
163
167
|
id: existing.id,
|
|
164
168
|
data,
|
|
165
169
|
overrideAccess: true,
|
|
170
|
+
req,
|
|
166
171
|
});
|
|
167
172
|
}
|
|
168
173
|
else {
|
|
@@ -170,6 +175,7 @@ export async function syncComponentCatalog(payload, manifestInput) {
|
|
|
170
175
|
collection: NITROGEN_COMPONENT_CATALOG_COLLECTION,
|
|
171
176
|
data,
|
|
172
177
|
overrideAccess: true,
|
|
178
|
+
req,
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
181
|
}
|
|
@@ -179,30 +185,31 @@ export async function syncComponentCatalog(payload, manifestInput) {
|
|
|
179
185
|
collection: NITROGEN_COMPONENT_CATALOG_COLLECTION,
|
|
180
186
|
id: existing.id,
|
|
181
187
|
overrideAccess: true,
|
|
188
|
+
req,
|
|
182
189
|
});
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
192
|
return entries;
|
|
186
193
|
}
|
|
187
|
-
export async function reindexDocumentUsage(payload, sourceCollection, doc, sourceType = 'document') {
|
|
194
|
+
export async function reindexDocumentUsage(payload, sourceCollection, doc, sourceType = 'document', req) {
|
|
188
195
|
const sourceDocumentId = String(doc.id);
|
|
189
|
-
const docsForSource = await findUsageDocsForSource(payload, sourceCollection, sourceDocumentId);
|
|
190
|
-
await deleteUsageDocs(payload, docsForSource);
|
|
191
|
-
return createUsageDocs(payload, sourceCollection, sourceType, doc);
|
|
196
|
+
const docsForSource = await findUsageDocsForSource(payload, sourceCollection, sourceDocumentId, req);
|
|
197
|
+
await deleteUsageDocs(payload, docsForSource, req);
|
|
198
|
+
return createUsageDocs(payload, sourceCollection, sourceType, doc, req);
|
|
192
199
|
}
|
|
193
|
-
export async function deleteDocumentUsage(payload, sourceCollection, sourceDocumentId) {
|
|
194
|
-
const docsForSource = await findUsageDocsForSource(payload, sourceCollection, String(sourceDocumentId));
|
|
195
|
-
await deleteUsageDocs(payload, docsForSource);
|
|
200
|
+
export async function deleteDocumentUsage(payload, sourceCollection, sourceDocumentId, req) {
|
|
201
|
+
const docsForSource = await findUsageDocsForSource(payload, sourceCollection, String(sourceDocumentId), req);
|
|
202
|
+
await deleteUsageDocs(payload, docsForSource, req);
|
|
196
203
|
}
|
|
197
|
-
export async function reindexAllComponentInventory(payload, collections, manifestInput) {
|
|
198
|
-
const entries = await syncComponentCatalog(payload, manifestInput);
|
|
204
|
+
export async function reindexAllComponentInventory(payload, collections, manifestInput, req) {
|
|
205
|
+
const entries = await syncComponentCatalog(payload, manifestInput, req);
|
|
199
206
|
const usageDocs = await findAllDocs(payload, NITROGEN_COMPONENT_USAGE_COLLECTION, {
|
|
200
207
|
limit: 200,
|
|
201
208
|
select: {
|
|
202
209
|
id: true,
|
|
203
210
|
},
|
|
204
|
-
});
|
|
205
|
-
await deleteUsageDocs(payload, usageDocs);
|
|
211
|
+
}, req);
|
|
212
|
+
await deleteUsageDocs(payload, usageDocs, req);
|
|
206
213
|
let documentCount = 0;
|
|
207
214
|
let usageCount = 0;
|
|
208
215
|
for (const collection of collections) {
|
|
@@ -216,10 +223,10 @@ export async function reindexAllComponentInventory(payload, collections, manifes
|
|
|
216
223
|
_status: true,
|
|
217
224
|
nitrogenData: true,
|
|
218
225
|
},
|
|
219
|
-
});
|
|
226
|
+
}, req);
|
|
220
227
|
for (const doc of docs) {
|
|
221
228
|
documentCount += 1;
|
|
222
|
-
usageCount += await createUsageDocs(payload, collection, collection === 'nitrogen-templates' ? 'template' : 'document', doc);
|
|
229
|
+
usageCount += await createUsageDocs(payload, collection, collection === 'nitrogen-templates' ? 'template' : 'document', doc, req);
|
|
223
230
|
}
|
|
224
231
|
}
|
|
225
232
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
|
|
5
5
|
"author": "Leonardo Dentzien <leo@torchmedia.ca>",
|
|
6
6
|
"type": "module",
|
|
@@ -55,4 +55,4 @@
|
|
|
55
55
|
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
56
56
|
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|