react-native-asleep 1.0.15 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -14
- package/android/build.gradle +1 -1
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +52 -64
- package/build/Asleep.types.d.ts +1 -1
- package/build/Asleep.types.d.ts.map +1 -1
- package/build/Asleep.types.js.map +1 -1
- package/build/AsleepStore.d.ts +1 -1
- package/build/AsleepStore.d.ts.map +1 -1
- package/build/AsleepStore.js +159 -86
- package/build/AsleepStore.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/ios/AsleepModule.swift +4 -0
- package/package.json +30 -16
- package/src/Asleep.types.ts +4 -8
- package/src/AsleepStore.ts +175 -154
- package/src/index.ts +15 -41
- package/.eslintrc.js +0 -5
- package/.releaserc.js +0 -58
- package/AGENTS.md +0 -107
- package/docs/PUBLISHING.md +0 -36
- package/tsconfig.json +0 -9
- /package/{License.md → LICENSE.md} +0 -0
package/src/index.ts
CHANGED
|
@@ -22,13 +22,7 @@ class Asleep {
|
|
|
22
22
|
|
|
23
23
|
setup = async (config: AsleepSetupConfig): Promise<void> => {
|
|
24
24
|
try {
|
|
25
|
-
await AsleepModule.setup(
|
|
26
|
-
config.apiKey,
|
|
27
|
-
config.baseUrl,
|
|
28
|
-
config.callbackUrl,
|
|
29
|
-
config.service,
|
|
30
|
-
config.enableODA
|
|
31
|
-
);
|
|
25
|
+
await AsleepModule.setup(config.apiKey, config.baseUrl, config.callbackUrl, config.service, config.enableODA);
|
|
32
26
|
} catch (error) {
|
|
33
27
|
console.error("setup error:", error);
|
|
34
28
|
throw error;
|
|
@@ -41,7 +35,7 @@ class Asleep {
|
|
|
41
35
|
config.apiKey,
|
|
42
36
|
config.userId,
|
|
43
37
|
config.baseUrl,
|
|
44
|
-
config.callbackUrl
|
|
38
|
+
config.callbackUrl,
|
|
45
39
|
);
|
|
46
40
|
return result;
|
|
47
41
|
} catch (error) {
|
|
@@ -73,10 +67,7 @@ class Asleep {
|
|
|
73
67
|
return this.convertKeysToCamelCase(report);
|
|
74
68
|
};
|
|
75
69
|
|
|
76
|
-
getReportList = async (
|
|
77
|
-
fromDate: string,
|
|
78
|
-
toDate: string
|
|
79
|
-
): Promise<AsleepSession[]> => {
|
|
70
|
+
getReportList = async (fromDate: string, toDate: string): Promise<AsleepSession[]> => {
|
|
80
71
|
const reportList = await AsleepModule.getReportList(fromDate, toDate);
|
|
81
72
|
return reportList.map((session: any) => {
|
|
82
73
|
const converted = this.convertKeysToCamelCase(session);
|
|
@@ -98,10 +89,7 @@ class Asleep {
|
|
|
98
89
|
return AsleepModule.deleteSession(sessionId);
|
|
99
90
|
};
|
|
100
91
|
|
|
101
|
-
getAverageReport = async (
|
|
102
|
-
fromDate: string,
|
|
103
|
-
toDate: string
|
|
104
|
-
): Promise<AsleepAverageReport> => {
|
|
92
|
+
getAverageReport = async (fromDate: string, toDate: string): Promise<AsleepAverageReport> => {
|
|
105
93
|
const averageReport = await AsleepModule.getAverageReport(fromDate, toDate);
|
|
106
94
|
return this.convertKeysToCamelCase(averageReport);
|
|
107
95
|
};
|
|
@@ -111,7 +99,7 @@ class Asleep {
|
|
|
111
99
|
*/
|
|
112
100
|
requestMicrophonePermission = async (): Promise<boolean> => {
|
|
113
101
|
console.warn(
|
|
114
|
-
|
|
102
|
+
"[AsleepSDK] requestMicrophonePermission is deprecated. Please use requestRequiredPermissions instead.",
|
|
115
103
|
);
|
|
116
104
|
return this.requestRequiredPermissions();
|
|
117
105
|
};
|
|
@@ -120,10 +108,7 @@ class Asleep {
|
|
|
120
108
|
return AsleepModule.requestRequiredPermissions();
|
|
121
109
|
};
|
|
122
110
|
|
|
123
|
-
setCustomNotification = async (
|
|
124
|
-
title: string,
|
|
125
|
-
text: string
|
|
126
|
-
): Promise<void> => {
|
|
111
|
+
setCustomNotification = async (title: string, text: string): Promise<void> => {
|
|
127
112
|
if (Platform.OS === "android") {
|
|
128
113
|
return AsleepModule.setCustomNotification(title, text);
|
|
129
114
|
} else {
|
|
@@ -144,10 +129,7 @@ class Asleep {
|
|
|
144
129
|
return obj;
|
|
145
130
|
};
|
|
146
131
|
|
|
147
|
-
addEventListener<K extends keyof AsleepEventType>(
|
|
148
|
-
eventType: K,
|
|
149
|
-
listener: (data: AsleepEventType[K]) => void
|
|
150
|
-
) {
|
|
132
|
+
addEventListener<K extends keyof AsleepEventType>(eventType: K, listener: (data: AsleepEventType[K]) => void) {
|
|
151
133
|
if (!this.listeners[eventType]) {
|
|
152
134
|
this.listeners[eventType] = [];
|
|
153
135
|
}
|
|
@@ -250,8 +232,7 @@ export const asleepStore = useAsleepStore;
|
|
|
250
232
|
export const AsleepSDK = {
|
|
251
233
|
setup: (config: AsleepSetupConfig) => useAsleepStore.getState().setup(config),
|
|
252
234
|
|
|
253
|
-
initAsleepConfig: (config: AsleepConfig) =>
|
|
254
|
-
useAsleepStore.getState().initAsleepConfig(config),
|
|
235
|
+
initAsleepConfig: (config: AsleepConfig) => useAsleepStore.getState().initAsleepConfig(config),
|
|
255
236
|
|
|
256
237
|
checkAndRestoreTracking: () => useAsleepStore.getState().checkAndRestoreTracking(),
|
|
257
238
|
|
|
@@ -263,23 +244,17 @@ export const AsleepSDK = {
|
|
|
263
244
|
|
|
264
245
|
stopTracking: () => useAsleepStore.getState().stopTracking(),
|
|
265
246
|
|
|
266
|
-
getReport: (sessionId: string) =>
|
|
267
|
-
useAsleepStore.getState().getReport(sessionId),
|
|
247
|
+
getReport: (sessionId: string) => useAsleepStore.getState().getReport(sessionId),
|
|
268
248
|
|
|
269
|
-
getReportList: (fromDate: string, toDate: string) =>
|
|
270
|
-
useAsleepStore.getState().getReportList(fromDate, toDate),
|
|
249
|
+
getReportList: (fromDate: string, toDate: string) => useAsleepStore.getState().getReportList(fromDate, toDate),
|
|
271
250
|
|
|
272
|
-
getAverageReport: (fromDate: string, toDate: string) =>
|
|
273
|
-
useAsleepStore.getState().getAverageReport(fromDate, toDate),
|
|
251
|
+
getAverageReport: (fromDate: string, toDate: string) => useAsleepStore.getState().getAverageReport(fromDate, toDate),
|
|
274
252
|
|
|
275
|
-
deleteSession: (sessionId: string) =>
|
|
276
|
-
useAsleepStore.getState().deleteSession(sessionId),
|
|
253
|
+
deleteSession: (sessionId: string) => useAsleepStore.getState().deleteSession(sessionId),
|
|
277
254
|
|
|
278
|
-
requestMicrophonePermission: () =>
|
|
279
|
-
useAsleepStore.getState().requestMicrophonePermission(),
|
|
255
|
+
requestMicrophonePermission: () => useAsleepStore.getState().requestMicrophonePermission(),
|
|
280
256
|
|
|
281
|
-
requestRequiredPermissions: () =>
|
|
282
|
-
useAsleepStore.getState().requestRequiredPermissions(),
|
|
257
|
+
requestRequiredPermissions: () => useAsleepStore.getState().requestRequiredPermissions(),
|
|
283
258
|
|
|
284
259
|
requestAnalysis: () => useAsleepStore.getState().requestAnalysis(),
|
|
285
260
|
|
|
@@ -301,8 +276,7 @@ export const AsleepSDK = {
|
|
|
301
276
|
|
|
302
277
|
enableLog: (print: boolean) => useAsleepStore.getState().enableLog(print),
|
|
303
278
|
|
|
304
|
-
setCustomNotification: (title: string, text: string) =>
|
|
305
|
-
useAsleepStore.getState().setCustomNotification(title, text),
|
|
279
|
+
setCustomNotification: (title: string, text: string) => useAsleepStore.getState().setCustomNotification(title, text),
|
|
306
280
|
|
|
307
281
|
clearError: () => useAsleepStore.getState().clearError(),
|
|
308
282
|
|
package/.eslintrc.js
DELETED
package/.releaserc.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
branches: ["main"],
|
|
3
|
-
plugins: [
|
|
4
|
-
[
|
|
5
|
-
"@semantic-release/commit-analyzer",
|
|
6
|
-
{
|
|
7
|
-
// Configure parser to recognize entire commit message as title
|
|
8
|
-
parserOpts: {
|
|
9
|
-
headerPattern: /^(.*)$/,
|
|
10
|
-
headerCorrespondence: ["subject"],
|
|
11
|
-
},
|
|
12
|
-
// Set rules to make any commit trigger a 'patch' release
|
|
13
|
-
releaseRules: [{ release: "patch" }],
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
"@semantic-release/release-notes-generator",
|
|
18
|
-
{
|
|
19
|
-
// Configure parser to recognize entire commit message as title
|
|
20
|
-
parserOpts: {
|
|
21
|
-
headerPattern: /^(.*)$/,
|
|
22
|
-
headerCorrespondence: ["subject"],
|
|
23
|
-
},
|
|
24
|
-
// Customize release notes generator
|
|
25
|
-
writerOpts: {
|
|
26
|
-
// Function to transform commit objects
|
|
27
|
-
transform: (commit) => {
|
|
28
|
-
// Since commit objects cannot be modified directly, create a copy to modify
|
|
29
|
-
const newCommit = { ...commit };
|
|
30
|
-
|
|
31
|
-
// Force assign 'fix' type recognized by release notes generator
|
|
32
|
-
// so that all commits are included in release notes.
|
|
33
|
-
// This will display all commits under the "Bug Fixes" section.
|
|
34
|
-
newCommit.type = "fix";
|
|
35
|
-
|
|
36
|
-
return newCommit;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
"@semantic-release/changelog",
|
|
42
|
-
[
|
|
43
|
-
"@semantic-release/npm",
|
|
44
|
-
{
|
|
45
|
-
npmPublish: true,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
[
|
|
49
|
-
"@semantic-release/git",
|
|
50
|
-
{
|
|
51
|
-
assets: ["package.json", "pnpm-lock.yaml", "CHANGELOG.md"],
|
|
52
|
-
message:
|
|
53
|
-
"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
"@semantic-release/github",
|
|
57
|
-
],
|
|
58
|
-
};
|
package/AGENTS.md
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# AGENTS.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
React Native SDK for Asleep's AI-powered sleep tracking technology. This SDK provides non-invasive sleep tracking through audio analysis without requiring wearable devices.
|
|
8
|
-
|
|
9
|
-
## Development Commands
|
|
10
|
-
|
|
11
|
-
### Building and Testing
|
|
12
|
-
```bash
|
|
13
|
-
# Build the SDK
|
|
14
|
-
pnpm build
|
|
15
|
-
|
|
16
|
-
# Clean build artifacts
|
|
17
|
-
pnpm clean
|
|
18
|
-
|
|
19
|
-
# Run linting
|
|
20
|
-
pnpm lint
|
|
21
|
-
|
|
22
|
-
# Run tests
|
|
23
|
-
pnpm test
|
|
24
|
-
|
|
25
|
-
# Prepare the module
|
|
26
|
-
pnpm prepare
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Example App Commands
|
|
30
|
-
```bash
|
|
31
|
-
# In the example directory
|
|
32
|
-
pnpm start # Start Expo development server
|
|
33
|
-
pnpm android # Run on Android
|
|
34
|
-
pnpm ios # Run on iOS
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Publishing and Release
|
|
38
|
-
```bash
|
|
39
|
-
# Manual release via GitHub Actions
|
|
40
|
-
# Go to Actions > Release > Run workflow
|
|
41
|
-
|
|
42
|
-
# Automatic semantic release
|
|
43
|
-
pnpm semantic-release
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Architecture
|
|
47
|
-
|
|
48
|
-
### Core Components
|
|
49
|
-
|
|
50
|
-
1. **Native Modules** (`ios/AsleepModule.swift`, `android/.../AsleepModule.kt`)
|
|
51
|
-
- Platform-specific implementations wrapping native Asleep SDKs
|
|
52
|
-
- Handle audio recording, permission management, and sleep tracking
|
|
53
|
-
- iOS SDK version: 3.2.0, Android SDK version: 3.2.0
|
|
54
|
-
|
|
55
|
-
2. **State Management** (`src/AsleepStore.ts`)
|
|
56
|
-
- Zustand store with singleton pattern for consistent state across app
|
|
57
|
-
- Handles all SDK state including tracking status, session management, and error handling
|
|
58
|
-
- Provides event listener initialization and cleanup
|
|
59
|
-
|
|
60
|
-
3. **API Surface** (`src/index.ts`)
|
|
61
|
-
- `useAsleep` hook for React components
|
|
62
|
-
- `AsleepSDK` singleton for non-React contexts
|
|
63
|
-
- Event-driven architecture with automatic state updates
|
|
64
|
-
|
|
65
|
-
4. **Type Definitions** (`src/Asleep.types.ts`)
|
|
66
|
-
- TypeScript interfaces for all API responses and configurations
|
|
67
|
-
- Comprehensive sleep report and session structures
|
|
68
|
-
|
|
69
|
-
### Key Features
|
|
70
|
-
|
|
71
|
-
- **Setup Methods**: Two initialization approaches - `setup()` for ODA (On-Device Analysis) and `initAsleepConfig()` for standard mode
|
|
72
|
-
- **Real-time Tracking**: Start/stop tracking with automatic microphone permission handling
|
|
73
|
-
- **Report Generation**: Fetch detailed sleep analysis reports with comprehensive metrics
|
|
74
|
-
- **Event System**: Automatic event handling through EventEmitter with state synchronization
|
|
75
|
-
- **Platform Differences**:
|
|
76
|
-
- Android: Returns analysis results immediately from `requestAnalysis()`
|
|
77
|
-
- iOS: Returns acknowledgment only, results come via `onAnalysisResult` event
|
|
78
|
-
|
|
79
|
-
### Native Integration Points
|
|
80
|
-
|
|
81
|
-
- **iOS**: Swift module using Expo modules, requires audio background mode
|
|
82
|
-
- **Android**: Kotlin module with foreground service for long-running tracking
|
|
83
|
-
- **Permissions**: Microphone access required on both platforms, battery optimization exemption recommended on Android
|
|
84
|
-
|
|
85
|
-
## Development Guidelines
|
|
86
|
-
|
|
87
|
-
### State Management Pattern
|
|
88
|
-
- Always use store actions for state updates
|
|
89
|
-
- Check `isSetupInProgress` and `isTracking` flags to prevent duplicate operations
|
|
90
|
-
- Handle platform differences in analysis result handling
|
|
91
|
-
|
|
92
|
-
### Error Handling
|
|
93
|
-
- All async operations should be wrapped in try-catch blocks
|
|
94
|
-
- Errors are automatically stored in the state and accessible via the `error` property
|
|
95
|
-
- Use the `addLog` function for debug logging when `enableLog(true)` is set
|
|
96
|
-
|
|
97
|
-
### Testing Changes
|
|
98
|
-
- Test on both iOS and Android platforms
|
|
99
|
-
- Verify permission handling flows
|
|
100
|
-
- Test background tracking scenarios
|
|
101
|
-
- Ensure state consistency across tracking lifecycle
|
|
102
|
-
|
|
103
|
-
### Release Process
|
|
104
|
-
- Uses semantic-release with custom configuration
|
|
105
|
-
- All commits trigger patch releases
|
|
106
|
-
- Changelog automatically generated
|
|
107
|
-
- NPM publishing handled by GitHub Actions
|
package/docs/PUBLISHING.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Publishing Guide
|
|
2
|
-
|
|
3
|
-
This package uses [semantic-release](https://semantic-release.gitbook.io/) for automated version management and package publishing.
|
|
4
|
-
|
|
5
|
-
## Automated Release Process
|
|
6
|
-
|
|
7
|
-
Releases are triggered automatically via GitHub Actions when changes are pushed to the `main` branch:
|
|
8
|
-
|
|
9
|
-
1. Push changes to `main` branch
|
|
10
|
-
2. GitHub Actions runs the Release workflow
|
|
11
|
-
3. semantic-release analyzes commits and determines version bump
|
|
12
|
-
4. Automatically publishes to npm if needed
|
|
13
|
-
|
|
14
|
-
## Manual Release
|
|
15
|
-
|
|
16
|
-
To trigger a release manually:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
# From GitHub UI
|
|
20
|
-
# Go to Actions → Release → Run workflow
|
|
21
|
-
|
|
22
|
-
# Or using GitHub CLI
|
|
23
|
-
gh workflow run release.yml --ref main
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Important Notes
|
|
27
|
-
|
|
28
|
-
- **DO NOT** add a custom `publish` script to package.json
|
|
29
|
-
- **DO NOT** run `npm publish` manually
|
|
30
|
-
- All releases must go through semantic-release to maintain version consistency
|
|
31
|
-
|
|
32
|
-
## Configuration
|
|
33
|
-
|
|
34
|
-
- Release configuration: `.releaserc.js`
|
|
35
|
-
- Publish settings: `package.json` → `publishConfig`
|
|
36
|
-
- Workflow: `.github/workflows/release.yml`
|
package/tsconfig.json
DELETED
|
File without changes
|