@altcraft/react-native-sdk 0.0.1 → 0.0.2
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/android/build.gradle +1 -1
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +53 -529
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -1
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +162 -0
- package/ios/Converter.swift +203 -0
- package/ios/Sdk.h +4 -3
- package/ios/Sdk.mm +74 -132
- package/ios/SdkModule.swift +260 -319
- package/lib/module/NativeSdk.js.map +1 -1
- package/lib/module/index.js +124 -341
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSdk.d.ts +11 -2
- package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +69 -332
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeSdk.ts +25 -6
- package/src/index.tsx +170 -368
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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,
|
|
@@ -6,137 +7,124 @@ import NativeSDK, {
|
|
|
6
7
|
type TokenData,
|
|
7
8
|
} from './NativeSdk';
|
|
8
9
|
|
|
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
|
-
*/
|
|
10
|
+
/** SDK event payload emitted from native via NativeEventEmitter ("AltcraftSdkEvent"). */
|
|
23
11
|
export type SdkEvent = {
|
|
24
12
|
function: string;
|
|
25
13
|
code: number | null;
|
|
26
14
|
message: string;
|
|
27
15
|
type: 'event' | 'error' | 'retryError';
|
|
28
|
-
value?:
|
|
16
|
+
value?: Record<string, unknown> | null;
|
|
29
17
|
};
|
|
30
18
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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. */
|
|
43
32
|
function toNativeStringMap(
|
|
44
|
-
input:
|
|
45
|
-
):
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
const out:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
52
|
+
|
|
53
|
+
default:
|
|
54
|
+
try {
|
|
55
|
+
out[key] = JSON.stringify(value);
|
|
56
|
+
} catch {
|
|
57
|
+
out[key] = String(value);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
return Object.keys(out).length > 0 ? out : null;
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* -
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* -
|
|
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)
|
|
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”)
|
|
70
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. */
|
|
71
93
|
export abstract class PushReceiver {
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
* @param message Flat `Record<string, string>` (matches typical data payload shape).
|
|
76
|
-
*/
|
|
77
|
-
abstract pushHandler(message: { [key: string]: string }): void;
|
|
94
|
+
/** Called with a flat push payload map. */
|
|
95
|
+
abstract pushHandler(message: Record<string, string>): void;
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
/**
|
|
81
|
-
* Registered JS receivers for push payload dispatch.
|
|
82
|
-
* If none are registered, a DefaultPushReceiver will log the payload.
|
|
83
|
-
*/
|
|
98
|
+
/** Registered JS receivers for push payloads. */
|
|
84
99
|
const registeredPushReceivers: PushReceiver[] = [];
|
|
85
100
|
|
|
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
|
-
*/
|
|
101
|
+
/** Registers a JS push receiver. */
|
|
93
102
|
export function registerPushReceiver(receiver: PushReceiver): void {
|
|
94
103
|
registeredPushReceivers.push(receiver);
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
/**
|
|
98
|
-
* Clears all registered push receivers.
|
|
99
|
-
*
|
|
100
|
-
* Useful for tests or reinitializing the integration layer.
|
|
101
|
-
*/
|
|
106
|
+
/** Clears all JS push receivers. */
|
|
102
107
|
export function clearPushReceivers(): void {
|
|
103
108
|
registeredPushReceivers.length = 0;
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
/**
|
|
107
|
-
* Default receiver used when no custom receivers are registered.
|
|
108
|
-
* Prevents silent drops during integration and provides visibility via console logs.
|
|
109
|
-
*/
|
|
111
|
+
/** Default receiver used when none are registered. */
|
|
110
112
|
class DefaultPushReceiver extends PushReceiver {
|
|
111
|
-
override pushHandler(message:
|
|
113
|
+
override pushHandler(message: Record<string, string>): void {
|
|
112
114
|
// eslint-disable-next-line no-console
|
|
113
115
|
console.log('[AltcraftSDK] Default push handler:', message);
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
|
-
* Forwards
|
|
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.
|
|
120
|
+
* Forwards a push payload to native SDK and then to JS receivers.
|
|
121
|
+
* This does not intercept system notifications by itself.
|
|
130
122
|
*/
|
|
131
|
-
export function takePush(message:
|
|
132
|
-
if (!message || Object.keys(message).length === 0)
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
123
|
+
export function takePush(message: Record<string, string>): void {
|
|
124
|
+
if (!message || Object.keys(message).length === 0) return;
|
|
135
125
|
|
|
136
|
-
// 1) Always forward to native SDK for parsing/internal processing
|
|
137
126
|
NativeSDK.takePush({ ...message });
|
|
138
127
|
|
|
139
|
-
// 2) Optionally forward to JS receivers (custom logic/analytics/debug)
|
|
140
128
|
const receivers =
|
|
141
129
|
registeredPushReceivers.length > 0
|
|
142
130
|
? registeredPushReceivers
|
|
@@ -154,30 +142,16 @@ export function takePush(message: { [key: string]: string }): void {
|
|
|
154
142
|
|
|
155
143
|
// ---------------- Events API for RN ----------------
|
|
156
144
|
|
|
157
|
-
/** RN subscription handle
|
|
145
|
+
/** RN subscription handle (NativeEventEmitter). */
|
|
158
146
|
type EventsSubscription = { remove: () => void } | null;
|
|
159
147
|
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
* Event name: "AltcraftSdkEvent"
|
|
163
|
-
*/
|
|
164
|
-
const nativeEventEmitter = new NativeEventEmitter(NativeSDK as any);
|
|
148
|
+
/** Native emitter for "AltcraftSdkEvent". */
|
|
149
|
+
const nativeEventEmitter = new NativeEventEmitter(NativeModules.SDKEventEmitter);
|
|
165
150
|
|
|
166
|
-
/**
|
|
167
|
-
* Current active subscription to native SDK events.
|
|
168
|
-
* Only one subscription is maintained; re-subscribing replaces the previous one.
|
|
169
|
-
*/
|
|
151
|
+
/** Current JS-side subscription. */
|
|
170
152
|
let eventsSubscription: EventsSubscription = null;
|
|
171
153
|
|
|
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
|
-
*/
|
|
154
|
+
/** Subscribes to native SDK events and routes them to the handler. */
|
|
181
155
|
export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
|
|
182
156
|
if (eventsSubscription) {
|
|
183
157
|
eventsSubscription.remove();
|
|
@@ -188,27 +162,20 @@ export function subscribeToEvents(handler: (event: SdkEvent) => void): void {
|
|
|
188
162
|
|
|
189
163
|
eventsSubscription = nativeEventEmitter.addListener(
|
|
190
164
|
'AltcraftSdkEvent',
|
|
191
|
-
(...args:
|
|
165
|
+
(...args: unknown[]) => {
|
|
192
166
|
const event = (args[0] ?? null) as SdkEvent | null;
|
|
193
167
|
if (!event) return;
|
|
194
168
|
|
|
195
169
|
try {
|
|
196
170
|
handler(event);
|
|
197
171
|
} catch (e) {
|
|
198
|
-
// eslint-disable-next-line no-console
|
|
199
172
|
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
200
173
|
}
|
|
201
174
|
}
|
|
202
175
|
);
|
|
203
176
|
}
|
|
204
177
|
|
|
205
|
-
/**
|
|
206
|
-
* Unsubscribes from Altcraft SDK events.
|
|
207
|
-
*
|
|
208
|
-
* Behavior:
|
|
209
|
-
* - removes the JS listener
|
|
210
|
-
* - calls `NativeSdk.unsubscribeFromEvent()` to stop native emissions
|
|
211
|
-
*/
|
|
178
|
+
/** Unsubscribes from native SDK events. */
|
|
212
179
|
export function unsubscribeFromEvent(): void {
|
|
213
180
|
if (eventsSubscription) {
|
|
214
181
|
eventsSubscription.remove();
|
|
@@ -218,122 +185,57 @@ export function unsubscribeFromEvent(): void {
|
|
|
218
185
|
NativeSDK.unsubscribeFromEvent();
|
|
219
186
|
}
|
|
220
187
|
|
|
221
|
-
// ----------------
|
|
188
|
+
// ---------------- SDK API ----------------
|
|
222
189
|
|
|
223
|
-
/**
|
|
224
|
-
* Initializes the Altcraft SDK.
|
|
225
|
-
*
|
|
226
|
-
* Native equivalents:
|
|
227
|
-
* - Android: `AltcraftSDK.initialization(context, configuration, complete)`
|
|
228
|
-
* - iOS: `AltcraftSDK.shared.initialization(configuration, completion)`
|
|
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).
|
|
238
|
-
*/
|
|
190
|
+
/** Initializes the Altcraft SDK. */
|
|
239
191
|
export function initialize(config: AltcraftConfig): Promise<void> {
|
|
240
192
|
return NativeSDK.initialize(config);
|
|
241
193
|
}
|
|
242
194
|
|
|
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
|
-
*/
|
|
195
|
+
/** Sets or clears the JWT used by the SDK. */
|
|
255
196
|
export function setJwt(token: string | null): void {
|
|
256
197
|
return NativeSDK.setJwt(token);
|
|
257
198
|
}
|
|
258
199
|
|
|
259
200
|
// platform-specific token setters
|
|
260
201
|
|
|
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
|
-
*/
|
|
202
|
+
/** Android-only: sets FCM token. */
|
|
270
203
|
export function setAndroidFcmToken(token: string | null): void {
|
|
271
204
|
return NativeSDK.setAndroidFcmToken(token);
|
|
272
205
|
}
|
|
273
206
|
|
|
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
|
-
*/
|
|
207
|
+
/** iOS-only: sets FCM token. */
|
|
279
208
|
export function setIosFcmToken(token: string | null): void {
|
|
280
209
|
return NativeSDK.setIosFcmToken(token);
|
|
281
210
|
}
|
|
282
211
|
|
|
283
|
-
/**
|
|
284
|
-
* Android-only: sets the HMS token.
|
|
285
|
-
*
|
|
286
|
-
* @param token HMS token or null.
|
|
287
|
-
*/
|
|
212
|
+
/** Android-only: sets HMS token. */
|
|
288
213
|
export function setAndroidHmsToken(token: string | null): void {
|
|
289
214
|
return NativeSDK.setAndroidHmsToken(token);
|
|
290
215
|
}
|
|
291
216
|
|
|
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
|
-
*/
|
|
217
|
+
/** iOS-only: sets HMS token. */
|
|
297
218
|
export function setIosHmsToken(token: string | null): void {
|
|
298
219
|
return NativeSDK.setIosHmsToken(token);
|
|
299
220
|
}
|
|
300
221
|
|
|
301
|
-
|
|
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
|
-
*/
|
|
222
|
+
/** iOS-only: sets APNs token. */
|
|
311
223
|
export function setApnsToken(token: string | null): void {
|
|
312
224
|
return NativeSDK.setApnsToken(token);
|
|
313
225
|
}
|
|
314
226
|
|
|
315
|
-
/**
|
|
316
|
-
* Android-only: sets the RuStore token.
|
|
317
|
-
*
|
|
318
|
-
* @param token RuStore token or null.
|
|
319
|
-
*/
|
|
227
|
+
/** Android-only: sets RuStore token. */
|
|
320
228
|
export function setRustoreToken(token: string | null): void {
|
|
321
229
|
return NativeSDK.setRustoreToken(token);
|
|
322
230
|
}
|
|
323
231
|
|
|
324
|
-
// ---------------- subscription (public:
|
|
232
|
+
// ---------------- subscription (public: unknown, native: string) ----------------
|
|
325
233
|
|
|
326
|
-
/**
|
|
327
|
-
* Performs a push subscribe request.
|
|
328
|
-
*
|
|
329
|
-
* Notes:
|
|
330
|
-
* - fire-and-forget: results/errors are delivered via the SDK Events stream
|
|
331
|
-
* - `sync` is forwarded to the SDK/server semantics
|
|
332
|
-
*/
|
|
234
|
+
/** Push subscribe (fire-and-forget). */
|
|
333
235
|
export function pushSubscribe(
|
|
334
236
|
sync: boolean | null = true,
|
|
335
|
-
profileFields:
|
|
336
|
-
customFields:
|
|
237
|
+
profileFields: Record<string, unknown> | null = null,
|
|
238
|
+
customFields: Record<string, unknown> | null = null,
|
|
337
239
|
cats: CategoryData[] | null = null,
|
|
338
240
|
replace: boolean | null = null,
|
|
339
241
|
skipTriggers: boolean | null = null
|
|
@@ -348,16 +250,11 @@ export function pushSubscribe(
|
|
|
348
250
|
);
|
|
349
251
|
}
|
|
350
252
|
|
|
351
|
-
/**
|
|
352
|
-
* Suspends push notifications for the current profile/subscription.
|
|
353
|
-
*
|
|
354
|
-
* Same parameter semantics as `pushSubscribe`.
|
|
355
|
-
* Results/errors are delivered via the SDK Events stream.
|
|
356
|
-
*/
|
|
253
|
+
/** Push suspend (fire-and-forget). */
|
|
357
254
|
export function pushSuspend(
|
|
358
255
|
sync: boolean | null = true,
|
|
359
|
-
profileFields:
|
|
360
|
-
customFields:
|
|
256
|
+
profileFields: Record<string, unknown> | null = null,
|
|
257
|
+
customFields: Record<string, unknown> | null = null,
|
|
361
258
|
cats: CategoryData[] | null = null,
|
|
362
259
|
replace: boolean | null = null,
|
|
363
260
|
skipTriggers: boolean | null = null
|
|
@@ -372,16 +269,11 @@ export function pushSuspend(
|
|
|
372
269
|
);
|
|
373
270
|
}
|
|
374
271
|
|
|
375
|
-
/**
|
|
376
|
-
* Performs a push unsubscribe request.
|
|
377
|
-
*
|
|
378
|
-
* Same parameter semantics as `pushSubscribe`.
|
|
379
|
-
* Results/errors are delivered via the SDK Events stream.
|
|
380
|
-
*/
|
|
272
|
+
/** Push unsubscribe (fire-and-forget). */
|
|
381
273
|
export function pushUnSubscribe(
|
|
382
274
|
sync: boolean | null = true,
|
|
383
|
-
profileFields:
|
|
384
|
-
customFields:
|
|
275
|
+
profileFields: Record<string, unknown> | null = null,
|
|
276
|
+
customFields: Record<string, unknown> | null = null,
|
|
385
277
|
cats: CategoryData[] | null = null,
|
|
386
278
|
replace: boolean | null = null,
|
|
387
279
|
skipTriggers: boolean | null = null
|
|
@@ -396,170 +288,98 @@ export function pushUnSubscribe(
|
|
|
396
288
|
);
|
|
397
289
|
}
|
|
398
290
|
|
|
399
|
-
/**
|
|
400
|
-
* Sends an "unSuspend" request and returns the response wrapped with HTTP status code.
|
|
401
|
-
*
|
|
402
|
-
* ⚠️ Can throw (reject):
|
|
403
|
-
* - native validation failure (missing data to create request)
|
|
404
|
-
* - request creation/sending failures
|
|
405
|
-
* - unexpected native exceptions
|
|
406
|
-
*
|
|
407
|
-
* @returns `ResponseWithHttpCode | null`
|
|
408
|
-
*/
|
|
291
|
+
/** Un-suspends push subscription and returns response (if any). */
|
|
409
292
|
export function unSuspendPushSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
410
293
|
return NativeSDK.unSuspendPushSubscription();
|
|
411
294
|
}
|
|
412
295
|
|
|
413
|
-
/**
|
|
414
|
-
* Returns the status of the latest subscription request stored in the profile.
|
|
415
|
-
*
|
|
416
|
-
* ⚠️ Can throw (reject) on native request creation/sending failures or unexpected exceptions.
|
|
417
|
-
*/
|
|
296
|
+
/** Returns latest subscription status (if any). */
|
|
418
297
|
export function getStatusOfLatestSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
419
298
|
return NativeSDK.getStatusOfLatestSubscription();
|
|
420
299
|
}
|
|
421
300
|
|
|
422
|
-
/**
|
|
423
|
-
* Returns the status of the latest subscription for the specified provider.
|
|
424
|
-
* If provider is null, native SDK may use the current provider (SDK-specific).
|
|
425
|
-
*
|
|
426
|
-
* ⚠️ Can throw (reject):
|
|
427
|
-
* - invalid provider
|
|
428
|
-
* - native request creation/sending failures
|
|
429
|
-
* - unexpected native exceptions
|
|
430
|
-
*
|
|
431
|
-
* @param provider Provider identifier or null.
|
|
432
|
-
*/
|
|
301
|
+
/** Returns latest subscription status for a provider (if any). */
|
|
433
302
|
export function getStatusOfLatestSubscriptionForProvider(
|
|
434
303
|
provider: string | null = null
|
|
435
304
|
): Promise<ResponseWithHttpCode | null> {
|
|
436
305
|
return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
|
|
437
306
|
}
|
|
438
307
|
|
|
439
|
-
/**
|
|
440
|
-
* Returns the status for the "current subscription context" (current provider + current token),
|
|
441
|
-
* according to native SDK rules.
|
|
442
|
-
*
|
|
443
|
-
* ⚠️ Can throw (reject) on native request creation/sending failures or unexpected exceptions.
|
|
444
|
-
*/
|
|
308
|
+
/** Returns current subscription status (if any). */
|
|
445
309
|
export function getStatusForCurrentSubscription(): Promise<ResponseWithHttpCode | null> {
|
|
446
310
|
return NativeSDK.getStatusForCurrentSubscription();
|
|
447
311
|
}
|
|
448
312
|
|
|
449
313
|
// ---------------- token public API ----------------
|
|
450
314
|
|
|
451
|
-
/**
|
|
452
|
-
* Returns the current push token selected/managed by the SDK.
|
|
453
|
-
*
|
|
454
|
-
* ⚠️ Can throw (reject) on unexpected native errors.
|
|
455
|
-
*
|
|
456
|
-
* May resolve `null` if token is not yet available or providers are not configured.
|
|
457
|
-
*/
|
|
315
|
+
/** Returns current push token (or null). */
|
|
458
316
|
export function getPushToken(): Promise<TokenData | null> {
|
|
459
317
|
return NativeSDK.getPushToken();
|
|
460
318
|
}
|
|
461
319
|
|
|
462
|
-
/**
|
|
463
|
-
* Deletes the device token for a given provider.
|
|
464
|
-
*
|
|
465
|
-
* ⚠️ Can throw (reject):
|
|
466
|
-
* - provider is null/invalid
|
|
467
|
-
* - native deletion flow fails
|
|
468
|
-
* - unexpected native exceptions
|
|
469
|
-
*
|
|
470
|
-
* @param provider Provider identifier (or null; native may treat this as invalid).
|
|
471
|
-
*/
|
|
320
|
+
/** Deletes device token for provider. */
|
|
472
321
|
export function deleteDeviceToken(provider: string | null): Promise<void> {
|
|
473
322
|
return NativeSDK.deleteDeviceToken(provider);
|
|
474
323
|
}
|
|
475
324
|
|
|
476
|
-
/**
|
|
477
|
-
* Forces a token refresh flow.
|
|
478
|
-
*
|
|
479
|
-
* ⚠️ Can throw (reject) on native failures or unexpected exceptions.
|
|
480
|
-
*/
|
|
325
|
+
/** Forces token refresh flow. */
|
|
481
326
|
export function forcedTokenUpdate(): Promise<void> {
|
|
482
327
|
return NativeSDK.forcedTokenUpdate();
|
|
483
328
|
}
|
|
484
329
|
|
|
485
|
-
/**
|
|
486
|
-
* Updates the provider priority list used by the SDK to select a push provider.
|
|
487
|
-
*
|
|
488
|
-
* ⚠️ Can throw (reject):
|
|
489
|
-
* - invalid provider list (unknown identifiers)
|
|
490
|
-
* - native update flow failure
|
|
491
|
-
* - unexpected native exceptions
|
|
492
|
-
*
|
|
493
|
-
* @param priorityList Ordered list of provider IDs, or null.
|
|
494
|
-
*/
|
|
330
|
+
/** Updates provider priority list. */
|
|
495
331
|
export function changePushProviderPriorityList(
|
|
496
332
|
priorityList: string[] | null
|
|
497
333
|
): Promise<void> {
|
|
498
334
|
return NativeSDK.changePushProviderPriorityList(priorityList);
|
|
499
335
|
}
|
|
500
336
|
|
|
501
|
-
/**
|
|
502
|
-
* Sets (or clears) a token for a specific provider.
|
|
503
|
-
|
|
504
|
-
*
|
|
505
|
-
* ⚠️ Can throw (reject):
|
|
506
|
-
* - provider is invalid/blank (native validation)
|
|
507
|
-
* - native set/delete flow fails
|
|
508
|
-
* - unexpected native exceptions
|
|
509
|
-
*
|
|
510
|
-
* @param provider Provider identifier.
|
|
511
|
-
* @param token Token string or null to clear.
|
|
512
|
-
*/
|
|
337
|
+
/** Sets or clears token for a specific provider. */
|
|
513
338
|
export function setPushToken(provider: string, token: string | null): Promise<void> {
|
|
514
339
|
return NativeSDK.setPushToken(provider, token);
|
|
515
340
|
}
|
|
516
341
|
|
|
517
342
|
// ---------------- sdk wrappers ----------------
|
|
518
343
|
|
|
519
|
-
/**
|
|
520
|
-
* Clears SDK local state and stops active SDK background work (SDK-specific).
|
|
521
|
-
*
|
|
522
|
-
* ⚠️ Can throw (reject) on unexpected native errors.
|
|
523
|
-
*/
|
|
344
|
+
/** Clears SDK local state. */
|
|
524
345
|
export function clear(): Promise<void> {
|
|
525
346
|
return NativeSDK.clear();
|
|
526
347
|
}
|
|
527
348
|
|
|
528
|
-
/**
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
*/
|
|
532
|
-
export function reinitializeRetryControlInThisSession(): void {
|
|
533
|
-
return NativeSDK.reinitializeRetryControlInThisSession();
|
|
349
|
+
/** Resets session init-control state (platform-dependent). */
|
|
350
|
+
export function unlockInitOperationsInThisSession(): void {
|
|
351
|
+
return NativeSDK.unlockInitOperationsInThisSession();
|
|
534
352
|
}
|
|
535
353
|
|
|
536
|
-
/**
|
|
537
|
-
* Requests notification permission (where applicable).
|
|
538
|
-
*
|
|
539
|
-
* Note:
|
|
540
|
-
* - Usually no Promise here; native may silently no-op if not supported.
|
|
541
|
-
*/
|
|
354
|
+
/** Requests notification permission (platform-dependent). */
|
|
542
355
|
export function requestNotificationPermission(): void {
|
|
543
356
|
return NativeSDK.requestNotificationPermission();
|
|
544
357
|
}
|
|
545
358
|
|
|
546
|
-
// ----------------
|
|
359
|
+
// ---------------- UserDefaults / SharedPreferences ----------------
|
|
547
360
|
|
|
548
|
-
/**
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
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) ----------------
|
|
372
|
+
|
|
373
|
+
/** Sends a mobile event (fire-and-forget). */
|
|
555
374
|
export function mobileEvent(
|
|
556
375
|
sid: string,
|
|
557
376
|
eventName: string,
|
|
558
377
|
sendMessageId: string | null = null,
|
|
559
|
-
payload:
|
|
560
|
-
matching:
|
|
378
|
+
payload: Record<string, unknown> | null = null,
|
|
379
|
+
matching: Record<string, unknown> | null = null,
|
|
561
380
|
matchingType: string | null = null,
|
|
562
|
-
profileFields:
|
|
381
|
+
profileFields: Record<string, unknown> | null = null,
|
|
382
|
+
utm: UTM | null = null
|
|
563
383
|
): void {
|
|
564
384
|
NativeSDK.mobileEvent(
|
|
565
385
|
sid,
|
|
@@ -568,76 +388,47 @@ export function mobileEvent(
|
|
|
568
388
|
toNativeStringMap(payload),
|
|
569
389
|
toNativeStringMap(matching),
|
|
570
390
|
matchingType,
|
|
571
|
-
toNativeStringMap(profileFields)
|
|
391
|
+
toNativeStringMap(profileFields),
|
|
392
|
+
utm
|
|
572
393
|
);
|
|
573
394
|
}
|
|
574
395
|
|
|
575
|
-
/**
|
|
576
|
-
* Manually registers a "delivery" event for a push notification.
|
|
577
|
-
*
|
|
578
|
-
* Note:
|
|
579
|
-
* - Fire-and-forget (no Promise). Native errors should be emitted as SDK events or logs.
|
|
580
|
-
*/
|
|
396
|
+
/** Manually records a push delivery event (fire-and-forget). */
|
|
581
397
|
export function deliveryEvent(
|
|
582
|
-
message:
|
|
398
|
+
message: Record<string, string> | null = null,
|
|
583
399
|
messageUID: string | null = null
|
|
584
400
|
): void {
|
|
585
401
|
const nativePayload =
|
|
586
402
|
message && Object.keys(message).length > 0 ? { ...message } : null;
|
|
587
403
|
|
|
588
|
-
|
|
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);
|
|
589
407
|
}
|
|
590
408
|
|
|
591
|
-
/**
|
|
592
|
-
* Manually registers an "open" event for a push notification.
|
|
593
|
-
*
|
|
594
|
-
* Note:
|
|
595
|
-
* - Fire-and-forget (no Promise). Native errors should be emitted as SDK events or logs.
|
|
596
|
-
*/
|
|
409
|
+
/** Manually records a push open event (fire-and-forget). */
|
|
597
410
|
export function openEvent(
|
|
598
|
-
message:
|
|
411
|
+
message: Record<string, string> | null = null,
|
|
599
412
|
messageUID: string | null = null
|
|
600
413
|
): void {
|
|
601
414
|
const nativePayload =
|
|
602
415
|
message && Object.keys(message).length > 0 ? { ...message } : null;
|
|
603
416
|
|
|
604
|
-
|
|
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);
|
|
605
420
|
}
|
|
606
421
|
|
|
607
422
|
// ---------------- Default export ----------------
|
|
608
423
|
|
|
609
|
-
/**
|
|
610
|
-
* Public React Native facade for the Altcraft SDK.
|
|
611
|
-
*
|
|
612
|
-
* Promise-returning methods (can throw on `await` / reject):
|
|
613
|
-
* - initialize
|
|
614
|
-
* - unSuspendPushSubscription
|
|
615
|
-
* - getStatusOfLatestSubscription
|
|
616
|
-
* - getStatusOfLatestSubscriptionForProvider
|
|
617
|
-
* - getStatusForCurrentSubscription
|
|
618
|
-
* - getPushToken
|
|
619
|
-
* - deleteDeviceToken
|
|
620
|
-
* - forcedTokenUpdate
|
|
621
|
-
* - changePushProviderPriorityList
|
|
622
|
-
* - setPushToken
|
|
623
|
-
* - clear
|
|
624
|
-
*/
|
|
424
|
+
/** Public React Native facade for the Altcraft SDK. */
|
|
625
425
|
const AltcraftSDK = {
|
|
626
426
|
initialize,
|
|
627
427
|
setJwt,
|
|
628
428
|
|
|
629
|
-
setAndroidFcmToken,
|
|
630
|
-
setIosFcmToken,
|
|
631
|
-
setAndroidHmsToken,
|
|
632
|
-
setIosHmsToken,
|
|
633
|
-
|
|
634
|
-
setApnsToken,
|
|
635
|
-
setRustoreToken,
|
|
636
|
-
|
|
637
429
|
pushSubscribe,
|
|
638
430
|
pushSuspend,
|
|
639
431
|
pushUnSubscribe,
|
|
640
|
-
|
|
641
432
|
unSuspendPushSubscription,
|
|
642
433
|
getStatusOfLatestSubscription,
|
|
643
434
|
getStatusOfLatestSubscriptionForProvider,
|
|
@@ -649,22 +440,33 @@ const AltcraftSDK = {
|
|
|
649
440
|
changePushProviderPriorityList,
|
|
650
441
|
setPushToken,
|
|
651
442
|
|
|
652
|
-
clear,
|
|
653
|
-
reinitializeRetryControlInThisSession,
|
|
654
|
-
requestNotificationPermission,
|
|
655
443
|
|
|
656
444
|
mobileEvent,
|
|
657
445
|
|
|
446
|
+
subscribeToEvents,
|
|
447
|
+
unsubscribeFromEvent,
|
|
448
|
+
|
|
449
|
+
clear,
|
|
450
|
+
|
|
451
|
+
//ios only
|
|
452
|
+
setIosFcmToken,
|
|
453
|
+
setIosHmsToken,
|
|
454
|
+
setApnsToken,
|
|
455
|
+
setUserDefaultsValue,
|
|
456
|
+
|
|
457
|
+
//android only
|
|
458
|
+
setAndroidFcmToken,
|
|
459
|
+
setAndroidHmsToken,
|
|
460
|
+
setRustoreToken,
|
|
658
461
|
PushReceiver,
|
|
659
462
|
registerPushReceiver,
|
|
660
463
|
clearPushReceivers,
|
|
661
464
|
takePush,
|
|
662
|
-
|
|
663
|
-
subscribeToEvents,
|
|
664
|
-
unsubscribeFromEvent,
|
|
665
|
-
|
|
666
465
|
deliveryEvent,
|
|
667
466
|
openEvent,
|
|
467
|
+
unlockInitOperationsInThisSession,
|
|
468
|
+
requestNotificationPermission,
|
|
469
|
+
|
|
668
470
|
};
|
|
669
471
|
|
|
670
472
|
export default AltcraftSDK;
|