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K,KAAO,EAAK,QAIoB,mBAA1B,OAAO,eACd,OAAO,eAAe,KAAM,YAAY,WAExC,KAAK,UAAY,YAAY,SAErC","file":"/npm/@sesame/react-native-wechat@0.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@sesame/react-native-wechat@0.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { DeviceEventEmitter, NativeModules, Platform } from 'react-native';\nimport { EventEmitter } from 'events';\n\nconst { RNWechat } = NativeModules;\n\nconst WeChat = RNWechat;\nlet isAppRegistered = false;\n\n// Event emitter to dispatch request and response from WeChat.\nconst emitter = new EventEmitter();\n\nDeviceEventEmitter.addListener('WeChat_Resp', resp => {\n    emitter.emit(resp.type, resp);\n});\n\nfunction wrapRegisterApp(nativeFunc) {\n    if (!nativeFunc) {\n        return undefined;\n    }\n    return (...args) => {\n        if (isAppRegistered) {\n            // FIXME(Yorkie): we ignore this error if AppRegistered is true.\n            return Promise.resolve(true);\n        }\n        isAppRegistered = true;\n        return new Promise((resolve, reject) => {\n            nativeFunc.apply(null, [\n                ...args,\n                (error, result) => {\n                    if (!error) {\n                        return resolve(result);\n                    }\n                    if (typeof error === 'string') {\n                        return reject(new Error(error));\n                    }\n                    reject(error);\n                },\n            ]);\n        });\n    };\n}\n\nfunction wrapApi(nativeFunc) {\n    if (!nativeFunc) {\n        return undefined;\n    }\n    return (...args) => {\n        if (!isAppRegistered) {\n            return Promise.reject(new Error('registerApp required.'));\n        }\n        return new Promise((resolve, reject) => {\n            nativeFunc.apply(null, [\n                ...args,\n                (error, result) => {\n                    if (!error) {\n                        return resolve(result);\n                    }\n                    if (typeof error === 'string') {\n                        return reject(new Error(error));\n                    }\n                    reject(error);\n                },\n            ]);\n        });\n    };\n}\n\n/**\n * `addListener` inherits from `events` module\n * @method addListener\n * @param {String} eventName - the event name\n * @param {Function} trigger - the function when event is fired\n */\nexport const addListener = emitter.addListener.bind(emitter);\n\n/**\n * `once` inherits from `events` module\n * @method once\n * @param {String} eventName - the event name\n * @param {Function} trigger - the function when event is fired\n */\nexport const once = emitter.once.bind(emitter);\n\n/**\n * `removeAllListeners` inherits from `events` module\n * @method removeAllListeners\n * @param {String} eventName - the event name\n */\nexport const removeAllListeners = emitter.removeAllListeners.bind(emitter);\n\n/**\n * @method registerApp\n * @param {String} appid - the app id\n * @return {Promise}\n */\nexport const registerApp = wrapRegisterApp(WeChat.registerApp);\n\n/**\n * Return if the wechat app is installed in the device.\n * @method isWXAppInstalled\n * @return {Promise}\n */\nexport const isWXAppInstalled = wrapApi(WeChat.isWXAppInstalled);\n\n/**\n * Get the wechat app installed url\n * @method getWXAppInstallUrl\n * @return {String} the wechat app installed url\n */\nexport const getWXAppInstallUrl = wrapApi(WeChat.getWXAppInstallUrl);\n\n/**\n * Get the wechat api version\n * @method getApiVersion\n * @return {String} the api version string\n */\nexport const getApiVersion = wrapApi(WeChat.getApiVersion);\n\n/**\n * Open wechat app\n * @method openWXApp\n * @return {Promise}\n */\nexport const openWXApp = wrapApi(WeChat.openWXApp);\n\n// wrap the APIs\nconst nativeShareToTimeline = wrapApi(WeChat.shareToTimeline);\nconst nativeShareToSession = wrapApi(WeChat.shareToSession);\nconst nativeShareToFavorite = wrapApi(WeChat.shareToFavorite);\nconst nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest);\n\n/**\n * @method sendAuthRequest\n * @param {Array} scopes - the scopes for authentication.\n * @return {Promise}\n */\nexport function sendAuthRequest(scopes, state) {\n    return new Promise((resolve, reject) => {\n        WeChat.sendAuthRequest(scopes, state, () => {});\n        emitter.once('SendAuth.Resp', resp => {\n            if (resp.errCode === 0) {\n                resolve(resp);\n            } else {\n                reject(new WechatError(resp));\n            }\n        });\n    });\n}\n\n/**\n * Share something to timeline/moments/朋友圈\n * @method shareToTimeline\n * @param {Object} data\n * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id.\n * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file}\n * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share.\n * @param {String} data.imageUrl - Provide a remote image if type equals image.\n * @param {String} data.videoUrl - Provide a remote video if type equals video.\n * @param {String} data.musicUrl - Provide a remote music if type equals audio.\n * @param {String} data.filePath - Provide a local file if type equals file.\n * @param {String} data.fileExtension - Provide the file type if type equals file.\n */\nexport function shareToTimeline(data) {\n    return new Promise((resolve, reject) => {\n        nativeShareToTimeline(data);\n        emitter.once('SendMessageToWX.Resp', resp => {\n            if (resp.errCode === 0) {\n                resolve(resp);\n            } else {\n                reject(new WechatError(resp));\n            }\n        });\n    });\n}\n\n/**\n * Share something to a friend or group\n * @method shareToSession\n * @param {Object} data\n * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id.\n * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file}\n * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share.\n * @param {String} data.imageUrl - Provide a remote image if type equals image.\n * @param {String} data.videoUrl - Provide a remote video if type equals video.\n * @param {String} data.musicUrl - Provide a remote music if type equals audio.\n * @param {String} data.filePath - Provide a local file if type equals file.\n * @param {String} data.fileExtension - Provide the file type if type equals file.\n */\nexport function shareToSession(data) {\n    return new Promise((resolve, reject) => {\n        nativeShareToSession(data);\n        emitter.once('SendMessageToWX.Resp', resp => {\n            if (resp.errCode === 0) {\n                resolve(resp);\n            } else {\n                reject(new WechatError(resp));\n            }\n        });\n    });\n}\n\n/**\n * Share something to favorite\n * @method shareToFavorite\n * @param {Object} data\n * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id.\n * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file}\n * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share.\n * @param {String} data.imageUrl - Provide a remote image if type equals image.\n * @param {String} data.videoUrl - Provide a remote video if type equals video.\n * @param {String} data.musicUrl - Provide a remote music if type equals audio.\n * @param {String} data.filePath - Provide a local file if type equals file.\n * @param {String} data.fileExtension - Provide the file type if type equals file.\n */\nexport function shareToFavorite(data) {\n    return new Promise((resolve, reject) => {\n        nativeShareToFavorite(data);\n        emitter.once('SendMessageToWX.Resp', resp => {\n            if (resp.errCode === 0) {\n                resolve(resp);\n            } else {\n                reject(new WechatError(resp));\n            }\n        });\n    });\n}\n\n/**\n * wechat pay\n * @param {Object} data\n * @param {String} data.partnerId\n * @param {String} data.prepayId\n * @param {String} data.nonceStr\n * @param {String} data.timeStamp\n * @param {String} data.package\n * @param {String} data.sign\n * @returns {Promise}\n */\nexport function pay(data) {\n    // FIXME(Yorkie): see https://github.com/yorkie/react-native-wechat/issues/203\n    // Here the server-side returns params in lowercase, but here SDK requires timeStamp\n    // for compatibility, we make this correction for users.\n    function correct(actual, fixed) {\n        if (!data[fixed] && data[actual]) {\n            data[fixed] = data[actual];\n            delete data[actual];\n        }\n    }\n    correct('prepayid', 'prepayId');\n    correct('noncestr', 'nonceStr');\n    correct('partnerid', 'partnerId');\n    correct('timestamp', 'timeStamp');\n\n    // FIXME(94cstyles)\n    // Android requires the type of the timeStamp field to be a string\n    if (Platform.OS === 'android') data.timeStamp = String(data.timeStamp)\n\n    return new Promise((resolve, reject) => {\n        WeChat.pay(data, result => {\n            if (result) reject(result);\n        });\n        emitter.once('PayReq.Resp', resp => {\n            if (resp.errCode === 0) {\n                resolve(resp);\n            } else {\n                reject(new WechatError(resp));\n            }\n        });\n    });\n}\n\n/**\n * promises will reject with this error when API call finish with an errCode other than zero.\n */\nexport class WechatError extends Error {\n    constructor(resp) {\n        const message = resp.errStr || resp.errCode.toString();\n        super(message);\n        this.name = 'WechatError';\n        this.code = resp.errCode;\n\n        // avoid babel's limition about extending Error class\n        // https://github.com/babel/babel/issues/3083\n        if (typeof Object.setPrototypeOf === 'function') {\n            Object.setPrototypeOf(this, WechatError.prototype);\n        } else {\n            this.__proto__ = WechatError.prototype;\n        }\n    }\n}"]}