payload-mcp-toolkit 0.7.0 → 0.7.4
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 +29 -8
- package/dist/api-keys.js +57 -21
- package/dist/api-keys.js.map +1 -1
- package/dist/auth-strategy.d.ts +18 -7
- package/dist/auth-strategy.js +54 -12
- package/dist/auth-strategy.js.map +1 -1
- package/dist/tools/_helpers.d.ts +34 -0
- package/dist/tools/_helpers.js +98 -0
- package/dist/tools/_helpers.js.map +1 -1
- package/dist/tools/publish-draft.js +33 -1
- package/dist/tools/publish-draft.js.map +1 -1
- package/dist/tools/publish-global-draft.js +30 -1
- package/dist/tools/publish-global-draft.js.map +1 -1
- package/package.json +29 -15
- package/dist/__tests__/api-keys.test.js +0 -292
- package/dist/__tests__/api-keys.test.js.map +0 -1
- package/dist/__tests__/auth-strategy.test.js +0 -681
- package/dist/__tests__/auth-strategy.test.js.map +0 -1
- package/dist/__tests__/conflict-detection.test.js +0 -69
- package/dist/__tests__/conflict-detection.test.js.map +0 -1
- package/dist/__tests__/delete-document.test.js +0 -70
- package/dist/__tests__/delete-document.test.js.map +0 -1
- package/dist/__tests__/endpoint.test.js +0 -143
- package/dist/__tests__/endpoint.test.js.map +0 -1
- package/dist/__tests__/find-document.test.js +0 -178
- package/dist/__tests__/find-document.test.js.map +0 -1
- package/dist/__tests__/find-global.test.js +0 -173
- package/dist/__tests__/find-global.test.js.map +0 -1
- package/dist/__tests__/global-versions.test.js +0 -183
- package/dist/__tests__/global-versions.test.js.map +0 -1
- package/dist/__tests__/hash.test.js +0 -58
- package/dist/__tests__/hash.test.js.map +0 -1
- package/dist/__tests__/index-integration.test.js +0 -191
- package/dist/__tests__/index-integration.test.js.map +0 -1
- package/dist/__tests__/introspection.test.js +0 -659
- package/dist/__tests__/introspection.test.js.map +0 -1
- package/dist/__tests__/patch-global-layout.test.js +0 -474
- package/dist/__tests__/patch-global-layout.test.js.map +0 -1
- package/dist/__tests__/patch-layout.test.js +0 -171
- package/dist/__tests__/patch-layout.test.js.map +0 -1
- package/dist/__tests__/registry.test.js +0 -795
- package/dist/__tests__/registry.test.js.map +0 -1
- package/dist/__tests__/resources.test.js +0 -139
- package/dist/__tests__/resources.test.js.map +0 -1
- package/dist/__tests__/update-global.test.js +0 -157
- package/dist/__tests__/update-global.test.js.map +0 -1
- package/dist/__tests__/url-validator.test.js +0 -326
- package/dist/__tests__/url-validator.test.js.map +0 -1
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { introspectBlocks, buildBlockNestingMap } from '../introspection';
|
|
3
|
-
import { createPatchLayoutTool } from '../tools/patch-layout';
|
|
4
|
-
const Heading = {
|
|
5
|
-
slug: 'heading',
|
|
6
|
-
fields: [
|
|
7
|
-
{
|
|
8
|
-
name: 'text',
|
|
9
|
-
type: 'text'
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
};
|
|
13
|
-
const CtaBanner = {
|
|
14
|
-
slug: 'ctaBanner',
|
|
15
|
-
fields: [
|
|
16
|
-
{
|
|
17
|
-
name: 'label',
|
|
18
|
-
type: 'text'
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
const Pages = {
|
|
23
|
-
slug: 'pages',
|
|
24
|
-
versions: {
|
|
25
|
-
drafts: true
|
|
26
|
-
},
|
|
27
|
-
fields: [
|
|
28
|
-
{
|
|
29
|
-
name: 'layout',
|
|
30
|
-
type: 'blocks',
|
|
31
|
-
blocks: [
|
|
32
|
-
Heading,
|
|
33
|
-
CtaBanner
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
function buildReq() {
|
|
39
|
-
return {
|
|
40
|
-
payload: {
|
|
41
|
-
findByID: vi.fn(),
|
|
42
|
-
update: vi.fn(),
|
|
43
|
-
logger: {
|
|
44
|
-
info: vi.fn(),
|
|
45
|
-
warn: vi.fn(),
|
|
46
|
-
error: vi.fn()
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
context: {},
|
|
50
|
-
user: null
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const allBlocks = [
|
|
54
|
-
Heading,
|
|
55
|
-
CtaBanner
|
|
56
|
-
];
|
|
57
|
-
const catalog = introspectBlocks(allBlocks);
|
|
58
|
-
const nesting = buildBlockNestingMap([
|
|
59
|
-
Pages
|
|
60
|
-
], [], allBlocks);
|
|
61
|
-
const drafts = new Set([
|
|
62
|
-
'pages'
|
|
63
|
-
]);
|
|
64
|
-
describe('patchLayout', ()=>{
|
|
65
|
-
it('flat layoutField writes {[layoutField]: finalLayout} — no regression from shared writePath', async ()=>{
|
|
66
|
-
// After extracting writePath into _layout-helpers, the collection tool
|
|
67
|
-
// doesn't itself use writePath, but this is the canonical regression
|
|
68
|
-
// check that the flat-path shape stays a single top-level key so
|
|
69
|
-
// Payload's `update` merges normally.
|
|
70
|
-
const tool = createPatchLayoutTool(catalog, nesting, drafts);
|
|
71
|
-
const req = buildReq();
|
|
72
|
-
req.payload.findByID.mockResolvedValue({
|
|
73
|
-
id: '1',
|
|
74
|
-
layout: [
|
|
75
|
-
{
|
|
76
|
-
blockType: 'heading',
|
|
77
|
-
text: 'a'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
});
|
|
81
|
-
req.payload.update.mockResolvedValue({
|
|
82
|
-
id: '1',
|
|
83
|
-
title: 'p'
|
|
84
|
-
});
|
|
85
|
-
await tool.handler({
|
|
86
|
-
collection: 'pages',
|
|
87
|
-
documentId: '1',
|
|
88
|
-
layoutField: 'layout',
|
|
89
|
-
blocks: [
|
|
90
|
-
{
|
|
91
|
-
blockType: 'ctaBanner',
|
|
92
|
-
label: 'Buy'
|
|
93
|
-
}
|
|
94
|
-
],
|
|
95
|
-
operation: 'append'
|
|
96
|
-
}, req, {});
|
|
97
|
-
expect(req.payload.update).toHaveBeenCalledWith(expect.objectContaining({
|
|
98
|
-
collection: 'pages',
|
|
99
|
-
id: '1',
|
|
100
|
-
data: {
|
|
101
|
-
layout: [
|
|
102
|
-
{
|
|
103
|
-
blockType: 'heading',
|
|
104
|
-
text: 'a'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
blockType: 'ctaBanner',
|
|
108
|
-
label: 'Buy'
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
114
|
-
it('full operation replaces the array wholesale', async ()=>{
|
|
115
|
-
const tool = createPatchLayoutTool(catalog, nesting, drafts);
|
|
116
|
-
const req = buildReq();
|
|
117
|
-
req.payload.findByID.mockResolvedValue({
|
|
118
|
-
id: '1',
|
|
119
|
-
layout: [
|
|
120
|
-
{
|
|
121
|
-
blockType: 'heading',
|
|
122
|
-
text: 'old'
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
});
|
|
126
|
-
req.payload.update.mockResolvedValue({
|
|
127
|
-
id: '1'
|
|
128
|
-
});
|
|
129
|
-
await tool.handler({
|
|
130
|
-
collection: 'pages',
|
|
131
|
-
documentId: '1',
|
|
132
|
-
layoutField: 'layout',
|
|
133
|
-
blocks: [
|
|
134
|
-
{
|
|
135
|
-
blockType: 'heading',
|
|
136
|
-
text: 'new'
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
operation: 'full'
|
|
140
|
-
}, req, {});
|
|
141
|
-
expect(req.payload.update).toHaveBeenCalledWith(expect.objectContaining({
|
|
142
|
-
data: {
|
|
143
|
-
layout: [
|
|
144
|
-
{
|
|
145
|
-
blockType: 'heading',
|
|
146
|
-
text: 'new'
|
|
147
|
-
}
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
}));
|
|
151
|
-
});
|
|
152
|
-
it('rejects unknown blockType with validation error', async ()=>{
|
|
153
|
-
const tool = createPatchLayoutTool(catalog, nesting, drafts);
|
|
154
|
-
const req = buildReq();
|
|
155
|
-
const result = await tool.handler({
|
|
156
|
-
collection: 'pages',
|
|
157
|
-
documentId: '1',
|
|
158
|
-
layoutField: 'layout',
|
|
159
|
-
blocks: [
|
|
160
|
-
{
|
|
161
|
-
blockType: 'mystery'
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
operation: 'full'
|
|
165
|
-
}, req, {});
|
|
166
|
-
expect(result.content[0].text).toMatch(/unknown blockType/i);
|
|
167
|
-
expect(req.payload.update).not.toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
//# sourceMappingURL=patch-layout.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/__tests__/patch-layout.test.ts"],"sourcesContent":["import { describe, it, expect, vi } from 'vitest'\r\nimport type { Block, CollectionConfig } from 'payload'\r\nimport { introspectBlocks, buildBlockNestingMap } from '../introspection'\r\nimport { createPatchLayoutTool } from '../tools/patch-layout'\r\n\r\nconst Heading: Block = { slug: 'heading', fields: [{ name: 'text', type: 'text' }] }\r\nconst CtaBanner: Block = { slug: 'ctaBanner', fields: [{ name: 'label', type: 'text' }] }\r\n\r\nconst Pages: CollectionConfig = {\r\n slug: 'pages',\r\n versions: { drafts: true },\r\n fields: [\r\n {\r\n name: 'layout',\r\n type: 'blocks',\r\n blocks: [Heading, CtaBanner],\r\n },\r\n ],\r\n}\r\n\r\nfunction buildReq() {\r\n return {\r\n payload: {\r\n findByID: vi.fn(),\r\n update: vi.fn(),\r\n logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },\r\n },\r\n context: {},\r\n user: null,\r\n }\r\n}\r\n\r\nconst allBlocks = [Heading, CtaBanner]\r\nconst catalog = introspectBlocks(allBlocks)\r\nconst nesting = buildBlockNestingMap([Pages], [], allBlocks)\r\nconst drafts = new Set(['pages'])\r\n\r\ndescribe('patchLayout', () => {\r\n it('flat layoutField writes {[layoutField]: finalLayout} — no regression from shared writePath', async () => {\r\n // After extracting writePath into _layout-helpers, the collection tool\r\n // doesn't itself use writePath, but this is the canonical regression\r\n // check that the flat-path shape stays a single top-level key so\r\n // Payload's `update` merges normally.\r\n const tool = createPatchLayoutTool(catalog, nesting, drafts)\r\n const req = buildReq()\r\n req.payload.findByID.mockResolvedValue({\r\n id: '1',\r\n layout: [{ blockType: 'heading', text: 'a' }],\r\n })\r\n req.payload.update.mockResolvedValue({ id: '1', title: 'p' })\r\n\r\n await tool.handler(\r\n {\r\n collection: 'pages',\r\n documentId: '1',\r\n layoutField: 'layout',\r\n blocks: [{ blockType: 'ctaBanner', label: 'Buy' }],\r\n operation: 'append',\r\n },\r\n req as never,\r\n {},\r\n )\r\n\r\n expect(req.payload.update).toHaveBeenCalledWith(\r\n expect.objectContaining({\r\n collection: 'pages',\r\n id: '1',\r\n data: {\r\n layout: [\r\n { blockType: 'heading', text: 'a' },\r\n { blockType: 'ctaBanner', label: 'Buy' },\r\n ],\r\n },\r\n }),\r\n )\r\n })\r\n\r\n it('full operation replaces the array wholesale', async () => {\r\n const tool = createPatchLayoutTool(catalog, nesting, drafts)\r\n const req = buildReq()\r\n req.payload.findByID.mockResolvedValue({\r\n id: '1',\r\n layout: [{ blockType: 'heading', text: 'old' }],\r\n })\r\n req.payload.update.mockResolvedValue({ id: '1' })\r\n\r\n await tool.handler(\r\n {\r\n collection: 'pages',\r\n documentId: '1',\r\n layoutField: 'layout',\r\n blocks: [{ blockType: 'heading', text: 'new' }],\r\n operation: 'full',\r\n },\r\n req as never,\r\n {},\r\n )\r\n\r\n expect(req.payload.update).toHaveBeenCalledWith(\r\n expect.objectContaining({\r\n data: { layout: [{ blockType: 'heading', text: 'new' }] },\r\n }),\r\n )\r\n })\r\n\r\n it('rejects unknown blockType with validation error', async () => {\r\n const tool = createPatchLayoutTool(catalog, nesting, drafts)\r\n const req = buildReq()\r\n const result = await tool.handler(\r\n {\r\n collection: 'pages',\r\n documentId: '1',\r\n layoutField: 'layout',\r\n blocks: [{ blockType: 'mystery' }],\r\n operation: 'full',\r\n },\r\n req as never,\r\n {},\r\n )\r\n expect(result.content[0]!.text).toMatch(/unknown blockType/i)\r\n expect(req.payload.update).not.toHaveBeenCalled()\r\n })\r\n})\r\n"],"names":["describe","it","expect","vi","introspectBlocks","buildBlockNestingMap","createPatchLayoutTool","Heading","slug","fields","name","type","CtaBanner","Pages","versions","drafts","blocks","buildReq","payload","findByID","fn","update","logger","info","warn","error","context","user","allBlocks","catalog","nesting","Set","tool","req","mockResolvedValue","id","layout","blockType","text","title","handler","collection","documentId","layoutField","label","operation","toHaveBeenCalledWith","objectContaining","data","result","content","toMatch","not","toHaveBeenCalled"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,mBAAkB;AACzE,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D,MAAMC,UAAiB;IAAEC,MAAM;IAAWC,QAAQ;QAAC;YAAEC,MAAM;YAAQC,MAAM;QAAO;KAAE;AAAC;AACnF,MAAMC,YAAmB;IAAEJ,MAAM;IAAaC,QAAQ;QAAC;YAAEC,MAAM;YAASC,MAAM;QAAO;KAAE;AAAC;AAExF,MAAME,QAA0B;IAC9BL,MAAM;IACNM,UAAU;QAAEC,QAAQ;IAAK;IACzBN,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;YACNK,QAAQ;gBAACT;gBAASK;aAAU;QAC9B;KACD;AACH;AAEA,SAASK;IACP,OAAO;QACLC,SAAS;YACPC,UAAUhB,GAAGiB,EAAE;YACfC,QAAQlB,GAAGiB,EAAE;YACbE,QAAQ;gBAAEC,MAAMpB,GAAGiB,EAAE;gBAAII,MAAMrB,GAAGiB,EAAE;gBAAIK,OAAOtB,GAAGiB,EAAE;YAAG;QACzD;QACAM,SAAS,CAAC;QACVC,MAAM;IACR;AACF;AAEA,MAAMC,YAAY;IAACrB;IAASK;CAAU;AACtC,MAAMiB,UAAUzB,iBAAiBwB;AACjC,MAAME,UAAUz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