@wayq/beekon-rn 0.0.1 → 0.0.5

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.
Files changed (92) hide show
  1. package/BeekonRn.podspec +4 -4
  2. package/README.md +94 -48
  3. package/android/build.gradle +11 -6
  4. package/android/src/main/java/in/wayq/beekonrn/BeekonRnModule.kt +428 -0
  5. package/android/src/main/java/{com → in}/wayq/beekonrn/BeekonRnPackage.kt +1 -1
  6. package/ios/BeekonRn.h +5 -1
  7. package/ios/BeekonRn.mm +90 -34
  8. package/ios/BeekonRn.swift +396 -116
  9. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/BeekonKit +0 -0
  10. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/Info.plist +0 -0
  11. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios.abi.json +8636 -0
  12. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  13. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios.swiftinterface +236 -0
  14. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/PrivacyInfo.xcprivacy +1 -1
  15. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/BeekonKit +0 -0
  16. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Info.plist +0 -0
  17. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.abi.json +8636 -0
  18. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  19. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.swiftinterface +236 -0
  20. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.abi.json +8636 -0
  21. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  22. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +236 -0
  23. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/PrivacyInfo.xcprivacy +1 -1
  24. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/_CodeSignature/CodeResources +2 -14
  25. package/lib/module/NativeBeekonRn.js +22 -7
  26. package/lib/module/NativeBeekonRn.js.map +1 -1
  27. package/lib/module/beekon.js +209 -60
  28. package/lib/module/beekon.js.map +1 -1
  29. package/lib/module/index.js +1 -0
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/module/internal/mappers.js +145 -23
  32. package/lib/module/internal/mappers.js.map +1 -1
  33. package/lib/module/types/enums.js +2 -0
  34. package/lib/module/types/{preset.js.map → enums.js.map} +1 -1
  35. package/lib/module/types/error.js +25 -0
  36. package/lib/module/types/error.js.map +1 -0
  37. package/lib/module/types/geofence.js +2 -0
  38. package/lib/module/types/{position.js.map → geofence.js.map} +1 -1
  39. package/lib/module/types/location.js +4 -0
  40. package/lib/module/types/location.js.map +1 -0
  41. package/lib/module/types/sync.js +2 -0
  42. package/lib/module/types/sync.js.map +1 -0
  43. package/lib/typescript/src/NativeBeekonRn.d.ts +113 -35
  44. package/lib/typescript/src/NativeBeekonRn.d.ts.map +1 -1
  45. package/lib/typescript/src/beekon.d.ts +84 -49
  46. package/lib/typescript/src/beekon.d.ts.map +1 -1
  47. package/lib/typescript/src/index.d.ts +7 -4
  48. package/lib/typescript/src/index.d.ts.map +1 -1
  49. package/lib/typescript/src/internal/mappers.d.ts +16 -3
  50. package/lib/typescript/src/internal/mappers.d.ts.map +1 -1
  51. package/lib/typescript/src/types/config.d.ts +53 -31
  52. package/lib/typescript/src/types/config.d.ts.map +1 -1
  53. package/lib/typescript/src/types/enums.d.ts +48 -0
  54. package/lib/typescript/src/types/enums.d.ts.map +1 -0
  55. package/lib/typescript/src/types/error.d.ts +20 -0
  56. package/lib/typescript/src/types/error.d.ts.map +1 -0
  57. package/lib/typescript/src/types/geofence.d.ts +36 -0
  58. package/lib/typescript/src/types/geofence.d.ts.map +1 -0
  59. package/lib/typescript/src/types/location.d.ts +40 -0
  60. package/lib/typescript/src/types/location.d.ts.map +1 -0
  61. package/lib/typescript/src/types/state.d.ts +18 -9
  62. package/lib/typescript/src/types/state.d.ts.map +1 -1
  63. package/lib/typescript/src/types/sync.d.ts +27 -0
  64. package/lib/typescript/src/types/sync.d.ts.map +1 -0
  65. package/package.json +5 -6
  66. package/scripts/fetch-beekonkit.sh +5 -2
  67. package/src/NativeBeekonRn.ts +120 -34
  68. package/src/beekon.ts +235 -63
  69. package/src/index.tsx +23 -4
  70. package/src/internal/mappers.ts +213 -22
  71. package/src/types/config.ts +54 -31
  72. package/src/types/enums.ts +64 -0
  73. package/src/types/error.ts +25 -0
  74. package/src/types/geofence.ts +37 -0
  75. package/src/types/location.ts +45 -0
  76. package/src/types/state.ts +23 -7
  77. package/src/types/sync.ts +23 -0
  78. package/android/src/main/java/com/wayq/beekonrn/BeekonRnModule.kt +0 -233
  79. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeDirectory +0 -0
  80. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeRequirements +0 -0
  81. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeRequirements-1 +0 -0
  82. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeResources +0 -233
  83. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeSignature +0 -0
  84. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/_CodeSignature/CodeResources +0 -113
  85. package/lib/module/types/position.js +0 -2
  86. package/lib/module/types/preset.js +0 -2
  87. package/lib/typescript/src/types/position.d.ts +0 -24
  88. package/lib/typescript/src/types/position.d.ts.map +0 -1
  89. package/lib/typescript/src/types/preset.d.ts +0 -12
  90. package/lib/typescript/src/types/preset.d.ts.map +0 -1
  91. package/src/types/position.ts +0 -23
  92. package/src/types/preset.ts +0 -11
@@ -1,50 +1,241 @@
1
1
  import type { BeekonConfig } from '../types/config';
2
- import type { BeekonState, PauseReason } from '../types/state';
3
- import type { Position } from '../types/position';
4
- import type { WireConfig, WirePosition, WireState } from '../NativeBeekonRn';
2
+ import type {
3
+ AccuracyMode,
4
+ ActivityType,
5
+ LocationQuality,
6
+ LocationTrigger,
7
+ MotionState,
8
+ StationaryMode,
9
+ } from '../types/enums';
10
+ import type {
11
+ BeekonGeofence,
12
+ GeofenceEvent,
13
+ Transition,
14
+ } from '../types/geofence';
15
+ import type { Location } from '../types/location';
16
+ import type { BeekonState, StopReason } from '../types/state';
17
+ import type { SyncFailure, SyncStatus } from '../types/sync';
18
+ import { BeekonError, type BeekonErrorKind } from '../types/error';
19
+ import type {
20
+ WireConfig,
21
+ WireGeofence,
22
+ WireGeofenceEvent,
23
+ WireKeyValue,
24
+ WireLocation,
25
+ WireState,
26
+ WireSyncStatus,
27
+ } from '../NativeBeekonRn';
28
+
29
+ // Config defaults. Kept here (not in the wire layer) so the native modules can
30
+ // treat every wire field as present.
31
+ const DEFAULTS = {
32
+ minTimeBetweenLocationsSeconds: 30,
33
+ minDistanceBetweenLocationsMeters: 100,
34
+ accuracyMode: 'balanced' as AccuracyMode,
35
+ whenStationary: 'pause' as StationaryMode,
36
+ stationaryRadiusMeters: 5,
37
+ detectActivity: false,
38
+ syncIntervalSeconds: 300,
39
+ syncBatchSize: 100,
40
+ };
41
+
42
+ // --- Public → wire ---------------------------------------------------------
43
+
44
+ export function recordToEntries(
45
+ record: Record<string, string> | undefined
46
+ ): WireKeyValue[] {
47
+ if (!record) return [];
48
+ return Object.keys(record).map((key) => ({ key, value: record[key]! }));
49
+ }
5
50
 
6
51
  export function configToWire(config: BeekonConfig): WireConfig {
52
+ const sync = config.sync;
53
+ return {
54
+ minTimeBetweenLocationsSeconds:
55
+ config.minTimeBetweenLocationsSeconds ??
56
+ DEFAULTS.minTimeBetweenLocationsSeconds,
57
+ minDistanceBetweenLocationsMeters:
58
+ config.minDistanceBetweenLocationsMeters ??
59
+ DEFAULTS.minDistanceBetweenLocationsMeters,
60
+ accuracyMode: config.accuracyMode ?? DEFAULTS.accuracyMode,
61
+ whenStationary: config.whenStationary ?? DEFAULTS.whenStationary,
62
+ stationaryRadiusMeters:
63
+ config.stationaryRadiusMeters ?? DEFAULTS.stationaryRadiusMeters,
64
+ detectActivity: config.detectActivity ?? DEFAULTS.detectActivity,
65
+ sync: sync
66
+ ? {
67
+ url: sync.url,
68
+ headers: recordToEntries(sync.headers),
69
+ intervalSeconds: sync.intervalSeconds ?? DEFAULTS.syncIntervalSeconds,
70
+ batchSize: sync.batchSize ?? DEFAULTS.syncBatchSize,
71
+ }
72
+ : undefined,
73
+ notification: config.notification
74
+ ? { title: config.notification.title, text: config.notification.text }
75
+ : undefined,
76
+ };
77
+ }
78
+
79
+ export function geofenceToWire(g: BeekonGeofence): WireGeofence {
7
80
  return {
8
- preset: config.preset ?? 'balanced',
9
- distanceFilterMeters: config.distanceFilterMeters,
10
- intervalMillis: config.intervalMillis,
11
- androidNotification: config.androidNotification,
12
- licenseKey: config.licenseKey,
81
+ id: g.id,
82
+ lat: g.latitude,
83
+ lng: g.longitude,
84
+ radiusMeters: g.radiusMeters,
85
+ notifyOnEntry: g.notifyOnEntry ?? true,
86
+ notifyOnExit: g.notifyOnExit ?? true,
13
87
  };
14
88
  }
15
89
 
16
- export function wireToPosition(w: WirePosition): Position {
90
+ // --- Wire public ---------------------------------------------------------
91
+
92
+ export function wireToLocation(w: WireLocation): Location {
17
93
  return {
18
- lat: w.lat,
19
- lng: w.lng,
94
+ id: w.id,
95
+ latitude: w.lat,
96
+ longitude: w.lng,
97
+ timestamp: new Date(w.timestampMs),
20
98
  accuracy: w.accuracy,
21
99
  speed: w.speed,
22
100
  bearing: w.bearing,
23
101
  altitude: w.altitude,
24
- timestamp: new Date(w.timestampMs),
102
+ quality: oneOf<LocationQuality>(
103
+ w.quality,
104
+ ['ok', 'lowAccuracy', 'implausibleSpeed'],
105
+ 'ok'
106
+ ),
107
+ trigger: oneOf<LocationTrigger>(
108
+ w.trigger,
109
+ ['interval', 'motion', 'checkIn', 'geofence', 'manual'],
110
+ 'interval'
111
+ ),
112
+ motion: oneOf<MotionState>(
113
+ w.motion,
114
+ ['moving', 'stationary', 'unknown'],
115
+ 'unknown'
116
+ ),
117
+ activity:
118
+ w.activity == null
119
+ ? null
120
+ : oneOf<ActivityType>(
121
+ w.activity,
122
+ [
123
+ 'stationary',
124
+ 'walking',
125
+ 'running',
126
+ 'cycling',
127
+ 'automotive',
128
+ 'unknown',
129
+ ],
130
+ 'unknown'
131
+ ),
132
+ isMock: w.isMock,
133
+ };
134
+ }
135
+
136
+ export function wireToGeofence(w: WireGeofence): BeekonGeofence {
137
+ return {
138
+ id: w.id,
139
+ latitude: w.lat,
140
+ longitude: w.lng,
141
+ radiusMeters: w.radiusMeters,
142
+ notifyOnEntry: w.notifyOnEntry,
143
+ notifyOnExit: w.notifyOnExit,
25
144
  };
26
145
  }
27
146
 
28
- function toPauseReason(s: string | undefined): PauseReason {
29
- if (s === 'permissionRevoked' || s === 'locationDisabled') return s;
30
- return 'unknown';
147
+ export function wireToGeofenceEvent(w: WireGeofenceEvent): GeofenceEvent {
148
+ return {
149
+ id: w.id,
150
+ geofenceId: w.geofenceId,
151
+ type: oneOf<Transition>(w.type, ['enter', 'exit'], 'enter'),
152
+ timestamp: new Date(w.timestampMs),
153
+ };
31
154
  }
32
155
 
33
156
  export function wireToState(w: WireState): BeekonState {
34
157
  switch (w.type) {
35
158
  case 'idle':
36
159
  return { kind: 'idle' };
37
- case 'starting':
38
- return { kind: 'starting' };
39
160
  case 'tracking':
40
161
  return { kind: 'tracking' };
41
- case 'paused':
42
- return { kind: 'paused', reason: toPauseReason(w.pauseReason) };
43
162
  case 'stopped':
44
- return { kind: 'stopped' };
163
+ return { kind: 'stopped', reason: toStopReason(w.stopReason) };
164
+ default:
165
+ // Forward-compat: treat unknown as idle rather than throwing.
166
+ return { kind: 'idle' };
167
+ }
168
+ }
169
+
170
+ export function wireToSyncStatus(w: WireSyncStatus): SyncStatus {
171
+ switch (w.type) {
172
+ case 'idle':
173
+ return { kind: 'idle' };
174
+ case 'pending':
175
+ return { kind: 'pending' };
176
+ case 'failed':
177
+ return { kind: 'failed', reason: toSyncFailure(w.failure) };
45
178
  default:
46
- // Defensive fallback. Native should never emit an unknown state, but
47
- // forward-compat: treat as idle rather than throwing.
48
179
  return { kind: 'idle' };
49
180
  }
50
181
  }
182
+
183
+ function toStopReason(s: string | undefined): StopReason {
184
+ return oneOf<StopReason>(
185
+ s,
186
+ [
187
+ 'user',
188
+ 'permissionDenied',
189
+ 'locationServicesDisabled',
190
+ 'locationUnavailable',
191
+ 'system',
192
+ ],
193
+ // The native side always populates the reason for a `stopped` state; an
194
+ // unknown/missing value means the wire contract was violated — fall back to
195
+ // `system` rather than throwing on a subscriber.
196
+ 'system'
197
+ );
198
+ }
199
+
200
+ function toSyncFailure(s: string | undefined): SyncFailure {
201
+ return oneOf<SyncFailure>(s, ['auth', 'rejected'], 'rejected');
202
+ }
203
+
204
+ /** Validate a wire enum string against the known set, with a safe fallback. */
205
+ function oneOf<T extends string>(
206
+ value: string | null | undefined,
207
+ allowed: readonly T[],
208
+ fallback: T
209
+ ): T {
210
+ return (allowed as readonly string[]).includes(value ?? '')
211
+ ? (value as T)
212
+ : fallback;
213
+ }
214
+
215
+ // --- Errors ----------------------------------------------------------------
216
+
217
+ /**
218
+ * Re-throw a native promise rejection as a typed {@link BeekonError}. The native
219
+ * modules encode the kind in the error-code string (`STORAGE_FAILURE`,
220
+ * `INVALID_GEOFENCE`); anything else falls through as the original error.
221
+ */
222
+ export function rethrowAsBeekonError(e: unknown): never {
223
+ const code = (e as { code?: string } | undefined)?.code;
224
+ const message = (e as { message?: string } | undefined)?.message ?? String(e);
225
+ const kind = codeToKind(code);
226
+ if (kind) {
227
+ throw new BeekonError(kind, message);
228
+ }
229
+ throw e;
230
+ }
231
+
232
+ function codeToKind(code: string | undefined): BeekonErrorKind | undefined {
233
+ switch (code) {
234
+ case 'STORAGE_FAILURE':
235
+ return 'storage';
236
+ case 'INVALID_GEOFENCE':
237
+ return 'invalidGeofence';
238
+ default:
239
+ return undefined;
240
+ }
241
+ }
@@ -1,42 +1,65 @@
1
- import type { Preset } from './preset';
1
+ import type { AccuracyMode, StationaryMode } from './enums';
2
2
 
3
3
  /**
4
- * Foreground service notification configrequired when running on Android
5
- * because Android 8+ requires a persistent notification while a foreground
6
- * service is active. Ignored on iOS.
4
+ * Foreground-service notification overrides. **Android-only** the platform
5
+ * requires every location foreground service to show a persistent notification.
6
+ * Both fields are optional; missing values fall back to native defaults.
7
+ * Ignored on iOS.
7
8
  */
8
- export type AndroidNotificationConfig = {
9
- /** NotificationChannel id (Android 8+). */
10
- channelId: string;
11
- /** User-visible channel display name. */
12
- channelName: string;
13
- /** Foreground notification id. Must be > 0. */
14
- notificationId: number;
15
- /** Notification title shown in the status bar. */
16
- title: string;
17
- /** Notification body text. */
18
- text: string;
9
+ export type NotificationConfig = {
10
+ /** Notification title. Defaults to "Tracking location". */
11
+ title?: string;
12
+ /** Notification body text. Defaults to no body. */
13
+ text?: string;
14
+ };
15
+
16
+ /**
17
+ * Server-upload configuration. Presence of {@link BeekonConfig.sync} turns on
18
+ * batched uploads of stored locations and geofence events; omitting it keeps
19
+ * tracking local-only.
20
+ */
21
+ export type SyncConfig = {
22
+ /** Ingest endpoint — an `http` or `https` URL. */
23
+ url: string;
24
+ /** Extra HTTP headers sent with every upload (e.g. `Authorization`). */
25
+ headers?: Record<string, string>;
19
26
  /**
20
- * Drawable resource name for the notification icon (e.g. `ic_notification`).
21
- * Resolved at runtime via `Resources.getIdentifier()` against the host app's
22
- * `res/drawable*` folders. Pass the resource name without extension or
23
- * `R.drawable.` prefix.
27
+ * Target seconds between uploads. The SDK enforces a 60s floor; background
28
+ * uploads may be delayed to the OS scheduler floor (~15 min). Default: `300`.
24
29
  */
25
- smallIconResName: string;
30
+ intervalSeconds?: number;
31
+ /** Maximum locations per upload. Clamped to `[1, 1000]`. Default: `100`. */
32
+ batchSize?: number;
26
33
  };
27
34
 
35
+ /**
36
+ * Tracking configuration. Every field is optional — `Beekon.start()` falls back
37
+ * to the previously persisted config, or to the documented defaults below if
38
+ * never configured.
39
+ *
40
+ * The two gate knobs (`minTimeBetweenLocationsSeconds`,
41
+ * `minDistanceBetweenLocationsMeters`) admit a fix only when **both** are
42
+ * satisfied; pass `0` to disable a gate.
43
+ */
28
44
  export type BeekonConfig = {
29
- /** Sampling preset. Default: `'balanced'`. */
30
- preset?: Preset;
31
- /** Override the preset's distance gate (meters). */
32
- distanceFilterMeters?: number;
33
- /** Override the preset's interval (milliseconds). */
34
- intervalMillis?: number;
45
+ /** Minimum seconds between admitted fixes (10s floor). Default: `30`. */
46
+ minTimeBetweenLocationsSeconds?: number;
47
+ /** Minimum metres between admitted fixes. `0` disables it. Default: `100`. */
48
+ minDistanceBetweenLocationsMeters?: number;
49
+ /** Accuracy / battery preset. Default: `'balanced'`. */
50
+ accuracyMode?: AccuracyMode;
51
+ /** Behaviour while stationary. Default: `'pause'`. */
52
+ whenStationary?: StationaryMode;
53
+ /** Stationary exit-geofence radius, clamped to `[5, 1000]`. Default: `5`. */
54
+ stationaryRadiusMeters?: number;
35
55
  /**
36
- * Required when running on Android. Ignored on iOS. The plugin throws
37
- * `NOT_CONFIGURED` if missing on Android.
56
+ * Detect physical activity (walking, driving, …). Requires the
57
+ * `ACTIVITY_RECOGNITION` permission on Android and the `NSMotionUsageDescription`
58
+ * Info.plist key on iOS. Default: `false`.
38
59
  */
39
- androidNotification?: AndroidNotificationConfig;
40
- /** Optional license key. Reserved for future use. */
41
- licenseKey?: string;
60
+ detectActivity?: boolean;
61
+ /** Server-upload configuration. Omit to keep tracking local-only. */
62
+ sync?: SyncConfig;
63
+ /** Android-only notification overrides. Ignored on iOS. */
64
+ notification?: NotificationConfig;
42
65
  };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Value enums shared across the public API, expressed as string-literal unions
3
+ * (idiomatic TS). Each mirrors the like-named enum on both native SDKs by value;
4
+ * the wire layer carries them as plain strings and the mappers translate.
5
+ */
6
+
7
+ /**
8
+ * Accuracy / battery-life preset for the location provider.
9
+ *
10
+ * - `'high'` — highest precision, highest battery cost (GPS-grade).
11
+ * - `'balanced'` — city-block precision, balanced battery (the default).
12
+ * - `'low'` — coarse, lowest battery.
13
+ */
14
+ export type AccuracyMode = 'high' | 'balanced' | 'low';
15
+
16
+ /**
17
+ * Behaviour while the device is stationary.
18
+ *
19
+ * - `'keepTracking'` — GPS stays on.
20
+ * - `'pause'` — GPS off while stationary, silent resume on movement (default).
21
+ * - `'pauseWithCheckIns'` — GPS off, but a location is recorded roughly every
22
+ * 15 minutes.
23
+ */
24
+ export type StationaryMode = 'keepTracking' | 'pause' | 'pauseWithCheckIns';
25
+
26
+ /**
27
+ * Why a {@link Location} was admitted and persisted.
28
+ *
29
+ * - `'interval'` — a scheduled fix that passed the time/distance gate.
30
+ * - `'motion'` — the device started or stopped moving.
31
+ * - `'checkIn'` — a periodic check-in while stationary.
32
+ * - `'geofence'` — a geofence crossing.
33
+ * - `'manual'` — an explicit request.
34
+ */
35
+ export type LocationTrigger =
36
+ | 'interval'
37
+ | 'motion'
38
+ | 'checkIn'
39
+ | 'geofence'
40
+ | 'manual';
41
+
42
+ /**
43
+ * The gate's quality verdict for a {@link Location}.
44
+ *
45
+ * - `'ok'` — passed the accuracy and speed checks.
46
+ * - `'lowAccuracy'` — worse than the usable accuracy threshold.
47
+ * - `'implausibleSpeed'` — an implausible jump from the previous fix.
48
+ */
49
+ export type LocationQuality = 'ok' | 'lowAccuracy' | 'implausibleSpeed';
50
+
51
+ /** Device motion when a {@link Location} was captured. */
52
+ export type MotionState = 'moving' | 'stationary' | 'unknown';
53
+
54
+ /**
55
+ * Detected physical activity. Only populated when
56
+ * {@link BeekonConfig.detectActivity} is enabled; otherwise `null`.
57
+ */
58
+ export type ActivityType =
59
+ | 'stationary'
60
+ | 'walking'
61
+ | 'running'
62
+ | 'cycling'
63
+ | 'automotive'
64
+ | 'unknown';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Error kinds thrown across the bridge. These are the **only** errors Beekon
3
+ * throws — permission / location-services / lifecycle problems never throw; they
4
+ * surface on the `onState` stream as `stopped(reason)` instead.
5
+ *
6
+ * - `'storage'` — a local-store (SQLite) read/write failed. Thrown by
7
+ * `getLocations()`, `deleteLocations()`, and `pendingUploadCount()`.
8
+ * - `'invalidGeofence'` — a geofence passed to `addGeofences()` failed
9
+ * validation (empty/oversized id, or non-positive radius).
10
+ */
11
+ export type BeekonErrorKind = 'storage' | 'invalidGeofence';
12
+
13
+ /**
14
+ * Typed error surfaced from the bridge. The native module rejects promises with
15
+ * the kind encoded as the error code; the facade re-wraps into this.
16
+ */
17
+ export class BeekonError extends Error {
18
+ public readonly kind: BeekonErrorKind;
19
+
20
+ constructor(kind: BeekonErrorKind, message: string) {
21
+ super(message);
22
+ this.name = 'BeekonError';
23
+ this.kind = kind;
24
+ }
25
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A circular geofence registered via `Beekon.addGeofences()`. Mirrors
3
+ * `BeekonGeofence` on both native SDKs. The SDK pages registrations
4
+ * automatically, so you may register more than the OS geofence limit.
5
+ */
6
+ export type BeekonGeofence = {
7
+ /** Unique id, 1–100 characters. Re-adding an existing id replaces it. */
8
+ id: string;
9
+ /** Center latitude in degrees, WGS-84. */
10
+ latitude: number;
11
+ /** Center longitude in degrees, WGS-84. */
12
+ longitude: number;
13
+ /** Radius in metres. Must be `> 0`; `>= 100` is recommended for reliability. */
14
+ radiusMeters: number;
15
+ /** Emit an event on entry. Default: `true`. */
16
+ notifyOnEntry?: boolean;
17
+ /** Emit an event on exit. Default: `true`. */
18
+ notifyOnExit?: boolean;
19
+ };
20
+
21
+ /** Whether a {@link GeofenceEvent} marks entering or exiting a geofence. */
22
+ export type Transition = 'enter' | 'exit';
23
+
24
+ /**
25
+ * A geofence entry/exit crossing, delivered via `Beekon.onGeofenceEvent()`.
26
+ * Mirrors `GeofenceEvent` on both native SDKs.
27
+ */
28
+ export type GeofenceEvent = {
29
+ /** Unique event id. Used as the dedup key on upload. */
30
+ id: string;
31
+ /** The {@link BeekonGeofence.id} that was crossed. */
32
+ geofenceId: string;
33
+ /** Whether the device entered or exited. */
34
+ type: Transition;
35
+ /** When the crossing happened. */
36
+ timestamp: Date;
37
+ };
@@ -0,0 +1,45 @@
1
+ import type {
2
+ ActivityType,
3
+ LocationQuality,
4
+ LocationTrigger,
5
+ MotionState,
6
+ } from './enums';
7
+
8
+ /**
9
+ * A single location fix as emitted by the native SDK after gating. Fields map
10
+ * 1:1 to `in.wayq.beekon.Location` on Android and `BeekonKit.Location` on iOS.
11
+ *
12
+ * `id`, `latitude`, `longitude`, and `timestamp` are always present. The four
13
+ * optional numeric fields are `null` when the OS did not report a value — the
14
+ * SDK never invents a value to mask absence (e.g. a stationary device returns
15
+ * `bearing === null`, not `0`). `activity` is `null` unless
16
+ * {@link BeekonConfig.detectActivity} is enabled.
17
+ */
18
+ export type Location = {
19
+ /** Stable, unique storage id. Used as the dedup key on upload. */
20
+ id: string;
21
+ /** Latitude in degrees, WGS-84. */
22
+ latitude: number;
23
+ /** Longitude in degrees, WGS-84. */
24
+ longitude: number;
25
+ /** Time the OS provider reported this fix (not when JS received it). */
26
+ timestamp: Date;
27
+ /** Horizontal accuracy in meters (1-sigma); `null` if unreported. */
28
+ accuracy: number | null;
29
+ /** Speed in m/s; `null` if unreported. */
30
+ speed: number | null;
31
+ /** Bearing in degrees `[0, 360)` clockwise from true north; `null` if unreported. */
32
+ bearing: number | null;
33
+ /** Altitude in meters above the WGS-84 ellipsoid; `null` if unreported. */
34
+ altitude: number | null;
35
+ /** The gate's quality verdict for this fix. */
36
+ quality: LocationQuality;
37
+ /** Why this fix was captured. */
38
+ trigger: LocationTrigger;
39
+ /** Device motion when this fix was captured. */
40
+ motion: MotionState;
41
+ /** Detected activity, or `null` unless activity detection is enabled. */
42
+ activity: ActivityType | null;
43
+ /** `true` if the OS flagged this fix as mock/simulated. */
44
+ isMock: boolean;
45
+ };
@@ -1,16 +1,32 @@
1
1
  /**
2
- * Why tracking is paused. Names match the native `PauseReason` enum on both
3
- * platforms byte-for-byte.
2
+ * Reason a tracking session ended. Mirrors `StopReason` on both platforms.
3
+ *
4
+ * - `'user'` — `Beekon.stop()` was called.
5
+ * - `'permissionDenied'` — location permission is missing or was revoked
6
+ * (user-fixable in Settings).
7
+ * - `'locationServicesDisabled'` — system-wide location services are off
8
+ * (user-fixable in Settings).
9
+ * - `'locationUnavailable'` — no usable location backend on this device (e.g.
10
+ * Google Play Services absent/outdated on Android). Not user-fixable.
11
+ * - `'system'` — the OS terminated tracking (e.g. foreground-service kill,
12
+ * or an unrecoverable internal error).
4
13
  */
5
- export type PauseReason = 'permissionRevoked' | 'locationDisabled' | 'unknown';
14
+ export type StopReason =
15
+ | 'user'
16
+ | 'permissionDenied'
17
+ | 'locationServicesDisabled'
18
+ | 'locationUnavailable'
19
+ | 'system';
6
20
 
7
21
  /**
8
- * Tracking state. Mirrors the native `BeekonState` sealed hierarchy on both
22
+ * Tracking state. Mirrors the native `BeekonState` sealed type on both
9
23
  * platforms. Use the `kind` field as a discriminator.
24
+ *
25
+ * Lifecycle: `idle → tracking → stopped(reason)`. `start()` / `stop()` never
26
+ * throw — this stream is the single source of truth for whether tracking is
27
+ * active and why it stopped.
10
28
  */
11
29
  export type BeekonState =
12
30
  | { kind: 'idle' }
13
- | { kind: 'starting' }
14
31
  | { kind: 'tracking' }
15
- | { kind: 'paused'; reason: PauseReason }
16
- | { kind: 'stopped' };
32
+ | { kind: 'stopped'; reason: StopReason };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Why a server upload failed terminally. Mirrors `SyncFailure` on both
3
+ * platforms.
4
+ *
5
+ * - `'auth'` — `401`/`403`; credentials were rejected. Refresh them (via
6
+ * `Beekon.configure()` with new `sync.headers`) and sync resumes.
7
+ * - `'rejected'` — `400`/`422`; the server rejected the payload. A payload bug;
8
+ * it won't self-resolve.
9
+ */
10
+ export type SyncFailure = 'auth' | 'rejected';
11
+
12
+ /**
13
+ * Upload health, delivered via `Beekon.onSyncStatus()`. Mirrors the native
14
+ * `SyncStatus` sealed type. Use the `kind` field as a discriminator.
15
+ *
16
+ * - `'idle'` — caught up, or sync is not configured.
17
+ * - `'pending'` — uploading or retrying (healthy).
18
+ * - `'failed'` — a terminal failure the app must act on.
19
+ */
20
+ export type SyncStatus =
21
+ | { kind: 'idle' }
22
+ | { kind: 'pending' }
23
+ | { kind: 'failed'; reason: SyncFailure };