@pooflabs/web 0.0.2 → 0.0.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.
- package/README.md +171 -85
- package/dist/auth/hooks/useAuth.d.ts +1 -1
- package/dist/auth/index.d.ts +1 -2
- package/dist/auth/providers/phantom-wallet-provider.d.ts +2 -2
- package/dist/auth/providers/privy-wallet-provider.d.ts +3 -3
- package/dist/auth/providers/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpDevnet-program.d.ts +1381 -0
- package/dist/auth/providers/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpMainnet-program.d.ts +1381 -0
- package/dist/auth/providers/sol/sol-utils.d.ts +41 -0
- package/dist/auth/providers/sol/taro6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRuDevnet-program.d.ts +1161 -0
- package/dist/auth/utils/auth-api.d.ts +5 -0
- package/dist/auth/utils/session-manager.d.ts +14 -0
- package/dist/auth/utils/utils.d.ts +8 -0
- package/dist/client/config.d.ts +20 -0
- package/dist/client/operations.d.ts +29 -0
- package/dist/client/subscription.d.ts +10 -0
- package/dist/global.d.ts +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.esm.js +5329 -7945
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5315 -7940
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +44 -0
- package/dist/utils/api.d.ts +8 -0
- package/package.json +15 -17
package/README.md
CHANGED
|
@@ -1,130 +1,216 @@
|
|
|
1
|
-
# @tarobase/web
|
|
2
1
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
8
|
+
## Table of Contents
|
|
9
|
+
- [Installation](#installation)
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
import { init, login, getCurrentUser, set, get } from '@tarobase/web';
|
|
11
|
+
- [Getting Started](#getting-started)
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
await init({
|
|
18
|
-
appId: 'your-app-id',
|
|
19
|
-
authMethod: 'phantom', // or 'privy'
|
|
20
|
-
});
|
|
13
|
+
- [Initialization](#initialization)
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
await login();
|
|
15
|
+
- [Authentication](#authentication)
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
const user = getCurrentUser();
|
|
27
|
-
console.log(user.address);
|
|
17
|
+
- [Usage Examples](#usage-examples)
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
await set('todos/123', { text: 'Buy milk', completed: false });
|
|
19
|
+
- [Initialize the SDK](#initialize-the-sdk)
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
const todo = await get('todos/123');
|
|
34
|
-
console.log(todo);
|
|
35
|
-
```
|
|
21
|
+
- [Authenticate a User](#authenticate-a-user)
|
|
36
22
|
|
|
37
|
-
|
|
23
|
+
- [Get Current User](#get-current-user)
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
import { useAuth } from '@tarobase/web';
|
|
25
|
+
- [Set Data](#set-data)
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
const { user, isLoading, isLoggedIn, login, logout } = useAuth();
|
|
27
|
+
- [On-Chain and Off-Chain Data](#on-chain-and-off-chain-data)
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
return <div>Loading...</div>;
|
|
47
|
-
}
|
|
29
|
+
- [Get Data](#get-data)
|
|
48
30
|
|
|
49
|
-
|
|
50
|
-
return <button onClick={login}>Login</button>;
|
|
51
|
-
}
|
|
31
|
+
- [Additional Resources](#additional-resources)
|
|
52
32
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Getting Started
|
|
59
|
+
### Initialization
|
|
63
60
|
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
import { init } from '@tarobase/js-sdk';
|
|
68
|
+
|
|
69
|
+
init({appId: 'YOUR_APP_ID' });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Authentication
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
|
|
75
|
+
To authenticate users, use the `login` function:
|
|
74
76
|
|
|
75
77
|
```typescript
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## Usage
|
|
101
|
+
|
|
102
|
+
### Get Current User
|
|
94
103
|
|
|
95
|
-
### Initialization
|
|
96
104
|
|
|
97
105
|
```typescript
|
|
98
|
-
|
|
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
|
-
|
|
116
|
+
|
|
102
117
|
|
|
118
|
+
### Set Data
|
|
103
119
|
```typescript
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
171
|
+
|
|
172
|
+
### Get Data
|
|
123
173
|
|
|
124
174
|
```typescript
|
|
125
|
-
|
|
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
|
-
|
|
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.
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AuthProvider, User } from '
|
|
1
|
+
import { AuthProvider, User } from '../types';
|
|
2
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
3
|
export declare function login(): Promise<User | null>;
|
|
5
4
|
export declare function logout(): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { EVMTransaction, SolTransaction, TransactionResult, User, AuthProvider } from '
|
|
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 '
|
|
4
|
+
import { SetOptions } from '../../client/operations';
|
|
5
5
|
export declare class PhantomWalletProvider implements AuthProvider {
|
|
6
6
|
private connection;
|
|
7
7
|
private initialized;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { EVMTransaction, SolTransaction, TransactionResult } from '
|
|
2
|
-
import { AuthProvider, User } from '
|
|
3
|
-
import { SetOptions } from '
|
|
1
|
+
import type { EVMTransaction, SolTransaction, TransactionResult } from '../../types';
|
|
2
|
+
import { AuthProvider, User } from '../../types';
|
|
3
|
+
import { SetOptions } from '../../client/operations';
|
|
4
4
|
export declare class PrivyWalletProvider implements AuthProvider {
|
|
5
5
|
private static instance;
|
|
6
6
|
private containerElement;
|