@jitsu/jitsu-react 1.1.0-canary.206.20230220023641 → 1.1.0-canary.211.20230220172137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { AnalyticsInterface } from "@jitsu/js";
3
- import { ExtendedJitsuOptions } from "./useJitsu";
4
- /**
5
- * An instance if Jitsu that is kept in the context. It's one of:
6
- * - AnalyticsInterface - for CSR, if Jitsu is initialized in browser
7
- * - ExtendedJitsuOptions - for SSR, if provider can't access context
8
- */
9
3
  export declare type JitsuInstance = {
10
4
  analytics: AnalyticsInterface;
11
- initOptions?: never;
12
- } | {
13
- analytics?: never;
14
- initOptions: ExtendedJitsuOptions;
15
5
  };
16
- declare const JitsuContext: import("react").Context<{
17
- analytics: AnalyticsInterface;
18
- initOptions?: undefined;
19
- } | {
20
- analytics?: undefined;
21
- initOptions: ExtendedJitsuOptions;
22
- } | null>;
6
+ declare const JitsuContext: import("react").Context<JitsuInstance | null>;
23
7
  export default JitsuContext;
package/dist/index.js CHANGED
@@ -4,46 +4,33 @@ var js = require('@jitsu/js');
4
4
  var JitsuContext = React.createContext(null);
5
5
 
6
6
  var JitsuProvider = function JitsuProvider(props) {
7
+ var instance;
7
8
  if (props.options.disabled) {
9
+ instance = {
10
+ analytics: js.emptyAnalytics
11
+ };
8
12
  return React.createElement(React.Fragment, null, props.children);
9
- }
10
- if (!props.options.host) {
13
+ } else if (!props.options.host) {
11
14
  var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
12
15
  console.error("%c" + msg, "color: red; font-weight: bold;");
13
- console.error(msg);
14
- return React.createElement(React.Fragment, null, props.children);
16
+ instance = {
17
+ analytics: js.emptyAnalytics
18
+ };
19
+ } else {
20
+ instance = {
21
+ analytics: js.jitsuAnalytics(props.options)
22
+ };
15
23
  }
16
24
  return React.createElement(JitsuContext.Provider, {
17
- value: js.isInBrowser() ? {
18
- analytics: js.jitsuAnalytics(props.options)
19
- } : {
20
- initOptions: props.options
21
- }
25
+ value: instance
22
26
  }, props.children);
23
27
  };
24
28
 
25
- var emptyAnalytics = {
26
- track: function track() {
27
- return Promise.resolve();
28
- },
29
- page: function page() {
30
- return Promise.resolve();
31
- },
32
- user: function user() {
33
- return {};
34
- },
35
- identify: function identify() {
36
- return Promise.resolve({});
37
- },
38
- reset: function reset() {
39
- return Promise.resolve({});
40
- }
41
- };
42
29
  function useJitsu(opts) {
43
30
  var jitsuInstance = React.useContext(JitsuContext);
44
31
  if (opts !== null && opts !== void 0 && opts.disabled) {
45
32
  return {
46
- analytics: emptyAnalytics
33
+ analytics: js.emptyAnalytics
47
34
  };
48
35
  }
49
36
  if (!jitsuInstance) {
@@ -53,9 +40,9 @@ function useJitsu(opts) {
53
40
  };
54
41
  } else {
55
42
  var msg = "Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react";
56
- console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
43
+ console.error("%c" + msg, "color: red; font-weight: bold;");
57
44
  return {
58
- analytics: emptyAnalytics
45
+ analytics: js.emptyAnalytics
59
46
  };
60
47
  }
61
48
  } else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
@@ -65,10 +52,7 @@ function useJitsu(opts) {
65
52
  analytics: jitsuInstance.analytics
66
53
  };
67
54
  } else {
68
- var analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : js.jitsuAnalytics(jitsuInstance.initOptions);
69
- return {
70
- analytics: analytics
71
- };
55
+ throw new Error("<JitsuProvider /> is not initialized with undefined analytics instance");
72
56
  }
73
57
  }
74
58
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\n/**\n * An instance if Jitsu that is kept in the context. It's one of:\n * - AnalyticsInterface - for CSR, if Jitsu is initialized in browser\n * - ExtendedJitsuOptions - for SSR, if provider can't access context\n */\nexport type JitsuInstance =\n | { analytics: AnalyticsInterface; initOptions?: never }\n | { analytics?: never; initOptions: ExtendedJitsuOptions };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics, isInBrowser } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n if (props.options.disabled) {\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n return (\n <JitsuContext.Provider\n value={isInBrowser() ? { analytics: jitsuAnalytics(props.options) } : { initOptions: props.options }}\n >\n {props.children}\n </JitsuContext.Provider>\n );\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\nconst emptyAnalytics = {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n //useJitsu() isn't wrapped into JitsuProvider. Return new instance of Jitsu provider if config is provided\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-size: 16px; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n const analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);\n return { analytics };\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","Provider","value","isInBrowser","analytics","jitsuAnalytics","initOptions","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAaA,IAAMA,YAAY,GAAGC,mBAAa,CAAuB,IAAI,CAAC;;ACP9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIA,KAAK,CAACC,OAAO,CAACC,QAAQ,EAAE;IAC1B,OAAOC,oBAACA,cAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAI,CAACJ,KAAK,CAACC,OAAO,CAACI,IAAI,EAAE;IACvB,IAAMC,GAAG,GAAG,6EAA6E;IACzFC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AAO;QAAEM,SAAS,EAAEG;OAAgB;;GAEvC,MAAM,IAAIS,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEnB,IAAI,IAAImB,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,UAAU,EAAE;IACzC,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;GAEF,MAAM,IAAIH,aAAa,CAACb,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,IAAMA,SAAS,GAAGa,aAAa,CAACX,WAAW,CAACZ,QAAQ,GAAGa,cAAc,GAAGF,iBAAc,CAACY,aAAa,CAACX,WAAW,CAAC;IACjH,OAAO;MAAEF,SAAS,EAATA;KAAW;;AAExB;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nexport type JitsuInstance = { analytics: AnalyticsInterface };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext, { JitsuInstance } from \"./JitsuContext\";\nimport { emptyAnalytics, jitsuAnalytics } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n let instance: JitsuInstance;\n if (props.options.disabled) {\n instance = { analytics: emptyAnalytics };\n return <React.Fragment>{props.children}</React.Fragment>;\n } else if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n instance = { analytics: emptyAnalytics };\n } else {\n instance = { analytics: jitsuAnalytics(props.options) };\n }\n return <JitsuContext.Provider value={instance}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions, emptyAnalytics } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n throw new Error(`<JitsuProvider /> is not initialized with undefined analytics instance`);\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","instance","options","disabled","analytics","emptyAnalytics","React","children","host","msg","console","error","jitsuAnalytics","Provider","value","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAKA,IAAMA,YAAY,GAAGC,mBAAa,CAAuB,IAAI,CAAC;;ACC9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIC,QA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,UAAU,EAAE;IACzC,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;GAEF,MAAM,IAAIH,aAAa,CAACb,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,MAAM,IAAIgB,KAAK,0EAA0E;;AAE7F;;;;;;"}
@@ -1,44 +1,31 @@
1
1
  import { createContext, createElement, Fragment, useContext } from 'react';
2
- import { isInBrowser, jitsuAnalytics } from '@jitsu/js';
2
+ import { jitsuAnalytics, emptyAnalytics } from '@jitsu/js';
3
3
 
4
4
  var JitsuContext = createContext(null);
5
5
 
6
6
  var JitsuProvider = function JitsuProvider(props) {
7
+ var instance;
7
8
  if (props.options.disabled) {
9
+ instance = {
10
+ analytics: emptyAnalytics
11
+ };
8
12
  return createElement(Fragment, null, props.children);
9
- }
10
- if (!props.options.host) {
13
+ } else if (!props.options.host) {
11
14
  var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
12
15
  console.error("%c" + msg, "color: red; font-weight: bold;");
13
- console.error(msg);
14
- return createElement(Fragment, null, props.children);
16
+ instance = {
17
+ analytics: emptyAnalytics
18
+ };
19
+ } else {
20
+ instance = {
21
+ analytics: jitsuAnalytics(props.options)
22
+ };
15
23
  }
16
24
  return createElement(JitsuContext.Provider, {
17
- value: isInBrowser() ? {
18
- analytics: jitsuAnalytics(props.options)
19
- } : {
20
- initOptions: props.options
21
- }
25
+ value: instance
22
26
  }, props.children);
23
27
  };
24
28
 
25
- var emptyAnalytics = {
26
- track: function track() {
27
- return Promise.resolve();
28
- },
29
- page: function page() {
30
- return Promise.resolve();
31
- },
32
- user: function user() {
33
- return {};
34
- },
35
- identify: function identify() {
36
- return Promise.resolve({});
37
- },
38
- reset: function reset() {
39
- return Promise.resolve({});
40
- }
41
- };
42
29
  function useJitsu(opts) {
43
30
  var jitsuInstance = useContext(JitsuContext);
44
31
  if (opts !== null && opts !== void 0 && opts.disabled) {
@@ -53,7 +40,7 @@ function useJitsu(opts) {
53
40
  };
54
41
  } else {
55
42
  var msg = "Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react";
56
- console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
43
+ console.error("%c" + msg, "color: red; font-weight: bold;");
57
44
  return {
58
45
  analytics: emptyAnalytics
59
46
  };
@@ -65,10 +52,7 @@ function useJitsu(opts) {
65
52
  analytics: jitsuInstance.analytics
66
53
  };
67
54
  } else {
68
- var analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);
69
- return {
70
- analytics: analytics
71
- };
55
+ throw new Error("<JitsuProvider /> is not initialized with undefined analytics instance");
72
56
  }
73
57
  }
74
58
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\n/**\n * An instance if Jitsu that is kept in the context. It's one of:\n * - AnalyticsInterface - for CSR, if Jitsu is initialized in browser\n * - ExtendedJitsuOptions - for SSR, if provider can't access context\n */\nexport type JitsuInstance =\n | { analytics: AnalyticsInterface; initOptions?: never }\n | { analytics?: never; initOptions: ExtendedJitsuOptions };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics, isInBrowser } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n if (props.options.disabled) {\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n return (\n <JitsuContext.Provider\n value={isInBrowser() ? { analytics: jitsuAnalytics(props.options) } : { initOptions: props.options }}\n >\n {props.children}\n </JitsuContext.Provider>\n );\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\nconst emptyAnalytics = {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n //useJitsu() isn't wrapped into JitsuProvider. Return new instance of Jitsu provider if config is provided\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-size: 16px; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n const analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);\n return { analytics };\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","Provider","value","isInBrowser","analytics","jitsuAnalytics","initOptions","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAaA,IAAMA,YAAY,GAAGC,aAAa,CAAuB,IAAI,CAAC;;ACP9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIA,KAAK,CAACC,OAAO,CAACC,QAAQ,EAAE;IAC1B,OAAOC,cAACA,QAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAI,CAACJ,KAAK,CAACC,OAAO,CAACI,IAAI,EAAE;IACvB,IAAMC,GAAG,GAAG,6EAA6E;IACzFC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,gCAAgC,CAAC;IAC3DC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,OAAOH,cAACA,QAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,OACED,cAACN,YAAY,CAACY,QAAQ;IACpBC,KAAK,EAAEC,WAAW,EAAE,GAAG;MAAEC,SAAS,EAAEC,cAAc,CAACb,KAAK,CAACC,OAAO;KAAG,GAAG;MAAEa,WAAW,EAAEd,KAAK,CAACC;;KAE1FD,KAAK,CAACI,QAAQ,CACO;AAE5B,CAAC;;ACND,IAAMW,cAAc,GAAG;EACrBC,KAAK,EAAE;IAAA,OAAMC,OAAO,CAACC,OAAO,EAAE;;EAC9BC,IAAI,EAAE;IAAA,OAAMF,OAAO,CAACC,OAAO,EAAE;;EAC7BE,IAAI,EAAE;IAAA,OAAO,EAAE;GAAC;EAChBC,QAAQ,EAAE;IAAA,OAAMJ,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;;EACnCI,KAAK,EAAE;IAAA,OAAML,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;;CACjC;AAKD,SAASK,QAAQ,CAACC,IAA2B;EAC3C,IAAIC,aAAa,GAAGC,UAAU,CAAC7B,YAAY,CAAC;EAC5C,IAAI2B,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEtB,QAAQ,EAAE;IAClB,OAAO;MAAEU,SAAS,EAAEG;KAAgB;;EAGtC,IAAI,CAACU,aAAa,EAAE;IAClB,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEnB,IAAI,IAAImB,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,UAAU,EAAE;MAClC,OAAO;QAAEf,SAAS,EAAEC,cAAc,CAACW,IAAI;OAAG;KAC3C,MAAM;MACL,IAAMlB,GAAG,GACP,iJAAiJ;MACnJC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,iDAAiD,CAAC;MAC5E,OAAO;QAAEM,SAAS,EAAEG;OAAgB;;GAEvC,MAAM,IAAIS,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEnB,IAAI,IAAImB,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,UAAU,EAAE;IACzC,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;GAEF,MAAM,IAAIH,aAAa,CAACb,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,IAAMA,SAAS,GAAGa,aAAa,CAACX,WAAW,CAACZ,QAAQ,GAAGa,cAAc,GAAGF,cAAc,CAACY,aAAa,CAACX,WAAW,CAAC;IACjH,OAAO;MAAEF,SAAS,EAATA;KAAW;;AAExB;;;;"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nexport type JitsuInstance = { analytics: AnalyticsInterface };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext, { JitsuInstance } from \"./JitsuContext\";\nimport { emptyAnalytics, jitsuAnalytics } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n let instance: JitsuInstance;\n if (props.options.disabled) {\n instance = { analytics: emptyAnalytics };\n return <React.Fragment>{props.children}</React.Fragment>;\n } else if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n instance = { analytics: emptyAnalytics };\n } else {\n instance = { analytics: jitsuAnalytics(props.options) };\n }\n return <JitsuContext.Provider value={instance}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions, emptyAnalytics } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n throw new Error(`<JitsuProvider /> is not initialized with undefined analytics instance`);\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","instance","options","disabled","analytics","emptyAnalytics","React","children","host","msg","console","error","jitsuAnalytics","Provider","value","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAKA,IAAMA,YAAY,GAAGC,aAAa,CAAuB,IAAI,CAAC;;ACC9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIC,QAAuB;EAC3B,IAAID,KAAK,CAACE,OAAO,CAACC,QAAQ,EAAE;IAC1BF,QAAQ,GAAG;MAAEG,SAAS,EAAEC;KAAgB;IACxC,OAAOC,cAACA,QAAc,QAAEN,KAAK,CAACO,QAAQ,CAAkB;GACzD,MAAM,IAAI,CAACP,KAAK,CAACE,OAAO,CAACM,IAAI,EAAE;IAC9B,IAAMC,GAAG,GAAG,6EAA6E;IACzFC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,gCAAgC,CAAC;IAC3DR,QAAQ,GAAG;MAAEG,SAAS,EAAEC;KAAgB;GACzC,MAAM;IACLJ,QAAQ,GAAG;MAAEG,SAAS,EAAEQ,cAAc,CAACZ,KAAK,CAACE,OAAO;KAAG;;EAEzD,OAAOI,cAACT,YAAY,CAACgB,QAAQ;IAACC,KAAK,EAAEb;KAAWD,KAAK,CAACO,QAAQ,CAAyB;AACzF,CAAC;;ACCD,SAASQ,QAAQ,CAACC,IAA2B;EAC3C,IAAIC,aAAa,GAAGC,UAAU,CAACrB,YAAY,CAAC;EAC5C,IAAImB,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEb,QAAQ,EAAE;IAClB,OAAO;MAAEC,SAAS,EAAEC;KAAgB;;EAEtC,IAAI,CAACY,aAAa,EAAE;IAClB,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAER,IAAI,IAAIQ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,UAAU,EAAE;MAClC,OAAO;QAAEf,SAAS,EAAEQ,cAAc,CAACI,IAAI;OAAG;KAC3C,MAAM;MACL,IAAMP,GAAG,GACP,iJAAiJ;MACnJC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,gCAAgC,CAAC;MAC3D,OAAO;QAAEL,SAAS,EAAEC;OAAgB;;GAEvC,MAAM,IAAIW,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAER,IAAI,IAAIQ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,UAAU,EAAE;IACzC,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;GAEF,MAAM,IAAIH,aAAa,CAACb,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,MAAM,IAAIgB,KAAK,0EAA0E;;AAE7F;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/jitsu-react",
3
- "version": "1.1.0-canary.206.20230220023641",
3
+ "version": "1.1.0-canary.211.20230220172137",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "node": ">=10"
12
12
  },
13
13
  "dependencies": {
14
- "@jitsu/js": "0.0.0"
14
+ "@jitsu/js": "1.1.0-canary.211.20230220172137"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "15.x || 16.x || 17.x || 18.x",
@@ -36,7 +36,7 @@
36
36
  "@types/node": "^18.11.9",
37
37
  "microbundle-crl": "^0.13.11",
38
38
  "typescript": "^4.9.3",
39
- "@jitsu/js": "0.0.0"
39
+ "@jitsu/js": "1.1.0-canary.211.20230220172137"
40
40
  },
41
41
  "files": [
42
42
  "dist"