@geolonia/geonicdb-sdk 0.18.1 → 0.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/geonicdb-sdk",
3
- "version": "0.18.1",
3
+ "version": "0.19.0",
4
4
  "description": "GeonicDB JavaScript SDK — NGSI-LD Context Broker client for browser and Node.js",
5
5
  "main": "geonicdb.cjs",
6
6
  "module": "geonicdb.mjs",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "peerDependencies": {
49
49
  "react": "^18 || ^19",
50
- "@geolonia/embed": "^1.0.0"
50
+ "@geolonia/embed": "^1.0.0 || ^5.0.0"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "react": {
package/react/index.d.ts CHANGED
@@ -408,6 +408,20 @@ declare class EventEmitter {
408
408
  protected emit<K extends keyof GeonicDBEventMap>(event: K, data?: GeonicDBEventMap[K]): void;
409
409
  protected emit(event: string, data?: unknown): void;
410
410
  }
411
+ /** Options for `GeonicDB.subscribeWebPush()`. */
412
+ export interface WebPushSubscribeOptions {
413
+ /**
414
+ * VAPID public key (base64url). Auto-fetched from
415
+ * `GET /.well-known/webpush-vapid-key` when omitted.
416
+ */
417
+ applicationServerKey?: string;
418
+ /**
419
+ * Service worker registration to subscribe through. Defaults to
420
+ * `navigator.serviceWorker.ready` — the caller must have already
421
+ * registered a service worker (e.g. `navigator.serviceWorker.register('/sw.js')`).
422
+ */
423
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
424
+ }
411
425
  declare class GeonicDB extends EventEmitter {
412
426
  private _auth;
413
427
  private _ws;
@@ -594,6 +608,50 @@ declare class GeonicDB extends EventEmitter {
594
608
  isConnected(): boolean;
595
609
  /** Subscribe to entity events (can be called before or after connect). */
596
610
  subscribe(options?: SubscribeOptions): void;
611
+ /**
612
+ * Fetch the deployment's VAPID public key for Web Push subscriptions.
613
+ *
614
+ * Hits the unauthenticated discovery endpoint
615
+ * `GET /.well-known/webpush-vapid-key` directly (not via `request()`) —
616
+ * it needs no login/API key and predates any session setup. Throws
617
+ * `GeonicDBError` with `statusCode: 503` if the deployment has no VAPID
618
+ * keys configured (503 has no dedicated error class — see
619
+ * `createErrorFromResponse()` in `./errors`).
620
+ */
621
+ getWebPushVapidKey(): Promise<string>;
622
+ /**
623
+ * Subscribe the current browser to Web Push notifications (#3014).
624
+ *
625
+ * Reuses an existing subscription on the service worker registration if
626
+ * one is already active *and* still matches the resolved VAPID public key
627
+ * — otherwise (e.g. after the deployment rotated its VAPID keys) it
628
+ * unsubscribes the stale one and re-subscribes with the current key.
629
+ * Fetches the deployment's VAPID public key (unless `applicationServerKey`
630
+ * is given) and calls `PushManager.subscribe()`. Convert the result with
631
+ * `toNgsiv2WebPushNotification()` / `toNgsiLdWebPushEndpoint()` and create
632
+ * the NGSI subscription with `request('POST', ...)`.
633
+ *
634
+ * Browser-only — throws in environments without Service Worker + Push API
635
+ * support (e.g. Node.js).
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * await navigator.serviceWorker.register('/sw.js');
640
+ * const subscription = await db.subscribeWebPush();
641
+ * await db.request('POST', '/v2/subscriptions', {
642
+ * description: 'Web Push notification',
643
+ * subject: { entities: [{ type: 'Sensor' }], condition: { attrs: ['value'] } },
644
+ * notification: { webpush: toNgsiv2WebPushNotification(subscription) },
645
+ * });
646
+ * ```
647
+ */
648
+ subscribeWebPush(options?: WebPushSubscribeOptions): Promise<PushSubscription>;
649
+ /**
650
+ * Unsubscribe the current browser from Web Push notifications, if
651
+ * subscribed. Returns `false` (no-op) when there is no active
652
+ * subscription or the environment has no Service Worker support.
653
+ */
654
+ unsubscribeWebPush(registration?: ServiceWorkerRegistration): Promise<boolean>;
597
655
  }
598
656
  /**
599
657
  * NGSI-LD and GeoJSON types for the ./react subpath.