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