@grabjs/superapp-sdk 1.8.1 → 1.8.3
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 +135 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,401,403].includes(i.status_code))return console.error("Native authorization returned ".concat(i.status_code,", 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})});
|
|
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 c(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 i(u){return function(){var e=this,a=arguments;return new Promise(function(t,n){var r=u.apply(e,a);function o(e){c(r,t,n,o,i,"next",e)}function i(e){c(r,t,n,o,i,"throw",e)}o(void 0)})}}function a(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,f(r.key),r)}}function u(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=f(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 l(){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,s,l,d,f,t=t&&t.prototype instanceof g?t:g,t=Object.create(t.prototype);return w(t,"_invoke",(o=e,i=n,l=r||[],d=!1,f={p:s=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,v}},function(e,t,n){if(1<s)throw TypeError("Generator is already running");for(d&&1===t&&p(t,n),u=t,c=n;(y=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(s=2,a){if(y=a[e=u?e:"next"]){if(!(y=y.call(a,c)))throw TypeError("iterator result is not an object");if(!y.done)return y;c=y.value,u<2&&(u=0)}else 1===u&&(y=a.return)&&y.call(a),u<2&&(c=TypeError("The iterator does not provide a '"+e+"' method"),u=1);a=h}else if((y=(d=f.n<0)?c:o.call(i,f))!==v)break}catch(e){a=h,u=1,c=e}finally{s=1}}return{value:y,done:d}}),!0),t;function p(e,t){for(u=e,c=t,y=0;!d&&s&&!n&&y<l.length;y++){var n,r=l[y],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 v;throw d=!0,t}}var v={};function g(){}function o(){}function i(){}var y=Object.getPrototypeOf,e=[][t]?y(y([][t]())):(w(y={},t,function(){return this}),y),a=i.prototype=g.prototype=Object.create(e);function u(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,i):(e.__proto__=i,w(e,n,"GeneratorFunction")),e.prototype=Object.create(a),e}return w(a,"constructor",o.prototype=i),w(i,"constructor",o),w(i,n,o.displayName="GeneratorFunction"),w(a),w(a,n,"Generator"),w(a,t,function(){return this}),w(a,"toString",function(){return"[object Generator]"}),(l=function(){return{w:r,m:u}})()}function w(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}(w=function(e,t,n,r){function o(t,n){w(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 d(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,s=!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){s=!0,o=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)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 f(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 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)}var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function p(e,t){return e(t={exports:{}},t.exports),t.exports}var v=p(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 v;((v=t).StreamEvent||(v.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",v.createDataStream=p,v.createSubscription=f,v.getModuleEnvironment=function(e,t){return e[t]?"android":e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]?"ios":void 0},v.wrapModule=function(u,c){var s,l,d;u["Wrapped"+c]=(s=u,l=c,d={},{invoke:function(t,n){return e=s,(r={funcNameToWrap:t,callbackNameFunc:function(){var e=d[t]||0;return d[t]=e+1,(e={moduleName:l,requestID:e,funcName:t}).moduleName+"_"+e.funcName+"Callback"+(null!==(e=e.requestID)?"_"+e:"")},funcToWrap:function(e){e={callback:e,method:t,module:l,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===v.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(v,"__esModule",{value:!0})}),g=(v=v)&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v,v=(()=>u(function e(){a(this,e),g.wrapModule(window,"CameraModule")},[{key:"scanQRCode",value:function(){return window.WrappedCameraModule.invoke("scanQRCode",0<arguments.length&&void 0!==arguments[0]?arguments[0]:{})}}]))(),y=(()=>u(function e(){a(this,e),g.wrapModule(window,"CheckoutModule")},[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]))(),m=(()=>u(function e(){a(this,e),g.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"!==n(e.data)?"data must be undefined or an object":null}}]))(),b={},k=p(function(e,t){e.exports=(e=(s=>{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=b}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)}},l=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=s.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 l.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 l.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 l.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 l.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?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*i,e=s.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 l.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)}),S=p(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 s=2,l=0;l<64;)u(s)&&(l<8&&(a[l]=c(o.pow(s,.5))),h[l]=c(o.pow(s,1/3)),l++),s++;var v=[],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],s=n[6],l=n[7],d=0;d<64;d++){v[d]=d<16?0|e[t+d]:(((f=v[d-15])<<25|f>>>7)^(f<<14|f>>>18)^f>>>3)+v[d-7]+(((f=v[d-2])<<15|f>>>17)^(f<<13|f>>>19)^f>>>10)+v[d-16];var f=r&o^r&i^o&i,p=l+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&s)+h[d]+v[d],l=s,s=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]+s|0,n[7]=n[7]+l|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})(k)}),M=p(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=k).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 c(){a(this,c),window.WrappedIdentityModule||g.wrapModule(window,"IdentityModule")}return u(c,[{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:"OPENID_CONFIG_ENDPOINTS",get:function(){return{staging:"https://partner-api.stg-myteksi.com/grabid/v1/oauth2/.well-known/openid-configuration",production:"https://partner-api.grab.com/grabid/v1/oauth2/.well-known/openid-configuration"}}},{key:"fetchAuthorizationEndpoint",value:(o=i(l().m(function e(t){var n,r,o,i;return l().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=this.OPENID_CONFIG_ENDPOINTS[t]){e.n=1;break}throw new Error("Invalid environment: ".concat(t,". Must be 'staging' or 'production'"));case 1:return e.p=1,e.n=2,fetch(n);case 2:if((r=e.v).ok){e.n=3;break}throw console.error("Failed to fetch OpenID configuration from ".concat(n,": ").concat(r.status," ").concat(r.statusText)),new Error("Failed to fetch authorization configuration");case 3:return e.n=4,r.json();case 4:if((o=e.v).authorization_endpoint){e.n=5;break}throw console.error("authorization_endpoint not found in OpenID configuration response"),new Error("Invalid authorization configuration");case 5:return e.a(2,o.authorization_endpoint);case 6:if(e.p=6,i=e.v,console.error("Error fetching authorization endpoint:",i),"Failed to fetch authorization configuration"===i.message||"Invalid authorization configuration"===i.message)throw i;e.n=7;break;case 7:throw new Error("Something wrong happened when fetching authorization configuration");case 8:return e.a(2)}},e,this,[[1,6]])})),function(e){return o.apply(this,arguments)})},{key:"generatePKCEArtifacts",value:function(){var e=c.generateRandomString(this.NONCE_LENGTH),t=c.generateRandomString(this.STATE_LENGTH),n=c.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:n,codeChallenge:c.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),this.setStorageItem("redirect_uri",e.redirectUri)}},{key:"getAuthorizationArtifacts",value:(r=i(l().m(function e(){var t,n,r,o,i;return l().w(function(e){for(;;)switch(e.n){case 0:if(t=this.getStorageItem("state"),n=this.getStorageItem("code_verifier"),r=this.getStorageItem("nonce"),o=this.getStorageItem("redirect_uri"),4===(i=[t,n,r,o].filter(function(e){return null!==e}).length))return e.a(2,Promise.resolve({status_code:200,result:{state:t,codeVerifier:n,nonce:r,redirectUri:o},error:null}));e.n=1;break;case 1:if(0===i)return e.a(2,Promise.resolve({status_code:204,result:null,error:null}));e.n=2;break;case 2:return e.a(2,Promise.resolve({status_code:400,result:null,error:"Inconsistent authorization artifacts in storage"}))}},e,this)})),function(){return r.apply(this,arguments)})},{key:"clearAuthorizationArtifacts",value:(e=i(l().m(function e(){return l().w(function(e){for(;;)if(0===e.n)return window.localStorage.removeItem("".concat(this.NAMESPACE,":nonce")),window.localStorage.removeItem("".concat(this.NAMESPACE,":state")),window.localStorage.removeItem("".concat(this.NAMESPACE,":code_verifier")),window.localStorage.removeItem("".concat(this.NAMESPACE,":redirect_uri")),window.localStorage.removeItem("".concat(this.NAMESPACE,":login_return_uri")),e.a(2,Promise.resolve({status_code:204,result:null,error:null}))},e,this)})),function(){return e.apply(this,arguments)})},{key:"setStorageItem",value:function(e,t){window.localStorage.setItem("".concat(this.NAMESPACE,":").concat(e),t)}},{key:"getStorageItem",value:function(e){return window.localStorage.getItem("".concat(this.NAMESPACE,":").concat(e))}},{key:"performWebAuthorization",value:(n=i(l().m(function e(t){var n,r,o;return l().w(function(e){for(;;)switch(e.p=e.n){case 0:return this.setStorageItem("login_return_uri",window.location.href),this.setStorageItem("redirect_uri",t.redirectUri),e.p=1,e.n=2,this.fetchAuthorizationEndpoint(t.environment);case 2:n=e.v,e.n=4;break;case 3:return e.p=3,o=e.v,e.a(2,Promise.resolve({status_code:400,error:o.message}));case 4:return o={client_id:t.clientId,scope:t.scope,response_type:"code",redirect_uri:t.redirectUri,nonce:t.nonce,state:t.state,code_challenge_method:t.codeChallengeMethod,code_challenge:t.codeChallenge},r=c.buildAuthorizeUrl(n,o),window.location.assign(r),e.a(2,Promise.resolve({status_code:302,result:null}))}},e,this,[[1,3]])})),function(e){return n.apply(this,arguments)})},{key:"authorize",value:(t=i(l().m(function e(t){var n,r,o,i,a,u;return l().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=c.validateAuthorizeRequest(t))return e.a(2,Promise.resolve({status_code:400,error:n}));e.n=1;break;case 1:if(n=this.generatePKCEArtifacts(),r=t.responseMode||"redirect",o="in_place"===r?c.normalizeUrl(window.location.href):t.redirectUri,this.storePKCEArtifacts(s(s({},n),{},{redirectUri:o})),i={clientId:t.clientId,redirectUri:t.redirectUri,scope:t.scope,nonce:n.nonce,state:n.state,codeChallenge:n.codeChallenge,codeChallengeMethod:n.codeChallengeMethod},c.shouldUseWebConsent(t))return e.a(2,this.performWebAuthorization(s(s({},i),{},{environment:t.environment})));e.n=2;break;case 2:return e.p=2,e.n=3,c.performNativeAuthorization(s(s({},i),{},{actualRedirectUri:o,responseMode:r}));case 3:if((a=e.v).error&&[400,401,403].includes(a.status_code))return console.error("Native authorization returned ".concat(a.status_code,", falling back to web flow:"),a.error),e.a(2,this.performWebAuthorization(s(s({},i),{},{environment:t.environment})));e.n=4;break;case 4:return e.a(2,a);case 5:return e.p=5,u=e.v,console.error("Native authorization failed, falling back to web flow:",u),e.a(2,this.performWebAuthorization(s(s({},i),{},{environment:t.environment})))}},e,this,[[2,5]])})),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 c.base64URLEncode(c.generateRandomString(e))}},{key:"generateCodeChallenge",value:function(e){return c.base64URLEncode(S(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=d(e,2),t=e[0],e=e[1];return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e))}).join("&");return"".concat(e,"?").concat(t)}},{key:"parseGrabUserAgent",value:function(e){return e&&"string"==typeof e&&(e=e.match(/(Grab|GrabBeta|GrabBetaDebug|GrabTaxi|GrabEarlyAccess)\/v?([0-9]+)\.([0-9]+)\.([0-9]+) \(.*(Android|iOS).*\)/i))?{appName:e[1],major:Number(e[2]),minor:Number(e[3]),patch:Number(e[4]),platform:e[5]}:null}},{key:"isVersionBelow",value:function(e,t){return e.major!==t.major?e.major<t.major:e.minor!==t.minor?e.minor<t.minor:e.patch<t.patch}},{key:"shouldUseWebConsent",value:function(e){var t=c.parseGrabUserAgent(window.navigator.userAgent);return!t||"staging"!==e.environment&&c.isVersionBelow(t,{major:5,minor:396,patch:0})}},{key:"performNativeAuthorization",value:function(e){return window.WrappedIdentityModule.invoke("authorize",{clientId:e.clientId,redirectUri:e.actualRedirectUri,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=c.validateRequiredString(e.scope,"scope");if(t)return t;t=c.validateRequiredString(e.clientId,"clientId");if(t)return t;t=c.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=c.validateRequiredString(e.environment,"environment");return t||("staging"!==e.environment&&"production"!==e.environment?"environment must be either 'staging' or 'production'":null)}}]);var t,n,e,r,o})(),_=(()=>u(function e(){a(this,e),g.wrapModule(window,"LocaleModule")},[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]))(),E=(()=>u(function e(){a(this,e),g.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")}}]))(),A=(()=>u(function e(){a(this,e),g.wrapModule(window,"MediaModule")},[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]))(),O=(()=>u(function e(){a(this,e),g.wrapModule(window,"PlatformModule")},[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]))(),I=(()=>u(function e(){a(this,e),g.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")}}]))(),P=(()=>u(function e(){a(this,e),g.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")}}]))(),N=(()=>u(function e(){a(this,e),g.wrapModule(window,"SystemWebViewKitModule")},[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]))();e.CameraModule=v,e.CheckoutModule=y,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=m,e.IdentityModule=C,e.LocaleModule=_,e.LocationModule=E,e.MediaModule=A,e.PlatformModule=O,e.ScopeModule=I,e.StorageModule=P,e.SystemWebViewKitModule=N,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/docs/IdentityModule.md
CHANGED
|
@@ -23,8 +23,25 @@ The IdentityModule provides functionality related to user identity.
|
|
|
23
23
|
| clientId | String | Yes | Client ID for authorization |
|
|
24
24
|
| scope | String | Yes | Scope of the authorization |
|
|
25
25
|
| redirectUri | String | Yes | Redirect URI for authorization callback |
|
|
26
|
-
|
|
|
27
|
-
| responseMode | String | No | Response mode ('redirect' or 'in_place') |
|
|
26
|
+
| environment | String | Yes | Environment ('staging' or 'production'). Used to fetch the authorization endpoint from the OpenID configuration for the web flow |
|
|
27
|
+
| responseMode | String | No | Response mode ('redirect' or 'in_place'). Defaults to 'redirect' if not specified |
|
|
28
|
+
|
|
29
|
+
**Important Note on `redirectUri` and `responseMode`:**
|
|
30
|
+
|
|
31
|
+
The actual `redirectUri` used during authorization may differ from the one you provide, depending on the flow:
|
|
32
|
+
|
|
33
|
+
- **`responseMode: 'in_place'` when native flow is available**: Uses the current page URL (normalized) as the `redirectUri`, overriding your provided value
|
|
34
|
+
- **`responseMode: 'in_place'` falling back to web flow if native flow is not available**: Uses your provided `redirectUri`
|
|
35
|
+
- **`responseMode: 'redirect'`**: Always uses your provided `redirectUri`
|
|
36
|
+
|
|
37
|
+
To ensure successful token exchange (which requires matching `redirectUri` values), **always retrieve the actual `redirectUri` from `getAuthorizationArtifacts()`** after authorization completes.
|
|
38
|
+
|
|
39
|
+
**Consent Selection Rules (Native vs Web):**
|
|
40
|
+
|
|
41
|
+
- If the user agent does not match the Grab app pattern, the SDK uses **web consent**.
|
|
42
|
+
- If `environment` is `staging`, the SDK **skips version gating** and attempts native consent.
|
|
43
|
+
- Otherwise, if the app version in the user agent is below **5.396.0** (iOS or Android), the SDK uses **web consent**.
|
|
44
|
+
- For supported versions, the SDK attempts **native consent** first and falls back to web on specific native errors.
|
|
28
45
|
|
|
29
46
|
**Return type**
|
|
30
47
|
|
|
@@ -53,21 +70,123 @@ const request = {
|
|
|
53
70
|
clientId: "your-client-id",
|
|
54
71
|
scope: "profile openid",
|
|
55
72
|
redirectUri: "https://your-redirect-uri.com",
|
|
56
|
-
|
|
73
|
+
environment: "production", // or "staging"
|
|
57
74
|
responseMode: "redirect"
|
|
58
75
|
};
|
|
59
76
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
const { result, error, status_code } = await identityModule.authorize(request);
|
|
78
|
+
if (status_code === 200 && result) {
|
|
79
|
+
// Authorization successful (in_place mode with native flow)
|
|
80
|
+
console.log("Auth Code:", result.code);
|
|
81
|
+
console.log("State:", result.state);
|
|
82
|
+
} else if (status_code === 302) {
|
|
83
|
+
// Authorization redirect initiated (web flow or redirect response mode)
|
|
84
|
+
// The page will redirect to the authorization server
|
|
85
|
+
} else if (status_code === 499) {
|
|
86
|
+
// User cancelled the authorization
|
|
87
|
+
console.log("User cancelled");
|
|
88
|
+
} else if (error) {
|
|
89
|
+
// Authorization failed
|
|
90
|
+
console.error("Auth error:", error);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. Get Authorization Artifacts
|
|
95
|
+
|
|
96
|
+
**Method name**: `getAuthorizationArtifacts`
|
|
97
|
+
|
|
98
|
+
**Description**
|
|
99
|
+
|
|
100
|
+
Retrieves the authorization artifacts that were stored in localStorage during the authorization flow. These include PKCE (Proof Key for Code Exchange) values and the actual `redirectUri` that was used. These values are needed to complete the OAuth token exchange after the authorization redirect.
|
|
101
|
+
|
|
102
|
+
**Important:** The `redirectUri` returned by this method is the **actual** redirect URI that was sent to the authorization server. This may differ from the `redirectUri` you provided to `authorize()` if you used `responseMode: 'in_place'` with native flow. You **must** use this returned `redirectUri` for token exchange to ensure OAuth compliance.
|
|
103
|
+
|
|
104
|
+
**Arguments**
|
|
105
|
+
|
|
106
|
+
None
|
|
107
|
+
|
|
108
|
+
**Return type**
|
|
109
|
+
|
|
110
|
+
| Name | Type | Description |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| result | Object \| null | Object containing the authorization artifacts (200), or null if not stored (204) or inconsistent (400) |
|
|
113
|
+
| error | String \| null | Error message if artifacts are inconsistent (400), otherwise null |
|
|
114
|
+
| status_code | Number | HTTP status code: 200 (success), 204 (no artifacts), or 400 (inconsistent state) |
|
|
115
|
+
|
|
116
|
+
**Result Object Properties**
|
|
117
|
+
|
|
118
|
+
When `status_code` is 200, the `result` object contains:
|
|
119
|
+
|
|
120
|
+
| Property | Type | Description |
|
|
121
|
+
| --- | --- | --- |
|
|
122
|
+
| state | String | The state parameter used for CSRF protection |
|
|
123
|
+
| codeVerifier | String | The PKCE code verifier used for token exchange |
|
|
124
|
+
| nonce | String | The nonce used for ID token verification |
|
|
125
|
+
| redirectUri | String | The actual redirect URI that was used during authorization |
|
|
126
|
+
|
|
127
|
+
**Status Codes**
|
|
128
|
+
|
|
129
|
+
- **200**: All four artifacts are present and returned in `result`
|
|
130
|
+
- **204**: No artifacts are stored (authorization has not been called yet)
|
|
131
|
+
- **400**: Inconsistent state detected (only some artifacts present, possible data corruption)
|
|
132
|
+
|
|
133
|
+
**Code example**
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
import { IdentityModule } from "@grabjs/superapp-sdk";
|
|
137
|
+
|
|
138
|
+
// Ideally, initialize this only once and reuse across app.
|
|
139
|
+
const identityModule = new IdentityModule();
|
|
140
|
+
|
|
141
|
+
// After authorization redirect, retrieve the stored artifacts
|
|
142
|
+
const { result, status_code, error } = await identityModule.getAuthorizationArtifacts();
|
|
143
|
+
|
|
144
|
+
if (status_code === 200 && result) {
|
|
145
|
+
// All artifacts present - proceed with token exchange
|
|
146
|
+
const { state, codeVerifier, nonce, redirectUri } = result;
|
|
147
|
+
console.log("State:", state);
|
|
148
|
+
console.log("Code Verifier:", codeVerifier);
|
|
149
|
+
console.log("Nonce:", nonce);
|
|
150
|
+
console.log("Redirect URI:", redirectUri);
|
|
151
|
+
} else if (status_code === 204) {
|
|
152
|
+
// No artifacts yet - user hasn't authorized
|
|
153
|
+
console.log("No authorization artifacts found. Authorization has not been initiated.");
|
|
154
|
+
} else if (status_code === 400) {
|
|
155
|
+
// Inconsistent state - possible data corruption
|
|
156
|
+
console.error("Authorization artifacts error:", error);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 3. Clear Authorization Artifacts
|
|
161
|
+
|
|
162
|
+
**Method name**: `clearAuthorizationArtifacts`
|
|
163
|
+
|
|
164
|
+
**Description**
|
|
165
|
+
|
|
166
|
+
Clears all stored authorization artifacts from localStorage. This should be called after a successful token exchange or when you need to reset the authorization state (e.g., on error or logout).
|
|
167
|
+
|
|
168
|
+
**Arguments**
|
|
169
|
+
|
|
170
|
+
None
|
|
171
|
+
|
|
172
|
+
**Return type**
|
|
173
|
+
|
|
174
|
+
| Name | Type | Description |
|
|
175
|
+
| --- | --- | --- |
|
|
176
|
+
| result | null | Always null (no data to return) |
|
|
177
|
+
| error | null | Always null (no error) |
|
|
178
|
+
| status_code | Number | Always 204 (No Content - successful operation) |
|
|
179
|
+
|
|
180
|
+
**Code example**
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
import { IdentityModule } from "@grabjs/superapp-sdk";
|
|
184
|
+
|
|
185
|
+
const identityModule = new IdentityModule();
|
|
186
|
+
|
|
187
|
+
// After successful token exchange or on error
|
|
188
|
+
const { status_code } = await identityModule.clearAuthorizationArtifacts();
|
|
189
|
+
if (status_code === 204) {
|
|
190
|
+
console.log("Authorization artifacts cleared");
|
|
191
|
+
}
|
|
73
192
|
```
|