@cloudsignal/pwa-sdk 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/CHANGELOG.md +42 -0
- package/README.md +383 -0
- package/dist/index.cjs +2051 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +1197 -0
- package/dist/index.d.ts +1197 -0
- package/dist/index.global.js +9 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +2026 -0
- package/dist/index.js.map +1 -0
- package/dist/service-worker.js +291 -0
- package/dist/service-worker.js.map +1 -0
- package/package.json +72 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-01-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release of CloudSignal PWA SDK
|
|
13
|
+
- **PWAClient** - Main SDK entry point with event-driven architecture
|
|
14
|
+
- **DeviceDetector** - Comprehensive device/browser/OS detection (35+ fields)
|
|
15
|
+
- **ServiceWorkerManager** - Service worker registration and update handling
|
|
16
|
+
- **InstallationManager** - PWA install prompt with iOS manual instructions
|
|
17
|
+
- **PushNotificationManager** - Web Push with VAPID authentication
|
|
18
|
+
- **HeartbeatManager** - Online status tracking with configurable intervals
|
|
19
|
+
- **Service Worker** - Push handling, badge management, notification history
|
|
20
|
+
- Full TypeScript support with exported types
|
|
21
|
+
- Multi-format builds: ESM, CommonJS, IIFE (browser)
|
|
22
|
+
- HMAC authentication for backend API calls
|
|
23
|
+
- Device fingerprinting for unique device identification
|
|
24
|
+
- IndexedDB storage for notification history
|
|
25
|
+
- Network status monitoring (online/offline events)
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
- Automatic install prompt capture and management
|
|
30
|
+
- iOS 16.4+ Safari push notification support
|
|
31
|
+
- App badge management via Badge API
|
|
32
|
+
- Configurable heartbeat intervals
|
|
33
|
+
- Debug mode for development
|
|
34
|
+
- Event system for all PWA lifecycle events
|
|
35
|
+
|
|
36
|
+
### Browser Support
|
|
37
|
+
|
|
38
|
+
- Chrome 80+
|
|
39
|
+
- Edge 80+
|
|
40
|
+
- Firefox 78+
|
|
41
|
+
- Safari 16.4+ (iOS and macOS)
|
|
42
|
+
- Samsung Internet 13+
|
package/README.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# CloudSignal PWA SDK
|
|
2
|
+
|
|
3
|
+
Progressive Web App SDK for CloudSignal platform with push notifications, installation management, and comprehensive device tracking.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **PWA Installation** - Automatic install prompt handling with iOS manual instructions
|
|
8
|
+
- **Push Notifications** - Web Push Protocol with VAPID authentication
|
|
9
|
+
- **Device Detection** - 35+ device/browser/OS detection fields
|
|
10
|
+
- **Heartbeat** - Real-time online status tracking
|
|
11
|
+
- **Service Worker** - Badge management, notification history, offline support
|
|
12
|
+
- **TypeScript** - Full type definitions included
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### npm
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @cloudsignal/pwa-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### CDN
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<!-- Latest version -->
|
|
26
|
+
<script src="https://cdn.cloudsignal.io/CloudSignalPWA.js"></script>
|
|
27
|
+
|
|
28
|
+
<!-- Specific version -->
|
|
29
|
+
<script src="https://cdn.cloudsignal.io/cloudsignal-pwa.v1.0.0.js"></script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import { CloudSignalPWA } from '@cloudsignal/pwa-sdk'
|
|
38
|
+
|
|
39
|
+
const pwa = new CloudSignalPWA({
|
|
40
|
+
organizationId: 'your-org-uuid',
|
|
41
|
+
organizationSecret: 'your-secret-key',
|
|
42
|
+
serviceId: 'your-service-uuid',
|
|
43
|
+
debug: true
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Initialize (downloads config, registers service worker)
|
|
47
|
+
await pwa.initialize()
|
|
48
|
+
|
|
49
|
+
// Get device information
|
|
50
|
+
const deviceInfo = pwa.getDeviceInfo()
|
|
51
|
+
console.log('Device:', deviceInfo.deviceModel, deviceInfo.browser)
|
|
52
|
+
|
|
53
|
+
// Check installation state
|
|
54
|
+
if (pwa.canInstall()) {
|
|
55
|
+
await pwa.showInstallPrompt()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Register for push notifications
|
|
59
|
+
const registration = await pwa.registerForPush({
|
|
60
|
+
userEmail: 'user@example.com'
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### CDN Usage
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script src="https://cdn.cloudsignal.io/CloudSignalPWA.js"></script>
|
|
68
|
+
<script>
|
|
69
|
+
const pwa = new CloudSignalPWA.CloudSignalPWA({
|
|
70
|
+
organizationId: 'your-org-uuid',
|
|
71
|
+
organizationSecret: 'your-secret-key',
|
|
72
|
+
serviceId: 'your-service-uuid'
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
pwa.initialize().then(() => {
|
|
76
|
+
console.log('PWA initialized')
|
|
77
|
+
})
|
|
78
|
+
</script>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API Reference
|
|
82
|
+
|
|
83
|
+
### Constructor
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
new CloudSignalPWA(config: PWAConfig)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Config Options:**
|
|
90
|
+
|
|
91
|
+
| Option | Type | Required | Description |
|
|
92
|
+
|--------|------|----------|-------------|
|
|
93
|
+
| `organizationId` | string | Yes | CloudSignal organization UUID |
|
|
94
|
+
| `organizationSecret` | string | Yes | Organization secret key |
|
|
95
|
+
| `serviceId` | string | Yes | PWA service UUID |
|
|
96
|
+
| `serviceUrl` | string | No | Service URL (default: `https://pwa.cloudsignal.app`) |
|
|
97
|
+
| `debug` | boolean | No | Enable debug logging |
|
|
98
|
+
| `serviceWorker` | object | No | Service worker config |
|
|
99
|
+
| `heartbeat` | object | No | Heartbeat config |
|
|
100
|
+
|
|
101
|
+
### Initialization
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
// Initialize the PWA client
|
|
105
|
+
await pwa.initialize(): Promise<InitializeResult>
|
|
106
|
+
|
|
107
|
+
// Download service configuration
|
|
108
|
+
await pwa.downloadConfig(): Promise<PWAServiceConfig | null>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Installation
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// Show install prompt (Chrome/Edge)
|
|
115
|
+
await pwa.showInstallPrompt(): Promise<InstallResult>
|
|
116
|
+
|
|
117
|
+
// Check if PWA can be installed
|
|
118
|
+
pwa.canInstall(): boolean
|
|
119
|
+
|
|
120
|
+
// Check if PWA is already installed
|
|
121
|
+
pwa.isInstalled(): boolean
|
|
122
|
+
|
|
123
|
+
// Get installation state
|
|
124
|
+
pwa.getInstallationState(): InstallationState
|
|
125
|
+
|
|
126
|
+
// Get install steps for current platform
|
|
127
|
+
pwa.getInstallSteps(): string[]
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Push Notifications
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
// Register for push notifications
|
|
134
|
+
await pwa.registerForPush(options?: RegisterOptions): Promise<Registration | null>
|
|
135
|
+
|
|
136
|
+
// Unregister from push notifications
|
|
137
|
+
await pwa.unregisterFromPush(): Promise<boolean>
|
|
138
|
+
|
|
139
|
+
// Update notification preferences
|
|
140
|
+
await pwa.updatePreferences(prefs: NotificationPreferences): Promise<boolean>
|
|
141
|
+
|
|
142
|
+
// Check registration status
|
|
143
|
+
await pwa.checkRegistrationStatus(): Promise<RegistrationStatusResponse | null>
|
|
144
|
+
|
|
145
|
+
// Request notification permission
|
|
146
|
+
await pwa.requestPermission(): Promise<NotificationPermission>
|
|
147
|
+
|
|
148
|
+
// Check if registered
|
|
149
|
+
pwa.isRegistered(): boolean
|
|
150
|
+
|
|
151
|
+
// Get registration ID
|
|
152
|
+
pwa.getRegistrationId(): string | null
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Device Information
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Get comprehensive device info (35+ fields)
|
|
159
|
+
pwa.getDeviceInfo(): DeviceInfo
|
|
160
|
+
|
|
161
|
+
// Get PWA capabilities
|
|
162
|
+
pwa.getCapabilities(): PWACapabilities
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Heartbeat
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// Start heartbeat for online status tracking
|
|
169
|
+
pwa.startHeartbeat(): void
|
|
170
|
+
|
|
171
|
+
// Stop heartbeat
|
|
172
|
+
pwa.stopHeartbeat(): void
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Badge Management
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// Clear app badge
|
|
179
|
+
pwa.clearBadge(): void
|
|
180
|
+
|
|
181
|
+
// Set app badge count
|
|
182
|
+
pwa.setBadge(count: number): void
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Events
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Subscribe to events
|
|
189
|
+
pwa.on(event: PWAEvent, handler: (data) => void): void
|
|
190
|
+
|
|
191
|
+
// Unsubscribe from events
|
|
192
|
+
pwa.off(event: PWAEvent, handler: (data) => void): void
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Available Events:**
|
|
196
|
+
|
|
197
|
+
| Event | Description |
|
|
198
|
+
|-------|-------------|
|
|
199
|
+
| `install:available` | Install prompt is available |
|
|
200
|
+
| `install:accepted` | User accepted install |
|
|
201
|
+
| `install:dismissed` | User dismissed install |
|
|
202
|
+
| `install:completed` | PWA was installed |
|
|
203
|
+
| `push:registered` | Push registration successful |
|
|
204
|
+
| `push:unregistered` | Push unregistration successful |
|
|
205
|
+
| `push:error` | Push operation failed |
|
|
206
|
+
| `permission:denied` | Notification permission denied |
|
|
207
|
+
| `config:loaded` | Service config downloaded |
|
|
208
|
+
| `config:error` | Config download failed |
|
|
209
|
+
| `heartbeat:sent` | Heartbeat sent successfully |
|
|
210
|
+
| `heartbeat:error` | Heartbeat failed |
|
|
211
|
+
| `network:online` | Network came online |
|
|
212
|
+
| `network:offline` | Network went offline |
|
|
213
|
+
| `sw:registered` | Service worker registered |
|
|
214
|
+
| `sw:updated` | Service worker updated |
|
|
215
|
+
|
|
216
|
+
## Service Worker Setup
|
|
217
|
+
|
|
218
|
+
Copy the service worker to your app's root directory:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# If using npm
|
|
222
|
+
cp node_modules/@cloudsignal/pwa-sdk/dist/service-worker.js public/
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Or download from CDN:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
curl -o public/service-worker.js https://cdn.cloudsignal.io/service-worker.v1.0.0.js
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## PWA Manifest
|
|
232
|
+
|
|
233
|
+
Create a `manifest.json` in your app's root:
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"name": "Your App Name",
|
|
238
|
+
"short_name": "App",
|
|
239
|
+
"start_url": "/",
|
|
240
|
+
"display": "standalone",
|
|
241
|
+
"theme_color": "#000000",
|
|
242
|
+
"background_color": "#ffffff",
|
|
243
|
+
"icons": [
|
|
244
|
+
{
|
|
245
|
+
"src": "/icon-192x192.png",
|
|
246
|
+
"sizes": "192x192",
|
|
247
|
+
"type": "image/png"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"src": "/icon-512x512.png",
|
|
251
|
+
"sizes": "512x512",
|
|
252
|
+
"type": "image/png"
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Add to your HTML:
|
|
259
|
+
|
|
260
|
+
```html
|
|
261
|
+
<link rel="manifest" href="/manifest.json">
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Device Information
|
|
265
|
+
|
|
266
|
+
The SDK detects 35+ device attributes:
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
const info = pwa.getDeviceInfo()
|
|
270
|
+
|
|
271
|
+
// Operating System
|
|
272
|
+
info.os // 'iOS', 'Android', 'Windows', 'macOS', 'Linux'
|
|
273
|
+
info.osVersion // '17.2', '14.0', 'Windows 10/11'
|
|
274
|
+
|
|
275
|
+
// Device
|
|
276
|
+
info.deviceType // 'iPhone', 'iPad', 'Phone', 'Tablet', 'Desktop'
|
|
277
|
+
info.deviceModel // 'iPhone 15 Pro', 'Samsung Galaxy S24'
|
|
278
|
+
info.isMobile // true/false
|
|
279
|
+
info.isTablet // true/false
|
|
280
|
+
info.isDesktop // true/false
|
|
281
|
+
|
|
282
|
+
// Browser
|
|
283
|
+
info.browser // 'Chrome', 'Safari', 'Firefox', 'Edge'
|
|
284
|
+
info.browserVersion // '120.0.6099.43'
|
|
285
|
+
|
|
286
|
+
// PWA Capabilities
|
|
287
|
+
info.supportLevel // 'full', 'partial', 'basic', 'none'
|
|
288
|
+
info.hasPushManager // true/false
|
|
289
|
+
info.hasServiceWorker // true/false
|
|
290
|
+
info.hasBadgeAPI // true/false
|
|
291
|
+
info.notificationPermission // 'granted', 'denied', 'default'
|
|
292
|
+
|
|
293
|
+
// Network
|
|
294
|
+
info.isOnline // true/false
|
|
295
|
+
info.connectionType // '4g', '3g', '2g', 'unknown'
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Example: React Integration
|
|
299
|
+
|
|
300
|
+
```jsx
|
|
301
|
+
import { useEffect, useState } from 'react'
|
|
302
|
+
import { CloudSignalPWA } from '@cloudsignal/pwa-sdk'
|
|
303
|
+
|
|
304
|
+
const pwa = new CloudSignalPWA({
|
|
305
|
+
organizationId: process.env.REACT_APP_ORG_ID,
|
|
306
|
+
organizationSecret: process.env.REACT_APP_ORG_SECRET,
|
|
307
|
+
serviceId: process.env.REACT_APP_SERVICE_ID
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
function App() {
|
|
311
|
+
const [canInstall, setCanInstall] = useState(false)
|
|
312
|
+
const [isRegistered, setIsRegistered] = useState(false)
|
|
313
|
+
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
pwa.initialize().then(() => {
|
|
316
|
+
setCanInstall(pwa.canInstall())
|
|
317
|
+
setIsRegistered(pwa.isRegistered())
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
pwa.on('install:available', () => setCanInstall(true))
|
|
321
|
+
pwa.on('push:registered', () => setIsRegistered(true))
|
|
322
|
+
}, [])
|
|
323
|
+
|
|
324
|
+
const handleInstall = async () => {
|
|
325
|
+
const result = await pwa.showInstallPrompt()
|
|
326
|
+
if (result.accepted) {
|
|
327
|
+
setCanInstall(false)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const handleEnableNotifications = async () => {
|
|
332
|
+
const registration = await pwa.registerForPush({
|
|
333
|
+
userEmail: 'user@example.com'
|
|
334
|
+
})
|
|
335
|
+
if (registration) {
|
|
336
|
+
setIsRegistered(true)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<div>
|
|
342
|
+
{canInstall && (
|
|
343
|
+
<button onClick={handleInstall}>Install App</button>
|
|
344
|
+
)}
|
|
345
|
+
{!isRegistered && (
|
|
346
|
+
<button onClick={handleEnableNotifications}>
|
|
347
|
+
Enable Notifications
|
|
348
|
+
</button>
|
|
349
|
+
)}
|
|
350
|
+
</div>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Browser Support
|
|
356
|
+
|
|
357
|
+
| Browser | PWA Install | Push Notifications |
|
|
358
|
+
|---------|-------------|-------------------|
|
|
359
|
+
| Chrome | ✅ | ✅ |
|
|
360
|
+
| Edge | ✅ | ✅ |
|
|
361
|
+
| Firefox | ❌ | ✅ |
|
|
362
|
+
| Safari (macOS) | ❌ | ✅ (macOS 13+) |
|
|
363
|
+
| Safari (iOS) | Manual | ✅ (iOS 16.4+) |
|
|
364
|
+
| Samsung Internet | ✅ | ✅ |
|
|
365
|
+
|
|
366
|
+
## TypeScript
|
|
367
|
+
|
|
368
|
+
Full TypeScript support with exported types:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
import {
|
|
372
|
+
CloudSignalPWA,
|
|
373
|
+
PWAConfig,
|
|
374
|
+
DeviceInfo,
|
|
375
|
+
InstallationState,
|
|
376
|
+
Registration,
|
|
377
|
+
PWAEvent
|
|
378
|
+
} from '@cloudsignal/pwa-sdk'
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
MIT License - Copyright (c) 2024 CloudSignal
|