@qonversion/capacitor-plugin
Version:
Qonversion provides full in-app purchases infrastructure, so you do not need to build your own server for receipt validation. Implement in-app subscriptions, validate user receipts, check subscription status, and provide access to your app features and co
1,085 lines (1,052 loc) • 111 kB
JavaScript
var capacitorQonversion = (function (exports, core) {
'use strict';
exports.LaunchMode = void 0;
(function (LaunchMode) {
LaunchMode["ANALYTICS"] = "Analytics";
LaunchMode["SUBSCRIPTION_MANAGEMENT"] = "SubscriptionManagement";
})(exports.LaunchMode || (exports.LaunchMode = {}));
exports.Environment = void 0;
(function (Environment) {
Environment["SANDBOX"] = "Sandbox";
Environment["PRODUCTION"] = "Production";
})(exports.Environment || (exports.Environment = {}));
exports.ProductType = void 0;
(function (ProductType) {
ProductType["TRIAL"] = "Trial";
ProductType["INTRO"] = "Intro";
ProductType["SUBSCRIPTION"] = "Subscription";
ProductType["IN_APP"] = "InApp";
ProductType["UNKNOWN"] = "Unknown";
})(exports.ProductType || (exports.ProductType = {}));
exports.SubscriptionPeriodUnit = void 0;
(function (SubscriptionPeriodUnit) {
SubscriptionPeriodUnit["DAY"] = "Day";
SubscriptionPeriodUnit["WEEK"] = "Week";
SubscriptionPeriodUnit["MONTH"] = "Month";
SubscriptionPeriodUnit["YEAR"] = "Year";
SubscriptionPeriodUnit["UNKNOWN"] = "Unknown";
})(exports.SubscriptionPeriodUnit || (exports.SubscriptionPeriodUnit = {}));
/**
* Recurrence mode of the pricing phase.
*/
exports.PricingPhaseRecurrenceMode = void 0;
(function (PricingPhaseRecurrenceMode) {
/**
* The billing plan payment recurs for infinite billing periods unless canceled.
*/
PricingPhaseRecurrenceMode["INFINITE_RECURRING"] = "InfiniteRecurring";
/**
* The billing plan payment recurs for a fixed number of billing periods
* set in {@link ProductPricingPhase.billingCycleCount}.
*/
PricingPhaseRecurrenceMode["FINITE_RECURRING"] = "FiniteRecurring";
/**
* The billing plan payment is a one-time charge that does not repeat.
*/
PricingPhaseRecurrenceMode["NON_RECURRING"] = "NonRecurring";
/**
* Unknown recurrence mode.
*/
PricingPhaseRecurrenceMode["UNKNOWN"] = "Unknown";
})(exports.PricingPhaseRecurrenceMode || (exports.PricingPhaseRecurrenceMode = {}));
/**
* Type of the pricing phase.
*/
exports.PricingPhaseType = void 0;
(function (PricingPhaseType) {
/**
* Regular subscription without any discounts like trial or intro offers.
*/
PricingPhaseType["REGULAR"] = "Regular";
/**
* A free phase.
*/
PricingPhaseType["FREE_TRIAL"] = "FreeTrial";
/**
* A phase with a discounted payment for a single period.
*/
PricingPhaseType["DISCOUNTED_SINGLE_PAYMENT"] = "DiscountedSinglePayment";
/**
* A phase with a discounted payment for several periods, described in {@link ProductPricingPhase.billingCycleCount}.
*/
PricingPhaseType["DISCOUNTED_RECURRING_PAYMENT"] = "DiscountedRecurringPayment";
/**
* Unknown pricing phase type.
*/
PricingPhaseType["UNKNOWN"] = "Unknown";
})(exports.PricingPhaseType || (exports.PricingPhaseType = {}));
exports.EntitlementRenewState = void 0;
(function (EntitlementRenewState) {
EntitlementRenewState["NON_RENEWABLE"] = "non_renewable";
EntitlementRenewState["UNKNOWN"] = "unknown";
EntitlementRenewState["WILL_RENEW"] = "will_renew";
EntitlementRenewState["CANCELED"] = "canceled";
EntitlementRenewState["BILLING_ISSUE"] = "billing_issue";
})(exports.EntitlementRenewState || (exports.EntitlementRenewState = {}));
exports.EntitlementSource = void 0;
(function (EntitlementSource) {
EntitlementSource["UNKNOWN"] = "Unknown";
EntitlementSource["APP_STORE"] = "AppStore";
EntitlementSource["PLAY_STORE"] = "PlayStore";
EntitlementSource["STRIPE"] = "Stripe";
EntitlementSource["MANUAL"] = "Manual";
})(exports.EntitlementSource || (exports.EntitlementSource = {}));
exports.TransactionEnvironment = void 0;
(function (TransactionEnvironment) {
TransactionEnvironment["PRODUCTION"] = "Production";
TransactionEnvironment["SANDBOX"] = "Sandbox";
})(exports.TransactionEnvironment || (exports.TransactionEnvironment = {}));
exports.TransactionOwnershipType = void 0;
(function (TransactionOwnershipType) {
TransactionOwnershipType["OWNER"] = "Owner";
TransactionOwnershipType["FAMILY_SHARING"] = "FamilySharing";
})(exports.TransactionOwnershipType || (exports.TransactionOwnershipType = {}));
exports.EntitlementGrantType = void 0;
(function (EntitlementGrantType) {
EntitlementGrantType["PURCHASE"] = "Purchase";
EntitlementGrantType["FAMILY_SHARING"] = "FamilySharing";
EntitlementGrantType["OFFER_CODE"] = "OfferCode";
EntitlementGrantType["MANUAL"] = "Manual";
})(exports.EntitlementGrantType || (exports.EntitlementGrantType = {}));
exports.TransactionType = void 0;
(function (TransactionType) {
TransactionType["UNKNOWN"] = "Unknown";
TransactionType["SUBSCRIPTION_STARTED"] = "SubscriptionStarted";
TransactionType["SUBSCRIPTION_RENEWED"] = "SubscriptionRenewed";
TransactionType["TRIAL_STARTED"] = "TrialStarted";
TransactionType["INTRO_STARTED"] = "IntroStarted";
TransactionType["INTRO_RENEWED"] = "IntroRenewed";
TransactionType["NON_CONSUMABLE_PURCHASE"] = "NonConsumablePurchase";
})(exports.TransactionType || (exports.TransactionType = {}));
exports.UserPropertyKey = void 0;
(function (UserPropertyKey) {
UserPropertyKey["EMAIL"] = "Email";
UserPropertyKey["NAME"] = "Name";
UserPropertyKey["KOCHAVA_DEVICE_ID"] = "KochavaDeviceId";
UserPropertyKey["APPS_FLYER_USER_ID"] = "AppsFlyerUserId";
UserPropertyKey["ADJUST_AD_ID"] = "AdjustAdId";
UserPropertyKey["CUSTOM_USER_ID"] = "CustomUserId";
UserPropertyKey["FACEBOOK_ATTRIBUTION"] = "FacebookAttribution";
UserPropertyKey["FIREBASE_APP_INSTANCE_ID"] = "FirebaseAppInstanceId";
UserPropertyKey["APP_SET_ID"] = "AppSetId";
UserPropertyKey["ADVERTISING_ID"] = "AdvertisingId";
UserPropertyKey["APP_METRICA_DEVICE_ID"] = "AppMetricaDeviceId";
UserPropertyKey["APP_METRICA_USER_PROFILE_ID"] = "AppMetricaUserProfileId";
UserPropertyKey["PUSH_WOOSH_HW_ID"] = "PushWooshHwId";
UserPropertyKey["PUSH_WOOSH_USER_ID"] = "PushWooshUserId";
UserPropertyKey["TENJIN_ANALYTICS_INSTALLATION_ID"] = "TenjinAnalyticsInstallationId";
UserPropertyKey["CUSTOM"] = "Custom";
})(exports.UserPropertyKey || (exports.UserPropertyKey = {}));
exports.AttributionProvider = void 0;
(function (AttributionProvider) {
AttributionProvider["APPSFLYER"] = "AppsFlyer";
AttributionProvider["BRANCH"] = "Branch";
AttributionProvider["ADJUST"] = "Adjust";
AttributionProvider["APPLE_SEARCH_ADS"] = "AppleSearchAds";
AttributionProvider["APPLE_AD_SERVICES"] = "AppleAdServices";
})(exports.AttributionProvider || (exports.AttributionProvider = {}));
/**
* A policy used for purchase updates on Android, which describes
* how to migrate from purchased plan to a new one.
*
* Used in {@link PurchaseOptions} class for purchase updates.
*/
exports.PurchaseUpdatePolicy = void 0;
(function (PurchaseUpdatePolicy) {
/**
* The new plan takes effect immediately, and the user is charged full price of new plan
* and is given a full billing cycle of subscription, plus remaining prorated time
* from the old plan.
*/
PurchaseUpdatePolicy["CHARGE_FULL_PRICE"] = "ChargeFullPrice";
/**
* The new plan takes effect immediately, and the billing cycle remains the same.
*/
PurchaseUpdatePolicy["CHARGE_PRORATED_PRICE"] = "ChargeProratedPrice";
/**
* The new plan takes effect immediately, and the remaining time will be prorated
* and credited to the user.
*/
PurchaseUpdatePolicy["WITH_TIME_PRORATION"] = "WithTimeProration";
/**
* The new purchase takes effect immediately, the new plan will take effect
* when the old item expires.
*/
PurchaseUpdatePolicy["DEFERRED"] = "Deferred";
/**
* The new plan takes effect immediately, and the new price will be charged
* on next recurrence time.
*/
PurchaseUpdatePolicy["WITHOUT_PRORATION"] = "WithoutProration";
/**
* Unknown police.
*/
PurchaseUpdatePolicy["UNKNOWN"] = "Unknown";
})(exports.PurchaseUpdatePolicy || (exports.PurchaseUpdatePolicy = {}));
exports.EntitlementsCacheLifetime = void 0;
(function (EntitlementsCacheLifetime) {
EntitlementsCacheLifetime["WEEK"] = "Week";
EntitlementsCacheLifetime["TWO_WEEKS"] = "TwoWeeks";
EntitlementsCacheLifetime["MONTH"] = "Month";
EntitlementsCacheLifetime["TWO_MONTHS"] = "TwoMonths";
EntitlementsCacheLifetime["THREE_MONTHS"] = "ThreeMonths";
EntitlementsCacheLifetime["SIX_MONTHS"] = "SixMonths";
EntitlementsCacheLifetime["YEAR"] = "Year";
EntitlementsCacheLifetime["UNLIMITED"] = "Unlimited";
})(exports.EntitlementsCacheLifetime || (exports.EntitlementsCacheLifetime = {}));
const SKPeriodUnit = {
0: "DAY",
1: "WEEK",
2: "MONTH",
3: "YEAR",
};
const SKProductDiscountType = {
0: "INTRODUCTORY",
1: "SUBSCRIPTION",
};
const SKProductDiscountPaymentMode = {
0: "PAY_AS_YOU_GO",
1: "PAY_UP_FRONT",
2: "FREE_TRIAL",
};
const OfferingTag = {
"-1": "UNKNOWN",
"0": "NONE",
"1": "MAIN",
};
exports.IntroEligibilityStatus = void 0;
(function (IntroEligibilityStatus) {
IntroEligibilityStatus["UNKNOWN"] = "unknown";
IntroEligibilityStatus["NON_INTRO_OR_TRIAL_PRODUCT"] = "non_intro_or_trial_product";
IntroEligibilityStatus["ELIGIBLE"] = "intro_or_trial_eligible";
IntroEligibilityStatus["INELIGIBLE"] = "intro_or_trial_ineligible";
})(exports.IntroEligibilityStatus || (exports.IntroEligibilityStatus = {}));
exports.ExperimentGroupType = void 0;
(function (ExperimentGroupType) {
ExperimentGroupType["UNKNOWN"] = "unknown";
ExperimentGroupType["CONTROL"] = "control";
ExperimentGroupType["TREATMENT"] = "treatment";
})(exports.ExperimentGroupType || (exports.ExperimentGroupType = {}));
exports.RemoteConfigurationSourceType = void 0;
(function (RemoteConfigurationSourceType) {
RemoteConfigurationSourceType["UNKNOWN"] = "unknown";
RemoteConfigurationSourceType["EXPERIMENT_CONTROL_GROUP"] = "experiment_control_group";
RemoteConfigurationSourceType["EXPERIMENT_TREATMENT_GROUP"] = "experiment_treatment_group";
RemoteConfigurationSourceType["REMOTE_CONFIGURATION"] = "remote_configuration";
})(exports.RemoteConfigurationSourceType || (exports.RemoteConfigurationSourceType = {}));
exports.RemoteConfigurationAssignmentType = void 0;
(function (RemoteConfigurationAssignmentType) {
RemoteConfigurationAssignmentType["UNKNOWN"] = "unknown";
RemoteConfigurationAssignmentType["AUTO"] = "auto";
RemoteConfigurationAssignmentType["MANUAL"] = "manual";
})(exports.RemoteConfigurationAssignmentType || (exports.RemoteConfigurationAssignmentType = {}));
exports.ActionType = void 0;
(function (ActionType) {
/**
* Unspecified action type
*/
ActionType["UNKNOWN"] = "unknown";
/**
* URL action that opens the URL using SafariViewController
*/
ActionType["URL"] = "url";
/**
* Deeplink action that opens if Application can open specified deeplink
*/
ActionType["DEEPLINK"] = "deeplink";
/**
* Navigation to another No-Codes screen
*/
ActionType["NAVIGATION"] = "navigation";
/**
* Purchase the product
*/
ActionType["PURCHASE"] = "purchase";
/**
* Restore all purchases
*/
ActionType["RESTORE"] = "restore";
/**
* Close current screen
*/
ActionType["CLOSE"] = "close";
/**
* Close all No-Code screens
*/
ActionType["CLOSE_ALL"] = "closeAll";
})(exports.ActionType || (exports.ActionType = {}));
exports.ScreenPresentationStyle = void 0;
(function (ScreenPresentationStyle) {
/**
* on Android - default screen transaction animation will be used.
* on iOS - not a modal presentation. This style pushes a controller to a current navigation stack.
* For iOS NavigationController on the top of the stack is required.
*/
ScreenPresentationStyle["PUSH"] = "Push";
/**
* on Android - screen will move from bottom to top.
* on iOS - UIModalPresentationFullScreen analog.
*/
ScreenPresentationStyle["FULL_SCREEN"] = "FullScreen";
/**
* iOS only - UIModalPresentationPopover analog
*/
ScreenPresentationStyle["POPOVER"] = "Popover";
/**
* Android only - screen will appear/disappear without any animation.
* For iOS consider providing the {@link ScreenPresentationConfig.animated} flag.
*/
ScreenPresentationStyle["NO_ANIMATION"] = "NoAnimation";
})(exports.ScreenPresentationStyle || (exports.ScreenPresentationStyle = {}));
exports.NoCodesErrorCode = void 0;
(function (NoCodesErrorCode) {
NoCodesErrorCode["UNKNOWN"] = "Unknown";
NoCodesErrorCode["BAD_NETWORK_REQUEST"] = "BadNetworkRequest";
NoCodesErrorCode["BAD_RESPONSE"] = "BadResponse";
NoCodesErrorCode["ACTIVITY_START"] = "ActivityStart";
NoCodesErrorCode["NETWORK_REQUEST_EXECUTION"] = "NetworkRequestExecution";
NoCodesErrorCode["SERIALIZATION"] = "Serialization";
NoCodesErrorCode["DESERIALIZATION"] = "Deserialization";
NoCodesErrorCode["REQUEST_DENIED"] = "RequestDenied";
NoCodesErrorCode["MAPPING"] = "Mapping";
NoCodesErrorCode["BACKEND_ERROR"] = "BackendError";
NoCodesErrorCode["SCREEN_NOT_FOUND"] = "ScreenNotFound";
NoCodesErrorCode["QONVERSION_ERROR"] = "QonversionError";
NoCodesErrorCode["INTERNAL"] = "Internal";
NoCodesErrorCode["AUTHORIZATION_FAILED"] = "AuthorizationFailed";
NoCodesErrorCode["CRITICAL"] = "Critical";
NoCodesErrorCode["PRODUCT_NOT_FOUND"] = "ProductNotFound";
NoCodesErrorCode["PRODUCTS_LOADING_FAILED"] = "ProductsLoadingFailed";
NoCodesErrorCode["RATE_LIMIT_EXCEEDED"] = "RateLimitExceeded";
NoCodesErrorCode["SCREEN_LOADING_FAILED"] = "ScreenLoadingFailed";
NoCodesErrorCode["SDK_INITIALIZATION_ERROR"] = "SDKInitializationError"; // iOS
})(exports.NoCodesErrorCode || (exports.NoCodesErrorCode = {}));
exports.PurchaseResultStatus = void 0;
(function (PurchaseResultStatus) {
/**
* The purchase was successful.
*/
PurchaseResultStatus["SUCCESS"] = "Success";
/**
* The purchase was canceled by the user.
*/
PurchaseResultStatus["USER_CANCELED"] = "UserCanceled";
/**
* The purchase is pending (e.g., waiting for parental approval).
*/
PurchaseResultStatus["PENDING"] = "Pending";
/**
* An error occurred during the purchase.
*/
PurchaseResultStatus["ERROR"] = "Error";
})(exports.PurchaseResultStatus || (exports.PurchaseResultStatus = {}));
exports.PurchaseResultSource = void 0;
(function (PurchaseResultSource) {
/**
* The result was obtained from the Qonversion API.
*/
PurchaseResultSource["API"] = "Api";
/**
* The result was obtained from the local store.
*/
PurchaseResultSource["LOCAL"] = "Local";
})(exports.PurchaseResultSource || (exports.PurchaseResultSource = {}));
exports.QonversionErrorCode = void 0;
(function (QonversionErrorCode) {
QonversionErrorCode["UNKNOWN"] = "Unknown";
QonversionErrorCode["API_RATE_LIMIT_EXCEEDED"] = "ApiRateLimitExceeded";
QonversionErrorCode["APPLE_STORE_ERROR"] = "AppleStoreError";
QonversionErrorCode["BACKEND_ERROR"] = "BackendError";
QonversionErrorCode["BILLING_UNAVAILABLE"] = "BillingUnavailable";
QonversionErrorCode["CLIENT_INVALID"] = "ClientInvalid";
QonversionErrorCode["CLOUD_SERVICE_NETWORK_CONNECTION_FAILED"] = "CloudServiceNetworkConnectionFailed";
QonversionErrorCode["CLOUD_SERVICE_PERMISSION_DENIED"] = "CloudServicePermissionDenied";
QonversionErrorCode["CLOUD_SERVICE_REVOKED"] = "CloudServiceRevoked";
QonversionErrorCode["FAILED_TO_RECEIVE_DATA"] = "FailedToReceiveData";
QonversionErrorCode["FEATURE_NOT_SUPPORTED"] = "FeatureNotSupported";
QonversionErrorCode["FRAUD_PURCHASE"] = "FraudPurchase";
QonversionErrorCode["INCORRECT_REQUEST"] = "IncorrectRequest";
QonversionErrorCode["INTERNAL_ERROR"] = "InternalError";
QonversionErrorCode["INVALID_CLIENT_UID"] = "InvalidClientUid";
QonversionErrorCode["INVALID_CREDENTIALS"] = "InvalidCredentials";
QonversionErrorCode["INVALID_STORE_CREDENTIALS"] = "InvalidStoreCredentials";
QonversionErrorCode["LAUNCH_ERROR"] = "LaunchError";
QonversionErrorCode["NETWORK_CONNECTION_FAILED"] = "NetworkConnectionFailed";
QonversionErrorCode["OFFERINGS_NOT_FOUND"] = "OfferingsNotFound";
QonversionErrorCode["PAYMENT_INVALID"] = "PaymentInvalid";
QonversionErrorCode["PAYMENT_NOT_ALLOWED"] = "PaymentNotAllowed";
QonversionErrorCode["PLAY_STORE_ERROR"] = "PlayStoreError";
QonversionErrorCode["PRIVACY_ACKNOWLEDGEMENT_REQUIRED"] = "PrivacyAcknowledgementRequired";
QonversionErrorCode["PRODUCT_ALREADY_OWNED"] = "ProductAlreadyOwned";
QonversionErrorCode["PRODUCT_NOT_FOUND"] = "ProductNotFound";
QonversionErrorCode["PRODUCT_NOT_OWNED"] = "ProductNotOwned";
QonversionErrorCode["PROJECT_CONFIG_ERROR"] = "ProjectConfigError";
QonversionErrorCode["PURCHASE_CANCELED"] = "PurchaseCanceled";
QonversionErrorCode["PURCHASE_INVALID"] = "PurchaseInvalid";
QonversionErrorCode["PURCHASE_PENDING"] = "PurchasePending";
QonversionErrorCode["PURCHASE_UNSPECIFIED"] = "PurchaseUnspecified";
QonversionErrorCode["RECEIPT_VALIDATION_ERROR"] = "ReceiptValidationError";
QonversionErrorCode["REMOTE_CONFIGURATION_NOT_AVAILABLE"] = "RemoteConfigurationNotAvailable";
QonversionErrorCode["RESPONSE_PARSING_FAILED"] = "ResponseParsingFailed";
QonversionErrorCode["STORE_PRODUCT_NOT_AVAILABLE"] = "StoreProductNotAvailable";
QonversionErrorCode["UNAUTHORIZED_REQUEST_DATA"] = "UnauthorizedRequestData";
QonversionErrorCode["UNKNOWN_CLIENT_PLATFORM"] = "UnknownClientPlatform";
})(exports.QonversionErrorCode || (exports.QonversionErrorCode = {}));
/**
* Theme mode for No-Code screens.
* Use this to control how screens adapt to light/dark themes.
*/
exports.NoCodesTheme = void 0;
(function (NoCodesTheme) {
/**
* Automatically follow the device's system appearance (default).
* The screen will use light theme in light mode and dark theme in dark mode.
*/
NoCodesTheme["AUTO"] = "auto";
/**
* Force light theme regardless of device settings.
*/
NoCodesTheme["LIGHT"] = "light";
/**
* Force dark theme regardless of device settings.
*/
NoCodesTheme["DARK"] = "dark";
})(exports.NoCodesTheme || (exports.NoCodesTheme = {}));
class IntroEligibility {
constructor(status) {
this.status = status;
}
}
class Offering {
constructor(id, tag, products) {
this.id = id;
this.tag = tag;
this.products = products;
}
productForIdentifier(identifier) {
return this.products.find((object) => object.qonversionId === identifier);
}
}
class Offerings {
constructor(main, availableOfferings) {
this.main = main;
this.availableOffering = availableOfferings;
}
offeringForIdentifier(identifier) {
return this.availableOffering.find((object) => object.id === identifier);
}
}
class Entitlement {
constructor(id, productId, isActive, renewState, source, startedTimestamp, renewsCount, grantType, transactions, expirationTimestamp, trialStartTimestamp, firstPurchaseTimestamp, lastPurchaseTimestamp, autoRenewDisableTimestamp, lastActivatedOfferCode) {
this.id = id;
this.productId = productId;
this.isActive = isActive;
this.renewState = renewState;
this.source = source;
this.startedDate = new Date(startedTimestamp);
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.renewsCount = renewsCount;
this.grantType = grantType;
this.transactions = transactions;
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.trialStartDate = trialStartTimestamp ? new Date(trialStartTimestamp) : undefined;
this.firstPurchaseDate = firstPurchaseTimestamp ? new Date(firstPurchaseTimestamp) : undefined;
this.lastPurchaseDate = lastPurchaseTimestamp ? new Date(lastPurchaseTimestamp) : undefined;
this.autoRenewDisableDate = autoRenewDisableTimestamp ? new Date(autoRenewDisableTimestamp) : undefined;
this.lastActivatedOfferCode = lastActivatedOfferCode;
}
}
class Product {
constructor(qonversionId, storeId, basePlanId, storeDetails, skProduct, offeringId, subscriptionPeriod, trialPeriod, type, prettyPrice, price, currencyCode, storeTitle, storeDescription, prettyIntroductoryPrice) {
this.qonversionId = qonversionId;
this.storeId = storeId;
this.basePlanId = basePlanId;
this.storeDetails = storeDetails;
this.skProduct = skProduct;
this.offeringId = offeringId;
this.subscriptionPeriod = subscriptionPeriod;
this.trialPeriod = trialPeriod;
this.type = type;
this.prettyPrice = prettyPrice;
this.price = price;
this.currencyCode = currencyCode;
this.storeTitle = storeTitle;
this.storeDescription = storeDescription;
this.prettyIntroductoryPrice = prettyIntroductoryPrice;
}
}
class SKProduct {
constructor(localizedDescription, localizedTitle, price, localeIdentifier, productIdentifier, isDownloadable, downloadContentVersion, downloadContentLengths, subscriptionPeriod, productDiscount, discounts, subscriptionGroupIdentifier, isFamilyShareable, currencyCode) {
this.localizedDescription = localizedDescription;
this.localizedTitle = localizedTitle;
this.price = price;
this.localeIdentifier = localeIdentifier;
this.productIdentifier = productIdentifier;
this.isDownloadable = isDownloadable;
this.downloadContentVersion = downloadContentVersion;
this.downloadContentLengths = downloadContentLengths;
this.subscriptionPeriod = subscriptionPeriod;
this.productDiscount = productDiscount;
this.discounts = discounts;
this.subscriptionGroupIdentifier = subscriptionGroupIdentifier;
this.isFamilyShareable = isFamilyShareable;
this.currencyCode = currencyCode;
}
}
class SKProductDiscount {
constructor(price, localeIdentifier, numberOfPeriods, subscriptionPeriod, paymentMode, identifier, type, currencySymbol) {
this.price = price;
this.localeIdentifier = localeIdentifier;
this.numberOfPeriods = numberOfPeriods;
this.subscriptionPeriod = subscriptionPeriod;
this.paymentMode = paymentMode;
this.identifier = identifier;
this.type = type;
this.currencySymbol = currencySymbol;
}
}
class SKSubscriptionPeriod {
constructor(numberOfUnits, unit) {
this.numberOfUnits = numberOfUnits;
this.unit = unit;
}
}
class QonversionError {
constructor(code, description, additionalMessage, domain) {
this.code = code;
this.domain = domain;
this.description = description;
this.additionalMessage = additionalMessage;
}
}
class User {
constructor(qonversionId, identityId) {
this.qonversionId = qonversionId;
this.identityId = identityId;
}
}
class Experiment {
constructor(id, name, group) {
this.id = id;
this.name = name;
this.group = group;
}
}
class ExperimentGroup {
constructor(id, name, type) {
this.id = id;
this.name = name;
this.type = type;
}
}
/**
* A class describing a subscription period
*/
class SubscriptionPeriod {
constructor(unitCount, unit, iso) {
this.unitCount = unitCount;
this.unit = unit;
this.iso = iso;
}
}
class RemoteConfig {
constructor(payload, experiment, source) {
this.payload = payload;
this.experiment = experiment;
this.source = source;
}
}
class RemoteConfigList {
constructor(remoteConfigs) {
this.remoteConfigs = remoteConfigs;
}
remoteConfigForContextKey(contextKey) {
return this.findRemoteConfigForContextKey(contextKey);
}
remoteConfigForEmptyContextKey() {
return this.findRemoteConfigForContextKey(null);
}
findRemoteConfigForContextKey(contextKey) {
return this.remoteConfigs.find(config => config.source.contextKey == contextKey);
}
}
class UserProperties {
constructor(properties) {
this.properties = properties;
this.definedProperties = properties.filter(property => property.definedKey !== exports.UserPropertyKey.CUSTOM);
this.customProperties = properties.filter(property => property.definedKey === exports.UserPropertyKey.CUSTOM);
this.flatPropertiesMap = new Map();
this.flatDefinedPropertiesMap = new Map();
this.flatCustomPropertiesMap = new Map();
properties.forEach(property => {
this.flatPropertiesMap.set(property.key, property.value);
if (property.definedKey == exports.UserPropertyKey.CUSTOM) {
this.flatCustomPropertiesMap.set(property.key, property.value);
}
else {
this.flatDefinedPropertiesMap.set(property.definedKey, property.value);
}
});
}
/**
* Searches for a property with the given property {@link key} in all properties list.
*/
getProperty(key) {
return this.properties.find(userProperty => userProperty.key == key);
}
/**
* Searches for a property with the given Qonversion defined property {@link key}
* in defined properties list.
*/
getDefinedProperty(key) {
return this.definedProperties.find(userProperty => userProperty.definedKey == key);
}
}
class UserProperty {
constructor(key, value) {
this.key = key;
this.value = value;
this.definedKey = Mapper.convertDefinedUserPropertyKey(key);
}
}
class RemoteConfigurationSource {
constructor(id, name, type, assignmentType, contextKey) {
this.id = id;
this.name = name;
this.type = type;
this.assignmentType = assignmentType;
this.contextKey = contextKey;
}
}
class Transaction {
constructor(originalTransactionId, transactionId, transactionTimestamp, environment, ownershipType, type, expirationTimestamp, transactionRevocationTimestamp, offerCode, promoOfferId) {
this.originalTransactionId = originalTransactionId;
this.transactionId = transactionId;
this.transactionDate = new Date(transactionTimestamp);
this.environment = environment;
this.ownershipType = ownershipType;
this.type = type;
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.transactionRevocationDate = transactionRevocationTimestamp ? new Date(transactionRevocationTimestamp) : undefined;
this.offerCode = offerCode;
this.promoOfferId = promoOfferId;
}
}
/**
* Represents the result of a purchase operation.
* Contains the status of the purchase, entitlements, and store transaction details.
*/
class PurchaseResult {
constructor(status, entitlements, error, isFallbackGenerated, source, storeTransaction) {
this.status = status;
this.entitlements = entitlements;
this.error = error;
this.isFallbackGenerated = isFallbackGenerated;
this.source = source;
this.storeTransaction = storeTransaction;
}
/**
* Returns true if the purchase was successful.
*/
get isSuccess() {
return this.status === exports.PurchaseResultStatus.SUCCESS;
}
/**
* Returns true if the purchase was canceled by the user.
*/
get isCanceled() {
return this.status === exports.PurchaseResultStatus.USER_CANCELED;
}
/**
* Returns true if the purchase is pending.
*/
get isPending() {
return this.status === exports.PurchaseResultStatus.PENDING;
}
/**
* Returns true if an error occurred during the purchase.
*/
get isError() {
return this.status === exports.PurchaseResultStatus.ERROR;
}
}
/**
* Represents a raw store transaction from the native platform.
* This is the transaction information as received from Apple App Store or Google Play Store.
*/
class StoreTransaction {
constructor(transactionId, originalTransactionId, transactionTimestamp, productId, quantity, promoOfferId, purchaseToken) {
this.transactionId = transactionId;
this.originalTransactionId = originalTransactionId;
this.transactionDate = transactionTimestamp ? new Date(transactionTimestamp) : undefined;
this.productId = productId;
this.quantity = quantity !== null && quantity !== void 0 ? quantity : 1;
this.promoOfferId = promoOfferId;
this.purchaseToken = purchaseToken;
}
}
/**
* This class contains all the information about the concrete Google product,
* either subscription or in-app. In case of a subscription also determines concrete base plan.
*/
class ProductStoreDetails {
constructor(basePlanId, productId, name, title, description, subscriptionOfferDetails, defaultSubscriptionOfferDetails, basePlanSubscriptionOfferDetails, inAppOfferDetails, hasTrialOffer, hasIntroOffer, hasTrialOrIntroOffer, productType, isInApp, isSubscription, isPrepaid, isInstallment) {
this.basePlanId = basePlanId;
this.productId = productId;
this.name = name;
this.title = title;
this.description = description;
this.subscriptionOfferDetails = subscriptionOfferDetails;
this.defaultSubscriptionOfferDetails = defaultSubscriptionOfferDetails;
this.basePlanSubscriptionOfferDetails = basePlanSubscriptionOfferDetails;
this.inAppOfferDetails = inAppOfferDetails;
this.hasTrialOffer = hasTrialOffer;
this.hasIntroOffer = hasIntroOffer;
this.hasTrialOrIntroOffer = hasTrialOrIntroOffer;
this.productType = productType;
this.isInApp = isInApp;
this.isSubscription = isSubscription;
this.isPrepaid = isPrepaid;
this.isInstallment = isInstallment;
}
}
/**
* This class contains all the information about the Google subscription offer details.
* It might be either a plain base plan details or a base plan with the concrete offer details.
*/
class ProductOfferDetails {
constructor(basePlanId, offerId, offerToken, tags, pricingPhases, basePlan, installmentPlanDetails, introPhase, trialPhase, hasTrial, hasIntro, hasTrialOrIntro) {
this.basePlanId = basePlanId;
this.offerId = offerId;
this.offerToken = offerToken;
this.tags = tags;
this.pricingPhases = pricingPhases;
this.basePlan = basePlan;
this.installmentPlanDetails = installmentPlanDetails;
this.introPhase = introPhase;
this.trialPhase = trialPhase;
this.hasTrial = hasTrial;
this.hasIntro = hasIntro;
this.hasTrialOrIntro = hasTrialOrIntro;
}
}
/**
* This class contains all the information about the Google in-app product details.
*/
class ProductInAppDetails {
constructor(price) {
this.price = price;
}
}
/**
* Information about the Google product's price.
*/
class ProductPrice {
constructor(priceAmountMicros, priceCurrencyCode, formattedPrice, isFree, currencySymbol = null) {
this.priceAmountMicros = priceAmountMicros;
this.priceCurrencyCode = priceCurrencyCode;
this.formattedPrice = formattedPrice;
this.isFree = isFree;
this.currencySymbol = currencySymbol;
}
}
/**
* This class represents a pricing phase, describing how a user pays at a point in time.
*/
class ProductPricingPhase {
constructor(price, billingPeriod, billingCycleCount, recurrenceMode, type, isTrial, isIntro, isBasePlan) {
this.price = price;
this.billingPeriod = billingPeriod;
this.billingCycleCount = billingCycleCount;
this.recurrenceMode = recurrenceMode;
this.type = type;
this.isTrial = isTrial;
this.isIntro = isIntro;
this.isBasePlan = isBasePlan;
}
}
/**
* This class represents the details about the installment plan for a subscription product.
*/
class ProductInstallmentPlanDetails {
constructor(commitmentPaymentsCount, subsequentCommitmentPaymentsCount) {
this.commitmentPaymentsCount = commitmentPaymentsCount;
this.subsequentCommitmentPaymentsCount = subsequentCommitmentPaymentsCount;
}
}
class PromotionalOffer {
constructor(productDiscount, paymentDiscount) {
this.productDiscount = productDiscount;
this.paymentDiscount = paymentDiscount;
}
}
class SKPaymentDiscount {
constructor(identifier, keyIdentifier, nonce, signature, timestamp) {
this.identifier = identifier;
this.keyIdentifier = keyIdentifier;
this.nonce = nonce;
this.signature = signature;
this.timestamp = timestamp;
}
}
class NoCodesAction {
constructor(type, value, error) {
this.type = type;
this.value = value;
this.error = error;
}
}
class NoCodesError {
constructor(code, description, additionalMessage, domain, error) {
this.code = code;
this.domain = domain;
this.description = description;
this.additionalMessage = additionalMessage;
this.error = error;
}
}
const priceMicrosRatio = 1000000;
class Mapper {
static convertPromoOffer(promoOffer) {
if (!promoOffer) {
return null;
}
const productDiscount = this.convertProductDiscount(promoOffer.productDiscount);
const paymentDiscount = this.convertPaymentDiscount(promoOffer.paymentDiscount);
return new PromotionalOffer(productDiscount, paymentDiscount);
}
static convertEntitlements(entitlements) {
let mappedPermissions = new Map();
if (!entitlements) {
return mappedPermissions;
}
for (const [key, entitlement] of Object.entries(entitlements)) {
let renewState;
switch (entitlement.renewState) {
case exports.EntitlementRenewState.NON_RENEWABLE:
renewState = exports.EntitlementRenewState.NON_RENEWABLE;
break;
case exports.EntitlementRenewState.WILL_RENEW:
renewState = exports.EntitlementRenewState.WILL_RENEW;
break;
case exports.EntitlementRenewState.CANCELED:
renewState = exports.EntitlementRenewState.CANCELED;
break;
case exports.EntitlementRenewState.BILLING_ISSUE:
renewState = exports.EntitlementRenewState.BILLING_ISSUE;
break;
default:
renewState = exports.EntitlementRenewState.UNKNOWN;
break;
}
const entitlementSource = this.convertEntitlementSource(entitlement.source);
const entitlementGrantType = this.convertEntitlementGrantType(entitlement.grantType);
const transactions = [];
if (Array.isArray(entitlement.transactions)) {
entitlement.transactions.forEach((transaction) => {
const mappedTransaction = this.convertTransaction(transaction);
transactions.push(mappedTransaction);
});
}
const mappedPermission = new Entitlement(entitlement.id, entitlement.productId, entitlement.active, renewState, entitlementSource, entitlement.startedTimestamp, entitlement.renewsCount, entitlementGrantType, transactions, entitlement.expirationTimestamp, entitlement.trialStartTimestamp, entitlement.firstPurchaseTimestamp, entitlement.lastPurchaseTimestamp, entitlement.autoRenewDisableTimestamp, entitlement.lastActivatedOfferCode);
mappedPermissions.set(key, mappedPermission);
}
return mappedPermissions;
}
static convertTransaction(transaction) {
const environment = this.convertTransactionEnvironment(transaction.environment);
const ownershipType = this.convertTransactionOwnershipType(transaction.ownershipType);
const type = this.convertTransactionType(transaction.type);
return new Transaction(transaction.originalTransactionId, transaction.transactionId, transaction.transactionTimestamp, environment, ownershipType, type, transaction.expirationTimestamp, transaction.transactionRevocationTimestamp, transaction.offerCode, transaction.promoOfferId);
}
static convertTransactionType(typeKey) {
switch (typeKey) {
case "SubscriptionStarted":
return exports.TransactionType.SUBSCRIPTION_STARTED;
case "SubscriptionRenewed":
return exports.TransactionType.SUBSCRIPTION_RENEWED;
case "TrialStarted":
return exports.TransactionType.TRIAL_STARTED;
case "IntroStarted":
return exports.TransactionType.INTRO_STARTED;
case "IntroRenewed":
return exports.TransactionType.INTRO_RENEWED;
case "NonConsumablePurchase":
return exports.TransactionType.NON_CONSUMABLE_PURCHASE;
}
return exports.TransactionType.UNKNOWN;
}
static convertTransactionOwnershipType(ownershipTypeKey) {
switch (ownershipTypeKey) {
case "Owner":
return exports.TransactionOwnershipType.OWNER;
case "FamilySharing":
return exports.TransactionOwnershipType.FAMILY_SHARING;
}
return exports.TransactionOwnershipType.OWNER;
}
static convertTransactionEnvironment(envKey) {
switch (envKey) {
case "Production":
return exports.TransactionEnvironment.PRODUCTION;
case "Sandbox":
return exports.TransactionEnvironment.SANDBOX;
}
return exports.TransactionEnvironment.PRODUCTION;
}
static convertEntitlementSource(sourceKey) {
switch (sourceKey) {
case "Unknown":
return exports.EntitlementSource.UNKNOWN;
case "AppStore":
return exports.EntitlementSource.APP_STORE;
case "PlayStore":
return exports.EntitlementSource.PLAY_STORE;
case "Stripe":
return exports.EntitlementSource.STRIPE;
case "Manual":
return exports.EntitlementSource.MANUAL;
}
return exports.EntitlementSource.UNKNOWN;
}
static convertEntitlementGrantType(typeKey) {
switch (typeKey) {
case "Purchase":
return exports.EntitlementGrantType.PURCHASE;
case "FamilySharing":
return exports.EntitlementGrantType.FAMILY_SHARING;
case "OfferCode":
return exports.EntitlementGrantType.OFFER_CODE;
case "Manual":
return exports.EntitlementGrantType.MANUAL;
}
return exports.EntitlementGrantType.PURCHASE;
}
static convertDefinedUserPropertyKey(sourceKey) {
switch (sourceKey) {
case '_q_email':
return exports.UserPropertyKey.EMAIL;
case '_q_name':
return exports.UserPropertyKey.NAME;
case '_q_kochava_device_id':
return exports.UserPropertyKey.KOCHAVA_DEVICE_ID;
case '_q_appsflyer_user_id':
return exports.UserPropertyKey.APPS_FLYER_USER_ID;
case '_q_adjust_adid':
return exports.UserPropertyKey.ADJUST_AD_ID;
case '_q_custom_user_id':
return exports.UserPropertyKey.CUSTOM_USER_ID;
case '_q_fb_attribution':
return exports.UserPropertyKey.FACEBOOK_ATTRIBUTION;
case '_q_firebase_instance_id':
return exports.UserPropertyKey.FIREBASE_APP_INSTANCE_ID;
case '_q_app_set_id':
return exports.UserPropertyKey.APP_SET_ID;
case '_q_advertising_id':
return exports.UserPropertyKey.ADVERTISING_ID;
case "_q_appmetrica_device_id":
return exports.UserPropertyKey.APP_METRICA_DEVICE_ID;
case "_q_appmetrica_user_profile_id":
return exports.UserPropertyKey.APP_METRICA_USER_PROFILE_ID;
case "_q_pushwoosh_hwid":
return exports.UserPropertyKey.PUSH_WOOSH_HW_ID;
case "_q_pushwoosh_user_id":
return exports.UserPropertyKey.PUSH_WOOSH_USER_ID;
case "_q_tenjin_aiid":
return exports.UserPropertyKey.TENJIN_ANALYTICS_INSTALLATION_ID;
}
return exports.UserPropertyKey.CUSTOM;
}
static convertUserProperties(properties) {
const mappedProperties = properties.properties.map(propertyData => new UserProperty(propertyData.key, propertyData.value));
return new UserProperties(mappedProperties);
}
static convertProducts(products) {
let mappedProducts = new Map();
if (!products) {
return mappedProducts;
}
for (const [key, product] of Object.entries(products)) {
const mappedProduct = this.convertProduct(product);
mappedProducts.set(key, mappedProduct);
}
return mappedProducts;
}
static convertProduct(product) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const productType = Mapper.convertProductType(product.type);
const subscriptionPeriod = Mapper.convertSubscriptionPeriod(product.subscriptionPeriod);
const trialPeriod = Mapper.convertSubscriptionPeriod(product.trialPeriod);
const offeringId = (_a = product.offeringId) !== null && _a !== void 0 ? _a : null;
let skProduct = null;
let storeDetails = null;
let price;
let currencyCode;
let storeTitle;
let storeDescription;
let prettyIntroductoryPrice;
if (!!product.skProduct) {
skProduct = Mapper.convertSKProduct(product.skProduct);
price = parseFloat(skProduct.price);
currencyCode = skProduct.currencyCode;
storeTitle = skProduct.localizedTitle;
storeDescription = skProduct.localizedDescription;
if (skProduct.productDiscount) {
prettyIntroductoryPrice = skProduct.productDiscount.currencySymbol + skProduct.productDiscount.price;
}
}
else {
let priceMicros = null;
if (!!product.storeDetails) {
storeDetails = Mapper.convertProductStoreDetails(product.storeDetails);
storeTitle = storeDetails.title;
storeDescription = storeDetails.description;
const defaultOffer = storeDetails.defaultSubscriptionOfferDetails;
const inAppOffer = storeDetails.inAppOfferDetails;
if (defaultOffer) {
priceMicros = (_c = (_b = defaultOffer.basePlan) === null || _b === void 0 ? void 0 : _b.price) === null || _c === void 0 ? void 0 : _c.priceAmountMicros;
currencyCode = (_e = (_d = defaultOffer.basePlan) === null || _d === void 0 ? void 0 : _d.price) === null || _e === void 0 ? void 0 : _e.priceCurrencyCode;
prettyIntroductoryPrice = (_g = (_f = defaultOffer.introPhase) === null || _f === void 0 ? void 0 : _f.price) === null || _g === void 0 ? void 0 : _g.formattedPrice;
}
else if (inAppOffer) {
priceMicros = inAppOffer.price.priceAmountMicros;
currencyCode = inAppOffer.price.priceCurrencyCode;
prettyIntroductoryPrice = undefined;
}
}
price = priceMicros ? priceMicros / priceMicrosRatio : undefined;
}
const mappedProduct = new Product(product.id, product.storeId, (_h = product.basePlanId) !== null && _h !== void 0 ? _h : null, storeDetails, skProduct, offeringId, subscriptionPeriod, trialPeriod, productType, (_j = product.prettyPrice) !== null && _j !== void 0 ? _j : null, price, currencyCode, storeTitle, storeDescription, prettyIntroductoryPrice);
return mappedProduct;
}
static convertOfferings(offerings) {
if (!offerings) {
return null;
}
if (!Array.isArray(offerings.availableOfferings) ||
offerings.availableOfferings.length === 0) {
return null;
}
let mainOffering = null;
if (offerings.main) {
mainOffering = this.convertOffering(offerings.main);
}
const availableOfferings = [];
offerings.availableOfferings.forEach((offering) => {
const mappedOffering = this.convertOffering(offering);
availableOfferings.push(mappedOffering);
});
return new Offerings(mainOffering, availableOfferings);
}
static convertOffering(offering) {
var _a;
const products = [];
offering.products.forEach((product) => {
const mappedProduct = this.convertProduct(product);
products.push(mappedProduct);
});
const tag = (_a = OfferingTag[offering.tag]) !== null && _a !== void 0 ? _a : OfferingTag['0'];
return new Offering(offering.id, tag, products);
}
static convertProductType(productType) {
let type = exports