@grabjs/superapp-sdk 1.7.16 → 1.7.18
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/dist/index.js +1 -1
- package/docs/CameraModule.md +44 -51
- package/docs/ContainerModule.md +59 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function o(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function r(e,n,t){return n&&o(e.prototype,n),t&&o(e,t),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var u,a,i=(function(e,n){function i(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];if(!e)return!1;var o=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return n.every(function(e){return 0<=o.indexOf(e)})}function
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function o(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function r(e,n,t){return n&&o(e.prototype,n),t&&o(e,t),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var u,a,i=(function(e,n){function i(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];if(!e)return!1;var o=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return n.every(function(e){return 0<=o.indexOf(e)})}function d(r,e){var u=e.callbackNameFunc,a=e.funcToWrap;return function(e){return{subscribe:e,then:function(o,r){return new Promise(function(){try{var n=null,t=!1;n=e({next:function(e){o&&o(e),n&&n.unsubscribe(),t=!0}}),t&&n&&n.unsubscribe()}catch(e){r&&r(e)}})}}}(function(t){var n,o=u();return r[o]=function(e){if(i(e,"status_code"))if(i(e.result,"event"))switch(e.result.event){case l.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else t&&t.next&&t.next(e)},a(o),n=function(e){var n=!1;return{isUnsubscribed:function(){return n},unsubscribe:function(){n||(delete r[o],t&&t.complete&&t.complete(),n=!0)}}}()})}var l;((l=n).StreamEvent||(l.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",l.wrapModule=function(u,a){u[function(e){return"Wrapped"+e}(a)]=function(e,o,n){var r={};return{invoke:function(n,t){return function(e,n){return n.funcNameToWrap,d(e,function(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&(t[o[r]]=e[o[r]])}return t}(n,["funcNameToWrap"]))}(e,{funcNameToWrap:n,callbackNameFunc:function(){var e=r[n]||0;return r[n]=e+1,function(e){var n=e.moduleName,t=e.funcName,o=e.requestID;return n+"_"+t+"Callback"+(null!==o?"_"+o:"")}({moduleName:o,requestID:e,funcName:n})},funcToWrap:function(e){return function(e){if(u[a])u[a][e.method](JSON.stringify(e));else{if(!(u.webkit&&u.webkit.messageHandlers&&u.webkit.messageHandlers[a]))throw new Error("Unexpected method '"+e.method+"' for module '"+a+"'");u.webkit.messageHandlers[a].postMessage(e)}}({callback:e,method:n,module:o,parameters:null!=t?t:{}})}})}}}(u,a)},Object.defineProperty(l,"__esModule",{value:!0})}(u={exports:{}},u.exports),u.exports),d=(a=i)&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,l=function(){function e(){t(this,e),d.wrapModule(window,"CameraModule")}return r(e,[{key:"scanQRCode",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return window.WrappedCameraModule.invoke("scanQRCode",e)}}]),e}(),c=function(){function e(){t(this,e),d.wrapModule(window,"CheckoutModule")}return r(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),f=function(){function e(){t(this,e),d.wrapModule(window,"ContainerModule")}return r(e,[{key:"setBackgroundColor",value:function(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}},{key:"setTitle",value:function(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}},{key:"hideBackButton",value:function(){return window.WrappedContainerModule.invoke("hideBackButton")}},{key:"showBackButton",value:function(){return window.WrappedContainerModule.invoke("showBackButton")}},{key:"hideRefreshButton",value:function(){return window.WrappedContainerModule.invoke("hideRefreshButton")}},{key:"showRefreshButton",value:function(){return window.WrappedContainerModule.invoke("showRefreshButton")}},{key:"close",value:function(){return window.WrappedContainerModule.invoke("close")}},{key:"onContentLoaded",value:function(){return window.WrappedContainerModule.invoke("onContentLoaded")}},{key:"showLoader",value:function(){return window.WrappedContainerModule.invoke("showLoader")}},{key:"hideLoader",value:function(){return window.WrappedContainerModule.invoke("hideLoader")}},{key:"openExternalLink",value:function(e){return window.WrappedContainerModule.invoke("openExternalLink",{url:e})}},{key:"sendAnalyticsEvent",value:function(e){var n=this._validateAnalyticsEvent(e);return n?{then:function(e){return e({status_code:400,error:n})}}:window.WrappedContainerModule.invoke("sendAnalyticsEvent",{state:e.state,name:e.name,data:e.data?JSON.stringify(e.data):null})}},{key:"isConnected",value:function(){var e=window.navigator&&window.navigator.userAgent;if(!e)return{then:function(e){return e({status_code:404,error:"User agent not available"})}};var n=e.toLowerCase().startsWith("grab");return{then:function(e){return e({status_code:n?200:404,error:n?null:"Not connected to Grab app"})}}}},{key:"_validateAnalyticsEvent",value:function(e){return null==e.name?"name is required":"string"!=typeof e.name?"name must be a string":null==e.state?"state is required":"string"!=typeof e.state?"state must be a string":null!=e.data&&"object"!==n(e.data)?"data must be undefined or an object":null}}]),e}(),s=function(){function e(){t(this,e),d.wrapModule(window,"LocaleModule")}return r(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){t(this,e),d.wrapModule(window,"LocationModule")}return r(e,[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}}]),e}(),w=function(){function e(){t(this,e),d.wrapModule(window,"MediaModule")}return r(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),v=function(){function e(){t(this,e),d.wrapModule(window,"PlatformModule")}return r(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),k=function(){function e(){t(this,e),d.wrapModule(window,"ScopeModule")}return r(e,[{key:"hasAccessTo",value:function(e,n){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:n})}},{key:"reloadScopes",value:function(){return window.WrappedScopeModule.invoke("reloadScopes")}}]),e}(),y=function(){function e(){t(this,e),d.wrapModule(window,"StorageModule")}return r(e,[{key:"setBoolean",value:function(e,n){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:n})}},{key:"getBoolean",value:function(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}},{key:"setInt",value:function(e,n){return window.WrappedStorageModule.invoke("setInt",{key:e,value:n})}},{key:"getInt",value:function(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}},{key:"setString",value:function(e,n){return window.WrappedStorageModule.invoke("setString",{key:e,value:n})}},{key:"getString",value:function(e){return window.WrappedStorageModule.invoke("getString",{key:e})}},{key:"setDouble",value:function(e,n){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:n})}},{key:"getDouble",value:function(e){return window.WrappedStorageModule.invoke("getDouble",{key:e})}},{key:"remove",value:function(e){return window.WrappedStorageModule.invoke("remove",{key:e})}},{key:"removeAll",value:function(){return window.WrappedStorageModule.invoke("removeAll")}}]),e}(),M=function(){function e(){t(this,e),d.wrapModule(window,"SystemWebViewKitModule")}return r(e,[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]),e}();e.CameraModule=l,e.CheckoutModule=c,e.ContainerAnalyticsEventData={TRANSACTION_AMOUNT:"transaction_amount",TRANSACTION_CURRENCY:"transaction_currency",PAGE:"page"},e.ContainerAnalyticsEventName={DEFAULT:"DEFAULT"},e.ContainerAnalyticsEventState={HOMEPAGE:"HOMEPAGE",CHECKOUT_PAGE:"CHECKOUT_PAGE",BOOKING_COMPLETION:"BOOKING_COMPLETION",CUSTOM:"CUSTOM"},e.ContainerModule=f,e.LocaleModule=s,e.LocationModule=p,e.MediaModule=w,e.PlatformModule=v,e.ScopeModule=k,e.StorageModule=y,e.SystemWebViewKitModule=M,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/docs/CameraModule.md
CHANGED
|
@@ -5,7 +5,7 @@ The CameraModule provides functionality to open the device camera for QR code sc
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
-
import { CameraModule
|
|
8
|
+
import { CameraModule } from '@grab/superapp-sdk';
|
|
9
9
|
|
|
10
10
|
const cameraModule = new CameraModule();
|
|
11
11
|
```
|
|
@@ -24,73 +24,66 @@ Opens the camera to scan QR codes with optional configuration.
|
|
|
24
24
|
|
|
25
25
|
**Example:**
|
|
26
26
|
```javascript
|
|
27
|
-
// With custom title
|
|
28
27
|
cameraModule.scanQRCode({ title: 'Scan Payment QR' })
|
|
29
|
-
.then((
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} else if (error) {
|
|
47
|
-
// Some error happened.
|
|
28
|
+
.then((response) => {
|
|
29
|
+
switch (response.status_code) {
|
|
30
|
+
case 200:
|
|
31
|
+
// Success - QR code scanned
|
|
32
|
+
console.log('QR Code scanned:', response.result.qrCode);
|
|
33
|
+
break;
|
|
34
|
+
case 204:
|
|
35
|
+
// No result - user cancelled
|
|
36
|
+
console.log('No result - user cancelled');
|
|
37
|
+
break;
|
|
38
|
+
case 403:
|
|
39
|
+
// Permission denied
|
|
40
|
+
console.log('Camera access denied:', response.error);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
// Handle other potential status codes
|
|
44
|
+
console.log('Error:', response.error);
|
|
48
45
|
}
|
|
49
46
|
});
|
|
50
47
|
```
|
|
51
48
|
|
|
52
|
-
## Constants
|
|
53
|
-
|
|
54
|
-
### `CameraResultCode`
|
|
55
|
-
|
|
56
|
-
Enum for different camera result codes:
|
|
57
|
-
|
|
58
|
-
- `SUCCESS`: Successfully scanned a QR code
|
|
59
|
-
- `CANCELLED`: User cancelled the camera operation
|
|
60
|
-
|
|
61
49
|
## Response Format
|
|
62
50
|
|
|
63
|
-
The camera method returns an object
|
|
51
|
+
The camera method returns an object with different structures based on the result:
|
|
64
52
|
|
|
53
|
+
### Success Response (Status Code 200)
|
|
65
54
|
```javascript
|
|
66
55
|
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
error: null // Error message if an error occurred
|
|
56
|
+
"status_code": 200,
|
|
57
|
+
"result": {
|
|
58
|
+
"qrCode": "scanned_qr_code_string" // The QR code content
|
|
59
|
+
}
|
|
72
60
|
}
|
|
73
61
|
```
|
|
74
62
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
### No Result Response (Status Code 204)
|
|
64
|
+
```javascript
|
|
65
|
+
{
|
|
66
|
+
"status_code": 204
|
|
67
|
+
// No result property
|
|
68
|
+
// No error property
|
|
69
|
+
}
|
|
70
|
+
```
|
|
78
71
|
|
|
72
|
+
### Error Response (Status Code 403)
|
|
79
73
|
```javascript
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} else if (result.code === CameraResultCode.CANCELLED) {
|
|
86
|
-
console.log('User cancelled camera');
|
|
87
|
-
}
|
|
88
|
-
} else if (error) {
|
|
89
|
-
// Some error happened.
|
|
90
|
-
}
|
|
91
|
-
});
|
|
74
|
+
{
|
|
75
|
+
"status_code": 403,
|
|
76
|
+
"error": "Camera access denied"
|
|
77
|
+
// No result property
|
|
78
|
+
}
|
|
92
79
|
```
|
|
93
80
|
|
|
81
|
+
## Status Codes
|
|
82
|
+
|
|
83
|
+
- `200`: Successfully scanned a QR code
|
|
84
|
+
- `204`: No result (user cancelled)
|
|
85
|
+
- `403`: Camera access denied
|
|
86
|
+
|
|
94
87
|
## Notes
|
|
95
88
|
|
|
96
89
|
Camera permissions and lifecycle (opening/closing) are handled automatically by the native iOS app, so no additional management is required from the JavaScript side.
|
package/docs/ContainerModule.md
CHANGED
|
@@ -235,7 +235,63 @@ containerModule.onContentLoaded().then(({ result, error }) => {
|
|
|
235
235
|
});
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
### 9.
|
|
238
|
+
### 9. Show loader
|
|
239
|
+
|
|
240
|
+
**Method name**: `showLoader`
|
|
241
|
+
Call this method to notify the client to show loader
|
|
242
|
+
|
|
243
|
+
**Arguments**
|
|
244
|
+
|
|
245
|
+
`None`
|
|
246
|
+
|
|
247
|
+
**Return type**
|
|
248
|
+
|
|
249
|
+
`None`
|
|
250
|
+
|
|
251
|
+
**Code example**
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
255
|
+
|
|
256
|
+
// Ideally, initialize this only one and reuse across app.
|
|
257
|
+
const containerModule = new ContainerModule();
|
|
258
|
+
|
|
259
|
+
containerModule.showLoader().then(({ result, error }) => {
|
|
260
|
+
if (error) {
|
|
261
|
+
// Some error happened.
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 10. Hide loader
|
|
267
|
+
|
|
268
|
+
**Method name**: `hideLoader`
|
|
269
|
+
Call this method to notify the client to hide loader
|
|
270
|
+
|
|
271
|
+
**Arguments**
|
|
272
|
+
|
|
273
|
+
`None`
|
|
274
|
+
|
|
275
|
+
**Return type**
|
|
276
|
+
|
|
277
|
+
`None`
|
|
278
|
+
|
|
279
|
+
**Code example**
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
283
|
+
|
|
284
|
+
// Ideally, initialize this only one and reuse across app.
|
|
285
|
+
const containerModule = new ContainerModule();
|
|
286
|
+
|
|
287
|
+
containerModule.hideLoader().then(({ result, error }) => {
|
|
288
|
+
if (error) {
|
|
289
|
+
// Some error happened.
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### 11. Open link in external browser
|
|
239
295
|
|
|
240
296
|
**Method name**: `openExternalLink`
|
|
241
297
|
Call this method to tell client to open the link in external browser
|
|
@@ -269,7 +325,7 @@ containerModule
|
|
|
269
325
|
});
|
|
270
326
|
```
|
|
271
327
|
|
|
272
|
-
###
|
|
328
|
+
### 12. Check connection status
|
|
273
329
|
|
|
274
330
|
**Method name**: `isConnected`
|
|
275
331
|
Call this method to check if the web app is connected to the Grab app via JSBridge.
|
|
@@ -298,7 +354,7 @@ containerModule.isConnected().then(({ status_code, error }) => {
|
|
|
298
354
|
});
|
|
299
355
|
```
|
|
300
356
|
|
|
301
|
-
###
|
|
357
|
+
### 13. Send analytics event
|
|
302
358
|
|
|
303
359
|
**Method name**: `sendAnalyticsEvent`
|
|
304
360
|
|