react-native-asleep 1.1.0 → 2.0.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.
- package/README.ko.md +374 -0
- package/README.md +298 -143
- package/android/build.gradle +1 -1
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +127 -84
- package/build/Asleep.types.d.ts +38 -20
- package/build/Asleep.types.d.ts.map +1 -1
- package/build/Asleep.types.js +24 -1
- package/build/Asleep.types.js.map +1 -1
- package/build/AsleepStore.d.ts +44 -43
- package/build/AsleepStore.d.ts.map +1 -1
- package/build/AsleepStore.js +539 -672
- package/build/AsleepStore.js.map +1 -1
- package/build/index.d.ts +11 -113
- package/build/index.d.ts.map +1 -1
- package/build/index.js +18 -184
- package/build/index.js.map +1 -1
- package/build/store/createStore.d.ts +14 -0
- package/build/store/createStore.d.ts.map +1 -0
- package/build/store/createStore.js +63 -0
- package/build/store/createStore.js.map +1 -0
- package/docs/INTEGRATION.ko.md +395 -0
- package/docs/INTEGRATION.md +442 -0
- package/ios/Asleep.podspec +1 -1
- package/ios/AsleepModule.swift +39 -14
- package/package.json +7 -7
- package/src/Asleep.types.ts +50 -21
- package/src/AsleepStore.ts +777 -893
- package/src/index.ts +37 -292
- package/src/store/createStore.ts +84 -0
|
@@ -58,7 +58,9 @@ class AsleepModule : Module() {
|
|
|
58
58
|
|
|
59
59
|
// Added variables to replace PreferenceHelper
|
|
60
60
|
private var isTracking = false
|
|
61
|
-
|
|
61
|
+
// Identity of the credentials used for the last initAsleepConfig: "apiKey:<key>" or
|
|
62
|
+
// "appId:<id>". Keys the reconnect short-circuit for both auth modes.
|
|
63
|
+
private var savedCredentialId: String? = null
|
|
62
64
|
private var savedUserId: String? = null
|
|
63
65
|
|
|
64
66
|
val trackingState: LiveData<TrackingState> get() = _trackingState
|
|
@@ -68,11 +70,11 @@ class AsleepModule : Module() {
|
|
|
68
70
|
companion object {
|
|
69
71
|
public const val MICROPHONE_PERMISSION_REQUEST_CODE = 1001
|
|
70
72
|
|
|
71
|
-
// Error codes for which Android SDK 3.2.x AsleepCore.onErrorCodeReceived tears
|
|
73
|
+
// Error codes for which Android SDK 3.2.x-3.3.1 AsleepCore.onErrorCodeReceived tears
|
|
72
74
|
// the session down and fires BOTH onFail and onFinish (dual dispatch). Only
|
|
73
75
|
// these may suppress the follow-up onFinish; for any other code the native
|
|
74
76
|
// 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.
|
|
77
|
+
// Must stay in sync with the first 13 TERMINAL_TRACKING_SDK_CODES in src/AsleepStore.ts.
|
|
76
78
|
private val TERMINAL_TRACKING_ERROR_CODES = setOf(
|
|
77
79
|
11003, // ERR_AUDIO
|
|
78
80
|
22000, 22401, 22409, 22422, 22500, // ERR_CREATE_*
|
|
@@ -146,100 +148,131 @@ class AsleepModule : Module() {
|
|
|
146
148
|
"onUserJoined", "onUserJoinFailed", "onUserDeleted", "onDebugLog",
|
|
147
149
|
"onSetupDidComplete", "onSetupDidFail", "onSetupInProgress", "onAnalysisResult")
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
// JS validates that exactly one credential form is present: apiKey, or appId + appSecret.
|
|
152
|
+
AsyncFunction("setup") { apiKey: String?, appId: String?, appSecret: String?, baseUrl: String?, callbackUrl: String?, service: String?, enableODA: Boolean?, promise: Promise ->
|
|
150
153
|
try {
|
|
151
154
|
val context = appContext.reactContext!!.applicationContext as Application
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
}
|
|
155
|
+
val setupListener = object : Asleep.AsleepSetupListener {
|
|
156
|
+
override fun onComplete() {
|
|
157
|
+
sendEvent("onSetupDidComplete", emptyMap<String, Any>())
|
|
158
|
+
promise.resolve("Setup completed")
|
|
176
159
|
}
|
|
177
|
-
|
|
160
|
+
|
|
161
|
+
override fun onProgress(progress: Int) {
|
|
162
|
+
sendEvent("onSetupInProgress", mapOf("progress" to progress))
|
|
163
|
+
sendEvent("onDebugLog", mapOf("message" to "Setup progress: $progress%"))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override fun onFail(errorCode: Int, detail: String) {
|
|
167
|
+
sendEvent("onSetupDidFail", mapOf("error" to detail, "sdkCode" to errorCode))
|
|
168
|
+
sendEvent("onDebugLog", mapOf("message" to "Setup failed: $errorCode - $detail"))
|
|
169
|
+
promise.reject("SETUP_FAILED", "Setup failed: $errorCode - $detail", null)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (appId != null && appSecret != null) {
|
|
174
|
+
Asleep.setup(
|
|
175
|
+
context = context,
|
|
176
|
+
appId = appId,
|
|
177
|
+
appSecret = appSecret,
|
|
178
|
+
baseUrl = baseUrl,
|
|
179
|
+
callbackUrl = callbackUrl,
|
|
180
|
+
service = service ?: "SleepTracking",
|
|
181
|
+
enableODA = enableODA,
|
|
182
|
+
asleepSetupListener = setupListener
|
|
183
|
+
)
|
|
184
|
+
} else {
|
|
185
|
+
Asleep.setup(
|
|
186
|
+
context = context,
|
|
187
|
+
apiKey = apiKey ?: "",
|
|
188
|
+
baseUrl = baseUrl,
|
|
189
|
+
callbackUrl = callbackUrl,
|
|
190
|
+
service = service ?: "SleepTracking",
|
|
191
|
+
enableODA = enableODA,
|
|
192
|
+
asleepSetupListener = setupListener
|
|
193
|
+
)
|
|
194
|
+
}
|
|
178
195
|
} catch (e: Exception) {
|
|
179
196
|
sendEvent("onDebugLog", mapOf("message" to "Setup failed: ${e.message}"))
|
|
180
197
|
promise.reject("UNEXPECTED_ERROR", "Setup failed: ${e.message}", e)
|
|
181
198
|
}
|
|
182
199
|
}
|
|
183
200
|
|
|
184
|
-
AsyncFunction("initAsleepConfig") { apiKey: String
|
|
201
|
+
AsyncFunction("initAsleepConfig") { apiKey: String?, appId: String?, appSecret: String?, userId: String?, baseUrl: String?, callbackUrl: String?, promise: Promise ->
|
|
185
202
|
try {
|
|
186
203
|
val context = appContext.reactContext!!.applicationContext as Application
|
|
187
|
-
|
|
188
|
-
if (
|
|
204
|
+
val useToken = appId != null && appSecret != null
|
|
205
|
+
val credentialId = if (useToken) "appId:$appId" else "apiKey:$apiKey"
|
|
206
|
+
|
|
207
|
+
if (isTracking && savedCredentialId == credentialId && savedUserId == userId) {
|
|
189
208
|
promise.resolve(mapOf("userId" to (savedUserId ?: "")))
|
|
190
209
|
sendEvent("onDebugLog", mapOf("message" to "Service reconnected"))
|
|
191
210
|
return@AsyncFunction
|
|
192
211
|
}
|
|
193
212
|
|
|
194
|
-
// Store
|
|
195
|
-
|
|
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
|
+
// Store the credential identity in memory instead of preferences
|
|
214
|
+
savedCredentialId = credentialId
|
|
213
215
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
val configListener = object : Asleep.AsleepConfigListener {
|
|
217
|
+
override fun onSuccess(userId: String?, asleepConfig: AsleepConfig?) {
|
|
218
|
+
if (userId != null) {
|
|
219
|
+
sendEvent("onDebugLog", mapOf("message" to "UserId is not null"))
|
|
220
|
+
// Store userId in memory instead of preferences
|
|
221
|
+
savedUserId = userId
|
|
222
|
+
sendEvent("onUserJoined", mapOf("userId" to userId))
|
|
223
|
+
}
|
|
224
|
+
_asleepConfig = asleepConfig
|
|
222
225
|
|
|
226
|
+
if (_asleepConfig != null) {
|
|
223
227
|
sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
}
|
|
228
|
+
_reportManager = Asleep.createReports(_asleepConfig)
|
|
229
|
+
} else {
|
|
230
|
+
sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is null"))
|
|
231
|
+
promise.reject("CONFIG_ERROR", "AsleepConfig is null", null)
|
|
232
|
+
return
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
235
|
+
sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
|
|
236
|
+
|
|
237
|
+
// Return userId in the response instead of just a success message
|
|
238
|
+
promise.resolve(mapOf("userId" to (userId ?: "")))
|
|
239
|
+
try {
|
|
240
|
+
sendEvent("onDebugLog", mapOf("message" to "Initialization successful with userId: $userId"))
|
|
241
|
+
} catch (e: Exception) {
|
|
242
|
+
sendEvent("onDebugLog", mapOf("message" to "Error sending debug log: ${e.message}"))
|
|
243
|
+
println("Error sending debug log: ${e.message}")
|
|
239
244
|
}
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
|
|
246
|
+
|
|
247
|
+
override fun onFail(errorCode: Int, detail: String) {
|
|
248
|
+
sendEvent("onDebugLog", mapOf("message" to "Initialization failed: $errorCode - $detail"))
|
|
249
|
+
sendEvent("onUserJoinFailed", mapOf("errorCode" to errorCode, "detail" to detail, "sdkCode" to errorCode))
|
|
250
|
+
promise.reject("INITIALIZATION_FAILED", "Initialization failed: $errorCode - $detail", null)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (useToken) {
|
|
255
|
+
Asleep.initAsleepConfig(
|
|
256
|
+
context = context,
|
|
257
|
+
appId = appId,
|
|
258
|
+
appSecret = appSecret,
|
|
259
|
+
userId = userId,
|
|
260
|
+
baseUrl = baseUrl,
|
|
261
|
+
callbackUrl = callbackUrl,
|
|
262
|
+
service = "SleepTracking",
|
|
263
|
+
asleepConfigListener = configListener
|
|
264
|
+
)
|
|
265
|
+
} else {
|
|
266
|
+
Asleep.initAsleepConfig(
|
|
267
|
+
context = context,
|
|
268
|
+
apiKey = apiKey,
|
|
269
|
+
userId = userId,
|
|
270
|
+
baseUrl = baseUrl,
|
|
271
|
+
callbackUrl = callbackUrl,
|
|
272
|
+
service = "SleepTracking",
|
|
273
|
+
asleepConfigListener = configListener
|
|
274
|
+
)
|
|
275
|
+
}
|
|
243
276
|
} catch (e: Exception) {
|
|
244
277
|
sendEvent("onDebugLog", mapOf("message" to "Initialization failed: ${e.message}"))
|
|
245
278
|
promise.reject("UNEXPECTED_ERROR", "Initialization failed: ${e.message}", e)
|
|
@@ -282,16 +315,7 @@ class AsleepModule : Module() {
|
|
|
282
315
|
|
|
283
316
|
AsyncFunction("startTracking") { config: Map<String, Any>?, promise: Promise ->
|
|
284
317
|
try {
|
|
285
|
-
|
|
286
|
-
// FOREGROUND_SERVICE_MICROPHONE was introduced in API 34 (UPSIDE_DOWN_CAKE).
|
|
287
|
-
// Gating on TIRAMISU (API 33) would false-deny on Android 13 where the permission
|
|
288
|
-
// doesn't exist yet.
|
|
289
|
-
val fgsPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
290
|
-
ContextCompat.checkSelfPermission(appContext.reactContext!!, Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
|
|
291
|
-
} else {
|
|
292
|
-
PackageManager.PERMISSION_GRANTED
|
|
293
|
-
}
|
|
294
|
-
if (audioPermission != PackageManager.PERMISSION_GRANTED || fgsPermission != PackageManager.PERMISSION_GRANTED) {
|
|
318
|
+
if (!hasRequiredPermissions()) {
|
|
295
319
|
// beginSleepTracking would crash with SecurityException at
|
|
296
320
|
// startForeground(type=microphone) on API 34+. Reject so JS requests via
|
|
297
321
|
// requestRequiredPermissions() and retries.
|
|
@@ -466,6 +490,10 @@ class AsleepModule : Module() {
|
|
|
466
490
|
}
|
|
467
491
|
}
|
|
468
492
|
|
|
493
|
+
AsyncFunction("hasRequiredPermissions") { promise: Promise ->
|
|
494
|
+
promise.resolve(hasRequiredPermissions())
|
|
495
|
+
}
|
|
496
|
+
|
|
469
497
|
// Deprecated method for backward compatibility
|
|
470
498
|
AsyncFunction("requestMicrophonePermission") { promise: Promise ->
|
|
471
499
|
// Delegate to the new method
|
|
@@ -659,6 +687,21 @@ class AsleepModule : Module() {
|
|
|
659
687
|
return gson.fromJson(json, object : TypeToken<O>() {}.type)
|
|
660
688
|
}
|
|
661
689
|
|
|
690
|
+
private fun hasRequiredPermissions(): Boolean {
|
|
691
|
+
val context = appContext.reactContext!!
|
|
692
|
+
val audioPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO)
|
|
693
|
+
// FOREGROUND_SERVICE_MICROPHONE was introduced in API 34 (UPSIDE_DOWN_CAKE).
|
|
694
|
+
// Gating on TIRAMISU (API 33) would false-deny on Android 13 where the permission
|
|
695
|
+
// doesn't exist yet.
|
|
696
|
+
val fgsPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
697
|
+
ContextCompat.checkSelfPermission(context, Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
|
|
698
|
+
} else {
|
|
699
|
+
PackageManager.PERMISSION_GRANTED
|
|
700
|
+
}
|
|
701
|
+
return audioPermission == PackageManager.PERMISSION_GRANTED &&
|
|
702
|
+
fgsPermission == PackageManager.PERMISSION_GRANTED
|
|
703
|
+
}
|
|
704
|
+
|
|
662
705
|
private suspend fun requestMicrophonePermission(): Boolean = suspendCancellableCoroutine { cont ->
|
|
663
706
|
val activity = appContext.currentActivity
|
|
664
707
|
if (activity != null) {
|
package/build/Asleep.types.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
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 AsleepSetupConfig = AsleepCredentials & {
|
|
9
21
|
baseUrl?: string;
|
|
10
22
|
callbackUrl?: string;
|
|
11
23
|
service?: string;
|
|
@@ -151,6 +163,8 @@ export type AsleepAnalysisAck = {
|
|
|
151
163
|
status: "requested";
|
|
152
164
|
timestamp: number;
|
|
153
165
|
};
|
|
166
|
+
export type SetupStatus = "idle" | "inProgress" | "complete";
|
|
167
|
+
export type TrackingStatus = "idle" | "tracking" | "paused" | "recoveryRequired";
|
|
154
168
|
export type AudioSessionOption = "duckOthers" | "allowAirPlay" | "allowBluetooth" | "allowBluetoothA2DP";
|
|
155
169
|
export type TrackingConfig = {
|
|
156
170
|
android?: {
|
|
@@ -176,23 +190,25 @@ export type TrackingConfig = {
|
|
|
176
190
|
*/
|
|
177
191
|
export type AsleepErrorCategory = "terminal" | "recordingDead" | "recoveryRequired" | "transient" | "unknown";
|
|
178
192
|
/**
|
|
179
|
-
* Structured
|
|
180
|
-
*
|
|
181
|
-
*
|
|
193
|
+
* Structured error used everywhere the SDK reports a failure.
|
|
194
|
+
*
|
|
195
|
+
* `code` is a stable machine identifier. Classified tracking failures also
|
|
196
|
+
* carry their category and documented native SDK code, while `cause` retains
|
|
197
|
+
* the original rejection or event payload for observability.
|
|
182
198
|
*/
|
|
183
|
-
export
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
199
|
+
export declare class AsleepError extends Error {
|
|
200
|
+
readonly code: string;
|
|
201
|
+
readonly category?: AsleepErrorCategory;
|
|
202
|
+
readonly sdkCode?: number;
|
|
203
|
+
readonly caseName?: string;
|
|
204
|
+
readonly cause?: unknown;
|
|
205
|
+
constructor(code: string, message: string, options?: {
|
|
206
|
+
cause?: unknown;
|
|
207
|
+
category?: AsleepErrorCategory;
|
|
208
|
+
sdkCode?: number;
|
|
209
|
+
caseName?: string;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
196
212
|
export type AsleepEventType = {
|
|
197
213
|
onTrackingCreated: {
|
|
198
214
|
sessionId?: string;
|
|
@@ -209,7 +225,9 @@ export type AsleepEventType = {
|
|
|
209
225
|
message?: string;
|
|
210
226
|
/**
|
|
211
227
|
* @deprecated On iOS this is the Swift enum declaration ordinal from
|
|
212
|
-
* NSError bridging, not the documented Asleep error code
|
|
228
|
+
* NSError bridging, not the documented Asleep error code, and it shifts
|
|
229
|
+
* when the native enum gains cases (iOS SDK 3.3.x moved 38/39 to 59/60).
|
|
230
|
+
* Use `sdkCode`, `caseName`, or `category`.
|
|
213
231
|
*/
|
|
214
232
|
errorCode?: number;
|
|
215
233
|
/** 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,
|
|
1
|
+
{"version":3,"file":"Asleep.types.d.ts","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,KAAK,CAAA;CAAE,GACpD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG;IAC7C,MAAM,CAAC,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Q,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,gBAAgB,EAAE,oBAAoB,CAAC;CACxC,CAAC"}
|
package/build/Asleep.types.js
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Structured error used everywhere the SDK reports a failure.
|
|
3
|
+
*
|
|
4
|
+
* `code` is a stable machine identifier. Classified tracking failures also
|
|
5
|
+
* carry their category and documented native SDK code, while `cause` retains
|
|
6
|
+
* the original rejection or event payload for observability.
|
|
7
|
+
*/
|
|
8
|
+
export class AsleepError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
category;
|
|
11
|
+
sdkCode;
|
|
12
|
+
caseName;
|
|
13
|
+
cause;
|
|
14
|
+
constructor(code, message, options) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "AsleepError";
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.category = options?.category;
|
|
19
|
+
this.sdkCode = options?.sdkCode;
|
|
20
|
+
this.caseName = options?.caseName;
|
|
21
|
+
this.cause = options?.cause;
|
|
22
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
2
25
|
//# sourceMappingURL=Asleep.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"AA+MA;;;;;;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 AsleepSetupConfig = AsleepCredentials & {\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, 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"]}
|
package/build/AsleepStore.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
isRecoveryRequired: boolean;
|
|
7
|
-
error: string | null;
|
|
8
|
-
errorInfo: AsleepErrorInfo | null;
|
|
9
|
-
userId: string | null;
|
|
1
|
+
import type { AsleepAnalysisAck, AsleepAnalysisResult, AsleepAverageReport, AsleepConfig, AsleepErrorCategory, AsleepEventType, AsleepReport, AsleepSession, AsleepSetupConfig, SetupStatus, TrackingConfig, TrackingStatus } from "./Asleep.types";
|
|
2
|
+
import { AsleepError } from "./Asleep.types";
|
|
3
|
+
export interface InternalAsleepState {
|
|
4
|
+
setupStatus: SetupStatus;
|
|
5
|
+
trackingStatus: TrackingStatus;
|
|
10
6
|
sessionId: string | null;
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
userId: string | null;
|
|
8
|
+
error: AsleepError | null;
|
|
13
9
|
analysisResult: AsleepAnalysisResult | null;
|
|
14
|
-
isODAEnabled: boolean;
|
|
15
10
|
isAnalyzing: boolean;
|
|
11
|
+
didClose: boolean;
|
|
12
|
+
isODAEnabled: boolean;
|
|
16
13
|
trackingStartTime: Date | null;
|
|
17
14
|
isInitialized: boolean;
|
|
18
|
-
isSetupInProgress: boolean;
|
|
19
|
-
isSetupComplete: boolean;
|
|
20
15
|
hasCheckedStatus: boolean;
|
|
21
16
|
hasCheckedBatteryOptimization: boolean;
|
|
17
|
+
showDebugLog: boolean;
|
|
18
|
+
log: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AsleepActions {
|
|
22
21
|
setup: (config: AsleepSetupConfig) => Promise<void>;
|
|
23
22
|
initAsleepConfig: (config: AsleepConfig) => Promise<void>;
|
|
24
23
|
checkAndRestoreTracking: () => Promise<{
|
|
@@ -33,42 +32,44 @@ export interface AsleepState {
|
|
|
33
32
|
startTracking: (config?: TrackingConfig) => Promise<void>;
|
|
34
33
|
stopTracking: () => Promise<void>;
|
|
35
34
|
resumeTracking: () => Promise<void>;
|
|
36
|
-
getReport: (sessionId: string) => Promise<AsleepReport
|
|
35
|
+
getReport: (sessionId: string) => Promise<AsleepReport>;
|
|
37
36
|
getReportList: (fromDate: string, toDate: string) => Promise<AsleepSession[]>;
|
|
38
|
-
getAverageReport: (fromDate: string, toDate: string) => Promise<AsleepAverageReport
|
|
37
|
+
getAverageReport: (fromDate: string, toDate: string) => Promise<AsleepAverageReport>;
|
|
39
38
|
deleteSession: (sessionId: string) => Promise<void>;
|
|
40
|
-
|
|
39
|
+
requestAnalysis: () => Promise<AsleepAnalysisResult | AsleepAnalysisAck>;
|
|
40
|
+
hasRequiredPermissions: () => Promise<boolean>;
|
|
41
41
|
requestRequiredPermissions: () => Promise<boolean>;
|
|
42
42
|
setCustomNotification: (title: string, text: string) => Promise<void>;
|
|
43
43
|
enableLog: (print: boolean) => void;
|
|
44
44
|
clearError: () => void;
|
|
45
|
-
requestAnalysis: () => Promise<AsleepAnalysisResult | AsleepAnalysisAck | null>;
|
|
46
45
|
addEventListener: <K extends keyof AsleepEventType>(eventType: K, listener: (data: AsleepEventType[K]) => void) => () => void;
|
|
47
|
-
getTrackingDurationMinutes: () => number;
|
|
48
|
-
setError: (error: string | null) => void;
|
|
49
|
-
setUserId: (userId: string | null) => void;
|
|
50
|
-
setSessionId: (sessionId: string | null) => void;
|
|
51
|
-
setIsTracking: (isTracking: boolean) => void;
|
|
52
|
-
setIsTrackingPaused: (isTrackingPaused: boolean) => void;
|
|
53
|
-
setDidClose: (didClose: boolean) => void;
|
|
54
|
-
setAnalysisResult: (result: AsleepAnalysisResult | null) => void;
|
|
55
|
-
setIsAnalyzing: (isAnalyzing: boolean) => void;
|
|
56
|
-
setTrackingStartTime: (time: Date | null) => void;
|
|
57
|
-
setIsInitialized: (initialized: boolean) => void;
|
|
58
|
-
setIsSetupInProgress: (inProgress: boolean) => void;
|
|
59
|
-
setIsSetupComplete: (complete: boolean) => void;
|
|
60
|
-
setHasCheckedStatus: (checked: boolean) => void;
|
|
61
|
-
setHasCheckedBatteryOptimization: (checked: boolean) => void;
|
|
62
|
-
addLog: (log: string) => void;
|
|
63
46
|
}
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
export interface AsleepPublicState {
|
|
48
|
+
status: TrackingStatus;
|
|
49
|
+
isTracking: boolean;
|
|
50
|
+
isTrackingPaused: boolean;
|
|
51
|
+
isRecoveryRequired: boolean;
|
|
52
|
+
isSetupInProgress: boolean;
|
|
53
|
+
isSetupComplete: boolean;
|
|
54
|
+
sessionId: string | null;
|
|
55
|
+
userId: string | null;
|
|
56
|
+
error: AsleepError | null;
|
|
57
|
+
analysisResult: AsleepAnalysisResult | null;
|
|
58
|
+
isAnalyzing: boolean;
|
|
59
|
+
didClose: boolean;
|
|
60
|
+
isODAEnabled: boolean;
|
|
61
|
+
log: string;
|
|
62
|
+
}
|
|
63
|
+
export type AsleepPublicApi = AsleepPublicState & AsleepActions;
|
|
64
|
+
export declare const useAsleepStore: import("./store/createStore").UseBoundStore<InternalAsleepState>;
|
|
65
|
+
type ErrorOptions = {
|
|
66
|
+
category?: AsleepErrorCategory;
|
|
67
|
+
sdkCode?: number;
|
|
68
|
+
caseName?: string;
|
|
69
|
+
};
|
|
70
|
+
export declare const normalizeError: (source: unknown, fallbackCode: string, options?: ErrorOptions) => AsleepError;
|
|
71
|
+
export declare const asleepActions: AsleepActions;
|
|
72
|
+
export declare const toPublicState: (internal: InternalAsleepState) => AsleepPublicApi;
|
|
73
73
|
export declare const initializeAsleepListeners: () => (() => void);
|
|
74
|
+
export {};
|
|
74
75
|
//# sourceMappingURL=AsleepStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EAEZ,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EAC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