From 8c768a11b8d421f6bc3729fe19349af486644eef Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 11 Mar 2025 12:11:15 +0200 Subject: [PATCH] Added contact properties to Send event action --- .../__snapshots__/snapshot.test.ts.snap | 1 + .../__snapshots__/snapshot.test.ts.snap | 1 + .../loops/sendEvent/__tests__/index.test.ts | 46 +++++++++++++++++-- .../loops/sendEvent/generated-types.ts | 6 +++ .../src/destinations/loops/sendEvent/index.ts | 9 +++- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/destination-actions/src/destinations/loops/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/loops/__tests__/__snapshots__/snapshot.test.ts.snap index b1e96ada5e2..67b180db25d 100644 --- a/packages/destination-actions/src/destinations/loops/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/loops/__tests__/__snapshots__/snapshot.test.ts.snap @@ -29,6 +29,7 @@ Object { "eventProperties": Object { "testType": "aeKHha#$d", }, + "testType": "aeKHha#$d", "userId": "aeKHha#$d", } `; diff --git a/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/__snapshots__/snapshot.test.ts.snap index a887c49c3a2..cfdc54b3f77 100644 --- a/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -7,6 +7,7 @@ Object { "eventProperties": Object { "testType": "gJCx1dPfi6rH2R", }, + "testType": "gJCx1dPfi6rH2R", "userId": "gJCx1dPfi6rH2R", } `; diff --git a/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/index.test.ts b/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/index.test.ts index dde4409b926..724c84c116f 100644 --- a/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/loops/sendEvent/__tests__/index.test.ts @@ -12,9 +12,11 @@ describe('Loops.sendEvent', () => { await testDestination.testAction('sendEvent', { settings: { apiKey: LOOPS_API_KEY } }) - } catch (err) { - expect(err.message).toContain("missing the required field 'userId'.") - expect(err.message).toContain("missing the required field 'eventName'.") + } catch (err: unknown) { + if (err instanceof Error) { + expect(err.message).toContain("missing the required field 'userId'.") + expect(err.message).toContain("missing the required field 'eventName'.") + } } }) @@ -77,4 +79,42 @@ describe('Loops.sendEvent', () => { expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) }) + + it('should work with contact properties', async () => { + const testPayload = { + userId: 'some-id-1', + eventName: 'signup', + eventProperties: { + someField: true, // boolean + someField1: 'hello', // string + someField2: '2024-04-01T10:09:65Z' // date + }, + contactProperties: { + firstName: 'Bob', + anIntegerProperty: 1 + } + } + const testPayloadOut = { + userId: 'some-id-1', + eventName: 'signup', + eventProperties: { + someField: true, + someField1: 'hello', + someField2: '2024-04-01T10:09:65Z' + }, + firstName: 'Bob', + anIntegerProperty: 1 + } + nock('https://app.loops.so/api/v1').post('/events/send', testPayloadOut).reply(200, { + success: true + }) + + const responses = await testDestination.testAction('sendEvent', { + mapping: testPayload, + settings: { apiKey: LOOPS_API_KEY } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + }) }) diff --git a/packages/destination-actions/src/destinations/loops/sendEvent/generated-types.ts b/packages/destination-actions/src/destinations/loops/sendEvent/generated-types.ts index e5c38bde32d..b58e32b450a 100644 --- a/packages/destination-actions/src/destinations/loops/sendEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/loops/sendEvent/generated-types.ts @@ -19,4 +19,10 @@ export interface Payload { eventProperties?: { [k: string]: unknown } + /** + * Contact properties that can will be updated on this contact. + */ + contactProperties?: { + [k: string]: unknown + } } diff --git a/packages/destination-actions/src/destinations/loops/sendEvent/index.ts b/packages/destination-actions/src/destinations/loops/sendEvent/index.ts index 79a564b13d7..4b8d7fbe4ac 100644 --- a/packages/destination-actions/src/destinations/loops/sendEvent/index.ts +++ b/packages/destination-actions/src/destinations/loops/sendEvent/index.ts @@ -39,6 +39,12 @@ const action: ActionDefinition = { '@path': '$.userId' } }, + contactProperties: { + label: 'Contact Properties', + description: "Optional properties that will be updated on the event's contact.", + type: 'object', + required: false + }, eventProperties: { label: 'Event Properties', description: 'Event-specific properties that can be included in emails triggered by this event.', @@ -54,7 +60,8 @@ const action: ActionDefinition = { email: payload.email, eventName: payload.eventName, userId: payload.userId, - eventProperties: payload.eventProperties + eventProperties: payload.eventProperties, + ...(typeof payload.contactProperties === 'object' && payload.contactProperties) } }) }