From a938b217e168c031442cc1ac7a1c98c6bd04979d Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Tue, 25 May 2021 10:36:30 +0700 Subject: [PATCH 1/3] chore: fix audit --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b72e3c17b..ebcac58f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4470,9 +4470,9 @@ } }, "hosted-git-info": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", - "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "html-encoding-sniffer": { From c61c71305b464e370b3bc96f7d918224fb718453 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Tue, 25 May 2021 11:40:49 +0700 Subject: [PATCH 2/3] feat: add sd asin report and missing metrics --- .../metrics/sponsored-display/index.ts | 2 +- ...onsored-display-ad-group-report-metrics.ts | 45 ++++-- .../sponsored-display-asin-report-metrics.ts | 25 ++++ ...onsored-display-campaign-report-metrics.ts | 86 +++++------ ...sponsored-display-common-report-metrics.ts | 136 ------------------ ...ored-display-product-ads-report-metrics.ts | 53 ++++--- ...sponsored-display-target-report-metrics.ts | 61 ++++---- src/operations/reports/report-types.ts | 1 + .../reports/sponsored-display/index.ts | 1 + .../sponsored-display-asin-report-params.ts | 11 ++ .../sponsored-display-report-operation.ts | 2 + ...ponsored-products-report-operation.test.ts | 31 ++++ 12 files changed, 204 insertions(+), 250 deletions(-) create mode 100644 src/operations/reports/metrics/sponsored-display/sponsored-display-asin-report-metrics.ts delete mode 100644 src/operations/reports/metrics/sponsored-display/sponsored-display-common-report-metrics.ts create mode 100644 src/operations/reports/sponsored-display/sponsored-display-asin-report-params.ts diff --git a/src/operations/reports/metrics/sponsored-display/index.ts b/src/operations/reports/metrics/sponsored-display/index.ts index c79ced7ae..b08ef6818 100644 --- a/src/operations/reports/metrics/sponsored-display/index.ts +++ b/src/operations/reports/metrics/sponsored-display/index.ts @@ -1,5 +1,5 @@ export * from './sponsored-display-ad-group-report-metrics' +export * from './sponsored-display-asin-report-metrics' export * from './sponsored-display-campaign-report-metrics' -export * from './sponsored-display-common-report-metrics' export * from './sponsored-display-product-ads-report-metrics' export * from './sponsored-display-target-report-metrics' diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-ad-group-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-ad-group-report-metrics.ts index 292158c68..176a8788a 100644 --- a/src/operations/reports/metrics/sponsored-display/sponsored-display-ad-group-report-metrics.ts +++ b/src/operations/reports/metrics/sponsored-display/sponsored-display-ad-group-report-metrics.ts @@ -1,23 +1,40 @@ import * as t from 'io-ts' -import { SponsoredDisplayCommonReportMetrics } from './sponsored-display-common-report-metrics' /** * Metrics specific to remarketing and T00020 tactic ad group. */ export const SponsoredDisplayAdGroupReportMetrics = t.union([ - SponsoredDisplayCommonReportMetrics, - - t.union([ - /** - * The name of the ad group. - */ - t.literal('adGroupName'), - - /** - * The identifier of the ad group. - */ - t.literal('adGroupId'), - ]), + t.literal('campaignName'), + t.literal('campaignId'), + t.literal('adGroupName'), + t.literal('adGroupId'), + t.literal('impressions'), + t.literal('clicks'), + t.literal('cost'), + t.literal('currency'), + t.literal('attributedConversions1d'), + t.literal('attributedConversions7d'), + t.literal('attributedConversions14d'), + t.literal('attributedConversions30d'), + t.literal('attributedConversions1dSameSKU'), + t.literal('attributedConversions7dSameSKU'), + t.literal('attributedConversions14dSameSKU'), + t.literal('attributedConversions30dSameSKU'), + t.literal('attributedUnitsOrdered1d'), + t.literal('attributedUnitsOrdered7d'), + t.literal('attributedUnitsOrdered14d'), + t.literal('attributedUnitsOrdered30d'), + t.literal('attributedSales1d'), + t.literal('attributedSales7d'), + t.literal('attributedSales14d'), + t.literal('attributedSales30d'), + t.literal('attributedSales1dSameSKU'), + t.literal('attributedSales7dSameSKU'), + t.literal('attributedSales14dSameSKU'), + t.literal('attributedSales30dSameSKU'), + t.literal('attributedOrdersNewToBrand14d'), + t.literal('attributedSalesNewToBrand14d'), + t.literal('attributedUnitsOrderedNewToBrand14d'), ]) export type SponsoredDisplayAdGroupReportMetrics = t.TypeOf< diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-asin-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-asin-report-metrics.ts new file mode 100644 index 000000000..29804de1f --- /dev/null +++ b/src/operations/reports/metrics/sponsored-display/sponsored-display-asin-report-metrics.ts @@ -0,0 +1,25 @@ +import * as t from 'io-ts' + +/** + * Metrics specific to remarketing and T00020 tactic ad group. + */ +export const SponsoredDisplayAsinReportMetrics = t.union([ + t.literal('campaignName'), + t.literal('campaignId'), + t.literal('adGroupName'), + t.literal('adGroupId'), + t.literal('asin'), + t.literal('otherAsin'), + t.literal('sku'), + t.literal('currency'), + t.literal('attributedUnitsOrdered1dOtherSKU'), + t.literal('attributedUnitsOrdered7dOtherSKU'), + t.literal('attributedUnitsOrdered14dOtherSKU'), + t.literal('attributedUnitsOrdered30dOtherSKU'), + t.literal('attributedSales1dOtherSKU'), + t.literal('attributedSales7dOtherSKU'), + t.literal('attributedSales14dOtherSKU'), + t.literal('attributedSales30dOtherSKU'), +]) + +export type SponsoredDisplayAsinReportMetrics = t.TypeOf diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-campaign-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-campaign-report-metrics.ts index a810a56d8..23ae6e39e 100644 --- a/src/operations/reports/metrics/sponsored-display/sponsored-display-campaign-report-metrics.ts +++ b/src/operations/reports/metrics/sponsored-display/sponsored-display-campaign-report-metrics.ts @@ -1,63 +1,41 @@ import * as t from 'io-ts' -import { SponsoredDisplayCommonReportMetrics } from './sponsored-display-common-report-metrics' /** * These metrics are specific to T00001 tactic campaign reports. */ export const SponsoredDisplayCampaignReportMetrics = t.union([ - SponsoredDisplayCommonReportMetrics, - - t.union([ - /** - * The name of the campaign. - */ - t.literal('campaignName'), - - /** - * The identifier of the campaign. - */ - t.literal('campaignId'), - - /** - * The status of the campaign. - */ - t.literal('campaignStatus'), - - /** - * The currency code associated with the campaign. - */ - t.literal('currency'), - - /** - * Total number of ad impressions. - */ - t.literal('impressions'), - - /** - * Total number of ad clicks associated with the campaign. Divide clicks by impressions to calculate click through rate (CTR). - */ - t.literal('clicks'), - - /** - * The total cost of all ad clicks for the campaign. Divide cost by clicks to calculate average cost per click (CPC). - */ - t.literal('cost'), - - /** - * Number of attributed detail page views occuring within 14 days of click on an ad. - */ - t.literal('attributedDPV14d'), - - /** - * Number of attributed units sold occurring within 14 days of click on an ad. - */ - t.literal('attributedUnitsSold14d'), - - /** - * Aggregate value of attributed sales occurring within 14 days of click on ad. - */ - t.literal('attributedSales14d'), - ]), + t.literal('campaignName'), + t.literal('campaignId'), + t.literal('campaignStatus'), + t.literal('impressions'), + t.literal('clicks'), + t.literal('cost'), + t.literal('currency'), + t.literal('attributedConversions1d'), + t.literal('attributedConversions7d'), + t.literal('attributedConversions14d'), + t.literal('attributedConversions30d'), + t.literal('attributedConversions1dSameSKU'), + t.literal('attributedConversions7dSameSKU'), + t.literal('attributedConversions14dSameSKU'), + t.literal('attributedConversions30dSameSKU'), + t.literal('attributedUnitsOrdered1d'), + t.literal('attributedUnitsOrdered7d'), + t.literal('attributedUnitsOrdered14d'), + t.literal('attributedUnitsOrdered30d'), + t.literal('attributedSales1d'), + t.literal('attributedSales7d'), + t.literal('attributedSales14d'), + t.literal('attributedSales30d'), + t.literal('attributedSales1dSameSKU'), + t.literal('attributedSales7dSameSKU'), + t.literal('attributedSales14dSameSKU'), + t.literal('attributedSales30dSameSKU'), + t.literal('attributedOrdersNewToBrand14d'), + t.literal('attributedSalesNewToBrand14d'), + t.literal('attributedUnitsOrderedNewToBrand14d'), + t.literal('attributedDPV14d'), + t.literal('attributedUnitsSold14d'), ]) export type SponsoredDisplayCampaignReportMetrics = t.TypeOf< diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-common-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-common-report-metrics.ts deleted file mode 100644 index 867cc5322..000000000 --- a/src/operations/reports/metrics/sponsored-display/sponsored-display-common-report-metrics.ts +++ /dev/null @@ -1,136 +0,0 @@ -import * as t from 'io-ts' - -export const SponsoredDisplayCommonReportMetrics = t.union([ - /** - * The name of the campaign. - */ - t.literal('campaignName'), - - /** - * The identifier of the campaign. - */ - t.literal('campaignId'), - - /** - * Total number of ad impressions. - */ - t.literal('impressions'), - - /** - * Total number of ad clicks associated with the campaign. - */ - t.literal('clicks'), - - /** - * The total cost of all ad clicks for the campaign. Divide cost by clicks to calculate average cost per click (CPC). - */ - t.literal('cost'), - - /** - * The currency code associated with the campaign. - */ - t.literal('currency'), - - /** - * Total number of attributed conversion events occuring within 24 hours of ad click. - */ - t.literal('attributedConversions1d'), - - /** - * Total number of attributed conversion events occuring within 7 days of ad click. - */ - t.literal('attributedConversions7d'), - - /** - * Total number of attributed conversion events occuring within 14 days of ad click. - */ - t.literal('attributedConversions14d'), - - /** - * Total number of attributed conversion events occuring within 30 days of ad click. - */ - t.literal('attributedConversions30d'), - - /** - * Total number of attributed conversion events occuring within 24 hours of ad click, where the SKU of the product advertised and the SKU of the conversion event are equivalent. - */ - t.literal('attributedConversions1dSameSKU'), - - /** - * Total number of attributed conversion events occuring within 7 days of ad click, where the SKU of the product advertised and the SKU of the conversion event are equivalent. - */ - t.literal('attributedConversions7dSameSKU'), - - /** - * Total number of attributed conversion events occuring within 14 days of ad click, where the SKU of the product advertised and the SKU of the conversion event are equivalent. - */ - t.literal('attributedConversions14dSameSKU'), - - /** - * Total number of attributed conversion events occuring within 30 days of ad click, where the SKU of the product advertised and the SKU of the conversion event are equivalent. - */ - t.literal('attributedConversions30dSameSKU'), - - /** - * Total number of attributed units ordered within 24 hours of ad click. - */ - t.literal('attributedUnitsOrdered1d'), - - /** - * Total number of attributed units ordered within 7 days of ad click. - */ - t.literal('attributedUnitsOrdered7d'), - - /** - * Total number of attributed units ordered within 14 days of ad click. - */ - t.literal('attributedUnitsOrdered14d'), - - /** - * Total number of attributed units ordered within 30 days of ad click. - */ - t.literal('attributedUnitsOrdered30d'), - - /** - * Total number of attributed sales occuring within 24 hours of ad click. - */ - t.literal('attributedSales1d'), - - /** - * Total number of attributed sales occuring within 7 days of ad click. - */ - t.literal('attributedSales7d'), - - /** - * Total number of attributed sales occuring within 14 days of ad click. - */ - t.literal('attributedSales14d'), - - /** - * Total number of attributed sales occuring within 30 days of ad click. - */ - t.literal('attributedSales30d'), - - /** - * Aggregate value of all attributed sales occuring within 24 hours of ad click, where the SKU of the product advertised and the SKU of the purchased item are equivalent. - */ - t.literal('attributedSales1dSameSKU'), - - /** - * Aggregate value of all attributed sales occuring within 7 days of ad click, where the SKU of the product advertised and the SKU of the purchased item are equivalent. - */ - t.literal('attributedSales7dSameSKU'), - - /** - * Aggregate value of all attributed sales occuring within 14 days of ad click, where the SKU of the product advertised and the SKU of the purchased item are equivalent. - */ - t.literal('attributedSales14dSameSKU'), - - /** - * Aggregate value of all attributed sales occuring within 30 days of ad click, where the SKU of the product advertised and the SKU of the purchased item are equivalent. - */ - t.literal('attributedSales30dSameSKU'), -]) -export type SponsoredDisplayCommonReportMetrics = t.TypeOf< - typeof SponsoredDisplayCommonReportMetrics -> diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-product-ads-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-product-ads-report-metrics.ts index c651b5283..8eeb63885 100644 --- a/src/operations/reports/metrics/sponsored-display/sponsored-display-product-ads-report-metrics.ts +++ b/src/operations/reports/metrics/sponsored-display/sponsored-display-product-ads-report-metrics.ts @@ -1,28 +1,43 @@ import * as t from 'io-ts' -import { SponsoredDisplayAdGroupReportMetrics } from './sponsored-display-ad-group-report-metrics' /** * Metrics specific to remarketing and T00020 tactic product ad. */ export const SponsoredDisplayProductAdsReportMetrics = t.union([ - SponsoredDisplayAdGroupReportMetrics, - - t.union([ - /** - * The ASIN of the product. - */ - t.literal('asin'), - - /** - * The SKU of the product. - */ - t.literal('sku'), - - /** - * The unique numerical ID of the ad. - */ - t.literal('adId'), - ]), + t.literal('campaignName'), + t.literal('campaignId'), + t.literal('adGroupName'), + t.literal('adGroupId'), + t.literal('asin'), + t.literal('sku'), + t.literal('adId'), + t.literal('impressions'), + t.literal('clicks'), + t.literal('cost'), + t.literal('currency'), + t.literal('attributedConversions1d'), + t.literal('attributedConversions7d'), + t.literal('attributedConversions14d'), + t.literal('attributedConversions30d'), + t.literal('attributedConversions1dSameSKU'), + t.literal('attributedConversions7dSameSKU'), + t.literal('attributedConversions14dSameSKU'), + t.literal('attributedConversions30dSameSKU'), + t.literal('attributedUnitsOrdered1d'), + t.literal('attributedUnitsOrdered7d'), + t.literal('attributedUnitsOrdered14d'), + t.literal('attributedUnitsOrdered30d'), + t.literal('attributedSales1d'), + t.literal('attributedSales7d'), + t.literal('attributedSales14d'), + t.literal('attributedSales30d'), + t.literal('attributedSales1dSameSKU'), + t.literal('attributedSales7dSameSKU'), + t.literal('attributedSales14dSameSKU'), + t.literal('attributedSales30dSameSKU'), + t.literal('attributedOrdersNewToBrand14d'), + t.literal('attributedSalesNewToBrand14d'), + t.literal('attributedUnitsOrderedNewToBrand14d'), ]) export type SponsoredDisplayProductAdsReportMetrics = t.TypeOf< diff --git a/src/operations/reports/metrics/sponsored-display/sponsored-display-target-report-metrics.ts b/src/operations/reports/metrics/sponsored-display/sponsored-display-target-report-metrics.ts index 5cee1bdc6..13c2e6491 100644 --- a/src/operations/reports/metrics/sponsored-display/sponsored-display-target-report-metrics.ts +++ b/src/operations/reports/metrics/sponsored-display/sponsored-display-target-report-metrics.ts @@ -1,35 +1,44 @@ import * as t from 'io-ts' -import { SponsoredDisplayCommonReportMetrics } from './sponsored-display-common-report-metrics' /** * These metrics are specific to T00020 tactic targeting reports: */ export const SponsoredDisplayTargetReportMetrics = t.union([ - SponsoredDisplayCommonReportMetrics, - - t.union([ - /** - * The identifier of the targeting expression used in a bid. - */ - t.literal('targetId'), - - /** - * The string representation of your expression object in targeting clauses. - */ - t.literal('targetingExpression'), - - /** - * The resolved string representation of your expression object in targeting clauses. - */ - t.literal('targetingText'), - - /** - * The type of match for the targeting expression used in bid. - * For manually created expressions, this value is TARGETING_EXPRESSION. - * For auto-targeting expressions this value is TARGETING_EXPRESSION_PREDEFINED. - */ - t.literal('targetingType'), - ]), + t.literal('campaignName'), + t.literal('campaignId'), + t.literal('adGroupName'), + t.literal('adGroupId'), + t.literal('targetId'), + t.literal('targetingExpression'), + t.literal('targetingText'), + t.literal('targetingType'), + t.literal('impressions'), + t.literal('clicks'), + t.literal('cost'), + t.literal('currency'), + t.literal('attributedConversions1d'), + t.literal('attributedConversions7d'), + t.literal('attributedConversions14d'), + t.literal('attributedConversions30d'), + t.literal('attributedConversions1dSameSKU'), + t.literal('attributedConversions7dSameSKU'), + t.literal('attributedConversions14dSameSKU'), + t.literal('attributedConversions30dSameSKU'), + t.literal('attributedUnitsOrdered1d'), + t.literal('attributedUnitsOrdered7d'), + t.literal('attributedUnitsOrdered14d'), + t.literal('attributedUnitsOrdered30d'), + t.literal('attributedSales1d'), + t.literal('attributedSales7d'), + t.literal('attributedSales14d'), + t.literal('attributedSales30d'), + t.literal('attributedSales1dSameSKU'), + t.literal('attributedSales7dSameSKU'), + t.literal('attributedSales14dSameSKU'), + t.literal('attributedSales30dSameSKU'), + t.literal('attributedOrdersNewToBrand14d'), + t.literal('attributedSalesNewToBrand14d'), + t.literal('attributedUnitsOrderedNewToBrand14d'), ]) export type SponsoredDisplayTargetReportMetrics = t.TypeOf< diff --git a/src/operations/reports/report-types.ts b/src/operations/reports/report-types.ts index 3249c7278..920ce7647 100644 --- a/src/operations/reports/report-types.ts +++ b/src/operations/reports/report-types.ts @@ -30,6 +30,7 @@ export type SponsoredBrandsReportType = t.TypeOf { + recordType: 'asins' +} diff --git a/src/operations/reports/sponsored-display/sponsored-display-report-operation.ts b/src/operations/reports/sponsored-display/sponsored-display-report-operation.ts index 9c0859f89..0d8c67416 100644 --- a/src/operations/reports/sponsored-display/sponsored-display-report-operation.ts +++ b/src/operations/reports/sponsored-display/sponsored-display-report-operation.ts @@ -4,6 +4,7 @@ import { BaseReportOperation } from '../base-report-operation' import { ReportResponse } from '../report-response' import { SponsoredDisplayAdGroupReportParams, + SponsoredDisplayAsinReportParams, SponsoredDisplayCampaignReportParams, SponsoredDisplayProductAdsReportParams, SponsoredDisplayTargetReportParams, @@ -11,6 +12,7 @@ import { export type SponsoredDisplayReportParams = | SponsoredDisplayAdGroupReportParams + | SponsoredDisplayAsinReportParams | SponsoredDisplayCampaignReportParams | SponsoredDisplayProductAdsReportParams | SponsoredDisplayTargetReportParams diff --git a/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts b/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts index 584d41fe0..d0ea5bf11 100644 --- a/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts +++ b/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts @@ -129,6 +129,37 @@ describe('SponsoredDisplayReportOperation', () => { expect(res.statusDetails).toBeDefined() }) + it(`should return a in progress status and metrics specific to T00020 tactic asin report`, async () => { + const res = await reportOperation.requestReport({ + recordType: 'asins', + reportDate: '20210520', + tactic: 'T00020', + metrics: [ + 'campaignName', + 'campaignId', + 'adGroupName', + 'adGroupId', + 'asin', + 'otherAsin', + 'sku', + 'currency', + 'attributedUnitsOrdered1dOtherSKU', + 'attributedUnitsOrdered7dOtherSKU', + 'attributedUnitsOrdered14dOtherSKU', + 'attributedUnitsOrdered30dOtherSKU', + 'attributedSales1dOtherSKU', + 'attributedSales7dOtherSKU', + 'attributedSales14dOtherSKU', + 'attributedSales30dOtherSKU', + ], + }) + + expect(res.reportId).toBeDefined() + expect(res.recordType).toStrictEqual('asins') + expect(res.status).toBe('IN_PROGRESS') + expect(res.statusDetails).toBeDefined() + }) + /** * TODO: error in Sandbox API without error message. * Need to check again on Production API. From 9d62bec249db3b8fe27baa6ed7a5f4edc1a3349e Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Tue, 25 May 2021 11:45:25 +0700 Subject: [PATCH 3/3] test: skip sd asin report because of unsupported from API --- .../sponsored-products-report-operation.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts b/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts index d0ea5bf11..89fe012fa 100644 --- a/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts +++ b/test/operations/reports/sponsored-display/sponsored-products-report-operation.test.ts @@ -129,7 +129,11 @@ describe('SponsoredDisplayReportOperation', () => { expect(res.statusDetails).toBeDefined() }) - it(`should return a in progress status and metrics specific to T00020 tactic asin report`, async () => { + /** + * TODO: "BadRequestError: Unsupported record type asins" error in Sandbox API. + * Need to check again on Production API. + */ + it.skip(`should return a in progress status and metrics specific to T00020 tactic asin report`, async () => { const res = await reportOperation.requestReport({ recordType: 'asins', reportDate: '20210520',