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.
@@ -1,12 +1,19 @@
1
- export type AsleepConfig = {
2
- apiKey: string;
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 =
7
+ | { apiKey: string; appId?: never; appSecret?: never }
8
+ | { appId: string; appSecret: string; apiKey?: never };
9
+
10
+ export type AsleepConfig = AsleepCredentials & {
3
11
  userId?: string;
4
12
  baseUrl?: string;
5
13
  callbackUrl?: string;
6
14
  };
7
15
 
8
- export type AsleepSetupConfig = {
9
- apiKey: string;
16
+ export type AsleepSetupConfig = AsleepCredentials & {
10
17
  baseUrl?: string;
11
18
  callbackUrl?: string;
12
19
  service?: string;
@@ -167,6 +174,10 @@ export type AsleepAnalysisAck = {
167
174
  timestamp: number;
168
175
  };
169
176
 
177
+ export type SetupStatus = "idle" | "inProgress" | "complete";
178
+
179
+ export type TrackingStatus = "idle" | "tracking" | "paused" | "recoveryRequired";
180
+
170
181
  export type AudioSessionOption = "duckOthers" | "allowAirPlay" | "allowBluetooth" | "allowBluetoothA2DP";
171
182
 
172
183
  export type TrackingConfig = {
@@ -195,23 +206,39 @@ export type TrackingConfig = {
195
206
  export type AsleepErrorCategory = "terminal" | "recordingDead" | "recoveryRequired" | "transient" | "unknown";
196
207
 
197
208
  /**
198
- * Structured view of the last onTrackingFailed event, exposed as
199
- * useAsleep().errorInfo alongside the legacy `error` JSON string. Cleared to
200
- * null wherever `error` is cleared.
209
+ * Structured error used everywhere the SDK reports a failure.
210
+ *
211
+ * `code` is a stable machine identifier. Classified tracking failures also
212
+ * carry their category and documented native SDK code, while `cause` retains
213
+ * the original rejection or event payload for observability.
201
214
  */
202
- export type AsleepErrorInfo = {
203
- /** Stable string code from the native module (e.g. "UPLOAD_TRACKING_TERMINATED"). */
204
- code: string;
205
- category: AsleepErrorCategory;
206
- /**
207
- * Numeric code documented by the native Asleep SDKs (range 10000-34999):
208
- * iOS `AsleepError.errorCode.code` (v3.2.0+), Android listener `errorCode`.
209
- */
210
- sdkCode?: number;
211
- message?: string;
212
- /** iOS: Swift enum case description for cases without an explicit code mapping. */
213
- caseName?: string;
214
- };
215
+ export class AsleepError extends Error {
216
+ readonly code: string;
217
+ readonly category?: AsleepErrorCategory;
218
+ readonly sdkCode?: number;
219
+ readonly caseName?: string;
220
+ readonly cause?: unknown;
221
+
222
+ constructor(
223
+ code: string,
224
+ message: string,
225
+ options?: {
226
+ cause?: unknown;
227
+ category?: AsleepErrorCategory;
228
+ sdkCode?: number;
229
+ caseName?: string;
230
+ },
231
+ ) {
232
+ super(message);
233
+ this.name = "AsleepError";
234
+ this.code = code;
235
+ this.category = options?.category;
236
+ this.sdkCode = options?.sdkCode;
237
+ this.caseName = options?.caseName;
238
+ this.cause = options?.cause;
239
+ Object.setPrototypeOf(this, new.target.prototype);
240
+ }
241
+ }
215
242
 
216
243
  export type AsleepEventType = {
217
244
  onTrackingCreated: { sessionId?: string };
@@ -223,7 +250,9 @@ export type AsleepEventType = {
223
250
  message?: string;
224
251
  /**
225
252
  * @deprecated On iOS this is the Swift enum declaration ordinal from
226
- * NSError bridging, not the documented Asleep error code. Use `sdkCode`.
253
+ * NSError bridging, not the documented Asleep error code, and it shifts
254
+ * when the native enum gains cases (iOS SDK 3.3.x moved 38/39 to 59/60).
255
+ * Use `sdkCode`, `caseName`, or `category`.
227
256
  */
228
257
  errorCode?: number;
229
258
  /** Numeric code documented by the native Asleep SDKs (both platforms). */