react-native-asleep 1.2.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 +263 -225
- package/android/build.gradle +1 -1
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +107 -74
- package/build/Asleep.types.d.ts +18 -4
- package/build/Asleep.types.d.ts.map +1 -1
- package/build/Asleep.types.js.map +1 -1
- package/build/AsleepStore.d.ts.map +1 -1
- package/build/AsleepStore.js +46 -16
- package/build/AsleepStore.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/docs/INTEGRATION.ko.md +395 -0
- package/docs/INTEGRATION.md +442 -0
- package/ios/Asleep.podspec +1 -1
- package/ios/AsleepModule.swift +35 -14
- package/package.json +5 -3
- package/src/Asleep.types.ts +14 -5
- package/src/AsleepStore.ts +69 -16
- package/src/index.ts +1 -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)
|
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;
|
|
@@ -213,7 +225,9 @@ export type AsleepEventType = {
|
|
|
213
225
|
message?: string;
|
|
214
226
|
/**
|
|
215
227
|
* @deprecated On iOS this is the Swift enum declaration ordinal from
|
|
216
|
-
* 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`.
|
|
217
231
|
*/
|
|
218
232
|
errorCode?: number;
|
|
219
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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ClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,0EAA0E;QAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,aAAa,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,kBAAkB,EAAE,SAAS,CAAC;IAC9B,cAAc,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,0EAA0E;QAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,iBAAiB,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,gBAAgB,EAAE,oBAAoB,CAAC;CACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"
|
|
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"]}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EACjB,WAAW,EACX,cAAc,EACd,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA4B7C,MA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AI,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,cAAc,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC5C,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG,aAAa,CAAC;AAKhE,eAAO,MAAM,cAAc,kEAgBxB,CAAC;AAcJ,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,OAAO,EAAE,cAAc,MAAM,EAAE,UAAS,YAAiB,KAAG,WA4ClG,CAAC;AA+FF,eAAO,MAAM,aAAa,EAAE,aAsV3B,CAAC;AAKF,eAAO,MAAM,aAAa,GAAI,UAAU,mBAAmB,KAAG,eAyC7D,CAAC;AAwKF,eAAO,MAAM,yBAAyB,QAAO,CAAC,MAAM,IAAI,CAiCvD,CAAC"}
|
package/build/AsleepStore.js
CHANGED
|
@@ -5,15 +5,19 @@ import AsleepModule from "./AsleepModule";
|
|
|
5
5
|
import { createStore } from "./store/createStore";
|
|
6
6
|
const emitter = new EventEmitter(AsleepModule);
|
|
7
7
|
// Native sessions are already gone for these errors and no close event follows.
|
|
8
|
-
const TERMINAL_TRACKING_ERROR_CODES = new Set(["UPLOAD_TRACKING_TERMINATED"
|
|
9
|
-
// iOS
|
|
10
|
-
const RECORDING_DEAD_ERROR_CODES = new Set(["AUDIO_INITIALIZATION_FAILED"]);
|
|
8
|
+
const TERMINAL_TRACKING_ERROR_CODES = new Set(["UPLOAD_TRACKING_TERMINATED"]);
|
|
9
|
+
// iOS stops recording but leaves the native session open; stopTracking() closes it.
|
|
10
|
+
const RECORDING_DEAD_ERROR_CODES = new Set(["AUDIO_INITIALIZATION_FAILED", "INTERRUPTION_RECOVERY_FAILED"]);
|
|
11
11
|
// iOS 3.2.0 needs an explicit foreground resume after this failure.
|
|
12
12
|
const RECOVERY_REQUIRED_ERROR_CODES = new Set(["CANNOT_ACTIVATE_IN_BACKGROUND"]);
|
|
13
|
-
// Android SDK 3.
|
|
14
|
-
// synchronized with AsleepModule.kt's TERMINAL_TRACKING_ERROR_CODES.
|
|
13
|
+
// The first 13 codes are the Android SDK 3.3.x session-teardown set; keep them
|
|
14
|
+
// synchronized with AsleepModule.kt's TERMINAL_TRACKING_ERROR_CODES. The rest are
|
|
15
|
+
// start failures after which no native session exists: iOS 3.3.2 create HTTP
|
|
16
|
+
// 400/403/429/404 (22400, 11403, 11404) and insufficient storage (11008, both
|
|
17
|
+
// platforms). Android reports create failures as 22000. 11010 (alreadyTracking)
|
|
18
|
+
// is deliberately absent because the existing session survives it.
|
|
15
19
|
const TERMINAL_TRACKING_SDK_CODES = new Set([
|
|
16
|
-
11003, 22000, 22401, 22409, 22422, 22500, 23499, 24000, 24400, 24401, 24403, 24404, 24500,
|
|
20
|
+
11003, 22000, 22401, 22409, 22422, 22500, 23499, 24000, 24400, 24401, 24403, 24404, 24500, 11008, 11403, 11404, 22400,
|
|
17
21
|
]);
|
|
18
22
|
// The native session survives these exhausted upload attempts.
|
|
19
23
|
const TRANSIENT_TRACKING_SDK_CODES = new Set([23000, 23500]);
|
|
@@ -112,6 +116,28 @@ const clearErrorIfUnchanged = (errorBefore) => {
|
|
|
112
116
|
if (current !== null && current === errorBefore)
|
|
113
117
|
useAsleepStore.setState({ error: null });
|
|
114
118
|
};
|
|
119
|
+
// Runtime guard for JS callers and casts that bypass the AsleepCredentials union.
|
|
120
|
+
const resolveCredentials = (config) => {
|
|
121
|
+
const { apiKey, appId, appSecret } = (config ?? {});
|
|
122
|
+
const hasApiKey = apiKey !== undefined;
|
|
123
|
+
const hasToken = appId !== undefined || appSecret !== undefined;
|
|
124
|
+
if (hasApiKey && hasToken) {
|
|
125
|
+
return storeAndThrow(new AsleepError("INVALID_ARGUMENT", "Pass either apiKey or appId/appSecret credentials, not both."));
|
|
126
|
+
}
|
|
127
|
+
if (!hasApiKey && !hasToken) {
|
|
128
|
+
return storeAndThrow(new AsleepError("INVALID_ARGUMENT", "Credentials are required: pass apiKey or appId/appSecret."));
|
|
129
|
+
}
|
|
130
|
+
const isNonEmpty = (value) => typeof value === "string" && value.length > 0;
|
|
131
|
+
if (hasApiKey) {
|
|
132
|
+
if (!isNonEmpty(apiKey))
|
|
133
|
+
return storeAndThrow(new AsleepError("INVALID_ARGUMENT", "apiKey must be a non-empty string."));
|
|
134
|
+
return { apiKey };
|
|
135
|
+
}
|
|
136
|
+
if (!isNonEmpty(appId) || !isNonEmpty(appSecret)) {
|
|
137
|
+
return storeAndThrow(new AsleepError("INVALID_ARGUMENT", "appId and appSecret must both be non-empty strings."));
|
|
138
|
+
}
|
|
139
|
+
return { appId, appSecret };
|
|
140
|
+
};
|
|
115
141
|
const normalizeReport = (report, sessionId) => {
|
|
116
142
|
const converted = convertKeysToCamelCase(report);
|
|
117
143
|
if (converted && !converted.session && converted.sessionId) {
|
|
@@ -137,6 +163,7 @@ const normalizeReport = (report, sessionId) => {
|
|
|
137
163
|
};
|
|
138
164
|
export const asleepActions = {
|
|
139
165
|
setup: async (config) => {
|
|
166
|
+
const credentials = resolveCredentials(config);
|
|
140
167
|
const state = useAsleepStore.getState();
|
|
141
168
|
if (state.setupStatus === "inProgress") {
|
|
142
169
|
storeAndThrow(new AsleepError("OPERATION_IN_PROGRESS", "Setup is already in progress."));
|
|
@@ -148,7 +175,7 @@ export const asleepActions = {
|
|
|
148
175
|
addLog("[setup] Start");
|
|
149
176
|
useAsleepStore.setState({ setupStatus: "inProgress" });
|
|
150
177
|
try {
|
|
151
|
-
await AsleepModule.setup(
|
|
178
|
+
await AsleepModule.setup(credentials.apiKey, credentials.appId, credentials.appSecret, config.baseUrl, config.callbackUrl, config.service, config.enableODA);
|
|
152
179
|
useAsleepStore.setState({
|
|
153
180
|
setupStatus: "complete",
|
|
154
181
|
isODAEnabled: config.enableODA || false,
|
|
@@ -162,6 +189,7 @@ export const asleepActions = {
|
|
|
162
189
|
}
|
|
163
190
|
},
|
|
164
191
|
initAsleepConfig: async (config) => {
|
|
192
|
+
const credentials = resolveCredentials(config);
|
|
165
193
|
const state = useAsleepStore.getState();
|
|
166
194
|
if (state.setupStatus === "inProgress") {
|
|
167
195
|
return storeAndThrow(new AsleepError("OPERATION_IN_PROGRESS", "Setup is already in progress."));
|
|
@@ -173,7 +201,7 @@ export const asleepActions = {
|
|
|
173
201
|
addLog("[initAsleepConfig] Start");
|
|
174
202
|
useAsleepStore.setState({ setupStatus: "inProgress" });
|
|
175
203
|
try {
|
|
176
|
-
await AsleepModule.initAsleepConfig(
|
|
204
|
+
await AsleepModule.initAsleepConfig(credentials.apiKey, credentials.appId, credentials.appSecret, config.userId, config.baseUrl, config.callbackUrl);
|
|
177
205
|
useAsleepStore.setState({ setupStatus: "complete", isInitialized: true });
|
|
178
206
|
clearErrorIfUnchanged(errorBefore);
|
|
179
207
|
addLog("[initAsleepConfig] Success");
|
|
@@ -547,8 +575,9 @@ const transitionForEvent = (eventType, payload, state) => {
|
|
|
547
575
|
if (terminal) {
|
|
548
576
|
return {
|
|
549
577
|
partial: {
|
|
550
|
-
// iOS
|
|
551
|
-
//
|
|
578
|
+
// iOS closeSessionSilently (upload 4xx) does not emit didClose, and
|
|
579
|
+
// start failures never create a session, so this branch must clear
|
|
580
|
+
// the projected session state itself.
|
|
552
581
|
error,
|
|
553
582
|
trackingStatus: "idle",
|
|
554
583
|
isAnalyzing: false,
|
|
@@ -561,8 +590,8 @@ const transitionForEvent = (eventType, payload, state) => {
|
|
|
561
590
|
if (recordingDead) {
|
|
562
591
|
return {
|
|
563
592
|
partial: {
|
|
564
|
-
// iOS
|
|
565
|
-
//
|
|
593
|
+
// iOS audioInitializationFailed and interruptionRecoveryFailed stop
|
|
594
|
+
// the recorder but keep the native session open (didClose=false).
|
|
566
595
|
error,
|
|
567
596
|
trackingStatus: "idle",
|
|
568
597
|
isAnalyzing: false,
|
|
@@ -574,8 +603,8 @@ const transitionForEvent = (eventType, payload, state) => {
|
|
|
574
603
|
}
|
|
575
604
|
if (recoveryRequired) {
|
|
576
605
|
return {
|
|
577
|
-
// iOS
|
|
578
|
-
//
|
|
606
|
+
// iOS cannotActivateInBackground keeps the session alive. 3.3.x also
|
|
607
|
+
// retries on foreground; only a later upload proves recovery.
|
|
579
608
|
partial: { error, trackingStatus: "recoveryRequired" },
|
|
580
609
|
log: `[onTrackingError] error: ${error.message}`,
|
|
581
610
|
};
|
|
@@ -588,8 +617,9 @@ const transitionForEvent = (eventType, payload, state) => {
|
|
|
588
617
|
return {
|
|
589
618
|
partial: {
|
|
590
619
|
error: null,
|
|
591
|
-
// iOS 3.2.1 can emit didResume twice
|
|
592
|
-
//
|
|
620
|
+
// iOS 3.2.1-3.3.0 can emit didResume twice, and recovery paths can
|
|
621
|
+
// resume without a prior pause. Always clear the error, but mutate
|
|
622
|
+
// the paused state only for the first event.
|
|
593
623
|
...(state.trackingStatus === "paused" ? { trackingStatus: "tracking" } : {}),
|
|
594
624
|
},
|
|
595
625
|
log: state.trackingStatus === "paused"
|