@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,18 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package '@octopus-community/react-native' doesn't seem to be linked. Make sure: \n\n` +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+
9
+ export const OctopusReactNativeSdk = NativeModules.OctopusReactNativeSdk
10
+ ? NativeModules.OctopusReactNativeSdk
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ },
17
+ }
18
+ );
package/src/logger.ts ADDED
@@ -0,0 +1,7 @@
1
+ export {
2
+ setLogger,
3
+ resetLogger,
4
+ setLogLevel,
5
+ getLogLevel,
6
+ } from './internals/logger';
7
+ export type { LoggerFunction } from './internals/logger';
package/src/openUI.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Opens the Octopus UI home screen.
5
+ */
6
+ export function openUI(): Promise<void> {
7
+ return OctopusReactNativeSdk.openUI();
8
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Represents the different user profile fields that can be managed by your application.
3
+ *
4
+ * These fields are used in SSO mode to specify which profile data your app
5
+ * will handle directly, rather than letting Octopus manage them.
6
+ */
7
+ export type UserProfileField =
8
+ /** The user's display name, nickname or username */
9
+ | 'username'
10
+ /** The user's biography or about section */
11
+ | 'biography'
12
+ /** The user's profile picture URL */
13
+ | 'profilePicture';
@@ -0,0 +1,36 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { addUserTokenRequestListener } from './addUserTokenRequestListener';
3
+
4
+ /**
5
+ * A function that provides user tokens for authentication.
6
+ *
7
+ * @returns A promise that resolves to a valid user token string.
8
+ * @throws Should throw an error if the token cannot be provided (e.g., user not logged in).
9
+ */
10
+ export type UserTokenProvider = () => Promise<string>;
11
+
12
+ /**
13
+ * React hook that registers a user token provider for SSO authentication.
14
+ *
15
+ * This hook automatically handles token requests from the Octopus SDK by calling
16
+ * the provided `userTokenProvider` function whenever a fresh token is needed.
17
+ * The hook manages the subscription lifecycle and ensures the latest token provider
18
+ * is always used.
19
+ */
20
+ export function useUserTokenProvider(userTokenProvider: UserTokenProvider) {
21
+ const userTokenProviderRef = useRef(userTokenProvider);
22
+
23
+ useEffect(() => {
24
+ userTokenProviderRef.current = userTokenProvider;
25
+ }, [userTokenProvider]);
26
+
27
+ useEffect(() => {
28
+ const subscription = addUserTokenRequestListener(() =>
29
+ userTokenProviderRef.current()
30
+ );
31
+
32
+ return () => {
33
+ subscription.remove();
34
+ };
35
+ }, []);
36
+ }