diff --git a/packages/destination-actions/src/destinations/recombee/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/recombee/__tests__/__snapshots__/snapshot.test.ts.snap index b60794bc72..8e6a447004 100644 --- a/packages/destination-actions/src/destinations/recombee/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/recombee/__tests__/__snapshots__/snapshot.test.ts.snap @@ -23,40 +23,24 @@ Object { exports[`Testing snapshot for actions-recombee destination: addCartAddition action - all fields 1`] = ` Object { - "requests": Array [ - Object { - "method": "POST", - "params": Object { - "additionalData": Object { - "testType": "fSK%!$(3gz2peZ!&@L@D", - }, - "amount": 85450379273175.05, - "cascadeCreate": true, - "itemId": "fSK%!$(3gz2peZ!&@L@D", - "price": 85450379273175.05, - "recommId": "fSK%!$(3gz2peZ!&@L@D", - "timestamp": "fSK%!$(3gz2peZ!&@L@D", - "userId": "fSK%!$(3gz2peZ!&@L@D", - }, - "path": "/cartadditions/", - }, - ], + "additionalData": Object { + "testType": "fSK%!$(3gz2peZ!&@L@D", + }, + "amount": 85450379273175.05, + "cascadeCreate": true, + "itemId": "fSK%!$(3gz2peZ!&@L@D", + "price": 85450379273175.05, + "recommId": "fSK%!$(3gz2peZ!&@L@D", + "timestamp": "fSK%!$(3gz2peZ!&@L@D", + "userId": "fSK%!$(3gz2peZ!&@L@D", } `; exports[`Testing snapshot for actions-recombee destination: addCartAddition action - required fields 1`] = ` Object { - "requests": Array [ - Object { - "method": "POST", - "params": Object { - "cascadeCreate": true, - "itemId": "fSK%!$(3gz2peZ!&@L@D", - "userId": "fSK%!$(3gz2peZ!&@L@D", - }, - "path": "/cartadditions/", - }, - ], + "cascadeCreate": true, + "itemId": "fSK%!$(3gz2peZ!&@L@D", + "userId": "fSK%!$(3gz2peZ!&@L@D", } `; diff --git a/packages/destination-actions/src/destinations/recombee/addBookmark/index.ts b/packages/destination-actions/src/destinations/recombee/addBookmark/index.ts index 573ba06aca..8caac70916 100644 --- a/packages/destination-actions/src/destinations/recombee/addBookmark/index.ts +++ b/packages/destination-actions/src/destinations/recombee/addBookmark/index.ts @@ -7,7 +7,7 @@ import { interactionFields } from '../commonFields' const action: ActionDefinition = { title: 'Add Bookmark', description: 'Adds a bookmark of the given item made by the given user.', - defaultSubscription: 'type = "track" and ( event = "Product Added to Wishlist" or event = "Product Shared" )', + defaultSubscription: 'type = "track" and event = "Product Added to Wishlist"', fields: { userId: { label: 'User ID', diff --git a/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/__snapshots__/snapshot.test.ts.snap index 615d63656c..a312858d95 100644 --- a/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/__snapshots__/snapshot.test.ts.snap @@ -2,39 +2,23 @@ exports[`Testing snapshot for Recombee's addCartAddition destination action: all fields 1`] = ` Object { - "requests": Array [ - Object { - "method": "POST", - "params": Object { - "additionalData": Object { - "testType": "E$o]!yX^hLQ^46#)", - }, - "amount": 34128252129771.52, - "cascadeCreate": true, - "itemId": "E$o]!yX^hLQ^46#)", - "price": 34128252129771.52, - "recommId": "E$o]!yX^hLQ^46#)", - "timestamp": "E$o]!yX^hLQ^46#)", - "userId": "E$o]!yX^hLQ^46#)", - }, - "path": "/cartadditions/", - }, - ], + "additionalData": Object { + "testType": "E$o]!yX^hLQ^46#)", + }, + "amount": 34128252129771.52, + "cascadeCreate": true, + "itemId": "E$o]!yX^hLQ^46#)", + "price": 34128252129771.52, + "recommId": "E$o]!yX^hLQ^46#)", + "timestamp": "E$o]!yX^hLQ^46#)", + "userId": "E$o]!yX^hLQ^46#)", } `; exports[`Testing snapshot for Recombee's addCartAddition destination action: required fields 1`] = ` Object { - "requests": Array [ - Object { - "method": "POST", - "params": Object { - "cascadeCreate": true, - "itemId": "E$o]!yX^hLQ^46#)", - "userId": "E$o]!yX^hLQ^46#)", - }, - "path": "/cartadditions/", - }, - ], + "cascadeCreate": true, + "itemId": "E$o]!yX^hLQ^46#)", + "userId": "E$o]!yX^hLQ^46#)", } `; diff --git a/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/index.test.ts b/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/index.test.ts index a3de609df5..433b67a357 100644 --- a/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/recombee/addCartAddition/__tests__/index.test.ts @@ -16,7 +16,7 @@ const SETTINGS: Settings = { describe('addCartAddition', () => { it('should validate action fields', async () => { nock('https://rapi-eu-west.recombee.com/') - .post(`/${DATABASE_ID}/batch/`) + .post(`/${DATABASE_ID}/cartadditions/`) .query({ hmac_timestamp: /.*/, hmac_sign: /.*/ @@ -38,24 +38,16 @@ describe('addCartAddition', () => { }) expect(await response[0].request.json()).toMatchObject({ - requests: [ - { - method: 'POST', - path: '/cartadditions/', - params: { - userId: 'user-id', - itemId: 'product-id', - timestamp: '2021-09-01T00:00:00.000Z', - cascadeCreate: true - } - } - ] + userId: 'user-id', + itemId: 'product-id', + timestamp: '2021-09-01T00:00:00.000Z', + cascadeCreate: true }) }) it('should validate action fields with recommId and additionalData', async () => { nock('https://rapi-eu-west.recombee.com/') - .post(`/${DATABASE_ID}/batch/`) + .post(`/${DATABASE_ID}/cartadditions/`) .query({ hmac_timestamp: /.*/, hmac_sign: /.*/ @@ -90,108 +82,15 @@ describe('addCartAddition', () => { }) expect(await response[0].request.json()).toMatchObject({ - requests: [ - { - method: 'POST', - path: '/cartadditions/', - params: { - userId: 'user-id', - itemId: 'product-id', - timestamp: '2021-09-01T00:00:00.000Z', - cascadeCreate: true, - recommId, - additionalData: { - region: 'region' - } - } - } - ] - }) - }) - - it('should validate action fields with multiple items', async () => { - nock('https://rapi-eu-west.recombee.com/') - .post(`/${DATABASE_ID}/batch/`) - .query({ - hmac_timestamp: /.*/, - hmac_sign: /.*/ - }) - .reply(200, [ - { code: 200, json: 'ok' }, - { code: 200, json: 'ok' } - ]) - - const event = createTestEvent({ userId: 'user-id', - properties: { - products: [ - { - product_id: 'item-1', - quantity: 1, - price: 100 - }, - { - product_id: 'item-2', - quantity: 2, - price: 200 - } - ] - }, - timestamp: '2021-09-01T00:00:00.000Z' - }) - - const response = await testDestination.testAction('addCartAddition', { - event, - settings: SETTINGS, - useDefaultMappings: true, - mapping: { - items: { - '@arrayPath': [ - '$.properties.products', - { - itemId: { - '@path': '$.product_id' - }, - amount: { - '@path': '$.quantity' - }, - price: { - '@path': '$.price' - } - } - ] - } + itemId: 'product-id', + timestamp: '2021-09-01T00:00:00.000Z', + cascadeCreate: true, + recommId, + additionalData: { + region: 'region' } }) - - expect(await response[0].request.json()).toMatchObject({ - requests: [ - { - method: 'POST', - path: '/cartadditions/', - params: { - userId: 'user-id', - itemId: 'item-1', - timestamp: '2021-09-01T00:00:00.000Z', - cascadeCreate: true, - amount: 1, - price: 100 - } - }, - { - method: 'POST', - path: '/cartadditions/', - params: { - userId: 'user-id', - itemId: 'item-2', - timestamp: '2021-09-01T00:00:00.000Z', - cascadeCreate: true, - amount: 2, - price: 200 - } - } - ] - }) }) it('should throw an error when fields are not mapped', async () => { diff --git a/packages/destination-actions/src/destinations/recombee/addCartAddition/generated-types.ts b/packages/destination-actions/src/destinations/recombee/addCartAddition/generated-types.ts index c41a66e95f..ebbeedbfbe 100644 --- a/packages/destination-actions/src/destinations/recombee/addCartAddition/generated-types.ts +++ b/packages/destination-actions/src/destinations/recombee/addCartAddition/generated-types.ts @@ -6,9 +6,9 @@ export interface Payload { */ userId: string /** - * The items that were added to the cart. + * The item that was added to the cart. */ - items: { + item: { /** * ID of the item. */ @@ -21,7 +21,7 @@ export interface Payload { * The price of the added item. If `amount` is greater than 1, the price of one item should be given. */ price?: number - }[] + } /** * The UTC timestamp of when the cart addition occurred. */ diff --git a/packages/destination-actions/src/destinations/recombee/addCartAddition/index.ts b/packages/destination-actions/src/destinations/recombee/addCartAddition/index.ts index a4df98dbbc..4e8e68f3d9 100644 --- a/packages/destination-actions/src/destinations/recombee/addCartAddition/index.ts +++ b/packages/destination-actions/src/destinations/recombee/addCartAddition/index.ts @@ -22,11 +22,10 @@ const action: ActionDefinition = { } } }, - items: { - label: 'Items', - description: 'The items that were added to the cart.', + item: { + label: 'Item', + description: 'The item that was added to the cart.', type: 'object', - multiple: true, required: true, properties: { itemId: { @@ -51,25 +50,15 @@ const action: ActionDefinition = { } }, default: { - // Product Added is an event with a single product - '@arrayPath': [ - '$.properties', - { - itemId: { - '@if': { - exists: { '@path': '$.product_id' }, - then: { '@path': '$.product_id' }, - else: { '@path': '$.asset_id' } - } - }, - amount: { - '@path': '$.quantity' - }, - price: { - '@path': '$.price' - } + itemId: { + '@if': { + exists: { '@path': '$.properties.product_id' }, + then: { '@path': '$.properties.product_id' }, + else: { '@path': '$.properties.sku' } } - ] + }, + amount: { '@path': '$.properties.quantity' }, + price: { '@path': '$.properties.price' } } }, timestamp: { @@ -83,25 +72,22 @@ const action: ActionDefinition = { }, perform: async (request, data) => { const client = new RecombeeApiClient(data.settings, request) - await client.send(new Batch(payloadToInteractions(data.payload))) + await client.send(payloadToInteraction(data.payload)) }, performBatch: async (request, data) => { const client = new RecombeeApiClient(data.settings, request) - await client.send(new Batch(data.payload.flatMap(payloadToInteractions))) + await client.send(new Batch(data.payload.map(payloadToInteraction))) } } -function payloadToInteractions(payload: Payload): AddCartAddition[] { - return payload.items.map( - (item) => - new AddCartAddition({ - userId: payload.userId, - ...item, - timestamp: payload.timestamp, - recommId: payload.recommId, - additionalData: payload.additionalData - }) - ) +function payloadToInteraction(payload: Payload): AddCartAddition { + return new AddCartAddition({ + userId: payload.userId, + ...payload.item, + timestamp: payload.timestamp, + recommId: payload.recommId, + additionalData: payload.additionalData + }) } export default action diff --git a/packages/destination-actions/src/destinations/recombee/commonFields.ts b/packages/destination-actions/src/destinations/recombee/commonFields.ts index 453cc675ec..5a9606ab8d 100644 --- a/packages/destination-actions/src/destinations/recombee/commonFields.ts +++ b/packages/destination-actions/src/destinations/recombee/commonFields.ts @@ -24,9 +24,9 @@ export function interactionFields(interactionName: string): Record = { 'URI of the Recombee API that should be used. *Keep this field empty unless you are calling the Recombee cluster based in a specific region or you were assigned a custom URI by the Recombee Support team.*', type: 'string', required: false, - format: 'hostname', depends_on: { conditions: [ { @@ -95,6 +94,13 @@ const destination: DestinationDefinition = { }, type: 'automatic' }, + { + name: 'Track - Ecommerce - Product Added', + subscribe: 'type = "track" and event = "Product Added"', + partnerAction: 'addCartAddition', + mapping: defaultValues(addCartAddition.fields), + type: 'automatic' + }, { name: 'Track - Ecommerce - Product Removed', subscribe: 'type = "track" and event = "Product Removed"',