@privy-io/expo 0.2.2 → 0.3.0-beta-20231101213309
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.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.mjs +7 -7
- package/package.json +6 -5
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;ACEA,oCAAoC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,2BAA2B,CAAC;CACvC,CAAC;AAEF,qCAAqC;IACnC,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,uCAAuC;IACrC,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,wCAAwC;IACtC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,qCAAqC;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,mCAAmC;IACjC,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,gCAAgC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,kCACI,4BAA4B,GAC5B,6BAA6B,GAC7B,+BAA+B,GAC/B,gCAAgC,GAChC,2BAA2B,GAC3B,6BAA6B,GAC7B,wBAAwB,CAAC;AAE7B,mCAAmC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,OAAO,MAAM,iBAAkB,mBAAmB,sCACxB,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,OAAO,MAAM,kBAAmB,mBAAmB,uCACxB,CAAC;AAG5B,OAAO,MAAM,oBAAqB,mB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H,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAMnB,CAAC;AAEF,OAAO,MAAM,uBAAwB,kBAAkB,sBAsDtD,CAAC;ACvHF,cAAc,uBAAuB,CAAC","sources":["packages-js-public/expo/src/src/context/EmbeddedWalletWebView.tsx","packages-js-public/expo/src/src/models/EmbeddedWalletState.ts","packages-js-public/expo/src/src/models/index.ts","packages-js-public/expo/src/src/utils/toStableSetter.ts","packages-js-public/expo/src/src/types.ts","packages-js-public/expo/src/src/utils/getUserEmbeddedWallet.ts","packages-js-public/expo/src/src/utils/toErrorState.ts","packages-js-public/expo/src/src/utils/index.ts","packages-js-public/expo/src/src/context/useConnectEmbeddedWallet.ts","packages-js-public/expo/src/src/context/useInitializeUser.ts","packages-js-public/expo/src/src/context/useRNAppStateToFetchUserOnAppResume.ts","packages-js-public/expo/src/src/expo.ts","packages-js-public/expo/src/src/hooks/hooks.types.ts","packages-js-public/expo/src/src/hooks/useLoginWithEmail.ts","packages-js-public/expo/src/src/hooks/useLinkEmail.ts","packages-js-public/expo/src/src/hooks/useLoginWithSMS.ts","packages-js-public/expo/src/src/hooks/useLinkSMS.ts","packages-js-public/expo/src/src/hooks/useEmbeddedWallet.ts","packages-js-public/expo/src/src/hooks/usePrivyClient.ts","packages-js-public/expo/src/src/hooks/usePrivy.ts","packages-js-public/expo/src/src/hooks/index.ts","packages-js-public/expo/src/src/PrivyProvider.tsx","packages-js-public/expo/src/src/index.ts","packages-js-public/expo/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"export * from '@privy-io/js-sdk-core';\nexport * from './PrivyProvider';\nexport * from './types';\nexport * from './models';\nexport * from './hooks';\nexport {getUserEmbeddedWallet} from './utils';\nexport {SecureStorageAdapter, useOAuthFlow} from './expo';\nexport type {OAuthFlowState} from './expo';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),
|
|
1
|
+
var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),r=require("react-native-webview"),a=require("react-fast-compare"),i=require("expo-application"),n=require("expo-linking"),o=require("expo-secure-store");function c(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 u(e,t,s,r){Object.defineProperty(e,t,{get:s,set:r,enumerable:!0,configurable:!0})}function l(e){return e&&e.__esModule?e.default:e}u(module.exports,"getUserEmbeddedWallet",()=>g),u(module.exports,"SecureStorageAdapter",()=>k),u(module.exports,"useOAuthFlow",()=>x);var d={};u(d,"PrivyContext",()=>W),u(d,"PrivyProvider",()=>I);var p={};p=JSON.parse('{"name":"@privy-io/expo","version":"0.3.0-beta-20231101213309","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","prepublishOnly":"npm run clean && npm run build","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/unit/**/*.test.ts\\"","test:ci":"npm run test","test-integration":"jest --testMatch \\"**/test/integration/**/*.test.ts\\"","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.7.0-beta-20231101213309","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:a})=>{let i=(0,t.useRef)(null);(0,t.useEffect)(()=>{i.current&&e.setMessagePoster(i.current)},[s,e]);let n=(0,t.useCallback)(async t=>{let{data:s}=t.nativeEvent,r=e.embeddedWallet.getMessageHandler();r?.(JSON.parse(s))},[e]);return l(t).createElement(l(r),{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>a(!0),onMessage:n})},y=e=>t=>e(e=>l(a)(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:r,setWallet:a,isWebViewReady:i})=>{let n=(0,t.useCallback)(async e=>{a({status:"creating"});try{let t=await s.embeddedWallet.create(e);a({status:"connected",provider:t})}catch(e){a({status:"error",error:"Error creating embedded wallet"})}},[s]),o=(0,t.useCallback)(async e=>{a({status:"connecting"});try{let t=await s.embeddedWallet.getProvider(e);a({status:"connected",provider:t})}catch(e){a({status:"error",error:"Error creating embedded wallet"})}},[s]);return(0,t.useEffect)(()=>{let t=async()=>{let t=!!g(r);// There is a user but no embedded wallet account
|
|
2
2
|
// We need to create an embedded walert for this user
|
|
3
|
-
if(
|
|
3
|
+
if(r&&!t){a({status:"not-created",create:n});return}// There is no embedded wallet account and there is also no user
|
|
4
4
|
// No change in state
|
|
5
5
|
if(t){// There is definitely a user with an embedded wallet
|
|
6
6
|
// so we try to connect and get a provider
|
|
7
7
|
// `getProvider` will internally attempt recovery of `pinless` wallets
|
|
8
8
|
// Otherwise, let the user know they need to prompt for recovery
|
|
9
|
-
|
|
10
|
-
i&&t()},[i,
|
|
11
|
-
}finally{
|
|
9
|
+
a({status:"connecting"});try{let e=await s.embeddedWallet.getProvider();a({status:"connected",provider:e})}catch(t){(0,e.errorIndicatesRecoveryIsNeeded)(t)?a({status:"needs-recovery",recover:o}):a({status:"error",error:"Error loading embedded wallet"})}}};// Automatically run on first load, once we know the iframe is loaded
|
|
10
|
+
i&&t()},[i,r])},v=({client:e,isUserInitialized:s,setIsUserInitialized:r})=>{(0,t.useEffect)(()=>{let t=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
|
|
11
|
+
}finally{r(!0)}};s||t()},[s])},C=({client:e})=>{let r=(0,t.useRef)(s.AppState.currentState);(0,t.useEffect)(()=>{let t=(0,s.AppState).addEventListener("change",t=>{r.current.match(/inactive|background/)&&"active"===t&&e.user.get().catch(()=>{}),r.current=t});return()=>{t.remove()}},[])},w=e=>"done"===e.status||"error"===e.status,x=()=>{let{oAuthState:e,client:s}=(0,t.useContext)(W),r=(0,t.useCallback)(async function({provider:e,redirectUri:t}){let{url:r}=await s.auth.oauth.generateURL(e,n.createURL(t||"/"));return n.openURL(r)},[s]);return{start:r,state:e}},S=({client:e,user:s,isUserInitialized:r,setOAuthState:a})=>{let i=n.useURL();return(0,t.useEffect)(()=>{let t=async()=>{if(!i){a({status:"done"});return}let{queryParams:t}=n.parse(i),{privy_oauth_state:r,privy_oauth_code:o}=t;if(!o||!r){a({status:"done"});return}a({status:"loading"});try{s?await e.auth.oauth.linkWithCode(o,r):await e.auth.oauth.loginWithCode(o,r),a({status:"done"})}catch(e){a(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])};
|
|
14
|
-
|
|
13
|
+
return n.openURL(i.split("?")[0])};r&&t()},[i,r])},E=()=>i.applicationId,k={get:e=>o.getItemAsync(e.replace(":","-")),put(e,t){o.setItemAsync(e.replace(":","-"),t)},del(e){o.deleteItemAsync(e.replace(":","-"))},getKeys:async()=>[]},W=/*#__PURE__*/(0,t.createContext)({}),I=r=>{let[a,i]=(0,t.useState)(!1),[n,o]=(0,t.useState)(!1),[c,u]=(0,t.useState)(null),[d,g]=(0,t.useState)({status:"initial"}),[m,b]=(0,t.useState)({status:"disconnected"}),[x,I]=(0,t.useState)({status:"initial"}),R=(0,t.useMemo)(()=>new(l(e))({storage:r.storage||k,appId:r.appId,// @ts-expect-error config for internal use only
|
|
14
|
+
nativeAppIdentifier:E(),baseUrl:r.baseUrl,sdkVersion:`expo:${/*@__PURE__*/l(p).version}`,callbacks:{setUser:y(u)}}),[r.storage,r.appId,r.baseUrl,u]);return C({client:R}),v({client:R,isUserInitialized:a,setIsUserInitialized:i}),f({client:R,user:c,isWebViewReady:n,setWallet:b}),S({client:R,isUserInitialized:a,user:c,setOAuthState:g}),l(t).createElement(l(t).Fragment,null,l(t).createElement(W.Provider,{value:{client:R,user:c,isReady:n&&a&&w(d),wallet:m,oAuthState:d,otpState:x,setOtpState:I}},r.children),l(t).createElement(s.View,{style:{width:0,height:0,overflow:"hidden"}},l(t).createElement(h,{client:R,isWebViewReady:n,setIsWebViewReady:o})))};var R={},U={};u(U,"isConnected",()=>M),u(U,"isConnecting",()=>j),u(U,"isDisconnected",()=>A),u(U,"isNotCreated",()=>L),u(U,"isCreating",()=>O),u(U,"hasError",()=>P),u(U,"needsRecovery",()=>_);const M=e=>"connected"===e.status,j=e=>"connecting"===e.status,A=e=>"disconnected"===e.status,L=e=>"not-created"===e.status,O=e=>"creating"===e.status,P=e=>"error"===e.status,_=e=>"needs-recovery"===e.status;c(R,U);var q={};u(q,"useLoginWithEmail",()=>z),u(q,"useLinkEmail",()=>V),u(q,"useLoginWithSMS",()=>N),u(q,"useLinkSMS",()=>D),u(q,"useEmbeddedWallet",()=>F),u(q,"usePrivyClient",()=>J),u(q,"usePrivy",()=>H);const z=()=>{let[e,s]=(0,t.useState)(""),{client:r,otpState:a,setOtpState:i}=(0,t.useContext)(W),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await r.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[r]),o=(0,t.useCallback)(async({code:t,email:s})=>{let a=s||e;if(!a)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{i({status:"submitting-code"});let e=await r.auth.email.loginWithCode(a,t);return i({status:"done"}),e}catch(e){i(b(e))}},[r,e]);return{sendCode:n,loginWithCode:o,state:a}},V=()=>{let[e,s]=(0,t.useState)(""),{client:r,otpState:a,setOtpState:i}=(0,t.useContext)(W),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await r.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[r]),o=(0,t.useCallback)(async({code:t,email:s})=>{let a=s||e;if(!a)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{i({status:"submitting-code"});let e=await r.auth.email.linkWithCode(a,t);return i({status:"done"}),e}catch(e){i(b(e))}},[r,e]);return{sendCode:n,linkWithCode:o,state:a}},N=()=>{let[e,s]=(0,t.useState)(""),{client:r,otpState:a,setOtpState:i}=(0,t.useContext)(W),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await r.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[r]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let a=s||e;if(!a)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{i({status:"submitting-code"});let a=await r.auth.phone.loginWithCode(s||e,t);return i({status:"done"}),a}catch(e){i(b(e))}},[r,e]);return{sendCode:n,loginWithCode:o,state:a}},D=()=>{let[e,s]=(0,t.useState)(""),{client:r,otpState:a,setOtpState:i}=(0,t.useContext)(W),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await r.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[r]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let a=s||e;if(!a)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{i({status:"submitting-code"});let a=await r.auth.phone.linkWithCode(s||e,t);return i({status:"done"}),a}catch(e){i(b(e))}},[r,e]);return{sendCode:n,linkWithCode:o,state:a}},F=()=>{let{wallet:e}=(0,t.useContext)(W);return e},J=()=>{let{client:e}=(0,t.useContext)(W);return e},H=()=>{let{user:e,isReady:s,client:r}=(0,t.useContext)(W),a=(0,t.useCallback)(()=>r.auth.logout(),[r]);return{user:e,isReady:s,logout:a}};c(module.exports,e),c(module.exports,d),c(module.exports,{}),c(module.exports,R),c(module.exports,q);
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as
|
|
1
|
+
import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as r,useMemo as s,useRef as i,useEffect as n,useCallback as o,useContext as c}from"react";import{View as d,AppState as l}from"react-native";import u from"react-native-webview";import p from"react-fast-compare";import{applicationId as h}from"expo-application";import{createURL as b,openURL as f,useURL as y,parse as m}from"expo-linking";import{getItemAsync as g,setItemAsync as v,deleteItemAsync as $}from"expo-secure-store";function w(e,t,a,r){Object.defineProperty(e,t,{get:a,set:r,enumerable:!0,configurable:!0})}var x,C={};w(C,"PrivyContext",()=>z),w(C,"PrivyProvider",()=>V);var E={};E=JSON.parse('{"name":"@privy-io/expo","version":"0.3.0-beta-20231101213309","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","prepublishOnly":"npm run clean && npm run build","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/unit/**/*.test.ts\\"","test:ci":"npm run test","test-integration":"jest --testMatch \\"**/test/integration/**/*.test.ts\\"","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.7.0-beta-20231101213309","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:r})=>{let s=i(null);n(()=>{s.current&&e.setMessagePoster(s.current)},[a,e]);let c=o(async t=>{let{data:a}=t.nativeEvent,r=e.embeddedWallet.getMessageHandler();r?.(JSON.parse(a))},[e]);return t.createElement(u,{style:{flex:1},ref:s,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>r(!0),onMessage:c})},S=e=>t=>e(e=>p(e,t)?e:t),k=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},I=e=>"object"==typeof e&&!!(e?.error&&e?.code),P=e=>t=>e instanceof Error?{status:"error",error:e}:I(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,M=({client:e,user:t,setWallet:a,isWebViewReady:r})=>{let s=o(async t=>{a({status:"creating"});try{let r=await e.embeddedWallet.create(t);a({status:"connected",provider:r})}catch(e){a({status:"error",error:"Error creating embedded wallet"})}},[e]),i=o(async t=>{a({status:"connecting"});try{let r=await e.embeddedWallet.getProvider(t);a({status:"connected",provider:r})}catch(e){a({status:"error",error:"Error creating embedded wallet"})}},[e]);return n(()=>{let n=async()=>{let r=!!k(t);// There is a user but no embedded wallet account
|
|
2
2
|
// We need to create an embedded walert for this user
|
|
3
|
-
if(t&&!
|
|
3
|
+
if(t&&!r){a({status:"not-created",create:s});return}// There is no embedded wallet account and there is also no user
|
|
4
4
|
// No change in state
|
|
5
|
-
if(
|
|
5
|
+
if(r){// There is definitely a user with an embedded wallet
|
|
6
6
|
// so we try to connect and get a provider
|
|
7
7
|
// `getProvider` will internally attempt recovery of `pinless` wallets
|
|
8
8
|
// Otherwise, let the user know they need to prompt for recovery
|
|
9
9
|
a({status:"connecting"});try{let t=await e.embeddedWallet.getProvider();a({status:"connected",provider:t})}catch(e){$diYGi$errorIndicatesRecoveryIsNeeded(e)?a({status:"needs-recovery",recover:i}):a({status:"error",error:"Error loading embedded wallet"})}}};// Automatically run on first load, once we know the iframe is loaded
|
|
10
|
-
|
|
11
|
-
}finally{a(!0)}};t||
|
|
10
|
+
r&&n()},[r,t])},R=({client:e,isUserInitialized:t,setIsUserInitialized:a})=>{n(()=>{let r=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
|
|
11
|
+
}finally{a(!0)}};t||r()},[t])},L=({client:e})=>{let t=i(l.currentState);n(()=>{let a=l.addEventListener("change",a=>{t.current.match(/inactive|background/)&&"active"===a&&e.user.get().catch(()=>{}),t.current=a});return()=>{a.remove()}},[])},U=e=>"done"===e.status||"error"===e.status,j=()=>{let{oAuthState:e,client:t}=c(z),a=o(async function({provider:e,redirectUri:a}){let{url:r}=await t.auth.oauth.generateURL(e,b(a||"/"));return f(r)},[t]);return{start:a,state:e}},A=({client:e,user:t,isUserInitialized:a,setOAuthState:r})=>{let s=y();return n(()=>{let i=async()=>{if(!s){r({status:"done"});return}let{queryParams:a}=m(s),{privy_oauth_state:i,privy_oauth_code:n}=a;if(!n||!i){r({status:"done"});return}r({status:"loading"});try{t?await e.auth.oauth.linkWithCode(n,i):await e.auth.oauth.loginWithCode(n,i),r({status:"done"})}catch(e){r(P(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 f(
|
|
14
|
-
|
|
13
|
+
return f(s.split("?")[0])};a&&i()},[s,a])},O=()=>h,_={get:e=>g(e.replace(":","-")),put(e,t){v(e.replace(":","-"),t)},del(e){$(e.replace(":","-"))},getKeys:async()=>[]},z=a({}),V=a=>{let[i,n]=r(!1),[o,c]=r(!1),[l,u]=r(null),[p,h]=r({status:"initial"}),[b,f]=r({status:"disconnected"}),[y,m]=r({status:"initial"}),g=s(()=>{var t;return new e({storage:a.storage||_,appId:a.appId,// @ts-expect-error config for internal use only
|
|
14
|
+
nativeAppIdentifier:O(),baseUrl:a.baseUrl,sdkVersion:`expo:${((t=E)&&t.__esModule?t.default:t).version}`,callbacks:{setUser:S(u)}})},[a.storage,a.appId,a.baseUrl,u]);return L({client:g}),R({client:g,isUserInitialized:i,setIsUserInitialized:n}),M({client:g,user:l,isWebViewReady:o,setWallet:f}),A({client:g,isUserInitialized:i,user:l,setOAuthState:h}),t.createElement(t.Fragment,null,t.createElement(z.Provider,{value:{client:g,user:l,isReady:o&&i&&U(p),wallet:b,oAuthState:p,otpState:y,setOtpState:m}},a.children),t.createElement(d,{style:{width:0,height:0,overflow:"hidden"}},t.createElement(W,{client:g,isWebViewReady:o,setIsWebViewReady:c})))};var N={};w(N,"isConnected",()=>D),w(N,"isConnecting",()=>q),w(N,"isDisconnected",()=>F),w(N,"isNotCreated",()=>J),w(N,"isCreating",()=>G),w(N,"hasError",()=>H),w(N,"needsRecovery",()=>K);let D=e=>"connected"===e.status,q=e=>"connecting"===e.status,F=e=>"disconnected"===e.status,J=e=>"not-created"===e.status,G=e=>"creating"===e.status,H=e=>"error"===e.status,K=e=>"needs-recovery"===e.status;x={},Object.keys(N).forEach(function(e){"default"===e||"__esModule"===e||x.hasOwnProperty(e)||Object.defineProperty(x,e,{enumerable:!0,get:function(){return N[e]}})});var Y={};w(Y,"useLoginWithEmail",()=>B),w(Y,"useLinkEmail",()=>Q),w(Y,"useLoginWithSMS",()=>T),w(Y,"useLinkSMS",()=>X),w(Y,"useEmbeddedWallet",()=>Z),w(Y,"usePrivyClient",()=>ee),w(Y,"usePrivy",()=>et);let B=()=>{let[e,t]=r(""),{client:a,otpState:s,setOtpState:i}=c(z),n=o(async({email:e})=>{t(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(P(e))}},[a]),d=o(async({code:t,email:r})=>{let s=r||e;if(!s)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.loginWithCode(s,t);return i({status:"done"}),e}catch(e){i(P(e))}},[a,e]);return{sendCode:n,loginWithCode:d,state:s}},Q=()=>{let[e,t]=r(""),{client:a,otpState:s,setOtpState:i}=c(z),n=o(async({email:e})=>{t(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(P(e))}},[a]),d=o(async({code:t,email:r})=>{let s=r||e;if(!s)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.linkWithCode(s,t);return i({status:"done"}),e}catch(e){i(P(e))}},[a,e]);return{sendCode:n,linkWithCode:d,state:s}},T=()=>{let[e,t]=r(""),{client:a,otpState:s,setOtpState:i}=c(z),n=o(async({phone:e})=>{t(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(P(e))}},[a]),d=o(async({code:t,phone:r})=>{let s=r||e;if(!s)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{i({status:"submitting-code"});let s=await a.auth.phone.loginWithCode(r||e,t);return i({status:"done"}),s}catch(e){i(P(e))}},[a,e]);return{sendCode:n,loginWithCode:d,state:s}},X=()=>{let[e,t]=r(""),{client:a,otpState:s,setOtpState:i}=c(z),n=o(async({phone:e})=>{t(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(P(e))}},[a]),d=o(async({code:t,phone:r})=>{let s=r||e;if(!s)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{i({status:"submitting-code"});let s=await a.auth.phone.linkWithCode(r||e,t);return i({status:"done"}),s}catch(e){i(P(e))}},[a,e]);return{sendCode:n,linkWithCode:d,state:s}},Z=()=>{let{wallet:e}=c(z);return e},ee=()=>{let{client:e}=c(z);return e},et=()=>{let{user:e,isReady:t,client:a}=c(z),r=o(()=>a.auth.logout(),[a]);return{user:e,isReady:t,logout:r}};export{k as getUserEmbeddedWallet,_ as SecureStorageAdapter,j as useOAuthFlow,z as PrivyContext,V as PrivyProvider,D as isConnected,q as isConnecting,F as isDisconnected,J as isNotCreated,G as isCreating,H as hasError,K as needsRecovery,B as useLoginWithEmail,Q as useLinkEmail,T as useLoginWithSMS,X as useLinkSMS,Z as useEmbeddedWallet,ee as usePrivyClient,et as usePrivy};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privy-io/expo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta-20231101213309",
|
|
4
4
|
"description": "Expo client for the Privy Auth API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -59,18 +59,19 @@
|
|
|
59
59
|
"react-native-webview": "*",
|
|
60
60
|
"expo-constants": "*",
|
|
61
61
|
"expo-linking": "*",
|
|
62
|
-
"expo-secure-store": "*"
|
|
62
|
+
"expo-secure-store": "*",
|
|
63
|
+
"expo-application": "*"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@privy-io/js-sdk-core": "
|
|
66
|
+
"@privy-io/js-sdk-core": "0.7.0-beta-20231101213309",
|
|
66
67
|
"react-fast-compare": "^3.2.2"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
70
|
"@privy-io/eslint-config-custom": "*",
|
|
71
|
+
"@privy-io/parcel-config": "*",
|
|
70
72
|
"@privy-io/tsconfig": "*",
|
|
71
73
|
"@tsconfig/node16-strictest-esm": "^1.0.3",
|
|
72
|
-
"parcel": "2.10.
|
|
73
|
-
"tsup": "^6.2.3",
|
|
74
|
+
"parcel": "2.10.1",
|
|
74
75
|
"typescript": "^4.9.5"
|
|
75
76
|
},
|
|
76
77
|
"author": "privy.io",
|