UNPKG

@namiml/web-sdk

Version:

Nami Web SDK makes subscriptions & in-app purchases easy, with powerful built-in paywalls and A/B testing

88 lines (87 loc) 4.57 kB
import { AvailableCampaignsResponseHandler } from "../types/campaign"; import { PaywallResultHandler } from "../types/paywall"; import { PaywallComponent } from "../components/Paywall"; import { Callback } from "../types/components/containers"; import { NamiPaywallActionHandler, NamiPaywallLaunchContext } from "../types/externals/paywall"; import { NamiCampaign } from "../types/externals/campaign"; /** * @class NamiCampaignManager * Provides methods for managing all aspects of a campaign. */ export declare class NamiCampaignManager { static instance: NamiCampaignManager; private emitter; /** * @returns {NamiCampaign[]} A list of NamiCampaign */ static allCampaigns(): NamiCampaign[]; /** * Checks if a campaign is available for a given argument. * The argument can be a label string, or a deeplink URL. * * @param label - The argument to check. Can be a label string, or a deeplink URL. * @returns {boolean} True if the campaign is available, False otherwise. */ static isCampaignAvailable(label: string): boolean; /** * Checks if a campaign is a Flow campaign for a given argument. * The argument can be a label string, or a deeplink URL. * * @param label - The label of the campaign to check. Can be a label string. * @param withUrl - The deeplink URL of the campaign to check. * @returns {boolean} True if the campaign is a Flow campaign, False otherwise. */ static isFlow(label?: string, withUrl?: string): boolean; /** * Fetches the latest active campaigns for the current device. * * @returns {Promise<NamiCampaign[]>} A promise that resolves to a list of active campaigns. */ static refresh(): Promise<NamiCampaign[]>; /** * Registers a handler that will be called whenever there is an update * in the list of active campaigns. The Nami SDK will trigger this callback * with the updated list of active campaigns. * * The handler will receive an array of `NamiCampaign` objects representing * the current active campaigns. * * @param {AvailableCampaignsResponseHandler} handler - The callback function that will be invoked when the campaign list is updated. * @returns {Callback} A function that can be called to unregister the handler. */ static registerAvailableCampaignsHandler(handler: AvailableCampaignsResponseHandler): Callback; /** * Launches a campaign with a given label. * @param label - The label of the campaign to launch. * @param withUrl - The deeplink URL of the campaign to launch. * @param actionCallback - Optional handler for paywall actions. * @returns {PaywallComponent | void} The launched paywall web component. */ static launch(label?: string, withUrl?: string, context?: NamiPaywallLaunchContext, resultCallback?: PaywallResultHandler, actionCallback?: NamiPaywallActionHandler): PaywallComponent; /** * Provide the list of product groups supported by the provided placement label or URL. * @param label Campaign placement label defined in Nami Control Center for launching a specific campaign. * @param uri Campaign placement URI defined in Nami Control Center for launching a specific campaign. * @return List of product groups associated with the specified campaign placement. */ static getProductGroups(label?: string, withUrl?: string): string[]; /** * Get all product SKUs associated with the provided placement label or URL. * @param label Campaign placement label defined in Nami Control Center for launching a specific campaign. * @param withUrl Campaign placement URI defined in Nami Control Center for launching a specific campaign. * @returns List of product SKUs associated with the specified campaign placement. */ static getAllProducts(label?: string, withUrl?: string): string[]; /** * Get the list of currently active product SKUs associated with the provided placement label or URL. * @param label Campaign placement label defined in Nami Control Center for launching a specific campaign. * @param withUrl Campaign placement URI defined in Nami Control Center for launching a specific campaign. * @returns List of current product SKUs associated with the specified campaign placement. */ static getCurrentProducts(label?: string, withUrl?: string): string[]; /** * Private Instance Methods */ private get sdkInitialized(); private campaignTypeAndLabel; }