@elizaos/capacitor-location 2.0.0-beta.1 → 2.0.11-beta.7

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
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
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 all
13
+ 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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @elizaos/capacitor-location
2
+
3
+ Capacitor plugin for geolocation within elizaOS apps. Provides current position, continuous location watching, and permission management across browser, iOS, and Android.
4
+
5
+ ## Capabilities
6
+
7
+ - **Get current position** — one-shot GPS/network fix with configurable accuracy and timeout
8
+ - **Watch position** — continuous location stream with distance and interval throttling
9
+ - **Permission management** — check and request OS location permissions
10
+ - **Cross-platform** — identical TypeScript API on web (Geolocation API), iOS (CoreLocation), and Android (FusedLocationProviderClient)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @elizaos/capacitor-location
16
+ npx cap sync
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { Location } from '@elizaos/capacitor-location';
23
+
24
+ // Get current position
25
+ const result = await Location.getCurrentPosition({ accuracy: 'high', timeout: 10000 });
26
+ console.log(result.coords.latitude, result.coords.longitude);
27
+
28
+ // Watch position changes
29
+ const { watchId } = await Location.watchPosition({ accuracy: 'high', minDistance: 10 });
30
+ await Location.addListener('locationChange', (location) => {
31
+ console.log('New position:', location.coords);
32
+ });
33
+
34
+ // Stop watching
35
+ await Location.clearWatch({ watchId });
36
+
37
+ // Permissions
38
+ const status = await Location.checkPermissions();
39
+ if (status.location !== 'granted') {
40
+ await Location.requestPermissions();
41
+ }
42
+ ```
43
+
44
+ ## API
45
+
46
+ ### `getCurrentPosition(options?)`
47
+
48
+ Returns a single `LocationResult` with the device's current coordinates.
49
+
50
+ Options:
51
+
52
+ | Option | Type | Default | Description |
53
+ |--------|------|---------|-------------|
54
+ | `accuracy` | `"best"\|"high"\|"medium"\|"low"\|"passive"` | `"high"` | Desired fix accuracy |
55
+ | `maxAge` | `number` (ms) | `0` | Return cached location if younger than this |
56
+ | `timeout` | `number` (ms) | `10000` | Abort if no fix within this window |
57
+
58
+ ### `watchPosition(options?)`
59
+
60
+ Starts continuous location updates. Returns `{ watchId: string }`. Location updates are delivered via the `locationChange` event. Stop with `clearWatch`.
61
+
62
+ Additional options beyond `getCurrentPosition`:
63
+
64
+ | Option | Type | Default | Description |
65
+ |--------|------|---------|-------------|
66
+ | `minDistance` | `number` (m) | `0` | Minimum movement before firing an update |
67
+ | `minInterval` | `number` (ms) | `0` | Minimum time between updates |
68
+
69
+ ### `clearWatch({ watchId })`
70
+
71
+ Stops a running watch by its ID.
72
+
73
+ ### `checkPermissions()`
74
+
75
+ Returns `LocationPermissionStatus` without prompting. Fields: `location` and `background` (iOS/Android only), each `"granted" | "denied" | "prompt"`.
76
+
77
+ ### `requestPermissions()`
78
+
79
+ Requests OS location permission. On web, this implicitly triggers a `getCurrentPosition` call (the only way browsers expose the permission prompt).
80
+
81
+ ### Events
82
+
83
+ | Event | Payload | Description |
84
+ |-------|---------|-------------|
85
+ | `locationChange` | `LocationResult` | Fired on each position update while watching |
86
+ | `error` | `LocationErrorEvent` | Fired on location errors |
87
+
88
+ `LocationErrorEvent.code` values: `PERMISSION_DENIED`, `POSITION_UNAVAILABLE`, `TIMEOUT`, `UNKNOWN`.
89
+
90
+ ## Platform setup
91
+
92
+ ### iOS
93
+
94
+ Add to `Info.plist`:
95
+
96
+ ```xml
97
+ <key>NSLocationWhenInUseUsageDescription</key>
98
+ <string>This app uses your location to …</string>
99
+
100
+ <!-- Only if requesting "always" permission -->
101
+ <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
102
+ <string>This app uses your location in the background to …</string>
103
+ ```
104
+
105
+ Minimum deployment target: iOS 13.0.
106
+
107
+ ### Android
108
+
109
+ Add to `AndroidManifest.xml`:
110
+
111
+ ```xml
112
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
113
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
114
+
115
+ <!-- Only if background location is needed -->
116
+ <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
117
+ ```
118
+
119
+ Requires Google Play Services (`com.google.android.gms:play-services-location`).
120
+
121
+ ## Building
122
+
123
+ ```bash
124
+ bun run build # tsc + rollup
125
+ bun run build:docs # regenerate README from JSDoc, then build
126
+ bun run clean # remove dist/
127
+ ```
128
+
@@ -6,6 +6,16 @@ ext {
6
6
  }
7
7
 
8
8
  apply plugin: 'com.android.library'
9
+ // Explicitly apply the Kotlin Android plugin. The kotlin-gradle-plugin is on
10
+ // the root buildscript classpath, but without applying it here AGP 8.13 falls
11
+ // back to its "built-in Kotlin" compile path (build/intermediates/
12
+ // built_in_kotlinc), which compiles the .kt sources but does NOT bundle the
13
+ // resulting .class files into the *release* library jar. The app's
14
+ // :app:assembleRelease then links a library AAR with zero plugin classes, so
15
+ // the Capacitor plugin (and any manifest-declared component) is absent from
16
+ // the release dex. Applying the standard Kotlin plugin wires Kotlin
17
+ // compilation into both the debug and release jar-bundling tasks.
18
+ apply plugin: 'org.jetbrains.kotlin.android'
9
19
  android {
10
20
  namespace = "ai.eliza.plugins.location"
11
21
  compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
@@ -21,8 +31,12 @@ android {
21
31
  }
22
32
  }
23
33
  compileOptions {
24
- sourceCompatibility JavaVersion.VERSION_17
25
- targetCompatibility JavaVersion.VERSION_17
34
+ sourceCompatibility JavaVersion.VERSION_21
35
+ targetCompatibility JavaVersion.VERSION_21
36
+ }
37
+
38
+ kotlinOptions {
39
+ jvmTarget = "21"
26
40
  }
27
41
  }
28
42
 
package/dist/esm/web.d.ts CHANGED
@@ -7,6 +7,9 @@ import type { LocationOptions, LocationPermissionStatus, LocationResult, WatchLo
7
7
  */
8
8
  export declare class LocationWeb extends WebPlugin {
9
9
  private watches;
10
+ private getGeolocation;
11
+ private normalizePositionOptions;
12
+ private validateWatchOptions;
10
13
  getCurrentPosition(options?: LocationOptions): Promise<LocationResult>;
11
14
  watchPosition(options?: WatchLocationOptions): Promise<{
12
15
  watchId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,OAAO,CAA6B;IAEtC,kBAAkB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAmDtE,aAAa,CACjB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAsDzB,UAAU,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvD,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAqBrD,kBAAkB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CAc9D"}
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,OAAO,CAA6B;IAE5C,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,wBAAwB;IAiBhC,OAAO,CAAC,oBAAoB;IAatB,kBAAkB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA8CtE,aAAa,CACjB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAkDzB,UAAU,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASvD,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAqBrD,kBAAkB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CAc9D"}
package/dist/esm/web.js CHANGED
@@ -6,14 +6,44 @@ import { WebPlugin } from "@capacitor/core";
6
6
  */
7
7
  export class LocationWeb extends WebPlugin {
8
8
  watches = new Map();
9
+ getGeolocation() {
10
+ if (!navigator.geolocation) {
11
+ throw new Error("Geolocation API is not available");
12
+ }
13
+ return navigator.geolocation;
14
+ }
15
+ normalizePositionOptions(options) {
16
+ const maxAge = options?.maxAge ?? 0;
17
+ const timeout = options?.timeout ?? 10000;
18
+ if (!Number.isFinite(maxAge) || maxAge < 0) {
19
+ throw new Error("maxAge must be a non-negative finite number");
20
+ }
21
+ if (!Number.isFinite(timeout) || timeout <= 0) {
22
+ throw new Error("timeout must be a positive finite number");
23
+ }
24
+ return {
25
+ enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
26
+ maximumAge: Math.trunc(maxAge),
27
+ timeout: Math.trunc(timeout),
28
+ };
29
+ }
30
+ validateWatchOptions(options) {
31
+ if (options?.minDistance !== undefined) {
32
+ if (!Number.isFinite(options.minDistance) || options.minDistance < 0) {
33
+ throw new Error("minDistance must be a non-negative finite number");
34
+ }
35
+ }
36
+ if (options?.minInterval !== undefined) {
37
+ if (!Number.isFinite(options.minInterval) || options.minInterval < 0) {
38
+ throw new Error("minInterval must be a non-negative finite number");
39
+ }
40
+ }
41
+ }
9
42
  async getCurrentPosition(options) {
43
+ const geolocation = this.getGeolocation();
44
+ const geoOptions = this.normalizePositionOptions(options);
10
45
  return new Promise((resolve, reject) => {
11
- const geoOptions = {
12
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
13
- maximumAge: options?.maxAge ?? 0,
14
- timeout: options?.timeout ?? 10000,
15
- };
16
- navigator.geolocation.getCurrentPosition((position) => {
46
+ geolocation.getCurrentPosition((position) => {
17
47
  resolve({
18
48
  coords: {
19
49
  latitude: position.coords.latitude,
@@ -48,12 +78,10 @@ export class LocationWeb extends WebPlugin {
48
78
  }
49
79
  async watchPosition(options) {
50
80
  const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;
51
- const geoOptions = {
52
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
53
- maximumAge: options?.maxAge ?? 0,
54
- timeout: options?.timeout ?? 10000,
55
- };
56
- const nativeWatchId = navigator.geolocation.watchPosition((position) => {
81
+ const geolocation = this.getGeolocation();
82
+ this.validateWatchOptions(options);
83
+ const geoOptions = this.normalizePositionOptions(options);
84
+ const nativeWatchId = geolocation.watchPosition((position) => {
57
85
  this.notifyListeners("locationChange", {
58
86
  coords: {
59
87
  latitude: position.coords.latitude,
@@ -88,10 +116,11 @@ export class LocationWeb extends WebPlugin {
88
116
  return { watchId };
89
117
  }
90
118
  async clearWatch(options) {
91
- const nativeWatchId = this.watches.get(options.watchId);
119
+ const watchId = typeof options?.watchId === "string" ? options.watchId : "";
120
+ const nativeWatchId = this.watches.get(watchId);
92
121
  if (nativeWatchId !== undefined) {
93
- navigator.geolocation.clearWatch(nativeWatchId);
94
- this.watches.delete(options.watchId);
122
+ this.getGeolocation().clearWatch(nativeWatchId);
123
+ this.watches.delete(watchId);
95
124
  }
96
125
  }
97
126
  async checkPermissions() {
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,SAAS;IAChC,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,KAAK,CAAC,kBAAkB,CAAC,OAAyB;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,UAAU,GAAoB;gBAClC,kBAAkB,EAChB,OAAO,EAAE,QAAQ,KAAK,MAAM,IAAI,OAAO,EAAE,QAAQ,KAAK,MAAM;gBAC9D,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;gBAChC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK;aACnC,CAAC;YAEF,SAAS,CAAC,WAAW,CAAC,kBAAkB,CACtC,CAAC,QAAQ,EAAE,EAAE;gBACX,OAAO,CAAC;oBACN,MAAM,EAAE;wBACN,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;wBAClC,SAAS,EAAE,QAAQ,CAAC,MAAM,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AAC;YACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,KAAyB,CAAC;YACpC,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;gBACnC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;YAChC,CAAC;YACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=web.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.test.d.ts","sourceRoot":"","sources":["../../src/web.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,199 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { LocationWeb } from "./web";
3
+ function setNavigator(value) {
4
+ Object.defineProperty(globalThis, "navigator", {
5
+ configurable: true,
6
+ value,
7
+ });
8
+ }
9
+ function position() {
10
+ return {
11
+ coords: {
12
+ latitude: 37.7,
13
+ longitude: -122.4,
14
+ altitude: null,
15
+ accuracy: 5,
16
+ altitudeAccuracy: null,
17
+ heading: null,
18
+ speed: null,
19
+ },
20
+ timestamp: 123,
21
+ };
22
+ }
23
+ function geoError(code, message = "geo failed") {
24
+ return {
25
+ code,
26
+ message,
27
+ PERMISSION_DENIED: 1,
28
+ POSITION_UNAVAILABLE: 2,
29
+ TIMEOUT: 3,
30
+ };
31
+ }
32
+ describe("LocationWeb", () => {
33
+ afterEach(() => {
34
+ vi.restoreAllMocks();
35
+ });
36
+ it("maps getCurrentPosition options and normalizes nullable coordinates", async () => {
37
+ const getCurrentPosition = vi.fn((success, _error, options) => {
38
+ expect(options).toEqual({
39
+ enableHighAccuracy: true,
40
+ maximumAge: 50,
41
+ timeout: 250,
42
+ });
43
+ success(position());
44
+ });
45
+ setNavigator({
46
+ geolocation: { getCurrentPosition },
47
+ });
48
+ await expect(new LocationWeb().getCurrentPosition({
49
+ accuracy: "best",
50
+ maxAge: 50,
51
+ timeout: 250,
52
+ })).resolves.toEqual({
53
+ coords: {
54
+ latitude: 37.7,
55
+ longitude: -122.4,
56
+ altitude: undefined,
57
+ accuracy: 5,
58
+ altitudeAccuracy: undefined,
59
+ speed: undefined,
60
+ heading: undefined,
61
+ timestamp: 123,
62
+ },
63
+ cached: false,
64
+ });
65
+ });
66
+ it.each([
67
+ [1, "PERMISSION_DENIED"],
68
+ [2, "POSITION_UNAVAILABLE"],
69
+ [3, "TIMEOUT"],
70
+ [999, "UNKNOWN"],
71
+ ])("maps geolocation error code %s to %s", async (code, expected) => {
72
+ const getCurrentPosition = vi.fn((_success, error) => {
73
+ error(geoError(code));
74
+ });
75
+ setNavigator({
76
+ geolocation: { getCurrentPosition },
77
+ });
78
+ await expect(new LocationWeb().getCurrentPosition()).rejects.toEqual({
79
+ code: expected,
80
+ message: "geo failed",
81
+ });
82
+ });
83
+ it("tracks and clears watch ids without leaking native watches", async () => {
84
+ const clearWatch = vi.fn();
85
+ const watchPosition = vi.fn((success, _error, options) => {
86
+ expect(options?.enableHighAccuracy).toBe(false);
87
+ success(position());
88
+ return 42;
89
+ });
90
+ const plugin = new LocationWeb();
91
+ const notify = vi
92
+ .spyOn(plugin, "notifyListeners")
93
+ .mockResolvedValue(undefined);
94
+ setNavigator({
95
+ geolocation: { watchPosition, clearWatch },
96
+ });
97
+ const { watchId } = await plugin.watchPosition({ accuracy: "low" });
98
+ expect(watchId).toMatch(/^watch-/);
99
+ expect(notify).toHaveBeenCalledWith("locationChange", expect.objectContaining({ cached: false }));
100
+ await plugin.clearWatch({ watchId });
101
+ await plugin.clearWatch({ watchId });
102
+ expect(clearWatch).toHaveBeenCalledTimes(1);
103
+ expect(clearWatch).toHaveBeenCalledWith(42);
104
+ });
105
+ it.each([
106
+ ["getCurrentPosition", { timeout: Number.POSITIVE_INFINITY }],
107
+ ["getCurrentPosition", { maxAge: -1 }],
108
+ ["watchPosition", { timeout: 0 }],
109
+ ["watchPosition", { maxAge: Number.NaN }],
110
+ ["watchPosition", { minDistance: -1 }],
111
+ ["watchPosition", { minInterval: Number.POSITIVE_INFINITY }],
112
+ ])("rejects hostile %s options %#", async (method, options) => {
113
+ setNavigator({
114
+ geolocation: {
115
+ getCurrentPosition: vi.fn(),
116
+ watchPosition: vi.fn(),
117
+ clearWatch: vi.fn(),
118
+ },
119
+ });
120
+ const plugin = new LocationWeb();
121
+ await expect(plugin[method](options)).rejects.toThrow(/must be .*finite number/);
122
+ });
123
+ it("emits structured watch errors for geolocation failures", async () => {
124
+ const watchPosition = vi.fn((_success, error) => {
125
+ error(geoError(2, "offline"));
126
+ return 7;
127
+ });
128
+ const plugin = new LocationWeb();
129
+ const notify = vi
130
+ .spyOn(plugin, "notifyListeners")
131
+ .mockResolvedValue(undefined);
132
+ setNavigator({
133
+ geolocation: {
134
+ watchPosition,
135
+ clearWatch: vi.fn(),
136
+ },
137
+ });
138
+ await expect(plugin.watchPosition()).resolves.toEqual({
139
+ watchId: expect.stringMatching(/^watch-/),
140
+ });
141
+ expect(notify).toHaveBeenCalledWith("error", {
142
+ code: "POSITION_UNAVAILABLE",
143
+ message: "offline",
144
+ });
145
+ });
146
+ it("fails explicitly when the geolocation API is unavailable", async () => {
147
+ setNavigator({});
148
+ await expect(new LocationWeb().getCurrentPosition()).rejects.toThrow("Geolocation API is not available");
149
+ });
150
+ it("normalizes permission query states and falls back to prompt on query errors", async () => {
151
+ for (const [state, expected] of [
152
+ ["granted", "granted"],
153
+ ["denied", "denied"],
154
+ ["prompt", "prompt"],
155
+ ]) {
156
+ setNavigator({
157
+ permissions: {
158
+ query: vi.fn(async () => ({ state })),
159
+ },
160
+ });
161
+ await expect(new LocationWeb().checkPermissions()).resolves.toEqual({
162
+ location: expected,
163
+ });
164
+ }
165
+ setNavigator({
166
+ permissions: {
167
+ query: vi.fn(async () => {
168
+ throw new Error("unsupported");
169
+ }),
170
+ },
171
+ });
172
+ await expect(new LocationWeb().checkPermissions()).resolves.toEqual({
173
+ location: "prompt",
174
+ });
175
+ });
176
+ it("uses current-position request outcome to infer requested permission", async () => {
177
+ const granted = new LocationWeb();
178
+ vi.spyOn(granted, "getCurrentPosition").mockResolvedValue({
179
+ coords: {
180
+ latitude: 0,
181
+ longitude: 0,
182
+ accuracy: 1,
183
+ timestamp: 1,
184
+ },
185
+ cached: false,
186
+ });
187
+ await expect(granted.requestPermissions()).resolves.toEqual({
188
+ location: "granted",
189
+ });
190
+ const denied = new LocationWeb();
191
+ vi.spyOn(denied, "getCurrentPosition").mockRejectedValue({
192
+ code: "PERMISSION_DENIED",
193
+ });
194
+ await expect(denied.requestPermissions()).resolves.toEqual({
195
+ location: "denied",
196
+ });
197
+ });
198
+ });
199
+ //# sourceMappingURL=web.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.test.js","sourceRoot":"","sources":["../../src/web.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAKpC,SAAS,YAAY,CAAC,KAAyB;IAC7C,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,EAAE;QAC7C,YAAY,EAAE,IAAI;QAClB,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ;IACf,OAAO;QACL,MAAM,EAAE;YACN,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,CAAC;YACX,gBAAgB,EAAE,IAAI;YACtB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI;SACZ;QACD,SAAS,EAAE,GAAG;KACQ,CAAC;AAC3B,CAAC;AAED,SAAS,QAAQ,CACf,IAAY,EACZ,OAAO,GAAG,YAAY;IAEt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,MAAM,EAAE;gBACN,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,CAAC;gBACZ,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,CAAC;aACb;YACD,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YAC1D,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,iBAAiB,CAAC;YACvD,IAAI,EAAE,mBAAmB;SAC1B,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACzD,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -14,14 +14,44 @@ const Location = core.registerPlugin("ElizaLocation", {
14
14
  */
15
15
  class LocationWeb extends core.WebPlugin {
16
16
  watches = new Map();
17
+ getGeolocation() {
18
+ if (!navigator.geolocation) {
19
+ throw new Error("Geolocation API is not available");
20
+ }
21
+ return navigator.geolocation;
22
+ }
23
+ normalizePositionOptions(options) {
24
+ const maxAge = options?.maxAge ?? 0;
25
+ const timeout = options?.timeout ?? 10000;
26
+ if (!Number.isFinite(maxAge) || maxAge < 0) {
27
+ throw new Error("maxAge must be a non-negative finite number");
28
+ }
29
+ if (!Number.isFinite(timeout) || timeout <= 0) {
30
+ throw new Error("timeout must be a positive finite number");
31
+ }
32
+ return {
33
+ enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
34
+ maximumAge: Math.trunc(maxAge),
35
+ timeout: Math.trunc(timeout),
36
+ };
37
+ }
38
+ validateWatchOptions(options) {
39
+ if (options?.minDistance !== undefined) {
40
+ if (!Number.isFinite(options.minDistance) || options.minDistance < 0) {
41
+ throw new Error("minDistance must be a non-negative finite number");
42
+ }
43
+ }
44
+ if (options?.minInterval !== undefined) {
45
+ if (!Number.isFinite(options.minInterval) || options.minInterval < 0) {
46
+ throw new Error("minInterval must be a non-negative finite number");
47
+ }
48
+ }
49
+ }
17
50
  async getCurrentPosition(options) {
51
+ const geolocation = this.getGeolocation();
52
+ const geoOptions = this.normalizePositionOptions(options);
18
53
  return new Promise((resolve, reject) => {
19
- const geoOptions = {
20
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
21
- maximumAge: options?.maxAge ?? 0,
22
- timeout: options?.timeout ?? 10000,
23
- };
24
- navigator.geolocation.getCurrentPosition((position) => {
54
+ geolocation.getCurrentPosition((position) => {
25
55
  resolve({
26
56
  coords: {
27
57
  latitude: position.coords.latitude,
@@ -56,12 +86,10 @@ class LocationWeb extends core.WebPlugin {
56
86
  }
57
87
  async watchPosition(options) {
58
88
  const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;
59
- const geoOptions = {
60
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
61
- maximumAge: options?.maxAge ?? 0,
62
- timeout: options?.timeout ?? 10000,
63
- };
64
- const nativeWatchId = navigator.geolocation.watchPosition((position) => {
89
+ const geolocation = this.getGeolocation();
90
+ this.validateWatchOptions(options);
91
+ const geoOptions = this.normalizePositionOptions(options);
92
+ const nativeWatchId = geolocation.watchPosition((position) => {
65
93
  this.notifyListeners("locationChange", {
66
94
  coords: {
67
95
  latitude: position.coords.latitude,
@@ -96,10 +124,11 @@ class LocationWeb extends core.WebPlugin {
96
124
  return { watchId };
97
125
  }
98
126
  async clearWatch(options) {
99
- const nativeWatchId = this.watches.get(options.watchId);
127
+ const watchId = typeof options?.watchId === "string" ? options.watchId : "";
128
+ const nativeWatchId = this.watches.get(watchId);
100
129
  if (nativeWatchId !== undefined) {
101
- navigator.geolocation.clearWatch(nativeWatchId);
102
- this.watches.delete(options.watchId);
130
+ this.getGeolocation().clearWatch(nativeWatchId);
131
+ this.watches.delete(watchId);
103
132
  }
104
133
  }
105
134
  async checkPermissions() {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.LocationWeb());\nexport const Location = registerPlugin(\"ElizaLocation\", {\n web: loadWeb,\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web implementation of the Location Plugin\n *\n * Uses the browser Geolocation API.\n */\nexport class LocationWeb extends WebPlugin {\n watches = new Map();\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n const geoOptions = {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: options?.maxAge ?? 0,\n timeout: options?.timeout ?? 10000,\n };\n navigator.geolocation.getCurrentPosition((position) => {\n resolve({\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n reject({ code, message: error.message });\n }, geoOptions);\n });\n }\n async watchPosition(options) {\n const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n const geoOptions = {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: options?.maxAge ?? 0,\n timeout: options?.timeout ?? 10000,\n };\n const nativeWatchId = navigator.geolocation.watchPosition((position) => {\n this.notifyListeners(\"locationChange\", {\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n this.notifyListeners(\"error\", { code, message: error.message });\n }, geoOptions);\n this.watches.set(watchId, nativeWatchId);\n return { watchId };\n }\n async clearWatch(options) {\n const nativeWatchId = this.watches.get(options.watchId);\n if (nativeWatchId !== undefined) {\n navigator.geolocation.clearWatch(nativeWatchId);\n this.watches.delete(options.watchId);\n }\n }\n async checkPermissions() {\n if (\"permissions\" in navigator) {\n try {\n const result = await navigator.permissions.query({\n name: \"geolocation\",\n });\n return {\n location: result.state === \"granted\"\n ? \"granted\"\n : result.state === \"denied\"\n ? \"denied\"\n : \"prompt\",\n };\n }\n catch {\n return { location: \"prompt\" };\n }\n }\n return { location: \"prompt\" };\n }\n async requestPermissions() {\n // On web, permissions are requested implicitly when calling getCurrentPosition\n // Try to get current position to trigger permission request\n try {\n await this.getCurrentPosition({ timeout: 5000 });\n return { location: \"granted\" };\n }\n catch (error) {\n const e = error;\n if (e.code === \"PERMISSION_DENIED\") {\n return { location: \"denied\" };\n }\n return { location: \"prompt\" };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAA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AAQ,OAAO,KAAK,EAAE;AACtB,YAAY,MAAM,CAAC,GAAG,KAAK;AAC3B,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;AAChD,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAC7C,YAAY;AACZ,YAAY,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AACzC,QAAQ;AACR,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.LocationWeb());\nexport const Location = registerPlugin(\"ElizaLocation\", {\n web: loadWeb,\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web implementation of the Location Plugin\n *\n * Uses the browser Geolocation API.\n */\nexport class LocationWeb extends WebPlugin {\n watches = new Map();\n getGeolocation() {\n if (!navigator.geolocation) {\n throw new Error(\"Geolocation API is not available\");\n }\n return navigator.geolocation;\n }\n normalizePositionOptions(options) {\n const maxAge = options?.maxAge ?? 0;\n const timeout = options?.timeout ?? 10000;\n if (!Number.isFinite(maxAge) || maxAge < 0) {\n throw new Error(\"maxAge must be a non-negative finite number\");\n }\n if (!Number.isFinite(timeout) || timeout <= 0) {\n throw new Error(\"timeout must be a positive finite number\");\n }\n return {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: Math.trunc(maxAge),\n timeout: Math.trunc(timeout),\n };\n }\n validateWatchOptions(options) {\n if (options?.minDistance !== undefined) {\n if (!Number.isFinite(options.minDistance) || options.minDistance < 0) {\n throw new Error(\"minDistance must be a non-negative finite number\");\n }\n }\n if (options?.minInterval !== undefined) {\n if (!Number.isFinite(options.minInterval) || options.minInterval < 0) {\n throw new Error(\"minInterval must be a non-negative finite number\");\n }\n }\n }\n async getCurrentPosition(options) {\n const geolocation = this.getGeolocation();\n const geoOptions = this.normalizePositionOptions(options);\n return new Promise((resolve, reject) => {\n geolocation.getCurrentPosition((position) => {\n resolve({\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n reject({ code, message: error.message });\n }, geoOptions);\n });\n }\n async watchPosition(options) {\n const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n const geolocation = this.getGeolocation();\n this.validateWatchOptions(options);\n const geoOptions = this.normalizePositionOptions(options);\n const nativeWatchId = geolocation.watchPosition((position) => {\n this.notifyListeners(\"locationChange\", {\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n this.notifyListeners(\"error\", { code, message: error.message });\n }, geoOptions);\n this.watches.set(watchId, nativeWatchId);\n return { watchId };\n }\n async clearWatch(options) {\n const watchId = typeof options?.watchId === \"string\" ? options.watchId : \"\";\n const nativeWatchId = this.watches.get(watchId);\n if (nativeWatchId !== undefined) {\n this.getGeolocation().clearWatch(nativeWatchId);\n this.watches.delete(watchId);\n }\n }\n async checkPermissions() {\n if (\"permissions\" in navigator) {\n try {\n const result = await navigator.permissions.query({\n name: \"geolocation\",\n });\n return {\n location: result.state === \"granted\"\n ? \"granted\"\n : result.state === \"denied\"\n ? \"denied\"\n : \"prompt\",\n };\n }\n catch {\n return { location: \"prompt\" };\n }\n }\n return { location: \"prompt\" };\n }\n async requestPermissions() {\n // On web, permissions are requested implicitly when calling getCurrentPosition\n // Try to get current position to trigger permission request\n try {\n await this.getCurrentPosition({ timeout: 5000 });\n return { location: \"granted\" };\n }\n catch (error) {\n const e = error;\n if (e.code === \"PERMISSION_DENIED\") {\n return { location: \"denied\" };\n }\n return { location: \"prompt\" };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC1D,MAAC,QAAQ,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACxD,IAAI,GAAG,EAAE,OAAO;AAChB,CAAC;;ACJD;AACA;AACA;AACA;AACA;AACO,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,OAAO,GAAG,IAAI,GAAG,EAAE;AACvB,IAAI,cAAc,GAAG;AACrB,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACpC,YAAY,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;AAC/D,QAAQ;AACR,QAAQ,OAAO,SAAS,CAAC,WAAW;AACpC,IAAI;AACJ,IAAI,wBAAwB,CAAC,OAAO,EAAE;AACtC,QAAQ,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,CAAC;AAC3C,QAAQ,MAAM,OAAO,GAAG,OAAO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MAAM,gBAAgB,GAAG;AAC7B,QAAQ,IAAI,aAAa,IAAI,SAAS,EAAE;AACxC,YAAY,IAAI;AAChB,gBAAgB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;AACjE,oBAAoB,IAAI,EAAE,aAAa;AACvC,iBAAiB,CAAC;AAClB,gBAAgB,OAAO;AACvB,oBAAoB,QAAQ,EAAE,MAAM,CAAC,KAAK,KAAK;AAC/C,0BAA0B;AAC1B,0BAA0B,MAAM,CAAC,KAAK,KAAK;AAC3C,8BAA8B;AAC9B,8BAA8B,QAAQ;AACtC,iBAAiB;AACjB,YAAY;AACZ,YAAY,MAAM;AAClB,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAC7C,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AACrC,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B;AACA;AACA,QAAQ,IAAI;AACZ,YAAY,MAAM,IAAI,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC5D,YAAY,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE;AAC1C,QAAQ;AACR,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,MAAM,CAAC,GAAG,KAAK;AAC3B,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;AAChD,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAC7C,YAAY;AACZ,YAAY,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AACzC,QAAQ;AACR,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -13,14 +13,44 @@ var capacitorLocation = (function (exports, core) {
13
13
  */
14
14
  class LocationWeb extends core.WebPlugin {
15
15
  watches = new Map();
16
+ getGeolocation() {
17
+ if (!navigator.geolocation) {
18
+ throw new Error("Geolocation API is not available");
19
+ }
20
+ return navigator.geolocation;
21
+ }
22
+ normalizePositionOptions(options) {
23
+ const maxAge = options?.maxAge ?? 0;
24
+ const timeout = options?.timeout ?? 10000;
25
+ if (!Number.isFinite(maxAge) || maxAge < 0) {
26
+ throw new Error("maxAge must be a non-negative finite number");
27
+ }
28
+ if (!Number.isFinite(timeout) || timeout <= 0) {
29
+ throw new Error("timeout must be a positive finite number");
30
+ }
31
+ return {
32
+ enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
33
+ maximumAge: Math.trunc(maxAge),
34
+ timeout: Math.trunc(timeout),
35
+ };
36
+ }
37
+ validateWatchOptions(options) {
38
+ if (options?.minDistance !== undefined) {
39
+ if (!Number.isFinite(options.minDistance) || options.minDistance < 0) {
40
+ throw new Error("minDistance must be a non-negative finite number");
41
+ }
42
+ }
43
+ if (options?.minInterval !== undefined) {
44
+ if (!Number.isFinite(options.minInterval) || options.minInterval < 0) {
45
+ throw new Error("minInterval must be a non-negative finite number");
46
+ }
47
+ }
48
+ }
16
49
  async getCurrentPosition(options) {
50
+ const geolocation = this.getGeolocation();
51
+ const geoOptions = this.normalizePositionOptions(options);
17
52
  return new Promise((resolve, reject) => {
18
- const geoOptions = {
19
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
20
- maximumAge: options?.maxAge ?? 0,
21
- timeout: options?.timeout ?? 10000,
22
- };
23
- navigator.geolocation.getCurrentPosition((position) => {
53
+ geolocation.getCurrentPosition((position) => {
24
54
  resolve({
25
55
  coords: {
26
56
  latitude: position.coords.latitude,
@@ -55,12 +85,10 @@ var capacitorLocation = (function (exports, core) {
55
85
  }
56
86
  async watchPosition(options) {
57
87
  const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;
58
- const geoOptions = {
59
- enableHighAccuracy: options?.accuracy === "best" || options?.accuracy === "high",
60
- maximumAge: options?.maxAge ?? 0,
61
- timeout: options?.timeout ?? 10000,
62
- };
63
- const nativeWatchId = navigator.geolocation.watchPosition((position) => {
88
+ const geolocation = this.getGeolocation();
89
+ this.validateWatchOptions(options);
90
+ const geoOptions = this.normalizePositionOptions(options);
91
+ const nativeWatchId = geolocation.watchPosition((position) => {
64
92
  this.notifyListeners("locationChange", {
65
93
  coords: {
66
94
  latitude: position.coords.latitude,
@@ -95,10 +123,11 @@ var capacitorLocation = (function (exports, core) {
95
123
  return { watchId };
96
124
  }
97
125
  async clearWatch(options) {
98
- const nativeWatchId = this.watches.get(options.watchId);
126
+ const watchId = typeof options?.watchId === "string" ? options.watchId : "";
127
+ const nativeWatchId = this.watches.get(watchId);
99
128
  if (nativeWatchId !== undefined) {
100
- navigator.geolocation.clearWatch(nativeWatchId);
101
- this.watches.delete(options.watchId);
129
+ this.getGeolocation().clearWatch(nativeWatchId);
130
+ this.watches.delete(watchId);
102
131
  }
103
132
  }
104
133
  async checkPermissions() {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.LocationWeb());\nexport const Location = registerPlugin(\"ElizaLocation\", {\n web: loadWeb,\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web implementation of the Location Plugin\n *\n * Uses the browser Geolocation API.\n */\nexport class LocationWeb extends WebPlugin {\n watches = new Map();\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n const geoOptions = {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: options?.maxAge ?? 0,\n timeout: options?.timeout ?? 10000,\n };\n navigator.geolocation.getCurrentPosition((position) => {\n resolve({\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n reject({ code, message: error.message });\n }, geoOptions);\n });\n }\n async watchPosition(options) {\n const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n const geoOptions = {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: options?.maxAge ?? 0,\n timeout: options?.timeout ?? 10000,\n };\n const nativeWatchId = navigator.geolocation.watchPosition((position) => {\n this.notifyListeners(\"locationChange\", {\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n this.notifyListeners(\"error\", { code, message: error.message });\n }, geoOptions);\n this.watches.set(watchId, nativeWatchId);\n return { watchId };\n }\n async clearWatch(options) {\n const nativeWatchId = this.watches.get(options.watchId);\n if (nativeWatchId !== undefined) {\n navigator.geolocation.clearWatch(nativeWatchId);\n this.watches.delete(options.watchId);\n }\n }\n async checkPermissions() {\n if (\"permissions\" in navigator) {\n try {\n const result = await navigator.permissions.query({\n name: \"geolocation\",\n });\n return {\n location: result.state === \"granted\"\n ? \"granted\"\n : result.state === \"denied\"\n ? \"denied\"\n : \"prompt\",\n };\n }\n catch {\n return { location: \"prompt\" };\n }\n }\n return { location: \"prompt\" };\n }\n async requestPermissions() {\n // On web, permissions are requested implicitly when calling getCurrentPosition\n // Try to get current position to trigger permission request\n try {\n await this.getCurrentPosition({ timeout: 5000 });\n return { location: \"granted\" };\n }\n catch (error) {\n const e = error;\n if (e.code === \"PERMISSION_DENIED\") {\n return { location: \"denied\" };\n }\n return { location: \"prompt\" };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC1D,UAAC,QAAQ,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACxD,IAAI,GAAG,EAAE,OAAO;IAChB,CAAC;;ICJD;IACA;IACA;IACA;IACA;IACO,MAAM,WAAW,SAASC,cAAS,CAAC;IAC3C,IAAI,OAAO,GAAG,IAAI,GAAG,EAAE;IACvB,IAAI,MAAM,kBAAkB,CAAC,OAAO,EAAE;IACtC,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YAAY,MAAM,UAAU,GAAG;IAC/B,gBAAgB,kBAAkB,EAAE,OAAO,EAAE,QAAQ,KAAK,MAAM,IAAI,OAAO,EAAE,QAAQ,KAAK,MAAM;IAChG,gBAAgB,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;IAChD,gBAAgB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK;IAClD,aAAa;IACb,YAAY,SAAS,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,QAAQ,KAAK;IACnE,gBAAgB,OAAO,CAAC;IACxB,oBAAoB,MAAM,EAAE;IAC5B,wBAAwB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;IAC1D,wBAAwB,SAAS,EAAE,QAAQ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;IAC9B,8BAA8B,QAAQ;IACtC,iBAAiB;IACjB,YAAY;IACZ,YAAY,MAAM;IAClB,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAC7C,YAAY;IACZ,QAAQ;IACR,QAAQ,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IACrC,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B;IACA;IACA,QAAQ,IAAI;IACZ,YAAY,MAAM,IAAI,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5D,YAAY,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE;IAC1C,QAAQ;IACR,QAAQ,OAAO,KAAK,EAAE;IACtB,YAAY,MAAM,CAAC,GAAG,KAAK;IAC3B,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;IAChD,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAC7C,YAAY;IACZ,YAAY,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IACzC,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.LocationWeb());\nexport const Location = registerPlugin(\"ElizaLocation\", {\n web: loadWeb,\n});\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\n/**\n * Web implementation of the Location Plugin\n *\n * Uses the browser Geolocation API.\n */\nexport class LocationWeb extends WebPlugin {\n watches = new Map();\n getGeolocation() {\n if (!navigator.geolocation) {\n throw new Error(\"Geolocation API is not available\");\n }\n return navigator.geolocation;\n }\n normalizePositionOptions(options) {\n const maxAge = options?.maxAge ?? 0;\n const timeout = options?.timeout ?? 10000;\n if (!Number.isFinite(maxAge) || maxAge < 0) {\n throw new Error(\"maxAge must be a non-negative finite number\");\n }\n if (!Number.isFinite(timeout) || timeout <= 0) {\n throw new Error(\"timeout must be a positive finite number\");\n }\n return {\n enableHighAccuracy: options?.accuracy === \"best\" || options?.accuracy === \"high\",\n maximumAge: Math.trunc(maxAge),\n timeout: Math.trunc(timeout),\n };\n }\n validateWatchOptions(options) {\n if (options?.minDistance !== undefined) {\n if (!Number.isFinite(options.minDistance) || options.minDistance < 0) {\n throw new Error(\"minDistance must be a non-negative finite number\");\n }\n }\n if (options?.minInterval !== undefined) {\n if (!Number.isFinite(options.minInterval) || options.minInterval < 0) {\n throw new Error(\"minInterval must be a non-negative finite number\");\n }\n }\n }\n async getCurrentPosition(options) {\n const geolocation = this.getGeolocation();\n const geoOptions = this.normalizePositionOptions(options);\n return new Promise((resolve, reject) => {\n geolocation.getCurrentPosition((position) => {\n resolve({\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n reject({ code, message: error.message });\n }, geoOptions);\n });\n }\n async watchPosition(options) {\n const watchId = `watch-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n const geolocation = this.getGeolocation();\n this.validateWatchOptions(options);\n const geoOptions = this.normalizePositionOptions(options);\n const nativeWatchId = geolocation.watchPosition((position) => {\n this.notifyListeners(\"locationChange\", {\n coords: {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n altitude: position.coords.altitude ?? undefined,\n accuracy: position.coords.accuracy,\n altitudeAccuracy: position.coords.altitudeAccuracy ?? undefined,\n speed: position.coords.speed ?? undefined,\n heading: position.coords.heading ?? undefined,\n timestamp: position.timestamp,\n },\n cached: false,\n });\n }, (error) => {\n let code;\n switch (error.code) {\n case error.PERMISSION_DENIED:\n code = \"PERMISSION_DENIED\";\n break;\n case error.POSITION_UNAVAILABLE:\n code = \"POSITION_UNAVAILABLE\";\n break;\n case error.TIMEOUT:\n code = \"TIMEOUT\";\n break;\n default:\n code = \"UNKNOWN\";\n }\n this.notifyListeners(\"error\", { code, message: error.message });\n }, geoOptions);\n this.watches.set(watchId, nativeWatchId);\n return { watchId };\n }\n async clearWatch(options) {\n const watchId = typeof options?.watchId === \"string\" ? options.watchId : \"\";\n const nativeWatchId = this.watches.get(watchId);\n if (nativeWatchId !== undefined) {\n this.getGeolocation().clearWatch(nativeWatchId);\n this.watches.delete(watchId);\n }\n }\n async checkPermissions() {\n if (\"permissions\" in navigator) {\n try {\n const result = await navigator.permissions.query({\n name: \"geolocation\",\n });\n return {\n location: result.state === \"granted\"\n ? \"granted\"\n : result.state === \"denied\"\n ? \"denied\"\n : \"prompt\",\n };\n }\n catch {\n return { location: \"prompt\" };\n }\n }\n return { location: \"prompt\" };\n }\n async requestPermissions() {\n // On web, permissions are requested implicitly when calling getCurrentPosition\n // Try to get current position to trigger permission request\n try {\n await this.getCurrentPosition({ timeout: 5000 });\n return { location: \"granted\" };\n }\n catch (error) {\n const e = error;\n if (e.code === \"PERMISSION_DENIED\") {\n return { location: \"denied\" };\n }\n return { location: \"prompt\" };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC1D,UAAC,QAAQ,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACxD,IAAI,GAAG,EAAE,OAAO;IAChB,CAAC;;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,YAAY,MAAM,CAAC,GAAG,KAAK;IAC3B,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;IAChD,gBAAgB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAC7C,YAAY;IACZ,YAAY,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;IACzC,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/capacitor-location",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.11-beta.7",
4
4
  "description": "Reads current location, watches movement, and manages geolocation permissions.",
5
5
  "keywords": [
6
6
  "location",
@@ -14,6 +14,8 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/esm/index.d.ts",
17
+ "bun": "./src/index.ts",
18
+ "development": "./src/index.ts",
17
19
  "import": "./dist/esm/index.js",
18
20
  "require": "./dist/plugin.cjs.js"
19
21
  },
@@ -29,17 +31,17 @@
29
31
  "dist"
30
32
  ],
31
33
  "scripts": {
32
- "build": "bun run clean && tsc && bun --bun rollup -c rollup.config.mjs",
34
+ "build": "node ../../packages/scripts/with-package-build-lock.mjs plugins/plugin-native-location -- bun run build:unlocked",
33
35
  "build:docs": "bun run clean && bun run docgen && tsc && bun --bun rollup -c rollup.config.mjs",
34
- "clean": "node ../../../scripts/rm-path-recursive.mjs dist",
36
+ "clean": "node ../../packages/scripts/rm-path-recursive.mjs dist",
35
37
  "prepublishOnly": "bun run build",
36
- "docgen": "docgen --api LocationPlugin --output-readme README.md --output-json dist/docs.json"
38
+ "test": "vitest run",
39
+ "docgen": "docgen --api LocationPlugin --output-readme README.md --output-json dist/docs.json",
40
+ "build:unlocked": "bun run clean && tsc && bunx rollup -c rollup.config.mjs"
37
41
  },
38
42
  "author": "elizaOS",
39
43
  "license": "MIT",
40
- "dependencies": {
41
- "@elizaos/app-core": "2.0.0-beta.1"
42
- },
44
+ "dependencies": {},
43
45
  "repository": {
44
46
  "type": "git",
45
47
  "url": "https://github.com/elizaOS/eliza.git",
@@ -55,12 +57,11 @@
55
57
  }
56
58
  },
57
59
  "devDependencies": {
58
- "@capacitor/cli": "^8.0.0",
59
60
  "@capacitor/core": "^8.3.1",
60
61
  "@capacitor/docgen": "^0.3.0",
61
- "rimraf": "^6.0.0",
62
62
  "rollup": "^4.60.2",
63
- "typescript": "^6.0.3"
63
+ "typescript": "^6.0.3",
64
+ "vitest": "^4.0.0"
64
65
  },
65
66
  "peerDependencies": {
66
67
  "@capacitor/core": "^8.3.1"
@@ -80,5 +81,6 @@
80
81
  "ios": true,
81
82
  "android": true
82
83
  }
83
- }
84
+ },
85
+ "gitHead": "cdbc876f793d96073d7eb0d09715a031ce0cd32e"
84
86
  }