@tachybase/plugin-auth-sms 1.0.6 → 1.0.18

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.
@@ -1,4 +1,4 @@
1
- (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@tachybase/client"),require("@tachybase/module-auth/client"),require("react/jsx-runtime"),require("react-i18next"),require("react"),require("@tachybase/schema"),require("antd")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-auth/client","react/jsx-runtime","react-i18next","react","@tachybase/schema","antd"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@tachybase/plugin-auth-sms"]={},e["@tachybase/client"],e["@tachybase/module-auth"],e.jsxRuntime,e["react-i18next"],e.react,e["@tachybase/schema"],e.antd))})(this,function(e,t,o,s,p,m,f,r){"use strict";var g=(e,t,o)=>new Promise((s,p)=>{var m=n=>{try{r(o.next(n))}catch(d){p(d)}},f=n=>{try{r(o.throw(n))}catch(d){p(d)}},r=n=>n.done?s(n.value):Promise.resolve(n.value).then(m,f);r((o=o.apply(e,t)).next())});const n="SMS",d="sms-auth";function v(){return p.useTranslation(d)}const A=()=>{const{t:c}=v();return s.jsx(t.SchemaComponent,{scope:{t:c},schema:{type:"object",properties:{sms:{type:"void",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox"}}}}}}}})};function F({targetFieldName:c="phone",actionType:h,value:l,onChange:i}){const{t:a}=p.useTranslation(),x=t.useAPIClient(),q=f.useForm(),[u,I]=m.useState(0),S=m.useRef(null);m.useEffect(()=>{u<=0&&S.current&&clearInterval(S.current)},[u]);function C(){return g(this,null,function*(){if(!(u>0))try{const{data:{data:y}}=yield x.resource("verifications").create({values:{type:h,phone:q.values[c]}});r.message.success(a("Operation succeeded")),l&&i("");const M=y.expiresAt?Math.ceil((Date.parse(y.expiresAt)-Date.now())/1e3):60;I(M),S.current=setInterval(()=>{I(P=>P-1)},1e3)}catch(y){console.error(y)}})}return s.jsxs("fieldset",{className:t.css`
1
+ (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@tachybase/client"),require("@tachybase/module-auth/client"),require("react/jsx-runtime"),require("react-i18next"),require("antd"),require("react"),require("@tachybase/schema")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-auth/client","react/jsx-runtime","react-i18next","antd","react","@tachybase/schema"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@tachybase/plugin-auth-sms"]={},e["@tachybase/client"],e["@tachybase/module-auth"],e.jsxRuntime,e["react-i18next"],e.antd,e.react,e["@tachybase/schema"]))})(this,function(e,t,a,o,d,i,h,l){"use strict";var b=(e,t,a)=>new Promise((o,d)=>{var i=r=>{try{l(a.next(r))}catch(x){d(x)}},h=r=>{try{l(a.throw(r))}catch(x){d(x)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(i,h);l((a=a.apply(e,t)).next())});const r="SMS",x="auth-sms";function A(){return d.useTranslation(x)}const M=()=>{const{t:s}=A();return o.jsx(t.SchemaComponent,{scope:{t:s},schema:{type:"object",properties:{sms:{type:"void",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox"},agreeMust:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Must agree to the agreement")}}',"x-component":"Checkbox"},agreeCode:{"x-decorator":"FormItem",type:"string",title:'{{t("Agree to the agreement text (html supported)")}}',"x-component":"Input.TextArea"}}}}}}}})};function v({targetFieldName:s="phone",actionType:u,value:p,onChange:n}){const{t:m}=d.useTranslation(),g=t.useAPIClient(),f=l.useForm(),[c,I]=h.useState(0),S=h.useRef(null);h.useEffect(()=>{c<=0&&S.current&&clearInterval(S.current)},[c]);function k(){return b(this,null,function*(){if(!(c>0))try{const{data:{data:y}}=yield g.resource("verifications").create({values:{type:u,phone:f.values[s]}});i.message.success(m("Operation succeeded")),p&&n("");const q=y.expiresAt?Math.ceil((Date.parse(y.expiresAt)-Date.now())/1e3):60;I(q),S.current=setInterval(()=>{I(P=>P-1)},1e3)}catch(y){console.error(y)}})}return o.jsxs("fieldset",{className:t.css`
2
2
  display: flex;
3
3
  gap: 0.5em;
4
- `,children:[s.jsx(r.Input,{value:l,onChange:i,placeholder:a("Verification code")}),s.jsx(r.Button,{onClick:C,disabled:u>0,children:u>0?a("Retry after {{count}} seconds",{count:u}):a("Send code")})]})}const T={type:"object",name:"phoneForm","x-component":"Form",properties:{phone:{type:"string",required:!0,"x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Phone")}}',style:{}}},code:{type:"string",required:!0,"x-component":"VerificationCode","x-component-props":{actionType:"auth:signIn",targetFieldName:"phone"},"x-decorator":"FormItem"},actions:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useSMSSignIn }}",style:{width:"100%"}}},tip:{type:"void","x-component":"div","x-content":'{{t("User will be registered automatically if not exists.", {ns: "sms-auth"})}}',"x-component-props":{style:{color:"#ccc"}},"x-visible":"{{ autoSignup }}"}}},j=c=>{const h=c.authenticator,{name:l,options:i}=h,a=!!(i!=null&&i.autoSignup),x=()=>o.useSignIn(l);return s.jsx(t.SchemaComponent,{schema:T,scope:{useSMSSignIn:x,autoSignup:a},components:{VerificationCode:F}})};class b extends t.Plugin{load(){return g(this,null,function*(){this.app.pm.get(o).registerType(n,{components:{SignInForm:j,AdminSettingsForm:A}})})}}e.SmsAuthPlugin=b,e.default=b,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
4
+ `,children:[o.jsx(i.Input,{value:p,onChange:n,placeholder:m("Verification code")}),o.jsx(i.Button,{onClick:k,disabled:c>0,children:c>0?m("Retry after {{count}} seconds",{count:c}):m("Send code")})]})}const F=({value:s,onChange:u,htmlCode:p=""})=>o.jsx(i.Checkbox,{checked:s,onChange:n=>u(n.target.checked),children:o.jsx("span",{dangerouslySetInnerHTML:{__html:p}})}),T={type:"object",name:"phoneForm","x-component":"Form",properties:{phone:{type:"string",required:!0,"x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Phone")}}',style:{}}},code:{type:"string",required:!0,"x-component":"VerificationCode","x-component-props":{actionType:"auth:signIn",targetFieldName:"phone"},"x-decorator":"FormItem"},agree:{type:"boolean","x-component":"HtmlAgreementCheckbox","x-component-props":{htmlCode:"{{ agreeCode }}"},"x-visible":"{{ agreeMust }}"},actions:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useSMSSignIn }}",style:{width:"100%"}},"x-reactions":[{dependencies:["agree"],fulfill:{state:{disabled:"{{ agreeMust && $deps[0] !== true }}"}}}]},tip:{type:"void","x-component":"div","x-content":'{{t("User will be registered automatically if not exists.", {ns: "sms-auth"})}}',"x-component-props":{style:{color:"#ccc"}},"x-visible":"{{ autoSignup }}"}}},j=s=>{const u=s.authenticator,{name:p,options:n}=u,m=!!(n!=null&&n.autoSignup),g=!!n.agreeMust,f=n.agreeCode,c=()=>a.useSignIn(p);return o.jsx(t.SchemaComponent,{schema:T,scope:{useSMSSignIn:c,autoSignup:m,agreeMust:g,agreeCode:f},components:{VerificationCode:v,HtmlAgreementCheckbox:F}})};class C extends t.Plugin{load(){return b(this,null,function*(){this.app.pm.get(a).registerType(r,{components:{SignInForm:j,AdminSettingsForm:M}})})}}e.SmsAuthPlugin=C,e.default=C,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,2 +1,2 @@
1
- export declare const NAMESPACE = "sms-auth";
2
- export declare function useAuthTranslation(): import("react-i18next").UseTranslationResponse<"sms-auth", undefined>;
1
+ export declare const NAMESPACE = "auth-sms";
2
+ export declare function useAuthTranslation(): import("react-i18next").UseTranslationResponse<"auth-sms", undefined>;
@@ -1,12 +1,12 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "1.0.6",
4
- "@tachybase/module-auth": "1.0.6",
5
- "@tachybase/schema": "1.0.6",
3
+ "@tachybase/client": "1.0.18",
4
+ "@tachybase/module-auth": "1.0.18",
5
+ "@tachybase/schema": "1.0.18",
6
6
  "antd": "5.22.5",
7
7
  "react-i18next": "15.2.0",
8
- "@tachybase/plugin-otp": "1.0.6",
9
- "@tachybase/server": "1.0.6",
10
- "@tachybase/auth": "1.0.6",
11
- "@tachybase/database": "1.0.6"
8
+ "@tachybase/plugin-otp": "1.0.18",
9
+ "@tachybase/server": "1.0.18",
10
+ "@tachybase/auth": "1.0.18",
11
+ "@tachybase/database": "1.0.18"
12
12
  };
@@ -1,4 +1,6 @@
1
1
  {
2
+ "Agree to the agreement text (html supported)": "Agree to the agreement text (html supported)",
3
+ "Must agree to the agreement": "Must agree to the agreement",
2
4
  "Sign in via SMS": "Sign in via SMS",
3
5
  "Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist",
4
6
  "User will be registered automatically if not exists.": "User will be registered automatically if not exists."
@@ -1,4 +1,6 @@
1
1
  {
2
+ "Agree to the agreement text (html supported)": "同意协议文本(支持html)",
3
+ "Must agree to the agreement": "必须同意协议",
2
4
  "Sign in via SMS": "短信登录",
3
5
  "Sign up automatically when the user does not exist": "用户不存在时自动注册",
4
6
  "User will be registered automatically if not exists.": "用户不存在时将自动注册。"
@@ -68,7 +68,7 @@ class SMSAuth extends import_auth.BaseAuth {
68
68
  throw new Error(ctx.t("The phone number is not registered, please register first", { ns: import_constants.namespace }));
69
69
  }
70
70
  } catch (err) {
71
- console.log(err);
71
+ console.error(err);
72
72
  throw new Error(err.message);
73
73
  }
74
74
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-auth-sms",
3
3
  "displayName": "Auth: SMS",
4
- "version": "1.0.6",
4
+ "version": "1.0.18",
5
5
  "description": "SMS authentication.",
6
6
  "keywords": [
7
7
  "Authentication"
@@ -13,17 +13,17 @@
13
13
  "antd": "5.22.5",
14
14
  "react": "~18.3.1",
15
15
  "react-i18next": "^15.2.0",
16
- "@tachybase/schema": "1.0.6"
16
+ "@tachybase/schema": "1.0.18"
17
17
  },
18
18
  "peerDependencies": {
19
- "@tachybase/actions": "1.0.6",
20
- "@tachybase/auth": "1.0.6",
21
- "@tachybase/client": "1.0.6",
22
- "@tachybase/plugin-otp": "1.0.6",
23
- "@tachybase/module-auth": "1.0.6",
24
- "@tachybase/server": "1.0.6",
25
- "@tachybase/database": "1.0.6",
26
- "@tachybase/test": "1.0.6"
19
+ "@tachybase/actions": "1.0.18",
20
+ "@tachybase/auth": "1.0.18",
21
+ "@tachybase/client": "1.0.18",
22
+ "@tachybase/database": "1.0.18",
23
+ "@tachybase/module-auth": "1.0.18",
24
+ "@tachybase/test": "1.0.18",
25
+ "@tachybase/plugin-otp": "1.0.18",
26
+ "@tachybase/server": "1.0.18"
27
27
  },
28
28
  "description.zh-CN": "通过短信验证码认证身份。",
29
29
  "displayName.zh-CN": "认证:短信",