@altcraft/react-native-sdk 0.0.1 → 0.0.3
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/LICENSE +20 -20
- package/README.md +5 -2
- package/android/build.gradle +2 -3
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +493 -896
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +326 -0
- package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +72 -0
- package/ios/Converter.swift +640 -0
- package/ios/Sdk.h +4 -3
- package/ios/Sdk.mm +124 -370
- package/ios/SdkModule.swift +436 -653
- package/lib/module/NativeSdk.js +35 -0
- package/lib/module/NativeSdk.js.map +1 -1
- package/lib/module/Utilities.js +94 -0
- package/lib/module/Utilities.js.map +1 -0
- package/lib/module/index.js +180 -419
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSdk.d.ts +117 -32
- package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
- package/lib/typescript/src/Utilities.d.ts +15 -0
- package/lib/typescript/src/Utilities.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +113 -308
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/NativeSdk.ts +156 -46
- package/src/Utilities.ts +116 -0
- package/src/index.tsx +255 -483
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -27
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnHMSProvider.kt +0 -32
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnJWTProvider.kt +0 -21
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnRustoreProvider.kt +0 -53
- package/ios/protocols/RNAPNSProvider.swift +0 -15
- package/ios/protocols/RNFCMProvider.swift +0 -24
- package/ios/protocols/RNHMSProvider.swift +0 -24
- package/ios/protocols/RNJWTProvider.swift +0 -15
package/src/index.tsx
CHANGED
|
@@ -1,347 +1,64 @@
|
|
|
1
|
-
import { NativeEventEmitter } from 'react-native';
|
|
1
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
2
|
+
|
|
2
3
|
import NativeSDK, {
|
|
3
4
|
type AltcraftConfig,
|
|
4
5
|
type CategoryData,
|
|
5
6
|
type ResponseWithHttpCode,
|
|
6
7
|
type TokenData,
|
|
8
|
+
type EmailSubscription,
|
|
9
|
+
type SmsSubscription,
|
|
10
|
+
type PushSubscription,
|
|
11
|
+
type CcDataSubscription,
|
|
12
|
+
type Subscription,
|
|
13
|
+
type UTM,
|
|
14
|
+
type SdkEvent,
|
|
7
15
|
} from './NativeSdk';
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
* SDK event payload emitted from the native layer via NativeEventEmitter.
|
|
11
|
-
*
|
|
12
|
-
* Native sources (conceptually):
|
|
13
|
-
* - Android (Kotlin): SDK Events module -> emits "AltcraftSdkEvent"
|
|
14
|
-
* - iOS (Swift): SDKEvents.shared -> bridge -> emits "AltcraftSdkEvent"
|
|
15
|
-
*
|
|
16
|
-
* Fields:
|
|
17
|
-
* - function: origin function/context name in the SDK
|
|
18
|
-
* - code: optional numeric code (HTTP/internal/etc.)
|
|
19
|
-
* - message: human-readable message
|
|
20
|
-
* - type: event category ("event" | "error" | "retryError")
|
|
21
|
-
* - value: optional extra data/context
|
|
22
|
-
*/
|
|
23
|
-
export type SdkEvent = {
|
|
24
|
-
function: string;
|
|
25
|
-
code: number | null;
|
|
26
|
-
message: string;
|
|
27
|
-
type: 'event' | 'error' | 'retryError';
|
|
28
|
-
value?: { [key: string]: any } | null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Converts a JS object to a string-to-string map suitable for passing through the RN bridge.
|
|
33
|
-
*
|
|
34
|
-
* Why:
|
|
35
|
-
* - TurboModules/bridges often prefer primitive types and predictable structures.
|
|
36
|
-
* - Native SDK public APIs frequently accept Map<String, String> (Android) / bridged dictionaries (iOS).
|
|
37
|
-
*
|
|
38
|
-
* Behavior:
|
|
39
|
-
* - null/undefined values are skipped
|
|
40
|
-
* - all other values are coerced via `String(v)`
|
|
41
|
-
* - returns `null` if the resulting map is empty (native side can treat it as "not provided")
|
|
42
|
-
*/
|
|
43
|
-
function toNativeStringMap(
|
|
44
|
-
input: { [key: string]: any } | null
|
|
45
|
-
): { [key: string]: string } | null {
|
|
46
|
-
if (!input) return null;
|
|
47
|
-
|
|
48
|
-
const out: { [key: string]: string } = {};
|
|
49
|
-
for (const [k, v] of Object.entries(input)) {
|
|
50
|
-
if (v == null) continue;
|
|
51
|
-
out[k] = String(v);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* JS-side abstraction for handling incoming push payloads.
|
|
59
|
-
*
|
|
60
|
-
* Native analogy:
|
|
61
|
-
* - Android: `AltcraftSDK.PushReceiver` + `PushReceiver.takePush(context, message)`
|
|
62
|
-
*
|
|
63
|
-
* In RN:
|
|
64
|
-
* - `takePush(...)` always forwards the payload to native (`NativeSdk.takePush`)
|
|
65
|
-
* - then optionally dispatches it to registered JS receivers (`PushReceiver`)
|
|
66
|
-
*
|
|
67
|
-
* This provides:
|
|
68
|
-
* - centralized forwarding to the Altcraft native SDK (parsing/internal flows)
|
|
69
|
-
* - optional additional JS-level handling (logging, routing, analytics, debugging)
|
|
70
|
-
*/
|
|
71
|
-
export abstract class PushReceiver {
|
|
72
|
-
/**
|
|
73
|
-
* Called when the JS facade receives a push payload.
|
|
74
|
-
*
|
|
75
|
-
* @param message Flat `Record<string, string>` (matches typical data payload shape).
|
|
76
|
-
*/
|
|
77
|
-
abstract pushHandler(message: { [key: string]: string }): void;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Registered JS receivers for push payload dispatch.
|
|
82
|
-
* If none are registered, a DefaultPushReceiver will log the payload.
|
|
83
|
-
*/
|
|
84
|
-
const registeredPushReceivers: PushReceiver[] = [];
|
|
17
|
+
import { Utilities } from './Utilities';
|
|
85
18
|
|
|
86
|
-
|
|
87
|
-
* Registers a JS receiver for incoming push payloads.
|
|
88
|
-
*
|
|
89
|
-
* Typically called once during app startup.
|
|
90
|
-
*
|
|
91
|
-
* @param receiver Implementation of `PushReceiver`.
|
|
92
|
-
*/
|
|
93
|
-
export function registerPushReceiver(receiver: PushReceiver): void {
|
|
94
|
-
registeredPushReceivers.push(receiver);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Clears all registered push receivers.
|
|
99
|
-
*
|
|
100
|
-
* Useful for tests or reinitializing the integration layer.
|
|
101
|
-
*/
|
|
102
|
-
export function clearPushReceivers(): void {
|
|
103
|
-
registeredPushReceivers.length = 0;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Default receiver used when no custom receivers are registered.
|
|
108
|
-
* Prevents silent drops during integration and provides visibility via console logs.
|
|
109
|
-
*/
|
|
110
|
-
class DefaultPushReceiver extends PushReceiver {
|
|
111
|
-
override pushHandler(message: { [key: string]: string }): void {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
console.log('[AltcraftSDK] Default push handler:', message);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Forwards an incoming push payload to the native Altcraft SDK and then to JS receivers.
|
|
119
|
-
*
|
|
120
|
-
* Native analogy:
|
|
121
|
-
* - Android: `AltcraftSDK.PushReceiver.takePush(context, message)`
|
|
122
|
-
*
|
|
123
|
-
* Important:
|
|
124
|
-
* - This method does NOT intercept notifications by itself.
|
|
125
|
-
* Platform-level interception must be implemented separately:
|
|
126
|
-
* - Android: FCM/HMS service -> call `takePush(message.data)`
|
|
127
|
-
* - iOS: AppDelegate / UNUserNotificationCenter / Notification Service Extension -> call `takePush(userInfo)`
|
|
128
|
-
*
|
|
129
|
-
* @param message Flat push payload map. Empty payloads are ignored.
|
|
130
|
-
*/
|
|
131
|
-
export function takePush(message: { [key: string]: string }): void {
|
|
132
|
-
if (!message || Object.keys(message).length === 0) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 1) Always forward to native SDK for parsing/internal processing
|
|
137
|
-
NativeSDK.takePush({ ...message });
|
|
138
|
-
|
|
139
|
-
// 2) Optionally forward to JS receivers (custom logic/analytics/debug)
|
|
140
|
-
const receivers =
|
|
141
|
-
registeredPushReceivers.length > 0
|
|
142
|
-
? registeredPushReceivers
|
|
143
|
-
: [new DefaultPushReceiver()];
|
|
144
|
-
|
|
145
|
-
for (const receiver of receivers) {
|
|
146
|
-
try {
|
|
147
|
-
receiver.pushHandler(message);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
// eslint-disable-next-line no-console
|
|
150
|
-
console.warn('[AltcraftSDK] PushReceiver error:', e);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ---------------- Events API for RN ----------------
|
|
156
|
-
|
|
157
|
-
/** RN subscription handle type (NativeEventEmitter). */
|
|
158
|
-
type EventsSubscription = { remove: () => void } | null;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Native event emitter used to receive SDK events from the native bridge.
|
|
162
|
-
* Event name: "AltcraftSdkEvent"
|
|
163
|
-
*/
|
|
164
|
-
const nativeEventEmitter = new NativeEventEmitter(NativeSDK as any);
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Current active subscription to native SDK events.
|
|
168
|
-
* Only one subscription is maintained; re-subscribing replaces the previous one.
|
|
169
|
-
*/
|
|
170
|
-
let eventsSubscription: EventsSubscription = null;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Subscribes to Altcraft SDK events and starts streaming them from native to JS.
|
|
174
|
-
*
|
|
175
|
-
* Contract:
|
|
176
|
-
* - If a previous subscription exists, it is removed.
|
|
177
|
-
* - Calls `NativeSdk.subscribeToEvents()` so the native side starts emitting events.
|
|
178
|
-
*
|
|
179
|
-
* @param handler JS handler invoked for each SDK event.
|
|
180
|
-
*/
|
|
181
|
-
export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
|
|
182
|
-
if (eventsSubscription) {
|
|
183
|
-
eventsSubscription.remove();
|
|
184
|
-
eventsSubscription = null;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
NativeSDK.subscribeToEvents();
|
|
188
|
-
|
|
189
|
-
eventsSubscription = nativeEventEmitter.addListener(
|
|
190
|
-
'AltcraftSdkEvent',
|
|
191
|
-
(...args: any[]) => {
|
|
192
|
-
const event = (args[0] ?? null) as SdkEvent | null;
|
|
193
|
-
if (!event) return;
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
handler(event);
|
|
197
|
-
} catch (e) {
|
|
198
|
-
// eslint-disable-next-line no-console
|
|
199
|
-
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Unsubscribes from Altcraft SDK events.
|
|
207
|
-
*
|
|
208
|
-
* Behavior:
|
|
209
|
-
* - removes the JS listener
|
|
210
|
-
* - calls `NativeSdk.unsubscribeFromEvent()` to stop native emissions
|
|
211
|
-
*/
|
|
212
|
-
export function unsubscribeFromEvent(): void {
|
|
213
|
-
if (eventsSubscription) {
|
|
214
|
-
eventsSubscription.remove();
|
|
215
|
-
eventsSubscription = null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
NativeSDK.unsubscribeFromEvent();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ---------------- existing public SDK API ----------------
|
|
19
|
+
// ---------------- SDK API ----------------
|
|
222
20
|
|
|
223
21
|
/**
|
|
224
22
|
* Initializes the Altcraft SDK.
|
|
225
23
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* Promise:
|
|
231
|
-
* - resolves on success
|
|
232
|
-
*
|
|
233
|
-
* ⚠️ Can throw (reject):
|
|
234
|
-
* - configuration mapping/validation errors on native side
|
|
235
|
-
* - native initialization failure (e.g. missing required fields, internal init error)
|
|
236
|
-
*
|
|
237
|
-
* @param config SDK configuration (apiUrl is required).
|
|
24
|
+
* @param config SDK configuration.
|
|
25
|
+
* `apiUrl` is required.
|
|
26
|
+
* Other fields are optional and depend on platform features.
|
|
27
|
+
* @returns Promise that resolves on successful initialization.
|
|
238
28
|
*/
|
|
239
29
|
export function initialize(config: AltcraftConfig): Promise<void> {
|
|
240
30
|
return NativeSDK.initialize(config);
|
|
241
31
|
}
|
|
242
32
|
|
|
243
|
-
|
|
244
|
-
* Sets/clears the JWT used by the SDK for authenticated requests.
|
|
245
|
-
*
|
|
246
|
-
* Native concept:
|
|
247
|
-
* - Android/iOS register a JWT provider; RN uses an internal provider backed by this token.
|
|
248
|
-
*
|
|
249
|
-
* Semantics:
|
|
250
|
-
* - token === null -> clear JWT provider/token
|
|
251
|
-
* - token !== null -> store token and enable provider
|
|
252
|
-
*
|
|
253
|
-
* @param token JWT string or null to clear.
|
|
254
|
-
*/
|
|
255
|
-
export function setJwt(token: string | null): void {
|
|
256
|
-
return NativeSDK.setJwt(token);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// platform-specific token setters
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Android-only: sets the FCM token to be used by the SDK.
|
|
263
|
-
*
|
|
264
|
-
* Typical usage:
|
|
265
|
-
* - after `messaging().getToken()`
|
|
266
|
-
* - when the token refreshes
|
|
267
|
-
*
|
|
268
|
-
* @param token FCM token or null to clear/unset.
|
|
269
|
-
*/
|
|
270
|
-
export function setAndroidFcmToken(token: string | null): void {
|
|
271
|
-
return NativeSDK.setAndroidFcmToken(token);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* iOS-only: kept for API symmetry (may be a no-op on other platforms).
|
|
276
|
-
*
|
|
277
|
-
* @param token iOS FCM token or null.
|
|
278
|
-
*/
|
|
279
|
-
export function setIosFcmToken(token: string | null): void {
|
|
280
|
-
return NativeSDK.setIosFcmToken(token);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Android-only: sets the HMS token.
|
|
285
|
-
*
|
|
286
|
-
* @param token HMS token or null.
|
|
287
|
-
*/
|
|
288
|
-
export function setAndroidHmsToken(token: string | null): void {
|
|
289
|
-
return NativeSDK.setAndroidHmsToken(token);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* iOS-only: kept for API symmetry (may be a no-op on other platforms).
|
|
294
|
-
*
|
|
295
|
-
* @param token iOS HMS token or null.
|
|
296
|
-
*/
|
|
297
|
-
export function setIosHmsToken(token: string | null): void {
|
|
298
|
-
return NativeSDK.setIosHmsToken(token);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// other tokens
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* iOS-only: sets the APNs token (usually forwarded from AppDelegate).
|
|
305
|
-
*
|
|
306
|
-
* Note:
|
|
307
|
-
* - APNs token is commonly represented as a hex string on native side.
|
|
308
|
-
*
|
|
309
|
-
* @param token APNs token as hex string or null.
|
|
310
|
-
*/
|
|
311
|
-
export function setApnsToken(token: string | null): void {
|
|
312
|
-
return NativeSDK.setApnsToken(token);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Android-only: sets the RuStore token.
|
|
317
|
-
*
|
|
318
|
-
* @param token RuStore token or null.
|
|
319
|
-
*/
|
|
320
|
-
export function setRustoreToken(token: string | null): void {
|
|
321
|
-
return NativeSDK.setRustoreToken(token);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// ---------------- subscription (public: any, native: string) ----------------
|
|
33
|
+
// ---------------- Push subscription ----------------
|
|
325
34
|
|
|
326
35
|
/**
|
|
327
|
-
*
|
|
36
|
+
* Sends a push subscribe request.
|
|
328
37
|
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
38
|
+
* @param sync Execution mode:
|
|
39
|
+
* `true` — sends a synchronous request to the server and returns
|
|
40
|
+
* the result of the operation execution.
|
|
41
|
+
* `false` — sends an asynchronous request and returns
|
|
42
|
+
* the result of task enqueueing on the server.
|
|
43
|
+
* `null` — native default behavior.
|
|
44
|
+
* @param profileFields Optional profile fields to attach to the request.
|
|
45
|
+
* @param customFields Optional custom fields to attach to the request.
|
|
46
|
+
* @param cats Optional categories list.
|
|
47
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
48
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
332
49
|
*/
|
|
333
50
|
export function pushSubscribe(
|
|
334
51
|
sync: boolean | null = true,
|
|
335
|
-
profileFields:
|
|
336
|
-
customFields:
|
|
52
|
+
profileFields: Record<string, unknown> | null = null,
|
|
53
|
+
customFields: Record<string, unknown> | null = null,
|
|
337
54
|
cats: CategoryData[] | null = null,
|
|
338
55
|
replace: boolean | null = null,
|
|
339
56
|
skipTriggers: boolean | null = null
|
|
340
57
|
): void {
|
|
341
58
|
NativeSDK.pushSubscribe(
|
|
342
59
|
sync,
|
|
343
|
-
toNativeStringMap(profileFields),
|
|
344
|
-
toNativeStringMap(customFields),
|
|
60
|
+
Utilities.toNativeStringMap(profileFields),
|
|
61
|
+
Utilities.toNativeStringMap(customFields),
|
|
345
62
|
cats,
|
|
346
63
|
replace,
|
|
347
64
|
skipTriggers
|
|
@@ -349,23 +66,27 @@ export function pushSubscribe(
|
|
|
349
66
|
}
|
|
350
67
|
|
|
351
68
|
/**
|
|
352
|
-
*
|
|
69
|
+
* Sends a push suspend request.
|
|
353
70
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
71
|
+
* @param sync Execution mode (see {@link pushSubscribe}).
|
|
72
|
+
* @param profileFields Optional profile fields.
|
|
73
|
+
* @param customFields Optional custom fields.
|
|
74
|
+
* @param cats Optional categories list.
|
|
75
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
76
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
356
77
|
*/
|
|
357
78
|
export function pushSuspend(
|
|
358
79
|
sync: boolean | null = true,
|
|
359
|
-
profileFields:
|
|
360
|
-
customFields:
|
|
80
|
+
profileFields: Record<string, unknown> | null = null,
|
|
81
|
+
customFields: Record<string, unknown> | null = null,
|
|
361
82
|
cats: CategoryData[] | null = null,
|
|
362
83
|
replace: boolean | null = null,
|
|
363
84
|
skipTriggers: boolean | null = null
|
|
364
85
|
): void {
|
|
365
86
|
NativeSDK.pushSuspend(
|
|
366
87
|
sync,
|
|
367
|
-
toNativeStringMap(profileFields),
|
|
368
|
-
toNativeStringMap(customFields),
|
|
88
|
+
Utilities.toNativeStringMap(profileFields),
|
|
89
|
+
Utilities.toNativeStringMap(customFields),
|
|
369
90
|
cats,
|
|
370
91
|
replace,
|
|
371
92
|
skipTriggers
|
|
@@ -373,235 +94,282 @@ export function pushSuspend(
|
|
|
373
94
|
}
|
|
374
95
|
|
|
375
96
|
/**
|
|
376
|
-
*
|
|
97
|
+
* Sends a push unsubscribe request.
|
|
377
98
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
99
|
+
* @param sync Execution mode (see {@link pushSubscribe}).
|
|
100
|
+
* @param profileFields Optional profile fields.
|
|
101
|
+
* @param customFields Optional custom fields.
|
|
102
|
+
* @param cats Optional categories list.
|
|
103
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
104
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
380
105
|
*/
|
|
381
106
|
export function pushUnSubscribe(
|
|
382
107
|
sync: boolean | null = true,
|
|
383
|
-
profileFields:
|
|
384
|
-
customFields:
|
|
108
|
+
profileFields: Record<string, unknown> | null = null,
|
|
109
|
+
customFields: Record<string, unknown> | null = null,
|
|
385
110
|
cats: CategoryData[] | null = null,
|
|
386
111
|
replace: boolean | null = null,
|
|
387
112
|
skipTriggers: boolean | null = null
|
|
388
113
|
): void {
|
|
389
114
|
NativeSDK.pushUnSubscribe(
|
|
390
115
|
sync,
|
|
391
|
-
toNativeStringMap(profileFields),
|
|
392
|
-
toNativeStringMap(customFields),
|
|
116
|
+
Utilities.toNativeStringMap(profileFields),
|
|
117
|
+
Utilities.toNativeStringMap(customFields),
|
|
393
118
|
cats,
|
|
394
119
|
replace,
|
|
395
120
|
skipTriggers
|
|
396
121
|
);
|
|
397
122
|
}
|
|
398
123
|
|
|
124
|
+
// ---------------- Promise APIs ----------------
|
|
125
|
+
|
|
399
126
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* ⚠️ Can throw (reject):
|
|
403
|
-
* - native validation failure (missing data to create request)
|
|
404
|
-
* - request creation/sending failures
|
|
405
|
-
* - unexpected native exceptions
|
|
127
|
+
* Unsuspends push subscriptions based on native matching rules.
|
|
406
128
|
*
|
|
407
|
-
* @returns
|
|
129
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
408
130
|
*/
|
|
409
131
|
export function unSuspendPushSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
410
132
|
return NativeSDK.unSuspendPushSubscription();
|
|
411
133
|
}
|
|
412
134
|
|
|
413
135
|
/**
|
|
414
|
-
* Returns the status of the latest subscription
|
|
136
|
+
* Returns the status of the latest subscription in profile.
|
|
415
137
|
*
|
|
416
|
-
*
|
|
138
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
417
139
|
*/
|
|
418
140
|
export function getStatusOfLatestSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
419
141
|
return NativeSDK.getStatusOfLatestSubscription();
|
|
420
142
|
}
|
|
421
143
|
|
|
422
144
|
/**
|
|
423
|
-
* Returns the status of the
|
|
424
|
-
* If provider is null, native SDK may use the current provider (SDK-specific).
|
|
145
|
+
* Returns the status of the subscription matching the current push token and provider context.
|
|
425
146
|
*
|
|
426
|
-
*
|
|
427
|
-
* - invalid provider
|
|
428
|
-
* - native request creation/sending failures
|
|
429
|
-
* - unexpected native exceptions
|
|
430
|
-
*
|
|
431
|
-
* @param provider Provider identifier or null.
|
|
147
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
432
148
|
*/
|
|
433
|
-
export function
|
|
434
|
-
|
|
435
|
-
): Promise<ResponseWithHttpCode | null> {
|
|
436
|
-
return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
|
|
149
|
+
export function getStatusForCurrentSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
150
|
+
return NativeSDK.getStatusForCurrentSubscription();
|
|
437
151
|
}
|
|
438
152
|
|
|
439
153
|
/**
|
|
440
|
-
* Returns the status
|
|
441
|
-
* according to native SDK rules.
|
|
154
|
+
* Returns the status of the latest subscription for the given provider.
|
|
442
155
|
*
|
|
443
|
-
*
|
|
156
|
+
* If `provider` is `null`, native side may use the current provider context.
|
|
157
|
+
*
|
|
158
|
+
* @param provider Optional provider identifier (platform-dependent).
|
|
159
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
444
160
|
*/
|
|
445
|
-
export function
|
|
446
|
-
|
|
161
|
+
export function getStatusOfLatestSubscriptionForProvider(
|
|
162
|
+
provider: string | null = null
|
|
163
|
+
): Promise<ResponseWithHttpCode | null> {
|
|
164
|
+
return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
|
|
447
165
|
}
|
|
448
166
|
|
|
449
|
-
// ----------------
|
|
167
|
+
// ---------------- Token API ----------------
|
|
450
168
|
|
|
451
169
|
/**
|
|
452
|
-
* Returns the current push token
|
|
453
|
-
*
|
|
454
|
-
* ⚠️ Can throw (reject) on unexpected native errors.
|
|
170
|
+
* Returns the current push token data from native side.
|
|
455
171
|
*
|
|
456
|
-
*
|
|
172
|
+
* @returns Promise resolving to token info or `null` if token is not available.
|
|
457
173
|
*/
|
|
458
174
|
export function getPushToken(): Promise<TokenData | null> {
|
|
459
175
|
return NativeSDK.getPushToken();
|
|
460
176
|
}
|
|
461
177
|
|
|
462
178
|
/**
|
|
463
|
-
*
|
|
179
|
+
* Sets or clears the push token for a specific provider.
|
|
464
180
|
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* - unexpected native exceptions
|
|
469
|
-
*
|
|
470
|
-
* @param provider Provider identifier (or null; native may treat this as invalid).
|
|
181
|
+
* @param provider Provider identifier (e.g. platform push provider name).
|
|
182
|
+
* @param token Token string or `null` to clear.
|
|
183
|
+
* @returns Promise that resolves when the token is saved on native side.
|
|
471
184
|
*/
|
|
472
|
-
export function
|
|
473
|
-
return NativeSDK.
|
|
185
|
+
export function setPushToken(provider: string, token: string | null): Promise<void> {
|
|
186
|
+
return NativeSDK.setPushToken(provider, token);
|
|
474
187
|
}
|
|
475
188
|
|
|
189
|
+
// ---------------- SDK wrappers ----------------
|
|
190
|
+
|
|
476
191
|
/**
|
|
477
|
-
*
|
|
192
|
+
* Clears SDK local state (native).
|
|
478
193
|
*
|
|
479
|
-
*
|
|
194
|
+
* @returns Promise that resolves after cleanup.
|
|
480
195
|
*/
|
|
481
|
-
export function
|
|
482
|
-
return NativeSDK.
|
|
196
|
+
export function clear(): Promise<void> {
|
|
197
|
+
return NativeSDK.clear();
|
|
483
198
|
}
|
|
484
199
|
|
|
200
|
+
|
|
201
|
+
// ---------------- MobileEvent ----------------
|
|
202
|
+
|
|
485
203
|
/**
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
* ⚠️ Can throw (reject):
|
|
489
|
-
* - invalid provider list (unknown identifiers)
|
|
490
|
-
* - native update flow failure
|
|
491
|
-
* - unexpected native exceptions
|
|
204
|
+
* Sends a mobile event to the server.
|
|
492
205
|
*
|
|
493
|
-
* @param
|
|
206
|
+
* @param sid Pixel identifier.
|
|
207
|
+
* @param eventName Event name.
|
|
208
|
+
* @param sendMessageId Optional message identifier to link the event.
|
|
209
|
+
* @param payload Optional event payload.
|
|
210
|
+
* @param matching Optional matching parameters.
|
|
211
|
+
* @param matchingType Optional matching mode/type.
|
|
212
|
+
* @param profileFields Optional profile fields.
|
|
213
|
+
* @param subscription Optional subscription info to attach (email/sms/push/cc_data).
|
|
214
|
+
* @param utm Optional UTM tags for attribution.
|
|
494
215
|
*/
|
|
495
|
-
export function
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
216
|
+
export function mobileEvent(
|
|
217
|
+
sid: string,
|
|
218
|
+
eventName: string,
|
|
219
|
+
sendMessageId: string | null = null,
|
|
220
|
+
payload: Record<string, unknown> | null = null,
|
|
221
|
+
matching: Record<string, unknown> | null = null,
|
|
222
|
+
matchingType: string | null = null,
|
|
223
|
+
profileFields: Record<string, unknown> | null = null,
|
|
224
|
+
subscription: Subscription | null = null,
|
|
225
|
+
utm: UTM | null = null
|
|
226
|
+
): void {
|
|
227
|
+
NativeSDK.mobileEvent(
|
|
228
|
+
sid,
|
|
229
|
+
eventName,
|
|
230
|
+
sendMessageId,
|
|
231
|
+
Utilities.toNativeStringMap(payload),
|
|
232
|
+
Utilities.toNativeStringMap(matching),
|
|
233
|
+
matchingType,
|
|
234
|
+
Utilities.toNativeStringMap(profileFields),
|
|
235
|
+
Utilities.subscriptionToNativeMap(subscription),
|
|
236
|
+
utm
|
|
237
|
+
);
|
|
499
238
|
}
|
|
500
239
|
|
|
240
|
+
// ---------------- SDK Event API ----------------
|
|
241
|
+
|
|
242
|
+
type EventsSubscription = { remove: () => void } | null;
|
|
243
|
+
const ALTCRAFT_SDK_EVENT_NAME = 'AltcraftSdkEvent' as const;
|
|
244
|
+
const nativeEventEmitter = new NativeEventEmitter(
|
|
245
|
+
NativeModules.SDKEventEmitter
|
|
246
|
+
);
|
|
247
|
+
let eventsSubscription: EventsSubscription = null;
|
|
248
|
+
|
|
501
249
|
/**
|
|
502
|
-
*
|
|
503
|
-
|
|
504
|
-
*
|
|
505
|
-
* ⚠️ Can throw (reject):
|
|
506
|
-
* - provider is invalid/blank (native validation)
|
|
507
|
-
* - native set/delete flow fails
|
|
508
|
-
* - unexpected native exceptions
|
|
250
|
+
* Subscribes to native SDK events and routes them to the provided handler.
|
|
509
251
|
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
252
|
+
* The SDK emits events via `NativeEventEmitter` with name {@link ALTCRAFT_SDK_EVENT_NAME}.
|
|
253
|
+
* Calling this function multiple times replaces the previous JS listener.
|
|
254
|
+
*
|
|
255
|
+
* @param handler Callback invoked for each incoming SDK event.
|
|
256
|
+
* The event object is produced by native and follows {@link SdkEvent}.
|
|
512
257
|
*/
|
|
513
|
-
export function
|
|
514
|
-
|
|
515
|
-
|
|
258
|
+
export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
|
|
259
|
+
if (eventsSubscription) {
|
|
260
|
+
eventsSubscription.remove();
|
|
261
|
+
eventsSubscription = null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Enables native-side subscription (starts producing events).
|
|
265
|
+
NativeSDK.subscribeToEvents();
|
|
516
266
|
|
|
517
|
-
|
|
267
|
+
eventsSubscription = nativeEventEmitter.addListener(
|
|
268
|
+
ALTCRAFT_SDK_EVENT_NAME,
|
|
269
|
+
(...args: unknown[]) => {
|
|
270
|
+
const event = (args[0] ?? null) as SdkEvent | null;
|
|
271
|
+
if (!event) return;
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
handler(event);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
}
|
|
518
281
|
|
|
519
282
|
/**
|
|
520
|
-
*
|
|
283
|
+
* Unsubscribes from native SDK events.
|
|
521
284
|
*
|
|
522
|
-
*
|
|
285
|
+
* Removes the JS listener and instructs native module to stop emitting events.
|
|
286
|
+
* Safe to call even if not subscribed.
|
|
523
287
|
*/
|
|
524
|
-
export function
|
|
525
|
-
|
|
288
|
+
export function unsubscribeFromEvent(): void {
|
|
289
|
+
if (eventsSubscription) {
|
|
290
|
+
eventsSubscription.remove();
|
|
291
|
+
eventsSubscription = null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
NativeSDK.unsubscribeFromEvent();
|
|
526
295
|
}
|
|
527
296
|
|
|
297
|
+
//Android-only behavior
|
|
298
|
+
|
|
299
|
+
// ---------------- Push payload bridge ----------------
|
|
300
|
+
|
|
528
301
|
/**
|
|
529
|
-
*
|
|
530
|
-
*
|
|
302
|
+
* Forwards a push payload to native SDK (Android-only behavior).
|
|
303
|
+
*
|
|
304
|
+
* @param message Push payload map (string-only).
|
|
531
305
|
*/
|
|
532
|
-
export function
|
|
533
|
-
|
|
306
|
+
export function takePush(message: Record<string, string>): void {
|
|
307
|
+
if (!message || Object.keys(message).length === 0) return;
|
|
308
|
+
NativeSDK.takePush({ ...message });
|
|
534
309
|
}
|
|
535
310
|
|
|
536
311
|
/**
|
|
537
|
-
* Requests notification permission (
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
* - Usually no Promise here; native may silently no-op if not supported.
|
|
312
|
+
* Requests notification permission (Android-only behavior).
|
|
313
|
+
* On Android it may trigger runtime permission flow,
|
|
314
|
+
* n iOS it can be a no-op or routed to native implementation.
|
|
541
315
|
*/
|
|
542
316
|
export function requestNotificationPermission(): void {
|
|
543
317
|
return NativeSDK.requestNotificationPermission();
|
|
544
318
|
}
|
|
545
319
|
|
|
546
|
-
// ----------------
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Sends a "mobile event" (non-push event) to Altcraft backend.
|
|
550
|
-
*
|
|
551
|
-
* Note:
|
|
552
|
-
* - This is fire-and-forget and does not return a Promise.
|
|
553
|
-
* - Any errors are expected to be surfaced via SDK Events stream (if enabled) or native logs.
|
|
554
|
-
*/
|
|
555
|
-
export function mobileEvent(
|
|
556
|
-
sid: string,
|
|
557
|
-
eventName: string,
|
|
558
|
-
sendMessageId: string | null = null,
|
|
559
|
-
payload: { [key: string]: any } | null = null,
|
|
560
|
-
matching: { [key: string]: any } | null = null,
|
|
561
|
-
matchingType: string | null = null,
|
|
562
|
-
profileFields: { [key: string]: any } | null = null
|
|
563
|
-
): void {
|
|
564
|
-
NativeSDK.mobileEvent(
|
|
565
|
-
sid,
|
|
566
|
-
eventName,
|
|
567
|
-
sendMessageId,
|
|
568
|
-
toNativeStringMap(payload),
|
|
569
|
-
toNativeStringMap(matching),
|
|
570
|
-
matchingType,
|
|
571
|
-
toNativeStringMap(profileFields)
|
|
572
|
-
);
|
|
573
|
-
}
|
|
320
|
+
// ---------------- Manual push events ----------------
|
|
574
321
|
|
|
575
322
|
/**
|
|
576
|
-
*
|
|
323
|
+
* Reports an Altcraft push delivery event (Android-only behavior).
|
|
577
324
|
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
325
|
+
* @param message Optional push payload (string-only).
|
|
326
|
+
* @param messageUID Optional Altcraft message UID.
|
|
580
327
|
*/
|
|
581
328
|
export function deliveryEvent(
|
|
582
|
-
message:
|
|
329
|
+
message: Record<string, string> | null = null,
|
|
583
330
|
messageUID: string | null = null
|
|
584
331
|
): void {
|
|
585
332
|
const nativePayload =
|
|
586
333
|
message && Object.keys(message).length > 0 ? { ...message } : null;
|
|
587
334
|
|
|
588
|
-
(NativeSDK as
|
|
335
|
+
(NativeSDK as unknown as {
|
|
336
|
+
deliveryEvent: (m: Record<string, string> | null, uid: string | null) => void;
|
|
337
|
+
}).deliveryEvent(nativePayload, messageUID);
|
|
589
338
|
}
|
|
590
339
|
|
|
591
340
|
/**
|
|
592
|
-
*
|
|
341
|
+
* Reports an Altcraft push open event (Android-only behavior).
|
|
593
342
|
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
343
|
+
* @param message Optional push payload (string-only).
|
|
344
|
+
* @param messageUID Optional Altcraft message UID.
|
|
596
345
|
*/
|
|
597
346
|
export function openEvent(
|
|
598
|
-
message:
|
|
347
|
+
message: Record<string, string> | null = null,
|
|
599
348
|
messageUID: string | null = null
|
|
600
349
|
): void {
|
|
601
350
|
const nativePayload =
|
|
602
351
|
message && Object.keys(message).length > 0 ? { ...message } : null;
|
|
603
352
|
|
|
604
|
-
(NativeSDK as
|
|
353
|
+
(NativeSDK as unknown as {
|
|
354
|
+
openEvent: (m: Record<string, string> | null, uid: string | null) => void;
|
|
355
|
+
}).openEvent(nativePayload, messageUID);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ---------------- UserDefaults ----------------
|
|
359
|
+
/**
|
|
360
|
+
* Stores a value into native UserDefaults (IOS-only behavior).
|
|
361
|
+
*
|
|
362
|
+
* @param suiteName iOS App Group suite name or `null` to use standard UserDefaults.
|
|
363
|
+
* @param key Storage key.
|
|
364
|
+
* @param value Any JS value; will be converted to string or removed when `null/undefined`.
|
|
365
|
+
*/
|
|
366
|
+
export function setUserDefaultsValue(
|
|
367
|
+
suiteName: string | null,
|
|
368
|
+
key: string,
|
|
369
|
+
value: unknown
|
|
370
|
+
): void {
|
|
371
|
+
const str = Utilities.toUserDefaultsString(value);
|
|
372
|
+
return NativeSDK.setUserDefaultsValue(suiteName, key, str);
|
|
605
373
|
}
|
|
606
374
|
|
|
607
375
|
// ---------------- Default export ----------------
|
|
@@ -609,62 +377,66 @@ export function openEvent(
|
|
|
609
377
|
/**
|
|
610
378
|
* Public React Native facade for the Altcraft SDK.
|
|
611
379
|
*
|
|
612
|
-
*
|
|
613
|
-
* -
|
|
614
|
-
* -
|
|
615
|
-
* -
|
|
616
|
-
* -
|
|
617
|
-
* -
|
|
618
|
-
* -
|
|
619
|
-
* -
|
|
620
|
-
* - forcedTokenUpdate
|
|
621
|
-
* - changePushProviderPriorityList
|
|
622
|
-
* - setPushToken
|
|
623
|
-
* - clear
|
|
380
|
+
* Provides:
|
|
381
|
+
* - SDK initialization
|
|
382
|
+
* - Push subscription operations
|
|
383
|
+
* - Subscription status queries
|
|
384
|
+
* - SDK event stream via NativeEventEmitter
|
|
385
|
+
* - Mobile events
|
|
386
|
+
* - Push token access
|
|
387
|
+
* - Local storage bridge (UserDefaults/SharedPreferences)
|
|
624
388
|
*/
|
|
625
389
|
const AltcraftSDK = {
|
|
390
|
+
// SDK initialization
|
|
626
391
|
initialize,
|
|
627
|
-
setJwt,
|
|
628
|
-
|
|
629
|
-
setAndroidFcmToken,
|
|
630
|
-
setIosFcmToken,
|
|
631
|
-
setAndroidHmsToken,
|
|
632
|
-
setIosHmsToken,
|
|
633
|
-
|
|
634
|
-
setApnsToken,
|
|
635
|
-
setRustoreToken,
|
|
636
392
|
|
|
393
|
+
// Push subscription
|
|
637
394
|
pushSubscribe,
|
|
638
395
|
pushSuspend,
|
|
639
396
|
pushUnSubscribe,
|
|
640
|
-
|
|
641
397
|
unSuspendPushSubscription,
|
|
398
|
+
|
|
399
|
+
// Profile status
|
|
642
400
|
getStatusOfLatestSubscription,
|
|
643
401
|
getStatusOfLatestSubscriptionForProvider,
|
|
644
402
|
getStatusForCurrentSubscription,
|
|
645
403
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
404
|
+
// SDK events
|
|
405
|
+
subscribeToEvents,
|
|
406
|
+
unsubscribeFromEvent,
|
|
407
|
+
|
|
408
|
+
// Mobile events
|
|
409
|
+
mobileEvent,
|
|
410
|
+
|
|
411
|
+
// Push token
|
|
650
412
|
setPushToken,
|
|
413
|
+
getPushToken,
|
|
651
414
|
|
|
415
|
+
// Clear SDK data
|
|
652
416
|
clear,
|
|
653
|
-
reinitializeRetryControlInThisSession,
|
|
654
|
-
requestNotificationPermission,
|
|
655
417
|
|
|
656
|
-
|
|
418
|
+
// Set UserDefault / SharedPreferenses
|
|
419
|
+
setUserDefaultsValue,
|
|
657
420
|
|
|
658
|
-
|
|
659
|
-
registerPushReceiver,
|
|
660
|
-
clearPushReceivers,
|
|
421
|
+
// Android only
|
|
661
422
|
takePush,
|
|
662
|
-
|
|
663
|
-
subscribeToEvents,
|
|
664
|
-
unsubscribeFromEvent,
|
|
665
|
-
|
|
666
423
|
deliveryEvent,
|
|
667
424
|
openEvent,
|
|
425
|
+
requestNotificationPermission,
|
|
668
426
|
};
|
|
669
427
|
|
|
670
428
|
export default AltcraftSDK;
|
|
429
|
+
|
|
430
|
+
export type {
|
|
431
|
+
AltcraftConfig,
|
|
432
|
+
CategoryData,
|
|
433
|
+
ResponseWithHttpCode,
|
|
434
|
+
TokenData,
|
|
435
|
+
EmailSubscription,
|
|
436
|
+
SmsSubscription,
|
|
437
|
+
PushSubscription,
|
|
438
|
+
CcDataSubscription,
|
|
439
|
+
Subscription,
|
|
440
|
+
UTM,
|
|
441
|
+
SdkEvent,
|
|
442
|
+
};
|