@wayq/beekon-rn 0.0.3 → 0.0.6

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 (84) hide show
  1. package/BeekonRn.podspec +5 -3
  2. package/CHANGELOG.md +103 -0
  3. package/README.md +326 -52
  4. package/android/build.gradle +9 -4
  5. package/android/src/main/java/in/wayq/beekonrn/BeekonRnModule.kt +411 -59
  6. package/ios/BeekonRn.mm +103 -24
  7. package/ios/BeekonRn.swift +465 -61
  8. package/ios/Frameworks/BeekonKit.xcframework/Info.plist +5 -5
  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 +11424 -1279
  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 +262 -36
  14. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/BeekonKit +0 -0
  15. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Info.plist +0 -0
  16. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.abi.json +11424 -1279
  17. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  18. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/arm64-apple-ios-simulator.swiftinterface +262 -36
  19. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.abi.json +11424 -1279
  20. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  21. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/Modules/BeekonKit.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +262 -36
  22. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64_x86_64-simulator/BeekonKit.framework/_CodeSignature/CodeResources +2 -80
  23. package/lib/module/NativeBeekonRn.js +35 -7
  24. package/lib/module/NativeBeekonRn.js.map +1 -1
  25. package/lib/module/beekon.js +246 -45
  26. package/lib/module/beekon.js.map +1 -1
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/internal/mappers.js +166 -25
  29. package/lib/module/internal/mappers.js.map +1 -1
  30. package/lib/module/types/auth.js +4 -0
  31. package/lib/module/types/auth.js.map +1 -0
  32. package/lib/module/types/config.js +2 -0
  33. package/lib/module/types/enums.js +2 -0
  34. package/lib/module/types/enums.js.map +1 -0
  35. package/lib/module/types/error.js +20 -4
  36. package/lib/module/types/error.js.map +1 -1
  37. package/lib/module/types/geofence.js +2 -0
  38. package/lib/module/types/geofence.js.map +1 -0
  39. package/lib/module/types/location.js +2 -0
  40. package/lib/module/types/sync.js +2 -0
  41. package/lib/module/types/sync.js.map +1 -0
  42. package/lib/typescript/src/NativeBeekonRn.d.ts +150 -20
  43. package/lib/typescript/src/NativeBeekonRn.d.ts.map +1 -1
  44. package/lib/typescript/src/beekon.d.ts +110 -33
  45. package/lib/typescript/src/beekon.d.ts.map +1 -1
  46. package/lib/typescript/src/index.d.ts +6 -2
  47. package/lib/typescript/src/index.d.ts.map +1 -1
  48. package/lib/typescript/src/internal/mappers.d.ts +16 -6
  49. package/lib/typescript/src/internal/mappers.d.ts.map +1 -1
  50. package/lib/typescript/src/types/auth.d.ts +99 -0
  51. package/lib/typescript/src/types/auth.d.ts.map +1 -0
  52. package/lib/typescript/src/types/config.d.ts +66 -20
  53. package/lib/typescript/src/types/config.d.ts.map +1 -1
  54. package/lib/typescript/src/types/enums.d.ts +62 -0
  55. package/lib/typescript/src/types/enums.d.ts.map +1 -0
  56. package/lib/typescript/src/types/error.d.ts +21 -5
  57. package/lib/typescript/src/types/error.d.ts.map +1 -1
  58. package/lib/typescript/src/types/geofence.d.ts +36 -0
  59. package/lib/typescript/src/types/geofence.d.ts.map +1 -0
  60. package/lib/typescript/src/types/location.d.ts +22 -8
  61. package/lib/typescript/src/types/location.d.ts.map +1 -1
  62. package/lib/typescript/src/types/state.d.ts +13 -4
  63. package/lib/typescript/src/types/state.d.ts.map +1 -1
  64. package/lib/typescript/src/types/sync.d.ts +27 -0
  65. package/lib/typescript/src/types/sync.d.ts.map +1 -0
  66. package/package.json +8 -5
  67. package/scripts/fetch-beekonkit.sh +5 -5
  68. package/src/NativeBeekonRn.ts +165 -20
  69. package/src/beekon.ts +278 -48
  70. package/src/index.tsx +24 -2
  71. package/src/internal/mappers.ts +242 -27
  72. package/src/types/auth.ts +101 -0
  73. package/src/types/config.ts +68 -20
  74. package/src/types/enums.ts +80 -0
  75. package/src/types/error.ts +23 -5
  76. package/src/types/geofence.ts +37 -0
  77. package/src/types/location.ts +28 -8
  78. package/src/types/state.ts +13 -3
  79. package/src/types/sync.ts +23 -0
  80. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeDirectory +0 -0
  81. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeRequirements +0 -0
  82. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeResources +0 -296
  83. package/ios/Frameworks/BeekonKit.xcframework/_CodeSignature/CodeSignature +0 -0
  84. package/ios/Frameworks/BeekonKit.xcframework/ios-arm64/BeekonKit.framework/_CodeSignature/CodeResources +0 -146
@@ -1,103 +1,304 @@
1
1
  "use strict";
2
2
 
3
3
  import NativeBeekon from "./NativeBeekonRn.js";
4
- import { configToWire, wireToLocation, wireToState, rethrowAsBeekonError } from "./internal/mappers.js";
4
+ import { configToWire, geofenceToWire, recordToEntries, rethrowAsBeekonError, wireToAuthTokens, wireToGeofence, wireToGeofenceEvent, wireToLocation, wireToState, wireToSyncStatus } from "./internal/mappers.js";
5
+ /**
6
+ * Fans the five native EventEmitters out to multiple JS subscribers and adds
7
+ * replay-1 semantics for `state` / `syncStatus` / `authTokens` (RN EventEmitters
8
+ * don't replay, so we cache the latest value and hand it to new subscribers
9
+ * immediately — matching the native StateFlow / AsyncStream contract).
10
+ * `location` / `geofenceEvent` are plain fan-out with no replay.
11
+ *
12
+ * Native subscriptions are opened once, on first use, and kept for the app
13
+ * lifetime — the native module collects its flows continuously regardless, so
14
+ * this only keeps the JS cache warm.
15
+ */
16
+ class EventHub {
17
+ subscribed = false;
18
+ stateListeners = new Set();
19
+ locationListeners = new Set();
20
+ geofenceListeners = new Set();
21
+ syncListeners = new Set();
22
+ authTokenListeners = new Set();
23
+ /** Idempotent: opens the native subscriptions the first time it is called. */
24
+ ensureSubscribed() {
25
+ if (this.subscribed) return;
26
+ this.subscribed = true;
27
+ NativeBeekon.onState(w => {
28
+ const s = wireToState(w);
29
+ this.lastState = s;
30
+ this.stateListeners.forEach(cb => cb(s));
31
+ });
32
+ NativeBeekon.onLocation(w => {
33
+ const l = wireToLocation(w);
34
+ this.locationListeners.forEach(cb => cb(l));
35
+ });
36
+ NativeBeekon.onGeofenceEvent(w => {
37
+ const g = wireToGeofenceEvent(w);
38
+ this.geofenceListeners.forEach(cb => cb(g));
39
+ });
40
+ NativeBeekon.onSyncStatus(w => {
41
+ const s = wireToSyncStatus(w);
42
+ this.lastSyncStatus = s;
43
+ this.syncListeners.forEach(cb => cb(s));
44
+ });
45
+ NativeBeekon.onAuthTokens(w => {
46
+ const t = wireToAuthTokens(w);
47
+ this.lastAuthTokens = t;
48
+ this.authTokenListeners.forEach(cb => cb(t));
49
+ });
50
+ }
51
+ onState(cb) {
52
+ this.ensureSubscribed();
53
+ this.stateListeners.add(cb);
54
+ if (this.lastState !== undefined) cb(this.lastState);
55
+ return () => {
56
+ this.stateListeners.delete(cb);
57
+ };
58
+ }
59
+ onLocation(cb) {
60
+ this.ensureSubscribed();
61
+ this.locationListeners.add(cb);
62
+ return () => {
63
+ this.locationListeners.delete(cb);
64
+ };
65
+ }
66
+ onGeofenceEvent(cb) {
67
+ this.ensureSubscribed();
68
+ this.geofenceListeners.add(cb);
69
+ return () => {
70
+ this.geofenceListeners.delete(cb);
71
+ };
72
+ }
73
+ onSyncStatus(cb) {
74
+ this.ensureSubscribed();
75
+ this.syncListeners.add(cb);
76
+ if (this.lastSyncStatus !== undefined) cb(this.lastSyncStatus);
77
+ return () => {
78
+ this.syncListeners.delete(cb);
79
+ };
80
+ }
81
+ onAuthTokens(cb) {
82
+ this.ensureSubscribed();
83
+ this.authTokenListeners.add(cb);
84
+ if (this.lastAuthTokens !== undefined) cb(this.lastAuthTokens);
85
+ return () => {
86
+ this.authTokenListeners.delete(cb);
87
+ };
88
+ }
89
+ }
5
90
 
6
91
  /**
7
- * Public facade for the Beekon SDK. Mirrors the native APIs:
92
+ * Public facade for the Beekon SDK a 1:1 mirror of the native APIs:
8
93
  *
9
94
  * - Android: `in.wayq.beekon.Beekon` (object)
10
95
  * - iOS: `BeekonKit.Beekon.shared` (actor)
11
96
  *
12
- * Lifecycle: `configure(config)` `start()` ... `stop()` (idempotent).
13
- * Subscribe to `onState` / `onLocation` for live updates; query
14
- * `history(from, to)` for persisted fixes.
97
+ * There is **no `initialize()`** the native SDKs auto-initialize. Lifecycle:
98
+ * `configure(config)` (optional; defaults 30s / 100m) → `start()`
99
+ * `stop()`. `start()` / `stop()` **never throw** — `onState` is the single
100
+ * source of truth for whether tracking is active and why it stopped.
15
101
  *
16
- * **Threading:** Methods are safe to call from any JS context. Subscribers'
102
+ * **Threading:** methods are safe to call from any JS context; subscriber
17
103
  * callbacks fire on the JS thread.
18
104
  *
19
- * **Persistence invariant:** the SDK persists every gated fix natively; JS is
20
- * a passive observer. In background, the JS engine is not guaranteed to be
21
- * alive — for past fixes, use `history()`.
105
+ * **Persistence invariant:** the SDK persists every gated fix natively; JS is a
106
+ * passive observer that is not guaranteed to be alive in the background. For
107
+ * past fixes use `getLocations()`.
22
108
  */
23
109
  class BeekonImpl {
110
+ hub = new EventHub();
111
+
24
112
  /**
25
113
  * Set tracking parameters. Optional — `start()` falls back to the previously
26
- * persisted config or the SDK default (30s / 100m) if never configured.
27
- *
28
- * While tracking, the new gate values take effect on the next admitted fix
29
- * without restarting the underlying location subscription.
114
+ * persisted config, or the SDK defaults if never configured. While tracking,
115
+ * gate thresholds take effect on the next admitted fix without restarting the
116
+ * location subscription; `accuracyMode` applies on the next `start()`.
30
117
  */
31
118
  async configure(config) {
119
+ this.hub.ensureSubscribed();
120
+ await NativeBeekon.configure(configToWire(config));
121
+ }
122
+
123
+ /**
124
+ * Begin tracking. Never throws — observe `onState` for the outcome
125
+ * (`stopped(reason)` on a permission / services / system problem). Beekon
126
+ * ships no permission API: request permissions in the host app, then observe
127
+ * `onState`.
128
+ */
129
+ async start() {
130
+ this.hub.ensureSubscribed();
131
+ await NativeBeekon.start();
132
+ }
133
+
134
+ /** Stop tracking. Idempotent. Registered geofences keep firing. */
135
+ async stop() {
136
+ this.hub.ensureSubscribed();
137
+ await NativeBeekon.stop();
138
+ }
139
+
140
+ /**
141
+ * Resume tracking if a session was active before the app was terminated. A
142
+ * no-op if the user explicitly stopped. Call early in app startup.
143
+ *
144
+ * Note: on a background relaunch the JS engine may not be running, so true
145
+ * cold-launch resume also requires native host wiring (Android: call
146
+ * `Beekon.start()` from `Application.onCreate`; iOS: `registerBackgroundTasks`
147
+ * in the AppDelegate). See the README.
148
+ */
149
+ async resumeIfNeeded() {
150
+ this.hub.ensureSubscribed();
151
+ await NativeBeekon.resumeIfNeeded();
152
+ }
153
+
154
+ /**
155
+ * Return a single fresh fix on demand — for the moment a host needs an
156
+ * immediate position (e.g. the instant a trip starts).
157
+ *
158
+ * Independent of tracking: works whether or not a session is running and never
159
+ * starts, stops, or disturbs one. The fix is not persisted and does not appear
160
+ * on `onLocation` — it is returned here only, tagged `'manual'`.
161
+ *
162
+ * Resolves `null` if no usable fix arrives within `timeoutMs` (default
163
+ * 15000). `accuracy` overrides the configured mode for this call only;
164
+ * omitted uses the configured mode.
165
+ *
166
+ * Throws `BeekonError` with kind `'permissionDenied'`,
167
+ * `'locationServicesDisabled'`, or `'locationUnavailable'` on a precondition
168
+ * failure.
169
+ */
170
+ async getCurrentLocation(options) {
32
171
  try {
33
- await NativeBeekon.configure(configToWire(config));
172
+ const wires = await NativeBeekon.getCurrentLocation(options?.timeoutMs ?? 15000, options?.accuracy ?? '');
173
+ return wires.length === 0 ? null : wireToLocation(wires[0]);
34
174
  } catch (e) {
35
175
  rethrowAsBeekonError(e);
36
176
  }
37
177
  }
38
178
 
39
179
  /**
40
- * Begin tracking. State transitions to `tracking`.
180
+ * Read persisted fixes in the inclusive range `[from, to]`, oldest first.
181
+ * Reads come from the SDK's local storage (Room on Android, GRDB on iOS) — the
182
+ * source of truth even when JS was asleep. With sync enabled, rows are deleted
183
+ * locally once the server accepts them, so this returns only un-uploaded fixes.
41
184
  *
42
- * Throws a `BeekonError` with kind:
43
- * - `'permissionDenied'` — location permission not granted.
44
- * - `'locationServicesDisabled'` — system location services off (or GMS
45
- * unavailable on Android).
185
+ * Throws `BeekonError` with kind `'storage'` on a database read failure.
46
186
  */
47
- async start() {
187
+ async getLocations(from, to) {
188
+ try {
189
+ const wires = await NativeBeekon.getLocations(from.getTime(), to.getTime());
190
+ return wires.map(wireToLocation);
191
+ } catch (e) {
192
+ rethrowAsBeekonError(e);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Delete stored locations captured before `before` (all of them when
198
+ * `before` is omitted). Returns the number of rows removed. Throws
199
+ * `BeekonError` with kind `'storage'` on a failure.
200
+ */
201
+ async deleteLocations(before) {
48
202
  try {
49
- await NativeBeekon.start();
203
+ // Negative is the wire sentinel for "delete all" (see NativeBeekonRn.ts).
204
+ return await NativeBeekon.deleteLocations(before ? before.getTime() : -1);
50
205
  } catch (e) {
51
206
  rethrowAsBeekonError(e);
52
207
  }
53
208
  }
54
209
 
55
- /** Stop tracking. Idempotent. State transitions to `stopped(user)`. */
56
- async stop() {
210
+ /**
211
+ * The number of stored locations not yet uploaded. Throws `BeekonError` with
212
+ * kind `'storage'` on a failure.
213
+ */
214
+ async pendingUploadCount() {
57
215
  try {
58
- await NativeBeekon.stop();
216
+ return await NativeBeekon.pendingUploadCount();
59
217
  } catch (e) {
60
218
  rethrowAsBeekonError(e);
61
219
  }
62
220
  }
63
221
 
64
222
  /**
65
- * Read persisted fixes in the time range [from, to]. Returns fixes in
66
- * chronological order. Reads come from the SDK's local storage (Room on
67
- * Android, GRDB on iOS) — the source of truth even when JS was asleep.
68
- *
69
- * Retention: fixes older than 7 days OR beyond the most recent 100K are
70
- * pruned automatically.
71
- *
72
- * Throws `BeekonError` with kind `'storageFailure'` on database read failure.
223
+ * Request an immediate upload. Best-effort and self-retrying; a no-op when
224
+ * sync is not configured.
225
+ */
226
+ async sync() {
227
+ await NativeBeekon.sync();
228
+ }
229
+
230
+ /** Set custom key/value fields (e.g. `user_id`) included with every upload. */
231
+ async setExtras(extras) {
232
+ await NativeBeekon.setExtras(recordToEntries(extras));
233
+ }
234
+
235
+ /**
236
+ * Register geofences. Re-adding an `id` replaces the existing one. Throws
237
+ * `BeekonError` with kind `'invalidGeofence'` if any entry fails validation —
238
+ * none are added when one is invalid.
73
239
  */
74
- async history(from, to) {
240
+ async addGeofences(geofences) {
75
241
  try {
76
- const wires = await NativeBeekon.history(from.getTime(), to.getTime());
77
- return wires.map(wireToLocation);
242
+ await NativeBeekon.addGeofences(geofences.map(geofenceToWire));
78
243
  } catch (e) {
79
244
  rethrowAsBeekonError(e);
80
245
  }
81
246
  }
82
247
 
248
+ /** Unregister geofences by id. Unknown ids are ignored. */
249
+ async removeGeofences(ids) {
250
+ await NativeBeekon.removeGeofences(ids);
251
+ }
252
+
253
+ /** The currently registered geofences. */
254
+ async listGeofences() {
255
+ const wires = await NativeBeekon.listGeofences();
256
+ return wires.map(wireToGeofence);
257
+ }
258
+
83
259
  /**
84
- * Subscribe to state transitions. Returns an unsubscribe function. The
85
- * current state is delivered to new subscribers immediately (replay-1
86
- * semantics, matching the native `state` flow / AsyncStream).
260
+ * Subscribe to tracking-state transitions (`idle` / `tracking` /
261
+ * `stopped(reason)`). The current state is delivered to new subscribers
262
+ * immediately (replay-1). Returns an unsubscribe function.
87
263
  */
88
264
  onState(cb) {
89
- const subscription = NativeBeekon.onState(wire => cb(wireToState(wire)));
90
- return () => subscription.remove();
265
+ return this.hub.onState(cb);
91
266
  }
92
267
 
93
268
  /**
94
- * Subscribe to gated locations as they arrive. Returns an unsubscribe
95
- * function. Broadcast (no replay) only delivers while the JS engine is
96
- * alive. For fixes emitted while JS was asleep, use `history()`.
269
+ * Subscribe to gated locations as they arrive. Broadcast (no replay) — only
270
+ * delivers while the JS engine is alive. For fixes emitted while JS was
271
+ * asleep, use `getLocations()`. Returns an unsubscribe function.
97
272
  */
98
273
  onLocation(cb) {
99
- const subscription = NativeBeekon.onLocation(wire => cb(wireToLocation(wire)));
100
- return () => subscription.remove();
274
+ return this.hub.onLocation(cb);
275
+ }
276
+
277
+ /**
278
+ * Subscribe to geofence enter / exit crossings. Broadcast (no replay).
279
+ * Returns an unsubscribe function.
280
+ */
281
+ onGeofenceEvent(cb) {
282
+ return this.hub.onGeofenceEvent(cb);
283
+ }
284
+
285
+ /**
286
+ * Subscribe to upload health (`idle` / `pending` / `failed(reason)`). The
287
+ * current status is delivered to new subscribers immediately (replay-1).
288
+ * Returns an unsubscribe function.
289
+ */
290
+ onSyncStatus(cb) {
291
+ return this.hub.onSyncStatus(cb);
292
+ }
293
+
294
+ /**
295
+ * Subscribe to token rotations the SDK performed during a native refresh (see
296
+ * `SyncConfig.auth`). Mirror them into your own session store. The latest
297
+ * rotation is delivered to new subscribers immediately (replay-1). Sensitive —
298
+ * delivered in-process only, never logged. Returns an unsubscribe function.
299
+ */
300
+ onAuthTokens(cb) {
301
+ return this.hub.onAuthTokens(cb);
101
302
  }
102
303
  }
103
304
  export const Beekon = new BeekonImpl();
@@ -1 +1 @@
1
- {"version":3,"names":["NativeBeekon","configToWire","wireToLocation","wireToState","rethrowAsBeekonError","BeekonImpl","configure","config","e","start","stop","history","from","to","wires","getTime","map","onState","cb","subscription","wire","remove","onLocation","Beekon"],"sourceRoot":"../../src","sources":["beekon.ts"],"mappings":";;AAAA,OAAOA,YAAY,MAAM,qBAAkB;AAI3C,SACEC,YAAY,EACZC,cAAc,EACdC,WAAW,EACXC,oBAAoB,QACf,uBAAoB;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,CAAC;EACf;AACF;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,SAASA,CAACC,MAAoB,EAAiB;IACnD,IAAI;MACF,MAAMP,YAAY,CAACM,SAAS,CAACL,YAAY,CAACM,MAAM,CAAC,CAAC;IACpD,CAAC,CAAC,OAAOC,CAAC,EAAE;MACVJ,oBAAoB,CAACI,CAAC,CAAC;IACzB;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,KAAKA,CAAA,EAAkB;IAC3B,IAAI;MACF,MAAMT,YAAY,CAACS,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAC,OAAOD,CAAC,EAAE;MACVJ,oBAAoB,CAACI,CAAC,CAAC;IACzB;EACF;;EAEA;EACA,MAAME,IAAIA,CAAA,EAAkB;IAC1B,IAAI;MACF,MAAMV,YAAY,CAACU,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,OAAOF,CAAC,EAAE;MACVJ,oBAAoB,CAACI,CAAC,CAAC;IACzB;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMG,OAAOA,CAACC,IAAU,EAAEC,EAAQ,EAAuB;IACvD,IAAI;MACF,MAAMC,KAAK,GAAG,MAAMd,YAAY,CAACW,OAAO,CAACC,IAAI,CAACG,OAAO,CAAC,CAAC,EAAEF,EAAE,CAACE,OAAO,CAAC,CAAC,CAAC;MACtE,OAAOD,KAAK,CAACE,GAAG,CAACd,cAAc,CAAC;IAClC,CAAC,CAAC,OAAOM,CAAC,EAAE;MACVJ,oBAAoB,CAACI,CAAC,CAAC;IACzB;EACF;;EAEA;AACF;AACA;AACA;AACA;EACES,OAAOA,CAACC,EAA4B,EAAc;IAChD,MAAMC,YAAY,GAAGnB,YAAY,CAACiB,OAAO,CAAEG,IAAI,IAAKF,EAAE,CAACf,WAAW,CAACiB,IAAI,CAAC,CAAC,CAAC;IAC1E,OAAO,MAAMD,YAAY,CAACE,MAAM,CAAC,CAAC;EACpC;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACJ,EAAyB,EAAc;IAChD,MAAMC,YAAY,GAAGnB,YAAY,CAACsB,UAAU,CAAEF,IAAI,IAChDF,EAAE,CAAChB,cAAc,CAACkB,IAAI,CAAC,CACzB,CAAC;IACD,OAAO,MAAMD,YAAY,CAACE,MAAM,CAAC,CAAC;EACpC;AACF;AAEA,OAAO,MAAME,MAAM,GAAG,IAAIlB,UAAU,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeBeekon","configToWire","geofenceToWire","recordToEntries","rethrowAsBeekonError","wireToAuthTokens","wireToGeofence","wireToGeofenceEvent","wireToLocation","wireToState","wireToSyncStatus","EventHub","subscribed","stateListeners","Set","locationListeners","geofenceListeners","syncListeners","authTokenListeners","ensureSubscribed","onState","w","s","lastState","forEach","cb","onLocation","l","onGeofenceEvent","g","onSyncStatus","lastSyncStatus","onAuthTokens","t","lastAuthTokens","add","undefined","delete","BeekonImpl","hub","configure","config","start","stop","resumeIfNeeded","getCurrentLocation","options","wires","timeoutMs","accuracy","length","e","getLocations","from","to","getTime","map","deleteLocations","before","pendingUploadCount","sync","setExtras","extras","addGeofences","geofences","removeGeofences","ids","listGeofences","Beekon"],"sourceRoot":"../../src","sources":["beekon.ts"],"mappings":";;AAAA,OAAOA,YAAY,MAAM,qBAAkB;AAQ3C,SACEC,YAAY,EACZC,cAAc,EACdC,eAAe,EACfC,oBAAoB,EACpBC,gBAAgB,EAChBC,cAAc,EACdC,mBAAmB,EACnBC,cAAc,EACdC,WAAW,EACXC,gBAAgB,QACX,uBAAoB;AAI3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,CAAC;EACLC,UAAU,GAAG,KAAK;EACTC,cAAc,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACjDC,iBAAiB,GAAG,IAAID,GAAG,CAAqB,CAAC;EACjDE,iBAAiB,GAAG,IAAIF,GAAG,CAA0B,CAAC;EACtDG,aAAa,GAAG,IAAIH,GAAG,CAAuB,CAAC;EAC/CI,kBAAkB,GAAG,IAAIJ,GAAG,CAAuB,CAAC;EAKrE;EACAK,gBAAgBA,CAAA,EAAS;IACvB,IAAI,IAAI,CAACP,UAAU,EAAE;IACrB,IAAI,CAACA,UAAU,GAAG,IAAI;IACtBZ,YAAY,CAACoB,OAAO,CAAEC,CAAC,IAAK;MAC1B,MAAMC,CAAC,GAAGb,WAAW,CAACY,CAAC,CAAC;MACxB,IAAI,CAACE,SAAS,GAAGD,CAAC;MAClB,IAAI,CAACT,cAAc,CAACW,OAAO,CAAEC,EAAE,IAAKA,EAAE,CAACH,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;IACFtB,YAAY,CAAC0B,UAAU,CAAEL,CAAC,IAAK;MAC7B,MAAMM,CAAC,GAAGnB,cA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AAeA,CAACC,GAAa,EAAiB;IAClD,MAAMlE,YAAY,CAACiE,eAAe,CAACC,GAAG,CAAC;EACzC;;EAEA;EACA,MAAMC,aAAaA,CAAA,EAA8B;IAC/C,MAAMpB,KAAK,GAAG,MAAM/C,YAAY,CAACmE,aAAa,CAAC,CAAC;IAChD,OAAOpB,KAAK,CAACS,GAAG,CAAClD,cAAc,CAAC;EAClC;;EAEA;AACF;AACA;AACA;AACA;EACEc,OAAOA,CAACK,EAA4B,EAAc;IAChD,OAAO,IAAI,CAACc,GAAG,CAACnB,OAAO,CAACK,EAAE,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACD,EAAyB,EAAc;IAChD,OAAO,IAAI,CAACc,GAAG,CAACb,UAAU,CAACD,EAAE,CAAC;EAChC;;EAEA;AACF;AACA;AACA;EACEG,eAAeA,CAACH,EAA8B,EAAc;IAC1D,OAAO,IAAI,CAACc,GAAG,CAACX,eAAe,CAACH,EAAE,CAAC;EACrC;;EAEA;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACL,EAA2B,EAAc;IACpD,OAAO,IAAI,CAACc,GAAG,CAACT,YAAY,CAACL,EAAE,CAAC;EAClC;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEO,YAAYA,CAACP,EAA2B,EAAc;IACpD,OAAO,IAAI,CAACc,GAAG,CAACP,YAAY,CAACP,EAAE,CAAC;EAClC;AACF;AAEA,OAAO,MAAM2C,MAAM,GAAG,IAAI9B,UAAU,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["Beekon","BeekonError"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,aAAU;AAIjC,SAASC,WAAW,QAA8B,kBAAe","ignoreList":[]}
1
+ {"version":3,"names":["Beekon","BeekonError"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,aAAU;AA0BjC,SAASC,WAAW,QAA8B,kBAAe","ignoreList":[]}
@@ -1,37 +1,127 @@
1
1
  "use strict";
2
2
 
3
3
  import { BeekonError } from "../types/error.js";
4
- const DEFAULT_INTERVAL_SECONDS = 30;
5
- const DEFAULT_DISTANCE_METERS = 100;
4
+ // Config defaults. Kept here (not in the wire layer) so the native modules can
5
+ // treat every wire field as present.
6
+ const DEFAULTS = {
7
+ minTimeBetweenLocationsSeconds: 30,
8
+ minDistanceBetweenLocationsMeters: 100,
9
+ accuracyMode: 'balanced',
10
+ whenStationary: 'pause',
11
+ stationaryRadiusMeters: 5,
12
+ detectActivity: false,
13
+ syncIntervalSeconds: 300,
14
+ syncBatchSize: 100,
15
+ authStrategy: 'bearer',
16
+ authBodyFormat: 'form',
17
+ authSkewMarginSeconds: 60,
18
+ authRefreshHeaders: {
19
+ Authorization: 'Bearer {accessToken}'
20
+ }
21
+ };
22
+
23
+ // --- Public → wire ---------------------------------------------------------
24
+
25
+ export function recordToEntries(record) {
26
+ if (!record) return [];
27
+ return Object.keys(record).map(key => ({
28
+ key,
29
+ value: record[key]
30
+ }));
31
+ }
6
32
  export function configToWire(config) {
33
+ const sync = config.sync;
34
+ return {
35
+ minTimeBetweenLocationsSeconds: config.minTimeBetweenLocationsSeconds ?? DEFAULTS.minTimeBetweenLocationsSeconds,
36
+ minDistanceBetweenLocationsMeters: config.minDistanceBetweenLocationsMeters ?? DEFAULTS.minDistanceBetweenLocationsMeters,
37
+ accuracyMode: config.accuracyMode ?? DEFAULTS.accuracyMode,
38
+ whenStationary: config.whenStationary ?? DEFAULTS.whenStationary,
39
+ stationaryRadiusMeters: config.stationaryRadiusMeters ?? DEFAULTS.stationaryRadiusMeters,
40
+ detectActivity: config.detectActivity ?? DEFAULTS.detectActivity,
41
+ sync: sync ? {
42
+ url: sync.url,
43
+ headers: recordToEntries(sync.headers),
44
+ intervalSeconds: sync.intervalSeconds ?? DEFAULTS.syncIntervalSeconds,
45
+ batchSize: sync.batchSize ?? DEFAULTS.syncBatchSize,
46
+ auth: sync.auth ? authToWire(sync.auth) : undefined
47
+ } : undefined,
48
+ notification: config.notification ? {
49
+ title: config.notification.title,
50
+ text: config.notification.text,
51
+ smallIcon: config.notification.smallIcon
52
+ } : undefined
53
+ };
54
+ }
55
+ export function geofenceToWire(g) {
7
56
  return {
8
- intervalSeconds: config.intervalSeconds ?? DEFAULT_INTERVAL_SECONDS,
9
- distanceMeters: config.distanceMeters ?? DEFAULT_DISTANCE_METERS,
10
- androidNotification: config.androidNotification
57
+ id: g.id,
58
+ lat: g.latitude,
59
+ lng: g.longitude,
60
+ radiusMeters: g.radiusMeters,
61
+ notifyOnEntry: g.notifyOnEntry ?? true,
62
+ notifyOnExit: g.notifyOnExit ?? true
11
63
  };
12
64
  }
65
+
66
+ // `expiresAt` (a `Date`) becomes epoch millis on the wire; the native side
67
+ // converts to epoch seconds. String maps travel as `WireKeyValue[]`.
68
+ export function authToWire(a) {
69
+ return {
70
+ accessToken: a.accessToken,
71
+ refreshToken: a.refreshToken,
72
+ expiresAtMs: a.expiresAt?.getTime(),
73
+ strategy: a.strategy ?? DEFAULTS.authStrategy,
74
+ refreshUrl: a.refreshUrl,
75
+ refreshPayload: recordToEntries(a.refreshPayload),
76
+ refreshHeaders: recordToEntries(a.refreshHeaders ?? DEFAULTS.authRefreshHeaders),
77
+ refreshBodyFormat: a.refreshBodyFormat ?? DEFAULTS.authBodyFormat,
78
+ responseMapping: {
79
+ accessToken: a.responseMapping?.accessToken,
80
+ refreshToken: a.responseMapping?.refreshToken,
81
+ expiresIn: a.responseMapping?.expiresIn,
82
+ expiresAt: a.responseMapping?.expiresAt
83
+ },
84
+ skewMarginSeconds: a.skewMarginSeconds ?? DEFAULTS.authSkewMarginSeconds,
85
+ seedEpoch: a.seedEpoch
86
+ };
87
+ }
88
+
89
+ // --- Wire → public ---------------------------------------------------------
90
+
13
91
  export function wireToLocation(w) {
14
92
  return {
15
- lat: w.lat,
16
- lng: w.lng,
93
+ id: w.id,
94
+ latitude: w.lat,
95
+ longitude: w.lng,
96
+ timestamp: new Date(w.timestampMs),
17
97
  accuracy: w.accuracy,
18
98
  speed: w.speed,
19
99
  bearing: w.bearing,
20
100
  altitude: w.altitude,
21
- timestamp: new Date(w.timestampMs)
101
+ quality: oneOf(w.quality, ['ok', 'lowAccuracy', 'implausibleSpeed'], 'ok'),
102
+ trigger: oneOf(w.trigger, ['interval', 'motion', 'checkIn', 'geofence', 'manual'], 'interval'),
103
+ motion: oneOf(w.motion, ['moving', 'stationary', 'unknown'], 'unknown'),
104
+ activity: w.activity == null ? null : oneOf(w.activity, ['stationary', 'walking', 'running', 'cycling', 'automotive', 'unknown'], 'unknown'),
105
+ isMock: w.isMock
22
106
  };
23
107
  }
24
- function toStopReason(s) {
25
- switch (s) {
26
- case 'user':
27
- case 'permissionDenied':
28
- case 'locationServicesDisabled':
29
- case 'system':
30
- return s;
31
- default:
32
- // Defensive — native should never emit an unknown reason.
33
- return 'user';
34
- }
108
+ export function wireToGeofence(w) {
109
+ return {
110
+ id: w.id,
111
+ latitude: w.lat,
112
+ longitude: w.lng,
113
+ radiusMeters: w.radiusMeters,
114
+ notifyOnEntry: w.notifyOnEntry,
115
+ notifyOnExit: w.notifyOnExit
116
+ };
117
+ }
118
+ export function wireToGeofenceEvent(w) {
119
+ return {
120
+ id: w.id,
121
+ geofenceId: w.geofenceId,
122
+ type: oneOf(w.type, ['enter', 'exit'], 'enter'),
123
+ timestamp: new Date(w.timestampMs)
124
+ };
35
125
  }
36
126
  export function wireToState(w) {
37
127
  switch (w.type) {
@@ -55,12 +145,59 @@ export function wireToState(w) {
55
145
  };
56
146
  }
57
147
  }
148
+ export function wireToSyncStatus(w) {
149
+ switch (w.type) {
150
+ case 'idle':
151
+ return {
152
+ kind: 'idle'
153
+ };
154
+ case 'pending':
155
+ return {
156
+ kind: 'pending'
157
+ };
158
+ case 'failed':
159
+ return {
160
+ kind: 'failed',
161
+ reason: toSyncFailure(w.failure)
162
+ };
163
+ default:
164
+ return {
165
+ kind: 'idle'
166
+ };
167
+ }
168
+ }
169
+
170
+ /** `expiresAtMs` (epoch millis) becomes a `Date`; `null` propagates faithfully. */
171
+ export function wireToAuthTokens(w) {
172
+ return {
173
+ accessToken: w.accessToken,
174
+ refreshToken: w.refreshToken,
175
+ expiresAt: w.expiresAtMs == null ? null : new Date(w.expiresAtMs),
176
+ epoch: w.epoch
177
+ };
178
+ }
179
+ function toStopReason(s) {
180
+ return oneOf(s, ['user', 'permissionDenied', 'locationServicesDisabled', 'locationUnavailable', 'system'],
181
+ // The native side always populates the reason for a `stopped` state; an
182
+ // unknown/missing value means the wire contract was violated — fall back to
183
+ // `system` rather than throwing on a subscriber.
184
+ 'system');
185
+ }
186
+ function toSyncFailure(s) {
187
+ return oneOf(s, ['auth', 'rejected'], 'rejected');
188
+ }
189
+
190
+ /** Validate a wire enum string against the known set, with a safe fallback. */
191
+ function oneOf(value, allowed, fallback) {
192
+ return allowed.includes(value ?? '') ? value : fallback;
193
+ }
194
+
195
+ // --- Errors ----------------------------------------------------------------
58
196
 
59
197
  /**
60
- * Re-throw a native promise rejection as a typed `BeekonError`. Native modules
61
- * encode the kind in the error code string (`PERMISSION_DENIED`,
62
- * `LOCATION_SERVICES_DISABLED`, `STORAGE_FAILURE`); anything else falls
63
- * through as the original error.
198
+ * Re-throw a native promise rejection as a typed {@link BeekonError}. The native
199
+ * modules encode the kind in the error-code string (`STORAGE_FAILURE`,
200
+ * `INVALID_GEOFENCE`); anything else falls through as the original error.
64
201
  */
65
202
  export function rethrowAsBeekonError(e) {
66
203
  const code = e?.code;
@@ -73,12 +210,16 @@ export function rethrowAsBeekonError(e) {
73
210
  }
74
211
  function codeToKind(code) {
75
212
  switch (code) {
213
+ case 'STORAGE_FAILURE':
214
+ return 'storage';
215
+ case 'INVALID_GEOFENCE':
216
+ return 'invalidGeofence';
76
217
  case 'PERMISSION_DENIED':
77
218
  return 'permissionDenied';
78
219
  case 'LOCATION_SERVICES_DISABLED':
79
220
  return 'locationServicesDisabled';
80
- case 'STORAGE_FAILURE':
81
- return 'storageFailure';
221
+ case 'LOCATION_UNAVAILABLE':
222
+ return 'locationUnavailable';
82
223
  default:
83
224
  return undefined;
84
225
  }
@@ -1 +1 @@
1
- {"version":3,"names":["BeekonError","DEFAULT_INTERVAL_SECONDS","DEFAULT_DISTANCE_METERS","configToWire","config","intervalSeconds","distanceMeters","androidNotification","wireToLocation","w","lat","lng","accuracy","speed","bearing","altitude","timestamp","Date","timestampMs","toStopReason","s","wireToState","type","kind","reason","stopReason","rethrowAsBeekonError","e","code","message","String","codeToKind","undefined"],"sourceRoot":"../../../src","sources":["internal/mappers.ts"],"mappings":";;AAGA,SAASA,WAAW,QAA8B,mBAAgB;AAGlE,MAAMC,wBAAwB,GAAG,EAAE;AACnC,MAAMC,uBAAuB,GAAG,GAAG;AAEnC,OAAO,SAASC,YAAYA,CAACC,MAAoB,EAAc;EAC7D,OAAO;IACLC,eAAe,EAAED,MAAM,CAACC,eAAe,IAAIJ,wBAAwB;IACnEK,cAAc,EAAEF,MAAM,CAACE,cAAc,IAAIJ,uBAAuB;IAChEK,mBAAmB,EAAEH,MAAM,CAACG;EAC9B,CAAC;AACH;AAEA,OAAO,SAASC,cAAcA,CAACC,CAAe,EAAY;EACxD,OAAO;IACLC,GAAG,EAAED,CAAC,CAACC,GAAG;IACVC,GAAG,EAAEF,CAAC,CAACE,GAAG;IACVC,QAAQ,EAAEH,CAAC,CAACG,QAAQ;IACpBC,KAAK,EAAEJ,CAAC,CAACI,KAAK;IACdC,OAAO,EAAEL,CAAC,CAACK,OAAO;IAClBC,QAAQ,EAAEN,CAAC,CAACM,QAAQ;IACpBC,SAAS,EAAE,IAAIC,IAAI,CAACR,CAAC,CAACS,WAAW;EACnC,CAAC;AACH;AAEA,SAASC,YAAYA,CAACC,CAAqB,EAAc;EACvD,QAAQA,CAAC;IACP,KAAK,MAAM;IACX,KAAK,kBAAkB;IACvB,KAAK,0BAA0B;IAC/B,KAAK,QAAQ;MACX,OAAOA,CAAC;IACV;MACE;MACA,OAAO,MAAM;EACjB;AACF;AAEA,OAAO,SAASC,WAAWA,CAACZ,CAAY,EAAe;EACrD,QAAQA,CAAC,CAACa,IAAI;IACZ,KAAK,MAAM;MACT,OAAO;QAAEC,IAAI,EAAE;MAAO,CAAC;IACzB,KAAK,UAAU;MACb,OAAO;QAAEA,IAAI,EAAE;MAAW,CAAC;IAC7B,KAAK,SAAS;MACZ,OAAO;QAAEA,IAAI,EAAE,SAAS;QAAEC,MAAM,EAAEL,YAAY,CAACV,CAAC,CAACgB,UAAU;MAAE,CAAC;IAChE;MACE;MACA,OAAO;QAAEF,IAAI,EAAE;MAAO,CAAC;EAC3B;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,oBAAoBA,CAACC,CAAU,EAAS;EACtD,MAAMC,IAAI,GAAID,CAAC,EAAoCC,IAAI;EACvD,MAAMC,OAAO,GAAIF,CAAC,EAAuCE,OAAO,IAAIC,MAAM,CAACH,CAAC,CAAC;EAC7E,MAAMJ,IAAI,GAAGQ,UAAU,CAACH,IAAI,CAAC;EAC7B,IAAIL,IAAI,EAAE;IACR,MAAM,IAAIvB,WAAW,CAACuB,IAAI,EAAEM,OAAO,CAAC;EACtC;EACA,MAAMF,CAAC;AACT;AAEA,SAASI,UAAUA,CAACH,IAAwB,EAA+B;EACzE,QAAQA,IAAI;IACV,KAAK,mBAAmB;MACtB,OAAO,kBAAkB;IAC3B,KAAK,4BAA4B;MAC/B,OAAO,0BAA0B;IACnC,KAAK,iBAAiB;MACpB,OAAO,gBAAgB;IACzB;MACE,OAAOI,SAAS;EACpB;AACF","ignoreList":[]}
1
+ {"version":3,"names":["BeekonError","DEFAULTS","minTimeBetweenLocationsSeconds","minDistanceBetweenLocationsMeters","accuracyMode","whenStationary","stationaryRadiusMeters","detectActivity","syncIntervalSeconds","syncBatchSize","authStrategy","authBodyFormat","authSkewMarginSeconds","authRefreshHeaders","Authorization","recordToEntries","record","Object","keys","map","key","value","configToWire","config","sync","url","headers","intervalSeconds","batchSize","auth","authToWire","undefined","notification","title","text","smallIcon","geofenceToWire","g","id","lat","latitude","lng","longitude","radiusMeters","notifyOnEntry","notifyOnExit","a","accessToken","refreshToken","expiresAtMs","expiresAt","getTime","strategy","refreshUrl","refreshPayload","refreshHeaders","refreshBodyFormat","responseMapping","expiresIn","skewMarginSeconds","seedEpoch","wireToLocation","w","timestamp","Date","timestampMs","accuracy","speed","bearing","altitude","quality","oneOf","trigger","motion","activity","isMock","wireToGeofence","wireToGeofenceEvent","geofenceId","type","wireToState","kind","reason","toStopReason","stopReason","wireToSyncStatus","toSyncFailure","failure","wireToAuthTokens","epoch","s","allowed","fallback","includes","rethrowAsBeekonError","e","code","message","String","codeToKind"],"sourceRoot":"../../../src","sources":["internal/mappers.ts"],"mappings":";;AAoBA,SAASA,WAAW,QAA8B,mBAAgB;AAalE;AACA;AACA,MAAMC,QAAQ,GAAG;EACfC,8BAA8B,EAAE,EAAE;EAClCC,iCAAiC,EAAE,GAAG;EACtCC,YAAY,EAAE,UAA0B;EACxCC,cAAc,EAAE,OAAyB;EACzCC,sBAAsB,EAAE,CAAC;EACzBC,cAAc,EAAE,KAAK;EACrBC,mBAAmB,EAAE,GAAG;EACxBC,aAAa,EAAE,GAAG;EAClBC,YAAY,EAAE,QAAwB;EACtCC,cAAc,EAAE,MAAwB;EACxCC,qBAAqB,EAAE,EAAE;EACzBC,kBAAkB,EAAE;IAAEC,aAAa,EAAE;EAAuB;AAI9D,CAAC;;AAED;;AAEA,OAAO,SAASC,eAAeA,CAC7BC,MAA0C,EAC1B;EAChB,IAAI,CAACA,MAAM,EAAE,OAAO,EAAE;EACtB,OAAOC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,GAAG,CAAEC,GAAG,KAAM;IAAEA,GAAG;IAAEC,KAAK,EAAEL,MAAM,CAACI,GAAG;EAAG,CAAC,CAAC,CAAC;AACzE;AAEA,OAAO,SAASE,YAAYA,CAACC,MAAoB,EAAc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zB,OAAO,qBAAqB;IAC9B;MACE,OAAOjE,SAAS;EACpB;AACF","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/auth.ts"],"mappings":"","ignoreList":[]}
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
+
3
+ export {};
2
4
  //# sourceMappingURL=config.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=enums.js.map