Allow clearing optional fields in n8n cookie updates
The previous fix prevented unintentional clearing of `privacyPolicyUrl` and `maxAgeSeconds` by skipping the field when its value was falsy, but this also removed the user's ability to explicitly clear an existing value. Move both fields into an `Additional Fields` collection so we can distinguish between "not provided" (skip) and "provided empty" (clear), matching the existing pattern in `vendor/update.operation.ts`. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -43,19 +43,6 @@ export const description: INodeProperties[] = [
|
||||
default: '',
|
||||
description: 'The name of the cookie banner',
|
||||
},
|
||||
{
|
||||
displayName: 'Privacy Policy URL',
|
||||
name: 'privacyPolicyUrl',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['cookieBanner'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The URL to the privacy policy',
|
||||
},
|
||||
{
|
||||
displayName: 'Cookie Policy URL',
|
||||
name: 'cookiePolicyUrl',
|
||||
@@ -122,6 +109,28 @@ export const description: INodeProperties[] = [
|
||||
default: '',
|
||||
description: 'The default language for the cookie banner',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['cookieBanner'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Privacy Policy URL',
|
||||
name: 'privacyPolicyUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The URL to the privacy policy. Leave empty to clear the existing value.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
@@ -130,11 +139,13 @@ export async function execute(
|
||||
): Promise<INodeExecutionData> {
|
||||
const cookieBannerId = this.getNodeParameter('cookieBannerId', itemIndex) as string;
|
||||
const name = this.getNodeParameter('name', itemIndex, '') as string;
|
||||
const privacyPolicyUrl = this.getNodeParameter('privacyPolicyUrl', itemIndex, '') as string;
|
||||
const cookiePolicyUrl = this.getNodeParameter('cookiePolicyUrl', itemIndex, '') as string;
|
||||
const consentExpiryDays = this.getNodeParameter('consentExpiryDays', itemIndex, 0) as number;
|
||||
const consentMode = this.getNodeParameter('consentMode', itemIndex, '') as string;
|
||||
const defaultLanguage = this.getNodeParameter('defaultLanguage', itemIndex, '') as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {}) as {
|
||||
privacyPolicyUrl?: string;
|
||||
};
|
||||
|
||||
const query = `
|
||||
mutation UpdateCookieBanner($input: UpdateCookieBannerInput!) {
|
||||
@@ -159,11 +170,13 @@ export async function execute(
|
||||
|
||||
const input: Record<string, unknown> = { cookieBannerId };
|
||||
if (name) input.name = name;
|
||||
if (privacyPolicyUrl) input.privacyPolicyUrl = privacyPolicyUrl;
|
||||
if (cookiePolicyUrl) input.cookiePolicyUrl = cookiePolicyUrl;
|
||||
if (consentExpiryDays) input.consentExpiryDays = consentExpiryDays;
|
||||
if (consentMode) input.consentMode = consentMode;
|
||||
if (defaultLanguage) input.defaultLanguage = defaultLanguage;
|
||||
if (additionalFields.privacyPolicyUrl !== undefined) {
|
||||
input.privacyPolicyUrl = additionalFields.privacyPolicyUrl === '' ? null : additionalFields.privacyPolicyUrl;
|
||||
}
|
||||
|
||||
const responseData = await proboApiRequest.call(this, query, { input });
|
||||
|
||||
|
||||
@@ -43,19 +43,6 @@ export const description: INodeProperties[] = [
|
||||
default: '',
|
||||
description: 'The display name for the cookie pattern',
|
||||
},
|
||||
{
|
||||
displayName: 'Max Age Seconds',
|
||||
name: 'maxAgeSeconds',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['cookiePattern'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
default: 0,
|
||||
description: 'The maximum age of the cookie in seconds (leave at 0 to keep unchanged)',
|
||||
},
|
||||
{
|
||||
displayName: 'Excluded',
|
||||
name: 'excluded',
|
||||
@@ -96,6 +83,31 @@ export const description: INodeProperties[] = [
|
||||
default: '',
|
||||
description: 'The description of the cookie pattern',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['cookiePattern'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Max Age Seconds',
|
||||
name: 'maxAgeSeconds',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
},
|
||||
default: 0,
|
||||
description: 'The maximum age of the cookie in seconds. Set to 0 to clear the existing value.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
@@ -104,9 +116,11 @@ export async function execute(
|
||||
): Promise<INodeExecutionData> {
|
||||
const cookiePatternId = this.getNodeParameter('cookiePatternId', itemIndex) as string;
|
||||
const displayName = this.getNodeParameter('displayName', itemIndex, '') as string;
|
||||
const maxAgeSeconds = this.getNodeParameter('maxAgeSeconds', itemIndex, 0) as number;
|
||||
const excluded = this.getNodeParameter('excluded', itemIndex, '') as string;
|
||||
const patternDescription = this.getNodeParameter('patternDescription', itemIndex, '') as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {}) as {
|
||||
maxAgeSeconds?: number;
|
||||
};
|
||||
|
||||
const query = `
|
||||
mutation UpdateCookiePattern($input: UpdateCookiePatternInput!) {
|
||||
@@ -133,9 +147,11 @@ export async function execute(
|
||||
|
||||
const input: Record<string, unknown> = { cookiePatternId };
|
||||
if (displayName) input.displayName = displayName;
|
||||
if (maxAgeSeconds > 0) input.maxAgeSeconds = maxAgeSeconds;
|
||||
if (excluded) input.excluded = excluded === 'true';
|
||||
if (patternDescription) input.description = patternDescription;
|
||||
if (additionalFields.maxAgeSeconds !== undefined) {
|
||||
input.maxAgeSeconds = additionalFields.maxAgeSeconds === 0 ? null : additionalFields.maxAgeSeconds;
|
||||
}
|
||||
|
||||
const responseData = await proboApiRequest.call(this, query, { input });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user