fix: number parsing regression (#5906)

This commit is contained in:
Calum H.
2026-04-24 19:39:30 +01:00
committed by GitHub
parent e3d6a498d0
commit faf593b2af
3 changed files with 58 additions and 2 deletions

View File

@@ -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),
}
})
}
/**