@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,5 @@
1
+ /**
2
+ * Closes the Octopus UI home screen.
3
+ */
4
+ export declare function closeUI(): Promise<void>;
5
+ //# sourceMappingURL=closeUI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closeUI.d.ts","sourceRoot":"","sources":["../../../src/closeUI.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvC"}
@@ -0,0 +1,30 @@
1
+ export interface ConnectUserParams {
2
+ /**
3
+ * Unique identifier for the user in your system.
4
+ * This should be a stable, unique ID that won't change for the user.
5
+ */
6
+ userId: string;
7
+ profile?: {
8
+ username?: string;
9
+ /**
10
+ * URL or local file path to the user's profile picture.
11
+ * Supports HTTP/HTTPS URLs and local file paths.
12
+ */
13
+ profilePicture?: string;
14
+ biography?: string;
15
+ /**
16
+ * Whether the user has reached legal age.
17
+ * Used for age-appropriate content filtering and compliance.
18
+ */
19
+ legalAgeReached?: boolean;
20
+ };
21
+ }
22
+ /**
23
+ * Connects a user using SSO authentication.
24
+ *
25
+ * This function establishes a connection between your app's user and Octopus.
26
+ * It requires that you have configured SSO mode during SDK initialization
27
+ * and have set up a token provider using `useUserTokenProvider` or `addUserTokenRequestListener`.
28
+ */
29
+ export declare function connectUser(params: ConnectUserParams): Promise<void>;
30
+ //# sourceMappingURL=connectUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectUser.d.ts","sourceRoot":"","sources":["../../../src/connectUser.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB;;;WAGG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE"}
@@ -0,0 +1,2 @@
1
+ export declare function disconnectUser(): Promise<void>;
2
+ //# sourceMappingURL=disconnectUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disconnectUser.d.ts","sourceRoot":"","sources":["../../../src/disconnectUser.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9C"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Used to categorize log messages by their severity and importance.
3
+ */
4
+ export declare enum LogLevel {
5
+ DEBUG = 0,
6
+ INFO = 1,
7
+ WARN = 2,
8
+ ERROR = 3
9
+ }
10
+ //# sourceMappingURL=LogLevel.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogLevel.enum.d.ts","sourceRoot":"","sources":["../../../../src/enums/LogLevel.enum.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,KAAK,IAAA;CACN"}
@@ -0,0 +1,13 @@
1
+ export * from './initialize';
2
+ export * from './openUI';
3
+ export * from './closeUI';
4
+ export * from './connectUser';
5
+ export * from './disconnectUser';
6
+ export * from './addUserTokenRequestListener';
7
+ export * from './useUserTokenProvider';
8
+ export * from './addLoginRequiredListener';
9
+ export * from './addEditUserListener';
10
+ export * from './types/userProfileField';
11
+ export * from './logger';
12
+ export * from './enums/LogLevel.enum';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { UserProfileField } from './types/userProfileField';
2
+ /**
3
+ * Configuration params for initializing the Octopus SDK.
4
+ */
5
+ export interface InitializeParams {
6
+ /** Your Octopus API key obtained from the Octopus dashboard */
7
+ apiKey: string;
8
+ /**
9
+ * The connection mode determines how user authentication is handled.
10
+ * - `sso`: Use Single Sign-On with your existing user system
11
+ * - `octopus`: Let Octopus handle user authentication
12
+ */
13
+ connectionMode: {
14
+ /** SSO mode configuration */
15
+ type: 'sso';
16
+ /** List of user profile fields that your app manages directly */
17
+ appManagedFields: UserProfileField[];
18
+ } | {
19
+ /** Octopus-managed authentication mode */
20
+ type: 'octopus';
21
+ };
22
+ }
23
+ /**
24
+ * Initializes the Octopus SDK with the provided configuration.
25
+ *
26
+ * This function must be called before using any other Octopus SDK features.
27
+ * It sets up the SDK with your API key and configures the authentication mode.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Initialize with SSO mode
32
+ * await initialize({
33
+ * apiKey: 'your-api-key',
34
+ * connectionMode: {
35
+ * type: 'sso',
36
+ * appManagedFields: ['username', 'profilePicture']
37
+ * }
38
+ * });
39
+ *
40
+ * // Initialize with Octopus authentication
41
+ * await initialize({
42
+ * apiKey: 'your-api-key',
43
+ * connectionMode: {
44
+ * type: 'octopus'
45
+ * }
46
+ * });
47
+ * ```
48
+ */
49
+ export declare function initialize(params: InitializeParams): Promise<void>;
50
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/initialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,cAAc,EACV;QACE,6BAA6B;QAC7B,IAAI,EAAE,KAAK,CAAC;QACZ,iEAAiE;QACjE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KACtC,GACD;QACE,0CAA0C;QAC1C,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC;CACP;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE"}
@@ -0,0 +1,3 @@
1
+ import { NativeEventEmitter } from 'react-native';
2
+ export declare const eventEmitter: NativeEventEmitter;
3
+ //# sourceMappingURL=eventEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventEmitter.d.ts","sourceRoot":"","sources":["../../../../src/internals/eventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,eAAO,MAAM,YAAY,oBAAgD,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { LogLevel } from '../enums/LogLevel.enum';
2
+ export type LoggerFunction = (level: LogLevel, message: string, data?: Error | Record<string, unknown> | unknown) => void;
3
+ /**
4
+ * Set a custom logger function to handle all logs
5
+ *
6
+ * @param logger A function that takes a log level and message and handles the logging
7
+ */
8
+ export declare const setLogger: (logger: LoggerFunction) => void;
9
+ /**
10
+ * Get the current logger function
11
+ */
12
+ export declare const getLogger: () => LoggerFunction;
13
+ /**
14
+ * Reset the logger to the default implementation
15
+ */
16
+ export declare const resetLogger: () => void;
17
+ export declare const setLogLevel: (level: LogLevel) => void;
18
+ export declare const getLogLevel: () => LogLevel;
19
+ export declare function log(level: LogLevel, message: string, data?: Error | Record<string, unknown> | unknown): void;
20
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/internals/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,KAC7C,IAAI,CAAC;AAYV;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,cAAc,KAAG,IAElD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,cAA+B,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,WAAW,QAAO,IAE9B,CAAC;AAIF,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,SAE1C,CAAC;AAEF,eAAO,MAAM,WAAW,gBAAiB,CAAC;AAE1C,wBAAgB,GAAG,CACjB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,GAC/C,IAAI,CAQN"}
@@ -0,0 +1,2 @@
1
+ export declare const OctopusReactNativeSdk: any;
2
+ //# sourceMappingURL=nativeModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeModule.d.ts","sourceRoot":"","sources":["../../../../src/internals/nativeModule.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,qBAAqB,KAS7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { setLogger, resetLogger, setLogLevel, getLogLevel, } from './internals/logger';
2
+ export type { LoggerFunction } from './internals/logger';
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Opens the Octopus UI home screen.
3
+ */
4
+ export declare function openUI(): Promise<void>;
5
+ //# sourceMappingURL=openUI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openUI.d.ts","sourceRoot":"","sources":["../../../src/openUI.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtC"}
@@ -0,0 +1,14 @@
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';
14
+ //# sourceMappingURL=userProfileField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userProfileField.d.ts","sourceRoot":"","sources":["../../../../src/types/userProfileField.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB;AAC1B,oDAAoD;AAClD,UAAU;AACZ,4CAA4C;GAC1C,WAAW;AACb,qCAAqC;GACnC,gBAAgB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A function that provides user tokens for authentication.
3
+ *
4
+ * @returns A promise that resolves to a valid user token string.
5
+ * @throws Should throw an error if the token cannot be provided (e.g., user not logged in).
6
+ */
7
+ export type UserTokenProvider = () => Promise<string>;
8
+ /**
9
+ * React hook that registers a user token provider for SSO authentication.
10
+ *
11
+ * This hook automatically handles token requests from the Octopus SDK by calling
12
+ * the provided `userTokenProvider` function whenever a fresh token is needed.
13
+ * The hook manages the subscription lifecycle and ensures the latest token provider
14
+ * is always used.
15
+ */
16
+ export declare function useUserTokenProvider(userTokenProvider: UserTokenProvider): void;
17
+ //# sourceMappingURL=useUserTokenProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserTokenProvider.d.ts","sourceRoot":"","sources":["../../../src/useUserTokenProvider.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,iBAAiB,EAAE,iBAAiB,QAgBxE"}
package/package.json ADDED
@@ -0,0 +1,136 @@
1
+ {
2
+ "name": "@octopus-community/react-native",
3
+ "version": "1.0.0",
4
+ "description": "React Native module for the Octopus Community SDK",
5
+ "source": "./src/index.ts",
6
+ "main": "./lib/module/index.js",
7
+ "types": "./lib/typescript/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "scripts/octopus_pods.rb",
24
+ "!ios/build",
25
+ "!android/build",
26
+ "!android/gradle",
27
+ "!android/gradlew",
28
+ "!android/gradlew.bat",
29
+ "!android/local.properties",
30
+ "!**/__tests__",
31
+ "!**/__fixtures__",
32
+ "!**/__mocks__",
33
+ "!**/.*"
34
+ ],
35
+ "scripts": {
36
+ "example": "yarn workspace @octopus-community/react-native-example",
37
+ "test": "yarn test:lint && yarn test:types && yarn test:unit",
38
+ "test:unit": "jest",
39
+ "test:types": "tsc",
40
+ "test:lint": "eslint \"**/*.{js,ts,tsx}\"",
41
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
42
+ "prepare": "typedoc && bob build"
43
+ },
44
+ "keywords": [
45
+ "react-native",
46
+ "ios",
47
+ "android"
48
+ ],
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/Octopus-Community/octopus-sdk-react-native.git"
52
+ },
53
+ "author": "Louis Lagrange <lagrange.louis@gmail.com> (https://github.com/Minishlink)",
54
+ "license": "SEE LICENSE IN LICENSE.md",
55
+ "bugs": {
56
+ "url": "https://github.com/Octopus-Community/octopus-sdk-react-native/issues"
57
+ },
58
+ "homepage": "https://github.com/Octopus-Community/octopus-sdk-react-native#readme",
59
+ "publishConfig": {
60
+ "registry": "https://registry.npmjs.org/"
61
+ },
62
+ "devDependencies": {
63
+ "@commitlint/config-conventional": "^19.6.0",
64
+ "@eslint/compat": "^1.2.7",
65
+ "@eslint/eslintrc": "^3.3.0",
66
+ "@eslint/js": "^9.22.0",
67
+ "@evilmartians/lefthook": "^1.5.0",
68
+ "@react-native/eslint-config": "^0.78.0",
69
+ "@types/jest": "^29.5.5",
70
+ "@types/react": "^19.0.0",
71
+ "commitlint": "^19.6.1",
72
+ "del-cli": "^5.1.0",
73
+ "eslint": "^9.22.0",
74
+ "eslint-config-prettier": "^10.1.1",
75
+ "eslint-plugin-prettier": "^5.2.3",
76
+ "jest": "^29.7.0",
77
+ "prettier": "^3.0.3",
78
+ "react": "19.0.0",
79
+ "react-native": "0.78.2",
80
+ "react-native-builder-bob": "^0.40.12",
81
+ "turbo": "^1.10.7",
82
+ "typedoc": "^0.28.7",
83
+ "typedoc-plugin-markdown": "^4.7.0",
84
+ "typescript": "^5.2.2"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "*",
88
+ "react-native": "*"
89
+ },
90
+ "workspaces": [
91
+ "example"
92
+ ],
93
+ "packageManager": "yarn@3.6.1",
94
+ "jest": {
95
+ "preset": "react-native",
96
+ "modulePathIgnorePatterns": [
97
+ "<rootDir>/example/node_modules",
98
+ "<rootDir>/lib/"
99
+ ]
100
+ },
101
+ "commitlint": {
102
+ "extends": [
103
+ "@commitlint/config-conventional"
104
+ ]
105
+ },
106
+ "prettier": {
107
+ "quoteProps": "consistent",
108
+ "singleQuote": true,
109
+ "tabWidth": 2,
110
+ "trailingComma": "es5",
111
+ "useTabs": false
112
+ },
113
+ "react-native-builder-bob": {
114
+ "source": "src",
115
+ "output": "lib",
116
+ "targets": [
117
+ [
118
+ "module",
119
+ {
120
+ "esm": true
121
+ }
122
+ ],
123
+ [
124
+ "typescript",
125
+ {
126
+ "project": "tsconfig.build.json"
127
+ }
128
+ ]
129
+ ]
130
+ },
131
+ "create-react-native-library": {
132
+ "type": "legacy-module",
133
+ "languages": "kotlin-swift",
134
+ "version": "0.49.8"
135
+ }
136
+ }
@@ -0,0 +1,19 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+ import type { UserProfileField } from './types/userProfileField';
3
+
4
+ export interface EditUserEventParams {
5
+ /** The user profile field that the user wants to edit */
6
+ fieldToEdit: UserProfileField | null;
7
+ }
8
+
9
+ export type EditUserListenerCallback = (params: EditUserEventParams) => void;
10
+
11
+ /**
12
+ * Adds a listener for edit user events.
13
+ *
14
+ * This listener is triggered when the Octopus SDK needs the host app to handle
15
+ * user profile editing for fields marked as app-managed in SSO mode.
16
+ */
17
+ export function addEditUserListener(callback: EditUserListenerCallback) {
18
+ return eventEmitter.addListener('editUser', callback);
19
+ }
@@ -0,0 +1,16 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+
3
+ export type LoginRequiredListenerCallback = () => void;
4
+
5
+ /**
6
+ * Adds a listener for login required events.
7
+ *
8
+ * This listener is triggered when the Octopus SDK detects that user
9
+ * authentication is required, typically in SSO mode when the user
10
+ * session has expired or the user is not logged in.
11
+ */
12
+ export function addLoginRequiredListener(
13
+ callback: LoginRequiredListenerCallback
14
+ ) {
15
+ return eventEmitter.addListener('loginRequired', callback);
16
+ }
@@ -0,0 +1,32 @@
1
+ import { eventEmitter } from './internals/eventEmitter';
2
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
3
+ import { log } from './internals/logger';
4
+ import { LogLevel } from './enums/LogLevel.enum';
5
+
6
+ export type UserTokenRequestListenerCallback = () => Promise<string>;
7
+
8
+ /**
9
+ * Adds a listener for user token requests events.
10
+ *
11
+ * This listener is triggered when the Octopus SDK needs
12
+ * a new user token.
13
+ * You may use this listener directly if you prefer not to use the useUserTokenProvider hook.
14
+ */
15
+ export function addUserTokenRequestListener(
16
+ callback: UserTokenRequestListenerCallback
17
+ ) {
18
+ const handleUserTokenRequest = async (event: { requestId: string }) => {
19
+ try {
20
+ const token = await callback();
21
+ await OctopusReactNativeSdk.completeUserTokenRequest(
22
+ event.requestId,
23
+ token
24
+ );
25
+ } catch (error) {
26
+ log(LogLevel.ERROR, 'Failed to provide user token to Octopus', error);
27
+ await OctopusReactNativeSdk.cancelUserTokenRequest(event.requestId);
28
+ }
29
+ };
30
+
31
+ return eventEmitter.addListener('userTokenRequest', handleUserTokenRequest);
32
+ }
package/src/closeUI.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ /**
4
+ * Closes the Octopus UI home screen.
5
+ */
6
+ export function closeUI(): Promise<void> {
7
+ return OctopusReactNativeSdk.closeUI();
8
+ }
@@ -0,0 +1,34 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ export interface ConnectUserParams {
4
+ /**
5
+ * Unique identifier for the user in your system.
6
+ * This should be a stable, unique ID that won't change for the user.
7
+ */
8
+ userId: string;
9
+ profile?: {
10
+ username?: string;
11
+ /**
12
+ * URL or local file path to the user's profile picture.
13
+ * Supports HTTP/HTTPS URLs and local file paths.
14
+ */
15
+ profilePicture?: string;
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
+ };
23
+ }
24
+
25
+ /**
26
+ * Connects a user using SSO authentication.
27
+ *
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`.
31
+ */
32
+ export function connectUser(params: ConnectUserParams): Promise<void> {
33
+ return OctopusReactNativeSdk.connectUser(params);
34
+ }
@@ -0,0 +1,5 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+
3
+ export function disconnectUser(): Promise<void> {
4
+ return OctopusReactNativeSdk.disconnectUser();
5
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Used to categorize log messages by their severity and importance.
3
+ */
4
+ export enum LogLevel {
5
+ DEBUG,
6
+ INFO,
7
+ WARN,
8
+ ERROR,
9
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from './initialize';
2
+ export * from './openUI';
3
+ export * from './closeUI';
4
+ export * from './connectUser';
5
+ export * from './disconnectUser';
6
+ export * from './addUserTokenRequestListener';
7
+ export * from './useUserTokenProvider';
8
+ export * from './addLoginRequiredListener';
9
+ export * from './addEditUserListener';
10
+ export * from './types/userProfileField';
11
+ export * from './logger';
12
+ export * from './enums/LogLevel.enum';
@@ -0,0 +1,56 @@
1
+ import { OctopusReactNativeSdk } from './internals/nativeModule';
2
+ import type { UserProfileField } from './types/userProfileField';
3
+
4
+ /**
5
+ * Configuration params for initializing the Octopus SDK.
6
+ */
7
+ export interface InitializeParams {
8
+ /** Your Octopus API key obtained from the Octopus dashboard */
9
+ apiKey: string;
10
+ /**
11
+ * The connection mode determines how user authentication is handled.
12
+ * - `sso`: Use Single Sign-On with your existing user system
13
+ * - `octopus`: Let Octopus handle user authentication
14
+ */
15
+ connectionMode:
16
+ | {
17
+ /** SSO mode configuration */
18
+ type: 'sso';
19
+ /** List of user profile fields that your app manages directly */
20
+ appManagedFields: UserProfileField[];
21
+ }
22
+ | {
23
+ /** Octopus-managed authentication mode */
24
+ type: 'octopus';
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Initializes the Octopus SDK with the provided configuration.
30
+ *
31
+ * This function must be called before using any other Octopus SDK features.
32
+ * It sets up the SDK with your API key and configures the authentication mode.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Initialize with SSO mode
37
+ * await initialize({
38
+ * apiKey: 'your-api-key',
39
+ * connectionMode: {
40
+ * type: 'sso',
41
+ * appManagedFields: ['username', 'profilePicture']
42
+ * }
43
+ * });
44
+ *
45
+ * // Initialize with Octopus authentication
46
+ * await initialize({
47
+ * apiKey: 'your-api-key',
48
+ * connectionMode: {
49
+ * type: 'octopus'
50
+ * }
51
+ * });
52
+ * ```
53
+ */
54
+ export function initialize(params: InitializeParams): Promise<void> {
55
+ return OctopusReactNativeSdk.initialize(params);
56
+ }
@@ -0,0 +1,4 @@
1
+ import { NativeEventEmitter } from 'react-native';
2
+ import { OctopusReactNativeSdk } from './nativeModule';
3
+
4
+ export const eventEmitter = new NativeEventEmitter(OctopusReactNativeSdk);
@@ -0,0 +1,60 @@
1
+ import { LogLevel } from '../enums/LogLevel.enum';
2
+
3
+ export type LoggerFunction = (
4
+ level: LogLevel,
5
+ message: string,
6
+ data?: Error | Record<string, unknown> | unknown
7
+ ) => void;
8
+
9
+ const defaultLogger: LoggerFunction = (
10
+ _level: LogLevel,
11
+ message: string,
12
+ data?: Error | Record<string, unknown> | unknown
13
+ ): void => {
14
+ console.log(`[Octopus] ${message}`, data);
15
+ };
16
+
17
+ let currentLogger: LoggerFunction = defaultLogger;
18
+
19
+ /**
20
+ * Set a custom logger function to handle all logs
21
+ *
22
+ * @param logger A function that takes a log level and message and handles the logging
23
+ */
24
+ export const setLogger = (logger: LoggerFunction): void => {
25
+ currentLogger = logger;
26
+ };
27
+
28
+ /**
29
+ * Get the current logger function
30
+ */
31
+ export const getLogger = (): LoggerFunction => currentLogger;
32
+
33
+ /**
34
+ * Reset the logger to the default implementation
35
+ */
36
+ export const resetLogger = (): void => {
37
+ currentLogger = defaultLogger;
38
+ };
39
+
40
+ let logLevel = LogLevel.WARN;
41
+
42
+ export const setLogLevel = (level: LogLevel) => {
43
+ logLevel = level;
44
+ };
45
+
46
+ export const getLogLevel = () => logLevel;
47
+
48
+ export function log(
49
+ level: LogLevel,
50
+ message: string,
51
+ data?: Error | Record<string, unknown> | unknown
52
+ ): void {
53
+ const currentLogLevel = getLogLevel();
54
+ if (level < currentLogLevel) {
55
+ return;
56
+ }
57
+
58
+ const logger = getLogger();
59
+ logger(level, message, data);
60
+ }