@kontextso/sdk-react-native 0.0.10-rc.0 → 0.0.10-rc.2

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
@@ -126,12 +126,12 @@ var Logger = class {
126
126
  var log = new Logger();
127
127
  var log_default = log;
128
128
  var UNRETRIABLE_ERRORS = [403, 429, 404];
129
- var fetchWithTimeout = async (input, init, customFetch2) => {
129
+ var fetchWithTimeout = async (input, init, customFetch) => {
130
130
  const { timeout = 16e3, ...rest } = init || {};
131
131
  const controller = new AbortController();
132
132
  const id = setTimeout(() => controller.abort(), timeout);
133
133
  try {
134
- const response = await (customFetch2 || fetch)(input, {
134
+ const response = await (customFetch || fetch)(input, {
135
135
  ...rest,
136
136
  signal: controller.signal
137
137
  });
@@ -145,14 +145,14 @@ var fetchWithTimeout = async (input, init, customFetch2) => {
145
145
  clearTimeout(id);
146
146
  }
147
147
  };
148
- var fetchRetry = async (input, init, singleRequestTimeout, maxRetries, onRetry, customFetch2) => {
148
+ var fetchRetry = async (input, init, singleRequestTimeout, maxRetries, onRetry, customFetch) => {
149
149
  let retries = 0;
150
150
  let response;
151
151
  let lastError = null;
152
152
  while (retries < maxRetries) {
153
153
  try {
154
154
  const requestInit = { ...init, timeout: singleRequestTimeout };
155
- response = await fetchWithTimeout(input, requestInit, customFetch2);
155
+ response = await fetchWithTimeout(input, requestInit, customFetch);
156
156
  if (UNRETRIABLE_ERRORS.includes(response.status)) {
157
157
  throw new Error(`Unretriable error: ${response.statusText}`);
158
158
  }
@@ -248,7 +248,7 @@ function mergeStyles(propStyles, defaultStyles, overridingStyles) {
248
248
  return mergedStyles;
249
249
  }
250
250
  var SINGLE_INIT_TIMEOUT_BUDGET_MS = 5e3;
251
- async function initialise(adServerUrl, publisherToken, visitorId, userId, conversationId, legacyVisitorId, character, customFetch2) {
251
+ async function initialise(adServerUrl, publisherToken, visitorId, userId, conversationId, legacyVisitorId, character, customFetch) {
252
252
  log_default.log("[Kontext] init ads started");
253
253
  const response = await fetchRetry(
254
254
  `${adServerUrl}/init`,
@@ -269,7 +269,7 @@ async function initialise(adServerUrl, publisherToken, visitorId, userId, conver
269
269
  () => {
270
270
  log_default.warn("[Kontext] Reinitialising ads");
271
271
  },
272
- customFetch2
272
+ customFetch
273
273
  );
274
274
  const { sessionId, enabledPlacements, ads, sessionDisabled, streamAdServer, onlyStream, remoteLogLevel, preloadTimeout, streamTimeout, defaultReactNativeStyles, overridingReactNativeStyles } = await response.json();
275
275
  const fixedAds = ads.map((ad) => {
@@ -301,7 +301,7 @@ function useInitializeAds({
301
301
  character,
302
302
  legacyVisitorId,
303
303
  captureError,
304
- customFetch: customFetch2,
304
+ customFetch,
305
305
  reactNativePropStyles
306
306
  }) {
307
307
  const [enabledPlacements, setEnabledPlacements] = (0, import_react3.useState)([]);
@@ -333,7 +333,7 @@ function useInitializeAds({
333
333
  conversationId,
334
334
  legacyVisitorId,
335
335
  character,
336
- customFetch2
336
+ customFetch
337
337
  ).then(({ sessionId: sessionId2, enabledPlacements: enabledPlacements2, ads: ads2, sessionDisabled, streamAdServer, onlyStream: onlyStream2, remoteLogLevel, preloadTimeout: preloadTimeout2, streamTimeout: streamTimeout2, defaultReactNativeStyles, overridingReactNativeStyles }) => {
338
338
  log_default.configureRemote(adServerUrl, {
339
339
  publisherToken,
@@ -390,7 +390,7 @@ function usePreloadAds({
390
390
  onlyStream,
391
391
  captureError,
392
392
  preloadTimeout,
393
- customFetch: customFetch2
393
+ customFetch
394
394
  }) {
395
395
  const [preloadDone, setPreloadDone] = (0, import_react4.useState)(false);
396
396
  const [ads, setAds] = (0, import_react4.useState)([]);
@@ -430,7 +430,7 @@ function usePreloadAds({
430
430
  sdkVersion: version
431
431
  })
432
432
  },
433
- customFetch2
433
+ customFetch
434
434
  );
435
435
  if (!response.ok) {
436
436
  throw new Error("Error preloading ads. Status: " + response.status);
@@ -688,7 +688,7 @@ function useStreamAds({
688
688
  publisherToken,
689
689
  captureError,
690
690
  streamTimeout,
691
- customFetch: customFetch2
691
+ customFetch
692
692
  }) {
693
693
  const [ads, setAds] = (0, import_react5.useState)([]);
694
694
  const fetchStream = async (messages2, code) => {
@@ -727,7 +727,7 @@ function useStreamAds({
727
727
  },
728
728
  timeout: streamTimeout
729
729
  },
730
- customFetch2
730
+ customFetch
731
731
  );
732
732
  if (!response.ok) {
733
733
  throw new Error("Error streaming ad. Status: " + response.status);
@@ -896,7 +896,7 @@ var AdsProviderWithoutBoundary = ({
896
896
  logLevel,
897
897
  onAdView,
898
898
  onAdClick,
899
- customFetch: customFetch2,
899
+ customFetch,
900
900
  reactNativePropStyles,
901
901
  isReactNative
902
902
  }) => {
@@ -950,7 +950,7 @@ var AdsProviderWithoutBoundary = ({
950
950
  character,
951
951
  isDisabled: !!isDisabled,
952
952
  captureError,
953
- customFetch: customFetch2,
953
+ customFetch,
954
954
  reactNativePropStyles
955
955
  });
956
956
  const isInitialised = !!isDisabled || !!initError || !!sessionId || sessionId === null;
@@ -969,7 +969,7 @@ var AdsProviderWithoutBoundary = ({
969
969
  onlyStream,
970
970
  captureError,
971
971
  preloadTimeout,
972
- customFetch: customFetch2
972
+ customFetch
973
973
  });
974
974
  const { ads: streamAds } = useStreamAds({
975
975
  userId,
@@ -985,7 +985,7 @@ var AdsProviderWithoutBoundary = ({
985
985
  publisherToken,
986
986
  captureError,
987
987
  streamTimeout,
988
- customFetch: customFetch2
988
+ customFetch
989
989
  });
990
990
  const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds, clickedAds });
991
991
  const markAdAsViewed = (ad) => {
@@ -1495,17 +1495,9 @@ var ErrorBoundary = class extends import_react11.default.Component {
1495
1495
  };
1496
1496
 
1497
1497
  // src/context/AdsProvider.tsx
1498
- var import_react_native5 = require("react-native");
1499
- var import_encoding = require("react-native-polyfill-globals/src/encoding");
1500
- var import_readable_stream = require("react-native-polyfill-globals/src/readable-stream");
1498
+ var import_fetch = require("expo/fetch");
1501
1499
  var import_jsx_runtime6 = require("react/jsx-runtime");
1502
1500
  var VISITOR_ID_KEY2 = "brain-visitor-id";
1503
- var customFetch = fetch;
1504
- if (import_react_native5.Platform.OS !== "web") {
1505
- (0, import_encoding.polyfill)();
1506
- (0, import_readable_stream.polyfill)();
1507
- customFetch = require("react-native-fetch-api").fetch;
1508
- }
1509
1501
  ErrorUtils.setGlobalHandler((error, isFatal) => {
1510
1502
  if (!isFatal) {
1511
1503
  log.warn(error);
@@ -1559,7 +1551,7 @@ var AdsProvider = ({
1559
1551
  onAdView,
1560
1552
  onAdClick,
1561
1553
  reactNativePropStyles: styles,
1562
- customFetch,
1554
+ customFetch: import_fetch.fetch,
1563
1555
  isReactNative: true
1564
1556
  }
1565
1557
  )
package/dist/index.mjs CHANGED
@@ -1,10 +1,3 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
1
  // src/formats/InlineAd.tsx
9
2
  import { useContext as useContext6, useEffect as useEffect8, useState as useState7 } from "react";
10
3
  import {
@@ -101,12 +94,12 @@ var Logger = class {
101
94
  var log = new Logger();
102
95
  var log_default = log;
103
96
  var UNRETRIABLE_ERRORS = [403, 429, 404];
104
- var fetchWithTimeout = async (input, init, customFetch2) => {
97
+ var fetchWithTimeout = async (input, init, customFetch) => {
105
98
  const { timeout = 16e3, ...rest } = init || {};
106
99
  const controller = new AbortController();
107
100
  const id = setTimeout(() => controller.abort(), timeout);
108
101
  try {
109
- const response = await (customFetch2 || fetch)(input, {
102
+ const response = await (customFetch || fetch)(input, {
110
103
  ...rest,
111
104
  signal: controller.signal
112
105
  });
@@ -120,14 +113,14 @@ var fetchWithTimeout = async (input, init, customFetch2) => {
120
113
  clearTimeout(id);
121
114
  }
122
115
  };
123
- var fetchRetry = async (input, init, singleRequestTimeout, maxRetries, onRetry, customFetch2) => {
116
+ var fetchRetry = async (input, init, singleRequestTimeout, maxRetries, onRetry, customFetch) => {
124
117
  let retries = 0;
125
118
  let response;
126
119
  let lastError = null;
127
120
  while (retries < maxRetries) {
128
121
  try {
129
122
  const requestInit = { ...init, timeout: singleRequestTimeout };
130
- response = await fetchWithTimeout(input, requestInit, customFetch2);
123
+ response = await fetchWithTimeout(input, requestInit, customFetch);
131
124
  if (UNRETRIABLE_ERRORS.includes(response.status)) {
132
125
  throw new Error(`Unretriable error: ${response.statusText}`);
133
126
  }
@@ -223,7 +216,7 @@ function mergeStyles(propStyles, defaultStyles, overridingStyles) {
223
216
  return mergedStyles;
224
217
  }
225
218
  var SINGLE_INIT_TIMEOUT_BUDGET_MS = 5e3;
226
- async function initialise(adServerUrl, publisherToken, visitorId, userId, conversationId, legacyVisitorId, character, customFetch2) {
219
+ async function initialise(adServerUrl, publisherToken, visitorId, userId, conversationId, legacyVisitorId, character, customFetch) {
227
220
  log_default.log("[Kontext] init ads started");
228
221
  const response = await fetchRetry(
229
222
  `${adServerUrl}/init`,
@@ -244,7 +237,7 @@ async function initialise(adServerUrl, publisherToken, visitorId, userId, conver
244
237
  () => {
245
238
  log_default.warn("[Kontext] Reinitialising ads");
246
239
  },
247
- customFetch2
240
+ customFetch
248
241
  );
249
242
  const { sessionId, enabledPlacements, ads, sessionDisabled, streamAdServer, onlyStream, remoteLogLevel, preloadTimeout, streamTimeout, defaultReactNativeStyles, overridingReactNativeStyles } = await response.json();
250
243
  const fixedAds = ads.map((ad) => {
@@ -276,7 +269,7 @@ function useInitializeAds({
276
269
  character,
277
270
  legacyVisitorId,
278
271
  captureError,
279
- customFetch: customFetch2,
272
+ customFetch,
280
273
  reactNativePropStyles
281
274
  }) {
282
275
  const [enabledPlacements, setEnabledPlacements] = useState([]);
@@ -308,7 +301,7 @@ function useInitializeAds({
308
301
  conversationId,
309
302
  legacyVisitorId,
310
303
  character,
311
- customFetch2
304
+ customFetch
312
305
  ).then(({ sessionId: sessionId2, enabledPlacements: enabledPlacements2, ads: ads2, sessionDisabled, streamAdServer, onlyStream: onlyStream2, remoteLogLevel, preloadTimeout: preloadTimeout2, streamTimeout: streamTimeout2, defaultReactNativeStyles, overridingReactNativeStyles }) => {
313
306
  log_default.configureRemote(adServerUrl, {
314
307
  publisherToken,
@@ -365,7 +358,7 @@ function usePreloadAds({
365
358
  onlyStream,
366
359
  captureError,
367
360
  preloadTimeout,
368
- customFetch: customFetch2
361
+ customFetch
369
362
  }) {
370
363
  const [preloadDone, setPreloadDone] = useState2(false);
371
364
  const [ads, setAds] = useState2([]);
@@ -405,7 +398,7 @@ function usePreloadAds({
405
398
  sdkVersion: version
406
399
  })
407
400
  },
408
- customFetch2
401
+ customFetch
409
402
  );
410
403
  if (!response.ok) {
411
404
  throw new Error("Error preloading ads. Status: " + response.status);
@@ -663,7 +656,7 @@ function useStreamAds({
663
656
  publisherToken,
664
657
  captureError,
665
658
  streamTimeout,
666
- customFetch: customFetch2
659
+ customFetch
667
660
  }) {
668
661
  const [ads, setAds] = useState3([]);
669
662
  const fetchStream = async (messages2, code) => {
@@ -702,7 +695,7 @@ function useStreamAds({
702
695
  },
703
696
  timeout: streamTimeout
704
697
  },
705
- customFetch2
698
+ customFetch
706
699
  );
707
700
  if (!response.ok) {
708
701
  throw new Error("Error streaming ad. Status: " + response.status);
@@ -871,7 +864,7 @@ var AdsProviderWithoutBoundary = ({
871
864
  logLevel,
872
865
  onAdView,
873
866
  onAdClick,
874
- customFetch: customFetch2,
867
+ customFetch,
875
868
  reactNativePropStyles,
876
869
  isReactNative
877
870
  }) => {
@@ -925,7 +918,7 @@ var AdsProviderWithoutBoundary = ({
925
918
  character,
926
919
  isDisabled: !!isDisabled,
927
920
  captureError,
928
- customFetch: customFetch2,
921
+ customFetch,
929
922
  reactNativePropStyles
930
923
  });
931
924
  const isInitialised = !!isDisabled || !!initError || !!sessionId || sessionId === null;
@@ -944,7 +937,7 @@ var AdsProviderWithoutBoundary = ({
944
937
  onlyStream,
945
938
  captureError,
946
939
  preloadTimeout,
947
- customFetch: customFetch2
940
+ customFetch
948
941
  });
949
942
  const { ads: streamAds } = useStreamAds({
950
943
  userId,
@@ -960,7 +953,7 @@ var AdsProviderWithoutBoundary = ({
960
953
  publisherToken,
961
954
  captureError,
962
955
  streamTimeout,
963
- customFetch: customFetch2
956
+ customFetch
964
957
  });
965
958
  const ads = mergeAds({ initAds, preloadAds, streamAds, viewedAds, clickedAds });
966
959
  const markAdAsViewed = (ad) => {
@@ -1470,17 +1463,9 @@ var ErrorBoundary = class extends React5.Component {
1470
1463
  };
1471
1464
 
1472
1465
  // src/context/AdsProvider.tsx
1473
- import { Platform as Platform2 } from "react-native";
1474
- import { polyfill as polyfillEncoding } from "react-native-polyfill-globals/src/encoding";
1475
- import { polyfill as polyfillReadableStream } from "react-native-polyfill-globals/src/readable-stream";
1466
+ import { fetch as fetch2 } from "expo/fetch";
1476
1467
  import { jsx as jsx6 } from "react/jsx-runtime";
1477
1468
  var VISITOR_ID_KEY2 = "brain-visitor-id";
1478
- var customFetch = fetch;
1479
- if (Platform2.OS !== "web") {
1480
- polyfillEncoding();
1481
- polyfillReadableStream();
1482
- customFetch = __require("react-native-fetch-api").fetch;
1483
- }
1484
1469
  ErrorUtils.setGlobalHandler((error, isFatal) => {
1485
1470
  if (!isFatal) {
1486
1471
  log.warn(error);
@@ -1534,7 +1519,7 @@ var AdsProvider = ({
1534
1519
  onAdView,
1535
1520
  onAdClick,
1536
1521
  reactNativePropStyles: styles,
1537
- customFetch,
1522
+ customFetch: fetch2,
1538
1523
  isReactNative: true
1539
1524
  }
1540
1525
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "0.0.10-rc.0",
3
+ "version": "0.0.10-rc.2",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -47,11 +47,7 @@
47
47
  "react-dom": "*",
48
48
  "react-native": "*"
49
49
  },
50
- "dependencies": {
51
- "react-native-fetch-api": "^3.0.0",
52
- "react-native-polyfill-globals": "^3.1.0",
53
- "web-streams-polyfill": "^3.1.1"
54
- },
50
+ "dependencies": {},
55
51
  "files": [
56
52
  "dist/*"
57
53
  ]