@grabjs/superapp-sdk 1.8.10 → 2.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.json +11473 -0
- package/dist/index.d.ts +1719 -0
- package/dist/index.esm.js +7 -0
- package/dist/index.js +7 -1
- package/package.json +44 -19
- package/docs/CameraModule.md +0 -89
- package/docs/CheckoutModule.md +0 -48
- package/docs/ContainerModule.md +0 -524
- package/docs/IdentityModule.md +0 -192
- package/docs/LocaleModule.md +0 -51
- package/docs/LocationModule.md +0 -172
- package/docs/MediaModule.md +0 -97
- package/docs/PlatformModule.md +0 -33
- package/docs/ProfileModule.md +0 -136
- package/docs/ScopeModule.md +0 -68
- package/docs/StorageModule.md +0 -327
- package/docs/SystemWebViewKitModule.md +0 -41
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Grab Taxi Holdings PTE LTD (GRAB)
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var n,o={exports:{}},i=(n||(n=1,function(e){function t(e){var t=!1;return{isUnsubscribed:function(){return t},unsubscribe:function(){t||(e(),t=!0)}}}function r(e){return{subscribe:e,then:function(t,r){return new Promise(function(n,o){try{var i=null,a=!1;i=e({next:function(e){n(null==t?void 0:t(e)),i&&i.unsubscribe(),a=!0}}),a&&i&&i.unsubscribe()}catch(e){null==r?o(e):n(r(e))}})}}}function n(n,o){return o.funcNameToWrap,function(n,o){var i=o.callbackNameFunc,a=o.funcToWrap;return r(function(r){var o,s=i();return n[s]=function(t){if(function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(!e)return!1;var n=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return t.every(function(e){return 0<=n.indexOf(e)})}(t.result,"event"))t.result.event===e.StreamEvent.STREAM_TERMINATED&&o.unsubscribe();else{var n=t.result,i=t.error,a=t.status_code;r&&r.next&&r.next({result:null===n?void 0:n,error:null===i?void 0:i,status_code:null===a?void 0:a})}},a(s),o=t(function(){n[s]=void 0,r&&r.complete&&r.complete()})})}(n,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&(r[n[o]]=e[n[o]])}return r}(o,["funcNameToWrap"]))}(e.StreamEvent||(e.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",e.createDataStream=r,e.createSubscription=t,e.getModuleEnvironment=function(e,t){return e[t]?"android":e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]?"ios":void 0},e.wrapModule=function(e,t){var r;e[(r=t,"Wrapped"+r)]=function(e,t,r){return{invoke:function(o,i){return n(e,{funcNameToWrap:o,callbackNameFunc:function(){return function(e,t){var r=t.moduleName,n=t.funcName,o=0;return function(){for(var t,i,a="";(a=(t={moduleName:r,funcName:n,requestID:o}).moduleName+"_"+t.funcName+"Callback"+(null!==(i=t.requestID)?"_"+i:""))in e;)o+=1;return o+=1,a}()}(e,{moduleName:t,funcName:o})},funcToWrap:function(e){return r({callback:e,method:o,module:t,parameters:null!=i?i:{}})}})}}}(e,t,function(r){if(e[t]&&e[t][r.method]instanceof Function)e[t][r.method](JSON.stringify(r));else{if(!(e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]))throw new Error("Unexpected method '"+r.method+"' for module '"+t+"'");e.webkit.messageHandlers[t].postMessage(r)}})},Object.defineProperty(e,"__esModule",{value:!0})}(o.exports)),o.exports);class a{get wrappedModule(){return window[`Wrapped${this.name}`]}constructor(e){if(this.name=e,!this.wrappedModule)try{i.wrapModule(window,this.name)}catch(e){throw new Error(`Failed to initialize ${this.name}: ${e.message}`)}}}class s extends a{constructor(){super("CameraModule")}scanQRCode(e){return this.wrappedModule.invoke("scanQRCode",e)}}class u extends a{constructor(){super("CheckoutModule")}triggerCheckout(e){return this.wrappedModule.invoke("triggerCheckout",e)}}class c extends a{constructor(){super("ContainerModule")}setBackgroundColor(e){return this.wrappedModule.invoke("setBackgroundColor",{backgroundColor:e})}setTitle(e){return this.wrappedModule.invoke("setTitle",{title:e})}hideBackButton(){return this.wrappedModule.invoke("hideBackButton")}showBackButton(){return this.wrappedModule.invoke("showBackButton")}hideRefreshButton(){return this.wrappedModule.invoke("hideRefreshButton")}showRefreshButton(){return this.wrappedModule.invoke("showRefreshButton")}close(){return this.wrappedModule.invoke("close")}onContentLoaded(){return this.wrappedModule.invoke("onContentLoaded")}showLoader(){return this.wrappedModule.invoke("showLoader")}hideLoader(){return this.wrappedModule.invoke("hideLoader")}openExternalLink(e){return this.wrappedModule.invoke("openExternalLink",{url:e})}onCtaTap(e){return this.wrappedModule.invoke("onCtaTap",{action:e})}sendAnalyticsEvent(e){const t=this.validateAnalyticsEvent(e);return t?Promise.resolve({status_code:400,error:t}):this.wrappedModule.invoke("sendAnalyticsEvent",{state:e.state,name:e.name,data:e.data?JSON.stringify(e.data):null})}isConnected(){const e=window.navigator&&window.navigator.userAgent;if(!e)return Promise.resolve({status_code:404,error:"User agent not available"});const t=/grab[a-z]*\//i.test(e);return Promise.resolve(t?{status_code:200,result:{connected:!0}}:{status_code:404,error:"Not connected to Grab app"})}getSessionParams(){return this.wrappedModule.invoke("getSessionParams")}validateAnalyticsEvent(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"!=typeof e.data?"data must be undefined or an object":null}}const l={HOMEPAGE:"HOMEPAGE",CHECKOUT_PAGE:"CHECKOUT_PAGE",BOOKING_COMPLETION:"BOOKING_COMPLETION",CUSTOM:"CUSTOM"},d={DEFAULT:"DEFAULT"},p={TRANSACTION_AMOUNT:"transaction_amount",TRANSACTION_CURRENCY:"transaction_currency",PAGE:"page"};var h,f,g={exports:{}},m={exports:{}},v=r(Object.freeze({__proto__:null,default:{}}));function w(){return h||(h=1,m.exports=(t=t||function(t){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==e&&e.crypto&&(r=e.crypto),!r)try{r=v}catch(e){}var n=function(){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.")},o=Object.create||function(){function e(){}return function(t){var r;return e.prototype=t,r=new e,e.prototype=null,r}}(),i={},a=i.lib={},s=a.Base={extend:function(e){var t=o(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,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)}},u=a.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||l).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes,o=e.sigBytes;if(this.clamp(),n%4)for(var i=0;i<o;i++){var a=r[i>>>2]>>>24-i%4*8&255;t[n+i>>>2]|=a<<24-(n+i)%4*8}else for(var s=0;s<o;s+=4)t[n+s>>>2]=r[s>>>2];return this.sigBytes+=o,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=t.ceil(r/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r<e;r+=4)t.push(n());return new u.init(t,e)}}),c=i.enc={},l=c.Hex={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new u.init(r,t/2)}},d=c.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(i))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new u.init(r,t)}},p=c.Utf8={stringify:function(e){try{return decodeURIComponent(escape(d.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return d.parse(unescape(encodeURIComponent(e)))}},h=a.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(e){var r,n=this._data,o=n.words,i=n.sigBytes,a=this.blockSize,s=i/(4*a),c=(s=e?t.ceil(s):t.max((0|s)-this._minBufferSize,0))*a,l=t.min(4*c,i);if(c){for(var d=0;d<c;d+=a)this._doProcessBlock(o,d);r=o.splice(0,c),n.sigBytes-=l}return new u.init(r,l)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});a.Hasher=h.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.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(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new f.HMAC.init(e,r).finalize(t)}}});var f=i.algo={};return i}(Math),t)),m.exports;var t}var y,b,_=t(f?g.exports:(f=1,g.exports=(y=w(),function(e){var t=y,r=t.lib,n=r.WordArray,o=r.Hasher,i=t.algo,a=[],s=[];!function(){function t(t){for(var r=e.sqrt(t),n=2;n<=r;n++)if(!(t%n))return!1;return!0}function r(e){return 4294967296*(e-(0|e))|0}for(var n=2,o=0;o<64;)t(n)&&(o<8&&(a[o]=r(e.pow(n,.5))),s[o]=r(e.pow(n,1/3)),o++),n++}();var u=[],c=i.SHA256=o.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],o=r[1],i=r[2],a=r[3],c=r[4],l=r[5],d=r[6],p=r[7],h=0;h<64;h++){if(h<16)u[h]=0|e[t+h];else{var f=u[h-15],g=(f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3,m=u[h-2],v=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;u[h]=g+u[h-7]+v+u[h-16]}var w=n&o^n&i^o&i,y=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),b=p+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&l^~c&d)+s[h]+u[h];p=d,d=l,l=c,c=a+b|0,a=i,i=o,o=n,n=b+(y+w)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+i|0,r[3]=r[3]+a|0,r[4]=r[4]+c|0,r[5]=r[5]+l|0,r[6]=r[6]+d|0,r[7]=r[7]+p|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,o=8*t.sigBytes;return r[o>>>5]|=128<<24-o%32,r[14+(o+64>>>9<<4)]=e.floor(n/4294967296),r[15+(o+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=o._createHelper(c),t.HmacSHA256=o._createHmacHelper(c)}(Math),y.SHA256))),M={exports:{}},E=(b||(b=1,M.exports=function(e){return r=(t=e).lib.WordArray,t.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp();for(var o=[],i=0;i<r;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,s=0;s<4&&i+.75*s<r;s++)o.push(n.charAt(a>>>6*(3-s)&63));var u=n.charAt(64);if(u)for(;o.length%4;)o.push(u);return o.join("")},parse:function(e){var t=e.length,n=this._map,o=this._reverseMap;if(!o){o=this._reverseMap=[];for(var i=0;i<n.length;i++)o[n.charCodeAt(i)]=i}var a=n.charAt(64);if(a){var s=e.indexOf(a);-1!==s&&(t=s)}return function(e,t,n){for(var o=[],i=0,a=0;a<t;a++)if(a%4){var s=n[e.charCodeAt(a-1)]<<a%4*2|n[e.charCodeAt(a)]>>>6-a%4*2;o[i>>>2]|=s<<24-i%4*8,i++}return r.create(o,i)}(e,t,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},e.enc.Base64;var t,r}(w())),M.exports),A=t(E);class C extends a{constructor(){super("IdentityModule")}get NAMESPACE(){return"grabid"}get CODE_CHALLENGE_METHOD(){return"S256"}get NONCE_LENGTH(){return 16}get STATE_LENGTH(){return 7}get CODE_VERIFIER_LENGTH(){return 64}get OPENID_CONFIG_ENDPOINTS(){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"}}async fetchAuthorizationEndpoint(e){const t=this.OPENID_CONFIG_ENDPOINTS[e];if(!t)throw new Error(`Invalid environment: ${e}. Must be 'staging' or 'production'`);try{const e=await fetch(t);if(!e.ok)throw console.error(`Failed to fetch OpenID configuration from ${t}: ${e.status} ${e.statusText}`),new Error("Failed to fetch authorization configuration");const r=await e.json();if(!r.authorization_endpoint)throw console.error("authorization_endpoint not found in OpenID configuration response"),new Error("Invalid authorization configuration");return r.authorization_endpoint}catch(e){if(console.error("Error fetching authorization endpoint:",e),"Failed to fetch authorization configuration"===e.message||"Invalid authorization configuration"===e.message)throw e;throw new Error("Something wrong happened when fetching authorization configuration",{cause:e})}}static generateRandomString(e){const t=new Uint32Array(e);crypto.getRandomValues(t);let r="";for(let n=0;n<e;n+=1)r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(t[n]%62);return r}static base64URLEncode(e){return e.toString(A).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}static generateCodeVerifier(e){return C.base64URLEncode(C.generateRandomString(e))}static generateCodeChallenge(e){return C.base64URLEncode(_(e))}generatePKCEArtifacts(){const e=C.generateRandomString(this.NONCE_LENGTH),t=C.generateRandomString(this.STATE_LENGTH),r=C.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:r,codeChallenge:C.generateCodeChallenge(r),codeChallengeMethod:this.CODE_CHALLENGE_METHOD}}storePKCEArtifacts(e){this.setStorageItem("nonce",e.nonce),this.setStorageItem("state",e.state),this.setStorageItem("code_verifier",e.codeVerifier),this.setStorageItem("redirect_uri",e.redirectUri)}async getAuthorizationArtifacts(){const e=this.getStorageItem("state"),t=this.getStorageItem("code_verifier"),r=this.getStorageItem("nonce"),n=this.getStorageItem("redirect_uri"),o=[e,t,r,n].filter(e=>null!==e).length;return 4===o?Promise.resolve({status_code:200,result:{state:e,codeVerifier:t,nonce:r,redirectUri:n},error:null}):0===o?Promise.resolve({status_code:204,result:null,error:null}):Promise.resolve({status_code:400,result:null,error:"Inconsistent authorization artifacts in storage"})}async clearAuthorizationArtifacts(){return window.localStorage.removeItem(`${this.NAMESPACE}:nonce`),window.localStorage.removeItem(`${this.NAMESPACE}:state`),window.localStorage.removeItem(`${this.NAMESPACE}:code_verifier`),window.localStorage.removeItem(`${this.NAMESPACE}:redirect_uri`),window.localStorage.removeItem(`${this.NAMESPACE}:login_return_uri`),Promise.resolve({status_code:204,result:null,error:null})}setStorageItem(e,t){window.localStorage.setItem(`${this.NAMESPACE}:${e}`,t)}getStorageItem(e){return window.localStorage.getItem(`${this.NAMESPACE}:${e}`)}static normalizeUrl(e){const t=new URL(e);return`${t.origin}${t.pathname}`}static buildAuthorizeUrl(e,t){return`${e}?${Object.entries(t).filter(e=>void 0!==e[1]&&null!==e[1]).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&")}`}static parseGrabUserAgent(e){if(!e||"string"!=typeof e)return null;const t=e.match(/(Grab|GrabBeta|GrabBetaDebug|GrabTaxi|GrabEarlyAccess)\/v?([0-9]+)\.([0-9]+)\.([0-9]+) \(.*(Android|iOS).*\)/i);return t?{appName:t[1],major:Number(t[2]),minor:Number(t[3]),patch:Number(t[4]),platform:t[5]}:null}static isVersionBelow(e,t){return e.major!==t.major?e.major<t.major:e.minor!==t.minor?e.minor<t.minor:e.patch<t.patch}static shouldUseWebConsent(e){const t=C.parseGrabUserAgent(window.navigator.userAgent);return!t||"staging"!==e.environment&&C.isVersionBelow(t,{major:5,minor:396,patch:0})}async performWebAuthorization(e){let t;this.setStorageItem("login_return_uri",window.location.href),this.setStorageItem("redirect_uri",e.redirectUri);try{t=await this.fetchAuthorizationEndpoint(e.environment)}catch(e){return Promise.resolve({status_code:400,error:e.message})}const r={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},n=C.buildAuthorizeUrl(t,r);return window.location.assign(n),Promise.resolve({status_code:302,result:null})}async performNativeAuthorization(e){return this.wrappedModule.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})}async authorize(e){const t=C.validateAuthorizeRequest(e);if(t)return Promise.resolve({status_code:400,error:t});const r=this.generatePKCEArtifacts(),n=e.responseMode||"redirect",o="in_place"===n?C.normalizeUrl(window.location.href):e.redirectUri;this.storePKCEArtifacts({...r,redirectUri:o});const i={clientId:e.clientId,redirectUri:e.redirectUri,scope:e.scope,nonce:r.nonce,state:r.state,codeChallenge:r.codeChallenge,codeChallengeMethod:r.codeChallengeMethod};if(C.shouldUseWebConsent(e))return this.performWebAuthorization({...i,environment:e.environment});try{const t=await this.performNativeAuthorization({...i,actualRedirectUri:o,responseMode:n});return t.error&&[400,401,403].includes(t.status_code)?(console.error(`Native authorization returned ${t.status_code}, falling back to web flow:`,t.error),this.performWebAuthorization({...i,environment:e.environment})):t}catch(t){return console.error("Native authorization failed, falling back to web flow:",t),this.performWebAuthorization({...i,environment:e.environment})}}static validateRequiredString(e,t){return e&&"string"==typeof e&&""!==e.trim()?null:`${t} is required and must be a non-empty string`}static validateAuthorizeRequest(e){if(null==e)return"request is required";const t=C.validateRequiredString(e.scope,"scope");if(t)return t;const r=C.validateRequiredString(e.clientId,"clientId");if(r)return r;const n=C.validateRequiredString(e.redirectUri,"redirectUri");if(n)return n;try{if(!new URL(e.redirectUri))return"redirectUri must be a valid URL"}catch{return"redirectUri must be a valid URL"}return C.validateRequiredString(e.environment,"environment")||("staging"!==e.environment&&"production"!==e.environment?"environment must be either 'staging' or 'production'":null)}}class S extends a{constructor(){super("ProfileModule")}static parseGrabUserAgent(e){if(!e||"string"!=typeof e)return null;const t=e.match(/(Grab|GrabBeta|GrabBetaDebug|GrabTaxi|GrabEarlyAccess)\/v?([0-9]+)\.([0-9]+)\.([0-9]+) \(.*(Android|iOS).*\)/i);return t?{appName:t[1],major:Number(t[2]),minor:Number(t[3]),patch:Number(t[4]),platform:t[5]}:null}static isVersionBelow(e,t){return e.major!==t.major?e.major<t.major:e.minor!==t.minor?e.minor<t.minor:e.patch<t.patch}static isSupported(){const e=S.parseGrabUserAgent(window.navigator.userAgent);return!!e&&!S.isVersionBelow(e,{major:5,minor:399,patch:0})}fetchEmail(){return S.isSupported()?this.wrappedModule.invoke("fetchEmail"):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}verifyEmail(e){return S.isSupported()?this.wrappedModule.invoke("verifyEmail",e):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}}class k extends a{constructor(){super("LocaleModule")}getLanguageLocaleIdentifier(){return this.wrappedModule.invoke("getLanguageLocaleIdentifier")}}class N extends a{constructor(){super("LocationModule")}getCoordinate(){return this.wrappedModule.invoke("getCoordinate")}observeLocationChange(){return this.wrappedModule.invoke("observeLocationChange")}getCountryCode(){return this.wrappedModule.invoke("getCountryCode")}}class I extends a{constructor(){super("MediaModule")}playDRMContent(e){return this.wrappedModule.invoke("playDRMContent",{data:e})}observePlayDRMContent(e){return this.wrappedModule.invoke("observePlayDRMContent",{data:e})}}class O extends a{constructor(){super("PlatformModule")}back(){return this.wrappedModule.invoke("back")}}class T extends a{constructor(){super("ScopeModule")}hasAccessTo(e,t){return this.wrappedModule.invoke("hasAccessTo",{module:e,method:t})}reloadScopes(){return this.wrappedModule.invoke("reloadScopes")}}class P extends a{constructor(){super("StorageModule")}setBoolean(e,t){return this.wrappedModule.invoke("setBoolean",{key:e,value:t})}getBoolean(e){return this.wrappedModule.invoke("getBoolean",{key:e})}setInt(e,t){return this.wrappedModule.invoke("setInt",{key:e,value:t})}getInt(e){return this.wrappedModule.invoke("getInt",{key:e})}setString(e,t){return this.wrappedModule.invoke("setString",{key:e,value:t})}getString(e){return this.wrappedModule.invoke("getString",{key:e})}setDouble(e,t){return this.wrappedModule.invoke("setDouble",{key:e,value:t})}getDouble(e){return this.wrappedModule.invoke("getDouble",{key:e})}remove(e){return this.wrappedModule.invoke("remove",{key:e})}removeAll(){return this.wrappedModule.invoke("removeAll")}}class B extends a{constructor(){super("SystemWebViewKitModule")}redirectToSystemWebView(e){return this.wrappedModule.invoke("redirectToSystemWebView",e)}}export{a as BaseModule,s as CameraModule,u as CheckoutModule,p as ContainerAnalyticsEventData,d as ContainerAnalyticsEventName,l as ContainerAnalyticsEventState,c as ContainerModule,C as IdentityModule,k as LocaleModule,N as LocationModule,I as MediaModule,O as PlatformModule,S as ProfileModule,T as ScopeModule,P as StorageModule,B as SystemWebViewKitModule};
|
package/dist/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
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 y?t:y,t=Object.create(t.prototype);return g(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;(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(s=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))!==v)break}catch(e){a=h,u=1,c=e}finally{s=1}}return{value:w,done:d}}),!0),t;function p(e,t){for(u=e,c=t,w=0;!d&&s&&!n&&w<l.length;w++){var n,r=l[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 v;throw d=!0,t}}var v={};function y(){}function o(){}function i(){}var w=Object.getPrototypeOf,e=[][t]?w(w([][t]())):(g(w={},t,function(){return this}),w),a=i.prototype=y.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]"}),(l=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 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})}),y=(v=v)&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v,v=(()=>u(function e(){a(this,e),y.wrapModule(window,"CameraModule")},[{key:"scanQRCode",value:function(){return window.WrappedCameraModule.invoke("scanQRCode",0<arguments.length&&void 0!==arguments[0]?arguments[0]:{})}}]))(),w=(()=>u(function e(){a(this,e),y.wrapModule(window,"CheckoutModule")},[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]))(),m=(()=>u(function e(){a(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"!==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||y.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",{cause:i});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})(),_=(()=>{function t(){a(this,t),window.WrappedProfileModule||y.wrapModule(window,"ProfileModule")}return u(t,[{key:"fetchEmail",value:function(){return t.isSupported()?window.WrappedProfileModule.invoke("fetchEmail"):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}},{key:"verifyEmail",value:function(e){return t.isSupported()?window.WrappedProfileModule.invoke("verifyEmail",e):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}}],[{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:"isSupported",value:function(){var e=t.parseGrabUserAgent(window.navigator.userAgent);return!!e&&!t.isVersionBelow(e,{major:5,minor:399,patch:0})}}])})(),E=(()=>u(function e(){a(this,e),y.wrapModule(window,"LocaleModule")},[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]))(),A=(()=>u(function e(){a(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")}}]))(),O=(()=>u(function e(){a(this,e),y.wrapModule(window,"MediaModule")},[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]))(),P=(()=>u(function e(){a(this,e),y.wrapModule(window,"PlatformModule")},[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]))(),I=(()=>u(function e(){a(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")}}]))(),N=(()=>u(function e(){a(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")}}]))(),T=(()=>u(function e(){a(this,e),y.wrapModule(window,"SystemWebViewKitModule")},[{key:"redirectToSystemWebView",value:function(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}]))();e.CameraModule=v,e.CheckoutModule=w,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,e.LocationModule=A,e.MediaModule=O,e.PlatformModule=P,e.ProfileModule=_,e.ScopeModule=I,e.StorageModule=N,e.SystemWebViewKitModule=T,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Grab Taxi Holdings PTE LTD (GRAB)
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SuperAppSDK={})}(this,function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var o,i={exports:{}},a=(o||(o=1,function(e){function t(e){var t=!1;return{isUnsubscribed:function(){return t},unsubscribe:function(){t||(e(),t=!0)}}}function r(e){return{subscribe:e,then:function(t,r){return new Promise(function(n,o){try{var i=null,a=!1;i=e({next:function(e){n(null==t?void 0:t(e)),i&&i.unsubscribe(),a=!0}}),a&&i&&i.unsubscribe()}catch(e){null==r?o(e):n(r(e))}})}}}function n(n,o){return o.funcNameToWrap,function(n,o){var i=o.callbackNameFunc,a=o.funcToWrap;return r(function(r){var o,s=i();return n[s]=function(t){if(function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(!e)return!1;var n=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return t.every(function(e){return 0<=n.indexOf(e)})}(t.result,"event"))t.result.event===e.StreamEvent.STREAM_TERMINATED&&o.unsubscribe();else{var n=t.result,i=t.error,a=t.status_code;r&&r.next&&r.next({result:null===n?void 0:n,error:null===i?void 0:i,status_code:null===a?void 0:a})}},a(s),o=t(function(){n[s]=void 0,r&&r.complete&&r.complete()})})}(n,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&(r[n[o]]=e[n[o]])}return r}(o,["funcNameToWrap"]))}(e.StreamEvent||(e.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",e.createDataStream=r,e.createSubscription=t,e.getModuleEnvironment=function(e,t){return e[t]?"android":e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]?"ios":void 0},e.wrapModule=function(e,t){var r;e[(r=t,"Wrapped"+r)]=function(e,t,r){return{invoke:function(o,i){return n(e,{funcNameToWrap:o,callbackNameFunc:function(){return function(e,t){var r=t.moduleName,n=t.funcName,o=0;return function(){for(var t,i,a="";(a=(t={moduleName:r,funcName:n,requestID:o}).moduleName+"_"+t.funcName+"Callback"+(null!==(i=t.requestID)?"_"+i:""))in e;)o+=1;return o+=1,a}()}(e,{moduleName:t,funcName:o})},funcToWrap:function(e){return r({callback:e,method:o,module:t,parameters:null!=i?i:{}})}})}}}(e,t,function(r){if(e[t]&&e[t][r.method]instanceof Function)e[t][r.method](JSON.stringify(r));else{if(!(e.webkit&&e.webkit.messageHandlers&&e.webkit.messageHandlers[t]))throw new Error("Unexpected method '"+r.method+"' for module '"+t+"'");e.webkit.messageHandlers[t].postMessage(r)}})},Object.defineProperty(e,"__esModule",{value:!0})}(i.exports)),i.exports);class s{get wrappedModule(){return window[`Wrapped${this.name}`]}constructor(e){if(this.name=e,!this.wrappedModule)try{a.wrapModule(window,this.name)}catch(e){throw new Error(`Failed to initialize ${this.name}: ${e.message}`)}}}var u,c,l={exports:{}},d={exports:{}},p=n(Object.freeze({__proto__:null,default:{}}));function h(){return u||(u=1,function(e){var r;e.exports=(r=r||function(e){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==t&&t.crypto&&(r=t.crypto),!r)try{r=p}catch(e){}var n=function(){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.")},o=Object.create||function(){function e(){}return function(t){var r;return e.prototype=t,r=new e,e.prototype=null,r}}(),i={},a=i.lib={},s=a.Base={extend:function(e){var t=o(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,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)}},u=a.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||l).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes,o=e.sigBytes;if(this.clamp(),n%4)for(var i=0;i<o;i++){var a=r[i>>>2]>>>24-i%4*8&255;t[n+i>>>2]|=a<<24-(n+i)%4*8}else for(var s=0;s<o;s+=4)t[n+s>>>2]=r[s>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r<e;r+=4)t.push(n());return new u.init(t,e)}}),c=i.enc={},l=c.Hex={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new u.init(r,t/2)}},d=c.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(i))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new u.init(r,t)}},h=c.Utf8={stringify:function(e){try{return decodeURIComponent(escape(d.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return d.parse(unescape(encodeURIComponent(e)))}},f=a.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r,n=this._data,o=n.words,i=n.sigBytes,a=this.blockSize,s=i/(4*a),c=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,l=e.min(4*c,i);if(c){for(var d=0;d<c;d+=a)this._doProcessBlock(o,d);r=o.splice(0,c),n.sigBytes-=l}return new u.init(r,l)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});a.Hasher=f.extend({cfg:s.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(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new g.HMAC.init(e,r).finalize(t)}}});var g=i.algo={};return i}(Math),r)}(d)),d.exports}var f,g=r((c||(c=1,function(e){var t;e.exports=(t=h(),function(e){var r=t,n=r.lib,o=n.WordArray,i=n.Hasher,a=r.algo,s=[],u=[];!function(){function t(t){for(var r=e.sqrt(t),n=2;n<=r;n++)if(!(t%n))return!1;return!0}function r(e){return 4294967296*(e-(0|e))|0}for(var n=2,o=0;o<64;)t(n)&&(o<8&&(s[o]=r(e.pow(n,.5))),u[o]=r(e.pow(n,1/3)),o++),n++}();var c=[],l=a.SHA256=i.extend({_doReset:function(){this._hash=new o.init(s.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],o=r[1],i=r[2],a=r[3],s=r[4],l=r[5],d=r[6],p=r[7],h=0;h<64;h++){if(h<16)c[h]=0|e[t+h];else{var f=c[h-15],g=(f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3,m=c[h-2],v=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;c[h]=g+c[h-7]+v+c[h-16]}var w=n&o^n&i^o&i,y=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),b=p+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&l^~s&d)+u[h]+c[h];p=d,d=l,l=s,s=a+b|0,a=i,i=o,o=n,n=b+(y+w)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+i|0,r[3]=r[3]+a|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+d|0,r[7]=r[7]+p|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,o=8*t.sigBytes;return r[o>>>5]|=128<<24-o%32,r[14+(o+64>>>9<<4)]=e.floor(n/4294967296),r[15+(o+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});r.SHA256=i._createHelper(l),r.HmacSHA256=i._createHmacHelper(l)}(Math),t.SHA256)}(l)),l.exports)),m={exports:{}},v=r((f||(f=1,function(e){var t,r,n;e.exports=(t=h(),n=(r=t).lib.WordArray,r.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp();for(var o=[],i=0;i<r;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,s=0;s<4&&i+.75*s<r;s++)o.push(n.charAt(a>>>6*(3-s)&63));var u=n.charAt(64);if(u)for(;o.length%4;)o.push(u);return o.join("")},parse:function(e){var t=e.length,r=this._map,o=this._reverseMap;if(!o){o=this._reverseMap=[];for(var i=0;i<r.length;i++)o[r.charCodeAt(i)]=i}var a=r.charAt(64);if(a){var s=e.indexOf(a);-1!==s&&(t=s)}return function(e,t,r){for(var o=[],i=0,a=0;a<t;a++)if(a%4){var s=r[e.charCodeAt(a-1)]<<a%4*2|r[e.charCodeAt(a)]>>>6-a%4*2;o[i>>>2]|=s<<24-i%4*8,i++}return n.create(o,i)}(e,t,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},t.enc.Base64)}(m)),m.exports));class w extends s{constructor(){super("IdentityModule")}get NAMESPACE(){return"grabid"}get CODE_CHALLENGE_METHOD(){return"S256"}get NONCE_LENGTH(){return 16}get STATE_LENGTH(){return 7}get CODE_VERIFIER_LENGTH(){return 64}get OPENID_CONFIG_ENDPOINTS(){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"}}async fetchAuthorizationEndpoint(e){const t=this.OPENID_CONFIG_ENDPOINTS[e];if(!t)throw new Error(`Invalid environment: ${e}. Must be 'staging' or 'production'`);try{const e=await fetch(t);if(!e.ok)throw console.error(`Failed to fetch OpenID configuration from ${t}: ${e.status} ${e.statusText}`),new Error("Failed to fetch authorization configuration");const r=await e.json();if(!r.authorization_endpoint)throw console.error("authorization_endpoint not found in OpenID configuration response"),new Error("Invalid authorization configuration");return r.authorization_endpoint}catch(e){if(console.error("Error fetching authorization endpoint:",e),"Failed to fetch authorization configuration"===e.message||"Invalid authorization configuration"===e.message)throw e;throw new Error("Something wrong happened when fetching authorization configuration",{cause:e})}}static generateRandomString(e){const t=new Uint32Array(e);crypto.getRandomValues(t);let r="";for(let n=0;n<e;n+=1)r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(t[n]%62);return r}static base64URLEncode(e){return e.toString(v).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}static generateCodeVerifier(e){return w.base64URLEncode(w.generateRandomString(e))}static generateCodeChallenge(e){return w.base64URLEncode(g(e))}generatePKCEArtifacts(){const e=w.generateRandomString(this.NONCE_LENGTH),t=w.generateRandomString(this.STATE_LENGTH),r=w.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:r,codeChallenge:w.generateCodeChallenge(r),codeChallengeMethod:this.CODE_CHALLENGE_METHOD}}storePKCEArtifacts(e){this.setStorageItem("nonce",e.nonce),this.setStorageItem("state",e.state),this.setStorageItem("code_verifier",e.codeVerifier),this.setStorageItem("redirect_uri",e.redirectUri)}async getAuthorizationArtifacts(){const e=this.getStorageItem("state"),t=this.getStorageItem("code_verifier"),r=this.getStorageItem("nonce"),n=this.getStorageItem("redirect_uri"),o=[e,t,r,n].filter(e=>null!==e).length;return 4===o?Promise.resolve({status_code:200,result:{state:e,codeVerifier:t,nonce:r,redirectUri:n},error:null}):0===o?Promise.resolve({status_code:204,result:null,error:null}):Promise.resolve({status_code:400,result:null,error:"Inconsistent authorization artifacts in storage"})}async clearAuthorizationArtifacts(){return window.localStorage.removeItem(`${this.NAMESPACE}:nonce`),window.localStorage.removeItem(`${this.NAMESPACE}:state`),window.localStorage.removeItem(`${this.NAMESPACE}:code_verifier`),window.localStorage.removeItem(`${this.NAMESPACE}:redirect_uri`),window.localStorage.removeItem(`${this.NAMESPACE}:login_return_uri`),Promise.resolve({status_code:204,result:null,error:null})}setStorageItem(e,t){window.localStorage.setItem(`${this.NAMESPACE}:${e}`,t)}getStorageItem(e){return window.localStorage.getItem(`${this.NAMESPACE}:${e}`)}static normalizeUrl(e){const t=new URL(e);return`${t.origin}${t.pathname}`}static buildAuthorizeUrl(e,t){return`${e}?${Object.entries(t).filter(e=>void 0!==e[1]&&null!==e[1]).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&")}`}static parseGrabUserAgent(e){if(!e||"string"!=typeof e)return null;const t=e.match(/(Grab|GrabBeta|GrabBetaDebug|GrabTaxi|GrabEarlyAccess)\/v?([0-9]+)\.([0-9]+)\.([0-9]+) \(.*(Android|iOS).*\)/i);return t?{appName:t[1],major:Number(t[2]),minor:Number(t[3]),patch:Number(t[4]),platform:t[5]}:null}static isVersionBelow(e,t){return e.major!==t.major?e.major<t.major:e.minor!==t.minor?e.minor<t.minor:e.patch<t.patch}static shouldUseWebConsent(e){const t=w.parseGrabUserAgent(window.navigator.userAgent);return!t||"staging"!==e.environment&&w.isVersionBelow(t,{major:5,minor:396,patch:0})}async performWebAuthorization(e){let t;this.setStorageItem("login_return_uri",window.location.href),this.setStorageItem("redirect_uri",e.redirectUri);try{t=await this.fetchAuthorizationEndpoint(e.environment)}catch(e){return Promise.resolve({status_code:400,error:e.message})}const r={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},n=w.buildAuthorizeUrl(t,r);return window.location.assign(n),Promise.resolve({status_code:302,result:null})}async performNativeAuthorization(e){return this.wrappedModule.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})}async authorize(e){const t=w.validateAuthorizeRequest(e);if(t)return Promise.resolve({status_code:400,error:t});const r=this.generatePKCEArtifacts(),n=e.responseMode||"redirect",o="in_place"===n?w.normalizeUrl(window.location.href):e.redirectUri;this.storePKCEArtifacts({...r,redirectUri:o});const i={clientId:e.clientId,redirectUri:e.redirectUri,scope:e.scope,nonce:r.nonce,state:r.state,codeChallenge:r.codeChallenge,codeChallengeMethod:r.codeChallengeMethod};if(w.shouldUseWebConsent(e))return this.performWebAuthorization({...i,environment:e.environment});try{const t=await this.performNativeAuthorization({...i,actualRedirectUri:o,responseMode:n});return t.error&&[400,401,403].includes(t.status_code)?(console.error(`Native authorization returned ${t.status_code}, falling back to web flow:`,t.error),this.performWebAuthorization({...i,environment:e.environment})):t}catch(t){return console.error("Native authorization failed, falling back to web flow:",t),this.performWebAuthorization({...i,environment:e.environment})}}static validateRequiredString(e,t){return e&&"string"==typeof e&&""!==e.trim()?null:`${t} is required and must be a non-empty string`}static validateAuthorizeRequest(e){if(null==e)return"request is required";const t=w.validateRequiredString(e.scope,"scope");if(t)return t;const r=w.validateRequiredString(e.clientId,"clientId");if(r)return r;const n=w.validateRequiredString(e.redirectUri,"redirectUri");if(n)return n;try{if(!new URL(e.redirectUri))return"redirectUri must be a valid URL"}catch{return"redirectUri must be a valid URL"}return w.validateRequiredString(e.environment,"environment")||("staging"!==e.environment&&"production"!==e.environment?"environment must be either 'staging' or 'production'":null)}}class y extends s{constructor(){super("ProfileModule")}static parseGrabUserAgent(e){if(!e||"string"!=typeof e)return null;const t=e.match(/(Grab|GrabBeta|GrabBetaDebug|GrabTaxi|GrabEarlyAccess)\/v?([0-9]+)\.([0-9]+)\.([0-9]+) \(.*(Android|iOS).*\)/i);return t?{appName:t[1],major:Number(t[2]),minor:Number(t[3]),patch:Number(t[4]),platform:t[5]}:null}static isVersionBelow(e,t){return e.major!==t.major?e.major<t.major:e.minor!==t.minor?e.minor<t.minor:e.patch<t.patch}static isSupported(){const e=y.parseGrabUserAgent(window.navigator.userAgent);return!!e&&!y.isVersionBelow(e,{major:5,minor:399,patch:0})}fetchEmail(){return y.isSupported()?this.wrappedModule.invoke("fetchEmail"):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}verifyEmail(e){return y.isSupported()?this.wrappedModule.invoke("verifyEmail",e):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}}e.BaseModule=s,e.CameraModule=class extends s{constructor(){super("CameraModule")}scanQRCode(e){return this.wrappedModule.invoke("scanQRCode",e)}},e.CheckoutModule=class extends s{constructor(){super("CheckoutModule")}triggerCheckout(e){return this.wrappedModule.invoke("triggerCheckout",e)}},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=class extends s{constructor(){super("ContainerModule")}setBackgroundColor(e){return this.wrappedModule.invoke("setBackgroundColor",{backgroundColor:e})}setTitle(e){return this.wrappedModule.invoke("setTitle",{title:e})}hideBackButton(){return this.wrappedModule.invoke("hideBackButton")}showBackButton(){return this.wrappedModule.invoke("showBackButton")}hideRefreshButton(){return this.wrappedModule.invoke("hideRefreshButton")}showRefreshButton(){return this.wrappedModule.invoke("showRefreshButton")}close(){return this.wrappedModule.invoke("close")}onContentLoaded(){return this.wrappedModule.invoke("onContentLoaded")}showLoader(){return this.wrappedModule.invoke("showLoader")}hideLoader(){return this.wrappedModule.invoke("hideLoader")}openExternalLink(e){return this.wrappedModule.invoke("openExternalLink",{url:e})}onCtaTap(e){return this.wrappedModule.invoke("onCtaTap",{action:e})}sendAnalyticsEvent(e){const t=this.validateAnalyticsEvent(e);return t?Promise.resolve({status_code:400,error:t}):this.wrappedModule.invoke("sendAnalyticsEvent",{state:e.state,name:e.name,data:e.data?JSON.stringify(e.data):null})}isConnected(){const e=window.navigator&&window.navigator.userAgent;if(!e)return Promise.resolve({status_code:404,error:"User agent not available"});const t=/grab[a-z]*\//i.test(e);return Promise.resolve(t?{status_code:200,result:{connected:!0}}:{status_code:404,error:"Not connected to Grab app"})}getSessionParams(){return this.wrappedModule.invoke("getSessionParams")}validateAnalyticsEvent(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"!=typeof e.data?"data must be undefined or an object":null}},e.IdentityModule=w,e.LocaleModule=class extends s{constructor(){super("LocaleModule")}getLanguageLocaleIdentifier(){return this.wrappedModule.invoke("getLanguageLocaleIdentifier")}},e.LocationModule=class extends s{constructor(){super("LocationModule")}getCoordinate(){return this.wrappedModule.invoke("getCoordinate")}observeLocationChange(){return this.wrappedModule.invoke("observeLocationChange")}getCountryCode(){return this.wrappedModule.invoke("getCountryCode")}},e.MediaModule=class extends s{constructor(){super("MediaModule")}playDRMContent(e){return this.wrappedModule.invoke("playDRMContent",{data:e})}observePlayDRMContent(e){return this.wrappedModule.invoke("observePlayDRMContent",{data:e})}},e.PlatformModule=class extends s{constructor(){super("PlatformModule")}back(){return this.wrappedModule.invoke("back")}},e.ProfileModule=y,e.ScopeModule=class extends s{constructor(){super("ScopeModule")}hasAccessTo(e,t){return this.wrappedModule.invoke("hasAccessTo",{module:e,method:t})}reloadScopes(){return this.wrappedModule.invoke("reloadScopes")}},e.StorageModule=class extends s{constructor(){super("StorageModule")}setBoolean(e,t){return this.wrappedModule.invoke("setBoolean",{key:e,value:t})}getBoolean(e){return this.wrappedModule.invoke("getBoolean",{key:e})}setInt(e,t){return this.wrappedModule.invoke("setInt",{key:e,value:t})}getInt(e){return this.wrappedModule.invoke("getInt",{key:e})}setString(e,t){return this.wrappedModule.invoke("setString",{key:e,value:t})}getString(e){return this.wrappedModule.invoke("getString",{key:e})}setDouble(e,t){return this.wrappedModule.invoke("setDouble",{key:e,value:t})}getDouble(e){return this.wrappedModule.invoke("getDouble",{key:e})}remove(e){return this.wrappedModule.invoke("remove",{key:e})}removeAll(){return this.wrappedModule.invoke("removeAll")}},e.SystemWebViewKitModule=class extends s{constructor(){super("SystemWebViewKitModule")}redirectToSystemWebView(e){return this.wrappedModule.invoke("redirectToSystemWebView",e)}}});
|
package/package.json
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grabjs/superapp-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.7",
|
|
4
4
|
"description": "SDK for Grab SuperApp WebView.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.esm.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": "24"
|
|
22
|
+
},
|
|
6
23
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"format
|
|
12
|
-
"lint
|
|
13
|
-
"
|
|
24
|
+
"build": "npm run build:dist && npm run build:docs",
|
|
25
|
+
"build:dist": "node scripts/build.mjs",
|
|
26
|
+
"build:docs": "typedoc",
|
|
27
|
+
"check": "npm run check:format && npm run check:lint",
|
|
28
|
+
"check:format": "prettier --check .",
|
|
29
|
+
"check:lint": "eslint .",
|
|
30
|
+
"clean": "rimraf dist build",
|
|
31
|
+
"fix": "npm run fix:format && npm run fix:lint",
|
|
32
|
+
"fix:format": "prettier --write .",
|
|
33
|
+
"fix:lint": "eslint . --fix",
|
|
14
34
|
"prepare": "husky",
|
|
15
35
|
"prepublishOnly": "npm run build",
|
|
16
36
|
"watch": "rollup -cw"
|
|
@@ -25,8 +45,7 @@
|
|
|
25
45
|
"Xijun Li <xijun.li@grabtaxi.com>"
|
|
26
46
|
],
|
|
27
47
|
"files": [
|
|
28
|
-
"dist
|
|
29
|
-
"docs"
|
|
48
|
+
"dist"
|
|
30
49
|
],
|
|
31
50
|
"keywords": [
|
|
32
51
|
"superapp",
|
|
@@ -41,27 +60,33 @@
|
|
|
41
60
|
},
|
|
42
61
|
"homepage": "https://github.com/grab/superapp-sdk#readme",
|
|
43
62
|
"dependencies": {
|
|
44
|
-
"@grabjs/mobile-kit-bridge-sdk": "^
|
|
63
|
+
"@grabjs/mobile-kit-bridge-sdk": "^2.2.2",
|
|
45
64
|
"crypto-js": "^4.2.0"
|
|
46
65
|
},
|
|
47
66
|
"devDependencies": {
|
|
48
|
-
"@babel/core": "^7.4.3",
|
|
49
|
-
"@babel/preset-env": "^7.4.3",
|
|
50
67
|
"@eslint/js": "^10.0.1",
|
|
51
68
|
"@eslint/json": "^1.0.1",
|
|
52
69
|
"@eslint/markdown": "^7.5.1",
|
|
70
|
+
"@microsoft/api-extractor": "^7.57.6",
|
|
71
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
72
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
73
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
74
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
75
|
+
"@types/node": "@types/node@^24",
|
|
53
76
|
"eslint": "^10.0.2",
|
|
54
77
|
"globals": "^17.4.0",
|
|
55
78
|
"husky": "^9.1.7",
|
|
56
79
|
"lint-staged": "^16.3.1",
|
|
57
80
|
"prettier": "3.8.1",
|
|
58
|
-
"
|
|
59
|
-
"rollup
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
81
|
+
"rimraf": "^6.1.3",
|
|
82
|
+
"rollup": "^4.59.0",
|
|
83
|
+
"tslib": "^2.8.1",
|
|
84
|
+
"typedoc": "^0.28.17",
|
|
85
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
86
|
+
"typescript": "^5.9.3"
|
|
63
87
|
},
|
|
64
88
|
"lint-staged": {
|
|
65
|
-
"**/*": "prettier --write --ignore-unknown"
|
|
89
|
+
"**/*": "prettier --write --ignore-unknown",
|
|
90
|
+
"*.{js,ts,mjs}": "eslint --fix"
|
|
66
91
|
}
|
|
67
92
|
}
|
package/docs/CameraModule.md
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# CameraModule
|
|
2
|
-
|
|
3
|
-
The CameraModule provides functionality to open the device camera for QR code scanning and retrieve the scan results.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
import { CameraModule } from '@grab/superapp-sdk';
|
|
9
|
-
|
|
10
|
-
const cameraModule = new CameraModule();
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Methods
|
|
14
|
-
|
|
15
|
-
### `scanQRCode(config)`
|
|
16
|
-
|
|
17
|
-
Opens the camera to scan QR codes with optional configuration.
|
|
18
|
-
|
|
19
|
-
**Parameters:**
|
|
20
|
-
- `config` (Object, optional): Configuration object for QR code scanning
|
|
21
|
-
- `title` (string, optional): Title to display in camera view
|
|
22
|
-
|
|
23
|
-
**Returns:** `Object` (QR code result object)
|
|
24
|
-
|
|
25
|
-
**Example:**
|
|
26
|
-
```javascript
|
|
27
|
-
cameraModule.scanQRCode({ title: 'Scan Payment QR' })
|
|
28
|
-
.then((response) => {
|
|
29
|
-
switch (response.status_code) {
|
|
30
|
-
case 200:
|
|
31
|
-
// Success - QR code scanned
|
|
32
|
-
console.log('QR Code scanned:', response.result.qrCode);
|
|
33
|
-
break;
|
|
34
|
-
case 204:
|
|
35
|
-
// No result - user cancelled
|
|
36
|
-
console.log('No result - user cancelled');
|
|
37
|
-
break;
|
|
38
|
-
case 403:
|
|
39
|
-
// Permission denied
|
|
40
|
-
console.log('Camera access denied:', response.error);
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
// Handle other potential status codes
|
|
44
|
-
console.log('Error:', response.error);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Response Format
|
|
50
|
-
|
|
51
|
-
The camera method returns an object with different structures based on the result:
|
|
52
|
-
|
|
53
|
-
### Success Response (Status Code 200)
|
|
54
|
-
```javascript
|
|
55
|
-
{
|
|
56
|
-
"status_code": 200,
|
|
57
|
-
"result": {
|
|
58
|
-
"qrCode": "scanned_qr_code_string" // The QR code content
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### No Result Response (Status Code 204)
|
|
64
|
-
```javascript
|
|
65
|
-
{
|
|
66
|
-
"status_code": 204
|
|
67
|
-
// No result property
|
|
68
|
-
// No error property
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Error Response (Status Code 403)
|
|
73
|
-
```javascript
|
|
74
|
-
{
|
|
75
|
-
"status_code": 403,
|
|
76
|
-
"error": "Camera access denied"
|
|
77
|
-
// No result property
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Status Codes
|
|
82
|
-
|
|
83
|
-
- `200`: Successfully scanned a QR code
|
|
84
|
-
- `204`: No result (user cancelled)
|
|
85
|
-
- `403`: Camera access denied
|
|
86
|
-
|
|
87
|
-
## Notes
|
|
88
|
-
|
|
89
|
-
Camera permissions and lifecycle (opening/closing) are handled automatically by the native iOS app, so no additional management is required from the JavaScript side.
|
package/docs/CheckoutModule.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# CheckoutModule
|
|
2
|
-
|
|
3
|
-
## Description
|
|
4
|
-
|
|
5
|
-
Provides APIs to trigger native checkout flow from web.
|
|
6
|
-
|
|
7
|
-
## Methods
|
|
8
|
-
|
|
9
|
-
### Trigger Checkout
|
|
10
|
-
|
|
11
|
-
**Method name**: `triggerCheckout`
|
|
12
|
-
|
|
13
|
-
**Arguments**
|
|
14
|
-
|
|
15
|
-
| Name | Type | Description |
|
|
16
|
-
| -------------- | ------ | -------------------------------------------------------------------------- |
|
|
17
|
-
| responseParams | String | The response params that partners get when charge init endpoint is called |
|
|
18
|
-
|
|
19
|
-
**Return type**
|
|
20
|
-
|
|
21
|
-
| Name | Type | Description |
|
|
22
|
-
| ------------- | ------ | ----------------------------------------------------- |
|
|
23
|
-
| transactionID | String | Unique identifier for the transaction at Grab side |
|
|
24
|
-
| status | String | Status of the transaction |
|
|
25
|
-
| errorReason | String | The reason why the transaction failed |
|
|
26
|
-
| errorCode | String | Error code associated with the failed transaction |
|
|
27
|
-
|
|
28
|
-
**Code example**
|
|
29
|
-
|
|
30
|
-
```javascript
|
|
31
|
-
import { CheckoutModule } from "@grabjs/superapp-sdk";
|
|
32
|
-
|
|
33
|
-
// Ideally, initialize this only one and reuse across app.
|
|
34
|
-
const checkoutModule = new checkoutModule();
|
|
35
|
-
|
|
36
|
-
// Get responseParams from chargeInit endpoint
|
|
37
|
-
const responseParams = chargeInit() // This is a dummy function
|
|
38
|
-
|
|
39
|
-
checkoutModule
|
|
40
|
-
.triggerCheckout(responseParams)
|
|
41
|
-
.then(({ result, error }) => {
|
|
42
|
-
if (result) {
|
|
43
|
-
// There is a valid result.
|
|
44
|
-
} else if (error) {
|
|
45
|
-
// Some error happened.
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
```
|