@grabjs/superapp-sdk 1.7.9 → 1.7.12
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/CheckoutModule.md +1 -4
- package/docs/ContainerModule.md +14 -14
- 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 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,a=(function(e,n){function a(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 l(r,e){var u=e.callbackNameFunc,i=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(a(e,"status_code"))if(a(e.result,"event"))switch(e.result.event){case d.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else t&&t.next&&t.next(e)},i(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 d;((d=n).StreamEvent||(d.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",d.wrapModule=function(u,i){u[function(e){return"Wrapped"+e}(i)]=function(e,o,n){var r={};return{invoke:function(n,t){return function(e,n){return n.funcNameToWrap,l(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[i])u[i][e.method](JSON.stringify(e));else{if(!(u.webkit&&u.webkit.messageHandlers&&u.webkit.messageHandlers[i]))throw new Error("Unexpected method '"+e.method+"' for module '"+i+"'");u.webkit.messageHandlers[i].postMessage(e)}}({callback:e,method:n,module:o,parameters:null!=t?t:{}})}})}}}(u,i)},Object.defineProperty(d,"__esModule",{value:!0})}(u={exports:{}},u.exports),u.exports),l=(i=a)&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,d=function(){function e(){t(this,e),l.wrapModule(window,"CheckoutModule")}return r(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),c=require("@grabjs/mobile-kit-bridge-sdk"),f=function(){function e(){t(this,e),c.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:"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:"_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),l.wrapModule(window,"LocaleModule")}return r(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){t(this,e),l.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),l.wrapModule(window,"MediaModule")}return r(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),v=require("@grabjs/mobile-kit-bridge-sdk"),k=function(){function e(){t(this,e),v.wrapModule(window,"PlatformModule")}return r(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),y=function(){function e(){t(this,e),l.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}(),M=require("@grabjs/mobile-kit-bridge-sdk"),b=function(){function e(){t(this,e),M.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}(),g=function(){function e(){t(this,e),l.wrapModule(window,"SystemWebViewKitModule")}return r(e,[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]),e}();e.CheckoutModule=d,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=k,e.ScopeModule=y,e.StorageModule=b,e.SystemWebViewKitModule=g,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/docs/CheckoutModule.md
CHANGED
|
@@ -15,7 +15,6 @@ Provides APIs to trigger native checkout flow from web.
|
|
|
15
15
|
| Name | Type | Description |
|
|
16
16
|
| -------------- | ------ | -------------------------------------------------------------------------- |
|
|
17
17
|
| responseParams | String | The response params that partners get when charge init endpoint is called |
|
|
18
|
-
| channel | String | The channel of triggering the transaction. In this case, it is `MiniApp` |
|
|
19
18
|
|
|
20
19
|
**Return type**
|
|
21
20
|
|
|
@@ -37,10 +36,8 @@ const checkoutModule = new checkoutModule();
|
|
|
37
36
|
// Get responseParams from chargeInit endpoint
|
|
38
37
|
const responseParams = chargeInit() // This is a dummy function
|
|
39
38
|
|
|
40
|
-
const channel = "MiniApp"
|
|
41
|
-
|
|
42
39
|
checkoutModule
|
|
43
|
-
.triggerCheckout(
|
|
40
|
+
.triggerCheckout(responseParams)
|
|
44
41
|
.then(({ result, error }) => {
|
|
45
42
|
if (result) {
|
|
46
43
|
// There is a valid result.
|
package/docs/ContainerModule.md
CHANGED
|
@@ -281,22 +281,22 @@ containerModule.openExternalLink("https://grab.com").then(({ result, error }) =>
|
|
|
281
281
|
|
|
282
282
|
| Property | Type | Required | Description |
|
|
283
283
|
| -------- | ------ | -------- | ----------------------------------------------------------------- |
|
|
284
|
-
| state | String | Yes | State of the event (cf. Predefined
|
|
285
|
-
| name | String | Yes | Name of the event (cf. Predefined
|
|
286
|
-
| data | Object | No | Additional data for the event (cf. Predefined
|
|
284
|
+
| state | String | Yes | State of the event (cf. Predefined ContainerAnalyticsEventState) |
|
|
285
|
+
| name | String | Yes | Name of the event (cf. Predefined ContainerAnalyticsEventName) |
|
|
286
|
+
| data | Object | No | Additional data for the event (cf. Predefined ContainerAnalyticsEventData) |
|
|
287
287
|
|
|
288
|
-
**Predefined
|
|
288
|
+
**Predefined ContainerAnalyticsEventState**
|
|
289
289
|
|
|
290
290
|
- 'HOMEPAGE'
|
|
291
291
|
- 'CHECKOUT_PAGE'
|
|
292
292
|
- 'BOOKING_COMPLETION'
|
|
293
293
|
- 'CUSTOM'
|
|
294
294
|
|
|
295
|
-
**Predefined
|
|
295
|
+
**Predefined ContainerAnalyticsEventName**
|
|
296
296
|
|
|
297
297
|
- 'DEFAULT'
|
|
298
298
|
|
|
299
|
-
**Predefined
|
|
299
|
+
**Predefined ContainerAnalyticsEventData**
|
|
300
300
|
|
|
301
301
|
- 'TRANSACTION_AMOUNT': 'transaction_amount'
|
|
302
302
|
- 'TRANSACTION_CURRENCY': 'transaction_currency'
|
|
@@ -309,14 +309,14 @@ containerModule.openExternalLink("https://grab.com").then(({ result, error }) =>
|
|
|
309
309
|
**Code example**
|
|
310
310
|
|
|
311
311
|
```javascript
|
|
312
|
-
import { ContainerModule,
|
|
312
|
+
import { ContainerModule, ContainerAnalyticsEventState, ContainerAnalyticsEventName, ContainerAnalyticsEventData } from "@grabjs/superapp-sdk";
|
|
313
313
|
|
|
314
314
|
const containerModule = new ContainerModule();
|
|
315
315
|
|
|
316
316
|
// Example: Send a DEFAULT event for HOMEPAGE state
|
|
317
317
|
containerModule.sendAnalyticsEvent({
|
|
318
|
-
state:
|
|
319
|
-
name:
|
|
318
|
+
state: ContainerAnalyticsEventState.HOMEPAGE,
|
|
319
|
+
name: ContainerAnalyticsEventName.DEFAULT,
|
|
320
320
|
}).then(({ result, error }) => {
|
|
321
321
|
if (error) {
|
|
322
322
|
// Handle validation or other errors
|
|
@@ -325,11 +325,11 @@ containerModule.sendAnalyticsEvent({
|
|
|
325
325
|
|
|
326
326
|
// Example: Send a BOOK event for CHECKOUT_PAGE state
|
|
327
327
|
containerModule.sendAnalyticsEvent({
|
|
328
|
-
state:
|
|
328
|
+
state: ContainerAnalyticsEventState.CHECKOUT_PAGE,
|
|
329
329
|
name: 'BOOK',
|
|
330
330
|
data: {
|
|
331
|
-
[
|
|
332
|
-
[
|
|
331
|
+
[ContainerAnalyticsEventData.TRANSACTION_AMOUNT]: 100,
|
|
332
|
+
[ContainerAnalyticsEventData.TRANSACTION_CURRENCY]: "SGD"
|
|
333
333
|
}
|
|
334
334
|
}).then(({ result, error }) => {
|
|
335
335
|
if (error) {
|
|
@@ -339,10 +339,10 @@ containerModule.sendAnalyticsEvent({
|
|
|
339
339
|
|
|
340
340
|
// Example: Send a CLICK_RIDE event for CUSTOM state
|
|
341
341
|
containerModule.sendAnalyticsEvent({
|
|
342
|
-
state:
|
|
342
|
+
state: ContainerAnalyticsEventState.CUSTOM,
|
|
343
343
|
name: 'CLICK_RIDE',
|
|
344
344
|
data: {
|
|
345
|
-
[
|
|
345
|
+
[ContainerAnalyticsEventData.PAGE]: "LIST_RIDES",
|
|
346
346
|
departure_time: "2025-06-01 08:00:00",
|
|
347
347
|
arrival_time: "2025-06-01 10:30:00",
|
|
348
348
|
departure_address: "6 Bayfront Ave, Singapore 018974",
|