@nitrogenbuilder/connector-payload 0.1.10 → 0.1.11

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.
@@ -3,6 +3,7 @@ export const NitrogenTemplates = {
3
3
  admin: {
4
4
  useAsTitle: 'title',
5
5
  defaultColumns: ['title', 'associatedCollection', 'updatedAt'],
6
+ group: 'Nitrogen',
6
7
  components: {
7
8
  edit: {
8
9
  beforeDocumentControls: [
@@ -0,0 +1,2 @@
1
+ import type { Endpoint } from 'payload';
2
+ export declare const collectionPickerEndpoints: Endpoint[];
@@ -0,0 +1,52 @@
1
+ export const collectionPickerEndpoints = [
2
+ // GET /api/nitrogen/v1/collection/:slug
3
+ // Generic read-only endpoint for fetching any collection's documents for use
4
+ // in the nitrogen editor's CtrlRelationship control.
5
+ {
6
+ path: '/nitrogen/v1/collection/:slug',
7
+ method: 'get',
8
+ handler: async (req) => {
9
+ const { payload, routeParams } = req;
10
+ const collectionSlug = routeParams?.slug;
11
+ if (!collectionSlug) {
12
+ return Response.json({ error: 'Collection slug is required' }, { status: 400 });
13
+ }
14
+ const url = new URL(req.url || '', 'http://localhost');
15
+ const search = url.searchParams.get('search') || '';
16
+ const page = parseInt(url.searchParams.get('page') || '1', 10);
17
+ const limit = parseInt(url.searchParams.get('limit') || '50', 10);
18
+ const depth = parseInt(url.searchParams.get('depth') || '1', 10);
19
+ try {
20
+ const where = {};
21
+ if (search) {
22
+ where['or'] = [
23
+ { title: { contains: search } },
24
+ { name: { contains: search } },
25
+ ];
26
+ }
27
+ const result = await payload.find({
28
+ collection: collectionSlug,
29
+ where,
30
+ page,
31
+ limit,
32
+ depth,
33
+ overrideAccess: false,
34
+ req,
35
+ });
36
+ return Response.json({
37
+ docs: result.docs,
38
+ totalDocs: result.totalDocs,
39
+ totalPages: result.totalPages,
40
+ page: result.page,
41
+ });
42
+ }
43
+ catch (err) {
44
+ const message = err instanceof Error ? err.message : String(err);
45
+ if (message.includes('not found') || message.includes('Unknown collection')) {
46
+ return Response.json({ error: `Collection "${collectionSlug}" not found` }, { status: 404 });
47
+ }
48
+ return Response.json({ error: message }, { status: 500 });
49
+ }
50
+ },
51
+ },
52
+ ];
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { nitrogenSettingsEndpoints } from "./endpoints/nitrogen-settings";
6
6
  import { allEndpoints } from "./endpoints/all";
7
7
  import { menuEndpoints } from "./endpoints/menu";
8
8
  import { createCollectionEndpoints } from "./endpoints/collection-endpoints";
9
+ import { collectionPickerEndpoints } from "./endpoints/collection-picker";
9
10
  import { registerCollection } from "./collection-registry";
10
11
  /** Fields required by Nitrogen that will be injected into collections if missing */
11
12
  const nitrogenRequiredFields = [
@@ -47,6 +48,7 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
47
48
  ...nitrogenSettingsEndpoints,
48
49
  ...allEndpoints,
49
50
  ...menuEndpoints,
51
+ ...collectionPickerEndpoints,
50
52
  ];
51
53
  // Register templates collection
52
54
  registerCollection("nitrogen-templates", "nitrogen-templates");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrogenbuilder/connector-payload",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
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",
@@ -24,11 +24,6 @@
24
24
  "files": [
25
25
  "dist"
26
26
  ],
27
- "scripts": {
28
- "build": "tsc",
29
- "typecheck": "tsc --noEmit",
30
- "prepublishOnly": "pnpm build"
31
- },
32
27
  "peerDependencies": {
33
28
  "payload": "^3.0.0",
34
29
  "next": "^15.0.0",
@@ -45,5 +40,9 @@
45
40
  "@nitrogenbuilder/client-react": "link:../monogen/packages/client-react",
46
41
  "@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
47
42
  "@nitrogenbuilder/types": "link:../monogen/packages/types"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "typecheck": "tsc --noEmit"
48
47
  }
49
- }
48
+ }