Skip to content

Commit 3990876

Browse files
committed
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls' into jwt/MOB-12298-new-improve-logger
2 parents de4db13 + efb72a6 commit 3990876

3 files changed

Lines changed: 37 additions & 49 deletions

File tree

src/core/classes/IterableAuthManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import RNIterableAPI from '../../api';
21
import { IterableAuthResponse } from './IterableAuthResponse';
2+
import { IterableApi } from './IterableApi';
33

44
/**
55
* Manages the authentication for the Iterable SDK.
@@ -22,7 +22,7 @@ export class IterableAuthManager {
2222
* ```
2323
*/
2424
pauseAuthRetries(pauseRetry: boolean) {
25-
return RNIterableAPI.pauseAuthRetries(pauseRetry);
25+
return IterableApi.pauseAuthRetries(pauseRetry);
2626
}
2727

2828
/**
@@ -33,6 +33,6 @@ export class IterableAuthManager {
3333
passAlongAuthToken(
3434
authToken: string | null | undefined
3535
): Promise<IterableAuthResponse | string | undefined> {
36-
return RNIterableAPI.passAlongAuthToken(authToken);
36+
return IterableApi.passAlongAuthToken(authToken);
3737
}
3838
}

src/inApp/classes/IterableInAppManager.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RNIterableAPI } from '../../api';
2-
import { IterableLogger } from '../../core/classes/IterableLogger';
1+
import { IterableApi } from '../../core/classes/IterableApi';
32
import type {
43
IterableInAppDeleteSource,
54
IterableInAppLocation,
@@ -14,6 +13,20 @@ import { IterableInAppMessage } from './IterableInAppMessage';
1413
* displaying messages, removing messages, setting read status, and more.
1514
*
1615
* The `inAppManager` property of an `Iterable` instance is set to an instance of this class.
16+
*
17+
* @example
18+
* ```typescript
19+
* const inAppManager = new IterableInAppManager();
20+
*
21+
* inAppManager.getMessages().then(messages => {
22+
* console.log('Messages:', messages);
23+
* });
24+
*
25+
* // You can also access an instance on `Iterable.inAppManager.inAppManager`
26+
* Iterable.inAppManager.getMessages().then(messages => {
27+
* console.log('Messages:', messages);
28+
* });
29+
* ```
1730
*/
1831
export class IterableInAppManager {
1932
/**
@@ -33,9 +46,7 @@ export class IterableInAppManager {
3346
* @returns A Promise that resolves to an array of in-app messages.
3447
*/
3548
getMessages(): Promise<IterableInAppMessage[]> {
36-
IterableLogger?.log('InAppManager.getMessages');
37-
38-
return RNIterableAPI.getInAppMessages() as unknown as Promise<
49+
return IterableApi.getInAppMessages() as unknown as Promise<
3950
IterableInAppMessage[]
4051
>;
4152
}
@@ -58,9 +69,7 @@ export class IterableInAppManager {
5869
* @returns A Promise that resolves to an array of messages marked as `saveToInbox`.
5970
*/
6071
getInboxMessages(): Promise<IterableInAppMessage[]> {
61-
IterableLogger?.log('InAppManager.getInboxMessages');
62-
63-
return RNIterableAPI.getInboxMessages() as unknown as Promise<
72+
return IterableApi.getInboxMessages() as unknown as Promise<
6473
IterableInAppMessage[]
6574
>;
6675
}
@@ -87,9 +96,7 @@ export class IterableInAppManager {
8796
message: IterableInAppMessage,
8897
consume: boolean
8998
): Promise<string | null> {
90-
IterableLogger?.log('InAppManager.show');
91-
92-
return RNIterableAPI.showMessage(message.messageId, consume);
99+
return IterableApi.showMessage(message.messageId, consume);
93100
}
94101

95102
/**
@@ -115,9 +122,7 @@ export class IterableInAppManager {
115122
location: IterableInAppLocation,
116123
source: IterableInAppDeleteSource
117124
): void {
118-
IterableLogger?.log('InAppManager.remove');
119-
120-
return RNIterableAPI.removeMessage(message.messageId, location, source);
125+
return IterableApi.removeMessage(message.messageId, location, source);
121126
}
122127

123128
/**
@@ -132,9 +137,7 @@ export class IterableInAppManager {
132137
* ```
133138
*/
134139
setReadForMessage(message: IterableInAppMessage, read: boolean) {
135-
IterableLogger?.log('InAppManager.setRead');
136-
137-
RNIterableAPI.setReadForMessage(message.messageId, read);
140+
return IterableApi.setReadForMessage(message.messageId, read);
138141
}
139142

140143
/**
@@ -152,11 +155,7 @@ export class IterableInAppManager {
152155
getHtmlContentForMessage(
153156
message: IterableInAppMessage
154157
): Promise<IterableHtmlInAppContent> {
155-
IterableLogger?.log('InAppManager.getHtmlContentForMessage');
156-
157-
return RNIterableAPI.getHtmlInAppContentForMessage(
158-
message.messageId
159-
) as unknown as Promise<IterableHtmlInAppContent>;
158+
return IterableApi.getHtmlInAppContentForMessage(message.messageId);
160159
}
161160

162161
/**
@@ -174,8 +173,6 @@ export class IterableInAppManager {
174173
* ```
175174
*/
176175
setAutoDisplayPaused(paused: boolean) {
177-
IterableLogger?.log('InAppManager.setAutoDisplayPaused');
178-
179-
RNIterableAPI.setAutoDisplayPaused(paused);
176+
return IterableApi.setAutoDisplayPaused(paused);
180177
}
181178
}

src/inbox/classes/IterableInboxDataModel.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RNIterableAPI } from '../../api';
2-
import { IterableLogger } from '../../core/classes/IterableLogger';
1+
import { IterableApi } from '../../core/classes/IterableApi';
32
import {
43
IterableHtmlInAppContent,
54
IterableInAppDeleteSource,
@@ -94,11 +93,7 @@ export class IterableInboxDataModel {
9493
* @returns A promise that resolves to the HTML content of the specified message.
9594
*/
9695
getHtmlContentForMessageId(id: string): Promise<IterableHtmlInAppContent> {
97-
IterableLogger?.log(
98-
'IterableInboxDataModel.getHtmlContentForItem messageId: ' + id
99-
);
100-
101-
return RNIterableAPI.getHtmlInAppContentForMessage(id).then(
96+
return IterableApi.getHtmlInAppContentForMessage(id).then(
10297
(content: IterableHtmlInAppContentRaw) => {
10398
return IterableHtmlInAppContent.fromDict(content);
10499
}
@@ -111,9 +106,7 @@ export class IterableInboxDataModel {
111106
* @param id - The unique identifier of the message to be marked as read.
112107
*/
113108
setMessageAsRead(id: string) {
114-
IterableLogger?.log('IterableInboxDataModel.setMessageAsRead');
115-
116-
RNIterableAPI.setReadForMessage(id, true);
109+
return IterableApi.setReadForMessage(id, true);
117110
}
118111

119112
/**
@@ -123,9 +116,11 @@ export class IterableInboxDataModel {
123116
* @param deleteSource - The source from which the delete action is initiated.
124117
*/
125118
deleteItemById(id: string, deleteSource: IterableInAppDeleteSource) {
126-
IterableLogger?.log('IterableInboxDataModel.deleteItemById');
127-
128-
RNIterableAPI.removeMessage(id, IterableInAppLocation.inbox, deleteSource);
119+
return IterableApi.removeMessage(
120+
id,
121+
IterableInAppLocation.inbox,
122+
deleteSource
123+
);
129124
}
130125

131126
/**
@@ -135,7 +130,7 @@ export class IterableInboxDataModel {
135130
* If the fetch operation fails, the promise resolves to an empty array.
136131
*/
137132
async refresh(): Promise<IterableInboxRowViewModel[]> {
138-
return RNIterableAPI.getInboxMessages().then(
133+
return IterableApi.getInboxMessages().then(
139134
(messages: IterableInAppMessage[]) => {
140135
return this.processMessages(messages);
141136
},
@@ -151,9 +146,7 @@ export class IterableInboxDataModel {
151146
* @param visibleRows - An array of `IterableInboxImpressionRowInfo` objects representing the rows that are currently visible.
152147
*/
153148
startSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
154-
RNIterableAPI.startSession(
155-
visibleRows as unknown as { [key: string]: string | number | boolean }[]
156-
);
149+
return IterableApi.startSession(visibleRows);
157150
}
158151

159152
/**
@@ -164,7 +157,7 @@ export class IterableInboxDataModel {
164157
*/
165158
async endSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
166159
await this.updateVisibleRows(visibleRows);
167-
RNIterableAPI.endSession();
160+
return IterableApi.endSession();
168161
}
169162

170163
/**
@@ -180,9 +173,7 @@ export class IterableInboxDataModel {
180173
* Defaults to an empty array if not provided.
181174
*/
182175
updateVisibleRows(visibleRows: IterableInboxImpressionRowInfo[] = []) {
183-
RNIterableAPI.updateVisibleRows(
184-
visibleRows as unknown as { [key: string]: string | number | boolean }[]
185-
);
176+
return IterableApi.updateVisibleRows(visibleRows);
186177
}
187178

188179
/**

0 commit comments

Comments
 (0)