From 127c4c2692fd658c42757f2392ca75ff31c34158 Mon Sep 17 00:00:00 2001 From: Innovative-GauravKochar <117165746+Innovative-GauravKochar@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:10:11 +0530 Subject: [PATCH] Worked on fixing the refresh access token issue and made currency dropdown (#2079) Co-authored-by: Gaurav Kochar --- .../amazon-amc/__tests__/index.test.ts | 13 --------- .../amazon-amc/generated-types.ts | 2 +- .../src/destinations/amazon-amc/index.ts | 29 +++++++++++++------ .../amazon-amc/syncAudiencesToDSP/index.ts | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/destination-actions/src/destinations/amazon-amc/__tests__/index.test.ts b/packages/destination-actions/src/destinations/amazon-amc/__tests__/index.test.ts index fee7c08b2b..a18fe5f03c 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/__tests__/index.test.ts @@ -114,19 +114,6 @@ describe('Amazon-Ads (actions)', () => { 'Missing description Value' ) }) - it('should fail if invalid currency is provided in audienceSettings', async () => { - const createAudienceInput = { - settings, - audienceName: 'Test Audience', - audienceSettings: { - ...audienceSettings, - ttl: 12345678, - currency: 'INVALID', - cpmCents: 1234 - } - } - await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError('Invalid Currency Value') - }) it('should throw an HTTPError when the response is not ok', async () => { nock(`${settings.region}`) diff --git a/packages/destination-actions/src/destinations/amazon-amc/generated-types.ts b/packages/destination-actions/src/destinations/amazon-amc/generated-types.ts index 949de28f15..0affe7853f 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/generated-types.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/generated-types.ts @@ -26,7 +26,7 @@ export interface AudienceSettings { */ cpmCents?: number /** - * The price paid. Base units depend on the currency. As an example, USD should be reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided values will be rounded to two digits with toFixed(2).Refer [Aamzon Ads Documentation](https://advertising.amazon.com/API/docs/en-us/amc-advertiser-audience#tag/Audience-Metadata/operation/CreateAudienceMetadataV2) to view supported Currency + * Currency code for the CPM value. */ currency?: string /** diff --git a/packages/destination-actions/src/destinations/amazon-amc/index.ts b/packages/destination-actions/src/destinations/amazon-amc/index.ts index 3c1b1856c0..e82742a261 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/index.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/index.ts @@ -5,7 +5,6 @@ import type { Settings, AudienceSettings } from './generated-types' import { AudiencePayload, AUTHORIZATION_URL, - CURRENCY, extractNumberAndSubstituteWithStringValue, REGEX_ADVERTISERID, REGEX_AUDIENCEID @@ -14,7 +13,7 @@ import { import syncAudiencesToDSP from './syncAudiencesToDSP' const destination: AudienceDestinationDefinition = { - name: 'Amazon AMC (Actions)', + name: 'Amazon Ads DSP and AMC', slug: 'actions-amazon-amc', mode: 'cloud', @@ -59,7 +58,7 @@ const destination: AudienceDestinationDefinition = { refreshAccessToken: async (request, { auth, settings }) => { const endpoint = AUTHORIZATION_URL[`${settings.region}`] try { - const res = await request(endpoint, { + const res = await request(`${endpoint}/auth/o2/token`, { method: 'POST', body: new URLSearchParams({ refresh_token: auth.refreshToken, @@ -95,8 +94,7 @@ const destination: AudienceDestinationDefinition = { return { headers: { authorization: `Bearer ${auth?.accessToken}`, - 'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_ADS_CLIENT_ID || '', - 'Content-Type': 'application/vnd.amcaudiences.v1+json' + 'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_ADS_CLIENT_ID || '' } } }, @@ -129,7 +127,23 @@ const destination: AudienceDestinationDefinition = { currency: { label: 'Currency', type: 'string', - description: `The price paid. Base units depend on the currency. As an example, USD should be reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided values will be rounded to two digits with toFixed(2).Refer [Aamzon Ads Documentation](https://advertising.amazon.com/API/docs/en-us/amc-advertiser-audience#tag/Audience-Metadata/operation/CreateAudienceMetadataV2) to view supported Currency` + description: `Currency code for the CPM value.`, + choices: [ + { value: 'USD', label: 'USD' }, + { value: 'CAD', label: 'CAD' }, + { value: 'JPY', label: 'JPY' }, + { value: 'GBP', label: 'GBP' }, + { value: 'EUR', label: 'EUR' }, + { value: 'SAR', label: 'SAR' }, + { value: 'AUD', label: 'AUD' }, + { value: 'AED', label: 'AED' }, + { value: 'CNY', label: 'CNY' }, + { value: 'MXN', label: 'MXN' }, + { value: 'INR', label: 'INR' }, + { value: 'SEK', label: 'SEK' }, + { value: 'TRY', label: 'TRY' } + ], + default: '' }, ttl: { type: 'number', @@ -202,9 +216,6 @@ const destination: AudienceDestinationDefinition = { } if (cpm_cents && currency) { - if (!CURRENCY.includes(currency)) { - throw new IntegrationError('Invalid Currency Value', 'INVALID_CURRENCY_VALUE', 400) - } const cpmCents = Number(cpm_cents) if (!cpmCents) { throw new IntegrationError('CPM_CENTS:-String can not be converted to Number', 'INVALID_CPMCENTS_VALUE', 400) diff --git a/packages/destination-actions/src/destinations/amazon-amc/syncAudiencesToDSP/index.ts b/packages/destination-actions/src/destinations/amazon-amc/syncAudiencesToDSP/index.ts index 98c0b5dd3b..f5297861b5 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/syncAudiencesToDSP/index.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/syncAudiencesToDSP/index.ts @@ -62,7 +62,7 @@ const action: ActionDefinition = { default: { '@path': '$.properties.postal' } }, state: { - label: 'Postal', + label: 'State', description: 'State Code. Value will be hashed before sending to Amazon.', type: 'string', required: false,