@kontextso/sdk-react-native 0.0.5-rc.5 → 0.0.5-rc.6

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/index.js CHANGED
@@ -39,14 +39,14 @@ __export(src_exports, {
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
41
  // src/formats/InlineAd.tsx
42
- var import_react11 = require("react");
42
+ var import_react12 = require("react");
43
43
  var import_react_native5 = require("react-native");
44
44
 
45
45
  // src/hooks/useAdViewed.tsx
46
- var import_react5 = require("react");
46
+ var import_react6 = require("react");
47
47
 
48
48
  // src/context/AdsProvider.tsx
49
- var import_react4 = __toESM(require("react"));
49
+ var import_react5 = __toESM(require("react"));
50
50
 
51
51
  // src/hooks/useInitializeAds.tsx
52
52
  var import_react = require("react");
@@ -201,7 +201,7 @@ var parseMessageText = (text) => {
201
201
  var import_loglevel = __toESM(require("loglevel"));
202
202
 
203
203
  // package.json
204
- var version = "0.0.5-rc.4";
204
+ var version = "0.0.5-rc.6";
205
205
 
206
206
  // src/hooks/useInitializeAds.tsx
207
207
  async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
@@ -747,8 +747,52 @@ function useStreamAds({
747
747
 
748
748
  // src/context/AdsProvider.tsx
749
749
  var import_loglevel4 = __toESM(require("loglevel"));
750
+
751
+ // src/components/ErrorBoundary.tsx
752
+ var import_react4 = __toESM(require("react"));
753
+ var captureErrorFn = (adServerUrl, error, componentStack, context) => {
754
+ fetch(`${adServerUrl}/error`, {
755
+ method: "POST",
756
+ body: JSON.stringify({
757
+ error: error.message,
758
+ stack: componentStack,
759
+ context
760
+ })
761
+ }).catch((e) => {
762
+ console.error(e);
763
+ }).finally(() => {
764
+ console.error(error, componentStack);
765
+ });
766
+ };
767
+ var ErrorBoundary = class extends import_react4.default.Component {
768
+ constructor(props) {
769
+ super(props);
770
+ this.state = {
771
+ hasError: false
772
+ };
773
+ }
774
+ static getDerivedStateFromError() {
775
+ return {
776
+ hasError: true
777
+ };
778
+ }
779
+ componentDidCatch(error, info) {
780
+ const adServerUrl = this.props.adserverUrl;
781
+ if (adServerUrl) {
782
+ captureErrorFn(adServerUrl, error, info.componentStack, this.props.reqBodyParams);
783
+ }
784
+ }
785
+ render() {
786
+ if (this.state.hasError) {
787
+ return this.props.fallback || null;
788
+ }
789
+ return this.props.children;
790
+ }
791
+ };
792
+
793
+ // src/context/AdsProvider.tsx
750
794
  var import_jsx_runtime = require("react/jsx-runtime");
751
- var AdsContext = import_react4.default.createContext(null);
795
+ var AdsContext = import_react5.default.createContext(null);
752
796
  AdsContext.displayName = "AdsContext";
753
797
  var VISITOR_ID_KEY = "brain-visitor-id";
754
798
  var AdsProviderWithoutBoundary = ({
@@ -766,7 +810,7 @@ var AdsProviderWithoutBoundary = ({
766
810
  onAdClick,
767
811
  ...props
768
812
  }) => {
769
- const [viewedAds, setViewedAds] = (0, import_react4.useState)([]);
813
+ const [viewedAds, setViewedAds] = (0, import_react5.useState)([]);
770
814
  const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
771
815
  import_loglevel4.default.setLevel(logLevel || "ERROR");
772
816
  const {
@@ -876,47 +920,49 @@ var AdsProvider = ({
876
920
  onAdClick,
877
921
  ...props
878
922
  }) => {
879
- return (
880
- // <ErrorBoundary
881
- // fallback={children}
882
- // adserverUrl={adserverUrl}
883
- // reqBodyParams={{
884
- // publisherToken,
885
- // adserverUrl,
886
- // conversationId,
887
- // character,
888
- // userId,
889
- // isLoading,
890
- // messages
891
- // }}
892
- // >
893
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
894
- AdsProviderWithoutBoundary,
895
- {
896
- children,
897
- messages,
923
+ const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
924
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
925
+ ErrorBoundary,
926
+ {
927
+ fallback: children,
928
+ adserverUrl: adServerUrlOrDefault,
929
+ reqBodyParams: {
898
930
  publisherToken,
899
- isLoading,
900
931
  adserverUrl,
901
- isDisabled,
902
- character,
903
932
  conversationId,
933
+ character,
904
934
  userId,
905
- logLevel,
906
- onAdView,
907
- onAdClick,
908
- throwError: props.throwError
909
- }
910
- )
935
+ isLoading,
936
+ messages
937
+ },
938
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
939
+ AdsProviderWithoutBoundary,
940
+ {
941
+ children,
942
+ messages,
943
+ publisherToken,
944
+ isLoading,
945
+ adserverUrl,
946
+ isDisabled,
947
+ character,
948
+ conversationId,
949
+ userId,
950
+ logLevel,
951
+ onAdView,
952
+ onAdClick,
953
+ throwError: props.throwError
954
+ }
955
+ )
956
+ }
911
957
  );
912
958
  };
913
959
 
914
960
  // src/hooks/useAdViewed.tsx
915
- var import_react6 = require("react");
961
+ var import_react7 = require("react");
916
962
  var import_loglevel5 = __toESM(require("loglevel"));
917
963
  function useAdViewed(ad) {
918
- const context = (0, import_react6.useContext)(AdsContext);
919
- const [stillMounted, setStillMounted] = (0, import_react5.useState)(false);
964
+ const context = (0, import_react7.useContext)(AdsContext);
965
+ const [stillMounted, setStillMounted] = (0, import_react6.useState)(false);
920
966
  const sendRequest = async () => {
921
967
  if (!context?.adserverUrl || !ad?.id) {
922
968
  return;
@@ -938,7 +984,7 @@ function useAdViewed(ad) {
938
984
  import_loglevel5.default.error("[BRAIN] Error sending view request", e);
939
985
  }
940
986
  };
941
- (0, import_react5.useEffect)(() => {
987
+ (0, import_react6.useEffect)(() => {
942
988
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
943
989
  return;
944
990
  }
@@ -948,7 +994,7 @@ function useAdViewed(ad) {
948
994
  setStillMounted(true);
949
995
  }, 1e3);
950
996
  }, [ad]);
951
- (0, import_react5.useEffect)(() => {
997
+ (0, import_react6.useEffect)(() => {
952
998
  if (stillMounted) {
953
999
  import_loglevel5.default.log("[BRAIN] sending request");
954
1000
  sendRequest();
@@ -961,14 +1007,14 @@ var import_loglevel8 = __toESM(require("loglevel"));
961
1007
 
962
1008
  // src/components/MarkdownText.tsx
963
1009
  var import_loglevel6 = __toESM(require("loglevel"));
964
- var import_react7 = require("react");
1010
+ var import_react8 = require("react");
965
1011
  var import_react_native2 = require("react-native");
966
1012
  var import_jsx_runtime2 = require("react/jsx-runtime");
967
1013
  function MarkdownText({
968
1014
  content,
969
1015
  onLinkClick
970
1016
  }) {
971
- const context = (0, import_react7.useContext)(AdsContext);
1017
+ const context = (0, import_react8.useContext)(AdsContext);
972
1018
  const textParts = parseMessageText(content);
973
1019
  const styles = context?.styles?.markdownText;
974
1020
  const linkClickHandler = (href) => {
@@ -1002,17 +1048,17 @@ function MarkdownText({
1002
1048
  // src/components/VideoPlayer.tsx
1003
1049
  var import_expo_av = require("expo-av");
1004
1050
  var import_loglevel7 = __toESM(require("loglevel"));
1005
- var import_react9 = require("react");
1051
+ var import_react10 = require("react");
1006
1052
  var import_react_native4 = require("react-native");
1007
1053
 
1008
1054
  // src/components/VideoProgressBar.tsx
1009
- var import_react8 = require("react");
1055
+ var import_react9 = require("react");
1010
1056
  var import_react_native3 = require("react-native");
1011
1057
  var import_jsx_runtime3 = require("react/jsx-runtime");
1012
1058
  function VideoProgressBar({ videoRef }) {
1013
- const [progress, setProgress] = (0, import_react8.useState)(0);
1014
- const styles = (0, import_react8.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1015
- (0, import_react8.useEffect)(() => {
1059
+ const [progress, setProgress] = (0, import_react9.useState)(0);
1060
+ const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1061
+ (0, import_react9.useEffect)(() => {
1016
1062
  const interval = setInterval(() => {
1017
1063
  if (!videoRef.current) {
1018
1064
  return;
@@ -1045,14 +1091,14 @@ var VideoPlayer = ({
1045
1091
  mediaPlacement,
1046
1092
  onLinkClick
1047
1093
  }) => {
1048
- const videoRef = (0, import_react9.useRef)(null);
1049
- const [isPlaying, setIsPlaying] = (0, import_react9.useState)(false);
1050
- const [isPaused, setIsPaused] = (0, import_react9.useState)(true);
1051
- const [isEnded, setIsEnded] = (0, import_react9.useState)(false);
1052
- const [showDownloadBadge, setShowDownloadBadge] = (0, import_react9.useState)(false);
1053
- const lastCallbackTimeRef = (0, import_react9.useRef)(0);
1054
- const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer;
1055
- (0, import_react9.useEffect)(() => {
1094
+ const videoRef = (0, import_react10.useRef)(null);
1095
+ const [isPlaying, setIsPlaying] = (0, import_react10.useState)(false);
1096
+ const [isPaused, setIsPaused] = (0, import_react10.useState)(true);
1097
+ const [isEnded, setIsEnded] = (0, import_react10.useState)(false);
1098
+ const [showDownloadBadge, setShowDownloadBadge] = (0, import_react10.useState)(false);
1099
+ const lastCallbackTimeRef = (0, import_react10.useRef)(0);
1100
+ const styles = (0, import_react10.useContext)(AdsContext)?.styles?.videoPlayer;
1101
+ (0, import_react10.useEffect)(() => {
1056
1102
  const interval = setInterval(() => {
1057
1103
  if (videoRef.current) {
1058
1104
  videoRef.current.getStatusAsync().then((status) => {
@@ -1135,9 +1181,9 @@ var VideoPlayer = ({
1135
1181
  };
1136
1182
 
1137
1183
  // src/hooks/useAd.tsx
1138
- var import_react10 = require("react");
1184
+ var import_react11 = require("react");
1139
1185
  function useAd({ code, messageId }) {
1140
- const context = (0, import_react10.useContext)(AdsContext);
1186
+ const context = (0, import_react11.useContext)(AdsContext);
1141
1187
  if (!context) {
1142
1188
  return null;
1143
1189
  }
@@ -1185,11 +1231,11 @@ function useAd({ code, messageId }) {
1185
1231
  var import_jsx_runtime5 = require("react/jsx-runtime");
1186
1232
  var InlineAd = ({ code, messageId, wrapper }) => {
1187
1233
  const ad = useAd({ code, messageId });
1188
- const [linkIncluded, setLinkIncluded] = (0, import_react11.useState)(false);
1189
- const context = (0, import_react11.useContext)(AdsContext);
1234
+ const [linkIncluded, setLinkIncluded] = (0, import_react12.useState)(false);
1235
+ const context = (0, import_react12.useContext)(AdsContext);
1190
1236
  const styles = context?.styles?.inlineAd;
1191
1237
  useAdViewed(ad);
1192
- (0, import_react11.useEffect)(() => {
1238
+ (0, import_react12.useEffect)(() => {
1193
1239
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1194
1240
  setLinkIncluded(true);
1195
1241
  }
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  import { useEffect as useEffect5, useState as useState5 } from "react";
21
21
 
22
22
  // src/context/AdsProvider.tsx
23
- import React, { useState as useState4 } from "react";
23
+ import React2, { useState as useState4 } from "react";
24
24
 
25
25
  // src/hooks/useInitializeAds.tsx
26
26
  import { useEffect, useState } from "react";
@@ -175,7 +175,7 @@ var parseMessageText = (text) => {
175
175
  import log from "loglevel";
176
176
 
177
177
  // package.json
178
- var version = "0.0.5-rc.4";
178
+ var version = "0.0.5-rc.6";
179
179
 
180
180
  // src/hooks/useInitializeAds.tsx
181
181
  async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
@@ -721,8 +721,52 @@ function useStreamAds({
721
721
 
722
722
  // src/context/AdsProvider.tsx
723
723
  import log4 from "loglevel";
724
+
725
+ // src/components/ErrorBoundary.tsx
726
+ import React from "react";
727
+ var captureErrorFn = (adServerUrl, error, componentStack, context) => {
728
+ fetch(`${adServerUrl}/error`, {
729
+ method: "POST",
730
+ body: JSON.stringify({
731
+ error: error.message,
732
+ stack: componentStack,
733
+ context
734
+ })
735
+ }).catch((e) => {
736
+ console.error(e);
737
+ }).finally(() => {
738
+ console.error(error, componentStack);
739
+ });
740
+ };
741
+ var ErrorBoundary = class extends React.Component {
742
+ constructor(props) {
743
+ super(props);
744
+ this.state = {
745
+ hasError: false
746
+ };
747
+ }
748
+ static getDerivedStateFromError() {
749
+ return {
750
+ hasError: true
751
+ };
752
+ }
753
+ componentDidCatch(error, info) {
754
+ const adServerUrl = this.props.adserverUrl;
755
+ if (adServerUrl) {
756
+ captureErrorFn(adServerUrl, error, info.componentStack, this.props.reqBodyParams);
757
+ }
758
+ }
759
+ render() {
760
+ if (this.state.hasError) {
761
+ return this.props.fallback || null;
762
+ }
763
+ return this.props.children;
764
+ }
765
+ };
766
+
767
+ // src/context/AdsProvider.tsx
724
768
  import { jsx } from "react/jsx-runtime";
725
- var AdsContext = React.createContext(null);
769
+ var AdsContext = React2.createContext(null);
726
770
  AdsContext.displayName = "AdsContext";
727
771
  var VISITOR_ID_KEY = "brain-visitor-id";
728
772
  var AdsProviderWithoutBoundary = ({
@@ -850,38 +894,40 @@ var AdsProvider = ({
850
894
  onAdClick,
851
895
  ...props
852
896
  }) => {
853
- return (
854
- // <ErrorBoundary
855
- // fallback={children}
856
- // adserverUrl={adserverUrl}
857
- // reqBodyParams={{
858
- // publisherToken,
859
- // adserverUrl,
860
- // conversationId,
861
- // character,
862
- // userId,
863
- // isLoading,
864
- // messages
865
- // }}
866
- // >
867
- /* @__PURE__ */ jsx(
868
- AdsProviderWithoutBoundary,
869
- {
870
- children,
871
- messages,
897
+ const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
898
+ return /* @__PURE__ */ jsx(
899
+ ErrorBoundary,
900
+ {
901
+ fallback: children,
902
+ adserverUrl: adServerUrlOrDefault,
903
+ reqBodyParams: {
872
904
  publisherToken,
873
- isLoading,
874
905
  adserverUrl,
875
- isDisabled,
876
- character,
877
906
  conversationId,
907
+ character,
878
908
  userId,
879
- logLevel,
880
- onAdView,
881
- onAdClick,
882
- throwError: props.throwError
883
- }
884
- )
909
+ isLoading,
910
+ messages
911
+ },
912
+ children: /* @__PURE__ */ jsx(
913
+ AdsProviderWithoutBoundary,
914
+ {
915
+ children,
916
+ messages,
917
+ publisherToken,
918
+ isLoading,
919
+ adserverUrl,
920
+ isDisabled,
921
+ character,
922
+ conversationId,
923
+ userId,
924
+ logLevel,
925
+ onAdView,
926
+ onAdClick,
927
+ throwError: props.throwError
928
+ }
929
+ )
930
+ }
885
931
  );
886
932
  };
887
933
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "0.0.5-rc.5",
3
+ "version": "0.0.5-rc.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",