UNPKG

@namiml/web-sdk

Version:

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

137 lines (136 loc) 5.53 kB
import { Callback } from "../types/components/containers"; import { AccountStateAction } from "../types/profile"; import { NamiCustomerJourneyStateHandler } from "../types/customer"; import { CustomerJourneyState } from "../types/externals/customer"; type AccountStateHandler = (action: AccountStateAction, success: boolean, error?: Error) => void; /** * @class NamiCustomerManager * Provides methods for managing customer-related functionality. */ export declare class NamiCustomerManager { static instance: NamiCustomerManager; private emitter; constructor(); /** * Checks if the customer is logged in. * * @returns {boolean} Returns true if the customer is logged in, false otherwise. */ static isLoggedIn(): boolean; /** * Returns the external ID of the currently logged in user. * * @returns {string | undefined} The external ID of the logged in user. */ static loggedInId(): string | undefined; /** * Logs in a customer with the specified ID. * * @param id - The ID of the customer to log in. Must be a SHA256 hash or UUID. * @returns {Promise<void>} A Promise that resolves when the login is successful. */ static login(externalId: string): Promise<void>; /** * This method detaches the whole platform account from the signed in user * @returns {Promise<void>} A Promise that resolves when the logout is successful. */ static logout(): Promise<void>; /** * This method for connecting the device to a Customer Data Platform identifier * * Advanced use case. Make sure you have user consent. * * @param id a value supplied from your CDP platform * @returns {Promise<void>} A Promise that resolves when CustomerDataPlatformId will be set. */ static setCustomerDataPlatformId(id: string): Promise<void>; /** * This method for clearing the Customer Data Platform identifier linked to this device * * Advanced use case. * @returns {Promise<void>} A Promise that resolves when CustomerDataPlatformId will be cleared. */ static clearCustomerDataPlatformId(): Promise<void>; /** * Registers a callback function to handle changes in the account state. * * @param callback - The callback function to be registered. * @returns {Callback} A function that can be used to unregister the original callback. */ static registerAccountStateHandler(handler: AccountStateHandler): Callback; /** * Sets the anonymous mode for the customer. * * @param enabled - A boolean value indicating whether the anonymous mode should be enabled or disabled. * @returns {Promise<void>} A Promise that resolves when the anonymous mode is set. */ static setAnonymousMode(enabled: boolean): Promise<void>; /** * @returns {boolean} whether or not the SDK is currently operating in anonymous mode */ static inAnonymousMode(): boolean; /** * Sets an optional customer attributes that can be used to personalize your Nami paywalls. * * @param key - The name of the attribute. For example: `firstName`. * @param value - The value of the customer attribute. For example: `Joe`. */ static setCustomerAttribute(key: string, value: string): void; /** * Retrieves the value for a given key in the on-device customer attribute key/value store. * * @param key - The name of the attribute. For example: `firstName` * @returns {string | null} The value of the customer attribute. */ static getCustomerAttribute(key: string): string | null; /** * Retrieves all the customer attribute key/value store. * * @returns {string | null} The value of the customer attribute. */ static getAllCustomerAttributes(): string[]; /** * Clears a value of the given key in the on-device key/value store. * * @param key - The key of the customer attribute to clear. */ static clearCustomerAttribute(key: string): void; /** * Clear all customer attributes from the on-device key/value store. */ static clearAllCustomerAttributes(): void; /** * @return current customer's journey state. */ static journeyState(): CustomerJourneyState | null; /** * @return the unique identifier Nami users to identify this device. Please note * you should not depend on the device identifier persisting across app re-installs. */ static deviceId(): string; /** * When there has been an update received to the active entitlements, * the Nami SDK will provide notification of that event through * this callback with list of active [NamiEntitlement] * * @param {NamiCustomerJourneyStateHandler} 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 registerJourneyStateHandler(handler: NamiCustomerJourneyStateHandler): Callback | undefined; /** * Private Static Methods */ private static invokeStateHandler; /** * Private Instance Methods */ private get isSDKInitialized(); private static updateCustomerDataPlatformId; /** * @returns whether or not the configured app platform id belongs to an anonymous mode * capable Nami account. */ private static anonymousModeCapability; private static refetchConfig; } export {};