payload-mcp-toolkit 0.3.4 → 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 +253 -151
- package/dist/api-keys.d.ts +46 -0
- package/dist/api-keys.js +308 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/auth-strategy.d.ts +96 -0
- package/dist/auth-strategy.js +261 -0
- package/dist/auth-strategy.js.map +1 -0
- package/dist/components/CollectionScopesMatrix.d.ts +8 -0
- package/dist/components/CollectionScopesMatrix.js +32 -0
- package/dist/components/CollectionScopesMatrix.js.map +1 -0
- package/dist/components/GlobalScopesMatrix.d.ts +8 -0
- package/dist/components/GlobalScopesMatrix.js +28 -0
- package/dist/components/GlobalScopesMatrix.js.map +1 -0
- package/dist/components/ScopesTable.d.ts +19 -0
- package/dist/components/ScopesTable.js +285 -0
- package/dist/components/ScopesTable.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/conflict-detection.d.ts +13 -0
- package/dist/conflict-detection.js +41 -0
- package/dist/conflict-detection.js.map +1 -0
- package/dist/draft-workflow.d.ts +46 -48
- package/dist/draft-workflow.js +53 -135
- package/dist/draft-workflow.js.map +1 -1
- package/dist/endpoint.d.ts +35 -0
- package/dist/endpoint.js +105 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/hash.d.ts +21 -0
- package/dist/hash.js +36 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +167 -69
- package/dist/index.js.map +1 -1
- package/dist/introspection.d.ts +17 -3
- package/dist/introspection.js +95 -36
- package/dist/introspection.js.map +1 -1
- package/dist/prompts.js +5 -5
- package/dist/prompts.js.map +1 -1
- package/dist/registry.d.ts +50 -0
- package/dist/registry.js +169 -0
- package/dist/registry.js.map +1 -0
- package/dist/resources.d.ts +5 -3
- package/dist/resources.js +23 -11
- package/dist/resources.js.map +1 -1
- package/dist/scope/audit-log.d.ts +18 -0
- package/dist/scope/audit-log.js +50 -0
- package/dist/scope/audit-log.js.map +1 -0
- package/dist/scope/policy.d.ts +73 -0
- package/dist/scope/policy.js +218 -0
- package/dist/scope/policy.js.map +1 -0
- package/dist/tools/_helpers.d.ts +62 -1
- package/dist/tools/_helpers.js +181 -0
- package/dist/tools/_helpers.js.map +1 -1
- package/dist/tools/_layout-helpers.d.ts +43 -0
- package/dist/tools/_layout-helpers.js +159 -0
- package/dist/tools/_layout-helpers.js.map +1 -0
- package/dist/tools/create-document.d.ts +5 -5
- package/dist/tools/create-document.js +25 -21
- package/dist/tools/create-document.js.map +1 -1
- package/dist/tools/delete-document.d.ts +25 -0
- package/dist/tools/delete-document.js +49 -0
- package/dist/tools/delete-document.js.map +1 -0
- package/dist/tools/find-document.d.ts +33 -0
- package/dist/tools/find-document.js +97 -0
- package/dist/tools/find-document.js.map +1 -0
- package/dist/tools/find-global.d.ts +26 -0
- package/dist/tools/find-global.js +122 -0
- package/dist/tools/find-global.js.map +1 -0
- package/dist/tools/global-versions.d.ts +39 -0
- package/dist/tools/global-versions.js +132 -0
- package/dist/tools/global-versions.js.map +1 -0
- package/dist/tools/patch-global-layout.d.ts +31 -0
- package/dist/tools/patch-global-layout.js +127 -0
- package/dist/tools/patch-global-layout.js.map +1 -0
- package/dist/tools/patch-layout.d.ts +5 -8
- package/dist/tools/patch-layout.js +18 -100
- package/dist/tools/patch-layout.js.map +1 -1
- package/dist/tools/publish-draft.d.ts +5 -4
- package/dist/tools/publish-draft.js +39 -2
- package/dist/tools/publish-draft.js.map +1 -1
- package/dist/tools/publish-global-draft.d.ts +20 -0
- package/dist/tools/publish-global-draft.js +79 -0
- package/dist/tools/publish-global-draft.js.map +1 -0
- package/dist/tools/resolve-reference.d.ts +5 -4
- package/dist/tools/resolve-reference.js +4 -0
- package/dist/tools/resolve-reference.js.map +1 -1
- package/dist/tools/safe-delete.d.ts +5 -5
- package/dist/tools/safe-delete.js +20 -15
- package/dist/tools/safe-delete.js.map +1 -1
- package/dist/tools/schedule-publish.d.ts +5 -5
- package/dist/tools/schedule-publish.js +23 -19
- package/dist/tools/schedule-publish.js.map +1 -1
- package/dist/tools/search-content.d.ts +5 -9
- package/dist/tools/search-content.js +16 -12
- package/dist/tools/search-content.js.map +1 -1
- package/dist/tools/update-document.d.ts +5 -5
- package/dist/tools/update-document.js +10 -5
- package/dist/tools/update-document.js.map +1 -1
- package/dist/tools/update-global.d.ts +27 -0
- package/dist/tools/update-global.js +72 -0
- package/dist/tools/update-global.js.map +1 -0
- package/dist/tools/upload-media.d.ts +5 -4
- package/dist/tools/upload-media.js +6 -1
- package/dist/tools/upload-media.js.map +1 -1
- package/dist/tools/versions.d.ts +10 -9
- package/dist/tools/versions.js +15 -7
- package/dist/tools/versions.js.map +1 -1
- package/dist/types.d.ts +56 -3
- package/dist/types.js +13 -6
- package/dist/types.js.map +1 -1
- package/package.json +39 -18
- package/dist/__tests__/introspection.test.js +0 -459
- package/dist/__tests__/introspection.test.js.map +0 -1
- package/dist/__tests__/url-validator.test.js +0 -326
- package/dist/__tests__/url-validator.test.js.map +0 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { extractBearerToken, hashKey } from './hash';
|
|
2
|
+
export const AUTH_STRATEGY_NAME = 'mcp-toolkit-bearer';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the row's slug, tolerating the pre-0.6 `collection` / `global`
|
|
5
|
+
* keys for one release. Logs a one-line warn when the legacy fallback
|
|
6
|
+
* fires so operators can spot keys that need re-saving. The fallback is
|
|
7
|
+
* scheduled for removal in v0.7.
|
|
8
|
+
*/ let warnedLegacyShape = false;
|
|
9
|
+
let warnedLegacyNonCustomOverride = false;
|
|
10
|
+
/** @internal test-only: reset the one-time legacy warns. */ export function _resetLegacyWarnsForTests() {
|
|
11
|
+
warnedLegacyShape = false;
|
|
12
|
+
warnedLegacyNonCustomOverride = false;
|
|
13
|
+
}
|
|
14
|
+
function readScopeSlug(entry, legacyKey, logger) {
|
|
15
|
+
if (typeof entry?.slug === 'string') return entry.slug;
|
|
16
|
+
const legacy = entry?.[legacyKey];
|
|
17
|
+
if (typeof legacy === 'string') {
|
|
18
|
+
if (!warnedLegacyShape) {
|
|
19
|
+
warnedLegacyShape = true;
|
|
20
|
+
logger?.warn?.({
|
|
21
|
+
event: 'mcp.auth.legacy_scope_shape',
|
|
22
|
+
legacyKey
|
|
23
|
+
}, `[payload-mcp-toolkit] composeScopes read a pre-0.6 row using \`${legacyKey}\`; resave the API key to migrate to {slug, actions}. The fallback is removed in v0.7.`);
|
|
24
|
+
}
|
|
25
|
+
return legacy;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const VALID_ACTIONS = new Set([
|
|
30
|
+
'read',
|
|
31
|
+
'create',
|
|
32
|
+
'update',
|
|
33
|
+
'delete'
|
|
34
|
+
]);
|
|
35
|
+
const VALID_GLOBAL_ACTIONS = new Set([
|
|
36
|
+
'read',
|
|
37
|
+
'update'
|
|
38
|
+
]);
|
|
39
|
+
/**
|
|
40
|
+
* Builds the runtime `KeyScopes` shape consumed by `registry.assertScopeAllows`
|
|
41
|
+
* from the typed scope fields on the api-key row.
|
|
42
|
+
*
|
|
43
|
+
* Returns null when no typed fields are populated AND no preset is set
|
|
44
|
+
* (= full access — back-compat for pre-0.5 rows that pre-date scoped authz).
|
|
45
|
+
*
|
|
46
|
+
* Two complementary fail-closed rules:
|
|
47
|
+
*
|
|
48
|
+
* 1. **`'custom'` deny-all sentinel.** `'custom'` is a UI sentinel meaning
|
|
49
|
+
* "use my override fields"; it never becomes `KeyScopes.preset` itself.
|
|
50
|
+
* Payload persists unset JSON / select fields as `null`, so a fresh
|
|
51
|
+
* Custom key with no overrides arrives as `{preset:'custom',
|
|
52
|
+
* collectionScopes:null, globalScopes:null, toolAllow:null,
|
|
53
|
+
* toolDeny:null}`. That row must deny everything (not fall through to
|
|
54
|
+
* full access). The sentinel emits `{collections:{}, globals:{},
|
|
55
|
+
* tools:{allow:[]}}`.
|
|
56
|
+
*
|
|
57
|
+
* 2. **Per-axis explicit-empty, Custom-only.** Under the Custom preset, an
|
|
58
|
+
* empty array on any axis (even `[]`) is honoured as written — an empty
|
|
59
|
+
* `toolAllow:[]` means "deny all tools on this axis", not "no opinion".
|
|
60
|
+
* Under non-Custom presets, empty arrays are IGNORED because Payload's
|
|
61
|
+
* hasMany / unpopulated-JSON reads return `[]` for fields the user
|
|
62
|
+
* never touched (the override matrices are hidden in the admin UI under
|
|
63
|
+
* non-Custom presets via `condition: isCustomPreset`). The on-write
|
|
64
|
+
* counterpart of this rule lives in `createApiKeysCollection`'s
|
|
65
|
+
* `beforeValidate` hook, which proactively nulls the override axes on
|
|
66
|
+
* save when the preset is non-Custom — both layers must stay in sync.
|
|
67
|
+
* Non-empty arrays still apply as layered narrowing under any preset.
|
|
68
|
+
* `toolDeny` is a deny-list, so an empty array carries no entries — it
|
|
69
|
+
* is dropped rather than emitted. NOTE: legacy non-Custom rows persisted
|
|
70
|
+
* BEFORE v0.7.1 with populated stale override arrays continue to narrow
|
|
71
|
+
* on read until each row is manually re-saved; the on-write fix only
|
|
72
|
+
* applies to fresh writes.
|
|
73
|
+
*/ export function composeScopes(row, logger) {
|
|
74
|
+
const presetRaw = row.preset;
|
|
75
|
+
const hasPreset = typeof presetRaw === 'string' && presetRaw.length > 0;
|
|
76
|
+
const hasCollectionScopesField = Array.isArray(row.collectionScopes);
|
|
77
|
+
const hasGlobalScopesField = Array.isArray(row.globalScopes);
|
|
78
|
+
const hasToolAllowField = Array.isArray(row.toolAllow);
|
|
79
|
+
const hasToolDenyField = Array.isArray(row.toolDeny);
|
|
80
|
+
// Pre-0.5 back-compat: row has no preset and no typed scope fields at
|
|
81
|
+
// all (all null/undefined). Treat as full access.
|
|
82
|
+
if (!hasPreset && !hasCollectionScopesField && !hasGlobalScopesField && !hasToolAllowField && !hasToolDenyField) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
// Sentinel: Custom preset with every axis null/undefined (no array
|
|
86
|
+
// committed) denies everything. Payload-persisted unset JSON / select
|
|
87
|
+
// fields arrive as null; this is the fresh-Custom-key case.
|
|
88
|
+
if (presetRaw === 'custom' && !hasCollectionScopesField && !hasGlobalScopesField && !hasToolAllowField && !hasToolDenyField) {
|
|
89
|
+
return {
|
|
90
|
+
collections: {},
|
|
91
|
+
globals: {},
|
|
92
|
+
tools: {
|
|
93
|
+
allow: []
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const out = {};
|
|
98
|
+
const isCustomPreset = presetRaw === 'custom';
|
|
99
|
+
if (hasPreset && !isCustomPreset) {
|
|
100
|
+
out.preset = presetRaw;
|
|
101
|
+
}
|
|
102
|
+
// Under non-Custom presets, the override fields are hidden in the admin
|
|
103
|
+
// UI (`condition: isCustomPreset`) and Payload's hasMany / relational
|
|
104
|
+
// reads return `[]` for unpopulated relations even when the user never
|
|
105
|
+
// touched them. Treating that `[]` as "deny-all on this axis" turns
|
|
106
|
+
// every preset key into a deny-all key once it round-trips through the
|
|
107
|
+
// DB. Apply the explicit-empty-means-deny semantic only when the user
|
|
108
|
+
// is on the Custom preset (where the override fields are visible and
|
|
109
|
+
// meaningful); under preset modes, ignore empty arrays so that the
|
|
110
|
+
// preset alone drives access. Non-empty arrays still apply as layered
|
|
111
|
+
// narrowing, matching the field description ("layered on top of preset
|
|
112
|
+
// and collection scopes").
|
|
113
|
+
const treatEmptyAsScope = isCustomPreset;
|
|
114
|
+
// Legacy-row warn: non-Custom preset rows persisted BEFORE v0.7.1 may
|
|
115
|
+
// carry populated override arrays from a prior Custom configuration
|
|
116
|
+
// (the on-write null-out hook landed in v0.7.1). These still apply as
|
|
117
|
+
// layered narrowing on read — fail-closed-safe (narrows, never widens)
|
|
118
|
+
// but may not match operator intent. Warn once per process so legacy
|
|
119
|
+
// rows can be audited and re-saved.
|
|
120
|
+
if (hasPreset && !isCustomPreset && !warnedLegacyNonCustomOverride && (hasCollectionScopesField && row.collectionScopes.length > 0 || hasGlobalScopesField && row.globalScopes.length > 0 || hasToolAllowField && row.toolAllow.length > 0)) {
|
|
121
|
+
warnedLegacyNonCustomOverride = true;
|
|
122
|
+
logger?.warn?.({
|
|
123
|
+
event: 'mcp.auth.legacy_non_custom_override'
|
|
124
|
+
}, `[payload-mcp-toolkit] composeScopes read an API key with a non-Custom preset (${presetRaw}) ` + `carrying populated override arrays. These still narrow access as written, but the ` + `v0.7.1 admin UI clears overrides on preset switch — re-save affected keys to align ` + `persisted state with current admin semantics.`);
|
|
125
|
+
}
|
|
126
|
+
const emitCollectionScopes = hasCollectionScopesField && (treatEmptyAsScope || row.collectionScopes.length > 0);
|
|
127
|
+
if (emitCollectionScopes) {
|
|
128
|
+
const collections = {};
|
|
129
|
+
for (const entry of row.collectionScopes){
|
|
130
|
+
const slug = readScopeSlug(entry, 'collection', logger);
|
|
131
|
+
if (!slug) continue;
|
|
132
|
+
const rawActions = Array.isArray(entry?.actions) ? entry.actions : [];
|
|
133
|
+
const actions = rawActions.filter((a)=>typeof a === 'string' && VALID_ACTIONS.has(a));
|
|
134
|
+
collections[slug] = actions;
|
|
135
|
+
}
|
|
136
|
+
out.collections = collections;
|
|
137
|
+
}
|
|
138
|
+
const emitGlobalScopes = hasGlobalScopesField && (treatEmptyAsScope || row.globalScopes.length > 0);
|
|
139
|
+
if (emitGlobalScopes) {
|
|
140
|
+
const globals = {};
|
|
141
|
+
for (const entry of row.globalScopes){
|
|
142
|
+
const slug = readScopeSlug(entry, 'global', logger);
|
|
143
|
+
if (!slug) continue;
|
|
144
|
+
const rawActions = Array.isArray(entry?.actions) ? entry.actions : [];
|
|
145
|
+
const actions = rawActions.filter((a)=>typeof a === 'string' && VALID_GLOBAL_ACTIONS.has(a));
|
|
146
|
+
globals[slug] = actions;
|
|
147
|
+
}
|
|
148
|
+
out.globals = globals;
|
|
149
|
+
}
|
|
150
|
+
const toolDeny = hasToolDenyField ? row.toolDeny.filter((t)=>typeof t === 'string') : [];
|
|
151
|
+
const emitDeny = toolDeny.length > 0;
|
|
152
|
+
const emitToolAllow = hasToolAllowField && (treatEmptyAsScope || row.toolAllow.length > 0);
|
|
153
|
+
if (emitToolAllow || emitDeny) {
|
|
154
|
+
out.tools = {};
|
|
155
|
+
if (emitToolAllow) {
|
|
156
|
+
const toolAllow = row.toolAllow.filter((t)=>typeof t === 'string');
|
|
157
|
+
out.tools.allow = toolAllow;
|
|
158
|
+
}
|
|
159
|
+
if (emitDeny) out.tools.deny = toolDeny;
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Builds the Payload `auth.strategies` entry that authenticates MCP requests.
|
|
165
|
+
*
|
|
166
|
+
* Authenticates `Authorization: Bearer <plaintext>` by computing the
|
|
167
|
+
* upstream-compatible `apiKeyIndex` HMAC and looking up the row. On match,
|
|
168
|
+
* it fires a non-blocking `lastUsedAt` write and hydrates `req.user` with
|
|
169
|
+
* the linked user record + key context for downstream scope checks.
|
|
170
|
+
*/ export function createBearerStrategy(options) {
|
|
171
|
+
const { collectionSlug, userCollection } = options;
|
|
172
|
+
return {
|
|
173
|
+
name: AUTH_STRATEGY_NAME,
|
|
174
|
+
authenticate: async ({ headers, payload })=>{
|
|
175
|
+
const headersAny = headers;
|
|
176
|
+
const headerValue = typeof headersAny.get === 'function' ? headersAny.get('authorization') : headersAny.authorization;
|
|
177
|
+
const token = extractBearerToken(headerValue ?? null);
|
|
178
|
+
if (!token) return {
|
|
179
|
+
user: null
|
|
180
|
+
};
|
|
181
|
+
const keyHash = hashKey(token, payload.secret);
|
|
182
|
+
const where = {
|
|
183
|
+
apiKeyIndex: {
|
|
184
|
+
equals: keyHash
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
let docs = [];
|
|
188
|
+
try {
|
|
189
|
+
const result = await payload.find({
|
|
190
|
+
collection: collectionSlug,
|
|
191
|
+
where,
|
|
192
|
+
depth: 1,
|
|
193
|
+
limit: 1,
|
|
194
|
+
pagination: false,
|
|
195
|
+
overrideAccess: true
|
|
196
|
+
});
|
|
197
|
+
docs = result.docs ?? [];
|
|
198
|
+
} catch (err) {
|
|
199
|
+
payload.logger.error({
|
|
200
|
+
err,
|
|
201
|
+
event: 'mcp.auth.lookup_failed'
|
|
202
|
+
}, '[payload-mcp-toolkit] API-key lookup failed');
|
|
203
|
+
return {
|
|
204
|
+
user: null
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const row = docs[0];
|
|
208
|
+
if (!row) return {
|
|
209
|
+
user: null
|
|
210
|
+
};
|
|
211
|
+
const now = Date.now();
|
|
212
|
+
if (row.revokedAt) return {
|
|
213
|
+
user: null
|
|
214
|
+
};
|
|
215
|
+
if (row.expiresAt) {
|
|
216
|
+
const expiry = new Date(row.expiresAt).getTime();
|
|
217
|
+
if (Number.isFinite(expiry) && expiry < now) return {
|
|
218
|
+
user: null
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const linkedUser = row.user;
|
|
222
|
+
if (!linkedUser || typeof linkedUser !== 'object') return {
|
|
223
|
+
user: null
|
|
224
|
+
};
|
|
225
|
+
const effectiveScopes = composeScopes(row, payload.logger);
|
|
226
|
+
// Fire-and-forget: do not block the request on this write.
|
|
227
|
+
void payload.update({
|
|
228
|
+
collection: collectionSlug,
|
|
229
|
+
id: row.id,
|
|
230
|
+
data: {
|
|
231
|
+
lastUsedAt: new Date().toISOString()
|
|
232
|
+
},
|
|
233
|
+
overrideAccess: true
|
|
234
|
+
}).catch(()=>{
|
|
235
|
+
// Intentionally swallow: lastUsedAt drift is acceptable.
|
|
236
|
+
});
|
|
237
|
+
const user = linkedUser;
|
|
238
|
+
return {
|
|
239
|
+
user: {
|
|
240
|
+
...user,
|
|
241
|
+
collection: userCollection,
|
|
242
|
+
_strategy: AUTH_STRATEGY_NAME,
|
|
243
|
+
_mcpKey: {
|
|
244
|
+
keyId: row.id,
|
|
245
|
+
keyPrefix: typeof row.keyPrefix === 'string' ? row.keyPrefix : null,
|
|
246
|
+
scopes: effectiveScopes
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Reads the per-request API-key context populated by the bearer strategy.
|
|
255
|
+
* Returns null for non-MCP requests (e.g. cookie-authenticated admin users).
|
|
256
|
+
*/ export function getApiKeyContext(req) {
|
|
257
|
+
const user = req.user;
|
|
258
|
+
return user?._mcpKey ?? null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=auth-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth-strategy.ts"],"sourcesContent":["import type { AuthStrategy, PayloadRequest, Where } from 'payload'\r\nimport { extractBearerToken, hashKey } from './hash'\r\nimport type { CollectionAction, GlobalAction, KeyScopes, ScopePreset } from './types'\r\n\r\nexport type { CollectionAction, GlobalAction, KeyScopes, ScopePreset } from './types'\r\n\r\nexport const AUTH_STRATEGY_NAME = 'mcp-toolkit-bearer'\r\n\r\nexport interface CreateBearerStrategyOptions {\r\n /** Slug of the API-keys collection (defaults to `payload-mcp-api-keys`). */\r\n collectionSlug: string\r\n /** Slug of the user collection that API keys link to. */\r\n userCollection: string\r\n}\r\n\r\n/**\r\n * Stored shape for a row in `collectionScopes` / `globalScopes` (v0.6+).\r\n * The parent field name encodes the axis — collection-vs-global is not\r\n * repeated in the row payload. Legacy `collection` / `global` keys from\r\n * pre-0.6 rows are tolerated by `composeScopes` for one release; v0.7\r\n * drops the fallback (see CHANGELOG).\r\n */\r\ninterface ScopeRow {\r\n slug?: unknown\r\n /** @deprecated pre-0.6 collectionScopes shape — read via fallback only. */\r\n collection?: unknown\r\n /** @deprecated pre-0.6 globalScopes shape — read via fallback only. */\r\n global?: unknown\r\n actions?: unknown\r\n}\r\n\r\ninterface ApiKeyRow {\r\n id: string | number\r\n user: unknown\r\n preset?: ScopePreset | 'custom' | null\r\n collectionScopes?: ScopeRow[] | null\r\n globalScopes?: ScopeRow[] | null\r\n toolAllow?: string[] | null\r\n toolDeny?: string[] | null\r\n expiresAt?: string | Date | null\r\n revokedAt?: string | Date | null\r\n apiKey?: string | null\r\n keyPrefix?: string | null\r\n}\r\n\r\n/**\r\n * Reads the row's slug, tolerating the pre-0.6 `collection` / `global`\r\n * keys for one release. Logs a one-line warn when the legacy fallback\r\n * fires so operators can spot keys that need re-saving. The fallback is\r\n * scheduled for removal in v0.7.\r\n */\r\nlet warnedLegacyShape = false\r\nlet warnedLegacyNonCustomOverride = false\r\n\r\n/** @internal test-only: reset the one-time legacy warns. */\r\nexport function _resetLegacyWarnsForTests(): void {\r\n warnedLegacyShape = false\r\n warnedLegacyNonCustomOverride = false\r\n}\r\n\r\nfunction readScopeSlug(\r\n entry: ScopeRow,\r\n legacyKey: 'collection' | 'global',\r\n logger?: { warn?: (...args: unknown[]) => void } | undefined,\r\n): string | null {\r\n if (typeof entry?.slug === 'string') return entry.slug\r\n const legacy = entry?.[legacyKey]\r\n if (typeof legacy === 'string') {\r\n if (!warnedLegacyShape) {\r\n warnedLegacyShape = true\r\n logger?.warn?.(\r\n { event: 'mcp.auth.legacy_scope_shape', legacyKey },\r\n `[payload-mcp-toolkit] composeScopes read a pre-0.6 row using \\`${legacyKey}\\`; resave the API key to migrate to {slug, actions}. The fallback is removed in v0.7.`,\r\n )\r\n }\r\n return legacy\r\n }\r\n return null\r\n}\r\n\r\nconst VALID_ACTIONS: ReadonlySet<CollectionAction> = new Set(['read', 'create', 'update', 'delete'])\r\nconst VALID_GLOBAL_ACTIONS: ReadonlySet<GlobalAction> = new Set(['read', 'update'])\r\n\r\n/**\r\n * Builds the runtime `KeyScopes` shape consumed by `registry.assertScopeAllows`\r\n * from the typed scope fields on the api-key row.\r\n *\r\n * Returns null when no typed fields are populated AND no preset is set\r\n * (= full access — back-compat for pre-0.5 rows that pre-date scoped authz).\r\n *\r\n * Two complementary fail-closed rules:\r\n *\r\n * 1. **`'custom'` deny-all sentinel.** `'custom'` is a UI sentinel meaning\r\n * \"use my override fields\"; it never becomes `KeyScopes.preset` itself.\r\n * Payload persists unset JSON / select fields as `null`, so a fresh\r\n * Custom key with no overrides arrives as `{preset:'custom',\r\n * collectionScopes:null, globalScopes:null, toolAllow:null,\r\n * toolDeny:null}`. That row must deny everything (not fall through to\r\n * full access). The sentinel emits `{collections:{}, globals:{},\r\n * tools:{allow:[]}}`.\r\n *\r\n * 2. **Per-axis explicit-empty, Custom-only.** Under the Custom preset, an\r\n * empty array on any axis (even `[]`) is honoured as written — an empty\r\n * `toolAllow:[]` means \"deny all tools on this axis\", not \"no opinion\".\r\n * Under non-Custom presets, empty arrays are IGNORED because Payload's\r\n * hasMany / unpopulated-JSON reads return `[]` for fields the user\r\n * never touched (the override matrices are hidden in the admin UI under\r\n * non-Custom presets via `condition: isCustomPreset`). The on-write\r\n * counterpart of this rule lives in `createApiKeysCollection`'s\r\n * `beforeValidate` hook, which proactively nulls the override axes on\r\n * save when the preset is non-Custom — both layers must stay in sync.\r\n * Non-empty arrays still apply as layered narrowing under any preset.\r\n * `toolDeny` is a deny-list, so an empty array carries no entries — it\r\n * is dropped rather than emitted. NOTE: legacy non-Custom rows persisted\r\n * BEFORE v0.7.1 with populated stale override arrays continue to narrow\r\n * on read until each row is manually re-saved; the on-write fix only\r\n * applies to fresh writes.\r\n */\r\nexport function composeScopes(\r\n row: ApiKeyRow,\r\n logger?: { warn?: (...args: unknown[]) => void },\r\n): KeyScopes | null {\r\n const presetRaw = row.preset\r\n const hasPreset = typeof presetRaw === 'string' && presetRaw.length > 0\r\n const hasCollectionScopesField = Array.isArray(row.collectionScopes)\r\n const hasGlobalScopesField = Array.isArray(row.globalScopes)\r\n const hasToolAllowField = Array.isArray(row.toolAllow)\r\n const hasToolDenyField = Array.isArray(row.toolDeny)\r\n\r\n // Pre-0.5 back-compat: row has no preset and no typed scope fields at\r\n // all (all null/undefined). Treat as full access.\r\n if (\r\n !hasPreset &&\r\n !hasCollectionScopesField &&\r\n !hasGlobalScopesField &&\r\n !hasToolAllowField &&\r\n !hasToolDenyField\r\n ) {\r\n return null\r\n }\r\n\r\n // Sentinel: Custom preset with every axis null/undefined (no array\r\n // committed) denies everything. Payload-persisted unset JSON / select\r\n // fields arrive as null; this is the fresh-Custom-key case.\r\n if (\r\n presetRaw === 'custom' &&\r\n !hasCollectionScopesField &&\r\n !hasGlobalScopesField &&\r\n !hasToolAllowField &&\r\n !hasToolDenyField\r\n ) {\r\n return { collections: {}, globals: {}, tools: { allow: [] } }\r\n }\r\n\r\n const out: KeyScopes = {}\r\n const isCustomPreset = presetRaw === 'custom'\r\n if (hasPreset && !isCustomPreset) {\r\n out.preset = presetRaw as ScopePreset\r\n }\r\n\r\n // Under non-Custom presets, the override fields are hidden in the admin\r\n // UI (`condition: isCustomPreset`) and Payload's hasMany / relational\r\n // reads return `[]` for unpopulated relations even when the user never\r\n // touched them. Treating that `[]` as \"deny-all on this axis\" turns\r\n // every preset key into a deny-all key once it round-trips through the\r\n // DB. Apply the explicit-empty-means-deny semantic only when the user\r\n // is on the Custom preset (where the override fields are visible and\r\n // meaningful); under preset modes, ignore empty arrays so that the\r\n // preset alone drives access. Non-empty arrays still apply as layered\r\n // narrowing, matching the field description (\"layered on top of preset\r\n // and collection scopes\").\r\n const treatEmptyAsScope = isCustomPreset\r\n\r\n // Legacy-row warn: non-Custom preset rows persisted BEFORE v0.7.1 may\r\n // carry populated override arrays from a prior Custom configuration\r\n // (the on-write null-out hook landed in v0.7.1). These still apply as\r\n // layered narrowing on read — fail-closed-safe (narrows, never widens)\r\n // but may not match operator intent. Warn once per process so legacy\r\n // rows can be audited and re-saved.\r\n if (\r\n hasPreset &&\r\n !isCustomPreset &&\r\n !warnedLegacyNonCustomOverride &&\r\n ((hasCollectionScopesField && (row.collectionScopes as unknown[]).length > 0) ||\r\n (hasGlobalScopesField && (row.globalScopes as unknown[]).length > 0) ||\r\n (hasToolAllowField && (row.toolAllow as unknown[]).length > 0))\r\n ) {\r\n warnedLegacyNonCustomOverride = true\r\n logger?.warn?.(\r\n { event: 'mcp.auth.legacy_non_custom_override' },\r\n `[payload-mcp-toolkit] composeScopes read an API key with a non-Custom preset (${presetRaw}) ` +\r\n `carrying populated override arrays. These still narrow access as written, but the ` +\r\n `v0.7.1 admin UI clears overrides on preset switch — re-save affected keys to align ` +\r\n `persisted state with current admin semantics.`,\r\n )\r\n }\r\n\r\n const emitCollectionScopes =\r\n hasCollectionScopesField &&\r\n (treatEmptyAsScope || (row.collectionScopes as unknown[]).length > 0)\r\n if (emitCollectionScopes) {\r\n const collections: Record<string, CollectionAction[]> = {}\r\n for (const entry of row.collectionScopes as ScopeRow[]) {\r\n const slug = readScopeSlug(entry, 'collection', logger)\r\n if (!slug) continue\r\n const rawActions = Array.isArray(entry?.actions) ? entry.actions : []\r\n const actions = rawActions.filter(\r\n (a): a is CollectionAction => typeof a === 'string' && VALID_ACTIONS.has(a as CollectionAction),\r\n )\r\n collections[slug] = actions\r\n }\r\n out.collections = collections\r\n }\r\n\r\n const emitGlobalScopes =\r\n hasGlobalScopesField &&\r\n (treatEmptyAsScope || (row.globalScopes as unknown[]).length > 0)\r\n if (emitGlobalScopes) {\r\n const globals: Record<string, GlobalAction[]> = {}\r\n for (const entry of row.globalScopes as ScopeRow[]) {\r\n const slug = readScopeSlug(entry, 'global', logger)\r\n if (!slug) continue\r\n const rawActions = Array.isArray(entry?.actions) ? entry.actions : []\r\n const actions = rawActions.filter(\r\n (a): a is GlobalAction => typeof a === 'string' && VALID_GLOBAL_ACTIONS.has(a as GlobalAction),\r\n )\r\n globals[slug] = actions\r\n }\r\n out.globals = globals\r\n }\r\n\r\n const toolDeny = hasToolDenyField\r\n ? (row.toolDeny as unknown[]).filter((t): t is string => typeof t === 'string')\r\n : []\r\n const emitDeny = toolDeny.length > 0\r\n const emitToolAllow =\r\n hasToolAllowField &&\r\n (treatEmptyAsScope || (row.toolAllow as unknown[]).length > 0)\r\n\r\n if (emitToolAllow || emitDeny) {\r\n out.tools = {}\r\n if (emitToolAllow) {\r\n const toolAllow = (row.toolAllow as unknown[]).filter((t): t is string => typeof t === 'string')\r\n out.tools.allow = toolAllow\r\n }\r\n if (emitDeny) out.tools.deny = toolDeny\r\n }\r\n\r\n return out\r\n}\r\n\r\n/**\r\n * Builds the Payload `auth.strategies` entry that authenticates MCP requests.\r\n *\r\n * Authenticates `Authorization: Bearer <plaintext>` by computing the\r\n * upstream-compatible `apiKeyIndex` HMAC and looking up the row. On match,\r\n * it fires a non-blocking `lastUsedAt` write and hydrates `req.user` with\r\n * the linked user record + key context for downstream scope checks.\r\n */\r\nexport function createBearerStrategy(options: CreateBearerStrategyOptions): AuthStrategy {\r\n const { collectionSlug, userCollection } = options\r\n\r\n return {\r\n name: AUTH_STRATEGY_NAME,\r\n authenticate: async ({ headers, payload }) => {\r\n const headersAny = headers as unknown as\r\n | { get?: (name: string) => string | null }\r\n | Record<string, string | undefined>\r\n const headerValue =\r\n typeof (headersAny as { get?: (name: string) => string | null }).get === 'function'\r\n ? (headersAny as { get: (name: string) => string | null }).get('authorization')\r\n : (headersAny as Record<string, string | undefined>).authorization\r\n const token = extractBearerToken(headerValue ?? null)\r\n if (!token) return { user: null }\r\n\r\n const keyHash = hashKey(token, payload.secret)\r\n const where: Where = { apiKeyIndex: { equals: keyHash } }\r\n\r\n let docs: ApiKeyRow[] = []\r\n try {\r\n const result = (await payload.find({\r\n collection: collectionSlug,\r\n where,\r\n depth: 1,\r\n limit: 1,\r\n pagination: false,\r\n overrideAccess: true,\r\n })) as unknown as { docs: ApiKeyRow[] }\r\n docs = result.docs ?? []\r\n } catch (err) {\r\n payload.logger.error(\r\n { err, event: 'mcp.auth.lookup_failed' },\r\n '[payload-mcp-toolkit] API-key lookup failed',\r\n )\r\n return { user: null }\r\n }\r\n\r\n const row = docs[0]\r\n if (!row) return { user: null }\r\n\r\n const now = Date.now()\r\n if (row.revokedAt) return { user: null }\r\n if (row.expiresAt) {\r\n const expiry = new Date(row.expiresAt).getTime()\r\n if (Number.isFinite(expiry) && expiry < now) return { user: null }\r\n }\r\n\r\n const linkedUser = row.user\r\n if (!linkedUser || typeof linkedUser !== 'object') return { user: null }\r\n\r\n const effectiveScopes: KeyScopes | null = composeScopes(row, payload.logger)\r\n\r\n // Fire-and-forget: do not block the request on this write.\r\n void payload\r\n .update({\r\n collection: collectionSlug,\r\n id: row.id,\r\n data: { lastUsedAt: new Date().toISOString() } as Record<string, unknown>,\r\n overrideAccess: true,\r\n })\r\n .catch(() => {\r\n // Intentionally swallow: lastUsedAt drift is acceptable.\r\n })\r\n\r\n const user = linkedUser as Record<string, unknown>\r\n return {\r\n user: {\r\n ...user,\r\n collection: userCollection,\r\n _strategy: AUTH_STRATEGY_NAME,\r\n _mcpKey: {\r\n keyId: row.id,\r\n keyPrefix: typeof row.keyPrefix === 'string' ? row.keyPrefix : null,\r\n scopes: effectiveScopes,\r\n },\r\n } as unknown as PayloadRequest['user'],\r\n }\r\n },\r\n }\r\n}\r\n\r\n/**\r\n * Reads the per-request API-key context populated by the bearer strategy.\r\n * Returns null for non-MCP requests (e.g. cookie-authenticated admin users).\r\n */\r\nexport function getApiKeyContext(req: PayloadRequest): {\r\n keyId: string | number\r\n keyPrefix: string | null\r\n scopes: KeyScopes | null\r\n} | null {\r\n const user = req.user as\r\n | (Record<string, unknown> & {\r\n _mcpKey?: { keyId: string | number; keyPrefix: string | null; scopes: KeyScopes | null }\r\n })\r\n | null\r\n | undefined\r\n return user?._mcpKey ?? null\r\n}\r\n"],"names":["extractBearerToken","hashKey","AUTH_STRATEGY_NAME","warnedLegacyShape","warnedLegacyNonCustomOverride","_resetLegacyWarnsForTests","readScopeSlug","entry","legacyKey","logger","slug","legacy","warn","event","VALID_ACTIONS","Set","VALID_GLOBAL_ACTIONS","composeScopes","row","presetRaw","preset","hasPreset","length","hasCollectionScopesField","Array","isArray","collectionScopes","hasGlobalScopesField","globalScopes","hasToolAllowField","toolAllow","hasToolDenyField","toolDeny","collections","globals","tools","allow","out","isCustomPreset","treatEmptyAsScope","emitCollectionScopes","rawActions","actions","filter","a","has","emitGlobalScopes","t","emitDeny","emitToolAllow","deny","createBearerStrategy","options","collectionSlug","userCollection","name","authenticate","headers","payload","headersAny","headerValue","get","authorization","token","user","keyHash","secret","where","apiKeyIndex","equals","docs","result","find","collection","depth","limit","pagination","overrideAccess","err","error","now","Date","revokedAt","expiresAt","expiry","getTime","Number","isFinite","linkedUser","effectiveScopes","update","id","data","lastUsedAt","toISOString","catch","_strategy","_mcpKey","keyId","keyPrefix","scopes","getApiKeyContext","req"],"mappings":"AACA,SAASA,kBAAkB,EAAEC,OAAO,QAAQ,SAAQ;AAKpD,OAAO,MAAMC,qBAAqB,qBAAoB;AAuCtD;;;;;CAKC,GACD,IAAIC,oBAAoB;AACxB,IAAIC,gCAAgC;AAEpC,0DAA0D,GAC1D,OAAO,SAASC;IACdF,oBAAoB;IACpBC,gCAAgC;AAClC;AAEA,SAASE,cACPC,KAAe,EACfC,SAAkC,EAClCC,MAA4D;IAE5D,IAAI,OAAOF,OAAOG,SAAS,UAAU,OAAOH,MAAMG,IAAI;IACtD,MAAMC,SAASJ,OAAO,CAACC,UAAU;IACjC,IAAI,OAAOG,WAAW,UAAU;QAC9B,IAAI,CAACR,mBAAmB;YACtBA,oBAAoB;YACpBM,QAAQG,OACN;gBAAEC,OAAO;gBAA+BL;YAAU,GAClD,CAAC,+DAA+D,EAAEA,UAAU,sFAAsF,CAAC;QAEvK;QACA,OAAOG;IACT;IACA,OAAO;AACT;AAEA,MAAMG,gBAA+C,IAAIC,IAAI;IAAC;IAAQ;IAAU;IAAU;CAAS;AACnG,MAAMC,uBAAkD,IAAID,IAAI;IAAC;IAAQ;CAAS;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCC,GACD,OAAO,SAASE,cACdC,GAAc,EACdT,MAAgD;IAEhD,MAAMU,YAAYD,IAAIE,MAAM;IAC5B,MAAM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ACD,OAAO,SAASY,iBAAiBC,GAAmB;IAKlD,MAAMtC,OAAOsC,IAAItC,IAAI;IAMrB,OAAOA,MAAMiC,WAAW;AAC1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface CollectionScopesMatrixProps {
|
|
3
|
+
path: string;
|
|
4
|
+
/** Forwarded via `clientProps` from `api-keys.ts`. */
|
|
5
|
+
availableCollections?: string[];
|
|
6
|
+
}
|
|
7
|
+
declare function CollectionScopesMatrix(props: CollectionScopesMatrixProps): React.ReactElement;
|
|
8
|
+
export default CollectionScopesMatrix;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ScopesTable } from './ScopesTable';
|
|
5
|
+
const ACTIONS = [
|
|
6
|
+
'read',
|
|
7
|
+
'create',
|
|
8
|
+
'update',
|
|
9
|
+
'delete'
|
|
10
|
+
];
|
|
11
|
+
const ACTION_LABELS = {
|
|
12
|
+
read: 'Read',
|
|
13
|
+
create: 'Create',
|
|
14
|
+
update: 'Update',
|
|
15
|
+
delete: 'Delete'
|
|
16
|
+
};
|
|
17
|
+
function CollectionScopesMatrix(props) {
|
|
18
|
+
const items = Array.isArray(props.availableCollections) ? props.availableCollections : [];
|
|
19
|
+
return /*#__PURE__*/ _jsx(ScopesTable, {
|
|
20
|
+
path: props.path,
|
|
21
|
+
items: items,
|
|
22
|
+
actions: ACTIONS,
|
|
23
|
+
actionLabels: ACTION_LABELS,
|
|
24
|
+
itemHeader: "Collection",
|
|
25
|
+
title: "Collection scopes",
|
|
26
|
+
description: 'Check the actions this key may perform on each collection. Unchecked rows are denied outright. Configured under the "Custom" preset; once set, these overrides apply to this key regardless of which preset is later selected.',
|
|
27
|
+
emptyMessage: "No collections are available to scope. Add collections to your Payload config and restart the dev server."
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export default CollectionScopesMatrix;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=CollectionScopesMatrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/CollectionScopesMatrix.tsx"],"sourcesContent":["'use client'\r\n\r\nimport * as React from 'react'\r\nimport { ScopesTable } from './ScopesTable'\r\n\r\nconst ACTIONS = ['read', 'create', 'update', 'delete']\r\nconst ACTION_LABELS: Record<string, string> = {\r\n read: 'Read',\r\n create: 'Create',\r\n update: 'Update',\r\n delete: 'Delete',\r\n}\r\n\r\nexport interface CollectionScopesMatrixProps {\r\n path: string\r\n /** Forwarded via `clientProps` from `api-keys.ts`. */\r\n availableCollections?: string[]\r\n}\r\n\r\nfunction CollectionScopesMatrix(props: CollectionScopesMatrixProps): React.ReactElement {\r\n const items = Array.isArray(props.availableCollections) ? props.availableCollections : []\r\n return (\r\n <ScopesTable\r\n path={props.path}\r\n items={items}\r\n actions={ACTIONS}\r\n actionLabels={ACTION_LABELS}\r\n itemHeader=\"Collection\"\r\n title=\"Collection scopes\"\r\n description='Check the actions this key may perform on each collection. Unchecked rows are denied outright. Configured under the \"Custom\" preset; once set, these overrides apply to this key regardless of which preset is later selected.'\r\n emptyMessage=\"No collections are available to scope. Add collections to your Payload config and restart the dev server.\"\r\n />\r\n )\r\n}\r\n\r\nexport default CollectionScopesMatrix\r\n"],"names":["React","ScopesTable","ACTIONS","ACTION_LABELS","read","create","update","delete","CollectionScopesMatrix","props","items","Array","isArray","availableCollections","path","actions","actionLabels","itemHeader","title","description","emptyMessage"],"mappings":"AAAA;;AAEA,YAAYA,WAAW,QAAO;AAC9B,SAASC,WAAW,QAAQ,gBAAe;AAE3C,MAAMC,UAAU;IAAC;IAAQ;IAAU;IAAU;CAAS;AACtD,MAAMC,gBAAwC;IAC5CC,MAAM;IACNC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;AACV;AAQA,SAASC,uBAAuBC,KAAkC;IAChE,MAAMC,QAAQC,MAAMC,OAAO,CAACH,MAAMI,oBAAoB,IAAIJ,MAAMI,oBAAoB,GAAG,EAAE;IACzF,qBACE,KAACZ;QACCa,MAAML,MAAMK,IAAI;QAChBJ,OAAOA;QACPK,SAASb;QACTc,cAAcb;QACdc,YAAW;QACXC,OAAM;QACNC,aAAY;QACZC,cAAa;;AAGnB;AAEA,eAAeZ,uBAAsB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface GlobalScopesMatrixProps {
|
|
3
|
+
path: string;
|
|
4
|
+
/** Forwarded via `clientProps` from `api-keys.ts`. */
|
|
5
|
+
availableGlobals?: string[];
|
|
6
|
+
}
|
|
7
|
+
declare function GlobalScopesMatrix(props: GlobalScopesMatrixProps): React.ReactElement;
|
|
8
|
+
export default GlobalScopesMatrix;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ScopesTable } from './ScopesTable';
|
|
5
|
+
const ACTIONS = [
|
|
6
|
+
'read',
|
|
7
|
+
'update'
|
|
8
|
+
];
|
|
9
|
+
const ACTION_LABELS = {
|
|
10
|
+
read: 'Read',
|
|
11
|
+
update: 'Update'
|
|
12
|
+
};
|
|
13
|
+
function GlobalScopesMatrix(props) {
|
|
14
|
+
const items = Array.isArray(props.availableGlobals) ? props.availableGlobals : [];
|
|
15
|
+
return /*#__PURE__*/ _jsx(ScopesTable, {
|
|
16
|
+
path: props.path,
|
|
17
|
+
items: items,
|
|
18
|
+
actions: ACTIONS,
|
|
19
|
+
actionLabels: ACTION_LABELS,
|
|
20
|
+
itemHeader: "Global",
|
|
21
|
+
title: "Global scopes",
|
|
22
|
+
description: 'Check the actions this key may perform on each global. Globals only support Read and Update (singletons cannot be created or deleted). Configured under the "Custom" preset; once set, these overrides apply to this key regardless of which preset is later selected.',
|
|
23
|
+
emptyMessage: "No globals are available to scope. Add globals to your Payload config and restart the dev server."
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export default GlobalScopesMatrix;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=GlobalScopesMatrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/GlobalScopesMatrix.tsx"],"sourcesContent":["'use client'\r\n\r\nimport * as React from 'react'\r\nimport { ScopesTable } from './ScopesTable'\r\n\r\nconst ACTIONS = ['read', 'update']\r\nconst ACTION_LABELS: Record<string, string> = {\r\n read: 'Read',\r\n update: 'Update',\r\n}\r\n\r\nexport interface GlobalScopesMatrixProps {\r\n path: string\r\n /** Forwarded via `clientProps` from `api-keys.ts`. */\r\n availableGlobals?: string[]\r\n}\r\n\r\nfunction GlobalScopesMatrix(props: GlobalScopesMatrixProps): React.ReactElement {\r\n const items = Array.isArray(props.availableGlobals) ? props.availableGlobals : []\r\n return (\r\n <ScopesTable\r\n path={props.path}\r\n items={items}\r\n actions={ACTIONS}\r\n actionLabels={ACTION_LABELS}\r\n itemHeader=\"Global\"\r\n title=\"Global scopes\"\r\n description='Check the actions this key may perform on each global. Globals only support Read and Update (singletons cannot be created or deleted). Configured under the \"Custom\" preset; once set, these overrides apply to this key regardless of which preset is later selected.'\r\n emptyMessage=\"No globals are available to scope. Add globals to your Payload config and restart the dev server.\"\r\n />\r\n )\r\n}\r\n\r\nexport default GlobalScopesMatrix\r\n"],"names":["React","ScopesTable","ACTIONS","ACTION_LABELS","read","update","GlobalScopesMatrix","props","items","Array","isArray","availableGlobals","path","actions","actionLabels","itemHeader","title","description","emptyMessage"],"mappings":"AAAA;;AAEA,YAAYA,WAAW,QAAO;AAC9B,SAASC,WAAW,QAAQ,gBAAe;AAE3C,MAAMC,UAAU;IAAC;IAAQ;CAAS;AAClC,MAAMC,gBAAwC;IAC5CC,MAAM;IACNC,QAAQ;AACV;AAQA,SAASC,mBAAmBC,KAA8B;IACxD,MAAMC,QAAQC,MAAMC,OAAO,CAACH,MAAMI,gBAAgB,IAAIJ,MAAMI,gBAAgB,GAAG,EAAE;IACjF,qBACE,KAACV;QACCW,MAAML,MAAMK,IAAI;QAChBJ,OAAOA;QACPK,SAASX;QACTY,cAAcX;QACdY,YAAW;QACXC,OAAM;QACNC,aAAY;QACZC,cAAa;;AAGnB;AAEA,eAAeZ,mBAAkB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface ScopesTableProps {
|
|
3
|
+
path: string;
|
|
4
|
+
/** Slugs to render as rows. */
|
|
5
|
+
items: string[];
|
|
6
|
+
/** Action columns shown to the operator. */
|
|
7
|
+
actions: string[];
|
|
8
|
+
/** Display label per action (e.g. { read: 'Read', update: 'Update' }). */
|
|
9
|
+
actionLabels: Record<string, string>;
|
|
10
|
+
/** Header label for the leftmost column. */
|
|
11
|
+
itemHeader: string;
|
|
12
|
+
/** Page-level title rendered above the table. */
|
|
13
|
+
title: string;
|
|
14
|
+
/** Helper sentence rendered between title and table. */
|
|
15
|
+
description: string;
|
|
16
|
+
/** Copy shown when `items` is empty. */
|
|
17
|
+
emptyMessage: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function ScopesTable(props: ScopesTableProps): React.ReactElement;
|