@appboxo/web-sdk 1.0.6 → 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 +43 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,21 +41,20 @@ const sdk = new AppboxoWebSDK({
|
|
|
41
41
|
baseUrl?: string; // Optional, default: "https://dashboard.appboxo.com/api/v1"
|
|
42
42
|
debug?: boolean; // Optional, default: false
|
|
43
43
|
onGetAuthCode?: () => Promise<string>; // Optional, for automatic auth code retrieval
|
|
44
|
+
onGetAuthTokens?: () => Promise<LoginResponse>; // Optional, for direct auth tokens
|
|
44
45
|
onPaymentRequest?: (params: PaymentRequest) => Promise<PaymentResponse>; // Optional, for handling payment requests
|
|
45
46
|
});
|
|
46
47
|
```
|
|
47
48
|
|
|
48
49
|
### Authentication
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
**1. Set auth code explicitly**
|
|
51
|
+
**OAuth flow:**
|
|
53
52
|
|
|
54
53
|
```typescript
|
|
55
54
|
sdk.setAuthCode(authCode);
|
|
56
55
|
```
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
Or provide a callback:
|
|
59
58
|
|
|
60
59
|
```typescript
|
|
61
60
|
const sdk = new AppboxoWebSDK({
|
|
@@ -68,11 +67,45 @@ const sdk = new AppboxoWebSDK({
|
|
|
68
67
|
});
|
|
69
68
|
```
|
|
70
69
|
|
|
70
|
+
**Direct auth flow:**
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
sdk.onAuth(async () => {
|
|
74
|
+
const response = await fetch('/api/get-miniapp-tokens');
|
|
75
|
+
const tokens = await response.json();
|
|
76
|
+
sdk.setAuthTokens(tokens.access_token, tokens.refresh_token);
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or use callback:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const sdk = new AppboxoWebSDK({
|
|
84
|
+
clientId: "your-client-id",
|
|
85
|
+
appId: "your-app-id",
|
|
86
|
+
onGetAuthTokens: async () => {
|
|
87
|
+
const res = await fetch('/api/get-miniapp-tokens');
|
|
88
|
+
const result = await res.json();
|
|
89
|
+
return {
|
|
90
|
+
token: result.access_token,
|
|
91
|
+
refresh_token: result.refresh_token
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or set tokens directly:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const tokens = await getTokensFromBackend();
|
|
101
|
+
sdk.setAuthTokens(tokens.access_token, tokens.refresh_token);
|
|
102
|
+
```
|
|
103
|
+
|
|
71
104
|
The SDK will try these in order:
|
|
72
105
|
|
|
73
|
-
1.
|
|
74
|
-
2.
|
|
75
|
-
3.
|
|
106
|
+
1. Pre-set tokens (`setAuthTokens`)
|
|
107
|
+
2. Direct auth callback (`onGetAuthTokens`)
|
|
108
|
+
3. OAuth auth code (`setAuthCode` or `onGetAuthCode` callback)
|
|
76
109
|
|
|
77
110
|
### Payment Processing
|
|
78
111
|
|
|
@@ -116,6 +149,8 @@ Note: When `onPaymentRequest` is set, the SDK automatically tells the miniapp it
|
|
|
116
149
|
| Method | Description |
|
|
117
150
|
|--------|-------------|
|
|
118
151
|
| `setAuthCode(code)` | Set authentication code |
|
|
152
|
+
| `setAuthTokens(token, refreshToken?)` | Set authentication tokens directly |
|
|
153
|
+
| `onAuth(callback)` | Register callback for authentication events |
|
|
119
154
|
| `mount(config)` | Create iframe and initialize SDK |
|
|
120
155
|
| `setIframe(iframe)` | Set iframe element manually |
|
|
121
156
|
| `initialize()` | Start listening for events |
|
|
@@ -166,6 +201,7 @@ function App() {
|
|
|
166
201
|
});
|
|
167
202
|
|
|
168
203
|
s.setAuthCode("your-auth-code");
|
|
204
|
+
|
|
169
205
|
s.onLoginComplete((success, data) => {
|
|
170
206
|
console.log('Login:', success ? 'success' : 'failed', data);
|
|
171
207
|
});
|