@grabjs/superapp-sdk 1.7.19 → 1.7.21
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/ContainerModule.md +36 -2
- package/docs/LocationModule.md +94 -0
- 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
|
|
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 o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(e,n){for(var o=0;o<n.length;o++){var t=n[o];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function r(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),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=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];if(!e)return!1;var t=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return n.every(function(e){return 0<=t.indexOf(e)})}function d(r,e){var u=e.callbackNameFunc,a=e.funcToWrap;return function(e){return{subscribe:e,then:function(t,r){return new Promise(function(){try{var n=null,o=!1;n=e({next:function(e){t&&t(e),n&&n.unsubscribe(),o=!0}}),o&&n&&n.unsubscribe()}catch(e){r&&r(e)}})}}}(function(o){var n,t=u();return r[t]=function(e){if(i(e,"status_code"))if(i(e.result,"event"))switch(e.result.event){case l.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else o&&o.next&&o.next(e)},a(t),n=function(e){var n=!1;return{isUnsubscribed:function(){return n},unsubscribe:function(){n||(delete r[t],o&&o.complete&&o.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,t,n){var r={};return{invoke:function(n,o){return function(e,n){return n.funcNameToWrap,d(e,function(e,n){var o={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(o[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&(o[t[r]]=e[t[r]])}return o}(n,["funcNameToWrap"]))}(e,{funcNameToWrap:n,callbackNameFunc:function(){var e=r[n]||0;return r[n]=e+1,function(e){var n=e.moduleName,o=e.funcName,t=e.requestID;return n+"_"+o+"Callback"+(null!==t?"_"+t:"")}({moduleName:t,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:t,parameters:null!=o?o:{}})}})}}}(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(){o(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(){o(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(){o(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:"onCtaTap",value:function(e){return window.WrappedContainerModule.invoke("onCtaTap",{action: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=/grab[a-z]*\//i.test(e);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(){o(this,e),d.wrapModule(window,"LocaleModule")}return r(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){o(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")}},{key:"getCountryCode",value:function(){return window.WrappedLocationModule.invoke("getCountryCode")}}]),e}(),w=function(){function e(){o(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(){o(this,e),d.wrapModule(window,"PlatformModule")}return r(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),k=function(){function e(){o(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(){o(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(){o(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/ContainerModule.md
CHANGED
|
@@ -325,7 +325,41 @@ containerModule
|
|
|
325
325
|
});
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
-
### 12.
|
|
328
|
+
### 12. On CTA Tap
|
|
329
|
+
|
|
330
|
+
**Method name**: `onCtaTap`
|
|
331
|
+
Call this method to notify the client that the user has continued the flow
|
|
332
|
+
|
|
333
|
+
**Arguments**
|
|
334
|
+
|
|
335
|
+
| Name | Type | Required | Description |
|
|
336
|
+
|--------| ------ | -------- |-------------|
|
|
337
|
+
| action | String | Yes | tap action |
|
|
338
|
+
|
|
339
|
+
**Return type**
|
|
340
|
+
|
|
341
|
+
`None`
|
|
342
|
+
|
|
343
|
+
**Code example**
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
347
|
+
|
|
348
|
+
// Ideally, initialize this only one and reuse across app.
|
|
349
|
+
const containerModule = new ContainerModule();
|
|
350
|
+
|
|
351
|
+
containerModule
|
|
352
|
+
.onCtaTap("AV_LANDING_PAGE_CONTINUE")
|
|
353
|
+
.then(({ result, error }) => {
|
|
354
|
+
if (result) {
|
|
355
|
+
// There is a valid result.
|
|
356
|
+
} else if (error) {
|
|
357
|
+
// Some error happened.
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### 13. Check connection status
|
|
329
363
|
|
|
330
364
|
**Method name**: `isConnected`
|
|
331
365
|
Call this method to check if the web app is connected to the Grab app via JSBridge.
|
|
@@ -354,7 +388,7 @@ containerModule.isConnected().then(({ status_code, error }) => {
|
|
|
354
388
|
});
|
|
355
389
|
```
|
|
356
390
|
|
|
357
|
-
###
|
|
391
|
+
### 14. Send analytics event
|
|
358
392
|
|
|
359
393
|
**Method name**: `sendAnalyticsEvent`
|
|
360
394
|
|
package/docs/LocationModule.md
CHANGED
|
@@ -76,3 +76,97 @@ const subscription = locationModule.observeLocationChange({}).subscribe({
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
```
|
|
79
|
+
|
|
80
|
+
### 3. Get current user country code
|
|
81
|
+
|
|
82
|
+
**Method name**: `getCountryCode`
|
|
83
|
+
|
|
84
|
+
**Scopes to be requested**: `mobile.geolocation`
|
|
85
|
+
|
|
86
|
+
**Arguments**: `None`
|
|
87
|
+
|
|
88
|
+
**Return type**
|
|
89
|
+
|
|
90
|
+
| Name | Type | Description |
|
|
91
|
+
| ----------- | ------ | ------------------------------ |
|
|
92
|
+
| countryCode | String | country code (e.g., "SG", "ID", "MY") |
|
|
93
|
+
|
|
94
|
+
**Code example**
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
import { LocationModule } from '@grab/superapp-sdk';
|
|
98
|
+
|
|
99
|
+
// Ideally, initialize this only one and reuse across app.
|
|
100
|
+
const locationModule = new LocationModule()
|
|
101
|
+
|
|
102
|
+
locationModule.getCountryCode({})
|
|
103
|
+
.then((response) => {
|
|
104
|
+
switch (response.status_code) {
|
|
105
|
+
case 200:
|
|
106
|
+
// Success - country code retrieved
|
|
107
|
+
console.log('Country code:', response.result);
|
|
108
|
+
break;
|
|
109
|
+
case 204:
|
|
110
|
+
// No result - location is undefined or might be uncovered by location service data
|
|
111
|
+
console.log('No result - location is undefined or uncovered by location service');
|
|
112
|
+
break;
|
|
113
|
+
case 403:
|
|
114
|
+
// Permission denied - mobile.geolocation scope not granted
|
|
115
|
+
console.log('Location access denied:', response.error);
|
|
116
|
+
break;
|
|
117
|
+
case 424:
|
|
118
|
+
// Location service has issue/unaccessible
|
|
119
|
+
console.log('Location service unavailable:', response.error);
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
// Handle other potential status codes
|
|
123
|
+
console.log('Error:', response.error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Response Format
|
|
129
|
+
|
|
130
|
+
The location methods return an object with different structures based on the result:
|
|
131
|
+
|
|
132
|
+
### Success Response (Status Code 200)
|
|
133
|
+
```javascript
|
|
134
|
+
{
|
|
135
|
+
"status_code": 200,
|
|
136
|
+
"result": "SG" // The country code (e.g., "SG", "ID", "MY")
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### No Result Response (Status Code 204)
|
|
141
|
+
```javascript
|
|
142
|
+
{
|
|
143
|
+
"status_code": 204
|
|
144
|
+
// No result property
|
|
145
|
+
// No error property
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Error Response (Status Code 403)
|
|
150
|
+
```javascript
|
|
151
|
+
{
|
|
152
|
+
"status_code": 403,
|
|
153
|
+
"error": "Location access denied"
|
|
154
|
+
// No result property
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Error Response (Status Code 424)
|
|
159
|
+
```javascript
|
|
160
|
+
{
|
|
161
|
+
"status_code": 424,
|
|
162
|
+
"error": "Determining country code from coordinates fails"
|
|
163
|
+
// No result property
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Status Codes
|
|
168
|
+
|
|
169
|
+
- `200`: Successfully retrieved country code
|
|
170
|
+
- `204`: No result (location is undefined or uncovered by location service or in ocean area)
|
|
171
|
+
- `403`: Location access denied (mobile.geolocation scope not granted)
|
|
172
|
+
- `424`: Location service unavailable/unaccessible
|