UNPKG

@microbitsclub/paywall-solid

Version:
39 lines (38 loc) 1.87 kB
import type { APIResponse } from '@microbitsclub/microbits-client'; import crossFetch from 'cross-fetch'; import { PaywallPopoverMode } from './paywall-popover-content'; import { UrlPath, UrlQuery } from './url'; declare type Dict<K extends string | number | symbol, T> = Partial<Record<K, T>>; export interface PaywallPopoverConfig { merchantId: string; merchantServerDomain?: string; merchantRoutePrefix?: string; fetchFunction?: typeof crossFetch; getServerUrl?: (path: UrlPath, query?: UrlQuery) => string; getContentUrl?: (path: UrlPath, query?: UrlQuery) => string; } export interface PaywallPopoverStore { readonly userSessionId?: string; readonly responseCache: Readonly<{ paywall: Dict<string, APIResponse.GetPaywallById>; contentAuthorized: Dict<string, APIResponse.IsUserSessionAuthorizedForPaywall>; }>; readonly popover?: Readonly<{ mode: PaywallPopoverMode; contentUrl: string; paywall: APIResponse.GetPaywallByIdData; }>; readonly hasUserSessionId: boolean; getPaywall(contentUrl: string): Promise<APIResponse.GetPaywallByContentUrlData | undefined>; isContentAuthorized(contentUrl: string): Promise<boolean>; attempNavigateToContent(contentUrl: string): Promise<void>; handleContentLinkClick(e: MouseEvent, contentUrl: string): Promise<void>; getContentLinkClickHandler(contentUrl: string): (e: MouseEvent) => void; navigateToGetUserSession(contentUrl: string, shouldPurchase: boolean): void; navigateToPurchaseThenViewContent(contentUrl: string): void; navigateToContent(contentUrl: string): void; showPopoverPaywall(contentUrl: string, mode: PaywallPopoverMode): Promise<void>; hidePopoverPaywall(): void; } export declare const createPaywallPopoverStore: (config: PaywallPopoverConfig) => PaywallPopoverStore; export {};