@cloudparse/up-miniapps-sdk 0.1.6 → 0.2.1

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.ts CHANGED
@@ -1,3 +1,50 @@
1
+ import React from 'react';
2
+ import { R as RouteResponse, a as RouteStep, b as RouteRequest, c as RoutingBackendConfig } from './index-B9dDciJq.js';
3
+ export { C as ClearRouteRequest, D as DrawRouteRequest, h as handleClearRoute, d as handleDrawRoute, e as handleRouteRequest } from './index-B9dDciJq.js';
4
+ import { ViewState } from '@vis.gl/react-maplibre';
5
+ import * as react_dom_client from 'react-dom/client';
6
+ import 'maplibre-gl';
7
+
8
+ interface BridgeMockerProps {
9
+ /** Optional appId to return in INITIALIZE response */
10
+ appId?: string;
11
+ /** Initial simulated location [lng, lat] */
12
+ initialLocation?: [number, number];
13
+ /** Whether the simulated user should be moving */
14
+ isMoving?: boolean;
15
+ /** An array of coordinates to follow. If provided, overrides random movement. */
16
+ simulationPath?: [number, number][];
17
+ /** Speed multiplier for the simulation interval. Default is 1. Higher is faster. */
18
+ simulationSpeed?: number;
19
+ /** Mock JWT token for NETWORK_REQUEST mocking */
20
+ mockJWTToken?: string;
21
+ children: React.ReactNode;
22
+ }
23
+ /**
24
+ * A utility component for Storybook that intercepts SDK bridge calls,
25
+ * simulates the behavior of the native shell app.
26
+ *
27
+ * NOTE: Logs are now handled by the standalone DebugConsole component.
28
+ */
29
+ declare const BridgeMocker: React.FC<BridgeMockerProps>;
30
+
31
+ interface DebugConsoleProps {
32
+ /**
33
+ * Whether to show the console initially.
34
+ * Can also be controlled via the 'debug' prop on SDKProvider.
35
+ */
36
+ isOpen?: boolean;
37
+ /**
38
+ * Optional callback when the console is closed.
39
+ */
40
+ onClose?: () => void;
41
+ }
42
+ /**
43
+ * A standalone debug console that intercepts and displays all Bridge communication.
44
+ * Useful for debugging both in mock mode (BridgeMocker) and on real devices.
45
+ */
46
+ declare const DebugConsole: React.FC<DebugConsoleProps>;
47
+
1
48
  /**
2
49
  * UP Mini-App SDK Types
3
50
  */
@@ -160,6 +207,8 @@ interface IInitializationResponse<Env extends Record<string, unknown> = Record<s
160
207
  userData: UserData;
161
208
  /** The params passed during the initialization */
162
209
  params: Params;
210
+ /** The edge insets of the mini app, representing the padding around the mini app's view within the Host Shell. */
211
+ insets: IEdgeInsets;
163
212
  }
164
213
  /**
165
214
  * Events emitted by the UI module.
@@ -168,13 +217,72 @@ declare enum UIEvent {
168
217
  /** Triggered when the user performs a native "Pull-to-Refresh". */
169
218
  TOP_SCROLL_MORE = "TOP_SCROLL_MORE",
170
219
  /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */
171
- BOTTOM_SCROLL_MORE = "BOTTOM_SCROLL_MORE"
220
+ BOTTOM_SCROLL_MORE = "BOTTOM_SCROLL_MORE",
221
+ /** Triggered when the user performs a native back gesture or presses the native back button. */
222
+ BACK_GESTURE = "BACK_GESTURE"
223
+ }
224
+ /**
225
+ * Events emitted by the Geolocation module.
226
+ */
227
+ declare enum GeolocationEvent {
228
+ /** Triggered when the user's location is updated (legacy polling). */
229
+ LOCATION_UPDATE = "LOCATION_UPDATE",
230
+ /** Triggered by the continuous location stream. */
231
+ LOCATION_STREAM_UPDATE = "LOCATION_STREAM_UPDATE"
232
+ }
233
+ /**
234
+ * Configuration options for the location stream.
235
+ */
236
+ interface LocationStreamConfig {
237
+ /** Polling cycle rate in milliseconds. Default: 250 */
238
+ interval?: number;
239
+ /** Distance change in meters to trigger an update. Default: 5 */
240
+ distanceFilter?: number;
241
+ /** Heading change in degrees to trigger an update. Default: 5 */
242
+ headingThreshold?: number;
243
+ /** Accelerometer delta in G-force to trigger an update. Default: 0.1 */
244
+ accelerometerThreshold?: number;
245
+ }
246
+ interface StreamLocationData {
247
+ coords: {
248
+ latitude: number;
249
+ longitude: number;
250
+ altitude: number | null;
251
+ accuracy: number | null;
252
+ altitudeAccuracy: number | null;
253
+ heading: number | null;
254
+ speed: number | null;
255
+ };
256
+ timestamp: number;
257
+ }
258
+ interface StreamHeadingData {
259
+ magneticHeading: number;
260
+ trueHeading: number;
261
+ accuracy: number;
262
+ }
263
+ interface StreamAccelerometerData {
264
+ x: number;
265
+ y: number;
266
+ z: number;
267
+ }
268
+ interface StreamUpdatePayload {
269
+ location: StreamLocationData;
270
+ heading: StreamHeadingData;
271
+ accelerometer: StreamAccelerometerData | null;
272
+ timestamp: number;
273
+ }
274
+ /**
275
+ * Global events emitted by the Host Shell that may affect the mini-app's context.
276
+ */
277
+ declare enum GlobalEvent {
278
+ /** Triggered when the Host Shell sends an update event to the mini-app, indicating changes in context. */
279
+ UPDATE_CONTEXT = "UPDATE_CONTEXT"
172
280
  }
173
281
  /**
174
282
  * Union type for all SDK events, allowing for both known enums and custom strings.
175
283
  * The (string & {}) pattern preserves IntelliSense for enum members.
176
284
  */
177
- type SDKEvent = UIEvent | (string & {});
285
+ type SDKEvent = UIEvent | GeolocationEvent | GlobalEvent | (string & {});
178
286
  /**
179
287
  * Configuration for native scroll interactions managed by the Host Shell.
180
288
  */
@@ -196,12 +304,595 @@ interface ScrollConfig {
196
304
  loadingMore?: boolean;
197
305
  };
198
306
  }
307
+ /**
308
+ * Edge insets representing padding or margins around a component, typically used for layout purposes.
309
+ */
310
+ interface IEdgeInsets {
311
+ top: number;
312
+ right: number;
313
+ bottom: number;
314
+ left: number;
315
+ }
316
+ /**
317
+ * The context state of the mini-app, which includes dynamic properties provided by the Host Shell, such as edge insets for layout adjustments. This type can be extended with additional properties as needed.
318
+ */
319
+ type IContextState = Record<string, any> & {
320
+ insets: IEdgeInsets;
321
+ };
199
322
 
200
323
  /**
201
- * Main SDK for UP Mini-Apps.
202
- * Provides access to native device features, storage, identity, and shell UI.
324
+ * Internal message envelope for bridge communication.
325
+ * @internal
326
+ */
327
+ interface IBridgeEnvelope<P = unknown, V = unknown> {
328
+ /** Unique identifier to match responses with requests. */
329
+ callbackId?: string;
330
+ /** The type/action of the message. */
331
+ type?: string;
332
+ /** Event name for pushed notifications (new protocol). */
333
+ eventName?: string;
334
+ /** Data payload for the message. */
335
+ payload?: P;
336
+ /** Whether the operation was successful. */
337
+ success?: boolean;
338
+ /** Error message if success is false. */
339
+ error?: string;
340
+ /** The result value for successful operations. */
341
+ value?: V;
342
+ /** Event name for pushed notifications (legacy protocol). */
343
+ event?: string;
344
+ }
345
+ /**
346
+ * The messages the bridge can ask for
203
347
  */
348
+ type BridgeMessageType = {
349
+ type: "STORAGE_SET";
350
+ payload: {
351
+ key: string;
352
+ value: string;
353
+ };
354
+ callbackId: string;
355
+ } | {
356
+ type: "STORAGE_GET";
357
+ payload: {
358
+ key: string;
359
+ };
360
+ callbackId: string;
361
+ } | {
362
+ type: "STORAGE_GET_ALL";
363
+ payload?: unknown;
364
+ callbackId: string;
365
+ } | {
366
+ type: "GET_LOCATION";
367
+ payload?: unknown;
368
+ callbackId: string;
369
+ } | {
370
+ type: "INITIALIZE";
371
+ payload: {
372
+ options: IInitializationOptions;
373
+ };
374
+ callbackId: string;
375
+ } | {
376
+ type: "DEBUG_LOG";
377
+ payload: {
378
+ message: unknown[];
379
+ };
380
+ callbackId: string;
381
+ } | {
382
+ type: "SECURE_SET";
383
+ payload: {
384
+ key: string;
385
+ value: string;
386
+ };
387
+ callbackId: string;
388
+ } | {
389
+ type: "SECURE_GET";
390
+ payload: {
391
+ key: string;
392
+ };
393
+ callbackId: string;
394
+ } | {
395
+ type: "PAYMENT_REQUEST";
396
+ payload: unknown;
397
+ callbackId: string;
398
+ } | {
399
+ type: "START_ACTIVITY";
400
+ payload: unknown;
401
+ callbackId: string;
402
+ } | {
403
+ type: "GET_USER_PROFILE";
404
+ payload?: {
405
+ fields?: string[];
406
+ };
407
+ callbackId: string;
408
+ } | {
409
+ type: "SPEND_FPOINTS";
410
+ payload: {
411
+ intentUuid: string;
412
+ };
413
+ callbackId: string;
414
+ } | {
415
+ type: "GET_FIDELITY_BALANCE";
416
+ payload?: unknown;
417
+ callbackId: string;
418
+ } | {
419
+ type: "GET_FIDELITY_HISTORY";
420
+ payload: IFidelityHistoryParams;
421
+ callbackId: string;
422
+ } | {
423
+ type: "EXIT";
424
+ payload?: unknown;
425
+ callbackId: string;
426
+ } | {
427
+ type: "DATABASE_GET_USER_DATA";
428
+ payload?: unknown;
429
+ callbackId: string;
430
+ } | {
431
+ type: "DATABASE_SET_USER_DATA";
432
+ payload: {
433
+ data: unknown;
434
+ };
435
+ callbackId: string;
436
+ } | {
437
+ type: "REQUEST_PERMISSION";
438
+ payload: {
439
+ type: "location" | "profile";
440
+ fields?: string[];
441
+ };
442
+ callbackId: string;
443
+ } | {
444
+ type: "TRIGGER_HAPTIC";
445
+ payload?: {
446
+ style?: HapticStyleType;
447
+ };
448
+ callbackId: string;
449
+ } | {
450
+ type: "NETWORK_REQUEST";
451
+ payload: {
452
+ url: string;
453
+ method?: string;
454
+ headers?: Record<string, string>;
455
+ body?: unknown;
456
+ };
457
+ callbackId: string;
458
+ } | {
459
+ type: "SET_SCROLL_CONFIG";
460
+ payload: ScrollConfig;
461
+ callbackId: string;
462
+ } | {
463
+ type: "SDK_ROUTING_GETROUTE";
464
+ payload: {
465
+ sdkVersion: string;
466
+ requestId: string;
467
+ payload: {
468
+ origin: [number, number];
469
+ destination: [number, number];
470
+ waypoints?: [number, number][];
471
+ profile: "driving" | "cycling" | "walking";
472
+ language?: string;
473
+ };
474
+ };
475
+ callbackId: string;
476
+ } | {
477
+ type: "SDK_ROUTING_DRAWROUTE";
478
+ payload: {
479
+ sdkVersion: string;
480
+ requestId: string;
481
+ payload: {
482
+ routeData: unknown;
483
+ };
484
+ };
485
+ callbackId: string;
486
+ } | {
487
+ type: "SDK_ROUTING_CLEARROUTE";
488
+ payload: {
489
+ sdkVersion: string;
490
+ requestId: string;
491
+ };
492
+ callbackId: string;
493
+ } | {
494
+ type: "UPDATE_CONTEXT";
495
+ payload: Record<string, unknown>;
496
+ callbackId: string;
497
+ } | {
498
+ type: "START_LOCATION_STREAM";
499
+ payload?: LocationStreamConfig;
500
+ callbackId: string;
501
+ } | {
502
+ type: "STOP_LOCATION_STREAM";
503
+ payload?: never;
504
+ callbackId: string;
505
+ } | {
506
+ type: string;
507
+ payload: unknown;
508
+ callbackId: string;
509
+ };
510
+
511
+ type DrawerState = "closed" | "peek" | "full";
512
+ interface POI {
513
+ id: string | number;
514
+ name: string;
515
+ longitude: number;
516
+ latitude: number;
517
+ type?: "bar" | "restaurant" | "shop" | string;
518
+ description?: string;
519
+ rating?: number;
520
+ metadata?: Record<string, unknown>;
521
+ /**
522
+ * Custom image URL for GL layer.
523
+ * If provided, the SDK will automatically load and cache this image.
524
+ */
525
+ imageUrl?: string;
526
+ /**
527
+ * Emoji character to display in GL layer (fallback if no icon).
528
+ */
529
+ emoji?: string;
530
+ /**
531
+ * Name of a sprite from the map style's sprite sheet (e.g., 'beer', 'cafe').
532
+ * If provided, this takes priority over emoji and default types.
533
+ */
534
+ spriteName?: string;
535
+ /**
536
+ * Whether to render as a native GL layer (performant) or a React Marker (flexible).
537
+ * Defaults to 'gl'.
538
+ */
539
+ displayMode?: "gl" | "marker";
540
+ /**
541
+ * Optional custom React component when displayMode is 'marker'.
542
+ */
543
+ markerComponent?: React.ReactNode;
544
+ }
545
+ interface MapProps {
546
+ /** Initial view state of the map. */
547
+ initialViewState?: Partial<ViewState>;
548
+ /** Inline styles for the map container. */
549
+ style?: React.CSSProperties;
550
+ /** Minimum and maximum bounds for the map. */
551
+ maxBounds?: [[number, number], [number, number]];
552
+ /** MapLibre style URL. Defaults to local server. */
553
+ mapStyle?: string;
554
+ /** Children components (Source, Layer, etc.) */
555
+ children?: React.ReactNode;
556
+ /** Additional CSS classes for the map container. */
557
+ className?: string;
558
+ /** Callback when the map is clicked. */
559
+ onClick?: (e: any) => void;
560
+ /** Callback when the map is clicked, but no interactive layers or POIs are hit. */
561
+ onMapClickMiss?: (e: any) => void;
562
+ /** Callback when the map is right-clicked or long-pressed. */
563
+ onContextMenu?: (e: any) => void;
564
+ /** IDs of layers that should be interactive. */
565
+ interactiveLayerIds?: string[];
566
+ /** Callback when the map is loaded. */
567
+ onLoad?: (e: any) => void;
568
+ /**
569
+ * Whether to show the user's current location on the map.
570
+ * Defaults to true.
571
+ */
572
+ showUserLocation?: boolean;
573
+ /**
574
+ * Whether the map should follow the user's location.
575
+ * Usually combined with showUserLocationButton for manual override.
576
+ * Note: The camera automatically locks when a route is provided.
577
+ */
578
+ followUser?: boolean;
579
+ /**
580
+ * Whether to show the built-in "Center on User" button.
581
+ * Defaults to true.
582
+ */
583
+ showUserLocationButton?: boolean;
584
+ /**
585
+ * Custom renderer for the user's location marker.
586
+ * If provided, overrides the default pulsating blue dot.
587
+ */
588
+ renderUserLocation?: (props: {
589
+ coords: [number, number];
590
+ heading: number | null;
591
+ }) => React.ReactNode;
592
+ /** A list of POIs to display. */
593
+ pois?: POI[];
594
+ /** Callback when a POI is clicked. */
595
+ onPoiClick?: (poi: POI) => void;
596
+ /** Route geometry to display on the map. */
597
+ route?: GeoJSON.LineString;
598
+ /** Whether to show the out-of-the-box navigation UI. */
599
+ showNavigationUI?: boolean;
600
+ /** Callback triggered when the user aborts/closes the navigation UI. */
601
+ onNavigationAbort?: () => void;
602
+ /**
603
+ * Integrated navigation configuration.
604
+ * If provided, the Map component will internally manage route calculation and tracking.
605
+ */
606
+ navigation?: {
607
+ /** Destination coordinates [lng, lat] */
608
+ destination: [number, number] | null;
609
+ /** Transport profile. Defaults to 'driving'. */
610
+ profile?: "driving" | "cycling" | "walking";
611
+ /** Minimum distance in meters the user must move before recalculating path geometry. Defaults to 50. */
612
+ recalculateThreshold?: number;
613
+ /** Whether to automatically show the navigation UI. Defaults to true if destination is set. */
614
+ showUI?: boolean;
615
+ /** Optional manual origin. Defaults to real-time user location. */
616
+ origin?: [number, number] | null;
617
+ /**
618
+ * Initial mode for the navigation.
619
+ * 'preview' shows the full route overview.
620
+ * 'navigation' starts active turn-by-turn tracking.
621
+ * Defaults to 'preview'.
622
+ */
623
+ mode?: "preview" | "navigation";
624
+ };
625
+ /** Callback triggered when the navigation mode changes (e.g. from preview to navigation). */
626
+ onNavigationModeChange?: (mode: "preview" | "navigation") => void;
627
+ /**
628
+ * The data for the navigation UI.
629
+ * Usually provided by the useLiveRouting hook.
630
+ * Note: This is automatically populated if the 'navigation' prop is used.
631
+ */
632
+ navigationData?: {
633
+ route: RouteResponse["data"] | null;
634
+ currentDistanceMeters?: number | null;
635
+ totalDistance?: number | null;
636
+ isCalculating?: boolean;
637
+ error?: string | null;
638
+ /** Current mode: 'preview' (overview) or 'navigation' (active guidance) */
639
+ mode?: "preview" | "navigation";
640
+ /** Function to transition to active navigation mode */
641
+ start?: () => void;
642
+ };
643
+ /** Whether to show the vertical drawer and floating right controls. Defaults to true. */
644
+ showControls?: boolean;
645
+ /** Custom menu items to display in the vertical drawer. */
646
+ menuItems?: MenuItem[];
647
+ /** Custom React node to render inside the drawer menu container instead of menuItems list. */
648
+ menuContent?: React.ReactNode;
649
+ /** Programmatically control the drawer state. */
650
+ drawerState?: DrawerState;
651
+ /** Ref to the drawer's scrollable container. */
652
+ drawerContentRef?: React.Ref<HTMLDivElement>;
653
+ /** Custom controls (e.g. buttons) to display floating above the recenter button. */
654
+ controlProps?: MapControlsProps;
655
+ /** Whether to enable touch drag gestures for the bottom sheet drawer. Defaults to false. */
656
+ enableTouchDrag?: boolean;
657
+ }
658
+ interface MenuItem {
659
+ id: string;
660
+ label: string;
661
+ icon: React.ReactNode;
662
+ onPress: () => void;
663
+ badge?: string | number;
664
+ disabled?: boolean;
665
+ }
666
+ interface CustomControl {
667
+ id: string;
668
+ icon: React.ReactNode;
669
+ onPress: () => void;
670
+ position: "above-recenter" | "below-recenter";
671
+ tooltip?: string;
672
+ activeState?: boolean;
673
+ }
674
+ interface EtaData {
675
+ etaMins: number;
676
+ distanceRemainingKm: number;
677
+ label?: string;
678
+ progress?: number;
679
+ mode?: "preview" | "navigation";
680
+ onAbort?: () => void;
681
+ onStart?: () => void;
682
+ isCalculating?: boolean;
683
+ error?: string | null;
684
+ }
685
+
686
+ interface MapInsets {
687
+ top: number;
688
+ bottom: number;
689
+ left: number;
690
+ right: number;
691
+ }
692
+ interface MapControlsState {
693
+ isFollowing: boolean;
694
+ setIsFollowing: (following: boolean) => void;
695
+ centerOnUser: (params?: CenterCallbackParams) => void;
696
+ bearing: number;
697
+ setBearing: (bearing: number) => void;
698
+ pitch: number;
699
+ setPitch: (pitch: number) => void;
700
+ resetBearing: (params?: CenterCallbackParams) => void;
701
+ etaData?: EtaData;
702
+ setEtaData: (data?: EtaData) => void;
703
+ hasControls: boolean;
704
+ setHasControls: (hasControls: boolean) => void;
705
+ drawerState: DrawerState;
706
+ setDrawerState: (state: DrawerState) => void;
707
+ /** Stable ref to the drawer's scrollable container. Always available. */
708
+ drawerContentRef: React.RefObject<HTMLDivElement | null>;
709
+ insets: MapInsets;
710
+ setInsets: (insets: Partial<MapInsets>) => void;
711
+ }
712
+ interface CenterCallbackParams {
713
+ pitch?: number;
714
+ }
715
+ interface MapControlsContextType extends MapControlsState {
716
+ _registerCenterCallback: (cb: (params?: CenterCallbackParams) => void) => void;
717
+ _registerResetBearingCallback: (cb: (params?: CenterCallbackParams) => void) => void;
718
+ }
719
+ declare const MapControlsContext: React.Context<MapControlsContextType | null>;
720
+ declare const SDKMapProvider: React.FC<{
721
+ children: React.ReactNode;
722
+ }>;
723
+ declare const useMapControls: () => MapControlsState;
724
+
725
+ interface MapControlsProps {
726
+ menuItems?: MenuItem[];
727
+ drawerSide?: "left" | "bottom";
728
+ defaultState?: DrawerState;
729
+ menuContent?: React.ReactNode;
730
+ children?: React.ReactNode;
731
+ customControls?: CustomControl[];
732
+ etaBarHeight?: number;
733
+ onRecenter?: (params?: CenterCallbackParams) => void;
734
+ isMapCentered?: boolean;
735
+ mapBearing?: number;
736
+ initialViewState?: Partial<ViewState>;
737
+ onResetBearing?: (params?: CenterCallbackParams) => void;
738
+ etaData?: EtaData;
739
+ customRecenterButton?: React.ReactNode;
740
+ customCompassButton?: React.ReactNode;
741
+ drawerPeekHeight?: string | number;
742
+ drawerFullHeight?: string | number;
743
+ drawerContentRef?: React.Ref<HTMLDivElement>;
744
+ enableTouchDrag?: boolean;
745
+ showScrollToTopButton?: boolean;
746
+ scrollToTopThreshold?: number;
747
+ isInternal?: boolean;
748
+ }
749
+ declare const MapControls: React.FC<MapControlsProps>;
750
+
751
+ interface MapMenuProps {
752
+ children?: React.ReactNode;
753
+ }
754
+ declare const MapMenu: React.FC<MapMenuProps>;
755
+ interface MapMenuItemProps {
756
+ id: string;
757
+ label: string;
758
+ icon?: React.ReactNode;
759
+ onPress?: () => void;
760
+ badge?: string | number;
761
+ disabled?: boolean;
762
+ children?: React.ReactNode;
763
+ }
764
+ declare const MapMenuItem: React.FC<MapMenuItemProps>;
765
+ interface MapMenuTitleProps {
766
+ children: React.ReactNode;
767
+ className?: string;
768
+ showDivider?: boolean;
769
+ }
770
+ declare const MapMenuTitle: React.FC<MapMenuTitleProps>;
771
+ interface MapMenuDividerProps {
772
+ className?: string;
773
+ }
774
+ declare const MapMenuDivider: React.FC<MapMenuDividerProps>;
775
+ interface MapMenuFooterProps {
776
+ children: React.ReactNode;
777
+ className?: string;
778
+ }
779
+ declare const MapMenuFooter: React.FC<MapMenuFooterProps>;
780
+
781
+ interface LiveRoutingOptions {
782
+ /** Origin coordinates [lng, lat]. If not provided, uses device location. */
783
+ origin?: [number, number] | null;
784
+ /** Destination coordinates [lng, lat] */
785
+ destination: [number, number] | null;
786
+ /** Transport profile. Defaults to 'driving'. */
787
+ profile?: "driving" | "cycling" | "walking";
788
+ /** Minimum distance in meters the user must move before recalculating path geometry. Defaults to 50. */
789
+ recalculateThreshold?: number;
790
+ /** Whether live routing is active. */
791
+ enabled?: boolean;
792
+ /** Initial mode: 'preview' or 'navigation'. Defaults to 'preview'. */
793
+ initialMode?: "preview" | "navigation";
794
+ }
795
+ interface LiveRoutingResult {
796
+ /** The calculated route data from the last API call */
797
+ route: RouteResponse["data"] | null;
798
+ /** Real-time distance to destination in meters */
799
+ currentDistanceMeters: number | null;
800
+ /** The initial total distance when the destination was first set */
801
+ totalDistance: number | null;
802
+ /** Whether a new calculation is in progress */
803
+ isCalculating: boolean;
804
+ /** Any error message from the routing service */
805
+ error: string | null;
806
+ /** Force a manual recalculation */
807
+ recalculate: () => void;
808
+ /** Current mode: 'preview' (overview) or 'navigation' (active guidance) */
809
+ mode: "preview" | "navigation";
810
+ /** Start active navigation (switch mode to 'navigation') */
811
+ start: () => void;
812
+ }
813
+ declare const useLiveRouting: ({ origin: manualOrigin, destination, profile, recalculateThreshold, enabled, initialMode, }: LiveRoutingOptions) => LiveRoutingResult;
814
+ /**
815
+ * A simple hook to fetch a route once between two points.
816
+ * Does not automatically recalculate or track user location.
817
+ */
818
+ declare const useRoute: (origin: [number, number] | null, destination: [number, number] | null, profile?: "driving" | "cycling" | "walking") => {
819
+ error: string | null;
820
+ isCalculating: boolean;
821
+ route: {
822
+ geometry: GeoJSON.LineString;
823
+ distanceMeters: number;
824
+ durationSeconds: number;
825
+ steps?: RouteStep[];
826
+ } | null | undefined;
827
+ };
828
+
829
+ /**
830
+ * Slices a LineString to start at the point closest to the provided coordinates.
831
+ * This removes the "already traveled" portion of the route.
832
+ */
833
+ declare const useTrimmedRoute: (route: GeoJSON.LineString | undefined, userLocation: [number, number] | null) => GeoJSON.LineString | undefined;
834
+
835
+ interface UserLocationState {
836
+ coords: [number, number] | null;
837
+ heading: number | null;
838
+ accuracy: number | null;
839
+ }
840
+ declare const useUserLocation: () => UserLocationState;
841
+
842
+ interface RouteLayerProps {
843
+ /** The route geometry as a GeoJSON LineString */
844
+ geometry?: GeoJSON.LineString;
845
+ /** Color of the route line. Defaults to #3b82f6 (blue-500). */
846
+ color?: string;
847
+ /** Width of the route line. Defaults to 5. */
848
+ width?: number;
849
+ /** Opacity of the route line. Defaults to 0.8. */
850
+ opacity?: number;
851
+ }
852
+ declare const RouteLayer: React.FC<RouteLayerProps>;
853
+
854
+ declare const Map: React.FC<MapProps>;
855
+
856
+ /**
857
+ * Renders the Map component into a DOM element.
858
+ * Useful for non-React environments (UMD/IIFE).
859
+ *
860
+ * @param containerId The ID of the HTML element where the map should be rendered.
861
+ * @param props The props to pass to the Map component.
862
+ * @returns The React root instance.
863
+ */
864
+ declare function renderMap(containerId: string, props?: MapProps): react_dom_client.Root;
865
+
866
+ /**
867
+ * Hook to check if the SDK is currently running in mock mode (browser)
868
+ * or native mode (shell app).
869
+ */
870
+ declare const useIsMocked: () => boolean;
871
+ interface SDKProviderProps extends Partial<Omit<BridgeMockerProps, "children">> {
872
+ children: React.ReactNode;
873
+ /**
874
+ * If true, shows the standalone DebugConsole for bridge traffic.
875
+ */
876
+ debug?: boolean;
877
+ }
878
+ /**
879
+ * A wrapper component that automatically enables the BridgeMocker
880
+ * when running outside the native shell app.
881
+ */
882
+ declare const SDKProvider: React.FC<SDKProviderProps>;
883
+
204
884
  declare class MiniAppSDK {
885
+ /**
886
+ * Map services.
887
+ * Provides access to MapLibre-based mapping components.
888
+ */
889
+ readonly maps: Readonly<{
890
+ /**
891
+ * Renders a MapLibre map into a DOM element.
892
+ * Useful for non-React environments.
893
+ */
894
+ render: typeof renderMap;
895
+ }>;
205
896
  private bridge;
206
897
  /**
207
898
  * Local SQLite Storage.
@@ -239,8 +930,19 @@ declare class MiniAppSDK {
239
930
  * Device Location services.
240
931
  */
241
932
  readonly location: Readonly<{
242
- /** Retrieves the current GPS position of the device. */
933
+ /**
934
+ * Retrieves the current GPS position of the device.
935
+ */
243
936
  getCurrentPosition: () => Promise<ILocationData>;
937
+ /**
938
+ * Starts the continuous location and sensor stream.
939
+ * @param config Optional configuration for thresholds and intervals.
940
+ */
941
+ startStream: (config?: LocationStreamConfig) => Promise<void>;
942
+ /**
943
+ * Stops the continuous location and sensor stream.
944
+ */
945
+ stopStream: () => Promise<void>;
244
946
  }>;
245
947
  /**
246
948
  * Identity & Profile management.
@@ -312,7 +1014,30 @@ declare class MiniAppSDK {
312
1014
  * Performs a network request via the host shell.
313
1015
  * @param options Request method, URL, headers, and body.
314
1016
  */
315
- request: (options: INetworkOptions) => Promise<INetworkResponse>;
1017
+ request: <T = unknown>(options: INetworkOptions) => Promise<INetworkResponse<T>>;
1018
+ }>;
1019
+ /**
1020
+ * Navigation and Journey controls.
1021
+ * Allows programmatically starting itineraries and managing navigation state.
1022
+ */
1023
+ readonly navigation: Readonly<{
1024
+ /**
1025
+ * Aborts the current navigation journey.
1026
+ */
1027
+ abort: () => void;
1028
+ /**
1029
+ * Creates a new itinerary preview.
1030
+ * @param options Destination and routing options.
1031
+ */
1032
+ createJourney: (options: {
1033
+ destination: [number, number];
1034
+ origin?: [number, number];
1035
+ profile?: "driving" | "cycling" | "walking";
1036
+ }) => void;
1037
+ /**
1038
+ * Starts the active navigation (active guidance).
1039
+ */
1040
+ start: () => void;
316
1041
  }>;
317
1042
  /**
318
1043
  * Fidelity & Rewards program integration.
@@ -325,6 +1050,10 @@ declare class MiniAppSDK {
325
1050
  * @param params Filtering and pagination parameters.
326
1051
  */
327
1052
  getFidelityHistory: (params?: IFidelityHistoryParams) => Promise<IFidelityTransaction[]>;
1053
+ /**
1054
+ * Triggers the native fidelity history view.
1055
+ */
1056
+ showHistory: () => Promise<void>;
328
1057
  /**
329
1058
  * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.
330
1059
  * @param intentUuid UUID generated by your backend for the transaction.
@@ -356,7 +1085,39 @@ declare class MiniAppSDK {
356
1085
  */
357
1086
  log: (...message: unknown[]) => Promise<unknown>;
358
1087
  }>;
1088
+ /**
1089
+ * Routing integration (OSRM / Valhalla).
1090
+ * Provides access to route calculation and rendering on the host map.
1091
+ */
1092
+ readonly routing: Readonly<{
1093
+ /**
1094
+ * Clears the currently rendered route.
1095
+ */
1096
+ clearRoute: () => Promise<void>;
1097
+ /**
1098
+ * Draws the calculated route on the host map.
1099
+ * @param routeData The route data returned by getRoute.
1100
+ */
1101
+ drawRoute: (routeData: NonNullable<RouteResponse["data"]>) => Promise<void>;
1102
+ /**
1103
+ * Calculates a route between points.
1104
+ * @param payload Request payload containing origin, destination, and options.
1105
+ */
1106
+ getRoute: (payload: RouteRequest["payload"]) => Promise<NonNullable<RouteResponse["data"]>>;
1107
+ }>;
359
1108
  constructor();
1109
+ /**
1110
+ * Configures global SDK settings.
1111
+ */
1112
+ config(options: {
1113
+ routingBackend?: RoutingBackendConfig;
1114
+ }): void;
1115
+ /**
1116
+ * Updates the global context shared between the Mini-App and the native shell.
1117
+ * Useful for synchronizing state like theme preferences, UI flags, or custom app-specific context.
1118
+ * @param context Partial context object to merge into the existing shell context.
1119
+ */
1120
+ updateContext(context: Record<string, unknown>): Promise<void>;
360
1121
  /**
361
1122
  * The starting point for the Mini-App. Must be called before any other SDK methods.
362
1123
  * @param options The options to provide to the shell app
@@ -368,13 +1129,13 @@ declare class MiniAppSDK {
368
1129
  * @param callback The function to execute when the event is triggered.
369
1130
  * @returns A function to unregister the listener.
370
1131
  */
371
- on(event: SDKEvent, callback: (data: unknown) => void): () => void;
1132
+ on<T = unknown>(event: SDKEvent, callback: (data: T) => void): () => void;
372
1133
  /**
373
1134
  * Unregisters a previously registered event listener.
374
1135
  * @param event The name of the event.
375
1136
  * @param callback The callback function to remove.
376
1137
  */
377
- off(event: SDKEvent, callback: (data: unknown) => void): void;
1138
+ off<T = unknown>(event: SDKEvent, callback: (data: T) => void): void;
378
1139
  }
379
1140
  /**
380
1141
  * Singleton instance of the MiniAppSDK.
@@ -382,147 +1143,4 @@ declare class MiniAppSDK {
382
1143
  */
383
1144
  declare const sdk: MiniAppSDK;
384
1145
 
385
- /**
386
- * Internal message envelope for bridge communication.
387
- * @internal
388
- */
389
- interface IBridgeEnvelope<P = unknown, V = unknown> {
390
- /** Unique identifier to match responses with requests. */
391
- callbackId?: string;
392
- /** The type/action of the message. */
393
- type?: string;
394
- /** Data payload for the message. */
395
- payload?: P;
396
- /** Whether the operation was successful. */
397
- success?: boolean;
398
- /** Error message if success is false. */
399
- error?: string;
400
- /** The result value for successful operations. */
401
- value?: V;
402
- /** Event name for pushed notifications. */
403
- event?: string;
404
- }
405
- /**
406
- * The messages the bridge can ask for
407
- */
408
- type BridgeMessageType = {
409
- type: "STORAGE_SET";
410
- payload: {
411
- key: string;
412
- value: string;
413
- };
414
- callbackId: string;
415
- } | {
416
- type: "STORAGE_GET";
417
- payload: {
418
- key: string;
419
- };
420
- callbackId: string;
421
- } | {
422
- type: "STORAGE_GET_ALL";
423
- payload?: unknown;
424
- callbackId: string;
425
- } | {
426
- type: "GET_LOCATION";
427
- payload?: unknown;
428
- callbackId: string;
429
- } | {
430
- type: "INITIALIZE";
431
- payload: {
432
- options: IInitializationOptions;
433
- };
434
- callbackId: string;
435
- } | {
436
- type: "DEBUG_LOG";
437
- payload: {
438
- message: unknown[];
439
- };
440
- callbackId: string;
441
- } | {
442
- type: "SECURE_SET";
443
- payload: {
444
- key: string;
445
- value: string;
446
- };
447
- callbackId: string;
448
- } | {
449
- type: "SECURE_GET";
450
- payload: {
451
- key: string;
452
- };
453
- callbackId: string;
454
- } | {
455
- type: "PAYMENT_REQUEST";
456
- payload: unknown;
457
- callbackId: string;
458
- } | {
459
- type: "START_ACTIVITY";
460
- payload: unknown;
461
- callbackId: string;
462
- } | {
463
- type: "GET_USER_PROFILE";
464
- payload?: {
465
- fields?: string[];
466
- };
467
- callbackId: string;
468
- } | {
469
- type: "SPEND_FPOINTS";
470
- payload: {
471
- intentUuid: string;
472
- };
473
- callbackId: string;
474
- } | {
475
- type: "GET_FIDELITY_BALANCE";
476
- payload?: unknown;
477
- callbackId: string;
478
- } | {
479
- type: "GET_FIDELITY_HISTORY";
480
- payload: IFidelityHistoryParams;
481
- callbackId: string;
482
- } | {
483
- type: "EXIT";
484
- payload?: unknown;
485
- callbackId: string;
486
- } | {
487
- type: "DATABASE_GET_USER_DATA";
488
- payload?: unknown;
489
- callbackId: string;
490
- } | {
491
- type: "DATABASE_SET_USER_DATA";
492
- payload: {
493
- data: unknown;
494
- };
495
- callbackId: string;
496
- } | {
497
- type: "REQUEST_PERMISSION";
498
- payload: {
499
- type: "location" | "profile";
500
- fields?: string[];
501
- };
502
- callbackId: string;
503
- } | {
504
- type: "TRIGGER_HAPTIC";
505
- payload?: {
506
- style?: HapticStyleType;
507
- };
508
- callbackId: string;
509
- } | {
510
- type: "NETWORK_REQUEST";
511
- payload: {
512
- url: string;
513
- method?: string;
514
- headers?: Record<string, string>;
515
- body?: unknown;
516
- };
517
- callbackId: string;
518
- } | {
519
- type: "SET_SCROLL_CONFIG";
520
- payload: ScrollConfig;
521
- callbackId: string;
522
- } | {
523
- type: string;
524
- payload: unknown;
525
- callbackId: string;
526
- };
527
-
528
- export { type BridgeMessageType, type FidelityTransactionTypeType, type HapticStyleType, type IBridgeEnvelope, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IUserProfile, MiniAppSDK, type NetworkMethodType, type SDKEvent, type ScrollConfig, UIEvent, sdk as default, sdk };
1146
+ export { type BridgeMessageType, BridgeMocker, type BridgeMockerProps, type CenterCallbackParams, type CustomControl, DebugConsole, type DebugConsoleProps, type DrawerState, type EtaData, type FidelityTransactionTypeType, GeolocationEvent, GlobalEvent, type HapticStyleType, type IBridgeEnvelope, type IContextState, type IEdgeInsets, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, 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, type NetworkMethodType, type POI, RouteLayer, type RouteLayerProps, RouteRequest, RouteResponse, RouteStep, type SDKEvent, SDKMapProvider, SDKProvider, type SDKProviderProps, type ScrollConfig, type StreamAccelerometerData, type StreamHeadingData, type StreamLocationData, type StreamUpdatePayload, UIEvent, type UserLocationState, sdk as default, renderMap, sdk, useIsMocked, useLiveRouting, useMapControls, useRoute, useTrimmedRoute, useUserLocation };