@bounded-sh/client 0.0.22 → 0.0.24
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 +24 -17
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{index.native-C9PMGtxX.mjs → index.native-D1YQ-LU7.mjs} +14 -6
- package/dist/index.native-D1YQ-LU7.mjs.map +1 -0
- package/dist/{index.native-C4a8IUpM.js → index.native-DcetyeOb.js} +14 -6
- package/dist/index.native-DcetyeOb.js.map +1 -0
- package/dist/index.native.js +1 -1
- package/dist/index.native.mjs +1 -1
- package/dist/{phantom-wallet-provider-DhpV9xKE.mjs → phantom-wallet-provider-3_IulJlh.mjs} +2 -2
- package/dist/{phantom-wallet-provider-DhpV9xKE.mjs.map → phantom-wallet-provider-3_IulJlh.mjs.map} +1 -1
- package/dist/{phantom-wallet-provider-BPRRcIaN.js → phantom-wallet-provider-DgBk6o3j.js} +2 -2
- package/dist/{phantom-wallet-provider-BPRRcIaN.js.map → phantom-wallet-provider-DgBk6o3j.js.map} +1 -1
- package/dist/{privy-wallet-provider-D4W91sqG.js → privy-wallet-provider-DNvtYCsQ.js} +3 -3
- package/dist/{privy-wallet-provider-D4W91sqG.js.map → privy-wallet-provider-DNvtYCsQ.js.map} +1 -1
- package/dist/{privy-wallet-provider-B6QyPXqq.mjs → privy-wallet-provider-DQtXFGFF.mjs} +3 -3
- package/dist/{privy-wallet-provider-B6QyPXqq.mjs.map → privy-wallet-provider-DQtXFGFF.mjs.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-B0O0BctB.js → solana-mobile-wallet-provider-CcnkDdgZ.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-B0O0BctB.js.map → solana-mobile-wallet-provider-CcnkDdgZ.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-OGKifgCZ.mjs → solana-mobile-wallet-provider-DE_zCpKE.mjs} +2 -2
- package/dist/{solana-mobile-wallet-provider-OGKifgCZ.mjs.map → solana-mobile-wallet-provider-DE_zCpKE.mjs.map} +1 -1
- package/package.json +2 -2
- package/dist/index.native-C4a8IUpM.js.map +0 -1
- package/dist/index.native-C9PMGtxX.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -50,13 +50,13 @@ Install the SDK via npm:
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
npm install @
|
|
53
|
+
npm install @bounded-sh/client
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
Or with Yarn:
|
|
58
58
|
```bash
|
|
59
|
-
yarn add @
|
|
59
|
+
yarn add @bounded-sh/client
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
|
|
@@ -66,31 +66,38 @@ yarn add @tarobase/js-sdk
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
Before using the SDK, initialize it with your **Application ID** and the one auth method this app intends to use.
|
|
69
|
+
Before using the SDK, initialize it with your **Application ID** and the one auth method this app intends to use. Missing `authMethod` fails closed so examples do not silently select the wrong identity path. Use `authMethod: 'email'` for Bounded Auth email OTP, `authMethod: 'phantom'` for Solana wallet auth, or `authMethod: 'none'` for public unauthenticated reads only.
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
|
-
import { init } from '@
|
|
73
|
+
import { init } from '@bounded-sh/client';
|
|
74
74
|
|
|
75
|
-
init({ appId: 'YOUR_APP_ID', authMethod: 'email' });
|
|
75
|
+
await init({ appId: 'YOUR_APP_ID', authMethod: 'email' });
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
### Authentication
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
For email OTP, initialize with `authMethod: 'email'` and call `login()` for the
|
|
81
|
+
inline email-code modal. OAuth/social providers use the hosted redirect or popup
|
|
82
|
+
helpers, which bind the returned token to the app id and registered redirect URI.
|
|
82
83
|
|
|
83
84
|
```typescript
|
|
84
|
-
import { login } from '@
|
|
85
|
+
import { login, loginWithRedirect, completeLoginFromRedirect } from '@bounded-sh/client';
|
|
86
|
+
|
|
87
|
+
// Email OTP:
|
|
88
|
+
await login();
|
|
89
|
+
|
|
90
|
+
// Hosted OAuth/social or hosted chooser:
|
|
91
|
+
await loginWithRedirect({ redirectUri: 'https://yourapp.com/auth/callback', methods: ['email'] });
|
|
85
92
|
|
|
86
|
-
//
|
|
87
|
-
|
|
93
|
+
// On your callback page, on load:
|
|
94
|
+
const user = await completeLoginFromRedirect();
|
|
88
95
|
```
|
|
89
96
|
|
|
90
97
|
You can also listen for authentication state changes:
|
|
91
98
|
|
|
92
99
|
```typescript
|
|
93
|
-
import { onAuthStateChanged } from '@
|
|
100
|
+
import { onAuthStateChanged } from '@bounded-sh/client';
|
|
94
101
|
|
|
95
102
|
onAuthStateChanged((user) => {
|
|
96
103
|
if (user) {
|
|
@@ -109,7 +116,7 @@ onAuthStateChanged((user) => {
|
|
|
109
116
|
|
|
110
117
|
|
|
111
118
|
```typescript
|
|
112
|
-
import { getCurrentUser } from '@
|
|
119
|
+
import { getCurrentUser } from '@bounded-sh/client';
|
|
113
120
|
|
|
114
121
|
const user = await getCurrentUser();
|
|
115
122
|
if (user) {
|
|
@@ -123,7 +130,7 @@ if (user) {
|
|
|
123
130
|
|
|
124
131
|
### Set Data
|
|
125
132
|
```typescript
|
|
126
|
-
import { set } from '@
|
|
133
|
+
import { set } from '@bounded-sh/client';
|
|
127
134
|
|
|
128
135
|
const path = 'path/to/data';
|
|
129
136
|
const data = { key: 'value' };
|
|
@@ -171,7 +178,7 @@ The `set` and `get` functions automatically handle whether data is stored **on-c
|
|
|
171
178
|
### Subscribe
|
|
172
179
|
|
|
173
180
|
```typescript
|
|
174
|
-
import { subscribe } from '@
|
|
181
|
+
import { subscribe } from '@bounded-sh/client';
|
|
175
182
|
|
|
176
183
|
// Subscribe to a single document
|
|
177
184
|
const unsubscribe = await subscribe('users/123/profile', {
|
|
@@ -194,7 +201,7 @@ await unsubscribe();
|
|
|
194
201
|
### Get Data
|
|
195
202
|
|
|
196
203
|
```typescript
|
|
197
|
-
import { get } from '@
|
|
204
|
+
import { get } from '@bounded-sh/client';
|
|
198
205
|
|
|
199
206
|
// Read a single document
|
|
200
207
|
const message = await get('messages/abc123');
|
|
@@ -223,7 +230,7 @@ console.log('Messages:', recent);
|
|
|
223
230
|
### Counting, Aggregation, Search, and Joins
|
|
224
231
|
|
|
225
232
|
```typescript
|
|
226
|
-
import { count, aggregate, queryAggregate, search, get } from '@
|
|
233
|
+
import { count, aggregate, queryAggregate, search, get } from '@bounded-sh/client';
|
|
227
234
|
|
|
228
235
|
// Count matching documents
|
|
229
236
|
const { value: openCount } = await count('orders', { filter: { status: 'open' } });
|
|
@@ -246,7 +253,7 @@ const projects = await get('projects', { shape: { owner: {} } });
|
|
|
246
253
|
Use `getMany` to efficiently fetch multiple documents in a single request:
|
|
247
254
|
|
|
248
255
|
```typescript
|
|
249
|
-
import { getMany } from '@
|
|
256
|
+
import { getMany } from '@bounded-sh/client';
|
|
250
257
|
|
|
251
258
|
// Fetch multiple documents at once (max 30 paths)
|
|
252
259
|
const results = await getMany([
|
package/dist/index.js
CHANGED
|
@@ -4246,6 +4246,14 @@ function tokenField(data, snake, camel) {
|
|
|
4246
4246
|
const value = (_a = data === null || data === void 0 ? void 0 : data[snake]) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data[camel];
|
|
4247
4247
|
return typeof value === 'string' ? value : '';
|
|
4248
4248
|
}
|
|
4249
|
+
function boundedRefreshTokenField(data) {
|
|
4250
|
+
for (const key of ['bounded_refresh_token', 'boundedRefreshToken', 'refreshToken']) {
|
|
4251
|
+
const value = data === null || data === void 0 ? void 0 : data[key];
|
|
4252
|
+
if (typeof value === 'string' && value.length > 0)
|
|
4253
|
+
return value;
|
|
4254
|
+
}
|
|
4255
|
+
return '';
|
|
4256
|
+
}
|
|
4249
4257
|
async function issuerBase() {
|
|
4250
4258
|
const cfg = await core.getConfig();
|
|
4251
4259
|
return (cfg.humanAuthApiUrl || 'https://auth.bounded.sh').replace(/\/$/, '');
|
|
@@ -4350,7 +4358,7 @@ async function finishGuestLinkIfPending(socialIdToken) {
|
|
|
4350
4358
|
return null; // link failed -> keep the plain social session
|
|
4351
4359
|
const upgraded = userFromIdToken(idToken);
|
|
4352
4360
|
const accessToken = tokenField(data, 'access_token', 'accessToken') || idToken;
|
|
4353
|
-
const refreshToken =
|
|
4361
|
+
const refreshToken = boundedRefreshTokenField(data);
|
|
4354
4362
|
await sessionManager().storeSession(String(upgraded.address || ''), accessToken, idToken, refreshToken, base);
|
|
4355
4363
|
setCurrentUser(upgraded);
|
|
4356
4364
|
return upgraded;
|
|
@@ -4491,7 +4499,7 @@ async function exchangeCode(code, verifier, redirectUri) {
|
|
|
4491
4499
|
if (!idToken)
|
|
4492
4500
|
throw new Error('No id_token returned from the token endpoint');
|
|
4493
4501
|
const accessToken = tokenField(data, 'access_token', 'accessToken') || idToken;
|
|
4494
|
-
const refreshToken =
|
|
4502
|
+
const refreshToken = boundedRefreshTokenField(data);
|
|
4495
4503
|
const user = userFromIdToken(idToken);
|
|
4496
4504
|
await sessionManager().storeSession(String(user.address || ''), accessToken, idToken, refreshToken, base);
|
|
4497
4505
|
try {
|