@amplytools/react-native-amply-sdk 0.1.0 → 0.1.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/README.md +33 -673
- package/android/build.gradle +1 -1
- package/android/src/main/java/tools/amply/sdk/reactnative/AmplyModule.kt +32 -1
- package/android/src/main/java/tools/amply/sdk/reactnative/core/AmplyClient.kt +5 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/core/DefaultAmplyClient.kt +49 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/AmplyInitializationOptions.kt +35 -1
- package/dist/src/index.d.ts +14 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +67 -0
- package/dist/src/nativeSpecs/NativeAmplyModule.d.ts +29 -0
- package/dist/src/nativeSpecs/NativeAmplyModule.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/DEVELOPMENT.md +177 -0
- package/docs/FEATURE_DEBUG.md +326 -0
- package/ios/Sources/AmplyReactNative/AmplyModule.mm +113 -1
- package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative-generated.mm +16 -2
- package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative.h +14 -0
- package/package.json +6 -7
- package/src/index.ts +78 -0
- package/src/nativeSpecs/NativeAmplyModule.ts +30 -0
package/android/build.gradle
CHANGED
|
@@ -15,7 +15,7 @@ buildscript {
|
|
|
15
15
|
apply plugin: 'com.android.library'
|
|
16
16
|
apply plugin: 'org.jetbrains.kotlin.android'
|
|
17
17
|
|
|
18
|
-
def amplySdkVersion = project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '0.1.
|
|
18
|
+
def amplySdkVersion = project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '0.1.8'
|
|
19
19
|
group = 'tools.amply'
|
|
20
20
|
version = amplySdkVersion
|
|
21
21
|
|
|
@@ -9,6 +9,7 @@ import tools.amply.sdk.reactnative.model.DataSetType.EventParam
|
|
|
9
9
|
import tools.amply.sdk.reactnative.model.DataSetType.Events
|
|
10
10
|
import tools.amply.sdk.reactnative.model.DataSetType.TriggeredEvent
|
|
11
11
|
import tools.amply.sdk.reactnative.model.EventEnvelope
|
|
12
|
+
import tools.amply.sdk.reactnative.model.LogLevel
|
|
12
13
|
import tools.amply.sdk.reactnative.NativeAmplyModuleSpec
|
|
13
14
|
import com.facebook.react.bridge.Arguments
|
|
14
15
|
import com.facebook.react.bridge.Dynamic
|
|
@@ -40,6 +41,7 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
40
41
|
private var lastEmittedDeepLinkId: Long? = null
|
|
41
42
|
private var lifecycleRegistered = false
|
|
42
43
|
private var systemEventsJob: Job? = null
|
|
44
|
+
private var logEventsJob: Job? = null
|
|
43
45
|
|
|
44
46
|
override fun getName(): String = NAME
|
|
45
47
|
|
|
@@ -57,8 +59,12 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
57
59
|
override fun initialize(config: ReadableMap, promise: Promise) {
|
|
58
60
|
scope.launch {
|
|
59
61
|
try {
|
|
60
|
-
|
|
62
|
+
val options = config.toInitializationOptions()
|
|
63
|
+
|
|
64
|
+
client.initialize(options)
|
|
61
65
|
ensureSystemEventCollection()
|
|
66
|
+
ensureLogEventCollection()
|
|
67
|
+
|
|
62
68
|
promise.resolve(null)
|
|
63
69
|
} catch (throwable: Throwable) {
|
|
64
70
|
promise.reject(INIT_ERROR, throwable)
|
|
@@ -136,6 +142,15 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
136
142
|
client.registerDeepLinkListener()
|
|
137
143
|
}
|
|
138
144
|
|
|
145
|
+
override fun setLogLevel(level: String) {
|
|
146
|
+
val newLevel = LogLevel.fromString(level)
|
|
147
|
+
client.setLogLevel(newLevel)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
override fun getLogLevel(): String {
|
|
151
|
+
return client.getLogLevel().toString()
|
|
152
|
+
}
|
|
153
|
+
|
|
139
154
|
override fun addListener(eventName: String) {
|
|
140
155
|
// Required by RN EventEmitter contracts. The native TurboModule infrastructure
|
|
141
156
|
// handles the actual listener bookkeeping through the C++ event emitter.
|
|
@@ -163,6 +178,8 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
163
178
|
deepLinkJob = null
|
|
164
179
|
systemEventsJob?.cancel()
|
|
165
180
|
systemEventsJob = null
|
|
181
|
+
logEventsJob?.cancel()
|
|
182
|
+
logEventsJob = null
|
|
166
183
|
lastEmittedDeepLinkId = null
|
|
167
184
|
client.shutdown()
|
|
168
185
|
}
|
|
@@ -183,6 +200,16 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
183
200
|
emitOnSystemEvent(event.toWritableMap())
|
|
184
201
|
}
|
|
185
202
|
|
|
203
|
+
private fun ensureLogEventCollection() {
|
|
204
|
+
if (logEventsJob == null) {
|
|
205
|
+
logEventsJob = scope.launch {
|
|
206
|
+
client.logEvents.collectLatest { event ->
|
|
207
|
+
emitOnSystemEvent(event.toWritableMap())
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
186
213
|
private fun ensureSystemEventCollection() {
|
|
187
214
|
if (systemEventsJob == null) {
|
|
188
215
|
systemEventsJob = scope.launch {
|
|
@@ -208,6 +235,8 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
208
235
|
null
|
|
209
236
|
}
|
|
210
237
|
val defaultConfig = if (hasKey("defaultConfig")) getString("defaultConfig") else null
|
|
238
|
+
val debug = if (hasKey("debug")) getBoolean("debug") else null
|
|
239
|
+
val logLevel = if (hasKey("logLevel")) LogLevel.fromString(getString("logLevel")) else null
|
|
211
240
|
|
|
212
241
|
return AmplyInitializationOptions(
|
|
213
242
|
appId = appId,
|
|
@@ -216,6 +245,8 @@ class AmplyModule(reactContext: ReactApplicationContext) :
|
|
|
216
245
|
endpoint = endpoint,
|
|
217
246
|
datasetPrefetch = datasetPrefetch,
|
|
218
247
|
defaultConfig = defaultConfig,
|
|
248
|
+
debug = debug,
|
|
249
|
+
logLevel = logLevel,
|
|
219
250
|
)
|
|
220
251
|
}
|
|
221
252
|
|
|
@@ -5,11 +5,13 @@ import tools.amply.sdk.reactnative.model.AmplyInitializationOptions
|
|
|
5
5
|
import tools.amply.sdk.reactnative.model.DataSetType
|
|
6
6
|
import tools.amply.sdk.reactnative.model.DeepLinkPayload
|
|
7
7
|
import tools.amply.sdk.reactnative.model.EventEnvelope
|
|
8
|
+
import tools.amply.sdk.reactnative.model.LogLevel
|
|
8
9
|
import kotlinx.coroutines.flow.SharedFlow
|
|
9
10
|
|
|
10
11
|
interface AmplyClient {
|
|
11
12
|
val deepLinkEvents: SharedFlow<DeepLinkPayload>
|
|
12
13
|
val systemEvents: SharedFlow<EventEnvelope>
|
|
14
|
+
val logEvents: SharedFlow<EventEnvelope>
|
|
13
15
|
|
|
14
16
|
suspend fun initialize(options: AmplyInitializationOptions)
|
|
15
17
|
|
|
@@ -24,6 +26,9 @@ interface AmplyClient {
|
|
|
24
26
|
fun registerDeepLinkListener()
|
|
25
27
|
fun registerSystemEventListener()
|
|
26
28
|
|
|
29
|
+
fun setLogLevel(level: LogLevel)
|
|
30
|
+
fun getLogLevel(): LogLevel
|
|
31
|
+
|
|
27
32
|
fun onHostResume(activity: Activity?)
|
|
28
33
|
|
|
29
34
|
fun shutdown()
|
|
@@ -28,6 +28,8 @@ import tools.amply.sdk.config.amplyConfig
|
|
|
28
28
|
import tools.amply.sdk.core.AmplySDKInterface
|
|
29
29
|
import tools.amply.sdk.events.EventInterface
|
|
30
30
|
import tools.amply.sdk.events.SystemEventsListener
|
|
31
|
+
import tools.amply.sdk.logging.LogEntry
|
|
32
|
+
import tools.amply.sdk.logging.LogListener
|
|
31
33
|
|
|
32
34
|
class DefaultAmplyClient(
|
|
33
35
|
private val application: Application,
|
|
@@ -53,6 +55,12 @@ class DefaultAmplyClient(
|
|
|
53
55
|
)
|
|
54
56
|
override val systemEvents: SharedFlow<EventEnvelope> = _systemEvents.asSharedFlow()
|
|
55
57
|
|
|
58
|
+
private val _logEvents = MutableSharedFlow<EventEnvelope>(
|
|
59
|
+
replay = 0,
|
|
60
|
+
extraBufferCapacity = 64,
|
|
61
|
+
)
|
|
62
|
+
override val logEvents: SharedFlow<EventEnvelope> = _logEvents.asSharedFlow()
|
|
63
|
+
|
|
56
64
|
override suspend fun initialize(options: AmplyInitializationOptions) {
|
|
57
65
|
var createdInstance = false
|
|
58
66
|
mutex.withLock {
|
|
@@ -65,6 +73,35 @@ class DefaultAmplyClient(
|
|
|
65
73
|
val instance = withContext(Dispatchers.Default) {
|
|
66
74
|
Amply(config, application)
|
|
67
75
|
}
|
|
76
|
+
|
|
77
|
+
// Set log level from config
|
|
78
|
+
val effectiveLogLevel = options.getEffectiveLogLevel()
|
|
79
|
+
instance.setLogLevel(effectiveLogLevel.toString())
|
|
80
|
+
|
|
81
|
+
// Set up log listener to emit logs to JS
|
|
82
|
+
instance.setLogListener(object : LogListener {
|
|
83
|
+
override fun onLog(entry: LogEntry) {
|
|
84
|
+
val envelope = EventEnvelope(
|
|
85
|
+
id = null,
|
|
86
|
+
name = "DebugLog",
|
|
87
|
+
type = "system",
|
|
88
|
+
timestamp = entry.timestamp,
|
|
89
|
+
properties = buildMap {
|
|
90
|
+
put("level", entry.level.toString())
|
|
91
|
+
put("category", entry.category)
|
|
92
|
+
put("message", entry.message)
|
|
93
|
+
entry.details?.let { put("details", it) }
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
if (!_logEvents.tryEmit(envelope)) {
|
|
97
|
+
android.util.Log.w(
|
|
98
|
+
"AmplyReactNative",
|
|
99
|
+
"Dropping log event due to backpressure"
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
68
105
|
ensureSystemEventsListener(instance)
|
|
69
106
|
amplyInstance = instance
|
|
70
107
|
createdInstance = true
|
|
@@ -177,6 +214,18 @@ class DefaultAmplyClient(
|
|
|
177
214
|
ensureSystemEventsListener(instance)
|
|
178
215
|
}
|
|
179
216
|
|
|
217
|
+
override fun setLogLevel(level: tools.amply.sdk.reactnative.model.LogLevel) {
|
|
218
|
+
val instance = amplyInstance ?: return
|
|
219
|
+
instance.setLogLevel(level.toString())
|
|
220
|
+
android.util.Log.i("AmplyReactNative", "Log level set to: $level")
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
override fun getLogLevel(): tools.amply.sdk.reactnative.model.LogLevel {
|
|
224
|
+
val instance = amplyInstance ?: return tools.amply.sdk.reactnative.model.LogLevel.NONE
|
|
225
|
+
val kmpLevel = instance.getLogLevel()
|
|
226
|
+
return tools.amply.sdk.reactnative.model.LogLevel.fromString(kmpLevel.toString())
|
|
227
|
+
}
|
|
228
|
+
|
|
180
229
|
override fun onHostResume(activity: Activity?) {
|
|
181
230
|
if (activity != null) {
|
|
182
231
|
lastResumedActivity.set(WeakReference(activity))
|
package/android/src/main/java/tools/amply/sdk/reactnative/model/AmplyInitializationOptions.kt
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
package tools.amply.sdk.reactnative.model
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Log level for SDK debug output.
|
|
5
|
+
*/
|
|
6
|
+
enum class LogLevel(val level: Int) {
|
|
7
|
+
NONE(0),
|
|
8
|
+
ERROR(1),
|
|
9
|
+
WARN(2),
|
|
10
|
+
INFO(3),
|
|
11
|
+
DEBUG(4);
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
fun fromString(value: String?): LogLevel = when (value?.lowercase()) {
|
|
15
|
+
"none" -> NONE
|
|
16
|
+
"error" -> ERROR
|
|
17
|
+
"warn" -> WARN
|
|
18
|
+
"info" -> INFO
|
|
19
|
+
"debug" -> DEBUG
|
|
20
|
+
else -> NONE
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun toString(): String = name.lowercase()
|
|
25
|
+
}
|
|
26
|
+
|
|
3
27
|
data class AmplyInitializationOptions(
|
|
4
28
|
val appId: String,
|
|
5
29
|
val apiKeyPublic: String,
|
|
@@ -7,4 +31,14 @@ data class AmplyInitializationOptions(
|
|
|
7
31
|
val endpoint: String?,
|
|
8
32
|
val datasetPrefetch: List<DataSetType>?,
|
|
9
33
|
val defaultConfig: String?,
|
|
10
|
-
|
|
34
|
+
val debug: Boolean?,
|
|
35
|
+
val logLevel: LogLevel?,
|
|
36
|
+
) {
|
|
37
|
+
/**
|
|
38
|
+
* Get the effective log level, resolving debug vs logLevel precedence.
|
|
39
|
+
* logLevel takes precedence if specified, otherwise debug: true = DEBUG level.
|
|
40
|
+
*/
|
|
41
|
+
fun getEffectiveLogLevel(): LogLevel {
|
|
42
|
+
return logLevel ?: if (debug == true) LogLevel.DEBUG else LogLevel.NONE
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
export { useAmplySystemEvents } from './hooks/useAmplySystemEvents';
|
|
2
2
|
export { formatSystemEventLabel } from './systemEventUtils';
|
|
3
|
-
import type { AmplyInitializationConfig, DataSetSnapshot, DataSetType, DeepLinkEvent, EventRecord, TrackEventPayload } from './nativeSpecs/NativeAmplyModule';
|
|
3
|
+
import type { AmplyInitializationConfig, DataSetSnapshot, DataSetType, DeepLinkEvent, EventRecord, LogLevel, TrackEventPayload } from './nativeSpecs/NativeAmplyModule';
|
|
4
4
|
export declare function initialize(config: AmplyInitializationConfig): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Set the log level at runtime.
|
|
7
|
+
* @param level The log level: 'none' | 'error' | 'warn' | 'info' | 'debug'
|
|
8
|
+
*/
|
|
9
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get the current log level.
|
|
12
|
+
* @returns The current log level
|
|
13
|
+
*/
|
|
14
|
+
export declare function getLogLevel(): LogLevel;
|
|
5
15
|
export declare function isInitialized(): boolean;
|
|
6
16
|
export declare function track(payload: TrackEventPayload): Promise<void>;
|
|
7
17
|
export declare function getRecentEvents(limit: number): Promise<EventRecord[]>;
|
|
@@ -9,7 +19,7 @@ export declare function getDataSetSnapshot(type: DataSetType): Promise<DataSetSn
|
|
|
9
19
|
export declare function addDeepLinkListener(listener: (event: DeepLinkEvent) => void): Promise<() => void>;
|
|
10
20
|
export declare function addSystemEventListener(listener: (event: EventRecord) => void): Promise<() => void>;
|
|
11
21
|
export declare function removeAllListeners(): void;
|
|
12
|
-
export type { AmplyInitializationConfig, DataSetSnapshot, DataSetType, DeepLinkEvent, EventRecord, TrackEventPayload, };
|
|
22
|
+
export type { AmplyInitializationConfig, DataSetSnapshot, DataSetType, DeepLinkEvent, EventRecord, LogLevel, TrackEventPayload, };
|
|
13
23
|
export declare function addSystemEventsListener(listener: (event: EventRecord) => void): Promise<() => void>;
|
|
14
24
|
export declare const systemEvents: {
|
|
15
25
|
addListener: typeof addSystemEventsListener;
|
|
@@ -24,6 +34,8 @@ declare const _default: {
|
|
|
24
34
|
addSystemEventListener: typeof addSystemEventListener;
|
|
25
35
|
addSystemEventsListener: typeof addSystemEventsListener;
|
|
26
36
|
removeAllListeners: typeof removeAllListeners;
|
|
37
|
+
setLogLevel: typeof setLogLevel;
|
|
38
|
+
getLogLevel: typeof getLogLevel;
|
|
27
39
|
systemEvents: {
|
|
28
40
|
addListener: typeof addSystemEventsListener;
|
|
29
41
|
};
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,oBAAoB,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAC,sBAAsB,EAAC,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EACV,yBAAyB,EACzB,eAAe,EACf,WAAW,EACX,aAAa,E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BAAiB,GAClB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACrC,OAAO,CAAC,MAAM,IAAI,CAAC,CAErB;AAED,eAAO,MAAM,YAAY;;CAExB,CAAC;;;;;;;;;;;;;;;;;AAEF,wBAaE"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,7 +3,50 @@ import { addSystemEventListener as addSystemEventListenerInternal } from './syst
|
|
|
3
3
|
export { useAmplySystemEvents } from './hooks/useAmplySystemEvents';
|
|
4
4
|
export { formatSystemEventLabel } from './systemEventUtils';
|
|
5
5
|
let deepLinkRegistered = false;
|
|
6
|
+
let debugLogListenerRegistered = false;
|
|
6
7
|
const deepLinkSubscriptions = new Set();
|
|
8
|
+
/**
|
|
9
|
+
* Format a debug log entry for console output.
|
|
10
|
+
*/
|
|
11
|
+
function formatDebugLog(event) {
|
|
12
|
+
var _a;
|
|
13
|
+
const props = event.properties;
|
|
14
|
+
const level = ((_a = props.level) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'DEBUG';
|
|
15
|
+
const category = props.category || '';
|
|
16
|
+
return `[Amply ${level}] [${category}] ${props.message || ''}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Set up debug log listener that outputs to console.
|
|
20
|
+
* This is called automatically when debug mode is enabled.
|
|
21
|
+
*/
|
|
22
|
+
function ensureDebugLogListener() {
|
|
23
|
+
if (debugLogListenerRegistered) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
debugLogListenerRegistered = true;
|
|
27
|
+
addSystemEventListenerInternal((event) => {
|
|
28
|
+
var _a;
|
|
29
|
+
if (event.name === 'DebugLog') {
|
|
30
|
+
const formattedLog = formatDebugLog(event);
|
|
31
|
+
const props = event.properties;
|
|
32
|
+
const level = (_a = props.level) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
33
|
+
// Use appropriate console method based on log level
|
|
34
|
+
switch (level) {
|
|
35
|
+
case 'error':
|
|
36
|
+
console.error(formattedLog);
|
|
37
|
+
break;
|
|
38
|
+
case 'warn':
|
|
39
|
+
console.warn(formattedLog);
|
|
40
|
+
break;
|
|
41
|
+
case 'debug':
|
|
42
|
+
console.debug(formattedLog);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
console.log(formattedLog);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
7
50
|
async function ensureDeepLinkRegistration() {
|
|
8
51
|
if (!deepLinkRegistered) {
|
|
9
52
|
console.log('[Amply] Calling registerDeepLinkListener on native module');
|
|
@@ -27,8 +70,30 @@ function trackDeepLinkSubscription(subscription) {
|
|
|
27
70
|
return unsubscribe;
|
|
28
71
|
}
|
|
29
72
|
export async function initialize(config) {
|
|
73
|
+
// Set up debug log listener if debug mode is enabled
|
|
74
|
+
if (config.debug || config.logLevel) {
|
|
75
|
+
ensureDebugLogListener();
|
|
76
|
+
}
|
|
30
77
|
await getNativeModule().initialize(config);
|
|
31
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the log level at runtime.
|
|
81
|
+
* @param level The log level: 'none' | 'error' | 'warn' | 'info' | 'debug'
|
|
82
|
+
*/
|
|
83
|
+
export function setLogLevel(level) {
|
|
84
|
+
// Ensure debug log listener is set up when changing log level
|
|
85
|
+
if (level !== 'none') {
|
|
86
|
+
ensureDebugLogListener();
|
|
87
|
+
}
|
|
88
|
+
getNativeModule().setLogLevel(level);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the current log level.
|
|
92
|
+
* @returns The current log level
|
|
93
|
+
*/
|
|
94
|
+
export function getLogLevel() {
|
|
95
|
+
return getNativeModule().getLogLevel();
|
|
96
|
+
}
|
|
32
97
|
export function isInitialized() {
|
|
33
98
|
return getNativeModule().isInitialized();
|
|
34
99
|
}
|
|
@@ -76,5 +141,7 @@ export default {
|
|
|
76
141
|
addSystemEventListener,
|
|
77
142
|
addSystemEventsListener,
|
|
78
143
|
removeAllListeners,
|
|
144
|
+
setLogLevel,
|
|
145
|
+
getLogLevel,
|
|
79
146
|
systemEvents,
|
|
80
147
|
};
|
|
@@ -3,6 +3,15 @@ import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
|
|
|
3
3
|
type JsonMap = {
|
|
4
4
|
[key: string]: unknown;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Log level for SDK debug output.
|
|
8
|
+
* - 'none': No logging
|
|
9
|
+
* - 'error': Only errors
|
|
10
|
+
* - 'warn': Errors and warnings
|
|
11
|
+
* - 'info': SDK lifecycle events (init, session start/end)
|
|
12
|
+
* - 'debug': Everything including campaign evaluation details
|
|
13
|
+
*/
|
|
14
|
+
export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
6
15
|
export type AmplyInitializationConfig = {
|
|
7
16
|
appId: string;
|
|
8
17
|
apiKeyPublic: string;
|
|
@@ -10,6 +19,16 @@ export type AmplyInitializationConfig = {
|
|
|
10
19
|
endpoint?: string | null;
|
|
11
20
|
datasetPrefetch?: DataSetType[] | null;
|
|
12
21
|
defaultConfig?: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Enable debug logging. Shorthand for logLevel: 'debug'.
|
|
24
|
+
* When true, logs will appear in the Metro console.
|
|
25
|
+
*/
|
|
26
|
+
debug?: boolean | null;
|
|
27
|
+
/**
|
|
28
|
+
* Set the log level for SDK output.
|
|
29
|
+
* Takes precedence over `debug` if both are specified.
|
|
30
|
+
*/
|
|
31
|
+
logLevel?: LogLevel | null;
|
|
13
32
|
};
|
|
14
33
|
export type EventType = 'custom' | 'system';
|
|
15
34
|
export type TrackEventPayload = {
|
|
@@ -65,6 +84,16 @@ export interface Spec extends TurboModule {
|
|
|
65
84
|
getRecentEvents(limit: number): Promise<EventRecord[]>;
|
|
66
85
|
getDataSetSnapshot(type: DataSetType): Promise<DataSetSnapshot>;
|
|
67
86
|
registerDeepLinkListener(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Set the log level at runtime.
|
|
89
|
+
* @param level The log level to set
|
|
90
|
+
*/
|
|
91
|
+
setLogLevel(level: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Get the current log level.
|
|
94
|
+
* @returns The current log level as a string
|
|
95
|
+
*/
|
|
96
|
+
getLogLevel(): string;
|
|
68
97
|
readonly onSystemEvent: EventEmitter<SystemEventPayload>;
|
|
69
98
|
readonly onDeepLink: EventEmitter<DeepLinkEvent>;
|
|
70
99
|
addListener(eventName: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAmplyModule.d.ts","sourceRoot":"","sources":["../../../src/nativeSpecs/NativeAmplyModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2CAA2C,CAAC;AAE5E,KAAK,OAAO,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAExC,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACvC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeAmplyModule.d.ts","sourceRoot":"","sources":["../../../src/nativeSpecs/NativeAmplyModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2CAA2C,CAAC;AAE5E,KAAK,OAAO,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAA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