@kontextso/sdk-react-native 4.0.0-rc.0 → 4.0.0-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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -4
- package/src/InlineAd.tsx +0 -1
- package/src/utils/sdk.ts +3 -3
- package/src/utils/device.ts +0 -89
- package/src/utils/validation.ts +0 -59
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontextso/sdk-react-native",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "Kontext SDK for React Native",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -51,9 +51,7 @@
|
|
|
51
51
|
"react-native-device-info": ">=10.0.0 <15.0.0",
|
|
52
52
|
"react-native-webview": "^13.10.0"
|
|
53
53
|
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"@kontextso/sdk-utils": "^1.0.0"
|
|
56
|
-
},
|
|
54
|
+
"dependencies": {},
|
|
57
55
|
"files": [
|
|
58
56
|
"dist/*",
|
|
59
57
|
"src",
|
package/src/InlineAd.tsx
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
} from '@kontextso/sdk-common'
|
|
8
8
|
import { Session } from './Session'
|
|
9
9
|
import { useRef, useEffect, useState, useCallback } from 'react'
|
|
10
|
-
import { View } from 'react-native'
|
|
11
10
|
import { WebView, type WebViewMessageEvent } from 'react-native-webview'
|
|
12
11
|
|
|
13
12
|
interface InlineAdProps {
|
package/src/utils/sdk.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { Platform } from '@kontextso/utils/user-agent'
|
|
3
2
|
import type { SDK } from '@kontextso/sdk-common'
|
|
3
|
+
import { Platform } from 'react-native'
|
|
4
4
|
import { version } from '../../package.json'
|
|
5
5
|
|
|
6
6
|
export interface SDKConfig {
|
|
@@ -10,7 +10,7 @@ export interface SDKConfig {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const getSdk = async (): Promise<SDKConfig> => ({
|
|
13
|
-
name: 'sdk-
|
|
14
|
-
platform: Platform.
|
|
13
|
+
name: 'sdk-react-native',
|
|
14
|
+
platform: Platform.OS === 'ios' ? 'ios' : 'android',
|
|
15
15
|
version,
|
|
16
16
|
})
|
package/src/utils/device.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { detectDeviceType, detectOS, parseUserAgent } from '@kontextso/utils/user-agent'
|
|
3
|
-
|
|
4
|
-
interface DeviceHardware {
|
|
5
|
-
type: 'handset' | 'tablet' | 'desktop' | 'tv' | 'other'
|
|
6
|
-
bootTime?: number
|
|
7
|
-
brand?: string
|
|
8
|
-
model?: string
|
|
9
|
-
sdCardAvailable?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface OperatingSystem {
|
|
13
|
-
name: string
|
|
14
|
-
version: string
|
|
15
|
-
locale: string
|
|
16
|
-
timezone: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ScreenInfo {
|
|
20
|
-
darkMode: boolean
|
|
21
|
-
dpr: number
|
|
22
|
-
height: number
|
|
23
|
-
width: number
|
|
24
|
-
orientation?: 'portrait' | 'landscape'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface AudioInfo {
|
|
28
|
-
volume?: number
|
|
29
|
-
muted?: boolean
|
|
30
|
-
outputPluggedIn?: boolean
|
|
31
|
-
outputType?: Array<'wired' | 'hdmi' | 'bluetooth' | 'usb' | 'other'>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface NetworkInfo {
|
|
35
|
-
carrier?: string
|
|
36
|
-
detail?: string
|
|
37
|
-
type?: 'wifi' | 'cellular' | 'ethernet' | 'other'
|
|
38
|
-
userAgent?: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface PowerInfo {
|
|
42
|
-
batteryLevel?: number
|
|
43
|
-
batteryState?: 'charging' | 'full' | 'unplugged' | 'unknown'
|
|
44
|
-
lowPowerMode?: boolean
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface DeviceConfig {
|
|
48
|
-
hardware: DeviceHardware
|
|
49
|
-
os: OperatingSystem
|
|
50
|
-
screen: ScreenInfo
|
|
51
|
-
audio?: AudioInfo
|
|
52
|
-
network?: NetworkInfo
|
|
53
|
-
power?: PowerInfo
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const getDevice = async (): Promise<DeviceConfig> => {
|
|
57
|
-
const userAgent = navigator.userAgent
|
|
58
|
-
const parsedUserAgent = parseUserAgent(userAgent)
|
|
59
|
-
const parsedDevice = parsedUserAgent?.getDevice()
|
|
60
|
-
const parsedOS = parsedUserAgent?.getOS()
|
|
61
|
-
// @ts-expect-error Not in types
|
|
62
|
-
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
network: {
|
|
66
|
-
userAgent,
|
|
67
|
-
detail: connection?.effectiveType,
|
|
68
|
-
type: connection?.type,
|
|
69
|
-
},
|
|
70
|
-
screen: {
|
|
71
|
-
width: screen.width,
|
|
72
|
-
height: screen.height,
|
|
73
|
-
dpr: window.devicePixelRatio || 1,
|
|
74
|
-
orientation: screen.orientation?.type?.includes('portrait') ? 'portrait' : 'landscape',
|
|
75
|
-
darkMode: window.matchMedia?.('(prefers-color-scheme: dark)').matches,
|
|
76
|
-
},
|
|
77
|
-
hardware: {
|
|
78
|
-
type: detectDeviceType(parsedUserAgent),
|
|
79
|
-
brand: parsedDevice?.vendor,
|
|
80
|
-
model: parsedDevice?.model,
|
|
81
|
-
},
|
|
82
|
-
os: {
|
|
83
|
-
name: detectOS(parsedUserAgent),
|
|
84
|
-
version: parsedOS?.version || '',
|
|
85
|
-
locale: navigator.language || 'en-US',
|
|
86
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
87
|
-
},
|
|
88
|
-
}
|
|
89
|
-
}
|
package/src/utils/validation.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { FetchAdParams } from "./interface"
|
|
2
|
-
|
|
3
|
-
const DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
|
|
4
|
-
|
|
5
|
-
export const validateFetchAdSettings = (settings: FetchAdParams) => {
|
|
6
|
-
if (!settings.adServerUrl) {
|
|
7
|
-
throw new Error('Server URL is required.')
|
|
8
|
-
}
|
|
9
|
-
if (!settings.publisherToken) {
|
|
10
|
-
throw new Error('Publisher token is required.')
|
|
11
|
-
}
|
|
12
|
-
if (!settings.conversationId) {
|
|
13
|
-
throw new Error('Conversation ID is required.')
|
|
14
|
-
}
|
|
15
|
-
if (typeof settings.conversationId !== 'string') {
|
|
16
|
-
throw new Error('Conversation ID must be a string.')
|
|
17
|
-
}
|
|
18
|
-
if (!settings.userId) {
|
|
19
|
-
throw new Error('User ID is required.')
|
|
20
|
-
}
|
|
21
|
-
if (typeof settings.userId !== 'string') {
|
|
22
|
-
throw new Error('User ID must be a string.')
|
|
23
|
-
}
|
|
24
|
-
if (!settings.enabledPlacementCodes || !Array.isArray(settings.enabledPlacementCodes) || settings.enabledPlacementCodes.length === 0) {
|
|
25
|
-
throw new Error('Placement code is required.')
|
|
26
|
-
}
|
|
27
|
-
if (!settings.messages || !Array.isArray(settings.messages) || settings.messages.length === 0) {
|
|
28
|
-
throw new Error('Messages are required.')
|
|
29
|
-
}
|
|
30
|
-
settings.messages.forEach((message: any) => {
|
|
31
|
-
if (!message.id) {
|
|
32
|
-
throw new Error('Message ID is required.')
|
|
33
|
-
}
|
|
34
|
-
if (typeof message.id !== 'string') {
|
|
35
|
-
throw new Error('Message ID must be a string.')
|
|
36
|
-
}
|
|
37
|
-
if (!message.content) {
|
|
38
|
-
throw new Error('Message content is required.')
|
|
39
|
-
}
|
|
40
|
-
if (!message.createdAt) {
|
|
41
|
-
throw new Error('Message createdAt is required.')
|
|
42
|
-
}
|
|
43
|
-
if (typeof message.createdAt !== 'string' && !(message.createdAt instanceof Date)) {
|
|
44
|
-
throw new Error('Message createdAt must be string or Date object.')
|
|
45
|
-
}
|
|
46
|
-
if (typeof message.createdAt === 'string' && !DATE_REGEX.test(message.createdAt)) {
|
|
47
|
-
throw new Error('Message createdAt must be a valid ISO 8601 date string.')
|
|
48
|
-
}
|
|
49
|
-
if (message.createdAt instanceof Date && Number.isNaN(message.createdAt.getTime())) {
|
|
50
|
-
throw new Error('Message createdAt must be a valid Date object.')
|
|
51
|
-
}
|
|
52
|
-
if (!message.role) {
|
|
53
|
-
throw new Error('Message role is required.')
|
|
54
|
-
}
|
|
55
|
-
if (message.role !== 'assistant' && message.role !== 'user') {
|
|
56
|
-
throw new Error('Message role must be either "assistant" or "user".')
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|