@frontegg/ionic-capacitor 1.0.0 → 2.0.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.
@@ -24,6 +24,49 @@ public class FronteggNativePlugin: CAPPlugin {
24
24
 
25
25
  override public func load() {
26
26
 
27
+ let config = self.getConfig()
28
+
29
+ let handleLoginWithSocialLogin = config.getBoolean("handleLoginWithSocialLogin", true)
30
+ let handleLoginWithSSO = config.getBoolean("handleLoginWithSSO", false)
31
+
32
+ if let array = config.getArray("regions", []),
33
+ array.count > 0 {
34
+ print("region initialization")
35
+ var regions:[RegionConfig] = []
36
+
37
+ array.forEach {item in
38
+ if let dict = item as? [String:String] {
39
+ regions.append(RegionConfig(
40
+ key: dict["key"]!,
41
+ baseUrl: dict["baseUrl"]!,
42
+ clientId: dict["clientId"]!
43
+ ))
44
+ }
45
+ }
46
+
47
+ if(regions.isEmpty){
48
+ print("Frontegg Error: Missing regions configurations")
49
+ exit(1)
50
+ }
51
+ fronteggApp.manualInitRegions(regions: regions,
52
+ handleLoginWithSocialLogin: handleLoginWithSocialLogin,
53
+ handleLoginWithSSO: handleLoginWithSSO)
54
+ } else {
55
+ print("standard initialization")
56
+ if let baseUrl = config.getString("baseUrl"),
57
+ let clientId = config.getString("clientId") {
58
+ fronteggApp.manualInit(baseUrl: baseUrl,
59
+ cliendId: clientId,
60
+ handleLoginWithSocialLogin: handleLoginWithSocialLogin,
61
+ handleLoginWithSSO: handleLoginWithSSO)
62
+ }else {
63
+ print("Frontegg Error: Missing baseUrl or clientId in project configurations")
64
+ exit(1)
65
+ }
66
+ }
67
+
68
+
69
+
27
70
  let auth = fronteggApp.auth
28
71
  var anyChange: AnyPublisher<Void, Never> {
29
72
  return Publishers.Merge8 (
@@ -34,7 +77,7 @@ public class FronteggNativePlugin: CAPPlugin {
34
77
  auth.$isLoading.map {_ in },
35
78
  auth.$initializing.map {_ in },
36
79
  auth.$showLoader.map {_ in },
37
- auth.$appLink.map {_ in }
80
+ auth.$selectedRegion.map{_ in}
38
81
  )
39
82
  .eraseToAnyPublisher()
40
83
  }
@@ -48,6 +91,8 @@ public class FronteggNativePlugin: CAPPlugin {
48
91
  self.sendEvent()
49
92
  }
50
93
 
94
+
95
+
51
96
  func sendEvent() {
52
97
  let auth = fronteggApp.auth
53
98
 
@@ -64,17 +109,44 @@ public class FronteggNativePlugin: CAPPlugin {
64
109
  "isLoading": auth.isLoading,
65
110
  "initializing": auth.initializing,
66
111
  "showLoader": auth.showLoader,
67
- "appLink": auth.appLink
112
+ "selectedRegion": regionToJson(auth.selectedRegion)
68
113
  ]
69
114
 
70
115
  self.notifyListeners("onFronteggAuthEvent", data: body as [String : Any])
71
116
  }
72
117
 
118
+
119
+ func regionToJson(_ region: RegionConfig?) -> [String:String]? {
120
+
121
+ if let reg = region {
122
+ return [
123
+ "baseUrl": reg.baseUrl,
124
+ "clientId": reg.clientId,
125
+ "key": reg.key
126
+ ]
127
+ }else {
128
+ return nil
129
+ }
130
+ }
131
+ func regionsToJson(_ regions: [RegionConfig]) -> [[String:String]] {
132
+
133
+ var regionData: [[String:String]] = []
134
+ regions.forEach { reg in
135
+ if let region = regionToJson(reg) {
136
+ regionData.append(region)
137
+ }
138
+ }
139
+
140
+ return regionData
141
+ }
142
+
73
143
  @objc func getConstants(_ call: CAPPluginCall) {
74
144
  call.resolve([
75
145
  "baseUrl": fronteggApp.baseUrl,
76
146
  "clientId": fronteggApp.clientId,
77
- "bundleId": Bundle.main.bundleIdentifier!
147
+ "bundleId": Bundle.main.bundleIdentifier!,
148
+ "isRegional": fronteggApp.auth.isRegional,
149
+ "regionData": regionsToJson(fronteggApp.auth.regionData)
78
150
  ])
79
151
  }
80
152
 
@@ -103,6 +175,15 @@ public class FronteggNativePlugin: CAPPlugin {
103
175
  }
104
176
  }
105
177
 
178
+ @objc func initWithRegion(_ call: CAPPluginCall) {
179
+ guard let regionKey = call.options["regionKey"] as? String else {
180
+ call.reject("No regionKey provided")
181
+ return
182
+ }
183
+
184
+ fronteggApp.initWithRegion(regionKey: regionKey)
185
+ }
186
+
106
187
  @objc func refreshToken(_ call: CAPPluginCall) {
107
188
 
108
189
  DispatchQueue.global(qos: .background).async {
@@ -128,9 +209,9 @@ public class FronteggNativePlugin: CAPPlugin {
128
209
  "isLoading": auth.isLoading,
129
210
  "initializing": auth.initializing,
130
211
  "showLoader": auth.showLoader,
131
- "appLink": auth.appLink
212
+ "selectedRegion": regionToJson(auth.selectedRegion)
132
213
  ]
133
- call.resolve(body as? [String: Any] ?? [:])
214
+ call.resolve(body as [String: Any] )
134
215
  }
135
216
 
136
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/ionic-capacitor",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Frontegg Ionic Capacitor SDK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",