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.28 to 1.0.31-alpha

README.md

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";function n(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 o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.r(t);var u=function(e,t){t.injectBefore((function(t){var r=t.url,n=t.opt,a=n.headers,u=n.params,c=e.getters["doraemon/oauth/ssoToken"],i=e.getters["doraemon/oauth/tokenInfo"]||{},s=i.access_token,f=i.token_type,p=i.tenant_id,d=e.getters["doraemon/oauth/clientInfo"],l=d.client_id,m=d.client_secret;if(a.Authorization="Basic ".concat(btoa("".concat(l,":").concat(m))),r.indexOf("/doraemon-oauth/oauth/token")>=0){var h=u.tenantId;(h||p)&&(a["Tenant-Id"]=h||p)}else if(s&&f)a.auth="".concat(f," ").concat(s);else{if(!c){var g=new Error;throw g.message="缺少鉴权信息",g.code=401,g}a.auth="bearer ".concat(c)}return{url:r,opt:o(o({},n),{},{headers:a})}}))},c={headers:{"Content-Type":"application/x-www-form-urlencoded"}};function i(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.done?t(i):Promise.resolve(i).then(n,o)}function s(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function u(e){i(a,n,o,u,c,"next",e)}function c(e){i(a,n,o,u,c,"throw",e)}u(void 0)}))}}function f(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 p(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 d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){l(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(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 m(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.done?t(i):Promise.resolve(i).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function u(e){m(a,n,o,u,c,"next",e)}function c(e){m(a,n,o,u,c,"throw",e)}u(void 0)}))}}var g={clientInfo:{client_id:"usercenter",client_secret:"1186045d5599de6ef2ca282347a55ca2",scope:"all"},userInfo:null,token:null,ssoToken:null,currentOrg:""},v=function(e){var t=function(e){return{login:(o=s(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,c);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=s(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,c);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=s(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,c);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=s(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,c);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 h(regeneratorRuntime.mark((function n(){var o,a,u,c,i,s,p,l,m,g,v,y,b,O;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.commit,a=e.state,u=e.dispatch,c=a.clientInfo,i=d(d({},r),{},{scope:c.scope}),n.next=5,t.login(i);case 5:if(!(s=n.sent).code||"200"!=="".concat(s.code)){n.next=16;break}return delete(p=d({},s)).success,delete p.code,l=p.access_token,m=p.token_type,g=p.refresh_token,v=p.expires_in,y=p.tenant_id,b=f(p,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:l,token_type:m,refresh_token:g,expires_in:v,tenant_id:y,last:(new Date).getTime()}),O={userName:b.user_name},n.next=15,u("getUserInfo",O);case 15:setTimeout(h(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u("refresh",{refresh_token:g});case 2:case"end":return e.stop()}}),e)}))),v/3*2*1e3);case 16:return n.abrupt("return",s);case 17:case"end":return n.stop()}}),n)})))()},refresh:function(e,r){return h(regeneratorRuntime.mark((function n(){var o,a,u,c,i,s,p,l,m,g,v;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(!(u=n.sent).code||"200"!=="".concat(u.code)){n.next=14;break}return delete(c=d({},u)).success,delete c.code,i=c.access_token,s=c.token_type,p=c.refresh_token,l=c.expires_in,m=c.tenant_id,g=f(c,["access_token","token_type","refresh_token","expires_in","tenant_id"]),o("UPDATE_TOKEN",{access_token:i,token_type:s,refresh_token:p,expires_in:l,tenant_id:m,last:(new Date).getTime()}),v={userName:g.user_name},n.next=13,a("getUserInfo",v);case 13:setTimeout(h(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:p});case 2:case"end":return e.stop()}}),e)}))),l/3*2*1e3);case 14:return n.abrupt("return",u);case 15:case"end":return n.stop()}}),n)})))()},getUserInfo:function(e,r){return h(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)})))()}}},y={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}},b={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:""}},O=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return{namespaced:!0,state:d(d(d({},g),t),r),actions:v(e),mutations:y,getters:b}},_=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"],O(t,e.state.doraemon.oauth||{},r)))};function w(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.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 u(e){w(a,n,o,u,c,"next",e)}function c(e){w(a,n,o,u,c,"throw",e)}u(void 0)}))}}function x(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.done?t(i):Promise.resolve(i).then(n,o)}var P=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},c);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 u(e){x(a,n,o,u,c,"next",e)}function c(e){x(a,n,o,u,c,"throw",e)}u(void 0)}))},function(e){return r.apply(this,arguments)})};var t,r};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 R(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){T(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 T(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function E(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.done?t(i):Promise.resolve(i).then(n,o)}var I={dictMap:{}},D=function(e){var t=P(e);return{getDictionary:function(e,r){return(n=regeneratorRuntime.mark((function n(){var o,a,u,c,i,s,f,p;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(o=e.commit,a=e.state,u=a.dictMap,c=r.code,i=r.cache,s=void 0===i||i,!u.hasOwnProperty(c)||!s){n.next=10;break}return n.next=7,Promise.resolve(u[c]);case 7:return n.abrupt("return",n.sent);case 10:return n.next=12,t.dict(c);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",T({},c,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 u(e){E(a,r,o,u,c,"next",e)}function c(e){E(a,r,o,u,c,"throw",e)}u(void 0)}))})();var n}}},S={UPDATE_DICT_CACHE:function(e,t){e.dictMap=Object.assign({},e.dictMap,t)}},M={},U=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:R(R({},I),t),actions:D(e),mutations:S,getters:M}}(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]:{};t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),_(t,r,n),u(t,r),e.prototype.do_refresh_token=function(){var e=k(regeneratorRuntime.mark((function e(r){var n,o,a,u,c,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,u=n.last,c=1e3*o,!((i=Date.now()-u)>c)){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)}))),c-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){t.hasModule("doraemon")||t.registerModule("doraemon",{namespaced:!0,state:t.state.doraemon}),U(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-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)}}}])}));
{
"name": "@ourea/doraemon-kit",
"version": "1.0.28",
"version": "1.0.31-alpha",
"description": "",

@@ -22,2 +22,3 @@ "main": "dist/index.js",

"babel-plugin-import-glob": "^2.0.0",
"js-base64": "^3.6.1",
"marked": "^1.0.0",

@@ -24,0 +25,0 @@ "parcel-bundler": "^1.12.4",

@@ -34,3 +34,7 @@ import httpInitFunc from './init/http-init'

// 利用token做单点登录 并获取用户信息
/**
* 利用token做单点登录 并获取用户信息
* 暂不支持直接通过 token 获取用户信息,原因如下:
* 因这种接口属于 聚合接口,即使提供也是需要拿token信息转一次,再根据用户名查用户,doraemon 无法控制接口量
*/
Vue.prototype.do_sso_by_token = async (token, name) => {

@@ -37,0 +41,0 @@ store.commit('doraemon/oauth/UPDATE_SSO_TOKEN', token)

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

import { Base64 } from 'js-base64'

@@ -16,2 +17,4 @@ export default (store, http) => {

const ssoToken = store.getters['doraemon/oauth/ssoToken']
const captchaKey = store.getters['doraemon/oauth/captchaKey'] // 验证码接口生成的 key
const captchaCode = store.getters['doraemon/oauth/captchaCode'] // 验证码
const { access_token, token_type, tenant_id } = store.getters['doraemon/oauth/tokenInfo'] || {}

@@ -28,2 +31,7 @@ const { client_id, client_secret } = store.getters['doraemon/oauth/clientInfo']

} else { // 其他普通接口
// 验证码登录验证信息
if (captchaKey && captchaCode) {
headers['Captcha-Code'] = captchaKey
headers['Captcha-Key'] = `${Base64.encode(captchaCode)}`
}
if (access_token && token_type) { // 优先使用 oauth 里面的 token 信息

@@ -30,0 +38,0 @@ headers['auth'] = `${token_type} ${access_token}`

@@ -22,2 +22,4 @@ /* eslint-disable no-empty-pattern */

currentOrg: '', // 当前的一个组织机构信息
captchaKey: '', // 验证码接口生成的 key
captchaCode: '', // 验证码
}

@@ -50,2 +52,14 @@

},
async ssoLogin({ commit, state, dispatch }, payload) {
const {
access_token, token_type, refresh_token, expires_in, tenant_id, // token 相关信息
...userInfo
} = payload
commit('UPDATE_TOKEN', { access_token, token_type, refresh_token, expires_in, tenant_id, last: new Date().getTime() })
const params = { userName: userInfo.user_name }
await dispatch('getUserInfo', params)
setTimeout(async () => {
await dispatch('refresh', { refresh_token })
}, expires_in / 3 * 2 * 1000)
},
// eslint-disable-next-line no-unused-vars

@@ -82,2 +96,8 @@ async refresh({ commit, rootGetters, dispatch, state }, payload) {

const mutations = {
UPDATE_CAPTCHA_KEY(state, token) {
state.captchaKey = token
},
UPDATE_CAPTCHA_CODE(state, token) {
state.captchaCode = token
},
UPDATE_SSO_TOKEN(state, token) {

@@ -103,2 +123,8 @@ state.ssoToken = token

const getters = {
captchaKey(state) {
return state.captchaKey
},
captchaCode(state) {
return state.captchaCode
},
ssoToken(state) {

@@ -105,0 +131,0 @@ return state.ssoToken

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