From 33dcd4b82acec4532fe71aed798a7ee0cc1620d6 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 18:24:10 -0800 Subject: [PATCH 01/22] Refactor file structure: move `IterableInbox` to `inbox` directory and update imports; create new hooks index file --- src/hooks/index.ts | 2 ++ src/{ => hooks}/useAppStateListener.ts | 0 src/{ => hooks}/useDeviceOrientation.tsx | 0 src/{ => inbox}/IterableInbox.tsx | 21 ++++++++++----------- src/inbox/index.ts | 1 + src/index.tsx | 6 +++--- src/screens/index.ts | 0 src/utils/index.ts | 0 8 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 src/hooks/index.ts rename src/{ => hooks}/useAppStateListener.ts (100%) rename src/{ => hooks}/useDeviceOrientation.tsx (100%) rename src/{ => inbox}/IterableInbox.tsx (93%) create mode 100644 src/inbox/index.ts create mode 100644 src/screens/index.ts create mode 100644 src/utils/index.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts new file mode 100644 index 000000000..35d77007a --- /dev/null +++ b/src/hooks/index.ts @@ -0,0 +1,2 @@ +export * from './useAppStateListener'; +export * from './useDeviceOrientation'; diff --git a/src/useAppStateListener.ts b/src/hooks/useAppStateListener.ts similarity index 100% rename from src/useAppStateListener.ts rename to src/hooks/useAppStateListener.ts diff --git a/src/useDeviceOrientation.tsx b/src/hooks/useDeviceOrientation.tsx similarity index 100% rename from src/useDeviceOrientation.tsx rename to src/hooks/useDeviceOrientation.tsx diff --git a/src/IterableInbox.tsx b/src/inbox/IterableInbox.tsx similarity index 93% rename from src/IterableInbox.tsx rename to src/inbox/IterableInbox.tsx index 08f4c6836..0f548eb3b 100644 --- a/src/IterableInbox.tsx +++ b/src/inbox/IterableInbox.tsx @@ -11,20 +11,19 @@ import { } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; -import type { InboxImpressionRowInfo } from './InboxImpressionRowInfo'; -import type { InboxRowViewModel } from './InboxRowViewModel'; -import { Iterable } from './Iterable'; +import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; +import type { InboxRowViewModel } from '../InboxRowViewModel'; +import { Iterable } from '../Iterable'; import { IterableInAppDeleteSource, IterableInAppLocation, -} from './IterableInAppClasses'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; -import IterableInboxDataModel from './IterableInboxDataModel'; -import IterableInboxEmptyState from './IterableInboxEmptyState'; -import IterableInboxMessageDisplay from './IterableInboxMessageDisplay'; -import IterableInboxMessageList from './IterableInboxMessageList'; -import useAppStateListener from './useAppStateListener'; -import useDeviceOrientation from './useDeviceOrientation'; +} from '../IterableInAppClasses'; +import type { IterableInboxCustomizations } from '../IterableInboxCustomizations'; +import IterableInboxDataModel from '../IterableInboxDataModel'; +import IterableInboxEmptyState from '../IterableInboxEmptyState'; +import IterableInboxMessageDisplay from '../IterableInboxMessageDisplay'; +import IterableInboxMessageList from '../IterableInboxMessageList'; +import { useAppStateListener, useDeviceOrientation } from '../hooks'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); diff --git a/src/inbox/index.ts b/src/inbox/index.ts new file mode 100644 index 000000000..1aae11ba7 --- /dev/null +++ b/src/inbox/index.ts @@ -0,0 +1 @@ +export * from './IterableInbox'; diff --git a/src/index.tsx b/src/index.tsx index b40df9825..9991b7a48 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,9 +32,9 @@ export { } from './IterableInAppClasses'; export { IterableInAppManager } from './IterableInAppManager'; export { IterableInAppMessage } from './IterableInAppMessage'; -export { IterableInbox, type IterableInboxProps } from './IterableInbox'; +export { IterableInbox, type IterableInboxProps } from './inbox/IterableInbox'; export type { IterableInboxCustomizations } from './IterableInboxCustomizations'; export { IterableInboxEmptyState } from './IterableInboxEmptyState'; export { IterableInboxMessageCell } from './IterableInboxMessageCell'; -export { useAppStateListener } from './useAppStateListener'; -export { useDeviceOrientation } from './useDeviceOrientation'; +export { useAppStateListener } from './hooks/useAppStateListener'; +export { useDeviceOrientation } from './hooks/useDeviceOrientation'; diff --git a/src/screens/index.ts b/src/screens/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 000000000..e69de29bb From a1d215f8f0eed50fdc218146e30ab0890faababa Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 18:27:11 -0800 Subject: [PATCH 02/22] Update imports for IterableInboxCustomizations to reflect new file structure --- src/IterableInboxEmptyState.tsx | 2 +- src/IterableInboxMessageCell.tsx | 2 +- src/IterableInboxMessageList.tsx | 2 +- src/inbox/IterableInbox.tsx | 2 +- src/{ => inbox}/IterableInboxCustomizations.ts | 0 src/inbox/index.ts | 1 + src/index.tsx | 5 ++--- 7 files changed, 7 insertions(+), 7 deletions(-) rename src/{ => inbox}/IterableInboxCustomizations.ts (100%) diff --git a/src/IterableInboxEmptyState.tsx b/src/IterableInboxEmptyState.tsx index d1c754764..5a71b6506 100644 --- a/src/IterableInboxEmptyState.tsx +++ b/src/IterableInboxEmptyState.tsx @@ -1,6 +1,6 @@ import { StyleSheet, Text, View } from 'react-native'; -import { type IterableInboxCustomizations } from './IterableInboxCustomizations'; +import { type IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; // TODO: Comment type EmptyStateProps = { diff --git a/src/IterableInboxMessageCell.tsx b/src/IterableInboxMessageCell.tsx index 3fdbc7548..36a92974c 100644 --- a/src/IterableInboxMessageCell.tsx +++ b/src/IterableInboxMessageCell.tsx @@ -12,7 +12,7 @@ import { } from 'react-native'; import type { InboxRowViewModel } from './InboxRowViewModel'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; +import type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; import IterableInboxDataModel from './IterableInboxDataModel'; diff --git a/src/IterableInboxMessageList.tsx b/src/IterableInboxMessageList.tsx index 5902b8b9e..b7204e060 100644 --- a/src/IterableInboxMessageList.tsx +++ b/src/IterableInboxMessageList.tsx @@ -4,7 +4,7 @@ import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; import type { InboxImpressionRowInfo } from './InboxImpressionRowInfo'; import type { InboxRowViewModel } from './InboxRowViewModel'; import IterableInAppMessage from './IterableInAppMessage'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; +import type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; import IterableInboxDataModel from './IterableInboxDataModel'; import IterableInboxMessageCell from './IterableInboxMessageCell'; diff --git a/src/inbox/IterableInbox.tsx b/src/inbox/IterableInbox.tsx index 0f548eb3b..d4d7b54d7 100644 --- a/src/inbox/IterableInbox.tsx +++ b/src/inbox/IterableInbox.tsx @@ -18,7 +18,7 @@ import { IterableInAppDeleteSource, IterableInAppLocation, } from '../IterableInAppClasses'; -import type { IterableInboxCustomizations } from '../IterableInboxCustomizations'; +import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; import IterableInboxDataModel from '../IterableInboxDataModel'; import IterableInboxEmptyState from '../IterableInboxEmptyState'; import IterableInboxMessageDisplay from '../IterableInboxMessageDisplay'; diff --git a/src/IterableInboxCustomizations.ts b/src/inbox/IterableInboxCustomizations.ts similarity index 100% rename from src/IterableInboxCustomizations.ts rename to src/inbox/IterableInboxCustomizations.ts diff --git a/src/inbox/index.ts b/src/inbox/index.ts index 1aae11ba7..601a9a660 100644 --- a/src/inbox/index.ts +++ b/src/inbox/index.ts @@ -1 +1,2 @@ export * from './IterableInbox'; +export * from './IterableInboxCustomizations'; diff --git a/src/index.tsx b/src/index.tsx index 9991b7a48..7ecf85a5b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -33,8 +33,7 @@ export { export { IterableInAppManager } from './IterableInAppManager'; export { IterableInAppMessage } from './IterableInAppMessage'; export { IterableInbox, type IterableInboxProps } from './inbox/IterableInbox'; -export type { IterableInboxCustomizations } from './IterableInboxCustomizations'; +export type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; export { IterableInboxEmptyState } from './IterableInboxEmptyState'; export { IterableInboxMessageCell } from './IterableInboxMessageCell'; -export { useAppStateListener } from './hooks/useAppStateListener'; -export { useDeviceOrientation } from './hooks/useDeviceOrientation'; +export { useAppStateListener, useDeviceOrientation } from './hooks'; From e5ff1889d2fd8dd049cc32067dc112819efb70cd Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 18:43:43 -0800 Subject: [PATCH 03/22] Refactor file structure: move inbox-related components to `inbox` directory and update imports accordingly --- src/inbox/IterableInbox.tsx | 11 ++++++----- src/{ => inbox}/IterableInboxDataModel.ts | 10 +++++----- src/{ => inbox}/IterableInboxEmptyState.tsx | 8 ++++---- src/{ => inbox}/IterableInboxMessageCell.tsx | 10 +++++----- src/{ => inbox}/IterableInboxMessageDisplay.tsx | 14 +++++++------- src/{ => inbox}/IterableInboxMessageList.tsx | 15 ++++++++------- src/inbox/index.ts | 2 ++ src/index.tsx | 11 +++++++---- 8 files changed, 44 insertions(+), 37 deletions(-) rename src/{ => inbox}/IterableInboxDataModel.ts (94%) rename src/{ => inbox}/IterableInboxEmptyState.tsx (89%) rename src/{ => inbox}/IterableInboxMessageCell.tsx (97%) rename src/{ => inbox}/IterableInboxMessageDisplay.tsx (95%) rename src/{ => inbox}/IterableInboxMessageList.tsx (89%) diff --git a/src/inbox/IterableInbox.tsx b/src/inbox/IterableInbox.tsx index d4d7b54d7..1093b6578 100644 --- a/src/inbox/IterableInbox.tsx +++ b/src/inbox/IterableInbox.tsx @@ -18,13 +18,14 @@ import { IterableInAppDeleteSource, IterableInAppLocation, } from '../IterableInAppClasses'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; -import IterableInboxDataModel from '../IterableInboxDataModel'; -import IterableInboxEmptyState from '../IterableInboxEmptyState'; -import IterableInboxMessageDisplay from '../IterableInboxMessageDisplay'; -import IterableInboxMessageList from '../IterableInboxMessageList'; import { useAppStateListener, useDeviceOrientation } from '../hooks'; +import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; +import IterableInboxDataModel from './IterableInboxDataModel'; +import IterableInboxEmptyState from './IterableInboxEmptyState'; +import IterableInboxMessageDisplay from './IterableInboxMessageDisplay'; +import IterableInboxMessageList from './IterableInboxMessageList'; + const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); diff --git a/src/IterableInboxDataModel.ts b/src/inbox/IterableInboxDataModel.ts similarity index 94% rename from src/IterableInboxDataModel.ts rename to src/inbox/IterableInboxDataModel.ts index 62ec110b8..6b88153ac 100644 --- a/src/IterableInboxDataModel.ts +++ b/src/inbox/IterableInboxDataModel.ts @@ -3,13 +3,13 @@ import { IterableHtmlInAppContent, IterableInAppDeleteSource, IterableInAppLocation, -} from './IterableInAppClasses'; +} from '../IterableInAppClasses'; -import { Iterable } from './Iterable'; +import { Iterable } from '../Iterable'; -import type { InboxImpressionRowInfo } from './InboxImpressionRowInfo'; -import type { InboxRowViewModel } from './InboxRowViewModel'; -import IterableInAppMessage from './IterableInAppMessage'; +import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; +import type { InboxRowViewModel } from '../InboxRowViewModel'; +import IterableInAppMessage from '../IterableInAppMessage'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/IterableInboxEmptyState.tsx b/src/inbox/IterableInboxEmptyState.tsx similarity index 89% rename from src/IterableInboxEmptyState.tsx rename to src/inbox/IterableInboxEmptyState.tsx index 5a71b6506..d901139a0 100644 --- a/src/IterableInboxEmptyState.tsx +++ b/src/inbox/IterableInboxEmptyState.tsx @@ -1,9 +1,9 @@ import { StyleSheet, Text, View } from 'react-native'; -import { type IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; +import { type IterableInboxCustomizations } from './IterableInboxCustomizations'; // TODO: Comment -type EmptyStateProps = { +export interface IterableInboxEmptyStateProps { customizations: IterableInboxCustomizations; tabBarHeight: number; tabBarPadding: number; @@ -11,7 +11,7 @@ type EmptyStateProps = { contentWidth: number; height: number; isPortrait: boolean; -}; +} export const IterableInboxEmptyState = ({ customizations, @@ -20,7 +20,7 @@ export const IterableInboxEmptyState = ({ navTitleHeight, height, isPortrait, -}: EmptyStateProps) => { +}: IterableInboxEmptyStateProps) => { const defaultTitle = 'No saved messages'; const defaultBody = 'Check again later!'; diff --git a/src/IterableInboxMessageCell.tsx b/src/inbox/IterableInboxMessageCell.tsx similarity index 97% rename from src/IterableInboxMessageCell.tsx rename to src/inbox/IterableInboxMessageCell.tsx index 36a92974c..6b11e5a5f 100644 --- a/src/IterableInboxMessageCell.tsx +++ b/src/inbox/IterableInboxMessageCell.tsx @@ -11,8 +11,8 @@ import { type ViewStyle, } from 'react-native'; -import type { InboxRowViewModel } from './InboxRowViewModel'; -import type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; +import type { InboxRowViewModel } from '../InboxRowViewModel'; +import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; import IterableInboxDataModel from './IterableInboxDataModel'; @@ -161,7 +161,7 @@ function defaultMessageListLayout( } // TODO: Comment -type MessageCellProps = { +export interface IterableInboxMessageCellProps { index: number; last: boolean; dataModel: IterableInboxDataModel; @@ -173,7 +173,7 @@ type MessageCellProps = { handleMessageSelect: Function; contentWidth: number; isPortrait: boolean; -}; +} // TODO: Comment export const IterableInboxMessageCell = ({ @@ -188,7 +188,7 @@ export const IterableInboxMessageCell = ({ handleMessageSelect, contentWidth, isPortrait, -}: MessageCellProps) => { +}: IterableInboxMessageCellProps) => { const position = useRef(new Animated.ValueXY()).current; let deleteSliderHeight = customizations.messageRow?.height diff --git a/src/IterableInboxMessageDisplay.tsx b/src/inbox/IterableInboxMessageDisplay.tsx similarity index 95% rename from src/IterableInboxMessageDisplay.tsx rename to src/inbox/IterableInboxMessageDisplay.tsx index 730a1320c..bff5cca8f 100644 --- a/src/IterableInboxMessageDisplay.tsx +++ b/src/inbox/IterableInboxMessageDisplay.tsx @@ -10,29 +10,29 @@ import { import Icon from 'react-native-vector-icons/Ionicons'; import { WebView } from 'react-native-webview'; -import { type InboxRowViewModel } from './InboxRowViewModel'; -import { Iterable } from './Iterable'; +import { type InboxRowViewModel } from '../InboxRowViewModel'; +import { Iterable } from '../Iterable'; import { IterableAction, IterableActionContext, IterableActionSource, -} from './IterableAction'; +} from '../IterableAction'; import { IterableEdgeInsets, IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, -} from './IterableInAppClasses'; +} from '../IterableInAppClasses'; // TODO: Comment -type MessageDisplayProps = { +export interface IterableInboxMessageDisplayProps { rowViewModel: InboxRowViewModel; inAppContentPromise: Promise; returnToInbox: Function; deleteRow: Function; contentWidth: number; isPortrait: boolean; -}; +} // TODO: Comment export const IterableInboxMessageDisplay = ({ @@ -42,7 +42,7 @@ export const IterableInboxMessageDisplay = ({ deleteRow, contentWidth, isPortrait, -}: MessageDisplayProps) => { +}: IterableInboxMessageDisplayProps) => { const messageTitle = rowViewModel.inAppMessage.inboxMetadata?.title; const [inAppContent, setInAppContent] = useState( new IterableHtmlInAppContent(new IterableEdgeInsets(0, 0, 0, 0), '') diff --git a/src/IterableInboxMessageList.tsx b/src/inbox/IterableInboxMessageList.tsx similarity index 89% rename from src/IterableInboxMessageList.tsx rename to src/inbox/IterableInboxMessageList.tsx index b7204e060..5bd3bb21f 100644 --- a/src/IterableInboxMessageList.tsx +++ b/src/inbox/IterableInboxMessageList.tsx @@ -1,15 +1,16 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; -import type { InboxImpressionRowInfo } from './InboxImpressionRowInfo'; -import type { InboxRowViewModel } from './InboxRowViewModel'; -import IterableInAppMessage from './IterableInAppMessage'; -import type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; +import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; +import type { InboxRowViewModel } from '../InboxRowViewModel'; +import IterableInAppMessage from '../IterableInAppMessage'; + +import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; import IterableInboxDataModel from './IterableInboxDataModel'; import IterableInboxMessageCell from './IterableInboxMessageCell'; // TODO: Comment -type MessageListProps = { +export interface IterableInboxMessageListProps { dataModel: IterableInboxDataModel; rowViewModels: InboxRowViewModel[]; customizations: IterableInboxCustomizations; @@ -19,7 +20,7 @@ type MessageListProps = { updateVisibleMessageImpressions: Function; contentWidth: number; isPortrait: boolean; -}; +} // TODO: Comment export const IterableInboxMessageList = ({ @@ -32,7 +33,7 @@ export const IterableInboxMessageList = ({ updateVisibleMessageImpressions, contentWidth, isPortrait, -}: MessageListProps) => { +}: IterableInboxMessageListProps) => { const [swiping, setSwiping] = useState(false); const flatListRef = useRef(null); diff --git a/src/inbox/index.ts b/src/inbox/index.ts index 601a9a660..6ed3d3a13 100644 --- a/src/inbox/index.ts +++ b/src/inbox/index.ts @@ -1,2 +1,4 @@ export * from './IterableInbox'; export * from './IterableInboxCustomizations'; +export * from './IterableInboxEmptyState'; +export * from './IterableInboxMessageCell'; diff --git a/src/index.tsx b/src/index.tsx index 7ecf85a5b..ffdfb8f4f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,8 +32,11 @@ export { } from './IterableInAppClasses'; export { IterableInAppManager } from './IterableInAppManager'; export { IterableInAppMessage } from './IterableInAppMessage'; -export { IterableInbox, type IterableInboxProps } from './inbox/IterableInbox'; -export type { IterableInboxCustomizations } from './inbox/IterableInboxCustomizations'; -export { IterableInboxEmptyState } from './IterableInboxEmptyState'; -export { IterableInboxMessageCell } from './IterableInboxMessageCell'; +export { + type IterableInboxCustomizations, + IterableInbox, + type IterableInboxProps, + IterableInboxEmptyState, + IterableInboxMessageCell, +} from './inbox'; export { useAppStateListener, useDeviceOrientation } from './hooks'; From 827462ae135f452610c849a10cb44502d940bd58 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 20:43:49 -0800 Subject: [PATCH 04/22] Refactor imports: consolidate IterableInApp classes into a single inApp module and update references --- src/Iterable.ts | 6 +++--- src/IterableConfig.ts | 3 +-- src/__mocks__/MockRNIterableAPI.ts | 2 +- src/__tests__/IterableInApp.test.ts | 4 ++-- src/{ => inApp}/IterableInAppClasses.ts | 0 src/{ => inApp}/IterableInAppManager.ts | 2 +- src/{ => inApp}/IterableInAppMessage.ts | 2 +- src/inApp/inApp.enums.ts | 0 src/inApp/index.ts | 3 +++ src/inbox/IterableInbox.tsx | 5 +---- src/inbox/IterableInboxDataModel.ts | 9 ++++----- src/inbox/IterableInboxMessageDisplay.tsx | 2 +- src/inbox/IterableInboxMessageList.tsx | 2 +- src/index.tsx | 6 +++--- 14 files changed, 22 insertions(+), 24 deletions(-) rename src/{ => inApp}/IterableInAppClasses.ts (100%) rename src/{ => inApp}/IterableInAppManager.ts (99%) rename src/{ => inApp}/IterableInAppMessage.ts (98%) create mode 100644 src/inApp/inApp.enums.ts create mode 100644 src/inApp/index.ts diff --git a/src/Iterable.ts b/src/Iterable.ts index 2daee5659..293aa9192 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -12,12 +12,12 @@ import { import { IterableAction, IterableActionContext } from './IterableAction'; import IterableConfig, { AuthResponse } from './IterableConfig'; import { + IterableInAppManager, + IterableInAppMessage, IterableInAppCloseSource, IterableInAppDeleteSource, IterableInAppLocation, -} from './IterableInAppClasses'; -import IterableInAppManager from './IterableInAppManager'; -import IterableInAppMessage from './IterableInAppMessage'; +} from './inApp'; import { IterableLogger } from './IterableLogger'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index 087ccb93d..d621e9c55 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -4,8 +4,7 @@ import { IterableLogLevel, } from './IterableAction'; import { IterableDataRegion } from './IterableDataRegion'; -import { IterableInAppShowResponse } from './IterableInAppClasses'; -import IterableInAppMessage from './IterableInAppMessage'; +import { IterableInAppShowResponse, IterableInAppMessage } from './inApp'; import { IterablePushPlatform } from './IterablePushPlatform'; // TODO: Add description diff --git a/src/__mocks__/MockRNIterableAPI.ts b/src/__mocks__/MockRNIterableAPI.ts index 03c3edac6..14d706142 100644 --- a/src/__mocks__/MockRNIterableAPI.ts +++ b/src/__mocks__/MockRNIterableAPI.ts @@ -1,5 +1,5 @@ import { IterableAttributionInfo } from '../Iterable'; -import IterableInAppMessage from '../IterableInAppMessage'; +import { IterableInAppMessage } from '../inApp'; export class MockRNIterableAPI { static email?: string; diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index 4889fa021..05f78d89a 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -4,7 +4,6 @@ import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; import { Iterable, EventName } from '../Iterable'; import IterableConfig from '../IterableConfig'; -import IterableInAppMessage from '../IterableInAppMessage'; import { IterableInAppLocation, IterableInAppTrigger, @@ -13,7 +12,8 @@ import { IterableInAppCloseSource, IterableInAppShowResponse, IterableInAppDeleteSource, -} from '../IterableInAppClasses'; + IterableInAppMessage, +} from '../inApp'; import { IterableLogger } from '../IterableLogger'; describe('Iterable In App', () => { diff --git a/src/IterableInAppClasses.ts b/src/inApp/IterableInAppClasses.ts similarity index 100% rename from src/IterableInAppClasses.ts rename to src/inApp/IterableInAppClasses.ts diff --git a/src/IterableInAppManager.ts b/src/inApp/IterableInAppManager.ts similarity index 99% rename from src/IterableInAppManager.ts rename to src/inApp/IterableInAppManager.ts index de2c0950b..f6e5a4dbf 100644 --- a/src/IterableInAppManager.ts +++ b/src/inApp/IterableInAppManager.ts @@ -1,6 +1,6 @@ import { NativeModules } from 'react-native'; -import { Iterable } from './Iterable'; +import { Iterable } from '../Iterable'; import { IterableHtmlInAppContent, IterableInAppDeleteSource, diff --git a/src/IterableInAppMessage.ts b/src/inApp/IterableInAppMessage.ts similarity index 98% rename from src/IterableInAppMessage.ts rename to src/inApp/IterableInAppMessage.ts index 816b250f7..0afe951ac 100644 --- a/src/IterableInAppMessage.ts +++ b/src/inApp/IterableInAppMessage.ts @@ -1,6 +1,6 @@ import { type ViewToken } from 'react-native'; -import IterableUtil from './IterableUtil'; +import IterableUtil from '../IterableUtil'; import { IterableInAppTrigger, diff --git a/src/inApp/inApp.enums.ts b/src/inApp/inApp.enums.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/inApp/index.ts b/src/inApp/index.ts new file mode 100644 index 000000000..e6f38b75a --- /dev/null +++ b/src/inApp/index.ts @@ -0,0 +1,3 @@ +export * from './IterableInAppClasses'; +export * from './IterableInAppManager'; +export * from './IterableInAppMessage'; diff --git a/src/inbox/IterableInbox.tsx b/src/inbox/IterableInbox.tsx index 1093b6578..ba1d3aa20 100644 --- a/src/inbox/IterableInbox.tsx +++ b/src/inbox/IterableInbox.tsx @@ -14,10 +14,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; import type { InboxRowViewModel } from '../InboxRowViewModel'; import { Iterable } from '../Iterable'; -import { - IterableInAppDeleteSource, - IterableInAppLocation, -} from '../IterableInAppClasses'; +import { IterableInAppDeleteSource, IterableInAppLocation } from '../inApp'; import { useAppStateListener, useDeviceOrientation } from '../hooks'; import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; diff --git a/src/inbox/IterableInboxDataModel.ts b/src/inbox/IterableInboxDataModel.ts index 6b88153ac..b0dbf3119 100644 --- a/src/inbox/IterableInboxDataModel.ts +++ b/src/inbox/IterableInboxDataModel.ts @@ -1,15 +1,14 @@ import { NativeModules } from 'react-native'; + import { IterableHtmlInAppContent, IterableInAppDeleteSource, IterableInAppLocation, -} from '../IterableInAppClasses'; - -import { Iterable } from '../Iterable'; - + IterableInAppMessage, +} from '../inApp'; import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; import type { InboxRowViewModel } from '../InboxRowViewModel'; -import IterableInAppMessage from '../IterableInAppMessage'; +import { Iterable } from '../Iterable'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inbox/IterableInboxMessageDisplay.tsx b/src/inbox/IterableInboxMessageDisplay.tsx index bff5cca8f..24bf2c3e5 100644 --- a/src/inbox/IterableInboxMessageDisplay.tsx +++ b/src/inbox/IterableInboxMessageDisplay.tsx @@ -22,7 +22,7 @@ import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, -} from '../IterableInAppClasses'; +} from '../inApp'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/inbox/IterableInboxMessageList.tsx b/src/inbox/IterableInboxMessageList.tsx index 5bd3bb21f..89752a424 100644 --- a/src/inbox/IterableInboxMessageList.tsx +++ b/src/inbox/IterableInboxMessageList.tsx @@ -3,7 +3,7 @@ import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; import type { InboxRowViewModel } from '../InboxRowViewModel'; -import IterableInAppMessage from '../IterableInAppMessage'; +import { IterableInAppMessage } from '../inApp'; import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; import IterableInboxDataModel from './IterableInboxDataModel'; diff --git a/src/index.tsx b/src/index.tsx index ffdfb8f4f..42e2ab2cf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,8 @@ export { export { IterableConfig } from './IterableConfig'; export { IterableDataRegion } from './IterableDataRegion'; export { + IterableInAppMessage, + IterableInAppManager, IterableEdgeInsets, IterableHtmlInAppContent, IterableInAppCloseSource, @@ -29,9 +31,7 @@ export { IterableInAppTriggerType, IterableInboxMetadata, type IterableInAppContent, -} from './IterableInAppClasses'; -export { IterableInAppManager } from './IterableInAppManager'; -export { IterableInAppMessage } from './IterableInAppMessage'; +} from './inApp'; export { type IterableInboxCustomizations, IterableInbox, From 27f1bf0f8fee3b28da5a2d3bb09f28f791bfe2cc Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:08:16 -0800 Subject: [PATCH 05/22] Refactor in-app structure: separate classes into individual files, introduce new enums, and update imports accordingly --- src/IterableEdgeInsets.ts | 25 ++++ src/inApp/IterableHtmlInAppContent.ts | 23 ++++ src/inApp/IterableInAppClasses.ts | 132 ------------------- src/inApp/IterableInAppManager.ts | 8 +- src/inApp/IterableInAppMessage.ts | 8 +- src/inApp/IterableInAppTrigger.ts | 17 +++ src/inApp/IterableInboxMetadata.ts | 24 ++++ src/inApp/enums/IterableInAppCloseSource.ts | 8 ++ src/inApp/enums/IterableInAppContentType.ts | 8 ++ src/inApp/enums/IterableInAppDeleteSource.ts | 8 ++ src/inApp/enums/IterableInAppLocation.ts | 7 + src/inApp/enums/IterableInAppShowResponse.ts | 9 ++ src/inApp/enums/IterableInAppTriggerType.ts | 11 ++ src/inApp/enums/index.ts | 6 + src/inApp/inApp.enums.ts | 0 src/inApp/index.ts | 6 +- src/inApp/types/IterableInAppContent.ts | 6 + src/inApp/types/index.ts | 1 + src/inbox/IterableInboxMessageDisplay.tsx | 2 +- src/index.tsx | 2 +- 20 files changed, 166 insertions(+), 145 deletions(-) create mode 100644 src/IterableEdgeInsets.ts create mode 100644 src/inApp/IterableHtmlInAppContent.ts delete mode 100644 src/inApp/IterableInAppClasses.ts create mode 100644 src/inApp/IterableInAppTrigger.ts create mode 100644 src/inApp/IterableInboxMetadata.ts create mode 100644 src/inApp/enums/IterableInAppCloseSource.ts create mode 100644 src/inApp/enums/IterableInAppContentType.ts create mode 100644 src/inApp/enums/IterableInAppDeleteSource.ts create mode 100644 src/inApp/enums/IterableInAppLocation.ts create mode 100644 src/inApp/enums/IterableInAppShowResponse.ts create mode 100644 src/inApp/enums/IterableInAppTriggerType.ts create mode 100644 src/inApp/enums/index.ts delete mode 100644 src/inApp/inApp.enums.ts create mode 100644 src/inApp/types/IterableInAppContent.ts create mode 100644 src/inApp/types/index.ts diff --git a/src/IterableEdgeInsets.ts b/src/IterableEdgeInsets.ts new file mode 100644 index 000000000..44ee24d1e --- /dev/null +++ b/src/IterableEdgeInsets.ts @@ -0,0 +1,25 @@ +// TODO: Add description +export class IterableEdgeInsets { + top: number; + left: number; + bottom: number; + right: number; + + constructor(top: number, left: number, bottom: number, right: number) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + static fromDict(dict: any): IterableEdgeInsets { + return new IterableEdgeInsets( + dict.top as number, + dict.left as number, + dict.bottom as number, + dict.right as number + ); + } +} + +export default IterableEdgeInsets; diff --git a/src/inApp/IterableHtmlInAppContent.ts b/src/inApp/IterableHtmlInAppContent.ts new file mode 100644 index 000000000..8b4ca72b5 --- /dev/null +++ b/src/inApp/IterableHtmlInAppContent.ts @@ -0,0 +1,23 @@ +import IterableEdgeInsets from '../IterableEdgeInsets'; + +import type { IterableInAppContent } from './types'; +import { IterableInAppContentType } from './enums'; + +// TODO: Add description +export class IterableHtmlInAppContent implements IterableInAppContent { + type: IterableInAppContentType = IterableInAppContentType.html; + edgeInsets: IterableEdgeInsets; + html: string; + + constructor(edgeInsets: IterableEdgeInsets, html: string) { + this.edgeInsets = edgeInsets; + this.html = html; + } + + static fromDict(dict: any): IterableHtmlInAppContent { + return new IterableHtmlInAppContent( + IterableEdgeInsets.fromDict(dict.edgeInsets), + dict.html as string + ); + } +} diff --git a/src/inApp/IterableInAppClasses.ts b/src/inApp/IterableInAppClasses.ts deleted file mode 100644 index 83a30cbb8..000000000 --- a/src/inApp/IterableInAppClasses.ts +++ /dev/null @@ -1,132 +0,0 @@ -/** - * TODO: Break this file into multiple files - */ - -// TODO: Add description -export enum IterableInAppShowResponse { - /** Show in-app */ - show = 0, - /** Skip showing in-app */ - skip = 1, -} - -// TODO: Add description -export enum IterableInAppTriggerType { - /** Tries to display the in-app automatically immediately */ - immediate = 0, - /** Used for Push to in-app */ - event = 1, - /** Do not display the in-app automatically via the SDK */ - never = 2, -} - -// TODO: Add description -export class IterableInAppTrigger { - type: IterableInAppTriggerType; - - constructor(type: IterableInAppTriggerType) { - this.type = type; - } - - static fromDict(dict: any): IterableInAppTrigger { - const type = dict.type as - | IterableInAppTriggerType - | IterableInAppTriggerType.immediate; - return new IterableInAppTrigger(type); - } -} - -// TODO: Add description -export enum IterableInAppContentType { - html = 0, - alert = 1, - banner = 2, -} - -// TODO: Add description -export enum IterableInAppLocation { - inApp = 0, - inbox = 1, -} - -// TODO: Add description -export enum IterableInAppCloseSource { - back = 0, - link = 1, - unknown = 100, -} - -// TODO: Add description -export enum IterableInAppDeleteSource { - inboxSwipe = 0, - deleteButton = 1, - unknown = 100, -} - -// TODO: Add description -export class IterableEdgeInsets { - top: number; - left: number; - bottom: number; - right: number; - - constructor(top: number, left: number, bottom: number, right: number) { - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; - } - - static fromDict(dict: any): IterableEdgeInsets { - return new IterableEdgeInsets( - dict.top as number, - dict.left as number, - dict.bottom as number, - dict.right as number - ); - } -} - -// TODO: Add description -export interface IterableInAppContent { - type: IterableInAppContentType; -} - -// TODO: Add description -export class IterableHtmlInAppContent implements IterableInAppContent { - type: IterableInAppContentType = IterableInAppContentType.html; - edgeInsets: IterableEdgeInsets; - html: string; - - constructor(edgeInsets: IterableEdgeInsets, html: string) { - this.edgeInsets = edgeInsets; - this.html = html; - } - - static fromDict(dict: any): IterableHtmlInAppContent { - return new IterableHtmlInAppContent( - IterableEdgeInsets.fromDict(dict.edgeInsets), - dict.html as string - ); - } -} - -export class IterableInboxMetadata { - title?: string; - subtitle?: string; - icon?: string; - - constructor( - title: string | undefined, - subtitle: string | undefined, - icon: string | undefined - ) { - this.title = title; - this.subtitle = subtitle; - this.icon = icon; - } - - static fromDict(dict: any): IterableInboxMetadata { - return new IterableInboxMetadata(dict.title, dict.subtitle, dict.icon); - } -} diff --git a/src/inApp/IterableInAppManager.ts b/src/inApp/IterableInAppManager.ts index f6e5a4dbf..d95065035 100644 --- a/src/inApp/IterableInAppManager.ts +++ b/src/inApp/IterableInAppManager.ts @@ -1,12 +1,10 @@ import { NativeModules } from 'react-native'; import { Iterable } from '../Iterable'; -import { - IterableHtmlInAppContent, - IterableInAppDeleteSource, - IterableInAppLocation, -} from './IterableInAppClasses'; + +import { IterableHtmlInAppContent } from './IterableHtmlInAppContent'; import IterableInAppMessage from './IterableInAppMessage'; +import type { IterableInAppLocation, IterableInAppDeleteSource } from './enums'; // TODO: Create a loader for this const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inApp/IterableInAppMessage.ts b/src/inApp/IterableInAppMessage.ts index 0afe951ac..218ab9872 100644 --- a/src/inApp/IterableInAppMessage.ts +++ b/src/inApp/IterableInAppMessage.ts @@ -2,11 +2,9 @@ import { type ViewToken } from 'react-native'; import IterableUtil from '../IterableUtil'; -import { - IterableInAppTrigger, - IterableInAppTriggerType, - IterableInboxMetadata, -} from './IterableInAppClasses'; +import { IterableInboxMetadata } from './IterableInboxMetadata'; +import { IterableInAppTriggerType } from './enums'; +import { IterableInAppTrigger } from './IterableInAppTrigger'; /** * Iterable in-app message diff --git a/src/inApp/IterableInAppTrigger.ts b/src/inApp/IterableInAppTrigger.ts new file mode 100644 index 000000000..0c03f944f --- /dev/null +++ b/src/inApp/IterableInAppTrigger.ts @@ -0,0 +1,17 @@ +import type { IterableInAppTriggerType } from './enums'; + +// TODO: Add description +export class IterableInAppTrigger { + type: IterableInAppTriggerType; + + constructor(type: IterableInAppTriggerType) { + this.type = type; + } + + static fromDict(dict: any): IterableInAppTrigger { + const type = dict.type as + | IterableInAppTriggerType + | IterableInAppTriggerType.immediate; + return new IterableInAppTrigger(type); + } +} diff --git a/src/inApp/IterableInboxMetadata.ts b/src/inApp/IterableInboxMetadata.ts new file mode 100644 index 000000000..5e77f9e34 --- /dev/null +++ b/src/inApp/IterableInboxMetadata.ts @@ -0,0 +1,24 @@ +/** + * TODO: Add description + */ +export class IterableInboxMetadata { + title?: string; + subtitle?: string; + icon?: string; + + constructor( + title: string | undefined, + subtitle: string | undefined, + icon: string | undefined + ) { + this.title = title; + this.subtitle = subtitle; + this.icon = icon; + } + + static fromDict(dict: any): IterableInboxMetadata { + return new IterableInboxMetadata(dict.title, dict.subtitle, dict.icon); + } +} + +export default IterableInboxMetadata; diff --git a/src/inApp/enums/IterableInAppCloseSource.ts b/src/inApp/enums/IterableInAppCloseSource.ts new file mode 100644 index 000000000..359a2c90e --- /dev/null +++ b/src/inApp/enums/IterableInAppCloseSource.ts @@ -0,0 +1,8 @@ +// TODO: Add description +export enum IterableInAppCloseSource { + back = 0, + link = 1, + unknown = 100, +} + +export default IterableInAppCloseSource; diff --git a/src/inApp/enums/IterableInAppContentType.ts b/src/inApp/enums/IterableInAppContentType.ts new file mode 100644 index 000000000..c97521890 --- /dev/null +++ b/src/inApp/enums/IterableInAppContentType.ts @@ -0,0 +1,8 @@ +// TODO: Add description +export enum IterableInAppContentType { + html = 0, + alert = 1, + banner = 2, +} + +export default IterableInAppContentType; diff --git a/src/inApp/enums/IterableInAppDeleteSource.ts b/src/inApp/enums/IterableInAppDeleteSource.ts new file mode 100644 index 000000000..24a86c2e3 --- /dev/null +++ b/src/inApp/enums/IterableInAppDeleteSource.ts @@ -0,0 +1,8 @@ +// TODO: Add description +export enum IterableInAppDeleteSource { + inboxSwipe = 0, + deleteButton = 1, + unknown = 100, +} + +export default IterableInAppDeleteSource; diff --git a/src/inApp/enums/IterableInAppLocation.ts b/src/inApp/enums/IterableInAppLocation.ts new file mode 100644 index 000000000..4a617c38e --- /dev/null +++ b/src/inApp/enums/IterableInAppLocation.ts @@ -0,0 +1,7 @@ +// TODO: Add description +export enum IterableInAppLocation { + inApp = 0, + inbox = 1, +} + +export default IterableInAppLocation; diff --git a/src/inApp/enums/IterableInAppShowResponse.ts b/src/inApp/enums/IterableInAppShowResponse.ts new file mode 100644 index 000000000..420e4e0ec --- /dev/null +++ b/src/inApp/enums/IterableInAppShowResponse.ts @@ -0,0 +1,9 @@ +// TODO: Add description +export enum IterableInAppShowResponse { + /** Show in-app */ + show = 0, + /** Skip showing in-app */ + skip = 1, +} + +export default IterableInAppShowResponse; diff --git a/src/inApp/enums/IterableInAppTriggerType.ts b/src/inApp/enums/IterableInAppTriggerType.ts new file mode 100644 index 000000000..416043daa --- /dev/null +++ b/src/inApp/enums/IterableInAppTriggerType.ts @@ -0,0 +1,11 @@ +// TODO: Add description +export enum IterableInAppTriggerType { + /** Tries to display the in-app automatically immediately */ + immediate = 0, + /** Used for Push to in-app */ + event = 1, + /** Do not display the in-app automatically via the SDK */ + never = 2, +} + +export default IterableInAppTriggerType; diff --git a/src/inApp/enums/index.ts b/src/inApp/enums/index.ts new file mode 100644 index 000000000..10769e440 --- /dev/null +++ b/src/inApp/enums/index.ts @@ -0,0 +1,6 @@ +export * from './IterableInAppShowResponse'; +export * from './IterableInAppTriggerType'; +export * from './IterableInAppContentType'; +export * from './IterableInAppLocation'; +export * from './IterableInAppDeleteSource'; +export * from './IterableInAppCloseSource'; diff --git a/src/inApp/inApp.enums.ts b/src/inApp/inApp.enums.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/inApp/index.ts b/src/inApp/index.ts index e6f38b75a..3f7287be5 100644 --- a/src/inApp/index.ts +++ b/src/inApp/index.ts @@ -1,3 +1,7 @@ -export * from './IterableInAppClasses'; +export * from './enums'; +export * from './IterableHtmlInAppContent'; export * from './IterableInAppManager'; export * from './IterableInAppMessage'; +export * from './IterableInAppTrigger'; +export * from './IterableInboxMetadata'; +export * from './types'; diff --git a/src/inApp/types/IterableInAppContent.ts b/src/inApp/types/IterableInAppContent.ts new file mode 100644 index 000000000..a2a312e58 --- /dev/null +++ b/src/inApp/types/IterableInAppContent.ts @@ -0,0 +1,6 @@ +import type { IterableInAppContentType } from '../enums'; + +// TODO: Add description +export interface IterableInAppContent { + type: IterableInAppContentType; +} diff --git a/src/inApp/types/index.ts b/src/inApp/types/index.ts new file mode 100644 index 000000000..bd83b3125 --- /dev/null +++ b/src/inApp/types/index.ts @@ -0,0 +1 @@ +export * from './IterableInAppContent'; diff --git a/src/inbox/IterableInboxMessageDisplay.tsx b/src/inbox/IterableInboxMessageDisplay.tsx index 24bf2c3e5..516e6134b 100644 --- a/src/inbox/IterableInboxMessageDisplay.tsx +++ b/src/inbox/IterableInboxMessageDisplay.tsx @@ -18,11 +18,11 @@ import { IterableActionSource, } from '../IterableAction'; import { - IterableEdgeInsets, IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, } from '../inApp'; +import { IterableEdgeInsets } from '../IterableEdgeInsets'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/index.tsx b/src/index.tsx index 42e2ab2cf..a45eeef69 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -17,10 +17,10 @@ export { } from './IterableAction'; export { IterableConfig } from './IterableConfig'; export { IterableDataRegion } from './IterableDataRegion'; +export { IterableEdgeInsets } from './IterableEdgeInsets'; export { IterableInAppMessage, IterableInAppManager, - IterableEdgeInsets, IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppContentType, From 507902a16de88aa2778e46b366c96e1391378e76 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:25:21 -0800 Subject: [PATCH 06/22] Refactor inbox structure: move components to a new `components` directory, consolidate type imports, and update references accordingly --- src/inbox/IterableInboxDataModel.ts | 3 +-- src/inbox/{ => components}/IterableInbox.tsx | 18 ++++++++++-------- .../IterableInboxEmptyState.tsx | 2 +- .../IterableInboxMessageCell.tsx | 5 ++--- .../IterableInboxMessageDisplay.tsx | 18 +++++++++--------- .../IterableInboxMessageList.tsx | 12 +++++++----- src/inbox/components/index.ts | 3 +++ src/inbox/index.ts | 6 ++---- .../types}/InboxImpressionRowInfo.ts | 0 src/{ => inbox/types}/InboxRowViewModel.ts | 2 +- .../{ => types}/IterableInboxCustomizations.ts | 0 src/inbox/types/index.ts | 3 +++ src/index.tsx | 4 ++-- 13 files changed, 41 insertions(+), 35 deletions(-) rename src/inbox/{ => components}/IterableInbox.tsx (96%) rename src/inbox/{ => components}/IterableInboxEmptyState.tsx (94%) rename src/inbox/{ => components}/IterableInboxMessageCell.tsx (97%) rename src/inbox/{ => components}/IterableInboxMessageDisplay.tsx (96%) rename src/inbox/{ => components}/IterableInboxMessageList.tsx (90%) create mode 100644 src/inbox/components/index.ts rename src/{ => inbox/types}/InboxImpressionRowInfo.ts (100%) rename src/{ => inbox/types}/InboxRowViewModel.ts (81%) rename src/inbox/{ => types}/IterableInboxCustomizations.ts (100%) create mode 100644 src/inbox/types/index.ts diff --git a/src/inbox/IterableInboxDataModel.ts b/src/inbox/IterableInboxDataModel.ts index b0dbf3119..547cbdb5d 100644 --- a/src/inbox/IterableInboxDataModel.ts +++ b/src/inbox/IterableInboxDataModel.ts @@ -6,8 +6,7 @@ import { IterableInAppLocation, IterableInAppMessage, } from '../inApp'; -import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; -import type { InboxRowViewModel } from '../InboxRowViewModel'; +import type { InboxImpressionRowInfo, InboxRowViewModel } from './types'; import { Iterable } from '../Iterable'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inbox/IterableInbox.tsx b/src/inbox/components/IterableInbox.tsx similarity index 96% rename from src/inbox/IterableInbox.tsx rename to src/inbox/components/IterableInbox.tsx index ba1d3aa20..859342267 100644 --- a/src/inbox/IterableInbox.tsx +++ b/src/inbox/components/IterableInbox.tsx @@ -11,14 +11,16 @@ import { } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; -import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; -import type { InboxRowViewModel } from '../InboxRowViewModel'; -import { Iterable } from '../Iterable'; -import { IterableInAppDeleteSource, IterableInAppLocation } from '../inApp'; -import { useAppStateListener, useDeviceOrientation } from '../hooks'; - -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; -import IterableInboxDataModel from './IterableInboxDataModel'; +import { Iterable } from '../../Iterable'; +import { useAppStateListener, useDeviceOrientation } from '../../hooks'; +import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp'; + +import IterableInboxDataModel from '../IterableInboxDataModel'; +import type { + InboxImpressionRowInfo, + InboxRowViewModel, + IterableInboxCustomizations, +} from '../types'; import IterableInboxEmptyState from './IterableInboxEmptyState'; import IterableInboxMessageDisplay from './IterableInboxMessageDisplay'; import IterableInboxMessageList from './IterableInboxMessageList'; diff --git a/src/inbox/IterableInboxEmptyState.tsx b/src/inbox/components/IterableInboxEmptyState.tsx similarity index 94% rename from src/inbox/IterableInboxEmptyState.tsx rename to src/inbox/components/IterableInboxEmptyState.tsx index d901139a0..a1a2074f1 100644 --- a/src/inbox/IterableInboxEmptyState.tsx +++ b/src/inbox/components/IterableInboxEmptyState.tsx @@ -1,6 +1,6 @@ import { StyleSheet, Text, View } from 'react-native'; -import { type IterableInboxCustomizations } from './IterableInboxCustomizations'; +import { type IterableInboxCustomizations } from '../types'; // TODO: Comment export interface IterableInboxEmptyStateProps { diff --git a/src/inbox/IterableInboxMessageCell.tsx b/src/inbox/components/IterableInboxMessageCell.tsx similarity index 97% rename from src/inbox/IterableInboxMessageCell.tsx rename to src/inbox/components/IterableInboxMessageCell.tsx index 6b11e5a5f..2f381835b 100644 --- a/src/inbox/IterableInboxMessageCell.tsx +++ b/src/inbox/components/IterableInboxMessageCell.tsx @@ -11,10 +11,9 @@ import { type ViewStyle, } from 'react-native'; -import type { InboxRowViewModel } from '../InboxRowViewModel'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; +import type { InboxRowViewModel, IterableInboxCustomizations } from '../types'; -import IterableInboxDataModel from './IterableInboxDataModel'; +import IterableInboxDataModel from '../IterableInboxDataModel'; // TODO: Change to component function defaultMessageListLayout( diff --git a/src/inbox/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx similarity index 96% rename from src/inbox/IterableInboxMessageDisplay.tsx rename to src/inbox/components/IterableInboxMessageDisplay.tsx index 516e6134b..3c4a51576 100644 --- a/src/inbox/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -10,19 +10,19 @@ import { import Icon from 'react-native-vector-icons/Ionicons'; import { WebView } from 'react-native-webview'; -import { type InboxRowViewModel } from '../InboxRowViewModel'; -import { Iterable } from '../Iterable'; -import { - IterableAction, - IterableActionContext, - IterableActionSource, -} from '../IterableAction'; import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, -} from '../inApp'; -import { IterableEdgeInsets } from '../IterableEdgeInsets'; +} from '../../inApp'; +import { Iterable } from '../../Iterable'; +import { + IterableAction, + IterableActionContext, + IterableActionSource, +} from '../../IterableAction'; +import { IterableEdgeInsets } from '../../IterableEdgeInsets'; +import { type InboxRowViewModel } from '../types'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/inbox/IterableInboxMessageList.tsx b/src/inbox/components/IterableInboxMessageList.tsx similarity index 90% rename from src/inbox/IterableInboxMessageList.tsx rename to src/inbox/components/IterableInboxMessageList.tsx index 89752a424..e45161338 100644 --- a/src/inbox/IterableInboxMessageList.tsx +++ b/src/inbox/components/IterableInboxMessageList.tsx @@ -1,12 +1,14 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; -import type { InboxImpressionRowInfo } from '../InboxImpressionRowInfo'; -import type { InboxRowViewModel } from '../InboxRowViewModel'; -import { IterableInAppMessage } from '../inApp'; +import { IterableInAppMessage } from '../../inApp'; -import type { IterableInboxCustomizations } from './IterableInboxCustomizations'; -import IterableInboxDataModel from './IterableInboxDataModel'; +import IterableInboxDataModel from '../IterableInboxDataModel'; +import type { + InboxImpressionRowInfo, + InboxRowViewModel, + IterableInboxCustomizations, +} from '../types'; import IterableInboxMessageCell from './IterableInboxMessageCell'; // TODO: Comment diff --git a/src/inbox/components/index.ts b/src/inbox/components/index.ts new file mode 100644 index 000000000..2ef11ac16 --- /dev/null +++ b/src/inbox/components/index.ts @@ -0,0 +1,3 @@ +export * from './IterableInbox'; +export * from './IterableInboxEmptyState'; +export * from './IterableInboxMessageCell'; diff --git a/src/inbox/index.ts b/src/inbox/index.ts index 6ed3d3a13..195d95f59 100644 --- a/src/inbox/index.ts +++ b/src/inbox/index.ts @@ -1,4 +1,2 @@ -export * from './IterableInbox'; -export * from './IterableInboxCustomizations'; -export * from './IterableInboxEmptyState'; -export * from './IterableInboxMessageCell'; +export * from './components'; +export * from './types'; diff --git a/src/InboxImpressionRowInfo.ts b/src/inbox/types/InboxImpressionRowInfo.ts similarity index 100% rename from src/InboxImpressionRowInfo.ts rename to src/inbox/types/InboxImpressionRowInfo.ts diff --git a/src/InboxRowViewModel.ts b/src/inbox/types/InboxRowViewModel.ts similarity index 81% rename from src/InboxRowViewModel.ts rename to src/inbox/types/InboxRowViewModel.ts index 966d8f95e..2d0aa9901 100644 --- a/src/InboxRowViewModel.ts +++ b/src/inbox/types/InboxRowViewModel.ts @@ -1,4 +1,4 @@ -import { IterableInAppMessage } from '.'; +import { IterableInAppMessage } from '../..'; // TODO: Add description export type InboxRowViewModel = { diff --git a/src/inbox/IterableInboxCustomizations.ts b/src/inbox/types/IterableInboxCustomizations.ts similarity index 100% rename from src/inbox/IterableInboxCustomizations.ts rename to src/inbox/types/IterableInboxCustomizations.ts diff --git a/src/inbox/types/index.ts b/src/inbox/types/index.ts new file mode 100644 index 000000000..5bd60a01e --- /dev/null +++ b/src/inbox/types/index.ts @@ -0,0 +1,3 @@ +export * from './InboxImpressionRowInfo'; +export * from './InboxRowViewModel'; +export * from './IterableInboxCustomizations'; diff --git a/src/index.tsx b/src/index.tsx index a45eeef69..a3627c3b4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,8 +2,6 @@ * React Native module for Iterable. * @module react-native-iterable-sdk */ -export type { InboxImpressionRowInfo } from './InboxImpressionRowInfo'; -export type { InboxRowViewModel } from './InboxRowViewModel'; export { Iterable, IterableAttributionInfo, @@ -38,5 +36,7 @@ export { type IterableInboxProps, IterableInboxEmptyState, IterableInboxMessageCell, + type InboxImpressionRowInfo, + type InboxRowViewModel, } from './inbox'; export { useAppStateListener, useDeviceOrientation } from './hooks'; From fd2ea1237813b57aedc0d3f4f39f89f2a630bc8c Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:32:56 -0800 Subject: [PATCH 07/22] Refactor Iterable module: rename AuthResponseCallback to IterableAuthResponseResult, move IterableAttributionInfo and IterableCommerceItem to separate files, and update imports accordingly --- src/Iterable.ts | 64 +++++------------------------- src/IterableAttributionInfo.ts | 16 ++++++++ src/IterableCommerceItem.ts | 41 +++++++++++++++++++ src/__mocks__/MockRNIterableAPI.ts | 2 +- src/__tests__/Iterable.test.ts | 8 ++-- src/index.tsx | 36 ++++++++--------- 6 files changed, 87 insertions(+), 80 deletions(-) create mode 100644 src/IterableAttributionInfo.ts create mode 100644 src/IterableCommerceItem.ts diff --git a/src/Iterable.ts b/src/Iterable.ts index 293aa9192..2d8b70ed3 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -19,64 +19,16 @@ import { IterableInAppLocation, } from './inApp'; import { IterableLogger } from './IterableLogger'; +import type IterableCommerceItem from './IterableCommerceItem'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); -enum AuthResponseCallback { +enum IterableAuthResponseResult { SUCCESS, FAILURE, } -export class IterableAttributionInfo { - campaignId: number; - templateId: number; - messageId: string; - - constructor(campaignId: number, templateId: number, messageId: string) { - this.campaignId = campaignId; - this.templateId = templateId; - this.messageId = messageId; - } -} - -export class IterableCommerceItem { - id: string; - name: string; - price: number; - quantity: number; - sku?: string; - description?: string; - url?: string; - imageUrl?: string; - categories?: Array; - dataFields?: any; - - constructor( - id: string, - name: string, - price: number, - quantity: number, - sku?: string, - description?: string, - url?: string, - imageUrl?: string, - categories?: Array, - dataFields?: any | undefined - ) { - this.id = id; - this.name = name; - this.price = price; - this.quantity = quantity; - this.sku = sku; - this.description = description; - this.url = url; - this.imageUrl = imageUrl; - this.categories = categories; - this.dataFields = dataFields; - } -} - export enum EventName { handleUrlCalled = 'handleUrlCalled', handleCustomActionCalled = 'handleCustomActionCalled', @@ -640,7 +592,7 @@ export class Iterable { } if (Iterable.savedConfig.authHandler) { - let authResponseCallback: AuthResponseCallback; + let authResponseCallback: IterableAuthResponseResult; RNEventEmitter.addListener(EventName.handleAuthCalled, () => { Iterable.savedConfig.authHandler!() .then((promiseResult) => { @@ -653,12 +605,14 @@ export class Iterable { ); setTimeout(() => { - if (authResponseCallback === AuthResponseCallback.SUCCESS) { + if ( + authResponseCallback === IterableAuthResponseResult.SUCCESS + ) { if ((promiseResult as AuthResponse).successCallback) { (promiseResult as AuthResponse).successCallback!(); } } else if ( - authResponseCallback === AuthResponseCallback.FAILURE + authResponseCallback === IterableAuthResponseResult.FAILURE ) { if ((promiseResult as AuthResponse).failureCallback) { (promiseResult as AuthResponse).failureCallback!(); @@ -680,10 +634,10 @@ export class Iterable { }); RNEventEmitter.addListener(EventName.handleAuthSuccessCalled, () => { - authResponseCallback = AuthResponseCallback.SUCCESS; + authResponseCallback = IterableAuthResponseResult.SUCCESS; }); RNEventEmitter.addListener(EventName.handleAuthFailureCalled, () => { - authResponseCallback = AuthResponseCallback.FAILURE; + authResponseCallback = IterableAuthResponseResult.FAILURE; }); } diff --git a/src/IterableAttributionInfo.ts b/src/IterableAttributionInfo.ts new file mode 100644 index 000000000..6b960d01b --- /dev/null +++ b/src/IterableAttributionInfo.ts @@ -0,0 +1,16 @@ +/** + * TODO: Add description + */ +export class IterableAttributionInfo { + campaignId: number; + templateId: number; + messageId: string; + + constructor(campaignId: number, templateId: number, messageId: string) { + this.campaignId = campaignId; + this.templateId = templateId; + this.messageId = messageId; + } +} + +export default IterableAttributionInfo; diff --git a/src/IterableCommerceItem.ts b/src/IterableCommerceItem.ts new file mode 100644 index 000000000..3132fd662 --- /dev/null +++ b/src/IterableCommerceItem.ts @@ -0,0 +1,41 @@ +/** + * TODO: Add description + */ +export class IterableCommerceItem { + id: string; + name: string; + price: number; + quantity: number; + sku?: string; + description?: string; + url?: string; + imageUrl?: string; + categories?: Array; + dataFields?: any; + + constructor( + id: string, + name: string, + price: number, + quantity: number, + sku?: string, + description?: string, + url?: string, + imageUrl?: string, + categories?: Array, + dataFields?: any | undefined + ) { + this.id = id; + this.name = name; + this.price = price; + this.quantity = quantity; + this.sku = sku; + this.description = description; + this.url = url; + this.imageUrl = imageUrl; + this.categories = categories; + this.dataFields = dataFields; + } +} + +export default IterableCommerceItem; diff --git a/src/__mocks__/MockRNIterableAPI.ts b/src/__mocks__/MockRNIterableAPI.ts index 14d706142..a6dc1e372 100644 --- a/src/__mocks__/MockRNIterableAPI.ts +++ b/src/__mocks__/MockRNIterableAPI.ts @@ -1,4 +1,4 @@ -import { IterableAttributionInfo } from '../Iterable'; +import { IterableAttributionInfo } from '../IterableAttributionInfo'; import { IterableInAppMessage } from '../inApp'; export class MockRNIterableAPI { diff --git a/src/__tests__/Iterable.test.ts b/src/__tests__/Iterable.test.ts index a257c8f0c..7cff557cb 100644 --- a/src/__tests__/Iterable.test.ts +++ b/src/__tests__/Iterable.test.ts @@ -10,14 +10,12 @@ import { IterableAction, IterableActionContext, IterableActionSource, + IterableAttributionInfo, + IterableCommerceItem, IterableConfig, IterableLogLevel, } from '../index'; -import { - EventName, - IterableAttributionInfo, - IterableCommerceItem, -} from '../Iterable'; +import { EventName } from '../Iterable'; import { IterableDataRegion } from '../IterableDataRegion'; import { IterableLogger } from '../IterableLogger'; diff --git a/src/index.tsx b/src/index.tsx index a3627c3b4..654746260 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,28 +2,15 @@ * React Native module for Iterable. * @module react-native-iterable-sdk */ +export { useAppStateListener, useDeviceOrientation } from './hooks'; export { - Iterable, - IterableAttributionInfo, - IterableCommerceItem, -} from './Iterable'; -export { - IterableAction, - IterableActionContext, - IterableActionSource, - IterableLogLevel, -} from './IterableAction'; -export { IterableConfig } from './IterableConfig'; -export { IterableDataRegion } from './IterableDataRegion'; -export { IterableEdgeInsets } from './IterableEdgeInsets'; -export { - IterableInAppMessage, - IterableInAppManager, IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppContentType, IterableInAppDeleteSource, IterableInAppLocation, + IterableInAppManager, + IterableInAppMessage, IterableInAppShowResponse, IterableInAppTrigger, IterableInAppTriggerType, @@ -31,12 +18,23 @@ export { type IterableInAppContent, } from './inApp'; export { - type IterableInboxCustomizations, IterableInbox, - type IterableInboxProps, IterableInboxEmptyState, IterableInboxMessageCell, type InboxImpressionRowInfo, type InboxRowViewModel, + type IterableInboxCustomizations, + type IterableInboxProps, } from './inbox'; -export { useAppStateListener, useDeviceOrientation } from './hooks'; +export { Iterable } from './Iterable'; +export { + IterableAction, + IterableActionContext, + IterableActionSource, + IterableLogLevel, +} from './IterableAction'; +export { IterableAttributionInfo } from './IterableAttributionInfo'; +export { IterableCommerceItem } from './IterableCommerceItem'; +export { IterableConfig } from './IterableConfig'; +export { IterableDataRegion } from './IterableDataRegion'; +export { IterableEdgeInsets } from './IterableEdgeInsets'; From 5af5f4584dc3f9706f043aa273d0fd205a8a0687 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:33:22 -0800 Subject: [PATCH 08/22] Refactor event names: rename EventName to IterableEventName in Iterable module and update references throughout the codebase --- src/Iterable.ts | 60 ++++++++++++++++++----------- src/__tests__/Iterable.test.ts | 20 +++++----- src/__tests__/IterableInApp.test.ts | 6 +-- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/Iterable.ts b/src/Iterable.ts index 2d8b70ed3..e4fb6c250 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -29,7 +29,7 @@ enum IterableAuthResponseResult { FAILURE, } -export enum EventName { +export enum IterableEventName { handleUrlCalled = 'handleUrlCalled', handleCustomActionCalled = 'handleCustomActionCalled', handleInAppCalled = 'handleInAppCalled', @@ -553,13 +553,15 @@ export class Iterable { // PRIVATE private static setupEventHandlers() { //Remove all listeners to avoid duplicate listeners - RNEventEmitter.removeAllListeners(EventName.handleUrlCalled); - RNEventEmitter.removeAllListeners(EventName.handleInAppCalled); - RNEventEmitter.removeAllListeners(EventName.handleCustomActionCalled); - RNEventEmitter.removeAllListeners(EventName.handleAuthCalled); + RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled); + RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled); + RNEventEmitter.removeAllListeners( + IterableEventName.handleCustomActionCalled + ); + RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled); if (Iterable.savedConfig.urlHandler) { - RNEventEmitter.addListener(EventName.handleUrlCalled, (dict) => { + RNEventEmitter.addListener(IterableEventName.handleUrlCalled, (dict) => { const url = dict.url; const context = IterableActionContext.fromDict(dict.context); Iterable.wakeApp(); @@ -576,24 +578,30 @@ export class Iterable { } if (Iterable.savedConfig.customActionHandler) { - RNEventEmitter.addListener(EventName.handleCustomActionCalled, (dict) => { - const action = IterableAction.fromDict(dict.action); - const context = IterableActionContext.fromDict(dict.context); - Iterable.savedConfig.customActionHandler!(action, context); - }); + RNEventEmitter.addListener( + IterableEventName.handleCustomActionCalled, + (dict) => { + const action = IterableAction.fromDict(dict.action); + const context = IterableActionContext.fromDict(dict.context); + Iterable.savedConfig.customActionHandler!(action, context); + } + ); } if (Iterable.savedConfig.inAppHandler) { - RNEventEmitter.addListener(EventName.handleInAppCalled, (messageDict) => { - const message = IterableInAppMessage.fromDict(messageDict); - const result = Iterable.savedConfig.inAppHandler!(message); - RNIterableAPI.setInAppShowResponse(result); - }); + RNEventEmitter.addListener( + IterableEventName.handleInAppCalled, + (messageDict) => { + const message = IterableInAppMessage.fromDict(messageDict); + const result = Iterable.savedConfig.inAppHandler!(message); + RNIterableAPI.setInAppShowResponse(result); + } + ); } if (Iterable.savedConfig.authHandler) { let authResponseCallback: IterableAuthResponseResult; - RNEventEmitter.addListener(EventName.handleAuthCalled, () => { + RNEventEmitter.addListener(IterableEventName.handleAuthCalled, () => { Iterable.savedConfig.authHandler!() .then((promiseResult) => { // Promise result can be either just String OR of type AuthResponse. @@ -633,12 +641,18 @@ export class Iterable { .catch((e) => Iterable.logger.log(e)); }); - RNEventEmitter.addListener(EventName.handleAuthSuccessCalled, () => { - authResponseCallback = IterableAuthResponseResult.SUCCESS; - }); - RNEventEmitter.addListener(EventName.handleAuthFailureCalled, () => { - authResponseCallback = IterableAuthResponseResult.FAILURE; - }); + RNEventEmitter.addListener( + IterableEventName.handleAuthSuccessCalled, + () => { + authResponseCallback = IterableAuthResponseResult.SUCCESS; + } + ); + RNEventEmitter.addListener( + IterableEventName.handleAuthFailureCalled, + () => { + authResponseCallback = IterableAuthResponseResult.FAILURE; + } + ); } function callUrlHandler(url: any, context: IterableActionContext) { diff --git a/src/__tests__/Iterable.test.ts b/src/__tests__/Iterable.test.ts index 7cff557cb..191fd279b 100644 --- a/src/__tests__/Iterable.test.ts +++ b/src/__tests__/Iterable.test.ts @@ -15,7 +15,7 @@ import { IterableConfig, IterableLogLevel, } from '../index'; -import { EventName } from '../Iterable'; +import { IterableEventName } from '../Iterable'; import { IterableDataRegion } from '../IterableDataRegion'; import { IterableLogger } from '../IterableLogger'; @@ -251,7 +251,7 @@ describe('Iterable', () => { ); // sets up event emitter const nativeEmitter = new NativeEventEmitter(); - nativeEmitter.removeAllListeners(EventName.handleUrlCalled); + nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled); // sets up config file and urlHandler function // urlHandler set to return false const config = new IterableConfig(); @@ -274,7 +274,7 @@ describe('Iterable', () => { context: { action: actionDict, source: 'inApp' }, }; // WHEN handleUrlCalled event is emitted - nativeEmitter.emit(EventName.handleUrlCalled, dict); + nativeEmitter.emit(IterableEventName.handleUrlCalled, dict); // THEN urlHandler and MockLinking is called with expected url return await TestHelper.delayed(0, () => { expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context); @@ -287,7 +287,7 @@ describe('Iterable', () => { ); // sets up event emitter const nativeEmitter = new NativeEventEmitter(); - nativeEmitter.removeAllListeners(EventName.handleUrlCalled); + nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled); // sets up config file and urlHandler function // urlHandler set to return false const config = new IterableConfig(); @@ -310,7 +310,7 @@ describe('Iterable', () => { context: { action: actionDict, source: 'inApp' }, }; // WHEN handleUrlCalled event is emitted - nativeEmitter.emit(EventName.handleUrlCalled, dict); + nativeEmitter.emit(IterableEventName.handleUrlCalled, dict); // THEN urlHandler is called and MockLinking.openURL is not called return await TestHelper.delayed(0, () => { expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context); @@ -323,7 +323,7 @@ describe('Iterable', () => { ); // sets up event emitter const nativeEmitter = new NativeEventEmitter(); - nativeEmitter.removeAllListeners(EventName.handleUrlCalled); + nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled); // sets up config file and urlHandler function // urlHandler set to return true const config = new IterableConfig(); @@ -346,7 +346,7 @@ describe('Iterable', () => { context: { action: actionDict, source: 'inApp' }, }; // WHEN handleUrlCalled event is emitted - nativeEmitter.emit(EventName.handleUrlCalled, dict); + nativeEmitter.emit(IterableEventName.handleUrlCalled, dict); // THEN urlHandler is called and MockLinking.openURL is not called return await TestHelper.delayed(0, () => { expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context); @@ -359,7 +359,9 @@ describe('Iterable', () => { ); // sets up event emitter const nativeEmitter = new NativeEventEmitter(); - nativeEmitter.removeAllListeners(EventName.handleCustomActionCalled); + nativeEmitter.removeAllListeners( + IterableEventName.handleCustomActionCalled + ); // sets up config file and customActionHandler function // customActionHandler set to return true const config = new IterableConfig(); @@ -380,7 +382,7 @@ describe('Iterable', () => { context: { action: actionDict, source: IterableActionSource.inApp }, }; // WHEN handleCustomActionCalled event is emitted - nativeEmitter.emit(EventName.handleCustomActionCalled, dict); + nativeEmitter.emit(IterableEventName.handleCustomActionCalled, dict); // THEN customActionHandler is called with expected action and expected context const expectedAction = new IterableAction(actionName, actionData); const expectedContext = new IterableActionContext( diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index 05f78d89a..9855464a8 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -2,7 +2,7 @@ import { NativeEventEmitter } from 'react-native'; import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; -import { Iterable, EventName } from '../Iterable'; +import { Iterable, IterableEventName } from '../Iterable'; import IterableConfig from '../IterableConfig'; import { IterableInAppLocation, @@ -137,7 +137,7 @@ describe('Iterable In App', () => { test('inAppHandler_messageAndEventEmitted_methodCalledWithMessage', () => { // sets up event emitter const nativeEmitter = new NativeEventEmitter(); - nativeEmitter.removeAllListeners(EventName.handleInAppCalled); + nativeEmitter.removeAllListeners(IterableEventName.handleInAppCalled); // sets up config file and inAppHandler function const config = new IterableConfig(); @@ -170,7 +170,7 @@ describe('Iterable In App', () => { ); // WHEN handleInAppCalled event is emitted - nativeEmitter.emit(EventName.handleInAppCalled, messageDict); + nativeEmitter.emit(IterableEventName.handleInAppCalled, messageDict); // THEN inAppHandler and MockRNIterableAPI.setInAppShowResponse is called with message expect(config.inAppHandler).toBeCalledWith(expectedMessage); From 7cf303c702757c6e6f03b23657009fd5da6f7e24 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:45:25 -0800 Subject: [PATCH 09/22] Refactor enums: move IterableAuthResponseResult, IterableEventName, and IterableActionSource to separate files and update imports accordingly --- src/Iterable.ts | 21 ++----------------- src/IterableAction.ts | 9 +------- src/__tests__/Iterable.test.ts | 6 +++--- src/__tests__/IterableInApp.test.ts | 15 ++++++------- src/enums/IterableActionSource.ts | 10 +++++++++ src/enums/IterableAuthResponseResult.ts | 6 ++++++ src/enums/IterableEventName.ts | 11 ++++++++++ src/enums/index.ts | 3 +++ .../IterableInboxMessageDisplay.tsx | 7 ++----- src/index.tsx | 2 +- 10 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/enums/IterableActionSource.ts create mode 100644 src/enums/IterableAuthResponseResult.ts create mode 100644 src/enums/IterableEventName.ts create mode 100644 src/enums/index.ts diff --git a/src/Iterable.ts b/src/Iterable.ts index e4fb6c250..b9fae3fa8 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -1,7 +1,3 @@ -/** - * TODO: Split into seperate files - */ - import { Linking, NativeEventEmitter, @@ -20,25 +16,12 @@ import { } from './inApp'; import { IterableLogger } from './IterableLogger'; import type IterableCommerceItem from './IterableCommerceItem'; +import { IterableEventName, IterableAuthResponseResult } from './enums'; +import IterableAttributionInfo from './IterableAttributionInfo'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); -enum IterableAuthResponseResult { - SUCCESS, - FAILURE, -} - -export enum IterableEventName { - handleUrlCalled = 'handleUrlCalled', - handleCustomActionCalled = 'handleCustomActionCalled', - handleInAppCalled = 'handleInAppCalled', - handleAuthCalled = 'handleAuthCalled', - receivedIterableInboxChanged = 'receivedIterableInboxChanged', - handleAuthSuccessCalled = 'handleAuthSuccessCalled', - handleAuthFailureCalled = 'handleAuthFailureCalled', -} - export class Iterable { static inAppManager = new IterableInAppManager(); diff --git a/src/IterableAction.ts b/src/IterableAction.ts index 7115e8c8a..212398eeb 100644 --- a/src/IterableAction.ts +++ b/src/IterableAction.ts @@ -1,11 +1,4 @@ -/** - * Enum representing the source of IterableAction. - */ -export enum IterableActionSource { - push = 0, - appLink = 1, - inApp = 2, -} +import type { IterableActionSource } from './enums'; /** * Enum representing what level of logs will Android and iOS project be printing on their consoles respectively. diff --git a/src/__tests__/Iterable.test.ts b/src/__tests__/Iterable.test.ts index 191fd279b..01fdfb6e7 100644 --- a/src/__tests__/Iterable.test.ts +++ b/src/__tests__/Iterable.test.ts @@ -13,10 +13,10 @@ import { IterableAttributionInfo, IterableCommerceItem, IterableConfig, + IterableDataRegion, + IterableEventName, IterableLogLevel, -} from '../index'; -import { IterableEventName } from '../Iterable'; -import { IterableDataRegion } from '../IterableDataRegion'; +} from '..'; import { IterableLogger } from '../IterableLogger'; describe('Iterable', () => { diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index 9855464a8..aca27c968 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -2,18 +2,19 @@ import { NativeEventEmitter } from 'react-native'; import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; -import { Iterable, IterableEventName } from '../Iterable'; -import IterableConfig from '../IterableConfig'; import { + Iterable, + IterableConfig, + IterableEventName, + IterableInAppCloseSource, + IterableInAppDeleteSource, IterableInAppLocation, + IterableInAppMessage, + IterableInAppShowResponse, IterableInAppTrigger, IterableInAppTriggerType, IterableInboxMetadata, - IterableInAppCloseSource, - IterableInAppShowResponse, - IterableInAppDeleteSource, - IterableInAppMessage, -} from '../inApp'; +} from '..'; import { IterableLogger } from '../IterableLogger'; describe('Iterable In App', () => { diff --git a/src/enums/IterableActionSource.ts b/src/enums/IterableActionSource.ts new file mode 100644 index 000000000..3ed59dcd0 --- /dev/null +++ b/src/enums/IterableActionSource.ts @@ -0,0 +1,10 @@ +/** + * Enum representing the source of IterableAction. + */ +export enum IterableActionSource { + push = 0, + appLink = 1, + inApp = 2, +} + +export default IterableActionSource; diff --git a/src/enums/IterableAuthResponseResult.ts b/src/enums/IterableAuthResponseResult.ts new file mode 100644 index 000000000..c4238c505 --- /dev/null +++ b/src/enums/IterableAuthResponseResult.ts @@ -0,0 +1,6 @@ +export enum IterableAuthResponseResult { + SUCCESS, + FAILURE, +} + +export default IterableAuthResponseResult; diff --git a/src/enums/IterableEventName.ts b/src/enums/IterableEventName.ts new file mode 100644 index 000000000..da8bb4e71 --- /dev/null +++ b/src/enums/IterableEventName.ts @@ -0,0 +1,11 @@ +export enum IterableEventName { + handleUrlCalled = 'handleUrlCalled', + handleCustomActionCalled = 'handleCustomActionCalled', + handleInAppCalled = 'handleInAppCalled', + handleAuthCalled = 'handleAuthCalled', + receivedIterableInboxChanged = 'receivedIterableInboxChanged', + handleAuthSuccessCalled = 'handleAuthSuccessCalled', + handleAuthFailureCalled = 'handleAuthFailureCalled', +} + +export default IterableEventName; diff --git a/src/enums/index.ts b/src/enums/index.ts new file mode 100644 index 000000000..e11e9d6c4 --- /dev/null +++ b/src/enums/index.ts @@ -0,0 +1,3 @@ +export * from './IterableActionSource'; +export * from './IterableAuthResponseResult'; +export * from './IterableEventName'; diff --git a/src/inbox/components/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx index 3c4a51576..84b49d224 100644 --- a/src/inbox/components/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -10,17 +10,14 @@ import { import Icon from 'react-native-vector-icons/Ionicons'; import { WebView } from 'react-native-webview'; +import { IterableActionSource } from '../../enums'; import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, } from '../../inApp'; import { Iterable } from '../../Iterable'; -import { - IterableAction, - IterableActionContext, - IterableActionSource, -} from '../../IterableAction'; +import { IterableAction, IterableActionContext } from '../../IterableAction'; import { IterableEdgeInsets } from '../../IterableEdgeInsets'; import { type InboxRowViewModel } from '../types'; diff --git a/src/index.tsx b/src/index.tsx index 654746260..3924ce5d1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,6 +2,7 @@ * React Native module for Iterable. * @module react-native-iterable-sdk */ +export { IterableActionSource, IterableEventName } from './enums'; export { useAppStateListener, useDeviceOrientation } from './hooks'; export { IterableHtmlInAppContent, @@ -30,7 +31,6 @@ export { Iterable } from './Iterable'; export { IterableAction, IterableActionContext, - IterableActionSource, IterableLogLevel, } from './IterableAction'; export { IterableAttributionInfo } from './IterableAttributionInfo'; From 95c4988b01baddc65a3842c38991abf64ca1bb9d Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 21:52:33 -0800 Subject: [PATCH 10/22] Refactor Iterable module: move IterableActionContext to a new file, update imports, and introduce IterableLogLevel enum --- src/Iterable.ts | 3 ++- src/IterableAction.ts | 27 --------------------------- src/IterableActionContext.ts | 23 +++++++++++++++++++++++ src/IterableConfig.ts | 10 ++++------ src/enums/IterableLogLevel.ts | 10 ++++++++++ src/enums/index.ts | 1 + src/index.tsx | 13 +++++++------ 7 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 src/IterableActionContext.ts create mode 100644 src/enums/IterableLogLevel.ts diff --git a/src/Iterable.ts b/src/Iterable.ts index b9fae3fa8..789927ece 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -5,7 +5,7 @@ import { Platform, } from 'react-native'; -import { IterableAction, IterableActionContext } from './IterableAction'; +import { IterableAction } from './IterableAction'; import IterableConfig, { AuthResponse } from './IterableConfig'; import { IterableInAppManager, @@ -18,6 +18,7 @@ import { IterableLogger } from './IterableLogger'; import type IterableCommerceItem from './IterableCommerceItem'; import { IterableEventName, IterableAuthResponseResult } from './enums'; import IterableAttributionInfo from './IterableAttributionInfo'; +import IterableActionContext from './IterableActionContext'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); diff --git a/src/IterableAction.ts b/src/IterableAction.ts index 212398eeb..307a7b65e 100644 --- a/src/IterableAction.ts +++ b/src/IterableAction.ts @@ -1,14 +1,3 @@ -import type { IterableActionSource } from './enums'; - -/** - * Enum representing what level of logs will Android and iOS project be printing on their consoles respectively. - */ -export enum IterableLogLevel { - debug = 1, - info = 2, - error = 3, -} - /** * IterableAction represents an action defined as a response to user events. * It is currently used in push notification actions (open push & action buttons). @@ -29,20 +18,4 @@ export class IterableAction { } } -export class IterableActionContext { - action: IterableAction; - source: IterableActionSource; - - constructor(action: IterableAction, source: IterableActionSource) { - this.action = action; - this.source = source; - } - - static fromDict(dict: any): IterableActionContext { - const action = IterableAction.fromDict(dict.action); - const source = dict.source as IterableActionSource; - return new IterableActionContext(action, source); - } -} - export default IterableAction; diff --git a/src/IterableActionContext.ts b/src/IterableActionContext.ts new file mode 100644 index 000000000..a2d5b5ff9 --- /dev/null +++ b/src/IterableActionContext.ts @@ -0,0 +1,23 @@ +import type { IterableActionSource } from './enums'; +import IterableAction from './IterableAction'; + +/** + * TODO: Add description + */ +export class IterableActionContext { + action: IterableAction; + source: IterableActionSource; + + constructor(action: IterableAction, source: IterableActionSource) { + this.action = action; + this.source = source; + } + + static fromDict(dict: any): IterableActionContext { + const action = IterableAction.fromDict(dict.action); + const source = dict.source as IterableActionSource; + return new IterableActionContext(action, source); + } +} + +export default IterableActionContext; diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index d621e9c55..4ba5fd04d 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -1,11 +1,9 @@ -import { - IterableAction, - IterableActionContext, - IterableLogLevel, -} from './IterableAction'; +import { IterableAction } from './IterableAction'; +import type { IterableActionContext } from './IterableActionContext'; import { IterableDataRegion } from './IterableDataRegion'; -import { IterableInAppShowResponse, IterableInAppMessage } from './inApp'; import { IterablePushPlatform } from './IterablePushPlatform'; +import { IterableLogLevel } from './enums'; +import { IterableInAppMessage, IterableInAppShowResponse } from './inApp'; // TODO: Add description type AuthCallBack = () => void; diff --git a/src/enums/IterableLogLevel.ts b/src/enums/IterableLogLevel.ts new file mode 100644 index 000000000..772332f97 --- /dev/null +++ b/src/enums/IterableLogLevel.ts @@ -0,0 +1,10 @@ +/** + * Enum representing what level of logs will Android and iOS project be printing on their consoles respectively. + */ +export enum IterableLogLevel { + debug = 1, + info = 2, + error = 3, +} + +export default IterableLogLevel; diff --git a/src/enums/index.ts b/src/enums/index.ts index e11e9d6c4..45450d592 100644 --- a/src/enums/index.ts +++ b/src/enums/index.ts @@ -1,3 +1,4 @@ export * from './IterableActionSource'; export * from './IterableAuthResponseResult'; export * from './IterableEventName'; +export * from './IterableLogLevel'; diff --git a/src/index.tsx b/src/index.tsx index 3924ce5d1..8b8363872 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,7 +2,11 @@ * React Native module for Iterable. * @module react-native-iterable-sdk */ -export { IterableActionSource, IterableEventName } from './enums'; +export { + IterableActionSource, + IterableEventName, + IterableLogLevel, +} from './enums'; export { useAppStateListener, useDeviceOrientation } from './hooks'; export { IterableHtmlInAppContent, @@ -28,11 +32,8 @@ export { type IterableInboxProps, } from './inbox'; export { Iterable } from './Iterable'; -export { - IterableAction, - IterableActionContext, - IterableLogLevel, -} from './IterableAction'; +export { IterableAction } from './IterableAction'; +export { IterableActionContext } from './IterableActionContext'; export { IterableAttributionInfo } from './IterableAttributionInfo'; export { IterableCommerceItem } from './IterableCommerceItem'; export { IterableConfig } from './IterableConfig'; From 3a52215dc6ce437db7298c7e8a7cc0e96e764956 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:00:00 -0800 Subject: [PATCH 11/22] Refactor Iterable module: update imports for IterableAuthResponse and IterableConfig, and create IterableAuthResponse class --- src/Iterable.ts | 29 +++++++++++++++-------------- src/IterableAuthResponse.ts | 10 ++++++++++ src/IterableConfig.ts | 13 ++----------- 3 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/IterableAuthResponse.ts diff --git a/src/Iterable.ts b/src/Iterable.ts index 789927ece..95cdec940 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -5,20 +5,21 @@ import { Platform, } from 'react-native'; -import { IterableAction } from './IterableAction'; -import IterableConfig, { AuthResponse } from './IterableConfig'; +import { IterableAuthResponseResult, IterableEventName } from './enums'; import { - IterableInAppManager, - IterableInAppMessage, IterableInAppCloseSource, IterableInAppDeleteSource, IterableInAppLocation, + IterableInAppManager, + IterableInAppMessage, } from './inApp'; -import { IterableLogger } from './IterableLogger'; -import type IterableCommerceItem from './IterableCommerceItem'; -import { IterableEventName, IterableAuthResponseResult } from './enums'; -import IterableAttributionInfo from './IterableAttributionInfo'; +import { IterableAction } from './IterableAction'; import IterableActionContext from './IterableActionContext'; +import IterableAttributionInfo from './IterableAttributionInfo'; +import { IterableAuthResponse } from './IterableAuthResponse'; +import type IterableCommerceItem from './IterableCommerceItem'; +import { IterableConfig } from './IterableConfig'; +import { IterableLogger } from './IterableLogger'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); @@ -591,23 +592,23 @@ export class Iterable { // Promise result can be either just String OR of type AuthResponse. // If type AuthReponse, authToken will be parsed looking for `authToken` within promised object. Two additional listeners will be registered for success and failure callbacks sent by native bridge layer. // Else it will be looked for as a String. - if (typeof promiseResult === typeof new AuthResponse()) { + if (typeof promiseResult === typeof new IterableAuthResponse()) { RNIterableAPI.passAlongAuthToken( - (promiseResult as AuthResponse).authToken + (promiseResult as IterableAuthResponse).authToken ); setTimeout(() => { if ( authResponseCallback === IterableAuthResponseResult.SUCCESS ) { - if ((promiseResult as AuthResponse).successCallback) { - (promiseResult as AuthResponse).successCallback!(); + if ((promiseResult as IterableAuthResponse).successCallback) { + (promiseResult as IterableAuthResponse).successCallback!(); } } else if ( authResponseCallback === IterableAuthResponseResult.FAILURE ) { - if ((promiseResult as AuthResponse).failureCallback) { - (promiseResult as AuthResponse).failureCallback!(); + if ((promiseResult as IterableAuthResponse).failureCallback) { + (promiseResult as IterableAuthResponse).failureCallback!(); } } else { Iterable.logger.log('No callback received from native layer'); diff --git a/src/IterableAuthResponse.ts b/src/IterableAuthResponse.ts new file mode 100644 index 000000000..8f49b2be8 --- /dev/null +++ b/src/IterableAuthResponse.ts @@ -0,0 +1,10 @@ +// TODO: Add comments and descriptions +// REVIEW: This seems to currently be used as a type instead of a class, so it +// might be better to make it a type +export class IterableAuthResponse { + authToken?: string = ''; + successCallback?: () => void; + failureCallback?: () => void; +} + +export default IterableAuthResponse; diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index 4ba5fd04d..096b94129 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -1,13 +1,11 @@ import { IterableAction } from './IterableAction'; import type { IterableActionContext } from './IterableActionContext'; +import type { IterableAuthResponse } from './IterableAuthResponse'; import { IterableDataRegion } from './IterableDataRegion'; import { IterablePushPlatform } from './IterablePushPlatform'; import { IterableLogLevel } from './enums'; import { IterableInAppMessage, IterableInAppShowResponse } from './inApp'; -// TODO: Add description -type AuthCallBack = () => void; - /** * An IterableConfig object sets various properties of the SDK. * An IterableConfig object is passed into the static initialize method on the Iterable class when initializing the SDK. @@ -69,7 +67,7 @@ export class IterableConfig { * React Native SDK. Provide an implementation for this method only if your app uses a * JWT-enabled API key. */ - authHandler?: () => Promise; + authHandler?: () => Promise; /** * Set the verbosity of Android and iOS project's log system. @@ -162,11 +160,4 @@ export class IterableConfig { } } -// TODO: Add comments and descriptions -export class AuthResponse { - authToken?: string = ''; - successCallback?: AuthCallBack; - failureCallback?: AuthCallBack; -} - export default IterableConfig; From 9ac9906735165d5e017c77ac1da5e4f98d08d183 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:03:21 -0800 Subject: [PATCH 12/22] Refactor Iterable module: update imports for IterableActionContext, IterableAttributionInfo, and IterableCommerceItem; consolidate imports from enums --- src/Iterable.ts | 6 +++--- src/IterableConfig.ts | 3 +-- src/{ => enums}/IterableDataRegion.ts | 0 src/enums/index.ts | 1 + src/index.tsx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename src/{ => enums}/IterableDataRegion.ts (100%) diff --git a/src/Iterable.ts b/src/Iterable.ts index 95cdec940..3c85ce496 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -14,10 +14,10 @@ import { IterableInAppMessage, } from './inApp'; import { IterableAction } from './IterableAction'; -import IterableActionContext from './IterableActionContext'; -import IterableAttributionInfo from './IterableAttributionInfo'; +import { IterableActionContext } from './IterableActionContext'; +import { IterableAttributionInfo } from './IterableAttributionInfo'; import { IterableAuthResponse } from './IterableAuthResponse'; -import type IterableCommerceItem from './IterableCommerceItem'; +import type { IterableCommerceItem } from './IterableCommerceItem'; import { IterableConfig } from './IterableConfig'; import { IterableLogger } from './IterableLogger'; diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index 096b94129..48da0dad7 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -1,9 +1,8 @@ import { IterableAction } from './IterableAction'; import type { IterableActionContext } from './IterableActionContext'; import type { IterableAuthResponse } from './IterableAuthResponse'; -import { IterableDataRegion } from './IterableDataRegion'; import { IterablePushPlatform } from './IterablePushPlatform'; -import { IterableLogLevel } from './enums'; +import { IterableDataRegion, IterableLogLevel } from './enums'; import { IterableInAppMessage, IterableInAppShowResponse } from './inApp'; /** diff --git a/src/IterableDataRegion.ts b/src/enums/IterableDataRegion.ts similarity index 100% rename from src/IterableDataRegion.ts rename to src/enums/IterableDataRegion.ts diff --git a/src/enums/index.ts b/src/enums/index.ts index 45450d592..09e137d6b 100644 --- a/src/enums/index.ts +++ b/src/enums/index.ts @@ -1,4 +1,5 @@ export * from './IterableActionSource'; export * from './IterableAuthResponseResult'; +export * from './IterableDataRegion'; export * from './IterableEventName'; export * from './IterableLogLevel'; diff --git a/src/index.tsx b/src/index.tsx index 8b8363872..537ee1077 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,6 +4,7 @@ */ export { IterableActionSource, + IterableDataRegion, IterableEventName, IterableLogLevel, } from './enums'; @@ -37,5 +38,4 @@ export { IterableActionContext } from './IterableActionContext'; export { IterableAttributionInfo } from './IterableAttributionInfo'; export { IterableCommerceItem } from './IterableCommerceItem'; export { IterableConfig } from './IterableConfig'; -export { IterableDataRegion } from './IterableDataRegion'; export { IterableEdgeInsets } from './IterableEdgeInsets'; From 20b10a315dc4b6ccb0b877d9317c4e69b8392805 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:06:08 -0800 Subject: [PATCH 13/22] Refactor Iterable module: move IterablePushPlatform enum to a separate file and update imports --- src/IterableConfig.ts | 7 +++++-- src/IterablePushPlatform.ts | 7 ------- src/enums/IterablePushPlatform.ts | 8 ++++++++ src/enums/index.ts | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) delete mode 100644 src/IterablePushPlatform.ts create mode 100644 src/enums/IterablePushPlatform.ts diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index 48da0dad7..d27f8e191 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -1,8 +1,11 @@ import { IterableAction } from './IterableAction'; import type { IterableActionContext } from './IterableActionContext'; import type { IterableAuthResponse } from './IterableAuthResponse'; -import { IterablePushPlatform } from './IterablePushPlatform'; -import { IterableDataRegion, IterableLogLevel } from './enums'; +import { + IterableDataRegion, + IterableLogLevel, + IterablePushPlatform, +} from './enums'; import { IterableInAppMessage, IterableInAppShowResponse } from './inApp'; /** diff --git a/src/IterablePushPlatform.ts b/src/IterablePushPlatform.ts deleted file mode 100644 index 33fe63fef..000000000 --- a/src/IterablePushPlatform.ts +++ /dev/null @@ -1,7 +0,0 @@ -enum IterablePushPlatform { - sandbox = 0, - production = 1, - auto = 2, -} - -export { IterablePushPlatform }; diff --git a/src/enums/IterablePushPlatform.ts b/src/enums/IterablePushPlatform.ts new file mode 100644 index 000000000..b0f25b27a --- /dev/null +++ b/src/enums/IterablePushPlatform.ts @@ -0,0 +1,8 @@ +// TODO: add decription +export enum IterablePushPlatform { + sandbox = 0, + production = 1, + auto = 2, +} + +export default IterablePushPlatform; diff --git a/src/enums/index.ts b/src/enums/index.ts index 09e137d6b..e95b5350c 100644 --- a/src/enums/index.ts +++ b/src/enums/index.ts @@ -3,3 +3,4 @@ export * from './IterableAuthResponseResult'; export * from './IterableDataRegion'; export * from './IterableEventName'; export * from './IterableLogLevel'; +export * from './IterablePushPlatform'; From f7066e7a418251177aaef9bbf80cfd061e269c3e Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:08:55 -0800 Subject: [PATCH 14/22] Refactor imports in IterableLogger, IterableUtil, and IterableInAppMessage: update to named imports for consistency --- src/IterableLogger.ts | 2 +- src/IterableUtil.ts | 1 + src/inApp/IterableInAppMessage.ts | 2 +- src/screens/index.ts | 0 src/utils/index.ts | 0 5 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 src/screens/index.ts delete mode 100644 src/utils/index.ts diff --git a/src/IterableLogger.ts b/src/IterableLogger.ts index 9346166e3..c69ce206d 100644 --- a/src/IterableLogger.ts +++ b/src/IterableLogger.ts @@ -1,4 +1,4 @@ -import IterableConfig from './IterableConfig'; +import { IterableConfig } from './IterableConfig'; // TODO: Add comments and descriptions export class IterableLogger { diff --git a/src/IterableUtil.ts b/src/IterableUtil.ts index e2dc049bc..54d962302 100644 --- a/src/IterableUtil.ts +++ b/src/IterableUtil.ts @@ -1,4 +1,5 @@ // TODO: Add a description +// TODO: Change to a util function instead of a class export class IterableUtil { static readBoolean(dict: any, key: string): boolean { if (dict[key]) { diff --git a/src/inApp/IterableInAppMessage.ts b/src/inApp/IterableInAppMessage.ts index 218ab9872..cfa0684dc 100644 --- a/src/inApp/IterableInAppMessage.ts +++ b/src/inApp/IterableInAppMessage.ts @@ -1,6 +1,6 @@ import { type ViewToken } from 'react-native'; -import IterableUtil from '../IterableUtil'; +import { IterableUtil } from '../IterableUtil'; import { IterableInboxMetadata } from './IterableInboxMetadata'; import { IterableInAppTriggerType } from './enums'; diff --git a/src/screens/index.ts b/src/screens/index.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index e69de29bb..000000000 From 5a1eea0ac171b3a1a8fa35b45925f794a96be0ac Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:21:03 -0800 Subject: [PATCH 15/22] Refactor Iterable module: update imports for consistency and rename types for clarity --- src/IterableActionContext.ts | 2 +- src/enums/IterableAuthResponseResult.ts | 1 + src/enums/IterableEventName.ts | 1 + src/inApp/IterableHtmlInAppContent.ts | 2 +- src/inApp/IterableInAppManager.ts | 2 +- src/inbox/IterableInboxDataModel.ts | 17 +++++++------ src/inbox/components/IterableInbox.tsx | 24 ++++++++++--------- .../components/IterableInboxMessageCell.tsx | 14 ++++++----- .../IterableInboxMessageDisplay.tsx | 4 ++-- .../components/IterableInboxMessageList.tsx | 23 +++++++++--------- ...o.ts => IterableInboxImpressionRowInfo.ts} | 2 +- ...wModel.ts => IterableInboxRowViewModel.ts} | 4 ++-- src/inbox/types/index.ts | 4 ++-- src/index.tsx | 4 ++-- 14 files changed, 57 insertions(+), 47 deletions(-) rename src/inbox/types/{InboxImpressionRowInfo.ts => IterableInboxImpressionRowInfo.ts} (60%) rename src/inbox/types/{InboxRowViewModel.ts => IterableInboxRowViewModel.ts} (63%) diff --git a/src/IterableActionContext.ts b/src/IterableActionContext.ts index a2d5b5ff9..dad40a6e4 100644 --- a/src/IterableActionContext.ts +++ b/src/IterableActionContext.ts @@ -1,5 +1,5 @@ import type { IterableActionSource } from './enums'; -import IterableAction from './IterableAction'; +import { IterableAction } from './IterableAction'; /** * TODO: Add description diff --git a/src/enums/IterableAuthResponseResult.ts b/src/enums/IterableAuthResponseResult.ts index c4238c505..565c6466f 100644 --- a/src/enums/IterableAuthResponseResult.ts +++ b/src/enums/IterableAuthResponseResult.ts @@ -1,3 +1,4 @@ +// TODO: Add description export enum IterableAuthResponseResult { SUCCESS, FAILURE, diff --git a/src/enums/IterableEventName.ts b/src/enums/IterableEventName.ts index da8bb4e71..f4aa04907 100644 --- a/src/enums/IterableEventName.ts +++ b/src/enums/IterableEventName.ts @@ -1,3 +1,4 @@ +// TODO: Add description export enum IterableEventName { handleUrlCalled = 'handleUrlCalled', handleCustomActionCalled = 'handleCustomActionCalled', diff --git a/src/inApp/IterableHtmlInAppContent.ts b/src/inApp/IterableHtmlInAppContent.ts index 8b4ca72b5..681930b3d 100644 --- a/src/inApp/IterableHtmlInAppContent.ts +++ b/src/inApp/IterableHtmlInAppContent.ts @@ -1,4 +1,4 @@ -import IterableEdgeInsets from '../IterableEdgeInsets'; +import { IterableEdgeInsets } from '../IterableEdgeInsets'; import type { IterableInAppContent } from './types'; import { IterableInAppContentType } from './enums'; diff --git a/src/inApp/IterableInAppManager.ts b/src/inApp/IterableInAppManager.ts index d95065035..22bb6a8a4 100644 --- a/src/inApp/IterableInAppManager.ts +++ b/src/inApp/IterableInAppManager.ts @@ -3,7 +3,7 @@ import { NativeModules } from 'react-native'; import { Iterable } from '../Iterable'; import { IterableHtmlInAppContent } from './IterableHtmlInAppContent'; -import IterableInAppMessage from './IterableInAppMessage'; +import { IterableInAppMessage } from './IterableInAppMessage'; import type { IterableInAppLocation, IterableInAppDeleteSource } from './enums'; // TODO: Create a loader for this diff --git a/src/inbox/IterableInboxDataModel.ts b/src/inbox/IterableInboxDataModel.ts index 547cbdb5d..71718f6c9 100644 --- a/src/inbox/IterableInboxDataModel.ts +++ b/src/inbox/IterableInboxDataModel.ts @@ -6,7 +6,10 @@ import { IterableInAppLocation, IterableInAppMessage, } from '../inApp'; -import type { InboxImpressionRowInfo, InboxRowViewModel } from './types'; +import type { + IterableInboxImpressionRowInfo, + IterableInboxRowViewModel, +} from './types'; import { Iterable } from '../Iterable'; const RNIterableAPI = NativeModules.RNIterableAPI; @@ -71,7 +74,7 @@ export class IterableInboxDataModel { RNIterableAPI.removeMessage(id, IterableInAppLocation.inbox, deleteSource); } - async refresh(): Promise> { + async refresh(): Promise> { return RNIterableAPI.getInboxMessages().then( (messages: Array) => { return this.processMessages(messages); @@ -84,16 +87,16 @@ export class IterableInboxDataModel { // inbox session tracking functions - startSession(visibleRows: Array = []) { + startSession(visibleRows: Array = []) { RNIterableAPI.startSession(visibleRows); } - async endSession(visibleRows: Array = []) { + async endSession(visibleRows: Array = []) { await this.updateVisibleRows(visibleRows); RNIterableAPI.endSession(); } - updateVisibleRows(visibleRows: Array = []) { + updateVisibleRows(visibleRows: Array = []) { RNIterableAPI.updateVisibleRows(visibleRows); } @@ -132,7 +135,7 @@ export class IterableInboxDataModel { private processMessages( messages: Array - ): Array { + ): Array { return this.sortAndFilter(messages).map( IterableInboxDataModel.getInboxRowViewModelForMessage ); @@ -162,7 +165,7 @@ export class IterableInboxDataModel { private static getInboxRowViewModelForMessage( message: IterableInAppMessage - ): InboxRowViewModel { + ): IterableInboxRowViewModel { return { title: message.inboxMetadata?.title ?? '', subtitle: message.inboxMetadata?.subtitle, diff --git a/src/inbox/components/IterableInbox.tsx b/src/inbox/components/IterableInbox.tsx index 859342267..94af5a837 100644 --- a/src/inbox/components/IterableInbox.tsx +++ b/src/inbox/components/IterableInbox.tsx @@ -17,13 +17,13 @@ import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp'; import IterableInboxDataModel from '../IterableInboxDataModel'; import type { - InboxImpressionRowInfo, - InboxRowViewModel, + IterableInboxImpressionRowInfo, + IterableInboxRowViewModel, IterableInboxCustomizations, } from '../types'; -import IterableInboxEmptyState from './IterableInboxEmptyState'; -import IterableInboxMessageDisplay from './IterableInboxMessageDisplay'; -import IterableInboxMessageList from './IterableInboxMessageList'; +import { IterableInboxEmptyState } from './IterableInboxEmptyState'; +import { IterableInboxMessageDisplay } from './IterableInboxMessageDisplay'; +import { IterableInboxMessageList } from './IterableInboxMessageList'; const RNIterableAPI = NativeModules.RNIterableAPI; const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); @@ -58,13 +58,15 @@ export const IterableInbox = ({ const [selectedRowViewModelIdx, setSelectedRowViewModelIdx] = useState(0); - const [rowViewModels, setRowViewModels] = useState([]); + const [rowViewModels, setRowViewModels] = useState< + IterableInboxRowViewModel[] + >([]); const [loading, setLoading] = useState(true); const [animatedValue] = useState(new Animated.Value(0)); const [isMessageDisplay, setIsMessageDisplay] = useState(false); const [visibleMessageImpressions, setVisibleMessageImpressions] = useState< - InboxImpressionRowInfo[] + IterableInboxImpressionRowInfo[] >([]); const styles = StyleSheet.create({ @@ -201,7 +203,7 @@ export const IterableInbox = ({ function handleMessageSelect( id: string, index: number, - models: InboxRowViewModel[] + models: IterableInboxRowViewModel[] ) { let newRowViewModels = models.map((rowViewModel) => { return rowViewModel.inAppMessage.messageId === id @@ -240,13 +242,13 @@ export const IterableInbox = ({ } function updateVisibleMessageImpressions( - messageImpressions: InboxImpressionRowInfo[] + messageImpressions: IterableInboxImpressionRowInfo[] ) { setVisibleMessageImpressions(messageImpressions); } function showMessageDisplay( - rowViewModelList: InboxRowViewModel[], + rowViewModelList: IterableInboxRowViewModel[], index: number ) { const selectedRowViewModel = rowViewModelList[index]; @@ -286,7 +288,7 @@ export const IterableInbox = ({ handleMessageSelect(messageId, index, rowViewModels) } updateVisibleMessageImpressions={( - messageImpressions: InboxImpressionRowInfo[] + messageImpressions: IterableInboxImpressionRowInfo[] ) => updateVisibleMessageImpressions(messageImpressions)} contentWidth={width} isPortrait={isPortrait} diff --git a/src/inbox/components/IterableInboxMessageCell.tsx b/src/inbox/components/IterableInboxMessageCell.tsx index 2f381835b..a1ea6a372 100644 --- a/src/inbox/components/IterableInboxMessageCell.tsx +++ b/src/inbox/components/IterableInboxMessageCell.tsx @@ -11,15 +11,17 @@ import { type ViewStyle, } from 'react-native'; -import type { InboxRowViewModel, IterableInboxCustomizations } from '../types'; - -import IterableInboxDataModel from '../IterableInboxDataModel'; +import { IterableInboxDataModel } from '../IterableInboxDataModel'; +import type { + IterableInboxRowViewModel, + IterableInboxCustomizations, +} from '../types'; // TODO: Change to component function defaultMessageListLayout( last: boolean, dataModel: IterableInboxDataModel, - rowViewModel: InboxRowViewModel, + rowViewModel: IterableInboxRowViewModel, customizations: IterableInboxCustomizations, isPortrait: boolean ) { @@ -121,7 +123,7 @@ function defaultMessageListLayout( ? { ...messageContainer, width: '90%' } : messageContainer; - function messageRowStyle(_rowViewModel: InboxRowViewModel) { + function messageRowStyle(_rowViewModel: IterableInboxRowViewModel) { return last ? { ...messageRow, borderBottomWidth: 1 } : messageRow; } @@ -164,7 +166,7 @@ export interface IterableInboxMessageCellProps { index: number; last: boolean; dataModel: IterableInboxDataModel; - rowViewModel: InboxRowViewModel; + rowViewModel: IterableInboxRowViewModel; customizations: IterableInboxCustomizations; swipingCheck: Function; messageListItemLayout: Function; diff --git a/src/inbox/components/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx index 84b49d224..726d96172 100644 --- a/src/inbox/components/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -19,11 +19,11 @@ import { import { Iterable } from '../../Iterable'; import { IterableAction, IterableActionContext } from '../../IterableAction'; import { IterableEdgeInsets } from '../../IterableEdgeInsets'; -import { type InboxRowViewModel } from '../types'; +import { type IterableInboxRowViewModel } from '../types'; // TODO: Comment export interface IterableInboxMessageDisplayProps { - rowViewModel: InboxRowViewModel; + rowViewModel: IterableInboxRowViewModel; inAppContentPromise: Promise; returnToInbox: Function; deleteRow: Function; diff --git a/src/inbox/components/IterableInboxMessageList.tsx b/src/inbox/components/IterableInboxMessageList.tsx index e45161338..99a58b32f 100644 --- a/src/inbox/components/IterableInboxMessageList.tsx +++ b/src/inbox/components/IterableInboxMessageList.tsx @@ -2,19 +2,18 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; import { IterableInAppMessage } from '../../inApp'; - -import IterableInboxDataModel from '../IterableInboxDataModel'; +import { IterableInboxDataModel } from '../IterableInboxDataModel'; import type { - InboxImpressionRowInfo, - InboxRowViewModel, + IterableInboxImpressionRowInfo, + IterableInboxRowViewModel, IterableInboxCustomizations, } from '../types'; -import IterableInboxMessageCell from './IterableInboxMessageCell'; +import { IterableInboxMessageCell } from './IterableInboxMessageCell'; // TODO: Comment export interface IterableInboxMessageListProps { dataModel: IterableInboxDataModel; - rowViewModels: InboxRowViewModel[]; + rowViewModels: IterableInboxRowViewModel[]; customizations: IterableInboxCustomizations; messageListItemLayout: Function; deleteRow: Function; @@ -40,7 +39,7 @@ export const IterableInboxMessageList = ({ const flatListRef = useRef(null); function renderRowViewModel( - rowViewModel: InboxRowViewModel, + rowViewModel: IterableInboxRowViewModel, index: number, last: boolean ) { @@ -64,14 +63,14 @@ export const IterableInboxMessageList = ({ function getRowInfosFromViewTokens( viewTokens: Array - ): Array { + ): Array { return viewTokens.map(function (viewToken) { const inAppMessage = IterableInAppMessage.fromViewToken(viewToken); const impression = { messageId: inAppMessage.messageId, silentInbox: inAppMessage.isSilentInbox(), - } as InboxImpressionRowInfo; + } as IterableInboxImpressionRowInfo; return impression; }); @@ -103,10 +102,12 @@ export const IterableInboxMessageList = ({ item, index, }: { - item: InboxRowViewModel; + item: IterableInboxRowViewModel; index: number; }) => renderRowViewModel(item, index, index === rowViewModels.length - 1)} - keyExtractor={(item: InboxRowViewModel) => item.inAppMessage.messageId} + keyExtractor={(item: IterableInboxRowViewModel) => + item.inAppMessage.messageId + } viewabilityConfig={inboxSessionViewabilityConfig} onViewableItemsChanged={inboxSessionItemsChanged} onLayout={() => { diff --git a/src/inbox/types/InboxImpressionRowInfo.ts b/src/inbox/types/IterableInboxImpressionRowInfo.ts similarity index 60% rename from src/inbox/types/InboxImpressionRowInfo.ts rename to src/inbox/types/IterableInboxImpressionRowInfo.ts index 5fa74fec6..0d95daece 100644 --- a/src/inbox/types/InboxImpressionRowInfo.ts +++ b/src/inbox/types/IterableInboxImpressionRowInfo.ts @@ -1,5 +1,5 @@ // TODO: Add description -export type InboxImpressionRowInfo = { +export type IterableInboxImpressionRowInfo = { messageId: string; silentInbox: boolean; }; diff --git a/src/inbox/types/InboxRowViewModel.ts b/src/inbox/types/IterableInboxRowViewModel.ts similarity index 63% rename from src/inbox/types/InboxRowViewModel.ts rename to src/inbox/types/IterableInboxRowViewModel.ts index 2d0aa9901..f5f6e3ca6 100644 --- a/src/inbox/types/InboxRowViewModel.ts +++ b/src/inbox/types/IterableInboxRowViewModel.ts @@ -1,7 +1,7 @@ -import { IterableInAppMessage } from '../..'; +import { IterableInAppMessage } from '../../inApp'; // TODO: Add description -export type InboxRowViewModel = { +export type IterableInboxRowViewModel = { title: string; subtitle?: string; imageUrl?: string; diff --git a/src/inbox/types/index.ts b/src/inbox/types/index.ts index 5bd60a01e..2cc9a9510 100644 --- a/src/inbox/types/index.ts +++ b/src/inbox/types/index.ts @@ -1,3 +1,3 @@ -export * from './InboxImpressionRowInfo'; -export * from './InboxRowViewModel'; +export * from './IterableInboxImpressionRowInfo'; export * from './IterableInboxCustomizations'; +export * from './IterableInboxRowViewModel'; diff --git a/src/index.tsx b/src/index.tsx index 537ee1077..e0a1530ca 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,8 +27,8 @@ export { IterableInbox, IterableInboxEmptyState, IterableInboxMessageCell, - type InboxImpressionRowInfo, - type InboxRowViewModel, + type IterableInboxImpressionRowInfo as InboxImpressionRowInfo, + type IterableInboxRowViewModel as InboxRowViewModel, type IterableInboxCustomizations, type IterableInboxProps, } from './inbox'; From 1db7ca44eb43233965a7cbd72827b2e1f4bd117a Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 22:44:00 -0800 Subject: [PATCH 16/22] Refactor imports in Iterable module: update paths to use absolute imports for inApp and inbox --- src/Iterable.ts | 2 +- src/IterableConfig.ts | 2 +- src/__mocks__/MockRNIterableAPI.ts | 2 +- src/inbox/IterableInboxDataModel.ts | 4 ++-- src/inbox/components/IterableInbox.tsx | 6 +++--- src/inbox/components/IterableInboxEmptyState.tsx | 2 +- src/inbox/components/IterableInboxMessageCell.tsx | 4 ++-- src/inbox/components/IterableInboxMessageDisplay.tsx | 7 ++++--- src/inbox/components/IterableInboxMessageList.tsx | 6 +++--- src/inbox/types/IterableInboxRowViewModel.ts | 2 +- tsconfig.json | 6 +++++- 11 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Iterable.ts b/src/Iterable.ts index 3c85ce496..fbf1fd258 100644 --- a/src/Iterable.ts +++ b/src/Iterable.ts @@ -12,7 +12,7 @@ import { IterableInAppLocation, IterableInAppManager, IterableInAppMessage, -} from './inApp'; +} from 'inApp'; import { IterableAction } from './IterableAction'; import { IterableActionContext } from './IterableActionContext'; import { IterableAttributionInfo } from './IterableAttributionInfo'; diff --git a/src/IterableConfig.ts b/src/IterableConfig.ts index d27f8e191..0c8b7b0bf 100644 --- a/src/IterableConfig.ts +++ b/src/IterableConfig.ts @@ -6,7 +6,7 @@ import { IterableLogLevel, IterablePushPlatform, } from './enums'; -import { IterableInAppMessage, IterableInAppShowResponse } from './inApp'; +import { IterableInAppMessage, IterableInAppShowResponse } from 'inApp'; /** * An IterableConfig object sets various properties of the SDK. diff --git a/src/__mocks__/MockRNIterableAPI.ts b/src/__mocks__/MockRNIterableAPI.ts index a6dc1e372..1de6afcc1 100644 --- a/src/__mocks__/MockRNIterableAPI.ts +++ b/src/__mocks__/MockRNIterableAPI.ts @@ -1,5 +1,5 @@ import { IterableAttributionInfo } from '../IterableAttributionInfo'; -import { IterableInAppMessage } from '../inApp'; +import { IterableInAppMessage } from 'inApp'; export class MockRNIterableAPI { static email?: string; diff --git a/src/inbox/IterableInboxDataModel.ts b/src/inbox/IterableInboxDataModel.ts index 71718f6c9..17d40dc52 100644 --- a/src/inbox/IterableInboxDataModel.ts +++ b/src/inbox/IterableInboxDataModel.ts @@ -5,11 +5,11 @@ import { IterableInAppDeleteSource, IterableInAppLocation, IterableInAppMessage, -} from '../inApp'; +} from 'inApp'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, -} from './types'; +} from 'inbox/types'; import { Iterable } from '../Iterable'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inbox/components/IterableInbox.tsx b/src/inbox/components/IterableInbox.tsx index 94af5a837..3588e115e 100644 --- a/src/inbox/components/IterableInbox.tsx +++ b/src/inbox/components/IterableInbox.tsx @@ -13,14 +13,14 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import { Iterable } from '../../Iterable'; import { useAppStateListener, useDeviceOrientation } from '../../hooks'; -import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp'; +import { IterableInAppDeleteSource, IterableInAppLocation } from 'inApp'; -import IterableInboxDataModel from '../IterableInboxDataModel'; +import IterableInboxDataModel from 'inbox/IterableInboxDataModel'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, IterableInboxCustomizations, -} from '../types'; +} from 'inbox/types'; import { IterableInboxEmptyState } from './IterableInboxEmptyState'; import { IterableInboxMessageDisplay } from './IterableInboxMessageDisplay'; import { IterableInboxMessageList } from './IterableInboxMessageList'; diff --git a/src/inbox/components/IterableInboxEmptyState.tsx b/src/inbox/components/IterableInboxEmptyState.tsx index a1a2074f1..7ff8d6b3a 100644 --- a/src/inbox/components/IterableInboxEmptyState.tsx +++ b/src/inbox/components/IterableInboxEmptyState.tsx @@ -1,6 +1,6 @@ import { StyleSheet, Text, View } from 'react-native'; -import { type IterableInboxCustomizations } from '../types'; +import { type IterableInboxCustomizations } from 'inbox/types'; // TODO: Comment export interface IterableInboxEmptyStateProps { diff --git a/src/inbox/components/IterableInboxMessageCell.tsx b/src/inbox/components/IterableInboxMessageCell.tsx index a1ea6a372..313d5a902 100644 --- a/src/inbox/components/IterableInboxMessageCell.tsx +++ b/src/inbox/components/IterableInboxMessageCell.tsx @@ -11,11 +11,11 @@ import { type ViewStyle, } from 'react-native'; -import { IterableInboxDataModel } from '../IterableInboxDataModel'; +import { IterableInboxDataModel } from 'inbox/IterableInboxDataModel'; import type { IterableInboxRowViewModel, IterableInboxCustomizations, -} from '../types'; +} from 'inbox/types'; // TODO: Change to component function defaultMessageListLayout( diff --git a/src/inbox/components/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx index 726d96172..0f9df19cf 100644 --- a/src/inbox/components/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -15,11 +15,12 @@ import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, -} from '../../inApp'; +} from 'inApp'; import { Iterable } from '../../Iterable'; -import { IterableAction, IterableActionContext } from '../../IterableAction'; +import { IterableAction } from '../../IterableAction'; import { IterableEdgeInsets } from '../../IterableEdgeInsets'; -import { type IterableInboxRowViewModel } from '../types'; +import { type IterableInboxRowViewModel } from 'inbox/types'; +import IterableActionContext from '../../IterableActionContext'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/inbox/components/IterableInboxMessageList.tsx b/src/inbox/components/IterableInboxMessageList.tsx index 99a58b32f..a1e740047 100644 --- a/src/inbox/components/IterableInboxMessageList.tsx +++ b/src/inbox/components/IterableInboxMessageList.tsx @@ -1,13 +1,13 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; -import { IterableInAppMessage } from '../../inApp'; -import { IterableInboxDataModel } from '../IterableInboxDataModel'; +import { IterableInAppMessage } from 'inApp'; +import { IterableInboxDataModel } from 'inbox/IterableInboxDataModel'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, IterableInboxCustomizations, -} from '../types'; +} from 'inbox/types'; import { IterableInboxMessageCell } from './IterableInboxMessageCell'; // TODO: Comment diff --git a/src/inbox/types/IterableInboxRowViewModel.ts b/src/inbox/types/IterableInboxRowViewModel.ts index f5f6e3ca6..2f1ca403e 100644 --- a/src/inbox/types/IterableInboxRowViewModel.ts +++ b/src/inbox/types/IterableInboxRowViewModel.ts @@ -1,4 +1,4 @@ -import { IterableInAppMessage } from '../../inApp'; +import { IterableInAppMessage } from 'inApp'; // TODO: Add description export type IterableInboxRowViewModel = { diff --git a/tsconfig.json b/tsconfig.json index 6d0983407..e51d5d5bd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,11 @@ "compilerOptions": { "rootDir": ".", "paths": { - "@iterable/react-native-sdk": ["./src/index"] + "@iterable/react-native-sdk": ["./src/index"], + "inbox/*": ["./src/inbox/*"], + "inbox": ["./src/inbox/index"], + "inApp/*": ["./src/inApp/*"], + "inApp": ["./src/inApp/index"], }, "allowUnreachableCode": false, "allowUnusedLabels": false, From 04dc426e4d7385f8a8f072e48a624639c229b67a Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Wed, 6 Nov 2024 23:12:30 -0800 Subject: [PATCH 17/22] Refactor imports and restructure files in Iterable module: consolidate exports, update paths for consistency, and enhance organization --- src/__mocks__/MockRNIterableAPI.ts | 2 +- src/__tests__/Iterable.test.ts | 2 +- src/__tests__/IterableInApp.test.ts | 2 +- src/{ => core/classes}/Iterable.ts | 3 ++- src/{ => core/classes}/IterableAction.ts | 0 .../classes}/IterableActionContext.ts | 2 +- .../classes}/IterableAttributionInfo.ts | 0 .../classes}/IterableAuthResponse.ts | 0 .../classes}/IterableCommerceItem.ts | 0 src/{ => core/classes}/IterableConfig.ts | 9 +++---- src/{ => core/classes}/IterableEdgeInsets.ts | 0 src/{ => core/classes}/IterableLogger.ts | 0 src/{ => core/classes}/IterableUtil.ts | 0 src/core/classes/index.ts | 10 ++++++++ src/{ => core}/enums/IterableActionSource.ts | 0 .../enums/IterableAuthResponseResult.ts | 0 src/{ => core}/enums/IterableDataRegion.ts | 0 src/{ => core}/enums/IterableEventName.ts | 0 src/{ => core}/enums/IterableLogLevel.ts | 0 src/{ => core}/enums/IterablePushPlatform.ts | 0 src/{ => core}/enums/index.ts | 0 src/{ => core}/hooks/index.ts | 0 src/{ => core}/hooks/useAppStateListener.ts | 0 src/{ => core}/hooks/useDeviceOrientation.tsx | 0 src/core/index.ts | 3 +++ .../{ => classes}/IterableHtmlInAppContent.ts | 6 ++--- .../{ => classes}/IterableInAppManager.ts | 8 ++++--- .../{ => classes}/IterableInAppMessage.ts | 7 +++--- .../{ => classes}/IterableInAppTrigger.ts | 2 +- .../{ => classes}/IterableInboxMetadata.ts | 0 src/inApp/classes/index.ts | 5 ++++ src/inApp/index.ts | 6 +---- src/inApp/types/IterableInAppContent.ts | 2 +- .../{ => classes}/IterableInboxDataModel.ts | 2 +- src/inbox/classes/index.ts | 1 + src/inbox/components/IterableInbox.tsx | 8 +++---- .../components/IterableInboxMessageCell.tsx | 2 +- .../IterableInboxMessageDisplay.tsx | 12 ++++++---- .../components/IterableInboxMessageList.tsx | 2 +- src/inbox/components/index.ts | 2 ++ src/inbox/index.ts | 1 + src/index.tsx | 24 ++++++++++--------- tsconfig.json | 2 ++ 43 files changed, 75 insertions(+), 50 deletions(-) rename src/{ => core/classes}/Iterable.ts (99%) rename src/{ => core/classes}/IterableAction.ts (100%) rename src/{ => core/classes}/IterableActionContext.ts (91%) rename src/{ => core/classes}/IterableAttributionInfo.ts (100%) rename src/{ => core/classes}/IterableAuthResponse.ts (100%) rename src/{ => core/classes}/IterableCommerceItem.ts (100%) rename src/{ => core/classes}/IterableConfig.ts (99%) rename src/{ => core/classes}/IterableEdgeInsets.ts (100%) rename src/{ => core/classes}/IterableLogger.ts (100%) rename src/{ => core/classes}/IterableUtil.ts (100%) create mode 100644 src/core/classes/index.ts rename src/{ => core}/enums/IterableActionSource.ts (100%) rename src/{ => core}/enums/IterableAuthResponseResult.ts (100%) rename src/{ => core}/enums/IterableDataRegion.ts (100%) rename src/{ => core}/enums/IterableEventName.ts (100%) rename src/{ => core}/enums/IterableLogLevel.ts (100%) rename src/{ => core}/enums/IterablePushPlatform.ts (100%) rename src/{ => core}/enums/index.ts (100%) rename src/{ => core}/hooks/index.ts (100%) rename src/{ => core}/hooks/useAppStateListener.ts (100%) rename src/{ => core}/hooks/useDeviceOrientation.tsx (100%) create mode 100644 src/core/index.ts rename src/inApp/{ => classes}/IterableHtmlInAppContent.ts (76%) rename src/inApp/{ => classes}/IterableInAppManager.ts (97%) rename src/inApp/{ => classes}/IterableInAppMessage.ts (97%) rename src/inApp/{ => classes}/IterableInAppTrigger.ts (86%) rename src/inApp/{ => classes}/IterableInboxMetadata.ts (100%) create mode 100644 src/inApp/classes/index.ts rename src/inbox/{ => classes}/IterableInboxDataModel.ts (99%) create mode 100644 src/inbox/classes/index.ts diff --git a/src/__mocks__/MockRNIterableAPI.ts b/src/__mocks__/MockRNIterableAPI.ts index 1de6afcc1..e75a83578 100644 --- a/src/__mocks__/MockRNIterableAPI.ts +++ b/src/__mocks__/MockRNIterableAPI.ts @@ -1,4 +1,4 @@ -import { IterableAttributionInfo } from '../IterableAttributionInfo'; +import { IterableAttributionInfo } from '../core/classes/IterableAttributionInfo'; import { IterableInAppMessage } from 'inApp'; export class MockRNIterableAPI { diff --git a/src/__tests__/Iterable.test.ts b/src/__tests__/Iterable.test.ts index 01fdfb6e7..e64241044 100644 --- a/src/__tests__/Iterable.test.ts +++ b/src/__tests__/Iterable.test.ts @@ -17,7 +17,7 @@ import { IterableEventName, IterableLogLevel, } from '..'; -import { IterableLogger } from '../IterableLogger'; +import { IterableLogger } from '../core/classes/IterableLogger'; describe('Iterable', () => { beforeEach(() => { diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index aca27c968..dc6284bc9 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -15,7 +15,7 @@ import { IterableInAppTriggerType, IterableInboxMetadata, } from '..'; -import { IterableLogger } from '../IterableLogger'; +import { IterableLogger } from '../core/classes/IterableLogger'; describe('Iterable In App', () => { beforeEach(() => { diff --git a/src/Iterable.ts b/src/core/classes/Iterable.ts similarity index 99% rename from src/Iterable.ts rename to src/core/classes/Iterable.ts index fbf1fd258..c3442ca3e 100644 --- a/src/Iterable.ts +++ b/src/core/classes/Iterable.ts @@ -5,7 +5,7 @@ import { Platform, } from 'react-native'; -import { IterableAuthResponseResult, IterableEventName } from './enums'; +import { IterableAuthResponseResult, IterableEventName } from 'core/enums'; import { IterableInAppCloseSource, IterableInAppDeleteSource, @@ -13,6 +13,7 @@ import { IterableInAppManager, IterableInAppMessage, } from 'inApp'; + import { IterableAction } from './IterableAction'; import { IterableActionContext } from './IterableActionContext'; import { IterableAttributionInfo } from './IterableAttributionInfo'; diff --git a/src/IterableAction.ts b/src/core/classes/IterableAction.ts similarity index 100% rename from src/IterableAction.ts rename to src/core/classes/IterableAction.ts diff --git a/src/IterableActionContext.ts b/src/core/classes/IterableActionContext.ts similarity index 91% rename from src/IterableActionContext.ts rename to src/core/classes/IterableActionContext.ts index dad40a6e4..170da95b6 100644 --- a/src/IterableActionContext.ts +++ b/src/core/classes/IterableActionContext.ts @@ -1,4 +1,4 @@ -import type { IterableActionSource } from './enums'; +import type { IterableActionSource } from 'core/enums'; import { IterableAction } from './IterableAction'; /** diff --git a/src/IterableAttributionInfo.ts b/src/core/classes/IterableAttributionInfo.ts similarity index 100% rename from src/IterableAttributionInfo.ts rename to src/core/classes/IterableAttributionInfo.ts diff --git a/src/IterableAuthResponse.ts b/src/core/classes/IterableAuthResponse.ts similarity index 100% rename from src/IterableAuthResponse.ts rename to src/core/classes/IterableAuthResponse.ts diff --git a/src/IterableCommerceItem.ts b/src/core/classes/IterableCommerceItem.ts similarity index 100% rename from src/IterableCommerceItem.ts rename to src/core/classes/IterableCommerceItem.ts diff --git a/src/IterableConfig.ts b/src/core/classes/IterableConfig.ts similarity index 99% rename from src/IterableConfig.ts rename to src/core/classes/IterableConfig.ts index 0c8b7b0bf..f643c752b 100644 --- a/src/IterableConfig.ts +++ b/src/core/classes/IterableConfig.ts @@ -1,13 +1,14 @@ -import { IterableAction } from './IterableAction'; -import type { IterableActionContext } from './IterableActionContext'; -import type { IterableAuthResponse } from './IterableAuthResponse'; import { IterableDataRegion, IterableLogLevel, IterablePushPlatform, -} from './enums'; +} from 'core/enums'; import { IterableInAppMessage, IterableInAppShowResponse } from 'inApp'; +import { IterableAction } from './IterableAction'; +import type { IterableActionContext } from './IterableActionContext'; +import type { IterableAuthResponse } from './IterableAuthResponse'; + /** * An IterableConfig object sets various properties of the SDK. * An IterableConfig object is passed into the static initialize method on the Iterable class when initializing the SDK. diff --git a/src/IterableEdgeInsets.ts b/src/core/classes/IterableEdgeInsets.ts similarity index 100% rename from src/IterableEdgeInsets.ts rename to src/core/classes/IterableEdgeInsets.ts diff --git a/src/IterableLogger.ts b/src/core/classes/IterableLogger.ts similarity index 100% rename from src/IterableLogger.ts rename to src/core/classes/IterableLogger.ts diff --git a/src/IterableUtil.ts b/src/core/classes/IterableUtil.ts similarity index 100% rename from src/IterableUtil.ts rename to src/core/classes/IterableUtil.ts diff --git a/src/core/classes/index.ts b/src/core/classes/index.ts new file mode 100644 index 000000000..60c26047c --- /dev/null +++ b/src/core/classes/index.ts @@ -0,0 +1,10 @@ +export * from './Iterable'; +export * from './IterableAction'; +export * from './IterableActionContext'; +export * from './IterableAttributionInfo'; +export * from './IterableAuthResponse'; +export * from './IterableCommerceItem'; +export * from './IterableConfig'; +export * from './IterableEdgeInsets'; +export * from './IterableLogger'; +export * from './IterableUtil'; diff --git a/src/enums/IterableActionSource.ts b/src/core/enums/IterableActionSource.ts similarity index 100% rename from src/enums/IterableActionSource.ts rename to src/core/enums/IterableActionSource.ts diff --git a/src/enums/IterableAuthResponseResult.ts b/src/core/enums/IterableAuthResponseResult.ts similarity index 100% rename from src/enums/IterableAuthResponseResult.ts rename to src/core/enums/IterableAuthResponseResult.ts diff --git a/src/enums/IterableDataRegion.ts b/src/core/enums/IterableDataRegion.ts similarity index 100% rename from src/enums/IterableDataRegion.ts rename to src/core/enums/IterableDataRegion.ts diff --git a/src/enums/IterableEventName.ts b/src/core/enums/IterableEventName.ts similarity index 100% rename from src/enums/IterableEventName.ts rename to src/core/enums/IterableEventName.ts diff --git a/src/enums/IterableLogLevel.ts b/src/core/enums/IterableLogLevel.ts similarity index 100% rename from src/enums/IterableLogLevel.ts rename to src/core/enums/IterableLogLevel.ts diff --git a/src/enums/IterablePushPlatform.ts b/src/core/enums/IterablePushPlatform.ts similarity index 100% rename from src/enums/IterablePushPlatform.ts rename to src/core/enums/IterablePushPlatform.ts diff --git a/src/enums/index.ts b/src/core/enums/index.ts similarity index 100% rename from src/enums/index.ts rename to src/core/enums/index.ts diff --git a/src/hooks/index.ts b/src/core/hooks/index.ts similarity index 100% rename from src/hooks/index.ts rename to src/core/hooks/index.ts diff --git a/src/hooks/useAppStateListener.ts b/src/core/hooks/useAppStateListener.ts similarity index 100% rename from src/hooks/useAppStateListener.ts rename to src/core/hooks/useAppStateListener.ts diff --git a/src/hooks/useDeviceOrientation.tsx b/src/core/hooks/useDeviceOrientation.tsx similarity index 100% rename from src/hooks/useDeviceOrientation.tsx rename to src/core/hooks/useDeviceOrientation.tsx diff --git a/src/core/index.ts b/src/core/index.ts new file mode 100644 index 000000000..731284104 --- /dev/null +++ b/src/core/index.ts @@ -0,0 +1,3 @@ +export * from './classes'; +export * from './enums'; +export * from './hooks'; diff --git a/src/inApp/IterableHtmlInAppContent.ts b/src/inApp/classes/IterableHtmlInAppContent.ts similarity index 76% rename from src/inApp/IterableHtmlInAppContent.ts rename to src/inApp/classes/IterableHtmlInAppContent.ts index 681930b3d..e6b53184b 100644 --- a/src/inApp/IterableHtmlInAppContent.ts +++ b/src/inApp/classes/IterableHtmlInAppContent.ts @@ -1,7 +1,7 @@ -import { IterableEdgeInsets } from '../IterableEdgeInsets'; +import { IterableEdgeInsets } from 'core'; -import type { IterableInAppContent } from './types'; -import { IterableInAppContentType } from './enums'; +import { IterableInAppContentType } from 'inApp/enums'; +import type { IterableInAppContent } from 'inApp/types'; // TODO: Add description export class IterableHtmlInAppContent implements IterableInAppContent { diff --git a/src/inApp/IterableInAppManager.ts b/src/inApp/classes/IterableInAppManager.ts similarity index 97% rename from src/inApp/IterableInAppManager.ts rename to src/inApp/classes/IterableInAppManager.ts index 22bb6a8a4..7f8297c83 100644 --- a/src/inApp/IterableInAppManager.ts +++ b/src/inApp/classes/IterableInAppManager.ts @@ -1,10 +1,12 @@ import { NativeModules } from 'react-native'; -import { Iterable } from '../Iterable'; - +import { Iterable } from 'core'; +import type { + IterableInAppDeleteSource, + IterableInAppLocation, +} from 'inApp/enums'; import { IterableHtmlInAppContent } from './IterableHtmlInAppContent'; import { IterableInAppMessage } from './IterableInAppMessage'; -import type { IterableInAppLocation, IterableInAppDeleteSource } from './enums'; // TODO: Create a loader for this const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inApp/IterableInAppMessage.ts b/src/inApp/classes/IterableInAppMessage.ts similarity index 97% rename from src/inApp/IterableInAppMessage.ts rename to src/inApp/classes/IterableInAppMessage.ts index cfa0684dc..2a04d059e 100644 --- a/src/inApp/IterableInAppMessage.ts +++ b/src/inApp/classes/IterableInAppMessage.ts @@ -1,10 +1,9 @@ import { type ViewToken } from 'react-native'; -import { IterableUtil } from '../IterableUtil'; - -import { IterableInboxMetadata } from './IterableInboxMetadata'; -import { IterableInAppTriggerType } from './enums'; +import { IterableUtil } from 'core'; +import { IterableInAppTriggerType } from 'inApp/enums'; import { IterableInAppTrigger } from './IterableInAppTrigger'; +import { IterableInboxMetadata } from './IterableInboxMetadata'; /** * Iterable in-app message diff --git a/src/inApp/IterableInAppTrigger.ts b/src/inApp/classes/IterableInAppTrigger.ts similarity index 86% rename from src/inApp/IterableInAppTrigger.ts rename to src/inApp/classes/IterableInAppTrigger.ts index 0c03f944f..ac2d2d611 100644 --- a/src/inApp/IterableInAppTrigger.ts +++ b/src/inApp/classes/IterableInAppTrigger.ts @@ -1,4 +1,4 @@ -import type { IterableInAppTriggerType } from './enums'; +import type { IterableInAppTriggerType } from 'inApp/enums'; // TODO: Add description export class IterableInAppTrigger { diff --git a/src/inApp/IterableInboxMetadata.ts b/src/inApp/classes/IterableInboxMetadata.ts similarity index 100% rename from src/inApp/IterableInboxMetadata.ts rename to src/inApp/classes/IterableInboxMetadata.ts diff --git a/src/inApp/classes/index.ts b/src/inApp/classes/index.ts new file mode 100644 index 000000000..ae4f861ae --- /dev/null +++ b/src/inApp/classes/index.ts @@ -0,0 +1,5 @@ +export * from './IterableHtmlInAppContent'; +export * from './IterableInAppManager'; +export * from './IterableInAppMessage'; +export * from './IterableInAppTrigger'; +export * from './IterableInboxMetadata'; diff --git a/src/inApp/index.ts b/src/inApp/index.ts index 3f7287be5..38c539f76 100644 --- a/src/inApp/index.ts +++ b/src/inApp/index.ts @@ -1,7 +1,3 @@ +export * from './classes'; export * from './enums'; -export * from './IterableHtmlInAppContent'; -export * from './IterableInAppManager'; -export * from './IterableInAppMessage'; -export * from './IterableInAppTrigger'; -export * from './IterableInboxMetadata'; export * from './types'; diff --git a/src/inApp/types/IterableInAppContent.ts b/src/inApp/types/IterableInAppContent.ts index a2a312e58..146b76b01 100644 --- a/src/inApp/types/IterableInAppContent.ts +++ b/src/inApp/types/IterableInAppContent.ts @@ -1,4 +1,4 @@ -import type { IterableInAppContentType } from '../enums'; +import type { IterableInAppContentType } from 'inApp/enums'; // TODO: Add description export interface IterableInAppContent { diff --git a/src/inbox/IterableInboxDataModel.ts b/src/inbox/classes/IterableInboxDataModel.ts similarity index 99% rename from src/inbox/IterableInboxDataModel.ts rename to src/inbox/classes/IterableInboxDataModel.ts index 17d40dc52..c1e6be1e5 100644 --- a/src/inbox/IterableInboxDataModel.ts +++ b/src/inbox/classes/IterableInboxDataModel.ts @@ -1,5 +1,6 @@ import { NativeModules } from 'react-native'; +import { Iterable } from 'core'; import { IterableHtmlInAppContent, IterableInAppDeleteSource, @@ -10,7 +11,6 @@ import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, } from 'inbox/types'; -import { Iterable } from '../Iterable'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inbox/classes/index.ts b/src/inbox/classes/index.ts new file mode 100644 index 000000000..52c9b2a70 --- /dev/null +++ b/src/inbox/classes/index.ts @@ -0,0 +1 @@ +export * from './IterableInboxDataModel'; diff --git a/src/inbox/components/IterableInbox.tsx b/src/inbox/components/IterableInbox.tsx index 3588e115e..d1424f565 100644 --- a/src/inbox/components/IterableInbox.tsx +++ b/src/inbox/components/IterableInbox.tsx @@ -11,15 +11,13 @@ import { } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; -import { Iterable } from '../../Iterable'; -import { useAppStateListener, useDeviceOrientation } from '../../hooks'; +import { Iterable, useAppStateListener, useDeviceOrientation } from 'core'; import { IterableInAppDeleteSource, IterableInAppLocation } from 'inApp'; - -import IterableInboxDataModel from 'inbox/IterableInboxDataModel'; +import { IterableInboxDataModel } from 'inbox/classes'; import type { + IterableInboxCustomizations, IterableInboxImpressionRowInfo, IterableInboxRowViewModel, - IterableInboxCustomizations, } from 'inbox/types'; import { IterableInboxEmptyState } from './IterableInboxEmptyState'; import { IterableInboxMessageDisplay } from './IterableInboxMessageDisplay'; diff --git a/src/inbox/components/IterableInboxMessageCell.tsx b/src/inbox/components/IterableInboxMessageCell.tsx index 313d5a902..3fe0ae2d8 100644 --- a/src/inbox/components/IterableInboxMessageCell.tsx +++ b/src/inbox/components/IterableInboxMessageCell.tsx @@ -11,7 +11,7 @@ import { type ViewStyle, } from 'react-native'; -import { IterableInboxDataModel } from 'inbox/IterableInboxDataModel'; +import { IterableInboxDataModel } from 'inbox/classes'; import type { IterableInboxRowViewModel, IterableInboxCustomizations, diff --git a/src/inbox/components/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx index 0f9df19cf..1f5701d34 100644 --- a/src/inbox/components/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -10,17 +10,19 @@ import { import Icon from 'react-native-vector-icons/Ionicons'; import { WebView } from 'react-native-webview'; -import { IterableActionSource } from '../../enums'; +import { + Iterable, + IterableAction, + IterableActionContext, + IterableActionSource, + IterableEdgeInsets, +} from 'core'; import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, } from 'inApp'; -import { Iterable } from '../../Iterable'; -import { IterableAction } from '../../IterableAction'; -import { IterableEdgeInsets } from '../../IterableEdgeInsets'; import { type IterableInboxRowViewModel } from 'inbox/types'; -import IterableActionContext from '../../IterableActionContext'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/inbox/components/IterableInboxMessageList.tsx b/src/inbox/components/IterableInboxMessageList.tsx index a1e740047..e2ee26830 100644 --- a/src/inbox/components/IterableInboxMessageList.tsx +++ b/src/inbox/components/IterableInboxMessageList.tsx @@ -2,7 +2,7 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; import { IterableInAppMessage } from 'inApp'; -import { IterableInboxDataModel } from 'inbox/IterableInboxDataModel'; +import { IterableInboxDataModel } from 'inbox/classes'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, diff --git a/src/inbox/components/index.ts b/src/inbox/components/index.ts index 2ef11ac16..f00e88241 100644 --- a/src/inbox/components/index.ts +++ b/src/inbox/components/index.ts @@ -1,3 +1,5 @@ export * from './IterableInbox'; export * from './IterableInboxEmptyState'; export * from './IterableInboxMessageCell'; +export * from './IterableInboxMessageDisplay'; +export * from './IterableInboxMessageList'; diff --git a/src/inbox/index.ts b/src/inbox/index.ts index 195d95f59..e8ff3a69b 100644 --- a/src/inbox/index.ts +++ b/src/inbox/index.ts @@ -1,2 +1,3 @@ +export * from './classes'; export * from './components'; export * from './types'; diff --git a/src/index.tsx b/src/index.tsx index e0a1530ca..45ec3f4e3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,13 +2,22 @@ * React Native module for Iterable. * @module react-native-iterable-sdk */ +export { + Iterable, + IterableAction, + IterableActionContext, + IterableAttributionInfo, + IterableCommerceItem, + IterableConfig, + IterableEdgeInsets, +} from 'core/classes'; export { IterableActionSource, IterableDataRegion, IterableEventName, IterableLogLevel, -} from './enums'; -export { useAppStateListener, useDeviceOrientation } from './hooks'; +} from 'core/enums'; +export { useAppStateListener, useDeviceOrientation } from 'core/hooks'; export { IterableHtmlInAppContent, IterableInAppCloseSource, @@ -22,7 +31,7 @@ export { IterableInAppTriggerType, IterableInboxMetadata, type IterableInAppContent, -} from './inApp'; +} from 'inApp'; export { IterableInbox, IterableInboxEmptyState, @@ -31,11 +40,4 @@ export { type IterableInboxRowViewModel as InboxRowViewModel, type IterableInboxCustomizations, type IterableInboxProps, -} from './inbox'; -export { Iterable } from './Iterable'; -export { IterableAction } from './IterableAction'; -export { IterableActionContext } from './IterableActionContext'; -export { IterableAttributionInfo } from './IterableAttributionInfo'; -export { IterableCommerceItem } from './IterableCommerceItem'; -export { IterableConfig } from './IterableConfig'; -export { IterableEdgeInsets } from './IterableEdgeInsets'; +} from 'inbox'; diff --git a/tsconfig.json b/tsconfig.json index e51d5d5bd..d26c9d046 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,8 @@ "rootDir": ".", "paths": { "@iterable/react-native-sdk": ["./src/index"], + "core/*": ["./src/core/*"], + "core": ["./src/core/index"], "inbox/*": ["./src/inbox/*"], "inbox": ["./src/inbox/index"], "inApp/*": ["./src/inApp/*"], From 1393e4b9f3d862d549f9d922e28f3dc1192bd32c Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Thu, 7 Nov 2024 00:21:09 -0800 Subject: [PATCH 18/22] Undid local path changes as they do not work with the build --- src/__mocks__/MockRNIterableAPI.ts | 4 ++-- src/__mocks__/index.ts | 2 ++ src/__tests__/Iterable.test.ts | 5 ++--- src/__tests__/IterableInApp.test.ts | 5 ++--- src/core/classes/Iterable.ts | 4 ++-- src/core/classes/IterableActionContext.ts | 2 +- src/core/classes/IterableConfig.ts | 5 ++--- src/inApp/classes/IterableHtmlInAppContent.ts | 6 +++--- src/inApp/classes/IterableInAppManager.ts | 4 ++-- src/inApp/classes/IterableInAppMessage.ts | 4 ++-- src/inApp/classes/IterableInAppTrigger.ts | 2 +- src/inApp/types/IterableInAppContent.ts | 2 +- src/inbox/classes/IterableInboxDataModel.ts | 6 +++--- src/inbox/components/IterableInbox.tsx | 13 +++++++++---- src/inbox/components/IterableInboxEmptyState.tsx | 2 +- src/inbox/components/IterableInboxMessageCell.tsx | 4 ++-- .../components/IterableInboxMessageDisplay.tsx | 7 ++++--- src/inbox/components/IterableInboxMessageList.tsx | 7 ++++--- src/inbox/types/IterableInboxRowViewModel.ts | 2 +- src/index.tsx | 10 +++++----- tsconfig.json | 8 +------- 21 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 src/__mocks__/index.ts diff --git a/src/__mocks__/MockRNIterableAPI.ts b/src/__mocks__/MockRNIterableAPI.ts index e75a83578..36c8daa1d 100644 --- a/src/__mocks__/MockRNIterableAPI.ts +++ b/src/__mocks__/MockRNIterableAPI.ts @@ -1,5 +1,5 @@ -import { IterableAttributionInfo } from '../core/classes/IterableAttributionInfo'; -import { IterableInAppMessage } from 'inApp'; +import { IterableAttributionInfo } from '../core'; +import { IterableInAppMessage } from '../inApp'; export class MockRNIterableAPI { static email?: string; diff --git a/src/__mocks__/index.ts b/src/__mocks__/index.ts new file mode 100644 index 000000000..1fac4fe8c --- /dev/null +++ b/src/__mocks__/index.ts @@ -0,0 +1,2 @@ +export * from './MockLinking'; +export * from './MockRNIterableAPI'; diff --git a/src/__tests__/Iterable.test.ts b/src/__tests__/Iterable.test.ts index e64241044..4ba387deb 100644 --- a/src/__tests__/Iterable.test.ts +++ b/src/__tests__/Iterable.test.ts @@ -2,8 +2,7 @@ import { NativeEventEmitter } from 'react-native'; import { MockLinking } from '../__mocks__/MockLinking'; import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; -import { TestHelper } from './TestHelper'; - +import { IterableLogger } from '../core'; // import from the same location that consumers import from import { Iterable, @@ -17,7 +16,7 @@ import { IterableEventName, IterableLogLevel, } from '..'; -import { IterableLogger } from '../core/classes/IterableLogger'; +import { TestHelper } from './TestHelper'; describe('Iterable', () => { beforeEach(() => { diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index dc6284bc9..ca31b0091 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -1,7 +1,5 @@ import { NativeEventEmitter } from 'react-native'; -import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; - import { Iterable, IterableConfig, @@ -15,7 +13,8 @@ import { IterableInAppTriggerType, IterableInboxMetadata, } from '..'; -import { IterableLogger } from '../core/classes/IterableLogger'; +import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; +import { IterableLogger } from '../core'; describe('Iterable In App', () => { beforeEach(() => { diff --git a/src/core/classes/Iterable.ts b/src/core/classes/Iterable.ts index c3442ca3e..b746f472d 100644 --- a/src/core/classes/Iterable.ts +++ b/src/core/classes/Iterable.ts @@ -5,14 +5,14 @@ import { Platform, } from 'react-native'; -import { IterableAuthResponseResult, IterableEventName } from 'core/enums'; import { IterableInAppCloseSource, IterableInAppDeleteSource, IterableInAppLocation, IterableInAppManager, IterableInAppMessage, -} from 'inApp'; +} from '../../inApp'; +import { IterableAuthResponseResult, IterableEventName } from '../enums'; import { IterableAction } from './IterableAction'; import { IterableActionContext } from './IterableActionContext'; diff --git a/src/core/classes/IterableActionContext.ts b/src/core/classes/IterableActionContext.ts index 170da95b6..ca358ef26 100644 --- a/src/core/classes/IterableActionContext.ts +++ b/src/core/classes/IterableActionContext.ts @@ -1,4 +1,4 @@ -import type { IterableActionSource } from 'core/enums'; +import type { IterableActionSource } from '../enums'; import { IterableAction } from './IterableAction'; /** diff --git a/src/core/classes/IterableConfig.ts b/src/core/classes/IterableConfig.ts index f643c752b..38aeedef8 100644 --- a/src/core/classes/IterableConfig.ts +++ b/src/core/classes/IterableConfig.ts @@ -1,10 +1,9 @@ +import { IterableInAppMessage, IterableInAppShowResponse } from '../../inApp'; import { IterableDataRegion, IterableLogLevel, IterablePushPlatform, -} from 'core/enums'; -import { IterableInAppMessage, IterableInAppShowResponse } from 'inApp'; - +} from '../enums'; import { IterableAction } from './IterableAction'; import type { IterableActionContext } from './IterableActionContext'; import type { IterableAuthResponse } from './IterableAuthResponse'; diff --git a/src/inApp/classes/IterableHtmlInAppContent.ts b/src/inApp/classes/IterableHtmlInAppContent.ts index e6b53184b..6e156eec2 100644 --- a/src/inApp/classes/IterableHtmlInAppContent.ts +++ b/src/inApp/classes/IterableHtmlInAppContent.ts @@ -1,7 +1,7 @@ -import { IterableEdgeInsets } from 'core'; +import { IterableEdgeInsets } from '../../core'; -import { IterableInAppContentType } from 'inApp/enums'; -import type { IterableInAppContent } from 'inApp/types'; +import { IterableInAppContentType } from '../enums'; +import type { IterableInAppContent } from '../types'; // TODO: Add description export class IterableHtmlInAppContent implements IterableInAppContent { diff --git a/src/inApp/classes/IterableInAppManager.ts b/src/inApp/classes/IterableInAppManager.ts index 7f8297c83..f8f958866 100644 --- a/src/inApp/classes/IterableInAppManager.ts +++ b/src/inApp/classes/IterableInAppManager.ts @@ -1,10 +1,10 @@ import { NativeModules } from 'react-native'; -import { Iterable } from 'core'; +import { Iterable } from '../../core'; import type { IterableInAppDeleteSource, IterableInAppLocation, -} from 'inApp/enums'; +} from '../enums'; import { IterableHtmlInAppContent } from './IterableHtmlInAppContent'; import { IterableInAppMessage } from './IterableInAppMessage'; diff --git a/src/inApp/classes/IterableInAppMessage.ts b/src/inApp/classes/IterableInAppMessage.ts index 2a04d059e..653439c09 100644 --- a/src/inApp/classes/IterableInAppMessage.ts +++ b/src/inApp/classes/IterableInAppMessage.ts @@ -1,7 +1,7 @@ import { type ViewToken } from 'react-native'; -import { IterableUtil } from 'core'; -import { IterableInAppTriggerType } from 'inApp/enums'; +import { IterableUtil } from '../../core'; +import { IterableInAppTriggerType } from '../enums'; import { IterableInAppTrigger } from './IterableInAppTrigger'; import { IterableInboxMetadata } from './IterableInboxMetadata'; diff --git a/src/inApp/classes/IterableInAppTrigger.ts b/src/inApp/classes/IterableInAppTrigger.ts index ac2d2d611..1737bfdf7 100644 --- a/src/inApp/classes/IterableInAppTrigger.ts +++ b/src/inApp/classes/IterableInAppTrigger.ts @@ -1,4 +1,4 @@ -import type { IterableInAppTriggerType } from 'inApp/enums'; +import type { IterableInAppTriggerType } from '../enums'; // TODO: Add description export class IterableInAppTrigger { diff --git a/src/inApp/types/IterableInAppContent.ts b/src/inApp/types/IterableInAppContent.ts index 146b76b01..a2a312e58 100644 --- a/src/inApp/types/IterableInAppContent.ts +++ b/src/inApp/types/IterableInAppContent.ts @@ -1,4 +1,4 @@ -import type { IterableInAppContentType } from 'inApp/enums'; +import type { IterableInAppContentType } from '../enums'; // TODO: Add description export interface IterableInAppContent { diff --git a/src/inbox/classes/IterableInboxDataModel.ts b/src/inbox/classes/IterableInboxDataModel.ts index c1e6be1e5..8badd410f 100644 --- a/src/inbox/classes/IterableInboxDataModel.ts +++ b/src/inbox/classes/IterableInboxDataModel.ts @@ -1,16 +1,16 @@ import { NativeModules } from 'react-native'; -import { Iterable } from 'core'; +import { Iterable } from '../../core'; import { IterableHtmlInAppContent, IterableInAppDeleteSource, IterableInAppLocation, IterableInAppMessage, -} from 'inApp'; +} from '../../inApp'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, -} from 'inbox/types'; +} from '../types'; const RNIterableAPI = NativeModules.RNIterableAPI; diff --git a/src/inbox/components/IterableInbox.tsx b/src/inbox/components/IterableInbox.tsx index d1424f565..700a86658 100644 --- a/src/inbox/components/IterableInbox.tsx +++ b/src/inbox/components/IterableInbox.tsx @@ -11,14 +11,19 @@ import { } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; -import { Iterable, useAppStateListener, useDeviceOrientation } from 'core'; -import { IterableInAppDeleteSource, IterableInAppLocation } from 'inApp'; -import { IterableInboxDataModel } from 'inbox/classes'; +import { + Iterable, + useAppStateListener, + useDeviceOrientation, +} from '../../core'; +import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp'; + +import { IterableInboxDataModel } from '../classes'; import type { IterableInboxCustomizations, IterableInboxImpressionRowInfo, IterableInboxRowViewModel, -} from 'inbox/types'; +} from '../types'; import { IterableInboxEmptyState } from './IterableInboxEmptyState'; import { IterableInboxMessageDisplay } from './IterableInboxMessageDisplay'; import { IterableInboxMessageList } from './IterableInboxMessageList'; diff --git a/src/inbox/components/IterableInboxEmptyState.tsx b/src/inbox/components/IterableInboxEmptyState.tsx index 7ff8d6b3a..a1a2074f1 100644 --- a/src/inbox/components/IterableInboxEmptyState.tsx +++ b/src/inbox/components/IterableInboxEmptyState.tsx @@ -1,6 +1,6 @@ import { StyleSheet, Text, View } from 'react-native'; -import { type IterableInboxCustomizations } from 'inbox/types'; +import { type IterableInboxCustomizations } from '../types'; // TODO: Comment export interface IterableInboxEmptyStateProps { diff --git a/src/inbox/components/IterableInboxMessageCell.tsx b/src/inbox/components/IterableInboxMessageCell.tsx index 3fe0ae2d8..693cb018a 100644 --- a/src/inbox/components/IterableInboxMessageCell.tsx +++ b/src/inbox/components/IterableInboxMessageCell.tsx @@ -11,11 +11,11 @@ import { type ViewStyle, } from 'react-native'; -import { IterableInboxDataModel } from 'inbox/classes'; +import { IterableInboxDataModel } from '../classes'; import type { IterableInboxRowViewModel, IterableInboxCustomizations, -} from 'inbox/types'; +} from '../types'; // TODO: Change to component function defaultMessageListLayout( diff --git a/src/inbox/components/IterableInboxMessageDisplay.tsx b/src/inbox/components/IterableInboxMessageDisplay.tsx index 1f5701d34..cccc0de77 100644 --- a/src/inbox/components/IterableInboxMessageDisplay.tsx +++ b/src/inbox/components/IterableInboxMessageDisplay.tsx @@ -16,13 +16,14 @@ import { IterableActionContext, IterableActionSource, IterableEdgeInsets, -} from 'core'; +} from '../../core'; import { IterableHtmlInAppContent, IterableInAppCloseSource, IterableInAppLocation, -} from 'inApp'; -import { type IterableInboxRowViewModel } from 'inbox/types'; +} from '../../inApp'; + +import { type IterableInboxRowViewModel } from '../types'; // TODO: Comment export interface IterableInboxMessageDisplayProps { diff --git a/src/inbox/components/IterableInboxMessageList.tsx b/src/inbox/components/IterableInboxMessageList.tsx index e2ee26830..2138a5290 100644 --- a/src/inbox/components/IterableInboxMessageList.tsx +++ b/src/inbox/components/IterableInboxMessageList.tsx @@ -1,13 +1,14 @@ import { useCallback, useRef, useState } from 'react'; import { type ViewabilityConfig, type ViewToken, FlatList } from 'react-native'; -import { IterableInAppMessage } from 'inApp'; -import { IterableInboxDataModel } from 'inbox/classes'; +import { IterableInAppMessage } from '../../inApp'; + +import { IterableInboxDataModel } from '../classes'; import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel, IterableInboxCustomizations, -} from 'inbox/types'; +} from '../types'; import { IterableInboxMessageCell } from './IterableInboxMessageCell'; // TODO: Comment diff --git a/src/inbox/types/IterableInboxRowViewModel.ts b/src/inbox/types/IterableInboxRowViewModel.ts index 2f1ca403e..f5f6e3ca6 100644 --- a/src/inbox/types/IterableInboxRowViewModel.ts +++ b/src/inbox/types/IterableInboxRowViewModel.ts @@ -1,4 +1,4 @@ -import { IterableInAppMessage } from 'inApp'; +import { IterableInAppMessage } from '../../inApp'; // TODO: Add description export type IterableInboxRowViewModel = { diff --git a/src/index.tsx b/src/index.tsx index 45ec3f4e3..48cd7e669 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -10,14 +10,14 @@ export { IterableCommerceItem, IterableConfig, IterableEdgeInsets, -} from 'core/classes'; +} from './core/classes'; export { IterableActionSource, IterableDataRegion, IterableEventName, IterableLogLevel, -} from 'core/enums'; -export { useAppStateListener, useDeviceOrientation } from 'core/hooks'; +} from './core/enums'; +export { useAppStateListener, useDeviceOrientation } from './core/hooks'; export { IterableHtmlInAppContent, IterableInAppCloseSource, @@ -31,7 +31,7 @@ export { IterableInAppTriggerType, IterableInboxMetadata, type IterableInAppContent, -} from 'inApp'; +} from './inApp'; export { IterableInbox, IterableInboxEmptyState, @@ -40,4 +40,4 @@ export { type IterableInboxRowViewModel as InboxRowViewModel, type IterableInboxCustomizations, type IterableInboxProps, -} from 'inbox'; +} from './inbox'; diff --git a/tsconfig.json b/tsconfig.json index d26c9d046..6d0983407 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,13 +2,7 @@ "compilerOptions": { "rootDir": ".", "paths": { - "@iterable/react-native-sdk": ["./src/index"], - "core/*": ["./src/core/*"], - "core": ["./src/core/index"], - "inbox/*": ["./src/inbox/*"], - "inbox": ["./src/inbox/index"], - "inApp/*": ["./src/inApp/*"], - "inApp": ["./src/inApp/index"], + "@iterable/react-native-sdk": ["./src/index"] }, "allowUnreachableCode": false, "allowUnusedLabels": false, From 6cfa8a20cf432dc4c8f19129f33c1b77d4e438d2 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Thu, 7 Nov 2024 00:34:15 -0800 Subject: [PATCH 19/22] Fix import path for package.json in Iterable class to ensure correct version retrieval --- src/core/classes/Iterable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/classes/Iterable.ts b/src/core/classes/Iterable.ts index b746f472d..0f4d3a936 100644 --- a/src/core/classes/Iterable.ts +++ b/src/core/classes/Iterable.ts @@ -659,7 +659,7 @@ export class Iterable { } private static getVersionFromPackageJson(): string { - const json = require('../package.json'); + const json = require('../../../package.json'); const version = json.version as string; return version; } From 468844655747dd1763a360d8c150a508ebd83be5 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Thu, 7 Nov 2024 11:56:05 -0800 Subject: [PATCH 20/22] Refactor types in inbox module: change type aliases to interfaces for IterableInboxCustomizations, IterableInboxImpressionRowInfo, and IterableInboxRowViewModel --- src/inbox/types/IterableInboxCustomizations.ts | 4 ++-- src/inbox/types/IterableInboxImpressionRowInfo.ts | 4 ++-- src/inbox/types/IterableInboxRowViewModel.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inbox/types/IterableInboxCustomizations.ts b/src/inbox/types/IterableInboxCustomizations.ts index 74ee52c35..17d621559 100644 --- a/src/inbox/types/IterableInboxCustomizations.ts +++ b/src/inbox/types/IterableInboxCustomizations.ts @@ -1,5 +1,5 @@ // TODO: Add description -export type IterableInboxCustomizations = { +export interface IterableInboxCustomizations { navTitle?: string; noMessagesTitle?: string; noMessagesBody?: string; @@ -66,4 +66,4 @@ export type IterableInboxCustomizations = { borderColor?: string; borderTopWidth?: number; }; -}; +} diff --git a/src/inbox/types/IterableInboxImpressionRowInfo.ts b/src/inbox/types/IterableInboxImpressionRowInfo.ts index 0d95daece..29833ae00 100644 --- a/src/inbox/types/IterableInboxImpressionRowInfo.ts +++ b/src/inbox/types/IterableInboxImpressionRowInfo.ts @@ -1,5 +1,5 @@ // TODO: Add description -export type IterableInboxImpressionRowInfo = { +export interface IterableInboxImpressionRowInfo { messageId: string; silentInbox: boolean; -}; +} diff --git a/src/inbox/types/IterableInboxRowViewModel.ts b/src/inbox/types/IterableInboxRowViewModel.ts index f5f6e3ca6..0c6e7f69d 100644 --- a/src/inbox/types/IterableInboxRowViewModel.ts +++ b/src/inbox/types/IterableInboxRowViewModel.ts @@ -1,11 +1,11 @@ import { IterableInAppMessage } from '../../inApp'; // TODO: Add description -export type IterableInboxRowViewModel = { +export interface IterableInboxRowViewModel { title: string; subtitle?: string; imageUrl?: string; createdAt?: Date; read: boolean; inAppMessage: IterableInAppMessage; -}; +} From 3d92e26123ad96998fd54c97d145dce042ee1af8 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Thu, 14 Nov 2024 14:17:29 -0800 Subject: [PATCH 21/22] Changed file order as it was messing with mocks --- src/__tests__/IterableInApp.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/__tests__/IterableInApp.test.ts b/src/__tests__/IterableInApp.test.ts index ca31b0091..c322d7c5a 100644 --- a/src/__tests__/IterableInApp.test.ts +++ b/src/__tests__/IterableInApp.test.ts @@ -1,5 +1,8 @@ import { NativeEventEmitter } from 'react-native'; +import { IterableLogger } from '../core'; +import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; + import { Iterable, IterableConfig, @@ -13,8 +16,6 @@ import { IterableInAppTriggerType, IterableInboxMetadata, } from '..'; -import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI'; -import { IterableLogger } from '../core'; describe('Iterable In App', () => { beforeEach(() => { From 4216fa720ab0df9171020294c8ac5b30e7da85f2 Mon Sep 17 00:00:00 2001 From: Loren Posen Date: Fri, 15 Nov 2024 14:50:27 -0800 Subject: [PATCH 22/22] Remove default exports from Iterable classes and enums --- src/core/classes/Iterable.ts | 2 -- src/core/classes/IterableAction.ts | 2 -- src/core/classes/IterableActionContext.ts | 2 -- src/core/classes/IterableAttributionInfo.ts | 2 -- src/core/classes/IterableAuthResponse.ts | 2 -- src/core/classes/IterableCommerceItem.ts | 2 -- src/core/classes/IterableConfig.ts | 2 -- src/core/classes/IterableEdgeInsets.ts | 2 -- src/core/enums/IterableActionSource.ts | 2 -- src/core/enums/IterableAuthResponseResult.ts | 2 -- src/core/enums/IterableEventName.ts | 2 -- src/core/enums/IterableLogLevel.ts | 2 -- src/core/enums/IterablePushPlatform.ts | 2 -- src/inApp/classes/IterableInboxMetadata.ts | 2 -- src/inApp/enums/IterableInAppCloseSource.ts | 2 -- src/inApp/enums/IterableInAppContentType.ts | 2 -- src/inApp/enums/IterableInAppDeleteSource.ts | 2 -- src/inApp/enums/IterableInAppLocation.ts | 2 -- src/inApp/enums/IterableInAppShowResponse.ts | 2 -- src/inApp/enums/IterableInAppTriggerType.ts | 2 -- 20 files changed, 40 deletions(-) diff --git a/src/core/classes/Iterable.ts b/src/core/classes/Iterable.ts index 0f4d3a936..e2bc169ac 100644 --- a/src/core/classes/Iterable.ts +++ b/src/core/classes/Iterable.ts @@ -664,5 +664,3 @@ export class Iterable { return version; } } - -export default Iterable; diff --git a/src/core/classes/IterableAction.ts b/src/core/classes/IterableAction.ts index 307a7b65e..b325487ae 100644 --- a/src/core/classes/IterableAction.ts +++ b/src/core/classes/IterableAction.ts @@ -17,5 +17,3 @@ export class IterableAction { return new IterableAction(dict.type, dict.data, dict.userInput); } } - -export default IterableAction; diff --git a/src/core/classes/IterableActionContext.ts b/src/core/classes/IterableActionContext.ts index ca358ef26..64581e7fd 100644 --- a/src/core/classes/IterableActionContext.ts +++ b/src/core/classes/IterableActionContext.ts @@ -19,5 +19,3 @@ export class IterableActionContext { return new IterableActionContext(action, source); } } - -export default IterableActionContext; diff --git a/src/core/classes/IterableAttributionInfo.ts b/src/core/classes/IterableAttributionInfo.ts index 6b960d01b..5b8a1929a 100644 --- a/src/core/classes/IterableAttributionInfo.ts +++ b/src/core/classes/IterableAttributionInfo.ts @@ -12,5 +12,3 @@ export class IterableAttributionInfo { this.messageId = messageId; } } - -export default IterableAttributionInfo; diff --git a/src/core/classes/IterableAuthResponse.ts b/src/core/classes/IterableAuthResponse.ts index 8f49b2be8..716b52b73 100644 --- a/src/core/classes/IterableAuthResponse.ts +++ b/src/core/classes/IterableAuthResponse.ts @@ -6,5 +6,3 @@ export class IterableAuthResponse { successCallback?: () => void; failureCallback?: () => void; } - -export default IterableAuthResponse; diff --git a/src/core/classes/IterableCommerceItem.ts b/src/core/classes/IterableCommerceItem.ts index 3132fd662..8cbcaad39 100644 --- a/src/core/classes/IterableCommerceItem.ts +++ b/src/core/classes/IterableCommerceItem.ts @@ -37,5 +37,3 @@ export class IterableCommerceItem { this.dataFields = dataFields; } } - -export default IterableCommerceItem; diff --git a/src/core/classes/IterableConfig.ts b/src/core/classes/IterableConfig.ts index 38aeedef8..be678e3d8 100644 --- a/src/core/classes/IterableConfig.ts +++ b/src/core/classes/IterableConfig.ts @@ -161,5 +161,3 @@ export class IterableConfig { }; } } - -export default IterableConfig; diff --git a/src/core/classes/IterableEdgeInsets.ts b/src/core/classes/IterableEdgeInsets.ts index 44ee24d1e..dd3da9749 100644 --- a/src/core/classes/IterableEdgeInsets.ts +++ b/src/core/classes/IterableEdgeInsets.ts @@ -21,5 +21,3 @@ export class IterableEdgeInsets { ); } } - -export default IterableEdgeInsets; diff --git a/src/core/enums/IterableActionSource.ts b/src/core/enums/IterableActionSource.ts index 3ed59dcd0..2cecfcf02 100644 --- a/src/core/enums/IterableActionSource.ts +++ b/src/core/enums/IterableActionSource.ts @@ -6,5 +6,3 @@ export enum IterableActionSource { appLink = 1, inApp = 2, } - -export default IterableActionSource; diff --git a/src/core/enums/IterableAuthResponseResult.ts b/src/core/enums/IterableAuthResponseResult.ts index 565c6466f..03fb6a30a 100644 --- a/src/core/enums/IterableAuthResponseResult.ts +++ b/src/core/enums/IterableAuthResponseResult.ts @@ -3,5 +3,3 @@ export enum IterableAuthResponseResult { SUCCESS, FAILURE, } - -export default IterableAuthResponseResult; diff --git a/src/core/enums/IterableEventName.ts b/src/core/enums/IterableEventName.ts index f4aa04907..648032f05 100644 --- a/src/core/enums/IterableEventName.ts +++ b/src/core/enums/IterableEventName.ts @@ -8,5 +8,3 @@ export enum IterableEventName { handleAuthSuccessCalled = 'handleAuthSuccessCalled', handleAuthFailureCalled = 'handleAuthFailureCalled', } - -export default IterableEventName; diff --git a/src/core/enums/IterableLogLevel.ts b/src/core/enums/IterableLogLevel.ts index 772332f97..11675183b 100644 --- a/src/core/enums/IterableLogLevel.ts +++ b/src/core/enums/IterableLogLevel.ts @@ -6,5 +6,3 @@ export enum IterableLogLevel { info = 2, error = 3, } - -export default IterableLogLevel; diff --git a/src/core/enums/IterablePushPlatform.ts b/src/core/enums/IterablePushPlatform.ts index b0f25b27a..fbe88b871 100644 --- a/src/core/enums/IterablePushPlatform.ts +++ b/src/core/enums/IterablePushPlatform.ts @@ -4,5 +4,3 @@ export enum IterablePushPlatform { production = 1, auto = 2, } - -export default IterablePushPlatform; diff --git a/src/inApp/classes/IterableInboxMetadata.ts b/src/inApp/classes/IterableInboxMetadata.ts index 5e77f9e34..517cb7fc8 100644 --- a/src/inApp/classes/IterableInboxMetadata.ts +++ b/src/inApp/classes/IterableInboxMetadata.ts @@ -20,5 +20,3 @@ export class IterableInboxMetadata { return new IterableInboxMetadata(dict.title, dict.subtitle, dict.icon); } } - -export default IterableInboxMetadata; diff --git a/src/inApp/enums/IterableInAppCloseSource.ts b/src/inApp/enums/IterableInAppCloseSource.ts index 359a2c90e..ebd780cec 100644 --- a/src/inApp/enums/IterableInAppCloseSource.ts +++ b/src/inApp/enums/IterableInAppCloseSource.ts @@ -4,5 +4,3 @@ export enum IterableInAppCloseSource { link = 1, unknown = 100, } - -export default IterableInAppCloseSource; diff --git a/src/inApp/enums/IterableInAppContentType.ts b/src/inApp/enums/IterableInAppContentType.ts index c97521890..4210a8603 100644 --- a/src/inApp/enums/IterableInAppContentType.ts +++ b/src/inApp/enums/IterableInAppContentType.ts @@ -4,5 +4,3 @@ export enum IterableInAppContentType { alert = 1, banner = 2, } - -export default IterableInAppContentType; diff --git a/src/inApp/enums/IterableInAppDeleteSource.ts b/src/inApp/enums/IterableInAppDeleteSource.ts index 24a86c2e3..10ae58f5c 100644 --- a/src/inApp/enums/IterableInAppDeleteSource.ts +++ b/src/inApp/enums/IterableInAppDeleteSource.ts @@ -4,5 +4,3 @@ export enum IterableInAppDeleteSource { deleteButton = 1, unknown = 100, } - -export default IterableInAppDeleteSource; diff --git a/src/inApp/enums/IterableInAppLocation.ts b/src/inApp/enums/IterableInAppLocation.ts index 4a617c38e..bca7fb8db 100644 --- a/src/inApp/enums/IterableInAppLocation.ts +++ b/src/inApp/enums/IterableInAppLocation.ts @@ -3,5 +3,3 @@ export enum IterableInAppLocation { inApp = 0, inbox = 1, } - -export default IterableInAppLocation; diff --git a/src/inApp/enums/IterableInAppShowResponse.ts b/src/inApp/enums/IterableInAppShowResponse.ts index 420e4e0ec..a6137e2fd 100644 --- a/src/inApp/enums/IterableInAppShowResponse.ts +++ b/src/inApp/enums/IterableInAppShowResponse.ts @@ -5,5 +5,3 @@ export enum IterableInAppShowResponse { /** Skip showing in-app */ skip = 1, } - -export default IterableInAppShowResponse; diff --git a/src/inApp/enums/IterableInAppTriggerType.ts b/src/inApp/enums/IterableInAppTriggerType.ts index 416043daa..4f1719a74 100644 --- a/src/inApp/enums/IterableInAppTriggerType.ts +++ b/src/inApp/enums/IterableInAppTriggerType.ts @@ -7,5 +7,3 @@ export enum IterableInAppTriggerType { /** Do not display the in-app automatically via the SDK */ never = 2, } - -export default IterableInAppTriggerType;