een-api-toolkit 0.3.15 → 0.3.20

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 (41) hide show
  1. package/CHANGELOG.md +45 -6
  2. package/README.md +1 -0
  3. package/dist/index.cjs +3 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +585 -0
  6. package/dist/index.js +485 -261
  7. package/dist/index.js.map +1 -1
  8. package/docs/AI-CONTEXT.md +144 -1
  9. package/examples/vue-alerts-metrics/e2e/auth.spec.ts +8 -1
  10. package/examples/vue-alerts-metrics/package-lock.json +8 -1
  11. package/examples/vue-alerts-metrics/package.json +4 -3
  12. package/examples/vue-alerts-metrics/src/components/AlertsList.vue +567 -16
  13. package/examples/vue-alerts-metrics/src/components/CameraSelector.vue +16 -6
  14. package/examples/vue-alerts-metrics/src/components/MetricsChart.vue +23 -9
  15. package/examples/vue-alerts-metrics/src/components/NotificationsList.vue +579 -17
  16. package/examples/vue-alerts-metrics/src/components/TimeRangeSelector.vue +197 -12
  17. package/examples/vue-alerts-metrics/src/composables/useHlsPlayer.ts +285 -0
  18. package/examples/vue-alerts-metrics/src/views/Dashboard.vue +31 -9
  19. package/examples/vue-alerts-metrics/src/views/Home.vue +56 -7
  20. package/examples/vue-event-subscriptions/.env.example +15 -0
  21. package/examples/vue-event-subscriptions/README.md +103 -0
  22. package/examples/vue-event-subscriptions/e2e/app.spec.ts +71 -0
  23. package/examples/vue-event-subscriptions/e2e/auth.spec.ts +290 -0
  24. package/examples/vue-event-subscriptions/index.html +13 -0
  25. package/examples/vue-event-subscriptions/package-lock.json +1719 -0
  26. package/examples/vue-event-subscriptions/package.json +28 -0
  27. package/examples/vue-event-subscriptions/playwright.config.ts +47 -0
  28. package/examples/vue-event-subscriptions/src/App.vue +233 -0
  29. package/examples/vue-event-subscriptions/src/main.ts +25 -0
  30. package/examples/vue-event-subscriptions/src/router/index.ts +68 -0
  31. package/examples/vue-event-subscriptions/src/views/Callback.vue +76 -0
  32. package/examples/vue-event-subscriptions/src/views/Home.vue +192 -0
  33. package/examples/vue-event-subscriptions/src/views/LiveEvents.vue +640 -0
  34. package/examples/vue-event-subscriptions/src/views/Login.vue +33 -0
  35. package/examples/vue-event-subscriptions/src/views/Logout.vue +59 -0
  36. package/examples/vue-event-subscriptions/src/views/Subscriptions.vue +402 -0
  37. package/examples/vue-event-subscriptions/src/vite-env.d.ts +12 -0
  38. package/examples/vue-event-subscriptions/tsconfig.json +21 -0
  39. package/examples/vue-event-subscriptions/tsconfig.node.json +10 -0
  40. package/examples/vue-event-subscriptions/vite.config.ts +12 -0
  41. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  # EEN API Toolkit - AI Reference
2
2
 
3
- > **Version:** 0.3.15
3
+ > **Version:** 0.3.20
4
4
  >
5
5
  > This file is optimized for AI assistants. It contains all API signatures,
6
6
  > types, and usage patterns in a single, parseable document.
@@ -214,6 +214,7 @@ Complete Vue 3 applications demonstrating toolkit features:
214
214
  | [vue-feeds](../examples/vue-feeds/) | Live video streaming (preview and main) | `src/views/Feeds.vue` |
215
215
  | [vue-events](../examples/vue-events/) | Events with bounding box overlays | `src/components/EventsModal.vue` |
216
216
  | [vue-alerts-metrics](../examples/vue-alerts-metrics/) | Event metrics, alerts, and notifications | `src/components/MetricsChart.vue`, `AlertsList.vue` |
217
+ | [vue-event-subscriptions](../examples/vue-event-subscriptions/) | Real-time event streaming with SSE | `src/views/Subscriptions.vue`, `LiveEvents.vue` |
217
218
 
218
219
  ### Configuration
219
220
 
@@ -293,6 +294,22 @@ Complete Vue 3 applications demonstrating toolkit features:
293
294
  | `listNotifications(params?)` | List notifications with filters | `Result<PaginatedResult<Notification>>` |
294
295
  | `getNotification(id)` | Get a specific notification by ID | `Result<Notification>` |
295
296
 
297
+ ### EventSubscriptions Functions
298
+
299
+ | Function | Purpose | Returns |
300
+ |----------|---------|---------|
301
+ | `listEventSubscriptions(params?)` | List all event subscriptions | `Result<PaginatedResult<EventSubscription>>` |
302
+ | `getEventSubscription(id)` | Get a specific subscription by ID | `Result<EventSubscription>` |
303
+ | `createEventSubscription(params)` | Create a new event subscription | `Result<EventSubscription>` |
304
+ | `deleteEventSubscription(id)` | Delete an event subscription | `Result<void>` |
305
+ | `connectToEventSubscription(sseUrl, options)` | Connect to SSE stream for real-time events | `Result<SSEConnection>` |
306
+
307
+ ### Utility Functions
308
+
309
+ | Function | Purpose | Returns |
310
+ |----------|---------|---------|
311
+ | `formatTimestamp(timestamp)` | Convert ISO timestamp from Z to +00:00 format (required by EEN API) | `string` |
312
+
296
313
  ---
297
314
 
298
315
  ## Core Types
@@ -1275,6 +1292,40 @@ console.log('Session URL:', data.url)
1275
1292
 
1276
1293
  ---
1277
1294
 
1295
+ ## Utilities
1296
+
1297
+ ### formatTimestamp
1298
+
1299
+ Converts ISO 8601 timestamps from `Z` (Zulu/UTC) format to `+00:00` format, as required by the EEN API.
1300
+
1301
+ **Why this is needed:** JavaScript's `Date.toISOString()` returns timestamps with a `Z` suffix (e.g., `2025-01-15T22:30:00.000Z`), but the EEN API requires the `+00:00` format (e.g., `2025-01-15T22:30:00.000+00:00`).
1302
+
1303
+ ```typescript
1304
+ import { formatTimestamp } from 'een-api-toolkit'
1305
+
1306
+ // Convert Z format to +00:00 format
1307
+ formatTimestamp('2025-01-15T22:30:00.000Z')
1308
+ // Returns: '2025-01-15T22:30:00.000+00:00'
1309
+
1310
+ // Already in +00:00 format - returns unchanged
1311
+ formatTimestamp('2025-01-15T22:30:00.000+00:00')
1312
+ // Returns: '2025-01-15T22:30:00.000+00:00'
1313
+
1314
+ // Common usage with Date objects
1315
+ const now = new Date()
1316
+ const apiTimestamp = formatTimestamp(now.toISOString())
1317
+ // Returns timestamp in EEN API format
1318
+ ```
1319
+
1320
+ **When to use:**
1321
+ - When displaying timestamps that match the exact format used in API calls (e.g., for debugging)
1322
+ - When making direct API calls outside of the toolkit
1323
+ - When building custom timestamp display components
1324
+
1325
+ **Note:** The toolkit's API functions (`listAlerts`, `getEventMetrics`, `listNotifications`, `listEvents`, etc.) automatically apply `formatTimestamp` internally, so you don't need to pre-format timestamps when using these functions.
1326
+
1327
+ ---
1328
+
1278
1329
  ## Live Video Streaming
1279
1330
 
1280
1331
  The EEN API Toolkit supports two methods for displaying live video from cameras:
@@ -1525,6 +1576,98 @@ video {
1525
1576
 
1526
1577
  ---
1527
1578
 
1579
+ ## HLS Video Playback Troubleshooting
1580
+
1581
+ For detailed troubleshooting, see the [HLS Video Troubleshooting Guide](./guides/HLS-VIDEO-TROUBLESHOOTING.md).
1582
+
1583
+ ### Overview
1584
+
1585
+ HLS video playback from the EEN API requires:
1586
+
1587
+ 1. **Initialize media session** - `initMediaSession()`
1588
+ 2. **Find recording intervals** - `listMedia()` with `include: ['hlsUrl']`
1589
+ 3. **Extract HLS URL** - From interval containing target timestamp
1590
+ 4. **Configure HLS.js with auth** - Bearer token in Authorization header
1591
+
1592
+ ### Key Requirements
1593
+
1594
+ | Requirement | Details |
1595
+ |-------------|---------|
1596
+ | Feed Type | HLS only available for `main` feeds, not `preview` |
1597
+ | Timestamp Format | Use `formatTimestamp()` to convert `Z` to `+00:00` |
1598
+ | Authentication | HLS.js requires `xhr.setRequestHeader('Authorization', `Bearer ${token}`)` |
1599
+ | Recording Coverage | Target timestamp must fall within a recording interval |
1600
+
1601
+ ### Common Issues
1602
+
1603
+ #### 401 Unauthorized
1604
+
1605
+ **Cause:** Using `withCredentials: true` instead of Authorization header.
1606
+
1607
+ ```typescript
1608
+ // WRONG
1609
+ const hls = new Hls({
1610
+ xhrSetup: (xhr) => { xhr.withCredentials = true }
1611
+ })
1612
+
1613
+ // CORRECT
1614
+ import { useAuthStore } from 'een-api-toolkit'
1615
+ const authStore = useAuthStore()
1616
+
1617
+ const hls = new Hls({
1618
+ xhrSetup: (xhr) => {
1619
+ xhr.setRequestHeader('Authorization', `Bearer ${authStore.token}`)
1620
+ }
1621
+ })
1622
+ ```
1623
+
1624
+ #### No Video Available for Timestamp
1625
+
1626
+ **Cause:** Search range too narrow or using wrong feed type.
1627
+
1628
+ ```typescript
1629
+ import { listMedia, formatTimestamp } from 'een-api-toolkit'
1630
+
1631
+ const targetTime = new Date(alertTimestamp)
1632
+ const searchStart = new Date(targetTime.getTime() - 60 * 60 * 1000) // 1 hour before
1633
+ const searchEnd = new Date(targetTime.getTime() + 60 * 60 * 1000) // 1 hour after
1634
+
1635
+ const result = await listMedia({
1636
+ deviceId: cameraId,
1637
+ type: 'main', // MUST be 'main' for HLS
1638
+ mediaType: 'video',
1639
+ startTimestamp: formatTimestamp(searchStart.toISOString()),
1640
+ endTimestamp: formatTimestamp(searchEnd.toISOString()),
1641
+ include: ['hlsUrl'] // MUST include 'hlsUrl'
1642
+ })
1643
+
1644
+ // Find interval containing target timestamp
1645
+ const intervals = result.data?.results ?? []
1646
+ const targetTimeMs = targetTime.getTime()
1647
+
1648
+ const matchingInterval = intervals.find(i => {
1649
+ if (!i.hlsUrl) return false
1650
+ const start = new Date(i.startTimestamp).getTime()
1651
+ const end = new Date(i.endTimestamp).getTime()
1652
+ return targetTimeMs >= start && targetTimeMs <= end
1653
+ })
1654
+ ```
1655
+
1656
+ #### Timestamp Format Error
1657
+
1658
+ **Cause:** Using `Z` suffix instead of `+00:00`.
1659
+
1660
+ ```typescript
1661
+ // WRONG
1662
+ const timestamp = new Date().toISOString() // "2025-01-15T22:30:00.000Z"
1663
+
1664
+ // CORRECT
1665
+ import { formatTimestamp } from 'een-api-toolkit'
1666
+ const timestamp = formatTimestamp(new Date().toISOString()) // "2025-01-15T22:30:00.000+00:00"
1667
+ ```
1668
+
1669
+ ---
1670
+
1528
1671
  ## Common Patterns
1529
1672
 
1530
1673
  ### Error Handling
@@ -283,14 +283,21 @@ test.describe('Vue Alerts & Metrics Example - Auth', () => {
283
283
  await expect(page.locator('[data-testid="dashboard-container"]')).toBeVisible({ timeout: TIMEOUTS.UI_UPDATE })
284
284
 
285
285
  // Test time range buttons
286
+ const buttonNone = page.locator('[data-testid="time-range-none"]')
286
287
  const button1h = page.locator('[data-testid="time-range-1h"]')
287
288
  const button24h = page.locator('[data-testid="time-range-24h"]')
288
289
 
290
+ await expect(buttonNone).toBeVisible()
289
291
  await expect(button1h).toBeVisible()
290
292
  await expect(button24h).toBeVisible()
291
293
 
292
- // 24h should be active by default
294
+ // 'None' should be active by default
295
+ await expect(buttonNone).toHaveClass(/active/)
296
+
297
+ // Click 24h and verify it becomes active
298
+ await button24h.click()
293
299
  await expect(button24h).toHaveClass(/active/)
300
+ await expect(buttonNone).not.toHaveClass(/active/)
294
301
 
295
302
  // Click 1h and verify it becomes active
296
303
  await button1h.click()
@@ -10,6 +10,7 @@
10
10
  "dependencies": {
11
11
  "chart.js": "^4.4.0",
12
12
  "een-api-toolkit": "file:../..",
13
+ "hls.js": "^1.6.15",
13
14
  "pinia": "^3.0.4",
14
15
  "vue": "^3.4.0",
15
16
  "vue-chartjs": "^5.3.0",
@@ -25,7 +26,7 @@
25
26
  }
26
27
  },
27
28
  "../..": {
28
- "version": "0.3.14",
29
+ "version": "0.3.15",
29
30
  "license": "MIT",
30
31
  "devDependencies": {
31
32
  "@eslint/js": "^9.39.2",
@@ -1296,6 +1297,12 @@
1296
1297
  "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
1297
1298
  }
1298
1299
  },
1300
+ "node_modules/hls.js": {
1301
+ "version": "1.6.15",
1302
+ "resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.6.15.tgz",
1303
+ "integrity": "sha512-E3a5VwgXimGHwpRGV+WxRTKeSp2DW5DI5MWv34ulL3t5UNmyJWCQ1KmLEHbYzcfThfXG8amBL+fCYPneGHC4VA==",
1304
+ "license": "Apache-2.0"
1305
+ },
1299
1306
  "node_modules/hookable": {
1300
1307
  "version": "5.5.3",
1301
1308
  "resolved": "https://registry.npmjs.org/hookable/-/hookable-5.5.3.tgz",
@@ -12,12 +12,13 @@
12
12
  "test:e2e:ui": "playwright test --ui"
13
13
  },
14
14
  "dependencies": {
15
+ "chart.js": "^4.4.0",
15
16
  "een-api-toolkit": "file:../..",
17
+ "hls.js": "^1.6.15",
16
18
  "pinia": "^3.0.4",
17
19
  "vue": "^3.4.0",
18
- "vue-router": "^4.2.0",
19
- "chart.js": "^4.4.0",
20
- "vue-chartjs": "^5.3.0"
20
+ "vue-chartjs": "^5.3.0",
21
+ "vue-router": "^4.2.0"
21
22
  },
22
23
  "devDependencies": {
23
24
  "@playwright/test": "^1.57.0",