@kontextso/sdk-react-native 3.0.5 → 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 +25 -15
- package/dist/index.mjs +29 -16
- package/package.json +8 -5
- package/src/__tests__/util.test.ts +9 -0
- package/src/context/AdsProvider.tsx +31 -15
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
|
|
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
|
|
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
|
};
|
|
@@ -454,11 +455,12 @@ 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
|
|
|
460
462
|
// package.json
|
|
461
|
-
var version = "3.0.
|
|
463
|
+
var version = "3.0.6";
|
|
462
464
|
|
|
463
465
|
// src/NativeRNKontext.ts
|
|
464
466
|
var import_react_native2 = require("react-native");
|
|
@@ -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":
|
|
@@ -508,10 +511,10 @@ var getDevice = async () => {
|
|
|
508
511
|
// outputType: Not available without native module
|
|
509
512
|
},
|
|
510
513
|
network: {
|
|
511
|
-
|
|
512
|
-
userAgent: await import_react_native_device_info.default.getUserAgent()
|
|
513
|
-
|
|
514
|
-
|
|
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
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
|
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
|
|
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
|
};
|
|
@@ -422,12 +423,16 @@ var InlineAd = ({ code, messageId, wrapper, ...props }) => {
|
|
|
422
423
|
var InlineAd_default = InlineAd;
|
|
423
424
|
|
|
424
425
|
// src/context/AdsProvider.tsx
|
|
425
|
-
import {
|
|
426
|
+
import {
|
|
427
|
+
AdsProviderInternal,
|
|
428
|
+
log
|
|
429
|
+
} from "@kontextso/sdk-react";
|
|
430
|
+
import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
|
|
426
431
|
import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
|
|
427
432
|
import DeviceInfo from "react-native-device-info";
|
|
428
433
|
|
|
429
434
|
// package.json
|
|
430
|
-
var version = "3.0.
|
|
435
|
+
var version = "3.0.6";
|
|
431
436
|
|
|
432
437
|
// src/NativeRNKontext.ts
|
|
433
438
|
import { TurboModuleRegistry } from "react-native";
|
|
@@ -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":
|
|
@@ -477,10 +483,10 @@ var getDevice = async () => {
|
|
|
477
483
|
// outputType: Not available without native module
|
|
478
484
|
},
|
|
479
485
|
network: {
|
|
480
|
-
|
|
481
|
-
userAgent: await DeviceInfo.getUserAgent()
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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.
|
|
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
|
|
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.
|
|
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": "
|
|
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,6 +47,7 @@
|
|
|
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",
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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'
|
|
3
10
|
import { Appearance, Dimensions, PixelRatio, Platform } from 'react-native'
|
|
4
11
|
import DeviceInfo, { type DeviceType } from 'react-native-device-info'
|
|
5
12
|
import { version } from '../../package.json'
|
|
@@ -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) {
|
|
@@ -50,10 +58,12 @@ const getDevice = async (): Promise<DeviceConfig> => {
|
|
|
50
58
|
// outputType: Not available without native module
|
|
51
59
|
},
|
|
52
60
|
network: {
|
|
53
|
-
|
|
61
|
+
carrier: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier) || undefined,
|
|
54
62
|
userAgent: await DeviceInfo.getUserAgent(),
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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',
|