Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
9be2327
refactor: streamline logging in Iterable class and enhance IterableLo…
lposen Oct 10, 2025
de4db13
refactor: remove IterableLogger instantiation from tests and clean up…
lposen Oct 10, 2025
3990876
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen Oct 10, 2025
cbd2799
refactor: enable logging in IterableApi methods by removing commented…
lposen Oct 10, 2025
2025291
test: add comprehensive unit tests for IterableLogger functionality
lposen Oct 10, 2025
307326e
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen Oct 10, 2025
0af6532
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen Oct 10, 2025
2fa18f8
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen Oct 14, 2025
644c510
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen Oct 14, 2025
a693494
docs: enhance IterableLogger documentation with descriptions and exa…
lposen Oct 14, 2025
54f4626
Merge branch 'jwt/MOB-12298-new-improve-logger' of github.com:Iterabl…
lposen Oct 14, 2025
a4bd708
Merge branch 'jwt/master' into jwt/MOB-12298-new-improve-logger
lposen Oct 17, 2025
c0a2c20
docs: removed a TODO and enhanced documentation for IterableLogger
lposen Oct 17, 2025
e06edab
Merge branch 'jwt/master' into jwt/MOB-12298-new-improve-logger
lposen Oct 17, 2025
6828a7a
fix: change default log level from info to debug in IterableConfig
lposen Oct 17, 2025
e2c6148
refactor: update default log level to debug in IterableLogger and rel…
lposen Oct 17, 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
19 changes: 10 additions & 9 deletions src/__tests__/IterableInApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { NativeEventEmitter } from 'react-native';

import { IterableLogger } from '../core';

import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI';

import {
Expand All @@ -21,7 +19,6 @@ import {
describe('Iterable In App', () => {
beforeEach(() => {
jest.clearAllMocks();
Iterable.logger = new IterableLogger(new IterableConfig());
});

test('trackInAppOpen_params_methodCalledWithParams', () => {
Expand Down Expand Up @@ -202,9 +199,11 @@ describe('Iterable In App', () => {
// WHEN the simulated local queue is set to the in-app messages
MockRNIterableAPI.setMessages(messages);
// THEN Iterable.inAppManager.getMessages returns the list of in-app messages
return await Iterable.inAppManager?.getMessages().then((messagesObtained) => {
expect(messagesObtained).toEqual(messages);
});
return await Iterable.inAppManager
?.getMessages()
.then((messagesObtained) => {
expect(messagesObtained).toEqual(messages);
});
});

test('showMessage_messageAndConsume_returnsClickedUrl', async () => {
Expand All @@ -222,9 +221,11 @@ describe('Iterable In App', () => {
// WHEN the simulated clicked url is set to the clicked url
MockRNIterableAPI.setClickedUrl(clickedUrl);
// THEN Iterable,inAppManager.showMessage returns the simulated clicked url
return await Iterable.inAppManager?.showMessage(message, consume).then((url) => {
expect(url).toEqual(clickedUrl);
});
return await Iterable.inAppManager
?.showMessage(message, consume)
.then((url) => {
expect(url).toEqual(clickedUrl);
});
});

test('removeMessage_params_methodCalledWithParams', () => {
Expand Down
21 changes: 6 additions & 15 deletions src/core/classes/Iterable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,32 @@ import { NativeEventEmitter, Platform } from 'react-native';

import { MockLinking } from '../../__mocks__/MockLinking';
import { MockRNIterableAPI } from '../../__mocks__/MockRNIterableAPI';
import { IterableLogger } from '..';
// import from the same location that consumers import from
import {
Iterable,
IterableAction,
IterableActionContext,
IterableActionSource,
IterableAttributionInfo,
IterableAuthResponse,
IterableCommerceItem,
IterableConfig,
IterableDataRegion,
IterableEventName,
IterableLogLevel,
IterableInAppMessage,
IterableInAppCloseSource,
IterableInAppDeleteSource,
IterableInAppLocation,
IterableInAppMessage,
IterableInAppShowResponse,
IterableInAppTrigger,
IterableInAppTriggerType,
IterableAuthResponse,
IterableInAppShowResponse,
IterableLogLevel,
} from '../..';
import { TestHelper } from '../../__tests__/TestHelper';

const getDefaultConfig = () => {
const config = new IterableConfig();
config.logReactNativeSdkCalls = false;
return config;
};

describe('Iterable', () => {
beforeEach(() => {
jest.clearAllMocks();
const config = getDefaultConfig();
Iterable.logger = new IterableLogger(config);
});

afterEach(() => {
Expand Down Expand Up @@ -265,7 +256,7 @@ describe('Iterable', () => {
expect(config.customActionHandler).toBe(undefined);
expect(config.inAppHandler).toBe(undefined);
expect(config.authHandler).toBe(undefined);
expect(config.logLevel).toBe(IterableLogLevel.info);
expect(config.logLevel).toBe(IterableLogLevel.debug);
expect(config.logReactNativeSdkCalls).toBe(true);
expect(config.expiringAuthTokenRefreshPeriod).toBe(60.0);
expect(config.allowedProtocols).toEqual([]);
Expand All @@ -281,7 +272,7 @@ describe('Iterable', () => {
expect(configDict.customActionHandlerPresent).toBe(false);
expect(configDict.inAppHandlerPresent).toBe(false);
expect(configDict.authHandlerPresent).toBe(false);
expect(configDict.logLevel).toBe(IterableLogLevel.info);
expect(configDict.logLevel).toBe(IterableLogLevel.debug);
expect(configDict.expiringAuthTokenRefreshPeriod).toBe(60.0);
expect(configDict.allowedProtocols).toEqual([]);
expect(configDict.androidSdkUseInMemoryStorageForInApps).toBe(false);
Expand Down
45 changes: 24 additions & 21 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);
*/
/* eslint-enable tsdoc/syntax */
export class Iterable {
/**
* Logger for the Iterable SDK
* Log level is set with {@link IterableLogLevel}
*/
static logger: IterableLogger = new IterableLogger(new IterableConfig());

/**
* Current configuration of the Iterable SDK
*/
Expand Down Expand Up @@ -121,9 +115,7 @@ export class Iterable {
config: IterableConfig = new IterableConfig()
): Promise<boolean> {
Iterable.savedConfig = config;
Iterable.logger = new IterableLogger(Iterable.savedConfig);

this.setupEventHandlers();
this.setupIterable(config);

const version = this.getVersionFromPackageJson();

Expand All @@ -141,10 +133,7 @@ export class Iterable {
config: IterableConfig = new IterableConfig(),
apiEndPoint: string
): Promise<boolean> {
Iterable.savedConfig = config;
Iterable.logger = new IterableLogger(Iterable.savedConfig);

this.setupEventHandlers();
this.setupIterable(config);

const version = this.getVersionFromPackageJson();

Expand All @@ -155,6 +144,22 @@ export class Iterable {
});
}

/**
* @internal
* Does basic setup of the Iterable SDK.
* @param config - The configuration object for the Iterable SDK
*/
private static setupIterable(config: IterableConfig = new IterableConfig()) {
if (config) {
Iterable.savedConfig = config;

IterableLogger.setLoggingEnabled(config.logReactNativeSdkCalls ?? true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So whats the two log config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two config values that are set are:

  1. Whether anything is going to be logged at all (config.logReactNativeSdkCalls --> IterableLogger.loggingEnabled)
  2. If things are being logged, how granular those logs are going to be (config.logLevel --> IterableLogger.logLevel)

I think that's what you were asking. Let me know if I misinterpreted the question.

IterableLogger.setLogLevel(config.logLevel);
}

this.setupEventHandlers();
}

/**
* Associate the current user with the passed in email parameter.
*
Expand Down Expand Up @@ -502,7 +507,7 @@ export class Iterable {
items: IterableCommerceItem[],
dataFields?: unknown
) {
Iterable?.logger?.log('trackPurchase');
IterableLogger?.log('trackPurchase');

IterableApi.trackPurchase({ total, items, dataFields });
}
Expand Down Expand Up @@ -531,7 +536,7 @@ export class Iterable {
location: IterableInAppLocation
) {
if (!message?.messageId) {
Iterable?.logger?.log(
IterableLogger?.log(
`Skipping trackInAppOpen because message ID is required, but received ${message}.`
);
return;
Expand Down Expand Up @@ -968,9 +973,7 @@ export class Iterable {
(promiseResult as IterableAuthResponse).failureCallback?.();
}
} else {
Iterable?.logger?.log(
'No callback received from native layer'
);
IterableLogger?.log('No callback received from native layer');
}
}, 1000);
// Use unref() to prevent the timeout from keeping the process alive
Expand All @@ -979,12 +982,12 @@ export class Iterable {
//If promise only returns string
Iterable.authManager.passAlongAuthToken(promiseResult as string);
} else {
Iterable?.logger?.log(
IterableLogger?.log(
'Unexpected promise returned. Auth token expects promise of String or AuthResponse type.'
);
}
})
.catch((e) => Iterable?.logger?.log(e));
.catch((e) => IterableLogger?.log(e));
});

RNEventEmitter.addListener(
Expand Down Expand Up @@ -1018,7 +1021,7 @@ export class Iterable {
}
})
.catch((reason) => {
Iterable?.logger?.log('could not open url: ' + reason);
IterableLogger?.log('could not open url: ' + reason);
});
}
}
Expand Down
Loading
Loading