@donation-alerts/api
Version:
Interact with Donation Alerts API.
114 lines (113 loc) • 3.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DonationAlertsDonation = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@donation-alerts/common");
const shared_utils_1 = require("@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 common_1.DataObject {
/**
* The unique identifier for the donation alert.
*/
get id() {
return this[common_1.rawDataSymbol].id;
}
/**
* The type of the alert.
*
* @remarks
* Always returns `Donations` in this context.
*/
get name() {
return this[common_1.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[common_1.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[common_1.rawDataSymbol].message_type;
}
/**
* The message sent by the donor along with the donation.
*/
get message() {
return this[common_1.rawDataSymbol].message;
}
/**
* The donated amount.
*/
get amount() {
return this[common_1.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[common_1.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[common_1.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[common_1.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 (0, shared_utils_1.mapNullable)(this[common_1.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,
};
}
};
exports.DonationAlertsDonation = DonationAlertsDonation;
exports.DonationAlertsDonation = DonationAlertsDonation = tslib_1.__decorate([
(0, common_1.ReadDocumentation)('api')
], DonationAlertsDonation);