AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(sendinblue): keep contacts blacklisted and templates active when an agent updates them (#16741)
Kishan Parmaref2c0b552341
diff --git a/bun.lock b/bun.lockindex dfd03ea0edf..bef5dacf7ae 100644--- a/bun.lock+++ b/bun.lock@@ -8282,7 +8282,7 @@},"packages/pieces/community/sendinblue": {"name": "@activepieces/piece-sendinblue",- "version": "0.5.1",+ "version": "0.6.0","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/packages/pieces/community/sendinblue/package.json b/packages/pieces/community/sendinblue/package.jsonindex a5ca5effc1c..d8e2922041a 100644--- a/packages/pieces/community/sendinblue/package.json+++ b/packages/pieces/community/sendinblue/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-sendinblue",- "version": "0.5.1",+ "version": "0.6.0","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","scripts": {diff --git a/packages/pieces/community/sendinblue/src/i18n/translation.json b/packages/pieces/community/sendinblue/src/i18n/translation.jsonindex 1117a21fea2..0eac8ca317a 100644--- a/packages/pieces/community/sendinblue/src/i18n/translation.json+++ b/packages/pieces/community/sendinblue/src/i18n/translation.json@@ -237,8 +237,8 @@"How the identifier above should be interpreted.": "How the identifier above should be interpreted.","Pass the set of attributes and their values. Attribute names must already exist in your Brevo account and be passed in capital letters, for eg: {\"FNAME\":\"Elly\", \"LNAME\":\"Roger\"}. Only the attributes you list are changed; the rest are left as they are.": "Pass the set of attributes and their values. Attribute names must already exist in your Brevo account and be passed in capital letters, for eg: {\"FNAME\":\"Elly\", \"LNAME\":\"Roger\"}. Only the attributes you list are changed; the rest are left as they are.","Sets a new external id for the contact.": "Sets a new external id for the contact.",- "Set this field to blacklist the contact for emails (emailBlacklisted = true). Leave untouched to keep the contact's current setting.": "Set this field to blacklist the contact for emails (emailBlacklisted = true). Leave untouched to keep the contact's current setting.",- "Set this field to blacklist the contact for SMS (smsBlacklisted = true). Leave untouched to keep the contact's current setting.": "Set this field to blacklist the contact for SMS (smsBlacklisted = true). Leave untouched to keep the contact's current setting.",+ "Whether the contact is blacklisted for emails. Leave empty or pick Leave unchanged to keep the contact's current setting.": "Whether the contact is blacklisted for emails. Leave empty or pick Leave unchanged to keep the contact's current setting.",+ "Whether the contact is blacklisted for SMS. Leave empty or pick Leave unchanged to keep the contact's current setting.": "Whether the contact is blacklisted for SMS. Leave empty or pick Leave unchanged to keep the contact's current setting.","Lists to add the contact to.": "Lists to add the contact to.","Lists to remove the contact from.": "Lists to remove the contact from.","Sender email addresses this contact must not receive transactional email from. Leave empty to change nothing.": "Sender email addresses this contact must not receive transactional email from. Leave empty to change nothing.",@@ -285,7 +285,7 @@"Required when creating a new template unless HTML URL is given. Must be at least 10 characters.": "Required when creating a new template unless HTML URL is given. Must be at least 10 characters.","URL Brevo fetches the HTML content from. Mutually exclusive with HTML Content.": "URL Brevo fetches the HTML content from. Mutually exclusive with HTML Content.","Personalization used for the display name in the To field, for example {{contact.FIRSTNAME}}.": "Personalization used for the display name in the To field, for example {{contact.FIRSTNAME}}.",- "Leave untouched to keep the template's current active state.": "Leave untouched to keep the template's current active state.",+ "Whether the template is active. Leave empty or pick Leave unchanged to keep the template's current active state.": "Whether the template is active. Leave empty or pick Leave unchanged to keep the template's current active state.","The id of the template to fetch, for example 12.": "The id of the template to fetch, for example 12.","Filter to active (checked) or inactive (unchecked) templates; leave unset to return both.": "Filter to active (checked) or inactive (unchecked) templates; leave unset to return both.","Maximum number of templates to return. Defaults to 50, max 1000.": "Maximum number of templates to return. Defaults to 50, max 1000.",@@ -355,6 +355,9 @@"Ascending": "Ascending","Descending": "Descending","Phone (SMS)": "Phone (SMS)",+ "Yes": "Yes",+ "No": "No",+ "Leave unchanged": "Leave unchanged","Companies": "Companies","Deals": "Deals","Contacts": "Contacts",@@ -392,6 +395,13 @@"PUT": "PUT","DELETE": "DELETE","HEAD": "HEAD",+ "Contact": "Contact",+ "Subscriptions": "Subscriptions",+ "Opt Out": "Opt Out",+ "Recipients": "Recipients",+ "Message": "Message",+ "Request": "Request",+ "Data to send": "Data to send","Contact Added to List": "Contact Added to List","Contact Updated": "Contact Updated","Contact Deleted": "Contact Deleted",diff --git a/packages/pieces/community/sendinblue/src/lib/actions/create-or-update-email-template.ts b/packages/pieces/community/sendinblue/src/lib/actions/create-or-update-email-template.tsindex 0fbe4153995..3de2905a7b4 100644--- a/packages/pieces/community/sendinblue/src/lib/actions/create-or-update-email-template.ts+++ b/packages/pieces/community/sendinblue/src/lib/actions/create-or-update-email-template.ts@@ -59,10 +59,10 @@ export const createOrUpdateEmailTemplate = createAction({description: 'Personalization used for the display name in the To field, for example {{contact.FIRSTNAME}}.',required: false,}),- is_active: Property.Checkbox({+ is_active: brevoProps.optionalBoolean({displayName: 'Active',- description: "Leave untouched to keep the template's current active state.",- required: false,+ description:+ "Whether the template is active. Leave empty or pick Leave unchanged to keep the template's current active state.",}),tag: Property.ShortText({displayName: 'Tag',@@ -123,7 +123,7 @@ export const createOrUpdateEmailTemplate = createAction({htmlUrl: html_url,replyTo: reply_to_email,toField: to_field,- isActive: is_active,+ isActive: brevoCommon.optionalBooleanValue(is_active),tag,attachmentUrl: attachment_url,};diff --git a/packages/pieces/community/sendinblue/src/lib/actions/update-contact.ts b/packages/pieces/community/sendinblue/src/lib/actions/update-contact.tsindex cffaa8fca88..4d3d9c33fc9 100644--- a/packages/pieces/community/sendinblue/src/lib/actions/update-contact.ts+++ b/packages/pieces/community/sendinblue/src/lib/actions/update-contact.ts@@ -50,15 +50,13 @@ export const updateContact = createAction({description: 'Sets a new external id for the contact.',required: false,}),- email_blacklisted: Property.Checkbox({+ email_blacklisted: brevoProps.optionalBoolean({displayName: 'Email Blacklisted?',- description: `Set this field to blacklist the contact for emails (emailBlacklisted = true). Leave untouched to keep the contact's current setting.`,- required: false,+ description: `Whether the contact is blacklisted for emails. Leave empty or pick Leave unchanged to keep the contact's current setting.`,}),- sms_blacklisted: Property.Checkbox({+ sms_blacklisted: brevoProps.optionalBoolean({displayName: 'SMS Blacklisted?',- description: `Set this field to blacklist the contact for SMS (smsBlacklisted = true). Leave untouched to keep the contact's current setting.`,- required: false,+ description: `Whether the contact is blacklisted for SMS. Leave empty or pick Leave unchanged to keep the contact's current setting.`,}),list_ids: brevoProps.listIds({displayName: 'Add to Lists',@@ -102,8 +100,8 @@ export const updateContact = createAction({const body = {ext_id,attributes: brevoCommon.isEmptyObject(attributes) ? undefined : attributes,- emailBlacklisted: email_blacklisted,- smsBlacklisted: sms_blacklisted,+ emailBlacklisted: brevoCommon.optionalBooleanValue(email_blacklisted),+ smsBlacklisted: brevoCommon.optionalBooleanValue(sms_blacklisted),listIds: listIds.length > 0 ? listIds : undefined,unlinkListIds: unlinkListIds.length > 0 ? unlinkListIds : undefined,smtpBlacklistSender: blockedSenders.length > 0 ? blockedSenders : undefined,diff --git a/packages/pieces/community/sendinblue/src/lib/common/index.ts b/packages/pieces/community/sendinblue/src/lib/common/index.tsindex fae822285d4..d5b3ece2ab4 100644--- a/packages/pieces/community/sendinblue/src/lib/common/index.ts+++ b/packages/pieces/community/sendinblue/src/lib/common/index.ts@@ -53,7 +53,18 @@ function isEmptyObject(value: Record<string, unknown> | undefined): boolean {return isNil(value) || Object.keys(value).length === 0;}-export const brevoCommon = { apiCall, isEmptyObject };+function optionalBooleanValue(value: unknown): boolean | undefined {+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : value;+ if (normalized === true || normalized === 'yes' || normalized === 'true') {+ return true;+ }+ if (normalized === false || normalized === 'no' || normalized === 'false') {+ return false;+ }+ return undefined;+}++export const brevoCommon = { apiCall, isEmptyObject, optionalBooleanValue };export const BREVO_API_URL = 'https://api.brevo.com/v3';diff --git a/packages/pieces/community/sendinblue/src/lib/common/props.ts b/packages/pieces/community/sendinblue/src/lib/common/props.tsindex 71582a08373..9fa4da37f2c 100644--- a/packages/pieces/community/sendinblue/src/lib/common/props.ts+++ b/packages/pieces/community/sendinblue/src/lib/common/props.ts@@ -105,6 +105,20 @@ export const brevoProps = {}},}),+ optionalBoolean: ({ displayName, description }: OptionalBooleanPropParams) =>+ Property.StaticDropdown<string, false>({+ displayName,+ description,+ required: false,+ options: {+ disabled: false,+ options: [+ { label: 'Yes', value: 'yes' },+ { label: 'No', value: 'no' },+ { label: 'Leave unchanged', value: 'unchanged' },+ ],+ },+ }),senderEmail: Property.Dropdown({displayName: 'Sender',description: 'The verified sender the email is sent from.',@@ -208,3 +222,8 @@ export type ListIdsPropParams = {displayName: string;description: string;};++export type OptionalBooleanPropParams = {+ displayName: string;+ description: string;+};diff --git a/packages/pieces/community/sendinblue/test/agent-optional-booleans.test.ts b/packages/pieces/community/sendinblue/test/agent-optional-booleans.test.tsnew file mode 100644index 00000000000..4e21a094cd7--- /dev/null+++ b/packages/pieces/community/sendinblue/test/agent-optional-booleans.test.ts@@ -0,0 +1,165 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { HttpRequest, httpClient } from '@activepieces/pieces-common';+import {+ Action,+ AppConnectionType,+ AppConnectionValueForAuthProperty,+ createMockActionContext,+ InputPropertyMap,+ PropertyType,+ StaticPropsValue,+} from '@activepieces/pieces-framework';+import { sendinblueAuth } from '../src/lib/auth';+import { brevoCommon } from '../src/lib/common';+import { createOrUpdateEmailTemplate } from '../src/lib/actions/create-or-update-email-template';+import { updateContact } from '../src/lib/actions/update-contact';++const AUTH: AppConnectionValueForAuthProperty<typeof sendinblueAuth> = {+ type: AppConnectionType.SECRET_TEXT,+ secret_text: 'test-key',+};++let requests: HttpRequest[] = [];++beforeEach(() => {+ requests = [];+ vi.spyOn(httpClient, 'sendRequest').mockImplementation(async (request) => {+ requests.push(request);+ return { status: 200, headers: {}, body: {} };+ });+});++afterEach(() => {+ vi.restoreAllMocks();+});++describe('brevoCommon.optionalBooleanValue', () => {+ it.each([true, 'yes', ' Yes ', 'TRUE', 'true'])('reads %j as true', (value) => {+ expect(brevoCommon.optionalBooleanValue(value)).toBe(true);+ });++ it.each([false, 'no', 'NO', ' False '])('reads %j as false', (value) => {+ expect(brevoCommon.optionalBooleanValue(value)).toBe(false);+ });++ it.each([undefined, null, '', 'unchanged', 'maybe', 1])('reads %j as leave unchanged', (value) => {+ expect(brevoCommon.optionalBooleanValue(value)).toBeUndefined();+ });+});++describe('agent-facing boolean props', () => {+ it.each([+ [updateContact.props.email_blacklisted],+ [updateContact.props.sms_blacklisted],+ [createOrUpdateEmailTemplate.props.is_active],+ ])('%# is an optional Yes / No / Leave unchanged dropdown', (prop) => {+ expect(prop.type).toBe(PropertyType.STATIC_DROPDOWN);+ expect(prop.required).toBe(false);+ expect(prop.options.options.map((option) => option.value)).toEqual(['yes', 'no', 'unchanged']);+ });+});++describe('Update Contact', () => {+ const base = {+ identifier: '[email protected]',+ identifier_type: 'email_id',+ attributes: { FIRSTNAME: 'Renamed' },+ ext_id: undefined,+ list_ids: undefined,+ unlink_list_ids: undefined,+ blocked_sender_addresses: undefined,+ };++ it.each([undefined, 'unchanged', 'maybe'])(+ 'leaves both blacklist flags out of the request for %j',+ async (flag) => {+ await run({+ action: updateContact,+ propsValue: { ...base, email_blacklisted: flag, sms_blacklisted: flag },+ });+ expect(requests).toHaveLength(1);+ expect(requests[0].body).toEqual({ attributes: { FIRSTNAME: 'Renamed' } });+ },+ );++ it('sends only the flags that are set', async () => {+ await run({+ action: updateContact,+ propsValue: { ...base, email_blacklisted: 'no', sms_blacklisted: 'unchanged' },+ });+ expect(requests[0].body).toEqual({+ attributes: { FIRSTNAME: 'Renamed' },+ emailBlacklisted: false,+ });+ });++ it.each([+ ['yes', true],+ ['no', false],+ ])('sends both flags for %j', async (flag, expected) => {+ await run({+ action: updateContact,+ propsValue: { ...base, email_blacklisted: flag, sms_blacklisted: flag },+ });+ expect(requests[0].body).toEqual({+ attributes: { FIRSTNAME: 'Renamed' },+ emailBlacklisted: expected,+ smsBlacklisted: expected,+ });+ });+});++describe('Create or Update Email Template', () => {+ const update = {+ template_id: 7,+ template_name: undefined,+ subject: 'Edited',+ sender_email: undefined,+ sender_name: undefined,+ html_content: undefined,+ html_url: undefined,+ reply_to_email: undefined,+ to_field: undefined,+ tag: undefined,+ attachment_url: undefined,+ };++ it.each([undefined, 'unchanged'])('leaves isActive out of an update for %j', async (is_active) => {+ await run({ action: createOrUpdateEmailTemplate, propsValue: { ...update, is_active } });+ expect(requests[0].url).toBe('https://api.brevo.com/v3/smtp/templates/7');+ expect(requests[0].body).toEqual({ subject: 'Edited' });+ });++ it.each([+ ['yes', true],+ ['no', false],+ ])('sends isActive for %j', async (is_active, expected) => {+ await run({ action: createOrUpdateEmailTemplate, propsValue: { ...update, is_active } });+ expect(requests[0].body).toEqual({ subject: 'Edited', isActive: expected });+ });++ it('leaves isActive out of a create when it is not set', async () => {+ await run({+ action: createOrUpdateEmailTemplate,+ propsValue: {+ ...update,+ template_id: undefined,+ template_name: 'New',+ sender_email: '[email protected]',+ html_content: '<p>Hello there</p>',+ is_active: undefined,+ },+ });+ expect(requests[0].body).not.toHaveProperty('isActive');+ });+});++function run<Props extends InputPropertyMap>({+ action,+ propsValue,+}: {+ action: Action<typeof sendinblueAuth, Props>;+ propsValue: StaticPropsValue<Props>;+}): Promise<unknown> {+ return action.run({ ...createMockActionContext<Props>({ propsValue }), auth: AUTH });+}