@kontextso/sdk-react-native 3.3.0-rc.6 → 3.3.0

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.mjs CHANGED
@@ -1,48 +1,57 @@
1
1
  // ../sdk-common/dist/index.mjs
2
2
  function makeIframeMessage(type, opts) {
3
- const { data, code, component } = opts
4
- const message = { type, data: { ...(data || {}), code, component } }
5
- return message
3
+ const { data, code, component } = opts;
4
+ const message = { type, data: { ...data || {}, code, component } };
5
+ return message;
6
6
  }
7
7
  function handleIframeMessage(handler, opts) {
8
- const { origin, code, component } = opts
8
+ const { origin, code, component } = opts;
9
9
  return (event) => {
10
- var _a, _b
11
- if (origin && event.origin !== origin) return
12
- const eventCode = (_a = event.data.data) == null ? void 0 : _a.code
13
- if (eventCode && code && eventCode !== code) return
14
- const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component
15
- if (eventComponent && component && eventComponent !== component) return
16
- handler(event.data)
17
- }
10
+ var _a, _b;
11
+ if (origin && event.origin !== origin) return;
12
+ const eventCode = (_a = event.data.data) == null ? void 0 : _a.code;
13
+ if (eventCode && code && eventCode !== code) return;
14
+ const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component;
15
+ if (eventComponent && component && eventComponent !== component) return;
16
+ handler(event.data);
17
+ };
18
18
  }
19
19
 
20
20
  // src/formats/Format.tsx
21
- import { AdsContext, convertParamsToString, ErrorBoundary, useBid, useIframeUrl } from '@kontextso/sdk-react'
22
- import { useContext, useEffect, useRef, useState } from 'react'
23
- import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-native'
21
+ import {
22
+ AdsContext,
23
+ convertParamsToString,
24
+ ErrorBoundary,
25
+ useBid,
26
+ useIframeUrl
27
+ } from "@kontextso/sdk-react";
28
+ import { useContext, useEffect, useRef, useState } from "react";
29
+ import { Keyboard, Linking, Modal, useWindowDimensions, View } from "react-native";
24
30
 
25
31
  // src/frame-webview.tsx
26
- import { forwardRef } from 'react'
27
- import { WebView } from 'react-native-webview'
28
- import { jsx } from 'react/jsx-runtime'
29
- var FrameWebView = forwardRef(({ iframeUrl, onMessage, style, onError, onLoad }, forwardedRef) => {
30
- return /* @__PURE__ */ jsx(WebView, {
31
- ref: forwardedRef,
32
- source: {
33
- uri: iframeUrl,
34
- },
35
- onMessage,
36
- style,
37
- allowsInlineMediaPlayback: true,
38
- mediaPlaybackRequiresUserAction: false,
39
- javaScriptEnabled: true,
40
- domStorageEnabled: true,
41
- allowsFullscreenVideo: false,
42
- originWhitelist: ['*'],
43
- sharedCookiesEnabled: true,
44
- thirdPartyCookiesEnabled: true,
45
- injectedJavaScript: `
32
+ import { forwardRef } from "react";
33
+ import { WebView } from "react-native-webview";
34
+ import { jsx } from "react/jsx-runtime";
35
+ var FrameWebView = forwardRef(
36
+ ({ iframeUrl, onMessage, style, onError, onLoad }, forwardedRef) => {
37
+ return /* @__PURE__ */ jsx(
38
+ WebView,
39
+ {
40
+ ref: forwardedRef,
41
+ source: {
42
+ uri: iframeUrl
43
+ },
44
+ onMessage,
45
+ style,
46
+ allowsInlineMediaPlayback: true,
47
+ mediaPlaybackRequiresUserAction: false,
48
+ javaScriptEnabled: true,
49
+ domStorageEnabled: true,
50
+ allowsFullscreenVideo: false,
51
+ originWhitelist: ["*"],
52
+ sharedCookiesEnabled: true,
53
+ thirdPartyCookiesEnabled: true,
54
+ injectedJavaScript: `
46
55
  window.addEventListener("message", function(event) {
47
56
  if (window.ReactNativeWebView && event.data) {
48
57
  // ReactNativeWebView.postMessage only supports string data
@@ -50,133 +59,135 @@ var FrameWebView = forwardRef(({ iframeUrl, onMessage, style, onError, onLoad },
50
59
  }
51
60
  }, false);
52
61
  `,
53
- onError,
54
- onLoad,
55
- })
56
- })
57
- var frame_webview_default = FrameWebView
62
+ onError,
63
+ onLoad
64
+ }
65
+ );
66
+ }
67
+ );
68
+ var frame_webview_default = FrameWebView;
58
69
 
59
70
  // src/services/SkOverlay.ts
60
- import { Platform } from 'react-native'
71
+ import { Platform } from "react-native";
61
72
 
62
73
  // src/NativeRNKontext.ts
63
- import { TurboModuleRegistry } from 'react-native'
64
- var NativeRNKontext_default = TurboModuleRegistry.getEnforcing('RNKontext')
74
+ import { TurboModuleRegistry } from "react-native";
75
+ var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
65
76
 
66
77
  // src/services/utils.ts
67
78
  var isValidAppStoreId = (id) => {
68
- return typeof id === 'string' && /^\d+$/.test(id)
69
- }
79
+ return typeof id === "string" && /^\d+$/.test(id);
80
+ };
70
81
 
71
82
  // src/services/SkOverlay.ts
72
83
  var isValidPosition = (p) => {
73
- return p === 'bottom' || p === 'bottomRaised'
74
- }
84
+ return p === "bottom" || p === "bottomRaised";
85
+ };
75
86
  async function presentSKOverlay(params) {
76
- if (Platform.OS !== 'ios') {
77
- return false
87
+ if (Platform.OS !== "ios") {
88
+ return false;
78
89
  }
79
- let { appStoreId, position, dismissible } = params
90
+ let { appStoreId, position, dismissible } = params;
80
91
  if (!isValidAppStoreId(appStoreId)) {
81
- return false
92
+ return false;
82
93
  }
83
94
  if (!isValidPosition(position)) {
84
- position = 'bottom'
95
+ position = "bottom";
85
96
  }
86
- if (typeof dismissible !== 'boolean') {
87
- dismissible = Boolean(dismissible)
97
+ if (typeof dismissible !== "boolean") {
98
+ dismissible = Boolean(dismissible);
88
99
  }
89
- return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible)
100
+ return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible);
90
101
  }
91
102
  async function dismissSKOverlay() {
92
- if (Platform.OS !== 'ios') {
93
- return false
103
+ if (Platform.OS !== "ios") {
104
+ return false;
94
105
  }
95
- return NativeRNKontext_default.dismissSKOverlay()
106
+ return NativeRNKontext_default.dismissSKOverlay();
96
107
  }
97
108
 
98
109
  // src/services/SkStoreProduct.ts
99
- import { Platform as Platform2 } from 'react-native'
110
+ import { Platform as Platform2 } from "react-native";
100
111
  async function presentSKStoreProduct(appStoreId) {
101
- if (Platform2.OS !== 'ios') {
102
- return false
112
+ if (Platform2.OS !== "ios") {
113
+ return false;
103
114
  }
104
115
  if (!isValidAppStoreId(appStoreId)) {
105
- return false
116
+ return false;
106
117
  }
107
- return NativeRNKontext_default.presentSKStoreProduct(appStoreId)
118
+ return NativeRNKontext_default.presentSKStoreProduct(appStoreId);
108
119
  }
109
120
  async function dismissSKStoreProduct() {
110
- if (Platform2.OS !== 'ios') {
111
- return false
121
+ if (Platform2.OS !== "ios") {
122
+ return false;
112
123
  }
113
- return NativeRNKontext_default.dismissSKStoreProduct()
124
+ return NativeRNKontext_default.dismissSKStoreProduct();
114
125
  }
115
126
 
116
127
  // src/formats/Format.tsx
117
- import { Fragment, jsx as jsx2, jsxs } from 'react/jsx-runtime'
128
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
118
129
  var sendMessage = (webViewRef, type, code, data) => {
119
130
  const message = makeIframeMessage(type, {
120
131
  data,
121
- code,
122
- })
132
+ code
133
+ });
123
134
  webViewRef.current?.injectJavaScript(`
124
135
  window.dispatchEvent(new MessageEvent('message', {
125
136
  data: ${JSON.stringify(message)}
126
137
  }));
127
- `)
128
- }
138
+ `);
139
+ };
129
140
  var getCachedContent = (context, bidId) => {
130
141
  if (!bidId) {
131
- return null
142
+ return null;
132
143
  }
133
- return context?.cachedContentRef?.current?.get(bidId) ?? null
134
- }
144
+ return context?.cachedContentRef?.current?.get(bidId) ?? null;
145
+ };
135
146
  var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
136
- const context = useContext(AdsContext)
137
- const bid = useBid({ code, messageId })
138
- const [height, setHeight] = useState(0)
139
- const cachedContent = getCachedContent(context, bid?.bidId)
140
- const iframeUrl = useIframeUrl(bid, code, messageId, 'sdk-react-native', otherParams.theme, cachedContent)
141
- const modalUrl = iframeUrl.replace('/api/frame/', '/api/modal/')
142
- const [showIframe, setShowIframe] = useState(false)
143
- const [iframeLoaded, setIframeLoaded] = useState(false)
144
- const [modalOpen, setModalOpen] = useState(false)
145
- const [modalShown, setModalShown] = useState(false)
146
- const [modalLoaded, setModalLoaded] = useState(false)
147
- const [containerStyles, setContainerStyles] = useState({})
148
- const [iframeStyles, setIframeStyles] = useState({})
149
- const containerRef = useRef(null)
150
- const webViewRef = useRef(null)
151
- const modalWebViewRef = useRef(null)
152
- const messageStatusRef = useRef('none' /* None */)
153
- const modalInitTimeoutRef = useRef(null)
154
- const isModalInitRef = useRef(false)
155
- const { height: windowHeight, width: windowWidth } = useWindowDimensions()
156
- const keyboardHeightRef = useRef(0)
157
- const isAdViewVisible = showIframe && iframeLoaded
147
+ const context = useContext(AdsContext);
148
+ const bid = useBid({ code, messageId });
149
+ const [height, setHeight] = useState(0);
150
+ const cachedContent = getCachedContent(context, bid?.bidId);
151
+ const iframeUrl = useIframeUrl(bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
152
+ const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
153
+ const [showIframe, setShowIframe] = useState(false);
154
+ const [iframeLoaded, setIframeLoaded] = useState(false);
155
+ const [modalOpen, setModalOpen] = useState(false);
156
+ const [modalShown, setModalShown] = useState(false);
157
+ const [modalLoaded, setModalLoaded] = useState(false);
158
+ const [containerStyles, setContainerStyles] = useState({});
159
+ const [iframeStyles, setIframeStyles] = useState({});
160
+ const containerRef = useRef(null);
161
+ const webViewRef = useRef(null);
162
+ const modalWebViewRef = useRef(null);
163
+ const messageStatusRef = useRef("none" /* None */);
164
+ const modalInitTimeoutRef = useRef(null);
165
+ const isModalInitRef = useRef(false);
166
+ const { height: windowHeight, width: windowWidth } = useWindowDimensions();
167
+ const keyboardHeightRef = useRef(0);
168
+ const isAdViewVisible = showIframe && iframeLoaded;
158
169
  const reset = () => {
159
- setHeight(0)
160
- setShowIframe(false)
161
- setContainerStyles({})
162
- setIframeStyles({})
163
- setIframeLoaded(false)
164
- resetModal()
165
- context?.resetAll()
166
- context?.captureError(new Error('Processing iframe error'))
167
- }
170
+ setHeight(0);
171
+ setShowIframe(false);
172
+ setContainerStyles({});
173
+ setIframeStyles({});
174
+ setIframeLoaded(false);
175
+ resetModal();
176
+ context?.resetAll();
177
+ context?.captureError(new Error("Processing iframe error"));
178
+ };
168
179
  const resetModal = () => {
169
180
  if (modalInitTimeoutRef.current) {
170
- clearTimeout(modalInitTimeoutRef.current)
171
- modalInitTimeoutRef.current = null
181
+ clearTimeout(modalInitTimeoutRef.current);
182
+ modalInitTimeoutRef.current = null;
172
183
  }
173
- isModalInitRef.current = false
174
- closeSkOverlay()
175
- closeSkStoreProduct()
176
- setModalOpen(false)
177
- setModalLoaded(false)
178
- setModalShown(false)
179
- }
184
+ isModalInitRef.current = false;
185
+ closeSkOverlay();
186
+ closeSkStoreProduct();
187
+ setModalOpen(false);
188
+ setModalLoaded(false);
189
+ setModalShown(false);
190
+ };
180
191
  const debug = (name, data = {}) => {
181
192
  context?.onDebugEventInternal?.(name, {
182
193
  code,
@@ -189,9 +200,9 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
189
200
  height,
190
201
  containerStyles,
191
202
  iframeStyles,
192
- ...data,
193
- })
194
- }
203
+ ...data
204
+ });
205
+ };
195
206
  const debugModal = (name, data = {}) => {
196
207
  context?.onDebugEventInternal?.(name, {
197
208
  code,
@@ -202,522 +213,546 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
202
213
  modalOpen,
203
214
  modalShown,
204
215
  modalLoaded,
205
- ...data,
206
- })
207
- }
216
+ ...data
217
+ });
218
+ };
208
219
  const openSkOverlay = async (appStoreId, position, dismissible) => {
209
220
  try {
210
- if (!(await presentSKOverlay({ appStoreId, position, dismissible }))) {
211
- return
221
+ if (!await presentSKOverlay({ appStoreId, position, dismissible })) {
222
+ return;
212
223
  }
213
- sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
214
- open: true,
215
- })
224
+ sendMessage(webViewRef, "update-skoverlay-iframe", code, {
225
+ open: true
226
+ });
216
227
  } catch (e) {
217
- debug('error-open-skoverlay-iframe', {
218
- error: e,
219
- })
220
- console.error('error opening sk overlay', e)
228
+ debug("error-open-skoverlay-iframe", {
229
+ error: e
230
+ });
231
+ console.error("error opening sk overlay", e);
221
232
  }
222
- }
233
+ };
223
234
  const closeSkOverlay = async () => {
224
235
  try {
225
- if (!(await dismissSKOverlay())) {
226
- return
236
+ if (!await dismissSKOverlay()) {
237
+ return;
227
238
  }
228
- sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
229
- open: false,
230
- })
239
+ sendMessage(webViewRef, "update-skoverlay-iframe", code, {
240
+ open: false
241
+ });
231
242
  } catch (e) {
232
- debug('error-dismiss-skoverlay-iframe', {
233
- error: e,
234
- })
235
- console.error('error dismissing sk overlay', e)
243
+ debug("error-dismiss-skoverlay-iframe", {
244
+ error: e
245
+ });
246
+ console.error("error dismissing sk overlay", e);
236
247
  }
237
- }
248
+ };
238
249
  const openSkStoreProduct = async (appStoreId) => {
239
250
  try {
240
- if (!(await presentSKStoreProduct(appStoreId))) {
241
- return false
251
+ if (!await presentSKStoreProduct(appStoreId)) {
252
+ return false;
242
253
  }
243
- sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
244
- open: true,
245
- })
246
- return true
254
+ sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
255
+ open: true
256
+ });
257
+ return true;
247
258
  } catch (e) {
248
- debug('error-open-skstoreproduct-iframe', {
249
- error: e,
250
- })
251
- console.error('error opening sk store product', e)
252
- return false
259
+ debug("error-open-skstoreproduct-iframe", {
260
+ error: e
261
+ });
262
+ console.error("error opening sk store product", e);
263
+ return false;
253
264
  }
254
- }
265
+ };
255
266
  const closeSkStoreProduct = async () => {
256
267
  try {
257
- if (!(await dismissSKStoreProduct())) {
258
- return false
268
+ if (!await dismissSKStoreProduct()) {
269
+ return false;
259
270
  }
260
- sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
261
- open: false,
262
- })
263
- return true
271
+ sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
272
+ open: false
273
+ });
274
+ return true;
264
275
  } catch (e) {
265
- debug('error-close-skstoreproduct-iframe', {
266
- error: e,
267
- })
268
- console.error('error closing sk store product', e)
269
- return false
276
+ debug("error-close-skstoreproduct-iframe", {
277
+ error: e
278
+ });
279
+ console.error("error closing sk store product", e);
280
+ return false;
270
281
  }
271
- }
282
+ };
272
283
  const openUrl = async (message) => {
273
284
  if (!message.data.url) {
274
- return
285
+ return;
275
286
  }
276
287
  try {
277
- await Linking.openURL(`${context?.adServerUrl}${message.data.url}`)
288
+ await Linking.openURL(`${context?.adServerUrl}${message.data.url}`);
278
289
  } catch (e) {
279
- console.error('error opening url', e)
290
+ console.error("error opening url", e);
280
291
  }
281
- }
292
+ };
282
293
  const handleClick = async (message) => {
283
294
  if (message.data.appStoreId) {
284
295
  try {
285
- if (!(await openSkStoreProduct(message.data.appStoreId))) {
286
- await openUrl(message)
296
+ if (!await openSkStoreProduct(message.data.appStoreId)) {
297
+ await openUrl(message);
287
298
  }
288
299
  } catch (e) {
289
- console.error('error opening sk store product', e)
290
- await openUrl(message)
300
+ console.error("error opening sk store product", e);
301
+ await openUrl(message);
291
302
  }
292
303
  } else {
293
- await openUrl(message)
304
+ await openUrl(message);
294
305
  }
295
- context?.onAdClickInternal(message.data)
296
- }
297
- debug('format-update-state')
306
+ context?.onAdClickInternal(message.data);
307
+ };
308
+ debug("format-update-state");
298
309
  const onMessage = (event) => {
299
310
  try {
300
- const data = JSON.parse(event.nativeEvent.data)
301
- debug('iframe-message', {
302
- message: data,
303
- })
311
+ const data = JSON.parse(event.nativeEvent.data);
312
+ debug("iframe-message", {
313
+ message: data
314
+ });
304
315
  const messageHandler = handleIframeMessage(
305
316
  (message) => {
306
317
  switch (message.type) {
307
- case 'init-iframe':
308
- setIframeLoaded(true)
309
- debug('iframe-post-message')
310
- messageStatusRef.current = 'message-received' /* MessageReceived */
311
- sendMessage(webViewRef, 'update-iframe', code, {
318
+ case "init-iframe":
319
+ setIframeLoaded(true);
320
+ debug("iframe-post-message");
321
+ messageStatusRef.current = "message-received" /* MessageReceived */;
322
+ sendMessage(webViewRef, "update-iframe", code, {
312
323
  messages: context?.messages,
313
- sdk: 'sdk-react-native',
324
+ sdk: "sdk-react-native",
314
325
  otherParams,
315
- messageId,
316
- })
317
- break
318
- case 'error-iframe':
319
- reset()
320
- break
321
- case 'resize-iframe':
322
- setHeight(message.data.height)
323
- break
324
- case 'click-iframe':
325
- handleClick(message)
326
- break
327
- case 'view-iframe':
328
- context?.onAdViewInternal(message.data)
329
- break
330
- case 'ad-done-iframe':
326
+ messageId
327
+ });
328
+ break;
329
+ case "error-iframe":
330
+ reset();
331
+ break;
332
+ case "resize-iframe":
333
+ setHeight(message.data.height);
334
+ break;
335
+ case "click-iframe":
336
+ handleClick(message);
337
+ break;
338
+ case "view-iframe":
339
+ context?.onAdViewInternal(message.data);
340
+ break;
341
+ case "ad-done-iframe":
331
342
  if (bid?.bidId && message.data.cachedContent) {
332
- context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent)
343
+ context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent);
333
344
  }
334
- break
335
- case 'show-iframe':
336
- setShowIframe(true)
337
- break
338
- case 'hide-iframe':
339
- setShowIframe(false)
340
- break
341
- case 'set-styles-iframe':
342
- setContainerStyles(message.data.containerStyles)
343
- setIframeStyles(message.data.iframeStyles)
344
- break
345
- case 'open-component-iframe':
346
- setModalOpen(true)
345
+ break;
346
+ case "show-iframe":
347
+ setShowIframe(true);
348
+ break;
349
+ case "hide-iframe":
350
+ setShowIframe(false);
351
+ break;
352
+ case "set-styles-iframe":
353
+ setContainerStyles(message.data.containerStyles);
354
+ setIframeStyles(message.data.iframeStyles);
355
+ break;
356
+ case "open-component-iframe":
357
+ setModalOpen(true);
347
358
  modalInitTimeoutRef.current = setTimeout(() => {
348
359
  if (!isModalInitRef.current) {
349
- resetModal()
360
+ resetModal();
350
361
  }
351
- }, message.data.timeout ?? 5e3)
352
- break
353
- case 'event-iframe':
354
- onEvent?.(message.data)
355
- context?.onAdEventInternal(message.data)
356
- messageStatusRef.current = 'message-received' /* MessageReceived */
357
- break
358
- case 'open-skoverlay-iframe':
359
- openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
360
- break
361
- case 'close-skoverlay-iframe':
362
- closeSkOverlay()
363
- break
364
- case 'open-skstoreproduct-iframe':
365
- openSkStoreProduct(message.data.appStoreId)
366
- break
367
- case 'close-skstoreproduct-iframe':
368
- closeSkStoreProduct()
369
- break
362
+ }, message.data.timeout ?? 5e3);
363
+ break;
364
+ case "event-iframe":
365
+ onEvent?.(message.data);
366
+ context?.onAdEventInternal(message.data);
367
+ messageStatusRef.current = "message-received" /* MessageReceived */;
368
+ break;
369
+ case "open-skoverlay-iframe":
370
+ openSkOverlay(
371
+ message.data.appStoreId,
372
+ message.data.position,
373
+ message.data.dismissible
374
+ );
375
+ break;
376
+ case "close-skoverlay-iframe":
377
+ closeSkOverlay();
378
+ break;
379
+ case "open-skstoreproduct-iframe":
380
+ openSkStoreProduct(message.data.appStoreId);
381
+ break;
382
+ case "close-skstoreproduct-iframe":
383
+ closeSkStoreProduct();
384
+ break;
370
385
  }
371
386
  },
372
387
  {
373
- code,
388
+ code
374
389
  }
375
- )
376
- messageHandler({ data })
390
+ );
391
+ messageHandler({ data });
377
392
  } catch (e) {
378
- debug('iframe-message-error', {
379
- error: e,
380
- })
381
- console.error('error parsing message from webview', e)
382
- reset()
393
+ debug("iframe-message-error", {
394
+ error: e
395
+ });
396
+ console.error("error parsing message from webview", e);
397
+ reset();
383
398
  }
384
- }
399
+ };
385
400
  const onModalMessage = (event) => {
386
401
  try {
387
- const data = JSON.parse(event.nativeEvent.data)
388
- debugModal('modal-iframe-message', {
389
- message: data,
390
- })
402
+ const data = JSON.parse(event.nativeEvent.data);
403
+ debugModal("modal-iframe-message", {
404
+ message: data
405
+ });
391
406
  const messageHandler = handleIframeMessage(
392
407
  (message) => {
393
408
  switch (message.type) {
394
- case 'close-component-iframe':
395
- resetModal()
396
- break
397
- case 'init-component-iframe':
398
- isModalInitRef.current = true
409
+ case "close-component-iframe":
410
+ resetModal();
411
+ break;
412
+ case "init-component-iframe":
413
+ isModalInitRef.current = true;
399
414
  if (modalInitTimeoutRef.current) {
400
- clearTimeout(modalInitTimeoutRef.current)
401
- modalInitTimeoutRef.current = null
415
+ clearTimeout(modalInitTimeoutRef.current);
416
+ modalInitTimeoutRef.current = null;
402
417
  }
403
- setModalShown(true)
404
- break
405
- case 'error-component-iframe':
406
- case 'error-iframe':
407
- resetModal()
408
- context?.captureError(new Error('Processing modal iframe error'))
409
- break
410
- case 'open-skoverlay-iframe':
411
- openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
412
- break
413
- case 'close-skoverlay-iframe':
414
- closeSkOverlay()
415
- break
416
- case 'click-iframe':
417
- handleClick(message)
418
- break
419
- case 'event-iframe':
420
- onEvent?.(message.data)
421
- context?.onAdEventInternal(message.data)
422
- break
423
- case 'open-skstoreproduct-iframe':
424
- openSkStoreProduct(message.data.appStoreId)
425
- break
426
- case 'close-skstoreproduct-iframe':
427
- closeSkStoreProduct()
428
- break
418
+ setModalShown(true);
419
+ break;
420
+ case "error-component-iframe":
421
+ case "error-iframe":
422
+ resetModal();
423
+ context?.captureError(new Error("Processing modal iframe error"));
424
+ break;
425
+ case "open-skoverlay-iframe":
426
+ openSkOverlay(
427
+ message.data.appStoreId,
428
+ message.data.position,
429
+ message.data.dismissible
430
+ );
431
+ break;
432
+ case "close-skoverlay-iframe":
433
+ closeSkOverlay();
434
+ break;
435
+ case "click-iframe":
436
+ handleClick(message);
437
+ break;
438
+ case "event-iframe":
439
+ onEvent?.(message.data);
440
+ context?.onAdEventInternal(message.data);
441
+ break;
442
+ case "open-skstoreproduct-iframe":
443
+ openSkStoreProduct(message.data.appStoreId);
444
+ break;
445
+ case "close-skstoreproduct-iframe":
446
+ closeSkStoreProduct();
447
+ break;
429
448
  }
430
449
  },
431
450
  {
432
451
  code,
433
- component: 'modal',
452
+ component: "modal"
434
453
  }
435
- )
436
- messageHandler({ data })
454
+ );
455
+ messageHandler({ data });
437
456
  } catch (e) {
438
- debugModal('modal-iframe-message-error', {
439
- error: e,
440
- })
441
- console.error('error parsing message from webview', e)
442
- resetModal()
457
+ debugModal("modal-iframe-message-error", {
458
+ error: e
459
+ });
460
+ console.error("error parsing message from webview", e);
461
+ resetModal();
443
462
  }
444
- }
463
+ };
445
464
  useEffect(() => {
446
465
  const interval = setInterval(() => {
447
- if (messageStatusRef.current === 'none' /* None */) {
448
- return
466
+ if (messageStatusRef.current === "none" /* None */) {
467
+ return;
449
468
  }
450
- if (messageStatusRef.current === 'message-received' /* MessageReceived */) {
451
- clearInterval(interval)
452
- return
469
+ if (messageStatusRef.current === "message-received" /* MessageReceived */) {
470
+ clearInterval(interval);
471
+ return;
453
472
  }
454
- debug('iframe-post-message-use-effect')
455
- setIframeLoaded(true)
456
- sendMessage(webViewRef, 'update-iframe', code, {
473
+ debug("iframe-post-message-use-effect");
474
+ setIframeLoaded(true);
475
+ sendMessage(webViewRef, "update-iframe", code, {
457
476
  messages: context?.messages,
458
- sdk: 'sdk-react-native',
477
+ sdk: "sdk-react-native",
459
478
  otherParams: {
460
479
  ...otherParams,
461
- _useEffect: true,
480
+ _useEffect: true
462
481
  },
463
- messageId,
464
- })
465
- }, 500)
482
+ messageId
483
+ });
484
+ }, 500);
466
485
  return () => {
467
- clearInterval(interval)
468
- }
469
- }, [])
470
- const paramsString = convertParamsToString(otherParams)
486
+ clearInterval(interval);
487
+ };
488
+ }, []);
489
+ const paramsString = convertParamsToString(otherParams);
471
490
  useEffect(() => {
472
491
  if (!iframeLoaded || !context?.adServerUrl || !bid || !webViewRef.current) {
473
- return
492
+ return;
474
493
  }
475
- debug('iframe-post-message')
476
- sendMessage(webViewRef, 'update-iframe', code, {
494
+ debug("iframe-post-message");
495
+ sendMessage(webViewRef, "update-iframe", code, {
477
496
  data: { otherParams },
478
- code,
479
- })
480
- }, [paramsString, iframeLoaded, context?.adServerUrl, bid, code])
497
+ code
498
+ });
499
+ }, [paramsString, iframeLoaded, context?.adServerUrl, bid, code]);
481
500
  const checkIfInViewport = () => {
482
- if (!containerRef.current) return
501
+ if (!containerRef.current) return;
483
502
  containerRef.current.measureInWindow((containerX, containerY, containerWidth, containerHeight) => {
484
- sendMessage(webViewRef, 'update-dimensions-iframe', code, {
503
+ sendMessage(webViewRef, "update-dimensions-iframe", code, {
485
504
  windowWidth,
486
505
  windowHeight,
487
506
  containerWidth,
488
507
  containerHeight,
489
508
  containerX,
490
509
  containerY,
491
- keyboardHeight: keyboardHeightRef.current,
492
- })
493
- })
494
- }
510
+ keyboardHeight: keyboardHeightRef.current
511
+ });
512
+ });
513
+ };
495
514
  useEffect(() => {
496
- if (!isAdViewVisible) return
515
+ if (!isAdViewVisible) return;
497
516
  const interval = setInterval(() => {
498
- checkIfInViewport()
499
- }, 250)
500
- return () => clearInterval(interval)
501
- }, [isAdViewVisible])
517
+ checkIfInViewport();
518
+ }, 250);
519
+ return () => clearInterval(interval);
520
+ }, [isAdViewVisible]);
502
521
  useEffect(() => {
503
- const showSubscription = Keyboard.addListener('keyboardDidShow', (e) => {
504
- keyboardHeightRef.current = e?.endCoordinates?.height ?? 0
505
- })
506
- const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {
507
- keyboardHeightRef.current = 0
508
- })
522
+ const showSubscription = Keyboard.addListener("keyboardDidShow", (e) => {
523
+ keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
524
+ });
525
+ const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
526
+ keyboardHeightRef.current = 0;
527
+ });
509
528
  return () => {
510
- showSubscription.remove()
511
- hideSubscription.remove()
512
- keyboardHeightRef.current = 0
513
- }
514
- }, [])
529
+ showSubscription.remove();
530
+ hideSubscription.remove();
531
+ keyboardHeightRef.current = 0;
532
+ };
533
+ }, []);
515
534
  if (!context || !bid || !iframeUrl) {
516
- return null
535
+ return null;
517
536
  }
518
- const inlineContent = /* @__PURE__ */ jsx2(frame_webview_default, {
519
- ref: webViewRef,
520
- iframeUrl,
521
- onMessage,
522
- style: {
523
- height,
524
- width: '100%',
525
- backgroundColor: 'transparent',
526
- borderWidth: 0,
527
- ...iframeStyles,
528
- },
529
- onError: () => {
530
- debug('iframe-error')
531
- reset()
532
- },
533
- onLoad: () => {
534
- debug('iframe-load')
535
- messageStatusRef.current = 'initialized' /* Initialized */
536
- },
537
- })
538
- const interstitialContent = /* @__PURE__ */ jsx2(Modal, {
539
- visible: modalOpen,
540
- transparent: true,
541
- onRequestClose: resetModal,
542
- animationType: 'slide',
543
- statusBarTranslucent: true,
544
- children: /* @__PURE__ */ jsx2(View, {
537
+ const inlineContent = /* @__PURE__ */ jsx2(
538
+ frame_webview_default,
539
+ {
540
+ ref: webViewRef,
541
+ iframeUrl,
542
+ onMessage,
545
543
  style: {
546
- flex: 1,
547
- // Don't show the modal until the modal page is loaded and sends 'init-component-iframe' message back to SDK
548
- ...(modalShown ? { opacity: 1, pointerEvents: 'auto' } : { opacity: 0, pointerEvents: 'none' }),
544
+ height,
545
+ width: "100%",
546
+ backgroundColor: "transparent",
547
+ borderWidth: 0,
548
+ ...iframeStyles
549
549
  },
550
- children: /* @__PURE__ */ jsx2(frame_webview_default, {
551
- ref: modalWebViewRef,
552
- iframeUrl: modalUrl,
553
- onMessage: onModalMessage,
554
- style: {
555
- backgroundColor: 'transparent',
556
- height: '100%',
557
- width: '100%',
558
- borderWidth: 0,
559
- },
560
- onError: () => {
561
- debug('modal-error')
562
- resetModal()
563
- },
564
- onLoad: () => {
565
- debug('modal-load')
566
- setModalLoaded(true)
550
+ onError: () => {
551
+ debug("iframe-error");
552
+ reset();
553
+ },
554
+ onLoad: () => {
555
+ debug("iframe-load");
556
+ messageStatusRef.current = "initialized" /* Initialized */;
557
+ }
558
+ }
559
+ );
560
+ const interstitialContent = /* @__PURE__ */ jsx2(
561
+ Modal,
562
+ {
563
+ visible: modalOpen,
564
+ transparent: true,
565
+ onRequestClose: resetModal,
566
+ animationType: "slide",
567
+ statusBarTranslucent: true,
568
+ children: /* @__PURE__ */ jsx2(
569
+ View,
570
+ {
571
+ style: {
572
+ flex: 1,
573
+ // Don't show the modal until the modal page is loaded and sends 'init-component-iframe' message back to SDK
574
+ ...modalShown ? { opacity: 1, pointerEvents: "auto" } : { opacity: 0, pointerEvents: "none" }
575
+ },
576
+ children: /* @__PURE__ */ jsx2(
577
+ frame_webview_default,
578
+ {
579
+ ref: modalWebViewRef,
580
+ iframeUrl: modalUrl,
581
+ onMessage: onModalMessage,
582
+ style: {
583
+ backgroundColor: "transparent",
584
+ height: "100%",
585
+ width: "100%",
586
+ borderWidth: 0
587
+ },
588
+ onError: () => {
589
+ debug("modal-error");
590
+ resetModal();
591
+ },
592
+ onLoad: () => {
593
+ debug("modal-load");
594
+ setModalLoaded(true);
595
+ }
596
+ }
597
+ )
598
+ }
599
+ )
600
+ }
601
+ );
602
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
603
+ /* @__PURE__ */ jsx2(
604
+ View,
605
+ {
606
+ style: isAdViewVisible ? containerStyles : {
607
+ height: 0,
608
+ overflow: "hidden"
567
609
  },
568
- }),
569
- }),
570
- })
571
- return /* @__PURE__ */ jsxs(Fragment, {
572
- children: [
573
- /* @__PURE__ */ jsx2(View, {
574
- style: isAdViewVisible
575
- ? containerStyles
576
- : {
577
- height: 0,
578
- overflow: 'hidden',
579
- },
580
610
  ref: containerRef,
581
- children: wrapper ? wrapper(inlineContent) : inlineContent,
582
- }),
583
- interstitialContent,
584
- ],
585
- })
586
- }
587
- var FormatWithErrorBoundary = (props) =>
588
- /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(Format, { ...props }) })
589
- var Format_default = FormatWithErrorBoundary
611
+ children: wrapper ? wrapper(inlineContent) : inlineContent
612
+ }
613
+ ),
614
+ interstitialContent
615
+ ] });
616
+ };
617
+ var FormatWithErrorBoundary = (props) => /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(Format, { ...props }) });
618
+ var Format_default = FormatWithErrorBoundary;
590
619
 
591
620
  // src/formats/InlineAd.tsx
592
- import { jsx as jsx3 } from 'react/jsx-runtime'
621
+ import { jsx as jsx3 } from "react/jsx-runtime";
593
622
  var InlineAd = ({ code, messageId, wrapper, ...props }) => {
594
- return /* @__PURE__ */ jsx3(Format_default, { code, messageId, wrapper, ...props })
595
- }
596
- var InlineAd_default = InlineAd
623
+ return /* @__PURE__ */ jsx3(Format_default, { code, messageId, wrapper, ...props });
624
+ };
625
+ var InlineAd_default = InlineAd;
597
626
 
598
627
  // src/context/AdsProvider.tsx
599
- import { AdsProviderInternal, log } from '@kontextso/sdk-react'
600
- import { fetch as fetchNetworkInfo, NetInfoStateType } from '@react-native-community/netinfo'
601
- import { Appearance, Dimensions, PixelRatio, Platform as Platform3 } from 'react-native'
602
- import DeviceInfo from 'react-native-device-info'
628
+ import {
629
+ AdsProviderInternal,
630
+ log
631
+ } from "@kontextso/sdk-react";
632
+ import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
633
+ import { Appearance, Dimensions, PixelRatio, Platform as Platform3 } from "react-native";
634
+ import DeviceInfo from "react-native-device-info";
603
635
 
604
636
  // package.json
605
- var version = '3.3.0-rc.3'
637
+ var version = "3.3.0";
606
638
 
607
639
  // src/context/AdsProvider.tsx
608
- import { jsx as jsx4 } from 'react/jsx-runtime'
640
+ import { jsx as jsx4 } from "react/jsx-runtime";
609
641
  ErrorUtils.setGlobalHandler((error, isFatal) => {
610
642
  if (!isFatal) {
611
- log.warn(error)
643
+ log.warn(error);
612
644
  } else {
613
- log.error(error)
645
+ log.error(error);
614
646
  }
615
- })
647
+ });
616
648
  var batteryLevelToPercent = (level) => {
617
- if (typeof level !== 'number' || !isFinite(level)) return void 0
618
- if (level < 0) return void 0
619
- return Math.max(0, Math.min(100, Math.round(level * 100)))
620
- }
649
+ if (typeof level !== "number" || !isFinite(level)) return void 0;
650
+ if (level < 0) return void 0;
651
+ return Math.max(0, Math.min(100, Math.round(level * 100)));
652
+ };
621
653
  var getDevice = async () => {
622
654
  try {
623
- const powerState = await DeviceInfo.getPowerState()
624
- const deviceType = DeviceInfo.getDeviceType()
625
- const soundOn = await NativeRNKontext_default.isSoundOn()
626
- const screen = Dimensions.get('screen')
627
- const networkInfo = await fetchNetworkInfo()
655
+ const powerState = await DeviceInfo.getPowerState();
656
+ const deviceType = DeviceInfo.getDeviceType();
657
+ const soundOn = await NativeRNKontext_default.isSoundOn();
658
+ const screen = Dimensions.get("screen");
659
+ const networkInfo = await fetchNetworkInfo();
628
660
  const mapDeviceTypeToHardwareType = () => {
629
661
  switch (deviceType) {
630
- case 'Handset':
631
- return 'handset'
632
- case 'Tablet':
633
- return 'tablet'
634
- case 'Tv':
635
- return 'tv'
636
- case 'Desktop':
637
- return 'desktop'
662
+ case "Handset":
663
+ return "handset";
664
+ case "Tablet":
665
+ return "tablet";
666
+ case "Tv":
667
+ return "tv";
668
+ case "Desktop":
669
+ return "desktop";
638
670
  default:
639
- return 'other'
671
+ return "other";
640
672
  }
641
- }
673
+ };
642
674
  return {
643
675
  hardware: {
644
676
  brand: DeviceInfo.getBrand(),
645
677
  model: DeviceInfo.getDeviceId(),
646
- type: mapDeviceTypeToHardwareType(),
678
+ type: mapDeviceTypeToHardwareType()
647
679
  // bootTime: Not available without native module
648
680
  // sdCardAvailable: Not available without native module
649
681
  },
650
682
  audio: {
651
- muted: soundOn,
683
+ muted: soundOn
652
684
  // volume: Requires react-native-volume-manager
653
685
  // outputPluggedIn: Not available without native module
654
686
  // outputType: Not available without native module
655
687
  },
656
688
  network: {
657
- carrier: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier) || void 0,
689
+ carrier: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier || void 0,
658
690
  userAgent: await DeviceInfo.getUserAgent(),
659
- type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type)
660
- ? networkInfo.type
661
- : NetInfoStateType.other,
662
- detail: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration) || void 0,
691
+ type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type) ? networkInfo.type : NetInfoStateType.other,
692
+ detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
663
693
  },
664
694
  os: {
665
695
  name: Platform3.OS,
666
696
  version: DeviceInfo.getSystemVersion(),
667
697
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
668
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
698
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
669
699
  },
670
700
  screen: {
671
- darkMode: Appearance.getColorScheme() === 'dark',
701
+ darkMode: Appearance.getColorScheme() === "dark",
672
702
  dpr: PixelRatio.get(),
673
703
  height: screen.height,
674
704
  width: screen.width,
675
- orientation: screen.width > screen.height ? 'landscape' : 'portrait',
705
+ orientation: screen.width > screen.height ? "landscape" : "portrait"
676
706
  },
677
707
  power: {
678
708
  batteryLevel: batteryLevelToPercent(powerState.batteryLevel),
679
709
  batteryState: powerState.batteryState,
680
- lowPowerMode: powerState.lowPowerMode,
681
- },
682
- }
710
+ lowPowerMode: powerState.lowPowerMode
711
+ }
712
+ };
683
713
  } catch (error) {
684
- console.error(error)
685
- return {}
714
+ console.error(error);
715
+ return {};
686
716
  }
687
- }
717
+ };
688
718
  var getApp = async () => {
689
719
  try {
690
720
  return {
691
721
  bundleId: DeviceInfo.getBundleId(),
692
722
  firstInstallTime: await DeviceInfo.getFirstInstallTime(),
693
723
  lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
694
- version: DeviceInfo.getVersion(),
724
+ version: DeviceInfo.getVersion()
695
725
  // Not supported in react-native-device-info v10
696
726
  // startTime: await DeviceInfo.getStartupTime(),
697
- }
727
+ };
698
728
  } catch (error) {
699
- console.error(error)
700
- return {}
729
+ console.error(error);
730
+ return {};
701
731
  }
702
- }
732
+ };
703
733
  var getSdk = async () => ({
704
- name: 'sdk-react-native',
705
- platform: Platform3.OS === 'ios' ? 'ios' : 'android',
706
- version,
707
- })
734
+ name: "sdk-react-native",
735
+ platform: Platform3.OS === "ios" ? "ios" : "android",
736
+ version
737
+ });
708
738
  var getTcf = async () => {
709
739
  try {
710
- const tcfData = await NativeRNKontext_default.getTcfData()
740
+ const tcfData = await NativeRNKontext_default.getTcfData();
741
+ const gdpr = tcfData.gdprApplies === 0 || tcfData.gdprApplies === 1 ? tcfData.gdprApplies : void 0;
742
+ const gdprConsent = typeof tcfData.tcString === "string" && tcfData.tcString.length > 0 ? tcfData.tcString : void 0;
711
743
  return {
712
- gdpr: tcfData.gdprApplies,
713
- gdprConsent: tcfData.tcString,
714
- }
744
+ ...gdpr !== void 0 ? { gdpr } : {},
745
+ ...gdprConsent !== void 0 ? { gdprConsent } : {}
746
+ };
715
747
  } catch (error) {
716
- console.error(error)
717
- return {}
748
+ console.error(error);
749
+ return {};
718
750
  }
719
- }
751
+ };
720
752
  var AdsProvider = (props) => {
721
- return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice, getSdk, getApp, getTcf })
722
- }
723
- export { AdsProvider, InlineAd_default as InlineAd }
753
+ return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice, getSdk, getApp, getTcf });
754
+ };
755
+ export {
756
+ AdsProvider,
757
+ InlineAd_default as InlineAd
758
+ };