@kontextso/sdk-react-native 3.0.4 → 3.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.js CHANGED
@@ -44,10 +44,11 @@ function makeIframeMessage(type, opts) {
44
44
  function handleIframeMessage(handler, opts) {
45
45
  const { origin, code, component } = opts;
46
46
  return (event) => {
47
+ var _a, _b;
47
48
  if (origin && event.origin !== origin) return;
48
- const eventCode = event.data.data?.code;
49
+ const eventCode = (_a = event.data.data) == null ? void 0 : _a.code;
49
50
  if (eventCode && code && eventCode !== code) return;
50
- const eventComponent = event.data.data?.component;
51
+ const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component;
51
52
  if (eventComponent && component && eventComponent !== component) return;
52
53
  handler(event.data);
53
54
  };
@@ -118,7 +119,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
118
119
  const bid = (0, import_sdk_react.useBid)({ code, messageId });
119
120
  const [height, setHeight] = (0, import_react2.useState)(0);
120
121
  const cachedContent = getCachedContent(context, bid?.bidId);
121
- const iframeUrl = (0, import_sdk_react.useIframeUrl)(context, bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
122
+ const iframeUrl = (0, import_sdk_react.useIframeUrl)(bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
122
123
  const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
123
124
  const [showIframe, setShowIframe] = (0, import_react2.useState)(false);
124
125
  const [iframeLoaded, setIframeLoaded] = (0, import_react2.useState)(false);
@@ -454,16 +455,17 @@ var InlineAd_default = InlineAd;
454
455
 
455
456
  // src/context/AdsProvider.tsx
456
457
  var import_sdk_react2 = require("@kontextso/sdk-react");
458
+ var import_netinfo = require("@react-native-community/netinfo");
457
459
  var import_react_native3 = require("react-native");
458
460
  var import_react_native_device_info = __toESM(require("react-native-device-info"));
459
461
 
462
+ // package.json
463
+ var version = "3.0.6";
464
+
460
465
  // src/NativeRNKontext.ts
461
466
  var import_react_native2 = require("react-native");
462
467
  var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
463
468
 
464
- // package.json
465
- var version = "3.0.4";
466
-
467
469
  // src/context/AdsProvider.tsx
468
470
  var import_jsx_runtime4 = require("react/jsx-runtime");
469
471
  ErrorUtils.setGlobalHandler((error, isFatal) => {
@@ -479,6 +481,7 @@ var getDevice = async () => {
479
481
  const deviceType = import_react_native_device_info.default.getDeviceType();
480
482
  const soundOn = await NativeRNKontext_default.isSoundOn();
481
483
  const screen = import_react_native3.Dimensions.get("screen");
484
+ const networkInfo = await (0, import_netinfo.fetch)();
482
485
  const mapDeviceTypeToHardwareType = () => {
483
486
  switch (deviceType) {
484
487
  case "Handset":
@@ -496,7 +499,7 @@ var getDevice = async () => {
496
499
  return {
497
500
  hardware: {
498
501
  brand: import_react_native_device_info.default.getBrand(),
499
- model: import_react_native_device_info.default.getModel(),
502
+ model: import_react_native_device_info.default.getDeviceId(),
500
503
  type: mapDeviceTypeToHardwareType()
501
504
  // bootTime: Not available without native module
502
505
  // sdCardAvailable: Not available without native module
@@ -508,10 +511,10 @@ var getDevice = async () => {
508
511
  // outputType: Not available without native module
509
512
  },
510
513
  network: {
511
- // carrier: await DeviceInfo.getCarrier(), not supported in react-native-device-info v10.0.0
512
- userAgent: await import_react_native_device_info.default.getUserAgent()
513
- // detail: Requires @react-native-community/netinfo
514
- // type: Requires @react-native-community/netinfo
514
+ carrier: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.carrier || void 0,
515
+ userAgent: await import_react_native_device_info.default.getUserAgent(),
516
+ type: [import_netinfo.NetInfoStateType.wifi, import_netinfo.NetInfoStateType.cellular, import_netinfo.NetInfoStateType.ethernet].includes(networkInfo.type) ? networkInfo.type : import_netinfo.NetInfoStateType.other,
517
+ detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
515
518
  },
516
519
  os: {
517
520
  name: import_react_native3.Platform.OS,
@@ -537,14 +540,21 @@ var getDevice = async () => {
537
540
  return {};
538
541
  }
539
542
  };
540
- var getApp = async () => ({
541
- bundleId: import_react_native_device_info.default.getBundleId(),
542
- // not supported in react-native-device-info v10.0.0
543
- // firstInstallTime: await DeviceInfo.getFirstInstallTime(),
544
- // lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
545
- // startTime: await DeviceInfo.getStartupTime(),
546
- version: import_react_native_device_info.default.getVersion()
547
- });
543
+ var getApp = async () => {
544
+ try {
545
+ return {
546
+ bundleId: import_react_native_device_info.default.getBundleId(),
547
+ firstInstallTime: await import_react_native_device_info.default.getFirstInstallTime(),
548
+ lastUpdateTime: await import_react_native_device_info.default.getLastUpdateTime(),
549
+ version: import_react_native_device_info.default.getVersion()
550
+ // Not supported in react-native-device-info v10
551
+ // startTime: await DeviceInfo.getStartupTime(),
552
+ };
553
+ } catch (error) {
554
+ console.error(error);
555
+ return {};
556
+ }
557
+ };
548
558
  var getSdk = async () => ({
549
559
  name: "sdk-react-native",
550
560
  platform: import_react_native3.Platform.OS === "ios" ? "ios" : "android",
package/dist/index.mjs CHANGED
@@ -7,10 +7,11 @@ function makeIframeMessage(type, opts) {
7
7
  function handleIframeMessage(handler, opts) {
8
8
  const { origin, code, component } = opts;
9
9
  return (event) => {
10
+ var _a, _b;
10
11
  if (origin && event.origin !== origin) return;
11
- const eventCode = event.data.data?.code;
12
+ const eventCode = (_a = event.data.data) == null ? void 0 : _a.code;
12
13
  if (eventCode && code && eventCode !== code) return;
13
- const eventComponent = event.data.data?.component;
14
+ const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component;
14
15
  if (eventComponent && component && eventComponent !== component) return;
15
16
  handler(event.data);
16
17
  };
@@ -87,7 +88,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
87
88
  const bid = useBid({ code, messageId });
88
89
  const [height, setHeight] = useState(0);
89
90
  const cachedContent = getCachedContent(context, bid?.bidId);
90
- const iframeUrl = useIframeUrl(context, bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
91
+ const iframeUrl = useIframeUrl(bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
91
92
  const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
92
93
  const [showIframe, setShowIframe] = useState(false);
93
94
  const [iframeLoaded, setIframeLoaded] = useState(false);
@@ -422,17 +423,21 @@ var InlineAd = ({ code, messageId, wrapper, ...props }) => {
422
423
  var InlineAd_default = InlineAd;
423
424
 
424
425
  // src/context/AdsProvider.tsx
425
- import { AdsProviderInternal, log } from "@kontextso/sdk-react";
426
- import { Platform, Dimensions, PixelRatio, Appearance } from "react-native";
426
+ import {
427
+ AdsProviderInternal,
428
+ log
429
+ } from "@kontextso/sdk-react";
430
+ import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
431
+ import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
427
432
  import DeviceInfo from "react-native-device-info";
428
433
 
434
+ // package.json
435
+ var version = "3.0.6";
436
+
429
437
  // src/NativeRNKontext.ts
430
438
  import { TurboModuleRegistry } from "react-native";
431
439
  var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
432
440
 
433
- // package.json
434
- var version = "3.0.4";
435
-
436
441
  // src/context/AdsProvider.tsx
437
442
  import { jsx as jsx4 } from "react/jsx-runtime";
438
443
  ErrorUtils.setGlobalHandler((error, isFatal) => {
@@ -448,6 +453,7 @@ var getDevice = async () => {
448
453
  const deviceType = DeviceInfo.getDeviceType();
449
454
  const soundOn = await NativeRNKontext_default.isSoundOn();
450
455
  const screen = Dimensions.get("screen");
456
+ const networkInfo = await fetchNetworkInfo();
451
457
  const mapDeviceTypeToHardwareType = () => {
452
458
  switch (deviceType) {
453
459
  case "Handset":
@@ -465,7 +471,7 @@ var getDevice = async () => {
465
471
  return {
466
472
  hardware: {
467
473
  brand: DeviceInfo.getBrand(),
468
- model: DeviceInfo.getModel(),
474
+ model: DeviceInfo.getDeviceId(),
469
475
  type: mapDeviceTypeToHardwareType()
470
476
  // bootTime: Not available without native module
471
477
  // sdCardAvailable: Not available without native module
@@ -477,10 +483,10 @@ var getDevice = async () => {
477
483
  // outputType: Not available without native module
478
484
  },
479
485
  network: {
480
- // carrier: await DeviceInfo.getCarrier(), not supported in react-native-device-info v10.0.0
481
- userAgent: await DeviceInfo.getUserAgent()
482
- // detail: Requires @react-native-community/netinfo
483
- // type: Requires @react-native-community/netinfo
486
+ carrier: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier || void 0,
487
+ userAgent: await DeviceInfo.getUserAgent(),
488
+ type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type) ? networkInfo.type : NetInfoStateType.other,
489
+ detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
484
490
  },
485
491
  os: {
486
492
  name: Platform.OS,
@@ -506,14 +512,21 @@ var getDevice = async () => {
506
512
  return {};
507
513
  }
508
514
  };
509
- var getApp = async () => ({
510
- bundleId: DeviceInfo.getBundleId(),
511
- // not supported in react-native-device-info v10.0.0
512
- // firstInstallTime: await DeviceInfo.getFirstInstallTime(),
513
- // lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
514
- // startTime: await DeviceInfo.getStartupTime(),
515
- version: DeviceInfo.getVersion()
516
- });
515
+ var getApp = async () => {
516
+ try {
517
+ return {
518
+ bundleId: DeviceInfo.getBundleId(),
519
+ firstInstallTime: await DeviceInfo.getFirstInstallTime(),
520
+ lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
521
+ version: DeviceInfo.getVersion()
522
+ // Not supported in react-native-device-info v10
523
+ // startTime: await DeviceInfo.getStartupTime(),
524
+ };
525
+ } catch (error) {
526
+ console.error(error);
527
+ return {};
528
+ }
529
+ };
517
530
  var getSdk = async () => ({
518
531
  name: "sdk-react-native",
519
532
  platform: Platform.OS === "ios" ? "ios" : "android",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -14,13 +14,15 @@
14
14
  "dev": "npm-run-all2 dev:js",
15
15
  "build:js": "tsup",
16
16
  "build": "npm run build:js && cross-env NODE_ENV=development npm run test:run",
17
- "test": "",
18
- "test:run": "",
17
+ "test:run": "vitest --run",
18
+ "test": "vitest --run",
19
+ "test:watch": "vitest --watch",
19
20
  "format": "biome format --write ."
20
21
  },
21
22
  "devDependencies": {
22
- "@kontextso/sdk-common": "^0.2.0",
23
+ "@kontextso/sdk-common": "^1.0.0",
23
24
  "@kontextso/typescript-config": "*",
25
+ "@react-native-community/netinfo": "11.3.1",
24
26
  "@testing-library/dom": "^10.4.0",
25
27
  "@testing-library/jest-dom": "^6.4.6",
26
28
  "@testing-library/react": "^16.0.0",
@@ -37,7 +39,7 @@
37
39
  "react": "^18.3.1",
38
40
  "react-dom": "^18.3.1",
39
41
  "react-native": "^0.80.1",
40
- "react-native-device-info": ">=12.0.0",
42
+ "react-native-device-info": "10.14.0",
41
43
  "react-native-webview": "^13.15.0",
42
44
  "react-test-renderer": "^18.3.1",
43
45
  "tsup": "^8.0.2",
@@ -45,13 +47,14 @@
45
47
  "vitest": "^2.1.2"
46
48
  },
47
49
  "peerDependencies": {
50
+ "@react-native-community/netinfo": "^11.0",
48
51
  "react": ">=18.0.0",
49
52
  "react-native": ">=0.73.0",
50
53
  "react-native-device-info": ">=10.0.0 <15.0.0",
51
54
  "react-native-webview": "^13.10.0"
52
55
  },
53
56
  "dependencies": {
54
- "@kontextso/sdk-react": "^3.0.4"
57
+ "@kontextso/sdk-react": "^3.0.5"
55
58
  },
56
59
  "files": [
57
60
  "dist/*",
@@ -0,0 +1,9 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ describe('utils', () => {
4
+ describe('test', () => {
5
+ test('test', () => {
6
+ expect(1).toBe(1)
7
+ })
8
+ })
9
+ })
@@ -1,9 +1,16 @@
1
- import type { AdsProviderProps, AppConfig, DeviceConfig, SDKConfig } from '@kontextso/sdk-react'
2
- import { AdsProviderInternal, log } from '@kontextso/sdk-react'
3
- import { Platform, Dimensions, PixelRatio, Appearance } from 'react-native'
1
+ import {
2
+ AdsProviderInternal,
3
+ type AdsProviderProps,
4
+ type AppConfig,
5
+ type DeviceConfig,
6
+ log,
7
+ type SDKConfig,
8
+ } from '@kontextso/sdk-react'
9
+ import { fetch as fetchNetworkInfo, NetInfoStateType } from '@react-native-community/netinfo'
10
+ import { Appearance, Dimensions, PixelRatio, Platform } from 'react-native'
4
11
  import DeviceInfo, { type DeviceType } from 'react-native-device-info'
5
- import KontextSDK from '../NativeRNKontext'
6
12
  import { version } from '../../package.json'
13
+ import KontextSDK from '../NativeRNKontext'
7
14
 
8
15
  ErrorUtils.setGlobalHandler((error, isFatal) => {
9
16
  if (!isFatal) {
@@ -19,6 +26,7 @@ const getDevice = async (): Promise<DeviceConfig> => {
19
26
  const deviceType = DeviceInfo.getDeviceType() as DeviceType
20
27
  const soundOn = await KontextSDK.isSoundOn()
21
28
  const screen = Dimensions.get('screen')
29
+ const networkInfo = await fetchNetworkInfo()
22
30
 
23
31
  const mapDeviceTypeToHardwareType = (): DeviceConfig['hardware']['type'] => {
24
32
  switch (deviceType) {
@@ -38,7 +46,7 @@ const getDevice = async (): Promise<DeviceConfig> => {
38
46
  return {
39
47
  hardware: {
40
48
  brand: DeviceInfo.getBrand(),
41
- model: DeviceInfo.getModel(),
49
+ model: DeviceInfo.getDeviceId(),
42
50
  type: mapDeviceTypeToHardwareType(),
43
51
  // bootTime: Not available without native module
44
52
  // sdCardAvailable: Not available without native module
@@ -50,10 +58,12 @@ const getDevice = async (): Promise<DeviceConfig> => {
50
58
  // outputType: Not available without native module
51
59
  },
52
60
  network: {
53
- // carrier: await DeviceInfo.getCarrier(), not supported in react-native-device-info v10.0.0
61
+ carrier: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier) || undefined,
54
62
  userAgent: await DeviceInfo.getUserAgent(),
55
- // detail: Requires @react-native-community/netinfo
56
- // type: Requires @react-native-community/netinfo
63
+ type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type)
64
+ ? (networkInfo.type as NetInfoStateType.wifi | NetInfoStateType.cellular | NetInfoStateType.ethernet)
65
+ : NetInfoStateType.other,
66
+ detail: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration) || undefined,
57
67
  },
58
68
  os: {
59
69
  name: Platform.OS,
@@ -81,16 +91,22 @@ const getDevice = async (): Promise<DeviceConfig> => {
81
91
  }
82
92
  }
83
93
 
84
- const getApp = async (): Promise<AppConfig> => ({
85
- bundleId: DeviceInfo.getBundleId(),
86
-
87
- // not supported in react-native-device-info v10.0.0
88
- // firstInstallTime: await DeviceInfo.getFirstInstallTime(),
89
- // lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
90
- // startTime: await DeviceInfo.getStartupTime(),
91
-
92
- version: DeviceInfo.getVersion(),
93
- })
94
+ const getApp = async (): Promise<AppConfig> => {
95
+ try {
96
+ return {
97
+ bundleId: DeviceInfo.getBundleId(),
98
+ firstInstallTime: await DeviceInfo.getFirstInstallTime(),
99
+ lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
100
+ version: DeviceInfo.getVersion(),
101
+ // Not supported in react-native-device-info v10
102
+ // startTime: await DeviceInfo.getStartupTime(),
103
+ }
104
+ } catch (error) {
105
+ console.error(error)
106
+ // @ts-expect-error
107
+ return {}
108
+ }
109
+ }
94
110
 
95
111
  const getSdk = async (): Promise<SDKConfig> => ({
96
112
  name: 'sdk-react-native',
@@ -52,7 +52,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
52
52
 
53
53
  const cachedContent = getCachedContent(context, bid?.bidId)
54
54
 
55
- const iframeUrl = useIframeUrl(context, bid, code, messageId, 'sdk-react-native', otherParams.theme, cachedContent)
55
+ const iframeUrl = useIframeUrl(bid, code, messageId, 'sdk-react-native', otherParams.theme, cachedContent)
56
56
  const modalUrl = iframeUrl.replace('/api/frame/', '/api/modal/')
57
57
 
58
58
  const [showIframe, setShowIframe] = useState<boolean>(false)