Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

feature: subscriptions api #85

Merged
merged 31 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
00dff3b
feat: init subscriptions
justinemmanuelmercado Jun 15, 2020
d273391
fix: update api ver
justinemmanuelmercado Jun 15, 2020
e14ba55
test: adds Polly recordings
Jun 15, 2020
c46da9d
test: register destination
justinemmanuelmercado Jun 15, 2020
a1abaad
test: improve subs test. add test to http for registerDestination case
justinemmanuelmercado Jun 15, 2020
97989cd
feat: register destination. prepare http for fix to clean params
justinemmanuelmercado Jun 15, 2020
3368363
fix: adapt cleanParameters for registerDestination parameters
justinemmanuelmercado Jun 15, 2020
908ecfd
fix: fix parameters registerDestination
justinemmanuelmercado Jun 15, 2020
e87ee0e
Merge branch 'master' of https://github.com/ScaleLeap/amazon-mws-api-…
justinemmanuelmercado Jun 15, 2020
bc61331
Merge branch 'feature/subscriptions-api' of https://github.com/ScaleL…
justinemmanuelmercado Jun 15, 2020
bc50c1b
test: update snapshot
justinemmanuelmercado Jun 15, 2020
78e0aaf
test: deregister destination
justinemmanuelmercado Jun 16, 2020
f71d347
feat: deregister destination
justinemmanuelmercado Jun 16, 2020
8e68cd3
test: list registered destinations
justinemmanuelmercado Jun 16, 2020
dd5a8d1
test: update deregister destination fixture
justinemmanuelmercado Jun 16, 2020
16c44a0
test: fix formatting errors
justinemmanuelmercado Jun 16, 2020
a3d99d0
feat: list registered destinations
justinemmanuelmercado Jun 16, 2020
55e5187
test: send test notification to destination
justinemmanuelmercado Jun 16, 2020
087bf63
feat: send test notification to destination
justinemmanuelmercado Jun 17, 2020
9df2762
test: create subscription test
justinemmanuelmercado Jun 17, 2020
bf9379e
test: create subscription
justinemmanuelmercado Jun 17, 2020
fee1cfa
test: add more complex test to match createSubscription params
justinemmanuelmercado Jun 17, 2020
ccf7ef6
feat: create subscription
justinemmanuelmercado Jun 17, 2020
12d9695
test: get subscription
justinemmanuelmercado Jun 17, 2020
220168b
test: fix get subscription test
justinemmanuelmercado Jun 17, 2020
54d8d20
feat: get subscription
justinemmanuelmercado Jun 17, 2020
45048d8
test: delete_subscription
justinemmanuelmercado Jun 17, 2020
a7ad3c5
feat:delete subscription
justinemmanuelmercado Jun 17, 2020
6774259
test: update subscription
justinemmanuelmercado Jun 17, 2020
bcf8ad5
feat: update subscription
justinemmanuelmercado Jun 17, 2020
cd9346e
fix: lint err
justinemmanuelmercado Jun 17, 2020
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
45 changes: 40 additions & 5 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,25 @@ export interface MWSOptions {
}

type HttpMethod = 'GET' | 'POST'
type ParameterTypes = string | number | (number | string)[] | object[] | boolean | undefined
type ParameterTypes =
| string
| number
| (number | string)[]
| object[]
| boolean
| { [key: string]: ParameterTypes }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better expressed as Record<string, ParameterTypes>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that at first, but it threw Type alias 'ParameterTypes' circularly references itself. and only used the above as a fix. Any reason why { [key: string]: ParameterTypes } won't work?

This is where I got the "fix" microsoft/TypeScript#14174. I didn't read through everything though so there may be something I missed in that issue that might've been a better fix

| undefined

type Parameters = Record<string, ParameterTypes>
type CleanParameters = Record<string, string>

export enum Resource {
Sellers = 'Sellers',
FulfilmentInventory = 'FulfillmentInventory',
Orders = 'Orders',
Products = 'Products',
FulfilmentInventory = 'FulfillmentInventory',
Reports = 'Reports',
Sellers = 'Sellers',
Subscriptions = 'Subscriptions',
}

interface ResourceActions {
Expand Down Expand Up @@ -117,6 +126,17 @@ interface ResourceActions {
| 'GetReportScheduleListByNextToken'
| 'GetReportScheduleCount'
| 'UpdateReportAcknowledgements'
[Resource.Subscriptions]:
| 'RegisterDestination'
| 'DeregisterDestination'
| 'ListRegisteredDestinations'
| 'SendTestNotificationToDestination'
| 'CreateSubscription'
| 'GetSubscription'
| 'DeleteSubscription'
| 'ListSubscriptions'
| 'UpdateSubscription'
| 'GetServiceStatus'
}

interface Request {
Expand Down Expand Up @@ -173,7 +193,15 @@ export const cleanParameters = (parameters: Parameters): CleanParameters =>
Object.entries(parameters)
.filter(([, parameter]) => parameter !== undefined)
.reduce((result, [key, parameter]) => {
if (Array.isArray(parameter)) {
if (typeof parameter === 'string' || !Number.isNaN(Number(parameter))) {
/**
* If parameter is type string or number, assign it to result
*/
Object.assign(result, { [key]: String(parameter) })
} else if (Array.isArray(parameter)) {
/**
* If parameter is type array reduce it to dotnotation
*/
parameter.forEach((parameterChild: string | number | object, index: number) => {
if (typeof parameterChild === 'string' || !Number.isNaN(Number(parameterChild))) {
Object.assign(result, { [`${key}.${index + 1}`]: String(parameterChild) })
Expand All @@ -182,7 +210,14 @@ export const cleanParameters = (parameters: Parameters): CleanParameters =>
}
})
} else {
Object.assign(result, { [key]: String(parameter) })
/**
* If parameter is type object parameterize it
*/
Object.entries(
cleanParameters(parameter as Parameters),
).forEach(([innerKey, innerValue]: [string, string]) =>
Object.assign(result, { [`${key}.${innerKey}`]: innerValue }),
)
}

return result
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './http'
export * from './mws'
export * from './sections/sellers'
export * from './sections/subscriptions'
export * from './sections/orders'
export * from './sections/products/products'
export * from './sections/fulfillment-inventory'
Expand Down
11 changes: 11 additions & 0 deletions src/mws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Orders } from './sections/orders'
import { Products } from './sections/products/products'
import { Reports } from './sections/reports'
import { Sellers } from './sections/sellers'
import { Subscriptions } from './sections/subscriptions'

export class MWS {
private _sellers!: Sellers
Expand All @@ -16,6 +17,8 @@ export class MWS {

private _reports!: Reports

private _subscriptions!: Subscriptions

constructor(private httpClient: HttpClient) {}

get sellers() {
Expand Down Expand Up @@ -57,4 +60,12 @@ export class MWS {

return this._reports
}

get subscriptions() {
if (!this._subscriptions) {
this._subscriptions = new Subscriptions(this.httpClient)
}

return this._subscriptions
}
}
Loading