Skip to content

Commit

Permalink
Worked on fixing the refresh access token issue and made currency dro…
Browse files Browse the repository at this point in the history
…pdown (#2079)

Co-authored-by: Gaurav Kochar <[email protected]>
  • Loading branch information
Innovative-GauravKochar and Gaurav Kochar authored Jun 6, 2024
1 parent 6dfaf37 commit 127c4c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions packages/destination-actions/src/destinations/amazon-amc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Settings, AudienceSettings } from './generated-types'
import {
AudiencePayload,
AUTHORIZATION_URL,
CURRENCY,
extractNumberAndSubstituteWithStringValue,
REGEX_ADVERTISERID,
REGEX_AUDIENCEID
Expand All @@ -14,7 +13,7 @@ import {
import syncAudiencesToDSP from './syncAudiencesToDSP'

const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
name: 'Amazon AMC (Actions)',
name: 'Amazon Ads DSP and AMC',
slug: 'actions-amazon-amc',
mode: 'cloud',

Expand Down Expand Up @@ -59,7 +58,7 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
refreshAccessToken: async (request, { auth, settings }) => {
const endpoint = AUTHORIZATION_URL[`${settings.region}`]
try {
const res = await request<RefreshTokenResponse>(endpoint, {
const res = await request<RefreshTokenResponse>(`${endpoint}/auth/o2/token`, {
method: 'POST',
body: new URLSearchParams({
refresh_token: auth.refreshToken,
Expand Down Expand Up @@ -95,8 +94,7 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
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 || ''
}
}
},
Expand Down Expand Up @@ -129,7 +127,23 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
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',
Expand Down Expand Up @@ -202,9 +216,6 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const action: ActionDefinition<Settings, Payload> = {
default: { '@path': '$.properties.postal' }
},
state: {
label: 'Postal',
label: 'State',
description: 'State Code. Value will be hashed before sending to Amazon.',
type: 'string',
required: false,
Expand Down

0 comments on commit 127c4c2

Please sign in to comment.