@nocobase/plugin-auth 1.4.0-beta.5 → 1.4.0-beta.7

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.
@@ -7,17 +7,17 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- (function(c,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react/jsx-runtime"),require("react"),require("react-i18next"),require("react-router-dom"),require("@formily/react"),require("@emotion/css"),require("antd"),require("@formily/shared"),require("@formily/antd-v5"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react/jsx-runtime","react","react-i18next","react-router-dom","@formily/react","@emotion/css","antd","@formily/shared","@formily/antd-v5","@ant-design/icons"],t):(c=typeof globalThis!="undefined"?globalThis:c||self,t(c["@nocobase/plugin-auth"]={},c["@nocobase/client"],c["@nocobase/utils"],c.jsxRuntime,c.react,c["react-i18next"],c["react-router-dom"],c["@formily/react"],c["@emotion/css"],c.antd,c["@formily/shared"],c["@formily/antd-v5"],c["@ant-design/icons"]))})(this,function(c,t,l,a,u,v,g,x,y,d,N,E,$){"use strict";var ye=Object.defineProperty,xe=Object.defineProperties;var he=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var D=(c,t,l)=>t in c?ye(c,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):c[t]=l,f=(c,t)=>{for(var l in t||(t={}))ge.call(t,l)&&D(c,l,t[l]);if(M)for(var l of M(t))fe.call(t,l)&&D(c,l,t[l]);return c},w=(c,t)=>xe(c,he(t));var z=(c,t,l)=>(D(c,typeof t!="symbol"?t+"":t,l),l);var b=(c,t,l)=>new Promise((a,u)=>{var v=y=>{try{x(l.next(y))}catch(d){u(d)}},g=y=>{try{x(l.throw(y))}catch(d){u(d)}},x=y=>y.done?a(y.value):Promise.resolve(y.value).then(v,g);x((l=l.apply(c,t)).next())});const Z="Email/Password",H=e=>{const r=t.useLocationSearch(),o=t.useApp();return u.useEffect(()=>{const i=new URLSearchParams(r),s=i.get("authenticator"),n=i.get("token");n&&(o.apiClient.auth.setToken(n),o.apiClient.auth.setAuthenticator(s))}),a.jsx(a.Fragment,{children:e.children})},F="auth";function S(){return v.useTranslation([F,"client"],{nsMode:"fallback"})}function A(e){return t.i18n.t(e,{ns:[F,"client"],nsMode:"fallback"})}const T=u.createContext([]);T.displayName="AuthenticatorsContext";const q=e=>u.useContext(T).find(o=>o.name===e),L=({children:e})=>{const r=t.useAPIClient(),{data:o=[],error:i,loading:s}=t.useRequest(()=>r.resource("authenticators").publicList().then(n=>{var p;return((p=n==null?void 0:n.data)==null?void 0:p.data)||[]}));if(s)return a.jsx("div",{style:{textAlign:"center",marginTop:20},children:a.jsx(d.Spin,{})});if(i)throw i;return a.jsx(T.Provider,{value:o,children:e})};function j(){var r;const{data:e}=t.useSystemSettings();return a.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[a.jsx("div",{style:{position:"fixed",top:"2em",right:"2em"},children:a.jsx(t.SwitchLanguage,{})}),a.jsx("h1",{style:{textAlign:"center"},children:a.jsx(t.ReadPretty.TextArea,{value:(r=e==null?void 0:e.data)==null?void 0:r.title})}),a.jsx(L,{children:a.jsx(g.Outlet,{})}),a.jsx("div",{className:y.css`
10
+ (function(c,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react/jsx-runtime"),require("react"),require("react-i18next"),require("react-router-dom"),require("@formily/react"),require("@emotion/css"),require("antd"),require("@formily/shared"),require("@formily/antd-v5"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react/jsx-runtime","react","react-i18next","react-router-dom","@formily/react","@emotion/css","antd","@formily/shared","@formily/antd-v5","@ant-design/icons"],t):(c=typeof globalThis!="undefined"?globalThis:c||self,t(c["@nocobase/plugin-auth"]={},c["@nocobase/client"],c["@nocobase/utils"],c.jsxRuntime,c.react,c["react-i18next"],c["react-router-dom"],c["@formily/react"],c["@emotion/css"],c.antd,c["@formily/shared"],c["@formily/antd-v5"],c["@ant-design/icons"]))})(this,function(c,t,m,a,l,A,g,x,y,d,k,$,E){"use strict";var he=Object.defineProperty,ge=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ve=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var N=(c,t,m)=>t in c?he(c,t,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[t]=m,h=(c,t)=>{for(var m in t||(t={}))ve.call(t,m)&&N(c,m,t[m]);if(_)for(var m of _(t))Ce.call(t,m)&&N(c,m,t[m]);return c},C=(c,t)=>ge(c,fe(t));var z=(c,t,m)=>(N(c,typeof t!="symbol"?t+"":t,m),m);var T=(c,t,m)=>new Promise((a,l)=>{var A=y=>{try{x(m.next(y))}catch(d){l(d)}},g=y=>{try{x(m.throw(y))}catch(d){l(d)}},x=y=>y.done?a(y.value):Promise.resolve(y.value).then(A,g);x((m=m.apply(c,t)).next())});const Z="Email/Password",H=e=>{const s=t.useLocationSearch(),o=t.useApp();return l.useEffect(()=>{const n=new URLSearchParams(s),r=n.get("authenticator"),i=n.get("token");i&&(o.apiClient.auth.setToken(i),o.apiClient.auth.setAuthenticator(r))}),a.jsx(a.Fragment,{children:e.children})},P="auth";function F(){return A.useTranslation([P,"client"],{nsMode:"fallback"})}function I(e){return t.i18n.t(e,{ns:[P,"client"],nsMode:"fallback"})}const w=l.createContext([]);w.displayName="AuthenticatorsContext";const q=e=>l.useContext(w).find(o=>o.name===e),L=({children:e})=>{const s=t.useAPIClient(),{data:o=[],error:n,loading:r}=t.useRequest(()=>s.resource("authenticators").publicList().then(i=>{var p;return((p=i==null?void 0:i.data)==null?void 0:p.data)||[]}));if(r)return a.jsx("div",{style:{textAlign:"center",marginTop:20},children:a.jsx(d.Spin,{})});if(n)throw n;return a.jsx(w.Provider,{value:o,children:e})};function j(){var s;const{data:e}=t.useSystemSettings();return a.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[a.jsx("div",{style:{position:"fixed",top:"2em",right:"2em"},children:a.jsx(t.SwitchLanguage,{})}),a.jsx("h1",{style:{textAlign:"center"},children:a.jsx(t.ReadPretty.TextArea,{value:(s=e==null?void 0:e.data)==null?void 0:s.title})}),a.jsx(L,{children:a.jsx(g.Outlet,{})}),a.jsx("div",{className:y.css`
11
11
  position: absolute;
12
12
  bottom: 24px;
13
13
  width: 100%;
14
14
  left: 0;
15
15
  text-align: center;
16
- `,children:a.jsx(t.PoweredBy,{})})]})}const K=()=>{var i;const r=t.usePlugin(C).authTypes.getEntities(),o={};for(const[s,n]of r)(i=n.components)!=null&&i.SignInForm&&(o[s]=n.components.SignInForm);return o},W=(e=[])=>{var n;const o=t.usePlugin(C).authTypes.getEntities(),i={};for(const[p,m]of o)(n=m.components)!=null&&n.SignInButton&&(i[p]=m.components.SignInButton);const s=Object.keys(i);return e.filter(p=>s.includes(p.authType)).map((p,m)=>u.createElement(i[p.authType],{key:m,authenticator:p}))},G=()=>{const{t:e}=S();t.useCurrentDocumentTitle("Signin"),t.useViewport();const r=K(),o=u.useContext(T),i=W(o);if(!o.length)return a.jsx("div",{style:{color:"#ccc"},children:e("No authentication methods available.")});const s=o.map(n=>{const p=r[n.authType];if(!p)return;const m=`${e("Sign-in")} (${x.Schema.compile(n.authTypeTitle||n.authType,{t:e})})`;return f({component:u.createElement(p,{authenticator:n}),tabTitle:n.title||m},n)}).filter(n=>n);return a.jsxs(d.Space,{direction:"vertical",className:y.css`
16
+ `,children:a.jsx(t.PoweredBy,{})})]})}const K=()=>{var n;const s=t.usePlugin(S).authTypes.getEntities(),o={};for(const[r,i]of s)(n=i.components)!=null&&n.SignInForm&&(o[r]=i.components.SignInForm);return o},W=(e=[])=>{var i;const o=t.usePlugin(S).authTypes.getEntities(),n={};for(const[p,u]of o)(i=u.components)!=null&&i.SignInButton&&(n[p]=u.components.SignInButton);const r=Object.keys(n);return e.filter(p=>r.includes(p.authType)).map((p,u)=>l.createElement(n[p.authType],{key:u,authenticator:p}))},G=()=>{const{t:e}=F();t.useCurrentDocumentTitle("Signin"),t.useViewport();const s=K(),o=l.useContext(w),n=W(o);if(!o.length)return a.jsx("div",{style:{color:"#ccc"},children:e("No authentication methods available.")});const r=o.map(i=>{const p=s[i.authType];if(!p)return;const u=`${e("Sign-in")} (${x.Schema.compile(i.authTypeTitle||i.authType,{t:e})})`;return h({component:l.createElement(p,{authenticator:i}),tabTitle:i.title||u},i)}).filter(i=>i);return a.jsxs(d.Space,{direction:"vertical",className:y.css`
17
17
  display: flex;
18
- `,children:[s.length>1?a.jsx(d.Tabs,{items:s.map(n=>({label:n.tabTitle,key:n.name,children:n.component}))}):s.length?a.jsx("div",{children:s[0].component}):a.jsx(a.Fragment,{}),a.jsx(d.Space,{direction:"vertical",className:y.css`
18
+ `,children:[r.length>1?a.jsx(d.Tabs,{items:r.map(i=>({label:i.tabTitle,key:i.name,children:i.component}))}):r.length?a.jsx("div",{children:r[0].component}):a.jsx(a.Fragment,{}),a.jsx(d.Space,{direction:"vertical",className:y.css`
19
19
  display: flex;
20
- `,children:i})]})},J=u.createContext({});J.displayName="SignupPageContext";const B=()=>{var i;const r=t.usePlugin(C).authTypes.getEntities(),o={};for(const[s,n]of r)(i=n.components)!=null&&i.SignUpForm&&(o[s]=n.components.SignUpForm);return o},Q=()=>{t.useViewport(),t.useCurrentDocumentTitle("Signup");const e=B(),[r]=g.useSearchParams(),o=r.get("name"),i=q(o),{authType:s}=i||{};return e[s]?u.createElement(e[s],{authenticatorName:o}):a.jsx(g.Navigate,{to:"/not-found",replace:!0})};function X(e="/admin"){const r=g.useNavigate(),[o]=g.useSearchParams();return u.useCallback(()=>{r(o.get("redirect")||"/admin",{replace:!0})},[r,o])}const O=e=>{const r=x.useForm(),o=t.useAPIClient(),i=X(),{refreshAsync:s}=t.useCurrentUserContext();return{run(){return b(this,null,function*(){yield r.submit(),yield o.auth.signIn(r.values,e),yield s(),i()})}}},Y={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
20
+ `,children:n})]})},J=l.createContext({});J.displayName="SignupPageContext";const B=()=>{var n;const s=t.usePlugin(S).authTypes.getEntities(),o={};for(const[r,i]of s)(n=i.components)!=null&&n.SignUpForm&&(o[r]=i.components.SignUpForm);return o},Q=()=>{t.useViewport(),t.useCurrentDocumentTitle("Signup");const e=B(),[s]=g.useSearchParams(),o=s.get("name"),n=q(o),{authType:r}=n||{};return e[r]?l.createElement(e[r],{authenticatorName:o}):a.jsx(g.Navigate,{to:"/not-found",replace:!0})};function X(e="/admin"){const s=g.useNavigate(),[o]=g.useSearchParams();return l.useCallback(()=>{s(o.get("redirect")||"/admin",{replace:!0})},[s,o])}const O=e=>{const s=x.useForm(),o=t.useAPIClient(),n=X(),{refreshAsync:r}=t.useCurrentUserContext();return{run(){return T(this,null,function*(){yield s.submit(),yield o.auth.signIn(s.values,e),yield r(),n()})}}},Y={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
21
21
  if (!value) {
22
22
  return t("Please enter your username or email");
23
23
  }
@@ -28,9 +28,9 @@
28
28
  } else {
29
29
  return /^[^@.<>"'/]{1,50}$/.test(value) || t("Please enter a valid username");
30
30
  }
31
- }}}`,"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 }}"}}},R=e=>{const{t:r}=S(),o=e.authenticator,{authType:i,name:s,options:n}=o,m=!!(B()[i]&&(n!=null&&n.allowSignUp)),h=`/signup?name=${s}`,P=()=>O(s);return a.jsx(t.SchemaComponent,{schema:Y,scope:{useBasicSignIn:P,allowSignUp:m,signUpLink:h,t:r}})},V={username:{type:"string","x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},email:{type:"string","x-component":"Input","x-validator":"email","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Email")}}',style:{}}}},ee=e=>{const r=g.useNavigate(),o=x.useForm(),i=t.useAPIClient(),{t:s}=v.useTranslation();return{run(){return b(this,null,function*(){var p;yield o.submit(),yield i.auth.signUp(o.values,e==null?void 0:e.authenticator),d.message.success(((p=e==null?void 0:e.message)==null?void 0:p.success)||s("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{r("/signin")},2e3)})}}},te=e=>({type:"object",name:N.uid(),"x-component":"FormV2",properties:w(f({},e),{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")}}'}}}})}),oe=({authenticatorName:e})=>{const{t:r}=S(),o=()=>ee({authenticator:e}),i=q(e),{options:s}=i;let{signupForm:n}=s;n!=null&&n.length&&n.some(h=>h.show&&h.required)||(n=[{field:"username",show:!0,required:!0}]);const p=u.useMemo(()=>n.filter(h=>h.show).reduce((h,P)=>{const I=P.field;if(V[I])return h[I]=V[I],P.required&&(h[I].required=!0),h},{}),[n]);if(!(s!=null&&s.allowSignUp))return a.jsx(g.Navigate,{to:"/not-found",replace:!0});const m=te(p);return a.jsx(t.SchemaComponent,{schema:m,scope:{useBasicSignUp:o,t:r}})},ne=()=>{const{t:e}=S();return a.jsx(t.SchemaComponent,{scope:{t:e},components:{Alert:d.Alert,FormTab:E.FormTab,ArrayTable:E.ArrayTable},schema:{type:"object",properties:{notice:{type:"void","x-decorator":"FormItem","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}},public:{type:"object",properties:{collapse:{type:"void","x-component":"FormTab",properties:{basic:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:A("Sign up settings")},properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox",default:!0},signupForm:{title:'{{t("Sign up form")}}',type:"array","x-decorator":"FormItem","x-component":"ArrayTable","x-component-props":{bordered:!1},"x-validator":`{{ (value) => {
32
- const field = value?.filter((item) => item.show && item.required);
33
- if (!field?.length) {
34
- return t('At least one field is required');
31
+ }}}`,"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 }}"}}},R=e=>{const{t:s}=F(),o=e.authenticator,{authType:n,name:r,options:i}=o,u=!!(B()[n]&&(i!=null&&i.allowSignUp)),f=`/signup?name=${r}`,v=()=>O(r);return a.jsx(t.SchemaComponent,{schema:Y,scope:{useBasicSignIn:v,allowSignUp:u,signUpLink:f,t:s}})},ee=e=>{const s=g.useNavigate(),o=x.useForm(),n=t.useAPIClient(),{t:r}=A.useTranslation();return{run(){return T(this,null,function*(){var p;yield o.submit(),yield n.auth.signUp(o.values,e==null?void 0:e.authenticator),d.message.success(((p=e==null?void 0:e.message)==null?void 0:p.success)||r("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{s("/signin")},2e3)})}}},te=e=>({type:"object",name:k.uid(),"x-component":"FormV2",properties:C(h({},e),{password:{type:"string",required:!0,title:'{{t("Password")}}',"x-component":"Password","x-decorator":"FormItem","x-component-props":{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",title:'{{t("Confirm password")}}',"x-component-props":{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")}}'}}}})}),oe=({authenticatorName:e})=>{const{t:s}=F(),o=()=>ee({authenticator:e}),n=q(e),{options:r}=n,{signupForm:i}=r,p=l.useMemo(()=>i.filter(f=>f.show).reduce((f,v)=>(f[v.field]=C(h({},v.uiSchema),{required:v.required,"x-decorator":"FormItem"}),f),{}),[i]);if(!(r!=null&&r.allowSignUp))return a.jsx(g.Navigate,{to:"/not-found",replace:!0});const u=te(p);return a.jsx(t.SchemaComponent,{schema:u,scope:{useBasicSignUp:o,t:s}})},ne=()=>{const e=t.useRecord(),n=t.useCollectionManager().getCollection("users").fields.filter(p=>{var u;return!p.hidden&&!p.target&&p.interface&&!((u=p.uiSchema)!=null&&u["x-read-pretty"])}),r=n.map(p=>{var u;return{value:p.name,label:(u=p.uiSchema)==null?void 0:u.title}}),i=l.useMemo(()=>{var f,v;const u=(((v=(f=e.options)==null?void 0:f.public)==null?void 0:v.signupForm)||[]).filter(b=>n.find(M=>M.name===b.field));for(const b of n)u.find(xe=>xe.field===b.name)||u.push({field:b.name,show:b.name==="username",required:b.name==="username"});return u},[n,e]);return l.useEffect(()=>{var p;e.options=C(h({},e.options),{public:C(h({},(p=e.options)==null?void 0:p.public),{signupForm:i})})},[e,i]),a.jsx(t.SchemaComponent,{components:{ArrayTable:$.ArrayTable},schema:{type:"void",properties:{signupForm:{title:'{{t("Sign up form")}}',type:"array","x-decorator":"FormItem","x-component":"ArrayTable","x-component-props":{bordered:!1},"x-validator":`{{ (value) => {
32
+ const check = value?.some((item) => ['username', 'email'].includes(item.field) && item.show && item.required);
33
+ if (!check) {
34
+ return t('At least one of the username or email fields is required');
35
35
  }
36
- } }}`,default:[{field:"username",show:!0,required:!0},{field:"email",show:!1,required:!1}],items:{type:"object","x-decorator":"ArrayItems.Item",properties:{column0:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:20,align:"center"},properties:{sort:{type:"void","x-component":"ArrayTable.SortHandle"}}},column1:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:100,title:A("Field")},properties:{field:{type:"string","x-decorator":"FormItem","x-component":"Select",enum:[{label:A("Username"),value:"username"},{label:A("Email"),value:"email"}],"x-read-pretty":!0}}},column2:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:A("Show")},properties:{show:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox"}}},column3:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:A("Required")},properties:{required:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox"}}}}}}}}}}}}}}})},U=u.createContext({type:""});U.displayName="AuthTypeContext";const k=u.createContext({types:[]});k.displayName="AuthTypesContext";const re=()=>{const{types:e}=u.useContext(k);return e},_={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)?"":t.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"}}]},se={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const r=t.useActionContext(),{type:o}=u.useContext(U);return t.useRequest(()=>Promise.resolve({data:{name:`s_${N.uid()}`,authType:o}}),w(f({},e),{refreshDeps:[r.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-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}},ie={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:_,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:_},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-component-props":{icon:"DeleteOutlined",useAction:"{{ cm.useBulkDestroyAction }}",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:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}",useAction(){const e=t.useAPIClient(),{t:r}=v.useTranslation();return{move(i,s){return b(this,null,function*(){yield e.resource("authenticators").move({sourceId:i.id,targetId:s.id}),d.message.success(r("Saved successfully"),.2)})}}}},properties:{id:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Configure")}}',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-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},ae=e=>{const r=t.useRecord(),o=t.useRequest(()=>Promise.resolve({data:f({},r.options)}),w(f({},e),{manual:!0})),{run:i}=o,s=t.useActionContext();return u.useEffect(()=>{s.visible&&i()},[s.visible,i]),o},ce=e=>{var i;const o=t.usePlugin(C).authTypes.get(e);return(i=o==null?void 0:o.components)==null?void 0:i.AdminSettingsForm},pe=x.observer(()=>{const e=x.useForm(),r=t.useRecord(),o=ce(e.values.authType||r.authType);return o?a.jsx(o,{}):null},{displayName:"Options"}),ue=()=>{const{setVisible:e}=t.useActionContext();return{run(){return b(this,null,function*(){e(!1)})}}},le=()=>{const{t:e}=v.useTranslation(),[r,o]=u.useState(!1),[i,s]=u.useState(""),n=re(),p=n.map(m=>w(f({},m),{onClick:()=>{o(!0),s(m.value)}}));return a.jsx(t.ActionContextProvider,{value:{visible:r,setVisible:o},children:a.jsxs(U.Provider,{value:{type:i},children:[a.jsx(d.Dropdown,{menu:{items:p},children:a.jsxs(d.Button,{icon:a.jsx($.PlusOutlined,{}),type:"primary",children:[e("Add new")," ",a.jsx($.DownOutlined,{})]})}),a.jsx(t.SchemaComponent,{scope:{useCloseAction:ue,types:n,setType:s},schema:se})]})})},me=()=>(t.useAsyncData(),!1),de=()=>{const{t:e}=S(),[r,o]=u.useState([]),i=t.useAPIClient();return t.useRequest(()=>i.resource("authenticators").listTypes().then(s=>{var p;return(((p=s==null?void 0:s.data)==null?void 0:p.data)||[]).map(m=>({key:m.name,label:x.Schema.compile(m.title||m.name,{t:e}),value:m.name}))}),{onSuccess:s=>{o(s)}}),a.jsx(d.Card,{bordered:!1,children:a.jsx(k.Provider,{value:{types:r},children:a.jsx(t.SchemaComponent,{schema:ie,components:{AddNew:le,Options:pe},scope:{types:r,useValuesFromOptions:ae,useCanNotDelete:me,t:e}})})})};class C extends t.Plugin{constructor(){super(...arguments);z(this,"authTypes",new l.Registry)}registerType(o,i){this.authTypes.register(o,i)}load(){return b(this,null,function*(){this.app.pluginSettingsManager.add(F,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${F}" })}}`,Component:de,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:j,SignInPage:G,SignUpPage:Q}),this.app.providers.unshift([H,{}]),this.registerType(Z,{components:{SignInForm:R,SignUpForm:oe,AdminSettingsForm:ne}})})}}c.AuthLayout=j,c.AuthenticatorsContext=T,c.AuthenticatorsContextProvider=L,c.PluginAuthClient=C,c.default=C,c.useAuthenticator=q,c.useSignIn=O,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
36
+ } }}`,default:i,items:{type:"object","x-decorator":"ArrayItems.Item",properties:{column0:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:20,align:"center"},properties:{sort:{type:"void","x-component":"ArrayTable.SortHandle"}}},column1:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:100,title:I("Field")},properties:{field:{type:"string","x-decorator":"FormItem","x-component":"Select",enum:r,"x-read-pretty":!0}}},column2:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:I("Show")},properties:{show:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:[".required"],fulfill:{state:{value:"{{ $deps[0] || $self.value }}"}}}}}},column3:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:I("Required")},properties:{required:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:[".show"],fulfill:{state:{value:"{{ !$deps[0] ? false : $self.value }}"}}}}}}}}}}}})},re=()=>{const{t:e}=F();return a.jsx(t.SchemaComponent,{scope:{t:e},components:{Alert:d.Alert,SignupFormSettings:ne,FormTab:$.FormTab},schema:{type:"object",properties:{notice:{type:"void","x-decorator":"FormItem","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}},public:{type:"object",properties:{collapse:{type:"void","x-component":"FormTab",properties:{basic:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:I("Sign up settings")},properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox",default:!0},[k.uid()]:{type:"void","x-component":"SignupFormSettings"}}}}}}}}}})},U=l.createContext({type:""});U.displayName="AuthTypeContext";const D=l.createContext({types:[]});D.displayName="AuthTypesContext";const se=()=>{const{types:e}=l.useContext(D);return e},V={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)?"":t.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"}}]},ie={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const s=t.useActionContext(),{type:o}=l.useContext(U);return t.useRequest(()=>Promise.resolve({data:{name:`s_${k.uid()}`,authType:o}}),C(h({},e),{refreshDeps:[s.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-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}},ae={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:V,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:V},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-component-props":{icon:"DeleteOutlined",useAction:"{{ cm.useBulkDestroyAction }}",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:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}",useAction(){const e=t.useAPIClient(),{t:s}=A.useTranslation();return{move(n,r){return T(this,null,function*(){yield e.resource("authenticators").move({sourceId:n.id,targetId:r.id}),d.message.success(s("Saved successfully"),.2)})}}}},properties:{id:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Configure")}}',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-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},ce=e=>{const s=t.useRecord(),o=t.useRequest(()=>Promise.resolve({data:h({},s.options)}),C(h({},e),{manual:!0})),{run:n}=o,r=t.useActionContext();return l.useEffect(()=>{r.visible&&n()},[r.visible,n]),o},pe=e=>{var n;const o=t.usePlugin(S).authTypes.get(e);return(n=o==null?void 0:o.components)==null?void 0:n.AdminSettingsForm},ue=x.observer(()=>{const e=x.useForm(),s=t.useRecord(),o=pe(e.values.authType||s.authType);return o?a.jsx(o,{}):null},{displayName:"Options"}),le=()=>{const{setVisible:e}=t.useActionContext();return{run(){return T(this,null,function*(){e(!1)})}}},me=()=>{const{t:e}=A.useTranslation(),[s,o]=l.useState(!1),[n,r]=l.useState(""),i=se(),p=i.map(u=>C(h({},u),{onClick:()=>{o(!0),r(u.value)}}));return a.jsx(t.ActionContextProvider,{value:{visible:s,setVisible:o},children:a.jsxs(U.Provider,{value:{type:n},children:[a.jsx(d.Dropdown,{menu:{items:p},children:a.jsxs(d.Button,{icon:a.jsx(E.PlusOutlined,{}),type:"primary",children:[e("Add new")," ",a.jsx(E.DownOutlined,{})]})}),a.jsx(t.SchemaComponent,{scope:{useCloseAction:le,types:i,setType:r},schema:ie})]})})},de=()=>(t.useAsyncData(),!1),ye=()=>{const{t:e}=F(),[s,o]=l.useState([]),n=t.useAPIClient();return t.useRequest(()=>n.resource("authenticators").listTypes().then(r=>{var p;return(((p=r==null?void 0:r.data)==null?void 0:p.data)||[]).map(u=>({key:u.name,label:x.Schema.compile(u.title||u.name,{t:e}),value:u.name}))}),{onSuccess:r=>{o(r)}}),a.jsx(d.Card,{bordered:!1,children:a.jsx(D.Provider,{value:{types:s},children:a.jsx(t.SchemaComponent,{schema:ae,components:{AddNew:me,Options:ue},scope:{types:s,useValuesFromOptions:ce,useCanNotDelete:de,t:e}})})})};class S extends t.Plugin{constructor(){super(...arguments);z(this,"authTypes",new m.Registry)}registerType(o,n){this.authTypes.register(o,n)}load(){return T(this,null,function*(){this.app.pluginSettingsManager.add(P,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${P}" })}}`,Component:ye,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:j,SignInPage:G,SignUpPage:Q}),this.app.providers.unshift([H,{}]),this.registerType(Z,{components:{SignInForm:R,SignUpForm:oe,AdminSettingsForm:re}})})}}c.AuthLayout=j,c.AuthenticatorsContext=w,c.AuthenticatorsContextProvider=L,c.PluginAuthClient=S,c.default=S,c.useAuthenticator=q,c.useSignIn=O,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -8,21 +8,22 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.4.0-beta.5",
11
+ "@nocobase/client": "1.4.0-beta.7",
12
12
  "react": "18.2.0",
13
- "@nocobase/utils": "1.4.0-beta.5",
14
- "@nocobase/auth": "1.4.0-beta.5",
15
- "@nocobase/database": "1.4.0-beta.5",
16
- "@nocobase/cache": "1.4.0-beta.5",
17
- "@nocobase/server": "1.4.0-beta.5",
18
- "@nocobase/test": "1.4.0-beta.5",
13
+ "@nocobase/utils": "1.4.0-beta.7",
14
+ "@nocobase/auth": "1.4.0-beta.7",
15
+ "@nocobase/database": "1.4.0-beta.7",
16
+ "lodash": "4.17.21",
17
+ "@nocobase/cache": "1.4.0-beta.7",
18
+ "@nocobase/server": "1.4.0-beta.7",
19
+ "@nocobase/test": "1.4.0-beta.7",
19
20
  "@formily/antd-v5": "1.1.9",
20
21
  "antd": "5.12.8",
22
+ "@formily/shared": "2.3.2",
21
23
  "@formily/react": "2.3.0",
22
24
  "react-router-dom": "6.21.0",
23
- "@formily/shared": "2.3.2",
24
25
  "react-i18next": "11.18.6",
25
26
  "@emotion/css": "11.13.0",
26
27
  "@ant-design/icons": "5.2.6",
27
- "@nocobase/actions": "1.4.0-beta.5"
28
+ "@nocobase/actions": "1.4.0-beta.7"
28
29
  };
@@ -28,5 +28,5 @@
28
28
  "Show": "Show",
29
29
  "Sign up settings": "Sign up settings",
30
30
  "Sign up form": "Sign up form",
31
- "At least one field is required": "At least one field is required"
31
+ "At least one of the username or email fields is required": "At least one of the username or email fields is required"
32
32
  }
@@ -28,5 +28,5 @@
28
28
  "Show": "显示",
29
29
  "Sign up settings": "注册设置",
30
30
  "Sign up form": "注册表单",
31
- "At least one field is required": "至少需要设置一个必填字段"
31
+ "At least one of the username or email fields is required": "至少需要设置用户名或邮箱中的一个字段为必填字段"
32
32
  }
@@ -1 +1 @@
1
- {"name":"cron","description":"Cron jobs for your node","version":"2.4.4","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":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage","test:types":"tsd","prepare":"husky install","release":"semantic-release"},"types":"types/index.d.ts","dependencies":{"@types/luxon":"~3.3.0","luxon":"~3.3.0"},"devDependencies":{"@commitlint/cli":"~17.6.6","@insurgentlab/commitlint-config":"^18.1.0","@insurgentlab/conventional-changelog-preset":"~6.0.3","@semantic-release/changelog":"~6.0.x","@semantic-release/commit-analyzer":"~9.0.x","@semantic-release/git":"~10.0.x","@semantic-release/github":"~8.1.x","@semantic-release/npm":"~10.0.x","@semantic-release/release-notes-generator":"~11.0.x","chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","husky":"^8.0.3","jest":"~29.5.x","prettier":"~2.8.x","semantic-release":"~21.0.x","sinon":"^15.0.x","tsd":"^0.28.1"},"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)","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)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","types","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2024-11-23T16:34:43.885Z"}
1
+ {"name":"cron","description":"Cron jobs for your node","version":"2.4.4","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":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage","test:types":"tsd","prepare":"husky install","release":"semantic-release"},"types":"types/index.d.ts","dependencies":{"@types/luxon":"~3.3.0","luxon":"~3.3.0"},"devDependencies":{"@commitlint/cli":"~17.6.6","@insurgentlab/commitlint-config":"^18.1.0","@insurgentlab/conventional-changelog-preset":"~6.0.3","@semantic-release/changelog":"~6.0.x","@semantic-release/commit-analyzer":"~9.0.x","@semantic-release/git":"~10.0.x","@semantic-release/github":"~8.1.x","@semantic-release/npm":"~10.0.x","@semantic-release/release-notes-generator":"~11.0.x","chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","husky":"^8.0.3","jest":"~29.5.x","prettier":"~2.8.x","semantic-release":"~21.0.x","sinon":"^15.0.x","tsd":"^0.28.1"},"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)","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)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","types","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2024-11-27T08:21:47.548Z"}
@@ -59,14 +59,14 @@ var authenticators_default = {
59
59
  sort: "sort"
60
60
  });
61
61
  ctx.body = authenticators.map((authenticator) => {
62
- var _a;
62
+ var _a, _b;
63
63
  const authType = authManager.getAuthConfig(authenticator.authType);
64
64
  return {
65
65
  name: authenticator.name,
66
66
  authType: authenticator.authType,
67
67
  authTypeTitle: (authType == null ? void 0 : authType.title) || "",
68
68
  title: authenticator.title,
69
- options: ((_a = authenticator.options) == null ? void 0 : _a.public) || {}
69
+ options: ((_a = authType == null ? void 0 : authType.getPublicOptions) == null ? void 0 : _a.call(authType, authenticator.options)) || ((_b = authenticator.options) == null ? void 0 : _b.public) || {}
70
70
  };
71
71
  });
72
72
  await next();
@@ -10,6 +10,7 @@ import { AuthConfig, BaseAuth } from '@nocobase/auth';
10
10
  export declare class BasicAuth extends BaseAuth {
11
11
  constructor(config: AuthConfig);
12
12
  validate(): Promise<any>;
13
+ private getSignupFormSettings;
13
14
  private verfiySignupParams;
14
15
  signUp(): Promise<any>;
15
16
  lostPassword(): Promise<any>;
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(basic_auth_exports);
42
42
  var import_auth = require("@nocobase/auth");
43
43
  var import_crypto = __toESM(require("crypto"));
44
44
  var import_preset = require("../preset");
45
+ var import_lodash = __toESM(require("lodash"));
45
46
  class BasicAuth extends import_auth.BaseAuth {
46
47
  constructor(config) {
47
48
  const userCollection = config.ctx.db.getCollection("users");
@@ -75,21 +76,27 @@ class BasicAuth extends import_auth.BaseAuth {
75
76
  }
76
77
  return user;
77
78
  }
78
- verfiySignupParams(values) {
79
+ getSignupFormSettings() {
79
80
  var _a;
80
81
  const options = ((_a = this.authenticator.options) == null ? void 0 : _a.public) || {};
81
- let { signupForm } = options;
82
- if (!((signupForm == null ? void 0 : signupForm.length) && signupForm.some((item) => item.show && item.required))) {
83
- signupForm = [{ field: "username", show: true, required: true }];
82
+ let { signupForm = [] } = options;
83
+ signupForm = signupForm.filter((item) => item.show);
84
+ if (!(signupForm.length && signupForm.some(
85
+ (item) => ["username", "email"].includes(item.field) && item.show && item.required
86
+ ))) {
87
+ signupForm.push({ field: "username", show: true, required: true });
84
88
  }
89
+ return signupForm;
90
+ }
91
+ verfiySignupParams(signupFormSettings, values) {
85
92
  const { username, email } = values;
86
- const usernameSetting = signupForm.find((item) => item.field === "username");
93
+ const usernameSetting = signupFormSettings.find((item) => item.field === "username");
87
94
  if (usernameSetting && usernameSetting.show) {
88
95
  if (username && !this.validateUsername(username) || usernameSetting.required && !username) {
89
96
  throw new Error("Please enter a valid username");
90
97
  }
91
98
  }
92
- const emailSetting = signupForm.find((item) => item.field === "email");
99
+ const emailSetting = signupFormSettings.find((item) => item.field === "email");
93
100
  if (emailSetting && emailSetting.show) {
94
101
  if (email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(email)) {
95
102
  throw new Error("Please enter a valid email address");
@@ -98,6 +105,12 @@ class BasicAuth extends import_auth.BaseAuth {
98
105
  throw new Error("Please enter a valid email address");
99
106
  }
100
107
  }
108
+ const requiredFields = signupFormSettings.filter((item) => item.show && item.required);
109
+ requiredFields.forEach((item) => {
110
+ if (!values[item.field]) {
111
+ throw new Error(`Please enter ${item.field}`);
112
+ }
113
+ });
101
114
  }
102
115
  async signUp() {
103
116
  var _a;
@@ -108,9 +121,10 @@ class BasicAuth extends import_auth.BaseAuth {
108
121
  }
109
122
  const User = ctx.db.getRepository("users");
110
123
  const { values } = ctx.action.params;
111
- const { username, email, password, confirm_password } = values;
124
+ const { password, confirm_password } = values;
125
+ const signupFormSettings = this.getSignupFormSettings();
112
126
  try {
113
- this.verfiySignupParams(values);
127
+ this.verfiySignupParams(signupFormSettings, values);
114
128
  } catch (error) {
115
129
  ctx.throw(400, this.ctx.t(error.message, { ns: import_preset.namespace }));
116
130
  }
@@ -120,7 +134,9 @@ class BasicAuth extends import_auth.BaseAuth {
120
134
  if (password !== confirm_password) {
121
135
  ctx.throw(400, ctx.t("The password is inconsistent, please re-enter", { ns: import_preset.namespace }));
122
136
  }
123
- const user = await User.create({ values: { username, email, password } });
137
+ const fields = signupFormSettings.map((item) => item.field);
138
+ const userValues = import_lodash.default.pick(values, fields);
139
+ const user = await User.create({ values: { ...userValues, password } });
124
140
  return user;
125
141
  }
126
142
  /* istanbul ignore next -- @preserve */
@@ -72,16 +72,42 @@ class PluginAuthServer extends import_server.Plugin {
72
72
  }
73
73
  this.app.authManager.registerTypes(import_preset.presetAuthType, {
74
74
  auth: import_basic_auth.BasicAuth,
75
- title: (0, import_utils.tval)("Password", { ns: import_preset.namespace })
75
+ title: (0, import_utils.tval)("Password", { ns: import_preset.namespace }),
76
+ getPublicOptions: (options) => {
77
+ var _a;
78
+ const usersCollection = this.db.getCollection("users");
79
+ let signupForm = ((_a = options == null ? void 0 : options.public) == null ? void 0 : _a.signupForm) || [];
80
+ signupForm = signupForm.filter((item) => item.show);
81
+ if (!(signupForm.length && signupForm.some(
82
+ (item) => ["username", "email"].includes(item.field) && item.show && item.required
83
+ ))) {
84
+ signupForm.unshift({ field: "username", show: true, required: true });
85
+ }
86
+ signupForm = signupForm.filter((field) => field.show).map((item) => {
87
+ var _a2;
88
+ const field = usersCollection.getField(item.field);
89
+ return {
90
+ ...item,
91
+ uiSchema: {
92
+ ...(_a2 = field.options) == null ? void 0 : _a2.uiSchema,
93
+ required: item.required
94
+ }
95
+ };
96
+ });
97
+ return {
98
+ ...options == null ? void 0 : options.public,
99
+ signupForm
100
+ };
101
+ }
76
102
  });
77
103
  Object.entries(import_auth.default).forEach(
78
104
  ([action, handler]) => {
79
105
  var _a;
80
- return (_a = this.app.resourcer.getResource("auth")) == null ? void 0 : _a.addAction(action, handler);
106
+ return (_a = this.app.resourceManager.getResource("auth")) == null ? void 0 : _a.addAction(action, handler);
81
107
  }
82
108
  );
83
109
  Object.entries(import_authenticators.default).forEach(
84
- ([action, handler]) => this.app.resourcer.registerAction(`authenticators:${action}`, handler)
110
+ ([action, handler]) => this.app.resourceManager.registerActionHandler(`authenticators:${action}`, handler)
85
111
  );
86
112
  ["check", "signIn", "signUp"].forEach((action) => this.app.acl.allow("auth", action));
87
113
  ["signOut", "changePassword"].forEach((action) => this.app.acl.allow("auth", action, "loggedIn"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-auth",
3
- "version": "1.4.0-beta.5",
3
+ "version": "1.4.0-beta.7",
4
4
  "main": "./dist/server/index.js",
5
5
  "homepage": "https://docs.nocobase.com/handbook/auth",
6
6
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/auth",
@@ -26,7 +26,7 @@
26
26
  "displayName.zh-CN": "用户认证",
27
27
  "description": "User authentication management, including password, SMS, and support for Single Sign-On (SSO) protocols, with extensibility.",
28
28
  "description.zh-CN": "用户认证管理,包括基础的密码认证、短信认证、SSO 协议的认证等,可扩展。",
29
- "gitHead": "f5d1207519ab2b82db0ced0369ed88e09d09d88b",
29
+ "gitHead": "8a518a9a0354e5e9ea5caa7c45779654fb517f0a",
30
30
  "keywords": [
31
31
  "Authentication"
32
32
  ]