/// import { EventEmitter } from 'events'; import { StoreOptions } from './StoreOptions'; import { WeChatConfig } from '../config'; export declare const STORE_EVENTS: { FLUSH_STORE: string; STORE_FLUSHED: string; DESTROYED: string; DESTROY: string; }; export interface StoreGlobalTokenItem extends Record { count?: number; modifyDate?: string | Date; accessToken?: string; jsapi_ticket?: string; } export interface StoreUrlSignatureItem extends Record { _id?: string | undefined; __v?: number | undefined; appId?: string; jsapi_ticket?: string; nonceStr: string; timestamp: string; url: string; signature?: string; accessToken?: string; signatureName?: string; createDate?: string | Date; modifyDate?: string | Date; updated?: boolean; } export interface StoreOAuthItem extends Record { _id?: string | undefined; __v?: number | undefined; key?: string; access_token: string; refresh_token?: string; expires_in?: number; openid?: string; scope: string; expirationTime: number; createDate?: string | Date; modifyDate?: string | Date; updated?: boolean; } export interface StoreCardItem extends Record { ticket?: string; expires_in?: number; errcode?: number | string; errmsg?: string; createDate?: string | Date; modifyDate?: string | Date; } export interface StoreMiniProgramItem extends Record { openid?: string; session_key?: string; unionid?: string; expires_in?: number; createDate?: string | Date; modifyDate?: string | Date; } export interface UrlSignaturesCollection { [urlAsKey: string]: StoreUrlSignatureItem; } export interface OAuthSignaturesCollection { [openIdAsKey: string]: StoreOAuthItem; } export interface MiniProgramSignaturesCollection { [openIdAsKey: string]: StoreMiniProgramItem; } export declare type StoreWechatConfig = { store?: string; } | WeChatConfig; export interface StoreInterface { wechatConfig: StoreWechatConfig; globalToken: StoreGlobalTokenItem; urls: UrlSignaturesCollection; oauth: OAuthSignaturesCollection; card: StoreCardItem; mp: MiniProgramSignaturesCollection; } /** * Store class constructor * @param options * @constructor */ declare class Store extends EventEmitter { cache: boolean; store: StoreInterface; wechatInterval: NodeJS.Timeout; constructor(options?: StoreOptions); /** * Get global token info * @return {Promise} */ getGlobalToken(): Promise; /** * Update the global token info, as if access_token or jsapi_ticket is refreshed * @param info new token info should be updated to store * @return updated global token info */ updateGlobalToken(info: StoreGlobalTokenItem): Promise; /** * Get signature for passed url from store * @param url */ getSignature(url: string): Promise; /** * Add signature to store for the new url * @param url * @param signatureInfo */ saveSignature(url: string, signatureInfo: StoreUrlSignatureItem): Promise; /** * Update url signature to store * @param url * @param newInfo * @return {Promise} */ updateSignature(url: string, newInfo: StoreUrlSignatureItem): Promise; /** * Check if signature of the url is existing in store * @param url * @return {Promise} */ isSignatureExisting(url: string): Promise; /** * Get cached oauth access token info for current user * should store openid like in current user session * @param key */ getOAuthAccessToken(key: string): Promise; /** * Save new oauth access token info * @param key * @param info user oauth access token info */ saveOAuthAccessToken(key: string, info: StoreOAuthItem): Promise; /** * * @param key * @param newInfo * @return {Promise} */ updateOAuthAccessToken(key: string, newInfo: StoreOAuthItem): Promise; getCardTicket(): Promise; /** * * @param ticketInfo */ updateCardTicket(ticketInfo: StoreCardItem): Promise; /** * Get mini program session_ket * @param key - object key for the session, default openid * @return {Promise} */ getMiniProgramSessionKey(key: string): Promise; /** * Get the session data with the key * @param key * @return {Promise} */ getMiniProgramSession(key: string): Promise; /** * Set the session associated with the key * @param {string} key - object key for the session, default openid * @param {object} data - session data * @return {Promise} - resolved with old session data */ setMiniProgramSession(key: string, data: StoreMiniProgramItem): Promise; /** * Flush cached store object to persistent storage, e.g Database, File, etc... */ flush(): Promise; /** * Destroy the Store instance */ destroy(): void; } export default Store;