@openfort/react-native 0.0.2 → 0.0.3

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/Iframe.js CHANGED
@@ -1,6 +1,5 @@
1
- import React from 'react';
2
- import { useEffect, useRef, useState } from "react";
3
- import { View } from "react-native";
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { Platform, Text, View } from "react-native";
4
3
  import WebView from "react-native-webview";
5
4
  const debugInjectedCode = `
6
5
  console.log = function(...message) {
@@ -18,6 +17,8 @@ const debugInjectedCode = `
18
17
  const injectedCode = `
19
18
  window.parent = {};
20
19
  window.parent.postMessage = (msg) => {console.log("---", msg); window.ReactNativeWebView.postMessage(JSON.stringify(msg))}
20
+
21
+ window.isAndroid = ${Platform.OS === 'android' ? 'true' : 'false'};
21
22
  `;
22
23
  export default function Iframe({ customUri, debug, debugVisible }) {
23
24
  const webViewRef = useRef(null);
@@ -25,14 +26,21 @@ export default function Iframe({ customUri, debug, debugVisible }) {
25
26
  const fnCallbackRef = useRef(null); // Ref to store the callback
26
27
  const [loaded, setLoaded] = useState(false);
27
28
  useEffect(() => {
28
- global.openfortListener = (fn) => {
29
+ if (!global.openfort)
30
+ throw new Error("Openfort SDK not initialized. Please make sure to add `import '@openfort/react-native/polyfills';` at the top of you app before using the SDK.");
31
+ global.openfort.iframeListener = (fn) => {
29
32
  fnCallbackRef.current = fn; // Store the callback in the ref
30
33
  };
31
- global.openfortPostMessage = (message) => {
32
- webViewRef?.current?.postMessage(JSON.stringify(message));
34
+ global.openfort.iframePostMessage = (message) => {
35
+ setLoaded(true);
36
+ if (!webViewRef.current) {
37
+ if (debug)
38
+ console.log("WebView is not initialized, trying to send message:", message);
39
+ return;
40
+ }
33
41
  if (debug)
34
42
  console.log("[Send message to web view]", message);
35
- setLoaded(true);
43
+ webViewRef.current.postMessage(JSON.stringify(message));
36
44
  };
37
45
  }, [webViewRef?.current]);
38
46
  const handleMessage = (event) => {
@@ -68,5 +76,9 @@ export default function Iframe({ customUri, debug, debugVisible }) {
68
76
  }
69
77
  const uriWithParams = finalUri.toString();
70
78
  return (React.createElement(View, { style: { flex: debugVisible ? 1 : 0 } },
79
+ debugVisible &&
80
+ React.createElement(Text, null,
81
+ "Debug: ",
82
+ uriWithParams),
71
83
  React.createElement(WebView, { ref: webViewRef, source: { uri: uriWithParams }, onMessage: handleMessage, injectedJavaScript: injectedCode + (debug ? debugInjectedCode : "") })));
72
84
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc",
@@ -18,18 +18,17 @@
18
18
  "react-native-get-random-values": "^1.11.0",
19
19
  "react-native-mmkv": "^3.2.0",
20
20
  "react-native-randombytes": "^3.6.1",
21
- "react-native-webview": "13.12.5",
21
+ "react-native-webview": "^13.13.5",
22
22
  "text-encoding": "^0.7.0",
23
23
  "uuid": "^11.1.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@openfort/openfort-js": "^0.8.31",
26
+ "@openfort/openfort-js": "^0.8.42",
27
27
  "react": "*",
28
28
  "react-native": "*"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@eslint/js": "^9.17.0",
32
- "@openfort/openfort-js": "^0.8.31",
33
32
  "@types/jsrsasign": "^10.5.15",
34
33
  "@types/react": "~18.3.12",
35
34
  "@types/react-test-renderer": "^18.3.0",
@@ -70,7 +70,8 @@ const localStorage: Storage = {
70
70
  global.localStorage = localStorage;
71
71
  global.sessionStorage = localStorage;
72
72
 
73
- global.JWK_UTILS = {
73
+ global.openfort = {}
74
+ global.openfort.jwk = {
74
75
  getKey: KEYUTIL.getKey,
75
76
  parse: KJUR.jws.JWS.parse,
76
77
  verifyJWT: KJUR.jws.JWS.verifyJWT,