@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","NativeSDK","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSdk.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","NativeSDK","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSdk.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;;AA0EA;;AA8GA;;AAEA,MAAMC,SAAS,GAAGD,mBAAmB,CAACE,YAAY,CAAO,KAAK,CAAC;AAC/D,eAAeD,SAAS","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,91 +1,81 @@
|
|
|
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
5
|
|
|
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
|
-
*/
|
|
6
|
+
/** SDK event payload emitted from native via NativeEventEmitter ("AltcraftSdkEvent"). */
|
|
20
7
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
*/
|
|
8
|
+
/** UTM tags for mobileEvent attribution. */
|
|
9
|
+
|
|
10
|
+
// ---------------- Utilities ----------------
|
|
11
|
+
|
|
12
|
+
/** Converts a JS object to { [key: string]: string } for the RN bridge; drops null/undefined. */
|
|
33
13
|
function toNativeStringMap(input) {
|
|
34
|
-
if (
|
|
14
|
+
if (input == null) return null;
|
|
35
15
|
const out = {};
|
|
36
|
-
for (const [
|
|
37
|
-
if (
|
|
38
|
-
|
|
16
|
+
for (const [key, value] of Object.entries(input)) {
|
|
17
|
+
if (value == null) continue;
|
|
18
|
+
switch (typeof value) {
|
|
19
|
+
case 'string':
|
|
20
|
+
out[key] = value;
|
|
21
|
+
break;
|
|
22
|
+
case 'number':
|
|
23
|
+
case 'boolean':
|
|
24
|
+
case 'bigint':
|
|
25
|
+
out[key] = String(value);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
try {
|
|
29
|
+
out[key] = JSON.stringify(value);
|
|
30
|
+
} catch {
|
|
31
|
+
out[key] = String(value);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
39
35
|
}
|
|
40
36
|
return Object.keys(out).length > 0 ? out : null;
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* -
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* -
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
* New Arch safe:
|
|
41
|
+
* TurboModule codegen does NOT support `any`.
|
|
42
|
+
* Therefore, we serialize any value for UserDefaults into `string`:
|
|
43
|
+
* - string -> as-is
|
|
44
|
+
* - number/boolean -> String(...)
|
|
45
|
+
* - object/array -> JSON.stringify(...)
|
|
46
|
+
* - null/undefined -> null (native side can treat it as “remove key”)
|
|
47
|
+
*/
|
|
48
|
+
function toUserDefaultsString(value) {
|
|
49
|
+
if (value == null) return null;
|
|
50
|
+
const t = typeof value;
|
|
51
|
+
if (t === 'string') return String(value);
|
|
52
|
+
if (t === 'number' || t === 'boolean') return String(value);
|
|
53
|
+
try {
|
|
54
|
+
return JSON.stringify(value);
|
|
55
|
+
} catch {
|
|
56
|
+
return String(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---------------- PushReceiver API (JS-side) ----------------
|
|
61
|
+
|
|
62
|
+
/** JS handler interface for incoming push payloads. */
|
|
57
63
|
export class PushReceiver {}
|
|
58
64
|
|
|
59
|
-
/**
|
|
60
|
-
* Registered JS receivers for push payload dispatch.
|
|
61
|
-
* If none are registered, a DefaultPushReceiver will log the payload.
|
|
62
|
-
*/
|
|
65
|
+
/** Registered JS receivers for push payloads. */
|
|
63
66
|
const registeredPushReceivers = [];
|
|
64
67
|
|
|
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
|
-
*/
|
|
68
|
+
/** Registers a JS push receiver. */
|
|
72
69
|
export function registerPushReceiver(receiver) {
|
|
73
70
|
registeredPushReceivers.push(receiver);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
/**
|
|
77
|
-
* Clears all registered push receivers.
|
|
78
|
-
*
|
|
79
|
-
* Useful for tests or reinitializing the integration layer.
|
|
80
|
-
*/
|
|
73
|
+
/** Clears all JS push receivers. */
|
|
81
74
|
export function clearPushReceivers() {
|
|
82
75
|
registeredPushReceivers.length = 0;
|
|
83
76
|
}
|
|
84
77
|
|
|
85
|
-
/**
|
|
86
|
-
* Default receiver used when no custom receivers are registered.
|
|
87
|
-
* Prevents silent drops during integration and provides visibility via console logs.
|
|
88
|
-
*/
|
|
78
|
+
/** Default receiver used when none are registered. */
|
|
89
79
|
class DefaultPushReceiver extends PushReceiver {
|
|
90
80
|
pushHandler(message) {
|
|
91
81
|
// eslint-disable-next-line no-console
|
|
@@ -94,30 +84,14 @@ class DefaultPushReceiver extends PushReceiver {
|
|
|
94
84
|
}
|
|
95
85
|
|
|
96
86
|
/**
|
|
97
|
-
* Forwards
|
|
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.
|
|
87
|
+
* Forwards a push payload to native SDK and then to JS receivers.
|
|
88
|
+
* This does not intercept system notifications by itself.
|
|
109
89
|
*/
|
|
110
90
|
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
|
|
91
|
+
if (!message || Object.keys(message).length === 0) return;
|
|
116
92
|
NativeSDK.takePush({
|
|
117
93
|
...message
|
|
118
94
|
});
|
|
119
|
-
|
|
120
|
-
// 2) Optionally forward to JS receivers (custom logic/analytics/debug)
|
|
121
95
|
const receivers = registeredPushReceivers.length > 0 ? registeredPushReceivers : [new DefaultPushReceiver()];
|
|
122
96
|
for (const receiver of receivers) {
|
|
123
97
|
try {
|
|
@@ -131,29 +105,15 @@ export function takePush(message) {
|
|
|
131
105
|
|
|
132
106
|
// ---------------- Events API for RN ----------------
|
|
133
107
|
|
|
134
|
-
/** RN subscription handle
|
|
108
|
+
/** RN subscription handle (NativeEventEmitter). */
|
|
135
109
|
|
|
136
|
-
/**
|
|
137
|
-
|
|
138
|
-
* Event name: "AltcraftSdkEvent"
|
|
139
|
-
*/
|
|
140
|
-
const nativeEventEmitter = new NativeEventEmitter(NativeSDK);
|
|
110
|
+
/** Native emitter for "AltcraftSdkEvent". */
|
|
111
|
+
const nativeEventEmitter = new NativeEventEmitter(NativeModules.SDKEventEmitter);
|
|
141
112
|
|
|
142
|
-
/**
|
|
143
|
-
* Current active subscription to native SDK events.
|
|
144
|
-
* Only one subscription is maintained; re-subscribing replaces the previous one.
|
|
145
|
-
*/
|
|
113
|
+
/** Current JS-side subscription. */
|
|
146
114
|
let eventsSubscription = null;
|
|
147
115
|
|
|
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
|
-
*/
|
|
116
|
+
/** Subscribes to native SDK events and routes them to the handler. */
|
|
157
117
|
export function subscribeToEvents(handler) {
|
|
158
118
|
if (eventsSubscription) {
|
|
159
119
|
eventsSubscription.remove();
|
|
@@ -166,19 +126,12 @@ export function subscribeToEvents(handler) {
|
|
|
166
126
|
try {
|
|
167
127
|
handler(event);
|
|
168
128
|
} catch (e) {
|
|
169
|
-
// eslint-disable-next-line no-console
|
|
170
129
|
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
171
130
|
}
|
|
172
131
|
});
|
|
173
132
|
}
|
|
174
133
|
|
|
175
|
-
/**
|
|
176
|
-
* Unsubscribes from Altcraft SDK events.
|
|
177
|
-
*
|
|
178
|
-
* Behavior:
|
|
179
|
-
* - removes the JS listener
|
|
180
|
-
* - calls `NativeSdk.unsubscribeFromEvent()` to stop native emissions
|
|
181
|
-
*/
|
|
134
|
+
/** Unsubscribes from native SDK events. */
|
|
182
135
|
export function unsubscribeFromEvent() {
|
|
183
136
|
if (eventsSubscription) {
|
|
184
137
|
eventsSubscription.remove();
|
|
@@ -187,351 +140,172 @@ export function unsubscribeFromEvent() {
|
|
|
187
140
|
NativeSDK.unsubscribeFromEvent();
|
|
188
141
|
}
|
|
189
142
|
|
|
190
|
-
// ----------------
|
|
143
|
+
// ---------------- SDK API ----------------
|
|
191
144
|
|
|
192
|
-
/**
|
|
193
|
-
* Initializes the Altcraft SDK.
|
|
194
|
-
*
|
|
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).
|
|
207
|
-
*/
|
|
145
|
+
/** Initializes the Altcraft SDK. */
|
|
208
146
|
export function initialize(config) {
|
|
209
147
|
return NativeSDK.initialize(config);
|
|
210
148
|
}
|
|
211
149
|
|
|
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
|
-
*/
|
|
150
|
+
/** Sets or clears the JWT used by the SDK. */
|
|
224
151
|
export function setJwt(token) {
|
|
225
152
|
return NativeSDK.setJwt(token);
|
|
226
153
|
}
|
|
227
154
|
|
|
228
155
|
// platform-specific token setters
|
|
229
156
|
|
|
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
|
-
*/
|
|
157
|
+
/** Android-only: sets FCM token. */
|
|
239
158
|
export function setAndroidFcmToken(token) {
|
|
240
159
|
return NativeSDK.setAndroidFcmToken(token);
|
|
241
160
|
}
|
|
242
161
|
|
|
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
|
-
*/
|
|
162
|
+
/** iOS-only: sets FCM token. */
|
|
248
163
|
export function setIosFcmToken(token) {
|
|
249
164
|
return NativeSDK.setIosFcmToken(token);
|
|
250
165
|
}
|
|
251
166
|
|
|
252
|
-
/**
|
|
253
|
-
* Android-only: sets the HMS token.
|
|
254
|
-
*
|
|
255
|
-
* @param token HMS token or null.
|
|
256
|
-
*/
|
|
167
|
+
/** Android-only: sets HMS token. */
|
|
257
168
|
export function setAndroidHmsToken(token) {
|
|
258
169
|
return NativeSDK.setAndroidHmsToken(token);
|
|
259
170
|
}
|
|
260
171
|
|
|
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
|
-
*/
|
|
172
|
+
/** iOS-only: sets HMS token. */
|
|
266
173
|
export function setIosHmsToken(token) {
|
|
267
174
|
return NativeSDK.setIosHmsToken(token);
|
|
268
175
|
}
|
|
269
176
|
|
|
270
|
-
|
|
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
|
-
*/
|
|
177
|
+
/** iOS-only: sets APNs token. */
|
|
280
178
|
export function setApnsToken(token) {
|
|
281
179
|
return NativeSDK.setApnsToken(token);
|
|
282
180
|
}
|
|
283
181
|
|
|
284
|
-
/**
|
|
285
|
-
* Android-only: sets the RuStore token.
|
|
286
|
-
*
|
|
287
|
-
* @param token RuStore token or null.
|
|
288
|
-
*/
|
|
182
|
+
/** Android-only: sets RuStore token. */
|
|
289
183
|
export function setRustoreToken(token) {
|
|
290
184
|
return NativeSDK.setRustoreToken(token);
|
|
291
185
|
}
|
|
292
186
|
|
|
293
|
-
// ---------------- subscription (public:
|
|
187
|
+
// ---------------- subscription (public: unknown, native: string) ----------------
|
|
294
188
|
|
|
295
|
-
/**
|
|
296
|
-
* Performs a push subscribe request.
|
|
297
|
-
*
|
|
298
|
-
* Notes:
|
|
299
|
-
* - fire-and-forget: results/errors are delivered via the SDK Events stream
|
|
300
|
-
* - `sync` is forwarded to the SDK/server semantics
|
|
301
|
-
*/
|
|
189
|
+
/** Push subscribe (fire-and-forget). */
|
|
302
190
|
export function pushSubscribe(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
303
191
|
NativeSDK.pushSubscribe(sync, toNativeStringMap(profileFields), toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
304
192
|
}
|
|
305
193
|
|
|
306
|
-
/**
|
|
307
|
-
* Suspends push notifications for the current profile/subscription.
|
|
308
|
-
*
|
|
309
|
-
* Same parameter semantics as `pushSubscribe`.
|
|
310
|
-
* Results/errors are delivered via the SDK Events stream.
|
|
311
|
-
*/
|
|
194
|
+
/** Push suspend (fire-and-forget). */
|
|
312
195
|
export function pushSuspend(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
313
196
|
NativeSDK.pushSuspend(sync, toNativeStringMap(profileFields), toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
314
197
|
}
|
|
315
198
|
|
|
316
|
-
/**
|
|
317
|
-
* Performs a push unsubscribe request.
|
|
318
|
-
*
|
|
319
|
-
* Same parameter semantics as `pushSubscribe`.
|
|
320
|
-
* Results/errors are delivered via the SDK Events stream.
|
|
321
|
-
*/
|
|
199
|
+
/** Push unsubscribe (fire-and-forget). */
|
|
322
200
|
export function pushUnSubscribe(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
323
201
|
NativeSDK.pushUnSubscribe(sync, toNativeStringMap(profileFields), toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
324
202
|
}
|
|
325
203
|
|
|
326
|
-
/**
|
|
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
|
|
333
|
-
*
|
|
334
|
-
* @returns `ResponseWithHttpCode | null`
|
|
335
|
-
*/
|
|
204
|
+
/** Un-suspends push subscription and returns response (if any). */
|
|
336
205
|
export function unSuspendPushSubscription() {
|
|
337
206
|
return NativeSDK.unSuspendPushSubscription();
|
|
338
207
|
}
|
|
339
208
|
|
|
340
|
-
/**
|
|
341
|
-
* Returns the status of the latest subscription request stored in the profile.
|
|
342
|
-
*
|
|
343
|
-
* ⚠️ Can throw (reject) on native request creation/sending failures or unexpected exceptions.
|
|
344
|
-
*/
|
|
209
|
+
/** Returns latest subscription status (if any). */
|
|
345
210
|
export function getStatusOfLatestSubscription() {
|
|
346
211
|
return NativeSDK.getStatusOfLatestSubscription();
|
|
347
212
|
}
|
|
348
213
|
|
|
349
|
-
/**
|
|
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
|
|
357
|
-
*
|
|
358
|
-
* @param provider Provider identifier or null.
|
|
359
|
-
*/
|
|
214
|
+
/** Returns latest subscription status for a provider (if any). */
|
|
360
215
|
export function getStatusOfLatestSubscriptionForProvider(provider = null) {
|
|
361
216
|
return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
|
|
362
217
|
}
|
|
363
218
|
|
|
364
|
-
/**
|
|
365
|
-
* Returns the status for the "current subscription context" (current provider + current token),
|
|
366
|
-
* according to native SDK rules.
|
|
367
|
-
*
|
|
368
|
-
* ⚠️ Can throw (reject) on native request creation/sending failures or unexpected exceptions.
|
|
369
|
-
*/
|
|
219
|
+
/** Returns current subscription status (if any). */
|
|
370
220
|
export function getStatusForCurrentSubscription() {
|
|
371
221
|
return NativeSDK.getStatusForCurrentSubscription();
|
|
372
222
|
}
|
|
373
223
|
|
|
374
224
|
// ---------------- token public API ----------------
|
|
375
225
|
|
|
376
|
-
/**
|
|
377
|
-
* Returns the current push token selected/managed by the SDK.
|
|
378
|
-
*
|
|
379
|
-
* ⚠️ Can throw (reject) on unexpected native errors.
|
|
380
|
-
*
|
|
381
|
-
* May resolve `null` if token is not yet available or providers are not configured.
|
|
382
|
-
*/
|
|
226
|
+
/** Returns current push token (or null). */
|
|
383
227
|
export function getPushToken() {
|
|
384
228
|
return NativeSDK.getPushToken();
|
|
385
229
|
}
|
|
386
230
|
|
|
387
|
-
/**
|
|
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
|
|
394
|
-
*
|
|
395
|
-
* @param provider Provider identifier (or null; native may treat this as invalid).
|
|
396
|
-
*/
|
|
231
|
+
/** Deletes device token for provider. */
|
|
397
232
|
export function deleteDeviceToken(provider) {
|
|
398
233
|
return NativeSDK.deleteDeviceToken(provider);
|
|
399
234
|
}
|
|
400
235
|
|
|
401
|
-
/**
|
|
402
|
-
* Forces a token refresh flow.
|
|
403
|
-
*
|
|
404
|
-
* ⚠️ Can throw (reject) on native failures or unexpected exceptions.
|
|
405
|
-
*/
|
|
236
|
+
/** Forces token refresh flow. */
|
|
406
237
|
export function forcedTokenUpdate() {
|
|
407
238
|
return NativeSDK.forcedTokenUpdate();
|
|
408
239
|
}
|
|
409
240
|
|
|
410
|
-
/**
|
|
411
|
-
* Updates the provider priority list used by the SDK to select a push provider.
|
|
412
|
-
*
|
|
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.
|
|
419
|
-
*/
|
|
241
|
+
/** Updates provider priority list. */
|
|
420
242
|
export function changePushProviderPriorityList(priorityList) {
|
|
421
243
|
return NativeSDK.changePushProviderPriorityList(priorityList);
|
|
422
244
|
}
|
|
423
245
|
|
|
424
|
-
/**
|
|
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
|
|
432
|
-
*
|
|
433
|
-
* @param provider Provider identifier.
|
|
434
|
-
* @param token Token string or null to clear.
|
|
435
|
-
*/
|
|
246
|
+
/** Sets or clears token for a specific provider. */
|
|
436
247
|
export function setPushToken(provider, token) {
|
|
437
248
|
return NativeSDK.setPushToken(provider, token);
|
|
438
249
|
}
|
|
439
250
|
|
|
440
251
|
// ---------------- sdk wrappers ----------------
|
|
441
252
|
|
|
442
|
-
/**
|
|
443
|
-
* Clears SDK local state and stops active SDK background work (SDK-specific).
|
|
444
|
-
*
|
|
445
|
-
* ⚠️ Can throw (reject) on unexpected native errors.
|
|
446
|
-
*/
|
|
253
|
+
/** Clears SDK local state. */
|
|
447
254
|
export function clear() {
|
|
448
255
|
return NativeSDK.clear();
|
|
449
256
|
}
|
|
450
257
|
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
*/
|
|
455
|
-
export function reinitializeRetryControlInThisSession() {
|
|
456
|
-
return NativeSDK.reinitializeRetryControlInThisSession();
|
|
258
|
+
/** Resets session init-control state (platform-dependent). */
|
|
259
|
+
export function unlockInitOperationsInThisSession() {
|
|
260
|
+
return NativeSDK.unlockInitOperationsInThisSession();
|
|
457
261
|
}
|
|
458
262
|
|
|
459
|
-
/**
|
|
460
|
-
* Requests notification permission (where applicable).
|
|
461
|
-
*
|
|
462
|
-
* Note:
|
|
463
|
-
* - Usually no Promise here; native may silently no-op if not supported.
|
|
464
|
-
*/
|
|
263
|
+
/** Requests notification permission (platform-dependent). */
|
|
465
264
|
export function requestNotificationPermission() {
|
|
466
265
|
return NativeSDK.requestNotificationPermission();
|
|
467
266
|
}
|
|
468
267
|
|
|
469
|
-
// ----------------
|
|
268
|
+
// ---------------- UserDefaults / SharedPreferences ----------------
|
|
470
269
|
|
|
471
|
-
/**
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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));
|
|
270
|
+
/** Stores a value into native UserDefaults / SharedPreferences (platform-dependent). */
|
|
271
|
+
export function setUserDefaultsValue(suiteName, key, value) {
|
|
272
|
+
const str = toUserDefaultsString(value);
|
|
273
|
+
return NativeSDK.setUserDefaultsValue(suiteName, key, str);
|
|
480
274
|
}
|
|
481
275
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
276
|
+
// ---------------- MobileEvent (public: unknown, native: string) ----------------
|
|
277
|
+
|
|
278
|
+
/** Sends a mobile event (fire-and-forget). */
|
|
279
|
+
export function mobileEvent(sid, eventName, sendMessageId = null, payload = null, matching = null, matchingType = null, profileFields = null, utm = null) {
|
|
280
|
+
NativeSDK.mobileEvent(sid, eventName, sendMessageId, toNativeStringMap(payload), toNativeStringMap(matching), matchingType, toNativeStringMap(profileFields), utm);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Manually records a push delivery event (fire-and-forget). */
|
|
488
284
|
export function deliveryEvent(message = null, messageUID = null) {
|
|
489
285
|
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
490
286
|
...message
|
|
491
287
|
} : null;
|
|
288
|
+
|
|
289
|
+
// Kept as runtime call for backward-compat if some platform exposes it outside codegen.
|
|
492
290
|
NativeSDK.deliveryEvent(nativePayload, messageUID);
|
|
493
291
|
}
|
|
494
292
|
|
|
495
|
-
/**
|
|
496
|
-
* Manually registers an "open" event for a push notification.
|
|
497
|
-
*
|
|
498
|
-
* Note:
|
|
499
|
-
* - Fire-and-forget (no Promise). Native errors should be emitted as SDK events or logs.
|
|
500
|
-
*/
|
|
293
|
+
/** Manually records a push open event (fire-and-forget). */
|
|
501
294
|
export function openEvent(message = null, messageUID = null) {
|
|
502
295
|
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
503
296
|
...message
|
|
504
297
|
} : null;
|
|
298
|
+
|
|
299
|
+
// Kept as runtime call for backward-compat if some platform exposes it outside codegen.
|
|
505
300
|
NativeSDK.openEvent(nativePayload, messageUID);
|
|
506
301
|
}
|
|
507
302
|
|
|
508
303
|
// ---------------- Default export ----------------
|
|
509
304
|
|
|
510
|
-
/**
|
|
511
|
-
* Public React Native facade for the Altcraft SDK.
|
|
512
|
-
*
|
|
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
|
|
525
|
-
*/
|
|
305
|
+
/** Public React Native facade for the Altcraft SDK. */
|
|
526
306
|
const AltcraftSDK = {
|
|
527
307
|
initialize,
|
|
528
308
|
setJwt,
|
|
529
|
-
setAndroidFcmToken,
|
|
530
|
-
setIosFcmToken,
|
|
531
|
-
setAndroidHmsToken,
|
|
532
|
-
setIosHmsToken,
|
|
533
|
-
setApnsToken,
|
|
534
|
-
setRustoreToken,
|
|
535
309
|
pushSubscribe,
|
|
536
310
|
pushSuspend,
|
|
537
311
|
pushUnSubscribe,
|
|
@@ -544,18 +318,27 @@ const AltcraftSDK = {
|
|
|
544
318
|
forcedTokenUpdate,
|
|
545
319
|
changePushProviderPriorityList,
|
|
546
320
|
setPushToken,
|
|
547
|
-
clear,
|
|
548
|
-
reinitializeRetryControlInThisSession,
|
|
549
|
-
requestNotificationPermission,
|
|
550
321
|
mobileEvent,
|
|
322
|
+
subscribeToEvents,
|
|
323
|
+
unsubscribeFromEvent,
|
|
324
|
+
clear,
|
|
325
|
+
//ios only
|
|
326
|
+
setIosFcmToken,
|
|
327
|
+
setIosHmsToken,
|
|
328
|
+
setApnsToken,
|
|
329
|
+
setUserDefaultsValue,
|
|
330
|
+
//android only
|
|
331
|
+
setAndroidFcmToken,
|
|
332
|
+
setAndroidHmsToken,
|
|
333
|
+
setRustoreToken,
|
|
551
334
|
PushReceiver,
|
|
552
335
|
registerPushReceiver,
|
|
553
336
|
clearPushReceivers,
|
|
554
337
|
takePush,
|
|
555
|
-
subscribeToEvents,
|
|
556
|
-
unsubscribeFromEvent,
|
|
557
338
|
deliveryEvent,
|
|
558
|
-
openEvent
|
|
339
|
+
openEvent,
|
|
340
|
+
unlockInitOperationsInThisSession,
|
|
341
|
+
requestNotificationPermission
|
|
559
342
|
};
|
|
560
343
|
export default AltcraftSDK;
|
|
561
344
|
//# sourceMappingURL=index.js.map
|