@flighthq/geolocation 0.5.1-next.920.da8f530 → 0.7.0-edge.5213.ead804b

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
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/geolocation`. The `@
13
13
  This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
14
14
 
15
15
  - [Flight project](https://github.com/flighthq/flight)
16
- - [Source for @flighthq/geolocation@0.5.1-next.920.da8f530](https://github.com/flighthq/flight/tree/da8f530894916f9baa6a9f6822b4f393b9e70a85/packages/geolocation)
17
- - [License](https://github.com/flighthq/flight/blob/da8f530894916f9baa6a9f6822b4f393b9e70a85/LICENSE.md)
16
+ - [Source for @flighthq/geolocation@0.7.0-edge.5213.ead804b](https://github.com/flighthq/flight/tree/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/packages/geolocation)
17
+ - [License](https://github.com/flighthq/flight/blob/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/LICENSE.md)
@@ -1,4 +1,5 @@
1
- export * from './geolocation';
2
- export * from './geolocationAccess';
3
- export { initializeGeoPosition, initializeWebGeolocationBackend } from './geolocation';
1
+ export * from './geolocation.ts';
2
+ export * from './geolocationAccess.ts';
3
+ export { initializeGeolocationPosition } from './geolocation.ts';
4
+ export type * from './types.ts';
4
5
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,mBAAmB,YAAY,CAAC"}
package/dist/contract.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './geolocation';
2
- export * from './geolocationAccess';
3
- export { initializeGeoPosition, initializeWebGeolocationBackend } from './geolocation';
1
+ export * from './geolocation.js';
2
+ export * from './geolocationAccess.js';
3
+ export { initializeGeolocationPosition } from './geolocation.js';
4
4
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,11 +1,10 @@
1
- import type { GeolocationBackend, GeolocationErrorReason, GeolocationRequestOptions, GeoPosition, GeoPositionResult, HasSystemGeolocation, EntityConstruction } from '@flighthq/types/contract';
2
- export declare function clearGeolocationWatch(host: Readonly<HasSystemGeolocation>, id: number): void;
3
- export declare function createGeoPosition(): GeoPosition;
4
- export declare function createWebGeolocationBackend(): GeolocationBackend;
5
- export declare function getCurrentGeoPosition(host: Readonly<HasSystemGeolocation>, options?: Readonly<GeolocationRequestOptions>): Promise<GeoPosition | null>;
6
- export declare function getCurrentGeoPositionResult(host: Readonly<HasSystemGeolocation>, options?: Readonly<GeolocationRequestOptions>): Promise<GeoPositionResult>;
7
- export declare function initializeGeoPosition(out: EntityConstruction<GeoPosition>): void;
8
- export declare function initializeWebGeolocationBackend(out: EntityConstruction<GeolocationBackend>): void;
9
- export declare function isGeolocationAvailable(host: Readonly<HasSystemGeolocation>): boolean;
10
- export declare function watchGeolocationPosition(host: Readonly<HasSystemGeolocation>, handler: (position: Readonly<GeoPosition>) => void, options?: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
1
+ import type { EntityConstruction } from '@flighthq/entity/contract';
2
+ import type { HostGeolocationCapability, GeolocationErrorReason, GeolocationPosition as FlightGeolocationPosition, GeolocationPositionResult, GeolocationRequestOptions } from './types.ts';
3
+ export declare function clearGeolocationWatch(hostGeolocation: Readonly<HostGeolocationCapability>, id: number): void;
4
+ export declare function createGeolocationPosition(): FlightGeolocationPosition;
5
+ export declare function getCurrentGeolocationPosition(hostGeolocation: Readonly<HostGeolocationCapability>, options?: Readonly<GeolocationRequestOptions>): Promise<FlightGeolocationPosition | null>;
6
+ export declare function getCurrentGeolocationPositionResult(hostGeolocation: Readonly<HostGeolocationCapability>, options?: Readonly<GeolocationRequestOptions>): Promise<GeolocationPositionResult>;
7
+ export declare function initializeGeolocationPosition(out: EntityConstruction<FlightGeolocationPosition>): void;
8
+ export declare function isGeolocationAvailable(hostGeolocation: Readonly<HostGeolocationCapability>): boolean;
9
+ export declare function watchGeolocationPosition(hostGeolocation: Readonly<HostGeolocationCapability>, handler: (position: Readonly<FlightGeolocationPosition>) => void, options?: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
11
10
  //# sourceMappingURL=geolocation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAE5F;AAED,wBAAgB,iBAAiB,IAAI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,CAAC,yBAAyB,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAE5G;AAED,wBAAgB,yBAAyB,IAAI,yBAAyB,CAIrE;AAED,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EACpD,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC5C,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAE3C;AAED,wBAAgB,mCAAmC,CACjD,eAAe,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EACpD,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC5C,OAAO,CAAC,yBAAyB,CAAC,CAEpC;AAED,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAUtG;AAED,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAEpG;AAED,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EACpD,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,yBAAyB,CAAC,KAAK,IAAI,EAChE,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EAC7C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,GACjD,MAAM,CAER"}
@@ -1,24 +1,19 @@
1
- import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
- export function clearGeolocationWatch(host, id) {
3
- host.system.geolocation.clearWatch(id);
1
+ import { allocateEntity } from '@flighthq/entity/contract';
2
+ export function clearGeolocationWatch(hostGeolocation, id) {
3
+ hostGeolocation.clearWatch(id);
4
4
  }
5
- export function createGeoPosition() {
5
+ export function createGeolocationPosition() {
6
6
  const out = allocateEntity();
7
- initializeGeoPosition(out);
8
- return finishEntity(out);
7
+ initializeGeolocationPosition(out);
8
+ return out;
9
9
  }
10
- export function createWebGeolocationBackend() {
11
- const out = allocateEntity();
12
- initializeWebGeolocationBackend(out);
13
- return finishEntity(out);
14
- }
15
- export function getCurrentGeoPosition(host, options) {
16
- return host.system.geolocation.getCurrentPosition(options ?? _emptyOptions);
10
+ export function getCurrentGeolocationPosition(hostGeolocation, options) {
11
+ return hostGeolocation.getCurrentPosition(options ?? _emptyOptions);
17
12
  }
18
- export function getCurrentGeoPositionResult(host, options) {
19
- return host.system.geolocation.getCurrentPositionResult(options ?? _emptyOptions);
13
+ export function getCurrentGeolocationPositionResult(hostGeolocation, options) {
14
+ return hostGeolocation.getCurrentPositionResult(options ?? _emptyOptions);
20
15
  }
21
- export function initializeGeoPosition(out) {
16
+ export function initializeGeolocationPosition(out) {
22
17
  out.accuracy = 0;
23
18
  out.altitude = 0;
24
19
  out.altitudeAccuracy = 0;
@@ -29,131 +24,11 @@ export function initializeGeoPosition(out) {
29
24
  out.speed = 0;
30
25
  out.timestamp = 0;
31
26
  }
32
- export function initializeWebGeolocationBackend(out) {
33
- out.clearWatch = (id) => {
34
- const geo = getWebGeolocation();
35
- if (geo === null || typeof geo.clearWatch !== 'function')
36
- return;
37
- try {
38
- geo.clearWatch(id);
39
- }
40
- catch {
41
- // Expected failure: the watch may already be gone or the host may deny access.
42
- }
43
- };
44
- out.getCurrentPosition = (options) => {
45
- return new Promise((resolve) => {
46
- const geo = getWebGeolocation();
47
- if (geo === null || typeof geo.getCurrentPosition !== 'function') {
48
- resolve(null);
49
- return;
50
- }
51
- try {
52
- geo.getCurrentPosition((position) => resolve(mapWebPosition(position)), () => resolve(null), toPositionOptions(options));
53
- }
54
- catch {
55
- resolve(null);
56
- }
57
- });
58
- };
59
- out.getCurrentPositionResult = (options) => {
60
- return new Promise((resolve) => {
61
- const geo = getWebGeolocation();
62
- if (geo === null || typeof geo.getCurrentPosition !== 'function') {
63
- resolve({ position: null, reason: 'unavailable' });
64
- return;
65
- }
66
- try {
67
- geo.getCurrentPosition((position) => resolve({ position: mapWebPosition(position), reason: null }), (error) => resolve({ position: null, reason: mapWebPositionError(error) }), toPositionOptions(options));
68
- }
69
- catch {
70
- resolve({ position: null, reason: 'unavailable' });
71
- }
72
- });
73
- };
74
- out.isAvailable = () => {
75
- if (typeof window !== 'undefined' && window.isSecureContext === false)
76
- return false;
77
- return getWebGeolocation() !== null;
78
- };
79
- out.promptForAccess = () => {
80
- return new Promise((resolve) => {
81
- const geo = getWebGeolocation();
82
- if (geo === null || typeof geo.getCurrentPosition !== 'function') {
83
- resolve({ reason: 'runtime-unavailable' });
84
- return;
85
- }
86
- try {
87
- geo.getCurrentPosition(() => resolve({ reason: 'granted' }), (error) => resolve({ reason: mapWebAccessError(error) }));
88
- }
89
- catch {
90
- resolve({ reason: 'operation-failed' });
91
- }
92
- });
93
- };
94
- out.watchPosition = (listener, options, onError) => {
95
- const geo = getWebGeolocation();
96
- if (geo === null || typeof geo.watchPosition !== 'function')
97
- return -1;
98
- try {
99
- return geo.watchPosition((position) => listener(mapWebPosition(position)), onError !== undefined ? (error) => onError(mapWebPositionError(error)) : () => { }, toPositionOptions(options));
100
- }
101
- catch {
102
- return -1;
103
- }
104
- };
105
- }
106
- export function isGeolocationAvailable(host) {
107
- return host.system.geolocation.isAvailable();
27
+ export function isGeolocationAvailable(hostGeolocation) {
28
+ return hostGeolocation.isAvailable();
108
29
  }
109
- export function watchGeolocationPosition(host, handler, options, onError) {
110
- return host.system.geolocation.watchPosition(handler, options ?? _emptyOptions, onError);
30
+ export function watchGeolocationPosition(hostGeolocation, handler, options, onError) {
31
+ return hostGeolocation.watchPosition(handler, options ?? _emptyOptions, onError);
111
32
  }
112
33
  const _emptyOptions = {};
113
- function getWebGeolocation() {
114
- if (typeof navigator === 'undefined')
115
- return null;
116
- return navigator.geolocation ?? null;
117
- }
118
- function mapWebPosition(position) {
119
- const coords = position.coords;
120
- const out = allocateEntity();
121
- out.accuracy = coords.accuracy;
122
- out.altitude = coords.altitude ?? 0;
123
- out.altitudeAccuracy = coords.altitudeAccuracy ?? 0;
124
- out.floorLevel = coords.floorLevel ?? 0;
125
- out.heading = coords.heading ?? 0;
126
- out.latitude = coords.latitude;
127
- out.longitude = coords.longitude;
128
- out.speed = coords.speed ?? 0;
129
- out.timestamp = position.timestamp;
130
- return finishEntity(out);
131
- }
132
- function mapWebAccessError(error) {
133
- switch (error.code) {
134
- case 1:
135
- return 'denied';
136
- case 3:
137
- return 'timeout';
138
- default:
139
- return 'operation-failed';
140
- }
141
- }
142
- function mapWebPositionError(error) {
143
- switch (error.code) {
144
- case 1:
145
- return 'denied';
146
- case 3:
147
- return 'timeout';
148
- default:
149
- return 'unavailable';
150
- }
151
- }
152
- function toPositionOptions(options) {
153
- return {
154
- enableHighAccuracy: options.enableHighAccuracy ?? false,
155
- maximumAge: options.maximumAgeMs,
156
- timeout: options.timeoutMs,
157
- };
158
- }
159
34
  //# sourceMappingURL=geolocation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAYzE,MAAM,UAAU,qBAAqB,CAAC,IAAoC,EAAE,EAAU;IACpF,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,GAAG,GAAG,cAAc,EAAe,CAAC;IAC1C,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,MAAM,GAAG,GAAG,cAAc,EAAsB,CAAC;IACjD,+BAA+B,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAoC,EACpC,OAA6C;IA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 +1,4 @@
1
- import type { GeolocationAccessOutcome, Host } from '@flighthq/types/contract';
1
+ import type { GeolocationAccessOutcome, HostGeolocationCapability } from './types.ts';
2
2
  /**
3
3
  * Raises the platform's own location-access prompt through the host's geolocation provider.
4
4
  *
@@ -10,5 +10,5 @@ import type { GeolocationAccessOutcome, Host } from '@flighthq/types/contract';
10
10
  * Reports `runtime-unavailable` rather than throwing when no provider is installed: an absent host
11
11
  * capability is an expected outcome, not API misuse.
12
12
  */
13
- export declare function promptForGeolocationAccess(host: Readonly<Host>): Promise<GeolocationAccessOutcome>;
13
+ export declare function promptForGeolocationAccess(hostGeolocation: Readonly<HostGeolocationCapability> | undefined): Promise<GeolocationAccessOutcome>;
14
14
  //# sourceMappingURL=geolocationAccess.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geolocationAccess.d.ts","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAUxG"}
1
+ {"version":3,"file":"geolocationAccess.d.ts","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC9C,eAAe,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,SAAS,GAC/D,OAAO,CAAC,wBAAwB,CAAC,CASnC"}
@@ -9,13 +9,12 @@
9
9
  * Reports `runtime-unavailable` rather than throwing when no provider is installed: an absent host
10
10
  * capability is an expected outcome, not API misuse.
11
11
  */
12
- export async function promptForGeolocationAccess(host) {
13
- const backend = host.system?.geolocation;
14
- if (backend === undefined || typeof backend.promptForAccess !== 'function') {
12
+ export async function promptForGeolocationAccess(hostGeolocation) {
13
+ if (hostGeolocation === undefined || typeof hostGeolocation.promptForAccess !== 'function') {
15
14
  return { reason: 'runtime-unavailable' };
16
15
  }
17
16
  try {
18
- return await backend.promptForAccess();
17
+ return await hostGeolocation.promptForAccess();
19
18
  }
20
19
  catch {
21
20
  return { reason: 'operation-failed' };
@@ -1 +1 @@
1
- {"version":3,"file":"geolocationAccess.js","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,IAAoB;IACnE,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC;IACzC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QAC3E,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACxC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"geolocationAccess.js","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,eAAgE;IAEhE,IAAI,eAAe,KAAK,SAAS,IAAI,OAAO,eAAe,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QAC3F,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,eAAe,CAAC,eAAe,EAAE,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACxC,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract';
1
+ export { clearGeolocationWatch, createGeolocationPosition, getCurrentGeolocationPosition, getCurrentGeolocationPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract.ts';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,mCAAmC,EACnC,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract';
1
+ export { clearGeolocationWatch, createGeolocationPosition, getCurrentGeolocationPosition, getCurrentGeolocationPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract.js';
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,mCAAmC,EACnC,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { EntityRaw, EntityRuntime, EntityRuntimeKey } from '@flighthq/entity/contract';
2
+ export interface GeolocationPosition extends EntityRaw {
3
+ [EntityRuntimeKey]: EntityRuntime | undefined;
4
+ latitude: number;
5
+ longitude: number;
6
+ accuracy: number;
7
+ altitude: number;
8
+ altitudeAccuracy: number;
9
+ floorLevel: number;
10
+ heading: number;
11
+ speed: number;
12
+ timestamp: number;
13
+ }
14
+ export type GeolocationErrorReason = 'denied' | 'timeout' | 'unavailable';
15
+ export interface GeolocationPositionResult {
16
+ position: GeolocationPosition | null;
17
+ reason: GeolocationErrorReason | null;
18
+ }
19
+ export interface GeolocationRequestOptions {
20
+ enableHighAccuracy?: boolean;
21
+ timeoutMs?: number;
22
+ maximumAgeMs?: number;
23
+ }
24
+ /**
25
+ * What happened when the capability raised its own access prompt.
26
+ *
27
+ * A CAPABILITY outcome, deliberately not a `PermissionState`: only the capability can raise the
28
+ * prompt, and G6 lets it keep that mechanism precisely because what it returns carries no permission
29
+ * vocabulary. Permissions projects this into its own outcome; nothing here names a state.
30
+ *
31
+ * `timeout` is an ACQUISITION observable and says nothing about the user. It occurs routinely with
32
+ * access already granted — indoors, no fix, a slow lock — so it must never be read as a dismissal.
33
+ * Only a permission-state query can tell those apart, and the capability may not hold one; it reports
34
+ * what it saw and leaves the interpretation to the owner that can query.
35
+ *
36
+ * `cleanup-failed` means access WAS obtained and releasing the probe failed afterwards. The decision
37
+ * survives it, so it is a distinct arm rather than a failure that discards the answer.
38
+ */
39
+ export type GeolocationAccessOutcome = {
40
+ readonly reason: 'cleanup-failed' | 'denied' | 'dismissed' | 'granted' | 'operation-failed' | 'runtime-unavailable' | 'timeout';
41
+ };
42
+ export interface HostGeolocationCapability {
43
+ getCurrentPosition(options: Readonly<GeolocationRequestOptions>): Promise<GeolocationPosition | null>;
44
+ getCurrentPositionResult(options: Readonly<GeolocationRequestOptions>): Promise<GeolocationPositionResult>;
45
+ isAvailable(): boolean;
46
+ watchPosition(listener: (position: Readonly<GeolocationPosition>) => void, options: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
47
+ clearWatch(id: number): void;
48
+ promptForAccess(): Promise<GeolocationAccessOutcome>;
49
+ }
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAS5F,MAAM,WAAW,mBAAoB,SAAQ,SAAS;IACpD,CAAC,gBAAgB,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAI1E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,MAAM,EACX,gBAAgB,GAChB,QAAQ,GACR,WAAW,GACX,SAAS,GACT,kBAAkB,GAClB,qBAAqB,GACrB,SAAS,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACtG,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAE3G,WAAW,IAAI,OAAO,CAAC;IACvB,aAAa,CACX,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,mBAAmB,CAAC,KAAK,IAAI,EAC3D,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EAC5C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,GACjD,MAAM,CAAC;IACV,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAG7B,eAAe,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACtD"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/geolocation",
3
- "version": "0.5.1-next.920.da8f530",
3
+ "version": "0.7.0-edge.5213.ead804b",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,17 +32,18 @@
32
32
  "scripts": {
33
33
  "build": "tsc -b",
34
34
  "clean": "tsc -b --clean",
35
+ "generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-geolocation --package geolocation",
36
+ "generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-geolocation --package geolocation --check",
35
37
  "test": "vitest run --config vitest.config.ts",
36
38
  "test:watch": "vitest --watch --config vitest.config.ts",
37
39
  "prepack": "npm run clean && npm run clean:dist && npm run build",
38
40
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
41
  },
40
42
  "dependencies": {
41
- "@flighthq/entity": "0.5.1-next.920.da8f530",
42
- "@flighthq/types": "0.5.1-next.920.da8f530"
43
+ "@flighthq/entity": "0.7.0-edge.5213.ead804b"
43
44
  },
44
45
  "devDependencies": {
45
- "typescript": "^5.3.0"
46
+ "typescript": "^7.0.2"
46
47
  },
47
48
  "description": "Device geolocation (current position, watch, permission) over a swappable web/native backend",
48
49
  "sideEffects": false
@@ -1,27 +1,19 @@
1
- import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
- import type {
3
- Entity,
4
- GeolocationBackend,
5
- GeolocationErrorReason,
6
- GeoPosition,
7
- HasSystemGeolocation,
8
- } from '@flighthq/types/contract';
9
- import { EntityRuntimeKey } from '@flighthq/types/contract';
1
+ import { allocateEntity } from '@flighthq/entity/contract';
2
+ import { EntityRuntimeKey } from '@flighthq/entity/contract';
10
3
 
11
4
  import {
12
5
  clearGeolocationWatch,
13
- createGeoPosition,
14
- createWebGeolocationBackend,
15
- getCurrentGeoPosition,
16
- getCurrentGeoPositionResult,
17
- initializeGeoPosition,
18
- initializeWebGeolocationBackend,
6
+ createGeolocationPosition,
7
+ getCurrentGeolocationPosition,
8
+ getCurrentGeolocationPositionResult,
9
+ initializeGeolocationPosition,
19
10
  isGeolocationAvailable,
20
11
  watchGeolocationPosition,
21
- } from './geolocation';
12
+ } from './geolocation.ts';
13
+ import type { HostGeolocationCapability, GeolocationErrorReason, GeolocationPosition } from './types.ts';
22
14
 
23
- function fakeBackend(available: boolean = true): GeolocationBackend & { cleared: number[]; lastWatch: number } {
24
- const out = allocateEntity<any>();
15
+ function fakeBackend(available: boolean = true): HostGeolocationCapability & { cleared: number[]; lastWatch: number } {
16
+ const out = allocateEntity<any>() as any;
25
17
  out.cleared = [];
26
18
  out.lastWatch = 0;
27
19
  out.promptForAccess = () => Promise.resolve({ reason: 'granted' as const });
@@ -29,13 +21,13 @@ function fakeBackend(available: boolean = true): GeolocationBackend & { cleared:
29
21
  out.cleared.push(id);
30
22
  };
31
23
  out.getCurrentPosition = async () => {
32
- const position = createGeoPosition();
24
+ const position = createGeolocationPosition();
33
25
  position.latitude = 1;
34
26
  position.longitude = 2;
35
27
  return position;
36
28
  };
37
29
  out.getCurrentPositionResult = async () => {
38
- const position = createGeoPosition();
30
+ const position = createGeolocationPosition();
39
31
  position.latitude = 1;
40
32
  position.longitude = 2;
41
33
  return { position, reason: null };
@@ -44,34 +36,38 @@ function fakeBackend(available: boolean = true): GeolocationBackend & { cleared:
44
36
  return available;
45
37
  };
46
38
  out.watchPosition = (
47
- listener: (position: GeoPosition) => void,
39
+ listener: (position: GeolocationPosition) => void,
48
40
  _options: Record<string, unknown>,
49
41
  onError?: (reason: GeolocationErrorReason) => void,
50
42
  ) => {
51
- const position = createGeoPosition();
43
+ const position = createGeolocationPosition();
52
44
  position.latitude = 3;
53
45
  listener(position);
54
46
  if (onError) onError('denied');
55
47
  return ++out.lastWatch;
56
48
  };
57
- return finishEntity(out);
49
+ return out;
58
50
  }
59
51
 
60
- function hostWith(backend: GeolocationBackend): HasSystemGeolocation {
61
- return { system: { geolocation: backend } } as HasSystemGeolocation;
52
+ function hostWith(backend: HostGeolocationCapability): {
53
+ readonly system: { readonly geolocation: HostGeolocationCapability };
54
+ } {
55
+ return { system: { geolocation: backend } } as {
56
+ readonly system: { readonly geolocation: HostGeolocationCapability };
57
+ };
62
58
  }
63
59
 
64
60
  describe('clearGeolocationWatch', () => {
65
61
  it('forwards the id to the host backend', () => {
66
62
  const backend = fakeBackend();
67
- clearGeolocationWatch(hostWith(backend), 7);
63
+ clearGeolocationWatch(hostWith(backend).system.geolocation, 7);
68
64
  expect(backend.cleared).toEqual([7]);
69
65
  });
70
66
  });
71
67
 
72
- describe('createGeoPosition', () => {
68
+ describe('createGeolocationPosition', () => {
73
69
  it('allocates a zeroed position', () => {
74
- const position = createGeoPosition();
70
+ const position = createGeolocationPosition();
75
71
  expect(Object.hasOwn(position, EntityRuntimeKey)).toBe(true);
76
72
  expect(position).toMatchObject({
77
73
  accuracy: 0,
@@ -87,115 +83,42 @@ describe('createGeoPosition', () => {
87
83
  });
88
84
  });
89
85
 
90
- describe('createWebGeolocationBackend', () => {
91
- it('resolves null and does not throw when geolocation is absent', async () => {
92
- const backend = createWebGeolocationBackend();
93
- expect(await backend.getCurrentPosition({})).toBeNull();
94
- expect(typeof backend.watchPosition(() => {}, {})).toBe('number');
95
- expect(() => backend.clearWatch(-1)).not.toThrow();
96
- });
97
-
98
- it('getCurrentPositionResult returns unavailable reason when geolocation is absent', async () => {
99
- const backend = createWebGeolocationBackend();
100
- const result = await backend.getCurrentPositionResult({});
101
- expect(result.position).toBeNull();
102
- expect(result.reason).toBe('unavailable');
103
- });
104
-
105
- it('reads a host-provided floorLevel from coords', async () => {
106
- const hadOwn = Object.prototype.hasOwnProperty.call(navigator, 'geolocation');
107
- const original =
108
- Object.getOwnPropertyDescriptor(navigator, 'geolocation') ??
109
- Object.getOwnPropertyDescriptor(Object.getPrototypeOf(navigator), 'geolocation');
110
- Object.defineProperty(navigator, 'geolocation', {
111
- configurable: true,
112
- value: {
113
- getCurrentPosition(success: (position: unknown) => void) {
114
- success({
115
- coords: {
116
- accuracy: 5,
117
- altitude: null,
118
- altitudeAccuracy: null,
119
- floorLevel: 3,
120
- heading: null,
121
- latitude: 1,
122
- longitude: 2,
123
- speed: null,
124
- },
125
- timestamp: 123,
126
- });
127
- },
128
- },
129
- });
130
- try {
131
- const backend = createWebGeolocationBackend();
132
- const position = await backend.getCurrentPosition({});
133
- expect(position?.floorLevel).toBe(3);
134
- } finally {
135
- if (hadOwn && original !== undefined) {
136
- Object.defineProperty(navigator, 'geolocation', original);
137
- } else {
138
- delete (navigator as { geolocation?: unknown }).geolocation;
139
- }
140
- }
141
- });
142
-
143
- it('reports availability only when geolocation exists in a secure context', () => {
144
- const backend = createWebGeolocationBackend();
145
- vi.stubGlobal('navigator', { geolocation: {} });
146
- vi.stubGlobal('window', { isSecureContext: true });
147
- expect(backend.isAvailable()).toBe(true);
148
-
149
- vi.stubGlobal('window', { isSecureContext: false });
150
- expect(backend.isAvailable()).toBe(false);
151
-
152
- vi.stubGlobal('navigator', {});
153
- vi.stubGlobal('window', { isSecureContext: true });
154
- expect(backend.isAvailable()).toBe(false);
155
- });
156
-
157
- afterEach(() => vi.unstubAllGlobals());
158
- });
159
-
160
- describe('getCurrentGeoPosition', () => {
86
+ describe('getCurrentGeolocationPosition', () => {
161
87
  it('returns the backend position', async () => {
162
- const position = (await getCurrentGeoPosition(hostWith(fakeBackend()))) as GeoPosition;
88
+ const position = (await getCurrentGeolocationPosition(
89
+ hostWith(fakeBackend()).system.geolocation,
90
+ )) as GeolocationPosition;
163
91
  expect(position.latitude).toBe(1);
164
92
  expect(position.longitude).toBe(2);
165
93
  });
166
94
  });
167
95
 
168
- describe('getCurrentGeoPositionResult', () => {
96
+ describe('getCurrentGeolocationPositionResult', () => {
169
97
  it('returns position and null reason on success', async () => {
170
- const result = await getCurrentGeoPositionResult(hostWith(fakeBackend()));
98
+ const result = await getCurrentGeolocationPositionResult(hostWith(fakeBackend()).system.geolocation);
171
99
  expect(result.position).not.toBeNull();
172
100
  expect(result.position!.latitude).toBe(1);
173
101
  expect(result.reason).toBeNull();
174
102
  });
175
103
  });
176
104
 
177
- describe('initializeGeoPosition', () => {
178
- it('is the construction initializer of createGeoPosition', () => {
179
- expect(typeof initializeGeoPosition).toBe('function');
105
+ describe('initializeGeolocationPosition', () => {
106
+ it('is the construction initializer of createGeolocationPosition', () => {
107
+ expect(typeof initializeGeolocationPosition).toBe('function');
180
108
  });
181
109
  });
182
110
 
183
- describe('initializeWebGeolocationBackend', () => {
184
- it('is the construction initializer of createWebGeolocationBackend', () => {
185
- expect(typeof initializeWebGeolocationBackend).toBe('function');
186
- });
187
- });
188
111
  describe('isGeolocationAvailable', () => {
189
112
  it('routes the host backend availability', () => {
190
- expect(isGeolocationAvailable(hostWith(fakeBackend(true)))).toBe(true);
191
- expect(isGeolocationAvailable(hostWith(fakeBackend(false)))).toBe(false);
113
+ expect(isGeolocationAvailable(hostWith(fakeBackend(true)).system.geolocation)).toBe(true);
114
+ expect(isGeolocationAvailable(hostWith(fakeBackend(false)).system.geolocation)).toBe(false);
192
115
  });
193
116
  });
194
117
 
195
118
  describe('watchGeolocationPosition', () => {
196
119
  it('delivers positions and returns a watch id', () => {
197
120
  let seen = 0;
198
- const id = watchGeolocationPosition(hostWith(fakeBackend()), (position) => {
121
+ const id = watchGeolocationPosition(hostWith(fakeBackend()).system.geolocation, (position) => {
199
122
  seen = position.latitude;
200
123
  });
201
124
  expect(id).toBe(1);
@@ -205,7 +128,7 @@ describe('watchGeolocationPosition', () => {
205
128
  it('delivers error reasons when onError is provided', () => {
206
129
  const errors: GeolocationErrorReason[] = [];
207
130
  watchGeolocationPosition(
208
- hostWith(fakeBackend()),
131
+ hostWith(fakeBackend()).system.geolocation,
209
132
  () => {},
210
133
  {},
211
134
  (reason) => errors.push(reason),
@@ -1,23 +1,16 @@
1
- import type { GeolocationAccessOutcome, GeolocationBackend } from '@flighthq/types/contract';
1
+ import { promptForGeolocationAccess } from './geolocationAccess.ts';
2
+ import type { GeolocationAccessOutcome, HostGeolocationCapability } from './types.ts';
2
3
 
3
- import { promptForGeolocationAccess } from './geolocationAccess';
4
-
5
- // A backend whose promptForAccess answer the test dictates. Only that member is exercised, so the
6
- // rest of GeolocationBackend stays absent on purpose — a probe needing a whole backend would be
4
+ // A provider whose promptForAccess answer the test dictates. Only that member is exercised, so the
5
+ // rest of HostGeolocationCapability stays absent on purpose — a probe needing the whole provider would be
7
6
  // testing the fake.
8
- function backendAnswering(outcome: GeolocationAccessOutcome): GeolocationBackend {
9
- return { promptForAccess: () => Promise.resolve(outcome) } as unknown as GeolocationBackend;
10
- }
11
-
12
- function hostWith(backend: GeolocationBackend | undefined): Parameters<typeof promptForGeolocationAccess>[0] {
13
- return { system: backend === undefined ? {} : { geolocation: backend } } as unknown as Parameters<
14
- typeof promptForGeolocationAccess
15
- >[0];
7
+ function providerAnswering(outcome: GeolocationAccessOutcome): HostGeolocationCapability {
8
+ return { promptForAccess: () => Promise.resolve(outcome) } as unknown as HostGeolocationCapability;
16
9
  }
17
10
 
18
11
  describe('promptForGeolocationAccess', () => {
19
12
  it('reports granted when the host grants access', async () => {
20
- expect(await promptForGeolocationAccess(hostWith(backendAnswering({ reason: 'granted' })))).toEqual({
13
+ expect(await promptForGeolocationAccess(providerAnswering({ reason: 'granted' }))).toEqual({
21
14
  reason: 'granted',
22
15
  });
23
16
  });
@@ -27,7 +20,7 @@ describe('promptForGeolocationAccess', () => {
27
20
  it('keeps denied, dismissed and timeout as three distinct outcomes', async () => {
28
21
  const reasons = await Promise.all(
29
22
  (['denied', 'dismissed', 'timeout'] as const).map(
30
- async (reason) => (await promptForGeolocationAccess(hostWith(backendAnswering({ reason })))).reason,
23
+ async (reason) => (await promptForGeolocationAccess(providerAnswering({ reason }))).reason,
31
24
  ),
32
25
  );
33
26
  expect(reasons).toEqual(['denied', 'dismissed', 'timeout']);
@@ -35,21 +28,21 @@ describe('promptForGeolocationAccess', () => {
35
28
  });
36
29
 
37
30
  it('reports runtime-unavailable when no provider is installed', async () => {
38
- expect(await promptForGeolocationAccess(hostWith(undefined))).toEqual({ reason: 'runtime-unavailable' });
31
+ expect(await promptForGeolocationAccess(undefined)).toEqual({ reason: 'runtime-unavailable' });
39
32
  });
40
33
 
41
34
  it('reports operation-failed when the provider throws', async () => {
42
35
  const throwing = {
43
36
  promptForAccess: () => Promise.reject(new Error('boom')),
44
- } as unknown as GeolocationBackend;
45
- expect(await promptForGeolocationAccess(hostWith(throwing))).toEqual({ reason: 'operation-failed' });
37
+ } as unknown as HostGeolocationCapability;
38
+ expect(await promptForGeolocationAccess(throwing)).toEqual({ reason: 'operation-failed' });
46
39
  });
47
40
 
48
41
  // A capability outcome, never permission vocabulary: G6 lets geolocation keep the mechanism only
49
42
  // because what it returns is not a PermissionState. `state` must never appear on this type.
50
43
  it('carries no permission state field on any arm', async () => {
51
44
  for (const reason of ['granted', 'denied', 'dismissed', 'timeout', 'cleanup-failed'] as const) {
52
- const outcome = await promptForGeolocationAccess(hostWith(backendAnswering({ reason })));
45
+ const outcome = await promptForGeolocationAccess(providerAnswering({ reason }));
53
46
  expect(Object.hasOwn(outcome, 'state')).toBe(false);
54
47
  }
55
48
  });