@grabjs/superapp-sdk 1.7.24 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/docs/IdentityModule.md +73 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function 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,a,i=(function(e,n){function i(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,a=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(i(e,"status_code"))if(i(e.result,"event"))switch(e.result.event){case l.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else o&&o.next&&o.next(e)},a(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,a){u[function(e){return"Wrapped"+e}(a)]=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[a])u[a][e.method](JSON.stringify(e));else{if(!(u.webkit&&u.webkit.messageHandlers&&u.webkit.messageHandlers[a]))throw new Error("Unexpected method '"+e.method+"' for module '"+a+"'");u.webkit.messageHandlers[a].postMessage(e)}}({callback:e,method:n,module:t,parameters:null!=o?o:{}})}})}}}(u,a)},Object.defineProperty(l,"__esModule",{value:!0})}(u={exports:{}},u.exports),u.exports),d=(a=i)&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,l=function(){function e(){o(this,e),d.wrapModule(window,"CameraModule")}return r(e,[{key:"scanQRCode",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return window.WrappedCameraModule.invoke("scanQRCode",e)}}]),e}(),c=function(){function e(){o(this,e),d.wrapModule(window,"CheckoutModule")}return r(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),f=function(){function e(){o(this,e),d.wrapModule(window,"ContainerModule")}return r(e,[{key:"setBackgroundColor",value:function(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}},{key:"setTitle",value:function(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}},{key:"hideBackButton",value:function(){return window.WrappedContainerModule.invoke("hideBackButton")}},{key:"showBackButton",value:function(){return window.WrappedContainerModule.invoke("showBackButton")}},{key:"hideRefreshButton",value:function(){return window.WrappedContainerModule.invoke("hideRefreshButton")}},{key:"showRefreshButton",value:function(){return window.WrappedContainerModule.invoke("showRefreshButton")}},{key:"close",value:function(){return window.WrappedContainerModule.invoke("close")}},{key:"onContentLoaded",value:function(){return window.WrappedContainerModule.invoke("onContentLoaded")}},{key:"showLoader",value:function(){return window.WrappedContainerModule.invoke("showLoader")}},{key:"hideLoader",value:function(){return window.WrappedContainerModule.invoke("hideLoader")}},{key:"openExternalLink",value:function(e){return window.WrappedContainerModule.invoke("openExternalLink",{url:e})}},{key:"onCtaTap",value:function(e){return window.WrappedContainerModule.invoke("onCtaTap",{action:e})}},{key:"sendAnalyticsEvent",value:function(e){var n=this._validateAnalyticsEvent(e);return n?{then:function(e){return e({status_code:400,error:n})}}:window.WrappedContainerModule.invoke("sendAnalyticsEvent",{state:e.state,name:e.name,data:e.data?JSON.stringify(e.data):null})}},{key:"isConnected",value:function(){var e=window.navigator&&window.navigator.userAgent;if(!e)return{then:function(e){return e({status_code:404,error:"User agent not available"})}};var n=/grab[a-z]*\//i.test(e);return{then:function(e){return e({status_code:n?200:404,error:n?null:"Not connected to Grab app"})}}}},{key:"getSessionParams",value:function(){return window.WrappedContainerModule.invoke("getSessionParams")}},{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),d.wrapModule(window,"LocaleModule")}return r(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){o(this,e),d.wrapModule(window,"LocationModule")}return r(e,[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}},{key:"getCountryCode",value:function(){return window.WrappedLocationModule.invoke("getCountryCode")}}]),e}(),w=function(){function e(){o(this,e),d.wrapModule(window,"MediaModule")}return r(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),v=function(){function e(){o(this,e),d.wrapModule(window,"PlatformModule")}return r(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),k=function(){function e(){o(this,e),d.wrapModule(window,"ScopeModule")}return r(e,[{key:"hasAccessTo",value:function(e,n){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:n})}},{key:"reloadScopes",value:function(){return window.WrappedScopeModule.invoke("reloadScopes")}}]),e}(),y=function(){function e(){o(this,e),d.wrapModule(window,"StorageModule")}return r(e,[{key:"setBoolean",value:function(e,n){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:n})}},{key:"getBoolean",value:function(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}},{key:"setInt",value:function(e,n){return window.WrappedStorageModule.invoke("setInt",{key:e,value:n})}},{key:"getInt",value:function(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}},{key:"setString",value:function(e,n){return window.WrappedStorageModule.invoke("setString",{key:e,value:n})}},{key:"getString",value:function(e){return window.WrappedStorageModule.invoke("getString",{key:e})}},{key:"setDouble",value:function(e,n){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:n})}},{key:"getDouble",value:function(e){return window.WrappedStorageModule.invoke("getDouble",{key:e})}},{key:"remove",value:function(e){return window.WrappedStorageModule.invoke("remove",{key:e})}},{key:"removeAll",value:function(){return window.WrappedStorageModule.invoke("removeAll")}}]),e}(),M=function(){function e(){o(this,e),d.wrapModule(window,"SystemWebViewKitModule")}return r(e,[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]),e}();e.CameraModule=l,e.CheckoutModule=c,e.ContainerAnalyticsEventData={TRANSACTION_AMOUNT:"transaction_amount",TRANSACTION_CURRENCY:"transaction_currency",PAGE:"page"},e.ContainerAnalyticsEventName={DEFAULT:"DEFAULT"},e.ContainerAnalyticsEventState={HOMEPAGE:"HOMEPAGE",CHECKOUT_PAGE:"CHECKOUT_PAGE",BOOKING_COMPLETION:"BOOKING_COMPLETION",CUSTOM:"CUSTOM"},e.ContainerModule=f,e.LocaleModule=s,e.LocationModule=p,e.MediaModule=w,e.PlatformModule=v,e.ScopeModule=k,e.StorageModule=y,e.SystemWebViewKitModule=M,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
((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){function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return n(e)}u.done?t(c):Promise.resolve(c).then(r,o)}function n(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 r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,u(r.key),r)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function t(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function s(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?t(Object(o),!0).forEach(function(e){var t,n;t=r,n=o[e=e],(e=u(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function d(){var h,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",n=e.toStringTag||"@@toStringTag";function r(e,t,n,r){var o,i,a,u,c,l,s,d,f,t=t&&t.prototype instanceof v?t:v,t=Object.create(t.prototype);return g(t,"_invoke",(o=e,i=n,s=r||[],d=!1,f={p:l=0,n:0,v:h,a:p,f:p.bind(h,4),d:function(e,t){return a=e,u=0,c=h,f.n=t,y}},function(e,t,n){if(1<l)throw TypeError("Generator is already running");for(d&&1===t&&p(t,n),u=t,c=n;(w=u<2?h:c)||!d;){a||(u?u<3?(1<u&&(f.n=-1),p(u,c)):f.n=c:f.v=c);try{if(l=2,a){if(w=a[e=u?e:"next"]){if(!(w=w.call(a,c)))throw TypeError("iterator result is not an object");if(!w.done)return w;c=w.value,u<2&&(u=0)}else 1===u&&(w=a.return)&&w.call(a),u<2&&(c=TypeError("The iterator does not provide a '"+e+"' method"),u=1);a=h}else if((w=(d=f.n<0)?c:o.call(i,f))!==y)break}catch(e){a=h,u=1,c=e}finally{l=1}}return{value:w,done:d}}),!0),t;function p(e,t){for(u=e,c=t,w=0;!d&&l&&!n&&w<s.length;w++){var n,r=s[w],o=f.p,i=r[2];3<e?(n=i===t)&&(c=r[(u=r[4])?5:u=3],r[4]=r[5]=h):r[0]<=o&&((n=e<2&&o<r[1])?(u=0,f.v=t,f.n=r[1]):o<i&&(n=e<3||r[0]>t||i<t)&&(r[4]=e,r[5]=t,f.n=i,u=0))}if(n||1<e)return y;throw d=!0,t}}var y={};function v(){}function o(){}function i(){}var w=Object.getPrototypeOf,e=[][t]?w(w([][t]())):(g(w={},t,function(){return this}),w),a=i.prototype=v.prototype=Object.create(e);function u(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,i):(e.__proto__=i,g(e,n,"GeneratorFunction")),e.prototype=Object.create(a),e}return g(a,"constructor",o.prototype=i),g(i,"constructor",o),g(i,n,o.displayName="GeneratorFunction"),g(a),g(a,n,"Generator"),g(a,t,function(){return this}),g(a,"toString",function(){return"[object Generator]"}),(d=function(){return{w:r,m:u}})()}function g(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}(g=function(e,t,n,r){function o(t,n){g(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(o("next",0),o("throw",1),o("return",2))})(e,t,n,r)}function a(e,t){return(e=>{if(Array.isArray(e))return e})(e)||((e,t)=>{var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,u=[],c=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(u.push(r.value),u.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}})(e,t)||((e,t)=>{var n;if(e)return"string"==typeof e?r(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0})(e,t)||(()=>{throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})()}function u(e){e=((e,t)=>{if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);if("object"!=typeof(n=n.call(e,t||"default")))return n;throw new TypeError("@@toPrimitive must return a primitive value.")})(e,"string");return"symbol"==typeof e?e:e+""}function c(e){return(c="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)}var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function f(e,t){return e(t={exports:{}},t.exports),t.exports}var p=f(function(e,t){function f(e){var t=!1;return{isUnsubscribed:function(){return t},unsubscribe:function(){t||(e(),t=!0)}}}function p(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 h(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(e)return e=e,t=Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e))),n.every(function(e){return 0<=t.indexOf(e)})}var y;((y=t).StreamEvent||(y.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",y.createDataStream=p,y.createSubscription=f,y.getModuleEnvironment=function(e,t){return e[t]?"android":e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]?"ios":void 0},y.wrapModule=function(u,c){var l,s,d;u["Wrapped"+c]=(l=u,s=c,d={},{invoke:function(t,n){return e=l,(r={funcNameToWrap:t,callbackNameFunc:function(){var e=d[t]||0;return d[t]=e+1,(e={moduleName:s,requestID:e,funcName:t}).moduleName+"_"+e.funcName+"Callback"+(null!==(e=e.requestID)?"_"+e:"")},funcToWrap:function(e){e={callback:e,method:t,module:s,parameters:null!=n?n:{}};if(u[c])u[c][e.method](JSON.stringify(e));else{if(!(u.webkit&&u.webkit.messageHandlers&&u.webkit.messageHandlers[c]))throw new Error("Unexpected method '"+e.method+"' for module '"+c+"'");u.webkit.messageHandlers[c].postMessage(e)}}}).funcNameToWrap,o=e,e=((e,t)=>{var n={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&(n[o[r]]=e[o[r]]);return n})(r,["funcNameToWrap"]),i=e.callbackNameFunc,a=e.funcToWrap,p(function(t){var n,e=i();return o[e]=function(e){h(e,"status_code")&&(h(e.result,"event")?e.result.event===y.StreamEvent.STREAM_TERMINATED&&n.unsubscribe():t&&t.next&&t.next(e))},a(e),n=f(function(){delete o[e],t&&t.complete&&t.complete()})});var e,r,o,i,a}})},Object.defineProperty(y,"__esModule",{value:!0})}),y=(p=p)&&p.__esModule&&Object.prototype.hasOwnProperty.call(p,"default")?p.default:p,p=(()=>i(function e(){n(this,e),y.wrapModule(window,"CameraModule")},[{key:"scanQRCode",value:function(){return window.WrappedCameraModule.invoke("scanQRCode",0<arguments.length&&void 0!==arguments[0]?arguments[0]:{})}}]))(),v=(()=>i(function e(){n(this,e),y.wrapModule(window,"CheckoutModule")},[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]))(),w=(()=>i(function e(){n(this,e),y.wrapModule(window,"ContainerModule")},[{key:"setBackgroundColor",value:function(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}},{key:"setTitle",value:function(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}},{key:"hideBackButton",value:function(){return window.WrappedContainerModule.invoke("hideBackButton")}},{key:"showBackButton",value:function(){return window.WrappedContainerModule.invoke("showBackButton")}},{key:"hideRefreshButton",value:function(){return window.WrappedContainerModule.invoke("hideRefreshButton")}},{key:"showRefreshButton",value:function(){return window.WrappedContainerModule.invoke("showRefreshButton")}},{key:"close",value:function(){return window.WrappedContainerModule.invoke("close")}},{key:"onContentLoaded",value:function(){return window.WrappedContainerModule.invoke("onContentLoaded")}},{key:"showLoader",value:function(){return window.WrappedContainerModule.invoke("showLoader")}},{key:"hideLoader",value:function(){return window.WrappedContainerModule.invoke("hideLoader")}},{key:"openExternalLink",value:function(e){return window.WrappedContainerModule.invoke("openExternalLink",{url:e})}},{key:"onCtaTap",value:function(e){return window.WrappedContainerModule.invoke("onCtaTap",{action:e})}},{key:"sendAnalyticsEvent",value:function(e){var t=this._validateAnalyticsEvent(e);return t?{then:function(e){return e({status_code:400,error:t})}}:window.WrappedContainerModule.invoke("sendAnalyticsEvent",{state:e.state,name:e.name,data:e.data?JSON.stringify(e.data):null})}},{key:"isConnected",value:function(){var t,e=window.navigator&&window.navigator.userAgent;return e?(t=/grab[a-z]*\//i.test(e),{then:function(e){return e({status_code:t?200:404,error:t?null:"Not connected to Grab app"})}}):{then:function(e){return e({status_code:404,error:"User agent not available"})}}}},{key:"getSessionParams",value:function(){return window.WrappedContainerModule.invoke("getSessionParams")}},{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"!==c(e.data)?"data must be undefined or an object":null}}]))(),m={},b=f(function(e,t){e.exports=(e=(l=>{var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),!(r=!(r=!(r="undefined"!=typeof globalThis&&globalThis.crypto?globalThis.crypto:r)&&"undefined"!=typeof window&&window.msCrypto?window.msCrypto:r)&&void 0!==h&&h.crypto?h.crypto:r))try{r=m}catch(e){}var n=Object.create||function(e){return t.prototype=e,e=new t,t.prototype=null,e};function t(){}var e={},o=e.lib={},i=o.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),(t.init.prototype=t).$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=o.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(var i=0;i<o;i++){var a=n[i>>>2]>>>24-i%4*8&255;t[r+i>>>2]|=a<<24-(r+i)%4*8}else for(var u=0;u<o;u+=4)t[r+u>>>2]=n[u>>>2];return this.sigBytes+=o,this},clamp:function(){var e=this.words,t=this.sigBytes;e[t>>>2]&=4294967295<<32-t%4*8,e.length=l.ceil(t/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],n=0;n<e;n+=4)t.push((()=>{if(r){if("function"==typeof r.getRandomValues)try{return r.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof r.randomBytes)try{return r.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")})());return new s.init(t,e)}}),a=e.enc={},u=a.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var i=t[o>>>2]>>>24-o%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var i=t[o>>>2]>>>24-o%4*8&255;r.push(String.fromCharCode(i))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},d=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=o.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=d.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(e){var t,n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i),u=(a=e?l.ceil(a):l.max((0|a)-this._minBufferSize,0))*i,e=l.min(4*u,o);if(u){for(var c=0;c<u;c+=i)this._doProcessBlock(r,c);t=r.splice(0,u),n.sigBytes-=e}return new s.init(t,e)},clone:function(){var e=i.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),p=(o.Hasher=f.extend({cfg:i.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(n){return function(e,t){return new n.init(t).finalize(e)}},_createHmacHelper:function(n){return function(e,t){return new p.HMAC.init(n,t).finalize(e)}}}),e.algo={});return e})(Math),e)}),k=f(function(e,t){e.exports=(e=>{var o=Math,t=e,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,a=[],h=[];function u(e){for(var t=o.sqrt(e),n=2;n<=t;n++)if(!(e%n))return;return 1}function c(e){return 4294967296*(e-(0|e))|0}for(var l=2,s=0;s<64;)u(l)&&(s<8&&(a[s]=c(o.pow(l,.5))),h[s]=c(o.pow(l,1/3)),s++),l++;var y=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(a.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],s=n[7],d=0;d<64;d++){y[d]=d<16?0|e[t+d]:(((f=y[d-15])<<25|f>>>7)^(f<<14|f>>>18)^f>>>3)+y[d-7]+(((f=y[d-2])<<15|f>>>17)^(f<<13|f>>>19)^f>>>10)+y[d-16];var f=r&o^r&i^o&i,p=s+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+h[d]+y[d],s=l,l=c,c=u,u=a+p|0,a=i,i=o,o=r,r=p+(((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+f)|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+s|0},_doFinalize:function(){var e=this._data,t=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return t[r>>>5]|=128<<24-r%32,t[14+(64+r>>>9<<4)]=o.floor(n/4294967296),t[15+(64+r>>>9<<4)]=n,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});return t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n),e.SHA256})(b)}),M=f(function(e,t){function a(e,t,n){for(var r,o,i=[],a=0,u=0;u<t;u++)u%4&&(r=n[e.charCodeAt(u-1)]<<u%4*2,o=n[e.charCodeAt(u)]>>>6-u%4*2,i[a>>>2]|=(r|o)<<24-a%4*8,a++);return c.create(i,a)}var c;e.exports=(c=(e=b).lib.WordArray,e.enc.Base64={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=this._map,o=(e.clamp(),[]),i=0;i<n;i+=3)for(var a=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,u=0;u<4&&i+.75*u<n;u++)o.push(r.charAt(a>>>6*(3-u)&63));var c=r.charAt(64);if(c)for(;o.length%4;)o.push(c);return o.join("")},parse:function(e){var t=e.length,n=this._map;if(!(r=this._reverseMap))for(var r=this._reverseMap=[],o=0;o<n.length;o++)r[n.charCodeAt(o)]=o;var i=n.charAt(64);return i&&-1!==(i=e.indexOf(i))&&(t=i),a(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},e.enc.Base64)}),C=(()=>{function u(){n(this,u),window.WrappedContainerModule||y.wrapModule(window,"ContainerModule")}return i(u,[{key:"NAMESPACE",get:function(){return"grabid"}},{key:"CODE_CHALLENGE_METHOD",get:function(){return"S256"}},{key:"NONCE_LENGTH",get:function(){return 16}},{key:"STATE_LENGTH",get:function(){return 7}},{key:"CODE_VERIFIER_LENGTH",get:function(){return 64}},{key:"generatePKCEArtifacts",value:function(){var e=u.generateRandomString(this.NONCE_LENGTH),t=u.generateRandomString(this.STATE_LENGTH),n=u.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:n,codeChallenge:u.generateCodeChallenge(n),codeChallengeMethod:this.CODE_CHALLENGE_METHOD}}},{key:"storePKCEArtifacts",value:function(e){this.setStorageItem("nonce",e.nonce),this.setStorageItem("state",e.state),this.setStorageItem("code_verifier",e.codeVerifier)}},{key:"setStorageItem",value:function(e,t){window.localStorage.setItem("".concat(this.NAMESPACE,":").concat(e),t)}},{key:"performWebAuthorization",value:function(e){this.setStorageItem("login_return_uri",window.location.href);var t={client_id:e.clientId,scope:e.scope,response_type:"code",redirect_uri:e.redirectUri,nonce:e.nonce,state:e.state,code_challenge_method:e.codeChallengeMethod,code_challenge:e.codeChallenge},e=u.buildAuthorizeUrl(e.authorizationEndpoint,t);return window.location.assign(e),Promise.resolve({status_code:302,result:null})}},{key:"authorize",value:(c=d().m(function e(t){var n,r,o,i,a;return d().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=u.validateAuthorizeRequest(t))return e.a(2,Promise.resolve({status_code:400,error:n}));e.n=1;break;case 1:return n=this.generatePKCEArtifacts(),this.storePKCEArtifacts(n),r={clientId:t.clientId,redirectUri:t.redirectUri,scope:t.scope,nonce:n.nonce,state:n.state,codeChallenge:n.codeChallenge,codeChallengeMethod:n.codeChallengeMethod},o=t.authorizationEndpoint,a=t.responseMode||"redirect",e.p=2,e.n=3,u.performNativeAuthorization(s(s({},r),{},{responseMode:a}));case 3:if((i=e.v).error&&400<=i.status_code)return console.error("Native authorization returned 403, falling back to web flow:",i.error),e.a(2,this.performWebAuthorization(s(s({},r),{},{authorizationEndpoint:o})));e.n=4;break;case 4:return e.a(2,i);case 5:return e.p=5,a=e.v,console.error("Native authorization failed, falling back to web flow:",a),e.a(2,this.performWebAuthorization(s(s({},r),{},{authorizationEndpoint:o})))}},e,this,[[2,5]])}),t=function(){var e=this,a=arguments;return new Promise(function(t,n){var r=c.apply(e,a);function o(e){l(r,t,n,o,i,"next",e)}function i(e){l(r,t,n,o,i,"throw",e)}o(void 0)})},function(e){return t.apply(this,arguments)})}],[{key:"generateRandomString",value:function(e){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=new Uint32Array(e),r=(crypto.getRandomValues(n),""),o=0;o<e;o+=1)r+=t.charAt(n[o]%t.length);return r}},{key:"base64URLEncode",value:function(e){return e.toString(M).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}},{key:"generateCodeVerifier",value:function(e){return u.base64URLEncode(u.generateRandomString(e))}},{key:"generateCodeChallenge",value:function(e){return u.base64URLEncode(k(e))}},{key:"normalizeUrl",value:function(e){e=new URL(e);return"".concat(e.origin).concat(e.pathname)}},{key:"buildAuthorizeUrl",value:function(e,t){t=Object.entries(t).filter(function(e){return null!=e[1]}).map(function(e){var e=a(e,2),t=e[0],e=e[1];return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e))}).join("&");return"".concat(e,"?").concat(t)}},{key:"performNativeAuthorization",value:function(e){return window.WrappedContainerModule.invoke("authorize",{clientId:e.clientId,redirectUri:u.normalizeUrl(window.location.href),scope:e.scope,nonce:e.nonce,state:e.state,codeChallenge:e.codeChallenge,codeChallengeMethod:e.codeChallengeMethod,responseMode:e.responseMode})}},{key:"validateRequiredString",value:function(e,t){return e&&"string"==typeof e&&""!==e.trim()?null:"".concat(t," is required and must be a non-empty string")}},{key:"validateAuthorizeRequest",value:function(e){if(null==e)return"request is required";var t=u.validateRequiredString(e.scope,"scope");if(t)return t;t=u.validateRequiredString(e.clientId,"clientId");if(t)return t;t=u.validateRequiredString(e.redirectUri,"redirectUri");if(t)return t;try{if(!new URL(e.redirectUri))return"redirectUri must be a valid URL"}catch(e){return"redirectUri must be a valid URL"}t=u.validateRequiredString(e.authorizationEndpoint,"authorizationEndpoint");if(t)return t;try{if(!new URL(e.authorizationEndpoint))return"authorizationEndpoint must be a valid URL"}catch(e){return"authorizationEndpoint must be a valid URL"}return null}}]);var c,t})(),S=(()=>i(function e(){n(this,e),y.wrapModule(window,"LocaleModule")},[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]))(),E=(()=>i(function e(){n(this,e),y.wrapModule(window,"LocationModule")},[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}},{key:"getCountryCode",value:function(){return window.WrappedLocationModule.invoke("getCountryCode")}}]))(),_=(()=>i(function e(){n(this,e),y.wrapModule(window,"MediaModule")},[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]))(),O=(()=>i(function e(){n(this,e),y.wrapModule(window,"PlatformModule")},[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]))(),A=(()=>i(function e(){n(this,e),y.wrapModule(window,"ScopeModule")},[{key:"hasAccessTo",value:function(e,t){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:t})}},{key:"reloadScopes",value:function(){return window.WrappedScopeModule.invoke("reloadScopes")}}]))(),T=(()=>i(function e(){n(this,e),y.wrapModule(window,"StorageModule")},[{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")}}]))(),W=(()=>i(function e(){n(this,e),y.wrapModule(window,"SystemWebViewKitModule")},[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]))();e.CameraModule=p,e.CheckoutModule=v,e.ContainerAnalyticsEventData={TRANSACTION_AMOUNT:"transaction_amount",TRANSACTION_CURRENCY:"transaction_currency",PAGE:"page"},e.ContainerAnalyticsEventName={DEFAULT:"DEFAULT"},e.ContainerAnalyticsEventState={HOMEPAGE:"HOMEPAGE",CHECKOUT_PAGE:"CHECKOUT_PAGE",BOOKING_COMPLETION:"BOOKING_COMPLETION",CUSTOM:"CUSTOM"},e.ContainerModule=w,e.IdentityModule=C,e.LocaleModule=S,e.LocationModule=E,e.MediaModule=_,e.PlatformModule=O,e.ScopeModule=A,e.StorageModule=T,e.SystemWebViewKitModule=W,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# IdentityModule
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
The IdentityModule provides functionality related to user identity.
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
### 1. Authorize
|
|
10
|
+
|
|
11
|
+
**Method name**: `authorize`
|
|
12
|
+
|
|
13
|
+
**Arguments**
|
|
14
|
+
|
|
15
|
+
| Name | Type | Required | Description |
|
|
16
|
+
| --- | --- | --- | --- |
|
|
17
|
+
| request | Object | Yes | Authorization request parameters |
|
|
18
|
+
|
|
19
|
+
**Request Object Properties**
|
|
20
|
+
|
|
21
|
+
| Property | Type | Required | Description |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| clientId | String | Yes | Client ID for authorization |
|
|
24
|
+
| scope | String | Yes | Scope of the authorization |
|
|
25
|
+
| redirectUri | String | Yes | Redirect URI for authorization callback |
|
|
26
|
+
| authorizationEndpoint | String | Yes | Endpoint for web authorization fallback |
|
|
27
|
+
| responseMode | String | No | Response mode ('redirect' or 'in_place') |
|
|
28
|
+
|
|
29
|
+
**Return type**
|
|
30
|
+
|
|
31
|
+
| Name | Type | Description |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| result | Object | Result of the authorization |
|
|
34
|
+
| error | String | Error message if authorization fails |
|
|
35
|
+
| status_code | Number | HTTP status code (e.g. 200 for success, 499 for user cancellation) |
|
|
36
|
+
|
|
37
|
+
**Result Object Properties**
|
|
38
|
+
|
|
39
|
+
| Property | Type | Description |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| state | String | The state parameter returned from the server |
|
|
42
|
+
| code | String | The authorization code returned from the server |
|
|
43
|
+
|
|
44
|
+
**Code example**
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { IdentityModule } from "@grabjs/superapp-sdk";
|
|
48
|
+
|
|
49
|
+
// Ideally, initialize this only one and reuse across app.
|
|
50
|
+
const identityModule = new IdentityModule();
|
|
51
|
+
|
|
52
|
+
const request = {
|
|
53
|
+
clientId: "your-client-id",
|
|
54
|
+
scope: "profile openid",
|
|
55
|
+
redirectUri: "https://your-redirect-uri.com",
|
|
56
|
+
authorizationEndpoint: "https://api.grab.com/grabid/v1/oauth2/authorize",
|
|
57
|
+
responseMode: "redirect"
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
identityModule.authorize(request).then(({ result, error, status_code }) => {
|
|
61
|
+
if (status_code === 200 && result) {
|
|
62
|
+
// Authorization successful
|
|
63
|
+
console.log("Auth Code:", result.code);
|
|
64
|
+
console.log("State:", result.state);
|
|
65
|
+
} else if (status_code === 499) {
|
|
66
|
+
// User cancelled the authorization
|
|
67
|
+
console.log("User cancelled");
|
|
68
|
+
} else if (error) {
|
|
69
|
+
// Authorization failed
|
|
70
|
+
console.error("Auth error:", error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grabjs/superapp-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "SDK for Grab SuperApp WebView.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/grab/superapp-sdk#readme",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@grabjs/mobile-kit-bridge-sdk": "^1.1.1"
|
|
37
|
+
"@grabjs/mobile-kit-bridge-sdk": "^1.1.1",
|
|
38
|
+
"crypto-js": "^4.2.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@babel/core": "^7.4.3",
|