@privy-io/expo 0.4.0 → 0.4.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),a=require("react-native-webview"),r=require("react-fast-compare"),i=require("expo-application"),n=require("expo-linking"),o=require("expo-secure-store");function u(e,t){return Object.keys(t).forEach(function(s){"default"===s||"__esModule"===s||e.hasOwnProperty(s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})}),e}function c(e,t,s,a){Object.defineProperty(e,t,{get:s,set:a,enumerable:!0,configurable:!0})}function l(e){return e&&e.__esModule?e.default:e}c(module.exports,"getUserEmbeddedWallet",()=>g),c(module.exports,"SecureStorageAdapter",()=>S),c(module.exports,"useOAuthFlow",()=>w);var d={};c(d,"PrivyContext",()=>E),c(d,"PrivyProvider",()=>W);var p={};p=JSON.parse('{"name":"@privy-io/expo","version":"0.4.0","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.9.0","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');const h=({client:e,isWebViewReady:s,setIsWebViewReady:r})=>{let i=(0,t.useRef)(null);(0,t.useEffect)(()=>{s&&i.current&&e.setMessagePoster(i.current)},[s,e]);let n=(0,t.useCallback)(async t=>{let{data:s}=t.nativeEvent,a=e.embeddedWallet.getMessageHandler();a?.(JSON.parse(s))},[e]);return l(t).createElement(l(a),{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>r(!0),onMessage:n})},y=e=>t=>e(e=>l(r)(e,t)?e:t),g=e=>{if(!e)return null;let t=e.linked_accounts.find(e=>"wallet"===e.type&&"privy"===e.wallet_client_type&&"embedded"===e.connector_type);return t||null},m=e=>"object"==typeof e&&!!(e?.error&&e?.code),b=e=>t=>e instanceof Error?{status:"error",error:e}:m(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,f=({client:s,user:a,wallet:r,setWallet:i,isWebViewReady:n})=>{let o=(0,t.useMemo)(()=>g(a),[a]),u=(0,t.useCallback)(async e=>{i({status:"creating"});try{let t=await s.embeddedWallet.create(e);i({status:"connected",provider:t})}catch(e){i({status:"error",error:"Error creating embedded wallet"})}},[s]),c=(0,t.useCallback)(async e=>{if(o){i({status:"connecting"});try{let t=await s.embeddedWallet.getProvider(o,e);i({status:"connected",provider:t})}catch(e){i({status:"needs-recovery",recover:c})}}},[s,o]);return(0,t.useEffect)(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
1
+ var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),a=require("react-native-webview"),r=require("react-fast-compare"),i=require("expo-application"),n=require("expo-linking"),o=require("expo-secure-store");function u(e,t){return Object.keys(t).forEach(function(s){"default"===s||"__esModule"===s||e.hasOwnProperty(s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})}),e}function c(e,t,s,a){Object.defineProperty(e,t,{get:s,set:a,enumerable:!0,configurable:!0})}function l(e){return e&&e.__esModule?e.default:e}c(module.exports,"getUserEmbeddedWallet",()=>g),c(module.exports,"SecureStorageAdapter",()=>S),c(module.exports,"useOAuthFlow",()=>w);var d={};c(d,"PrivyContext",()=>E),c(d,"PrivyProvider",()=>W);var p={};p=JSON.parse('{"name":"@privy-io/expo","version":"0.4.1","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.9.1","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');const h=({client:e,isWebViewReady:s,setIsWebViewReady:r})=>{let i=(0,t.useRef)(null);(0,t.useEffect)(()=>{s&&i.current&&e.setMessagePoster(i.current)},[s,e]);let n=(0,t.useCallback)(async t=>{let{data:s}=t.nativeEvent,a=e.embeddedWallet.getMessageHandler();a?.(JSON.parse(s))},[e]);return l(t).createElement(l(a),{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>r(!0),onMessage:n})},y=e=>t=>e(e=>l(r)(e,t)?e:t),g=e=>{if(!e)return null;let t=e.linked_accounts.find(e=>"wallet"===e.type&&"privy"===e.wallet_client_type&&"embedded"===e.connector_type);return t||null},m=e=>"object"==typeof e&&!!(e?.error&&e?.code),b=e=>t=>e instanceof Error?{status:"error",error:e}:m(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,f=({client:s,user:a,wallet:r,setWallet:i,isWebViewReady:n})=>{let o=(0,t.useMemo)(()=>g(a),[a]),u=(0,t.useCallback)(async e=>{i({status:"creating"});try{let t=await s.embeddedWallet.create(e);i({status:"connected",provider:t})}catch(e){i({status:"error",error:"Error creating embedded wallet"})}},[s]),c=(0,t.useCallback)(async e=>{if(o){i({status:"connecting"});try{let t=await s.embeddedWallet.getProvider(o,e);i({status:"connected",provider:t})}catch(e){i({status:"needs-recovery",recover:c})}}},[s,o]);return(0,t.useEffect)(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
2
2
  // the wallet returns to disconnected state along with a logged out user
3
3
  if(!a&&"disconnected"!==r.status)return i({status:"disconnected"});async function t(){// There is a user but no embedded wallet account
4
4
  // We need to create an embedded walert for this user
@@ -10,5 +10,5 @@ i({status:"connecting"});try{let e=await s.embeddedWallet.getProvider(o);i({stat
10
10
  n&&t()},[n,a,o])},C=({client:e,isUserInitialized:s,setIsUserInitialized:a})=>{(0,t.useEffect)(()=>{let t=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
11
11
  }finally{a(!0)}};s||t()},[s])},v=e=>"loading"!==e.status,w=()=>{let{oAuthState:e,client:s}=(0,t.useContext)(E),a=(0,t.useCallback)(async function({provider:e,redirectUri:t}){let{url:a}=await s.auth.oauth.generateURL(e,n.createURL(t||"/"));return n.openURL(a)},[s]);return{start:a,state:e}},x=({client:e,user:s,isUserInitialized:a,setOAuthState:r})=>{let i=n.useURL();return(0,t.useEffect)(()=>{let t=async()=>{if(!i){r({status:"done"});return}let{queryParams:t}=n.parse(i),{privy_oauth_state:a,privy_oauth_code:o}=t;if(!o||!a){r({status:"done"});return}r({status:"loading"});try{s?await e.auth.oauth.linkWithCode(o,a):await e.auth.oauth.loginWithCode(o,a),r({status:"done"})}catch(e){r(b(e))}// Since stripping query params off the url in place is not possible
12
12
  // navigating to the currentUrl less the query params should accomplish the same
13
- return n.openURL(i.split("?")[0])};a&&t()},[i,a])},k=()=>i.applicationId,S={get:e=>o.getItemAsync(e.replace(":","-")),put(e,t){o.setItemAsync(e.replace(":","-"),t)},del(e){o.deleteItemAsync(e.replace(":","-"))},getKeys:async()=>[]},E=/*#__PURE__*/(0,t.createContext)({}),W=a=>{let[r,i]=(0,t.useState)(!1),[n,o]=(0,t.useState)(!1),[u,c]=(0,t.useState)(null),[d,g]=(0,t.useState)({status:"disconnected"}),[m,b]=(0,t.useState)({status:"initial"}),[w,W]=(0,t.useState)({status:"initial"}),I=(0,t.useCallback)(e=>{if(e)return y(c)(e);c(null),b({status:"initial"}),W({status:"initial"}),g({status:"disconnected"})},[]),R=(0,t.useMemo)(()=>new(l(e))({storage:a.storage||S,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
13
+ return n.openURL(i.split("?")[0])};a&&t()},[i,a])},k=()=>i.applicationId,S={get:e=>o.getItemAsync(e.replace(":","-")),put:(e,t)=>o.setItemAsync(e.replace(":","-"),t),del:e=>o.deleteItemAsync(e.replace(":","-")),getKeys:async()=>[]},E=/*#__PURE__*/(0,t.createContext)({}),W=a=>{let[r,i]=(0,t.useState)(!1),[n,o]=(0,t.useState)(!1),[u,c]=(0,t.useState)(null),[d,g]=(0,t.useState)({status:"disconnected"}),[m,b]=(0,t.useState)({status:"initial"}),[w,W]=(0,t.useState)({status:"initial"}),I=(0,t.useCallback)(e=>{if(e)return y(c)(e);c(null),b({status:"initial"}),W({status:"initial"}),g({status:"disconnected"})},[]),R=(0,t.useMemo)(()=>new(l(e))({storage:a.storage||S,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
14
14
  nativeAppIdentifier:k(),baseUrl:a.baseUrl,sdkVersion:`expo:${/*@__PURE__*/l(p).version}`,callbacks:{setUser:I}}),[a.storage,a.appId,a.baseUrl,a.supportedChains,I]),A=(0,t.useCallback)(()=>(I(null),R.auth.logout()),[I,R]),U=(0,t.useCallback)(()=>R.getAccessToken(),[R]);return C({client:R,isUserInitialized:r,setIsUserInitialized:i}),f({client:R,user:u,isWebViewReady:n,wallet:d,setWallet:g}),x({client:R,isUserInitialized:r,user:u,setOAuthState:W}),l(t).createElement(l(t).Fragment,null,l(t).createElement(E.Provider,{value:{client:R,user:u,isReady:n&&r&&v(w),logout:A,getAccessToken:U,wallet:d,oAuthState:w,otpState:m,setOtpState:b}},a.children),l(t).createElement(s.View,{style:{width:0,height:0,overflow:"hidden"}},l(t).createElement(h,{client:R,isWebViewReady:n,setIsWebViewReady:o})))};var I={},R={};c(R,"isConnected",()=>A),c(R,"isConnecting",()=>U),c(R,"isDisconnected",()=>M),c(R,"isNotCreated",()=>j),c(R,"isCreating",()=>P),c(R,"hasError",()=>L),c(R,"needsRecovery",()=>O);const A=e=>"connected"===e.status,U=e=>"connecting"===e.status,M=e=>"disconnected"===e.status,j=e=>"not-created"===e.status,P=e=>"creating"===e.status,L=e=>"error"===e.status,O=e=>"needs-recovery"===e.status;u(I,R);var _={};c(_,"useLoginWithEmail",()=>q),c(_,"useLinkEmail",()=>z),c(_,"useLoginWithSMS",()=>V),c(_,"useLinkSMS",()=>N),c(_,"useEmbeddedWallet",()=>D),c(_,"usePrivyClient",()=>T),c(_,"usePrivy",()=>F);const q=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(E),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.loginWithCode(r,t);return i({status:"done"}),e}catch(e){i(b(e))}},[a,e]);return{sendCode:n,loginWithCode:o,state:r}},z=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(E),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.linkWithCode(r,t);return i({status:"done"}),e}catch(e){i(b(e))}},[a,e]);return{sendCode:n,linkWithCode:o,state:r}},V=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(E),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{i({status:"submitting-code"});let r=await a.auth.phone.loginWithCode(s||e,t);return i({status:"done"}),r}catch(e){i(b(e))}},[a,e]);return{sendCode:n,loginWithCode:o,state:r}},N=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(E),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{i({status:"submitting-code"});let r=await a.auth.phone.linkWithCode(s||e,t);return i({status:"done"}),r}catch(e){i(b(e))}},[a,e]);return{sendCode:n,linkWithCode:o,state:r}},D=()=>{let{wallet:e}=(0,t.useContext)(E);return e},T=()=>{let{client:e}=(0,t.useContext)(E);return e},F=()=>{let{user:e,isReady:s,logout:a,getAccessToken:r}=(0,t.useContext)(E);return{user:e,isReady:s,logout:a,getAccessToken:r}};u(module.exports,e),u(module.exports,d),u(module.exports,{}),u(module.exports,I),u(module.exports,_);
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as s,useCallback as r,useMemo as i,useRef as n,useEffect as o,useContext as c}from"react";import{View as d}from"react-native";import l from"react-native-webview";import u from"react-fast-compare";import{applicationId as p}from"expo-application";import{createURL as f,openURL as h,useURL as y,parse as b}from"expo-linking";import{getItemAsync as g,setItemAsync as m,deleteItemAsync as v}from"expo-secure-store";function $(e,t,a,s){Object.defineProperty(e,t,{get:a,set:s,enumerable:!0,configurable:!0})}var w,x={};$(x,"PrivyContext",()=>O),$(x,"PrivyProvider",()=>_);var C={};C=JSON.parse('{"name":"@privy-io/expo","version":"0.4.0","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.9.0","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');let W=({client:e,isWebViewReady:a,setIsWebViewReady:s})=>{let i=n(null);o(()=>{a&&i.current&&e.setMessagePoster(i.current)},[a,e]);let c=r(async t=>{let{data:a}=t.nativeEvent,s=e.embeddedWallet.getMessageHandler();s?.(JSON.parse(a))},[e]);return t.createElement(l,{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>s(!0),onMessage:c})},E=e=>t=>e(e=>u(e,t)?e:t),S=e=>{if(!e)return null;let t=e.linked_accounts.find(e=>"wallet"===e.type&&"privy"===e.wallet_client_type&&"embedded"===e.connector_type);return t||null},k=e=>"object"==typeof e&&!!(e?.error&&e?.code),I=e=>t=>e instanceof Error?{status:"error",error:e}:k(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,P=({client:e,user:t,wallet:a,setWallet:s,isWebViewReady:n})=>{let c=i(()=>S(t),[t]),d=r(async t=>{s({status:"creating"});try{let a=await e.embeddedWallet.create(t);s({status:"connected",provider:a})}catch(e){s({status:"error",error:"Error creating embedded wallet"})}},[e]),l=r(async t=>{if(c){s({status:"connecting"});try{let a=await e.embeddedWallet.getProvider(c,t);s({status:"connected",provider:a})}catch(e){s({status:"needs-recovery",recover:l})}}},[e,c]);return o(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
1
+ import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as s,useCallback as r,useMemo as i,useRef as n,useEffect as o,useContext as c}from"react";import{View as d}from"react-native";import l from"react-native-webview";import u from"react-fast-compare";import{applicationId as p}from"expo-application";import{createURL as f,openURL as h,useURL as y,parse as b}from"expo-linking";import{getItemAsync as g,setItemAsync as m,deleteItemAsync as v}from"expo-secure-store";function $(e,t,a,s){Object.defineProperty(e,t,{get:a,set:s,enumerable:!0,configurable:!0})}var w,x={};$(x,"PrivyContext",()=>O),$(x,"PrivyProvider",()=>_);var C={};C=JSON.parse('{"name":"@privy-io/expo","version":"0.4.1","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.9.1","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');let W=({client:e,isWebViewReady:a,setIsWebViewReady:s})=>{let i=n(null);o(()=>{a&&i.current&&e.setMessagePoster(i.current)},[a,e]);let c=r(async t=>{let{data:a}=t.nativeEvent,s=e.embeddedWallet.getMessageHandler();s?.(JSON.parse(a))},[e]);return t.createElement(l,{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>s(!0),onMessage:c})},E=e=>t=>e(e=>u(e,t)?e:t),S=e=>{if(!e)return null;let t=e.linked_accounts.find(e=>"wallet"===e.type&&"privy"===e.wallet_client_type&&"embedded"===e.connector_type);return t||null},k=e=>"object"==typeof e&&!!(e?.error&&e?.code),I=e=>t=>e instanceof Error?{status:"error",error:e}:k(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,P=({client:e,user:t,wallet:a,setWallet:s,isWebViewReady:n})=>{let c=i(()=>S(t),[t]),d=r(async t=>{s({status:"creating"});try{let a=await e.embeddedWallet.create(t);s({status:"connected",provider:a})}catch(e){s({status:"error",error:"Error creating embedded wallet"})}},[e]),l=r(async t=>{if(c){s({status:"connecting"});try{let a=await e.embeddedWallet.getProvider(c,t);s({status:"connected",provider:a})}catch(e){s({status:"needs-recovery",recover:l})}}},[e,c]);return o(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
2
2
  // the wallet returns to disconnected state along with a logged out user
3
3
  if(!t&&"disconnected"!==a.status)return s({status:"disconnected"});async function r(){// There is a user but no embedded wallet account
4
4
  // We need to create an embedded walert for this user
@@ -10,5 +10,5 @@ s({status:"connecting"});try{let t=await e.embeddedWallet.getProvider(c);s({stat
10
10
  n&&r()},[n,t,c])},R=({client:e,isUserInitialized:t,setIsUserInitialized:a})=>{o(()=>{let s=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
11
11
  }finally{a(!0)}};t||s()},[t])},A=e=>"loading"!==e.status,M=()=>{let{oAuthState:e,client:t}=c(O),a=r(async function({provider:e,redirectUri:a}){let{url:s}=await t.auth.oauth.generateURL(e,f(a||"/"));return h(s)},[t]);return{start:a,state:e}},L=({client:e,user:t,isUserInitialized:a,setOAuthState:s})=>{let r=y();return o(()=>{let i=async()=>{if(!r){s({status:"done"});return}let{queryParams:a}=b(r),{privy_oauth_state:i,privy_oauth_code:n}=a;if(!n||!i){s({status:"done"});return}s({status:"loading"});try{t?await e.auth.oauth.linkWithCode(n,i):await e.auth.oauth.loginWithCode(n,i),s({status:"done"})}catch(e){s(I(e))}// Since stripping query params off the url in place is not possible
12
12
  // navigating to the currentUrl less the query params should accomplish the same
13
- return h(r.split("?")[0])};a&&i()},[r,a])},U=()=>p,j={get:e=>g(e.replace(":","-")),put(e,t){m(e.replace(":","-"),t)},del(e){v(e.replace(":","-"))},getKeys:async()=>[]},O=a({}),_=a=>{let[n,o]=s(!1),[c,l]=s(!1),[u,p]=s(null),[f,h]=s({status:"disconnected"}),[y,b]=s({status:"initial"}),[g,m]=s({status:"initial"}),v=r(e=>{if(e)return E(p)(e);p(null),b({status:"initial"}),m({status:"initial"}),h({status:"disconnected"})},[]),$=i(()=>{var t;return new e({storage:a.storage||j,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
13
+ return h(r.split("?")[0])};a&&i()},[r,a])},U=()=>p,j={get:e=>g(e.replace(":","-")),put:(e,t)=>m(e.replace(":","-"),t),del:e=>v(e.replace(":","-")),getKeys:async()=>[]},O=a({}),_=a=>{let[n,o]=s(!1),[c,l]=s(!1),[u,p]=s(null),[f,h]=s({status:"disconnected"}),[y,b]=s({status:"initial"}),[g,m]=s({status:"initial"}),v=r(e=>{if(e)return E(p)(e);p(null),b({status:"initial"}),m({status:"initial"}),h({status:"disconnected"})},[]),$=i(()=>{var t;return new e({storage:a.storage||j,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
14
14
  nativeAppIdentifier:U(),baseUrl:a.baseUrl,sdkVersion:`expo:${((t=C)&&t.__esModule?t.default:t).version}`,callbacks:{setUser:v}})},[a.storage,a.appId,a.baseUrl,a.supportedChains,v]),w=r(()=>(v(null),$.auth.logout()),[v,$]),x=r(()=>$.getAccessToken(),[$]);return R({client:$,isUserInitialized:n,setIsUserInitialized:o}),P({client:$,user:u,isWebViewReady:c,wallet:f,setWallet:h}),L({client:$,isUserInitialized:n,user:u,setOAuthState:m}),t.createElement(t.Fragment,null,t.createElement(O.Provider,{value:{client:$,user:u,isReady:c&&n&&A(g),logout:w,getAccessToken:x,wallet:f,oAuthState:g,otpState:y,setOtpState:b}},a.children),t.createElement(d,{style:{width:0,height:0,overflow:"hidden"}},t.createElement(W,{client:$,isWebViewReady:c,setIsWebViewReady:l})))};var z={};$(z,"isConnected",()=>V),$(z,"isConnecting",()=>N),$(z,"isDisconnected",()=>D),$(z,"isNotCreated",()=>T),$(z,"isCreating",()=>q),$(z,"hasError",()=>F),$(z,"needsRecovery",()=>J);let V=e=>"connected"===e.status,N=e=>"connecting"===e.status,D=e=>"disconnected"===e.status,T=e=>"not-created"===e.status,q=e=>"creating"===e.status,F=e=>"error"===e.status,J=e=>"needs-recovery"===e.status;w={},Object.keys(z).forEach(function(e){"default"===e||"__esModule"===e||w.hasOwnProperty(e)||Object.defineProperty(w,e,{enumerable:!0,get:function(){return z[e]}})});var G={};$(G,"useLoginWithEmail",()=>H),$(G,"useLinkEmail",()=>K),$(G,"useLoginWithSMS",()=>Y),$(G,"useLinkSMS",()=>B),$(G,"useEmbeddedWallet",()=>Q),$(G,"usePrivyClient",()=>X),$(G,"usePrivy",()=>Z);let H=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(O),o=r(async({email:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.email.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(I(e))}},[a]),d=r(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{n({status:"submitting-code"});let e=await a.auth.email.loginWithCode(r,t);return n({status:"done"}),e}catch(e){n(I(e))}},[a,e]);return{sendCode:o,loginWithCode:d,state:i}},K=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(O),o=r(async({email:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.email.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(I(e))}},[a]),d=r(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{n({status:"submitting-code"});let e=await a.auth.email.linkWithCode(r,t);return n({status:"done"}),e}catch(e){n(I(e))}},[a,e]);return{sendCode:o,linkWithCode:d,state:i}},Y=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(O),o=r(async({phone:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.phone.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(I(e))}},[a]),d=r(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{n({status:"submitting-code"});let r=await a.auth.phone.loginWithCode(s||e,t);return n({status:"done"}),r}catch(e){n(I(e))}},[a,e]);return{sendCode:o,loginWithCode:d,state:i}},B=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(O),o=r(async({phone:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.phone.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(I(e))}},[a]),d=r(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{n({status:"submitting-code"});let r=await a.auth.phone.linkWithCode(s||e,t);return n({status:"done"}),r}catch(e){n(I(e))}},[a,e]);return{sendCode:o,linkWithCode:d,state:i}},Q=()=>{let{wallet:e}=c(O);return e},X=()=>{let{client:e}=c(O);return e},Z=()=>{let{user:e,isReady:t,logout:a,getAccessToken:s}=c(O);return{user:e,isReady:t,logout:a,getAccessToken:s}};export{S as getUserEmbeddedWallet,j as SecureStorageAdapter,M as useOAuthFlow,O as PrivyContext,_ as PrivyProvider,V as isConnected,N as isConnecting,D as isDisconnected,T as isNotCreated,q as isCreating,F as hasError,J as needsRecovery,H as useLoginWithEmail,K as useLinkEmail,Y as useLoginWithSMS,B as useLinkSMS,Q as useEmbeddedWallet,X as usePrivyClient,Z as usePrivy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/expo",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Expo client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -61,7 +61,7 @@
61
61
  "expo-application": "*"
62
62
  },
63
63
  "dependencies": {
64
- "@privy-io/js-sdk-core": "0.9.0",
64
+ "@privy-io/js-sdk-core": "0.9.1",
65
65
  "react-fast-compare": "^3.2.2"
66
66
  },
67
67
  "devDependencies": {