258 lines
8.8 KiB
TypeScript
258 lines
8.8 KiB
TypeScript
// Metro module 4228 (f4229).
|
|
import Record from "../../lib/Record";
|
|
import ApplicationRecord from "../../records/ApplicationRecord";
|
|
import { THE_GAME_AWARD_WINNER_SKUS } from "./SKUConstants";
|
|
import { GIFTABLE_CURRENCIES, OperatingSystems, SKUFlags, SKUTypes } from "../../Constants";
|
|
import Module3771 from "../../_bundle/Module3771";
|
|
import getPricesFromServer from "./utils/getPricesFromServer";
|
|
import transformSKUTenantMetadata from "./utils/transformSKUTenantMetadata";
|
|
import { hasFlag } from "../../_bundle/Module1384";
|
|
class SKURecord extends Record {
|
|
constructor(a0) {
|
|
super();
|
|
this.id = a0.id;
|
|
this.type = a0.type;
|
|
this.applicationId = a0.applicationId;
|
|
this.application = a0.application;
|
|
this.eligiblePaymentGateways = a0.eligiblePaymentGateways;
|
|
this.googleSkuIds = a0.googleSkuIds;
|
|
this.productLine = a0.productLine;
|
|
this.name = a0.name;
|
|
this.preorderReleaseAt = a0.preorderReleaseAt;
|
|
this.preorderApproximateReleaseDate = a0.preorderApproximateReleaseDate;
|
|
this.releaseDate = a0.releaseDate;
|
|
this.summary = a0.summary;
|
|
this.features = a0.features;
|
|
this.genres = a0.genres;
|
|
this.dependentSkuId = a0.dependentSkuId;
|
|
this.manifests = a0.manifests;
|
|
this.availableRegions = a0.availableRegions;
|
|
this.accessType = a0.accessType;
|
|
this.systemRequirements = a0.systemRequirements;
|
|
this.contentRating = a0.contentRating;
|
|
this.contentRatingAgency = a0.contentRatingAgency;
|
|
this.legalNotice = a0.legalNotice;
|
|
this.price = a0.price;
|
|
this.prices = a0.prices;
|
|
this.premium = a0.premium;
|
|
this.showAgeGate = a0.showAgeGate;
|
|
this.restricted = a0.restricted;
|
|
this.slug = a0.slug;
|
|
this.exclusive = a0.exclusive;
|
|
this.locales = a0.locales;
|
|
this.flags = a0.flags;
|
|
this.externalPurchaseUrl = a0.externalPurchaseUrl || null;
|
|
this.deleted = a0.deleted;
|
|
this.bundledSkuIds = a0.bundledSkuIds;
|
|
this.bundledSkus = a0.bundledSkus;
|
|
this.tenantMetadata = a0.tenantMetadata;
|
|
this.selectedOptions = a0.selectedOptions;
|
|
this.productId = a0.productId;
|
|
this.thumbnailAssetId = a0.thumbnailAssetId;
|
|
this.description = a0.description;
|
|
this.orbsReward = a0.orbsReward;
|
|
this.eligibleOffers = a0.eligibleOffers;
|
|
this.previewAssetPaths = a0.previewAssetPaths;
|
|
}
|
|
static createFromServer(a0) {
|
|
const price = a0.price;
|
|
const application = a0.application != null ? ApplicationRecord.createFromServer(a0.application) : null;
|
|
let eligible_payment_gateways = a0.eligible_payment_gateways;
|
|
if (eligible_payment_gateways == null) {
|
|
eligible_payment_gateways = null;
|
|
}
|
|
let google_sku_ids = a0.google_sku_ids;
|
|
if (google_sku_ids == null) {
|
|
google_sku_ids = null;
|
|
}
|
|
let name = a0.name;
|
|
if (name == null) {
|
|
name = "";
|
|
}
|
|
const r2 = {
|
|
id: a0.id,
|
|
type: a0.type,
|
|
applicationId: a0.application_id,
|
|
application,
|
|
eligiblePaymentGateways: eligible_payment_gateways,
|
|
googleSkuIds: google_sku_ids,
|
|
productLine: a0.product_line,
|
|
name,
|
|
releaseDate: a0.release_date != null ? Module3771(a0.release_date) : null,
|
|
preorderReleaseAt: a0.preorder_release_at != null ? Module3771(a0.preorder_release_at) : null,
|
|
preorderApproximateReleaseDate: a0.preorder_approximate_release_date,
|
|
summary: a0.summary,
|
|
features: new Set(a0.features),
|
|
genres: new Set(a0.genres),
|
|
dependentSkuId: a0.dependent_sku_id,
|
|
manifests: a0.manifests,
|
|
availableRegions: a0.available_regions,
|
|
accessType: a0.access_type,
|
|
systemRequirements: a0.system_requirements,
|
|
contentRating: a0.content_rating,
|
|
contentRatingAgency: a0.content_rating_agency,
|
|
legalNotice: a0.legal_notice,
|
|
price: price != null ? {
|
|
amount: price.amount,
|
|
currency: price.currency,
|
|
saleAmount: price.sale_amount,
|
|
salePercentage: price.sale_percentage,
|
|
premium: price.premium
|
|
} : null,
|
|
prices: getPricesFromServer(a0.prices),
|
|
premium: null,
|
|
showAgeGate: null,
|
|
restricted: null,
|
|
slug: null,
|
|
exclusive: null,
|
|
locales: null,
|
|
flags: null,
|
|
externalPurchaseUrl: null,
|
|
deleted: null,
|
|
bundledSkuIds: null,
|
|
bundledSkus: null,
|
|
tenantMetadata: null,
|
|
selectedOptions: null,
|
|
productId: null,
|
|
thumbnailAssetId: null,
|
|
description: null,
|
|
orbsReward: null,
|
|
eligibleOffers: null,
|
|
previewAssetPaths: null
|
|
};
|
|
let premium = a0.premium;
|
|
if (premium == null) {
|
|
premium = false;
|
|
}
|
|
r2.premium = premium;
|
|
r2.showAgeGate = a0.show_age_gate || false;
|
|
r2.restricted = a0.restricted || false;
|
|
let slug = a0.slug;
|
|
if (slug == null) {
|
|
slug = "";
|
|
}
|
|
r2.slug = slug;
|
|
r2.exclusive = a0.exclusive || false;
|
|
let locales = a0.locales;
|
|
if (locales == null) {
|
|
locales = ["en-US"];
|
|
}
|
|
r2.locales = locales;
|
|
r2.flags = a0.flags;
|
|
r2.externalPurchaseUrl = a0.external_purchase_url;
|
|
let deleted = a0.deleted;
|
|
if (deleted == null) {
|
|
deleted = false;
|
|
}
|
|
r2.deleted = deleted;
|
|
let bundled_sku_ids = a0.bundled_sku_ids;
|
|
if (bundled_sku_ids == null) {
|
|
bundled_sku_ids = [];
|
|
}
|
|
r2.bundledSkuIds = bundled_sku_ids;
|
|
const bundled_skus = a0.bundled_skus;
|
|
let bundledSkus = bundled_skus == null ? void 0 : bundled_skus.map((bundled_sku) => SKURecord.createFromServer(bundled_sku));
|
|
if (bundledSkus == null) {
|
|
bundledSkus = [];
|
|
}
|
|
r2.bundledSkus = bundledSkus;
|
|
r2.tenantMetadata = transformSKUTenantMetadata(a0.tenant_metadata);
|
|
const selected_options = a0.selected_options;
|
|
let selectedOptions = selected_options == null ? void 0 : selected_options.map((selected_option) => ({
|
|
optionName: selected_option.option_name,
|
|
optionValue: selected_option.option_value
|
|
}));
|
|
if (selectedOptions == null) {
|
|
selectedOptions = [];
|
|
}
|
|
r2.selectedOptions = selectedOptions;
|
|
r2.productId = a0.product_id;
|
|
r2.thumbnailAssetId = a0.thumbnail_asset_id;
|
|
r2.description = a0.description;
|
|
r2.orbsReward = a0.orbs_reward;
|
|
let eligible_offers = a0.eligible_offers;
|
|
if (eligible_offers == null) {
|
|
eligible_offers = [];
|
|
}
|
|
r2.eligibleOffers = eligible_offers;
|
|
r2.previewAssetPaths = a0.preview_asset_paths != null ? {
|
|
fgStatic: a0.preview_asset_paths.fg_static,
|
|
fgAnimated: a0.preview_asset_paths.fg_animated,
|
|
bgStatic: a0.preview_asset_paths.bg_static,
|
|
bgAnimated: a0.preview_asset_paths.bg_animated
|
|
} : null;
|
|
return new SKURecord(r2);
|
|
}
|
|
get supportedOperatingSystems() {
|
|
let r6 = this.systemRequirements != null ? Object.keys(this.systemRequirements) : [];
|
|
if (!(r6.length > 0)) {
|
|
r6 = [OperatingSystems.WINDOWS];
|
|
}
|
|
return r6;
|
|
}
|
|
get isOnSale() {
|
|
return this.price != null && this.price.saleAmount != null;
|
|
}
|
|
isGiftable(r3 = this.price) {
|
|
return this.type === SKUTypes.DURABLE_PRIMARY && this.available && this.requiresPayment && r3 != null && GIFTABLE_CURRENCIES.has(r3.currency) && this.externalPurchaseUrl == null;
|
|
}
|
|
getPrice(r6 = null, r2 = true) {
|
|
const price = this.price;
|
|
if (price == null) {
|
|
return null;
|
|
}
|
|
if (r6 != null) {
|
|
const premium = price.premium;
|
|
const r8 = premium == null ? void 0 : premium[r6];
|
|
if (r8 != null) {
|
|
return {
|
|
amount: r8.amount,
|
|
currency: price.currency
|
|
};
|
|
}
|
|
}
|
|
return r2 && price.saleAmount != null ? {
|
|
amount: price.saleAmount,
|
|
currency: price.currency
|
|
} : {
|
|
amount: price.amount,
|
|
currency: price.currency
|
|
};
|
|
}
|
|
getDisplaySalePercentage() {
|
|
return this.price == null ? null : this.price.salePercentage == null ? null : `-${this.price.salePercentage}%`;
|
|
}
|
|
get requiresPayment() {
|
|
const price = this.getPrice();
|
|
const premium = this.premium;
|
|
return (premium ? !premium : price != null) && price.amount > 0;
|
|
}
|
|
get isTheGameAwardsWinner() {
|
|
return THE_GAME_AWARD_WINNER_SKUS.has(this.id);
|
|
}
|
|
get available() {
|
|
return hasFlag(this.flags, SKUFlags.AVAILABLE) || this.externalPurchaseUrl != null;
|
|
}
|
|
isAvailableForDistribution() {
|
|
let r1 = this.available && this.getPrice() != null && this.externalPurchaseUrl == null;
|
|
if (r1) {
|
|
const premium = this.premium;
|
|
r1 = premium ? hasFlag(this.flags, SKUFlags.PREMIUM_AND_DISTRIBUTION) : !premium;
|
|
}
|
|
return r1;
|
|
}
|
|
isAvailable() {
|
|
return hasFlag(this.flags, SKUFlags.AVAILABLE);
|
|
}
|
|
isPremiumPerk() {
|
|
return this.premium && (hasFlag(this.flags, SKUFlags.PREMIUM_PURCHASE) || hasFlag(this.flags, SKUFlags.PREMIUM_AND_DISTRIBUTION));
|
|
}
|
|
hasFeature(a0) {
|
|
return this.features.has(a0);
|
|
}
|
|
isPreorder() {
|
|
return this.preorderReleaseAt != null || this.preorderApproximateReleaseDate != null;
|
|
}
|
|
}
|
|
export default SKURecord;
|