@grabjs/superapp-sdk 2.0.0-beta.28 → 2.0.0-beta.29

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 CHANGED
@@ -12,95 +12,6 @@ Each module encapsulates a specific domain of functionality, offering strongly-t
12
12
  - **Streaming Support** — Real-time data streams for location updates and media events
13
13
  - **Automatic Fallbacks** — Graceful degradation when native features are unavailable
14
14
 
15
- ## Installation
16
-
17
- ### NPM (ES Modules)
18
-
19
- ```bash
20
- npm install @grabjs/superapp-sdk
21
- ```
22
-
23
- ```typescript
24
- import { ContainerModule, LocationModule } from '@grabjs/superapp-sdk';
25
- ```
26
-
27
- ### CDN (UMD Bundle)
28
-
29
- ```html
30
- <script src="https://cdn.jsdelivr.net/npm/@grabjs/superapp-sdk/dist/index.js"></script>
31
- <script>
32
- const { ContainerModule, LocationModule } = window.SuperAppSDK;
33
- </script>
34
- ```
35
-
36
- ## Usage
37
-
38
- ### Basic Module Initialization
39
-
40
- All modules are instantiated with a simple constructor call:
41
-
42
- ```typescript
43
- import { ContainerModule, LocationModule, IdentityModule } from '@grabjs/superapp-sdk';
44
-
45
- const container = new ContainerModule();
46
- const location = new LocationModule();
47
- const identity = new IdentityModule();
48
- ```
49
-
50
- ### Handling Responses
51
-
52
- All SDK methods return a standardized response with HTTP-style status codes. Use type guards for response handling and type narrowing:
53
-
54
- ```typescript
55
- import { CameraModule, isSuccess, isError } from '@grabjs/superapp-sdk';
56
-
57
- const camera = new CameraModule();
58
- const response = await camera.scanQRCode({ title: 'Scan Payment QR' });
59
-
60
- if (isSuccess(response)) {
61
- switch (response.status_code) {
62
- case 200:
63
- console.log('QR Code scanned:', response.result.qrCode);
64
- break;
65
- case 204:
66
- console.log('Scanning cancelled');
67
- break;
68
- }
69
- } else if (isError(response)) {
70
- switch (response.status_code) {
71
- case 403:
72
- console.error('Camera permission denied:', response.error);
73
- break;
74
- default:
75
- console.error('Request failed:', response.error);
76
- }
77
- }
78
- ```
79
-
80
- ### Working with Streams
81
-
82
- Some modules provide streaming methods for real-time data:
83
-
84
- ```typescript
85
- import { LocationModule, isSuccess } from '@grabjs/superapp-sdk';
86
-
87
- const location = new LocationModule();
88
-
89
- const subscription = location.observeLocationChange().subscribe({
90
- next: (response) => {
91
- if (isSuccess(response)) {
92
- console.log('Location:', response.result);
93
- }
94
- },
95
- complete: () => {
96
- console.log('Stream ended');
97
- },
98
- });
99
-
100
- // Unsubscribe when done
101
- subscription.unsubscribe();
102
- ```
103
-
104
15
  ## Available Modules
105
16
 
106
17
  - **[CameraModule](https://grab.github.io/superapp-sdk/classes/CameraModule.html)** — Access device camera capabilities for QR code scanning
@@ -135,60 +46,8 @@ subscription.unsubscribe();
135
46
 
136
47
  - **[UserAttributesModule](https://grab.github.io/superapp-sdk/classes/UserAttributesModule.html)** — Access user attribute data
137
48
 
138
- > **Important:** Always call `ScopeModule.reloadScopes()` on MiniApp launch and after OAuth before accessing protected resources — scopes are not loaded automatically.
139
-
140
- ## Response Status Codes
141
-
142
- The SDK uses HTTP-style status codes for all responses:
143
-
144
- | Code | Type | Description |
145
- | ----- | ----------------- | --------------------------------------------------- |
146
- | `200` | OK | Request successful, `result` contains response data |
147
- | `204` | No Content | Request successful, no data returned |
148
- | `302` | Redirect | OAuth redirect in progress |
149
- | `400` | Bad Request | Invalid request parameters |
150
- | `401` | Unauthorized | Authentication required |
151
- | `403` | Forbidden | Insufficient permissions for this operation |
152
- | `404` | Not Found | Resource not found |
153
- | `424` | Failed Dependency | Underlying native request failed |
154
- | `426` | Upgrade Required | Requires newer Grab app version |
155
- | `500` | Internal Error | Unexpected SDK error |
156
- | `501` | Not Implemented | Method requires Grab SuperApp environment |
157
-
158
- ## Type Guards
159
-
160
- The SDK provides type guards for response narrowing:
161
-
162
- ```typescript
163
- import {
164
- isSuccess,
165
- isError,
166
- isOk,
167
- isNoContent,
168
- isClientError,
169
- isServerError,
170
- isFound,
171
- isRedirection,
172
- } from '@grabjs/superapp-sdk';
173
-
174
- if (isSuccess(response)) {
175
- // 200 or 204 — use isOk() / isNoContent() to narrow further
176
- }
177
- if (isError(response)) {
178
- // response.error: string is guaranteed
179
- // use isClientError() / isServerError() to narrow further
180
- }
181
- if (isRedirection(response)) {
182
- // 302 — use isFound() to narrow further
183
- }
184
- ```
185
-
186
- ## Best Practices
187
-
188
- 1. **Always check for success with type guards** before accessing `response.result`. Use `isSuccess()` and `isError()` for type-safe response handling.
189
-
190
- 2. **Never use try/catch for SDK errors** — SDK methods never throw. All failures are returned as responses with a numeric `status_code` and an `error` field.
191
-
192
- 3. **Call `reloadScopes()` when your MiniApp launches and after OAuth** before accessing protected resources.
193
-
194
- 4. **Unsubscribe from streams** when your component unmounts or you no longer need updates.
49
+ ## Documentation
50
+
51
+ - [Setup Guide](https://grab.github.io/superapp-sdk/documents/Setup.html) — installation, importing, environment requirements
52
+ - [Core Concepts](https://grab.github.io/superapp-sdk/documents/Core_Concepts.html) — response pattern, status codes, type guards
53
+ - [Integration Guide](https://grab.github.io/superapp-sdk/documents/Integration_Guide.html) initialization sequence, permission handling, navigation