Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/233 use amazon market marketplaces #261

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@scaleleap/amazon-marketplaces": "4.0.1",
"client-oauth2": "4.2.5",
"cross-fetch": "3.0.4",
"fp-ts": "2.5.3",
Expand Down
59 changes: 24 additions & 35 deletions src/operations/commons/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as t from 'io-ts'

import {
AmazonMarketplaceAdvertisingCountryCode,
AmazonMarketplaceAdvertisingCurrency,
AmazonMarketplaceAdvertisingTimeZone,
} from '@scaleleap/amazon-marketplaces'

export class EnumType<A> extends t.Type<A> {
public readonly _tag: 'EnumType' = 'EnumType'
public enumObject!: object
Expand All @@ -17,43 +23,26 @@ export class EnumType<A> extends t.Type<A> {
// simple helper function
export const createEnumType = <T>(e: object, name?: string) => new EnumType<T>(e, name)

export enum CountryCodeEnum {
AU = 'AU',
CA = 'CA',
DE = 'DE',
ES = 'ES',
FR = 'FR',
IT = 'IT',
JP = 'JP',
UK = 'UK',
US = 'US',
}

export const CountryCodeType = createEnumType<CountryCodeEnum>(CountryCodeEnum)
export type CountryCodeType = t.TypeOf<typeof CountryCodeType>
export const AmazonMarketplaceAdvertisingCountryCodeType = createEnumType<
AmazonMarketplaceAdvertisingCountryCode
>(AmazonMarketplaceAdvertisingCountryCode)
export type AmazonMarketplaceAdvertisingCountryCodeType = t.TypeOf<
typeof AmazonMarketplaceAdvertisingCountryCodeType
>

export enum CurrencyCodeEnum {
AUD = 'AUD',
CAD = 'CAD',
EUR = 'EUR',
GBP = 'GBP',
JPY = 'JPY',
USD = 'USD',
}

export const CurrencyCodeType = createEnumType<CurrencyCodeEnum>(CurrencyCodeEnum)
export type CurrencyCodeType = t.TypeOf<typeof CurrencyCodeType>

export enum TimeZoneEnum {
AMERICA_LOS_ANGELES = 'America/Los_Angeles',
ASIA_TOKYO = 'Asia/Tokyo',
AUSTRALIA_SYDNEY = 'Australia/Sydney',
EUROPE_LONDON = 'Europe/London',
EUROPE_PARIS = 'Europe/Paris',
}
export const AmazonMarketplaceAdvertisingCurrencyType = createEnumType<
AmazonMarketplaceAdvertisingCurrency
>(AmazonMarketplaceAdvertisingCurrency)
export type AmazonMarketplaceAdvertisingCurrencyType = t.TypeOf<
typeof AmazonMarketplaceAdvertisingCurrencyType
>

export const TimeZoneType = createEnumType<TimeZoneEnum>(TimeZoneEnum)
export type TimeZoneType = t.TypeOf<typeof TimeZoneType>
export const AmazonMarketplaceAdvertisingTimeZoneType = createEnumType<
AmazonMarketplaceAdvertisingTimeZone
>(AmazonMarketplaceAdvertisingTimeZone)
export type AmazonMarketplaceAdvertisingTimeZoneType = t.TypeOf<
typeof AmazonMarketplaceAdvertisingTimeZoneType
>

export const ListPagination = t.partial({
/**
Expand Down
4 changes: 2 additions & 2 deletions src/operations/portfolios/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as t from 'io-ts'
import { CurrencyCodeType, createEnumType } from '../commons/types'
import { AmazonMarketplaceAdvertisingCurrencyType, createEnumType } from '../commons/types'
import { DateFromNumber } from 'io-ts-types/lib/DateFromNumber'

export const PortfolioId = t.number
Expand All @@ -17,7 +17,7 @@ export const PortfolioBudget = t.partial({
/**
* The currency code of the budget.
*/
currencyCode: CurrencyCodeType,
currencyCode: AmazonMarketplaceAdvertisingCurrencyType,

/**
* The policy of the portfolio.
Expand Down
7 changes: 5 additions & 2 deletions src/operations/profiles/profile-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ProfileRegistrationResponse,
} from './types'
import { Decode, DecodeArray } from '../../decorators'
import { CountryCodeEnum, CountryCodeType } from '../commons/types'
import { AmazonMarketplaceAdvertisingCountryCodeType } from '../commons/types'
import { AmazonMarketplaceAdvertisingCountryCode } from '@scaleleap/amazon-marketplaces'

export class ProfileOperation extends Operation {
protected resource = 'profiles'
Expand Down Expand Up @@ -57,7 +58,9 @@ export class ProfileOperation extends Operation {
* @memberof ProfileOperation
*/
@Decode(RegisterProfileResponse)
public registerProfile(countryCode: CountryCodeType = CountryCodeEnum.US) {
public registerProfile(
countryCode: AmazonMarketplaceAdvertisingCountryCodeType = AmazonMarketplaceAdvertisingCountryCode.US,
) {
return this.client.put<RegisterProfileResponse>(`${this.version}/${this.resource}/register`, {
countryCode,
})
Expand Down
15 changes: 10 additions & 5 deletions src/operations/profiles/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as t from 'io-ts'
import { CurrencyCodeType, TimeZoneType, CountryCodeType, createEnumType } from '../commons/types'
import {
AmazonMarketplaceAdvertisingCurrencyType,
AmazonMarketplaceAdvertisingTimeZoneType,
AmazonMarketplaceAdvertisingCountryCodeType,
createEnumType,
} from '../commons/types'

export const ProfileId = t.number
export type ProfileId = t.TypeOf<typeof ProfileId>
Expand Down Expand Up @@ -73,17 +78,17 @@ export const Profile = t.intersection([
/**
* The country code identifying the publisher(s) on which ads will run.
*/
countryCode: CountryCodeType,
countryCode: AmazonMarketplaceAdvertisingCountryCodeType,

/**
* The currency used for all monetary values for entities under this profile.
*/
currencyCode: CurrencyCodeType,
currencyCode: AmazonMarketplaceAdvertisingCurrencyType,

/**
* The tz database time zone used for all date-based campaign management and reporting.
*/
timezone: TimeZoneType,
timezone: AmazonMarketplaceAdvertisingTimeZoneType,

/**
* Account info.
Expand All @@ -108,7 +113,7 @@ export const RegisterBrand = t.strict({
/**
* The country in which you wish to register the profile. Can be one of: US, CA, UK, DE, FR, IT, ES, JP, AU
*/
countryCode: CountryCodeType,
countryCode: AmazonMarketplaceAdvertisingCountryCodeType,

/**
* REQUIRED. Brand name.
Expand Down
4 changes: 2 additions & 2 deletions test/operations/profiles/profile-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OperationProvider } from '../../../src/operations/operation-provider'
import { ProfileOperation } from '../../../src/operations/profiles/profile-operation'
import { httpClientFactory } from '../../http-client-factory'
import { Profile, RegisterProfileResponseStatusEnum } from '../../../src/operations/profiles/types'
import { CountryCodeEnum } from '../../../src/operations/commons/types'
import { AmazonMarketplaceAdvertisingCountryCode } from '@scaleleap/amazon-marketplaces'
import { POLLY_PASSTHROUGH_TAG } from '../../constants'
import { delay } from '../../test-utils'

Expand Down Expand Up @@ -83,7 +83,7 @@ describe('ProfileOperation', () => {
await delay()

const param = {
countryCode: CountryCodeEnum.US,
countryCode: AmazonMarketplaceAdvertisingCountryCode.US,
brand: 'yay',
}

Expand Down