vibes-react-native 5.0.0 → 5.0.1-rc2
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/ios/Vibes.swift +2 -3
- package/ios/VibesClient.swift +3 -4
- package/ios/VibesPluginLogger.swift +2 -5
- package/package.json +3 -2
- package/vendor/VibesPush/LICENSE +13 -0
- package/vendor/VibesPush/Sources/APIDefinition.swift +502 -0
- package/vendor/VibesPush/Sources/Actions.swift +24 -0
- package/vendor/VibesPush/Sources/AppObserver.swift +137 -0
- package/vendor/VibesPush/Sources/AuthTokenBehavior.swift +17 -0
- package/vendor/VibesPush/Sources/CombinedLogger.swift +53 -0
- package/vendor/VibesPush/Sources/ConsoleLogger.swift +97 -0
- package/vendor/VibesPush/Sources/Credential.swift +41 -0
- package/vendor/VibesPush/Sources/CredentialManager.swift +24 -0
- package/vendor/VibesPush/Sources/Date+iso8601.swift +34 -0
- package/vendor/VibesPush/Sources/Date+logPrefix.swift +20 -0
- package/vendor/VibesPush/Sources/DeviceToken.swift +15 -0
- package/vendor/VibesPush/Sources/DeviceType.swift +143 -0
- package/vendor/VibesPush/Sources/Dictionary+merged.swift +11 -0
- package/vendor/VibesPush/Sources/Event.swift +83 -0
- package/vendor/VibesPush/Sources/EventCollection.swift +36 -0
- package/vendor/VibesPush/Sources/EventTracker.swift +39 -0
- package/vendor/VibesPush/Sources/FoundationExtensions.swift +16 -0
- package/vendor/VibesPush/Sources/GitTag.swift +27 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPBehavior.swift +19 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPMethod.swift +20 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPResource.swift +69 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPResourceClient.swift +190 -0
- package/vendor/VibesPush/Sources/HTTP/JSONParser.swift +91 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/AssociatePersonOperation.swift +56 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/BaseOperation.swift +153 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/EventOperation.swift +73 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetGitTagsOperation.swift +61 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessageOperation.swift +59 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessagesOperation.swift +57 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetPersonOperation.swift +53 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetVibesAppInfoOperation.swift +45 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/MigrationCallbackOperation.swift +45 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/RegisterDeviceOperation.swift +66 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/RegisterPushOperation.swift +73 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/TrackProductActionOperation.swift +75 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/TrackPurchaseActionOperation.swift +81 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterDeviceOperation.swift +64 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterPushOperation.swift +72 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPatch.swift +57 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPut.swift +59 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateMessageOperation.swift +50 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/VibesQueueOperation.swift +76 -0
- package/vendor/VibesPush/Sources/HTTP/ResourceResult.swift +38 -0
- package/vendor/VibesPush/Sources/HTTPURLResponse+cURL.swift +16 -0
- package/vendor/VibesPush/Sources/InboxMessage.swift +219 -0
- package/vendor/VibesPush/Sources/Info.plist +26 -0
- package/vendor/VibesPush/Sources/InputStream+readToString.swift +19 -0
- package/vendor/VibesPush/Sources/KeychainStorage.swift +64 -0
- package/vendor/VibesPush/Sources/LocalObject.swift +25 -0
- package/vendor/VibesPush/Sources/LocalStorageKeys.swift +19 -0
- package/vendor/VibesPush/Sources/LocalStorageType.swift +47 -0
- package/vendor/VibesPush/Sources/LocalValue.swift +67 -0
- package/vendor/VibesPush/Sources/PersistentEventStorage.swift +81 -0
- package/vendor/VibesPush/Sources/Person.swift +98 -0
- package/vendor/VibesPush/Sources/Product.swift +103 -0
- package/vendor/VibesPush/Sources/Purchase.swift +108 -0
- package/vendor/VibesPush/Sources/TrackedEventType.swift +48 -0
- package/vendor/VibesPush/Sources/URLRequest+cURL.swift +36 -0
- package/vendor/VibesPush/Sources/UserDefaultsStorage.swift +32 -0
- package/vendor/VibesPush/Sources/Vibes.swift +1069 -0
- package/vendor/VibesPush/Sources/VibesAPI.swift +81 -0
- package/vendor/VibesPush/Sources/VibesAPIDelegate.swift +41 -0
- package/vendor/VibesPush/Sources/VibesAppInfo.swift +77 -0
- package/vendor/VibesPush/Sources/VibesConfiguration.swift +108 -0
- package/vendor/VibesPush/Sources/VibesLogger.swift +65 -0
- package/vendor/VibesPush/Sources/VibesResult.swift +78 -0
- package/vibes-react-native.podspec +6 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// A closure used as a completion handler for API requests.
|
|
4
|
+
typealias APICompletion<A> = (ResourceResult<A>) -> Void
|
|
5
|
+
|
|
6
|
+
/// A protocol that indicates the required interface for being considered an
|
|
7
|
+
/// `VibesAPI`
|
|
8
|
+
protocol VibesAPIType {
|
|
9
|
+
func request<A>(resource: HTTPResource<A>, completion: APICompletion<A>?)
|
|
10
|
+
func request<A>(authToken: String?, resource: HTTPResource<A>, completion: APICompletion<A>?)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// An API client for requesting Resources from the Vibes API. It wraps an
|
|
14
|
+
/// `HTTPResourceClientType` to layer in Vibes-specific API functionality, e.g.
|
|
15
|
+
/// handling of authentcation tokens.
|
|
16
|
+
class VibesAPI: VibesAPIType {
|
|
17
|
+
/// The HTTP client to use for making network requests.
|
|
18
|
+
private let client: HTTPResourceClientType
|
|
19
|
+
|
|
20
|
+
/// Initialize this object.
|
|
21
|
+
///
|
|
22
|
+
/// - parameters:
|
|
23
|
+
/// - client: the HTTP client to use for making network requests.
|
|
24
|
+
init(client: HTTPResourceClientType) {
|
|
25
|
+
self.client = client
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Initialize this object.
|
|
29
|
+
///
|
|
30
|
+
/// - parameters:
|
|
31
|
+
/// - url: the URL object used for creating client.
|
|
32
|
+
convenience init(url: URL) {
|
|
33
|
+
let sessionConfig = URLSessionConfiguration.default
|
|
34
|
+
sessionConfig.timeoutIntervalForRequest = 5.0
|
|
35
|
+
sessionConfig.timeoutIntervalForResource = 5.0
|
|
36
|
+
let session = URLSession(configuration: sessionConfig)
|
|
37
|
+
|
|
38
|
+
let client = HTTPResourceClient(baseURL: url, session: session) {
|
|
39
|
+
Vibes.configuredLogger
|
|
40
|
+
}
|
|
41
|
+
self.init(client: client)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Requests a resource from the Vibes API.
|
|
45
|
+
///
|
|
46
|
+
/// Use this function when making a request that does not necessitate
|
|
47
|
+
/// authentication (e.g. registering a device).
|
|
48
|
+
///
|
|
49
|
+
/// - parameters:
|
|
50
|
+
/// - resource: the resource to request from the API
|
|
51
|
+
/// - completion: a closure to receive the result of the API request
|
|
52
|
+
func request<A>(resource: HTTPResource<A>, completion: APICompletion<A>?) {
|
|
53
|
+
request(resource: resource, behavior: nil, completion: completion)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Requests a resource from the Vibes API, using an authentication token.
|
|
57
|
+
///
|
|
58
|
+
/// Use this function when making a request that does necessitate
|
|
59
|
+
/// authentication (most do).
|
|
60
|
+
///
|
|
61
|
+
/// - parameters:
|
|
62
|
+
/// - authToken: the authentication token to send along with this request
|
|
63
|
+
/// - resource: the resource to request from the API
|
|
64
|
+
/// - completion: a closure to receive the result of the API request
|
|
65
|
+
func request<A>(authToken: String?, resource: HTTPResource<A>, completion: APICompletion<A>?) {
|
|
66
|
+
let authTokenBehavior = AuthTokenBehavior(token: authToken)
|
|
67
|
+
request(resource: resource, behavior: authTokenBehavior, completion: completion)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// A helper method for requesting a resource via the API.
|
|
71
|
+
///
|
|
72
|
+
/// - parameters:
|
|
73
|
+
/// - resource: the resource to request from the API
|
|
74
|
+
/// - behavior: an `HTTPBehavior` to use when making this request
|
|
75
|
+
/// - completion: a closure to receive the result of the API request
|
|
76
|
+
private func request<A>(resource: HTTPResource<A>, behavior: HTTPBehavior?, completion: APICompletion<A>?) {
|
|
77
|
+
client.request(resource: resource, behavior: behavior) { httpResult in
|
|
78
|
+
completion?(httpResult)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VibesAPIDelegate.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Jean-Michel Barbieri on 3/8/18.
|
|
6
|
+
// Copyright © 2018 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
@objc public protocol VibesAPIDelegate {
|
|
11
|
+
/// Callback to inform SDK users of the result of the device registration
|
|
12
|
+
/// - parameters:
|
|
13
|
+
/// - deviceId: the vibes device id that uniquely identifies the registered device
|
|
14
|
+
/// - error: Registration device error
|
|
15
|
+
@objc optional func didRegisterDevice(deviceId: String?, error: Error?)
|
|
16
|
+
|
|
17
|
+
/// Callback to inform SDK users of the result of the device unregistration
|
|
18
|
+
/// - parameters:
|
|
19
|
+
/// - error: Unregistration device error
|
|
20
|
+
@objc optional func didUnregisterDevice(error: Error?)
|
|
21
|
+
|
|
22
|
+
/// Callback to inform SDK users of the result of the device push registration
|
|
23
|
+
/// - parameters:
|
|
24
|
+
/// - error: Push registration error
|
|
25
|
+
@objc optional func didRegisterPush(error: Error?)
|
|
26
|
+
|
|
27
|
+
/// Callback to inform SDK users of the result of the device push unregistration
|
|
28
|
+
/// - parameters:
|
|
29
|
+
/// - error: Push unregistration error
|
|
30
|
+
@objc optional func didUnregisterPush(error: Error?)
|
|
31
|
+
|
|
32
|
+
/// Callback to inform SDK users of the result of the device update
|
|
33
|
+
/// - parameters:
|
|
34
|
+
/// - error: Device update error
|
|
35
|
+
@objc optional func didUpdateDevice(error: Error?)
|
|
36
|
+
|
|
37
|
+
/// Callback to inform SDK users of the result of associating a person with this device
|
|
38
|
+
/// - parameters:
|
|
39
|
+
/// - error: Associate person error
|
|
40
|
+
@objc optional func didAssociatePerson(error: Error?)
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//
|
|
2
|
+
// InboxStatus.swift
|
|
3
|
+
// VibesPush
|
|
4
|
+
//
|
|
5
|
+
// Created by DHwty on 10/11/2020.
|
|
6
|
+
// Copyright © 2020 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
/// Vibes App Info
|
|
12
|
+
@objcMembers
|
|
13
|
+
public class VibesAppInfo: NSObject, JSONDecodable, LocalObjectType, JSONEncodable {
|
|
14
|
+
|
|
15
|
+
/// Local Atrributes
|
|
16
|
+
public var attributes: [String: Any] {
|
|
17
|
+
return [
|
|
18
|
+
"app_id": appId ?? "",
|
|
19
|
+
"inbox_enabled": inboxEnabled = false,
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public func encodeJSON() -> VibesJSONDictionary {
|
|
24
|
+
return [
|
|
25
|
+
"app_id": appId as AnyObject,
|
|
26
|
+
"inbox_enabled": inboxEnabled as AnyObject,
|
|
27
|
+
] as VibesJSONDictionary
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public var jsonString: String? {
|
|
31
|
+
let jsonData = try? JSONSerialization.data(withJSONObject: encodeJSON(), options: .prettyPrinted)
|
|
32
|
+
return String(data: jsonData!, encoding: .utf8)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// An uniqie identifier assosiated with the app
|
|
36
|
+
public internal(set) var appId: String!
|
|
37
|
+
/// The app inbox status
|
|
38
|
+
public internal(set) var inboxEnabled: Bool = false
|
|
39
|
+
|
|
40
|
+
override init() {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Initialize new VibesAppInfo using properties
|
|
44
|
+
///
|
|
45
|
+
/// - Parameters:
|
|
46
|
+
/// - appId: The app id
|
|
47
|
+
/// - inboxEnabled: The app inbox status
|
|
48
|
+
init(appId: String, inboxEnabled: Bool) {
|
|
49
|
+
self.appId = appId
|
|
50
|
+
self.inboxEnabled = inboxEnabled
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Initialize new VibesAppInfo from JSONObject
|
|
54
|
+
///
|
|
55
|
+
/// - Parameter json: The JSON object
|
|
56
|
+
required convenience init?(json: VibesJSONDictionary) {
|
|
57
|
+
self.init()
|
|
58
|
+
guard let appId = json["app_id"] as? String,
|
|
59
|
+
let inboxEnabled = json["inbox_enabled"] as? Bool else { return nil }
|
|
60
|
+
|
|
61
|
+
self.appId = appId
|
|
62
|
+
self.inboxEnabled = inboxEnabled
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Initialize this object using Attributes
|
|
66
|
+
///
|
|
67
|
+
/// - Parameter attributes: - The dictionary with attributes
|
|
68
|
+
public required convenience init?(attributes: [String: Any]) {
|
|
69
|
+
self.init()
|
|
70
|
+
|
|
71
|
+
guard let appId = attributes["app_id"] as? String, !appId.isEmpty,
|
|
72
|
+
let inboxEnabled = attributes["inbox_enabled"] as? Bool else { return nil }
|
|
73
|
+
|
|
74
|
+
self.appId = appId
|
|
75
|
+
self.inboxEnabled = inboxEnabled
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@objcMembers
|
|
4
|
+
public class VibesConfiguration: NSObject {
|
|
5
|
+
/// The internal console logger
|
|
6
|
+
internal static var consoleLogger: ConsoleLogger?
|
|
7
|
+
|
|
8
|
+
// MARK: Public Instance Properties
|
|
9
|
+
|
|
10
|
+
/// A unique advertising identifier for this device
|
|
11
|
+
public var advertisingId: String?
|
|
12
|
+
|
|
13
|
+
/// The default URL to hit when talking to the Vibes API
|
|
14
|
+
public let apiUrl: String
|
|
15
|
+
|
|
16
|
+
/// The default tracking URL to hit when talking to the Vibes API
|
|
17
|
+
public var trackingApiUrl: String
|
|
18
|
+
|
|
19
|
+
/// The logger to use.
|
|
20
|
+
public var logger: CombinedLogger?
|
|
21
|
+
|
|
22
|
+
/// Storage to store credential
|
|
23
|
+
public let storageType: VibesStorageEnum
|
|
24
|
+
|
|
25
|
+
/// Array for Objc interoperability , type of tracking
|
|
26
|
+
public var trackedEventTypes: NSArray
|
|
27
|
+
|
|
28
|
+
public var vibesAPIURL: URL {
|
|
29
|
+
if let url = URL(string: apiUrl) {
|
|
30
|
+
return url
|
|
31
|
+
} else {
|
|
32
|
+
return URL(string: VibesConfiguration.defaultApiUrl)!
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public var vibesTrackingAPIURL: URL {
|
|
37
|
+
if let url = URL(string: trackingApiUrl) {
|
|
38
|
+
return url
|
|
39
|
+
} else {
|
|
40
|
+
return URL(string: VibesConfiguration.defaultTrackingApiUrl)!
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// MARK: Private Static Properties
|
|
45
|
+
|
|
46
|
+
/// The default URL to hit when talking to the Vibes API
|
|
47
|
+
private static let defaultApiUrl = "https://public-api.vibescm.com/mobile_apps"
|
|
48
|
+
|
|
49
|
+
/// TThe default URL to use to talk to EU Vibes environment, if not overridden by client settings.
|
|
50
|
+
private static let europeApiUrl = "https://public-api.vibescmeurope.com/mobile_apps"
|
|
51
|
+
|
|
52
|
+
/// The default URL to use to send tracking info to Vibes, if not overridden by client settings.
|
|
53
|
+
private static let defaultTrackingApiUrl = "https://tagtracking.vibescm.com/track"
|
|
54
|
+
|
|
55
|
+
/// The default URL to use to send tracking info to EU Vibes environment
|
|
56
|
+
private static let europeTrackingApiUrl = "https://tagtracking.eu.vibes.com/track"
|
|
57
|
+
|
|
58
|
+
/// Enable Developer Logging which will print logs to the console.
|
|
59
|
+
///
|
|
60
|
+
/// - Parameter level: The minimum Log level, Default is `.verbose`
|
|
61
|
+
public func enableDevLogging(level: LogLevel = .verbose) {
|
|
62
|
+
VibesConfiguration.consoleLogger = ConsoleLogger(level: level)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Disable Developer Logging
|
|
66
|
+
public func disableDevLogging() {
|
|
67
|
+
VibesConfiguration.consoleLogger = nil
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
///
|
|
71
|
+
/// Configure paramenters for Vibes instance.
|
|
72
|
+
///
|
|
73
|
+
/// - parameters:
|
|
74
|
+
/// - advertisingId: AdSupport.advertisingId. If the application doesn't
|
|
75
|
+
/// support it nil will be sent as value to the backend.
|
|
76
|
+
/// - apiUrl: An optional URL to hit for accessing for the Vibes API; if not
|
|
77
|
+
/// present, the staging URL will be used.
|
|
78
|
+
/// - trackingApiUrl: An optional URL to hit for accessing for the Vibes Tracking API ; if not
|
|
79
|
+
/// present, the staging URL will be used.
|
|
80
|
+
/// - logger: The logger to use, in addition to`ConsoleLogger`. if enabled.
|
|
81
|
+
/// You can enable console logging with `Vibes.shared.configuration.enableDevLogging()`
|
|
82
|
+
/// and disable with `Vibes.shared.configuration.disableDevLogging()` at any point.
|
|
83
|
+
/// - storageType: define the type of storage for storing data locally; if not
|
|
84
|
+
/// present, data will be securely stored in the Keychain.
|
|
85
|
+
/// - trackedEventTypes: NSArray for Objc interoperability , type of tracking
|
|
86
|
+
/// events sent to Vibes; if not present, all events type (`.launch`,
|
|
87
|
+
/// `.clickthru` e.t.c) will be monitored.
|
|
88
|
+
///
|
|
89
|
+
public init(advertisingId: String? = nil,
|
|
90
|
+
apiUrl: String? = nil,
|
|
91
|
+
trackingApiUrl: String? = nil,
|
|
92
|
+
logger: VibesLogger? = nil,
|
|
93
|
+
storageType: VibesStorageEnum = .KEYCHAIN,
|
|
94
|
+
trackedEventTypes: NSArray = TrackedEventType.all as NSArray) {
|
|
95
|
+
self.advertisingId = advertisingId
|
|
96
|
+
self.apiUrl = apiUrl ?? VibesConfiguration.defaultApiUrl
|
|
97
|
+
if let apiUrl = apiUrl,
|
|
98
|
+
let trackingApiUrl = trackingApiUrl,
|
|
99
|
+
apiUrl.contains("vibescmeurope.com") && !trackingApiUrl.contains("eu.vibes.com") {
|
|
100
|
+
self.trackingApiUrl = VibesConfiguration.europeTrackingApiUrl
|
|
101
|
+
} else {
|
|
102
|
+
self.trackingApiUrl = trackingApiUrl ?? VibesConfiguration.defaultTrackingApiUrl
|
|
103
|
+
}
|
|
104
|
+
self.logger = CombinedLogger(customLogger: logger)
|
|
105
|
+
self.storageType = storageType
|
|
106
|
+
self.trackedEventTypes = trackedEventTypes
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// A protocol for logging the Vibes SDK's HTTP-related logs
|
|
4
|
+
@objc public protocol VibesLogger {
|
|
5
|
+
/// Logs a message to the logger if the `logObject.level` matches or is above the configured log `level`
|
|
6
|
+
///
|
|
7
|
+
/// - Parameters:
|
|
8
|
+
/// - logObject: The Log object with log `level` and specified log `message`.
|
|
9
|
+
@objc func log(_ logObject: LogObject)
|
|
10
|
+
|
|
11
|
+
/// Logs an HTTP request.
|
|
12
|
+
///
|
|
13
|
+
/// - parameters:
|
|
14
|
+
/// - request: the HTTP request to log
|
|
15
|
+
@objc func log(request: URLRequest)
|
|
16
|
+
|
|
17
|
+
/// Logs an HTTP response with its accompanying data.
|
|
18
|
+
///
|
|
19
|
+
/// - parameters:
|
|
20
|
+
/// - response: the HTTP response to log
|
|
21
|
+
/// - data: the data received, if any
|
|
22
|
+
@objc func log(response: URLResponse, data: Data?)
|
|
23
|
+
|
|
24
|
+
/// Logs an error.
|
|
25
|
+
///
|
|
26
|
+
/// - parameters:
|
|
27
|
+
/// - error: the error that occurred
|
|
28
|
+
@objc func log(error: Error)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Log Object with log `level` and `message`
|
|
32
|
+
@objc public class LogObject: NSObject {
|
|
33
|
+
/// The Log leve
|
|
34
|
+
@objc public let level: LogLevel
|
|
35
|
+
/// The log message
|
|
36
|
+
@objc public let message: String
|
|
37
|
+
|
|
38
|
+
public init(_ level: LogLevel, message: String) {
|
|
39
|
+
self.level = level
|
|
40
|
+
self.message = message
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// A simple enum for specifying desired log level
|
|
45
|
+
@objc public enum LogLevel: Int {
|
|
46
|
+
/// All requests and their info (endpoint, header, body, etc.), and errors
|
|
47
|
+
case verbose = 0
|
|
48
|
+
|
|
49
|
+
/// Request method and endpoint, and errors
|
|
50
|
+
case info
|
|
51
|
+
|
|
52
|
+
/// Only errors
|
|
53
|
+
case error
|
|
54
|
+
|
|
55
|
+
public var logPrefix: String {
|
|
56
|
+
switch self {
|
|
57
|
+
case .verbose:
|
|
58
|
+
return "VERBOSE"
|
|
59
|
+
case .info:
|
|
60
|
+
return "INFO"
|
|
61
|
+
default:
|
|
62
|
+
return "ERROR"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// A custom error enum that indicates why a Vibes operation has failed.
|
|
2
|
+
public enum VibesError: Error {
|
|
3
|
+
/// An error indicating that the request could not be performed because
|
|
4
|
+
/// the device credentials are not available. This may indicate that the call
|
|
5
|
+
/// to `registerDevice` never completed successfully.
|
|
6
|
+
case noCredentials
|
|
7
|
+
|
|
8
|
+
/// An error indicating that the request could not be performed because
|
|
9
|
+
/// the device's push token is not available. This may indicate that the call
|
|
10
|
+
/// to `setPushToken` was never made.
|
|
11
|
+
case noPushToken
|
|
12
|
+
|
|
13
|
+
/// An error indicating that the request could not be performed because
|
|
14
|
+
/// authorization has failed.
|
|
15
|
+
case authFailed(String)
|
|
16
|
+
|
|
17
|
+
/// An error indicating that we have attempted to track an array containing
|
|
18
|
+
/// no events.
|
|
19
|
+
case noEvents
|
|
20
|
+
|
|
21
|
+
/// An error indicating that we have attempted to track an array containing
|
|
22
|
+
/// events with multiple types.
|
|
23
|
+
case tooManyEventTypes
|
|
24
|
+
|
|
25
|
+
/// A catch-all error, for issues that don't fall into other cases.
|
|
26
|
+
case other(String)
|
|
27
|
+
|
|
28
|
+
/// A friendly human-readable description of the error that occurred.
|
|
29
|
+
public var description: String {
|
|
30
|
+
switch self {
|
|
31
|
+
case .noCredentials:
|
|
32
|
+
return "There are no available credentials"
|
|
33
|
+
case .noPushToken:
|
|
34
|
+
return "There is no push token available"
|
|
35
|
+
case .noEvents:
|
|
36
|
+
return "There are no events to track"
|
|
37
|
+
case .tooManyEventTypes:
|
|
38
|
+
return "Too many types of events - can only handle one type at a time"
|
|
39
|
+
case .authFailed(let details):
|
|
40
|
+
return "Authentication failed: \(details)"
|
|
41
|
+
case .other(let details):
|
|
42
|
+
return "Error: \(details)"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// A generic result object to created a tagged union of success or failure for
|
|
48
|
+
/// completion a Vibes operation.
|
|
49
|
+
public enum VibesResult<T> {
|
|
50
|
+
/// Used to indicate that a Vibes operation was successful
|
|
51
|
+
case success(T)
|
|
52
|
+
|
|
53
|
+
/// Used to indicate that the Vibes operation failed; the reason why is
|
|
54
|
+
/// attached as aa `VibesError`
|
|
55
|
+
case failure(VibesError)
|
|
56
|
+
|
|
57
|
+
/// Create a VibesResult from a ResourceResult. This keeps our public API
|
|
58
|
+
/// separate from our internal ones.
|
|
59
|
+
///
|
|
60
|
+
/// - parameters:
|
|
61
|
+
/// - result: a ResourceResult to convert into a VibesResult
|
|
62
|
+
init(_ result: ResourceResult<T>) {
|
|
63
|
+
switch result {
|
|
64
|
+
case .success(let value):
|
|
65
|
+
self = VibesResult<T>.success(value)
|
|
66
|
+
case .failure(let error):
|
|
67
|
+
switch error {
|
|
68
|
+
case .invalidResponse(let statusCode, let responseText) where statusCode == 401:
|
|
69
|
+
self = VibesResult<T>.failure(.authFailed(responseText))
|
|
70
|
+
case .invalidResponse(let statusCode, let responseText):
|
|
71
|
+
let description = "[HTTP \(statusCode)]: \(responseText)"
|
|
72
|
+
self = VibesResult<T>.failure(.other(description))
|
|
73
|
+
default:
|
|
74
|
+
self = VibesResult<T>.failure(.other("\(error)"))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -11,10 +11,14 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
13
|
s.platforms = { :ios => "15.6" }
|
|
14
|
+
s.swift_version = "5.0"
|
|
14
15
|
s.source = { :git => "https://github.com/vibes/vibes-react-native.git", :tag => "#{s.version}" }
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
# Compile the iOS SDK into this pod so `pod install` does not need
|
|
18
|
+
# VibesPush on CocoaPods trunk. App targets can still `import VibesPush`.
|
|
19
|
+
s.module_name = "VibesPush"
|
|
20
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}", "vendor/VibesPush/Sources/**/*.swift"
|
|
21
|
+
s.frameworks = "Foundation", "UIKit"
|
|
17
22
|
|
|
18
23
|
s.dependency "React-Core"
|
|
19
|
-
s.dependency "VibesPush", "5.0.0"
|
|
20
24
|
end
|