Skip to content

Commit

Permalink
fix: adds countryCode to AmazonMarketplaceAdvertising
Browse files Browse the repository at this point in the history
Adds countryCode prop to AmazonMarketplaceAdvertising, that is separate
from Amazon Marketplace countryCode, as it uses different values.

BREAKING CHANGE: Adds countryCode to AmazonMarketplaceAdvertising that is different from AmazonMarketplaceCountryCode enum.
Closes #122
  • Loading branch information
moltar committed Mar 9, 2020
1 parent dbb6b58 commit 82b043f
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const US = findAmazonMarketplaceOrFail('countryCode', AmazonMarketplaceAdvertisi
"webServiceUri": "https://mws.amazonservices.ca",
"advertising": {
"uri": "https://advertising-api.amazon.com",
"countryCode": "CA",
"bids": {
"sponsoredBrands": {
"min": 10,
Expand Down
30 changes: 30 additions & 0 deletions src/amazon-marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ export enum AmazonMarketplaceAdvertisingCurrency {
USD = 'USD',
}

/**
* Amazon Marketplace Advertising country code enum.
*
* The country code identifying the publisher(s) on which ads will run.
*/
export enum AmazonMarketplaceAdvertisingCountryCode {
AE = 'AE',
AU = 'AU',
CA = 'CA',
DE = 'DE',
ES = 'ES',
FR = 'FR',
IT = 'IT',
JP = 'JP',
UK = 'UK', // Not a real country code, but such is life. See https://github.com/ScaleLeap/amazon-marketplaces/issues/122
US = 'US',
}

/**
* Time Zone enum.
*/
Expand Down Expand Up @@ -67,6 +85,18 @@ export interface AmazonMarketplaceAdvertising {
*/
readonly timeZone: AmazonMarketplaceAdvertisingTimeZone

/**
* The country code identifying the publisher(s) on which ads will run.
*
* [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) with the exception of UK, which uses
* `UK` instead of `GB`.
*
* @example
*
* AmazonMarketplaceAdvertisingCountryCode.CA
*/
readonly countryCode: AmazonMarketplaceAdvertisingCountryCode

/**
* Minimum and maximum bids for each advertising type.
*/
Expand Down
25 changes: 25 additions & 0 deletions src/european-advertising-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceAdvertising,
} from './amazon-marketplace'

export function europeanAdvertisingFactory(
countryCode: AmazonMarketplaceAdvertisingCountryCode,
): AmazonMarketplaceAdvertising {
return {
uri: 'https://advertising-api-eu.amazon.com',
countryCode,
bids: {
sponsoredBrands: {
min: 10,
max: 3900,
},
sponsoredProducts: {
min: 2,
max: 100000,
},
},
timeZone: AmazonMarketplaceAdvertisingTimeZone.EUROPE_PARIS,
}
}
2 changes: 2 additions & 0 deletions src/marketplaces/AE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'

export const AE = new AmazonMarketplace({
Expand All @@ -14,6 +15,7 @@ export const AE = new AmazonMarketplace({
webServiceUri: 'https://mws.amazonservices.ae',
advertising: {
uri: 'https://advertising-api-eu.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.AE,
bids: {
sponsoredBrands: {
min: 24,
Expand Down
2 changes: 2 additions & 0 deletions src/marketplaces/AU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'

export const AU = new AmazonMarketplace({
Expand All @@ -14,6 +15,7 @@ export const AU = new AmazonMarketplace({
webServiceUri: 'https://mws.amazonservices.com.au',
advertising: {
uri: 'https://advertising-api-fe.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.AU,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
18 changes: 3 additions & 15 deletions src/marketplaces/DE.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
AmazonMarketplace,
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'
import { europeanAdvertisingFactory } from '../european-advertising-factory'

export const DE = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.DE,
Expand All @@ -12,18 +13,5 @@ export const DE = new AmazonMarketplace({
name: 'Germany',
uri: 'https://www.amazon.de',
webServiceUri: 'https://mws-eu.amazonservices.com',
advertising: {
uri: 'https://advertising-api-eu.amazon.com',
bids: {
sponsoredBrands: {
min: 10,
max: 3900,
},
sponsoredProducts: {
min: 2,
max: 100000,
},
},
timeZone: AmazonMarketplaceAdvertisingTimeZone.EUROPE_PARIS,
},
advertising: europeanAdvertisingFactory(AmazonMarketplaceAdvertisingCountryCode.DE),
})
5 changes: 3 additions & 2 deletions src/marketplaces/ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
AmazonMarketplace,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'
import { DE } from './DE'
import { europeanAdvertisingFactory } from '../european-advertising-factory'

export const ES = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.ES,
Expand All @@ -12,5 +13,5 @@ export const ES = new AmazonMarketplace({
name: 'Spain',
uri: 'https://www.amazon.es',
webServiceUri: 'https://mws-eu.amazonservices.com',
advertising: Object.assign({}, DE.advertising),
advertising: europeanAdvertisingFactory(AmazonMarketplaceAdvertisingCountryCode.ES),
})
5 changes: 3 additions & 2 deletions src/marketplaces/FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
AmazonMarketplace,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'
import { DE } from './DE'
import { europeanAdvertisingFactory } from '../european-advertising-factory'

export const FR = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.FR,
Expand All @@ -12,5 +13,5 @@ export const FR = new AmazonMarketplace({
name: 'France',
uri: 'https://www.amazon.fr',
webServiceUri: 'https://mws-eu.amazonservices.com',
advertising: Object.assign({}, DE.advertising),
advertising: europeanAdvertisingFactory(AmazonMarketplaceAdvertisingCountryCode.FR),
})
2 changes: 2 additions & 0 deletions src/marketplaces/GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'
import { DE } from './DE'

Expand All @@ -19,6 +20,7 @@ export const GB = new AmazonMarketplace({
webServiceUri: DE.webServiceUri,
advertising: {
uri: DE.advertising.uri,
countryCode: AmazonMarketplaceAdvertisingCountryCode.UK,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
5 changes: 3 additions & 2 deletions src/marketplaces/IT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
AmazonMarketplace,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'
import { DE } from './DE'
import { europeanAdvertisingFactory } from '../european-advertising-factory'

export const IT = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.IT,
Expand All @@ -12,5 +13,5 @@ export const IT = new AmazonMarketplace({
name: 'Italy',
uri: 'https://www.amazon.it',
webServiceUri: 'https://mws-eu.amazonservices.com',
advertising: Object.assign({}, DE.advertising),
advertising: europeanAdvertisingFactory(AmazonMarketplaceAdvertisingCountryCode.DE),
})
2 changes: 2 additions & 0 deletions src/marketplaces/JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'

export const JP = new AmazonMarketplace({
Expand All @@ -14,6 +15,7 @@ export const JP = new AmazonMarketplace({
webServiceUri: 'https://mws.amazonservices.jp',
advertising: {
uri: 'https://advertising-api-fe.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.JP,
bids: {
sponsoredBrands: {
min: 1000,
Expand Down
2 changes: 2 additions & 0 deletions src/marketplaces/US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
} from '../amazon-marketplace'

export const US = new AmazonMarketplace({
Expand All @@ -14,6 +15,7 @@ export const US = new AmazonMarketplace({
webServiceUri: 'https://mws.amazonservices.com',
advertising: {
uri: 'https://advertising-api.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.US,
bids: {
sponsoredBrands: {
min: 10,
Expand Down

0 comments on commit 82b043f

Please sign in to comment.