Skip to content

Commit

Permalink
feat: adds AmazonMarketplaceAdvertisingRegion object
Browse files Browse the repository at this point in the history
Adds AmazonMarketplaceAdvertisingRegion object suppot.

BREAKING CHANGE: Adds AmazonMarketplaceAdvertisingRegion object suppot.
  • Loading branch information
moltar authored and Roman committed Mar 10, 2020
1 parent b1b8f61 commit 87c27c9
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 58 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ const US = findAmazonMarketplaceOrFail('countryCode', AmazonMarketplaceCountryCo
"uri": "https://www.amazon.ca",
"webServiceUri": "https://mws.amazonservices.ca",
"advertising": {
"uri": "https://advertising-api.amazon.com",
"countryCode": "CA",
"region": "NA",
"timeZone": "America/Los_Angeles",
"region": {
"accessTokenUri": "https://api.amazon.com/auth/o2/token",
"authorizationUri": "https://www.amazon.com/ap/oa",
"code": "NA",
"endpoint": "https://advertising-api.amazon.com",
"name": "North America",
},
"bids": {
"sponsoredBrands": {
"min": 10,
Expand All @@ -94,7 +100,6 @@ const US = findAmazonMarketplaceOrFail('countryCode', AmazonMarketplaceCountryCo
"max": 100000
}
},
"timeZone": "America/Los_Angeles"
}
}
```
Expand Down
33 changes: 33 additions & 0 deletions src/amazon-marketplace-advertising-region.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export interface AmazonMarketplaceAdvertisingRegion {
/**
* Region code.
*/
code: string

/**
* Region name.
*/
name: string

/**
* Authorization URI.
*/
authorizationUri: string

/**
* Access Token URI
*/
accessTokenUri: string

/**
* Access endpoint URI.
*/
endpoint: string
}

export class AmazonMarketplaceAdvertisingRegion implements AmazonMarketplaceAdvertisingRegion {
constructor(data: AmazonMarketplaceAdvertisingRegion) {
Object.assign(this, data)
Object.freeze(this)
}
}
16 changes: 2 additions & 14 deletions src/amazon-marketplace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AmazonMarketplaceAdvertisingRegion } from './amazon-marketplace-advertising-region'

/**
* Amazon Marketplace country code enum.
*/
Expand Down Expand Up @@ -70,21 +72,7 @@ export enum AmazonMarketplaceAdvertisingTimeZone {
EUROPE_PARIS = 'Europe/Paris',
}

/**
* Amazon Advertising API Regions
*/
export enum AmazonMarketplaceAdvertisingRegion {
NORTH_AMERICA = 'NA',
EUROPE = 'EU',
FAR_EAST = 'FE',
}

export interface AmazonMarketplaceAdvertising {
/**
* Amazon Advertising API endpoint URI.
*/
readonly uri: string

/**
* Amazon Advertising account time zone.
*
Expand Down
5 changes: 2 additions & 3 deletions src/european-advertising-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import {
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingTimeZone,
AmazonMarketplaceAdvertising,
AmazonMarketplaceAdvertisingRegion,
} from './amazon-marketplace'
import { marketplaceAdvertisingRegions } from './marketplace-advertising-regions'

export function europeanAdvertisingFactory(
countryCode: AmazonMarketplaceAdvertisingCountryCode,
): AmazonMarketplaceAdvertising {
return {
uri: 'https://advertising-api-eu.amazon.com',
countryCode,
region: AmazonMarketplaceAdvertisingRegion.EUROPE,
region: marketplaceAdvertisingRegions.EU,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
9 changes: 9 additions & 0 deletions src/marketplace-advertising-regions/EU.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AmazonMarketplaceAdvertisingRegion } from '../amazon-marketplace-advertising-region'

export const EU = new AmazonMarketplaceAdvertisingRegion({
accessTokenUri: 'https://api.amazon.co.uk/auth/o2/token',
authorizationUri: 'https://eu.account.amazon.com/ap/oa',
code: 'EU',
endpoint: 'https://advertising-api-eu.amazon.com',
name: 'Europe',
})
9 changes: 9 additions & 0 deletions src/marketplace-advertising-regions/FE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AmazonMarketplaceAdvertisingRegion } from '../amazon-marketplace-advertising-region'

export const FE = new AmazonMarketplaceAdvertisingRegion({
accessTokenUri: 'https://api.amazon.co.jp/auth/o2/token',
authorizationUri: 'https://apac.account.amazon.com/ap/oa',
code: 'FE',
endpoint: 'https://advertising-api-fe.amazon.com',
name: 'Far East',
})
9 changes: 9 additions & 0 deletions src/marketplace-advertising-regions/NA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AmazonMarketplaceAdvertisingRegion } from '../amazon-marketplace-advertising-region'

export const NA = new AmazonMarketplaceAdvertisingRegion({
accessTokenUri: 'https://api.amazon.com/auth/o2/token',
authorizationUri: 'https://www.amazon.com/ap/oa',
code: 'NA',
endpoint: 'https://advertising-api.amazon.com',
name: 'North America',
})
9 changes: 9 additions & 0 deletions src/marketplace-advertising-regions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { EU } from './EU'
import { FE } from './FE'
import { NA } from './NA'

export const marketplaceAdvertisingRegions = {
EU,
FE,
NA,
} as const
5 changes: 2 additions & 3 deletions src/marketplaces/AE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'

export const AE = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.AE,
Expand All @@ -15,9 +15,8 @@ export const AE = new AmazonMarketplace({
uri: 'https://www.amazon.ae',
webServiceUri: 'https://mws.amazonservices.ae',
advertising: {
uri: 'https://advertising-api-eu.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.AE,
region: AmazonMarketplaceAdvertisingRegion.EUROPE,
region: marketplaceAdvertisingRegions.EU,
bids: {
sponsoredBrands: {
min: 24,
Expand Down
5 changes: 2 additions & 3 deletions src/marketplaces/AU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'

export const AU = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.AU,
Expand All @@ -15,9 +15,8 @@ export const AU = new AmazonMarketplace({
uri: 'https://www.amazon.com.au',
webServiceUri: 'https://mws.amazonservices.com.au',
advertising: {
uri: 'https://advertising-api-fe.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.AU,
region: AmazonMarketplaceAdvertisingRegion.FAR_EAST,
region: marketplaceAdvertisingRegions.FE,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
5 changes: 2 additions & 3 deletions src/marketplaces/CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'

/**
* Canada
Expand All @@ -18,9 +18,8 @@ export const CA = new AmazonMarketplace({
uri: 'https://www.amazon.ca',
webServiceUri: 'https://mws.amazonservices.ca',
advertising: {
uri: 'https://advertising-api.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.CA,
region: AmazonMarketplaceAdvertisingRegion.NORTH_AMERICA,
region: marketplaceAdvertisingRegions.NA,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
5 changes: 2 additions & 3 deletions src/marketplaces/GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'
import { DE } from './DE'

if (!DE.advertising) {
Expand All @@ -20,9 +20,8 @@ export const GB = new AmazonMarketplace({
uri: 'https://www.amazon.co.uk',
webServiceUri: DE.webServiceUri,
advertising: {
uri: DE.advertising.uri,
countryCode: AmazonMarketplaceAdvertisingCountryCode.UK,
region: AmazonMarketplaceAdvertisingRegion.EUROPE,
region: marketplaceAdvertisingRegions.EU,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
5 changes: 2 additions & 3 deletions src/marketplaces/JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'

export const JP = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.JP,
Expand All @@ -15,9 +15,8 @@ export const JP = new AmazonMarketplace({
uri: 'https://www.amazon.co.jp',
webServiceUri: 'https://mws.amazonservices.jp',
advertising: {
uri: 'https://advertising-api-fe.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.JP,
region: AmazonMarketplaceAdvertisingRegion.FAR_EAST,
region: marketplaceAdvertisingRegions.FE,
bids: {
sponsoredBrands: {
min: 1000,
Expand Down
5 changes: 2 additions & 3 deletions src/marketplaces/US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AmazonMarketplaceCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingRegion,
} from '../amazon-marketplace'
import { marketplaceAdvertisingRegions } from '../marketplace-advertising-regions'

export const US = new AmazonMarketplace({
countryCode: AmazonMarketplaceCountryCode.US,
Expand All @@ -15,9 +15,8 @@ export const US = new AmazonMarketplace({
uri: 'https://www.amazon.com',
webServiceUri: 'https://mws.amazonservices.com',
advertising: {
uri: 'https://advertising-api.amazon.com',
countryCode: AmazonMarketplaceAdvertisingCountryCode.US,
region: AmazonMarketplaceAdvertisingRegion.NORTH_AMERICA,
region: marketplaceAdvertisingRegions.NA,
bids: {
sponsoredBrands: {
min: 10,
Expand Down
Loading

0 comments on commit 87c27c9

Please sign in to comment.