@kontextso/sdk-react-native 2.2.0-rc.3 → 2.2.0-rc.4

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
@@ -323,7 +323,7 @@ var Format = ({ code, messageId, wrapper, ...otherParams }) => {
323
323
  }, 250);
324
324
  return () => clearInterval(interval);
325
325
  }, []);
326
- if (!context || !bid || !iframeUrl) {
326
+ if (!context || !bid || !iframeUrl || context.isDisabled) {
327
327
  return null;
328
328
  }
329
329
  const getWidth = () => {
@@ -425,6 +425,9 @@ var import_react_native_device_info = __toESM(require("react-native-device-info"
425
425
  var import_react_native2 = require("react-native");
426
426
  var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
427
427
 
428
+ // package.json
429
+ var version = "2.2.0-rc.4";
430
+
428
431
  // src/context/AdsProvider.tsx
429
432
  var import_jsx_runtime4 = require("react/jsx-runtime");
430
433
  ErrorUtils.setGlobalHandler((error, isFatal) => {
@@ -436,41 +439,82 @@ ErrorUtils.setGlobalHandler((error, isFatal) => {
436
439
  });
437
440
  var getDevice = async () => {
438
441
  try {
439
- const os = import_react_native3.Platform.OS;
440
- const systemVersion = import_react_native_device_info.default.getSystemVersion();
441
- const model = import_react_native_device_info.default.getModel();
442
- const brand = import_react_native_device_info.default.getBrand();
443
- const deviceId = import_react_native_device_info.default.getDeviceId();
442
+ const powerState = await import_react_native_device_info.default.getPowerState();
444
443
  const deviceType = import_react_native_device_info.default.getDeviceType();
445
- const appBundleId = import_react_native_device_info.default.getBundleId();
446
- const appVersion = import_react_native_device_info.default.getVersion();
447
- let soundOn = false;
448
- try {
449
- soundOn = await NativeRNKontext_default.isSoundOn();
450
- } catch (error) {
451
- import_sdk_react2.log.warn("Failed to read output volume", error);
452
- }
453
- const rnv = import_react_native3.Platform.constants.reactNativeVersion;
454
- const reactNativeVersion = `${rnv.major}.${rnv.minor}.${rnv.patch}`;
444
+ const soundOn = await NativeRNKontext_default.isSoundOn();
445
+ const screen = import_react_native3.Dimensions.get("screen");
446
+ const mapDeviceTypeToHardwareType = () => {
447
+ switch (deviceType) {
448
+ case "Handset":
449
+ return "handset";
450
+ case "Tablet":
451
+ return "tablet";
452
+ case "Tv":
453
+ return "tv";
454
+ case "Desktop":
455
+ return "desktop";
456
+ default:
457
+ return "other";
458
+ }
459
+ };
455
460
  return {
456
- os,
457
- systemVersion,
458
- reactNativeVersion,
459
- model,
460
- brand,
461
- deviceId,
462
- deviceType,
463
- appBundleId,
464
- appVersion,
465
- soundOn
461
+ hardware: {
462
+ brand: import_react_native_device_info.default.getBrand(),
463
+ model: import_react_native_device_info.default.getModel(),
464
+ type: mapDeviceTypeToHardwareType()
465
+ // bootTime: Not available without native module
466
+ // sdCardAvailable: Not available without native module
467
+ },
468
+ audio: {
469
+ muted: soundOn
470
+ // volume: Requires react-native-volume-manager
471
+ // outputPluggedIn: Not available without native module
472
+ // outputType: Not available without native module
473
+ },
474
+ network: {
475
+ carrier: await import_react_native_device_info.default.getCarrier(),
476
+ userAgent: await import_react_native_device_info.default.getUserAgent()
477
+ // detail: Requires @react-native-community/netinfo
478
+ // type: Requires @react-native-community/netinfo
479
+ },
480
+ os: {
481
+ name: import_react_native3.Platform.OS,
482
+ version: import_react_native_device_info.default.getSystemVersion(),
483
+ locale: Intl.DateTimeFormat().resolvedOptions().locale,
484
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
485
+ },
486
+ screen: {
487
+ darkMode: import_react_native3.Appearance.getColorScheme() === "dark",
488
+ dpr: import_react_native3.PixelRatio.get(),
489
+ height: screen.height,
490
+ width: screen.width,
491
+ orientation: screen.width > screen.height ? "landscape" : "portrait"
492
+ },
493
+ power: {
494
+ batteryLevel: powerState.batteryLevel,
495
+ batteryState: powerState.batteryState,
496
+ lowPowerMode: powerState.lowPowerMode
497
+ }
466
498
  };
467
499
  } catch (error) {
468
500
  console.error(error);
501
+ return {};
469
502
  }
470
- return {};
471
503
  };
504
+ var getApp = async () => ({
505
+ bundleId: import_react_native_device_info.default.getBundleId(),
506
+ firstInstallTime: await import_react_native_device_info.default.getFirstInstallTime(),
507
+ lastUpdateTime: await import_react_native_device_info.default.getLastUpdateTime(),
508
+ startTime: await import_react_native_device_info.default.getStartupTime(),
509
+ version: import_react_native_device_info.default.getVersion()
510
+ });
511
+ var getSdk = async () => ({
512
+ name: "sdk-react-native",
513
+ platform: import_react_native3.Platform.OS === "ios" ? "ios" : "android",
514
+ version
515
+ });
472
516
  var AdsProvider = (props) => {
473
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_sdk_react2.AdsProviderInternal, { ...props, getDevice });
517
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_sdk_react2.AdsProviderInternal, { ...props, getDevice, getSdk, getApp });
474
518
  };
475
519
  // Annotate the CommonJS export names for ESM import in node:
476
520
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -292,7 +292,7 @@ var Format = ({ code, messageId, wrapper, ...otherParams }) => {
292
292
  }, 250);
293
293
  return () => clearInterval(interval);
294
294
  }, []);
295
- if (!context || !bid || !iframeUrl) {
295
+ if (!context || !bid || !iframeUrl || context.isDisabled) {
296
296
  return null;
297
297
  }
298
298
  const getWidth = () => {
@@ -387,13 +387,16 @@ var InlineAd_default = InlineAd;
387
387
 
388
388
  // src/context/AdsProvider.tsx
389
389
  import { AdsProviderInternal, log } from "@kontextso/sdk-react";
390
- import { Platform } from "react-native";
390
+ import { Platform, Dimensions, PixelRatio, Appearance } from "react-native";
391
391
  import DeviceInfo from "react-native-device-info";
392
392
 
393
393
  // src/NativeRNKontext.ts
394
394
  import { TurboModuleRegistry } from "react-native";
395
395
  var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
396
396
 
397
+ // package.json
398
+ var version = "2.2.0-rc.4";
399
+
397
400
  // src/context/AdsProvider.tsx
398
401
  import { jsx as jsx4 } from "react/jsx-runtime";
399
402
  ErrorUtils.setGlobalHandler((error, isFatal) => {
@@ -405,41 +408,82 @@ ErrorUtils.setGlobalHandler((error, isFatal) => {
405
408
  });
406
409
  var getDevice = async () => {
407
410
  try {
408
- const os = Platform.OS;
409
- const systemVersion = DeviceInfo.getSystemVersion();
410
- const model = DeviceInfo.getModel();
411
- const brand = DeviceInfo.getBrand();
412
- const deviceId = DeviceInfo.getDeviceId();
411
+ const powerState = await DeviceInfo.getPowerState();
413
412
  const deviceType = DeviceInfo.getDeviceType();
414
- const appBundleId = DeviceInfo.getBundleId();
415
- const appVersion = DeviceInfo.getVersion();
416
- let soundOn = false;
417
- try {
418
- soundOn = await NativeRNKontext_default.isSoundOn();
419
- } catch (error) {
420
- log.warn("Failed to read output volume", error);
421
- }
422
- const rnv = Platform.constants.reactNativeVersion;
423
- const reactNativeVersion = `${rnv.major}.${rnv.minor}.${rnv.patch}`;
413
+ const soundOn = await NativeRNKontext_default.isSoundOn();
414
+ const screen = Dimensions.get("screen");
415
+ const mapDeviceTypeToHardwareType = () => {
416
+ switch (deviceType) {
417
+ case "Handset":
418
+ return "handset";
419
+ case "Tablet":
420
+ return "tablet";
421
+ case "Tv":
422
+ return "tv";
423
+ case "Desktop":
424
+ return "desktop";
425
+ default:
426
+ return "other";
427
+ }
428
+ };
424
429
  return {
425
- os,
426
- systemVersion,
427
- reactNativeVersion,
428
- model,
429
- brand,
430
- deviceId,
431
- deviceType,
432
- appBundleId,
433
- appVersion,
434
- soundOn
430
+ hardware: {
431
+ brand: DeviceInfo.getBrand(),
432
+ model: DeviceInfo.getModel(),
433
+ type: mapDeviceTypeToHardwareType()
434
+ // bootTime: Not available without native module
435
+ // sdCardAvailable: Not available without native module
436
+ },
437
+ audio: {
438
+ muted: soundOn
439
+ // volume: Requires react-native-volume-manager
440
+ // outputPluggedIn: Not available without native module
441
+ // outputType: Not available without native module
442
+ },
443
+ network: {
444
+ carrier: await DeviceInfo.getCarrier(),
445
+ userAgent: await DeviceInfo.getUserAgent()
446
+ // detail: Requires @react-native-community/netinfo
447
+ // type: Requires @react-native-community/netinfo
448
+ },
449
+ os: {
450
+ name: Platform.OS,
451
+ version: DeviceInfo.getSystemVersion(),
452
+ locale: Intl.DateTimeFormat().resolvedOptions().locale,
453
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
454
+ },
455
+ screen: {
456
+ darkMode: Appearance.getColorScheme() === "dark",
457
+ dpr: PixelRatio.get(),
458
+ height: screen.height,
459
+ width: screen.width,
460
+ orientation: screen.width > screen.height ? "landscape" : "portrait"
461
+ },
462
+ power: {
463
+ batteryLevel: powerState.batteryLevel,
464
+ batteryState: powerState.batteryState,
465
+ lowPowerMode: powerState.lowPowerMode
466
+ }
435
467
  };
436
468
  } catch (error) {
437
469
  console.error(error);
470
+ return {};
438
471
  }
439
- return {};
440
472
  };
473
+ var getApp = async () => ({
474
+ bundleId: DeviceInfo.getBundleId(),
475
+ firstInstallTime: await DeviceInfo.getFirstInstallTime(),
476
+ lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
477
+ startTime: await DeviceInfo.getStartupTime(),
478
+ version: DeviceInfo.getVersion()
479
+ });
480
+ var getSdk = async () => ({
481
+ name: "sdk-react-native",
482
+ platform: Platform.OS === "ios" ? "ios" : "android",
483
+ version
484
+ });
441
485
  var AdsProvider = (props) => {
442
- return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice });
486
+ return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice, getSdk, getApp });
443
487
  };
444
488
  export {
445
489
  AdsProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "2.2.0-rc.3",
3
+ "version": "2.2.0-rc.4",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -55,7 +55,7 @@
55
55
  "react-native-webview": "^13.15.0"
56
56
  },
57
57
  "dependencies": {
58
- "@kontextso/sdk-react": "^1.2.4"
58
+ "@kontextso/sdk-react": "^2.0.0"
59
59
  },
60
60
  "files": [
61
61
  "dist/*",
@@ -1,10 +1,9 @@
1
- 'use client'
2
-
3
- import type { AdsProviderProps, Device } from '@kontextso/sdk-react'
1
+ import type { AdsProviderProps, AppConfig, DeviceConfig, SDKConfig } from '@kontextso/sdk-react'
4
2
  import { AdsProviderInternal, log } from '@kontextso/sdk-react'
5
- import { Platform } from 'react-native'
6
- import DeviceInfo from 'react-native-device-info'
3
+ import { Platform, Dimensions, PixelRatio, Appearance } from 'react-native'
4
+ import DeviceInfo, { type DeviceType } from 'react-native-device-info'
7
5
  import KontextSDK from '../NativeRNKontext'
6
+ import { version } from '../../package.json'
8
7
 
9
8
  ErrorUtils.setGlobalHandler((error, isFatal) => {
10
9
  if (!isFatal) {
@@ -14,45 +13,88 @@ ErrorUtils.setGlobalHandler((error, isFatal) => {
14
13
  }
15
14
  })
16
15
 
17
- const getDevice = async (): Promise<Device> => {
16
+ const getDevice = async (): Promise<DeviceConfig> => {
18
17
  try {
19
- const os = Platform.OS
20
- const systemVersion = DeviceInfo.getSystemVersion()
21
- const model = DeviceInfo.getModel()
22
- const brand = DeviceInfo.getBrand()
23
- const deviceId = DeviceInfo.getDeviceId()
24
- const deviceType = DeviceInfo.getDeviceType()
25
- const appBundleId = DeviceInfo.getBundleId()
26
- const appVersion = DeviceInfo.getVersion()
18
+ const powerState = await DeviceInfo.getPowerState()
19
+ const deviceType = DeviceInfo.getDeviceType() as DeviceType
20
+ const soundOn = await KontextSDK.isSoundOn()
21
+ const screen = Dimensions.get('screen')
27
22
 
28
- let soundOn = false
29
- try {
30
- soundOn = await KontextSDK.isSoundOn()
31
- } catch (error) {
32
- log.warn('Failed to read output volume', error)
23
+ const mapDeviceTypeToHardwareType = (): DeviceConfig['hardware']['type'] => {
24
+ switch (deviceType) {
25
+ case 'Handset':
26
+ return 'handset'
27
+ case 'Tablet':
28
+ return 'tablet'
29
+ case 'Tv':
30
+ return 'tv'
31
+ case 'Desktop':
32
+ return 'desktop'
33
+ default:
34
+ return 'other'
35
+ }
33
36
  }
34
37
 
35
- const rnv = Platform.constants.reactNativeVersion
36
- const reactNativeVersion = `${rnv.major}.${rnv.minor}.${rnv.patch}`
37
-
38
38
  return {
39
- os,
40
- systemVersion,
41
- reactNativeVersion,
42
- model,
43
- brand,
44
- deviceId,
45
- deviceType,
46
- appBundleId,
47
- appVersion,
48
- soundOn,
39
+ hardware: {
40
+ brand: DeviceInfo.getBrand(),
41
+ model: DeviceInfo.getModel(),
42
+ type: mapDeviceTypeToHardwareType(),
43
+ // bootTime: Not available without native module
44
+ // sdCardAvailable: Not available without native module
45
+ },
46
+ audio: {
47
+ muted: soundOn,
48
+ // volume: Requires react-native-volume-manager
49
+ // outputPluggedIn: Not available without native module
50
+ // outputType: Not available without native module
51
+ },
52
+ network: {
53
+ carrier: await DeviceInfo.getCarrier(),
54
+ userAgent: await DeviceInfo.getUserAgent(),
55
+ // detail: Requires @react-native-community/netinfo
56
+ // type: Requires @react-native-community/netinfo
57
+ },
58
+ os: {
59
+ name: Platform.OS,
60
+ version: DeviceInfo.getSystemVersion(),
61
+ locale: Intl.DateTimeFormat().resolvedOptions().locale,
62
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
63
+ },
64
+ screen: {
65
+ darkMode: Appearance.getColorScheme() === 'dark',
66
+ dpr: PixelRatio.get(),
67
+ height: screen.height,
68
+ width: screen.width,
69
+ orientation: screen.width > screen.height ? 'landscape' : 'portrait',
70
+ },
71
+ power: {
72
+ batteryLevel: powerState.batteryLevel,
73
+ batteryState: powerState.batteryState,
74
+ lowPowerMode: powerState.lowPowerMode,
75
+ },
49
76
  }
50
77
  } catch (error) {
51
78
  console.error(error)
79
+ // @ts-expect-error
80
+ return {}
52
81
  }
53
- return {}
54
82
  }
55
83
 
84
+ const getApp = async (): Promise<AppConfig> => ({
85
+ bundleId: DeviceInfo.getBundleId(),
86
+ firstInstallTime: await DeviceInfo.getFirstInstallTime(),
87
+ lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
88
+ startTime: await DeviceInfo.getStartupTime(),
89
+ version: DeviceInfo.getVersion(),
90
+ })
91
+
92
+ const getSdk = async (): Promise<SDKConfig> => ({
93
+ name: 'sdk-react-native',
94
+ platform: Platform.OS === 'ios' ? 'ios' : 'android',
95
+ version,
96
+ })
97
+
56
98
  export const AdsProvider = (props: AdsProviderProps) => {
57
- return <AdsProviderInternal {...props} getDevice={getDevice} />
99
+ return <AdsProviderInternal {...props} getDevice={getDevice} getSdk={getSdk} getApp={getApp} />
58
100
  }
@@ -294,7 +294,7 @@ const Format = ({ code, messageId, wrapper, ...otherParams }: FormatProps) => {
294
294
  return () => clearInterval(interval)
295
295
  }, [])
296
296
 
297
- if (!context || !bid || !iframeUrl) {
297
+ if (!context || !bid || !iframeUrl || context.isDisabled) {
298
298
  return null
299
299
  }
300
300