@applicaster/quick-brick-native-apple 5.20.2 → 5.20.4

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "QuickBrickApple",
3
- "version": "5.20.2",
3
+ "version": "5.20.4",
4
4
  "platforms": {
5
5
  "ios": "14.0",
6
6
  "tvos": "14.0"
@@ -16,7 +16,7 @@
16
16
  "authors": "Applicaster LTD.",
17
17
  "source": {
18
18
  "git": "https://github.com/applicaster/Zapp-Frameworks.git",
19
- "tag": "@@applicaster/quick-brick-native-apple/5.20.2"
19
+ "tag": "@@applicaster/quick-brick-native-apple/5.20.4"
20
20
  },
21
21
  "requires_arc": true,
22
22
  "source_files": "universal/**/*.{m,swift}",
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "ZappCore": [],
36
36
  "React": [],
37
+ "React-Core": [],
37
38
  "React-RCTLinking": [],
38
39
  "XrayLogger": []
39
40
  },
@@ -8,10 +8,13 @@
8
8
 
9
9
  import Foundation
10
10
  import React
11
+ import XrayLogger
11
12
  import ZappCore
12
13
 
13
14
  @objc(AppLoaderBridge)
14
15
  class AppLoaderBridge: NSObject, RCTBridgeModule {
16
+ lazy var logger = Logger.getLogger(for: "\(Bundle.main.bundleIdentifier!)/native_application/AppLoaderBridge")
17
+
15
18
  static func moduleName() -> String! {
16
19
  "AppLoaderBridge"
17
20
  }
@@ -26,15 +29,17 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
26
29
  }
27
30
 
28
31
  enum Errors {
29
- static let canNotAccessAppData = "Can not access application data"
30
- static let parameterDoesNotExist = "The type parameter does not exist/supported"
31
- static let noIdentifierBody = "FacadeConnector can't delegate applicationData"
32
- static let noCharacters = "Layout id without charaters"
33
- static let urlCreationMessage = "There was a problem to create the new layout URLs"
34
- static let switchToNewLayoutMessage = "There was a problem to switch to new layout URLs"
35
- static let canNotGetPluginsContent = "Can not get the plugins content"
36
- static let canNotGetPipesEndpointContent = "Can not get the pipes endpoint content"
37
- static let canNotGetCellStylesContent = "Can not get the cell style content"
32
+ static let parameterDoesNotExist = (message: "The type parameter does not exist/supported", code: "1")
33
+ static let canNotAccessAppData = (message: "Can not access application data", code: "2")
34
+ static let switchToNewLayoutMessage = (message: "There was a problem to switch to new layout URLs", code: "3")
35
+ static let canNotGetRemoteConfigurationContent = (message: "Can not get the remotet configuration content", code: "4")
36
+ static let canNotGetPluginsContent = (message: "Can not get the plugins content", code: "5")
37
+ static let canNotGetOriginLayoutContent = (message: "Can not get the origin layout from layout.json content", code: "6")
38
+ static let canNotGetLayoutContentFromId = (message: "Can not get the layout from content id", code: "7")
39
+ static let canNotGetOriginCellStylesContent = (message: "Can not get the origin cellStyles from cell_styles.json", code: "8")
40
+ static let canNotGetCellStylesContent = (message: "Can not get the layout from content id", code: "9")
41
+ static let canNotGetStylesContent = (message: "Can not get the stylescontent", code: "10")
42
+ static let canNotGetPipesEndpointContent = (message: "Can not get the pipes endpoint content", code: "11")
38
43
  }
39
44
 
40
45
  enum ContentType: String {
@@ -47,7 +52,8 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
47
52
  }
48
53
 
49
54
  enum Consts {
50
- static let currentLayoutId = "currentLayoutId"
55
+ static let activeLayoutId = "active_layout_id"
56
+ static let defaultLayoutId = "default_layout_id"
51
57
  }
52
58
 
53
59
  // MARK: - Bridge Methods
@@ -57,68 +63,82 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
57
63
  resolver: @escaping RCTPromiseResolveBlock,
58
64
  rejecter: @escaping RCTPromiseRejectBlock) {
59
65
  guard let applicationData = FacadeConnector.connector?.applicationData else {
60
- rejecter("2", Errors.canNotAccessAppData, nil)
66
+ rejecter(Errors.canNotAccessAppData.code, Errors.canNotAccessAppData.message, nil)
61
67
  return
62
68
  }
63
69
 
64
70
  guard let contentType = ContentType(rawValue: type) else {
65
- rejecter("1", Errors.parameterDoesNotExist, nil)
71
+ rejecter(Errors.parameterDoesNotExist.code, Errors.parameterDoesNotExist.message, nil)
66
72
  return
67
73
  }
68
74
 
69
75
  switch contentType {
70
76
  case .remoteConfigurations:
71
77
  guard let remoteConfig = applicationData.remoteConfigurationUrlContent() else {
72
- rejecter("2", Errors.canNotAccessAppData, nil)
78
+ rejecter(Errors.canNotGetRemoteConfigurationContent.code, Errors.canNotGetRemoteConfigurationContent.message, nil)
73
79
  return
74
80
  }
81
+
75
82
  let remoteConfigJsonString = remoteConfig.getJsonString()
76
83
  resolver(remoteConfigJsonString)
77
84
  case .pluginConfigurations:
78
85
  guard let pluginsContent = applicationData.pluginsUrlContent() else {
79
- rejecter("7", Errors.canNotGetPluginsContent, nil)
86
+ rejecter(Errors.canNotGetPluginsContent.code, Errors.canNotGetPluginsContent.message, nil)
80
87
  return
81
88
  }
82
89
 
83
90
  let jsonString = JsonHelper.convertObjectToJsonString(object: pluginsContent, options: [])
84
91
  resolver(jsonString)
85
92
  case .layout:
86
- guard let layoutId = getLayoutId() else {
87
- resolver(applicationData.layoutUrlContent()?.getJsonString())
93
+ guard let layoutId = getActiveOrDefaultFallbackLayoutId() else {
94
+ if let layoutContent = applicationData.layoutUrlContent() {
95
+ let layoutContentJsonString = layoutContent.getJsonString()
96
+ resolver(layoutContentJsonString)
97
+
98
+ } else {
99
+ rejecter(Errors.canNotGetOriginLayoutContent.code, Errors.canNotGetOriginLayoutContent.message, nil)
100
+ }
88
101
  return
89
102
  }
90
103
 
91
104
  applicationData.layoutUrlContent(for: layoutId) { layoutUrlContent in
92
105
  guard let layoutUrlContent = layoutUrlContent else {
93
- rejecter("4", Errors.switchToNewLayoutMessage, nil)
106
+ rejecter(Errors.canNotGetLayoutContentFromId.code, Errors.canNotGetLayoutContentFromId.message, nil)
94
107
  return
95
108
  }
96
109
 
97
110
  resolver(layoutUrlContent.getJsonString())
98
111
  }
99
- case .styles:
100
- guard let layoutId = getLayoutId() else {
101
- resolver(applicationData.stylesUrlContent()?.getJsonString())
112
+ case .cellStyles:
113
+ guard let layoutId = getActiveOrDefaultFallbackLayoutId() else {
114
+ if let cellStylesContent = applicationData.cellStylesUrlContent() {
115
+ let cellStylesContentJsonString = cellStylesContent.getJsonString()
116
+ resolver(cellStylesContentJsonString)
117
+ } else {
118
+ rejecter(Errors.canNotGetOriginCellStylesContent.code, Errors.canNotGetOriginCellStylesContent.message, nil)
119
+ }
102
120
  return
103
121
  }
104
122
 
105
123
  applicationData.cellStylesUrlContent(for: layoutId) { cellStylesUrlContent in
106
124
  guard let cellStylesUrlContent = cellStylesUrlContent else {
107
- rejecter("4", Errors.switchToNewLayoutMessage, nil)
125
+ rejecter(Errors.canNotGetCellStylesContent.code, Errors.canNotGetCellStylesContent.message, nil)
108
126
  return
109
127
  }
110
128
 
111
129
  resolver(cellStylesUrlContent.getJsonString())
112
130
  }
113
- case .cellStyles:
114
- guard let cellStylesData = applicationData.cellStylesUrlContent() else {
115
- rejecter("9", Errors.canNotGetCellStylesContent, nil)
131
+ case .styles:
132
+ guard let stylesURLContent = applicationData.stylesUrlContent() else {
133
+ rejecter(Errors.canNotGetStylesContent.code, Errors.canNotGetStylesContent.message, nil)
116
134
  return
117
135
  }
118
- resolver(cellStylesData.getJsonString())
136
+
137
+ let stylesURLContentJsonString = stylesURLContent.getJsonString()
138
+ resolver(stylesURLContentJsonString)
119
139
  case .pipesEndpoints:
120
140
  guard let pipesEndpointContent = applicationData.pipesEndpointContent() else {
121
- rejecter("8", Errors.canNotGetPipesEndpointContent, nil)
141
+ rejecter(Errors.canNotGetPipesEndpointContent.code, Errors.canNotGetPipesEndpointContent.message, nil)
122
142
  return
123
143
  }
124
144
  resolver(pipesEndpointContent.getJsonString())
@@ -131,22 +151,22 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
131
151
  rejecter: @escaping RCTPromiseRejectBlock) {
132
152
  // Construct the layout and cell_style URLS
133
153
  guard let applicationData = FacadeConnector.connector?.applicationData else {
134
- rejecter("2", Errors.canNotAccessAppData, nil)
154
+ rejecter(Errors.canNotAccessAppData.code, Errors.canNotAccessAppData.message, nil)
135
155
  return
136
156
  }
137
157
 
138
158
  applicationData.layoutUrlContent(for: layoutId) { layoutUrlContent in
139
159
  guard let _ = layoutUrlContent else {
140
- rejecter("4", Errors.switchToNewLayoutMessage, nil)
160
+ rejecter(Errors.switchToNewLayoutMessage.code, Errors.switchToNewLayoutMessage.message, nil)
141
161
  return
142
162
  }
143
163
 
144
164
  applicationData.cellStylesUrlContent(for: layoutId) { cellStylesUrlContent in
145
165
  DispatchQueue.main.async {
146
166
  guard let _ = cellStylesUrlContent,
147
- self.saveLayoutId(id: layoutId)
167
+ self.saveActiveLayoutId(id: layoutId)
148
168
  else {
149
- rejecter("4", Errors.switchToNewLayoutMessage, nil)
169
+ rejecter(Errors.switchToNewLayoutMessage.code, Errors.switchToNewLayoutMessage.message, nil)
150
170
  return
151
171
  }
152
172
  resolver(true)
@@ -158,7 +178,7 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
158
178
  // get the current layout id
159
179
  @objc public func getCurrentLayoutId(_ resolve: @escaping RCTPromiseResolveBlock,
160
180
  rejecter: @escaping RCTPromiseRejectBlock) {
161
- guard let layoutId = getLayoutId() else {
181
+ guard let layoutId = getActiveOrDefaultFallbackLayoutId() else {
162
182
  getDefaultLayoutId(resolve, rejecter: rejecter)
163
183
  return
164
184
  }
@@ -169,14 +189,19 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
169
189
  // get the defualt layout id
170
190
  @objc public func getDefaultLayoutId(_ resolve: @escaping RCTPromiseResolveBlock,
171
191
  rejecter: @escaping RCTPromiseRejectBlock) {
192
+ if let cachedDefaultLayoutId = FacadeConnector.connector?.storage?.localStorageValue(for: Consts.defaultLayoutId, namespace: nil) {
193
+ resolve(cachedDefaultLayoutId)
194
+ return
195
+ }
196
+
172
197
  guard let applicationData = FacadeConnector.connector?.applicationData else {
173
- rejecter("2", Errors.canNotAccessAppData, nil)
198
+ rejecter(Errors.canNotAccessAppData.code, Errors.canNotAccessAppData.message, nil)
174
199
  return
175
200
  }
176
201
 
177
202
  let layoutId = applicationData.layoutId()
178
203
  guard layoutId.isEmpty == false else {
179
- rejecter("3", Errors.parameterDoesNotExist, nil)
204
+ rejecter(Errors.parameterDoesNotExist.code, Errors.parameterDoesNotExist.message, nil)
180
205
  return
181
206
  }
182
207
  resolve(layoutId)
@@ -184,14 +209,20 @@ class AppLoaderBridge: NSObject, RCTBridgeModule {
184
209
 
185
210
  // MARK: - Private Methods
186
211
 
187
- private func saveLayoutId(id: String) -> Bool {
188
- FacadeConnector.connector?.storage?.sessionStorageSetValue(for: Consts.currentLayoutId,
212
+ private func saveActiveLayoutId(id: String) -> Bool {
213
+ FacadeConnector.connector?.storage?.sessionStorageSetValue(for: Consts.activeLayoutId,
189
214
  value: id,
190
215
  namespace: nil) ?? false
191
216
  }
192
217
 
193
- private func getLayoutId() -> String? {
194
- FacadeConnector.connector?.storage?.sessionStorageValue(for: Consts.currentLayoutId,
195
- namespace: nil)
218
+ private func getActiveOrDefaultFallbackLayoutId() -> String? {
219
+ guard let layoutId = FacadeConnector.connector?.storage?.sessionStorageValue(for: Consts.activeLayoutId,
220
+ namespace: nil) ??
221
+ FacadeConnector.connector?.storage?.localStorageValue(for: Consts.defaultLayoutId,
222
+ namespace: nil) else {
223
+ logger?.errorLog(message: "getActiveOrDefaultFallbackLayoutId: Can not find active layout id or default layout id. Please check application configuration")
224
+ return nil
225
+ }
226
+ return layoutId
196
227
  }
197
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-native-apple",
3
- "version": "5.20.2",
3
+ "version": "5.20.4",
4
4
  "description": "iOS and tvOS native code for QuickBrick applications. This package is used to provide native logic for QuickBrick",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"