@appboxo/web-sdk 1.0.7 → 1.0.8
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 +18 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,27 +40,21 @@ const sdk = new AppboxoWebSDK({
|
|
|
40
40
|
userId?: string; // Optional, user reference identifier
|
|
41
41
|
baseUrl?: string; // Optional, default: "https://dashboard.appboxo.com/api/v1"
|
|
42
42
|
debug?: boolean; // Optional, default: false
|
|
43
|
-
onGetAuthCode?: () => Promise<string>; // Optional, for automatic auth code retrieval
|
|
44
|
-
onGetAuthTokens?: () => Promise<LoginResponse>; // Optional, for
|
|
43
|
+
onGetAuthCode?: () => Promise<string>; // Optional, for automatic auth code retrieval
|
|
44
|
+
onGetAuthTokens?: () => Promise<LoginResponse>; // Optional, for direct auth tokens
|
|
45
45
|
onPaymentRequest?: (params: PaymentRequest) => Promise<PaymentResponse>; // Optional, for handling payment requests
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
### Authentication
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
#### Boxo Connect OAuth
|
|
54
|
-
|
|
55
|
-
Traditional OAuth 2.0 flow where the host app backend provides auth codes and access tokens to the Boxo Platform.
|
|
56
|
-
|
|
57
|
-
**1. Set auth code explicitly**
|
|
51
|
+
**OAuth flow:**
|
|
58
52
|
|
|
59
53
|
```typescript
|
|
60
54
|
sdk.setAuthCode(authCode);
|
|
61
55
|
```
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
Or provide a callback:
|
|
64
58
|
|
|
65
59
|
```typescript
|
|
66
60
|
const sdk = new AppboxoWebSDK({
|
|
@@ -73,47 +67,25 @@ const sdk = new AppboxoWebSDK({
|
|
|
73
67
|
});
|
|
74
68
|
```
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
1. Explicitly set auth code
|
|
78
|
-
2. Callback function (`onGetAuthCode`)
|
|
79
|
-
3. Mock auth code (fallback for testing)
|
|
80
|
-
|
|
81
|
-
#### Boxo Connect Direct
|
|
82
|
-
|
|
83
|
-
Direct authentication flow where the host app backend calls Boxo Dashboard connect endpoint to get miniapp tokens, then provides them directly to the SDK.
|
|
84
|
-
|
|
85
|
-
**1. Use `onAuth` lifecycle hook (Recommended)**
|
|
70
|
+
**Direct auth flow:**
|
|
86
71
|
|
|
87
72
|
```typescript
|
|
88
|
-
const sdk = new AppboxoWebSDK({
|
|
89
|
-
clientId: "your-client-id",
|
|
90
|
-
appId: "your-app-id"
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// onAuth hook is triggered when miniapp calls login()
|
|
94
73
|
sdk.onAuth(async () => {
|
|
95
|
-
|
|
96
|
-
const response = await fetch('/api/get-miniapp-tokens', {
|
|
97
|
-
headers: { 'Authorization': `Bearer ${yourHostAppToken}` }
|
|
98
|
-
});
|
|
74
|
+
const response = await fetch('/api/get-miniapp-tokens');
|
|
99
75
|
const tokens = await response.json();
|
|
100
|
-
|
|
101
|
-
// Set tokens directly
|
|
102
76
|
sdk.setAuthTokens(tokens.access_token, tokens.refresh_token);
|
|
103
77
|
});
|
|
104
78
|
```
|
|
105
79
|
|
|
106
|
-
|
|
80
|
+
Or use callback:
|
|
107
81
|
|
|
108
82
|
```typescript
|
|
109
83
|
const sdk = new AppboxoWebSDK({
|
|
110
84
|
clientId: "your-client-id",
|
|
111
85
|
appId: "your-app-id",
|
|
112
86
|
onGetAuthTokens: async () => {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
const result = await response.json();
|
|
87
|
+
const res = await fetch('/api/get-miniapp-tokens');
|
|
88
|
+
const result = await res.json();
|
|
117
89
|
return {
|
|
118
90
|
token: result.access_token,
|
|
119
91
|
refresh_token: result.refresh_token
|
|
@@ -122,25 +94,18 @@ const sdk = new AppboxoWebSDK({
|
|
|
122
94
|
});
|
|
123
95
|
```
|
|
124
96
|
|
|
125
|
-
|
|
97
|
+
Or set tokens directly:
|
|
126
98
|
|
|
127
99
|
```typescript
|
|
128
|
-
const sdk = new AppboxoWebSDK({
|
|
129
|
-
clientId: "your-client-id",
|
|
130
|
-
appId: "your-app-id"
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// If you already have tokens, set them before miniapp calls login()
|
|
134
100
|
const tokens = await getTokensFromBackend();
|
|
135
101
|
sdk.setAuthTokens(tokens.access_token, tokens.refresh_token);
|
|
136
102
|
```
|
|
137
103
|
|
|
138
|
-
|
|
104
|
+
The SDK will try these in order:
|
|
139
105
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
3. OAuth flow (`setAuthCode()` or `onGetAuthCode` callback)
|
|
106
|
+
1. Pre-set tokens (`setAuthTokens`)
|
|
107
|
+
2. Direct auth callback (`onGetAuthTokens`)
|
|
108
|
+
3. OAuth auth code (`setAuthCode` or `onGetAuthCode` callback)
|
|
144
109
|
|
|
145
110
|
### Payment Processing
|
|
146
111
|
|
|
@@ -183,9 +148,9 @@ Note: When `onPaymentRequest` is set, the SDK automatically tells the miniapp it
|
|
|
183
148
|
|
|
184
149
|
| Method | Description |
|
|
185
150
|
|--------|-------------|
|
|
186
|
-
| `setAuthCode(code)` | Set authentication code
|
|
187
|
-
| `setAuthTokens(token, refreshToken?)` | Set authentication tokens directly
|
|
188
|
-
| `onAuth(callback)` | Register
|
|
151
|
+
| `setAuthCode(code)` | Set authentication code |
|
|
152
|
+
| `setAuthTokens(token, refreshToken?)` | Set authentication tokens directly |
|
|
153
|
+
| `onAuth(callback)` | Register callback for authentication events |
|
|
189
154
|
| `mount(config)` | Create iframe and initialize SDK |
|
|
190
155
|
| `setIframe(iframe)` | Set iframe element manually |
|
|
191
156
|
| `initialize()` | Start listening for events |
|
|
@@ -235,15 +200,7 @@ function App() {
|
|
|
235
200
|
},
|
|
236
201
|
});
|
|
237
202
|
|
|
238
|
-
|
|
239
|
-
// s.setAuthCode("your-auth-code");
|
|
240
|
-
|
|
241
|
-
// Boxo Connect Direct - onAuth hook
|
|
242
|
-
s.onAuth(async () => {
|
|
243
|
-
const response = await fetch('/api/get-miniapp-tokens');
|
|
244
|
-
const tokens = await response.json();
|
|
245
|
-
s.setAuthTokens(tokens.access_token, tokens.refresh_token);
|
|
246
|
-
});
|
|
203
|
+
s.setAuthCode("your-auth-code");
|
|
247
204
|
|
|
248
205
|
s.onLoginComplete((success, data) => {
|
|
249
206
|
console.log('Login:', success ? 'success' : 'failed', data);
|