@nemme/js-sdk 0.9.0 → 0.9.4
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/chunks/chunk-CZZ4p3Yf.js +1 -0
- package/dist/chunks/client-Bcd4ux9A.js +2 -0
- package/dist/chunks/client-Bcd4ux9A.js.map +1 -0
- package/dist/chunks/client-DSNW6X_M.js +364 -0
- package/dist/chunks/client-DSNW6X_M.js.map +1 -0
- package/dist/chunks/form-manager-BsBsY3Hj.js +12 -0
- package/dist/chunks/form-manager-BsBsY3Hj.js.map +1 -0
- package/dist/chunks/form-manager-UhU4AnMM.js +7066 -0
- package/dist/chunks/form-manager-UhU4AnMM.js.map +1 -0
- package/dist/chunks/httpClient-0OJWJWzk.js +162 -0
- package/dist/chunks/httpClient-0OJWJWzk.js.map +1 -0
- package/dist/chunks/httpClient-B2q7jRzA.js +2 -0
- package/dist/chunks/httpClient-B2q7jRzA.js.map +1 -0
- package/dist/forms.cjs +1 -2
- package/dist/forms.esm.js +2 -6
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +7 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/js-sdk.css +2 -1
- package/dist/nemme-sdk.umd.js +14 -14
- package/dist/nemme-sdk.umd.js.map +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.esm.js +94 -81
- package/dist/react.esm.js.map +1 -1
- package/dist/shims/use-sync-external-store-shim.d.ts +1 -0
- package/dist/style.cjs +1 -2
- package/dist/style.esm.js +0 -2
- package/package.json +26 -22
- package/dist/chunks/client-DNykEThs.js +0 -420
- package/dist/chunks/client-DNykEThs.js.map +0 -1
- package/dist/chunks/client-DTI3C-RQ.js +0 -2
- package/dist/chunks/client-DTI3C-RQ.js.map +0 -1
- package/dist/chunks/form-manager-CdG9IzjD.js +0 -12
- package/dist/chunks/form-manager-CdG9IzjD.js.map +0 -1
- package/dist/chunks/form-manager-Cf8vMLbu.js +0 -6143
- package/dist/chunks/form-manager-Cf8vMLbu.js.map +0 -1
- package/dist/chunks/httpClient-D2IO92uv.js +0 -149
- package/dist/chunks/httpClient-D2IO92uv.js.map +0 -1
- package/dist/chunks/httpClient-hrn9Ffa2.js +0 -2
- package/dist/chunks/httpClient-hrn9Ffa2.js.map +0 -1
- package/dist/chunks/jsx-runtime-BubrbI3X.js +0 -2
- package/dist/chunks/jsx-runtime-BubrbI3X.js.map +0 -1
- package/dist/chunks/jsx-runtime-jIxVPx5o.js +0 -32
- package/dist/chunks/jsx-runtime-jIxVPx5o.js.map +0 -1
- package/dist/forms.cjs.map +0 -1
- package/dist/forms.esm.js.map +0 -1
- package/dist/style.cjs.map +0 -1
- package/dist/style.esm.js.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=react.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/chunk-CZZ4p3Yf.js`),t=require(`./chunks/client-Bcd4ux9A.js`);let n=require(`react`);n=e.n(n,1);let r=require(`react/jsx-runtime`);var i=(0,n.createContext)(void 0);function a(e,t){switch(t.type){case`reset`:return{client:null,isInitialized:!1,error:null};case`success`:return{client:t.client,isInitialized:t.initialized,error:t.error};case`error`:return{client:null,isInitialized:!1,error:t.error}}}var o=({clientKey:e,config:o,children:s})=>{let[c,l]=(0,n.useReducer)(a,{client:null,isInitialized:!1,error:null}),u=(0,n.useMemo)(()=>o,[JSON.stringify(o)]);(0,n.useEffect)(()=>{let n=!1,r=null;return l({type:`reset`}),(async()=>{try{let i=new t.t(e);if(await i.init(u),n){i.destroy();return}r=i,l({type:`success`,client:i,initialized:i.initialized,error:i.lastInitError?i.lastInitError.message:null})}catch(e){n||l({type:`error`,error:e instanceof Error?e.message:`Failed to initialize Nemme client`})}})(),()=>{n=!0,r&&r.destroy()}},[e,u]);let d={client:c.client,isInitialized:c.isInitialized,error:c.error};return(0,r.jsx)(i.Provider,{value:d,children:s})},s=()=>{let e=(0,n.useContext)(i);if(e===void 0)throw Error(`useNemmeContext must be used within a NemmeProvider`);return e},c=()=>{let{client:e,isInitialized:t,error:r}=s();return{track:(0,n.useCallback)(async n=>{if(!e||!t){console.warn(`Nemme client not initialized`);return}return e.track(n)},[e,t]),flush:(0,n.useCallback)(async()=>{if(!e||!t){console.warn(`Nemme client not initialized`);return}return e.flush()},[e,t]),isInitialized:t,error:r,client:e}};exports.NemmeProvider=o,exports.useNemme=c,exports.useNemmeContext=s;
|
|
2
|
+
//# sourceMappingURL=react.cjs.map
|
package/dist/react.cjs.map
CHANGED
|
@@ -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, useMemo, useReducer } 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\ntype State = {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n};\n\ntype Action =\n | { type: 'reset' }\n | { type: 'success'; client: NemmeClient; initialized: boolean; error: string | null }\n | { type: 'error'; error: string };\n\nfunction reducer(_state: State, action: Action): State {\n switch (action.type) {\n case 'reset':\n return { client: null, isInitialized: false, error: null };\n case 'success':\n return { client: action.client, isInitialized: action.initialized, error: action.error };\n case 'error':\n return { client: null, isInitialized: false, error: action.error };\n }\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [state, dispatch] = useReducer(reducer, { client: null, isInitialized: false, error: null });\n\n // Stabilize config: only changes when the serialized value differs\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableConfig = useMemo<ClientConfigType>(() => config, [
|
|
1
|
+
{"version":3,"file":"react.cjs","names":[],"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, useMemo, useReducer } 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\ntype State = {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n};\n\ntype Action =\n | { type: 'reset' }\n | { type: 'success'; client: NemmeClient; initialized: boolean; error: string | null }\n | { type: 'error'; error: string };\n\nfunction reducer(_state: State, action: Action): State {\n switch (action.type) {\n case 'reset':\n return { client: null, isInitialized: false, error: null };\n case 'success':\n return { client: action.client, isInitialized: action.initialized, error: action.error };\n case 'error':\n return { client: null, isInitialized: false, error: action.error };\n }\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [state, dispatch] = useReducer(reducer, { client: null, isInitialized: false, error: null });\n\n // Stabilize config: only changes when the serialized value differs\n const serializedConfig = JSON.stringify(config);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableConfig = useMemo<ClientConfigType>(() => config, [serializedConfig]);\n\n useEffect(() => {\n let isCancelled = false;\n let currentClient: NemmeClient | null = null;\n\n dispatch({ type: 'reset' });\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(stableConfig);\n\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n dispatch({\n type: 'success',\n client: nemmeClient,\n initialized: nemmeClient.initialized,\n error: nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null\n });\n } catch (err) {\n if (!isCancelled) {\n dispatch({\n type: 'error',\n error: err instanceof Error ? err.message : 'Failed to initialize Nemme client'\n });\n }\n }\n };\n\n initializeClient();\n\n return () => {\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, stableConfig]);\n\n const value: NemmeContextType = {\n client: state.client,\n isInitialized: state.isInitialized,\n error: state.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"],"mappings":"+NASA,IAAa,GAAA,EAAA,EAAA,eAA2D,IAAA,GAAU,CCalF,SAAS,EAAQ,EAAe,EAAuB,CACrD,OAAQ,EAAO,KAAf,CACE,IAAK,QACH,MAAO,CAAE,OAAQ,KAAM,cAAe,GAAO,MAAO,KAAM,CAC5D,IAAK,UACH,MAAO,CAAE,OAAQ,EAAO,OAAQ,cAAe,EAAO,YAAa,MAAO,EAAO,MAAO,CAC1F,IAAK,QACH,MAAO,CAAE,OAAQ,KAAM,cAAe,GAAO,MAAO,EAAO,MAAO,EAIxE,IAAa,GAA+C,CAAE,YAAW,SAAQ,cAAe,CAC9F,GAAM,CAAC,EAAO,IAAA,EAAA,EAAA,YAAuB,EAAS,CAAE,OAAQ,KAAM,cAAe,GAAO,MAAO,KAAM,CAAC,CAK5F,GAAA,EAAA,EAAA,aAA+C,EAAQ,CAFpC,KAAK,UAAU,EAEsB,CAAiB,CAAC,EAEhF,EAAA,EAAA,eAAgB,CACd,IAAI,EAAc,GACd,EAAoC,KAiCxC,OA/BA,EAAS,CAAE,KAAM,QAAS,CAAC,EA6B3B,SA3BqC,CACnC,GAAI,CACF,IAAM,EAAc,IAAI,EAAA,EAAY,EAAU,CAG9C,GAFA,MAAM,EAAY,KAAK,EAAa,CAEhC,EAAa,CACf,EAAY,SAAS,CACrB,OAGF,EAAgB,EAChB,EAAS,CACP,KAAM,UACN,OAAQ,EACR,YAAa,EAAY,YACzB,MAAO,EAAY,cAAgB,EAAY,cAAc,QAAU,KACxE,CAAC,OACK,EAAK,CACP,GACH,EAAS,CACP,KAAM,QACN,MAAO,aAAe,MAAQ,EAAI,QAAU,oCAC7C,CAAC,KAKU,KAEL,CACX,EAAc,GACV,GACF,EAAc,SAAS,GAG1B,CAAC,EAAW,EAAa,CAAC,CAE7B,IAAM,EAA0B,CAC9B,OAAQ,EAAM,OACd,cAAe,EAAM,cACrB,MAAO,EAAM,MACd,CAED,OAAO,EAAA,EAAA,KAAC,EAAa,SAAd,CAA8B,QAAQ,WAAiC,CAAA,ECvFnE,MAAwB,CACnC,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAa,CACxC,GAAI,IAAY,IAAA,GACd,MAAU,MAAM,sDAAsD,CAExE,OAAO,GCJI,MAAiB,CAC5B,GAAM,CAAE,SAAQ,gBAAe,SAAU,GAAiB,CAqB1D,MAAO,CACL,OAAA,EAAA,EAAA,aAnBA,KAAoC,IAAe,CACjD,GAAI,CAAC,GAAU,CAAC,EAAe,CAC7B,QAAQ,KAAK,+BAA+B,CAC5C,OAEF,OAAO,EAAO,MAAM,EAAQ,EAE9B,CAAC,EAAQ,EAAc,CAYvB,CACA,OAAA,EAAA,EAAA,aAVwB,SAAY,CACpC,GAAI,CAAC,GAAU,CAAC,EAAe,CAC7B,QAAQ,KAAK,+BAA+B,CAC5C,OAEF,OAAO,EAAO,OAAO,EACpB,CAAC,EAAQ,EAAc,CAIxB,CACA,gBACA,QACA,SACD"}
|
package/dist/react.esm.js
CHANGED
|
@@ -1,83 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { t as e } from "./chunks/client-DSNW6X_M.js";
|
|
2
|
+
import { createContext as t, useCallback as n, useContext as r, useEffect as i, useMemo as a, useReducer as o } from "react";
|
|
3
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react/context.ts
|
|
5
|
+
var c = t(void 0);
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/react/NemmeProvider.tsx
|
|
8
|
+
function l(e, t) {
|
|
9
|
+
switch (t.type) {
|
|
10
|
+
case "reset": return {
|
|
11
|
+
client: null,
|
|
12
|
+
isInitialized: !1,
|
|
13
|
+
error: null
|
|
14
|
+
};
|
|
15
|
+
case "success": return {
|
|
16
|
+
client: t.client,
|
|
17
|
+
isInitialized: t.initialized,
|
|
18
|
+
error: t.error
|
|
19
|
+
};
|
|
20
|
+
case "error": return {
|
|
21
|
+
client: null,
|
|
22
|
+
isInitialized: !1,
|
|
23
|
+
error: t.error
|
|
24
|
+
};
|
|
25
|
+
}
|
|
14
26
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
27
|
+
var u = ({ clientKey: t, config: n, children: r }) => {
|
|
28
|
+
let [u, d] = o(l, {
|
|
29
|
+
client: null,
|
|
30
|
+
isInitialized: !1,
|
|
31
|
+
error: null
|
|
32
|
+
}), f = a(() => n, [JSON.stringify(n)]);
|
|
33
|
+
i(() => {
|
|
34
|
+
let n = !1, r = null;
|
|
35
|
+
return d({ type: "reset" }), (async () => {
|
|
36
|
+
try {
|
|
37
|
+
let i = new e(t);
|
|
38
|
+
if (await i.init(f), n) {
|
|
39
|
+
i.destroy();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
r = i, d({
|
|
43
|
+
type: "success",
|
|
44
|
+
client: i,
|
|
45
|
+
initialized: i.initialized,
|
|
46
|
+
error: i.lastInitError ? i.lastInitError.message : null
|
|
47
|
+
});
|
|
48
|
+
} catch (e) {
|
|
49
|
+
n || d({
|
|
50
|
+
type: "error",
|
|
51
|
+
error: e instanceof Error ? e.message : "Failed to initialize Nemme client"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
})(), () => {
|
|
55
|
+
n = !0, r && r.destroy();
|
|
56
|
+
};
|
|
57
|
+
}, [t, f]);
|
|
58
|
+
let p = {
|
|
59
|
+
client: u.client,
|
|
60
|
+
isInitialized: u.isInitialized,
|
|
61
|
+
error: u.error
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ s(c.Provider, {
|
|
64
|
+
value: p,
|
|
65
|
+
children: r
|
|
66
|
+
});
|
|
67
|
+
}, d = () => {
|
|
68
|
+
let e = r(c);
|
|
69
|
+
if (e === void 0) throw Error("useNemmeContext must be used within a NemmeProvider");
|
|
70
|
+
return e;
|
|
71
|
+
}, f = () => {
|
|
72
|
+
let { client: e, isInitialized: t, error: r } = d();
|
|
73
|
+
return {
|
|
74
|
+
track: n(async (n) => {
|
|
75
|
+
if (!e || !t) {
|
|
76
|
+
console.warn("Nemme client not initialized");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return e.track(n);
|
|
80
|
+
}, [e, t]),
|
|
81
|
+
flush: n(async () => {
|
|
82
|
+
if (!e || !t) {
|
|
83
|
+
console.warn("Nemme client not initialized");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return e.flush();
|
|
87
|
+
}, [e, t]),
|
|
88
|
+
isInitialized: t,
|
|
89
|
+
error: r,
|
|
90
|
+
client: e
|
|
91
|
+
};
|
|
77
92
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=react.esm.js.map
|
|
93
|
+
//#endregion
|
|
94
|
+
export { u as NemmeProvider, f as useNemme, d as useNemmeContext };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=react.esm.js.map
|
package/dist/react.esm.js.map
CHANGED
|
@@ -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, useMemo, useReducer } 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\ntype State = {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n};\n\ntype Action =\n | { type: 'reset' }\n | { type: 'success'; client: NemmeClient; initialized: boolean; error: string | null }\n | { type: 'error'; error: string };\n\nfunction reducer(_state: State, action: Action): State {\n switch (action.type) {\n case 'reset':\n return { client: null, isInitialized: false, error: null };\n case 'success':\n return { client: action.client, isInitialized: action.initialized, error: action.error };\n case 'error':\n return { client: null, isInitialized: false, error: action.error };\n }\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [state, dispatch] = useReducer(reducer, { client: null, isInitialized: false, error: null });\n\n // Stabilize config: only changes when the serialized value differs\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableConfig = useMemo<ClientConfigType>(() => config, [
|
|
1
|
+
{"version":3,"file":"react.esm.js","names":[],"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, useMemo, useReducer } 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\ntype State = {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n};\n\ntype Action =\n | { type: 'reset' }\n | { type: 'success'; client: NemmeClient; initialized: boolean; error: string | null }\n | { type: 'error'; error: string };\n\nfunction reducer(_state: State, action: Action): State {\n switch (action.type) {\n case 'reset':\n return { client: null, isInitialized: false, error: null };\n case 'success':\n return { client: action.client, isInitialized: action.initialized, error: action.error };\n case 'error':\n return { client: null, isInitialized: false, error: action.error };\n }\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [state, dispatch] = useReducer(reducer, { client: null, isInitialized: false, error: null });\n\n // Stabilize config: only changes when the serialized value differs\n const serializedConfig = JSON.stringify(config);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableConfig = useMemo<ClientConfigType>(() => config, [serializedConfig]);\n\n useEffect(() => {\n let isCancelled = false;\n let currentClient: NemmeClient | null = null;\n\n dispatch({ type: 'reset' });\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(stableConfig);\n\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n dispatch({\n type: 'success',\n client: nemmeClient,\n initialized: nemmeClient.initialized,\n error: nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null\n });\n } catch (err) {\n if (!isCancelled) {\n dispatch({\n type: 'error',\n error: err instanceof Error ? err.message : 'Failed to initialize Nemme client'\n });\n }\n }\n };\n\n initializeClient();\n\n return () => {\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, stableConfig]);\n\n const value: NemmeContextType = {\n client: state.client,\n isInitialized: state.isInitialized,\n error: state.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"],"mappings":";;;;AASA,IAAa,IAAe,EAA4C,KAAA,EAAU;;;ACalF,SAAS,EAAQ,GAAe,GAAuB;CACrD,QAAQ,EAAO,MAAf;EACE,KAAK,SACH,OAAO;GAAE,QAAQ;GAAM,eAAe;GAAO,OAAO;GAAM;EAC5D,KAAK,WACH,OAAO;GAAE,QAAQ,EAAO;GAAQ,eAAe,EAAO;GAAa,OAAO,EAAO;GAAO;EAC1F,KAAK,SACH,OAAO;GAAE,QAAQ;GAAM,eAAe;GAAO,OAAO,EAAO;GAAO;;;AAIxE,IAAa,KAA+C,EAAE,cAAW,WAAQ,kBAAe;CAC9F,IAAM,CAAC,GAAO,KAAY,EAAW,GAAS;EAAE,QAAQ;EAAM,eAAe;EAAO,OAAO;EAAM,CAAC,EAK5F,IAAe,QAAgC,GAAQ,CAFpC,KAAK,UAAU,EAEsB,CAAiB,CAAC;CAEhF,QAAgB;EACd,IAAI,IAAc,IACd,IAAoC;EAiCxC,OA/BA,EAAS,EAAE,MAAM,SAAS,CAAC,GA6B3B,YA3BqC;GACnC,IAAI;IACF,IAAM,IAAc,IAAI,EAAY,EAAU;IAG9C,IAFA,MAAM,EAAY,KAAK,EAAa,EAEhC,GAAa;KACf,EAAY,SAAS;KACrB;;IAIF,AADA,IAAgB,GAChB,EAAS;KACP,MAAM;KACN,QAAQ;KACR,aAAa,EAAY;KACzB,OAAO,EAAY,gBAAgB,EAAY,cAAc,UAAU;KACxE,CAAC;YACK,GAAK;IACZ,AAAK,KACH,EAAS;KACP,MAAM;KACN,OAAO,aAAe,QAAQ,EAAI,UAAU;KAC7C,CAAC;;MAKU,QAEL;GAEX,AADA,IAAc,IACV,KACF,EAAc,SAAS;;IAG1B,CAAC,GAAW,EAAa,CAAC;CAE7B,IAAM,IAA0B;EAC9B,QAAQ,EAAM;EACd,eAAe,EAAM;EACrB,OAAO,EAAM;EACd;CAED,OAAO,kBAAC,EAAa,UAAd;EAA8B;EAAQ;EAAiC,CAAA;GCvFnE,UAAwB;CACnC,IAAM,IAAU,EAAW,EAAa;CACxC,IAAI,MAAY,KAAA,GACd,MAAU,MAAM,sDAAsD;CAExE,OAAO;GCJI,UAAiB;CAC5B,IAAM,EAAE,WAAQ,kBAAe,aAAU,GAAiB;CAqB1D,OAAO;EACL,OApBY,EACZ,OAAoC,MAAe;GACjD,IAAI,CAAC,KAAU,CAAC,GAAe;IAC7B,QAAQ,KAAK,+BAA+B;IAC5C;;GAEF,OAAO,EAAO,MAAM,EAAQ;KAE9B,CAAC,GAAQ,EAAc,CAYvB;EACA,OAVY,EAAY,YAAY;GACpC,IAAI,CAAC,KAAU,CAAC,GAAe;IAC7B,QAAQ,KAAK,+BAA+B;IAC5C;;GAEF,OAAO,EAAO,OAAO;KACpB,CAAC,GAAQ,EAAc,CAIxB;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSyncExternalStore } from 'react';
|
package/dist/style.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=style.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
package/dist/style.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemme/js-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"author": "Nemme AS",
|
|
58
58
|
"license": "MIT",
|
|
59
59
|
"description": "Nemme JS SDK",
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"registry": "https://registry.npmjs.org/",
|
|
62
|
+
"access": "public"
|
|
63
|
+
},
|
|
60
64
|
"peerDependencies": {
|
|
61
65
|
"react": "^19.0.0",
|
|
62
66
|
"react-dom": "^19.0.0"
|
|
@@ -73,53 +77,53 @@
|
|
|
73
77
|
"@phosphor-icons/react": "^2.1.10",
|
|
74
78
|
"date-fns": "^4.1.0",
|
|
75
79
|
"i18next-browser-languagedetector": "^8.2.1",
|
|
76
|
-
"react-i18next": "^
|
|
80
|
+
"react-i18next": "^17.0.7"
|
|
77
81
|
},
|
|
78
82
|
"devDependencies": {
|
|
79
83
|
"@bcoe/v8-coverage": "^1.0.2",
|
|
80
|
-
"@chromatic-com/storybook": "^5.
|
|
84
|
+
"@chromatic-com/storybook": "^5.1.2",
|
|
81
85
|
"@eslint/compat": "^2.0.2",
|
|
82
86
|
"@eslint/eslintrc": "^3.2.0",
|
|
83
|
-
"@eslint/js": "^
|
|
87
|
+
"@eslint/js": "^10.0.1",
|
|
84
88
|
"@nemme/ui-kit": "^0.2.1",
|
|
85
|
-
"@storybook/addon-a11y": "^10.
|
|
86
|
-
"@storybook/addon-docs": "^10.
|
|
87
|
-
"@storybook/addon-vitest": "^10.
|
|
88
|
-
"@storybook/react-vite": "^10.
|
|
89
|
+
"@storybook/addon-a11y": "^10.3.6",
|
|
90
|
+
"@storybook/addon-docs": "^10.3.6",
|
|
91
|
+
"@storybook/addon-vitest": "^10.3.6",
|
|
92
|
+
"@storybook/react-vite": "^10.3.6",
|
|
89
93
|
"@tailwindcss/postcss": "^4.1.13",
|
|
90
94
|
"@tailwindcss/vite": "^4.1.13",
|
|
91
95
|
"@testing-library/jest-dom": "^6.6.3",
|
|
92
96
|
"@testing-library/react": "^16.3.2",
|
|
93
97
|
"@types/react": "^19.2.14",
|
|
94
98
|
"@types/react-dom": "^19.2.3",
|
|
95
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
96
|
-
"@typescript-eslint/parser": "^8.
|
|
97
|
-
"@vitejs/plugin-react": "^
|
|
99
|
+
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
100
|
+
"@typescript-eslint/parser": "^8.59.2",
|
|
101
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
98
102
|
"@vitest/browser": "^4.0.18",
|
|
99
103
|
"@vitest/coverage-v8": "^4.0.18",
|
|
100
|
-
"ast-v8-to-istanbul": "^0.
|
|
101
|
-
"eslint": "^
|
|
104
|
+
"ast-v8-to-istanbul": "^1.0.0",
|
|
105
|
+
"eslint": "^10.3.0",
|
|
102
106
|
"eslint-config-prettier": "^10.1.5",
|
|
103
107
|
"eslint-plugin-prettier": "^5.4.1",
|
|
104
108
|
"eslint-plugin-react": "^7.37.5",
|
|
105
109
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
106
|
-
"eslint-plugin-storybook": "^10.
|
|
110
|
+
"eslint-plugin-storybook": "^10.3.6",
|
|
107
111
|
"globals": "^17.3.0",
|
|
108
112
|
"happy-dom": "^20.6.1",
|
|
109
113
|
"husky": "^9.1.7",
|
|
110
|
-
"lint-staged": "^
|
|
114
|
+
"lint-staged": "^17.0.4",
|
|
111
115
|
"playwright": "^1.58.2",
|
|
112
116
|
"postcss": "^8.5.6",
|
|
113
117
|
"postcss-import": "^16.1.1",
|
|
114
|
-
"postcss-prefixwrap": "^1.
|
|
118
|
+
"postcss-prefixwrap": "^1.58.0",
|
|
115
119
|
"prettier": "^3.5.1",
|
|
116
|
-
"react": "^19.2.
|
|
117
|
-
"react-dom": "^19.2.
|
|
118
|
-
"storybook": "^10.
|
|
120
|
+
"react": "^19.2.6",
|
|
121
|
+
"react-dom": "^19.2.6",
|
|
122
|
+
"storybook": "^10.3.6",
|
|
119
123
|
"tailwindcss": "^4.1.13",
|
|
120
|
-
"typescript": "^
|
|
121
|
-
"vite": "^
|
|
122
|
-
"vite-plugin-dts": "^
|
|
124
|
+
"typescript": "^6.0.3",
|
|
125
|
+
"vite": "^8.0.11",
|
|
126
|
+
"vite-plugin-dts": "^5.0.0",
|
|
123
127
|
"vitest": "^4.0.18"
|
|
124
128
|
}
|
|
125
129
|
}
|