diff --git a/packages/core/src/destination-kit/index.ts b/packages/core/src/destination-kit/index.ts index 818efd8402..f794968524 100644 --- a/packages/core/src/destination-kit/index.ts +++ b/packages/core/src/destination-kit/index.ts @@ -34,7 +34,6 @@ import { AuthTokens, getAuthData, getOAuth2Data, updateOAuthSettings } from './p import { InputData, Features } from '../mapping-kit' import { retry } from '../retry' import { HTTPError } from '..' -import isEmpty from 'lodash/isEmpty' export type { BaseActionDefinition, @@ -95,15 +94,12 @@ export type AudienceResult = { } export type AudienceMode = { type: 'realtime' } | { type: 'synced'; full_audience_sync: boolean } -export type Personas = { computation_id: 'string'; computation_key: 'string' } export type CreateAudienceInput = { settings: Settings audienceSettings?: AudienceSettings - personas?: Personas - audienceName: string statsContext?: StatsContext @@ -430,10 +426,6 @@ export class Destination { if (!instanceOfAudienceDestinationSettingsWithCreateGet(audienceDefinition.audienceConfig)) { throw new Error('Unexpected call to createAudience') } - //validate audienceField Input - if (!isEmpty(createAudienceInput.audienceSettings)) { - validateSchema(createAudienceInput.audienceSettings, fieldsToJsonSchema(audienceDefinition.audienceFields)) - } const destinationSettings = this.getDestinationSettings(createAudienceInput.settings as unknown as JSONObject) const auth = getAuthData(createAudienceInput.settings as unknown as JSONObject) const context: ExecuteInput = { @@ -444,6 +436,7 @@ export class Destination { } const options = this.extendRequest?.(context) ?? {} const requestClient = createRequestClient({ ...options, statsContext: context.statsContext }) + return audienceDefinition.audienceConfig?.createAudience(requestClient, createAudienceInput) } 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 dd112557bc..2498008c66 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 @@ -136,22 +136,6 @@ describe('Amazon-Ads (actions)', () => { await expect(testDestination.createAudience(createAudienceInputTemp)).rejects.toThrowError('Bad Request') }) - it('Should throw an error when invalid cpmCent is provided', async () => { - const createAudienceInput = { - settings, - audienceName: 'Test Audience', - audienceSettings: { - ...audienceSettings, - ttl: '12345678', - currency: 'USD', - cpmCents: 'invalid cpm cents' - } - } - - await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError( - 'CPM Cents must be a number but it was a string.' - ) - }) it('creates an audience', async () => { const endpoint = AUTHORIZATION_URL[`${settings.region}`] @@ -167,9 +151,9 @@ describe('Amazon-Ads (actions)', () => { audienceName: 'Test Audience', audienceSettings: { ...audienceSettings, - ttl: '12345678', + ttl: 12345678, currency: 'USD', - cpmCents: '1234' + cpmCents: 1234 } } diff --git a/packages/destination-actions/src/destinations/amazon-amc/index.ts b/packages/destination-actions/src/destinations/amazon-amc/index.ts index c73b567e4a..ff0244a582 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/index.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/index.ts @@ -179,14 +179,22 @@ const destination: AudienceDestinationDefinition = { } if (ttl) { - payload.metadata.ttl = ttl + const timeToLive = Number(ttl) + if (!timeToLive) { + throw new IntegrationError('TTL:-String can not be converted to Number', 'INVALID_TTL_VALUE', 400) + } + payload.metadata.ttl = timeToLive } if (cpm_cents && currency) { + const cpmCents = Number(cpm_cents) + if (!cpmCents) { + throw new IntegrationError('CPM_CENTS:-String can not be converted to Number', 'INVALID_CPMCENTS_VALUE', 400) + } payload.metadata.audienceFees = [] payload.metadata?.audienceFees.push({ currency, - cpmCents: cpm_cents + cpmCents: cpmCents }) } diff --git a/packages/destination-actions/src/destinations/facebook-custom-audiences/__tests__/index.test.ts b/packages/destination-actions/src/destinations/facebook-custom-audiences/__tests__/index.test.ts index 36bbfc8ab4..12beacd957 100644 --- a/packages/destination-actions/src/destinations/facebook-custom-audiences/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/facebook-custom-audiences/__tests__/index.test.ts @@ -2,7 +2,7 @@ import nock from 'nock' import { createTestIntegration, IntegrationError } from '@segment/actions-core' import Destination, { FACEBOOK_API_VERSION } from '../index' -const adAccountId = '1500000000000000' +const adAccountId = 1500000000000000 const audienceId = '1506489116128966' const testDestination = createTestIntegration(Destination) const getAudienceUrl = `https://graph.facebook.com/${FACEBOOK_API_VERSION}/` @@ -29,7 +29,7 @@ describe('Facebook Custom Audiences', () => { it('should fail if no ad account ID is set', async () => { createAudienceInput.audienceName = 'The Void' - createAudienceInput.audienceSettings.adAccountId = '' + createAudienceInput.audienceSettings.adAccountId = 0 await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError) }) diff --git a/packages/destination-actions/src/destinations/taboola-actions/__tests__/index.test.ts b/packages/destination-actions/src/destinations/taboola-actions/__tests__/index.test.ts index 6f3f1daf4d..96877b110f 100644 --- a/packages/destination-actions/src/destinations/taboola-actions/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/taboola-actions/__tests__/index.test.ts @@ -16,6 +16,8 @@ const getAudienceInput = { audienceSettings: {} } + + describe('Taboola (actions)', () => { describe('testAuthentication', () => { it('should validate authentication inputs', async () => { @@ -31,6 +33,7 @@ describe('Taboola (actions)', () => { describe('createAudience', () => { it('should fail if no audience name is set', async () => { + const createAudienceInput1 = { settings: { client_id: 'test_client_id', @@ -40,7 +43,7 @@ describe('Taboola (actions)', () => { audienceSettings: { ttl_in_hours: 1024, exclude_from_campaigns: false, - account_id: accountId + account_id:accountId } } @@ -50,6 +53,7 @@ describe('Taboola (actions)', () => { }) it('should fail if no account ID is set', async () => { + const createAudienceInput2 = { settings: { client_id: 'test_client_id', @@ -59,7 +63,7 @@ describe('Taboola (actions)', () => { audienceSettings: { ttl_in_hours: 1024, exclude_from_campaigns: false, - account_id: '' + account_id:'' } } @@ -81,7 +85,7 @@ describe('Taboola (actions)', () => { audienceSettings: { ttl_in_hours: 1024, exclude_from_campaigns: false, - account_id: accountId + account_id:accountId } } const r = await testDestination.createAudience(createAudienceInput3) diff --git a/packages/destination-actions/src/destinations/yahoo-audiences/__tests__/index.test.ts b/packages/destination-actions/src/destinations/yahoo-audiences/__tests__/index.test.ts index 4671c00eb1..fb117fa6cb 100644 --- a/packages/destination-actions/src/destinations/yahoo-audiences/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/yahoo-audiences/__tests__/index.test.ts @@ -18,10 +18,11 @@ const createAudienceInput = { customer_desc: CUST_DESC }, audienceName: '', - audienceSettings: {}, - personas: { - computation_key: AUDIENCE_KEY, - computation_id: AUDIENCE_ID + audienceSettings: { + personas: { + computation_key: AUDIENCE_KEY, + computation_id: AUDIENCE_ID + } } } diff --git a/packages/destination-actions/src/destinations/yahoo-audiences/index.ts b/packages/destination-actions/src/destinations/yahoo-audiences/index.ts index e2b9d14c8e..9bd5de134b 100644 --- a/packages/destination-actions/src/destinations/yahoo-audiences/index.ts +++ b/packages/destination-actions/src/destinations/yahoo-audiences/index.ts @@ -115,8 +115,9 @@ const destination: AudienceDestinationDefinition = { }, async createAudience(request, createAudienceInput) { + const audienceSettings = createAudienceInput.audienceSettings // @ts-ignore type is not defined, and we will define it later - const personas = createAudienceInput.personas as PersonasSettings + const personas = audienceSettings.personas as PersonasSettings if (!personas) { throw new IntegrationError('Missing computation parameters: Id and Key', 'MISSING_REQUIRED_FIELD', 400) }