react-native-asleep 1.2.0 → 2.1.0

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.
@@ -73,7 +73,7 @@ repositories {
73
73
  }
74
74
 
75
75
  dependencies {
76
- implementation('ai.asleep:asleepsdk:3.2.1') {
76
+ implementation('ai.asleep:asleepsdk:3.3.1') {
77
77
  exclude group: 'com.android.support'
78
78
  }
79
79
 
@@ -2,6 +2,10 @@ package ai.asleep.reactnative
2
2
 
3
3
  import ai.asleep.asleepsdk.Asleep
4
4
  import ai.asleep.asleepsdk.data.AsleepConfig
5
+ import ai.asleep.asleepsdk.data.Gender
6
+ import ai.asleep.asleepsdk.data.ProductInfo
7
+ import ai.asleep.asleepsdk.data.UserInfo
8
+ import ai.asleep.asleepsdk.data.UserMetadata
5
9
  import ai.asleep.asleepsdk.data.Report
6
10
  import ai.asleep.asleepsdk.data.SleepSession
7
11
  import ai.asleep.asleepsdk.tracking.Reports
@@ -11,6 +15,8 @@ import com.google.gson.reflect.TypeToken
11
15
  import expo.modules.kotlin.exception.CodedException
12
16
  import expo.modules.kotlin.modules.Module
13
17
  import expo.modules.kotlin.modules.ModuleDefinition
18
+ import expo.modules.kotlin.records.Field
19
+ import expo.modules.kotlin.records.Record
14
20
  import expo.modules.kotlin.Promise
15
21
  import android.Manifest
16
22
  import android.app.Activity
@@ -42,6 +48,7 @@ import android.util.Log
42
48
  import android.os.PowerManager
43
49
  import android.provider.Settings
44
50
  import android.net.Uri
51
+ import java.util.Date
45
52
 
46
53
  class AsleepModule : Module() {
47
54
  private val gson = Gson()
@@ -58,7 +65,9 @@ class AsleepModule : Module() {
58
65
 
59
66
  // Added variables to replace PreferenceHelper
60
67
  private var isTracking = false
61
- private var savedApiKey: String? = null
68
+ // Identity of the credentials used for the last initAsleepConfig: "apiKey:<key>" or
69
+ // "appId:<id>". Keys the reconnect short-circuit for both auth modes.
70
+ private var savedCredentialId: String? = null
62
71
  private var savedUserId: String? = null
63
72
 
64
73
  val trackingState: LiveData<TrackingState> get() = _trackingState
@@ -68,11 +77,11 @@ class AsleepModule : Module() {
68
77
  companion object {
69
78
  public const val MICROPHONE_PERMISSION_REQUEST_CODE = 1001
70
79
 
71
- // Error codes for which Android SDK 3.2.x AsleepCore.onErrorCodeReceived tears
80
+ // Error codes for which Android SDK 3.2.x-3.3.1 AsleepCore.onErrorCodeReceived tears
72
81
  // the session down and fires BOTH onFail and onFinish (dual dispatch). Only
73
82
  // these may suppress the follow-up onFinish; for any other code the native
74
83
  // session is still alive and a later onFinish is a genuine close.
75
- // Must stay in sync with TERMINAL_TRACKING_SDK_CODES in src/AsleepStore.ts.
84
+ // Must stay in sync with the first 13 TERMINAL_TRACKING_SDK_CODES in src/AsleepStore.ts.
76
85
  private val TERMINAL_TRACKING_ERROR_CODES = setOf(
77
86
  11003, // ERR_AUDIO
78
87
  22000, 22401, 22409, 22422, 22500, // ERR_CREATE_*
@@ -146,100 +155,160 @@ class AsleepModule : Module() {
146
155
  "onUserJoined", "onUserJoinFailed", "onUserDeleted", "onDebugLog",
147
156
  "onSetupDidComplete", "onSetupDidFail", "onSetupInProgress", "onAnalysisResult")
148
157
 
149
- AsyncFunction("setup") { apiKey: String, baseUrl: String?, callbackUrl: String?, service: String?, enableODA: Boolean?, promise: Promise ->
158
+ // JS validates the credential form and productInfo. Credentials travel as one record
159
+ // because AsyncFunction accepts at most eight parameters including the promise.
160
+ // A null productInfo skips product registration.
161
+ AsyncFunction("setup") { credentials: SetupCredentialsRecord, baseUrl: String?, callbackUrl: String?, service: String?, enableODA: Boolean?, productInfo: ProductInfoRecord?, promise: Promise ->
162
+ // setup() may switch credentials; drop the previous user config until the
163
+ // next initAsleepConfig() succeeds so per-user calls never run as the previous user.
164
+ _asleepConfig = null
165
+ _reportManager = null
166
+ val apiKey = credentials.apiKey
167
+ val appId = credentials.appId
168
+ val appSecret = credentials.appSecret
169
+ val product = productInfo?.let { record ->
170
+ val identifierType = when (record.identifierType) {
171
+ "serial" -> Asleep.ProductIdentifierType.SERIAL
172
+ "mac_address" -> Asleep.ProductIdentifierType.MAC_ADDRESS
173
+ else -> {
174
+ promise.reject("INVALID_ARGUMENT", "Unknown productInfo.identifierType: ${record.identifierType}", null)
175
+ return@AsyncFunction
176
+ }
177
+ }
178
+ ProductInfo(record.model, identifierType, record.identifierValue)
179
+ }
150
180
  try {
151
181
  val context = appContext.reactContext!!.applicationContext as Application
152
-
153
- Asleep.setup(
154
- context = context,
155
- apiKey = apiKey,
156
- baseUrl = baseUrl,
157
- callbackUrl = callbackUrl,
158
- service = service ?: "SleepTracking",
159
- enableODA = enableODA,
160
- asleepSetupListener = object : Asleep.AsleepSetupListener {
161
- override fun onComplete() {
162
- sendEvent("onSetupDidComplete", emptyMap<String, Any>())
163
- promise.resolve("Setup completed")
164
- }
165
-
166
- override fun onProgress(progress: Int) {
167
- sendEvent("onSetupInProgress", mapOf("progress" to progress))
168
- sendEvent("onDebugLog", mapOf("message" to "Setup progress: $progress%"))
169
- }
170
-
171
- override fun onFail(errorCode: Int, detail: String) {
172
- sendEvent("onSetupDidFail", mapOf("error" to detail, "sdkCode" to errorCode))
173
- sendEvent("onDebugLog", mapOf("message" to "Setup failed: $errorCode - $detail"))
174
- promise.reject("SETUP_FAILED", "Setup failed: $errorCode - $detail", null)
175
- }
182
+ val setupListener = object : Asleep.AsleepSetupListener {
183
+ override fun onComplete() {
184
+ sendEvent("onSetupDidComplete", emptyMap<String, Any>())
185
+ promise.resolve("Setup completed")
176
186
  }
177
- )
187
+
188
+ override fun onProgress(progress: Int) {
189
+ sendEvent("onSetupInProgress", mapOf("progress" to progress))
190
+ sendEvent("onDebugLog", mapOf("message" to "Setup progress: $progress%"))
191
+ }
192
+
193
+ override fun onFail(errorCode: Int, detail: String) {
194
+ sendEvent("onSetupDidFail", mapOf("error" to detail, "sdkCode" to errorCode))
195
+ sendEvent("onDebugLog", mapOf("message" to "Setup failed: $errorCode - $detail"))
196
+ rejectWithSdkCode(promise, "SETUP_FAILED", errorCode, "Setup failed: $errorCode - $detail")
197
+ }
198
+ }
199
+
200
+ if (appId != null && appSecret != null) {
201
+ Asleep.setup(
202
+ context = context,
203
+ appId = appId,
204
+ appSecret = appSecret,
205
+ baseUrl = baseUrl,
206
+ callbackUrl = callbackUrl,
207
+ service = service ?: "SleepTracking",
208
+ enableODA = enableODA,
209
+ asleepSetupListener = setupListener,
210
+ productInfo = product
211
+ )
212
+ } else {
213
+ Asleep.setup(
214
+ context = context,
215
+ apiKey = apiKey ?: "",
216
+ baseUrl = baseUrl,
217
+ callbackUrl = callbackUrl,
218
+ service = service ?: "SleepTracking",
219
+ enableODA = enableODA,
220
+ asleepSetupListener = setupListener,
221
+ productInfo = product
222
+ )
223
+ }
178
224
  } catch (e: Exception) {
179
225
  sendEvent("onDebugLog", mapOf("message" to "Setup failed: ${e.message}"))
180
226
  promise.reject("UNEXPECTED_ERROR", "Setup failed: ${e.message}", e)
181
227
  }
182
228
  }
183
229
 
184
- AsyncFunction("initAsleepConfig") { apiKey: String, userId: String?, baseUrl: String?, callbackUrl: String?, promise: Promise ->
230
+ AsyncFunction("initAsleepConfig") { apiKey: String?, appId: String?, appSecret: String?, userId: String?, baseUrl: String?, callbackUrl: String?, promise: Promise ->
185
231
  try {
186
232
  val context = appContext.reactContext!!.applicationContext as Application
187
-
188
- if (isTracking && savedApiKey == apiKey && savedUserId == userId) {
233
+ val useToken = appId != null && appSecret != null
234
+ val credentialId = if (useToken) "appId:$appId" else "apiKey:$apiKey"
235
+
236
+ // Only a live config from a previous successful init may take the shortcut;
237
+ // after a failed re-init the config is null and init must run again.
238
+ if (isTracking && _asleepConfig != null && savedCredentialId == credentialId && savedUserId == userId) {
189
239
  promise.resolve(mapOf("userId" to (savedUserId ?: "")))
190
240
  sendEvent("onDebugLog", mapOf("message" to "Service reconnected"))
191
241
  return@AsyncFunction
192
242
  }
193
243
 
194
- // Store API key in memory instead of preferences
195
- savedApiKey = apiKey
196
-
197
- Asleep.initAsleepConfig(
198
- context = context,
199
- apiKey = apiKey,
200
- userId = userId,
201
- baseUrl = baseUrl,
202
- callbackUrl = callbackUrl,
203
- service = "SleepTracking",
204
- object : Asleep.AsleepConfigListener {
205
- override fun onSuccess(userId: String?, asleepConfig: AsleepConfig?) {
206
- if (userId != null) {
207
- sendEvent("onDebugLog", mapOf("message" to "UserId is not null"))
208
- // Store userId in memory instead of preferences
209
- savedUserId = userId
210
- sendEvent("onUserJoined", mapOf("userId" to userId))
211
- }
212
- _asleepConfig = asleepConfig
213
-
214
- if (_asleepConfig != null) {
215
- sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
216
- _reportManager = Asleep.createReports(_asleepConfig)
217
- } else {
218
- sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is null"))
219
- promise.reject("CONFIG_ERROR", "AsleepConfig is null", null)
220
- return
221
- }
244
+ // Drop the previous user's config until onSuccess delivers the new one,
245
+ // so metadata and report calls never run as the previous user. On
246
+ // onFail both stay null.
247
+ _asleepConfig = null
248
+ _reportManager = null
249
+
250
+ val configListener = object : Asleep.AsleepConfigListener {
251
+ override fun onSuccess(userId: String?, asleepConfig: AsleepConfig?) {
252
+ // Record the credential identity only once this init succeeded.
253
+ savedCredentialId = credentialId
254
+ if (userId != null) {
255
+ sendEvent("onDebugLog", mapOf("message" to "UserId is not null"))
256
+ // Store userId in memory instead of preferences
257
+ savedUserId = userId
258
+ sendEvent("onUserJoined", mapOf("userId" to userId))
259
+ }
260
+ _asleepConfig = asleepConfig
222
261
 
262
+ if (_asleepConfig != null) {
223
263
  sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
224
-
225
- // Return userId in the response instead of just a success message
226
- promise.resolve(mapOf("userId" to (userId ?: "")))
227
- try {
228
- sendEvent("onDebugLog", mapOf("message" to "Initialization successful with userId: $userId"))
229
- } catch (e: Exception) {
230
- sendEvent("onDebugLog", mapOf("message" to "Error sending debug log: ${e.message}"))
231
- println("Error sending debug log: ${e.message}")
232
- }
264
+ _reportManager = Asleep.createReports(_asleepConfig)
265
+ } else {
266
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is null"))
267
+ promise.reject("CONFIG_ERROR", "AsleepConfig is null", null)
268
+ return
233
269
  }
234
270
 
235
- override fun onFail(errorCode: Int, detail: String) {
236
- sendEvent("onDebugLog", mapOf("message" to "Initialization failed: $errorCode - $detail"))
237
- sendEvent("onUserJoinFailed", mapOf("errorCode" to errorCode, "detail" to detail, "sdkCode" to errorCode))
238
- promise.reject("INITIALIZATION_FAILED", "Initialization failed: $errorCode - $detail", null)
271
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
272
+
273
+ // Return userId in the response instead of just a success message
274
+ promise.resolve(mapOf("userId" to (userId ?: "")))
275
+ try {
276
+ sendEvent("onDebugLog", mapOf("message" to "Initialization successful with userId: $userId"))
277
+ } catch (e: Exception) {
278
+ sendEvent("onDebugLog", mapOf("message" to "Error sending debug log: ${e.message}"))
279
+ println("Error sending debug log: ${e.message}")
239
280
  }
240
281
  }
241
- )
242
-
282
+
283
+ override fun onFail(errorCode: Int, detail: String) {
284
+ sendEvent("onDebugLog", mapOf("message" to "Initialization failed: $errorCode - $detail"))
285
+ sendEvent("onUserJoinFailed", mapOf("errorCode" to errorCode, "detail" to detail, "sdkCode" to errorCode))
286
+ promise.reject("INITIALIZATION_FAILED", "Initialization failed: $errorCode - $detail", null)
287
+ }
288
+ }
289
+
290
+ if (useToken) {
291
+ Asleep.initAsleepConfig(
292
+ context = context,
293
+ appId = appId,
294
+ appSecret = appSecret,
295
+ userId = userId,
296
+ baseUrl = baseUrl,
297
+ callbackUrl = callbackUrl,
298
+ service = "SleepTracking",
299
+ asleepConfigListener = configListener
300
+ )
301
+ } else {
302
+ Asleep.initAsleepConfig(
303
+ context = context,
304
+ apiKey = apiKey,
305
+ userId = userId,
306
+ baseUrl = baseUrl,
307
+ callbackUrl = callbackUrl,
308
+ service = "SleepTracking",
309
+ asleepConfigListener = configListener
310
+ )
311
+ }
243
312
  } catch (e: Exception) {
244
313
  sendEvent("onDebugLog", mapOf("message" to "Initialization failed: ${e.message}"))
245
314
  promise.reject("UNEXPECTED_ERROR", "Initialization failed: ${e.message}", e)
@@ -342,8 +411,13 @@ class AsleepModule : Module() {
342
411
  return@Function isTracking
343
412
  }
344
413
 
345
- AsyncFunction("stopTracking") { promise: Promise ->
346
- Asleep.endSleepTracking()
414
+ // Range bounds are epoch milliseconds; JS validates start < end before calling.
415
+ AsyncFunction("stopTracking") { analysisStartMs: Double?, analysisEndMs: Double?, promise: Promise ->
416
+ if (analysisStartMs != null && analysisEndMs != null) {
417
+ Asleep.endSleepTracking(Date(analysisStartMs.toLong()), Date(analysisEndMs.toLong()))
418
+ } else {
419
+ Asleep.endSleepTracking()
420
+ }
347
421
  isTracking = false
348
422
  promise.resolve(null)
349
423
  }
@@ -457,6 +531,102 @@ class AsleepModule : Module() {
457
531
  }
458
532
  }
459
533
 
534
+ // Resolves when the server accepts the request. Range bounds are epoch
535
+ // milliseconds and are always passed explicitly (null when absent).
536
+ AsyncFunction("reanalyze") { sessionId: String, analysisStartMs: Double?, analysisEndMs: Double?, promise: Promise ->
537
+ val reportManager = _reportManager
538
+ if (reportManager == null) {
539
+ promise.reject("MISSING_PREREQUISITE", "Report manager is not initialized", null)
540
+ return@AsyncFunction
541
+ }
542
+ val listener = object : Reports.ReanalyzeListener {
543
+ override fun onSuccess(sessionId: String) {
544
+ sendEvent("onDebugLog", mapOf("message" to "reanalyze accepted: $sessionId"))
545
+ promise.resolve(null)
546
+ }
547
+
548
+ override fun onFail(errorCode: Int, detail: String) {
549
+ sendEvent("onDebugLog", mapOf("message" to "reanalyze failed: $errorCode - $detail"))
550
+ // 11009 ERR_INVALID_PARAMETER: start >= end (JS validates this first).
551
+ val code = if (errorCode == 11009) "INVALID_ARGUMENT" else "REANALYZE_FAILED"
552
+ rejectWithSdkCode(promise, code, errorCode, detail)
553
+ }
554
+ }
555
+ try {
556
+ if (analysisStartMs != null && analysisEndMs != null) {
557
+ reportManager.reanalyze(sessionId, Date(analysisStartMs.toLong()), Date(analysisEndMs.toLong()), listener)
558
+ } else {
559
+ reportManager.reanalyze(sessionId, listener)
560
+ }
561
+ } catch (e: Exception) {
562
+ rejectWithSdkCode(promise, "REANALYZE_FAILED", 30000, e.message ?: "Failed to request reanalysis")
563
+ }
564
+ }
565
+
566
+ AsyncFunction("saveUserMetadata") { metadata: UserMetadataRecord, promise: Promise ->
567
+ val config = _asleepConfig
568
+ if (config == null) {
569
+ promise.reject("MISSING_PREREQUISITE", "AsleepConfig is not initialized", null)
570
+ return@AsyncFunction
571
+ }
572
+ val model = try {
573
+ val gender = metadata.gender?.let { raw ->
574
+ Gender.values().firstOrNull { it.value == raw }
575
+ ?: throw IllegalArgumentException("Unknown gender: $raw")
576
+ }
577
+ // The UserMetadata constructor throws IllegalArgumentException for out-of-range values.
578
+ UserMetadata(
579
+ birthYear = metadata.birthYear,
580
+ birthMonth = metadata.birthMonth,
581
+ birthDay = metadata.birthDay,
582
+ gender = gender,
583
+ height = metadata.height?.toFloat(),
584
+ weight = metadata.weight?.toFloat()
585
+ )
586
+ } catch (e: IllegalArgumentException) {
587
+ rejectWithSdkCode(promise, "INVALID_ARGUMENT", 27400, e.message ?: "Invalid user metadata")
588
+ return@AsyncFunction
589
+ }
590
+ try {
591
+ config.saveUserMetadata(model, object : Asleep.SaveUserMetadataListener {
592
+ override fun onSuccess(userInfo: UserInfo) {
593
+ sendEvent("onDebugLog", mapOf("message" to "saveUserMetadata completed"))
594
+ promise.resolve(null)
595
+ }
596
+
597
+ override fun onFail(errorCode: Int, detail: String) {
598
+ sendEvent("onDebugLog", mapOf("message" to "saveUserMetadata failed: $errorCode - $detail"))
599
+ val code = if (errorCode == 27400) "INVALID_ARGUMENT" else "SAVE_USER_METADATA_FAILED"
600
+ rejectWithSdkCode(promise, code, errorCode, detail)
601
+ }
602
+ })
603
+ } catch (e: Exception) {
604
+ rejectWithSdkCode(promise, "SAVE_USER_METADATA_FAILED", 27000, e.message ?: "Failed to save user metadata")
605
+ }
606
+ }
607
+
608
+ AsyncFunction("fetchUserMetadata") { promise: Promise ->
609
+ val config = _asleepConfig
610
+ if (config == null) {
611
+ promise.reject("MISSING_PREREQUISITE", "AsleepConfig is not initialized", null)
612
+ return@AsyncFunction
613
+ }
614
+ try {
615
+ config.fetchUserMetadata(object : Asleep.FetchUserMetadataListener {
616
+ override fun onSuccess(metadata: UserMetadata?) {
617
+ promise.resolve(metadata?.serializeToMap())
618
+ }
619
+
620
+ override fun onFail(errorCode: Int, detail: String) {
621
+ sendEvent("onDebugLog", mapOf("message" to "fetchUserMetadata failed: $errorCode - $detail"))
622
+ rejectWithSdkCode(promise, "FETCH_USER_METADATA_FAILED", errorCode, detail)
623
+ }
624
+ })
625
+ } catch (e: Exception) {
626
+ rejectWithSdkCode(promise, "FETCH_USER_METADATA_FAILED", 27100, e.message ?: "Failed to fetch user metadata")
627
+ }
628
+ }
629
+
460
630
  AsyncFunction("hasRequiredPermissions") { promise: Promise ->
461
631
  promise.resolve(hasRequiredPermissions())
462
632
  }
@@ -641,6 +811,12 @@ class AsleepModule : Module() {
641
811
  }
642
812
  }
643
813
 
814
+ // Expo rejections carry only a code string and a message. JS normalizeError
815
+ // splits "<CODE>:<sdkCode>" back into AsleepError.code and AsleepError.sdkCode.
816
+ private fun rejectWithSdkCode(promise: Promise, code: String, sdkCode: Int, message: String) {
817
+ promise.reject("$code:$sdkCode", message, null)
818
+ }
819
+
644
820
  private fun <T> T.serializeToMap(): Map<String, Any> {
645
821
  return convert()
646
822
  }
@@ -684,3 +860,24 @@ class AsleepModule : Module() {
684
860
  }
685
861
  }
686
862
  }
863
+
864
+ class SetupCredentialsRecord : Record {
865
+ @Field val apiKey: String? = null
866
+ @Field val appId: String? = null
867
+ @Field val appSecret: String? = null
868
+ }
869
+
870
+ class ProductInfoRecord : Record {
871
+ @Field val model: String = ""
872
+ @Field val identifierType: String = ""
873
+ @Field val identifierValue: String = ""
874
+ }
875
+
876
+ class UserMetadataRecord : Record {
877
+ @Field val birthYear: Int? = null
878
+ @Field val birthMonth: Int? = null
879
+ @Field val birthDay: Int? = null
880
+ @Field val gender: String? = null
881
+ @Field val height: Double? = null
882
+ @Field val weight: Double? = null
883
+ }
@@ -1,15 +1,45 @@
1
- export type AsleepConfig = {
1
+ /**
2
+ * Authentication passed to `setup()` and `initAsleepConfig()`: either an API
3
+ * key or a token-auth `appId` / `appSecret` pair. The two forms are mutually
4
+ * exclusive; supplying neither or both is rejected with `INVALID_ARGUMENT`.
5
+ */
6
+ export type AsleepCredentials = {
2
7
  apiKey: string;
8
+ appId?: never;
9
+ appSecret?: never;
10
+ } | {
11
+ appId: string;
12
+ appSecret: string;
13
+ apiKey?: never;
14
+ };
15
+ export type AsleepConfig = AsleepCredentials & {
3
16
  userId?: string;
4
17
  baseUrl?: string;
5
18
  callbackUrl?: string;
6
19
  };
7
- export type AsleepSetupConfig = {
8
- apiKey: string;
20
+ export type AsleepProductIdentifierType = "serial" | "mac_address";
21
+ /**
22
+ * The hardware product this app runs on, registered with Asleep during
23
+ * `setup()`. `setup()` rejects invalid input with `INVALID_ARGUMENT` before any
24
+ * native call. Values are sent as given; they are not trimmed.
25
+ */
26
+ export type AsleepProductInfo = {
27
+ /** Product model name, 1-100 characters, not blank. */
28
+ model: string;
29
+ identifierType: AsleepProductIdentifierType;
30
+ /** The device's serial number or MAC address, 1-255 characters, not blank. */
31
+ identifierValue: string;
32
+ };
33
+ export type AsleepSetupConfig = AsleepCredentials & {
9
34
  baseUrl?: string;
10
35
  callbackUrl?: string;
11
36
  service?: string;
12
37
  enableODA?: boolean;
38
+ /**
39
+ * Registers this device as a product before setup completes. Omit it to skip
40
+ * registration. See "Device registration" in the README.
41
+ */
42
+ productInfo?: AsleepProductInfo;
13
43
  };
14
44
  export type AsleepReport = {
15
45
  timezone: string;
@@ -138,6 +168,48 @@ export type AsleepAverageReport = {
138
168
  neverSleptSessions?: AsleepNeverSleptSession[];
139
169
  sleptSessions?: AsleepSleptSession[];
140
170
  };
171
+ /**
172
+ * Wall-clock window the server analyzes instead of the whole recording.
173
+ * `start` must be at least one second before `end` (whole-second precision);
174
+ * otherwise the action rejects with `INVALID_ARGUMENT` before any native call.
175
+ */
176
+ export type AsleepAnalysisRange = {
177
+ start: Date;
178
+ end: Date;
179
+ };
180
+ export type StopTrackingOptions = {
181
+ /**
182
+ * Analyze only this window of the session. The server may silently ignore
183
+ * an invalid range and analyze the full session; no event reports that.
184
+ */
185
+ analysisRange?: AsleepAnalysisRange;
186
+ };
187
+ export type ReanalyzeOptions = {
188
+ /**
189
+ * Re-run analysis only for this window. Omitting it re-analyzes the full
190
+ * session and replaces any range set earlier, including one set at stop.
191
+ */
192
+ analysisRange?: AsleepAnalysisRange;
193
+ };
194
+ export type AsleepGender = "male" | "female" | "non_binary" | "other" | "prefer_not_to_say";
195
+ /**
196
+ * Optional user profile used by the server to personalize analysis. Every
197
+ * field is optional; omitted fields are not sent. `saveUserMetadata()` rejects
198
+ * out-of-range values with `INVALID_ARGUMENT` before any native call.
199
+ */
200
+ export type AsleepUserMetadata = {
201
+ /** Integer, 1900-2100. */
202
+ birthYear?: number;
203
+ /** Integer, 1-12. */
204
+ birthMonth?: number;
205
+ /** Integer, 1-31. */
206
+ birthDay?: number;
207
+ gender?: AsleepGender;
208
+ /** Centimeters, 1-500. The native SDKs truncate to one decimal place. */
209
+ height?: number;
210
+ /** Kilograms, 1-1000. The native SDKs truncate to one decimal place. */
211
+ weight?: number;
212
+ };
141
213
  export type AsleepAnalysisResult = {
142
214
  id?: string;
143
215
  state?: string;
@@ -213,7 +285,9 @@ export type AsleepEventType = {
213
285
  message?: string;
214
286
  /**
215
287
  * @deprecated On iOS this is the Swift enum declaration ordinal from
216
- * NSError bridging, not the documented Asleep error code. Use `sdkCode`.
288
+ * NSError bridging, not the documented Asleep error code, and it shifts
289
+ * when the native enum gains cases (iOS SDK 3.3.x moved 38/39 to 59/60).
290
+ * Use `sdkCode`, `caseName`, or `category`.
217
291
  */
218
292
  errorCode?: number;
219
293
  /** Numeric code documented by the native Asleep SDKs (both platforms). */
@@ -1 +1 @@
1
- {"version":3,"file":"Asleep.types.d.ts","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM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C,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["export type AsleepConfig = {\n apiKey: string;\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepSetupConfig = {\n apiKey: string;\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\n// From getReportList() - maps to SDK SleepSession\nexport type AsleepSession = {\n id: string; // mapped from sessionId\n state: string;\n startTime: string; // mapped from sessionStartTime\n endTime?: string; // mapped from sessionEndTime\n createdTimezone: string;\n unexpectedEndTime?: string;\n lastReceivedSeqNum?: number;\n timeInBed?: number;\n};\n\n// From getAverageReport() sleptSessions - maps to SDK SleptSession\nexport type AsleepSleptSession = {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n sleepEfficiency: number;\n sleepLatency?: number;\n wakeupLatency?: number;\n lightLatency?: number;\n deepLatency?: number;\n remLatency?: number;\n sleepTime?: string;\n wakeTime?: string;\n timeInWake: number;\n timeInSleepPeriod: number;\n timeInSleep: number;\n timeInBed: number;\n timeInRem?: number;\n timeInLight?: number;\n timeInDeep?: number;\n timeInStableBreath?: number;\n timeInUnstableBreath?: number;\n timeInSnoring?: number;\n timeInNoSnoring?: number;\n wakeRatio: number;\n sleepRatio: number;\n remRatio?: number;\n lightRatio?: number;\n deepRatio?: number;\n stableBreathRatio?: number;\n unstableBreathRatio?: number;\n snoringRatio?: number;\n noSnoringRatio?: number;\n unstableBreathCount?: number;\n breathingPattern?: string;\n breathingIndex?: number;\n sleepCycle?: number;\n sleepCycleCount?: number;\n wasoCount?: number;\n longestWaso?: number;\n snoringCount?: number;\n};\n\n// From getAverageReport() neverSleptSessions - maps to SDK NeverSleptSession\nexport type AsleepNeverSleptSession = {\n id: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n};\n\nexport type AsleepAverageReport = {\n period: {\n timezone: string;\n startDate: string;\n endDate: string;\n };\n peculiarities: string[];\n averageStats?: AsleepStat;\n neverSleptSessions?: AsleepNeverSleptSession[];\n sleptSessions?: AsleepSleptSession[];\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\n// iOS resolves requestAnalysis with an ack while the real payload arrives via the\n// onAnalysisResult event. Android resolves with the full AsleepAnalysisResult and also\n// fires the event. Consumers reading the promise return value should narrow on `status`.\nexport type AsleepAnalysisAck = {\n status: \"requested\";\n timestamp: number;\n};\n\nexport type SetupStatus = \"idle\" | \"inProgress\" | \"complete\";\n\nexport type TrackingStatus = \"idle\" | \"tracking\" | \"paused\" | \"recoveryRequired\";\n\nexport type AudioSessionOption = \"duckOthers\" | \"allowAirPlay\" | \"allowBluetooth\" | \"allowBluetoothA2DP\";\n\nexport type TrackingConfig = {\n android?: {\n notification?: {\n title?: string;\n text?: string;\n icon?: string;\n };\n };\n ios?: {\n /** Additional AVAudioSession options appended to SDK defaults (mixWithOthers, allowBluetoothA2DP, defaultToSpeaker). Options reset on each startTracking() call. */\n audioSessionOptions?: AudioSessionOption[];\n };\n};\n\n/**\n * Coarse classification of a tracking-runtime failure (onTrackingFailed),\n * derived from the native error code. The library reports the objective fact;\n * the app decides log severity. Recommended mapping:\n * - \"terminal\" / \"recordingDead\" → error (session or recorder is gone)\n * - \"recoveryRequired\" / \"transient\" → warning (tracking is still alive and a\n * defined recovery path exists)\n * - \"unknown\" → error (unclassified; do not assume it is benign)\n */\nexport type AsleepErrorCategory = \"terminal\" | \"recordingDead\" | \"recoveryRequired\" | \"transient\" | \"unknown\";\n\n/**\n * Structured error used everywhere the SDK reports a failure.\n *\n * `code` is a stable machine identifier. Classified tracking failures also\n * carry their category and documented native SDK code, while `cause` retains\n * the original rejection or event payload for observability.\n */\nexport class AsleepError extends Error {\n readonly code: string;\n readonly category?: AsleepErrorCategory;\n readonly sdkCode?: number;\n readonly caseName?: string;\n readonly cause?: unknown;\n\n constructor(\n code: string,\n message: string,\n options?: {\n cause?: unknown;\n category?: AsleepErrorCategory;\n sdkCode?: number;\n caseName?: string;\n },\n ) {\n super(message);\n this.name = \"AsleepError\";\n this.code = code;\n this.category = options?.category;\n this.sdkCode = options?.sdkCode;\n this.caseName = options?.caseName;\n this.cause = options?.cause;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: {\n error: string;\n code: string;\n message?: string;\n /**\n * @deprecated On iOS this is the Swift enum declaration ordinal from\n * NSError bridging, not the documented Asleep error code. Use `sdkCode`.\n */\n errorCode?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n caseName?: string;\n };\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: { userId: string };\n onUserJoinFailed: {\n error?: string;\n errorCode?: number;\n detail?: string;\n caseName?: string;\n code?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onUserDeleted: { userId: string };\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: {\n error: string;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onSetupInProgress: { progress: number };\n onAnalysisResult: AsleepAnalysisResult;\n};\n"]}
1
+ {"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"AAkRA;;;;;;GAMG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,QAAQ,CAAuB;IAC/B,OAAO,CAAU;IACjB,QAAQ,CAAU;IAClB,KAAK,CAAW;IAEzB,YACE,IAAY,EACZ,OAAe,EACf,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["/**\n * Authentication passed to `setup()` and `initAsleepConfig()`: either an API\n * key or a token-auth `appId` / `appSecret` pair. The two forms are mutually\n * exclusive; supplying neither or both is rejected with `INVALID_ARGUMENT`.\n */\nexport type AsleepCredentials =\n | { apiKey: string; appId?: never; appSecret?: never }\n | { appId: string; appSecret: string; apiKey?: never };\n\nexport type AsleepConfig = AsleepCredentials & {\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepProductIdentifierType = \"serial\" | \"mac_address\";\n\n/**\n * The hardware product this app runs on, registered with Asleep during\n * `setup()`. `setup()` rejects invalid input with `INVALID_ARGUMENT` before any\n * native call. Values are sent as given; they are not trimmed.\n */\nexport type AsleepProductInfo = {\n /** Product model name, 1-100 characters, not blank. */\n model: string;\n identifierType: AsleepProductIdentifierType;\n /** The device's serial number or MAC address, 1-255 characters, not blank. */\n identifierValue: string;\n};\n\nexport type AsleepSetupConfig = AsleepCredentials & {\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n /**\n * Registers this device as a product before setup completes. Omit it to skip\n * registration. See \"Device registration\" in the README.\n */\n productInfo?: AsleepProductInfo;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\n// From getReportList() - maps to SDK SleepSession\nexport type AsleepSession = {\n id: string; // mapped from sessionId\n state: string;\n startTime: string; // mapped from sessionStartTime\n endTime?: string; // mapped from sessionEndTime\n createdTimezone: string;\n unexpectedEndTime?: string;\n lastReceivedSeqNum?: number;\n timeInBed?: number;\n};\n\n// From getAverageReport() sleptSessions - maps to SDK SleptSession\nexport type AsleepSleptSession = {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n sleepEfficiency: number;\n sleepLatency?: number;\n wakeupLatency?: number;\n lightLatency?: number;\n deepLatency?: number;\n remLatency?: number;\n sleepTime?: string;\n wakeTime?: string;\n timeInWake: number;\n timeInSleepPeriod: number;\n timeInSleep: number;\n timeInBed: number;\n timeInRem?: number;\n timeInLight?: number;\n timeInDeep?: number;\n timeInStableBreath?: number;\n timeInUnstableBreath?: number;\n timeInSnoring?: number;\n timeInNoSnoring?: number;\n wakeRatio: number;\n sleepRatio: number;\n remRatio?: number;\n lightRatio?: number;\n deepRatio?: number;\n stableBreathRatio?: number;\n unstableBreathRatio?: number;\n snoringRatio?: number;\n noSnoringRatio?: number;\n unstableBreathCount?: number;\n breathingPattern?: string;\n breathingIndex?: number;\n sleepCycle?: number;\n sleepCycleCount?: number;\n wasoCount?: number;\n longestWaso?: number;\n snoringCount?: number;\n};\n\n// From getAverageReport() neverSleptSessions - maps to SDK NeverSleptSession\nexport type AsleepNeverSleptSession = {\n id: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n};\n\nexport type AsleepAverageReport = {\n period: {\n timezone: string;\n startDate: string;\n endDate: string;\n };\n peculiarities: string[];\n averageStats?: AsleepStat;\n neverSleptSessions?: AsleepNeverSleptSession[];\n sleptSessions?: AsleepSleptSession[];\n};\n\n/**\n * Wall-clock window the server analyzes instead of the whole recording.\n * `start` must be at least one second before `end` (whole-second precision);\n * otherwise the action rejects with `INVALID_ARGUMENT` before any native call.\n */\nexport type AsleepAnalysisRange = {\n start: Date;\n end: Date;\n};\n\nexport type StopTrackingOptions = {\n /**\n * Analyze only this window of the session. The server may silently ignore\n * an invalid range and analyze the full session; no event reports that.\n */\n analysisRange?: AsleepAnalysisRange;\n};\n\nexport type ReanalyzeOptions = {\n /**\n * Re-run analysis only for this window. Omitting it re-analyzes the full\n * session and replaces any range set earlier, including one set at stop.\n */\n analysisRange?: AsleepAnalysisRange;\n};\n\nexport type AsleepGender = \"male\" | \"female\" | \"non_binary\" | \"other\" | \"prefer_not_to_say\";\n\n/**\n * Optional user profile used by the server to personalize analysis. Every\n * field is optional; omitted fields are not sent. `saveUserMetadata()` rejects\n * out-of-range values with `INVALID_ARGUMENT` before any native call.\n */\nexport type AsleepUserMetadata = {\n /** Integer, 1900-2100. */\n birthYear?: number;\n /** Integer, 1-12. */\n birthMonth?: number;\n /** Integer, 1-31. */\n birthDay?: number;\n gender?: AsleepGender;\n /** Centimeters, 1-500. The native SDKs truncate to one decimal place. */\n height?: number;\n /** Kilograms, 1-1000. The native SDKs truncate to one decimal place. */\n weight?: number;\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\n// iOS resolves requestAnalysis with an ack while the real payload arrives via the\n// onAnalysisResult event. Android resolves with the full AsleepAnalysisResult and also\n// fires the event. Consumers reading the promise return value should narrow on `status`.\nexport type AsleepAnalysisAck = {\n status: \"requested\";\n timestamp: number;\n};\n\nexport type SetupStatus = \"idle\" | \"inProgress\" | \"complete\";\n\nexport type TrackingStatus = \"idle\" | \"tracking\" | \"paused\" | \"recoveryRequired\";\n\nexport type AudioSessionOption = \"duckOthers\" | \"allowAirPlay\" | \"allowBluetooth\" | \"allowBluetoothA2DP\";\n\nexport type TrackingConfig = {\n android?: {\n notification?: {\n title?: string;\n text?: string;\n icon?: string;\n };\n };\n ios?: {\n /** Additional AVAudioSession options appended to SDK defaults (mixWithOthers, allowBluetoothA2DP, defaultToSpeaker). Options reset on each startTracking() call. */\n audioSessionOptions?: AudioSessionOption[];\n };\n};\n\n/**\n * Coarse classification of a tracking-runtime failure (onTrackingFailed),\n * derived from the native error code. The library reports the objective fact;\n * the app decides log severity. Recommended mapping:\n * - \"terminal\" / \"recordingDead\" → error (session or recorder is gone)\n * - \"recoveryRequired\" / \"transient\" → warning (tracking is still alive and a\n * defined recovery path exists)\n * - \"unknown\" → error (unclassified; do not assume it is benign)\n */\nexport type AsleepErrorCategory = \"terminal\" | \"recordingDead\" | \"recoveryRequired\" | \"transient\" | \"unknown\";\n\n/**\n * Structured error used everywhere the SDK reports a failure.\n *\n * `code` is a stable machine identifier. Classified tracking failures also\n * carry their category and documented native SDK code, while `cause` retains\n * the original rejection or event payload for observability.\n */\nexport class AsleepError extends Error {\n readonly code: string;\n readonly category?: AsleepErrorCategory;\n readonly sdkCode?: number;\n readonly caseName?: string;\n readonly cause?: unknown;\n\n constructor(\n code: string,\n message: string,\n options?: {\n cause?: unknown;\n category?: AsleepErrorCategory;\n sdkCode?: number;\n caseName?: string;\n },\n ) {\n super(message);\n this.name = \"AsleepError\";\n this.code = code;\n this.category = options?.category;\n this.sdkCode = options?.sdkCode;\n this.caseName = options?.caseName;\n this.cause = options?.cause;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: {\n error: string;\n code: string;\n message?: string;\n /**\n * @deprecated On iOS this is the Swift enum declaration ordinal from\n * NSError bridging, not the documented Asleep error code, and it shifts\n * when the native enum gains cases (iOS SDK 3.3.x moved 38/39 to 59/60).\n * Use `sdkCode`, `caseName`, or `category`.\n */\n errorCode?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n caseName?: string;\n };\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: { userId: string };\n onUserJoinFailed: {\n error?: string;\n errorCode?: number;\n detail?: string;\n caseName?: string;\n code?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onUserDeleted: { userId: string };\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: {\n error: string;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onSetupInProgress: { progress: number };\n onAnalysisResult: AsleepAnalysisResult;\n};\n"]}