@donation-alerts/api
Version:
Interact with Donation Alerts API.
172 lines (171 loc) • 5.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DonationAlertsMerchandise = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@donation-alerts/common");
const shared_utils_1 = require("@stimulcross/shared-utils");
const typescript_memoize_1 = require("typescript-memoize");
const donation_alerts_merchandise_merchant_1 = require("./donation-alerts-merchandise-merchant");
/**
* Represents Donation Alerts merchandise.
*
* @remarks
* This class provides detailed information about Donation Alerts merchandise items, such as
* the associated merchant, pricing details, availability status, and localized titles.
* It parses and exposes raw data provided by the Donation Alerts API for ease of use.
*/
let DonationAlertsMerchandise = class DonationAlertsMerchandise extends common_1.DataObject {
/**
* Unique merchandise ID on Donation Alerts.
*/
get id() {
return this[common_1.rawDataSymbol].id;
}
/**
* Information about the merchant associated with the merchandise.
*
* @returns An instance of {@link DonationAlertsMerchandiseMerchant} containing merchant details.
*/
get merchant() {
return new donation_alerts_merchandise_merchant_1.DonationAlertsMerchandiseMerchant(this[common_1.rawDataSymbol].merchant);
}
/**
* Unique ID of the merchandise on the merchant's platform.
*
* @remarks
* This identifier is set by the merchant and is unique to their platform or online store.
*
* @returns The merchant's unique merchandise ID as a string.
*/
get identifier() {
return this[common_1.rawDataSymbol].identifier;
}
/**
* Merchandise titles in different locales.
*
* @remarks
* Provides titles for the merchandise across supported locales, including a mandatory
* `en_US` title field.
*
* @returns A {@link DonationAlertsMerchandiseTitleData} object containing localized titles for the merchandise
* as values.
*/
get title() {
return this[common_1.rawDataSymbol].title;
}
/**
* Availability status of the merchandise.
*
* @remarks
* Indicates whether the merchandise is active and available for purchase.
*
* @returns `true` if the merchandise is active; otherwise `false`.
*/
get isActive() {
return this[common_1.rawDataSymbol].is_active === 1;
}
/**
* Pricing mode for the merchandise.
*
* @remarks
* Indicates whether the revenue (`priceUser` and `priceService`)
* is calculated as an absolute amount or a percentage of the total.
*
* @returns `true` if pricing is percentage-based; otherwise `false`.
*/
get isPercentage() {
return this[common_1.rawDataSymbol].is_percentage === 1;
}
/**
* The currency used for merchandise prices.
*
* @remarks
* Provides the ISO 4217-formatted currency code for the merchandise prices.
*
* @returns The currency code as a string.
*/
get currency() {
return this[common_1.rawDataSymbol].currency;
}
/**
* Revenue added to the streamer for each sale of the merchandise.
*
* @remarks
* Shows the amount of money the streamer earns from each sale of the merchandise.
*
* @returns The revenue amount as a number.
*/
get priceUser() {
return this[common_1.rawDataSymbol].price_user;
}
/**
* Revenue added to Donation Alerts for each sale of the merchandise.
*
* @remarks
* Reflects the commission or revenue that Donation Alerts earns per sale.
*
* @returns The revenue amount as a number.
*/
get priceService() {
return this[common_1.rawDataSymbol].price_service;
}
/**
* URL to the merchandise's web page.
*
* @remarks
* If the merchandise does not have a web page, `null` is returned.
*
* @returns The URL as a string, or `null` if not set.
*/
get url() {
return this[common_1.rawDataSymbol].url;
}
/**
* URL to the merchandise's image.
*
* @remarks
* If no image is set, `null` is returned.
*
* @returns The URL to the image as a string, or `null` if not set.
*/
get imageUrl() {
return this[common_1.rawDataSymbol].img_url;
}
/**
* Merchandising end date.
*
* @remarks
* The date and time at which the merchandise becomes inactive and
* unavailable for purchase.
*
* If no end date is set, `null` is returned.
*
* @returns A `Date` object indicating the end date, or `null` if not set.
*/
get endDate() {
return (0, shared_utils_1.mapNullable)(this[common_1.rawDataSymbol].end_at, (v) => new Date(v));
}
toJSON() {
return {
id: this.id,
merchant: this.merchant.toJSON(),
identifier: this.identifier,
title: this.title,
isActive: this.isActive,
isPercentage: this.isPercentage,
currency: this.currency,
priceUser: this.priceUser,
priceService: this.priceService,
url: this.url,
imageUrl: this.imageUrl,
endDate: this.endDate,
};
}
};
exports.DonationAlertsMerchandise = DonationAlertsMerchandise;
tslib_1.__decorate([
(0, typescript_memoize_1.Memoize)()
], DonationAlertsMerchandise.prototype, "merchant", null);
exports.DonationAlertsMerchandise = DonationAlertsMerchandise = tslib_1.__decorate([
(0, common_1.ReadDocumentation)('api')
], DonationAlertsMerchandise);