@trymellon/js 1.5.0 → 1.6.2

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/dist/react.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- "use strict";var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(e,r)=>{for(var t in r)y(e,t,{get:r[t],enumerable:!0})},x=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of d(r))!f.call(e,l)&&l!==t&&y(e,l,{get:()=>r[l],enumerable:!(n=T(r,l))||n.enumerable});return e};var E=e=>x(y({},"__esModule",{value:!0}),e);var A={};h(A,{TryMellonProvider:()=>m,useAuthenticate:()=>M,useRegister:()=>g,useTryMellon:()=>u});module.exports=E(A);var s=require("react"),R=require("react/jsx-runtime"),p=(0,s.createContext)(null);function m(e){return(0,R.jsx)(p.Provider,{value:e.client,children:e.children})}function u(){let e=(0,s.useContext)(p);if(e==null)throw new Error("useTryMellon must be used within TryMellonProvider");return e}var i=require("react");function g(){let e=u(),[r,t]=(0,i.useState)({result:null,loading:!1,error:null}),n=(0,i.useCallback)(async l=>{t(c=>({...c,loading:!0,error:null,result:null}));let o=await e.register(l);return t({result:o,loading:!1,error:o.ok?null:o.error}),o},[e]);return{result:r.result,loading:r.loading,error:r.error,execute:n}}var a=require("react");function M(){let e=u(),[r,t]=(0,a.useState)({result:null,loading:!1,error:null}),n=(0,a.useCallback)(async l=>{t(c=>({...c,loading:!0,error:null,result:null}));let o=await e.authenticate(l);return t({result:o,loading:!1,error:o.ok?null:o.error}),o},[e]);return{result:r.result,loading:r.loading,error:r.error,execute:n}}
2
+ "use strict";var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!x.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(n=A(t,o))||n.enumerable});return e};var S=e=>E(c({},"__esModule",{value:!0}),e);var O={};h(O,{TryMellonProvider:()=>y,useAuthenticate:()=>f,useRegister:()=>R,useTryMellon:()=>l});module.exports=S(O);var i=require("react"),m=require("react/jsx-runtime"),a=(0,i.createContext)(null);function y(e){return(0,m.jsx)(a.Provider,{value:e.client,children:e.children})}function l(){let e=(0,i.useContext)(a);if(e==null)throw new Error("useTryMellon must be used within TryMellonProvider");return e}var T=require("react");var u=require("react");function p(e){let[t,r]=(0,u.useState)({result:null,loading:!1,error:null}),n=(0,u.useCallback)(async o=>{r(g=>({...g,loading:!0,error:null,result:null}));let s=await e(o);return r({result:s,loading:!1,error:s.ok?null:s.error}),s},[e]);return{result:t.result,loading:t.loading,error:t.error,execute:n}}function R(){let e=l(),t=(0,T.useCallback)(r=>e.register(r),[e]);return p(t)}var M=require("react");function f(){let e=l(),t=(0,M.useCallback)(r=>e.authenticate(r),[e]);return p(t)}
3
3
  //# sourceMappingURL=react.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react/index.ts","../src/react/context.tsx","../src/react/use-register.tsx","../src/react/use-authenticate.tsx"],"sourcesContent":["export { TryMellonProvider, useTryMellon } from './context';\nexport { useRegister } from './use-register';\nexport { useAuthenticate } from './use-authenticate';\n","import { createContext, useContext, type ReactNode } from 'react';\nimport type { TryMellon } from '../core/trymellon';\n\nconst TryMellonContext = createContext<TryMellon | null>(null);\n\nexport function TryMellonProvider(props: { client: TryMellon; children: ReactNode }) {\n return (\n <TryMellonContext.Provider value={props.client}>{props.children}</TryMellonContext.Provider>\n );\n}\n\nexport function useTryMellon(): TryMellon {\n const client = useContext(TryMellonContext);\n if (client == null) {\n throw new Error('useTryMellon must be used within TryMellonProvider');\n }\n return client;\n}\n","import { useState, useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport type { RegisterOptions, RegisterResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseRegisterState = {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useRegister(): {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: RegisterOptions) => Promise<Result<RegisterResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const [state, setState] = useState<UseRegisterState>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: RegisterOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await client.register(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [client]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n","import { useState, useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport type { AuthenticateOptions, AuthenticateResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseAuthenticateState = {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useAuthenticate(): {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: AuthenticateOptions) => Promise<Result<AuthenticateResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const [state, setState] = useState<UseAuthenticateState>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: AuthenticateOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await client.authenticate(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [client]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n"],"mappings":";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAA0D,iBAOtDC,EAAA,6BAJEC,KAAmB,iBAAgC,IAAI,EAEtD,SAASC,EAAkBC,EAAmD,CACnF,SACE,OAACF,EAAiB,SAAjB,CAA0B,MAAOE,EAAM,OAAS,SAAAA,EAAM,SAAS,CAEpE,CAEO,SAASC,GAA0B,CACxC,IAAMC,KAAS,cAAWJ,CAAgB,EAC1C,GAAII,GAAU,KACZ,MAAM,IAAI,MAAM,oDAAoD,EAEtE,OAAOA,CACT,CCjBA,IAAAC,EAAsC,iBAY/B,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtB,CAACC,EAAOC,CAAQ,KAAI,YAA2B,CACnD,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,KAAU,eACd,MAAOC,GAA6B,CAClCF,EAAUG,IAAO,CAAE,GAAGA,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMC,EAAS,MAAMP,EAAO,SAASK,CAAO,EAC5C,OAAAF,EAAS,CACP,OAAAI,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACP,CAAM,CACT,EAEA,MAAO,CACL,OAAQE,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAE,CACF,CACF,CC7CA,IAAAI,EAAsC,iBAY/B,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtB,CAACC,EAAOC,CAAQ,KAAI,YAA+B,CACvD,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,KAAU,eACd,MAAOC,GAAiC,CACtCF,EAAUG,IAAO,CAAE,GAAGA,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMC,EAAS,MAAMP,EAAO,aAAaK,CAAO,EAChD,OAAAF,EAAS,CACP,OAAAI,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACP,CAAM,CACT,EAEA,MAAO,CACL,OAAQE,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAE,CACF,CACF","names":["react_exports","__export","TryMellonProvider","useAuthenticate","useRegister","useTryMellon","__toCommonJS","import_react","import_jsx_runtime","TryMellonContext","TryMellonProvider","props","useTryMellon","client","import_react","useRegister","client","useTryMellon","state","setState","execute","options","s","result","import_react","useAuthenticate","client","useTryMellon","state","setState","execute","options","s","result"]}
1
+ {"version":3,"sources":["../src/react/index.ts","../src/react/context.tsx","../src/react/use-register.tsx","../src/react/use-action.ts","../src/react/use-authenticate.tsx"],"sourcesContent":["export { TryMellonProvider, useTryMellon } from './context';\nexport { useRegister } from './use-register';\nexport { useAuthenticate } from './use-authenticate';\n","import { createContext, useContext, type ReactNode } from 'react';\nimport type { TryMellon } from '../core/trymellon';\n\nconst TryMellonContext = createContext<TryMellon | null>(null);\n\nexport function TryMellonProvider(props: { client: TryMellon; children: ReactNode }) {\n return (\n <TryMellonContext.Provider value={props.client}>{props.children}</TryMellonContext.Provider>\n );\n}\n\nexport function useTryMellon(): TryMellon {\n const client = useContext(TryMellonContext);\n if (client == null) {\n throw new Error('useTryMellon must be used within TryMellonProvider');\n }\n return client;\n}\n","import { useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport { useTryMellonAction, type UseActionState } from './use-action';\nimport type { RegisterOptions, RegisterResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseRegisterState = UseActionState<RegisterResult>;\n\nexport function useRegister(): {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: RegisterOptions) => Promise<Result<RegisterResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const action = useCallback((options: RegisterOptions) => client.register(options), [client]);\n return useTryMellonAction(action);\n}\n","import { useState, useCallback } from 'react';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseActionState<TResult> = {\n result: Result<TResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useTryMellonAction<TOptions, TResult>(\n action: (options: TOptions) => Promise<Result<TResult, TryMellonError>>\n) {\n const [state, setState] = useState<UseActionState<TResult>>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: TOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await action(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [action]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n","import { useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport { useTryMellonAction, type UseActionState } from './use-action';\nimport type { AuthenticateOptions, AuthenticateResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseAuthenticateState = UseActionState<AuthenticateResult>;\n\nexport function useAuthenticate(): {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: AuthenticateOptions) => Promise<Result<AuthenticateResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const action = useCallback(\n (options: AuthenticateOptions) => client.authenticate(options),\n [client]\n );\n return useTryMellonAction(action);\n}\n"],"mappings":";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAA0D,iBAOtDC,EAAA,6BAJEC,KAAmB,iBAAgC,IAAI,EAEtD,SAASC,EAAkBC,EAAmD,CACnF,SACE,OAACF,EAAiB,SAAjB,CAA0B,MAAOE,EAAM,OAAS,SAAAA,EAAM,SAAS,CAEpE,CAEO,SAASC,GAA0B,CACxC,IAAMC,KAAS,cAAWJ,CAAgB,EAC1C,GAAII,GAAU,KACZ,MAAM,IAAI,MAAM,oDAAoD,EAEtE,OAAOA,CACT,CCjBA,IAAAC,EAA4B,iBCA5B,IAAAC,EAAsC,iBAU/B,SAASC,EACdC,EACA,CACA,GAAM,CAACC,EAAOC,CAAQ,KAAI,YAAkC,CAC1D,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,KAAU,eACd,MAAOC,GAAsB,CAC3BF,EAAUG,IAAO,CAAE,GAAGA,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMC,EAAS,MAAMN,EAAOI,CAAO,EACnC,OAAAF,EAAS,CACP,OAAAI,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACN,CAAM,CACT,EAEA,MAAO,CACL,OAAQC,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAE,CACF,CACF,CD9BO,SAASI,GAKd,CACA,IAAMC,EAASC,EAAa,EACtBC,KAAS,eAAaC,GAA6BH,EAAO,SAASG,CAAO,EAAG,CAACH,CAAM,CAAC,EAC3F,OAAOI,EAAmBF,CAAM,CAClC,CElBA,IAAAG,EAA4B,iBASrB,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtBC,KAAS,eACZC,GAAiCH,EAAO,aAAaG,CAAO,EAC7D,CAACH,CAAM,CACT,EACA,OAAOI,EAAmBF,CAAM,CAClC","names":["react_exports","__export","TryMellonProvider","useAuthenticate","useRegister","useTryMellon","__toCommonJS","import_react","import_jsx_runtime","TryMellonContext","TryMellonProvider","props","useTryMellon","client","import_react","import_react","useTryMellonAction","action","state","setState","execute","options","s","result","useRegister","client","useTryMellon","action","options","useTryMellonAction","import_react","useAuthenticate","client","useTryMellon","action","options","useTryMellonAction"]}
package/dist/react.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import{createContext as a,useContext as c}from"react";import{jsx as p}from"react/jsx-runtime";var i=a(null);function y(e){return p(i.Provider,{value:e.client,children:e.children})}function o(){let e=c(i);if(e==null)throw new Error("useTryMellon must be used within TryMellonProvider");return e}import{useState as m,useCallback as R}from"react";function g(){let e=o(),[t,l]=m({result:null,loading:!1,error:null}),n=R(async u=>{l(s=>({...s,loading:!0,error:null,result:null}));let r=await e.register(u);return l({result:r,loading:!1,error:r.ok?null:r.error}),r},[e]);return{result:t.result,loading:t.loading,error:t.error,execute:n}}import{useState as M,useCallback as T}from"react";function d(){let e=o(),[t,l]=M({result:null,loading:!1,error:null}),n=T(async u=>{l(s=>({...s,loading:!0,error:null,result:null}));let r=await e.authenticate(u);return l({result:r,loading:!1,error:r.ok?null:r.error}),r},[e]);return{result:t.result,loading:t.loading,error:t.error,execute:n}}export{y as TryMellonProvider,d as useAuthenticate,g as useRegister,o as useTryMellon};
2
+ import{createContext as c,useContext as a}from"react";import{jsx as m}from"react/jsx-runtime";var s=c(null);function y(e){return m(s.Provider,{value:e.client,children:e.children})}function o(){let e=a(s);if(e==null)throw new Error("useTryMellon must be used within TryMellonProvider");return e}import{useCallback as M}from"react";import{useState as T,useCallback as R}from"react";function n(e){let[t,r]=T({result:null,loading:!1,error:null}),i=R(async u=>{r(p=>({...p,loading:!0,error:null,result:null}));let l=await e(u);return r({result:l,loading:!1,error:l.ok?null:l.error}),l},[e]);return{result:t.result,loading:t.loading,error:t.error,execute:i}}function f(){let e=o(),t=M(r=>e.register(r),[e]);return n(t)}import{useCallback as g}from"react";function A(){let e=o(),t=g(r=>e.authenticate(r),[e]);return n(t)}export{y as TryMellonProvider,A as useAuthenticate,f as useRegister,o as useTryMellon};
3
3
  //# sourceMappingURL=react.js.map
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react/context.tsx","../src/react/use-register.tsx","../src/react/use-authenticate.tsx"],"sourcesContent":["import { createContext, useContext, type ReactNode } from 'react';\nimport type { TryMellon } from '../core/trymellon';\n\nconst TryMellonContext = createContext<TryMellon | null>(null);\n\nexport function TryMellonProvider(props: { client: TryMellon; children: ReactNode }) {\n return (\n <TryMellonContext.Provider value={props.client}>{props.children}</TryMellonContext.Provider>\n );\n}\n\nexport function useTryMellon(): TryMellon {\n const client = useContext(TryMellonContext);\n if (client == null) {\n throw new Error('useTryMellon must be used within TryMellonProvider');\n }\n return client;\n}\n","import { useState, useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport type { RegisterOptions, RegisterResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseRegisterState = {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useRegister(): {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: RegisterOptions) => Promise<Result<RegisterResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const [state, setState] = useState<UseRegisterState>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: RegisterOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await client.register(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [client]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n","import { useState, useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport type { AuthenticateOptions, AuthenticateResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseAuthenticateState = {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useAuthenticate(): {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: AuthenticateOptions) => Promise<Result<AuthenticateResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const [state, setState] = useState<UseAuthenticateState>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: AuthenticateOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await client.authenticate(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [client]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n"],"mappings":";AAAA,OAAS,iBAAAA,EAAe,cAAAC,MAAkC,QAOtD,cAAAC,MAAA,oBAJJ,IAAMC,EAAmBH,EAAgC,IAAI,EAEtD,SAASI,EAAkBC,EAAmD,CACnF,OACEH,EAACC,EAAiB,SAAjB,CAA0B,MAAOE,EAAM,OAAS,SAAAA,EAAM,SAAS,CAEpE,CAEO,SAASC,GAA0B,CACxC,IAAMC,EAASN,EAAWE,CAAgB,EAC1C,GAAII,GAAU,KACZ,MAAM,IAAI,MAAM,oDAAoD,EAEtE,OAAOA,CACT,CCjBA,OAAS,YAAAC,EAAU,eAAAC,MAAmB,QAY/B,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtB,CAACC,EAAOC,CAAQ,EAAIC,EAA2B,CACnD,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,EAAUC,EACd,MAAOC,GAA6B,CAClCJ,EAAU,IAAO,CAAE,GAAG,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMK,EAAS,MAAMR,EAAO,SAASO,CAAO,EAC5C,OAAAJ,EAAS,CACP,OAAAK,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACR,CAAM,CACT,EAEA,MAAO,CACL,OAAQE,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAG,CACF,CACF,CC7CA,OAAS,YAAAI,EAAU,eAAAC,MAAmB,QAY/B,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtB,CAACC,EAAOC,CAAQ,EAAIC,EAA+B,CACvD,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,EAAUC,EACd,MAAOC,GAAiC,CACtCJ,EAAU,IAAO,CAAE,GAAG,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMK,EAAS,MAAMR,EAAO,aAAaO,CAAO,EAChD,OAAAJ,EAAS,CACP,OAAAK,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACR,CAAM,CACT,EAEA,MAAO,CACL,OAAQE,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAG,CACF,CACF","names":["createContext","useContext","jsx","TryMellonContext","TryMellonProvider","props","useTryMellon","client","useState","useCallback","useRegister","client","useTryMellon","state","setState","useState","execute","useCallback","options","result","useState","useCallback","useAuthenticate","client","useTryMellon","state","setState","useState","execute","useCallback","options","result"]}
1
+ {"version":3,"sources":["../src/react/context.tsx","../src/react/use-register.tsx","../src/react/use-action.ts","../src/react/use-authenticate.tsx"],"sourcesContent":["import { createContext, useContext, type ReactNode } from 'react';\nimport type { TryMellon } from '../core/trymellon';\n\nconst TryMellonContext = createContext<TryMellon | null>(null);\n\nexport function TryMellonProvider(props: { client: TryMellon; children: ReactNode }) {\n return (\n <TryMellonContext.Provider value={props.client}>{props.children}</TryMellonContext.Provider>\n );\n}\n\nexport function useTryMellon(): TryMellon {\n const client = useContext(TryMellonContext);\n if (client == null) {\n throw new Error('useTryMellon must be used within TryMellonProvider');\n }\n return client;\n}\n","import { useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport { useTryMellonAction, type UseActionState } from './use-action';\nimport type { RegisterOptions, RegisterResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseRegisterState = UseActionState<RegisterResult>;\n\nexport function useRegister(): {\n result: Result<RegisterResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: RegisterOptions) => Promise<Result<RegisterResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const action = useCallback((options: RegisterOptions) => client.register(options), [client]);\n return useTryMellonAction(action);\n}\n","import { useState, useCallback } from 'react';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseActionState<TResult> = {\n result: Result<TResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n};\n\nexport function useTryMellonAction<TOptions, TResult>(\n action: (options: TOptions) => Promise<Result<TResult, TryMellonError>>\n) {\n const [state, setState] = useState<UseActionState<TResult>>({\n result: null,\n loading: false,\n error: null,\n });\n\n const execute = useCallback(\n async (options: TOptions) => {\n setState((s) => ({ ...s, loading: true, error: null, result: null }));\n const result = await action(options);\n setState({\n result,\n loading: false,\n error: result.ok ? null : result.error,\n });\n return result;\n },\n [action]\n );\n\n return {\n result: state.result,\n loading: state.loading,\n error: state.error,\n execute,\n };\n}\n","import { useCallback } from 'react';\nimport { useTryMellon } from './context';\nimport { useTryMellonAction, type UseActionState } from './use-action';\nimport type { AuthenticateOptions, AuthenticateResult } from '../types';\nimport type { TryMellonError } from '../errors';\nimport type { Result } from '../utils/result';\n\nexport type UseAuthenticateState = UseActionState<AuthenticateResult>;\n\nexport function useAuthenticate(): {\n result: Result<AuthenticateResult, TryMellonError> | null;\n loading: boolean;\n error: TryMellonError | null;\n execute: (options: AuthenticateOptions) => Promise<Result<AuthenticateResult, TryMellonError>>;\n} {\n const client = useTryMellon();\n const action = useCallback(\n (options: AuthenticateOptions) => client.authenticate(options),\n [client]\n );\n return useTryMellonAction(action);\n}\n"],"mappings":";AAAA,OAAS,iBAAAA,EAAe,cAAAC,MAAkC,QAOtD,cAAAC,MAAA,oBAJJ,IAAMC,EAAmBH,EAAgC,IAAI,EAEtD,SAASI,EAAkBC,EAAmD,CACnF,OACEH,EAACC,EAAiB,SAAjB,CAA0B,MAAOE,EAAM,OAAS,SAAAA,EAAM,SAAS,CAEpE,CAEO,SAASC,GAA0B,CACxC,IAAMC,EAASN,EAAWE,CAAgB,EAC1C,GAAII,GAAU,KACZ,MAAM,IAAI,MAAM,oDAAoD,EAEtE,OAAOA,CACT,CCjBA,OAAS,eAAAC,MAAmB,QCA5B,OAAS,YAAAC,EAAU,eAAAC,MAAmB,QAU/B,SAASC,EACdC,EACA,CACA,GAAM,CAACC,EAAOC,CAAQ,EAAIL,EAAkC,CAC1D,OAAQ,KACR,QAAS,GACT,MAAO,IACT,CAAC,EAEKM,EAAUL,EACd,MAAOM,GAAsB,CAC3BF,EAAUG,IAAO,CAAE,GAAGA,EAAG,QAAS,GAAM,MAAO,KAAM,OAAQ,IAAK,EAAE,EACpE,IAAMC,EAAS,MAAMN,EAAOI,CAAO,EACnC,OAAAF,EAAS,CACP,OAAAI,EACA,QAAS,GACT,MAAOA,EAAO,GAAK,KAAOA,EAAO,KACnC,CAAC,EACMA,CACT,EACA,CAACN,CAAM,CACT,EAEA,MAAO,CACL,OAAQC,EAAM,OACd,QAASA,EAAM,QACf,MAAOA,EAAM,MACb,QAAAE,CACF,CACF,CD9BO,SAASI,GAKd,CACA,IAAMC,EAASC,EAAa,EACtBC,EAASC,EAAaC,GAA6BJ,EAAO,SAASI,CAAO,EAAG,CAACJ,CAAM,CAAC,EAC3F,OAAOK,EAAmBH,CAAM,CAClC,CElBA,OAAS,eAAAI,MAAmB,QASrB,SAASC,GAKd,CACA,IAAMC,EAASC,EAAa,EACtBC,EAASC,EACZC,GAAiCJ,EAAO,aAAaI,CAAO,EAC7D,CAACJ,CAAM,CACT,EACA,OAAOK,EAAmBH,CAAM,CAClC","names":["createContext","useContext","jsx","TryMellonContext","TryMellonProvider","props","useTryMellon","client","useCallback","useState","useCallback","useTryMellonAction","action","state","setState","execute","options","s","result","useRegister","client","useTryMellon","action","useCallback","options","useTryMellonAction","useCallback","useAuthenticate","client","useTryMellon","action","useCallback","options","useTryMellonAction"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trymellon/js",
3
- "version": "1.5.0",
3
+ "version": "1.6.2",
4
4
  "description": "SDK oficial de TryMellon para integrar autenticación passwordless con Passkeys / WebAuthn",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",