@cloudparse/up-miniapps-sdk 0.6.1 → 0.6.2

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/dist/index.d.cts CHANGED
@@ -1614,6 +1614,15 @@ interface WsMessage {
1614
1614
  event?: string;
1615
1615
  [key: string]: unknown;
1616
1616
  }
1617
+ /**
1618
+ * `"open"` is the only state where the wire connection is actually live —
1619
+ * `"connecting"` covers both the initial handshake and every reconnect
1620
+ * backoff wait, `"closed"` covers not-yet-started and lost-and-not-yet-
1621
+ * retried. A consumer that wants a poll-based fallback (only meaningful
1622
+ * while genuinely disconnected) should treat anything other than `"open"`
1623
+ * as "poll".
1624
+ */
1625
+ type WsConnectionStatus = "connecting" | "open" | "closed";
1617
1626
  interface BaseWsServiceOptions<TMessage extends WsMessage> {
1618
1627
  /**
1619
1628
  * The REST client from `createApiService` — reused here for two things:
@@ -1720,6 +1729,21 @@ interface WsServiceClient<TMessage extends WsMessage = WsMessage> {
1720
1729
  * function.
1721
1730
  */
1722
1731
  onMessage(callback: (message: TMessage) => void): () => void;
1732
+ /**
1733
+ * Current connection status, read synchronously — no subscription needed
1734
+ * for a one-off check.
1735
+ */
1736
+ getStatus(): WsConnectionStatus;
1737
+ /**
1738
+ * Subscribes to connection status transitions. Fires once immediately
1739
+ * with the current status on subscribe, then again on every change.
1740
+ * Returns an unsubscribe function. Intended for a consumer that wants a
1741
+ * poll-based fallback only while genuinely disconnected (see
1742
+ * `WsConnectionStatus`'s own doc comment) — driving that off `onMessage`
1743
+ * pings alone can't distinguish "connected but quiet" from "never
1744
+ * connected".
1745
+ */
1746
+ onStatusChange(callback: (status: WsConnectionStatus) => void): () => void;
1723
1747
  }
1724
1748
  interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1725
1749
  /** Opens the connection if not already open/connecting. Safe to call repeatedly. */
@@ -1733,6 +1757,10 @@ interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1733
1757
  * client. Implicitly calls `connect()`. Returns an unsubscribe function.
1734
1758
  */
1735
1759
  onMessage(callback: (message: TMessage) => void): () => void;
1760
+ /** Current connection status, read synchronously. See `WsConnectionStatus`. */
1761
+ getStatus(): WsConnectionStatus;
1762
+ /** Subscribes to connection status transitions. See `WsServiceClient.onStatusChange`. */
1763
+ onStatusChange(callback: (status: WsConnectionStatus) => void): () => void;
1736
1764
  }
1737
1765
  /**
1738
1766
  * Creates a reconnecting, (usually) authenticated WebSocket client — the WS
@@ -1769,4 +1797,4 @@ interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1769
1797
  declare function createWsService<TMessage extends WsMessage = WsMessage>(options: CreateChannelWsServiceOptions<TMessage>): WsServiceClient<TMessage>;
1770
1798
  declare function createWsService<TMessage extends WsMessage = WsMessage>(options: CreateBroadcastWsServiceOptions<TMessage>): BroadcastWsServiceClient<TMessage>;
1771
1799
 
1772
- export { type ApiServiceClient, type BridgeMessageType, BridgeMocker, type BridgeMockerProps, type BroadcastWsServiceClient, type CenterCallbackParams, type CreateApiServiceOptions, type CreateBroadcastWsServiceOptions, type CreateChannelWsServiceOptions, type CreateWsServiceOptions, type CustomControl, DebugConsole, type DebugConsoleProps, type DeclarativeJourneyOptions, type DrawerState, type EtaData, type FidelityTransactionTypeType, type FlyToParams, GeolocationEvent, GlobalEvent, type HapticStyleType, type IBridgeEnvelope, type IContextState, type IEdgeInsets, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IGenerateQrCodeOptions, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IPickImageResult, type ISaveImageResult, type IUserProfile, type LiveRoutingOptions, type LiveRoutingResult, type LocationStreamConfig, Map, MapControls, MapControlsContext, type MapControlsProps, type MapControlsState, type MapInsets, MapMenu, MapMenuDivider, type MapMenuDividerProps, MapMenuFooter, type MapMenuFooterProps, MapMenuItem, type MapMenuItemProps, type MapMenuProps, MapMenuTitle, type MapMenuTitleProps, type MapProps, type MenuItem, MiniAppSDK, MockLocationContext, type MockLocationContextType, type NetworkMethodType, type POI, QRScanner, type QRScannerProps, RouteLayer, type RouteLayerProps, RouteRequest, RouteResponse, RouteStep, type SDKEvent, SDKMapProvider, SDKProvider, type SDKProviderProps, type ScrollConfig, type StreamAccelerometerData, type StreamHeadingData, type StreamLocationData, type StreamUpdatePayload, type SwipeAxisPriority, SwipeCarousel, type SwipeCarouselItem, type SwipeCarouselProps, type SwipeCarouselVerticalDragConfig, UIEvent, type UseJourneyOptions, type UseJourneyResult, type UserLocationState, type WsMessage, type WsServiceClient, createApiService, createWsService, sdk as default, renderMap, sdk, useIsMocked, useJourney, useLiveRouting, useMapControls, useMockLocation, useRoute, useTrimmedRoute, useUserLocation };
1800
+ export { type ApiServiceClient, type BridgeMessageType, BridgeMocker, type BridgeMockerProps, type BroadcastWsServiceClient, type CenterCallbackParams, type CreateApiServiceOptions, type CreateBroadcastWsServiceOptions, type CreateChannelWsServiceOptions, type CreateWsServiceOptions, type CustomControl, DebugConsole, type DebugConsoleProps, type DeclarativeJourneyOptions, type DrawerState, type EtaData, type FidelityTransactionTypeType, type FlyToParams, GeolocationEvent, GlobalEvent, type HapticStyleType, type IBridgeEnvelope, type IContextState, type IEdgeInsets, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IGenerateQrCodeOptions, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IPickImageResult, type ISaveImageResult, type IUserProfile, type LiveRoutingOptions, type LiveRoutingResult, type LocationStreamConfig, Map, MapControls, MapControlsContext, type MapControlsProps, type MapControlsState, type MapInsets, MapMenu, MapMenuDivider, type MapMenuDividerProps, MapMenuFooter, type MapMenuFooterProps, MapMenuItem, type MapMenuItemProps, type MapMenuProps, MapMenuTitle, type MapMenuTitleProps, type MapProps, type MenuItem, MiniAppSDK, MockLocationContext, type MockLocationContextType, type NetworkMethodType, type POI, QRScanner, type QRScannerProps, RouteLayer, type RouteLayerProps, RouteRequest, RouteResponse, RouteStep, type SDKEvent, SDKMapProvider, SDKProvider, type SDKProviderProps, type ScrollConfig, type StreamAccelerometerData, type StreamHeadingData, type StreamLocationData, type StreamUpdatePayload, type SwipeAxisPriority, SwipeCarousel, type SwipeCarouselItem, type SwipeCarouselProps, type SwipeCarouselVerticalDragConfig, UIEvent, type UseJourneyOptions, type UseJourneyResult, type UserLocationState, type WsConnectionStatus, type WsMessage, type WsServiceClient, createApiService, createWsService, sdk as default, renderMap, sdk, useIsMocked, useJourney, useLiveRouting, useMapControls, useMockLocation, useRoute, useTrimmedRoute, useUserLocation };
package/dist/index.d.ts CHANGED
@@ -1614,6 +1614,15 @@ interface WsMessage {
1614
1614
  event?: string;
1615
1615
  [key: string]: unknown;
1616
1616
  }
1617
+ /**
1618
+ * `"open"` is the only state where the wire connection is actually live —
1619
+ * `"connecting"` covers both the initial handshake and every reconnect
1620
+ * backoff wait, `"closed"` covers not-yet-started and lost-and-not-yet-
1621
+ * retried. A consumer that wants a poll-based fallback (only meaningful
1622
+ * while genuinely disconnected) should treat anything other than `"open"`
1623
+ * as "poll".
1624
+ */
1625
+ type WsConnectionStatus = "connecting" | "open" | "closed";
1617
1626
  interface BaseWsServiceOptions<TMessage extends WsMessage> {
1618
1627
  /**
1619
1628
  * The REST client from `createApiService` — reused here for two things:
@@ -1720,6 +1729,21 @@ interface WsServiceClient<TMessage extends WsMessage = WsMessage> {
1720
1729
  * function.
1721
1730
  */
1722
1731
  onMessage(callback: (message: TMessage) => void): () => void;
1732
+ /**
1733
+ * Current connection status, read synchronously — no subscription needed
1734
+ * for a one-off check.
1735
+ */
1736
+ getStatus(): WsConnectionStatus;
1737
+ /**
1738
+ * Subscribes to connection status transitions. Fires once immediately
1739
+ * with the current status on subscribe, then again on every change.
1740
+ * Returns an unsubscribe function. Intended for a consumer that wants a
1741
+ * poll-based fallback only while genuinely disconnected (see
1742
+ * `WsConnectionStatus`'s own doc comment) — driving that off `onMessage`
1743
+ * pings alone can't distinguish "connected but quiet" from "never
1744
+ * connected".
1745
+ */
1746
+ onStatusChange(callback: (status: WsConnectionStatus) => void): () => void;
1723
1747
  }
1724
1748
  interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1725
1749
  /** Opens the connection if not already open/connecting. Safe to call repeatedly. */
@@ -1733,6 +1757,10 @@ interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1733
1757
  * client. Implicitly calls `connect()`. Returns an unsubscribe function.
1734
1758
  */
1735
1759
  onMessage(callback: (message: TMessage) => void): () => void;
1760
+ /** Current connection status, read synchronously. See `WsConnectionStatus`. */
1761
+ getStatus(): WsConnectionStatus;
1762
+ /** Subscribes to connection status transitions. See `WsServiceClient.onStatusChange`. */
1763
+ onStatusChange(callback: (status: WsConnectionStatus) => void): () => void;
1736
1764
  }
1737
1765
  /**
1738
1766
  * Creates a reconnecting, (usually) authenticated WebSocket client — the WS
@@ -1769,4 +1797,4 @@ interface BroadcastWsServiceClient<TMessage extends WsMessage = WsMessage> {
1769
1797
  declare function createWsService<TMessage extends WsMessage = WsMessage>(options: CreateChannelWsServiceOptions<TMessage>): WsServiceClient<TMessage>;
1770
1798
  declare function createWsService<TMessage extends WsMessage = WsMessage>(options: CreateBroadcastWsServiceOptions<TMessage>): BroadcastWsServiceClient<TMessage>;
1771
1799
 
1772
- export { type ApiServiceClient, type BridgeMessageType, BridgeMocker, type BridgeMockerProps, type BroadcastWsServiceClient, type CenterCallbackParams, type CreateApiServiceOptions, type CreateBroadcastWsServiceOptions, type CreateChannelWsServiceOptions, type CreateWsServiceOptions, type CustomControl, DebugConsole, type DebugConsoleProps, type DeclarativeJourneyOptions, type DrawerState, type EtaData, type FidelityTransactionTypeType, type FlyToParams, GeolocationEvent, GlobalEvent, type HapticStyleType, type IBridgeEnvelope, type IContextState, type IEdgeInsets, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IGenerateQrCodeOptions, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IPickImageResult, type ISaveImageResult, type IUserProfile, type LiveRoutingOptions, type LiveRoutingResult, type LocationStreamConfig, Map, MapControls, MapControlsContext, type MapControlsProps, type MapControlsState, type MapInsets, MapMenu, MapMenuDivider, type MapMenuDividerProps, MapMenuFooter, type MapMenuFooterProps, MapMenuItem, type MapMenuItemProps, type MapMenuProps, MapMenuTitle, type MapMenuTitleProps, type MapProps, type MenuItem, MiniAppSDK, MockLocationContext, type MockLocationContextType, type NetworkMethodType, type POI, QRScanner, type QRScannerProps, RouteLayer, type RouteLayerProps, RouteRequest, RouteResponse, RouteStep, type SDKEvent, SDKMapProvider, SDKProvider, type SDKProviderProps, type ScrollConfig, type StreamAccelerometerData, type StreamHeadingData, type StreamLocationData, type StreamUpdatePayload, type SwipeAxisPriority, SwipeCarousel, type SwipeCarouselItem, type SwipeCarouselProps, type SwipeCarouselVerticalDragConfig, UIEvent, type UseJourneyOptions, type UseJourneyResult, type UserLocationState, type WsMessage, type WsServiceClient, createApiService, createWsService, sdk as default, renderMap, sdk, useIsMocked, useJourney, useLiveRouting, useMapControls, useMockLocation, useRoute, useTrimmedRoute, useUserLocation };
1800
+ export { type ApiServiceClient, type BridgeMessageType, BridgeMocker, type BridgeMockerProps, type BroadcastWsServiceClient, type CenterCallbackParams, type CreateApiServiceOptions, type CreateBroadcastWsServiceOptions, type CreateChannelWsServiceOptions, type CreateWsServiceOptions, type CustomControl, DebugConsole, type DebugConsoleProps, type DeclarativeJourneyOptions, type DrawerState, type EtaData, type FidelityTransactionTypeType, type FlyToParams, GeolocationEvent, GlobalEvent, type HapticStyleType, type IBridgeEnvelope, type IContextState, type IEdgeInsets, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IGenerateQrCodeOptions, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IPickImageResult, type ISaveImageResult, type IUserProfile, type LiveRoutingOptions, type LiveRoutingResult, type LocationStreamConfig, Map, MapControls, MapControlsContext, type MapControlsProps, type MapControlsState, type MapInsets, MapMenu, MapMenuDivider, type MapMenuDividerProps, MapMenuFooter, type MapMenuFooterProps, MapMenuItem, type MapMenuItemProps, type MapMenuProps, MapMenuTitle, type MapMenuTitleProps, type MapProps, type MenuItem, MiniAppSDK, MockLocationContext, type MockLocationContextType, type NetworkMethodType, type POI, QRScanner, type QRScannerProps, RouteLayer, type RouteLayerProps, RouteRequest, RouteResponse, RouteStep, type SDKEvent, SDKMapProvider, SDKProvider, type SDKProviderProps, type ScrollConfig, type StreamAccelerometerData, type StreamHeadingData, type StreamLocationData, type StreamUpdatePayload, type SwipeAxisPriority, SwipeCarousel, type SwipeCarouselItem, type SwipeCarouselProps, type SwipeCarouselVerticalDragConfig, UIEvent, type UseJourneyOptions, type UseJourneyResult, type UserLocationState, type WsConnectionStatus, type WsMessage, type WsServiceClient, createApiService, createWsService, sdk as default, renderMap, sdk, useIsMocked, useJourney, useLiveRouting, useMapControls, useMockLocation, useRoute, useTrimmedRoute, useUserLocation };
package/dist/index.js CHANGED
@@ -3487,7 +3487,7 @@ var loadImage2 = (src) => new Promise((resolve, reject) => {
3487
3487
  });
3488
3488
 
3489
3489
  // package.json
3490
- var version = "0.6.1";
3490
+ var version = "0.6.2";
3491
3491
 
3492
3492
  // src/sdk.ts
3493
3493
  function deepFreeze(obj) {
@@ -5093,6 +5093,13 @@ function createWsService(options) {
5093
5093
  let reconnectTimeout = null;
5094
5094
  let reconnectDelay = 1e3;
5095
5095
  let isConnecting = false;
5096
+ let status = "closed";
5097
+ const statusListeners = /* @__PURE__ */ new Set();
5098
+ const setStatus = (next) => {
5099
+ if (status === next) return;
5100
+ status = next;
5101
+ for (const cb of statusListeners) cb(status);
5102
+ };
5096
5103
  const getWsUrl = () => options.baseUrl || options.api.wsUrl || "";
5097
5104
  const sendAction = (action, channelId) => {
5098
5105
  if (ws?.readyState === WebSocket.OPEN) {
@@ -5111,6 +5118,7 @@ function createWsService(options) {
5111
5118
  return;
5112
5119
  }
5113
5120
  isConnecting = true;
5121
+ setStatus("connecting");
5114
5122
  try {
5115
5123
  const wsUrl = getWsUrl();
5116
5124
  if (!wsUrl) {
@@ -5118,6 +5126,7 @@ function createWsService(options) {
5118
5126
  "[WS] No WebSocket backend URL available, connection delayed."
5119
5127
  );
5120
5128
  isConnecting = false;
5129
+ setStatus("closed");
5121
5130
  return;
5122
5131
  }
5123
5132
  let authParams = {};
@@ -5133,6 +5142,7 @@ function createWsService(options) {
5133
5142
  } else {
5134
5143
  console.warn("[WS] No auth available, connection delayed.");
5135
5144
  isConnecting = false;
5145
+ setStatus("closed");
5136
5146
  return;
5137
5147
  }
5138
5148
  const params = new URLSearchParams({ ...options.query, ...authParams });
@@ -5140,6 +5150,7 @@ function createWsService(options) {
5140
5150
  ws = new WebSocket(query ? `${wsUrl}?${query}` : wsUrl);
5141
5151
  ws.onopen = () => {
5142
5152
  isConnecting = false;
5153
+ setStatus("open");
5143
5154
  reconnectDelay = 1e3;
5144
5155
  if (channelField) {
5145
5156
  for (const channelId of subscriptions.keys()) {
@@ -5166,6 +5177,7 @@ function createWsService(options) {
5166
5177
  };
5167
5178
  ws.onclose = () => {
5168
5179
  isConnecting = false;
5180
+ setStatus("closed");
5169
5181
  scheduleReconnect();
5170
5182
  };
5171
5183
  ws.onerror = (err) => {
@@ -5176,6 +5188,7 @@ function createWsService(options) {
5176
5188
  } catch (err) {
5177
5189
  console.error("[WS] Failed to establish connection:", err);
5178
5190
  isConnecting = false;
5191
+ setStatus("closed");
5179
5192
  scheduleReconnect();
5180
5193
  }
5181
5194
  };
@@ -5189,6 +5202,15 @@ function createWsService(options) {
5189
5202
  ws.close();
5190
5203
  ws = null;
5191
5204
  }
5205
+ setStatus("closed");
5206
+ };
5207
+ const getStatus = () => status;
5208
+ const onStatusChange = (callback) => {
5209
+ statusListeners.add(callback);
5210
+ callback(status);
5211
+ return () => {
5212
+ statusListeners.delete(callback);
5213
+ };
5192
5214
  };
5193
5215
  const subscribe = (channelId, callback) => {
5194
5216
  const isNewChannel = !subscriptions.has(channelId);
@@ -5214,9 +5236,9 @@ function createWsService(options) {
5214
5236
  };
5215
5237
  };
5216
5238
  if (channelField) {
5217
- return { connect, disconnect, onMessage, subscribe };
5239
+ return { connect, disconnect, onMessage, subscribe, getStatus, onStatusChange };
5218
5240
  }
5219
- return { connect, disconnect, onMessage };
5241
+ return { connect, disconnect, onMessage, getStatus, onStatusChange };
5220
5242
  }
5221
5243
 
5222
5244
  // src/index.ts