Fix destructive update behavior in n8n cookie operations

Avoid clearing existing values when optional fields are left at their
defaults: only send privacyPolicyUrl/maxAgeSeconds when truthy, filter
empty entries from gcmConsentTypes, and constrain consentExpiryDays to
positive integers on create.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-01 20:11:37 +04:00
parent 1996545125
commit 1650b26fa9
4 changed files with 10 additions and 8 deletions

View File

@@ -82,6 +82,9 @@ export const description: INodeProperties[] = [
operation: ['create'], operation: ['create'],
}, },
}, },
typeOptions: {
minValue: 1,
},
default: 365, default: 365,
description: 'Number of days before consent expires', description: 'Number of days before consent expires',
required: true, required: true,

View File

@@ -159,9 +159,7 @@ export async function execute(
const input: Record<string, unknown> = { cookieBannerId }; const input: Record<string, unknown> = { cookieBannerId };
if (name) input.name = name; if (name) input.name = name;
if (privacyPolicyUrl !== undefined) { if (privacyPolicyUrl) input.privacyPolicyUrl = privacyPolicyUrl;
input.privacyPolicyUrl = privacyPolicyUrl === '' ? null : privacyPolicyUrl;
}
if (cookiePolicyUrl) input.cookiePolicyUrl = cookiePolicyUrl; if (cookiePolicyUrl) input.cookiePolicyUrl = cookiePolicyUrl;
if (consentExpiryDays) input.consentExpiryDays = consentExpiryDays; if (consentExpiryDays) input.consentExpiryDays = consentExpiryDays;
if (consentMode) input.consentMode = consentMode; if (consentMode) input.consentMode = consentMode;

View File

@@ -150,7 +150,10 @@ export async function execute(
if (slug) input.slug = slug; if (slug) input.slug = slug;
if (categoryDescription) input.description = categoryDescription; if (categoryDescription) input.description = categoryDescription;
if (gcmConsentTypes) { if (gcmConsentTypes) {
input.gcmConsentTypes = gcmConsentTypes.split(',').map((s) => s.trim()); input.gcmConsentTypes = gcmConsentTypes
.split(',')
.map((s) => s.trim())
.filter((s) => s.length > 0);
} }
if (posthogConsent) input.posthogConsent = posthogConsent === 'true'; if (posthogConsent) input.posthogConsent = posthogConsent === 'true';

View File

@@ -54,7 +54,7 @@ export const description: INodeProperties[] = [
}, },
}, },
default: 0, default: 0,
description: 'The maximum age of the cookie in seconds (0 to clear)', description: 'The maximum age of the cookie in seconds (leave at 0 to keep unchanged)',
}, },
{ {
displayName: 'Excluded', displayName: 'Excluded',
@@ -133,9 +133,7 @@ export async function execute(
const input: Record<string, unknown> = { cookiePatternId }; const input: Record<string, unknown> = { cookiePatternId };
if (displayName) input.displayName = displayName; if (displayName) input.displayName = displayName;
if (maxAgeSeconds !== undefined) { if (maxAgeSeconds > 0) input.maxAgeSeconds = maxAgeSeconds;
input.maxAgeSeconds = maxAgeSeconds === 0 ? null : maxAgeSeconds;
}
if (excluded) input.excluded = excluded === 'true'; if (excluded) input.excluded = excluded === 'true';
if (patternDescription) input.description = patternDescription; if (patternDescription) input.description = patternDescription;