@grabjs/superapp-sdk 1.8.10 → 2.0.0-beta.1

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.
@@ -0,0 +1,171 @@
1
+ export declare class CameraModule {
2
+ /**
3
+ * Opens the camera to scan QR codes
4
+ * @param {Object} [config] - Configuration object for QR code scanning
5
+ * @param {string} [config.title] - Title to display in camera view
6
+ * @returns {Promise<Object>} Promise that resolves to response object with status_code:
7
+ * - 200: Success with result.qrCode containing the scanned QR code
8
+ * - 204: No result (user cancelled or no QR code detected)
9
+ * - 403: Camera access denied with error message
10
+ */
11
+ scanQRCode(config?: {
12
+ title?: string;
13
+ }): Promise<any>;
14
+ }
15
+
16
+ export declare class CheckoutModule {
17
+ triggerCheckout(checkoutDetails: any): any;
18
+ }
19
+
20
+ export declare namespace ContainerAnalyticsEventData {
21
+ let TRANSACTION_AMOUNT: string;
22
+ let TRANSACTION_CURRENCY: string;
23
+ let PAGE: string;
24
+ }
25
+
26
+ export declare namespace ContainerAnalyticsEventName {
27
+ let DEFAULT: string;
28
+ }
29
+
30
+ export declare namespace ContainerAnalyticsEventState {
31
+ let HOMEPAGE: string;
32
+ let CHECKOUT_PAGE: string;
33
+ let BOOKING_COMPLETION: string;
34
+ let CUSTOM: string;
35
+ }
36
+
37
+ export declare class ContainerModule {
38
+ setBackgroundColor(backgroundColor: any): any;
39
+ setTitle(title: any): any;
40
+ hideBackButton(): any;
41
+ showBackButton(): any;
42
+ hideRefreshButton(): any;
43
+ showRefreshButton(): any;
44
+ close(): any;
45
+ onContentLoaded(): any;
46
+ showLoader(): any;
47
+ hideLoader(): any;
48
+ openExternalLink(url: any): any;
49
+ onCtaTap(action: any): any;
50
+ sendAnalyticsEvent(eventDetails: any): any;
51
+ isConnected(): {
52
+ then: (callback: any) => any;
53
+ };
54
+ getSessionParams(): any;
55
+ _validateAnalyticsEvent(eventDetails: any): "name is required" | "name must be a string" | "state is required" | "state must be a string" | "data must be undefined or an object";
56
+ }
57
+
58
+ export declare class IdentityModule {
59
+ static generateRandomString(length: any): string;
60
+ static base64URLEncode(str: any): any;
61
+ static generateCodeVerifier(len: any): any;
62
+ static generateCodeChallenge(codeVerifier: any): any;
63
+ static normalizeUrl(urlString: any): string;
64
+ static buildAuthorizeUrl(authorizationEndpoint: any, requestMap: any): string;
65
+ static parseGrabUserAgent(userAgent: any): {
66
+ appName: string;
67
+ major: number;
68
+ minor: number;
69
+ patch: number;
70
+ platform: string;
71
+ };
72
+ static isVersionBelow(current: any, min: any): boolean;
73
+ static shouldUseWebConsent(request: any): boolean;
74
+ static performNativeAuthorization(invokeParams: any): any;
75
+ static validateRequiredString(value: any, fieldName: any): string;
76
+ static validateAuthorizeRequest(request: any): string;
77
+ get NAMESPACE(): string;
78
+ get CODE_CHALLENGE_METHOD(): string;
79
+ get NONCE_LENGTH(): number;
80
+ get STATE_LENGTH(): number;
81
+ get CODE_VERIFIER_LENGTH(): number;
82
+ get OPENID_CONFIG_ENDPOINTS(): {
83
+ staging: string;
84
+ production: string;
85
+ };
86
+ fetchAuthorizationEndpoint(environment: any): Promise<any>;
87
+ generatePKCEArtifacts(): {
88
+ nonce: string;
89
+ state: string;
90
+ codeVerifier: any;
91
+ codeChallenge: any;
92
+ codeChallengeMethod: string;
93
+ };
94
+ storePKCEArtifacts(artifacts: any): void;
95
+ getAuthorizationArtifacts(): Promise<{
96
+ status_code: number;
97
+ result: any;
98
+ error: any;
99
+ }>;
100
+ clearAuthorizationArtifacts(): Promise<{
101
+ status_code: number;
102
+ result: any;
103
+ error: any;
104
+ }>;
105
+ setStorageItem(key: any, value: any): void;
106
+ getStorageItem(key: any): string;
107
+ performWebAuthorization(params: any): Promise<{
108
+ status_code: number;
109
+ error: any;
110
+ } | {
111
+ status_code: number;
112
+ result: any;
113
+ }>;
114
+ authorize(request: any): Promise<any>;
115
+ }
116
+
117
+ export declare class LocaleModule {
118
+ getLanguageLocaleIdentifier(): any;
119
+ }
120
+
121
+ export declare class LocationModule {
122
+ getCoordinate(): any;
123
+ observeLocationChange(): any;
124
+ getCountryCode(): any;
125
+ }
126
+
127
+ export declare class MediaModule {
128
+ playDRMContent(data: any): any;
129
+ }
130
+
131
+ export declare class PlatformModule {
132
+ back(): any;
133
+ }
134
+
135
+ export declare class ProfileModule {
136
+ static parseGrabUserAgent(userAgent: any): {
137
+ appName: string;
138
+ major: number;
139
+ minor: number;
140
+ patch: number;
141
+ platform: string;
142
+ };
143
+ static isVersionBelow(current: any, min: any): boolean;
144
+ static isSupported(): boolean;
145
+ fetchEmail(): any;
146
+ verifyEmail(verifyEmailDetails: any): any;
147
+ }
148
+
149
+ export declare class ScopeModule {
150
+ hasAccessTo(module: any, method: any): any;
151
+ reloadScopes(): any;
152
+ }
153
+
154
+ export declare class StorageModule {
155
+ setBoolean(key: any, value: any): any;
156
+ getBoolean(key: any): any;
157
+ setInt(key: any, value: any): any;
158
+ getInt(key: any): any;
159
+ setString(key: any, value: any): any;
160
+ getString(key: any): any;
161
+ setDouble(key: any, value: any): any;
162
+ getDouble(key: any): any;
163
+ remove(key: any): any;
164
+ removeAll(): any;
165
+ }
166
+
167
+ export declare class SystemWebViewKitModule {
168
+ redirectToSystemWebView(payload: any): any;
169
+ }
170
+
171
+ export { }
@@ -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=t((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{constructor(){i.wrapModule(window,"CameraModule")}scanQRCode(e={}){return window.WrappedCameraModule.invoke("scanQRCode",e)}}class s{constructor(){i.wrapModule(window,"CheckoutModule")}triggerCheckout(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}const u={HOMEPAGE:"HOMEPAGE",CHECKOUT_PAGE:"CHECKOUT_PAGE",BOOKING_COMPLETION:"BOOKING_COMPLETION",CUSTOM:"CUSTOM"},c={DEFAULT:"DEFAULT"},d={TRANSACTION_AMOUNT:"transaction_amount",TRANSACTION_CURRENCY:"transaction_currency",PAGE:"page"};class l{constructor(){i.wrapModule(window,"ContainerModule")}setBackgroundColor(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}setTitle(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}hideBackButton(){return window.WrappedContainerModule.invoke("hideBackButton")}showBackButton(){return window.WrappedContainerModule.invoke("showBackButton")}hideRefreshButton(){return window.WrappedContainerModule.invoke("hideRefreshButton")}showRefreshButton(){return window.WrappedContainerModule.invoke("showRefreshButton")}close(){return window.WrappedContainerModule.invoke("close")}onContentLoaded(){return window.WrappedContainerModule.invoke("onContentLoaded")}showLoader(){return window.WrappedContainerModule.invoke("showLoader")}hideLoader(){return window.WrappedContainerModule.invoke("hideLoader")}openExternalLink(e){return window.WrappedContainerModule.invoke("openExternalLink",{url:e})}onCtaTap(e){return window.WrappedContainerModule.invoke("onCtaTap",{action:e})}sendAnalyticsEvent(e){const t=this._validateAnalyticsEvent(e);return t?{then:e=>e({status_code:400,error:t})}:window.WrappedContainerModule.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{then:e=>e({status_code:404,error:"User agent not available"})};const t=/grab[a-z]*\//i.test(e);return{then:e=>e({status_code:t?200:404,error:t?null:"Not connected to Grab app"})}}getSessionParams(){return window.WrappedContainerModule.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}}var p,f,h={exports:{}},w={exports:{}},g=r(Object.freeze({__proto__:null,default:{}}));function m(){return p||(p=1,w.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=g}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||d).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={},d=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)}},l=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(l.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return l.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=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,d=t.min(4*c,i);if(c){for(var l=0;l<c;l+=a)this._doProcessBlock(o,l);r=o.splice(0,c),n.sigBytes-=d}return new u.init(r,d)},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 h.HMAC.init(e,r).finalize(t)}}});var h=i.algo={};return i}(Math),t)),w.exports;var t}var v,y,b=t(f?h.exports:(f=1,h.exports=(v=m(),function(e){var t=v,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],d=r[5],l=r[6],p=r[7],f=0;f<64;f++){if(f<16)u[f]=0|e[t+f];else{var h=u[f-15],w=(h<<25|h>>>7)^(h<<14|h>>>18)^h>>>3,g=u[f-2],m=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;u[f]=w+u[f-7]+m+u[f-16]}var v=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&d^~c&l)+s[f]+u[f];p=l,l=d,d=c,c=a+b|0,a=i,i=o,o=n,n=b+(y+v)|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]+d|0,r[6]=r[6]+l|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),v.SHA256))),_={exports:{}},M=(y||(y=1,_.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}(m())),_.exports),C=t(M);class S{constructor(){window.WrappedIdentityModule||i.wrapModule(window,"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(C).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}static generateCodeVerifier(e){return S.base64URLEncode(S.generateRandomString(e))}static generateCodeChallenge(e){return S.base64URLEncode(b(e))}generatePKCEArtifacts(){const e=S.generateRandomString(this.NONCE_LENGTH),t=S.generateRandomString(this.STATE_LENGTH),r=S.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:r,codeChallenge:S.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=S.parseGrabUserAgent(window.navigator.userAgent);return!t||"staging"!==e.environment&&S.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=S.buildAuthorizeUrl(t,r);return window.location.assign(n),Promise.resolve({status_code:302,result:null})}static performNativeAuthorization(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})}async authorize(e){const t=S.validateAuthorizeRequest(e);if(t)return Promise.resolve({status_code:400,error:t});const r=this.generatePKCEArtifacts(),n=e.responseMode||"redirect",o="in_place"===n?S.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(S.shouldUseWebConsent(e))return this.performWebAuthorization({...i,environment:e.environment});try{const t=await S.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=S.validateRequiredString(e.scope,"scope");if(t)return t;const r=S.validateRequiredString(e.clientId,"clientId");if(r)return r;const n=S.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 S.validateRequiredString(e.environment,"environment")||("staging"!==e.environment&&"production"!==e.environment?"environment must be either 'staging' or 'production'":null)}}class E{constructor(){window.WrappedProfileModule||i.wrapModule(window,"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=E.parseGrabUserAgent(window.navigator.userAgent);return!!e&&!E.isVersionBelow(e,{major:5,minor:399,patch:0})}fetchEmail(){return E.isSupported()?window.WrappedProfileModule.invoke("fetchEmail"):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}verifyEmail(e){return E.isSupported()?window.WrappedProfileModule.invoke("verifyEmail",e):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}}class A{constructor(){i.wrapModule(window,"LocaleModule")}getLanguageLocaleIdentifier(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}class k{constructor(){i.wrapModule(window,"LocationModule")}getCoordinate(){return window.WrappedLocationModule.invoke("getCoordinate")}observeLocationChange(){return window.WrappedLocationModule.invoke("observeLocationChange")}getCountryCode(){return window.WrappedLocationModule.invoke("getCountryCode")}}class N{constructor(){i.wrapModule(window,"MediaModule")}playDRMContent(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}class I{constructor(){i.wrapModule(window,"PlatformModule")}back(){return window.WrappedPlatformModule.invoke("back")}}class O{constructor(){i.wrapModule(window,"ScopeModule")}hasAccessTo(e,t){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:t})}reloadScopes(){return window.WrappedScopeModule.invoke("reloadScopes")}}class T{constructor(){i.wrapModule(window,"StorageModule")}setBoolean(e,t){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:t})}getBoolean(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}setInt(e,t){return window.WrappedStorageModule.invoke("setInt",{key:e,value:t})}getInt(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}setString(e,t){return window.WrappedStorageModule.invoke("setString",{key:e,value:t})}getString(e){return window.WrappedStorageModule.invoke("getString",{key:e})}setDouble(e,t){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:t})}getDouble(e){return window.WrappedStorageModule.invoke("getDouble",{key:e})}remove(e){return window.WrappedStorageModule.invoke("remove",{key:e})}removeAll(){return window.WrappedStorageModule.invoke("removeAll")}}class W{constructor(){i.wrapModule(window,"SystemWebViewKitModule")}redirectToSystemWebView(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}export{a as CameraModule,s as CheckoutModule,d as ContainerAnalyticsEventData,c as ContainerAnalyticsEventName,u as ContainerAnalyticsEventState,l as ContainerModule,S as IdentityModule,A as LocaleModule,k as LocationModule,N as MediaModule,I as PlatformModule,E as ProfileModule,O as ScopeModule,T as StorageModule,W 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,a,s={exports:{}},u=(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})}(s.exports)),s.exports),c=r(u),d={exports:{}},l={exports:{}},p=n(Object.freeze({__proto__:null,default:{}}));function f(){return i||(i=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||d).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={},d=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)}},l=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)}},f=c.Utf8={stringify:function(e){try{return decodeURIComponent(escape(l.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return l.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=f.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,d=e.min(4*c,i);if(c){for(var l=0;l<c;l+=a)this._doProcessBlock(o,l);r=o.splice(0,c),n.sigBytes-=d}return new u.init(r,d)},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 g.HMAC.init(e,r).finalize(t)}}});var g=i.algo={};return i}(Math),r)}(l)),l.exports}var h,g=r((a||(a=1,function(e){var t;e.exports=(t=f(),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=[],d=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],d=r[5],l=r[6],p=r[7],f=0;f<64;f++){if(f<16)c[f]=0|e[t+f];else{var h=c[f-15],g=(h<<25|h>>>7)^(h<<14|h>>>18)^h>>>3,w=c[f-2],m=(w<<15|w>>>17)^(w<<13|w>>>19)^w>>>10;c[f]=g+c[f-7]+m+c[f-16]}var v=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&d^~s&l)+u[f]+c[f];p=l,l=d,d=s,s=a+b|0,a=i,i=o,o=n,n=b+(y+v)|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]+d|0,r[6]=r[6]+l|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(d),r.HmacSHA256=i._createHmacHelper(d)}(Math),t.SHA256)}(d)),d.exports)),w={exports:{}},m=r((h||(h=1,function(e){var t,r,n;e.exports=(t=f(),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)}(w)),w.exports));class v{constructor(){window.WrappedIdentityModule||c.wrapModule(window,"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(m).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}static generateCodeVerifier(e){return v.base64URLEncode(v.generateRandomString(e))}static generateCodeChallenge(e){return v.base64URLEncode(g(e))}generatePKCEArtifacts(){const e=v.generateRandomString(this.NONCE_LENGTH),t=v.generateRandomString(this.STATE_LENGTH),r=v.generateCodeVerifier(this.CODE_VERIFIER_LENGTH);return{nonce:e,state:t,codeVerifier:r,codeChallenge:v.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=v.parseGrabUserAgent(window.navigator.userAgent);return!t||"staging"!==e.environment&&v.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=v.buildAuthorizeUrl(t,r);return window.location.assign(n),Promise.resolve({status_code:302,result:null})}static performNativeAuthorization(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})}async authorize(e){const t=v.validateAuthorizeRequest(e);if(t)return Promise.resolve({status_code:400,error:t});const r=this.generatePKCEArtifacts(),n=e.responseMode||"redirect",o="in_place"===n?v.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(v.shouldUseWebConsent(e))return this.performWebAuthorization({...i,environment:e.environment});try{const t=await v.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=v.validateRequiredString(e.scope,"scope");if(t)return t;const r=v.validateRequiredString(e.clientId,"clientId");if(r)return r;const n=v.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 v.validateRequiredString(e.environment,"environment")||("staging"!==e.environment&&"production"!==e.environment?"environment must be either 'staging' or 'production'":null)}}class y{constructor(){window.WrappedProfileModule||c.wrapModule(window,"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()?window.WrappedProfileModule.invoke("fetchEmail"):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}verifyEmail(e){return y.isSupported()?window.WrappedProfileModule.invoke("verifyEmail",e):Promise.resolve({status_code:403,error:"This feature requires Grab app version 5.399 or above."})}}e.CameraModule=class{constructor(){c.wrapModule(window,"CameraModule")}scanQRCode(e={}){return window.WrappedCameraModule.invoke("scanQRCode",e)}},e.CheckoutModule=class{constructor(){c.wrapModule(window,"CheckoutModule")}triggerCheckout(e){return window.WrappedCheckoutModule.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{constructor(){c.wrapModule(window,"ContainerModule")}setBackgroundColor(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}setTitle(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}hideBackButton(){return window.WrappedContainerModule.invoke("hideBackButton")}showBackButton(){return window.WrappedContainerModule.invoke("showBackButton")}hideRefreshButton(){return window.WrappedContainerModule.invoke("hideRefreshButton")}showRefreshButton(){return window.WrappedContainerModule.invoke("showRefreshButton")}close(){return window.WrappedContainerModule.invoke("close")}onContentLoaded(){return window.WrappedContainerModule.invoke("onContentLoaded")}showLoader(){return window.WrappedContainerModule.invoke("showLoader")}hideLoader(){return window.WrappedContainerModule.invoke("hideLoader")}openExternalLink(e){return window.WrappedContainerModule.invoke("openExternalLink",{url:e})}onCtaTap(e){return window.WrappedContainerModule.invoke("onCtaTap",{action:e})}sendAnalyticsEvent(e){const t=this._validateAnalyticsEvent(e);return t?{then:e=>e({status_code:400,error:t})}:window.WrappedContainerModule.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{then:e=>e({status_code:404,error:"User agent not available"})};const t=/grab[a-z]*\//i.test(e);return{then:e=>e({status_code:t?200:404,error:t?null:"Not connected to Grab app"})}}getSessionParams(){return window.WrappedContainerModule.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=v,e.LocaleModule=class{constructor(){c.wrapModule(window,"LocaleModule")}getLanguageLocaleIdentifier(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}},e.LocationModule=class{constructor(){c.wrapModule(window,"LocationModule")}getCoordinate(){return window.WrappedLocationModule.invoke("getCoordinate")}observeLocationChange(){return window.WrappedLocationModule.invoke("observeLocationChange")}getCountryCode(){return window.WrappedLocationModule.invoke("getCountryCode")}},e.MediaModule=class{constructor(){c.wrapModule(window,"MediaModule")}playDRMContent(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}},e.PlatformModule=class{constructor(){c.wrapModule(window,"PlatformModule")}back(){return window.WrappedPlatformModule.invoke("back")}},e.ProfileModule=y,e.ScopeModule=class{constructor(){c.wrapModule(window,"ScopeModule")}hasAccessTo(e,t){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:t})}reloadScopes(){return window.WrappedScopeModule.invoke("reloadScopes")}},e.StorageModule=class{constructor(){c.wrapModule(window,"StorageModule")}setBoolean(e,t){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:t})}getBoolean(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}setInt(e,t){return window.WrappedStorageModule.invoke("setInt",{key:e,value:t})}getInt(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}setString(e,t){return window.WrappedStorageModule.invoke("setString",{key:e,value:t})}getString(e){return window.WrappedStorageModule.invoke("getString",{key:e})}setDouble(e,t){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:t})}getDouble(e){return window.WrappedStorageModule.invoke("getDouble",{key:e})}remove(e){return window.WrappedStorageModule.invoke("remove",{key:e})}removeAll(){return window.WrappedStorageModule.invoke("removeAll")}},e.SystemWebViewKitModule=class{constructor(){c.wrapModule(window,"SystemWebViewKitModule")}redirectToSystemWebView(e){return window.WrappedSystemWebViewKitModule.invoke("redirectToSystemWebView",e)}}});
package/package.json CHANGED
@@ -1,11 +1,29 @@
1
1
  {
2
2
  "name": "@grabjs/superapp-sdk",
3
- "version": "1.8.10",
3
+ "version": "2.0.0-beta.1",
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": "rm -rf dist && rollup -c",
24
+ "build": "node scripts/build.mjs",
8
25
  "check": "npm run format:check && npm run lint:check",
26
+ "clean": "rimraf dist build",
9
27
  "fix": "npm run format:fix && npm run lint:fix",
10
28
  "format:check": "prettier --check .",
11
29
  "format:fix": "prettier --write .",
@@ -25,8 +43,7 @@
25
43
  "Xijun Li <xijun.li@grabtaxi.com>"
26
44
  ],
27
45
  "files": [
28
- "dist/index.js",
29
- "docs"
46
+ "dist"
30
47
  ],
31
48
  "keywords": [
32
49
  "superapp",
@@ -41,25 +58,28 @@
41
58
  },
42
59
  "homepage": "https://github.com/grab/superapp-sdk#readme",
43
60
  "dependencies": {
44
- "@grabjs/mobile-kit-bridge-sdk": "^1.1.1",
61
+ "@grabjs/mobile-kit-bridge-sdk": "^2.2.2",
45
62
  "crypto-js": "^4.2.0"
46
63
  },
47
64
  "devDependencies": {
48
- "@babel/core": "^7.4.3",
49
- "@babel/preset-env": "^7.4.3",
50
65
  "@eslint/js": "^10.0.1",
51
66
  "@eslint/json": "^1.0.1",
52
67
  "@eslint/markdown": "^7.5.1",
68
+ "@microsoft/api-extractor": "^7.57.6",
69
+ "@rollup/plugin-commonjs": "^29.0.0",
70
+ "@rollup/plugin-node-resolve": "^16.0.3",
71
+ "@rollup/plugin-terser": "^0.4.4",
72
+ "@rollup/plugin-typescript": "^12.3.0",
73
+ "@types/node": "@types/node@^24",
53
74
  "eslint": "^10.0.2",
54
75
  "globals": "^17.4.0",
55
76
  "husky": "^9.1.7",
56
77
  "lint-staged": "^16.3.1",
57
78
  "prettier": "3.8.1",
58
- "rollup": "^1.7.0",
59
- "rollup-plugin-babel": "^4.3.2",
60
- "rollup-plugin-commonjs": "^9.3.4",
61
- "rollup-plugin-node-resolve": "^4.2.2",
62
- "rollup-plugin-uglify": "^6.0.2"
79
+ "rimraf": "^6.1.3",
80
+ "rollup": "^4.59.0",
81
+ "tslib": "^2.8.1",
82
+ "typescript": "^5.9.3"
63
83
  },
64
84
  "lint-staged": {
65
85
  "**/*": "prettier --write --ignore-unknown"
@@ -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.
@@ -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
- ```