@grabjs/superapp-sdk 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/index.js +1 -1
- package/docs/CheckoutModule.md +51 -0
- package/docs/ContainerModule.md +245 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,13 +49,12 @@ Each resonse from the native bridge follows the same structure described bellow.
|
|
|
49
49
|
| 500 | Internal Error | Unexpected internal error (e.g. failed to serialize response object) |
|
|
50
50
|
|
|
51
51
|
### Success response example
|
|
52
|
-
|
|
53
52
|
```json
|
|
54
53
|
{
|
|
55
54
|
"status_code": 200,
|
|
56
55
|
"result": {
|
|
57
|
-
"latitude": 1.
|
|
58
|
-
"longitude": 1.
|
|
56
|
+
"latitude": 1.234567,
|
|
57
|
+
"longitude": -1.234567
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
```
|
|
@@ -68,3 +67,6 @@ Each resonse from the native bridge follows the same structure described bellow.
|
|
|
68
67
|
"error": "Client doesn't have access to method \"getLocation\" in module \"LocationModule\""
|
|
69
68
|
}
|
|
70
69
|
```
|
|
70
|
+
---
|
|
71
|
+
* **GDMCOMMENT:** Latitudes and longitudes used in this file are either sourced from GrabPlaces, GrabMaps, OSM or randomly created by the developer and are not obtained from other external sources.
|
|
72
|
+
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function n(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(e,n){for(var o=0;o<n.length;o++){var t=n[o];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function o(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,u,i=(function(e,n){function a(e){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];if(!e)return!1;var t=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return n.every(function(e){return 0<=t.indexOf(e)})}function
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).SuperAppSDK={})}(this,function(e){"use strict";function n(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(e,n){for(var o=0;o<n.length;o++){var t=n[o];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function o(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,u,i=(function(e,n){function a(e){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];if(!e)return!1;var t=function(e){return Object.keys(e).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(e)))}(e);return n.every(function(e){return 0<=t.indexOf(e)})}function d(r,e){var u=e.callbackNameFunc,i=e.funcToWrap;return function(e){return{subscribe:e,then:function(t,r){return new Promise(function(){try{var n=null,o=!1;n=e({next:function(e){t&&t(e),n&&n.unsubscribe(),o=!0}}),o&&n&&n.unsubscribe()}catch(e){r&&r(e)}})}}}(function(o){var n,t=u();return r[t]=function(e){if(a(e,"status_code"))if(a(e.result,"event"))switch(e.result.event){case l.StreamEvent.STREAM_TERMINATED:n.unsubscribe()}else o&&o.next&&o.next(e)},i(t),n=function(e){var n=!1;return{isUnsubscribed:function(){return n},unsubscribe:function(){n||(delete r[t],o&&o.complete&&o.complete(),n=!0)}}}()})}var l;((l=n).StreamEvent||(l.StreamEvent={})).STREAM_TERMINATED="STREAM_TERMINATED",l.wrapModule=function(u,i){u[function(e){return"Wrapped"+e}(i)]=function(e,t,n){var r={};return{invoke:function(n,o){return function(e,n){return n.funcNameToWrap,d(e,function(e,n){var o={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(o[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&(o[t[r]]=e[t[r]])}return o}(n,["funcNameToWrap"]))}(e,{funcNameToWrap:n,callbackNameFunc:function(){var e=r[n]||0;return r[n]=e+1,function(e){var n=e.moduleName,o=e.funcName,t=e.requestID;return n+"_"+o+"Callback"+(null!==t?"_"+t:"")}({moduleName:t,requestID:e,funcName:n})},funcToWrap:function(e){return function(e){if(u[i])u[i][e.method](JSON.stringify(e));else{if(!(u.webkit&&u.webkit.messageHandlers&&u.webkit.messageHandlers[i]))throw new Error("Unexpected method '"+e.method+"' for module '"+i+"'");u.webkit.messageHandlers[i].postMessage(e)}}({callback:e,method:n,module:t,parameters:null!=o?o:{}})}})}}}(u,i)},Object.defineProperty(l,"__esModule",{value:!0})}(r={exports:{}},r.exports),r.exports),a=(u=i)&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u,d=function(){function e(){n(this,e),a.wrapModule(window,"CheckoutModule")}return o(e,[{key:"triggerCheckout",value:function(e){return window.WrappedCheckoutModule.invoke("triggerCheckout",e)}}]),e}(),l=require("@grabjs/mobile-kit-bridge-sdk"),c=function(){function e(){n(this,e),l.wrapModule(window,"ContainerModule")}return o(e,[{key:"setBackgroundColor",value:function(e){return window.WrappedContainerModule.invoke("setBackgroundColor",{backgroundColor:e})}},{key:"setTitle",value:function(e){return window.WrappedContainerModule.invoke("setTitle",{title:e})}},{key:"hideBackButton",value:function(){return window.WrappedContainerModule.invoke("hideBackButton",{})}},{key:"showBackButton",value:function(){return window.WrappedContainerModule.invoke("showBackButton",{})}},{key:"hideRefreshButton",value:function(){return window.WrappedContainerModule.invoke("hideRefreshButton",{})}},{key:"showRefreshButton",value:function(){return window.WrappedContainerModule.invoke("showRefreshButton",{})}},{key:"hideLoader",value:function(){return window.WrappedContainerModule.invoke("hideLoader",{})}},{key:"close",value:function(){return window.WrappedContainerModule.invoke("close",{})}}]),e}(),f=function(){function e(){n(this,e),a.wrapModule(window,"LocaleModule")}return o(e,[{key:"getLanguageLocaleIdentifier",value:function(){return window.WrappedLocaleModule.invoke("getLanguageLocaleIdentifier")}}]),e}(),p=function(){function e(){n(this,e),a.wrapModule(window,"LocationModule")}return o(e,[{key:"getCoordinate",value:function(){return window.WrappedLocationModule.invoke("getCoordinate")}},{key:"observeLocationChange",value:function(){return window.WrappedLocationModule.invoke("observeLocationChange")}}]),e}(),s=function(){function e(){n(this,e),a.wrapModule(window,"MediaModule")}return o(e,[{key:"playDRMContent",value:function(e){return window.WrappedMediaModule.invoke("playDRMContent",{data:e})}}]),e}(),w=require("@grabjs/mobile-kit-bridge-sdk"),k=function(){function e(){n(this,e),w.wrapModule(window,"PlatformModule")}return o(e,[{key:"back",value:function(){return window.WrappedPlatformModule.invoke("back")}}]),e}(),v=function(){function e(){n(this,e),a.wrapModule(window,"ScopeModule")}return o(e,[{key:"hasAccessTo",value:function(e,n){return window.WrappedScopeModule.invoke("hasAccessTo",{module:e,method:n})}},{key:"reloadScopes",value:function(){return window.WrappedScopeModule.invoke("reloadScopes")}}]),e}(),M=require("@grabjs/mobile-kit-bridge-sdk"),y=function(){function e(){n(this,e),M.wrapModule(window,"StorageModule")}return o(e,[{key:"setBoolean",value:function(e,n){return window.WrappedStorageModule.invoke("setBoolean",{key:e,value:n})}},{key:"getBoolean",value:function(e){return window.WrappedStorageModule.invoke("getBoolean",{key:e})}},{key:"setInt",value:function(e,n){return window.WrappedStorageModule.invoke("setInt",{key:e,value:n})}},{key:"getInt",value:function(e){return window.WrappedStorageModule.invoke("getInt",{key:e})}},{key:"setString",value:function(e,n){return window.WrappedStorageModule.invoke("setString",{key:e,value:n})}},{key:"getString",value:function(e){return window.WrappedStorageModule.invoke("getString",{key:e})}},{key:"setDouble",value:function(e,n){return window.WrappedStorageModule.invoke("setDouble",{key:e,value:n})}},{key:"getDouble",value:function(e){return window.WrappedStorageModule.invoke("getDouble",{key:e})}},{key:"remove",value:function(e){return window.WrappedStorageModule.invoke("remove",{key:e})}},{key:"removeAll",value:function(){return window.WrappedStorageModule.invoke("removeAll")}}]),e}();e.CheckoutModule=d,e.ContainerModule=c,e.LocaleModule=f,e.LocationModule=p,e.MediaModule=s,e.PlatformModule=k,e.ScopeModule=v,e.StorageModule=y,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
| channel | String | The channel of triggering the transaction. In this case, it is `MiniApp` |
|
|
19
|
+
|
|
20
|
+
**Return type**
|
|
21
|
+
|
|
22
|
+
| Name | Type | Description |
|
|
23
|
+
| ------------- | ------ | ----------------------------------------------------- |
|
|
24
|
+
| transactionID | String | Unique identifier for the transaction at Grab side |
|
|
25
|
+
| status | String | Status of the transaction |
|
|
26
|
+
| errorReason | String | The reason why the transaction failed |
|
|
27
|
+
| errorCode | String | Error code associated with the failed transaction |
|
|
28
|
+
|
|
29
|
+
**Code example**
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { CheckoutModule } from "@grabjs/superapp-sdk";
|
|
33
|
+
|
|
34
|
+
// Ideally, initialize this only one and reuse across app.
|
|
35
|
+
const checkoutModule = new checkoutModule();
|
|
36
|
+
|
|
37
|
+
// Get responseParams from chargeInit endpoint
|
|
38
|
+
const responseParams = chargeInit() // This is a dummy function
|
|
39
|
+
|
|
40
|
+
const channel = "MiniApp"
|
|
41
|
+
|
|
42
|
+
checkoutModule
|
|
43
|
+
.triggerCheckout({ responseParams, channel })
|
|
44
|
+
.then(({ result, error }) => {
|
|
45
|
+
if (result) {
|
|
46
|
+
// There is a valid result.
|
|
47
|
+
} else if (error) {
|
|
48
|
+
// Some error happened.
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
```
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# ContainerModule
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Provides APIs to interract with the webview container.
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
### 1. Set background color
|
|
10
|
+
|
|
11
|
+
**Method name**: `setBackgroundColor`
|
|
12
|
+
|
|
13
|
+
**Arguments**
|
|
14
|
+
|
|
15
|
+
| Name | Type | Description |
|
|
16
|
+
| --------------- | ------ | ----------------------- |
|
|
17
|
+
| backgroundColor | String | Hexadecimal color value |
|
|
18
|
+
|
|
19
|
+
**Return type**
|
|
20
|
+
|
|
21
|
+
`None`
|
|
22
|
+
|
|
23
|
+
**Code example**
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
27
|
+
|
|
28
|
+
// Ideally, initialize this only one and reuse across app.
|
|
29
|
+
const containerModule = new ContainerModule();
|
|
30
|
+
|
|
31
|
+
containerModule
|
|
32
|
+
.setBackgroundColor("#ffffff")
|
|
33
|
+
.then(({ result, error }) => {
|
|
34
|
+
if (result) {
|
|
35
|
+
// There is a valid result.
|
|
36
|
+
} else if (error) {
|
|
37
|
+
// Some error happened.
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Set title
|
|
43
|
+
|
|
44
|
+
**Method name**: `setTitle`
|
|
45
|
+
|
|
46
|
+
**Arguments**
|
|
47
|
+
|
|
48
|
+
| Name | Type | Description |
|
|
49
|
+
| ----- | ------ | ----------------- |
|
|
50
|
+
| title | String | Title of the page |
|
|
51
|
+
|
|
52
|
+
**Return type**
|
|
53
|
+
|
|
54
|
+
`None`
|
|
55
|
+
|
|
56
|
+
**Code example**
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
60
|
+
|
|
61
|
+
// Ideally, initialize this only one and reuse across app.
|
|
62
|
+
const containerModule = new ContainerModule();
|
|
63
|
+
|
|
64
|
+
containerModule.setTitle("Home").then(({ result, error }) => {
|
|
65
|
+
if (result) {
|
|
66
|
+
// There is a valid result.
|
|
67
|
+
} else if (error) {
|
|
68
|
+
// Some error happened.
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. Hide back button
|
|
74
|
+
|
|
75
|
+
**Method name**: `hideBackButton`
|
|
76
|
+
|
|
77
|
+
**Arguments**
|
|
78
|
+
|
|
79
|
+
`None`
|
|
80
|
+
|
|
81
|
+
**Return type**
|
|
82
|
+
|
|
83
|
+
`None`
|
|
84
|
+
|
|
85
|
+
**Code example**
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
89
|
+
|
|
90
|
+
// Ideally, initialize this only one and reuse across app.
|
|
91
|
+
const containerModule = new ContainerModule();
|
|
92
|
+
|
|
93
|
+
containerModule.hideBackButton().then(({ result, error }) => {
|
|
94
|
+
if (result) {
|
|
95
|
+
// There is a valid result.
|
|
96
|
+
} else if (error) {
|
|
97
|
+
// Some error happened.
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 4. Show back button
|
|
103
|
+
|
|
104
|
+
**Method name**: `showBackButton`
|
|
105
|
+
|
|
106
|
+
**Arguments**
|
|
107
|
+
|
|
108
|
+
`None`
|
|
109
|
+
|
|
110
|
+
**Return type**
|
|
111
|
+
|
|
112
|
+
`None`
|
|
113
|
+
|
|
114
|
+
**Code example**
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
118
|
+
|
|
119
|
+
// Ideally, initialize this only one and reuse across app.
|
|
120
|
+
const containerModule = new ContainerModule();
|
|
121
|
+
|
|
122
|
+
containerModule.showBackButton().then(({ result, error }) => {
|
|
123
|
+
if (result) {
|
|
124
|
+
// There is a valid result.
|
|
125
|
+
} else if (error) {
|
|
126
|
+
// Some error happened.
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 5. Hide refresh button
|
|
132
|
+
|
|
133
|
+
**Method name**: `hideRefreshButton`
|
|
134
|
+
|
|
135
|
+
**Arguments**
|
|
136
|
+
|
|
137
|
+
`None`
|
|
138
|
+
|
|
139
|
+
**Return type**
|
|
140
|
+
|
|
141
|
+
`None`
|
|
142
|
+
|
|
143
|
+
**Code example**
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
147
|
+
|
|
148
|
+
// Ideally, initialize this only one and reuse across app.
|
|
149
|
+
const containerModule = new ContainerModule();
|
|
150
|
+
|
|
151
|
+
containerModule.hideRefreshButton().then(({ result, error }) => {
|
|
152
|
+
if (result) {
|
|
153
|
+
// There is a valid result.
|
|
154
|
+
} else if (error) {
|
|
155
|
+
// Some error happened.
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 6. Show refresh button
|
|
161
|
+
|
|
162
|
+
**Method name**: `showRefreshButton`
|
|
163
|
+
|
|
164
|
+
**Arguments**
|
|
165
|
+
|
|
166
|
+
`None`
|
|
167
|
+
|
|
168
|
+
**Return type**
|
|
169
|
+
|
|
170
|
+
`None`
|
|
171
|
+
|
|
172
|
+
**Code example**
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
176
|
+
|
|
177
|
+
// Ideally, initialize this only one and reuse across app.
|
|
178
|
+
const containerModule = new ContainerModule();
|
|
179
|
+
|
|
180
|
+
containerModule.showRefreshButton().then(({ result, error }) => {
|
|
181
|
+
if (result) {
|
|
182
|
+
// There is a valid result.
|
|
183
|
+
} else if (error) {
|
|
184
|
+
// Some error happened.
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 7. Hide loader
|
|
190
|
+
|
|
191
|
+
**Method name**: `hideLoader`
|
|
192
|
+
|
|
193
|
+
**Arguments**
|
|
194
|
+
|
|
195
|
+
`None`
|
|
196
|
+
|
|
197
|
+
**Return type**
|
|
198
|
+
|
|
199
|
+
`None`
|
|
200
|
+
|
|
201
|
+
**Code example**
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
205
|
+
|
|
206
|
+
// Ideally, initialize this only one and reuse across app.
|
|
207
|
+
const containerModule = new ContainerModule();
|
|
208
|
+
|
|
209
|
+
containerModule.hideLoader().then(({ result, error }) => {
|
|
210
|
+
if (result) {
|
|
211
|
+
// There is a valid result.
|
|
212
|
+
} else if (error) {
|
|
213
|
+
// Some error happened.
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 8. Close
|
|
219
|
+
|
|
220
|
+
**Method name**: `close`
|
|
221
|
+
|
|
222
|
+
**Arguments**
|
|
223
|
+
|
|
224
|
+
`None`
|
|
225
|
+
|
|
226
|
+
**Return type**
|
|
227
|
+
|
|
228
|
+
`None`
|
|
229
|
+
|
|
230
|
+
**Code example**
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
234
|
+
|
|
235
|
+
// Ideally, initialize this only one and reuse across app.
|
|
236
|
+
const containerModule = new ContainerModule();
|
|
237
|
+
|
|
238
|
+
containerModule.close().then(({ result, error }) => {
|
|
239
|
+
if (result) {
|
|
240
|
+
// There is a valid result.
|
|
241
|
+
} else if (error) {
|
|
242
|
+
// Some error happened.
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
```
|