@grabjs/superapp-sdk 1.6.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/dist/index.js +1 -1
- package/docs/CheckoutModule.md +51 -0
- package/docs/ContainerModule.md +155 -12
- package/package.json +1 -1
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}
|
|
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
|
+
```
|
package/docs/ContainerModule.md
CHANGED
|
@@ -6,9 +6,9 @@ Provides APIs to interract with the webview container.
|
|
|
6
6
|
|
|
7
7
|
## Methods
|
|
8
8
|
|
|
9
|
-
### 1. Set
|
|
9
|
+
### 1. Set background color
|
|
10
10
|
|
|
11
|
-
**Method name**: `
|
|
11
|
+
**Method name**: `setBackgroundColor`
|
|
12
12
|
|
|
13
13
|
**Arguments**
|
|
14
14
|
|
|
@@ -29,7 +29,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
|
29
29
|
const containerModule = new ContainerModule();
|
|
30
30
|
|
|
31
31
|
containerModule
|
|
32
|
-
.
|
|
32
|
+
.setBackgroundColor("#ffffff")
|
|
33
33
|
.then(({ result, error }) => {
|
|
34
34
|
if (result) {
|
|
35
35
|
// There is a valid result.
|
|
@@ -39,9 +39,9 @@ containerModule
|
|
|
39
39
|
});
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
### 2. Set
|
|
42
|
+
### 2. Set title
|
|
43
43
|
|
|
44
|
-
**Method name**: `
|
|
44
|
+
**Method name**: `setTitle`
|
|
45
45
|
|
|
46
46
|
**Arguments**
|
|
47
47
|
|
|
@@ -61,7 +61,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
|
61
61
|
// Ideally, initialize this only one and reuse across app.
|
|
62
62
|
const containerModule = new ContainerModule();
|
|
63
63
|
|
|
64
|
-
containerModule.
|
|
64
|
+
containerModule.setTitle("Home").then(({ result, error }) => {
|
|
65
65
|
if (result) {
|
|
66
66
|
// There is a valid result.
|
|
67
67
|
} else if (error) {
|
|
@@ -70,15 +70,158 @@ containerModule.setHeaderTitle("Home").then(({ result, error }) => {
|
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### 3.
|
|
73
|
+
### 3. Hide back button
|
|
74
74
|
|
|
75
|
-
**Method name**: `
|
|
75
|
+
**Method name**: `hideBackButton`
|
|
76
76
|
|
|
77
77
|
**Arguments**
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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`
|
|
82
225
|
|
|
83
226
|
**Return type**
|
|
84
227
|
|
|
@@ -92,7 +235,7 @@ import { ContainerModule } from "@grabjs/superapp-sdk";
|
|
|
92
235
|
// Ideally, initialize this only one and reuse across app.
|
|
93
236
|
const containerModule = new ContainerModule();
|
|
94
237
|
|
|
95
|
-
containerModule.
|
|
238
|
+
containerModule.close().then(({ result, error }) => {
|
|
96
239
|
if (result) {
|
|
97
240
|
// There is a valid result.
|
|
98
241
|
} else if (error) {
|