Skip to content

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

feat(customer-io): add filtering Reporting Webhook trigger (#15658)

Olivier Sambourg6fe5f5fd0f60
diff --git a/bun.lock b/bun.lock
index 55b22787598..4777376d4df 100644
--- a/bun.lock
+++ b/bun.lock
@@ -2372,7 +2372,7 @@
},
"packages/pieces/community/customer-io": {
"name": "@activepieces/piece-customer-io",
- "version": "0.4.1",
+ "version": "0.5.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -2382,6 +2382,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/customgpt": {
diff --git a/packages/pieces/community/customer-io/package.json b/packages/pieces/community/customer-io/package.json
index f8d306f8c45..946a9e87b47 100644
--- a/packages/pieces/community/customer-io/package.json
+++ b/packages/pieces/community/customer-io/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-customer-io",
- "version": "0.4.1",
+ "version": "0.5.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
@@ -11,11 +11,13 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
},
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
}
}
diff --git a/packages/pieces/community/customer-io/src/i18n/translation.json b/packages/pieces/community/customer-io/src/i18n/translation.json
index 290fc0278a6..ad17b12f73f 100644
--- a/packages/pieces/community/customer-io/src/i18n/translation.json
+++ b/packages/pieces/community/customer-io/src/i18n/translation.json
@@ -21,15 +21,19 @@
"Headers": "Headers",
"Query Parameters": "Query Parameters",
"Body Type": "Body Type",
- "Response is Binary ?": "Response is Binary ?",
- "No Error on Failure": "No Error on Failure",
- "Timeout (in seconds)": "Timeout (in seconds)",
+ "Response is Binary": "Response is Binary",
+ "Return Error as Output": "Return Error as Output",
+ "Timeout": "Timeout",
"Follow redirects": "Follow redirects",
"The unique value representing a person. You may identify a person by id, email address, or the cio_id (when updating people), depending on your workspace settings": "The unique value representing a person. You may identify a person by id, email address, or the cio_id (when updating people), depending on your workspace settings",
"The name of the event. This is how you'll reference the event in campaigns or segments": "The name of the event. This is how you'll reference the event in campaigns or segments",
"Event information to be sent to Customer.io": "Event information to be sent to Customer.io",
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
+ "Appended to the URL as ?key=value.": "Appended to the URL as ?key=value.",
"Enable for files like PDFs, images, etc.": "Enable for files like PDFs, images, etc.",
+ "On a failed request, output the error instead of failing the step.": "On a failed request, output the error instead of failing the step.",
+ "Seconds to wait for a response. Empty: up to the flow limit (10 min).": "Seconds to wait for a response. Empty: up to the flow limit (10 min).",
+ "Follow 3xx redirects instead of returning them as the response.": "Follow 3xx redirects instead of returning them as the response.",
"Key Value": "Key Value",
"JSON": "JSON",
"GET": "GET",
@@ -40,5 +44,85 @@
"HEAD": "HEAD",
"None": "None",
"Form Data": "Form Data",
- "Raw": "Raw"
+ "Raw": "Raw",
+ "New Reporting Event": "New Reporting Event",
+ "Fires on a Customer.io reporting-webhook event (delivered, bounced, clicked, …). Subscribe to only the event types you need, and optionally match a single campaign, action, or recipient domain so unrelated events never start a run.": "Fires on a Customer.io reporting-webhook event (delivered, bounced, clicked, …). Subscribe to only the event types you need, and optionally match a single campaign, action, or recipient domain so unrelated events never start a run.",
+ "Event Types": "Event Types",
+ "Campaign ID": "Campaign ID",
+ "Action ID": "Action ID",
+ "Recipient Domain": "Recipient Domain",
+ "Which reporting events Customer.io should send.": "Which reporting events Customer.io should send.",
+ "Optional. Only start a run for events of this campaign.": "Optional. Only start a run for events of this campaign.",
+ "Optional. When set, only events for this action/message start a run.": "Optional. When set, only events for this action/message start a run.",
+ "Optional. Only start a run when the recipient email is at this domain.": "Optional. Only start a run when the recipient email is at this domain.",
+ "Customer — Subscribed": "Customer — Subscribed",
+ "Customer — Unsubscribed": "Customer — Unsubscribed",
+ "Customer — Subscription Preferences Changed": "Customer — Subscription Preferences Changed",
+ "Email — Drafted": "Email — Drafted",
+ "Email — Attempted": "Email — Attempted",
+ "Email — Sent": "Email — Sent",
+ "Email — Delivered": "Email — Delivered",
+ "Email — Opened": "Email — Opened",
+ "Email — Clicked": "Email — Clicked",
+ "Email — Converted": "Email — Converted",
+ "Email — Unsubscribed": "Email — Unsubscribed",
+ "Email — Bounced": "Email — Bounced",
+ "Email — Dropped": "Email — Dropped",
+ "Email — Spammed": "Email — Spammed",
+ "Email — Failed": "Email — Failed",
+ "Email — Undeliverable": "Email — Undeliverable",
+ "Push — Drafted": "Push — Drafted",
+ "Push — Attempted": "Push — Attempted",
+ "Push — Sent": "Push — Sent",
+ "Push — Delivered": "Push — Delivered",
+ "Push — Opened": "Push — Opened",
+ "Push — Clicked": "Push — Clicked",
+ "Push — Converted": "Push — Converted",
+ "Push — Bounced": "Push — Bounced",
+ "Push — Dropped": "Push — Dropped",
+ "Push — Failed": "Push — Failed",
+ "Push — Undeliverable": "Push — Undeliverable",
+ "SMS — Drafted": "SMS — Drafted",
+ "SMS — Attempted": "SMS — Attempted",
+ "SMS — Sent": "SMS — Sent",
+ "SMS — Delivered": "SMS — Delivered",
+ "SMS — Clicked": "SMS — Clicked",
+ "SMS — Converted": "SMS — Converted",
+ "SMS — Bounced": "SMS — Bounced",
+ "SMS — Dropped": "SMS — Dropped",
+ "SMS — Failed": "SMS — Failed",
+ "SMS — Undeliverable": "SMS — Undeliverable",
+ "SMS — Replied": "SMS — Replied",
+ "WhatsApp — Drafted": "WhatsApp — Drafted",
+ "WhatsApp — Attempted": "WhatsApp — Attempted",
+ "WhatsApp — Sent": "WhatsApp — Sent",
+ "WhatsApp — Delivered": "WhatsApp — Delivered",
+ "WhatsApp — Opened": "WhatsApp — Opened",
+ "WhatsApp — Clicked": "WhatsApp — Clicked",
+ "WhatsApp — Converted": "WhatsApp — Converted",
+ "WhatsApp — Bounced": "WhatsApp — Bounced",
+ "WhatsApp — Dropped": "WhatsApp — Dropped",
+ "WhatsApp — Failed": "WhatsApp — Failed",
+ "WhatsApp — Undeliverable": "WhatsApp — Undeliverable",
+ "WhatsApp — Replied": "WhatsApp — Replied",
+ "Slack — Drafted": "Slack — Drafted",
+ "Slack — Attempted": "Slack — Attempted",
+ "Slack — Sent": "Slack — Sent",
+ "Slack — Clicked": "Slack — Clicked",
+ "Slack — Failed": "Slack — Failed",
+ "Slack — Undeliverable": "Slack — Undeliverable",
+ "Webhook — Drafted": "Webhook — Drafted",
+ "Webhook — Attempted": "Webhook — Attempted",
+ "Webhook — Sent": "Webhook — Sent",
+ "Webhook — Clicked": "Webhook — Clicked",
+ "Webhook — Failed": "Webhook — Failed",
+ "Webhook — Undeliverable": "Webhook — Undeliverable",
+ "In-App — Drafted": "In-App — Drafted",
+ "In-App — Attempted": "In-App — Attempted",
+ "In-App — Sent": "In-App — Sent",
+ "In-App — Opened": "In-App — Opened",
+ "In-App — Clicked": "In-App — Clicked",
+ "In-App — Converted": "In-App — Converted",
+ "In-App — Failed": "In-App — Failed",
+ "In-App — Undeliverable": "In-App — Undeliverable"
}
\ No newline at end of file
diff --git a/packages/pieces/community/customer-io/src/index.ts b/packages/pieces/community/customer-io/src/index.ts
index 1bf82e5780d..7d7c8907c5c 100644
--- a/packages/pieces/community/customer-io/src/index.ts
+++ b/packages/pieces/community/customer-io/src/index.ts
@@ -4,6 +4,7 @@ import {
Property,
} from '@activepieces/pieces-framework';
import { createEvent } from './lib/actions/create_event';
+import { newReportingEvent } from './lib/trigger/new-reporting-event';
import { createCustomApiCallAction } from '@activepieces/pieces-common';
import { customerIOCommon } from './lib/common';
import { Buffer } from 'buffer';
@@ -71,5 +72,5 @@ export const customerIo: any = createPiece({
}),
}),
],
- triggers: [],
+ triggers: [newReportingEvent],
});
diff --git a/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.test.ts b/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.test.ts
new file mode 100644
index 00000000000..42e94c25e1e
--- /dev/null
+++ b/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.test.ts
@@ -0,0 +1,133 @@
+/// <reference types="vitest/globals" />
+
+import { newReportingEvent } from './new-reporting-event';
+
+const EVENT = {
+ event_id: '01E4C8AY5K21N2QNRBD9YXJ13Z',
+ object_type: 'email',
+ metric: 'delivered',
+ timestamp: 1585254331,
+ data: {
+ action_id: 489,
+ campaign_id: 20,
+ recipient: '[email protected]',
+ },
+};
+
+const buildContext = ({
+ propsValue,
+ body,
+}: {
+ propsValue: unknown;
+ body: unknown;
+}) =>
+ ({
+ propsValue,
+ payload: {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body,
+ queryParams: {},
+ },
+ } as never);
+
+describe('customer-io new-reporting-event run()', () => {
+ test('returns the event when no filters are set', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'] }, body: EVENT })
+ );
+
+ expect(output).toEqual([EVENT]);
+ });
+
+ test('returns the event when campaign, action and domain all match', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: {
+ events: ['email_delivered'],
+ campaign_id: 20,
+ action_id: 489,
+ recipient_domain: 'odoo.com',
+ }, body: EVENT })
+ );
+
+ expect(output).toEqual([EVENT]);
+ });
+
+ test('drops the event when the campaign does not match', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], campaign_id: 99 }, body: EVENT })
+ );
+
+ expect(output).toEqual([]);
+ });
+
+ test('drops the event when the action does not match', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], action_id: 1 }, body: EVENT })
+ );
+
+ expect(output).toEqual([]);
+ });
+
+ test('drops the event when the recipient domain does not match', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], recipient_domain: 'example.com' }, body: EVENT })
+ );
+
+ expect(output).toEqual([]);
+ });
+
+ test('matches the recipient domain case-insensitively and tolerates a leading @', async () => {
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], recipient_domain: '@ODOO.com' }, body: EVENT })
+ );
+
+ expect(output).toEqual([EVENT]);
+ });
+
+ test('matches on email_address when recipient is absent', async () => {
+ const event = {
+ ...EVENT,
+ data: { action_id: 489, campaign_id: 20, email_address: '[email protected]' },
+ };
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], recipient_domain: 'odoo.com' }, body: event })
+ );
+
+ expect(output).toEqual([event]);
+ });
+
+ test('matches on identifiers.email even when recipient holds a non-email address', async () => {
+ const event = {
+ ...EVENT,
+ object_type: 'sms',
+ data: {
+ action_id: 489,
+ campaign_id: 20,
+ recipient: '+15551234567',
+ identifiers: { email: '[email protected]' },
+ },
+ };
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['sms_delivered'], recipient_domain: 'odoo.com' }, body: event })
+ );
+
+ expect(output).toEqual([event]);
+ });
+
+ test('matches on identifiers.email when recipient and email_address are absent', async () => {
+ const event = {
+ ...EVENT,
+ data: {
+ action_id: 489,
+ campaign_id: 20,
+ identifiers: { email: '[email protected]' },
+ },
+ };
+ const output = await newReportingEvent.run(
+ buildContext({ propsValue: { events: ['email_delivered'], recipient_domain: 'odoo.com' }, body: event })
+ );
+
+ expect(output).toEqual([event]);
+ });
+});
diff --git a/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.ts b/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.ts
new file mode 100644
index 00000000000..24ee67ada9f
--- /dev/null
+++ b/packages/pieces/community/customer-io/src/lib/trigger/new-reporting-event.ts
@@ -0,0 +1,278 @@
+import { HttpError, HttpMethod, httpClient } from '@activepieces/pieces-common';
+import {
+ Property,
+ TriggerStrategy,
+ createTrigger,
+} from '@activepieces/pieces-framework';
+import { customerIOAuth } from '../auth';
+import { customerIOCommon } from '../common';
+
+const WEBHOOK_ID_STORE_KEY = 'customerio_reporting_webhook_id';
+
+const CUSTOMER_IO_EVENTS: { label: string; value: string }[] = [
+ { label: 'Customer — Subscribed', value: 'customer_subscribed' },
+ { label: 'Customer — Unsubscribed', value: 'customer_unsubscribed' },
+ {
+ label: 'Customer — Subscription Preferences Changed',
+ value: 'customer_subscription_preferences_changed',
+ },
+ { label: 'Email — Drafted', value: 'email_drafted' },
+ { label: 'Email — Attempted', value: 'email_attempted' },
+ { label: 'Email — Sent', value: 'email_sent' },
+ { label: 'Email — Delivered', value: 'email_delivered' },
+ { label: 'Email — Opened', value: 'email_opened' },
+ { label: 'Email — Clicked', value: 'email_clicked' },
+ { label: 'Email — Converted', value: 'email_converted' },
+ { label: 'Email — Unsubscribed', value: 'email_unsubscribed' },
+ { label: 'Email — Bounced', value: 'email_bounced' },
+ { label: 'Email — Dropped', value: 'email_dropped' },
+ { label: 'Email — Spammed', value: 'email_spammed' },
+ { label: 'Email — Failed', value: 'email_failed' },
+ { label: 'Email — Undeliverable', value: 'email_undeliverable' },
+ { label: 'Push — Drafted', value: 'push_drafted' },
+ { label: 'Push — Attempted', value: 'push_attempted' },
+ { label: 'Push — Sent', value: 'push_sent' },
+ { label: 'Push — Delivered', value: 'push_delivered' },
+ { label: 'Push — Opened', value: 'push_opened' },
+ { label: 'Push — Clicked', value: 'push_clicked' },
+ { label: 'Push — Converted', value: 'push_converted' },
+ { label: 'Push — Bounced', value: 'push_bounced' },
+ { label: 'Push — Dropped', value: 'push_dropped' },
+ { label: 'Push — Failed', value: 'push_failed' },
+ { label: 'Push — Undeliverable', value: 'push_undeliverable' },
+ { label: 'SMS — Drafted', value: 'sms_drafted' },
+ { label: 'SMS — Attempted', value: 'sms_attempted' },
+ { label: 'SMS — Sent', value: 'sms_sent' },
+ { label: 'SMS — Delivered', value: 'sms_delivered' },
+ { label: 'SMS — Clicked', value: 'sms_clicked' },
+ { label: 'SMS — Converted', value: 'sms_converted' },
+ { label: 'SMS — Bounced', value: 'sms_bounced' },
+ { label: 'SMS — Dropped', value: 'sms_dropped' },
+ { label: 'SMS — Failed', value: 'sms_failed' },
+ { label: 'SMS — Undeliverable', value: 'sms_undeliverable' },
+ { label: 'SMS — Replied', value: 'sms_replied' },
+ { label: 'WhatsApp — Drafted', value: 'whatsapp_drafted' },
+ { label: 'WhatsApp — Attempted', value: 'whatsapp_attempted' },
+ { label: 'WhatsApp — Sent', value: 'whatsapp_sent' },
+ { label: 'WhatsApp — Delivered', value: 'whatsapp_delivered' },
+ { label: 'WhatsApp — Opened', value: 'whatsapp_opened' },
+ { label: 'WhatsApp — Clicked', value: 'whatsapp_clicked' },
+ { label: 'WhatsApp — Converted', value: 'whatsapp_converted' },
+ { label: 'WhatsApp — Bounced', value: 'whatsapp_bounced' },
+ { label: 'WhatsApp — Dropped', value: 'whatsapp_dropped' },
+ { label: 'WhatsApp — Failed', value: 'whatsapp_failed' },
+ { label: 'WhatsApp — Undeliverable', value: 'whatsapp_undeliverable' },
+ { label: 'WhatsApp — Replied', value: 'whatsapp_replied' },
+ { label: 'Slack — Drafted', value: 'slack_drafted' },
+ { label: 'Slack — Attempted', value: 'slack_attempted' },
+ { label: 'Slack — Sent', value: 'slack_sent' },
+ { label: 'Slack — Clicked', value: 'slack_clicked' },
+ { label: 'Slack — Failed', value: 'slack_failed' },
+ { label: 'Slack — Undeliverable', value: 'slack_undeliverable' },
+ { label: 'Webhook — Drafted', value: 'webhook_drafted' },
+ { label: 'Webhook — Attempted', value: 'webhook_attempted' },
+ { label: 'Webhook — Sent', value: 'webhook_sent' },
+ { label: 'Webhook — Clicked', value: 'webhook_clicked' },
+ { label: 'Webhook — Failed', value: 'webhook_failed' },
+ { label: 'Webhook — Undeliverable', value: 'webhook_undeliverable' },
+ { label: 'In-App — Drafted', value: 'in_app_drafted' },
+ { label: 'In-App — Attempted', value: 'in_app_attempted' },
+ { label: 'In-App — Sent', value: 'in_app_sent' },
+ { label: 'In-App — Opened', value: 'in_app_opened' },
+ { label: 'In-App — Clicked', value: 'in_app_clicked' },
+ { label: 'In-App — Converted', value: 'in_app_converted' },
+ { label: 'In-App — Failed', value: 'in_app_failed' },
+ { label: 'In-App — Undeliverable', value: 'in_app_undeliverable' },
+];
+
+export const newReportingEvent = createTrigger({
+ auth: customerIOAuth,
+ name: 'new_reporting_event',
+ classification: 'READ',
+ displayName: 'New Reporting Event',
+ description:
+ 'Fires on a Customer.io reporting-webhook event (delivered, bounced, clicked, …). Subscribe to only the event types you need, and optionally match a single campaign, action, or recipient domain so unrelated events never start a run.',
+ aiMetadata: {
+ description:
+ 'Fires on each Customer.io reporting-webhook event of the subscribed types (e.g. email_delivered, email_bounced, sms_clicked). Requires the event types to subscribe to, and optionally filters by campaign ID, action ID, or recipient email domain so only matching events start a run. Returns the raw Customer.io event envelope (event_id, object_type, metric, timestamp, data).',
+ },
+ type: TriggerStrategy.WEBHOOK,
+ props: {
+ events: Property.StaticMultiSelectDropdown({
+ displayName: 'Event Types',
+ description: 'Which reporting events Customer.io should send.',
+ required: true,
+ options: {
+ options: CUSTOMER_IO_EVENTS,
+ },
+ }),
+ campaign_id: Property.Number({
+ displayName: 'Campaign ID',
+ description: 'Optional. Only start a run for events of this campaign.',
+ required: false,
+ }),
+ action_id: Property.Number({
+ displayName: 'Action ID',
+ description:
+ 'Optional. When set, only events for this action/message start a run.',
+ required: false,
+ }),
+ recipient_domain: Property.ShortText({
+ displayName: 'Recipient Domain',
+ description:
+ 'Optional. Only start a run when the recipient email is at this domain.',
+ placeholder: 'odoo.com',
+ required: false,
+ }),
+ },
+ sampleData: {
+ event_id: '01E4C8AY5K21N2QNRBD9YXJ13Z',
+ object_type: 'email',
+ metric: 'delivered',
+ timestamp: 1585254331,
+ data: {
+ action_id: 489,
+ campaign_id: 20,
+ customer_id: '0200102',
+ identifiers: {
+ id: '0200102',
+ email: '[email protected]',
+ cio_id: 'd9c106000001',
+ },
+ delivery_id: 'RPILAgABcRhIBqSp7kiPekGBIeVh',
+ recipient: '[email protected]',
+ subject: 'Welcome to Alan',
+ },
+ },
+ async onEnable(context) {
+ const { region, api_bearer_token } = context.auth.props;
+ const apiUrl = customerIOCommon[region || 'us'].apiUrl;
+ const segments = context.webhookUrl.split('?')[0].split('/').filter(Boolean);
+ const lastSegment = segments[segments.length - 1];
+ const flowIdentifier =
+ lastSegment === 'test' ? segments[segments.length - 2] : lastSegment;
+ const response = await httpClient.sendRequest<{ id: number }>({
+ method: HttpMethod.POST,
+ url: `${apiUrl}reporting_webhooks`,
+ headers: { Authorization: `Bearer ${api_bearer_token}` },
+ body: {
+ endpoint: context.webhookUrl,
+ events: context.propsValue.events,
+ name: flowIdentifier ? `Activepieces (${flowIdentifier})` : 'Activepieces',
+ disabled: false,
+ },
+ });
+ try {
+ await context.store.put(WEBHOOK_ID_STORE_KEY, response.body.id);
+ } catch (error) {
+ await deleteReportingWebhook({
+ apiUrl,
+ token: api_bearer_token,
+ webhookId: response.body.id,
+ }).catch(() => undefined);
+ throw error;
+ }
+ },
+ async onDisable(context) {
+ const webhookId = await context.store.get<number>(WEBHOOK_ID_STORE_KEY);
+ if (!webhookId) {
+ return;
+ }
+ const { region, api_bearer_token } = context.auth.props;
+ await deleteReportingWebhook({
+ apiUrl: customerIOCommon[region || 'us'].apiUrl,
+ token: api_bearer_token,
+ webhookId,
+ });
+ },
+ async run(context) {
+ const body = context.payload.body;
+ const event: CustomerIoReportingEvent = isReportingEvent(body) ? body : {};
+ const { campaign_id, action_id, recipient_domain } = context.propsValue;
+ const data = event.data ?? {};
+
+ if (
+ campaign_id !== undefined &&
+ campaign_id !== null &&
+ data.campaign_id !== campaign_id
+ ) {
+ return [];
+ }
+ if (
+ action_id !== undefined &&
+ action_id !== null &&
+ data.action_id !== action_id
+ ) {
+ return [];
+ }
+ if (
+ recipient_domain &&
+ ![data.recipient, data.email_address, data.identifiers?.email].some(
+ (candidate) =>
+ recipientMatchesDomain({
+ recipient: candidate,
+ domain: recipient_domain,
+ })
+ )
+ ) {
+ return [];
+ }
+ return [event];
+ },
+});
+
+async function deleteReportingWebhook({
+ apiUrl,
+ token,
+ webhookId,
+}: {
+ apiUrl: string;
+ token: string;
+ webhookId: number;
+}): Promise<void> {
+ try {
+ await httpClient.sendRequest({
+ method: HttpMethod.DELETE,
+ url: `${apiUrl}reporting_webhooks/${webhookId}`,
+ headers: { Authorization: `Bearer ${token}` },
+ });
+ } catch (error) {
+ if (error instanceof HttpError && error.response.status === 404) {
+ return;
+ }
+ throw error;
+ }
+}
+
+function isReportingEvent(body: unknown): body is CustomerIoReportingEvent {
+ return typeof body === 'object' && body !== null;
+}
+
+function recipientMatchesDomain({
+ recipient,
+ domain,
+}: {
+ recipient: string | undefined;
+ domain: string;
+}): boolean {
+ if (!recipient) {
+ return false;
+ }
+ const normalized = domain.replace(/^@/, '').toLowerCase();
+ return recipient.toLowerCase().endsWith(`@${normalized}`);
+}
+
+type CustomerIoReportingEvent = {
+ event_id?: string;
+ object_type?: string;
+ metric?: string;
+ timestamp?: number;
+ data?: {
+ campaign_id?: number;
+ action_id?: number;
+ recipient?: string;
+ email_address?: string;
+ identifiers?: { email?: string };
+ [key: string]: unknown;
+ };
+};
diff --git a/packages/pieces/community/customer-io/vitest.config.ts b/packages/pieces/community/customer-io/vitest.config.ts
new file mode 100644
index 00000000000..1bd3d1e5fe7
--- /dev/null
+++ b/packages/pieces/community/customer-io/vitest.config.ts
@@ -0,0 +1,19 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: 'node',
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ '@activepieces/core-piece-types': path.resolve(repoRoot, 'packages/core/piece-types/src/index.ts'),
+ '@activepieces/core-utils': path.resolve(repoRoot, 'packages/core/utils/src/index.ts'),
+ },
+ },
+})