diff --git a/src/operations/campaigns/sponsored-brands-campaign-operation.ts b/src/operations/campaigns/sponsored-brands-campaign-operation.ts index 6554331e9..3971b7aed 100644 --- a/src/operations/campaigns/sponsored-brands-campaign-operation.ts +++ b/src/operations/campaigns/sponsored-brands-campaign-operation.ts @@ -3,41 +3,17 @@ import { Decode, DecodeArray } from '../../decorators' import { AmazonAdTypeURIPrefix } from '../amazon-ad-type-uri-prefix' import { - Campaign, ListCampaignsParams, CampaignId, CampaignResponse, SponsoredBrandsCampaignUpdateParams, - CampaignExtended, + SponsoredBrandsCampaignCreateParams, + SponsoredBrandsCampaign, } from './types' export class SponsoredBrandsCampaignOperation extends Operation { protected resource = `${this.version}/${AmazonAdTypeURIPrefix.SponsoredBrands}/campaigns` - /** - * Gets an array of all campaigns associated with the client identifier passed in the authorization header, filtered by specified criteria. - * - * @param {ListCampaignsParams} [params] - * @returns - * @memberof SponsoredBrandsCampaignOperation - */ - @DecodeArray(Campaign) - public listCampaigns(params?: ListCampaignsParams) { - return this.client.get(this.paramsFilterTransformer('', params)) - } - - /** - * Gets an array of all campaigns with extended fields associated with the client identifier passed in the authorization header, filtered by specified criteria. - * - * @param {ListCampaignsParams} [params] - * @returns - * @memberof SponsoredBrandsCampaignOperation - */ - @DecodeArray(CampaignExtended) - public listCampaignsEx(params?: ListCampaignsParams) { - return this.client.get(this.paramsFilterTransformer('/extended', params)) - } - /** * Gets a campaign specified by identifier * @@ -45,32 +21,32 @@ export class SponsoredBrandsCampaignOperation extends Operation { * @returns * @memberof SponsoredBrandsCampaignOperation */ - @Decode(Campaign) + @Decode(SponsoredBrandsCampaign) public getCampaign(campaignId: CampaignId) { - return this.client.get(`${this.resource}/${campaignId}`) + return this.client.get(`${this.resource}/${campaignId}`) } /** - * Gets a campaign with extended fields specified by identifier + * Gets an array of all campaigns associated with the client identifier passed in the authorization header, filtered by specified criteria. * - * @param {CampaignId} campaignId + * @param {ListCampaignsParams} [params] * @returns * @memberof SponsoredBrandsCampaignOperation */ - @Decode(CampaignExtended) - public getCampaignEx(campaignId: CampaignId) { - return this.client.get(`${this.resource}/extended/${campaignId}`) + @DecodeArray(SponsoredBrandsCampaign) + public listCampaigns(params?: ListCampaignsParams) { + return this.client.get(this.paramsFilterTransformer('', params)) } /** * Creates one or more new Campaigns * - * @param {Campaign[]} campaigns + * @param {SponsoredBrandsCampaignCreateParams[]} campaigns * @returns * @memberof SponsoredBrandsCampaignOperation */ @DecodeArray(CampaignResponse) - public createCampaigns(campaigns: Campaign[]) { + public createCampaigns(campaigns: SponsoredBrandsCampaignCreateParams[]) { return this.client.post(this.resource, campaigns) } diff --git a/src/operations/campaigns/types.ts b/src/operations/campaigns/types.ts index 718bcf598..c9a8555c7 100644 --- a/src/operations/campaigns/types.ts +++ b/src/operations/campaigns/types.ts @@ -146,6 +146,37 @@ export type SponsoredProductsCampaignCreateParams = t.TypeOf< typeof SponsoredProductsCampaignCreateParams > +export const SponsoredBrandsCampaignCreateParams = t.strict({ + /** + * Campaign name limit is 128 characters. + * Duplicate campaign names are not allowed. Campaigns with zero positive keywords are not allowed. + */ + name: CampaignName, + + /** + * Differentiates between a keyword-targeted and automatically targeted campaign. + */ + targetingType: CampaignTargetingType, + + /** + * The state of the campaign. + */ + state: CampaignState, + + /** + * Daily budget for the campaign. + */ + dailyBudget: t.number, + + /** + * The date the campaign will go or went live as YYYYMMDD. + */ + startDate: t.string, +}) +export type SponsoredBrandsCampaignCreateParams = t.TypeOf< + typeof SponsoredBrandsCampaignCreateParams +> + export const SponsoredProductsCampaignUpdateParams = t.intersection([ t.type({ /** diff --git a/test/operations/campaigns/sponsored-brands-campaign-operation.test.ts b/test/operations/campaigns/sponsored-brands-campaign-operation.test.ts index 28533267b..2f5ebce79 100644 --- a/test/operations/campaigns/sponsored-brands-campaign-operation.test.ts +++ b/test/operations/campaigns/sponsored-brands-campaign-operation.test.ts @@ -16,21 +16,6 @@ describe('SponsoredBrandsCampaignOperation', () => { }) }) - // Error: Unable to extract parameter from http request for javax.ws.rs.PathParam("campaignId") value is 'extended' for public abstract com.amazon.adapi.model.hsa.ExternalCampaign com.amazon.adapi.resource.HsaCampaignInterface.getCampaign(long) - describe.skip('listCampaignsEx', () => { - it(`should return an array of expanded campaigns`, async () => { - const res = await campaignOperation.listCampaignsEx() - expect(Array.isArray(res)).toBeTruthy() - }) - - it(`should return a filtered list of results`, async () => { - const res = await campaignOperation.listCampaignsEx({ - campaignIdFilter: [CAMPAIGN_ID], - }) - expect(Array.isArray(res)).toBeTruthy() - }) - }) - // Skip: Sponsored brand campaign list is empty describe.skip('getCampaign', () => { it(`should return a single campaign`, async () => { @@ -39,26 +24,16 @@ describe('SponsoredBrandsCampaignOperation', () => { }) }) - // Skip: Sponsored brand campaign list is empty - describe.skip('getCampaignEx', () => { - it(`should return a single extended campaign`, async () => { - const res = await campaignOperation.getCampaignEx(CAMPAIGN_ID) - expect(res).toBeTruthy() - }) - }) - // Return an error: No resource method found for POST, return 405 with Allow header describe.skip('createCampaigns', () => { it(`should create a campaign`, async () => { const res = await campaignOperation.createCampaigns([ { name: 'test campaign 4', - campaignType: 'sponsoredProducts', - dailyBudget: 1, - state: 'enabled', targetingType: 'manual', + state: 'enabled', + dailyBudget: 1, startDate: '20190301', - premiumBidAdjustment: true, }, ])