@kontextso/sdk-react-native 0.0.5-rc.6 → 0.0.5-rc.8
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 +34 -29
- package/dist/index.mjs +34 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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.
|
|
204
|
+
var version = "0.0.5-rc.7";
|
|
205
205
|
|
|
206
206
|
// src/hooks/useInitializeAds.tsx
|
|
207
207
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
@@ -301,7 +301,7 @@ function useInitializeAds({
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
).catch((e) => {
|
|
304
|
-
import_loglevel.default.
|
|
304
|
+
import_loglevel.default.warn("[BRAIN] Error initializing ads", e);
|
|
305
305
|
setError(e.message);
|
|
306
306
|
});
|
|
307
307
|
} else {
|
|
@@ -382,8 +382,7 @@ function usePreloadAds({
|
|
|
382
382
|
setPreloadDone(true);
|
|
383
383
|
import_loglevel2.default.log("[BRAIN] preload ads finished");
|
|
384
384
|
} catch (e) {
|
|
385
|
-
import_loglevel2.default.
|
|
386
|
-
setPreloadDone(true);
|
|
385
|
+
import_loglevel2.default.warn("[BRAIN] Error preloading ads", e);
|
|
387
386
|
}
|
|
388
387
|
}
|
|
389
388
|
preload();
|
|
@@ -624,7 +623,11 @@ if (import_react_native.Platform.OS !== "web") {
|
|
|
624
623
|
patchFetch = require("react-native-fetch-api").fetch;
|
|
625
624
|
}
|
|
626
625
|
ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
627
|
-
|
|
626
|
+
if (!isFatal) {
|
|
627
|
+
import_loglevel3.default.warn(error);
|
|
628
|
+
} else {
|
|
629
|
+
import_loglevel3.default.error(error);
|
|
630
|
+
}
|
|
628
631
|
});
|
|
629
632
|
function useStreamAds({
|
|
630
633
|
userId,
|
|
@@ -729,7 +732,7 @@ function useStreamAds({
|
|
|
729
732
|
);
|
|
730
733
|
import_loglevel3.default.log(`[BRAIN] streaming ${code} ad done`);
|
|
731
734
|
} catch (e) {
|
|
732
|
-
import_loglevel3.default.
|
|
735
|
+
import_loglevel3.default.warn("[BRAIN] Error streaming ad", e);
|
|
733
736
|
setAds((oldAds) => [...oldAds, { isError: true, code }]);
|
|
734
737
|
}
|
|
735
738
|
};
|
|
@@ -746,22 +749,21 @@ function useStreamAds({
|
|
|
746
749
|
}
|
|
747
750
|
|
|
748
751
|
// src/context/AdsProvider.tsx
|
|
749
|
-
var
|
|
752
|
+
var import_loglevel5 = __toESM(require("loglevel"));
|
|
750
753
|
|
|
751
754
|
// src/components/ErrorBoundary.tsx
|
|
752
755
|
var import_react4 = __toESM(require("react"));
|
|
756
|
+
var import_loglevel4 = __toESM(require("loglevel"));
|
|
753
757
|
var captureErrorFn = (adServerUrl, error, componentStack, context) => {
|
|
754
758
|
fetch(`${adServerUrl}/error`, {
|
|
755
759
|
method: "POST",
|
|
756
760
|
body: JSON.stringify({
|
|
757
|
-
error: error
|
|
761
|
+
error: error?.message,
|
|
758
762
|
stack: componentStack,
|
|
759
763
|
context
|
|
760
764
|
})
|
|
761
765
|
}).catch((e) => {
|
|
762
|
-
|
|
763
|
-
}).finally(() => {
|
|
764
|
-
console.error(error, componentStack);
|
|
766
|
+
import_loglevel4.default.warn("Error reporting client error", e);
|
|
765
767
|
});
|
|
766
768
|
};
|
|
767
769
|
var ErrorBoundary = class extends import_react4.default.Component {
|
|
@@ -779,7 +781,7 @@ var ErrorBoundary = class extends import_react4.default.Component {
|
|
|
779
781
|
componentDidCatch(error, info) {
|
|
780
782
|
const adServerUrl = this.props.adserverUrl;
|
|
781
783
|
if (adServerUrl) {
|
|
782
|
-
captureErrorFn(adServerUrl, error, info
|
|
784
|
+
captureErrorFn(adServerUrl, error, info?.componentStack, this.props.reqBodyParams);
|
|
783
785
|
}
|
|
784
786
|
}
|
|
785
787
|
render() {
|
|
@@ -812,7 +814,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
812
814
|
}) => {
|
|
813
815
|
const [viewedAds, setViewedAds] = (0, import_react5.useState)([]);
|
|
814
816
|
const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
|
|
815
|
-
|
|
817
|
+
import_loglevel5.default.setLevel(logLevel || "ERROR");
|
|
816
818
|
const {
|
|
817
819
|
ads: initAds,
|
|
818
820
|
sessionId,
|
|
@@ -856,11 +858,14 @@ var AdsProviderWithoutBoundary = ({
|
|
|
856
858
|
publisherToken
|
|
857
859
|
});
|
|
858
860
|
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds });
|
|
859
|
-
if (props.throwError && Math.random() < 0.
|
|
861
|
+
if (props.throwError && Math.random() < 0.1) {
|
|
860
862
|
throw new Error("Test error");
|
|
861
863
|
}
|
|
864
|
+
if (props.throwError && Math.random() < 0.1) {
|
|
865
|
+
Promise.reject(new Error("Test async error"));
|
|
866
|
+
}
|
|
862
867
|
const markAdAsViewed = (ad) => {
|
|
863
|
-
|
|
868
|
+
import_loglevel5.default.debug("[Brain] Calling onAdView");
|
|
864
869
|
onAdView && onAdView({
|
|
865
870
|
id: ad.id,
|
|
866
871
|
code: ad.code,
|
|
@@ -872,7 +877,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
872
877
|
setViewedAds((old) => [...old, ad.id]);
|
|
873
878
|
};
|
|
874
879
|
const onAdClickInternal = (ad) => {
|
|
875
|
-
|
|
880
|
+
import_loglevel5.default.debug("[Brain] Calling onAdClick");
|
|
876
881
|
onAdClick && onAdClick({
|
|
877
882
|
id: ad.id,
|
|
878
883
|
code: ad.code,
|
|
@@ -959,7 +964,7 @@ var AdsProvider = ({
|
|
|
959
964
|
|
|
960
965
|
// src/hooks/useAdViewed.tsx
|
|
961
966
|
var import_react7 = require("react");
|
|
962
|
-
var
|
|
967
|
+
var import_loglevel6 = __toESM(require("loglevel"));
|
|
963
968
|
function useAdViewed(ad) {
|
|
964
969
|
const context = (0, import_react7.useContext)(AdsContext);
|
|
965
970
|
const [stillMounted, setStillMounted] = (0, import_react6.useState)(false);
|
|
@@ -979,34 +984,34 @@ function useAdViewed(ad) {
|
|
|
979
984
|
if (!response.ok) {
|
|
980
985
|
throw new Error("Error sending view request");
|
|
981
986
|
}
|
|
982
|
-
|
|
987
|
+
import_loglevel6.default.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
|
|
983
988
|
} catch (e) {
|
|
984
|
-
|
|
989
|
+
import_loglevel6.default.warn("[BRAIN] Error sending view request", e);
|
|
985
990
|
}
|
|
986
991
|
};
|
|
987
992
|
(0, import_react6.useEffect)(() => {
|
|
988
993
|
if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
|
|
989
994
|
return;
|
|
990
995
|
}
|
|
991
|
-
|
|
996
|
+
import_loglevel6.default.log("[BRAIN] setting timeout", ad.id, ad.code);
|
|
992
997
|
setTimeout(() => {
|
|
993
|
-
|
|
998
|
+
import_loglevel6.default.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
|
|
994
999
|
setStillMounted(true);
|
|
995
1000
|
}, 1e3);
|
|
996
1001
|
}, [ad]);
|
|
997
1002
|
(0, import_react6.useEffect)(() => {
|
|
998
1003
|
if (stillMounted) {
|
|
999
|
-
|
|
1004
|
+
import_loglevel6.default.log("[BRAIN] sending request");
|
|
1000
1005
|
sendRequest();
|
|
1001
1006
|
}
|
|
1002
1007
|
}, [stillMounted]);
|
|
1003
1008
|
}
|
|
1004
1009
|
|
|
1005
1010
|
// src/formats/InlineAd.tsx
|
|
1006
|
-
var
|
|
1011
|
+
var import_loglevel9 = __toESM(require("loglevel"));
|
|
1007
1012
|
|
|
1008
1013
|
// src/components/MarkdownText.tsx
|
|
1009
|
-
var
|
|
1014
|
+
var import_loglevel7 = __toESM(require("loglevel"));
|
|
1010
1015
|
var import_react8 = require("react");
|
|
1011
1016
|
var import_react_native2 = require("react-native");
|
|
1012
1017
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -1020,7 +1025,7 @@ function MarkdownText({
|
|
|
1020
1025
|
const linkClickHandler = (href) => {
|
|
1021
1026
|
onLinkClick();
|
|
1022
1027
|
import_react_native2.Linking.openURL(href).catch(
|
|
1023
|
-
(err) =>
|
|
1028
|
+
(err) => import_loglevel7.default.warn("Failed to open URL:", err)
|
|
1024
1029
|
);
|
|
1025
1030
|
return false;
|
|
1026
1031
|
};
|
|
@@ -1047,7 +1052,7 @@ function MarkdownText({
|
|
|
1047
1052
|
|
|
1048
1053
|
// src/components/VideoPlayer.tsx
|
|
1049
1054
|
var import_expo_av = require("expo-av");
|
|
1050
|
-
var
|
|
1055
|
+
var import_loglevel8 = __toESM(require("loglevel"));
|
|
1051
1056
|
var import_react10 = require("react");
|
|
1052
1057
|
var import_react_native4 = require("react-native");
|
|
1053
1058
|
|
|
@@ -1142,7 +1147,7 @@ var VideoPlayer = ({
|
|
|
1142
1147
|
};
|
|
1143
1148
|
const handleLinkClick = (url) => {
|
|
1144
1149
|
if (url) {
|
|
1145
|
-
import_react_native4.Linking.openURL(url).catch((err) =>
|
|
1150
|
+
import_react_native4.Linking.openURL(url).catch((err) => import_loglevel8.default.warn("Failed to open URL:", err));
|
|
1146
1151
|
onLinkClick();
|
|
1147
1152
|
}
|
|
1148
1153
|
};
|
|
@@ -1244,7 +1249,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1244
1249
|
if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
|
|
1245
1250
|
return null;
|
|
1246
1251
|
const onProgress = (progress) => {
|
|
1247
|
-
|
|
1252
|
+
import_loglevel9.default.log(`Progress: ${progress}`);
|
|
1248
1253
|
};
|
|
1249
1254
|
const handleImageClick = (url) => {
|
|
1250
1255
|
if (url) {
|
|
@@ -1253,7 +1258,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1253
1258
|
window.open(url, "_blank");
|
|
1254
1259
|
} else {
|
|
1255
1260
|
import_react_native5.Linking.openURL(url).catch(
|
|
1256
|
-
(err) =>
|
|
1261
|
+
(err) => import_loglevel9.default.warn("Failed to open URL:", err)
|
|
1257
1262
|
);
|
|
1258
1263
|
}
|
|
1259
1264
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -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.
|
|
178
|
+
var version = "0.0.5-rc.7";
|
|
179
179
|
|
|
180
180
|
// src/hooks/useInitializeAds.tsx
|
|
181
181
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
@@ -275,7 +275,7 @@ function useInitializeAds({
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
).catch((e) => {
|
|
278
|
-
log.
|
|
278
|
+
log.warn("[BRAIN] Error initializing ads", e);
|
|
279
279
|
setError(e.message);
|
|
280
280
|
});
|
|
281
281
|
} else {
|
|
@@ -356,8 +356,7 @@ function usePreloadAds({
|
|
|
356
356
|
setPreloadDone(true);
|
|
357
357
|
log2.log("[BRAIN] preload ads finished");
|
|
358
358
|
} catch (e) {
|
|
359
|
-
log2.
|
|
360
|
-
setPreloadDone(true);
|
|
359
|
+
log2.warn("[BRAIN] Error preloading ads", e);
|
|
361
360
|
}
|
|
362
361
|
}
|
|
363
362
|
preload();
|
|
@@ -598,7 +597,11 @@ if (Platform.OS !== "web") {
|
|
|
598
597
|
patchFetch = __require("react-native-fetch-api").fetch;
|
|
599
598
|
}
|
|
600
599
|
ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
601
|
-
|
|
600
|
+
if (!isFatal) {
|
|
601
|
+
log3.warn(error);
|
|
602
|
+
} else {
|
|
603
|
+
log3.error(error);
|
|
604
|
+
}
|
|
602
605
|
});
|
|
603
606
|
function useStreamAds({
|
|
604
607
|
userId,
|
|
@@ -703,7 +706,7 @@ function useStreamAds({
|
|
|
703
706
|
);
|
|
704
707
|
log3.log(`[BRAIN] streaming ${code} ad done`);
|
|
705
708
|
} catch (e) {
|
|
706
|
-
log3.
|
|
709
|
+
log3.warn("[BRAIN] Error streaming ad", e);
|
|
707
710
|
setAds((oldAds) => [...oldAds, { isError: true, code }]);
|
|
708
711
|
}
|
|
709
712
|
};
|
|
@@ -720,22 +723,21 @@ function useStreamAds({
|
|
|
720
723
|
}
|
|
721
724
|
|
|
722
725
|
// src/context/AdsProvider.tsx
|
|
723
|
-
import
|
|
726
|
+
import log5 from "loglevel";
|
|
724
727
|
|
|
725
728
|
// src/components/ErrorBoundary.tsx
|
|
726
729
|
import React from "react";
|
|
730
|
+
import log4 from "loglevel";
|
|
727
731
|
var captureErrorFn = (adServerUrl, error, componentStack, context) => {
|
|
728
732
|
fetch(`${adServerUrl}/error`, {
|
|
729
733
|
method: "POST",
|
|
730
734
|
body: JSON.stringify({
|
|
731
|
-
error: error
|
|
735
|
+
error: error?.message,
|
|
732
736
|
stack: componentStack,
|
|
733
737
|
context
|
|
734
738
|
})
|
|
735
739
|
}).catch((e) => {
|
|
736
|
-
|
|
737
|
-
}).finally(() => {
|
|
738
|
-
console.error(error, componentStack);
|
|
740
|
+
log4.warn("Error reporting client error", e);
|
|
739
741
|
});
|
|
740
742
|
};
|
|
741
743
|
var ErrorBoundary = class extends React.Component {
|
|
@@ -753,7 +755,7 @@ var ErrorBoundary = class extends React.Component {
|
|
|
753
755
|
componentDidCatch(error, info) {
|
|
754
756
|
const adServerUrl = this.props.adserverUrl;
|
|
755
757
|
if (adServerUrl) {
|
|
756
|
-
captureErrorFn(adServerUrl, error, info
|
|
758
|
+
captureErrorFn(adServerUrl, error, info?.componentStack, this.props.reqBodyParams);
|
|
757
759
|
}
|
|
758
760
|
}
|
|
759
761
|
render() {
|
|
@@ -786,7 +788,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
786
788
|
}) => {
|
|
787
789
|
const [viewedAds, setViewedAds] = useState4([]);
|
|
788
790
|
const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
|
|
789
|
-
|
|
791
|
+
log5.setLevel(logLevel || "ERROR");
|
|
790
792
|
const {
|
|
791
793
|
ads: initAds,
|
|
792
794
|
sessionId,
|
|
@@ -830,11 +832,14 @@ var AdsProviderWithoutBoundary = ({
|
|
|
830
832
|
publisherToken
|
|
831
833
|
});
|
|
832
834
|
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds });
|
|
833
|
-
if (props.throwError && Math.random() < 0.
|
|
835
|
+
if (props.throwError && Math.random() < 0.1) {
|
|
834
836
|
throw new Error("Test error");
|
|
835
837
|
}
|
|
838
|
+
if (props.throwError && Math.random() < 0.1) {
|
|
839
|
+
Promise.reject(new Error("Test async error"));
|
|
840
|
+
}
|
|
836
841
|
const markAdAsViewed = (ad) => {
|
|
837
|
-
|
|
842
|
+
log5.debug("[Brain] Calling onAdView");
|
|
838
843
|
onAdView && onAdView({
|
|
839
844
|
id: ad.id,
|
|
840
845
|
code: ad.code,
|
|
@@ -846,7 +851,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
846
851
|
setViewedAds((old) => [...old, ad.id]);
|
|
847
852
|
};
|
|
848
853
|
const onAdClickInternal = (ad) => {
|
|
849
|
-
|
|
854
|
+
log5.debug("[Brain] Calling onAdClick");
|
|
850
855
|
onAdClick && onAdClick({
|
|
851
856
|
id: ad.id,
|
|
852
857
|
code: ad.code,
|
|
@@ -933,7 +938,7 @@ var AdsProvider = ({
|
|
|
933
938
|
|
|
934
939
|
// src/hooks/useAdViewed.tsx
|
|
935
940
|
import { useContext } from "react";
|
|
936
|
-
import
|
|
941
|
+
import log6 from "loglevel";
|
|
937
942
|
function useAdViewed(ad) {
|
|
938
943
|
const context = useContext(AdsContext);
|
|
939
944
|
const [stillMounted, setStillMounted] = useState5(false);
|
|
@@ -953,34 +958,34 @@ function useAdViewed(ad) {
|
|
|
953
958
|
if (!response.ok) {
|
|
954
959
|
throw new Error("Error sending view request");
|
|
955
960
|
}
|
|
956
|
-
|
|
961
|
+
log6.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
|
|
957
962
|
} catch (e) {
|
|
958
|
-
|
|
963
|
+
log6.warn("[BRAIN] Error sending view request", e);
|
|
959
964
|
}
|
|
960
965
|
};
|
|
961
966
|
useEffect5(() => {
|
|
962
967
|
if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
|
|
963
968
|
return;
|
|
964
969
|
}
|
|
965
|
-
|
|
970
|
+
log6.log("[BRAIN] setting timeout", ad.id, ad.code);
|
|
966
971
|
setTimeout(() => {
|
|
967
|
-
|
|
972
|
+
log6.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
|
|
968
973
|
setStillMounted(true);
|
|
969
974
|
}, 1e3);
|
|
970
975
|
}, [ad]);
|
|
971
976
|
useEffect5(() => {
|
|
972
977
|
if (stillMounted) {
|
|
973
|
-
|
|
978
|
+
log6.log("[BRAIN] sending request");
|
|
974
979
|
sendRequest();
|
|
975
980
|
}
|
|
976
981
|
}, [stillMounted]);
|
|
977
982
|
}
|
|
978
983
|
|
|
979
984
|
// src/formats/InlineAd.tsx
|
|
980
|
-
import
|
|
985
|
+
import log9 from "loglevel";
|
|
981
986
|
|
|
982
987
|
// src/components/MarkdownText.tsx
|
|
983
|
-
import
|
|
988
|
+
import log7 from "loglevel";
|
|
984
989
|
import { useContext as useContext2 } from "react";
|
|
985
990
|
import {
|
|
986
991
|
Linking,
|
|
@@ -997,7 +1002,7 @@ function MarkdownText({
|
|
|
997
1002
|
const linkClickHandler = (href) => {
|
|
998
1003
|
onLinkClick();
|
|
999
1004
|
Linking.openURL(href).catch(
|
|
1000
|
-
(err) =>
|
|
1005
|
+
(err) => log7.warn("Failed to open URL:", err)
|
|
1001
1006
|
);
|
|
1002
1007
|
return false;
|
|
1003
1008
|
};
|
|
@@ -1024,7 +1029,7 @@ function MarkdownText({
|
|
|
1024
1029
|
|
|
1025
1030
|
// src/components/VideoPlayer.tsx
|
|
1026
1031
|
import { ResizeMode, Video } from "expo-av";
|
|
1027
|
-
import
|
|
1032
|
+
import log8 from "loglevel";
|
|
1028
1033
|
import { useContext as useContext4, useEffect as useEffect7, useRef, useState as useState7 } from "react";
|
|
1029
1034
|
import { Linking as Linking2, Text as Text2, TouchableOpacity, View as View2 } from "react-native";
|
|
1030
1035
|
|
|
@@ -1119,7 +1124,7 @@ var VideoPlayer = ({
|
|
|
1119
1124
|
};
|
|
1120
1125
|
const handleLinkClick = (url) => {
|
|
1121
1126
|
if (url) {
|
|
1122
|
-
Linking2.openURL(url).catch((err) =>
|
|
1127
|
+
Linking2.openURL(url).catch((err) => log8.warn("Failed to open URL:", err));
|
|
1123
1128
|
onLinkClick();
|
|
1124
1129
|
}
|
|
1125
1130
|
};
|
|
@@ -1221,7 +1226,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1221
1226
|
if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
|
|
1222
1227
|
return null;
|
|
1223
1228
|
const onProgress = (progress) => {
|
|
1224
|
-
|
|
1229
|
+
log9.log(`Progress: ${progress}`);
|
|
1225
1230
|
};
|
|
1226
1231
|
const handleImageClick = (url) => {
|
|
1227
1232
|
if (url) {
|
|
@@ -1230,7 +1235,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1230
1235
|
window.open(url, "_blank");
|
|
1231
1236
|
} else {
|
|
1232
1237
|
Linking3.openURL(url).catch(
|
|
1233
|
-
(err) =>
|
|
1238
|
+
(err) => log9.warn("Failed to open URL:", err)
|
|
1234
1239
|
);
|
|
1235
1240
|
}
|
|
1236
1241
|
}
|