@nemme/js-sdk 0.6.0 → 0.6.1

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,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("./chunks/jsx-runtime-BubrbI3X.js"),r=require("react"),w=require("./chunks/client-DZJN73sh.js"),d=r.createContext(void 0),y=({clientKey:e,config:n,children:s})=>{const[l,i]=r.useState(null),[o,u]=r.useState(!1),[C,a]=r.useState(null);r.useEffect(()=>{let c=null,m=!1;const x=async()=>{try{const t=new w.NemmeClient(e);if(await t.init(n),m){t.destroy();return}c=t,i(t),u(t.initialized),a(t.lastInitError?t.lastInitError.message:null)}catch(t){m||(a(t instanceof Error?t.message:"Failed to initialize Nemme client"),u(!1))}},v=setTimeout(()=>{i(null),u(!1),a(null)},0);return x(),()=>{clearTimeout(v),m=!0,c&&c.destroy()}},[e,n]);const N={client:l,isInitialized:o,error:C};return z.jsxRuntimeExports.jsx(d.Provider,{value:N,children:s})},f=()=>{const e=r.useContext(d);if(e===void 0)throw new Error("useNemmeContext must be used within a NemmeProvider");return e},E=()=>{const{client:e,isInitialized:n,error:s}=f(),l=r.useCallback(async o=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.track(o)},[e,n]),i=r.useCallback(async()=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.flush()},[e,n]);return{track:l,flush:i,isInitialized:n,error:s,client:e}};exports.NemmeProvider=y;exports.useNemme=E;exports.useNemmeContext=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),r=require("react"),w=require("./chunks/client-DVvy_lUY.js"),d=r.createContext(void 0),y=({clientKey:e,config:n,children:s})=>{const[l,i]=r.useState(null),[o,a]=r.useState(!1),[C,c]=r.useState(null);r.useEffect(()=>{let u=null,m=!1;const x=async()=>{try{const t=new w.NemmeClient(e);if(await t.init(n),m){t.destroy();return}u=t,i(t),a(t.initialized),c(t.lastInitError?t.lastInitError.message:null)}catch(t){m||(c(t instanceof Error?t.message:"Failed to initialize Nemme client"),a(!1))}},v=setTimeout(()=>{i(null),a(!1),c(null)},0);return x(),()=>{clearTimeout(v),m=!0,u&&u.destroy()}},[e,n]);const N={client:l,isInitialized:o,error:C};return z.jsx(d.Provider,{value:N,children:s})},f=()=>{const e=r.useContext(d);if(e===void 0)throw new Error("useNemmeContext must be used within a NemmeProvider");return e},I=()=>{const{client:e,isInitialized:n,error:s}=f(),l=r.useCallback(async o=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.track(o)},[e,n]),i=r.useCallback(async()=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.flush()},[e,n]);return{track:l,flush:i,isInitialized:n,error:s,client:e}};exports.NemmeProvider=y;exports.useNemme=I;exports.useNemmeContext=f;
2
2
  //# sourceMappingURL=react.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.cjs","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNem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AAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,CACT,ECLaE,EAAW,IAAM,CAC5B,KAAM,CAAE,OAAApB,EAAQ,cAAAG,EAAe,MAAAE,CAAA,EAAUY,EAAA,EAEnCI,EAAQC,EAAAA,YACZ,MAAoCC,GAAe,CACjD,GAAI,CAACvB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAMuB,CAAO,CAC7B,EACA,CAACvB,EAAQG,CAAa,CAAA,EAGlBqB,EAAQF,EAAAA,YAAY,SAAY,CACpC,GAAI,CAACtB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAA,CAChB,EAAG,CAACA,EAAQG,CAAa,CAAC,EAE1B,MAAO,CACL,MAAAkB,EACA,MAAAG,EACA,cAAArB,EACA,MAAAE,EACA,OAAAL,CAAA,CAEJ"}
1
+ {"version":3,"file":"react.cjs","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNemme","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MAAM,qDAAqD,EAEvE,OAAOA,CACT,ECLaE,EAAW,IAAM,CAC5B,KAAM,CAAE,OAAApB,EAAQ,cAAAG,EAAe,MAAAE,CAAA,EAAUY,EAAA,EAEnCI,EAAQC,EAAAA,YACZ,MAAoCC,GAAe,CACjD,GAAI,CAACvB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAMuB,CAAO,CAC7B,EACA,CAACvB,EAAQG,CAAa,CAAA,EAGlBqB,EAAQF,EAAAA,YAAY,SAAY,CACpC,GAAI,CAACtB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAA,CAChB,EAAG,CAACA,EAAQG,CAAa,CAAC,EAE1B,MAAO,CACL,MAAAkB,EACA,MAAAG,EACA,cAAArB,EACA,MAAAE,EACA,OAAAL,CAAA,CAEJ"}
package/dist/react.esm.js CHANGED
@@ -1,9 +1,9 @@
1
- import { j as w } from "./chunks/jsx-runtime-jIxVPx5o.js";
2
- import { createContext as E, useState as u, useEffect as I, useContext as v, useCallback as d } from "react";
3
- import { N as h } from "./chunks/client-CEykSZ2c.js";
4
- const f = E(void 0), P = ({ clientKey: e, config: n, children: i }) => {
1
+ import { jsx as w } from "react/jsx-runtime";
2
+ import { createContext as I, useState as u, useEffect as v, useContext as E, useCallback as d } from "react";
3
+ import { N as h } from "./chunks/client-BPx3v4ob.js";
4
+ const f = I(void 0), b = ({ clientKey: e, config: n, children: i }) => {
5
5
  const [s, r] = u(null), [o, l] = u(!1), [C, a] = u(null);
6
- I(() => {
6
+ v(() => {
7
7
  let c = null, m = !1;
8
8
  const x = async () => {
9
9
  try {
@@ -28,14 +28,14 @@ const f = E(void 0), P = ({ clientKey: e, config: n, children: i }) => {
28
28
  isInitialized: o,
29
29
  error: C
30
30
  };
31
- return /* @__PURE__ */ w.jsx(f.Provider, { value: N, children: i });
32
- }, p = () => {
33
- const e = v(f);
31
+ return /* @__PURE__ */ w(f.Provider, { value: N, children: i });
32
+ }, y = () => {
33
+ const e = E(f);
34
34
  if (e === void 0)
35
35
  throw new Error("useNemmeContext must be used within a NemmeProvider");
36
36
  return e;
37
- }, b = () => {
38
- const { client: e, isInitialized: n, error: i } = p(), s = d(
37
+ }, T = () => {
38
+ const { client: e, isInitialized: n, error: i } = y(), s = d(
39
39
  async (o) => {
40
40
  if (!e || !n) {
41
41
  console.warn("Nemme client not initialized");
@@ -60,8 +60,8 @@ const f = E(void 0), P = ({ clientKey: e, config: n, children: i }) => {
60
60
  };
61
61
  };
62
62
  export {
63
- P as NemmeProvider,
64
- b as useNemme,
65
- p as useNemmeContext
63
+ b as NemmeProvider,
64
+ T as useNemme,
65
+ y as useNemmeContext
66
66
  };
67
67
  //# sourceMappingURL=react.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.esm.js","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNemme","track","useCallback","options","flush"],"mappings":";;;AASO,MAAMA,IAAeC,EAA4C,MAAS,GCE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,MAAM,qDAAqD;AAEvE,SAAOA;AACT,GCLaE,IAAW,MAAM;AAC5B,QAAM,EAAE,QAAApB,GAAQ,eAAAG,GAAe,OAAAE,EAAA,IAAUY,EAAA,GAEnCI,IAAQC;AAAA,IACZ,OAAoCC,MAAe;AACjD,UAAI,CAACvB,KAAU,CAACG,GAAe;AAC7B,gBAAQ,KAAK,8BAA8B;AAC3C;AAAA,MACF;AACA,aAAOH,EAAO,MAAMuB,CAAO;AAAA,IAC7B;AAAA,IACA,CAACvB,GAAQG,CAAa;AAAA,EAAA,GAGlBqB,IAAQF,EAAY,YAAY;AACpC,QAAI,CAACtB,KAAU,CAACG,GAAe;AAC7B,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AACA,WAAOH,EAAO,MAAA;AAAA,EAChB,GAAG,CAACA,GAAQG,CAAa,CAAC;AAE1B,SAAO;AAAA,IACL,OAAAkB;AAAA,IACA,OAAAG;AAAA,IACA,eAAArB;AAAA,IACA,OAAAE;AAAA,IACA,QAAAL;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"react.esm.js","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNemme","track","useCallback","options","flush"],"mappings":";;;AASO,MAAMA,IAAeC,EAA4C,MAAS,GCEpEC,IAA8C,CAAC,EAAE,WAAAC,GAAW,QAAAC,GAAQ,UAAAC,QAAe;AAC9F,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAA6B,IAAI,GACvD,CAACC,GAAeC,CAAgB,IAAIF,EAAS,EAAK,GAClD,CAACG,GAAOC,CAAQ,IAAIJ,EAAwB,IAAI;AAEtD,EAAAK,EAAU,MAAM;AACd,QAAIC,IAAoC,MACpCC,IAAc;AAElB,UAAMC,IAAmB,YAAY;AACnC,UAAI;AACF,cAAMC,IAAc,IAAIC,EAAYf,CAAS;AAI7C,YAHA,MAAMc,EAAY,KAAKb,CAAM,GAGzBW,GAAa;AACf,UAAAE,EAAY,QAAA;AACZ;AAAA,QACF;AAEA,QAAAH,IAAgBG,GAChBV,EAAUU,CAAW,GACrBP,EAAiBO,EAAY,WAAW,GACxCL,EAASK,EAAY,gBAAgBA,EAAY,cAAc,UAAU,IAAI;AAAA,MAC/E,SAASE,GAAK;AACZ,QAAKJ,MACHH,EAASO,aAAe,QAAQA,EAAI,UAAU,mCAAmC,GACjFT,EAAiB,EAAK;AAAA,MAE1B;AAAA,IACF,GAGMU,IAAU,WAAW,MAAM;AAC/B,MAAAb,EAAU,IAAI,GACdG,EAAiB,EAAK,GACtBE,EAAS,IAAI;AAAA,IACf,GAAG,CAAC;AAEJ,WAAAI,EAAA,GAEO,MAAM;AACX,mBAAaI,CAAO,GACpBL,IAAc,IACVD,KACFA,EAAc,QAAA;AAAA,IAElB;AAAA,EACF,GAAG,CAACX,GAAWC,CAAM,CAAC;AAEtB,QAAMiB,IAA0B;AAAA,IAC9B,QAAAf;AAAA,IACA,eAAAG;AAAA,IACA,OAAAE;AAAA,EAAA;AAGF,SAAO,gBAAAW,EAACtB,EAAa,UAAb,EAAsB,OAAAqB,GAAe,UAAAhB,EAAA,CAAS;AACxD,GCjEakB,IAAkB,MAAM;AACnC,QAAMC,IAAUC,EAAWzB,CAAY;AACvC,MAAIwB,MAAY;AACd,UAAM,IAAI,MAAM,qDAAqD;AAEvE,SAAOA;AACT,GCLaE,IAAW,MAAM;AAC5B,QAAM,EAAE,QAAApB,GAAQ,eAAAG,GAAe,OAAAE,EAAA,IAAUY,EAAA,GAEnCI,IAAQC;AAAA,IACZ,OAAoCC,MAAe;AACjD,UAAI,CAACvB,KAAU,CAACG,GAAe;AAC7B,gBAAQ,KAAK,8BAA8B;AAC3C;AAAA,MACF;AACA,aAAOH,EAAO,MAAMuB,CAAO;AAAA,IAC7B;AAAA,IACA,CAACvB,GAAQG,CAAa;AAAA,EAAA,GAGlBqB,IAAQF,EAAY,YAAY;AACpC,QAAI,CAACtB,KAAU,CAACG,GAAe;AAC7B,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AACA,WAAOH,EAAO,MAAA;AAAA,EAChB,GAAG,CAACA,GAAQG,CAAa,CAAC;AAE1B,SAAO;AAAA,IACL,OAAAkB;AAAA,IACA,OAAAG;AAAA,IACA,eAAArB;AAAA,IACA,OAAAE;AAAA,IACA,QAAAL;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemme/js-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",