@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.
- package/LICENSE +20 -20
- package/README.md +119 -27
- package/Sdk.podspec +2 -2
- package/android/build.gradle +3 -4
- package/android/src/main/java/com/altcraft/sdk/SdkEventEmitter.kt +50 -0
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +663 -480
- package/android/src/main/java/com/altcraft/sdk/SdkPackage.kt +16 -8
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +164 -0
- package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +72 -0
- package/ios/Converter.swift +485 -48
- package/ios/Sdk.mm +195 -270
- package/ios/SdkModule.swift +456 -507
- package/lib/module/NativeSdk.js +35 -0
- package/lib/module/NativeSdk.js.map +1 -1
- package/lib/module/Utilities.js +178 -0
- package/lib/module/Utilities.js.map +1 -0
- package/lib/module/index.js +335 -245
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSdk.d.ts +125 -33
- package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
- package/lib/typescript/src/Utilities.d.ts +47 -0
- package/lib/typescript/src/Utilities.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +218 -94
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeSdk.ts +169 -46
- package/src/Utilities.ts +180 -0
- package/src/index.tsx +410 -312
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -26
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnHMSProvider.kt +0 -32
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnJWTProvider.kt +0 -21
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnRustoreProvider.kt +0 -53
- package/ios/protocols/RNAPNSProvider.swift +0 -15
- package/ios/protocols/RNFCMProvider.swift +0 -24
- package/ios/protocols/RNHMSProvider.swift +0 -24
- package/ios/protocols/RNJWTProvider.swift +0 -15
package/lib/module/index.js
CHANGED
|
@@ -2,343 +2,433 @@
|
|
|
2
2
|
|
|
3
3
|
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
4
4
|
import NativeSDK from "./NativeSdk.js";
|
|
5
|
+
import { Utilities, ActionFieldBuilder, actionField } from "./Utilities.js";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
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. */
|
|
13
|
-
function toNativeStringMap(input) {
|
|
14
|
-
if (input == null) return null;
|
|
15
|
-
const out = {};
|
|
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
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
37
|
-
}
|
|
7
|
+
// ---------------- SDK API ----------------
|
|
38
8
|
|
|
39
9
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* - null/undefined -> null (native side can treat it as “remove key”)
|
|
10
|
+
* Initializes the Altcraft SDK.
|
|
11
|
+
*
|
|
12
|
+
* @param config SDK configuration.
|
|
13
|
+
* `apiUrl` is required.
|
|
14
|
+
* Other fields are optional and depend on platform features.
|
|
15
|
+
* @returns Promise that resolves on successful initialization.
|
|
47
16
|
*/
|
|
48
|
-
function
|
|
49
|
-
|
|
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
|
-
}
|
|
17
|
+
export function initialize(config) {
|
|
18
|
+
return NativeSDK.initialize(config);
|
|
58
19
|
}
|
|
59
20
|
|
|
60
|
-
// ----------------
|
|
61
|
-
|
|
62
|
-
/** JS handler interface for incoming push payloads. */
|
|
63
|
-
export class PushReceiver {}
|
|
64
|
-
|
|
65
|
-
/** Registered JS receivers for push payloads. */
|
|
66
|
-
const registeredPushReceivers = [];
|
|
67
|
-
|
|
68
|
-
/** Registers a JS push receiver. */
|
|
69
|
-
export function registerPushReceiver(receiver) {
|
|
70
|
-
registeredPushReceivers.push(receiver);
|
|
71
|
-
}
|
|
21
|
+
// ---------------- Push subscription ----------------
|
|
72
22
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Sends a push subscribe request.
|
|
25
|
+
*
|
|
26
|
+
* @param sync Execution mode:
|
|
27
|
+
* `true` — sends a synchronous request to the server and returns
|
|
28
|
+
* the result of the operation execution.
|
|
29
|
+
* `false` — sends an asynchronous request and returns
|
|
30
|
+
* the result of task enqueueing on the server.
|
|
31
|
+
* `null` — native default behavior.
|
|
32
|
+
* @param profileFields Optional profile fields to attach to the request.
|
|
33
|
+
* @param customFields Optional custom fields to attach to the request.
|
|
34
|
+
* @param cats Optional categories list.
|
|
35
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
36
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
37
|
+
*/
|
|
38
|
+
export function pushSubscribe(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
39
|
+
NativeSDK.pushSubscribe(sync, Utilities.toNativeStringMap(profileFields), Utilities.toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
76
40
|
}
|
|
77
41
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Sends a push suspend request.
|
|
44
|
+
*
|
|
45
|
+
* @param sync Execution mode (see {@link pushSubscribe}).
|
|
46
|
+
* @param profileFields Optional profile fields.
|
|
47
|
+
* @param customFields Optional custom fields.
|
|
48
|
+
* @param cats Optional categories list.
|
|
49
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
50
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
51
|
+
*/
|
|
52
|
+
export function pushSuspend(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
53
|
+
NativeSDK.pushSuspend(sync, Utilities.toNativeStringMap(profileFields), Utilities.toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
84
54
|
}
|
|
85
55
|
|
|
86
56
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
57
|
+
* Sends a push unsubscribe request.
|
|
58
|
+
*
|
|
59
|
+
* @param sync Execution mode (see {@link pushSubscribe}).
|
|
60
|
+
* @param profileFields Optional profile fields.
|
|
61
|
+
* @param customFields Optional custom fields.
|
|
62
|
+
* @param cats Optional categories list.
|
|
63
|
+
* @param replace Optional flag to replace an existing subscription.
|
|
64
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
89
65
|
*/
|
|
90
|
-
export function
|
|
91
|
-
|
|
92
|
-
NativeSDK.takePush({
|
|
93
|
-
...message
|
|
94
|
-
});
|
|
95
|
-
const receivers = registeredPushReceivers.length > 0 ? registeredPushReceivers : [new DefaultPushReceiver()];
|
|
96
|
-
for (const receiver of receivers) {
|
|
97
|
-
try {
|
|
98
|
-
receiver.pushHandler(message);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
|
-
console.warn('[AltcraftSDK] PushReceiver error:', e);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
66
|
+
export function pushUnSubscribe(sync = true, profileFields = null, customFields = null, cats = null, replace = null, skipTriggers = null) {
|
|
67
|
+
NativeSDK.pushUnSubscribe(sync, Utilities.toNativeStringMap(profileFields), Utilities.toNativeStringMap(customFields), cats, replace, skipTriggers);
|
|
104
68
|
}
|
|
105
69
|
|
|
106
|
-
// ----------------
|
|
107
|
-
|
|
108
|
-
/** RN subscription handle (NativeEventEmitter). */
|
|
70
|
+
// ---------------- Promise APIs ----------------
|
|
109
71
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export function subscribeToEvents(handler) {
|
|
118
|
-
if (eventsSubscription) {
|
|
119
|
-
eventsSubscription.remove();
|
|
120
|
-
eventsSubscription = null;
|
|
121
|
-
}
|
|
122
|
-
NativeSDK.subscribeToEvents();
|
|
123
|
-
eventsSubscription = nativeEventEmitter.addListener('AltcraftSdkEvent', (...args) => {
|
|
124
|
-
const event = args[0] ?? null;
|
|
125
|
-
if (!event) return;
|
|
126
|
-
try {
|
|
127
|
-
handler(event);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
72
|
+
/**
|
|
73
|
+
* Unsuspends push subscriptions based on native matching rules.
|
|
74
|
+
*
|
|
75
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
76
|
+
*/
|
|
77
|
+
export function unSuspendPushSubscription() {
|
|
78
|
+
return NativeSDK.unSuspendPushSubscription();
|
|
132
79
|
}
|
|
133
80
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
NativeSDK.
|
|
81
|
+
/**
|
|
82
|
+
* Returns the status of the latest subscription in profile.
|
|
83
|
+
*
|
|
84
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
85
|
+
*/
|
|
86
|
+
export function getStatusOfLatestSubscription() {
|
|
87
|
+
return NativeSDK.getStatusOfLatestSubscription();
|
|
141
88
|
}
|
|
142
89
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Returns the status of the subscription matching the current push token and provider context.
|
|
92
|
+
*
|
|
93
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
94
|
+
*/
|
|
95
|
+
export function getStatusForCurrentSubscription() {
|
|
96
|
+
return NativeSDK.getStatusForCurrentSubscription();
|
|
148
97
|
}
|
|
149
98
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Returns the status of the latest subscription for the given provider.
|
|
101
|
+
*
|
|
102
|
+
* If `provider` is `null`, native side may use the current provider context.
|
|
103
|
+
*
|
|
104
|
+
* @param provider Optional provider identifier (platform-dependent).
|
|
105
|
+
* @returns Promise resolving to response with HTTP code or `null` if unavailable.
|
|
106
|
+
*/
|
|
107
|
+
export function getStatusOfLatestSubscriptionForProvider(provider = null) {
|
|
108
|
+
return NativeSDK.getStatusOfLatestSubscriptionForProvider(provider);
|
|
153
109
|
}
|
|
154
110
|
|
|
155
|
-
//
|
|
111
|
+
// ---------------- Token API ----------------
|
|
156
112
|
|
|
157
|
-
/**
|
|
158
|
-
|
|
159
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Returns the current push token data from native side.
|
|
115
|
+
*
|
|
116
|
+
* @returns Promise resolving to token info or `null` if token is not available.
|
|
117
|
+
*/
|
|
118
|
+
export function getPushToken() {
|
|
119
|
+
return NativeSDK.getPushToken();
|
|
160
120
|
}
|
|
161
121
|
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Sets or clears the push token for a specific provider.
|
|
124
|
+
*
|
|
125
|
+
* @param provider Provider identifier (e.g. platform push provider name).
|
|
126
|
+
* @param token Token string or `null` to clear.
|
|
127
|
+
* @returns Promise that resolves when the token is saved on native side.
|
|
128
|
+
*/
|
|
129
|
+
export function setPushToken(provider, token) {
|
|
130
|
+
return NativeSDK.setPushToken(provider, token);
|
|
165
131
|
}
|
|
166
132
|
|
|
167
|
-
|
|
168
|
-
export function setAndroidHmsToken(token) {
|
|
169
|
-
return NativeSDK.setAndroidHmsToken(token);
|
|
170
|
-
}
|
|
133
|
+
// ---------------- SDK wrappers ----------------
|
|
171
134
|
|
|
172
|
-
/**
|
|
173
|
-
|
|
174
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Clears SDK local state (native).
|
|
137
|
+
*
|
|
138
|
+
* @returns Promise that resolves after cleanup.
|
|
139
|
+
*/
|
|
140
|
+
export function clear() {
|
|
141
|
+
return NativeSDK.clear();
|
|
175
142
|
}
|
|
176
143
|
|
|
177
|
-
|
|
178
|
-
export function setApnsToken(token) {
|
|
179
|
-
return NativeSDK.setApnsToken(token);
|
|
180
|
-
}
|
|
144
|
+
// ---------------- MobileEvent ----------------
|
|
181
145
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Sends a mobile event to the server.
|
|
148
|
+
*
|
|
149
|
+
* @param sid Pixel identifier.
|
|
150
|
+
* @param eventName Event name.
|
|
151
|
+
* @param sendMessageId Optional message identifier to link the event.
|
|
152
|
+
* @param payload Optional event payload.
|
|
153
|
+
* @param matching Optional matching parameters.
|
|
154
|
+
* @param matchingType Optional matching mode/type.
|
|
155
|
+
* @param profileFields Optional profile fields.
|
|
156
|
+
* @param subscription Optional subscription info to attach (email/sms/push/cc_data).
|
|
157
|
+
* @param utm Optional UTM tags for attribution.
|
|
158
|
+
*/
|
|
159
|
+
export function mobileEvent(sid, eventName, sendMessageId = null, payload = null, matching = null, matchingType = null, profileFields = null, subscription = null, utm = null) {
|
|
160
|
+
NativeSDK.mobileEvent(sid, eventName, sendMessageId, Utilities.toNativeStringMap(payload), Utilities.toNativeStringMap(matching), matchingType, Utilities.toNativeStringMap(profileFields), Utilities.subscriptionToNativeMap(subscription), utm ?? {
|
|
161
|
+
campaign: null,
|
|
162
|
+
content: null,
|
|
163
|
+
keyword: null,
|
|
164
|
+
medium: null,
|
|
165
|
+
source: null,
|
|
166
|
+
temp: null
|
|
167
|
+
});
|
|
185
168
|
}
|
|
186
169
|
|
|
187
|
-
// ----------------
|
|
170
|
+
// ---------------- SDK Event API ----------------
|
|
188
171
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
172
|
+
const ALTCRAFT_SDK_EVENT_NAME = 'AltcraftSdkEvent';
|
|
173
|
+
const nativeEventEmitter = new NativeEventEmitter(NativeModules.SDKEventEmitter);
|
|
174
|
+
let eventsSubscription = null;
|
|
175
|
+
const eventHandlers = new Set();
|
|
176
|
+
function ensureNativeSubscription() {
|
|
177
|
+
if (eventsSubscription === null) {
|
|
178
|
+
NativeSDK.subscribeToEvents();
|
|
179
|
+
eventsSubscription = nativeEventEmitter.addListener(ALTCRAFT_SDK_EVENT_NAME, (...args) => {
|
|
180
|
+
const event = args[0] ?? null;
|
|
181
|
+
if (!event) return;
|
|
182
|
+
const handlers = Array.from(eventHandlers);
|
|
183
|
+
for (const handler of handlers) {
|
|
184
|
+
try {
|
|
185
|
+
handler(event);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
console.warn('[AltcraftSDK] subscribeToEvents handler error:', e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Subscribes to native SDK events and routes them to the provided handler.
|
|
196
|
+
*
|
|
197
|
+
* Multiple callers can subscribe independently — each handler receives every event.
|
|
198
|
+
* The native subscription is activated only once (first caller).
|
|
199
|
+
*
|
|
200
|
+
* @param handler Callback invoked for each incoming SDK event.
|
|
201
|
+
* The event object is produced by native and follows {@link SdkEvent}.
|
|
202
|
+
*/
|
|
203
|
+
export function subscribeToEvents(handler) {
|
|
204
|
+
eventHandlers.add(handler);
|
|
205
|
+
ensureNativeSubscription();
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Unsubscribes a specific handler from native SDK events.
|
|
210
|
+
*
|
|
211
|
+
* When the last handler is removed, the native subscription is also released.
|
|
212
|
+
* Safe to call even if not subscribed.
|
|
213
|
+
*/
|
|
214
|
+
export function unsubscribeFromEvent(handler) {
|
|
215
|
+
if (handler) {
|
|
216
|
+
eventHandlers.delete(handler);
|
|
217
|
+
}
|
|
218
|
+
if (eventHandlers.size === 0) {
|
|
219
|
+
if (eventsSubscription) {
|
|
220
|
+
eventsSubscription.remove();
|
|
221
|
+
eventsSubscription = null;
|
|
222
|
+
}
|
|
223
|
+
NativeSDK.unsubscribeFromEvent();
|
|
224
|
+
}
|
|
202
225
|
}
|
|
203
226
|
|
|
204
|
-
|
|
205
|
-
export function unSuspendPushSubscription() {
|
|
206
|
-
return NativeSDK.unSuspendPushSubscription();
|
|
207
|
-
}
|
|
227
|
+
//Android-only behavior
|
|
208
228
|
|
|
209
|
-
|
|
210
|
-
export function getStatusOfLatestSubscription() {
|
|
211
|
-
return NativeSDK.getStatusOfLatestSubscription();
|
|
212
|
-
}
|
|
229
|
+
// ---------------- Push payload bridge ----------------
|
|
213
230
|
|
|
214
|
-
/**
|
|
215
|
-
|
|
216
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Forwards a push payload to native SDK (Android-only behavior).
|
|
233
|
+
*
|
|
234
|
+
* @param message Push payload map (string-only).
|
|
235
|
+
*/
|
|
236
|
+
export function takePush(message) {
|
|
237
|
+
if (!message || Object.keys(message).length === 0) return;
|
|
238
|
+
NativeSDK.takePush({
|
|
239
|
+
...message
|
|
240
|
+
});
|
|
217
241
|
}
|
|
218
242
|
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Requests notification permission (Android-only behavior).
|
|
245
|
+
* On Android it may trigger runtime permission flow,
|
|
246
|
+
* n iOS it can be a no-op or routed to native implementation.
|
|
247
|
+
*/
|
|
248
|
+
export function requestNotificationPermission() {
|
|
249
|
+
return NativeSDK.requestNotificationPermission();
|
|
222
250
|
}
|
|
223
251
|
|
|
224
|
-
// ----------------
|
|
252
|
+
// ---------------- Manual push events ----------------
|
|
225
253
|
|
|
226
|
-
/**
|
|
227
|
-
|
|
228
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Reports an Altcraft push delivery event (Android-only behavior).
|
|
256
|
+
*
|
|
257
|
+
* @param message Optional push payload (string-only).
|
|
258
|
+
* @param messageUID Optional Altcraft message UID.
|
|
259
|
+
*/
|
|
260
|
+
export function deliveryEvent(message = null, messageUID = null) {
|
|
261
|
+
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
262
|
+
...message
|
|
263
|
+
} : null;
|
|
264
|
+
NativeSDK.deliveryEvent(nativePayload, messageUID);
|
|
229
265
|
}
|
|
230
266
|
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Reports an Altcraft push open event (Android-only behavior).
|
|
269
|
+
*
|
|
270
|
+
* @param message Optional push payload (string-only).
|
|
271
|
+
* @param messageUID Optional Altcraft message UID.
|
|
272
|
+
*/
|
|
273
|
+
export function openEvent(message = null, messageUID = null) {
|
|
274
|
+
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
275
|
+
...message
|
|
276
|
+
} : null;
|
|
277
|
+
NativeSDK.openEvent(nativePayload, messageUID);
|
|
234
278
|
}
|
|
235
279
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
280
|
+
// ---------------- UserDefaults ----------------
|
|
281
|
+
/**
|
|
282
|
+
* Stores a value into native UserDefaults (IOS-only behavior).
|
|
283
|
+
*
|
|
284
|
+
* @param suiteName iOS App Group suite name or `null` to use standard UserDefaults.
|
|
285
|
+
* @param key Storage key.
|
|
286
|
+
* @param value Any JS value; will be converted to string or removed when `null/undefined`.
|
|
287
|
+
*/
|
|
288
|
+
export function setUserDefaultsValue(suiteName, key, value) {
|
|
289
|
+
const str = Utilities.toUserDefaultsString(value);
|
|
290
|
+
return NativeSDK.setUserDefaultsValue(suiteName, key, str);
|
|
239
291
|
}
|
|
240
292
|
|
|
241
|
-
|
|
242
|
-
export function changePushProviderPriorityList(priorityList) {
|
|
243
|
-
return NativeSDK.changePushProviderPriorityList(priorityList);
|
|
244
|
-
}
|
|
293
|
+
// ---------------- Profile API ----------------
|
|
245
294
|
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Updates profile fields on the server.
|
|
297
|
+
*
|
|
298
|
+
* @param profileFields Optional profile fields to update.
|
|
299
|
+
* @param skipTriggers Optional flag to skip trigger execution on the server.
|
|
300
|
+
*/
|
|
301
|
+
export function updateProfileFields(profileFields = null, skipTriggers = null) {
|
|
302
|
+
NativeSDK.updateProfileFields(Utilities.toNativeStringMap(profileFields), skipTriggers);
|
|
249
303
|
}
|
|
250
304
|
|
|
251
|
-
// ----------------
|
|
252
|
-
|
|
253
|
-
/** Clears SDK local state. */
|
|
254
|
-
export function clear() {
|
|
255
|
-
return NativeSDK.clear();
|
|
256
|
-
}
|
|
305
|
+
// ---------------- Token management API ----------------
|
|
257
306
|
|
|
258
|
-
/**
|
|
259
|
-
|
|
260
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Forces a push token refresh (delete current token + re-register).
|
|
309
|
+
*
|
|
310
|
+
* @returns Promise that resolves when the token update flow completes.
|
|
311
|
+
*/
|
|
312
|
+
export function forcedTokenUpdate() {
|
|
313
|
+
return NativeSDK.forcedTokenUpdate();
|
|
261
314
|
}
|
|
262
315
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Deletes the device token for a given provider.
|
|
318
|
+
*
|
|
319
|
+
* @param provider Provider identifier (e.g. `android-firebase`, `ios-firebase`).
|
|
320
|
+
* @returns Promise that resolves when the delete call completes.
|
|
321
|
+
*/
|
|
322
|
+
export function deleteDeviceToken(provider) {
|
|
323
|
+
return NativeSDK.deleteDeviceToken(provider);
|
|
266
324
|
}
|
|
267
325
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Changes the push provider priority list at runtime.
|
|
328
|
+
*
|
|
329
|
+
* @param priorityList Ordered list of provider identifiers.
|
|
330
|
+
* @returns Promise that resolves when the priority list is updated.
|
|
331
|
+
*/
|
|
332
|
+
export function changePushProviderPriorityList(priorityList) {
|
|
333
|
+
if (!priorityList || priorityList.length === 0) {
|
|
334
|
+
return Promise.resolve();
|
|
335
|
+
}
|
|
336
|
+
return NativeSDK.changePushProviderPriorityList(priorityList);
|
|
274
337
|
}
|
|
275
338
|
|
|
276
|
-
// ----------------
|
|
339
|
+
// ---------------- PushReceiver helpers ----------------
|
|
277
340
|
|
|
278
|
-
/**
|
|
279
|
-
|
|
280
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Checks whether a push payload belongs to Altcraft.
|
|
343
|
+
*
|
|
344
|
+
* @param message Push payload map (string-only).
|
|
345
|
+
* @returns `true` if the message contains the Altcraft marker key.
|
|
346
|
+
*/
|
|
347
|
+
export function isAltcraftPush(message) {
|
|
348
|
+
if (!message || Object.keys(message).length === 0) return false;
|
|
349
|
+
return NativeSDK.isAltcraftPush({
|
|
350
|
+
...message
|
|
351
|
+
});
|
|
281
352
|
}
|
|
282
353
|
|
|
283
|
-
|
|
284
|
-
export function deliveryEvent(message = null, messageUID = null) {
|
|
285
|
-
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
286
|
-
...message
|
|
287
|
-
} : null;
|
|
354
|
+
// ---------------- SDK lifecycle ----------------
|
|
288
355
|
|
|
289
|
-
|
|
290
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Allows re-running initial retry/scheduling/token-check logic
|
|
358
|
+
* in this process on the next initialization (Android only).
|
|
359
|
+
* No-op on iOS.
|
|
360
|
+
*/
|
|
361
|
+
export function unlockInitialOperationsInThisSession() {
|
|
362
|
+
NativeSDK.unlockInitialOperationsInThisSession();
|
|
291
363
|
}
|
|
292
364
|
|
|
293
|
-
|
|
294
|
-
export function openEvent(message = null, messageUID = null) {
|
|
295
|
-
const nativePayload = message && Object.keys(message).length > 0 ? {
|
|
296
|
-
...message
|
|
297
|
-
} : null;
|
|
365
|
+
// ---------------- iOS-only ----------------
|
|
298
366
|
|
|
299
|
-
|
|
300
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Sets the App Group name for shared UserDefaults and Core Data (iOS only).
|
|
369
|
+
* Must be called before SDK initialization.
|
|
370
|
+
*
|
|
371
|
+
* @param groupName App Group identifier or `null` to clear.
|
|
372
|
+
*/
|
|
373
|
+
export function setAppGroup(groupName) {
|
|
374
|
+
NativeSDK.setAppGroup(groupName);
|
|
301
375
|
}
|
|
302
376
|
|
|
303
377
|
// ---------------- Default export ----------------
|
|
304
378
|
|
|
305
|
-
/**
|
|
379
|
+
/**
|
|
380
|
+
* Public React Native facade for the Altcraft SDK.
|
|
381
|
+
*
|
|
382
|
+
* Provides:
|
|
383
|
+
* - SDK initialization
|
|
384
|
+
* - Push subscription operations
|
|
385
|
+
* - Subscription status queries
|
|
386
|
+
* - SDK event stream via NativeEventEmitter
|
|
387
|
+
* - Mobile events
|
|
388
|
+
* - Push token access
|
|
389
|
+
* - Local storage bridge (UserDefaults/SharedPreferences)
|
|
390
|
+
*/
|
|
306
391
|
const AltcraftSDK = {
|
|
392
|
+
// SDK initialization
|
|
307
393
|
initialize,
|
|
308
|
-
|
|
394
|
+
// Push subscription
|
|
309
395
|
pushSubscribe,
|
|
310
396
|
pushSuspend,
|
|
311
397
|
pushUnSubscribe,
|
|
312
398
|
unSuspendPushSubscription,
|
|
399
|
+
// Profile status
|
|
313
400
|
getStatusOfLatestSubscription,
|
|
314
401
|
getStatusOfLatestSubscriptionForProvider,
|
|
315
402
|
getStatusForCurrentSubscription,
|
|
316
|
-
|
|
317
|
-
deleteDeviceToken,
|
|
318
|
-
forcedTokenUpdate,
|
|
319
|
-
changePushProviderPriorityList,
|
|
320
|
-
setPushToken,
|
|
321
|
-
mobileEvent,
|
|
403
|
+
// SDK events
|
|
322
404
|
subscribeToEvents,
|
|
323
405
|
unsubscribeFromEvent,
|
|
406
|
+
// Mobile events
|
|
407
|
+
mobileEvent,
|
|
408
|
+
// Push token
|
|
409
|
+
setPushToken,
|
|
410
|
+
getPushToken,
|
|
411
|
+
// Clear SDK data
|
|
324
412
|
clear,
|
|
325
|
-
//
|
|
326
|
-
setIosFcmToken,
|
|
327
|
-
setIosHmsToken,
|
|
328
|
-
setApnsToken,
|
|
413
|
+
// Set UserDefault / SharedPreferenses
|
|
329
414
|
setUserDefaultsValue,
|
|
330
|
-
//
|
|
331
|
-
setAndroidFcmToken,
|
|
332
|
-
setAndroidHmsToken,
|
|
333
|
-
setRustoreToken,
|
|
334
|
-
PushReceiver,
|
|
335
|
-
registerPushReceiver,
|
|
336
|
-
clearPushReceivers,
|
|
415
|
+
// Android only
|
|
337
416
|
takePush,
|
|
338
417
|
deliveryEvent,
|
|
339
418
|
openEvent,
|
|
340
|
-
|
|
341
|
-
|
|
419
|
+
requestNotificationPermission,
|
|
420
|
+
unlockInitialOperationsInThisSession,
|
|
421
|
+
// Profile API
|
|
422
|
+
updateProfileFields,
|
|
423
|
+
// Token management
|
|
424
|
+
forcedTokenUpdate,
|
|
425
|
+
deleteDeviceToken,
|
|
426
|
+
changePushProviderPriorityList,
|
|
427
|
+
// PushReceiver helpers
|
|
428
|
+
isAltcraftPush,
|
|
429
|
+
// iOS only
|
|
430
|
+
setAppGroup
|
|
342
431
|
};
|
|
343
432
|
export default AltcraftSDK;
|
|
433
|
+
export { ActionFieldBuilder, actionField };
|
|
344
434
|
//# sourceMappingURL=index.js.map
|