@donation-alerts/api
Version:
Interact with Donation Alerts API.
111 lines (110 loc) • 3.21 kB
JavaScript
import { __decorate } from "tslib";
import { DataObject, rawDataSymbol, ReadDocumentation, } from '@donation-alerts/common';
import { mapNullable } from '@stimulcross/shared-utils';
/**
* Represents a donation received through Donation Alerts.
*
* @remarks
* This class provides detailed information about a donation, including user details, donation amount, message,
* currency, and timestamps for creation and display.
*/
let DonationAlertsDonation = class DonationAlertsDonation extends DataObject {
/**
* The unique identifier for the donation alert.
*/
get id() {
return this[rawDataSymbol].id;
}
/**
* The type of the alert.
*
* @remarks
* Always returns `Donations` in this context.
*/
get name() {
return this[rawDataSymbol].name;
}
/**
* The username of the donor.
*
* @remarks
* This is the name that the user who sent the donation chose to display publicly.
*/
get username() {
return this[rawDataSymbol].username;
}
/**
* The type of the message accompanying the donation.
*
* @remarks
* Possible values:
* - `text` — A plain text message sent with the donation.
* - `audio` — A message that includes an audio component.
*/
get messageType() {
return this[rawDataSymbol].message_type;
}
/**
* The message sent by the donor along with the donation.
*/
get message() {
return this[rawDataSymbol].message;
}
/**
* The donated amount.
*/
get amount() {
return this[rawDataSymbol].amount;
}
/**
* The currency of the donated amount.
*
* @remarks
* This value represents the currency code in ISO 4217 format (e.g., `USD`, `EUR`, `RUB`).
*/
get currency() {
return this[rawDataSymbol].currency;
}
/**
* Indicates whether the alert was shown in the streamer's widget.
*
* @returns `true` if the donation alert has been displayed; otherwise, `false`.
*/
get isShown() {
return this[rawDataSymbol].is_shown === 1;
}
/**
* The date and time when the donation was received.
*
* @returns A `Date` object representing the donation creation time.
*/
get creationDate() {
return new Date(this[rawDataSymbol].created_at);
}
/**
* The date and time when the alert was shown on the streamer's widget.
*
* @returns A `Date` object if the alert was shown; `null` otherwise.
*/
get showDate() {
return mapNullable(this[rawDataSymbol].shown_at, (v) => new Date(v));
}
toJSON() {
return {
id: this.id,
name: this.name,
username: this.username,
messageType: this.messageType,
message: this.message,
amount: this.amount,
currency: this.currency,
isShown: this.isShown,
creationDate: this.creationDate,
showDate: this.showDate,
};
}
};
DonationAlertsDonation = __decorate([
ReadDocumentation('api')
], DonationAlertsDonation);
export { DonationAlertsDonation };