@grabjs/superapp-sdk 1.7.7 → 1.7.9

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 CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function l(e){return(l="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,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function n(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,a,i=(function(e,t){function u(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(!e)return!1;var o=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return t.every(function(e){return 0<=o.indexOf(e)})}function c(r,e){var a=e.callbackNameFunc,i=e.funcToWrap;return function(e){return{subscribe:e,then:function(o,r){return new Promise(function(){try{var t=null,n=!1;t=e({next:function(e){o&&o(e),t&&t.unsubscribe(),n=!0}}),n&&t&&t.unsubscribe()}catch(e){r&&r(e)}})}}}(function(n){var t,o=a();return r[o]=function(e){if(u(e,"status_code"))if(u(e.result,"event"))switch(e.result.event){case s.StreamEvent.STREAM_TERMINATED:t.unsubscribe()}else n&&n.next&&n.next(e)},i(o),t=function(e){var t=!1;return{isUnsubscribed:function(){return t},unsubscribe:function(){t||(delete r[o],n&&n.complete&&n.complete(),t=!0)}}}()})}var s;((s=t).StreamEvent||(s.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",s.wrapModule=function(a,i){a[function(e){return"Wrapped"+e}(i)]=function(e,o,t){var r={};return{invoke:function(t,n){return function(e,t){return t.funcNameToWrap,c(e,function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&(n[o[r]]=e[o[r]])}return n}(t,["funcNameToWrap"]))}(e,{funcNameToWrap:t,callbackNameFunc:function(){var e=r[t]||0;return r[t]=e+1,function(e){var t=e.moduleName,n=e.funcName,o=e.requestID;return t+"_"+n+"Callback"+(null!==o?"_"+o:"")}({moduleName:o,requestID:e,funcName:t})},funcToWrap:function(e){return function(e){if(a[i])a[i][e.method](JSON.stringify(e));else{if(!(a.webkit&&a.webkit.messageHandlers&&a.webkit.messageHandlers[i]))throw new Error("Unexpected method '"+e.method+"' for module '"+i+"'");a.webkit.messageHandlers[i].postMessage(e)}}({callback:e,method:t,module:o,parameters:null!=n?n:{}})}})}}}(a,i)},Object.defineProperty(s,"__esModule",{value:!0})}(r={exports:{}},r.exports),r.exports),u=(a=i)&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,c=function(){function e(){t(this,e),u.wrapModule(window,"CheckoutModule")}return n(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),s=require("@grabjs/mobile-kit-bridge-sdk"),v={STARTED:"STARTED",PAYMENT_STATUS_UPDATED:"PAYMENT_STATUS_UPDATED",ERROR_OCCURRED:"ERROR_OCCURRED",CUSTOM:"CUSTOM"},d={WARNING:"WARNING",ERROR:"ERROR",CRITICAL:"CRITICAL"},f={SUCCESS:"SUCCESS",FAILURE:"FAILURE",CANCEL:"CANCEL",PROCESSING:"PROCESSING"},p=function(){function e(){t(this,e),s.wrapModule(window,"ContainerModule")}return n(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:"sendAnalyticsEvent",value:function(e){var t=this._validateAnalyticsEvent(e);return t?{then:function(e){return e({result:null,error:t})}}:window.WrappedContainerModule.invoke("sendAnalyticsEvent",{url:e.url,sessionId:e.sessionId,viewName:e.viewName,eventName:e.eventName,eventData:JSON.stringify(e.eventData)})}},{key:"_validateAnalyticsEvent",value:function(e){for(var t=0,n=["eventName"];t<n.length;t++){var o=n[t];if(!e[o])return"Missing required field: ".concat(o)}if(e.url&&"string"!=typeof e.url)return"url must be a string";if(e.sessionId&&"string"!=typeof e.sessionId)return"sessionId must be a string";if(e.viewName&&"string"!=typeof e.viewName)return"viewName must be a string";var r=Object.values(v);if(!r.includes(e.eventName))return"Invalid eventName. Must be one of: ".concat(r.join(", "));switch(e.eventName){case v.STARTED:return this._validateStartedEvent(e.eventData);case v.PAYMENT_STATUS_UPDATED:return this._validatePaymentStatusUpdatedEvent(e.eventData);case v.ERROR_OCCURRED:return this._validateErrorOccurredEvent(e.eventData);case v.CUSTOM:return this._validateCustomEvent(e.eventData)}return null}},{key:"_validateStartedEvent",value:function(e){return null!=e?"".concat(v.STARTED," event should have empty eventData"):null}},{key:"_validatePaymentStatusUpdatedEvent",value:function(e){if(!e)return"".concat(v.PAYMENT_STATUS_UPDATED," event requires eventData");if("object"!==l(e)||Array.isArray(e))return"".concat(v.PAYMENT_STATUS_UPDATED," event requires eventData to be an object");var t=["transactionId","statusCode","statusMessage","products","amount","currency","promoCodes"],n=Object.keys(e).filter(function(e){return!t.includes(e)});if(0<n.length)return"".concat(v.PAYMENT_STATUS_UPDATED," event does not allow additional fields in eventData: ").concat(n.join(", "));if(e.transactionId&&"string"!=typeof e.transactionId)return"".concat(v.PAYMENT_STATUS_UPDATED," event requires transactionId in eventData to be a string");if(!e.statusCode)return"".concat(v.PAYMENT_STATUS_UPDATED," event requires statusCode in eventData to be defined");if("string"!=typeof e.statusCode)return"".concat(v.PAYMENT_STATUS_UPDATED," event requires statusCode in eventData to be a string");var o=Object.values(f);if(!o.includes(e.statusCode))return"".concat(v.PAYMENT_STATUS_UPDATED," event requires statusCode in eventData to be one of: ").concat(o.join(", "));if(e.statusMessage&&"string"!=typeof e.statusMessage)return"".concat(v.PAYMENT_STATUS_UPDATED," event requires statusMessage in eventData to be a string");if(e.products){if(!Array.isArray(e.products))return"".concat(v.PAYMENT_STATUS_UPDATED," event requires products in eventData to be an array");var r=!0,a=!1,i=void 0;try{for(var u,c=function(){var e=u.value,t=["id","quantity"],n=Object.keys(e).filter(function(e){return!t.includes(e)});return 0<n.length?{v:"".concat(v.PAYMENT_STATUS_UPDATED," event does not allow additional fields in eventData.products item: ").concat(n.join(", "))}:e.id?"string"!=typeof e.id?{v:"".concat(v.PAYMENT_STATUS_UPDATED," event requires id in eventData.products item to be a string")}:e.quantity&&"number"!=typeof e.quantity?{v:"".concat(v.PAYMENT_STATUS_UPDATED," event requires quantity in eventData.products item to be a number")}:void 0:{v:"".concat(v.PAYMENT_STATUS_UPDATED," event requires id in eventData.products item to be defined")}},s=e.products[Symbol.iterator]();!(r=(u=s.next()).done);r=!0){var d=c();if("object"===l(d))return d.v}}catch(e){a=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(a)throw i}}}return e.amount&&"number"!=typeof e.amount?"".concat(v.PAYMENT_STATUS_UPDATED," event requires amount in eventData to be a number"):e.currency&&"string"!=typeof e.currency?"".concat(v.PAYMENT_STATUS_UPDATED," event requires currency in eventData to be a string"):!e.promoCodes||Array.isArray(e.promoCodes)&&e.promoCodes.every(function(e){return"string"==typeof e})?null:"".concat(v.PAYMENT_STATUS_UPDATED," event requires promoCodes in eventData to be an array of strings")}},{key:"_validateErrorOccurredEvent",value:function(e){if(!e)return"".concat(v.ERROR_OCCURRED," event requires eventData");if("object"!==l(e)||Array.isArray(e))return"".concat(v.ERROR_OCCURRED," event requires eventData to be an object");var t=["errorCode","errorMessage","errorSeverity"],n=Object.keys(e).filter(function(e){return!t.includes(e)});return 0<n.length?"".concat(v.ERROR_OCCURRED," event does not allow additional fields in eventData: ").concat(n.join(", ")):e.errorCode?"string"!=typeof e.errorCode?"".concat(v.ERROR_OCCURRED," event requires errorCode in eventData to be a string"):e.errorMessage&&"string"!=typeof e.errorMessage?"".concat(v.ERROR_OCCURRED," event requires errorMessage in eventData to be a string"):e.errorSeverity&&!Object.values(d).includes(e.errorSeverity)?"".concat(v.ERROR_OCCURRED," event requires errorSeverity in eventData to be one of: ").concat(Object.values(d).join(", ")):null:"".concat(v.ERROR_OCCURRED," event requires errorCode in eventData to be defined")}},{key:"_validateCustomEvent",value:function(e){if(!e)return"".concat(v.CUSTOM," event requires eventData");if("object"!==l(e)||Array.isArray(e))return"".concat(v.CUSTOM," event requires eventData to be an object");var t=["customEventName","customEventData"],n=Object.keys(e).filter(function(e){return!t.includes(e)});return 0<n.length?"".concat(v.CUSTOM," event does not allow additional fields in eventData: ").concat(n.join(", ")):e.customEventName?"string"!=typeof e.customEventName?"".concat(v.CUSTOM," event requires customEventName in eventData to be a string"):null:"".concat(v.CUSTOM," event requires customEventName in eventData to be defined")}}]),e}(),y=function(){function e(){t(this,e),u.wrapModule(window,"LocaleModule")}return n(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),w=function(){function e(){t(this,e),u.wrapModule(window,"LocationModule")}return n(e,[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}}]),e}(),T=function(){function e(){t(this,e),u.wrapModule(window,"MediaModule")}return n(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),b=require("@grabjs/mobile-kit-bridge-sdk"),S=function(){function e(){t(this,e),b.wrapModule(window,"PlatformModule")}return n(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),M=function(){function e(){t(this,e),u.wrapModule(window,"ScopeModule")}return n(e,[{key:"hasAccessTo",value:function(e,t){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:t})}},{key:"reloadScopes",value:function(){return window.WrappedScopeModule.invoke("reloadScopes")}}]),e}(),m=require("@grabjs/mobile-kit-bridge-sdk"),E=function(){function e(){t(this,e),m.wrapModule(window,"StorageModule")}return n(e,[{key:"setBoolean",value:function(e,t){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:t})}},{key:"getBoolean",value:function(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}},{key:"setInt",value:function(e,t){return window.WrappedStorageModule.invoke("setInt",{key:e,value:t})}},{key:"getInt",value:function(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}},{key:"setString",value:function(e,t){return window.WrappedStorageModule.invoke("setString",{key:e,value:t})}},{key:"getString",value:function(e){return window.WrappedStorageModule.invoke("getString",{key:e})}},{key:"setDouble",value:function(e,t){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:t})}},{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}(),k=function(){function e(){t(this,e),u.wrapModule(window,"SystemWebViewKitModule")}return n(e,[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]),e}();e.CheckoutModule=c,e.ContainerModule=p,e.LocaleModule=y,e.LocationModule=w,e.MediaModule=T,e.PlatformModule=S,e.ScopeModule=M,e.StorageModule=E,e.SystemWebViewKitModule=k,Object.defineProperty(e,"__esModule",{value:!0})});
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,i,a=(function(e,n){function a(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 l(r,e){var u=e.callbackNameFunc,i=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(a(e,"status_code"))if(a(e.result,"event"))switch(e.result.event){case d.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else o&&o.next&&o.next(e)},i(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 d;((d=n).StreamEvent||(d.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",d.wrapModule=function(u,i){u[function(e){return"Wrapped"+e}(i)]=function(e,t,n){var r={};return{invoke:function(n,o){return function(e,n){return n.funcNameToWrap,l(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[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:t,parameters:null!=o?o:{}})}})}}}(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(){o(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(){o(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(){o(this,e),l.wrapModule(window,"LocaleModule")}return r(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){o(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(){o(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(){o(this,e),v.wrapModule(window,"PlatformModule")}return r(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),y=function(){function e(){o(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}(),b=require("@grabjs/mobile-kit-bridge-sdk"),M=function(){function e(){o(this,e),b.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(){o(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.ContainerModule=f,e.LocaleModule=s,e.LocationModule=p,e.MediaModule=w,e.PlatformModule=k,e.ScopeModule=y,e.StorageModule=M,e.SystemWebViewKitModule=g,Object.defineProperty(e,"__esModule",{value:!0})});
@@ -235,165 +235,124 @@ containerModule.onContentLoaded().then(({ result, error }) => {
235
235
  });
236
236
  ```
237
237
 
238
- ### 9. Send analytics event
238
+ ### 9. Open link in external browser
239
239
 
240
- **Method name**: `sendAnalyticsEvent`
240
+ **Method name**: `openExternalLink`
241
+ Call this method to tell client to open the link in external browser
241
242
 
242
243
  **Arguments**
243
244
 
244
- An object, containing the following properties:
245
+ | Name | Type | Required | Description |
246
+ | ---- | ------ | -------- | ----------- |
247
+ | url | String | Yes | URL to open |
245
248
 
246
- | Name | Type | Required | Description |
247
- | ----------- | ------ | -------- | -------------------------------------------------------------- |
248
- | `url` | String | No | The URL associated with the event |
249
- | `sessionId` | String | No | A unique identifier for the user's session |
250
- | `viewName` | String | No | The name of the page or screen displayed when the event occurs |
251
- | `eventName` | String | Yes | Name of the event |
252
- | `eventData` | Any | No | The event data (can be any type) |
249
+ **Return type**
253
250
 
254
- **Events**
251
+ `None`
255
252
 
256
- The following events are available:
253
+ **Code example**
257
254
 
258
- - `STARTED`
255
+ ```javascript
256
+ import { ContainerModule } from "@grabjs/superapp-sdk";
259
257
 
260
- - **Description**: Triggered when the MiniApp is initialized.
261
- - **Requirements for eventData**:
262
- - Must be empty
258
+ // Ideally, initialize this only one and reuse across app.
259
+ const containerModule = new ContainerModule();
263
260
 
264
- - `PAYMENT_STATUS_UPDATED`
261
+ containerModule.openExternalLink("https://grab.com").then(({ result, error }) => {
262
+ if (result) {
263
+ // There is a valid result.
264
+ } else if (error) {
265
+ // Some error happened.
266
+ }
267
+ });
268
+ ```
269
+
270
+ ### 10. Send analytics event
265
271
 
266
- - **Description**: Triggered when a payment status is updated.
267
- - **Requirements for eventData**:
268
- - `transactionId` (String, optional): The transaction identifier provided by the GrabPay SDK
269
- - `statusCode` (String, required): The status of the payment. Must be one of: 'SUCCESS', 'FAILURE', 'CANCEL', 'PROCESSING' (case-sensitive)
270
- - `statusMessage` (String, optional): A message describing the status update
271
- - `products` (Array of objects, optional): The products that are being purchased
272
- - Each product must have:
273
- - `id` (String, required): The product's unique identifier
274
- - `quantity` (Number, optional): The quantity of the product
275
- - `amount` (Number, optional): The total amount of the transaction
276
- - `currency` (String, optional): The currency used for the transaction
277
- - `promoCodes` (Array of string, optional): Any promo codes applied to this transaction
272
+ **Method name**: `sendAnalyticsEvent`
278
273
 
279
- - `ERROR_OCCURRED`
274
+ **Arguments**
280
275
 
281
- - **Description**: Triggered when an error occurs within the MiniApp.
282
- - **Requirements for eventData**:
283
- - `errorCode` (String, required): A code or type identifying the error
284
- - `errorMessage` (String, optional): A message describing the error
285
- - `errorSeverity` (String, optional): The severity level of the error. Must be one of: 'WARNING', 'ERROR', 'CRITICAL' (case-sensitive)
276
+ | Name | Type | Required | Description |
277
+ | ------------ | ------ | -------- | ------------------------------------------------------- |
278
+ | eventDetails | Object | Yes | Event details containing state, name, and data |
286
279
 
287
- - `CUSTOM`
288
- - **Description**: Triggered when a custom event should be tracked within the MiniApp.
289
- - **Requirements for eventData**:
290
- - `customEventName` (String, required): The name of the custom event
291
- - `customEventData` (Any, optional): An object containing the custom event data
280
+ **EventDetails Object Properties**
292
281
 
293
- **Return type**
282
+ | Property | Type | Required | Description |
283
+ | -------- | ------ | -------- | ----------------------------------------------------------------- |
284
+ | state | String | Yes | State of the event (cf. Predefined AnalyticsEventState) |
285
+ | name | String | Yes | Name of the event (cf. Predefined AnalyticsEventName) |
286
+ | data | Object | No | Additional data for the event (cf. Predefined AnalyticsEventData) |
294
287
 
295
- `None`
288
+ **Predefined AnalyticsEventState**
289
+
290
+ - 'HOMEPAGE'
291
+ - 'CHECKOUT_PAGE'
292
+ - 'BOOKING_COMPLETION'
293
+ - 'CUSTOM'
296
294
 
297
- **Validation**
295
+ **Predefined AnalyticsEventName**
298
296
 
299
- The SDK performs strict validation on all events:
297
+ - 'DEFAULT'
300
298
 
301
- - All required fields must be present
302
- - Field types must match their specifications exactly
303
- - No additional fields are allowed beyond those specified
304
- - Validation errors will be returned in the `error` field of the response
299
+ **Predefined AnalyticsEventData**
300
+
301
+ - 'TRANSACTION_AMOUNT': 'transaction_amount'
302
+ - 'TRANSACTION_CURRENCY': 'transaction_currency'
303
+ - 'PAGE': 'page'
304
+
305
+ **Return type**
306
+
307
+ `None`
305
308
 
306
309
  **Code example**
307
310
 
308
311
  ```javascript
309
- import {
310
- ContainerModule,
311
- AnalyticsEventName,
312
- PaymentStatusCode,
313
- ErrorSeverity,
314
- } from "@grabjs/superapp-sdk";
312
+ import { ContainerModule, AnalyticsEventState, AnalyticsEventName, AnalyticsEventData } from "@grabjs/superapp-sdk";
315
313
 
316
- // Ideally, initialize this only one and reuse across app.
317
314
  const containerModule = new ContainerModule();
318
315
 
319
- // Example for STARTED event
320
- containerModule
321
- .sendAnalyticsEvent({
322
- url: "https://www.grab.com/sg/",
323
- sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
324
- viewName: "Home",
325
- eventName: AnalyticsEventName.STARTED,
326
- eventData: null,
327
- })
328
- .then(({ result, error }) => {
329
- if (error) {
330
- // Some error happened.
331
- }
332
- });
333
-
334
- // Example for PAYMENT_STATUS_UPDATED event
335
- containerModule
336
- .sendAnalyticsEvent({
337
- url: "https://www.grab.com/sg/",
338
- sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
339
- viewName: "Payment",
340
- eventName: AnalyticsEventName.PAYMENT_STATUS_UPDATED,
341
- eventData: {
342
- transactionId: "txn_123456",
343
- statusCode: PaymentStatusCode.SUCCESS,
344
- statusMessage: "Payment completed successfully",
345
- products: [
346
- { id: "product_1", quantity: 2 },
347
- { id: "product_2", quantity: 1 },
348
- ],
349
- amount: 100.5,
350
- currency: "SGD",
351
- promoCodes: ["10%OFF"],
352
- },
353
- })
354
- .then(({ result, error }) => {
355
- if (error) {
356
- // Some error happened.
357
- }
358
- });
359
-
360
- // Example for ERROR_OCCURRED event
361
- containerModule
362
- .sendAnalyticsEvent({
363
- url: "https://www.grab.com/sg/",
364
- sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
365
- viewName: "Payment",
366
- eventName: AnalyticsEventName.ERROR_OCCURRED,
367
- eventData: {
368
- errorCode: "PAYMENT_FAILED",
369
- errorMessage: "Failed to process payment due to insufficient funds",
370
- errorSeverity: ErrorSeverity.ERROR,
371
- },
372
- })
373
- .then(({ result, error }) => {
374
- if (error) {
375
- // Some error happened.
376
- }
377
- });
378
-
379
- // Example for CUSTOM event
380
- containerModule
381
- .sendAnalyticsEvent({
382
- url: "https://www.grab.com/sg/",
383
- sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
384
- viewName: "Home",
385
- eventName: AnalyticsEventName.CUSTOM,
386
- eventData: {
387
- customEventName: "USER_ACTION",
388
- customEventData: {
389
- action: "button_click",
390
- buttonId: "submit_order",
391
- },
392
- },
393
- })
394
- .then(({ result, error }) => {
395
- if (error) {
396
- // Some error happened.
397
- }
398
- });
316
+ // Example: Send a DEFAULT event for HOMEPAGE state
317
+ containerModule.sendAnalyticsEvent({
318
+ state: AnalyticsEventState.HOMEPAGE,
319
+ name: AnalyticsEventName.DEFAULT,
320
+ }).then(({ result, error }) => {
321
+ if (error) {
322
+ // Handle validation or other errors
323
+ }
324
+ });
325
+
326
+ // Example: Send a BOOK event for CHECKOUT_PAGE state
327
+ containerModule.sendAnalyticsEvent({
328
+ state: AnalyticsEventState.CHECKOUT_PAGE,
329
+ name: 'BOOK',
330
+ data: {
331
+ [AnalyticsEventData.TRANSACTION_AMOUNT]: 100,
332
+ [AnalyticsEventData.TRANSACTION_CURRENCY]: "SGD"
333
+ }
334
+ }).then(({ result, error }) => {
335
+ if (error) {
336
+ // Handle validation or other errors
337
+ }
338
+ });
339
+
340
+ // Example: Send a CLICK_RIDE event for CUSTOM state
341
+ containerModule.sendAnalyticsEvent({
342
+ state: AnalyticsEventState.CUSTOM,
343
+ name: 'CLICK_RIDE',
344
+ data: {
345
+ [AnalyticsEventData.PAGE]: "LIST_RIDES",
346
+ departure_time: "2025-06-01 08:00:00",
347
+ arrival_time: "2025-06-01 10:30:00",
348
+ departure_address: "6 Bayfront Ave, Singapore 018974",
349
+ arrival_address: "Petronas Twin Tower, Kuala Lumpur City Centre, 50088 Kuala Lumpur, Malaysia",
350
+ }
351
+
352
+ }).then(({ result, error }) => {
353
+ if (error) {
354
+ // Handle validation or other errors
355
+ }
356
+ });
399
357
  ```
358
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grabjs/superapp-sdk",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
4
4
  "description": "SDK for Grab SuperApp WebView.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {