@flighthq/geolocation 0.5.1-next.973.788d3d7 → 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 +2 -2
- package/dist/contract.d.ts +4 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -3
- package/dist/contract.js.map +1 -1
- package/dist/geolocation.d.ts +7 -8
- package/dist/geolocation.d.ts.map +1 -1
- package/dist/geolocation.js +12 -137
- 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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +5 -4
- package/src/geolocation.test.ts +22 -99
- package/src/geolocationAccess.test.ts +12 -19
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.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
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)
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from './geolocation';
|
|
2
|
-
export * from './geolocationAccess';
|
|
3
|
-
export { initializeGeolocationPosition
|
|
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
|
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,
|
|
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 { initializeGeolocationPosition
|
|
1
|
+
export * from './geolocation.js';
|
|
2
|
+
export * from './geolocationAccess.js';
|
|
3
|
+
export { initializeGeolocationPosition } from './geolocation.js';
|
|
4
4
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,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"}
|
package/dist/geolocation.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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;
|
|
3
4
|
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>;
|
|
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
7
|
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;
|
|
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,
|
|
1
|
+
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,IAAI,yBAAyB,EAChD,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,QAAQ,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"}
|
package/dist/geolocation.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { allocateEntity
|
|
2
|
-
export function clearGeolocationWatch(
|
|
3
|
-
|
|
1
|
+
import { allocateEntity } from '@flighthq/entity/contract';
|
|
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
|
-
return
|
|
8
|
+
return 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
|
-
};
|
|
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(
|
|
110
|
-
return
|
|
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,
|
|
1
|
+
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAW3D,MAAM,UAAU,qBAAqB,CAAC,eAAoD,EAAE,EAAU;IACpG,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,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,eAAoD,EACpD,OAA6C;IAE7C,OAAO,eAAe,CAAC,kBAAkB,CAAC,OAAO,IAAI,aAAa,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,eAAoD,EACpD,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,eAAoD;IACzF,OAAO,eAAe,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,eAAoD,EACpD,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, 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(
|
|
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,
|
|
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(
|
|
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,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, createGeolocationPosition, getCurrentGeolocationPosition, getCurrentGeolocationPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract';
|
|
1
|
+
export { clearGeolocationWatch, createGeolocationPosition, getCurrentGeolocationPosition, getCurrentGeolocationPositionResult, isGeolocationAvailable, promptForGeolocationAccess, watchGeolocationPosition, } from './contract.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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, createGeolocationPosition, getCurrentGeolocationPosition, getCurrentGeolocationPositionResult, 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,yBAAyB,EACzB,6BAA6B,EAC7B,mCAAmC,EACnC,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,
|
|
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"}
|
package/dist/types.d.ts
ADDED
|
@@ -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 @@
|
|
|
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.
|
|
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.
|
|
42
|
-
"@flighthq/types": "0.5.1-next.973.788d3d7"
|
|
43
|
+
"@flighthq/entity": "0.7.0-edge.5213.ead804b"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"typescript": "^
|
|
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
|
package/src/geolocation.test.ts
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import { allocateEntity
|
|
2
|
-
import
|
|
3
|
-
Entity,
|
|
4
|
-
GeolocationBackend,
|
|
5
|
-
GeolocationErrorReason,
|
|
6
|
-
GeolocationPosition,
|
|
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
6
|
createGeolocationPosition,
|
|
14
|
-
createWebGeolocationBackend,
|
|
15
7
|
getCurrentGeolocationPosition,
|
|
16
8
|
getCurrentGeolocationPositionResult,
|
|
17
9
|
initializeGeolocationPosition,
|
|
18
|
-
initializeWebGeolocationBackend,
|
|
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):
|
|
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 });
|
|
@@ -54,17 +46,21 @@ function fakeBackend(available: boolean = true): GeolocationBackend & { cleared:
|
|
|
54
46
|
if (onError) onError('denied');
|
|
55
47
|
return ++out.lastWatch;
|
|
56
48
|
};
|
|
57
|
-
return
|
|
49
|
+
return out;
|
|
58
50
|
}
|
|
59
51
|
|
|
60
|
-
function hostWith(backend:
|
|
61
|
-
|
|
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
|
});
|
|
@@ -87,79 +83,11 @@ describe('createGeolocationPosition', () => {
|
|
|
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
86
|
describe('getCurrentGeolocationPosition', () => {
|
|
161
87
|
it('returns the backend position', async () => {
|
|
162
|
-
const position = (await getCurrentGeolocationPosition(
|
|
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
|
});
|
|
@@ -167,7 +95,7 @@ describe('getCurrentGeolocationPosition', () => {
|
|
|
167
95
|
|
|
168
96
|
describe('getCurrentGeolocationPositionResult', () => {
|
|
169
97
|
it('returns position and null reason on success', async () => {
|
|
170
|
-
const result = await getCurrentGeolocationPositionResult(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();
|
|
@@ -180,22 +108,17 @@ describe('initializeGeolocationPosition', () => {
|
|
|
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
|
|
1
|
+
import { promptForGeolocationAccess } from './geolocationAccess.ts';
|
|
2
|
+
import type { GeolocationAccessOutcome, HostGeolocationCapability } from './types.ts';
|
|
2
3
|
|
|
3
|
-
|
|
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
|
|
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];
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
45
|
-
expect(await promptForGeolocationAccess(
|
|
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(
|
|
45
|
+
const outcome = await promptForGeolocationAccess(providerAnswering({ reason }));
|
|
53
46
|
expect(Object.hasOwn(outcome, 'state')).toBe(false);
|
|
54
47
|
}
|
|
55
48
|
});
|