@octopus-community/react-native 1.0.8 → 1.9.1

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 (108) hide show
  1. package/OctopusReactNativeSdk.podspec +1 -1
  2. package/README.md +40 -35
  3. package/android/build.gradle +2 -0
  4. package/android/gradle.properties +2 -2
  5. package/android/src/main/AndroidManifest.xml +2 -1
  6. package/android/src/main/AndroidManifestNew.xml +2 -1
  7. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusActivity.kt +56 -0
  8. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusContent.kt +396 -0
  9. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusEventEmitter.kt +22 -0
  10. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusEventSerializer.kt +339 -0
  11. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactModule.kt +326 -0
  12. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/{OctopusReactNativeSdkPackage.kt → OctopusReactPackage.kt} +3 -3
  13. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSDKInitializer.kt +22 -9
  14. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSSOAuthenticator.kt +5 -15
  15. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIController.kt +17 -2
  16. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIViewManager.kt +63 -0
  17. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/ProfileFieldMapper.kt +2 -2
  18. package/ios/OctopusEventManager.swift +27 -0
  19. package/ios/OctopusEventSerializer.swift +271 -0
  20. package/ios/OctopusReactNativeSdk.mm +26 -1
  21. package/ios/OctopusReactNativeSdk.swift +216 -2
  22. package/ios/OctopusSSOAuthenticator.swift +1 -5
  23. package/ios/OctopusUIManager.swift +83 -0
  24. package/ios/OctopusUIViewManager.m +7 -0
  25. package/ios/OctopusUIViewManager.swift +37 -0
  26. package/lib/module/OctopusUIView.js +39 -0
  27. package/lib/module/OctopusUIView.js.map +1 -0
  28. package/lib/module/addHasAccessToCommunityListener.js +33 -0
  29. package/lib/module/addHasAccessToCommunityListener.js.map +1 -0
  30. package/lib/module/addNavigateToUrlListener.js +41 -0
  31. package/lib/module/addNavigateToUrlListener.js.map +1 -0
  32. package/lib/module/addNotSeenNotificationsCountListener.js +30 -0
  33. package/lib/module/addNotSeenNotificationsCountListener.js.map +1 -0
  34. package/lib/module/addSDKEventListener.js +48 -0
  35. package/lib/module/addSDKEventListener.js.map +1 -0
  36. package/lib/module/connectUser.js +24 -3
  37. package/lib/module/connectUser.js.map +1 -1
  38. package/lib/module/index.js +12 -0
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/initialize.js +9 -12
  41. package/lib/module/initialize.js.map +1 -1
  42. package/lib/module/openUI.js +23 -2
  43. package/lib/module/openUI.js.map +1 -1
  44. package/lib/module/overrideCommunityAccess.js +36 -0
  45. package/lib/module/overrideCommunityAccess.js.map +1 -0
  46. package/lib/module/overrideDefaultLocale.js +75 -0
  47. package/lib/module/overrideDefaultLocale.js.map +1 -0
  48. package/lib/module/trackCommunityAccess.js +33 -0
  49. package/lib/module/trackCommunityAccess.js.map +1 -0
  50. package/lib/module/trackCustomEvent.js +36 -0
  51. package/lib/module/trackCustomEvent.js.map +1 -0
  52. package/lib/module/types/sdkEvents.js +2 -0
  53. package/lib/module/types/sdkEvents.js.map +1 -0
  54. package/lib/module/types/urlOpeningStrategy.js +23 -0
  55. package/lib/module/types/urlOpeningStrategy.js.map +1 -0
  56. package/lib/module/updateNotSeenNotificationsCount.js +33 -0
  57. package/lib/module/updateNotSeenNotificationsCount.js.map +1 -0
  58. package/lib/typescript/src/OctopusUIView.d.ts +32 -0
  59. package/lib/typescript/src/OctopusUIView.d.ts.map +1 -0
  60. package/lib/typescript/src/addHasAccessToCommunityListener.d.ts +27 -0
  61. package/lib/typescript/src/addHasAccessToCommunityListener.d.ts.map +1 -0
  62. package/lib/typescript/src/addNavigateToUrlListener.d.ts +31 -0
  63. package/lib/typescript/src/addNavigateToUrlListener.d.ts.map +1 -0
  64. package/lib/typescript/src/addNotSeenNotificationsCountListener.d.ts +24 -0
  65. package/lib/typescript/src/addNotSeenNotificationsCountListener.d.ts.map +1 -0
  66. package/lib/typescript/src/addSDKEventListener.d.ts +43 -0
  67. package/lib/typescript/src/addSDKEventListener.d.ts.map +1 -0
  68. package/lib/typescript/src/connectUser.d.ts +24 -8
  69. package/lib/typescript/src/connectUser.d.ts.map +1 -1
  70. package/lib/typescript/src/index.d.ts +13 -0
  71. package/lib/typescript/src/index.d.ts.map +1 -1
  72. package/lib/typescript/src/initialize.d.ts +9 -12
  73. package/lib/typescript/src/initialize.d.ts.map +1 -1
  74. package/lib/typescript/src/openUI.d.ts +28 -1
  75. package/lib/typescript/src/openUI.d.ts.map +1 -1
  76. package/lib/typescript/src/overrideCommunityAccess.d.ts +30 -0
  77. package/lib/typescript/src/overrideCommunityAccess.d.ts.map +1 -0
  78. package/lib/typescript/src/overrideDefaultLocale.d.ts +37 -0
  79. package/lib/typescript/src/overrideDefaultLocale.d.ts.map +1 -0
  80. package/lib/typescript/src/trackCommunityAccess.d.ts +27 -0
  81. package/lib/typescript/src/trackCommunityAccess.d.ts.map +1 -0
  82. package/lib/typescript/src/trackCustomEvent.d.ts +30 -0
  83. package/lib/typescript/src/trackCustomEvent.d.ts.map +1 -0
  84. package/lib/typescript/src/types/sdkEvents.d.ts +222 -0
  85. package/lib/typescript/src/types/sdkEvents.d.ts.map +1 -0
  86. package/lib/typescript/src/types/urlOpeningStrategy.d.ts +20 -0
  87. package/lib/typescript/src/types/urlOpeningStrategy.d.ts.map +1 -0
  88. package/lib/typescript/src/updateNotSeenNotificationsCount.d.ts +27 -0
  89. package/lib/typescript/src/updateNotSeenNotificationsCount.d.ts.map +1 -0
  90. package/package.json +2 -1
  91. package/src/OctopusUIView.tsx +57 -0
  92. package/src/addHasAccessToCommunityListener.ts +38 -0
  93. package/src/addNavigateToUrlListener.ts +54 -0
  94. package/src/addNotSeenNotificationsCountListener.ts +35 -0
  95. package/src/addSDKEventListener.ts +49 -0
  96. package/src/connectUser.ts +24 -8
  97. package/src/index.ts +13 -0
  98. package/src/initialize.ts +9 -12
  99. package/src/openUI.ts +32 -2
  100. package/src/overrideCommunityAccess.ts +33 -0
  101. package/src/overrideDefaultLocale.ts +88 -0
  102. package/src/trackCommunityAccess.ts +30 -0
  103. package/src/trackCustomEvent.ts +36 -0
  104. package/src/types/sdkEvents.ts +315 -0
  105. package/src/types/urlOpeningStrategy.ts +20 -0
  106. package/src/updateNotSeenNotificationsCount.ts +30 -0
  107. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactNativeSdkModule.kt +0 -155
  108. package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIActivity.kt +0 -434
@@ -0,0 +1,57 @@
1
+ import {
2
+ requireNativeComponent,
3
+ StyleSheet,
4
+ type StyleProp,
5
+ type ViewStyle,
6
+ } from 'react-native';
7
+
8
+ export interface OctopusUIViewProps {
9
+ /**
10
+ * When `true`, URLs tapped inside the community UI are not opened by the SDK.
11
+ * Instead, a `navigateToUrl` event is emitted. Subscribe with
12
+ * `addNavigateToUrlListener` to receive the URL.
13
+ *
14
+ * @default false
15
+ */
16
+ interceptUrls?: boolean;
17
+ style?: StyleProp<ViewStyle>;
18
+ }
19
+
20
+ const NativeOctopusUIView =
21
+ requireNativeComponent<OctopusUIViewProps>('OctopusUIView');
22
+
23
+ /**
24
+ * Embeds the Octopus Community UI as a native view inside your screen.
25
+ * Use this when you want to keep your app navigation (e.g. bottom tab bar) visible
26
+ * instead of opening the SDK in fullscreen with `openUI()`.
27
+ *
28
+ * You must call `initialize()` before rendering this component.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * function CommunityTab() {
33
+ * return (
34
+ * <View style={{ flex: 1 }}>
35
+ * <OctopusUIView interceptUrls={true} style={StyleSheet.absoluteFill} />
36
+ * </View>
37
+ * );
38
+ * }
39
+ * ```
40
+ */
41
+ export function OctopusUIView({
42
+ interceptUrls = false,
43
+ style,
44
+ }: OctopusUIViewProps) {
45
+ return (
46
+ <NativeOctopusUIView
47
+ interceptUrls={interceptUrls}
48
+ style={StyleSheet.flatten([styles.default, style])}
49
+ />
50
+ );
51
+ }
52
+
53
+ const styles = StyleSheet.create({
54
+ default: {
55
+ flex: 1,
56
+ },
57
+ });
@@ -0,0 +1,38 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+
3
+ export type HasAccessToCommunityListenerCallback = (hasAccess: boolean) => void;
4
+
5
+ /**
6
+ * Adds a listener for community access changes.
7
+ *
8
+ * This listener receives the **Octopus-managed** access state: the cohort value that determines
9
+ * whether the user has access to the community (when the SDK manages the A/B logic). It is triggered
10
+ * when that state changes — e.g. after you call `overrideCommunityAccess`, or when the cohort is
11
+ * updated by Octopus. Use it to show or hide community entry points in your UI. If your app manages
12
+ * access itself (and only reports it via `trackCommunityAccess`), this listener is less relevant,
13
+ * since the SDK is not the source of the access decision.
14
+ *
15
+ * @param callback - Function called when the access status changes
16
+ * @returns A subscription object with a `remove()` method to unsubscribe
17
+ * @see {@link overrideCommunityAccess} – set the cohort when Octopus manages A/B.
18
+ * @see {@link trackCommunityAccess} – report access for analytics when your app manages access.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const subscription = addHasAccessToCommunityListener((hasAccess) => {
23
+ * console.log(`Has access to community: ${hasAccess}`);
24
+ * // Show or hide community features based on access
25
+ * });
26
+ * subscription.remove();
27
+ * ```
28
+ */
29
+ export function addHasAccessToCommunityListener(
30
+ callback: HasAccessToCommunityListenerCallback
31
+ ) {
32
+ return eventEmitter.addListener(
33
+ 'hasAccessToCommunityChanged',
34
+ (data: { hasAccess: boolean }) => {
35
+ callback(data.hasAccess);
36
+ }
37
+ );
38
+ }
@@ -0,0 +1,54 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
3
+ import {
4
+ type UrlOpeningStrategy,
5
+ UrlOpeningStrategy as UrlOpeningStrategyEnum,
6
+ } from './types/urlOpeningStrategy';
7
+
8
+ export type NavigateToUrlListenerCallback = (
9
+ url: string
10
+ ) => UrlOpeningStrategy | Promise<UrlOpeningStrategy>;
11
+
12
+ /**
13
+ * Adds a listener for URL navigation events from the Octopus Community UI.
14
+ *
15
+ * Only has an effect when the UI was opened with `openUI({ interceptUrls: true })`.
16
+ * When the user taps a link, this callback is invoked with the URL. Return
17
+ * `handledByApp` if your app handles the URL (e.g. in-app web view), or
18
+ * `handledByOctopus` to let the SDK open it in the system browser.
19
+ *
20
+ * @param callback - Function called with the tapped URL. Can be async.
21
+ * Return `UrlOpeningStrategy.handledByApp` or `UrlOpeningStrategy.handledByOctopus`.
22
+ * @returns A subscription object with a `remove()` method to unsubscribe.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const subscription = addNavigateToUrlListener(async (url) => {
27
+ * if (url.startsWith('https://myapp.com/')) {
28
+ * // Handle deep link in-app
29
+ * Linking.openURL(url);
30
+ * return UrlOpeningStrategy.handledByApp;
31
+ * }
32
+ * return UrlOpeningStrategy.handledByOctopus; // Open in system browser
33
+ * });
34
+ *
35
+ * // Later, to unsubscribe:
36
+ * subscription.remove();
37
+ * ```
38
+ */
39
+ export function addNavigateToUrlListener(
40
+ callback: NavigateToUrlListenerCallback
41
+ ) {
42
+ return eventEmitter.addListener(
43
+ 'navigateToUrl',
44
+ async (data: { url: string }) => {
45
+ const strategy = await Promise.resolve(callback(data.url));
46
+ if (strategy === UrlOpeningStrategyEnum.handledByOctopus) {
47
+ OctopusReactNativeSdk.handleUrlStrategy(
48
+ data.url,
49
+ UrlOpeningStrategyEnum.handledByOctopus
50
+ );
51
+ }
52
+ }
53
+ );
54
+ }
@@ -0,0 +1,35 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+
3
+ export type NotSeenNotificationsCountListenerCallback = (count: number) => void;
4
+
5
+ /**
6
+ * Adds a listener for not seen notifications count changes.
7
+ *
8
+ * This listener is triggered whenever the count of unseen notifications changes.
9
+ * The count is automatically updated by the SDK, but can also be manually refreshed
10
+ * using `updateNotSeenNotificationsCount()`.
11
+ *
12
+ * @param callback - Function called when the notification count changes
13
+ * @returns A subscription object with a `remove()` method to unsubscribe
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const subscription = addNotSeenNotificationsCountListener((count) => {
18
+ * console.log(`Unseen notifications: ${count}`);
19
+ * // Update your app's badge or UI
20
+ * });
21
+ *
22
+ * // Later, to unsubscribe:
23
+ * subscription.remove();
24
+ * ```
25
+ */
26
+ export function addNotSeenNotificationsCountListener(
27
+ callback: NotSeenNotificationsCountListenerCallback
28
+ ) {
29
+ return eventEmitter.addListener(
30
+ 'notSeenNotificationsCountChanged',
31
+ (data: { count: number }) => {
32
+ callback(data.count);
33
+ }
34
+ );
35
+ }
@@ -0,0 +1,49 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+ import type { SDKEvent } from './types/sdkEvents';
3
+
4
+ export type SDKEventListenerCallback = (event: SDKEvent) => void;
5
+
6
+ /**
7
+ * Adds a listener for SDK events.
8
+ *
9
+ * This listener receives all SDK events including:
10
+ * - Content creation (posts, comments, replies)
11
+ * - Content deletion
12
+ * - Reactions and interactions
13
+ * - Gamification events
14
+ * - Screen navigation
15
+ * - Profile modifications
16
+ * - Session events
17
+ * - And more...
18
+ *
19
+ * Use TypeScript type guards to narrow down specific event types:
20
+ *
21
+ * @param callback - Function called when any SDK event occurs
22
+ * @returns A subscription object with a `remove()` method to unsubscribe
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const subscription = addSDKEventListener((event) => {
27
+ * switch (event.type) {
28
+ * case 'postCreated':
29
+ * console.log(`Post created: ${event.postId}`);
30
+ * break;
31
+ * case 'reactionModified':
32
+ * console.log(`Reaction changed on ${event.contentId}`);
33
+ * break;
34
+ * case 'gamificationPointsGained':
35
+ * console.log(`Gained ${event.points} points for ${event.action}`);
36
+ * break;
37
+ * // ... handle other event types
38
+ * }
39
+ * });
40
+ *
41
+ * // Later, to unsubscribe:
42
+ * subscription.remove();
43
+ * ```
44
+ */
45
+ export function addSDKEventListener(callback: SDKEventListenerCallback) {
46
+ return eventEmitter.addListener('sdkEvent', (data: SDKEvent) => {
47
+ callback(data);
48
+ });
49
+ }
@@ -14,20 +14,36 @@ export interface ConnectUserParams {
14
14
  */
15
15
  profilePicture?: string;
16
16
  biography?: string;
17
- /**
18
- * Whether the user has reached legal age.
19
- * Used for age-appropriate content filtering and compliance.
20
- */
21
- legalAgeReached?: boolean;
22
17
  };
23
18
  }
24
19
 
25
20
  /**
26
21
  * Connects a user using SSO authentication.
27
22
  *
28
- * This function establishes a connection between your app's user and Octopus.
29
- * It requires that you have configured SSO mode during SDK initialization
30
- * and have set up a token provider using `useUserTokenProvider` or `addUserTokenRequestListener`.
23
+ * This function establishes a connection between your app's user and Octopus. It requires that you
24
+ * have configured SSO mode during SDK initialization and have set up a token provider using
25
+ * `useUserTokenProvider` or `addUserTokenRequestListener`. The token is obtained via your token
26
+ * provider; you do not pass it directly to `connectUser`. Call `connectUser` after the user logs in;
27
+ * call `disconnectUser` when they log out.
28
+ *
29
+ * @param params - User id and optional profile (username, profilePicture, biography). See {@link ConnectUserParams}.
30
+ * @returns A promise that resolves when the user is connected. Rejects if the SDK is not initialized,
31
+ * SSO is not configured, or the token provider fails.
32
+ * @see {@link useUserTokenProvider} – provide JWT from React components.
33
+ * @see {@link addUserTokenRequestListener} – provide JWT without React.
34
+ * @see {@link disconnectUser} – disconnect the current user.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * await connectUser({
39
+ * userId: 'unique-user-id-from-your-backend',
40
+ * profile: {
41
+ * username: 'john_doe',
42
+ * profilePicture: 'https://example.com/avatar.jpg',
43
+ * biography: 'Software developer'
44
+ * }
45
+ * });
46
+ * ```
31
47
  */
32
48
  export function connectUser(params: ConnectUserParams): Promise<void> {
33
49
  return OctopusReactNativeSdk.connectUser(params);
package/src/index.ts CHANGED
@@ -3,10 +3,23 @@ export * from './openUI';
3
3
  export * from './closeUI';
4
4
  export * from './connectUser';
5
5
  export * from './disconnectUser';
6
+ export * from './trackCustomEvent';
7
+ export * from './overrideDefaultLocale';
8
+ export * from './updateNotSeenNotificationsCount';
9
+ export * from './overrideCommunityAccess';
10
+ export * from './trackCommunityAccess';
6
11
  export * from './addUserTokenRequestListener';
7
12
  export * from './useUserTokenProvider';
8
13
  export * from './addLoginRequiredListener';
9
14
  export * from './addEditUserListener';
15
+ export * from './addNotSeenNotificationsCountListener';
16
+ export * from './addHasAccessToCommunityListener';
17
+ export * from './addSDKEventListener';
18
+ export * from './addNavigateToUrlListener';
10
19
  export * from './types/userProfileField';
20
+ export * from './types/sdkEvents';
21
+ export * from './types/urlOpeningStrategy';
11
22
  export * from './logger';
12
23
  export * from './enums/LogLevel.enum';
24
+ export { OctopusUIView } from './OctopusUIView';
25
+ export type { OctopusUIViewProps } from './OctopusUIView';
package/src/initialize.ts CHANGED
@@ -144,26 +144,23 @@ export interface InitializeParams {
144
144
  /**
145
145
  * Initializes the Octopus SDK with the provided configuration.
146
146
  *
147
- * This function must be called before using any other Octopus SDK features.
148
- * It sets up the SDK with your API key and configures the authentication mode.
147
+ * This function must be called before using any other Octopus SDK features. It sets up the SDK
148
+ * with your API key, connection mode (SSO or Octopus-managed authentication), and optional theme
149
+ * and UI options. For SSO, you also need to set up a token provider with `useUserTokenProvider` or
150
+ * `addUserTokenRequestListener` before calling `connectUser`.
151
+ *
152
+ * @param params - See {@link InitializeParams} (including `theme`, `ui`). For theming guide see the main README.
153
+ * @see {@link connectUser} – connect a user after initialization (SSO mode).
149
154
  *
150
155
  * @example
151
156
  * ```typescript
152
- * // Initialize with SSO mode
153
157
  * await initialize({
154
158
  * apiKey: 'your-api-key',
155
- * connectionMode: {
156
- * type: 'sso',
157
- * appManagedFields: ['username', 'profilePicture']
158
- * }
159
+ * connectionMode: { type: 'sso', appManagedFields: ['username', 'profilePicture'] }
159
160
  * });
160
- *
161
- * // Initialize with Octopus authentication
162
161
  * await initialize({
163
162
  * apiKey: 'your-api-key',
164
- * connectionMode: {
165
- * type: 'octopus'
166
- * }
163
+ * connectionMode: { type: 'octopus' }
167
164
  * });
168
165
  * ```
169
166
  */
package/src/openUI.ts CHANGED
@@ -1,8 +1,38 @@
1
1
  import { OctopusReactNativeSdk } from './internals/nativeModule';
2
2
 
3
+ /**
4
+ * Options for opening the Octopus UI.
5
+ */
6
+ export interface OpenUIOptions {
7
+ /**
8
+ * When `true`, URLs tapped inside the community UI are not opened by the SDK.
9
+ * Instead, a `navigateToUrl` event is emitted. Subscribe with
10
+ * `addNavigateToUrlListener` to receive the URL and decide whether to handle
11
+ * it in-app or delegate back to the SDK (system browser).
12
+ *
13
+ * @default false
14
+ */
15
+ interceptUrls?: boolean;
16
+ }
17
+
3
18
  /**
4
19
  * Opens the Octopus UI home screen.
20
+ *
21
+ * @param options - Optional configuration. Use `interceptUrls: true` to receive
22
+ * URL taps via `addNavigateToUrlListener` instead of having the SDK open them.
23
+ * @returns A promise that resolves when the UI has been opened.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Open UI with default behaviour (SDK opens links in system browser)
28
+ * await openUI();
29
+ *
30
+ * // Open UI with URL interception (app receives links via addNavigateToUrlListener)
31
+ * await openUI({ interceptUrls: true });
32
+ * ```
5
33
  */
6
- export function openUI(): Promise<void> {
7
- return OctopusReactNativeSdk.openUI();
34
+ export function openUI(options?: OpenUIOptions): Promise<void> {
35
+ const opts = options ?? {};
36
+ const interceptUrls = opts.interceptUrls === true;
37
+ return OctopusReactNativeSdk.openUI({ interceptUrls });
8
38
  }
@@ -0,0 +1,33 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Override the community access cohort for the current user.
5
+ *
6
+ * **When to use:** When the **Octopus SDK manages the A/B logic** — i.e. Octopus assigns
7
+ * the cohort and decides who has access to the community. In that case, the "Has access
8
+ * to community" state is the cohort value. Use this function to override that cohort
9
+ * (e.g. for testing or feature gating). The new state is reflected via `addHasAccessToCommunityListener`.
10
+ *
11
+ * **When not to use:** If **your app** decides who has access (e.g. your own feature flag or A/B logic),
12
+ * do not use `overrideCommunityAccess`. Use `trackCommunityAccess` instead to report the access
13
+ * value to Octopus for analytics only; that does not change the actual access state in the SDK.
14
+ *
15
+ * @param hasAccess - `true` to grant access, `false` to deny access.
16
+ * @returns A promise that resolves when the override has been applied.
17
+ * @throws An error if the SDK is not initialized or the call fails.
18
+ * @see {@link addHasAccessToCommunityListener} – subscribe to the Octopus-managed community access state.
19
+ * @see {@link trackCommunityAccess} – when your app manages access, report it for analytics only (no change to SDK state).
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const subscription = addHasAccessToCommunityListener((hasAccess) => {
24
+ * console.log(`Has access to community: ${hasAccess}`);
25
+ * });
26
+ * await overrideCommunityAccess(true);
27
+ * await overrideCommunityAccess(false);
28
+ * subscription.remove();
29
+ * ```
30
+ */
31
+ export function overrideCommunityAccess(hasAccess: boolean): Promise<void> {
32
+ return OctopusReactNativeSdk.overrideCommunityAccess(hasAccess);
33
+ }
@@ -0,0 +1,88 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Parameters for overriding the default locale used by the Octopus SDK UI.
5
+ * Uses ISO 639-1 language code and optional ISO 3166-1 alpha-2 country code.
6
+ */
7
+ export interface OverrideLocaleParams {
8
+ /** ISO 639-1 language code (e.g. `"en"`, `"fr"`). */
9
+ languageCode: string;
10
+ /** Optional ISO 3166-1 alpha-2 country code (e.g. `"US"`, `"FR"`). */
11
+ countryCode?: string;
12
+ }
13
+
14
+ /** ISO 639-1: exactly 2 alphabetic characters (case-insensitive, normalized to lowercase). */
15
+ const LANGUAGE_CODE_REGEX = /^[a-zA-Z]{2}$/;
16
+
17
+ /** ISO 3166-1 alpha-2: exactly 2 alphabetic characters (case-insensitive, normalized to uppercase). */
18
+ const COUNTRY_CODE_REGEX = /^[a-zA-Z]{2}$/;
19
+
20
+ function validateAndNormalizeLocale(locale: OverrideLocaleParams): {
21
+ languageCode: string;
22
+ countryCode: string | null;
23
+ } {
24
+ const lang = locale.languageCode?.trim() ?? '';
25
+ if (!LANGUAGE_CODE_REGEX.test(lang)) {
26
+ throw new Error(
27
+ "overrideDefaultLocale: languageCode must be a 2-letter ISO 639-1 code (e.g. 'en', 'fr')"
28
+ );
29
+ }
30
+ const country = locale.countryCode?.trim();
31
+ if (country !== undefined && country !== '') {
32
+ if (!COUNTRY_CODE_REGEX.test(country)) {
33
+ throw new Error(
34
+ "overrideDefaultLocale: countryCode must be a 2-letter ISO 3166-1 alpha-2 code (e.g. 'US', 'FR')"
35
+ );
36
+ }
37
+ return {
38
+ languageCode: lang.toLowerCase(),
39
+ countryCode: country.toUpperCase(),
40
+ };
41
+ }
42
+ return {
43
+ languageCode: lang.toLowerCase(),
44
+ countryCode: null,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Override the default locale used by the Octopus SDK for its UI.
50
+ *
51
+ * The change takes effect immediately for subsequently displayed SDK screens.
52
+ * Pass `null` to reset to the system default locale.
53
+ *
54
+ * @param locale - Object with `languageCode` and optional `countryCode`
55
+ * (e.g. `{ languageCode: 'fr' }` or `{ languageCode: 'en', countryCode: 'US' }`).
56
+ * Pass `null` to use the system default (no override).
57
+ * @returns A promise that resolves when the override has been applied.
58
+ * @throws An error if the SDK is not initialized or the call fails.
59
+ * @throws An error if locale is invalid (e.g. non-ISO language/country codes).
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * // Use French
64
+ * await overrideDefaultLocale({ languageCode: 'fr' });
65
+ *
66
+ * // Use English (US)
67
+ * await overrideDefaultLocale({ languageCode: 'en', countryCode: 'US' });
68
+ *
69
+ * // Reset to system default
70
+ * await overrideDefaultLocale(null);
71
+ * ```
72
+ */
73
+ export function overrideDefaultLocale(
74
+ locale: OverrideLocaleParams | null
75
+ ): Promise<void> {
76
+ if (locale === null) {
77
+ return OctopusReactNativeSdk.overrideDefaultLocale(null, null);
78
+ }
79
+ try {
80
+ const { languageCode, countryCode } = validateAndNormalizeLocale(locale);
81
+ return OctopusReactNativeSdk.overrideDefaultLocale(
82
+ languageCode,
83
+ countryCode
84
+ );
85
+ } catch (e) {
86
+ return Promise.reject(e);
87
+ }
88
+ }
@@ -0,0 +1,30 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Track community access for analytics without changing the actual access.
5
+ *
6
+ * **When to use:** When **your app manages its own A/B logic** — i.e. your app decides who can see
7
+ * the community (e.g. via your own feature flag or experiment). Call this to report that decision
8
+ * to Octopus for analytics only. It does not grant or restrict access in the SDK; it only records
9
+ * the value for reporting.
10
+ *
11
+ * **When not to use:** If the **Octopus SDK manages the cohort** (Octopus assigns who has access),
12
+ * use `overrideCommunityAccess` to change the cohort and `addHasAccessToCommunityListener` to react
13
+ * to it. Use `trackCommunityAccess` only when the access decision is owned by your app and you just
14
+ * need to report it.
15
+ *
16
+ * @param hasAccess - The access value to report (e.g. the variant your app decided).
17
+ * @returns A promise that resolves when the tracking call has completed.
18
+ * @throws An error if the SDK is not initialized or the call fails.
19
+ * @see {@link overrideCommunityAccess} – when Octopus manages the cohort, override it (and use addHasAccessToCommunityListener to react).
20
+ * @see {@link addHasAccessToCommunityListener} – subscribe to the Octopus-managed access state (relevant when Octopus or override sets it).
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * await trackCommunityAccess(true);
25
+ * await trackCommunityAccess(false);
26
+ * ```
27
+ */
28
+ export function trackCommunityAccess(hasAccess: boolean): Promise<void> {
29
+ return OctopusReactNativeSdk.trackCommunityAccess(hasAccess);
30
+ }
@@ -0,0 +1,36 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Track custom events that are merged into Octopus analytics reports.
5
+ *
6
+ * Use this to send app-specific business events (e.g. purchases, feature usage)
7
+ * so they appear alongside Octopus Community analytics.
8
+ *
9
+ * All property values must be strings. Non-string values should be stringified
10
+ * before calling (e.g. numbers as `"123"`, booleans as `"true"`).
11
+ *
12
+ * @param name - The name of the custom event (e.g. `"purchase"`, `"screen_view"`).
13
+ * @param properties - Optional map of string key-value pairs attached to the event.
14
+ * @returns A promise that resolves when the event has been tracked.
15
+ * @throws An error if the SDK is not initialized or tracking fails.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * await trackCustomEvent('purchase', {
20
+ * product_id: '123',
21
+ * price: '9.99',
22
+ * currency: 'EUR',
23
+ * });
24
+ *
25
+ * await trackCustomEvent('feature_used', {
26
+ * feature: 'community_search',
27
+ * source: 'home_screen',
28
+ * });
29
+ * ```
30
+ */
31
+ export function trackCustomEvent(
32
+ name: string,
33
+ properties?: Record<string, string>
34
+ ): Promise<void> {
35
+ return OctopusReactNativeSdk.trackCustomEvent(name, properties ?? {});
36
+ }