@quiltt/react-native 3.3.0 → 3.3.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/CHANGELOG.md +18 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/components/QuilttConnector.tsx +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @quiltt/react-native
|
|
2
2
|
|
|
3
|
+
## 3.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4a9118b: React Native sdk to support Plaid Oauth url
|
|
8
|
+
- Updated dependencies [4a9118b]
|
|
9
|
+
- @quiltt/core@3.3.2
|
|
10
|
+
- @quiltt/react@3.3.2
|
|
11
|
+
|
|
12
|
+
## 3.3.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 9bfbc03: Match eventType with MessageType in react native sdk
|
|
17
|
+
- Updated dependencies [9bfbc03]
|
|
18
|
+
- @quiltt/core@3.3.1
|
|
19
|
+
- @quiltt/react@3.3.1
|
|
20
|
+
|
|
3
21
|
## 3.3.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var T=(r,o)=>{for(var i in o)b(r,i,{get:o[i],enumerable:!0})},U=(r,o,i,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let c of L(o))!Q.call(r,c)&&c!==i&&b(r,c,{get:()=>o[c],enumerable:!(t=D(o,c))||t.enumerable});return r};var K=r=>U(b({},"__esModule",{value:!0}),r);var I={};T(I,{QuilttConnector:()=>k,default:()=>M});module.exports=K(I);var G=require("core-js/stable/atob"),X=require("core-js/stable/url");var p=require("@quiltt/core"),n=require("react"),A=require("react-native"),q=require("react-native-webview");var l=require("react-native"),y=require("react/jsx-runtime"),C=({children:r})=>(0,y.jsx)(l.SafeAreaView,{style:$.AndroidSafeArea,children:r}),$=l.StyleSheet.create({AndroidSafeArea:{flex:1,backgroundColor:"white",paddingTop:l.Platform.OS==="android"?l.StatusBar.currentHeight:0}});var P=require("@quiltt/react"),w=require("react/jsx-runtime"),j=({connectorId:r,connectionId:o,oauthRedirectUrl:i,onEvent:t,onLoad:c,onExit:s,onExitSuccess:u,onExitAbort:f,onExitError:m})=>{let h=(0,n.useRef)(null),{session:d}=(0,P.useQuilttSession)();i=encodeURIComponent(i);let R=`https://${r}.quiltt.app/?mode=webview&oauth_redirect_url=${i}&sdk=react-native`,V=(0,n.useCallback)(()=>{var e;let a=` const options = { source: 'quiltt', type: 'Options', token: '${d==null?void 0:d.token}', connectorId: '${r}', connectionId: '${o}', }; const compactedOptions = Object.keys(options).reduce((acc, key) => { if (options[key] !== 'undefined') { acc[key] = options[key]; } return acc; }, {}); window.postMessage(compactedOptions); `;(e=h.current)==null||e.injectJavaScript(a)},[o,r,d==null?void 0:d.token]),O=a=>{let e=new URL(a.url);return e.host.includes("quiltt")?!0:e.protocol==="quilttconnector:"?(W(e),!1):(g(e.href),!1)},S=()=>{var e;let a="localStorage.clear();";(e=h.current)==null||e.injectJavaScript(a)},W=a=>{a.searchParams.delete("source"),a.searchParams.append("connectorId",r);let e=Object.fromEntries(a.searchParams);switch(a.host){case"Load":V(),t==null||t(p.ConnectorSDKEventType.Load,e),c==null||c(e);break;case"ExitAbort":S(),t==null||t(p.ConnectorSDKEventType.ExitAbort,e),s==null||s(p.ConnectorSDKEventType.ExitAbort,e),f==null||f(e);break;case"ExitError":S(),t==null||t(p.ConnectorSDKEventType.ExitError,e),s==null||s(p.ConnectorSDKEventType.ExitError,e),m==null||m(e);break;case"ExitSuccess":S(),t==null||t(p.ConnectorSDKEventType.ExitSuccess,e),s==null||s(p.ConnectorSDKEventType.ExitSuccess,e),u==null||u(e);break;case"OauthRequested":g(a.searchParams.get("oauthUrl"));break;default:console.log("unhandled event",a);break}},g=a=>A.Linking.openURL(a);return(0,w.jsx)(C,{children:(0,w.jsx)(q.WebView,{ref:h,originWhitelist:["https://*","quilttconnector://*"],source:{uri:R},onShouldStartLoadWithRequest:O,javaScriptEnabled:!0,domStorageEnabled:!0,webviewDebuggingEnabled:!0})})},k=j;var M=k;0&&(module.exports={QuilttConnector});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/components/QuilttConnector.tsx","../src/components/AndroidSafeAreaView.tsx"],"sourcesContent":["// Hermes doesn't have atob\n// https://github.com/facebook/hermes/issues/1178\nimport 'core-js/stable/atob'\n// React Native's URL implementation is incomplete\n// https://github.com/facebook/react-native/issues/16434\nimport 'core-js/stable/url'\nimport QuilttConnector from './components/QuilttConnector'\n\nexport { QuilttConnector }\nexport default QuilttConnector\n","import {\n ConnectorSDKCallbackMetadata,\n ConnectorSDKCallbacks,\n ConnectorSDKEventType,\n} from '@quiltt/core'\nimport { useCallback, useRef } from 'react'\nimport { Linking } from 'react-native'\nimport { WebView } from 'react-native-webview'\nimport { AndroidSafeAreaView } from './AndroidSafeAreaView'\nimport type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes'\nimport { useQuilttSession } from '@quiltt/react'\n\ntype QuilttConnectorProps = {\n connectorId: string\n connectionId?: string\n oauthRedirectUrl: string\n} & ConnectorSDKCallbacks\n\nexport const QuilttConnector = ({\n connectorId,\n connectionId,\n oauthRedirectUrl,\n onEvent,\n onLoad,\n onExit,\n onExitSuccess,\n onExitAbort,\n onExitError,\n}: QuilttConnectorProps) => {\n const webViewRef = useRef<WebView>(null)\n const { session } = useQuilttSession()\n oauthRedirectUrl = encodeURIComponent(oauthRedirectUrl)\n const connectorUrl = `https://${connectorId}.quiltt.app/?mode=webview&oauth_redirect_url=${oauthRedirectUrl}&sdk=react-native` // @todo append version from package.json\n\n const initInjectedJavaScript = useCallback(() => {\n const script = `\\\n const options = {\\\n source: 'quiltt',\\\n type: 'Options',\\\n token: '${session?.token}',\\\n connectorId: '${connectorId}',\\\n connectionId: '${connectionId}',\\\n };\\\n const compactedOptions = Object.keys(options).reduce((acc, key) => {\\\n if (options[key] !== 'undefined') {\\\n acc[key] = options[key];\\\n }\\\n return acc;\\\n }, {});\\\n window.postMessage(compactedOptions);\\\n `\n webViewRef.current?.injectJavaScript(script)\n }, [connectionId, connectorId, session?.token])\n\n const eventHandler = (request: ShouldStartLoadRequest) => {\n const url = new URL(request.url)\n if (url.protocol === 'quilttconnector:') {\n handleQuilttEvent(url)\n return false\n }\n return
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/QuilttConnector.tsx","../src/components/AndroidSafeAreaView.tsx"],"sourcesContent":["// Hermes doesn't have atob\n// https://github.com/facebook/hermes/issues/1178\nimport 'core-js/stable/atob'\n// React Native's URL implementation is incomplete\n// https://github.com/facebook/react-native/issues/16434\nimport 'core-js/stable/url'\nimport QuilttConnector from './components/QuilttConnector'\n\nexport { QuilttConnector }\nexport default QuilttConnector\n","import {\n ConnectorSDKCallbackMetadata,\n ConnectorSDKCallbacks,\n ConnectorSDKEventType,\n} from '@quiltt/core'\nimport { useCallback, useRef } from 'react'\nimport { Linking } from 'react-native'\nimport { WebView } from 'react-native-webview'\nimport { AndroidSafeAreaView } from './AndroidSafeAreaView'\nimport type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes'\nimport { useQuilttSession } from '@quiltt/react'\n\ntype QuilttConnectorProps = {\n connectorId: string\n connectionId?: string\n oauthRedirectUrl: string\n} & ConnectorSDKCallbacks\n\nexport const QuilttConnector = ({\n connectorId,\n connectionId,\n oauthRedirectUrl,\n onEvent,\n onLoad,\n onExit,\n onExitSuccess,\n onExitAbort,\n onExitError,\n}: QuilttConnectorProps) => {\n const webViewRef = useRef<WebView>(null)\n const { session } = useQuilttSession()\n oauthRedirectUrl = encodeURIComponent(oauthRedirectUrl)\n const connectorUrl = `https://${connectorId}.quiltt.app/?mode=webview&oauth_redirect_url=${oauthRedirectUrl}&sdk=react-native` // @todo append version from package.json\n\n const initInjectedJavaScript = useCallback(() => {\n const script = `\\\n const options = {\\\n source: 'quiltt',\\\n type: 'Options',\\\n token: '${session?.token}',\\\n connectorId: '${connectorId}',\\\n connectionId: '${connectionId}',\\\n };\\\n const compactedOptions = Object.keys(options).reduce((acc, key) => {\\\n if (options[key] !== 'undefined') {\\\n acc[key] = options[key];\\\n }\\\n return acc;\\\n }, {});\\\n window.postMessage(compactedOptions);\\\n `\n webViewRef.current?.injectJavaScript(script)\n }, [connectionId, connectorId, session?.token])\n\n const eventHandler = (request: ShouldStartLoadRequest) => {\n const url = new URL(request.url)\n if (url.host.includes('quiltt')) return true\n if (url.protocol === 'quilttconnector:') {\n handleQuilttEvent(url)\n return false\n }\n // Plaid set oauth url by doing window.location.href = url\n // This is the only way I know to handle this.\n handleOAuthUrl(url.href)\n return false\n }\n\n const clearLocalStorage = () => {\n const script = 'localStorage.clear();'\n webViewRef.current?.injectJavaScript(script)\n }\n\n const handleQuilttEvent = (url: URL) => {\n url.searchParams.delete('source')\n url.searchParams.append('connectorId', connectorId)\n const metadata = Object.fromEntries(url.searchParams) as ConnectorSDKCallbackMetadata\n\n const eventType = url.host\n switch (eventType) {\n case 'Load':\n initInjectedJavaScript()\n onEvent?.(ConnectorSDKEventType.Load, metadata)\n onLoad?.(metadata)\n break\n case 'ExitAbort':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitAbort, metadata)\n onExit?.(ConnectorSDKEventType.ExitAbort, metadata)\n onExitAbort?.(metadata)\n break\n case 'ExitError':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitError, metadata)\n onExit?.(ConnectorSDKEventType.ExitError, metadata)\n onExitError?.(metadata)\n break\n case 'ExitSuccess':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitSuccess, metadata)\n onExit?.(ConnectorSDKEventType.ExitSuccess, metadata)\n onExitSuccess?.(metadata)\n break\n case 'OauthRequested':\n handleOAuthUrl(url.searchParams.get('oauthUrl') as string)\n break\n default:\n console.log('unhandled event', url)\n break\n }\n }\n\n const handleOAuthUrl = (oauthUrl: string) => Linking.openURL(oauthUrl)\n\n return (\n <AndroidSafeAreaView>\n <WebView\n ref={webViewRef}\n originWhitelist={['https://*', 'quilttconnector://*']} // Maybe relax this to *?\n source={{ uri: connectorUrl }}\n onShouldStartLoadWithRequest={eventHandler}\n javaScriptEnabled\n domStorageEnabled // To enable localStorage in Android webview\n webviewDebuggingEnabled // Not sure if this works\n />\n </AndroidSafeAreaView>\n )\n}\n\nexport default QuilttConnector\n","import { SafeAreaView, StyleSheet, Platform, StatusBar } from 'react-native'\nimport { PropsWithChildren } from 'react'\n\nexport const AndroidSafeAreaView = ({ children }: PropsWithChildren) => (\n <SafeAreaView style={styles.AndroidSafeArea}>{children}</SafeAreaView>\n)\n\nconst styles = StyleSheet.create({\n AndroidSafeArea: {\n flex: 1,\n backgroundColor: 'white',\n paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,\n },\n})\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAO,+BAGPC,EAAO,8BCLP,IAAAC,EAIO,wBACPC,EAAoC,iBACpCC,EAAwB,wBACxBC,EAAwB,gCCPxB,IAAAC,EAA8D,wBAI5DC,EAAA,6BADWC,EAAsB,CAAC,CAAE,SAAAC,CAAS,OAC7C,OAAC,gBAAa,MAAOC,EAAO,gBAAkB,SAAAD,EAAS,EAGnDC,EAAS,aAAW,OAAO,CAC/B,gBAAiB,CACf,KAAM,EACN,gBAAiB,QACjB,WAAY,WAAS,KAA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B,GAC3ChB,GAAA,MAAAA,EAAS,wBAAsB,UAAWgB,GAC1Cd,GAAA,MAAAA,EAAcc,GACd,MACF,IAAK,YACHD,EAAkB,EAClBjB,GAAA,MAAAA,EAAU,wBAAsB,UAAWkB,GAC3ChB,GAAA,MAAAA,EAAS,wBAAsB,UAAWgB,GAC1Cb,GAAA,MAAAA,EAAca,GACd,MACF,IAAK,cACHD,EAAkB,EAClBjB,GAAA,MAAAA,EAAU,wBAAsB,YAAakB,GAC7ChB,GAAA,MAAAA,EAAS,wBAAsB,YAAagB,GAC5Cf,GAAA,MAAAA,EAAgBe,GAChB,MACF,IAAK,iBACHF,EAAeF,EAAI,aAAa,IAAI,UAAU,CAAW,EACzD,MACF,QACE,QAAQ,IAAI,kBAAmBA,CAAG,EAClC,KACJ,CACF,EAEME,EAAkBG,GAAqB,UAAQ,QAAQA,CAAQ,EAErE,SACE,OAACC,EAAA,CACC,mBAAC,WACC,IAAKd,EACL,gBAAiB,CAAC,YAAa,qBAAqB,EACpD,OAAQ,CAAE,IAAKE,CAAa,EAC5B,6BAA8BI,EAC9B,kBAAiB,GACjB,kBAAiB,GACjB,wBAAuB,GACzB,EACF,CAEJ,EAEOS,EAAQzB,EDvHf,IAAO0B,EAAQC","names":["src_exports","__export","QuilttConnector_default","src_default","__toCommonJS","import_atob","import_url","import_core","import_react","import_react_native","import_react_native_webview","import_react_native","import_jsx_runtime","AndroidSafeAreaView","children","styles","import_react","import_jsx_runtime","QuilttConnector","connectorId","connectionId","oauthRedirectUrl","onEvent","onLoad","onExit","onExitSuccess","onExitAbort","onExitError","webViewRef","session","connectorUrl","initInjectedJavaScript","_a","script","eventHandler","request","url","handleQuilttEvent","handleOAuthUrl","clearLocalStorage","metadata","oauthUrl","AndroidSafeAreaView","QuilttConnector_default","src_default","QuilttConnector_default"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"core-js/stable/atob";import"core-js/stable/url";import{ConnectorSDKEventType as o}from"@quiltt/core";import{useCallback as
|
|
1
|
+
import"core-js/stable/atob";import"core-js/stable/url";import{ConnectorSDKEventType as o}from"@quiltt/core";import{useCallback as W,useRef as D}from"react";import{Linking as L}from"react-native";import{WebView as Q}from"react-native-webview";import{SafeAreaView as A,StyleSheet as q,Platform as P,StatusBar as R}from"react-native";import{jsx as O}from"react/jsx-runtime";var S=({children:c})=>O(A,{style:V.AndroidSafeArea,children:c}),V=q.create({AndroidSafeArea:{flex:1,backgroundColor:"white",paddingTop:P.OS==="android"?R.currentHeight:0}});import{useQuilttSession as T}from"@quiltt/react";import{jsx as b}from"react/jsx-runtime";var U=({connectorId:c,connectionId:m,oauthRedirectUrl:i,onEvent:r,onLoad:l,onExit:a,onExitSuccess:p,onExitAbort:d,onExitError:n})=>{let u=D(null),{session:s}=T();i=encodeURIComponent(i);let k=`https://${c}.quiltt.app/?mode=webview&oauth_redirect_url=${i}&sdk=react-native`,g=W(()=>{var e;let t=` const options = { source: 'quiltt', type: 'Options', token: '${s==null?void 0:s.token}', connectorId: '${c}', connectionId: '${m}', }; const compactedOptions = Object.keys(options).reduce((acc, key) => { if (options[key] !== 'undefined') { acc[key] = options[key]; } return acc; }, {}); window.postMessage(compactedOptions); `;(e=u.current)==null||e.injectJavaScript(t)},[m,c,s==null?void 0:s.token]),C=t=>{let e=new URL(t.url);return e.host.includes("quiltt")?!0:e.protocol==="quilttconnector:"?(y(e),!1):(h(e.href),!1)},f=()=>{var e;let t="localStorage.clear();";(e=u.current)==null||e.injectJavaScript(t)},y=t=>{t.searchParams.delete("source"),t.searchParams.append("connectorId",c);let e=Object.fromEntries(t.searchParams);switch(t.host){case"Load":g(),r==null||r(o.Load,e),l==null||l(e);break;case"ExitAbort":f(),r==null||r(o.ExitAbort,e),a==null||a(o.ExitAbort,e),d==null||d(e);break;case"ExitError":f(),r==null||r(o.ExitError,e),a==null||a(o.ExitError,e),n==null||n(e);break;case"ExitSuccess":f(),r==null||r(o.ExitSuccess,e),a==null||a(o.ExitSuccess,e),p==null||p(e);break;case"OauthRequested":h(t.searchParams.get("oauthUrl"));break;default:console.log("unhandled event",t);break}},h=t=>L.openURL(t);return b(S,{children:b(Q,{ref:u,originWhitelist:["https://*","quilttconnector://*"],source:{uri:k},onShouldStartLoadWithRequest:C,javaScriptEnabled:!0,domStorageEnabled:!0,webviewDebuggingEnabled:!0})})},w=U;var x=w;export{w as QuilttConnector,x as default};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/components/QuilttConnector.tsx","../src/components/AndroidSafeAreaView.tsx"],"sourcesContent":["// Hermes doesn't have atob\n// https://github.com/facebook/hermes/issues/1178\nimport 'core-js/stable/atob'\n// React Native's URL implementation is incomplete\n// https://github.com/facebook/react-native/issues/16434\nimport 'core-js/stable/url'\nimport QuilttConnector from './components/QuilttConnector'\n\nexport { QuilttConnector }\nexport default QuilttConnector\n","import {\n ConnectorSDKCallbackMetadata,\n ConnectorSDKCallbacks,\n ConnectorSDKEventType,\n} from '@quiltt/core'\nimport { useCallback, useRef } from 'react'\nimport { Linking } from 'react-native'\nimport { WebView } from 'react-native-webview'\nimport { AndroidSafeAreaView } from './AndroidSafeAreaView'\nimport type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes'\nimport { useQuilttSession } from '@quiltt/react'\n\ntype QuilttConnectorProps = {\n connectorId: string\n connectionId?: string\n oauthRedirectUrl: string\n} & ConnectorSDKCallbacks\n\nexport const QuilttConnector = ({\n connectorId,\n connectionId,\n oauthRedirectUrl,\n onEvent,\n onLoad,\n onExit,\n onExitSuccess,\n onExitAbort,\n onExitError,\n}: QuilttConnectorProps) => {\n const webViewRef = useRef<WebView>(null)\n const { session } = useQuilttSession()\n oauthRedirectUrl = encodeURIComponent(oauthRedirectUrl)\n const connectorUrl = `https://${connectorId}.quiltt.app/?mode=webview&oauth_redirect_url=${oauthRedirectUrl}&sdk=react-native` // @todo append version from package.json\n\n const initInjectedJavaScript = useCallback(() => {\n const script = `\\\n const options = {\\\n source: 'quiltt',\\\n type: 'Options',\\\n token: '${session?.token}',\\\n connectorId: '${connectorId}',\\\n connectionId: '${connectionId}',\\\n };\\\n const compactedOptions = Object.keys(options).reduce((acc, key) => {\\\n if (options[key] !== 'undefined') {\\\n acc[key] = options[key];\\\n }\\\n return acc;\\\n }, {});\\\n window.postMessage(compactedOptions);\\\n `\n webViewRef.current?.injectJavaScript(script)\n }, [connectionId, connectorId, session?.token])\n\n const eventHandler = (request: ShouldStartLoadRequest) => {\n const url = new URL(request.url)\n if (url.protocol === 'quilttconnector:') {\n handleQuilttEvent(url)\n return false\n }\n return
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/QuilttConnector.tsx","../src/components/AndroidSafeAreaView.tsx"],"sourcesContent":["// Hermes doesn't have atob\n// https://github.com/facebook/hermes/issues/1178\nimport 'core-js/stable/atob'\n// React Native's URL implementation is incomplete\n// https://github.com/facebook/react-native/issues/16434\nimport 'core-js/stable/url'\nimport QuilttConnector from './components/QuilttConnector'\n\nexport { QuilttConnector }\nexport default QuilttConnector\n","import {\n ConnectorSDKCallbackMetadata,\n ConnectorSDKCallbacks,\n ConnectorSDKEventType,\n} from '@quiltt/core'\nimport { useCallback, useRef } from 'react'\nimport { Linking } from 'react-native'\nimport { WebView } from 'react-native-webview'\nimport { AndroidSafeAreaView } from './AndroidSafeAreaView'\nimport type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes'\nimport { useQuilttSession } from '@quiltt/react'\n\ntype QuilttConnectorProps = {\n connectorId: string\n connectionId?: string\n oauthRedirectUrl: string\n} & ConnectorSDKCallbacks\n\nexport const QuilttConnector = ({\n connectorId,\n connectionId,\n oauthRedirectUrl,\n onEvent,\n onLoad,\n onExit,\n onExitSuccess,\n onExitAbort,\n onExitError,\n}: QuilttConnectorProps) => {\n const webViewRef = useRef<WebView>(null)\n const { session } = useQuilttSession()\n oauthRedirectUrl = encodeURIComponent(oauthRedirectUrl)\n const connectorUrl = `https://${connectorId}.quiltt.app/?mode=webview&oauth_redirect_url=${oauthRedirectUrl}&sdk=react-native` // @todo append version from package.json\n\n const initInjectedJavaScript = useCallback(() => {\n const script = `\\\n const options = {\\\n source: 'quiltt',\\\n type: 'Options',\\\n token: '${session?.token}',\\\n connectorId: '${connectorId}',\\\n connectionId: '${connectionId}',\\\n };\\\n const compactedOptions = Object.keys(options).reduce((acc, key) => {\\\n if (options[key] !== 'undefined') {\\\n acc[key] = options[key];\\\n }\\\n return acc;\\\n }, {});\\\n window.postMessage(compactedOptions);\\\n `\n webViewRef.current?.injectJavaScript(script)\n }, [connectionId, connectorId, session?.token])\n\n const eventHandler = (request: ShouldStartLoadRequest) => {\n const url = new URL(request.url)\n if (url.host.includes('quiltt')) return true\n if (url.protocol === 'quilttconnector:') {\n handleQuilttEvent(url)\n return false\n }\n // Plaid set oauth url by doing window.location.href = url\n // This is the only way I know to handle this.\n handleOAuthUrl(url.href)\n return false\n }\n\n const clearLocalStorage = () => {\n const script = 'localStorage.clear();'\n webViewRef.current?.injectJavaScript(script)\n }\n\n const handleQuilttEvent = (url: URL) => {\n url.searchParams.delete('source')\n url.searchParams.append('connectorId', connectorId)\n const metadata = Object.fromEntries(url.searchParams) as ConnectorSDKCallbackMetadata\n\n const eventType = url.host\n switch (eventType) {\n case 'Load':\n initInjectedJavaScript()\n onEvent?.(ConnectorSDKEventType.Load, metadata)\n onLoad?.(metadata)\n break\n case 'ExitAbort':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitAbort, metadata)\n onExit?.(ConnectorSDKEventType.ExitAbort, metadata)\n onExitAbort?.(metadata)\n break\n case 'ExitError':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitError, metadata)\n onExit?.(ConnectorSDKEventType.ExitError, metadata)\n onExitError?.(metadata)\n break\n case 'ExitSuccess':\n clearLocalStorage()\n onEvent?.(ConnectorSDKEventType.ExitSuccess, metadata)\n onExit?.(ConnectorSDKEventType.ExitSuccess, metadata)\n onExitSuccess?.(metadata)\n break\n case 'OauthRequested':\n handleOAuthUrl(url.searchParams.get('oauthUrl') as string)\n break\n default:\n console.log('unhandled event', url)\n break\n }\n }\n\n const handleOAuthUrl = (oauthUrl: string) => Linking.openURL(oauthUrl)\n\n return (\n <AndroidSafeAreaView>\n <WebView\n ref={webViewRef}\n originWhitelist={['https://*', 'quilttconnector://*']} // Maybe relax this to *?\n source={{ uri: connectorUrl }}\n onShouldStartLoadWithRequest={eventHandler}\n javaScriptEnabled\n domStorageEnabled // To enable localStorage in Android webview\n webviewDebuggingEnabled // Not sure if this works\n />\n </AndroidSafeAreaView>\n )\n}\n\nexport default QuilttConnector\n","import { SafeAreaView, StyleSheet, Platform, StatusBar } from 'react-native'\nimport { PropsWithChildren } from 'react'\n\nexport const AndroidSafeAreaView = ({ children }: PropsWithChildren) => (\n <SafeAreaView style={styles.AndroidSafeArea}>{children}</SafeAreaView>\n)\n\nconst styles = StyleSheet.create({\n AndroidSafeArea: {\n flex: 1,\n backgroundColor: 'white',\n paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,\n },\n})\n"],"mappings":"AAEA,MAAO,sBAGP,MAAO,qBCLP,OAGE,yBAAAA,MACK,eACP,OAAS,eAAAC,EAAa,UAAAC,MAAc,QACpC,OAAS,WAAAC,MAAe,eACxB,OAAS,WAAAC,MAAe,uBCPxB,OAAS,gBAAAC,EAAc,cAAAC,EAAY,YAAAC,EAAU,aAAAC,MAAiB,eAI5D,cAAAC,MAAA,oBADK,IAAMC,EAAsB,CAAC,CAAE,SAAAC,CAAS,IAC7CF,EAACJ,EAAA,CAAa,MAAOO,EAAO,gBAAkB,SAAAD,EAAS,EAGnDC,EAASN,EAAW,OAAO,CAC/B,gBAAiB,CACf,KAAM,EACN,gBAAiB,QACjB,WAAYC,EAAS,KAAO,UAAYC,EAAU,cAAgB,CACpE,CACF,CAAC,EDHD,OAAS,oBAAAK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UAAWD,GAC1ChB,GAAA,MAAAA,EAAcgB,GACd,MACF,IAAK,YACHD,EAAkB,EAClBnB,GAAA,MAAAA,EAAUqB,EAAsB,UAAWD,GAC3ClB,GAAA,MAAAA,EAASmB,EAAsB,UAAWD,GAC1Cf,GAAA,MAAAA,EAAce,GACd,MACF,IAAK,cACHD,EAAkB,EAClBnB,GAAA,MAAAA,EAAUqB,EAAsB,YAAaD,GAC7ClB,GAAA,MAAAA,EAASmB,EAAsB,YAAaD,GAC5CjB,GAAA,MAAAA,EAAgBiB,GAChB,MACF,IAAK,iBACHF,EAAeF,EAAI,aAAa,IAAI,UAAU,CAAW,EACzD,MACF,QACE,QAAQ,IAAI,kBAAmBA,CAAG,EAClC,KACJ,CACF,EAEME,EAAkBI,GAAqBC,EAAQ,QAAQD,CAAQ,EAErE,OACE3B,EAAC6B,EAAA,CACC,SAAA7B,EAAC8B,EAAA,CACC,IAAKnB,EACL,gBAAiB,CAAC,YAAa,qBAAqB,EACpD,OAAQ,CAAE,IAAKG,CAAa,EAC5B,6BAA8BK,EAC9B,kBAAiB,GACjB,kBAAiB,GACjB,wBAAuB,GACzB,EACF,CAEJ,EAEOY,EAAQ9B,EDvHf,IAAO+B,EAAQC","names":["ConnectorSDKEventType","useCallback","useRef","Linking","WebView","SafeAreaView","StyleSheet","Platform","StatusBar","jsx","AndroidSafeAreaView","children","styles","useQuilttSession","jsx","QuilttConnector","connectorId","connectionId","oauthRedirectUrl","onEvent","onLoad","onExit","onExitSuccess","onExitAbort","onExitError","webViewRef","useRef","session","connectorUrl","initInjectedJavaScript","useCallback","_a","script","eventHandler","request","url","handleQuilttEvent","handleOAuthUrl","clearLocalStorage","metadata","ConnectorSDKEventType","oauthUrl","Linking","AndroidSafeAreaView","WebView","QuilttConnector_default","src_default","QuilttConnector_default"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiltt/react-native",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "React Native components for Quiltt Connector",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"core-js": "3.33.2",
|
|
25
25
|
"react-native-webview": "13.6.2",
|
|
26
|
-
"@quiltt/core": "3.3.
|
|
27
|
-
"@quiltt/react": "3.3.
|
|
26
|
+
"@quiltt/core": "3.3.2",
|
|
27
|
+
"@quiltt/react": "3.3.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@apollo/client": "3.7.16",
|
|
@@ -54,11 +54,15 @@ export const QuilttConnector = ({
|
|
|
54
54
|
|
|
55
55
|
const eventHandler = (request: ShouldStartLoadRequest) => {
|
|
56
56
|
const url = new URL(request.url)
|
|
57
|
+
if (url.host.includes('quiltt')) return true
|
|
57
58
|
if (url.protocol === 'quilttconnector:') {
|
|
58
59
|
handleQuilttEvent(url)
|
|
59
60
|
return false
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
// Plaid set oauth url by doing window.location.href = url
|
|
63
|
+
// This is the only way I know to handle this.
|
|
64
|
+
handleOAuthUrl(url.href)
|
|
65
|
+
return false
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
const clearLocalStorage = () => {
|
|
@@ -73,7 +77,7 @@ export const QuilttConnector = ({
|
|
|
73
77
|
|
|
74
78
|
const eventType = url.host
|
|
75
79
|
switch (eventType) {
|
|
76
|
-
case '
|
|
80
|
+
case 'Load':
|
|
77
81
|
initInjectedJavaScript()
|
|
78
82
|
onEvent?.(ConnectorSDKEventType.Load, metadata)
|
|
79
83
|
onLoad?.(metadata)
|
|
@@ -97,7 +101,7 @@ export const QuilttConnector = ({
|
|
|
97
101
|
onExitSuccess?.(metadata)
|
|
98
102
|
break
|
|
99
103
|
case 'OauthRequested':
|
|
100
|
-
|
|
104
|
+
handleOAuthUrl(url.searchParams.get('oauthUrl') as string)
|
|
101
105
|
break
|
|
102
106
|
default:
|
|
103
107
|
console.log('unhandled event', url)
|
|
@@ -105,6 +109,8 @@ export const QuilttConnector = ({
|
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
const handleOAuthUrl = (oauthUrl: string) => Linking.openURL(oauthUrl)
|
|
113
|
+
|
|
108
114
|
return (
|
|
109
115
|
<AndroidSafeAreaView>
|
|
110
116
|
<WebView
|