@pooflabs/web 0.0.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/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # @tarobase/web
2
+
3
+ Web SDK for Tarobase API - Browser/Frontend implementation. This package provides identical functionality to the original `@tarobase/js-sdk` package, but uses a modular architecture with shared functionality in `@tarobase/core`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @tarobase/web
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { init, login, getCurrentUser, set, get } from '@tarobase/web';
15
+
16
+ // Initialize the SDK
17
+ await init({
18
+ appId: 'your-app-id',
19
+ authMethod: 'phantom', // or 'privy'
20
+ });
21
+
22
+ // Log in
23
+ await login();
24
+
25
+ // Get the current user
26
+ const user = getCurrentUser();
27
+ console.log(user.address);
28
+
29
+ // Set data
30
+ await set('todos/123', { text: 'Buy milk', completed: false });
31
+
32
+ // Get data
33
+ const todo = await get('todos/123');
34
+ console.log(todo);
35
+ ```
36
+
37
+ ### React Hook
38
+
39
+ ```typescript
40
+ import { useAuth } from '@tarobase/web';
41
+
42
+ function MyComponent() {
43
+ const { user, isLoading, isLoggedIn, login, logout } = useAuth();
44
+
45
+ if (isLoading) {
46
+ return <div>Loading...</div>;
47
+ }
48
+
49
+ if (!isLoggedIn) {
50
+ return <button onClick={login}>Login</button>;
51
+ }
52
+
53
+ return (
54
+ <div>
55
+ <p>Logged in as: {user.address}</p>
56
+ <button onClick={logout}>Logout</button>
57
+ </div>
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## Authentication Methods
63
+
64
+ ### Phantom Wallet
65
+
66
+ ```typescript
67
+ await init({
68
+ appId: 'your-app-id',
69
+ authMethod: 'phantom'
70
+ });
71
+ ```
72
+
73
+ ### Privy Wallet
74
+
75
+ ```typescript
76
+ await init({
77
+ appId: 'your-app-id',
78
+ authMethod: 'privy',
79
+ privyConfig: {
80
+ appId: 'your-privy-app-id',
81
+ config: {
82
+ // Privy configuration options
83
+ embeddedWallets: {
84
+ solana: {
85
+ createOnLogin: "users-without-wallets"
86
+ }
87
+ }
88
+ }
89
+ }
90
+ });
91
+ ```
92
+
93
+ ## API Reference
94
+
95
+ ### Initialization
96
+
97
+ ```typescript
98
+ function init(newConfig: Partial<ClientConfig>): Promise<void>;
99
+ ```
100
+
101
+ ### Authentication
102
+
103
+ ```typescript
104
+ function login(): Promise<User | null>;
105
+ function logout(): Promise<void>;
106
+ function getCurrentUser(): User | null;
107
+ function onAuthStateChanged(callback: (user: User | null) => void): void;
108
+ ```
109
+
110
+ ### Data Operations
111
+
112
+ ```typescript
113
+ function get(path: string): Promise<any>;
114
+ function set(path: string, data: any, options?: SetOptions): Promise<any>;
115
+ function setMany(paths: { [key: string]: any }, options?: SetOptions): Promise<any>;
116
+ function setFile(path: string, file: File, metadata?: any): Promise<any>;
117
+ function getFiles(path: string): Promise<any>;
118
+ function runQuery(queryString: string, variables?: any): Promise<any>;
119
+ function runQueryMany(queryString: string, variables?: any): Promise<any>;
120
+ ```
121
+
122
+ ### Subscriptions
123
+
124
+ ```typescript
125
+ function subscribe(path: string, options?: SubscriptionOptions): Promise<() => void>;
126
+ ```
127
+
128
+ ## Contributing
129
+
130
+ Please see the main repository for contribution guidelines.
@@ -0,0 +1,8 @@
1
+ import { User } from '@tarobase/core';
2
+ export interface UseAuthResult {
3
+ login: () => Promise<void>;
4
+ logout: () => Promise<void>;
5
+ loading: boolean;
6
+ user: User | null;
7
+ }
8
+ export declare function useAuth(): UseAuthResult;
@@ -0,0 +1,5 @@
1
+ import { AuthProvider, User } from '@tarobase/core';
2
+ export declare function getAuthProvider(): Promise<AuthProvider>;
3
+ export declare function matchAuthProvider(appName: string | null, appLogoUrl: string | null, authMethod: string, rpcUrl: string, privyConfig?: any): Promise<AuthProvider>;
4
+ export declare function login(): Promise<User | null>;
5
+ export declare function logout(): Promise<void>;
@@ -0,0 +1,74 @@
1
+ import type { EVMTransaction, SolTransaction, TransactionResult, User, AuthProvider } from '@tarobase/core';
2
+ import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
3
+ import { CreatePhantomConfig } from '@phantom/wallet-sdk';
4
+ import { SetOptions } from '@tarobase/core';
5
+ export declare class PhantomWalletProvider implements AuthProvider {
6
+ private connection;
7
+ private initialized;
8
+ private networkUrl;
9
+ private embeddedWallet;
10
+ private embeddedConfig;
11
+ constructor(networkUrl?: string, embeddedConfig?: CreatePhantomConfig);
12
+ private init;
13
+ /**
14
+ * Shows the embedded wallet UI
15
+ */
16
+ showWallet(): void;
17
+ /**
18
+ * Hides the embedded wallet UI
19
+ */
20
+ hideWallet(): void;
21
+ /**
22
+ * Opens the swap screen in the embedded wallet
23
+ * @param options Swap options (buy token, sell token, amount)
24
+ */
25
+ openSwap(options: {
26
+ buy: string;
27
+ sell?: string;
28
+ amount?: string;
29
+ }): void;
30
+ /**
31
+ * Opens the buy screen in the embedded wallet
32
+ * @param options Buy options (token to buy, amount in USD)
33
+ */
34
+ openBuy(options: {
35
+ amount?: number;
36
+ buy: string;
37
+ }): void;
38
+ private getProvider;
39
+ /**
40
+ * Ensures the wallet is connected and returns the provider
41
+ * This method will attempt to connect if not already connected
42
+ */
43
+ private ensureConnected;
44
+ login(): Promise<User | null>;
45
+ restoreSession(): Promise<User | null>;
46
+ address(): Promise<string | null>;
47
+ runTransaction(evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
48
+ signMessage(message: string): Promise<string>;
49
+ logout(): Promise<void>;
50
+ getNativeMethods(): Promise<any>;
51
+ }
52
+ declare global {
53
+ interface Window {
54
+ phantom?: {
55
+ solana?: {
56
+ isPhantom: boolean;
57
+ isConnected: boolean;
58
+ publicKey: PublicKey;
59
+ connect: () => Promise<{
60
+ publicKey: PublicKey;
61
+ }>;
62
+ disconnect: () => Promise<void>;
63
+ signMessage: (message: Uint8Array, encoding: string) => Promise<{
64
+ signature: Uint8Array;
65
+ }>;
66
+ signTransaction: (transaction: Transaction | VersionedTransaction) => Promise<Transaction>;
67
+ signAndSendTransaction: (transaction: Transaction | VersionedTransaction) => Promise<{
68
+ signature: string;
69
+ }>;
70
+ };
71
+ };
72
+ CUSTOM_TAROBASE_APP_ID_HEADER?: string;
73
+ }
74
+ }
@@ -0,0 +1,27 @@
1
+ import type { EVMTransaction, SolTransaction, TransactionResult } from '@tarobase/core';
2
+ import { AuthProvider, User } from '@tarobase/core';
3
+ import { SetOptions } from '@tarobase/core';
4
+ export declare class PrivyWalletProvider implements AuthProvider {
5
+ private static instance;
6
+ private containerElement;
7
+ private networkUrl;
8
+ private root;
9
+ private privyMethods;
10
+ private privyConfig;
11
+ private pendingLogin;
12
+ private pendingTransaction;
13
+ constructor(appName: string | null, appLogoUrl: string | null, privyConfig?: {
14
+ appId: string;
15
+ config: any;
16
+ }, networkUrl?: string);
17
+ static getInstance(appName: string | null, appLogoUrl: string | null, privyConfig: any): PrivyWalletProvider;
18
+ private initialize;
19
+ login(): Promise<User | null>;
20
+ getNativeMethods(): Promise<any>;
21
+ logout(): Promise<void>;
22
+ runTransaction(_evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
23
+ signMessage(message: string): Promise<string>;
24
+ restoreSession(): Promise<User | null>;
25
+ private createSession;
26
+ private ensureReady;
27
+ }
@@ -0,0 +1,8 @@
1
+ import { User } from '@tarobase/core';
2
+ import { ClientConfig } from '@tarobase/core';
3
+ export declare function init(newConfig: Partial<ClientConfig>): Promise<void>;
4
+ export declare function onAuthStateChanged(callback: (user: User | null) => void): void;
5
+ export declare function login(): Promise<User | null>;
6
+ export declare function logout(): Promise<void>;
7
+ export declare function setCurrentUser(user: User | null): void;
8
+ export declare function getCurrentUser(): User | null;
@@ -0,0 +1,8 @@
1
+ export { init, getCurrentUser, onAuthStateChanged, login, logout } from "./global";
2
+ export { getConfig } from '@tarobase/core';
3
+ export { getAuthProvider } from './auth';
4
+ export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany } from '@tarobase/core';
5
+ export { subscribe } from '@tarobase/core';
6
+ export * from '@tarobase/core';
7
+ export { useAuth } from './auth/hooks/useAuth';
8
+ export { getIdToken } from '@tarobase/core';