Skip to content

Commit efb72a6

Browse files
committed
refactor: replace RNIterableAPI references with IterableApi
1 parent 4da6aa0 commit efb72a6

3 files changed

Lines changed: 42 additions & 46 deletions

File tree

src/core/classes/IterableAuthManager.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
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.
66
*
77
* @example
88
* ```typescript
9-
* const config = new IterableConfig();
10-
* const logger = new IterableLogger(config);
11-
* const authManager = new IterableAuthManager(logger);
9+
* const authManager = new IterableAuthManager();
1210
* ```
1311
*/
1412
export class IterableAuthManager {
@@ -24,7 +22,7 @@ export class IterableAuthManager {
2422
* ```
2523
*/
2624
pauseAuthRetries(pauseRetry: boolean) {
27-
return RNIterableAPI.pauseAuthRetries(pauseRetry);
25+
return IterableApi.pauseAuthRetries(pauseRetry);
2826
}
2927

3028
/**
@@ -35,6 +33,6 @@ export class IterableAuthManager {
3533
passAlongAuthToken(
3634
authToken: string | null | undefined
3735
): Promise<IterableAuthResponse | string | undefined> {
38-
return RNIterableAPI.passAlongAuthToken(authToken);
36+
return IterableApi.passAlongAuthToken(authToken);
3937
}
4038
}

src/inApp/classes/IterableInAppManager.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RNIterableAPI } from '../../api';
2-
import { Iterable } from '../../core/classes/Iterable';
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,9 @@ export class IterableInAppManager {
3346
* @returns A Promise that resolves to an array of in-app messages.
3447
*/
3548
getMessages(): Promise<IterableInAppMessage[]> {
36-
Iterable?.logger?.log('InAppManager.getMessages');
37-
38-
return RNIterableAPI.getInAppMessages() as unknown as Promise<IterableInAppMessage[]>;
49+
return IterableApi.getInAppMessages() as unknown as Promise<
50+
IterableInAppMessage[]
51+
>;
3952
}
4053

4154
/**
@@ -56,9 +69,9 @@ export class IterableInAppManager {
5669
* @returns A Promise that resolves to an array of messages marked as `saveToInbox`.
5770
*/
5871
getInboxMessages(): Promise<IterableInAppMessage[]> {
59-
Iterable?.logger?.log('InAppManager.getInboxMessages');
60-
61-
return RNIterableAPI.getInboxMessages() as unknown as Promise<IterableInAppMessage[]>;
72+
return IterableApi.getInboxMessages() as unknown as Promise<
73+
IterableInAppMessage[]
74+
>;
6275
}
6376

6477
/**
@@ -83,9 +96,7 @@ export class IterableInAppManager {
8396
message: IterableInAppMessage,
8497
consume: boolean
8598
): Promise<string | null> {
86-
Iterable?.logger?.log('InAppManager.show');
87-
88-
return RNIterableAPI.showMessage(message.messageId, consume);
99+
return IterableApi.showMessage(message.messageId, consume);
89100
}
90101

91102
/**
@@ -111,9 +122,7 @@ export class IterableInAppManager {
111122
location: IterableInAppLocation,
112123
source: IterableInAppDeleteSource
113124
): void {
114-
Iterable?.logger?.log('InAppManager.remove');
115-
116-
return RNIterableAPI.removeMessage(message.messageId, location, source);
125+
return IterableApi.removeMessage(message.messageId, location, source);
117126
}
118127

119128
/**
@@ -128,9 +137,7 @@ export class IterableInAppManager {
128137
* ```
129138
*/
130139
setReadForMessage(message: IterableInAppMessage, read: boolean) {
131-
Iterable?.logger?.log('InAppManager.setRead');
132-
133-
RNIterableAPI.setReadForMessage(message.messageId, read);
140+
return IterableApi.setReadForMessage(message.messageId, read);
134141
}
135142

136143
/**
@@ -148,9 +155,7 @@ export class IterableInAppManager {
148155
getHtmlContentForMessage(
149156
message: IterableInAppMessage
150157
): Promise<IterableHtmlInAppContent> {
151-
Iterable?.logger?.log('InAppManager.getHtmlContentForMessage');
152-
153-
return RNIterableAPI.getHtmlInAppContentForMessage(message.messageId) as unknown as Promise<IterableHtmlInAppContent>;
158+
return IterableApi.getHtmlInAppContentForMessage(message.messageId);
154159
}
155160

156161
/**
@@ -168,8 +173,6 @@ export class IterableInAppManager {
168173
* ```
169174
*/
170175
setAutoDisplayPaused(paused: boolean) {
171-
Iterable?.logger?.log('InAppManager.setAutoDisplayPaused');
172-
173-
RNIterableAPI.setAutoDisplayPaused(paused);
176+
return IterableApi.setAutoDisplayPaused(paused);
174177
}
175178
}

src/inbox/classes/IterableInboxDataModel.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RNIterableAPI } from '../../api';
2-
import { Iterable } from '../../core/classes/Iterable';
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-
Iterable?.logger?.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-
Iterable?.logger?.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-
Iterable?.logger?.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,7 +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(visibleRows as unknown as { [key: string]: string | number | boolean }[]);
149+
return IterableApi.startSession(visibleRows);
155150
}
156151

157152
/**
@@ -162,7 +157,7 @@ export class IterableInboxDataModel {
162157
*/
163158
async endSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
164159
await this.updateVisibleRows(visibleRows);
165-
RNIterableAPI.endSession();
160+
return IterableApi.endSession();
166161
}
167162

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

184179
/**

0 commit comments

Comments
 (0)