diff --git a/packages/browser-destinations/package.json b/packages/browser-destinations/package.json index dc0e10d318..a17d915d57 100644 --- a/packages/browser-destinations/package.json +++ b/packages/browser-destinations/package.json @@ -84,7 +84,7 @@ "size-limit": [ { "path": "dist/web/*/*.js", - "limit": "169 KB" + "limit": "190 KB" } ] } diff --git a/packages/core/src/destination-kit/index.ts b/packages/core/src/destination-kit/index.ts index c7619f78c3..d4034522d4 100644 --- a/packages/core/src/destination-kit/index.ts +++ b/packages/core/src/destination-kit/index.ts @@ -34,6 +34,7 @@ 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, @@ -94,12 +95,15 @@ export type AudienceResult = { } export type AudienceMode = { type: 'realtime' } | { type: 'synced'; full_audience_sync: boolean } +export type Personas = { computation_id: 'string'; computation_key: 'string' } & { [key: string]: any } export type CreateAudienceInput = { settings: Settings audienceSettings?: AudienceSettings + personas?: Personas + audienceName: string statsContext?: StatsContext @@ -426,6 +430,10 @@ 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 = { @@ -436,7 +444,6 @@ 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 2498008c66..dd112557bc 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,6 +136,22 @@ 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}`] @@ -151,9 +167,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 ff0244a582..c73b567e4a 100644 --- a/packages/destination-actions/src/destinations/amazon-amc/index.ts +++ b/packages/destination-actions/src/destinations/amazon-amc/index.ts @@ -179,22 +179,14 @@ const destination: AudienceDestinationDefinition = { } if (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 + payload.metadata.ttl = ttl } 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: cpmCents + cpmCents: cpm_cents }) } 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 12beacd957..36bbfc8ab4 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 = 0 + createAudienceInput.audienceSettings.adAccountId = '' 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 96877b110f..6f3f1daf4d 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,8 +16,6 @@ const getAudienceInput = { audienceSettings: {} } - - describe('Taboola (actions)', () => { describe('testAuthentication', () => { it('should validate authentication inputs', async () => { @@ -33,7 +31,6 @@ describe('Taboola (actions)', () => { describe('createAudience', () => { it('should fail if no audience name is set', async () => { - const createAudienceInput1 = { settings: { client_id: 'test_client_id', @@ -43,7 +40,7 @@ describe('Taboola (actions)', () => { audienceSettings: { ttl_in_hours: 1024, exclude_from_campaigns: false, - account_id:accountId + account_id: accountId } } @@ -53,7 +50,6 @@ describe('Taboola (actions)', () => { }) it('should fail if no account ID is set', async () => { - const createAudienceInput2 = { settings: { client_id: 'test_client_id', @@ -63,7 +59,7 @@ describe('Taboola (actions)', () => { audienceSettings: { ttl_in_hours: 1024, exclude_from_campaigns: false, - account_id:'' + account_id: '' } } @@ -85,7 +81,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 fb117fa6cb..4671c00eb1 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,11 +18,10 @@ 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 9bd5de134b..e2b9d14c8e 100644 --- a/packages/destination-actions/src/destinations/yahoo-audiences/index.ts +++ b/packages/destination-actions/src/destinations/yahoo-audiences/index.ts @@ -115,9 +115,8 @@ 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 = audienceSettings.personas as PersonasSettings + const personas = createAudienceInput.personas as PersonasSettings if (!personas) { throw new IntegrationError('Missing computation parameters: Id and Key', 'MISSING_REQUIRED_FIELD', 400) }