@appboxo/capacitor-boxo-sdk 0.0.2
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/CapacitorBoxoSdk.podspec +18 -0
- package/Package.swift +28 -0
- package/README.md +240 -0
- package/android/build.gradle +84 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/boxo/sdk/capacitor/AppboxoPlugin.kt +322 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +485 -0
- package/dist/esm/definitions.d.ts +156 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +10 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/AppboxoPlugin/AppboxoPlugin.swift +293 -0
- package/ios/Tests/AppboxoPluginTests/AppboxoPluginTests.swift +15 -0
- package/package.json +80 -0
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var capacitorAppboxo = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Appboxo = core.registerPlugin('Appboxo');
|
|
5
|
+
|
|
6
|
+
exports.Appboxo = Appboxo;
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
return exports;
|
|
11
|
+
|
|
12
|
+
})({}, capacitorExports);
|
|
13
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Appboxo = registerPlugin('Appboxo');\nexport * from './definitions';\nexport { Appboxo };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;AACK,OAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import AppBoxoSDK
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
8
|
+
*/
|
|
9
|
+
@objc(AppboxoPlugin)
|
|
10
|
+
public class AppboxoPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
11
|
+
private let CUSTOM_EVENT = "custom_event"
|
|
12
|
+
private let PAYMENT_EVENT = "payment_event"
|
|
13
|
+
private let MINIAPP_LIFECYCLE_EVENT = "miniapp_lifecycle"
|
|
14
|
+
|
|
15
|
+
public let identifier = "AppboxoPlugin"
|
|
16
|
+
public let jsName = "Appboxo"
|
|
17
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
18
|
+
CAPPluginMethod(name: "setConfig", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "openMiniapp", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "setAuthCode", returnType: CAPPluginReturnPromise),
|
|
21
|
+
CAPPluginMethod(name: "closeMiniapp", returnType: CAPPluginReturnPromise),
|
|
22
|
+
CAPPluginMethod(name: "sendCustomEvent", returnType: CAPPluginReturnPromise),
|
|
23
|
+
CAPPluginMethod(name: "sendPaymentEvent", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "getMiniapps", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "hideMiniapps", returnType: CAPPluginReturnPromise),
|
|
26
|
+
CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise)
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
@objc func setConfig(_ call: CAPPluginCall) {
|
|
30
|
+
let clientId = call.getString("clientId") ?? ""
|
|
31
|
+
let userId = call.getString("userId") ?? ""
|
|
32
|
+
let sandboxMode = call.getBool("sandboxMde", false)
|
|
33
|
+
let theme = call.getString("theme", "system")
|
|
34
|
+
let showPermissionsPage = call.getBool("showPermissionsPage", true)
|
|
35
|
+
let showClearCache = call.getBool("showClearCache", true)
|
|
36
|
+
var globalTheme : Theme = .System
|
|
37
|
+
switch (theme) {
|
|
38
|
+
case "dark":
|
|
39
|
+
globalTheme = .Dark
|
|
40
|
+
case "light":
|
|
41
|
+
globalTheme = .Light
|
|
42
|
+
default:
|
|
43
|
+
globalTheme = .System
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let config = Config(clientId: clientId, theme: globalTheme)
|
|
47
|
+
config.sandboxMode = sandboxMode
|
|
48
|
+
config.permissionsPage = showPermissionsPage
|
|
49
|
+
config.showClearCache = showClearCache
|
|
50
|
+
config.setUserId(id: userId)
|
|
51
|
+
|
|
52
|
+
Appboxo.shared.setConfig(config: config)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@objc func openMiniapp(_ call: CAPPluginCall) {
|
|
56
|
+
let appId = call.getString("appId") ?? ""
|
|
57
|
+
let data = call.getObject("data")?.toMap() ?? nil
|
|
58
|
+
let theme = call.getString("theme")
|
|
59
|
+
let extraUrlParams = call.getObject("extraUrlParams")?.toMap() ?? nil
|
|
60
|
+
let colors = call.getObject("colors")?.toMap() ?? nil
|
|
61
|
+
let enableSplash = call.getBool("enableSplash")
|
|
62
|
+
|
|
63
|
+
let miniApp = Appboxo.shared.getMiniapp(appId: appId)
|
|
64
|
+
miniApp.setData(data: data)
|
|
65
|
+
miniApp.delegate = self
|
|
66
|
+
|
|
67
|
+
let miniappConfig = MiniappConfig()
|
|
68
|
+
if let enableSplash = enableSplash {
|
|
69
|
+
miniappConfig.enableSplash(isSplashEnabled: enableSplash)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if let theme = theme {
|
|
73
|
+
switch theme {
|
|
74
|
+
case "dark":
|
|
75
|
+
miniappConfig.setTheme(theme: .Dark)
|
|
76
|
+
case "light":
|
|
77
|
+
miniappConfig.setTheme(theme: .Light)
|
|
78
|
+
case "system":
|
|
79
|
+
miniappConfig.setTheme(theme: .System)
|
|
80
|
+
default:
|
|
81
|
+
break
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if let extraUrlParams = extraUrlParams as? [String : String] {
|
|
86
|
+
miniappConfig.setExtraParams(extraParams: extraUrlParams)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if let colors = colors {
|
|
90
|
+
miniappConfig.setColor(color: MiniappColor(primary: colors["primary_color"] as? String ?? "", secondary: colors["secondary_color"] as? String ?? "", tertiary: colors["tertiary_color"] as? String ?? ""))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
miniApp.setConfig(config: miniappConfig)
|
|
94
|
+
|
|
95
|
+
guard let viewController = bridge?.viewController else { return }
|
|
96
|
+
DispatchQueue.main.async {
|
|
97
|
+
miniApp.open(viewController: viewController)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@objc func setAuthCode(_ call: CAPPluginCall) {
|
|
103
|
+
let appId = call.getString("appId") ?? ""
|
|
104
|
+
let authCode = call.getString("authCode") ?? ""
|
|
105
|
+
|
|
106
|
+
DispatchQueue.main.async {
|
|
107
|
+
Appboxo.shared.getMiniapp(appId: appId).setAuthCode(authCode: authCode)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@objc func closeMiniapp(_ call: CAPPluginCall) {
|
|
112
|
+
let appId = call.getString("appId") ?? ""
|
|
113
|
+
|
|
114
|
+
if let miniapp = Appboxo.shared.getExistingMiniapp(appId: appId) {
|
|
115
|
+
DispatchQueue.main.async {
|
|
116
|
+
miniapp.close()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@objc func sendCustomEvent(_ call: CAPPluginCall) {
|
|
122
|
+
let appId = call.getString("appId") ?? ""
|
|
123
|
+
|
|
124
|
+
let customEvent = CustomEvent()
|
|
125
|
+
customEvent.requestId = call.getInt("requestId", 0)
|
|
126
|
+
customEvent.type = call.getString("type") ?? ""
|
|
127
|
+
customEvent.errorType = call.getString("errorType") ?? ""
|
|
128
|
+
customEvent.payload = call.getObject("payload")?.toMap()
|
|
129
|
+
|
|
130
|
+
DispatchQueue.main.async {
|
|
131
|
+
Appboxo.shared.getMiniapp(appId: appId).sendCustomEvent(customEvent: customEvent)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@objc func sendPaymentEvent(_ call: CAPPluginCall) {
|
|
136
|
+
let appId = call.getString("appId") ?? ""
|
|
137
|
+
|
|
138
|
+
let paymentData = PaymentData()
|
|
139
|
+
paymentData.transactionToken = call.getString("transactionToken") ?? ""
|
|
140
|
+
paymentData.miniappOrderId = call.getString("miniappOrderId") ?? ""
|
|
141
|
+
paymentData.amount = call.getDouble("amount", 0.0)
|
|
142
|
+
paymentData.currency = call.getString("currency") ?? ""
|
|
143
|
+
paymentData.status = call.getString("status") ?? ""
|
|
144
|
+
paymentData.hostappOrderId = call.getString("hostappOrderId") ?? ""
|
|
145
|
+
paymentData.extraParams = call.getObject("extraParams")?.toMap()
|
|
146
|
+
|
|
147
|
+
DispatchQueue.main.async {
|
|
148
|
+
Appboxo.shared.getMiniapp(appId: appId).sendPaymentEvent(paymentData: paymentData)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@objc func getMiniapps(_ call: CAPPluginCall) {
|
|
153
|
+
Appboxo.shared.getMiniapps { miniapps, error in
|
|
154
|
+
if let error = error {
|
|
155
|
+
call.reject(error)
|
|
156
|
+
} else {
|
|
157
|
+
var list = JSArray()
|
|
158
|
+
|
|
159
|
+
miniapps.forEach { miniappData in
|
|
160
|
+
var data = JSObject()
|
|
161
|
+
data["appId"] = miniappData.appId
|
|
162
|
+
data["name"] = miniappData.name
|
|
163
|
+
data["category"] = miniappData.category
|
|
164
|
+
data["logo"] = miniappData.logo
|
|
165
|
+
data["description"] = miniappData.longDescription
|
|
166
|
+
list.append(data)
|
|
167
|
+
}
|
|
168
|
+
call.resolve(["miniapps" : list])
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@objc func hideMiniapps(_ call: CAPPluginCall) {
|
|
174
|
+
DispatchQueue.main.async {
|
|
175
|
+
Appboxo.shared.hideMiniapps()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@objc func logout(_ call: CAPPluginCall) {
|
|
180
|
+
DispatchQueue.main.async {
|
|
181
|
+
Appboxo.shared.logout()
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
extension AppboxoPlugin : MiniappDelegate {
|
|
187
|
+
public func didReceivePaymentEvent(miniapp: Miniapp, paymentData: PaymentData) {
|
|
188
|
+
let dict = [
|
|
189
|
+
"appId" : miniapp.appId,
|
|
190
|
+
"transactionToken" : paymentData.transactionToken,
|
|
191
|
+
"miniappOrderId" : paymentData.miniappOrderId,
|
|
192
|
+
"amount" : paymentData.amount,
|
|
193
|
+
"currency" : paymentData.currency,
|
|
194
|
+
"status" : paymentData.status,
|
|
195
|
+
"hostappOrderId" : paymentData.hostappOrderId,
|
|
196
|
+
"extraParams" : paymentData.extraParams ?? [String : Any]()
|
|
197
|
+
] as [String: Any]
|
|
198
|
+
|
|
199
|
+
notifyListeners(PAYMENT_EVENT, data: dict)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public func didReceiveCustomEvent(miniapp: Miniapp, customEvent: CustomEvent) {
|
|
203
|
+
let dict = [
|
|
204
|
+
"appId" : miniapp.appId,
|
|
205
|
+
"requestId" : customEvent.requestId,
|
|
206
|
+
"type" : customEvent.type,
|
|
207
|
+
"errorType" : customEvent.errorType,
|
|
208
|
+
"payload" : customEvent.payload ?? [String : Any]()
|
|
209
|
+
] as [String: Any]
|
|
210
|
+
|
|
211
|
+
notifyListeners(CUSTOM_EVENT, data: dict)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public func onLaunch(miniapp: Miniapp) {
|
|
215
|
+
let dict = [
|
|
216
|
+
"appId" : miniapp.appId,
|
|
217
|
+
"lifecycle" : "onLaunch"
|
|
218
|
+
]
|
|
219
|
+
|
|
220
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public func onResume(miniapp: Miniapp) {
|
|
224
|
+
let dict = [
|
|
225
|
+
"appId" : miniapp.appId,
|
|
226
|
+
"lifecycle" : "onResume"
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public func onPause(miniapp: Miniapp) {
|
|
233
|
+
let dict = [
|
|
234
|
+
"appId" : miniapp.appId,
|
|
235
|
+
"lifecycle" : "onPause"
|
|
236
|
+
]
|
|
237
|
+
|
|
238
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public func onClose(miniapp: Miniapp) {
|
|
242
|
+
let dict = [
|
|
243
|
+
"appId" : miniapp.appId,
|
|
244
|
+
"lifecycle" : "onClose"
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public func onError(miniapp: Miniapp, message: String) {
|
|
251
|
+
let dict = [
|
|
252
|
+
"appId" : miniapp.appId,
|
|
253
|
+
"lifecycle" : "onError",
|
|
254
|
+
"error" : message
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public func onUserInteraction(miniapp: Miniapp) {
|
|
261
|
+
let dict = [
|
|
262
|
+
"appId" : miniapp.appId,
|
|
263
|
+
"lifecycle" : "onUserInteraction"
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public func onAuth(miniapp: Miniapp) {
|
|
270
|
+
let dict = [
|
|
271
|
+
"appId" : miniapp.appId,
|
|
272
|
+
"lifecycle" : "onAuth"
|
|
273
|
+
]
|
|
274
|
+
|
|
275
|
+
notifyListeners(MINIAPP_LIFECYCLE_EVENT, data: dict)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
extension JSObject {
|
|
280
|
+
func toMap() -> [String : Any] {
|
|
281
|
+
var dict = [String : Any]()
|
|
282
|
+
|
|
283
|
+
keys.forEach { key in
|
|
284
|
+
if let object = self[key] as? JSObject {
|
|
285
|
+
dict[key] = object.toMap()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
dict[key] = self[key]
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return dict
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import AppboxoPlugin
|
|
3
|
+
|
|
4
|
+
class AppboxoTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = Appboxo()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appboxo/capacitor-boxo-sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A capacitor wrapper over Appboxo SDK for IOS and Android.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapacitorBoxoSdk.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Appboxo pte. ltd",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Appboxo/capacitor-appboxo-sdk.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Appboxo/capacitor-appboxo-sdk/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CapacitorBoxoSdk -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api AppboxoPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@capacitor/android": "^5.7.7",
|
|
50
|
+
"@capacitor/core": "^5.7.7",
|
|
51
|
+
"@capacitor/docgen": "^0.2.2",
|
|
52
|
+
"@capacitor/ios": "^5.7.7",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^1.0.1",
|
|
55
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"prettier": "~2.3.0",
|
|
58
|
+
"prettier-plugin-java": "~1.0.2",
|
|
59
|
+
"rimraf": "^3.0.2",
|
|
60
|
+
"rollup": "^2.32.0",
|
|
61
|
+
"swiftlint": "^1.0.1",
|
|
62
|
+
"typescript": "~4.1.5"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@capacitor/core": "^5.7.7"
|
|
66
|
+
},
|
|
67
|
+
"prettier": "@ionic/prettier-config",
|
|
68
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
71
|
+
},
|
|
72
|
+
"capacitor": {
|
|
73
|
+
"ios": {
|
|
74
|
+
"src": "ios"
|
|
75
|
+
},
|
|
76
|
+
"android": {
|
|
77
|
+
"src": "android"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|