expo-background-tracking 1.0.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/build/geo.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /** Geodesic helpers. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.haversine = haversine;
5
+ exports.pointInPolygon = pointInPolygon;
6
+ exports.centroid = centroid;
7
+ exports.uuidv4 = uuidv4;
8
+ const R = 6371000; // earth radius, metres
9
+ function haversine(lat1, lon1, lat2, lon2) {
10
+ const toRad = (d) => (d * Math.PI) / 180;
11
+ const dLat = toRad(lat2 - lat1);
12
+ const dLon = toRad(lon2 - lon1);
13
+ const a = Math.sin(dLat / 2) ** 2 +
14
+ Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
15
+ return 2 * R * Math.asin(Math.sqrt(a));
16
+ }
17
+ /** Point-in-polygon (ray casting) — vertices as [lat, lon]. */
18
+ function pointInPolygon(lat, lon, vertices) {
19
+ let inside = false;
20
+ for (let i = 0, j = vertices.length - 1; i < vertices.length; j = i++) {
21
+ const [yi, xi] = vertices[i];
22
+ const [yj, xj] = vertices[j];
23
+ if (yi > lat !== yj > lat && lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) {
24
+ inside = !inside;
25
+ }
26
+ }
27
+ return inside;
28
+ }
29
+ /** Centroid of a polygon's vertices ([lat, lon]). */
30
+ function centroid(vertices) {
31
+ const n = vertices.length || 1;
32
+ let lat = 0;
33
+ let lon = 0;
34
+ for (const [vLat, vLon] of vertices) {
35
+ lat += vLat;
36
+ lon += vLon;
37
+ }
38
+ return { latitude: lat / n, longitude: lon / n };
39
+ }
40
+ function uuidv4() {
41
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
42
+ const r = (Math.random() * 16) | 0;
43
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
44
+ return v.toString(16);
45
+ });
46
+ }
@@ -0,0 +1,6 @@
1
+ export { BackgroundGeolocation, LOCATION_TASK } from './BackgroundGeolocation';
2
+ export { GEOFENCE_TASK } from './GeofenceManager';
3
+ export { isExpoGo, isBackgroundCapable } from './environment';
4
+ export * from './types';
5
+ import { BackgroundGeolocation } from './BackgroundGeolocation';
6
+ export default BackgroundGeolocation;
package/build/index.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.isBackgroundCapable = exports.isExpoGo = exports.GEOFENCE_TASK = exports.LOCATION_TASK = exports.BackgroundGeolocation = void 0;
18
+ var BackgroundGeolocation_1 = require("./BackgroundGeolocation");
19
+ Object.defineProperty(exports, "BackgroundGeolocation", { enumerable: true, get: function () { return BackgroundGeolocation_1.BackgroundGeolocation; } });
20
+ Object.defineProperty(exports, "LOCATION_TASK", { enumerable: true, get: function () { return BackgroundGeolocation_1.LOCATION_TASK; } });
21
+ var GeofenceManager_1 = require("./GeofenceManager");
22
+ Object.defineProperty(exports, "GEOFENCE_TASK", { enumerable: true, get: function () { return GeofenceManager_1.GEOFENCE_TASK; } });
23
+ var environment_1 = require("./environment");
24
+ Object.defineProperty(exports, "isExpoGo", { enumerable: true, get: function () { return environment_1.isExpoGo; } });
25
+ Object.defineProperty(exports, "isBackgroundCapable", { enumerable: true, get: function () { return environment_1.isBackgroundCapable; } });
26
+ __exportStar(require("./types"), exports);
27
+ const BackgroundGeolocation_2 = require("./BackgroundGeolocation");
28
+ exports.default = BackgroundGeolocation_2.BackgroundGeolocation;
@@ -0,0 +1,275 @@
1
+ /**
2
+ * expo-background-tracking — Type definitions.
3
+ * API surface modeled after transistorsoft/react-native-background-geolocation.
4
+ */
5
+ export declare enum DesiredAccuracy {
6
+ NAVIGATION = -2,
7
+ HIGH = -1,
8
+ MEDIUM = 10,
9
+ LOW = 100,
10
+ VERY_LOW = 1000,
11
+ LOWEST = 3000
12
+ }
13
+ export declare enum LogLevel {
14
+ OFF = 0,
15
+ ERROR = 1,
16
+ WARNING = 2,
17
+ INFO = 3,
18
+ DEBUG = 4,
19
+ VERBOSE = 5
20
+ }
21
+ export declare enum ActivityType {
22
+ OTHER = 1,
23
+ AUTOMOTIVE_NAVIGATION = 2,
24
+ FITNESS = 3,
25
+ OTHER_NAVIGATION = 4,
26
+ AIRBORNE = 5
27
+ }
28
+ export declare enum PersistMode {
29
+ ALL = 2,
30
+ LOCATION = 1,
31
+ GEOFENCE = -1,
32
+ NONE = 0
33
+ }
34
+ export declare enum AuthorizationStatus {
35
+ NOT_DETERMINED = 0,
36
+ RESTRICTED = 1,
37
+ DENIED = 2,
38
+ ALWAYS = 3,
39
+ WHEN_IN_USE = 4
40
+ }
41
+ export declare enum AccuracyAuthorization {
42
+ FULL = 0,
43
+ REDUCED = 1
44
+ }
45
+ export type MotionActivityType = 'still' | 'walking' | 'on_foot' | 'running' | 'on_bicycle' | 'in_vehicle' | 'unknown';
46
+ export type GeofenceAction = 'ENTER' | 'EXIT' | 'DWELL';
47
+ export type TrackingMode = 0 | 1;
48
+ export type LocationError = 0 | 1 | 2 | 3 | 408 | 499;
49
+ export interface Coords {
50
+ latitude: number;
51
+ longitude: number;
52
+ accuracy: number;
53
+ speed: number;
54
+ speed_accuracy?: number;
55
+ heading: number;
56
+ heading_accuracy?: number;
57
+ altitude: number;
58
+ altitude_accuracy?: number;
59
+ ellipsoidal_altitude?: number;
60
+ }
61
+ export interface Battery {
62
+ level: number;
63
+ is_charging: boolean;
64
+ }
65
+ export interface ActivityChangeEvent {
66
+ activity: MotionActivityType;
67
+ confidence: number;
68
+ }
69
+ export interface Location {
70
+ uuid: string;
71
+ timestamp: string;
72
+ age?: number;
73
+ odometer: number;
74
+ is_moving: boolean;
75
+ coords: Coords;
76
+ activity: ActivityChangeEvent;
77
+ battery: Battery;
78
+ extras?: Record<string, unknown>;
79
+ event?: 'motionchange' | 'geofence' | 'heartbeat' | 'providerchange';
80
+ mock?: boolean;
81
+ sample?: boolean;
82
+ }
83
+ export interface MotionChangeEvent {
84
+ isMoving: boolean;
85
+ location: Location;
86
+ }
87
+ export interface HeartbeatEvent {
88
+ location: Location;
89
+ }
90
+ export interface Geofence {
91
+ identifier: string;
92
+ radius?: number;
93
+ latitude?: number;
94
+ longitude?: number;
95
+ /** Polygon geofence: list of [latitude, longitude] vertices. */
96
+ vertices?: Array<[number, number]>;
97
+ notifyOnEntry?: boolean;
98
+ notifyOnExit?: boolean;
99
+ notifyOnDwell?: boolean;
100
+ loiteringDelay?: number;
101
+ extras?: Record<string, unknown>;
102
+ }
103
+ export interface GeofenceEvent {
104
+ identifier: string;
105
+ action: GeofenceAction;
106
+ location: Location;
107
+ extras?: Record<string, unknown>;
108
+ }
109
+ export interface GeofencesChangeEvent {
110
+ on: Geofence[];
111
+ off: string[];
112
+ }
113
+ export interface HttpEvent {
114
+ success: boolean;
115
+ status: number;
116
+ responseText: string;
117
+ }
118
+ export interface Authorization {
119
+ strategy?: 'JWT' | 'BASIC';
120
+ accessToken?: string;
121
+ refreshToken?: string;
122
+ refreshUrl?: string;
123
+ refreshPayload?: Record<string, string>;
124
+ refreshHeaders?: Record<string, string>;
125
+ expires?: number;
126
+ }
127
+ export interface AuthorizationEvent {
128
+ success: boolean;
129
+ status?: number;
130
+ response?: Record<string, unknown>;
131
+ error?: string;
132
+ }
133
+ export interface ProviderChangeEvent {
134
+ enabled: boolean;
135
+ status: AuthorizationStatus;
136
+ network: boolean;
137
+ gps: boolean;
138
+ accuracyAuthorization: AccuracyAuthorization;
139
+ }
140
+ export interface ConnectivityChangeEvent {
141
+ connected: boolean;
142
+ }
143
+ /** e.g. "1-5 09:00-17:00" (ISO day numbers 1=Monday … 7=Sunday) */
144
+ export type ScheduleItem = string;
145
+ export interface ScheduleEvent {
146
+ enabled: boolean;
147
+ state: State;
148
+ }
149
+ export interface Notification {
150
+ title?: string;
151
+ text?: string;
152
+ color?: string;
153
+ channelName?: string;
154
+ smallIcon?: string;
155
+ largeIcon?: string;
156
+ priority?: number;
157
+ sticky?: boolean;
158
+ actions?: string[];
159
+ }
160
+ export interface Config {
161
+ desiredAccuracy?: DesiredAccuracy;
162
+ distanceFilter?: number;
163
+ stationaryRadius?: number;
164
+ locationTimeout?: number;
165
+ useSignificantChangesOnly?: boolean;
166
+ pausesLocationUpdatesAutomatically?: boolean;
167
+ showsBackgroundLocationIndicator?: boolean;
168
+ activityType?: ActivityType;
169
+ deferTime?: number;
170
+ disableElasticity?: boolean;
171
+ elasticityMultiplier?: number;
172
+ stopAfterElapsedMinutes?: number;
173
+ geofenceProximityRadius?: number;
174
+ geofenceInitialTriggerEntry?: boolean;
175
+ geofenceModeHighAccuracy?: boolean;
176
+ isMoving?: boolean;
177
+ stopTimeout?: number;
178
+ motionTriggerDelay?: number;
179
+ disableMotionActivityUpdates?: boolean;
180
+ disableStopDetection?: boolean;
181
+ stopOnStationary?: boolean;
182
+ url?: string;
183
+ method?: 'POST' | 'PUT' | 'OPTIONS';
184
+ httpRootProperty?: string;
185
+ params?: Record<string, unknown>;
186
+ headers?: Record<string, string>;
187
+ extras?: Record<string, unknown>;
188
+ autoSync?: boolean;
189
+ autoSyncThreshold?: number;
190
+ batchSync?: boolean;
191
+ maxBatchSize?: number;
192
+ locationTemplate?: string;
193
+ geofenceTemplate?: string;
194
+ maxDaysToPersist?: number;
195
+ maxRecordsToPersist?: number;
196
+ persistMode?: PersistMode;
197
+ httpTimeout?: number;
198
+ authorization?: Authorization;
199
+ disableAutoSyncOnCellular?: boolean;
200
+ stopOnTerminate?: boolean;
201
+ startOnBoot?: boolean;
202
+ heartbeatInterval?: number;
203
+ schedule?: ScheduleItem[];
204
+ preventSuspend?: boolean;
205
+ foregroundService?: boolean;
206
+ notification?: Notification;
207
+ debug?: boolean;
208
+ logLevel?: LogLevel;
209
+ logMaxDays?: number;
210
+ locationAuthorizationRequest?: 'Always' | 'WhenInUse' | 'Any';
211
+ backgroundPermissionRationale?: {
212
+ title?: string;
213
+ message?: string;
214
+ positiveAction?: string;
215
+ negativeAction?: string;
216
+ };
217
+ reset?: boolean;
218
+ }
219
+ export interface State extends Config {
220
+ enabled: boolean;
221
+ isMoving?: boolean;
222
+ schedulerEnabled: boolean;
223
+ trackingMode: TrackingMode;
224
+ odometer: number;
225
+ didLaunchInBackground?: boolean;
226
+ isFirstBoot?: boolean;
227
+ }
228
+ export interface CurrentPositionRequest {
229
+ timeout?: number;
230
+ maximumAge?: number;
231
+ persist?: boolean;
232
+ samples?: number;
233
+ desiredAccuracy?: number;
234
+ extras?: Record<string, unknown>;
235
+ }
236
+ export interface WatchPositionRequest {
237
+ interval?: number;
238
+ desiredAccuracy?: DesiredAccuracy;
239
+ persist?: boolean;
240
+ extras?: Record<string, unknown>;
241
+ }
242
+ export interface Sensors {
243
+ platform: 'ios' | 'android' | string;
244
+ accelerometer: boolean;
245
+ gyroscope: boolean;
246
+ magnetometer: boolean;
247
+ motion_hardware: boolean;
248
+ }
249
+ export interface DeviceInfo {
250
+ model: string;
251
+ manufacturer: string;
252
+ version: string;
253
+ platform: string;
254
+ framework: string;
255
+ }
256
+ export interface SQLQuery {
257
+ start?: number;
258
+ end?: number;
259
+ limit?: number;
260
+ order?: -1 | 1;
261
+ }
262
+ export interface HeadlessEvent {
263
+ name: 'location' | 'motionchange' | 'geofence' | 'heartbeat' | 'http' | 'providerchange' | 'connectivitychange' | 'powersavechange' | 'schedule' | 'enabledchange' | 'activitychange' | 'authorization' | 'geofenceschange' | 'notificationaction';
264
+ params: unknown;
265
+ }
266
+ export type HeadlessTask = (event: HeadlessEvent) => Promise<void>;
267
+ export interface Subscription {
268
+ remove: () => void;
269
+ }
270
+ export type EventName = HeadlessEvent['name'];
271
+ export interface LogEntry {
272
+ timestamp: string;
273
+ level: string;
274
+ message: string;
275
+ }
package/build/types.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * expo-background-tracking — Type definitions.
4
+ * API surface modeled after transistorsoft/react-native-background-geolocation.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.AccuracyAuthorization = exports.AuthorizationStatus = exports.PersistMode = exports.ActivityType = exports.LogLevel = exports.DesiredAccuracy = void 0;
8
+ // ---------------------------------------------------------------------------
9
+ // Enums / constants
10
+ // ---------------------------------------------------------------------------
11
+ var DesiredAccuracy;
12
+ (function (DesiredAccuracy) {
13
+ DesiredAccuracy[DesiredAccuracy["NAVIGATION"] = -2] = "NAVIGATION";
14
+ DesiredAccuracy[DesiredAccuracy["HIGH"] = -1] = "HIGH";
15
+ DesiredAccuracy[DesiredAccuracy["MEDIUM"] = 10] = "MEDIUM";
16
+ DesiredAccuracy[DesiredAccuracy["LOW"] = 100] = "LOW";
17
+ DesiredAccuracy[DesiredAccuracy["VERY_LOW"] = 1000] = "VERY_LOW";
18
+ DesiredAccuracy[DesiredAccuracy["LOWEST"] = 3000] = "LOWEST";
19
+ })(DesiredAccuracy || (exports.DesiredAccuracy = DesiredAccuracy = {}));
20
+ var LogLevel;
21
+ (function (LogLevel) {
22
+ LogLevel[LogLevel["OFF"] = 0] = "OFF";
23
+ LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
24
+ LogLevel[LogLevel["WARNING"] = 2] = "WARNING";
25
+ LogLevel[LogLevel["INFO"] = 3] = "INFO";
26
+ LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
27
+ LogLevel[LogLevel["VERBOSE"] = 5] = "VERBOSE";
28
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
29
+ var ActivityType;
30
+ (function (ActivityType) {
31
+ ActivityType[ActivityType["OTHER"] = 1] = "OTHER";
32
+ ActivityType[ActivityType["AUTOMOTIVE_NAVIGATION"] = 2] = "AUTOMOTIVE_NAVIGATION";
33
+ ActivityType[ActivityType["FITNESS"] = 3] = "FITNESS";
34
+ ActivityType[ActivityType["OTHER_NAVIGATION"] = 4] = "OTHER_NAVIGATION";
35
+ ActivityType[ActivityType["AIRBORNE"] = 5] = "AIRBORNE";
36
+ })(ActivityType || (exports.ActivityType = ActivityType = {}));
37
+ var PersistMode;
38
+ (function (PersistMode) {
39
+ PersistMode[PersistMode["ALL"] = 2] = "ALL";
40
+ PersistMode[PersistMode["LOCATION"] = 1] = "LOCATION";
41
+ PersistMode[PersistMode["GEOFENCE"] = -1] = "GEOFENCE";
42
+ PersistMode[PersistMode["NONE"] = 0] = "NONE";
43
+ })(PersistMode || (exports.PersistMode = PersistMode = {}));
44
+ var AuthorizationStatus;
45
+ (function (AuthorizationStatus) {
46
+ AuthorizationStatus[AuthorizationStatus["NOT_DETERMINED"] = 0] = "NOT_DETERMINED";
47
+ AuthorizationStatus[AuthorizationStatus["RESTRICTED"] = 1] = "RESTRICTED";
48
+ AuthorizationStatus[AuthorizationStatus["DENIED"] = 2] = "DENIED";
49
+ AuthorizationStatus[AuthorizationStatus["ALWAYS"] = 3] = "ALWAYS";
50
+ AuthorizationStatus[AuthorizationStatus["WHEN_IN_USE"] = 4] = "WHEN_IN_USE";
51
+ })(AuthorizationStatus || (exports.AuthorizationStatus = AuthorizationStatus = {}));
52
+ var AccuracyAuthorization;
53
+ (function (AccuracyAuthorization) {
54
+ AccuracyAuthorization[AccuracyAuthorization["FULL"] = 0] = "FULL";
55
+ AccuracyAuthorization[AccuracyAuthorization["REDUCED"] = 1] = "REDUCED";
56
+ })(AccuracyAuthorization || (exports.AccuracyAuthorization = AccuracyAuthorization = {}));