react-native-carrot-quest 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CarrotQuest.podspec +34 -0
- package/LICENSE +20 -0
- package/README.md +457 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +136 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +11 -0
- package/android/src/main/java/com/margelo/nitro/carrotquest/CarrotQuest.kt +585 -0
- package/android/src/main/java/com/margelo/nitro/carrotquest/CarrotQuestPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/carrotquest/CarrotQuestSetup.kt +472 -0
- package/ios/CarrotQuest.swift +588 -0
- package/ios/CarrotQuestSetup.swift +333 -0
- package/lib/module/CarrotQuest.nitro.js +4 -0
- package/lib/module/CarrotQuest.nitro.js.map +1 -0
- package/lib/module/carrot-quest.js +136 -0
- package/lib/module/carrot-quest.js.map +1 -0
- package/lib/module/carrot-quest.native.js +155 -0
- package/lib/module/carrot-quest.native.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/subscriptions.js +76 -0
- package/lib/module/subscriptions.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/CarrotQuest.nitro.d.ts +394 -0
- package/lib/typescript/src/CarrotQuest.nitro.d.ts.map +1 -0
- package/lib/typescript/src/carrot-quest.d.ts +37 -0
- package/lib/typescript/src/carrot-quest.d.ts.map +1 -0
- package/lib/typescript/src/carrot-quest.native.d.ts +37 -0
- package/lib/typescript/src/carrot-quest.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/subscriptions.d.ts +32 -0
- package/lib/typescript/src/subscriptions.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JCarrotQuestEventValue.cpp +30 -0
- package/nitrogen/generated/android/c++/JCarrotQuestEventValue.hpp +83 -0
- package/nitrogen/generated/android/c++/JCarrotQuestLogCategory.hpp +76 -0
- package/nitrogen/generated/android/c++/JCarrotQuestLogEntry.hpp +100 -0
- package/nitrogen/generated/android/c++/JCarrotQuestLogLevel.hpp +70 -0
- package/nitrogen/generated/android/c++/JCarrotQuestProperty.hpp +74 -0
- package/nitrogen/generated/android/c++/JCarrotQuestPropertyKind.hpp +61 -0
- package/nitrogen/generated/android/c++/JCarrotQuestPropertyOperation.hpp +73 -0
- package/nitrogen/generated/android/c++/JCarrotQuestSetupOptions.hpp +94 -0
- package/nitrogen/generated/android/c++/JCarrotQuestTheme.hpp +64 -0
- package/nitrogen/generated/android/c++/JCarrotQuestUrlSource.hpp +64 -0
- package/nitrogen/generated/android/c++/JCarrotQuestUserProperties.hpp +84 -0
- package/nitrogen/generated/android/c++/JFunc_void_CarrotQuestLogEntry.hpp +84 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridCarrotQuestSpec.cpp +388 -0
- package/nitrogen/generated/android/c++/JHybridCarrotQuestSpec.hpp +96 -0
- package/nitrogen/generated/android/carrotquest+autolinking.cmake +82 -0
- package/nitrogen/generated/android/carrotquest+autolinking.gradle +27 -0
- package/nitrogen/generated/android/carrotquestOnLoad.cpp +62 -0
- package/nitrogen/generated/android/carrotquestOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestEventValue.kt +75 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestLogCategory.kt +29 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestLogEntry.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestLogLevel.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestProperty.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestPropertyKind.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestPropertyOperation.kt +28 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestSetupOptions.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestTheme.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestUrlSource.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/CarrotQuestUserProperties.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/Func_void_CarrotQuestLogEntry.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/Func_void_bool.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/Func_void_std__string.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/HybridCarrotQuestSpec.kt +209 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/carrotquest/carrotquestOnLoad.kt +35 -0
- package/nitrogen/generated/ios/CarrotQuest+autolinking.rb +62 -0
- package/nitrogen/generated/ios/CarrotQuest-Swift-Cxx-Bridge.cpp +97 -0
- package/nitrogen/generated/ios/CarrotQuest-Swift-Cxx-Bridge.hpp +637 -0
- package/nitrogen/generated/ios/CarrotQuest-Swift-Cxx-Umbrella.hpp +80 -0
- package/nitrogen/generated/ios/CarrotQuestAutolinking.mm +33 -0
- package/nitrogen/generated/ios/CarrotQuestAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridCarrotQuestSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCarrotQuestSpecSwift.hpp +344 -0
- package/nitrogen/generated/ios/swift/CarrotQuestEventValue.swift +32 -0
- package/nitrogen/generated/ios/swift/CarrotQuestLogCategory.swift +64 -0
- package/nitrogen/generated/ios/swift/CarrotQuestLogEntry.swift +86 -0
- package/nitrogen/generated/ios/swift/CarrotQuestLogLevel.swift +56 -0
- package/nitrogen/generated/ios/swift/CarrotQuestProperty.swift +56 -0
- package/nitrogen/generated/ios/swift/CarrotQuestPropertyKind.swift +44 -0
- package/nitrogen/generated/ios/swift/CarrotQuestPropertyOperation.swift +60 -0
- package/nitrogen/generated/ios/swift/CarrotQuestSetupOptions.swift +172 -0
- package/nitrogen/generated/ios/swift/CarrotQuestTheme.swift +48 -0
- package/nitrogen/generated/ios/swift/CarrotQuestUrlSource.swift +48 -0
- package/nitrogen/generated/ios/swift/CarrotQuestUserProperties.swift +110 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_CarrotQuestLogEntry.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift +53 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +53 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridCarrotQuestSpec.swift +88 -0
- package/nitrogen/generated/ios/swift/HybridCarrotQuestSpec_cxx.swift +674 -0
- package/nitrogen/generated/shared/c++/CarrotQuestLogCategory.hpp +100 -0
- package/nitrogen/generated/shared/c++/CarrotQuestLogEntry.hpp +114 -0
- package/nitrogen/generated/shared/c++/CarrotQuestLogLevel.hpp +92 -0
- package/nitrogen/generated/shared/c++/CarrotQuestProperty.hpp +101 -0
- package/nitrogen/generated/shared/c++/CarrotQuestPropertyKind.hpp +80 -0
- package/nitrogen/generated/shared/c++/CarrotQuestPropertyOperation.hpp +96 -0
- package/nitrogen/generated/shared/c++/CarrotQuestSetupOptions.hpp +121 -0
- package/nitrogen/generated/shared/c++/CarrotQuestTheme.hpp +84 -0
- package/nitrogen/generated/shared/c++/CarrotQuestUrlSource.hpp +84 -0
- package/nitrogen/generated/shared/c++/CarrotQuestUserProperties.hpp +97 -0
- package/nitrogen/generated/shared/c++/HybridCarrotQuestSpec.cpp +55 -0
- package/nitrogen/generated/shared/c++/HybridCarrotQuestSpec.hpp +118 -0
- package/package.json +140 -0
- package/src/CarrotQuest.nitro.ts +493 -0
- package/src/carrot-quest.native.tsx +241 -0
- package/src/carrot-quest.tsx +207 -0
- package/src/index.tsx +57 -0
- package/src/subscriptions.ts +83 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type {
|
|
3
|
+
CarrotQuest,
|
|
4
|
+
CarrotQuestEventValue,
|
|
5
|
+
CarrotQuestLogEntry,
|
|
6
|
+
CarrotQuestProperty,
|
|
7
|
+
CarrotQuestSetupOptions,
|
|
8
|
+
CarrotQuestTheme,
|
|
9
|
+
CarrotQuestUrlSource,
|
|
10
|
+
CarrotQuestUserProperties,
|
|
11
|
+
} from './CarrotQuest.nitro';
|
|
12
|
+
import type { CarrotQuestSubscription } from './subscriptions';
|
|
13
|
+
import { createChannel } from './subscriptions';
|
|
14
|
+
|
|
15
|
+
const native = NitroModules.createHybridObject<CarrotQuest>('CarrotQuest');
|
|
16
|
+
|
|
17
|
+
// MARK: - Lifecycle
|
|
18
|
+
|
|
19
|
+
export function isConfigured(): boolean {
|
|
20
|
+
return native.isConfigured;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function setup(
|
|
24
|
+
apiKey: string,
|
|
25
|
+
options?: CarrotQuestSetupOptions
|
|
26
|
+
): Promise<void> {
|
|
27
|
+
return native.setup(apiKey, options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getSdkVersion(): string {
|
|
31
|
+
return native.getSdkVersion();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// MARK: - Authentication
|
|
35
|
+
|
|
36
|
+
export function auth(
|
|
37
|
+
userId: string,
|
|
38
|
+
userAuthKey: string
|
|
39
|
+
): Promise<string | undefined> {
|
|
40
|
+
return native.auth(userId, userAuthKey);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function hashedAuth(
|
|
44
|
+
userId: string,
|
|
45
|
+
hash: string
|
|
46
|
+
): Promise<string | undefined> {
|
|
47
|
+
return native.hashedAuth(userId, hash);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function logout(): Promise<void> {
|
|
51
|
+
return native.logout();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MARK: - Chat UI
|
|
55
|
+
|
|
56
|
+
export function openChat(): Promise<void> {
|
|
57
|
+
return native.openChat();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function closeChat(): Promise<void> {
|
|
61
|
+
return native.closeChat();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function isChatOpen(): boolean {
|
|
65
|
+
return native.isChatOpen;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const chatVisibilityChannel = createChannel<[boolean]>((dispatch) =>
|
|
69
|
+
native.onChatVisibilityChanged(dispatch)
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export function onChatVisibilityChanged(
|
|
73
|
+
listener: (visible: boolean) => void
|
|
74
|
+
): CarrotQuestSubscription {
|
|
75
|
+
return chatVisibilityChannel(listener);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function setTheme(theme: CarrotQuestTheme): void {
|
|
79
|
+
native.setTheme(theme);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// MARK: - Unread state
|
|
83
|
+
|
|
84
|
+
export function getUnreadConversationsCount(): Promise<number> {
|
|
85
|
+
return native.getUnreadConversationsCount();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getUnreadMessagesCount(): Promise<number | undefined> {
|
|
89
|
+
return native.getUnreadMessagesCount();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const unreadConversationsChannel = createChannel<[number]>((dispatch) =>
|
|
93
|
+
native.onUnreadConversationsChanged(dispatch)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export function onUnreadConversationsChanged(
|
|
97
|
+
listener: (count: number) => void
|
|
98
|
+
): CarrotQuestSubscription {
|
|
99
|
+
return unreadConversationsChannel(listener);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// MARK: - User properties
|
|
103
|
+
|
|
104
|
+
export function setUserProperties(properties: CarrotQuestUserProperties): void {
|
|
105
|
+
native.setUserProperties(properties);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function setProperties(properties: CarrotQuestProperty[]): void {
|
|
109
|
+
native.setProperties(properties);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// MARK: - Tracking
|
|
113
|
+
|
|
114
|
+
export function trackEvent(
|
|
115
|
+
name: string,
|
|
116
|
+
params?: Record<string, CarrotQuestEventValue>
|
|
117
|
+
): void {
|
|
118
|
+
native.trackEvent(name, params);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function trackScreen(name: string): void {
|
|
122
|
+
native.trackScreen(name);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function trackUtm(url: string): void {
|
|
126
|
+
native.trackUtm(url);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// MARK: - Push notifications
|
|
130
|
+
|
|
131
|
+
export function setPushToken(token: string): void {
|
|
132
|
+
native.setPushToken(token);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function deletePushToken(): void {
|
|
136
|
+
native.deletePushToken();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function pushNotificationsUnsubscribe(): Promise<void> {
|
|
140
|
+
return native.pushNotificationsUnsubscribe();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function pushCampaignsUnsubscribe(): Promise<void> {
|
|
144
|
+
return native.pushCampaignsUnsubscribe();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Accepts either a decoded payload object or the raw JSON string the native
|
|
149
|
+
* side expects.
|
|
150
|
+
*/
|
|
151
|
+
const encodePayload = (payload: Record<string, unknown> | string): string =>
|
|
152
|
+
typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
153
|
+
|
|
154
|
+
export function isCarrotPush(
|
|
155
|
+
payload: Record<string, unknown> | string
|
|
156
|
+
): boolean {
|
|
157
|
+
return native.isCarrotPush(encodePayload(payload));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function isAutoMessage(
|
|
161
|
+
payload: Record<string, unknown> | string
|
|
162
|
+
): boolean {
|
|
163
|
+
return native.isAutoMessage(encodePayload(payload));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function handlePushNotification(
|
|
167
|
+
payload: Record<string, unknown> | string
|
|
168
|
+
): void {
|
|
169
|
+
native.handlePushNotification(encodePayload(payload));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function handlePushClick(
|
|
173
|
+
payload: Record<string, unknown> | string,
|
|
174
|
+
openLink = true
|
|
175
|
+
): void {
|
|
176
|
+
native.handlePushClick(encodePayload(payload), openLink);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function getPushLink(
|
|
180
|
+
payload: Record<string, unknown> | string
|
|
181
|
+
): string | undefined {
|
|
182
|
+
return native.getPushLink(encodePayload(payload));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function wasPushShownEarlier(
|
|
186
|
+
payload: Record<string, unknown> | string
|
|
187
|
+
): Promise<boolean> {
|
|
188
|
+
return native.wasPushShownEarlier(encodePayload(payload));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// MARK: - Deep links
|
|
192
|
+
|
|
193
|
+
// The SDK registers a handler per url type, so each source gets its own
|
|
194
|
+
// channel rather than sharing one.
|
|
195
|
+
const urlChannels = new Map<
|
|
196
|
+
CarrotQuestUrlSource,
|
|
197
|
+
(listener: (url: string) => void) => CarrotQuestSubscription
|
|
198
|
+
>();
|
|
199
|
+
|
|
200
|
+
export function onUrlOpen(
|
|
201
|
+
source: CarrotQuestUrlSource,
|
|
202
|
+
listener: (url: string) => void
|
|
203
|
+
): CarrotQuestSubscription {
|
|
204
|
+
let channel = urlChannels.get(source);
|
|
205
|
+
|
|
206
|
+
if (!channel) {
|
|
207
|
+
channel = createChannel<[string]>((dispatch) =>
|
|
208
|
+
native.onUrlOpen(source, dispatch)
|
|
209
|
+
);
|
|
210
|
+
urlChannels.set(source, channel);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return channel(listener);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function openBrowserLink(url: string): void {
|
|
217
|
+
native.openBrowserLink(url);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function openUniversalLink(url: string): void {
|
|
221
|
+
native.openUniversalLink(url);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// MARK: - Diagnostics
|
|
225
|
+
|
|
226
|
+
export function getDiagnostics(): string | undefined {
|
|
227
|
+
return native.getDiagnostics();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// The only channel with a native detach — and the only one whose volume makes
|
|
231
|
+
// it matter, since a verbose log level pushes an entry per network call.
|
|
232
|
+
const logChannel = createChannel<[CarrotQuestLogEntry]>(
|
|
233
|
+
(dispatch) => native.onLog(dispatch),
|
|
234
|
+
() => native.offLog()
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
export function onLog(
|
|
238
|
+
listener: (entry: CarrotQuestLogEntry) => void
|
|
239
|
+
): CarrotQuestSubscription {
|
|
240
|
+
return logChannel(listener);
|
|
241
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CarrotQuestEventValue,
|
|
3
|
+
CarrotQuestLogEntry,
|
|
4
|
+
CarrotQuestProperty,
|
|
5
|
+
CarrotQuestSetupOptions,
|
|
6
|
+
CarrotQuestTheme,
|
|
7
|
+
CarrotQuestUrlSource,
|
|
8
|
+
CarrotQuestUserProperties,
|
|
9
|
+
} from './CarrotQuest.nitro';
|
|
10
|
+
import type { CarrotQuestSubscription } from './subscriptions';
|
|
11
|
+
import { noopSubscription } from './subscriptions';
|
|
12
|
+
|
|
13
|
+
const unsupported = (method: string): never => {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`react-native-carrot-quest: ${method}() is only supported on iOS and Android.`
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// MARK: - Lifecycle
|
|
20
|
+
|
|
21
|
+
export function isConfigured(): boolean {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function setup(
|
|
26
|
+
_apiKey: string,
|
|
27
|
+
_options?: CarrotQuestSetupOptions
|
|
28
|
+
): Promise<void> {
|
|
29
|
+
return unsupported('setup');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getSdkVersion(): string {
|
|
33
|
+
return unsupported('getSdkVersion');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// MARK: - Authentication
|
|
37
|
+
|
|
38
|
+
export function auth(
|
|
39
|
+
_userId: string,
|
|
40
|
+
_userAuthKey: string
|
|
41
|
+
): Promise<string | undefined> {
|
|
42
|
+
return unsupported('auth');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function hashedAuth(
|
|
46
|
+
_userId: string,
|
|
47
|
+
_hash: string
|
|
48
|
+
): Promise<string | undefined> {
|
|
49
|
+
return unsupported('hashedAuth');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function logout(): Promise<void> {
|
|
53
|
+
return unsupported('logout');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// MARK: - Chat UI
|
|
57
|
+
|
|
58
|
+
export function openChat(): Promise<void> {
|
|
59
|
+
return unsupported('openChat');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function closeChat(): Promise<void> {
|
|
63
|
+
return unsupported('closeChat');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function isChatOpen(): boolean {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function onChatVisibilityChanged(
|
|
71
|
+
_listener: (visible: boolean) => void
|
|
72
|
+
): CarrotQuestSubscription {
|
|
73
|
+
return noopSubscription;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function setTheme(_theme: CarrotQuestTheme): void {
|
|
77
|
+
unsupported('setTheme');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// MARK: - Unread state
|
|
81
|
+
|
|
82
|
+
export function getUnreadConversationsCount(): Promise<number> {
|
|
83
|
+
return unsupported('getUnreadConversationsCount');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getUnreadMessagesCount(): Promise<number | undefined> {
|
|
87
|
+
return unsupported('getUnreadMessagesCount');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function onUnreadConversationsChanged(
|
|
91
|
+
_listener: (count: number) => void
|
|
92
|
+
): CarrotQuestSubscription {
|
|
93
|
+
return noopSubscription;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// MARK: - User properties
|
|
97
|
+
|
|
98
|
+
export function setUserProperties(
|
|
99
|
+
_properties: CarrotQuestUserProperties
|
|
100
|
+
): void {
|
|
101
|
+
unsupported('setUserProperties');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function setProperties(_properties: CarrotQuestProperty[]): void {
|
|
105
|
+
unsupported('setProperties');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// MARK: - Tracking
|
|
109
|
+
|
|
110
|
+
export function trackEvent(
|
|
111
|
+
_name: string,
|
|
112
|
+
_params?: Record<string, CarrotQuestEventValue>
|
|
113
|
+
): void {
|
|
114
|
+
unsupported('trackEvent');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function trackScreen(_name: string): void {
|
|
118
|
+
unsupported('trackScreen');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function trackUtm(_url: string): void {
|
|
122
|
+
unsupported('trackUtm');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// MARK: - Push notifications
|
|
126
|
+
|
|
127
|
+
export function setPushToken(_token: string): void {
|
|
128
|
+
unsupported('setPushToken');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function deletePushToken(): void {
|
|
132
|
+
unsupported('deletePushToken');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function pushNotificationsUnsubscribe(): Promise<void> {
|
|
136
|
+
return unsupported('pushNotificationsUnsubscribe');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function pushCampaignsUnsubscribe(): Promise<void> {
|
|
140
|
+
return unsupported('pushCampaignsUnsubscribe');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isCarrotPush(
|
|
144
|
+
_payload: Record<string, unknown> | string
|
|
145
|
+
): boolean {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function isAutoMessage(
|
|
150
|
+
_payload: Record<string, unknown> | string
|
|
151
|
+
): boolean {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function handlePushNotification(
|
|
156
|
+
_payload: Record<string, unknown> | string
|
|
157
|
+
): void {
|
|
158
|
+
unsupported('handlePushNotification');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function handlePushClick(
|
|
162
|
+
_payload: Record<string, unknown> | string,
|
|
163
|
+
_openLink?: boolean
|
|
164
|
+
): void {
|
|
165
|
+
unsupported('handlePushClick');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getPushLink(
|
|
169
|
+
_payload: Record<string, unknown> | string
|
|
170
|
+
): string | undefined {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function wasPushShownEarlier(
|
|
175
|
+
_payload: Record<string, unknown> | string
|
|
176
|
+
): Promise<boolean> {
|
|
177
|
+
return Promise.resolve(false);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// MARK: - Deep links
|
|
181
|
+
|
|
182
|
+
export function onUrlOpen(
|
|
183
|
+
_source: CarrotQuestUrlSource,
|
|
184
|
+
_listener: (url: string) => void
|
|
185
|
+
): CarrotQuestSubscription {
|
|
186
|
+
return noopSubscription;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function openBrowserLink(_url: string): void {
|
|
190
|
+
unsupported('openBrowserLink');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function openUniversalLink(_url: string): void {
|
|
194
|
+
unsupported('openUniversalLink');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// MARK: - Diagnostics
|
|
198
|
+
|
|
199
|
+
export function getDiagnostics(): string | undefined {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function onLog(
|
|
204
|
+
_listener: (entry: CarrotQuestLogEntry) => void
|
|
205
|
+
): CarrotQuestSubscription {
|
|
206
|
+
return noopSubscription;
|
|
207
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as CarrotQuest from './carrot-quest';
|
|
2
|
+
|
|
3
|
+
export default CarrotQuest;
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
auth,
|
|
7
|
+
closeChat,
|
|
8
|
+
deletePushToken,
|
|
9
|
+
getDiagnostics,
|
|
10
|
+
getPushLink,
|
|
11
|
+
getSdkVersion,
|
|
12
|
+
getUnreadConversationsCount,
|
|
13
|
+
getUnreadMessagesCount,
|
|
14
|
+
handlePushClick,
|
|
15
|
+
handlePushNotification,
|
|
16
|
+
hashedAuth,
|
|
17
|
+
isAutoMessage,
|
|
18
|
+
isCarrotPush,
|
|
19
|
+
isChatOpen,
|
|
20
|
+
isConfigured,
|
|
21
|
+
logout,
|
|
22
|
+
onChatVisibilityChanged,
|
|
23
|
+
onLog,
|
|
24
|
+
onUnreadConversationsChanged,
|
|
25
|
+
onUrlOpen,
|
|
26
|
+
openBrowserLink,
|
|
27
|
+
openChat,
|
|
28
|
+
openUniversalLink,
|
|
29
|
+
pushCampaignsUnsubscribe,
|
|
30
|
+
pushNotificationsUnsubscribe,
|
|
31
|
+
setProperties,
|
|
32
|
+
setPushToken,
|
|
33
|
+
setTheme,
|
|
34
|
+
setUserProperties,
|
|
35
|
+
setup,
|
|
36
|
+
trackEvent,
|
|
37
|
+
trackScreen,
|
|
38
|
+
trackUtm,
|
|
39
|
+
} from './carrot-quest';
|
|
40
|
+
|
|
41
|
+
export type { CarrotQuestSubscription } from './subscriptions';
|
|
42
|
+
|
|
43
|
+
export type {
|
|
44
|
+
CarrotQuest,
|
|
45
|
+
CarrotQuestEcommerceProperty,
|
|
46
|
+
CarrotQuestEventValue,
|
|
47
|
+
CarrotQuestLogCategory,
|
|
48
|
+
CarrotQuestLogEntry,
|
|
49
|
+
CarrotQuestLogLevel,
|
|
50
|
+
CarrotQuestProperty,
|
|
51
|
+
CarrotQuestPropertyKind,
|
|
52
|
+
CarrotQuestPropertyOperation,
|
|
53
|
+
CarrotQuestSetupOptions,
|
|
54
|
+
CarrotQuestTheme,
|
|
55
|
+
CarrotQuestUrlSource,
|
|
56
|
+
CarrotQuestUserProperties,
|
|
57
|
+
} from './CarrotQuest.nitro';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JS-side listener registry that multiplexes many subscribers over a single
|
|
3
|
+
* native callback.
|
|
4
|
+
*
|
|
5
|
+
* Each SDK hook (`onVisibilityUIChanged`, `setCloseChatCallback`,
|
|
6
|
+
* `setUnreadConversationsCallback`, `CustomUrlOpener.set(for:)`) is a *setter*:
|
|
7
|
+
* registering twice replaces the first callback. Handing that directly to app
|
|
8
|
+
* code means two components cannot both listen, and a component that remounts
|
|
9
|
+
* — or is hot-reloaded — leaves a stale closure installed with no way to
|
|
10
|
+
* detach it.
|
|
11
|
+
*
|
|
12
|
+
* So the native callback is installed exactly once per channel, and fan-out
|
|
13
|
+
* happens here where a subscription can actually be removed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Returned by every listener registration. Call `remove()` to unsubscribe. */
|
|
17
|
+
export interface CarrotQuestSubscription {
|
|
18
|
+
remove(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const noopSubscription: CarrotQuestSubscription = { remove: () => {} };
|
|
22
|
+
|
|
23
|
+
export { noopSubscription };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates an `add(listener)` function for one native channel.
|
|
27
|
+
*
|
|
28
|
+
* @param install receives the fan-out dispatcher and wires it to the native
|
|
29
|
+
* callback. Called on the first subscription, and again after a teardown.
|
|
30
|
+
* @param uninstall detaches the native callback once the last listener is
|
|
31
|
+
* removed. Omit it for channels the SDK cannot detach — the dispatcher then
|
|
32
|
+
* stays installed and fans out to an empty set, which is only acceptable for
|
|
33
|
+
* low-frequency signals.
|
|
34
|
+
*/
|
|
35
|
+
export function createChannel<Args extends unknown[]>(
|
|
36
|
+
install: (dispatch: (...args: Args) => void) => void,
|
|
37
|
+
uninstall?: () => void
|
|
38
|
+
): (listener: (...args: Args) => void) => CarrotQuestSubscription {
|
|
39
|
+
const listeners = new Set<(...args: Args) => void>();
|
|
40
|
+
let installed = false;
|
|
41
|
+
|
|
42
|
+
const dispatch = (...args: Args) => {
|
|
43
|
+
// Copy first: a listener may unsubscribe itself (or another) while we emit.
|
|
44
|
+
for (const listener of [...listeners]) {
|
|
45
|
+
try {
|
|
46
|
+
listener(...args);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// One misbehaving subscriber must not stop the others, and this call
|
|
49
|
+
// originates from native code where a throw has nowhere to go.
|
|
50
|
+
console.error('react-native-carrot-quest: listener threw', error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (listener) => {
|
|
56
|
+
if (!installed) {
|
|
57
|
+
// Install lazily so merely importing the package does not register
|
|
58
|
+
// native callbacks.
|
|
59
|
+
installed = true;
|
|
60
|
+
install(dispatch);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
listeners.add(listener);
|
|
64
|
+
|
|
65
|
+
let removed = false;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
remove: () => {
|
|
69
|
+
// Idempotent: removing twice must not disturb a re-added listener.
|
|
70
|
+
if (removed) return;
|
|
71
|
+
removed = true;
|
|
72
|
+
listeners.delete(listener);
|
|
73
|
+
|
|
74
|
+
// Detach once nobody is listening, so native stops pushing across the
|
|
75
|
+
// bridge. The next subscription reinstalls.
|
|
76
|
+
if (listeners.size === 0 && uninstall && installed) {
|
|
77
|
+
installed = false;
|
|
78
|
+
uninstall();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|