forked from Iterable/react-native-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeRNIterableAPI.ts
More file actions
183 lines (163 loc) · 5.29 KB
/
NativeRNIterableAPI.ts
File metadata and controls
183 lines (163 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// NOTE: No types can be imported because of the way new arch works, so we have
// to re-define the types here.
interface EmbeddedMessage {
metadata: {
messageId: string;
placementId: number;
campaignId?: number | null;
isProof?: boolean;
};
elements: {
buttons?:
| {
id: string;
title?: string | null;
action: { type: string; data?: string } | null;
}[]
| null;
body?: string | null;
mediaUrl?: string | null;
mediaUrlCaption?: string | null;
defaultAction?: { type: string; data?: string } | null;
text?: { id: string; text?: string | null; label?: string | null }[] | null;
title?: string | null;
} | null;
payload?: { [key: string]: string | number | boolean | null } | null;
}
export interface Spec extends TurboModule {
// Initialization
initializeWithApiKey(
apiKey: string,
config: { [key: string]: string | number | boolean | undefined | string[] },
version: string
): Promise<boolean>;
initialize2WithApiKey(
apiKey: string,
config: { [key: string]: string | number | boolean | undefined | string[] },
version: string,
apiEndPointOverride: string
): Promise<boolean>;
// User management
setEmail(email: string | null, authToken?: string | null): void;
getEmail(): Promise<string | null>;
setUserId(userId?: string | null, authToken?: string | null): void;
getUserId(): Promise<string | null | undefined>;
// In-app messaging
setInAppShowResponse(number: number): void;
getInAppMessages(): Promise<{ [key: string]: string | number | boolean }[]>;
getInboxMessages(): Promise<{ [key: string]: string | number | boolean }[]>;
getUnreadInboxMessagesCount(): Promise<number>;
showMessage(messageId: string, consume: boolean): Promise<string | null>;
removeMessage(messageId: string, location: number, source: number): void;
setReadForMessage(messageId: string, read: boolean): void;
setAutoDisplayPaused(autoDisplayPaused: boolean): void;
// Tracking
trackEvent(
name: string,
dataFields?: { [key: string]: string | number | boolean }
): void;
trackPushOpenWithCampaignId(
campaignId: number,
templateId: number | null,
messageId: string,
appAlreadyRunning: boolean,
dataFields?: { [key: string]: string | number | boolean }
): void;
trackInAppOpen(messageId: string, location: number): void;
trackInAppClick(
messageId: string,
location: number,
clickedUrl: string
): void;
trackInAppClose(
messageId: string,
location: number,
source: number,
clickedUrl?: string | null
): void;
inAppConsume(messageId: string, location: number, source: number): void;
// Commerce
updateCart(items: { [key: string]: string | number | boolean }[]): void;
trackPurchase(
total: number,
items: { [key: string]: string | number | boolean }[],
dataFields?: { [key: string]: string | number | boolean }
): void;
// User data
updateUser(
dataFields: { [key: string]: string | number | boolean },
mergeNestedObjects: boolean
): void;
updateEmail(email: string, authToken?: string): void;
// Attribution
getAttributionInfo(): Promise<{
[key: string]: string | number | boolean;
} | null>;
setAttributionInfo(
dict: { [key: string]: string | number | boolean } | null
): void;
// Device management
disableDeviceForCurrentUser(): void;
registerForPush(): void;
getLastPushPayload(): Promise<{
[key: string]: string | number | boolean;
} | null>;
// Content
getHtmlInAppContentForMessage(
messageId: string
): Promise<{ [key: string]: string | number | boolean }>;
// App links
handleAppLink(appLink: string): Promise<boolean>;
// Subscriptions
updateSubscriptions(
emailListIds: number[] | null,
unsubscribedChannelIds: number[] | null,
unsubscribedMessageTypeIds: number[] | null,
subscribedMessageTypeIds: number[] | null,
campaignId: number,
templateId: number
): void;
// Session tracking
startSession(
visibleRows: { [key: string]: string | number | boolean }[]
): void;
endSession(): void;
updateVisibleRows(
visibleRows: { [key: string]: string | number | boolean }[]
): void;
// Auth
passAlongAuthToken(authToken?: string | null): void;
pauseAuthRetries(pauseRetry: boolean): void;
// Embedded Messaging
syncEmbeddedMessages(): void;
startEmbeddedSession(): void;
endEmbeddedSession(): void;
startEmbeddedImpression(messageId: string, placementId: number): void;
pauseEmbeddedImpression(messageId: string): void;
getEmbeddedMessages(
placementIds: number[] | null
): Promise<EmbeddedMessage[]>;
trackEmbeddedClick(
message: EmbeddedMessage,
buttonId: string | null,
clickedUrl: string | null
): void;
// Wake app -- android only
wakeApp(): void;
// REQUIRED for RCTEventEmitter
addListener(eventName: string): void;
removeListeners(count: number): void;
}
// Check if we're in a test environment
const isTestEnvironment = () => {
return (
typeof jest !== 'undefined' ||
process.env.NODE_ENV === 'test' ||
process.env.JEST_WORKER_ID !== undefined
);
};
export default isTestEnvironment()
? undefined
: TurboModuleRegistry.getEnforcing<Spec>('RNIterableAPI');