From 410fa13a74ff2c4e0eeac96c768727cf022d14fb Mon Sep 17 00:00:00 2001 From: Innovative-GauravKochar <117165746+Innovative-GauravKochar@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:52:33 +0530 Subject: [PATCH] Removed getAuthToken from Amazon AMC while creating audience (#2286) Co-authored-by: Gaurav Kochar --- .../amazon-amc/__tests__/index.test.ts | 21 +------------------ .../src/destinations/amazon-amc/index.ts | 17 ++------------- 2 files changed, 3 insertions(+), 35 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 2498008c66..d72322169f 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 @@ -1,5 +1,5 @@ import nock from 'nock' -import { createTestIntegration, InvalidAuthenticationError } from '@segment/actions-core' +import { createTestIntegration } from '@segment/actions-core' import Definition from '../index' import { HTTPError } from '@segment/actions-core/*' import { AUTHORIZATION_URL } from '../utils' @@ -116,15 +116,6 @@ describe('Amazon-Ads (actions)', () => { ) }) - it('should fail if refresh token API gets failed', async () => { - const endpoint = AUTHORIZATION_URL[`${settings.region}`] - nock(`${endpoint}`).post('/auth/o2/token').reply(401) - - await expect(testDestination.createAudience(createAudienceInputTemp)).rejects.toThrowError( - InvalidAuthenticationError - ) - }) - it('should throw an HTTPError when createAudience API response is not ok', async () => { const endpoint = AUTHORIZATION_URL[`${settings.region}`] nock(`${endpoint}`).post('/auth/o2/token').reply(200) @@ -138,9 +129,6 @@ describe('Amazon-Ads (actions)', () => { }) it('creates an audience', async () => { - const endpoint = AUTHORIZATION_URL[`${settings.region}`] - nock(`${endpoint}`).post('/auth/o2/token').reply(200) - nock(`${settings.region}`) .post('/amc/audiences/metadata') .matchHeader('content-type', 'application/vnd.amcaudiences.v1+json') @@ -205,13 +193,6 @@ describe('Amazon-Ads (actions)', () => { await expect(audiencePromise).rejects.toHaveProperty('response.statusText', 'Not Found') await expect(audiencePromise).rejects.toHaveProperty('response.status', 404) }) - it('should fail if refresh token API gets failed ', async () => { - const endpoint = AUTHORIZATION_URL[`${settings.region}`] - nock(`${endpoint}`).post('/auth/o2/token').reply(401) - - const audiencePromise = testDestination.getAudience(getAudienceInput) - await expect(audiencePromise).rejects.toThrow(InvalidAuthenticationError) - }) it('should throw an IntegrationError when the audienceId is not provided', async () => { getAudienceInput.externalId = '' diff --git a/packages/destination-actions/src/destinations/amazon-amc/index.ts b/packages/destination-actions/src/destinations/amazon-amc/index.ts index ff0244a582..43f66f24b5 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/index.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/index.ts @@ -4,7 +4,6 @@ import type { Settings, AudienceSettings } from './generated-types' import { AudiencePayload, extractNumberAndSubstituteWithStringValue, - getAuthSettings, getAuthToken, REGEX_ADVERTISERID, REGEX_AUDIENCEID @@ -198,10 +197,6 @@ const destination: AudienceDestinationDefinition = { }) } - // @ts-ignore - TS doesn't know about the oauth property - const authSettings = getAuthSettings(settings) - const authToken = await getAuthToken(request, createAudienceInput.settings, authSettings) - let payloadString = JSON.stringify(payload) // Regular expression to find a advertiserId numeric string and replace the quoted advertiserId string with an unquoted number // AdvertiserId is very big number string and can not be assigned or converted to number directly as it changes the value due to integer overflow. @@ -211,8 +206,7 @@ const destination: AudienceDestinationDefinition = { method: 'POST', body: payloadString, headers: { - 'Content-Type': 'application/vnd.amcaudiences.v1+json', - authorization: `Bearer ${authToken}` + 'Content-Type': 'application/vnd.amcaudiences.v1+json' } }) @@ -229,18 +223,11 @@ const destination: AudienceDestinationDefinition = { const audience_id = getAudienceInput.externalId const { settings } = getAudienceInput const endpoint = settings.region - if (!audience_id) { throw new IntegrationError('Missing audienceId value', 'MISSING_REQUIRED_FIELD', 400) } - // @ts-ignore - TS doesn't know about the oauth property - const authSettings = getAuthSettings(settings) - const authToken = await getAuthToken(request, settings, authSettings) const response = await request(`${endpoint}/amc/audiences/metadata/${audience_id}`, { - method: 'GET', - headers: { - authorization: `Bearer ${authToken}` - } + method: 'GET' }) const res = await response.text() // Regular expression to find a audienceId number and replace the audienceId with quoted string