despia-native 1.0.8 → 1.0.10

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.
Files changed (2) hide show
  1. package/README.md +140 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  JavaScript SDK for [Despia](https://despia.com) - Transform your web app into a native iOS & Android app without writing Swift or Kotlin. This npm package provides command queuing and variable watching for seamless integration with Despia's GPU-accelerated native runtime, enabling access to 25+ device APIs through simple JavaScript calls.
4
4
 
5
+ **Import:** `import despia from 'despia-native';` (default export, not destructured)
6
+
7
+ **IMPORTANT: This SDK package is REQUIRED for TypeScript, React, Vue, and other modern frameworks!** While `window.despia = ""` works in vanilla JavaScript, this package provides type safety, command queuing, and variable watching for professional development environments.
8
+
5
9
  ## About Despia
6
10
 
7
11
  Despia bridges the gap between web and native mobile development. Build your app using the web technologies you already know, then deploy it as a truly native application to the App Store and Google Play - complete with hardware acceleration, offline support, and deep OS integration.
@@ -47,6 +51,142 @@ Our visual editor allows you to configure native widgets, shortcuts, and dynamic
47
51
  npm install despia-native
48
52
  ```
49
53
 
54
+ ## Getting Started
55
+
56
+ ### Step 1: Import Despia SDK
57
+
58
+ **IMPORTANT: Always import as `despia` (default export), NOT as `{Commands}` or destructured imports!**
59
+
60
+ ```javascript
61
+ // CORRECT - ES6/ES2015 modules (default import)
62
+ import despia from 'despia-native';
63
+
64
+ // CORRECT - CommonJS
65
+ const despia = require('despia-native');
66
+
67
+ // CORRECT - Browser (if using UMD build)
68
+ // <script src="despia-native.js"></script>
69
+ // despia is available globally
70
+
71
+ // WRONG - Don't do this!
72
+ // import { Commands } from 'despia-native';
73
+ // import { despia } from 'despia-native';
74
+ ```
75
+
76
+ **The SDK exports a single function called `despia` as the default export.**
77
+
78
+ ### Step 2: Use Native Features
79
+
80
+ ```javascript
81
+ // Simple commands (no response needed)
82
+ despia('lighthaptic://'); // Light haptic feedback
83
+ despia('takescreenshot://'); // Take screenshot
84
+ despia('spinneron://'); // Show loading spinner
85
+
86
+ // Commands that return data (use await)
87
+ const appInfo = await despia('getappversion://', ['versionNumber', 'bundleNumber']);
88
+ console.log(appInfo); // { versionNumber: '1.0.0', bundleNumber: '123' }
89
+
90
+ const contacts = await despia('readcontacts://', ['contacts']);
91
+ console.log(contacts); // { contacts: [...] }
92
+ ```
93
+
94
+ ### Step 3: Handle Responses
95
+
96
+ ```javascript
97
+ // For commands that set variables, watch for them
98
+ const result = await despia('get-uuid://', ['uuid']);
99
+ console.log('Device UUID:', result.uuid);
100
+
101
+ // For commands with no response, just call them
102
+ despia('lighthaptic://');
103
+ despia('takescreenshot://');
104
+ ```
105
+
106
+ ### Quick Examples
107
+
108
+ ```javascript
109
+ // Haptic feedback
110
+ despia('lighthaptic://'); // Light vibration
111
+ despia('heavyhaptic://'); // Heavy vibration
112
+ despia('successhaptic://'); // Success vibration
113
+
114
+ // App information
115
+ const appInfo = await despia('getappversion://', ['versionNumber', 'bundleNumber']);
116
+ const deviceId = await despia('get-uuid://', ['uuid']);
117
+
118
+ // UI controls
119
+ despia('spinneron://'); // Show loading
120
+ despia('spinneroff://'); // Hide loading
121
+ despia('hidebars://on'); // Hide status bar
122
+
123
+ // Screenshots and sharing
124
+ despia('takescreenshot://');
125
+ despia('shareapp://message?=Hello&url=https://myapp.com');
126
+ ```
127
+
128
+ ### Common Import Issues
129
+
130
+ **If you get errors like "Commands is not a function" or "despia is not defined":**
131
+
132
+ ```javascript
133
+ // WRONG - This will cause errors
134
+ import { Commands } from 'despia-native';
135
+ import { despia } from 'despia-native';
136
+
137
+ // CORRECT - Always use default import
138
+ import despia from 'despia-native';
139
+
140
+ // Now you can use it
141
+ despia('lighthaptic://');
142
+ ```
143
+
144
+ **The package exports a single function as the default export, not named exports.**
145
+
146
+ ## When to Use This SDK Package
147
+
148
+ ### Vanilla JavaScript (works without this package)
149
+
150
+ ```javascript
151
+ // This WORKS in vanilla JavaScript:
152
+ window.despia = 'lighthaptic://';
153
+ window.despia = 'getappversion://';
154
+ ```
155
+
156
+ **Vanilla JS is fine for simple cases, but lacks:**
157
+ - **TypeScript Support** - No type definitions or autocomplete
158
+ - **Command Queuing** - Commands may be lost or executed out of order
159
+ - **Variable Watching** - Can't wait for responses from native commands
160
+ - **Error Handling** - No timeout or error management
161
+ - **Type Safety** - No validation or IntelliSense
162
+
163
+ ### Modern Frameworks Need This Package
164
+
165
+ ```javascript
166
+ // This WON'T work in TypeScript, React, Vue, etc.:
167
+ window.despia = 'lighthaptic://'; // TypeScript errors, no type safety
168
+ window.despia = 'getappversion://'; // No command queuing, no variable watching
169
+ ```
170
+
171
+ ### Modern Frameworks (TypeScript, React, Vue, etc.)
172
+
173
+ ```javascript
174
+ // This WORKS perfectly in modern frameworks:
175
+ import despia from 'despia-native';
176
+
177
+ despia('lighthaptic://'); // Type-safe, queued, with error handling
178
+ const result = await despia('getappversion://', ['versionNumber']); // Variable watching
179
+ ```
180
+
181
+ **Benefits of using this SDK:**
182
+ - **TypeScript Support** - Full type definitions and autocomplete
183
+ - **Command Queuing** - Sequential execution, no lost commands
184
+ - **Variable Watching** - Automatic waiting for native responses
185
+ - **Error Handling** - Timeouts, error management, debugging
186
+ - **Type Safety** - Validated commands, autocomplete, IntelliSense
187
+
188
+ **This package is REQUIRED for TypeScript, React, Vue, Angular, and other modern frameworks.**
189
+
50
190
  ## Usage
51
191
 
52
192
  ### Basic Despia Command Execution
@@ -452,7 +592,6 @@ Despia operates through a streamlined protocol handler system, allowing you to i
452
592
  - **Direct Access** - Proxy-based access to window variables
453
593
 
454
594
  ### How It Works
455
-
456
595
  Despia's protocol handler system eliminates the need for complex libraries or dependencies, making it compatible across various frameworks and platforms. The SDK uses the setter pattern to execute commands:
457
596
 
458
597
  ```javascript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "despia-native",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "JavaScript SDK for Despia native integrations with command queuing and variable watching",
5
5
  "main": "index.js",
6
6
  "module": "index.js",