@donation-alerts/api
Version:
Interact with Donation Alerts API.
169 lines (168 loc) • 5.3 kB
JavaScript
import { __decorate } from "tslib";
import { DataObject, rawDataSymbol, ReadDocumentation, } from '@donation-alerts/common';
import { mapNullable } from '@stimulcross/shared-utils';
import { Memoize } from 'typescript-memoize';
import { DonationAlertsMerchandiseMerchant, } from "./donation-alerts-merchandise-merchant.mjs";
/**
* 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 DataObject {
/**
* Unique merchandise ID on Donation Alerts.
*/
get id() {
return this[rawDataSymbol].id;
}
/**
* Information about the merchant associated with the merchandise.
*
* @returns An instance of {@link DonationAlertsMerchandiseMerchant} containing merchant details.
*/
get merchant() {
return new DonationAlertsMerchandiseMerchant(this[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[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[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[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[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[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[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[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[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[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 mapNullable(this[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,
};
}
};
__decorate([
Memoize()
], DonationAlertsMerchandise.prototype, "merchant", null);
DonationAlertsMerchandise = __decorate([
ReadDocumentation('api')
], DonationAlertsMerchandise);
export { DonationAlertsMerchandise };