@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.
Files changed (2) hide show
  1. package/README.md +18 -61
  2. 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 (OAuth)
44
- onGetAuthTokens?: () => Promise<LoginResponse>; // Optional, for Boxo Connect Direct
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
- The SDK supports two authentication methods: **Boxo Connect OAuth** and **Boxo Connect Direct**.
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
- **2. Provide callback**
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
- The SDK will try OAuth methods in this order:
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
- // Your backend calls Boxo Dashboard connect endpoint to get miniapp tokens
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
- **2. Use `onGetAuthTokens` callback**
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 response = await fetch('/api/get-miniapp-tokens', {
114
- headers: { 'Authorization': `Bearer ${yourHostAppToken}` }
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
- **3. Pre-set tokens before login**
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
- **Authentication Priority Order:**
104
+ The SDK will try these in order:
139
105
 
140
- When the miniapp calls `login()`, the SDK will try these methods in order:
141
- 1. Pre-set tokens (via `setAuthTokens()`)
142
- 2. `onGetAuthTokens` callback
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 (OAuth) |
187
- | `setAuthTokens(token, refreshToken?)` | Set authentication tokens directly (Boxo Connect Direct) |
188
- | `onAuth(callback)` | Register lifecycle hook for authentication (Boxo Connect Direct) |
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
- // Boxo Connect OAuth
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appboxo/web-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Boxo Desktop Host App SDK for handling miniapp events",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",