zixflow-reactnative 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.
- package/LICENSE +21 -0
- package/README.md +451 -0
- package/android/build.gradle +155 -0
- package/android/cio-core.gradle +12 -0
- package/android/consumer-rules.pro +3 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +19 -0
- package/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt +85 -0
- package/android/src/main/java/io/customer/reactnative/sdk/NativeCustomerIOModule.kt +201 -0
- package/android/src/main/java/io/customer/reactnative/sdk/constant/Keys.kt +20 -0
- package/android/src/main/java/io/customer/reactnative/sdk/extension/MapExtensions.kt +92 -0
- package/android/src/main/java/io/customer/reactnative/sdk/extension/ReactExtensions.kt +11 -0
- package/android/src/main/java/io/customer/reactnative/sdk/extension/StringExtensions.kt +3 -0
- package/android/src/main/java/io/customer/reactnative/sdk/extension/ViewExtensions.kt +34 -0
- package/android/src/main/java/io/customer/reactnative/sdk/location/NativeLocationModule.kt +66 -0
- package/android/src/main/java/io/customer/reactnative/sdk/logging/NativeCustomerIOLoggingModule.kt +90 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/InlineInAppMessageViewManager.kt +56 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/NativeMessagingInAppModule.kt +215 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/NotificationInboxExtensions.kt +23 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/ReactInAppEventListener.kt +77 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/ReactInAppPlatformDelegate.kt +37 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/ReactInlineInAppMessageView.kt +44 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messaginginapp/ReactNotificationInboxChangeListener.kt +47 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messagingpush/NativeMessagingPushModule.kt +283 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt +9 -0
- package/android/src/main/java/io/customer/reactnative/sdk/messagingpush/PushMessagingExtensions.kt +58 -0
- package/android/src/main/java/io/customer/reactnative/sdk/util/Preconditions.kt +35 -0
- package/android/src/main/res/values/customer_io_config.xml +13 -0
- package/customerio-reactnative.podspec +60 -0
- package/ios/CustomerioReactnative.xcodeproj/project.pbxproj +285 -0
- package/ios/CustomerioReactnative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/CustomerioReactnative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/wrappers/CustomerioReactnative-Bridging-Header.h +2 -0
- package/ios/wrappers/NativeCustomerIO.mm +100 -0
- package/ios/wrappers/NativeCustomerIO.swift +162 -0
- package/ios/wrappers/inapp/InboxMessage+Conversion.swift +22 -0
- package/ios/wrappers/inapp/NativeMessagingInApp.mm +122 -0
- package/ios/wrappers/inapp/NativeMessagingInApp.swift +214 -0
- package/ios/wrappers/inapp/ReactInAppEventListener.swift +74 -0
- package/ios/wrappers/inapp/inline/InlineInAppMessageStateEvent.swift +23 -0
- package/ios/wrappers/inapp/inline/RCTInlineMessageNative.h +18 -0
- package/ios/wrappers/inapp/inline/RCTInlineMessageNative.mm +168 -0
- package/ios/wrappers/inapp/inline/ReactInlineMessageView.h +42 -0
- package/ios/wrappers/inapp/inline/ReactInlineMessageView.swift +124 -0
- package/ios/wrappers/location/NativeLocation.mm +52 -0
- package/ios/wrappers/location/NativeLocation.swift +37 -0
- package/ios/wrappers/logging/NativeCustomerIOLogging.mm +81 -0
- package/ios/wrappers/logging/NativeCustomerIOLogging.swift +62 -0
- package/ios/wrappers/push/NativeMessagingPush.mm +87 -0
- package/ios/wrappers/push/NativeMessagingPush.swift +119 -0
- package/ios/wrappers/utils/CioConfigUtils.swift +63 -0
- package/ios/wrappers/utils/CioConstants.swift +25 -0
- package/ios/wrappers/utils/Preconditions.swift +20 -0
- package/ios/wrappers/utils/RCTCustomerIOUtils.h +19 -0
- package/lib/commonjs/cio-params.js +2 -0
- package/lib/commonjs/cio-params.js.map +1 -0
- package/lib/commonjs/components/InlineInAppMessageView.js +146 -0
- package/lib/commonjs/components/InlineInAppMessageView.js.map +1 -0
- package/lib/commonjs/components/index.js +14 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/customerio-cdp.js +163 -0
- package/lib/commonjs/customerio-cdp.js.map +1 -0
- package/lib/commonjs/customerio-inapp.js +107 -0
- package/lib/commonjs/customerio-inapp.js.map +1 -0
- package/lib/commonjs/customerio-location.js +53 -0
- package/lib/commonjs/customerio-location.js.map +1 -0
- package/lib/commonjs/customerio-push.js +115 -0
- package/lib/commonjs/customerio-push.js.map +1 -0
- package/lib/commonjs/index.js +17 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/native-logger-listener.js +84 -0
- package/lib/commonjs/native-logger-listener.js.map +1 -0
- package/lib/commonjs/notification-inbox.js +132 -0
- package/lib/commonjs/notification-inbox.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/postInstall.js +13 -0
- package/lib/commonjs/postInstall.js.map +1 -0
- package/lib/commonjs/specs/components/InlineMessageNativeComponent.ts +59 -0
- package/lib/commonjs/specs/modules/NativeCustomerIO.js +40 -0
- package/lib/commonjs/specs/modules/NativeCustomerIO.js.map +1 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOLocation.js +15 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOLocation.js.map +1 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOLogging.js +19 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOLogging.js.map +1 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOMessagingInApp.js +16 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOMessagingInApp.js.map +1 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOMessagingPush.js +15 -0
- package/lib/commonjs/specs/modules/NativeCustomerIOMessagingPush.js.map +1 -0
- package/lib/commonjs/types/data-pipelines.js +123 -0
- package/lib/commonjs/types/data-pipelines.js.map +1 -0
- package/lib/commonjs/types/in-app.js +43 -0
- package/lib/commonjs/types/in-app.js.map +1 -0
- package/lib/commonjs/types/index.js +39 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/internal.js +2 -0
- package/lib/commonjs/types/internal.js.map +1 -0
- package/lib/commonjs/types/push.js +49 -0
- package/lib/commonjs/types/push.js.map +1 -0
- package/lib/commonjs/utils/native-bridge.js +31 -0
- package/lib/commonjs/utils/native-bridge.js.map +1 -0
- package/lib/commonjs/utils/param-validation.js +136 -0
- package/lib/commonjs/utils/param-validation.js.map +1 -0
- package/lib/commonjs/zixflow.js +71 -0
- package/lib/commonjs/zixflow.js.map +1 -0
- package/lib/module/cio-params.js +2 -0
- package/lib/module/cio-params.js.map +1 -0
- package/lib/module/components/InlineInAppMessageView.js +141 -0
- package/lib/module/components/InlineInAppMessageView.js.map +1 -0
- package/lib/module/components/index.js +6 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/customerio-cdp.js +157 -0
- package/lib/module/customerio-cdp.js.map +1 -0
- package/lib/module/customerio-inapp.js +92 -0
- package/lib/module/customerio-inapp.js.map +1 -0
- package/lib/module/customerio-location.js +48 -0
- package/lib/module/customerio-location.js.map +1 -0
- package/lib/module/customerio-push.js +111 -0
- package/lib/module/customerio-push.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/native-logger-listener.js +79 -0
- package/lib/module/native-logger-listener.js.map +1 -0
- package/lib/module/notification-inbox.js +127 -0
- package/lib/module/notification-inbox.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/postInstall.js +13 -0
- package/lib/module/postInstall.js.map +1 -0
- package/lib/module/specs/components/InlineMessageNativeComponent.ts +59 -0
- package/lib/module/specs/modules/NativeCustomerIO.js +41 -0
- package/lib/module/specs/modules/NativeCustomerIO.js.map +1 -0
- package/lib/module/specs/modules/NativeCustomerIOLocation.js +13 -0
- package/lib/module/specs/modules/NativeCustomerIOLocation.js.map +1 -0
- package/lib/module/specs/modules/NativeCustomerIOLogging.js +18 -0
- package/lib/module/specs/modules/NativeCustomerIOLogging.js.map +1 -0
- package/lib/module/specs/modules/NativeCustomerIOMessagingInApp.js +15 -0
- package/lib/module/specs/modules/NativeCustomerIOMessagingInApp.js.map +1 -0
- package/lib/module/specs/modules/NativeCustomerIOMessagingPush.js +13 -0
- package/lib/module/specs/modules/NativeCustomerIOMessagingPush.js.map +1 -0
- package/lib/module/types/data-pipelines.js +126 -0
- package/lib/module/types/data-pipelines.js.map +1 -0
- package/lib/module/types/in-app.js +42 -0
- package/lib/module/types/in-app.js.map +1 -0
- package/lib/module/types/index.js +6 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/internal.js +2 -0
- package/lib/module/types/internal.js.map +1 -0
- package/lib/module/types/push.js +47 -0
- package/lib/module/types/push.js.map +1 -0
- package/lib/module/utils/native-bridge.js +25 -0
- package/lib/module/utils/native-bridge.js.map +1 -0
- package/lib/module/utils/param-validation.js +132 -0
- package/lib/module/utils/param-validation.js.map +1 -0
- package/lib/module/zixflow.js +23 -0
- package/lib/module/zixflow.js.map +1 -0
- package/lib/typescript/commonjs/cio-params.d.ts +5 -0
- package/lib/typescript/commonjs/cio-params.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/InlineInAppMessageView.d.ts +41 -0
- package/lib/typescript/commonjs/components/InlineInAppMessageView.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/customerio-cdp.d.ts +40 -0
- package/lib/typescript/commonjs/customerio-cdp.d.ts.map +1 -0
- package/lib/typescript/commonjs/customerio-inapp.d.ts +48 -0
- package/lib/typescript/commonjs/customerio-inapp.d.ts.map +1 -0
- package/lib/typescript/commonjs/customerio-location.d.ts +31 -0
- package/lib/typescript/commonjs/customerio-location.d.ts.map +1 -0
- package/lib/typescript/commonjs/customerio-push.d.ts +56 -0
- package/lib/typescript/commonjs/customerio-push.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +8 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/native-logger-listener.d.ts +8 -0
- package/lib/typescript/commonjs/native-logger-listener.d.ts.map +1 -0
- package/lib/typescript/commonjs/notification-inbox.d.ts +57 -0
- package/lib/typescript/commonjs/notification-inbox.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/postInstall.d.ts +2 -0
- package/lib/typescript/commonjs/postInstall.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/components/InlineMessageNativeComponent.d.ts +40 -0
- package/lib/typescript/commonjs/specs/components/InlineMessageNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIO.d.ts +46 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIO.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOLocation.d.ts +14 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOLocation.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOLogging.d.ts +18 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOLogging.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOMessagingInApp.d.ts +23 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOMessagingInApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOMessagingPush.d.ts +20 -0
- package/lib/typescript/commonjs/specs/modules/NativeCustomerIOMessagingPush.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/data-pipelines.d.ts +143 -0
- package/lib/typescript/commonjs/types/data-pipelines.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/in-app.d.ts +67 -0
- package/lib/typescript/commonjs/types/in-app.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +4 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/internal.d.ts +20 -0
- package/lib/typescript/commonjs/types/internal.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/push.d.ts +49 -0
- package/lib/typescript/commonjs/types/push.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/native-bridge.d.ts +9 -0
- package/lib/typescript/commonjs/utils/native-bridge.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/param-validation.d.ts +44 -0
- package/lib/typescript/commonjs/utils/param-validation.d.ts.map +1 -0
- package/lib/typescript/commonjs/zixflow.d.ts +14 -0
- package/lib/typescript/commonjs/zixflow.d.ts.map +1 -0
- package/lib/typescript/module/cio-params.d.ts +5 -0
- package/lib/typescript/module/cio-params.d.ts.map +1 -0
- package/lib/typescript/module/components/InlineInAppMessageView.d.ts +41 -0
- package/lib/typescript/module/components/InlineInAppMessageView.d.ts.map +1 -0
- package/lib/typescript/module/components/index.d.ts +3 -0
- package/lib/typescript/module/components/index.d.ts.map +1 -0
- package/lib/typescript/module/customerio-cdp.d.ts +40 -0
- package/lib/typescript/module/customerio-cdp.d.ts.map +1 -0
- package/lib/typescript/module/customerio-inapp.d.ts +48 -0
- package/lib/typescript/module/customerio-inapp.d.ts.map +1 -0
- package/lib/typescript/module/customerio-location.d.ts +31 -0
- package/lib/typescript/module/customerio-location.d.ts.map +1 -0
- package/lib/typescript/module/customerio-push.d.ts +56 -0
- package/lib/typescript/module/customerio-push.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +8 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/native-logger-listener.d.ts +8 -0
- package/lib/typescript/module/native-logger-listener.d.ts.map +1 -0
- package/lib/typescript/module/notification-inbox.d.ts +57 -0
- package/lib/typescript/module/notification-inbox.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/postInstall.d.ts +2 -0
- package/lib/typescript/module/postInstall.d.ts.map +1 -0
- package/lib/typescript/module/specs/components/InlineMessageNativeComponent.d.ts +40 -0
- package/lib/typescript/module/specs/components/InlineMessageNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIO.d.ts +46 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIO.d.ts.map +1 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOLocation.d.ts +14 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOLocation.d.ts.map +1 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOLogging.d.ts +18 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOLogging.d.ts.map +1 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOMessagingInApp.d.ts +23 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOMessagingInApp.d.ts.map +1 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOMessagingPush.d.ts +20 -0
- package/lib/typescript/module/specs/modules/NativeCustomerIOMessagingPush.d.ts.map +1 -0
- package/lib/typescript/module/types/data-pipelines.d.ts +143 -0
- package/lib/typescript/module/types/data-pipelines.d.ts.map +1 -0
- package/lib/typescript/module/types/in-app.d.ts +67 -0
- package/lib/typescript/module/types/in-app.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +4 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/types/internal.d.ts +20 -0
- package/lib/typescript/module/types/internal.d.ts.map +1 -0
- package/lib/typescript/module/types/push.d.ts +49 -0
- package/lib/typescript/module/types/push.d.ts.map +1 -0
- package/lib/typescript/module/utils/native-bridge.d.ts +9 -0
- package/lib/typescript/module/utils/native-bridge.d.ts.map +1 -0
- package/lib/typescript/module/utils/param-validation.d.ts +44 -0
- package/lib/typescript/module/utils/param-validation.d.ts.map +1 -0
- package/lib/typescript/module/zixflow.d.ts +14 -0
- package/lib/typescript/module/zixflow.d.ts.map +1 -0
- package/package.json +165 -0
- package/src/cio-params.ts +4 -0
- package/src/components/InlineInAppMessageView.tsx +187 -0
- package/src/components/index.ts +3 -0
- package/src/customerio-cdp.ts +190 -0
- package/src/customerio-inapp.ts +127 -0
- package/src/customerio-location.ts +56 -0
- package/src/customerio-push.ts +127 -0
- package/src/index.ts +9 -0
- package/src/native-logger-listener.ts +84 -0
- package/src/notification-inbox.ts +154 -0
- package/src/postInstall.js +10 -0
- package/src/specs/components/InlineMessageNativeComponent.ts +59 -0
- package/src/specs/modules/NativeCustomerIO.ts +55 -0
- package/src/specs/modules/NativeCustomerIOLocation.ts +15 -0
- package/src/specs/modules/NativeCustomerIOLogging.ts +24 -0
- package/src/specs/modules/NativeCustomerIOMessagingInApp.ts +30 -0
- package/src/specs/modules/NativeCustomerIOMessagingPush.ts +27 -0
- package/src/types/data-pipelines.ts +150 -0
- package/src/types/in-app.ts +69 -0
- package/src/types/index.ts +3 -0
- package/src/types/internal.ts +20 -0
- package/src/types/push.ts +50 -0
- package/src/utils/native-bridge.ts +30 -0
- package/src/utils/param-validation.ts +178 -0
- package/src/zixflow.ts +24 -0
- package/zixflow-reactnative-richpush.podspec +42 -0
- package/zixflow-reactnative.podspec +66 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { CustomerIOInAppMessaging } from './customerio-inapp';
|
|
2
|
+
import { CustomerIOLocation } from './customerio-location';
|
|
3
|
+
import { CustomerIOPushMessaging } from './customerio-push';
|
|
4
|
+
import { NativeLoggerListener } from './native-logger-listener';
|
|
5
|
+
import {
|
|
6
|
+
default as NativeModule,
|
|
7
|
+
type Spec as CodegenSpec,
|
|
8
|
+
} from './specs/modules/NativeCustomerIO';
|
|
9
|
+
import {
|
|
10
|
+
CioLogLevel,
|
|
11
|
+
MetricEvent,
|
|
12
|
+
type CioConfig,
|
|
13
|
+
type CustomAttributes,
|
|
14
|
+
type IdentifyParams,
|
|
15
|
+
} from './types';
|
|
16
|
+
import type { NativeSDKArgs } from './types/internal';
|
|
17
|
+
import { callNativeModule, ensureNativeModule } from './utils/native-bridge';
|
|
18
|
+
import { assert, validate } from './utils/param-validation';
|
|
19
|
+
|
|
20
|
+
const packageJson = require('../../package.json');
|
|
21
|
+
|
|
22
|
+
// Track whether CustomerIO SDK has been initialized to prevent usage before setup
|
|
23
|
+
let _initialized = false;
|
|
24
|
+
|
|
25
|
+
// Reference to the native CustomerIO Data Pipelines module for SDK operations
|
|
26
|
+
const nativeModule = ensureNativeModule(NativeModule);
|
|
27
|
+
|
|
28
|
+
// Wrapper function that ensures SDK is initialized before calling native methods
|
|
29
|
+
const withNativeModule = <R>(fn: (native: CodegenSpec) => R): R => {
|
|
30
|
+
return callNativeModule(nativeModule, fn);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** @public */
|
|
34
|
+
export class CustomerIO {
|
|
35
|
+
/** Initialize the CustomerIO SDK with given configuration. */
|
|
36
|
+
static readonly initialize = async (config: CioConfig) => {
|
|
37
|
+
assert.config(config);
|
|
38
|
+
|
|
39
|
+
if (config.logLevel && config.logLevel !== CioLogLevel.None) {
|
|
40
|
+
NativeLoggerListener.initialize();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const expoVersion = packageJson.expoVersion ?? '';
|
|
44
|
+
const args: NativeSDKArgs = {
|
|
45
|
+
packageSource: expoVersion ? 'Expo' : 'ReactNative',
|
|
46
|
+
packageVersion: expoVersion || packageJson.version || '',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const promise = callNativeModule(NativeModule, (native) =>
|
|
50
|
+
native.initialize(config, args)
|
|
51
|
+
);
|
|
52
|
+
return promise.then(() => {
|
|
53
|
+
_initialized = true;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Identify a user to start tracking their activity. Requires userId, traits, or both. */
|
|
58
|
+
static readonly identify = async ({
|
|
59
|
+
userId,
|
|
60
|
+
traits,
|
|
61
|
+
}: IdentifyParams = {}) => {
|
|
62
|
+
if (validate.isUndefined(userId) && validate.isUndefined(traits)) {
|
|
63
|
+
throw new Error('You must provide either userId or traits to identify');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
assert.string(userId, 'userId', {
|
|
67
|
+
allowEmpty: false,
|
|
68
|
+
usage: 'Identify',
|
|
69
|
+
optional: true,
|
|
70
|
+
});
|
|
71
|
+
const normalizedTraits = assert.attributes(traits, 'traits', {
|
|
72
|
+
usage: 'Identify',
|
|
73
|
+
optional: true,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return withNativeModule<any>((native) =>
|
|
77
|
+
native.identify({ userId, traits: normalizedTraits })
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** Clear current user identification and stop tracking. */
|
|
82
|
+
static readonly clearIdentify = async () => {
|
|
83
|
+
return withNativeModule<any>((native) => native.clearIdentify());
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Track an event with optional properties. */
|
|
87
|
+
static readonly track = async (
|
|
88
|
+
name: string,
|
|
89
|
+
properties?: Record<string, any>
|
|
90
|
+
) => {
|
|
91
|
+
assert.string(name, 'name', { usage: 'Track Event' });
|
|
92
|
+
const normalizedProps = assert.attributes(properties, 'properties', {
|
|
93
|
+
usage: 'Track Event',
|
|
94
|
+
optional: true,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return withNativeModule<any>((native) =>
|
|
98
|
+
native.track(name, normalizedProps)
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Track a screen view event with optional properties. */
|
|
103
|
+
static readonly screen = async (
|
|
104
|
+
title: string,
|
|
105
|
+
properties?: Record<string, any>
|
|
106
|
+
) => {
|
|
107
|
+
assert.string(title, 'title', { usage: 'Screen' });
|
|
108
|
+
const normalizedProps = assert.attributes(properties, 'properties', {
|
|
109
|
+
usage: 'Screen',
|
|
110
|
+
optional: true,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return withNativeModule<any>((native) =>
|
|
114
|
+
native.screen(title, normalizedProps)
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** Set or update attributes for the currently identified user profile. */
|
|
119
|
+
static readonly setProfileAttributes = async (
|
|
120
|
+
attributes: Record<string, any>
|
|
121
|
+
) => {
|
|
122
|
+
const normalizedAttrs = assert.attributes(attributes, 'attributes', {
|
|
123
|
+
usage: 'Profile',
|
|
124
|
+
}) as CustomAttributes;
|
|
125
|
+
|
|
126
|
+
return withNativeModule<any>((native) =>
|
|
127
|
+
native.setProfileAttributes(normalizedAttrs)
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** Set attributes for the current device. */
|
|
132
|
+
static readonly setDeviceAttributes = async (
|
|
133
|
+
attributes: Record<string, any>
|
|
134
|
+
) => {
|
|
135
|
+
const normalizedAttrs = assert.attributes(attributes, 'attributes', {
|
|
136
|
+
usage: 'Device',
|
|
137
|
+
}) as CustomAttributes;
|
|
138
|
+
|
|
139
|
+
return withNativeModule<any>((native) =>
|
|
140
|
+
native.setDeviceAttributes(normalizedAttrs)
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** Register a device token for push notifications. */
|
|
145
|
+
static readonly registerDeviceToken = async (token: string) => {
|
|
146
|
+
assert.string(token, 'token', { usage: 'Device' });
|
|
147
|
+
|
|
148
|
+
return withNativeModule((native) => native.registerDeviceToken(token));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/** Remove the current device token to stop receiving push notifications. */
|
|
152
|
+
static readonly deleteDeviceToken = async () => {
|
|
153
|
+
return withNativeModule((native) => native.deleteDeviceToken());
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Track push notification metrics for delivered, opened, or converted events. */
|
|
157
|
+
static readonly trackMetric = async ({
|
|
158
|
+
deliveryID,
|
|
159
|
+
deviceToken,
|
|
160
|
+
event,
|
|
161
|
+
}: {
|
|
162
|
+
deliveryID: string;
|
|
163
|
+
deviceToken: string;
|
|
164
|
+
event: MetricEvent;
|
|
165
|
+
}) => {
|
|
166
|
+
assert.string(deliveryID, 'deliveryID', { usage: 'Track Metric' });
|
|
167
|
+
assert.string(deviceToken, 'deviceToken', { usage: 'Track Metric' });
|
|
168
|
+
assert.string(event, 'event', { usage: 'Track Metric' });
|
|
169
|
+
|
|
170
|
+
return withNativeModule((native) =>
|
|
171
|
+
native.trackMetric(deliveryID, deviceToken, event)
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Check if the CustomerIO SDK has been initialized.
|
|
177
|
+
* @deprecated This method will be removed in a future version. If you need this functionality, please contact us.
|
|
178
|
+
*/
|
|
179
|
+
static readonly isInitialized = () => _initialized;
|
|
180
|
+
|
|
181
|
+
static readonly inAppMessaging = new CustomerIOInAppMessaging();
|
|
182
|
+
static readonly location = new CustomerIOLocation();
|
|
183
|
+
static readonly pushMessaging = new CustomerIOPushMessaging();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Initialize native logger when this module loads to ensure it's always available.
|
|
187
|
+
// Since customerio-cdp.ts is the main SDK entry point and always imported,
|
|
188
|
+
// this guarantees logger initialization even when native-logger-listener.ts
|
|
189
|
+
// isn't directly accessed, also supporting auto-initialization in Expo apps.
|
|
190
|
+
NativeLoggerListener.initNativeLogger();
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type EventSubscription, type TurboModule } from 'react-native';
|
|
2
|
+
import { InlineInAppMessageView } from './components';
|
|
3
|
+
import { NativeLoggerListener } from './native-logger-listener';
|
|
4
|
+
import {
|
|
5
|
+
NotificationInbox,
|
|
6
|
+
type NotificationInboxSpec,
|
|
7
|
+
} from './notification-inbox';
|
|
8
|
+
import NativeCustomerIOMessagingInApp, {
|
|
9
|
+
type Spec as CodegenSpec,
|
|
10
|
+
} from './specs/modules/NativeCustomerIOMessagingInApp';
|
|
11
|
+
import type { InAppMessageEventType } from './types';
|
|
12
|
+
import { callNativeModule, ensureNativeModule } from './utils/native-bridge';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Ensures all methods defined in codegen spec are implemented by the public module
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
interface NativeInAppSpec extends Omit<
|
|
20
|
+
CodegenSpec,
|
|
21
|
+
keyof TurboModule | NotificationInboxSpec | 'onInAppEventReceived'
|
|
22
|
+
> {}
|
|
23
|
+
|
|
24
|
+
// Reference to the native CustomerIO Data Pipelines module for SDK operations
|
|
25
|
+
const nativeModule = ensureNativeModule(NativeCustomerIOMessagingInApp);
|
|
26
|
+
|
|
27
|
+
// Wrapper function that ensures SDK is initialized before calling native methods
|
|
28
|
+
const withNativeModule = <R>(fn: (native: CodegenSpec) => R): R => {
|
|
29
|
+
return callNativeModule(nativeModule, fn);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Helper class so that registering event listeners is easier for customers.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
class CustomerIOInAppMessaging implements NativeInAppSpec {
|
|
38
|
+
private _notificationInbox?: NotificationInbox;
|
|
39
|
+
|
|
40
|
+
registerEventsListener(
|
|
41
|
+
listener: (event: InAppMessageEvent) => void
|
|
42
|
+
): EventSubscription {
|
|
43
|
+
const emitter = (data: any) => {
|
|
44
|
+
// Convert raw native payload to InAppMessageEvent
|
|
45
|
+
const event = new InAppMessageEvent(
|
|
46
|
+
data.eventType as InAppMessageEventType,
|
|
47
|
+
data.messageId,
|
|
48
|
+
data.deliveryId,
|
|
49
|
+
data.actionValue,
|
|
50
|
+
data.actionName
|
|
51
|
+
);
|
|
52
|
+
listener(event);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return withNativeModule((native) => {
|
|
56
|
+
try {
|
|
57
|
+
// Register TurboModule event listener and return subscription.
|
|
58
|
+
// This method is generated by codegen in the native modules.
|
|
59
|
+
// Wrapped in try-catch due to previous reports of crashes on certain Android architectures.
|
|
60
|
+
return native.onInAppEventReceived(emitter);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
NativeLoggerListener.warn(
|
|
63
|
+
'Failed to attach in-app event listener:',
|
|
64
|
+
error
|
|
65
|
+
);
|
|
66
|
+
// Return a no-op subscription to maintain backwards compatibility
|
|
67
|
+
return {
|
|
68
|
+
remove: () => {},
|
|
69
|
+
eventType: '',
|
|
70
|
+
key: 0,
|
|
71
|
+
subscriber: null as any,
|
|
72
|
+
} as EventSubscription;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Dismisses any currently displayed in-app message
|
|
79
|
+
*/
|
|
80
|
+
dismissMessage() {
|
|
81
|
+
withNativeModule((native) => native.dismissMessage());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets the message inbox instance for managing inbox messages
|
|
86
|
+
*
|
|
87
|
+
* @returns NotificationInbox instance for fetching and managing inbox messages
|
|
88
|
+
*/
|
|
89
|
+
inbox(): NotificationInbox {
|
|
90
|
+
if (!this._notificationInbox) {
|
|
91
|
+
this._notificationInbox = new NotificationInbox();
|
|
92
|
+
}
|
|
93
|
+
return this._notificationInbox;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Class to hold in-app event attributes.
|
|
99
|
+
*/
|
|
100
|
+
/** @public */
|
|
101
|
+
class InAppMessageEvent {
|
|
102
|
+
eventType: InAppMessageEventType;
|
|
103
|
+
messageId: string;
|
|
104
|
+
deliveryId?: string;
|
|
105
|
+
actionValue?: string;
|
|
106
|
+
actionName?: string;
|
|
107
|
+
|
|
108
|
+
constructor(
|
|
109
|
+
eventType: InAppMessageEventType,
|
|
110
|
+
messageId: string,
|
|
111
|
+
deliveryId?: string,
|
|
112
|
+
actionValue?: string,
|
|
113
|
+
actionName?: string
|
|
114
|
+
) {
|
|
115
|
+
this.eventType = eventType;
|
|
116
|
+
this.deliveryId = deliveryId;
|
|
117
|
+
this.messageId = messageId;
|
|
118
|
+
this.actionValue = actionValue;
|
|
119
|
+
this.actionName = actionName;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Export in-app messaging types and components for simplified imports
|
|
124
|
+
export type { InlineInAppMessageViewProps } from './components';
|
|
125
|
+
export { NotificationInbox } from './notification-inbox';
|
|
126
|
+
export type { InboxMessage, NotificationInboxChangeListener } from './types';
|
|
127
|
+
export { CustomerIOInAppMessaging, InAppMessageEvent, InlineInAppMessageView };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
default as NativeModule,
|
|
4
|
+
type Spec as CodegenSpec,
|
|
5
|
+
} from './specs/modules/NativeCustomerIOLocation';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ensures all methods defined in codegen spec are implemented by the public module
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
interface NativeLocationSpec extends Omit<CodegenSpec, keyof TurboModule> {}
|
|
13
|
+
|
|
14
|
+
// Location is an optional module — NativeModule may be null when location is not enabled.
|
|
15
|
+
// Methods silently no-op when the native module is unavailable, with a one-time dev warning.
|
|
16
|
+
let hasWarnedNotEnabled = false;
|
|
17
|
+
const withNativeModule = (fn: (native: CodegenSpec) => void): void => {
|
|
18
|
+
if (NativeModule) {
|
|
19
|
+
fn(NativeModule);
|
|
20
|
+
} else if (__DEV__ && !hasWarnedNotEnabled) {
|
|
21
|
+
hasWarnedNotEnabled = true;
|
|
22
|
+
console.warn(
|
|
23
|
+
'Customer.io: Location module is not enabled. ' +
|
|
24
|
+
'To use location features, set customerio_location_enabled=true in ' +
|
|
25
|
+
'gradle.properties (Android) or add the location subspec to your Podfile (iOS).'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** @public */
|
|
31
|
+
export class CustomerIOLocation implements NativeLocationSpec {
|
|
32
|
+
/**
|
|
33
|
+
* Sets the last known location from the host app's existing location system.
|
|
34
|
+
* Use this when your app already manages location and you want to send that data
|
|
35
|
+
* to Customer.io without the SDK managing location permissions directly.
|
|
36
|
+
*
|
|
37
|
+
* @param latitude - Latitude in degrees, must be between -90 and 90
|
|
38
|
+
* @param longitude - Longitude in degrees, must be between -180 and 180
|
|
39
|
+
*/
|
|
40
|
+
setLastKnownLocation(latitude: number, longitude: number): void {
|
|
41
|
+
return withNativeModule((native) =>
|
|
42
|
+
native.setLastKnownLocation(latitude, longitude)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Requests a single location update and sends the result to Customer.io.
|
|
48
|
+
* No-ops if location tracking is disabled or permission is not granted.
|
|
49
|
+
*
|
|
50
|
+
* The SDK does not request location permission. The host app must request
|
|
51
|
+
* runtime permissions and only call this when permission is granted.
|
|
52
|
+
*/
|
|
53
|
+
requestLocationUpdate(): void {
|
|
54
|
+
return withNativeModule((native) => native.requestLocationUpdate());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Platform, type TurboModule } from 'react-native';
|
|
2
|
+
import NativeCustomerIOMessagingPush, {
|
|
3
|
+
type Spec as CodegenSpec,
|
|
4
|
+
} from './specs/modules/NativeCustomerIOMessagingPush';
|
|
5
|
+
import {
|
|
6
|
+
type CioPushPermissionOptions,
|
|
7
|
+
CioPushPermissionStatus,
|
|
8
|
+
} from './types';
|
|
9
|
+
import { callNativeModule, ensureNativeModule } from './utils/native-bridge';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ensures all methods defined in codegen spec are implemented by the public module
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
interface NativePushSpec extends Omit<CodegenSpec, keyof TurboModule> {}
|
|
17
|
+
|
|
18
|
+
// Reference to the native CustomerIO Data Pipelines module for SDK operations
|
|
19
|
+
const nativeModule = ensureNativeModule(NativeCustomerIOMessagingPush);
|
|
20
|
+
|
|
21
|
+
// Wrapper function that ensures SDK is initialized before calling native methods
|
|
22
|
+
const withNativeModule = <R>(fn: (native: CodegenSpec) => R): R => {
|
|
23
|
+
return callNativeModule(nativeModule, fn);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
class CustomerIOPushMessaging implements NativePushSpec {
|
|
28
|
+
/**
|
|
29
|
+
* Processes push notification received outside the CIO SDK. The method displays notification on
|
|
30
|
+
* device and tracks CIO metrics for push notification.
|
|
31
|
+
*
|
|
32
|
+
* @param message - push payload received from FCM. The payload must contain data payload received in push
|
|
33
|
+
* notification.
|
|
34
|
+
* @param handleNotificationTrigger - indicates whether it should display the notification or not.
|
|
35
|
+
* true (default): The SDK will display the notification and track associated metrics.
|
|
36
|
+
* false: The SDK will only process the notification to track metrics but will not display any notification.
|
|
37
|
+
* @returns promise that resolves to boolean indicating if the notification was handled by the SDK or not.
|
|
38
|
+
*/
|
|
39
|
+
onMessageReceived(
|
|
40
|
+
message: any,
|
|
41
|
+
handleNotificationTrigger: boolean = true
|
|
42
|
+
): Promise<boolean> {
|
|
43
|
+
if (Platform.OS === 'ios') {
|
|
44
|
+
// Since push notifications on iOS work fine with multiple notification services,
|
|
45
|
+
// We don't need to process them on iOS for now.
|
|
46
|
+
// Resolving promise to true makes it easier for callers to avoid adding
|
|
47
|
+
// unnecessary platform specific checks.
|
|
48
|
+
return Promise.resolve(true);
|
|
49
|
+
} else {
|
|
50
|
+
return withNativeModule((native) =>
|
|
51
|
+
native.onMessageReceived(message, handleNotificationTrigger)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Handles push notification received when app is background. Since FCM itself displays the notification
|
|
58
|
+
* when app is background, this method makes it easier to determine whether the notification should be
|
|
59
|
+
* displayed or not.
|
|
60
|
+
*
|
|
61
|
+
* @see [onMessageReceived] for more details
|
|
62
|
+
*/
|
|
63
|
+
onBackgroundMessageReceived(message: any): Promise<boolean> {
|
|
64
|
+
return this.onMessageReceived(message, !message.notification);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Track push notifications metrics using this method.
|
|
69
|
+
* Call this method when a user interacts and taps open the push notification.
|
|
70
|
+
* @param payload - Customer.io payload as received from the push notification
|
|
71
|
+
*/
|
|
72
|
+
trackNotificationResponseReceived(payload: Object) {
|
|
73
|
+
// Tracking push notification metrics on Android is handled automatically
|
|
74
|
+
// through the Google Services API, so there is no need to make a specific call for it.
|
|
75
|
+
// This method is specific to iOS and works as expected on Android without any additional intervention.
|
|
76
|
+
if (payload == null || this.isAndroid()) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
withNativeModule((native) =>
|
|
80
|
+
native.trackNotificationResponseReceived(payload)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Track push notifications metrics using this method.
|
|
86
|
+
* Call this method when a push notification is received.
|
|
87
|
+
* @param payload - Customer.io payload as received from the push notification
|
|
88
|
+
*/
|
|
89
|
+
trackNotificationReceived(payload: Object) {
|
|
90
|
+
// Tracking push notification metrics on Android is handled automatically
|
|
91
|
+
// through the Google Services API, so there is no need to make a specific call for it.
|
|
92
|
+
// This method is specific to iOS and works as expected on Android without any additional intervention.
|
|
93
|
+
if (payload == null || this.isAndroid()) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
withNativeModule((native) => native.trackNotificationReceived(payload));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the registered device token for the app.
|
|
101
|
+
* @returns Promise with device token as a string, or error if no token is
|
|
102
|
+
* registered or the method fails to fetch token.
|
|
103
|
+
*/
|
|
104
|
+
getRegisteredDeviceToken(): Promise<string> {
|
|
105
|
+
return withNativeModule((native) => native.getRegisteredDeviceToken());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
showPromptForPushNotifications(
|
|
109
|
+
options: CioPushPermissionOptions = { ios: { badge: true, sound: true } }
|
|
110
|
+
): Promise<CioPushPermissionStatus> {
|
|
111
|
+
return withNativeModule((native) =>
|
|
112
|
+
native.showPromptForPushNotifications(options)
|
|
113
|
+
).then((status) => status as CioPushPermissionStatus);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getPushPermissionStatus(): Promise<CioPushPermissionStatus> {
|
|
117
|
+
return withNativeModule((native) => native.getPushPermissionStatus()).then(
|
|
118
|
+
(status) => status as CioPushPermissionStatus
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
isAndroid(): boolean {
|
|
123
|
+
return Platform.OS === 'android';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { CustomerIOPushMessaging };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file serves as the entry point for the module zixflow-reactnative.
|
|
3
|
+
*
|
|
4
|
+
* This SDK is a customized fork of the Customer.io React Native SDK,
|
|
5
|
+
* optimized for use with the Zixflow platform.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Export ONLY the Zixflow-branded API (no backward compatibility with CustomerIO names)
|
|
9
|
+
export * from './zixflow';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import NativeCustomerIOLogging from './specs/modules/NativeCustomerIOLogging';
|
|
2
|
+
import { CioLogLevel } from './types';
|
|
3
|
+
import { callNativeModule, ensureNativeModule } from './utils/native-bridge';
|
|
4
|
+
|
|
5
|
+
// Reference to the native CustomerIO logging module for SDK operations
|
|
6
|
+
const nativeModule = ensureNativeModule(NativeCustomerIOLogging);
|
|
7
|
+
|
|
8
|
+
// Wrapper function that ensures SDK is initialized before calling native methods
|
|
9
|
+
const withNativeModule = <R>(
|
|
10
|
+
fn: (native: typeof NativeCustomerIOLogging) => R
|
|
11
|
+
): R => {
|
|
12
|
+
return callNativeModule(nativeModule, fn);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/* @internal */
|
|
16
|
+
export class NativeLoggerListener {
|
|
17
|
+
private static isInitialized = false;
|
|
18
|
+
// Prefix for all CustomerIO log messages
|
|
19
|
+
private static loggerPrefix = '[CIO] ';
|
|
20
|
+
|
|
21
|
+
static async initialize(): Promise<void> {
|
|
22
|
+
// Prevent multiple registrations of the same log listener
|
|
23
|
+
if (this.isInitialized) {
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Using console.log will log to the JavaScript side but prevent
|
|
28
|
+
// React Native's default behavior of redirecting logs to the native side.
|
|
29
|
+
// By doing it asynchronously, we ensure the logs are captured on both
|
|
30
|
+
// the JavaScript and native ends.
|
|
31
|
+
const logEvent = async (event: {
|
|
32
|
+
logLevel: CioLogLevel;
|
|
33
|
+
message: string;
|
|
34
|
+
}) => {
|
|
35
|
+
switch (event.logLevel) {
|
|
36
|
+
case CioLogLevel.Debug:
|
|
37
|
+
console.debug(this.loggerPrefix + event.message);
|
|
38
|
+
break;
|
|
39
|
+
case CioLogLevel.Info:
|
|
40
|
+
console.info(this.loggerPrefix + event.message);
|
|
41
|
+
break;
|
|
42
|
+
case CioLogLevel.Error:
|
|
43
|
+
console.error(this.loggerPrefix + event.message);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
console.log(this.loggerPrefix + event);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const logHandler = (data: any) => {
|
|
52
|
+
const event = data as { logLevel: CioLogLevel; message: string };
|
|
53
|
+
logEvent(event);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
withNativeModule((native) => {
|
|
57
|
+
try {
|
|
58
|
+
// Register TurboModule event listener and return subscription.
|
|
59
|
+
// This method is generated by codegen in the native modules.
|
|
60
|
+
// Wrapped in try-catch due to previous reports of crashes on certain Android architectures.
|
|
61
|
+
native.onCioLogEvent(logHandler);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
NativeLoggerListener.warn('Failed to attach log listener:', error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
this.isInitialized = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Logs warning messages in development mode only, with CIO prefix
|
|
70
|
+
static warn(message: string, error?: unknown) {
|
|
71
|
+
if (__DEV__) {
|
|
72
|
+
console.warn(this.loggerPrefix + message, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Initializes native logger listener with error handling
|
|
77
|
+
static initNativeLogger() {
|
|
78
|
+
try {
|
|
79
|
+
NativeLoggerListener.initialize();
|
|
80
|
+
} catch (error) {
|
|
81
|
+
NativeLoggerListener.warn('Failed to initialize native logger:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|