@donation-alerts/api
Version:
Interact with Donation Alerts API.
141 lines (140 loc) • 4.26 kB
JavaScript
import { __decorate } from "tslib";
import { DataObject, rawDataSymbol, ReadDocumentation, } from '@donation-alerts/common';
import { mapNullable } from '@stimulcross/shared-utils';
/**
* Represents Donation Alerts merchandise sale alert.
*
* @remarks
* This class provides detailed information about merchandise sale alerts
* generated on the Donation Alerts platform. It includes information about
* the alert type, customer, amount of the sale, currency, and whether the alert
* was displayed in the streamer's widget.
*/
let DonationAlertsMerchandiseSale = class DonationAlertsMerchandiseSale extends DataObject {
/**
* The unique identifier for the merchandise sale alert, assigned by Donation Alerts.
*
* @returns The alert ID as a number.
*/
get id() {
return this[rawDataSymbol].id;
}
/**
* Type of the generated alert.
*
* @returns A string representing the alert type, e.g., `'merchandise-sale'`.
*/
get name() {
return this[rawDataSymbol].name;
}
/**
* Unique sale ID generated by the developer.
*
* @remarks
* This ID helps developers associate a sale in Donation Alerts with their own
* internal records or database.
*
* @returns The external sale ID as a string.
*/
get externalId() {
return this[rawDataSymbol].external_id;
}
/**
* The username of the customer who purchased the merchandise.
*
* @remarks
* If the customer's name is not available, `null` is returned.
*
* @returns The customer's username as a string, or `null` if unknown.
*/
get username() {
return this[rawDataSymbol].username;
}
/**
* The message sent by the customer while purchasing the merchandise.
*
* @remarks
* If the message is not provided, `null` is returned.
*
* @returns The customer's message as a string, or `null` if not provided.
*/
get message() {
return this[rawDataSymbol].message;
}
/**
* Grand total amount of the sale.
*
* @remarks
* Total value of the merchandise sale, including all included items.
*
* @returns The total sale amount as a number.
*/
get amount() {
return this[rawDataSymbol].amount;
}
/**
* The currency of the merchandise sale.
*
* @remarks
* Currency code (ISO 4217) representing the currency in which the sale was made.
*
* @returns A string representing the currency code.
*/
get currency() {
return this[rawDataSymbol].currency;
}
/**
* Total number of bought items.
*
* @returns The number of purchased items as a number.
*/
get boughtAmount() {
return this[rawDataSymbol].bought_amount;
}
/**
* Whether the alert was shown in the streamer's widget.
*
* @returns `true` if the alert was shown; otherwise, `false`.
*/
get isShown() {
return this[rawDataSymbol].is_shown === 1;
}
/**
* The date and time when the sale alert was created.
*
* @returns A `Date` object representing the creation date of the sale alert.
*/
get creationDate() {
return new Date(this[rawDataSymbol].created_at);
}
/**
* The date and time when the alert was shown.
*
* @remarks
* If the alert hasn't been shown yet, `null` is returned.
*
* @returns A `Date` object representing the time the alert was shown, or `null`.
*/
get showDate() {
return mapNullable(this[rawDataSymbol].shown_at, (v) => new Date(v));
}
toJSON() {
return {
id: this.id,
name: this.name,
externalId: this.externalId,
username: this.username,
message: this.message,
amount: this.amount,
currency: this.currency,
boughtAmount: this.boughtAmount,
creationDate: this.creationDate,
isShown: this.isShown,
showDate: this.showDate,
};
}
};
DonationAlertsMerchandiseSale = __decorate([
ReadDocumentation('api')
], DonationAlertsMerchandiseSale);
export { DonationAlertsMerchandiseSale };