@altcraft/react-native-sdk 0.0.2 → 0.0.4

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 (36) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +119 -27
  3. package/Sdk.podspec +2 -2
  4. package/android/build.gradle +3 -4
  5. package/android/src/main/java/com/altcraft/sdk/SdkEventEmitter.kt +50 -0
  6. package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +663 -480
  7. package/android/src/main/java/com/altcraft/sdk/SdkPackage.kt +16 -8
  8. package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +164 -0
  9. package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +72 -0
  10. package/ios/Converter.swift +485 -48
  11. package/ios/Sdk.mm +195 -270
  12. package/ios/SdkModule.swift +456 -507
  13. package/lib/module/NativeSdk.js +35 -0
  14. package/lib/module/NativeSdk.js.map +1 -1
  15. package/lib/module/Utilities.js +178 -0
  16. package/lib/module/Utilities.js.map +1 -0
  17. package/lib/module/index.js +335 -245
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/typescript/src/NativeSdk.d.ts +125 -33
  20. package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
  21. package/lib/typescript/src/Utilities.d.ts +47 -0
  22. package/lib/typescript/src/Utilities.d.ts.map +1 -0
  23. package/lib/typescript/src/index.d.ts +218 -94
  24. package/lib/typescript/src/index.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/NativeSdk.ts +169 -46
  27. package/src/Utilities.ts +180 -0
  28. package/src/index.tsx +410 -312
  29. package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -26
  30. package/android/src/main/java/com/altcraft/sdk/interfaces/RnHMSProvider.kt +0 -32
  31. package/android/src/main/java/com/altcraft/sdk/interfaces/RnJWTProvider.kt +0 -21
  32. package/android/src/main/java/com/altcraft/sdk/interfaces/RnRustoreProvider.kt +0 -53
  33. package/ios/protocols/RNAPNSProvider.swift +0 -15
  34. package/ios/protocols/RNFCMProvider.swift +0 -24
  35. package/ios/protocols/RNHMSProvider.swift +0 -24
  36. package/ios/protocols/RNJWTProvider.swift +0 -15
package/src/index.tsx CHANGED
@@ -5,233 +5,48 @@ import NativeSDK, {
5
5
  type CategoryData,
6
6
  type ResponseWithHttpCode,
7
7
  type TokenData,
8
+ type EmailSubscription,
9
+ type SmsSubscription,
10
+ type PushSubscription,
11
+ type CcDataSubscription,
12
+ type Subscription,
13
+ type UTM,
14
+ type SdkEvent,
8
15
  } from './NativeSdk';
9
16
 
10
- /** SDK event payload emitted from native via NativeEventEmitter ("AltcraftSdkEvent"). */
11
- export type SdkEvent = {
12
- function: string;
13
- code: number | null;
14
- message: string;
15
- type: 'event' | 'error' | 'retryError';
16
- value?: Record<string, unknown> | null;
17
- };
18
-
19
- /** UTM tags for mobileEvent attribution. */
20
- export type UTM = {
21
- campaign?: string | null;
22
- content?: string | null;
23
- keyword?: string | null;
24
- medium?: string | null;
25
- source?: string | null;
26
- temp?: string | null;
27
- };
28
-
29
- // ---------------- Utilities ----------------
30
-
31
- /** Converts a JS object to { [key: string]: string } for the RN bridge; drops null/undefined. */
32
- function toNativeStringMap(
33
- input: Record<string, unknown> | null
34
- ): Record<string, string> | null {
35
- if (input == null) return null;
36
-
37
- const out: Record<string, string> = {};
38
-
39
- for (const [key, value] of Object.entries(input)) {
40
- if (value == null) continue;
41
-
42
- switch (typeof value) {
43
- case 'string':
44
- out[key] = value;
45
- break;
46
-
47
- case 'number':
48
- case 'boolean':
49
- case 'bigint':
50
- out[key] = String(value);
51
- break;
17
+ import { Utilities, ActionFieldBuilder, actionField } from './Utilities';
52
18
 
53
- default:
54
- try {
55
- out[key] = JSON.stringify(value);
56
- } catch {
57
- out[key] = String(value);
58
- }
59
- break;
60
- }
61
- }
62
-
63
- return Object.keys(out).length > 0 ? out : null;
64
- }
65
-
66
- /**
67
- * New Arch safe:
68
- * TurboModule codegen does NOT support `any`.
69
- * Therefore, we serialize any value for UserDefaults into `string`:
70
- * - string -> as-is
71
- * - number/boolean -> String(...)
72
- * - object/array -> JSON.stringify(...)
73
- * - null/undefined -> null (native side can treat it as “remove key”)
74
- */
75
- function toUserDefaultsString(value: unknown): string | null {
76
- if (value == null) return null;
77
-
78
- const t = typeof value;
79
-
80
- if (t === 'string') return String(value);
81
- if (t === 'number' || t === 'boolean') return String(value);
82
-
83
- try {
84
- return JSON.stringify(value);
85
- } catch {
86
- return String(value);
87
- }
88
- }
89
-
90
- // ---------------- PushReceiver API (JS-side) ----------------
91
-
92
- /** JS handler interface for incoming push payloads. */
93
- export abstract class PushReceiver {
94
- /** Called with a flat push payload map. */
95
- abstract pushHandler(message: Record<string, string>): void;
96
- }
97
-
98
- /** Registered JS receivers for push payloads. */
99
- const registeredPushReceivers: PushReceiver[] = [];
100
-
101
- /** Registers a JS push receiver. */
102
- export function registerPushReceiver(receiver: PushReceiver): void {
103
- registeredPushReceivers.push(receiver);
104
- }
105
-
106
- /** Clears all JS push receivers. */
107
- export function clearPushReceivers(): void {
108
- registeredPushReceivers.length = 0;
109
- }
110
-
111
- /** Default receiver used when none are registered. */
112
- class DefaultPushReceiver extends PushReceiver {
113
- override pushHandler(message: Record<string, string>): void {
114
- // eslint-disable-next-line no-console
115
- console.log('[AltcraftSDK] Default push handler:', message);
116
- }
117
- }
19
+ // ---------------- SDK API ----------------
118
20
 
119
21
  /**
120
- * Forwards a push payload to native SDK and then to JS receivers.
121
- * This does not intercept system notifications by itself.
22
+ * Initializes the Altcraft SDK.
23
+ *
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.
122
28
  */
123
- export function takePush(message: Record<string, string>): void {
124
- if (!message || Object.keys(message).length === 0) return;
125
-
126
- NativeSDK.takePush({ ...message });
127
-
128
- const receivers =
129
- registeredPushReceivers.length > 0
130
- ? registeredPushReceivers
131
- : [new DefaultPushReceiver()];
132
-
133
- for (const receiver of receivers) {
134
- try {
135
- receiver.pushHandler(message);
136
- } catch (e) {
137
- // eslint-disable-next-line no-console
138
- console.warn('[AltcraftSDK] PushReceiver error:', e);
139
- }
140
- }
141
- }
142
-
143
- // ---------------- Events API for RN ----------------
144
-
145
- /** RN subscription handle (NativeEventEmitter). */
146
- type EventsSubscription = { remove: () => void } | null;
147
-
148
- /** Native emitter for "AltcraftSdkEvent". */
149
- const nativeEventEmitter = new NativeEventEmitter(NativeModules.SDKEventEmitter);
150
-
151
- /** Current JS-side subscription. */
152
- let eventsSubscription: EventsSubscription = null;
153
-
154
- /** Subscribes to native SDK events and routes them to the handler. */
155
- export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
156
- if (eventsSubscription) {
157
- eventsSubscription.remove();
158
- eventsSubscription = null;
159
- }
160
-
161
- NativeSDK.subscribeToEvents();
162
-
163
- eventsSubscription = nativeEventEmitter.addListener(
164
- 'AltcraftSdkEvent',
165
- (...args: unknown[]) => {
166
- const event = (args[0] ?? null) as SdkEvent | null;
167
- if (!event) return;
168
-
169
- try {
170
- handler(event);
171
- } catch (e) {
172
- console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
173
- }
174
- }
175
- );
176
- }
177
-
178
- /** Unsubscribes from native SDK events. */
179
- export function unsubscribeFromEvent(): void {
180
- if (eventsSubscription) {
181
- eventsSubscription.remove();
182
- eventsSubscription = null;
183
- }
184
-
185
- NativeSDK.unsubscribeFromEvent();
186
- }
187
-
188
- // ---------------- SDK API ----------------
189
-
190
- /** Initializes the Altcraft SDK. */
191
29
  export function initialize(config: AltcraftConfig): Promise<void> {
192
30
  return NativeSDK.initialize(config);
193
31
  }
194
32
 
195
- /** Sets or clears the JWT used by the SDK. */
196
- export function setJwt(token: string | null): void {
197
- return NativeSDK.setJwt(token);
198
- }
33
+ // ---------------- Push subscription ----------------
199
34
 
200
- // platform-specific token setters
201
-
202
- /** Android-only: sets FCM token. */
203
- export function setAndroidFcmToken(token: string | null): void {
204
- return NativeSDK.setAndroidFcmToken(token);
205
- }
206
-
207
- /** iOS-only: sets FCM token. */
208
- export function setIosFcmToken(token: string | null): void {
209
- return NativeSDK.setIosFcmToken(token);
210
- }
211
-
212
- /** Android-only: sets HMS token. */
213
- export function setAndroidHmsToken(token: string | null): void {
214
- return NativeSDK.setAndroidHmsToken(token);
215
- }
216
-
217
- /** iOS-only: sets HMS token. */
218
- export function setIosHmsToken(token: string | null): void {
219
- return NativeSDK.setIosHmsToken(token);
220
- }
221
-
222
- /** iOS-only: sets APNs token. */
223
- export function setApnsToken(token: string | null): void {
224
- return NativeSDK.setApnsToken(token);
225
- }
226
-
227
- /** Android-only: sets RuStore token. */
228
- export function setRustoreToken(token: string | null): void {
229
- return NativeSDK.setRustoreToken(token);
230
- }
231
-
232
- // ---------------- subscription (public: unknown, native: string) ----------------
233
-
234
- /** Push subscribe (fire-and-forget). */
35
+ /**
36
+ * Sends a push subscribe request.
37
+ *
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.
49
+ */
235
50
  export function pushSubscribe(
236
51
  sync: boolean | null = true,
237
52
  profileFields: Record<string, unknown> | null = null,
@@ -242,15 +57,24 @@ export function pushSubscribe(
242
57
  ): void {
243
58
  NativeSDK.pushSubscribe(
244
59
  sync,
245
- toNativeStringMap(profileFields),
246
- toNativeStringMap(customFields),
60
+ Utilities.toNativeStringMap(profileFields),
61
+ Utilities.toNativeStringMap(customFields),
247
62
  cats,
248
63
  replace,
249
64
  skipTriggers
250
65
  );
251
66
  }
252
67
 
253
- /** Push suspend (fire-and-forget). */
68
+ /**
69
+ * Sends a push suspend request.
70
+ *
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.
77
+ */
254
78
  export function pushSuspend(
255
79
  sync: boolean | null = true,
256
80
  profileFields: Record<string, unknown> | null = null,
@@ -261,15 +85,24 @@ export function pushSuspend(
261
85
  ): void {
262
86
  NativeSDK.pushSuspend(
263
87
  sync,
264
- toNativeStringMap(profileFields),
265
- toNativeStringMap(customFields),
88
+ Utilities.toNativeStringMap(profileFields),
89
+ Utilities.toNativeStringMap(customFields),
266
90
  cats,
267
91
  replace,
268
92
  skipTriggers
269
93
  );
270
94
  }
271
95
 
272
- /** Push unsubscribe (fire-and-forget). */
96
+ /**
97
+ * Sends a push unsubscribe request.
98
+ *
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.
105
+ */
273
106
  export function pushUnSubscribe(
274
107
  sync: boolean | null = true,
275
108
  profileFields: Record<string, unknown> | null = null,
@@ -280,97 +113,108 @@ export function pushUnSubscribe(
280
113
  ): void {
281
114
  NativeSDK.pushUnSubscribe(
282
115
  sync,
283
- toNativeStringMap(profileFields),
284
- toNativeStringMap(customFields),
116
+ Utilities.toNativeStringMap(profileFields),
117
+ Utilities.toNativeStringMap(customFields),
285
118
  cats,
286
119
  replace,
287
120
  skipTriggers
288
121
  );
289
122
  }
290
123
 
291
- /** Un-suspends push subscription and returns response (if any). */
124
+ // ---------------- Promise APIs ----------------
125
+
126
+ /**
127
+ * Unsuspends push subscriptions based on native matching rules.
128
+ *
129
+ * @returns Promise resolving to response with HTTP code or `null` if unavailable.
130
+ */
292
131
  export function unSuspendPushSubscription(): Promise<ResponseWithHttpCode | null> {
293
132
  return NativeSDK.unSuspendPushSubscription();
294
133
  }
295
134
 
296
- /** Returns latest subscription status (if any). */
135
+ /**
136
+ * Returns the status of the latest subscription in profile.
137
+ *
138
+ * @returns Promise resolving to response with HTTP code or `null` if unavailable.
139
+ */
297
140
  export function getStatusOfLatestSubscription(): Promise<ResponseWithHttpCode | null> {
298
141
  return NativeSDK.getStatusOfLatestSubscription();
299
142
  }
300
143
 
301
- /** Returns latest subscription status for a provider (if any). */
144
+ /**
145
+ * Returns the status of the subscription matching the current push token and provider context.
146
+ *
147
+ * @returns Promise resolving to response with HTTP code or `null` if unavailable.
148
+ */
149
+ export function getStatusForCurrentSubscription(): Promise<ResponseWithHttpCode | null> {
150
+ return NativeSDK.getStatusForCurrentSubscription();
151
+ }
152
+
153
+ /**
154
+ * Returns the status of the latest subscription for the given provider.
155
+ *
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.
160
+ */
302
161
  export function getStatusOfLatestSubscriptionForProvider(
303
162
  provider: string | null = null
304
163
  ): Promise<ResponseWithHttpCode | null> {
305
164
  return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
306
165
  }
307
166
 
308
- /** Returns current subscription status (if any). */
309
- export function getStatusForCurrentSubscription(): Promise<ResponseWithHttpCode | null> {
310
- return NativeSDK.getStatusForCurrentSubscription();
311
- }
312
-
313
- // ---------------- token public API ----------------
167
+ // ---------------- Token API ----------------
314
168
 
315
- /** Returns current push token (or null). */
169
+ /**
170
+ * Returns the current push token data from native side.
171
+ *
172
+ * @returns Promise resolving to token info or `null` if token is not available.
173
+ */
316
174
  export function getPushToken(): Promise<TokenData | null> {
317
175
  return NativeSDK.getPushToken();
318
176
  }
319
177
 
320
- /** Deletes device token for provider. */
321
- export function deleteDeviceToken(provider: string | null): Promise<void> {
322
- return NativeSDK.deleteDeviceToken(provider);
323
- }
324
-
325
- /** Forces token refresh flow. */
326
- export function forcedTokenUpdate(): Promise<void> {
327
- return NativeSDK.forcedTokenUpdate();
328
- }
329
-
330
- /** Updates provider priority list. */
331
- export function changePushProviderPriorityList(
332
- priorityList: string[] | null
178
+ /**
179
+ * Sets or clears the push token for a specific provider.
180
+ *
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.
184
+ */
185
+ export function setPushToken(
186
+ provider: string,
187
+ token: string | null
333
188
  ): Promise<void> {
334
- return NativeSDK.changePushProviderPriorityList(priorityList);
335
- }
336
-
337
- /** Sets or clears token for a specific provider. */
338
- export function setPushToken(provider: string, token: string | null): Promise<void> {
339
189
  return NativeSDK.setPushToken(provider, token);
340
190
  }
341
191
 
342
- // ---------------- sdk wrappers ----------------
192
+ // ---------------- SDK wrappers ----------------
343
193
 
344
- /** Clears SDK local state. */
194
+ /**
195
+ * Clears SDK local state (native).
196
+ *
197
+ * @returns Promise that resolves after cleanup.
198
+ */
345
199
  export function clear(): Promise<void> {
346
200
  return NativeSDK.clear();
347
201
  }
348
202
 
349
- /** Resets session init-control state (platform-dependent). */
350
- export function unlockInitOperationsInThisSession(): void {
351
- return NativeSDK.unlockInitOperationsInThisSession();
352
- }
353
-
354
- /** Requests notification permission (platform-dependent). */
355
- export function requestNotificationPermission(): void {
356
- return NativeSDK.requestNotificationPermission();
357
- }
358
-
359
- // ---------------- UserDefaults / SharedPreferences ----------------
360
-
361
- /** Stores a value into native UserDefaults / SharedPreferences (platform-dependent). */
362
- export function setUserDefaultsValue(
363
- suiteName: string | null,
364
- key: string,
365
- value: unknown
366
- ): void {
367
- const str = toUserDefaultsString(value);
368
- return NativeSDK.setUserDefaultsValue(suiteName, key, str);
369
- }
370
-
371
- // ---------------- MobileEvent (public: unknown, native: string) ----------------
203
+ // ---------------- MobileEvent ----------------
372
204
 
373
- /** Sends a mobile event (fire-and-forget). */
205
+ /**
206
+ * Sends a mobile event to the server.
207
+ *
208
+ * @param sid Pixel identifier.
209
+ * @param eventName Event name.
210
+ * @param sendMessageId Optional message identifier to link the event.
211
+ * @param payload Optional event payload.
212
+ * @param matching Optional matching parameters.
213
+ * @param matchingType Optional matching mode/type.
214
+ * @param profileFields Optional profile fields.
215
+ * @param subscription Optional subscription info to attach (email/sms/push/cc_data).
216
+ * @param utm Optional UTM tags for attribution.
217
+ */
374
218
  export function mobileEvent(
375
219
  sid: string,
376
220
  eventName: string,
@@ -379,21 +223,122 @@ export function mobileEvent(
379
223
  matching: Record<string, unknown> | null = null,
380
224
  matchingType: string | null = null,
381
225
  profileFields: Record<string, unknown> | null = null,
226
+ subscription: Subscription | null = null,
382
227
  utm: UTM | null = null
383
228
  ): void {
384
229
  NativeSDK.mobileEvent(
385
230
  sid,
386
231
  eventName,
387
232
  sendMessageId,
388
- toNativeStringMap(payload),
389
- toNativeStringMap(matching),
233
+ Utilities.toNativeStringMap(payload),
234
+ Utilities.toNativeStringMap(matching),
390
235
  matchingType,
391
- toNativeStringMap(profileFields),
392
- utm
236
+ Utilities.toNativeStringMap(profileFields),
237
+ Utilities.subscriptionToNativeMap(subscription),
238
+ utm ?? { campaign: null, content: null, keyword: null, medium: null, source: null, temp: null }
393
239
  );
394
240
  }
395
241
 
396
- /** Manually records a push delivery event (fire-and-forget). */
242
+ // ---------------- SDK Event API ----------------
243
+
244
+ type EventsSubscription = { remove: () => void } | null;
245
+ const ALTCRAFT_SDK_EVENT_NAME = 'AltcraftSdkEvent' as const;
246
+ const nativeEventEmitter = new NativeEventEmitter(
247
+ NativeModules.SDKEventEmitter
248
+ );
249
+
250
+ let eventsSubscription: EventsSubscription = null;
251
+ const eventHandlers = new Set<(event: SdkEvent) => void>();
252
+
253
+ function ensureNativeSubscription(): void {
254
+ if (eventsSubscription === null) {
255
+ NativeSDK.subscribeToEvents();
256
+ eventsSubscription = nativeEventEmitter.addListener(
257
+ ALTCRAFT_SDK_EVENT_NAME,
258
+ (...args: unknown[]) => {
259
+ const event = (args[0] ?? null) as SdkEvent | null;
260
+ if (!event) return;
261
+
262
+ const handlers = Array.from(eventHandlers);
263
+ for (const handler of handlers) {
264
+ try {
265
+ handler(event);
266
+ } catch (e) {
267
+ console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
268
+ }
269
+ }
270
+ }
271
+ );
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Subscribes to native SDK events and routes them to the provided handler.
277
+ *
278
+ * Multiple callers can subscribe independently — each handler receives every event.
279
+ * The native subscription is activated only once (first caller).
280
+ *
281
+ * @param handler Callback invoked for each incoming SDK event.
282
+ * The event object is produced by native and follows {@link SdkEvent}.
283
+ */
284
+ export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
285
+ eventHandlers.add(handler);
286
+ ensureNativeSubscription();
287
+ }
288
+
289
+ /**
290
+ * Unsubscribes a specific handler from native SDK events.
291
+ *
292
+ * When the last handler is removed, the native subscription is also released.
293
+ * Safe to call even if not subscribed.
294
+ */
295
+ export function unsubscribeFromEvent(
296
+ handler?: (event: SdkEvent) => void
297
+ ): void {
298
+ if (handler) {
299
+ eventHandlers.delete(handler);
300
+ }
301
+
302
+ if (eventHandlers.size === 0) {
303
+ if (eventsSubscription) {
304
+ eventsSubscription.remove();
305
+ eventsSubscription = null;
306
+ }
307
+ NativeSDK.unsubscribeFromEvent();
308
+ }
309
+ }
310
+
311
+ //Android-only behavior
312
+
313
+ // ---------------- Push payload bridge ----------------
314
+
315
+ /**
316
+ * Forwards a push payload to native SDK (Android-only behavior).
317
+ *
318
+ * @param message Push payload map (string-only).
319
+ */
320
+ export function takePush(message: Record<string, string>): void {
321
+ if (!message || Object.keys(message).length === 0) return;
322
+ NativeSDK.takePush({ ...message });
323
+ }
324
+
325
+ /**
326
+ * Requests notification permission (Android-only behavior).
327
+ * On Android it may trigger runtime permission flow,
328
+ * n iOS it can be a no-op or routed to native implementation.
329
+ */
330
+ export function requestNotificationPermission(): void {
331
+ return NativeSDK.requestNotificationPermission();
332
+ }
333
+
334
+ // ---------------- Manual push events ----------------
335
+
336
+ /**
337
+ * Reports an Altcraft push delivery event (Android-only behavior).
338
+ *
339
+ * @param message Optional push payload (string-only).
340
+ * @param messageUID Optional Altcraft message UID.
341
+ */
397
342
  export function deliveryEvent(
398
343
  message: Record<string, string> | null = null,
399
344
  messageUID: string | null = null
@@ -401,12 +346,22 @@ export function deliveryEvent(
401
346
  const nativePayload =
402
347
  message && Object.keys(message).length > 0 ? { ...message } : null;
403
348
 
404
- // Kept as runtime call for backward-compat if some platform exposes it outside codegen.
405
- (NativeSDK as unknown as { deliveryEvent: (m: Record<string, string> | null, uid: string | null) => void })
406
- .deliveryEvent(nativePayload, messageUID);
349
+ (
350
+ NativeSDK as unknown as {
351
+ deliveryEvent: (
352
+ m: Record<string, string> | null,
353
+ uid: string | null
354
+ ) => void;
355
+ }
356
+ ).deliveryEvent(nativePayload, messageUID);
407
357
  }
408
358
 
409
- /** Manually records a push open event (fire-and-forget). */
359
+ /**
360
+ * Reports an Altcraft push open event (Android-only behavior).
361
+ *
362
+ * @param message Optional push payload (string-only).
363
+ * @param messageUID Optional Altcraft message UID.
364
+ */
410
365
  export function openEvent(
411
366
  message: Record<string, string> | null = null,
412
367
  messageUID: string | null = null
@@ -414,59 +369,202 @@ export function openEvent(
414
369
  const nativePayload =
415
370
  message && Object.keys(message).length > 0 ? { ...message } : null;
416
371
 
417
- // Kept as runtime call for backward-compat if some platform exposes it outside codegen.
418
- (NativeSDK as unknown as { openEvent: (m: Record<string, string> | null, uid: string | null) => void })
419
- .openEvent(nativePayload, messageUID);
372
+ (
373
+ NativeSDK as unknown as {
374
+ openEvent: (m: Record<string, string> | null, uid: string | null) => void;
375
+ }
376
+ ).openEvent(nativePayload, messageUID);
377
+ }
378
+
379
+ // ---------------- UserDefaults ----------------
380
+ /**
381
+ * Stores a value into native UserDefaults (IOS-only behavior).
382
+ *
383
+ * @param suiteName iOS App Group suite name or `null` to use standard UserDefaults.
384
+ * @param key Storage key.
385
+ * @param value Any JS value; will be converted to string or removed when `null/undefined`.
386
+ */
387
+ export function setUserDefaultsValue(
388
+ suiteName: string | null,
389
+ key: string,
390
+ value: unknown
391
+ ): void {
392
+ const str = Utilities.toUserDefaultsString(value);
393
+ return NativeSDK.setUserDefaultsValue(suiteName, key, str);
394
+ }
395
+
396
+ // ---------------- Profile API ----------------
397
+
398
+ /**
399
+ * Updates profile fields on the server.
400
+ *
401
+ * @param profileFields Optional profile fields to update.
402
+ * @param skipTriggers Optional flag to skip trigger execution on the server.
403
+ */
404
+ export function updateProfileFields(
405
+ profileFields: Record<string, unknown> | null = null,
406
+ skipTriggers: boolean | null = null
407
+ ): void {
408
+ NativeSDK.updateProfileFields(
409
+ Utilities.toNativeStringMap(profileFields),
410
+ skipTriggers
411
+ );
412
+ }
413
+
414
+ // ---------------- Token management API ----------------
415
+
416
+ /**
417
+ * Forces a push token refresh (delete current token + re-register).
418
+ *
419
+ * @returns Promise that resolves when the token update flow completes.
420
+ */
421
+ export function forcedTokenUpdate(): Promise<void> {
422
+ return NativeSDK.forcedTokenUpdate();
423
+ }
424
+
425
+ /**
426
+ * Deletes the device token for a given provider.
427
+ *
428
+ * @param provider Provider identifier (e.g. `android-firebase`, `ios-firebase`).
429
+ * @returns Promise that resolves when the delete call completes.
430
+ */
431
+ export function deleteDeviceToken(provider: string): Promise<void> {
432
+ return NativeSDK.deleteDeviceToken(provider);
433
+ }
434
+
435
+ /**
436
+ * Changes the push provider priority list at runtime.
437
+ *
438
+ * @param priorityList Ordered list of provider identifiers.
439
+ * @returns Promise that resolves when the priority list is updated.
440
+ */
441
+ export function changePushProviderPriorityList(
442
+ priorityList: string[] | null
443
+ ): Promise<void> {
444
+ if (!priorityList || priorityList.length === 0) {
445
+ return Promise.resolve();
446
+ }
447
+ return NativeSDK.changePushProviderPriorityList(priorityList);
448
+ }
449
+
450
+ // ---------------- PushReceiver helpers ----------------
451
+
452
+ /**
453
+ * Checks whether a push payload belongs to Altcraft.
454
+ *
455
+ * @param message Push payload map (string-only).
456
+ * @returns `true` if the message contains the Altcraft marker key.
457
+ */
458
+ export function isAltcraftPush(message: Record<string, string>): boolean {
459
+ if (!message || Object.keys(message).length === 0) return false;
460
+ return NativeSDK.isAltcraftPush({ ...message });
461
+ }
462
+
463
+ // ---------------- SDK lifecycle ----------------
464
+
465
+ /**
466
+ * Allows re-running initial retry/scheduling/token-check logic
467
+ * in this process on the next initialization (Android only).
468
+ * No-op on iOS.
469
+ */
470
+ export function unlockInitialOperationsInThisSession(): void {
471
+ NativeSDK.unlockInitialOperationsInThisSession();
472
+ }
473
+
474
+ // ---------------- iOS-only ----------------
475
+
476
+ /**
477
+ * Sets the App Group name for shared UserDefaults and Core Data (iOS only).
478
+ * Must be called before SDK initialization.
479
+ *
480
+ * @param groupName App Group identifier or `null` to clear.
481
+ */
482
+ export function setAppGroup(groupName: string | null): void {
483
+ NativeSDK.setAppGroup(groupName);
420
484
  }
421
485
 
422
486
  // ---------------- Default export ----------------
423
487
 
424
- /** Public React Native facade for the Altcraft SDK. */
488
+ /**
489
+ * Public React Native facade for the Altcraft SDK.
490
+ *
491
+ * Provides:
492
+ * - SDK initialization
493
+ * - Push subscription operations
494
+ * - Subscription status queries
495
+ * - SDK event stream via NativeEventEmitter
496
+ * - Mobile events
497
+ * - Push token access
498
+ * - Local storage bridge (UserDefaults/SharedPreferences)
499
+ */
425
500
  const AltcraftSDK = {
501
+ // SDK initialization
426
502
  initialize,
427
- setJwt,
428
503
 
504
+ // Push subscription
429
505
  pushSubscribe,
430
506
  pushSuspend,
431
507
  pushUnSubscribe,
432
508
  unSuspendPushSubscription,
509
+
510
+ // Profile status
433
511
  getStatusOfLatestSubscription,
434
512
  getStatusOfLatestSubscriptionForProvider,
435
513
  getStatusForCurrentSubscription,
436
514
 
437
- getPushToken,
438
- deleteDeviceToken,
439
- forcedTokenUpdate,
440
- changePushProviderPriorityList,
441
- setPushToken,
442
-
515
+ // SDK events
516
+ subscribeToEvents,
517
+ unsubscribeFromEvent,
443
518
 
519
+ // Mobile events
444
520
  mobileEvent,
445
521
 
446
- subscribeToEvents,
447
- unsubscribeFromEvent,
522
+ // Push token
523
+ setPushToken,
524
+ getPushToken,
448
525
 
526
+ // Clear SDK data
449
527
  clear,
450
528
 
451
- //ios only
452
- setIosFcmToken,
453
- setIosHmsToken,
454
- setApnsToken,
529
+ // Set UserDefault / SharedPreferenses
455
530
  setUserDefaultsValue,
456
531
 
457
- //android only
458
- setAndroidFcmToken,
459
- setAndroidHmsToken,
460
- setRustoreToken,
461
- PushReceiver,
462
- registerPushReceiver,
463
- clearPushReceivers,
532
+ // Android only
464
533
  takePush,
465
534
  deliveryEvent,
466
535
  openEvent,
467
- unlockInitOperationsInThisSession,
468
536
  requestNotificationPermission,
537
+ unlockInitialOperationsInThisSession,
469
538
 
539
+ // Profile API
540
+ updateProfileFields,
541
+
542
+ // Token management
543
+ forcedTokenUpdate,
544
+ deleteDeviceToken,
545
+ changePushProviderPriorityList,
546
+
547
+ // PushReceiver helpers
548
+ isAltcraftPush,
549
+
550
+ // iOS only
551
+ setAppGroup,
470
552
  };
471
553
 
472
554
  export default AltcraftSDK;
555
+
556
+ export { ActionFieldBuilder, actionField };
557
+
558
+ export type {
559
+ AltcraftConfig,
560
+ CategoryData,
561
+ ResponseWithHttpCode,
562
+ TokenData,
563
+ EmailSubscription,
564
+ SmsSubscription,
565
+ PushSubscription,
566
+ CcDataSubscription,
567
+ Subscription,
568
+ UTM,
569
+ SdkEvent,
570
+ };