fix: number parsing regression (#5906)
This commit is contained in:
@@ -31,3 +31,4 @@ export { XHRUploadClient } from './platform/xhr-upload-client'
|
||||
export { clearNodeAuthState, nodeAuthState, setNodeAuthState } from './state/node-auth'
|
||||
export * from './types'
|
||||
export { withJWTRetry } from './utils/jwt-retry'
|
||||
export type { Override, RawDecimal } from './utils/types'
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
import { AbstractModule } from '../../../core/abstract-module'
|
||||
import type { Override, RawDecimal } from '../../../utils/types'
|
||||
import type { Labrinth } from '../types'
|
||||
|
||||
type RawPayoutBalance = Override<
|
||||
Labrinth.Payout.v3.PayoutBalance,
|
||||
{
|
||||
available: RawDecimal
|
||||
withdrawn_lifetime: RawDecimal
|
||||
withdrawn_ytd: RawDecimal
|
||||
pending: RawDecimal
|
||||
dates: Record<string, RawDecimal>
|
||||
}
|
||||
>
|
||||
|
||||
type RawTransactionItem =
|
||||
| Override<
|
||||
Extract<Labrinth.Payout.v3.TransactionItem, { type: 'withdrawal' }>,
|
||||
{
|
||||
amount: RawDecimal
|
||||
fee: RawDecimal | null
|
||||
}
|
||||
>
|
||||
| Override<
|
||||
Extract<Labrinth.Payout.v3.TransactionItem, { type: 'payout_available' }>,
|
||||
{
|
||||
amount: RawDecimal
|
||||
}
|
||||
>
|
||||
|
||||
export class LabrinthPayoutV3Module extends AbstractModule {
|
||||
public getModuleID(): string {
|
||||
return 'labrinth_payout_v3'
|
||||
@@ -12,11 +39,22 @@ export class LabrinthPayoutV3Module extends AbstractModule {
|
||||
* @returns Promise resolving to the user's payout balance
|
||||
*/
|
||||
public async getBalance(): Promise<Labrinth.Payout.v3.PayoutBalance> {
|
||||
return this.client.request<Labrinth.Payout.v3.PayoutBalance>('/payout/balance', {
|
||||
const balance = await this.client.request<RawPayoutBalance>('/payout/balance', {
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
return {
|
||||
...balance,
|
||||
available: Number(balance.available),
|
||||
withdrawn_lifetime: Number(balance.withdrawn_lifetime),
|
||||
withdrawn_ytd: Number(balance.withdrawn_ytd),
|
||||
pending: Number(balance.pending),
|
||||
dates: Object.fromEntries(
|
||||
Object.entries(balance.dates).map(([date, amount]) => [date, Number(amount)]),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,11 +63,26 @@ export class LabrinthPayoutV3Module extends AbstractModule {
|
||||
* @returns Promise resolving to an array of transaction items
|
||||
*/
|
||||
public async getHistory(): Promise<Labrinth.Payout.v3.TransactionItem[]> {
|
||||
return this.client.request<Labrinth.Payout.v3.TransactionItem[]>('/payout/history', {
|
||||
const history = await this.client.request<RawTransactionItem[]>('/payout/history', {
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
return history.map((transaction) => {
|
||||
if (transaction.type === 'withdrawal') {
|
||||
return {
|
||||
...transaction,
|
||||
amount: Number(transaction.amount),
|
||||
fee: transaction.fee === null ? null : Number(transaction.fee),
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...transaction,
|
||||
amount: Number(transaction.amount),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
2
packages/api-client/src/utils/types.ts
Normal file
2
packages/api-client/src/utils/types.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export type Override<T, R> = Omit<T, keyof R> & R
|
||||
export type RawDecimal = string | number
|
||||
Reference in New Issue
Block a user