@kontextso/sdk-react-native 0.0.5 → 0.0.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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -9
- package/dist/index.mjs +25 -9
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -97,7 +97,7 @@ var fetchRetry = async (input, init, maxRetries = 3, retryPeriod = 500) => {
|
|
|
97
97
|
};
|
|
98
98
|
var fixUrl = (adserverUrl, ad) => {
|
|
99
99
|
if (ad.content) {
|
|
100
|
-
ad.content = ad.content.replace("/
|
|
100
|
+
ad.content = ad.content.replace("/impression/", `${adserverUrl}/impression/`);
|
|
101
101
|
}
|
|
102
102
|
return { ...ad, url: `${adserverUrl}${ad.url}` };
|
|
103
103
|
};
|
|
@@ -105,7 +105,8 @@ var mergeAds = ({
|
|
|
105
105
|
initAds,
|
|
106
106
|
preloadAds,
|
|
107
107
|
streamAds,
|
|
108
|
-
viewedAds
|
|
108
|
+
viewedAds,
|
|
109
|
+
clickedAds
|
|
109
110
|
}) => {
|
|
110
111
|
const ads = [...initAds];
|
|
111
112
|
if (Array.isArray(preloadAds)) {
|
|
@@ -132,6 +133,7 @@ var mergeAds = ({
|
|
|
132
133
|
}
|
|
133
134
|
for (const ad of ads) {
|
|
134
135
|
ad.viewed = viewedAds.includes(ad?.id || "placeholder");
|
|
136
|
+
ad.clicked = clickedAds.includes(ad?.id || "placeholder");
|
|
135
137
|
}
|
|
136
138
|
return ads;
|
|
137
139
|
};
|
|
@@ -204,6 +206,8 @@ var import_loglevel = __toESM(require("loglevel"));
|
|
|
204
206
|
var version = "0.0.5-rc.8";
|
|
205
207
|
|
|
206
208
|
// src/hooks/useInitializeAds.tsx
|
|
209
|
+
var SINGLE_INIT_TIMEOUT_BUDGET_MS = 3e3;
|
|
210
|
+
var SINGLE_INIT_RETRIES = 3;
|
|
207
211
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
208
212
|
import_loglevel.default.log("[BRAIN] init ads started");
|
|
209
213
|
const response = await fetchRetry(
|
|
@@ -221,8 +225,8 @@ async function initialize(adServerUrl, publisherToken, userId, conversationId, l
|
|
|
221
225
|
character
|
|
222
226
|
})
|
|
223
227
|
},
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
SINGLE_INIT_TIMEOUT_BUDGET_MS,
|
|
229
|
+
SINGLE_INIT_RETRIES
|
|
226
230
|
);
|
|
227
231
|
const {
|
|
228
232
|
sessionId,
|
|
@@ -715,8 +719,8 @@ function useStreamAds({
|
|
|
715
719
|
isLoading: false,
|
|
716
720
|
isStreaming: true,
|
|
717
721
|
content: content.replace(
|
|
718
|
-
new RegExp(`/
|
|
719
|
-
`/
|
|
722
|
+
new RegExp(`/impression/${adData.product.id}/redirect`, "g"),
|
|
723
|
+
`/impression/${adData.id}/redirect`
|
|
720
724
|
)
|
|
721
725
|
});
|
|
722
726
|
return newAd;
|
|
@@ -813,6 +817,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
813
817
|
...props
|
|
814
818
|
}) => {
|
|
815
819
|
const [viewedAds, setViewedAds] = (0, import_react5.useState)([]);
|
|
820
|
+
const [clickedAds, setClickedAds] = (0, import_react5.useState)([]);
|
|
816
821
|
const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
|
|
817
822
|
import_loglevel5.default.setLevel(logLevel || "ERROR");
|
|
818
823
|
const {
|
|
@@ -857,7 +862,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
857
862
|
enabledPlacements,
|
|
858
863
|
publisherToken
|
|
859
864
|
});
|
|
860
|
-
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds });
|
|
865
|
+
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds, clickedAds });
|
|
861
866
|
const markAdAsViewed = (ad) => {
|
|
862
867
|
import_loglevel5.default.debug("[Brain] Calling onAdView");
|
|
863
868
|
onAdView && onAdView({
|
|
@@ -878,6 +883,13 @@ var AdsProviderWithoutBoundary = ({
|
|
|
878
883
|
messageId: ad.messageId,
|
|
879
884
|
content: ad.content
|
|
880
885
|
});
|
|
886
|
+
if (!ad.id) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (clickedAds.includes(ad.id)) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
setClickedAds((old) => [...old, ad.id]);
|
|
881
893
|
};
|
|
882
894
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
883
895
|
AdsContext.Provider,
|
|
@@ -971,7 +983,7 @@ function useAdViewed(ad) {
|
|
|
971
983
|
serverUrl = context.streamAdServerUrl;
|
|
972
984
|
}
|
|
973
985
|
try {
|
|
974
|
-
const response = await fetch(`${serverUrl}/
|
|
986
|
+
const response = await fetch(`${serverUrl}/impression/${ad.id}/view`, {
|
|
975
987
|
method: "POST"
|
|
976
988
|
});
|
|
977
989
|
if (!response.ok) {
|
|
@@ -1256,6 +1268,10 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1256
1268
|
}
|
|
1257
1269
|
}
|
|
1258
1270
|
};
|
|
1271
|
+
let adContent = ad.content;
|
|
1272
|
+
if (ad.clicked && ad.rewardContent) {
|
|
1273
|
+
adContent = ad.rewardContent;
|
|
1274
|
+
}
|
|
1259
1275
|
const content = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native5.View, { style: styles?.container, children: [
|
|
1260
1276
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native5.View, { style: styles?.adBadgeContainer, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native5.Text, { style: styles?.adBadgeText, children: "Ad" }) }),
|
|
1261
1277
|
ad.imageUrl && ad.mediaPlacement === "top" && !ad.isStreaming && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -1285,7 +1301,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1285
1301
|
MarkdownText,
|
|
1286
1302
|
{
|
|
1287
1303
|
onLinkClick: () => context?.onAdClickInternal(ad),
|
|
1288
|
-
content:
|
|
1304
|
+
content: adContent
|
|
1289
1305
|
}
|
|
1290
1306
|
) }),
|
|
1291
1307
|
ad.imageUrl && ad.mediaPlacement === "bottom" && !ad.isStreaming && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
package/dist/index.mjs
CHANGED
|
@@ -71,7 +71,7 @@ var fetchRetry = async (input, init, maxRetries = 3, retryPeriod = 500) => {
|
|
|
71
71
|
};
|
|
72
72
|
var fixUrl = (adserverUrl, ad) => {
|
|
73
73
|
if (ad.content) {
|
|
74
|
-
ad.content = ad.content.replace("/
|
|
74
|
+
ad.content = ad.content.replace("/impression/", `${adserverUrl}/impression/`);
|
|
75
75
|
}
|
|
76
76
|
return { ...ad, url: `${adserverUrl}${ad.url}` };
|
|
77
77
|
};
|
|
@@ -79,7 +79,8 @@ var mergeAds = ({
|
|
|
79
79
|
initAds,
|
|
80
80
|
preloadAds,
|
|
81
81
|
streamAds,
|
|
82
|
-
viewedAds
|
|
82
|
+
viewedAds,
|
|
83
|
+
clickedAds
|
|
83
84
|
}) => {
|
|
84
85
|
const ads = [...initAds];
|
|
85
86
|
if (Array.isArray(preloadAds)) {
|
|
@@ -106,6 +107,7 @@ var mergeAds = ({
|
|
|
106
107
|
}
|
|
107
108
|
for (const ad of ads) {
|
|
108
109
|
ad.viewed = viewedAds.includes(ad?.id || "placeholder");
|
|
110
|
+
ad.clicked = clickedAds.includes(ad?.id || "placeholder");
|
|
109
111
|
}
|
|
110
112
|
return ads;
|
|
111
113
|
};
|
|
@@ -178,6 +180,8 @@ import log from "loglevel";
|
|
|
178
180
|
var version = "0.0.5-rc.8";
|
|
179
181
|
|
|
180
182
|
// src/hooks/useInitializeAds.tsx
|
|
183
|
+
var SINGLE_INIT_TIMEOUT_BUDGET_MS = 3e3;
|
|
184
|
+
var SINGLE_INIT_RETRIES = 3;
|
|
181
185
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
182
186
|
log.log("[BRAIN] init ads started");
|
|
183
187
|
const response = await fetchRetry(
|
|
@@ -195,8 +199,8 @@ async function initialize(adServerUrl, publisherToken, userId, conversationId, l
|
|
|
195
199
|
character
|
|
196
200
|
})
|
|
197
201
|
},
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
SINGLE_INIT_TIMEOUT_BUDGET_MS,
|
|
203
|
+
SINGLE_INIT_RETRIES
|
|
200
204
|
);
|
|
201
205
|
const {
|
|
202
206
|
sessionId,
|
|
@@ -689,8 +693,8 @@ function useStreamAds({
|
|
|
689
693
|
isLoading: false,
|
|
690
694
|
isStreaming: true,
|
|
691
695
|
content: content.replace(
|
|
692
|
-
new RegExp(`/
|
|
693
|
-
`/
|
|
696
|
+
new RegExp(`/impression/${adData.product.id}/redirect`, "g"),
|
|
697
|
+
`/impression/${adData.id}/redirect`
|
|
694
698
|
)
|
|
695
699
|
});
|
|
696
700
|
return newAd;
|
|
@@ -787,6 +791,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
787
791
|
...props
|
|
788
792
|
}) => {
|
|
789
793
|
const [viewedAds, setViewedAds] = useState4([]);
|
|
794
|
+
const [clickedAds, setClickedAds] = useState4([]);
|
|
790
795
|
const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
|
|
791
796
|
log5.setLevel(logLevel || "ERROR");
|
|
792
797
|
const {
|
|
@@ -831,7 +836,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
831
836
|
enabledPlacements,
|
|
832
837
|
publisherToken
|
|
833
838
|
});
|
|
834
|
-
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds });
|
|
839
|
+
const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds, clickedAds });
|
|
835
840
|
const markAdAsViewed = (ad) => {
|
|
836
841
|
log5.debug("[Brain] Calling onAdView");
|
|
837
842
|
onAdView && onAdView({
|
|
@@ -852,6 +857,13 @@ var AdsProviderWithoutBoundary = ({
|
|
|
852
857
|
messageId: ad.messageId,
|
|
853
858
|
content: ad.content
|
|
854
859
|
});
|
|
860
|
+
if (!ad.id) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
if (clickedAds.includes(ad.id)) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
setClickedAds((old) => [...old, ad.id]);
|
|
855
867
|
};
|
|
856
868
|
return /* @__PURE__ */ jsx(
|
|
857
869
|
AdsContext.Provider,
|
|
@@ -945,7 +957,7 @@ function useAdViewed(ad) {
|
|
|
945
957
|
serverUrl = context.streamAdServerUrl;
|
|
946
958
|
}
|
|
947
959
|
try {
|
|
948
|
-
const response = await fetch(`${serverUrl}/
|
|
960
|
+
const response = await fetch(`${serverUrl}/impression/${ad.id}/view`, {
|
|
949
961
|
method: "POST"
|
|
950
962
|
});
|
|
951
963
|
if (!response.ok) {
|
|
@@ -1233,6 +1245,10 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1233
1245
|
}
|
|
1234
1246
|
}
|
|
1235
1247
|
};
|
|
1248
|
+
let adContent = ad.content;
|
|
1249
|
+
if (ad.clicked && ad.rewardContent) {
|
|
1250
|
+
adContent = ad.rewardContent;
|
|
1251
|
+
}
|
|
1236
1252
|
const content = /* @__PURE__ */ jsxs2(View3, { style: styles?.container, children: [
|
|
1237
1253
|
/* @__PURE__ */ jsx5(View3, { style: styles?.adBadgeContainer, children: /* @__PURE__ */ jsx5(Text3, { style: styles?.adBadgeText, children: "Ad" }) }),
|
|
1238
1254
|
ad.imageUrl && ad.mediaPlacement === "top" && !ad.isStreaming && /* @__PURE__ */ jsx5(
|
|
@@ -1262,7 +1278,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
|
|
|
1262
1278
|
MarkdownText,
|
|
1263
1279
|
{
|
|
1264
1280
|
onLinkClick: () => context?.onAdClickInternal(ad),
|
|
1265
|
-
content:
|
|
1281
|
+
content: adContent
|
|
1266
1282
|
}
|
|
1267
1283
|
) }),
|
|
1268
1284
|
ad.imageUrl && ad.mediaPlacement === "bottom" && !ad.isStreaming && /* @__PURE__ */ jsx5(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontextso/sdk-react-native",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"dev": "npm-run-all dev:js",
|
|
11
11
|
"build:js": "tsup",
|
|
12
12
|
"build": "npm run build:js && cross-env NODE_ENV=development npm run test:run",
|
|
13
|
-
"test": "",
|
|
14
|
-
"test:run": "",
|
|
13
|
+
"test": "vitest --run",
|
|
14
|
+
"test:run": "vitest --run",
|
|
15
15
|
"_test": "vitest",
|
|
16
16
|
"_test:run": "vitest --run",
|
|
17
17
|
"_test:watch": "vitest --watch",
|