@octane-xplat/geolocation 0.0.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alec Larson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # @octane-xplat/geolocation
1
+ # `@octane-xplat/geolocation`
2
2
 
3
- Version 0.0.1 is a reservation stub so the automated release can publish this package name. It has no supported API. Use a later release for the implementation.
3
+ ```sh
4
+ pnpm add @octane-xplat/geolocation
5
+ ```
6
+
7
+ Device geolocation behind one capability object. iOS and Android run
8
+ `@nativescript/geolocation`; web uses `navigator.geolocation`; the macOS
9
+ AppKit dev host reports `supported: false` (no CoreLocation bridge).
10
+
11
+ ```ts
12
+ import { geolocation } from '@octane-xplat/geolocation'
13
+
14
+ if ((await geolocation.ensure()) === 'granted') {
15
+ const pos = await geolocation.impl!.getCurrentPosition()
16
+ // { latitude, longitude, accuracy, altitude, heading, speed, timestamp }
17
+ }
18
+ ```
19
+
20
+ The shared capability contract: `supported` reports whether an
21
+ implementation exists on this target, `ensure()` resolves
22
+ `'granted' | 'denied' | 'unsupported'` (it prompts where the platform
23
+ defers the prompt), and `impl` is the service once usable. Nullable
24
+ `altitude`/`heading`/`speed` mean the platform did not report them.
25
+
26
+ ```ts
27
+ import { geolocation } from '@octane-xplat/geolocation'
28
+
29
+ if ((await geolocation.ensure()) === 'granted') {
30
+ const pos = await geolocation.impl!.getCurrentPosition()
31
+ // { latitude, longitude, accuracy, altitude, heading, speed, timestamp }
32
+ }
33
+ ```
34
+
35
+ Guide: [Using device features](../../docs/platform/platform-services.md);
36
+ per-target availability: [platform notes](../../docs/notes/platform-notes.md).
37
+ Exercised by the harness `Services` screen
38
+ ([`packages/app/src/Services.tsrx`](../app/src/Services.tsrx)).
package/package.json CHANGED
@@ -1,19 +1,68 @@
1
1
  {
2
2
  "name": "@octane-xplat/geolocation",
3
- "version": "0.0.1",
3
+ "version": "0.10.0",
4
4
  "description": "Device geolocation for Octane xplat — matching web + NativeScript implementations",
5
+ "keywords": [
6
+ "android",
7
+ "cross-platform",
8
+ "geolocation",
9
+ "gps",
10
+ "ios",
11
+ "location",
12
+ "nativescript",
13
+ "octane",
14
+ "web",
15
+ "xplat"
16
+ ],
17
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/geolocation",
5
18
  "license": "MIT",
6
19
  "repository": {
7
20
  "type": "git",
8
- "url": "https://github.com/octane-xplat/octane-xplat.git",
21
+ "url": "https://github.com/octane-xplat/octane-xplat",
9
22
  "directory": "packages/geolocation"
10
23
  },
11
- "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/geolocation",
12
- "main": "./index.js",
13
- "types": "./index.d.ts",
14
24
  "files": [
15
- "README.md",
16
- "index.js",
17
- "index.d.ts"
18
- ]
19
- }
25
+ "src"
26
+ ],
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "macos": "./src/index.macos.ts",
31
+ "default": "./src/index.ts"
32
+ },
33
+ "./*": "./src/*"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "@nativescript/geolocation": "9.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "@nativescript-community/octane": "0.2.4",
43
+ "@nativescript/core": "9.1.2",
44
+ "octane": "0.6.3"
45
+ },
46
+ "peerDependencies": {
47
+ "@nativescript-community/octane": ">=0.2.1 <1",
48
+ "@nativescript/core": ">=9.1.0 <10",
49
+ "octane": ">=0.6.3 <1"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@nativescript-community/octane": {
53
+ "optional": true
54
+ },
55
+ "@nativescript/core": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "nativescript": {
60
+ "platforms": {
61
+ "android": "9.1.0",
62
+ "ios": "9.1.0"
63
+ }
64
+ },
65
+ "scripts": {
66
+ "test:packed": "node tests/packed-consumer.mjs"
67
+ }
68
+ }
@@ -0,0 +1,8 @@
1
+ // Geolocation — AppKit host leaf. CoreLocation is not bridged on the dev host.
2
+ import type { Capability, GeolocationImpl } from './types'
3
+
4
+ export const geolocation: Capability<GeolocationImpl> = {
5
+ supported: false,
6
+ ensure: async () => 'unsupported',
7
+ impl: null,
8
+ }
@@ -0,0 +1,49 @@
1
+ // Geolocation — native leaf. The plugin's enableLocationRequest() owns the
2
+ // runtime prompt; getCurrentLocation() is normalized to the web position shape.
3
+ import * as geolocationApi from '@nativescript/geolocation'
4
+ import { CoreTypes } from '@nativescript/core'
5
+ import type { Capability, GeolocationImpl, GeolocationPosition } from './types'
6
+
7
+ function asPosition(nativeLocation: any): GeolocationPosition {
8
+ return {
9
+ latitude: nativeLocation.latitude,
10
+ longitude: nativeLocation.longitude,
11
+ accuracy: nativeLocation.horizontalAccuracy ?? nativeLocation.accuracy ?? 0,
12
+ altitude: nativeLocation.altitude ?? null,
13
+ heading: nativeLocation.direction ?? nativeLocation.heading ?? null,
14
+ speed: nativeLocation.speed ?? null,
15
+ timestamp: Number(nativeLocation.timestamp ?? Date.now()),
16
+ }
17
+ }
18
+
19
+ const impl: GeolocationImpl = {
20
+ async getCurrentPosition(options) {
21
+ const nativePosition = await geolocationApi.getCurrentLocation({
22
+ desiredAccuracy: options?.enableHighAccuracy
23
+ ? CoreTypes.Accuracy.high
24
+ : CoreTypes.Accuracy.any,
25
+ maximumAge: options?.maximumAge,
26
+ timeout: options?.timeout,
27
+ })
28
+
29
+ return asPosition(nativePosition)
30
+ },
31
+ }
32
+
33
+ export const geolocation: Capability<GeolocationImpl> = {
34
+ supported: true,
35
+ async ensure() {
36
+ try {
37
+ await geolocationApi.enableLocationRequest()
38
+ return 'granted'
39
+ } catch {
40
+ return 'denied'
41
+ }
42
+ },
43
+ impl,
44
+ }
45
+
46
+ // See @octane-xplat/media for the pattern — registers the kind this leaf owns
47
+ // for the platform permissions dispatcher.
48
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
49
+ permissionOwners.location = () => geolocation.ensure()
@@ -0,0 +1,53 @@
1
+ // Geolocation — web leaf. The browser owns the permission prompt and returns
2
+ // the platform-neutral position shape used by the service contract.
3
+ import type { Capability, GeolocationImpl, GeolocationOptions, GeolocationPosition } from './types'
4
+
5
+ const supported = typeof navigator !== 'undefined' && 'geolocation' in navigator
6
+
7
+ function readPosition(options?: GeolocationOptions): Promise<GeolocationPosition> {
8
+ return new Promise((resolve, reject) => {
9
+ navigator.geolocation.getCurrentPosition(
10
+ (position) =>
11
+ resolve({
12
+ latitude: position.coords.latitude,
13
+ longitude: position.coords.longitude,
14
+ accuracy: position.coords.accuracy,
15
+ altitude: position.coords.altitude,
16
+ heading: position.coords.heading,
17
+ speed: position.coords.speed,
18
+ timestamp: position.timestamp,
19
+ }),
20
+ reject,
21
+ {
22
+ enableHighAccuracy: options?.enableHighAccuracy,
23
+ timeout: options?.timeout,
24
+ maximumAge: options?.maximumAge,
25
+ },
26
+ )
27
+ })
28
+ }
29
+
30
+ const impl: GeolocationImpl = {
31
+ getCurrentPosition: readPosition,
32
+ }
33
+
34
+ export const geolocation: Capability<GeolocationImpl> = {
35
+ supported,
36
+ async ensure() {
37
+ if (!supported) {
38
+ return 'unsupported'
39
+ }
40
+
41
+ try {
42
+ await readPosition({ timeout: 15000 })
43
+ return 'granted'
44
+ } catch (error) {
45
+ const code = (error as { code?: number }).code
46
+ return code === 1 ? 'denied' : 'unsupported'
47
+ }
48
+ },
49
+ impl,
50
+ }
51
+
52
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
53
+ permissionOwners.location = () => geolocation.ensure()
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export { geolocation } from './geolocation.macos'
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export { geolocation } from './geolocation'
package/src/types.ts ADDED
@@ -0,0 +1,29 @@
1
+ /** Optional capability — never throws for absence (docs/platform/platform-services.md). */
2
+ export interface Capability<T> {
3
+ supported: boolean
4
+ ensure(): Promise<'granted' | 'denied' | 'unsupported'>
5
+ /** usable iff supported && ensured */
6
+ impl: T | null
7
+ }
8
+
9
+ export type PermissionResult = 'granted' | 'denied' | 'unsupported'
10
+
11
+ export interface GeolocationOptions {
12
+ enableHighAccuracy?: boolean
13
+ timeout?: number
14
+ maximumAge?: number
15
+ }
16
+
17
+ export interface GeolocationPosition {
18
+ latitude: number
19
+ longitude: number
20
+ accuracy: number
21
+ altitude: number | null
22
+ heading: number | null
23
+ speed: number | null
24
+ timestamp: number
25
+ }
26
+
27
+ export interface GeolocationImpl {
28
+ getCurrentPosition(options?: GeolocationOptions): Promise<GeolocationPosition>
29
+ }
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {}
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- // Reservation stub; implementation will arrive in a later release.
2
- module.exports = {}