@grabjs/superapp-sdk 1.7.3 → 1.7.6

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}(),p=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}(),s=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;return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",{parameters:n})}}]),e}();e.CheckoutModule=d,e.ContainerModule=c,e.LocaleModule=f,e.LocationModule=p,e.MediaModule=s,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 r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var o,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 r=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return t.every(function(e){return 0<=r.indexOf(e)})}function c(o,e){var a=e.callbackNameFunc,i=e.funcToWrap;return function(e){return{subscribe:e,then:function(r,o){return new Promise(function(){try{var t=null,n=!1;t=e({next:function(e){r&&r(e),t&&t.unsubscribe(),n=!0}}),n&&t&&t.unsubscribe()}catch(e){o&&o(e)}})}}}(function(n){var t,r=a();return o[r]=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(r),t=function(e){var t=!1;return{isUnsubscribed:function(){return t},unsubscribe:function(){t||(delete o[r],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,r,t){var o={};return{invoke:function(t,n){return function(e,t){return t.funcNameToWrap,c(e,function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&(n[r[o]]=e[r[o]])}return n}(t,["funcNameToWrap"]))}(e,{funcNameToWrap:t,callbackNameFunc:function(){var e=o[t]||0;return o[t]=e+1,function(e){var t=e.moduleName,n=e.funcName,r=e.requestID;return t+"_"+n+"Callback"+(null!==r?"_"+r:"")}({moduleName:r,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:r,parameters:null!=n?n:{}})}})}}}(a,i)},Object.defineProperty(s,"__esModule",{value:!0})}(o={exports:{}},o.exports),o.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:"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 r=n[t];if(!e[r])return"Missing required field: ".concat(r)}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 o=Object.values(v);if(!o.includes(e.eventName))return"Invalid eventName. Must be one of: ".concat(o.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 r=Object.values(f);if(!r.includes(e.statusCode))return"".concat(v.PAYMENT_STATUS_UPDATED," event requires statusCode in eventData to be one of: ").concat(r.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 o=!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]();!(o=(u=s.next()).done);o=!0){var d=c();if("object"===l(d))return d.v}}catch(e){a=!0,i=e}finally{try{o||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}(),g=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=g,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,31 +205,165 @@ containerModule.hideLoader().then(({ result, error }) => {
215
205
  });
216
206
  ```
217
207
 
218
- ### 8. Close
208
+ ### 8. Send analytics event
219
209
 
220
- **Method name**: `close`
210
+ **Method name**: `sendAnalyticsEvent`
221
211
 
222
212
  **Arguments**
223
213
 
224
- `None`
214
+ An object, containing the following properties:
215
+
216
+ | Name | Type | Required | Description |
217
+ | ----------- | ------ | -------- | -------------------------------------------------------------- |
218
+ | `url` | String | No | The URL associated with the event |
219
+ | `sessionId` | String | No | A unique identifier for the user's session |
220
+ | `viewName` | String | No | The name of the page or screen displayed when the event occurs |
221
+ | `eventName` | String | Yes | Name of the event |
222
+ | `eventData` | Any | No | The event data (can be any type) |
223
+
224
+ **Events**
225
+
226
+ The following events are available:
227
+
228
+ - `STARTED`
229
+
230
+ - **Description**: Triggered when the MiniApp is initialized.
231
+ - **Requirements for eventData**:
232
+ - Must be empty
233
+
234
+ - `PAYMENT_STATUS_UPDATED`
235
+
236
+ - **Description**: Triggered when a payment status is updated.
237
+ - **Requirements for eventData**:
238
+ - `transactionId` (String, optional): The transaction identifier provided by the GrabPay SDK
239
+ - `statusCode` (String, required): The status of the payment. Must be one of: 'SUCCESS', 'FAILURE', 'CANCEL', 'PROCESSING' (case-sensitive)
240
+ - `statusMessage` (String, optional): A message describing the status update
241
+ - `products` (Array of objects, optional): The products that are being purchased
242
+ - Each product must have:
243
+ - `id` (String, required): The product's unique identifier
244
+ - `quantity` (Number, optional): The quantity of the product
245
+ - `amount` (Number, optional): The total amount of the transaction
246
+ - `currency` (String, optional): The currency used for the transaction
247
+ - `promoCodes` (Array of string, optional): Any promo codes applied to this transaction
248
+
249
+ - `ERROR_OCCURRED`
250
+
251
+ - **Description**: Triggered when an error occurs within the MiniApp.
252
+ - **Requirements for eventData**:
253
+ - `errorCode` (String, required): A code or type identifying the error
254
+ - `errorMessage` (String, optional): A message describing the error
255
+ - `errorSeverity` (String, optional): The severity level of the error. Must be one of: 'WARNING', 'ERROR', 'CRITICAL' (case-sensitive)
256
+
257
+ - `CUSTOM`
258
+ - **Description**: Triggered when a custom event should be tracked within the MiniApp.
259
+ - **Requirements for eventData**:
260
+ - `customEventName` (String, required): The name of the custom event
261
+ - `customEventData` (Any, optional): An object containing the custom event data
225
262
 
226
263
  **Return type**
227
264
 
228
265
  `None`
229
266
 
267
+ **Validation**
268
+
269
+ The SDK performs strict validation on all events:
270
+
271
+ - All required fields must be present
272
+ - Field types must match their specifications exactly
273
+ - No additional fields are allowed beyond those specified
274
+ - Validation errors will be returned in the `error` field of the response
275
+
230
276
  **Code example**
231
277
 
232
278
  ```javascript
233
- import { ContainerModule } from "@grabjs/superapp-sdk";
279
+ import {
280
+ ContainerModule,
281
+ AnalyticsEventName,
282
+ PaymentStatusCode,
283
+ ErrorSeverity,
284
+ } from "@grabjs/superapp-sdk";
234
285
 
235
286
  // Ideally, initialize this only one and reuse across app.
236
287
  const containerModule = new ContainerModule();
237
288
 
238
- containerModule.close().then(({ result, error }) => {
239
- if (result) {
240
- // There is a valid result.
241
- } else if (error) {
242
- // Some error happened.
243
- }
244
- });
289
+ // Example for STARTED event
290
+ containerModule
291
+ .sendAnalyticsEvent({
292
+ url: "https://www.grab.com/sg/",
293
+ sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
294
+ viewName: "Home",
295
+ eventName: AnalyticsEventName.STARTED,
296
+ eventData: null,
297
+ })
298
+ .then(({ result, error }) => {
299
+ if (error) {
300
+ // Some error happened.
301
+ }
302
+ });
303
+
304
+ // Example for PAYMENT_STATUS_UPDATED event
305
+ containerModule
306
+ .sendAnalyticsEvent({
307
+ url: "https://www.grab.com/sg/",
308
+ sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
309
+ viewName: "Payment",
310
+ eventName: AnalyticsEventName.PAYMENT_STATUS_UPDATED,
311
+ eventData: {
312
+ transactionId: "txn_123456",
313
+ statusCode: PaymentStatusCode.SUCCESS,
314
+ statusMessage: "Payment completed successfully",
315
+ products: [
316
+ { id: "product_1", quantity: 2 },
317
+ { id: "product_2", quantity: 1 },
318
+ ],
319
+ amount: 100.5,
320
+ currency: "SGD",
321
+ promoCodes: ["10%OFF"],
322
+ },
323
+ })
324
+ .then(({ result, error }) => {
325
+ if (error) {
326
+ // Some error happened.
327
+ }
328
+ });
329
+
330
+ // Example for ERROR_OCCURRED event
331
+ containerModule
332
+ .sendAnalyticsEvent({
333
+ url: "https://www.grab.com/sg/",
334
+ sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
335
+ viewName: "Payment",
336
+ eventName: AnalyticsEventName.ERROR_OCCURRED,
337
+ eventData: {
338
+ errorCode: "PAYMENT_FAILED",
339
+ errorMessage: "Failed to process payment due to insufficient funds",
340
+ errorSeverity: ErrorSeverity.ERROR,
341
+ },
342
+ })
343
+ .then(({ result, error }) => {
344
+ if (error) {
345
+ // Some error happened.
346
+ }
347
+ });
348
+
349
+ // Example for CUSTOM event
350
+ containerModule
351
+ .sendAnalyticsEvent({
352
+ url: "https://www.grab.com/sg/",
353
+ sessionId: "e48553f4-625a-431d-adae-56d7801c083c",
354
+ viewName: "Home",
355
+ eventName: AnalyticsEventName.CUSTOM,
356
+ eventData: {
357
+ customEventName: "USER_ACTION",
358
+ customEventData: {
359
+ action: "button_click",
360
+ buttonId: "submit_order",
361
+ },
362
+ },
363
+ })
364
+ .then(({ result, error }) => {
365
+ if (error) {
366
+ // Some error happened.
367
+ }
368
+ });
245
369
  ```
@@ -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.3",
3
+ "version": "1.7.6",
4
4
  "description": "SDK for Grab SuperApp WebView.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {