@namiml/web-sdk
Version:
Nami Web SDK makes subscriptions & in-app purchases easy, with powerful built-in paywalls and A/B testing
187 lines (186 loc) • 4.99 kB
TypeScript
import { NamiCampaign } from "./externals/campaign";
import { TComponent, TContainer } from "./components";
import { TCarouselSlidesState, THeaderFooter } from "./components/containers";
import { TDeviceOrientation } from "./device";
import { PaywallSKU } from "./sku";
import { NamiPurchase } from "./externals/purchase";
import { Optional } from "./utils";
import { LaunchCampaignError } from "./externals/errors";
import { NamiPaywallAction, NamiPaywallComponentChange, NamiPaywallEventVideoMetadata, NamiPaywallLaunchContext } from "./externals/paywall";
import { NamiSKU } from "./externals/sku";
export type TPaywallContext = TInitialState & {
paywallId: string;
livePaywalls: IPaywall[];
selectedPaywall?: IPaywall;
selectedCampaign?: NamiCampaign;
campaignRules: NamiCampaign[];
anySkuHasTrialOffer: boolean;
anySkuHasIntroOffer: boolean;
anySkuHasPromoOffer: boolean;
safeAreaTop: number;
slides?: TCarouselSlidesState;
currentPage: string;
fullScreenPresentation?: boolean;
isLoggedIn?: boolean;
darkMode?: boolean;
orientation: TDeviceOrientation;
focusedState: boolean;
platformId: string;
mediaList: {
[key: string]: any;
};
customer: {
[key: string]: any;
};
hasNotch: boolean;
skuItems: PaywallSKU[];
groups: {
id: string;
displayName: string;
ref: string;
}[];
currentGroupId: string;
selectedProducts: {
[currentGroupId: string]: string | null;
};
launch: TPaywallLaunchContext;
sku: {
[key: string]: any;
};
purchaseInProgress: boolean;
productBeingPurchased?: NamiSKU;
timeSpentOnPaywall?: number;
userInteractionEnabled?: boolean;
};
export type TPaywallLaunchContext = Required<NamiPaywallLaunchContext>;
export type ProductGroup = {
id: string;
products: PaywallSKU[];
ref: string;
};
export interface IPaywall {
id: string;
name: string;
paywall_type: string;
sku_menus: ISkuMenu[];
template: TPaywallTemplate;
fonts: FontCollection;
}
export interface ISkuMenu {
id: string;
name: string;
display_name: string;
ref: string;
products: PaywallSKU[];
}
export interface IEntitlements {
id: string;
entitlement_ref_id: string;
name: string;
description: string | null;
type: string;
}
export interface IProductsWithComponents extends PaywallSKU {
components: TComponent;
}
export type FontCollection = {
[fontName: string]: FontDetails;
};
export type FontDetails = {
id: string;
family: string;
style: string;
file: string;
};
export type TPaywallTemplate = {
id: string;
orgs?: string | null;
org_id?: string | null;
changelog?: string;
userHasAccess?: boolean;
media?: {
[key: string]: string;
};
pages: TPages[];
ready?: boolean;
version: string | number;
codename: string;
doc_link: string;
thumbnail?: string;
skuContexts?: {
[skuId: string]: {
[key: string]: any;
};
};
initialState: TInitialState;
min_sdk_version: string;
capabilities?: string[];
displaySingleGroup?: boolean;
};
export type TPages = {
name: string;
header: THeaderFooter;
contentContainer: TContainer | null;
footer: THeaderFooter;
backgroundContainer: TContainer | null;
};
export type TInitialState = {
slides?: TCarouselSlidesState;
currentPage: string;
fullScreenPresentation?: boolean;
isLoggedIn?: boolean;
[key: string]: any;
groups: InitiateStateGroup[];
currentGroupId: string;
selectedProducts: {
[currentGroupId: string]: string | null;
};
};
export type InitiateStateGroup = {
id: string;
displayName: string;
ref: string;
};
export type TPaywallMedia = {
id: string;
content: string | null;
paywall: string;
name: string;
};
export type TProductGroup = {
id: string;
display_name: string;
display_order: number;
default: boolean;
paywall: string;
ref: string;
};
export type TMediaTypes = {
[name: string]: Optional<TPaywallMedia, 'id'>;
};
export type TOffer = {
freeTrialEligible: boolean;
introEligible: boolean;
promoEligible: boolean;
};
export declare enum PaywallManagerEvents {
BuySku = "RegisterBuySKU",
Close = "PaywallCloseRequested",
SignIn = "PaywallSignInRequested",
Restore = "PaywallRestoreRequested",
DeeplinkAction = "PaywallDeeplinkAction"
}
export type PaywallActionEvent = {
action: NamiPaywallAction;
sku?: NamiSKU;
videoMetaData: NamiPaywallEventVideoMetadata;
timeSpentOnPaywall?: number;
componentChange?: NamiPaywallComponentChange;
purchaseError?: string;
purchases?: NamiPurchase[];
};
export type PaywallResultHandler = (success: boolean, error?: LaunchCampaignError) => void;
export type NamiAppSuppliedVideoDetails = {
url: string;
name?: string;
};