@yarrow-uz/rn-map-sdk 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,8 @@
1
+ # @yarrow-uz/rn-map-sdk
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 45b65f6: Add the React Native SDK: `@yarrow-uz/rn-map-sdk` ships `YarrowMapView` (MapLibre Native with Yarrow styles), `RouteLayer` + `useYarrowRouting` for routing, `useYarrowSearch` for search, and an AsyncStorage user-token adapter. Core gains an exported `USER_TOKEN_STORAGE_KEY` and an optional `sdkType` argument on `trackDau` (the web SDK keeps reporting `javascript`); the web-sdk patch republishes the rebuilt bundle with that core.
8
+ - adf31db: Add offline region support: `YarrowOfflineManager` downloads MapLibre Native offline packs for a bounding box + zoom range (idempotent by name, resumable, typed error codes, tile-count/size estimation), `useYarrowOfflineRegions` exposes region state for offline settings screens, and ambient-cache sizing/invalidation is available on the manager. Regions are staleness-flagged via `maxAgeDays` and refreshed with native revalidation. Replaces the inert web-style `yarrowcache` behavior on native, where `addProtocol` does not exist.
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ YARROW PROPRIETARY SUBSCRIPTION LICENSE
2
+ Version 1.0
3
+ Effective Date: February 18, 2026
4
+
5
+ Copyright (c) 2026 Yarrow. All rights reserved.
6
+
7
+ 1. Definitions
8
+ "Licensor" means Yarrow.
9
+ "Software" means this software, including all associated source code, object code, documentation, updates, and related materials.
10
+ "Subscriber" means the individual or entity granted access under this License pursuant to a valid subscription.
11
+
12
+ 2. Limited License Grant
13
+ Subject to continuous compliance with this License and an active, valid subscription, Licensor grants Subscriber a limited, non-exclusive, non-transferable, non-sublicensable, revocable right to access and use the Software solely for Subscriber's internal authorized purposes.
14
+
15
+ 3. Restrictions
16
+ Subscriber must not, and must not permit any third party to:
17
+ a) copy the Software, in whole or in part;
18
+ b) redistribute, publish, disclose, transmit, lease, lend, or otherwise make the Software available to any third party;
19
+ c) modify, adapt, translate, create derivative works from, or otherwise alter the Software;
20
+ d) reverse engineer, decompile, disassemble, decode, or otherwise attempt to derive source code, structure, or underlying ideas of the Software, except where such restriction is prohibited by applicable law and cannot be waived;
21
+ e) sublicense, assign, transfer, or otherwise grant rights in the Software to any third party;
22
+ f) sell, resell, license for a fee, or otherwise commercially exploit the Software or access to it.
23
+
24
+ 3.1. Permitted Technical Acts
25
+ Notwithstanding Section 3, and only while Subscriber maintains a valid subscription, Subscriber may:
26
+ a) install the Software from Licensor's designated distribution channels (including public package registries) and make copies strictly incidental to installation, dependency management, building, testing, and deployment of Subscriber's applications;
27
+ b) compile, bundle, minify, tree-shake, or otherwise mechanically transform the Software as an ordinary part of building Subscriber's applications, provided the Software's functionality is not otherwise modified;
28
+ c) serve and deliver the Software, in bundled or original form, to end users' browsers solely as an integrated component of Subscriber's applications.
29
+ Such acts do not constitute prohibited copying, modification, redistribution, or making available under Section 3. No rights are granted to distribute the Software on a standalone basis, to expose it as a service or SDK to third-party developers, or to remove or alter any Yarrow branding, attribution, or license notices.
30
+
31
+ 4. Subscription Requirement and Access Control
32
+ Access to and use of the Software is permitted only while Subscriber maintains a valid subscription. Any access or use without a valid subscription is strictly prohibited and constitutes a material breach of this License.
33
+
34
+ 5. Revocation
35
+ Licensor may suspend or revoke any subscription and any related access rights at any time, with or without notice, in Licensor's sole discretion.
36
+
37
+ 6. Termination
38
+ Any violation of this License automatically and immediately terminates all rights granted under this License, without notice. Upon termination, Subscriber must immediately cease all use and access of the Software.
39
+
40
+ 7. Reservation of Rights
41
+ The Software is licensed, not sold. All rights not expressly granted are reserved by Licensor.
42
+
43
+ 8. No Waiver
44
+ Failure by Licensor to enforce any provision of this License will not constitute a waiver of future enforcement of that or any other provision.
package/README.md CHANGED
@@ -1,3 +1,226 @@
1
- # Temporary Holding Version
1
+ # @yarrow-uz/rn-map-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Yarrow Map SDK for React Native — interactive MapLibre Native maps, search and
4
+ routing for iOS and Android.
5
+
6
+ ## Features
7
+
8
+ - Native MapLibre maps (via [`@maplibre/maplibre-react-native`](https://github.com/maplibre/maplibre-react-native)) with Yarrow light/dark, satellite and hybrid styles
9
+ - Route planning, rendering and turn-by-turn directions
10
+ - Debounced, abortable search hooks
11
+ - Offline region downloads (pause/resume/invalidate) plus ambient-cache control
12
+ - Anonymous user-token tracking with an AsyncStorage adapter
13
+ - DAU reporting (`sdk_type: "react-native"`)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @yarrow-uz/rn-map-sdk @maplibre/maplibre-react-native
19
+ ```
20
+
21
+ > Get your API key from the [Yarrow Dashboard](https://dashboard.yarrow.uz).
22
+
23
+ ### Requirements
24
+
25
+ - **React Native >= 0.80** (or **Expo >= 54**)
26
+ - **React >= 19.1**
27
+ - `@maplibre/maplibre-react-native` **^11.5.1** installed in your app — it
28
+ carries the native iOS/Android code. Follow its
29
+ [installation guide](https://maplibre.org/maplibre-react-native/docs/install)
30
+ (Expo config plugin or bare-workflow autolinking).
31
+
32
+ The platform-agnostic core is compiled **into** this package's dist, so
33
+ `@yarrow-uz/rn-map-sdk` is the only Yarrow package you install.
34
+
35
+ ## Quick start
36
+
37
+ ```tsx
38
+ import { useRef } from 'react';
39
+ import { YarrowMapView, type MapRef } from '@yarrow-uz/rn-map-sdk';
40
+
41
+ export function MapScreen() {
42
+ const mapRef = useRef<MapRef>(null);
43
+
44
+ return (
45
+ <YarrowMapView
46
+ apiKey="YOUR_API_KEY"
47
+ center={[69.2401, 41.2995]} // Tashkent [lng, lat]
48
+ zoom={12}
49
+ theme="dark"
50
+ styleType="default" // 'default' | 'satellite' | 'hybrid'
51
+ style={{ flex: 1 }}
52
+ onReady={(map) => map.getCenter().then(console.log)}
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ Props: `apiKey` and `center` are required; `zoom` (default 10), `minZoom` (0),
59
+ `maxZoom` (19), `theme` (`light`), `styleType` (`default`), `attribution`,
60
+ `logo`, `compass` (all `true`), `dauTracking` (`true`), `onReady`,
61
+ `onLoadError`, `onPress`, `cameraRef`, `style` and `children` are optional.
62
+
63
+ The component ref is the MapLibre `MapRef` (`getCenter`, `getBounds`,
64
+ `queryRenderedFeatures`, …). Pass `cameraRef` for camera control:
65
+
66
+ ```tsx
67
+ import { useRef } from 'react';
68
+ import { YarrowMapView, type CameraRef } from '@yarrow-uz/rn-map-sdk';
69
+
70
+ const cameraRef = useRef<CameraRef>(null);
71
+ cameraRef.current?.flyTo({ center: [69.2401, 41.2995], zoom: 14 });
72
+ ```
73
+
74
+ Camera props (`center`, `zoom`) only apply on mount — recenter through
75
+ `cameraRef`. `theme`/`styleType` changes hot-swap the style natively.
76
+
77
+ ## Routing
78
+
79
+ `useYarrowRouting` is headless state; `<RouteLayer>` renders it:
80
+
81
+ ```tsx
82
+ import { YarrowMapView, RouteLayer, useYarrowRouting } from '@yarrow-uz/rn-map-sdk';
83
+
84
+ function Directions({ origin, destination }) {
85
+ const { routes, isLoading, error, buildRoute, clearRoutes } = useYarrowRouting({
86
+ profile: 'driving',
87
+ language: 'uz',
88
+ });
89
+
90
+ return (
91
+ <YarrowMapView apiKey="YOUR_API_KEY" center={origin}>
92
+ <RouteLayer
93
+ routes={routes}
94
+ onPressRoute={(event, index) => console.log('route', index)}
95
+ />
96
+ </YarrowMapView>
97
+ );
98
+ }
99
+ ```
100
+
101
+ `buildRoute({ coordinates })` resolves to `{ features, directions, meta }`
102
+ ("no route found" resolves to an empty result instead of rejecting; network
103
+ failures reject and set `error`).
104
+
105
+ ## Search
106
+
107
+ ```tsx
108
+ const { results, isLoading, error } = useYarrowSearch(query, {
109
+ lat: 41.2995,
110
+ lon: 69.2401,
111
+ debounceMs: 300,
112
+ });
113
+ ```
114
+
115
+ Results are plain `SearchResult` objects — render them with your own markers
116
+ (e.g. `Marker` or `ViewAnnotation` from `@maplibre/maplibre-react-native`).
117
+
118
+ ## Anonymous user token
119
+
120
+ Tracking uses a persistent anonymous token. On the web core falls back to
121
+ `localStorage`; React Native has none, so persist it via AsyncStorage at app
122
+ startup:
123
+
124
+ ```tsx
125
+ import AsyncStorage from '@react-native-async-storage/async-storage';
126
+ import { setAsyncStorageTokenStorage } from '@yarrow-uz/rn-map-sdk';
127
+
128
+ await setAsyncStorageTokenStorage(AsyncStorage);
129
+ ```
130
+
131
+ `@react-native-async-storage/async-storage` is an **optional** peer
132
+ dependency — without it, tokens are ephemeral (per-session). Any storage
133
+ shaped `{ getItem, setItem }` works via the same function, or wire your own
134
+ synchronous storage with `setTokenStorage()`.
135
+
136
+ ## Offline regions
137
+
138
+ The web SDK caches tiles through its `yarrowcache` protocol; native MapLibre
139
+ has no `addProtocol`, so offline support here is **region packs** instead:
140
+ pick a bounding box and zoom range, download it once, and the map renders
141
+ from the native offline database with no network.
142
+
143
+ ```tsx
144
+ import { YarrowOfflineManager } from '@yarrow-uz/rn-map-sdk';
145
+
146
+ const offline = new YarrowOfflineManager({ apiKey: 'YOUR_API_KEY' });
147
+
148
+ // Estimate before downloading — pure tile math, no network.
149
+ const { tileCount, estSizeBytes } = offline.estimateRegion({
150
+ bounds: [69.15, 41.2, 69.4, 41.4], // Tashkent [w, s, e, n]
151
+ minZoom: 8,
152
+ maxZoom: 15,
153
+ });
154
+
155
+ const region = await offline.downloadRegion({
156
+ name: 'tashkent-city',
157
+ bounds: [69.15, 41.2, 69.4, 41.4],
158
+ styleType: 'default', // pack pins one style; swap offline only within packed styles
159
+ theme: 'light',
160
+ maxAgeDays: 30,
161
+ onProgress: (p) => console.log(`${p.percentage}%`),
162
+ onError: (e) => console.error(e.code, e.message),
163
+ });
164
+ await region.done; // resolves with final progress, rejects on download failure
165
+ ```
166
+
167
+ // region: { id, name, done, refreshStatus(), pause(), resume(), invalidate(), delete() }
168
+ ```
169
+
170
+ Downloads default to zooms **8–15** (higher zooms multiply the tile count
171
+ fast — always estimate first) and are idempotent by `name`: re-downloading a
172
+ finished region is a no-op, an interrupted one resumes, and mismatched
173
+ parameters throw a `params-mismatch` error (pass `force: true` to replace).
174
+ Errors carry a `code` — `'tile-count-limit-exceeded'`, `'region-too-large'`,
175
+ `'network'`, `'disk'`, `'not-found'`, `'params-mismatch'`, `'unknown'`.
176
+
177
+ `handle.done` rejects on the first download failure and **stays rejected** —
178
+ retry with `handle.resume()` and track recovery through `onProgress` /
179
+ `refreshStatus()` rather than awaiting `done` again. `handle.pause() /
180
+ resume() / invalidate() / delete()` manage the region; `invalidate()` is the
181
+ cheap refresh path (native revalidation — only changed tiles re-download).
182
+ `offline.getRegion(name)` retrieves handles for previously downloaded
183
+ regions (across app restarts) without touching them.
184
+
185
+ Regions never expire natively: `maxAgeDays` only makes `listRegions()`
186
+ flag them `isStale`.
187
+
188
+ For offline settings screens, use the hook — it polls while downloads run:
189
+
190
+ ```tsx
191
+ import { useYarrowOfflineRegions } from '@yarrow-uz/rn-map-sdk';
192
+
193
+ const { regions, download, pause, resume, invalidate, remove, error } =
194
+ useYarrowOfflineRegions({ apiKey: 'YOUR_API_KEY' });
195
+ ```
196
+
197
+ Native tiles also land in an **ambient cache** (automatic LRU of seen tiles,
198
+ no TTL). Size it once at app startup:
199
+
200
+ ```ts
201
+ offline.setAmbientCacheSize(128 * 1024 * 1024); // default is platform-defined
202
+ offline.invalidateAmbientCache(); // recommended refresh
203
+ ```
204
+
205
+ `offline.resetDatabase()` wipes everything (ambient cache + all packs) and is
206
+ destructive — MapLibre's JS layer only re-reads the database on app restart,
207
+ so prefer per-region `invalidate()`/`delete()`.
208
+
209
+ ## Example app
210
+
211
+ `packages/example` is a private Expo app that runs the SDK on a real Android
212
+ device (native MapLibre, live styles, routes and search) — the React Native
213
+ counterpart of the web-sdk browser-test harness. See
214
+ [packages/example/README.md](../example/README.md).
215
+
216
+ ## Development
217
+
218
+ ```bash
219
+ bun install
220
+ bun run --filter '@yarrow-uz/rn-map-sdk' test
221
+ bun run --filter '@yarrow-uz/rn-map-sdk' build
222
+ ```
223
+
224
+ ## License
225
+
226
+ See [LICENSE](./LICENSE).