From 63c662078af7fa832fb443ea5c187b60e9ca36ac Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Mon, 4 Nov 2024 16:00:28 +0530 Subject: [PATCH 1/3] feat: update pinterest_tag single product events with new mapping --- .../pinterest_tag/procWorkflow.yaml | 41 +++++++++++-------- .../data_scenarios/cdk_v2/failure.json | 8 ++++ .../data_scenarios/cdk_v2/success.json | 12 ++++++ .../proc/batch_input_multiplex.json | 12 ++++++ .../proc/multiplex_partial_failure.json | 8 ++++ .../destination/proc/multiplex_success.json | 8 ++++ .../destination/router/failure_test.json | 8 ++++ .../pinterest_tag/processor/data.ts | 7 ++-- .../destinations/pinterest_tag/router/data.ts | 2 +- .../destinations/pinterest_tag/step/data.ts | 7 ++-- 10 files changed, 87 insertions(+), 26 deletions(-) diff --git a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml index 64d391c888..77741c743d 100644 --- a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml +++ b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml @@ -11,6 +11,8 @@ bindings: path: ../../../../v0/util - name: validateEventName path: ../../../../v0/util + - path: lodash + name: toString steps: - name: checkIfProcessed condition: .message.statusCode @@ -67,9 +69,9 @@ steps: "event_id": $.getOneByPaths(., ^.destination.Config.deduplicationKey) ?? .messageId, "app_id": ^.destination.Config.appId, "advertiser_id": ^.destination.Config.advertiserId, - "partner_name": .properties.partnerName, - "device_carrier": .context.network.carrier, - "wifi": .context.network.wifi + "partner_name": .properties.partnerName ? $.toString(.properties.partnerName) : undefined, + "device_carrier": .properties.partnerName ? $.toString(.context.network.carrier) : undefined, + "wifi": .context.network.wifi ? Boolean(.context.network.wifi) : undefined }); $.outputs.apiVersion === {{$.API_VERSION.v5}} ? commonFields = commonFields{~["advertiser_id"]}; $.removeUndefinedValues(commonFields) @@ -107,7 +109,7 @@ steps: "client_user_agent": .context.userAgent, "external_id": {{{{$.getGenericPaths("userId")}}}}, "click_id": .properties.clickId, - "partner_id": .traits.partnerId ?? .context.traits.partnerId + "partner_id": .traits.partnerId ?? .context.traits.partnerId ? $.toString(.traits.partnerId ?? .context.traits.partnerId) : undefined }); !.destination.Config.sendExternalId ? userFields = userFields{~["external_id"]} : null; userFields = $.removeUndefinedAndNullAndEmptyValues(userFields); @@ -125,19 +127,20 @@ steps: steps: - name: customFields template: | + console.log('Stringified contentName',toString) const customFields = .message.().({ "currency": .properties.currency, - "value": .properties.value !== undefined ? String(.properties.value) : - .properties.total !== undefined ? String(.properties.total) : - .properties.revenue !== undefined ? String(.properties.revenue) : undefined, + "value": .properties.value !== undefined ? $.toString(.properties.value) : + .properties.total !== undefined ? $.toString(.properties.total) : + .properties.revenue !== undefined ? $.toString(.properties.revenue) : undefined, "num_items": .properties.numOfItems && Number(.properties.numOfItems), "order_id": .properties.order_id, "search_string": .properties.query, "opt_out_type": .properties.optOutType, - "content_name": .properties.contentName, - "content_category": .properties.contentCategory, - "content_brand": .properties.contentBrand, - "np": .properties.np + "content_name": .properties.contentName ? $.toString(.properties.contentName) : undefined, + "content_category": .properties.contentCategory ? $.toString(.properties.contentCategory) : undefined, + "content_brand": .properties.contentBrand ? $.toString(.properties.contentBrand) : undefined, + "np": .properties.np ? $.toString(.properties.np) : undefined }); $.removeUndefinedValues(customFields) @@ -151,11 +154,11 @@ steps: "content_ids": products.(.product_id ?? .sku ?? .id)[], "contents": .message.properties@prop.products.({ "quantity": Number(.quantity ?? prop.quantity ?? 1), - "item_price": String(.price ?? prop.price), - "item_name": String(.name), - "id": .product_id ?? .sku, - "item_category": .category, - "item_brand": .brand + "item_price": $.toString(.price ?? prop.price), + "item_name": $.toString(.name), + "id": .product_id ?? .sku ? $.toString(.product_id ?? .sku) : undefined, + "item_category": .category ? $.toString(.category) : undefined, + "item_brand": .brand ? $.toString(.brand) : undefined })[] } else: @@ -167,7 +170,11 @@ steps: "content_ids": (props.product_id ?? props.sku ?? props.id)[], "contents": { "quantity": Number(props.quantity) || 1, - "item_price": String(props.price) + "item_price": props.price ? $.toString(props.price), + "item_name": props.name ? $.toString(props.name), + "id": props.product_id ?? props.sku ? $.toString(props.product_id ?? props.sku) : undefined, + "item_category": props.category ? $.toString(props.category) : undefined, + "item_brand": props.brand ? $.toString(props.brand) : undefined }[] }; - name: combineAllEcomFields diff --git a/test/apitests/data_scenarios/cdk_v2/failure.json b/test/apitests/data_scenarios/cdk_v2/failure.json index 1635a3f0db..154d24481d 100644 --- a/test/apitests/data_scenarios/cdk_v2/failure.json +++ b/test/apitests/data_scenarios/cdk_v2/failure.json @@ -556,6 +556,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -679,6 +683,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/apitests/data_scenarios/cdk_v2/success.json b/test/apitests/data_scenarios/cdk_v2/success.json index ced7433a28..88f430dd7c 100644 --- a/test/apitests/data_scenarios/cdk_v2/success.json +++ b/test/apitests/data_scenarios/cdk_v2/success.json @@ -556,6 +556,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -634,6 +638,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -712,6 +720,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/apitests/data_scenarios/destination/proc/batch_input_multiplex.json b/test/apitests/data_scenarios/destination/proc/batch_input_multiplex.json index 3ce7c15091..3deb7d4b8b 100644 --- a/test/apitests/data_scenarios/destination/proc/batch_input_multiplex.json +++ b/test/apitests/data_scenarios/destination/proc/batch_input_multiplex.json @@ -388,6 +388,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -466,6 +470,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -544,6 +552,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/apitests/data_scenarios/destination/proc/multiplex_partial_failure.json b/test/apitests/data_scenarios/destination/proc/multiplex_partial_failure.json index 0e467c26d0..a2652855d5 100644 --- a/test/apitests/data_scenarios/destination/proc/multiplex_partial_failure.json +++ b/test/apitests/data_scenarios/destination/proc/multiplex_partial_failure.json @@ -388,6 +388,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -466,6 +470,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/apitests/data_scenarios/destination/proc/multiplex_success.json b/test/apitests/data_scenarios/destination/proc/multiplex_success.json index 66b6c870a9..ba4d5266f3 100644 --- a/test/apitests/data_scenarios/destination/proc/multiplex_success.json +++ b/test/apitests/data_scenarios/destination/proc/multiplex_success.json @@ -207,6 +207,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -285,6 +289,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/apitests/data_scenarios/destination/router/failure_test.json b/test/apitests/data_scenarios/destination/router/failure_test.json index 9e36da50cb..197456f66a 100644 --- a/test/apitests/data_scenarios/destination/router/failure_test.json +++ b/test/apitests/data_scenarios/destination/router/failure_test.json @@ -754,6 +754,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } @@ -781,6 +785,10 @@ "content_ids": ["123"], "contents": [ { + "id": "123", + "item_brand": "Gamepro", + "item_category": "Games", + "item_name": "Game", "quantity": 11, "item_price": "13.49" } diff --git a/test/integrations/destinations/pinterest_tag/processor/data.ts b/test/integrations/destinations/pinterest_tag/processor/data.ts index b856d247d7..bcb1f8f309 100644 --- a/test/integrations/destinations/pinterest_tag/processor/data.ts +++ b/test/integrations/destinations/pinterest_tag/processor/data.ts @@ -482,7 +482,7 @@ export const data = [ order_id: '50314b8e9bcf000000000000', num_items: 2, content_ids: ['123'], - contents: [{ quantity: 2, item_price: '25' }], + contents: [{ id: '123', quantity: 2, item_price: '25' }], }, }, JSON_ARRAY: {}, @@ -2405,7 +2405,7 @@ export const data = [ order_id: '50314b8e9bcf000000000000', num_items: 0, content_ids: ['1234'], - contents: [{ quantity: 1, item_price: 'undefined' }], + contents: [{ id: '1234', quantity: 1 }], }, }, JSON_ARRAY: {}, @@ -2666,7 +2666,7 @@ export const data = [ advertiser_id: '123456', app_id: '429047995', custom_data: { - contents: [{ item_price: 'undefined', quantity: 1 }], + contents: [{ quantity: 1 }], currency: 'USD', num_items: 0, order_id: '50314b8e9bcf000000000000', @@ -3562,7 +3562,6 @@ export const data = [ contents: [ { quantity: 1, - item_price: 'undefined', }, ], currency: 'USD', diff --git a/test/integrations/destinations/pinterest_tag/router/data.ts b/test/integrations/destinations/pinterest_tag/router/data.ts index c9ab29a45a..4049f7663a 100644 --- a/test/integrations/destinations/pinterest_tag/router/data.ts +++ b/test/integrations/destinations/pinterest_tag/router/data.ts @@ -815,7 +815,7 @@ export const data = [ order_id: '50314b8e9bcf000000000000', num_items: 2, content_ids: ['123'], - contents: [{ quantity: 2, item_price: '25' }], + contents: [{ id: '123', quantity: 2, item_price: '25' }], }, }, { diff --git a/test/integrations/destinations/pinterest_tag/step/data.ts b/test/integrations/destinations/pinterest_tag/step/data.ts index b607e3c9fa..71f12c735c 100644 --- a/test/integrations/destinations/pinterest_tag/step/data.ts +++ b/test/integrations/destinations/pinterest_tag/step/data.ts @@ -468,7 +468,7 @@ export const data = [ order_id: '50314b8e9bcf000000000000', num_items: 2, content_ids: ['123'], - contents: [{ quantity: 2, item_price: '25' }], + contents: [{ id: '123', quantity: 2, item_price: '25' }], }, }, JSON_ARRAY: {}, @@ -2420,7 +2420,7 @@ export const data = [ order_id: '50314b8e9bcf000000000000', num_items: 0, content_ids: ['1234'], - contents: [{ quantity: 1, item_price: 'undefined' }], + contents: [{ id: '1234', quantity: 1 }], }, }, JSON_ARRAY: {}, @@ -2685,7 +2685,7 @@ export const data = [ advertiser_id: '123456', app_id: '429047995', custom_data: { - contents: [{ item_price: 'undefined', quantity: 1 }], + contents: [{ quantity: 1 }], currency: 'USD', num_items: 0, order_id: '50314b8e9bcf000000000000', @@ -3606,7 +3606,6 @@ export const data = [ contents: [ { quantity: 1, - item_price: 'undefined', }, ], }, From f7183cade9736f83da0876786e973f3122371c04 Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Mon, 11 Nov 2024 11:40:08 +0530 Subject: [PATCH 2/3] chore: use toString function from integrations-lib --- src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml | 4 ++-- .../integrations/destinations/pinterest_tag/processor/data.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml index 77741c743d..3703b771c8 100644 --- a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml +++ b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml @@ -11,8 +11,8 @@ bindings: path: ../../../../v0/util - name: validateEventName path: ../../../../v0/util - - path: lodash - name: toString + - path: '@rudderstack/integrations-lib' + steps: - name: checkIfProcessed condition: .message.statusCode diff --git a/test/integrations/destinations/pinterest_tag/processor/data.ts b/test/integrations/destinations/pinterest_tag/processor/data.ts index bcb1f8f309..4982444346 100644 --- a/test/integrations/destinations/pinterest_tag/processor/data.ts +++ b/test/integrations/destinations/pinterest_tag/processor/data.ts @@ -3486,7 +3486,7 @@ export const data = [ timestamp: '2020-08-14T05:30:30.118Z', properties: { tax: 2, - total: 27.5, + total: [27.5, 123], coupon: 'hasbros', revenue: 48, currency: 'USD', @@ -3565,7 +3565,7 @@ export const data = [ }, ], currency: 'USD', - value: '27.5', + value: '[27.5,123]', order_id: '50314b8e9bcf000000000000', }, event_name: 'custom event', From 5c0b692130608853c7974aad21dd55305d717cdc Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Mon, 11 Nov 2024 16:05:47 +0530 Subject: [PATCH 3/3] chore: update integrations-lib library --- package-lock.json | 6 ++- package.json | 2 +- .../pinterest_tag/procWorkflow.yaml | 41 +++++++++---------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e33a864ca..1099b643d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@koa/router": "^12.0.0", "@ndhoule/extend": "^2.0.0", "@pyroscope/nodejs": "^0.2.9", - "@rudderstack/integrations-lib": "^0.2.10", + "@rudderstack/integrations-lib": "^0.2.13", "@rudderstack/json-template-engine": "^0.18.0", "@rudderstack/workflow-engine": "^0.8.13", "@shopify/jest-koa-mocks": "^5.1.1", @@ -6602,7 +6602,9 @@ } }, "node_modules/@rudderstack/integrations-lib": { - "version": "0.2.10", + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/@rudderstack/integrations-lib/-/integrations-lib-0.2.13.tgz", + "integrity": "sha512-MBI+OQpnYAuOzRlbGCnUX6oVfQsYA7daZ8z07WmqQYQtWFOfd2yFbaxKclu+R/a8W7+jBo4gvbW+ScEW6h+Mgg==", "license": "MIT", "dependencies": { "axios": "^1.4.0", diff --git a/package.json b/package.json index 9b0165feb4..91498fc428 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@koa/router": "^12.0.0", "@ndhoule/extend": "^2.0.0", "@pyroscope/nodejs": "^0.2.9", - "@rudderstack/integrations-lib": "^0.2.10", + "@rudderstack/integrations-lib": "^0.2.13", "@rudderstack/json-template-engine": "^0.18.0", "@rudderstack/workflow-engine": "^0.8.13", "@shopify/jest-koa-mocks": "^5.1.1", diff --git a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml index 3703b771c8..aebb7b0667 100644 --- a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml +++ b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml @@ -69,8 +69,8 @@ steps: "event_id": $.getOneByPaths(., ^.destination.Config.deduplicationKey) ?? .messageId, "app_id": ^.destination.Config.appId, "advertiser_id": ^.destination.Config.advertiserId, - "partner_name": .properties.partnerName ? $.toString(.properties.partnerName) : undefined, - "device_carrier": .properties.partnerName ? $.toString(.context.network.carrier) : undefined, + "partner_name": .properties.partnerName ? $.convertToString(.properties.partnerName) : undefined, + "device_carrier": .properties.partnerName ? $.convertToString(.context.network.carrier) : undefined, "wifi": .context.network.wifi ? Boolean(.context.network.wifi) : undefined }); $.outputs.apiVersion === {{$.API_VERSION.v5}} ? commonFields = commonFields{~["advertiser_id"]}; @@ -109,7 +109,7 @@ steps: "client_user_agent": .context.userAgent, "external_id": {{{{$.getGenericPaths("userId")}}}}, "click_id": .properties.clickId, - "partner_id": .traits.partnerId ?? .context.traits.partnerId ? $.toString(.traits.partnerId ?? .context.traits.partnerId) : undefined + "partner_id": .traits.partnerId ?? .context.traits.partnerId ? $.convertToString(.traits.partnerId ?? .context.traits.partnerId) : undefined }); !.destination.Config.sendExternalId ? userFields = userFields{~["external_id"]} : null; userFields = $.removeUndefinedAndNullAndEmptyValues(userFields); @@ -127,20 +127,19 @@ steps: steps: - name: customFields template: | - console.log('Stringified contentName',toString) const customFields = .message.().({ "currency": .properties.currency, - "value": .properties.value !== undefined ? $.toString(.properties.value) : - .properties.total !== undefined ? $.toString(.properties.total) : - .properties.revenue !== undefined ? $.toString(.properties.revenue) : undefined, + "value": .properties.value !== undefined ? $.convertToString(.properties.value) : + .properties.total !== undefined ? $.convertToString(.properties.total) : + .properties.revenue !== undefined ? $.convertToString(.properties.revenue) : undefined, "num_items": .properties.numOfItems && Number(.properties.numOfItems), "order_id": .properties.order_id, "search_string": .properties.query, "opt_out_type": .properties.optOutType, - "content_name": .properties.contentName ? $.toString(.properties.contentName) : undefined, - "content_category": .properties.contentCategory ? $.toString(.properties.contentCategory) : undefined, - "content_brand": .properties.contentBrand ? $.toString(.properties.contentBrand) : undefined, - "np": .properties.np ? $.toString(.properties.np) : undefined + "content_name": .properties.contentName ? $.convertToString(.properties.contentName) : undefined, + "content_category": .properties.contentCategory ? $.convertToString(.properties.contentCategory) : undefined, + "content_brand": .properties.contentBrand ? $.convertToString(.properties.contentBrand) : undefined, + "np": .properties.np ? $.convertToString(.properties.np) : undefined }); $.removeUndefinedValues(customFields) @@ -154,11 +153,11 @@ steps: "content_ids": products.(.product_id ?? .sku ?? .id)[], "contents": .message.properties@prop.products.({ "quantity": Number(.quantity ?? prop.quantity ?? 1), - "item_price": $.toString(.price ?? prop.price), - "item_name": $.toString(.name), - "id": .product_id ?? .sku ? $.toString(.product_id ?? .sku) : undefined, - "item_category": .category ? $.toString(.category) : undefined, - "item_brand": .brand ? $.toString(.brand) : undefined + "item_price": $.convertToString(.price ?? prop.price), + "item_name": $.convertToString(.name), + "id": .product_id ?? .sku ? $.convertToString(.product_id ?? .sku) : undefined, + "item_category": .category ? $.convertToString(.category) : undefined, + "item_brand": .brand ? $.convertToString(.brand) : undefined })[] } else: @@ -170,11 +169,11 @@ steps: "content_ids": (props.product_id ?? props.sku ?? props.id)[], "contents": { "quantity": Number(props.quantity) || 1, - "item_price": props.price ? $.toString(props.price), - "item_name": props.name ? $.toString(props.name), - "id": props.product_id ?? props.sku ? $.toString(props.product_id ?? props.sku) : undefined, - "item_category": props.category ? $.toString(props.category) : undefined, - "item_brand": props.brand ? $.toString(props.brand) : undefined + "item_price": props.price ? $.convertToString(props.price), + "item_name": props.name ? $.convertToString(props.name), + "id": props.product_id ?? props.sku ? $.convertToString(props.product_id ?? props.sku) : undefined, + "item_category": props.category ? $.convertToString(props.category) : undefined, + "item_brand": props.brand ? $.convertToString(props.brand) : undefined }[] }; - name: combineAllEcomFields