Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ourea/doraemon-kit

Package Overview
Dependencies
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ourea/doraemon-kit - npm Package Compare versions

Comparing version 1.0.31-alpha to 1.0.31-alpha.1

2

dist/index.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("doraemon-kit",[],t):"object"==typeof exports?exports["doraemon-kit"]=t():e["doraemon-kit"]=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);const n="function"==typeof btoa,o="function"==typeof Buffer,a=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),c=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],u=((e=>{let t={};e.forEach((e,r)=>t[e]=r)})(c),String.fromCharCode.bind(String)),i=("function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/[+\/]/g,e=>"+"==e?"-":"_").replace(/=+$/m,"")),s=e=>{let t,r,n,o,a="";const u=e.length%3;for(let u=0;u<e.length;){if((r=e.charCodeAt(u++))>255||(n=e.charCodeAt(u++))>255||(o=e.charCodeAt(u++))>255)throw new TypeError("invalid character found");t=r<<16|n<<8|o,a+=c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[63&t]}return u?a.slice(0,u-3)+"===".substring(u):a},f=n?e=>btoa(e):o?e=>Buffer.from(e,"binary").toString("base64"):s,p=o?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,n=e.length;r<n;r+=4096)t.push(u.apply(null,e.subarray(r,r+4096)));return f(t.join(""))},d=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?u(192|t>>>6)+u(128|63&t):u(224|t>>>12&15)+u(128|t>>>6&63)+u(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return u(240|t>>>18&7)+u(128|t>>>12&63)+u(128|t>>>6&63)+u(128|63&t)},l=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,m=e=>e.replace(l,d),h=o?e=>Buffer.from(e,"utf8").toString("base64"):a?e=>p(a.encode(e)):e=>f(m(e)),g=(e,t=!1)=>t?i(h(e)):h(e),y=g;function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){_(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var O=function(e,t){t.injectBefore((function(t){var r=t.url,n=t.opt,o=n.headers,a=n.params,c=e.getters["doraemon/oauth/ssoToken"],u=e.getters["doraemon/oauth/captchaKey"],i=e.getters["doraemon/oauth/captchaCode"],s=e.getters["doraemon/oauth/tokenInfo"]||{},f=s.access_token,p=s.token_type,d=s.tenant_id,l=e.getters["doraemon/oauth/clientInfo"],m=l.client_id,h=l.client_secret;if(o.Authorization="Basic ".concat(btoa("".concat(m,":").concat(h))),r.indexOf("/doraemon-oauth/oauth/token")>=0){var g=a.tenantId;(g||d)&&(o["Tenant-Id"]=g||d)}else if(u&&i&&(o["Captcha-Code"]=u,o["Captcha-Key"]="".concat(y(i))),f&&p)o.auth="".concat(p," ").concat(f);else{if(!c){var v=new Error;throw v.message="缺少鉴权信息",v.code=401,v}o.auth="bearer ".concat(c)}return{url:r,opt:b(b({},n),{},{headers:o})}}))},w={headers:{"Content-Type":"application/x-www-form-urlencoded"}};function k(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function x(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){k(a,n,o,c,u,"next",e)}function u(e){k(a,n,o,c,u,"throw",e)}c(void 0)}))}}function P(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function j(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?j(Object(r),!0).forEach((function(t){E(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):j(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function E(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function R(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function D(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){R(a,n,o,c,u,"next",e)}function u(e){R(a,n,o,c,u,"throw",e)}c(void 0)}))}}var I={clientInfo:{client_id:"usercenter",client_secret:"1186045d5599de6ef2ca282347a55ca2",scope:"all"},userInfo:null,token:null,ssoToken:null,currentOrg:"",captchaKey:"",captchaCode:""},A=function(e){var t=function(e){return{login:(o=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-oauth/oauth/token",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return o.apply(this,arguments)}),refresh:(n=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r.grant_type="refresh_token",r.scope="all",t.next=4,e.post("/doraemon-oauth/oauth/token",r,w);case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)}))),function(e){return n.apply(this,arguments)}),ssoLogin:(r=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-oauth/oauth/token",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return r.apply(this,arguments)}),getUserInfo:(t=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.get("/doraemon-user/user/getByUserName",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return t.apply(this,arguments)})};var t,r,n,o}(e);return{login:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p,d,l,m,h,g,y;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,a=e.state,c=e.dispatch,u=a.clientInfo,i=T(T({},r),{},{scope:u.scope}),n.next=5,t.login(i);case 5:if(!(s=n.sent).code||"200"!=="".concat(s.code)){n.next=16;break}return delete(f=T({},s)).success,delete f.code,p=f.access_token,d=f.token_type,l=f.refresh_token,m=f.expires_in,h=f.tenant_id,g=P(f,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:p,token_type:d,refresh_token:l,expires_in:m,tenant_id:h,last:(new Date).getTime()}),y={userName:g.user_name},n.next=15,c("getUserInfo",y);case 15:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c("refresh",{refresh_token:l});case 2:case"end":return e.stop()}}),e)}))),m/3*2*1e3);case 16:return n.abrupt("return",s);case 17:case"end":return n.stop()}}),n)})))()},ssoLogin:function(e,t){return D(regeneratorRuntime.mark((function r(){var n,o,a,c,u,i,s,f,p;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.commit,e.state,o=e.dispatch,a=t.access_token,c=t.token_type,u=t.refresh_token,i=t.expires_in,s=t.tenant_id,f=P(t,["access_token","token_type","refresh_token","expires_in","tenant_id"]),n("UPDATE_TOKEN",{access_token:a,token_type:c,refresh_token:u,expires_in:i,tenant_id:s,last:(new Date).getTime()}),p={userName:f.user_name},r.next=6,o("getUserInfo",p);case 6:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o("refresh",{refresh_token:u});case 2:case"end":return e.stop()}}),e)}))),i/3*2*1e3);case 7:case"end":return r.stop()}}),r)})))()},refresh:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p,d,l,m;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,e.rootGetters,a=e.dispatch,e.state,n.next=3,t.refresh(r);case 3:if(!(c=n.sent).code||"200"!=="".concat(c.code)){n.next=14;break}return delete(u=T({},c)).success,delete u.code,i=u.access_token,s=u.token_type,f=u.refresh_token,p=u.expires_in,d=u.tenant_id,l=P(u,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:i,token_type:s,refresh_token:f,expires_in:p,tenant_id:d,last:(new Date).getTime()}),m={userName:l.user_name},n.next=13,a("getUserInfo",m);case 13:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a("refresh",{refresh_token:f});case 2:case"end":return e.stop()}}),e)}))),p/3*2*1e3);case 14:return n.abrupt("return",c);case 15:case"end":return n.stop()}}),n)})))()},getUserInfo:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,n.next=3,t.getUserInfo(r);case 3:(a=n.sent).code&&"200"==="".concat(a.code)&&o("SET_USER_INFO",a.data);case 5:case"end":return n.stop()}}),n)})))()}}},C={UPDATE_CAPTCHA_KEY:function(e,t){e.captchaKey=t},UPDATE_CAPTCHA_CODE:function(e,t){e.captchaCode=t},UPDATE_SSO_TOKEN:function(e,t){e.ssoToken=t},UPDATE_TOKEN:function(e,t){e.token=t},SET_USER_INFO:function(e,t){e.userInfo=t;var r=t.currentOrg,n=t.organizationId;e.currentOrg=r||n},UPDATE_CURRENT_ORG:function(e,t){e.currentOrg=t},UPDATE_LAST_REFRESH_TIME:function(e,t){e.lastRefreshTime=t}},S={captchaKey:function(e){return e.captchaKey},captchaCode:function(e){return e.captchaCode},ssoToken:function(e){return e.ssoToken},tokenInfo:function(e){return e.token},userInfo:function(e){return e.userInfo},clientInfo:function(e){return e.clientInfo},lastRefreshTime:function(e){return e.lastRefreshTime},currentOrgId:function(e){return e.currentOrg},userOrgId:function(e){return e.userInfo?e.userInfo.organizationId:""}},U=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return{namespaced:!0,state:T(T(T({},I),t),r),actions:A(e),mutations:C,getters:S}},M=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};console.log("registerModule","->","doraemon/oauth: start"),e.hasModule("doraemon/oauth")||(console.log("registerModule","->","doraemon/oauth"),e.registerModule(["doraemon","oauth"],U(t,e.state.doraemon.oauth||{},r)))};function N(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function K(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){N(a,n,o,c,u,"next",e)}function u(e){N(a,n,o,c,u,"throw",e)}c(void 0)}))}}function B(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}var F=function(e){return{dict:(t=regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-propertydict/propertyDict/listByPrefix",{prefix:r},w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})),r=function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(e){B(a,n,o,c,u,"next",e)}function u(e){B(a,n,o,c,u,"throw",e)}c(void 0)}))},function(e){return r.apply(this,arguments)})};var t,r};function H(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?H(Object(r),!0).forEach((function(t){L(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function L(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function G(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}var Y={dictMap:{}},W=function(e){var t=F(e);return{getDictionary:function(e,r){return(n=regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(o=e.commit,a=e.state,c=a.dictMap,u=r.code,i=r.cache,s=void 0===i||i,!c.hasOwnProperty(u)||!s){n.next=10;break}return n.next=7,Promise.resolve(c[u]);case 7:return n.abrupt("return",n.sent);case 10:return n.next=12,t.dict(u);case 12:(f=n.sent).code&&"200"==="".concat(f.code)&&(p=f.data.map((function(e){return{name:e.displayName,value:e.id,_data:e}})),o("UPDATE_DICT_CACHE",L({},u,p)));case 14:case"end":return n.stop()}}),n)})),function(){var e=this,t=arguments;return new Promise((function(r,o){var a=n.apply(e,t);function c(e){G(a,r,o,c,u,"next",e)}function u(e){G(a,r,o,c,u,"throw",e)}c(void 0)}))})();var n}}},q={UPDATE_DICT_CACHE:function(e,t){e.dictMap=Object.assign({},e.dictMap,t)}},J={},Q=function(e,t){console.log("registerModule","->","doraemon/dictionary: start"),e.hasModule("doraemon/dictionary")||(console.log("registerModule","->","doraemon/dictionary"),e.registerModule(["doraemon","dictionary"],function(e,t){return{namespaced:!0,state:z(z({},Y),t),actions:W(e),mutations:q,getters:J}}(t,e.state.doraemon.dictionary||{})))};window&&(window.__POWER_BY_DORAEMON_KIT__=!0);t.default={Oauth:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};arguments.length>4&&void 0!==arguments[4]&&arguments[4];t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),M(t,r,n),O(t,r),e.prototype.do_refresh_token=function(){var e=K(regeneratorRuntime.mark((function e(r){var n,o,a,c,u,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=t.getters["doraemon/oauth/tokenInfo"])||!n.refresh_token){e.next=14;break}if(o=n.expires_in,a=n.refresh_token,c=n.last,u=1e3*o,!((i=Date.now()-c)>u)){e.next=13;break}if(!r){e.next=10;break}r(),e.next=11;break;case 10:throw new Error("超过token刷新时间请跳转到登录页。");case 11:e.next=14;break;case 13:setTimeout(K(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.dispatch("doraemon/oauth/refresh",{refresh_token:a});case 2:case"end":return e.stop()}}),e)}))),u-i);case 14:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.prototype.do_sso_by_token=function(){var e=K(regeneratorRuntime.mark((function e(r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.commit("doraemon/oauth/UPDATE_SSO_TOKEN",r),e.t0=n,!e.t0){e.next=5;break}return e.next=5,t.dispatch("doraemon/oauth/getUserInfo",{userName:n});case 5:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},Dictionary:function(e,t,r){arguments.length>3&&void 0!==arguments[3]&&arguments[3];t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),Q(t,r)}}}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("doraemon-kit",[],t):"object"==typeof exports?exports["doraemon-kit"]=t():e["doraemon-kit"]=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);const n="function"==typeof btoa,o="function"==typeof Buffer,a=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),c=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],u=((e=>{let t={};e.forEach((e,r)=>t[e]=r)})(c),String.fromCharCode.bind(String)),i=("function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/[+\/]/g,e=>"+"==e?"-":"_").replace(/=+$/m,"")),s=e=>{let t,r,n,o,a="";const u=e.length%3;for(let u=0;u<e.length;){if((r=e.charCodeAt(u++))>255||(n=e.charCodeAt(u++))>255||(o=e.charCodeAt(u++))>255)throw new TypeError("invalid character found");t=r<<16|n<<8|o,a+=c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[63&t]}return u?a.slice(0,u-3)+"===".substring(u):a},f=n?e=>btoa(e):o?e=>Buffer.from(e,"binary").toString("base64"):s,p=o?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,n=e.length;r<n;r+=4096)t.push(u.apply(null,e.subarray(r,r+4096)));return f(t.join(""))},d=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?u(192|t>>>6)+u(128|63&t):u(224|t>>>12&15)+u(128|t>>>6&63)+u(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return u(240|t>>>18&7)+u(128|t>>>12&63)+u(128|t>>>6&63)+u(128|63&t)},l=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,m=e=>e.replace(l,d),h=o?e=>Buffer.from(e,"utf8").toString("base64"):a?e=>p(a.encode(e)):e=>f(m(e)),g=(e,t=!1)=>t?i(h(e)):h(e),y=g;function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){_(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var O=function(e,t){t.injectBefore((function(t){var r=t.url,n=t.opt,o=n.headers,a=n.params,c=e.getters["doraemon/oauth/ssoToken"],u=e.getters["doraemon/oauth/captchaKey"],i=e.getters["doraemon/oauth/captchaCode"],s=e.getters["doraemon/oauth/tokenInfo"]||{},f=s.access_token,p=s.token_type,d=s.tenant_id,l=e.getters["doraemon/oauth/clientInfo"],m=l.client_id,h=l.client_secret;if(o.Authorization="Basic ".concat(btoa("".concat(m,":").concat(h))),r.indexOf("/doraemon-oauth/oauth/token")>=0){var g=a.tenantId;(g||d)&&(o["Tenant-Id"]=g||d)}else if(u&&i&&(o["Captcha-Key"]=u,o["Captcha-Code"]="".concat(y(i))),f&&p)o.auth="".concat(p," ").concat(f);else{if(!c){var v=new Error;throw v.message="缺少鉴权信息",v.code=401,v}o.auth="bearer ".concat(c)}return{url:r,opt:b(b({},n),{},{headers:o})}}))},w={headers:{"Content-Type":"application/x-www-form-urlencoded"}};function k(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function x(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){k(a,n,o,c,u,"next",e)}function u(e){k(a,n,o,c,u,"throw",e)}c(void 0)}))}}function P(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function j(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?j(Object(r),!0).forEach((function(t){E(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):j(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function E(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function R(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function D(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){R(a,n,o,c,u,"next",e)}function u(e){R(a,n,o,c,u,"throw",e)}c(void 0)}))}}var I={clientInfo:{client_id:"usercenter",client_secret:"1186045d5599de6ef2ca282347a55ca2",scope:"all"},userInfo:null,token:null,ssoToken:null,currentOrg:"",captchaKey:"",captchaCode:""},A=function(e){var t=function(e){return{login:(o=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-oauth/oauth/token",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return o.apply(this,arguments)}),refresh:(n=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r.grant_type="refresh_token",r.scope="all",t.next=4,e.post("/doraemon-oauth/oauth/token",r,w);case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)}))),function(e){return n.apply(this,arguments)}),ssoLogin:(r=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-oauth/oauth/token",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return r.apply(this,arguments)}),getUserInfo:(t=x(regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.get("/doraemon-user/user/getByUserName",r,w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(e){return t.apply(this,arguments)})};var t,r,n,o}(e);return{login:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p,d,l,m,h,g,y;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,a=e.state,c=e.dispatch,u=a.clientInfo,i=T(T({},r),{},{scope:u.scope}),n.next=5,t.login(i);case 5:if(!(s=n.sent).code||"200"!=="".concat(s.code)){n.next=16;break}return delete(f=T({},s)).success,delete f.code,p=f.access_token,d=f.token_type,l=f.refresh_token,m=f.expires_in,h=f.tenant_id,g=P(f,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:p,token_type:d,refresh_token:l,expires_in:m,tenant_id:h,last:(new Date).getTime()}),y={userName:g.user_name},n.next=15,c("getUserInfo",y);case 15:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c("refresh",{refresh_token:l});case 2:case"end":return e.stop()}}),e)}))),m/3*2*1e3);case 16:return n.abrupt("return",s);case 17:case"end":return n.stop()}}),n)})))()},ssoLogin:function(e,t){return D(regeneratorRuntime.mark((function r(){var n,o,a,c,u,i,s,f,p;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.commit,e.state,o=e.dispatch,a=t.access_token,c=t.token_type,u=t.refresh_token,i=t.expires_in,s=t.tenant_id,f=P(t,["access_token","token_type","refresh_token","expires_in","tenant_id"]),n("UPDATE_TOKEN",{access_token:a,token_type:c,refresh_token:u,expires_in:i,tenant_id:s,last:(new Date).getTime()}),p={userName:f.user_name},r.next=6,o("getUserInfo",p);case 6:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o("refresh",{refresh_token:u});case 2:case"end":return e.stop()}}),e)}))),i/3*2*1e3);case 7:case"end":return r.stop()}}),r)})))()},refresh:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p,d,l,m;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,e.rootGetters,a=e.dispatch,e.state,n.next=3,t.refresh(r);case 3:if(!(c=n.sent).code||"200"!=="".concat(c.code)){n.next=14;break}return delete(u=T({},c)).success,delete u.code,i=u.access_token,s=u.token_type,f=u.refresh_token,p=u.expires_in,d=u.tenant_id,l=P(u,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:i,token_type:s,refresh_token:f,expires_in:p,tenant_id:d,last:(new Date).getTime()}),m={userName:l.user_name},n.next=13,a("getUserInfo",m);case 13:setTimeout(D(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a("refresh",{refresh_token:f});case 2:case"end":return e.stop()}}),e)}))),p/3*2*1e3);case 14:return n.abrupt("return",c);case 15:case"end":return n.stop()}}),n)})))()},getUserInfo:function(e,r){return D(regeneratorRuntime.mark((function n(){var o,a;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,n.next=3,t.getUserInfo(r);case 3:(a=n.sent).code&&"200"==="".concat(a.code)&&o("SET_USER_INFO",a.data);case 5:case"end":return n.stop()}}),n)})))()}}},C={UPDATE_CAPTCHA_KEY:function(e,t){e.captchaKey=t},UPDATE_CAPTCHA_CODE:function(e,t){e.captchaCode=t},UPDATE_SSO_TOKEN:function(e,t){e.ssoToken=t},UPDATE_TOKEN:function(e,t){e.token=t},SET_USER_INFO:function(e,t){e.userInfo=t;var r=t.currentOrg,n=t.organizationId;e.currentOrg=r||n},UPDATE_CURRENT_ORG:function(e,t){e.currentOrg=t},UPDATE_LAST_REFRESH_TIME:function(e,t){e.lastRefreshTime=t}},S={captchaKey:function(e){return e.captchaKey},captchaCode:function(e){return e.captchaCode},ssoToken:function(e){return e.ssoToken},tokenInfo:function(e){return e.token},userInfo:function(e){return e.userInfo},clientInfo:function(e){return e.clientInfo},lastRefreshTime:function(e){return e.lastRefreshTime},currentOrgId:function(e){return e.currentOrg},userOrgId:function(e){return e.userInfo?e.userInfo.organizationId:""}},U=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return{namespaced:!0,state:T(T(T({},I),t),r),actions:A(e),mutations:C,getters:S}},M=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};console.log("registerModule","->","doraemon/oauth: start"),e.hasModule("doraemon/oauth")||(console.log("registerModule","->","doraemon/oauth"),e.registerModule(["doraemon","oauth"],U(t,e.state.doraemon.oauth||{},r)))};function N(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}function K(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){N(a,n,o,c,u,"next",e)}function u(e){N(a,n,o,c,u,"throw",e)}c(void 0)}))}}function B(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}var F=function(e){return{dict:(t=regeneratorRuntime.mark((function t(r){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.post("/doraemon-propertydict/propertyDict/listByPrefix",{prefix:r},w);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})),r=function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(e){B(a,n,o,c,u,"next",e)}function u(e){B(a,n,o,c,u,"throw",e)}c(void 0)}))},function(e){return r.apply(this,arguments)})};var t,r};function H(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?H(Object(r),!0).forEach((function(t){L(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function L(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function G(e,t,r,n,o,a,c){try{var u=e[a](c),i=u.value}catch(e){return void r(e)}u.done?t(i):Promise.resolve(i).then(n,o)}var Y={dictMap:{}},W=function(e){var t=F(e);return{getDictionary:function(e,r){return(n=regeneratorRuntime.mark((function n(){var o,a,c,u,i,s,f,p;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(o=e.commit,a=e.state,c=a.dictMap,u=r.code,i=r.cache,s=void 0===i||i,!c.hasOwnProperty(u)||!s){n.next=10;break}return n.next=7,Promise.resolve(c[u]);case 7:return n.abrupt("return",n.sent);case 10:return n.next=12,t.dict(u);case 12:(f=n.sent).code&&"200"==="".concat(f.code)&&(p=f.data.map((function(e){return{name:e.displayName,value:e.id,_data:e}})),o("UPDATE_DICT_CACHE",L({},u,p)));case 14:case"end":return n.stop()}}),n)})),function(){var e=this,t=arguments;return new Promise((function(r,o){var a=n.apply(e,t);function c(e){G(a,r,o,c,u,"next",e)}function u(e){G(a,r,o,c,u,"throw",e)}c(void 0)}))})();var n}}},q={UPDATE_DICT_CACHE:function(e,t){e.dictMap=Object.assign({},e.dictMap,t)}},J={},Q=function(e,t){console.log("registerModule","->","doraemon/dictionary: start"),e.hasModule("doraemon/dictionary")||(console.log("registerModule","->","doraemon/dictionary"),e.registerModule(["doraemon","dictionary"],function(e,t){return{namespaced:!0,state:z(z({},Y),t),actions:W(e),mutations:q,getters:J}}(t,e.state.doraemon.dictionary||{})))};window&&(window.__POWER_BY_DORAEMON_KIT__=!0);t.default={Oauth:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};arguments.length>4&&void 0!==arguments[4]&&arguments[4];t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),M(t,r,n),O(t,r),e.prototype.do_refresh_token=function(){var e=K(regeneratorRuntime.mark((function e(r){var n,o,a,c,u,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=t.getters["doraemon/oauth/tokenInfo"])||!n.refresh_token){e.next=14;break}if(o=n.expires_in,a=n.refresh_token,c=n.last,u=1e3*o,!((i=Date.now()-c)>u)){e.next=13;break}if(!r){e.next=10;break}r(),e.next=11;break;case 10:throw new Error("超过token刷新时间请跳转到登录页。");case 11:e.next=14;break;case 13:setTimeout(K(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.dispatch("doraemon/oauth/refresh",{refresh_token:a});case 2:case"end":return e.stop()}}),e)}))),u-i);case 14:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.prototype.do_sso_by_token=function(){var e=K(regeneratorRuntime.mark((function e(r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.commit("doraemon/oauth/UPDATE_SSO_TOKEN",r),e.t0=n,!e.t0){e.next=5;break}return e.next=5,t.dispatch("doraemon/oauth/getUserInfo",{userName:n});case 5:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},Dictionary:function(e,t,r){arguments.length>3&&void 0!==arguments[3]&&arguments[3];t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),Q(t,r)}}}])}));
{
"name": "@ourea/doraemon-kit",
"version": "1.0.31-alpha",
"version": "1.0.31-alpha.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -11,2 +11,4 @@ # Doraemon-kit

## 版本更新说明:
1.0.29添加添加token单点登录的接口
1.0.29 添加添加token单点登录的接口
1.0.31 验证码登录
新增 `UPDATE_CAPTCHA_KEY` `UPDATE_CAPTCHA_CODE` 两个 `mutation`,

@@ -32,4 +32,4 @@ import { Base64 } from 'js-base64'

if (captchaKey && captchaCode) {
headers['Captcha-Code'] = captchaKey
headers['Captcha-Key'] = `${Base64.encode(captchaCode)}`
headers['Captcha-Key'] = captchaKey
headers['Captcha-Code'] = `${Base64.encode(captchaCode)}`
}

@@ -36,0 +36,0 @@ if (access_token && token_type) { // 优先使用 oauth 里面的 token 信息

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc