@dashx/react-native 0.1.25 → 1.0.3
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/android/build.gradle +22 -149
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
- package/android/gradlew +34 -21
- package/android/gradlew.bat +24 -19
- package/android/src/main/AndroidManifest.xml +2 -8
- package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +248 -0
- package/android/src/main/java/com/dashx/rn/sdk/{DashXPackage.kt → DashXReactNativePackage.kt} +2 -1
- package/android/src/main/java/com/dashx/rn/sdk/util/ArrayUtil.java +131 -0
- package/android/src/main/java/com/dashx/rn/sdk/util/MapUtil.java +142 -0
- package/android/src/main/java/com/dashx/rn/sdk/{Utils.kt → util/Utils.kt} +5 -5
- package/index.js +68 -72
- package/ios/DashX.swift +110 -95
- package/ios/DashXReactNative-Bridging-Header.h +4 -0
- package/ios/DashXReactNative.m +25 -0
- package/ios/DashXReactNative.xcodeproj/project.pbxproj +280 -0
- package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/contents.xcworkspacedata +1 -1
- package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- package/package.json +6 -12
- package/DashX.podspec +0 -27
- package/android/README.md +0 -23
- package/android/src/main/java/com/dashx/rn/sdk/DashXActivityLifecycleCallbacks.kt +0 -93
- package/android/src/main/java/com/dashx/rn/sdk/DashXClientInterceptor.kt +0 -66
- package/android/src/main/java/com/dashx/rn/sdk/DashXExceptionHandler.kt +0 -28
- package/android/src/main/java/com/dashx/rn/sdk/DashXMessagingService.kt +0 -176
- package/android/src/main/java/com/dashx/rn/sdk/DashXModule.kt +0 -193
- package/android/src/main/java/com/dashx/rn/sdk/NotificationReceiver.kt +0 -17
- package/ios/API.swift +0 -2420
- package/ios/Constants.swift +0 -14
- package/ios/DashX.m +0 -17
- package/ios/DashX.xcodeproj/project.pbxproj +0 -356
- package/ios/DashX.xcodeproj/xcshareddata/xcschemes/DashX.xcscheme +0 -67
- package/ios/DashXAppDelegate.swift +0 -73
- package/ios/DashXApplicationLifecycleCallbacks.swift +0 -65
- package/ios/DashXClient.swift +0 -319
- package/ios/DashXData.swift +0 -19
- package/ios/DashXLog.swift +0 -44
- package/ios/DashXUIViewController.swift +0 -15
- package/ios/Network.swift +0 -74
- package/ios/README.md +0 -80
- package/ios/Utils.swift +0 -13
- package/ios/graphql/AddContent.graphql +0 -8
- package/ios/graphql/AddItemToCart.graphql +0 -33
- package/ios/graphql/EditContent.graphql +0 -8
- package/ios/graphql/FetchCart.graphql +0 -33
- package/ios/graphql/FetchContent.graphql +0 -3
- package/ios/graphql/IdentifyAccount.graphql +0 -5
- package/ios/graphql/SearchContent.graphql +0 -3
- package/ios/graphql/SubscribeContact.graphql +0 -6
- package/ios/graphql/TrackEvent.graphql +0 -5
- package/ios/schema.json +0 -37038
package/ios/DashXClient.swift
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Apollo
|
|
3
|
-
|
|
4
|
-
enum DashXClientError: Error {
|
|
5
|
-
case noArgsInIdentify
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class DashXClient {
|
|
9
|
-
static let instance = DashXClient()
|
|
10
|
-
private var anonymousUid: String?
|
|
11
|
-
private var uid: String?
|
|
12
|
-
private var deviceToken: String?
|
|
13
|
-
|
|
14
|
-
private var mustSubscribe: Bool = false;
|
|
15
|
-
|
|
16
|
-
private init() {
|
|
17
|
-
generateAnonymousUid()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
func setDeviceToken(to: String) {
|
|
21
|
-
self.deviceToken = to
|
|
22
|
-
|
|
23
|
-
if (self.mustSubscribe) {
|
|
24
|
-
self.subscribe()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
func setTargetEnvironment(to: String) {
|
|
29
|
-
ConfigInterceptor.shared.targetEnvironment = to
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func setTargetInstallation(to: String) {
|
|
33
|
-
ConfigInterceptor.shared.targetInstallation = to
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func setIdentityToken(to: String) {
|
|
37
|
-
ConfigInterceptor.shared.identityToken = to
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private func generateAnonymousUid(withRegenerate: Bool = false) {
|
|
41
|
-
let preferences = UserDefaults.standard
|
|
42
|
-
let anonymousUidKey = Constants.USER_PREFERENCES_KEY_ANONYMOUS_UID
|
|
43
|
-
|
|
44
|
-
if !withRegenerate && preferences.object(forKey: anonymousUidKey) != nil {
|
|
45
|
-
self.anonymousUid = preferences.string(forKey: anonymousUidKey) ?? nil
|
|
46
|
-
} else {
|
|
47
|
-
self.anonymousUid = UUID().uuidString
|
|
48
|
-
preferences.set(self.anonymousUid, forKey: anonymousUidKey)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// MARK: -- identify
|
|
52
|
-
|
|
53
|
-
func identify(_ uid: String?, withOptions: NSDictionary?) throws {
|
|
54
|
-
if uid != nil {
|
|
55
|
-
self.uid = uid
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if withOptions == nil {
|
|
60
|
-
throw DashXClientError.noArgsInIdentify
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let optionsDictionary = withOptions as? [String: String]
|
|
64
|
-
|
|
65
|
-
self.uid = optionsDictionary?["uid"]
|
|
66
|
-
|
|
67
|
-
let identifyAccountInput = DashXGql.IdentifyAccountInput(
|
|
68
|
-
uid: optionsDictionary?["uid"],
|
|
69
|
-
anonymousUid: anonymousUid,
|
|
70
|
-
email: optionsDictionary?["email"],
|
|
71
|
-
phone: optionsDictionary?["phone"],
|
|
72
|
-
name: optionsDictionary?["name"],
|
|
73
|
-
firstName: optionsDictionary?["firstName"],
|
|
74
|
-
lastName: optionsDictionary?["lastName"]
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
let identifyAccountMutation = DashXGql.IdentifyAccountMutation(input: identifyAccountInput)
|
|
78
|
-
|
|
79
|
-
Network.shared.apollo.perform(mutation: identifyAccountMutation) { result in
|
|
80
|
-
switch result {
|
|
81
|
-
case .success(let graphQLResult):
|
|
82
|
-
DashXLog.d(tag: #function, "Sent identify with \(String(describing: graphQLResult))")
|
|
83
|
-
case .failure(let error):
|
|
84
|
-
DashXLog.d(tag: #function, "Encountered an error during identify(): \(error)")
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
func reset() {
|
|
90
|
-
self.uid = nil
|
|
91
|
-
self.generateAnonymousUid(withRegenerate: true)
|
|
92
|
-
}
|
|
93
|
-
// MARK: -- track
|
|
94
|
-
|
|
95
|
-
func track(_ event: String, withData: NSDictionary?) {
|
|
96
|
-
let trackEventInput = DashXGql.TrackEventInput(
|
|
97
|
-
event: event,
|
|
98
|
-
accountUid: uid,
|
|
99
|
-
accountAnonymousUid: anonymousUid,
|
|
100
|
-
data: withData as? [String: JSONDecodable?]
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
DashXLog.d(tag: #function, "Calling track with \(trackEventInput)")
|
|
104
|
-
|
|
105
|
-
let trackEventMutation = DashXGql.TrackEventMutation(input: trackEventInput)
|
|
106
|
-
|
|
107
|
-
Network.shared.apollo.perform(mutation: trackEventMutation) { result in
|
|
108
|
-
switch result {
|
|
109
|
-
case .success(let graphQLResult):
|
|
110
|
-
DashXLog.d(tag: #function, "Sent track with \(String(describing: graphQLResult))")
|
|
111
|
-
case .failure(let error):
|
|
112
|
-
DashXLog.d(tag: #function, "Encountered an error during track(): \(error)")
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
func screen(_ screenName: String, withData: NSDictionary?) {
|
|
118
|
-
let properties = withData as? [String: Any]
|
|
119
|
-
|
|
120
|
-
track(Constants.INTERNAL_EVENT_APP_SCREEN_VIEWED, withData: properties?.merging([ "name": screenName], uniquingKeysWith: { (_, new) in new }) as NSDictionary?)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// https://stackoverflow.com/a/11197770
|
|
124
|
-
func getDeviceModel() -> String {
|
|
125
|
-
var systemInfo = utsname()
|
|
126
|
-
uname(&systemInfo)
|
|
127
|
-
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
|
128
|
-
return machineMirror.children.reduce("") { identifier, element in
|
|
129
|
-
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
|
130
|
-
return identifier + String(UnicodeScalar(UInt8(value)))
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// MARK: -- subscribe
|
|
135
|
-
|
|
136
|
-
func subscribe() {
|
|
137
|
-
if deviceToken == nil {
|
|
138
|
-
self.mustSubscribe = true
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
self.mustSubscribe = false
|
|
143
|
-
|
|
144
|
-
let preferences = UserDefaults.standard
|
|
145
|
-
let deviceTokenKey = Constants.USER_PREFERENCES_KEY_DEVICE_TOKEN
|
|
146
|
-
|
|
147
|
-
if preferences.string(forKey: deviceTokenKey) == deviceToken {
|
|
148
|
-
DashXLog.d(tag: #function, "Already subscribed: \(String(describing: deviceToken))")
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let subscribeContactInput = DashXGql.SubscribeContactInput(
|
|
153
|
-
accountUid: uid,
|
|
154
|
-
accountAnonymousUid: anonymousUid!,
|
|
155
|
-
name: UIDevice.current.model,
|
|
156
|
-
kind: .ios,
|
|
157
|
-
value: deviceToken!,
|
|
158
|
-
osName: UIDevice.current.systemName,
|
|
159
|
-
osVersion: UIDevice.current.systemVersion,
|
|
160
|
-
deviceModel: getDeviceModel(),
|
|
161
|
-
deviceManufacturer: "Apple"
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
DashXLog.d(tag: #function, "Calling subscribe with \(subscribeContactInput)")
|
|
165
|
-
|
|
166
|
-
let subscribeContactMutation = DashXGql.SubscribeContactMutation(input: subscribeContactInput)
|
|
167
|
-
|
|
168
|
-
Network.shared.apollo.perform(mutation: subscribeContactMutation) { result in
|
|
169
|
-
switch result {
|
|
170
|
-
case .success(let graphQLResult):
|
|
171
|
-
if graphQLResult.data != nil {
|
|
172
|
-
preferences.set(graphQLResult.data?.subscribeContact.value, forKey: deviceTokenKey)
|
|
173
|
-
DashXLog.d(tag: #function, "Sent subscribe with \(String(describing: graphQLResult))")
|
|
174
|
-
}
|
|
175
|
-
case .failure(let error):
|
|
176
|
-
DashXLog.d(tag: #function, "Encountered an error during subscribe(): \(error)")
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// MARK: -- content
|
|
181
|
-
|
|
182
|
-
func fetchContent(
|
|
183
|
-
_ contentType: String,
|
|
184
|
-
_ content: String,
|
|
185
|
-
_ preview: Bool? = true,
|
|
186
|
-
_ language: String?,
|
|
187
|
-
_ fields: [String]? = [],
|
|
188
|
-
_ include: [String]? = [],
|
|
189
|
-
_ exclude: [String]? = [],
|
|
190
|
-
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
191
|
-
_ reject: @escaping RCTPromiseRejectBlock
|
|
192
|
-
) {
|
|
193
|
-
let fetchContentInput = DashXGql.FetchContentInput(
|
|
194
|
-
contentType: contentType,
|
|
195
|
-
content: content,
|
|
196
|
-
preview: preview,
|
|
197
|
-
language: language,
|
|
198
|
-
fields: fields,
|
|
199
|
-
include: include,
|
|
200
|
-
exclude: exclude
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
DashXLog.d(tag: #function, "Calling fetchContent with \(fetchContentInput)")
|
|
204
|
-
|
|
205
|
-
let findContentQuery = DashXGql.FetchContentQuery(input: fetchContentInput)
|
|
206
|
-
|
|
207
|
-
Network.shared.apollo.fetch(query: findContentQuery, cachePolicy: .returnCacheDataElseFetch) { result in
|
|
208
|
-
switch result {
|
|
209
|
-
case .success(let graphQLResult):
|
|
210
|
-
DashXLog.d(tag: #function, "Sent findContent with \(String(describing: graphQLResult))")
|
|
211
|
-
let content = graphQLResult.data?.fetchContent
|
|
212
|
-
resolve(content)
|
|
213
|
-
case .failure(let error):
|
|
214
|
-
DashXLog.d(tag: #function, "Encountered an error during fetchContent(): \(error)")
|
|
215
|
-
reject("", error.localizedDescription, error)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
func searchContent(
|
|
221
|
-
_ contentType: String,
|
|
222
|
-
_ returnType: String,
|
|
223
|
-
_ filter: NSDictionary?,
|
|
224
|
-
_ order: NSDictionary?,
|
|
225
|
-
_ limit: Int?,
|
|
226
|
-
_ preview: Bool? = true,
|
|
227
|
-
_ language: String?,
|
|
228
|
-
_ fields: [String]? = [],
|
|
229
|
-
_ include: [String]? = [],
|
|
230
|
-
_ exclude: [String]? = [],
|
|
231
|
-
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
232
|
-
_ reject: @escaping RCTPromiseRejectBlock
|
|
233
|
-
) {
|
|
234
|
-
let searchContentsInput = DashXGql.SearchContentInput(
|
|
235
|
-
contentType: contentType,
|
|
236
|
-
returnType: returnType,
|
|
237
|
-
filter: filter as? [String: Any],
|
|
238
|
-
order: order as? [String: Any],
|
|
239
|
-
limit: limit,
|
|
240
|
-
preview: preview,
|
|
241
|
-
language: language,
|
|
242
|
-
fields: fields,
|
|
243
|
-
include: include,
|
|
244
|
-
exclude: exclude
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
DashXLog.d(tag: #function, "Calling searchContent with \(searchContentsInput)")
|
|
248
|
-
|
|
249
|
-
let searchContentQuery = DashXGql.SearchContentQuery(input: searchContentsInput)
|
|
250
|
-
|
|
251
|
-
Network.shared.apollo.fetch(query: searchContentQuery, cachePolicy: .returnCacheDataElseFetch) { result in
|
|
252
|
-
switch result {
|
|
253
|
-
case .success(let graphQLResult):
|
|
254
|
-
let json = graphQLResult.data?.searchContent
|
|
255
|
-
DashXLog.d(tag: #function, "Sent searchContents with \(String(describing: json))")
|
|
256
|
-
resolve(json)
|
|
257
|
-
case .failure(let error):
|
|
258
|
-
DashXLog.d(tag: #function, "Encountered an error during searchContent(): \(error)")
|
|
259
|
-
reject("", error.localizedDescription, error)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// MARK: -- cart
|
|
264
|
-
|
|
265
|
-
func addItemToCart(
|
|
266
|
-
_ itemId: String,
|
|
267
|
-
_ pricingId: String,
|
|
268
|
-
_ quantity: String,
|
|
269
|
-
_ reset: Bool,
|
|
270
|
-
_ custom: NSDictionary?,
|
|
271
|
-
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
272
|
-
_ reject: @escaping RCTPromiseRejectBlock
|
|
273
|
-
) {
|
|
274
|
-
let addItemToCartInput = DashXGql.AddItemToCartInput(
|
|
275
|
-
accountUid: self.uid, accountAnonymousUid: self.anonymousUid, itemId: itemId, pricingId: pricingId, quantity: quantity, reset: reset, custom: custom as? [String: JSONDecodable?]
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
DashXLog.d(tag: #function, "Calling addItemToCart with \(addItemToCartInput)")
|
|
279
|
-
|
|
280
|
-
let addItemToCartMutation = DashXGql.AddItemToCartMutation(input: addItemToCartInput)
|
|
281
|
-
|
|
282
|
-
Network.shared.apollo.perform(mutation: addItemToCartMutation) { result in
|
|
283
|
-
switch result {
|
|
284
|
-
case .success(let graphQLResult):
|
|
285
|
-
let json = graphQLResult.data?.addItemToCart
|
|
286
|
-
DashXLog.d(tag: #function, "Sent addItemToCart with \(String(describing: json))")
|
|
287
|
-
resolve(json?.resultMap)
|
|
288
|
-
case .failure(let error):
|
|
289
|
-
DashXLog.d(tag: #function, "Encountered an error during addItemToCart(): \(error)")
|
|
290
|
-
reject("", error.localizedDescription, error)
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
func fetchCart(
|
|
296
|
-
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
297
|
-
_ reject: @escaping RCTPromiseRejectBlock
|
|
298
|
-
) {
|
|
299
|
-
let fetchCartInput = DashXGql.FetchCartInput(
|
|
300
|
-
accountUid: self.uid, accountAnonymousUid: self.anonymousUid
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
DashXLog.d(tag: #function, "Calling fetchCart with \(fetchCartInput)")
|
|
304
|
-
|
|
305
|
-
let fetchCartQuery = DashXGql.FetchCartQuery(input: fetchCartInput)
|
|
306
|
-
|
|
307
|
-
Network.shared.apollo.fetch(query: fetchCartQuery) { result in
|
|
308
|
-
switch result {
|
|
309
|
-
case .success(let graphQLResult):
|
|
310
|
-
let json = graphQLResult.data?.fetchCart
|
|
311
|
-
DashXLog.d(tag: #function, "Sent fetchCart with \(String(describing: json))")
|
|
312
|
-
resolve(json?.resultMap)
|
|
313
|
-
case .failure(let error):
|
|
314
|
-
DashXLog.d(tag: #function, "Encountered an error during fetchCart(): \(error)")
|
|
315
|
-
reject("", error.localizedDescription, error)
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
package/ios/DashXData.swift
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Apollo
|
|
3
|
-
|
|
4
|
-
public extension DashXGql {
|
|
5
|
-
typealias JSON = [String : Any?]
|
|
6
|
-
typealias Json = [String : Any?]
|
|
7
|
-
typealias UUID = String
|
|
8
|
-
typealias DateTime = String
|
|
9
|
-
typealias Decimal = String
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
extension String {
|
|
13
|
-
func convertToDictionary() -> [String: Any]? {
|
|
14
|
-
if let data = data(using: .utf8) {
|
|
15
|
-
return try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
|
|
16
|
-
}
|
|
17
|
-
return nil
|
|
18
|
-
}
|
|
19
|
-
}
|
package/ios/DashXLog.swift
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import os.log
|
|
3
|
-
|
|
4
|
-
class DashXLog {
|
|
5
|
-
enum LogLevel: Int {
|
|
6
|
-
case info = 1
|
|
7
|
-
case debug = 0
|
|
8
|
-
case off = -1
|
|
9
|
-
|
|
10
|
-
static func <= (lhs: Self, rhs: Self) -> Bool {
|
|
11
|
-
return lhs.rawValue <= rhs.rawValue
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
func on () -> Bool {
|
|
15
|
-
return self.rawValue > LogLevel.off.rawValue
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static private var logLevel: LogLevel = .off
|
|
20
|
-
|
|
21
|
-
static func setLogLevel(to: Int) {
|
|
22
|
-
self.logLevel = LogLevel(rawValue: to) ?? .off
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static func d(tag: String, _ data: String) {
|
|
26
|
-
if logLevel.on() && logLevel <= .debug {
|
|
27
|
-
if #available(iOS 10.0, *) {
|
|
28
|
-
os_log("%@: %@", type: .debug, tag, data)
|
|
29
|
-
} else {
|
|
30
|
-
print("%@: %@", tag, data)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static func i(tag: String, _ data: String) {
|
|
36
|
-
if logLevel.on() && logLevel <= .info {
|
|
37
|
-
if #available(iOS 10.0, *) {
|
|
38
|
-
os_log("%@: %@", type: .info, tag, data)
|
|
39
|
-
} else {
|
|
40
|
-
print("%@: %@", tag, data)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
extension UIViewController {
|
|
4
|
-
static func swizzle() {
|
|
5
|
-
let originalSelector = #selector(viewDidLoad)
|
|
6
|
-
let swizzledSelector = #selector(swizzledViewDidLoad)
|
|
7
|
-
swizzler(UIViewController.self, UIViewController.self, originalSelector, swizzledSelector)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
@objc func swizzledViewDidLoad() {
|
|
11
|
-
DashXClient.instance.track(Constants.INTERNAL_EVENT_APP_SCREEN_VIEWED, withData: [:])
|
|
12
|
-
// Call the original viewDidLoad - using the swizzledViewDidLoad signature
|
|
13
|
-
swizzledViewDidLoad()
|
|
14
|
-
}
|
|
15
|
-
}
|
package/ios/Network.swift
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Apollo
|
|
3
|
-
|
|
4
|
-
class Network {
|
|
5
|
-
static let shared = Network()
|
|
6
|
-
private var baseUri: String = "https://api.dashx.com/graphql"
|
|
7
|
-
|
|
8
|
-
func setBaseUri(to: String) {
|
|
9
|
-
self.baseUri = to
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
func getBaseUri() -> String {
|
|
13
|
-
return self.baseUri
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
private(set) lazy var apollo: ApolloClient = {
|
|
17
|
-
let client = URLSessionClient()
|
|
18
|
-
let cache = InMemoryNormalizedCache()
|
|
19
|
-
let store = ApolloStore(cache: cache)
|
|
20
|
-
let provider = NetworkInterceptorProvider(client: client, store: store)
|
|
21
|
-
let url = URL(string: baseUri)!
|
|
22
|
-
let transport = RequestChainNetworkTransport(
|
|
23
|
-
interceptorProvider: provider,
|
|
24
|
-
endpointURL: url
|
|
25
|
-
)
|
|
26
|
-
return ApolloClient(networkTransport: transport, store: store)
|
|
27
|
-
}()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class NetworkInterceptorProvider: DefaultInterceptorProvider {
|
|
31
|
-
override func interceptors<Operation: GraphQLOperation>(for operation: Operation) -> [ApolloInterceptor] {
|
|
32
|
-
var interceptors = super.interceptors(for: operation)
|
|
33
|
-
interceptors.insert(ConfigInterceptor.shared, at: 0)
|
|
34
|
-
return interceptors
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class ConfigInterceptor: ApolloInterceptor {
|
|
39
|
-
static let shared = ConfigInterceptor()
|
|
40
|
-
|
|
41
|
-
var publicKey: String?
|
|
42
|
-
var targetInstallation: String?
|
|
43
|
-
var targetEnvironment: String?
|
|
44
|
-
var identityToken: String?
|
|
45
|
-
|
|
46
|
-
func interceptAsync<Operation: GraphQLOperation>(
|
|
47
|
-
chain: RequestChain,
|
|
48
|
-
request: HTTPRequest<Operation>,
|
|
49
|
-
response: HTTPResponse<Operation>?,
|
|
50
|
-
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
|
|
51
|
-
|
|
52
|
-
if let publicKey = self.publicKey {
|
|
53
|
-
request.addHeader(name: "X-PUBLIC-KEY", value: "\(publicKey)")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if let targetInstallation = self.targetInstallation {
|
|
57
|
-
request.addHeader(name: "X-TARGET-INSTALLATION", value: "\(targetInstallation)")
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if let targetEnvironment = self.targetEnvironment {
|
|
61
|
-
request.addHeader(name: "X-TARGET-ENVIRONMENT", value: "\(targetEnvironment)")
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if let identityToken = self.identityToken {
|
|
65
|
-
request.addHeader(name: "X-IDENTITY-TOKEN", value: "\(identityToken)")
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
chain.proceedAsync(
|
|
69
|
-
request: request,
|
|
70
|
-
response: response,
|
|
71
|
-
completion: completion
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
}
|
package/ios/README.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# iOS Native Module
|
|
2
|
-
|
|
3
|
-
## Development
|
|
4
|
-
|
|
5
|
-
### Obtaining Graphql schema and generating Graphql operation
|
|
6
|
-
|
|
7
|
-
- Make sure to install Apollo CLI via npm:
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
$ npm i -g apollo
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
- In order to generate code, Apollo requires local copy of Graphql schema, to download that:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
$ apollo schema:download --endpoint="https://api.dashx.com/graphql" schema.json
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
This will save a `schama.json` file in your ios directory.
|
|
20
|
-
|
|
21
|
-
- Add Graphql request in `graphql` dir.
|
|
22
|
-
|
|
23
|
-
- Regenerate `API.swift` using:
|
|
24
|
-
|
|
25
|
-
```sh
|
|
26
|
-
$ apollo client:codegen --target=swift --namespace=DashXGql --localSchemaFile=schema.json --includes="graphql/*.graphql" --passthroughCustomScalars API.swift
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
For example, if you want to generate code for `FetchContent`.
|
|
30
|
-
|
|
31
|
-
- Download schema
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
$ apollo schema:download --endpoint="https://api.dashx.com/graphql" schema.json
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
- Add request in `graphql` dir with following contents:
|
|
38
|
-
|
|
39
|
-
```graphql
|
|
40
|
-
query FetchContent($input: FetchContentInput!) {
|
|
41
|
-
fetchContent(input: $input)
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
- Re-generate API.swift so it includes the `FetchContent` operation
|
|
46
|
-
|
|
47
|
-
```sh
|
|
48
|
-
$ apollo client:codegen --target=swift --namespace=DashXGql --localSchemaFile=schema.json --includes="graphql/*.graphql" --passthroughCustomScalars API.swift
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
- Now you can use FetchContent operation like so:
|
|
52
|
-
|
|
53
|
-
```swift
|
|
54
|
-
let fetchContentInput = DashXGql.FetchContentInput( // Note the DashXGql namespace
|
|
55
|
-
contentType: contentType,
|
|
56
|
-
content: content,
|
|
57
|
-
preview: preview,
|
|
58
|
-
language: language,
|
|
59
|
-
fields: fields,
|
|
60
|
-
include: include,
|
|
61
|
-
exclude: exclude
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
DashXLog.d(tag: #function, "Calling fetchContent with \(fetchContentInput)")
|
|
65
|
-
|
|
66
|
-
let fetchContentQuery = DashXGql.FetchContentQuery(input: fetchContentInput)
|
|
67
|
-
|
|
68
|
-
Network.shared.apollo.fetch(query: fetchContentQuery, cachePolicy: .returnCacheDataElseFetch) { result in
|
|
69
|
-
switch result {
|
|
70
|
-
case .success(let graphQLResult):
|
|
71
|
-
DashXLog.d(tag: #function, "Sent fetchContent with \(String(describing: graphQLResult))")
|
|
72
|
-
let content = graphQLResult.data?.fetchContent
|
|
73
|
-
resolve(content)
|
|
74
|
-
case .failure(let error):
|
|
75
|
-
DashXLog.d(tag: #function, "Encountered an error during fetchContent(): \(error)")
|
|
76
|
-
reject("", error.localizedDescription, error)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
|
package/ios/Utils.swift
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
let swizzler: (AnyClass, AnyClass, Selector, Selector) -> Void = { mainClass, swizzledClass, originalSelector, swizzledSelector in
|
|
4
|
-
guard let swizzledMethod = class_getInstanceMethod(swizzledClass, swizzledSelector) else {
|
|
5
|
-
return
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if let originalMethod = class_getInstanceMethod(mainClass, originalSelector) {
|
|
9
|
-
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
10
|
-
} else {
|
|
11
|
-
class_addMethod(mainClass, swizzledSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
mutation AddItemToCart($input: AddItemToCartInput!) {
|
|
2
|
-
addItemToCart(input:$input) {
|
|
3
|
-
id
|
|
4
|
-
status
|
|
5
|
-
subtotal
|
|
6
|
-
discount
|
|
7
|
-
tax
|
|
8
|
-
total
|
|
9
|
-
gatewayMeta
|
|
10
|
-
currencyCode
|
|
11
|
-
orderItems {
|
|
12
|
-
id
|
|
13
|
-
quantity
|
|
14
|
-
unitPrice
|
|
15
|
-
subtotal
|
|
16
|
-
discount
|
|
17
|
-
tax
|
|
18
|
-
total
|
|
19
|
-
custom
|
|
20
|
-
currencyCode
|
|
21
|
-
}
|
|
22
|
-
couponRedemptions {
|
|
23
|
-
coupon {
|
|
24
|
-
name
|
|
25
|
-
identifier
|
|
26
|
-
discountType
|
|
27
|
-
discountAmount
|
|
28
|
-
currencyCode
|
|
29
|
-
expiresAt
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
query FetchCart($input: FetchCartInput!) {
|
|
2
|
-
fetchCart(input:$input) {
|
|
3
|
-
id
|
|
4
|
-
status
|
|
5
|
-
subtotal
|
|
6
|
-
discount
|
|
7
|
-
tax
|
|
8
|
-
total
|
|
9
|
-
gatewayMeta
|
|
10
|
-
currencyCode
|
|
11
|
-
orderItems {
|
|
12
|
-
id
|
|
13
|
-
quantity
|
|
14
|
-
unitPrice
|
|
15
|
-
subtotal
|
|
16
|
-
discount
|
|
17
|
-
tax
|
|
18
|
-
total
|
|
19
|
-
custom
|
|
20
|
-
currencyCode
|
|
21
|
-
}
|
|
22
|
-
couponRedemptions {
|
|
23
|
-
coupon {
|
|
24
|
-
name
|
|
25
|
-
identifier
|
|
26
|
-
discountType
|
|
27
|
-
discountAmount
|
|
28
|
-
currencyCode
|
|
29
|
-
expiresAt
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|