@pooflabs/web 0.0.2 → 0.0.4

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 CHANGED
@@ -1,130 +1,216 @@
1
- # @tarobase/web
2
1
 
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`.
2
+ # Tarobase JS SDK
3
+ Tarobase is the web3 alternative to firebase. It is a powerful platform that simplifies the integration of hybrid on-chain actions and data for modern web and mobile applications.
4
4
 
5
- ## Installation
5
+ Welcome to the **Tarobase JavaScript SDK**! This SDK allows you to interact with the Tarobase platform seamlessly from your JavaScript or TypeScript applications. Whether you're building a web app, a Node.js service, or a React Native application (support coming soon), the Tarobase JS SDK provides the tools you need.
6
6
 
7
- ```bash
8
- npm install @tarobase/web
9
- ```
10
7
 
11
- ## Usage
8
+ ## Table of Contents
9
+ - [Installation](#installation)
12
10
 
13
- ```typescript
14
- import { init, login, getCurrentUser, set, get } from '@tarobase/web';
11
+ - [Getting Started](#getting-started)
15
12
 
16
- // Initialize the SDK
17
- await init({
18
- appId: 'your-app-id',
19
- authMethod: 'phantom', // or 'privy'
20
- });
13
+ - [Initialization](#initialization)
21
14
 
22
- // Log in
23
- await login();
15
+ - [Authentication](#authentication)
24
16
 
25
- // Get the current user
26
- const user = getCurrentUser();
27
- console.log(user.address);
17
+ - [Usage Examples](#usage-examples)
28
18
 
29
- // Set data
30
- await set('todos/123', { text: 'Buy milk', completed: false });
19
+ - [Initialize the SDK](#initialize-the-sdk)
31
20
 
32
- // Get data
33
- const todo = await get('todos/123');
34
- console.log(todo);
35
- ```
21
+ - [Authenticate a User](#authenticate-a-user)
36
22
 
37
- ### React Hook
23
+ - [Get Current User](#get-current-user)
38
24
 
39
- ```typescript
40
- import { useAuth } from '@tarobase/web';
25
+ - [Set Data](#set-data)
41
26
 
42
- function MyComponent() {
43
- const { user, isLoading, isLoggedIn, login, logout } = useAuth();
27
+ - [On-Chain and Off-Chain Data](#on-chain-and-off-chain-data)
44
28
 
45
- if (isLoading) {
46
- return <div>Loading...</div>;
47
- }
29
+ - [Get Data](#get-data)
48
30
 
49
- if (!isLoggedIn) {
50
- return <button onClick={login}>Login</button>;
51
- }
31
+ - [Additional Resources](#additional-resources)
52
32
 
53
- return (
54
- <div>
55
- <p>Logged in as: {user.address}</p>
56
- <button onClick={logout}>Logout</button>
57
- </div>
58
- );
59
- }
33
+ - [React Native Support](#react-native-support)
34
+
35
+ - [Contributing](#contributing)
36
+
37
+ - [License](#license)
38
+
39
+
40
+
41
+ ## Installation
42
+
43
+ Install the SDK via npm:
44
+
45
+
46
+ ```bash
47
+ npm install @tarobase/js-sdk
48
+ ```
49
+
50
+
51
+ Or with Yarn:
52
+ ```bash
53
+ yarn add @tarobase/js-sdk
60
54
  ```
61
55
 
62
- ## Authentication Methods
56
+
57
+
58
+ ## Getting Started
59
+ ### Initialization
63
60
 
64
- ### Phantom Wallet
61
+
65
62
 
63
+ Before using the SDK, initialize it with your **Application ID**. You can obtain your `appId` by creating an application on the [Tarobase Console](https://console.tarobase.com). The console also allows you to configure your application's policies, including data storage preferences (on-chain or off-chain) and data schemas.
64
+
65
+
66
66
  ```typescript
67
- await init({
68
- appId: 'your-app-id',
69
- authMethod: 'phantom'
70
- });
71
- ```
67
+ import { init } from '@tarobase/js-sdk';
68
+
69
+ init({appId: 'YOUR_APP_ID' });
70
+ ```
71
+
72
+ ### Authentication
72
73
 
73
- ### Privy Wallet
74
+
75
+ To authenticate users, use the `login` function:
74
76
 
75
77
  ```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
- }
78
+ import { login } from '@tarobase/js-sdk';
79
+
80
+ // Start the login process
81
+ login();
82
+ ```
83
+
84
+ You can also listen for authentication state changes:
85
+
86
+ ```typescript
87
+ import { onAuthStateChanged } from '@tarobase/js-sdk';
88
+
89
+ onAuthStateChanged((user) => {
90
+ if (user) {
91
+ console.log('User logged in:', user.address);
92
+ } else {
93
+ console.log('User logged out');
94
+ }
90
95
  });
91
96
  ```
92
97
 
93
- ## API Reference
98
+
99
+
100
+ ## Usage
101
+
102
+ ### Get Current User
94
103
 
95
- ### Initialization
96
104
 
97
105
  ```typescript
98
- function init(newConfig: Partial<ClientConfig>): Promise<void>;
106
+ import { getCurrentUser } from '@tarobase/js-sdk';
107
+
108
+ const user = await getCurrentUser();
109
+ if (user) {
110
+ console.log('Current user:', user.address);
111
+ } else {
112
+ console.log('No user is currently logged in.');
113
+ }
99
114
  ```
100
115
 
101
- ### Authentication
116
+
102
117
 
118
+ ### Set Data
103
119
  ```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;
120
+ import { set } from '@tarobase/js-sdk';
121
+
122
+ const path = 'path/to/data';
123
+ const data = { key: 'value' };
124
+
125
+ await set(path, data);
126
+
127
+ console.log(`Data set at ${path}`);
108
128
  ```
129
+
130
+
131
+ #### On-Chain and Off-Chain Data
132
+
133
+ The `set` and `get` functions automatically handle whether data is stored **on-chain** or **off-chain** based on your application's policy configuration in the [Tarobase Console](https://console.tarobase.com).
134
+
135
+
136
+ **On-Chain Data:**
137
+
138
+ - If the data path corresponds to on-chain storage defined in your application policy, the `set` function will store data on-chain.
139
+
140
+ - The data must adhere to the `fields` schema defined in your Tarobase policy.
141
+
142
+ - Transactions are handled automatically, and users may be prompted to approve blockchain transactions.
143
+
144
+ **Off-Chain Data:**
145
+
146
+ - If the data path corresponds to off-chain storage, the `set` function will store data off-chain.
147
+
148
+
149
+
150
+ **Important:**
151
+
152
+
153
+
154
+ - Manage your data storage preferences and define policies at the [Tarobase Console](https://console.tarobase.com).
155
+
156
+ - Ensure that for on-chain data, the parameters you provide to `set` match the `fields` specified in your Tarobase policy.
109
157
 
110
- ### Data Operations
158
+ - The policy also controls what can be `set` or `get` in your application.
159
+
160
+ - For information on how to form your policy specifically for your app's use-cases, view the policy docs [here](https://docs.tarobase.com/policies).
161
+
162
+
163
+ ### Subscribe
111
164
 
112
165
  ```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>;
166
+ await subscribe('path/to/data', {}, (data) => {
167
+ console.log('Data updated:', data); }
168
+ );
120
169
  ```
121
170
 
122
- ### Subscriptions
171
+
172
+ ### Get Data
123
173
 
124
174
  ```typescript
125
- function subscribe(path: string, options?: SubscriptionOptions): Promise<() => void>;
175
+ import { get } from '@tarobase/js-sdk';
176
+
177
+ const path = 'messages/abc123';
178
+ const data = await get(path);
179
+
180
+ const collection = 'messages';
181
+ // For colletion queries, include a plain english prompt to filter your results accordingly,
182
+ // smart queries will be constructed on your behalf by tarobase.
183
+ const data = await get(path, { prompt: "where text starts with the letter f" });
184
+
185
+ console.log(`Data at ${path}:`, data);
126
186
  ```
127
187
 
128
- ## Contributing
188
+ **Note:** Similar to `set`, the `get` and `subscribe` functions will automatically retrieve data from on-chain or off-chain storage based on your application's configuration.
189
+
190
+
191
+
192
+
193
+ ### Additional Resources
194
+ For more comprehensive examples, detailed guides, and API references, please visit our documentation site:
195
+
196
+ - [Tarobase Documentation](https://docs.tarobase.com)
197
+
198
+ - Quickstart Guide
199
+
200
+ - [API Reference](https://docs.tarobase.com/api)
201
+
202
+
203
+ ### React Native Support
204
+ Support for **React Native** is coming soon! Stay tuned for updates, and feel free to check back on our [documentation site](https://docs.tarobase.com) for the latest information.
205
+
206
+ ### Contributing
207
+ Contributions are welcome! Please open an issue or submit a pull request on GitHub.
208
+
209
+ ### License
210
+ This Tarobase JS SDK project is licensed under the MIT License.
211
+
212
+ * * * * *
213
+
214
+
215
+ Thank you for using the Tarobase JS SDK! If you have any questions or need further assistance, feel free to crete an issue.
129
216
 
130
- Please see the main repository for contribution guidelines.
@@ -1,4 +1,4 @@
1
- import { User } from '@tarobase/core';
1
+ import { User } from '../../types';
2
2
  export interface UseAuthResult {
3
3
  login: () => Promise<void>;
4
4
  logout: () => Promise<void>;
@@ -1,5 +1,6 @@
1
- import { AuthProvider, User } from '@tarobase/core';
1
+ export { deserializeTransaction } from './providers/sol/sol-utils';
2
+ import { AuthProvider, User } from '../types';
3
+ export declare const SURFNET_RPC_URL = "https://surfpool.fly.dev";
2
4
  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
5
  export declare function login(): Promise<User | null>;
5
6
  export declare function logout(): Promise<void>;
@@ -1,7 +1,7 @@
1
- import type { EVMTransaction, SolTransaction, TransactionResult, User, AuthProvider } from '@tarobase/core';
1
+ import type { EVMTransaction, SolTransaction, TransactionResult, User, AuthProvider } from '../../types';
2
2
  import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
3
3
  import { CreatePhantomConfig } from '@phantom/wallet-sdk';
4
- import { SetOptions } from '@tarobase/core';
4
+ import { SetOptions } from '../../client/operations';
5
5
  export declare class PhantomWalletProvider implements AuthProvider {
6
6
  private connection;
7
7
  private initialized;
@@ -45,6 +45,7 @@ export declare class PhantomWalletProvider implements AuthProvider {
45
45
  restoreSession(): Promise<User | null>;
46
46
  address(): Promise<string | null>;
47
47
  runTransaction(evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
48
+ signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
48
49
  signMessage(message: string): Promise<string>;
49
50
  logout(): Promise<void>;
50
51
  getNativeMethods(): Promise<any>;
@@ -1,6 +1,7 @@
1
- import type { EVMTransaction, SolTransaction, TransactionResult } from '@tarobase/core';
2
- import { AuthProvider, User } from '@tarobase/core';
3
- import { SetOptions } from '@tarobase/core';
1
+ import type { EVMTransaction, SolTransaction, TransactionResult } from '../../types';
2
+ import { AuthProvider, User } from '../../types';
3
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
4
+ import { SetOptions } from '../../client/operations';
4
5
  export declare class PrivyWalletProvider implements AuthProvider {
5
6
  private static instance;
6
7
  private containerElement;
@@ -20,6 +21,7 @@ export declare class PrivyWalletProvider implements AuthProvider {
20
21
  getNativeMethods(): Promise<any>;
21
22
  logout(): Promise<void>;
22
23
  runTransaction(_evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
24
+ signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
23
25
  signMessage(message: string): Promise<string>;
24
26
  restoreSession(): Promise<User | null>;
25
27
  private createSession;