@tachybase/module-auth 1.3.19 → 1.3.21

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.
@@ -26,5 +26,5 @@ export declare class PluginAuthClient extends Plugin {
26
26
  }
27
27
  export { AuthenticatorsContext, useAuthenticator } from './authenticator';
28
28
  export type { Authenticator } from './authenticator';
29
- export { useSignIn } from './basic';
29
+ export { useSignIn, useRedirect } from './basic';
30
30
  export default PluginAuthClient;
@@ -1,14 +1,14 @@
1
- (function(d,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("@tachybase/client"),require("@tachybase/utils/client"),require("react/jsx-runtime"),require("react"),require("react-router-dom"),require("@tachybase/schema"),require("react-i18next"),require("antd"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/utils/client","react/jsx-runtime","react","react-router-dom","@tachybase/schema","react-i18next","antd","@ant-design/icons"],i):(d=typeof globalThis!="undefined"?globalThis:d||self,i(d["@tachybase/module-auth"]={},d["@tachybase/client"],d["@tachybase/utils"],d.jsxRuntime,d.react,d["react-router-dom"],d["@tachybase/schema"],d["react-i18next"],d.antd,d["@ant-design/icons"]))})(this,function(d,i,g,c,f,C,v,F,x,N){"use strict";var Jt=Object.defineProperty,Qt=Object.defineProperties;var Rt=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var Ke=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable;var $e=(d,i,g)=>i in d?Jt(d,i,{enumerable:!0,configurable:!0,writable:!0,value:g}):d[i]=g,E=(d,i)=>{for(var g in i||(i={}))Ke.call(i,g)&&$e(d,g,i[g]);if(K)for(var g of K(i))We.call(i,g)&&$e(d,g,i[g]);return d},W=(d,i)=>Qt(d,Rt(i));var Ge=(d,i)=>{var g={};for(var c in d)Ke.call(d,c)&&i.indexOf(c)<0&&(g[c]=d[c]);if(d!=null&&K)for(var c of K(d))i.indexOf(c)<0&&We.call(d,c)&&(g[c]=d[c]);return g};var k=(d,i,g)=>new Promise((c,f)=>{var C=x=>{try{F(g.next(x))}catch(N){f(N)}},v=x=>{try{F(g.throw(x))}catch(N){f(N)}},F=x=>x.done?c(x.value):Promise.resolve(x.value).then(C,v);F((g=g.apply(d,i)).next())});const He="Email/Password",Xe=e=>{const o=C.useLocation(),t=i.useAPIClient();return f.useEffect(()=>{const n=new URLSearchParams(o.search),r=n.get("authenticator"),s=n.get("token");s&&(t.auth.setToken(s),t.auth.setAuthenticator(r))}),c.jsx(c.Fragment,{children:e.children})},P="auth";function w(){return F.useTranslation([P,"core"],{nsMode:"fallback"})}const q=e=>i.tval(e,{ns:P}),j=f.createContext([]);j.displayName="AuthenticatorsContext";const G=e=>f.useContext(j).find(t=>t.name===e);function ze(e){var s;const{data:o}=i.useSystemSettings(),t=i.useAPIClient(),{data:n=[],error:r}=i.useRequest(()=>t.resource("authenticators").publicList().then(a=>{var p;return((p=a==null?void 0:a.data)==null?void 0:p.data)||[]}));if(r)throw r;return c.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[c.jsx("h1",{children:(s=o==null?void 0:o.data)==null?void 0:s.title}),c.jsx(j.Provider,{value:n,children:c.jsx(C.Outlet,{})}),c.jsx("div",{className:i.css`
1
+ (function(d,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("@tachybase/client"),require("@tachybase/utils/client"),require("react/jsx-runtime"),require("react"),require("react-router-dom"),require("@tachybase/schema"),require("react-i18next"),require("antd"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/utils/client","react/jsx-runtime","react","react-router-dom","@tachybase/schema","react-i18next","antd","@ant-design/icons"],i):(d=typeof globalThis!="undefined"?globalThis:d||self,i(d["@tachybase/module-auth"]={},d["@tachybase/client"],d["@tachybase/utils"],d.jsxRuntime,d.react,d["react-router-dom"],d["@tachybase/schema"],d["react-i18next"],d.antd,d["@ant-design/icons"]))})(this,function(d,i,g,c,f,C,v,F,x,N){"use strict";var Jt=Object.defineProperty,Qt=Object.defineProperties;var Rt=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var We=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable;var Ke=(d,i,g)=>i in d?Jt(d,i,{enumerable:!0,configurable:!0,writable:!0,value:g}):d[i]=g,E=(d,i)=>{for(var g in i||(i={}))We.call(i,g)&&Ke(d,g,i[g]);if(K)for(var g of K(i))Ge.call(i,g)&&Ke(d,g,i[g]);return d},W=(d,i)=>Qt(d,Rt(i));var He=(d,i)=>{var g={};for(var c in d)We.call(d,c)&&i.indexOf(c)<0&&(g[c]=d[c]);if(d!=null&&K)for(var c of K(d))i.indexOf(c)<0&&Ge.call(d,c)&&(g[c]=d[c]);return g};var k=(d,i,g)=>new Promise((c,f)=>{var C=x=>{try{F(g.next(x))}catch(N){f(N)}},v=x=>{try{F(g.throw(x))}catch(N){f(N)}},F=x=>x.done?c(x.value):Promise.resolve(x.value).then(C,v);F((g=g.apply(d,i)).next())});const Xe="Email/Password",ze=e=>{const o=C.useLocation(),t=i.useAPIClient();return f.useEffect(()=>{const n=new URLSearchParams(o.search),r=n.get("authenticator"),s=n.get("token");s&&(t.auth.setToken(s),t.auth.setAuthenticator(r))}),c.jsx(c.Fragment,{children:e.children})},P="auth";function w(){return F.useTranslation([P,"core"],{nsMode:"fallback"})}const q=e=>i.tval(e,{ns:P}),j=f.createContext([]);j.displayName="AuthenticatorsContext";const G=e=>f.useContext(j).find(t=>t.name===e);function Ye(e){var s;const{data:o}=i.useSystemSettings(),t=i.useAPIClient(),{data:n=[],error:r}=i.useRequest(()=>t.resource("authenticators").publicList().then(a=>{var p;return((p=a==null?void 0:a.data)==null?void 0:p.data)||[]}));if(r)throw r;return c.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[c.jsx("h1",{children:(s=o==null?void 0:o.data)==null?void 0:s.title}),c.jsx(j.Provider,{value:n,children:c.jsx(C.Outlet,{})}),c.jsx("div",{className:i.css`
2
2
  position: absolute;
3
3
  bottom: 24px;
4
4
  width: 100%;
5
5
  left: 0;
6
6
  text-align: center;
7
- `,children:c.jsx(i.PoweredBy,{})})]})}const Ye=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.SignInForm&&(t[r]=s.components.SignInForm);return t},Ze=(e=[])=>{var s;const t=i.usePlugin(_).authTypes.getEntities(),n={};for(const[a,p]of t)(s=p.components)!=null&&s.SignInButton&&(n[a]=p.components.SignInButton);const r=Object.keys(n);return e.filter(a=>r.includes(a.authType)).map((a,p)=>f.createElement(n[a.authType],{key:p,authenticator:a}))},Je=()=>{const{t:e}=w();i.useCurrentDocumentTitle("Signin"),i.useViewport();const o=Ye(),t=f.useContext(j),n=Ze(t);if(!t.length)return c.jsx("div",{style:{color:"#ccc"},children:e("No authentication methods available.")});const r=t.map(s=>{const a=o[s.authType];if(!a)return;const p=`${e("Sign-in")} (${e(s.authTypeTitle||s.authType)})`;return E({component:f.createElement(a,{authenticator:s}),tabTitle:s.title||s.name==="basic"?p:`${e(s.name)}`},s)}).filter(s=>s);return c.jsxs(x.Space,{direction:"vertical",className:i.css`
7
+ `,children:c.jsx(i.PoweredBy,{})})]})}const Ze=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.SignInForm&&(t[r]=s.components.SignInForm);return t},Je=(e=[])=>{var s;const t=i.usePlugin(_).authTypes.getEntities(),n={};for(const[a,p]of t)(s=p.components)!=null&&s.SignInButton&&(n[a]=p.components.SignInButton);const r=Object.keys(n);return e.filter(a=>r.includes(a.authType)).map((a,p)=>f.createElement(n[a.authType],{key:p,authenticator:a}))},Qe=()=>{const{t:e}=w();i.useCurrentDocumentTitle("Signin"),i.useViewport();const o=Ze(),t=f.useContext(j),n=Je(t);if(!t.length)return c.jsx("div",{style:{color:"#ccc"},children:e("No authentication methods available.")});const r=t.map(s=>{const a=o[s.authType];if(!a)return;const p=`${e("Sign-in")} (${e(s.authTypeTitle||s.authType)})`;return E({component:f.createElement(a,{authenticator:s}),tabTitle:s.title||s.name==="basic"?p:`${e(s.name)}`},s)}).filter(s=>s);return c.jsxs(x.Space,{direction:"vertical",className:i.css`
8
8
  display: flex;
9
9
  `,children:[r.length>1?c.jsx(x.Tabs,{items:r.map(s=>({label:s.tabTitle,key:s.name,children:s.component}))}):r.length?c.jsx("div",{children:r[0].component}):c.jsx(c.Fragment,{}),c.jsx(x.Space,{direction:"vertical",className:i.css`
10
10
  display: flex;
11
- `,children:n})]})},Qe=f.createContext({});Qe.displayName="SignupPageContext";const me=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.SignUpForm&&(t[r]=s.components.SignUpForm);return t},Re=()=>{i.useViewport(),i.useCurrentDocumentTitle("Signup");const e=me(),[o]=C.useSearchParams(),t=o.get("name"),n=G(t),{authType:r}=n||{};return e[r]?f.createElement(e[r],{authenticatorName:t}):c.jsx(C.Navigate,{to:"/not-found",replace:!0})};function et(e="/admin"){const o=C.useNavigate(),[t]=C.useSearchParams();return f.useCallback(()=>{o(t.get("redirect")||"/admin",{replace:!0})},[o,t])}const ye=e=>{const o=v.useForm(),t=i.useAPIClient(),n=et(),{refreshAsync:r}=i.useCurrentUserContext();return{run(){return k(this,null,function*(){yield o.submit(),yield t.auth.signIn(o.values,e),yield r(),n()})}}},tt={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
11
+ `,children:n})]})},Re=f.createContext({});Re.displayName="SignupPageContext";const me=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.SignUpForm&&(t[r]=s.components.SignUpForm);return t},et=()=>{i.useViewport(),i.useCurrentDocumentTitle("Signup");const e=me(),[o]=C.useSearchParams(),t=o.get("name"),n=G(t),{authType:r}=n||{};return e[r]?f.createElement(e[r],{authenticatorName:t}):c.jsx(C.Navigate,{to:"/not-found",replace:!0})};function ye(e="/admin"){const o=C.useNavigate(),[t]=C.useSearchParams();return f.useCallback(()=>{o(t.get("redirect")||"/admin",{replace:!0})},[o,t])}const he=e=>{const o=v.useForm(),t=i.useAPIClient(),n=ye(),{refreshAsync:r}=i.useCurrentUserContext();return{run(){return k(this,null,function*(){yield o.submit(),yield t.auth.signIn(o.values,e),yield r(),n()})}}},tt={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
12
12
  if (!value) {
13
13
  return t("Please enter your username or email");
14
14
  }
@@ -19,4 +19,4 @@
19
19
  } else {
20
20
  return /^[^@.<>"'/]{2,16}$/.test(value) || t("Please enter a valid username");
21
21
  }
22
- }}}`,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username/Email")}}',style:{}}},password:{type:"string","x-component":"Password",required:!0,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',style:{}}},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useBasicSignIn }}",style:{width:"100%"}}}}},signUp:{type:"void","x-component":"Link","x-component-props":{to:"{{ signUpLink }}"},"x-content":'{{t("Create an account")}}',"x-visible":"{{ allowSignUp }}"}}},nt=e=>{const{t:o}=w(),t=e.authenticator,{authType:n,name:r,options:s}=t,p=!!me()[n]&&(s==null?void 0:s.allowSignUp),h=`/signup?name=${r}`,l=()=>ye(r);return c.jsx(i.SchemaComponent,{schema:tt,scope:{useBasicSignIn:l,allowSignUp:p,signUpLink:h,t:o}})},ot=e=>{const o=C.useNavigate(),t=v.useForm(),n=i.useAPIClient(),{t:r}=F.useTranslation();return{run(){return k(this,null,function*(){var a;yield t.submit(),yield n.auth.signUp(t.values,e==null?void 0:e.authenticator),x.message.success(((a=e==null?void 0:e.message)==null?void 0:a.success)||r("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{o("/signin")},2e3)})}}},rt={type:"object",name:v.uid(),"x-component":"FormV2",properties:{username:{type:"string",required:!0,"x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirm_password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirm_password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Confirm password")}}',style:{}},"x-reactions":[{dependencies:[".password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign up")}}',type:"void","x-component":"Action","x-component-props":{block:!0,type:"primary",htmlType:"submit",useAction:"{{ useBasicSignUp }}",style:{width:"100%"}}}}},link:{type:"void","x-component":"div",properties:{link:{type:"void","x-component":"Link","x-component-props":{to:"/signin"},"x-content":'{{t("Log in with an existing account")}}'}}}}},it=({authenticatorName:e})=>{const{t:o}=w(),t=()=>ot({authenticator:e}),n=G(e),{options:r}=n;return r!=null&&r.allowSignUp?c.jsx(i.SchemaComponent,{schema:rt,scope:{useBasicSignUp:t,t:o}}):c.jsx(C.Navigate,{to:"/not-found",replace:!0})},st=()=>{const{t:e}=w();return c.jsx(i.SchemaComponent,{scope:{t:e},components:{Alert:x.Alert},schema:{type:"object",properties:{public:{type:"object",properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox","x-component-props":{defaultChecked:!0}}}},notice:{type:"void","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}}}}})},at=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.BindForm&&(t[r]=s.components.BindForm);return t},ct=()=>{const e=i.useRecord(),t=at()[e.authType];return f.createElement(t,{authenticator:e})},ut={type:"void",name:"authenticatorBind","x-decorator":"TableBlockProvider","x-decorator-props":{collection:{name:"authenticators",sortable:!1,fields:[{interface:"input",type:"string",name:"authType"},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"bind",uiSchema:{type:"boolean",title:'{{t("Bind")}}',"x-component":"Checkbox"}},{type:"string",name:"nickname",uiSchema:{type:"string",title:'{{t("Nickname")}}',"x-component":"Input"}}]},resource:"authenticators",action:"bindTypes",params:{sort:["sort"]},rowKey:"name",showIndex:!0},"x-component":"div",properties:{table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"name"},properties:{authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0}}},title:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{description:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},bind:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{bind:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{unbind:{"x-visible":'{{ $self.query(".bind").value() }}',type:"void",title:'{{ t("Unbind") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Unbind')}}",content:"{{t('Are you sure to unbind this authenticator?')}}"},useAction:"{{ useUnbindAction }}"}},bind:{"x-visible":'{{ !$self.query(".bind").value() }}',type:"void",title:"{{ t('Bind') }}","x-component":"Action.Link",properties:{modal:{type:"void","x-decorator":"Form",title:"{{ t('Bind') }}","x-component":"Action.Modal","x-component-props":{width:800},properties:{form:{type:"void","x-component":"BindForm"}}}}}}}}}}}}},pt=()=>{const{refreshCM:e}=i.useCollectionManager_deprecated(),o=i.useAPIClient(),t=i.useRecord();return{run(){return k(this,null,function*(){yield o.resource("authenticators").unbind({authenticator:t.name}),e()})}}},lt=()=>{const{t:e}=w();return c.jsx(x.Card,{bordered:!1,children:c.jsx(i.SchemaComponent,{schema:ut,components:{BindForm:ct},scope:{t:e,useUnbindAction:pt}})})};var L=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var H,fe;function xe(){if(fe)return H;fe=1;function e(o){var t=typeof o;return o!=null&&(t=="object"||t=="function")}return H=e,H}var X,ge;function dt(){if(ge)return X;ge=1;var e=typeof L=="object"&&L&&L.Object===Object&&L;return X=e,X}var z,be;function Te(){if(be)return z;be=1;var e=dt(),o=typeof self=="object"&&self&&self.Object===Object&&self,t=e||o||Function("return this")();return z=t,z}var Y,ve;function mt(){if(ve)return Y;ve=1;var e=Te(),o=function(){return e.Date.now()};return Y=o,Y}var Z,Se;function yt(){if(Se)return Z;Se=1;var e=/\s/;function o(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return Z=o,Z}var J,Ce;function ht(){if(Ce)return J;Ce=1;var e=yt(),o=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(o,"")}return J=t,J}var Q,Ae;function we(){if(Ae)return Q;Ae=1;var e=Te(),o=e.Symbol;return Q=o,Q}var R,Ie;function ft(){if(Ie)return R;Ie=1;var e=we(),o=Object.prototype,t=o.hasOwnProperty,n=o.toString,r=e?e.toStringTag:void 0;function s(a){var p=t.call(a,r),h=a[r];try{a[r]=void 0;var l=!0}catch(m){}var u=n.call(a);return l&&(p?a[r]=h:delete a[r]),u}return R=s,R}var ee,Ee;function xt(){if(Ee)return ee;Ee=1;var e=Object.prototype,o=e.toString;function t(n){return o.call(n)}return ee=t,ee}var te,ke;function gt(){if(ke)return te;ke=1;var e=we(),o=ft(),t=xt(),n="[object Null]",r="[object Undefined]",s=e?e.toStringTag:void 0;function a(p){return p==null?p===void 0?r:n:s&&s in Object(p)?o(p):t(p)}return te=a,te}var ne,Fe;function bt(){if(Fe)return ne;Fe=1;function e(o){return o!=null&&typeof o=="object"}return ne=e,ne}var oe,Pe;function Tt(){if(Pe)return oe;Pe=1;var e=gt(),o=bt(),t="[object Symbol]";function n(r){return typeof r=="symbol"||o(r)&&e(r)==t}return oe=n,oe}var re,_e;function vt(){if(_e)return re;_e=1;var e=ht(),o=xe(),t=Tt(),n=NaN,r=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,p=parseInt;function h(l){if(typeof l=="number")return l;if(t(l))return n;if(o(l)){var u=typeof l.valueOf=="function"?l.valueOf():l;l=o(u)?u+"":u}if(typeof l!="string")return l===0?l:+l;l=e(l);var m=s.test(l);return m||a.test(l)?p(l.slice(2),m?2:8):r.test(l)?n:+l}return re=h,re}var ie,Oe;function St(){if(Oe)return ie;Oe=1;var e=xe(),o=mt(),t=vt(),n="Expected a function",r=Math.max,s=Math.min;function a(p,h,l){var u,m,y,S,T,A,O=0,Le=!1,B=!1,pe=!0;if(typeof p!="function")throw new TypeError(n);h=t(h)||0,e(l)&&(Le=!!l.leading,B="maxWait"in l,y=B?r(t(l.maxWait)||0,h):y,pe="trailing"in l?!!l.trailing:pe);function le(b){var I=u,D=m;return u=m=void 0,O=b,S=p.apply(D,I),S}function Xt(b){return O=b,T=setTimeout($,h),Le?le(b):S}function zt(b){var I=b-A,D=b-O,Me=h-I;return B?s(Me,y-D):Me}function Ue(b){var I=b-A,D=b-O;return A===void 0||I>=h||I<0||B&&D>=y}function $(){var b=o();if(Ue(b))return Ve(b);T=setTimeout($,zt(b))}function Ve(b){return T=void 0,pe&&u?le(b):(u=m=void 0,S)}function Yt(){T!==void 0&&clearTimeout(T),O=0,u=A=m=T=void 0}function Zt(){return T===void 0?S:Ve(o())}function de(){var b=o(),I=Ue(b);if(u=arguments,m=this,A=b,I){if(T===void 0)return Xt(A);if(B)return clearTimeout(T),T=setTimeout($,h),le(A)}return T===void 0&&(T=setTimeout($,h)),S}return de.cancel=Yt,de.flush=Zt,de}return ie=a,ie}var Ct=St();const At=he(Ct),U={EMPTY_TOKEN:"EMPTY_TOKEN",EXPIRED_TOKEN:"EXPIRED_TOKEN",INVALID_TOKEN:"INVALID_TOKEN",TOKEN_RENEW_FAILED:"TOKEN_RENEW_FAILED",BLOCKED_TOKEN:"BLOCKED_TOKEN",EXPIRED_SESSION:"EXPIRED_SESSION",NOT_EXIST_USER:"NOT_EXIST_USER",SKIP_TOKEN_RENEW:"SKIP_TOKEN_RENEW",USER_HAS_NO_ROLES_ERR:"USER_HAS_NO_ROLES_ERR"};function wt(e,o){const t=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=new RegExp(`^${t.replace(/\/?$/,"")}(\\/|$)`);return e.replace(n,"/")||e}const It=At(e=>{e()},3e3,{leading:!0,trailing:!1});function Et({app:e}){return e.apiClient.axios,[n=>{var s;const r=(s=n==null?void 0:n.headers)==null?void 0:s["x-new-token"];return r&&e.apiClient.auth.setToken(r),n},n=>{var m,y,S,T,A;const r=(y=(m=n==null?void 0:n.response)==null?void 0:m.headers)==null?void 0:y["x-new-token"],s=(T=(S=n==null?void 0:n.response)==null?void 0:S.data)==null?void 0:T.errors,a=Array.isArray(s)?s[0]:null,p=e.router.state,{pathname:h,search:l}=p.location,u=e.router.basename;if(r&&e.apiClient.auth.setToken(r),n.status===401&&(a!=null&&a.code)&&U[a.code]&&(e.apiClient.auth.setToken(""),h===e.getHref("signin")&&(a==null?void 0:a.code)!==U.EMPTY_TOKEN&&n.config&&(n.config.skipNotify=!1),(a==null?void 0:a.code)==="USER_HAS_NO_ROLES_ERR"&&(n.config.skipNotify=!0,e.error=a)),n.status===401&&!((A=n.config)!=null&&A.skipAuth)&&(a!=null&&a.code)&&U[a.code]){if(!a||(a==null?void 0:a.code)===U.SKIP_TOKEN_RENEW)throw n;if(h!==e.getHref("signin")){const O=wt(h,u);It(()=>{e.apiClient.auth.setToken(null),e.router.navigate(`/signin?redirect=${O}${l}`,{replace:!0})})}}throw n}]}const se=f.createContext({type:""});se.displayName="AuthTypeContext";const ae=f.createContext({types:[]});ae.displayName="AuthTypesContext";const kt=()=>{const{types:e}=f.useContext(ae);return e},Ft=e=>{const o=i.useRecord(),t=i.useRequest(()=>Promise.resolve({data:E({},o.options)}),W(E({},e),{manual:!0})),{run:n}=t,r=i.useActionContext();return f.useEffect(()=>{r.visible&&n()},[r.visible,n]),t},Pt=e=>{var n;const t=i.usePlugin(_).authTypes.get(e);return(n=t==null?void 0:t.components)==null?void 0:n.AdminSettingsForm},_t=v.observer(()=>{const e=v.useForm(),o=i.useRecord(),t=Pt(e.values.authType||o.authType);return t?c.jsx(t,{}):null},{displayName:"Options"}),Ne={name:"authenticators",sortable:!0,fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Auth UID")}}',"x-component":"Input","x-validator":e=>/^[a-zA-Z0-9_-]+$/.test(e)?"":i.i18n.t("a-z, A-Z, 0-9, _, -"),required:!0}},{interface:"input",type:"string",name:"authType",uiSchema:{type:"string",title:'{{t("Auth Type")}}',"x-component":"Select",dataSource:"{{ types }}",required:!0}},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},Ot={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const o=i.useActionContext(),{type:t}=f.useContext(se);return i.useRequest(()=>Promise.resolve({data:{name:`s_${v.uid()}`,authType:t}}),W(E({},e),{refreshDeps:[o.visible]}))}},title:'{{t("Add new")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},create:{title:'{{ t("Submit") }}',"x-action":"submit","x-component":"Action","x-use-component-props":"useCreateDatabaseConnectionAction","x-component-props":{type:"primary"}}}}}}}},Nt={type:"void",name:"authenticators","x-decorator":"TableBlockProvider","x-decorator-props":{collection:Ne,dragSort:!0,action:"list",params:{pageSize:50,sort:"sort",appends:[]}},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-action":"destroy","x-decorator":"ACLActionProvider","x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{icon:"DeleteOutlined",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"array","x-uid":"input","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{id:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{updateAuthenticator:{type:"void",title:'{{ t("Edit") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer",icon:"EditOutlined"},"x-decorator":"ACLActionProvider",properties:{drawer:{type:"void",title:'{{ t("Edit record") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{card:{type:"void","x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"authenticators:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:Ne},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-action":"destroy","x-component":"Action.Link","x-use-component-props":"useDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"}},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},qt=()=>{const{setVisible:e}=i.useActionContext();return{run(){return k(this,null,function*(){e(!1)})}}},jt=()=>{const{t:e}=F.useTranslation(),[o,t]=f.useState(!1),[n,r]=f.useState(""),s=kt(),a=s.map(p=>W(E({},p),{onClick:()=>{t(!0),r(p.value)}}));return c.jsx(i.ActionContextProvider,{value:{visible:o,setVisible:t},children:c.jsxs(se.Provider,{value:{type:n},children:[c.jsx(x.Dropdown,{menu:{items:a},children:c.jsxs(x.Button,{icon:c.jsx(N.PlusOutlined,{}),type:"primary",children:[e("Add new")," ",c.jsx(N.DownOutlined,{})]})}),c.jsx(i.SchemaComponent,{scope:{useCloseAction:qt,types:s,setType:r},schema:Ot})]})})},Bt=()=>{const{data:e}=i.useAsyncData();return!1},Dt=()=>{const{t:e}=w(),[o,t]=f.useState([]),n=i.useAPIClient();return i.useRequest(()=>n.resource("authenticators").listTypes().then(r=>{var a;return(((a=r==null?void 0:r.data)==null?void 0:a.data)||[]).map(p=>({key:p.name,label:e(p.title||p.name),value:p.name}))}),{onSuccess:r=>{t(r)}}),c.jsx(x.Card,{bordered:!1,children:c.jsx(ae.Provider,{value:{types:o},children:c.jsx(i.SchemaComponent,{schema:Nt,components:{AddNew:jt,Options:_t},scope:{types:o,useValuesFromOptions:Ft,useCanNotDelete:Bt,t:e}})})})},{Option:ce}=x.Select,Lt=v.connect(e=>{const{t:o}=w(),m=e,{value:t,onChange:n,minNum:r=1}=m,s=Ge(m,["value","onChange","minNum"]),a=/^(\d*)([a-zA-Z]*)$/,p=t?t.match(a):null;f.useEffect(()=>{p||n("10m")},[p,n]);const[h,l]=p?[parseInt(p[1]),p[2]]:[10,"m"],u=c.jsxs(x.Select,{value:l,onChange:y=>n(`${h}${y}`),style:{width:120},children:[c.jsx(ce,{value:"m",children:o("Minutes")}),c.jsx(ce,{value:"h",children:o("Hours")}),c.jsx(ce,{value:"d",children:o("Days")})]});return c.jsx(x.InputNumber,E({value:h,addonAfter:u,min:r,onChange:y=>n(`${y!=null?y:1}${l}`)},s))},v.mapProps({onInput:"onChange"})),V={InputTime:"InputTime"},Ut={[V.InputTime]:Lt};var ue,qe;function Vt(){if(qe)return ue;qe=1;var e=1e3,o=e*60,t=o*60,n=t*24,r=n*7,s=n*365.25;ue=function(u,m){m=m||{};var y=typeof u;if(y==="string"&&u.length>0)return a(u);if(y==="number"&&isFinite(u))return m.long?h(u):p(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function a(u){if(u=String(u),!(u.length>100)){var m=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(m){var y=parseFloat(m[1]),S=(m[2]||"ms").toLowerCase();switch(S){case"years":case"year":case"yrs":case"yr":case"y":return y*s;case"weeks":case"week":case"w":return y*r;case"days":case"day":case"d":return y*n;case"hours":case"hour":case"hrs":case"hr":case"h":return y*t;case"minutes":case"minute":case"mins":case"min":case"m":return y*o;case"seconds":case"second":case"secs":case"sec":case"s":return y*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return y;default:return}}}}function p(u){var m=Math.abs(u);return m>=n?Math.round(u/n)+"d":m>=t?Math.round(u/t)+"h":m>=o?Math.round(u/o)+"m":m>=e?Math.round(u/e)+"s":u+"ms"}function h(u){var m=Math.abs(u);return m>=n?l(u,m,n,"day"):m>=t?l(u,m,t,"hour"):m>=o?l(u,m,o,"minute"):m>=e?l(u,m,e,"second"):u+" ms"}function l(u,m,y,S){var T=m>=y*1.5;return Math.round(u/y)+" "+S+(T?"s":"")}return ue}var Mt=Vt();const je=he(Mt),Be="token-policy-config",De="tokenControlConfig",$t=()=>{const e=i.useAPIClient(),o=f.useMemo(()=>v.createForm(),[]);return f.useEffect(()=>{k(null,null,function*(){var n;try{const{data:r}=yield e.resource(De).get({filterByTk:Be});(n=r==null?void 0:r.data)!=null&&n.config&&o.setValues(r.data.config)}catch(r){console.error(r)}})},[o,e]),{form:o}},Kt=()=>{const{message:e}=x.App.useApp(),o=i.useAPIClient(),t=v.useForm(),{t:n}=w();return{type:"primary",onClick(){return k(this,null,function*(){t.clearErrors("*");const{tokenExpirationTime:s,sessionExpirationTime:a,expiredTokenRenewLimit:p}=t.values;if(je(s)>=je(a)){t.setFieldState("tokenExpirationTime",l=>{l.feedbacks=[{type:"error",code:"ValidateError",messages:[n("Token validity period must be less than session validity period!")]}]});return}yield t.submit();const h=yield o.resource(De).update({values:{config:t.values},filterByTk:Be});h&&h.status===200&&e.success(n("Saved successfully!"))})}}},M={useSubmitActionProps:"useSubmitActionProps",useEditForm:"useEditForm"},Wt={[M.useEditForm]:$t,[M.useSubmitActionProps]:Kt},Gt={name:v.uid(),"x-component":"FormV2","x-use-component-props":M.useEditForm,type:"object",properties:{sessionExpirationTime:{type:"string",title:q("Session validity period"),"x-decorator":"FormItem","x-component":V.InputTime,required:!0,description:q("The maximum valid time for each user login. During the session validity, the Token will be automatically updated. After the timeout, the user is required to log in again.")},tokenExpirationTime:{type:"string",title:q("Token validity period"),"x-decorator":"FormItem","x-component":V.InputTime,required:!0,description:q("The validity period of each issued API Token. After the Token expires, if it is within the session validity period and has not exceeded the refresh limit, the server will automatically issue a new Token to maintain the user session, otherwise the user is required to log in again. (Each Token can only be refreshed once)")},expiredTokenRenewLimit:{type:"string",title:"{{t('Expired token refresh limit')}}","x-decorator":"FormItem","x-component":V.InputTime,"x-component-props":{minNum:0},required:!0,description:q("The maximum time limit allowed for refreshing a Token after it expires. After this time limit, the token cannot be automatically renewed, and the user needs to log in again.")},footer:{type:"void","x-component":"ActionBar","x-component-props":{layout:"one-column"},properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":M.useSubmitActionProps}}}}},Ht=()=>{const{t:e}=w();return c.jsx(x.Card,{bordered:!1,children:c.jsx(i.SchemaComponent,{schema:Gt,scope:E({t:e},Wt),components:Ut})})};class _ extends i.Plugin{constructor(){super(...arguments),this.authTypes=new g.Registry}registerType(o,t){this.authTypes.register(o,t)}load(){return k(this,null,function*(){this.app.systemSettingsManager.add("system-services."+P,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${P}" })}}`,Component:Dt,aclSnippet:"pm.auth.authenticators"}),this.app.userSettingsManager.add(P,{icon:"LoginOutlined",title:`{{t("Authentication login bind", { ns: "${P}" })}}`,Component:lt,aclSnippet:"pm.auth.authenticators"}),this.router.add("auth",{Component:"AuthLayout"}),this.router.add("auth.signin",{path:"/signin",Component:"SignInPage"}),this.router.add("auth.signup",{path:"/signup",Component:"SignUpPage"}),this.app.addComponents({AuthLayout:ze,SignInPage:Je,SignUpPage:Re}),this.app.providers.unshift([Xe,{}]),this.registerType(He,{components:{SignInForm:nt,SignUpForm:it,AdminSettingsForm:st}}),this.app.systemSettingsManager.add("security.token-policy",{title:`{{t("Token policy", { ns: "${P}" })}}`,Component:Ht,aclSnippet:"pm.security.token-policy",icon:"ApiOutlined",sort:0});const[o,t]=Et({app:this.app});this.app.apiClient.axios.interceptors.response.handlers.unshift({fulfilled:o,rejected:t,synchronous:!1,runWhen:null})})}}d.AuthenticatorsContext=j,d.PluginAuthClient=_,d.default=_,d.useAuthenticator=G,d.useSignIn=ye,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
22
+ }}}`,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username/Email")}}',style:{}}},password:{type:"string","x-component":"Password",required:!0,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',style:{}}},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useBasicSignIn }}",style:{width:"100%"}}}}},signUp:{type:"void","x-component":"Link","x-component-props":{to:"{{ signUpLink }}"},"x-content":'{{t("Create an account")}}',"x-visible":"{{ allowSignUp }}"}}},nt=e=>{const{t:o}=w(),t=e.authenticator,{authType:n,name:r,options:s}=t,p=!!me()[n]&&(s==null?void 0:s.allowSignUp),h=`/signup?name=${r}`,l=()=>he(r);return c.jsx(i.SchemaComponent,{schema:tt,scope:{useBasicSignIn:l,allowSignUp:p,signUpLink:h,t:o}})},ot=e=>{const o=C.useNavigate(),t=v.useForm(),n=i.useAPIClient(),{t:r}=F.useTranslation();return{run(){return k(this,null,function*(){var a;yield t.submit(),yield n.auth.signUp(t.values,e==null?void 0:e.authenticator),x.message.success(((a=e==null?void 0:e.message)==null?void 0:a.success)||r("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{o("/signin")},2e3)})}}},rt={type:"object",name:v.uid(),"x-component":"FormV2",properties:{username:{type:"string",required:!0,"x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirm_password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirm_password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Confirm password")}}',style:{}},"x-reactions":[{dependencies:[".password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign up")}}',type:"void","x-component":"Action","x-component-props":{block:!0,type:"primary",htmlType:"submit",useAction:"{{ useBasicSignUp }}",style:{width:"100%"}}}}},link:{type:"void","x-component":"div",properties:{link:{type:"void","x-component":"Link","x-component-props":{to:"/signin"},"x-content":'{{t("Log in with an existing account")}}'}}}}},it=({authenticatorName:e})=>{const{t:o}=w(),t=()=>ot({authenticator:e}),n=G(e),{options:r}=n;return r!=null&&r.allowSignUp?c.jsx(i.SchemaComponent,{schema:rt,scope:{useBasicSignUp:t,t:o}}):c.jsx(C.Navigate,{to:"/not-found",replace:!0})},st=()=>{const{t:e}=w();return c.jsx(i.SchemaComponent,{scope:{t:e},components:{Alert:x.Alert},schema:{type:"object",properties:{public:{type:"object",properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox","x-component-props":{defaultChecked:!0}}}},notice:{type:"void","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}}}}})},at=()=>{var n;const o=i.usePlugin(_).authTypes.getEntities(),t={};for(const[r,s]of o)(n=s.components)!=null&&n.BindForm&&(t[r]=s.components.BindForm);return t},ct=()=>{const e=i.useRecord(),t=at()[e.authType];return f.createElement(t,{authenticator:e})},ut={type:"void",name:"authenticatorBind","x-decorator":"TableBlockProvider","x-decorator-props":{collection:{name:"authenticators",sortable:!1,fields:[{interface:"input",type:"string",name:"authType"},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"bind",uiSchema:{type:"boolean",title:'{{t("Bind")}}',"x-component":"Checkbox"}},{type:"string",name:"nickname",uiSchema:{type:"string",title:'{{t("Nickname")}}',"x-component":"Input"}}]},resource:"authenticators",action:"bindTypes",params:{sort:["sort"]},rowKey:"name",showIndex:!0},"x-component":"div",properties:{table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"name"},properties:{authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0}}},title:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{description:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},bind:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{bind:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{unbind:{"x-visible":'{{ $self.query(".bind").value() }}',type:"void",title:'{{ t("Unbind") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Unbind')}}",content:"{{t('Are you sure to unbind this authenticator?')}}"},useAction:"{{ useUnbindAction }}"}},bind:{"x-visible":'{{ !$self.query(".bind").value() }}',type:"void",title:"{{ t('Bind') }}","x-component":"Action.Link",properties:{modal:{type:"void","x-decorator":"Form",title:"{{ t('Bind') }}","x-component":"Action.Modal","x-component-props":{width:800},properties:{form:{type:"void","x-component":"BindForm"}}}}}}}}}}}}},pt=()=>{const{refreshCM:e}=i.useCollectionManager_deprecated(),o=i.useAPIClient(),t=i.useRecord();return{run(){return k(this,null,function*(){yield o.resource("authenticators").unbind({authenticator:t.name}),e()})}}},lt=()=>{const{t:e}=w();return c.jsx(x.Card,{bordered:!1,children:c.jsx(i.SchemaComponent,{schema:ut,components:{BindForm:ct},scope:{t:e,useUnbindAction:pt}})})};var L=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var H,xe;function ge(){if(xe)return H;xe=1;function e(o){var t=typeof o;return o!=null&&(t=="object"||t=="function")}return H=e,H}var X,be;function dt(){if(be)return X;be=1;var e=typeof L=="object"&&L&&L.Object===Object&&L;return X=e,X}var z,Te;function ve(){if(Te)return z;Te=1;var e=dt(),o=typeof self=="object"&&self&&self.Object===Object&&self,t=e||o||Function("return this")();return z=t,z}var Y,Se;function mt(){if(Se)return Y;Se=1;var e=ve(),o=function(){return e.Date.now()};return Y=o,Y}var Z,Ce;function yt(){if(Ce)return Z;Ce=1;var e=/\s/;function o(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return Z=o,Z}var J,Ae;function ht(){if(Ae)return J;Ae=1;var e=yt(),o=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(o,"")}return J=t,J}var Q,we;function Ie(){if(we)return Q;we=1;var e=ve(),o=e.Symbol;return Q=o,Q}var R,Ee;function ft(){if(Ee)return R;Ee=1;var e=Ie(),o=Object.prototype,t=o.hasOwnProperty,n=o.toString,r=e?e.toStringTag:void 0;function s(a){var p=t.call(a,r),h=a[r];try{a[r]=void 0;var l=!0}catch(m){}var u=n.call(a);return l&&(p?a[r]=h:delete a[r]),u}return R=s,R}var ee,ke;function xt(){if(ke)return ee;ke=1;var e=Object.prototype,o=e.toString;function t(n){return o.call(n)}return ee=t,ee}var te,Fe;function gt(){if(Fe)return te;Fe=1;var e=Ie(),o=ft(),t=xt(),n="[object Null]",r="[object Undefined]",s=e?e.toStringTag:void 0;function a(p){return p==null?p===void 0?r:n:s&&s in Object(p)?o(p):t(p)}return te=a,te}var ne,Pe;function bt(){if(Pe)return ne;Pe=1;function e(o){return o!=null&&typeof o=="object"}return ne=e,ne}var oe,_e;function Tt(){if(_e)return oe;_e=1;var e=gt(),o=bt(),t="[object Symbol]";function n(r){return typeof r=="symbol"||o(r)&&e(r)==t}return oe=n,oe}var re,Oe;function vt(){if(Oe)return re;Oe=1;var e=ht(),o=ge(),t=Tt(),n=NaN,r=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,p=parseInt;function h(l){if(typeof l=="number")return l;if(t(l))return n;if(o(l)){var u=typeof l.valueOf=="function"?l.valueOf():l;l=o(u)?u+"":u}if(typeof l!="string")return l===0?l:+l;l=e(l);var m=s.test(l);return m||a.test(l)?p(l.slice(2),m?2:8):r.test(l)?n:+l}return re=h,re}var ie,Ne;function St(){if(Ne)return ie;Ne=1;var e=ge(),o=mt(),t=vt(),n="Expected a function",r=Math.max,s=Math.min;function a(p,h,l){var u,m,y,S,T,A,O=0,Ue=!1,B=!1,pe=!0;if(typeof p!="function")throw new TypeError(n);h=t(h)||0,e(l)&&(Ue=!!l.leading,B="maxWait"in l,y=B?r(t(l.maxWait)||0,h):y,pe="trailing"in l?!!l.trailing:pe);function le(b){var I=u,D=m;return u=m=void 0,O=b,S=p.apply(D,I),S}function Xt(b){return O=b,T=setTimeout($,h),Ue?le(b):S}function zt(b){var I=b-A,D=b-O,$e=h-I;return B?s($e,y-D):$e}function Ve(b){var I=b-A,D=b-O;return A===void 0||I>=h||I<0||B&&D>=y}function $(){var b=o();if(Ve(b))return Me(b);T=setTimeout($,zt(b))}function Me(b){return T=void 0,pe&&u?le(b):(u=m=void 0,S)}function Yt(){T!==void 0&&clearTimeout(T),O=0,u=A=m=T=void 0}function Zt(){return T===void 0?S:Me(o())}function de(){var b=o(),I=Ve(b);if(u=arguments,m=this,A=b,I){if(T===void 0)return Xt(A);if(B)return clearTimeout(T),T=setTimeout($,h),le(A)}return T===void 0&&(T=setTimeout($,h)),S}return de.cancel=Yt,de.flush=Zt,de}return ie=a,ie}var Ct=St();const At=fe(Ct),U={EMPTY_TOKEN:"EMPTY_TOKEN",EXPIRED_TOKEN:"EXPIRED_TOKEN",INVALID_TOKEN:"INVALID_TOKEN",TOKEN_RENEW_FAILED:"TOKEN_RENEW_FAILED",BLOCKED_TOKEN:"BLOCKED_TOKEN",EXPIRED_SESSION:"EXPIRED_SESSION",NOT_EXIST_USER:"NOT_EXIST_USER",SKIP_TOKEN_RENEW:"SKIP_TOKEN_RENEW",USER_HAS_NO_ROLES_ERR:"USER_HAS_NO_ROLES_ERR"};function wt(e,o){const t=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=new RegExp(`^${t.replace(/\/?$/,"")}(\\/|$)`);return e.replace(n,"/")||e}const It=At(e=>{e()},3e3,{leading:!0,trailing:!1});function Et({app:e}){return e.apiClient.axios,[n=>{var s;const r=(s=n==null?void 0:n.headers)==null?void 0:s["x-new-token"];return r&&e.apiClient.auth.setToken(r),n},n=>{var m,y,S,T,A;const r=(y=(m=n==null?void 0:n.response)==null?void 0:m.headers)==null?void 0:y["x-new-token"],s=(T=(S=n==null?void 0:n.response)==null?void 0:S.data)==null?void 0:T.errors,a=Array.isArray(s)?s[0]:null,p=e.router.state,{pathname:h,search:l}=p.location,u=e.router.basename;if(r&&e.apiClient.auth.setToken(r),n.status===401&&(a!=null&&a.code)&&U[a.code]&&(e.apiClient.auth.setToken(""),h===e.getHref("signin")&&(a==null?void 0:a.code)!==U.EMPTY_TOKEN&&n.config&&(n.config.skipNotify=!1),(a==null?void 0:a.code)==="USER_HAS_NO_ROLES_ERR"&&(n.config.skipNotify=!0,e.error=a)),n.status===401&&!((A=n.config)!=null&&A.skipAuth)&&(a!=null&&a.code)&&U[a.code]){if(!a||(a==null?void 0:a.code)===U.SKIP_TOKEN_RENEW)throw n;if(h!==e.getHref("signin")){const O=wt(h,u);It(()=>{e.apiClient.auth.setToken(null),e.router.navigate(`/signin?redirect=${O}${l}`,{replace:!0})})}}throw n}]}const se=f.createContext({type:""});se.displayName="AuthTypeContext";const ae=f.createContext({types:[]});ae.displayName="AuthTypesContext";const kt=()=>{const{types:e}=f.useContext(ae);return e},Ft=e=>{const o=i.useRecord(),t=i.useRequest(()=>Promise.resolve({data:E({},o.options)}),W(E({},e),{manual:!0})),{run:n}=t,r=i.useActionContext();return f.useEffect(()=>{r.visible&&n()},[r.visible,n]),t},Pt=e=>{var n;const t=i.usePlugin(_).authTypes.get(e);return(n=t==null?void 0:t.components)==null?void 0:n.AdminSettingsForm},_t=v.observer(()=>{const e=v.useForm(),o=i.useRecord(),t=Pt(e.values.authType||o.authType);return t?c.jsx(t,{}):null},{displayName:"Options"}),qe={name:"authenticators",sortable:!0,fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Auth UID")}}',"x-component":"Input","x-validator":e=>/^[a-zA-Z0-9_-]+$/.test(e)?"":i.i18n.t("a-z, A-Z, 0-9, _, -"),required:!0}},{interface:"input",type:"string",name:"authType",uiSchema:{type:"string",title:'{{t("Auth Type")}}',"x-component":"Select",dataSource:"{{ types }}",required:!0}},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},Ot={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const o=i.useActionContext(),{type:t}=f.useContext(se);return i.useRequest(()=>Promise.resolve({data:{name:`s_${v.uid()}`,authType:t}}),W(E({},e),{refreshDeps:[o.visible]}))}},title:'{{t("Add new")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},create:{title:'{{ t("Submit") }}',"x-action":"submit","x-component":"Action","x-use-component-props":"useCreateDatabaseConnectionAction","x-component-props":{type:"primary"}}}}}}}},Nt={type:"void",name:"authenticators","x-decorator":"TableBlockProvider","x-decorator-props":{collection:qe,dragSort:!0,action:"list",params:{pageSize:50,sort:"sort",appends:[]}},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-action":"destroy","x-decorator":"ACLActionProvider","x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{icon:"DeleteOutlined",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"array","x-uid":"input","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{id:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{updateAuthenticator:{type:"void",title:'{{ t("Edit") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer",icon:"EditOutlined"},"x-decorator":"ACLActionProvider",properties:{drawer:{type:"void",title:'{{ t("Edit record") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{card:{type:"void","x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"authenticators:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:qe},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-action":"destroy","x-component":"Action.Link","x-use-component-props":"useDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"}},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},qt=()=>{const{setVisible:e}=i.useActionContext();return{run(){return k(this,null,function*(){e(!1)})}}},jt=()=>{const{t:e}=F.useTranslation(),[o,t]=f.useState(!1),[n,r]=f.useState(""),s=kt(),a=s.map(p=>W(E({},p),{onClick:()=>{t(!0),r(p.value)}}));return c.jsx(i.ActionContextProvider,{value:{visible:o,setVisible:t},children:c.jsxs(se.Provider,{value:{type:n},children:[c.jsx(x.Dropdown,{menu:{items:a},children:c.jsxs(x.Button,{icon:c.jsx(N.PlusOutlined,{}),type:"primary",children:[e("Add new")," ",c.jsx(N.DownOutlined,{})]})}),c.jsx(i.SchemaComponent,{scope:{useCloseAction:qt,types:s,setType:r},schema:Ot})]})})},Bt=()=>{const{data:e}=i.useAsyncData();return!1},Dt=()=>{const{t:e}=w(),[o,t]=f.useState([]),n=i.useAPIClient();return i.useRequest(()=>n.resource("authenticators").listTypes().then(r=>{var a;return(((a=r==null?void 0:r.data)==null?void 0:a.data)||[]).map(p=>({key:p.name,label:e(p.title||p.name),value:p.name}))}),{onSuccess:r=>{t(r)}}),c.jsx(x.Card,{bordered:!1,children:c.jsx(ae.Provider,{value:{types:o},children:c.jsx(i.SchemaComponent,{schema:Nt,components:{AddNew:jt,Options:_t},scope:{types:o,useValuesFromOptions:Ft,useCanNotDelete:Bt,t:e}})})})},{Option:ce}=x.Select,Lt=v.connect(e=>{const{t:o}=w(),m=e,{value:t,onChange:n,minNum:r=1}=m,s=He(m,["value","onChange","minNum"]),a=/^(\d*)([a-zA-Z]*)$/,p=t?t.match(a):null;f.useEffect(()=>{p||n("10m")},[p,n]);const[h,l]=p?[parseInt(p[1]),p[2]]:[10,"m"],u=c.jsxs(x.Select,{value:l,onChange:y=>n(`${h}${y}`),style:{width:120},children:[c.jsx(ce,{value:"m",children:o("Minutes")}),c.jsx(ce,{value:"h",children:o("Hours")}),c.jsx(ce,{value:"d",children:o("Days")})]});return c.jsx(x.InputNumber,E({value:h,addonAfter:u,min:r,onChange:y=>n(`${y!=null?y:1}${l}`)},s))},v.mapProps({onInput:"onChange"})),V={InputTime:"InputTime"},Ut={[V.InputTime]:Lt};var ue,je;function Vt(){if(je)return ue;je=1;var e=1e3,o=e*60,t=o*60,n=t*24,r=n*7,s=n*365.25;ue=function(u,m){m=m||{};var y=typeof u;if(y==="string"&&u.length>0)return a(u);if(y==="number"&&isFinite(u))return m.long?h(u):p(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function a(u){if(u=String(u),!(u.length>100)){var m=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(m){var y=parseFloat(m[1]),S=(m[2]||"ms").toLowerCase();switch(S){case"years":case"year":case"yrs":case"yr":case"y":return y*s;case"weeks":case"week":case"w":return y*r;case"days":case"day":case"d":return y*n;case"hours":case"hour":case"hrs":case"hr":case"h":return y*t;case"minutes":case"minute":case"mins":case"min":case"m":return y*o;case"seconds":case"second":case"secs":case"sec":case"s":return y*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return y;default:return}}}}function p(u){var m=Math.abs(u);return m>=n?Math.round(u/n)+"d":m>=t?Math.round(u/t)+"h":m>=o?Math.round(u/o)+"m":m>=e?Math.round(u/e)+"s":u+"ms"}function h(u){var m=Math.abs(u);return m>=n?l(u,m,n,"day"):m>=t?l(u,m,t,"hour"):m>=o?l(u,m,o,"minute"):m>=e?l(u,m,e,"second"):u+" ms"}function l(u,m,y,S){var T=m>=y*1.5;return Math.round(u/y)+" "+S+(T?"s":"")}return ue}var Mt=Vt();const Be=fe(Mt),De="token-policy-config",Le="tokenControlConfig",$t=()=>{const e=i.useAPIClient(),o=f.useMemo(()=>v.createForm(),[]);return f.useEffect(()=>{k(null,null,function*(){var n;try{const{data:r}=yield e.resource(Le).get({filterByTk:De});(n=r==null?void 0:r.data)!=null&&n.config&&o.setValues(r.data.config)}catch(r){console.error(r)}})},[o,e]),{form:o}},Kt=()=>{const{message:e}=x.App.useApp(),o=i.useAPIClient(),t=v.useForm(),{t:n}=w();return{type:"primary",onClick(){return k(this,null,function*(){t.clearErrors("*");const{tokenExpirationTime:s,sessionExpirationTime:a,expiredTokenRenewLimit:p}=t.values;if(Be(s)>=Be(a)){t.setFieldState("tokenExpirationTime",l=>{l.feedbacks=[{type:"error",code:"ValidateError",messages:[n("Token validity period must be less than session validity period!")]}]});return}yield t.submit();const h=yield o.resource(Le).update({values:{config:t.values},filterByTk:De});h&&h.status===200&&e.success(n("Saved successfully!"))})}}},M={useSubmitActionProps:"useSubmitActionProps",useEditForm:"useEditForm"},Wt={[M.useEditForm]:$t,[M.useSubmitActionProps]:Kt},Gt={name:v.uid(),"x-component":"FormV2","x-use-component-props":M.useEditForm,type:"object",properties:{sessionExpirationTime:{type:"string",title:q("Session validity period"),"x-decorator":"FormItem","x-component":V.InputTime,required:!0,description:q("The maximum valid time for each user login. During the session validity, the Token will be automatically updated. After the timeout, the user is required to log in again.")},tokenExpirationTime:{type:"string",title:q("Token validity period"),"x-decorator":"FormItem","x-component":V.InputTime,required:!0,description:q("The validity period of each issued API Token. After the Token expires, if it is within the session validity period and has not exceeded the refresh limit, the server will automatically issue a new Token to maintain the user session, otherwise the user is required to log in again. (Each Token can only be refreshed once)")},expiredTokenRenewLimit:{type:"string",title:"{{t('Expired token refresh limit')}}","x-decorator":"FormItem","x-component":V.InputTime,"x-component-props":{minNum:0},required:!0,description:q("The maximum time limit allowed for refreshing a Token after it expires. After this time limit, the token cannot be automatically renewed, and the user needs to log in again.")},footer:{type:"void","x-component":"ActionBar","x-component-props":{layout:"one-column"},properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":M.useSubmitActionProps}}}}},Ht=()=>{const{t:e}=w();return c.jsx(x.Card,{bordered:!1,children:c.jsx(i.SchemaComponent,{schema:Gt,scope:E({t:e},Wt),components:Ut})})};class _ extends i.Plugin{constructor(){super(...arguments),this.authTypes=new g.Registry}registerType(o,t){this.authTypes.register(o,t)}load(){return k(this,null,function*(){this.app.systemSettingsManager.add("system-services."+P,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${P}" })}}`,Component:Dt,aclSnippet:"pm.auth.authenticators"}),this.app.userSettingsManager.add(P,{icon:"LoginOutlined",title:`{{t("Authentication login bind", { ns: "${P}" })}}`,Component:lt,aclSnippet:"pm.auth.authenticators"}),this.router.add("auth",{Component:"AuthLayout"}),this.router.add("auth.signin",{path:"/signin",Component:"SignInPage"}),this.router.add("auth.signup",{path:"/signup",Component:"SignUpPage"}),this.app.addComponents({AuthLayout:Ye,SignInPage:Qe,SignUpPage:et}),this.app.providers.unshift([ze,{}]),this.registerType(Xe,{components:{SignInForm:nt,SignUpForm:it,AdminSettingsForm:st}}),this.app.systemSettingsManager.add("security.token-policy",{title:`{{t("Token policy", { ns: "${P}" })}}`,Component:Ht,aclSnippet:"pm.security.token-policy",icon:"ApiOutlined",sort:0});const[o,t]=Et({app:this.app});this.app.apiClient.axios.interceptors.response.handlers.unshift({fulfilled:o,rejected:t,synchronous:!1,runWhen:null})})}}d.AuthenticatorsContext=j,d.PluginAuthClient=_,d.default=_,d.useAuthenticator=G,d.useRedirect=ye,d.useSignIn=he,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,19 +1,19 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "1.3.19",
3
+ "@tachybase/client": "1.3.21",
4
4
  "react-router-dom": "6.28.1",
5
- "@tachybase/utils": "1.3.19",
5
+ "@tachybase/utils": "1.3.21",
6
6
  "axios": "1.7.7",
7
7
  "lodash": "4.17.21",
8
- "@tachybase/auth": "1.3.19",
9
- "@tachybase/database": "1.3.19",
10
- "@tachybase/cache": "1.3.19",
11
- "@tachybase/server": "1.3.19",
12
- "@tachybase/logger": "1.3.19",
13
- "@tachybase/test": "1.3.19",
8
+ "@tachybase/auth": "1.3.21",
9
+ "@tachybase/database": "1.3.21",
10
+ "@tachybase/cache": "1.3.21",
11
+ "@tachybase/server": "1.3.21",
12
+ "@tachybase/logger": "1.3.21",
13
+ "@tachybase/test": "1.3.21",
14
14
  "antd": "5.22.5",
15
- "@tachybase/schema": "1.3.19",
15
+ "@tachybase/schema": "1.3.21",
16
16
  "react-i18next": "15.2.0",
17
17
  "@ant-design/icons": "5.3.7",
18
- "@tachybase/actions": "1.3.19"
18
+ "@tachybase/actions": "1.3.21"
19
19
  };
@@ -1 +1 @@
1
- {"name":"cron","description":"Cron jobs for your node","version":"3.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc -b tsconfig.build.json","lint:eslint":"eslint src/ tests/","lint:prettier":"prettier ./**/*.{json,md,yml} --check","lint":"npm run lint:eslint && npm run lint:prettier","lint:fix":"npm run lint:eslint -- --fix && npm run lint:prettier -- --write","test":"jest --coverage","test:watch":"jest --watch --coverage","test:fuzz":"jest --testMatch='**/*.fuzz.ts' --coverage=false --testTimeout=120000","prepare":"husky"},"dependencies":{"@types/luxon":"~3.4.0","luxon":"~3.5.0"},"devDependencies":{"@commitlint/cli":"19.6.0","@eslint/js":"^9.14.0","@fast-check/jest":"2.0.3","@insurgent/commitlint-config":"20.0.0","@insurgent/conventional-changelog-preset":"10.0.0","@semantic-release/changelog":"6.0.3","@semantic-release/commit-analyzer":"13.0.0","@semantic-release/git":"10.0.1","@semantic-release/github":"11.0.1","@semantic-release/npm":"12.0.1","@semantic-release/release-notes-generator":"14.0.1","@types/jest":"29.5.14","@types/node":"20.17.9","@types/sinon":"17.0.3","chai":"4.5.0","eslint":"8.57.1","eslint-config-prettier":"9.1.0","eslint-plugin-jest":"27.9.0","eslint-plugin-prettier":"5.2.1","husky":"9.1.7","jest":"29.7.0","lint-staged":"15.2.10","prettier":"3.3.3","semantic-release":"24.2.0","sinon":"17.0.2","ts-jest":"29.2.5","typescript":"5.7.2","typescript-eslint":"^7.2.0"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Pierre Cavin <me@sherlox.io> (https://github.com/sheerlox)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"files":["dist/**/*.js","dist/**/*.d.ts","CHANGELOG.md","LICENSE","README.md"],"lint-staged":{"*.ts":"eslint src/ tests/ --fix","*.{json,md,yml}":"prettier ./**/*.{json,md,yml} --check --write"},"_lastModified":"2025-07-17T10:54:02.285Z"}
1
+ {"name":"cron","description":"Cron jobs for your node","version":"3.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc -b tsconfig.build.json","lint:eslint":"eslint src/ tests/","lint:prettier":"prettier ./**/*.{json,md,yml} --check","lint":"npm run lint:eslint && npm run lint:prettier","lint:fix":"npm run lint:eslint -- --fix && npm run lint:prettier -- --write","test":"jest --coverage","test:watch":"jest --watch --coverage","test:fuzz":"jest --testMatch='**/*.fuzz.ts' --coverage=false --testTimeout=120000","prepare":"husky"},"dependencies":{"@types/luxon":"~3.4.0","luxon":"~3.5.0"},"devDependencies":{"@commitlint/cli":"19.6.0","@eslint/js":"^9.14.0","@fast-check/jest":"2.0.3","@insurgent/commitlint-config":"20.0.0","@insurgent/conventional-changelog-preset":"10.0.0","@semantic-release/changelog":"6.0.3","@semantic-release/commit-analyzer":"13.0.0","@semantic-release/git":"10.0.1","@semantic-release/github":"11.0.1","@semantic-release/npm":"12.0.1","@semantic-release/release-notes-generator":"14.0.1","@types/jest":"29.5.14","@types/node":"20.17.9","@types/sinon":"17.0.3","chai":"4.5.0","eslint":"8.57.1","eslint-config-prettier":"9.1.0","eslint-plugin-jest":"27.9.0","eslint-plugin-prettier":"5.2.1","husky":"9.1.7","jest":"29.7.0","lint-staged":"15.2.10","prettier":"3.3.3","semantic-release":"24.2.0","sinon":"17.0.2","ts-jest":"29.2.5","typescript":"5.7.2","typescript-eslint":"^7.2.0"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Pierre Cavin <me@sherlox.io> (https://github.com/sheerlox)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"files":["dist/**/*.js","dist/**/*.d.ts","CHANGELOG.md","LICENSE","README.md"],"lint-staged":{"*.ts":"eslint src/ tests/ --fix","*.{json,md,yml}":"prettier ./**/*.{json,md,yml} --check --write"},"_lastModified":"2025-07-25T05:47:10.431Z"}
@@ -1 +1 @@
1
- {"name":"ms","version":"2.1.3","description":"Tiny millisecond conversion utility","repository":"vercel/ms","main":"./index","files":["index.js"],"scripts":{"precommit":"lint-staged","lint":"eslint lib/* bin/*","test":"mocha tests.js"},"eslintConfig":{"extends":"eslint:recommended","env":{"node":true,"es6":true}},"lint-staged":{"*.js":["npm run lint","prettier --single-quote --write","git add"]},"license":"MIT","devDependencies":{"eslint":"4.18.2","expect.js":"0.3.1","husky":"0.14.3","lint-staged":"5.0.0","mocha":"4.0.1","prettier":"2.0.5"},"_lastModified":"2025-07-17T10:54:02.383Z"}
1
+ {"name":"ms","version":"2.1.3","description":"Tiny millisecond conversion utility","repository":"vercel/ms","main":"./index","files":["index.js"],"scripts":{"precommit":"lint-staged","lint":"eslint lib/* bin/*","test":"mocha tests.js"},"eslintConfig":{"extends":"eslint:recommended","env":{"node":true,"es6":true}},"lint-staged":{"*.js":["npm run lint","prettier --single-quote --write","git add"]},"license":"MIT","devDependencies":{"eslint":"4.18.2","expect.js":"0.3.1","husky":"0.14.3","lint-staged":"5.0.0","mocha":"4.0.1","prettier":"2.0.5"},"_lastModified":"2025-07-25T05:47:10.520Z"}
@@ -143,7 +143,7 @@ class BasicAuth extends import_auth.BaseAuth {
143
143
  async changePassword() {
144
144
  const ctx = this.ctx;
145
145
  const {
146
- values: { oldPassword, newPassword }
146
+ values: { oldPassword, newPassword, phone, code }
147
147
  } = ctx.action.params;
148
148
  const currentUser = ctx.auth.user;
149
149
  if (!currentUser) {
@@ -161,12 +161,21 @@ class BasicAuth extends import_auth.BaseAuth {
161
161
  }
162
162
  });
163
163
  const pwd = this.userCollection.getField("password");
164
+ const verificationPlugin = ctx.app.getPlugin("otp");
164
165
  if (user.password !== null) {
165
166
  const isValid = await pwd.verify(oldPassword, user.password);
166
167
  if (!isValid) {
167
168
  ctx.throw(401, ctx.t("The username, email or password is incorrect, please re-enter", { ns: import_preset.namespace }));
168
169
  }
169
170
  }
171
+ if (code && phone) {
172
+ try {
173
+ await verificationPlugin.intercept(ctx, async () => {
174
+ });
175
+ } catch (e) {
176
+ ctx.throw(401, ctx.t("The verification code is incorrect or expired", { ns: import_preset.namespace }));
177
+ }
178
+ }
170
179
  user.password = newPassword;
171
180
  await user.save();
172
181
  return currentUser;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/module-auth",
3
3
  "displayName": "Authentication",
4
- "version": "1.3.19",
4
+ "version": "1.3.21",
5
5
  "description": "User authentication management, including password, SMS, and support for Single Sign-On (SSO) protocols, with extensibility.",
6
6
  "keywords": [
7
7
  "Authentication",
@@ -19,18 +19,18 @@
19
19
  "react": "^18.3.1",
20
20
  "react-i18next": "^15.2.0",
21
21
  "react-router-dom": "6.28.1",
22
- "@tachybase/schema": "1.3.19"
22
+ "@tachybase/schema": "1.3.21"
23
23
  },
24
24
  "peerDependencies": {
25
- "@tachybase/actions": "1.3.19",
26
- "@tachybase/auth": "1.3.19",
27
- "@tachybase/client": "1.3.19",
28
- "@tachybase/database": "1.3.19",
29
- "@tachybase/cache": "1.3.19",
30
- "@tachybase/server": "1.3.19",
31
- "@tachybase/test": "1.3.19",
32
- "@tachybase/logger": "1.3.19",
33
- "@tachybase/utils": "1.3.19"
25
+ "@tachybase/actions": "1.3.21",
26
+ "@tachybase/auth": "1.3.21",
27
+ "@tachybase/cache": "1.3.21",
28
+ "@tachybase/database": "1.3.21",
29
+ "@tachybase/client": "1.3.21",
30
+ "@tachybase/logger": "1.3.21",
31
+ "@tachybase/server": "1.3.21",
32
+ "@tachybase/utils": "1.3.21",
33
+ "@tachybase/test": "1.3.21"
34
34
  },
35
35
  "description.zh-CN": "用户认证管理,包括基础的密码认证、短信认证、SSO 协议的认证等,可扩展。",
36
36
  "displayName.zh-CN": "用户认证",