@donation-alerts/api
Version:
Interact with Donation Alerts API.
144 lines (143 loc) • 4.57 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DonationAlertsMerchandiseSale = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@donation-alerts/common");
const shared_utils_1 = require("@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 common_1.DataObject {
/**
* The unique identifier for the merchandise sale alert, assigned by Donation Alerts.
*
* @returns The alert ID as a number.
*/
get id() {
return this[common_1.rawDataSymbol].id;
}
/**
* Type of the generated alert.
*
* @returns A string representing the alert type, e.g., `'merchandise-sale'`.
*/
get name() {
return this[common_1.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[common_1.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[common_1.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[common_1.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[common_1.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[common_1.rawDataSymbol].currency;
}
/**
* Total number of bought items.
*
* @returns The number of purchased items as a number.
*/
get boughtAmount() {
return this[common_1.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[common_1.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[common_1.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 (0, shared_utils_1.mapNullable)(this[common_1.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,
};
}
};
exports.DonationAlertsMerchandiseSale = DonationAlertsMerchandiseSale;
exports.DonationAlertsMerchandiseSale = DonationAlertsMerchandiseSale = tslib_1.__decorate([
(0, common_1.ReadDocumentation)('api')
], DonationAlertsMerchandiseSale);