@nice2dev/auth 1.4.19 → 1.4.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.
- package/CHANGELOG.md +50 -0
- package/dist/NiceLoginForm.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @nice2dev/auth — Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 15ed387: Controls A (round 44, 1.4.21): forms, navigation and layout fixes from the showcase feedback.
|
|
8
|
+
|
|
9
|
+
- **NiceStepper** (and NiceWizard, which uses it):
|
|
10
|
+
- connectors sit level with the middle of the circle, however many lines a description has;
|
|
11
|
+
- vertical steps centre the circle on the item;
|
|
12
|
+
- steps take `status` (`completed`, `active`, `pending`, `error`, `skipped`) and `description`.
|
|
13
|
+
- **NiceDocumentApprovalFlow** draws its steps with NiceStepper. The decision panel stays.
|
|
14
|
+
- **NiceMenu:** new `panelAnchor: 'item' | 'menu'`. With `'menu'`, `panelAlign` lines the panel up
|
|
15
|
+
with the whole bar.
|
|
16
|
+
- **NiceBottomSheet:**
|
|
17
|
+
- snap points are visible dots (`showSnapPoints`), and clicking one jumps there;
|
|
18
|
+
- the handle is a slider (arrow keys, Home, End);
|
|
19
|
+
- a new `initialSnap` or new `snapPoints` move an open sheet.
|
|
20
|
+
- **NiceSortable:** the drop line is measured from the items. It sits midway between two items, and
|
|
21
|
+
in a row it is as tall as an item. Dragging down drops after the hovered item.
|
|
22
|
+
- **NiceDraggable:** marks itself while dragged (`nice-draggable--dragging`). `NICE_DRAG_MIME` and
|
|
23
|
+
`readNiceDrag()` read a drop.
|
|
24
|
+
- **NiceResponsiveBox** follows its own width with a ResizeObserver: it stacks below `stackBelow`
|
|
25
|
+
(480) and wraps at `minItemWidth`.
|
|
26
|
+
- **NiceIconRail, NiceSortableTree:** `size` scales the buttons, the icons and the text, not only the
|
|
27
|
+
spacing.
|
|
28
|
+
- **NiceLoginForm** (auth): an empty `title` hides the heading.
|
|
29
|
+
- **NiceSpeechToText:** errors read as translated sentences, not browser codes, and a new
|
|
30
|
+
`onError(code)` reports the code.
|
|
31
|
+
- **NiceQuestCard:** at 100 % the bar turns green and shows a check mark.
|
|
32
|
+
- **NiceLeaderboard:** players without a photo get initials on one of six theme tones.
|
|
33
|
+
- **NiceTutorial:** new `showBackButton`, `showCloseButton`, `showProgressBar` and `showSpeedControl`.
|
|
34
|
+
- **NiceEntityEditor:** "Add field" and "New entity" open dialogs.
|
|
35
|
+
- **NiceI18nEditor:**
|
|
36
|
+
- removals ask first (`confirmRemove`);
|
|
37
|
+
- Undo and Redo (Ctrl+Z, Ctrl+Y);
|
|
38
|
+
- `onSave` adds a Save button (Ctrl+S);
|
|
39
|
+
- the buttons are icon-only.
|
|
40
|
+
- **Validation:**
|
|
41
|
+
- rules take a `group`, and NiceValidationBuilder has "+ Group";
|
|
42
|
+
- `evaluateValidation(rules, record, { groups, includeUngrouped })` and `isRecordValid` check only
|
|
43
|
+
the chosen groups.
|
|
44
|
+
- **NiceViewRegistry:** the default registry renders `dataGrid`, `chart`, `kpi` and `badge`, so the
|
|
45
|
+
studio's view preview no longer shows "Unknown control".
|
|
46
|
+
- **NiceGantt:** `dependencyStyle="rounded"` draws curves on every route, including arrows that run
|
|
47
|
+
back to the left and links within one row.
|
|
48
|
+
|
|
49
|
+
## 1.4.20
|
|
50
|
+
|
|
51
|
+
No changes in this release.
|
|
52
|
+
|
|
3
53
|
## 1.4.19
|
|
4
54
|
|
|
5
55
|
No changes in this release.
|
package/dist/NiceLoginForm.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface NiceLoginFormProps {
|
|
|
26
26
|
showRegisterLink?: boolean;
|
|
27
27
|
/** Fires when "Register" is clicked. */
|
|
28
28
|
onRegisterClick?: () => void;
|
|
29
|
-
/** Title text. */
|
|
29
|
+
/** Title text. An empty string hides the heading; omitted shows the translated "Sign In". */
|
|
30
30
|
title?: string;
|
|
31
31
|
/** Submit button label. */
|
|
32
32
|
submitLabel?: string;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),e=require("react/jsx-runtime"),q=require("@nice2dev/ui-core");function re(r={}){const{onLogin:a,onRefresh:n,onLogout:t,storageKey:i="nice_auth",persistAuth:d=!1}=r,[l,c]=s.useState(()=>{if(d&&typeof window<"u")try{const h=localStorage.getItem(i);if(h)return{...JSON.parse(h),loading:!1,error:null}}catch{}return{isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null}}),u=s.useCallback(h=>{c(p=>{const x={...p,...h};return d&&typeof window<"u"&&(x.isAuthenticated?localStorage.setItem(i,JSON.stringify({isAuthenticated:!0,user:x.user})):localStorage.removeItem(i)),x})},[d,i]),k=s.useCallback(async(h,p)=>{u({loading:!0,error:null});try{if(a){const x=await a(h,p);return u({isAuthenticated:!0,user:x.user,tokens:x.tokens,loading:!1}),!0}return u({loading:!1,error:"No login handler configured"}),!1}catch(x){return u({loading:!1,error:(x==null?void 0:x.message)??"Login failed"}),!1}},[a,u]),f=s.useCallback(()=>{t==null||t(),u({isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null})},[t,u]),g=s.useCallback(async()=>{var h;if(!((h=l.tokens)!=null&&h.refreshToken)||!n)return!1;try{const p=await n(l.tokens.refreshToken);return u({tokens:p}),!0}catch{return f(),!1}},[l.tokens,n,u,f]),C=s.useCallback((h,p)=>{u({isAuthenticated:!0,user:h,tokens:p,loading:!1,error:null})},[u]),w=s.useCallback((...h)=>l.user?h.every(p=>l.user.roles.includes(p)):!1,[l.user]),o=s.useCallback((...h)=>l.user?h.every(p=>l.user.permissions.includes(p)):!1,[l.user]),b=s.useCallback(()=>{u({error:null})},[u]);return{...l,login:k,logout:f,refreshToken:g,setAuth:C,hasRoles:w,hasPermissions:o,clearError:b}}const ce=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,showRememberMe:t=!0,showForgotPassword:i=!0,onForgotPassword:d,showRegisterLink:l=!0,onRegisterClick:c,title:u,submitLabel:k,logo:f,footer:g,className:C,style:w,emailLabel:o,passwordLabel:b,tracelessPolicy:h,privacyMessage:p},x)=>{const{t:j}=q.useNiceTranslation(),[$,N]=s.useState(""),[S,F]=s.useState(""),[I,_]=s.useState(!1),P=s.useMemo(()=>!(!t||h&&!h.cookiesAllowed),[t,h]),D=s.useCallback(T=>{T.preventDefault();const R=(h==null?void 0:h.cookiesAllowed)===!1?!1:I;r==null||r({email:$,password:S,rememberMe:R})},[$,S,I,r,h]);return e.jsxs("form",{ref:x,className:`nice-login-form${C?` ${C}`:""}`,style:w,onSubmit:D,noValidate:!0,children:[f&&e.jsx("div",{className:"nice-login-form__logo",children:f}),e.jsx("h2",{className:"nice-login-form__title",children:u??j("loginForm.title","Sign In")}),n&&e.jsx("div",{className:"nice-login-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-email",children:o??j("loginForm.email","Email")}),e.jsx("input",{id:"nice-login-email",className:"nice-input",type:"email",value:$,onChange:T=>N(T.target.value),autoComplete:"email",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-password",children:b??j("loginForm.password","Password")}),e.jsx("input",{id:"nice-login-password",className:"nice-input",type:"password",value:S,onChange:T=>F(T.target.value),autoComplete:"current-password",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__options",children:[P&&e.jsxs("label",{className:"nice-login-form__remember",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:T=>_(T.target.checked),disabled:a}),e.jsx("span",{children:j("loginForm.rememberMe","Remember me")})]}),!P&&t&&p&&e.jsx("span",{className:"nice-login-form__privacy-notice",children:p}),i&&e.jsx("button",{type:"button",className:"nice-login-form__forgot",onClick:d,disabled:a,children:j("loginForm.forgotPassword","Forgot password?")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-login-form__submit",disabled:a||!$||!S,children:a?"…":k??j("loginForm.signIn","Sign In")}),l&&e.jsxs("div",{className:"nice-login-form__register",children:[e.jsxs("span",{children:[j("loginForm.dontHaveAnAccount","Don't have an account?")," "]}),e.jsx("button",{type:"button",onClick:c,disabled:a,children:j("loginForm.register","Register")})]}),g&&e.jsx("div",{className:"nice-login-form__footer",children:g})]})}),{displayName:"NiceLoginForm"}),ie={0:"Very weak",1:"Weak",2:"Fair",3:"Strong",4:"Very strong"},oe={0:"#d9534f",1:"#f0ad4e",2:"#5bc0de",3:"#5cb85c",4:"#2e7d32"};function H(r){if(!r)return 0;let a=0;return r.length>=8&&a++,r.length>=12&&a++,/[a-z]/.test(r)&&/[A-Z]/.test(r)&&a++,/\d/.test(r)&&a++,/[^a-zA-Z0-9]/.test(r)&&a++,Math.min(4,a)}const W=Object.assign(s.forwardRef(({password:r,strength:a,showLabel:n=!0,labels:t,className:i},d)=>{const{t:l}=q.useNiceTranslation(),c=a??H(r),u=oe[c],k=(c+1)/5*100;return e.jsxs("div",{ref:d,className:`nice-password-strength${i?` ${i}`:""}`,children:[e.jsx("div",{className:"nice-password-strength__bar",children:e.jsx("div",{className:"nice-password-strength__fill",style:{width:`${k}%`,backgroundColor:u}})}),n&&e.jsx("span",{className:"nice-password-strength__label",style:{color:u},children:t?t[c]:l(`passwordStrength.level.${c}`,ie[c])})]})}),{displayName:"NicePasswordStrength"}),le=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,onLoginClick:t,showPasswordStrength:i=!0,minPasswordStrength:d=2,termsUrl:l,privacyUrl:c,title:u,logo:k,footer:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(""),[j,$]=s.useState(""),[N,S]=s.useState(""),[F,I]=s.useState(""),[_,P]=s.useState(!1),D=H(N),T=N===F,R=b&&j&&N&&T&&_&&D>=d&&!a,m=s.useCallback(v=>{v.preventDefault(),R&&(r==null||r({firstName:b,lastName:p,email:j,password:N,acceptTerms:_}))},[R,b,p,j,N,_,r]);return e.jsxs("form",{ref:w,className:`nice-register-form${g?` ${g}`:""}`,style:C,onSubmit:m,noValidate:!0,children:[k&&e.jsx("div",{className:"nice-register-form__logo",children:k}),e.jsx("h2",{className:"nice-register-form__title",children:u??o("registrationForm.title","Create Account")}),n&&e.jsx("div",{className:"nice-register-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-register-form__row",children:[e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-first",children:o("registrationForm.firstName","First name *")}),e.jsx("input",{id:"nice-reg-first",className:"nice-input",type:"text",value:b,onChange:v=>h(v.target.value),required:!0,disabled:a,autoComplete:"given-name"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-last",children:o("registrationForm.lastName","Last name")}),e.jsx("input",{id:"nice-reg-last",className:"nice-input",type:"text",value:p,onChange:v=>x(v.target.value),disabled:a,autoComplete:"family-name"})]})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-email",children:o("registrationForm.email","Email *")}),e.jsx("input",{id:"nice-reg-email",className:"nice-input",type:"email",value:j,onChange:v=>$(v.target.value),required:!0,disabled:a,autoComplete:"email"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-pass",children:o("registrationForm.password","Password *")}),e.jsx("input",{id:"nice-reg-pass",className:"nice-input",type:"password",value:N,onChange:v=>S(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),i&&N.length>0&&e.jsx(W,{password:N})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-confirm",children:o("registrationForm.confirmPassword","Confirm password *")}),e.jsx("input",{id:"nice-reg-confirm",className:"nice-input",type:"password",value:F,onChange:v=>I(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),F&&!T&&e.jsx("span",{className:"nice-error-text",children:o("registrationForm.passwordsDoNotMatch","Passwords do not match")})]}),e.jsxs("label",{className:"nice-register-form__terms",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:v=>P(v.target.checked),disabled:a}),e.jsxs("span",{children:[o("registrationForm.iAcceptThe","I accept the")," ",l?e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.terms","Terms")}):o("registrationForm.terms","Terms"),c&&e.jsxs(e.Fragment,{children:[" ",o("registrationForm.and","and")," ",e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.privacyPolicy","Privacy Policy")})]})," *"]})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-register-form__submit",disabled:!R,children:a?"…":o("registrationForm.register","Register")}),t&&e.jsxs("div",{className:"nice-register-form__login",children:[e.jsxs("span",{children:[o("registrationForm.alreadyHaveAnAccount","Already have an account?")," "]}),e.jsx("button",{type:"button",onClick:t,children:o("registrationForm.signIn","Sign in")})]}),f&&e.jsx("div",{className:"nice-register-form__footer",children:f})]})}),{displayName:"NiceRegistrationForm"}),de=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.3em",height:"0.6em",margin:"0 0.35em 0.15em 0.1em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)",...r}}),ee=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.85em",height:"0.85em",borderRadius:"50%",border:"0.12em solid currentColor",borderTopColor:"transparent",transform:"rotate(-45deg)",...r}}),Y={lowercase:"abcdefghijklmnopqrstuvwxyz",uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",digits:"0123456789",symbols:"!@#$%^&*()-_=+[]{};:,.?/~"},ue=/[0Oo1lI|]/g,z={length:16,lowercase:!0,uppercase:!0,digits:!0,symbols:!0,excludeAmbiguous:!1},X={password:"Generated password",length:"Length",lowercase:"Lowercase (a–z)",uppercase:"Uppercase (A–Z)",digits:"Digits (0–9)",symbols:"Symbols (!@#…)",excludeAmbiguous:"Avoid look-alikes (0 O 1 l I)",generate:"Generate",copy:"Copy",copied:"Copied",noCharacterSets:"Pick at least one kind of character."},he=r=>{const a=globalThis.crypto;if(!a||typeof a.getRandomValues!="function")throw new Error("generatePassword: crypto.getRandomValues is not available");return a.getRandomValues(r)};let me=0;function Z(r,a){const n=Math.floor(4294967296/r)*r,t=new Uint32Array(1);for(;;){const i=a(t)[0];if(i<n)return i%r}}function J(r={},a=he){const n={...z,...r},t=["lowercase","uppercase","digits","symbols"].filter(c=>n[c]).map(c=>n.excludeAmbiguous?Y[c].replace(ue,""):Y[c]).filter(c=>c.length>0);if(t.length===0)return"";const i=Math.max(t.length,Math.min(1024,Math.floor(n.length))),d=t.join(""),l=t.map(c=>c[Z(c.length,a)]);for(;l.length<i;)l.push(d[Z(d.length,a)]);for(let c=l.length-1;c>0;c--){const u=Z(c+1,a);[l[c],l[u]]=[l[u],l[c]]}return l.join("")}const pe=({value:r,defaultValue:a="",onChange:n,options:t,defaultOptions:i,onOptionsChange:d,minLength:l=8,maxLength:c=64,showStrength:u=!0,showCopy:k=!0,onCopy:f,labels:g,disabled:C=!1,className:w,style:o,id:b})=>{const{t:h}=q.useNiceTranslation(),p={...Object.fromEntries(Object.keys(X).map(M=>[M,h(`passwordGenerator.${M}`,X[M])])),...g},[x]=s.useState(()=>`nice-password-generator-${++me}`),j=b??x,[$,N]=s.useState(()=>({...z,...i})),S=t?{...z,...t}:$,[F,I]=s.useState(()=>r===void 0&&!a?J({...z,...i,...t}):a),_=r??F,[P,D]=s.useState(!1),T=s.useRef(void 0);s.useEffect(()=>()=>clearTimeout(T.current),[]);const R=s.useCallback(M=>{r===void 0&&I(M),D(!1),n==null||n(M)},[r,n]),m=s.useCallback(M=>R(J(M)),[R]),v=(M,E)=>{const U={...S,[M]:E};t||N(U),d==null||d(U),m(U)},G=async()=>{!_||!navigator.clipboard||(await navigator.clipboard.writeText(_),D(!0),clearTimeout(T.current),T.current=setTimeout(()=>D(!1),1500),f==null||f(_))},A=!S.lowercase&&!S.uppercase&&!S.digits&&!S.symbols,V=Math.min(c,Math.max(l,S.length));return e.jsxs("div",{id:b,className:`nice-password-generator${w?` ${w}`:""}`,style:o,children:[e.jsxs("div",{className:"nice-password-generator__output",children:[e.jsx("input",{id:`${j}-value`,className:"nice-password-generator__value",type:"text",readOnly:!0,spellCheck:!1,autoComplete:"off",value:_,"aria-label":p.password}),e.jsx("button",{type:"button",className:"nice-password-generator__button",onClick:()=>m(S),disabled:C||A,"aria-label":p.generate,title:p.generate,children:e.jsx(ee,{})}),k&&e.jsx("button",{type:"button",className:"nice-password-generator__button nice-password-generator__button--copy",onClick:G,disabled:C||!_,"aria-live":"polite",children:P?e.jsxs(e.Fragment,{children:[e.jsx(de,{})," ",p.copied]}):p.copy})]}),u&&e.jsx(W,{password:_}),e.jsxs("div",{className:"nice-password-generator__length",children:[e.jsx("label",{htmlFor:`${j}-length`,children:p.length}),e.jsx("input",{id:`${j}-length`,type:"range",min:l,max:c,value:V,disabled:C,onChange:M=>v("length",Number(M.target.value))}),e.jsx("output",{htmlFor:`${j}-length`,className:"nice-password-generator__length-value",children:V})]}),e.jsx("div",{className:"nice-password-generator__sets",children:["lowercase","uppercase","digits","symbols","excludeAmbiguous"].map(M=>e.jsxs("label",{className:"nice-password-generator__option",children:[e.jsx("input",{type:"checkbox",checked:S[M],disabled:C,onChange:E=>v(M,E.target.checked)}),p[M]]},M))}),A&&e.jsx("p",{className:"nice-password-generator__error",role:"alert",children:p.noCharacterSets})]})},ge=Object.assign(s.forwardRef(({requireCurrentPassword:r=!0,onSubmit:a,loading:n=!1,error:t,success:i,minPasswordStrength:d=2,title:l,className:c,style:u},k)=>{const{t:f}=q.useNiceTranslation(),[g,C]=s.useState(""),[w,o]=s.useState(""),[b,h]=s.useState(""),p=H(w),x=w===b,j=(!r||g.length>0)&&w.length>0&&x&&p>=d&&!n,$=s.useCallback(N=>{N.preventDefault(),j&&(a==null||a({currentPassword:r?g:void 0,newPassword:w}))},[j,g,w,r,a]);return e.jsxs("form",{ref:k,className:`nice-change-password${c?` ${c}`:""}`,style:u,onSubmit:$,noValidate:!0,children:[e.jsx("h3",{className:"nice-change-password__title",children:l??f("changePassword.title","Change Password")}),t&&e.jsx("div",{className:"nice-change-password__error",role:"alert",children:t}),i&&e.jsx("div",{className:"nice-change-password__success",role:"status",children:i}),r&&e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-current",children:f("changePassword.currentPassword","Current password")}),e.jsx("input",{id:"nice-cp-current",className:"nice-input",type:"password",value:g,onChange:N=>C(N.target.value),autoComplete:"current-password",disabled:n,required:!0})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-new",children:f("changePassword.newPassword","New password")}),e.jsx("input",{id:"nice-cp-new",className:"nice-input",type:"password",value:w,onChange:N=>o(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),w.length>0&&e.jsx(W,{password:w})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-confirm",children:f("changePassword.confirmNewPassword","Confirm new password")}),e.jsx("input",{id:"nice-cp-confirm",className:"nice-input",type:"password",value:b,onChange:N=>h(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),b&&!x&&e.jsx("span",{className:"nice-error-text",children:f("changePassword.passwordsDoNotMatch","Passwords do not match")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:!j,children:n?"…":f("changePassword.changePassword","Change Password")})]})}),{displayName:"NiceChangePassword"}),fe=Object.assign(s.forwardRef(({secret:r,qrCodeUrl:a,issuer:n,accountName:t,onVerify:i,loading:d=!1,error:l,onCancel:c,recoveryCodes:u,step:k="setup",onStepChange:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(!1),[j,$]=s.useState(!1),N=s.useCallback(F=>{F.preventDefault(),b.length>=6&&(i==null||i(b))},[b,i]),S=`otpauth://totp/${n?`${n}:`:""}${t??"user"}?secret=${r}${n?`&issuer=${n}`:""}&digits=6&period=30`;return e.jsxs("div",{ref:w,className:`nice-2fa-setup${g?` ${g}`:""}`,style:C,children:[e.jsx("h3",{className:"nice-2fa-setup__title",children:o("twoFaSetup.twoFactorAuthentication","Two-Factor Authentication")}),k==="setup"&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.scanThisQrCodeWith","Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):")}),a?e.jsx("img",{src:a,alt:o("twoFaSetup.n2faQrCode","2FA QR Code"),className:"nice-2fa-setup__qr"}):e.jsxs("div",{className:"nice-2fa-setup__qr-placeholder",children:[e.jsx("span",{children:o("twoFaSetup.qrCode","QR Code")}),e.jsx("code",{className:"nice-2fa-setup__uri",children:S})]}),e.jsxs("div",{className:"nice-2fa-setup__secret",children:[e.jsxs("span",{children:[o("twoFaSetup.orEnterManually","Or enter manually:")," "]}),p?e.jsx("code",{className:"nice-2fa-setup__secret-key",children:r}):e.jsx("button",{type:"button",onClick:()=>x(!0),children:o("twoFaSetup.showSecretKey","Show secret key")})]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:()=>f==null?void 0:f("verify"),children:o("twoFaSetup.nextVerify","Next — Verify")})]}),k==="verify"&&e.jsxs("form",{className:"nice-2fa-setup__step",onSubmit:N,children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.enterThe6DigitCode","Enter the 6-digit code from your authenticator app:")}),l&&e.jsx("div",{className:"nice-2fa-setup__error",role:"alert",children:l}),e.jsx("input",{className:"nice-input nice-2fa-setup__code-input",type:"text",inputMode:"numeric",maxLength:6,value:b,onChange:F=>h(F.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",autoFocus:!0,disabled:d,autoComplete:"one-time-code"}),e.jsxs("div",{className:"nice-2fa-setup__actions",children:[e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>f==null?void 0:f("setup"),children:o("twoFaSetup.back","Back")}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:d||b.length<6,children:d?"…":o("twoFaSetup.verify","Verify")})]})]}),k==="recovery"&&u&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.saveTheseRecoveryCodesIn","Save these recovery codes in a safe place. Each code can only be used once:")}),e.jsx("div",{className:"nice-2fa-setup__recovery-codes",children:u.map((F,I)=>e.jsx("code",{className:"nice-2fa-setup__recovery-code",children:F},I))}),e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>{var F;(F=navigator.clipboard)==null||F.writeText(u.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),e=require("react/jsx-runtime"),q=require("@nice2dev/ui-core");function re(r={}){const{onLogin:a,onRefresh:n,onLogout:t,storageKey:i="nice_auth",persistAuth:d=!1}=r,[l,c]=s.useState(()=>{if(d&&typeof window<"u")try{const h=localStorage.getItem(i);if(h)return{...JSON.parse(h),loading:!1,error:null}}catch{}return{isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null}}),u=s.useCallback(h=>{c(p=>{const x={...p,...h};return d&&typeof window<"u"&&(x.isAuthenticated?localStorage.setItem(i,JSON.stringify({isAuthenticated:!0,user:x.user})):localStorage.removeItem(i)),x})},[d,i]),k=s.useCallback(async(h,p)=>{u({loading:!0,error:null});try{if(a){const x=await a(h,p);return u({isAuthenticated:!0,user:x.user,tokens:x.tokens,loading:!1}),!0}return u({loading:!1,error:"No login handler configured"}),!1}catch(x){return u({loading:!1,error:(x==null?void 0:x.message)??"Login failed"}),!1}},[a,u]),f=s.useCallback(()=>{t==null||t(),u({isAuthenticated:!1,user:null,tokens:null,loading:!1,error:null})},[t,u]),g=s.useCallback(async()=>{var h;if(!((h=l.tokens)!=null&&h.refreshToken)||!n)return!1;try{const p=await n(l.tokens.refreshToken);return u({tokens:p}),!0}catch{return f(),!1}},[l.tokens,n,u,f]),C=s.useCallback((h,p)=>{u({isAuthenticated:!0,user:h,tokens:p,loading:!1,error:null})},[u]),w=s.useCallback((...h)=>l.user?h.every(p=>l.user.roles.includes(p)):!1,[l.user]),o=s.useCallback((...h)=>l.user?h.every(p=>l.user.permissions.includes(p)):!1,[l.user]),b=s.useCallback(()=>{u({error:null})},[u]);return{...l,login:k,logout:f,refreshToken:g,setAuth:C,hasRoles:w,hasPermissions:o,clearError:b}}const ce=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,showRememberMe:t=!0,showForgotPassword:i=!0,onForgotPassword:d,showRegisterLink:l=!0,onRegisterClick:c,title:u,submitLabel:k,logo:f,footer:g,className:C,style:w,emailLabel:o,passwordLabel:b,tracelessPolicy:h,privacyMessage:p},x)=>{const{t:j}=q.useNiceTranslation(),[$,N]=s.useState(""),[S,F]=s.useState(""),[I,_]=s.useState(!1),P=s.useMemo(()=>!(!t||h&&!h.cookiesAllowed),[t,h]),D=s.useCallback(T=>{T.preventDefault();const R=(h==null?void 0:h.cookiesAllowed)===!1?!1:I;r==null||r({email:$,password:S,rememberMe:R})},[$,S,I,r,h]);return e.jsxs("form",{ref:x,className:`nice-login-form${C?` ${C}`:""}`,style:w,onSubmit:D,noValidate:!0,children:[f&&e.jsx("div",{className:"nice-login-form__logo",children:f}),u!==""&&e.jsx("h2",{className:"nice-login-form__title",children:u??j("loginForm.title","Sign In")}),n&&e.jsx("div",{className:"nice-login-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-email",children:o??j("loginForm.email","Email")}),e.jsx("input",{id:"nice-login-email",className:"nice-input",type:"email",value:$,onChange:T=>N(T.target.value),autoComplete:"email",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__field",children:[e.jsx("label",{htmlFor:"nice-login-password",children:b??j("loginForm.password","Password")}),e.jsx("input",{id:"nice-login-password",className:"nice-input",type:"password",value:S,onChange:T=>F(T.target.value),autoComplete:"current-password",required:!0,disabled:a})]}),e.jsxs("div",{className:"nice-login-form__options",children:[P&&e.jsxs("label",{className:"nice-login-form__remember",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:T=>_(T.target.checked),disabled:a}),e.jsx("span",{children:j("loginForm.rememberMe","Remember me")})]}),!P&&t&&p&&e.jsx("span",{className:"nice-login-form__privacy-notice",children:p}),i&&e.jsx("button",{type:"button",className:"nice-login-form__forgot",onClick:d,disabled:a,children:j("loginForm.forgotPassword","Forgot password?")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-login-form__submit",disabled:a||!$||!S,children:a?"…":k??j("loginForm.signIn","Sign In")}),l&&e.jsxs("div",{className:"nice-login-form__register",children:[e.jsxs("span",{children:[j("loginForm.dontHaveAnAccount","Don't have an account?")," "]}),e.jsx("button",{type:"button",onClick:c,disabled:a,children:j("loginForm.register","Register")})]}),g&&e.jsx("div",{className:"nice-login-form__footer",children:g})]})}),{displayName:"NiceLoginForm"}),ie={0:"Very weak",1:"Weak",2:"Fair",3:"Strong",4:"Very strong"},oe={0:"#d9534f",1:"#f0ad4e",2:"#5bc0de",3:"#5cb85c",4:"#2e7d32"};function H(r){if(!r)return 0;let a=0;return r.length>=8&&a++,r.length>=12&&a++,/[a-z]/.test(r)&&/[A-Z]/.test(r)&&a++,/\d/.test(r)&&a++,/[^a-zA-Z0-9]/.test(r)&&a++,Math.min(4,a)}const W=Object.assign(s.forwardRef(({password:r,strength:a,showLabel:n=!0,labels:t,className:i},d)=>{const{t:l}=q.useNiceTranslation(),c=a??H(r),u=oe[c],k=(c+1)/5*100;return e.jsxs("div",{ref:d,className:`nice-password-strength${i?` ${i}`:""}`,children:[e.jsx("div",{className:"nice-password-strength__bar",children:e.jsx("div",{className:"nice-password-strength__fill",style:{width:`${k}%`,backgroundColor:u}})}),n&&e.jsx("span",{className:"nice-password-strength__label",style:{color:u},children:t?t[c]:l(`passwordStrength.level.${c}`,ie[c])})]})}),{displayName:"NicePasswordStrength"}),le=Object.assign(s.forwardRef(({onSubmit:r,loading:a=!1,error:n,onLoginClick:t,showPasswordStrength:i=!0,minPasswordStrength:d=2,termsUrl:l,privacyUrl:c,title:u,logo:k,footer:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(""),[j,$]=s.useState(""),[N,S]=s.useState(""),[F,I]=s.useState(""),[_,P]=s.useState(!1),D=H(N),T=N===F,R=b&&j&&N&&T&&_&&D>=d&&!a,m=s.useCallback(v=>{v.preventDefault(),R&&(r==null||r({firstName:b,lastName:p,email:j,password:N,acceptTerms:_}))},[R,b,p,j,N,_,r]);return e.jsxs("form",{ref:w,className:`nice-register-form${g?` ${g}`:""}`,style:C,onSubmit:m,noValidate:!0,children:[k&&e.jsx("div",{className:"nice-register-form__logo",children:k}),e.jsx("h2",{className:"nice-register-form__title",children:u??o("registrationForm.title","Create Account")}),n&&e.jsx("div",{className:"nice-register-form__error",role:"alert",children:n}),e.jsxs("div",{className:"nice-register-form__row",children:[e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-first",children:o("registrationForm.firstName","First name *")}),e.jsx("input",{id:"nice-reg-first",className:"nice-input",type:"text",value:b,onChange:v=>h(v.target.value),required:!0,disabled:a,autoComplete:"given-name"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-last",children:o("registrationForm.lastName","Last name")}),e.jsx("input",{id:"nice-reg-last",className:"nice-input",type:"text",value:p,onChange:v=>x(v.target.value),disabled:a,autoComplete:"family-name"})]})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-email",children:o("registrationForm.email","Email *")}),e.jsx("input",{id:"nice-reg-email",className:"nice-input",type:"email",value:j,onChange:v=>$(v.target.value),required:!0,disabled:a,autoComplete:"email"})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-pass",children:o("registrationForm.password","Password *")}),e.jsx("input",{id:"nice-reg-pass",className:"nice-input",type:"password",value:N,onChange:v=>S(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),i&&N.length>0&&e.jsx(W,{password:N})]}),e.jsxs("div",{className:"nice-register-form__field",children:[e.jsx("label",{htmlFor:"nice-reg-confirm",children:o("registrationForm.confirmPassword","Confirm password *")}),e.jsx("input",{id:"nice-reg-confirm",className:"nice-input",type:"password",value:F,onChange:v=>I(v.target.value),required:!0,disabled:a,autoComplete:"new-password"}),F&&!T&&e.jsx("span",{className:"nice-error-text",children:o("registrationForm.passwordsDoNotMatch","Passwords do not match")})]}),e.jsxs("label",{className:"nice-register-form__terms",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:v=>P(v.target.checked),disabled:a}),e.jsxs("span",{children:[o("registrationForm.iAcceptThe","I accept the")," ",l?e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.terms","Terms")}):o("registrationForm.terms","Terms"),c&&e.jsxs(e.Fragment,{children:[" ",o("registrationForm.and","and")," ",e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:o("registrationForm.privacyPolicy","Privacy Policy")})]})," *"]})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary nice-register-form__submit",disabled:!R,children:a?"…":o("registrationForm.register","Register")}),t&&e.jsxs("div",{className:"nice-register-form__login",children:[e.jsxs("span",{children:[o("registrationForm.alreadyHaveAnAccount","Already have an account?")," "]}),e.jsx("button",{type:"button",onClick:t,children:o("registrationForm.signIn","Sign in")})]}),f&&e.jsx("div",{className:"nice-register-form__footer",children:f})]})}),{displayName:"NiceRegistrationForm"}),de=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.3em",height:"0.6em",margin:"0 0.35em 0.15em 0.1em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)",...r}}),ee=({style:r})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"0.85em",height:"0.85em",borderRadius:"50%",border:"0.12em solid currentColor",borderTopColor:"transparent",transform:"rotate(-45deg)",...r}}),Y={lowercase:"abcdefghijklmnopqrstuvwxyz",uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",digits:"0123456789",symbols:"!@#$%^&*()-_=+[]{};:,.?/~"},ue=/[0Oo1lI|]/g,z={length:16,lowercase:!0,uppercase:!0,digits:!0,symbols:!0,excludeAmbiguous:!1},X={password:"Generated password",length:"Length",lowercase:"Lowercase (a–z)",uppercase:"Uppercase (A–Z)",digits:"Digits (0–9)",symbols:"Symbols (!@#…)",excludeAmbiguous:"Avoid look-alikes (0 O 1 l I)",generate:"Generate",copy:"Copy",copied:"Copied",noCharacterSets:"Pick at least one kind of character."},he=r=>{const a=globalThis.crypto;if(!a||typeof a.getRandomValues!="function")throw new Error("generatePassword: crypto.getRandomValues is not available");return a.getRandomValues(r)};let me=0;function Z(r,a){const n=Math.floor(4294967296/r)*r,t=new Uint32Array(1);for(;;){const i=a(t)[0];if(i<n)return i%r}}function J(r={},a=he){const n={...z,...r},t=["lowercase","uppercase","digits","symbols"].filter(c=>n[c]).map(c=>n.excludeAmbiguous?Y[c].replace(ue,""):Y[c]).filter(c=>c.length>0);if(t.length===0)return"";const i=Math.max(t.length,Math.min(1024,Math.floor(n.length))),d=t.join(""),l=t.map(c=>c[Z(c.length,a)]);for(;l.length<i;)l.push(d[Z(d.length,a)]);for(let c=l.length-1;c>0;c--){const u=Z(c+1,a);[l[c],l[u]]=[l[u],l[c]]}return l.join("")}const pe=({value:r,defaultValue:a="",onChange:n,options:t,defaultOptions:i,onOptionsChange:d,minLength:l=8,maxLength:c=64,showStrength:u=!0,showCopy:k=!0,onCopy:f,labels:g,disabled:C=!1,className:w,style:o,id:b})=>{const{t:h}=q.useNiceTranslation(),p={...Object.fromEntries(Object.keys(X).map(M=>[M,h(`passwordGenerator.${M}`,X[M])])),...g},[x]=s.useState(()=>`nice-password-generator-${++me}`),j=b??x,[$,N]=s.useState(()=>({...z,...i})),S=t?{...z,...t}:$,[F,I]=s.useState(()=>r===void 0&&!a?J({...z,...i,...t}):a),_=r??F,[P,D]=s.useState(!1),T=s.useRef(void 0);s.useEffect(()=>()=>clearTimeout(T.current),[]);const R=s.useCallback(M=>{r===void 0&&I(M),D(!1),n==null||n(M)},[r,n]),m=s.useCallback(M=>R(J(M)),[R]),v=(M,E)=>{const U={...S,[M]:E};t||N(U),d==null||d(U),m(U)},G=async()=>{!_||!navigator.clipboard||(await navigator.clipboard.writeText(_),D(!0),clearTimeout(T.current),T.current=setTimeout(()=>D(!1),1500),f==null||f(_))},A=!S.lowercase&&!S.uppercase&&!S.digits&&!S.symbols,V=Math.min(c,Math.max(l,S.length));return e.jsxs("div",{id:b,className:`nice-password-generator${w?` ${w}`:""}`,style:o,children:[e.jsxs("div",{className:"nice-password-generator__output",children:[e.jsx("input",{id:`${j}-value`,className:"nice-password-generator__value",type:"text",readOnly:!0,spellCheck:!1,autoComplete:"off",value:_,"aria-label":p.password}),e.jsx("button",{type:"button",className:"nice-password-generator__button",onClick:()=>m(S),disabled:C||A,"aria-label":p.generate,title:p.generate,children:e.jsx(ee,{})}),k&&e.jsx("button",{type:"button",className:"nice-password-generator__button nice-password-generator__button--copy",onClick:G,disabled:C||!_,"aria-live":"polite",children:P?e.jsxs(e.Fragment,{children:[e.jsx(de,{})," ",p.copied]}):p.copy})]}),u&&e.jsx(W,{password:_}),e.jsxs("div",{className:"nice-password-generator__length",children:[e.jsx("label",{htmlFor:`${j}-length`,children:p.length}),e.jsx("input",{id:`${j}-length`,type:"range",min:l,max:c,value:V,disabled:C,onChange:M=>v("length",Number(M.target.value))}),e.jsx("output",{htmlFor:`${j}-length`,className:"nice-password-generator__length-value",children:V})]}),e.jsx("div",{className:"nice-password-generator__sets",children:["lowercase","uppercase","digits","symbols","excludeAmbiguous"].map(M=>e.jsxs("label",{className:"nice-password-generator__option",children:[e.jsx("input",{type:"checkbox",checked:S[M],disabled:C,onChange:E=>v(M,E.target.checked)}),p[M]]},M))}),A&&e.jsx("p",{className:"nice-password-generator__error",role:"alert",children:p.noCharacterSets})]})},ge=Object.assign(s.forwardRef(({requireCurrentPassword:r=!0,onSubmit:a,loading:n=!1,error:t,success:i,minPasswordStrength:d=2,title:l,className:c,style:u},k)=>{const{t:f}=q.useNiceTranslation(),[g,C]=s.useState(""),[w,o]=s.useState(""),[b,h]=s.useState(""),p=H(w),x=w===b,j=(!r||g.length>0)&&w.length>0&&x&&p>=d&&!n,$=s.useCallback(N=>{N.preventDefault(),j&&(a==null||a({currentPassword:r?g:void 0,newPassword:w}))},[j,g,w,r,a]);return e.jsxs("form",{ref:k,className:`nice-change-password${c?` ${c}`:""}`,style:u,onSubmit:$,noValidate:!0,children:[e.jsx("h3",{className:"nice-change-password__title",children:l??f("changePassword.title","Change Password")}),t&&e.jsx("div",{className:"nice-change-password__error",role:"alert",children:t}),i&&e.jsx("div",{className:"nice-change-password__success",role:"status",children:i}),r&&e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-current",children:f("changePassword.currentPassword","Current password")}),e.jsx("input",{id:"nice-cp-current",className:"nice-input",type:"password",value:g,onChange:N=>C(N.target.value),autoComplete:"current-password",disabled:n,required:!0})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-new",children:f("changePassword.newPassword","New password")}),e.jsx("input",{id:"nice-cp-new",className:"nice-input",type:"password",value:w,onChange:N=>o(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),w.length>0&&e.jsx(W,{password:w})]}),e.jsxs("div",{className:"nice-change-password__field",children:[e.jsx("label",{htmlFor:"nice-cp-confirm",children:f("changePassword.confirmNewPassword","Confirm new password")}),e.jsx("input",{id:"nice-cp-confirm",className:"nice-input",type:"password",value:b,onChange:N=>h(N.target.value),autoComplete:"new-password",disabled:n,required:!0}),b&&!x&&e.jsx("span",{className:"nice-error-text",children:f("changePassword.passwordsDoNotMatch","Passwords do not match")})]}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:!j,children:n?"…":f("changePassword.changePassword","Change Password")})]})}),{displayName:"NiceChangePassword"}),fe=Object.assign(s.forwardRef(({secret:r,qrCodeUrl:a,issuer:n,accountName:t,onVerify:i,loading:d=!1,error:l,onCancel:c,recoveryCodes:u,step:k="setup",onStepChange:f,className:g,style:C},w)=>{const{t:o}=q.useNiceTranslation(),[b,h]=s.useState(""),[p,x]=s.useState(!1),[j,$]=s.useState(!1),N=s.useCallback(F=>{F.preventDefault(),b.length>=6&&(i==null||i(b))},[b,i]),S=`otpauth://totp/${n?`${n}:`:""}${t??"user"}?secret=${r}${n?`&issuer=${n}`:""}&digits=6&period=30`;return e.jsxs("div",{ref:w,className:`nice-2fa-setup${g?` ${g}`:""}`,style:C,children:[e.jsx("h3",{className:"nice-2fa-setup__title",children:o("twoFaSetup.twoFactorAuthentication","Two-Factor Authentication")}),k==="setup"&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.scanThisQrCodeWith","Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):")}),a?e.jsx("img",{src:a,alt:o("twoFaSetup.n2faQrCode","2FA QR Code"),className:"nice-2fa-setup__qr"}):e.jsxs("div",{className:"nice-2fa-setup__qr-placeholder",children:[e.jsx("span",{children:o("twoFaSetup.qrCode","QR Code")}),e.jsx("code",{className:"nice-2fa-setup__uri",children:S})]}),e.jsxs("div",{className:"nice-2fa-setup__secret",children:[e.jsxs("span",{children:[o("twoFaSetup.orEnterManually","Or enter manually:")," "]}),p?e.jsx("code",{className:"nice-2fa-setup__secret-key",children:r}):e.jsx("button",{type:"button",onClick:()=>x(!0),children:o("twoFaSetup.showSecretKey","Show secret key")})]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:()=>f==null?void 0:f("verify"),children:o("twoFaSetup.nextVerify","Next — Verify")})]}),k==="verify"&&e.jsxs("form",{className:"nice-2fa-setup__step",onSubmit:N,children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.enterThe6DigitCode","Enter the 6-digit code from your authenticator app:")}),l&&e.jsx("div",{className:"nice-2fa-setup__error",role:"alert",children:l}),e.jsx("input",{className:"nice-input nice-2fa-setup__code-input",type:"text",inputMode:"numeric",maxLength:6,value:b,onChange:F=>h(F.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",autoFocus:!0,disabled:d,autoComplete:"one-time-code"}),e.jsxs("div",{className:"nice-2fa-setup__actions",children:[e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>f==null?void 0:f("setup"),children:o("twoFaSetup.back","Back")}),e.jsx("button",{type:"submit",className:"nice-btn nice-btn--primary",disabled:d||b.length<6,children:d?"…":o("twoFaSetup.verify","Verify")})]})]}),k==="recovery"&&u&&e.jsxs("div",{className:"nice-2fa-setup__step",children:[e.jsx("p",{className:"nice-2fa-setup__instruction",children:o("twoFaSetup.saveTheseRecoveryCodesIn","Save these recovery codes in a safe place. Each code can only be used once:")}),e.jsx("div",{className:"nice-2fa-setup__recovery-codes",children:u.map((F,I)=>e.jsx("code",{className:"nice-2fa-setup__recovery-code",children:F},I))}),e.jsx("button",{type:"button",className:"nice-btn",onClick:()=>{var F;(F=navigator.clipboard)==null||F.writeText(u.join(`
|
|
2
2
|
`)),$(!0)},children:j?o("twoFaSetup.copied","Copied!"):o("twoFaSetup.copyAllCodes","Copy all codes")}),c&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",onClick:c,children:o("twoFaSetup.done","Done")})]}),c&&k!=="recovery"&&e.jsx("button",{type:"button",className:"nice-2fa-setup__cancel",onClick:c,children:o("twoFaSetup.cancel","Cancel")})]})}),{displayName:"NiceTwoFaSetup"}),xe=500;function O(r,a){return Math.floor(Math.random()*(a-r+1))+r}function be(){return`${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function je(r,a){switch(r){case"math":{const n=a==="easy"?5:a==="hard"?20:10,t=O(1,n),i=O(1,n),d=a!=="easy"&&t>=i&&Math.random()<.5,l=d?t-i:t+i;return{kind:"math",prompt:`${t} ${d?"−":"+"} ${i}`,answer:l}}case"text":{const n=a==="easy"?4:a==="hard"?7:5,t="ABCDEFGHJKMNPQRSTUVWXYZ23456789";let i="";for(let d=0;d<n;d++)i+=t[O(0,t.length-1)];return{kind:"text",text:i}}case"slider":return{kind:"slider",target:O(70,92),tolerance:a==="easy"?8:a==="hard"?2:4};case"checkbox":default:return{kind:"checkbox"}}}function _e(r,a,n){if(!r)return;const t=r.getContext("2d");if(!t)return;const i=r.width,d=r.height;t.clearRect(0,0,i,d),t.fillStyle=n?"#1a1a1a":"#f3f4f6",t.fillRect(0,0,i,d),t.strokeStyle=n?"rgba(255,255,255,0.18)":"rgba(0,0,0,0.18)",t.lineWidth=1;for(let c=0;c<6;c++)t.beginPath(),t.moveTo(O(0,i),O(0,d)),t.lineTo(O(0,i),O(0,d)),t.stroke();t.fillStyle=n?"#e5e7eb":"#111827",t.textBaseline="middle";const l=i/(a.length+1);for(let c=0;c<a.length;c++){const u=O(22,30);t.save(),t.translate(l*(c+1),d/2+O(-4,4)),t.rotate(O(-22,22)*Math.PI/180),t.font=`bold ${u}px monospace`,t.fillText(a[c],-u/3,0),t.restore()}}const we=Object.assign(s.forwardRef((r,a)=>{const{t:n}=q.useNiceTranslation(),{variant:t,difficulty:i="medium",refreshable:d=!0,verifyToken:l,expiresMs:c,label:u=n("captcha.imNotARobot","I'm not a robot"),provider:k="custom",siteKey:f,onVerify:g,onExpire:C,onError:w,onRefresh:o,theme:b="light",size:h="normal",customRender:p,className:x,style:j}=r,$=s.useRef(null),N=s.useRef(null),S=s.useRef(void 0),[F,I]=s.useState(0),[_,P]=s.useState("idle"),[D,T]=s.useState(""),[R,m]=s.useState(""),[v,G]=s.useState(0),A=s.useMemo(()=>je(t??"checkbox",i),[t,i,F]),V=s.useCallback(()=>{P("idle"),T(""),m(""),G(0),I(y=>y+1)},[]),M=s.useCallback(()=>{V(),o==null||o()},[V,o]);s.useImperativeHandle(a,()=>({reset:V,refresh:M,container:$.current}),[V,M]),s.useEffect(()=>{t==="text"&&A.kind==="text"&&_e(N.current,A.text,b==="dark")},[t,A,b]),s.useEffect(()=>{if(_!=="verified"||!c)return;const y=setTimeout(()=>{C==null||C(),V()},c);return()=>clearTimeout(y)},[_,c,C,V]);const E=s.useCallback(()=>{const y=`ntd-cap:${t}:${be()}`;l?(P("verifying"),T(""),Promise.resolve().then(()=>l(y)).then(Q=>{Q?(P("verified"),g==null||g(y)):(P("error"),T(n("captcha.verificationFailedPleaseTryAgain","Verification failed. Please try again.")),I(ne=>ne+1),m(""))}).catch(Q=>{P("error"),T(n("captcha.verificationErrorPleaseTryAgain","Verification error. Please try again.")),w==null||w(Q)})):(P("verified"),g==null||g(y))},[t,l,g,w,n]),U=s.useCallback(()=>{P("error"),T(n("captcha.incorrectPleaseTryAgain","Incorrect, please try again.")),I(y=>y+1),m("")},[n]),te=s.useCallback(()=>{_==="verifying"||_==="verified"||(P("verifying"),T(""),S.current=setTimeout(E,xe))},[_,E]);s.useEffect(()=>()=>clearTimeout(S.current),[]);const K=s.useCallback(()=>{A.kind==="math"?R.trim()!==""&&Number(R)===A.answer?E():U():A.kind==="text"&&(R.trim().toUpperCase()===A.text?E():U())},[A,R,E,U]),se=s.useCallback(y=>{G(y),!(A.kind!=="slider"||_==="verified"||_==="verifying")&&Math.abs(y-A.target)<=A.tolerance&&E()},[A,_,E]);if(!t)return k==="custom"&&p?e.jsx("div",{ref:$,className:`nice-captcha nice-captcha--custom${x?` ${x}`:""}`,style:j,children:p}):e.jsx("div",{ref:$,className:`nice-captcha nice-captcha--${k} nice-captcha--${b}${h==="compact"?" nice-captcha--compact":""}${x?` ${x}`:""}`,style:j,"data-sitekey":f,"data-theme":b,"data-size":h,children:e.jsxs("div",{className:"nice-captcha__placeholder",children:[e.jsx("span",{children:n("captcha.captcha","Captcha ({provider})").replace("{provider}",String(k))}),e.jsx("p",{children:n("captcha.loadTheSdkToActivate","Load the {provider} SDK to activate verification.").replace("{provider}",String(k))})]})});const L=_==="verifying",B=_==="verified",ae=`nice-captcha nice-captcha--${t} nice-captcha--${b} nice-captcha--${_}${h==="compact"?" nice-captcha--compact":""}${x?` ${x}`:""}`;return e.jsxs("div",{ref:$,className:ae,style:j,role:"group","aria-label":n("captcha.captchaChallenge","Captcha challenge"),"data-variant":t,"data-status":_,"data-theme":b,children:[t==="checkbox"&&e.jsxs("button",{type:"button",className:"nice-captcha__checkbox",role:"checkbox","aria-checked":B,"aria-busy":L,disabled:L||B,onClick:te,children:[e.jsx("span",{className:"nice-captcha__box","aria-hidden":"true",children:L?"…":B?e.jsx("span",{style:{display:"inline-block",width:"0.3em",height:"0.6em",marginBottom:"0.15em",borderRight:"0.12em solid currentColor",borderBottom:"0.12em solid currentColor",transform:"rotate(45deg)"}}):""}),e.jsx("span",{className:"nice-captcha__label",children:u})]}),t==="math"&&A.kind==="math"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsxs("span",{className:"nice-captcha__prompt","aria-hidden":"true",children:[A.prompt," ="]}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"number",inputMode:"numeric",value:R,"aria-label":n("captcha.whatIs","What is {prompt}?").replace("{prompt}",String(A.prompt)),disabled:L||B,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),K())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||B||R.trim()==="",onClick:K,children:L?"…":n("captcha.verify","Verify")})]}),t==="text"&&A.kind==="text"&&e.jsxs("div",{className:"nice-captcha__challenge",children:[e.jsx("canvas",{ref:N,className:"nice-captcha__canvas",width:160,height:56,"aria-hidden":"true"}),e.jsx("input",{className:"nice-input nice-captcha__answer",type:"text",autoCapitalize:"characters",autoComplete:"off",value:R,"aria-label":n("captcha.typeTheCharactersShownIn","Type the characters shown in the image"),disabled:L||B,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),K())}}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary nice-captcha__verify",disabled:L||B||R.trim()==="",onClick:K,children:L?"…":n("captcha.verify","Verify")})]}),t==="slider"&&A.kind==="slider"&&e.jsxs("div",{className:"nice-captcha__challenge nice-captcha__challenge--slider",children:[e.jsx("span",{className:"nice-captcha__slider-hint","aria-hidden":"true",children:B?n("captcha.verified","Verified"):n("captcha.slideToTheMarker","Slide to the marker")}),e.jsxs("div",{className:"nice-captcha__track",children:[e.jsx("span",{className:"nice-captcha__target","aria-hidden":"true",style:{left:`${A.target}%`}}),e.jsx("input",{className:"nice-captcha__slider",type:"range",min:0,max:100,value:v,"aria-label":n("captcha.slideTheHandleToThe","Slide the handle to the marker to verify"),"aria-valuetext":`${v}%`,disabled:B||L,onChange:y=>se(Number(y.target.value))})]})]}),e.jsxs("div",{className:"nice-captcha__footer",children:[e.jsx("div",{className:"nice-captcha__message",role:"status","aria-live":"polite",children:D}),d&&e.jsx("button",{type:"button",className:"nice-captcha__refresh","aria-label":n("captcha.refreshChallenge","Refresh challenge"),title:n("captcha.refreshChallenge","Refresh challenge"),onClick:M,children:e.jsx(ee,{})})]})]})}),{displayName:"NiceCaptcha"}),Ne=[{id:"google",label:"Google",color:"#4285f4",textColor:"#fff"},{id:"microsoft",label:"Microsoft",color:"#00a4ef",textColor:"#fff"},{id:"discord",label:"Discord",color:"#5865f2",textColor:"#fff"},{id:"spotify",label:"Spotify",color:"#1db954",textColor:"#fff"},{id:"github",label:"GitHub",color:"#24292e",textColor:"#fff"}],ve=Object.assign(s.forwardRef(({providers:r=Ne,onProviderClick:a,disabled:n=!1,loadingProvider:t,direction:i="vertical",separatorText:d,showSeparator:l=!0,className:c,style:u},k)=>{const{t:f}=q.useNiceTranslation();return e.jsxs("div",{ref:k,className:`nice-oauth nice-oauth--${i}${c?` ${c}`:""}`,style:u,children:[l&&e.jsxs("div",{className:"nice-oauth__separator",children:[e.jsx("hr",{}),e.jsx("span",{children:d??f("oAuthButtons.orContinueWith","or continue with")}),e.jsx("hr",{})]}),e.jsx("div",{className:"nice-oauth__buttons",children:r.map(g=>e.jsxs("button",{type:"button",className:`nice-oauth__btn${t===g.id?" nice-oauth__btn--loading":""}`,style:{backgroundColor:g.color,color:g.textColor},onClick:()=>a==null?void 0:a(g.id),disabled:n||!!t,children:[g.icon&&e.jsx("span",{className:"nice-oauth__btn-icon",children:g.icon}),e.jsx("span",{className:"nice-oauth__btn-label",children:t===g.id?"…":g.label})]},g.id))})]})}),{displayName:"NiceOAuthButtons"}),ke=s.forwardRef(function(a,n){const{t}=q.useNiceTranslation(),{tokens:i,onCreate:d,onRevoke:l,availableScopes:c=[],maxTokens:u=10,title:k=t("tokenManagement.apiTokens","API Tokens"),className:f,style:g}=a,[C,w]=s.useState(!1),[o,b]=s.useState(""),[h,p]=s.useState([]),[x,j]=s.useState("90"),[$,N]=s.useState(null),[S,F]=s.useState(!1),[I,_]=s.useState(null),P=s.useCallback(async()=>{if(!(!d||!o.trim())){F(!0);try{const m=x?parseInt(x,10):void 0,v=await d(o.trim(),h,m);N(v),b(""),p([]),w(!1)}finally{F(!1)}}},[d,o,h,x]),D=s.useCallback(async m=>{if(l){_(m);try{await l(m)}finally{_(null)}}},[l]),T=m=>{p(v=>v.includes(m)?v.filter(G=>G!==m):[...v,m])},R=i.length<u;return e.jsxs("div",{ref:n,className:`nice-token-management ${f??""}`,style:g,children:[e.jsxs("div",{className:"nice-token-management__header",children:[e.jsx("h3",{children:k}),R&&e.jsx("button",{className:"nice-token-management__new-btn",onClick:()=>w(!0),disabled:C,children:t("tokenManagement.newToken","+ New Token")})]}),$&&e.jsxs("div",{className:"nice-token-management__reveal",children:[e.jsxs("p",{children:[e.jsx("strong",{children:t("tokenManagement.newTokenCreated","New token created!")})," ",t("tokenManagement.copyItNowItWont","Copy it now — it won't be shown again.")]}),e.jsx("code",{className:"nice-token-management__token-value",children:$}),e.jsx("button",{onClick:()=>N(null),children:t("tokenManagement.dismiss","Dismiss")})]}),C&&e.jsxs("div",{className:"nice-token-management__create-form",children:[e.jsxs("label",{children:[t("tokenManagement.name","Name"),e.jsx("input",{type:"text",value:o,onChange:m=>b(m.target.value),placeholder:t("tokenManagement.myApiToken","My API token"),maxLength:64})]}),c.length>0&&e.jsxs("fieldset",{children:[e.jsx("legend",{children:t("tokenManagement.scopes","Scopes")}),c.map(m=>e.jsxs("label",{className:"nice-token-management__scope",children:[e.jsx("input",{type:"checkbox",checked:h.includes(m),onChange:()=>T(m)}),m]},m))]}),e.jsxs("label",{children:[t("tokenManagement.expiresInDays","Expires in (days)"),e.jsx("input",{type:"number",value:x,onChange:m=>j(m.target.value),min:1,max:365})]}),e.jsxs("div",{className:"nice-token-management__create-actions",children:[e.jsx("button",{onClick:P,disabled:S||!o.trim(),children:S?t("tokenManagement.creating","Creating…"):t("tokenManagement.createToken","Create Token")}),e.jsx("button",{onClick:()=>w(!1),children:t("tokenManagement.cancel","Cancel")})]})]}),i.length===0?e.jsx("p",{className:"nice-token-management__empty",children:t("tokenManagement.noApiTokensYet","No API tokens yet.")}):e.jsxs("table",{className:"nice-token-management__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:t("tokenManagement.name","Name")}),e.jsx("th",{children:t("tokenManagement.prefix","Prefix")}),e.jsx("th",{children:t("tokenManagement.created","Created")}),e.jsx("th",{children:t("tokenManagement.expires","Expires")}),e.jsx("th",{children:t("tokenManagement.lastUsed","Last Used")}),e.jsx("th",{children:t("tokenManagement.scopes","Scopes")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.map(m=>{var v;return e.jsxs("tr",{children:[e.jsx("td",{children:m.name}),e.jsx("td",{children:e.jsxs("code",{children:[m.prefix,"…"]})}),e.jsx("td",{children:m.createdAt}),e.jsx("td",{children:m.expiresAt??"—"}),e.jsx("td",{children:m.lastUsedAt??t("tokenManagement.never","Never")}),e.jsx("td",{children:((v=m.scopes)==null?void 0:v.join(", "))||"—"}),e.jsx("td",{children:e.jsx("button",{className:"nice-token-management__revoke-btn",onClick:()=>D(m.id),disabled:I===m.id,children:I===m.id?t("tokenManagement.revoking","Revoking…"):t("tokenManagement.revoke","Revoke")})})]},m.id)})})]})]})});exports.NiceCaptcha=we;exports.NiceChangePassword=ge;exports.NiceLoginForm=ce;exports.NiceOAuthButtons=ve;exports.NicePasswordGenerator=pe;exports.NicePasswordStrength=W;exports.NiceRegistrationForm=le;exports.NiceTokenManagement=ke;exports.NiceTwoFaSetup=fe;exports.calcPasswordStrength=H;exports.generatePassword=J;exports.useAuth=re;
|
package/dist/index.mjs
CHANGED
|
@@ -121,7 +121,7 @@ const Te = /* @__PURE__ */ Object.assign(
|
|
|
121
121
|
noValidate: !0,
|
|
122
122
|
children: [
|
|
123
123
|
f && /* @__PURE__ */ e("div", { className: "nice-login-form__logo", children: f }),
|
|
124
|
-
/* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: h ?? N("loginForm.title", "Sign In") }),
|
|
124
|
+
h !== "" && /* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: h ?? N("loginForm.title", "Sign In") }),
|
|
125
125
|
n && /* @__PURE__ */ e("div", { className: "nice-login-form__error", role: "alert", children: n }),
|
|
126
126
|
/* @__PURE__ */ r("div", { className: "nice-login-form__field", children: [
|
|
127
127
|
/* @__PURE__ */ e("label", { htmlFor: "nice-login-email", children: o ?? N("loginForm.email", "Email") }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice2dev/auth",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.21",
|
|
4
4
|
"description": "Nice2Dev Auth — Login, registration, OAuth, 2FA, captcha, password strength, token management for React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"react-dom": ">=17.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@nice2dev/ui-core": "^1.4.
|
|
67
|
+
"@nice2dev/ui-core": "^1.4.21",
|
|
68
68
|
"@testing-library/jest-dom": "^7.0.1",
|
|
69
69
|
"@testing-library/react": "^16.3.3",
|
|
70
70
|
"@types/react": "^19.2.18",
|