despia-native 1.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/LICENSE +21 -0
- package/README.md +428 -0
- package/index.d.ts +122 -0
- package/index.js +0 -0
- package/package.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 despia-native
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# Despia SDK
|
|
2
|
+
|
|
3
|
+
JavaScript SDK for [Despia](https://docs.despia.com) native integrations with command queuing and variable watching capabilities.
|
|
4
|
+
|
|
5
|
+
## About Despia
|
|
6
|
+
|
|
7
|
+
Despia provides native device capabilities to web applications through a simple protocol system. Access features like:
|
|
8
|
+
- App Links & Deep Linking
|
|
9
|
+
- Native Widgets & App Clips
|
|
10
|
+
- In-App Purchases & Subscriptions
|
|
11
|
+
- Push Notifications & Local Notifications
|
|
12
|
+
- Camera Roll & File Downloads
|
|
13
|
+
- Biometric Authentication
|
|
14
|
+
- Background Location
|
|
15
|
+
- And many more native features
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install despia
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Despia Command Execution
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import despia from 'despia';
|
|
29
|
+
|
|
30
|
+
// Execute a Despia protocol command (no response)
|
|
31
|
+
await despia('lighthaptic://');
|
|
32
|
+
|
|
33
|
+
// Execute command and watch for response variables
|
|
34
|
+
const result = await despia('getappversion://', ['versionNumber', 'bundleNumber'], 5000);
|
|
35
|
+
console.log(result); // { versionNumber: '1.0.0', bundleNumber: '123' }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Despia Command Examples
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// Native Widgets
|
|
42
|
+
await despia('widget://${svg}?refresh=${refresh_time}');
|
|
43
|
+
|
|
44
|
+
// RevenueCat In-App Purchases
|
|
45
|
+
await despia('revenuecat://purchase?external_id=user_777&product=monthly_premium');
|
|
46
|
+
|
|
47
|
+
// Contact Permissions
|
|
48
|
+
await despia('requestcontactpermission://');
|
|
49
|
+
const contacts = await despia('readcontacts://', ['contacts']);
|
|
50
|
+
|
|
51
|
+
// Background Location
|
|
52
|
+
await despia('backgroundlocationon://');
|
|
53
|
+
// Use native browser geolocation API (not despia wrapper)
|
|
54
|
+
const watchId = navigator.geolocation.watchPosition(
|
|
55
|
+
(position) => console.log('Location:', position),
|
|
56
|
+
(error) => console.error('Location error:', error)
|
|
57
|
+
);
|
|
58
|
+
// To stop
|
|
59
|
+
await despia('backgroundlocationoff://');
|
|
60
|
+
navigator.geolocation.clearWatch(watchId);
|
|
61
|
+
|
|
62
|
+
// Push Notifications
|
|
63
|
+
await despia('registerpush://');
|
|
64
|
+
await despia('sendlocalpushmsg://push.send?s=60&msg=Hello&!#New Message&!#https://myapp.com');
|
|
65
|
+
const oneSignalData = await despia('getonesignalplayerid://', ['onesignalplayerid']);
|
|
66
|
+
|
|
67
|
+
// Haptic Feedback
|
|
68
|
+
await despia('lighthaptic://');
|
|
69
|
+
await despia('heavyhaptic://');
|
|
70
|
+
await despia('successhaptic://');
|
|
71
|
+
await despia('warninghaptic://');
|
|
72
|
+
await despia('errorhaptic://');
|
|
73
|
+
|
|
74
|
+
// App Information
|
|
75
|
+
const appInfo = await despia('getappversion://', ['versionNumber', 'bundleNumber']);
|
|
76
|
+
const deviceInfo = await despia('get-uuid://', ['uuid']);
|
|
77
|
+
|
|
78
|
+
// Screenshots and Scanning
|
|
79
|
+
await despia('takescreenshot://');
|
|
80
|
+
await despia('scanningmode://auto');
|
|
81
|
+
await despia('scanningmode://on');
|
|
82
|
+
await despia('scanningmode://off');
|
|
83
|
+
|
|
84
|
+
// Store and Location
|
|
85
|
+
const storeData = await despia('getstorelocation://', ['storeLocation']);
|
|
86
|
+
|
|
87
|
+
// Image and File Operations
|
|
88
|
+
await despia('savethisimage://?url=${image_url}');
|
|
89
|
+
await despia('file://${file_url}');
|
|
90
|
+
|
|
91
|
+
// App Control
|
|
92
|
+
await despia('reset://');
|
|
93
|
+
const trackingData = await despia('user-disable-tracking://', ['trackingDisabled']);
|
|
94
|
+
|
|
95
|
+
// UI Controls
|
|
96
|
+
await despia('spinneron://');
|
|
97
|
+
await despia('spinneroff://');
|
|
98
|
+
await despia('hidebars://on');
|
|
99
|
+
await despia('hidebars://off');
|
|
100
|
+
|
|
101
|
+
// Sharing
|
|
102
|
+
await despia('shareapp://message?=${message}&url=${url}');
|
|
103
|
+
|
|
104
|
+
// Status Bar Styling
|
|
105
|
+
await despia('statusbarcolor://{255, 255, 255}');
|
|
106
|
+
await despia('statusbartextcolor://{black}');
|
|
107
|
+
|
|
108
|
+
// Biometric Authentication
|
|
109
|
+
await despia('bioauth://');
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Direct Window Variable Access
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
// Access any window variable directly (useful for Despia response data)
|
|
116
|
+
const currentUser = despia.currentUser;
|
|
117
|
+
const deviceInfo = despia.deviceInfo;
|
|
118
|
+
const appVersion = despia.appVersion;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Advanced Usage with Variable Watching
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
// Watch multiple response variables with custom timeout
|
|
125
|
+
const appData = await despia('getappversion://', ['versionNumber', 'bundleNumber'], 15000);
|
|
126
|
+
|
|
127
|
+
// Chain multiple Despia commands
|
|
128
|
+
await despia('lighthaptic://');
|
|
129
|
+
await despia('getappversion://', ['versionNumber', 'bundleNumber']);
|
|
130
|
+
await despia('successhaptic://');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Background Location Workflow
|
|
134
|
+
|
|
135
|
+
Background location tracking requires a two-step process:
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
// Step 1: Enable native background location tracking via Despia
|
|
139
|
+
await despia('backgroundlocationon://');
|
|
140
|
+
|
|
141
|
+
// Step 2: Use native browser geolocation API for actual tracking (not despia wrapper)
|
|
142
|
+
const watchId = navigator.geolocation.watchPosition(
|
|
143
|
+
(position) => {
|
|
144
|
+
console.log('Location update:', {
|
|
145
|
+
latitude: position.coords.latitude,
|
|
146
|
+
longitude: position.coords.longitude,
|
|
147
|
+
accuracy: position.coords.accuracy,
|
|
148
|
+
timestamp: position.timestamp
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
(error) => {
|
|
152
|
+
console.error('Location error:', error);
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
enableHighAccuracy: true,
|
|
156
|
+
timeout: 10000,
|
|
157
|
+
maximumAge: 60000
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// To stop tracking:
|
|
162
|
+
// Step 1: Disable native background tracking via Despia
|
|
163
|
+
await despia('backgroundlocationoff://');
|
|
164
|
+
// Step 2: Clear browser geolocation watch (native API)
|
|
165
|
+
navigator.geolocation.clearWatch(watchId);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Contact Access Workflow
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
// Step 1: Request contact permission
|
|
172
|
+
await despia('requestcontactpermission://');
|
|
173
|
+
|
|
174
|
+
// Step 2: Read contacts after permission granted
|
|
175
|
+
const contactData = await despia('readcontacts://', ['contacts']);
|
|
176
|
+
console.log('Contacts:', contactData.contacts);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Haptic Feedback
|
|
180
|
+
|
|
181
|
+
All haptic feedback commands have no response - they provide immediate tactile feedback:
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
// Basic haptic feedback
|
|
185
|
+
await despia('lighthaptic://'); // Light haptic feedback - subtle vibration
|
|
186
|
+
await despia('heavyhaptic://'); // Heavy haptic feedback - strong vibration
|
|
187
|
+
|
|
188
|
+
// Contextual haptic feedback
|
|
189
|
+
await despia('successhaptic://'); // Success haptic feedback - positive confirmation
|
|
190
|
+
await despia('warninghaptic://'); // Warning haptic feedback - attention alert
|
|
191
|
+
await despia('errorhaptic://'); // Error haptic feedback - negative feedback
|
|
192
|
+
|
|
193
|
+
// Use cases:
|
|
194
|
+
// - Button press feedback (light/heavy)
|
|
195
|
+
// - Success notifications (successhaptic)
|
|
196
|
+
// - Warning alerts (warninghaptic)
|
|
197
|
+
// - Error feedback (errorhaptic)
|
|
198
|
+
// - UI interaction confirmation
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Biometric Authentication
|
|
202
|
+
|
|
203
|
+
Biometric authentication requires setting up callback functions before running the command:
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
// Step 1: Set up the biometric authentication SDK
|
|
207
|
+
if (!document.getElementById("bioauth-sdk")) {
|
|
208
|
+
const script = document.createElement("script")
|
|
209
|
+
script.id = "bioauth-sdk"
|
|
210
|
+
script.type = "text/javascript"
|
|
211
|
+
script.textContent = `
|
|
212
|
+
function onBioAuthSuccess() {
|
|
213
|
+
window.bioauthSuccess()
|
|
214
|
+
}
|
|
215
|
+
function onBioAuthFailure(errorCode, errorMessage) {
|
|
216
|
+
window.bioauthFailure(errorCode, errorMessage)
|
|
217
|
+
}
|
|
218
|
+
function onBioAuthUnavailable() {
|
|
219
|
+
window.bioauthUnavailable()
|
|
220
|
+
}
|
|
221
|
+
`
|
|
222
|
+
document.head.appendChild(script)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Step 2: Define your callback functions
|
|
226
|
+
window.bioauthSuccess = function() {
|
|
227
|
+
if (navigator.userAgent.includes("despia")) {
|
|
228
|
+
console.log("Biometric authentication successful");
|
|
229
|
+
// Handle successful authentication
|
|
230
|
+
// Redirect user, unlock features, etc.
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
window.bioauthFailure = function(errorCode, errorMessage) {
|
|
235
|
+
if (navigator.userAgent.includes("despia")) {
|
|
236
|
+
console.log("Biometric authentication failed:", errorCode, errorMessage);
|
|
237
|
+
// Handle authentication failure
|
|
238
|
+
// Show error message, fallback to password, etc.
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
window.bioauthUnavailable = function() {
|
|
243
|
+
if (navigator.userAgent.includes("despia")) {
|
|
244
|
+
console.log("Biometric authentication unavailable");
|
|
245
|
+
// Handle when biometric auth is not available
|
|
246
|
+
// Fallback to alternative authentication method
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Step 3: Trigger biometric authentication
|
|
251
|
+
await despia('bioauth://');
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### App Information & Device Data
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
// Get app version information
|
|
258
|
+
const appInfo = await despia('getappversion://', ['versionNumber', 'bundleNumber']);
|
|
259
|
+
console.log('App Version:', appInfo.versionNumber);
|
|
260
|
+
console.log('Bundle Number:', appInfo.bundleNumber);
|
|
261
|
+
|
|
262
|
+
// Get device UUID (native device ID)
|
|
263
|
+
const deviceData = await despia('get-uuid://', ['uuid']);
|
|
264
|
+
console.log('Device UUID:', deviceData.uuid);
|
|
265
|
+
|
|
266
|
+
// Get store location
|
|
267
|
+
const storeData = await despia('getstorelocation://', ['storeLocation']);
|
|
268
|
+
console.log('Store Location:', storeData.storeLocation);
|
|
269
|
+
|
|
270
|
+
// Check tracking permission
|
|
271
|
+
const trackingData = await despia('user-disable-tracking://', ['trackingDisabled']);
|
|
272
|
+
console.log('Tracking Disabled:', trackingData.trackingDisabled);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### UI Controls & Styling
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
// Loading spinner controls
|
|
279
|
+
await despia('spinneron://'); // Show loading spinner
|
|
280
|
+
await despia('spinneroff://'); // Hide loading spinner
|
|
281
|
+
|
|
282
|
+
// Full screen mode
|
|
283
|
+
await despia('hidebars://on'); // Hide status bar (full screen)
|
|
284
|
+
await despia('hidebars://off'); // Show status bar
|
|
285
|
+
|
|
286
|
+
// Status bar styling
|
|
287
|
+
await despia('statusbarcolor://{255, 255, 255}'); // Set status bar background color (RGB)
|
|
288
|
+
await despia('statusbartextcolor://{black}'); // Set status bar text color (black/white)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### File & Media Operations
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
// Take screenshot (saves to device)
|
|
295
|
+
await despia('takescreenshot://');
|
|
296
|
+
|
|
297
|
+
// Save image from URL
|
|
298
|
+
await despia('savethisimage://?url=https://example.com/image.jpg');
|
|
299
|
+
|
|
300
|
+
// Download file from URL
|
|
301
|
+
await despia('file://https://example.com/document.pdf');
|
|
302
|
+
|
|
303
|
+
// Share app with message and URL
|
|
304
|
+
await despia('shareapp://message?=Check%20out%20this%20app&url=https://myapp.com');
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Scanning Mode
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
// Control scanning mode
|
|
311
|
+
await despia('scanningmode://auto'); // Auto scanning mode
|
|
312
|
+
await despia('scanningmode://on'); // Enable scanning
|
|
313
|
+
await despia('scanningmode://off'); // Disable scanning
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### App Reset
|
|
317
|
+
|
|
318
|
+
```javascript
|
|
319
|
+
// Reset app (use with caution)
|
|
320
|
+
await despia('reset://');
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Native Safe Area
|
|
324
|
+
|
|
325
|
+
Access native safe area insets via CSS custom properties:
|
|
326
|
+
|
|
327
|
+
```css
|
|
328
|
+
/* Use native safe area insets in your CSS */
|
|
329
|
+
.my-element {
|
|
330
|
+
padding-top: var(--safe-area-top);
|
|
331
|
+
padding-bottom: var(--safe-area-bottom);
|
|
332
|
+
padding-left: var(--safe-area-left);
|
|
333
|
+
padding-right: var(--safe-area-right);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* Full height with safe area consideration */
|
|
337
|
+
.full-height {
|
|
338
|
+
height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
These CSS variables are automatically provided by the Despia native runtime and represent the device's safe area insets (notches, home indicators, etc.).
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
## API Reference
|
|
347
|
+
|
|
348
|
+
### `despia(command, watch?, timeout?)`
|
|
349
|
+
|
|
350
|
+
- **command** (string): The Despia protocol command (e.g., `'applinks://open?url=...'`)
|
|
351
|
+
- **watch** (string[], optional): Array of variable names to watch for in the response
|
|
352
|
+
- **timeout** (number, optional): Timeout in milliseconds (default: 10000)
|
|
353
|
+
|
|
354
|
+
Returns a Promise that resolves when all watched variables are available or timeout is reached.
|
|
355
|
+
|
|
356
|
+
### Direct Property Access
|
|
357
|
+
|
|
358
|
+
Access any window variable directly through the despia object:
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
despia.variableName // Equivalent to window.variableName
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Despia Protocol Format
|
|
365
|
+
|
|
366
|
+
Despia uses a simple protocol format for all native integrations:
|
|
367
|
+
|
|
368
|
+
```
|
|
369
|
+
feature://action?parameters
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Examples:
|
|
373
|
+
- `lighthaptic://`
|
|
374
|
+
- `getappversion://`
|
|
375
|
+
- `revenuecat://purchase?external_id=user_777&product=monthly_premium`
|
|
376
|
+
- `requestcontactpermission://`
|
|
377
|
+
- `savethisimage://?url=https://example.com/image.jpg`
|
|
378
|
+
|
|
379
|
+
## Available Despia Features
|
|
380
|
+
|
|
381
|
+
Your app can access these native features:
|
|
382
|
+
|
|
383
|
+
- **Native Widgets** - Create widgets with SVG and refresh time
|
|
384
|
+
- **In-App Purchases** - RevenueCat integration with external user IDs
|
|
385
|
+
- **Contact Access** - Request permissions and read contacts
|
|
386
|
+
- **Background Location** - Native tracking with browser geolocation API
|
|
387
|
+
- **Push Notifications** - OneSignal integration and local push messages
|
|
388
|
+
- **Haptic Feedback** - Light, heavy, success, warning, and error feedback
|
|
389
|
+
- **App Information** - Version numbers, bundle numbers, device UUID
|
|
390
|
+
- **Screenshots** - Take device screenshots
|
|
391
|
+
- **Scanning Mode** - Auto, on, and off scanning controls
|
|
392
|
+
- **Store Location** - Get store location data
|
|
393
|
+
- **File Operations** - Save images and download files
|
|
394
|
+
- **App Control** - Reset app and disable tracking
|
|
395
|
+
- **UI Controls** - Loading spinners and full screen mode
|
|
396
|
+
- **Sharing** - Share app with custom messages and URLs
|
|
397
|
+
- **Status Bar** - Control colors and text colors
|
|
398
|
+
- **Biometric Authentication** - Native biometric auth with callbacks
|
|
399
|
+
|
|
400
|
+
## TypeScript Support
|
|
401
|
+
|
|
402
|
+
Full TypeScript definitions are included:
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
import despia from 'despia';
|
|
406
|
+
|
|
407
|
+
// Type-safe usage with Despia commands
|
|
408
|
+
const result: { versionNumber: string; bundleNumber: string } = await despia(
|
|
409
|
+
'getappversion://',
|
|
410
|
+
['versionNumber', 'bundleNumber']
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// Direct property access
|
|
414
|
+
const deviceInfo: any = despia.deviceInfo;
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## Integration with Despia
|
|
418
|
+
|
|
419
|
+
This SDK is designed to work with [Despia's native integration system](https://docs.despia.com/docs/native-integrations/getting-started). The SDK provides:
|
|
420
|
+
|
|
421
|
+
- **Command Queuing** - Sequential execution of Despia commands
|
|
422
|
+
- **Variable Watching** - Async monitoring of response variables
|
|
423
|
+
- **Timeout Handling** - Configurable timeouts for long-running operations
|
|
424
|
+
- **Direct Access** - Proxy-based access to window variables
|
|
425
|
+
|
|
426
|
+
## License
|
|
427
|
+
|
|
428
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// index.d.ts - TypeScript definitions for Despia SDK
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Despia protocol command types
|
|
5
|
+
*/
|
|
6
|
+
type DespiaCommand =
|
|
7
|
+
| `applinks://${string}`
|
|
8
|
+
| `widget://${string}`
|
|
9
|
+
| `revenuecat://${string}`
|
|
10
|
+
| `requestcontactpermission://`
|
|
11
|
+
| `readcontacts://`
|
|
12
|
+
| `backgroundlocationon://`
|
|
13
|
+
| `backgroundlocationoff://`
|
|
14
|
+
| `registerpush://`
|
|
15
|
+
| `sendlocalpushmsg://${string}`
|
|
16
|
+
| `getonesignalplayerid://`
|
|
17
|
+
| `getappversion://`
|
|
18
|
+
| `get-uuid://`
|
|
19
|
+
| `takescreenshot://`
|
|
20
|
+
| `scanningmode://auto`
|
|
21
|
+
| `scanningmode://on`
|
|
22
|
+
| `scanningmode://off`
|
|
23
|
+
| `getstorelocation://`
|
|
24
|
+
| `savethisimage://?url=${string}`
|
|
25
|
+
| `reset://`
|
|
26
|
+
| `user-disable-tracking://`
|
|
27
|
+
| `spinneron://`
|
|
28
|
+
| `spinneroff://`
|
|
29
|
+
| `shareapp://message?=${string}&url=${string}`
|
|
30
|
+
| `hidebars://on`
|
|
31
|
+
| `hidebars://off`
|
|
32
|
+
| `bioauth://`
|
|
33
|
+
| `statusbarcolor://{${string}}`
|
|
34
|
+
| `statusbartextcolor://{${string}}`
|
|
35
|
+
| `lighthaptic://`
|
|
36
|
+
| `heavyhaptic://`
|
|
37
|
+
| `successhaptic://`
|
|
38
|
+
| `warninghaptic://`
|
|
39
|
+
| `errorhaptic://`
|
|
40
|
+
| `haptic://${string}`
|
|
41
|
+
| `purchase://${string}`
|
|
42
|
+
| `push://${string}`
|
|
43
|
+
| `camera://${string}`
|
|
44
|
+
| `biometric://${string}`
|
|
45
|
+
| `location://${string}`
|
|
46
|
+
| `download://${string}`
|
|
47
|
+
| `analytics://${string}`
|
|
48
|
+
| `statusbar://${string}`
|
|
49
|
+
| `file://${string}`
|
|
50
|
+
| string; // Allow any string for future protocol extensions
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Main Despia SDK function interface
|
|
54
|
+
*/
|
|
55
|
+
interface DespiaFunction {
|
|
56
|
+
/**
|
|
57
|
+
* Execute a Despia protocol command without watching for response variables
|
|
58
|
+
* @param command - The Despia protocol command (e.g., 'applinks://open?url=...')
|
|
59
|
+
* @returns Promise that resolves when command is queued
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* await despia('applinks://open?url=https://example.com');
|
|
64
|
+
* await despia('biometric://authenticate?reason=Login');
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
(command: DespiaCommand): Promise<void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Execute a Despia protocol command and watch for specific response variables
|
|
71
|
+
* @param command - The Despia protocol command
|
|
72
|
+
* @param watch - Array of variable names to watch for in the response
|
|
73
|
+
* @param timeout - Timeout in milliseconds (default: 10000)
|
|
74
|
+
* @returns Promise that resolves with the watched variables or times out
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const result = await despia('biometric://authenticate', ['authResult', 'userID']);
|
|
79
|
+
* const purchase = await despia('purchase://product?sku=premium', ['purchaseResult', 'transactionID']);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
<T = Record<string, any>>(command: DespiaCommand, watch: string[], timeout?: number): Promise<T>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Access any window variable directly (useful for Despia response data)
|
|
86
|
+
* @param key - The variable name to access
|
|
87
|
+
* @returns The value of the window variable
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const currentUser = despia.currentUser;
|
|
92
|
+
* const deviceInfo = despia.deviceInfo;
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Despia SDK - JavaScript SDK for Despia native integrations
|
|
100
|
+
*
|
|
101
|
+
* Provides command queuing, variable watching, and direct window access for
|
|
102
|
+
* Despia's native integration system.
|
|
103
|
+
*
|
|
104
|
+
* @see https://docs.despia.com/docs/native-integrations/getting-started
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import despia from 'despia';
|
|
109
|
+
*
|
|
110
|
+
* // Execute Despia protocol commands
|
|
111
|
+
* await despia('applinks://open?url=https://maps.apple.com');
|
|
112
|
+
*
|
|
113
|
+
* // Execute and watch for response variables
|
|
114
|
+
* const authResult = await despia('biometric://authenticate', ['authResult', 'userID']);
|
|
115
|
+
*
|
|
116
|
+
* // Access window variables directly
|
|
117
|
+
* const deviceInfo = despia.deviceInfo;
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare const despia: DespiaFunction;
|
|
121
|
+
|
|
122
|
+
export default despia;
|
package/index.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "despia-native",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "JavaScript SDK for Despia native integrations with command queuing and variable watching",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"keywords": ["despia", "sdk", "mobile", "native", "bridge", "applinks", "biometric", "purchase", "push", "camera", "location", "download", "haptic", "widget", "revenuecat", "contacts"],
|
|
9
|
+
"author": "Despia Native <developers@despia.com>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"No tests specified\"",
|
|
14
|
+
"prepublishOnly": "npm test"
|
|
15
|
+
},
|
|
16
|
+
"files": ["index.js", "index.d.ts", "README.md"]
|
|
17
|
+
}
|