@flighthq/geolocation 0.5.1-edge.1059.c56d3cd → 0.5.1-edge.1350.8ce488b
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 +2 -2
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/geolocation.d.ts +6 -8
- package/dist/geolocation.d.ts.map +1 -1
- package/dist/geolocation.js +10 -135
- package/dist/geolocation.js.map +1 -1
- package/dist/geolocationAccess.d.ts +2 -2
- package/dist/geolocationAccess.d.ts.map +1 -1
- package/dist/geolocationAccess.js +3 -4
- package/dist/geolocationAccess.js.map +1 -1
- package/package.json +3 -3
- package/src/geolocation.test.ts +15 -89
- package/src/geolocationAccess.test.ts +11 -17
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-edge.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/geolocation@0.5.1-edge.1350.8ce488b](https://github.com/flighthq/flight/tree/8ce488bfe444eded2fb281e7b9696e5ce7fabdc0/packages/geolocation)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/8ce488bfe444eded2fb281e7b9696e5ce7fabdc0/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './geolocation';
|
|
2
2
|
export * from './geolocationAccess';
|
|
3
|
-
export { initializeGeolocationPosition
|
|
3
|
+
export { initializeGeolocationPosition } from './geolocation';
|
|
4
4
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -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,6BAA6B,EAAE
|
|
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,6BAA6B,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -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,6BAA6B,EAAE
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/geolocation.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function clearGeolocationWatch(
|
|
1
|
+
import type { HostGeolocationProvider, GeolocationErrorReason, GeolocationPosition as FlightGeolocationPosition, GeolocationPositionResult, GeolocationRequestOptions, EntityConstruction } from '@flighthq/types/contract';
|
|
2
|
+
export declare function clearGeolocationWatch(hostGeolocation: Readonly<HostGeolocationProvider>, id: number): void;
|
|
3
3
|
export declare function createGeolocationPosition(): FlightGeolocationPosition;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function getCurrentGeolocationPositionResult(host: Readonly<HasSystemGeolocation>, options?: Readonly<GeolocationRequestOptions>): Promise<GeolocationPositionResult>;
|
|
4
|
+
export declare function getCurrentGeolocationPosition(hostGeolocation: Readonly<HostGeolocationProvider>, options?: Readonly<GeolocationRequestOptions>): Promise<FlightGeolocationPosition | null>;
|
|
5
|
+
export declare function getCurrentGeolocationPositionResult(hostGeolocation: Readonly<HostGeolocationProvider>, options?: Readonly<GeolocationRequestOptions>): Promise<GeolocationPositionResult>;
|
|
7
6
|
export declare function initializeGeolocationPosition(out: EntityConstruction<FlightGeolocationPosition>): void;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function watchGeolocationPosition(host: Readonly<HasSystemGeolocation>, handler: (position: Readonly<FlightGeolocationPosition>) => void, options?: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
|
|
7
|
+
export declare function isGeolocationAvailable(hostGeolocation: Readonly<HostGeolocationProvider>): boolean;
|
|
8
|
+
export declare function watchGeolocationPosition(hostGeolocation: Readonly<HostGeolocationProvider>, handler: (position: Readonly<FlightGeolocationPosition>) => void, options?: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
|
|
11
9
|
//# sourceMappingURL=geolocation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,IAAI,yBAAyB,EAChD,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAE1G;AAED,wBAAgB,yBAAyB,IAAI,yBAAyB,CAIrE;AAED,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EAClD,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC5C,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAE3C;AAED,wBAAgB,mCAAmC,CACjD,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EAClD,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,uBAAuB,CAAC,GAAG,OAAO,CAElG;AAED,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EAClD,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"}
|
package/dist/geolocation.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
|
-
export function clearGeolocationWatch(
|
|
3
|
-
|
|
2
|
+
export function clearGeolocationWatch(hostGeolocation, id) {
|
|
3
|
+
hostGeolocation.clearWatch(id);
|
|
4
4
|
}
|
|
5
5
|
export function createGeolocationPosition() {
|
|
6
6
|
const out = allocateEntity();
|
|
7
7
|
initializeGeolocationPosition(out);
|
|
8
8
|
return finishEntity(out);
|
|
9
9
|
}
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
initializeWebGeolocationBackend(out);
|
|
13
|
-
return finishEntity(out);
|
|
14
|
-
}
|
|
15
|
-
export function getCurrentGeolocationPosition(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 getCurrentGeolocationPositionResult(
|
|
19
|
-
return
|
|
13
|
+
export function getCurrentGeolocationPositionResult(hostGeolocation, options) {
|
|
14
|
+
return hostGeolocation.getCurrentPositionResult(options ?? _emptyOptions);
|
|
20
15
|
}
|
|
21
16
|
export function initializeGeolocationPosition(out) {
|
|
22
17
|
out.accuracy = 0;
|
|
@@ -29,131 +24,11 @@ export function initializeGeolocationPosition(out) {
|
|
|
29
24
|
out.speed = 0;
|
|
30
25
|
out.timestamp = 0;
|
|
31
26
|
}
|
|
32
|
-
export function
|
|
33
|
-
|
|
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
|
-
};
|
|
27
|
+
export function isGeolocationAvailable(hostGeolocation) {
|
|
28
|
+
return hostGeolocation.isAvailable();
|
|
105
29
|
}
|
|
106
|
-
export function
|
|
107
|
-
return
|
|
108
|
-
}
|
|
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
|
package/dist/geolocation.js.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUzE,MAAM,UAAU,qBAAqB,CAAC,eAAkD,EAAE,EAAU;IAClG,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,MAAM,GAAG,GAAG,cAAc,EAA6B,CAAC;IACxD,6BAA6B,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,eAAkD,EAClD,OAA6C;IAE7C,OAAO,eAAe,CAAC,kBAAkB,CAAC,OAAO,IAAI,aAAa,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,eAAkD,EAClD,OAA6C;IAE7C,OAAO,eAAe,CAAC,wBAAwB,CAAC,OAAO,IAAI,aAAa,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,GAAkD;IAC9F,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjB,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjB,GAAG,CAAC,gBAAgB,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC;IACnB,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjB,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;IAClB,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IACd,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,eAAkD;IACvF,OAAO,eAAe,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,eAAkD,EAClD,OAAgE,EAChE,OAA6C,EAC7C,OAAkD;IAElD,OAAO,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,OAAO,CAAC,CAAC;AACnF,CAAC;AAED,MAAM,aAAa,GAA8B,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GeolocationAccessOutcome,
|
|
1
|
+
import type { GeolocationAccessOutcome, HostGeolocationProvider } from '@flighthq/types/contract';
|
|
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(
|
|
13
|
+
export declare function promptForGeolocationAccess(hostGeolocation: Readonly<HostGeolocationProvider> | 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,
|
|
1
|
+
{"version":3,"file":"geolocationAccess.d.ts","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAElG;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC9C,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,GAAG,SAAS,GAC7D,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(
|
|
13
|
-
|
|
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
|
|
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,
|
|
1
|
+
{"version":3,"file":"geolocationAccess.js","sourceRoot":"","sources":["../src/geolocationAccess.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,eAA8D;IAE9D,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/geolocation",
|
|
3
|
-
"version": "0.5.1-edge.
|
|
3
|
+
"version": "0.5.1-edge.1350.8ce488b",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-edge.
|
|
42
|
-
"@flighthq/types": "0.5.1-edge.
|
|
41
|
+
"@flighthq/entity": "0.5.1-edge.1350.8ce488b",
|
|
42
|
+
"@flighthq/types": "0.5.1-edge.1350.8ce488b"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/geolocation.test.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import type {
|
|
3
3
|
Entity,
|
|
4
|
-
|
|
4
|
+
HostGeolocationProvider,
|
|
5
5
|
GeolocationErrorReason,
|
|
6
6
|
GeolocationPosition,
|
|
7
|
-
HasSystemGeolocation,
|
|
8
7
|
} from '@flighthq/types/contract';
|
|
9
8
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
10
9
|
|
|
11
10
|
import {
|
|
12
11
|
clearGeolocationWatch,
|
|
13
12
|
createGeolocationPosition,
|
|
14
|
-
createWebGeolocationBackend,
|
|
15
13
|
getCurrentGeolocationPosition,
|
|
16
14
|
getCurrentGeolocationPositionResult,
|
|
17
15
|
initializeGeolocationPosition,
|
|
18
|
-
initializeWebGeolocationBackend,
|
|
19
16
|
isGeolocationAvailable,
|
|
20
17
|
watchGeolocationPosition,
|
|
21
18
|
} from './geolocation';
|
|
22
19
|
|
|
23
|
-
function fakeBackend(available: boolean = true):
|
|
20
|
+
function fakeBackend(available: boolean = true): HostGeolocationProvider & { cleared: number[]; lastWatch: number } {
|
|
24
21
|
const out = allocateEntity<any>();
|
|
25
22
|
out.cleared = [];
|
|
26
23
|
out.lastWatch = 0;
|
|
@@ -57,14 +54,16 @@ function fakeBackend(available: boolean = true): GeolocationBackend & { cleared:
|
|
|
57
54
|
return finishEntity(out);
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
function hostWith(backend:
|
|
61
|
-
|
|
57
|
+
function hostWith(backend: HostGeolocationProvider): {
|
|
58
|
+
readonly system: { readonly geolocation: HostGeolocationProvider };
|
|
59
|
+
} {
|
|
60
|
+
return { system: { geolocation: backend } } as { readonly system: { readonly geolocation: HostGeolocationProvider } };
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
describe('clearGeolocationWatch', () => {
|
|
65
64
|
it('forwards the id to the host backend', () => {
|
|
66
65
|
const backend = fakeBackend();
|
|
67
|
-
clearGeolocationWatch(hostWith(backend), 7);
|
|
66
|
+
clearGeolocationWatch(hostWith(backend).system.geolocation, 7);
|
|
68
67
|
expect(backend.cleared).toEqual([7]);
|
|
69
68
|
});
|
|
70
69
|
});
|
|
@@ -87,79 +86,11 @@ describe('createGeolocationPosition', () => {
|
|
|
87
86
|
});
|
|
88
87
|
});
|
|
89
88
|
|
|
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
89
|
describe('getCurrentGeolocationPosition', () => {
|
|
161
90
|
it('returns the backend position', async () => {
|
|
162
|
-
const position = (await getCurrentGeolocationPosition(
|
|
91
|
+
const position = (await getCurrentGeolocationPosition(
|
|
92
|
+
hostWith(fakeBackend()).system.geolocation,
|
|
93
|
+
)) as GeolocationPosition;
|
|
163
94
|
expect(position.latitude).toBe(1);
|
|
164
95
|
expect(position.longitude).toBe(2);
|
|
165
96
|
});
|
|
@@ -167,7 +98,7 @@ describe('getCurrentGeolocationPosition', () => {
|
|
|
167
98
|
|
|
168
99
|
describe('getCurrentGeolocationPositionResult', () => {
|
|
169
100
|
it('returns position and null reason on success', async () => {
|
|
170
|
-
const result = await getCurrentGeolocationPositionResult(hostWith(fakeBackend()));
|
|
101
|
+
const result = await getCurrentGeolocationPositionResult(hostWith(fakeBackend()).system.geolocation);
|
|
171
102
|
expect(result.position).not.toBeNull();
|
|
172
103
|
expect(result.position!.latitude).toBe(1);
|
|
173
104
|
expect(result.reason).toBeNull();
|
|
@@ -180,22 +111,17 @@ describe('initializeGeolocationPosition', () => {
|
|
|
180
111
|
});
|
|
181
112
|
});
|
|
182
113
|
|
|
183
|
-
describe('initializeWebGeolocationBackend', () => {
|
|
184
|
-
it('is the construction initializer of createWebGeolocationBackend', () => {
|
|
185
|
-
expect(typeof initializeWebGeolocationBackend).toBe('function');
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
114
|
describe('isGeolocationAvailable', () => {
|
|
189
115
|
it('routes the host backend availability', () => {
|
|
190
|
-
expect(isGeolocationAvailable(hostWith(fakeBackend(true)))).toBe(true);
|
|
191
|
-
expect(isGeolocationAvailable(hostWith(fakeBackend(false)))).toBe(false);
|
|
116
|
+
expect(isGeolocationAvailable(hostWith(fakeBackend(true)).system.geolocation)).toBe(true);
|
|
117
|
+
expect(isGeolocationAvailable(hostWith(fakeBackend(false)).system.geolocation)).toBe(false);
|
|
192
118
|
});
|
|
193
119
|
});
|
|
194
120
|
|
|
195
121
|
describe('watchGeolocationPosition', () => {
|
|
196
122
|
it('delivers positions and returns a watch id', () => {
|
|
197
123
|
let seen = 0;
|
|
198
|
-
const id = watchGeolocationPosition(hostWith(fakeBackend()), (position) => {
|
|
124
|
+
const id = watchGeolocationPosition(hostWith(fakeBackend()).system.geolocation, (position) => {
|
|
199
125
|
seen = position.latitude;
|
|
200
126
|
});
|
|
201
127
|
expect(id).toBe(1);
|
|
@@ -205,7 +131,7 @@ describe('watchGeolocationPosition', () => {
|
|
|
205
131
|
it('delivers error reasons when onError is provided', () => {
|
|
206
132
|
const errors: GeolocationErrorReason[] = [];
|
|
207
133
|
watchGeolocationPosition(
|
|
208
|
-
hostWith(fakeBackend()),
|
|
134
|
+
hostWith(fakeBackend()).system.geolocation,
|
|
209
135
|
() => {},
|
|
210
136
|
{},
|
|
211
137
|
(reason) => errors.push(reason),
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import type { GeolocationAccessOutcome,
|
|
1
|
+
import type { GeolocationAccessOutcome, HostGeolocationProvider } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import { promptForGeolocationAccess } from './geolocationAccess';
|
|
4
4
|
|
|
5
|
-
// A
|
|
6
|
-
// rest of
|
|
5
|
+
// A provider whose promptForAccess answer the test dictates. Only that member is exercised, so the
|
|
6
|
+
// rest of HostGeolocationProvider stays absent on purpose — a probe needing the whole provider would be
|
|
7
7
|
// testing the fake.
|
|
8
|
-
function
|
|
9
|
-
return { promptForAccess: () => Promise.resolve(outcome) } as unknown as
|
|
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];
|
|
8
|
+
function providerAnswering(outcome: GeolocationAccessOutcome): HostGeolocationProvider {
|
|
9
|
+
return { promptForAccess: () => Promise.resolve(outcome) } as unknown as HostGeolocationProvider;
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
describe('promptForGeolocationAccess', () => {
|
|
19
13
|
it('reports granted when the host grants access', async () => {
|
|
20
|
-
expect(await promptForGeolocationAccess(
|
|
14
|
+
expect(await promptForGeolocationAccess(providerAnswering({ reason: 'granted' }))).toEqual({
|
|
21
15
|
reason: 'granted',
|
|
22
16
|
});
|
|
23
17
|
});
|
|
@@ -27,7 +21,7 @@ describe('promptForGeolocationAccess', () => {
|
|
|
27
21
|
it('keeps denied, dismissed and timeout as three distinct outcomes', async () => {
|
|
28
22
|
const reasons = await Promise.all(
|
|
29
23
|
(['denied', 'dismissed', 'timeout'] as const).map(
|
|
30
|
-
async (reason) => (await promptForGeolocationAccess(
|
|
24
|
+
async (reason) => (await promptForGeolocationAccess(providerAnswering({ reason }))).reason,
|
|
31
25
|
),
|
|
32
26
|
);
|
|
33
27
|
expect(reasons).toEqual(['denied', 'dismissed', 'timeout']);
|
|
@@ -35,21 +29,21 @@ describe('promptForGeolocationAccess', () => {
|
|
|
35
29
|
});
|
|
36
30
|
|
|
37
31
|
it('reports runtime-unavailable when no provider is installed', async () => {
|
|
38
|
-
expect(await promptForGeolocationAccess(
|
|
32
|
+
expect(await promptForGeolocationAccess(undefined)).toEqual({ reason: 'runtime-unavailable' });
|
|
39
33
|
});
|
|
40
34
|
|
|
41
35
|
it('reports operation-failed when the provider throws', async () => {
|
|
42
36
|
const throwing = {
|
|
43
37
|
promptForAccess: () => Promise.reject(new Error('boom')),
|
|
44
|
-
} as unknown as
|
|
45
|
-
expect(await promptForGeolocationAccess(
|
|
38
|
+
} as unknown as HostGeolocationProvider;
|
|
39
|
+
expect(await promptForGeolocationAccess(throwing)).toEqual({ reason: 'operation-failed' });
|
|
46
40
|
});
|
|
47
41
|
|
|
48
42
|
// A capability outcome, never permission vocabulary: G6 lets geolocation keep the mechanism only
|
|
49
43
|
// because what it returns is not a PermissionState. `state` must never appear on this type.
|
|
50
44
|
it('carries no permission state field on any arm', async () => {
|
|
51
45
|
for (const reason of ['granted', 'denied', 'dismissed', 'timeout', 'cleanup-failed'] as const) {
|
|
52
|
-
const outcome = await promptForGeolocationAccess(
|
|
46
|
+
const outcome = await promptForGeolocationAccess(providerAnswering({ reason }));
|
|
53
47
|
expect(Object.hasOwn(outcome, 'state')).toBe(false);
|
|
54
48
|
}
|
|
55
49
|
});
|