@octopus-community/react-native 1.0.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.
Files changed (106) hide show
  1. package/LICENSE.md +143 -0
  2. package/OctopusReactNativeSdk.podspec +33 -0
  3. package/README.md +161 -0
  4. package/android/build.gradle +92 -0
  5. package/android/gradle.properties +9 -0
  6. package/android/src/main/AndroidManifest.xml +9 -0
  7. package/android/src/main/AndroidManifestNew.xml +8 -0
  8. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusEventEmitter.kt +48 -0
  9. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactNativeSdkModule.kt +73 -0
  10. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactNativeSdkPackage.kt +17 -0
  11. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSDKInitializer.kt +55 -0
  12. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSSOAuthenticator.kt +124 -0
  13. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIActivity.kt +71 -0
  14. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIController.kt +34 -0
  15. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/ProfileFieldMapper.kt +39 -0
  16. package/ios/OctopusEventManager.swift +44 -0
  17. package/ios/OctopusReactNativeSdk-Bridging-Header.h +3 -0
  18. package/ios/OctopusReactNativeSdk.mm +37 -0
  19. package/ios/OctopusReactNativeSdk.swift +148 -0
  20. package/ios/OctopusSDKInitializer.swift +62 -0
  21. package/ios/OctopusSSOAuthenticator.swift +157 -0
  22. package/ios/OctopusUIManager.swift +40 -0
  23. package/ios/ProfileFieldMapper.swift +43 -0
  24. package/lib/module/addEditUserListener.js +13 -0
  25. package/lib/module/addEditUserListener.js.map +1 -0
  26. package/lib/module/addLoginRequiredListener.js +14 -0
  27. package/lib/module/addLoginRequiredListener.js.map +1 -0
  28. package/lib/module/addUserTokenRequestListener.js +26 -0
  29. package/lib/module/addUserTokenRequestListener.js.map +1 -0
  30. package/lib/module/closeUI.js +11 -0
  31. package/lib/module/closeUI.js.map +1 -0
  32. package/lib/module/connectUser.js +14 -0
  33. package/lib/module/connectUser.js.map +1 -0
  34. package/lib/module/disconnectUser.js +7 -0
  35. package/lib/module/disconnectUser.js.map +1 -0
  36. package/lib/module/enums/LogLevel.enum.js +13 -0
  37. package/lib/module/enums/LogLevel.enum.js.map +1 -0
  38. package/lib/module/index.js +15 -0
  39. package/lib/module/index.js.map +1 -0
  40. package/lib/module/initialize.js +38 -0
  41. package/lib/module/initialize.js.map +1 -0
  42. package/lib/module/internals/eventEmitter.js +6 -0
  43. package/lib/module/internals/eventEmitter.js.map +1 -0
  44. package/lib/module/internals/logger.js +42 -0
  45. package/lib/module/internals/logger.js.map +1 -0
  46. package/lib/module/internals/nativeModule.js +13 -0
  47. package/lib/module/internals/nativeModule.js.map +1 -0
  48. package/lib/module/logger.js +4 -0
  49. package/lib/module/logger.js.map +1 -0
  50. package/lib/module/openUI.js +11 -0
  51. package/lib/module/openUI.js.map +1 -0
  52. package/lib/module/package.json +1 -0
  53. package/lib/module/types/userProfileField.js +2 -0
  54. package/lib/module/types/userProfileField.js.map +1 -0
  55. package/lib/module/useUserTokenProvider.js +33 -0
  56. package/lib/module/useUserTokenProvider.js.map +1 -0
  57. package/lib/typescript/package.json +1 -0
  58. package/lib/typescript/src/addEditUserListener.d.ts +14 -0
  59. package/lib/typescript/src/addEditUserListener.d.ts.map +1 -0
  60. package/lib/typescript/src/addLoginRequiredListener.d.ts +10 -0
  61. package/lib/typescript/src/addLoginRequiredListener.d.ts.map +1 -0
  62. package/lib/typescript/src/addUserTokenRequestListener.d.ts +10 -0
  63. package/lib/typescript/src/addUserTokenRequestListener.d.ts.map +1 -0
  64. package/lib/typescript/src/closeUI.d.ts +5 -0
  65. package/lib/typescript/src/closeUI.d.ts.map +1 -0
  66. package/lib/typescript/src/connectUser.d.ts +30 -0
  67. package/lib/typescript/src/connectUser.d.ts.map +1 -0
  68. package/lib/typescript/src/disconnectUser.d.ts +2 -0
  69. package/lib/typescript/src/disconnectUser.d.ts.map +1 -0
  70. package/lib/typescript/src/enums/LogLevel.enum.d.ts +10 -0
  71. package/lib/typescript/src/enums/LogLevel.enum.d.ts.map +1 -0
  72. package/lib/typescript/src/index.d.ts +13 -0
  73. package/lib/typescript/src/index.d.ts.map +1 -0
  74. package/lib/typescript/src/initialize.d.ts +50 -0
  75. package/lib/typescript/src/initialize.d.ts.map +1 -0
  76. package/lib/typescript/src/internals/eventEmitter.d.ts +3 -0
  77. package/lib/typescript/src/internals/eventEmitter.d.ts.map +1 -0
  78. package/lib/typescript/src/internals/logger.d.ts +20 -0
  79. package/lib/typescript/src/internals/logger.d.ts.map +1 -0
  80. package/lib/typescript/src/internals/nativeModule.d.ts +2 -0
  81. package/lib/typescript/src/internals/nativeModule.d.ts.map +1 -0
  82. package/lib/typescript/src/logger.d.ts +3 -0
  83. package/lib/typescript/src/logger.d.ts.map +1 -0
  84. package/lib/typescript/src/openUI.d.ts +5 -0
  85. package/lib/typescript/src/openUI.d.ts.map +1 -0
  86. package/lib/typescript/src/types/userProfileField.d.ts +14 -0
  87. package/lib/typescript/src/types/userProfileField.d.ts.map +1 -0
  88. package/lib/typescript/src/useUserTokenProvider.d.ts +17 -0
  89. package/lib/typescript/src/useUserTokenProvider.d.ts.map +1 -0
  90. package/package.json +136 -0
  91. package/src/addEditUserListener.ts +19 -0
  92. package/src/addLoginRequiredListener.ts +16 -0
  93. package/src/addUserTokenRequestListener.ts +32 -0
  94. package/src/closeUI.ts +8 -0
  95. package/src/connectUser.ts +34 -0
  96. package/src/disconnectUser.ts +5 -0
  97. package/src/enums/LogLevel.enum.ts +9 -0
  98. package/src/index.ts +12 -0
  99. package/src/initialize.ts +56 -0
  100. package/src/internals/eventEmitter.ts +4 -0
  101. package/src/internals/logger.ts +60 -0
  102. package/src/internals/nativeModule.ts +18 -0
  103. package/src/logger.ts +7 -0
  104. package/src/openUI.ts +8 -0
  105. package/src/types/userProfileField.ts +13 -0
  106. package/src/useUserTokenProvider.ts +36 -0
@@ -0,0 +1,157 @@
1
+ import Octopus
2
+
3
+ class OctopusSSOAuthenticator {
4
+ private weak var octopusSDK: OctopusSDK?
5
+ private weak var eventManager: OctopusEventManager?
6
+ private var pendingTokenRequests: [String: CheckedContinuation<String, Error>] = [:]
7
+
8
+ init(octopusSDK: OctopusSDK, eventManager: OctopusEventManager) {
9
+ self.octopusSDK = octopusSDK
10
+ self.eventManager = eventManager
11
+ }
12
+
13
+ func connectUser(params: [String: Any]) async throws {
14
+ guard let octopus = octopusSDK else {
15
+ throw AuthenticationError.sdkNotInitialized
16
+ }
17
+
18
+ do {
19
+ let clientUser = try await parseClientUser(from: params)
20
+ octopus.connectUser(clientUser) {
21
+ return try await self.requestTokenFromRN()
22
+ }
23
+ } catch let error as AuthenticationError {
24
+ throw error
25
+ } catch {
26
+ throw AuthenticationError.unknownError(error)
27
+ }
28
+ }
29
+
30
+ func completeTokenRequest(requestId: String, token: String) {
31
+ if let continuation = pendingTokenRequests.removeValue(forKey: requestId) {
32
+ continuation.resume(returning: token)
33
+ }
34
+ }
35
+
36
+ func cancelTokenRequest(requestId: String) {
37
+ if let continuation = pendingTokenRequests.removeValue(forKey: requestId) {
38
+ continuation.resume(throwing: CancellationError())
39
+ }
40
+ }
41
+
42
+ private func requestTokenFromRN() async throws -> String {
43
+ let requestId = UUID().uuidString
44
+
45
+ return try await withCheckedThrowingContinuation { continuation in
46
+ pendingTokenRequests[requestId] = continuation
47
+ eventManager?.emitUserTokenRequest(requestId: requestId)
48
+ }
49
+ }
50
+
51
+ func disconnectUser() throws {
52
+ guard let octopus = octopusSDK else {
53
+ throw AuthenticationError.sdkNotInitialized
54
+ }
55
+
56
+ octopus.disconnectUser()
57
+
58
+ // Cancel all pending token requests
59
+ for (_, continuation) in pendingTokenRequests {
60
+ continuation.resume(throwing: CancellationError())
61
+ }
62
+ pendingTokenRequests.removeAll()
63
+ }
64
+
65
+ private func parseClientUser(from params: [String: Any]) async throws -> ClientUser {
66
+ guard let userId = params["userId"] as? String else {
67
+ throw AuthenticationError.invalidUserParams
68
+ }
69
+
70
+ let profile = try await parseUserProfile(from: params["profile"] as? [String: Any])
71
+
72
+ return ClientUser(
73
+ userId: userId,
74
+ profile: profile
75
+ )
76
+ }
77
+
78
+ private func parseUserProfile(from profileParams: [String: Any]?) async throws -> ClientUser.Profile {
79
+ guard let profileParams = profileParams else {
80
+ return ClientUser.Profile()
81
+ }
82
+
83
+ let username = profileParams["username"] as? String
84
+ let biography = profileParams["biography"] as? String
85
+ let legalAgeReached = profileParams["legalAgeReached"] as? Bool
86
+
87
+ let ageInformation: ClientUser.AgeInformation? = legalAgeReached != nil ? (legalAgeReached! ? .legalAgeReached : .underaged) : nil
88
+
89
+ var profilePictureData: Data? = nil
90
+ if let pictureUrl = profileParams["profilePicture"] as? String {
91
+ profilePictureData = try await loadImageData(from: pictureUrl)
92
+ }
93
+
94
+ return ClientUser.Profile(
95
+ nickname: username,
96
+ bio: biography,
97
+ picture: profilePictureData,
98
+ ageInformation: ageInformation
99
+ )
100
+ }
101
+
102
+ private func loadImageData(from urlString: String) async throws -> Data? {
103
+ if urlString.hasPrefix("http://") || urlString.hasPrefix("https://") {
104
+ guard let url = URL(string: urlString) else { return nil }
105
+ do {
106
+ let (data, _) = try await URLSession.shared.data(from: url)
107
+ return data
108
+ } catch {
109
+ throw AuthenticationError.profilePictureLoadError
110
+ }
111
+ } else if urlString.hasPrefix("file://") {
112
+ guard let url = URL(string: urlString) else { return nil }
113
+ return try await withCheckedThrowingContinuation { continuation in
114
+ DispatchQueue.global(qos: .userInitiated).async {
115
+ do {
116
+ let data = try Data(contentsOf: url)
117
+ continuation.resume(returning: data)
118
+ } catch {
119
+ continuation.resume(throwing: AuthenticationError.profilePictureLoadError)
120
+ }
121
+ }
122
+ }
123
+ } else {
124
+ let url = URL(fileURLWithPath: urlString)
125
+ return try await withCheckedThrowingContinuation { continuation in
126
+ DispatchQueue.global(qos: .userInitiated).async {
127
+ do {
128
+ let data = try Data(contentsOf: url)
129
+ continuation.resume(returning: data)
130
+ } catch {
131
+ continuation.resume(throwing: AuthenticationError.profilePictureLoadError)
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ enum AuthenticationError: Error, LocalizedError {
140
+ case sdkNotInitialized
141
+ case invalidUserParams
142
+ case profilePictureLoadError
143
+ case unknownError(Error)
144
+
145
+ var errorDescription: String? {
146
+ switch self {
147
+ case .sdkNotInitialized:
148
+ return "SDK not initialized"
149
+ case .invalidUserParams:
150
+ return "Invalid user parameters"
151
+ case .profilePictureLoadError:
152
+ return "Failed to load profile picture"
153
+ case .unknownError(let underlyingError):
154
+ return "Unknown error: \(underlyingError.localizedDescription)"
155
+ }
156
+ }
157
+ }
@@ -0,0 +1,40 @@
1
+ import Octopus
2
+ import OctopusUI
3
+ import SwiftUI
4
+ import UIKit
5
+ import React
6
+
7
+ class OctopusUIManager {
8
+ private weak var presentedViewController: UIViewController?
9
+
10
+ func openUI(octopus: OctopusSDK) throws {
11
+ guard let presentingViewController = RCTPresentedViewController() else {
12
+ throw NSError(domain: "OPEN_UI_ERROR", code: 0, userInfo: [NSLocalizedDescriptionKey: "Could not find presenting view controller"])
13
+ }
14
+
15
+ let octopusHomeScreen = OctopusHomeScreen(octopus: octopus)
16
+ let hostingController = UIHostingController(rootView: octopusHomeScreen)
17
+ hostingController.modalPresentationStyle = .fullScreen
18
+
19
+ presentedViewController = hostingController
20
+
21
+ presentingViewController.present(hostingController, animated: true)
22
+ }
23
+
24
+ func closeUI() throws {
25
+ guard let presentedVC = presentedViewController else {
26
+ throw NSError(domain: "CLOSE_UI_ERROR", code: 0, userInfo: [NSLocalizedDescriptionKey: "No UI is currently presented"])
27
+ }
28
+
29
+ presentedVC.dismiss(animated: true) {
30
+ self.presentedViewController = nil
31
+ }
32
+ }
33
+
34
+ func cleanup() {
35
+ if let presentedVC = presentedViewController {
36
+ presentedVC.dismiss(animated: false, completion: nil)
37
+ presentedViewController = nil
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,43 @@
1
+ import Octopus
2
+
3
+ struct ProfileFieldMapper {
4
+ static func fromReactNativeArray(_ appManagedFields: [String]?) -> Set<ConnectionMode.SSOConfiguration.ProfileField> {
5
+ guard let fields = appManagedFields else {
6
+ return []
7
+ }
8
+
9
+ var profileFields: Set<ConnectionMode.SSOConfiguration.ProfileField> = []
10
+ for field in fields {
11
+ if let profileField = fromReactNativeString(field) {
12
+ profileFields.insert(profileField)
13
+ }
14
+ }
15
+ return profileFields
16
+ }
17
+
18
+ static func fromReactNativeString(_ fieldName: String?) -> ConnectionMode.SSOConfiguration.ProfileField? {
19
+ switch fieldName {
20
+ case "username":
21
+ return .nickname
22
+ case "biography":
23
+ return .bio
24
+ case "profilePicture":
25
+ return .picture
26
+ default:
27
+ return nil
28
+ }
29
+ }
30
+
31
+ static func toReactNativeString(_ profileField: ConnectionMode.SSOConfiguration.ProfileField?) -> String? {
32
+ switch profileField {
33
+ case .nickname:
34
+ return "username"
35
+ case .bio:
36
+ return "biography"
37
+ case .picture:
38
+ return "profilePicture"
39
+ default:
40
+ return nil
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ import { eventEmitter } from "./internals/eventEmitter.js";
4
+ /**
5
+ * Adds a listener for edit user events.
6
+ *
7
+ * This listener is triggered when the Octopus SDK needs the host app to handle
8
+ * user profile editing for fields marked as app-managed in SSO mode.
9
+ */
10
+ export function addEditUserListener(callback) {
11
+ return eventEmitter.addListener('editUser', callback);
12
+ }
13
+ //# sourceMappingURL=addEditUserListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["eventEmitter","addEditUserListener","callback","addListener"],"sourceRoot":"../../src","sources":["addEditUserListener.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,6BAA0B;AAUvD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,QAAkC,EAAE;EACtE,OAAOF,YAAY,CAACG,WAAW,CAAC,UAAU,EAAED,QAAQ,CAAC;AACvD","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ import { eventEmitter } from "./internals/eventEmitter.js";
4
+ /**
5
+ * Adds a listener for login required events.
6
+ *
7
+ * This listener is triggered when the Octopus SDK detects that user
8
+ * authentication is required, typically in SSO mode when the user
9
+ * session has expired or the user is not logged in.
10
+ */
11
+ export function addLoginRequiredListener(callback) {
12
+ return eventEmitter.addListener('loginRequired', callback);
13
+ }
14
+ //# sourceMappingURL=addLoginRequiredListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["eventEmitter","addLoginRequiredListener","callback","addListener"],"sourceRoot":"../../src","sources":["addLoginRequiredListener.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,6BAA0B;AAIvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,wBAAwBA,CACtCC,QAAuC,EACvC;EACA,OAAOF,YAAY,CAACG,WAAW,CAAC,eAAe,EAAED,QAAQ,CAAC;AAC5D","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ import { eventEmitter } from "./internals/eventEmitter.js";
4
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
5
+ import { log } from "./internals/logger.js";
6
+ import { LogLevel } from "./enums/LogLevel.enum.js";
7
+ /**
8
+ * Adds a listener for user token requests events.
9
+ *
10
+ * This listener is triggered when the Octopus SDK needs
11
+ * a new user token.
12
+ * You may use this listener directly if you prefer not to use the useUserTokenProvider hook.
13
+ */
14
+ export function addUserTokenRequestListener(callback) {
15
+ const handleUserTokenRequest = async event => {
16
+ try {
17
+ const token = await callback();
18
+ await OctopusReactNativeSdk.completeUserTokenRequest(event.requestId, token);
19
+ } catch (error) {
20
+ log(LogLevel.ERROR, 'Failed to provide user token to Octopus', error);
21
+ await OctopusReactNativeSdk.cancelUserTokenRequest(event.requestId);
22
+ }
23
+ };
24
+ return eventEmitter.addListener('userTokenRequest', handleUserTokenRequest);
25
+ }
26
+ //# sourceMappingURL=addUserTokenRequestListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["eventEmitter","OctopusReactNativeSdk","log","LogLevel","addUserTokenRequestListener","callback","handleUserTokenRequest","event","token","completeUserTokenRequest","requestId","error","ERROR","cancelUserTokenRequest","addListener"],"sourceRoot":"../../src","sources":["addUserTokenRequestListener.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,6BAA0B;AACvD,SAASC,qBAAqB,QAAQ,6BAA0B;AAChE,SAASC,GAAG,QAAQ,uBAAoB;AACxC,SAASC,QAAQ,QAAQ,0BAAuB;AAIhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CACzCC,QAA0C,EAC1C;EACA,MAAMC,sBAAsB,GAAG,MAAOC,KAA4B,IAAK;IACrE,IAAI;MACF,MAAMC,KAAK,GAAG,MAAMH,QAAQ,CAAC,CAAC;MAC9B,MAAMJ,qBAAqB,CAACQ,wBAAwB,CAClDF,KAAK,CAACG,SAAS,EACfF,KACF,CAAC;IACH,CAAC,CAAC,OAAOG,KAAK,EAAE;MACdT,GAAG,CAACC,QAAQ,CAACS,KAAK,EAAE,yCAAyC,EAAED,KAAK,CAAC;MACrE,MAAMV,qBAAqB,CAACY,sBAAsB,CAACN,KAAK,CAACG,SAAS,CAAC;IACrE;EACF,CAAC;EAED,OAAOV,YAAY,CAACc,WAAW,CAAC,kBAAkB,EAAER,sBAAsB,CAAC;AAC7E","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
4
+
5
+ /**
6
+ * Closes the Octopus UI home screen.
7
+ */
8
+ export function closeUI() {
9
+ return OctopusReactNativeSdk.closeUI();
10
+ }
11
+ //# sourceMappingURL=closeUI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OctopusReactNativeSdk","closeUI"],"sourceRoot":"../../src","sources":["closeUI.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;;AAEhE;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAA,EAAkB;EACvC,OAAOD,qBAAqB,CAACC,OAAO,CAAC,CAAC;AACxC","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
4
+ /**
5
+ * Connects a user using SSO authentication.
6
+ *
7
+ * This function establishes a connection between your app's user and Octopus.
8
+ * It requires that you have configured SSO mode during SDK initialization
9
+ * and have set up a token provider using `useUserTokenProvider` or `addUserTokenRequestListener`.
10
+ */
11
+ export function connectUser(params) {
12
+ return OctopusReactNativeSdk.connectUser(params);
13
+ }
14
+ //# sourceMappingURL=connectUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OctopusReactNativeSdk","connectUser","params"],"sourceRoot":"../../src","sources":["connectUser.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;AAwBhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAACC,MAAyB,EAAiB;EACpE,OAAOF,qBAAqB,CAACC,WAAW,CAACC,MAAM,CAAC;AAClD","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
4
+ export function disconnectUser() {
5
+ return OctopusReactNativeSdk.disconnectUser();
6
+ }
7
+ //# sourceMappingURL=disconnectUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OctopusReactNativeSdk","disconnectUser"],"sourceRoot":"../../src","sources":["disconnectUser.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;AAEhE,OAAO,SAASC,cAAcA,CAAA,EAAkB;EAC9C,OAAOD,qBAAqB,CAACC,cAAc,CAAC,CAAC;AAC/C","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Used to categorize log messages by their severity and importance.
5
+ */
6
+ export let LogLevel = /*#__PURE__*/function (LogLevel) {
7
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
8
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
9
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
10
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
11
+ return LogLevel;
12
+ }({});
13
+ //# sourceMappingURL=LogLevel.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LogLevel"],"sourceRoot":"../../../src","sources":["enums/LogLevel.enum.ts"],"mappings":";;AAAA;AACA;AACA;AACA,WAAYA,QAAQ,0BAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ export * from "./initialize.js";
4
+ export * from "./openUI.js";
5
+ export * from "./closeUI.js";
6
+ export * from "./connectUser.js";
7
+ export * from "./disconnectUser.js";
8
+ export * from "./addUserTokenRequestListener.js";
9
+ export * from "./useUserTokenProvider.js";
10
+ export * from "./addLoginRequiredListener.js";
11
+ export * from "./addEditUserListener.js";
12
+ export * from "./types/userProfileField.js";
13
+ export * from "./logger.js";
14
+ export * from "./enums/LogLevel.enum.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,iBAAc;AAC5B,cAAc,aAAU;AACxB,cAAc,cAAW;AACzB,cAAc,kBAAe;AAC7B,cAAc,qBAAkB;AAChC,cAAc,kCAA+B;AAC7C,cAAc,2BAAwB;AACtC,cAAc,+BAA4B;AAC1C,cAAc,0BAAuB;AACrC,cAAc,6BAA0B;AACxC,cAAc,aAAU;AACxB,cAAc,0BAAuB","ignoreList":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
4
+
5
+ /**
6
+ * Configuration params for initializing the Octopus SDK.
7
+ */
8
+
9
+ /**
10
+ * Initializes the Octopus SDK with the provided configuration.
11
+ *
12
+ * This function must be called before using any other Octopus SDK features.
13
+ * It sets up the SDK with your API key and configures the authentication mode.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Initialize with SSO mode
18
+ * await initialize({
19
+ * apiKey: 'your-api-key',
20
+ * connectionMode: {
21
+ * type: 'sso',
22
+ * appManagedFields: ['username', 'profilePicture']
23
+ * }
24
+ * });
25
+ *
26
+ * // Initialize with Octopus authentication
27
+ * await initialize({
28
+ * apiKey: 'your-api-key',
29
+ * connectionMode: {
30
+ * type: 'octopus'
31
+ * }
32
+ * });
33
+ * ```
34
+ */
35
+ export function initialize(params) {
36
+ return OctopusReactNativeSdk.initialize(params);
37
+ }
38
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OctopusReactNativeSdk","initialize","params"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;;AAGhE;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,MAAwB,EAAiB;EAClE,OAAOF,qBAAqB,CAACC,UAAU,CAACC,MAAM,CAAC;AACjD","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ import { NativeEventEmitter } from 'react-native';
4
+ import { OctopusReactNativeSdk } from "./nativeModule.js";
5
+ export const eventEmitter = new NativeEventEmitter(OctopusReactNativeSdk);
6
+ //# sourceMappingURL=eventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","OctopusReactNativeSdk","eventEmitter"],"sourceRoot":"../../../src","sources":["internals/eventEmitter.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,cAAc;AACjD,SAASC,qBAAqB,QAAQ,mBAAgB;AAEtD,OAAO,MAAMC,YAAY,GAAG,IAAIF,kBAAkB,CAACC,qBAAqB,CAAC","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { LogLevel } from "../enums/LogLevel.enum.js";
4
+ const defaultLogger = (_level, message, data) => {
5
+ console.log(`[Octopus] ${message}`, data);
6
+ };
7
+ let currentLogger = defaultLogger;
8
+
9
+ /**
10
+ * Set a custom logger function to handle all logs
11
+ *
12
+ * @param logger A function that takes a log level and message and handles the logging
13
+ */
14
+ export const setLogger = logger => {
15
+ currentLogger = logger;
16
+ };
17
+
18
+ /**
19
+ * Get the current logger function
20
+ */
21
+ export const getLogger = () => currentLogger;
22
+
23
+ /**
24
+ * Reset the logger to the default implementation
25
+ */
26
+ export const resetLogger = () => {
27
+ currentLogger = defaultLogger;
28
+ };
29
+ let logLevel = LogLevel.WARN;
30
+ export const setLogLevel = level => {
31
+ logLevel = level;
32
+ };
33
+ export const getLogLevel = () => logLevel;
34
+ export function log(level, message, data) {
35
+ const currentLogLevel = getLogLevel();
36
+ if (level < currentLogLevel) {
37
+ return;
38
+ }
39
+ const logger = getLogger();
40
+ logger(level, message, data);
41
+ }
42
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LogLevel","defaultLogger","_level","message","data","console","log","currentLogger","setLogger","logger","getLogger","resetLogger","logLevel","WARN","setLogLevel","level","getLogLevel","currentLogLevel"],"sourceRoot":"../../../src","sources":["internals/logger.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,2BAAwB;AAQjD,MAAMC,aAA6B,GAAGA,CACpCC,MAAgB,EAChBC,OAAe,EACfC,IAAgD,KACvC;EACTC,OAAO,CAACC,GAAG,CAAC,aAAaH,OAAO,EAAE,EAAEC,IAAI,CAAC;AAC3C,CAAC;AAED,IAAIG,aAA6B,GAAGN,aAAa;;AAEjD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMO,SAAS,GAAIC,MAAsB,IAAW;EACzDF,aAAa,GAAGE,MAAM;AACxB,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAsBH,aAAa;;AAE5D;AACA;AACA;AACA,OAAO,MAAMI,WAAW,GAAGA,CAAA,KAAY;EACrCJ,aAAa,GAAGN,aAAa;AAC/B,CAAC;AAED,IAAIW,QAAQ,GAAGZ,QAAQ,CAACa,IAAI;AAE5B,OAAO,MAAMC,WAAW,GAAIC,KAAe,IAAK;EAC9CH,QAAQ,GAAGG,KAAK;AAClB,CAAC;AAED,OAAO,MAAMC,WAAW,GAAGA,CAAA,KAAMJ,QAAQ;AAEzC,OAAO,SAASN,GAAGA,CACjBS,KAAe,EACfZ,OAAe,EACfC,IAAgD,EAC1C;EACN,MAAMa,eAAe,GAAGD,WAAW,CAAC,CAAC;EACrC,IAAID,KAAK,GAAGE,eAAe,EAAE;IAC3B;EACF;EAEA,MAAMR,MAAM,GAAGC,SAAS,CAAC,CAAC;EAC1BD,MAAM,CAACM,KAAK,EAAEZ,OAAO,EAAEC,IAAI,CAAC;AAC9B","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ import { NativeModules, Platform } from 'react-native';
4
+ const LINKING_ERROR = `The package '@octopus-community/react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
5
+ ios: "- You have run 'pod install'\n",
6
+ default: ''
7
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
8
+ export const OctopusReactNativeSdk = NativeModules.OctopusReactNativeSdk ? NativeModules.OctopusReactNativeSdk : new Proxy({}, {
9
+ get() {
10
+ throw new Error(LINKING_ERROR);
11
+ }
12
+ });
13
+ //# sourceMappingURL=nativeModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","OctopusReactNativeSdk","Proxy","get","Error"],"sourceRoot":"../../../src","sources":["internals/nativeModule.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,0FAA0F,GAC1FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,OAAO,MAAMC,qBAAqB,GAAGN,aAAa,CAACM,qBAAqB,GACpEN,aAAa,CAACM,qBAAqB,GACnC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { setLogger, resetLogger, setLogLevel, getLogLevel } from "./internals/logger.js";
4
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["setLogger","resetLogger","setLogLevel","getLogLevel"],"sourceRoot":"../../src","sources":["logger.ts"],"mappings":";;AAAA,SACEA,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,WAAW,QACN,uBAAoB","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ import { OctopusReactNativeSdk } from "./internals/nativeModule.js";
4
+
5
+ /**
6
+ * Opens the Octopus UI home screen.
7
+ */
8
+ export function openUI() {
9
+ return OctopusReactNativeSdk.openUI();
10
+ }
11
+ //# sourceMappingURL=openUI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OctopusReactNativeSdk","openUI"],"sourceRoot":"../../src","sources":["openUI.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,6BAA0B;;AAEhE;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CAAA,EAAkB;EACtC,OAAOD,qBAAqB,CAACC,MAAM,CAAC,CAAC;AACvC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=userProfileField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/userProfileField.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useRef } from 'react';
4
+ import { addUserTokenRequestListener } from "./addUserTokenRequestListener.js";
5
+
6
+ /**
7
+ * A function that provides user tokens for authentication.
8
+ *
9
+ * @returns A promise that resolves to a valid user token string.
10
+ * @throws Should throw an error if the token cannot be provided (e.g., user not logged in).
11
+ */
12
+
13
+ /**
14
+ * React hook that registers a user token provider for SSO authentication.
15
+ *
16
+ * This hook automatically handles token requests from the Octopus SDK by calling
17
+ * the provided `userTokenProvider` function whenever a fresh token is needed.
18
+ * The hook manages the subscription lifecycle and ensures the latest token provider
19
+ * is always used.
20
+ */
21
+ export function useUserTokenProvider(userTokenProvider) {
22
+ const userTokenProviderRef = useRef(userTokenProvider);
23
+ useEffect(() => {
24
+ userTokenProviderRef.current = userTokenProvider;
25
+ }, [userTokenProvider]);
26
+ useEffect(() => {
27
+ const subscription = addUserTokenRequestListener(() => userTokenProviderRef.current());
28
+ return () => {
29
+ subscription.remove();
30
+ };
31
+ }, []);
32
+ }
33
+ //# sourceMappingURL=useUserTokenProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","addUserTokenRequestListener","useUserTokenProvider","userTokenProvider","userTokenProviderRef","current","subscription","remove"],"sourceRoot":"../../src","sources":["useUserTokenProvider.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAASC,2BAA2B,QAAQ,kCAA+B;;AAE3E;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,iBAAoC,EAAE;EACzE,MAAMC,oBAAoB,GAAGJ,MAAM,CAACG,iBAAiB,CAAC;EAEtDJ,SAAS,CAAC,MAAM;IACdK,oBAAoB,CAACC,OAAO,GAAGF,iBAAiB;EAClD,CAAC,EAAE,CAACA,iBAAiB,CAAC,CAAC;EAEvBJ,SAAS,CAAC,MAAM;IACd,MAAMO,YAAY,GAAGL,2BAA2B,CAAC,MAC/CG,oBAAoB,CAACC,OAAO,CAAC,CAC/B,CAAC;IAED,OAAO,MAAM;MACXC,YAAY,CAACC,MAAM,CAAC,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,14 @@
1
+ import type { UserProfileField } from './types/userProfileField';
2
+ export interface EditUserEventParams {
3
+ /** The user profile field that the user wants to edit */
4
+ fieldToEdit: UserProfileField | null;
5
+ }
6
+ export type EditUserListenerCallback = (params: EditUserEventParams) => void;
7
+ /**
8
+ * Adds a listener for edit user events.
9
+ *
10
+ * This listener is triggered when the Octopus SDK needs the host app to handle
11
+ * user profile editing for fields marked as app-managed in SSO mode.
12
+ */
13
+ export declare function addEditUserListener(callback: EditUserListenerCallback): import("react-native").EmitterSubscription;
14
+ //# sourceMappingURL=addEditUserListener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addEditUserListener.d.ts","sourceRoot":"","sources":["../../../src/addEditUserListener.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,wBAAwB,8CAErE"}
@@ -0,0 +1,10 @@
1
+ export type LoginRequiredListenerCallback = () => void;
2
+ /**
3
+ * Adds a listener for login required events.
4
+ *
5
+ * This listener is triggered when the Octopus SDK detects that user
6
+ * authentication is required, typically in SSO mode when the user
7
+ * session has expired or the user is not logged in.
8
+ */
9
+ export declare function addLoginRequiredListener(callback: LoginRequiredListenerCallback): import("react-native").EmitterSubscription;
10
+ //# sourceMappingURL=addLoginRequiredListener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addLoginRequiredListener.d.ts","sourceRoot":"","sources":["../../../src/addLoginRequiredListener.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG,MAAM,IAAI,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,6BAA6B,8CAGxC"}
@@ -0,0 +1,10 @@
1
+ export type UserTokenRequestListenerCallback = () => Promise<string>;
2
+ /**
3
+ * Adds a listener for user token requests events.
4
+ *
5
+ * This listener is triggered when the Octopus SDK needs
6
+ * a new user token.
7
+ * You may use this listener directly if you prefer not to use the useUserTokenProvider hook.
8
+ */
9
+ export declare function addUserTokenRequestListener(callback: UserTokenRequestListenerCallback): import("react-native").EmitterSubscription;
10
+ //# sourceMappingURL=addUserTokenRequestListener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addUserTokenRequestListener.d.ts","sourceRoot":"","sources":["../../../src/addUserTokenRequestListener.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gCAAgC,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;AAErE;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,gCAAgC,8CAgB3C"}