@account-kit/privy-integration 4.73.1-alpha.2 → 4.73.1-alpha.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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React Native stub for web Provider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
6
+ export declare function useAlchemyConfig(): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React Native stub for web Provider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export function AlchemyProvider() {
6
+ throw new Error("Web Provider is not available in React Native. " +
7
+ 'Import from "@account-kit/privy-integration/react-native" instead.');
8
+ }
9
+ export function useAlchemyConfig() {
10
+ throw new Error("useAlchemyConfig from web Provider is not available in React Native. " +
11
+ 'Import from "@account-kit/privy-integration/react-native" instead.');
12
+ }
13
+ //# sourceMappingURL=Provider.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Provider.native.js","sourceRoot":"","sources":["../../src/Provider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,KAAK,CACb,iDAAiD;QAC/C,oEAAoE,CACvE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,KAAK,CACb,uEAAuE;QACrE,oEAAoE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * React Native stub for web Provider\n * This file prevents Metro from importing web-specific code\n */\n\nexport function AlchemyProvider() {\n throw new Error(\n \"Web Provider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n\nexport function useAlchemyConfig() {\n throw new Error(\n \"useAlchemyConfig from web Provider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React Native stub for web adapter
3
+ * This file prevents Metro from importing @privy-io/react-auth
4
+ */
5
+ export declare const webAdapter: null;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React Native stub for web adapter
3
+ * This file prevents Metro from importing @privy-io/react-auth
4
+ */
5
+ export const webAdapter = null;
6
+ //# sourceMappingURL=web.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.native.js","sourceRoot":"","sources":["../../../src/adapters/web.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC","sourcesContent":["/**\n * React Native stub for web adapter\n * This file prevents Metro from importing @privy-io/react-auth\n */\n\nexport const webAdapter = null;\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export function AlchemyProvider() {
6
+ throw new Error("WebProvider is not available in React Native. " +
7
+ 'Import from "@account-kit/privy-integration/react-native" instead.');
8
+ }
9
+ //# sourceMappingURL=WebProvider.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebProvider.native.js","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,KAAK,CACb,gDAAgD;QAC9C,oEAAoE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * React Native stub for WebProvider\n * This file prevents Metro from importing web-specific code\n */\n\nexport function AlchemyProvider() {\n throw new Error(\n \"WebProvider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.73.1-alpha.2";
1
+ export declare const VERSION = "4.73.1-alpha.3";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.73.1-alpha.2";
3
+ export const VERSION = "4.73.1-alpha.3";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.73.1-alpha.2\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.73.1-alpha.3\";\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React Native stub for web Provider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
6
+ export declare function useAlchemyConfig(): void;
7
+ //# sourceMappingURL=Provider.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Provider.native.d.ts","sourceRoot":"","sources":["../../src/Provider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B;AAED,wBAAgB,gBAAgB,SAK/B"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React Native stub for web adapter
3
+ * This file prevents Metro from importing @privy-io/react-auth
4
+ */
5
+ export declare const webAdapter: null;
6
+ //# sourceMappingURL=web.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.native.d.ts","sourceRoot":"","sources":["../../../src/adapters/web.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,UAAU,MAAO,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
6
+ //# sourceMappingURL=WebProvider.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebProvider.native.d.ts","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.73.1-alpha.2";
1
+ export declare const VERSION = "4.73.1-alpha.3";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/privy-integration",
3
- "version": "4.73.1-alpha.2",
3
+ "version": "4.73.1-alpha.3",
4
4
  "description": "Use Alchemy gas sponsorship, swaps and more with Privy",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -10,11 +10,19 @@
10
10
  "module": "./dist/esm/index.js",
11
11
  "types": "./dist/types/index.d.ts",
12
12
  "typings": "./dist/types/index.d.ts",
13
- "react-native": "./dist/esm/react-native.js",
14
13
  "sideEffects": false,
14
+ "react-native": {
15
+ "main": "./dist/esm/react-native.js",
16
+ "./dist/esm/adapters/web.js": "./dist/esm/adapters/web.native.js",
17
+ "./dist/esm/providers/WebProvider.js": "./dist/esm/providers/WebProvider.native.js",
18
+ "./dist/esm/Provider.js": "./dist/esm/Provider.native.js",
19
+ "@privy-io/react-auth": false,
20
+ "@privy-io/react-auth/solana": false
21
+ },
15
22
  "files": [
16
23
  "dist",
17
24
  "src/**/*.ts",
25
+ "src/**/*.tsx",
18
26
  "!dist/**/*.tsbuildinfo",
19
27
  "!vitest.config.ts",
20
28
  "!.env",
@@ -56,8 +64,8 @@
56
64
  "typescript-template": "*"
57
65
  },
58
66
  "dependencies": {
59
- "@account-kit/infra": "^4.73.1-alpha.2",
60
- "@account-kit/wallet-client": "^4.73.1-alpha.2"
67
+ "@account-kit/infra": "^4.73.1-alpha.3",
68
+ "@account-kit/wallet-client": "^4.73.1-alpha.3"
61
69
  },
62
70
  "peerDependencies": {
63
71
  "@privy-io/expo": "^0.58.0",
@@ -87,5 +95,5 @@
87
95
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
88
96
  },
89
97
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
90
- "gitHead": "a453772c21ab2fab5ff0093b4168eb8e3fe73b89"
98
+ "gitHead": "441fb5248356d672e1f868829bb818009f878f5c"
91
99
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * React Native stub for web Provider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+
6
+ export function AlchemyProvider() {
7
+ throw new Error(
8
+ "Web Provider is not available in React Native. " +
9
+ 'Import from "@account-kit/privy-integration/react-native" instead.',
10
+ );
11
+ }
12
+
13
+ export function useAlchemyConfig() {
14
+ throw new Error(
15
+ "useAlchemyConfig from web Provider is not available in React Native. " +
16
+ 'Import from "@account-kit/privy-integration/react-native" instead.',
17
+ );
18
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Web-specific exports
3
+ * Re-exports the web provider and hooks for React applications
4
+ */
5
+ export { AlchemyProvider } from "./providers/WebProvider.js";
6
+ export { useAlchemyConfig } from "./context/AlchemyContext.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React Native stub for web adapter
3
+ * This file prevents Metro from importing @privy-io/react-auth
4
+ */
5
+
6
+ export const webAdapter = null;
@@ -0,0 +1,162 @@
1
+ import {
2
+ type PropsWithChildren,
3
+ createContext,
4
+ useContext,
5
+ useRef,
6
+ useEffect,
7
+ } from "react";
8
+ import type { SmartWalletClient } from "@account-kit/wallet-client";
9
+ import type { AlchemyProviderConfig } from "../types.js";
10
+ import type { PrivyAdapter } from "../adapters/types.js";
11
+
12
+ /**
13
+ * Context for Alchemy configuration
14
+ */
15
+ const AlchemyConfigContext = createContext<AlchemyProviderConfig | null>(null);
16
+
17
+ /**
18
+ * Context for the platform adapter
19
+ */
20
+ const AdapterContext = createContext<PrivyAdapter | null>(null);
21
+
22
+ /**
23
+ * Client cache stored in React tree (similar to QueryClient in React Query)
24
+ *
25
+ * @internal
26
+ */
27
+ interface ClientCache {
28
+ client: SmartWalletClient | null;
29
+ cacheKey: string | null;
30
+ }
31
+
32
+ const ClientCacheContext = createContext<ClientCache | null>(null);
33
+
34
+ /**
35
+ * Props for AlchemyContextProvider
36
+ */
37
+ interface AlchemyContextProviderProps extends PropsWithChildren {
38
+ config: AlchemyProviderConfig;
39
+ adapter: PrivyAdapter;
40
+ }
41
+
42
+ /**
43
+ * Internal provider component that manages Alchemy context
44
+ * Used by both web and React Native providers
45
+ *
46
+ * @internal
47
+ * @param {AlchemyContextProviderProps} props - Component props
48
+ * @param {React.ReactNode} props.children - React children to wrap with context
49
+ * @param {AlchemyProviderConfig} props.config - Alchemy configuration
50
+ * @param {PrivyAdapter} props.adapter - Platform adapter
51
+ * @returns {JSX.Element} Context provider component
52
+ */
53
+ export function AlchemyContextProvider({
54
+ children,
55
+ config,
56
+ adapter,
57
+ }: AlchemyContextProviderProps) {
58
+ const { authenticated, user } = adapter.usePrivyAuth();
59
+
60
+ // Store cache in a ref - persists across renders but scoped to this component instance
61
+ // This makes it SSR-safe (each request gets its own cache) and React StrictMode-safe
62
+ const cache = useRef<ClientCache>({
63
+ client: null,
64
+ cacheKey: null,
65
+ });
66
+
67
+ // Track previous state to detect logout and wallet changes
68
+ const prevAuthenticatedRef = useRef(authenticated);
69
+ const prevWalletAddressRef = useRef(user?.wallet?.address);
70
+
71
+ // Automatically reset cache when user logs out or switches wallets
72
+ useEffect(() => {
73
+ const wasAuthenticated = prevAuthenticatedRef.current;
74
+ const prevWalletAddress = prevWalletAddressRef.current;
75
+ const currentWalletAddress = user?.wallet?.address;
76
+
77
+ // Reset cache on logout
78
+ if (wasAuthenticated && !authenticated) {
79
+ cache.current.client = null;
80
+ cache.current.cacheKey = null;
81
+ }
82
+
83
+ // Reset cache on wallet address change (account switching)
84
+ if (
85
+ authenticated &&
86
+ prevWalletAddress &&
87
+ currentWalletAddress &&
88
+ prevWalletAddress !== currentWalletAddress
89
+ ) {
90
+ cache.current.client = null;
91
+ cache.current.cacheKey = null;
92
+ }
93
+
94
+ // Update refs for next render
95
+ prevAuthenticatedRef.current = authenticated;
96
+ prevWalletAddressRef.current = currentWalletAddress;
97
+ }, [authenticated, user?.wallet?.address]);
98
+
99
+ return (
100
+ <AlchemyConfigContext.Provider value={config}>
101
+ <AdapterContext.Provider value={adapter}>
102
+ <ClientCacheContext.Provider value={cache.current}>
103
+ {children}
104
+ </ClientCacheContext.Provider>
105
+ </AdapterContext.Provider>
106
+ </AlchemyConfigContext.Provider>
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Hook to access Alchemy provider configuration
112
+ * Must be used within an <AlchemyProvider> component
113
+ *
114
+ * @returns {AlchemyProviderConfig} The current Alchemy configuration
115
+ * @throws {Error} If used outside of AlchemyProvider
116
+ *
117
+ * @example
118
+ * ```tsx
119
+ * const config = useAlchemyConfig();
120
+ * console.log('Policy ID:', config.policyId);
121
+ * ```
122
+ */
123
+ export function useAlchemyConfig(): AlchemyProviderConfig {
124
+ const context = useContext(AlchemyConfigContext);
125
+ if (!context) {
126
+ throw new Error("useAlchemyConfig must be used within <AlchemyProvider />");
127
+ }
128
+ return context;
129
+ }
130
+
131
+ /**
132
+ * Hook to access the platform adapter
133
+ * Must be used within an <AlchemyProvider> component
134
+ *
135
+ * @internal
136
+ * @returns {PrivyAdapter} The platform adapter
137
+ */
138
+ export function useAdapter(): PrivyAdapter {
139
+ const context = useContext(AdapterContext);
140
+ if (!context) {
141
+ throw new Error(
142
+ "useAdapter must be used within <AlchemyProvider />. Make sure AlchemyProvider is nested inside PrivyProvider.",
143
+ );
144
+ }
145
+ return context;
146
+ }
147
+
148
+ /**
149
+ * Hook to access the client cache (internal use only)
150
+ *
151
+ * @internal
152
+ * @returns {ClientCache} The client cache object
153
+ */
154
+ export function useClientCache(): ClientCache {
155
+ const context = useContext(ClientCacheContext);
156
+ if (!context) {
157
+ throw new Error(
158
+ "useClientCache must be used within <AlchemyProvider />. Make sure AlchemyProvider is nested inside PrivyProvider.",
159
+ );
160
+ }
161
+ return context;
162
+ }
@@ -0,0 +1,45 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import { AlchemyContextProvider } from "../context/AlchemyContext.js";
3
+ import { reactNativeAdapter } from "../adapters/react-native.js";
4
+ import type { AlchemyProviderConfig } from "../types.js";
5
+
6
+ /**
7
+ * Provider component for React Native (Expo) applications
8
+ * Must be nested INSIDE PrivyProvider from @privy-io/expo
9
+ *
10
+ * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
11
+ * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
12
+ * @param {string} [props.apiKey] - Your Alchemy API key
13
+ * @param {string} [props.jwt] - JWT token for authentication
14
+ * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
15
+ * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
16
+ * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
17
+ * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
18
+ * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
19
+ * @returns {JSX.Element} Provider component
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { PrivyProvider } from '@privy-io/expo';
24
+ * import { AlchemyProvider } from '@account-kit/privy-integration/react-native';
25
+ *
26
+ * <PrivyProvider appId="..." clientId="...">
27
+ * <AlchemyProvider
28
+ * apiKey="your-alchemy-api-key"
29
+ * policyId="your-gas-policy-id"
30
+ * >
31
+ * <YourApp />
32
+ * </AlchemyProvider>
33
+ * </PrivyProvider>
34
+ * ```
35
+ */
36
+ export function AlchemyProvider({
37
+ children,
38
+ ...config
39
+ }: PropsWithChildren<AlchemyProviderConfig>) {
40
+ return (
41
+ <AlchemyContextProvider config={config} adapter={reactNativeAdapter}>
42
+ {children}
43
+ </AlchemyContextProvider>
44
+ );
45
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+
6
+ export function AlchemyProvider() {
7
+ throw new Error(
8
+ "WebProvider is not available in React Native. " +
9
+ 'Import from "@account-kit/privy-integration/react-native" instead.',
10
+ );
11
+ }
@@ -0,0 +1,45 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import { AlchemyContextProvider } from "../context/AlchemyContext.js";
3
+ import { webAdapter } from "../adapters/web.js";
4
+ import type { AlchemyProviderConfig } from "../types.js";
5
+
6
+ /**
7
+ * Provider component for React web applications
8
+ * Must be nested INSIDE PrivyProvider from @privy-io/react-auth
9
+ *
10
+ * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
11
+ * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
12
+ * @param {string} [props.apiKey] - Your Alchemy API key
13
+ * @param {string} [props.jwt] - JWT token for authentication
14
+ * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
15
+ * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
16
+ * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
17
+ * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
18
+ * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
19
+ * @returns {JSX.Element} Provider component
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { PrivyProvider } from '@privy-io/react-auth';
24
+ * import { AlchemyProvider } from '@account-kit/privy-integration';
25
+ *
26
+ * <PrivyProvider appId="...">
27
+ * <AlchemyProvider
28
+ * apiKey="your-alchemy-api-key"
29
+ * policyId="your-gas-policy-id"
30
+ * >
31
+ * <YourApp />
32
+ * </AlchemyProvider>
33
+ * </PrivyProvider>
34
+ * ```
35
+ */
36
+ export function AlchemyProvider({
37
+ children,
38
+ ...config
39
+ }: PropsWithChildren<AlchemyProviderConfig>) {
40
+ return (
41
+ <AlchemyContextProvider config={config} adapter={webAdapter}>
42
+ {children}
43
+ </AlchemyContextProvider>
44
+ );
45
+ }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.73.1-alpha.2";
3
+ export const VERSION = "4.73.1-alpha.3";