@cloudbase/auth 2.5.49-beta.1 → 2.5.49-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ export { printWarn, throwError } from '@cloudbase/utilities/dist/cjs/libs/util';
2
+ export { ERRORS, COMMUNITY_SITE_URL } from '@cloudbase/utilities/dist/cjs/constants';
3
+ export { catchErrorsDecorator } from '@cloudbase/utilities/dist/cjs/helpers';
4
+ export { CloudbaseEventEmitter } from '@cloudbase/utilities/dist/cjs/libs/events';
5
+ export { CloudbaseCache } from '@cloudbase/utilities/dist/cjs/libs/cache';
6
+ export { defualt as adapterForWxMp } from 'cloudbase-adapter-wx_mp';
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_auth_utilities",[],e):"object"==typeof exports?exports.cloudbase_auth_utilities=e():t.cloudbase_auth_utilities=e()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var t={69:(t,e,r)=>{var n;r.r(e),r.d(e,{AbstractSDKRequest:()=>o,AbstractStorage:()=>i,StorageType:()=>n,formatUrl:()=>c}),function(t){t.local="local",t.none="none",t.session="session"}(n||(n={}));var o=function(){},i=function(){};function c(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),o="";for(var i in r)""===o?!n&&(e+="?"):o+="&",o+=i+"="+encodeURIComponent(r[i]);return/^http(s)?\:\/\//.test(e+=o)?e:""+t+e}},876:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var r="@cloudbase/js-sdk";e.setSdkName=function(t){r=t},e.getSdkName=function(){return r};var n="https:";e.setProtocol=function(t){n=t},e.getProtocol=function(){return n},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},767:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},254:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(r(876),e),o(r(767),e),e.OATUH_LOGINTYPE="constants"},343:function(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function c(t){try{s(n.next(t))}catch(t){i(t)}}function a(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(c,a)}s((n=n.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(c=0)),c;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,n=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){c=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){c.label=a[1];break}if(6===a[0]&&c.label<o[1]){c.label=o[1],o=a;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(a);break}o[2]&&c.ops.pop(),c.trys.pop();continue}a=e.call(t,c)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.catchErrorsDecorator=void 0;var i=r(3),c=r(254),a=!1;"undefined"!=typeof navigator&&navigator.userAgent&&(a=-1!==navigator.userAgent.indexOf("Firefox"));var s=a?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,u=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function l(t){var e=t.err,r=t.className,n=t.methodName,o=t.sourceLink;if(!o)return null;var i,c=e.stack.split("\n"),s=a?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(r,"\\.descriptor.value\\s*\\[as\\s").concat(n,"\\]\\s*\\(.*\\)$")),l=a?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(r,"\\.descriptor.value\\s*\\[as\\s").concat(n,"\\]")),f=c.findIndex((function(t){return s.test(t)}));if(-1!==f){var p=c.filter((function(t,e){return e>f}));p.unshift(c[f].replace(l,"".concat(r,".").concat(n)).replace(u,o)),(i=new Error).stack="".concat(a?"@debugger":"Error","\n").concat(p.join("\n"))}return i}e.catchErrorsDecorator=function(t){var e=t.mode,r=void 0===e?"async":e,a=t.customInfo,f=void 0===a?{}:a,p=t.title,d=t.messages,h=void 0===d?[]:d;return function(t,e,a){if(c.IS_DEBUG_MODE){var d=f.className||t.constructor.name,y=f.methodName||e,v=a.value,g=function(t){var e="",r=t.stack.split("\n"),n=r.findIndex((function(t){return s.test(t)}));if(-1!==n){var o=u.exec(r[n+1]||"");e=o?o[0]:""}return e}(new Error);a.value="sync"===r?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=l({err:new Error,className:d,methodName:y,sourceLink:g});try{return v.apply(this,t)}catch(t){var n=t,o=t.message,c=t.error,a=t.error_description,s={title:p||"".concat(d,".").concat(y," failed"),content:[{type:"error",body:t}]};if(o&&/^\{.*\}$/.test(o)){var u=JSON.parse(o);s.subtitle=o,u.code&&(r?(r.code=u.code,r.msg=u.msg):(t.code=u.code,t.message=u.msg),n=r||t,s.content=h.map((function(t){return{type:"info",body:t}})))}throw c&&a&&(s.subtitle=a,r?(r.code=c,r.msg=a):(t.code=c,t.message=a),n=r||t,s.content=h.map((function(t){return{type:"info",body:t}}))),(0,i.printGroupLog)(s),n}}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n(this,void 0,void 0,(function(){var e,r,n,c,a,s,u,f;return o(this,(function(o){switch(o.label){case 0:e=l({err:new Error,className:d,methodName:y,sourceLink:g}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,v.apply(this,t)];case 2:return[2,o.sent()];case 3:throw r=o.sent(),n=r,c=r.message,a=r.error,s=r.error_description,u={title:p||"".concat(d,".").concat(y," failed"),content:[{type:"error",body:r}]},c&&/^\{.*\}$/.test(c)&&(f=JSON.parse(c),u.subtitle=f,f.code&&(e?(e.code=f.code,e.message=f.msg):(r.code=f.code,r.message=f.msg),n=e||r,u.content=h.map((function(t){return{type:"info",body:t}})))),a&&s&&(u.subtitle=s,e?(e.code=a,e.msg=s):(r.code=a,r.message=s),n=e||r,u.content=h.map((function(t){return{type:"info",body:t}}))),(0,i.printGroupLog)(u),n;case 4:return[2]}}))}))}}}}},731:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(343),e)},442:function(t,e,r){var n,o=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function c(t){try{s(n.next(t))}catch(t){i(t)}}function a(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(c,a)}s((n=n.apply(t,e||[])).next())}))},c=this&&this.__generator||function(t,e){var r,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(c=0)),c;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,n=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){c=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){c.label=a[1];break}if(6===a[0]&&c.label<o[1]){c.label=o[1],o=a;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(a);break}o[2]&&c.ops.pop(),c.trys.pop();continue}a=e.call(t,c)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.CloudbaseCache=void 0;var a=r(69),s=r(3),u=r(254),l=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return o(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(a.AbstractStorage);var f=function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,o=t.keys,i=void 0===o?{}:o;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":return e.localStorage?e.localStorage:((0,s.printWarn)(u.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new l(e.root));case"none":return new l(e.root);default:return e.localStorage?e.localStorage:((0,s.printWarn)(u.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new l(e.root))}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:u.ERRORS.OPERATION_FAIL,msg:"[".concat((0,u.getSdkName)(),"][").concat(u.ERRORS.OPERATION_FAIL,"]setStore failed"),info:t}))}}else(0,s.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return i(this,void 0,void 0,(function(){var n;return c(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return process.env.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}(0,s.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return i(this,void 0,void 0,(function(){var n;return c(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return[2,process.env.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=o.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):(0,s.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return i(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))},t}();e.CloudbaseCache=f},424:function(t,e,r){var n,o=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var c=r(3);var a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var s=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return o(e,t),e}(a);e.IErrorEvent=s;var u=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,c.isInstanceOf)(t,s))return console.error(t.error),this;var r=(0,c.isString)(t)?new a(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,u=this.listeners[n]?i([],this.listeners[n],!0):[];o<u.length;o++){u[o].call(this,r)}}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=u;var l=new u;e.addEventListener=function(t,e){l.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),l.fire(t,e)},e.removeEventListener=function(t,e){l.off(t,e)}},3:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.transformPhone=e.sleep=e.printGroupLog=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var n=r(254);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.formatUrl=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),o="";return Object.keys(r).forEach((function(t){""===o?!n&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var r=e||window.location.search,n=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=r.substr(r.indexOf("?")+1).match(n);return null!=o?o[2]:""};e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var r=e.split("?")[0],n=[],o=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==o){for(var i=(n=o.split("&")).length-1;i>=0;i-=1)n[i].split("=")[0]===t&&n.splice(i,1);r="".concat(r,"?").concat(n.join("&"))}return r},e.createPromiseCallback=function(){var t;if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var r=new Promise((function(e,r){t=function(t,n){return t?r(t):e(n)}}));return t.promise=r,t},e.execCallback=function(t,e,r){if(void 0===r&&(r=null),t&&"function"==typeof t)return t(e,r);if(e)throw e;return r},e.printWarn=function(t,e){console.warn("[".concat((0,n.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,n.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,n.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){throw new Error(JSON.stringify({code:t,msg:"[".concat((0,n.getSdkName)(),"][").concat(t,"]:").concat(e)}))},e.printGroupLog=function(t){var e=t.title,r=t.subtitle,n=void 0===r?"":r,o=t.content,i=void 0===o?[]:o,c=t.printTrace,a=void 0!==c&&c,s=t.collapsed;void 0!==s&&s?console.groupCollapsed(e,n):console.group(e,n);for(var u=0,l=i;u<l.length;u++){var f=l[u],p=f.type,d=f.body;switch(p){case"info":console.log(d);break;case"warn":console.warn(d);break;case"error":console.error(d)}}a&&console.trace("stack trace:"),console.groupEnd()};e.sleep=function(t){return void 0===t&&(t=0),new Promise((function(e){return setTimeout(e,t)}))},e.transformPhone=function(t){return"+86".concat(t)}},399:(t,e,r)=>{r.r(e),r.d(e,{WxMpWebSocket:()=>f,WxRequest:()=>u,default:()=>p,wxMpStorage:()=>l});var n,o=r(69),i=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),c=function(){return(c=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},a=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function c(t){try{s(n.next(t))}catch(t){i(t)}}function a(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(c,a)}s((n=n.apply(t,e||[])).next())}))},s=function(t,e){var r,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,n=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};var u=function(t){function e(e){void 0===e&&(e={});var r=t.call(this)||this,n=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return r._timeout=n||0,r._timeoutMsg=o||"请求超时",r._restrictedMethods=i||["get","post","upload","download"],r}return i(e,t),e.prototype.post=function(t){var e=this;return new Promise((function(r,n){var i=t.url,c=t.data,a=t.headers,s=wx.request({url:(0,o.formatUrl)("https:",i),data:c,timeout:e._timeout,method:"POST",header:a,success:function(t){r(t)},fail:function(t){n(t)},complete:function(t){if(t&&t.errMsg&&(e._timeout&&-1!==e._restrictedMethods.indexOf("post")&&"request:fail timeout"===t.errMsg)){console.warn(e._timeoutMsg);try{s.abort()}catch(t){}}}})}))},e.prototype.upload=function(t){var e=this,r=this;return new Promise((function(n){return a(e,void 0,void 0,(function(){var e,o,i,a,u,l;return s(this,(function(s){return e=t.url,o=t.file,i=t.data,a=t.headers,u=t.onUploadProgress,l=wx.uploadFile({url:e,filePath:o,name:"file",formData:c({},i),header:a,timeout:this._timeout,success:function(t){var e={statusCode:t.statusCode,data:t.data||{}};200===t.statusCode&&i.success_action_status&&(e.statusCode=parseInt(i.success_action_status,10)),n(e)},fail:function(t){n(t)},complete:function(t){if(t&&t.errMsg&&(r._timeout&&-1!==r._restrictedMethods.indexOf("upload")&&"request:fail timeout"===t.errMsg)){console.warn(r._timeoutMsg);try{l.abort()}catch(t){}}}}),u&&l.onProgressUpdate((function(t){u(t)})),[2]}))}))}))},e.prototype.download=function(t){var e=this,r=this;return new Promise((function(n,i){var c=t.url,a=t.headers,s=wx.downloadFile({url:(0,o.formatUrl)("https:",c),header:a,timeout:e._timeout,success:function(t){200===t.statusCode&&t.tempFilePath?n({statusCode:200,tempFilePath:t.tempFilePath}):n(t)},fail:function(t){i(t)},complete:function(t){if(t&&t.errMsg&&(r._timeout&&-1!==r._restrictedMethods.indexOf("download")&&"request:fail timeout"===t.errMsg)){console.warn(r._timeoutMsg);try{s.abort()}catch(t){}}}})}))},e}(o.AbstractSDKRequest),l={setItem:function(t,e){wx.setStorageSync(t,e)},getItem:function(t){return wx.getStorageSync(t)},removeItem:function(t){wx.removeStorageSync(t)},clear:function(){wx.clearStorageSync()}},f=function(t,e){void 0===e&&(e={});var r=wx.connectSocket(c({url:t},e));return{set onopen(t){r.onOpen(t)},set onmessage(t){r.onMessage(t)},set onclose(t){r.onClose(t)},set onerror(t){r.onError(t)},send:function(t){return r.send({data:t})},close:function(t,e){return r.close({code:t,reason:e})},get readyState(){return r.readyState},CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3}};const p={genAdapter:function(){return{root:{},reqClass:u,wsClass:f,localStorage:l,primaryStorage:o.StorageType.local,getAppSign:function(){var t=wx.getAccountInfoSync();return"undefined"!=typeof App||"undefined"!=typeof getApp||wx.onAppHide||wx.offAppHide||wx.onAppShow||wx.offAppShow?t&&t.miniProgram?t.miniProgram.appId:"":t&&t.plugin?t.plugin.appId:""}}},isMatch:function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(t){return!1}return!0},runtime:"wx_mp"}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{var t=n;Object.defineProperty(t,"__esModule",{value:!0}),t.adapterForWxMp=t.CloudbaseCache=t.CloudbaseEventEmitter=t.catchErrorsDecorator=t.COMMUNITY_SITE_URL=t.ERRORS=t.throwError=t.printWarn=void 0;var e=r(3);Object.defineProperty(t,"printWarn",{enumerable:!0,get:function(){return e.printWarn}}),Object.defineProperty(t,"throwError",{enumerable:!0,get:function(){return e.throwError}});var o=r(254);Object.defineProperty(t,"ERRORS",{enumerable:!0,get:function(){return o.ERRORS}}),Object.defineProperty(t,"COMMUNITY_SITE_URL",{enumerable:!0,get:function(){return o.COMMUNITY_SITE_URL}});var i=r(731);Object.defineProperty(t,"catchErrorsDecorator",{enumerable:!0,get:function(){return i.catchErrorsDecorator}});var c=r(424);Object.defineProperty(t,"CloudbaseEventEmitter",{enumerable:!0,get:function(){return c.CloudbaseEventEmitter}});var a=r(442);Object.defineProperty(t,"CloudbaseCache",{enumerable:!0,get:function(){return a.CloudbaseCache}});var s=r(399);Object.defineProperty(t,"adapterForWxMp",{enumerable:!0,get:function(){return s.defualt}})})(),n})());
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@cloudbase/auth",
3
- "version": "2.5.49-beta.1",
3
+ "version": "2.5.49-beta.3",
4
4
  "description": "cloudbase javascript sdk auth componets",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
+ "miniprogram": "dist/miniprogram",
7
8
  "scripts": {
8
9
  "tsc": "rm -rf dist/ && tsc -p tsconfig.esm.json && tsc -p tsconfig.json",
9
10
  "lint": "eslint --fix \"./src/**/*.ts\"",
10
- "build": "npm run lint && npm run tsc",
11
+ "build": "npm run lint && npm run tsc && npm run build:mp",
12
+ "tsc:mp": "tsc -p tsconfig.esm.json --outDir dist/miniprogram",
13
+ "build:mp": "npm run tsc:mp && webpack --config ./webpack/webpack.miniprogram.js",
11
14
  "precommit": "npm run lint"
12
15
  },
13
16
  "publishConfig": {
@@ -28,8 +31,9 @@
28
31
  "author": "",
29
32
  "license": "Apache-2.0",
30
33
  "dependencies": {
31
- "@cloudbase/oauth": "^2.5.49-beta.1",
32
- "@cloudbase/utilities": "^2.5.49-beta.0"
34
+ "@cloudbase/oauth": "^2.5.49-beta.3",
35
+ "@cloudbase/utilities": "^2.5.49-beta.0",
36
+ "cloudbase-adapter-wx_mp": "0.2.0"
33
37
  },
34
38
  "devDependencies": {
35
39
  "@cloudbase/types": "^2.5.49-beta.0"
package/src/adapter.ts CHANGED
@@ -1,5 +1,5 @@
1
- import adapterForWxMp from 'cloudbase-adapter-wx_mp'
2
- import { AuthOptions } from '@cloudbase/oauth'
1
+ import { adapterForWxMp } from './utilities'
2
+ import type { AuthOptions } from '@cloudbase/oauth'
3
3
 
4
4
  declare const wx: any
5
5
 
package/src/index.ts CHANGED
@@ -1,23 +1,26 @@
1
1
  import type { ICloudbase, ICloudbaseConfig } from '@cloudbase/types'
2
- import { utils, constants, helpers, events } from '@cloudbase/utilities'
3
2
  import type { ICloudbaseCache } from '@cloudbase/types/cache'
4
3
  import type { ICloudbaseRequest } from '@cloudbase/types/request'
5
4
  import type { ICloudbaseAuthConfig, IUser, IUserInfo, ILoginState } from '@cloudbase/types/auth'
6
5
  import type { ICloudbaseComponent } from '@cloudbase/types/component'
7
6
 
8
7
  import { authModels, CloudbaseOAuth, AuthOptions, Credentials } from '@cloudbase/oauth'
9
- import { GrantProviderTokenResponse, ProviderSubType } from '@cloudbase/oauth/dist/cjs/auth/models'
8
+ import type { GrantProviderTokenResponse, ProviderSubType } from '@cloudbase/oauth/dist/cjs/auth/models'
10
9
  import { useAuthAdapter } from './adapter'
11
- import adapterForWxMp from 'cloudbase-adapter-wx_mp'
10
+ import {
11
+ printWarn,
12
+ throwError,
13
+ ERRORS,
14
+ COMMUNITY_SITE_URL,
15
+ catchErrorsDecorator,
16
+ CloudbaseEventEmitter,
17
+ CloudbaseCache,
18
+ adapterForWxMp,
19
+ } from './utilities'
12
20
 
13
21
  declare const cloudbase: ICloudbase
14
22
  declare const wx: any
15
23
 
16
- const { printWarn, throwError } = utils
17
- const { ERRORS, COMMUNITY_SITE_URL } = constants
18
- const { catchErrorsDecorator } = helpers
19
- const { CloudbaseEventEmitter } = events
20
-
21
24
  const COMPONENT_NAME = 'auth'
22
25
 
23
26
  const EVENTS = {
@@ -1069,6 +1072,12 @@ class Auth {
1069
1072
  public async getCredentials(): Promise<Credentials> {
1070
1073
  return this.oauthInstance.authApi.getCredentials()
1071
1074
  }
1075
+ /**
1076
+ * 写入身份信息
1077
+ */
1078
+ public async setCredentials(credentials: Credentials) {
1079
+ await this.oauthInstance.oauth2client.setCredentials(credentials)
1080
+ }
1072
1081
 
1073
1082
  @catchErrorsDecorator({
1074
1083
  title: '获取身份源类型',
@@ -1120,18 +1129,19 @@ export function generateAuthInstance(
1120
1129
  clientId: ICloudbaseConfig['clientId']
1121
1130
  env: ICloudbaseConfig['env']
1122
1131
  apiOrigin: string
1123
- cache: ICloudbase['cache']
1132
+ cache?: ICloudbaseCache
1124
1133
  platform?: ICloudbase['platform']
1125
1134
  app?: ICloudbase
1126
1135
  debug?: ICloudbaseAuthConfig['debug']
1127
1136
  },
1128
1137
  ) {
1138
+ const { region = 'ap-shanghai' } = config
1129
1139
  const { runtime } = options?.platform || {}
1130
1140
 
1131
1141
  const { env, clientId, debug, cache, app: cloudbase } = options || {}
1132
1142
  let { apiOrigin } = options || {}
1133
1143
  if (!apiOrigin) {
1134
- apiOrigin = `https://${env}.${config.region}.tcb-api.tencentcloudapi.com`
1144
+ apiOrigin = `https://${env}.${region}.tcb-api.tencentcloudapi.com`
1135
1145
  }
1136
1146
  const oauthInstance = new CloudbaseOAuth(useAuthAdapter({
1137
1147
  env,
@@ -1148,11 +1158,17 @@ export function generateAuthInstance(
1148
1158
 
1149
1159
  const authInstance = new Auth({
1150
1160
  env,
1151
- region: config.region,
1161
+ region,
1152
1162
  persistence: config.persistence,
1153
1163
  debug,
1154
- cache,
1155
- runtime,
1164
+ cache:
1165
+ cache
1166
+ || new CloudbaseCache({
1167
+ persistence: config.persistence,
1168
+ keys: { userInfoKey: `user_info_${env}` },
1169
+ platformInfo: options?.platform,
1170
+ }),
1171
+ runtime: runtime || 'web',
1156
1172
  _fromApp: cloudbase,
1157
1173
  oauthInstance,
1158
1174
  })
@@ -0,0 +1,7 @@
1
+ // 为了减少小程序体积,导出方法并 boudle,同时防止其中使用了 web 运行环境
2
+ export { printWarn, throwError } from '@cloudbase/utilities/dist/cjs/libs/util'
3
+ export { ERRORS, COMMUNITY_SITE_URL } from '@cloudbase/utilities/dist/cjs/constants'
4
+ export { catchErrorsDecorator } from '@cloudbase/utilities/dist/cjs/helpers'
5
+ export { CloudbaseEventEmitter } from '@cloudbase/utilities/dist/cjs/libs/events'
6
+ export { CloudbaseCache } from '@cloudbase/utilities/dist/cjs/libs/cache'
7
+ export { defualt as adapterForWxMp } from 'cloudbase-adapter-wx_mp'
@@ -0,0 +1,81 @@
1
+ const webpack = require('webpack')
2
+ const TerserPlugin = require('terser-webpack-plugin')
3
+ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
4
+
5
+ module.exports = function (options) {
6
+ const { context, entry, output, mode, watch, externals, definePlugin = {}, optimization = {} } = options
7
+ const isDevelopment = mode !== 'production'
8
+ let plugins = [
9
+ new webpack.DefinePlugin(
10
+ Object.assign(
11
+ {
12
+ 'globalThis.IS_MP_BUILD': false,
13
+ },
14
+ definePlugin,
15
+ ),
16
+ ),
17
+ // new BundleAnalyzerPlugin(),
18
+ ].filter((item) => !!item)
19
+ return {
20
+ context,
21
+ entry,
22
+ mode,
23
+ watch,
24
+ watchOptions: {
25
+ ignored: [output.path],
26
+ },
27
+ output,
28
+ externals,
29
+ cache: {
30
+ type: 'memory',
31
+ },
32
+ devtool: false,
33
+ resolve: {
34
+ extensions: ['.ts', '.js', '.json'],
35
+ },
36
+ module: {
37
+ rules: [
38
+ {
39
+ test: /\.ts$/,
40
+ exclude: [/node_modules/],
41
+ use: ['babel-loader', 'ts-loader'],
42
+ },
43
+ {
44
+ test: /\.js$/,
45
+ exclude: [/node_modules/],
46
+ use: ['babel-loader'],
47
+ },
48
+ {
49
+ test: /package\.json$/,
50
+ loader: 'package-json-cleanup-loader',
51
+ options: {
52
+ only: ['version'],
53
+ },
54
+ },
55
+ ],
56
+ noParse: [/sjcl\.js$/],
57
+ },
58
+ plugins,
59
+ optimization: {
60
+ emitOnErrors: false,
61
+ removeEmptyChunks: true,
62
+ usedExports: true,
63
+ ...optimization,
64
+ ...(isDevelopment
65
+ ? {
66
+ minimize: false,
67
+ removeAvailableModules: false,
68
+ concatenateModules: true,
69
+ }
70
+ : {
71
+ minimizer: [
72
+ new TerserPlugin({
73
+ test: /\.js(\?.*)?$/i,
74
+ cache: false,
75
+ parallel: true,
76
+ }),
77
+ ],
78
+ }),
79
+ },
80
+ }
81
+ }
@@ -0,0 +1,29 @@
1
+ const path = require('path')
2
+
3
+ const params = {
4
+ context: path.resolve(__dirname, '../../'),
5
+ mode: 'production',
6
+ watch: false,
7
+ entry: path.resolve(__dirname, '../src/utilities.ts'),
8
+ output: {
9
+ path: path.resolve(__dirname, '../dist/miniprogram'),
10
+ filename: 'utilities.js',
11
+ library: `cloudbase_auth_utilities`,
12
+ libraryTarget: 'umd',
13
+ umdNamedDefine: true,
14
+ globalObject: 'typeof window !== "undefined"?window:this',
15
+ },
16
+ externals: {
17
+ '@cloudbase/oauth': {
18
+ root: 'tcboauth',
19
+ commonjs: '@cloudbase/oauth',
20
+ commonjs2: '@cloudbase/oauth',
21
+ amd: '@cloudbase/oauth',
22
+ },
23
+ },
24
+ definePlugin: {
25
+ 'process.env.NODE_ENV': JSON.stringify('production'), // 注入环境变量,用于业务代码判断
26
+ },
27
+ }
28
+
29
+ module.exports = require('./web.prod.js')(params)