@flapsdk/vault-runtime 0.1.40-next.0 → 0.1.40-next.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/README.md CHANGED
@@ -6,7 +6,7 @@ Generated from `flap-vault-ui-template`.
6
6
 
7
7
  This package is the shared runtime surface that local preview, Artifact Workbench, and `flap.sh` should agree on.
8
8
 
9
- Package version: `0.1.40-next.0`. Source commit: `0d21863aa19bde5ad6712d760d3badea6a28e3a4`.
9
+ Package version: `0.1.40-next.2`. Source commit: `4a2cedefdd7a6f6d2bbd48283aa8a34dec41b8f0`.
10
10
 
11
11
  ## Exports
12
12
 
@@ -17,12 +17,71 @@ Package version: `0.1.40-next.0`. Source commit: `0d21863aa19bde5ad6712d760d3bad
17
17
 
18
18
  See `runtime-contract.json` for the machine-readable subpath contract.
19
19
 
20
+ ## Mini App subroutes
21
+
22
+ Standalone Mini Apps use `useMiniAppRouter()` from `./sdk`. It returns
23
+ App-relative `pathname`, decoded `segments`, `search`, and
24
+ `push(path)`, `replace(path)`, `back()`. Paths start with `/`
25
+ inside the current App; external URLs, traversal, encoded separators and hashes
26
+ are rejected. Routing grants no wallet or contract access.
27
+ `MINI_APP_ROUTING_VERSION = 1` and `sdkFeatures.miniAppRouting = 1`
28
+ identify the feature. Hosts inject a `router` into `MiniAppRuntimeProvider`;
29
+ `./host` exports `parseMiniAppPath`, `createMiniAppMemoryRouter` and
30
+ `createMiniAppBrowserRouter`. Old Apps need no adapter. The new hook fails
31
+ explicitly if the host has not enabled routing. Deploy supporting hosts before
32
+ accepting new route-dependent artifacts; source-package provenance is unchanged.
33
+
34
+ ## Street maps
35
+
36
+ The `./ui` export `FlapStreetMap` requires `mapCapabilities: ["street-map-v1"]` and `uiFeatures.streetMap = 1`. Hosts copy the packaged `runtime-map/maplibre-6.15.0-worker.mjs` to the exact same-origin path `/runtime-map/maplibre-6.15.0-worker.mjs`. The fixed MapLibre 6.15.0 engine is lazy bundled; there is no CDN loader, arbitrary style/URL/Worker/HTML API or automatic GPS request. Pass points, center and optional existing GPS coordinates, then handle state and supply a localized list fallback. Points are capped at 2000, zoom at 3..18. Fixed OpenFreeMap dark resources are requested without credentials; the provider sees the client IP and viewport. This direct-resource policy does not isolate redirects or guarantee upstream availability. WebGL2/Worker failure and a 15-second startup timeout show the fallback. Map-owned canvas/listeners/observers are released on unmount; MapLibre retains its page-wide shared pool, capped at two Workers, for reuse. Preserve the package Worker license and fixed attribution links. Old UI remains compatible; deployed 0.1.39 hosts do not gain this testing feature. See template docs/street-map.md and docs/street-map.zh-CN.md.
37
+
38
+ ## Location and motion sensors
39
+
40
+ This release adds `useGeolocation()`, `useDeviceMotion()` and
41
+ `useDeviceOrientation()` to `./sdk`, with `DEVICE_SENSORS_VERSION = 1`
42
+ and `sdkFeatures.deviceSensors = 1`. Declare only the channels used in
43
+ `manifest.deviceCapabilities`: `location`, `motion`, `orientation`.
44
+ Vault UI can also use `useFlapSdk().device`; standalone Mini Apps can use
45
+ `useMiniAppSdk().device`. Each channel provides `getSnapshot()`,
46
+ `subscribe(listener)`, `request(options?)` and `stop()`.
47
+
48
+ Call `request()` directly from a user click. Mounting or subscribing never
49
+ requests permission or starts collection. Permission and actual data are
50
+ separate: use readings only after `status === "active"` and non-null data.
51
+ Handle refusal, unsupported/insecure environments, policy restrictions,
52
+ timeout, missing data and background pauses with usable click/touch/manual
53
+ fallbacks. Location is a system estimate; inspect accuracy and timestamp.
54
+
55
+ The `./host` entry exports `createBrowserDeviceSensors` and
56
+ `createMockDeviceSensors`; providers accept a host-owned `deviceSensors`
57
+ adapter and scope it to the declaration. Mock values are explicitly marked.
58
+ Components cannot create adapters or call raw browser permission APIs.
59
+ Old manifests without device declarations retain their behavior and do not
60
+ request permissions. Phone and wallet support still requires real-device tests.
61
+
62
+ This package is an explicit next-channel testing release. Install its exact version; stable latest and deployed hosts are not upgraded by this publication.
63
+
64
+
65
+ ## FSI queries
66
+
67
+ Declare `https://fsi.taxed.fun/fsi/v1` in `manifest.endpoints` to use
68
+ `sdk.readFsi(relativePath, params)` with the current FSI host. The legacy
69
+ `https://bsc-debug.butterfly.army/fsi/v1` prefix remains supported. Only
70
+ declaring the legacy prefix preserves legacy routing; declaring both selects
71
+ the current host regardless of array order. Failed requests never fall back
72
+ to the other host. Both require an exact reviewed root declaration and retain
73
+ the HTTPS origin, path, GET, credential and redirect restrictions.
74
+ Hosts and Workbench must deploy matching runtime and checker policies before
75
+ accepting source packages that declare the new endpoint.
76
+
20
77
  ## Shared Vault UI and Mini App v2
21
78
 
22
- The preview channel includes standalone App wallet operations through
79
+ This shared runtime supports standalone App wallet operations through
23
80
  `useFlapSdk({ chainId })` and the host-owned `CopyButton` from `./ui`.
24
81
  Vault UI keeps `useFlapSdk()` and its token-bound context. Both use this one
25
82
  package; existing token-bound Mini Apps remain compatible.
83
+ Stable development uses the official main template and npm latest.
84
+ The shared CopyButton copies up to 1,048,576 UTF-16 code units without truncation.
26
85
 
27
86
  ## Dynamic IPFS content
28
87
 
@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';
12
12
 
13
13
  var RuntimeContext = createContext(null);
14
14
  var MiniAppContext = createContext(null);
15
+ var MiniAppRoutingContext = createContext(null);
15
16
  function useFlapSdk(options) {
16
17
  const vault = useContext(RuntimeContext);
17
18
  const app = useContext(MiniAppContext);
@@ -1655,7 +1656,7 @@ function ConsumerVideoSessionPlayer({ consumer, startClip = 0, label, fallback =
1655
1656
  }, [reader, startClip]);
1656
1657
  React10.useEffect(() => {
1657
1658
  if (!videoRef.current) return;
1658
- const controller = new VideoSessionController(videoRef.current, async () => (await import('./mpegts-J2J6JTD7.js')).default, setMediaState);
1659
+ const controller = new VideoSessionController(videoRef.current, async () => (await import('./mpegts-6MFVUHRP.js')).default, setMediaState);
1659
1660
  controllerRef.current = controller;
1660
1661
  return () => {
1661
1662
  controller.dispose();
@@ -1915,7 +1916,7 @@ function VideoSessionPlayer(props) {
1915
1916
  return "consumer" in props && props.consumer !== void 0 ? /* @__PURE__ */ jsx(ConsumerVideoSessionPlayer, { ...props }) : /* @__PURE__ */ jsx(VideoClipSessionPlayer, { ...props });
1916
1917
  }
1917
1918
  async function loadMpegts() {
1918
- return (await import('./mpegts-J2J6JTD7.js')).default;
1919
+ return (await import('./mpegts-6MFVUHRP.js')).default;
1919
1920
  }
1920
1921
  function VideoClipSessionPlayer({ clips, label, fallback = null, className, autoPlay = false, muted = false }) {
1921
1922
  const videoRef = React10.useRef(null);
@@ -1953,6 +1954,206 @@ function VideoClipSessionPlayer({ clips, label, fallback = null, className, auto
1953
1954
  ] });
1954
1955
  }
1955
1956
 
1956
- export { AddressLink, Alert, BinanceImage, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, CopyButton, Countdown, DataRow, DetailTile, ExternalLink2 as ExternalLink, Input, IpfsBackground, IpfsImage, IpfsText, Metric, MiniAppContext, NftMetadataImage, ReviewedFrame, RuntimeContext, StatusBadge, TxButton, VaultBanner, VideoSessionPlayer, VideoSessionReadError, buttonVariants, createConsumerVideoSessionReader, readVideoSessionLength, readVideoSessionSlice, useFlapI18n, useFlapNotify, useFlapSdk, useVaultContext };
1957
- //# sourceMappingURL=chunk-NWBIKFHH.js.map
1958
- //# sourceMappingURL=chunk-NWBIKFHH.js.map
1957
+ // src/ui/streetMapPolicy.ts
1958
+ var STREET_MAP_WORKER_PATH = "/runtime-map/maplibre-6.15.0-worker.mjs";
1959
+ var STREET_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
1960
+ var STREET_MAP_MAX_POINTS = 2e3;
1961
+ function validStreetMapCoordinate(value) {
1962
+ if (!value || typeof value !== "object") return false;
1963
+ const coordinate = value;
1964
+ return Number.isFinite(coordinate.lat) && Math.abs(coordinate.lat) <= 85.051129 && Number.isFinite(coordinate.lng) && Math.abs(coordinate.lng) <= 180;
1965
+ }
1966
+ function validStreetMapPoints(value) {
1967
+ if (!Array.isArray(value) || value.length > STREET_MAP_MAX_POINTS) return false;
1968
+ const ids = /* @__PURE__ */ new Set();
1969
+ for (const point of value) {
1970
+ if (!validStreetMapCoordinate(point)) return false;
1971
+ const item = point;
1972
+ if (typeof item.id !== "string" || !item.id.length || item.id.length > 128 || ids.has(item.id) || typeof item.title !== "string" || item.title.length > 256 || item.rarity !== void 0 && !["common", "rare", "epic", "legendary"].includes(item.rarity)) return false;
1973
+ ids.add(item.id);
1974
+ }
1975
+ return true;
1976
+ }
1977
+ function streetMapZoom(value) {
1978
+ return value === void 0 ? 12 : Math.min(18, Math.max(3, value));
1979
+ }
1980
+ function streetMapRequest(url) {
1981
+ if (typeof url !== "string" || url.length > 1024) throw new Error("street-map/resource-blocked");
1982
+ const parsed = new URL(url);
1983
+ if (parsed.origin !== "https://tiles.openfreemap.org" || parsed.username || parsed.password || parsed.search || parsed.hash || /[\\\u0000-\u0020]/.test(url) || /%(?:2f|5c|2e|00)/i.test(parsed.pathname)) throw new Error("street-map/resource-blocked");
1984
+ const pathname = parsed.pathname;
1985
+ const allowed = pathname === "/styles/dark" || pathname === "/planet" || /^\/planet\/\d{8}_\d{6}_pt\/\d{1,2}\/\d{1,6}\/\d{1,6}\.pbf$/.test(pathname) || /^\/natural_earth\/ne2sr\/[0-6]\/\d{1,2}\/\d{1,2}\.png$/.test(pathname) || /^\/sprites\/ofm_[a-zA-Z0-9]{1,32}\/ofm(?:@2x)?\.(?:json|png)$/.test(pathname) || /^\/fonts\/[a-zA-Z0-9_,%+.-]{1,256}\/\d{1,7}-\d{1,7}\.pbf$/.test(pathname);
1986
+ if (!allowed) throw new Error("street-map/resource-blocked");
1987
+ return { url: parsed.href, credentials: "omit", referrerPolicy: "no-referrer" };
1988
+ }
1989
+ function streetMapPointData(points) {
1990
+ return { type: "FeatureCollection", features: points.map((point) => ({
1991
+ type: "Feature",
1992
+ geometry: { type: "Point", coordinates: [point.lng, point.lat] },
1993
+ // Titles stay React text in fallbacks. Never expose HTML or remote attribution.
1994
+ properties: { id: point.id, rarity: point.rarity ?? "common" }
1995
+ })) };
1996
+ }
1997
+ function streetMapLocationData(location) {
1998
+ return { type: "FeatureCollection", features: location ? [{ type: "Feature", geometry: { type: "Point", coordinates: [location.lng, location.lat] }, properties: {} }] : [] };
1999
+ }
2000
+ var EMPTY_POINTS = [];
2001
+ var DEFAULT_CENTER = { lat: 31.2304, lng: 121.4737 };
2002
+ var MAP_CSS = `.flap-street-map{position:relative;width:100%;min-height:400px;background:var(--background,#070808);overflow:hidden}.flap-street-map__canvas{position:absolute;inset:0}.flap-street-map .maplibregl-canvas{position:absolute;left:0;top:0}.flap-street-map .maplibregl-canvas-container{position:absolute;inset:0}.flap-street-map .maplibregl-interactive{cursor:grab;user-select:none;-webkit-user-select:none;touch-action:none}.flap-street-map .maplibregl-interactive:active{cursor:grabbing}.flap-street-map__fallback{position:relative;padding:16px}.flap-street-map__fallback button{display:block;text-align:left;color:inherit}.flap-street-map__attribution{position:absolute;bottom:0;right:0;z-index:1;padding:2px 5px;background:var(--background,#070808);color:var(--muted-foreground,#a3a3a3);font:10px/1.5 sans-serif}.flap-street-map__attribution a{color:inherit;text-decoration:underline}`;
2003
+ function FlapStreetMap({ points = EMPTY_POINTS, center, userLocation, zoom, onSelectPoint, onStateChange, fallback, className }) {
2004
+ const vault = React10.useContext(RuntimeContext), app = React10.useContext(MiniAppContext);
2005
+ const declared = (app ?? vault)?.context.manifest.mapCapabilities?.includes("street-map-v1") === true;
2006
+ const valid = validStreetMapPoints(points) && (center === void 0 || validStreetMapCoordinate(center)) && (userLocation == null || validStreetMapCoordinate(userLocation)) && (zoom === void 0 || Number.isFinite(zoom));
2007
+ const containerRef = React10.useRef(null);
2008
+ const mapRef = React10.useRef(null);
2009
+ const failRef = React10.useRef(null);
2010
+ const latest = React10.useRef({ points, center, userLocation, zoom, onSelectPoint, onStateChange });
2011
+ latest.current = { points, center, userLocation, zoom, onSelectPoint, onStateChange };
2012
+ const [state, setState] = React10.useState({ status: "loading" });
2013
+ React10.useEffect(() => {
2014
+ let disposed = false;
2015
+ let failed = false;
2016
+ let map = null;
2017
+ let resize;
2018
+ let timeout;
2019
+ let canvas;
2020
+ const emit = (next) => {
2021
+ if (disposed) return;
2022
+ setState(next);
2023
+ try {
2024
+ latest.current.onStateChange?.(next);
2025
+ } catch {
2026
+ console.error("FlapStreetMap onStateChange failed.");
2027
+ }
2028
+ };
2029
+ const cleanMap = () => {
2030
+ if (timeout) clearTimeout(timeout);
2031
+ resize?.disconnect();
2032
+ canvas?.removeEventListener("webglcontextlost", contextLost);
2033
+ if (map) {
2034
+ const previous = map;
2035
+ map = null;
2036
+ if (mapRef.current === previous) mapRef.current = null;
2037
+ previous.remove();
2038
+ }
2039
+ };
2040
+ const fail = (reason) => {
2041
+ if (disposed || failed) return;
2042
+ failed = true;
2043
+ cleanMap();
2044
+ emit({ status: "unavailable", reason });
2045
+ };
2046
+ const contextLost = () => fail("context-lost");
2047
+ failRef.current = fail;
2048
+ if (!declared || !valid) {
2049
+ emit({ status: "unavailable", reason: declared ? "invalid-input" : "not-declared" });
2050
+ return () => {
2051
+ disposed = true;
2052
+ if (failRef.current === fail) failRef.current = null;
2053
+ };
2054
+ }
2055
+ emit({ status: "loading" });
2056
+ const mount = containerRef.current;
2057
+ let supported = typeof Worker === "function";
2058
+ try {
2059
+ const probe = document.createElement("canvas");
2060
+ const context = supported ? probe.getContext("webgl2") : null;
2061
+ supported = !!context;
2062
+ context?.getExtension("WEBGL_lose_context")?.loseContext();
2063
+ } catch {
2064
+ supported = false;
2065
+ }
2066
+ if (!supported || !mount) fail("unsupported");
2067
+ else {
2068
+ timeout = setTimeout(() => fail("timeout"), 15e3);
2069
+ void import('./maplibre-gl-5HQYASCY.js').then((engine) => {
2070
+ if (disposed || failed || !containerRef.current || containerRef.current !== mount) return;
2071
+ engine.setWorkerUrl(STREET_MAP_WORKER_PATH);
2072
+ engine.setWorkerCount(2);
2073
+ const current = latest.current;
2074
+ const initial = current.center ?? current.userLocation ?? DEFAULT_CENTER;
2075
+ map = new engine.Map({
2076
+ container: mount,
2077
+ style: STREET_MAP_STYLE,
2078
+ center: [initial.lng, initial.lat],
2079
+ zoom: streetMapZoom(current.zoom),
2080
+ minZoom: 3,
2081
+ maxZoom: 18,
2082
+ attributionControl: false,
2083
+ maxTileCacheSize: 128,
2084
+ // MapLibre forwards this to fetch. Its public type currently omits the
2085
+ // valid Fetch credentials="omit" value; no cookie/header is provided.
2086
+ transformRequest: (url) => streetMapRequest(url)
2087
+ });
2088
+ mapRef.current = map;
2089
+ canvas = map.getCanvas();
2090
+ canvas.addEventListener("webglcontextlost", contextLost);
2091
+ map.on("error", () => fail("load-failed"));
2092
+ map.on("load", () => {
2093
+ if (disposed || failed || !map) return;
2094
+ try {
2095
+ map.addSource("flap-points", { type: "geojson", data: streetMapPointData(latest.current.points) });
2096
+ map.addLayer({ id: "flap-points-glow", type: "circle", source: "flap-points", paint: { "circle-radius": 14, "circle-color": "#f59e0b", "circle-opacity": 0.25, "circle-blur": 0.6 } });
2097
+ map.addLayer({ id: "flap-points-core", type: "circle", source: "flap-points", paint: { "circle-radius": 6, "circle-color": "#fbbf24", "circle-stroke-width": 1.5, "circle-stroke-color": "#000000" } });
2098
+ map.addSource("flap-location", { type: "geojson", data: streetMapLocationData(latest.current.userLocation) });
2099
+ map.addLayer({ id: "flap-location-dot", type: "circle", source: "flap-location", paint: { "circle-radius": 7, "circle-color": "#38bdf8", "circle-stroke-width": 2, "circle-stroke-color": "#ffffff" } });
2100
+ map.on("click", "flap-points-core", (event) => {
2101
+ const id = event.features?.[0]?.properties?.id;
2102
+ if (typeof id === "string" && latest.current.points.some((point) => point.id === id)) {
2103
+ try {
2104
+ latest.current.onSelectPoint?.(id);
2105
+ } catch {
2106
+ console.error("FlapStreetMap onSelectPoint failed.");
2107
+ }
2108
+ }
2109
+ });
2110
+ if (timeout) clearTimeout(timeout);
2111
+ if (latest.current.center) map.jumpTo({ center: [latest.current.center.lng, latest.current.center.lat], zoom: streetMapZoom(latest.current.zoom) });
2112
+ else if (latest.current.zoom !== void 0) map.setZoom(streetMapZoom(latest.current.zoom));
2113
+ emit({ status: "ready" });
2114
+ } catch {
2115
+ fail("load-failed");
2116
+ }
2117
+ });
2118
+ if (typeof ResizeObserver === "function") {
2119
+ resize = new ResizeObserver(() => map?.resize());
2120
+ resize.observe(mount);
2121
+ }
2122
+ }).catch(() => fail("load-failed"));
2123
+ }
2124
+ return () => {
2125
+ disposed = true;
2126
+ if (failRef.current === fail) failRef.current = null;
2127
+ cleanMap();
2128
+ };
2129
+ }, [declared, valid]);
2130
+ React10.useEffect(() => {
2131
+ const map = mapRef.current;
2132
+ if (!valid || !map || !map.getSource("flap-points")) return;
2133
+ try {
2134
+ map.getSource("flap-points")?.setData(streetMapPointData(points));
2135
+ map.getSource("flap-location")?.setData(streetMapLocationData(userLocation));
2136
+ if (center) map.jumpTo({ center: [center.lng, center.lat], ...zoom === void 0 ? {} : { zoom: streetMapZoom(zoom) } });
2137
+ else if (zoom !== void 0) map.setZoom(streetMapZoom(zoom));
2138
+ } catch {
2139
+ failRef.current?.("load-failed");
2140
+ }
2141
+ }, [points, center, userLocation, zoom, valid]);
2142
+ const visibleState = !declared ? { status: "unavailable", reason: "not-declared" } : !valid ? { status: "unavailable", reason: "invalid-input" } : state;
2143
+ return /* @__PURE__ */ jsxs("div", { className: ["flap-street-map", className].filter(Boolean).join(" "), "data-flap-ui": "street-map", "data-map-state": visibleState.status, "data-map-reason": visibleState.reason, children: [
2144
+ /* @__PURE__ */ jsx("style", { children: MAP_CSS }),
2145
+ /* @__PURE__ */ jsx("div", { ref: containerRef, className: "flap-street-map__canvas", "aria-hidden": visibleState.status !== "ready", style: { visibility: visibleState.status === "ready" ? "visible" : "hidden" } }),
2146
+ visibleState.status !== "ready" && /* @__PURE__ */ jsx("div", { className: "flap-street-map__fallback", children: fallback ?? (validStreetMapPoints(points) ? points.map((point) => /* @__PURE__ */ jsx("button", { type: "button", onClick: () => onSelectPoint?.(point.id), children: point.title }, point.id)) : null) }),
2147
+ /* @__PURE__ */ jsxs("div", { className: "flap-street-map__attribution", children: [
2148
+ /* @__PURE__ */ jsx("a", { href: "https://openfreemap.org/", target: "_blank", rel: "noopener noreferrer", children: "OpenFreeMap" }),
2149
+ " \xB7 ",
2150
+ /* @__PURE__ */ jsx("a", { href: "https://openmaptiles.org/", target: "_blank", rel: "noopener noreferrer", children: "OpenMapTiles" }),
2151
+ " \xB7 ",
2152
+ /* @__PURE__ */ jsx("a", { href: "https://www.openstreetmap.org/copyright", target: "_blank", rel: "noopener noreferrer", children: "\xA9 OpenStreetMap" })
2153
+ ] })
2154
+ ] });
2155
+ }
2156
+
2157
+ export { AddressLink, Alert, BinanceImage, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, CopyButton, Countdown, DataRow, DetailTile, ExternalLink2 as ExternalLink, FlapStreetMap, Input, IpfsBackground, IpfsImage, IpfsText, Metric, MiniAppContext, MiniAppRoutingContext, NftMetadataImage, ReviewedFrame, RuntimeContext, StatusBadge, TxButton, VaultBanner, VideoSessionPlayer, VideoSessionReadError, buttonVariants, createConsumerVideoSessionReader, readVideoSessionLength, readVideoSessionSlice, useFlapI18n, useFlapNotify, useFlapSdk, useVaultContext };
2158
+ //# sourceMappingURL=chunk-2K4HG2TC.js.map
2159
+ //# sourceMappingURL=chunk-2K4HG2TC.js.map