@grabjs/superapp-sdk 1.7.15 → 1.7.17
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 +146 -49
- 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,i
|
|
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.CameraResultCode={SUCCESS:"SUCCESS",CANCELLED:"CANCELLED"},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
|
@@ -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
|
|
@@ -258,29 +314,60 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
|
258
314
|
// Ideally, initialize this only one and reuse across app.
|
|
259
315
|
const containerModule = new ContainerModule();
|
|
260
316
|
|
|
261
|
-
containerModule
|
|
262
|
-
|
|
263
|
-
|
|
317
|
+
containerModule
|
|
318
|
+
.openExternalLink("https://grab.com")
|
|
319
|
+
.then(({ result, error }) => {
|
|
320
|
+
if (result) {
|
|
321
|
+
// There is a valid result.
|
|
322
|
+
} else if (error) {
|
|
323
|
+
// Some error happened.
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### 12. Check connection status
|
|
329
|
+
|
|
330
|
+
**Method name**: `isConnected`
|
|
331
|
+
Call this method to check if the web app is connected to the Grab app via JSBridge.
|
|
332
|
+
|
|
333
|
+
**Arguments**
|
|
334
|
+
|
|
335
|
+
`None`
|
|
336
|
+
|
|
337
|
+
**Return type**
|
|
338
|
+
|
|
339
|
+
`None`
|
|
340
|
+
|
|
341
|
+
**Code example**
|
|
342
|
+
|
|
343
|
+
```javascript
|
|
344
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
345
|
+
|
|
346
|
+
const containerModule = new ContainerModule();
|
|
347
|
+
|
|
348
|
+
containerModule.isConnected().then(({ status_code, error }) => {
|
|
349
|
+
if (status_code === 200) {
|
|
350
|
+
// Connected to Grab app
|
|
264
351
|
} else if (error) {
|
|
265
|
-
//
|
|
352
|
+
// Not connected to Grab app
|
|
266
353
|
}
|
|
267
354
|
});
|
|
268
355
|
```
|
|
269
356
|
|
|
270
|
-
###
|
|
357
|
+
### 13. Send analytics event
|
|
271
358
|
|
|
272
359
|
**Method name**: `sendAnalyticsEvent`
|
|
273
360
|
|
|
274
361
|
**Arguments**
|
|
275
362
|
|
|
276
|
-
| Name | Type | Required | Description
|
|
277
|
-
| ------------ | ------ | -------- |
|
|
278
|
-
| eventDetails | Object | Yes | Event details containing state, name, and data
|
|
363
|
+
| Name | Type | Required | Description |
|
|
364
|
+
| ------------ | ------ | -------- | ---------------------------------------------- |
|
|
365
|
+
| eventDetails | Object | Yes | Event details containing state, name, and data |
|
|
279
366
|
|
|
280
367
|
**EventDetails Object Properties**
|
|
281
368
|
|
|
282
|
-
| Property | Type | Required | Description
|
|
283
|
-
| -------- | ------ | -------- |
|
|
369
|
+
| Property | Type | Required | Description |
|
|
370
|
+
| -------- | ------ | -------- | -------------------------------------------------------------------------- |
|
|
284
371
|
| state | String | Yes | State of the event (cf. Predefined ContainerAnalyticsEventState) |
|
|
285
372
|
| name | String | Yes | Name of the event (cf. Predefined ContainerAnalyticsEventName) |
|
|
286
373
|
| data | Object | No | Additional data for the event (cf. Predefined ContainerAnalyticsEventData) |
|
|
@@ -309,50 +396,60 @@ containerModule.openExternalLink("https://grab.com").then(({ result, error }) =>
|
|
|
309
396
|
**Code example**
|
|
310
397
|
|
|
311
398
|
```javascript
|
|
312
|
-
import {
|
|
399
|
+
import {
|
|
400
|
+
ContainerModule,
|
|
401
|
+
ContainerAnalyticsEventState,
|
|
402
|
+
ContainerAnalyticsEventName,
|
|
403
|
+
ContainerAnalyticsEventData,
|
|
404
|
+
} from "@grabjs/superapp-sdk";
|
|
313
405
|
|
|
314
406
|
const containerModule = new ContainerModule();
|
|
315
407
|
|
|
316
408
|
// Example: Send a DEFAULT event for HOMEPAGE state
|
|
317
|
-
containerModule
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
409
|
+
containerModule
|
|
410
|
+
.sendAnalyticsEvent({
|
|
411
|
+
state: ContainerAnalyticsEventState.HOMEPAGE,
|
|
412
|
+
name: ContainerAnalyticsEventName.DEFAULT,
|
|
413
|
+
})
|
|
414
|
+
.then(({ result, error }) => {
|
|
415
|
+
if (error) {
|
|
416
|
+
// Handle validation or other errors
|
|
417
|
+
}
|
|
418
|
+
});
|
|
325
419
|
|
|
326
420
|
// Example: Send a BOOK event for CHECKOUT_PAGE state
|
|
327
|
-
containerModule
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
421
|
+
containerModule
|
|
422
|
+
.sendAnalyticsEvent({
|
|
423
|
+
state: ContainerAnalyticsEventState.CHECKOUT_PAGE,
|
|
424
|
+
name: "BOOK",
|
|
425
|
+
data: {
|
|
426
|
+
[ContainerAnalyticsEventData.TRANSACTION_AMOUNT]: 100,
|
|
427
|
+
[ContainerAnalyticsEventData.TRANSACTION_CURRENCY]: "SGD",
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
.then(({ result, error }) => {
|
|
431
|
+
if (error) {
|
|
432
|
+
// Handle validation or other errors
|
|
433
|
+
}
|
|
434
|
+
});
|
|
339
435
|
|
|
340
436
|
// Example: Send a CLICK_RIDE event for CUSTOM state
|
|
341
|
-
containerModule
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
437
|
+
containerModule
|
|
438
|
+
.sendAnalyticsEvent({
|
|
439
|
+
state: ContainerAnalyticsEventState.CUSTOM,
|
|
440
|
+
name: "CLICK_RIDE",
|
|
441
|
+
data: {
|
|
442
|
+
[ContainerAnalyticsEventData.PAGE]: "LIST_RIDES",
|
|
443
|
+
departure_time: "2025-06-01 08:00:00",
|
|
444
|
+
arrival_time: "2025-06-01 10:30:00",
|
|
445
|
+
departure_address: "6 Bayfront Ave, Singapore 018974",
|
|
446
|
+
arrival_address:
|
|
447
|
+
"Petronas Twin Tower, Kuala Lumpur City Centre, 50088 Kuala Lumpur, Malaysia",
|
|
448
|
+
},
|
|
449
|
+
})
|
|
450
|
+
.then(({ result, error }) => {
|
|
451
|
+
if (error) {
|
|
452
|
+
// Handle validation or other errors
|
|
453
|
+
}
|
|
454
|
+
});
|
|
357
455
|
```
|
|
358
|
-
|