@viafoura/sdk-react-native 0.1.0
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/README.md +40 -0
- package/android/build.gradle +48 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/viafourasdk/NewCommentModule.kt +27 -0
- package/android/src/main/java/expo/modules/viafourasdk/NewCommentView.kt +153 -0
- package/android/src/main/java/expo/modules/viafourasdk/PreviewCommentsModule.kt +26 -0
- package/android/src/main/java/expo/modules/viafourasdk/PreviewCommentsView.kt +157 -0
- package/android/src/main/java/expo/modules/viafourasdk/ProfileModule.kt +21 -0
- package/android/src/main/java/expo/modules/viafourasdk/ProfileView.kt +134 -0
- package/android/src/main/java/expo/modules/viafourasdk/ViafouraModule.kt +123 -0
- package/build/NewCommentView.d.ts +4 -0
- package/build/NewCommentView.d.ts.map +1 -0
- package/build/NewCommentView.js +13 -0
- package/build/NewCommentView.js.map +1 -0
- package/build/PreviewCommentsView.d.ts +4 -0
- package/build/PreviewCommentsView.d.ts.map +1 -0
- package/build/PreviewCommentsView.js +7 -0
- package/build/PreviewCommentsView.js.map +1 -0
- package/build/ProfileView.d.ts +4 -0
- package/build/ProfileView.d.ts.map +1 -0
- package/build/ProfileView.js +13 -0
- package/build/ProfileView.js.map +1 -0
- package/build/Viafoura.types.d.ts +92 -0
- package/build/Viafoura.types.d.ts.map +1 -0
- package/build/Viafoura.types.js +2 -0
- package/build/Viafoura.types.js.map +1 -0
- package/build/ViafouraModule.d.ts +15 -0
- package/build/ViafouraModule.d.ts.map +1 -0
- package/build/ViafouraModule.js +3 -0
- package/build/ViafouraModule.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +14 -0
- package/ios/PreviewCommentsModule.swift +195 -0
- package/ios/Viafoura.podspec +30 -0
- package/ios/ViafouraModule.swift +281 -0
- package/package.json +56 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
// Optional Viafoura SDK import. Code is guarded to build without it.
|
|
4
|
+
#if canImport(ViafouraSDK)
|
|
5
|
+
import ViafouraSDK
|
|
6
|
+
|
|
7
|
+
enum VFAdapterError: Error, LocalizedError {
|
|
8
|
+
case invalidProvider
|
|
9
|
+
case invalidInitialization
|
|
10
|
+
|
|
11
|
+
var errorDescription: String? {
|
|
12
|
+
switch self {
|
|
13
|
+
case .invalidProvider:
|
|
14
|
+
return "Invalid social login provider"
|
|
15
|
+
case .invalidInitialization:
|
|
16
|
+
return "Invalid Viafoura initialization parameters"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
struct VFAuthAdapter {
|
|
22
|
+
private let authService = ViafouraSDK.auth()
|
|
23
|
+
|
|
24
|
+
func logout() {
|
|
25
|
+
authService.logout()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func login(email: String, password: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
29
|
+
authService.login(email: email, password: password) { result in
|
|
30
|
+
switch result {
|
|
31
|
+
case .success:
|
|
32
|
+
completion(.success(()))
|
|
33
|
+
case .failure(let error):
|
|
34
|
+
completion(.failure(error))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func signup(name: String, email: String, password: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
40
|
+
authService.signup(name: name, email: email, password: password, recaptchaToken: nil) { result in
|
|
41
|
+
switch result {
|
|
42
|
+
case .success:
|
|
43
|
+
completion(.success(()))
|
|
44
|
+
case .failure(let error):
|
|
45
|
+
completion(.failure(error))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func socialLogin(token: String, provider: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
51
|
+
guard let p = VFSocialLoginProvider(rawValue: provider) else {
|
|
52
|
+
completion(.failure(VFAdapterError.invalidProvider))
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
authService.socialLogin(token: token, provider: p) { result in
|
|
56
|
+
switch result {
|
|
57
|
+
case .success:
|
|
58
|
+
completion(.success(()))
|
|
59
|
+
case .failure(let error):
|
|
60
|
+
completion(.failure(error))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func openIdLogin(token: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
66
|
+
authService.openIdLogin(token: token) { result in
|
|
67
|
+
switch result {
|
|
68
|
+
case .success:
|
|
69
|
+
completion(.success(()))
|
|
70
|
+
case .failure(let error):
|
|
71
|
+
completion(.failure(error))
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func cookieLogin(token: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
77
|
+
authService.cookieLogin(token: token) { result in
|
|
78
|
+
switch result {
|
|
79
|
+
case .success:
|
|
80
|
+
completion(.success(()))
|
|
81
|
+
case .failure(let error):
|
|
82
|
+
completion(.failure(error))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
func resetPassword(email: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
88
|
+
authService.resetPassword(email: email) { result in
|
|
89
|
+
switch result {
|
|
90
|
+
case .success:
|
|
91
|
+
completion(.success(()))
|
|
92
|
+
case .failure(let error):
|
|
93
|
+
completion(.failure(error))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
struct VFCoreAdapter {
|
|
100
|
+
func initialize(siteUUID: String, siteDomain: String, enableLogging: Bool?) {
|
|
101
|
+
if let enableLogging {
|
|
102
|
+
ViafouraSDK.setLoggingEnabled(enableLogging)
|
|
103
|
+
}
|
|
104
|
+
ViafouraSDK.initialize(siteUUID: siteUUID, siteDomain: siteDomain)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#else
|
|
109
|
+
|
|
110
|
+
enum VFAdapterError: Error, LocalizedError {
|
|
111
|
+
case sdkUnavailable
|
|
112
|
+
case invalidProvider
|
|
113
|
+
case invalidInitialization
|
|
114
|
+
|
|
115
|
+
var errorDescription: String? {
|
|
116
|
+
switch self {
|
|
117
|
+
case .sdkUnavailable:
|
|
118
|
+
return "ViafouraSDK is not installed. Add the iOS SDK to enable auth."
|
|
119
|
+
case .invalidProvider:
|
|
120
|
+
return "Invalid social login provider"
|
|
121
|
+
case .invalidInitialization:
|
|
122
|
+
return "Invalid Viafoura initialization parameters"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
struct VFAuthAdapter {
|
|
128
|
+
func logout() { /* no-op when SDK unavailable */ }
|
|
129
|
+
|
|
130
|
+
func login(email: String, password: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
131
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
func signup(name: String, email: String, password: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
135
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
func socialLogin(token: String, provider: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
139
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
func openIdLogin(token: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
143
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func cookieLogin(token: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
147
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func resetPassword(email: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
151
|
+
completion(.failure(VFAdapterError.sdkUnavailable))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
struct VFCoreAdapter {
|
|
156
|
+
func initialize(siteUUID: String, siteDomain: String, enableLogging: Bool?) {
|
|
157
|
+
// no-op
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#endif
|
|
162
|
+
|
|
163
|
+
public class ViafouraModule: Module {
|
|
164
|
+
private let auth = VFAuthAdapter()
|
|
165
|
+
private let core = VFCoreAdapter()
|
|
166
|
+
|
|
167
|
+
// Each module class must implement the definition function. The definition consists of components
|
|
168
|
+
// that describes the module's functionality and behavior.
|
|
169
|
+
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
170
|
+
public func definition() -> ModuleDefinition {
|
|
171
|
+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
172
|
+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
173
|
+
// The module will be accessible from `requireNativeModule('Viafoura')` in JavaScript.
|
|
174
|
+
Name("Viafoura")
|
|
175
|
+
|
|
176
|
+
// Defines constant property on the module.
|
|
177
|
+
Constant("PI") {
|
|
178
|
+
Double.pi
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Defines event names that the module can send to JavaScript.
|
|
182
|
+
Events("onChange")
|
|
183
|
+
|
|
184
|
+
// MARK: - Auth API
|
|
185
|
+
AsyncFunction("logout") {
|
|
186
|
+
self.auth.logout()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
AsyncFunction("login") { (email: String, password: String) async throws in
|
|
190
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
191
|
+
self.auth.login(email: email, password: password) { result in
|
|
192
|
+
switch result {
|
|
193
|
+
case .success:
|
|
194
|
+
continuation.resume()
|
|
195
|
+
case .failure(let error):
|
|
196
|
+
continuation.resume(throwing: error)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
AsyncFunction("signup") { (name: String, email: String, password: String) async throws in
|
|
203
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
204
|
+
self.auth.signup(name: name, email: email, password: password) { result in
|
|
205
|
+
switch result {
|
|
206
|
+
case .success:
|
|
207
|
+
continuation.resume()
|
|
208
|
+
case .failure(let error):
|
|
209
|
+
continuation.resume(throwing: error)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
AsyncFunction("socialLogin") { (token: String, provider: String?) async throws in
|
|
216
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
217
|
+
guard let provider = provider, !provider.isEmpty else {
|
|
218
|
+
continuation.resume(throwing: VFAdapterError.invalidProvider)
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
self.auth.socialLogin(token: token, provider: provider) { result in
|
|
222
|
+
switch result {
|
|
223
|
+
case .success:
|
|
224
|
+
continuation.resume()
|
|
225
|
+
case .failure(let error):
|
|
226
|
+
continuation.resume(throwing: error)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
AsyncFunction("openIdLogin") { (token: String) async throws in
|
|
233
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
234
|
+
self.auth.openIdLogin(token: token) { result in
|
|
235
|
+
switch result {
|
|
236
|
+
case .success:
|
|
237
|
+
continuation.resume()
|
|
238
|
+
case .failure(let error):
|
|
239
|
+
continuation.resume(throwing: error)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
AsyncFunction("cookieLogin") { (token: String) async throws in
|
|
246
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
247
|
+
self.auth.cookieLogin(token: token) { result in
|
|
248
|
+
switch result {
|
|
249
|
+
case .success:
|
|
250
|
+
continuation.resume()
|
|
251
|
+
case .failure(let error):
|
|
252
|
+
continuation.resume(throwing: error)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
AsyncFunction("resetPassword") { (email: String) async throws in
|
|
259
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
260
|
+
self.auth.resetPassword(email: email) { result in
|
|
261
|
+
switch result {
|
|
262
|
+
case .success:
|
|
263
|
+
continuation.resume()
|
|
264
|
+
case .failure(let error):
|
|
265
|
+
continuation.resume(throwing: error)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// MARK: - Core API
|
|
272
|
+
AsyncFunction("initialize") { (siteUUID: String, siteDomain: String, enableLogging: Bool?) async throws in
|
|
273
|
+
guard !siteUUID.isEmpty, !siteDomain.isEmpty else {
|
|
274
|
+
throw VFAdapterError.invalidInitialization
|
|
275
|
+
}
|
|
276
|
+
self.core.initialize(siteUUID: siteUUID, siteDomain: siteDomain, enableLogging: enableLogging)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// No additional native view here. PreviewComments is exposed via a separate module.
|
|
280
|
+
}
|
|
281
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viafoura/sdk-react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "My new module",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"open:ios": "xed ../../example/ios",
|
|
16
|
+
"open:android": "open -a \"Android Studio\" ../../example/android"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"expo",
|
|
21
|
+
"viafoura-sdk",
|
|
22
|
+
"Viafoura"
|
|
23
|
+
],
|
|
24
|
+
"repository": "https://github.com/viafoura/sdk-react-native",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/viafoura/sdk-react-native/issues"
|
|
27
|
+
},
|
|
28
|
+
"author": "Viafoura <support@viafoura.com> ()",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://github.com/viafoura/sdk-react-native#readme",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"build",
|
|
36
|
+
"ios",
|
|
37
|
+
"android",
|
|
38
|
+
"expo-module.config.json",
|
|
39
|
+
"README.md",
|
|
40
|
+
"package.json"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "~19.1.0",
|
|
45
|
+
"@types/invariant": "^2.2.35",
|
|
46
|
+
"expo-module-scripts": "^5.0.7",
|
|
47
|
+
"expo": "^54.0.12",
|
|
48
|
+
"react-native": "0.81.4"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"expo": "*",
|
|
52
|
+
"expo-modules-core": "*",
|
|
53
|
+
"react": "*",
|
|
54
|
+
"react-native": "*"
|
|
55
|
+
}
|
|
56
|
+
}
|