Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e78a6ea
feat: refactor Iterable class and introduce IterableApi for improved …
lposen Oct 7, 2025
1ff7740
feat: add authManager to Iterable class
lposen Oct 7, 2025
1a8fa41
refactor: replace RNIterableAPI calls with IterableApi methods
lposen Oct 7, 2025
72d066a
docs: replace RNIterableAPI with IterableApi in IterableInAppManager
lposen Oct 7, 2025
510c581
refactor: integrate IterableApi methods in IterableInboxDataModel
lposen Oct 7, 2025
564bcbd
docs: enhance IterableApi documentation with detailed method descript…
lposen Oct 7, 2025
8aa92c1
Merge branch 'jwt/MOB-11032-task-4-ios-bridge-retrypolicy-and-authfai…
lposen Oct 9, 2025
2e9d116
Merge branch 'jwt/MOB-11032-task-4-ios-bridge-retrypolicy-and-authfai…
lposen Oct 9, 2025
a9f46c1
refactor: remove default constants module and instantiate defaults di…
lposen Oct 9, 2025
01c7919
refactor: instantiate IterableInAppManager and IterableAuthManager di…
lposen Oct 9, 2025
382164d
refactor: remove circular dependency comments in Iterable class
lposen Oct 9, 2025
a7ff561
chore: add circular dependency check script to package.json
lposen Oct 9, 2025
eb2c376
refactor: remove unnecessary type-only import to simplify Iterable class
lposen Oct 10, 2025
b10097a
refactor: streamline logging by removing logger instances and using s…
lposen Oct 10, 2025
b776414
test: add comprehensive tests for IterableLogger class, addressing lo…
lposen Oct 10, 2025
65cb551
feat: add authentication manager to Iterable class
lposen Oct 10, 2025
5bbb5fc
refactor: remove pauseAuthRetries method from Iterable class
lposen Oct 10, 2025
92fbff1
chore: disable TSDoc syntax rule for IterableRetryBackoff enum
lposen Oct 10, 2025
e94100f
feat: add pauseAuthRetries method to authentication manager and enhan…
lposen Oct 10, 2025
5e4e579
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen Oct 10, 2025
3737d57
fix: improve null safety in IterableInAppMessage.fromViewToken method
lposen Oct 10, 2025
2d6c381
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen Oct 10, 2025
c6b62d0
refactor: remove instantiation of IterableInAppManager and IterableAu…
lposen Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 76 additions & 159 deletions src/core/classes/Iterable.ts

Large diffs are not rendered by default.

600 changes: 600 additions & 0 deletions src/core/classes/IterableApi.ts

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/core/classes/IterableAuthManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defaultLogger } from '../constants/defaults';
import { IterableLogger } from './IterableLogger';
import { IterableApi } from './IterableApi';

/**
* Manages the authentication for the Iterable SDK.
*
* @example
* ```typescript
* const config = new IterableConfig();
* const logger = new IterableLogger(config);
* const authManager = new IterableAuthManager(logger);
* ```
*/
export class IterableAuthManager {
/**
* The logger for the Iterable SDK.
*/
static logger: IterableLogger = defaultLogger;

constructor(logger: IterableLogger) {
IterableAuthManager.logger = logger;
}

/**
* Pause the authentication retry mechanism.
*
* @param pauseRetry - Whether to pause the authentication retry mechanism
*
* @example
* ```typescript
* const authManager = new IterableAuthManager();
* authManager.pauseAuthRetries(true);
* ```
*/
pauseAuthRetries(pauseRetry: boolean) {
return IterableApi.pauseAuthRetries(pauseRetry);
}
}
6 changes: 4 additions & 2 deletions src/core/classes/IterableLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { IterableConfig } from './IterableConfig';
*
* This class is responsible for logging messages based on the configuration provided.
*
* TODO: add a logLevel property to the IterableLogger class to control the level of logging.
*
* @remarks
* The logging behavior is controlled by the `logReactNativeSdkCalls` property
* in {@link IterableConfig}.
Expand Down Expand Up @@ -39,13 +41,13 @@ export class IterableLogger {
*
* @param message - The message to be logged.
*/
log(message: string) {
log(message?: unknown, ...optionalParams: unknown[]) {
// default to `true` in the case of unit testing where `Iterable` is not initialized
// which is most likely in a debug environment anyways
const loggingEnabled = this.config.logReactNativeSdkCalls ?? true;

if (loggingEnabled) {
console.log(message);
console.log(message, ...optionalParams);
}
}
}
9 changes: 9 additions & 0 deletions src/core/constants/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IterableInAppManager } from '../../inApp/classes/IterableInAppManager';
import { IterableAuthManager } from '../classes/IterableAuthManager';
import { IterableConfig } from '../classes/IterableConfig';
import { IterableLogger } from '../classes/IterableLogger';

export const defaultConfig = new IterableConfig();
export const defaultLogger = new IterableLogger(defaultConfig);
export const defaultInAppManager = new IterableInAppManager(defaultLogger);
export const defaultAuthManager = new IterableAuthManager(defaultLogger);
Empty file added src/core/constants/index.ts
Empty file.
65 changes: 36 additions & 29 deletions src/inApp/classes/IterableInAppManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { RNIterableAPI } from '../../api';
import { Iterable } from '../../core/classes/Iterable';
import type {
IterableInAppDeleteSource,
IterableInAppLocation,
} from '../enums';
import { IterableHtmlInAppContent } from './IterableHtmlInAppContent';
import { IterableInAppMessage } from './IterableInAppMessage';
import { IterableApi } from '../../core/classes/IterableApi';
import { IterableLogger } from '../../core/classes/IterableLogger';
import { defaultLogger } from '../../core/constants/defaults';
import type { IterableInAppDeleteSource } from '../enums/IterableInAppDeleteSource';
import type { IterableInAppLocation } from '../enums/IterableInAppLocation';
import type { IterableHtmlInAppContent } from './IterableHtmlInAppContent';
import type { IterableInAppMessage } from './IterableInAppMessage';

/**
* Manages in-app messages for the current user.
Expand All @@ -14,8 +13,24 @@ import { IterableInAppMessage } from './IterableInAppMessage';
* displaying messages, removing messages, setting read status, and more.
*
* The `inAppManager` property of an `Iterable` instance is set to an instance of this class.
*
* @example
* ```typescript
* const config = new IterableConfig();
* const logger = new IterableLogger(config);
* const inAppManager = new IterableInAppManager(logger);
* ```
*/
export class IterableInAppManager {
/**
* The logger for the Iterable SDK.
*/
static logger: IterableLogger = defaultLogger;

constructor(logger: IterableLogger) {
IterableInAppManager.logger = logger;
}

/**
* Retrieve the current user's list of in-app messages stored in the local queue.
*
Expand All @@ -33,9 +48,9 @@ export class IterableInAppManager {
* @returns A Promise that resolves to an array of in-app messages.
*/
getMessages(): Promise<IterableInAppMessage[]> {
Iterable?.logger?.log('InAppManager.getMessages');

return RNIterableAPI.getInAppMessages() as unknown as Promise<IterableInAppMessage[]>;
return IterableApi.getInAppMessages() as unknown as Promise<
IterableInAppMessage[]
>;
}

/**
Expand All @@ -56,9 +71,9 @@ export class IterableInAppManager {
* @returns A Promise that resolves to an array of messages marked as `saveToInbox`.
*/
getInboxMessages(): Promise<IterableInAppMessage[]> {
Iterable?.logger?.log('InAppManager.getInboxMessages');

return RNIterableAPI.getInboxMessages() as unknown as Promise<IterableInAppMessage[]>;
return IterableApi.getInboxMessages() as unknown as Promise<
IterableInAppMessage[]
>;
}

/**
Expand All @@ -83,9 +98,7 @@ export class IterableInAppManager {
message: IterableInAppMessage,
consume: boolean
): Promise<string | null> {
Iterable?.logger?.log('InAppManager.show');

return RNIterableAPI.showMessage(message.messageId, consume);
return IterableApi.showMessage(message.messageId, consume);
}

/**
Expand All @@ -111,9 +124,7 @@ export class IterableInAppManager {
location: IterableInAppLocation,
source: IterableInAppDeleteSource
): void {
Iterable?.logger?.log('InAppManager.remove');

return RNIterableAPI.removeMessage(message.messageId, location, source);
return IterableApi.removeMessage(message.messageId, location, source);
}

/**
Expand All @@ -128,9 +139,7 @@ export class IterableInAppManager {
* ```
*/
setReadForMessage(message: IterableInAppMessage, read: boolean) {
Iterable?.logger?.log('InAppManager.setRead');

RNIterableAPI.setReadForMessage(message.messageId, read);
return IterableApi.setReadForMessage(message.messageId, read);
}

/**
Expand All @@ -148,9 +157,9 @@ export class IterableInAppManager {
getHtmlContentForMessage(
message: IterableInAppMessage
): Promise<IterableHtmlInAppContent> {
Iterable?.logger?.log('InAppManager.getHtmlContentForMessage');

return RNIterableAPI.getHtmlInAppContentForMessage(message.messageId) as unknown as Promise<IterableHtmlInAppContent>;
return IterableApi.getHtmlInAppContentForMessage(
message.messageId
) as unknown as Promise<IterableHtmlInAppContent>;
}

/**
Expand All @@ -168,8 +177,6 @@ export class IterableInAppManager {
* ```
*/
setAutoDisplayPaused(paused: boolean) {
Iterable?.logger?.log('InAppManager.setAutoDisplayPaused');

RNIterableAPI.setAutoDisplayPaused(paused);
return IterableApi.setAutoDisplayPaused(paused);
}
}
29 changes: 12 additions & 17 deletions src/inbox/classes/IterableInboxDataModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RNIterableAPI } from '../../api';
import { Iterable } from '../../core/classes/Iterable';
import { IterableApi } from '../../core/classes/IterableApi';
import {
IterableHtmlInAppContent,
IterableInAppDeleteSource,
Expand Down Expand Up @@ -94,11 +93,7 @@ export class IterableInboxDataModel {
* @returns A promise that resolves to the HTML content of the specified message.
*/
getHtmlContentForMessageId(id: string): Promise<IterableHtmlInAppContent> {
Iterable?.logger?.log(
'IterableInboxDataModel.getHtmlContentForItem messageId: ' + id
);

return RNIterableAPI.getHtmlInAppContentForMessage(id).then(
return IterableApi.getHtmlInAppContentForMessage(id).then(
(content: IterableHtmlInAppContentRaw) => {
return IterableHtmlInAppContent.fromDict(content);
}
Expand All @@ -111,9 +106,7 @@ export class IterableInboxDataModel {
* @param id - The unique identifier of the message to be marked as read.
*/
setMessageAsRead(id: string) {
Iterable?.logger?.log('IterableInboxDataModel.setMessageAsRead');

RNIterableAPI.setReadForMessage(id, true);
return IterableApi.setReadForMessage(id, true);
}

/**
Expand All @@ -123,9 +116,11 @@ export class IterableInboxDataModel {
* @param deleteSource - The source from which the delete action is initiated.
*/
deleteItemById(id: string, deleteSource: IterableInAppDeleteSource) {
Iterable?.logger?.log('IterableInboxDataModel.deleteItemById');

RNIterableAPI.removeMessage(id, IterableInAppLocation.inbox, deleteSource);
return IterableApi.removeMessage(
id,
IterableInAppLocation.inbox,
deleteSource
);
}

/**
Expand All @@ -135,7 +130,7 @@ export class IterableInboxDataModel {
* If the fetch operation fails, the promise resolves to an empty array.
*/
async refresh(): Promise<IterableInboxRowViewModel[]> {
return RNIterableAPI.getInboxMessages().then(
return IterableApi.getInboxMessages().then(
(messages: IterableInAppMessage[]) => {
return this.processMessages(messages);
},
Expand All @@ -151,7 +146,7 @@ export class IterableInboxDataModel {
* @param visibleRows - An array of `IterableInboxImpressionRowInfo` objects representing the rows that are currently visible.
*/
startSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
RNIterableAPI.startSession(visibleRows as unknown as { [key: string]: string | number | boolean }[]);
return IterableApi.startSession(visibleRows);
}

/**
Expand All @@ -162,7 +157,7 @@ export class IterableInboxDataModel {
*/
async endSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
await this.updateVisibleRows(visibleRows);
RNIterableAPI.endSession();
return IterableApi.endSession();
}

/**
Expand All @@ -178,7 +173,7 @@ export class IterableInboxDataModel {
* Defaults to an empty array if not provided.
*/
updateVisibleRows(visibleRows: IterableInboxImpressionRowInfo[] = []) {
RNIterableAPI.updateVisibleRows(visibleRows as unknown as { [key: string]: string | number | boolean }[]);
return IterableApi.updateVisibleRows(visibleRows);
}

/**
Expand Down
Loading