fix(core-shared): satisfy strict typecheck in purge job + audit hook
Some checks failed
CI / typecheck + lint + boundaries + test + build (pull_request) Has been cancelled
CodeQL / Analyze (javascript-typescript) (pull_request) Has been cancelled
Sentry PII guard (R31) / pii-guard (pull_request) Has been cancelled
CI / Playwright e2e (pull_request) Has been cancelled
CI / Storybook smoke tests + visual regression (pull_request) Has been cancelled
Some checks failed
CI / typecheck + lint + boundaries + test + build (pull_request) Has been cancelled
CodeQL / Analyze (javascript-typescript) (pull_request) Has been cancelled
Sentry PII guard (R31) / pii-guard (pull_request) Has been cancelled
CI / Playwright e2e (pull_request) Has been cancelled
CI / Storybook smoke tests + visual regression (pull_request) Has been cancelled
The hoisted applyAction closure loses the collection narrowing (TS18048) and apps with generated CollectionSlug unions reject comparing slugs to 'audit-logs' (TS2367). Re-bind the narrowed collection and widen the slug comparison to string. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,8 +58,10 @@ export function createReqScopedAuditErasureHook(
|
|||||||
return async ({ doc, req }) => {
|
return async ({ doc, req }) => {
|
||||||
if (typeof doc.id !== "string" && typeof doc.id !== "number") return;
|
if (typeof doc.id !== "string" && typeof doc.id !== "number") return;
|
||||||
const payload = req.payload;
|
const payload = req.payload;
|
||||||
|
// `slug as string`: apps with generated CollectionSlug types narrow slug
|
||||||
|
// to their registered union, which need not include "audit-logs".
|
||||||
const hasAuditCollection = payload.config.collections?.some(
|
const hasAuditCollection = payload.config.collections?.some(
|
||||||
(c) => c.slug === "audit-logs",
|
(c) => (c.slug as string) === "audit-logs",
|
||||||
);
|
);
|
||||||
if (!hasAuditCollection) return;
|
if (!hasAuditCollection) return;
|
||||||
const auditLog = new PayloadAuditLog(
|
const auditLog = new PayloadAuditLog(
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ export function buildPurgeHandler(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-bind after the guard: narrowing does not flow into hoisted closures.
|
||||||
|
const targetCollection = collection;
|
||||||
|
|
||||||
const taskSlug = `retention-purge--${collectionSlug}`;
|
const taskSlug = `retention-purge--${collectionSlug}`;
|
||||||
|
|
||||||
async function applyAction(
|
async function applyAction(
|
||||||
@@ -120,7 +123,7 @@ export function buildPurgeHandler(
|
|||||||
|
|
||||||
if (action === "pseudonymize") {
|
if (action === "pseudonymize") {
|
||||||
const piiFields: Record<string, null> = {};
|
const piiFields: Record<string, null> = {};
|
||||||
for (const field of collection.fields) {
|
for (const field of targetCollection.fields) {
|
||||||
const f = field as { name?: string; custom?: { pii?: unknown } };
|
const f = field as { name?: string; custom?: { pii?: unknown } };
|
||||||
if (f.name && f.custom?.pii) {
|
if (f.name && f.custom?.pii) {
|
||||||
piiFields[f.name] = null;
|
piiFields[f.name] = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user