@grabjs/superapp-sdk 1.7.4 → 1.7.7

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,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,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 o(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 r,u,i=(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 d(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 l.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 l;((l=n).StreamEvent||(l.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",l.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,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[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(l,"__esModule",{value:!0})}(r={exports:{}},r.exports),r.exports),a=(u=i)&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u,d=function(){function e(){n(this,e),a.wrapModule(window,"CheckoutModule")}return o(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),l=require("@grabjs/mobile-kit-bridge-sdk"),c=function(){function e(){n(this,e),l.wrapModule(window,"ContainerModule")}return o(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:"hideLoader",value:function(){return window.WrappedContainerModule.invoke("hideLoader")}},{key:"close",value:function(){return window.WrappedContainerModule.invoke("close")}}]),e}(),f=function(){function e(){n(this,e),a.wrapModule(window,"LocaleModule")}return o(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),s=function(){function e(){n(this,e),a.wrapModule(window,"LocationModule")}return o(e,[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}}]),e}(),p=function(){function e(){n(this,e),a.wrapModule(window,"MediaModule")}return o(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),w=require("@grabjs/mobile-kit-bridge-sdk"),k=function(){function e(){n(this,e),w.wrapModule(window,"PlatformModule")}return o(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),v=function(){function e(){n(this,e),a.wrapModule(window,"ScopeModule")}return o(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=require("@grabjs/mobile-kit-bridge-sdk"),M=function(){function e(){n(this,e),y.wrapModule(window,"StorageModule")}return o(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}(),b=function(){function e(){n(this,e),a.wrapModule(window,"SystemWebViewKitModule")}return o(e,[{key:"redirectToSystemWebView",value:function(e){var n=e.parameters,o=JSON.stringify({method:"redirectToSystemWebView",parameters:n});return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",o)}}]),e}();e.CheckoutModule=d,e.ContainerModule=c,e.LocaleModule=f,e.LocationModule=s,e.MediaModule=p,e.PlatformModule=k,e.ScopeModule=v,e.StorageModule=M,e.SystemWebViewKitModule=b,Object.defineProperty(e,"__esModule",{value:!0})});
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})});
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Description
4
4
 
5
- Provides APIs to interract with the webview container.
5
+ Provides APIs to interact with the webview container.
6
6
 
7
7
  ## Methods
8
8
 
@@ -12,9 +12,9 @@ Provides APIs to interract with the webview container.
12
12
 
13
13
  **Arguments**
14
14
 
15
- | Name | Type | Description |
16
- | --------------- | ------ | ----------------------- |
17
- | backgroundColor | String | Hexadecimal color value |
15
+ | Name | Type | Required | Description |
16
+ | --------------- | ------ | -------- | ----------------------- |
17
+ | backgroundColor | String | Yes | Hexadecimal color value |
18
18
 
19
19
  **Return type**
20
20
 
@@ -28,15 +28,11 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
28
28
  // Ideally, initialize this only one and reuse across app.
29
29
  const containerModule = new ContainerModule();
30
30
 
31
- containerModule
32
- .setBackgroundColor("#ffffff")
33
- .then(({ result, error }) => {
34
- if (result) {
35
- // There is a valid result.
36
- } else if (error) {
37
- // Some error happened.
38
- }
39
- });
31
+ containerModule.setBackgroundColor("#ffffff").then(({ result, error }) => {
32
+ if (error) {
33
+ // Some error happened.
34
+ }
35
+ });
40
36
  ```
41
37
 
42
38
  ### 2. Set title
@@ -45,9 +41,9 @@ containerModule
45
41
 
46
42
  **Arguments**
47
43
 
48
- | Name | Type | Description |
49
- | ----- | ------ | ----------------- |
50
- | title | String | Title of the page |
44
+ | Name | Type | Required | Description |
45
+ | ----- | ------ | -------- | ----------------- |
46
+ | title | String | Yes | Title of the page |
51
47
 
52
48
  **Return type**
53
49
 
@@ -62,9 +58,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
62
58
  const containerModule = new ContainerModule();
63
59
 
64
60
  containerModule.setTitle("Home").then(({ result, error }) => {
65
- if (result) {
66
- // There is a valid result.
67
- } else if (error) {
61
+ if (error) {
68
62
  // Some error happened.
69
63
  }
70
64
  });
@@ -91,9 +85,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
91
85
  const containerModule = new ContainerModule();
92
86
 
93
87
  containerModule.hideBackButton().then(({ result, error }) => {
94
- if (result) {
95
- // There is a valid result.
96
- } else if (error) {
88
+ if (error) {
97
89
  // Some error happened.
98
90
  }
99
91
  });
@@ -120,9 +112,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
120
112
  const containerModule = new ContainerModule();
121
113
 
122
114
  containerModule.showBackButton().then(({ result, error }) => {
123
- if (result) {
124
- // There is a valid result.
125
- } else if (error) {
115
+ if (error) {
126
116
  // Some error happened.
127
117
  }
128
118
  });
@@ -186,9 +176,9 @@ containerModule.showRefreshButton().then(({ result, error }) => {
186
176
  });
187
177
  ```
188
178
 
189
- ### 7. Hide loader
179
+ ### 7. Close
190
180
 
191
- **Method name**: `hideLoader`
181
+ **Method name**: `close`
192
182
 
193
183
  **Arguments**
194
184
 
@@ -206,7 +196,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
206
196
  // Ideally, initialize this only one and reuse across app.
207
197
  const containerModule = new ContainerModule();
208
198
 
209
- containerModule.hideLoader().then(({ result, error }) => {
199
+ containerModule.close().then(({ result, error }) => {
210
200
  if (result) {
211
201
  // There is a valid result.
212
202
  } else if (error) {
@@ -215,9 +205,10 @@ containerModule.hideLoader().then(({ result, error }) => {
215
205
  });
216
206
  ```
217
207
 
218
- ### 8. Close
208
+ ### 8. On content loaded
219
209
 
220
- **Method name**: `close`
210
+ **Method name**: `onContentLoaded`
211
+ Call this method to notify the client that page content loaded
221
212
 
222
213
  **Arguments**
223
214
 
@@ -235,7 +226,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
235
226
  // Ideally, initialize this only one and reuse across app.
236
227
  const containerModule = new ContainerModule();
237
228
 
238
- containerModule.close().then(({ result, error }) => {
229
+ containerModule.onContentLoaded().then(({ result, error }) => {
239
230
  if (result) {
240
231
  // There is a valid result.
241
232
  } else if (error) {
@@ -243,3 +234,166 @@ containerModule.close().then(({ result, error }) => {
243
234
  }
244
235
  });
245
236
  ```
237
+
238
+ ### 9. Send analytics event
239
+
240
+ **Method name**: `sendAnalyticsEvent`
241
+
242
+ **Arguments**
243
+
244
+ An object, containing the following properties:
245
+
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) |
253
+
254
+ **Events**
255
+
256
+ The following events are available:
257
+
258
+ - `STARTED`
259
+
260
+ - **Description**: Triggered when the MiniApp is initialized.
261
+ - **Requirements for eventData**:
262
+ - Must be empty
263
+
264
+ - `PAYMENT_STATUS_UPDATED`
265
+
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
278
+
279
+ - `ERROR_OCCURRED`
280
+
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)
286
+
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
292
+
293
+ **Return type**
294
+
295
+ `None`
296
+
297
+ **Validation**
298
+
299
+ The SDK performs strict validation on all events:
300
+
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
305
+
306
+ **Code example**
307
+
308
+ ```javascript
309
+ import {
310
+ ContainerModule,
311
+ AnalyticsEventName,
312
+ PaymentStatusCode,
313
+ ErrorSeverity,
314
+ } from "@grabjs/superapp-sdk";
315
+
316
+ // Ideally, initialize this only one and reuse across app.
317
+ const containerModule = new ContainerModule();
318
+
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
+ });
399
+ ```
@@ -30,9 +30,8 @@ import { SystemWebViewKitModule } from '@grab/superapp-sdk';
30
30
  const systemWebViewKitModule = new SystemWebViewKitModule();
31
31
 
32
32
  // open the system webview
33
- systemWebViewKitModule.redirectToSystemWebView({
34
- parameters: { url: 'https://example.com' }
35
- }).then({ result, error }) => {
33
+ systemWebViewKitModule.redirectToSystemWebView({ url: 'http://wwww.example.com' })
34
+ .then({ result, error }) => {
36
35
  if (!!result) {
37
36
  // There is a valid result.
38
37
  } else if (!!error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grabjs/superapp-sdk",
3
- "version": "1.7.4",
3
+ "version": "1.7.7",
4
4
  "description": "SDK for Grab SuperApp WebView.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {